Blame SOURCES/gdb-rhbz1182151-ibm-z13-16of22.patch

0b42f8
commit 417c80f9e456477935cdc74461d35630dfdbfdff
0b42f8
Author: Andreas Arnez <arnez@linux.vnet.ibm.com>
0b42f8
Date:   Mon Apr 27 11:38:47 2015 +0200
0b42f8
0b42f8
    S390: Vector ABI support
0b42f8
    
0b42f8
    With the S390 vector ABI, vector registers are used for passing vector
0b42f8
    arguments and for returning a vector.  Support this ABI in inferior
0b42f8
    function calls and when setting or retrieving a function's return
0b42f8
    value.
0b42f8
    
0b42f8
    gdb/ChangeLog:
0b42f8
    
0b42f8
    	* s390-linux-tdep.c: Include "elf/s390.h" and "elf-bfd.h".
0b42f8
    	(enum s390_vector_abi_kind): New enum.
0b42f8
    	(struct gdbarch_tdep)<vector_abi>: New field.
0b42f8
    	(s390_effective_inner_type): Add parameter min_size.  Stop
0b42f8
    	unwrapping if the inner type is smaller than min_size.
0b42f8
    	(s390_function_arg_float): Adjust call to
0b42f8
    	s390_effective_inner_type.
0b42f8
    	(s390_function_arg_vector): New function.
0b42f8
    	(s390_function_arg_integer): Adjust comment.
0b42f8
    	(struct s390_arg_state)<vr>: New field.
0b42f8
    	(s390_handle_arg): Add parameter 'is_unnamed'.  Pass vector
0b42f8
    	arguments according to vector ABI when appropriate.
0b42f8
    	(s390_push_dummy_call): Initialize the argument state's field
0b42f8
    	'vr'.  Adjust calls to s390_handle_arg.
0b42f8
    	(s390_register_return_value): Handle vector return values.
0b42f8
    	(s390_return_value): Apply the "register" return value convention
0b42f8
    	to a vector when appropriate.
0b42f8
    	(s390_gdbarch_init): Initialize tdep->vector_abi.
0b42f8
    	* NEWS: Announce S390 vector ABI support.
0b42f8
0b42f8
### a/gdb/ChangeLog
0b42f8
### b/gdb/ChangeLog
0b42f8
## -1,5 +1,27 @@
0b42f8
 2015-04-27  Andreas Arnez  <arnez@linux.vnet.ibm.com>
0b42f8
 
0b42f8
+	* s390-linux-tdep.c: Include "elf/s390.h" and "elf-bfd.h".
0b42f8
+	(enum s390_vector_abi_kind): New enum.
0b42f8
+	(struct gdbarch_tdep)<vector_abi>: New field.
0b42f8
+	(s390_effective_inner_type): Add parameter min_size.  Stop
0b42f8
+	unwrapping if the inner type is smaller than min_size.
0b42f8
+	(s390_function_arg_float): Adjust call to
0b42f8
+	s390_effective_inner_type.
0b42f8
+	(s390_function_arg_vector): New function.
0b42f8
+	(s390_function_arg_integer): Adjust comment.
0b42f8
+	(struct s390_arg_state)<vr>: New field.
0b42f8
+	(s390_handle_arg): Add parameter 'is_unnamed'.  Pass vector
0b42f8
+	arguments according to vector ABI when appropriate.
0b42f8
+	(s390_push_dummy_call): Initialize the argument state's field
0b42f8
+	'vr'.  Adjust calls to s390_handle_arg.
0b42f8
+	(s390_register_return_value): Handle vector return values.
0b42f8
+	(s390_return_value): Apply the "register" return value convention
0b42f8
+	to a vector when appropriate.
0b42f8
+	(s390_gdbarch_init): Initialize tdep->vector_abi.
0b42f8
+	* NEWS: Announce S390 vector ABI support.
0b42f8
+
0b42f8
+2015-04-27  Andreas Arnez  <arnez@linux.vnet.ibm.com>
0b42f8
+
0b42f8
 	* s390-linux-tdep.c (s390_return_value_convention): Remove
0b42f8
 	function.  Inline its logic...
0b42f8
 	(s390_return_value): ...here.  Instead, move the handling of the
0b42f8
Index: gdb-7.6.1/gdb/NEWS
0b42f8
===================================================================
0b42f8
--- gdb-7.6.1.orig/gdb/NEWS	2016-02-21 22:34:07.599040574 +0100
0b42f8
+++ gdb-7.6.1/gdb/NEWS	2016-02-21 22:34:13.476086880 +0100
0b42f8
@@ -21,6 +21,8 @@
0b42f8
 * GDB now supports access to vector registers on S/390 GNU/Linux
0b42f8
   targets.
