Fix RV32 multi-core: Setup page table for other cores.

master
WangRunji 6 years ago
parent e5a196c00f
commit ba4a24ba3b

@ -1,4 +1,4 @@
use core::slice; use core::{slice, mem};
use memory::{active_table, FRAME_ALLOCATOR, init_heap, MemoryArea, MemoryAttr, MemorySet}; use memory::{active_table, FRAME_ALLOCATOR, init_heap, MemoryArea, MemoryAttr, MemorySet};
use super::riscv::{addr::*, register::sstatus}; use super::riscv::{addr::*, register::sstatus};
use ucore_memory::PAGE_SIZE; use ucore_memory::PAGE_SIZE;
@ -16,6 +16,13 @@ pub fn init() {
remap_the_kernel(); remap_the_kernel();
} }
pub fn init_other() {
unsafe {
sstatus::set_sum(); // Allow user memory access
asm!("csrw 0x180, $0; sfence.vma" :: "r"(SATP) :: "volatile");
}
}
fn init_frame_allocator() { fn init_frame_allocator() {
use bit_allocator::BitAlloc; use bit_allocator::BitAlloc;
use core::ops::Range; use core::ops::Range;
@ -42,11 +49,15 @@ fn remap_the_kernel() {
ms.push(MemoryArea::new_identity(srodata as usize, erodata as usize, MemoryAttr::default().readonly(), "rodata")); ms.push(MemoryArea::new_identity(srodata as usize, erodata as usize, MemoryAttr::default().readonly(), "rodata"));
ms.push(MemoryArea::new_identity(sbss as usize, ebss as usize, MemoryAttr::default(), "bss")); ms.push(MemoryArea::new_identity(sbss as usize, ebss as usize, MemoryAttr::default(), "bss"));
unsafe { ms.activate(); } unsafe { ms.activate(); }
use core::mem::forget; unsafe { SATP = ms.token(); }
forget(ms); mem::forget(ms);
info!("kernel remap end"); info!("kernel remap end");
} }
// First core stores its SATP here.
// Other cores load it later.
static mut SATP: usize = 0;
// Symbols provided by linker script // Symbols provided by linker script
extern { extern {
fn stext(); fn stext();

@ -35,6 +35,7 @@ pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize) -> ! {
fn others_main() -> ! { fn others_main() -> ! {
interrupt::init(); interrupt::init();
memory::init_other();
timer::init(); timer::init();
::kmain(); ::kmain();
} }

Loading…
Cancel
Save