gdb/
[deliverable/binutils-gdb.git] / gdb / ppc-sysv-tdep.c
index 703ca4db40a314450f5e395f650ea5a676fe950e..a4521abb265e699a532975aba8a9d2434f283dc4 100644 (file)
@@ -1,8 +1,8 @@
 /* Target-dependent code for PowerPC systems using the SVR4 ABI
    for GDB, the GNU debugger.
 
-   Copyright (C) 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 2000-2003, 2005, 2007-2012 Free Software Foundation,
+   Inc.
 
    This file is part of GDB.
 
 #include "target.h"
 #include "objfiles.h"
 #include "infcall.h"
+#include "dwarf2.h"
 
-/* Pass the arguments in either registers, or in the stack. Using the
+
+/* Check whether FTPYE is a (pointer to) function type that should use
+   the OpenCL vector ABI.  */
+
+static int
+ppc_sysv_use_opencl_abi (struct type *ftype)
+{
+  ftype = check_typedef (ftype);
+
+  if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
+    ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
+
+  return (TYPE_CODE (ftype) == TYPE_CODE_FUNC
+         && TYPE_CALLING_CONVENTION (ftype) == DW_CC_GDB_IBM_OpenCL);
+}
+
+/* Pass the arguments in either registers, or in the stack.  Using the
    ppc sysv ABI, the first eight words of the argument list (that might
    be less than eight parameters if some parameters occupy more than one
    word) are passed in r3..r10 registers.  float and double parameters are
-   passed in fpr's, in addition to that. Rest of the parameters if any
-   are passed in user stack. 
+   passed in fpr's, in addition to that.  Rest of the parameters if any
+   are passed in user stack.
 
    If the function is returning a structure, then the return address is passed
    in r3, then the first 7 words of the parametes can be passed in registers,
-   starting from r4. */
+   starting from r4.  */
 
 CORE_ADDR
 ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
@@ -50,6 +67,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST saved_sp;
   int argspace = 0;            /* 0 is an initial wrong guess.  */
   int write_pass;
@@ -327,6 +345,126 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                 Hence we increase freg even when writing to memory.  */
              freg += 2;
            }
