did interrupts stuff

This commit is contained in:
2025-02-22 03:19:05 +00:00
parent d12160c5d0
commit 2ee21dea05
10 changed files with 112 additions and 7 deletions
+78 -1
View File
@@ -1,18 +1,95 @@
use lib_ascii::println_log;
use lib_serial::serial_println;
use x86_64::instructions::port::Port;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
use spin::Lazy;
use pic8259::ChainedPics;
use spin::{Lazy, Mutex};
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
let mut idt = InterruptDescriptorTable::new();
idt.breakpoint.set_handler_fn(breakpoint_handler);
idt.double_fault.set_handler_fn(double_fault_handler);
idt.general_protection_fault
.set_handler_fn(general_protection_fault_handler);
idt[InterruptIndex::Timer.as_u8()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_u8()].set_handler_fn(keyboard_interrupt_handler);
idt
});
<<<<<<< Updated upstream
=======
pub const PIC_1_OFFSET: u8 = 32;
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
pub static PICS: Mutex<ChainedPics> =
Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
#[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())
}
}
>>>>>>> Stashed changes
pub fn init_idt() {
IDT.load();
unsafe {
PICS.lock().initialize();
PICS.lock().write_masks(0xfc, 0xff);
}
}
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
<<<<<<< Updated upstream
println_log!("Exception: Breakpoint\n{:#?}", stack_frame);
}
=======
serial_println!("Exception: Breakpoint\n{:#?}", stack_frame);
println_log!("Exception: Breakpoint\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn general_protection_fault_handler(
stack_frame: InterruptStackFrame,
_error_code: u64,
) {
serial_println!("Exception: General Protection Fault\n{:#?}", stack_frame);
panic!("Exception: General Protection Fault\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn double_fault_handler(
stack_frame: InterruptStackFrame,
_error_code: u64,
) -> ! {
serial_println!("Exception: Double Fault\n{:#?}", stack_frame);
panic!("Exception: Double Fault\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
let mut port = Port::new(0x60);
let _scancode: u8 = unsafe { port.read() };
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
}
}
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
}
}
>>>>>>> Stashed changes