-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisr_wrapper.asm
338 lines (309 loc) · 4.78 KB
/
isr_wrapper.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
extern generic_interrupt_handler
extern generic_exception_handler
extern PIC_sendEOI
align 4
%macro setup_isr 0
push rbp ; Start new stack frame
mov rbp, rsp
push r10
push r11
push rdi
push rsi
push rdx
push rcx
push r8
push r9
push rax
%endmacro
%macro cleanup_isr 0
pop rax
pop r9
pop r8
pop rcx
pop rdx
pop rsi
pop rdi
pop r11
pop r10
mov rsp, rbp ; Remove stack frame
pop rbp
%endmacro
section .text
bits 64
global keyboard_isr_wrapper
extern keyboard_interrupt_handler
keyboard_isr_wrapper:
setup_isr
cld ; C code following sysV ABI requires DF be cleared on call
call keyboard_interrupt_handler
cleanup_isr
iretq
global page_fault_isr_wrapper
extern page_fault_interrupt_handler
page_fault_isr_wrapper:
pop rbx
setup_isr
cld ; C code following sysV ABI requires DF be cleared on call
mov rdi, rbx
mov rsi, cr2
call page_fault_interrupt_handler
cleanup_isr
iretq
global sys_call_isr_wrapper
extern sys_call_interrupt_handler
sys_call_isr_wrapper:
; Return SS
; Return RSP
; RFlags
; Return CS
; RIP
push gs
push fs
push r15
push r14
push r13
push r12
push r11
push r10
push r9
push r8
push rsi
push rdi
push rdx
push rcx
push rbx
push rax
mov rsi, rsp
call sys_call_interrupt_handler
pop rax
pop rbx
pop rcx
pop rdx
pop rdi
pop rsi
pop r8
pop r9
pop r10
pop r11
pop r12
pop r13
pop r14
pop r15
;pop cs
;pop ss
;pop ds
;pop es
pop fs
pop gs
iretq
;
; Declare generic interrupt handlers
;
%macro exception_no_err 1
global isr_wrapper_%1
isr_wrapper_%1:
setup_isr
cld ; C code following sysV ABI requires DF be cleared on call
mov rdi, %1
mov rsi, 0
call generic_exception_handler
cleanup_isr
iretq
%endmacro
%macro exception_err 1
global isr_wrapper_%1
isr_wrapper_%1:
pop rbx
pop r12
setup_isr
cld ; C code following sysV ABI requires DF be cleared on call
mov rdi, %1
mov rsi, rbx
mov rdx, r12
call generic_exception_handler
cleanup_isr
iretq
%endmacro
; Follow SystemV ABI calling convention
%macro isr 1
global isr_wrapper_%1
isr_wrapper_%1:
setup_isr
cld ; C code following sysV ABI requires DF be cleared on call
mov rdi, %1
call generic_interrupt_handler
cleanup_isr
iretq
%endmacro
%macro pic_isr 1
global isr_wrapper_%1
isr_wrapper_%1:
setup_isr
cld ; C code following sysV ABI requires DF be cleared on call
mov rdi, %1
call generic_interrupt_handler
mov rdi, %1
call PIC_sendEOI
cleanup_isr
iretq
%endmacro
exception_no_err 0x0
exception_no_err 0x1
exception_no_err 0x2
exception_no_err 0x3
exception_no_err 0x4
exception_no_err 0x5
exception_no_err 0x6
exception_no_err 0x7
exception_no_err 0x8
exception_no_err 0x9
exception_err 0xa
exception_err 0xb
exception_err 0xc
exception_err 0xd
exception_err 0xe
exception_no_err 0xf
exception_no_err 0x10
exception_err 0x11
exception_no_err 0x12
exception_no_err 0x13
exception_no_err 0x14
exception_no_err 0x15
exception_no_err 0x16
exception_no_err 0x17
exception_no_err 0x18
exception_no_err 0x19
exception_no_err 0x1a
exception_no_err 0x1b
exception_no_err 0x1c
exception_no_err 0x1d
exception_err 0x1e
exception_no_err 0x1f
pic_isr 0x20
pic_isr 0x21
pic_isr 0x22
pic_isr 0x23
pic_isr 0x24
pic_isr 0x25
pic_isr 0x26
pic_isr 0x27
pic_isr 0x28
pic_isr 0x29
pic_isr 0x2a
pic_isr 0x2b
pic_isr 0x2c
pic_isr 0x2d
pic_isr 0x2e
pic_isr 0x2f
isr 0x30
isr 0x31
isr 0x32
isr 0x33
isr 0x34
isr 0x35
isr 0x36
isr 0x37
isr 0x38
isr 0x39
isr 0x3a
isr 0x3b
isr 0x3c
isr 0x3d
isr 0x3e
isr 0x3f
isr 0x40
isr 0x41
isr 0x42
isr 0x43
isr 0x44
isr 0x45
isr 0x46
isr 0x47
isr 0x48
isr 0x49
isr 0x4a
isr 0x4b
isr 0x4c
isr 0x4d
isr 0x4e
isr 0x4f
isr 0x50
isr 0x51
isr 0x52
isr 0x53
isr 0x54
isr 0x55
isr 0x56
isr 0x57
isr 0x58
isr 0x59
isr 0x5a
isr 0x5b
isr 0x5c
isr 0x5d
isr 0x5e
isr 0x5f
isr 0x60
isr 0x61
isr 0x62
isr 0x63
isr 0x64
isr 0x65
isr 0x66
isr 0x67
isr 0x68
isr 0x69
isr 0x6a
isr 0x6b
isr 0x6c
isr 0x6d
isr 0x6e
isr 0x6f
isr 0x70
isr 0x71
isr 0x72
isr 0x73
isr 0x74
isr 0x75
isr 0x76
isr 0x77
isr 0x78
isr 0x79
isr 0x7a
isr 0x7b
isr 0x7c
isr 0x7d
isr 0x7e
isr 0x7f
isr 0x80
isr 0x81
isr 0x82
isr 0x83
isr 0x84
isr 0x85
isr 0x86
isr 0x87
isr 0x88
isr 0x89
isr 0x8a
isr 0x8b
isr 0x8c
isr 0x8d
isr 0x8e
isr 0x8f
isr 0x90
isr 0x91
isr 0x92
isr 0x93
isr 0x94
isr 0x95
isr 0x96
isr 0x97
isr 0x98
isr 0x99
isr 0x9a
isr 0x9b
isr 0x9c
isr 0x9d
isr 0x9e
isr 0x9f