public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH V2 1/1] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
@ 2017-01-05 15:53 Walfred Tedeschi
  2017-01-09 20:35 ` Luis Machado
  2017-01-19 19:45 ` Pedro Alves
  0 siblings, 2 replies; 5+ messages in thread
From: Walfred Tedeschi @ 2017-01-05 15:53 UTC (permalink / raw)
  To: palves, brobecker; +Cc: gdb-patches, Walfred Tedeschi

This patch allows examination of the registers FS_BASE and GS_BASE
for Linux Systems running on 64bit. Tests for simple read and write
of the new registers is also added with this patch.

Tests were performed on:
x86_64 RHEL 5.3     - For the older ptrace calls.
x86_64 Ubuntu 16.10 - For the new ptrace calls.


Changes from Richard's version:
* Added support for remote.
* Added test cases.


Change requested by John Baldwin, as reported at:

* Moved initialization of fs_base and gs_base from amd64-linux-tdep.c
to amd64-tdep.c

Changes after Pedro's comments:
* Moved usage of "HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE" to native
files.
* Double checked indentation on "gdb/features/Makefile".
* Removed hard coded register number from "64bit-segments.xml"
* Register size was kept as same as orig_rax.
* Removed spurious function from the test sample.
* Test is using prepare_for_testing.

Additional comment on register ordering:
orig_rax is the last register added there is a special macro that defines
it in this way. On gdbserver side it is defined in the middle of
the registers and stays there always for compatibility.

I have added the two new registers just after the orig_rax.  This causes
that they will be in the gdbserver side just after orig_rax and in gdb

I still can add then where I would prefer, the definition is
done by the macros defining AMD64_FSBASE_REGNUM. In this sense they have
been added just before the orig_rax.

This decision was taken based on the fact that we would like to add
hardware registers as usual before the orig_rax, and with this addition
also before the fs_base and gs_base.


2017-01-05  Walfred Tedeschi  <walfred.tedeschi@intel.com>
	    Richard Henderson  <rth@redhat.com>

gdb/ChangeLog:

	* amd64-linux-nat.c (PTRACE_ARCH_PRCTL): New define.
	(amd64_linux_fetch_inferior_registers): Add case to fetch FS_BASE
	GS_BASE for older kernels.
	(amd64_linux_store_inferior_registers): Add case to store FS_BASE
	GS_BASE for older kernels.
	* amd64-linux-tdep.c (amd64_linux_gregset_reg_offset): Add FS_BASE
	and GS_BASE to the offset table.
	(amd64_linux_register_reggroup_p): Add FS_BASE and GS_BASE to the
	system register group.
	* amd64-linux-tdep.h (AMD64_LINUX_ORIG_RAX_REGNUM): Set the value
	to AMD64_NUM_REGS.
	* amd64-nat.c (amd64_native_gregset_reg_offset): Adds valid_regnum
	to test validit of the register.  Implements case for older
	kernels.
	* amd64-tdep.c (amd64_init_abi): Add segment registers for the
	amd64 ABI.
	* amd64-tdep.h (amd64_regnum): Add AMD64_FSBASE_REGNUM and
	AMD64_GSBASE_REGNUM.
	(AMD64_NUM_REGS): Set to AMD64_GSBASE_REGNUM + 1.
	* features/Makefile (amd64-linux.dat, amd64-avx-linux.dat)
	(amd64-mpx-linux.dat, amd64-avx512-linux.dat, x32-linux.dat)
	(x32-avx-linux.dat, x32-avx512-linux.dat): Add
	i386/64bit-segments.xml in those rules.
	* features/i386/64bit-segments.xml: New file.
	* features/i386/amd64-avx-mpx-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx512-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-mpx-linux.xml: Add 64bit-segments.xml.
	* features/i386/x32-avx512-linux.xml: Add 64bit-segments.xml.
	* features/i386/x32-avx-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx-linux.c: Regenerated.
	* features/i386/amd64-avx-mpx-linux.c: Regenerated.
	* features/i386/amd64-avx-mpx.c: Regenerated.
	* features/i386/amd64-avx512-linux.c: Regenerated.
	* features/i386/amd64-linux.c: Regenerated.
	* features/i386/amd64-mpx-linux.c: Regenerated.
	* features/i386/i386-avx-mpx-linux.c: Regenerated.
	* features/i386/i386-avx-mpx.c: Regenerated.
	* features/i386/x32-avx-linux.c: Regenerated.
	* features/i386/x32-avx512-linux.c: Regenerated.
	* regformats/i386/amd64-avx-linux.dat: Regenerated.
	* regformats/i386/amd64-avx-mpx-linux.dat: Regenerated.
	* regformats/i386/amd64-avx512-linux.dat: Regenerated.
	* regformats/i386/amd64-linux.dat: Regenerated.
	* regformats/i386/amd64-mpx-linux.dat: Regenerated.
	* regformats/i386/x32-avx-linux.dat: Regenerated.
	* regformats/i386/x32-avx512-linux.dat: Regenerated.
	* regformats/i386/x32-linux.dat: Regenerated.

gdb/doc/ChangeLog:

	* gdb.texinfo (i386 Features): Add system segment registers
	as feature.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_64_regmap): Add fs_base and gs_base
	to the register table.
	(x86_fill_gregset): Add support for old kernels for the
	fs_base and gs_base system registers.
	(x86_store_gregset): Likewise.
	* configure.srv (srv_i386_64bit_xmlfiles): Add 64bit-segments.xml.

gdb/testsuite/ChangeLog:

	* gdb.arch/amd64-gs_base.c: New file.
	* gdb.arch/amd64-gs_base.exp: New file.

---
 gdb/amd64-linux-nat.c                       |  53 ++++++++
 gdb/amd64-linux-tdep.c                      |   7 +-
 gdb/amd64-linux-tdep.h                      |   2 +-
 gdb/amd64-nat.c                             |  19 ++-
 gdb/amd64-tdep.c                            |  13 ++
 gdb/amd64-tdep.h                            |   6 +-
 gdb/doc/gdb.texinfo                         |   3 +
 gdb/features/Makefile                       |  17 +--
 gdb/features/i386/64bit-segments.xml        |  12 ++
 gdb/features/i386/amd64-avx-linux.c         |  36 +++---
 gdb/features/i386/amd64-avx-linux.xml       |   1 +
 gdb/features/i386/amd64-avx-mpx-linux.c     |  48 +++----
 gdb/features/i386/amd64-avx-mpx-linux.xml   |   1 +
 gdb/features/i386/amd64-avx512-linux.c      | 192 ++++++++++++++--------------
 gdb/features/i386/amd64-avx512-linux.xml    |   1 +
 gdb/features/i386/amd64-linux.c             |   4 +
 gdb/features/i386/amd64-linux.xml           |   1 +
 gdb/features/i386/amd64-mpx-linux.c         |  16 ++-
 gdb/features/i386/amd64-mpx-linux.xml       |   1 +
 gdb/features/i386/x32-avx-linux.c           |  36 +++---
 gdb/features/i386/x32-avx-linux.xml         |   1 +
 gdb/features/i386/x32-avx512-linux.c        | 192 ++++++++++++++--------------
 gdb/features/i386/x32-avx512-linux.xml      |   1 +
 gdb/features/i386/x32-linux.c               |   4 +
 gdb/features/i386/x32-linux.xml             |   1 +
 gdb/gdbserver/configure.srv                 |   2 +-
 gdb/gdbserver/linux-x86-low.c               |  32 +++++
 gdb/regformats/i386/amd64-avx-linux.dat     |   2 +
 gdb/regformats/i386/amd64-avx-mpx-linux.dat |   2 +
 gdb/regformats/i386/amd64-avx512-linux.dat  |   2 +
 gdb/regformats/i386/amd64-linux.dat         |   2 +
 gdb/regformats/i386/amd64-mpx-linux.dat     |   2 +
 gdb/regformats/i386/x32-avx-linux.dat       |   2 +
 gdb/regformats/i386/x32-avx512-linux.dat    |   2 +
 gdb/regformats/i386/x32-linux.dat           |   2 +
 gdb/testsuite/gdb.arch/amd64-gs_base.c      |  26 ++++
 gdb/testsuite/gdb.arch/amd64-gs_base.exp    |  51 ++++++++
 37 files changed, 531 insertions(+), 264 deletions(-)
 create mode 100644 gdb/features/i386/64bit-segments.xml
 create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.c
 create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.exp

diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
index 4a2036b..0ec22cb 100644
--- a/gdb/amd64-linux-nat.c
+++ b/gdb/amd64-linux-nat.c
@@ -40,6 +40,11 @@
 #include "nat/linux-ptrace.h"
 #include "nat/amd64-linux-siginfo.h"
 
+/* This definition comes from prctl.h, but some kernels may not have it.  */
+#ifndef PTRACE_ARCH_PRCTL
+#define PTRACE_ARCH_PRCTL      30
+#endif
+
 /* Mapping between the general-purpose registers in GNU/Linux x86-64
    `struct user' format and GDB's register cache layout for GNU/Linux
    i386.
@@ -171,6 +176,30 @@ amd64_linux_fetch_inferior_registers (struct target_ops *ops,
 
 	  amd64_supply_fxsave (regcache, -1, &fpregs);
 	}
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+      {
+	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
+	   fs_base and gs_base fields of user_regs_struct can be
+	   used directly.  */
+	unsigned long base;
+
+	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
+	  {
+	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_FS) < 0)
+	      perror_with_name (_("Couldn't get segment register fs_base"));
+
+	    regcache_raw_supply (regcache, AMD64_FSBASE_REGNUM, &base);
+	  }
+
+	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
+	  {
+	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_GS) < 0)
+	      perror_with_name (_("Couldn't get segment register gs_base"));
+
+	    regcache_raw_supply (regcache, AMD64_GSBASE_REGNUM, &base);
+	  }
+      }
+#endif
     }
 }
 
@@ -237,6 +266,30 @@ amd64_linux_store_inferior_registers (struct target_ops *ops,
 	  if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0)
 	    perror_with_name (_("Couldn't write floating point status"));
 	}
+
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+      {
+	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
+	   fs_base and gs_base fields of user_regs_struct can be
+	   used directly.  */
+	void *base;
+
+	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
+	  {
+	    regcache_raw_collect (regcache, AMD64_FSBASE_REGNUM, &base);
+
+	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_FS) < 0)
+	      perror_with_name (_("Couldn't write fs_base"));
+	  }
+	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
+	  {
+
+	    regcache_raw_collect (regcache, AMD64_GSBASE_REGNUM, &base);
+	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_GS) < 0)
+	      perror_with_name (_("Couldn't write gs_base"));
+	  }
+      }
+#endif
     }
 }
 \f
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 1e9f75f..b9d7176 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -103,6 +103,9 @@ int amd64_linux_gregset_reg_offset[] =
   -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1,
+
+  /* End of hardware registers */
+  21 * 8, 22 * 8,		      /* fs_base and gs_base.  */
   15 * 8			      /* "orig_rax" */
 };
 \f
@@ -284,7 +287,9 @@ static int
 amd64_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				 struct reggroup *group)
 { 
-  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM)
+  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM
+      || regnum == AMD64_FSBASE_REGNUM
+      || regnum == AMD64_GSBASE_REGNUM)
     return (group == system_reggroup
             || group == save_reggroup
             || group == restore_reggroup);
diff --git a/gdb/amd64-linux-tdep.h b/gdb/amd64-linux-tdep.h
index 5d032a6..3704caa 100644
--- a/gdb/amd64-linux-tdep.h
+++ b/gdb/amd64-linux-tdep.h
@@ -26,7 +26,7 @@
 /* Register number for the "orig_rax" register.  If this register
    contains a value >= 0 it is interpreted as the system call number
    that the kernel is supposed to restart.  */
-#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_ZMM31H_REGNUM + 1)
+#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_NUM_REGS)
 
 /* Total number of registers for GNU/Linux.  */
 #define AMD64_LINUX_NUM_REGS (AMD64_LINUX_ORIG_RAX_REGNUM + 1)
diff --git a/gdb/amd64-nat.c b/gdb/amd64-nat.c
index 18c8a99..0143632 100644
--- a/gdb/amd64-nat.c
+++ b/gdb/amd64-nat.c
@@ -53,6 +53,7 @@ amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum)
 {
   int *reg_offset = amd64_native_gregset64_reg_offset;
   int num_regs = amd64_native_gregset64_num_regs;
+  bool valid_regnum = false;
 
   gdb_assert (regnum >= 0);
 
@@ -65,10 +66,22 @@ amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum)
   if (num_regs > gdbarch_num_regs (gdbarch))
     num_regs = gdbarch_num_regs (gdbarch);
 
-  if (regnum < num_regs && regnum < gdbarch_num_regs (gdbarch))
-    return reg_offset[regnum];
+  /* Looks like we do not need the second part of the &&.
+     Register validity is already guaranteed in the first part due to the
+     comparison above.  */
+  valid_regnum = regnum < num_regs && regnum < gdbarch_num_regs (gdbarch);
 
-  return -1;
+  if (valid_regnum == false)
+    return -1;
+
+  /* Definition of the offset foresees new kernel support, it has to be
+     corrected here in case the kernel is older.  */
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+  if (regnum == AMD64_FSBASE_REGNUM || regnum == AMD64_GSBASE_REGNUM)
+    return -1;
+#endif
+
+  return reg_offset[regnum];
 }
 
 /* Return whether the native general-purpose register set supplies
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index a636742..2588025 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -3047,6 +3047,19 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
       tdep->bnd0r_regnum = AMD64_BND0R_REGNUM;
     }
 
+  if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments") != NULL)
+    {
+      const struct tdesc_feature *feature =
+	  tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments");
+      struct tdesc_arch_data *tdesc_data_segments
+      = (struct tdesc_arch_data *) info.tdep_info;
+
+      tdesc_numbered_register (feature, tdesc_data_segments,
+		       AMD64_FSBASE_REGNUM, "fs_base");
+      tdesc_numbered_register (feature, tdesc_data_segments,
+		       AMD64_GSBASE_REGNUM, "gs_base");
+    }
+
   tdep->num_byte_regs = 20;
   tdep->num_word_regs = 16;
   tdep->num_dword_regs = 16;
diff --git a/gdb/amd64-tdep.h b/gdb/amd64-tdep.h
index 3f84947..8ccf031 100644
--- a/gdb/amd64-tdep.h
+++ b/gdb/amd64-tdep.h
@@ -76,13 +76,15 @@ enum amd64_regnum
   AMD64_K0_REGNUM,
   AMD64_K7_REGNUM = AMD64_K0_REGNUM + 7,
   AMD64_ZMM0H_REGNUM,
-  AMD64_ZMM31H_REGNUM = AMD64_ZMM0H_REGNUM + 31
+  AMD64_ZMM31H_REGNUM = AMD64_ZMM0H_REGNUM + 31,
+  AMD64_FSBASE_REGNUM,
+  AMD64_GSBASE_REGNUM
 };
 
 /* Number of general purpose registers.  */
 #define AMD64_NUM_GREGS		24
 
-#define AMD64_NUM_REGS		(AMD64_ZMM31H_REGNUM + 1)
+#define AMD64_NUM_REGS		(AMD64_GSBASE_REGNUM + 1)
 
 extern struct target_desc *tdesc_amd64;
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 2b6b654..4e854ce 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -41148,6 +41148,9 @@ Memory Protection Extension (MPX).  It should describe the following registers:
 The @samp{org.gnu.gdb.i386.linux} feature is optional.  It should
 describe a single register, @samp{orig_eax}.
 
+The @samp{org.gnu.gdb.i386.segments} feature is optional.  It should
+describe two system registers: @samp{fs_base} and @samp{gs_base}.
+
 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
 @samp{org.gnu.gdb.i386.avx} feature.  It should
 describe additional @sc{xmm} registers:
diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index 63f8248..5a82641 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -259,7 +259,7 @@ $(outdir)/i386/i386-linux.dat: i386/32bit-core.xml i386/32bit-sse.xml \
 			       i386/32bit-linux.xml
 $(outdir)/i386/amd64.dat: i386/64bit-core.xml i386/64bit-sse.xml
 $(outdir)/i386/amd64-linux.dat: i386/64bit-core.xml i386/64bit-sse.xml \
-			        i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/i386-avx.dat: i386/32bit-core.xml i386/32bit-avx.xml
 $(outdir)/i386/i386-avx-linux.dat: i386/32bit-core.xml i386/32bit-avx.xml \
 			       i386/32bit-linux.xml
@@ -279,11 +279,11 @@ $(outdir)/i386/i386-mmx.dat: i386/32bit-core.xml
 $(outdir)/i386/i386-mmx-linux.dat: i386/32bit-core.xml i386/32bit-linux.xml
 $(outdir)/i386/amd64-avx.dat: i386/64bit-core.xml i386/64bit-avx.xml
 $(outdir)/i386/amd64-avx-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
-				    i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/amd64-mpx-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
-			       i386/64bit-linux.xml i386/64bit-mpx.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml i386/64bit-mpx.xml
 $(outdir)/i386/amd64-avx-mpx-linux.dat: i386/64bit-core.xml \
-			       i386/64bit-linux.xml i386/64bit-mpx.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml i386/64bit-mpx.xml
 $(outdir)/i386/amd64-mpx.dat: i386/64bit-core.xml i386/64bit-avx.xml \
 			       i386/64bit-mpx.xml
 $(outdir)/i386/amd64-avx-mpx.dat: i386/64bit-core.xml \
@@ -292,17 +292,18 @@ $(outdir)/i386/amd64-avx512.dat: i386/64bit-core.xml i386/64bit-avx.xml \
 			       i386/64bit-mpx.xml i386/64bit-avx512.xml
 $(outdir)/i386/amd64-avx512-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
 			       i386/64bit-mpx.xml i386/64bit-avx512.xml \
-			       i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/x32.dat: i386/x32-core.xml i386/64bit-sse.xml
 $(outdir)/i386/x32-linux.dat: i386/x32-core.xml i386/64bit-sse.xml \
-			      i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/x32-avx.dat: i386/x32-core.xml i386/64bit-avx.xml
 $(outdir)/i386/x32-avx-linux.dat: i386/x32-core.xml i386/64bit-avx.xml \
-				  i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/x32-avx512.dat: i386/x32-core.xml i386/64bit-avx.xml \
 			       i386/64bit-mpx.xml i386/64bit-avx512.xml
 $(outdir)/i386/x32-avx512-linux.dat: i386/x32-core.xml i386/64bit-avx.xml \
-			       i386/64bit-mpx.xml i386/64bit-avx512.xml i386/64bit-linux.xml
+			       i386/64bit-mpx.xml i386/64bit-avx512.xml \
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 
 # 'all' doesn't build the C files, so don't delete them in 'clean'
 # either.
diff --git a/gdb/features/i386/64bit-segments.xml b/gdb/features/i386/64bit-segments.xml
new file mode 100644
index 0000000..16c0929
--- /dev/null
+++ b/gdb/features/i386/64bit-segments.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2016 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.i386.segments">
+  <reg name="fs_base" bitsize="64" type="int"/>
+  <reg name="gs_base" bitsize="64" type="int"/>
+</feature>
diff --git a/gdb/features/i386/amd64-avx-linux.c b/gdb/features/i386/amd64-avx-linux.c
index 9c8f9eb..1d56dbf 100644
--- a/gdb/features/i386/amd64-avx-linux.c
+++ b/gdb/features/i386/amd64-avx-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   tdesc_amd64_avx_linux = result;
 }
diff --git a/gdb/features/i386/amd64-avx-linux.xml b/gdb/features/i386/amd64-avx-linux.xml
index 470dd55..2dac9cd 100644
--- a/gdb/features/i386/amd64-avx-linux.xml
+++ b/gdb/features/i386/amd64-avx-linux.xml
@@ -14,5 +14,6 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
 </target>
diff --git a/gdb/features/i386/amd64-avx-mpx-linux.c b/gdb/features/i386/amd64-avx-mpx-linux.c
index 4605480..26c1339 100644
--- a/gdb/features/i386/amd64-avx-mpx-linux.c
+++ b/gdb/features/i386/amd64-avx-mpx-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx_mpx_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
   type = tdesc_create_struct (feature, "br128");
@@ -200,12 +204,12 @@ initialize_tdesc_amd64_avx_mpx_linux (void)
   field_type = tdesc_named_type (feature, "_bndcfgu");
   tdesc_add_field (type, "config", field_type);
 
-  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
+  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
 
   tdesc_amd64_avx_mpx_linux = result;
 }
diff --git a/gdb/features/i386/amd64-avx-mpx-linux.xml b/gdb/features/i386/amd64-avx-mpx-linux.xml
index e29317f..433f777 100644
--- a/gdb/features/i386/amd64-avx-mpx-linux.xml
+++ b/gdb/features/i386/amd64-avx-mpx-linux.xml
@@ -14,6 +14,7 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
   <xi:include href="64bit-mpx.xml"/>
 </target>
diff --git a/gdb/features/i386/amd64-avx512-linux.c b/gdb/features/i386/amd64-avx512-linux.c
index ec3ba61..b071f62 100644
--- a/gdb/features/i386/amd64-avx512-linux.c
+++ b/gdb/features/i386/amd64-avx512-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx512_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
   type = tdesc_create_struct (feature, "br128");
@@ -200,12 +204,12 @@ initialize_tdesc_amd64_avx512_linux (void)
   field_type = tdesc_named_type (feature, "_bndcfgu");
   tdesc_add_field (type, "config", field_type);
 
-  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
+  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
   field_type = tdesc_named_type (feature, "ieee_single");
@@ -245,78 +249,78 @@ initialize_tdesc_amd64_avx512_linux (void)
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_create_vector (feature, "v2ui128", field_type, 2);
 
-  tdesc_create_reg (feature, "xmm16", 80, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm17", 81, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm18", 82, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm19", 83, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm20", 84, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm21", 85, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm22", 86, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm23", 87, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm24", 88, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm25", 89, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm26", 90, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm27", 91, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm28", 92, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm29", 93, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm30", 94, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm31", 95, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "ymm16h", 96, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm17h", 97, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm18h", 98, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm19h", 99, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm20h", 100, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm21h", 101, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm22h", 102, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm23h", 103, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm24h", 104, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm25h", 105, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm26h", 106, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm27h", 107, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm28h", 108, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm29h", 109, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm30h", 110, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm31h", 111, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "k0", 112, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 113, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 114, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 115, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 116, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 117, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 118, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 119, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 120, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 121, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 122, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 123, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 124, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 125, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 126, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 127, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm8h", 128, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm9h", 129, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm10h", 130, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm11h", 131, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm12h", 132, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm13h", 133, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm14h", 134, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm15h", 135, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm16h", 136, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm17h", 137, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm18h", 138, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm19h", 139, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm20h", 140, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm21h", 141, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm22h", 142, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm23h", 143, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm24h", 144, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm25h", 145, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm26h", 146, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm27h", 147, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm28h", 148, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm29h", 149, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm30h", 150, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm31h", 151, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "xmm16", 82, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm17", 83, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm18", 84, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm19", 85, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm20", 86, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm21", 87, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm22", 88, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm23", 89, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm24", 90, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm25", 91, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm26", 92, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm27", 93, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm28", 94, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm29", 95, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm30", 96, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm31", 97, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "ymm16h", 98, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm17h", 99, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm18h", 100, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm19h", 101, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm20h", 102, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm21h", 103, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm22h", 104, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm23h", 105, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm24h", 106, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm25h", 107, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm26h", 108, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm27h", 109, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm28h", 110, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm29h", 111, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm30h", 112, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm31h", 113, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "k0", 114, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k1", 115, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k2", 116, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k3", 117, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k4", 118, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k5", 119, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k6", 120, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k7", 121, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "zmm0h", 122, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm1h", 123, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm2h", 124, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm3h", 125, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm4h", 126, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm5h", 127, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm6h", 128, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm7h", 129, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm8h", 130, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm9h", 131, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm10h", 132, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm11h", 133, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm12h", 134, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm13h", 135, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm14h", 136, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm15h", 137, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm16h", 138, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm17h", 139, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm18h", 140, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm19h", 141, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm20h", 142, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm21h", 143, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm22h", 144, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm23h", 145, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm24h", 146, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm25h", 147, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm26h", 148, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm27h", 149, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm28h", 150, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm29h", 151, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm30h", 152, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm31h", 153, 1, NULL, 256, "v2ui128");
 
   tdesc_amd64_avx512_linux = result;
 }
diff --git a/gdb/features/i386/amd64-avx512-linux.xml b/gdb/features/i386/amd64-avx512-linux.xml
index 2ee2e8b..516f4e3 100644
--- a/gdb/features/i386/amd64-avx512-linux.xml
+++ b/gdb/features/i386/amd64-avx512-linux.xml
@@ -14,6 +14,7 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
   <xi:include href="64bit-mpx.xml"/>
   <xi:include href="64bit-avx512.xml"/>
diff --git a/gdb/features/i386/amd64-linux.c b/gdb/features/i386/amd64-linux.c
index 02aeba5..0e921ba9 100644
--- a/gdb/features/i386/amd64-linux.c
+++ b/gdb/features/i386/amd64-linux.c
@@ -151,5 +151,9 @@ initialize_tdesc_amd64_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   tdesc_amd64_linux = result;
 }
diff --git a/gdb/features/i386/amd64-linux.xml b/gdb/features/i386/amd64-linux.xml
index 2ce9341..7d3a9f2 100644
--- a/gdb/features/i386/amd64-linux.xml
+++ b/gdb/features/i386/amd64-linux.xml
@@ -14,4 +14,5 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
 </target>
diff --git a/gdb/features/i386/amd64-mpx-linux.c b/gdb/features/i386/amd64-mpx-linux.c
index a20ca4f..e26a74a 100644
--- a/gdb/features/i386/amd64-mpx-linux.c
+++ b/gdb/features/i386/amd64-mpx-linux.c
@@ -151,6 +151,10 @@ initialize_tdesc_amd64_mpx_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
   type = tdesc_create_struct (feature, "br128");
   field_type = tdesc_named_type (feature, "uint64");
@@ -182,12 +186,12 @@ initialize_tdesc_amd64_mpx_linux (void)
   field_type = tdesc_named_type (feature, "_bndcfgu");
   tdesc_add_field (type, "config", field_type);
 
-  tdesc_create_reg (feature, "bnd0raw", 58, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 59, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 60, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 61, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 62, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 63, 1, NULL, 64, "status");
+  tdesc_create_reg (feature, "bnd0raw", 60, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", 61, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", 62, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", 63, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", 64, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", 65, 1, NULL, 64, "status");
 
   tdesc_amd64_mpx_linux = result;
 }
diff --git a/gdb/features/i386/amd64-mpx-linux.xml b/gdb/features/i386/amd64-mpx-linux.xml
index 9c7cf9a..853b819 100644
--- a/gdb/features/i386/amd64-mpx-linux.xml
+++ b/gdb/features/i386/amd64-mpx-linux.xml
@@ -14,5 +14,6 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-mpx.xml"/>
 </target>
diff --git a/gdb/features/i386/x32-avx-linux.c b/gdb/features/i386/x32-avx-linux.c
index b12c71c..8406815 100644
--- a/gdb/features/i386/x32-avx-linux.c
+++ b/gdb/features/i386/x32-avx-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_x32_avx_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   tdesc_x32_avx_linux = result;
 }
diff --git a/gdb/features/i386/x32-avx-linux.xml b/gdb/features/i386/x32-avx-linux.xml
index f60a443..89d2e7c 100644
--- a/gdb/features/i386/x32-avx-linux.xml
+++ b/gdb/features/i386/x32-avx-linux.xml
@@ -14,5 +14,6 @@
   <xi:include href="x32-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
 </target>
diff --git a/gdb/features/i386/x32-avx512-linux.c b/gdb/features/i386/x32-avx512-linux.c
index 7b2ab90..3994996 100644
--- a/gdb/features/i386/x32-avx512-linux.c
+++ b/gdb/features/i386/x32-avx512-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_x32_avx512_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
   type = tdesc_create_struct (feature, "br128");
@@ -200,12 +204,12 @@ initialize_tdesc_x32_avx512_linux (void)
   field_type = tdesc_named_type (feature, "_bndcfgu");
   tdesc_add_field (type, "config", field_type);
 
-  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
+  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
   field_type = tdesc_named_type (feature, "ieee_single");
@@ -245,78 +249,78 @@ initialize_tdesc_x32_avx512_linux (void)
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_create_vector (feature, "v2ui128", field_type, 2);
 
-  tdesc_create_reg (feature, "xmm16", 80, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm17", 81, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm18", 82, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm19", 83, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm20", 84, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm21", 85, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm22", 86, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm23", 87, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm24", 88, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm25", 89, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm26", 90, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm27", 91, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm28", 92, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm29", 93, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm30", 94, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm31", 95, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "ymm16h", 96, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm17h", 97, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm18h", 98, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm19h", 99, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm20h", 100, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm21h", 101, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm22h", 102, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm23h", 103, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm24h", 104, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm25h", 105, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm26h", 106, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm27h", 107, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm28h", 108, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm29h", 109, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm30h", 110, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm31h", 111, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "k0", 112, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 113, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 114, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 115, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 116, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 117, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 118, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 119, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 120, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 121, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 122, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 123, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 124, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 125, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 126, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 127, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm8h", 128, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm9h", 129, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm10h", 130, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm11h", 131, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm12h", 132, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm13h", 133, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm14h", 134, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm15h", 135, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm16h", 136, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm17h", 137, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm18h", 138, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm19h", 139, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm20h", 140, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm21h", 141, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm22h", 142, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm23h", 143, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm24h", 144, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm25h", 145, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm26h", 146, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm27h", 147, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm28h", 148, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm29h", 149, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm30h", 150, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm31h", 151, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "xmm16", 82, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm17", 83, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm18", 84, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm19", 85, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm20", 86, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm21", 87, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm22", 88, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm23", 89, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm24", 90, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm25", 91, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm26", 92, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm27", 93, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm28", 94, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm29", 95, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm30", 96, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm31", 97, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "ymm16h", 98, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm17h", 99, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm18h", 100, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm19h", 101, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm20h", 102, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm21h", 103, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm22h", 104, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm23h", 105, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm24h", 106, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm25h", 107, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm26h", 108, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm27h", 109, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm28h", 110, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm29h", 111, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm30h", 112, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm31h", 113, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "k0", 114, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k1", 115, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k2", 116, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k3", 117, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k4", 118, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k5", 119, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k6", 120, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k7", 121, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "zmm0h", 122, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm1h", 123, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm2h", 124, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm3h", 125, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm4h", 126, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm5h", 127, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm6h", 128, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm7h", 129, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm8h", 130, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm9h", 131, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm10h", 132, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm11h", 133, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm12h", 134, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm13h", 135, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm14h", 136, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm15h", 137, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm16h", 138, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm17h", 139, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm18h", 140, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm19h", 141, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm20h", 142, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm21h", 143, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm22h", 144, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm23h", 145, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm24h", 146, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm25h", 147, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm26h", 148, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm27h", 149, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm28h", 150, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm29h", 151, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm30h", 152, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm31h", 153, 1, NULL, 256, "v2ui128");
 
   tdesc_x32_avx512_linux = result;
 }
diff --git a/gdb/features/i386/x32-avx512-linux.xml b/gdb/features/i386/x32-avx512-linux.xml
index 73238dc..7266c8e 100644
--- a/gdb/features/i386/x32-avx512-linux.xml
+++ b/gdb/features/i386/x32-avx512-linux.xml
@@ -14,6 +14,7 @@
   <xi:include href="x32-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
   <xi:include href="64bit-mpx.xml"/>
   <xi:include href="64bit-avx512.xml"/>
