do_fsave() ends with an FNINIT, which is what the FSAVE instruction and the signal frame setup both want, but it makes the helper unusable for a caller that only wants to read the state out: recording the registers would destroy them.
Move the FNINIT into helper_fsave() and cpu_x86_fsave(), and expose the store alone as cpu_x86_fsave_noinit(). No functional change; the next patch uses the new entry point to write the x87 registers to a guest core dump. Signed-off-by: Matt Turner <[email protected]> --- target/i386/cpu.h | 2 ++ target/i386/tcg/fpu_helper.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git ./target/i386/cpu.h ./target/i386/cpu.h index 9ce8ca0038..2a543ee808 100644 --- ./target/i386/cpu.h +++ ./target/i386/cpu.h @@ -2717,6 +2717,8 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector, */ void cpu_x86_load_seg(CPUX86State *s, X86Seg seg_reg, int selector); void cpu_x86_fsave(CPUX86State *s, void *host, size_t len); +/* As cpu_x86_fsave(), but leaving the FPU state undisturbed. */ +void cpu_x86_fsave_noinit(CPUX86State *s, void *host, size_t len); void cpu_x86_frstor(CPUX86State *s, void *host, size_t len); void cpu_x86_fxsave(CPUX86State *s, void *host, size_t len); void cpu_x86_fxrstor(CPUX86State *s, void *host, size_t len); diff --git ./target/i386/tcg/fpu_helper.c ./target/i386/tcg/fpu_helper.c index b812125efa..f7cf4220ff 100644 --- ./target/i386/tcg/fpu_helper.c +++ ./target/i386/tcg/fpu_helper.c @@ -2536,6 +2536,10 @@ void helper_fldenv(CPUX86State *env, target_ulong ptr, int data32) do_fldenv(&ac, ptr, data32); } +/* + * Store the environment and the register stack, as FSAVE does, but + * without the FNINIT that FSAVE performs afterward. + */ static void do_fsave(X86Access *ac, target_ulong ptr, int data32) { CPUX86State *env = ac->env; @@ -2548,8 +2552,6 @@ static void do_fsave(X86Access *ac, target_ulong ptr, int data32) do_fstt(ac, ptr, tmp); ptr += 10; } - - do_fninit(env); } void helper_fsave(CPUX86State *env, target_ulong ptr, int data32) @@ -2559,6 +2561,7 @@ void helper_fsave(CPUX86State *env, target_ulong ptr, int data32) access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, GETPC()); do_fsave(&ac, ptr, data32); + do_fninit(env); } static void do_frstor(X86Access *ac, target_ulong ptr, int data32) @@ -3085,6 +3088,12 @@ void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) #if defined(CONFIG_USER_ONLY) void cpu_x86_fsave(CPUX86State *env, void *host, size_t len) +{ + cpu_x86_fsave_noinit(env, host, len); + do_fninit(env); +} + +void cpu_x86_fsave_noinit(CPUX86State *env, void *host, size_t len) { X86Access ac = { .haddr1 = host, -- 2.54.0
