Blame SOURCES/gdb-rhbz1498758-3of5.patch

15e4b0
commit 1b63490c9173f8c9770b7885def720516aa9b9f8
15e4b0
Author: Andreas Arnez <arnez@linux.vnet.ibm.com>
15e4b0
Date:   Mon Sep 25 16:02:23 2017 +0200
15e4b0
15e4b0
    S390: Add guarded-storage register support to GDB
15e4b0
    
15e4b0
    Recognize targets with the new guarded-storage feature and then present
15e4b0
    the guarded-storage registers and the Linux-specific guarded-storage
15e4b0
    broadcast control block appropriately.
15e4b0
    
15e4b0
    gdb/ChangeLog:
15e4b0
    
15e4b0
            * s390-linux-nat.c (have_regset_gs): New static variable.
15e4b0
            (s390_linux_fetch_inferior_registers): Handle guarded-storage
15e4b0
            control block and guarded-storage broadcast control regsets.
15e4b0
            (s390_read_description): Detect whether the target has
15e4b0
            guarded-storage support, return appropriate tdesc.
15e4b0
            * s390-linux-tdep.c (features/s390-gs-linux64.c): New include.
15e4b0
            (features/s390x-gs-linux64.c): Likewise.
15e4b0
            (struct gdbarch_tdep) <have_gs>: New field.
15e4b0
            (s390_regmap_gs, s390_regmap_gsbc, s390_gs_regset)
15e4b0
            (s390_gsbc_regset): New variables.
15e4b0
            (s390_iterate_over_regset_sections): Iterate over s390_gs_regset
15e4b0
            and s390_gsbc_regset, if applicable.
15e4b0
            (s390_core_read_description): Check whether core file was from a
15e4b0
            target with guarded-storage support; include appropriate regsets.
15e4b0
            (s390_gdbarch_init): Add registers for guarded-storage support.
15e4b0
            (_initialize_s390_tdep): Initialize new target descriptions that
15e4b0
            include registers for guarded-storage support.
15e4b0
            * s390-linux-tdep.h (HWCAP_S390_GS, S390_GSD_REGNUM)
15e4b0
            (S390_GSSM_REGNUM, S390_GSEPLA_REGNUM)
15e4b0
            (S390_BC_GSD_REGNUM, S390_BC_GSSM_REGNUM): New defines.
15e4b0
            (S390_NUM_REGS): Adjust macro definition.
15e4b0
            (s390_gs_regset, s390_gsbc_regset, tdesc_s390_gs_linux64)
15e4b0
            (tdesc_s390x_gs_linux64): New declarations.
15e4b0
15e4b0
### a/gdb/ChangeLog
15e4b0
### b/gdb/ChangeLog
15e4b0
## -1,5 +1,31 @@
15e4b0
 2017-09-25  Andreas Arnez  <arnez@linux.vnet.ibm.com>
15e4b0
 
15e4b0
+	* s390-linux-nat.c (have_regset_gs): New static variable.
15e4b0
+	(s390_linux_fetch_inferior_registers): Handle guarded-storage
15e4b0
+	control block and guarded-storage broadcast control regsets.
15e4b0
+	(s390_read_description): Detect whether the target has
15e4b0
+	guarded-storage support, return appropriate tdesc.
15e4b0
+	* s390-linux-tdep.c (features/s390-gs-linux64.c): New include.
15e4b0
+	(features/s390x-gs-linux64.c): Likewise.
15e4b0
+	(struct gdbarch_tdep) <have_gs>: New field.
15e4b0
+	(s390_regmap_gs, s390_regmap_gsbc, s390_gs_regset)
15e4b0
+	(s390_gsbc_regset): New variables.
15e4b0
+	(s390_iterate_over_regset_sections): Iterate over s390_gs_regset
15e4b0
+	and s390_gsbc_regset, if applicable.
15e4b0
+	(s390_core_read_description): Check whether core file was from a
15e4b0
+	target with guarded-storage support; include appropriate regsets.
15e4b0
+	(s390_gdbarch_init): Add registers for guarded-storage support.
15e4b0
+	(_initialize_s390_tdep): Initialize new target descriptions that
15e4b0
+	include registers for guarded-storage support.
15e4b0
+	* s390-linux-tdep.h (HWCAP_S390_GS, S390_GSD_REGNUM)
15e4b0
+	(S390_GSSM_REGNUM, S390_GSEPLA_REGNUM)
15e4b0
+	(S390_BC_GSD_REGNUM, S390_BC_GSSM_REGNUM): New defines.
15e4b0
+	(S390_NUM_REGS): Adjust macro definition.
15e4b0
+	(s390_gs_regset, s390_gsbc_regset, tdesc_s390_gs_linux64)
15e4b0
+	(tdesc_s390x_gs_linux64): New declarations.
15e4b0
+
15e4b0
+2017-09-25  Andreas Arnez  <arnez@linux.vnet.ibm.com>
15e4b0
+
15e4b0
 	* features/s390-gs-linux64.xml: New file.
15e4b0
 	* features/s390-gs.xml: New file.
15e4b0
 	* features/s390-gsbc.xml: New file.
15e4b0
--- a/gdb/s390-linux-nat.c
15e4b0
+++ b/gdb/s390-linux-nat.c
15e4b0
@@ -54,6 +54,7 @@ static int have_regset_last_break = 0;
15e4b0
 static int have_regset_system_call = 0;
15e4b0
 static int have_regset_tdb = 0;
15e4b0
 static int have_regset_vxrs = 0;
15e4b0
+static int have_regset_gs = 0;
15e4b0
 
15e4b0
 /* Register map for 32-bit executables running under a 64-bit
15e4b0
    kernel.  */
15e4b0
@@ -406,6 +407,18 @@ s390_linux_fetch_inferior_registers (struct target_ops *ops,
15e4b0
 	fetch_regset (regcache, tid, NT_S390_VXRS_HIGH, 16 * 16,
15e4b0
 		      &s390_vxrs_high_regset);
15e4b0
     }
15e4b0
+
15e4b0
+  if (have_regset_gs)
15e4b0
+    {
15e4b0
+      if (regnum == -1 || (regnum >= S390_GSD_REGNUM
15e4b0
+			   && regnum <= S390_GSEPLA_REGNUM))
15e4b0
+	fetch_regset (regcache, tid, NT_S390_GS_CB, 4 * 8,
15e4b0
+		      &s390_gs_regset);
15e4b0
+      if (regnum == -1 || (regnum >= S390_BC_GSD_REGNUM
15e4b0
+			   && regnum <= S390_BC_GSEPLA_REGNUM))
15e4b0
+	fetch_regset (regcache, tid, NT_S390_GS_BC, 4 * 8,
15e4b0
+		      &s390_gsbc_regset);
15e4b0
+    }
15e4b0
 }
15e4b0
 