diff --git a/gdb/features/i386/x32-linux.c b/gdb/features/i386/x32-linux.c
index 1262688..ae49549 100644
--- a/gdb/features/i386/x32-linux.c
+++ b/gdb/features/i386/x32-linux.c
@@ -151,5 +151,9 @@ initialize_tdesc_x32_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   tdesc_x32_linux = result;
 }
diff --git a/gdb/features/i386/x32-linux.xml b/gdb/features/i386/x32-linux.xml
index a7d0899..023a48d 100644
--- a/gdb/features/i386/x32-linux.xml
+++ b/gdb/features/i386/x32-linux.xml
@@ -14,4 +14,5 @@
   <xi:include href="x32-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
 </target>
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 3267599..d03dcb9 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -35,7 +35,7 @@ ipa_x32_linux_regobj="x32-linux-ipa.o x32-avx-linux-ipa.o x32-avx512-linux-ipa.o
 ipa_ppc_linux_regobj="powerpc-32l-ipa.o powerpc-altivec32l-ipa.o powerpc-cell32l-ipa.o powerpc-vsx32l-ipa.o powerpc-isa205-32l-ipa.o powerpc-isa205-altivec32l-ipa.o powerpc-isa205-vsx32l-ipa.o powerpc-e500l-ipa.o powerpc-64l-ipa.o powerpc-altivec64l-ipa.o powerpc-cell64l-ipa.o powerpc-vsx64l-ipa.o powerpc-isa205-64l-ipa.o powerpc-isa205-altivec64l-ipa.o powerpc-isa205-vsx64l-ipa.o"
 
 srv_i386_32bit_xmlfiles="i386/32bit-core.xml i386/32bit-sse.xml i386/32bit-avx.xml i386/32bit-avx512.xml i386/32bit-mpx.xml"
-srv_i386_64bit_xmlfiles="i386/64bit-core.xml i386/64bit-sse.xml i386/64bit-avx.xml i386/64bit-avx512.xml i386/x32-core.xml i386/64bit-mpx.xml"
+srv_i386_64bit_xmlfiles="i386/64bit-core.xml i386/64bit-segments.xml i386/64bit-sse.xml i386/64bit-avx.xml i386/64bit-avx512.xml i386/x32-core.xml i386/64bit-mpx.xml"
 srv_i386_xmlfiles="i386/i386.xml i386/i386-avx.xml i386/i386-avx512.xml i386/i386-mpx.xml i386/i386-avx-mpx.xml i386/i386-mmx.xml $srv_i386_32bit_xmlfiles"
 srv_amd64_xmlfiles="i386/amd64.xml i386/amd64-avx.xml i386/amd64-avx512.xml i386/x32.xml i386/x32-avx.xml i386/x32-avx512.xml i386/amd64-mpx.xml i386/amd64-avx-mpx.xml  $srv_i386_64bit_xmlfiles"
 srv_i386_linux_xmlfiles="i386/i386-linux.xml i386/i386-avx-linux.xml i386/i386-avx512-linux.xml i386/i386-mmx-linux.xml i386/32bit-linux.xml i386/i386-mpx-linux.xml i386/i386-avx-mpx-linux.xml $srv_i386_32bit_xmlfiles"
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index dd9538a..8fdf324 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -133,6 +133,11 @@ static const int x86_64_regmap[] =
   -1,
   -1, -1, -1, -1, -1, -1, -1, -1,
   ORIG_RAX * 8,
+#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+  21 * 8,  22 * 8,
+#else
+  -1, -1,
+#endif
   -1, -1, -1, -1,			/* MPX registers BND0 ... BND3.  */
   -1, -1,				/* MPX registers BNDCFGU, BNDSTATUS.  */
   -1, -1, -1, -1, -1, -1, -1, -1,       /* xmm16 ... xmm31 (AVX512)  */
@@ -306,6 +311,20 @@ x86_fill_gregset (struct regcache *regcache, void *buf)
       for (i = 0; i < X86_64_NUM_REGS; i++)
 	if (x86_64_regmap[i] != -1)
 	  collect_register (regcache, i, ((char *) buf) + x86_64_regmap[i]);
+
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+      {
+        unsigned long base;
+        int lwpid = lwpid_of (current_thread);
+
+        collect_register_by_name (regcache, "fs_base", &base);
+        ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_SET_FS);
+
+        collect_register_by_name (regcache, "gs_base", &base);
+        ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_SET_GS);
+      }
+#endif
+
       return;
     }
 
@@ -332,6 +351,19 @@ x86_store_gregset (struct regcache *regcache, const void *buf)
       for (i = 0; i < X86_64_NUM_REGS; i++)
 	if (x86_64_regmap[i] != -1)
 	  supply_register (regcache, i, ((char *) buf) + x86_64_regmap[i]);
+
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+      {
+        unsigned long base;
+        int lwpid = lwpid_of (current_thread);
+
+        if (ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_GET_FS) == 0)
+          supply_register_by_name (regcache, "fs_base", &base);
+
+        if (ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_GET_GS) == 0)
+          supply_register_by_name (regcache, "gs_base", &base);
+      }
+#endif
       return;
     }
 #endif
diff --git a/gdb/regformats/i386/amd64-avx-linux.dat b/gdb/regformats/i386/amd64-avx-linux.dat
index d8199da..7780b3b 100644
--- a/gdb/regformats/i386/amd64-avx-linux.dat
+++ b/gdb/regformats/i386/amd64-avx-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/amd64-avx-mpx-linux.dat b/gdb/regformats/i386/amd64-avx-mpx-linux.dat
index 6d45324..7c2f928 100644
--- a/gdb/regformats/i386/amd64-avx-mpx-linux.dat
+++ b/gdb/regformats/i386/amd64-avx-mpx-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/amd64-avx512-linux.dat b/gdb/regformats/i386/amd64-avx512-linux.dat
index dfc41e2..f1658d3 100644
--- a/gdb/regformats/i386/amd64-avx512-linux.dat
+++ b/gdb/regformats/i386/amd64-avx512-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/amd64-linux.dat b/gdb/regformats/i386/amd64-linux.dat
index 6914cc4..cd16a15 100644
--- a/gdb/regformats/i386/amd64-linux.dat
+++ b/gdb/regformats/i386/amd64-linux.dat
@@ -61,3 +61,5 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
diff --git a/gdb/regformats/i386/amd64-mpx-linux.dat b/gdb/regformats/i386/amd64-mpx-linux.dat
index 523ae01..10487f6 100644
--- a/gdb/regformats/i386/amd64-mpx-linux.dat
+++ b/gdb/regformats/i386/amd64-mpx-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:bnd0raw
 128:bnd1raw
 128:bnd2raw
diff --git a/gdb/regformats/i386/x32-avx-linux.dat b/gdb/regformats/i386/x32-avx-linux.dat
index a2b8d02..eb0e3953 100644
--- a/gdb/regformats/i386/x32-avx-linux.dat
+++ b/gdb/regformats/i386/x32-avx-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/x32-avx512-linux.dat b/gdb/regformats/i386/x32-avx512-linux.dat
index 0f5b2ce..0b7f73a 100644
--- a/gdb/regformats/i386/x32-avx512-linux.dat
+++ b/gdb/regformats/i386/x32-avx512-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/x32-linux.dat b/gdb/regformats/i386/x32-linux.dat
index d976a25..eee378f 100644
--- a/gdb/regformats/i386/x32-linux.dat
+++ b/gdb/regformats/i386/x32-linux.dat
@@ -61,3 +61,5 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.c b/gdb/testsuite/gdb.arch/amd64-gs_base.c
new file mode 100644
index 0000000..d0a2a8f
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-gs_base.c
@@ -0,0 +1,26 @@
+/* Test program for fs_base and gs_base.
+
+   Copyright 2016 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+main (void)
+{
+  volatile int a;
+  a = 10;
+  return a;
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.exp b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
new file mode 100644
index 0000000..f2dc887
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
@@ -0,0 +1,51 @@
+# Copyright 2016 Free Software Foundation, Inc.
+
+# Contributed by Intel Corp. <walfred.tedeschi@intel.com>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+if { ![istarget "x86_64-*linux*"] } then {
+    verbose "Skipping x86_64 fs_base and gs_base tests."
+    return
+}
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+     [list debug nowarnings]] } {
+    return -1
+}
+
+if ![runto_main] {
+    untested "could not run to main"
+    return -1
+}
+
+gdb_test "print /x \$fs_base" "= $hex" "print fs_base"
+gdb_test "print /x \$gs_base" "= $hex" "print gs_base"
+
+gdb_test "print \$fs_base = 2" "= 2" "set fs_base"
+gdb_test "print \$gs_base = 3" "= 3" "set gs_base"
+
+# Test the presence of fs_base and gs_base on the system
+# register group and values.
+#
+set ws "\[\t \]*"
+set info_reg_out [multi_line "info register sys" \
+          "fs_base${ws}0x2${ws}2"\
+          "gs_base${ws}0x3${ws}3"\
+          "orig_rax${ws}$hex${ws}\[-\]$decimal" ]
+
+gdb_test "info register sys" $info_reg_out\
+   "info registers fs_base and gs_base with value"
-- 
2.9.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/1] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2017-01-05 15:53 [PATCH V2 1/1] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
@ 2017-01-09 20:35 ` Luis Machado
  2017-01-19 19:49   ` Pedro Alves
  2017-01-19 19:45 ` Pedro Alves
  1 sibling, 1 reply; 5+ messages in thread
From: Luis Machado @ 2017-01-09 20:35 UTC (permalink / raw)
  To: Walfred Tedeschi, palves, brobecker; +Cc: gdb-patches

On 01/05/2017 09:53 AM, Walfred Tedeschi wrote:
> This patch allows examination of the registers FS_BASE and GS_BASE
> for Linux Systems running on 64bit. Tests for simple read and write
> of the new registers is also added with this patch.
>
> Tests were performed on:
> x86_64 RHEL 5.3     - For the older ptrace calls.
> x86_64 Ubuntu 16.10 - For the new ptrace calls.
>
>
> Changes from Richard's version:
> * Added support for remote.
> * Added test cases.
>
>
> Change requested by John Baldwin, as reported at:
>
> * Moved initialization of fs_base and gs_base from amd64-linux-tdep.c
> to amd64-tdep.c
>
> Changes after Pedro's comments:
> * Moved usage of "HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE" to native
> files.
> * Double checked indentation on "gdb/features/Makefile".
> * Removed hard coded register number from "64bit-segments.xml"
> * Register size was kept as same as orig_rax.
> * Removed spurious function from the test sample.
> * Test is using prepare_for_testing.
>
> Additional comment on register ordering:
> orig_rax is the last register added there is a special macro that defines
> it in this way. On gdbserver side it is defined in the middle of
> the registers and stays there always for compatibility.
>
> I have added the two new registers just after the orig_rax.  This causes
> that they will be in the gdbserver side just after orig_rax and in gdb
>
> I still can add then where I would prefer, the definition is
> done by the macros defining AMD64_FSBASE_REGNUM. In this sense they have
> been added just before the orig_rax.
>
> This decision was taken based on the fact that we would like to add
> hardware registers as usual before the orig_rax, and with this addition
> also before the fs_base and gs_base.
>
>
> 2017-01-05  Walfred Tedeschi  <walfred.tedeschi@intel.com>
> 	    Richard Henderson  <rth@redhat.com>
>
> gdb/ChangeLog:
>
> 	* amd64-linux-nat.c (PTRACE_ARCH_PRCTL): New define.
> 	(amd64_linux_fetch_inferior_registers): Add case to fetch FS_BASE
> 	GS_BASE for older kernels.
> 	(amd64_linux_store_inferior_registers): Add case to store FS_BASE
> 	GS_BASE for older kernels.
> 	* amd64-linux-tdep.c (amd64_linux_gregset_reg_offset): Add FS_BASE
> 	and GS_BASE to the offset table.
> 	(amd64_linux_register_reggroup_p): Add FS_BASE and GS_BASE to the
> 	system register group.
> 	* amd64-linux-tdep.h (AMD64_LINUX_ORIG_RAX_REGNUM): Set the value
> 	to AMD64_NUM_REGS.
> 	* amd64-nat.c (amd64_native_gregset_reg_offset): Adds valid_regnum
> 	to test validit of the register.  Implements case for older
> 	kernels.
> 	* amd64-tdep.c (amd64_init_abi): Add segment registers for the
> 	amd64 ABI.
> 	* amd64-tdep.h (amd64_regnum): Add AMD64_FSBASE_REGNUM and
> 	AMD64_GSBASE_REGNUM.
> 	(AMD64_NUM_REGS): Set to AMD64_GSBASE_REGNUM + 1.
> 	* features/Makefile (amd64-linux.dat, amd64-avx-linux.dat)
> 	(amd64-mpx-linux.dat, amd64-avx512-linux.dat, x32-linux.dat)
> 	(x32-avx-linux.dat, x32-avx512-linux.dat): Add
> 	i386/64bit-segments.xml in those rules.
> 	* features/i386/64bit-segments.xml: New file.
> 	* features/i386/amd64-avx-mpx-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-avx-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-avx512-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-mpx-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/x32-avx512-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/x32-avx-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-avx-linux.c: Regenerated.
> 	* features/i386/amd64-avx-mpx-linux.c: Regenerated.
> 	* features/i386/amd64-avx-mpx.c: Regenerated.
> 	* features/i386/amd64-avx512-linux.c: Regenerated.
> 	* features/i386/amd64-linux.c: Regenerated.
> 	* features/i386/amd64-mpx-linux.c: Regenerated.
> 	* features/i386/i386-avx-mpx-linux.c: Regenerated.
> 	* features/i386/i386-avx-mpx.c: Regenerated.
> 	* features/i386/x32-avx-linux.c: Regenerated.
> 	* features/i386/x32-avx512-linux.c: Regenerated.
> 	* regformats/i386/amd64-avx-linux.dat: Regenerated.
> 	* regformats/i386/amd64-avx-mpx-linux.dat: Regenerated.
> 	* regformats/i386/amd64-avx512-linux.dat: Regenerated.
> 	* regformats/i386/amd64-linux.dat: Regenerated.
> 	* regformats/i386/amd64-mpx-linux.dat: Regenerated.
> 	* regformats/i386/x32-avx-linux.dat: Regenerated.
> 	* regformats/i386/x32-avx512-linux.dat: Regenerated.
> 	* regformats/i386/x32-linux.dat: Regenerated.
>
> gdb/doc/ChangeLog:
>
> 	* gdb.texinfo (i386 Features): Add system segment registers
> 	as feature.
>
> gdb/gdbserver/ChangeLog:
>
> 	* linux-x86-low.c (x86_64_regmap): Add fs_base and gs_base
> 	to the register table.
> 	(x86_fill_gregset): Add support for old kernels for the
> 	fs_base and gs_base system registers.
> 	(x86_store_gregset): Likewise.
> 	* configure.srv (srv_i386_64bit_xmlfiles): Add 64bit-segments.xml.
>
> gdb/testsuite/ChangeLog:
>
> 	* gdb.arch/amd64-gs_base.c: New file.
> 	* gdb.arch/amd64-gs_base.exp: New file.
>
> ---
>  gdb/amd64-linux-nat.c                       |  53 ++++++++
>  gdb/amd64-linux-tdep.c                      |   7 +-
>  gdb/amd64-linux-tdep.h                      |   2 +-
>  gdb/amd64-nat.c                             |  19 ++-
>  gdb/amd64-tdep.c                            |  13 ++
>  gdb/amd64-tdep.h                            |   6 +-
>  gdb/doc/gdb.texinfo                         |   3 +
>  gdb/features/Makefile                       |  17 +--
>  gdb/features/i386/64bit-segments.xml        |  12 ++
>  gdb/features/i386/amd64-avx-linux.c         |  36 +++---
>  gdb/features/i386/amd64-avx-linux.xml       |   1 +
>  gdb/features/i386/amd64-avx-mpx-linux.c     |  48 +++----
>  gdb/features/i386/amd64-avx-mpx-linux.xml   |   1 +
>  gdb/features/i386/amd64-avx512-linux.c      | 192 ++++++++++++++--------------
>  gdb/features/i386/amd64-avx512-linux.xml    |   1 +
>  gdb/features/i386/amd64-linux.c             |   4 +
>  gdb/features/i386/amd64-linux.xml           |   1 +
>  gdb/features/i386/amd64-mpx-linux.c         |  16 ++-
>  gdb/features/i386/amd64-mpx-linux.xml       |   1 +
>  gdb/features/i386/x32-avx-linux.c           |  36 +++---
>  gdb/features/i386/x32-avx-linux.xml         |   1 +
>  gdb/features/i386/x32-avx512-linux.c        | 192 ++++++++++++++--------------
>  gdb/features/i386/x32-avx512-linux.xml      |   1 +
>  gdb/features/i386/x32-linux.c               |   4 +
>  gdb/features/i386/x32-linux.xml             |   1 +
>  gdb/gdbserver/configure.srv                 |   2 +-
>  gdb/gdbserver/linux-x86-low.c               |  32 +++++
>  gdb/regformats/i386/amd64-avx-linux.dat     |   2 +
>  gdb/regformats/i386/amd64-avx-mpx-linux.dat |   2 +
>  gdb/regformats/i386/amd64-avx512-linux.dat  |   2 +
>  gdb/regformats/i386/amd64-linux.dat         |   2 +
>  gdb/regformats/i386/amd64-mpx-linux.dat     |   2 +
>  gdb/regformats/i386/x32-avx-linux.dat       |   2 +
>  gdb/regformats/i386/x32-avx512-linux.dat    |   2 +
>  gdb/regformats/i386/x32-linux.dat           |   2 +
>  gdb/testsuite/gdb.arch/amd64-gs_base.c      |  26 ++++
>  gdb/testsuite/gdb.arch/amd64-gs_base.exp    |  51 ++++++++
>  37 files changed, 531 insertions(+), 264 deletions(-)
>  create mode 100644 gdb/features/i386/64bit-segments.xml
>  create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.c
>  create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.exp
>
> diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
> index 4a2036b..0ec22cb 100644
> --- a/gdb/amd64-linux-nat.c
> +++ b/gdb/amd64-linux-nat.c
> @@ -40,6 +40,11 @@
>  #include "nat/linux-ptrace.h"
>  #include "nat/amd64-linux-siginfo.h"
>
> +/* This definition comes from prctl.h, but some kernels may not have it.  */

Would it be worth mentioning the version of the oldest kernel that 
carries this definition?

> +#ifndef PTRACE_ARCH_PRCTL
> +#define PTRACE_ARCH_PRCTL      30
> +#endif
> +
>  /* Mapping between the general-purpose registers in GNU/Linux x86-64
>     `struct user' format and GDB's register cache layout for GNU/Linux
>     i386.
> @@ -171,6 +176,30 @@ amd64_linux_fetch_inferior_registers (struct target_ops *ops,
>
>  	  amd64_supply_fxsave (regcache, -1, &fpregs);
>  	}
> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +      {
> +	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
> +	   fs_base and gs_base fields of user_regs_struct can be
> +	   used directly.  */
> +	unsigned long base;
> +
> +	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
> +	  {
> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_FS) < 0)
> +	      perror_with_name (_("Couldn't get segment register fs_base"));
> +
> +	    regcache_raw_supply (regcache, AMD64_FSBASE_REGNUM, &base);
> +	  }
> +
> +	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
> +	  {
> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_GS) < 0)
> +	      perror_with_name (_("Couldn't get segment register gs_base"));
> +
> +	    regcache_raw_supply (regcache, AMD64_GSBASE_REGNUM, &base);
> +	  }
> +      }
> +#endif
>      }
>  }
>
> @@ -237,6 +266,30 @@ amd64_linux_store_inferior_registers (struct target_ops *ops,
>  	  if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0)
>  	    perror_with_name (_("Couldn't write floating point status"));
>  	}
> +
> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +      {
> +	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
> +	   fs_base and gs_base fields of user_regs_struct can be
> +	   used directly.  */
> +	void *base;
> +
> +	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
> +	  {
> +	    regcache_raw_collect (regcache, AMD64_FSBASE_REGNUM, &base);
> +
> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_FS) < 0)
> +	      perror_with_name (_("Couldn't write fs_base"));

Nit, but should we make the messages more coherent?

"Couldn't write segment register fs_base" for example?

> +	  }
> +	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
> +	  {
> +
> +	    regcache_raw_collect (regcache, AMD64_GSBASE_REGNUM, &base);
> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_GS) < 0)
> +	      perror_with_name (_("Couldn't write gs_base"));
> +	  }
> +      }
> +#endif
>      }
>  }
>  \f
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 1e9f75f..b9d7176 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -103,6 +103,9 @@ int amd64_linux_gregset_reg_offset[] =
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
> +
> +  /* End of hardware registers */
> +  21 * 8, 22 * 8,		      /* fs_base and gs_base.  */
>    15 * 8			      /* "orig_rax" */
>  };
>  \f
> @@ -284,7 +287,9 @@ static int
>  amd64_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>  				 struct reggroup *group)
>  {
> -  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM)
> +  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM
> +      || regnum == AMD64_FSBASE_REGNUM
> +      || regnum == AMD64_GSBASE_REGNUM)
>      return (group == system_reggroup
>              || group == save_reggroup
>              || group == restore_reggroup);
> diff --git a/gdb/amd64-linux-tdep.h b/gdb/amd64-linux-tdep.h
> index 5d032a6..3704caa 100644
> --- a/gdb/amd64-linux-tdep.h
> +++ b/gdb/amd64-linux-tdep.h
> @@ -26,7 +26,7 @@
>  /* Register number for the "orig_rax" register.  If this register
>     contains a value >= 0 it is interpreted as the system call number
>     that the kernel is supposed to restart.  */
> -#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_ZMM31H_REGNUM + 1)
> +#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_NUM_REGS)
>
>  /* Total number of registers for GNU/Linux.  */
>  #define AMD64_LINUX_NUM_REGS (AMD64_LINUX_ORIG_RAX_REGNUM + 1)
> diff --git a/gdb/amd64-nat.c b/gdb/amd64-nat.c
> index 18c8a99..0143632 100644
> --- a/gdb/amd64-nat.c
> +++ b/gdb/amd64-nat.c
> @@ -53,6 +53,7 @@ amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum)
>  {
>    int *reg_offset = amd64_native_gregset64_reg_offset;
>    int num_regs = amd64_native_gregset64_num_regs;
> +  bool valid_regnum = false;
>
>    gdb_assert (regnum >= 0);
>
> @@ -65,10 +66,22 @@ amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum)
>    if (num_regs > gdbarch_num_regs (gdbarch))
>      num_regs = gdbarch_num_regs (gdbarch);
>
> -  if (regnum < num_regs && regnum < gdbarch_num_regs (gdbarch))
> -    return reg_offset[regnum];
> +  /* Looks like we do not need the second part of the &&.
> +     Register validity is already guaranteed in the first part due to the
> +     comparison above.  */

It looks that way. Can we remove that conditional block then and remove 
the comment?

> +  valid_regnum = regnum < num_regs && regnum < gdbarch_num_regs (gdbarch);
>
> -  return -1;
> +  if (valid_regnum == false)
> +    return -1;
> +
> +  /* Definition of the offset foresees new kernel support, it has to be
> +     corrected here in case the kernel is older.  */
> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +  if (regnum == AMD64_FSBASE_REGNUM || regnum == AMD64_GSBASE_REGNUM)
> +    return -1;
> +#endif
> +
> +  return reg_offset[regnum];
>  }
>
>  /* Return whether the native general-purpose register set supplies
> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
> index a636742..2588025 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -3047,6 +3047,19 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>        tdep->bnd0r_regnum = AMD64_BND0R_REGNUM;
>      }
>
> +  if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments") != NULL)
> +    {
> +      const struct tdesc_feature *feature =
> +	  tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments");
> +      struct tdesc_arch_data *tdesc_data_segments
> +      = (struct tdesc_arch_data *) info.tdep_info;
> +
> +      tdesc_numbered_register (feature, tdesc_data_segments,
> +		       AMD64_FSBASE_REGNUM, "fs_base");
> +      tdesc_numbered_register (feature, tdesc_data_segments,
> +		       AMD64_GSBASE_REGNUM, "gs_base");
> +    }
> +
>    tdep->num_byte_regs = 20;
>    tdep->num_word_regs = 16;
>    tdep->num_dword_regs = 16;
> diff --git a/gdb/amd64-tdep.h b/gdb/amd64-tdep.h
> index 3f84947..8ccf031 100644
> --- a/gdb/amd64-tdep.h
> +++ b/gdb/amd64-tdep.h
> @@ -76,13 +76,15 @@ enum amd64_regnum
>    AMD64_K0_REGNUM,
>    AMD64_K7_REGNUM = AMD64_K0_REGNUM + 7,
>    AMD64_ZMM0H_REGNUM,
> -  AMD64_ZMM31H_REGNUM = AMD64_ZMM0H_REGNUM + 31
> +  AMD64_ZMM31H_REGNUM = AMD64_ZMM0H_REGNUM + 31,
> +  AMD64_FSBASE_REGNUM,
> +  AMD64_GSBASE_REGNUM
>  };
>
>  /* Number of general purpose registers.  */
>  #define AMD64_NUM_GREGS		24
>
> -#define AMD64_NUM_REGS		(AMD64_ZMM31H_REGNUM + 1)
> +#define AMD64_NUM_REGS		(AMD64_GSBASE_REGNUM + 1)
>
>  extern struct target_desc *tdesc_amd64;
>
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 2b6b654..4e854ce 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -41148,6 +41148,9 @@ Memory Protection Extension (MPX).  It should describe the following registers:
>  The @samp{org.gnu.gdb.i386.linux} feature is optional.  It should
>  describe a single register, @samp{orig_eax}.
>
> +The @samp{org.gnu.gdb.i386.segments} feature is optional.  It should
> +describe two system registers: @samp{fs_base} and @samp{gs_base}.
> +
>  The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
>  @samp{org.gnu.gdb.i386.avx} feature.  It should
>  describe additional @sc{xmm} registers:
> diff --git a/gdb/features/Makefile b/gdb/features/Makefile
> index 63f8248..5a82641 100644
> --- a/gdb/features/Makefile
> +++ b/gdb/features/Makefile
> @@ -259,7 +259,7 @@ $(outdir)/i386/i386-linux.dat: i386/32bit-core.xml i386/32bit-sse.xml \
>  			       i386/32bit-linux.xml
>  $(outdir)/i386/amd64.dat: i386/64bit-core.xml i386/64bit-sse.xml
>  $(outdir)/i386/amd64-linux.dat: i386/64bit-core.xml i386/64bit-sse.xml \
> -			        i386/64bit-linux.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml
>  $(outdir)/i386/i386-avx.dat: i386/32bit-core.xml i386/32bit-avx.xml
>  $(outdir)/i386/i386-avx-linux.dat: i386/32bit-core.xml i386/32bit-avx.xml \
>  			       i386/32bit-linux.xml
> @@ -279,11 +279,11 @@ $(outdir)/i386/i386-mmx.dat: i386/32bit-core.xml
>  $(outdir)/i386/i386-mmx-linux.dat: i386/32bit-core.xml i386/32bit-linux.xml
>  $(outdir)/i386/amd64-avx.dat: i386/64bit-core.xml i386/64bit-avx.xml
>  $(outdir)/i386/amd64-avx-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
> -				    i386/64bit-linux.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml
>  $(outdir)/i386/amd64-mpx-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
> -			       i386/64bit-linux.xml i386/64bit-mpx.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml i386/64bit-mpx.xml
>  $(outdir)/i386/amd64-avx-mpx-linux.dat: i386/64bit-core.xml \
> -			       i386/64bit-linux.xml i386/64bit-mpx.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml i386/64bit-mpx.xml
>  $(outdir)/i386/amd64-mpx.dat: i386/64bit-core.xml i386/64bit-avx.xml \
>  			       i386/64bit-mpx.xml
>  $(outdir)/i386/amd64-avx-mpx.dat: i386/64bit-core.xml \
> @@ -292,17 +292,18 @@ $(outdir)/i386/amd64-avx512.dat: i386/64bit-core.xml i386/64bit-avx.xml \
>  			       i386/64bit-mpx.xml i386/64bit-avx512.xml
>  $(outdir)/i386/amd64-avx512-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
>  			       i386/64bit-mpx.xml i386/64bit-avx512.xml \
> -			       i386/64bit-linux.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml
>  $(outdir)/i386/x32.dat: i386/x32-core.xml i386/64bit-sse.xml
>  $(outdir)/i386/x32-linux.dat: i386/x32-core.xml i386/64bit-sse.xml \
> -			      i386/64bit-linux.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml
>  $(outdir)/i386/x32-avx.dat: i386/x32-core.xml i386/64bit-avx.xml
>  $(outdir)/i386/x32-avx-linux.dat: i386/x32-core.xml i386/64bit-avx.xml \
> -				  i386/64bit-linux.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml
>  $(outdir)/i386/x32-avx512.dat: i386/x32-core.xml i386/64bit-avx.xml \
>  			       i386/64bit-mpx.xml i386/64bit-avx512.xml
>  $(outdir)/i386/x32-avx512-linux.dat: i386/x32-core.xml i386/64bit-avx.xml \
> -			       i386/64bit-mpx.xml i386/64bit-avx512.xml i386/64bit-linux.xml
> +			       i386/64bit-mpx.xml i386/64bit-avx512.xml \
> +			       i386/64bit-linux.xml i386/64bit-segments.xml
>
>  # 'all' doesn't build the C files, so don't delete them in 'clean'
>  # either.
> diff --git a/gdb/features/i386/64bit-segments.xml b/gdb/features/i386/64bit-segments.xml
> new file mode 100644
> index 0000000..16c0929
> --- /dev/null
> +++ b/gdb/features/i386/64bit-segments.xml
> @@ -0,0 +1,12 @@
> +<?xml version="1.0"?>
> +<!-- Copyright (C) 2016 Free Software Foundation, Inc.

2017

