Skip to content

Commit 69f0c46

Browse files
committed
refactor: Add specialized hstatus_csr_t
1 parent c268fb2 commit 69f0c46

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

riscv/csrs.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,3 +1851,16 @@ void mtval2_csr_t::verify_permissions(insn_t insn, bool write) const {
18511851
if (!proc->extension_enabled('H') && !proc->extension_enabled(EXT_SSDBLTRP))
18521852
throw trap_illegal_instruction(insn.bits());
18531853
}
1854+
1855+
hstatus_csr_t::hstatus_csr_t(processor_t* const proc, const reg_t addr):
1856+
basic_csr_t(proc, addr, set_field((reg_t)0, HSTATUS_VSXL, xlen_to_uxl(proc->get_const_xlen()))) {
1857+
}
1858+
1859+
bool hstatus_csr_t::unlogged_write(const reg_t val) noexcept {
1860+
const reg_t mask = HSTATUS_VTSR | HSTATUS_VTW
1861+
| (proc->supports_impl(IMPL_MMU) ? HSTATUS_VTVM : 0)
1862+
| HSTATUS_HU | HSTATUS_SPVP | HSTATUS_SPV | HSTATUS_GVA;
1863+
1864+
const reg_t new_hstatus = (read() & ~mask) | (val & mask);
1865+
return basic_csr_t::unlogged_write(new_hstatus);
1866+
}

riscv/csrs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,4 +891,11 @@ class mtval2_csr_t: public hypervisor_csr_t {
891891
mtval2_csr_t(processor_t* const proc, const reg_t addr);
892892
virtual void verify_permissions(insn_t insn, bool write) const override;
893893
};
894+
895+
class hstatus_csr_t final: public basic_csr_t {
896+
public:
897+
hstatus_csr_t(processor_t* const proc, const reg_t addr);
898+
protected:
899+
virtual bool unlogged_write(const reg_t val) noexcept override;
900+
};
894901
#endif

riscv/processor.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,7 @@ void state_t::reset(processor_t* const proc, reg_t max_isa)
297297
csrmap[CSR_SCAUSE] = scause = std::make_shared<virtualized_csr_t>(proc, nonvirtual_scause, vscause);
298298
csrmap[CSR_MTVAL2] = mtval2 = std::make_shared<mtval2_csr_t>(proc, CSR_MTVAL2);
299299
csrmap[CSR_MTINST] = mtinst = std::make_shared<hypervisor_csr_t>(proc, CSR_MTINST);
300-
const reg_t hstatus_init = set_field((reg_t)0, HSTATUS_VSXL, xlen_to_uxl(proc->get_const_xlen()));
301-
const reg_t hstatus_mask = HSTATUS_VTSR | HSTATUS_VTW
302-
| (proc->supports_impl(IMPL_MMU) ? HSTATUS_VTVM : 0)
303-
| HSTATUS_HU | HSTATUS_SPVP | HSTATUS_SPV | HSTATUS_GVA;
304-
csrmap[CSR_HSTATUS] = hstatus = std::make_shared<masked_csr_t>(proc, CSR_HSTATUS, hstatus_mask, hstatus_init);
300+
csrmap[CSR_HSTATUS] = hstatus = std::make_shared<hstatus_csr_t>(proc, CSR_HSTATUS);
305301
csrmap[CSR_HGEIE] = std::make_shared<const_csr_t>(proc, CSR_HGEIE, 0);
306302
csrmap[CSR_HGEIP] = std::make_shared<const_csr_t>(proc, CSR_HGEIP, 0);
307303
csrmap[CSR_HIDELEG] = hideleg = std::make_shared<hideleg_csr_t>(proc, CSR_HIDELEG, mideleg);

0 commit comments

Comments
 (0)