15e4b0
 /* Store register REGNUM back into the child process.  If REGNUM is
15e4b0
@@ -974,8 +987,13 @@ s390_read_description (struct target_ops *ops)
15e4b0
       && check_regset (tid, NT_S390_VXRS_LOW, 16 * 8)
15e4b0
       && check_regset (tid, NT_S390_VXRS_HIGH, 16 * 16);
15e4b0
 
15e4b0
+    have_regset_gs = (hwcap & HWCAP_S390_GS)
15e4b0
+      && check_regset (tid, NT_S390_GS_CB, 4 * 8)
15e4b0
+      && check_regset (tid, NT_S390_GS_BC, 4 * 8);
15e4b0
+
15e4b0
     if (s390_target_wordsize () == 8)
15e4b0
-      return (have_regset_vxrs ?
15e4b0
+      return (have_regset_gs ? tdesc_s390x_gs_linux64 :
15e4b0
+	      have_regset_vxrs ?
15e4b0
 	      (have_regset_tdb ? tdesc_s390x_tevx_linux64 :
15e4b0
 	       tdesc_s390x_vx_linux64) :
15e4b0
 	      have_regset_tdb ? tdesc_s390x_te_linux64 :
15e4b0
@@ -984,7 +1002,8 @@ s390_read_description (struct target_ops *ops)
15e4b0
 	      tdesc_s390x_linux64);
15e4b0
 
15e4b0
     if (hwcap & HWCAP_S390_HIGH_GPRS)
15e4b0
-      return (have_regset_vxrs ?
15e4b0
+      return (have_regset_gs ? tdesc_s390_gs_linux64 :
15e4b0
+	      have_regset_vxrs ?
15e4b0
 	      (have_regset_tdb ? tdesc_s390_tevx_linux64 :
15e4b0
 	       tdesc_s390_vx_linux64) :
15e4b0
 	      have_regset_tdb ? tdesc_s390_te_linux64 :
15e4b0
--- a/gdb/s390-linux-tdep.c
15e4b0
+++ b/gdb/s390-linux-tdep.c
15e4b0
@@ -69,12 +69,14 @@
15e4b0
 #include "features/s390-te-linux64.c"
15e4b0
 #include "features/s390-vx-linux64.c"
15e4b0
 #include "features/s390-tevx-linux64.c"
15e4b0
+#include "features/s390-gs-linux64.c"
15e4b0
 #include "features/s390x-linux64.c"
15e4b0
 #include "features/s390x-linux64v1.c"
15e4b0
 #include "features/s390x-linux64v2.c"
15e4b0
 #include "features/s390x-te-linux64.c"
15e4b0
 #include "features/s390x-vx-linux64.c"
15e4b0
 #include "features/s390x-tevx-linux64.c"
15e4b0
+#include "features/s390x-gs-linux64.c"
15e4b0
 
15e4b0
 #define XML_SYSCALL_FILENAME_S390 "syscalls/s390-linux.xml"
15e4b0
 #define XML_SYSCALL_FILENAME_S390X "syscalls/s390x-linux.xml"
15e4b0
@@ -113,6 +115,7 @@ struct gdbarch_tdep
15e4b0
   int have_linux_v1;
15e4b0
   int have_linux_v2;
15e4b0
   int have_tdb;
15e4b0
+  bool have_gs;
15e4b0
 };
15e4b0
 
15e4b0
 
15e4b0
@@ -834,6 +837,24 @@ static const struct regcache_map_entry s390_regmap_vxrs_high[] =
15e4b0
     { 0 }
15e4b0
   };
15e4b0
 
15e4b0
+static const struct regcache_map_entry s390_regmap_gs[] =
15e4b0
+  {
15e4b0
+    { 1, REGCACHE_MAP_SKIP, 8 },
15e4b0
+    { 1, S390_GSD_REGNUM, 8 },
15e4b0
+    { 1, S390_GSSM_REGNUM, 8 },
15e4b0
+    { 1, S390_GSEPLA_REGNUM, 8 },
15e4b0
+    { 0 }
15e4b0
+  };
15e4b0
+
15e4b0
+static const struct regcache_map_entry s390_regmap_gsbc[] =
15e4b0
+  {
15e4b0
+    { 1, REGCACHE_MAP_SKIP, 8 },
15e4b0
+    { 1, S390_BC_GSD_REGNUM, 8 },
15e4b0
+    { 1, S390_BC_GSSM_REGNUM, 8 },
15e4b0
+    { 1, S390_BC_GSEPLA_REGNUM, 8 },
15e4b0
+    { 0 }
15e4b0
+  };
15e4b0
+
15e4b0
 
15e4b0
 /* Supply the TDB regset.  Like regcache_supply_regset, but invalidate
15e4b0
    the TDB registers unless the TDB format field is valid.  */
15e4b0
@@ -905,6 +926,18 @@ const struct regset s390_vxrs_high_regset = {
15e4b0
   regcache_collect_regset
15e4b0
 };
15e4b0
 
