feat: No more kernel page table switching upon interrupt.
[lunaix-os.git] / lunaix-os / kernel / asm / x86 / interrupt.S
1 #define __ASM__
2 #include <arch/x86/interrupts.h>
3 // #define __ASM_INTR_DIAGNOSIS
4
5 .macro isr_template vector, no_error_code=1
6     .global _asm_isr\vector
7     .type _asm_isr\vector, @function
8     _asm_isr\vector:
9         .if \no_error_code
10             pushl $0x0
11         .endif
12         pushl $\vector
13         jmp interrupt_wrapper
14 .endm
15
16 #ifdef __ASM_INTR_DIAGNOSIS
17 .section .bss
18     .global debug_resv
19     debug_resv:
20         .skip 16
21 #endif
22
23 .section .text
24     isr_template FAULT_DIVISION_ERROR
25     isr_template FAULT_GENERAL_PROTECTION, no_error_code=0
26     isr_template FAULT_PAGE_FAULT, no_error_code=0
27
28     isr_template LUNAIX_SYS_PANIC
29     isr_template LUNAIX_SYS_CALL
30
31     isr_template APIC_ERROR_IV
32     isr_template APIC_LINT0_IV
33     isr_template APIC_TIMER_IV
34     isr_template APIC_SPIV_IV
35     isr_template RTC_TIMER_IV
36     isr_template PC_KBD_IV
37
38     interrupt_wrapper:
39         pushl %esp
40
41         pushl %esi
42         pushl %ebp
43         pushl %edi
44         pushl %edx
45         pushl %ecx
46         pushl %ebx
47         pushl %eax
48
49         movl %esp, %eax
50         andl $0xfffffff0, %esp
51         subl $16, %esp
52         movl %eax, (%esp)
53
54         call intr_handler
55
56     .global soft_iret
57     soft_iret:
58         popl %esp
59
60         popl %eax
61         popl %ebx
62         popl %ecx
63         popl %edx
64         popl %edi
65         popl %ebp
66         popl %esi
67         popl %esp
68
69         addl $8, %esp
70
71 #ifdef __ASM_INTR_DIAGNOSIS
72         cmpl $0, (%esp)
73         jz 1f
74         iret
75 1:
76         movl $__current, %eax
77         movl  (%esp), %ebx
78         movl $debug_resv, %ecx
79         ud2
80 #else
81         iret
82 #endif