-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
353 changed files
with
47,318 additions
and
0 deletions.
There are no files selected for viewing
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,81 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
# Kernel Build Results | ||
obj/ | ||
bin/ | ||
|
||
# vim | ||
|
||
# Swap | ||
[._]*.s[a-v][a-z] | ||
!*.svg # comment out if you don't need vector files | ||
[._]*.sw[a-p] | ||
[._]s[a-rt-v][a-z] | ||
[._]ss[a-gi-z] | ||
[._]sw[a-p] | ||
|
||
# Session | ||
Session.vim | ||
Sessionx.vim | ||
|
||
# Temporary | ||
.netrwhist | ||
*~ | ||
# Auto-generated tag files | ||
tags | ||
# Persistent undo | ||
[._]*.un~ | ||
|
||
# Visual Studio Code | ||
.vscode/ |
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,3 @@ | ||
[submodule "riscv-pk"] | ||
path = riscv-pk | ||
url = https://github.com/riscv/riscv-pk.git |
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,44 @@ | ||
# 环境配置 | ||
关于环境配置可以在[这里](https://github.com/NKU-EmbeddedSystem/riscv64-ucore/blob/k210-lab0/README.md)找到 | ||
|
||
# 与运行在qemu上版本的代码改动 | ||
对每一处修改的说明: | ||
- [不包括终端的改动](https://github.com/Kirhhoff/riscv64-ucore/commit/82db2c9b26aff29d82aed49b53b5fd611d3e30d9) | ||
- [添加SD卡驱动](https://github.com/Kirhhoff/riscv64-ucore/commit/671c0baf00365361793694413ce2fb95bbc1813b) | ||
- [对终端的改动](https://github.com/Kirhhoff/riscv64-ucore/commit/7680ebb35c247c356f3846e88b57f37ee68ce4a8) | ||
|
||
### 添加低地址内核映射 | ||
初始内核页表(entry.S中hard code的部分)只设置了高地址的内存映射,而刚开启分页时,内核仍然运行在低地址,随后才跳转到高地址,因此低地址部分的内核映射是必要的。qemu模拟器对此没有要求,而对实际环境这是必须的。 | ||
|
||
### 对memlayout的修改 | ||
qemu版本使用opensbi作为bootloader,将控制权移交给内核时跳转地址为0x80200000,同时内核运行的起始虚拟地址为0xFFFFFFFFC0200000,模拟器模拟出的最大物理地址为0x88000000。k210版本使用rustsbi作为bootloader,跳转地址为0x80020000,内核运行的起始虚拟地址为0xFFFFFFFFC0020000,实际物理地址最大为0x80600000(见[k210规格说明书](https://s3.cn-north-1.amazonaws.com.cn/dl.kendryte.com/documents/kendryte_datasheet_20180919020633.pdf))。 | ||
|
||
因此,要修改两部分代码:一方面要修改memlayout中宏的定义,使得符号地址能够被正确计算;另一方面要修改linker script中的链接地址,使得代码运行的虚拟地址正确。 | ||
|
||
### 不同版本指令集带来的兼容性问题 | ||
risc-v ucore编写时基于[v1.11](https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMFDQC-and-Priv-v1.11/riscv-privileged-20190608.pdf)的特权指令集,而k210实现时基于[v1.9](https://people.eecs.berkeley.edu/~krste/papers/riscv-privileged-v1.9.1.pdf)的特权指令集,两者大体上相同,但对我们的代码产生了两处影响 | ||
- v1.11中sstatus寄存器的SUM bit设置时允许S-mode访问用户态地址,然而在v1.9中,这个bit代表PUM,设置时会反而禁止这样的访问,因此需要删除原本设置这一bit的语句,同时修改对这个位的宏名称。 | ||
- 相比于v1.11,v1.9没有定义sstatus的UXL位,在宏定义中删去这一项 | ||
|
||
### 对齐问题 | ||
risc-v对内存读写指令有着较强的对齐要求,如当读取8字节指令作用在仅4字节对齐的地址上时,会触发misalignment异常,而在qemu版本中用户态syscall的内联汇编使用了错误对齐的内存读写指令,会触发异常。对齐在模拟器中不是强制要求的,但在实际环境中是必须的。 | ||
|
||
### 初始化部分 | ||
qemu版本在初始化时有一个get_char操作,但在实际环境下会阻塞内核的正常运行,因此删去这条语句。 | ||
|
||
### 用户栈的对齐 | ||
在给用户态进程准备初始栈以及参数时,除argc外其他数据类型均为8字节长,最后位于栈顶的argc为4字节,这会导致控制权刚移交到用户态时的栈指针不是8字节对齐的,但用户态并不知道这一点,会默认刚进入用户态的初始状态为8字节对齐。因此这里使用一个trick在内核准备栈参数以及传递这个参数时临时使用8字节的long类型,而在umain移交给main时再将该类型cast回4字节的int,同时避免的截断(因为最开始类型为4字节)。 | ||
|
||
### SD卡驱动 | ||
默认booting时会尝试检测SD卡,如果存在且成功初始化则会打印: | ||
``` | ||
Successfully initialize SD card! | ||
``` | ||
失败或超时则打印: | ||
``` | ||
Fail to connect to SD card! | ||
``` | ||
初始化时默认**不会**进行读写测试,以防出现意料外的数据损失;也可以通过取消注释kern/driver/sdcard.c的sd_test来进行读写测试,这个测试会对倒数第10、9两个扇区备份后进行读写测试,然后恢复其数据,但仍可能会造成数据损失,因此需要谨慎。 | ||
|
||
### 控制台改动 | ||
qemu版本的控制台输入使用sbi调用来获得,在每个时钟tick时检查,并将其feed进缓冲区。实际环境中通过外部中断获得,这里注册外部中断handler需要使用rustsbi提供的ecall扩展,同时键盘中断通过UARTHS传递到处理器,在handler中通过其中断号来识别。另外,在中断handler中不能直接feed输入,而只将其放在缓冲区中,而在每个时钟tick才尝试唤醒等待io的进程,从而避免在handler中触发调度。 |
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,3 @@ | ||
target remote localhost:1234 | ||
break *0x00000000802000ea | ||
continue |
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,169 @@ | ||
cmake_minimum_required(VERSION 3.17) | ||
project(lab8 C) | ||
|
||
set(CMAKE_C_STANDARD 11) | ||
|
||
include_directories(.) | ||
include_directories(kern) | ||
include_directories(kern/debug) | ||
include_directories(kern/driver) | ||
include_directories(kern/fs) | ||
include_directories(kern/fs/devs) | ||
include_directories(kern/fs/sfs) | ||
include_directories(kern/fs/swap) | ||
include_directories(kern/fs/vfs) | ||
include_directories(kern/init) | ||
include_directories(kern/libs) | ||
include_directories(kern/mm) | ||
include_directories(kern/process) | ||
include_directories(kern/schedule) | ||
include_directories(kern/sync) | ||
include_directories(kern/syscall) | ||
include_directories(kern/trap) | ||
include_directories(libs) | ||
include_directories(tools) | ||
include_directories(user) | ||
include_directories(user/libs) | ||
|
||
add_executable(lab8 | ||
kern/debug/assert.h | ||
kern/debug/kdebug.c | ||
kern/debug/kdebug.h | ||
kern/debug/kmonitor.c | ||
kern/debug/kmonitor.h | ||
kern/debug/panic.c | ||
kern/debug/stab.h | ||
kern/driver/clock.c | ||
kern/driver/clock.h | ||
kern/driver/console.c | ||
kern/driver/console.h | ||
kern/driver/ide.c | ||
kern/driver/ide.h | ||
kern/driver/intr.c | ||
kern/driver/intr.h | ||
kern/driver/kbdreg.h | ||
kern/driver/picirq.c | ||
kern/driver/picirq.h | ||
kern/driver/ramdisk.c | ||
kern/driver/ramdisk.h | ||
kern/fs/devs/dev.c | ||
kern/fs/devs/dev.h | ||
kern/fs/devs/dev_disk0.c | ||
kern/fs/devs/dev_stdin.c | ||
kern/fs/devs/dev_stdout.c | ||
kern/fs/sfs/bitmap.c | ||
kern/fs/sfs/bitmap.h | ||
kern/fs/sfs/sfs.c | ||
kern/fs/sfs/sfs.h | ||
kern/fs/sfs/sfs_fs.c | ||
kern/fs/sfs/sfs_inode.c | ||
kern/fs/sfs/sfs_io.c | ||
kern/fs/sfs/sfs_lock.c | ||
kern/fs/swap/swapfs.c | ||
kern/fs/swap/swapfs.h | ||
kern/fs/vfs/inode.c | ||
kern/fs/vfs/inode.h | ||
kern/fs/vfs/vfs.c | ||
kern/fs/vfs/vfs.h | ||
kern/fs/vfs/vfsdev.c | ||
kern/fs/vfs/vfsfile.c | ||
kern/fs/vfs/vfslookup.c | ||
kern/fs/vfs/vfspath.c | ||
kern/fs/file.c | ||
kern/fs/file.h | ||
kern/fs/fs.c | ||
kern/fs/fs.h | ||
kern/fs/iobuf.c | ||
kern/fs/iobuf.h | ||
kern/fs/sysfile.c | ||
kern/fs/sysfile.h | ||
kern/init/init.c | ||
kern/libs/readline.c | ||
kern/libs/stdio.c | ||
kern/libs/string.c | ||
kern/mm/default_pmm.c | ||
kern/mm/default_pmm.h | ||
kern/mm/kmalloc.c | ||
kern/mm/kmalloc.h | ||
kern/mm/memlayout.h | ||
kern/mm/mmu.h | ||
kern/mm/pmm.c | ||
kern/mm/pmm.h | ||
kern/mm/swap.c | ||
kern/mm/swap.h | ||
kern/mm/swap_fifo.c | ||
kern/mm/swap_fifo.h | ||
kern/mm/vmm.c | ||
kern/mm/vmm.h | ||
kern/process/proc.c | ||
kern/process/proc.h | ||
kern/schedule/default_sched.h | ||
kern/schedule/default_sched_stride.c | ||
kern/schedule/sched.c | ||
kern/schedule/sched.h | ||
kern/sync/check_sync.c | ||
kern/sync/monitor.c | ||
kern/sync/monitor.h | ||
kern/sync/sem.c | ||
kern/sync/sem.h | ||
kern/sync/sync.h | ||
kern/sync/wait.c | ||
kern/sync/wait.h | ||
kern/syscall/syscall.c | ||
kern/syscall/syscall.h | ||
kern/trap/trap.c | ||
kern/trap/trap.h | ||
libs/atomic.h | ||
libs/defs.h | ||
libs/dirent.h | ||
libs/elf.h | ||
libs/error.h | ||
libs/hash.c | ||
libs/list.h | ||
libs/printfmt.c | ||
libs/rand.c | ||
libs/riscv.h | ||
libs/sbi.h | ||
libs/skew_heap.h | ||
libs/stat.h | ||
libs/stdarg.h | ||
libs/stdio.h | ||
libs/stdlib.h | ||
libs/string.c | ||
libs/string.h | ||
libs/unistd.h | ||
tools/mksfs.c | ||
tools/sign.c | ||
tools/vector.c | ||
user/libs/dir.c | ||
user/libs/dir.h | ||
user/libs/file.c | ||
user/libs/file.h | ||
user/libs/lock.h | ||
user/libs/panic.c | ||
user/libs/stdio.c | ||
user/libs/syscall.c | ||
user/libs/syscall.h | ||
user/libs/ulib.c | ||
user/libs/ulib.h | ||
user/libs/umain.c | ||
user/badarg.c | ||
user/badsegment.c | ||
user/divzero.c | ||
user/exit.c | ||
user/faultread.c | ||
user/faultreadkernel.c | ||
user/forktest.c | ||
user/forktree.c | ||
user/hello.c | ||
user/matrix.c | ||
user/pgdir.c | ||
user/priority.c | ||
user/sh.c | ||
user/sleep.c | ||
user/sleepkill.c | ||
user/softint.c | ||
user/spin.c | ||
user/testbss.c | ||
user/waitkill.c | ||
user/yield.c kern/driver/sdcard.h kern/driver/sdcard.c kern/driver/fpioa.h kern/driver/fpioa.c kern/driver/sysctl.h kern/driver/sysctl.c kern/driver/spi.h kern/driver/spi.c kern/driver/gpiohs.h kern/driver/gpiohs.c kern/driver/io.h libs/util.h kern/libs/util.c) |
Oops, something went wrong.