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
Generated
+10
View File
@@ -11,6 +11,7 @@ dependencies = [
"lib_framebuffer", "lib_framebuffer",
"lib_serial", "lib_serial",
"limine", "limine",
"pic8259",
"spin", "spin",
"x86_64", "x86_64",
] ]
@@ -104,6 +105,15 @@ dependencies = [
"scopeguard", "scopeguard",
] ]
[[package]]
name = "pic8259"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62d9a86c292b165f757e47e7fd66855def189b2564609bc4203727b27c33db22"
dependencies = [
"x86_64",
]
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.19" version = "1.0.19"
+1 -1
View File
@@ -21,7 +21,7 @@ incremental = false
codegen-units = 1 codegen-units = 1
[profile.release] [profile.release]
opt-level = "z" opt-level = 3
debug = false debug = false
debug-assertions = false debug-assertions = false
overflow-checks = false overflow-checks = false
+1
View File
@@ -10,6 +10,7 @@ lib_serial = { path = "../lib/lib_serial" }
lib_ascii = { path = "../lib/lib_ascii" } lib_ascii = { path = "../lib/lib_ascii" }
x86_64 = "0.15.2" x86_64 = "0.15.2"
spin = "0.9.8" spin = "0.9.8"
pic8259 = "0.11.0"
[build-dependencies] [build-dependencies]
cc = "1.2.14" cc = "1.2.14"
+78 -1
View File
@@ -1,18 +1,95 @@
use lib_ascii::println_log; use lib_ascii::println_log;
use lib_serial::serial_println;
use x86_64::instructions::port::Port;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
use spin::Lazy; use pic8259::ChainedPics;
use spin::{Lazy, Mutex};
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| { static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
let mut idt = InterruptDescriptorTable::new(); let mut idt = InterruptDescriptorTable::new();
idt.breakpoint.set_handler_fn(breakpoint_handler); 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 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() { pub fn init_idt() {
IDT.load(); IDT.load();
unsafe {
PICS.lock().initialize();
PICS.lock().write_masks(0xfc, 0xff);
}
} }
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) { extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
<<<<<<< Updated upstream
println_log!("Exception: Breakpoint\n{:#?}", stack_frame); 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
+4
View File
@@ -1 +1,5 @@
<<<<<<< Updated upstream
=======
pub mod gdt;
>>>>>>> Stashed changes
pub mod interrupts; pub mod interrupts;
+6
View File
@@ -1,6 +1,7 @@
#![no_std] #![no_std]
#![feature(abi_x86_interrupt)] #![feature(abi_x86_interrupt)]
use arch::x86_64::interrupts;
use core::arch::asm; use core::arch::asm;
use limine::request::{RequestsEndMarker, RequestsStartMarker}; use limine::request::{RequestsEndMarker, RequestsStartMarker};
use limine::BaseRevision; use limine::BaseRevision;
@@ -54,5 +55,10 @@ pub fn boot() -> Result<(), &'static str> {
lib_serial::init()?; lib_serial::init()?;
arch::x86_64::interrupts::init_idt(); arch::x86_64::interrupts::init_idt();
<<<<<<< Updated upstream
=======
x86_64::instructions::interrupts::enable();
>>>>>>> Stashed changes
Ok(()) Ok(())
} }
+9 -2
View File
@@ -14,8 +14,6 @@ unsafe extern "C" fn kmain() -> ! {
let dimensions2 = lib_framebuffer::screensize_px(); let dimensions2 = lib_framebuffer::screensize_px();
println_log!(" [ Initialising ] "); println_log!(" [ Initialising ] ");
x86_64::instructions::interrupts::int3();
println!("Dimensions: {}x{} (px)", dimensions2.0, dimensions2.1); println!("Dimensions: {}x{} (px)", dimensions2.0, dimensions2.1);
println!("Dimensions: {}x{} (chars)", dimensions.0, dimensions.1); println!("Dimensions: {}x{} (chars)", dimensions.0, dimensions.1);
@@ -39,6 +37,15 @@ unsafe extern "C" fn kmain() -> ! {
\\______/ \\______/ \\_/ \\______| \\______/ \\______/ \\_/ \\______|
" "
); );
<<<<<<< Updated upstream
=======
// for i in 0..100000 {
// println!("{}", i);
// }
loop {}
>>>>>>> Stashed changes
FoundryOS::hcf(); FoundryOS::hcf();
} }