PMP fetch exception causing `X` propagation through IF stage
Hi Tom,
I ran into 2 related (at least in this situation) issues when running some PMP tests, the waves and a code snippet are shown below:
In this situation, all PMP regions are using TOR address matching, pmpaddr0 is set to the address of <main> (which gets word-aligned to 0x80001e14) with all permissions enabled, and pmpaddr1 is set to 0x8000447c with all permissions initially disabled. With regards to instruction execution order, Ibex has just executed a jump instruction located at 0x80000314 and has jumped to <main>.
Just before the M3 marker in the waves, Ibex is executing an instruction fetch from 80001e14 to handle the first half of the misaligned instruction located at <main>, we can see that the request line goes high successfully and the testbench responds by asserting the grant line which goes high right at the M3 marker.
The first issue I see here is that given the PMP configuration this fetch to 80001e14 should raise an exception immediately as this address is controlled by the pmpaddr1 region, but the core allows this fetch to succeed as it has somehow matched this to region0. I think this error is due to how region_match_high[c][r] is assigned within the PMP matching logic - it seems like it should be a strict < inequality instead of a <= to check equality of the upper bound as per the PMP specification of TOR matching.
Going past this error, what happens next is also fairly interesting; first just after M3, the core is about to send a second fetch request to 0x80001e18 to fulfill the second part of the misaligned instruction at <main>, but correctly flags it as a PMP fault and does not raise the top level request line to the testbench to complete the misaligned instruction fetch.
At marker M1, the testbench asserts rvalid on the IMEM interface and responds with the data word 0x61170000 to fulfill the fetch request to 0x80001e14, the upper half of which matches the lower half of the instruction at <main>, and the lower half of which matches the ecall at 80001e12. The fifo in the prefetcher however seems to think that it should still output a valid instruction on the following cycle, constructs an rdata_unaligned out of in_rdata_i[15:0] and rdata[31:16] (which results in 0xXXXX6117), and raises out_valid_o to qualify this instruction to the rest of the pipeline, resulting in ASSERT_KNOWN_IF failures later on in the decode stage, the IbexBranchDecisionValid assertion in particular.
Should now be fixed