{"id":13440720,"url":"https://github.com/chyyuu/os_kernel_lab","last_synced_at":"2026-03-16T00:01:26.194Z","repository":{"id":4362961,"uuid":"5499304","full_name":"chyyuu/os_kernel_lab","owner":"chyyuu","description":"OS kernel labs based on Rust/C Lang \u0026 RISC-V 64/X86-32","archived":false,"fork":false,"pushed_at":"2023-01-27T03:05:28.000Z","size":99196,"stargazers_count":4034,"open_issues_count":9,"forks_count":1902,"subscribers_count":217,"default_branch":"main","last_synced_at":"2026-02-11T23:07:43.796Z","etag":null,"topics":["kernel","lab","os","risc-v","rust"],"latest_commit_sha":null,"homepage":"https://rcore-os.github.io/rCore-Tutorial-Book-v3/index.html","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chyyuu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-21T18:44:08.000Z","updated_at":"2026-02-11T02:57:37.000Z","dependencies_parsed_at":"2023-02-15T04:45:58.480Z","dependency_job_id":null,"html_url":"https://github.com/chyyuu/os_kernel_lab","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chyyuu/os_kernel_lab","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyyuu%2Fos_kernel_lab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyyuu%2Fos_kernel_lab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyyuu%2Fos_kernel_lab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyyuu%2Fos_kernel_lab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chyyuu","download_url":"https://codeload.github.com/chyyuu/os_kernel_lab/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chyyuu%2Fos_kernel_lab/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30280337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T01:43:35.720Z","status":"online","status_checked_at":"2026-03-09T02:00:08.011Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kernel","lab","os","risc-v","rust"],"created_at":"2024-07-31T03:01:25.502Z","updated_at":"2026-03-16T00:01:26.134Z","avatar_url":"https://github.com/chyyuu.png","language":"Rust","readme":"# rCore-Tutorial-v3\nrCore-Tutorial version 3.6. See the [Documentation in Chinese](https://rcore-os.github.io/rCore-Tutorial-Book-v3/).\n\nrCore-Tutorial API Docs.  See the [API Docs of Ten OSes ](#OS-API-DOCS)\n\nIf you don't know  Rust Language and try to learn it, please visit [Rust Learning Resources](https://github.com/rcore-os/rCore/wiki/study-resource-of-system-programming-in-RUST)\n\nOfficial QQ group number: 735045051\n\n## news\n- 23/06/2022: Version 3.6.0 is on the way! Now we directly update the code on chX branches, please periodically check if there are any updates.\n\n## Overview\n\nThis project aims to show how to write an **Unix-like OS** running on **RISC-V** platforms **from scratch** in **[Rust](https://www.rust-lang.org/)** for **beginners** without any background knowledge about **computer architectures, assembly languages or operating systems**.\n\n## Features\n\n* Platform supported: `qemu-system-riscv64` simulator or dev boards based on [Kendryte K210 SoC](https://canaan.io/product/kendryteai) such as [Maix Dock](https://www.seeedstudio.com/Sipeed-MAIX-Dock-p-4815.html)\n* OS\n  * concurrency of multiple processes each of which contains mutiple native threads\n  * preemptive scheduling(Round-Robin algorithm)\n  * dynamic memory management in kernel\n  * virtual memory\n  * a simple file system with a block cache\n  * an interactive shell in the userspace\n* **only 4K+ LoC**\n* [A detailed documentation in Chinese](https://rcore-os.github.io/rCore-Tutorial-Book-v3/) in spite of the lack of comments in the code(English version is not available at present)\n\n## Prerequisites\n\n### Install Rust\n\nSee [official guide](https://www.rust-lang.org/tools/install).\n\nInstall some tools:\n\n```sh\n$ rustup target add riscv64gc-unknown-none-elf\n$ cargo install cargo-binutils --vers =0.3.3\n$ rustup component add llvm-tools-preview\n$ rustup component add rust-src\n```\n\n### Install Qemu\n\nHere we manually compile and install Qemu 7.0.0. For example, on Ubuntu 18.04:\n\n```sh\n# install dependency packages\n$ sudo apt install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \\\n              gawk build-essential bison flex texinfo gperf libtool patchutils bc \\\n              zlib1g-dev libexpat-dev pkg-config  libglib2.0-dev libpixman-1-dev git tmux python3 python3-pip\n# download Qemu source code\n$ wget https://download.qemu.org/qemu-7.0.0.tar.xz\n# extract to qemu-7.0.0/\n$ tar xvJf qemu-7.0.0.tar.xz\n$ cd qemu-7.0.0\n# build\n$ ./configure --target-list=riscv64-softmmu,riscv64-linux-user\n$ make -j$(nproc)\n```\n\nThen, add following contents to `~/.bashrc`(please adjust these paths according to your environment):\n\n```\nexport PATH=$PATH:/home/shinbokuow/Downloads/built/qemu-7.0.0\nexport PATH=$PATH:/home/shinbokuow/Downloads/built/qemu-7.0.0/riscv64-softmmu\nexport PATH=$PATH:/home/shinbokuow/Downloads/built/qemu-7.0.0/riscv64-linux-user\n```\n\nFinally, update the current shell:\n\n```sh\n$ source ~/.bashrc\n```\n\nNow we can check the version of Qemu:\n\n```sh\n$ qemu-system-riscv64 --version\nQEMU emulator version 7.0.0\nCopyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers\n```\n\n### Install RISC-V GNU Embedded Toolchain(including GDB)\n\nDownload the compressed file according to your platform From [Sifive website](https://www.sifive.com/software)(Ctrl+F 'toolchain').\n\nExtract it and append the location of the 'bin' directory under its root directory to `$PATH`.\n\nFor example, we can check the version of GDB:\n\n```sh\n$ riscv64-unknown-elf-gdb --version\nGNU gdb (SiFive GDB-Metal 10.1.0-2020.12.7) 10.1\nCopyright (C) 2020 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later \u003chttp://gnu.org/licenses/gpl.html\u003e\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n```\n\n### Install serial tools(Optional, if you want to run on K210)\n\n```sh\n$ pip3 install pyserial\n$ sudo apt install python3-serial\n```\n\n## Run our project\n\n### Qemu\n\n```sh\n$ git clone https://github.com/rcore-os/rCore-Tutorial-v3.git\n$ cd rCore-Tutorial-v3/os\n$ make run\n```\n\nAfter outputing some debug messages, the kernel lists all the applications available and enter the user shell:\n\n```\n/**** APPS ****\nmpsc_sem\nusertests\npipetest\nforktest2\ncat\ninitproc\nrace_adder_loop\nthreads_arg\nrace_adder_mutex_spin\nrace_adder_mutex_blocking\nforktree\nuser_shell\nhuge_write\nrace_adder\nrace_adder_atomic\nthreads\nstack_overflow\nfiletest_simple\nforktest_simple\ncmdline_args\nrun_pipe_test\nforktest\nmatrix\nexit\nfantastic_text\nsleep_simple\nyield\nhello_world\npipe_large_test\nsleep\nphil_din_mutex\n**************/\nRust user shell\n\u003e\u003e \n```\n\nYou can run any application except for `initproc` and `user_shell` itself. To run an application, just input its filename and hit enter. `usertests` can run a bunch of applications, thus it is recommended.\n\nType `Ctrl+a` then `x` to exit Qemu.\n\n### K210\n\nBefore chapter 6, you do not need a SD card:\n\n```sh\n$ git clone https://github.com/rcore-os/rCore-Tutorial-v3.git\n$ cd rCore-Tutorial-v3/os\n$ make run BOARD=k210\n```\n\nFrom chapter 6, before running the kernel, we should insert a SD card into PC and manually write the filesystem image to it:\n\n```sh\n$ cd rCore-Tutorial-v3/os\n$ make sdcard\n```\n\nBy default it will overwrite the device `/dev/sdb` which is the SD card, but you can provide another location. For example, `make sdcard SDCARD=/dev/sdc`.\n\nAfter that, remove the SD card from PC and insert it to the slot of K210. Connect the K210 to PC and then:\n\n```sh\n$ git clone https://github.com/rcore-os/rCore-Tutorial-v3.git\n$ cd rCore-Tutorial-v3/os\n$ make run BOARD=k210\n```\n\nType `Ctrl+]` to disconnect from K210.\n\n\n## Show runtime debug info of OS kernel version\nThe branch of ch9-log contains a lot of debug info. You could try to run rcore tutorial \nfor understand the internal behavior of os kernel.\n\n```sh\n$ git clone https://github.com/rcore-os/rCore-Tutorial-v3.git\n$ cd rCore-Tutorial-v3/os\n$ git checkout ch9-log\n$ make run\n......\n[rustsbi] RustSBI version 0.2.0-alpha.10, adapting to RISC-V SBI v0.3\n.______       __    __      _______.___________.  _______..______   __\n|   _  \\     |  |  |  |    /       |           | /       ||   _  \\ |  |\n|  |_)  |    |  |  |  |   |   (----`---|  |----`|   (----`|  |_)  ||  |\n|      /     |  |  |  |    \\   \\       |  |      \\   \\    |   _  \u003c |  |\n|  |\\  \\----.|  `--'  |.----)   |      |  |  .----)   |   |  |_)  ||  |\n| _| `._____| \\______/ |_______/       |__|  |_______/    |______/ |__|\n\n[rustsbi] Implementation: RustSBI-QEMU Version 0.0.2\n[rustsbi-dtb] Hart count: cluster0 with 1 cores\n[rustsbi] misa: RV64ACDFIMSU\n[rustsbi] mideleg: ssoft, stimer, sext (0x222)\n[rustsbi] medeleg: ima, ia, bkpt, la, sa, uecall, ipage, lpage, spage (0xb1ab)\n[rustsbi] pmp0: 0x10000000 ..= 0x10001fff (rw-)\n[rustsbi] pmp1: 0x2000000 ..= 0x200ffff (rw-)\n[rustsbi] pmp2: 0xc000000 ..= 0xc3fffff (rw-)\n[rustsbi] pmp3: 0x80000000 ..= 0x8fffffff (rwx)\n[rustsbi] enter supervisor 0x80200000\n[KERN] rust_main() begin\n[KERN] clear_bss() begin\n[KERN] clear_bss() end\n[KERN] mm::init() begin\n[KERN] mm::init_heap() begin\n[KERN] mm::init_heap() end\n[KERN] mm::init_frame_allocator() begin\n[KERN] mm::frame_allocator::lazy_static!FRAME_ALLOCATOR begin\n......\n```\n\n## Rustdoc\n\nCurrently it can only help you view the code since only a tiny part of the code has been documented.\n\nYou can open a doc html of `os` using `cargo doc --no-deps --open` under `os` directory.\n\n### OS-API-DOCS\nThe API Docs for Ten OS\n1. [Lib-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch1/os/index.html)\n1. [Batch-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch2/os/index.html)\n1. [MultiProg-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch3-coop/os/index.html)\n1. [TimeSharing-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch3/os/index.html)\n1. [AddrSpace-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch4/os/index.html)\n1. [Process-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch5/os/index.html)\n1. [FileSystem-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch6/os/index.html)\n1. [IPC-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch7/os/index.html)\n1. [SyncMutex-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch8/os/index.html)\n1. [IODevice-OS API doc](https://learningos.github.io/rCore-Tutorial-v3/ch9/os/index.html)\n\n## Working in progress\n\nOur first release 3.6.0 (chapter 1-9) has been published, and we are still working on it.\n\n* chapter 9: need more descripts about different I/O devices\n\nHere are the updates since 3.5.0:\n\n### Completed\n\n* [x] automatically clean up and rebuild before running our project on a different platform\n* [x] fix `power` series application in early chapters, now you can find modulus in the output\n* [x] use `UPSafeCell` instead of `RefCell` or `spin::Mutex` in order to access static data structures and adjust its API so that it cannot be borrowed twice at a time(mention `\u0026 .exclusive_access().task[0]` in `run_first_task`)\n* [x] move `TaskContext` into `TaskControlBlock` instead of restoring it in place on kernel stack(since ch3), eliminating annoying `task_cx_ptr2`\n* [x] replace `llvm_asm!` with `asm!`\n* [x] expand the fs image size generated by `rcore-fs-fuse` to 128MiB\n* [x] add a new test named `huge_write` which evaluates the fs performance(qemu\\~500KiB/s k210\\~50KiB/s)\n* [x] flush all block cache to disk after a fs transaction which involves write operation\n* [x] replace `spin::Mutex` with `UPSafeCell` before SMP chapter\n* [x] add codes for a new chapter about synchronization \u0026 mutual exclusion(uniprocessor only)\n* [x] bug fix: we should call `find_pte` rather than `find_pte_create` in `PageTable::unmap`\n* [x] clarify: \"check validity of level-3 pte in `find_pte` instead of checking it outside this function\" should not be a bug\n* [x] code of chapter 8: synchronization on a uniprocessor\n* [x] switch the code of chapter 6 and chapter 7\n* [x] support signal mechanism in chapter 7/8(only works for apps with a single thread)\n* [x] Add boards/ directory and support rustdoc, for example you can use `cargo doc --no-deps --open` to view the documentation of a crate\n* [x] code of chapter 9: device drivers based on interrupts, including UART, block, keyboard, mouse, gpu devices\n* [x] add CI autotest and doc in github \n### Todo(High priority)\n\n* [ ] review documentation, current progress: 8/9\n* [ ] use old fs image optionally, do not always rebuild the image\n* [ ] shell functionality improvement(to be continued...)\n* [ ] give every non-zero process exit code an unique and clear error type\n* [ ] effective error handling of mm module\n* [ ] add more os functions for understanding os conecpts and principles\n### Todo(Low priority)\n\n* [ ] rewrite practice doc and remove some inproper questions\n* [ ] provide smooth debug experience at a Rust source code level\n* [ ] format the code using official tools\n\n### Crates\n\nWe will add them later.\n","funding_links":[],"categories":["HarmonyOS","Rust","Rust 程序设计","General Operating System"],"sub_categories":["Windows Manager","网络服务_其他"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchyyuu%2Fos_kernel_lab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchyyuu%2Fos_kernel_lab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchyyuu%2Fos_kernel_lab/lists"}