From 2e7042897db661d6f4f4c9c2dd175fb8adb42984 Mon Sep 17 00:00:00 2001 From: "muhammad.moiz.hussain" Date: Fri, 2 Jan 2026 17:54:27 +0100 Subject: [PATCH] when AIA throw virt intruction exception and V=1 & vs-mode, otherwise throw illegal instruction exception --- riscv/csrs.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/riscv/csrs.cc b/riscv/csrs.cc index a805802e..4590ccd0 100644 --- a/riscv/csrs.cc +++ b/riscv/csrs.cc @@ -1919,7 +1919,16 @@ void sscsrind_reg_csr_t::verify_permissions(insn_t insn, bool write) const { csr_t_p proxy_csr = get_reg(); if (proxy_csr == nullptr) { - throw trap_illegal_instruction(insn.bits()); + // An attempt from VS-mode to access any inaccessible sireg* causes virtual instruction exception when AIA is enabled + if (proc->extension_enabled_const(EXT_SMAIA)) { + if (state->prv == PRV_S && state->v) { + throw trap_virtual_instruction(insn.bits()); + } else { + throw trap_illegal_instruction(insn.bits()); + } + } else { + throw trap_illegal_instruction(insn.bits()); + } } proxy_csr->verify_permissions(insn, write); }