Skip to content

Commit 33d80b4

Browse files
authored
Merge pull request #1776 from YenHaoChen/pr-pm
pointer masking: Fix: Let transformed_addr of fetching be unchanged
2 parents bfe9173 + 0648ab4 commit 33d80b4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

riscv/mmu.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ mem_access_info_t mmu_t::generate_access_info(reg_t addr, access_type type, xlat
643643
return {addr, addr, 0, false, {}, type};
644644
bool virt = proc->state.v;
645645
reg_t mode = proc->state.prv;
646+
reg_t transformed_addr = addr;
646647
if (type != FETCH) {
647648
if (in_mprv()) {
648649
mode = get_field(proc->state.mstatus->read(), MSTATUS_MPP);
@@ -653,10 +654,11 @@ mem_access_info_t mmu_t::generate_access_info(reg_t addr, access_type type, xlat
653654
virt = true;
654655
mode = get_field(proc->state.hstatus->read(), HSTATUS_SPVP);
655656
}
657+
auto xlen = proc->get_const_xlen();
658+
reg_t pmlen = get_pmlen(virt, mode, xlate_flags);
659+
reg_t satp = proc->state.satp->readvirt(virt);
660+
bool is_physical_addr = mode == PRV_M || get_field(satp, SATP64_MODE) == SATP_MODE_OFF;
661+
transformed_addr = is_physical_addr ? zext(addr, xlen - pmlen) : sext(addr, xlen - pmlen);
656662
}
657-
reg_t pmlen = get_pmlen(virt, mode, xlate_flags);
658-
reg_t satp = proc->state.satp->readvirt(virt);
659-
bool is_physical_addr = mode == PRV_M || get_field(satp, SATP64_MODE) == SATP_MODE_OFF;
660-
reg_t transformed_addr = is_physical_addr ? zext(addr, 64 - pmlen) : sext(addr, 64 - pmlen);
661663
return {addr, transformed_addr, mode, virt, xlate_flags, type};
662664
}

0 commit comments

Comments
 (0)