From 85ab2228ddb802c33a967349d69b2d948846bd01 Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Wed, 13 Jul 2022 09:33:36 -0700 Subject: Add proxy for accessing the low 32 bits of a 64-bit CSR Use this for mstatus on RV32 so that `csrw mstatus` does not modify the bits in `mstatush`. Fixes #1044. --- riscv/csrs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'riscv/csrs.h') diff --git a/riscv/csrs.h b/riscv/csrs.h index 3998d79..500bde7 100644 --- a/riscv/csrs.h +++ b/riscv/csrs.h @@ -54,7 +54,9 @@ class csr_t { const unsigned csr_priv; const bool csr_read_only; + // For access to written_value() and unlogged_write(): friend class rv32_high_csr_t; + friend class rv32_low_csr_t; }; typedef std::shared_ptr csr_t_p; @@ -249,6 +251,19 @@ class mstatus_csr_t final: public base_status_csr_t { typedef std::shared_ptr mstatus_csr_t_p; +// For RV32 CSRs that are split into two, e.g. mstatus/mstatush +// CSRW should only modify the lower half +class rv32_low_csr_t: public csr_t { + public: + rv32_low_csr_t(processor_t* const proc, const reg_t addr, csr_t_p orig); + virtual reg_t read() const noexcept override; + virtual void verify_permissions(insn_t insn, bool write) const override; + protected: + virtual bool unlogged_write(const reg_t val) noexcept override; + private: + csr_t_p orig; +}; + class rv32_high_csr_t: public csr_t { public: rv32_high_csr_t(processor_t* const proc, const reg_t addr, csr_t_p orig); -- cgit v1.1