Compare commits
No commits in common. "9b5004bf8108c7452ddc58a8874488ce17e1effa" and "d14ad3a912da850e5b45cf7aee1da188939b4d2c" have entirely different histories.
9b5004bf81
...
d14ad3a912
@ -1,34 +0,0 @@
|
|||||||
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,15 +1,20 @@
|
|||||||
use pic8259::ChainedPics;
|
use pic8259::ChainedPics;
|
||||||
use crate::{println};
|
use crate::{print, println};
|
||||||
pub use pit::{timer_interrupt_handler};
|
use lazy_static::lazy_static;
|
||||||
pub use keyboard::keyboard_interrupt_handler;
|
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;
|
||||||
|
|
||||||
pub mod pit;
|
pub mod pit;
|
||||||
pub mod keyboard;
|
|
||||||
|
|
||||||
pub const PIC_1_OFFSET: u8 = 32;
|
pub const PIC_1_OFFSET: u8 = 32;
|
||||||
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
||||||
|
|
||||||
|
|
||||||
|
pub const PS2_CONTROLLER_PORT: u16 = 0x60;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum InterruptIndex {
|
pub enum InterruptIndex {
|
||||||
@ -36,3 +41,27 @@ 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,16 +1,9 @@
|
|||||||
use super::{PICS, InterruptIndex};
|
use super::{PICS, InterruptIndex};
|
||||||
use x86_64::structures::idt::InterruptStackFrame;
|
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) {
|
pub extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||||
|
// print!(".");
|
||||||
unsafe {
|
unsafe {
|
||||||
TICKS += 1;
|
|
||||||
PICS.lock()
|
PICS.lock()
|
||||||
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
|
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user