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

2c2fa1
commit 4e65a17e62c7c2f3c0409d9769cca2e916a88379
2c2fa1
Author: Andreas Arnez <arnez@linux.vnet.ibm.com>
2c2fa1
Date:   Mon Apr 27 11:38:47 2015 +0200
2c2fa1
2c2fa1
    S390: Re-arrange implementation of s390_return_value
2c2fa1
    
2c2fa1
    Move related logic in the implementation of s390_return_value closer
2c2fa1
    together.  This makes it easier to read and extend.
2c2fa1
    
2c2fa1
    gdb/ChangeLog:
2c2fa1
    
2c2fa1
    	* s390-linux-tdep.c (s390_return_value_convention): Remove
2c2fa1
    	function.  Inline its logic...
2c2fa1
    	(s390_return_value): ...here.  Instead, move the handling of the
2c2fa1
    	"register" return value convention...
2c2fa1
    	(s390_register_return_value): ...here.  New function.
2c2fa1
2c2fa1
### a/gdb/ChangeLog
2c2fa1
### b/gdb/ChangeLog
2c2fa1
## -1,5 +1,13 @@
2c2fa1
 2015-04-27  Andreas Arnez  <arnez@linux.vnet.ibm.com>
2c2fa1
 
2c2fa1
+	* s390-linux-tdep.c (s390_return_value_convention): Remove
2c2fa1
+	function.  Inline its logic...
2c2fa1
+	(s390_return_value): ...here.  Instead, move the handling of the
2c2fa1
+	"register" return value convention...
2c2fa1
+	(s390_register_return_value): ...here.  New function.
2c2fa1
+
2c2fa1
+2015-04-27  Andreas Arnez  <arnez@linux.vnet.ibm.com>
2c2fa1
+
2c2fa1
 	* s390-linux-tdep.c
2c2fa1
 	(is_float_singleton): Remove function.  Move the "singleton" part
2c2fa1
 	of the logic...
2c2fa1
Index: gdb-7.6.1/gdb/s390-tdep.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/s390-tdep.c	2016-02-21 22:31:47.311935241 +0100
2c2fa1
+++ gdb-7.6.1/gdb/s390-tdep.c	2016-02-21 22:31:59.326029901 +0100
2c2fa1
@@ -2865,110 +2865,98 @@
2c2fa1
 }
2c2fa1
 
2c2fa1
 
2c2fa1
-/* Function return value access.  */
2c2fa1
+/* Helper for s390_return_value: Set or retrieve a function return
2c2fa1
+   value if it resides in a register.  */
2c2fa1
 
