Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
(forgive the basic question I'm fairly new to Ghidra and 8051)
I'm in the midst of decompiling an 8051-compatible binary, and there's apparently two different ways to access the generic registers (R0-R7). They can be accessed directly, e.g.:
MOV R7, #0x8
or they can be accessed through the register bank. Assuming
PSW[3:4] == 0
(Bank 0 selected), they can also be read with:MOV R1, BANK0_R7
Apparently moving directly from one register to another (
MOV R1, R7
) isn't a valid op on the 8051, so the compiler uses the memory bank reference instead.The problem is that Ghidra seems to have no idea that these are the same thing, and the program uses these registers to pass function parameters. E.g., the caller uses:
MOV R7, #0x8
LCALL MyFunction
and
MyFunction()
will haveMOV R1, BANK0_R7
as the first instruction. I can add the parameter to the function signature and set it's storage to R7, which turns the call site into:MyFunction(8)
Great! But inside
MyFunction(char p1)
's decompile I get e.g.switch(BANK0_R7):
instead of
switch(p1)
The same problem happens on return values. Is there a way to help Ghidra understand that R7 and BANK0_R7 are the same thing (when PSW[3:4] == 0)?
Actually I'd be fine with ignoring PSW and just somehow hard coding the fact that BANK0_R7 and R7 are the same thing, since the program I'm decompiling never changes it.
I tried adding an overlay, but it doesn't let me create a memory region that overlays registers.
Beta Was this translation helpful? Give feedback.
All reactions