You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ECALL changes PC and mepc but leaves mstatus MIE/MPIE/MPP unchanged; MRET does not restore them #447
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.S sets mstatus, executes ecall, reads mstatus/mepc/mcause in the handler, executes mret, then reads mstatus again.
# 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.elf
The 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):
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 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: rtlsim DEBUG=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.