summaryrefslogtreecommitdiff
path: root/kernel/src
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src')
-rw-r--r--kernel/src/interrupts/exceptions.rs66
-rw-r--r--kernel/src/interrupts/idt.rs (renamed from kernel/src/interrupts/table.rs)0
-rw-r--r--kernel/src/interrupts/mod.rs14
-rw-r--r--kernel/src/lib.rs2
4 files changed, 59 insertions, 23 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)
+ ),
+ }
}
diff --git a/kernel/src/interrupts/table.rs b/kernel/src/interrupts/idt.rs
index 9541f22..9541f22 100644
--- a/kernel/src/interrupts/table.rs
+++ b/kernel/src/interrupts/idt.rs
diff --git a/kernel/src/interrupts/mod.rs b/kernel/src/interrupts/mod.rs
index 14de3f2..4ff3c4d 100644
--- a/kernel/src/interrupts/mod.rs
+++ b/kernel/src/interrupts/mod.rs
@@ -1,3 +1,13 @@
-mod exceptions;
+pub mod exceptions;
pub mod gdt;
-pub mod table;
+pub mod idt;
+
+#[repr(usize)]
+#[derive(PartialEq, Clone, Copy)]
+pub enum Interrupts {
+ NONE,
+ PAGE_FAULT,
+ DOUBLE_FAULT,
+ NOT_PRESENT,
+ BREAKPOINT,
+}
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index 52d41ed..8ab660d 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -32,5 +32,5 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
pub fn init() {
interrupts::gdt::init();
- interrupts::table::init();
+ interrupts::idt::init();
}