Skip to content

Commit 928743b

Browse files
committed
Teach Sstc to respect xenvcfg.STCE
When menvcfg.STCE=0, mip.STIP reverts to its defined behavior as if unsupporting Sstc extension. When henvcfg.STCE=0, mip.VSTIP reverts to its defined behavior as if unsupporting Sstc extension. [riscvarchive/riscv-time-compare#5] The previous Sstc implementation does not respect the xenvcfg.STCE. In other words, the Sstc may assert mip.STIP (mip.VSTIP) when menvcfg.STCE=0 (henvcfg.STCE=0), which is a misbehaving.
1 parent 7c89063 commit 928743b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

riscv/csrs.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,8 @@ void time_counter_csr_t::sync(const reg_t val) noexcept {
10751075
if (proc->extension_enabled(EXT_SSTC)) {
10761076
const reg_t mip_val = (shadow_val >= state->stimecmp->read() ? MIP_STIP : 0) |
10771077
(shadow_val + state->htimedelta->read() >= state->vstimecmp->read() ? MIP_VSTIP : 0);
1078-
state->mip->backdoor_write_with_mask(MIP_STIP | MIP_VSTIP, mip_val);
1078+
const reg_t mask = ((state->menvcfg->read() & MENVCFG_STCE) ? MIP_STIP : 0) | ((state->henvcfg->read() & HENVCFG_STCE) ? MIP_VSTIP : 0);
1079+
state->mip->backdoor_write_with_mask(mask, mip_val);
10791080
}
10801081
}
10811082

@@ -1533,7 +1534,8 @@ stimecmp_csr_t::stimecmp_csr_t(processor_t* const proc, const reg_t addr, const
15331534
}
15341535

15351536
bool stimecmp_csr_t::unlogged_write(const reg_t val) noexcept {
1536-
state->mip->backdoor_write_with_mask(intr_mask, state->time->read() >= val ? intr_mask : 0);
1537+
const reg_t mask = ((state->menvcfg->read() & MENVCFG_STCE) ? MIP_STIP : 0) | ((state->henvcfg->read() & HENVCFG_STCE) ? MIP_VSTIP : 0);
1538+
state->mip->backdoor_write_with_mask(mask, state->time->read() >= val ? intr_mask : 0);
15371539
return basic_csr_t::unlogged_write(val);
15381540
}
15391541

0 commit comments

Comments
 (0)