Handle timer interrupt
This commit is contained in:
parent
2627b216a1
commit
0b8cd65458
@ -5,6 +5,22 @@ use pic8259_simple::ChainedPics;
|
||||
use spin;
|
||||
use crate::gdt;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[repr(u8)]
|
||||
pub enum InterruptIndex {
|
||||
Timer = PIC_1_OFFSET,
|
||||
}
|
||||
|
||||
impl InterruptIndex {
|
||||
fn as_u8(self) -> u8 {
|
||||
self as u8
|
||||
}
|
||||
fn as_usize(self) -> usize {
|
||||
usize::from(self as u8)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const PIC_1_OFFSET: u8 = 32;
|
||||
const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
||||
static PICS: spin::Mutex<ChainedPics> =
|
||||
@ -18,10 +34,14 @@ lazy_static! {
|
||||
idt.double_fault.set_handler_fn(double_fault_handler)
|
||||
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
||||
}
|
||||
idt[InterruptIndex::Timer.as_usize()]
|
||||
.set_handler_fn(timer_interrupt_handler);
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn init_idt() {
|
||||
IDT.load();
|
||||
}
|
||||
@ -30,6 +50,7 @@ pub fn initalize_pics() {
|
||||
unsafe {
|
||||
PICS.lock().initialize();
|
||||
}
|
||||
x86_64::instructions::interrupts::enable();
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) {
|
||||
@ -40,3 +61,10 @@ extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFra
|
||||
extern "x86-interrupt" fn double_fault_handler(stack_frame: &mut InterruptStackFrame, code: u64) {
|
||||
panic!("EXCEPTION - DOUBLE FAULT (code {})\n{:#?}", code, stack_frame);
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut InterruptStackFrame) {
|
||||
print!(".");
|
||||
unsafe {
|
||||
PICS.lock().notify_end_of_interrupt(InterruptIndex::Timer.as_u8())
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,10 @@ pub extern "C" fn _start() -> ! {
|
||||
for i in 1..10 {
|
||||
println!("Gamarjoba, munde: {}", i);
|
||||
}
|
||||
loop {}
|
||||
loop {
|
||||
for _ in 0..100_000 {
|
||||
}
|
||||
print!("-");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,10 @@ macro_rules! println {
|
||||
#[doc(hidden)]
|
||||
pub fn _print(args: fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
WRITER.lock().write_fmt(args).unwrap();
|
||||
use x86_64::instructions::interrupts;
|
||||
interrupts::without_interrupts(|| {
|
||||
WRITER.lock().write_fmt(args).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
Loading…
Reference in New Issue
Block a user