Fix root page table ptr/buffer.

master
Yuhao Zhou 6 years ago
parent 1f8b73744c
commit 5e44304f74

@ -5,7 +5,7 @@
.section .text.context
.globl switch_context
.extern root_page_table_ptr
.extern _root_page_table_ptr
switch_context:
// save from's registers
@ -25,7 +25,7 @@ switch_context:
sw ra, 12*4(sp)
sw sp, 13*4(sp)
la s0, root_page_table_ptr
la s0, _root_page_table_ptr
lw AT, 0(s0)
sw AT, 4(sp)

@ -158,9 +158,9 @@ kernel_stack:
kernel_stack_top:
.align 12 #PGSHIFT
.global root_page_table_buffer
root_page_table_buffer:
.global _root_page_table_buffer
_root_page_table_buffer:
.space 1024 * 4 # 4KB
.global root_page_table_ptr
root_page_table_ptr:
.global _root_page_table_ptr
_root_page_table_ptr:
.space 4 # 4bytes

@ -1,9 +1,5 @@
use mips::registers::cp0;
extern {
static root_page_table_ptr : *mut usize;
}
/// Saved registers on a trap.
#[derive(Clone)]
#[repr(C)]

@ -5,6 +5,7 @@ use crate::drivers::DRIVERS;
use mips::paging::{PageTable as MIPSPageTable, PageTableEntry, PageTableFlags as EF, TwoLevelPageTable};
use mips::addr::*;
pub use self::context::*;
use crate::arch::paging::get_root_page_table_ptr;
use log::*;
#[path = "context.rs"]
@ -131,10 +132,6 @@ fn syscall(tf: &mut TrapFrame) {
tf.v0 = ret as usize;
}
extern {
static root_page_table_ptr : *mut usize;
}
fn page_fault(tf: &mut TrapFrame) {
// TODO: set access/dirty bit
let addr = tf.vaddr;
@ -146,7 +143,7 @@ fn page_fault(tf: &mut TrapFrame) {
let virt_addr = VirtAddr::new(addr);
let root_table = unsafe {
&mut *(root_page_table_ptr as *mut MIPSPageTable)
&mut *(get_root_page_table_ptr() as *mut MIPSPageTable)
};
let tlb_entry = root_table.lookup(addr);
tlb::write_tlb_random(tlb_entry);

@ -3,12 +3,21 @@ use rcore_memory::PAGE_SIZE;
use log::*;
use crate::memory::{FRAME_ALLOCATOR, init_heap, MemoryAttr, MemorySet, Linear};
use crate::consts::{MEMORY_OFFSET, MEMORY_END, KERNEL_OFFSET};
use crate::arch::paging::*;
/// Initialize the memory management module
pub fn init() {
// initialize heap and Frame allocator
init_frame_allocator();
init_heap();
set_root_page_table_ptr(0xFFFF_FFFF);
extern "C" {
fn _root_page_table_buffer();
fn _root_page_table_ptr();
}
println!("_root_page_table_ptr {:x}", _root_page_table_ptr as usize);
}
pub fn init_other() {

@ -6,8 +6,6 @@ use mips::paging::{Mapper, PageTable as MIPSPageTable, PageTableEntry, PageTable
use mips::paging::{FrameAllocator, FrameDeallocator};
use rcore_memory::paging::*;
use log::*;
#[cfg(target_arch = "riscv32")]
use crate::consts::KERNEL_P2_INDEX;
pub struct ActivePageTable(TwoLevelPageTable<'static>, PageEntry);
@ -46,18 +44,38 @@ impl PageTable for ActivePageTable {
}
}
extern "C" {
fn _root_page_table_buffer();
fn _root_page_table_ptr();
}
pub fn set_root_page_table_ptr(ptr : usize) {
unsafe {
*(_root_page_table_ptr as *mut usize) = ptr;
}
}
pub fn get_root_page_table_ptr() -> usize {
unsafe {
*(_root_page_table_ptr as *mut usize)
}
}
pub fn root_page_table_buffer() -> &'static mut MIPSPageTable {
unsafe {
&mut *(_root_page_table_ptr as *mut MIPSPageTable)
}
}
impl PageTableExt for ActivePageTable {}
/// The virtual address of root page table
extern {
static root_page_table_buffer : *mut MIPSPageTable;
static root_page_table_ptr : *mut usize;
}
impl ActivePageTable {
pub unsafe fn new() -> Self {
ActivePageTable(
TwoLevelPageTable::new(&mut *(root_page_table_buffer as *mut MIPSPageTable)),
TwoLevelPageTable::new(root_page_table_buffer()),
::core::mem::uninitialized()
)
}
@ -123,11 +141,11 @@ impl InactivePageTable for InactivePageTable0 {
}
unsafe fn set_token(token: usize) {
*root_page_table_ptr = token;
set_root_page_table_ptr(token);
}
fn active_token() -> usize {
unsafe { *root_page_table_ptr }
get_root_page_table_ptr()
}
fn flush_tlb() {

Loading…
Cancel
Save