Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org
Cc: "George, Jini Susan" <JiniSusan.George@amd.com>,
	Aleksandar Paunovic <aleksandar.paunovic@intel.com>
Subject: [PATCH v3 11/13] gdbserver: Refactor the legacy region within the xsave struct
Date: Tue,  3 May 2022 14:05:13 -0700	[thread overview]
Message-ID: <20220503210515.30739-12-jhb@FreeBSD.org> (raw)
In-Reply-To: <20220503210515.30739-1-jhb@FreeBSD.org>

From: Aleksandar Paunovic <aleksandar.paunovic@intel.com>

Legacy fields of the XSAVE area are already defined within fx_save
struct.  Reuse this struct to remove code duplication.

The two changed functions are called within all tests which run
gdbserver.

gdbserver/ChangeLog:
2021-03-11  Aleksandar Paunovic  <aleksandar.paunovic@intel.com>

	* i387-fp.cc (struct i387_xsave): Remove code duplication.
        (i387_cache_to_xsave): Refactoring.
        (i387_xsave_to_cache): Refactoring.

Signed-off-by: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
---
 gdbserver/i387-fp.cc | 110 ++++++++++++++++++-------------------------
 1 file changed, 45 insertions(+), 65 deletions(-)

diff --git a/gdbserver/i387-fp.cc b/gdbserver/i387-fp.cc
index f419e74d608..309c3cc42db 100644
--- a/gdbserver/i387-fp.cc
+++ b/gdbserver/i387-fp.cc
@@ -82,27 +82,7 @@ struct i387_fxsave {
 };
 
 struct i387_xsave {
-  /* All these are only sixteen bits, plus padding, except for fop (which
-     is only eleven bits), and fooff / fioff (which are 32 bits each).  */
-  unsigned short fctrl;
-  unsigned short fstat;
-  unsigned short ftag;
-  unsigned short fop;
-  unsigned int fioff;
-  unsigned short fiseg;
-  unsigned short pad1;
-  unsigned int fooff;
-  unsigned short foseg;
-  unsigned short pad12;
-
-  unsigned int mxcsr;
-  unsigned int mxcsr_mask;
-
-  /* Space for eight 80-bit FP values in 128-bit spaces.  */
-  unsigned char st_space[128];
-
-  /* Space for eight 128-bit XMM values, or 16 on x86-64.  */
-  unsigned char xmm_space[256];
+  struct i387_fxsave fx;
 
   unsigned char reserved1[48];
 
@@ -286,28 +266,28 @@ i387_cache_to_xsave (struct regcache *regcache, void *buf)
       if ((clear_bv & X86_XSTATE_X87))
 	{
 	  for (i = 0; i < 8; i++)
-	    memset (((char *) &fp->st_space[0]) + i * 16, 0, 10);
+	    memset (((char *) &fp->fx.st_space[0]) + i * 16, 0, 10);
 
-	  fp->fioff = 0;
-	  fp->fooff = 0;
-	  fp->fctrl = I387_FCTRL_INIT_VAL;
-	  fp->fstat = 0;
-	  fp->ftag = 0;
-	  fp->fiseg = 0;
-	  fp->foseg = 0;
-	  fp->fop = 0;
+	  fp->fx.fioff = 0;
+	  fp->fx.fooff = 0;
+	  fp->fx.fctrl = I387_FCTRL_INIT_VAL;
+	  fp->fx.fstat = 0;
+	  fp->fx.ftag = 0;
+	  fp->fx.fiseg = 0;
+	  fp->fx.foseg = 0;
+	  fp->fx.fop = 0;
 	}
 
       if ((clear_bv & X86_XSTATE_SSE))
 	for (i = 0; i < num_xmm_registers; i++)
-	  memset (((char *) &fp->xmm_space[0]) + i * 16, 0, 16);
+	  memset (((char *) &fp->fx.xmm_space[0]) + i * 16, 0, 16);
 
       if ((clear_bv & X86_XSTATE_AVX))
 	for (i = 0; i < num_xmm_registers; i++)
 	  memset (((char *) &fp->ymmh_space[0]) + i * 16, 0, 16);
 
       if ((clear_bv & X86_XSTATE_SSE) && (clear_bv & X86_XSTATE_AVX))
-	memset (((char *) &fp->mxcsr), 0, 4);
+	memset (((char *) &fp->fx.mxcsr), 0, 4);
 
       if ((clear_bv & X86_XSTATE_BNDREGS))
 	for (i = 0; i < num_mpx_bnd_registers; i++)
@@ -348,7 +328,7 @@ i387_cache_to_xsave (struct regcache *regcache, void *buf)
       for (i = 0; i < 8; i++)
 	{
 	  collect_register (regcache, i + st0_regnum, raw);
-	  p = ((char *) &fp->st_space[0]) + i * 16;
+	  p = ((char *) &fp->fx.st_space[0]) + i * 16;
 	  if (memcmp (raw, p, 10))
 	    {
 	      xstate_bv |= X86_XSTATE_X87;
@@ -365,7 +345,7 @@ i387_cache_to_xsave (struct regcache *regcache, void *buf)
       for (i = 0; i < num_xmm_registers; i++) 
 	{
 	  collect_register (regcache, i + xmm0_regnum, raw);
-	  p = ((char *) &fp->xmm_space[0]) + i * 16;
+	  p = ((char *) &fp->fx.xmm_space[0]) + i * 16;
 	  if (memcmp (raw, p, 16))
 	    {
 	      xstate_bv |= X86_XSTATE_SSE;
@@ -536,53 +516,53 @@ i387_cache_to_xsave (struct regcache *regcache, void *buf)
   if ((x86_xcr0 & X86_XSTATE_SSE) || (x86_xcr0 & X86_XSTATE_AVX))
     {
       collect_register_by_name (regcache, "mxcsr", raw);
-      if (memcmp (raw, &fp->mxcsr, 4) != 0)
+      if (memcmp (raw, &fp->fx.mxcsr, 4) != 0)
 	{
 	  if (((fp->xstate_bv | xstate_bv)
 	       & (X86_XSTATE_SSE | X86_XSTATE_AVX)) == 0)
 	    xstate_bv |= X86_XSTATE_SSE;
-	  memcpy (&fp->mxcsr, raw, 4);
+	  memcpy (&fp->fx.mxcsr, raw, 4);
 	}
     }
 
   if (x86_xcr0 & X86_XSTATE_X87)
     {
       collect_register_by_name (regcache, "fioff", raw);
-      if (memcmp (raw, &fp->fioff, 4) != 0)
+      if (memcmp (raw, &fp->fx.fioff, 4) != 0)
 	{
 	  xstate_bv |= X86_XSTATE_X87;
-	  memcpy (&fp->fioff, raw, 4);
+	  memcpy (&fp->fx.fioff, raw, 4);
 	}
 
       collect_register_by_name (regcache, "fooff", raw);
-      if (memcmp (raw, &fp->fooff, 4) != 0)
+      if (memcmp (raw, &fp->fx.fooff, 4) != 0)
 	{
 	  xstate_bv |= X86_XSTATE_X87;
-	  memcpy (&fp->fooff, raw, 4);
+	  memcpy (&fp->fx.fooff, raw, 4);
 	}
 
       /* This one's 11 bits... */
       val2 = regcache_raw_get_unsigned_by_name (regcache, "fop");
-      val2 = (val2 & 0x7FF) | (fp->fop & 0xF800);
-      if (fp->fop != val2)
+      val2 = (val2 & 0x7FF) | (fp->fx.fop & 0xF800);
+      if (fp->fx.fop != val2)
 	{
 	  xstate_bv |= X86_XSTATE_X87;
-	  fp->fop = val2;
+	  fp->fx.fop = val2;
 	}
 
       /* Some registers are 16-bit.  */
       val = regcache_raw_get_unsigned_by_name (regcache, "fctrl");
-      if (fp->fctrl != val)
+      if (fp->fx.fctrl != val)
 	{
 	  xstate_bv |= X86_XSTATE_X87;
-	  fp->fctrl = val;
+	  fp->fx.fctrl = val;
 	}
 
       val = regcache_raw_get_unsigned_by_name (regcache, "fstat");
-      if (fp->fstat != val)
+      if (fp->fx.fstat != val)
 	{
 	  xstate_bv |= X86_XSTATE_X87;
-	  fp->fstat = val;
+	  fp->fx.fstat = val;
 	}
 
       /* Convert to the simplifed tag form stored in fxsave data.  */
@@ -595,24 +575,24 @@ i387_cache_to_xsave (struct regcache *regcache, void *buf)
 	  if (tag != 3)
 	    val2 |= (1 << i);
 	}
-      if (fp->ftag != val2)
+      if (fp->fx.ftag != val2)
 	{
 	  xstate_bv |= X86_XSTATE_X87;
-	  fp->ftag = val2;
+	  fp->fx.ftag = val2;
 	}
 
       val = regcache_raw_get_unsigned_by_name (regcache, "fiseg");
-      if (fp->fiseg != val)
+      if (fp->fx.fiseg != val)
 	{
 	  xstate_bv |= X86_XSTATE_X87;
-	  fp->fiseg = val;
+	  fp->fx.fiseg = val;
 	}
 
       val = regcache_raw_get_unsigned_by_name (regcache, "foseg");
-      if (fp->foseg != val)
+      if (fp->fx.foseg != val)
 	{
 	  xstate_bv |= X86_XSTATE_X87;
-	  fp->foseg = val;
+	  fp->fx.foseg = val;
 	}
     }
 
@@ -757,7 +737,7 @@ i387_xsave_to_cache (struct regcache *regcache, const void *buf)
 	}
       else
 	{
-	  p = (gdb_byte *) &fp->st_space[0];
+	  p = (gdb_byte *) &fp->fx.st_space[0];
 	  for (i = 0; i < 8; i++)
 	    supply_register (regcache, i + st0_regnum, p + i * 16);
 	}
@@ -774,7 +754,7 @@ i387_xsave_to_cache (struct regcache *regcache, const void *buf)
 	}
       else
 	{
-	  p = (gdb_byte *) &fp->xmm_space[0];
+	  p = (gdb_byte *) &fp->fx.xmm_space[0];
 	  for (i = 0; i < num_xmm_registers; i++)
 	    supply_register (regcache, i + xmm0_regnum, p + i * 16);
 	}
@@ -924,7 +904,7 @@ i387_xsave_to_cache (struct regcache *regcache, const void *buf)
       supply_register_by_name (regcache, "mxcsr", &default_mxcsr);
     }
   else
-    supply_register_by_name (regcache, "mxcsr", &fp->mxcsr);
+    supply_register_by_name (regcache, "mxcsr", &fp->fx.mxcsr);
 
   if ((clear_bv & X86_XSTATE_X87) != 0)
     {
@@ -945,23 +925,23 @@ i387_xsave_to_cache (struct regcache *regcache, const void *buf)
     }
   else
     {
-      supply_register_by_name (regcache, "fioff", &fp->fioff);
-      supply_register_by_name (regcache, "fooff", &fp->fooff);
+      supply_register_by_name (regcache, "fioff", &fp->fx.fioff);
+      supply_register_by_name (regcache, "fooff", &fp->fx.fooff);
 
       /* Some registers are 16-bit.  */
-      val = fp->fctrl & 0xFFFF;
+      val = fp->fx.fctrl & 0xFFFF;
       supply_register_by_name (regcache, "fctrl", &val);
 
-      val = fp->fstat & 0xFFFF;
+      val = fp->fx.fstat & 0xFFFF;
       supply_register_by_name (regcache, "fstat", &val);
 
       /* Generate the form of ftag data that GDB expects.  */
-      top = (fp->fstat >> 11) & 0x7;
+      top = (fp->fx.fstat >> 11) & 0x7;
       val = 0;
       for (i = 7; i >= 0; i--)
 	{
 	  int tag;
-	  if (fp->ftag & (1 << i))
+	  if (fp->fx.ftag & (1 << i))
 	    tag = i387_ftag (fxp, (i + 8 - top) % 8);
 	  else
 	    tag = 3;
@@ -969,13 +949,13 @@ i387_xsave_to_cache (struct regcache *regcache, const void *buf)
 	}
       supply_register_by_name (regcache, "ftag", &val);
 
-      val = fp->fiseg & 0xFFFF;
+      val = fp->fx.fiseg & 0xFFFF;
       supply_register_by_name (regcache, "fiseg", &val);
 
-      val = fp->foseg & 0xFFFF;
+      val = fp->fx.foseg & 0xFFFF;
       supply_register_by_name (regcache, "foseg", &val);
 
-      val = (fp->fop) & 0x7FF;
+      val = (fp->fx.fop) & 0x7FF;
       supply_register_by_name (regcache, "fop", &val);
     }
 }
