diff --git a/src/interrupts.rs b/src/interrupts.rs index 5348439..0070e25 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -4,12 +4,11 @@ use pic8259::ChainedPics; use spin; use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode}; -#[derive(Debug, Clone, Copy)] -#[repr(u8)] -pub enum InterruptIndex { - Timer = PIC_1_OFFSET, - Keyboard, -} +pub const PIC_1_OFFSET: u8 = 32; +pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8; + +pub static PICS: spin::Mutex = + spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) }); lazy_static! { static ref IDT: InterruptDescriptorTable = { @@ -28,6 +27,23 @@ lazy_static! { }; } +#[derive(Debug, Clone, Copy)] +#[repr(u8)] +pub enum InterruptIndex { + Timer = PIC_1_OFFSET, + Keyboard, +} + +impl InterruptIndex { + fn as_u8(self) -> u8 { + self as u8 + } + + fn as_usize(self) -> usize { + usize::from(self.as_u8()) + } +} + pub fn init_idt() { IDT.load(); } @@ -109,20 +125,4 @@ extern "x86-interrupt" fn page_fault_handler( fn test_breakpoint_exception() { // invoke a breakpoint exception x86_64::instructions::interrupts::int3(); -} - -pub const PIC_1_OFFSET: u8 = 32; -pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8; - -pub static PICS: spin::Mutex = - spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) }); - -impl InterruptIndex { - fn as_u8(self) -> u8 { - self as u8 - } - - fn as_usize(self) -> usize { - usize::from(self.as_u8()) - } -} +} \ No newline at end of file