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板條箱的文檔我們稍後將它們添加。