Browse Source

AIA: Add inaccessible vstopei CSR

AIA introduces the concept of inaccessible CSR, where accessing from
M-mode or HS-mode raises an illegal instruction exception, but doing so
from VS-mode or VU-mode raises a virtual instruction exception.

Without IMSIC, mtopei and stopei do not exist. In contrast, vstopei is
an inaccessible CSR even without IMSIC, i.e., exits and is HS-qualified.

In summary, accessing stopei from M-mode or HS-mode (v=0) raises illegal
instruction, and accessing stopei (actually vstopei) from VS-mode or
VU-mode (v=1) raises virtual instruction.
pull/1988/head
YenHaoChen 2 years ago
committed by Binno
parent
commit
55152fe5ae
  1. 1
      riscv/csr_init.cc
  2. 11
      riscv/csrs.cc
  3. 9
      riscv/csrs.h

1
riscv/csr_init.cc

@ -527,6 +527,7 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa)
if (proc->extension_enabled_const(EXT_SSAIA)) { // Included by EXT_SMAIA
add_supervisor_csr(CSR_STOPI, std::make_shared<nonvirtual_stopi_csr_t>(proc, CSR_STOPI));
add_supervisor_csr(CSR_STOPEI, std::make_shared<inaccessible_csr_t>(proc, CSR_STOPEI));
auto hvien = std::make_shared<const_csr_t>(proc, CSR_HVIEN, 0);
auto hviprio1 = std::make_shared<const_csr_t>(proc, CSR_HVIPRIO1, 0);
auto hviprio2 = std::make_shared<const_csr_t>(proc, CSR_HVIPRIO2, 0);

11
riscv/csrs.cc

@ -2080,3 +2080,14 @@ reg_t nonvirtual_stopi_csr_t::read() const noexcept {
bool nonvirtual_stopi_csr_t::unlogged_write(const reg_t UNUSED val) noexcept {
return false;
}
inaccessible_csr_t::inaccessible_csr_t(processor_t* const proc, const reg_t addr):
csr_t(proc, addr) {
}
void inaccessible_csr_t::verify_permissions(insn_t insn, bool write) const {
if (state->v)
throw trap_virtual_instruction(insn.bits());
else
throw trap_illegal_instruction(insn.bits());
}

9
riscv/csrs.h

@ -957,4 +957,13 @@ class nonvirtual_stopi_csr_t: public csr_t {
protected:
bool unlogged_write(const reg_t val) noexcept override;
};
class inaccessible_csr_t: public csr_t {
public:
inaccessible_csr_t(processor_t* const proc, const reg_t addr);
virtual void verify_permissions(insn_t insn, bool write) const override;
reg_t read() const noexcept override { return 0; }
protected:
bool unlogged_write(const reg_t val) noexcept override { return false; }
};
#endif

Loading…
Cancel
Save