Add keyboard interrupt handler

This commit is contained in:
greg 2019-07-18 10:32:50 -07:00
parent 8b262daa3c
commit 817a99d589

View File

@ -9,6 +9,7 @@ use crate::gdt;
#[repr(u8)] #[repr(u8)]
pub enum InterruptIndex { pub enum InterruptIndex {
Timer = PIC_1_OFFSET, Timer = PIC_1_OFFSET,
Keyboard,
} }
impl InterruptIndex { impl InterruptIndex {
@ -36,6 +37,8 @@ lazy_static! {
} }
idt[InterruptIndex::Timer.as_usize()] idt[InterruptIndex::Timer.as_usize()]
.set_handler_fn(timer_interrupt_handler); .set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_usize()]
.set_handler_fn(keyboard_interrupt_handler);
idt idt
}; };
} }
@ -68,3 +71,15 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut InterruptSt
PICS.lock().notify_end_of_interrupt(InterruptIndex::Timer.as_u8()) PICS.lock().notify_end_of_interrupt(InterruptIndex::Timer.as_u8())
} }
} }
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut InterruptStackFrame) {
use x86_64::instructions::port::Port;
let mut port = Port::new(0x60);
let scancode: u8 = unsafe { port.read() };
print!("k");
unsafe {
PICS.lock().notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8())
}
}