render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0004-target-riscv-Fix-tb-flags-FS-status.patch

b98348
From: ShihPo Hung <shihpo.hung@sifive.com>
b98348
Date: Tue, 14 Jan 2020 22:17:31 -0800
1d442b
Subject: [PATCH] target/riscv: Fix tb->flags FS status
b98348
b98348
It was found that running libquantum on riscv-linux qemu produced an
b98348
incorrect result. After investigation, FP registers are not saved
b98348
during context switch due to incorrect mstatus.FS.
b98348
b98348
In current implementation tb->flags merges all non-disabled state to
b98348
dirty. This means the code in mark_fs_dirty in translate.c that
b98348
handles initial and clean states is unreachable.
b98348
b98348
This patch fixes it and is successfully tested with:
b98348
  libquantum
b98348
b98348
Thanks to Richard for pointing out the actual bug.
b98348
b98348
v3: remove the redundant condition
b98348
v2: root cause FS problem
b98348
b98348
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
b98348
Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
b98348
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
b98348
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
b98348
---
b98348
 target/riscv/cpu.h | 5 +----
b98348
 1 file changed, 1 insertion(+), 4 deletions(-)
b98348
b98348
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
b98348
index e59343e13c..de0a8d893a 100644
b98348
--- a/target/riscv/cpu.h
b98348
+++ b/target/riscv/cpu.h
b98348
@@ -293,10 +293,7 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
b98348
 #ifdef CONFIG_USER_ONLY
b98348
     *flags = TB_FLAGS_MSTATUS_FS;
b98348
 #else
b98348
-    *flags = cpu_mmu_index(env, 0);
b98348
-    if (riscv_cpu_fp_enabled(env)) {
b98348
-        *flags |= TB_FLAGS_MSTATUS_FS;
b98348
-    }
b98348
+    *flags = cpu_mmu_index(env, 0) | (env->mstatus & MSTATUS_FS);
b98348
 #endif
b98348
 }
b98348