Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
e552f3c
Add sys_yield tests and compile them to different location.
wyfcyx Nov 28, 2020
91043b0
Switch ok with debug mode apps, implement sys_exit correctly later.
wyfcyx Nov 28, 2020
4590f23
sys_yield tests worked on qemu.
wyfcyx Nov 28, 2020
63aaa9d
Chapter3: power2/3/5 & sleep test worked on k210/qemu based on timer.
wyfcyx Nov 29, 2020
4b01ff7
Build application at 0x0 in release mode.
wyfcyx Dec 2, 2020
2fd70b0
Heap test passed on k210/qemu, heap size = 3M.
wyfcyx Dec 2, 2020
1256085
Frame Allocator OK.
wyfcyx Dec 3, 2020
0011fe9
Kernel remapped.
wyfcyx Dec 4, 2020
3625b75
Analyse ELF.
wyfcyx Dec 4, 2020
064f1cb
Fetching buffer arguments from user space.
wyfcyx Dec 6, 2020
f54573a
Fetch buffer in user space as a Vec.
wyfcyx Dec 7, 2020
8ee3671
Split kernel/user trap handler && Fix user tests.
wyfcyx Dec 7, 2020
949f209
ch4 ok on qemu/k210 && Remove some comments.
wyfcyx Dec 7, 2020
44ea4ac
Update env.
wyfcyx Jan 2, 2021
75c639d
Remove meaningless sstatus::set_sie() when initializing.
wyfcyx Jan 3, 2021
3032199
Flush icache before returning to user.
wyfcyx Jan 3, 2021
7d22eb8
Move some variable name to task_cx to task_cx_ptr2
wyfcyx Jan 4, 2021
ff2c39e
Update from previous chapters.
wyfcyx Jan 5, 2021
44aa8a3
rust-toochain --> nightly
chyyuu Jan 16, 2021
49b20e7
Fix os/Makefile: Support macOS
wyfcyx Jan 20, 2021
e5dd61c
Fix k210 CLOCK_FREQ
wyfcyx Jan 26, 2021
1e15b35
Do not clone KERNEL_SPACE in mm::init
wyfcyx Jan 26, 2021
8cb5722
Update os/Makefile && Update rust to 2021-01-30
wyfcyx Feb 2, 2021
23ef1eb
Bump rustsbi to 0.1.1 && make config of qemu/k210 different
wyfcyx Feb 7, 2021
e12a932
Move kflash.py out of proj.
wyfcyx Feb 8, 2021
665307e
Fix alignment in os/build.rs
wyfcyx Feb 13, 2021
747af4f
Fix overflow bug when ceiling va
wyfcyx Feb 23, 2021
f0596b9
Add Ubuntu18.04 docker
wyfcyx Feb 27, 2021
29e9aa6
Do not fetch tools when running on qemu.
wyfcyx Mar 5, 2021
187b0be
Link small sections in linker
wyfcyx Mar 7, 2021
1496f31
Bump rustsbi to 0.2.0-alpha.1[81d53d8]
wyfcyx Mar 9, 2021
78aea96
Fix end_va bug in translated_byte_buffer
wyfcyx Mar 23, 2021
f1de835
Downgrade cargo-binutils to 0.2.0
wyfcyx Apr 5, 2021
312b355
RefCell->UPSafeCell && TaskCx->TCB
wyfcyx Jul 12, 2021
1407c63
Bump rustsbi to qemu[d4968dd2] k210[b689314e].
wyfcyx Jul 17, 2021
aea416a
rustc 1.55.0-nightly (2f391da2e 2021-07-14)
wyfcyx Jul 17, 2021
07fc98b
Replace llvm_asm! with asm
wyfcyx Jul 18, 2021
6983848
Exclusive UPSafeCell: A RefCell wrapper
wyfcyx Jul 19, 2021
a4bced5
update to rustc 1.56.0-nightly (08095fc1f 2021-07-26)
chyyuu Jul 29, 2021
f41af0a
Update rustc && rustsbi
wyfcyx Aug 26, 2021
6187cda
Update README
wyfcyx Aug 26, 2021
928a6f0
Remove spin::Mutex in frame_allocator and memory_set.
wyfcyx Sep 7, 2021
6d0eb28
rust->nightly-2021-10-15,cargo-binutils->0.3.3
wyfcyx Oct 20, 2021
4d95f0c
Now construction of PA/VA only uses 56/39 bits.
wyfcyx Nov 13, 2021
2a5b451
update user module to 2021autumn version
zhanghx0905 Nov 19, 2021
bf8882a
os gettime syscall consistent with user mod
zhanghx0905 Nov 19, 2021
4bf473a
remove wrong impl of gettime
zhanghx0905 Nov 19, 2021
1979212
Merge pull request #38 from zhanghx0905/ch4
chyyuu Nov 20, 2021
9d69c9f
update .gitignore, README.md, dev-env-info.md
chyyuu Nov 20, 2021
c5834c1
ch4-lab: rewrite sys_get_time
brelance Mar 19, 2023
ea9e293
add commit for switch branches
brelance Mar 19, 2023
7ae1d87
add commit for switch branches
brelance Mar 19, 2023
c30140f
checkout other branch
brelance Mar 20, 2023
252cbc0
add commit for change branch
brelance Mar 20, 2023
87817ec
add commit to checkout branch
brelance Mar 20, 2023
a28cdec
configurate vscode debug
brelance Mar 20, 2023
69112b5
configurate vscode debug
brelance Mar 20, 2023
03fcbfa
test sleep passed
brelance Mar 20, 2023
ee88080
add sys_mmap system call
brelance Mar 20, 2023
8a90a17
add unmap syscall
brelance Mar 20, 2023
0fd14ec
test and debug: all test cases passed
brelance Mar 21, 2023
e86333d
merge ch1-lab to ch4-lab
brelance Mar 21, 2023
800d3a3
test and debug: extend tran_handler
brelance Mar 21, 2023
7f3776f
cofigurate makefiles
brelance Mar 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/*
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/*
os/target/*
os/.idea/*
.idea
Cargo.lock
target
os/src/link_app.S
user/target/*
user/.idea/*
os/last-*
user/build
tools
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "cppdbg",
"request": "launch",
"name": "rcore-debug",
"program": "${workspaceFolder}/os/target/riscv64gc-unknown-none-elf/release/os",
"miDebuggerServerAddress": "localhost:1234",

"miDebuggerPath": "/usr/bin/gdb-multiarch",
"cwd": "${workspaceRoot}",
// "preLaunchTask": "rcore-build"
}
]
}
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// Prevent "can't find crate for `test`" error on no_std
// Ref: https://github.com/rust-lang/vscode-rust/issues/729
// For vscode-rust plugin users:
"rust.target": "riscv64gc-unknown-none-elf",
"rust.all_targets": false,
// For Rust Analyzer plugin users:
"rust-analyzer.cargo.target": "riscv64gc-unknown-none-elf",
"rust-analyzer.checkOnSave.allTargets": false,
// "rust-analyzer.cargo.features": [
// "board_qemu"
// ]
}
11 changes: 11 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "rcore-build",
"type": "shell",
"isBackground": true,
"command": "cd os && make TEST=1 gdbserver"
}
]
}
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:18.04
LABEL maintainer="dinghao188" \
version="1.1" \
description="ubuntu 18.04 with tools for tsinghua's rCore-Tutorial-V3"

#install some deps
RUN set -x \
&& apt-get update \
&& apt-get install -y curl wget autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \
gawk build-essential bison flex texinfo gperf libtool patchutils bc xz-utils \
zlib1g-dev libexpat-dev pkg-config libglib2.0-dev libpixman-1-dev git tmux python3

#install rust and qemu
RUN set -x; \
RUSTUP='/root/rustup.sh' \
&& cd $HOME \
#install rust
&& curl https://sh.rustup.rs -sSf > $RUSTUP && chmod +x $RUSTUP \
&& $RUSTUP -y --default-toolchain nightly --profile minimal \

#compile qemu
&& wget https://ftp.osuosl.org/pub/blfs/conglomeration/qemu/qemu-5.0.0.tar.xz \
&& tar xvJf qemu-5.0.0.tar.xz \
&& cd qemu-5.0.0 \
&& ./configure --target-list=riscv64-softmmu,riscv64-linux-user \
&& make -j$(nproc) install \
&& cd $HOME && rm -rf qemu-5.0.0 qemu-5.0.0.tar.xz

#for chinese network
RUN set -x; \
APT_CONF='/etc/apt/sources.list'; \
CARGO_CONF='/root/.cargo/config'; \
BASHRC='/root/.bashrc' \
&& echo 'export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static' >> $BASHRC \
&& echo 'export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup' >> $BASHRC \
&& touch $CARGO_CONF \
&& echo '[source.crates-io]' > $CARGO_CONF \
&& echo "replace-with = 'ustc'" >> $CARGO_CONF \
&& echo '[source.ustc]' >> $CARGO_CONF \
&& echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> $CARGO_CONF
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DOCKER_NAME ?= dinghao188/rcore-tutorial
.PHONY: docker build_docker

docker:
docker run --rm -it --mount type=bind,source=$(shell pwd),destination=/mnt ${DOCKER_NAME}

build_docker:
docker build -t ${DOCKER_NAME} .
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,67 @@
# rCore-Tutorial-v3
rCore-Tutorial version 3.
rCore-Tutorial version 3.5. See the [Documentation in Chinese](https://rcore-os.github.io/rCore-Tutorial-Book-v3/).

## news
- 2021.11.20: Now we are updating our labs. Please checkout chX-dev Branches for our current new labs. (Notice: please see the [Dependency] section in the end of this doc)

## Overview

This 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**.

## Features

* 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)
* OS
* concurrency of multiple processes
* preemptive scheduling(Round-Robin algorithm)
* dynamic memory management in kernel
* virtual memory
* a simple file system with a block cache
* an interactive shell in the userspace
* **only 4K+ LoC**
* [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)

## Run our project

TODO:

## Working in progress

Now we are still updating our project, you can find latest changes on branches `chX-dev` such as `ch1-dev`. We are intended to publish first release 3.5.0 after completing most of the tasks mentioned below.

Overall progress: ch7

### Completed

* [x] automatically clean up and rebuild before running our project on a different platform
* [x] fix `power` series application in early chapters, now you can find modulus in the output
* [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 `& .exclusive_access().task[0]` in `run_first_task`)
* [x] move `TaskContext` into `TaskControlBlock` instead of restoring it in place on kernel stack(since ch3), eliminating annoying `task_cx_ptr2`
* [x] replace `llvm_asm!` with `asm!`
* [x] expand the fs image size generated by `rcore-fs-fuse` to 128MiB
* [x] add a new test named `huge_write` which evaluates the fs performance(qemu\~500KiB/s k210\~50KiB/s)
* [x] flush all block cache to disk after a fs transaction which involves write operation
* [x] replace `spin::Mutex` with `UPSafeCell` before SMP chapter
* [x] add codes for a new chapter about synchronization & mutual exclusion(uniprocessor only)

### Todo(High priority)

* [ ] support Allwinner's RISC-V D1 chip
* [ ] bug fix: we should call `find_pte` rather than `find_pte_create` in `PageTable::unmap`
* [ ] bug fix: check validity of level-3 pte in `find_pte` instead of checking it outside this function
* [ ] use old fs image optionally, do not always rebuild the image
* [ ] add new system calls: getdents64/fstat
* [ ] shell functionality improvement(to be continued...)
* [ ] give every non-zero process exit code an unique and clear error type
* [ ] effective error handling of mm module

### Todo(Low priority)

* [ ] rewrite practice doc and remove some inproper questions
* [ ] provide smooth debug experience at a Rust source code level
* [ ] format the code using official tools


### Crates

We will add them later.
Binary file modified bootloader/rustsbi-k210.bin
Binary file not shown.
Binary file modified bootloader/rustsbi-qemu.bin
Binary file not shown.
18 changes: 18 additions & 0 deletions dev-env-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# rCore-Tutorial-v3
rCore-Tutorial version 3.x

## Dependency

### Binaries

* rustc: 1.57.0-nightly (e1e9319d9 2021-10-14)

* cargo-binutils: 0.3.3

* qemu: 5.0.0

* rustsbi-lib: 0.2.0-alpha.4

rustsbi-qemu: d4968dd2

rustsbi-k210: b689314e
132 changes: 0 additions & 132 deletions os/Cargo.lock

This file was deleted.

12 changes: 11 additions & 1 deletion os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ edition = "2018"

[dependencies]
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
buddy_system_allocator = "0.6"
bitflags = "1.2.1"
xmas-elf = "0.7.0"

[features]
board_qemu = []
board_k210 = []

[profile.release]
debug = true
Loading