1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright (C) 2000-2018 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 #include "target-float.h"
35 /* Check whether FTPYE is a (pointer to) function type that should use
36 the OpenCL vector ABI. */
39 ppc_sysv_use_opencl_abi (struct type
*ftype
)
41 ftype
= check_typedef (ftype
);
43 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
)
44 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
46 return (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
47 && TYPE_CALLING_CONVENTION (ftype
) == DW_CC_GDB_IBM_OpenCL
);
50 /* Pass the arguments in either registers, or in the stack. Using the
51 ppc sysv ABI, the first eight words of the argument list (that might
52 be less than eight parameters if some parameters occupy more than one
53 word) are passed in r3..r10 registers. float and double parameters are
54 passed in fpr's, in addition to that. Rest of the parameters if any
55 are passed in user stack.
57 If the function is returning a structure, then the return address is passed
58 in r3, then the first 7 words of the parametes can be passed in registers,
62 ppc_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
63 struct regcache
*regcache
, CORE_ADDR bp_addr
,
64 int nargs
, struct value
**args
, CORE_ADDR sp
,
65 int struct_return
, CORE_ADDR struct_addr
)
67 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
68 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
69 int opencl_abi
= ppc_sysv_use_opencl_abi (value_type (function
));
71 int argspace
= 0; /* 0 is an initial wrong guess. */
74 gdb_assert (tdep
->wordsize
== 4);
76 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
79 /* Go through the argument list twice.
81 Pass 1: Figure out how much new stack space is required for
82 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
83 ABI doesn't reserve any extra space for parameters which are put
84 in registers, but does always push structures and then pass their
87 Pass 2: Replay the same computation but this time also write the
88 values out to the target. */
90 for (write_pass
= 0; write_pass
< 2; write_pass
++)
93 /* Next available floating point register for float and double
96 /* Next available general register for non-float, non-vector
99 /* Next available vector register for vector arguments. */
101 /* Arguments start above the "LR save word" and "Back chain". */
102 int argoffset
= 2 * tdep
->wordsize
;
103 /* Structures start after the arguments. */
104 int structoffset
= argoffset
+ argspace
;
106 /* If the function is returning a `struct', then the first word
107 (which will be passed in r3) is used for struct return
108 address. In that case we should advance one word and start
109 from r4 register to copy parameters. */
113 regcache_cooked_write_signed (regcache
,
114 tdep
->ppc_gp0_regnum
+ greg
,
119 for (argno
= 0; argno
< nargs
; argno
++)
121 struct value
*arg
= args
[argno
];
122 struct type
*type
= check_typedef (value_type (arg
));
123 int len
= TYPE_LENGTH (type
);
124 const bfd_byte
*val
= value_contents (arg
);
126 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& len
<= 8
127 && !tdep
->soft_float
)
129 /* Floating point value converted to "double" then
130 passed in an FP register, when the registers run out,
131 8 byte aligned stack is used. */
136 /* Always store the floating point value using
137 the register's floating-point format. */
138 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
140 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
141 target_float_convert (val
, type
, regval
, regtype
);
142 regcache_cooked_write (regcache
,
143 tdep
->ppc_fp0_regnum
+ freg
,
150 /* The SysV ABI tells us to convert floats to
151 doubles before writing them to an 8 byte aligned
152 stack location. Unfortunately GCC does not do
153 that, and stores floats into 4 byte aligned
154 locations without converting them to doubles.
155 Since there is no know compiler that actually
156 follows the ABI here, we implement the GCC
159 /* Align to 4 bytes or 8 bytes depending on the type of
160 the argument (float or double). */
161 argoffset
= align_up (argoffset
, len
);
163 write_memory (sp
+ argoffset
, val
, len
);
167 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
170 && (gdbarch_long_double_format (gdbarch
)
171 == floatformats_ibm_long_double
))
173 /* IBM long double passed in two FP registers if
174 available, otherwise 8-byte aligned stack. */
179 regcache_cooked_write (regcache
,
180 tdep
->ppc_fp0_regnum
+ freg
,
182 regcache_cooked_write (regcache
,
183 tdep
->ppc_fp0_regnum
+ freg
+ 1,
190 argoffset
= align_up (argoffset
, 8);
192 write_memory (sp
+ argoffset
, val
, len
);
197 && (TYPE_CODE (type
) == TYPE_CODE_INT
/* long long */
198 || TYPE_CODE (type
) == TYPE_CODE_FLT
/* double */
199 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
200 && tdep
->soft_float
)))
202 /* "long long" or soft-float "double" or "_Decimal64"
203 passed in an odd/even register pair with the low
204 addressed word in the odd register and the high
205 addressed word in the even register, or when the
206 registers run out an 8 byte aligned stack
210 /* Just in case GREG was 10. */
212 argoffset
= align_up (argoffset
, 8);
214 write_memory (sp
+ argoffset
, val
, len
);
219 /* Must start on an odd register - r3/r4 etc. */
224 regcache_cooked_write (regcache
,
225 tdep
->ppc_gp0_regnum
+ greg
+ 0,
227 regcache_cooked_write (regcache
,
228 tdep
->ppc_gp0_regnum
+ greg
+ 1,
235 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
236 && (gdbarch_long_double_format (gdbarch
)
237 == floatformats_ibm_long_double
))
238 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
239 && tdep
->soft_float
)))
241 /* Soft-float IBM long double or _Decimal128 passed in
242 four consecutive registers, or on the stack. The
243 registers are not necessarily odd/even pairs. */
247 argoffset
= align_up (argoffset
, 8);
249 write_memory (sp
+ argoffset
, val
, len
);
256 regcache_cooked_write (regcache
,
257 tdep
->ppc_gp0_regnum
+ greg
+ 0,
259 regcache_cooked_write (regcache
,
260 tdep
->ppc_gp0_regnum
+ greg
+ 1,
262 regcache_cooked_write (regcache
,
263 tdep
->ppc_gp0_regnum
+ greg
+ 2,
265 regcache_cooked_write (regcache
,
266 tdep
->ppc_gp0_regnum
+ greg
+ 3,
272 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
<= 8
273 && !tdep
->soft_float
)
275 /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can
282 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
285 /* 32-bit decimal floats are right aligned in the
287 if (TYPE_LENGTH (type
) == 4)
289 memcpy (regval
+ 4, val
, 4);
295 regcache_cooked_write (regcache
,
296 tdep
->ppc_fp0_regnum
+ freg
, p
);
303 argoffset
= align_up (argoffset
, len
);
306 /* Write value in the stack's parameter save area. */
307 write_memory (sp
+ argoffset
, val
, len
);
312 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
== 16
313 && !tdep
->soft_float
)
315 /* 128-bit decimal floats go in f2 .. f7, always in even/odd
316 pairs. They can end up in memory, using two doublewords. */
320 /* Make sure freg is even. */
325 regcache_cooked_write (regcache
,
326 tdep
->ppc_fp0_regnum
+ freg
, val
);
327 regcache_cooked_write (regcache
,
328 tdep
->ppc_fp0_regnum
+ freg
+ 1, val
+ 8);
333 argoffset
= align_up (argoffset
, 8);
336 write_memory (sp
+ argoffset
, val
, 16);
341 /* If a 128-bit decimal float goes to the stack because only f7
342 and f8 are free (thus there's no even/odd register pair
343 available), these registers should be marked as occupied.
344 Hence we increase freg even when writing to memory. */
348 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
349 && TYPE_VECTOR (type
)
352 /* OpenCL vectors shorter than 16 bytes are passed as if
353 a series of independent scalars. */
354 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
355 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
357 for (i
= 0; i
< nelt
; i
++)
359 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
361 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
&& !tdep
->soft_float
)
367 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
368 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
370 = register_type (gdbarch
, regnum
);
371 target_float_convert (elval
, eltype
,
373 regcache_cooked_write (regcache
, regnum
, regval
);
379 argoffset
= align_up (argoffset
, len
);
381 write_memory (sp
+ argoffset
, val
, len
);
385 else if (TYPE_LENGTH (eltype
) == 8)
389 /* Just in case GREG was 10. */
391 argoffset
= align_up (argoffset
, 8);
393 write_memory (sp
+ argoffset
, elval
,
394 TYPE_LENGTH (eltype
));
399 /* Must start on an odd register - r3/r4 etc. */
404 int regnum
= tdep
->ppc_gp0_regnum
+ greg
;
405 regcache_cooked_write (regcache
,
406 regnum
+ 0, elval
+ 0);
407 regcache_cooked_write (regcache
,
408 regnum
+ 1, elval
+ 4);
415 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
416 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
417 unpack_long (eltype
, elval
));
422 regcache_cooked_write (regcache
,
423 tdep
->ppc_gp0_regnum
+ greg
,
429 argoffset
= align_up (argoffset
, tdep
->wordsize
);
431 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
432 argoffset
+= tdep
->wordsize
;
438 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
439 && TYPE_VECTOR (type
)
442 /* OpenCL vectors 16 bytes or longer are passed as if
443 a series of AltiVec vectors. */
446 for (i
= 0; i
< len
/ 16; i
++)
448 const gdb_byte
*elval
= val
+ i
* 16;
453 regcache_cooked_write (regcache
,
454 tdep
->ppc_vr0_regnum
+ vreg
,
460 argoffset
= align_up (argoffset
, 16);
462 write_memory (sp
+ argoffset
, elval
, 16);
468 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
469 && TYPE_VECTOR (type
)
470 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
472 /* Vector parameter passed in an Altivec register, or
473 when that runs out, 16 byte aligned stack location. */
477 regcache_cooked_write (regcache
,
478 tdep
->ppc_vr0_regnum
+ vreg
, val
);
483 argoffset
= align_up (argoffset
, 16);
485 write_memory (sp
+ argoffset
, val
, 16);
490 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
491 && TYPE_VECTOR (type
)
492 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
494 /* Vector parameter passed in an e500 register, or when
495 that runs out, 8 byte aligned stack location. Note
496 that since e500 vector and general purpose registers
497 both map onto the same underlying register set, a
498 "greg" and not a "vreg" is consumed here. A cooked
499 write stores the value in the correct locations
500 within the raw register cache. */
504 regcache_cooked_write (regcache
,
505 tdep
->ppc_ev0_regnum
+ greg
, val
);
510 argoffset
= align_up (argoffset
, 8);
512 write_memory (sp
+ argoffset
, val
, 8);
518 /* Reduce the parameter down to something that fits in a
520 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
521 memset (word
, 0, PPC_MAX_REGISTER_SIZE
);
522 if (len
> tdep
->wordsize
523 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
524 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
526 /* Structs and large values are put in an
527 aligned stack slot ... */
528 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
529 && TYPE_VECTOR (type
)
531 structoffset
= align_up (structoffset
, 16);
533 structoffset
= align_up (structoffset
, 8);
536 write_memory (sp
+ structoffset
, val
, len
);
537 /* ... and then a "word" pointing to that address is
538 passed as the parameter. */
539 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
543 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
544 /* Sign or zero extend the "int" into a "word". */
545 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
546 unpack_long (type
, val
));
548 /* Always goes in the low address. */
549 memcpy (word
, val
, len
);
550 /* Store that "word" in a register, or on the stack.
551 The words have "4" byte alignment. */
555 regcache_cooked_write (regcache
,
556 tdep
->ppc_gp0_regnum
+ greg
, word
);
561 argoffset
= align_up (argoffset
, tdep
->wordsize
);
563 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
564 argoffset
+= tdep
->wordsize
;
569 /* Compute the actual stack space requirements. */
572 /* Remember the amount of space needed by the arguments. */
573 argspace
= argoffset
;
574 /* Allocate space for both the arguments and the structures. */
575 sp
-= (argoffset
+ structoffset
);
576 /* Ensure that the stack is still 16 byte aligned. */
577 sp
= align_down (sp
, 16);
580 /* The psABI says that "A caller of a function that takes a
581 variable argument list shall set condition register bit 6 to
582 1 if it passes one or more arguments in the floating-point
583 registers. It is strongly recommended that the caller set the
584 bit to 0 otherwise..." Doing this for normal functions too
590 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_cr_regnum
, &cr
);
595 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_cr_regnum
, cr
);
600 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
602 /* Write the backchain (it occupies WORDSIZED bytes). */
603 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, saved_sp
);
605 /* Point the inferior function call's return address at the dummy's
607 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
612 /* Handle the return-value conventions for Decimal Floating Point values. */
613 static enum return_value_convention
614 get_decimal_float_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
615 struct regcache
*regcache
, gdb_byte
*readbuf
,
616 const gdb_byte
*writebuf
)
618 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
620 gdb_assert (TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
);
622 /* 32-bit and 64-bit decimal floats in f1. */
623 if (TYPE_LENGTH (valtype
) <= 8)
625 if (writebuf
!= NULL
)
627 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
630 /* 32-bit decimal float is right aligned in the doubleword. */
631 if (TYPE_LENGTH (valtype
) == 4)
633 memcpy (regval
+ 4, writebuf
, 4);
639 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, p
);
643 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, readbuf
);
645 /* Left align 32-bit decimal float. */
646 if (TYPE_LENGTH (valtype
) == 4)
647 memcpy (readbuf
, readbuf
+ 4, 4);
650 /* 128-bit decimal floats in f2,f3. */
651 else if (TYPE_LENGTH (valtype
) == 16)
653 if (writebuf
!= NULL
|| readbuf
!= NULL
)
657 for (i
= 0; i
< 2; i
++)
659 if (writebuf
!= NULL
)
660 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 2 + i
,
663 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 2 + i
,
670 internal_error (__FILE__
, __LINE__
, _("Unknown decimal float size."));
672 return RETURN_VALUE_REGISTER_CONVENTION
;
675 /* Handle the return-value conventions specified by the SysV 32-bit
676 PowerPC ABI (including all the supplements):
678 no floating-point: floating-point values returned using 32-bit
679 general-purpose registers.
681 Altivec: 128-bit vectors returned using vector registers.
683 e500: 64-bit vectors returned using the full full 64 bit EV
684 register, floating-point values returned using 32-bit
685 general-purpose registers.
687 GCC (broken): Small struct values right (instead of left) aligned
688 when returned in general-purpose registers. */
690 static enum return_value_convention
691 do_ppc_sysv_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
692 struct type
*type
, struct regcache
*regcache
,
693 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
696 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
697 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
698 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
700 gdb_assert (tdep
->wordsize
== 4);
702 if (TYPE_CODE (type
) == TYPE_CODE_FLT
703 && TYPE_LENGTH (type
) <= 8
704 && !tdep
->soft_float
)
708 /* Floats and doubles stored in "f1". Convert the value to
709 the required type. */
710 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
711 struct type
*regtype
= register_type (gdbarch
,
712 tdep
->ppc_fp0_regnum
+ 1);
713 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, regval
);
714 target_float_convert (regval
, regtype
, readbuf
, type
);
718 /* Floats and doubles stored in "f1". Convert the value to
719 the register's "double" type. */
720 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
721 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
722 target_float_convert (writebuf
, type
, regval
, regtype
);
723 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
725 return RETURN_VALUE_REGISTER_CONVENTION
;
727 if (TYPE_CODE (type
) == TYPE_CODE_FLT
728 && TYPE_LENGTH (type
) == 16
730 && (gdbarch_long_double_format (gdbarch
)
731 == floatformats_ibm_long_double
))
733 /* IBM long double stored in f1 and f2. */
736 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, readbuf
);
737 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 2, readbuf
+ 8);
741 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, writebuf
);
742 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 2,
745 return RETURN_VALUE_REGISTER_CONVENTION
;
747 if (TYPE_LENGTH (type
) == 16
748 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
749 && (gdbarch_long_double_format (gdbarch
)
750 == floatformats_ibm_long_double
))
751 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& tdep
->soft_float
)))
753 /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
757 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
);
758 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
759 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 5, readbuf
+ 8);
760 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 6, readbuf
+ 12);
764 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
765 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
767 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 5,
769 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 6,
772 return RETURN_VALUE_REGISTER_CONVENTION
;
774 if ((TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
775 || (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8)
776 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& TYPE_LENGTH (type
) == 8
777 && tdep
->soft_float
))
781 /* A long long, double or _Decimal64 stored in the 32 bit
783 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
+ 0);
784 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
788 /* A long long, double or _Decimal64 stored in the 32 bit
790 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
792 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
795 return RETURN_VALUE_REGISTER_CONVENTION
;
797 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& !tdep
->soft_float
)
798 return get_decimal_float_return_value (gdbarch
, type
, regcache
, readbuf
,
800 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
801 || TYPE_CODE (type
) == TYPE_CODE_CHAR
802 || TYPE_CODE (type
) == TYPE_CODE_BOOL
803 || TYPE_CODE (type
) == TYPE_CODE_PTR
804 || TYPE_IS_REFERENCE (type
)
805 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
806 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
810 /* Some sort of integer stored in r3. Since TYPE isn't
811 bigger than the register, sign extension isn't a problem
812 - just do everything unsigned. */
814 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
816 store_unsigned_integer (readbuf
, TYPE_LENGTH (type
), byte_order
,
821 /* Some sort of integer stored in r3. Use unpack_long since
822 that should handle any required sign extension. */
823 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
824 unpack_long (type
, writebuf
));
826 return RETURN_VALUE_REGISTER_CONVENTION
;
828 /* OpenCL vectors < 16 bytes are returned as distinct
829 scalars in f1..f2 or r3..r10. */
830 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
831 && TYPE_VECTOR (type
)
832 && TYPE_LENGTH (type
) < 16
835 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
836 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
838 for (i
= 0; i
< nelt
; i
++)
840 int offset
= i
* TYPE_LENGTH (eltype
);
842 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
844 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
845 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
846 struct type
*regtype
= register_type (gdbarch
, regnum
);
848 if (writebuf
!= NULL
)
850 target_float_convert (writebuf
+ offset
, eltype
,
852 regcache_cooked_write (regcache
, regnum
, regval
);
856 regcache
->cooked_read (regnum
, regval
);
857 target_float_convert (regval
, regtype
,
858 readbuf
+ offset
, eltype
);
863 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
866 if (writebuf
!= NULL
)
868 regval
= unpack_long (eltype
, writebuf
+ offset
);
869 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
873 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
874 store_unsigned_integer (readbuf
+ offset
,
875 TYPE_LENGTH (eltype
), byte_order
,
881 return RETURN_VALUE_REGISTER_CONVENTION
;
883 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
884 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
885 && TYPE_VECTOR (type
)
886 && TYPE_LENGTH (type
) >= 16
889 int n_regs
= TYPE_LENGTH (type
) / 16;
892 for (i
= 0; i
< n_regs
; i
++)
895 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
897 if (writebuf
!= NULL
)
898 regcache_cooked_write (regcache
, regnum
, writebuf
+ offset
);
900 regcache
->cooked_read (regnum
, readbuf
+ offset
);
903 return RETURN_VALUE_REGISTER_CONVENTION
;
905 if (TYPE_LENGTH (type
) == 16
906 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
907 && TYPE_VECTOR (type
)
908 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
912 /* Altivec places the return value in "v2". */
913 regcache
->cooked_read (tdep
->ppc_vr0_regnum
+ 2, readbuf
);
917 /* Altivec places the return value in "v2". */
918 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, writebuf
);
920 return RETURN_VALUE_REGISTER_CONVENTION
;
922 if (TYPE_LENGTH (type
) == 16
923 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
924 && TYPE_VECTOR (type
)
925 && tdep
->vector_abi
== POWERPC_VEC_GENERIC
)
927 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
928 GCC without AltiVec returns them in memory, but it warns about
929 ABI risks in that case; we don't try to support it. */
932 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
+ 0);
933 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
934 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 5, readbuf
+ 8);
935 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 6, readbuf
+ 12);
939 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
941 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
943 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 5,
945 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 6,
948 return RETURN_VALUE_REGISTER_CONVENTION
;
950 if (TYPE_LENGTH (type
) == 8
951 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
952 && TYPE_VECTOR (type
)
953 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
955 /* The e500 ABI places return values for the 64-bit DSP types
956 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
957 corresponds to the entire r3 value for e500, whereas GDB's r3
958 only corresponds to the least significant 32-bits. So place
959 the 64-bit DSP type's value in ev3. */
961 regcache
->cooked_read (tdep
->ppc_ev0_regnum
+ 3, readbuf
);
963 regcache_cooked_write (regcache
, tdep
->ppc_ev0_regnum
+ 3, writebuf
);
964 return RETURN_VALUE_REGISTER_CONVENTION
;
966 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
968 /* GCC screwed up for structures or unions whose size is less
969 than or equal to 8 bytes.. Instead of left-aligning, it
970 right-aligns the data into the buffer formed by r3, r4. */
971 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
972 int len
= TYPE_LENGTH (type
);
973 int offset
= (2 * tdep
->wordsize
- len
) % tdep
->wordsize
;
977 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3,
978 regvals
+ 0 * tdep
->wordsize
);
979 if (len
> tdep
->wordsize
)
980 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4,
981 regvals
+ 1 * tdep
->wordsize
);
982 memcpy (readbuf
, regvals
+ offset
, len
);
986 memset (regvals
, 0, sizeof regvals
);
987 memcpy (regvals
+ offset
, writebuf
, len
);
988 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
989 regvals
+ 0 * tdep
->wordsize
);
990 if (len
> tdep
->wordsize
)
991 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
992 regvals
+ 1 * tdep
->wordsize
);
995 return RETURN_VALUE_REGISTER_CONVENTION
;
997 if (TYPE_LENGTH (type
) <= 8)
1001 /* This matches SVr4 PPC, it does not match GCC. */
1002 /* The value is right-padded to 8 bytes and then loaded, as
1003 two "words", into r3/r4. */
1004 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
1005 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3,
1006 regvals
+ 0 * tdep
->wordsize
);
1007 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1008 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4,
1009 regvals
+ 1 * tdep
->wordsize
);
1010 memcpy (readbuf
, regvals
, TYPE_LENGTH (type
));
1014 /* This matches SVr4 PPC, it does not match GCC. */
1015 /* The value is padded out to 8 bytes and then loaded, as
1016 two "words" into r3/r4. */
1017 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
1018 memset (regvals
, 0, sizeof regvals
);
1019 memcpy (regvals
, writebuf
, TYPE_LENGTH (type
));
1020 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1021 regvals
+ 0 * tdep
->wordsize
);
1022 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1023 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1024 regvals
+ 1 * tdep
->wordsize
);
1026 return RETURN_VALUE_REGISTER_CONVENTION
;
1028 return RETURN_VALUE_STRUCT_CONVENTION
;
1031 enum return_value_convention
1032 ppc_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1033 struct type
*valtype
, struct regcache
*regcache
,
1034 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1036 return do_ppc_sysv_return_value (gdbarch
,
1037 function
? value_type (function
) : NULL
,
1038 valtype
, regcache
, readbuf
, writebuf
, 0);
1041 enum return_value_convention
1042 ppc_sysv_abi_broken_return_value (struct gdbarch
*gdbarch
,
1043 struct value
*function
,
1044 struct type
*valtype
,
1045 struct regcache
*regcache
,
1046 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1048 return do_ppc_sysv_return_value (gdbarch
,
1049 function
? value_type (function
) : NULL
,
1050 valtype
, regcache
, readbuf
, writebuf
, 1);
1053 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
1054 function's code address back into the function's descriptor
1057 Find a value for the TOC register. Every symbol should have both
1058 ".FN" and "FN" in the minimal symbol table. "FN" points at the
1059 FN's descriptor, while ".FN" points at the entry point (which
1060 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
1061 FN's descriptor address (while at the same time being careful to
1062 find "FN" in the same object file as ".FN"). */
1065 convert_code_addr_to_desc_addr (CORE_ADDR code_addr
, CORE_ADDR
*desc_addr
)
1067 struct obj_section
*dot_fn_section
;
1068 struct bound_minimal_symbol dot_fn
;
1069 struct bound_minimal_symbol fn
;
1071 /* Find the minimal symbol that corresponds to CODE_ADDR (should
1072 have a name of the form ".FN"). */
1073 dot_fn
= lookup_minimal_symbol_by_pc (code_addr
);
1074 if (dot_fn
.minsym
== NULL
|| MSYMBOL_LINKAGE_NAME (dot_fn
.minsym
)[0] != '.')
1076 /* Get the section that contains CODE_ADDR. Need this for the
1077 "objfile" that it contains. */
1078 dot_fn_section
= find_pc_section (code_addr
);
1079 if (dot_fn_section
== NULL
|| dot_fn_section
->objfile
== NULL
)
1081 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
1082 address. Only look for the minimal symbol in ".FN"'s object file
1083 - avoids problems when two object files (i.e., shared libraries)
1084 contain a minimal symbol with the same name. */
1085 fn
= lookup_minimal_symbol (MSYMBOL_LINKAGE_NAME (dot_fn
.minsym
) + 1, NULL
,
1086 dot_fn_section
->objfile
);
1087 if (fn
.minsym
== NULL
)
1089 /* Found a descriptor. */
1090 (*desc_addr
) = BMSYMBOL_VALUE_ADDRESS (fn
);
1094 /* Walk down the type tree of TYPE counting consecutive base elements.
1095 If *FIELD_TYPE is NULL, then set it to the first valid floating point
1096 or vector type. If a non-floating point or vector type is found, or
1097 if a floating point or vector type that doesn't match a non-NULL
1098 *FIELD_TYPE is found, then return -1, otherwise return the count in the
1102 ppc64_aggregate_candidate (struct type
*type
,
1103 struct type
**field_type
)
1105 type
= check_typedef (type
);
1107 switch (TYPE_CODE (type
))
1110 case TYPE_CODE_DECFLOAT
:
1113 if (TYPE_CODE (*field_type
) == TYPE_CODE (type
)
1114 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1118 case TYPE_CODE_COMPLEX
:
1119 type
= TYPE_TARGET_TYPE (type
);
1120 if (TYPE_CODE (type
) == TYPE_CODE_FLT
1121 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1125 if (TYPE_CODE (*field_type
) == TYPE_CODE (type
)
1126 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1131 case TYPE_CODE_ARRAY
:
1132 if (TYPE_VECTOR (type
))
1136 if (TYPE_CODE (*field_type
) == TYPE_CODE (type
)
1137 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1142 LONGEST count
, low_bound
, high_bound
;
1144 count
= ppc64_aggregate_candidate
1145 (TYPE_TARGET_TYPE (type
), field_type
);
1149 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1151 count
*= high_bound
- low_bound
;
1153 /* There must be no padding. */
1155 return TYPE_LENGTH (type
) == 0 ? 0 : -1;
1156 else if (TYPE_LENGTH (type
) != count
* TYPE_LENGTH (*field_type
))
1163 case TYPE_CODE_STRUCT
:
1164 case TYPE_CODE_UNION
:
1169 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
1173 if (field_is_static (&TYPE_FIELD (type
, i
)))
1176 sub_count
= ppc64_aggregate_candidate
1177 (TYPE_FIELD_TYPE (type
, i
), field_type
);
1178 if (sub_count
== -1)
1181 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1184 count
= std::max (count
, sub_count
);
1187 /* There must be no padding. */
1189 return TYPE_LENGTH (type
) == 0 ? 0 : -1;
1190 else if (TYPE_LENGTH (type
) != count
* TYPE_LENGTH (*field_type
))
1204 /* If an argument of type TYPE is a homogeneous float or vector aggregate
1205 that shall be passed in FP/vector registers according to the ELFv2 ABI,
1206 return the homogeneous element type in *ELT_TYPE and the number of
1207 elements in *N_ELTS, and return non-zero. Otherwise, return zero. */
1210 ppc64_elfv2_abi_homogeneous_aggregate (struct type
*type
,
1211 struct type
**elt_type
, int *n_elts
)
1213 /* Complex types at the top level are treated separately. However,
1214 complex types can be elements of homogeneous aggregates. */
1215 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1216 || TYPE_CODE (type
) == TYPE_CODE_UNION
1217 || (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& !TYPE_VECTOR (type
)))
1219 struct type
*field_type
= NULL
;
1220 LONGEST field_count
= ppc64_aggregate_candidate (type
, &field_type
);
1222 if (field_count
> 0)
1224 int n_regs
= ((TYPE_CODE (field_type
) == TYPE_CODE_FLT
1225 || TYPE_CODE (field_type
) == TYPE_CODE_DECFLOAT
)?
1226 (TYPE_LENGTH (field_type
) + 7) >> 3 : 1);
1228 /* The ELFv2 ABI allows homogeneous aggregates to occupy
1229 up to 8 registers. */
1230 if (field_count
* n_regs
<= 8)
1233 *elt_type
= field_type
;
1235 *n_elts
= (int) field_count
;
1236 /* Note that field_count is LONGEST since it may hold the size
1237 of an array, while *n_elts is int since its value is bounded
1238 by the number of registers used for argument passing. The
1239 cast cannot overflow due to the bounds checking above. */
1248 /* Structure holding the next argument position. */
1249 struct ppc64_sysv_argpos
1251 /* Register cache holding argument registers. If this is NULL,
1252 we only simulate argument processing without actually updating
1253 any registers or memory. */
1254 struct regcache
*regcache
;
1255 /* Next available general-purpose argument register. */
1257 /* Next available floating-point argument register. */
1259 /* Next available vector argument register. */
1261 /* The address, at which the next general purpose parameter
1262 (integer, struct, float, vector, ...) should be saved. */
1264 /* The address, at which the next by-reference parameter
1265 (non-Altivec vector, variably-sized type) should be saved. */
1269 /* VAL is a value of length LEN. Store it into the argument area on the
1270 stack and load it into the corresponding general-purpose registers
1271 required by the ABI, and update ARGPOS.
1273 If ALIGN is nonzero, it specifies the minimum alignment required
1274 for the on-stack copy of the argument. */
1277 ppc64_sysv_abi_push_val (struct gdbarch
*gdbarch
,
1278 const bfd_byte
*val
, int len
, int align
,
1279 struct ppc64_sysv_argpos
*argpos
)
1281 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1284 /* Enforce alignment of stack location, if requested. */
1285 if (align
> tdep
->wordsize
)
1287 CORE_ADDR aligned_gparam
= align_up (argpos
->gparam
, align
);
1289 argpos
->greg
+= (aligned_gparam
- argpos
->gparam
) / tdep
->wordsize
;
1290 argpos
->gparam
= aligned_gparam
;
1293 /* The ABI (version 1.9) specifies that values smaller than one
1294 doubleword are right-aligned and those larger are left-aligned.
1295 GCC versions before 3.4 implemented this incorrectly; see
1296 <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */
1297 if (len
< tdep
->wordsize
1298 && gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1299 offset
= tdep
->wordsize
- len
;
1301 if (argpos
->regcache
)
1302 write_memory (argpos
->gparam
+ offset
, val
, len
);
1303 argpos
->gparam
= align_up (argpos
->gparam
+ len
, tdep
->wordsize
);
1305 while (len
>= tdep
->wordsize
)
1307 if (argpos
->regcache
&& argpos
->greg
<= 10)
1308 regcache_cooked_write (argpos
->regcache
,
1309 tdep
->ppc_gp0_regnum
+ argpos
->greg
, val
);
1311 len
-= tdep
->wordsize
;
1312 val
+= tdep
->wordsize
;
1317 if (argpos
->regcache
&& argpos
->greg
<= 10)
1318 regcache_cooked_write_part (argpos
->regcache
,
1319 tdep
->ppc_gp0_regnum
+ argpos
->greg
,
1325 /* The same as ppc64_sysv_abi_push_val, but using a single-word integer
1326 value VAL as argument. */
1329 ppc64_sysv_abi_push_integer (struct gdbarch
*gdbarch
, ULONGEST val
,
1330 struct ppc64_sysv_argpos
*argpos
)
1332 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1333 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1334 gdb_byte buf
[PPC_MAX_REGISTER_SIZE
];
1336 if (argpos
->regcache
)
1337 store_unsigned_integer (buf
, tdep
->wordsize
, byte_order
, val
);
1338 ppc64_sysv_abi_push_val (gdbarch
, buf
, tdep
->wordsize
, 0, argpos
);
1341 /* VAL is a value of TYPE, a (binary or decimal) floating-point type.
1342 Load it into a floating-point register if required by the ABI,
1343 and update ARGPOS. */
1346 ppc64_sysv_abi_push_freg (struct gdbarch
*gdbarch
,
1347 struct type
*type
, const bfd_byte
*val
,
1348 struct ppc64_sysv_argpos
*argpos
)
1350 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1351 if (tdep
->soft_float
)
1354 if (TYPE_LENGTH (type
) <= 8
1355 && TYPE_CODE (type
) == TYPE_CODE_FLT
)
1357 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1359 if (argpos
->regcache
&& argpos
->freg
<= 13)
1361 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1362 struct type
*regtype
= register_type (gdbarch
, regnum
);
1363 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
1365 target_float_convert (val
, type
, regval
, regtype
);
1366 regcache_cooked_write (argpos
->regcache
, regnum
, regval
);
1371 else if (TYPE_LENGTH (type
) <= 8
1372 && TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1374 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1375 placed in the least significant word. */
1376 if (argpos
->regcache
&& argpos
->freg
<= 13)
1378 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1381 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1382 offset
= 8 - TYPE_LENGTH (type
);
1384 regcache_cooked_write_part (argpos
->regcache
, regnum
,
1385 offset
, TYPE_LENGTH (type
), val
);
1390 else if (TYPE_LENGTH (type
) == 16
1391 && TYPE_CODE (type
) == TYPE_CODE_FLT
1392 && (gdbarch_long_double_format (gdbarch
)
1393 == floatformats_ibm_long_double
))
1395 /* IBM long double stored in two consecutive FPRs. */
1396 if (argpos
->regcache
&& argpos
->freg
<= 13)
1398 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1400 regcache_cooked_write (argpos
->regcache
, regnum
, val
);
1401 if (argpos
->freg
<= 12)
1402 regcache_cooked_write (argpos
->regcache
, regnum
+ 1, val
+ 8);
1407 else if (TYPE_LENGTH (type
) == 16
1408 && TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1410 /* 128-bit decimal floating-point values are stored in and even/odd
1411 pair of FPRs, with the even FPR holding the most significant half. */
1412 argpos
->freg
+= argpos
->freg
& 1;
1414 if (argpos
->regcache
&& argpos
->freg
<= 12)
1416 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1417 int lopart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 : 0;
1418 int hipart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 0 : 8;
1420 regcache_cooked_write (argpos
->regcache
, regnum
, val
+ hipart
);
1421 regcache_cooked_write (argpos
->regcache
, regnum
+ 1, val
+ lopart
);
1428 /* VAL is a value of AltiVec vector type. Load it into a vector register
1429 if required by the ABI, and update ARGPOS. */
1432 ppc64_sysv_abi_push_vreg (struct gdbarch
*gdbarch
, const bfd_byte
*val
,
1433 struct ppc64_sysv_argpos
*argpos
)
1435 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1437 if (argpos
->regcache
&& argpos
->vreg
<= 13)
1438 regcache_cooked_write (argpos
->regcache
,
1439 tdep
->ppc_vr0_regnum
+ argpos
->vreg
, val
);
1444 /* VAL is a value of TYPE. Load it into memory and/or registers
1445 as required by the ABI, and update ARGPOS. */
1448 ppc64_sysv_abi_push_param (struct gdbarch
*gdbarch
,
1449 struct type
*type
, const bfd_byte
*val
,
1450 struct ppc64_sysv_argpos
*argpos
)
1452 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1454 if (TYPE_CODE (type
) == TYPE_CODE_FLT
1455 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1457 /* Floating-point scalars are passed in floating-point registers. */
1458 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 0, argpos
);
1459 ppc64_sysv_abi_push_freg (gdbarch
, type
, val
, argpos
);
1461 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
)
1462 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
1463 && TYPE_LENGTH (type
) == 16)
1465 /* AltiVec vectors are passed aligned, and in vector registers. */
1466 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 16, argpos
);
1467 ppc64_sysv_abi_push_vreg (gdbarch
, val
, argpos
);
1469 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
)
1470 && TYPE_LENGTH (type
) >= 16)
1472 /* Non-Altivec vectors are passed by reference. */
1474 /* Copy value onto the stack ... */
1475 CORE_ADDR addr
= align_up (argpos
->refparam
, 16);
1476 if (argpos
->regcache
)
1477 write_memory (addr
, val
, TYPE_LENGTH (type
));
1478 argpos
->refparam
= align_up (addr
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1480 /* ... and pass a pointer to the copy as parameter. */
1481 ppc64_sysv_abi_push_integer (gdbarch
, addr
, argpos
);
1483 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
1484 || TYPE_CODE (type
) == TYPE_CODE_ENUM
1485 || TYPE_CODE (type
) == TYPE_CODE_BOOL
1486 || TYPE_CODE (type
) == TYPE_CODE_CHAR
1487 || TYPE_CODE (type
) == TYPE_CODE_PTR
1488 || TYPE_IS_REFERENCE (type
))
1489 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
1493 if (argpos
->regcache
)
1495 /* Sign extend the value, then store it unsigned. */
1496 word
= unpack_long (type
, val
);
1498 /* Convert any function code addresses into descriptors. */
1499 if (tdep
->elf_abi
== POWERPC_ELF_V1
1500 && (TYPE_CODE (type
) == TYPE_CODE_PTR
1501 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1503 struct type
*target_type
1504 = check_typedef (TYPE_TARGET_TYPE (type
));
1506 if (TYPE_CODE (target_type
) == TYPE_CODE_FUNC
1507 || TYPE_CODE (target_type
) == TYPE_CODE_METHOD
)
1509 CORE_ADDR desc
= word
;
1511 convert_code_addr_to_desc_addr (word
, &desc
);
1517 ppc64_sysv_abi_push_integer (gdbarch
, word
, argpos
);
1521 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 0, argpos
);
1523 /* The ABI (version 1.9) specifies that structs containing a
1524 single floating-point value, at any level of nesting of
1525 single-member structs, are passed in floating-point registers. */
1526 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1527 && TYPE_NFIELDS (type
) == 1)
1529 while (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1530 && TYPE_NFIELDS (type
) == 1)
1531 type
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
1533 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1534 ppc64_sysv_abi_push_freg (gdbarch
, type
, val
, argpos
);
1537 /* In the ELFv2 ABI, homogeneous floating-point or vector
1538 aggregates are passed in a series of registers. */
1539 if (tdep
->elf_abi
== POWERPC_ELF_V2
)
1541 struct type
*eltype
;
1544 if (ppc64_elfv2_abi_homogeneous_aggregate (type
, &eltype
, &nelt
))
1545 for (i
= 0; i
< nelt
; i
++)
1547 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1549 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
1550 || TYPE_CODE (eltype
) == TYPE_CODE_DECFLOAT
)
1551 ppc64_sysv_abi_push_freg (gdbarch
, eltype
, elval
, argpos
);
1552 else if (TYPE_CODE (eltype
) == TYPE_CODE_ARRAY
1553 && TYPE_VECTOR (eltype
)
1554 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
1555 && TYPE_LENGTH (eltype
) == 16)
1556 ppc64_sysv_abi_push_vreg (gdbarch
, elval
, argpos
);
1562 /* Pass the arguments in either registers, or in the stack. Using the
1563 ppc 64 bit SysV ABI.
1565 This implements a dumbed down version of the ABI. It always writes
1566 values to memory, GPR and FPR, even when not necessary. Doing this
1567 greatly simplifies the logic. */
1570 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
,
1571 struct value
*function
,
1572 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1573 int nargs
, struct value
**args
, CORE_ADDR sp
,
1574 int struct_return
, CORE_ADDR struct_addr
)
1576 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
1577 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1578 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1579 int opencl_abi
= ppc_sysv_use_opencl_abi (value_type (function
));
1580 ULONGEST back_chain
;
1581 /* See for-loop comment below. */
1583 /* Size of the by-reference parameter copy region, the final value is
1584 computed in the for-loop below. */
1585 LONGEST refparam_size
= 0;
1586 /* Size of the general parameter region, the final value is computed
1587 in the for-loop below. */
1588 LONGEST gparam_size
= 0;
1589 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
1590 calls to align_up(), align_down(), etc. because this makes it
1591 easier to reuse this code (in a copy/paste sense) in the future,
1592 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
1593 at some point makes it easier to verify that this function is
1594 correct without having to do a non-local analysis to figure out
1595 the possible values of tdep->wordsize. */
1596 gdb_assert (tdep
->wordsize
== 8);
1598 /* This function exists to support a calling convention that
1599 requires floating-point registers. It shouldn't be used on
1600 processors that lack them. */
1601 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1603 /* By this stage in the proceedings, SP has been decremented by "red
1604 zone size" + "struct return size". Fetch the stack-pointer from
1605 before this and use that as the BACK_CHAIN. */
1606 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
1609 /* Go through the argument list twice.
1611 Pass 1: Compute the function call's stack space and register
1614 Pass 2: Replay the same computation but this time also write the
1615 values out to the target. */
1617 for (write_pass
= 0; write_pass
< 2; write_pass
++)
1621 struct ppc64_sysv_argpos argpos
;
1628 /* During the first pass, GPARAM and REFPARAM are more like
1629 offsets (start address zero) than addresses. That way
1630 they accumulate the total stack space each region
1632 argpos
.regcache
= NULL
;
1634 argpos
.refparam
= 0;
1638 /* Decrement the stack pointer making space for the Altivec
1639 and general on-stack parameters. Set refparam and gparam
1640 to their corresponding regions. */
1641 argpos
.regcache
= regcache
;
1642 argpos
.refparam
= align_down (sp
- refparam_size
, 16);
1643 argpos
.gparam
= align_down (argpos
.refparam
- gparam_size
, 16);
1644 /* Add in space for the TOC, link editor double word (v1 only),
1645 compiler double word (v1 only), LR save area, CR save area,
1647 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1648 sp
= align_down (argpos
.gparam
- 48, 16);
1650 sp
= align_down (argpos
.gparam
- 32, 16);
1653 /* If the function is returning a `struct', then there is an
1654 extra hidden parameter (which will be passed in r3)
1655 containing the address of that struct.. In that case we
1656 should advance one word and start from r4 register to copy
1657 parameters. This also consumes one on-stack parameter slot. */
1659 ppc64_sysv_abi_push_integer (gdbarch
, struct_addr
, &argpos
);
1661 for (argno
= 0; argno
< nargs
; argno
++)
1663 struct value
*arg
= args
[argno
];
1664 struct type
*type
= check_typedef (value_type (arg
));
1665 const bfd_byte
*val
= value_contents (arg
);
1667 if (TYPE_CODE (type
) == TYPE_CODE_COMPLEX
)
1669 /* Complex types are passed as if two independent scalars. */
1670 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1672 ppc64_sysv_abi_push_param (gdbarch
, eltype
, val
, &argpos
);
1673 ppc64_sysv_abi_push_param (gdbarch
, eltype
,
1674 val
+ TYPE_LENGTH (eltype
), &argpos
);
1676 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
)
1679 /* OpenCL vectors shorter than 16 bytes are passed as if
1680 a series of independent scalars; OpenCL vectors 16 bytes
1681 or longer are passed as if a series of AltiVec vectors. */
1682 struct type
*eltype
;
1685 if (TYPE_LENGTH (type
) < 16)
1686 eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1688 eltype
= register_type (gdbarch
, tdep
->ppc_vr0_regnum
);
1690 nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
1691 for (i
= 0; i
< nelt
; i
++)
1693 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1695 ppc64_sysv_abi_push_param (gdbarch
, eltype
, elval
, &argpos
);
1700 /* All other types are passed as single arguments. */
1701 ppc64_sysv_abi_push_param (gdbarch
, type
, val
, &argpos
);
1707 /* Save the true region sizes ready for the second pass. */
1708 refparam_size
= argpos
.refparam
;
1709 /* Make certain that the general parameter save area is at
1710 least the minimum 8 registers (or doublewords) in size. */
1711 if (argpos
.greg
< 8)
1712 gparam_size
= 8 * tdep
->wordsize
;
1714 gparam_size
= argpos
.gparam
;
1719 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
1721 /* Write the backchain (it occupies WORDSIZED bytes). */
1722 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, back_chain
);
1724 /* Point the inferior function call's return address at the dummy's
1726 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
1728 /* In the ELFv1 ABI, use the func_addr to find the descriptor, and use
1729 that to find the TOC. If we're calling via a function pointer,
1730 the pointer itself identifies the descriptor. */
1731 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1733 struct type
*ftype
= check_typedef (value_type (function
));
1734 CORE_ADDR desc_addr
= value_as_address (function
);
1736 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
1737 || convert_code_addr_to_desc_addr (func_addr
, &desc_addr
))
1739 /* The TOC is the second double word in the descriptor. */
1741 read_memory_unsigned_integer (desc_addr
+ tdep
->wordsize
,
1742 tdep
->wordsize
, byte_order
);
1744 regcache_cooked_write_unsigned (regcache
,
1745 tdep
->ppc_gp0_regnum
+ 2, toc
);
1749 /* In the ELFv2 ABI, we need to pass the target address in r12 since
1750 we may be calling a global entry point. */
1751 if (tdep
->elf_abi
== POWERPC_ELF_V2
)
1752 regcache_cooked_write_unsigned (regcache
,
1753 tdep
->ppc_gp0_regnum
+ 12, func_addr
);
1758 /* Subroutine of ppc64_sysv_abi_return_value that handles "base" types:
1759 integer, floating-point, and AltiVec vector types.
1761 This routine also handles components of aggregate return types;
1762 INDEX describes which part of the aggregate is to be handled.
1764 Returns true if VALTYPE is some such base type that could be handled,
1767 ppc64_sysv_abi_return_value_base (struct gdbarch
*gdbarch
, struct type
*valtype
,
1768 struct regcache
*regcache
, gdb_byte
*readbuf
,
1769 const gdb_byte
*writebuf
, int index
)
1771 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1773 /* Integers live in GPRs starting at r3. */
1774 if ((TYPE_CODE (valtype
) == TYPE_CODE_INT
1775 || TYPE_CODE (valtype
) == TYPE_CODE_ENUM
1776 || TYPE_CODE (valtype
) == TYPE_CODE_CHAR
1777 || TYPE_CODE (valtype
) == TYPE_CODE_BOOL
)
1778 && TYPE_LENGTH (valtype
) <= 8)
1780 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + index
;
1782 if (writebuf
!= NULL
)
1784 /* Be careful to sign extend the value. */
1785 regcache_cooked_write_unsigned (regcache
, regnum
,
1786 unpack_long (valtype
, writebuf
));
1788 if (readbuf
!= NULL
)
1790 /* Extract the integer from GPR. Since this is truncating the
1791 value, there isn't a sign extension problem. */
1794 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
1795 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
),
1796 gdbarch_byte_order (gdbarch
), regval
);
1801 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1803 if (TYPE_LENGTH (valtype
) <= 8
1804 && TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1806 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + index
;
1807 struct type
*regtype
= register_type (gdbarch
, regnum
);
1808 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
1810 if (writebuf
!= NULL
)
1812 target_float_convert (writebuf
, valtype
, regval
, regtype
);
1813 regcache_cooked_write (regcache
, regnum
, regval
);
1815 if (readbuf
!= NULL
)
1817 regcache
->cooked_read (regnum
, regval
);
1818 target_float_convert (regval
, regtype
, readbuf
, valtype
);
1823 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1824 placed in the least significant word. */
1825 if (TYPE_LENGTH (valtype
) <= 8
1826 && TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
)
1828 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + index
;
1831 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1832 offset
= 8 - TYPE_LENGTH (valtype
);
1834 if (writebuf
!= NULL
)
1835 regcache_cooked_write_part (regcache
, regnum
,
1836 offset
, TYPE_LENGTH (valtype
), writebuf
);
1837 if (readbuf
!= NULL
)
1838 regcache_cooked_read_part (regcache
, regnum
,
1839 offset
, TYPE_LENGTH (valtype
), readbuf
);
1843 /* IBM long double stored in two consecutive FPRs. */
1844 if (TYPE_LENGTH (valtype
) == 16
1845 && TYPE_CODE (valtype
) == TYPE_CODE_FLT
1846 && (gdbarch_long_double_format (gdbarch
)
1847 == floatformats_ibm_long_double
))
1849 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + 2 * index
;
1851 if (writebuf
!= NULL
)
1853 regcache_cooked_write (regcache
, regnum
, writebuf
);
1854 regcache_cooked_write (regcache
, regnum
+ 1, writebuf
+ 8);
1856 if (readbuf
!= NULL
)
1858 regcache
->cooked_read (regnum
, readbuf
);
1859 regcache
->cooked_read (regnum
+ 1, readbuf
+ 8);
1864 /* 128-bit decimal floating-point values are stored in an even/odd
1865 pair of FPRs, with the even FPR holding the most significant half. */
1866 if (TYPE_LENGTH (valtype
) == 16
1867 && TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
)
1869 int regnum
= tdep
->ppc_fp0_regnum
+ 2 + 2 * index
;
1870 int lopart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 : 0;
1871 int hipart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 0 : 8;
1873 if (writebuf
!= NULL
)
1875 regcache_cooked_write (regcache
, regnum
, writebuf
+ hipart
);
1876 regcache_cooked_write (regcache
, regnum
+ 1, writebuf
+ lopart
);
1878 if (readbuf
!= NULL
)
1880 regcache
->cooked_read (regnum
, readbuf
+ hipart
);
1881 regcache
->cooked_read (regnum
+ 1, readbuf
+ lopart
);
1886 /* AltiVec vectors are returned in VRs starting at v2. */
1887 if (TYPE_LENGTH (valtype
) == 16
1888 && TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
)
1889 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1891 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + index
;
1893 if (writebuf
!= NULL
)
1894 regcache_cooked_write (regcache
, regnum
, writebuf
);
1895 if (readbuf
!= NULL
)
1896 regcache
->cooked_read (regnum
, readbuf
);
1900 /* Short vectors are returned in GPRs starting at r3. */
1901 if (TYPE_LENGTH (valtype
) <= 8
1902 && TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
))
1904 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + index
;
1907 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1908 offset
= 8 - TYPE_LENGTH (valtype
);
1910 if (writebuf
!= NULL
)
1911 regcache_cooked_write_part (regcache
, regnum
,
1912 offset
, TYPE_LENGTH (valtype
), writebuf
);
1913 if (readbuf
!= NULL
)
1914 regcache_cooked_read_part (regcache
, regnum
,
1915 offset
, TYPE_LENGTH (valtype
), readbuf
);
1922 /* The 64 bit ABI return value convention.
1924 Return non-zero if the return-value is stored in a register, return
1925 0 if the return-value is instead stored on the stack (a.k.a.,
1926 struct return convention).
1928 For a return-value stored in a register: when WRITEBUF is non-NULL,
1929 copy the buffer to the corresponding register return-value location
1930 location; when READBUF is non-NULL, fill the buffer from the
1931 corresponding register return-value location. */
1932 enum return_value_convention
1933 ppc64_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1934 struct type
*valtype
, struct regcache
*regcache
,
1935 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1937 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1938 struct type
*func_type
= function
? value_type (function
) : NULL
;
1939 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
1940 struct type
*eltype
;
1943 /* This function exists to support a calling convention that
1944 requires floating-point registers. It shouldn't be used on
1945 processors that lack them. */
1946 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1948 /* Complex types are returned as if two independent scalars. */
1949 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
)
1951 eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1953 for (i
= 0; i
< 2; i
++)
1955 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
1956 readbuf
, writebuf
, i
);
1960 readbuf
+= TYPE_LENGTH (eltype
);
1962 writebuf
+= TYPE_LENGTH (eltype
);
1964 return RETURN_VALUE_REGISTER_CONVENTION
;
1967 /* OpenCL vectors shorter than 16 bytes are returned as if
1968 a series of independent scalars; OpenCL vectors 16 bytes
1969 or longer are returned as if a series of AltiVec vectors. */
1970 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
)
1973 if (TYPE_LENGTH (valtype
) < 16)
1974 eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1976 eltype
= register_type (gdbarch
, tdep
->ppc_vr0_regnum
);
1978 nelt
= TYPE_LENGTH (valtype
) / TYPE_LENGTH (eltype
);
1979 for (i
= 0; i
< nelt
; i
++)
1981 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
1982 readbuf
, writebuf
, i
);
1986 readbuf
+= TYPE_LENGTH (eltype
);
1988 writebuf
+= TYPE_LENGTH (eltype
);
1990 return RETURN_VALUE_REGISTER_CONVENTION
;
1993 /* All pointers live in r3. */
1994 if (TYPE_CODE (valtype
) == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (valtype
))
1996 int regnum
= tdep
->ppc_gp0_regnum
+ 3;
1998 if (writebuf
!= NULL
)
1999 regcache_cooked_write (regcache
, regnum
, writebuf
);
2000 if (readbuf
!= NULL
)
2001 regcache
->cooked_read (regnum
, readbuf
);
2002 return RETURN_VALUE_REGISTER_CONVENTION
;
2005 /* Small character arrays are returned, right justified, in r3. */
2006 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
2007 && !TYPE_VECTOR (valtype
)
2008 && TYPE_LENGTH (valtype
) <= 8
2009 && TYPE_CODE (TYPE_TARGET_TYPE (valtype
)) == TYPE_CODE_INT
2010 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
2012 int regnum
= tdep
->ppc_gp0_regnum
+ 3;
2013 int offset
= (register_size (gdbarch
, regnum
) - TYPE_LENGTH (valtype
));
2015 if (writebuf
!= NULL
)
2016 regcache_cooked_write_part (regcache
, regnum
,
2017 offset
, TYPE_LENGTH (valtype
), writebuf
);
2018 if (readbuf
!= NULL
)
2019 regcache_cooked_read_part (regcache
, regnum
,
2020 offset
, TYPE_LENGTH (valtype
), readbuf
);
2021 return RETURN_VALUE_REGISTER_CONVENTION
;
2024 /* In the ELFv2 ABI, homogeneous floating-point or vector
2025 aggregates are returned in registers. */
2026 if (tdep
->elf_abi
== POWERPC_ELF_V2
2027 && ppc64_elfv2_abi_homogeneous_aggregate (valtype
, &eltype
, &nelt
)
2028 && (TYPE_CODE (eltype
) == TYPE_CODE_FLT
2029 || TYPE_CODE (eltype
) == TYPE_CODE_DECFLOAT
2030 || (TYPE_CODE (eltype
) == TYPE_CODE_ARRAY
2031 && TYPE_VECTOR (eltype
)
2032 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
2033 && TYPE_LENGTH (eltype
) == 16)))
2035 for (i
= 0; i
< nelt
; i
++)
2037 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
2038 readbuf
, writebuf
, i
);
2042 readbuf
+= TYPE_LENGTH (eltype
);
2044 writebuf
+= TYPE_LENGTH (eltype
);
2047 return RETURN_VALUE_REGISTER_CONVENTION
;
2050 /* In the ELFv2 ABI, aggregate types of up to 16 bytes are
2051 returned in registers r3:r4. */
2052 if (tdep
->elf_abi
== POWERPC_ELF_V2
2053 && TYPE_LENGTH (valtype
) <= 16
2054 && (TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
2055 || TYPE_CODE (valtype
) == TYPE_CODE_UNION
2056 || (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
2057 && !TYPE_VECTOR (valtype
))))
2059 int n_regs
= ((TYPE_LENGTH (valtype
) + tdep
->wordsize
- 1)
2063 for (i
= 0; i
< n_regs
; i
++)
2065 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
2066 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
2067 int offset
= i
* tdep
->wordsize
;
2068 int len
= TYPE_LENGTH (valtype
) - offset
;
2070 if (len
> tdep
->wordsize
)
2071 len
= tdep
->wordsize
;
2073 if (writebuf
!= NULL
)
2075 memset (regval
, 0, sizeof regval
);
2076 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
2078 memcpy (regval
+ tdep
->wordsize
- len
, writebuf
, len
);
2080 memcpy (regval
, writebuf
+ offset
, len
);
2081 regcache_cooked_write (regcache
, regnum
, regval
);
2083 if (readbuf
!= NULL
)
2085 regcache
->cooked_read (regnum
, regval
);
2086 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
2088 memcpy (readbuf
, regval
+ tdep
->wordsize
- len
, len
);
2090 memcpy (readbuf
+ offset
, regval
, len
);
2093 return RETURN_VALUE_REGISTER_CONVENTION
;
2096 /* Handle plain base types. */
2097 if (ppc64_sysv_abi_return_value_base (gdbarch
, valtype
, regcache
,
2098 readbuf
, writebuf
, 0))
2099 return RETURN_VALUE_REGISTER_CONVENTION
;
2101 return RETURN_VALUE_STRUCT_CONVENTION
;