Compare commits
2 Commits
d14ad3a912
...
9b5004bf81
Author | SHA1 | Date | |
---|---|---|---|
9b5004bf81 | |||
ee6e6c49cc |
34
src/interrupts/pic/keyboard.rs
Normal file
34
src/interrupts/pic/keyboard.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
||||
use lazy_static::lazy_static;
|
||||
use super::{PICS, InterruptIndex};
|
||||
use x86_64::instructions::port::Port;
|
||||
use spin::{self, Mutex};
|
||||
use crate::{print};
|
||||
use x86_64::structures::idt::{InterruptStackFrame};
|
||||
|
||||
pub const PS2_CONTROLLER_PORT: u16 = 0x60;
|
||||
|
||||
pub extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||
lazy_static! {
|
||||
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> = Mutex::new(
|
||||
Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore)
|
||||
);
|
||||
}
|
||||
|
||||
let mut keyboard = KEYBOARD.lock();
|
||||
let mut port = Port::new(PS2_CONTROLLER_PORT);
|
||||
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) => print!("{}", character),
|
||||
DecodedKey::RawKey(key) => print!("{:?}", key),
|
||||
}
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
PICS.lock()
|
||||
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
|
||||
}
|
||||
}
|
@ -1,20 +1,15 @@
|
||||
use pic8259::ChainedPics;
|
||||
use crate::{print, println};
|
||||
use lazy_static::lazy_static;
|
||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
||||
use x86_64::structures::idt::{InterruptStackFrame};
|
||||
use x86_64::instructions::port::Port;
|
||||
use spin::{self, Mutex};
|
||||
pub use pit::timer_interrupt_handler;
|
||||
use crate::{println};
|
||||
pub use pit::{timer_interrupt_handler};
|
||||
pub use keyboard::keyboard_interrupt_handler;
|
||||
|
||||
pub mod pit;
|
||||
pub mod keyboard;
|
||||
|
||||
pub const PIC_1_OFFSET: u8 = 32;
|
||||
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
||||
|
||||
|
||||
pub const PS2_CONTROLLER_PORT: u16 = 0x60;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(u8)]
|
||||
pub enum InterruptIndex {
|
||||
@ -41,27 +36,3 @@ pub fn init_pic() {
|
||||
}
|
||||
|
||||
|
||||
pub extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||
lazy_static! {
|
||||
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> = Mutex::new(
|
||||
Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore)
|
||||
);
|
||||
}
|
||||
|
||||
let mut keyboard = KEYBOARD.lock();
|
||||
let mut port = Port::new(PS2_CONTROLLER_PORT);
|
||||
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) => print!("{}", character),
|
||||
DecodedKey::RawKey(key) => print!("{:?}", key),
|
||||
}
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
PICS.lock()
|
||||
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,16 @@
|
||||
use super::{PICS, InterruptIndex};
|
||||
use x86_64::structures::idt::InterruptStackFrame;
|
||||
|
||||
static mut TICKS: u64 = 0;
|
||||
|
||||
pub fn gettick() -> u64 {
|
||||
unsafe { return TICKS }
|
||||
|
||||
}
|
||||
|
||||
pub extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||
// print!(".");
|
||||
unsafe {
|
||||
TICKS += 1;
|
||||
PICS.lock()
|
||||
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user