Architectural Support: x86_64 (#37)
[lunaix-os.git] / lunaix-os / arch / x86 / exceptions / isrdef.c
1 /* Generated from i386_isrdef.c.j2. Do NOT modify */
2
3 #include <lunaix/types.h>
4 #include "sys/int_handler.h"
5 #include "sys/vectors.h"
6 #include "sys/x86_isa.h"
7
8 #define IDT_INTERRUPT 0x70
9 #define IDT_ATTR(dpl, type) (((type) << 5) | ((dpl & 3) << 13) | (1 << 15))
10 #define IDT_ENTRY 256
11
12 #define __expand_iv(iv) _asm_isr##iv()
13 #define DECLARE_ISR(iv) extern void __expand_iv(iv);
14
15 #ifndef CONFIG_ARCH_X86_64
16
17 static inline void 
18 install_idte(struct x86_sysdesc* idt, int iv, ptr_t isr, int dpl) 
19 {
20     struct x86_sysdesc* idte = &idt[iv];
21
22     idte->hi = ((ptr_t)isr & 0xffff0000) | IDT_ATTR(dpl, IDT_INTERRUPT); 
23     idte->lo = (KCODE_SEG << 16) | ((ptr_t)isr & 0x0000ffff);           
24 }
25 struct x86_sysdesc _idt[IDT_ENTRY];
26 u16_t _idt_limit = sizeof(_idt) - 1;
27
28 #else
29
30 static inline must_inline void 
31 install_idte(struct x86_sysdesc* idt, int iv, ptr_t isr, int dpl) 
32 {
33     struct x86_sysdesc* idte = &idt[iv];
34     
35     idte->hi = isr >> 32;
36     
37     idte->lo = (isr & 0xffff0000UL) | IDT_ATTR(dpl, IDT_INTERRUPT); 
38
39     idte->lo <<= 32;                                                     
40     idte->lo |= (KCODE_SEG << 16) | (isr & 0x0000ffffUL);
41 }
42
43 struct x86_sysdesc _idt[IDT_ENTRY];
44 u16_t _idt_limit = sizeof(_idt) - 1;
45
46 #endif
47
48 DECLARE_ISR(0)
49 DECLARE_ISR(33)
50
51 void
52 exception_install_handler()
53 {
54     ptr_t start = (ptr_t)_asm_isr0;
55     
56     for (int i = 0; i < 256; i++) {
57         install_idte(_idt, i, start, 0);
58         start += 16;
59     }
60
61     install_idte(_idt, 33, (ptr_t)_asm_isr33, 3);
62
63 #ifdef CONFIG_ARCH_X86_64
64     // TODO set different IST to some exception so it can get a
65     //      better and safe stack to work with
66 #endif
67 }