Skip to content

Commit

Permalink
Smstateen: Implement *stateen0[59] controlling CSR stopi
Browse files Browse the repository at this point in the history
  • Loading branch information
YenHaoChen committed May 10, 2024
1 parent af497f3 commit c4a012f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions riscv/csrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,18 @@ nonvirtual_stopi_csr_t::nonvirtual_stopi_csr_t(processor_t* const proc, const re
csr_t(proc, addr) {
}

void nonvirtual_stopi_csr_t::verify_permissions(insn_t insn, bool write) const {
if (proc->extension_enabled(EXT_SMSTATEEN)) {
if ((state->prv < PRV_M) && !(state->mstateen[0]->read() & MSTATEEN0_AIA))
throw trap_illegal_instruction(insn.bits());

if (state->v && !(state->hstateen[0]->read() & HSTATEEN0_AIA))
throw trap_virtual_instruction(insn.bits());
}

csr_t::verify_permissions(insn, write);
}

reg_t nonvirtual_stopi_csr_t::read() const noexcept {
reg_t enabled_interrupts = state->nonvirtual_sip->read() & state->nonvirtual_sie->read() & state->mideleg->read() & ~state->hideleg->read();
if (!enabled_interrupts)
Expand Down
1 change: 1 addition & 0 deletions riscv/csrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ typedef std::shared_ptr<mvip_csr_t> mvip_csr_t_p;
class nonvirtual_stopi_csr_t: public csr_t {
public:
nonvirtual_stopi_csr_t(processor_t* const proc, const reg_t addr);
virtual void verify_permissions(insn_t insn, bool write) const override;
virtual reg_t read() const noexcept override;
protected:
bool unlogged_write(const reg_t val) noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion riscv/processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ void state_t::reset(processor_t* const proc, reg_t max_isa)
vstopi = csrmap[CSR_VSTOPI] = std::make_shared<vstopi_csr_t>(proc, CSR_VSTOPI);
if (proc->extension_enabled_const(EXT_SSAIA)) { // Included by EXT_SMAIA
csr_t_p nonvirtual_stopi = std::make_shared<nonvirtual_stopi_csr_t>(proc, CSR_STOPI);
csrmap[CSR_STOPI] = std::make_shared<virtualized_csr_t>(proc, nonvirtual_stopi, vstopi);
csrmap[CSR_STOPI] = std::make_shared<virtualized_stimecmp_csr_t>(proc, nonvirtual_stopi, vstopi);
csrmap[CSR_STOPEI] = std::make_shared<inaccessible_csr_t>(proc, CSR_STOPEI);
auto hvien = std::make_shared<aia_csr_t>(proc, CSR_HVIEN, 0, 0);
auto hviprio1 = std::make_shared<aia_csr_t>(proc, CSR_HVIPRIO1, 0, 0);
Expand Down

0 comments on commit c4a012f

Please sign in to comment.