|
| 1 | +extern "C" { |
| 2 | + fn SupervisorSoft(); |
| 3 | + fn MachineSoft(); |
| 4 | + fn SupervisorTimer(); |
| 5 | + fn MachineTimer(); |
| 6 | + fn SupervisorExternal(); |
| 7 | + fn MachineExternal(); |
| 8 | + fn DefaultHandler(); |
| 9 | +} |
| 10 | + |
| 11 | +#[doc(hidden)] |
| 12 | +#[no_mangle] |
| 13 | +pub static __CORE_INTERRUPTS: [Option<unsafe extern "C" fn()>; 12] = [ |
| 14 | + None, |
| 15 | + Some(SupervisorSoft), |
| 16 | + None, |
| 17 | + Some(MachineSoft), |
| 18 | + None, |
| 19 | + Some(SupervisorTimer), |
| 20 | + None, |
| 21 | + Some(MachineTimer), |
| 22 | + None, |
| 23 | + Some(SupervisorExternal), |
| 24 | + None, |
| 25 | + Some(MachineExternal), |
| 26 | +]; |
| 27 | + |
| 28 | +#[export_name = "_dispatch_core_interrupt"] |
| 29 | +unsafe extern "C" fn dispatch_core_interrupt(code: usize) { |
| 30 | + if code < __CORE_INTERRUPTS.len() { |
| 31 | + let h = &__CORE_INTERRUPTS[code]; |
| 32 | + if let Some(handler) = h { |
| 33 | + handler(); |
| 34 | + } else { |
| 35 | + DefaultHandler(); |
| 36 | + } |
| 37 | + } else { |
| 38 | + DefaultHandler(); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +#[cfg(all(riscv, feature = "v-trap"))] |
| 43 | +core::arch::global_asm!( |
| 44 | + r#" .section .trap, "ax" |
| 45 | + .weak _vector_table |
| 46 | + .type _vector_table, @function |
| 47 | + |
| 48 | + .option push |
| 49 | + .balign 0x4 // TODO check if this is the correct alignment |
| 50 | + .option norelax |
| 51 | + .option norvc |
| 52 | + |
| 53 | + _vector_table: |
| 54 | + j _start_trap // Interrupt 0 is used for exceptions |
| 55 | + j _start_SupervisorSoft_trap |
| 56 | + j _start_DefaultHandler_trap // Interrupt 2 is reserved |
| 57 | + j _start_MachineSoft_trap |
| 58 | + j _start_DefaultHandler_trap // Interrupt 4 is reserved |
| 59 | + j _start_SupervisorTimer_trap |
| 60 | + j _start_DefaultHandler_trap // Interrupt 6 is reserved |
| 61 | + j _start_MachineTimer_trap |
| 62 | + j _start_DefaultHandler_trap // Interrupt 8 is reserved |
| 63 | + j _start_SupervisorExternal_trap |
| 64 | + j _start_DefaultHandler_trap // Interrupt 10 is reserved |
| 65 | + j _start_MachineExternal_trap |
| 66 | + |
| 67 | + .option pop"# |
| 68 | +); |
0 commit comments