link in the prelude object

main
pantonshire 1 year ago
parent 559a4275ba
commit e20030fbc3

@ -1,7 +1,12 @@
%include "defines.s" %include "defines.s"
[org BOOT1_LOADPOINT]
[bits 16] [bits 16]
section .prelude
extern boot1_bin_len
global prelude
prelude: prelude:
hlt hlt
dd boot1_bin_len

@ -20,24 +20,31 @@ fn main() {
} }
fn emit_link_args() { fn emit_link_args() {
println!("cargo::rustc-link-arg=-Tlink.ld"); let linker_script_path = "link.ld";
println!("cargo::rustc-link-arg=-T{}", linker_script_path);
rerun_if_changed(linker_script_path.as_ref());
} }
fn rerun_if_changed(path: &Path) { fn rerun_if_changed(path: &Path) {
if let Some(path_str) = path.to_str() { let path_str = path.to_str()
println!("cargo::rerun-if-changed={}", path_str); .expect("expected path to be valid utf8");
} println!("cargo::rerun-if-changed={}", path_str);
else { }
eprintln!("invalid unicode file path");
} fn link_obj(path: &Path) {
let path_str = path.to_str()
.expect("expected path to be valid utf8");
println!("cargo::rustc-link-arg={}", path_str);
} }
fn build_asm(nasm: &Nasm, out_dir: &Path) { fn build_asm(nasm: &Nasm, out_dir: &Path) {
let prelude_obj_path = out_dir.join("prelude.o");
nasm.assemble( nasm.assemble(
&out_dir.join("prelude.bin"), &prelude_obj_path,
&["asm/prelude.s".as_ref()], &["asm/prelude.s".as_ref()],
&["../include".as_ref()], &["../include".as_ref()],
).unwrap(); ).unwrap();
link_obj(&prelude_obj_path);
} }
struct Nasm { struct Nasm {
@ -57,9 +64,9 @@ impl Nasm {
let mut cmd = Command::new(&self.bin_path); let mut cmd = Command::new(&self.bin_path);
cmd cmd
.arg("-Werror")
.arg("-f") .arg("-f")
.arg("bin") .arg("elf");
.arg("-Werror");
for include in includes { for include in includes {
let mut buf = OsString::new(); let mut buf = OsString::new();

@ -1,10 +1,34 @@
OUTPUT_FORMAT("binary") OUTPUT_FORMAT("binary")
. = 0x9000;
SECTIONS {
.text : { *(.text); *(.text.*) }
.data : { *(.data); *(.data.*) }
.bss : { *(.bss); *(.bss.*) }
.rodata : { *(.rodata); *(.rodata.*) }
}
. = 0x8200;
SECTIONS {
.prelude : {
*(.prelude)
}
.text : {
*(.text)
*(.text.*)
}
.data : {
*(.data)
*(.data.*)
}
.bss : {
*(.bss)
*(.bss.*)
}
.rodata : {
*(.rodata)
*(.rodata.*)
}
/* Define a symbol for the total length of the binary, so the prelude knows how many blocks to
* load from disk.
*/
boot1_bin_len = . - 0x8200;
}

@ -10,6 +10,10 @@ const VGA_ADDR: usize = 0xb8000;
const STR: &[u8] = b"the quick brown fox jumps over the lazy dog"; const STR: &[u8] = b"the quick brown fox jumps over the lazy dog";
extern "C" {
fn prelude() -> !;
}
#[panic_handler] #[panic_handler]
fn panic(_info: &PanicInfo) -> ! { fn panic(_info: &PanicInfo) -> ! {
hlt() hlt()
@ -43,7 +47,8 @@ pub extern "C" fn _start() -> ! {
vga_buf[0] = 0x1f02; //smiley vga_buf[0] = 0x1f02; //smiley
hlt() // hlt()
unsafe { prelude() };
} }
#[inline] #[inline]

Loading…
Cancel
Save