Two secutive exception, tlb refill -> tlb fetch
- ERA is wrong on fetch exceptions after a branch. Every fetch fault on a branch target reports the branch’s PC, not the target:
┌─────────────────────────┬──────────────┬───────────┐
│ Fetch fault on │ ERA reported │ Should be │
├─────────────────────────┼──────────────┼───────────┤
│ 0x2C120 (bl at 0x10730) │ 0x10730 │ 0x2C120 │
├─────────────────────────┼──────────────┼───────────┤
│ 0x4F210 (bl at 0x2A20C) │ 0x2A20C │ 0x4F210 │
├─────────────────────────┼──────────────┼───────────┤
│ 0x0 (jirl at 0x2A204) │ 0x2A204 │ 0x0 │
└─────────────────────────┴──────────────┴───────────┘
BADV is correct (pf_vaddr_q), but the PC sent with the exception (ifu_exu_pc_d) comes from the previous instruction. It works today because re-running bl/jirl r0 gives the same result. It breaks for branches that aren’t safe to repeat, like jirl $r1,$r1,0, and it confuses the kernel’s fault reporting. When fet_exc_vld/tlbr/pif/ppi is set, ifu_exu_pc_d should be pf_vaddr_q.
One more hardware finding: ERA after an interrupt right after ertn is kept by a workaround
In c7bcsr.v l.412: assign era_exception_wen = exu_csr_except_w & ~exu_csr_last_inst_ertn; When the instruction just before the exception was ertn (true here, because the interrupt was taken on the first instruction after returning from the page fault), ERA is not updated and keeps the old value. In this case that is correct only because the first instruction after ertn is always at ERA.