Skip to content

Commit 3bd855f

Browse files
cphurley82eyck
authored andcommitted
fix: report an instruction access fault for a denied fetch
riscv_hart_m_p::read set RV_CAUSE_LOAD_ACCESS unconditionally when the memory chain returned an error, so a PMP-denied instruction fetch surfaced as a load access fault. RV_CAUSE_FETCH_ACCESS was consumed by the trap dispatch switch but never assigned in this wrapper. riscv_hart_mu_p and riscv_hart_msu_vp already selected the cause on is_fetch, so this was an oversight in the M-mode wrapper alone; it now matches them. The two fetch tests only asserted that some trap fired, which is why this went unnoticed; both now assert the cause.
1 parent 1c68c43 commit 3bd855f

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎src/iss/arch/riscv_hart_m_p.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ iss::status riscv_hart_m_p<BASE, FEAT>::read(const addr_t& a, const unsigned len
187187
}
188188
auto res = this->memory.rd_mem({address_type::PHYSICAL, a.access, a.space, a.val}, length, data);
189189
if(unlikely(res != iss::Ok && (access & access_type::DEBUG) == 0)) {
190-
this->reg.trap_state = (1UL << 31) | traits<BASE>::RV_CAUSE_LOAD_ACCESS << 16;
190+
auto trap_id = is_fetch(a.access) ? traits<BASE>::RV_CAUSE_FETCH_ACCESS : traits<BASE>::RV_CAUSE_LOAD_ACCESS;
191+
this->reg.trap_state = (1UL << 31) | trap_id << 16;
191192
this->fault_data = addr;
192193
}
193194
return res;

0 commit comments

Comments
 (0)