0b42f8
 
0b42f8
+* GDB now supports the vector ABI on S/390 GNU/Linux targets.
0b42f8
+
0b42f8
 * GDB now honors the content of the file /proc/PID/coredump_filter
0b42f8
   (PID is the process ID) on GNU/Linux systems.  This file can be used
0b42f8
   to specify the types of memory mappings that will be included in a
0b42f8
Index: gdb-7.6.1/gdb/s390-tdep.c
0b42f8
===================================================================
0b42f8
--- gdb-7.6.1.orig/gdb/s390-tdep.c	2016-02-21 22:34:07.599040574 +0100
0b42f8
+++ gdb-7.6.1/gdb/s390-tdep.c	2016-02-21 22:35:45.273797475 +0100
0b42f8
@@ -52,7 +52,9 @@
0b42f8
 #include "user-regs.h"
0b42f8
 #include "cli/cli-utils.h"
0b42f8
 #include <ctype.h>
0b42f8
-#include <elf.h>
0b42f8
+//#include <elf.h> // Conflicts with "elf-bfd.h".
0b42f8
+#include "elf/s390.h"
0b42f8
+#include "elf-bfd.h"
0b42f8
 
0b42f8
 #include "features/s390-linux32.c"
0b42f8
 #include "features/s390-linux32v1.c"
0b42f8
@@ -70,6 +72,12 @@
0b42f8
 #include "features/s390x-vx-linux64.c"
0b42f8
 #include "features/s390x-tevx-linux64.c"
0b42f8
 
0b42f8
+enum s390_vector_abi_kind
0b42f8
+{
0b42f8
+  S390_VECTOR_ABI_NONE,
0b42f8
+  S390_VECTOR_ABI_128
0b42f8
+};
0b42f8
+
0b42f8
 /* The tdep structure.  */
0b42f8
 
0b42f8
 struct gdbarch_tdep
0b42f8
@@ -77,6 +85,9 @@
0b42f8
   /* ABI version.  */
0b42f8
   enum { ABI_LINUX_S390, ABI_LINUX_ZSERIES } abi;
0b42f8
 
0b42f8
+  /* Vector ABI.  */
0b42f8
+  enum s390_vector_abi_kind vector_abi;
0b42f8
+
0b42f8
   /* Pseudo register numbers.  */
0b42f8
   int gpr_full_regnum;
0b42f8
   int pc_regnum;
0b42f8
@@ -2552,14 +2563,24 @@
0b42f8
      float x;
0b42f8
      struct { float x };
0b42f8
      struct { struct { float x; } x; };
0b42f8
-     struct { struct { struct { float x; } x; } x; };  */
0b42f8
+     struct { struct { struct { float x; } x; } x; };
0b42f8
+
0b42f8
+   However, if an inner type is smaller than MIN_SIZE, abort the
0b42f8
+   unwrapping.  */
0b42f8
 
0b42f8
 static struct type *
0b42f8
-s390_effective_inner_type (struct type *type)
0b42f8
+s390_effective_inner_type (struct type *type, unsigned int min_size)
0b42f8
 {
0b42f8
   while (TYPE_CODE (type) == TYPE_CODE_STRUCT
0b42f8
 	 && TYPE_NFIELDS (type) == 1)
0b42f8
-    type = check_typedef (TYPE_FIELD_TYPE (type, 0));
0b42f8
+    {
0b42f8
+      struct type *inner = check_typedef (TYPE_FIELD_TYPE (type, 0));
0b42f8
+
0b42f8
+      if (TYPE_LENGTH (inner) < min_size)
0b42f8
+	break;
0b42f8
+      type = inner;
0b42f8
+    }
0b42f8
+
0b42f8
   return type;
0b42f8
 }
0b42f8
 
0b42f8
@@ -2576,12 +2597,26 @@
0b42f8
 
0b42f8
   /* A struct containing just a float or double is passed like a float
0b42f8
      or double.  */
0b42f8
-  type = s390_effective_inner_type (type);
0b42f8
+  type = s390_effective_inner_type (type, 0);
0b42f8
 
0b42f8
   return (TYPE_CODE (type) == TYPE_CODE_FLT
0b42f8
 	  || TYPE_CODE (type) == TYPE_CODE_DECFLOAT);
0b42f8
 }
0b42f8
 
0b42f8
+/* Return non-zero if TYPE should be passed like a vector.  */
0b42f8
+
0b42f8
+static int
0b42f8
+s390_function_arg_vector (struct type *type)
0b42f8
+{
0b42f8
+  if (TYPE_LENGTH (type) > 16)
0b42f8
+    return 0;
0b42f8
+
0b42f8
+  /* Structs containing just a vector are passed like a vector.  */
0b42f8
+  type = s390_effective_inner_type (type, TYPE_LENGTH (type));
0b42f8
+
0b42f8
+  return TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type);
0b42f8
+}
0b42f8
+
0b42f8
 /* Determine whether N is a power of two.  */
0b42f8
 
0b42f8
 static int
0b42f8
@@ -2591,8 +2626,8 @@
0b42f8
 }
0b42f8
 
0b42f8
 /* For an argument whose type is TYPE and which is not passed like a
0b42f8
-   float, return non-zero if it should be passed like "int" or "long
0b42f8
-   long".  */
0b42f8
+   float or vector, return non-zero if it should be passed like "int"
0b42f8
+   or "long long".  */
0b42f8
 
0b42f8
 static int
0b42f8
 s390_function_arg_integer (struct type *type)
0b42f8
@@ -2622,9 +2657,9 @@
0b42f8
   {
0b42f8
     /* Register cache, or NULL, if we are in "preparation mode".  */
0b42f8
     struct regcache *regcache;
0b42f8
-    /* Next available general/floating-point register for argument
0b42f8
-       passing.  */
0b42f8
-    int gr, fr;
0b42f8
+    /* Next available general/floating-point/vector register for
0b42f8
+       argument passing.  */
0b42f8
+    int gr, fr, vr;
0b42f8
     /* Current pointer to copy area (grows downwards).  */
0b42f8
     CORE_ADDR copy;
0b42f8
     /* Current pointer to parameter area (grows upwards).  */
0b42f8
@@ -2639,7 +2674,7 @@
0b42f8
 static void
0b42f8
 s390_handle_arg (struct s390_arg_state *as, struct value *arg,
0b42f8
 		 struct gdbarch_tdep *tdep, int word_size,
0b42f8
-		 enum bfd_endian byte_order)
0b42f8
+		 enum bfd_endian byte_order, int is_unnamed)
0b42f8
 {
0b42f8
   struct type *type = check_typedef (value_type (arg));
0b42f8
   ULONGEST length = TYPE_LENGTH (type);
0b42f8
@@ -2671,6 +2706,28 @@
0b42f8
 			  length);
0b42f8
 	}
0b42f8
     }
0b42f8
+  else if (tdep->vector_abi == S390_VECTOR_ABI_128
0b42f8
+	   && s390_function_arg_vector (type))
0b42f8
+    {
0b42f8
+      static const char use_vr[] = {24, 26, 28, 30, 25, 27, 29, 31};
0b42f8
+
0b42f8
+      if (!is_unnamed && as->vr < ARRAY_SIZE (use_vr))
0b42f8
+	{
0b42f8
+	  int regnum = S390_V24_REGNUM + use_vr[as->vr] - 24;
0b42f8
+
0b42f8
+	  if (write_mode)
0b42f8
+	    regcache_cooked_write_part (as->regcache, regnum,
0b42f8
+					0, length,
0b42f8
+					value_contents (arg));
0b42f8
+	  as->vr++;
0b42f8
+	}
0b42f8
+      else
0b42f8
+	{
0b42f8
+	  if (write_mode)
0b42f8
+	    write_memory (as->argp, value_contents (arg), length);
0b42f8
+	  as->argp = align_up (as->argp + length, word_size);
0b42f8
+	}
0b42f8
+    }
0b42f8
   else if (s390_function_arg_integer (type) && length <= word_size)
0b42f8
     {
0b42f8
       ULONGEST val;
0b42f8
@@ -2783,10 +2840,15 @@
0b42f8
   int i;
0b42f8
   struct s390_arg_state arg_state, arg_prep;
0b42f8
   CORE_ADDR param_area_start, new_sp;
0b42f8
+  struct type *ftype = check_typedef (value_type (function));
0b42f8
+
0b42f8
+  if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
0b42f8
+    ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
0b42f8
 
0b42f8
   arg_prep.copy = sp;
0b42f8
   arg_prep.gr = struct_return ? 3 : 2;
0b42f8
   arg_prep.fr = 0;
0b42f8
+  arg_prep.vr = 0;
0b42f8
   arg_prep.argp = 0;
0b42f8
   arg_prep.regcache = NULL;
0b42f8
 
0b42f8
@@ -2796,7 +2858,8 @@
0b42f8
   /* Update arg_state.copy with the start of the reference-to-copy area
0b42f8
      and arg_state.argp with the size of the parameter area.  */
0b42f8
   for (i = 0; i < nargs; i++)
0b42f8
-    s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order);
0b42f8
+    s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order,
0b42f8
+		     TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype));
0b42f8
 
0b42f8
   param_area_start = align_down (arg_state.copy - arg_state.argp, 8);
0b42f8
 
0b42f8
@@ -2822,7 +2885,8 @@
0b42f8
 
0b42f8
   /* Write all parameters.  */
0b42f8
   for (i = 0; i < nargs; i++)
0b42f8
-    s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order);
0b42f8
+    s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order,
0b42f8
+		     TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype));
0b42f8
 
0b42f8
   /* Store return PSWA.  In 31-bit mode, keep addressing mode bit.  */
0b42f8
   if (word_size == 4)
0b42f8
@@ -2888,6 +2952,16 @@
0b42f8
 	regcache_cooked_read_part (regcache, S390_F0_REGNUM,
0b42f8
 				   0, length, out);
0b42f8
     }
0b42f8
+  else if (code == TYPE_CODE_ARRAY)
0b42f8
+    {
0b42f8
+      /* Vector: left-aligned in v24.  */
0b42f8
+      if (in != NULL)
0b42f8
+	regcache_cooked_write_part (regcache, S390_V24_REGNUM,
0b42f8
+				    0, length, in);
0b42f8
+      else
0b42f8
+	regcache_cooked_read_part (regcache, S390_V24_REGNUM,
0b42f8
+				   0, length, out);
0b42f8
+    }
0b42f8
   else if (length <= word_size)
0b42f8
     {
0b42f8
       /* Integer: zero- or sign-extended in r2.  */
0b42f8
@@ -2939,10 +3013,15 @@
0b42f8
     {
0b42f8
     case TYPE_CODE_STRUCT:
0b42f8
     case TYPE_CODE_UNION:
0b42f8
-    case TYPE_CODE_ARRAY:
0b42f8
     case TYPE_CODE_COMPLEX:
0b42f8
       rvc = RETURN_VALUE_STRUCT_CONVENTION;
0b42f8
       break;
0b42f8
+    case TYPE_CODE_ARRAY:
0b42f8
+      rvc = (gdbarch_tdep (gdbarch)->vector_abi == S390_VECTOR_ABI_128
0b42f8
+	     && TYPE_LENGTH (type) <= 16 && TYPE_VECTOR (type))
0b42f8
+	? RETURN_VALUE_REGISTER_CONVENTION
0b42f8
+	: RETURN_VALUE_STRUCT_CONVENTION;
0b42f8
+      break;
0b42f8
     default:
0b42f8
       rvc = TYPE_LENGTH (type) <= 8
0b42f8
 	? RETURN_VALUE_REGISTER_CONVENTION
0b42f8
@@ -3038,6 +3117,7 @@
0b42f8
   struct gdbarch *gdbarch;
0b42f8
   struct gdbarch_tdep *tdep;
0b42f8
   int tdep_abi;
0b42f8
+  enum s390_vector_abi_kind vector_abi;
0b42f8
   int have_upper = 0;
0b42f8
   int have_linux_v1 = 0;
0b42f8
   int have_linux_v2 = 0;
0b42f8
@@ -3220,6 +3300,18 @@
0b42f8
 	}
0b42f8
     }
0b42f8
 
0b42f8
+  /* Determine vector ABI.  */
0b42f8
+  vector_abi = S390_VECTOR_ABI_NONE;
0b42f8
+#ifdef HAVE_ELF
0b42f8
+  if (have_vx
0b42f8
+      && info.abfd != NULL
0b42f8
+      && info.abfd->format == bfd_object
0b42f8
+      && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
0b42f8
+      && bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
0b42f8
+				   Tag_GNU_S390_ABI_Vector) == 2)
0b42f8
+    vector_abi = S390_VECTOR_ABI_128;
0b42f8
+#endif
0b42f8
+
0b42f8
   /* Find a candidate among extant architectures.  */
0b42f8
   for (arches = gdbarch_list_lookup_by_info (arches, &info;;
0b42f8
        arches != NULL;
0b42f8
@@ -3230,6 +3322,8 @@
0b42f8
 	continue;
0b42f8
       if (tdep->abi != tdep_abi)
0b42f8
 	continue;
0b42f8
+      if (tdep->vector_abi != vector_abi)
0b42f8
+	continue;
0b42f8
       if ((tdep->gpr_full_regnum != -1) != have_upper)
0b42f8
 	continue;
0b42f8
       if (tdesc_data != NULL)
0b42f8
@@ -3240,6 +3334,7 @@
0b42f8
   /* Otherwise create a new gdbarch for the specified machine type.  */
0b42f8
   tdep = XCALLOC (1, struct gdbarch_tdep);
0b42f8
   tdep->abi = tdep_abi;
0b42f8
+  tdep->vector_abi = vector_abi;
0b42f8
   tdep->have_linux_v1 = have_linux_v1;
0b42f8
   tdep->have_linux_v2 = have_linux_v2;
0b42f8
   tdep->have_tdb = have_tdb;