[v6,12/15] gdbserver: Refactor the legacy region within the xsave struct

Message ID 20230714155151.21723-13-jhb@FreeBSD.org
State New
Headers
Series Handle variable XSAVE layouts |

Commit Message

John Baldwin July 14, 2023, 3:51 p.m. UTC
  From: Aleksandar Paunovic <aleksandar.paunovic@intel.com>

Legacy fields of the XSAVE area are already defined within fx_save
struct.  Use class inheritance to remove code duplication.

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

Signed-off-by: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
Co-authored-by: John Baldwin <jhb@FreeBSD.org>
---
 gdbserver/i387-fp.cc | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)
  

Comments

Simon Marchi Aug. 28, 2023, 4:50 p.m. UTC | #1
On 7/14/23 11:51, John Baldwin wrote:
> From: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
> 
> Legacy fields of the XSAVE area are already defined within fx_save
> struct.  Use class inheritance to remove code duplication.
> 
> The two changed functions are called within all tests which run
> gdbserver.
> 
> Signed-off-by: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
> Co-authored-by: John Baldwin <jhb@FreeBSD.org>
> ---
>  gdbserver/i387-fp.cc | 27 ++-------------------------
>  1 file changed, 2 insertions(+), 25 deletions(-)
> 
> diff --git a/gdbserver/i387-fp.cc b/gdbserver/i387-fp.cc
> index b8d7a912f26..a122e2d860b 100644
> --- a/gdbserver/i387-fp.cc
> +++ b/gdbserver/i387-fp.cc
> @@ -81,29 +81,7 @@ struct i387_fxsave {
>    unsigned char xmm_space[256];
>  };
>  
> -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_xsave : public i387_fxsave {


The { should go on the next line... can you fix all the structs in this
file with an obvious patch on top of the series?

Otherwise:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  
John Baldwin Aug. 28, 2023, 5:32 p.m. UTC | #2
On 8/28/23 9:50 AM, Simon Marchi wrote:
> On 7/14/23 11:51, John Baldwin wrote:
>> From: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
>>
>> Legacy fields of the XSAVE area are already defined within fx_save
>> struct.  Use class inheritance to remove code duplication.
>>
>> The two changed functions are called within all tests which run
>> gdbserver.
>>
>> Signed-off-by: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
>> Co-authored-by: John Baldwin <jhb@FreeBSD.org>
>> ---
>>   gdbserver/i387-fp.cc | 27 ++-------------------------
>>   1 file changed, 2 insertions(+), 25 deletions(-)
>>
>> diff --git a/gdbserver/i387-fp.cc b/gdbserver/i387-fp.cc
>> index b8d7a912f26..a122e2d860b 100644
>> --- a/gdbserver/i387-fp.cc
>> +++ b/gdbserver/i387-fp.cc
>> @@ -81,29 +81,7 @@ struct i387_fxsave {
>>     unsigned char xmm_space[256];
>>   };
>>   
>> -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_xsave : public i387_fxsave {
> 
> 
> The { should go on the next line... can you fix all the structs in this
> file with an obvious patch on top of the series?

Will do, thanks!
  

Patch

diff --git a/gdbserver/i387-fp.cc b/gdbserver/i387-fp.cc
index b8d7a912f26..a122e2d860b 100644
--- a/gdbserver/i387-fp.cc
+++ b/gdbserver/i387-fp.cc
@@ -81,29 +81,7 @@  struct i387_fxsave {
   unsigned char xmm_space[256];
 };
 
-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_xsave : public i387_fxsave {
   unsigned char reserved1[48];
 
   /* The extended control register 0 (the XFEATURE_ENABLED_MASK
@@ -725,7 +703,6 @@  void
 i387_xsave_to_cache (struct regcache *regcache, const void *buf)
 {
   struct i387_xsave *fp = (struct i387_xsave *) buf;
-  struct i387_fxsave *fxp = (struct i387_fxsave *) buf;
   bool amd64 = register_size (regcache->tdesc, 0) == 8;
   int i, top;
   unsigned long val;
@@ -962,7 +939,7 @@  i387_xsave_to_cache (struct regcache *regcache, const void *buf)
 	{
 	  int tag;
 	  if (fp->ftag & (1 << i))
-	    tag = i387_ftag (fxp, (i + 8 - top) % 8);
+	    tag = i387_ftag (fp, (i + 8 - top) % 8);
 	  else
 	    tag = 3;
 	  val |= tag << (2 * i);