Raw, very basic bootloader binary in pure Rust?

Viewed 547

My goal is to do https://github.com/cfenollosa/os-tutorial/tree/master/01-bootsector-barebones in pure Rust using asm, or rather global_asm.

Here's what I tried:

  1. Create a new project and create .cargo/config.toml with these contents:
    [build]
    target = "target.json"
    
    [unstable]
    build-std = ["core", "compiler_builtins"]
    
  2. Create the target.json with these contents:
    {
        "llvm-target": "x86_64-unknown-none",
        "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
        "arch": "x86_64",
        "target-endian": "little",
        "target-pointer-width": "64",
        "target-c-int-width": "32",
        "os": "none",
        "executables": true,
        "linker-flavor": "ld.lld",
        "linker": "rust-lld",
        "panic-strategy": "abort",
        "disable-redzone": true,
        "features": "-mmx,-sse,+soft-float"
    }
    
  3. And finally src/main.rs:
    #![feature(global_asm)]
    #![no_main]
    #![no_std]
    
    global_asm!(r#"
    loop:
      jmp loop
    .org 510
    .word 0xaa55
    "# :::: "volatile");
    
    #[panic_handler]
    fn panic(panic_info: &core::panic::PanicInfo) -> ! {
        loop {}
    }
    
  4. A few setup commands:
    rustup override set nightly
    cargo install cargo-binutils
    rustup component add llvm-tools-preview
    
  5. Compile and transform it using cargo objcopy -- -O binary boot_sect_simple.bin

This compiles successfully and the next step would be to run the binary in QEMU. The problem is that this boot_sect_simple.bin contains zero bytes.

How can I get this to work?

0 Answers
Related