Compare commits

...

2 Commits

Author SHA1 Message Date
9b5004bf81 feat(keyboard): add distinct module for keyboard
All checks were successful
continuous-integration/drone Build is passing
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-04-21 17:38:46 +02:00
ee6e6c49cc feat(pit): add tick counter
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-04-21 17:33:13 +02:00
3 changed files with 46 additions and 34 deletions

@ -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 pic8259::ChainedPics;
use crate::{print, println}; use crate::{println};
use lazy_static::lazy_static; pub use pit::{timer_interrupt_handler};
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1}; pub use keyboard::keyboard_interrupt_handler;
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 {
@ -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 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());
} }