New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
M68000 decompiler: Read of volatile region ignored if followed by one or more writes #393
Comments
Does the read have any side-effect, like priming the NVRAM for write? Looks like the code is loading D0b with the volatile read, and then setting it to zero for the rest of the writes, unless I'm missing something. I suppose reading a value from volatile memory could have side-effects and support might need to be added, if there isn't a way to do this currently. |
@emteere - Yep, the read has side effects. This is part of a block of code which initialises a Dallas DS1234 NVRAM controller. The NVRAM controller "listens" to the RAM address bus for reads and writes -- a read resets a shift register inside the chip, then the following sixteen RAM writes carry an instruction code for the chip (in this case, it's "enable memory writes and NVRAM battery backup"). The instruction is executed (if valid) when the 16th bit is clocked in. I'd say that any read or write from volatile space should be shown, even if the result is discarded. This is a fairly common pattern for memory mapped I/O -- parts like ASICs and I/O ports doing things when a memory address is read or written. The 68682 UART has a few like this (e.g. read from an MMIO register to start the timer counting). |
I've noticed the same problem of volatile reads being dropped in the decompiled output for ARM programs, so it seems like this issue is not specific to the M68000 decompiler. Memory-mapped FIFO hardware registers are another good example of reads generating side effects, where each read removes an item from the FIFO regardless of whether the value is used later by the program. A specific scenario that I've observed in the ARM decompiler is disassembly along the lines of:
being decompiled into a single line like:
This is quite misleading, as the decompilation gives the impression that I support @philpem's suggestion of preserving all accesses to volatile memory, even when the results of such accesses are discarded. |
Is that related: #296 ? |
This should be fixed now in master and in upcoming 9.2. The problem was that the LOAD operation was getting removed as dead code before the decompiler discovered the load address was constant and in volatile memory. |
Describe the bug
When a read of a volatile memory region is followed by a sequence of zero-writes, the read is silently dropped from the decompiled output.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Decompiler shows a read from volatile space (with the result discarded), followed by a sequence of volatile writes of value zero.
Environment (please complete the following information):
Additional context
Disassembly extract:
Decompiler output:
Note that the byte read from NVRAMCON[30] into D0 is ignored, but the writes are accepted.
The text was updated successfully, but these errors were encountered: