Translate error code and print cr2 register

This commit is contained in:
Philipp Oppermann
2016-08-03 16:39:34 +02:00
parent 69f1b58bb0
commit a9319ea83e

View File

@@ -85,13 +85,27 @@ extern "C" fn invalid_opcode_handler(stack_frame: *const ExceptionStackFrame)
loop {}
}
bitflags! {
flags PageFaultErrorCode: u64 {
const PROTECTION_VIOLATION = 1 << 0,
const CAUSED_BY_WRITE = 1 << 1,
const USER_MODE = 1 << 2,
const MALFORMED_TABLE = 1 << 3,
const INSTRUCTION_FETCH = 1 << 4,
}
}
extern "C" fn page_fault_handler(stack_frame: *const ExceptionStackFrame,
error_code: u64) -> !
{
use x86::controlregs;
unsafe {
print_error(format_args!(
"EXCEPTION: PAGE FAULT with error code {:?}\n{:#?}",
error_code, *stack_frame));
"EXCEPTION: PAGE FAULT while accessing {:#x}\
\nerror code: {:?}\n{:#?}",
controlregs::cr2(),
PageFaultErrorCode::from_bits(error_code).unwrap(),
*stack_frame));
}
loop {}
}