From 410829451bb1bc01691308acb850c7bba9075075 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Fri, 25 Oct 2019 16:11:37 +0200 Subject: Iink rust binary --- kernel/Cargo.toml | 3 +++ kernel/build.sh | 10 +++++++--- kernel/src/lib.rs | 3 +++ kernel/src/linker.ld | 2 +- kernel/src/long_mode_init.asm | 4 ++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 410d6d7..9dd89c3 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -7,3 +7,6 @@ edition = "2018" [lib] crate-type = ["staticlib"] + +[dependencies] +compiler_builtins = { git = "https://github.com/rust-lang/compiler-builtins" } diff --git a/kernel/build.sh b/kernel/build.sh index 4a8130b..8fa91ce 100755 --- a/kernel/build.sh +++ b/kernel/build.sh @@ -1,14 +1,18 @@ #!/usr/bin/sh ASM_PATH="src/" -TARGET_PATH="target/" +TARGET_PATH="target" TMP_PATH="$TARGET_PATH/temp/" OBJ_PATH="$TMP_PATH" LINK_SCRIPT_PATH="src/" GRUB_CFG_PATH="src/grub.cfg" +ARCH="x86_64" +TARGET="$ARCH-uff" +RUST_BIN="$TARGET_PATH/$TARGET/debug/libkernel.a" remove_target() { - rm -rf $TARGET_PATH &> /dev/null + rm -rf $TMP_PATH/* &> /dev/null + rm -f $TARGET_PATH/uff.iso &> /dev/null } create_target() { @@ -27,7 +31,7 @@ build_kernel_elf() { for f in $ASM_PATH/*.asm; do nasm -felf64 "$f" -o $OBJ_PATH/"$(basename -s .asm $f)".o done - ld -n -o $TARGET_PATH/kernel.bin -T $LINK_SCRIPT_PATH/linker.ld $OBJ_PATH/*.o + ld -n -o $TARGET_PATH/kernel.bin -gc-sections -T $LINK_SCRIPT_PATH/linker.ld $OBJ_PATH/*.o $RUST_BIN cleanup_temp } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 066a526..05b90ef 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,6 +1,9 @@ +#![feature(compiler_builtins_lib)] #![no_std] #![no_main] +extern crate compiler_builtins; + #[no_mangle] pub extern "C" fn _start() -> ! { loop {} diff --git a/kernel/src/linker.ld b/kernel/src/linker.ld index cef8809..9b5355c 100644 --- a/kernel/src/linker.ld +++ b/kernel/src/linker.ld @@ -6,7 +6,7 @@ SECTIONS { .boot : { /* ensure that the multiboot heater is at the beginning */ - *(.multiboot_header) + KEEP(*(.multiboot_header)) } .text : diff --git a/kernel/src/long_mode_init.asm b/kernel/src/long_mode_init.asm index f105388..751af9b 100644 --- a/kernel/src/long_mode_init.asm +++ b/kernel/src/long_mode_init.asm @@ -14,4 +14,8 @@ long_mode_start: ; print `Uff!` to screen mov rax, 0x8521846683668255 mov qword [0xb8000], rax + + extern _start + call _start + hlt -- cgit v1.2.3-70-g09d2