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