15e4b0
+const struct regset s390_gs_regset = {
15e4b0
+  s390_regmap_gs,
15e4b0
+  regcache_supply_regset,
15e4b0
+  regcache_collect_regset
15e4b0
+};
15e4b0
+
15e4b0
+const struct regset s390_gsbc_regset = {
15e4b0
+  s390_regmap_gsbc,
15e4b0
+  regcache_supply_regset,
15e4b0
+  regcache_collect_regset
15e4b0
+};
15e4b0
+
15e4b0
 /* Iterate over supported core file register note sections. */
15e4b0
 
15e4b0
 static void
15e4b0
@@ -951,6 +984,23 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
15e4b0
       cb (".reg-s390-vxrs-high", 16 * 16, &s390_vxrs_high_regset,
15e4b0
 	  "s390 vector registers 16-31", cb_data);
15e4b0
     }
15e4b0
+
15e4b0
+  /* Iterate over the guarded-storage regsets if in "read" mode, or if
15e4b0
+     their registers are available.  */
15e4b0
+  if (tdep->have_gs)
15e4b0
+    {
15e4b0
+      if (regcache == NULL
15e4b0
+	  || REG_VALID == regcache_register_status (regcache,
15e4b0
+						    S390_GSD_REGNUM))
15e4b0
+	cb (".reg-s390-gs-cb", 4 * 8, &s390_gs_regset,
15e4b0
+	    "s390 guarded-storage registers", cb_data);
15e4b0
+
15e4b0
+      if (regcache == NULL
15e4b0
+	  || REG_VALID == regcache_register_status (regcache,
15e4b0
+						    S390_BC_GSD_REGNUM))
15e4b0
+	cb (".reg-s390-gs-bc", 4 * 8, &s390_gsbc_regset,
15e4b0
+	    "s390 guarded-storage broadcast control", cb_data);
15e4b0
+    }
15e4b0
 }
15e4b0
 
15e4b0
 static const struct target_desc *
