From 817a99d589dd28487052f696ef596c60f9b2647e Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 18 Jul 2019 10:32:50 -0700 Subject: [PATCH] Add keyboard interrupt handler --- src/interrupts.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/interrupts.rs b/src/interrupts.rs index 5825b09..84a198d 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -9,6 +9,7 @@ use crate::gdt; #[repr(u8)] pub enum InterruptIndex { Timer = PIC_1_OFFSET, + Keyboard, } impl InterruptIndex { @@ -36,6 +37,8 @@ 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 }; } @@ -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()) } } + +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()) + } +}