target/riscv: fix exception index on instruction access fault
authorEmmanuel Blot <emmanuel.blot@sifive.com>
Fri, 16 Apr 2021 14:17:11 +0000 (16:17 +0200)
committerAlistair Francis <alistair.francis@wdc.com>
Tue, 11 May 2021 10:02:07 +0000 (20:02 +1000)
When no MMU is used and the guest code attempts to fetch an instruction
from an invalid memory location, the exception index defaults to a data
load access fault, rather an instruction access fault.

Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: FB9EA197-B018-4879-AB0F-922C2047A08B@sifive.com
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
target/riscv/cpu_helper.c

index 659ca8a1739689bfafb780868ce5664c9e332dc4..1018c0036d092ec8261767b2f3a92967abae37a8 100644 (file)
@@ -694,8 +694,10 @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
 
     if (access_type == MMU_DATA_STORE) {
         cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
-    } else {
+    } else if (access_type == MMU_DATA_LOAD) {
         cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT;
+    } else {
+        cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT;
     }
 
     env->badaddr = addr;