Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rcore-os
RCore Tutorial V3
提交
5729debb
R
RCore Tutorial V3
项目概览
rcore-os
/
RCore Tutorial V3
上一次同步 1 年多
通知
15
Star
793
Fork
260
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RCore Tutorial V3
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5729debb
编写于
5月 20, 2022
作者:
chyyuu1972
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add cargo fmt in Makefile, and exec make fmt
上级
fdeaca9b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
39 addition
and
48 deletion
+39
-48
Makefile
Makefile
+2
-0
os/src/boards/k210.rs
os/src/boards/k210.rs
+0
-1
os/src/boards/qemu.rs
os/src/boards/qemu.rs
+0
-1
os/src/config.rs
os/src/config.rs
+0
-1
os/src/drivers/block/mod.rs
os/src/drivers/block/mod.rs
+2
-2
os/src/mm/memory_set.rs
os/src/mm/memory_set.rs
+15
-21
user/src/bin/early_exit.rs
user/src/bin/early_exit.rs
+4
-3
user/src/bin/stackful_coroutine.rs
user/src/bin/stackful_coroutine.rs
+16
-19
未找到文件。
Makefile
浏览文件 @
5729debb
...
...
@@ -6,3 +6,5 @@ docker:
build_docker
:
docker build
-t
${DOCKER_NAME}
.
fmt
:
cd
easy-fs
;
cargo
fmt
;
cd
../easy-fs-fuse cargo
fmt
;
cd
../os
;
cargo
fmt
;
cd
../user
;
cargo
fmt
;
cd
..
\ No newline at end of file
os/src/boards/k210.rs
浏览文件 @
5729debb
...
...
@@ -20,4 +20,3 @@ pub const MMIO: &[(usize, usize)] = &[
];
pub
type
BlockDeviceImpl
=
crate
::
drivers
::
block
::
SDCardWrapper
;
os/src/boards/qemu.rs
浏览文件 @
5729debb
...
...
@@ -3,4 +3,3 @@ pub const CLOCK_FREQ: usize = 12500000;
pub
const
MMIO
:
&
[(
usize
,
usize
)]
=
&
[(
0x10001000
,
0x1000
)];
pub
type
BlockDeviceImpl
=
crate
::
drivers
::
block
::
VirtIOBlock
;
os/src/config.rs
浏览文件 @
5729debb
...
...
@@ -11,4 +11,3 @@ pub const TRAMPOLINE: usize = usize::MAX - PAGE_SIZE + 1;
pub
const
TRAP_CONTEXT_BASE
:
usize
=
TRAMPOLINE
-
PAGE_SIZE
;
pub
use
crate
::
board
::{
CLOCK_FREQ
,
MMIO
};
os/src/drivers/block/mod.rs
浏览文件 @
5729debb
mod
sdcard
;
mod
virtio_blk
;
pub
use
virtio_blk
::
VirtIOBlock
;
pub
use
sdcard
::
SDCardWrapper
;
pub
use
virtio_blk
::
VirtIOBlock
;
use
crate
::
board
::
BlockDeviceImpl
;
use
alloc
::
sync
::
Arc
;
use
easy_fs
::
BlockDevice
;
use
lazy_static
::
*
;
use
crate
::
board
::
BlockDeviceImpl
;
lazy_static!
{
pub
static
ref
BLOCK_DEVICE
:
Arc
<
dyn
BlockDevice
>
=
Arc
::
new
(
BlockDeviceImpl
::
new
());
...
...
os/src/mm/memory_set.rs
浏览文件 @
5729debb
...
...
@@ -351,26 +351,20 @@ pub fn remap_test() {
let
mid_text
:
VirtAddr
=
((
stext
as
usize
+
etext
as
usize
)
/
2
)
.into
();
let
mid_rodata
:
VirtAddr
=
((
srodata
as
usize
+
erodata
as
usize
)
/
2
)
.into
();
let
mid_data
:
VirtAddr
=
((
sdata
as
usize
+
edata
as
usize
)
/
2
)
.into
();
assert
!
(
!
kernel_space
.page_table
.translate
(
mid_text
.floor
())
.unwrap
()
.writable
(),
);
assert
!
(
!
kernel_space
.page_table
.translate
(
mid_rodata
.floor
())
.unwrap
()
.writable
(),
);
assert
!
(
!
kernel_space
.page_table
.translate
(
mid_data
.floor
())
.unwrap
()
.executable
(),
);
assert
!
(
!
kernel_space
.page_table
.translate
(
mid_text
.floor
())
.unwrap
()
.writable
(),);
assert
!
(
!
kernel_space
.page_table
.translate
(
mid_rodata
.floor
())
.unwrap
()
.writable
(),);
assert
!
(
!
kernel_space
.page_table
.translate
(
mid_data
.floor
())
.unwrap
()
.executable
(),);
println!
(
"remap_test passed!"
);
}
user/src/bin/early_exit.rs
浏览文件 @
5729debb
...
...
@@ -5,11 +5,13 @@
extern
crate
user_lib
;
extern
crate
alloc
;
use
user_lib
::{
thread_create
,
exit
};
use
alloc
::
vec
::
Vec
;
use
user_lib
::{
exit
,
thread_create
};
pub
fn
thread_a
()
->
!
{
for
i
in
0
..
1000
{
print!
(
"{}"
,
i
);
}
for
i
in
0
..
1000
{
print!
(
"{}"
,
i
);
}
exit
(
1
)
}
...
...
@@ -19,4 +21,3 @@ pub fn main() -> i32 {
println!
(
"main thread exited."
);
exit
(
0
)
}
user/src/bin/stackful_coroutine.rs
浏览文件 @
5729debb
...
...
@@ -3,7 +3,6 @@
// https://github.com/cfsamson/example-greenthreads
#![no_std]
#![no_main]
#![feature(naked_functions)]
#![feature(asm)]
...
...
@@ -17,10 +16,10 @@ use core::arch::asm;
use
alloc
::
vec
;
use
alloc
::
vec
::
Vec
;
use
user_lib
::
{
exit
}
;
use
user_lib
::
exit
;
// In our simple example we set most constraints here.
const
DEFAULT_STACK_SIZE
:
usize
=
4096
;
//128 got SEGFAULT, 256(1024, 4096) got right results.
const
DEFAULT_STACK_SIZE
:
usize
=
4096
;
//128 got SEGFAULT, 256(1024, 4096) got right results.
const
MAX_TASKS
:
usize
=
5
;
static
mut
RUNTIME
:
usize
=
0
;
...
...
@@ -93,10 +92,7 @@ impl Runtime {
let
mut
available_tasks
:
Vec
<
Task
>
=
(
1
..
MAX_TASKS
)
.map
(|
i
|
Task
::
new
(
i
))
.collect
();
tasks
.append
(
&
mut
available_tasks
);
Runtime
{
tasks
,
current
:
0
,
}
Runtime
{
tasks
,
current
:
0
}
}
/// This is cheating a bit, but we need a pointer to our Runtime stored so we can call yield on it even if
...
...
@@ -110,9 +106,9 @@ impl Runtime {
/// This is where we start running our runtime. If it is our base task, we call yield until
/// it returns false (which means that there are no tasks scheduled) and we are done.
pub
fn
run
(
&
mut
self
){
while
self
.t_yield
()
{}
println!
(
"All tasks finished!"
);
pub
fn
run
(
&
mut
self
)
{
while
self
.t_yield
()
{}
println!
(
"All tasks finished!"
);
}
/// This is our return function. The only place we use this is in our `guard` function.
...
...
@@ -131,7 +127,7 @@ impl Runtime {
/// If we find a task that's ready to be run we change the state of the current task from `Running` to `Ready`.
/// Then we call switch which will save the current context (the old context) and load the new context
/// into the CPU which then resumes based on the context it was just passed.
///
///
/// NOITCE: if we comment below `#[inline(never)]`, we can not get the corrent running result
#[inline(never)]
fn
t_yield
(
&
mut
self
)
->
bool
{
...
...
@@ -200,10 +196,9 @@ impl Runtime {
// enough space to actually get an aligned pointer in the first place).
let
s_ptr
=
(
s_ptr
as
usize
&
!
7
)
as
*
mut
u8
;
available
.ctx.x1
=
guard
as
u64
;
//ctx.x1 is old return address
available
.ctx.nx1
=
f
as
u64
;
//ctx.nx2 is new return address
available
.ctx.x1
=
guard
as
u64
;
//ctx.x1 is old return address
available
.ctx.nx1
=
f
as
u64
;
//ctx.nx2 is new return address
available
.ctx.x2
=
s_ptr
.offset
(
-
32
)
as
u64
;
//cxt.x2 is sp
}
available
.state
=
State
::
Ready
;
}
...
...
@@ -264,9 +259,10 @@ pub fn yield_task() {
/// see: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
#[naked]
#[no_mangle]
unsafe
fn
switch
(
old
:
*
mut
TaskContext
,
new
:
*
const
TaskContext
)
{
unsafe
fn
switch
(
old
:
*
mut
TaskContext
,
new
:
*
const
TaskContext
)
{
// a0: _old, a1: _new
asm!
(
"
asm!
(
"
sd x1, 0x00(a0)
sd x2, 0x08(a0)
sd x8, 0x10(a0)
...
...
@@ -300,12 +296,13 @@ unsafe fn switch(old: *mut TaskContext, new: *const TaskContext) {
ld t0, 0x70(a1)
jr t0
"
,
options
(
noreturn
)
"
,
options
(
noreturn
)
);
}
#[no_mangle]
pub
fn
main
()
{
pub
fn
main
()
{
println!
(
"stackful_coroutine begin..."
);
println!
(
"TASK 0(Runtime) STARTING"
);
let
mut
runtime
=
Runtime
::
new
();
...
...
@@ -349,4 +346,4 @@ pub fn main() {
runtime
.run
();
println!
(
"stackful_coroutine PASSED"
);
exit
(
0
);
}
\ No newline at end of file
}
Miykael_xxm
🚴
@xiongjiamu
mentioned in commit
61b6d3b1
·
5月 22, 2022
mentioned in commit
61b6d3b1
mentioned in commit 61b6d3b17f9c3c7eb4bb2f14cf6ac46e721fcd7d
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录