Source

Target

Commits (27)
Showing with 129821 additions and 68 deletions
+129821 -68
......@@ -6,16 +6,16 @@
将清华大学uCore/rCore/zCore教学系统移植到LoongArch平台上,并进行力所能及的优化。清华大学操作系统课程使用的教学系统,uCore为最早的C语言实现版本,rCore为使用rust语言重新实现的版本,支持x86/RISCV/ARM/MIPS等架构,zCore为谷歌微内核zircon的rust实现。
#### 前期调研情况分析
#### 调研情况分析
1. loongArch平台上有比较完善的工具链,可以支持rust的开发
2. loongArch的指令和mips、riscv相似,可以快速进行学习
3. 有过rcore的开发经验,项目可以进行
4. 有qemu模拟的龙芯平台可以进行虚拟实验
#### 与导师沟通情况
#### 项目目标
目前与老师交流了很多问题,都得到了老师耐心的回答,并且老师提供了丰富的资料。当前老师已经建立了微信群
根据硬件差异将`rCore`逐步迁移到`loongArch64`平台上,并撰写详细的实验手册,以期达到学习操作系统的同学可以熟悉如何在`loongArcch`平台上进行相关的实验,同时也将`rCore`扩展到新的平台
#### 目标规划:
......@@ -24,69 +24,111 @@ ch0:
- [x] 阅读LoongArch相关材料,熟悉相关指令和开发流程
- [x] 搭建交叉编译环境,调试linux系统的启动过程
- [x] 将Linux的启动过程的反汇编代码移植进入rCore
- [x] 完成串口输出功能
ch1:
- [ ] qemu模拟的LoongArch平台的关机功能
- [x] LoongArch的操作系统启动过程解析
- [x] 第一次进入操作系统
- [x] 完成串口输出功能
ch2:
- [x] LoongArch特权指令的使用
- [x] qemu模拟器的地址空间分布
- [x] 使用rust编写loongArch的寄存器支持
- [x] 特权级切换
- [x] 加载应用程序
ch3:
- [x] 中断
- [x] 多道程序共享
- [x] 计时器
- [x] buddy system allocator
- [x] 多道程序
- [x] 协作式多道程序
- [x] 分时多任务
- [x] 时钟
ch4:
- [ ] 页表
- [ ]
- [x] `buddy system allocator`
- [x] 三级页表
- [x] TLB管理
- [x] 地址空间
ch5:
- [x] 进程抽象
- [x] 地址空间切换
ch6:
........
- [x] PCI设备探测
- [x] ahci协议
- [x] 文件系统easy-fs
ch7:
- [x] 输入输出重定向
- [x] 管道
- [x] 信号
#### 当前开发状态说明
ch8:
已经可以成功的运行rcore的前两章代码,完成内核态与用户态的转换。添加LoonArch寄存器的支持,便于在内核代码中使用相关寄存器。目前正在开发第三章和第四章功能。
- [x] 内核态线程抽象
- [x] 信号量
- [x] 锁机制
- [x] 条件变量
其它:
- [x] 简易内核栈回溯`loongArch64`版本
- [x] 简易内核栈回溯`risc-v`版本
- [x] VESA BIOS Extensions 显示(初步)
#### 项目运行
项目存在许多分支,每一个分支均对应于某一章的全部或者一部分。项目的具体环境配置位于实验手册中。
```
进入loongrCore目录下
make run
make run #直接运行
make debug #gdb
```
运行截图:
![image-20220605235656760](sourcepicture/image-20220605235656760.png)
![](sourcepicture/run.gif)
#### 一些说明文件和实验过程:
[linker.md](linker.md)
要查看提供的教程,请进入rCoreloongArch目录,使用mdbook命令
[cross_tool.md](cross_tools.md)
```
mdbook serve --open
```
[manual.md](manual.md)
在线查看指导教程。
或者查看根目录下导出的**rCoreloongArch-tutorial.pdf**文件。
#### 其它仓库地址
https://github.com/Godones/rCoreloongArch
#### 未来
- [ ] 添加键盘、鼠标中断的完整支持
- [ ] 图形化显示
- [ ] 教程的细致化
#### 其它仓库地址
https://github.com/Godones/rCoreloongArch
#### 参考资源
* [QEMU模拟器](https://github.com/foxsen/qemu-loongarch-runenv)。可以在PC上模拟运行LoongArch架构的操作系统
* [关于LoongArch架构的工具链及文档](https://github.com/loongson)
* [相关OS信息](https://github.com/chyyuu/os_course_info)
* [VBE](https://en.wikipedia.org/wiki/VESA_BIOS_Extensions)
* [riscv os](https://blog.stephenmarz.com/category/os/)
# 龙芯平台交叉工具链
在进行实验之前,需要安装一些基本的工具和搭建实验环境。本实验需要在linux操作系统上进行。下面的操作均在wsl2下完成。
## Qemu的安装
```
git clone https://github.com/foxsen/qemu.git
git checkout loongarch-v2022-05-02
cd qemu
mkdir build
cd ./build/
../configure --target-list=loongarch64-softmmu --disable-werror (调试版本加--enable-debug)
make -j4
```
由于qemu官方的代码还没有龙芯平台的编译选项,因此需要从龙芯平台下载对应的分支进行编译。
注意在编译完成后可能仍然无法使用提示缺少相关的动态库,这时可自行上网查看相应的安装方法,对于缺失的库,其安装方式大都是相同的,只是在名字上有一点差异。
另一种方法: 在仓库中的`qemu-loongarch-runenv`中已经包含了基础的工具和uefi固件,若无法编译可使用此目录下的可执行文件,但其也存在缺少库的问题,解决方法同上。
## 安装GCC工具链
1. 下载[this gcc cross compiler](https://github.com/loongson/build-tools/releases/download/2021.12.21/loongarch64-clfs-2021-12-18-cross-tools-gcc-full.tar.xz) 到/opt/cross_tools目录
2. 解压gcc工具链
```
tar xzvf cross-tools-update.tar.gz
cd ./cross-tools-update
./update.sh
```
3. 解压rust工具链,上面给出的链接中包含rust工具
```
tar xzvf rust.tar.gz
sudo mv ./rust /opt
```
4. 设置环境变量
```
编辑~/.zshrc 加入export PATH=$PATH:/opt/cross-tools/bin:/opt/rust/bin
或者~/.bashrc
```
\ No newline at end of file
This diff is collapsed.
File added
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File moved
File moved
File added
File moved
File added
......@@ -132,3 +132,94 @@ TLB 表项的比较部分包括:
![image-20220707161012062](sourcepicture/image-20220707161012062.png)
# 第五章
### 问题1: 在用户程序`matrix`实现中,如果是如下的代码:
```rust
println!("pid {} is running ({} times)!.", getpid(), times);
```
则会造成页错误,如果改成如下的代码:
```rust
println!("yield began");
yield_();
println!("pid {} is running ({} times)!.", getpid(), times);
```
则会运行通过。
解决思路1: 在任务切换时是否正确进行了相关寄存器的设置?
实际效果: 以第一种代码为例,在设置正确寄存器后,虽然可以正常打印这句话,但是后面仍然会造成指令不存在的错误
解决思路2:删除掉第二中的添加的打印语句,改成如下的语句:
```rust
let mut i = 2;
yield_();
println!("pid {} is running ({} times {})!.", getpid(), times,i);
```
效果:
在这种情况下,将会发生访问的地址出现错误的情况,此时出错地址不在正常的地址空间中。
==debug过程:==
在TLB重填处理函数中将出错地址打印出来,通过观察,此地址应该属于内核区域,因此不会在对应的应用程序的地址空间找到对应的页表项。而应用程序这里出错的位置是打印函数`println`,因此推测可能是`print`函数实现有错误,再去查看rcore的源代码后发现`print/println`的实现确实有过更改,因此这里就暂时将实现修改,在测试后发现居然可以正常运行了,因此就需要仔细对比前后两者的实现了。
老版本实现:
```rust
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::print::_print(format_args!($($arg)*)));
}
#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}
```
新版本实现:
```rust
macro_rules! print {
($fmt: literal $(, $($arg: tt)+)?) => {
$crate::print::_print(format_args!($fmt $(, $($arg)+)?));
}
}
#[macro_export]
/// println string macro
macro_rules! println {
($fmt: literal $(, $($arg: tt)+)?) => {
$crate::print::_print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
}
}
```
两者实现差异:
todo!
通过再次测试,又发现当TLB重填处理过程单独出来时,仍然会造成其它错误,而当将TLB重填过程与之前的中断和异常处理的入口设置为同一个,这时又不会造成错误,因此这里也需要观察两个方法实现的差异。
todo!
### Rust template
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/easy-fs-fuse.iml" filepath="$PROJECT_DIR$/.idea/easy-fs-fuse.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
[package]
name = "easy-fs-fuse"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "3.0.14"
rand = "0.8.4"
easy-fs = {path = "../easy-fs"}
\ No newline at end of file