Compare commits
2 Commits
290bb39216
...
d14ad3a912
Author | SHA1 | Date | |
---|---|---|---|
d14ad3a912 | |||
bdf28e38f4 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ iso
|
|||||||
julios
|
julios
|
||||||
.gdb_history
|
.gdb_history
|
||||||
peda-session-julios.txt
|
peda-session-julios.txt
|
||||||
|
*.swp
|
||||||
|
@ -1,39 +1,13 @@
|
|||||||
use crate::gdt;
|
use crate::gdt;
|
||||||
use crate::hlt_loop;
|
use crate::hlt_loop;
|
||||||
use crate::vga::{self, Color, ColorCode};
|
use crate::vga::{self, Color, ColorCode};
|
||||||
use crate::{print, println};
|
use crate::{println};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
|
||||||
use pic8259::ChainedPics;
|
|
||||||
use spin::{self, Mutex};
|
|
||||||
use x86_64::instructions::port::Port;
|
|
||||||
use x86_64::structures::idt::PageFaultErrorCode;
|
use x86_64::structures::idt::PageFaultErrorCode;
|
||||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||||
|
use pic::{InterruptIndex, init_pic, keyboard_interrupt_handler, timer_interrupt_handler};
|
||||||
|
|
||||||
pub const PIC_1_OFFSET: u8 = 32;
|
pub mod pic;
|
||||||
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 {
|
|
||||||
Timer = PIC_1_OFFSET,
|
|
||||||
Keyboard,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InterruptIndex {
|
|
||||||
fn as_u8(self) -> u8 {
|
|
||||||
self as u8
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_usize(self) -> usize {
|
|
||||||
usize::from(self.as_u8())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub static PICS: spin::Mutex<ChainedPics> =
|
|
||||||
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref IDT: InterruptDescriptorTable = {
|
static ref IDT: InterruptDescriptorTable = {
|
||||||
@ -55,8 +29,7 @@ pub fn init_idt() {
|
|||||||
println!("Loading IDT");
|
println!("Loading IDT");
|
||||||
IDT.load();
|
IDT.load();
|
||||||
|
|
||||||
println!("Initializing PIC");
|
init_pic();
|
||||||
unsafe { PICS.lock().initialize() };
|
|
||||||
|
|
||||||
println!("Enabling interrupts");
|
println!("Enabling interrupts");
|
||||||
x86_64::instructions::interrupts::enable();
|
x86_64::instructions::interrupts::enable();
|
||||||
@ -92,35 +65,4 @@ extern "x86-interrupt" fn double_fault_handler(
|
|||||||
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
|
||||||
// print!(".");
|
|
||||||
unsafe {
|
|
||||||
PICS.lock()
|
|
||||||
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
67
src/interrupts/pic/mod.rs
Normal file
67
src/interrupts/pic/mod.rs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
pub mod pit;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
Timer = PIC_1_OFFSET,
|
||||||
|
Keyboard,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InterruptIndex {
|
||||||
|
pub fn as_u8(self) -> u8 {
|
||||||
|
self as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_usize(self) -> usize {
|
||||||
|
usize::from(self.as_u8())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static PICS: spin::Mutex<ChainedPics> =
|
||||||
|
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
|
||||||
|
|
||||||
|
pub fn init_pic() {
|
||||||
|
println!("Initializing PIC");
|
||||||
|
unsafe { PICS.lock().initialize() };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
10
src/interrupts/pic/pit.rs
Normal file
10
src/interrupts/pic/pit.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
use super::{PICS, InterruptIndex};
|
||||||
|
use x86_64::structures::idt::InterruptStackFrame;
|
||||||
|
|
||||||
|
pub extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||||
|
// print!(".");
|
||||||
|
unsafe {
|
||||||
|
PICS.lock()
|
||||||
|
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user