diff --git a/src/arch/riscv32/boot/entry.asm b/src/arch/riscv32/boot/entry.asm index 0a6898d..6c11050 100644 --- a/src/arch/riscv32/boot/entry.asm +++ b/src/arch/riscv32/boot/entry.asm @@ -8,6 +8,6 @@ kern_entry: .align 12 #PGSHIFT .global bootstack bootstack: - .space 4096 * 8 #KSTACKSIZE + .space 4096 * 16 #KSTACKSIZE .global bootstacktop bootstacktop: diff --git a/src/arch/riscv32/memory.rs b/src/arch/riscv32/memory.rs index 3f8b146..a3aaacc 100644 --- a/src/arch/riscv32/memory.rs +++ b/src/arch/riscv32/memory.rs @@ -11,8 +11,10 @@ pub fn init() { let frame = Frame::of_addr(PhysAddr::new(&PAGE_TABLE_ROOT as *const _ as u32)); super::paging::setup_page_table(frame); init_frame_allocator(); - remap_the_kernel(); + let ms = remap_the_kernel(); init_heap(); + use core::mem::forget; + forget(ms); } fn init_frame_allocator() { @@ -32,7 +34,7 @@ fn init_frame_allocator() { } } -fn remap_the_kernel() { +fn remap_the_kernel() -> MemorySet { use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE}; let kstack = Stack { top: bootstacktop as usize, @@ -47,6 +49,7 @@ fn remap_the_kernel() { ms.push(MemoryArea::new(KERNEL_HEAP_OFFSET, KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE, MemoryAttr::default(), "kernel_heap")); unsafe { ms.activate(); } info!("kernel remap end"); + ms } // Symbols provided by linker script diff --git a/src/arch/riscv32/mod.rs b/src/arch/riscv32/mod.rs index 02fd440..96f804a 100644 --- a/src/arch/riscv32/mod.rs +++ b/src/arch/riscv32/mod.rs @@ -11,6 +11,5 @@ pub fn init() { println!("Hello RISCV! {}", 123); interrupt::init(); memory::init(); -// timer::init(); - loop {} + timer::init(); } \ No newline at end of file diff --git a/src/arch/riscv32/paging.rs b/src/arch/riscv32/paging.rs index a1aff40..ffea89b 100644 --- a/src/arch/riscv32/paging.rs +++ b/src/arch/riscv32/paging.rs @@ -69,11 +69,12 @@ impl PageTable for ActivePageTable { } } +const ROOT_PAGE_TABLE: *mut RvPageTable = + (((RECURSIVE_PAGE_PML4 << 10) | (RECURSIVE_PAGE_PML4 + 1)) << 12) as *mut RvPageTable; + impl ActivePageTable { pub unsafe fn new() -> Self { - let root_addr = ((RECURSIVE_PAGE_PML4 << 10) | (RECURSIVE_PAGE_PML4 + 1)) << 12; - println!("{:x?}", &*(root_addr as *const RvPageTable)); - ActivePageTable(RecursivePageTable::new(&mut *(root_addr as *mut _)).unwrap()) + ActivePageTable(RecursivePageTable::new(&mut *ROOT_PAGE_TABLE).unwrap()) } fn with_temporary_map(&mut self, frame: &Frame, f: impl FnOnce(&mut ActivePageTable, &mut RvPageTable)) { // Create a temporary page @@ -177,6 +178,7 @@ impl InactivePageTable for InactivePageTable0 { debug!("switch table {:?} -> {:?}", old_frame, new_frame); if old_frame != new_frame { satp::set(satp::Mode::Sv32, 0, new_frame); + sfence_vma_all(); } } @@ -186,11 +188,13 @@ impl InactivePageTable for InactivePageTable0 { debug!("switch table {:?} -> {:?}", old_frame, new_frame); if old_frame != new_frame { satp::set(satp::Mode::Sv32, 0, new_frame); + sfence_vma_all(); } f(); debug!("switch table {:?} -> {:?}", new_frame, old_frame); if old_frame != new_frame { satp::set(satp::Mode::Sv32, 0, old_frame); + sfence_vma_all(); } } @@ -209,7 +213,7 @@ impl InactivePageTable for InactivePageTable0 { impl InactivePageTable0 { fn map_kernel(&mut self) { - let mut table = unsafe { &mut *(0xfffff000 as *mut RvPageTable) }; + let table = unsafe { &mut *ROOT_PAGE_TABLE }; let e1 = table[KERNEL_PML4].clone(); let e2 = table[KERNEL_PML4 + 1].clone(); self.edit(|_| { diff --git a/src/lib.rs b/src/lib.rs index d561b6b..7f72192 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,7 +95,7 @@ mod arch; #[cfg(target_arch = "riscv")] pub extern fn rust_main() -> ! { arch::init(); - memory::init_heap(); + println!("RISCV init end"); loop {} }