Skip to content

Commit 07655a2

Browse files
committed
fixes PMP and memory access handling
1 parent a778cdd commit 07655a2

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/iss/arch/riscv_hart_msu_vp.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,14 @@ iss::status riscv_hart_msu_vp<BASE, FEAT>::read(const addr_t& a, const unsigned
267267
return iss::Err;
268268
}
269269
auto res = this->memory.rd_mem({address_type::VIRTUAL, a.access, a.space, a.val}, length, data);
270-
if(unlikely(res != iss::Ok && (access & access_type::DEBUG) == 0)) {
271-
this->reg.trap_state = (1UL << 31) | traits<BASE>::RV_CAUSE_LOAD_ACCESS << 16;
270+
if(unlikely(res != iss::Ok && !is_debug(a.access))) {
271+
auto trap_id = is_fetch(a.access)?traits<BASE>::RV_CAUSE_FETCH_ACCESS:traits<BASE>::RV_CAUSE_LOAD_ACCESS;
272+
this->reg.trap_state = (1UL << 31) | trap_id << 16;
272273
this->fault_data = addr;
273274
}
274275
return res;
275276
} catch(trap_access& ta) {
276-
if((access & access_type::DEBUG) == 0) {
277+
if(!is_debug(access)) {
277278
this->reg.trap_state = (1UL << 31) | ta.id;
278279
this->fault_data = ta.addr;
279280
}
@@ -283,7 +284,7 @@ iss::status riscv_hart_msu_vp<BASE, FEAT>::read(const addr_t& a, const unsigned
283284
}
284285
return iss::Ok;
285286
} catch(trap_access& ta) {
286-
if((access & access_type::DEBUG) == 0) {
287+
if(!is_debug(access)) {
287288
this->reg.trap_state = (1UL << 31) | ta.id;
288289
this->fault_data = ta.addr;
289290
}
@@ -386,7 +387,7 @@ iss::status riscv_hart_msu_vp<BASE, FEAT>::write(const addr_t& a, const unsigned
386387
}
387388
return iss::Ok;
388389
} catch(trap_access& ta) {
389-
if((access & access_type::DEBUG) == 0) {
390+
if(!is_debug(access)) {
390391
this->reg.trap_state = (1UL << 31) | ta.id;
391392
this->fault_data = ta.addr;
392393
}

src/iss/arch/riscv_hart_mu_p.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,14 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::read(const addr_t& a, const unsigned le
229229
return iss::Err;
230230
}
231231
auto res = this->memory.rd_mem({address_type::PHYSICAL, a.access, a.space, a.val}, length, data);
232-
if(unlikely(res != iss::Ok && (access & access_type::DEBUG) == 0)) {
233-
this->reg.trap_state = (1UL << 31) | traits<BASE>::RV_CAUSE_LOAD_ACCESS << 16;
232+
if(unlikely(res != iss::Ok && !is_debug(access))) {
233+
auto trap_id = is_fetch(a.access)?traits<BASE>::RV_CAUSE_FETCH_ACCESS:traits<BASE>::RV_CAUSE_LOAD_ACCESS;
234+
this->reg.trap_state = (1UL << 31) | trap_id << 16;
234235
this->fault_data = addr;
235236
}
236237
return res;
237238
} catch(trap_access& ta) {
238-
if((access & access_type::DEBUG) == 0) {
239+
if(!is_debug(access)) {
239240
this->reg.trap_state = (1UL << 31) | ta.id;
240241
this->fault_data = ta.addr;
241242
}
@@ -245,7 +246,7 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::read(const addr_t& a, const unsigned le
245246
}
246247
return iss::Ok;
247248
} catch(trap_access& ta) {
248-
if((access & access_type::DEBUG) == 0) {
249+
if(!is_debug(access)) {
249250
this->reg.trap_state = (1UL << 31) | ta.id;
250251
this->fault_data = ta.addr;
251252
}
@@ -334,7 +335,7 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::write(const addr_t& a, const unsigned l
334335
}
335336
return iss::Ok;
336337
} catch(trap_access& ta) {
337-
if((access & access_type::DEBUG) == 0) {
338+
if(!is_debug(access)) {
338339
this->reg.trap_state = (1UL << 31) | ta.id;
339340
this->fault_data = ta.addr;
340341
}

src/iss/mem/pmp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ template <typename PLAT, size_t NUM_ENTRIES = 16> struct pmp : public memory_ele
9494
!pmp_check(addr.access, addr.val, length) && !is_debug(addr.access)) {
9595
if(is_debug(addr.access))
9696
throw trap_access(0, addr.val);
97-
hart_if.raise_trap(/*trap_id*/ 0, /*cause*/ (addr.access == access_type::FETCH) ? 1 : 5, /*fault_data*/ addr.val);
97+
// trap is raised in privilege wrapper
9898
return iss::Err;
9999
}
100100
return down_stream_mem.rd_mem(addr, length, data);
@@ -105,7 +105,7 @@ template <typename PLAT, size_t NUM_ENTRIES = 16> struct pmp : public memory_ele
105105
if(likely(addr.space == arch::traits<PLAT>::MEM) && !pmp_check(addr.access, addr.val, length) && !is_debug(addr.access)) {
106106
if(is_debug(addr.access))
107107
throw trap_access(0, addr.val);
108-
hart_if.raise_trap(/*trap_id*/ 0, /*cause*/ 7, /*fault_data*/ addr.val);
108+
// trap is raised in privilege wrapper, so we just return error
109109
return iss::Err;
110110
}
111111
return down_stream_mem.wr_mem(addr, length, data);

0 commit comments

Comments
 (0)