1 /// Represents supported CPU exceptions. 2 #[repr(C)] 3 #[derive(Debug)] 4 pub struct ExceptionType(isize); 5 6 impl ExceptionType { 7 /// Undefined Exception 8 pub const EXCEPT_EBC_UNDEFINED: Self = Self(0); 9 /// Divide-by-zero Error 10 pub const EXCEPT_EBC_DIVIDE_ERROR: Self = Self(1); 11 /// Debug Exception 12 pub const EXCEPT_EBC_DEBUG: Self = Self(2); 13 /// Breakpoint 14 pub const EXCEPT_EBC_BREAKPOINT: Self = Self(3); 15 /// Overflow 16 pub const EXCEPT_EBC_OVERFLOW: Self = Self(4); 17 /// Invalid Opcode 18 pub const EXCEPT_EBC_INVALID_OPCODE: Self = Self(5); 19 /// Stack-Segment Fault 20 pub const EXCEPT_EBC_STACK_FAULT: Self = Self(6); 21 /// Alignment Check 22 pub const EXCEPT_EBC_ALIGNMENT_CHECK: Self = Self(7); 23 /// Instruction Encoding Exception 24 pub const EXCEPT_EBC_INSTRUCTION_ENCODING: Self = Self(8); 25 /// Bad Breakpoint Exception 26 pub const EXCEPT_EBC_BAD_BREAK: Self = Self(9); 27 /// Single Step Exception 28 pub const EXCEPT_EBC_SINGLE_STEP: Self = Self(10); 29 } 30 31 #[cfg(target_arch = "x86")] 32 impl ExceptionType { 33 /// Divide-by-zero Error 34 pub const EXCEPT_IA32_DIVIDE_ERROR: ExceptionType = ExceptionType(0); 35 /// Debug Exception 36 pub const EXCEPT_IA32_DEBUG: ExceptionType = ExceptionType(1); 37 /// Non-maskable Interrupt 38 pub const EXCEPT_IA32_NMI: ExceptionType = ExceptionType(2); 39 /// Breakpoint 40 pub const EXCEPT_IA32_BREAKPOINT: ExceptionType = ExceptionType(3); 41 /// Overflow 42 pub const EXCEPT_IA32_OVERFLOW: ExceptionType = ExceptionType(4); 43 /// Bound Range Exceeded 44 pub const EXCEPT_IA32_BOUND: ExceptionType = ExceptionType(5); 45 /// Invalid Opcode 46 pub const EXCEPT_IA32_INVALID_OPCODE: ExceptionType = ExceptionType(6); 47 /// Double Fault 48 pub const EXCEPT_IA32_DOUBLE_FAULT: ExceptionType = ExceptionType(8); 49 /// Invalid TSS 50 pub const EXCEPT_IA32_INVALID_TSS: ExceptionType = ExceptionType(10); 51 /// Segment Not Present 52 pub const EXCEPT_IA32_SEG_NOT_PRESENT: ExceptionType = ExceptionType(11); 53 /// Stack-Segment Fault 54 pub const EXCEPT_IA32_STACK_FAULT: ExceptionType = ExceptionType(12); 55 /// General Protection Fault 56 pub const EXCEPT_IA32_GP_FAULT: ExceptionType = ExceptionType(13); 57 /// Page Fault 58 pub const EXCEPT_IA32_PAGE_FAULT: ExceptionType = ExceptionType(14); 59 /// x87 Floating-Point Exception 60 pub const EXCEPT_IA32_FP_ERROR: ExceptionType = ExceptionType(16); 61 /// Alignment Check 62 pub const EXCEPT_IA32_ALIGNMENT_CHECK: ExceptionType = ExceptionType(17); 63 /// Machine Check 64 pub const EXCEPT_IA32_MACHINE_CHECK: ExceptionType = ExceptionType(18); 65 /// SIMD Floating-Point Exception 66 pub const EXCEPT_IA32_SIMD: ExceptionType = ExceptionType(19); 67 } 68 69 #[cfg(target_arch = "x86_64")] 70 impl ExceptionType { 71 /// Divide-by-zero Error 72 pub const EXCEPT_X64_DIVIDE_ERROR: Self = Self(0); 73 /// Debug Exception 74 pub const EXCEPT_X64_DEBUG: Self = Self(1); 75 /// Non-maskable Interrupt 76 pub const EXCEPT_X64_NMI: Self = Self(2); 77 /// Breakpoint 78 pub const EXCEPT_X64_BREAKPOINT: Self = Self(3); 79 /// Overflow 80 pub const EXCEPT_X64_OVERFLOW: Self = Self(4); 81 /// Bound Range Exceeded 82 pub const EXCEPT_X64_BOUND: Self = Self(5); 83 /// Invalid Opcode 84 pub const EXCEPT_X64_INVALID_OPCODE: Self = Self(6); 85 /// Double Fault 86 pub const EXCEPT_X64_DOUBLE_FAULT: Self = Self(8); 87 /// Invalid TSS 88 pub const EXCEPT_X64_INVALID_TSS: Self = Self(10); 89 /// Segment Not Present 90 pub const EXCEPT_X64_SEG_NOT_PRESENT: Self = Self(11); 91 /// Stack-Segment Fault 92 pub const EXCEPT_X64_STACK_FAULT: Self = Self(12); 93 /// General Protection Fault 94 pub const EXCEPT_X64_GP_FAULT: Self = Self(13); 95 /// Page Fault 96 pub const EXCEPT_X64_PAGE_FAULT: Self = Self(14); 97 /// x87 Floating-Point Exception 98 pub const EXCEPT_X64_FP_ERROR: Self = Self(16); 99 /// Alignment Check 100 pub const EXCEPT_X64_ALIGNMENT_CHECK: Self = Self(17); 101 /// Machine Check 102 pub const EXCEPT_X64_MACHINE_CHECK: Self = Self(18); 103 /// SIMD Floating-Point Exception 104 pub const EXCEPT_X64_SIMD: Self = Self(19); 105 } 106 107 #[cfg(target_arch = "arm")] 108 impl ExceptionType { 109 /// Processor reset 110 pub const EXCEPT_ARM_RESET: ExceptionType = ExceptionType(0); 111 /// Undefined instruction 112 pub const EXCEPT_ARM_UNDEFINED_INSTRUCTION: ExceptionType = ExceptionType(1); 113 /// Software Interrupt 114 pub const EXCEPT_ARM_SOFTWARE_INTERRUPT: ExceptionType = ExceptionType(2); 115 /// Prefetch aborted 116 pub const EXCEPT_ARM_PREFETCH_ABORT: ExceptionType = ExceptionType(3); 117 /// Data access memory abort 118 pub const EXCEPT_ARM_DATA_ABORT: ExceptionType = ExceptionType(4); 119 /// Reserved 120 pub const EXCEPT_ARM_RESERVED: ExceptionType = ExceptionType(5); 121 /// Normal interrupt 122 pub const EXCEPT_ARM_IRQ: ExceptionType = ExceptionType(6); 123 /// Fast interrupt 124 pub const EXCEPT_ARM_FIQ: ExceptionType = ExceptionType(7); 125 /// In the UEFI spec for "convenience", unsure if we'll need it. Set to `EXCEPT_ARM_FIQ` 126 pub const MAX_ARM_EXCEPTION: ExceptionType = ExceptionType::EXCEPT_ARM_FIQ; 127 } 128 129 #[cfg(target_arch = "aarch64")] 130 impl ExceptionType { 131 /// Synchronous exception, such as attempting to execute an invalid instruction 132 pub const EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS: ExceptionType = ExceptionType(0); 133 /// Normal interrupt 134 pub const EXCEPT_AARCH64_IRQ: ExceptionType = ExceptionType(1); 135 /// Fast interrupt 136 pub const EXCEPT_AARCH64_FIQ: ExceptionType = ExceptionType(2); 137 /// System Error 138 pub const EXCEPT_AARCH64_SERROR: ExceptionType = ExceptionType(3); 139 /// In the UEFI spec for "convenience", unsure if we'll need it. Set to `EXCEPT_AARCH64_SERROR` 140 pub const MAX_AARCH64_EXCEPTION: ExceptionType = ExceptionType::EXCEPT_AARCH64_SERROR; 141 } 142 143 #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] 144 impl ExceptionType { 145 /// Instruction misaligned 146 pub const EXCEPT_RISCV_INST_MISALIGNED: ExceptionType = ExceptionType(0); 147 /// Instruction access fault 148 pub const EXCEPT_RISCV_INST_ACCESS_FAULT: ExceptionType = ExceptionType(1); 149 /// Illegal instruction 150 pub const EXCEPT_RISCV_ILLEGAL_INST: ExceptionType = ExceptionType(2); 151 /// Breakpoint 152 pub const EXCEPT_RISCV_BREAKPOINT: ExceptionType = ExceptionType(3); 153 /// Load address misaligned 154 pub const EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED: ExceptionType = ExceptionType(4); 155 /// Load accept fault 156 pub const EXCEPT_RISCV_LOAD_ACCESS_FAULT: ExceptionType = ExceptionType(5); 157 /// Store AMO address misaligned 158 pub const EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED: ExceptionType = ExceptionType(6); 159 /// Store AMO access fault 160 pub const EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT: ExceptionType = ExceptionType(7); 161 /// ECALL from User mode 162 pub const EXCEPT_RISCV_ENV_CALL_FROM_UMODE: ExceptionType = ExceptionType(8); 163 /// ECALL from Supervisor mode 164 pub const EXCEPT_RISCV_ENV_CALL_FROM_SMODE: ExceptionType = ExceptionType(9); 165 /// ECALL from Machine mode 166 pub const EXCEPT_RISCV_ENV_CALL_FROM_MMODE: ExceptionType = ExceptionType(11); 167 /// Instruction page fault 168 pub const EXCEPT_RISCV_INST_PAGE_FAULT: ExceptionType = ExceptionType(12); 169 /// Load page fault 170 pub const EXCEPT_RISCV_LOAD_PAGE_FAULT: ExceptionType = ExceptionType(13); 171 /// Store AMO page fault 172 pub const EXCEPT_RISCV_STORE_AMO_PAGE_FAULT: ExceptionType = ExceptionType(15); 173 // RISC-V interrupt types 174 /// Supervisor software interrupt 175 pub const EXCEPT_RISCV_SUPERVISOR_SOFTWARE_INT: ExceptionType = ExceptionType(1); 176 /// Machine software interrupt 177 pub const EXCEPT_RISCV_MACHINE_SOFTWARE_INT: ExceptionType = ExceptionType(3); 178 /// Supervisor timer interrupt 179 pub const EXCEPT_RISCV_SUPERVISOR_TIMER_INT: ExceptionType = ExceptionType(5); 180 /// Machine timer interrupt 181 pub const EXCEPT_RISCV_MACHINE_TIMER_INT: ExceptionType = ExceptionType(7); 182 /// Supervisor external interrupt 183 pub const EXCEPT_RISCV_SUPERVISOR_EXTERNAL_INT: ExceptionType = ExceptionType(9); 184 /// Machine external interrupt 185 pub const EXCEPT_RISCV_MACHINE_EXTERNAL_INT: ExceptionType = ExceptionType(11); 186 } 187