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

RISC-V: CSR instruction disassembly: Decode CSR register number into a string when a standardized register is used #6376

Open
pdietl opened this issue Jan 30, 2025 · 2 comments
Labels
Arch: RISC-V Issues with the RISC-V architecture plugin Component: Architecture Issue needs changes to an architecture plugin Effort: Trivial Issue should take < 1 day Impact: Low Issue is a papercut or has a good, supported workaround

Comments

@pdietl
Copy link
Contributor

pdietl commented Jan 30, 2025

Currently, CSR instructions are decoded like so:

Image

But there are many CSR register numbers with a defined definition in the RISC-V ISA Manual Volume II: Privileged Architecture. Examples:

Image

I propose instead of the disassembly showing csrrs zero, 0x300, t0, it instead show csrrs zero, mstatus, t0. Likewise in the higher-level ILs.

I can make these changes, but I'm not great at Rust and I need some pointers on how to do it. Providing an example of the aforementioned instruction would suffice and I could then fill in the rest.

Based on recent contributors, I will humbly ask @emesare, @ehntoo for assistance.

@emesare emesare added Component: Architecture Issue needs changes to an architecture plugin Impact: Low Issue is a papercut or has a good, supported workaround Effort: Trivial Issue should take < 1 day Arch: RISC-V Issues with the RISC-V architecture plugin labels Jan 30, 2025
@emesare
Copy link
Member

emesare commented Jan 30, 2025

Firstly you want to update the intrinsic param type for csr to an enumeration with the csr register names and their number.

NameAndType::new("csr", Conf::new(Type::int(4, false), MAX_CONFIDENCE)),

You can create an enumeration using EnumerationBuilder:

https://dev-rust.binary.ninja/binaryninja/types/struct.Enumeration.html#method.builder

Then finalizing the enumeration builder and passing it to Type::enumeration:

https://dev-rust.binary.ninja/binaryninja/types/struct.Type.html#method.enumeration

Then you want to update the instruction_text function to special case for those instructions with a csr register numeric.

for (i, oper) in operands.iter().enumerate() {

@pdietl
Copy link
Contributor Author

pdietl commented Jan 30, 2025

@emesare Thanks so much! I'll get on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: RISC-V Issues with the RISC-V architecture plugin Component: Architecture Issue needs changes to an architecture plugin Effort: Trivial Issue should take < 1 day Impact: Low Issue is a papercut or has a good, supported workaround
Projects
None yet
Development

No branches or pull requests

2 participants