-- 
2.34.1


  parent reply	other threads:[~2022-05-03 21:09 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03 21:05 [PATCH v3 00/13] Handle variable XSAVE layouts John Baldwin
2022-05-03 21:05 ` [PATCH v3 01/13] x86: Add an x86_xsave_layout structure to handle " John Baldwin
2022-05-03 21:05 ` [PATCH v3 02/13] core: Support fetching TARGET_OBJECT_X86_XSAVE_LAYOUT from architectures John Baldwin
2022-05-03 21:05 ` [PATCH v3 03/13] nat/x86-cpuid.h: Add x86_cpuid_count wrapper around __get_cpuid_count John Baldwin
2022-05-03 21:05 ` [PATCH v3 04/13] x86 nat: Add helper functions to save the XSAVE layout for the host John Baldwin
2022-05-03 21:05 ` [PATCH v3 05/13] gdb: Update x86 FreeBSD architectures to support XSAVE layouts John Baldwin
2022-05-03 21:05 ` [PATCH v3 06/13] gdb: Support XSAVE layouts for the current host in the FreeBSD x86 targets John Baldwin
2022-05-03 21:05 ` [PATCH v3 07/13] gdb: Update x86 Linux architectures to support XSAVE layouts John Baldwin
2022-05-03 21:05 ` [PATCH v3 08/13] gdb: Support XSAVE layouts for the current host in the Linux x86 targets John Baldwin
2022-05-03 21:05 ` [PATCH v3 09/13] gdb: Use x86_xstate_layout to parse the XSAVE extended state area John Baldwin
2022-05-03 21:05 ` [PATCH v3 10/13] gdbserver: Add a function to set the XSAVE mask and size John Baldwin
2022-05-03 21:05 ` John Baldwin [this message]
2022-05-03 21:05 ` [PATCH v3 12/13] gdbserver: Read offsets of the XSAVE extended region via CPUID John Baldwin
2022-05-03 21:05 ` [PATCH v3 13/13] x86: Remove X86_XSTATE_SIZE and related constants John Baldwin
2022-05-10 10:48 ` [PATCH v3 00/13] Handle variable XSAVE layouts George, Jini Susan via Gdb-patches
2022-05-18 21:48   ` John Baldwin
2022-05-18 21:53 ` John Baldwin
2022-05-19 15:42   ` Willgerodt, Felix via Gdb-patches
2022-05-19 16:05     ` John Baldwin
2022-05-20 14:53       ` Willgerodt, Felix via Gdb-patches

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=20220503210515.30739-12-jhb@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=JiniSusan.George@amd.com \
    --cc=aleksandar.paunovic@intel.com \
    --cc=gdb-patches@sourceware.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox