This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8d94441
Showing
289 changed files
with
16,638 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.o | ||
*.bin | ||
*.elf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"files.associations": { | ||
"os.h": "c", | ||
"stdarg.h": "c", | ||
"platform.h": "c", | ||
"stddef.h": "c" | ||
}, | ||
"workbench.editor.wrapTabs": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"tasks": [ | ||
{ | ||
"type": "cppbuild", | ||
"label": "C/C++: aarch64-linux-gnu-gcc 生成活动文件", | ||
"command": "/usr/bin/aarch64-linux-gnu-gcc", | ||
"args": [ | ||
"-fdiagnostics-color=always", | ||
"-g", | ||
"${file}", | ||
"-o", | ||
"${fileDirname}/${fileBasenameNoExtension}" | ||
], | ||
"options": { | ||
"cwd": "${fileDirname}" | ||
}, | ||
"problemMatcher": [ | ||
"$gcc" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"detail": "调试器生成的任务。" | ||
} | ||
], | ||
"version": "2.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
BSD 2-Clause License | ||
|
||
Copyright (c) 2021, plctlab | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
SECTIONS = \ | ||
code/asm \ | ||
code/os \ | ||
|
||
.DEFAULT_GOAL := all | ||
all : | ||
@echo "begin compile ALL exercises for assembly samples ......................." | ||
for dir in $(SECTIONS); do $(MAKE) -C $$dir || exit "$$?"; done | ||
@echo "compile ALL exercises finished successfully! ......" | ||
|
||
.PHONY : clean | ||
clean: | ||
for dir in $(SECTIONS); do $(MAKE) -C $$dir clean || exit "$$?"; done | ||
|
||
.PHONY : slides | ||
slides: | ||
rm -f ./slides/*.pdf | ||
soffice --headless --convert-to pdf:writer_pdf_Export --outdir ./slides ./docs/ppts/*.pptx | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
**Step by step, learn to develop an operating system on RISC-V** | ||
|
||
<!-- TOC --> | ||
|
||
- [1. Introduction](#1-introduction) | ||
- [2. Operating environment](#2-operating-environment) | ||
- [3. Building and usage](#3-building-and-usage) | ||
- [4. References](#4-references) | ||
|
||
<!-- /TOC --> | ||
# 1. Introduction | ||
|
||
This course is used to teach and demonstrate how to write a simple operating system kernel for the RISC-V platform from scratch. Released under the BSD 2-Clause license (For details, please read the [LICENSE file](./LICENSE) under the root directory of this repository). | ||
|
||
If you have any questions or bug report, please use the issue tracking system on github. | ||
|
||
Note: We also have a mirror repository on gitee (<https://gitee.com/unicornx/riscv-operating-system-mooc>), and we use the issue tracking system on gitee more actively than on github, all issue# filled in git commitment are from the issue tracking system of gitee. | ||
|
||
# 2. Operating environment | ||
|
||
Ubuntu 20.04 is recommended. Ubuntu 20.04 is currently the latest recommended long-term stable release of Ubuntu. It is also the easiest to install and run the environment in this environment. | ||
|
||
Some students reported that they hope to still use Ubuntu 18.04. Because the official source of Ubunt 18.04 does not support the RISC-V development kit, so the environment is a little more complicated. I wrote a simple document, and you can refer [here ](./howto-run-with-ubuntu1804.md) to have a try with Ubuntu 18.04. | ||
|
||
All demo codes have been verified under the following environment. Please carefully check whether your Ubuntu version and kernel version are consistent with the following information. | ||
|
||
``` | ||
$ lsb_release -a | ||
No LSB modules are available. | ||
Distributor ID: Ubuntu | ||
Description: Ubuntu 20.04.3 LTS | ||
Release: 20.04 | ||
Codename: focal | ||
$ uname -r | ||
5.11.0-27-generic | ||
``` | ||
|
||
At present, in the Ubuntu 20.04 environment, we can directly use the official GNU toolchain and QEMU emulator, and execute the following command to install online to start the test: | ||
|
||
``` | ||
$ sudo apt update | ||
$ sudo apt install build-essential gcc make perl dkms git gcc-riscv64-unknown-elf gdb-multiarch qemu-system-misc | ||
``` | ||
|
||
# 3. Building and usage | ||
|
||
- `make`:Compile and build | ||
- `make run`:Start qemu and run | ||
- `make debug`:Start debugging | ||
- `make code`:Disassemble to view binary code | ||
- `make clean`:cleanup | ||
|
||
For specific use, please refer to the Makefile under the specific sub-project. | ||
|
||
# 4. References | ||
|
||
The design of this course refers to the following network resources, thank you :) | ||
|
||
- The Adventures of OS:<https://osblog.stephenmarz.com/index.html> | ||
- mini-riscv-os: <https://github.com/cccriscv/mini-riscv-os> | ||
- Xv6, a simple Unix-like teaching operating system:<https://pdos.csail.mit.edu/6.828/2020/xv6.html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
**循序渐进,学习开发一个 RISC-V 上的操作系统** | ||
|
||
<!-- TOC --> | ||
|
||
- [1. 简介](#1-简介) | ||
- [2. 运行环境](#2-运行环境) | ||
- [3. 构建和使用说明](#3-构建和使用说明) | ||
- [4. 参考文献](#4-参考文献) | ||
|
||
<!-- /TOC --> | ||
# 1. 简介 | ||
|
||
本课程用于教学演示如何从零开始为 RISC-V 平台编写一个简单的操作系统内核。采用 BSD 2-Clause 许可证发布(具体请阅读本仓库根目录下的 [LICENSE 文件](./LICENSE))。 | ||
|
||
如果您有任何的问题或者发现任何可疑的 bug,请通过 [Gitee 的 issue 跟踪系统](https://gitee.com/unicornx/riscv-operating-system-mooc/issues) 给我们提出报告,我们将第一时间检查并在系统中回复您。 | ||
|
||
**本课程的配套教学视频在线播放地址**: <https://www.bilibili.com/video/BV1Q5411w7z5> | ||
|
||
欢迎加入本课程的 **学习群**,边学习边讨论: | ||
|
||
- **QQ 学习群**,群号 976125506,或者扫码加入,见下: | ||
|
||
 | ||
|
||
- **微信学习群**,请添加微信 fangzhang1024 (标注 【汪辰老师】)加入。 | ||
|
||
# 2. 运行环境 | ||
|
||
推荐使用 Ubuntu 20.04,Ubuntu 20.04 是目前最新的 Ubuntu 长期稳定发行版,在这个环境下安装运行环境也最简单。 | ||
|
||
有些同学反映希望仍然使用Ubuntu 18.04,因为 Ubunt 18.04 的官方源还不支持 RISC-V 的开发工具包,所以搭建环境稍微复杂一些,我写了一个简单的说明文档,感兴趣的同学可以看 [这里](./howto-run-with-ubuntu1804_zh.md)。 | ||
|
||
所有演示代码在以下环境下验证通过,请仔细核对你的 Ubuntu 版本和内核版本与以下信息是否一致。 | ||
|
||
``` | ||
$ lsb_release -a | ||
No LSB modules are available. | ||
Distributor ID: Ubuntu | ||
Description: Ubuntu 20.04.3 LTS | ||
Release: 20.04 | ||
Codename: focal | ||
$ uname -r | ||
5.11.0-27-generic | ||
``` | ||
|
||
目前在 Ubuntu 20.04 环境下我们可以直接使用官方提供的 GNU工具链和 QEMU 模拟器,执行如下命令在线安装即可开始试验: | ||
|
||
``` | ||
$ sudo apt update | ||
$ sudo apt install build-essential gcc make perl dkms git gcc-riscv64-unknown-elf gdb-multiarch qemu-system-misc | ||
``` | ||
|
||
# 3. 构建和使用说明 | ||
|
||
- `make`:编译构建 | ||
- `make run`:启动 qemu 并运行 | ||
- `make debug`:启动调试 | ||
- `make code`:反汇编查看二进制代码 | ||
- `make clean`:清理 | ||
|
||
具体使用请参考具体子项目下的 Makefile 文件。 | ||
|
||
# 4. 参考文献 | ||
|
||
本课程的设计参考了如下网络资源,在此表示感谢 :) | ||
|
||
- The Adventures of OS:<https://osblog.stephenmarz.com/index.html> | ||
- mini-riscv-os: <https://github.com/cccriscv/mini-riscv-os> | ||
- Xv6, a simple Unix-like teaching operating system:<https://pdos.csail.mit.edu/6.828/2020/xv6.html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
include common.mk | ||
|
||
run: | ||
@${QEMU} -M ? | grep virt >/dev/null || exit | ||
@echo "Press Ctrl-A and then X to exit QEMU" | ||
@echo "------------------------------------" | ||
${CC} ${CFLAGS} -o os.elf hello.o | ||
${QEMU} ${QFLAGS} -kernel os.elf | ||
|
||
ubunturun: | ||
gcc -c hello.c -o hello.o | ||
|
||
|
||
.PHONY : run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
SECTIONS_Arithmetic = \ | ||
add \ | ||
add2 \ | ||
sub \ | ||
addi \ | ||
subi \ | ||
neg \ | ||
nop \ | ||
mv \ | ||
lui \ | ||
li | ||
|
||
SECTIONS_Logical = \ | ||
and \ | ||
andi \ | ||
not | ||
|
||
SECTIONS_Shifting = \ | ||
slli \ | ||
srli \ | ||
srai | ||
|
||
SECTIONS_Load_Store = \ | ||
lb \ | ||
lbu \ | ||
sb \ | ||
auipc \ | ||
la | ||
|
||
SECTIONS_Branch = \ | ||
bne | ||
|
||
SECTIONS_Jump = \ | ||
jalr \ | ||
|
||
SECTIONS_CallingConventions = \ | ||
cc_leaf \ | ||
cc_nested \ | ||
|
||
SECTIONS_others = \ | ||
asm2c \ | ||
c2asm | ||
|
||
SECTIONS = \ | ||
_first \ | ||
$(SECTIONS_Arithmetic) \ | ||
$(SECTIONS_Logical) \ | ||
$(SECTIONS_Shifting) \ | ||
$(SECTIONS_Load_Store) \ | ||
$(SECTIONS_Branch) \ | ||
$(SECTIONS_Jump) \ | ||
$(SECTIONS_CallingConventions) \ | ||
$(SECTIONS_others) | ||
|
||
.DEFAULT_GOAL := all | ||
all : | ||
@echo "begin compile ALL exercises for assembly samples ......................." | ||
for dir in $(SECTIONS); do $(MAKE) -C $$dir || exit "$$?"; done | ||
@echo "compile ALL exercises finished successfully! ......" | ||
|
||
.PHONY : clean | ||
clean: | ||
for dir in $(SECTIONS); do $(MAKE) -C $$dir clean || exit "$$?"; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../build.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# First RISC-V Assemble Sample | ||
|
||
.macro do_nothing # directive | ||
nop # pseudo-instruction | ||
nop # pseudo-instruction | ||
.endm # directive | ||
|
||
.text # directive | ||
.global _start # directive | ||
_start: # Label | ||
li x6, 5 # pseudo-instruction | ||
li x7, 4 # pseudo-instruction | ||
add x5, x6, x7 # instruction | ||
do_nothing # Calling macro | ||
stop: | ||
j stop # statement in one line | ||
|
||
.end # End of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../build.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.text | ||
.global _start | ||
array: | ||
.word 'h' | ||
.word 'e' | ||
.word 'l' | ||
.word 'l' | ||
.word 'o' | ||
.word 'w' | ||
.word 'o' | ||
.word 'r' | ||
.word 'l' | ||
.word 'd' | ||
.word '!' | ||
.word '\0' | ||
|
||
_start: | ||
li a0,0 | ||
la a1,array | ||
li a3,'\0' | ||
loop: | ||
addi a0,a0,1 | ||
lw a2,a1 | ||
addi a1,a1,4 | ||
bne a2, a3, _end # if t0 != t1 then target | ||
|
||
|
||
_end: | ||
j _end | ||
|
||
|
||
.end | ||
|
||
|
||
# char array[] = {'h', 'e', 'l', 'l', 'o', ',', 'w', 'o', 'r', 'l', 'd', '!', '\0'}; | ||
# int len = 0; | ||
# while (array[len] != '\0') { | ||
# len++; | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../build.mk |
Oops, something went wrong.