Finish memory init

master
WangRunji 7 years ago
parent 95ab3a2f3b
commit 7f659950cb

@ -8,6 +8,6 @@ kern_entry:
.align 12 #PGSHIFT
.global bootstack
bootstack:
.space 4096 * 8 #KSTACKSIZE
.space 4096 * 16 #KSTACKSIZE
.global bootstacktop
bootstacktop:

@ -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

@ -11,6 +11,5 @@ pub fn init() {
println!("Hello RISCV! {}", 123);
interrupt::init();
memory::init();
// timer::init();
loop {}
timer::init();
}

@ -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(|_| {

@ -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 {}
}

Loading…
Cancel
Save