Skip to content

Commit

Permalink
Merge pull request #1776 from YenHaoChen/pr-pm
Browse files Browse the repository at this point in the history
pointer masking: Fix: Let transformed_addr of fetching be unchanged
  • Loading branch information
aswaterman authored Aug 18, 2024
2 parents bfe9173 + 0648ab4 commit 33d80b4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions riscv/mmu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ mem_access_info_t mmu_t::generate_access_info(reg_t addr, access_type type, xlat
return {addr, addr, 0, false, {}, type};
bool virt = proc->state.v;
reg_t mode = proc->state.prv;
reg_t transformed_addr = addr;
if (type != FETCH) {
if (in_mprv()) {
mode = get_field(proc->state.mstatus->read(), MSTATUS_MPP);
Expand All @@ -653,10 +654,11 @@ mem_access_info_t mmu_t::generate_access_info(reg_t addr, access_type type, xlat
virt = true;
mode = get_field(proc->state.hstatus->read(), HSTATUS_SPVP);
}
auto xlen = proc->get_const_xlen();
reg_t pmlen = get_pmlen(virt, mode, xlate_flags);
reg_t satp = proc->state.satp->readvirt(virt);
bool is_physical_addr = mode == PRV_M || get_field(satp, SATP64_MODE) == SATP_MODE_OFF;
transformed_addr = is_physical_addr ? zext(addr, xlen - pmlen) : sext(addr, xlen - pmlen);
}
reg_t pmlen = get_pmlen(virt, mode, xlate_flags);
reg_t satp = proc->state.satp->readvirt(virt);
bool is_physical_addr = mode == PRV_M || get_field(satp, SATP64_MODE) == SATP_MODE_OFF;
reg_t transformed_addr = is_physical_addr ? zext(addr, 64 - pmlen) : sext(addr, 64 - pmlen);
return {addr, transformed_addr, mode, virt, xlate_flags, type};
}

0 comments on commit 33d80b4

Please sign in to comment.