Reject invalid JALR and SYSTEM encodings - #12
Merged
Conversation
jserv
reviewed
Aug 3, 2026
| reserved-ret-funct3-1:00c000ef,05d00893,00000073,00009067 \ | ||
| CSR-funct3-1:05d00893,00001073 \ | ||
| CSR-funct3-5:05d00893,00005073 \ | ||
| ebreak:05d00893,00100073 \ |
Collaborator
There was a problem hiding this comment.
ebreak is grouped with the decode-gate rejections, but unlike the other RVOPT_BAD_ENC cases it decodes successfully as K_SYSTEM and is rejected later as SYS_BAD in analyze_syscalls() — not by the JALR/SYSTEM decode gate. The test still passes (rc=1 + "unsupported op"), so this is only a grouping nuance: it exercises the SYS_BAD emission path rather than the decode gate the neighboring cases test. Might be worth a one-line comment saying so.
Contributor
Author
There was a problem hiding this comment.
Thx prof's advice. ebreak pass decode as K_SYSTEM and is reject later as SYS_BAD. Add a comment to distinguish it from the decode-gate rejection cases.
thc1006
force-pushed
the
rvopt-reject-invalid-encodings
branch
from
August 3, 2026 04:19
c53a379 to
5d7b85f
Compare
decode_word() accepts every opcode 0x67 word as JALR and every opcode 0x73 word as SYSTEM. This allows 0x00009067, whose JALR funct3 is reserved, to be lowered as a direct jump. It also allows 0x00001073, a CSR instruction, to become SYS_EXIT when a7 is 93. JALR requires funct3 == 0, while ECALL and EBREAK use exact instruction words. Reject the other encodings, check the exact ECALL word in analyze_syscalls(), and add hand-encoded regression cases. make check-all passes. Signed-off-by: thc1006 <hctsai1006@cs.nctu.edu.tw>
thc1006
force-pushed
the
rvopt-reject-invalid-encodings
branch
from
August 3, 2026 04:25
5d7b85f to
4c45bf0
Compare
Collaborator
|
Thank @thc1006 for contributing! |
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.
decode_word()accept every opcode0x67word as JALR and every opcode0x73word asSYSTEM. This allows0x00009067, whose JALRfunct3is reserved and to be lowered as a direct jump. It also allow0x00001073, a CSR instruction, to becomeSYS_EXITwhena7is93.JALR requires
funct3 == 0, whileECALLandEBREAKuse exact instruction words. Reject the other encodings, check the exactECALLword inanalyze_syscalls(), and add hand-encoded regression cases.make check-allpasses.Summary by cubic
Reject invalid JALR and SYSTEM encodings to stop reserved forms from being lowered as jumps or syscalls. JALR now requires funct3==000, and SYSTEM matches only exact ECALL/EBREAK words.
python3to pack words.Written for commit 4c45bf0. Summary will update on new commits.