RISC-V: add reg_access and test its usages in C and Python#2895
Open
moste00 wants to merge 1 commit intocapstone-engine:nextfrom
Open
RISC-V: add reg_access and test its usages in C and Python#2895moste00 wants to merge 1 commit intocapstone-engine:nextfrom
moste00 wants to merge 1 commit intocapstone-engine:nextfrom
Conversation
reg_access is a convenience wrapper over the `operands` array that filters the register operands (including those used as memory base address) and returns them sorted into read and written registers. It wasn't implemented for RISC-V, this PR implements it. The following decisions were made for RISC-V: 1- System registers (CSRs) are not registers This follows existing Capstone convention, where almost every archiceture that have system registers except x86 treats them as a seperate address space. From a purely practical POV, the reg_access function API returns registers as an array of integers, and the address space of normal registers intersects with that of system registers so there is nothing in the return value to distinguish them. 2- PC is not an implicit register Whenever an instruction reads PC (e.g. all call-ish instructions JAL[R]?) this is NOT counted as an implicit read of the PC. The reason is that the PC is somewhat "second class" in RISC-V, it's an archiectural register but has no actual index and can never be directly written to by any instruction in any standard extension no matter the privliege. Meanwhile, all instruction that read the PC have names that make it obvious they read the PC so adding that information to the implicit reads array would be redundant.
Contributor
Author
|
@Rot127 please review. |
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.
Your checklist for this pull request
Detailed description
Capstone module callback
reg_accessis a convenience wrapper over theoperandsarray that filters out the register operands (including those used as memory base address) from the rest of the operands and returns them sorted into read and written registers. It wasn't implemented for RISC-V, this PR implements it.The following decisions were made for RISC-V's
reg_access:1- System registers (CSRs) are not registers
This follows existing Capstone convention, where almost every architecture that have system registers except x86 treats them as a seperate address space.
From a purely practical POV, the
reg_accessAPI returns registers as an array of integers, and the address space of normal registers intersects with that of system registers so there is nothing in the return value to distinguish them.2- The PC is not an implicit register
Whenever an instruction reads PC (e.g. all call-ish instructions JAL[R]?) this is NOT counted as an implicit read of the PC.
The reason is that the PC is somewhat "second class" in RISC-V, it's an archiectural register but has no actual index and can never be directly written to by any instruction in any standard extension no matter the privliege.
Meanwhile, all instruction that read the PC have names that make it obvious they read the PC so adding that information to the implicit reads array would be redundant.
Again from a purely practical POV, the PC has no index defined by
riscv.h, which makes sense as it's never referenced by any instruction.Test plan
Added two unit tests to prove the callback can be run from the consumer side of the C and Python API of Capstone.
Closing issues
closes #2406 .