mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Introduce an InterruptIndex enum (#557)
The following modifications aim to group the hardware interrupts' indexes in an easily accessible structure, while being more friendly to eventual evolutions. * the hardware interrupts' indexes `TIMER_INTERRUPT_ID` and `KEYBOARD_INTERRUPT_ID` have been replaced by the attributes `Timer` and `Keyboard` contained in `enum InterruptIndex`. * only the first attribute `Timer` is explicitly declared, the following as inferred by the compiler. * the functions `as_u8` and `as_usize` avoid the need of casts to `u8` or `usize`.
This commit is contained in:
committed by
Philipp Oppermann
parent
09ff2e01b1
commit
babf9d8cce
@@ -13,8 +13,17 @@ use x86_64::structures::idt::{ExceptionStackFrame, InterruptDescriptorTable};
|
|||||||
pub const PIC_1_OFFSET: u8 = 32;
|
pub const PIC_1_OFFSET: u8 = 32;
|
||||||
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
||||||
|
|
||||||
pub const TIMER_INTERRUPT_ID: u8 = PIC_1_OFFSET;
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub const KEYBOARD_INTERRUPT_ID: u8 = PIC_1_OFFSET + 1;
|
#[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 static PICS: spin::Mutex<ChainedPics> =
|
pub static PICS: spin::Mutex<ChainedPics> =
|
||||||
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
|
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
|
||||||
@@ -28,8 +37,8 @@ lazy_static! {
|
|||||||
.set_handler_fn(double_fault_handler)
|
.set_handler_fn(double_fault_handler)
|
||||||
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
||||||
}
|
}
|
||||||
idt[usize::from(TIMER_INTERRUPT_ID)].set_handler_fn(timer_interrupt_handler);
|
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
|
||||||
idt[usize::from(KEYBOARD_INTERRUPT_ID)].set_handler_fn(keyboard_interrupt_handler);
|
idt[InterruptIndex::Keyboard.as_usize()].set_handler_fn(keyboard_interrupt_handler);
|
||||||
idt
|
idt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -52,7 +61,7 @@ extern "x86-interrupt" fn double_fault_handler(
|
|||||||
|
|
||||||
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut ExceptionStackFrame) {
|
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut ExceptionStackFrame) {
|
||||||
print!(".");
|
print!(".");
|
||||||
unsafe { PICS.lock().notify_end_of_interrupt(TIMER_INTERRUPT_ID) }
|
unsafe { PICS.lock().notify_end_of_interrupt(InterruptIndex::Timer.as_u8()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut ExceptionStackFrame) {
|
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut ExceptionStackFrame) {
|
||||||
@@ -78,5 +87,5 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut Exceptio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe { PICS.lock().notify_end_of_interrupt(KEYBOARD_INTERRUPT_ID) }
|
unsafe { PICS.lock().notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8()) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user