15e4b0
@@ -959,7 +1009,7 @@ s390_core_read_description (struct gdbarch *gdbarch,
15e4b0
 {
15e4b0
   asection *section = bfd_get_section_by_name (abfd, ".reg");
15e4b0
   CORE_ADDR hwcap = 0;
15e4b0
-  int high_gprs, v1, v2, te, vx;
15e4b0
+  bool high_gprs, v1, v2, te, vx, gs;
15e4b0
 
15e4b0
   target_auxv_search (target, AT_HWCAP, &hwcap);
15e4b0
   if (!section)
15e4b0
@@ -971,12 +1021,14 @@ s390_core_read_description (struct gdbarch *gdbarch,
15e4b0
   v2 = (bfd_get_section_by_name (abfd, ".reg-s390-system-call") != NULL);
15e4b0
   vx = (hwcap & HWCAP_S390_VX);
15e4b0
   te = (hwcap & HWCAP_S390_TE);
15e4b0
+  gs = (hwcap & HWCAP_S390_GS);
15e4b0
 
15e4b0
   switch (bfd_section_size (abfd, section))
15e4b0
     {
15e4b0
     case s390_sizeof_gregset:
15e4b0
       if (high_gprs)
15e4b0
-	return (te && vx ? tdesc_s390_tevx_linux64 :
15e4b0
+	return (gs ? tdesc_s390_gs_linux64 :
15e4b0
+		te && vx ? tdesc_s390_tevx_linux64 :
15e4b0
 		vx ? tdesc_s390_vx_linux64 :
15e4b0
 		te ? tdesc_s390_te_linux64 :
15e4b0
 		v2 ? tdesc_s390_linux64v2 :
15e4b0
@@ -986,7 +1038,8 @@ s390_core_read_description (struct gdbarch *gdbarch,
15e4b0
 		v1 ? tdesc_s390_linux32v1 : tdesc_s390_linux32);
15e4b0
 
15e4b0
     case s390x_sizeof_gregset:
15e4b0
-      return (te && vx ? tdesc_s390x_tevx_linux64 :
15e4b0
+      return (gs ? tdesc_s390x_gs_linux64 :
15e4b0
+	      te && vx ? tdesc_s390x_tevx_linux64 :
15e4b0
 	      vx ? tdesc_s390x_vx_linux64 :
15e4b0
 	      te ? tdesc_s390x_te_linux64 :
15e4b0
 	      v2 ? tdesc_s390x_linux64v2 :
15e4b0
@@ -7767,6 +7820,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
15e4b0
   int have_linux_v2 = 0;
15e4b0
   int have_tdb = 0;
15e4b0
   int have_vx = 0;
15e4b0
+  int have_gs = 0;
15e4b0
   int first_pseudo_reg, last_pseudo_reg;
15e4b0
   static const char *const stap_register_prefixes[] = { "%", NULL };
15e4b0
   static const char *const stap_register_indirection_prefixes[] = { "(",
15e4b0
@@ -7834,6 +7888,12 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
15e4b0
 	"v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24",
15e4b0
 	"v25", "v26", "v27", "v28", "v29", "v30", "v31",
15e4b0
       };
15e4b0
+      static const char *const gs_cb[] = {
15e4b0
+	"gsd", "gssm", "gsepla",
15e4b0
+      };
15e4b0
+      static const char *const gs_bc[] = {
15e4b0
+	"bc_gsd", "bc_gssm", "bc_gsepla",
15e4b0
+      };
15e4b0
       const struct tdesc_feature *feature;
15e4b0
       int i, valid_p = 1;
15e4b0
 
15e4b0
@@ -7937,6 +7997,29 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
15e4b0
 	  have_vx = 1;
15e4b0
 	}
15e4b0
 
15e4b0
+      /* Guarded-storage registers.  */
15e4b0
+      feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.gs");
15e4b0
+      if (feature)
15e4b0
+	{
15e4b0
+	  for (i = 0; i < 3; i++)
15e4b0
+	    valid_p &= tdesc_numbered_register (feature, tdesc_data,
15e4b0
+						S390_GSD_REGNUM + i,
15e4b0
+						gs_cb[i]);
15e4b0
+	  have_gs = 1;
15e4b0
+	}
15e4b0
+
15e4b0
+      /* Guarded-storage broadcast control.  */
15e4b0
+      feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.gsbc");
15e4b0
+      if (feature)
15e4b0
+	{
15e4b0
+	  valid_p &= have_gs;
15e4b0
+
15e4b0
+	  for (i = 0; i < 3; i++)
15e4b0
+	    valid_p &= tdesc_numbered_register (feature, tdesc_data,
15e4b0
+						S390_BC_GSD_REGNUM + i,
15e4b0
+						gs_bc[i]);
15e4b0
+	}
15e4b0
+
15e4b0
       if (!valid_p)
15e4b0
 	{
15e4b0
 	  tdesc_data_cleanup (tdesc_data);
15e4b0
@@ -7970,6 +8053,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
15e4b0
 	continue;
15e4b0
       if ((tdep->gpr_full_regnum != -1) != have_upper)
15e4b0
 	continue;
15e4b0
+      if (tdep->have_gs != have_gs)
15e4b0
+	continue;
15e4b0
       if (tdesc_data != NULL)
15e4b0
 	tdesc_data_cleanup (tdesc_data);
15e4b0
       return arches->gdbarch;
15e4b0
@@ -7982,6 +8067,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
15e4b0
   tdep->have_linux_v1 = have_linux_v1;
15e4b0
   tdep->have_linux_v2 = have_linux_v2;
15e4b0
   tdep->have_tdb = have_tdb;
15e4b0
+  tdep->have_gs = have_gs;
15e4b0
   gdbarch = gdbarch_alloc (&info, tdep);
15e4b0
 
15e4b0
   set_gdbarch_believe_pcc_promotion (gdbarch, 0);
15e4b0
@@ -8157,10 +8243,12 @@ _initialize_s390_tdep (void)
15e4b0
   initialize_tdesc_s390_te_linux64 ();
15e4b0
   initialize_tdesc_s390_vx_linux64 ();
15e4b0
   initialize_tdesc_s390_tevx_linux64 ();
15e4b0
+  initialize_tdesc_s390_gs_linux64 ();
15e4b0
   initialize_tdesc_s390x_linux64 ();
15e4b0
   initialize_tdesc_s390x_linux64v1 ();
15e4b0
   initialize_tdesc_s390x_linux64v2 ();
15e4b0
   initialize_tdesc_s390x_te_linux64 ();
15e4b0
   initialize_tdesc_s390x_vx_linux64 ();
15e4b0
   initialize_tdesc_s390x_tevx_linux64 ();
15e4b0
+  initialize_tdesc_s390x_gs_linux64 ();
15e4b0
 }
15e4b0
--- a/gdb/s390-linux-tdep.h
15e4b0
+++ b/gdb/s390-linux-tdep.h
15e4b0
@@ -33,6 +33,10 @@
15e4b0
 #define HWCAP_S390_VX 2048
15e4b0
 #endif
15e4b0
 
15e4b0
+#ifndef HWCAP_S390_GS
15e4b0
+#define HWCAP_S390_GS 16384
15e4b0
+#endif
15e4b0
+
15e4b0
 /* Register information.  */
15e4b0
 
15e4b0
 /* Program Status Word.  */
15e4b0
@@ -166,8 +170,14 @@
15e4b0
 #define S390_V29_REGNUM 119
15e4b0
 #define S390_V30_REGNUM 120
15e4b0
 #define S390_V31_REGNUM 121
15e4b0
+#define S390_GSD_REGNUM 122
15e4b0
+#define S390_GSSM_REGNUM 123
15e4b0
+#define S390_GSEPLA_REGNUM 124
15e4b0
+#define S390_BC_GSD_REGNUM 125
15e4b0
+#define S390_BC_GSSM_REGNUM 126
15e4b0
+#define S390_BC_GSEPLA_REGNUM 127
15e4b0
 /* Total.  */
15e4b0
-#define S390_NUM_REGS 122
15e4b0
+#define S390_NUM_REGS 128
15e4b0
 
15e4b0
 /* Special register usage.  */
15e4b0
 #define S390_SP_REGNUM S390_R15_REGNUM
15e4b0
@@ -198,6 +208,8 @@ extern const struct regset s390_tdb_regset;
15e4b0
 #define s390_sizeof_tdbregset 0x100
15e4b0
 extern const struct regset s390_vxrs_low_regset;
15e4b0
 extern const struct regset s390_vxrs_high_regset;
15e4b0
+extern const struct regset s390_gs_regset;
15e4b0
+extern const struct regset s390_gsbc_regset;
15e4b0
 
15e4b0
 /* GNU/Linux target descriptions.  */
15e4b0
 extern struct target_desc *tdesc_s390_linux32;
15e4b0
@@ -209,11 +221,13 @@ extern struct target_desc *tdesc_s390_linux64v2;
15e4b0
 extern struct target_desc *tdesc_s390_te_linux64;
15e4b0
 extern struct target_desc *tdesc_s390_vx_linux64;
15e4b0
 extern struct target_desc *tdesc_s390_tevx_linux64;
15e4b0
+extern struct target_desc *tdesc_s390_gs_linux64;
15e4b0
 extern struct target_desc *tdesc_s390x_linux64;
15e4b0
 extern struct target_desc *tdesc_s390x_linux64v1;
15e4b0
 extern struct target_desc *tdesc_s390x_linux64v2;
15e4b0
 extern struct target_desc *tdesc_s390x_te_linux64;
15e4b0
 extern struct target_desc *tdesc_s390x_vx_linux64;
15e4b0
 extern struct target_desc *tdesc_s390x_tevx_linux64;
15e4b0
+extern struct target_desc *tdesc_s390x_gs_linux64;
15e4b0
 
15e4b0
 #endif