forked from ReKernel/ReKernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisr.asm
More file actions
executable file
·119 lines (108 loc) · 3.52 KB
/
Copy pathisr.asm
File metadata and controls
executable file
·119 lines (108 loc) · 3.52 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
; isr.asm — Interrupt / IRQ stubs
bits 32
section .text
extern interrupt_handler
; ── Common path ──────────────────────────────────────────────────────────────
; Stack on entry (built bottom-up by CPU + stubs):
; [cpu] ss, useresp (only on priv-change), eflags, cs, eip
; [stub] err_code, int_no
; [below] saved by us: eax..edi (pusha), ds, es, fs, gs
;
; We pass &gs as the registers_t* argument.
; ─────────────────────────────────────────────────────────────────────────────
isr_common_stub:
pusha ; saves eax,ecx,edx,ebx,esp,ebp,esi,edi
push ds
push es
push fs
push gs
; Load kernel data segments
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; esp now points at saved gs = start of registers_t on the stack
mov eax, esp ; take the pointer BEFORE push so it's stable
push eax ; argument: registers_t *regs
call interrupt_handler
add esp, 4 ; clean up argument
pop gs
pop fs
pop es
pop ds
popa
add esp, 8 ; discard int_no + err_code
iret
; ── Macros ───────────────────────────────────────────────────────────────────
%macro ISR_NOERR 1
global isr%1
isr%1:
push dword 0 ; dummy error code
push dword %1 ; interrupt number
jmp isr_common_stub
%endmacro
%macro ISR_ERR 1
global isr%1
isr%1: ; CPU already pushed error code
push dword %1
jmp isr_common_stub
%endmacro
%macro IRQ 2 ; (irq_num, mapped_int_num)
global irq%1
irq%1:
push dword 0
push dword %2
jmp isr_common_stub
%endmacro
; ── CPU exceptions 0–31 ──────────────────────────────────────────────────────
ISR_NOERR 0 ; Divide by zero
ISR_NOERR 1 ; Debug
ISR_NOERR 2 ; NMI
ISR_NOERR 3 ; Breakpoint
ISR_NOERR 4 ; Overflow
ISR_NOERR 5 ; Bound range exceeded
ISR_NOERR 6 ; Invalid opcode
ISR_NOERR 7 ; Device not available
ISR_ERR 8 ; Double fault
ISR_NOERR 9 ; Coprocessor segment overrun
ISR_ERR 10 ; Invalid TSS
ISR_ERR 11 ; Segment not present
ISR_ERR 12 ; Stack-segment fault
ISR_ERR 13 ; General protection fault
ISR_ERR 14 ; Page fault
ISR_NOERR 15
ISR_NOERR 16 ; x87 FPU
ISR_ERR 17 ; Alignment check
ISR_NOERR 18 ; Machine check
ISR_NOERR 19 ; SIMD FPU
ISR_NOERR 20 ; Virtualisation
ISR_ERR 21 ; Control protection
ISR_NOERR 22
ISR_NOERR 23
ISR_NOERR 24
ISR_NOERR 25
ISR_NOERR 26
ISR_NOERR 27
ISR_NOERR 28
ISR_NOERR 29
ISR_NOERR 30
ISR_NOERR 31
; ── Hardware IRQs (remapped to ints 32–47) ────────────────────────────────────
IRQ 0, 32 ; PIT
IRQ 1, 33 ; PS/2 keyboard
IRQ 2, 34 ; PIC cascade
IRQ 3, 35
IRQ 4, 36
IRQ 5, 37
IRQ 6, 38
IRQ 7, 39 ; spurious
IRQ 8, 40 ; RTC
IRQ 9, 41
IRQ 10, 42
IRQ 11, 43
IRQ 12, 44
IRQ 13, 45
IRQ 14, 46
IRQ 15, 47 ; spurious slave
section .note.GNU-stack noalloc noexec nowrite progbits