Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sfence.vma instruction #23041

Merged
merged 3 commits into from
Jun 13, 2024

Conversation

buildandcrash
Copy link
Contributor

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

Description

This pull request adds support for the sfence.vma instruction to the RISC-V plugin in Radare2 and fixes (#23021).

Changes Made:

Introduced sfence.vma instruction mnemonic, operand definition, and opcode matching in riscv.c.
Updated the opcode table (riscv_builtin_opcodes) to include sfence.vma with its corresponding opcode values and operand specifications.
Reason for Change:
The sfence.vma instruction is part of the RISC-V ISA and is used for flushing virtual memory address translations. Including support for sfence.vma enhances the completeness of the RISC-V plugin in Radare2, enabling better analysis and disassembly capabilities for binaries that utilize this instruction.

Testing:

Manually tested the functionality by disassembling binaries containing sfence.vma instructions.
Verified proper decoding and disassembly output alignment with RISC-V specifications.

Before:

rasm2 -D -a riscv -b 64 73000012
0x00000000   4                 73000012  invalid

After:

rasm2 -D -a riscv -b 64 73000012
0x00000000   4                 73000012  sfence.vma zero, zero

Additional Notes:

This change ensures compatibility with the latest RISC-V ISA extensions and improves the utility of Radare2 for analyzing modern RISC-V binaries.

@trufae
Copy link
Collaborator

trufae commented Jun 13, 2024

Sweet! thanks for your contribution! would you like to continue extending the stock disassembler to support more VMA instructions? I bet there will be other pretty common ones around the same code.

Also, how is this instruction recognized by the analizer? because it should be reported as a different family (privileged or thready maybe)

@buildandcrash
Copy link
Contributor Author

Thank you! Contributing to radare2 would be an honor. I will add support to anything missing as I go, since I am working on RISC-V projects these days.

Also, the sfence.vma instruction was a replacement for sfence.vm which is considered an "improved" privileged instruction

@trufae trufae merged commit 1d6210b into radareorg:master Jun 13, 2024
38 of 40 checks passed
@trufae
Copy link
Collaborator

trufae commented Jun 13, 2024

Awesome! glad to have some riscv improvements, i love this arch but i can't spent fulltime on it yet. Btw if you care about decompilation maybe you can also check this PR wargio/r2dec-js#291

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