armv4t_emu icon indicating copy to clipboard operation
armv4t_emu copied to clipboard

Proper Data / Prefetch Abort support

Open daniel5151 opened this issue 4 years ago • 0 comments

At the moment, the Memory trait assumes that all memory accesses are guaranteed to succeed. In reality, it's entirely possible for a memory access to fail, and for a Prefetch / Data Abort to be signaled.

This is particularly important when emulating systems with an MMU. This excerpt from the ARM7TDMI technical reference explains:

The abort mechanism enables the implementation of a demand-paged virtual memory system. In such a system, the processor is allowed to generate arbitrary addresses. When the data at an address is unavailable, the Memory Management Unit (MMU) signals an abort

It just so happens that the projects armv4t_emu was originally written for didn't use the MMU, and this functionality was overlooked in the implementation.


Taking a look at the code, this shouldn't be too tricky to fix.

  • Prefetch Aborts shouldn't be too bad, though some careful consideration needs to be taken to ensure each instruction is only accessed once (i.e: no double-reads)
  • Data Aborts will be a little trickier, since the behavior of the Data Abort varies depending on what instruction caused the abort.
  • Data Aborts under ARMv4T can be either Base Updated or Base Restored. Which of the two is decided on a per-implementation basis. e.g: ARM7TDMI uses the former, while ARM9TDMI uses the latter. There aught to be some way to toggling between these two modes.
  • There might be some interesting edge-case behavior in cases where a Data Abort and Prefetch Abort happen in quick succession.

The annoying thing with this change is how invasive it is. The Memory interface will have to be modified to return Option<uX> and Option<()>, where None signals an abort. Not only does this affect the public API, but it will also clutter up the ARM/Thumb instruction executors. That's fine, and is a fair price to pay for correctness.

daniel5151 avatar May 02 '20 04:05 daniel5151