Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41b2e69

Browse files
committed
used mode swap test worked on qemu/k210+rustsbi
1 parent 2153567 commit 41b2e69

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

os/src/linker.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
OUTPUT_ARCH(riscv)
33
ENTRY(_start)
44

5-
BASE_ADDRESS = 0xffffffff80200000;
5+
BASE_ADDRESS = 0xffffffff80020000;
66

77
SECTIONS
88
{

os/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub extern "C" fn rust_main(_hart_id: usize, dtb_pa: PhysicalAddress) -> ! {
7373
crate::board::device_init(dtb_pa);
7474
fs::init();
7575

76+
/*
7677
{
7778
let mut processor = PROCESSOR.lock();
7879
println!("get processor!");
@@ -83,6 +84,8 @@ pub extern "C" fn rust_main(_hart_id: usize, dtb_pa: PhysicalAddress) -> ! {
8384
processor.add_thread(thread);
8485
println!("thread has been added!");
8586
}
87+
*/
88+
8689
/*
8790
PROCESSOR.lock().add_thread(create_kernel_thread(
8891
Process::new_kernel().unwrap(),
@@ -91,6 +94,8 @@ pub extern "C" fn rust_main(_hart_id: usize, dtb_pa: PhysicalAddress) -> ! {
9194
));
9295
*/
9396

97+
PROCESSOR.lock().add_thread(create_user_process("user_shell"));
98+
9499
extern "C" {
95100
fn __restore(context: usize);
96101
}

os/src/memory/mapping/mapping.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ impl Mapping {
112112
page_data
113113
};
114114

115-
println!("vpn = {}", vpn);
116115
// 建立映射,先检查是否有配额来分配新的物理页面
117116
if !self.mapped_pairs.full() {
118-
println!("not full, alloc a new frame");
119117
// 有配额,分配新的物理页面
120118
let mut frame = FRAME_ALLOCATOR.lock().alloc()?;
121119
// 更新页表
@@ -125,7 +123,6 @@ impl Mapping {
125123
// 保存
126124
self.mapped_pairs.push(vpn, frame, entry);
127125
} else {
128-
println!("full!");
129126
// 配额用完,改为在置换文件中分配一个页面
130127
let swap_page = SwapTracker::new()?;
131128
// 更新页表

os/src/process/process.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ impl Process {
6969
range.end += alloc_size;
7070
}
7171
// 分配物理页面,建立映射
72-
println!("start running stack mapping!");
7372
memory_set.add_segment(
7473
Segment {
7574
map_type: MapType::Framed,

os/src/process/thread.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ impl Thread {
6262
) -> MemoryResult<Arc<Thread>> {
6363
// 让所属进程分配并映射一段空间,作为线程的栈
6464
let stack = process.alloc_page_range(STACK_SIZE, Flags::READABLE | Flags::WRITABLE)?;
65-
println!("stack = {}, {}", stack.start, stack.end);
6665

6766
// 构建线程的 Context
6867
let context = Context::new(stack.end.into(), entry_point, arguments, process.is_user);

user/src/bin/swap_test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![no_std]
2+
#![no_main]
3+
#[macro_use]
4+
extern crate user_lib;
5+
6+
static mut array: [usize; 256 * 1024] = [0usize; 256 * 1024];
7+
#[no_mangle]
8+
pub unsafe fn main()->usize{
9+
for i in 0..array.len() {
10+
array[i] = i;
11+
}
12+
for i in 0..array.len() {
13+
assert_eq!(i, array[i]);
14+
}
15+
println!("\x1b[32mtest passed\x1b[0m");
16+
0
17+
}

0 commit comments

Comments
 (0)