diff options
-rw-r--r-- | kernel/src/interrupts/idt.rs | 16 | ||||
-rw-r--r-- | kernel/src/interrupts/interrupts.rs | 8 | ||||
-rw-r--r-- | kernel/src/interrupts/mod.rs | 18 |
3 files changed, 34 insertions, 8 deletions
diff --git a/kernel/src/interrupts/idt.rs b/kernel/src/interrupts/idt.rs index e85ef5a..87f16c0 100644 --- a/kernel/src/interrupts/idt.rs +++ b/kernel/src/interrupts/idt.rs @@ -1,3 +1,4 @@ +use super::{exceptions, gdt, interrupts, Interrupts}; use lazy_static::lazy_static; use x86_64::structures::idt::InterruptDescriptorTable; @@ -5,19 +6,20 @@ lazy_static! { static ref IDT: InterruptDescriptorTable = { let mut idt = InterruptDescriptorTable::new(); idt.breakpoint - .set_handler_fn(super::exceptions::breakpoint_handler); + .set_handler_fn(exceptions::breakpoint_handler); idt.segment_not_present - .set_handler_fn(super::exceptions::segment_not_present_handler); + .set_handler_fn(exceptions::segment_not_present_handler); idt.general_protection_fault - .set_handler_fn(super::exceptions::general_protection_fault_handler); + .set_handler_fn(exceptions::general_protection_fault_handler); unsafe { idt.double_fault - .set_handler_fn(super::exceptions::double_fault_handler) - .set_stack_index(super::gdt::DOUBLE_FAULT_IST_INDEX); + .set_handler_fn(exceptions::double_fault_handler) + .set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX); idt.page_fault - .set_handler_fn(super::exceptions::page_fault_handler) - .set_stack_index(super::gdt::PAGE_FAULT_IST_INDEX); + .set_handler_fn(exceptions::page_fault_handler) + .set_stack_index(gdt::PAGE_FAULT_IST_INDEX); } + idt[Interrupts::Timer.as_usize()].set_handler_fn(interrupts::timer_handler); idt }; diff --git a/kernel/src/interrupts/interrupts.rs b/kernel/src/interrupts/interrupts.rs new file mode 100644 index 0000000..6296375 --- /dev/null +++ b/kernel/src/interrupts/interrupts.rs @@ -0,0 +1,8 @@ +use super::Interrupts; +use crate::io::qemu; +use x86_64::structures::idt::{InterruptStackFrame, PageFaultErrorCode}; + +pub extern "x86-interrupt" fn timer_handler(stack_frame: &mut InterruptStackFrame) { + panic!("Timer interrupt recieved\n\n") + // notify End of interrupt +} diff --git a/kernel/src/interrupts/mod.rs b/kernel/src/interrupts/mod.rs index 087a59c..076c61c 100644 --- a/kernel/src/interrupts/mod.rs +++ b/kernel/src/interrupts/mod.rs @@ -1,8 +1,11 @@ pub mod exceptions; pub mod gdt; pub mod idt; +pub mod interrupts; -#[repr(usize)] +const INT_OFFSET: u8 = 32; + +#[repr(u8)] #[derive(PartialEq, Clone, Copy)] pub enum Interrupts { None, @@ -11,4 +14,17 @@ pub enum Interrupts { NotPresent, Breakpoint, GeneralProtectionFault, + + Timer = INT_OFFSET, + Keyboard = INT_OFFSET + 1, +} + +impl Interrupts { + fn as_u8(self) -> u8 { + self as u8 + } + + fn as_usize(self) -> usize { + usize::from(self.as_u8()) + } } |