01ab6391bd47d60d6cc26cc08a214da6b768c675
[lunaix-os.git] / lunaix-os / scripts / templates / i386 / i386_isrdef.c.j2
1 #include "i386_intr.h"
2 #include <lunaix/types.h>
3
4 #define IDT_INTERRUPT 0x70
5 #define KERNEL_CS 0x8
6 #define IDT_ATTR(dpl, type) (((type) << 5) | ((dpl & 3) << 13) | (1 << 15))
7 #define IDT_ENTRY 256
8
9 #define DECLARE_ISR(iv) extern void _asm_isr##iv();
10
11 #define ISR_INSTALL(idt, iv, isr)                                        \
12     _idt[iv] = ((ptr_t)isr & 0xffff0000) | IDT_ATTR(0, IDT_INTERRUPT);   \
13     _idt[iv] <<= 32;                                                     \
14     _idt[iv] |= (KERNEL_CS << 16) | ((ptr_t)isr & 0x0000ffff);           \
15
16 u64_t _idt[IDT_ENTRY];
17 u16_t _idt_limit = sizeof(_idt) - 1;
18
19 {% for isrdef in data["exception"] -%}
20     DECLARE_ISR({{ isrdef["index"] }})
21 {% endfor %}
22
23 void
24 exception_install_handler()
25 {
26 {% for isrdef in data["exception"] %}
27     ISR_INSTALL(_idt, {{ isrdef["index"] }}, _asm_isr{{ isrdef["index"] }})
28 {% endfor %}
29 }