+         else if (len < 16
+                  && TYPE_CODE (type) == TYPE_CODE_ARRAY
+                  && TYPE_VECTOR (type)
+                  && opencl_abi)
+           {
+             /* OpenCL vectors shorter than 16 bytes are passed as if
+                a series of independent scalars.  */
+             struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
+             int i, nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
+
+             for (i = 0; i < nelt; i++)
+               {
+                 const gdb_byte *elval = val + i * TYPE_LENGTH (eltype);
+
+                 if (TYPE_CODE (eltype) == TYPE_CODE_FLT && !tdep->soft_float)
+                   {
+                     if (freg <= 8)
+                       {
+                         if (write_pass)
+                           {
+                             int regnum = tdep->ppc_fp0_regnum + freg;
+                             gdb_byte regval[MAX_REGISTER_SIZE];
+                             struct type *regtype
+                               = register_type (gdbarch, regnum);
+                             convert_typed_floating (elval, eltype,
+                                                     regval, regtype);
+                             regcache_cooked_write (regcache, regnum, regval);
+                           }
+                         freg++;
+                       }
+                     else
+                       {
+                         argoffset = align_up (argoffset, len);
+                         if (write_pass)
+                           write_memory (sp + argoffset, val, len);
+                         argoffset += len;
+                       }
+                   }
+                 else if (TYPE_LENGTH (eltype) == 8)
+                   {
+                     if (greg > 9)
+                       {
+                         /* Just in case GREG was 10.  */
+                         greg = 11;
+                         argoffset = align_up (argoffset, 8);
+                         if (write_pass)
+                           write_memory (sp + argoffset, elval,
+                                         TYPE_LENGTH (eltype));
+                         argoffset += 8;
+                       }
+                     else
+                       {
+                         /* Must start on an odd register - r3/r4 etc.  */
+                         if ((greg & 1) == 0)
+                           greg++;
+                         if (write_pass)
+                           {
+                             int regnum = tdep->ppc_gp0_regnum + greg;
+                             regcache_cooked_write (regcache,
+                                                    regnum + 0, elval + 0);
+                             regcache_cooked_write (regcache,
+                                                    regnum + 1, elval + 4);
+                           }
+                         greg += 2;
+                       }
+                   }
+                 else
+                   {
+                     gdb_byte word[MAX_REGISTER_SIZE];
+                     store_unsigned_integer (word, tdep->wordsize, byte_order,
+                                             unpack_long (eltype, elval));
+
+                     if (greg <= 10)
+                       {
+                         if (write_pass)
+                           regcache_cooked_write (regcache,
+                                                  tdep->ppc_gp0_regnum + greg,
+                                                  word);
+                         greg++;
+                       }
+                     else
+                       {
+                         argoffset = align_up (argoffset, tdep->wordsize);
+                         if (write_pass)
+                           write_memory (sp + argoffset, word, tdep->wordsize);
+                         argoffset += tdep->wordsize;
+                       }
+                   }
+               }
+           }
+         else if (len >= 16
+                  && TYPE_CODE (type) == TYPE_CODE_ARRAY
+                  && TYPE_VECTOR (type)
+                  && opencl_abi)
+           {
+             /* OpenCL vectors 16 bytes or longer are passed as if
+                a series of AltiVec vectors.  */
+             int i;
+
+             for (i = 0; i < len / 16; i++)
+               {
+                 const gdb_byte *elval = val + i * 16;
+
+                 if (vreg <= 13)
+                   {
+                     if (write_pass)
+                       regcache_cooked_write (regcache,
+                                              tdep->ppc_vr0_regnum + vreg,
+                                              elval);
+                     vreg++;
+                   }
+                 else
+                   {
+                     argoffset = align_up (argoffset, 16);
+                     if (write_pass)
+                       write_memory (sp + argoffset, elval, 16);
+                     argoffset += 16;
+                   }
+               }
+           }
          else if (len == 16
                   && TYPE_CODE (type) == TYPE_CODE_ARRAY
                   && TYPE_VECTOR (type)
@@ -387,7 +525,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                  || TYPE_CODE (type) == TYPE_CODE_UNION)
                {
                  /* Structs and large values are put in an
-                    aligned stack slot ... */
+                    aligned stack slot ...  */
                  if (TYPE_CODE (type) == TYPE_CODE_ARRAY
                      && TYPE_VECTOR (type)
                      && len >= 16)
@@ -443,7 +581,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
       /* The psABI says that "A caller of a function that takes a
         variable argument list shall set condition register bit 6 to
         1 if it passes one or more arguments in the floating-point
-        registers. It is strongly recommended that the caller set the
+        registers.  It is strongly recommended that the caller set the
         bit to 0 otherwise..."  Doing this for normal functions too
         shouldn't hurt.  */
       if (write_pass)
@@ -531,7 +669,7 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
     }
   else
     /* Can't happen.  */
-    internal_error (__FILE__, __LINE__, "Unknown decimal float size.");
+    internal_error (__FILE__, __LINE__, _("Unknown decimal float size."));
 
   return RETURN_VALUE_REGISTER_CONVENTION;
 }
@@ -552,13 +690,17 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
    when returned in general-purpose registers.  */
 
 static enum return_value_convention
-do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
-                         struct regcache *regcache, gdb_byte *readbuf,
-                         const gdb_byte *writebuf, int broken_gcc)
+do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
+                         struct type *type, struct regcache *regcache,
+                         gdb_byte *readbuf, const gdb_byte *writebuf,
+                         int broken_gcc)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
+
   gdb_assert (tdep->wordsize == 4);
+
   if (TYPE_CODE (type) == TYPE_CODE_FLT
       && TYPE_LENGTH (type) <= 8
       && !tdep->soft_float)
@@ -587,7 +729,8 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
   if (TYPE_CODE (type) == TYPE_CODE_FLT
       && TYPE_LENGTH (type) == 16
       && !tdep->soft_float
-      && (gdbarch_long_double_format (gdbarch) == floatformats_ibm_long_double))
+      && (gdbarch_long_double_format (gdbarch)
+         == floatformats_ibm_long_double))
     {
       /* IBM long double stored in f1 and f2.  */
       if (readbuf)
@@ -606,7 +749,8 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
     }
   if (TYPE_LENGTH (type) == 16
       && ((TYPE_CODE (type) == TYPE_CODE_FLT
-          && (gdbarch_long_double_format (gdbarch) == floatformats_ibm_long_double))
+          && (gdbarch_long_double_format (gdbarch)
+              == floatformats_ibm_long_double))
          || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && tdep->soft_float)))
     {
       /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
@@ -689,6 +833,83 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
        }
       return RETURN_VALUE_REGISTER_CONVENTION;
     }
+  /* OpenCL vectors < 16 bytes are returned as distinct
+     scalars in f1..f2 or r3..r10.  */
+  if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+      && TYPE_VECTOR (type)
+      && TYPE_LENGTH (type) < 16
+      && opencl_abi)
+    {
+      struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
+      int i, nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
+
+      for (i = 0; i < nelt; i++)
+       {
+         int offset = i * TYPE_LENGTH (eltype);
+
+         if (TYPE_CODE (eltype) == TYPE_CODE_FLT)
+           {
+             int regnum = tdep->ppc_fp0_regnum + 1 + i;
+             gdb_byte regval[MAX_REGISTER_SIZE];
+             struct type *regtype = register_type (gdbarch, regnum);
+
+             if (writebuf != NULL)
+               {
+                 convert_typed_floating (writebuf + offset, eltype,
+                                         regval, regtype);
+                 regcache_cooked_write (regcache, regnum, regval);
+               }
+             if (readbuf != NULL)
+               {
+                 regcache_cooked_read (regcache, regnum, regval);
+                 convert_typed_floating (regval, regtype,
+                                         readbuf + offset, eltype);
+               }
+           }
+         else
+           {
+             int regnum = tdep->ppc_gp0_regnum + 3 + i;
+             ULONGEST regval;
+
+             if (writebuf != NULL)
+               {
+                 regval = unpack_long (eltype, writebuf + offset);
+                 regcache_cooked_write_unsigned (regcache, regnum, regval);
+               }
+             if (readbuf != NULL)
+               {
+                 regcache_cooked_read_unsigned (regcache, regnum, &regval);
+                 store_unsigned_integer (readbuf + offset,
+                                         TYPE_LENGTH (eltype), byte_order,
+                                         regval);
+               }
+           }
+       }
+
+      return RETURN_VALUE_REGISTER_CONVENTION;
+    }
+  /* OpenCL vectors >= 16 bytes are returned in v2..v9.  */
+  if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+      && TYPE_VECTOR (type)
+      && TYPE_LENGTH (type) >= 16
+      && opencl_abi)
+    {
+      int n_regs = TYPE_LENGTH (type) / 16;
+      int i;
+
+      for (i = 0; i < n_regs; i++)
+       {
+         int offset = i * 16;
+         int regnum = tdep->ppc_vr0_regnum + 2 + i;
+
+         if (writebuf != NULL)
+           regcache_cooked_write (regcache, regnum, writebuf + offset);
+         if (readbuf != NULL)
+           regcache_cooked_read (regcache, regnum, readbuf + offset);
+       }
+
+      return RETURN_VALUE_REGISTER_CONVENTION;
+    }
   if (TYPE_LENGTH (type) == 16
       && TYPE_CODE (type) == TYPE_CODE_ARRAY
       && TYPE_VECTOR (type)
@@ -820,23 +1041,25 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
 }
 
 enum return_value_convention
-ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
                           struct type *valtype, struct regcache *regcache,
                           gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf,
-                                  writebuf, 0);
+  return do_ppc_sysv_return_value (gdbarch,
+                                  function ? value_type (function) : NULL,
+                                  valtype, regcache, readbuf, writebuf, 0);
 }
 
 enum return_value_convention
 ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch,
-                                 struct type *func_type,
+                                 struct value *function,
                                  struct type *valtype,
                                  struct regcache *regcache,
                                  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf,
-                                  writebuf, 1);
+  return do_ppc_sysv_return_value (gdbarch,
+                                  function ? value_type (function) : NULL,
+                                  valtype, regcache, readbuf, writebuf, 1);
 }
 
 /* The helper function for 64-bit SYSV push_dummy_call.  Converts the
@@ -880,15 +1103,16 @@ convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr)
   return 1;
 }
 
-/* Pass the arguments in either registers, or in the stack. Using the
+/* Pass the arguments in either registers, or in the stack.  Using the
    ppc 64 bit SysV ABI.
 
    This implements a dumbed down version of the ABI.  It always writes
    values to memory, GPR and FPR, even when not necessary.  Doing this
-   greatly simplifies the logic. */
+   greatly simplifies the logic.  */
 
 CORE_ADDR
-ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
+ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
+                               struct value *function,
                                struct regcache *regcache, CORE_ADDR bp_addr,
                                int nargs, struct value **args, CORE_ADDR sp,
                                int struct_return, CORE_ADDR struct_addr)
@@ -896,17 +1120,18 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   CORE_ADDR func_addr = find_function_addr (function, NULL);
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST back_chain;
   /* See for-loop comment below.  */
   int write_pass;
-  /* Size of the Altivec's vector parameter region, the final value is
+  /* Size of the by-reference parameter copy region, the final value is
      computed in the for-loop below.  */
-  LONGEST vparam_size = 0;
+  LONGEST refparam_size = 0;
   /* Size of the general parameter region, the final value is computed
      in the for-loop below.  */
   LONGEST gparam_size = 0;
   /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
-     calls to align_up(), align_down(), etc.  because this makes it
+     calls to align_up(), align_down(), etc. because this makes it
      easier to reuse this code (in a copy/paste sense) in the future,
      but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
      at some point makes it easier to verify that this function is
@@ -945,28 +1170,28 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
       /* Next available vector register for vector arguments.  */
       int vreg = 2;
       /* The address, at which the next general purpose parameter
-         (integer, struct, float, ...) should be saved.  */
+         (integer, struct, float, vector, ...) should be saved.  */
       CORE_ADDR gparam;
-      /* Address, at which the next Altivec vector parameter should be
-         saved.  */
-      CORE_ADDR vparam;
+      /* The address, at which the next by-reference parameter
+        (non-Altivec vector, variably-sized type) should be saved.  */
+      CORE_ADDR refparam;
 
       if (!write_pass)
        {
-         /* During the first pass, GPARAM and VPARAM are more like
+         /* During the first pass, GPARAM and REFPARAM are more like
             offsets (start address zero) than addresses.  That way
             they accumulate the total stack space each region
             requires.  */
          gparam = 0;
-         vparam = 0;
+         refparam = 0;
        }
       else
        {
          /* Decrement the stack pointer making space for the Altivec
-            and general on-stack parameters.  Set vparam and gparam
+            and general on-stack parameters.  Set refparam and gparam
             to their corresponding regions.  */
-         vparam = align_down (sp - vparam_size, 16);
-         gparam = align_down (vparam - gparam_size, 16);
+         refparam = align_down (sp - refparam_size, 16);
+         gparam = align_down (refparam - gparam_size, 16);
          /* Add in space for the TOC, link editor double word,
             compiler double word, LR save area, CR save area.  */
          sp = align_down (gparam - 48, 16);
@@ -1140,28 +1365,156 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
              greg += 2;
              gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
            }
-         else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type)
+         else if (TYPE_LENGTH (type) < 16
                   && TYPE_CODE (type) == TYPE_CODE_ARRAY
-                  && tdep->ppc_vr0_regnum >= 0)
+                  && TYPE_VECTOR (type)
+                  && opencl_abi)
            {
-             /* In the Altivec ABI, vectors go in the vector
-                registers v2 .. v13, or when that runs out, a vector
-                annex which goes above all the normal parameters.
-                NOTE: cagney/2003-09-21: This is a guess based on the
-                PowerOpen Altivec ABI.  */
-             if (vreg <= 13)
+             /* OpenCL vectors shorter than 16 bytes are passed as if
+                a series of independent scalars.  */
+             struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
+             int i, nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
+
+             for (i = 0; i < nelt; i++)
                {
+                 const gdb_byte *elval = val + i * TYPE_LENGTH (eltype);
+
+                 if (TYPE_CODE (eltype) == TYPE_CODE_FLT)
+                   {
+                     if (write_pass)
+                       {
+                         gdb_byte regval[MAX_REGISTER_SIZE];
+                         const gdb_byte *p;
+
+                         if (TYPE_LENGTH (eltype) == 4)
+                           {
+                             memcpy (regval, elval, 4);
+                             memcpy (regval + 4, elval, 4);
+                             p = regval;
+                           }
+                         else
+                           p = elval;
+
+                         write_memory (gparam, p, 8);
+
+                         if (freg <= 13)
+                           {
+                             int regnum = tdep->ppc_fp0_regnum + freg;
+                             struct type *regtype
+                               = register_type (gdbarch, regnum);
+
+                             convert_typed_floating (elval, eltype,
+                                                     regval, regtype);
+                             regcache_cooked_write (regcache, regnum, regval);
+                           }
+
+                         if (greg <= 10)
+                           regcache_cooked_write (regcache,
+                                                  tdep->ppc_gp0_regnum + greg,
+                                                  regval);
+                       }
+
+                     freg++;
+                     greg++;
+                     gparam = align_up (gparam + 8, tdep->wordsize);
+                   }
+                 else
+                   {
+                     if (write_pass)
+                       {
+                         ULONGEST word = unpack_long (eltype, elval);
+                         if (greg <= 10)
+                           regcache_cooked_write_unsigned
+                             (regcache, tdep->ppc_gp0_regnum + greg, word);
+
+                         write_memory_unsigned_integer
+                           (gparam, tdep->wordsize, byte_order, word);
+                       }
+
+                     greg++;
+                     gparam = align_up (gparam + TYPE_LENGTH (eltype),
+                                        tdep->wordsize);
+                   }
+               }
+           }
+         else if (TYPE_LENGTH (type) >= 16
+                  && TYPE_CODE (type) == TYPE_CODE_ARRAY
+                  && TYPE_VECTOR (type)
+                  && opencl_abi)
+           {
+             /* OpenCL vectors 16 bytes or longer are passed as if
+                a series of AltiVec vectors.  */
+             int i;
+
+             for (i = 0; i < TYPE_LENGTH (type) / 16; i++)
+               {
+                 const gdb_byte *elval = val + i * 16;
+
+                 gparam = align_up (gparam, 16);
+                 greg += greg & 1;
+
                  if (write_pass)
+                   {
+                     if (vreg <= 13)
+                       regcache_cooked_write (regcache,
+                                              tdep->ppc_vr0_regnum + vreg,
+                                              elval);
+
+                     write_memory (gparam, elval, 16);
+                   }
+
+                 greg += 2;
+                 vreg++;
+                 gparam += 16;
+               }
+           }
+         else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type)
+                  && TYPE_CODE (type) == TYPE_CODE_ARRAY
+                  && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
+           {
+             /* In the Altivec ABI, vectors go in the vector registers
+                v2 .. v13, as well as the parameter area -- always at
+                16-byte aligned addresses.  */
+
+             gparam = align_up (gparam, 16);
+             greg += greg & 1;
+
+             if (write_pass)
+               {
+                 if (vreg <= 13)
                    regcache_cooked_write (regcache,
                                           tdep->ppc_vr0_regnum + vreg, val);
-                 vreg++;
+
+                 write_memory (gparam, val, TYPE_LENGTH (type));
                }
-             else
+
+             greg += 2;
+             vreg++;
+             gparam += 16;
+           }
+         else if (TYPE_LENGTH (type) >= 16 && TYPE_VECTOR (type)
+                  && TYPE_CODE (type) == TYPE_CODE_ARRAY)
+           {
+             /* Non-Altivec vectors are passed by reference.  */
+
+             /* Copy value onto the stack ...  */
+             refparam = align_up (refparam, 16);
+             if (write_pass)
+               write_memory (refparam, val, TYPE_LENGTH (type));
+
+             /* ... and pass a pointer to the copy as parameter.  */
+             if (write_pass)
                {
-                 if (write_pass)
-                   write_memory (vparam, val, TYPE_LENGTH (type));
-                 vparam = align_up (vparam + TYPE_LENGTH (type), 16);
+                 if (greg <= 10)
+                   regcache_cooked_write_unsigned (regcache,
+                                                   tdep->ppc_gp0_regnum +
+                                                   greg, refparam);
+                 write_memory_unsigned_integer (gparam, tdep->wordsize,
+                                                byte_order, refparam);
                }
+             greg++;
+             gparam = align_up (gparam + tdep->wordsize, tdep->wordsize);
+             refparam = align_up (refparam + TYPE_LENGTH (type), tdep->wordsize);
            }
          else if ((TYPE_CODE (type) == TYPE_CODE_INT
                    || TYPE_CODE (type) == TYPE_CODE_ENUM
@@ -1305,7 +1658,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
       if (!write_pass)
        {
          /* Save the true region sizes ready for the second pass.  */
-         vparam_size = vparam;
+         refparam_size = refparam;
          /* Make certain that the general parameter save area is at
             least the minimum 8 registers (or doublewords) in size.  */
          if (greg < 8)
@@ -1326,10 +1679,14 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
 
   /* Use the func_addr to find the descriptor, and use that to find
-     the TOC.  */
+     the TOC.  If we're calling via a function pointer, the pointer
+     itself identifies the descriptor.  */
   {
-    CORE_ADDR desc_addr;
-    if (convert_code_addr_to_desc_addr (func_addr, &desc_addr))
+    struct type *ftype = check_typedef (value_type (function));
+    CORE_ADDR desc_addr = value_as_address (function);
+
+    if (TYPE_CODE (ftype) == TYPE_CODE_PTR
+       || convert_code_addr_to_desc_addr (func_addr, &desc_addr))
       {
        /* The TOC is the second double word in the descriptor.  */
        CORE_ADDR toc =
@@ -1355,12 +1712,14 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
    location; when READBUF is non-NULL, fill the buffer from the
    corresponding register return-value location.  */
 enum return_value_convention
-ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
                             struct type *valtype, struct regcache *regcache,
                             gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  struct type *func_type = function ? value_type (function) : NULL;
+  int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
 
   /* This function exists to support a calling convention that
      requires floating-point registers.  It shouldn't be used on
@@ -1423,6 +1782,83 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type,
        regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf);
       return RETURN_VALUE_REGISTER_CONVENTION;
     }
+  /* OpenCL vectors < 16 bytes are returned as distinct
+     scalars in f1..f2 or r3..r10.  */
+  if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
+      && TYPE_VECTOR (valtype)
+      && TYPE_LENGTH (valtype) < 16
+      && opencl_abi)
+    {
+      struct type *eltype = check_typedef (TYPE_TARGET_TYPE (valtype));
+      int i, nelt = TYPE_LENGTH (valtype) / TYPE_LENGTH (eltype);
+
+      for (i = 0; i < nelt; i++)
+       {
+         int offset = i * TYPE_LENGTH (eltype);
+
+         if (TYPE_CODE (eltype) == TYPE_CODE_FLT)
+           {
+             int regnum = tdep->ppc_fp0_regnum + 1 + i;
+             gdb_byte regval[MAX_REGISTER_SIZE];
+             struct type *regtype = register_type (gdbarch, regnum);
+
+             if (writebuf != NULL)
+               {
+                 convert_typed_floating (writebuf + offset, eltype,
+                                         regval, regtype);
+                 regcache_cooked_write (regcache, regnum, regval);
+               }
+             if (readbuf != NULL)
+               {
+                 regcache_cooked_read (regcache, regnum, regval);
+                 convert_typed_floating (regval, regtype,
+                                         readbuf + offset, eltype);
+               }
+           }
+         else
+           {
+             int regnum = tdep->ppc_gp0_regnum + 3 + i;
+             ULONGEST regval;
+
+             if (writebuf != NULL)
+               {
+                 regval = unpack_long (eltype, writebuf + offset);
+                 regcache_cooked_write_unsigned (regcache, regnum, regval);
+               }
+             if (readbuf != NULL)
+               {
+                 regcache_cooked_read_unsigned (regcache, regnum, &regval);
+                 store_unsigned_integer (readbuf + offset,
+                                         TYPE_LENGTH (eltype), byte_order,
+                                         regval);
+               }
+           }
+       }
+
+      return RETURN_VALUE_REGISTER_CONVENTION;
+    }
+  /* OpenCL vectors >= 16 bytes are returned in v2..v9.  */
+  if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
+      && TYPE_VECTOR (valtype)
+      && TYPE_LENGTH (valtype) >= 16
+      && opencl_abi)
+    {
+      int n_regs = TYPE_LENGTH (valtype) / 16;
+      int i;
+
+      for (i = 0; i < n_regs; i++)
+       {
+         int offset = i * 16;
+         int regnum = tdep->ppc_vr0_regnum + 2 + i;
+
+         if (writebuf != NULL)
+           regcache_cooked_write (regcache, regnum, writebuf + offset);
+         if (readbuf != NULL)
+           regcache_cooked_read (regcache, regnum, readbuf + offset);
+       }
+
+      return RETURN_VALUE_REGISTER_CONVENTION;
+    }
   /* Array type has more than one use.  */
   if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
     {
@@ -1443,12 +1879,14 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type,
        }
       /* A VMX vector is returned in v2.  */
       if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
-        && TYPE_VECTOR (valtype) && tdep->ppc_vr0_regnum >= 0)
+         && TYPE_VECTOR (valtype)
+         && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
         {
           if (readbuf)
             regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
           if (writebuf)
-            regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf);
+            regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2,
+                                  writebuf);
           return RETURN_VALUE_REGISTER_CONVENTION;
         }
     }
This page took 0.034122 seconds and 4 git commands to generate.