forked from anshugupta673/x86_64-decOS-MSC-KIIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trap.asm
234 lines (192 loc) · 2.82 KB
/
trap.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
section .text
extern handler
global vector0
global vector1
global vector2
global vector3
global vector4
global vector5
global vector6
global vector7
global vector8
global vector10
global vector11
global vector12
global vector13
global vector14
global vector16
global vector17
global vector18
global vector19
global vector32
global vector33
global vector39
global sysint
global eoi
global read_isr
global load_idt
global load_cr3
global pstart
global read_cr2
global swap
global TrapReturn
global in_byte
Trap:
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
push rbp
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
mov rdi,rsp
call handler
TrapReturn:
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rbp
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
add rsp,16
iretq
vector0:
push 0
push 0
jmp Trap
vector1:
push 0
push 1
jmp Trap
vector2:
push 0
push 2
jmp Trap
vector3:
push 0
push 3
jmp Trap
vector4:
push 0
push 4
jmp Trap
vector5:
push 0
push 5
jmp Trap
vector6:
push 0
push 6
jmp Trap
vector7:
push 0
push 7
jmp Trap
vector8:
push 8
jmp Trap
vector10:
push 10
jmp Trap
vector11:
push 11
jmp Trap
vector12:
push 12
jmp Trap
vector13:
push 13
jmp Trap
vector14:
push 14
jmp Trap
vector16:
push 0
push 16
jmp Trap
vector17:
push 17
jmp Trap
vector18:
push 0
push 18
jmp Trap
vector19:
push 0
push 19
jmp Trap
vector32:
push 0
push 32
jmp Trap
vector33:
push 0
push 33
jmp Trap
vector39:
push 0
push 39
jmp Trap
sysint:
push 0
push 0x80
jmp Trap
eoi:
mov al,0x20
out 0x20,al
ret
read_isr:
mov al,11
out 0x20,al
in al,0x20
ret
load_idt:
lidt [rdi]
ret
load_cr3:
mov rax,rdi
mov cr3,rax
ret
read_cr2:
mov rax,cr2
ret
pstart:
mov rsp,rdi
jmp TrapReturn
swap:
push rbx
push rbp
push r12
push r13
push r14
push r15
mov [rdi],rsp
mov rsp,rsi
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
ret
in_byte:
mov rdx,rdi
in al,dx
ret