RCore-Tutorial版本3.6。请参阅中文的文档。
rcore-Tutorial API文档。查看十个OS的API文档
如果您不知道Rust语言并尝试学习,请访问Rust Learning资源
官方QQ组编号:735045051
该项目旨在展示如何在Rust的Rust中为初学者的RUST上的RISC-V平台上运行类似Unix的OS,而没有任何背景知识有关计算机体系结构,汇编语言或操作系统的知识。
qemu-system-riscv64模拟器或基于Kendryte K210 SOC的Dev板,例如Maix Dock请参阅官方指南。
安装一些工具:
$ rustup target add riscv64gc-unknown-none-elf
$ cargo install cargo-binutils --vers =0.3.3
$ rustup component add llvm-tools-preview
$ rustup component add rust-src在这里,我们手动编译并安装QEMU 7.0.0。例如,在Ubuntu 18.04:
# install dependency packages
$ sudo apt install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev
gawk build-essential bison flex texinfo gperf libtool patchutils bc
zlib1g-dev libexpat-dev pkg-config libglib2.0-dev libpixman-1-dev git tmux python3 python3-pip
# download Qemu source code
$ wget https://download.qemu.org/qemu-7.0.0.tar.xz
# extract to qemu-7.0.0/
$ tar xvJf qemu-7.0.0.tar.xz
$ cd qemu-7.0.0
# build
$ ./configure --target-list=riscv64-softmmu,riscv64-linux-user
$ make -j $( nproc )然后,将以下内容添加到~/.bashrc (请根据您的环境调整这些路径):
export PATH=$PATH:/home/shinbokuow/Downloads/built/qemu-7.0.0
export PATH=$PATH:/home/shinbokuow/Downloads/built/qemu-7.0.0/riscv64-softmmu
export PATH=$PATH:/home/shinbokuow/Downloads/built/qemu-7.0.0/riscv64-linux-user
最后,更新当前的外壳:
$ source ~ /.bashrc现在我们可以检查Qemu的版本:
$ qemu-system-riscv64 --version
QEMU emulator version 7.0.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers根据您的平台从Sifive网站(CTRL+F'工具链')下载压缩文件。
提取它并将“ bin”目录的位置附加到其根$PATH下的位置。
例如,我们可以检查GDB的版本:
$ riscv64-unknown-elf-gdb --version
GNU gdb (SiFive GDB-Metal 10.1.0-2020.12.7) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later < http://gnu.org/licenses/gpl.html >
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.$ pip3 install pyserial
$ sudo apt install python3-serial$ git clone https://github.com/rcore-os/rCore-Tutorial-v3.git
$ cd rCore-Tutorial-v3/os
$ make run输出一些调试消息后,内核列出了所有可用的应用程序,并输入用户外壳:
/**** APPS ****
mpsc_sem
usertests
pipetest
forktest2
cat
initproc
race_adder_loop
threads_arg
race_adder_mutex_spin
race_adder_mutex_blocking
forktree
user_shell
huge_write
race_adder
race_adder_atomic
threads
stack_overflow
filetest_simple
forktest_simple
cmdline_args
run_pipe_test
forktest
matrix
exit
fantastic_text
sleep_simple
yield
hello_world
pipe_large_test
sleep
phil_din_mutex
**************/
Rust user shell
>>
您可以运行除initproc和user_shell本身以外的任何应用程序。要运行一个应用程序,只需输入其文件名并命中输入即可。 usertests可以运行大量应用程序,因此建议使用。
键入Ctrl+a然后x键退出QEMU。
在第6章之前,您不需要SD卡:
$ git clone https://github.com/rcore-os/rCore-Tutorial-v3.git
$ cd rCore-Tutorial-v3/os
$ make run BOARD=k210从第6章中,在运行内核之前,我们应该将SD卡插入PC中,然后手动将文件系统图像写入其中:
$ cd rCore-Tutorial-v3/os
$ make sdcard默认情况下,它将覆盖SD卡的设备/dev/sdb ,但您可以提供另一个位置。例如, make sdcard SDCARD=/dev/sdc 。
之后,从PC上卸下SD卡,然后将其插入K210的插槽。将K210连接到PC,然后:
$ git clone https://github.com/rcore-os/rCore-Tutorial-v3.git
$ cd rCore-Tutorial-v3/os
$ make run BOARD=k210类型Ctrl+]与K210断开连接。
CH9-LOG的分支包含许多调试信息。您可以尝试运行RCORE教程以了解OS内核的内部行为。
$ git clone https://github.com/rcore-os/rCore-Tutorial-v3.git
$ cd rCore-Tutorial-v3/os
$ git checkout ch9-log
$ make run
......
[rustsbi] RustSBI version 0.2.0-alpha.10, adapting to RISC-V SBI v0.3
.______ __ __ _______.___________. _______..______ __
| _ | | | | / | | / || _ | |
| | _) | | | | | | (---- ` --- | | ---- ` | (---- ` | | _) || |
| / | | | | | | | _ < | |
| | - ---. | ` -- ' |.----) | | | .----) | | |_) || |
| _| `._____| ______/ |_______/ |__| |_______/ |______/ |__|
[rustsbi] Implementation: RustSBI-QEMU Version 0.0.2
[rustsbi-dtb] Hart count: cluster0 with 1 cores
[rustsbi] misa: RV64ACDFIMSU
[rustsbi] mideleg: ssoft, stimer, sext (0x222)
[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
[KERN] rust_main() begin
[KERN] clear_bss() begin
[KERN] clear_bss() end
[KERN] mm::init() begin
[KERN] mm::init_heap() begin
[KERN] mm::init_heap() end
[KERN] mm::init_frame_allocator() begin
[KERN] mm::frame_allocator::lazy_static!FRAME_ALLOCATOR begin
...... 当前,它只能帮助您查看代码,因为仅记录了代码的一小部分。
您可以使用os目录下的cargo doc --no-deps --open os的DOC HTML。
十个OS的API文档
我们的第一个版本3.6.0(第1-9章)已发布,我们仍在努力。
这是自3.5.0以来的更新:
power Series应用程序,现在您可以在输出中找到模量UPSafeCell而不是RefCell或spin::Mutex以访问静态数据结构并调整其API,以便一次无法借用两次(提及& .exclusive_access().task[0] run_first_task中的任务[0] TaskContext移动到TaskControlBlock ,而不是在内核堆栈(自CH3)上恢复到适当的位置,消除了烦人的task_cx_ptr2 llvm_asm!与asm! rcore-fs-fuse生成的FS图像大小扩展到128mib huge_write的新测试,该测试评估FS性能(QEMU〜500KIB/S K210〜50KIB/s) UPSafeCell替换spin::Mutex find_pte而不是pagetable中的find_pte_create PageTable::unmap find_pte中3级PTE的有效性,而不是在此功能之外检查它” cargo doc --no-deps --open板条箱的文档我们稍后将它们添加。