All user-space apps ware moved to 8MB virtual address address (link.ld changes);...
[ZeXOS.git] / kernel / arch / x86_64 / int.s
blob85acc8d181284d4b0bba45bc55ec59d2261a0193
1 ; ZeX/OS
2 ; Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
3 ; Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 ; This program is free software: you can redistribute it and/or modify
6 ; it under the terms of the GNU General Public License as published by
7 ; the Free Software Foundation, either version 3 of the License, or
8 ; (at your option) any later version.
10 ; This program is distributed in the hope that it will be useful,
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; GNU General Public License for more details.
15 ; You should have received a copy of the GNU General Public License
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
19 %macro IMP 1
20 %ifdef UNDERBARS
21 EXTERN _%1
22 %define %1 _%1
23 %else
24 EXTERN %1
25 %endif
26 %endmacro
28 %macro EXP 1
29 GLOBAL $_%1
30 $_%1:
31 GLOBAL $%1
32 $%1:
33 %endmacro
35 ; IMPORTS
36 ; from KRNL.LD
37 IMP bss
38 IMP end
40 ; from MAIN.C
41 IMP g_curr_thread
42 IMP fault
43 IMP main
45 [BITS 32]
46 ; This will set up our new segment registers. We need to do
47 ; something special in order to set CS. We do what is called a
48 ; far jump. A jump that includes a segment as well as an offset.
49 ; This is declared in C as 'extern void gdt_flush();'
50 EXP gdt_flush ; Allows the C code to link to this
51 IMP gp ; Says that '_gp' is in another file
52 ;_gdt_flush:
53 lgdt [gp] ; Load the GDT with our '_gp' which is a special pointer
54 mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
55 mov ds, ax
56 mov es, ax
57 mov fs, ax
58 mov gs, ax
59 jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
60 flush2:
61 ret ; Returns back to the C code!
63 ; Loads the IDT defined in '_idtp' into the processor.
64 ; This is declared in C as 'extern void idt_load();'
65 EXP idt_load
66 IMP idtp
67 lidt [idtp]
68 ret
70 ; 0: Divide By Zero Exception
71 EXP isr0
72 cli
73 push byte 0
74 push byte 0
75 jmp isr_common_stub
77 ; 1: Debug Exception
78 EXP isr1
79 cli
80 push byte 0
81 push byte 1
82 jmp isr_common_stub
84 ; 2: Non Maskable Interrupt Exception
85 EXP isr2
86 cli
87 push byte 0
88 push byte 2
89 jmp isr_common_stub
91 ; 3: Int 3 Exception
92 EXP isr3
93 cli
94 push byte 0
95 push byte 3
96 jmp isr_common_stub
98 ; 4: INTO Exception
99 EXP isr4
101 push byte 0
102 push byte 4
103 jmp isr_common_stub
105 ; 5: Out of Bounds Exception
106 EXP isr5
108 push byte 0
109 push byte 5
110 jmp isr_common_stub
112 ; 6: Invalid Opcode Exception
113 EXP isr6
114 cli
115 push byte 0
116 push byte 6
117 jmp isr_common_stub
119 ; 7: Coprocessor Not Available Exception
120 EXP isr7
122 push byte 0
123 push byte 7
124 jmp isr_common_stub
126 ; 8: Double Fault Exception (With Error Code!)
127 EXP isr8
129 push byte 8
130 jmp isr_common_stub
132 ; 9: Coprocessor Segment Overrun Exception
133 EXP isr9
135 push byte 0
136 push byte 9
137 jmp isr_common_stub
139 ; 10: Bad TSS Exception (With Error Code!)
140 EXP isr10
142 push byte 10
143 jmp isr_common_stub
145 ; 11: Segment Not Present Exception (With Error Code!)
146 EXP isr11
148 push byte 11
149 jmp isr_common_stub
151 ; 12: Stack Fault Exception (With Error Code!)
152 EXP isr12
154 push byte 12
155 jmp isr_common_stub
157 ; 13: General Protection Fault Exception (With Error Code!)
158 EXP isr13
160 push byte 13
161 jmp isr_common_stub
163 ; 14: Page Fault Exception (With Error Code!)
164 EXP isr14
166 push byte 14
167 jmp isr_common_stub
169 ; 15: Reserved Exception
170 EXP isr15
172 push byte 0
173 push byte 15
174 jmp isr_common_stub
176 ; 16: Floating Point Exception
177 EXP isr16
179 push byte 0
180 push byte 16
181 jmp isr_common_stub
183 ; 17: Alignment Check Exception
184 EXP isr17
186 push byte 0
187 push byte 17
188 jmp isr_common_stub
190 ; 18: Machine Check Exception
191 EXP isr18
193 push byte 0
194 push byte 18
195 jmp isr_common_stub
197 ; 19: Reserved
198 EXP isr19
200 push byte 0
201 push byte 19
202 jmp isr_common_stub
204 ; 20: Reserved
205 EXP isr20
207 push byte 0
208 push byte 20
209 jmp isr_common_stub
211 ; 21: Reserved
212 EXP isr21
214 push byte 0
215 push byte 21
216 jmp isr_common_stub
218 ; 22: Reserved
219 EXP isr22
221 push byte 0
222 push byte 22
223 jmp isr_common_stub
225 ; 23: Reserved
226 EXP isr23
228 push byte 0
229 push byte 23
230 jmp isr_common_stub
232 ; 24: Reserved
233 EXP isr24
235 push byte 0
236 push byte 24
237 jmp isr_common_stub
239 ; 25: Reserved
240 EXP isr25
242 push byte 0
243 push byte 25
244 jmp isr_common_stub
246 ; 26: Reserved
247 EXP isr26
249 push byte 0
250 push byte 26
251 jmp isr_common_stub
253 ; 27: Reserved
254 EXP isr27
256 push byte 0
257 push byte 27
258 jmp isr_common_stub
260 ; 28: Reserved
261 EXP isr28
263 push byte 0
264 push byte 28
265 jmp isr_common_stub
267 ; 29: Reserved
268 EXP isr29
270 push byte 0
271 push byte 29
272 jmp isr_common_stub
274 ; 30: Reserved
275 EXP isr30
277 push byte 0
278 push byte 30
279 jmp isr_common_stub
281 ; 31: Reserved
282 EXP isr31
284 push byte 0
285 push byte 31
286 jmp isr_common_stub
289 ; We call a C function in here. We need to let the assembler know
290 ; that '_fault_handler' exists in another file
293 ; This is our common ISR stub. It saves the processor state, sets
294 ; up for kernel mode segments, calls the C-level fault handler,
295 ; and finally restores the stack frame.
296 isr_common_stub:
297 IMP fault_handler
298 pusha
299 push ds
300 push es
301 push fs
302 push gs
303 mov ax, 0x10
304 mov ds, ax
305 mov es, ax
306 mov fs, ax
307 mov gs, ax
308 mov eax, esp
309 push eax
310 mov eax, fault_handler
311 call eax
312 pop eax
313 pop gs
314 pop fs
315 pop es
316 pop ds
317 popa
318 add esp, 8
319 iret
321 ;global _irq0
322 ;global _irq1
323 ;global _irq2
324 ;global _irq3
325 ;global _irq4
326 ;global _irq5
327 ;global _irq6
328 ;global _irq7
329 ;global _irq8
330 ;global _irq9
331 ;global _irq10
332 ;global _irq11
333 ;global _irq12
334 ;global _irq13
335 ;global _irq14
336 ;global _irq15
338 ; 32: IRQ0
339 EXP irq0
341 push byte 0
342 push byte 32
343 jmp irq_common_stub
345 ; 33: IRQ1
346 EXP irq1
348 push byte 0
349 push byte 33
350 jmp irq_common_stub
352 ; 34: IRQ2
353 EXP irq2
355 push byte 0
356 push byte 34
357 jmp irq_common_stub
359 ; 35: IRQ3
360 EXP irq3
362 push byte 0
363 push byte 35
364 jmp irq_common_stub
366 ; 36: IRQ4
367 EXP irq4
369 push byte 0
370 push byte 36
371 jmp irq_common_stub
373 ; 37: IRQ5
374 EXP irq5
376 push byte 0
377 push byte 37
378 jmp irq_common_stub
380 ; 38: IRQ6
381 EXP irq6
383 push byte 0
384 push byte 38
385 jmp irq_common_stub
387 ; 39: IRQ7
388 EXP irq7
390 push byte 0
391 push byte 39
392 jmp irq_common_stub
394 ; 40: IRQ8
395 EXP irq8
397 push byte 0
398 push byte 40
399 jmp irq_common_stub
401 ; 41: IRQ9
402 EXP irq9
404 push byte 0
405 push byte 41
406 jmp irq_common_stub
408 ; 42: IRQ10
409 EXP irq10
411 push byte 0
412 push byte 42
413 jmp irq_common_stub
415 ; 43: IRQ11
416 EXP irq11
418 push byte 0
419 push byte 43
420 jmp irq_common_stub
422 ; 44: IRQ12
423 EXP irq12
425 push byte 0
426 push byte 44
427 jmp irq_common_stub
429 ; 45: IRQ13
430 EXP irq13
432 push byte 0
433 push byte 45
434 jmp irq_common_stub
436 ; 46: IRQ14
437 EXP irq14
439 push byte 0
440 push byte 46
441 jmp irq_common_stub
443 ; 47: IRQ15
444 EXP irq15
446 push byte 0
447 push byte 47
448 jmp irq_common_stub
450 IMP irq_handler
452 irq_common_stub:
453 pusha
454 push ds
455 push es
456 push fs
457 push gs
459 mov ax, 0x10
460 mov ds, ax
461 mov es, ax
462 mov fs, ax
463 mov gs, ax
464 mov eax, esp
466 push eax
467 mov eax, irq_handler
468 call eax
469 pop eax
471 pop gs
472 pop fs
473 pop es
474 pop ds
475 popa
476 add esp, 8
477 iret
479 ;extern testf
480 ;global testf_c
482 ;testf_c:
483 ; mov ecx, testf
484 ; jmp syscall0
486 ; syscall with 0 args
488 ;IMP syscall_handler
489 ;EXP system_call
490 ; push ds ; switch to kernel space
491 ; push es
492 ; mov eax, 0x10
493 ; mov ds, eax
494 ; mov es, eax
496 ; call syscall_handler ; make call
498 ; pop es ; back to userland
499 ; pop ds
500 ; retf 0
501 ; iret
503 IMP syscall_handler
504 EXP system_call
505 pusha
506 push ds
507 push es
508 push fs
509 push gs
511 mov ax, 0x10
512 mov ds, ax
513 mov es, ax
514 mov fs, ax
515 mov gs, ax
517 ; mov eax, esp
519 ; push edx
520 ; push ecx
521 ; push ebx
522 push esp
524 call syscall_handler ; make call
526 add esp, 4
527 ; pop eax
528 ; pop ebx
529 ; pop ecx
530 ; pop edx
532 pop gs
533 pop fs
534 pop es
535 pop ds
537 popa
539 iret