fix(csr): mask xepc[1:0] on sepc and vsepc write (IALIGN=32) - #7
Open
ojasshelke46 wants to merge 1 commit into
Open
fix(csr): mask xepc[1:0] on sepc and vsepc write (IALIGN=32)#7ojasshelke46 wants to merge 1 commit into
ojasshelke46 wants to merge 1 commit into
Conversation
On a CSR write, sepc and vsepc masked only bit[0] to zero
({csr_wdata[63:1], 1'b0}), allowing a 2-byte-misaligned value to be
stored in these exception-PC registers.
This core does not implement the C extension: def_pkg ISA_CODE hardwires
the C bit to 0, so IALIGN=32. The RISC-V privileged spec requires every
exception-PC CSR (mepc/sepc/vsepc) to hold a value aligned to IALIGN,
i.e. bits [1:0] read as zero when IALIGN=32. A misaligned sepc/vsepc is
used as the jump target on SRET and would raise a spurious
instruction-address-misaligned trap that should not be reachable. mepc
already masks bits [1:0] correctly a few lines away in the same block.
Mask bits [1:0] on both writes to match mepc:
sepc_int = {csr_wdata[63:2], 2'b0};
vsepc_d = {csr_wdata[63:2], 2'b0}; // inside the RVH guard
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
On a CSR write,
sepcandvsepcmask only bit[0] to zero(
{csr_wdata[63:1], 1'b0}), allowing a 2-byte-misaligned value to bestored in these exception-PC registers.
This core does not implement the C extension —
def_pkgISA_CODEhardwires the C bit to 0, so IALIGN=32. Per the RISC-V privileged spec
every exception-PC CSR (
mepc/sepc/vsepc) must hold a value alignedto IALIGN, i.e. bits[1:0] read as zero. A misaligned
sepc/vsepcisused as the jump target on
SRETand would raise a spuriousinstruction-address-misaligned trap that should not be reachable.
mepcalready masks bits[1:0] correctly a few lines away in the same block.Change
Mask bits[1:0] on both writes to match
mepc:sepc:sepc_int = {csr_wdata[63:2], 2'b0};vsepc:vsepc_d = {csr_wdata[63:2], 2'b0};(inside theRVHguard)Related
#6 applies the same
sepcfix (plus anstvecchange). This PRadditionally covers
vsepc, the RVH virtual-supervisor exception-PC,which #6 leaves masking only bit[0].
Testing
verilator --lint-only -Walloncsr_bsc.sv: warning set is identicalbefore and after the change (0 errors, no new warnings, none on the
changed lines). There is no CSR/SRET testbench in-tree to exercise the
path at runtime.