14
|
1 ; The default interrupt handlers.
|
|
2 ; from 20 - 31 are reserved vectors.
|
|
3 ; below are the custom ones!
|
|
4
|
|
5 section .text
|
|
6 align 4
|
|
7
|
25
|
8 ; Function to read the current instruction pointer value:
|
|
9 global read_rip
|
|
10 read_rip:
|
|
11 pop rax
|
|
12 jmp rax
|
|
13
|
14
|
14 global loadIDT
|
|
15 loadIDT:
|
17
|
16 extern idtP
|
|
17 ; TODO: make this pointer thing more insightfull:
|
|
18 lidt [idtP]
|
14
|
19 ret
|
|
20
|
31
|
21 ; ISR related assembler wrappers:
|
|
22
|
|
23 %macro ISR_NOERRCODE 1
|
|
24 global INT%1
|
|
25 INT%1:
|
|
26 cli
|
|
27 push strict qword 0 ; push dummy error code
|
|
28 push strict qword %1 ; push interrupt number
|
|
29 jmp isr_common_stub
|
|
30 %endmacro
|
|
31
|
|
32 %macro ISR_ERRCODE 1
|
|
33 global INT%1
|
|
34 INT%1:
|
|
35 cli
|
|
36 push strict qword %1 ; push interrupt number
|
|
37 jmp isr_common_stub
|
|
38 %endmacro
|
|
39
|
|
40 isr_common_stub:
|
|
41 ; Do some saving:
|
17
|
42 push rax
|
|
43 push rcx
|
|
44 push rdx
|
|
45 push rbx
|
|
46 push rbp
|
|
47 push rsi
|
|
48 push rdi
|
31
|
49
|
|
50 ; AMD64 calling convention, first parameter is in rdi:
|
|
51 mov rdi, rsp ; Load stack pointer into rdi to indicate where the registers on the stack are (so that we can change them!)
|
17
|
52
|
31
|
53 extern isr_handler
|
|
54 call isr_handler
|
|
55
|
17
|
56 pop rdi
|
|
57 pop rsi
|
|
58 pop rbp
|
|
59 pop rbx
|
|
60 pop rdx
|
|
61 pop rcx
|
|
62 pop rax
|
|
63
|
31
|
64 add rsp, 16 ; cleanup error code and isr number
|
|
65 sti
|
|
66 iretq
|
14
|
67
|
|
68 ; Exception handlers:
|
31
|
69 ISR_NOERRCODE 0
|
|
70 ISR_NOERRCODE 1
|
|
71 ISR_NOERRCODE 2
|
|
72 ISR_NOERRCODE 3
|
|
73 ISR_NOERRCODE 4
|
|
74 ISR_NOERRCODE 5
|
|
75 ISR_NOERRCODE 6
|
|
76 ISR_NOERRCODE 7
|
|
77 ISR_ERRCODE 8
|
|
78 ISR_NOERRCODE 9
|
|
79 ISR_ERRCODE 10
|
|
80 ISR_ERRCODE 11
|
|
81 ISR_ERRCODE 12
|
|
82 ISR_ERRCODE 13
|
|
83 ISR_ERRCODE 14
|
|
84 ; 15 is reserved
|
|
85 ISR_NOERRCODE 16
|
|
86 ISR_ERRCODE 17
|
|
87 ISR_NOERRCODE 18
|
|
88 ISR_NOERRCODE 19
|
14
|
89
|
31
|
90 ISR_NOERRCODE 32
|
|
91 ISR_NOERRCODE 33
|
|
92 ISR_NOERRCODE 34
|
14
|
93
|
31
|
94 ; default handler:
|
|
95 ISR_NOERRCODE 255
|
|
96
|
|
97
|