From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org
Cc: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
Subject: [PATCH v4 11/13] gdbserver: Refactor the legacy region within the xsave struct
Date: Fri, 17 Mar 2023 18:09:03 -0700 [thread overview]
Message-ID: <20230318010905.14294-12-jhb@FreeBSD.org> (raw)
In-Reply-To: <20230318010905.14294-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.
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 9bb9f497a01..eaff47be3d8 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.39.1
next prev parent reply other threads:[~2023-03-18 1:09 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-18 1:08 [PATCH v4 00/13] Handle variable XSAVE layouts John Baldwin
2023-03-18 1:08 ` [PATCH v4 01/13] x86: Add an x86_xsave_layout structure to handle " John Baldwin
2023-03-28 11:35 ` George, Jini Susan
2023-04-10 19:28 ` John Baldwin
2023-04-06 19:09 ` Simon Marchi
2023-04-10 20:03 ` John Baldwin
2023-04-11 1:19 ` Simon Marchi
2023-04-11 14:23 ` Pedro Alves
2023-04-11 16:02 ` John Baldwin
2023-03-18 1:08 ` [PATCH v4 02/13] core: Support fetching TARGET_OBJECT_X86_XSAVE_LAYOUT from architectures John Baldwin
2023-04-06 19:28 ` Simon Marchi
2023-04-10 20:42 ` John Baldwin
2023-04-11 1:49 ` Simon Marchi
2023-04-11 16:06 ` John Baldwin
2023-04-11 16:21 ` Simon Marchi
2023-04-11 23:59 ` John Baldwin
2023-03-18 1:08 ` [PATCH v4 03/13] nat/x86-cpuid.h: Add x86_cpuid_count wrapper around __get_cpuid_count John Baldwin
2023-04-06 19:33 ` Simon Marchi
2023-04-10 20:49 ` John Baldwin
2023-04-11 1:49 ` Simon Marchi
2023-03-18 1:08 ` [PATCH v4 04/13] x86 nat: Add helper functions to save the XSAVE layout for the host John Baldwin
2023-04-06 19:40 ` Simon Marchi
2023-04-10 21:00 ` John Baldwin
2023-04-11 1:51 ` Simon Marchi
2023-03-18 1:08 ` [PATCH v4 05/13] gdb: Update x86 FreeBSD architectures to support XSAVE layouts John Baldwin
2023-04-06 19:54 ` Simon Marchi
2023-04-10 21:02 ` John Baldwin
2023-04-11 1:55 ` Simon Marchi
2023-03-18 1:08 ` [PATCH v4 06/13] gdb: Support XSAVE layouts for the current host in the FreeBSD x86 targets John Baldwin
2023-04-06 20:18 ` Simon Marchi
2023-04-10 21:27 ` John Baldwin
2023-04-11 2:23 ` Simon Marchi
2023-04-11 16:19 ` John Baldwin
2023-04-11 16:46 ` Simon Marchi
2023-04-11 21:37 ` John Baldwin
2023-04-11 22:35 ` John Baldwin
2023-04-12 14:35 ` Simon Marchi
2023-03-18 1:08 ` [PATCH v4 07/13] gdb: Update x86 Linux architectures to support XSAVE layouts John Baldwin
2023-04-07 1:43 ` Simon Marchi
2023-04-10 21:29 ` John Baldwin
2023-03-18 1:09 ` [PATCH v4 08/13] gdb: Support XSAVE layouts for the current host in the Linux x86 targets John Baldwin
2023-04-07 1:54 ` Simon Marchi
2023-03-18 1:09 ` [PATCH v4 09/13] gdb: Use x86_xstate_layout to parse the XSAVE extended state area John Baldwin
2023-04-07 2:13 ` Simon Marchi
2023-04-10 21:40 ` John Baldwin
2023-03-18 1:09 ` [PATCH v4 10/13] gdbserver: Add a function to set the XSAVE mask and size John Baldwin
2023-04-12 15:08 ` Simon Marchi
2023-04-27 17:24 ` John Baldwin
2023-03-18 1:09 ` John Baldwin [this message]
2023-04-12 18:34 ` [PATCH v4 11/13] gdbserver: Refactor the legacy region within the xsave struct Simon Marchi
2023-04-27 19:51 ` John Baldwin
2023-03-18 1:09 ` [PATCH v4 12/13] gdbserver: Read offsets of the XSAVE extended region via CPUID John Baldwin
2023-04-11 14:46 ` Pedro Alves
2023-04-11 16:25 ` John Baldwin
2023-04-12 19:11 ` Simon Marchi
2023-04-12 21:07 ` John Baldwin
2023-04-13 15:07 ` Simon Marchi
2023-03-18 1:09 ` [PATCH v4 13/13] x86: Remove X86_XSTATE_SIZE and related constants John Baldwin
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=20230318010905.14294-12-jhb@FreeBSD.org \
--to=jhb@freebsd.org \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).