summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/src/interrupts/exception_handlers.rs10
-rw-r--r--kernel/src/interrupts/idt.rs12
-rw-r--r--kernel/src/interrupts/mod.rs23
3 files changed, 41 insertions, 4 deletions
diff --git a/kernel/src/interrupts/exception_handlers.rs b/kernel/src/interrupts/exception_handlers.rs
index cd223bb..ef67eff 100644
--- a/kernel/src/interrupts/exception_handlers.rs
+++ b/kernel/src/interrupts/exception_handlers.rs
@@ -35,6 +35,16 @@ pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStac
}
}
+pub extern "x86-interrupt" fn div_zero_handler(stack_frame: &mut InterruptStackFrame) {
+ match get_expected_fault() {
+ InterruptType::DivZero => qemu::exit_qemu(qemu::QemuExitCode::Success),
+ _ => panic!(
+ "Divide by zero exception thrown\n\n{}",
+ exception_default!(stack_frame)
+ ),
+ }
+}
+
pub extern "x86-interrupt" fn general_protection_fault_handler(
stack_frame: &mut InterruptStackFrame,
error_code: u64,
diff --git a/kernel/src/interrupts/idt.rs b/kernel/src/interrupts/idt.rs
index 8cd01d0..3eb9724 100644
--- a/kernel/src/interrupts/idt.rs
+++ b/kernel/src/interrupts/idt.rs
@@ -5,8 +5,14 @@ use x86_64::structures::idt::InterruptDescriptorTable;
lazy_static! {
static ref IDT: InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new();
+ for i in 32..255 {
+ idt[i].set_handler_fn(dummy_handler);
+ }
+
idt.breakpoint
.set_handler_fn(exception_handlers::breakpoint_handler);
+ idt.divide_by_zero
+ .set_handler_fn(exception_handlers::div_zero_handler);
idt.segment_not_present
.set_handler_fn(exception_handlers::segment_not_present_handler);
idt.general_protection_fault
@@ -25,6 +31,12 @@ lazy_static! {
};
}
+pub extern "x86-interrupt" fn dummy_handler(
+ stack_frame: &mut x86_64::structures::idt::InterruptStackFrame,
+) {
+ panic!("unhandled interrupt recieved");
+}
+
pub fn init() {
IDT.load()
}
diff --git a/kernel/src/interrupts/mod.rs b/kernel/src/interrupts/mod.rs
index b39eb37..27993ec 100644
--- a/kernel/src/interrupts/mod.rs
+++ b/kernel/src/interrupts/mod.rs
@@ -9,15 +9,30 @@ const INT_OFFSET: u8 = 32;
#[repr(u8)]
#[derive(PartialEq, Clone, Copy)]
pub enum InterruptType {
- None,
- PageFault,
+ DivZero,
+ Debug,
+ NonMaskableInterrupt,
+ Breakpoint,
+ Overflow,
+ BountRange,
+ InvalidOptcode,
+ DeviceNotAvailable,
DoubleFault,
+ CoprocessorOverrun,
+ InvalidTTS,
NotPresent,
- Breakpoint,
+ StackSegmentFault,
GeneralProtectionFault,
-
+ PageFault,
+ x87Floating = 16,
+ AlignmentCheck,
+ MachineCheck,
+ SIMD,
+ Virtualization,
+ Security,
Timer = INT_OFFSET,
Keyboard = INT_OFFSET + 1,
+ None = 255,
}
impl InterruptType {