DMEM fault during misaligned memory access
Hi all,
When running this set of instructions:
The following waves were generated:
The sw instructions at PC=0x800058d0 has a misaligned memory address, and is thus split into two internal memory transactions. In the waves, around 395,800,000ps corresponds to the memory response to the first of these two transactions, which is when the testbench randomly asserts a memory fault here. According to Ibex documentation for this situation, the second memory transaction should continue as normal, ignoring the response data, and then the core needs to also jump to the corresponding fault handler (located at PC=0x80014000 in our case). The LSU's FSM transitions to it's error handling states from the misaligned transaction states, and the core jumps to 0x80014000 (which encodes the instruction j 80014080) directly after 0x800058d0, but while executing this jump instruction, the core jumps to 0x8001e112 instead, throwing an illegal instruction exception, and then proceeds to wait for the rvalid corresponding to the second part of the original misaligned transaction. This occurs around 395,835,000ps, and after this, the core jumps back to the fault handler, and fully executes it. This intermediate PC of 0x8001e112 is calculated as the incorrect jump address from load address data that's already in the execution pipeline, and is muxed through due to lsu_addr_incr_req_i going high while waiting for the second half of the misaligned memory transaction to complete. Maybe a potential solution for this would be to only jump to the fault handler after the second part of the misaligned transactions has completed?
Best,
Udi
When the changes were made to remove the timing loop on data_valid, I tried to keep the error behaviour the same as before. The core takes the error exception as soon as the first transaction completes, but the LSU carries on with the second transaction in the background. That's causing the issue here, and I can see other issues that might be caused by the LSU operating in the background. I'll prepare a PR to make the LSU stall the core until both parts of the transaction are complete (as suggested), and then take the exception if either aborted (recording the correct address).