From 59a7f07012d6aecc08d436cfd10111636c920871 Mon Sep 17 00:00:00 2001 From: Conzer Date: Tue, 3 Dec 2024 19:55:09 -0500 Subject: [PATCH] Enable base PICS (3h53m) --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/interrupts.rs | 10 +++++++++- src/lib.rs | 2 ++ src/main.rs | 3 +-- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1de5cb..107e2fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,6 +32,7 @@ version = "0.1.0" dependencies = [ "bootloader", "lazy_static", + "pic8259", "spin 0.5.2", "uart_16550", "volatile 0.2.7", @@ -47,6 +48,15 @@ dependencies = [ "spin 0.9.8", ] +[[package]] +name = "pic8259" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb844b5b01db1e0b17938685738f113bfc903846f18932b378bc0eabfa40e194" +dependencies = [ + "x86_64", +] + [[package]] name = "rustversion" version = "1.0.18" diff --git a/Cargo.toml b/Cargo.toml index a79ce8f..31a0bd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ volatile = "0.2.6" spin = "0.5.2" x86_64 = "0.14.2" uart_16550 = "0.2.0" +pic8259 = "0.10.1" [dependencies.lazy_static] version = "1.0" diff --git a/src/interrupts.rs b/src/interrupts.rs index c9f1da3..565a2c7 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -2,6 +2,8 @@ use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; use crate::println; use lazy_static::lazy_static; use crate::gdt; +use pic8259::ChainedPics; +use spin; lazy_static! { static ref IDT: InterruptDescriptorTable = { @@ -36,4 +38,10 @@ extern "x86-interrupt" fn double_fault_handler( fn test_breakpoint_exception() { // invoke a breakpoint exception x86_64::instructions::interrupts::int3(); -} \ No newline at end of file +} + +pub const PIC_1_OFFSET: u8 = 32; +pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8; + +pub static PICS: spin::Mutex = + spin::Mutex::new(unsafe {ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) }); diff --git a/src/lib.rs b/src/lib.rs index a28f671..29a1583 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ pub mod gdt; pub fn init() { gdt::init(); interrupts::init_idt(); + unsafe { interrupts::PICS.lock().initialize() }; + x86_64::instructions::interrupts::enable(); } use core::panic::PanicInfo; diff --git a/src/main.rs b/src/main.rs index b66d41a..25a985b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use donald::println; #[no_mangle] pub extern "C" fn _start() -> ! { println!("Hello World{}", "!"); - + println!("It did not crash!"); donald::init(); fn stack_overflow() { @@ -22,7 +22,6 @@ pub extern "C" fn _start() -> ! { #[cfg(test)] test_main(); - println!("It did not crash!"); loop {} }