Finish memory init

toolchain_update
WangRunji 7 years ago
parent 95ab3a2f3b
commit 7f659950cb

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

@ -11,8 +11,10 @@ pub fn init() {
let frame = Frame::of_addr(PhysAddr::new(&PAGE_TABLE_ROOT as *const _ as u32)); let frame = Frame::of_addr(PhysAddr::new(&PAGE_TABLE_ROOT as *const _ as u32));
super::paging::setup_page_table(frame); super::paging::setup_page_table(frame);
init_frame_allocator(); init_frame_allocator();
remap_the_kernel(); let ms = remap_the_kernel();
init_heap(); init_heap();
use core::mem::forget;
forget(ms);
} }
fn init_frame_allocator() { 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}; use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE};
let kstack = Stack { let kstack = Stack {
top: bootstacktop as usize, 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")); ms.push(MemoryArea::new(KERNEL_HEAP_OFFSET, KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE, MemoryAttr::default(), "kernel_heap"));
unsafe { ms.activate(); } unsafe { ms.activate(); }
info!("kernel remap end"); info!("kernel remap end");
ms
} }
// Symbols provided by linker script // Symbols provided by linker script

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

@ -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 { impl ActivePageTable {
pub unsafe fn new() -> Self { pub unsafe fn new() -> Self {
let root_addr = ((RECURSIVE_PAGE_PML4 << 10) | (RECURSIVE_PAGE_PML4 + 1)) << 12; ActivePageTable(RecursivePageTable::new(&mut *ROOT_PAGE_TABLE).unwrap())
println!("{:x?}", &*(root_addr as *const RvPageTable));
ActivePageTable(RecursivePageTable::new(&mut *(root_addr as *mut _)).unwrap())
} }
fn with_temporary_map(&mut self, frame: &Frame, f: impl FnOnce(&mut ActivePageTable, &mut RvPageTable)) { fn with_temporary_map(&mut self, frame: &Frame, f: impl FnOnce(&mut ActivePageTable, &mut RvPageTable)) {
// Create a temporary page // Create a temporary page
@ -177,6 +178,7 @@ impl InactivePageTable for InactivePageTable0 {
debug!("switch table {:?} -> {:?}", old_frame, new_frame); debug!("switch table {:?} -> {:?}", old_frame, new_frame);
if old_frame != new_frame { if old_frame != new_frame {
satp::set(satp::Mode::Sv32, 0, 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); debug!("switch table {:?} -> {:?}", old_frame, new_frame);
if old_frame != new_frame { if old_frame != new_frame {
satp::set(satp::Mode::Sv32, 0, new_frame); satp::set(satp::Mode::Sv32, 0, new_frame);
sfence_vma_all();
} }
f(); f();
debug!("switch table {:?} -> {:?}", new_frame, old_frame); debug!("switch table {:?} -> {:?}", new_frame, old_frame);
if old_frame != new_frame { if old_frame != new_frame {
satp::set(satp::Mode::Sv32, 0, old_frame); satp::set(satp::Mode::Sv32, 0, old_frame);
sfence_vma_all();
} }
} }
@ -209,7 +213,7 @@ impl InactivePageTable for InactivePageTable0 {
impl InactivePageTable0 { impl InactivePageTable0 {
fn map_kernel(&mut self) { 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 e1 = table[KERNEL_PML4].clone();
let e2 = table[KERNEL_PML4 + 1].clone(); let e2 = table[KERNEL_PML4 + 1].clone();
self.edit(|_| { self.edit(|_| {

@ -95,7 +95,7 @@ mod arch;
#[cfg(target_arch = "riscv")] #[cfg(target_arch = "riscv")]
pub extern fn rust_main() -> ! { pub extern fn rust_main() -> ! {
arch::init(); arch::init();
memory::init_heap(); println!("RISCV init end");
loop {} loop {}
} }

Loading…
Cancel
Save