diff --git a/kernel/src/arch/riscv32/memory.rs b/kernel/src/arch/riscv32/memory.rs index 277423f..2ae895b 100644 --- a/kernel/src/arch/riscv32/memory.rs +++ b/kernel/src/arch/riscv32/memory.rs @@ -21,13 +21,7 @@ pub fn init() { */ #[cfg(not(feature = "no_mmu"))] pub fn init() { - #[repr(align(4096))] // align the PageData struct to 4096 bytes - struct PageData([u8; PAGE_SIZE]); - static PAGE_TABLE_ROOT: PageData = PageData([0; PAGE_SIZE]); - unsafe { sstatus::set_sum(); } // Allow user memory access - let frame = Frame::of_addr(PhysAddr::new(&PAGE_TABLE_ROOT as *const _ as usize)); - super::paging::setup_page_table(frame); // set up page table // initialize heap and Frame allocator init_frame_allocator(); init_heap(); @@ -70,10 +64,7 @@ fn init_frame_allocator() { } } -/* -* @brief: -* remmap the kernel memory address with 4K page recorded in p1 page table -*/ +/// Remap the kernel memory address with 4K page recorded in p1 page table #[cfg(not(feature = "no_mmu"))] fn remap_the_kernel() { let mut ms = MemorySet::new_bare(); diff --git a/kernel/src/arch/riscv32/mod.rs b/kernel/src/arch/riscv32/mod.rs index f874e5f..72dae42 100644 --- a/kernel/src/arch/riscv32/mod.rs +++ b/kernel/src/arch/riscv32/mod.rs @@ -9,6 +9,8 @@ pub mod cpu; #[no_mangle] pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize, functions: usize) -> ! { + // An initial recursive page table has been set by BBL (shared by all cores) + unsafe { cpu::set_cpu_id(hartid); } if hartid != 0 { diff --git a/kernel/src/arch/riscv32/paging.rs b/kernel/src/arch/riscv32/paging.rs index b9215ca..5ed075b 100644 --- a/kernel/src/arch/riscv32/paging.rs +++ b/kernel/src/arch/riscv32/paging.rs @@ -11,38 +11,6 @@ use ucore_memory::PAGE_SIZE; use ucore_memory::paging::*; use log::*; -/* -* @param: -* Frame: page table root frame -* @brief: -* setup page table in the frame -*/ -// need 1 page -#[cfg(target_arch = "riscv32")] -pub fn setup_page_table(frame: Frame) { - let p2 = unsafe { &mut *(frame.start_address().as_usize() as *mut RvPageTable) }; - p2.zero(); - p2.set_recursive(RECURSIVE_INDEX, frame.clone()); - - // Set kernel identity map - // 0x10000000 ~ 1K area - p2.map_identity(0x40, EF::VALID | EF::READABLE | EF::WRITABLE); - // 0x80000000 ~ 12M area - p2.map_identity(KERNEL_P2_INDEX, EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE); - p2.map_identity(KERNEL_P2_INDEX + 1, EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE); - p2.map_identity(KERNEL_P2_INDEX + 2, EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE); - - use riscv::register::satp; - unsafe { satp::set(satp::Mode::Sv32, 0, frame); } - sfence_vma_all(); - info!("setup init page table end"); -} - -#[cfg(target_arch = "riscv64")] -pub fn setup_page_table(_frame: Frame) { - unimplemented!(); -} - pub struct ActivePageTable(RecursivePageTable<'static>); pub struct PageEntry(PageTableEntry); diff --git a/riscv-pk b/riscv-pk index 71b2add..11fe816 160000 --- a/riscv-pk +++ b/riscv-pk @@ -1 +1 @@ -Subproject commit 71b2addd7ada2f07ca8e6f02787d706afa4fbe66 +Subproject commit 11fe816ca3b7745268e9322c51cd115d6059654e