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

Skip to content

Commit 2153567

Browse files
committed
swap kernel test passed on k210/qemu+rustsbi
1 parent f7df809 commit 2153567

File tree

8 files changed

+29
-4
lines changed

8 files changed

+29
-4
lines changed

bootloader/rustsbi-k210.bin

96 Bytes
Binary file not shown.

os/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ K210-SERIALPORT = /dev/ttyUSB0
1212
K210-BURNER = ../tools/kflash.py
1313

1414
# Disassembly
15-
DISASM ?= -d
15+
DISASM ?= -D
1616

1717
USER_DIR := ../user
1818
USER_BUILD := $(USER_DIR)/build
@@ -44,6 +44,9 @@ $(BIN_FILE): kernel
4444
asm:
4545
@$(OBJDUMP) $(DISASM) $(KERNEL_FILE) | less
4646

47+
asm-save:
48+
@$(OBJDUMP) $(DISASM) $(KERNEL_FILE) > asm
49+
4750
# 清理编译出的文件
4851
clean:
4952
@cargo clean

os/src/board/k210/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
pub const BOARD_MEMORY_END_ADDRESS: usize = 0x8060_0000;
44
pub const BOARD_KERNEL_HEAP_SIZE: usize = 0x30_0000;
5-
pub const BOARD_STACK_SIZE: usize = 0x8000;
6-
pub const BOARD_KERNEL_STACK_SIZE: usize = 0x8000;
5+
pub const BOARD_STACK_SIZE: usize = 0x8_0000;
6+
pub const BOARD_KERNEL_STACK_SIZE: usize = 0x8_0000;
77

88
pub const MMIO_INTERVALS: &[(usize, usize)] = &[
99
(0x0200_0000, 0x1000), /* CLINT */

os/src/interrupt/handler.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ pub fn handle_interrupt(context: &mut Context, scause: Scause, stval: usize) ->
5252
return processor.prepare_next_thread();
5353
}
5454
}
55+
//println!("into intr handle!");
56+
//println!("cause = {:?}", scause.cause());
5557
// 根据中断类型来处理,返回的 Context 必须位于放在内核栈顶
5658
match scause.cause() {
5759
// 断点中断(ebreak)
@@ -61,7 +63,10 @@ pub fn handle_interrupt(context: &mut Context, scause: Scause, stval: usize) ->
6163
// 缺页异常
6264
Trap::Exception(Exception::LoadPageFault)
6365
| Trap::Exception(Exception::StorePageFault)
64-
| Trap::Exception(Exception::InstructionPageFault) => page_fault(context, scause, stval),
66+
| Trap::Exception(Exception::InstructionPageFault)
67+
| Trap::Exception(Exception::LoadFault)
68+
| Trap::Exception(Exception::StoreFault)
69+
| Trap::Exception(Exception::InstructionFault) => page_fault(context, scause, stval),
6570
// 时钟中断
6671
Trap::Interrupt(Interrupt::SupervisorTimer) => supervisor_timer(context),
6772
// 外部中断(键盘输入)

os/src/main.rs

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

76+
{
77+
let mut processor = PROCESSOR.lock();
78+
println!("get processor!");
79+
let kernel_process = Process::new_kernel().unwrap();
80+
println!("kernel process created!");
81+
let thread = create_kernel_thread(kernel_process, test_page_fault as usize, None);
82+
println!("kernel thread created!");
83+
processor.add_thread(thread);
84+
println!("thread has been added!");
85+
}
86+
/*
7687
PROCESSOR.lock().add_thread(create_kernel_thread(
7788
Process::new_kernel().unwrap(),
7889
test_page_fault as usize,
7990
None,
8091
));
92+
*/
8193

8294
extern "C" {
8395
fn __restore(context: usize);

os/src/memory/mapping/mapping.rs

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

115+
println!("vpn = {}", vpn);
115116
// 建立映射,先检查是否有配额来分配新的物理页面
116117
if !self.mapped_pairs.full() {
118+
println!("not full, alloc a new frame");
117119
// 有配额,分配新的物理页面
118120
let mut frame = FRAME_ALLOCATOR.lock().alloc()?;
119121
// 更新页表
@@ -123,6 +125,7 @@ impl Mapping {
123125
// 保存
124126
self.mapped_pairs.push(vpn, frame, entry);
125127
} else {
128+
println!("full!");
126129
// 配额用完,改为在置换文件中分配一个页面
127130
let swap_page = SwapTracker::new()?;
128131
// 更新页表

os/src/process/process.rs

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

os/src/process/thread.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ 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);
6566

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

0 commit comments

Comments
 (0)