- vdpa-dev: Fix initialisation order to restore VDUSE compatibility - tcg: Allow top bit of SIMD_DATA_BITS to be set in simd_desc() - migration: fix-possible-int-overflow - target/m68k: Map FPU exceptions to FPSR register - qemu-options: Fix CXL Fixed Memory Window interleave-granularity typo - hvf: arm: Fix encodings for ID_AA64PFR1_EL1 and debug System registers - hw/intc/arm_gic: Fix handling of NS view of GICC_APR<n> - qio: Inherit follow_coroutine_ctx across TLS - target/riscv: Fix the element agnostic function problem - accel/tcg: Fix typo causing tb->page_addr[1] to not be recorded - tcg/loongarch64: Fix tcg_out_movi vs some pcrel pointers - migration: Fix file migration with fdset - ui/vnc: don't return an empty SASL mechlist to the client - target/arm: Fix FJCVTZS vs flush-to-zero - hw/ppc/e500: Prefer QOM cast - sphinx/qapidoc: Fix to generate doc for explicit, unboxed arguments - hw/ppc/e500: Remove unused "irqs" parameter - hw/ppc/e500: Add missing device tree properties to i2c controller node - hw/i386/amd_iommu: Don't leak memory in amdvi_update_iotlb() - hw/arm/mps2-tz.c: fix RX/TX interrupts order - target/i386: csv: Add support to migrate the incoming context for CSV3 guest - target/i386: csv: Add support to migrate the outgoing context for CSV3 guest - target/i386: csv: Add support to migrate the incoming page for CSV3 guest - target/i386: csv: Add support to migrate the outgoing page for CSV3 guest - linux-headers: update kernel headers to include CSV3 migration cmds - vfio: Only map shared region for CSV3 virtual machine - vga: Force full update for CSV3 guest - target/i386: csv: Load initial image to private memory for CSV3 guest - target/i386: csv: Do not register/unregister guest secure memory for CSV3 guest - target/i386: cpu: Populate CPUID 0x8000_001F when CSV3 is active - target/i386: csv: Add command to load vmcb to CSV3 guest memory - target/i386: csv: Add command to load data to CSV3 guest memory - target/i386: csv: Add command to initialize CSV3 context - target/i386: csv: Add CSV3 context - next-kbd: convert to use qemu_input_handler_register() - qemu/bswap: Undefine CPU_CONVERT() once done - exec/memop: Remove unused memop_big_endian() helper - hw/nvme: fix handling of over-committed queues - 9pfs: fix crash on 'Treaddir' request - hw/misc/psp: Pin the hugepage memory specified by mem2 during use for psp - hw/misc: support tkm use mem2 memory - hw/i386: add mem2 option for qemu - kvm: add support for guest physical bits - target/i386: add guest-phys-bits cpu property Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com> (cherry picked from commit f45f35e88509a4ffa9f62332ee9601e9fe1f8d09)
219 lines
7.1 KiB
Diff
219 lines
7.1 KiB
Diff
From a8a621a06d54b987502d277f33021547d00fd133 Mon Sep 17 00:00:00 2001
|
|
From: Keith Packard <keithp@keithp.com>
|
|
Date: Wed, 2 Aug 2023 20:52:31 -0700
|
|
Subject: [PATCH] target/m68k: Map FPU exceptions to FPSR register
|
|
|
|
Add helpers for reading/writing the 68881 FPSR register so that
|
|
changes in floating point exception state can be seen by the
|
|
application.
|
|
|
|
Call these helpers in pre_load/post_load hooks to synchronize
|
|
exception state.
|
|
|
|
Signed-off-by: Keith Packard <keithp@keithp.com>
|
|
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
|
|
Message-Id: <20230803035231.429697-1-keithp@keithp.com>
|
|
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
|
|
(cherry picked from commit 5888357942da1fd5a50efb6e4a6af8b1a27a5af8)
|
|
Signed-off-by: zhujun2 <zhujun2_yewu@cmss.chinamobile.com>
|
|
---
|
|
target/m68k/cpu.c | 12 +++++--
|
|
target/m68k/cpu.h | 3 +-
|
|
target/m68k/fpu_helper.c | 72 ++++++++++++++++++++++++++++++++++++++++
|
|
target/m68k/helper.c | 4 +--
|
|
target/m68k/helper.h | 2 ++
|
|
target/m68k/translate.c | 4 +--
|
|
6 files changed, 90 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
|
|
index 11c7e0a790..d95deaafcd 100644
|
|
--- a/target/m68k/cpu.c
|
|
+++ b/target/m68k/cpu.c
|
|
@@ -396,12 +396,19 @@ static const VMStateDescription vmstate_freg = {
|
|
}
|
|
};
|
|
|
|
-static int fpu_post_load(void *opaque, int version)
|
|
+static int fpu_pre_save(void *opaque)
|
|
{
|
|
M68kCPU *s = opaque;
|
|
|
|
- cpu_m68k_restore_fp_status(&s->env);
|
|
+ s->env.fpsr = cpu_m68k_get_fpsr(&s->env);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int fpu_post_load(void *opaque, int version)
|
|
+{
|
|
+ M68kCPU *s = opaque;
|
|
|
|
+ cpu_m68k_set_fpsr(&s->env, s->env.fpsr);
|
|
return 0;
|
|
}
|
|
|
|
@@ -410,6 +417,7 @@ const VMStateDescription vmmstate_fpu = {
|
|
.version_id = 1,
|
|
.minimum_version_id = 1,
|
|
.needed = fpu_needed,
|
|
+ .pre_save = fpu_pre_save,
|
|
.post_load = fpu_post_load,
|
|
.fields = (VMStateField[]) {
|
|
VMSTATE_UINT32(env.fpcr, M68kCPU),
|
|
diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
|
|
index 6cfc696d2b..4d78da9d5f 100644
|
|
--- a/target/m68k/cpu.h
|
|
+++ b/target/m68k/cpu.h
|
|
@@ -199,7 +199,8 @@ void cpu_m68k_set_ccr(CPUM68KState *env, uint32_t);
|
|
void cpu_m68k_set_sr(CPUM68KState *env, uint32_t);
|
|
void cpu_m68k_restore_fp_status(CPUM68KState *env);
|
|
void cpu_m68k_set_fpcr(CPUM68KState *env, uint32_t val);
|
|
-
|
|
+uint32_t cpu_m68k_get_fpsr(CPUM68KState *env);
|
|
+void cpu_m68k_set_fpsr(CPUM68KState *env, uint32_t val);
|
|
|
|
/*
|
|
* Instead of computing the condition codes after each m68k instruction,
|
|
diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c
|
|
index ab120b5f59..8314791f50 100644
|
|
--- a/target/m68k/fpu_helper.c
|
|
+++ b/target/m68k/fpu_helper.c
|
|
@@ -164,6 +164,78 @@ void HELPER(set_fpcr)(CPUM68KState *env, uint32_t val)
|
|
cpu_m68k_set_fpcr(env, val);
|
|
}
|
|
|
|
+/* Convert host exception flags to cpu_m68k form. */
|
|
+static int cpu_m68k_exceptbits_from_host(int host_bits)
|
|
+{
|
|
+ int target_bits = 0;
|
|
+
|
|
+ if (host_bits & float_flag_invalid) {
|
|
+ target_bits |= 0x80;
|
|
+ }
|
|
+ if (host_bits & float_flag_overflow) {
|
|
+ target_bits |= 0x40;
|
|
+ }
|
|
+ if (host_bits & (float_flag_underflow | float_flag_output_denormal)) {
|
|
+ target_bits |= 0x20;
|
|
+ }
|
|
+ if (host_bits & float_flag_divbyzero) {
|
|
+ target_bits |= 0x10;
|
|
+ }
|
|
+ if (host_bits & float_flag_inexact) {
|
|
+ target_bits |= 0x08;
|
|
+ }
|
|
+ return target_bits;
|
|
+}
|
|
+
|
|
+/* Convert cpu_m68k exception flags to target form. */
|
|
+static int cpu_m68k_exceptbits_to_host(int target_bits)
|
|
+{
|
|
+ int host_bits = 0;
|
|
+
|
|
+ if (target_bits & 0x80) {
|
|
+ host_bits |= float_flag_invalid;
|
|
+ }
|
|
+ if (target_bits & 0x40) {
|
|
+ host_bits |= float_flag_overflow;
|
|
+ }
|
|
+ if (target_bits & 0x20) {
|
|
+ host_bits |= float_flag_underflow;
|
|
+ }
|
|
+ if (target_bits & 0x10) {
|
|
+ host_bits |= float_flag_divbyzero;
|
|
+ }
|
|
+ if (target_bits & 0x08) {
|
|
+ host_bits |= float_flag_inexact;
|
|
+ }
|
|
+ return host_bits;
|
|
+}
|
|
+
|
|
+uint32_t cpu_m68k_get_fpsr(CPUM68KState *env)
|
|
+{
|
|
+ int host_flags = get_float_exception_flags(&env->fp_status);
|
|
+ int target_flags = cpu_m68k_exceptbits_from_host(host_flags);
|
|
+ int except = (env->fpsr & ~(0xf8)) | target_flags;
|
|
+ return except;
|
|
+}
|
|
+
|
|
+uint32_t HELPER(get_fpsr)(CPUM68KState *env)
|
|
+{
|
|
+ return cpu_m68k_get_fpsr(env);
|
|
+}
|
|
+
|
|
+void cpu_m68k_set_fpsr(CPUM68KState *env, uint32_t val)
|
|
+{
|
|
+ env->fpsr = val;
|
|
+
|
|
+ int host_flags = cpu_m68k_exceptbits_to_host((int) env->fpsr);
|
|
+ set_float_exception_flags(host_flags, &env->fp_status);
|
|
+}
|
|
+
|
|
+void HELPER(set_fpsr)(CPUM68KState *env, uint32_t val)
|
|
+{
|
|
+ cpu_m68k_set_fpsr(env, val);
|
|
+}
|
|
+
|
|
#define PREC_BEGIN(prec) \
|
|
do { \
|
|
FloatX80RoundPrec old = \
|
|
diff --git a/target/m68k/helper.c b/target/m68k/helper.c
|
|
index 0a1544cd68..beab4b96bc 100644
|
|
--- a/target/m68k/helper.c
|
|
+++ b/target/m68k/helper.c
|
|
@@ -118,7 +118,7 @@ static int m68k_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, int n)
|
|
case 8: /* fpcontrol */
|
|
return gdb_get_reg32(mem_buf, env->fpcr);
|
|
case 9: /* fpstatus */
|
|
- return gdb_get_reg32(mem_buf, env->fpsr);
|
|
+ return gdb_get_reg32(mem_buf, cpu_m68k_get_fpsr(env));
|
|
case 10: /* fpiar, not implemented */
|
|
return gdb_get_reg32(mem_buf, 0);
|
|
}
|
|
@@ -137,7 +137,7 @@ static int m68k_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
|
|
cpu_m68k_set_fpcr(env, ldl_p(mem_buf));
|
|
return 4;
|
|
case 9: /* fpstatus */
|
|
- env->fpsr = ldl_p(mem_buf);
|
|
+ cpu_m68k_set_fpsr(env, ldl_p(mem_buf));
|
|
return 4;
|
|
case 10: /* fpiar, not implemented */
|
|
return 4;
|
|
diff --git a/target/m68k/helper.h b/target/m68k/helper.h
|
|
index 2bbe0dc032..95aa5e53bb 100644
|
|
--- a/target/m68k/helper.h
|
|
+++ b/target/m68k/helper.h
|
|
@@ -54,6 +54,8 @@ DEF_HELPER_4(fsdiv, void, env, fp, fp, fp)
|
|
DEF_HELPER_4(fddiv, void, env, fp, fp, fp)
|
|
DEF_HELPER_4(fsgldiv, void, env, fp, fp, fp)
|
|
DEF_HELPER_FLAGS_3(fcmp, TCG_CALL_NO_RWG, void, env, fp, fp)
|
|
+DEF_HELPER_2(set_fpsr, void, env, i32)
|
|
+DEF_HELPER_1(get_fpsr, i32, env)
|
|
DEF_HELPER_FLAGS_2(set_fpcr, TCG_CALL_NO_RWG, void, env, i32)
|
|
DEF_HELPER_FLAGS_2(ftst, TCG_CALL_NO_RWG, void, env, fp)
|
|
DEF_HELPER_3(fconst, void, env, fp, i32)
|
|
diff --git a/target/m68k/translate.c b/target/m68k/translate.c
|
|
index 4a0b0b2703..f8eeb70379 100644
|
|
--- a/target/m68k/translate.c
|
|
+++ b/target/m68k/translate.c
|
|
@@ -4686,7 +4686,7 @@ static void gen_load_fcr(DisasContext *s, TCGv res, int reg)
|
|
tcg_gen_movi_i32(res, 0);
|
|
break;
|
|
case M68K_FPSR:
|
|
- tcg_gen_ld_i32(res, tcg_env, offsetof(CPUM68KState, fpsr));
|
|
+ gen_helper_get_fpsr(res, tcg_env);
|
|
break;
|
|
case M68K_FPCR:
|
|
tcg_gen_ld_i32(res, tcg_env, offsetof(CPUM68KState, fpcr));
|
|
@@ -4700,7 +4700,7 @@ static void gen_store_fcr(DisasContext *s, TCGv val, int reg)
|
|
case M68K_FPIAR:
|
|
break;
|
|
case M68K_FPSR:
|
|
- tcg_gen_st_i32(val, tcg_env, offsetof(CPUM68KState, fpsr));
|
|
+ gen_helper_set_fpsr(tcg_env, val);
|
|
break;
|
|
case M68K_FPCR:
|
|
gen_helper_set_fpcr(tcg_env, val);
|
|
--
|
|
2.41.0.windows.1
|
|
|