Skip to content

Commit

Permalink
Smstateen: Implement *stateen0[59] controlling CSR vstopi
Browse files Browse the repository at this point in the history
  • Loading branch information
YenHaoChen committed May 9, 2024
1 parent 653444f commit cd83c62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions riscv/csrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,18 @@ vstopi_csr_t::vstopi_csr_t(processor_t* const proc, const reg_t addr):
csr_t(proc, addr) {
}

void vstopi_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 vstopi_csr_t::read() const noexcept {
reg_t hvictl = state->hvictl->read();
bool vti = hvictl & HVICTL_VTI;
Expand Down
1 change: 1 addition & 0 deletions riscv/csrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ class inaccessible_csr_t: public csr_t {
class vstopi_csr_t: public csr_t {
public:
vstopi_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

0 comments on commit cd83c62

Please sign in to comment.