|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Baumer Electric AG |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @brief Assembler-hooks specific to Nuclei's Extended Core Interrupt Controller |
| 9 | + */ |
| 10 | + |
| 11 | +#include <zephyr/arch/cpu.h> |
| 12 | + |
| 13 | + |
| 14 | +GTEXT(__soc_handle_irq) |
| 15 | +/* |
| 16 | + * In an ECLIC, pending interrupts don't have to be cleared by hand. |
| 17 | + * In vectored mode, interrupts are cleared automatically. |
| 18 | + * In non-vectored mode, interrupts are cleared when writing the mnxti register (done in |
| 19 | + * __soc_handle_all_irqs). |
| 20 | + * Thus this function can directly return. |
| 21 | + */ |
| 22 | +SECTION_FUNC(exception.other, __soc_handle_irq) |
| 23 | + ret |
| 24 | + |
| 25 | +#if !defined(CONFIG_RISCV_VECTORED_MODE) |
| 26 | + |
| 27 | +GTEXT(__soc_handle_all_irqs) |
| 28 | + |
| 29 | +#ifdef CONFIG_TRACING |
| 30 | +/* imports */ |
| 31 | +GTEXT(sys_trace_isr_enter) |
| 32 | +GTEXT(sys_trace_isr_exit) |
| 33 | +#endif |
| 34 | + |
| 35 | +/* |
| 36 | + * This function services and clears all pending interrupts for an ECLIC in non-vectored mode. |
| 37 | + */ |
| 38 | +SECTION_FUNC(exception.other, __soc_handle_all_irqs) |
| 39 | + mv t2, ra |
| 40 | + |
| 41 | + /* Read and clear mnxti to get highest current interrupt and enable interrupts. Will return |
| 42 | + * original interrupt if no others appear. */ |
| 43 | + csrrci a0, 0x345, MSTATUS_IEN |
| 44 | + beqz a0, irq_done /* Check if original interrupt vanished. */ |
| 45 | + |
| 46 | +irq_loop: |
| 47 | + |
| 48 | +#ifdef CONFIG_TRACING_ISR |
| 49 | + call sys_trace_isr_enter |
| 50 | +#endif |
| 51 | + |
| 52 | + /* Call corresponding registered function in _sw_isr_table. a0 is offset in words, table is |
| 53 | + * 2-word wide -> shift by one */ |
| 54 | + la t0, _sw_isr_table |
| 55 | + slli a0, a0, (1) |
| 56 | + add t0, t0, a0 |
| 57 | + |
| 58 | + /* Load argument in a0 register */ |
| 59 | + lw a0, 0(t0) |
| 60 | + |
| 61 | + /* Load ISR function address in register t1 */ |
| 62 | + lw t1, RV_REGSIZE(t0) |
| 63 | + |
| 64 | + /* Call ISR function */ |
| 65 | + jalr ra, t1, 0 |
| 66 | + |
| 67 | + /* Read and clear mnxti to get highest current interrupt and enable interrupts. */ |
| 68 | + csrrci a0, 0x345, MSTATUS_IEN |
| 69 | + |
| 70 | +#ifdef CONFIG_TRACING_ISR |
| 71 | + call sys_trace_isr_exit |
| 72 | +#endif |
| 73 | + |
| 74 | + bnez a0, irq_loop |
| 75 | + |
| 76 | +irq_done: |
| 77 | + mv ra, t2 |
| 78 | + ret |
| 79 | +#endif |
0 commit comments