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, 76*e2841179SLoGin 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, 90*e2841179SLoGin 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, 104*e2841179SLoGin 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, 118*e2841179SLoGin 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, 132*e2841179SLoGin 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, 146*e2841179SLoGin 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, 160*e2841179SLoGin 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, 174*e2841179SLoGin 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, 188*e2841179SLoGin 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, 202*e2841179SLoGin 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 217f2022a8aSLoGin let msg1: &str; 218f2022a8aSLoGin if (error_code & 0x1) != 0 { 219f2022a8aSLoGin msg1 = ERR_MSG_1; 220f2022a8aSLoGin } else { 221f2022a8aSLoGin msg1 = ""; 222f2022a8aSLoGin } 223f2022a8aSLoGin 224f2022a8aSLoGin let msg2: &str; 225f2022a8aSLoGin if (error_code & 0x02) != 0 { 226f2022a8aSLoGin msg2 = ERR_MSG_2; 227f2022a8aSLoGin } else { 228f2022a8aSLoGin if (error_code & 0x04) != 0 { 229f2022a8aSLoGin msg2 = ERR_MSG_3; 230f2022a8aSLoGin } else { 231f2022a8aSLoGin msg2 = ERR_MSG_4; 232f2022a8aSLoGin } 233f2022a8aSLoGin } 234f2022a8aSLoGin kerror!( 235f2022a8aSLoGin "do_invalid_TSS(10), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}\n{}{}", 236f2022a8aSLoGin error_code, 237f2022a8aSLoGin regs.rsp, 238f2022a8aSLoGin regs.rip, 239*e2841179SLoGin smp_get_processor_id().data(), 240f2022a8aSLoGin ProcessManager::current_pid(), 241f2022a8aSLoGin msg1, 242f2022a8aSLoGin msg2 243f2022a8aSLoGin ); 244f2022a8aSLoGin panic!("Invalid TSS"); 245f2022a8aSLoGin } 246f2022a8aSLoGin 247f2022a8aSLoGin /// 处理段不存在 11 #NP 248f2022a8aSLoGin #[no_mangle] 249f2022a8aSLoGin unsafe extern "C" fn do_segment_not_exists(regs: &'static TrapFrame, error_code: u64) { 250f2022a8aSLoGin kerror!( 251f2022a8aSLoGin "do_segment_not_exists(11), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}", 252f2022a8aSLoGin error_code, 253f2022a8aSLoGin regs.rsp, 254f2022a8aSLoGin regs.rip, 255*e2841179SLoGin smp_get_processor_id().data(), 256f2022a8aSLoGin ProcessManager::current_pid() 257f2022a8aSLoGin ); 258f2022a8aSLoGin panic!("Segment Not Exists"); 259f2022a8aSLoGin } 260f2022a8aSLoGin 261f2022a8aSLoGin /// 处理栈段错误 12 #SS 262f2022a8aSLoGin #[no_mangle] 263f2022a8aSLoGin unsafe extern "C" fn do_stack_segment_fault(regs: &'static TrapFrame, error_code: u64) { 264f2022a8aSLoGin kerror!( 265f2022a8aSLoGin "do_stack_segment_fault(12), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}", 266f2022a8aSLoGin error_code, 267f2022a8aSLoGin regs.rsp, 268f2022a8aSLoGin regs.rip, 269*e2841179SLoGin smp_get_processor_id().data(), 270f2022a8aSLoGin ProcessManager::current_pid() 271f2022a8aSLoGin ); 272f2022a8aSLoGin panic!("Stack Segment Fault"); 273f2022a8aSLoGin } 274f2022a8aSLoGin 275f2022a8aSLoGin /// 处理一般保护异常 13 #GP 276f2022a8aSLoGin #[no_mangle] 277f2022a8aSLoGin unsafe extern "C" fn do_general_protection(regs: &'static TrapFrame, error_code: u64) { 278f2022a8aSLoGin 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."; 279f2022a8aSLoGin const ERR_MSG_2: &str = "Refers to a gate descriptor in the IDT;\n"; 280f2022a8aSLoGin const ERR_MSG_3: &str = "Refers to a descriptor in the GDT or the current LDT;\n"; 281f2022a8aSLoGin const ERR_MSG_4: &str = "Refers to a segment or gate descriptor in the LDT;\n"; 282f2022a8aSLoGin const ERR_MSG_5: &str = "Refers to a descriptor in the current GDT;\n"; 283f2022a8aSLoGin 284f2022a8aSLoGin let msg1: &str; 285f2022a8aSLoGin if (error_code & 0x1) != 0 { 286f2022a8aSLoGin msg1 = ERR_MSG_1; 287f2022a8aSLoGin } else { 288f2022a8aSLoGin msg1 = ""; 289f2022a8aSLoGin } 290f2022a8aSLoGin 291f2022a8aSLoGin let msg2: &str; 292f2022a8aSLoGin if (error_code & 0x02) != 0 { 293f2022a8aSLoGin msg2 = ERR_MSG_2; 294f2022a8aSLoGin } else { 295f2022a8aSLoGin msg2 = ERR_MSG_3; 296f2022a8aSLoGin } 297f2022a8aSLoGin 298f2022a8aSLoGin let msg3: &str; 299f2022a8aSLoGin if (error_code & 0x02) == 0 { 300f2022a8aSLoGin if (error_code & 0x04) != 0 { 301f2022a8aSLoGin msg3 = ERR_MSG_4; 302f2022a8aSLoGin } else { 303f2022a8aSLoGin msg3 = ERR_MSG_5; 304f2022a8aSLoGin } 305f2022a8aSLoGin } else { 306f2022a8aSLoGin msg3 = ""; 307f2022a8aSLoGin } 308f2022a8aSLoGin kerror!( 309f2022a8aSLoGin "do_general_protection(13), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?} 310f2022a8aSLoGin {}{}{} 311f2022a8aSLoGin Segment Selector Index: {:#x}\n 312f2022a8aSLoGin ", 313f2022a8aSLoGin error_code, 314f2022a8aSLoGin regs.rsp, 315f2022a8aSLoGin regs.rip, 316*e2841179SLoGin smp_get_processor_id().data(), 317f2022a8aSLoGin ProcessManager::current_pid(), 318f2022a8aSLoGin msg1, msg2, msg3, 319f2022a8aSLoGin error_code & 0xfff8 320f2022a8aSLoGin ); 321f2022a8aSLoGin panic!("General Protection"); 322f2022a8aSLoGin } 323f2022a8aSLoGin 324f2022a8aSLoGin /// 处理页错误 14 #PF 325f2022a8aSLoGin #[no_mangle] 326f2022a8aSLoGin unsafe extern "C" fn do_page_fault(regs: &'static TrapFrame, error_code: u64) { 327f2022a8aSLoGin kerror!( 328f2022a8aSLoGin "do_page_fault(14), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}, \nFault Address: {:#x}", 329f2022a8aSLoGin error_code, 330f2022a8aSLoGin regs.rsp, 331f2022a8aSLoGin regs.rip, 332*e2841179SLoGin smp_get_processor_id().data(), 333f2022a8aSLoGin ProcessManager::current_pid(), 334f2022a8aSLoGin x86::controlregs::cr2() 335f2022a8aSLoGin ); 336f2022a8aSLoGin 337f2022a8aSLoGin if (error_code & 0x01) == 0 { 338f2022a8aSLoGin print!("Page Not Present,\t"); 339f2022a8aSLoGin } 340f2022a8aSLoGin if (error_code & 0x02) != 0 { 341f2022a8aSLoGin print!("Write Access,\t"); 342f2022a8aSLoGin } else { 343f2022a8aSLoGin print!("Read Access,\t"); 344f2022a8aSLoGin } 345f2022a8aSLoGin 346f2022a8aSLoGin if (error_code & 0x04) != 0 { 347f2022a8aSLoGin print!("Fault in user(3),\t"); 348f2022a8aSLoGin } else { 349f2022a8aSLoGin print!("Fault in supervisor(0,1,2),\t"); 350f2022a8aSLoGin } 351f2022a8aSLoGin 352f2022a8aSLoGin if (error_code & 0x08) != 0 { 353f2022a8aSLoGin print!("Reserved bit violation cause fault,\t"); 354f2022a8aSLoGin } 355f2022a8aSLoGin 356f2022a8aSLoGin if (error_code & 0x10) != 0 { 357f2022a8aSLoGin print!("Instruction fetch cause fault,\t"); 358f2022a8aSLoGin } 359f2022a8aSLoGin print!("\n"); 360f2022a8aSLoGin 361f2022a8aSLoGin CurrentIrqArch::interrupt_enable(); 362f2022a8aSLoGin panic!("Page Fault"); 363f2022a8aSLoGin } 364f2022a8aSLoGin 365f2022a8aSLoGin /// 处理x87 FPU错误 16 #MF 366f2022a8aSLoGin #[no_mangle] 367f2022a8aSLoGin unsafe extern "C" fn do_x87_FPU_error(regs: &'static TrapFrame, error_code: u64) { 368f2022a8aSLoGin kerror!( 369f2022a8aSLoGin "do_x87_FPU_error(16), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}", 370f2022a8aSLoGin error_code, 371f2022a8aSLoGin regs.rsp, 372f2022a8aSLoGin regs.rip, 373*e2841179SLoGin smp_get_processor_id().data(), 374f2022a8aSLoGin ProcessManager::current_pid() 375f2022a8aSLoGin ); 376f2022a8aSLoGin panic!("x87 FPU Error"); 377f2022a8aSLoGin } 378f2022a8aSLoGin 379f2022a8aSLoGin /// 处理对齐检查 17 #AC 380f2022a8aSLoGin #[no_mangle] 381f2022a8aSLoGin unsafe extern "C" fn do_alignment_check(regs: &'static TrapFrame, error_code: u64) { 382f2022a8aSLoGin kerror!( 383f2022a8aSLoGin "do_alignment_check(17), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}", 384f2022a8aSLoGin error_code, 385f2022a8aSLoGin regs.rsp, 386f2022a8aSLoGin regs.rip, 387*e2841179SLoGin smp_get_processor_id().data(), 388f2022a8aSLoGin ProcessManager::current_pid() 389f2022a8aSLoGin ); 390f2022a8aSLoGin panic!("Alignment Check"); 391f2022a8aSLoGin } 392f2022a8aSLoGin 393f2022a8aSLoGin /// 处理机器检查 18 #MC 394f2022a8aSLoGin #[no_mangle] 395f2022a8aSLoGin unsafe extern "C" fn do_machine_check(regs: &'static TrapFrame, error_code: u64) { 396f2022a8aSLoGin kerror!( 397f2022a8aSLoGin "do_machine_check(18), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}", 398f2022a8aSLoGin error_code, 399f2022a8aSLoGin regs.rsp, 400f2022a8aSLoGin regs.rip, 401*e2841179SLoGin smp_get_processor_id().data(), 402f2022a8aSLoGin ProcessManager::current_pid() 403f2022a8aSLoGin ); 404f2022a8aSLoGin panic!("Machine Check"); 405f2022a8aSLoGin } 406f2022a8aSLoGin 407f2022a8aSLoGin /// 处理SIMD异常 19 #XM 408f2022a8aSLoGin #[no_mangle] 409f2022a8aSLoGin unsafe extern "C" fn do_SIMD_exception(regs: &'static TrapFrame, error_code: u64) { 410f2022a8aSLoGin kerror!( 411f2022a8aSLoGin "do_SIMD_exception(19), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}", 412f2022a8aSLoGin error_code, 413f2022a8aSLoGin regs.rsp, 414f2022a8aSLoGin regs.rip, 415*e2841179SLoGin smp_get_processor_id().data(), 416f2022a8aSLoGin ProcessManager::current_pid() 417f2022a8aSLoGin ); 418f2022a8aSLoGin panic!("SIMD Exception"); 419f2022a8aSLoGin } 420f2022a8aSLoGin 421f2022a8aSLoGin /// 处理虚拟化异常 20 #VE 422f2022a8aSLoGin #[no_mangle] 423f2022a8aSLoGin unsafe extern "C" fn do_virtualization_exception(regs: &'static TrapFrame, error_code: u64) { 424f2022a8aSLoGin kerror!( 425f2022a8aSLoGin "do_virtualization_exception(20), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}", 426f2022a8aSLoGin error_code, 427f2022a8aSLoGin regs.rsp, 428f2022a8aSLoGin regs.rip, 429*e2841179SLoGin smp_get_processor_id().data(), 430f2022a8aSLoGin ProcessManager::current_pid() 431f2022a8aSLoGin ); 432f2022a8aSLoGin panic!("Virtualization Exception"); 433f2022a8aSLoGin } 434f2022a8aSLoGin 435f2022a8aSLoGin #[no_mangle] 436f2022a8aSLoGin unsafe extern "C" fn ignore_int_handler(_regs: &'static TrapFrame, _error_code: u64) { 437f2022a8aSLoGin kwarn!("Unknown interrupt."); 438f2022a8aSLoGin } 439