Repository navigation
Conversation
… misa MXL at XLEN 64 The synchronous trap path (ECALL/EBREAK/MRET) redirected the PC and saved mepc/mcause but never touched mstatus, and the trap CSRs were plain XLEN latches with no legalisation: - trap entry did not do MPIE<-MIE, MIE<-0, and MRET did not restore MIE from MPIE, so the interrupt-enable stack that preemption relies on was missing (#447); - mepc kept bit 1 with C disabled (and bit 0 always), and mtvec kept any MODE value, though only direct mode exists (#448). Each warp now stores only the defined bits: mstatus MIE, MPIE and FS (FS is a plain field for now), with MPP reading 11 since M is the only mode; mtvec [XLEN-1:2], so MODE reads 0; mepc [XLEN-1:1] with C and [XLEN-1:2] without. Trap entry and MRET update the stack; hardware still wins a same-cycle software write. SimX matches bit for bit. The bit positions are shared through VX_types.toml (VX_CSR_MSTATUS_*). Beacon on the core: logic depth unchanged, 496 fewer flops (31 per warp). At XLEN 64 misa placed MXL at bits 31:30 instead of XLEN-1:XLEN-2, in the RTL, SimX and the SimX debug module; it now uses the top bits. The DTM test read only DATA0 for misa and never wrote DATA1, which hid a stale high word in its register writes; it now handles both at XLEN 64. SimX gaps that blocked the machine-mode suite are closed: misa returned 0, and mvendorid/marchid/mimpid aborted; they now match the RTL. The ISA suites gain rv32mi/rv64mi (mcsr, scall, sbreak). Tests that need fault producers, user mode, triggers, counters or PMP are listed in ISA_SKIP with the reason. Passing on SimX and rtlsim at XLEN 32 and 64, with C on and off; rv32ui/rv32uf unchanged. Fixes #447, fixes #448. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cking The trap path handled only ECALL/EBREAK. A taken jump or branch to a target with bit 1 set (C off) did not trap: DEBUG builds fetched the misaligned PC and release builds silently dropped the low bits (#445). mstatus.FS was not tracked, so FP instructions ran with FS=Off and FS never became Dirty (#446). Illegal encodings had no defined behaviour: undefined decode fields in the RTL, an abort in SimX. Misaligned fetch (cause 0): the branch unit takes target bit 1 from the adder before PC truncation, so DEBUG and release behave the same; the decision uses the last active lane, the lane the warp follows, and a trapping jump writes no link register. mepc is the jump's PC (carried in dest, as for ECALL); mtval is 0 for every cause, which the spec allows and which avoids ~330 LUT of per-warp target muxes. Illegal instruction (cause 2), a new INST_BR_ILLEGAL uop that stalls the warp like ECALL: unknown major opcodes (including built-out extensions), reserved F/D encodings, shamt[5] on RV32 and RV64 word shifts, writes to read-only CSRs, reserved compressed encodings (the RTL decompressor now expands them to the all-zero word; SimX marks the same set, and the rd=x0 HINT forms execute as no-ops on both), and FP instructions or FP-CSR accesses under FS=Off, including the Vortex extensions that use FP registers (packed/wide/matrix FP ld/st, TCU MMA, TFU, RTU GETWF/CB_RET), conditional branches with the reserved funct3 2 or 3, and SYSTEM encodings other than the CSR accesses, ECALL, EBREAK, URET, SRET, MRET and WFI. WFI runs as a no-op (there is no interrupt to wait for: the RTL decodes it as a jump to the next instruction), and no SYSTEM instruction outside the CSR accesses writes rd. FS: resets to Initial so kernels that never touch mstatus keep running, and is read-only zero without F; SD reads FS==Dirty; FP-state writers set Dirty at decode unless they trap. An mstatus CSR access stalls its warp at decode until the CSR unit takes it (csr_unlock on sched_csr_if), keeping the FS check and the Dirty update in program order; SimX releases at the same point. misa writes are ignored (WARL). SimX applies trap, mret and PC-redirect effects only on an instruction's last lane packet, as the RTL does; before, a split instruction raised a trap once per packet and clobbered MPIE (also for ECALL/EBREAK/MRET). SimX aborts with the cause, PC and instruction when an illegal or misaligned fault is taken with mtvec=0 (a plain kernel has no handler); the RTL jumps to mtvec as architected. The trap CSRs are device state on both sides: a device reset clears them and a kernel launch keeps them (SimX used to clear them at every launch, the RTL never did). rv32mi/rv64mi now also run illegal, shamt and ma_fetch; csr stays skipped (tests 14-15 need misa.U cleared or an unimplemented-CSR trap). CI runs them on the default build with C off (isa-mi), the only build where ma_fetch reaches the misaligned-fetch trap. A new regression, trap_illegal, covers what no riscv-test that runs reaches: FP instructions, loads, CSR accesses and moves under FS=Off, the reserved branch and SYSTEM encodings and WFI (cause and mepc each), and FS going from Initial to Dirty with SD; on the old code it fails every probe. The RVC unit test now expects the rd=x0 HINTs to expand and checks the reserved points. Passing on SimX and rtlsim at XLEN 32 and 64, default and A+C, rv32ui/uc with C on, NUM_ALU_LANES=2 (rv32mi, sgemm, diverge), sgemm_tcu; sgemm instruction and cycle counts unchanged. Beacon (core, A+C): depth unchanged (15, mean-50 11.6, 278 registers at 8+ levels), +68 LUT, +5 FF. Fixes #445, fixes #446. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 19, 2026
ECALL changes PC and mepc but leaves mstatus MIE/MPIE/MPP unchanged; MRET does not restore them
#447
Closed
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two commits complete the M-mode trap path. The design doc is updated (
docs/designs/trap_and_exception_foundation.md).1. mstatus stack, WARL CSRs and misa (fixes #447 and #448)
mretrestores MIE←MPIE and sets MPIE←1.mtvecandmepcare WARL.misaputs MXL in the top bits at XLEN 64.dtm_test.pymatch.2. Fault producers and mstatus.FS (fixes #445 and #446)
Misaligned fetch (cause 0): a taken jump or branch to a target with bit 1 set, when C is off. Before, it fetched the misaligned PC in debug builds and silently dropped bits in release builds.
Illegal instruction (cause 2), through a new
INST_BR_ILLEGALuop:shamt[5]on RV32;funct3and unknown SYSTEM encodings;WFIruns as a no-op.FS: resets to Initial. FP writes set Dirty at decode, and SD follows. FS is read-only zero without F.
A CSR access to
mstatusholds its warp until the CSR unit takes it, so the FS check and the Dirty update stay in program order.Trap CSRs are device state: a launch keeps them on both sides. SimX used to clear them at every launch.
mtvalis 0 for every cause, which the spec allows. Writing the target there would cost about 330 LUT of per-warp muxes.Impact and evidence
Impact class: R3 (
ci/change_impact.py classify). Maintainer approval needed.Contracts touched:
VX_decode_sched_if: addsfs_offandfs_dirty.VX_sched_csr_if: addscsr_unlock.sched_csr_wr_tINST_BR_ILLEGALreplacesINST_BR_OTHER.VX_types.toml:VX_CSR_MSTATUS_*bit positions.mcsr,scall,sbreak,illegal,shamt,ma_fetch) on SimX and rtlsim at XLEN 32 and 64, with C off and with A+C. Newtrap_illegalpasses on SimX and rtlsim at XLEN 32 and 64; on master it fails every probe. RVC unit test passes at XLEN 32 and 64. multikernel, reopen and module_reload pass on SimX. sgemm, diverge and sgemm_tcu pass.model_parityperf_gatelogic_gate-Walllint at XLEN 32 and 64 (standard matrix, C+A, 2 ALU lanes) and at XLEN 32 with F off; SimX with-DSIMX_FUNCTIONALNew CI cases:
isa-mi: machine-mode suites with C off, the only build wherema_fetchreaches the trap.trap-illegalNo test silenced. The
csrriscv-test stays skipped for the documented reason: tests 14-15 needmisa.Ucleared.No golden data changed.
RTL and SimX move together.
No toolchain pin change.
🤖 Generated with Claude Code