From f6737b4b72b5eef7206e5061eb24908bcae11d7b Mon Sep 17 00:00:00 2001 From: Conzer Date: Tue, 3 Dec 2024 21:36:45 -0500 Subject: [PATCH] basic keyboard interrupt --- src/interrupts.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/interrupts.rs b/src/interrupts.rs index 2caf624..6ff253d 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -16,6 +16,9 @@ lazy_static! { } idt[InterruptIndex::Timer.as_usize()] .set_handler_fn(timer_interrupt_handler); + + idt[InterruptIndex::Keyboard.as_usize()] + .set_handler_fn(keyboard_interrupt_handler); idt }; @@ -53,6 +56,7 @@ pub static PICS: spin::Mutex = #[repr(u8)] pub enum InterruptIndex { Timer = PIC_1_OFFSET, + Keyboard, } impl InterruptIndex { @@ -74,4 +78,18 @@ extern "x86-interrupt" fn timer_interrupt_handler( PICS.lock() .notify_end_of_interrupt(InterruptIndex::Timer.as_u8()); } +} +extern "x86-interrupt" fn keyboard_interrupt_handler( + _stack_frame: InterruptStackFrame) +{ + use x86_64::instructions::port::Port; + + let mut port = Port::new(0x60); + let scancode: u8 = unsafe { port.read() }; + print!("{}", scancode); + + unsafe { + PICS.lock() + .notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8()); + } } \ No newline at end of file