Proper handling of RISC-V memory accesses via offsets from global pointer #6849
Replies: 3 comments 3 replies
-
Similar experience, Ghidra does not pick up on the first lot of instructions in BootROM including where |
Beta Was this translation helpful? Give feedback.
-
Workaround: Go to the address of the instruction just after This also demands that you figure out the value. Is there not any better way in Ghidra to do this? |
Beta Was this translation helpful? Give feedback.
-
Manually setting the register value of @eshattow It should be noted that your suggested procedure isn't quite suitable when dealing with embedded microcontroller code. There, you typically have an IRQ vector table at the beginning of the .text (i.e. flash memory) section, which jumps to a reset handler, within which Figuring out the
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am attempting to reverse engineer some RISC-V microcontroller code, but there is one particular aspect related to its handling of code using the global pointer (
gp
) register that is making understanding the code more difficult and tedious than it probably should be. I am wondering if there is a way to make Ghidra decompile the code into something more understandable.In this particular code, the
gp
register is initialised early on (in reset vector handler) with a value equal to the end of RAM, 0x20000800. Thereafter, most accesses to static/global variables in the code are made via offset fromgp
. (I believe this is probably because the code was compiled using GCC with the--relax
option.)For example:
Ghidra is only able to decompile this as:
Another example:
This is not particularly helpful, as I'm having to manually translate these into the actual memory addresses that are being accessed, and keep track of everything separately. It also doesn't help assigning a label and data type to these memory locations, as accesses this way won't use those attributes.
Ghidra obviously knows how to translate RAM accesses that are relative to an address in another register, because it does this successfully for other code not involving
gp
:Is the problem because Ghidra doesn't know what the value of
gp
is at any given point?Is there any way to turn the
gp
-using code into something more sensible?Beta Was this translation helpful? Give feedback.
All reactions