Skip to content

Commit 7f8c663

Browse files
committed
pointer masking: Implement hstatus.HUPMM (Flush TLB on changing hstatus.HUPMM)
1 parent 69f0c46 commit 7f8c663

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

riscv/csrs.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,8 +1859,15 @@ hstatus_csr_t::hstatus_csr_t(processor_t* const proc, const reg_t addr):
18591859
bool hstatus_csr_t::unlogged_write(const reg_t val) noexcept {
18601860
const reg_t mask = HSTATUS_VTSR | HSTATUS_VTW
18611861
| (proc->supports_impl(IMPL_MMU) ? HSTATUS_VTVM : 0)
1862+
| (proc->extension_enabled(EXT_SSNPM) ? HSTATUS_HUPMM : 0)
18621863
| HSTATUS_HU | HSTATUS_SPVP | HSTATUS_SPV | HSTATUS_GVA;
18631864

1864-
const reg_t new_hstatus = (read() & ~mask) | (val & mask);
1865+
const reg_t pmm_reserved = 1; // Reserved value of mseccfg.PMM
1866+
reg_t pmm = get_field(val, HSTATUS_HUPMM);
1867+
const reg_t adjusted_val = set_field(val, HSTATUS_HUPMM, pmm != pmm_reserved ? pmm : 0);
1868+
1869+
const reg_t new_hstatus = (read() & ~mask) | (adjusted_val & mask);
1870+
if (get_field(new_hstatus, HSTATUS_HUPMM) != get_field(read(), HSTATUS_HUPMM))
1871+
proc->get_mmu()->flush_tlb();
18651872
return basic_csr_t::unlogged_write(new_hstatus);
18661873
}

riscv/mmu.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,12 @@ reg_t mmu_t::get_pmlen(bool effective_virt, reg_t effective_priv, xlate_flags_t
624624
pmm = get_field(proc->state.menvcfg->read(), MENVCFG_PMM);
625625
else if (effective_virt && effective_priv == PRV_S)
626626
pmm = get_field(proc->state.henvcfg->read(), HENVCFG_PMM);
627+
else if (proc->state.prv == PRV_U && flags.forced_virt)
628+
pmm = get_field(proc->state.hstatus->read(), HSTATUS_HUPMM);
627629
else if (effective_priv == PRV_U)
628630
pmm = get_field(proc->state.senvcfg->read(), SENVCFG_PMM);
631+
else
632+
assert(false);
629633

630634
switch (pmm) {
631635
case 2: return 7;

0 commit comments

Comments
 (0)