forked from haileys/rustboot
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathexception.rs
84 lines (74 loc) · 1.83 KB
/
exception.rs
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
use core::mem::transmute;
use platform::io;
use cpu::Context;
#[repr(u8)]
pub enum Fault {
DivideError = 0,
NMI = 2,
Breakpoint = 3,
Overflow = 4,
BoundExceeded = 5,
InvalidOpcode = 6,
NoMathCoprocessor = 7,
DoubleFault = 8,
CoprocessorSegmentOverun = 9,
InvalidTss = 10,
SegmentNotPresent = 11,
StackSegmentFault = 12,
GeneralProtection = 13,
PageFault = 14,
FloatingPointError = 16,
AlignmentCheck = 17,
MachineCheck = 18,
SimdFpException = 19,
}
static Exceptions: &'static [&'static str] = &[
"Divide-by-zero Error",
"Debug",
"Non-maskable Interrupt",
"Breakpoint",
"Overflow",
"Bound Range Exceeded",
"Invalid Opcode",
"Device Not Available",
"Double Fault",
"Coprocessor Segment Overrun",
"Invalid TSS",
"Segment Not Present",
"Stack-Segment Fault",
"General Protection Fault",
"Page Fault",
"Reserved",
"x87 Floating-Point Exception",
"Alignment Check",
"Machine Check",
"SIMD Floating-Point Exception",
"Virtualization Exception",
];
#[no_split_stack]
#[inline(never)]
unsafe fn blue_screen(stack: &Context) {
io::puts("Exception ");
io::puts(Exceptions[stack.int_no as uint]);
asm!("hlt");
}
#[no_split_stack]
#[inline(never)]
pub unsafe fn exception_handler() -> extern "C" unsafe fn() {
asm!("jmp skip_exception_handler
exception_handler_asm:"
:::: "volatile", "intel");
// Points to the data on the stack
let stack_ptr = Context::save();
if stack_ptr.int_no as u8 == transmute(Breakpoint) {
asm!("debug:" :::: "volatile")
}
else {
blue_screen(stack_ptr);
}
Context::restore();
asm!("skip_exception_handler:"
:::: "volatile", "intel");
extern { fn exception_handler_asm(); }
exception_handler_asm
}