-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlr32.S
211 lines (159 loc) · 3.67 KB
/
handlr32.S
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
/*****************************************************************************/
/* File: handlr32.S */
/* */
/* Description: x86 32 bit interrupt, trap and fault handler. */
/* */
/* Author: Shoily O Rahman <shoily@gmail.com> */
/* */
/* Date: June 15, 2020 */
/* */
/*****************************************************************************/
.code32
.text
.globl common_trap_handler
.globl trap_handler_14
.globl sys_call_handler_128
.globl irq_handler_0
.globl irq_handler_1
.globl irq_handler_2
.globl irq_handler_3
.globl irq_handler_4
.globl irq_handler_5
.globl irq_handler_6
.globl irq_handler_7
.globl irq_handler_8
.globl irq_handler_9
.globl irq_handler_10
.globl irq_handler_11
.globl irq_handler_12
.globl irq_handler_13
.globl irq_handler_14
.globl irq_handler_15
// macro for defining IRQ handler using PIC
.macro DEFINE_IRQ_HANDLER irqn
irq_handler_\irqn:
pushl $\irqn
pusha
push %ds
push %es
push %fs
push %gs
pushl $0
movl $0x28, %eax
movl %eax, %ds
movl %eax, %es
movl %eax, %fs
movl %eax, %gs
sti
movl %esp, %ebp
push %ebp
call common_interrupt_handler
addl $8, %esp
pop %gs
pop %fs
pop %es
pop %ds
popa
addl $4, %esp
iret
.endm
// macro for defining system call handler
.macro DEFINE_SYS_CALL_HANDLER syscallnr
sys_call_handler_\syscallnr:
pushl $\syscallnr
pusha
push %ds
push %es
push %fs
push %gs
pushl $0
movl %esp, %ebp
movl $0x28, %eax
movl %eax, %ds
movl %eax, %es
movl %eax, %fs
movl %eax, %gs
push %ebp
call common_sys_call_handler
addl $8, %esp
pop %gs
pop %fs
pop %es
pop %ds
popa
addl $4, %esp
iret
.endm
// macro for defining trap handler
.macro DEFINE_TRAP_HANDLER trapnr
trap_handler_\trapnr:
cli
pusha
push %ds
push %es
push %fs
push %gs
pushl $\trapnr
movl %esp, %ebp
movl $0x28, %eax
movl %eax, %ds
movl %eax, %es
movl %eax, %fs
movl %eax, %gs
push %ebp
call trap_handler
addl $8, %esp
pop %gs
pop %fs
pop %es
pop %ds
popa
addl $4, %esp
sti
iret
.endm
// define IRQ handlers 0-15
DEFINE_IRQ_HANDLER 0
DEFINE_IRQ_HANDLER 1
DEFINE_IRQ_HANDLER 2
DEFINE_IRQ_HANDLER 3
DEFINE_IRQ_HANDLER 4
DEFINE_IRQ_HANDLER 5
DEFINE_IRQ_HANDLER 6
DEFINE_IRQ_HANDLER 7
DEFINE_IRQ_HANDLER 8
DEFINE_IRQ_HANDLER 9
DEFINE_IRQ_HANDLER 10
DEFINE_IRQ_HANDLER 11
DEFINE_IRQ_HANDLER 12
DEFINE_IRQ_HANDLER 13
DEFINE_IRQ_HANDLER 14
DEFINE_IRQ_HANDLER 15
// define system call handlers
DEFINE_SYS_CALL_HANDLER 128
// define trap handler
DEFINE_TRAP_HANDLER 14
common_trap_handler:
cli
pusha
push %ds
push %es
push %fs
push %gs
pushl $0
movl %esp, %ebp
movl $0x28, %eax
movl %eax, %ds
movl %eax, %es
movl %eax, %fs
movl %eax, %gs
push %ebp
call trap_handler
addl $8, %esp
pop %gs
pop %fs
pop %es
pop %ds
popa
sti
iret