> +
> +     Copying and distribution of this file, with or without modification,
> +     are permitted in any medium without royalty provided the copyright
> +     notice and this notice are preserved.  -->
> +
> +<!DOCTYPE feature SYSTEM "gdb-target.dtd">
> +<feature name="org.gnu.gdb.i386.segments">
> +  <reg name="fs_base" bitsize="64" type="int"/>
> +  <reg name="gs_base" bitsize="64" type="int"/>
> +</feature>
> diff --git a/gdb/features/i386/amd64-avx-linux.c b/gdb/features/i386/amd64-avx-linux.c
> index 9c8f9eb..1d56dbf 100644
> --- a/gdb/features/i386/amd64-avx-linux.c
> +++ b/gdb/features/i386/amd64-avx-linux.c
> @@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx_linux (void)
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
>    tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
>
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
> +  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
> +  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
> +
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
> -  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
>
>    tdesc_amd64_avx_linux = result;
>  }
> diff --git a/gdb/features/i386/amd64-avx-linux.xml b/gdb/features/i386/amd64-avx-linux.xml
> index 470dd55..2dac9cd 100644
> --- a/gdb/features/i386/amd64-avx-linux.xml
> +++ b/gdb/features/i386/amd64-avx-linux.xml
> @@ -14,5 +14,6 @@
>    <xi:include href="64bit-core.xml"/>
>    <xi:include href="64bit-sse.xml"/>
>    <xi:include href="64bit-linux.xml"/>
> +  <xi:include href="64bit-segments.xml"/>
>    <xi:include href="64bit-avx.xml"/>
>  </target>
> diff --git a/gdb/features/i386/amd64-avx-mpx-linux.c b/gdb/features/i386/amd64-avx-mpx-linux.c
> index 4605480..26c1339 100644
> --- a/gdb/features/i386/amd64-avx-mpx-linux.c
> +++ b/gdb/features/i386/amd64-avx-mpx-linux.c
> @@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx_mpx_linux (void)
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
>    tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
>
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
> +  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
> +  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
> +
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
> -  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
>
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
>    type = tdesc_create_struct (feature, "br128");
> @@ -200,12 +204,12 @@ initialize_tdesc_amd64_avx_mpx_linux (void)
>    field_type = tdesc_named_type (feature, "_bndcfgu");
>    tdesc_add_field (type, "config", field_type);
>
> -  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
> -  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
> +  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
> +  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
>
>    tdesc_amd64_avx_mpx_linux = result;
>  }
> diff --git a/gdb/features/i386/amd64-avx-mpx-linux.xml b/gdb/features/i386/amd64-avx-mpx-linux.xml
> index e29317f..433f777 100644
> --- a/gdb/features/i386/amd64-avx-mpx-linux.xml
> +++ b/gdb/features/i386/amd64-avx-mpx-linux.xml
> @@ -14,6 +14,7 @@
>    <xi:include href="64bit-core.xml"/>
>    <xi:include href="64bit-sse.xml"/>
>    <xi:include href="64bit-linux.xml"/>
> +  <xi:include href="64bit-segments.xml"/>
>    <xi:include href="64bit-avx.xml"/>
>    <xi:include href="64bit-mpx.xml"/>
>  </target>
> diff --git a/gdb/features/i386/amd64-avx512-linux.c b/gdb/features/i386/amd64-avx512-linux.c
> index ec3ba61..b071f62 100644
> --- a/gdb/features/i386/amd64-avx512-linux.c
> +++ b/gdb/features/i386/amd64-avx512-linux.c
> @@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx512_linux (void)
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
>    tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
>
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
> +  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
> +  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
> +
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
> -  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
>
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
>    type = tdesc_create_struct (feature, "br128");
> @@ -200,12 +204,12 @@ initialize_tdesc_amd64_avx512_linux (void)
>    field_type = tdesc_named_type (feature, "_bndcfgu");
>    tdesc_add_field (type, "config", field_type);
>
> -  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
> -  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
> +  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
> +  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
>
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
>    field_type = tdesc_named_type (feature, "ieee_single");
> @@ -245,78 +249,78 @@ initialize_tdesc_amd64_avx512_linux (void)
>    field_type = tdesc_named_type (feature, "uint128");
>    tdesc_create_vector (feature, "v2ui128", field_type, 2);
>
> -  tdesc_create_reg (feature, "xmm16", 80, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm17", 81, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm18", 82, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm19", 83, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm20", 84, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm21", 85, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm22", 86, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm23", 87, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm24", 88, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm25", 89, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm26", 90, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm27", 91, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm28", 92, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm29", 93, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm30", 94, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm31", 95, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "ymm16h", 96, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm17h", 97, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm18h", 98, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm19h", 99, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm20h", 100, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm21h", 101, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm22h", 102, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm23h", 103, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm24h", 104, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm25h", 105, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm26h", 106, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm27h", 107, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm28h", 108, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm29h", 109, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm30h", 110, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm31h", 111, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "k0", 112, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k1", 113, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k2", 114, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k3", 115, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k4", 116, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k5", 117, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k6", 118, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k7", 119, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "zmm0h", 120, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm1h", 121, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm2h", 122, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm3h", 123, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm4h", 124, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm5h", 125, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm6h", 126, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm7h", 127, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm8h", 128, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm9h", 129, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm10h", 130, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm11h", 131, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm12h", 132, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm13h", 133, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm14h", 134, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm15h", 135, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm16h", 136, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm17h", 137, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm18h", 138, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm19h", 139, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm20h", 140, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm21h", 141, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm22h", 142, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm23h", 143, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm24h", 144, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm25h", 145, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm26h", 146, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm27h", 147, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm28h", 148, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm29h", 149, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm30h", 150, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm31h", 151, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "xmm16", 82, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm17", 83, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm18", 84, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm19", 85, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm20", 86, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm21", 87, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm22", 88, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm23", 89, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm24", 90, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm25", 91, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm26", 92, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm27", 93, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm28", 94, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm29", 95, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm30", 96, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm31", 97, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "ymm16h", 98, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm17h", 99, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm18h", 100, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm19h", 101, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm20h", 102, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm21h", 103, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm22h", 104, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm23h", 105, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm24h", 106, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm25h", 107, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm26h", 108, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm27h", 109, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm28h", 110, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm29h", 111, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm30h", 112, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm31h", 113, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "k0", 114, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k1", 115, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k2", 116, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k3", 117, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k4", 118, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k5", 119, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k6", 120, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k7", 121, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "zmm0h", 122, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm1h", 123, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm2h", 124, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm3h", 125, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm4h", 126, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm5h", 127, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm6h", 128, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm7h", 129, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm8h", 130, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm9h", 131, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm10h", 132, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm11h", 133, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm12h", 134, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm13h", 135, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm14h", 136, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm15h", 137, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm16h", 138, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm17h", 139, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm18h", 140, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm19h", 141, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm20h", 142, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm21h", 143, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm22h", 144, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm23h", 145, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm24h", 146, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm25h", 147, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm26h", 148, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm27h", 149, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm28h", 150, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm29h", 151, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm30h", 152, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm31h", 153, 1, NULL, 256, "v2ui128");
>
>    tdesc_amd64_avx512_linux = result;
>  }
> diff --git a/gdb/features/i386/amd64-avx512-linux.xml b/gdb/features/i386/amd64-avx512-linux.xml
> index 2ee2e8b..516f4e3 100644
> --- a/gdb/features/i386/amd64-avx512-linux.xml
> +++ b/gdb/features/i386/amd64-avx512-linux.xml
> @@ -14,6 +14,7 @@
>    <xi:include href="64bit-core.xml"/>
>    <xi:include href="64bit-sse.xml"/>
>    <xi:include href="64bit-linux.xml"/>
> +  <xi:include href="64bit-segments.xml"/>
>    <xi:include href="64bit-avx.xml"/>
>    <xi:include href="64bit-mpx.xml"/>
>    <xi:include href="64bit-avx512.xml"/>
> diff --git a/gdb/features/i386/amd64-linux.c b/gdb/features/i386/amd64-linux.c
> index 02aeba5..0e921ba9 100644
> --- a/gdb/features/i386/amd64-linux.c
> +++ b/gdb/features/i386/amd64-linux.c
> @@ -151,5 +151,9 @@ initialize_tdesc_amd64_linux (void)
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
>    tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
>
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
> +  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
> +  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
> +
>    tdesc_amd64_linux = result;
>  }
> diff --git a/gdb/features/i386/amd64-linux.xml b/gdb/features/i386/amd64-linux.xml
> index 2ce9341..7d3a9f2 100644
> --- a/gdb/features/i386/amd64-linux.xml
> +++ b/gdb/features/i386/amd64-linux.xml
> @@ -14,4 +14,5 @@
>    <xi:include href="64bit-core.xml"/>
>    <xi:include href="64bit-sse.xml"/>
>    <xi:include href="64bit-linux.xml"/>
> +  <xi:include href="64bit-segments.xml"/>
>  </target>
> diff --git a/gdb/features/i386/amd64-mpx-linux.c b/gdb/features/i386/amd64-mpx-linux.c
> index a20ca4f..e26a74a 100644
> --- a/gdb/features/i386/amd64-mpx-linux.c
> +++ b/gdb/features/i386/amd64-mpx-linux.c
> @@ -151,6 +151,10 @@ initialize_tdesc_amd64_mpx_linux (void)
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
>    tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
>
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
> +  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
> +  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
> +
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
>    type = tdesc_create_struct (feature, "br128");
>    field_type = tdesc_named_type (feature, "uint64");
> @@ -182,12 +186,12 @@ initialize_tdesc_amd64_mpx_linux (void)
>    field_type = tdesc_named_type (feature, "_bndcfgu");
>    tdesc_add_field (type, "config", field_type);
>
> -  tdesc_create_reg (feature, "bnd0raw", 58, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd1raw", 59, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd2raw", 60, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd3raw", 61, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bndcfgu", 62, 1, NULL, 64, "cfgu");
> -  tdesc_create_reg (feature, "bndstatus", 63, 1, NULL, 64, "status");
> +  tdesc_create_reg (feature, "bnd0raw", 60, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd1raw", 61, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd2raw", 62, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd3raw", 63, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bndcfgu", 64, 1, NULL, 64, "cfgu");
> +  tdesc_create_reg (feature, "bndstatus", 65, 1, NULL, 64, "status");
>
>    tdesc_amd64_mpx_linux = result;
>  }
> diff --git a/gdb/features/i386/amd64-mpx-linux.xml b/gdb/features/i386/amd64-mpx-linux.xml
> index 9c7cf9a..853b819 100644
> --- a/gdb/features/i386/amd64-mpx-linux.xml
> +++ b/gdb/features/i386/amd64-mpx-linux.xml
> @@ -14,5 +14,6 @@
>    <xi:include href="64bit-core.xml"/>
>    <xi:include href="64bit-sse.xml"/>
>    <xi:include href="64bit-linux.xml"/>
> +  <xi:include href="64bit-segments.xml"/>
>    <xi:include href="64bit-mpx.xml"/>
>  </target>
> diff --git a/gdb/features/i386/x32-avx-linux.c b/gdb/features/i386/x32-avx-linux.c
> index b12c71c..8406815 100644
> --- a/gdb/features/i386/x32-avx-linux.c
> +++ b/gdb/features/i386/x32-avx-linux.c
> @@ -151,23 +151,27 @@ initialize_tdesc_x32_avx_linux (void)
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
>    tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
>
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
> +  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
> +  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
> +
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
> -  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
>
>    tdesc_x32_avx_linux = result;
>  }
> diff --git a/gdb/features/i386/x32-avx-linux.xml b/gdb/features/i386/x32-avx-linux.xml
> index f60a443..89d2e7c 100644
> --- a/gdb/features/i386/x32-avx-linux.xml
> +++ b/gdb/features/i386/x32-avx-linux.xml
> @@ -14,5 +14,6 @@
>    <xi:include href="x32-core.xml"/>
>    <xi:include href="64bit-sse.xml"/>
>    <xi:include href="64bit-linux.xml"/>
> +  <xi:include href="64bit-segments.xml"/>
>    <xi:include href="64bit-avx.xml"/>
>  </target>
> diff --git a/gdb/features/i386/x32-avx512-linux.c b/gdb/features/i386/x32-avx512-linux.c
> index 7b2ab90..3994996 100644
> --- a/gdb/features/i386/x32-avx512-linux.c
> +++ b/gdb/features/i386/x32-avx512-linux.c
> @@ -151,23 +151,27 @@ initialize_tdesc_x32_avx512_linux (void)
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
>    tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
>
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
> +  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
> +  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
> +
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
> -  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
>
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
>    type = tdesc_create_struct (feature, "br128");
> @@ -200,12 +204,12 @@ initialize_tdesc_x32_avx512_linux (void)
>    field_type = tdesc_named_type (feature, "_bndcfgu");
>    tdesc_add_field (type, "config", field_type);
>
> -  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
> -  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
> -  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
> +  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
> +  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
> +  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
>
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
>    field_type = tdesc_named_type (feature, "ieee_single");
> @@ -245,78 +249,78 @@ initialize_tdesc_x32_avx512_linux (void)
>    field_type = tdesc_named_type (feature, "uint128");
>    tdesc_create_vector (feature, "v2ui128", field_type, 2);
>
> -  tdesc_create_reg (feature, "xmm16", 80, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm17", 81, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm18", 82, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm19", 83, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm20", 84, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm21", 85, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm22", 86, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm23", 87, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm24", 88, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm25", 89, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm26", 90, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm27", 91, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm28", 92, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm29", 93, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm30", 94, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "xmm31", 95, 1, NULL, 128, "vec128");
> -  tdesc_create_reg (feature, "ymm16h", 96, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm17h", 97, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm18h", 98, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm19h", 99, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm20h", 100, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm21h", 101, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm22h", 102, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm23h", 103, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm24h", 104, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm25h", 105, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm26h", 106, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm27h", 107, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm28h", 108, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm29h", 109, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm30h", 110, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "ymm31h", 111, 1, NULL, 128, "uint128");
> -  tdesc_create_reg (feature, "k0", 112, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k1", 113, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k2", 114, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k3", 115, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k4", 116, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k5", 117, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k6", 118, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "k7", 119, 1, NULL, 64, "uint64");
> -  tdesc_create_reg (feature, "zmm0h", 120, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm1h", 121, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm2h", 122, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm3h", 123, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm4h", 124, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm5h", 125, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm6h", 126, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm7h", 127, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm8h", 128, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm9h", 129, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm10h", 130, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm11h", 131, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm12h", 132, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm13h", 133, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm14h", 134, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm15h", 135, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm16h", 136, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm17h", 137, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm18h", 138, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm19h", 139, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm20h", 140, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm21h", 141, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm22h", 142, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm23h", 143, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm24h", 144, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm25h", 145, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm26h", 146, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm27h", 147, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm28h", 148, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm29h", 149, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm30h", 150, 1, NULL, 256, "v2ui128");
> -  tdesc_create_reg (feature, "zmm31h", 151, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "xmm16", 82, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm17", 83, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm18", 84, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm19", 85, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm20", 86, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm21", 87, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm22", 88, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm23", 89, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm24", 90, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm25", 91, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm26", 92, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm27", 93, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm28", 94, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm29", 95, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm30", 96, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "xmm31", 97, 1, NULL, 128, "vec128");
> +  tdesc_create_reg (feature, "ymm16h", 98, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm17h", 99, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm18h", 100, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm19h", 101, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm20h", 102, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm21h", 103, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm22h", 104, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm23h", 105, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm24h", 106, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm25h", 107, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm26h", 108, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm27h", 109, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm28h", 110, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm29h", 111, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm30h", 112, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "ymm31h", 113, 1, NULL, 128, "uint128");
> +  tdesc_create_reg (feature, "k0", 114, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k1", 115, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k2", 116, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k3", 117, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k4", 118, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k5", 119, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k6", 120, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "k7", 121, 1, NULL, 64, "uint64");
> +  tdesc_create_reg (feature, "zmm0h", 122, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm1h", 123, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm2h", 124, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm3h", 125, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm4h", 126, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm5h", 127, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm6h", 128, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm7h", 129, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm8h", 130, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm9h", 131, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm10h", 132, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm11h", 133, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm12h", 134, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm13h", 135, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm14h", 136, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm15h", 137, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm16h", 138, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm17h", 139, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm18h", 140, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm19h", 141, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm20h", 142, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm21h", 143, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm22h", 144, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm23h", 145, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm24h", 146, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm25h", 147, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm26h", 148, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm27h", 149, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm28h", 150, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm29h", 151, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm30h", 152, 1, NULL, 256, "v2ui128");
> +  tdesc_create_reg (feature, "zmm31h", 153, 1, NULL, 256, "v2ui128");
>
>    tdesc_x32_avx512_linux = result;
>  }
> diff --git a/gdb/features/i386/x32-avx512-linux.xml b/gdb/features/i386/x32-avx512-linux.xml
> index 73238dc..7266c8e 100644
> --- a/gdb/features/i386/x32-avx512-linux.xml
> +++ b/gdb/features/i386/x32-avx512-linux.xml
> @@ -14,6 +14,7 @@
>    <xi:include href="x32-core.xml"/>
>    <xi:include href="64bit-sse.xml"/>
>    <xi:include href="64bit-linux.xml"/>
> +  <xi:include href="64bit-segments.xml"/>
>    <xi:include href="64bit-avx.xml"/>
>    <xi:include href="64bit-mpx.xml"/>
>    <xi:include href="64bit-avx512.xml"/>
> diff --git a/gdb/features/i386/x32-linux.c b/gdb/features/i386/x32-linux.c
> index 1262688..ae49549 100644
> --- a/gdb/features/i386/x32-linux.c
> +++ b/gdb/features/i386/x32-linux.c
> @@ -151,5 +151,9 @@ initialize_tdesc_x32_linux (void)
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
>    tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
>
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
> +  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
> +  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
> +
>    tdesc_x32_linux = result;
>  }
> diff --git a/gdb/features/i386/x32-linux.xml b/gdb/features/i386/x32-linux.xml
> index a7d0899..023a48d 100644
> --- a/gdb/features/i386/x32-linux.xml
> +++ b/gdb/features/i386/x32-linux.xml
> @@ -14,4 +14,5 @@
>    <xi:include href="x32-core.xml"/>
>    <xi:include href="64bit-sse.xml"/>
>    <xi:include href="64bit-linux.xml"/>
> +  <xi:include href="64bit-segments.xml"/>
>  </target>
> diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
> index 3267599..d03dcb9 100644
> --- a/gdb/gdbserver/configure.srv
> +++ b/gdb/gdbserver/configure.srv
> @@ -35,7 +35,7 @@ ipa_x32_linux_regobj="x32-linux-ipa.o x32-avx-linux-ipa.o x32-avx512-linux-ipa.o
>  ipa_ppc_linux_regobj="powerpc-32l-ipa.o powerpc-altivec32l-ipa.o powerpc-cell32l-ipa.o powerpc-vsx32l-ipa.o powerpc-isa205-32l-ipa.o powerpc-isa205-altivec32l-ipa.o powerpc-isa205-vsx32l-ipa.o powerpc-e500l-ipa.o powerpc-64l-ipa.o powerpc-altivec64l-ipa.o powerpc-cell64l-ipa.o powerpc-vsx64l-ipa.o powerpc-isa205-64l-ipa.o powerpc-isa205-altivec64l-ipa.o powerpc-isa205-vsx64l-ipa.o"
>
>  srv_i386_32bit_xmlfiles="i386/32bit-core.xml i386/32bit-sse.xml i386/32bit-avx.xml i386/32bit-avx512.xml i386/32bit-mpx.xml"
> -srv_i386_64bit_xmlfiles="i386/64bit-core.xml i386/64bit-sse.xml i386/64bit-avx.xml i386/64bit-avx512.xml i386/x32-core.xml i386/64bit-mpx.xml"
> +srv_i386_64bit_xmlfiles="i386/64bit-core.xml i386/64bit-segments.xml i386/64bit-sse.xml i386/64bit-avx.xml i386/64bit-avx512.xml i386/x32-core.xml i386/64bit-mpx.xml"
>  srv_i386_xmlfiles="i386/i386.xml i386/i386-avx.xml i386/i386-avx512.xml i386/i386-mpx.xml i386/i386-avx-mpx.xml i386/i386-mmx.xml $srv_i386_32bit_xmlfiles"
>  srv_amd64_xmlfiles="i386/amd64.xml i386/amd64-avx.xml i386/amd64-avx512.xml i386/x32.xml i386/x32-avx.xml i386/x32-avx512.xml i386/amd64-mpx.xml i386/amd64-avx-mpx.xml  $srv_i386_64bit_xmlfiles"
>  srv_i386_linux_xmlfiles="i386/i386-linux.xml i386/i386-avx-linux.xml i386/i386-avx512-linux.xml i386/i386-mmx-linux.xml i386/32bit-linux.xml i386/i386-mpx-linux.xml i386/i386-avx-mpx-linux.xml $srv_i386_32bit_xmlfiles"
> diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
> index dd9538a..8fdf324 100644
> --- a/gdb/gdbserver/linux-x86-low.c
> +++ b/gdb/gdbserver/linux-x86-low.c
> @@ -133,6 +133,11 @@ static const int x86_64_regmap[] =
>    -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    ORIG_RAX * 8,
> +#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +  21 * 8,  22 * 8,
> +#else
> +  -1, -1,
> +#endif
>    -1, -1, -1, -1,			/* MPX registers BND0 ... BND3.  */
>    -1, -1,				/* MPX registers BNDCFGU, BNDSTATUS.  */
>    -1, -1, -1, -1, -1, -1, -1, -1,       /* xmm16 ... xmm31 (AVX512)  */
> @@ -306,6 +311,20 @@ x86_fill_gregset (struct regcache *regcache, void *buf)
>        for (i = 0; i < X86_64_NUM_REGS; i++)
>  	if (x86_64_regmap[i] != -1)
>  	  collect_register (regcache, i, ((char *) buf) + x86_64_regmap[i]);
> +
> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +      {
> +        unsigned long base;
> +        int lwpid = lwpid_of (current_thread);
> +
> +        collect_register_by_name (regcache, "fs_base", &base);
> +        ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_SET_FS);
> +
> +        collect_register_by_name (regcache, "gs_base", &base);
> +        ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_SET_GS);
> +      }
> +#endif
> +
>        return;
>      }
>
> @@ -332,6 +351,19 @@ x86_store_gregset (struct regcache *regcache, const void *buf)
>        for (i = 0; i < X86_64_NUM_REGS; i++)
>  	if (x86_64_regmap[i] != -1)
>  	  supply_register (regcache, i, ((char *) buf) + x86_64_regmap[i]);
> +
> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +      {
> +        unsigned long base;
> +        int lwpid = lwpid_of (current_thread);
> +
> +        if (ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_GET_FS) == 0)
> +          supply_register_by_name (regcache, "fs_base", &base);
> +
> +        if (ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_GET_GS) == 0)
> +          supply_register_by_name (regcache, "gs_base", &base);
> +      }
> +#endif
>        return;
>      }
>  #endif
> diff --git a/gdb/regformats/i386/amd64-avx-linux.dat b/gdb/regformats/i386/amd64-avx-linux.dat
> index d8199da..7780b3b 100644
> --- a/gdb/regformats/i386/amd64-avx-linux.dat
> +++ b/gdb/regformats/i386/amd64-avx-linux.dat
> @@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
>  128:xmm15
>  32:mxcsr
>  64:orig_rax
> +64:fs_base
> +64:gs_base
>  128:ymm0h
>  128:ymm1h
>  128:ymm2h
> diff --git a/gdb/regformats/i386/amd64-avx-mpx-linux.dat b/gdb/regformats/i386/amd64-avx-mpx-linux.dat
> index 6d45324..7c2f928 100644
> --- a/gdb/regformats/i386/amd64-avx-mpx-linux.dat
> +++ b/gdb/regformats/i386/amd64-avx-mpx-linux.dat
> @@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
>  128:xmm15
>  32:mxcsr
>  64:orig_rax
> +64:fs_base
> +64:gs_base
>  128:ymm0h
>  128:ymm1h
>  128:ymm2h
> diff --git a/gdb/regformats/i386/amd64-avx512-linux.dat b/gdb/regformats/i386/amd64-avx512-linux.dat
> index dfc41e2..f1658d3 100644
> --- a/gdb/regformats/i386/amd64-avx512-linux.dat
> +++ b/gdb/regformats/i386/amd64-avx512-linux.dat
> @@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
>  128:xmm15
>  32:mxcsr
>  64:orig_rax
> +64:fs_base
> +64:gs_base
>  128:ymm0h
>  128:ymm1h
>  128:ymm2h
> diff --git a/gdb/regformats/i386/amd64-linux.dat b/gdb/regformats/i386/amd64-linux.dat
> index 6914cc4..cd16a15 100644
> --- a/gdb/regformats/i386/amd64-linux.dat
> +++ b/gdb/regformats/i386/amd64-linux.dat
> @@ -61,3 +61,5 @@ expedite:rbp,rsp,rip
>  128:xmm15
>  32:mxcsr
>  64:orig_rax
> +64:fs_base
> +64:gs_base
> diff --git a/gdb/regformats/i386/amd64-mpx-linux.dat b/gdb/regformats/i386/amd64-mpx-linux.dat
> index 523ae01..10487f6 100644
> --- a/gdb/regformats/i386/amd64-mpx-linux.dat
> +++ b/gdb/regformats/i386/amd64-mpx-linux.dat
> @@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
>  128:xmm15
>  32:mxcsr
>  64:orig_rax
> +64:fs_base
> +64:gs_base
>  128:bnd0raw
>  128:bnd1raw
>  128:bnd2raw
> diff --git a/gdb/regformats/i386/x32-avx-linux.dat b/gdb/regformats/i386/x32-avx-linux.dat
> index a2b8d02..eb0e3953 100644
> --- a/gdb/regformats/i386/x32-avx-linux.dat
> +++ b/gdb/regformats/i386/x32-avx-linux.dat
> @@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
>  128:xmm15
>  32:mxcsr
>  64:orig_rax
> +64:fs_base
> +64:gs_base
>  128:ymm0h
>  128:ymm1h
>  128:ymm2h
> diff --git a/gdb/regformats/i386/x32-avx512-linux.dat b/gdb/regformats/i386/x32-avx512-linux.dat
> index 0f5b2ce..0b7f73a 100644
> --- a/gdb/regformats/i386/x32-avx512-linux.dat
> +++ b/gdb/regformats/i386/x32-avx512-linux.dat
> @@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
>  128:xmm15
>  32:mxcsr
>  64:orig_rax
> +64:fs_base
> +64:gs_base
>  128:ymm0h
>  128:ymm1h
>  128:ymm2h
> diff --git a/gdb/regformats/i386/x32-linux.dat b/gdb/regformats/i386/x32-linux.dat
> index d976a25..eee378f 100644
> --- a/gdb/regformats/i386/x32-linux.dat
> +++ b/gdb/regformats/i386/x32-linux.dat
> @@ -61,3 +61,5 @@ expedite:rbp,rsp,rip
>  128:xmm15
>  32:mxcsr
>  64:orig_rax
> +64:fs_base
> +64:gs_base
> diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.c b/gdb/testsuite/gdb.arch/amd64-gs_base.c
> new file mode 100644
> index 0000000..d0a2a8f
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.c
> @@ -0,0 +1,26 @@
> +/* Test program for fs_base and gs_base.
> +
> +   Copyright 2016 Free Software Foundation, Inc.
> +

2017

> +   This file is part of GDB.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +int
> +main (void)
> +{
> +  volatile int a;
> +  a = 10;
> +  return a;
> +}
> diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.exp b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
> new file mode 100644
> index 0000000..f2dc887
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
> @@ -0,0 +1,51 @@
> +# Copyright 2016 Free Software Foundation, Inc.
> +

2017

> +# Contributed by Intel Corp. <walfred.tedeschi@intel.com>
> +

As discussed recently, these contribution notices should be moved to the 
manual if one wishes to expose it.

> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +standard_testfile
> +
> +if { ![istarget "x86_64-*linux*"] } then {
> +    verbose "Skipping x86_64 fs_base and gs_base tests."

I think untested would be better here.

> +    return
> +}
> +
> +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \

"failed to prepare" as opposed to ${testfile}.exp

> +     [list debug nowarnings]] } {
> +    return -1
> +}
> +
> +if ![runto_main] {
> +    untested "could not run to main"
> +    return -1
> +}
> +
> +gdb_test "print /x \$fs_base" "= $hex" "print fs_base"
> +gdb_test "print /x \$gs_base" "= $hex" "print gs_base"
> +
> +gdb_test "print \$fs_base = 2" "= 2" "set fs_base"
> +gdb_test "print \$gs_base = 3" "= 3" "set gs_base"
> +
> +# Test the presence of fs_base and gs_base on the system
> +# register group and values.
> +#
> +set ws "\[\t \]*"
> +set info_reg_out [multi_line "info register sys" \
> +          "fs_base${ws}0x2${ws}2"\
> +          "gs_base${ws}0x3${ws}3"\
> +          "orig_rax${ws}$hex${ws}\[-\]$decimal" ]
> +
> +gdb_test "info register sys" $info_reg_out\
> +   "info registers fs_base and gs_base with value"
>

Otherwise i have no further comments.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/1] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2017-01-05 15:53 [PATCH V2 1/1] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
  2017-01-09 20:35 ` Luis Machado
@ 2017-01-19 19:45 ` Pedro Alves
  2017-01-20 14:29   ` Tedeschi, Walfred
  1 sibling, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2017-01-19 19:45 UTC (permalink / raw)
  To: Walfred Tedeschi, brobecker; +Cc: gdb-patches

Hi Walfred,

On 01/05/2017 03:53 PM, Walfred Tedeschi wrote:

> orig_rax is the last register added there is a special macro that defines
> it in this way. On gdbserver side it is defined in the middle of
> the registers and stays there always for compatibility.

For compatibility with what?

(I think some punctuation in the first sentence would make it
much easier to grok.)

> I have added the two new registers just after the orig_rax.  This causes
> that they will be in the gdbserver side just after orig_rax and in gdb

in gdb [...] ?

> 
> I still can add then where I would prefer, the definition is
> done by the macros defining AMD64_FSBASE_REGNUM. 

I don't understand what you mean.  What would you prefer?

> In this sense they have
> been added just before the orig_rax.
> 
> This decision was taken based on the fact that we would like to add
> hardware registers as usual before the orig_rax, and with this addition
> also before the fs_base and gs_base.

But the gdb register numbers have no bearing on what the user
sees?  It's the order in the target description that
matters, isn't it?

Maybe what you're saying is this:

> --- a/gdb/amd64-linux-tdep.h
> +++ b/gdb/amd64-linux-tdep.h
> @@ -26,7 +26,7 @@
>  /* Register number for the "orig_rax" register.  If this register
>     contains a value >= 0 it is interpreted as the system call number
>     that the kernel is supposed to restart.  */
> -#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_ZMM31H_REGNUM + 1)
> +#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_NUM_REGS)

... AFAICS, AMD64_LINUX_ORIG_RAX_REGNUM is defined as the
register that follows the last register defined in 
amd64-tdep.h, which is always AMD64_NUM_REGS.  I.e., first
we define the "common" registers, and then the
Linux-specific "virtual" registers.

So this this change above makes it simpler to add new
amd64-generic registers without having to remember to
change amd64-linux-tdep.h.  Right?  If that was split into
a small preparatory patch with a rationale like that, it'd
have been much clearer, I think.

> 
> 
> 2017-01-05  Walfred Tedeschi  <walfred.tedeschi@intel.com>
> 	    Richard Henderson  <rth@redhat.com>
> 
> gdb/ChangeLog:
> 
> 	* amd64-linux-nat.c (PTRACE_ARCH_PRCTL): New define.
> 	(amd64_linux_fetch_inferior_registers): Add case to fetch FS_BASE
> 	GS_BASE for older kernels.
> 	(amd64_linux_store_inferior_registers): Add case to store FS_BASE
> 	GS_BASE for older kernels.
> 	* amd64-linux-tdep.c (amd64_linux_gregset_reg_offset): Add FS_BASE
> 	and GS_BASE to the offset table.
> 	(amd64_linux_register_reggroup_p): Add FS_BASE and GS_BASE to the
> 	system register group.
> 	* amd64-linux-tdep.h (AMD64_LINUX_ORIG_RAX_REGNUM): Set the value
> 	to AMD64_NUM_REGS.
> 	* amd64-nat.c (amd64_native_gregset_reg_offset): Adds valid_regnum
> 	to test validit of the register.  Implements case for older
> 	kernels.
> 	* amd64-tdep.c (amd64_init_abi): Add segment registers for the
> 	amd64 ABI.
> 	* amd64-tdep.h (amd64_regnum): Add AMD64_FSBASE_REGNUM and
> 	AMD64_GSBASE_REGNUM.
> 	(AMD64_NUM_REGS): Set to AMD64_GSBASE_REGNUM + 1.
> 	* features/Makefile (amd64-linux.dat, amd64-avx-linux.dat)
> 	(amd64-mpx-linux.dat, amd64-avx512-linux.dat, x32-linux.dat)
> 	(x32-avx-linux.dat, x32-avx512-linux.dat): Add
> 	i386/64bit-segments.xml in those rules.
> 	* features/i386/64bit-segments.xml: New file.
> 	* features/i386/amd64-avx-mpx-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-avx-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-avx512-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-mpx-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/x32-avx512-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/x32-avx-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-linux.xml: Add 64bit-segments.xml.
> 	* features/i386/amd64-avx-linux.c: Regenerated.
> 	* features/i386/amd64-avx-mpx-linux.c: Regenerated.
> 	* features/i386/amd64-avx-mpx.c: Regenerated.
> 	* features/i386/amd64-avx512-linux.c: Regenerated.
> 	* features/i386/amd64-linux.c: Regenerated.
> 	* features/i386/amd64-mpx-linux.c: Regenerated.
> 	* features/i386/i386-avx-mpx-linux.c: Regenerated.
> 	* features/i386/i386-avx-mpx.c: Regenerated.
> 	* features/i386/x32-avx-linux.c: Regenerated.
> 	* features/i386/x32-avx512-linux.c: Regenerated.
> 	* regformats/i386/amd64-avx-linux.dat: Regenerated.
> 	* regformats/i386/amd64-avx-mpx-linux.dat: Regenerated.
> 	* regformats/i386/amd64-avx512-linux.dat: Regenerated.
> 	* regformats/i386/amd64-linux.dat: Regenerated.
> 	* regformats/i386/amd64-mpx-linux.dat: Regenerated.
> 	* regformats/i386/x32-avx-linux.dat: Regenerated.
> 	* regformats/i386/x32-avx512-linux.dat: Regenerated.
> 	* regformats/i386/x32-linux.dat: Regenerated.
> 
> gdb/doc/ChangeLog:
> 
> 	* gdb.texinfo (i386 Features): Add system segment registers
> 	as feature.
> 
> gdb/gdbserver/ChangeLog:
> 
> 	* linux-x86-low.c (x86_64_regmap): Add fs_base and gs_base
> 	to the register table.
> 	(x86_fill_gregset): Add support for old kernels for the
> 	fs_base and gs_base system registers.
> 	(x86_store_gregset): Likewise.
> 	* configure.srv (srv_i386_64bit_xmlfiles): Add 64bit-segments.xml.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.arch/amd64-gs_base.c: New file.
> 	* gdb.arch/amd64-gs_base.exp: New file.
> 
> ---
>  gdb/amd64-linux-nat.c                       |  53 ++++++++
>  gdb/amd64-linux-tdep.c                      |   7 +-
>  gdb/amd64-linux-tdep.h                      |   2 +-
>  gdb/amd64-nat.c                             |  19 ++-
>  gdb/amd64-tdep.c                            |  13 ++
>  gdb/amd64-tdep.h                            |   6 +-
>  gdb/doc/gdb.texinfo                         |   3 +
>  gdb/features/Makefile                       |  17 +--
>  gdb/features/i386/64bit-segments.xml        |  12 ++
>  gdb/features/i386/amd64-avx-linux.c         |  36 +++---
>  gdb/features/i386/amd64-avx-linux.xml       |   1 +
>  gdb/features/i386/amd64-avx-mpx-linux.c     |  48 +++----
>  gdb/features/i386/amd64-avx-mpx-linux.xml   |   1 +
>  gdb/features/i386/amd64-avx512-linux.c      | 192 ++++++++++++++--------------
>  gdb/features/i386/amd64-avx512-linux.xml    |   1 +
>  gdb/features/i386/amd64-linux.c             |   4 +
>  gdb/features/i386/amd64-linux.xml           |   1 +
>  gdb/features/i386/amd64-mpx-linux.c         |  16 ++-
>  gdb/features/i386/amd64-mpx-linux.xml       |   1 +
>  gdb/features/i386/x32-avx-linux.c           |  36 +++---
>  gdb/features/i386/x32-avx-linux.xml         |   1 +
>  gdb/features/i386/x32-avx512-linux.c        | 192 ++++++++++++++--------------
>  gdb/features/i386/x32-avx512-linux.xml      |   1 +
>  gdb/features/i386/x32-linux.c               |   4 +
>  gdb/features/i386/x32-linux.xml             |   1 +
>  gdb/gdbserver/configure.srv                 |   2 +-
>  gdb/gdbserver/linux-x86-low.c               |  32 +++++
>  gdb/regformats/i386/amd64-avx-linux.dat     |   2 +
>  gdb/regformats/i386/amd64-avx-mpx-linux.dat |   2 +
>  gdb/regformats/i386/amd64-avx512-linux.dat  |   2 +
>  gdb/regformats/i386/amd64-linux.dat         |   2 +
>  gdb/regformats/i386/amd64-mpx-linux.dat     |   2 +
>  gdb/regformats/i386/x32-avx-linux.dat       |   2 +
>  gdb/regformats/i386/x32-avx512-linux.dat    |   2 +
>  gdb/regformats/i386/x32-linux.dat           |   2 +
>  gdb/testsuite/gdb.arch/amd64-gs_base.c      |  26 ++++
>  gdb/testsuite/gdb.arch/amd64-gs_base.exp    |  51 ++++++++
>  37 files changed, 531 insertions(+), 264 deletions(-)
>  create mode 100644 gdb/features/i386/64bit-segments.xml
>  create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.c
>  create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.exp
> 
> diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
> index 4a2036b..0ec22cb 100644
> --- a/gdb/amd64-linux-nat.c
> +++ b/gdb/amd64-linux-nat.c
> @@ -40,6 +40,11 @@
>  #include "nat/linux-ptrace.h"
>  #include "nat/amd64-linux-siginfo.h"
>  
> +/* This definition comes from prctl.h, but some kernels may not have it.  */
> +#ifndef PTRACE_ARCH_PRCTL
> +#define PTRACE_ARCH_PRCTL      30
> +#endif
> +
>  /* Mapping between the general-purpose registers in GNU/Linux x86-64
>     `struct user' format and GDB's register cache layout for GNU/Linux
>     i386.
> @@ -171,6 +176,30 @@ amd64_linux_fetch_inferior_registers (struct target_ops *ops,
>  
>  	  amd64_supply_fxsave (regcache, -1, &fpregs);
>  	}
> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +      {
> +	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
> +	   fs_base and gs_base fields of user_regs_struct can be
> +	   used directly.  */
> +	unsigned long base;
> +
> +	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
> +	  {
> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_FS) < 0)
> +	      perror_with_name (_("Couldn't get segment register fs_base"));
> +
> +	    regcache_raw_supply (regcache, AMD64_FSBASE_REGNUM, &base);
> +	  }
> +
> +	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
> +	  {
> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_GS) < 0)
> +	      perror_with_name (_("Couldn't get segment register gs_base"));
> +
> +	    regcache_raw_supply (regcache, AMD64_GSBASE_REGNUM, &base);
> +	  }
> +      }
> +#endif
>      }
>  }
>  
> @@ -237,6 +266,30 @@ amd64_linux_store_inferior_registers (struct target_ops *ops,
>  	  if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0)
>  	    perror_with_name (_("Couldn't write floating point status"));
>  	}
> +
> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +      {
> +	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
> +	   fs_base and gs_base fields of user_regs_struct can be
> +	   used directly.  */
> +	void *base;
> +
> +	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
> +	  {
> +	    regcache_raw_collect (regcache, AMD64_FSBASE_REGNUM, &base);
> +
> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_FS) < 0)
> +	      perror_with_name (_("Couldn't write fs_base"));
> +	  }
> +	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
> +	  {
> +
> +	    regcache_raw_collect (regcache, AMD64_GSBASE_REGNUM, &base);
> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_GS) < 0)
> +	      perror_with_name (_("Couldn't write gs_base"));
> +	  }
> +      }
> +#endif
>      }
>  }
>  \f
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 1e9f75f..b9d7176 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -103,6 +103,9 @@ int amd64_linux_gregset_reg_offset[] =
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
> +
> +  /* End of hardware registers */
> +  21 * 8, 22 * 8,		      /* fs_base and gs_base.  */
>    15 * 8			      /* "orig_rax" */
>  };
>  \f
> @@ -284,7 +287,9 @@ static int
>  amd64_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>  				 struct reggroup *group)
>  { 
> -  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM)
> +  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM
> +      || regnum == AMD64_FSBASE_REGNUM
> +      || regnum == AMD64_GSBASE_REGNUM)
>      return (group == system_reggroup
>              || group == save_reggroup
>              || group == restore_reggroup);
> diff --git a/gdb/amd64-linux-tdep.h b/gdb/amd64-linux-tdep.h
> index 5d032a6..3704caa 100644
> --- a/gdb/amd64-linux-tdep.h
> +++ b/gdb/amd64-linux-tdep.h
> @@ -26,7 +26,7 @@
>  /* Register number for the "orig_rax" register.  If this register
>     contains a value >= 0 it is interpreted as the system call number
>     that the kernel is supposed to restart.  */
> -#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_ZMM31H_REGNUM + 1)
> +#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_NUM_REGS)
>  
>  /* Total number of registers for GNU/Linux.  */
>  #define AMD64_LINUX_NUM_REGS (AMD64_LINUX_ORIG_RAX_REGNUM + 1)
> diff --git a/gdb/amd64-nat.c b/gdb/amd64-nat.c
> index 18c8a99..0143632 100644
> --- a/gdb/amd64-nat.c
> +++ b/gdb/amd64-nat.c
> @@ -53,6 +53,7 @@ amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum)
>  {
>    int *reg_offset = amd64_native_gregset64_reg_offset;
>    int num_regs = amd64_native_gregset64_num_regs;
> +  bool valid_regnum = false;
>  
>    gdb_assert (regnum >= 0);
>  
> @@ -65,10 +66,22 @@ amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum)
>    if (num_regs > gdbarch_num_regs (gdbarch))
>      num_regs = gdbarch_num_regs (gdbarch);
>  
> -  if (regnum < num_regs && regnum < gdbarch_num_regs (gdbarch))
> -    return reg_offset[regnum];
> +  /* Looks like we do not need the second part of the &&.
> +     Register validity is already guaranteed in the first part due to the
> +     comparison above.  */

