Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
volatile = "0.2.6"
spin = "0.5.2"
uart_16550 = "0.2.0"
pc-keyboard = "0.7.0"

[target.'cfg(target_arch = "x86_64")'.dependencies]
x86_64 = "0.14.2"
Expand All @@ -19,11 +20,15 @@ features = ["spin_no_std"]

[package.metadata.bootimage]
test-args = [
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio",
"-display", "none"
"-device",
"isa-debug-exit,iobase=0xf4,iosize=0x04",
"-serial",
"stdio",
"-display",
"none",
]
test-success-exit-code = 33 # (0x10 << 1) | 1
test-timeout = 300 # In seconds (5 minutes)
test-timeout = 300 # In seconds (5 minutes)

[[test]]
name = "should_panic"
Expand Down
50 changes: 50 additions & 0 deletions src/arch/amd64/interrupts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::arch::gdt;
use crate::print;
use crate::println;
use lazy_static::lazy_static;
use pic8259::ChainedPics;
Expand All @@ -15,6 +16,7 @@ pub static PICS: spin::Mutex<ChainedPics> =
#[repr(u8)]
pub enum InterruptIndex {
Timer = PIC_1_OFFSET,
Keyboard,
}

impl InterruptIndex {
Expand All @@ -37,6 +39,7 @@ lazy_static! {
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
}
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_usize()].set_handler_fn(keyboard_interrupt_handler);

idt
};
Expand All @@ -57,6 +60,53 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFr
}
}

extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
use spin::Mutex;
use x86_64::instructions::port::Port;
use lazy_static::lazy_static; // Make sure to import lazy_static

lazy_static! {
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> =
Mutex::new(Keyboard::new(
ScancodeSet1::new(),
layouts::Us104Key,
HandleControl::Ignore
));
}

let mut keyboard = KEYBOARD.lock();
let mut port = Port::new(0x60);

let scancode: u8 = unsafe { port.read() };
if let Ok(Some(key_event)) = keyboard.add_byte(scancode) {
if let Some(key) = keyboard.process_keyevent(key_event) {
match key {
DecodedKey::Unicode(character) => match character {
'\t' => print!(" "), // Print four spaces for tab
' ' => print!(" "), // Print space for spacebar
_ => print!("{}", character), // Print other characters as is
},
DecodedKey::RawKey(key) => {
match key {
pc_keyboard::KeyCode::LControl |
pc_keyboard::KeyCode::RControl |
pc_keyboard::KeyCode::LAlt |
pc_keyboard::KeyCode::RShift |
// Add other non-printable keys here
_ => (), // Do nothing for non-printable keys
}
}
}
}
}

unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
}
}

extern "x86-interrupt" fn double_fault_handler(
stack_frame: InterruptStackFrame,
_error_code: u64,
Expand Down