Skip to content

Commit 7f7ef30

Browse files
bors[bot]stlankes
andauthored
700: add usefull debug messages for all exceptions r=stlankes a=stlankes Co-authored-by: Stefan Lankes <[email protected]>
2 parents 46f57fe + aea143e commit 7f7ef30

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

src/arch/x86_64/kernel/interrupts.rs

+115
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ pub fn install() {
3434
set_general_handler!(idt, unhandle, 32..64);
3535
set_general_handler!(idt, unknown, 64..);
3636

37+
idt.divide_error.set_handler_fn(divide_error_exception);
38+
idt.debug.set_handler_fn(debug_exception);
39+
idt.breakpoint.set_handler_fn(breakpoint_exception);
40+
idt.overflow.set_handler_fn(overflow_exception);
41+
idt.bound_range_exceeded
42+
.set_handler_fn(bound_range_exceeded_exception);
43+
idt.invalid_opcode.set_handler_fn(invalid_opcode_exception);
44+
idt.device_not_available
45+
.set_handler_fn(device_not_available_exception);
46+
idt.invalid_tss.set_handler_fn(invalid_tss_exception);
47+
idt.segment_not_present
48+
.set_handler_fn(segment_not_present_exception);
49+
idt.stack_segment_fault
50+
.set_handler_fn(stack_segment_fault_exception);
51+
idt.general_protection_fault
52+
.set_handler_fn(general_protection_exception);
53+
idt.page_fault.set_handler_fn(page_fault_handler);
54+
idt.x87_floating_point
55+
.set_handler_fn(floating_point_exception);
56+
idt.alignment_check
57+
.set_handler_fn(alignment_check_exception);
58+
idt.simd_floating_point
59+
.set_handler_fn(simd_floating_point_exception);
60+
idt.virtualization.set_handler_fn(virtualization_exception);
61+
3762
unsafe {
3863
idt.double_fault
3964
.set_handler_fn(double_fault_exception)
@@ -78,11 +103,41 @@ fn unknown(_stack_frame: ExceptionStackFrame, index: u8, _error_code: Option<u64
78103
apic::eoi();
79104
}
80105

106+
extern "x86-interrupt" fn divide_error_exception(stack_frame: ExceptionStackFrame) {
107+
error!("Divide Error (#DE) Exception: {:#?}", stack_frame);
108+
scheduler::abort();
109+
}
110+
111+
extern "x86-interrupt" fn debug_exception(stack_frame: ExceptionStackFrame) {
112+
error!("Debug (#DB) Exception: {:#?}", stack_frame);
113+
scheduler::abort();
114+
}
115+
81116
extern "x86-interrupt" fn nmi_exception(stack_frame: ExceptionStackFrame) {
82117
error!("Non-Maskable Interrupt (NMI) Exception: {:#?}", stack_frame);
83118
scheduler::abort();
84119
}
85120

121+
extern "x86-interrupt" fn breakpoint_exception(stack_frame: ExceptionStackFrame) {
122+
error!("Breakpoint (#BP) Exception: {:#?}", stack_frame);
123+
scheduler::abort();
124+
}
125+
126+
extern "x86-interrupt" fn overflow_exception(stack_frame: ExceptionStackFrame) {
127+
error!("Overflow (#OF) Exception: {:#?}", stack_frame);
128+
scheduler::abort();
129+
}
130+
131+
extern "x86-interrupt" fn bound_range_exceeded_exception(stack_frame: ExceptionStackFrame) {
132+
error!("BOUND Range Exceeded (#BR) Exception: {:#?}", stack_frame);
133+
scheduler::abort();
134+
}
135+
136+
extern "x86-interrupt" fn invalid_opcode_exception(stack_frame: ExceptionStackFrame) {
137+
error!("Invalid Opcode (#UD) Exception: {:#?}", stack_frame);
138+
scheduler::abort();
139+
}
140+
86141
extern "x86-interrupt" fn device_not_available_exception(_stack_frame: ExceptionStackFrame) {
87142
// We set the CR0_TASK_SWITCHED flag every time we switch to a task.
88143
// This causes the "Device Not Available" Exception (int #7) to be thrown as soon as we use the FPU for the first time.
@@ -98,6 +153,46 @@ extern "x86-interrupt" fn device_not_available_exception(_stack_frame: Exception
98153
core_scheduler().fpu_switch();
99154
}
100155

156+
extern "x86-interrupt" fn invalid_tss_exception(stack_frame: ExceptionStackFrame, _code: u64) {
157+
error!("Invalid TSS (#TS) Exception: {:#?}", stack_frame);
158+
scheduler::abort();
159+
}
160+
161+
extern "x86-interrupt" fn segment_not_present_exception(
162+
stack_frame: ExceptionStackFrame,
163+
_code: u64,
164+
) {
165+
error!("Segment Not Present (#NP) Exception: {:#?}", stack_frame);
166+
scheduler::abort();
167+
}
168+
169+
extern "x86-interrupt" fn stack_segment_fault_exception(
170+
stack_frame: ExceptionStackFrame,
171+
error_code: u64,
172+
) {
173+
error!(
174+
"Stack Segment Fault (#SS) Exception: {:#?}, error {:#X}",
175+
stack_frame, error_code
176+
);
177+
scheduler::abort();
178+
}
179+
180+
extern "x86-interrupt" fn general_protection_exception(
181+
stack_frame: ExceptionStackFrame,
182+
error_code: u64,
183+
) {
184+
error!(
185+
"General Protection (#GP) Exception: {:#?}, error {:#X}",
186+
stack_frame, error_code
187+
);
188+
error!(
189+
"fs = {:#X}, gs = {:#X}",
190+
processor::readfs(),
191+
processor::readgs()
192+
);
193+
scheduler::abort();
194+
}
195+
101196
extern "x86-interrupt" fn double_fault_exception(
102197
stack_frame: ExceptionStackFrame,
103198
error_code: u64,
@@ -109,6 +204,16 @@ extern "x86-interrupt" fn double_fault_exception(
109204
scheduler::abort()
110205
}
111206

207+
extern "x86-interrupt" fn floating_point_exception(stack_frame: ExceptionStackFrame) {
208+
error!("Floating-Point Error (#MF) Exception: {:#?}", stack_frame);
209+
scheduler::abort();
210+
}
211+
212+
extern "x86-interrupt" fn alignment_check_exception(stack_frame: ExceptionStackFrame, _code: u64) {
213+
error!("Alignment Check (#AC) Exception: {:#?}", stack_frame);
214+
scheduler::abort();
215+
}
216+
112217
pub extern "x86-interrupt" fn page_fault_handler(
113218
stack_frame: ExceptionStackFrame,
114219
error_code: PageFaultErrorCode,
@@ -127,6 +232,16 @@ extern "x86-interrupt" fn machine_check_exception(stack_frame: ExceptionStackFra
127232
scheduler::abort()
128233
}
129234

235+
extern "x86-interrupt" fn simd_floating_point_exception(stack_frame: ExceptionStackFrame) {
236+
error!("SIMD Floating-Point (#XM) Exception: {:#?}", stack_frame);
237+
scheduler::abort();
238+
}
239+
240+
extern "x86-interrupt" fn virtualization_exception(stack_frame: ExceptionStackFrame) {
241+
error!("Virtualization (#VE) Exception: {:#?}", stack_frame);
242+
scheduler::abort();
243+
}
244+
130245
static IRQ_NAMES: InterruptTicketMutex<HashMap<u32, &'static str, RandomState>> =
131246
InterruptTicketMutex::new(HashMap::with_hasher(RandomState::with_seeds(0, 0, 0, 0)));
132247

0 commit comments

Comments
 (0)