[BUG] Wrong exception cause being raised in CSR Logic (illegal instruction instead of Virtual Instruction exception)
Created by: somyadashora
Is there an existing CVA6 bug for this?
-
I have searched the existing bug issues
Bug Description
It the Privilege Check section of CSR Logic
if (access_priv < csr_addr.csr_decode.priv_lvl) begin
if (v_q && csr_addr.csr_decode.priv_lvl == riscv::PRIV_LVL_HS)
virtual_privilege_violation = 1'b1;
else privilege_violation = 1'b1;
end
Consider the case the hart is in VU mode and trying to access the Supervisor CSR sstatus
, the logic would raise an illegal instruction exception (privilege_violation). The issue is that the sstatus
(or any other supervisor CSR) has privilege level (PRIV_LVL_S
). This is wrong functionality as spec says we should raise Virtual Instruction Exception.
The riscv-isa-manual says the following :
* in VU-mode, attempts to access an implemented non-high-half supervisor
CSR when the same access (read/write) would be allowed in HS-mode,
assuming `mstatus`.TVM=0;
The following functionality is found in spike RISCV ISA Simulator
if (priv < csr_priv) {
if (state->v && csr_priv <= PRV_HS)
throw trap_virtual_instruction(insn.bits());
throw trap_illegal_instruction(insn.bits());
}
Note the condition csr_priv <= PRV_HS
Possible solution: Modifying the condition in question to below would solve the above mentioned bug
if (access_priv < csr_addr.csr_decode.priv_lvl) begin
if (v_q && csr_addr.csr_decode.priv_lvl <= riscv::PRIV_LVL_HS)
virtual_privilege_violation = 1'b1;
else privilege_violation = 1'b1;
end