target/riscv: Correctly implement TSR trap
authorAlistair Francis <alistair.francis@wdc.com>
Tue, 21 Jan 2020 05:36:57 +0000 (21:36 -0800)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Tue, 17 Mar 2020 00:03:13 +0000 (17:03 -0700)
As reported in: https://bugs.launchpad.net/qemu/+bug/1851939 we weren't
correctly handling illegal instructions based on the value of MSTATUS_TSR
and the current privledge level.

This patch fixes the issue raised in the bug by raising an illegal
instruction if TSR is set and we are in S-Mode.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Jonathan Behrens <jonathan@fintelia.io
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
target/riscv/op_helper.c

index 8736f689c26131b932930f422ea2ea63e4b25aed..c6412f680c76e536e4e40f262a1a78ac70ba2311 100644 (file)
@@ -85,7 +85,7 @@ target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb)
     }
 
     if (env->priv_ver >= PRIV_VERSION_1_10_0 &&
-        get_field(env->mstatus, MSTATUS_TSR)) {
+        get_field(env->mstatus, MSTATUS_TSR) && !(env->priv >= PRV_M)) {
         riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
     }