summaryrefslogtreecommitdiff
path: root/kernel/src/interrupts/idt.rs
blob: 87f16c0c151c30cf18ce835781081edf9a8784d6 (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
use super::{exceptions, gdt, interrupts, Interrupts};
use lazy_static::lazy_static;
use x86_64::structures::idt::InterruptDescriptorTable;

lazy_static! {
    static ref IDT: InterruptDescriptorTable = {
        let mut idt = InterruptDescriptorTable::new();
        idt.breakpoint
            .set_handler_fn(exceptions::breakpoint_handler);
        idt.segment_not_present
            .set_handler_fn(exceptions::segment_not_present_handler);
        idt.general_protection_fault
            .set_handler_fn(exceptions::general_protection_fault_handler);
        unsafe {
            idt.double_fault
                .set_handler_fn(exceptions::double_fault_handler)
                .set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
            idt.page_fault
                .set_handler_fn(exceptions::page_fault_handler)
                .set_stack_index(gdt::PAGE_FAULT_IST_INDEX);
        }
        idt[Interrupts::Timer.as_usize()].set_handler_fn(interrupts::timer_handler);

        idt
    };
}

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