-
Notifications
You must be signed in to change notification settings - Fork 2
/
exception.c
272 lines (229 loc) · 4.79 KB
/
exception.c
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
#include "lib.h"
#include "exception.h"
#include "x86_desc.h"
#include "exception_wrappers.h"
/*
* void init_exception(void)
* Inputs: void
* Outputs: none
* Function: set up idt table for exceptions
*/
void init_exception(void){
/* set 20 idt entries for exceptions */
SET_IDT_ENTRY(idt[0x0], divide_error_wrapper);
SET_IDT_ENTRY(idt[0x1], reserved_wrapper);
SET_IDT_ENTRY(idt[0x2], nmi_wrapper);
SET_IDT_ENTRY(idt[0x3], breakpoint_wrapper);
SET_IDT_ENTRY(idt[0x4], overflow_wrapper);
SET_IDT_ENTRY(idt[0x5], bound_range_exceeded_wrapper);
SET_IDT_ENTRY(idt[0x6], invalid_opcode_wrapper);
SET_IDT_ENTRY(idt[0x7], device_not_available_wrapper);
SET_IDT_ENTRY(idt[0x8], double_fault_wrapper);
SET_IDT_ENTRY(idt[0x9], coprocessor_segment_overrun_wrapper);
SET_IDT_ENTRY(idt[0xA], invalid_tss_wrapper);
SET_IDT_ENTRY(idt[0xB], segment_not_present_wrapper);
SET_IDT_ENTRY(idt[0xC], stack_segment_falut_wrapper);
SET_IDT_ENTRY(idt[0xD], general_protection_wrapper);
SET_IDT_ENTRY(idt[0xE], page_fault_wrapper);
SET_IDT_ENTRY(idt[0x10], floating_point_error_wrapper);
SET_IDT_ENTRY(idt[0x11], alignment_check_wrapper);
SET_IDT_ENTRY(idt[0x12], machine_check_wrapper);
SET_IDT_ENTRY(idt[0x13], simd_float_point_exception_wrapper);
}
/*
* void divide_error(void)
* Inputs: void
* Function: handles divide error exception
*/
void divide_error(void)
{
clear();
puts("Divide Error", 1);
while(1);
}
/*
* void reserved(void)
* Inputs: void
* Function: handles reserved exception
*/
void reserved(void){
clear();
puts("RESERVED", 1);
while(1);
}
/*
* void nmi(void)
* Inputs: void
* Function: handles NMI exception
*/
void nmi(void){
clear();
puts("NMI Interrupt", 1);
while(1);
}
/*
* void breakpoint(void)
* Inputs: void
* Function: handles breakpoint exception
*/
void breakpoint(void){
clear();
puts("Overflow", 1);
while(1);
}
/*
* void overflow(void)
* Inputs: void
* Function: handles overflow exception
*/
void overflow(void){
clear();
puts("Breakpoint", 1);
while(1);
}
/*
* void bound_range_exceeded(void)
* Inputs: void
* Function: handles bound_range_exceeded exception
*/
void bound_range_exceeded(void){
clear();
puts("BOUND Range Exceeded", 1);
while(1);
}
/*
* void invalid_opcode(void)
* Inputs: void
* Function: handles invalid_opcode exception
*/
void invalid_opcode(void){
clear();
puts("Invalid Opcode", 1);
while(1);
}
/*
* void device_not_available(void)
* Inputs: void
* Function: handles device_not_available exception
*/
void device_not_available(void){
clear();
puts("Device Not Available", 1);
while(1);
}
/*
* void double_fault(void)
* Inputs: void
* Function: handles double_fault exception
*/
void double_fault(void){
clear();
puts("Double Fault", 1);
while(1);
}
/*
* void coprocessor_segment_overrun(void)
* Inputs: void
* Function: handles coprocessor_segment_overrun exception
*/
void coprocessor_segment_overrun(void){
clear();
puts("Coprocessor Segment Overrun", 1);
while(1);
}
/*
* void invalid_tss(void)
* Inputs: void
* Function: handles invalid_tss exception
*/
void invalid_tss(void){
clear();
puts("Invalid TSS", 1);
while(1);
}
/*
* void segment_not_present(void)
* Inputs: void
* Function: handles segment_not_present exception
*/
void segment_not_present(void){
clear();
puts("Segment Not Present", 1);
while(1);
}
/*
* void stack_segment_falut(void)
* Inputs: void
* Function: handles stack_segment_falut exception
*/
void stack_segment_falut(void){
clear();
puts("Stack-Segment Fault", 1);
while(1);
}
/*
* void general_protection(void)
* Inputs: void
* Function: handles general_protection exception
*/
void general_protection(void){
clear();
puts("General Protection", 1);
while(1);
}
/*
* void page_fault(void)
* Inputs: void
* Function: handles page_fault exception
*/
void page_fault(void){
//clear();
int fault;
asm volatile("movl %%cr2, %0" \
: \
:"r"(fault) \
:"memory");
printf("fault: %x\n", fault);
puts("Page Fault Exception!!", 1);
while(1);
}
/*
* void floating_point_error(void)
* Inputs: void
* Function: handles floating_point_error exception
*/
void floating_point_error(void){
clear();
puts("x87 FPU Floating-Point Error", 1);
while(1);
}
/*
* void alignment_check(void)
* Inputs: void
* Function: handles alignment_check exception
*/
void alignment_check(void){
clear();
puts("Alignment Check", 1);
while(1);
}
/*
* void machine_check(void)
* Inputs: void
* Function: handles machine_check exception
*/
void machine_check(void){
clear();
puts("Machine Check", 1);
while(1);
}
/*
* void simd_float_point_exception(void)
* Inputs: void
* Function: handles simd_float_point_exceptionexception
*/
void simd_float_point_exception(void){
clear();
puts("SIMD Floating-Point Exception", 1);
while(1);
}