celtic / akari

My attempt at bringing light to operating system development.

This URL has Read+Write access

celtic (author)
Sat Jun 13 00:07:58 -0700 2009
commit  24cf1cf9194b91e5b29088b8cb755eb6901e2f20
tree    ed8996f3fb5da5333e8662f570ffb2afa11513a7
parent  8b62939f66e6192c78c7888d9b727cfbe0cffa13
akari / interrupts.s
100644 400 lines (320 sloc) 5.175 kb
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
.code32
.section .text
 
.globl _isr0
.globl _isr1
.globl _isr2
.globl _isr3
.globl _isr4
.globl _isr5
.globl _isr6
.globl _isr7
.globl _isr8
.globl _isr9
.globl _isra
.globl _isrb
.globl _isrc
.globl _isrd
.globl _isre
.globl _isrf
.globl _isr10
.globl _isr11
.globl _isr12
.globl _isr13
.globl _isr14
.globl _isr15
.globl _isr16
.globl _isr17
.globl _isr18
.globl _isr19
.globl _isr1a
.globl _isr1b
.globl _isr1c
.globl _isr1d
.globl _isr1e
.globl _isr1f
.globl _isr80
 
.globl _irq0
.globl _irq1
.globl _irq2
.globl _irq3
.globl _irq4
.globl _irq5
.globl _irq6
.globl _irq7
.globl _irq8
.globl _irq9
.globl _irqa
.globl _irqb
.globl _irqc
.globl _irqd
.globl _irqe
.globl _irqf
 
_isr0: cli
push $0x00
push $0x00
jmp isr_common
 
_isr1: cli
push $0x00
push $0x01
jmp isr_common
 
_isr2: cli
push $0x00
push $0x02
jmp isr_common
 
_isr3: cli
push $0x00
push $0x03
jmp isr_common
 
_isr4: cli
push $0x00
push $0x04
jmp isr_common
 
_isr5: cli
push $0x00
push $0x05
jmp isr_common
 
_isr6: cli
push $0x00
push $0x06
jmp isr_common
 
_isr7: cli
push $0x00
push $0x07
jmp isr_common
 
_isr8: cli
push $0x08
jmp isr_common
 
_isr9: cli
push $0x00
push $0x09
jmp isr_common
 
_isra: cli
push $0x0a
jmp isr_common
 
_isrb: cli
push $0x0b
jmp isr_common
 
_isrc: cli
push $0x0c
jmp isr_common
 
_isrd: cli
push $0x0d
jmp isr_common
 
_isre: cli
push $0x0e
jmp isr_common
 
_isrf: cli
push $0x00
push $0x0f
jmp isr_common
 
_isr10: cli
push $0x00
push $0x10
jmp isr_common
 
_isr11: cli
push $0x00
push $0x11
jmp isr_common
 
_isr12: cli
push $0x00
push $0x12
jmp isr_common
 
_isr13: cli
push $0x00
push $0x13
jmp isr_common
 
_isr14: cli
push $0x00
push $0x14
jmp isr_common
 
_isr15: cli
push $0x00
push $0x15
jmp isr_common
 
_isr16: cli
push $0x00
push $0x16
jmp isr_common
 
_isr17: cli
push $0x00
push $0x17
jmp isr_common
 
_isr18: cli
push $0x00
push $0x18
jmp isr_common
 
_isr19: cli
push $0x00
push $0x19
jmp isr_common
 
_isr1a: cli
push $0x00
push $0x1a
jmp isr_common
 
_isr1b: cli
push $0x00
push $0x1b
jmp isr_common
 
_isr1c: cli
push $0x00
push $0x1c
jmp isr_common
 
_isr1d: cli
push $0x00
push $0x1d
jmp isr_common
 
_isr1e: cli
push $0x00
push $0x1e
jmp isr_common
 
_isr1f: cli
push $0x00
push $0x1f
jmp isr_common
 
_isr80: cli
push $0x00
push $0x80
jmp isr_common
 
 
#; timer is special case, handled manually!
_irq0: cli
push $0x00
push $0x20
jmp irq_timer_multitask
 
_irq1: cli
push $0x00
push $0x21
jmp irq_common
 
_irq2: cli
push $0x00
push $0x22
jmp irq_common
 
_irq3: cli
push $0x00
push $0x23
jmp irq_common
 
_irq4: cli
push $0x00
push $0x24
jmp irq_common
 
_irq5: cli
push $0x00
push $0x25
jmp irq_common
 
_irq6: cli
push $0x00
push $0x26
jmp irq_common
 
_irq7: cli
push $0x00
push $0x27
jmp irq_common
 
_irq8: cli
push $0x00
push $0x28
jmp irq_common
 
_irq9: cli
push $0x00
push $0x29
jmp irq_common
 
_irqa: cli
push $0x00
push $0x2a
jmp irq_common
 
_irqb: cli
push $0x00
push $0x2b
jmp irq_common
 
_irqc: cli
push $0x00
push $0x2c
jmp irq_common
 
_irqd: cli
push $0x00
push $0x2d
jmp irq_common
 
_irqe: cli
push $0x00
push $0x2e
jmp irq_common
 
_irqf: cli
push $0x00
push $0x2f
jmp irq_common
 
.type isr_common, @function
isr_common:
pusha
 
mov %ds, %ax
push %eax
 
mov %esp, %eax #; stack from here *up*: ds, `pusha', task switch
#; mov $0xE0000000, %esp
push %eax #; ptr to said stack becomes parameter for _irq_handler
 
mov $0x10, %ax #; kernel data segment descriptor
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
 
call _isr_handler
 
mov %eax, %esp
 
pop %eax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
 
popa
add $8, %esp #; cleans pushed error code, and pushed ISR number
sti
iret #; pops CS, EIP, EFLAGS, SS, ESP
 
.type irq_common, @function
irq_common:
pusha
 
mov %ds, %ax
push %eax
 
mov %esp, %eax #; stack from here *up*: ds, `pusha', task switch
#; mov $0xE0000000, %esp
push %eax #; ptr to said stack becomes parameter for _irq_handler
 
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
 
call _irq_handler
 
mov %eax, %esp
 
pop %eax
mov %ax, %ds #; restore from stack, which _irq_handler may change
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
 
popa
add $8, %esp
sti #; waits one instruction, remember?
iret
 
.type irq_timer_multitask, @function
irq_timer_multitask:
pusha
 
mov %ds, %ax
push %eax
 
mov %esp, %eax
mov $0xE0000000, %esp #; XXX <- does this belong? As long as IRQs don't happen in the µkernel!
push %eax
 
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
 
mov $0x20, %al
outb %al, $0x20 #; EOI to master irq controller
 
call _AkariMicrokernel #; see use of %eax below, i.e. the return value.
 
#; add $4, %esp #; remove the pointer arg we pushed
#; technically the above is wasted since we replace %esp below,
#; but should we not at some point later, don't forget to remove
#; the pointer arg with something similar!
 
mov %eax, %esp #; this will be either the utks or kernel-stack. either way.
 
pop %eax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
 
popa
add $8, %esp
sti
iret