GDB (API)
/home/stan/gdb/src/gdb/ppc-sysv-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for PowerPC systems using the SVR4 ABI
00002    for GDB, the GNU debugger.
00003 
00004    Copyright (C) 2000-2013 Free Software Foundation, Inc.
00005 
00006    This file is part of GDB.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 3 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00020 
00021 #include "defs.h"
00022 #include "gdbcore.h"
00023 #include "inferior.h"
00024 #include "regcache.h"
00025 #include "value.h"
00026 #include "gdb_string.h"
00027 #include "gdb_assert.h"
00028 #include "ppc-tdep.h"
00029 #include "target.h"
00030 #include "objfiles.h"
00031 #include "infcall.h"
00032 #include "dwarf2.h"
00033 
00034 
00035 /* Check whether FTPYE is a (pointer to) function type that should use
00036    the OpenCL vector ABI.  */
00037 
00038 static int
00039 ppc_sysv_use_opencl_abi (struct type *ftype)
00040 {
00041   ftype = check_typedef (ftype);
00042 
00043   if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
00044     ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
00045 
00046   return (TYPE_CODE (ftype) == TYPE_CODE_FUNC
00047           && TYPE_CALLING_CONVENTION (ftype) == DW_CC_GDB_IBM_OpenCL);
00048 }
00049 
00050 /* Pass the arguments in either registers, or in the stack.  Using the
00051    ppc sysv ABI, the first eight words of the argument list (that might
00052    be less than eight parameters if some parameters occupy more than one
00053    word) are passed in r3..r10 registers.  float and double parameters are
00054    passed in fpr's, in addition to that.  Rest of the parameters if any
00055    are passed in user stack.
00056 
00057    If the function is returning a structure, then the return address is passed
00058    in r3, then the first 7 words of the parametes can be passed in registers,
00059    starting from r4.  */
00060 
00061 CORE_ADDR
00062 ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
00063                               struct regcache *regcache, CORE_ADDR bp_addr,
00064                               int nargs, struct value **args, CORE_ADDR sp,
00065                               int struct_return, CORE_ADDR struct_addr)
00066 {
00067   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00068   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00069   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
00070   ULONGEST saved_sp;
00071   int argspace = 0;             /* 0 is an initial wrong guess.  */
00072   int write_pass;
00073 
00074   gdb_assert (tdep->wordsize == 4);
00075 
00076   regcache_cooked_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch),
00077                                  &saved_sp);
00078 
00079   /* Go through the argument list twice.
00080 
00081      Pass 1: Figure out how much new stack space is required for
00082      arguments and pushed values.  Unlike the PowerOpen ABI, the SysV
00083      ABI doesn't reserve any extra space for parameters which are put
00084      in registers, but does always push structures and then pass their
00085      address.
00086 
00087      Pass 2: Replay the same computation but this time also write the
00088      values out to the target.  */
00089 
00090   for (write_pass = 0; write_pass < 2; write_pass++)
00091     {
00092       int argno;
00093       /* Next available floating point register for float and double
00094          arguments.  */
00095       int freg = 1;
00096       /* Next available general register for non-float, non-vector
00097          arguments.  */
00098       int greg = 3;
00099       /* Next available vector register for vector arguments.  */
00100       int vreg = 2;
00101       /* Arguments start above the "LR save word" and "Back chain".  */
00102       int argoffset = 2 * tdep->wordsize;
00103       /* Structures start after the arguments.  */
00104       int structoffset = argoffset + argspace;
00105 
00106       /* If the function is returning a `struct', then the first word
00107          (which will be passed in r3) is used for struct return
00108          address.  In that case we should advance one word and start
00109          from r4 register to copy parameters.  */
00110       if (struct_return)
00111         {
00112           if (write_pass)
00113             regcache_cooked_write_signed (regcache,
00114                                           tdep->ppc_gp0_regnum + greg,
00115                                           struct_addr);
00116           greg++;
00117         }
00118 
00119       for (argno = 0; argno < nargs; argno++)
00120         {
00121           struct value *arg = args[argno];
00122           struct type *type = check_typedef (value_type (arg));
00123           int len = TYPE_LENGTH (type);
00124           const bfd_byte *val = value_contents (arg);
00125 
00126           if (TYPE_CODE (type) == TYPE_CODE_FLT && len <= 8
00127               && !tdep->soft_float)
00128             {
00129               /* Floating point value converted to "double" then
00130                  passed in an FP register, when the registers run out,
00131                  8 byte aligned stack is used.  */
00132               if (freg <= 8)
00133                 {
00134                   if (write_pass)
00135                     {
00136                       /* Always store the floating point value using
00137                          the register's floating-point format.  */
00138                       gdb_byte regval[MAX_REGISTER_SIZE];
00139                       struct type *regtype
00140                         = register_type (gdbarch, tdep->ppc_fp0_regnum + freg);
00141                       convert_typed_floating (val, type, regval, regtype);
00142                       regcache_cooked_write (regcache,
00143                                              tdep->ppc_fp0_regnum + freg,
00144                                              regval);
00145                     }
00146                   freg++;
00147                 }
00148               else
00149                 {
00150                   /* The SysV ABI tells us to convert floats to
00151                      doubles before writing them to an 8 byte aligned
00152                      stack location.  Unfortunately GCC does not do
00153                      that, and stores floats into 4 byte aligned
00154                      locations without converting them to doubles.
00155                      Since there is no know compiler that actually
00156                      follows the ABI here, we implement the GCC
00157                      convention.  */
00158 
00159                   /* Align to 4 bytes or 8 bytes depending on the type of
00160                      the argument (float or double).  */
00161                   argoffset = align_up (argoffset, len);
00162                   if (write_pass)
00163                       write_memory (sp + argoffset, val, len);
00164                   argoffset += len;
00165                 }
00166             }
00167           else if (TYPE_CODE (type) == TYPE_CODE_FLT
00168                    && len == 16
00169                    && !tdep->soft_float
00170                    && (gdbarch_long_double_format (gdbarch)
00171                        == floatformats_ibm_long_double))
00172             {
00173               /* IBM long double passed in two FP registers if
00174                  available, otherwise 8-byte aligned stack.  */
00175               if (freg <= 7)
00176                 {
00177                   if (write_pass)
00178                     {
00179                       regcache_cooked_write (regcache,
00180                                              tdep->ppc_fp0_regnum + freg,
00181                                              val);
00182                       regcache_cooked_write (regcache,
00183                                              tdep->ppc_fp0_regnum + freg + 1,
00184                                              val + 8);
00185                     }
00186                   freg += 2;
00187                 }
00188               else
00189                 {
00190                   argoffset = align_up (argoffset, 8);
00191                   if (write_pass)
00192                     write_memory (sp + argoffset, val, len);
00193                   argoffset += 16;
00194                 }
00195             }
00196           else if (len == 8
00197                    && (TYPE_CODE (type) == TYPE_CODE_INT        /* long long */
00198                        || TYPE_CODE (type) == TYPE_CODE_FLT     /* double */
00199                        || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT
00200                            && tdep->soft_float)))
00201             {
00202               /* "long long" or soft-float "double" or "_Decimal64"
00203                  passed in an odd/even register pair with the low
00204                  addressed word in the odd register and the high
00205                  addressed word in the even register, or when the
00206                  registers run out an 8 byte aligned stack
00207                  location.  */
00208               if (greg > 9)
00209                 {
00210                   /* Just in case GREG was 10.  */
00211                   greg = 11;
00212                   argoffset = align_up (argoffset, 8);
00213                   if (write_pass)
00214                     write_memory (sp + argoffset, val, len);
00215                   argoffset += 8;
00216                 }
00217               else
00218                 {
00219                   /* Must start on an odd register - r3/r4 etc.  */
00220                   if ((greg & 1) == 0)
00221                     greg++;
00222                   if (write_pass)
00223                     {
00224                       regcache_cooked_write (regcache,
00225                                              tdep->ppc_gp0_regnum + greg + 0,
00226                                              val + 0);
00227                       regcache_cooked_write (regcache,
00228                                              tdep->ppc_gp0_regnum + greg + 1,
00229                                              val + 4);
00230                     }
00231                   greg += 2;
00232                 }
00233             }
00234           else if (len == 16
00235                    && ((TYPE_CODE (type) == TYPE_CODE_FLT
00236                         && (gdbarch_long_double_format (gdbarch)
00237                             == floatformats_ibm_long_double))
00238                        || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT
00239                            && tdep->soft_float)))
00240             {
00241               /* Soft-float IBM long double or _Decimal128 passed in
00242                  four consecutive registers, or on the stack.  The
00243                  registers are not necessarily odd/even pairs.  */
00244               if (greg > 7)
00245                 {
00246                   greg = 11;
00247                   argoffset = align_up (argoffset, 8);
00248                   if (write_pass)
00249                     write_memory (sp + argoffset, val, len);
00250                   argoffset += 16;
00251                 }
00252               else
00253                 {
00254                   if (write_pass)
00255                     {
00256                       regcache_cooked_write (regcache,
00257                                              tdep->ppc_gp0_regnum + greg + 0,
00258                                              val + 0);
00259                       regcache_cooked_write (regcache,
00260                                              tdep->ppc_gp0_regnum + greg + 1,
00261                                              val + 4);
00262                       regcache_cooked_write (regcache,
00263                                              tdep->ppc_gp0_regnum + greg + 2,
00264                                              val + 8);
00265                       regcache_cooked_write (regcache,
00266                                              tdep->ppc_gp0_regnum + greg + 3,
00267                                              val + 12);
00268                     }
00269                   greg += 4;
00270                 }
00271             }
00272           else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && len <= 8
00273                    && !tdep->soft_float)
00274             {
00275               /* 32-bit and 64-bit decimal floats go in f1 .. f8.  They can
00276                  end up in memory.  */
00277 
00278               if (freg <= 8)
00279                 {
00280                   if (write_pass)
00281                     {
00282                       gdb_byte regval[MAX_REGISTER_SIZE];
00283                       const gdb_byte *p;
00284 
00285                       /* 32-bit decimal floats are right aligned in the
00286                          doubleword.  */
00287                       if (TYPE_LENGTH (type) == 4)
00288                       {
00289                         memcpy (regval + 4, val, 4);
00290                         p = regval;
00291                       }
00292                       else
00293                         p = val;
00294 
00295                       regcache_cooked_write (regcache,
00296                           tdep->ppc_fp0_regnum + freg, p);
00297                     }
00298 
00299                   freg++;
00300                 }
00301               else
00302                 {
00303                   argoffset = align_up (argoffset, len);
00304 
00305                   if (write_pass)
00306                     /* Write value in the stack's parameter save area.  */
00307                     write_memory (sp + argoffset, val, len);
00308 
00309                   argoffset += len;
00310                 }
00311             }
00312           else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && len == 16
00313                    && !tdep->soft_float)
00314             {
00315               /* 128-bit decimal floats go in f2 .. f7, always in even/odd
00316                  pairs.  They can end up in memory, using two doublewords.  */
00317 
00318               if (freg <= 6)
00319                 {
00320                   /* Make sure freg is even.  */
00321                   freg += freg & 1;
00322 
00323                   if (write_pass)
00324                     {
00325                       regcache_cooked_write (regcache,
00326                                              tdep->ppc_fp0_regnum + freg, val);
00327                       regcache_cooked_write (regcache,
00328                           tdep->ppc_fp0_regnum + freg + 1, val + 8);
00329                     }
00330                 }
00331               else
00332                 {
00333                   argoffset = align_up (argoffset, 8);
00334 
00335                   if (write_pass)
00336                     write_memory (sp + argoffset, val, 16);
00337 
00338                   argoffset += 16;
00339                 }
00340 
00341               /* If a 128-bit decimal float goes to the stack because only f7
00342                  and f8 are free (thus there's no even/odd register pair
00343                  available), these registers should be marked as occupied.
00344                  Hence we increase freg even when writing to memory.  */
00345               freg += 2;
00346             }
00347           else if (len < 16
00348                    && TYPE_CODE (type) == TYPE_CODE_ARRAY
00349                    && TYPE_VECTOR (type)
00350                    && opencl_abi)
00351             {
00352               /* OpenCL vectors shorter than 16 bytes are passed as if
00353                  a series of independent scalars.  */
00354               struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
00355               int i, nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
00356 
00357               for (i = 0; i < nelt; i++)
00358                 {
00359                   const gdb_byte *elval = val + i * TYPE_LENGTH (eltype);
00360 
00361                   if (TYPE_CODE (eltype) == TYPE_CODE_FLT && !tdep->soft_float)
00362                     {
00363                       if (freg <= 8)
00364                         {
00365                           if (write_pass)
00366                             {
00367                               int regnum = tdep->ppc_fp0_regnum + freg;
00368                               gdb_byte regval[MAX_REGISTER_SIZE];
00369                               struct type *regtype
00370                                 = register_type (gdbarch, regnum);
00371                               convert_typed_floating (elval, eltype,
00372                                                       regval, regtype);
00373                               regcache_cooked_write (regcache, regnum, regval);
00374                             }
00375                           freg++;
00376                         }
00377                       else
00378                         {
00379                           argoffset = align_up (argoffset, len);
00380                           if (write_pass)
00381                             write_memory (sp + argoffset, val, len);
00382                           argoffset += len;
00383                         }
00384                     }
00385                   else if (TYPE_LENGTH (eltype) == 8)
00386                     {
00387                       if (greg > 9)
00388                         {
00389                           /* Just in case GREG was 10.  */
00390                           greg = 11;
00391                           argoffset = align_up (argoffset, 8);
00392                           if (write_pass)
00393                             write_memory (sp + argoffset, elval,
00394                                           TYPE_LENGTH (eltype));
00395                           argoffset += 8;
00396                         }
00397                       else
00398                         {
00399                           /* Must start on an odd register - r3/r4 etc.  */
00400                           if ((greg & 1) == 0)
00401                             greg++;
00402                           if (write_pass)
00403                             {
00404                               int regnum = tdep->ppc_gp0_regnum + greg;
00405                               regcache_cooked_write (regcache,
00406                                                      regnum + 0, elval + 0);
00407                               regcache_cooked_write (regcache,
00408                                                      regnum + 1, elval + 4);
00409                             }
00410                           greg += 2;
00411                         }
00412                     }
00413                   else
00414                     {
00415                       gdb_byte word[MAX_REGISTER_SIZE];
00416                       store_unsigned_integer (word, tdep->wordsize, byte_order,
00417                                               unpack_long (eltype, elval));
00418 
00419                       if (greg <= 10)
00420                         {
00421                           if (write_pass)
00422                             regcache_cooked_write (regcache,
00423                                                    tdep->ppc_gp0_regnum + greg,
00424                                                    word);
00425                           greg++;
00426                         }
00427                       else
00428                         {
00429                           argoffset = align_up (argoffset, tdep->wordsize);
00430                           if (write_pass)
00431                             write_memory (sp + argoffset, word, tdep->wordsize);
00432                           argoffset += tdep->wordsize;
00433                         }
00434                     }
00435                 }
00436             }
00437           else if (len >= 16
00438                    && TYPE_CODE (type) == TYPE_CODE_ARRAY
00439                    && TYPE_VECTOR (type)
00440                    && opencl_abi)
00441             {
00442               /* OpenCL vectors 16 bytes or longer are passed as if
00443                  a series of AltiVec vectors.  */
00444               int i;
00445 
00446               for (i = 0; i < len / 16; i++)
00447                 {
00448                   const gdb_byte *elval = val + i * 16;
00449 
00450                   if (vreg <= 13)
00451                     {
00452                       if (write_pass)
00453                         regcache_cooked_write (regcache,
00454                                                tdep->ppc_vr0_regnum + vreg,
00455                                                elval);
00456                       vreg++;
00457                     }
00458                   else
00459                     {
00460                       argoffset = align_up (argoffset, 16);
00461                       if (write_pass)
00462                         write_memory (sp + argoffset, elval, 16);
00463                       argoffset += 16;
00464                     }
00465                 }
00466             }
00467           else if (len == 16
00468                    && TYPE_CODE (type) == TYPE_CODE_ARRAY
00469                    && TYPE_VECTOR (type)
00470                    && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
00471             {
00472               /* Vector parameter passed in an Altivec register, or
00473                  when that runs out, 16 byte aligned stack location.  */
00474               if (vreg <= 13)
00475                 {
00476                   if (write_pass)
00477                     regcache_cooked_write (regcache,
00478                                            tdep->ppc_vr0_regnum + vreg, val);
00479                   vreg++;
00480                 }
00481               else
00482                 {
00483                   argoffset = align_up (argoffset, 16);
00484                   if (write_pass)
00485                     write_memory (sp + argoffset, val, 16);
00486                   argoffset += 16;
00487                 }
00488             }
00489           else if (len == 8
00490                    && TYPE_CODE (type) == TYPE_CODE_ARRAY
00491                    && TYPE_VECTOR (type)
00492                    && tdep->vector_abi == POWERPC_VEC_SPE)
00493             {
00494               /* Vector parameter passed in an e500 register, or when
00495                  that runs out, 8 byte aligned stack location.  Note
00496                  that since e500 vector and general purpose registers
00497                  both map onto the same underlying register set, a
00498                  "greg" and not a "vreg" is consumed here.  A cooked
00499                  write stores the value in the correct locations
00500                  within the raw register cache.  */
00501               if (greg <= 10)
00502                 {
00503                   if (write_pass)
00504                     regcache_cooked_write (regcache,
00505                                            tdep->ppc_ev0_regnum + greg, val);
00506                   greg++;
00507                 }
00508               else
00509                 {
00510                   argoffset = align_up (argoffset, 8);
00511                   if (write_pass)
00512                     write_memory (sp + argoffset, val, 8);
00513                   argoffset += 8;
00514                 }
00515             }
00516           else
00517             {
00518               /* Reduce the parameter down to something that fits in a
00519                  "word".  */
00520               gdb_byte word[MAX_REGISTER_SIZE];
00521               memset (word, 0, MAX_REGISTER_SIZE);
00522               if (len > tdep->wordsize
00523                   || TYPE_CODE (type) == TYPE_CODE_STRUCT
00524                   || TYPE_CODE (type) == TYPE_CODE_UNION)
00525                 {
00526                   /* Structs and large values are put in an
00527                      aligned stack slot ...  */
00528                   if (TYPE_CODE (type) == TYPE_CODE_ARRAY
00529                       && TYPE_VECTOR (type)
00530                       && len >= 16)
00531                     structoffset = align_up (structoffset, 16);
00532                   else
00533                     structoffset = align_up (structoffset, 8);
00534 
00535                   if (write_pass)
00536                     write_memory (sp + structoffset, val, len);
00537                   /* ... and then a "word" pointing to that address is
00538                      passed as the parameter.  */
00539                   store_unsigned_integer (word, tdep->wordsize, byte_order,
00540                                           sp + structoffset);
00541                   structoffset += len;
00542                 }
00543               else if (TYPE_CODE (type) == TYPE_CODE_INT)
00544                 /* Sign or zero extend the "int" into a "word".  */
00545                 store_unsigned_integer (word, tdep->wordsize, byte_order,
00546                                         unpack_long (type, val));
00547               else
00548                 /* Always goes in the low address.  */
00549                 memcpy (word, val, len);
00550               /* Store that "word" in a register, or on the stack.
00551                  The words have "4" byte alignment.  */
00552               if (greg <= 10)
00553                 {
00554                   if (write_pass)
00555                     regcache_cooked_write (regcache,
00556                                            tdep->ppc_gp0_regnum + greg, word);
00557                   greg++;
00558                 }
00559               else
00560                 {
00561                   argoffset = align_up (argoffset, tdep->wordsize);
00562                   if (write_pass)
00563                     write_memory (sp + argoffset, word, tdep->wordsize);
00564                   argoffset += tdep->wordsize;
00565                 }
00566             }
00567         }
00568 
00569       /* Compute the actual stack space requirements.  */
00570       if (!write_pass)
00571         {
00572           /* Remember the amount of space needed by the arguments.  */
00573           argspace = argoffset;
00574           /* Allocate space for both the arguments and the structures.  */
00575           sp -= (argoffset + structoffset);
00576           /* Ensure that the stack is still 16 byte aligned.  */
00577           sp = align_down (sp, 16);
00578         }
00579 
00580       /* The psABI says that "A caller of a function that takes a
00581          variable argument list shall set condition register bit 6 to
00582          1 if it passes one or more arguments in the floating-point
00583          registers.  It is strongly recommended that the caller set the
00584          bit to 0 otherwise..."  Doing this for normal functions too
00585          shouldn't hurt.  */
00586       if (write_pass)
00587         {
00588           ULONGEST cr;
00589 
00590           regcache_cooked_read_unsigned (regcache, tdep->ppc_cr_regnum, &cr);
00591           if (freg > 1)
00592             cr |= 0x02000000;
00593           else
00594             cr &= ~0x02000000;
00595           regcache_cooked_write_unsigned (regcache, tdep->ppc_cr_regnum, cr);
00596         }
00597     }
00598 
00599   /* Update %sp.   */
00600   regcache_cooked_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp);
00601 
00602   /* Write the backchain (it occupies WORDSIZED bytes).  */
00603   write_memory_signed_integer (sp, tdep->wordsize, byte_order, saved_sp);
00604 
00605   /* Point the inferior function call's return address at the dummy's
00606      breakpoint.  */
00607   regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
00608 
00609   return sp;
00610 }
00611 
00612 /* Handle the return-value conventions for Decimal Floating Point values
00613    in both ppc32 and ppc64, which are the same.  */
00614 static int
00615 get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
00616                                 struct regcache *regcache, gdb_byte *readbuf,
00617                                 const gdb_byte *writebuf)
00618 {
00619   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00620 
00621   gdb_assert (TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT);
00622 
00623   /* 32-bit and 64-bit decimal floats in f1.  */
00624   if (TYPE_LENGTH (valtype) <= 8)
00625     {
00626       if (writebuf != NULL)
00627         {
00628           gdb_byte regval[MAX_REGISTER_SIZE];
00629           const gdb_byte *p;
00630 
00631           /* 32-bit decimal float is right aligned in the doubleword.  */
00632           if (TYPE_LENGTH (valtype) == 4)
00633             {
00634               memcpy (regval + 4, writebuf, 4);
00635               p = regval;
00636             }
00637           else
00638             p = writebuf;
00639 
00640           regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, p);
00641         }
00642       if (readbuf != NULL)
00643         {
00644           regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf);
00645 
00646           /* Left align 32-bit decimal float.  */
00647           if (TYPE_LENGTH (valtype) == 4)
00648             memcpy (readbuf, readbuf + 4, 4);
00649         }
00650     }
00651   /* 128-bit decimal floats in f2,f3.  */
00652   else if (TYPE_LENGTH (valtype) == 16)
00653     {
00654       if (writebuf != NULL || readbuf != NULL)
00655         {
00656           int i;
00657 
00658           for (i = 0; i < 2; i++)
00659             {
00660               if (writebuf != NULL)
00661                 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 2 + i,
00662                                        writebuf + i * 8);
00663               if (readbuf != NULL)
00664                 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 2 + i,
00665                                       readbuf + i * 8);
00666             }
00667         }
00668     }
00669   else
00670     /* Can't happen.  */
00671     internal_error (__FILE__, __LINE__, _("Unknown decimal float size."));
00672 
00673   return RETURN_VALUE_REGISTER_CONVENTION;
00674 }
00675 
00676 /* Handle the return-value conventions specified by the SysV 32-bit
00677    PowerPC ABI (including all the supplements):
00678 
00679    no floating-point: floating-point values returned using 32-bit
00680    general-purpose registers.
00681 
00682    Altivec: 128-bit vectors returned using vector registers.
00683 
00684    e500: 64-bit vectors returned using the full full 64 bit EV
00685    register, floating-point values returned using 32-bit
00686    general-purpose registers.
00687 
00688    GCC (broken): Small struct values right (instead of left) aligned
00689    when returned in general-purpose registers.  */
00690 
00691 static enum return_value_convention
00692 do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
00693                           struct type *type, struct regcache *regcache,
00694                           gdb_byte *readbuf, const gdb_byte *writebuf,
00695                           int broken_gcc)
00696 {
00697   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00698   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00699   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
00700 
00701   gdb_assert (tdep->wordsize == 4);
00702 
00703   if (TYPE_CODE (type) == TYPE_CODE_FLT
00704       && TYPE_LENGTH (type) <= 8
00705       && !tdep->soft_float)
00706     {
00707       if (readbuf)
00708         {
00709           /* Floats and doubles stored in "f1".  Convert the value to
00710              the required type.  */
00711           gdb_byte regval[MAX_REGISTER_SIZE];
00712           struct type *regtype = register_type (gdbarch,
00713                                                 tdep->ppc_fp0_regnum + 1);
00714           regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
00715           convert_typed_floating (regval, regtype, readbuf, type);
00716         }
00717       if (writebuf)
00718         {
00719           /* Floats and doubles stored in "f1".  Convert the value to
00720              the register's "double" type.  */
00721           gdb_byte regval[MAX_REGISTER_SIZE];
00722           struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
00723           convert_typed_floating (writebuf, type, regval, regtype);
00724           regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
00725         }
00726       return RETURN_VALUE_REGISTER_CONVENTION;
00727     }
00728   if (TYPE_CODE (type) == TYPE_CODE_FLT
00729       && TYPE_LENGTH (type) == 16
00730       && !tdep->soft_float
00731       && (gdbarch_long_double_format (gdbarch)
00732           == floatformats_ibm_long_double))
00733     {
00734       /* IBM long double stored in f1 and f2.  */
00735       if (readbuf)
00736         {
00737           regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf);
00738           regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 2,
00739                                 readbuf + 8);
00740         }
00741       if (writebuf)
00742         {
00743           regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, writebuf);
00744           regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 2,
00745                                  writebuf + 8);
00746         }
00747       return RETURN_VALUE_REGISTER_CONVENTION;
00748     }
00749   if (TYPE_LENGTH (type) == 16
00750       && ((TYPE_CODE (type) == TYPE_CODE_FLT
00751            && (gdbarch_long_double_format (gdbarch)
00752                == floatformats_ibm_long_double))
00753           || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && tdep->soft_float)))
00754     {
00755       /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
00756          r5, r6.  */
00757       if (readbuf)
00758         {
00759           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf);
00760           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
00761                                 readbuf + 4);
00762           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5,
00763                                 readbuf + 8);
00764           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6,
00765                                 readbuf + 12);
00766         }
00767       if (writebuf)
00768         {
00769           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf);
00770           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
00771                                  writebuf + 4);
00772           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5,
00773                                  writebuf + 8);
00774           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6,
00775                                  writebuf + 12);
00776         }
00777       return RETURN_VALUE_REGISTER_CONVENTION;
00778     }
00779   if ((TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 8)
00780       || (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
00781       || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && TYPE_LENGTH (type) == 8
00782           && tdep->soft_float))
00783     {
00784       if (readbuf)
00785         {
00786           /* A long long, double or _Decimal64 stored in the 32 bit
00787              r3/r4.  */
00788           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
00789                                 readbuf + 0);
00790           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
00791                                 readbuf + 4);
00792         }
00793       if (writebuf)
00794         {
00795           /* A long long, double or _Decimal64 stored in the 32 bit
00796              r3/r4.  */
00797           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
00798                                  writebuf + 0);
00799           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
00800                                  writebuf + 4);
00801         }
00802       return RETURN_VALUE_REGISTER_CONVENTION;
00803     }
00804   if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && !tdep->soft_float)
00805     return get_decimal_float_return_value (gdbarch, type, regcache, readbuf,
00806                                            writebuf);
00807   else if ((TYPE_CODE (type) == TYPE_CODE_INT
00808             || TYPE_CODE (type) == TYPE_CODE_CHAR
00809             || TYPE_CODE (type) == TYPE_CODE_BOOL
00810             || TYPE_CODE (type) == TYPE_CODE_PTR
00811             || TYPE_CODE (type) == TYPE_CODE_REF
00812             || TYPE_CODE (type) == TYPE_CODE_ENUM)
00813            && TYPE_LENGTH (type) <= tdep->wordsize)
00814     {
00815       if (readbuf)
00816         {
00817           /* Some sort of integer stored in r3.  Since TYPE isn't
00818              bigger than the register, sign extension isn't a problem
00819              - just do everything unsigned.  */
00820           ULONGEST regval;
00821           regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
00822                                          &regval);
00823           store_unsigned_integer (readbuf, TYPE_LENGTH (type), byte_order,
00824                                   regval);
00825         }
00826       if (writebuf)
00827         {
00828           /* Some sort of integer stored in r3.  Use unpack_long since
00829              that should handle any required sign extension.  */
00830           regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
00831                                           unpack_long (type, writebuf));
00832         }
00833       return RETURN_VALUE_REGISTER_CONVENTION;
00834     }
00835   /* OpenCL vectors < 16 bytes are returned as distinct
00836      scalars in f1..f2 or r3..r10.  */
00837   if (TYPE_CODE (type) == TYPE_CODE_ARRAY
00838       && TYPE_VECTOR (type)
00839       && TYPE_LENGTH (type) < 16
00840       && opencl_abi)
00841     {
00842       struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
00843       int i, nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
00844 
00845       for (i = 0; i < nelt; i++)
00846         {
00847           int offset = i * TYPE_LENGTH (eltype);
00848 
00849           if (TYPE_CODE (eltype) == TYPE_CODE_FLT)
00850             {
00851               int regnum = tdep->ppc_fp0_regnum + 1 + i;
00852               gdb_byte regval[MAX_REGISTER_SIZE];
00853               struct type *regtype = register_type (gdbarch, regnum);
00854 
00855               if (writebuf != NULL)
00856                 {
00857                   convert_typed_floating (writebuf + offset, eltype,
00858                                           regval, regtype);
00859                   regcache_cooked_write (regcache, regnum, regval);
00860                 }
00861               if (readbuf != NULL)
00862                 {
00863                   regcache_cooked_read (regcache, regnum, regval);
00864                   convert_typed_floating (regval, regtype,
00865                                           readbuf + offset, eltype);
00866                 }
00867             }
00868           else
00869             {
00870               int regnum = tdep->ppc_gp0_regnum + 3 + i;
00871               ULONGEST regval;
00872 
00873               if (writebuf != NULL)
00874                 {
00875                   regval = unpack_long (eltype, writebuf + offset);
00876                   regcache_cooked_write_unsigned (regcache, regnum, regval);
00877                 }
00878               if (readbuf != NULL)
00879                 {
00880                   regcache_cooked_read_unsigned (regcache, regnum, &regval);
00881                   store_unsigned_integer (readbuf + offset,
00882                                           TYPE_LENGTH (eltype), byte_order,
00883                                           regval);
00884                 }
00885             }
00886         }
00887 
00888       return RETURN_VALUE_REGISTER_CONVENTION;
00889     }
00890   /* OpenCL vectors >= 16 bytes are returned in v2..v9.  */
00891   if (TYPE_CODE (type) == TYPE_CODE_ARRAY
00892       && TYPE_VECTOR (type)
00893       && TYPE_LENGTH (type) >= 16
00894       && opencl_abi)
00895     {
00896       int n_regs = TYPE_LENGTH (type) / 16;
00897       int i;
00898 
00899       for (i = 0; i < n_regs; i++)
00900         {
00901           int offset = i * 16;
00902           int regnum = tdep->ppc_vr0_regnum + 2 + i;
00903 
00904           if (writebuf != NULL)
00905             regcache_cooked_write (regcache, regnum, writebuf + offset);
00906           if (readbuf != NULL)
00907             regcache_cooked_read (regcache, regnum, readbuf + offset);
00908         }
00909 
00910       return RETURN_VALUE_REGISTER_CONVENTION;
00911     }
00912   if (TYPE_LENGTH (type) == 16
00913       && TYPE_CODE (type) == TYPE_CODE_ARRAY
00914       && TYPE_VECTOR (type)
00915       && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
00916     {
00917       if (readbuf)
00918         {
00919           /* Altivec places the return value in "v2".  */
00920           regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
00921         }
00922       if (writebuf)
00923         {
00924           /* Altivec places the return value in "v2".  */
00925           regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf);
00926         }
00927       return RETURN_VALUE_REGISTER_CONVENTION;
00928     }
00929   if (TYPE_LENGTH (type) == 16
00930       && TYPE_CODE (type) == TYPE_CODE_ARRAY
00931       && TYPE_VECTOR (type)
00932       && tdep->vector_abi == POWERPC_VEC_GENERIC)
00933     {
00934       /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
00935          GCC without AltiVec returns them in memory, but it warns about
00936          ABI risks in that case; we don't try to support it.  */
00937       if (readbuf)
00938         {
00939           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
00940                                 readbuf + 0);
00941           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
00942                                 readbuf + 4);
00943           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5,
00944                                 readbuf + 8);
00945           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6,
00946                                 readbuf + 12);
00947         }
00948       if (writebuf)
00949         {
00950           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
00951                                  writebuf + 0);
00952           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
00953                                  writebuf + 4);
00954           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5,
00955                                  writebuf + 8);
00956           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6,
00957                                  writebuf + 12);
00958         }
00959       return RETURN_VALUE_REGISTER_CONVENTION;
00960     }
00961   if (TYPE_LENGTH (type) == 8
00962       && TYPE_CODE (type) == TYPE_CODE_ARRAY
00963       && TYPE_VECTOR (type)
00964       && tdep->vector_abi == POWERPC_VEC_SPE)
00965     {
00966       /* The e500 ABI places return values for the 64-bit DSP types
00967          (__ev64_opaque__) in r3.  However, in GDB-speak, ev3
00968          corresponds to the entire r3 value for e500, whereas GDB's r3
00969          only corresponds to the least significant 32-bits.  So place
00970          the 64-bit DSP type's value in ev3.  */
00971       if (readbuf)
00972         regcache_cooked_read (regcache, tdep->ppc_ev0_regnum + 3, readbuf);
00973       if (writebuf)
00974         regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + 3, writebuf);
00975       return RETURN_VALUE_REGISTER_CONVENTION;
00976     }
00977   if (broken_gcc && TYPE_LENGTH (type) <= 8)
00978     {
00979       /* GCC screwed up for structures or unions whose size is less
00980          than or equal to 8 bytes..  Instead of left-aligning, it
00981          right-aligns the data into the buffer formed by r3, r4.  */
00982       gdb_byte regvals[MAX_REGISTER_SIZE * 2];
00983       int len = TYPE_LENGTH (type);
00984       int offset = (2 * tdep->wordsize - len) % tdep->wordsize;
00985 
00986       if (readbuf)
00987         {
00988           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
00989                                 regvals + 0 * tdep->wordsize);
00990           if (len > tdep->wordsize)
00991             regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
00992                                   regvals + 1 * tdep->wordsize);
00993           memcpy (readbuf, regvals + offset, len);
00994         }
00995       if (writebuf)
00996         {
00997           memset (regvals, 0, sizeof regvals);
00998           memcpy (regvals + offset, writebuf, len);
00999           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
01000                                  regvals + 0 * tdep->wordsize);
01001           if (len > tdep->wordsize)
01002             regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
01003                                    regvals + 1 * tdep->wordsize);
01004         }
01005 
01006       return RETURN_VALUE_REGISTER_CONVENTION;
01007     }
01008   if (TYPE_LENGTH (type) <= 8)
01009     {
01010       if (readbuf)
01011         {
01012           /* This matches SVr4 PPC, it does not match GCC.  */
01013           /* The value is right-padded to 8 bytes and then loaded, as
01014              two "words", into r3/r4.  */
01015           gdb_byte regvals[MAX_REGISTER_SIZE * 2];
01016           regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
01017                                 regvals + 0 * tdep->wordsize);
01018           if (TYPE_LENGTH (type) > tdep->wordsize)
01019             regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
01020                                   regvals + 1 * tdep->wordsize);
01021           memcpy (readbuf, regvals, TYPE_LENGTH (type));
01022         }
01023       if (writebuf)
01024         {
01025           /* This matches SVr4 PPC, it does not match GCC.  */
01026           /* The value is padded out to 8 bytes and then loaded, as
01027              two "words" into r3/r4.  */
01028           gdb_byte regvals[MAX_REGISTER_SIZE * 2];
01029           memset (regvals, 0, sizeof regvals);
01030           memcpy (regvals, writebuf, TYPE_LENGTH (type));
01031           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
01032                                  regvals + 0 * tdep->wordsize);
01033           if (TYPE_LENGTH (type) > tdep->wordsize)
01034             regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
01035                                    regvals + 1 * tdep->wordsize);
01036         }
01037       return RETURN_VALUE_REGISTER_CONVENTION;
01038     }
01039   return RETURN_VALUE_STRUCT_CONVENTION;
01040 }
01041 
01042 enum return_value_convention
01043 ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
01044                            struct type *valtype, struct regcache *regcache,
01045                            gdb_byte *readbuf, const gdb_byte *writebuf)
01046 {
01047   return do_ppc_sysv_return_value (gdbarch,
01048                                    function ? value_type (function) : NULL,
01049                                    valtype, regcache, readbuf, writebuf, 0);
01050 }
01051 
01052 enum return_value_convention
01053 ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch,
01054                                   struct value *function,
01055                                   struct type *valtype,
01056                                   struct regcache *regcache,
01057                                   gdb_byte *readbuf, const gdb_byte *writebuf)
01058 {
01059   return do_ppc_sysv_return_value (gdbarch,
01060                                    function ? value_type (function) : NULL,
01061                                    valtype, regcache, readbuf, writebuf, 1);
01062 }
01063 
01064 /* The helper function for 64-bit SYSV push_dummy_call.  Converts the
01065    function's code address back into the function's descriptor
01066    address.
01067 
01068    Find a value for the TOC register.  Every symbol should have both
01069    ".FN" and "FN" in the minimal symbol table.  "FN" points at the
01070    FN's descriptor, while ".FN" points at the entry point (which
01071    matches FUNC_ADDR).  Need to reverse from FUNC_ADDR back to the
01072    FN's descriptor address (while at the same time being careful to
01073    find "FN" in the same object file as ".FN").  */
01074 
01075 static int
01076 convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr)
01077 {
01078   struct obj_section *dot_fn_section;
01079   struct bound_minimal_symbol dot_fn;
01080   struct minimal_symbol *fn;
01081 
01082   /* Find the minimal symbol that corresponds to CODE_ADDR (should
01083      have a name of the form ".FN").  */
01084   dot_fn = lookup_minimal_symbol_by_pc (code_addr);
01085   if (dot_fn.minsym == NULL || SYMBOL_LINKAGE_NAME (dot_fn.minsym)[0] != '.')
01086     return 0;
01087   /* Get the section that contains CODE_ADDR.  Need this for the
01088      "objfile" that it contains.  */
01089   dot_fn_section = find_pc_section (code_addr);
01090   if (dot_fn_section == NULL || dot_fn_section->objfile == NULL)
01091     return 0;
01092   /* Now find the corresponding "FN" (dropping ".") minimal symbol's
01093      address.  Only look for the minimal symbol in ".FN"'s object file
01094      - avoids problems when two object files (i.e., shared libraries)
01095      contain a minimal symbol with the same name.  */
01096   fn = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn.minsym) + 1, NULL,
01097                               dot_fn_section->objfile);
01098   if (fn == NULL)
01099     return 0;
01100   /* Found a descriptor.  */
01101   (*desc_addr) = SYMBOL_VALUE_ADDRESS (fn);
01102   return 1;
01103 }
01104 
01105 /* Push a float in either registers, or in the stack.  Using the ppc 64 bit
01106    SysV ABI.
01107 
01108    This implements a dumbed down version of the ABI.  It always writes
01109    values to memory, GPR and FPR, even when not necessary.  Doing this
01110    greatly simplifies the logic.  */
01111 
01112 static void
01113 ppc64_sysv_abi_push_float (struct gdbarch *gdbarch, struct regcache *regcache,
01114                            struct gdbarch_tdep *tdep, struct type *type, 
01115                            const bfd_byte *val, int freg, int greg,
01116                            CORE_ADDR gparam)
01117 {
01118   gdb_byte regval[MAX_REGISTER_SIZE];
01119   const gdb_byte *p;
01120 
01121   if (TYPE_LENGTH (type) <= 8)
01122     {
01123       /* Version 1.7 of the 64-bit PowerPC ELF ABI says:
01124 
01125          "Single precision floating point values are mapped to
01126          the first word in a single doubleword."
01127 
01128          And version 1.9 says:
01129 
01130          "Single precision floating point values are mapped to
01131          the second word in a single doubleword."
01132 
01133          GDB then writes single precision floating point values
01134          at both words in a doubleword, to support both ABIs.  */
01135       if (TYPE_LENGTH (type) == 4)
01136         {
01137           memcpy (regval, val, 4);
01138           memcpy (regval + 4, val, 4);
01139           p = regval;
01140         }
01141       else
01142         p = val;
01143 
01144       /* Write value in the stack's parameter save area.  */
01145       write_memory (gparam, p, 8);
01146 
01147       /* Floats and Doubles go in f1 .. f13.  They also consume a left aligned
01148          GREG, and can end up in memory.  */
01149       if (freg <= 13)
01150         {
01151           struct type *regtype;
01152 
01153           regtype = register_type (gdbarch, tdep->ppc_fp0_regnum + freg);
01154           convert_typed_floating (val, type, regval, regtype);
01155           regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, regval);
01156         }
01157       if (greg <= 10)
01158         regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg, regval);
01159     }
01160   else
01161     {
01162       /* IBM long double stored in two doublewords of the
01163          parameter save area and corresponding registers.  */
01164       if (!tdep->soft_float && freg <= 13)
01165         {
01166           regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, val);
01167           if (freg <= 12)
01168             regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg + 1,
01169                                    val + 8);
01170         }
01171       if (greg <= 10)
01172         {
01173           regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg, val);
01174           if (greg <= 9)
01175             regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 1,
01176                                    val + 8);
01177         }
01178       write_memory (gparam, val, TYPE_LENGTH (type));
01179     }
01180 }
01181 
01182 /* Pass the arguments in either registers, or in the stack.  Using the
01183    ppc 64 bit SysV ABI.
01184 
01185    This implements a dumbed down version of the ABI.  It always writes
01186    values to memory, GPR and FPR, even when not necessary.  Doing this
01187    greatly simplifies the logic.  */
01188 
01189 CORE_ADDR
01190 ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
01191                                 struct value *function,
01192                                 struct regcache *regcache, CORE_ADDR bp_addr,
01193                                 int nargs, struct value **args, CORE_ADDR sp,
01194                                 int struct_return, CORE_ADDR struct_addr)
01195 {
01196   CORE_ADDR func_addr = find_function_addr (function, NULL);
01197   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01198   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01199   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
01200   ULONGEST back_chain;
01201   /* See for-loop comment below.  */
01202   int write_pass;
01203   /* Size of the by-reference parameter copy region, the final value is
01204      computed in the for-loop below.  */
01205   LONGEST refparam_size = 0;
01206   /* Size of the general parameter region, the final value is computed
01207      in the for-loop below.  */
01208   LONGEST gparam_size = 0;
01209   /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
01210      calls to align_up(), align_down(), etc. because this makes it
01211      easier to reuse this code (in a copy/paste sense) in the future,
01212      but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
01213      at some point makes it easier to verify that this function is
01214      correct without having to do a non-local analysis to figure out
01215      the possible values of tdep->wordsize.  */
01216   gdb_assert (tdep->wordsize == 8);
01217 
01218   /* This function exists to support a calling convention that
01219      requires floating-point registers.  It shouldn't be used on
01220      processors that lack them.  */
01221   gdb_assert (ppc_floating_point_unit_p (gdbarch));
01222 
01223   /* By this stage in the proceedings, SP has been decremented by "red
01224      zone size" + "struct return size".  Fetch the stack-pointer from
01225      before this and use that as the BACK_CHAIN.  */
01226   regcache_cooked_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch),
01227                                  &back_chain);
01228 
01229   /* Go through the argument list twice.
01230 
01231      Pass 1: Compute the function call's stack space and register
01232      requirements.
01233 
01234      Pass 2: Replay the same computation but this time also write the
01235      values out to the target.  */
01236 
01237   for (write_pass = 0; write_pass < 2; write_pass++)
01238     {
01239       int argno;
01240       /* Next available floating point register for float and double
01241          arguments.  */
01242       int freg = 1;
01243       /* Next available general register for non-vector (but possibly
01244          float) arguments.  */
01245       int greg = 3;
01246       /* Next available vector register for vector arguments.  */
01247       int vreg = 2;
01248       /* The address, at which the next general purpose parameter
01249          (integer, struct, float, vector, ...) should be saved.  */
01250       CORE_ADDR gparam;
01251       /* The address, at which the next by-reference parameter
01252          (non-Altivec vector, variably-sized type) should be saved.  */
01253       CORE_ADDR refparam;
01254 
01255       if (!write_pass)
01256         {
01257           /* During the first pass, GPARAM and REFPARAM are more like
01258              offsets (start address zero) than addresses.  That way
01259              they accumulate the total stack space each region
01260              requires.  */
01261           gparam = 0;
01262           refparam = 0;
01263         }
01264       else
01265         {
01266           /* Decrement the stack pointer making space for the Altivec
01267              and general on-stack parameters.  Set refparam and gparam
01268              to their corresponding regions.  */
01269           refparam = align_down (sp - refparam_size, 16);
01270           gparam = align_down (refparam - gparam_size, 16);
01271           /* Add in space for the TOC, link editor double word,
01272              compiler double word, LR save area, CR save area.  */
01273           sp = align_down (gparam - 48, 16);
01274         }
01275 
01276       /* If the function is returning a `struct', then there is an
01277          extra hidden parameter (which will be passed in r3)
01278          containing the address of that struct..  In that case we
01279          should advance one word and start from r4 register to copy
01280          parameters.  This also consumes one on-stack parameter slot.  */
01281       if (struct_return)
01282         {
01283           if (write_pass)
01284             regcache_cooked_write_signed (regcache,
01285                                           tdep->ppc_gp0_regnum + greg,
01286                                           struct_addr);
01287           greg++;
01288           gparam = align_up (gparam + tdep->wordsize, tdep->wordsize);
01289         }
01290 
01291       for (argno = 0; argno < nargs; argno++)
01292         {
01293           struct value *arg = args[argno];
01294           struct type *type = check_typedef (value_type (arg));
01295           const bfd_byte *val = value_contents (arg);
01296 
01297           if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8)
01298             {
01299               if (write_pass)
01300                   ppc64_sysv_abi_push_float (gdbarch, regcache, tdep, type,
01301                                              val, freg, greg, gparam);
01302 
01303               freg++;
01304               greg++;
01305               /* Always consume parameter stack space.  */
01306               gparam = align_up (gparam + 8, tdep->wordsize);
01307             }
01308           else if (TYPE_CODE (type) == TYPE_CODE_FLT
01309                    && TYPE_LENGTH (type) == 16
01310                    && (gdbarch_long_double_format (gdbarch)
01311                        == floatformats_ibm_long_double))
01312             {
01313               if (write_pass)
01314                 ppc64_sysv_abi_push_float (gdbarch, regcache, tdep, type,
01315                                            val, freg, greg, gparam);
01316               freg += 2;
01317               greg += 2;
01318               gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
01319             }
01320           else if (TYPE_CODE (type) == TYPE_CODE_COMPLEX
01321               && (TYPE_LENGTH (type) == 8 || TYPE_LENGTH (type) == 16))
01322             {
01323               int i;
01324 
01325               for (i = 0; i < 2; i++)
01326                 {
01327                   if (write_pass)
01328                     {
01329                       struct type *target_type;
01330 
01331                       target_type = check_typedef (TYPE_TARGET_TYPE (type));
01332                       ppc64_sysv_abi_push_float (gdbarch, regcache, tdep,
01333                                                  target_type, val + i *
01334                                                  TYPE_LENGTH (target_type),
01335                                                  freg, greg, gparam);
01336                     }
01337                   freg++;
01338                   greg++;
01339                   /* Always consume parameter stack space.  */
01340                   gparam = align_up (gparam + 8, tdep->wordsize);
01341                 }
01342             }
01343           else if (TYPE_CODE (type) == TYPE_CODE_COMPLEX
01344                    && TYPE_LENGTH (type) == 32
01345                    && (gdbarch_long_double_format (gdbarch)
01346                        == floatformats_ibm_long_double))
01347             {
01348               int i;
01349 
01350               for (i = 0; i < 2; i++)
01351                 {
01352                   struct type *target_type;
01353 
01354                   target_type = check_typedef (TYPE_TARGET_TYPE (type));
01355                   if (write_pass)
01356                     ppc64_sysv_abi_push_float (gdbarch, regcache, tdep,
01357                                                target_type, val + i *
01358                                                TYPE_LENGTH (target_type),
01359                                                freg, greg, gparam);
01360                   freg += 2;
01361                   greg += 2;
01362                   gparam = align_up (gparam + TYPE_LENGTH (target_type),
01363                                      tdep->wordsize);
01364                 }
01365             }
01366           else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT
01367                    && TYPE_LENGTH (type) <= 8)
01368             {
01369               /* 32-bit and 64-bit decimal floats go in f1 .. f13.  They can
01370                  end up in memory.  */
01371               if (write_pass)
01372                 {
01373                   gdb_byte regval[MAX_REGISTER_SIZE];
01374                   const gdb_byte *p;
01375 
01376                   /* 32-bit decimal floats are right aligned in the
01377                      doubleword.  */
01378                   if (TYPE_LENGTH (type) == 4)
01379                     {
01380                       memcpy (regval + 4, val, 4);
01381                       p = regval;
01382                     }
01383                   else
01384                     p = val;
01385 
01386                   /* Write value in the stack's parameter save area.  */
01387                   write_memory (gparam, p, 8);
01388 
01389                   if (freg <= 13)
01390                     regcache_cooked_write (regcache,
01391                                            tdep->ppc_fp0_regnum + freg, p);
01392                 }
01393 
01394               freg++;
01395               greg++;
01396               /* Always consume parameter stack space.  */
01397               gparam = align_up (gparam + 8, tdep->wordsize);
01398             }
01399           else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT &&
01400                    TYPE_LENGTH (type) == 16)
01401             {
01402               /* 128-bit decimal floats go in f2 .. f12, always in even/odd
01403                  pairs.  They can end up in memory, using two doublewords.  */
01404               if (write_pass)
01405                 {
01406                   if (freg <= 12)
01407                     {
01408                       /* Make sure freg is even.  */
01409                       freg += freg & 1;
01410                       regcache_cooked_write (regcache,
01411                                              tdep->ppc_fp0_regnum + freg, val);
01412                       regcache_cooked_write (regcache,
01413                           tdep->ppc_fp0_regnum + freg + 1, val + 8);
01414                     }
01415 
01416                   write_memory (gparam, val, TYPE_LENGTH (type));
01417                 }
01418 
01419               freg += 2;
01420               greg += 2;
01421               gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
01422             }
01423           else if (TYPE_LENGTH (type) < 16
01424                    && TYPE_CODE (type) == TYPE_CODE_ARRAY
01425                    && TYPE_VECTOR (type)
01426                    && opencl_abi)
01427             {
01428               /* OpenCL vectors shorter than 16 bytes are passed as if
01429                  a series of independent scalars.  */
01430               struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
01431               int i, nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
01432 
01433               for (i = 0; i < nelt; i++)
01434                 {
01435                   const gdb_byte *elval = val + i * TYPE_LENGTH (eltype);
01436 
01437                   if (TYPE_CODE (eltype) == TYPE_CODE_FLT)
01438                     {
01439                       if (write_pass)
01440                         {
01441                           gdb_byte regval[MAX_REGISTER_SIZE];
01442                           const gdb_byte *p;
01443 
01444                           if (TYPE_LENGTH (eltype) == 4)
01445                             {
01446                               memcpy (regval, elval, 4);
01447                               memcpy (regval + 4, elval, 4);
01448                               p = regval;
01449                             }
01450                           else
01451                             p = elval;
01452 
01453                           write_memory (gparam, p, 8);
01454 
01455                           if (freg <= 13)
01456                             {
01457                               int regnum = tdep->ppc_fp0_regnum + freg;
01458                               struct type *regtype
01459                                 = register_type (gdbarch, regnum);
01460 
01461                               convert_typed_floating (elval, eltype,
01462                                                       regval, regtype);
01463                               regcache_cooked_write (regcache, regnum, regval);
01464                             }
01465 
01466                           if (greg <= 10)
01467                             regcache_cooked_write (regcache,
01468                                                    tdep->ppc_gp0_regnum + greg,
01469                                                    regval);
01470                         }
01471 
01472                       freg++;
01473                       greg++;
01474                       gparam = align_up (gparam + 8, tdep->wordsize);
01475                     }
01476                   else
01477                     {
01478                       if (write_pass)
01479                         {
01480                           ULONGEST word = unpack_long (eltype, elval);
01481                           if (greg <= 10)
01482                             regcache_cooked_write_unsigned
01483                               (regcache, tdep->ppc_gp0_regnum + greg, word);
01484 
01485                           write_memory_unsigned_integer
01486                             (gparam, tdep->wordsize, byte_order, word);
01487                         }
01488 
01489                       greg++;
01490                       gparam = align_up (gparam + TYPE_LENGTH (eltype),
01491                                          tdep->wordsize);
01492                     }
01493                 }
01494             }
01495           else if (TYPE_LENGTH (type) >= 16
01496                    && TYPE_CODE (type) == TYPE_CODE_ARRAY
01497                    && TYPE_VECTOR (type)
01498                    && opencl_abi)
01499             {
01500               /* OpenCL vectors 16 bytes or longer are passed as if
01501                  a series of AltiVec vectors.  */
01502               int i;
01503 
01504               for (i = 0; i < TYPE_LENGTH (type) / 16; i++)
01505                 {
01506                   const gdb_byte *elval = val + i * 16;
01507 
01508                   gparam = align_up (gparam, 16);
01509                   greg += greg & 1;
01510 
01511                   if (write_pass)
01512                     {
01513                       if (vreg <= 13)
01514                         regcache_cooked_write (regcache,
01515                                                tdep->ppc_vr0_regnum + vreg,
01516                                                elval);
01517 
01518                       write_memory (gparam, elval, 16);
01519                     }
01520 
01521                   greg += 2;
01522                   vreg++;
01523                   gparam += 16;
01524                 }
01525             }
01526           else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type)
01527                    && TYPE_CODE (type) == TYPE_CODE_ARRAY
01528                    && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
01529             {
01530               /* In the Altivec ABI, vectors go in the vector registers
01531                  v2 .. v13, as well as the parameter area -- always at
01532                  16-byte aligned addresses.  */
01533 
01534               gparam = align_up (gparam, 16);
01535               greg += greg & 1;
01536 
01537               if (write_pass)
01538                 {
01539                   if (vreg <= 13)
01540                     regcache_cooked_write (regcache,
01541                                            tdep->ppc_vr0_regnum + vreg, val);
01542 
01543                   write_memory (gparam, val, TYPE_LENGTH (type));
01544                 }
01545 
01546               greg += 2;
01547               vreg++;
01548               gparam += 16;
01549             }
01550           else if (TYPE_LENGTH (type) >= 16 && TYPE_VECTOR (type)
01551                    && TYPE_CODE (type) == TYPE_CODE_ARRAY)
01552             {
01553               /* Non-Altivec vectors are passed by reference.  */
01554 
01555               /* Copy value onto the stack ...  */
01556               refparam = align_up (refparam, 16);
01557               if (write_pass)
01558                 write_memory (refparam, val, TYPE_LENGTH (type));
01559 
01560               /* ... and pass a pointer to the copy as parameter.  */
01561               if (write_pass)
01562                 {
01563                   if (greg <= 10)
01564                     regcache_cooked_write_unsigned (regcache,
01565                                                     tdep->ppc_gp0_regnum +
01566                                                     greg, refparam);
01567                   write_memory_unsigned_integer (gparam, tdep->wordsize,
01568                                                  byte_order, refparam);
01569                 }
01570               greg++;
01571               gparam = align_up (gparam + tdep->wordsize, tdep->wordsize);
01572               refparam = align_up (refparam + TYPE_LENGTH (type), tdep->wordsize);
01573             }
01574           else if ((TYPE_CODE (type) == TYPE_CODE_INT
01575                     || TYPE_CODE (type) == TYPE_CODE_ENUM
01576                     || TYPE_CODE (type) == TYPE_CODE_BOOL
01577                     || TYPE_CODE (type) == TYPE_CODE_CHAR
01578                     || TYPE_CODE (type) == TYPE_CODE_PTR
01579                     || TYPE_CODE (type) == TYPE_CODE_REF)
01580                    && TYPE_LENGTH (type) <= 8)
01581             {
01582               /* Scalars and Pointers get sign[un]extended and go in
01583                  gpr3 .. gpr10.  They can also end up in memory.  */
01584               if (write_pass)
01585                 {
01586                   /* Sign extend the value, then store it unsigned.  */
01587                   ULONGEST word = unpack_long (type, val);
01588                   /* Convert any function code addresses into
01589                      descriptors.  */
01590                   if (TYPE_CODE (type) == TYPE_CODE_PTR
01591                       || TYPE_CODE (type) == TYPE_CODE_REF)
01592                     {
01593                       struct type *target_type;
01594                       target_type = check_typedef (TYPE_TARGET_TYPE (type));
01595 
01596                       if (TYPE_CODE (target_type) == TYPE_CODE_FUNC
01597                           || TYPE_CODE (target_type) == TYPE_CODE_METHOD)
01598                         {
01599                           CORE_ADDR desc = word;
01600                           convert_code_addr_to_desc_addr (word, &desc);
01601                           word = desc;
01602                         }
01603                     }
01604                   if (greg <= 10)
01605                     regcache_cooked_write_unsigned (regcache,
01606                                                     tdep->ppc_gp0_regnum +
01607                                                     greg, word);
01608                   write_memory_unsigned_integer (gparam, tdep->wordsize,
01609                                                  byte_order, word);
01610                 }
01611               greg++;
01612               gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
01613             }
01614           else
01615             {
01616               int byte;
01617               for (byte = 0; byte < TYPE_LENGTH (type);
01618                    byte += tdep->wordsize)
01619                 {
01620                   if (write_pass && greg <= 10)
01621                     {
01622                       gdb_byte regval[MAX_REGISTER_SIZE];
01623                       int len = TYPE_LENGTH (type) - byte;
01624                       if (len > tdep->wordsize)
01625                         len = tdep->wordsize;
01626                       memset (regval, 0, sizeof regval);
01627                       /* The ABI (version 1.9) specifies that values
01628                          smaller than one doubleword are right-aligned
01629                          and those larger are left-aligned.  GCC
01630                          versions before 3.4 implemented this
01631                          incorrectly; see
01632                          <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>.  */
01633                       if (byte == 0)
01634                         memcpy (regval + tdep->wordsize - len,
01635                                 val + byte, len);
01636                       else
01637                         memcpy (regval, val + byte, len);
01638                       regcache_cooked_write (regcache, greg, regval);
01639                     }
01640                   greg++;
01641                 }
01642               if (write_pass)
01643                 {
01644                   /* WARNING: cagney/2003-09-21: Strictly speaking, this
01645                      isn't necessary, unfortunately, GCC appears to get
01646                      "struct convention" parameter passing wrong putting
01647                      odd sized structures in memory instead of in a
01648                      register.  Work around this by always writing the
01649                      value to memory.  Fortunately, doing this
01650                      simplifies the code.  */
01651                   int len = TYPE_LENGTH (type);
01652                   if (len < tdep->wordsize)
01653                     write_memory (gparam + tdep->wordsize - len, val, len);
01654                   else
01655                     write_memory (gparam, val, len);
01656                 }
01657               if (freg <= 13
01658                   && TYPE_CODE (type) == TYPE_CODE_STRUCT
01659                   && TYPE_NFIELDS (type) == 1
01660                   && TYPE_LENGTH (type) <= 16)
01661                 {
01662                   /* The ABI (version 1.9) specifies that structs
01663                      containing a single floating-point value, at any
01664                      level of nesting of single-member structs, are
01665                      passed in floating-point registers.  */
01666                   while (TYPE_CODE (type) == TYPE_CODE_STRUCT
01667                          && TYPE_NFIELDS (type) == 1)
01668                     type = check_typedef (TYPE_FIELD_TYPE (type, 0));
01669                   if (TYPE_CODE (type) == TYPE_CODE_FLT)
01670                     {
01671                       if (TYPE_LENGTH (type) <= 8)
01672                         {
01673                           if (write_pass)
01674                             {
01675                               gdb_byte regval[MAX_REGISTER_SIZE];
01676                               struct type *regtype
01677                                 = register_type (gdbarch,
01678                                                  tdep->ppc_fp0_regnum);
01679                               convert_typed_floating (val, type, regval,
01680                                                       regtype);
01681                               regcache_cooked_write (regcache,
01682                                                      (tdep->ppc_fp0_regnum
01683                                                       + freg),
01684                                                      regval);
01685                             }
01686                           freg++;
01687                         }
01688                       else if (TYPE_LENGTH (type) == 16
01689                                && (gdbarch_long_double_format (gdbarch)
01690                                    == floatformats_ibm_long_double))
01691                         {
01692                           if (write_pass)
01693                             {
01694                               regcache_cooked_write (regcache,
01695                                                      (tdep->ppc_fp0_regnum
01696                                                       + freg),
01697                                                      val);
01698                               if (freg <= 12)
01699                                 regcache_cooked_write (regcache,
01700                                                        (tdep->ppc_fp0_regnum
01701                                                         + freg + 1),
01702                                                        val + 8);
01703                             }
01704                           freg += 2;
01705                         }
01706                     }
01707                 }
01708               /* Always consume parameter stack space.  */
01709               gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
01710             }
01711         }
01712 
01713       if (!write_pass)
01714         {
01715           /* Save the true region sizes ready for the second pass.  */
01716           refparam_size = refparam;
01717           /* Make certain that the general parameter save area is at
01718              least the minimum 8 registers (or doublewords) in size.  */
01719           if (greg < 8)
01720             gparam_size = 8 * tdep->wordsize;
01721           else
01722             gparam_size = gparam;
01723         }
01724     }
01725 
01726   /* Update %sp.   */
01727   regcache_cooked_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp);
01728 
01729   /* Write the backchain (it occupies WORDSIZED bytes).  */
01730   write_memory_signed_integer (sp, tdep->wordsize, byte_order, back_chain);
01731 
01732   /* Point the inferior function call's return address at the dummy's
01733      breakpoint.  */
01734   regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
01735 
01736   /* Use the func_addr to find the descriptor, and use that to find
01737      the TOC.  If we're calling via a function pointer, the pointer
01738      itself identifies the descriptor.  */
01739   {
01740     struct type *ftype = check_typedef (value_type (function));
01741     CORE_ADDR desc_addr = value_as_address (function);
01742 
01743     if (TYPE_CODE (ftype) == TYPE_CODE_PTR
01744         || convert_code_addr_to_desc_addr (func_addr, &desc_addr))
01745       {
01746         /* The TOC is the second double word in the descriptor.  */
01747         CORE_ADDR toc =
01748           read_memory_unsigned_integer (desc_addr + tdep->wordsize,
01749                                         tdep->wordsize, byte_order);
01750         regcache_cooked_write_unsigned (regcache,
01751                                         tdep->ppc_gp0_regnum + 2, toc);
01752       }
01753   }
01754 
01755   return sp;
01756 }
01757 
01758 
01759 /* The 64 bit ABI return value convention.
01760 
01761    Return non-zero if the return-value is stored in a register, return
01762    0 if the return-value is instead stored on the stack (a.k.a.,
01763    struct return convention).
01764 
01765    For a return-value stored in a register: when WRITEBUF is non-NULL,
01766    copy the buffer to the corresponding register return-value location
01767    location; when READBUF is non-NULL, fill the buffer from the
01768    corresponding register return-value location.  */
01769 enum return_value_convention
01770 ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
01771                              struct type *valtype, struct regcache *regcache,
01772                              gdb_byte *readbuf, const gdb_byte *writebuf)
01773 {
01774   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01775   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01776   struct type *func_type = function ? value_type (function) : NULL;
01777   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
01778 
01779   /* This function exists to support a calling convention that
01780      requires floating-point registers.  It shouldn't be used on
01781      processors that lack them.  */
01782   gdb_assert (ppc_floating_point_unit_p (gdbarch));
01783 
01784   /* Floats and doubles in F1.  */
01785   if (TYPE_CODE (valtype) == TYPE_CODE_FLT && TYPE_LENGTH (valtype) <= 8)
01786     {
01787       gdb_byte regval[MAX_REGISTER_SIZE];
01788       struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
01789       if (writebuf != NULL)
01790         {
01791           convert_typed_floating (writebuf, valtype, regval, regtype);
01792           regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
01793         }
01794       if (readbuf != NULL)
01795         {
01796           regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
01797           convert_typed_floating (regval, regtype, readbuf, valtype);
01798         }
01799       return RETURN_VALUE_REGISTER_CONVENTION;
01800     }
01801   if (TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT)
01802     return get_decimal_float_return_value (gdbarch, valtype, regcache, readbuf,
01803                                            writebuf);
01804   /* Integers in r3.  */
01805   if ((TYPE_CODE (valtype) == TYPE_CODE_INT
01806        || TYPE_CODE (valtype) == TYPE_CODE_ENUM
01807        || TYPE_CODE (valtype) == TYPE_CODE_CHAR
01808        || TYPE_CODE (valtype) == TYPE_CODE_BOOL)
01809       && TYPE_LENGTH (valtype) <= 8)
01810     {
01811       if (writebuf != NULL)
01812         {
01813           /* Be careful to sign extend the value.  */
01814           regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
01815                                           unpack_long (valtype, writebuf));
01816         }
01817       if (readbuf != NULL)
01818         {
01819           /* Extract the integer from r3.  Since this is truncating the
01820              value, there isn't a sign extension problem.  */
01821           ULONGEST regval;
01822           regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
01823                                          &regval);
01824           store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), byte_order,
01825                                   regval);
01826         }
01827       return RETURN_VALUE_REGISTER_CONVENTION;
01828     }
01829   /* All pointers live in r3.  */
01830   if (TYPE_CODE (valtype) == TYPE_CODE_PTR
01831       || TYPE_CODE (valtype) == TYPE_CODE_REF)
01832     {
01833       /* All pointers live in r3.  */
01834       if (writebuf != NULL)
01835         regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf);
01836       if (readbuf != NULL)
01837         regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf);
01838       return RETURN_VALUE_REGISTER_CONVENTION;
01839     }
01840   /* OpenCL vectors < 16 bytes are returned as distinct
01841      scalars in f1..f2 or r3..r10.  */
01842   if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
01843       && TYPE_VECTOR (valtype)
01844       && TYPE_LENGTH (valtype) < 16
01845       && opencl_abi)
01846     {
01847       struct type *eltype = check_typedef (TYPE_TARGET_TYPE (valtype));
01848       int i, nelt = TYPE_LENGTH (valtype) / TYPE_LENGTH (eltype);
01849 
01850       for (i = 0; i < nelt; i++)
01851         {
01852           int offset = i * TYPE_LENGTH (eltype);
01853 
01854           if (TYPE_CODE (eltype) == TYPE_CODE_FLT)
01855             {
01856               int regnum = tdep->ppc_fp0_regnum + 1 + i;
01857               gdb_byte regval[MAX_REGISTER_SIZE];
01858               struct type *regtype = register_type (gdbarch, regnum);
01859 
01860               if (writebuf != NULL)
01861                 {
01862                   convert_typed_floating (writebuf + offset, eltype,
01863                                           regval, regtype);
01864                   regcache_cooked_write (regcache, regnum, regval);
01865                 }
01866               if (readbuf != NULL)
01867                 {
01868                   regcache_cooked_read (regcache, regnum, regval);
01869                   convert_typed_floating (regval, regtype,
01870                                           readbuf + offset, eltype);
01871                 }
01872             }
01873           else
01874             {
01875               int regnum = tdep->ppc_gp0_regnum + 3 + i;
01876               ULONGEST regval;
01877 
01878               if (writebuf != NULL)
01879                 {
01880                   regval = unpack_long (eltype, writebuf + offset);
01881                   regcache_cooked_write_unsigned (regcache, regnum, regval);
01882                 }
01883               if (readbuf != NULL)
01884                 {
01885                   regcache_cooked_read_unsigned (regcache, regnum, &regval);
01886                   store_unsigned_integer (readbuf + offset,
01887                                           TYPE_LENGTH (eltype), byte_order,
01888                                           regval);
01889                 }
01890             }
01891         }
01892 
01893       return RETURN_VALUE_REGISTER_CONVENTION;
01894     }
01895   /* OpenCL vectors >= 16 bytes are returned in v2..v9.  */
01896   if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
01897       && TYPE_VECTOR (valtype)
01898       && TYPE_LENGTH (valtype) >= 16
01899       && opencl_abi)
01900     {
01901       int n_regs = TYPE_LENGTH (valtype) / 16;
01902       int i;
01903 
01904       for (i = 0; i < n_regs; i++)
01905         {
01906           int offset = i * 16;
01907           int regnum = tdep->ppc_vr0_regnum + 2 + i;
01908 
01909           if (writebuf != NULL)
01910             regcache_cooked_write (regcache, regnum, writebuf + offset);
01911           if (readbuf != NULL)
01912             regcache_cooked_read (regcache, regnum, readbuf + offset);
01913         }
01914 
01915       return RETURN_VALUE_REGISTER_CONVENTION;
01916     }
01917   /* Array type has more than one use.  */
01918   if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
01919     {
01920       /* Small character arrays are returned, right justified, in r3.  */
01921       if (TYPE_LENGTH (valtype) <= 8
01922         && TYPE_CODE (TYPE_TARGET_TYPE (valtype)) == TYPE_CODE_INT
01923         && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype)) == 1)
01924         {
01925           int offset = (register_size (gdbarch, tdep->ppc_gp0_regnum + 3)
01926                        - TYPE_LENGTH (valtype));
01927           if (writebuf != NULL)
01928            regcache_cooked_write_part (regcache, tdep->ppc_gp0_regnum + 3,
01929                                       offset, TYPE_LENGTH (valtype), writebuf);
01930           if (readbuf != NULL)
01931            regcache_cooked_read_part (regcache, tdep->ppc_gp0_regnum + 3,
01932                                       offset, TYPE_LENGTH (valtype), readbuf);
01933           return RETURN_VALUE_REGISTER_CONVENTION;
01934         }
01935       /* A VMX vector is returned in v2.  */
01936       if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
01937           && TYPE_VECTOR (valtype)
01938           && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
01939         {
01940           if (readbuf)
01941             regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
01942           if (writebuf)
01943             regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2,
01944                                    writebuf);
01945           return RETURN_VALUE_REGISTER_CONVENTION;
01946         }
01947     }
01948   /* Big floating point values get stored in adjacent floating
01949      point registers, starting with F1.  */
01950   if (TYPE_CODE (valtype) == TYPE_CODE_FLT
01951       && (TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 32))
01952     {
01953       if (writebuf || readbuf != NULL)
01954         {
01955           int i;
01956           for (i = 0; i < TYPE_LENGTH (valtype) / 8; i++)
01957             {
01958               if (writebuf != NULL)
01959                 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i,
01960                                        (const bfd_byte *) writebuf + i * 8);
01961               if (readbuf != NULL)
01962                 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i,
01963                                       (bfd_byte *) readbuf + i * 8);
01964             }
01965         }
01966       return RETURN_VALUE_REGISTER_CONVENTION;
01967     }
01968   /* Complex values get returned in f1:f2, need to convert.  */
01969   if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX
01970       && (TYPE_LENGTH (valtype) == 8 || TYPE_LENGTH (valtype) == 16))
01971     {
01972       if (regcache != NULL)
01973         {
01974           int i;
01975           for (i = 0; i < 2; i++)
01976             {
01977               gdb_byte regval[MAX_REGISTER_SIZE];
01978               struct type *regtype =
01979                 register_type (gdbarch, tdep->ppc_fp0_regnum);
01980               struct type *target_type;
01981               target_type = check_typedef (TYPE_TARGET_TYPE (valtype));
01982               if (writebuf != NULL)
01983                 {
01984                   convert_typed_floating ((const bfd_byte *) writebuf +
01985                                           i * TYPE_LENGTH (target_type), 
01986                                           target_type, regval, regtype);
01987                   regcache_cooked_write (regcache,
01988                                          tdep->ppc_fp0_regnum + 1 + i,
01989                                          regval);
01990                 }
01991               if (readbuf != NULL)
01992                 {
01993                   regcache_cooked_read (regcache,
01994                                         tdep->ppc_fp0_regnum + 1 + i,
01995                                         regval);
01996                   convert_typed_floating (regval, regtype,
01997                                           (bfd_byte *) readbuf +
01998                                           i * TYPE_LENGTH (target_type),
01999                                           target_type);
02000                 }
02001             }
02002         }
02003       return RETURN_VALUE_REGISTER_CONVENTION;
02004     }
02005   /* Big complex values get stored in f1:f4.  */
02006   if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX && TYPE_LENGTH (valtype) == 32)
02007     {
02008       if (regcache != NULL)
02009         {
02010           int i;
02011           for (i = 0; i < 4; i++)
02012             {
02013               if (writebuf != NULL)
02014                 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i,
02015                                        (const bfd_byte *) writebuf + i * 8);
02016               if (readbuf != NULL)
02017                 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i,
02018                                       (bfd_byte *) readbuf + i * 8);
02019             }
02020         }
02021       return RETURN_VALUE_REGISTER_CONVENTION;
02022     }
02023   return RETURN_VALUE_STRUCT_CONVENTION;
02024 }
02025 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines