All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Turner <mattst88@gmail.com>
To: qemu-devel@nongnu.org
Cc: Helge Deller <deller@gmx.de>, Laurent Vivier <laurent@vivier.eu>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH 1/3] target/i386: split the FNINIT out of do_fsave()
Date: Wed,  9 Sep 2026 21:34:40 -0400	[thread overview]
Message-ID: <20260910013442.1517793-2-mattst88@gmail.com> (raw)
In-Reply-To: <20260910013442.1517793-1-mattst88@gmail.com>

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 <mattst88@gmail.com>
---
 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



  reply	other threads:[~2026-09-10  1:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  1:34 [PATCH 0/3] linux-user: write the x86 floating-point registers to a core dump Matt Turner
2026-09-10  1:34 ` Matt Turner [this message]
2026-09-10  1:34 ` [PATCH 2/3] linux-user/i386: write the " Matt Turner
2026-09-10  1:34 ` [PATCH 3/3] linux-user/x86_64: " Matt Turner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260910013442.1517793-2-mattst88@gmail.com \
    --to=mattst88@gmail.com \
    --cc=deller@gmx.de \
    --cc=laurent@vivier.eu \
    --cc=pbonzini@redhat.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.