2c2fa1
-static enum return_value_convention
2c2fa1
-s390_return_value_convention (struct gdbarch *gdbarch, struct type *type)
2c2fa1
+static void
2c2fa1
+s390_register_return_value (struct gdbarch *gdbarch, struct type *type,
2c2fa1
+			    struct regcache *regcache,
2c2fa1
+			    gdb_byte *out, const gdb_byte *in)
2c2fa1
 {
2c2fa1
-  if (TYPE_LENGTH (type) > 8)
2c2fa1
-    return RETURN_VALUE_STRUCT_CONVENTION;
2c2fa1
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2c2fa1
+  int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2c2fa1
+  int length = TYPE_LENGTH (type);
2c2fa1
+  int code = TYPE_CODE (type);
2c2fa1
 
2c2fa1
-  switch (TYPE_CODE (type))
2c2fa1
+  if (code == TYPE_CODE_FLT || code == TYPE_CODE_DECFLOAT)
2c2fa1
     {
2c2fa1
-    case TYPE_CODE_STRUCT:
2c2fa1
-    case TYPE_CODE_UNION:
2c2fa1
-    case TYPE_CODE_ARRAY:
2c2fa1
-    case TYPE_CODE_COMPLEX:
2c2fa1
-      return RETURN_VALUE_STRUCT_CONVENTION;
2c2fa1
-
2c2fa1
-    default:
2c2fa1
-      return RETURN_VALUE_REGISTER_CONVENTION;
2c2fa1
+      /* Float-like value: left-aligned in f0.  */
2c2fa1
+      if (in != NULL)
2c2fa1
+	regcache_cooked_write_part (regcache, S390_F0_REGNUM,
2c2fa1
+				    0, length, in);
2c2fa1
+      else
2c2fa1
+	regcache_cooked_read_part (regcache, S390_F0_REGNUM,
2c2fa1
+				   0, length, out);
2c2fa1
+    }
2c2fa1
+  else if (length <= word_size)
2c2fa1
+    {
2c2fa1
+      /* Integer: zero- or sign-extended in r2.  */
2c2fa1
+      if (out != NULL)
2c2fa1
+	regcache_cooked_read_part (regcache, S390_R2_REGNUM,
2c2fa1
+				   word_size - length, length, out);
2c2fa1
+      else if (TYPE_UNSIGNED (type))
2c2fa1
+	regcache_cooked_write_unsigned
2c2fa1
+	  (regcache, S390_R2_REGNUM,
2c2fa1
+	   extract_unsigned_integer (in, length, byte_order));
2c2fa1
+      else
2c2fa1
+	regcache_cooked_write_signed
2c2fa1
+	  (regcache, S390_R2_REGNUM,
2c2fa1
+	   extract_signed_integer (in, length, byte_order));
2c2fa1
     }
2c2fa1
+  else if (length == 2 * word_size)
2c2fa1
+    {
2c2fa1
+      /* Double word: in r2 and r3.  */
2c2fa1
+      if (in != NULL)
2c2fa1
+	{
2c2fa1
+	  regcache_cooked_write (regcache, S390_R2_REGNUM, in);
2c2fa1
+	  regcache_cooked_write (regcache, S390_R3_REGNUM,
2c2fa1
+				 in + word_size);
2c2fa1
+	}
2c2fa1
+      else
2c2fa1
+	{
2c2fa1
+	  regcache_cooked_read (regcache, S390_R2_REGNUM, out);
2c2fa1
+	  regcache_cooked_read (regcache, S390_R3_REGNUM,
2c2fa1
+				out + word_size);
2c2fa1
+	}
2c2fa1
+    }
2c2fa1
+  else
2c2fa1
+    internal_error (__FILE__, __LINE__, _("invalid return type"));
2c2fa1
 }
2c2fa1
 
2c2fa1
+
2c2fa1
+/* Implement the 'return_value' gdbarch method.  */
2c2fa1
+
2c2fa1
 static enum return_value_convention
2c2fa1
 s390_return_value (struct gdbarch *gdbarch, struct value *function,
2c2fa1
 		   struct type *type, struct regcache *regcache,
2c2fa1
 		   gdb_byte *out, const gdb_byte *in)
