summaryrefslogtreecommitdiff
path: root/kernel/src/interrupts/idt.rs
blob: c901916fdbd3d7b6ef7f3684889a5d6741488ddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use super::{exception_handlers, gdt, interrupt_handlers, InterruptType};
use lazy_static::lazy_static;
use x86_64::structures::idt::InterruptDescriptorTable;

lazy_static! {
    static ref IDT: InterruptDescriptorTable = {
        let mut idt = InterruptDescriptorTable::new();
        for i in 32..256 {
            idt[i].set_handler_fn(dummy_handler);
        }

        idt.breakpoint
            .set_handler_fn(exception_handlers::breakpoint_handler);
        idt.divide_by_zero
            .set_handler_fn(exception_handlers::div_zero_handler);
        idt.segment_not_present
            .set_handler_fn(exception_handlers::segment_not_present_handler);
        idt.general_protection_fault
            .set_handler_fn(exception_handlers::general_protection_fault_handler);
        unsafe {
            idt.double_fault
                .set_handler_fn(exception_handlers::double_fault_handler)
                .set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
            idt.page_fault
                .set_handler_fn(exception_handlers::page_fault_handler)
                .set_stack_index(gdt::PAGE_FAULT_IST_INDEX);
        }
        idt[InterruptType::Timer.as_usize()].set_handler_fn(interrupt_handlers::timer_handler);
        idt[InterruptType::Keyboard.as_usize()]
            .set_handler_fn(interrupt_handlers::keyboard_handler);

        idt
    };
}

pub extern "x86-interrupt" fn dummy_handler(
    stack_frame: &mut x86_64::structures::idt::InterruptStackFrame,
) {
    panic!("unhandled interrupt recieved");
}

pub fn init() {
    IDT.load()
}