Skip to content

Commit 0648ab4

Browse files
committed
pointer masking: refactor: Use xlen to avoid sketchy, hardcoded number 64
1 parent 3833093 commit 0648ab4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

riscv/mmu.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,11 @@ mem_access_info_t mmu_t::generate_access_info(reg_t addr, access_type type, xlat
654654
virt = true;
655655
mode = get_field(proc->state.hstatus->read(), HSTATUS_SPVP);
656656
}
657+
auto xlen = proc->get_const_xlen();
657658
reg_t pmlen = get_pmlen(virt, mode, xlate_flags);
658659
reg_t satp = proc->state.satp->readvirt(virt);
659660
bool is_physical_addr = mode == PRV_M || get_field(satp, SATP64_MODE) == SATP_MODE_OFF;
660-
transformed_addr = is_physical_addr ? zext(addr, 64 - pmlen) : sext(addr, 64 - pmlen);
661+
transformed_addr = is_physical_addr ? zext(addr, xlen - pmlen) : sext(addr, xlen - pmlen);
661662
}
662663
return {addr, transformed_addr, mode, virt, xlate_flags, type};
663664
}

0 commit comments

Comments
 (0)