xref: /DragonOS/kernel/src/arch/x86_64/interrupt/trap.rs (revision f2022a8a1cc4a8e2a85e9061e036e9c491a2fa00)
1*f2022a8aSLoGin use system_error::SystemError;
2*f2022a8aSLoGin 
3*f2022a8aSLoGin use crate::{
4*f2022a8aSLoGin     arch::CurrentIrqArch, exception::InterruptArch, kerror, kwarn, mm::VirtAddr, print,
5*f2022a8aSLoGin     process::ProcessManager, smp::core::smp_get_processor_id,
6*f2022a8aSLoGin };
7*f2022a8aSLoGin 
8*f2022a8aSLoGin use super::{
9*f2022a8aSLoGin     entry::{set_intr_gate, set_system_trap_gate},
10*f2022a8aSLoGin     TrapFrame,
11*f2022a8aSLoGin };
12*f2022a8aSLoGin 
13*f2022a8aSLoGin extern "C" {
14*f2022a8aSLoGin     fn trap_divide_error();
15*f2022a8aSLoGin     fn trap_debug();
16*f2022a8aSLoGin     fn trap_nmi();
17*f2022a8aSLoGin     fn trap_int3();
18*f2022a8aSLoGin     fn trap_overflow();
19*f2022a8aSLoGin     fn trap_bounds();
20*f2022a8aSLoGin     fn trap_undefined_opcode();
21*f2022a8aSLoGin     fn trap_dev_not_avaliable();
22*f2022a8aSLoGin     fn trap_double_fault();
23*f2022a8aSLoGin     fn trap_coprocessor_segment_overrun();
24*f2022a8aSLoGin     fn trap_invalid_TSS();
25*f2022a8aSLoGin     fn trap_segment_not_exists();
26*f2022a8aSLoGin     fn trap_stack_segment_fault();
27*f2022a8aSLoGin     fn trap_general_protection();
28*f2022a8aSLoGin     fn trap_page_fault();
29*f2022a8aSLoGin     fn trap_x87_FPU_error();
30*f2022a8aSLoGin     fn trap_alignment_check();
31*f2022a8aSLoGin     fn trap_machine_check();
32*f2022a8aSLoGin     fn trap_SIMD_exception();
33*f2022a8aSLoGin     fn trap_virtualization_exception();
34*f2022a8aSLoGin }
35*f2022a8aSLoGin 
36*f2022a8aSLoGin #[inline(never)]
37*f2022a8aSLoGin pub fn arch_trap_init() -> Result<(), SystemError> {
38*f2022a8aSLoGin     unsafe {
39*f2022a8aSLoGin         set_intr_gate(0, 0, VirtAddr::new(trap_divide_error as usize));
40*f2022a8aSLoGin         set_intr_gate(1, 0, VirtAddr::new(trap_debug as usize));
41*f2022a8aSLoGin         set_intr_gate(2, 0, VirtAddr::new(trap_nmi as usize));
42*f2022a8aSLoGin         set_system_trap_gate(3, 0, VirtAddr::new(trap_int3 as usize));
43*f2022a8aSLoGin         set_system_trap_gate(4, 0, VirtAddr::new(trap_overflow as usize));
44*f2022a8aSLoGin         set_system_trap_gate(5, 0, VirtAddr::new(trap_bounds as usize));
45*f2022a8aSLoGin         set_intr_gate(6, 0, VirtAddr::new(trap_undefined_opcode as usize));
46*f2022a8aSLoGin         set_intr_gate(7, 0, VirtAddr::new(trap_dev_not_avaliable as usize));
47*f2022a8aSLoGin         set_intr_gate(8, 0, VirtAddr::new(trap_double_fault as usize));
48*f2022a8aSLoGin         set_intr_gate(
49*f2022a8aSLoGin             9,
50*f2022a8aSLoGin             0,
51*f2022a8aSLoGin             VirtAddr::new(trap_coprocessor_segment_overrun as usize),
52*f2022a8aSLoGin         );
53*f2022a8aSLoGin         set_intr_gate(10, 0, VirtAddr::new(trap_invalid_TSS as usize));
54*f2022a8aSLoGin         set_intr_gate(11, 0, VirtAddr::new(trap_segment_not_exists as usize));
55*f2022a8aSLoGin         set_intr_gate(12, 0, VirtAddr::new(trap_stack_segment_fault as usize));
56*f2022a8aSLoGin         set_intr_gate(13, 0, VirtAddr::new(trap_general_protection as usize));
57*f2022a8aSLoGin         set_intr_gate(14, 0, VirtAddr::new(trap_page_fault as usize));
58*f2022a8aSLoGin         // 中断号15由Intel保留,不能使用
59*f2022a8aSLoGin         set_intr_gate(16, 0, VirtAddr::new(trap_x87_FPU_error as usize));
60*f2022a8aSLoGin         set_intr_gate(17, 0, VirtAddr::new(trap_alignment_check as usize));
61*f2022a8aSLoGin         set_intr_gate(18, 0, VirtAddr::new(trap_machine_check as usize));
62*f2022a8aSLoGin         set_intr_gate(19, 0, VirtAddr::new(trap_SIMD_exception as usize));
63*f2022a8aSLoGin         set_intr_gate(20, 0, VirtAddr::new(trap_virtualization_exception as usize));
64*f2022a8aSLoGin     }
65*f2022a8aSLoGin     return Ok(());
66*f2022a8aSLoGin }
67*f2022a8aSLoGin 
68*f2022a8aSLoGin /// 处理除法错误 0 #DE
69*f2022a8aSLoGin #[no_mangle]
70*f2022a8aSLoGin unsafe extern "C" fn do_divide_error(regs: &'static TrapFrame, error_code: u64) {
71*f2022a8aSLoGin     kerror!(
72*f2022a8aSLoGin         "do_divide_error(0), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
73*f2022a8aSLoGin         error_code,
74*f2022a8aSLoGin         regs.rsp,
75*f2022a8aSLoGin         regs.rip,
76*f2022a8aSLoGin         smp_get_processor_id(),
77*f2022a8aSLoGin         ProcessManager::current_pid()
78*f2022a8aSLoGin     );
79*f2022a8aSLoGin     panic!("Divide Error");
80*f2022a8aSLoGin }
81*f2022a8aSLoGin 
82*f2022a8aSLoGin /// 处理调试异常 1 #DB
83*f2022a8aSLoGin #[no_mangle]
84*f2022a8aSLoGin unsafe extern "C" fn do_debug(regs: &'static TrapFrame, error_code: u64) {
85*f2022a8aSLoGin     kerror!(
86*f2022a8aSLoGin         "do_debug(1), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
87*f2022a8aSLoGin         error_code,
88*f2022a8aSLoGin         regs.rsp,
89*f2022a8aSLoGin         regs.rip,
90*f2022a8aSLoGin         smp_get_processor_id(),
91*f2022a8aSLoGin         ProcessManager::current_pid()
92*f2022a8aSLoGin     );
93*f2022a8aSLoGin     panic!("Debug Exception");
94*f2022a8aSLoGin }
95*f2022a8aSLoGin 
96*f2022a8aSLoGin /// 处理NMI中断 2 NMI
97*f2022a8aSLoGin #[no_mangle]
98*f2022a8aSLoGin unsafe extern "C" fn do_nmi(regs: &'static TrapFrame, error_code: u64) {
99*f2022a8aSLoGin     kerror!(
100*f2022a8aSLoGin         "do_nmi(2), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
101*f2022a8aSLoGin         error_code,
102*f2022a8aSLoGin         regs.rsp,
103*f2022a8aSLoGin         regs.rip,
104*f2022a8aSLoGin         smp_get_processor_id(),
105*f2022a8aSLoGin         ProcessManager::current_pid()
106*f2022a8aSLoGin     );
107*f2022a8aSLoGin     panic!("NMI Interrupt");
108*f2022a8aSLoGin }
109*f2022a8aSLoGin 
110*f2022a8aSLoGin /// 处理断点异常 3 #BP
111*f2022a8aSLoGin #[no_mangle]
112*f2022a8aSLoGin unsafe extern "C" fn do_int3(regs: &'static TrapFrame, error_code: u64) {
113*f2022a8aSLoGin     kerror!(
114*f2022a8aSLoGin         "do_int3(3), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
115*f2022a8aSLoGin         error_code,
116*f2022a8aSLoGin         regs.rsp,
117*f2022a8aSLoGin         regs.rip,
118*f2022a8aSLoGin         smp_get_processor_id(),
119*f2022a8aSLoGin         ProcessManager::current_pid()
120*f2022a8aSLoGin     );
121*f2022a8aSLoGin     panic!("Int3");
122*f2022a8aSLoGin }
123*f2022a8aSLoGin 
124*f2022a8aSLoGin /// 处理溢出异常 4 #OF
125*f2022a8aSLoGin #[no_mangle]
126*f2022a8aSLoGin unsafe extern "C" fn do_overflow(regs: &'static TrapFrame, error_code: u64) {
127*f2022a8aSLoGin     kerror!(
128*f2022a8aSLoGin         "do_overflow(4), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
129*f2022a8aSLoGin         error_code,
130*f2022a8aSLoGin         regs.rsp,
131*f2022a8aSLoGin         regs.rip,
132*f2022a8aSLoGin         smp_get_processor_id(),
133*f2022a8aSLoGin         ProcessManager::current_pid()
134*f2022a8aSLoGin     );
135*f2022a8aSLoGin     panic!("Overflow Exception");
136*f2022a8aSLoGin }
137*f2022a8aSLoGin 
138*f2022a8aSLoGin /// 处理BOUND指令检查异常 5 #BR
139*f2022a8aSLoGin #[no_mangle]
140*f2022a8aSLoGin unsafe extern "C" fn do_bounds(regs: &'static TrapFrame, error_code: u64) {
141*f2022a8aSLoGin     kerror!(
142*f2022a8aSLoGin         "do_bounds(5), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
143*f2022a8aSLoGin         error_code,
144*f2022a8aSLoGin         regs.rsp,
145*f2022a8aSLoGin         regs.rip,
146*f2022a8aSLoGin         smp_get_processor_id(),
147*f2022a8aSLoGin         ProcessManager::current_pid()
148*f2022a8aSLoGin     );
149*f2022a8aSLoGin     panic!("Bounds Check");
150*f2022a8aSLoGin }
151*f2022a8aSLoGin 
152*f2022a8aSLoGin /// 处理未定义操作码异常 6 #UD
153*f2022a8aSLoGin #[no_mangle]
154*f2022a8aSLoGin unsafe extern "C" fn do_undefined_opcode(regs: &'static TrapFrame, error_code: u64) {
155*f2022a8aSLoGin     kerror!(
156*f2022a8aSLoGin         "do_undefined_opcode(6), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
157*f2022a8aSLoGin         error_code,
158*f2022a8aSLoGin         regs.rsp,
159*f2022a8aSLoGin         regs.rip,
160*f2022a8aSLoGin         smp_get_processor_id(),
161*f2022a8aSLoGin         ProcessManager::current_pid()
162*f2022a8aSLoGin     );
163*f2022a8aSLoGin     panic!("Undefined Opcode");
164*f2022a8aSLoGin }
165*f2022a8aSLoGin 
166*f2022a8aSLoGin /// 处理设备不可用异常(FPU不存在) 7 #NM
167*f2022a8aSLoGin #[no_mangle]
168*f2022a8aSLoGin unsafe extern "C" fn do_dev_not_avaliable(regs: &'static TrapFrame, error_code: u64) {
169*f2022a8aSLoGin     kerror!(
170*f2022a8aSLoGin         "do_dev_not_avaliable(7), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
171*f2022a8aSLoGin         error_code,
172*f2022a8aSLoGin         regs.rsp,
173*f2022a8aSLoGin         regs.rip,
174*f2022a8aSLoGin         smp_get_processor_id(),
175*f2022a8aSLoGin         ProcessManager::current_pid()
176*f2022a8aSLoGin     );
177*f2022a8aSLoGin     panic!("Device Not Available");
178*f2022a8aSLoGin }
179*f2022a8aSLoGin 
180*f2022a8aSLoGin /// 处理双重错误 8 #DF
181*f2022a8aSLoGin #[no_mangle]
182*f2022a8aSLoGin unsafe extern "C" fn do_double_fault(regs: &'static TrapFrame, error_code: u64) {
183*f2022a8aSLoGin     kerror!(
184*f2022a8aSLoGin         "do_double_fault(8), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
185*f2022a8aSLoGin         error_code,
186*f2022a8aSLoGin         regs.rsp,
187*f2022a8aSLoGin         regs.rip,
188*f2022a8aSLoGin         smp_get_processor_id(),
189*f2022a8aSLoGin         ProcessManager::current_pid()
190*f2022a8aSLoGin     );
191*f2022a8aSLoGin     panic!("Double Fault");
192*f2022a8aSLoGin }
193*f2022a8aSLoGin 
194*f2022a8aSLoGin /// 处理协处理器段越界 9 #MF
195*f2022a8aSLoGin #[no_mangle]
196*f2022a8aSLoGin unsafe extern "C" fn do_coprocessor_segment_overrun(regs: &'static TrapFrame, error_code: u64) {
197*f2022a8aSLoGin     kerror!(
198*f2022a8aSLoGin         "do_coprocessor_segment_overrun(9), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
199*f2022a8aSLoGin         error_code,
200*f2022a8aSLoGin         regs.rsp,
201*f2022a8aSLoGin         regs.rip,
202*f2022a8aSLoGin         smp_get_processor_id(),
203*f2022a8aSLoGin         ProcessManager::current_pid()
204*f2022a8aSLoGin     );
205*f2022a8aSLoGin     panic!("Coprocessor Segment Overrun");
206*f2022a8aSLoGin }
207*f2022a8aSLoGin 
208*f2022a8aSLoGin /// 处理无效TSS 10 #TS
209*f2022a8aSLoGin #[no_mangle]
210*f2022a8aSLoGin unsafe extern "C" fn do_invalid_TSS(regs: &'static TrapFrame, error_code: u64) {
211*f2022a8aSLoGin     const ERR_MSG_1: &str =
212*f2022a8aSLoGin         "The exception occurred during delivery of an event external to the program.\n";
213*f2022a8aSLoGin     const ERR_MSG_2: &str = "Refers to a descriptor in the IDT.\n";
214*f2022a8aSLoGin     const ERR_MSG_3: &str = "Refers to a descriptor in the current LDT.\n";
215*f2022a8aSLoGin     const ERR_MSG_4: &str = "Refers to a descriptor in the GDT.\n";
216*f2022a8aSLoGin 
217*f2022a8aSLoGin     let msg1: &str;
218*f2022a8aSLoGin     if (error_code & 0x1) != 0 {
219*f2022a8aSLoGin         msg1 = ERR_MSG_1;
220*f2022a8aSLoGin     } else {
221*f2022a8aSLoGin         msg1 = "";
222*f2022a8aSLoGin     }
223*f2022a8aSLoGin 
224*f2022a8aSLoGin     let msg2: &str;
225*f2022a8aSLoGin     if (error_code & 0x02) != 0 {
226*f2022a8aSLoGin         msg2 = ERR_MSG_2;
227*f2022a8aSLoGin     } else {
228*f2022a8aSLoGin         if (error_code & 0x04) != 0 {
229*f2022a8aSLoGin             msg2 = ERR_MSG_3;
230*f2022a8aSLoGin         } else {
231*f2022a8aSLoGin             msg2 = ERR_MSG_4;
232*f2022a8aSLoGin         }
233*f2022a8aSLoGin     }
234*f2022a8aSLoGin     kerror!(
235*f2022a8aSLoGin         "do_invalid_TSS(10), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}\n{}{}",
236*f2022a8aSLoGin         error_code,
237*f2022a8aSLoGin         regs.rsp,
238*f2022a8aSLoGin         regs.rip,
239*f2022a8aSLoGin         smp_get_processor_id(),
240*f2022a8aSLoGin         ProcessManager::current_pid(),
241*f2022a8aSLoGin         msg1,
242*f2022a8aSLoGin         msg2
243*f2022a8aSLoGin     );
244*f2022a8aSLoGin     panic!("Invalid TSS");
245*f2022a8aSLoGin }
246*f2022a8aSLoGin 
247*f2022a8aSLoGin /// 处理段不存在 11 #NP
248*f2022a8aSLoGin #[no_mangle]
249*f2022a8aSLoGin unsafe extern "C" fn do_segment_not_exists(regs: &'static TrapFrame, error_code: u64) {
250*f2022a8aSLoGin     kerror!(
251*f2022a8aSLoGin         "do_segment_not_exists(11), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
252*f2022a8aSLoGin         error_code,
253*f2022a8aSLoGin         regs.rsp,
254*f2022a8aSLoGin         regs.rip,
255*f2022a8aSLoGin         smp_get_processor_id(),
256*f2022a8aSLoGin         ProcessManager::current_pid()
257*f2022a8aSLoGin     );
258*f2022a8aSLoGin     panic!("Segment Not Exists");
259*f2022a8aSLoGin }
260*f2022a8aSLoGin 
261*f2022a8aSLoGin /// 处理栈段错误 12 #SS
262*f2022a8aSLoGin #[no_mangle]
263*f2022a8aSLoGin unsafe extern "C" fn do_stack_segment_fault(regs: &'static TrapFrame, error_code: u64) {
264*f2022a8aSLoGin     kerror!(
265*f2022a8aSLoGin         "do_stack_segment_fault(12), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
266*f2022a8aSLoGin         error_code,
267*f2022a8aSLoGin         regs.rsp,
268*f2022a8aSLoGin         regs.rip,
269*f2022a8aSLoGin         smp_get_processor_id(),
270*f2022a8aSLoGin         ProcessManager::current_pid()
271*f2022a8aSLoGin     );
272*f2022a8aSLoGin     panic!("Stack Segment Fault");
273*f2022a8aSLoGin }
274*f2022a8aSLoGin 
275*f2022a8aSLoGin /// 处理一般保护异常 13 #GP
276*f2022a8aSLoGin #[no_mangle]
277*f2022a8aSLoGin unsafe extern "C" fn do_general_protection(regs: &'static TrapFrame, error_code: u64) {
278*f2022a8aSLoGin     const ERR_MSG_1: &str = "The exception occurred during delivery of an event external to the program, such as an interrupt or an earlier exception.";
279*f2022a8aSLoGin     const ERR_MSG_2: &str = "Refers to a gate descriptor in the IDT;\n";
280*f2022a8aSLoGin     const ERR_MSG_3: &str = "Refers to a descriptor in the GDT or the current LDT;\n";
281*f2022a8aSLoGin     const ERR_MSG_4: &str = "Refers to a segment or gate descriptor in the LDT;\n";
282*f2022a8aSLoGin     const ERR_MSG_5: &str = "Refers to a descriptor in the current GDT;\n";
283*f2022a8aSLoGin 
284*f2022a8aSLoGin     let msg1: &str;
285*f2022a8aSLoGin     if (error_code & 0x1) != 0 {
286*f2022a8aSLoGin         msg1 = ERR_MSG_1;
287*f2022a8aSLoGin     } else {
288*f2022a8aSLoGin         msg1 = "";
289*f2022a8aSLoGin     }
290*f2022a8aSLoGin 
291*f2022a8aSLoGin     let msg2: &str;
292*f2022a8aSLoGin     if (error_code & 0x02) != 0 {
293*f2022a8aSLoGin         msg2 = ERR_MSG_2;
294*f2022a8aSLoGin     } else {
295*f2022a8aSLoGin         msg2 = ERR_MSG_3;
296*f2022a8aSLoGin     }
297*f2022a8aSLoGin 
298*f2022a8aSLoGin     let msg3: &str;
299*f2022a8aSLoGin     if (error_code & 0x02) == 0 {
300*f2022a8aSLoGin         if (error_code & 0x04) != 0 {
301*f2022a8aSLoGin             msg3 = ERR_MSG_4;
302*f2022a8aSLoGin         } else {
303*f2022a8aSLoGin             msg3 = ERR_MSG_5;
304*f2022a8aSLoGin         }
305*f2022a8aSLoGin     } else {
306*f2022a8aSLoGin         msg3 = "";
307*f2022a8aSLoGin     }
308*f2022a8aSLoGin     kerror!(
309*f2022a8aSLoGin         "do_general_protection(13), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}
310*f2022a8aSLoGin {}{}{}
311*f2022a8aSLoGin Segment Selector Index: {:#x}\n
312*f2022a8aSLoGin ",
313*f2022a8aSLoGin         error_code,
314*f2022a8aSLoGin         regs.rsp,
315*f2022a8aSLoGin         regs.rip,
316*f2022a8aSLoGin         smp_get_processor_id(),
317*f2022a8aSLoGin         ProcessManager::current_pid(),
318*f2022a8aSLoGin         msg1, msg2, msg3,
319*f2022a8aSLoGin         error_code & 0xfff8
320*f2022a8aSLoGin     );
321*f2022a8aSLoGin     panic!("General Protection");
322*f2022a8aSLoGin }
323*f2022a8aSLoGin 
324*f2022a8aSLoGin /// 处理页错误 14 #PF
325*f2022a8aSLoGin #[no_mangle]
326*f2022a8aSLoGin unsafe extern "C" fn do_page_fault(regs: &'static TrapFrame, error_code: u64) {
327*f2022a8aSLoGin     kerror!(
328*f2022a8aSLoGin         "do_page_fault(14), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}, \nFault Address: {:#x}",
329*f2022a8aSLoGin         error_code,
330*f2022a8aSLoGin         regs.rsp,
331*f2022a8aSLoGin         regs.rip,
332*f2022a8aSLoGin         smp_get_processor_id(),
333*f2022a8aSLoGin         ProcessManager::current_pid(),
334*f2022a8aSLoGin         x86::controlregs::cr2()
335*f2022a8aSLoGin     );
336*f2022a8aSLoGin 
337*f2022a8aSLoGin     if (error_code & 0x01) == 0 {
338*f2022a8aSLoGin         print!("Page Not Present,\t");
339*f2022a8aSLoGin     }
340*f2022a8aSLoGin     if (error_code & 0x02) != 0 {
341*f2022a8aSLoGin         print!("Write Access,\t");
342*f2022a8aSLoGin     } else {
343*f2022a8aSLoGin         print!("Read Access,\t");
344*f2022a8aSLoGin     }
345*f2022a8aSLoGin 
346*f2022a8aSLoGin     if (error_code & 0x04) != 0 {
347*f2022a8aSLoGin         print!("Fault in user(3),\t");
348*f2022a8aSLoGin     } else {
349*f2022a8aSLoGin         print!("Fault in supervisor(0,1,2),\t");
350*f2022a8aSLoGin     }
351*f2022a8aSLoGin 
352*f2022a8aSLoGin     if (error_code & 0x08) != 0 {
353*f2022a8aSLoGin         print!("Reserved bit violation cause fault,\t");
354*f2022a8aSLoGin     }
355*f2022a8aSLoGin 
356*f2022a8aSLoGin     if (error_code & 0x10) != 0 {
357*f2022a8aSLoGin         print!("Instruction fetch cause fault,\t");
358*f2022a8aSLoGin     }
359*f2022a8aSLoGin     print!("\n");
360*f2022a8aSLoGin 
361*f2022a8aSLoGin     CurrentIrqArch::interrupt_enable();
362*f2022a8aSLoGin     panic!("Page Fault");
363*f2022a8aSLoGin }
364*f2022a8aSLoGin 
365*f2022a8aSLoGin /// 处理x87 FPU错误 16 #MF
366*f2022a8aSLoGin #[no_mangle]
367*f2022a8aSLoGin unsafe extern "C" fn do_x87_FPU_error(regs: &'static TrapFrame, error_code: u64) {
368*f2022a8aSLoGin     kerror!(
369*f2022a8aSLoGin         "do_x87_FPU_error(16), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
370*f2022a8aSLoGin         error_code,
371*f2022a8aSLoGin         regs.rsp,
372*f2022a8aSLoGin         regs.rip,
373*f2022a8aSLoGin         smp_get_processor_id(),
374*f2022a8aSLoGin         ProcessManager::current_pid()
375*f2022a8aSLoGin     );
376*f2022a8aSLoGin     panic!("x87 FPU Error");
377*f2022a8aSLoGin }
378*f2022a8aSLoGin 
379*f2022a8aSLoGin /// 处理对齐检查 17 #AC
380*f2022a8aSLoGin #[no_mangle]
381*f2022a8aSLoGin unsafe extern "C" fn do_alignment_check(regs: &'static TrapFrame, error_code: u64) {
382*f2022a8aSLoGin     kerror!(
383*f2022a8aSLoGin         "do_alignment_check(17), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
384*f2022a8aSLoGin         error_code,
385*f2022a8aSLoGin         regs.rsp,
386*f2022a8aSLoGin         regs.rip,
387*f2022a8aSLoGin         smp_get_processor_id(),
388*f2022a8aSLoGin         ProcessManager::current_pid()
389*f2022a8aSLoGin     );
390*f2022a8aSLoGin     panic!("Alignment Check");
391*f2022a8aSLoGin }
392*f2022a8aSLoGin 
393*f2022a8aSLoGin /// 处理机器检查 18 #MC
394*f2022a8aSLoGin #[no_mangle]
395*f2022a8aSLoGin unsafe extern "C" fn do_machine_check(regs: &'static TrapFrame, error_code: u64) {
396*f2022a8aSLoGin     kerror!(
397*f2022a8aSLoGin         "do_machine_check(18), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
398*f2022a8aSLoGin         error_code,
399*f2022a8aSLoGin         regs.rsp,
400*f2022a8aSLoGin         regs.rip,
401*f2022a8aSLoGin         smp_get_processor_id(),
402*f2022a8aSLoGin         ProcessManager::current_pid()
403*f2022a8aSLoGin     );
404*f2022a8aSLoGin     panic!("Machine Check");
405*f2022a8aSLoGin }
406*f2022a8aSLoGin 
407*f2022a8aSLoGin /// 处理SIMD异常 19 #XM
408*f2022a8aSLoGin #[no_mangle]
409*f2022a8aSLoGin unsafe extern "C" fn do_SIMD_exception(regs: &'static TrapFrame, error_code: u64) {
410*f2022a8aSLoGin     kerror!(
411*f2022a8aSLoGin         "do_SIMD_exception(19), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
412*f2022a8aSLoGin         error_code,
413*f2022a8aSLoGin         regs.rsp,
414*f2022a8aSLoGin         regs.rip,
415*f2022a8aSLoGin         smp_get_processor_id(),
416*f2022a8aSLoGin         ProcessManager::current_pid()
417*f2022a8aSLoGin     );
418*f2022a8aSLoGin     panic!("SIMD Exception");
419*f2022a8aSLoGin }
420*f2022a8aSLoGin 
421*f2022a8aSLoGin /// 处理虚拟化异常 20 #VE
422*f2022a8aSLoGin #[no_mangle]
423*f2022a8aSLoGin unsafe extern "C" fn do_virtualization_exception(regs: &'static TrapFrame, error_code: u64) {
424*f2022a8aSLoGin     kerror!(
425*f2022a8aSLoGin         "do_virtualization_exception(20), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}",
426*f2022a8aSLoGin         error_code,
427*f2022a8aSLoGin         regs.rsp,
428*f2022a8aSLoGin         regs.rip,
429*f2022a8aSLoGin         smp_get_processor_id(),
430*f2022a8aSLoGin         ProcessManager::current_pid()
431*f2022a8aSLoGin     );
432*f2022a8aSLoGin     panic!("Virtualization Exception");
433*f2022a8aSLoGin }
434*f2022a8aSLoGin 
435*f2022a8aSLoGin #[no_mangle]
436*f2022a8aSLoGin unsafe extern "C" fn ignore_int_handler(_regs: &'static TrapFrame, _error_code: u64) {
437*f2022a8aSLoGin     kwarn!("Unknown interrupt.");
438*f2022a8aSLoGin }
439