Skip to content

fix(nemu): encode trap as 0x0005006b so rs1 is a0 - #75

Merged
poemonsense merged 1 commit into
mainfrom
circle-patch1
Sep 20, 2026
Merged

poemonsense merged 1 commit into
mainfrom
circle-patch1

Conversation

@good-circle

Copy link
Copy Markdown
Contributor

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.

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 poemonsense left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fix the nemu decoder as well?

@poemonsense
poemonsense merged commit 641e288 into main Sep 20, 2026
2 checks passed
@poemonsense
poemonsense deleted the circle-patch1 branch September 20, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants