1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 08:26:17 +04:00

Fix root page table ptr/buffer.

This commit is contained in:
Yuhao Zhou 2019-04-06 20:26:10 +08:00
parent 1f8b73744c
commit 5e44304f74
6 changed files with 44 additions and 24 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -3,12 +3,21 @@ use rcore_memory::PAGE_SIZE;
use log::*; use log::*;
use crate::memory::{FRAME_ALLOCATOR, init_heap, MemoryAttr, MemorySet, Linear}; use crate::memory::{FRAME_ALLOCATOR, init_heap, MemoryAttr, MemorySet, Linear};
use crate::consts::{MEMORY_OFFSET, MEMORY_END, KERNEL_OFFSET}; use crate::consts::{MEMORY_OFFSET, MEMORY_END, KERNEL_OFFSET};
use crate::arch::paging::*;
/// Initialize the memory management module /// Initialize the memory management module
pub fn init() { pub fn init() {
// initialize heap and Frame allocator // initialize heap and Frame allocator
init_frame_allocator(); init_frame_allocator();
init_heap(); 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() { pub fn init_other() {

View File

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