- It's based on this wiki: https://os.phil-opp.com/freestanding-rust-binary/
- The primary goal for this is educating myself on how to operating systems work.
- The program is built with --edition 2021 using rustup. My work environment:
-
- Arch Linux on x86_64 AMD Ryzen 5 3600X CPU
In order to actually build the application,you need to define a special target value. To avoid any linker errors you need to disable the dependency for the default C runtime.
rustup target add thumbv7em-none-eabihf
cargo build --target thumbv7em-none-eabihf
- Reference: Clang LLVM
- Linux
-
cargo rustc -- -C link-arg=-nostartfiles
- Windows
-
cargo rustc -- -C link-args="/ENTRY:_start /SUBSYSTEM:console"
- macOS
-
cargo rustc -- -C link-args="-e __start -static -nostartfiles"
- I highly recommend using rustup for the ease of setting up.
-
rusup default nightly
-
cargo install bootimage
-
rustup component add llvm-tools-preview
-
cargo bootimage
- NOTE: your terminal should be opened at the root directory at the repo.
- If it isn't, then you need to modify the
file=
part to your full target path. qemu-system-x86_64 -drive format=raw, file=target/x86_64-config/debug/bootimage-operating-system-rust.bin
- ALTERNATIVE: If your terminal is in the repo, you can just type
cargo run
- (For Linux)
dd if=target/x86_64-blog_os/debug/bootimage-blog_os.bin of=/dev/sdX && sync
- ^ Replace sdX with the drive/usb stick you want to write it in.
- !!! It'll delete all the data on that drive/usb stick. !!!