File 0003-S390-Add-vector-register-support-to-gdbserver.patch of Package gdb.783

Part of fate#318039

From bf2d68ab8c9da89a7caec2abdd2cc27c607f4a04 Mon Sep 17 00:00:00 2001
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
Date: Mon, 2 Mar 2015 10:57:40 +0100
Subject: [PATCH] S390: Add vector register support to gdbserver

On S/390 targets with vector registers, enable gdbserver to advertise
and handle the feature "org.gnu.gdb.s390.vx".

gdb/gdbserver/ChangeLog:

	* Makefile.in (s390-vx-linux64.c, s390-tevx-linux64.c)
	(s390x-vx-linux64.c, s390x-tevx-linux64.c): New rules.
	(clean): Add "rm -f" for above C files.
	* configure.srv (srv_regobj): Add s390-vx-linux64.o,
	s390-tevx-linux64.o, s390x-vx-linux64.o, and s390x-tevx-linux64.o.
	(srv_xmlfiles): Add s390-vx-linux64.xml, s390-tevx-linux64.xml,
	s390x-vx-linux64.xml, s390x-tevx-linux64.xml, and s390-vx.xml.
	* linux-s390-low.c (HWCAP_S390_VX): New macro.
	(init_registers_s390_vx_linux64, init_registers_s390_tevx_linux64)
	(init_registers_s390x_vx_linux64)
	(init_registers_s390x_tevx_linux64)
	(tdesc_s390_vx_linux64, tdesc_s390_tevx_linux64)
	(tdesc_s390x_vx_linux64, tdesc_s390x_tevx_linux64): New extern
	declarations.
	(s390_fill_vxrs_low, s390_store_vxrs_low, s390_fill_vxrs_high)
	(s390_store_vxrs_high): New functions.
	(s390_regsets): Add entries for NT_S390_VXRS_LOW and
	NT_S390_VXRS_HIGH.
	(s390_arch_setup): Add logic for selecting one of the new target
	descriptions.  Activate the new vector regsets if applicable.
	(initialize_low_arch): Also invoke init_registers_s390_vx_linux64,
	init_registers_s390_tevx_linux64, init_registers_s390x_vx_linux64,
	and init_registers_s390x_tevx_linux64.
---
 gdb/gdbserver/ChangeLog        | 26 ++++++++++++
 gdb/gdbserver/Makefile.in      | 12 +++++-
 gdb/gdbserver/configure.srv    |  9 ++++
 gdb/gdbserver/linux-s390-low.c | 94 ++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 137 insertions(+), 4 deletions(-)

Index: gdb-7.9.1/gdb/gdbserver/Makefile.in
===================================================================
--- gdb-7.9.1.orig/gdb/gdbserver/Makefile.in	2015-07-10 16:18:29.000000000 +0200
+++ gdb-7.9.1/gdb/gdbserver/Makefile.in	2015-07-10 16:19:13.000000000 +0200
@@ -356,7 +356,9 @@ clean:
 	rm -f s390-linux32.c s390-linux64.c s390x-linux64.c
 	rm -f s390-linux32v1.c s390-linux32v2.c s390-linux64v1.c
 	rm -f s390-linux64v2.c s390x-linux64v1.c s390x-linux64v2.c
-	rm -f s390-te-linux32.c s390-te-linux64.c
+	rm -f s390-te-linux64.c s390x-te-linux64.c
+	rm -f s390-vx-linux64.c s390x-vx-linux64.c
+	rm -f s390-tevx-linux64.c s390x-tevx-linux64.c
 	rm -f tic6x-c64xp-linux.c tic6x-c64x-linux.c tic6x-c62x-linux.c
 	rm -f xml-builtin.c stamp-xml
 	rm -f i386-avx.c i386-avx-linux.c
@@ -684,6 +686,10 @@ s390-linux64v2.c : $(srcdir)/../regforma
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390-linux64v2.dat s390-linux64v2.c
 s390-te-linux64.c : $(srcdir)/../regformats/s390-te-linux64.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390-te-linux64.dat s390-te-linux64.c
+s390-vx-linux64.c : $(srcdir)/../regformats/s390-vx-linux64.dat $(regdat_sh)
+	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390-vx-linux64.dat s390-vx-linux64.c
+s390-tevx-linux64.c : $(srcdir)/../regformats/s390-tevx-linux64.dat $(regdat_sh)
+	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390-tevx-linux64.dat s390-tevx-linux64.c
 s390x-linux64.c : $(srcdir)/../regformats/s390x-linux64.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390x-linux64.dat s390x-linux64.c
 s390x-linux64v1.c : $(srcdir)/../regformats/s390x-linux64v1.dat $(regdat_sh)
@@ -692,6 +698,10 @@ s390x-linux64v2.c : $(srcdir)/../regform
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390x-linux64v2.dat s390x-linux64v2.c
 s390x-te-linux64.c : $(srcdir)/../regformats/s390x-te-linux64.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390x-te-linux64.dat s390x-te-linux64.c
+s390x-vx-linux64.c : $(srcdir)/../regformats/s390x-vx-linux64.dat $(regdat_sh)
+	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390x-vx-linux64.dat s390x-vx-linux64.c
+s390x-tevx-linux64.c : $(srcdir)/../regformats/s390x-tevx-linux64.dat $(regdat_sh)
+	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/s390x-tevx-linux64.dat s390x-tevx-linux64.c
 
 tic6x-c64xp-linux.c : $(srcdir)/../regformats/tic6x-c64xp-linux.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/tic6x-c64xp-linux.dat tic6x-c64xp-linux.c
Index: gdb-7.9.1/gdb/gdbserver/configure.srv
===================================================================
--- gdb-7.9.1.orig/gdb/gdbserver/configure.srv	2015-07-10 16:18:29.000000000 +0200
+++ gdb-7.9.1/gdb/gdbserver/configure.srv	2015-07-10 16:19:13.000000000 +0200
@@ -260,10 +260,14 @@ case "${target}" in
 			srv_regobj="${srv_regobj} s390-linux64v1.o"
 			srv_regobj="${srv_regobj} s390-linux64v2.o"
 			srv_regobj="${srv_regobj} s390-te-linux64.o"
+			srv_regobj="${srv_regobj} s390-vx-linux64.o"
+			srv_regobj="${srv_regobj} s390-tevx-linux64.o"
 			srv_regobj="${srv_regobj} s390x-linux64.o"
 			srv_regobj="${srv_regobj} s390x-linux64v1.o"
 			srv_regobj="${srv_regobj} s390x-linux64v2.o"
 			srv_regobj="${srv_regobj} s390x-te-linux64.o"
+			srv_regobj="${srv_regobj} s390x-vx-linux64.o"
+			srv_regobj="${srv_regobj} s390x-tevx-linux64.o"
 			srv_tgtobj="$srv_linux_obj linux-s390-low.o"
 			srv_xmlfiles="s390-linux32.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390-linux32v1.xml"
@@ -272,16 +276,21 @@ case "${target}" in
 			srv_xmlfiles="${srv_xmlfiles} s390-linux64v1.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390-linux64v2.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390-te-linux64.xml"
+			srv_xmlfiles="${srv_xmlfiles} s390-vx-linux64.xml"
+			srv_xmlfiles="${srv_xmlfiles} s390-tevx-linux64.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390x-linux64.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390x-linux64v1.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390x-linux64v2.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390x-te-linux64.xml"
+			srv_xmlfiles="${srv_xmlfiles} s390x-vx-linux64.xml"
+			srv_xmlfiles="${srv_xmlfiles} s390x-tevx-linux64.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390-core32.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390-core64.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390x-core64.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390-acr.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390-fpr.xml"
 			srv_xmlfiles="${srv_xmlfiles} s390-tdb.xml"
+			srv_xmlfiles="${srv_xmlfiles} s390-vx.xml"
 			srv_linux_usrregs=yes
 			srv_linux_regsets=yes
 			srv_linux_thread_db=yes
Index: gdb-7.9.1/gdb/gdbserver/linux-s390-low.c
===================================================================
--- gdb-7.9.1.orig/gdb/gdbserver/linux-s390-low.c	2015-07-10 16:18:29.000000000 +0200
+++ gdb-7.9.1/gdb/gdbserver/linux-s390-low.c	2015-07-10 16:19:13.000000000 +0200
@@ -36,6 +36,10 @@
 #define HWCAP_S390_TE 1024
 #endif
 
+#ifndef HWCAP_S390_VX
+#define HWCAP_S390_VX 2048
+#endif
+
 #ifndef PTRACE_GETREGSET
 #define PTRACE_GETREGSET 0x4204
 #endif
@@ -72,6 +76,14 @@ extern const struct target_desc *tdesc_s
 void init_registers_s390_te_linux64 (void);
 extern const struct target_desc *tdesc_s390_te_linux64;
 
+/* Defined in auto-generated file s390-vx-linux64.c.  */
+void init_registers_s390_vx_linux64 (void);
+extern const struct target_desc *tdesc_s390_vx_linux64;
+
+/* Defined in auto-generated file s390-tevx-linux64.c.  */
+void init_registers_s390_tevx_linux64 (void);
+extern const struct target_desc *tdesc_s390_tevx_linux64;
+
 /* Defined in auto-generated file s390x-linux64.c.  */
 void init_registers_s390x_linux64 (void);
 extern const struct target_desc *tdesc_s390x_linux64;
@@ -88,6 +100,14 @@ extern const struct target_desc *tdesc_s
 void init_registers_s390x_te_linux64 (void);
 extern const struct target_desc *tdesc_s390x_te_linux64;
 
+/* Defined in auto-generated file s390x-vx-linux64.c.  */
+void init_registers_s390x_vx_linux64 (void);
+extern const struct target_desc *tdesc_s390x_vx_linux64;
+
+/* Defined in auto-generated file s390x-tevx-linux64.c.  */
+void init_registers_s390x_tevx_linux64 (void);
+extern const struct target_desc *tdesc_s390x_tevx_linux64;
+
 #define s390_num_regs 52
 
 static int s390_regmap[] = {
@@ -324,6 +344,46 @@ s390_store_tdb (struct regcache *regcach
     supply_register (regcache, tr0 + i, (const char *) buf + 8 * (16 + i));
 }
 
+static void
+s390_fill_vxrs_low (struct regcache *regcache, void *buf)
+{
+  int v0 = find_regno (regcache->tdesc, "v0l");
+  int i;
+
+  for (i = 0; i < 16; i++)
+    collect_register (regcache, v0 + i, (char *) buf + 8 * i);
+}
+
+static void
+s390_store_vxrs_low (struct regcache *regcache, const void *buf)
+{
+  int v0 = find_regno (regcache->tdesc, "v0l");
+  int i;
+
+  for (i = 0; i < 16; i++)
+    supply_register (regcache, v0 + i, (const char *) buf + 8 * i);
+}
+
+static void
+s390_fill_vxrs_high (struct regcache *regcache, void *buf)
+{
+  int v16 = find_regno (regcache->tdesc, "v16");
+  int i;
+
+  for (i = 0; i < 16; i++)
+    collect_register (regcache, v16 + i, (char *) buf + 16 * i);
+}
+
+static void
+s390_store_vxrs_high (struct regcache *regcache, const void *buf)
+{
+  int v16 = find_regno (regcache->tdesc, "v16");
+  int i;
+
+  for (i = 0; i < 16; i++)
+    supply_register (regcache, v16 + i, (const char *) buf + 16 * i);
+}
+
 static struct regset_info s390_regsets[] = {
   { 0, 0, 0, 0, GENERAL_REGS, s390_fill_gregset, NULL },
   /* Last break address is read-only; no fill function.  */
@@ -334,6 +394,10 @@ static struct regset_info s390_regsets[]
   /* TDB is read-only.  */
   { PTRACE_GETREGSET, -1, NT_S390_TDB, 0, EXTENDED_REGS,
     NULL, s390_store_tdb },
+  { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_S390_VXRS_LOW, 0,
+    EXTENDED_REGS, s390_fill_vxrs_low, s390_store_vxrs_low },
+  { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_S390_VXRS_HIGH, 0,
+    EXTENDED_REGS, s390_fill_vxrs_high, s390_store_vxrs_high },
   { 0, 0, 0, -1, -1, NULL, NULL }
 };
 
@@ -439,6 +503,8 @@ s390_arch_setup (void)
   int have_regset_system_call
     = s390_check_regset (pid, NT_S390_SYSTEM_CALL, 4);
   int have_regset_tdb = s390_check_regset (pid, NT_S390_TDB, 256);
+  int have_regset_vxrs = s390_check_regset (pid, NT_S390_VXRS_LOW, 128)
+    && s390_check_regset (pid, NT_S390_VXRS_HIGH, 256);
 
   /* Assume 31-bit inferior process.  */
   if (have_regset_system_call)
@@ -464,8 +530,14 @@ s390_arch_setup (void)
 	if (have_regset_tdb)
 	  have_regset_tdb =
 	    (s390_get_hwcap (tdesc_s390x_linux64v2) & HWCAP_S390_TE) != 0;
-
-	if (have_regset_tdb)
+	if (have_regset_vxrs)
+	  have_regset_vxrs =
+	    (s390_get_hwcap (tdesc_s390x_linux64v2) & HWCAP_S390_VX) != 0;
+
+	if (have_regset_vxrs)
+	  tdesc = (have_regset_tdb ? tdesc_s390x_tevx_linux64 :
+		   tdesc_s390x_vx_linux64);
+	else if (have_regset_tdb)
 	  tdesc = tdesc_s390x_te_linux64;
 	else if (have_regset_system_call)
 	  tdesc = tdesc_s390x_linux64v2;
@@ -482,8 +554,13 @@ s390_arch_setup (void)
 	have_hwcap_s390_high_gprs = 1;
 	if (have_regset_tdb)
 	  have_regset_tdb = (s390_get_hwcap (tdesc) & HWCAP_S390_TE) != 0;
+	if (have_regset_vxrs)
+	  have_regset_vxrs = (s390_get_hwcap (tdesc) & HWCAP_S390_VX) != 0;
 
-	if (have_regset_tdb)
+	if (have_regset_vxrs)
+	  tdesc = (have_regset_tdb ? tdesc_s390_tevx_linux64 :
+		   tdesc_s390_vx_linux64);
+	else if (have_regset_tdb)
 	  tdesc = tdesc_s390_te_linux64;
 	else if (have_regset_system_call)
 	  tdesc = tdesc_s390_linux64v2;
@@ -508,6 +585,13 @@ s390_arch_setup (void)
 	  break;
 	case NT_S390_TDB:
 	  regset->size = have_regset_tdb ? 256 : 0;
+	  break;
+	case NT_S390_VXRS_LOW:
+	  regset->size = have_regset_vxrs ? 128 : 0;
+	  break;
+	case NT_S390_VXRS_HIGH:
+	  regset->size = have_regset_vxrs ? 256 : 0;
+	  break;
 	default:
 	  break;
 	}
@@ -615,10 +699,14 @@ initialize_low_arch (void)
   init_registers_s390_linux64v1 ();
   init_registers_s390_linux64v2 ();
   init_registers_s390_te_linux64 ();
+  init_registers_s390_vx_linux64 ();
+  init_registers_s390_tevx_linux64 ();
   init_registers_s390x_linux64 ();
   init_registers_s390x_linux64v1 ();
   init_registers_s390x_linux64v2 ();
   init_registers_s390x_te_linux64 ();
+  init_registers_s390x_vx_linux64 ();
+  init_registers_s390x_tevx_linux64 ();
 
   initialize_regsets_info (&s390_regsets_info);
 #ifdef __s390x__