ghidra icon indicating copy to clipboard operation
ghidra copied to clipboard

i8085 OUT instruction discarded by decompiler

Open hjanetzek opened this issue 2 years ago • 14 comments

Describe the bug The decompiler results are almost complete except for missing the OUT instruction.

shot-2022-08-27_19-58-59

I can provide the ROM data or project if needed.

Environment (please complete the following information):

  • OS: Linux Arch
  • Java Version: OpenJDK Runtime Environment (build 11.0.16.1+1)
  • Ghidra Version: Version 10.1.5 Build DEV 2022-Aug-14 1349 UTC
  • Ghidra Origin: Arch package

hjanetzek avatar Aug 27 '22 18:08 hjanetzek

Setting the region to be initialized removes the = ?? from listing view but does not affect ~disassembly~ decompilation (also not after re-create function or clear code and run disassemble again shot-2022-08-27_22-00-26 )

hjanetzek avatar Aug 27 '22 20:08 hjanetzek

Found the option for saving the decompile debug log :) https://gist.github.com/hjanetzek/4e1bfbdbc7eb6282385084da7c5b426f

hjanetzek avatar Aug 27 '22 21:08 hjanetzek

You keep saying disassembly, do you mean decompiler, or is the assembly presented incorrectly?

The OUT from z80 is probably how 8085 should be written in SLEIGH, but on master decompiler was still not showing 2 stores even with a fix (make PCODE have a STORE). When loading this function as z80 it does have both,

mumbel avatar Aug 28 '22 20:08 mumbel

Thank you for the pointer, I'll have a look.

... sorry about the wrong terminology - it's my first project like this.

hjanetzek avatar Aug 28 '22 20:08 hjanetzek

Could it suffice to just edit 8085.slaspec file? Yesterday I've changed it to

macro ioWrite(addr,val) {
   *[io]:1 addr = val;
}

:OUT IOAddr8  is op0_8=0xd3; IOAddr8 {
        ioWrite(IOAddr8, A);
}

And after restart today the OUT instructions show up in decompiled code: shot-2022-08-29_20-09-04

hjanetzek avatar Aug 29 '22 18:08 hjanetzek

@hjanetzek Can you do me a favor and on the listing view click the button to Edit the Listing fields, then enable the PCode field so I can see what the pcode for the OUT instruction is showing in your binary?

GhidorahRex avatar Sep 12 '22 14:09 GhidorahRex

Hi @GhidorahRex - I tried but PCode seems not to possible to activate. The button stays greyed out when clicking or moving to other rows. shot-2022-09-12_16-54-41

hjanetzek avatar Sep 12 '22 14:09 hjanetzek

Sorry, I forgot to mention: you should be able to right-click it and select "enable field"

GhidorahRex avatar Sep 12 '22 15:09 GhidorahRex

ok - there it is shot-2022-09-12_17-04-26

hjanetzek avatar Sep 12 '22 15:09 hjanetzek

This is the listing after you modified the OUT instruction to use the macro, correct?

GhidorahRex avatar Sep 12 '22 15:09 GhidorahRex

Yes right. now it should be back to the original

shot-2022-09-12_18-02-38

hjanetzek avatar Sep 12 '22 16:09 hjanetzek

Still trying to troubleshoot to get the correct fix, but adding <range space="io"/> to the global section in 8085.cspec then restarting ghidra provides a better fix than adding the macro.

GhidorahRex avatar Sep 12 '22 16:09 GhidorahRex

LGTM :)

hjanetzek avatar Sep 12 '22 16:09 hjanetzek

I guess it threw me off, didn't really realize there's two syntax for STORE operations. Didn't expect an issue that big vs just the one instruction/constructor. Out of curiosity is there something weird about that where *[]X = COPY A is preferred over a STORE. Guessing high PCODE would eventually convert to STORE?

mumbel avatar Sep 12 '22 18:09 mumbel

I had a similar issue when decompiling Z80 assembly. Marking the io memory as volatile as described in #2257 was an effective workaround.

neuromancer avatar Mar 09 '24 11:03 neuromancer