Skip to content

Fix stores, srai and jalr in the RISC-V assembler ##arch - #27133

Merged
trufae merged 1 commit into
radareorg:masterfrom
HuzaifaChaudary:riscv-asm-stores-shifts
Oct 26, 2026
Merged

trufae merged 1 commit into
radareorg:masterfrom
HuzaifaChaudary:riscv-asm-stores-shifts

Conversation

@HuzaifaChaudary

@HuzaifaChaudary HuzaifaChaudary commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
  • Mark this if you consider it ready to merge
  • I've added tests (optional)
  • I wrote some lines in the book (optional)

Description

the RISC-V assembler sent everything through the I-type encoder , so some instructions came out as something else :

input before after
sw a1, 8(sp) a3258100 = sw s0, 11(sp) 2324b100
srai a0, a0, 3 13553500 = srli a0, a0, 3 13553540
jalr ra, 8(a0) Missing argument , then e7f0ffff e7008500
  • stores use the S-type layout , and sb , sh and sd are added next to sw
  • srai has its 0x20 funct7 , slli and srli are added , the shift amount is checked to be 0..63
  • jalr and jr take rs , rd, rs , imm(rs) and rd, imm(rs)
  • the loads lb , lh , ld , lbu , lhu and lwu are added , they work like lw
  • I and S immediates outside -2048..2047 , or a missing register , are refused instead of being or'ed into other fields

found by decoding random words with llvm-mc , assembling the text with rasm2 -a riscv and decoding the result again . out of 3482 distinct instructions , 880 came back the same before and 1934 now , the wrong ones went from 315 to 5 ( c.nop with a hint immediate ) and none that were right changed . the 16 new lines in db/asm/riscv_64 check against llvm's bytes , 15 of them fail before the change . db/asm has no failures .

Copilot AI balanced review requested due to automatic review settings October 22, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@trufae
trufae merged commit 23955a2 into radareorg:master Oct 26, 2026
49 of 50 checks passed
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.

3 participants