summaryrefslogtreecommitdiff
path: root/kernel/src/interrupts/exceptions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/interrupts/exceptions.rs')
-rw-r--r--kernel/src/interrupts/exceptions.rs66
1 files changed, 46 insertions, 20 deletions
diff --git a/kernel/src/interrupts/exceptions.rs b/kernel/src/interrupts/exceptions.rs
index 1e7680a..f6d5176 100644
--- a/kernel/src/interrupts/exceptions.rs
+++ b/kernel/src/interrupts/exceptions.rs
@@ -1,3 +1,5 @@
+use super::Interrupts;
+use crate::io::qemu;
use x86_64::structures::idt::{InterruptStackFrame, PageFaultErrorCode};
macro_rules! exception_default {
@@ -11,11 +13,26 @@ macro_rules! exception_default {
};
}
+static mut expected_fault: Interrupts = Interrupts::NONE;
+
+pub unsafe fn expect_fault(int: Interrupts) {
+ if expected_fault == Interrupts::NONE {
+ expected_fault = int;
+ }
+}
+
+fn get_expected_fault() -> Interrupts {
+ unsafe { expected_fault }
+}
+
pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) {
- panic!(
- "BREAKPOINT exception thrown\n\n{}",
- exception_default!(stack_frame)
- );
+ match get_expected_fault() {
+ Interrupts::BREAKPOINT => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ _ => panic!(
+ "BREAKPOINT exception thrown\n\n{}",
+ exception_default!(stack_frame)
+ ),
+ }
}
pub extern "x86-interrupt" fn page_fault_handler(
@@ -24,32 +41,41 @@ pub extern "x86-interrupt" fn page_fault_handler(
) {
use x86_64::registers::control::Cr2;
- panic!(
- "PAGE FAULT while accessing address: 0x{:08x}\nerror code: {:?}(0x{:x})\n{}",
- Cr2::read().as_u64(),
- error_code,
- error_code.bits(),
- exception_default!(stack_frame)
- );
+ match get_expected_fault() {
+ Interrupts::PAGE_FAULT => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ _ => panic!(
+ "PAGE FAULT while accessing address: 0x{:08x}\nerror code: {:?}(0x{:x})\n{}",
+ Cr2::read().as_u64(),
+ error_code,
+ error_code.bits(),
+ exception_default!(stack_frame)
+ ),
+ }
}
pub extern "x86-interrupt" fn segment_not_present_handler(
stack_frame: &mut InterruptStackFrame,
error_code: u64,
) {
- panic!(
- "SEGMENT NOT PRESENT exception\nerror code: 0x{:x}\n{}",
- error_code,
- exception_default!(stack_frame)
- );
+ match get_expected_fault() {
+ Interrupts::NOT_PRESENT => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ _ => panic!(
+ "SEGMENT NOT PRESENT exception\nerror code: 0x{:x}\n{}",
+ error_code,
+ exception_default!(stack_frame)
+ ),
+ }
}
pub extern "x86-interrupt" fn double_fault_handler(
stack_frame: &mut InterruptStackFrame,
_error_code: u64, // code is always zero
) {
- panic!(
- "DOUBLE FAULT\nthis is a fatal exception\n{}",
- exception_default!(stack_frame)
- );
+ match get_expected_fault() {
+ Interrupts::NOT_PRESENT => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ _ => panic!(
+ "DOUBLE FAULT\nthis is a fatal exception\n{}",
+ exception_default!(stack_frame)
+ ),
+ }
}