From 2627b216a18a1dbbd9ec486ce32bd61d9505c7cc Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 18 Jul 2019 03:28:55 -0700 Subject: [PATCH] Programmable Interrupt Controller --- Cargo.toml | 1 + src/interrupts.rs | 14 +++++++++++++- src/main.rs | 6 +----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 52f1a0e..0b77b42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ bootloader = "0.6.0" volatile = "0.2.6" spin = "0.5.0" x86_64 = "0.7.2" +pic8259_simple = "0.1.1" [dependencies.lazy_static] version = "1.3.0" diff --git a/src/interrupts.rs b/src/interrupts.rs index 3d70e98..991207c 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -1,9 +1,15 @@ use lazy_static::lazy_static; use x86_64::structures::idt::{InterruptStackFrame, InterruptDescriptorTable}; use crate::println; - +use pic8259_simple::ChainedPics; +use spin; use crate::gdt; +const PIC_1_OFFSET: u8 = 32; +const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8; +static PICS: spin::Mutex = + spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) }); + lazy_static! { static ref IDT: InterruptDescriptorTable = { let mut idt = InterruptDescriptorTable::new(); @@ -20,6 +26,12 @@ pub fn init_idt() { IDT.load(); } +pub fn initalize_pics() { + unsafe { + PICS.lock().initialize(); + } +} + extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) { println!("EXCEPTION - BREAKPOINT\n{:#?}", stack_frame); diff --git a/src/main.rs b/src/main.rs index 18f9035..459af83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ fn panic(info: &PanicInfo) -> !{ } pub fn init() { + interrupts::initalize_pics(); gdt::init(); interrupts::init_idt(); } @@ -24,11 +25,6 @@ pub fn init() { pub extern "C" fn _start() -> ! { init(); - fn yolo() { - yolo(); - } - - yolo(); for i in 1..10 {