aboutsummaryrefslogtreecommitdiff
path: root/riscv/csrs.cc
diff options
context:
space:
mode:
authorYenHaoChen <howard25336284@gmail.com>2024-02-02 10:17:30 +0800
committerYenHaoChen <howard25336284@gmail.com>2024-02-06 08:43:50 +0800
commit20a735414863ffaa5525bc5bac04f6bc256e6f07 (patch)
treedc4af280e8a5971150b5df99cb3c659ab4b5091a /riscv/csrs.cc
parent7c890632ec91104fe6ccd9f16f70842c4412a1fd (diff)
downloadriscv-isa-sim-20a735414863ffaa5525bc5bac04f6bc256e6f07.zip
riscv-isa-sim-20a735414863ffaa5525bc5bac04f6bc256e6f07.tar.gz
riscv-isa-sim-20a735414863ffaa5525bc5bac04f6bc256e6f07.tar.bz2
Fix hvip.VSEIP and hvip.VSTIP, so they don't observe platform-specific interrupts or CSR hgeip bits
The H extension defines that bits VSEIP, VSTIP, and VSSIP of hvip are writable. (The other bits of hvip are read-only 0.) Only hip.VSSIP (mip.VSSIP) is an alias of hvip.VSSIP. The hip.VSEIP is the logical-OR of hvip.VSEIP, selected bit of hgeip by hstatus.VGEIN, and platform-specific external interrupt signals to VS-level, e.g., from AIA. The hip.VSTIP is the logical-OR of hvip.VSTIP and platform-specific timer interrupt signals to VS-level, e.g., from Sstc. Thus, the read values of hvip.VSEIP and hvip.VSTIP differ from the ones of hip.VSEIP and hip.VSTIP (mip.VSEIP and mip.VSTIP). In other words, the hvip isn't an alias (proxy) of mip. The current aliasing (proxy) implementation does not provide the desired behavior for hvip.VSEIP and hvip.VSTIP. An ISA-level behavior difference is that any platform-specific external and timer interrupt signals directed to VS-level should not be observable through the hvip. For instance, the hvip should not observe the virtual timer interrupt signal from the vstimecmp CSR (Sstc extension), which isn't true in the current implementation. Additionally, the hvip should not observe the virtual external interrupt signal from the IMSIC device (AIA extension). Another ISA-level behavior difference is that the hgeip and hstatus.VGEIN also should not affect hvip.VSEIP, which isn't true in the current implementation. This commit fixes the issue by giving the hvip a specialized class, hvip_csr_t. The hvip_csr_t aliases the hvip.VSSIP to the mip.VSSIP but decouples the hvip.VSEIP and hvip.VSTIP from mip.VSEIP and mip.VSTIP. Additionally, the commit updates the read value of mip to be the logical-OR of hvip.VSEIP, hvip.VSTIP, and other sources.
Diffstat (limited to 'riscv/csrs.cc')
-rw-r--r--riscv/csrs.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/riscv/csrs.cc b/riscv/csrs.cc
index b76b496..74f07c9 100644
--- a/riscv/csrs.cc
+++ b/riscv/csrs.cc
@@ -728,6 +728,10 @@ mip_csr_t::mip_csr_t(processor_t* const proc, const reg_t addr):
mip_or_mie_csr_t(proc, addr) {
}
+reg_t mip_csr_t::read() const noexcept {
+ return val | state->hvip->basic_csr_t::read();
+}
+
void mip_csr_t::backdoor_write_with_mask(const reg_t mask, const reg_t val) noexcept {
this->val = (this->val & ~mask) | (val & mask);
}
@@ -1717,3 +1721,16 @@ void srmcfg_csr_t::verify_permissions(insn_t insn, bool write) const {
if (state->v)
throw trap_virtual_instruction(insn.bits());
}
+
+hvip_csr_t::hvip_csr_t(processor_t* const proc, const reg_t addr, const reg_t init):
+ basic_csr_t(proc, addr, init) {
+}
+
+reg_t hvip_csr_t::read() const noexcept {
+ return basic_csr_t::read() | (state->mip->read() & MIP_VSSIP); // hvip.VSSIP is an alias of mip.VSSIP
+}
+
+bool hvip_csr_t::unlogged_write(const reg_t val) noexcept {
+ state->mip->write_with_mask(MIP_VSSIP, val); // hvip.VSSIP is an alias of mip.VSSIP
+ return basic_csr_t::unlogged_write(val & (MIP_VSEIP | MIP_VSTIP));
+}