target/m68k: Map FPU exceptions to FPSR register
PATCH 1/1 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.
--- target/m68k/cpu.c | 12 +++++++ target/m68k/cpu.h | 2 ++ target/m68k/fpu_helper.c | 72 ++++++++++++++++++++++++++++++++++++++++ target/m68k/helper.c | 4 +-- target/m68k/helper.h | 2 ++ target/m68k/translate.c | 4 +-- 6 files changed, 92 insertions(+), 4 deletions(-)
target/m68k/cpu.c +12 -0
@@ -404,12 +404,23 @@ static const VMStateDescription vmstate_freg = { } }; +static int fpu_pre_load (void *opaque) +{ +M68kCPU *s = opaque; + + 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_restore_fp_status (&s->env); +cpu_m68k_set_fpsr (&s->env, s->env.fpsr); +return 0 ; }
@@ -418,6 +429,7 @@ const VMStateDescription vmmstate_fpu = { .version_id = 1, .minimum_version_id = 1, .needed = fpu_needed, + .pre_load = fpu_pre_load, .post_load = fpu_post_load, .fields = (VMStateField []) {VMSTATE_UINT32 (env.fpcr, M68kCPU),
target/m68k/cpu.h +2 -0
@@ -173,6 +173,8 @@ struct ArchCPU {CPUM68KState env; }; +uint32_t cpu_m68k_get_fpsr (CPUM68KState *env); +void cpu_m68k_set_fpsr (CPUM68KState *env,uint32_t val);#ifndef CONFIG_USER_ONLY void m68k_cpu_do_interrupt (CPUState *cpu);
target/m68k/fpu_helper.c +72 -0
78 lines not on this page · raw message
target/m68k/helper.c +2 -2
@@ -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 ;
target/m68k/helper.h +2 -0
@@ -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)
target/m68k/translate.c +2 -2
@@ -4718,7 +4718,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, cpu_env, offsetof(CPUM68KState , fpsr)); +gen_helper_get_fpsr (res, cpu_env);break ;case M68K_FPCR :tcg_gen_ld_i32 (res, cpu_env, offsetof(CPUM68KState , fpcr));
@@ -4732,7 +4732,7 @@ static void gen_store_fcr(DisasContext *s, TCGv val, int reg)case M68K_FPIAR :break ;case M68K_FPSR : -tcg_gen_st_i32 (val, cpu_env, offsetof(CPUM68KState , fpsr)); +gen_helper_set_fpsr (cpu_env, val);break ;case M68K_FPCR :gen_helper_set_fpcr (cpu_env, val);
Signature · 1 line
2.40.1
Quoted 8 lines · Keith Packard via
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<[email protected]>
Quoted 8 lines
--- target/m68k/cpu.c | 12 +++++++ target/m68k/cpu.h | 2 ++ target/m68k/fpu_helper.c | 72 ++++++++++++++++++++++++++++++++++++++++ target/m68k/helper.c | 4 +-- target/m68k/helper.h | 2 ++ target/m68k/translate.c | 4 +-- 6 files changed, 92 insertions(+), 4 deletions(-)
r~
Richard Henderson
AppliedQuoted 8 lines · Keith Packard via
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<[email protected]>
Quoted 8 lines
--- target/m68k/cpu.c | 12 +++++++ target/m68k/cpu.h | 2 ++ target/m68k/fpu_helper.c | 72 ++++++++++++++++++++++++++++++++++++++++ target/m68k/helper.c | 4 +-- target/m68k/helper.h | 2 ++ target/m68k/translate.c | 4 +-- 6 files changed, 92 insertions(+), 4 deletions(-)
Queued to m68k-next.
r~