Agreed.  The best would be to send a small preparatory patch that
fixed that.

> +  valid_regnum = regnum < num_regs && regnum < gdbarch_num_regs (gdbarch);
>  
> -  return -1;
> +  if (valid_regnum == false)
> +    return -1;

Write:

  if (!valid_regnum)

But I fail to see the point of the new variable?  It's not used
after that check.

> +
> +  /* Definition of the offset foresees new kernel support, it has to be
> +     corrected here in case the kernel is older.  */

This comment reads to me like we'll need to change the code as soon
as the kernel is updated/changed for something.  Which is course
not what you want to say.

  /* Kernels that predate Linux 2.6.25 don't provide access to
     these segment registers in user_regs_struct.   */
#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
  if (regnum == AMD64_FSBASE_REGNUM || regnum == AMD64_GSBASE_REGNUM)
    return -1;
#endif

> index 0000000..d0a2a8f
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.c

> +
> +int
> +main (void)
> +{
> +  volatile int a;
> +  a = 10;
> +  return a;

Does the .exp file make use of this?

> +}
> diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.exp b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
> new file mode 100644
> index 0000000..f2dc887
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
> @@ -0,0 +1,51 @@
> +# Copyright 2016 Free Software Foundation, Inc.
> +
> +# Contributed by Intel Corp. <walfred.tedeschi@intel.com>
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +standard_testfile
> +
> +if { ![istarget "x86_64-*linux*"] } then {
> +    verbose "Skipping x86_64 fs_base and gs_base tests."
> +    return
> +}
> +
> +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
> +     [list debug nowarnings]] } {
> +    return -1
> +}
> +
> +if ![runto_main] {
> +    untested "could not run to main"
> +    return -1
> +}
> +
> +gdb_test "print /x \$fs_base" "= $hex" "print fs_base"
> +gdb_test "print /x \$gs_base" "= $hex" "print gs_base"
> +
> +gdb_test "print \$fs_base = 2" "= 2" "set fs_base"
> +gdb_test "print \$gs_base = 3" "= 3" "set gs_base"
> +
> +# Test the presence of fs_base and gs_base on the system
> +# register group and values.
> +#
> +set ws "\[\t \]*"

Better to use '+' instead of '*' to enforce at least
one space, and avoid false positives like 0x33.

> +set info_reg_out [multi_line "info register sys" \
> +          "fs_base${ws}0x2${ws}2"\
> +          "gs_base${ws}0x3${ws}3"\
> +          "orig_rax${ws}$hex${ws}\[-\]$decimal" ]
> +
> +gdb_test "info register sys" $info_reg_out\
> +   "info registers fs_base and gs_base with value"
> 

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/1] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2017-01-09 20:35 ` Luis Machado
@ 2017-01-19 19:49   ` Pedro Alves
  0 siblings, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2017-01-19 19:49 UTC (permalink / raw)
  To: Luis Machado, Walfred Tedeschi, brobecker; +Cc: gdb-patches

On 01/09/2017 08:35 PM, Luis Machado wrote:

>> --- /dev/null
>> +++ b/gdb/features/i386/64bit-segments.xml
>> @@ -0,0 +1,12 @@
>> +<?xml version="1.0"?>
>> +<!-- Copyright (C) 2016 Free Software Foundation, Inc.
> 
> 2017

Please make that 2016-2017, since the file's contents
existed in 2016.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/1] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2017-01-19 19:45 ` Pedro Alves
@ 2017-01-20 14:29   ` Tedeschi, Walfred
  0 siblings, 0 replies; 5+ messages in thread
From: Tedeschi, Walfred @ 2017-01-20 14:29 UTC (permalink / raw)
  To: Pedro Alves, brobecker; +Cc: gdb-patches



On 01/19/2017 08:44 PM, Pedro Alves wrote:
> Hi Walfred,
>
> On 01/05/2017 03:53 PM, Walfred Tedeschi wrote:
>
>> orig_rax is the last register added there is a special macro that defines
>> it in this way. On gdbserver side it is defined in the middle of
>> the registers and stays there always for compatibility.
> For compatibility with what?
I was considering newer and older versions gdb/gdbserver respectively.
This came into my mind due to some reviews with Mark. That was the first
commit for MPX.

>
> (I think some punctuation in the first sentence would make it
> much easier to grok.)
I will change the text.
>> I have added the two new registers just after the orig_rax.  This causes
>> that they will be in the gdbserver side just after orig_rax and in gdb
> in gdb [...] ?
and in GDB just before.
(sorry)
>
>> I still can add then where I would prefer, the definition is
>> done by the macros defining AMD64_FSBASE_REGNUM.
> I don't understand what you mean.  What would you prefer?

To let ORIG_RAX at the end in GDB, adding general register before it.
As you guessed bellow.

>> In this sense they have
>> been added just before the orig_rax.
>>
>> This decision was taken based on the fact that we would like to add
>> hardware registers as usual before the orig_rax, and with this addition
>> also before the fs_base and gs_base.
> But the gdb register numbers have no bearing on what the user
> sees?  It's the order in the target description that
> matters, isn't it?
>
> Maybe what you're saying is this:
>
>> --- a/gdb/amd64-linux-tdep.h
>> +++ b/gdb/amd64-linux-tdep.h
>> @@ -26,7 +26,7 @@
>>   /* Register number for the "orig_rax" register.  If this register
>>      contains a value >= 0 it is interpreted as the system call number
>>      that the kernel is supposed to restart.  */
>> -#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_ZMM31H_REGNUM + 1)
>> +#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_NUM_REGS)
> ... AFAICS, AMD64_LINUX_ORIG_RAX_REGNUM is defined as the
> register that follows the last register defined in
> amd64-tdep.h, which is always AMD64_NUM_REGS.  I.e., first
> we define the "common" registers, and then the
> Linux-specific "virtual" registers.
>
> So this this change above makes it simpler to add new
> amd64-generic registers without having to remember to
> change amd64-linux-tdep.h.  Right?  If that was split into
> a small preparatory patch with a rationale like that, it'd
> have been much clearer, I think.
Agree, it would be easier. I saw the changes in Richard's commit
and liked it a lot.

