From 929d6712119f8d4dbd62a054a4249e19e80d1c99 Mon Sep 17 00:00:00 2001 From: YenHaoChen Date: Tue, 27 Feb 2024 14:24:13 +0800 Subject: [PATCH] AIA: Let mvien.SSIP be writable When mvien.SSIP=0, mvip.SSIP is an alias of mip.SSIP. Accessing mvip.SSIP reads from and writes to mip.SSIP. When mvien.SSIP=1, mvip.SSIP is a separate writable bit independent of mip.SSIP. Accessing mvip.SSIP reads from and writes to the separate, writable, independent bit normally. --- riscv/csr_init.cc | 2 +- riscv/csrs.cc | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/riscv/csr_init.cc b/riscv/csr_init.cc index 307eab7b..a6c34a6e 100644 --- a/riscv/csr_init.cc +++ b/riscv/csr_init.cc @@ -475,7 +475,7 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa) const reg_t srmcfg_mask = SRMCFG_MCID | SRMCFG_RCID; add_const_ext_csr(EXT_SSQOSID, CSR_SRMCFG, std::make_shared(proc, CSR_SRMCFG, srmcfg_mask, 0)); - mvien = std::make_shared(proc, CSR_MVIEN, 0); + mvien = std::make_shared(proc, CSR_MVIEN, MIP_SSIP, 0); mvip = std::make_shared(proc, CSR_MVIP, 0); if (proc->extension_enabled_const(EXT_SMAIA)) { add_csr(CSR_MTOPI, std::make_shared(proc, CSR_MTOPI)); diff --git a/riscv/csrs.cc b/riscv/csrs.cc index e7f3a102..8dd5071e 100644 --- a/riscv/csrs.cc +++ b/riscv/csrs.cc @@ -1999,12 +1999,14 @@ mvip_csr_t::mvip_csr_t(processor_t* const proc, const reg_t addr, const reg_t in } reg_t mvip_csr_t::read() const noexcept { + const reg_t val = basic_csr_t::read(); + const reg_t mvien = state->mvien->read(); const reg_t mip = state->mip->read(); const reg_t menvcfg = state->menvcfg->read(); return 0 | (mip & MIP_SEIP) | ((menvcfg & MENVCFG_STCE) ? 0 : (mip & MIP_STIP)) - | (mip & MIP_SSIP) + | (((mvien & MIP_SSIP) ? val : mip) & MIP_SSIP) ; } @@ -2012,7 +2014,9 @@ bool mvip_csr_t::unlogged_write(const reg_t val) noexcept { state->mip->write_with_mask(MIP_SEIP, val); if (!(state->menvcfg->read() & MENVCFG_STCE)) state->mip->write_with_mask(MIP_STIP, val); // mvip.STIP is an alias of mip.STIP when mip.STIP is writable - state->mip->write_with_mask(MIP_SSIP, val); + if (!(state->mvien->read() & MIP_SSIP)) + state->mip->write_with_mask(MIP_SSIP, val); // mvip.SSIP is an alias of mip.SSIP when mvien.SSIP=0 - return false; + const reg_t new_val = ((state->mvien->read() & MIP_SSIP) ? val : basic_csr_t::read()) & MIP_SSIP; + return basic_csr_t::unlogged_write(new_val); }