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