Will do as you proposed, with a previous preparatory commit.
>>
>> 2017-01-05  Walfred Tedeschi  <walfred.tedeschi@intel.com>
>> 	    Richard Henderson  <rth@redhat.com>
>>
>> gdb/ChangeLog:
>>
>> 	* amd64-linux-nat.c (PTRACE_ARCH_PRCTL): New define.
>> 	(amd64_linux_fetch_inferior_registers): Add case to fetch FS_BASE
>> 	GS_BASE for older kernels.
>> 	(amd64_linux_store_inferior_registers): Add case to store FS_BASE
>> 	GS_BASE for older kernels.
>> 	* amd64-linux-tdep.c (amd64_linux_gregset_reg_offset): Add FS_BASE
>> 	and GS_BASE to the offset table.
>> 	(amd64_linux_register_reggroup_p): Add FS_BASE and GS_BASE to the
>> 	system register group.
>> 	* amd64-linux-tdep.h (AMD64_LINUX_ORIG_RAX_REGNUM): Set the value
>> 	to AMD64_NUM_REGS.
>> 	* amd64-nat.c (amd64_native_gregset_reg_offset): Adds valid_regnum
>> 	to test validit of the register.  Implements case for older
>> 	kernels.
>> 	* amd64-tdep.c (amd64_init_abi): Add segment registers for the
>> 	amd64 ABI.
>> 	* amd64-tdep.h (amd64_regnum): Add AMD64_FSBASE_REGNUM and
>> 	AMD64_GSBASE_REGNUM.
>> 	(AMD64_NUM_REGS): Set to AMD64_GSBASE_REGNUM + 1.
>> 	* features/Makefile (amd64-linux.dat, amd64-avx-linux.dat)
>> 	(amd64-mpx-linux.dat, amd64-avx512-linux.dat, x32-linux.dat)
>> 	(x32-avx-linux.dat, x32-avx512-linux.dat): Add
>> 	i386/64bit-segments.xml in those rules.
>> 	* features/i386/64bit-segments.xml: New file.
>> 	* features/i386/amd64-avx-mpx-linux.xml: Add 64bit-segments.xml.
>> 	* features/i386/amd64-avx-linux.xml: Add 64bit-segments.xml.
>> 	* features/i386/amd64-avx512-linux.xml: Add 64bit-segments.xml.
>> 	* features/i386/amd64-mpx-linux.xml: Add 64bit-segments.xml.
>> 	* features/i386/x32-avx512-linux.xml: Add 64bit-segments.xml.
>> 	* features/i386/x32-avx-linux.xml: Add 64bit-segments.xml.
>> 	* features/i386/amd64-linux.xml: Add 64bit-segments.xml.
>> 	* features/i386/amd64-avx-linux.c: Regenerated.
>> 	* features/i386/amd64-avx-mpx-linux.c: Regenerated.
>> 	* features/i386/amd64-avx-mpx.c: Regenerated.
>> 	* features/i386/amd64-avx512-linux.c: Regenerated.
>> 	* features/i386/amd64-linux.c: Regenerated.
>> 	* features/i386/amd64-mpx-linux.c: Regenerated.
>> 	* features/i386/i386-avx-mpx-linux.c: Regenerated.
>> 	* features/i386/i386-avx-mpx.c: Regenerated.
>> 	* features/i386/x32-avx-linux.c: Regenerated.
>> 	* features/i386/x32-avx512-linux.c: Regenerated.
>> 	* regformats/i386/amd64-avx-linux.dat: Regenerated.
>> 	* regformats/i386/amd64-avx-mpx-linux.dat: Regenerated.
>> 	* regformats/i386/amd64-avx512-linux.dat: Regenerated.
>> 	* regformats/i386/amd64-linux.dat: Regenerated.
>> 	* regformats/i386/amd64-mpx-linux.dat: Regenerated.
>> 	* regformats/i386/x32-avx-linux.dat: Regenerated.
>> 	* regformats/i386/x32-avx512-linux.dat: Regenerated.
>> 	* regformats/i386/x32-linux.dat: Regenerated.
>>
>> gdb/doc/ChangeLog:
>>
>> 	* gdb.texinfo (i386 Features): Add system segment registers
>> 	as feature.
>>
>> gdb/gdbserver/ChangeLog:
>>
>> 	* linux-x86-low.c (x86_64_regmap): Add fs_base and gs_base
>> 	to the register table.
>> 	(x86_fill_gregset): Add support for old kernels for the
>> 	fs_base and gs_base system registers.
>> 	(x86_store_gregset): Likewise.
>> 	* configure.srv (srv_i386_64bit_xmlfiles): Add 64bit-segments.xml.
>>
>> gdb/testsuite/ChangeLog:
>>
>> 	* gdb.arch/amd64-gs_base.c: New file.
>> 	* gdb.arch/amd64-gs_base.exp: New file.
>>
>> ---
>>   gdb/amd64-linux-nat.c                       |  53 ++++++++
>>   gdb/amd64-linux-tdep.c                      |   7 +-
>>   gdb/amd64-linux-tdep.h                      |   2 +-
>>   gdb/amd64-nat.c                             |  19 ++-
>>   gdb/amd64-tdep.c                            |  13 ++
>>   gdb/amd64-tdep.h                            |   6 +-
>>   gdb/doc/gdb.texinfo                         |   3 +
>>   gdb/features/Makefile                       |  17 +--
>>   gdb/features/i386/64bit-segments.xml        |  12 ++
>>   gdb/features/i386/amd64-avx-linux.c         |  36 +++---
>>   gdb/features/i386/amd64-avx-linux.xml       |   1 +
>>   gdb/features/i386/amd64-avx-mpx-linux.c     |  48 +++----
>>   gdb/features/i386/amd64-avx-mpx-linux.xml   |   1 +
>>   gdb/features/i386/amd64-avx512-linux.c      | 192 ++++++++++++++--------------
>>   gdb/features/i386/amd64-avx512-linux.xml    |   1 +
>>   gdb/features/i386/amd64-linux.c             |   4 +
>>   gdb/features/i386/amd64-linux.xml           |   1 +
>>   gdb/features/i386/amd64-mpx-linux.c         |  16 ++-
>>   gdb/features/i386/amd64-mpx-linux.xml       |   1 +
>>   gdb/features/i386/x32-avx-linux.c           |  36 +++---
>>   gdb/features/i386/x32-avx-linux.xml         |   1 +
>>   gdb/features/i386/x32-avx512-linux.c        | 192 ++++++++++++++--------------
>>   gdb/features/i386/x32-avx512-linux.xml      |   1 +
>>   gdb/features/i386/x32-linux.c               |   4 +
>>   gdb/features/i386/x32-linux.xml             |   1 +
>>   gdb/gdbserver/configure.srv                 |   2 +-
>>   gdb/gdbserver/linux-x86-low.c               |  32 +++++
>>   gdb/regformats/i386/amd64-avx-linux.dat     |   2 +
>>   gdb/regformats/i386/amd64-avx-mpx-linux.dat |   2 +
>>   gdb/regformats/i386/amd64-avx512-linux.dat  |   2 +
>>   gdb/regformats/i386/amd64-linux.dat         |   2 +
>>   gdb/regformats/i386/amd64-mpx-linux.dat     |   2 +
>>   gdb/regformats/i386/x32-avx-linux.dat       |   2 +
>>   gdb/regformats/i386/x32-avx512-linux.dat    |   2 +
>>   gdb/regformats/i386/x32-linux.dat           |   2 +
>>   gdb/testsuite/gdb.arch/amd64-gs_base.c      |  26 ++++
>>   gdb/testsuite/gdb.arch/amd64-gs_base.exp    |  51 ++++++++
>>   37 files changed, 531 insertions(+), 264 deletions(-)
>>   create mode 100644 gdb/features/i386/64bit-segments.xml
>>   create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.c
>>   create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.exp
>>
>> diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
>> index 4a2036b..0ec22cb 100644
>> --- a/gdb/amd64-linux-nat.c
>> +++ b/gdb/amd64-linux-nat.c
>> @@ -40,6 +40,11 @@
>>   #include "nat/linux-ptrace.h"
>>   #include "nat/amd64-linux-siginfo.h"
>>   
>> +/* This definition comes from prctl.h, but some kernels may not have it.  */
>> +#ifndef PTRACE_ARCH_PRCTL
>> +#define PTRACE_ARCH_PRCTL      30
>> +#endif
>> +
>>   /* Mapping between the general-purpose registers in GNU/Linux x86-64
>>      `struct user' format and GDB's register cache layout for GNU/Linux
>>      i386.
>> @@ -171,6 +176,30 @@ amd64_linux_fetch_inferior_registers (struct target_ops *ops,
>>   
>>   	  amd64_supply_fxsave (regcache, -1, &fpregs);
>>   	}
>> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
>> +      {
>> +	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
>> +	   fs_base and gs_base fields of user_regs_struct can be
>> +	   used directly.  */
>> +	unsigned long base;
>> +
>> +	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
>> +	  {
>> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_FS) < 0)
>> +	      perror_with_name (_("Couldn't get segment register fs_base"));
>> +
>> +	    regcache_raw_supply (regcache, AMD64_FSBASE_REGNUM, &base);
>> +	  }
>> +
>> +	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
>> +	  {
>> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_GS) < 0)
>> +	      perror_with_name (_("Couldn't get segment register gs_base"));
>> +
>> +	    regcache_raw_supply (regcache, AMD64_GSBASE_REGNUM, &base);
>> +	  }
>> +      }
>> +#endif
>>       }
>>   }
>>   
>> @@ -237,6 +266,30 @@ amd64_linux_store_inferior_registers (struct target_ops *ops,
>>   	  if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0)
>>   	    perror_with_name (_("Couldn't write floating point status"));
>>   	}
>> +
>> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
>> +      {
>> +	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
>> +	   fs_base and gs_base fields of user_regs_struct can be
>> +	   used directly.  */
>> +	void *base;
>> +
>> +	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
>> +	  {
>> +	    regcache_raw_collect (regcache, AMD64_FSBASE_REGNUM, &base);
>> +
>> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_FS) < 0)
>> +	      perror_with_name (_("Couldn't write fs_base"));
>> +	  }
>> +	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
>> +	  {
>> +
>> +	    regcache_raw_collect (regcache, AMD64_GSBASE_REGNUM, &base);
>> +	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_GS) < 0)
>> +	      perror_with_name (_("Couldn't write gs_base"));
>> +	  }
>> +      }
>> +#endif
>>       }
>>   }
>>   \f
>> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
>> index 1e9f75f..b9d7176 100644
>> --- a/gdb/amd64-linux-tdep.c
>> +++ b/gdb/amd64-linux-tdep.c
>> @@ -103,6 +103,9 @@ int amd64_linux_gregset_reg_offset[] =
>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>     -1, -1, -1, -1, -1, -1, -1, -1,
>> +
>> +  /* End of hardware registers */
>> +  21 * 8, 22 * 8,		      /* fs_base and gs_base.  */
>>     15 * 8			      /* "orig_rax" */
>>   };
>>   \f
>> @@ -284,7 +287,9 @@ static int
>>   amd64_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>>   				 struct reggroup *group)
>>   {
>> -  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM)
>> +  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM
>> +      || regnum == AMD64_FSBASE_REGNUM
>> +      || regnum == AMD64_GSBASE_REGNUM)
>>       return (group == system_reggroup
>>               || group == save_reggroup
>>               || group == restore_reggroup);
>> diff --git a/gdb/amd64-linux-tdep.h b/gdb/amd64-linux-tdep.h
>> index 5d032a6..3704caa 100644
>> --- a/gdb/amd64-linux-tdep.h
>> +++ b/gdb/amd64-linux-tdep.h
>> @@ -26,7 +26,7 @@
>>   /* Register number for the "orig_rax" register.  If this register
>>      contains a value >= 0 it is interpreted as the system call number
>>      that the kernel is supposed to restart.  */
>> -#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_ZMM31H_REGNUM + 1)
>> +#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_NUM_REGS)
>>   
>>   /* Total number of registers for GNU/Linux.  */
>>   #define AMD64_LINUX_NUM_REGS (AMD64_LINUX_ORIG_RAX_REGNUM + 1)
>> diff --git a/gdb/amd64-nat.c b/gdb/amd64-nat.c
>> index 18c8a99..0143632 100644
>> --- a/gdb/amd64-nat.c
>> +++ b/gdb/amd64-nat.c
>> @@ -53,6 +53,7 @@ amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum)
>>   {
>>     int *reg_offset = amd64_native_gregset64_reg_offset;
>>     int num_regs = amd64_native_gregset64_num_regs;
>> +  bool valid_regnum = false;
>>   
>>     gdb_assert (regnum >= 0);
>>   
>> @@ -65,10 +66,22 @@ amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum)
>>     if (num_regs > gdbarch_num_regs (gdbarch))
>>       num_regs = gdbarch_num_regs (gdbarch);
>>   
>> -  if (regnum < num_regs && regnum < gdbarch_num_regs (gdbarch))
>> -    return reg_offset[regnum];
>> +  /* Looks like we do not need the second part of the &&.
>> +     Register validity is already guaranteed in the first part due to the
>> +     comparison above.  */
> Agreed.  The best would be to send a small preparatory patch that
> fixed that.
>
>> +  valid_regnum = regnum < num_regs && regnum < gdbarch_num_regs (gdbarch);
>>   
>> -  return -1;
>> +  if (valid_regnum == false)
>> +    return -1;
> Write:
>
>    if (!valid_regnum)
>
> But I fail to see the point of the new variable?  It's not used
> after that check.
I was considering a post patch, but pre patch is better; This way we do 
not need to create an
additional variable.
>> +
>> +  /* Definition of the offset foresees new kernel support, it has to be
>> +     corrected here in case the kernel is older.  */
> This comment reads to me like we'll need to change the code as soon
> as the kernel is updated/changed for something.  Which is course
> not what you want to say.
>
>    /* Kernels that predate Linux 2.6.25 don't provide access to
>       these segment registers in user_regs_struct.   */
> #ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
>    if (regnum == AMD64_FSBASE_REGNUM || regnum == AMD64_GSBASE_REGNUM)
>      return -1;
> #endif
>
>> index 0000000..d0a2a8f
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.c
>> +
>> +int
>> +main (void)
>> +{
>> +  volatile int a;
>> +  a = 10;
>> +  return a;
> Does the .exp file make use of this?
Not really, I will minimize the sample.
>> +}
>> diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.exp b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
>> new file mode 100644
>> index 0000000..f2dc887
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
>> @@ -0,0 +1,51 @@
>> +# Copyright 2016 Free Software Foundation, Inc.
>> +
>> +# Contributed by Intel Corp. <walfred.tedeschi@intel.com>
>> +
>> +# This program is free software; you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation; either version 3 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
>> +
>> +standard_testfile
>> +
>> +if { ![istarget "x86_64-*linux*"] } then {
>> +    verbose "Skipping x86_64 fs_base and gs_base tests."
>> +    return
>> +}
>> +
>> +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
>> +     [list debug nowarnings]] } {
>> +    return -1
>> +}
>> +
>> +if ![runto_main] {
>> +    untested "could not run to main"
>> +    return -1
>> +}
>> +
>> +gdb_test "print /x \$fs_base" "= $hex" "print fs_base"
>> +gdb_test "print /x \$gs_base" "= $hex" "print gs_base"
>> +
>> +gdb_test "print \$fs_base = 2" "= 2" "set fs_base"
>> +gdb_test "print \$gs_base = 3" "= 3" "set gs_base"
>> +
>> +# Test the presence of fs_base and gs_base on the system
>> +# register group and values.
>> +#
>> +set ws "\[\t \]*"
> Better to use '+' instead of '*' to enforce at least
> one space, and avoid false positives like 0x33.
ok! Thanks!
>> +set info_reg_out [multi_line "info register sys" \
>> +          "fs_base${ws}0x2${ws}2"\
>> +          "gs_base${ws}0x3${ws}3"\
>> +          "orig_rax${ws}$hex${ws}\[-\]$decimal" ]
>> +
>> +gdb_test "info register sys" $info_reg_out\
>> +   "info registers fs_base and gs_base with value"
>>
> Thanks,
> Pedro Alves
>

Thank you very much for the review!

Regards,
/Fred
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-20 14:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-05 15:53 [PATCH V2 1/1] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
2017-01-09 20:35 ` Luis Machado
2017-01-19 19:49   ` Pedro Alves
2017-01-19 19:45 ` Pedro Alves
2017-01-20 14:29   ` Tedeschi, Walfred

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).