Add a timer interrupt handler

This commit is contained in:
Philipp Oppermann
2019-01-25 14:09:12 +01:00
parent 28a11e47bc
commit 4060ac558c
2 changed files with 11 additions and 4 deletions

View File

@@ -3,15 +3,17 @@
// for a Windows system. // for a Windows system.
#![cfg(not(windows))] #![cfg(not(windows))]
use crate::{gdt, println}; use crate::{gdt, print, println};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use x86_64::structures::idt::{ExceptionStackFrame, InterruptDescriptorTable};
use pic8259_simple::ChainedPics; use pic8259_simple::ChainedPics;
use spin; use spin;
use x86_64::structures::idt::{ExceptionStackFrame, InterruptDescriptorTable};
pub const PIC_1_OFFSET: u8 = 32; pub const PIC_1_OFFSET: u8 = 32;
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8; pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
pub const TIMER_INTERRUPT_ID: u8 = PIC_1_OFFSET;
pub static PICS: spin::Mutex<ChainedPics> = pub static PICS: spin::Mutex<ChainedPics> =
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) }); spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
@@ -21,9 +23,11 @@ lazy_static! {
idt.breakpoint.set_handler_fn(breakpoint_handler); idt.breakpoint.set_handler_fn(breakpoint_handler);
idt.double_fault.set_handler_fn(double_fault_handler); idt.double_fault.set_handler_fn(double_fault_handler);
unsafe { unsafe {
idt.double_fault.set_handler_fn(double_fault_handler) idt.double_fault
.set_handler_fn(double_fault_handler)
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX); .set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
} }
idt[usize::from(TIMER_INTERRUPT_ID)].set_handler_fn(timer_interrupt_handler);
idt idt
}; };
} }
@@ -43,3 +47,7 @@ extern "x86-interrupt" fn double_fault_handler(
println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame); println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
loop {} loop {}
} }
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut ExceptionStackFrame) {
print!(".");
}

View File

@@ -21,7 +21,6 @@ pub extern "C" fn _start() -> ! {
loop {} loop {}
} }
/// This function is called on panic. /// This function is called on panic.
#[cfg(not(test))] #[cfg(not(test))]
#[panic_handler] #[panic_handler]