+#include "i386_intr.h"
+#include <lunaix/types.h>
+
+#define IDT_INTERRUPT 0x70
+#define KERNEL_CS 0x8
+#define IDT_ATTR(dpl, type) (((type) << 5) | ((dpl & 3) << 13) | (1 << 15))
+#define IDT_ENTRY 256
+
+#define DECLARE_ISR(iv) extern void _asm_isr##iv();
+
+#define ISR_INSTALL(idt, iv, isr) \
+ _idt[iv] = ((ptr_t)isr & 0xffff0000) | IDT_ATTR(0, IDT_INTERRUPT); \
+ _idt[iv] <<= 32; \
+ _idt[iv] |= (KERNEL_CS << 16) | ((ptr_t)isr & 0x0000ffff); \
+
+u64_t _idt[IDT_ENTRY];
+u16_t _idt_limit = sizeof(_idt) - 1;
+
+{% for isrdef in data["exception"] -%}
+ DECLARE_ISR({{ isrdef["index"] }})
+{% endfor %}
+
+void
+exception_install_handler()
+{
+{% for isrdef in data["exception"] %}
+ ISR_INSTALL(_idt, {{ isrdef["index"] }}, _asm_isr{{ isrdef["index"] }})
+{% endfor %}
+}
\ No newline at end of file