课程
跟随的清华大学 OS 课程实验 C 语言版指导书,因为不熟悉 Rust 就没有选 Rust 的指导书。项目的 Github 仓库见此。
环境搭建
使用的 Arch Linux WSL 环境,参考指导书里的过程进行以下环境搭建操作。
paru -S riscv64-elf-binutils riscv64-elf-gcc riscv64-elf-gdb musl-riscv64 riscv64-linux-gnu-binutils riscv64-linux-gnu-gcc安装交叉编译环境;paru -S qemu-emulators-full安装 qemu;git clone https://github.com/LearningOS/uCore-Tutorial-Code-2022S.git克隆仓库,并切到分支ch1进行测试;- 因为 Arch 包前缀和指导书里的不一样,按
/Makefile:8:TOOLPREFIX = riscv64-elf-修改交叉编译器前缀; - 按
/Makefile:2:all: build修改Makefile,这样可以通过make达到和make build一样的效果。修改前make指令出错,疑似是原Makefile的疏漏; - 利用 Arch 中的
bear包通过Makefile生成compile_commands.json供LSP读取,指令为bear -- make LOG=trace; - 本地测试
make run LOG=trace出现rustsbi panic,替换了下/bootloader/rustsbi-qemu.bin就修好了。具体操作为从rustsbi-qemu的仓库最新 Release 下载下来,然后将其中的rustsbi-qemu.bin替换掉项目中的文件即可。
这样,执行完 make run LOG=trace 后应当能出现正确的测试结果,如下。
~/p/ucore (ch1)> make run LOG=trace
qemu-system-riscv64 -nographic -machine virt -bios ./bootloader/rustsbi-qemu.bin -kernel build/kernel
[rustsbi] RustSBI version 0.2.2, adapting to RISC-V SBI v1.0.0
.______ __ __ _______.___________. _______..______ __
| _ \ | | | | / | | / || _ \ | |
| |_) | | | | | | (----`---| |----`| (----`| |_) || |
| / | | | | \ \ | | \ \ | _ < | |
| |\ \----.| `--' |.----) | | | .----) | | |_) || |
| _| `._____| \______/ |_______/ |__| |_______/ |______/ |__|
[rustsbi] Implementation: RustSBI-QEMU Version 0.1.1
[rustsbi-dtb] Hart count: cluster0 with 1 cores
[rustsbi] misa: RV64ACDFHIMSU
[rustsbi] mideleg: ssoft, stimer, sext (0x1666)
[rustsbi] medeleg: ima, ia, bkpt, la, sa, uecall, ipage, lpage, spage (0xb1ab)
[rustsbi] pmp0: 0x10000000 ..= 0x10001fff (rw-)
[rustsbi] pmp1: 0x2000000 ..= 0x200ffff (rw-)
[rustsbi] pmp2: 0xc000000 ..= 0xc3fffff (rw-)
[rustsbi] pmp3: 0x80000000 ..= 0x8fffffff (rwx)
[rustsbi] enter supervisor 0x80200000
hello wrold!
[ERROR 0]stext: 0x0000000080200000
[WARN 0]etext: 0x0000000080201000
[INFO 0]sroda: 0x0000000080201000
[DEBUG 0]eroda: 0x0000000080202000
[DEBUG 0]sdata: 0x0000000080202000
[INFO 0]edata: 0x0000000080202000
[WARN 0]sbss : 0x0000000080212000
[ERROR 0]ebss : 0x0000000080212000
[PANIC 0] os/main.c:39: ALL DONE