Skip to content

Commit 70687cc

Browse files
authored
Merge pull request #2015 from binno/fix_mseccfg_write
Continue mseccfg write operation even without PMP setting
2 parents 79907ef + c17d206 commit 70687cc

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

riscv/csrs.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -315,31 +315,31 @@ bool mseccfg_csr_t::get_sseed() const noexcept {
315315
}
316316

317317
bool mseccfg_csr_t::unlogged_write(const reg_t val) noexcept {
318-
if (proc->n_pmp == 0)
319-
return false;
320-
321-
// pmpcfg.L is 1 in any rule or entry (including disabled entries)
322-
const bool pmplock_recorded = std::any_of(state->pmpaddr, state->pmpaddr + proc->n_pmp,
323-
[](const pmpaddr_csr_t_p & c) { return c->is_locked(); } );
324318
reg_t new_val = read();
325319

326-
// When RLB is 0 and pmplock_recorded, RLB is locked to 0.
327-
// Otherwise set the RLB bit according val
328-
if (!(pmplock_recorded && (read() & MSECCFG_RLB) == 0)) {
329-
new_val &= ~MSECCFG_RLB;
330-
new_val |= (val & MSECCFG_RLB);
331-
}
320+
if (proc->n_pmp != 0) {
321+
// pmpcfg.L is 1 in any rule or entry (including disabled entries)
322+
const bool pmplock_recorded = std::any_of(state->pmpaddr, state->pmpaddr + proc->n_pmp,
323+
[](const pmpaddr_csr_t_p & c) { return c->is_locked(); } );
324+
325+
// When RLB is 0 and pmplock_recorded, RLB is locked to 0.
326+
// Otherwise set the RLB bit according val
327+
if (!(pmplock_recorded && (read() & MSECCFG_RLB) == 0)) {
328+
new_val &= ~MSECCFG_RLB;
329+
new_val |= (val & MSECCFG_RLB);
330+
}
332331

333-
new_val |= (val & MSECCFG_MMWP); //MMWP is sticky
334-
new_val |= (val & MSECCFG_MML); //MML is sticky
332+
new_val |= (val & MSECCFG_MMWP); //MMWP is sticky
333+
new_val |= (val & MSECCFG_MML); //MML is sticky
334+
335+
proc->get_mmu()->flush_tlb();
336+
}
335337

336338
if (proc->extension_enabled(EXT_ZKR)) {
337339
uint64_t mask = MSECCFG_USEED | MSECCFG_SSEED;
338340
new_val = (new_val & ~mask) | (val & mask);
339341
}
340342

341-
proc->get_mmu()->flush_tlb();
342-
343343
if (proc->extension_enabled(EXT_ZICFILP)) {
344344
new_val &= ~MSECCFG_MLPE;
345345
new_val |= (val & MSECCFG_MLPE);

0 commit comments

Comments
 (0)