Skip to content

Commit 0bd10fc

Browse files
committed
[cpu]double-trap exception has highest priority
1 parent 004938d commit 0bd10fc

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

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 |

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

0 commit comments

Comments
 (0)