Skip to content

Commit a101bfe

Browse files
committed
Ignore writes to henvcfg fields (PBMTE, STCE, and ADUE) when read-only 0
The henvcfg fields, i.e., PBMTE, STCE, and ADUE, are read-only 0 when the corresponding bits in menvcfg are 0. Besides the reading behavior, the spec also specified the writing behavior, i.e., ignoring writes. This commit ignores writes to the henvcfg fields when read-only 0. Reference: riscv/riscv-isa-manual#1312
1 parent 3427b45 commit a101bfe

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

riscv/csrs.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,11 @@ void henvcfg_csr_t::verify_permissions(insn_t insn, bool write) const {
15491549
masked_csr_t::verify_permissions(insn, write);
15501550
}
15511551

1552+
bool henvcfg_csr_t::unlogged_write(const reg_t val) noexcept {
1553+
const reg_t mask = menvcfg->read() | ~(MENVCFG_PBMTE | MENVCFG_STCE | MENVCFG_ADUE);
1554+
return envcfg_csr_t::unlogged_write((masked_csr_t::read() & ~mask) | (val & mask));
1555+
}
1556+
15521557
stimecmp_csr_t::stimecmp_csr_t(processor_t* const proc, const reg_t addr, const reg_t imask):
15531558
basic_csr_t(proc, addr, 0), intr_mask(imask) {
15541559
}

riscv/csrs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ class henvcfg_csr_t final: public envcfg_csr_t {
490490

491491
virtual void verify_permissions(insn_t insn, bool write) const override;
492492

493+
protected:
494+
virtual bool unlogged_write(const reg_t val) noexcept override;
495+
493496
private:
494497
csr_t_p menvcfg;
495498
};

0 commit comments

Comments
 (0)