Add page fault handler to riscv 32.

master
lcy1996 6 years ago
parent f5acc273d7
commit 0a7ec18701

@ -72,6 +72,9 @@ pub extern fn rust_trap(tf: &mut TrapFrame) {
Trap::Interrupt(I::SupervisorTimer) => timer(), Trap::Interrupt(I::SupervisorTimer) => timer(),
Trap::Exception(E::IllegalInstruction) => illegal_inst(tf), Trap::Exception(E::IllegalInstruction) => illegal_inst(tf),
Trap::Exception(E::UserEnvCall) => syscall(tf), Trap::Exception(E::UserEnvCall) => syscall(tf),
Trap::Exception(E::LoadPageFault) => page_fault(tf),
Trap::Exception(E::StoreFault) => page_fault(tf),
Trap::Exception(E::InstructionPageFault) => page_fault(tf),
_ => ::trap::error(tf), _ => ::trap::error(tf),
} }
::trap::before_return(); ::trap::before_return();
@ -111,6 +114,24 @@ fn illegal_inst(tf: &mut TrapFrame) {
} }
} }
/*
* @param:
* TrapFrame: the Trapframe for the page fault exception
* @brief:
* process page fault exception
*/
fn page_fault(tf: &mut TrapFrame) {
let addr: usize;
// move stval(i.e. sbadaddr) to addr
addr = stval::read();
error!("\nEXCEPTION: Page Fault @ {:#x}", addr);
use memory::page_fault_handler;
if !page_fault_handler(addr) {
::trap::error(tf);
}
}
/// Migrate from riscv-pk /// Migrate from riscv-pk
/* /*
* @param: * @param:

@ -52,7 +52,14 @@ pub fn active_table() -> MutexGuard<'static, CowExt<ActivePageTable>> {
ACTIVE_TABLE.lock() ACTIVE_TABLE.lock()
} }
// Return true to continue, false to halt /*
* @param:
* addr: the virtual address of the page fault
* @brief:
* handle page fault
* @retval:
* Return true to continue, false to halt
*/
pub fn page_fault_handler(addr: usize) -> bool { pub fn page_fault_handler(addr: usize) -> bool {
// Handle copy on write // Handle copy on write
unsafe { ACTIVE_TABLE.force_unlock(); } unsafe { ACTIVE_TABLE.force_unlock(); }

Loading…
Cancel
Save