NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
51.42k stars 5.86k forks source link

Z80: Decompiler gets confused when mixing interrupt control and stack operations #1208

Open agatti opened 4 years ago

agatti commented 4 years ago

Describe the bug The decompiler creates an incorrect instruction flow. Maybe it gets confused by stack manipulation and interrupt control code being interleaved rather than nested.

To Reproduce Steps to reproduce the behavior:

  1. Load the attached test.bin file as a Z80 binary starting at $8000.
  2. Let auto-analysis start - nothing will happen.
  3. Start disassemble from the very first instruction, the decompiler window will fill up with some invalid code.

Expected behavior In the decompiled code, enableMaskableInterrupts is supposed to appear after the write to DAT_io_00a1, not right after disableMaskableInterrupts.

Screenshots

Screenshot 2019-11-03 05 05 00

Attachments

test.bin.gz

Environment (please complete the following information):

emteere commented 4 years ago

Weird, will try to reproduce.

cbuschardt commented 4 years ago

Did you remember to mark the io region as volatile in the "Window->Memory Map" window?

agatti commented 4 years ago

@cbuschardt Marking the IO region as volatile lets the decompiler work as intended, indeed. Thanks for the tip.

That said, is it still a bug in the decompiler? Values are written to the IO area, so there are fewer assumptions to be made from the data in question.