Repository navigation
Description
Environment Setup
Stock XLEN=32 configuration, F enabled, C disabled, IALIGN=32. Tested at commit b447578d9f3bb116d658c614cf3407153f0536da. Driver: rtlsim built DEBUG=1; the test is a bare-metal ELF.
f2_trap_mstatus/23_trap_mstatus/23_trap_mstatus.Ssetsmstatus, executesecall, readsmstatus/mepc/mcausein the handler, executesmret, then readsmstatusagain.
# rtlsim built DEBUG=1 from the commit above (XLEN=32, F on, C off).
spike -l --log-commits --isa=rv32imaf -m128 f2_trap_mstatus/23_trap_mstatus/ref.elf
./rtlsim f2_trap_mstatus/23_trap_mstatus/dut.elfThe test ran to completion (spike_rc=0, dut_rc=0).
Expected behavior
Per the RISC-V Privileged Specification, machine.adoc (mstatus register, trap-entry / MRET behaviour): on a trap into M-mode, MPIE is loaded from MIE, MIE is cleared, and MPP is set to the current privilege; MRET restores MIE from MPIE and sets MPIE.
Observed results
DUT (logs/23_trap_mstatus_dut.dbg.log, commit of csrr s0,mstatus at PC 0x8000001c in the handler, and at PC 0x80000034 after MRET):
359: ...-commit commit: ... PC=0x8000001c, ex=SFU, rd=8, ... data={0x8, 0x8, 0x8, 0x8} <--
517: ...-commit commit: ... PC=0x80000034, ex=SFU, rd=19, ... data={0x8, 0x8, 0x8, 0x8} <--
mstatus stays 0x8 (only MIE set) both in the handler and after MRET; no MPIE/MPP transition is observable. The trap itself does happen — the ECALL at 0x80000014 is decoded (op=ECALL) and the handler runs.
Spike (logs/23_trap_mstatus_ref.commits):
core 0: 3 0x80000010 (0x30029373) x6 0x00000000 c768_mstatus 0x00000008
core 0: 0x80000014 (0x00000073) ecall
core 0: exception trap_machine_ecall, epc 0x80000014
core 0: 0x8000001c (0x30002473) csrr s0, mstatus
core 0: 3 0x8000001c (0x30002473) x8 0x00001880 <--
core 0: 0x80000030 (0x30200073) mret
core 0: 3 0x80000030 (0x30200073) c768_mstatus 0x00000088 <--
core 0: 0x80000034 (0x300029f3) csrr s3, mstatus
core 0: 3 0x80000034 (0x300029f3) x19 0x00000088
Spike reads 0x1880 in the handler (MPIE set, MPP=3, MIE cleared) and leaves 0x88 after MRET. The interrupt source is not wired up on this DUT, but ECALL does enter the handler, so the mstatus protocol is still expected to apply.
The trap-entry and MRET path in VX_csr_data.sv writes mepc/mcause but appears not to update the mstatus MIE/MPIE/MPP fields. This may be a deliberate simplification of the trap path.
Affected revision and environment
- Tested at commit
b447578d9f3bb116d658c614cf3407153f0536da VERSION:VORTEX_VERSION=3.0,TOOLCHAIN_REV=v3.0.1- DUT simulator:
rtlsimDEBUG=1 - Reference: Spike
--isa=rv32imaf -m128 - OS: Linux 6.8.0-90-generic x86_64.
Minimal RTL reproducer
The log excerpts are from logs/23_trap_mstatus_dut.dbg.log in the attachment.
Attachment: testcase.zip contains 23_trap_mstatus.S, its prelinked dut.elf / ref.elf, link.ld, probe_macros.h, and the full DUT (logs/23_trap_mstatus_dut.dbg.log) and Spike (logs/23_trap_mstatus_ref.commits) logs.
Activity
tinebp commentedon Nov 19, 2026
Fixed by #487.
trap: mstatus stack, WARL CSRs, misaligned-fetch and illegal-instruct…