Repository navigation
fix(nemu): encode trap as 0x0005006b so rs1 is a0 - #75
Merged
Merged
Conversation
The helpers and linux/hello already put the trap code in a0. NEMU always reads gpr[10] (a0), so `.word 0x0000006b` still works there because its decode mask does not require rs1=a0. NutShell and XiangShan decode this custom trap as I-type and take the argument from rs1. With rs1=x0 they see 0, so GOOD_TRAP, timer disable (0x100), and profiling notify (0x101) become an unexpected halt with code 0. Use 0x0005006b in nemu-trap, nemu-exec, and linux/hello so rs1 names a0.
poemonsense
approved these changes
Sep 20, 2026
poemonsense
left a comment
Member
There was a problem hiding this comment.
Should we fix the nemu decoder as well?
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.
The helpers and linux/hello already put the trap code in a0. NEMU always reads gpr[10] (a0), so
.word 0x0000006bstill works there because its decode mask does not require rs1=a0.NutShell and XiangShan decode this custom trap as I-type and take the argument from rs1. With rs1=x0 they see 0, so GOOD_TRAP, timer disable (0x100), and profiling notify (0x101) become an unexpected halt with code 0.
Use 0x0005006b in nemu-trap, nemu-exec, and linux/hello so rs1 names a0.