Rust
2026/3/31小于 1 分钟
对于学习到的一些基础知识,这里不再介绍,着重强调一下用户态这个东西,也就是说U,S,M三种模式
no_std
在linux上面开启一个编译risvc的rust程序也很简单。
in your
project, find the.cargoand go into the file.cargo/config.toml- add the following content:
[build] target = "riscv64gc-unknown-none-elf"now, go into your
main.rs, you will find that there is a error- run following commands
rustup target add riscv64gc-unknown-none-elf- then, to fix the error use
no_std
// src/main.rs #![no_std] #![no_main] mod lang_items; fn main(){ } //src/lang_items.rs use core::panic::PanicInfo; #[panic_handler] fn panic(_info: &PanicInfo) -> ! { loop {} } // without this, your project won't go on // because you give up std lib // in no_std panic_handler is empty // which means you must implement it by yourself // then you could biuld your projectdebug your project
- install tools
cargo install cargo-binutils rustup component add llvm-tools-preview- DEBUG
file target/riscv64gc-unknown-none-elf/debug/hello_os rust-readobj -h target/riscv64gc-unknown-none-elf/debug/hello_os rust-objdump -S target/riscv64gc-unknown-none-elf/debug/hello_os
learn qemu
qemu-system-riscv64 \
-machine virt \
-nographic \
-bios ../bootloader/rustsbi-qemu.bin \
-device loader,file=target/riscv64gc-unknown-none-elf/release/os.bin,addr=0x80200000