Replies: 3 comments 3 replies
-
Looking at old riscv-opc.h in binutols, this logic has been removed. I most certainly scripted parsing these back when this was originally developed (~2019-2020). |
Beta Was this translation helpful? Give feedback.
-
Binutils currently supports xthead, core-v, sifive, and ventana custom RISCV instructions along with a few dozen standard extensions.
|
Beta Was this translation helpful? Give feedback.
-
It looks like the support for those instructions come from the Rocket Chip project (one of the open source implementations) that at one point had an Xcustom extension (see bminor/binutils-gdb@cb4ff67) |
Beta Was this translation helpful? Give feedback.
-
Hi all - got a real stumper here. Devs will love this - Ghidra is getting something right I'd just like to know why it's getting it right. :-D
RISC-V custom instructions are the wild west and I've seen discussions elsewhere about adding support for specific processors that have documented extensions. But this is about how Ghidra handles the general case of instructions in the custom opcode space.
Ghidra/Processors/RISCV/data/languages/riscv.custom.sinc
Is where RISC-V custom instructions are handled. Ghidra is following a convention to determine whether those instructions have 0,1, or 2 source operands, e.g.:
(op1214 corresponds to the field commonly called "funct3" or "cf_id1" in the RISC-V documentation. So if the function field is 2 we're going to say it's a single operand, if the function field is 3 we're going to say it has two operands, etc.)
The question is: where did this convention come from? I can't find any guidance in RISC-V documentation (historical or current) that defines it this way. There is currently a "Custom Composable Extensions" draft specification but it suggests the custom-0 space be used for 2-register r-type instructions and the custom-1 space be used for 1-register I-type instructions. My guess is that maybe some of the proposed extensions were following this convention at some point? (but I couldn't find evidence of that either).
The reason I ask is that I have a sans-hardware firmware image I'm working with (so I know it's RISC-V, I know it's using custom extensions, but I have no clue what the actual target processor is) ...and Ghidra seems to be getting the operand parsing right for the custom-0 space. So in trying to determine what kind of custom extensions my target processor might be using I'd love to know where Ghidra got this convention from.
@GhidorahRex looks like he has something he's working from in this commit so maybe he can shed some light on the situation? The commit history on the file doesn't have any clues. I saw this was added due to this discussion also that @mumbel was involved in.
Thanks all - really appreciate all of the work that goes into this awesome tool.
Beta Was this translation helpful? Give feedback.
All reactions