|
| 1 | +use crate::TrapFrame; |
| 2 | + |
| 3 | +extern "C" { |
| 4 | + fn InstructionMisaligned(trap_frame: &TrapFrame); |
| 5 | + fn InstructionFault(trap_frame: &TrapFrame); |
| 6 | + fn IllegalInstruction(trap_frame: &TrapFrame); |
| 7 | + fn Breakpoint(trap_frame: &TrapFrame); |
| 8 | + fn LoadMisaligned(trap_frame: &TrapFrame); |
| 9 | + fn LoadFault(trap_frame: &TrapFrame); |
| 10 | + fn StoreMisaligned(trap_frame: &TrapFrame); |
| 11 | + fn StoreFault(trap_frame: &TrapFrame); |
| 12 | + fn UserEnvCall(trap_frame: &TrapFrame); |
| 13 | + fn SupervisorEnvCall(trap_frame: &TrapFrame); |
| 14 | + fn MachineEnvCall(trap_frame: &TrapFrame); |
| 15 | + fn InstructionPageFault(trap_frame: &TrapFrame); |
| 16 | + fn LoadPageFault(trap_frame: &TrapFrame); |
| 17 | + fn StorePageFault(trap_frame: &TrapFrame); |
| 18 | + fn ExceptionHandler(trap_frame: &TrapFrame); |
| 19 | +} |
| 20 | + |
| 21 | +#[doc(hidden)] |
| 22 | +#[no_mangle] |
| 23 | +pub static __EXCEPTIONS: [Option<unsafe extern "C" fn(&TrapFrame)>; 16] = [ |
| 24 | + Some(InstructionMisaligned), |
| 25 | + Some(InstructionFault), |
| 26 | + Some(IllegalInstruction), |
| 27 | + Some(Breakpoint), |
| 28 | + Some(LoadMisaligned), |
| 29 | + Some(LoadFault), |
| 30 | + Some(StoreMisaligned), |
| 31 | + Some(StoreFault), |
| 32 | + Some(UserEnvCall), |
| 33 | + Some(SupervisorEnvCall), |
| 34 | + None, |
| 35 | + Some(MachineEnvCall), |
| 36 | + Some(InstructionPageFault), |
| 37 | + Some(LoadPageFault), |
| 38 | + None, |
| 39 | + Some(StorePageFault), |
| 40 | +]; |
| 41 | + |
| 42 | +#[export_name = "_dispatch_exception"] |
| 43 | +#[inline] |
| 44 | +unsafe extern "C" fn dispatch_exception(trap_frame: &TrapFrame, code: usize) { |
| 45 | + if code < __EXCEPTIONS.len() { |
| 46 | + match &__EXCEPTIONS[code] { |
| 47 | + Some(handler) => handler(trap_frame), |
| 48 | + None => ExceptionHandler(trap_frame), |
| 49 | + } |
| 50 | + } else { |
| 51 | + ExceptionHandler(trap_frame); |
| 52 | + } |
| 53 | +} |
0 commit comments