2c2fa1
 {
2c2fa1
-  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2c2fa1
-  int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2c2fa1
   enum return_value_convention rvc;
2c2fa1
-  int length;
2c2fa1
 
2c2fa1
   type = check_typedef (type);
2c2fa1
-  rvc = s390_return_value_convention (gdbarch, type);
2c2fa1
-  length = TYPE_LENGTH (type);
2c2fa1
 
2c2fa1
-  if (in)
2c2fa1
+  switch (TYPE_CODE (type))
2c2fa1
     {
2c2fa1
-      switch (rvc)
2c2fa1
-	{
2c2fa1
-	case RETURN_VALUE_REGISTER_CONVENTION:
2c2fa1
-	  if (TYPE_CODE (type) == TYPE_CODE_FLT
2c2fa1
-	      || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
2c2fa1
-	    {
2c2fa1
-	      /* When we store a single-precision value in an FP register,
2c2fa1
-		 it occupies the leftmost bits.  */
2c2fa1
-	      regcache_cooked_write_part (regcache, S390_F0_REGNUM, 
2c2fa1
-					  0, length, in);
2c2fa1
-	    }
2c2fa1
-	  else if (length <= word_size)
2c2fa1
-	    {
2c2fa1
-	      /* Integer arguments are always extended to word size.  */
2c2fa1
-	      if (TYPE_UNSIGNED (type))
2c2fa1
-		regcache_cooked_write_unsigned (regcache, S390_R2_REGNUM,
2c2fa1
-			extract_unsigned_integer (in, length, byte_order));
2c2fa1
-	      else
2c2fa1
-		regcache_cooked_write_signed (regcache, S390_R2_REGNUM,
2c2fa1
-			extract_signed_integer (in, length, byte_order));
2c2fa1
-	    }
2c2fa1
-	  else if (length == 2*word_size)
2c2fa1
-	    {
2c2fa1
-	      regcache_cooked_write (regcache, S390_R2_REGNUM, in);
2c2fa1
-	      regcache_cooked_write (regcache, S390_R3_REGNUM, in + word_size);
2c2fa1
-	    }
2c2fa1
-	  else
2c2fa1
-	    internal_error (__FILE__, __LINE__, _("invalid return type"));
2c2fa1
-	  break;
2c2fa1
-
2c2fa1
-	case RETURN_VALUE_STRUCT_CONVENTION:
2c2fa1
-	  error (_("Cannot set function return value."));
2c2fa1
-	  break;
2c2fa1
-	}
2c2fa1
+    case TYPE_CODE_STRUCT:
2c2fa1
+    case TYPE_CODE_UNION:
2c2fa1
+    case TYPE_CODE_ARRAY:
2c2fa1
+    case TYPE_CODE_COMPLEX:
2c2fa1
+      rvc = RETURN_VALUE_STRUCT_CONVENTION;
2c2fa1
+      break;
2c2fa1
+    default:
2c2fa1
+      rvc = TYPE_LENGTH (type) <= 8
2c2fa1
+	? RETURN_VALUE_REGISTER_CONVENTION
2c2fa1
+	: RETURN_VALUE_STRUCT_CONVENTION;
2c2fa1
     }
2c2fa1
-  else if (out)
2c2fa1
+
2c2fa1
+  if (in != NULL || out != NULL)
2c2fa1
     {
2c2fa1
-      switch (rvc)
2c2fa1
-	{
2c2fa1
-	case RETURN_VALUE_REGISTER_CONVENTION:
2c2fa1
-	  if (TYPE_CODE (type) == TYPE_CODE_FLT
2c2fa1
-	      || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
2c2fa1
-	    {
2c2fa1
-	      /* When we store a single-precision value in an FP register,
2c2fa1
-		 it occupies the leftmost bits.  */
2c2fa1
-	      regcache_cooked_read_part (regcache, S390_F0_REGNUM, 
2c2fa1
-					 0, length, out);
2c2fa1
-	    }
2c2fa1
-	  else if (length <= word_size)
2c2fa1
-	    {
2c2fa1
-	      /* Integer arguments occupy the rightmost bits.  */
2c2fa1
-	      regcache_cooked_read_part (regcache, S390_R2_REGNUM, 
2c2fa1
-					 word_size - length, length, out);
2c2fa1
-	    }
2c2fa1
-	  else if (length == 2*word_size)
2c2fa1
-	    {
2c2fa1
-	      regcache_cooked_read (regcache, S390_R2_REGNUM, out);
2c2fa1
-	      regcache_cooked_read (regcache, S390_R3_REGNUM, out + word_size);
2c2fa1
-	    }
2c2fa1
-	  else
2c2fa1
-	    internal_error (__FILE__, __LINE__, _("invalid return type"));
2c2fa1
-	  break;
2c2fa1
-
2c2fa1
-	case RETURN_VALUE_STRUCT_CONVENTION:
2c2fa1
-	  error (_("Function return value unknown."));
2c2fa1
-	  break;
2c2fa1
-	}
2c2fa1
+      if (rvc == RETURN_VALUE_REGISTER_CONVENTION)
2c2fa1
+	s390_register_return_value (gdbarch, type, regcache, out, in);
2c2fa1
+      else if (in != NULL)
2c2fa1
+	error (_("Cannot set function return value."));
2c2fa1
+      else
2c2fa1
+	error (_("Function return value unknown."));
2c2fa1
     }
2c2fa1
 
2c2fa1
   return rvc;