Skip to content

Commit 90537fa

Browse files
authored
[rte] cleanups and optimizations (#1299)
2 parents 2eae568 + dc1b669 commit 90537fa

File tree

23 files changed

+195
-179
lines changed

23 files changed

+195
-179
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mimpid = 0x01040312 -> Version 01.04.03.12 -> v1.4.3.12
2929

3030
| Date | Version | Comment | Ticket |
3131
|:----:|:-------:|:--------|:------:|
32+
| 27.06.2025 | 1.11.7.3 | RTE cleanups; double-trap exception now has highest priority | [#1299](https://github.com/stnolting/neorv32/pull/1299) |
3233
| 21.06.2025 | 1.11.7.2 | :test_tube: add double-trap exception (loosely based on the RISC-V `Smdbltrp` ISA extension) | [#1294](https://github.com/stnolting/neorv32/pull/1294) |
3334
| 20.06.2025 | 1.11.7.1 | remove WDT's "strict" configuration bit; minor rtl cleanups | [#1293](https://github.com/stnolting/neorv32/pull/1293) |
3435
| 20.06.2025 | [**:rocket:1.11.7**](https://github.com/stnolting/neorv32/releases/tag/v1.11.7) | **New release** | |

docs/datasheet/cpu.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,17 +1298,17 @@ Whenever any trap (synchronous or asynchronous) is taken into M-mode an internal
12981298
only if the triggering trap does not cause a debug-mode entry. It is cleared again when executing an `mret` instruction.
12991299
Hence, this flag indicates "_inside trap_" status when set. If a second _synchronous_ trap occurs while this flag is set,
13001300
a double-trap exception is raised. The RISC-V-compliant "double-trap" exception code 16 (see <<_neorv32_trap_listing>>)
1301-
is used to identify this event. In summary, an trap that is followed by a synchronous trap (without an `mret` in between)
1301+
is used to identify this event. In summary, a trap that is followed by a synchronous trap (without an `mret` in between)
13021302
causes a double-trap exception:
13031303

13041304
.Double-Trap Scenarios
13051305
[cols="<3,<3,<4"]
13061306
[options="header", grid="rows"]
13071307
|=======================
13081308
| First Trap | Second Trap | Resulting State
1309-
| Synchronous (e.g. `ecall`) | Synchronous (e.g. `ecall`) | **Double-trap**
1309+
| Synchronous (e.g. `ecall`) | Synchronous (e.g. `ecall`) | **Double-trap exception**
13101310
| Synchronous (e.g. `ecall`) | Asynchronous (interrupt) | Second trap is not triggered; IRQs are automatically disabled upon trap entry (<<_mstatus>>.`MIE` automatically clears)
1311-
| Asynchronous (interrupt) | Synchronous (e.g. `ecall`) | **Double-trap**
1311+
| Asynchronous (interrupt) | Synchronous (e.g. `ecall`) | **Double-trap exception**
13121312
| Asynchronous (interrupt) | Asynchronous (interrupt) | Second trap is not triggered; IRQs are automatically disabled upon trap entry (<<_mstatus>>.`MIE` automatically clears); see <<_nested_interrupts>>
13131313
|=======================
13141314

@@ -1363,8 +1363,8 @@ can be used to output debug information, to bring the system into a safe state o
13631363
|=======================
13641364
| Prio. | `mcause` | RTE Trap ID | Cause | `mepc` | `mtval` | `mtinst` | Note
13651365
8+^| **Exceptions** (_synchronous_ to instruction execution)
1366-
| 1 | `0x00000001` | `TRAP_CODE_I_ACCESS` | instruction access fault | I-PC | 0 | INS | **fatal**
1367-
| 2 | `0x00000010` | `TRAP_CODE_DOUBLE_TRAP` | <<_double_trap_exception>> | I-PC | 0 | INS | **fatal**
1366+
| 1 | `0x00000010` | `TRAP_CODE_DOUBLE_TRAP` | <<_double_trap_exception>> | I-PC | 0 | INS | **fatal**
1367+
| 2 | `0x00000001` | `TRAP_CODE_I_ACCESS` | instruction access fault | I-PC | 0 | INS | **fatal**
13681368
| 3 | `0x00000002` | `TRAP_CODE_I_ILLEGAL` | illegal instruction | PC | 0 | INS |
13691369
| 4 | `0x00000000` | `TRAP_CODE_I_MISALIGNED` | instruction address misaligned | PC | 0 | INS | **fatal**
13701370
| 5 | `0x0000000b` | `TRAP_CODE_MENV_CALL` | environment call from M-mode | PC | 0 | INS |

docs/datasheet/software.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ The NEORV32 HAL consists of the following files.
7474
| `neorv32_gpio.c` | `neorv32_gpio.h` | <<_general_purpose_input_and_output_port_gpio>> HAL
7575
| `neorv32_gptmr.c` | `neorv32_gptmr.h` | <<_general_purpose_timer_gptmr>> HAL
7676
| - | `neorv32_intrinsics.h` | Macros for intrinsics and custom instructions
77+
| - | `neorv32_legacy.h` | Legacy / backwards-compatibility wrappers (**do not use for new designs**)
7778
| `neorv32_neoled.c` | `neorv32_neoled.h` | <<_smart_led_interface_neoled>> HAL
7879
| `neorv32_onewire.c` | `neorv32_onewire.h` | <<_one_wire_serial_interface_controller_onewire>> HAL
7980
| `neorv32_pwm.c` | `neorv32_pwm.h` | <<_pulse_width_modulation_controller_pwm>> HAL

rtl/core/neorv32_cpu_control.vhd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ begin
907907
elsif rising_edge(clk_i) then
908908
trap_ctrl.cause <= (others => '0'); -- default
909909
-- standard RISC-V exceptions --
910-
if (trap_ctrl.exc_buf(exc_iaccess_c) = '1') then trap_ctrl.cause <= trap_iaf_c; -- instruction access fault
911-
elsif (trap_ctrl.exc_buf(exc_doublet_c) = '1') then trap_ctrl.cause <= trap_dbt_c; -- double-trap
910+
if (trap_ctrl.exc_buf(exc_doublet_c) = '1') then trap_ctrl.cause <= trap_dbt_c; -- double-trap
911+
elsif (trap_ctrl.exc_buf(exc_iaccess_c) = '1') then trap_ctrl.cause <= trap_iaf_c; -- instruction access fault
912912
elsif (trap_ctrl.exc_buf(exc_illegal_c) = '1') then trap_ctrl.cause <= trap_iil_c; -- illegal instruction
913913
elsif (trap_ctrl.exc_buf(exc_ialign_c) = '1') then trap_ctrl.cause <= trap_ima_c; -- instruction address misaligned
914914
elsif (trap_ctrl.exc_buf(exc_ecall_c) = '1') then trap_ctrl.cause <= trap_env_c(6 downto 2) & replicate_f(csr.prv_level, 2); -- environment call (U/M)

rtl/core/neorv32_package.vhd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package neorv32_package is
2929

3030
-- Architecture Constants -----------------------------------------------------------------
3131
-- -------------------------------------------------------------------------------------------
32-
constant hw_version_c : std_ulogic_vector(31 downto 0) := x"01110702"; -- hardware version
32+
constant hw_version_c : std_ulogic_vector(31 downto 0) := x"01110703"; -- hardware version
3333
constant archid_c : natural := 19; -- official RISC-V architecture ID
3434
constant XLEN : natural := 32; -- native data path width
3535

sim/neorv32_tb.vhd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ begin
346346
FIFO_WIDTH => 32+4+1,
347347
FIFO_RSYNC => false,
348348
FIFO_SAFE => true,
349-
FULL_RESET => true
349+
FULL_RESET => true,
350+
OUT_GATE => false
350351
)
351352
port map (
352353
-- control --

sw/example/bus_explorer/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ int main() {
6262

6363
// capture all exceptions and give debug info via UART
6464
neorv32_rte_setup();
65-
neorv32_rte_handler_install(RTE_TRAP_L_MISALIGNED, memory_trap_handler);
66-
neorv32_rte_handler_install(RTE_TRAP_L_ACCESS, memory_trap_handler);
67-
neorv32_rte_handler_install(RTE_TRAP_S_MISALIGNED, memory_trap_handler);
68-
neorv32_rte_handler_install(RTE_TRAP_S_ACCESS, memory_trap_handler);
65+
neorv32_rte_handler_install(TRAP_CODE_L_MISALIGNED, memory_trap_handler);
66+
neorv32_rte_handler_install(TRAP_CODE_L_ACCESS, memory_trap_handler);
67+
neorv32_rte_handler_install(TRAP_CODE_S_MISALIGNED, memory_trap_handler);
68+
neorv32_rte_handler_install(TRAP_CODE_S_ACCESS, memory_trap_handler);
6969

7070
// disable all interrupt sources
7171
neorv32_cpu_csr_write(CSR_MIE, 0);

sw/example/demo_clint/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ int main() {
7777
neorv32_clint_mtimecmp_set(-1);
7878

7979
// install CLINT handlers to RTE
80-
neorv32_rte_handler_install(RTE_TRAP_MTI, mti_irq_handler);
81-
neorv32_rte_handler_install(RTE_TRAP_MSI, msi_irq_handler);
80+
neorv32_rte_handler_install(TRAP_CODE_MTI, mti_irq_handler);
81+
neorv32_rte_handler_install(TRAP_CODE_MSI, msi_irq_handler);
8282

8383
// start real time clock
8484
neorv32_uart0_printf("\nStarting real-time clock demo...\n");

sw/example/demo_dma/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int main() {
6363
neorv32_uart0_printf("Descriptor FIFO depth: %u\n", neorv32_dma_get_descriptor_fifo_depth());
6464

6565
// install DMA interrupt handler
66-
neorv32_rte_handler_install(DMA_RTE_ID, dma_firq_handler);
66+
neorv32_rte_handler_install(DMA_TRAP_CODE, dma_firq_handler);
6767

6868
// enable DMA
6969
neorv32_dma_enable();

sw/example/demo_dual_core_rte/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ int app_main(void) {
115115

116116
// setup machine timer interrupt for ALL cores
117117
neorv32_clint_mtimecmp_set(0); // initialize core-specific MTIMECMP
118-
neorv32_rte_handler_install(RTE_TRAP_MTI, trap_handler_mtmi); // install trap handler
118+
neorv32_rte_handler_install(TRAP_CODE_MTI, trap_handler_mtmi); // install trap handler
119119
neorv32_cpu_csr_set(CSR_MIE, 1 << CSR_MIE_MTIE); // enable interrupt source
120120

121121
// setup machine software interrupt for ALL cores
122-
neorv32_rte_handler_install(RTE_TRAP_MSI, trap_handler_mswi); // install trap handler
122+
neorv32_rte_handler_install(TRAP_CODE_MSI, trap_handler_mswi); // install trap handler
123123
neorv32_cpu_csr_set(CSR_MIE, 1 << CSR_MIE_MSIE); // enable interrupt source
124124

125125
// setup machine environment call trap for ALL cores
126-
neorv32_rte_handler_install(RTE_TRAP_MENV_CALL, trap_handler_ecall); // install trap handler
126+
neorv32_rte_handler_install(TRAP_CODE_MENV_CALL, trap_handler_ecall); // install trap handler
127127

128128

129129
// trigger environment call exception (just to test the according handler)

0 commit comments

Comments
 (0)