1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright (C) 2000-2022 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 (ftype
->code () == TYPE_CODE_PTR
)
44 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
46 return (ftype
->code () == 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 parameters 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 function_call_return_method return_method
,
66 CORE_ADDR struct_addr
)
68 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
69 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
70 int opencl_abi
= ppc_sysv_use_opencl_abi (value_type (function
));
72 int argspace
= 0; /* 0 is an initial wrong guess. */
75 gdb_assert (tdep
->wordsize
== 4);
77 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
80 /* Go through the argument list twice.
82 Pass 1: Figure out how much new stack space is required for
83 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
84 ABI doesn't reserve any extra space for parameters which are put
85 in registers, but does always push structures and then pass their
88 Pass 2: Replay the same computation but this time also write the
89 values out to the target. */
91 for (write_pass
= 0; write_pass
< 2; write_pass
++)
94 /* Next available floating point register for float and double
97 /* Next available general register for non-float, non-vector
100 /* Next available vector register for vector arguments. */
102 /* Arguments start above the "LR save word" and "Back chain". */
103 int argoffset
= 2 * tdep
->wordsize
;
104 /* Structures start after the arguments. */
105 int structoffset
= argoffset
+ argspace
;
107 /* If the function is returning a `struct', then the first word
108 (which will be passed in r3) is used for struct return
109 address. In that case we should advance one word and start
110 from r4 register to copy parameters. */
111 if (return_method
== return_method_struct
)
114 regcache_cooked_write_signed (regcache
,
115 tdep
->ppc_gp0_regnum
+ greg
,
120 for (argno
= 0; argno
< nargs
; argno
++)
122 struct value
*arg
= args
[argno
];
123 struct type
*type
= check_typedef (value_type (arg
));
124 int len
= TYPE_LENGTH (type
);
125 const bfd_byte
*val
= value_contents (arg
).data ();
127 if (type
->code () == TYPE_CODE_FLT
&& len
<= 8
128 && !tdep
->soft_float
)
130 /* Floating point value converted to "double" then
131 passed in an FP register, when the registers run out,
132 8 byte aligned stack is used. */
137 /* Always store the floating point value using
138 the register's floating-point format. */
139 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
141 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
142 target_float_convert (val
, type
, regval
, regtype
);
143 regcache
->cooked_write (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_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 (tdep
->ppc_fp0_regnum
+ freg
, val
);
180 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
+ 1,
187 argoffset
= align_up (argoffset
, 8);
189 write_memory (sp
+ argoffset
, val
, len
);
194 && (type
->code () == TYPE_CODE_INT
/* long long */
195 || type
->code () == TYPE_CODE_FLT
/* double */
196 || (type
->code () == TYPE_CODE_DECFLOAT
197 && tdep
->soft_float
)))
199 /* "long long" or soft-float "double" or "_Decimal64"
200 passed in an odd/even register pair with the low
201 addressed word in the odd register and the high
202 addressed word in the even register, or when the
203 registers run out an 8 byte aligned stack
207 /* Just in case GREG was 10. */
209 argoffset
= align_up (argoffset
, 8);
211 write_memory (sp
+ argoffset
, val
, len
);
216 /* Must start on an odd register - r3/r4 etc. */
221 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 0,
223 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 1,
230 && ((type
->code () == TYPE_CODE_FLT
231 && (gdbarch_long_double_format (gdbarch
)
232 == floatformats_ibm_long_double
))
233 || (type
->code () == TYPE_CODE_DECFLOAT
234 && tdep
->soft_float
)))
236 /* Soft-float IBM long double or _Decimal128 passed in
237 four consecutive registers, or on the stack. The
238 registers are not necessarily odd/even pairs. */
242 argoffset
= align_up (argoffset
, 8);
244 write_memory (sp
+ argoffset
, val
, len
);
251 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 0,
253 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 1,
255 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 2,
257 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 3,
263 else if (type
->code () == TYPE_CODE_DECFLOAT
&& len
<= 8
264 && !tdep
->soft_float
)
266 /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can
273 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
276 /* 32-bit decimal floats are right aligned in the
278 if (TYPE_LENGTH (type
) == 4)
280 memcpy (regval
+ 4, val
, 4);
286 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
, p
);
293 argoffset
= align_up (argoffset
, len
);
296 /* Write value in the stack's parameter save area. */
297 write_memory (sp
+ argoffset
, val
, len
);
302 else if (type
->code () == TYPE_CODE_DECFLOAT
&& len
== 16
303 && !tdep
->soft_float
)
305 /* 128-bit decimal floats go in f2 .. f7, always in even/odd
306 pairs. They can end up in memory, using two doublewords. */
310 /* Make sure freg is even. */
315 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
, val
);
316 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
+ 1,
322 argoffset
= align_up (argoffset
, 8);
325 write_memory (sp
+ argoffset
, val
, 16);
330 /* If a 128-bit decimal float goes to the stack because only f7
331 and f8 are free (thus there's no even/odd register pair
332 available), these registers should be marked as occupied.
333 Hence we increase freg even when writing to memory. */
337 && type
->code () == TYPE_CODE_ARRAY
338 && type
->is_vector ()
341 /* OpenCL vectors shorter than 16 bytes are passed as if
342 a series of independent scalars. */
343 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
344 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
346 for (i
= 0; i
< nelt
; i
++)
348 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
350 if (eltype
->code () == TYPE_CODE_FLT
&& !tdep
->soft_float
)
356 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
357 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
359 = register_type (gdbarch
, regnum
);
360 target_float_convert (elval
, eltype
,
362 regcache
->cooked_write (regnum
, regval
);
368 argoffset
= align_up (argoffset
, len
);
370 write_memory (sp
+ argoffset
, val
, len
);
374 else if (TYPE_LENGTH (eltype
) == 8)
378 /* Just in case GREG was 10. */
380 argoffset
= align_up (argoffset
, 8);
382 write_memory (sp
+ argoffset
, elval
,
383 TYPE_LENGTH (eltype
));
388 /* Must start on an odd register - r3/r4 etc. */
393 int regnum
= tdep
->ppc_gp0_regnum
+ greg
;
394 regcache
->cooked_write (regnum
+ 0, elval
+ 0);
395 regcache
->cooked_write (regnum
+ 1, elval
+ 4);
402 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
403 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
404 unpack_long (eltype
, elval
));
409 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
,
415 argoffset
= align_up (argoffset
, tdep
->wordsize
);
417 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
418 argoffset
+= tdep
->wordsize
;
424 && type
->code () == TYPE_CODE_ARRAY
425 && type
->is_vector ()
428 /* OpenCL vectors 16 bytes or longer are passed as if
429 a series of AltiVec vectors. */
432 for (i
= 0; i
< len
/ 16; i
++)
434 const gdb_byte
*elval
= val
+ i
* 16;
439 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ vreg
,
445 argoffset
= align_up (argoffset
, 16);
447 write_memory (sp
+ argoffset
, elval
, 16);
453 && ((type
->code () == TYPE_CODE_ARRAY
454 && type
->is_vector ()
455 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
456 || (type
->code () == TYPE_CODE_FLT
457 && (gdbarch_long_double_format (gdbarch
)
458 == floatformats_ieee_quad
))))
460 /* Vector parameter passed in an Altivec register, or
461 when that runs out, 16 byte aligned stack location.
462 IEEE FLOAT 128-bit also passes parameters in vector
467 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ vreg
, val
);
472 argoffset
= align_up (argoffset
, 16);
474 write_memory (sp
+ argoffset
, val
, 16);
479 && type
->code () == TYPE_CODE_ARRAY
480 && type
->is_vector ()
481 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
483 /* Vector parameter passed in an e500 register, or when
484 that runs out, 8 byte aligned stack location. Note
485 that since e500 vector and general purpose registers
486 both map onto the same underlying register set, a
487 "greg" and not a "vreg" is consumed here. A cooked
488 write stores the value in the correct locations
489 within the raw register cache. */
493 regcache
->cooked_write (tdep
->ppc_ev0_regnum
+ greg
, val
);
498 argoffset
= align_up (argoffset
, 8);
500 write_memory (sp
+ argoffset
, val
, 8);
506 /* Reduce the parameter down to something that fits in a
508 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
509 memset (word
, 0, PPC_MAX_REGISTER_SIZE
);
510 if (len
> tdep
->wordsize
511 || type
->code () == TYPE_CODE_STRUCT
512 || type
->code () == TYPE_CODE_UNION
)
514 /* Structs and large values are put in an
515 aligned stack slot ... */
516 if (type
->code () == TYPE_CODE_ARRAY
517 && type
->is_vector ()
519 structoffset
= align_up (structoffset
, 16);
521 structoffset
= align_up (structoffset
, 8);
524 write_memory (sp
+ structoffset
, val
, len
);
525 /* ... and then a "word" pointing to that address is
526 passed as the parameter. */
527 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
531 else if (type
->code () == TYPE_CODE_INT
)
532 /* Sign or zero extend the "int" into a "word". */
533 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
534 unpack_long (type
, val
));
536 /* Always goes in the low address. */
537 memcpy (word
, val
, len
);
538 /* Store that "word" in a register, or on the stack.
539 The words have "4" byte alignment. */
543 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
, word
);
548 argoffset
= align_up (argoffset
, tdep
->wordsize
);
550 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
551 argoffset
+= tdep
->wordsize
;
556 /* Compute the actual stack space requirements. */
559 /* Remember the amount of space needed by the arguments. */
560 argspace
= argoffset
;
561 /* Allocate space for both the arguments and the structures. */
562 sp
-= (argoffset
+ structoffset
);
563 /* Ensure that the stack is still 16 byte aligned. */
564 sp
= align_down (sp
, 16);
567 /* The psABI says that "A caller of a function that takes a
568 variable argument list shall set condition register bit 6 to
569 1 if it passes one or more arguments in the floating-point
570 registers. It is strongly recommended that the caller set the
571 bit to 0 otherwise..." Doing this for normal functions too
577 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_cr_regnum
, &cr
);
582 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_cr_regnum
, cr
);
587 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
589 /* Write the backchain (it occupies WORDSIZED bytes). */
590 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, saved_sp
);
592 /* Point the inferior function call's return address at the dummy's
594 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
599 /* Handle the return-value conventions for Decimal Floating Point values. */
600 static enum return_value_convention
601 get_decimal_float_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
602 struct regcache
*regcache
, gdb_byte
*readbuf
,
603 const gdb_byte
*writebuf
)
605 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
607 gdb_assert (valtype
->code () == TYPE_CODE_DECFLOAT
);
609 /* 32-bit and 64-bit decimal floats in f1. */
610 if (TYPE_LENGTH (valtype
) <= 8)
612 if (writebuf
!= NULL
)
614 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
617 /* 32-bit decimal float is right aligned in the doubleword. */
618 if (TYPE_LENGTH (valtype
) == 4)
620 memcpy (regval
+ 4, writebuf
, 4);
626 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, p
);
630 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, readbuf
);
632 /* Left align 32-bit decimal float. */
633 if (TYPE_LENGTH (valtype
) == 4)
634 memcpy (readbuf
, readbuf
+ 4, 4);
637 /* 128-bit decimal floats in f2,f3. */
638 else if (TYPE_LENGTH (valtype
) == 16)
640 if (writebuf
!= NULL
|| readbuf
!= NULL
)
644 for (i
= 0; i
< 2; i
++)
646 if (writebuf
!= NULL
)
647 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 2 + i
,
650 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 2 + i
,
657 internal_error (__FILE__
, __LINE__
, _("Unknown decimal float size."));
659 return RETURN_VALUE_REGISTER_CONVENTION
;
662 /* Handle the return-value conventions specified by the SysV 32-bit
663 PowerPC ABI (including all the supplements):
665 no floating-point: floating-point values returned using 32-bit
666 general-purpose registers.
668 Altivec: 128-bit vectors returned using vector registers.
670 e500: 64-bit vectors returned using the full full 64 bit EV
671 register, floating-point values returned using 32-bit
672 general-purpose registers.
674 GCC (broken): Small struct values right (instead of left) aligned
675 when returned in general-purpose registers. */
677 static enum return_value_convention
678 do_ppc_sysv_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
679 struct type
*type
, struct regcache
*regcache
,
680 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
683 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
684 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
685 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
687 gdb_assert (tdep
->wordsize
== 4);
689 if (type
->code () == TYPE_CODE_FLT
690 && TYPE_LENGTH (type
) <= 8
691 && !tdep
->soft_float
)
695 /* Floats and doubles stored in "f1". Convert the value to
696 the required type. */
697 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
698 struct type
*regtype
= register_type (gdbarch
,
699 tdep
->ppc_fp0_regnum
+ 1);
700 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, regval
);
701 target_float_convert (regval
, regtype
, readbuf
, type
);
705 /* Floats and doubles stored in "f1". Convert the value to
706 the register's "double" type. */
707 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
708 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
709 target_float_convert (writebuf
, type
, regval
, regtype
);
710 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, regval
);
712 return RETURN_VALUE_REGISTER_CONVENTION
;
714 if (type
->code () == TYPE_CODE_FLT
715 && TYPE_LENGTH (type
) == 16
717 && (gdbarch_long_double_format (gdbarch
)
718 == floatformats_ibm_long_double
))
720 /* IBM long double stored in f1 and f2. */
723 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, readbuf
);
724 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 2, readbuf
+ 8);
728 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, writebuf
);
729 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 2, writebuf
+ 8);
731 return RETURN_VALUE_REGISTER_CONVENTION
;
733 if (TYPE_LENGTH (type
) == 16
734 && ((type
->code () == TYPE_CODE_FLT
735 && (gdbarch_long_double_format (gdbarch
)
736 == floatformats_ibm_long_double
))
737 || (type
->code () == TYPE_CODE_DECFLOAT
&& tdep
->soft_float
)))
739 /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
743 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
);
744 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
745 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 5, readbuf
+ 8);
746 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 6, readbuf
+ 12);
750 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
);
751 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
752 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 5, writebuf
+ 8);
753 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 6, writebuf
+ 12);
755 return RETURN_VALUE_REGISTER_CONVENTION
;
757 if ((type
->code () == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
758 || (type
->code () == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8)
759 || (type
->code () == TYPE_CODE_DECFLOAT
&& TYPE_LENGTH (type
) == 8
760 && tdep
->soft_float
))
764 /* A long long, double or _Decimal64 stored in the 32 bit
766 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
+ 0);
767 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
771 /* A long long, double or _Decimal64 stored in the 32 bit
773 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
+ 0);
774 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
776 return RETURN_VALUE_REGISTER_CONVENTION
;
778 if (type
->code () == TYPE_CODE_DECFLOAT
&& !tdep
->soft_float
)
779 return get_decimal_float_return_value (gdbarch
, type
, regcache
, readbuf
,
781 else if ((type
->code () == TYPE_CODE_INT
782 || type
->code () == TYPE_CODE_CHAR
783 || type
->code () == TYPE_CODE_BOOL
784 || type
->code () == TYPE_CODE_PTR
785 || TYPE_IS_REFERENCE (type
)
786 || type
->code () == TYPE_CODE_ENUM
)
787 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
791 /* Some sort of integer stored in r3. Since TYPE isn't
792 bigger than the register, sign extension isn't a problem
793 - just do everything unsigned. */
795 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
797 store_unsigned_integer (readbuf
, TYPE_LENGTH (type
), byte_order
,
802 /* Some sort of integer stored in r3. Use unpack_long since
803 that should handle any required sign extension. */
804 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
805 unpack_long (type
, writebuf
));
807 return RETURN_VALUE_REGISTER_CONVENTION
;
809 /* OpenCL vectors < 16 bytes are returned as distinct
810 scalars in f1..f2 or r3..r10. */
811 if (type
->code () == TYPE_CODE_ARRAY
812 && type
->is_vector ()
813 && TYPE_LENGTH (type
) < 16
816 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
817 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
819 for (i
= 0; i
< nelt
; i
++)
821 int offset
= i
* TYPE_LENGTH (eltype
);
823 if (eltype
->code () == TYPE_CODE_FLT
)
825 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
826 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
827 struct type
*regtype
= register_type (gdbarch
, regnum
);
829 if (writebuf
!= NULL
)
831 target_float_convert (writebuf
+ offset
, eltype
,
833 regcache
->cooked_write (regnum
, regval
);
837 regcache
->cooked_read (regnum
, regval
);
838 target_float_convert (regval
, regtype
,
839 readbuf
+ offset
, eltype
);
844 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
847 if (writebuf
!= NULL
)
849 regval
= unpack_long (eltype
, writebuf
+ offset
);
850 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
854 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
855 store_unsigned_integer (readbuf
+ offset
,
856 TYPE_LENGTH (eltype
), byte_order
,
862 return RETURN_VALUE_REGISTER_CONVENTION
;
864 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
865 if (type
->code () == TYPE_CODE_ARRAY
866 && type
->is_vector ()
867 && TYPE_LENGTH (type
) >= 16
870 int n_regs
= TYPE_LENGTH (type
) / 16;
873 for (i
= 0; i
< n_regs
; i
++)
876 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
878 if (writebuf
!= NULL
)
879 regcache
->cooked_write (regnum
, writebuf
+ offset
);
881 regcache
->cooked_read (regnum
, readbuf
+ offset
);
884 return RETURN_VALUE_REGISTER_CONVENTION
;
886 if (TYPE_LENGTH (type
) == 16
887 && type
->code () == TYPE_CODE_ARRAY
888 && type
->is_vector ()
889 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
893 /* Altivec places the return value in "v2". */
894 regcache
->cooked_read (tdep
->ppc_vr0_regnum
+ 2, readbuf
);
898 /* Altivec places the return value in "v2". */
899 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ 2, writebuf
);
901 return RETURN_VALUE_REGISTER_CONVENTION
;
903 if (TYPE_LENGTH (type
) == 16
904 && type
->code () == TYPE_CODE_ARRAY
905 && type
->is_vector ()
906 && tdep
->vector_abi
== POWERPC_VEC_GENERIC
)
908 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
909 GCC without AltiVec returns them in memory, but it warns about
910 ABI risks in that case; we don't try to support it. */
913 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
+ 0);
914 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
915 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 5, readbuf
+ 8);
916 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 6, readbuf
+ 12);
920 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
+ 0);
921 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
922 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 5, writebuf
+ 8);
923 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 6, writebuf
+ 12);
925 return RETURN_VALUE_REGISTER_CONVENTION
;
927 if (TYPE_LENGTH (type
) == 8
928 && type
->code () == TYPE_CODE_ARRAY
929 && type
->is_vector ()
930 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
932 /* The e500 ABI places return values for the 64-bit DSP types
933 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
934 corresponds to the entire r3 value for e500, whereas GDB's r3
935 only corresponds to the least significant 32-bits. So place
936 the 64-bit DSP type's value in ev3. */
938 regcache
->cooked_read (tdep
->ppc_ev0_regnum
+ 3, readbuf
);
940 regcache
->cooked_write (tdep
->ppc_ev0_regnum
+ 3, writebuf
);
941 return RETURN_VALUE_REGISTER_CONVENTION
;
943 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
945 /* GCC screwed up for structures or unions whose size is less
946 than or equal to 8 bytes.. Instead of left-aligning, it
947 right-aligns the data into the buffer formed by r3, r4. */
948 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
949 int len
= TYPE_LENGTH (type
);
950 int offset
= (2 * tdep
->wordsize
- len
) % tdep
->wordsize
;
954 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3,
955 regvals
+ 0 * tdep
->wordsize
);
956 if (len
> tdep
->wordsize
)
957 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4,
958 regvals
+ 1 * tdep
->wordsize
);
959 memcpy (readbuf
, regvals
+ offset
, len
);
963 memset (regvals
, 0, sizeof regvals
);
964 memcpy (regvals
+ offset
, writebuf
, len
);
965 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3,
966 regvals
+ 0 * tdep
->wordsize
);
967 if (len
> tdep
->wordsize
)
968 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4,
969 regvals
+ 1 * tdep
->wordsize
);
972 return RETURN_VALUE_REGISTER_CONVENTION
;
974 if (TYPE_LENGTH (type
) <= 8)
978 /* This matches SVr4 PPC, it does not match GCC. */
979 /* The value is right-padded to 8 bytes and then loaded, as
980 two "words", into r3/r4. */
981 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
982 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3,
983 regvals
+ 0 * tdep
->wordsize
);
984 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
985 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4,
986 regvals
+ 1 * tdep
->wordsize
);
987 memcpy (readbuf
, regvals
, TYPE_LENGTH (type
));
991 /* This matches SVr4 PPC, it does not match GCC. */
992 /* The value is padded out to 8 bytes and then loaded, as
993 two "words" into r3/r4. */
994 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
995 memset (regvals
, 0, sizeof regvals
);
996 memcpy (regvals
, writebuf
, TYPE_LENGTH (type
));
997 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3,
998 regvals
+ 0 * tdep
->wordsize
);
999 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1000 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4,
1001 regvals
+ 1 * tdep
->wordsize
);
1003 return RETURN_VALUE_REGISTER_CONVENTION
;
1005 return RETURN_VALUE_STRUCT_CONVENTION
;
1008 enum return_value_convention
1009 ppc_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1010 struct type
*valtype
, struct regcache
*regcache
,
1011 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1013 return do_ppc_sysv_return_value (gdbarch
,
1014 function
? value_type (function
) : NULL
,
1015 valtype
, regcache
, readbuf
, writebuf
, 0);
1018 enum return_value_convention
1019 ppc_sysv_abi_broken_return_value (struct gdbarch
*gdbarch
,
1020 struct value
*function
,
1021 struct type
*valtype
,
1022 struct regcache
*regcache
,
1023 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1025 return do_ppc_sysv_return_value (gdbarch
,
1026 function
? value_type (function
) : NULL
,
1027 valtype
, regcache
, readbuf
, writebuf
, 1);
1030 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
1031 function's code address back into the function's descriptor
1034 Find a value for the TOC register. Every symbol should have both
1035 ".FN" and "FN" in the minimal symbol table. "FN" points at the
1036 FN's descriptor, while ".FN" points at the entry point (which
1037 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
1038 FN's descriptor address (while at the same time being careful to
1039 find "FN" in the same object file as ".FN"). */
1042 convert_code_addr_to_desc_addr (CORE_ADDR code_addr
, CORE_ADDR
*desc_addr
)
1044 struct obj_section
*dot_fn_section
;
1045 struct bound_minimal_symbol dot_fn
;
1046 struct bound_minimal_symbol fn
;
1048 /* Find the minimal symbol that corresponds to CODE_ADDR (should
1049 have a name of the form ".FN"). */
1050 dot_fn
= lookup_minimal_symbol_by_pc (code_addr
);
1051 if (dot_fn
.minsym
== NULL
|| dot_fn
.minsym
->linkage_name ()[0] != '.')
1053 /* Get the section that contains CODE_ADDR. Need this for the
1054 "objfile" that it contains. */
1055 dot_fn_section
= find_pc_section (code_addr
);
1056 if (dot_fn_section
== NULL
|| dot_fn_section
->objfile
== NULL
)
1058 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
1059 address. Only look for the minimal symbol in ".FN"'s object file
1060 - avoids problems when two object files (i.e., shared libraries)
1061 contain a minimal symbol with the same name. */
1062 fn
= lookup_minimal_symbol (dot_fn
.minsym
->linkage_name () + 1, NULL
,
1063 dot_fn_section
->objfile
);
1064 if (fn
.minsym
== NULL
)
1066 /* Found a descriptor. */
1067 (*desc_addr
) = fn
.value_address ();
1071 /* Walk down the type tree of TYPE counting consecutive base elements.
1072 If *FIELD_TYPE is NULL, then set it to the first valid floating point
1073 or vector type. If a non-floating point or vector type is found, or
1074 if a floating point or vector type that doesn't match a non-NULL
1075 *FIELD_TYPE is found, then return -1, otherwise return the count in the
1079 ppc64_aggregate_candidate (struct type
*type
,
1080 struct type
**field_type
)
1082 type
= check_typedef (type
);
1084 switch (type
->code ())
1087 case TYPE_CODE_DECFLOAT
:
1090 if ((*field_type
)->code () == type
->code ()
1091 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1095 case TYPE_CODE_COMPLEX
:
1096 type
= TYPE_TARGET_TYPE (type
);
1097 if (type
->code () == TYPE_CODE_FLT
1098 || type
->code () == TYPE_CODE_DECFLOAT
)
1102 if ((*field_type
)->code () == type
->code ()
1103 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1108 case TYPE_CODE_ARRAY
:
1109 if (type
->is_vector ())
1113 if ((*field_type
)->code () == type
->code ()
1114 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1119 LONGEST count
, low_bound
, high_bound
;
1121 count
= ppc64_aggregate_candidate
1122 (TYPE_TARGET_TYPE (type
), field_type
);
1126 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1128 count
*= high_bound
- low_bound
;
1130 /* There must be no padding. */
1132 return TYPE_LENGTH (type
) == 0 ? 0 : -1;
1133 else if (TYPE_LENGTH (type
) != count
* TYPE_LENGTH (*field_type
))
1140 case TYPE_CODE_STRUCT
:
1141 case TYPE_CODE_UNION
:
1146 for (i
= 0; i
< type
->num_fields (); i
++)
1150 if (field_is_static (&type
->field (i
)))
1153 sub_count
= ppc64_aggregate_candidate
1154 (type
->field (i
).type (), field_type
);
1155 if (sub_count
== -1)
1158 if (type
->code () == TYPE_CODE_STRUCT
)
1161 count
= std::max (count
, sub_count
);
1164 /* There must be no padding. */
1166 return TYPE_LENGTH (type
) == 0 ? 0 : -1;
1167 else if (TYPE_LENGTH (type
) != count
* TYPE_LENGTH (*field_type
))
1181 /* If an argument of type TYPE is a homogeneous float or vector aggregate
1182 that shall be passed in FP/vector registers according to the ELFv2 ABI,
1183 return the homogeneous element type in *ELT_TYPE and the number of
1184 elements in *N_ELTS, and return non-zero. Otherwise, return zero. */
1187 ppc64_elfv2_abi_homogeneous_aggregate (struct type
*type
,
1188 struct type
**elt_type
, int *n_elts
,
1189 struct gdbarch
*gdbarch
)
1191 /* Complex types at the top level are treated separately. However,
1192 complex types can be elements of homogeneous aggregates. */
1193 if (type
->code () == TYPE_CODE_STRUCT
1194 || type
->code () == TYPE_CODE_UNION
1195 || (type
->code () == TYPE_CODE_ARRAY
&& !type
->is_vector ()))
1197 struct type
*field_type
= NULL
;
1198 LONGEST field_count
= ppc64_aggregate_candidate (type
, &field_type
);
1200 if (field_count
> 0)
1204 if (field_type
->code () == TYPE_CODE_FLT
1205 && (gdbarch_long_double_format (gdbarch
)
1206 == floatformats_ieee_quad
))
1207 /* IEEE Float 128-bit uses one vector register. */
1210 else if (field_type
->code () == TYPE_CODE_FLT
1211 || field_type
->code () == TYPE_CODE_DECFLOAT
)
1212 n_regs
= (TYPE_LENGTH (field_type
) + 7) >> 3;
1217 /* The ELFv2 ABI allows homogeneous aggregates to occupy
1218 up to 8 registers. */
1219 if (field_count
* n_regs
<= 8)
1222 *elt_type
= field_type
;
1224 *n_elts
= (int) field_count
;
1225 /* Note that field_count is LONGEST since it may hold the size
1226 of an array, while *n_elts is int since its value is bounded
1227 by the number of registers used for argument passing. The
1228 cast cannot overflow due to the bounds checking above. */
1237 /* Structure holding the next argument position. */
1238 struct ppc64_sysv_argpos
1240 /* Register cache holding argument registers. If this is NULL,
1241 we only simulate argument processing without actually updating
1242 any registers or memory. */
1243 struct regcache
*regcache
;
1244 /* Next available general-purpose argument register. */
1246 /* Next available floating-point argument register. */
1248 /* Next available vector argument register. */
1250 /* The address, at which the next general purpose parameter
1251 (integer, struct, float, vector, ...) should be saved. */
1253 /* The address, at which the next by-reference parameter
1254 (non-Altivec vector, variably-sized type) should be saved. */
1258 /* VAL is a value of length LEN. Store it into the argument area on the
1259 stack and load it into the corresponding general-purpose registers
1260 required by the ABI, and update ARGPOS.
1262 If ALIGN is nonzero, it specifies the minimum alignment required
1263 for the on-stack copy of the argument. */
1266 ppc64_sysv_abi_push_val (struct gdbarch
*gdbarch
,
1267 const bfd_byte
*val
, int len
, int align
,
1268 struct ppc64_sysv_argpos
*argpos
)
1270 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1273 /* Enforce alignment of stack location, if requested. */
1274 if (align
> tdep
->wordsize
)
1276 CORE_ADDR aligned_gparam
= align_up (argpos
->gparam
, align
);
1278 argpos
->greg
+= (aligned_gparam
- argpos
->gparam
) / tdep
->wordsize
;
1279 argpos
->gparam
= aligned_gparam
;
1282 /* The ABI (version 1.9) specifies that values smaller than one
1283 doubleword are right-aligned and those larger are left-aligned.
1284 GCC versions before 3.4 implemented this incorrectly; see
1285 <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */
1286 if (len
< tdep
->wordsize
1287 && gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1288 offset
= tdep
->wordsize
- len
;
1290 if (argpos
->regcache
)
1291 write_memory (argpos
->gparam
+ offset
, val
, len
);
1292 argpos
->gparam
= align_up (argpos
->gparam
+ len
, tdep
->wordsize
);
1294 while (len
>= tdep
->wordsize
)
1296 if (argpos
->regcache
&& argpos
->greg
<= 10)
1297 argpos
->regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ argpos
->greg
,
1300 len
-= tdep
->wordsize
;
1301 val
+= tdep
->wordsize
;
1306 if (argpos
->regcache
&& argpos
->greg
<= 10)
1307 argpos
->regcache
->cooked_write_part
1308 (tdep
->ppc_gp0_regnum
+ argpos
->greg
, offset
, len
, val
);
1313 /* The same as ppc64_sysv_abi_push_val, but using a single-word integer
1314 value VAL as argument. */
1317 ppc64_sysv_abi_push_integer (struct gdbarch
*gdbarch
, ULONGEST val
,
1318 struct ppc64_sysv_argpos
*argpos
)
1320 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1321 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1322 gdb_byte buf
[PPC_MAX_REGISTER_SIZE
];
1324 if (argpos
->regcache
)
1325 store_unsigned_integer (buf
, tdep
->wordsize
, byte_order
, val
);
1326 ppc64_sysv_abi_push_val (gdbarch
, buf
, tdep
->wordsize
, 0, argpos
);
1329 /* VAL is a value of TYPE, a (binary or decimal) floating-point type.
1330 Load it into a floating-point register if required by the ABI,
1331 and update ARGPOS. */
1334 ppc64_sysv_abi_push_freg (struct gdbarch
*gdbarch
,
1335 struct type
*type
, const bfd_byte
*val
,
1336 struct ppc64_sysv_argpos
*argpos
)
1338 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1339 if (tdep
->soft_float
)
1342 if (TYPE_LENGTH (type
) <= 8
1343 && type
->code () == TYPE_CODE_FLT
)
1345 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1347 if (argpos
->regcache
&& argpos
->freg
<= 13)
1349 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1350 struct type
*regtype
= register_type (gdbarch
, regnum
);
1351 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
1353 target_float_convert (val
, type
, regval
, regtype
);
1354 argpos
->regcache
->cooked_write (regnum
, regval
);
1359 else if (TYPE_LENGTH (type
) <= 8
1360 && type
->code () == TYPE_CODE_DECFLOAT
)
1362 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1363 placed in the least significant word. */
1364 if (argpos
->regcache
&& argpos
->freg
<= 13)
1366 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1369 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1370 offset
= 8 - TYPE_LENGTH (type
);
1372 argpos
->regcache
->cooked_write_part (regnum
, offset
,
1373 TYPE_LENGTH (type
), val
);
1378 else if (TYPE_LENGTH (type
) == 16
1379 && type
->code () == TYPE_CODE_FLT
1380 && (gdbarch_long_double_format (gdbarch
)
1381 == floatformats_ibm_long_double
))
1383 /* IBM long double stored in two consecutive FPRs. */
1384 if (argpos
->regcache
&& argpos
->freg
<= 13)
1386 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1388 argpos
->regcache
->cooked_write (regnum
, val
);
1389 if (argpos
->freg
<= 12)
1390 argpos
->regcache
->cooked_write (regnum
+ 1, val
+ 8);
1395 else if (TYPE_LENGTH (type
) == 16
1396 && type
->code () == TYPE_CODE_DECFLOAT
)
1398 /* 128-bit decimal floating-point values are stored in and even/odd
1399 pair of FPRs, with the even FPR holding the most significant half. */
1400 argpos
->freg
+= argpos
->freg
& 1;
1402 if (argpos
->regcache
&& argpos
->freg
<= 12)
1404 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1405 int lopart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 : 0;
1406 int hipart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 0 : 8;
1408 argpos
->regcache
->cooked_write (regnum
, val
+ hipart
);
1409 argpos
->regcache
->cooked_write (regnum
+ 1, val
+ lopart
);
1416 /* VAL is a value of AltiVec vector type. Load it into a vector register
1417 if required by the ABI, and update ARGPOS. */
1420 ppc64_sysv_abi_push_vreg (struct gdbarch
*gdbarch
, const bfd_byte
*val
,
1421 struct ppc64_sysv_argpos
*argpos
)
1423 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1425 if (argpos
->regcache
&& argpos
->vreg
<= 13)
1426 argpos
->regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ argpos
->vreg
, val
);
1431 /* VAL is a value of TYPE. Load it into memory and/or registers
1432 as required by the ABI, and update ARGPOS. */
1435 ppc64_sysv_abi_push_param (struct gdbarch
*gdbarch
,
1436 struct type
*type
, const bfd_byte
*val
,
1437 struct ppc64_sysv_argpos
*argpos
)
1439 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1441 if (type
->code () == TYPE_CODE_FLT
1442 && TYPE_LENGTH (type
) == 16
1443 && (gdbarch_long_double_format (gdbarch
)
1444 == floatformats_ieee_quad
))
1446 /* IEEE FLOAT128, args in vector registers. */
1447 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 0, argpos
);
1448 ppc64_sysv_abi_push_vreg (gdbarch
, val
, argpos
);
1450 else if (type
->code () == TYPE_CODE_FLT
1451 || type
->code () == TYPE_CODE_DECFLOAT
)
1453 /* Floating-point scalars are passed in floating-point registers. */
1454 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 0, argpos
);
1455 ppc64_sysv_abi_push_freg (gdbarch
, type
, val
, argpos
);
1457 else if (type
->code () == TYPE_CODE_ARRAY
&& type
->is_vector ()
1458 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
1459 && TYPE_LENGTH (type
) == 16)
1461 /* AltiVec vectors are passed aligned, and in vector registers. */
1462 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 16, argpos
);
1463 ppc64_sysv_abi_push_vreg (gdbarch
, val
, argpos
);
1465 else if (type
->code () == TYPE_CODE_ARRAY
&& type
->is_vector ()
1466 && TYPE_LENGTH (type
) >= 16)
1468 /* Non-Altivec vectors are passed by reference. */
1470 /* Copy value onto the stack ... */
1471 CORE_ADDR addr
= align_up (argpos
->refparam
, 16);
1472 if (argpos
->regcache
)
1473 write_memory (addr
, val
, TYPE_LENGTH (type
));
1474 argpos
->refparam
= align_up (addr
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1476 /* ... and pass a pointer to the copy as parameter. */
1477 ppc64_sysv_abi_push_integer (gdbarch
, addr
, argpos
);
1479 else if ((type
->code () == TYPE_CODE_INT
1480 || type
->code () == TYPE_CODE_ENUM
1481 || type
->code () == TYPE_CODE_BOOL
1482 || type
->code () == TYPE_CODE_CHAR
1483 || type
->code () == TYPE_CODE_PTR
1484 || TYPE_IS_REFERENCE (type
))
1485 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
1489 if (argpos
->regcache
)
1491 /* Sign extend the value, then store it unsigned. */
1492 word
= unpack_long (type
, val
);
1494 /* Convert any function code addresses into descriptors. */
1495 if (tdep
->elf_abi
== POWERPC_ELF_V1
1496 && (type
->code () == TYPE_CODE_PTR
1497 || type
->code () == TYPE_CODE_REF
))
1499 struct type
*target_type
1500 = check_typedef (TYPE_TARGET_TYPE (type
));
1502 if (target_type
->code () == TYPE_CODE_FUNC
1503 || target_type
->code () == TYPE_CODE_METHOD
)
1505 CORE_ADDR desc
= word
;
1507 convert_code_addr_to_desc_addr (word
, &desc
);
1513 ppc64_sysv_abi_push_integer (gdbarch
, word
, argpos
);
1517 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 0, argpos
);
1519 /* The ABI (version 1.9) specifies that structs containing a
1520 single floating-point value, at any level of nesting of
1521 single-member structs, are passed in floating-point registers. */
1522 if (type
->code () == TYPE_CODE_STRUCT
1523 && type
->num_fields () == 1 && tdep
->elf_abi
== POWERPC_ELF_V1
)
1525 while (type
->code () == TYPE_CODE_STRUCT
1526 && type
->num_fields () == 1)
1527 type
= check_typedef (type
->field (0).type ());
1529 if (type
->code () == TYPE_CODE_FLT
) {
1530 /* Handle the case of 128-bit floats for both IEEE and IBM long double
1532 if (TYPE_LENGTH (type
) == 16
1533 && (gdbarch_long_double_format (gdbarch
)
1534 == floatformats_ieee_quad
))
1535 ppc64_sysv_abi_push_vreg (gdbarch
, val
, argpos
);
1537 ppc64_sysv_abi_push_freg (gdbarch
, type
, val
, argpos
);
1541 /* In the ELFv2 ABI, homogeneous floating-point or vector
1542 aggregates are passed in a series of registers. */
1543 if (tdep
->elf_abi
== POWERPC_ELF_V2
)
1545 struct type
*eltype
;
1548 if (ppc64_elfv2_abi_homogeneous_aggregate (type
, &eltype
, &nelt
,
1550 for (i
= 0; i
< nelt
; i
++)
1552 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1554 if (eltype
->code () == TYPE_CODE_FLT
1555 && TYPE_LENGTH (eltype
) == 16
1556 && (gdbarch_long_double_format (gdbarch
)
1557 == floatformats_ieee_quad
))
1558 /* IEEE FLOAT128, args in vector registers. */
1559 ppc64_sysv_abi_push_vreg (gdbarch
, elval
, argpos
);
1561 else if (eltype
->code () == TYPE_CODE_FLT
1562 || eltype
->code () == TYPE_CODE_DECFLOAT
)
1563 /* IBM long double and all other floats and decfloats, args
1564 are in a pair of floating point registers. */
1565 ppc64_sysv_abi_push_freg (gdbarch
, eltype
, elval
, argpos
);
1566 else if (eltype
->code () == TYPE_CODE_ARRAY
1567 && eltype
->is_vector ()
1568 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
1569 && TYPE_LENGTH (eltype
) == 16)
1570 ppc64_sysv_abi_push_vreg (gdbarch
, elval
, argpos
);
1576 /* Pass the arguments in either registers, or in the stack. Using the
1577 ppc 64 bit SysV ABI.
1579 This implements a dumbed down version of the ABI. It always writes
1580 values to memory, GPR and FPR, even when not necessary. Doing this
1581 greatly simplifies the logic. */
1584 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
,
1585 struct value
*function
,
1586 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1587 int nargs
, struct value
**args
, CORE_ADDR sp
,
1588 function_call_return_method return_method
,
1589 CORE_ADDR struct_addr
)
1591 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
1592 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1593 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1594 int opencl_abi
= ppc_sysv_use_opencl_abi (value_type (function
));
1595 ULONGEST back_chain
;
1596 /* See for-loop comment below. */
1598 /* Size of the by-reference parameter copy region, the final value is
1599 computed in the for-loop below. */
1600 LONGEST refparam_size
= 0;
1601 /* Size of the general parameter region, the final value is computed
1602 in the for-loop below. */
1603 LONGEST gparam_size
= 0;
1604 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
1605 calls to align_up(), align_down(), etc. because this makes it
1606 easier to reuse this code (in a copy/paste sense) in the future,
1607 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
1608 at some point makes it easier to verify that this function is
1609 correct without having to do a non-local analysis to figure out
1610 the possible values of tdep->wordsize. */
1611 gdb_assert (tdep
->wordsize
== 8);
1613 /* This function exists to support a calling convention that
1614 requires floating-point registers. It shouldn't be used on
1615 processors that lack them. */
1616 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1618 /* By this stage in the proceedings, SP has been decremented by "red
1619 zone size" + "struct return size". Fetch the stack-pointer from
1620 before this and use that as the BACK_CHAIN. */
1621 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
1624 /* Go through the argument list twice.
1626 Pass 1: Compute the function call's stack space and register
1629 Pass 2: Replay the same computation but this time also write the
1630 values out to the target. */
1632 for (write_pass
= 0; write_pass
< 2; write_pass
++)
1636 struct ppc64_sysv_argpos argpos
;
1643 /* During the first pass, GPARAM and REFPARAM are more like
1644 offsets (start address zero) than addresses. That way
1645 they accumulate the total stack space each region
1647 argpos
.regcache
= NULL
;
1649 argpos
.refparam
= 0;
1653 /* Decrement the stack pointer making space for the Altivec
1654 and general on-stack parameters. Set refparam and gparam
1655 to their corresponding regions. */
1656 argpos
.regcache
= regcache
;
1657 argpos
.refparam
= align_down (sp
- refparam_size
, 16);
1658 argpos
.gparam
= align_down (argpos
.refparam
- gparam_size
, 16);
1659 /* Add in space for the TOC, link editor double word (v1 only),
1660 compiler double word (v1 only), LR save area, CR save area,
1662 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1663 sp
= align_down (argpos
.gparam
- 48, 16);
1665 sp
= align_down (argpos
.gparam
- 32, 16);
1668 /* If the function is returning a `struct', then there is an
1669 extra hidden parameter (which will be passed in r3)
1670 containing the address of that struct.. In that case we
1671 should advance one word and start from r4 register to copy
1672 parameters. This also consumes one on-stack parameter slot. */
1673 if (return_method
== return_method_struct
)
1674 ppc64_sysv_abi_push_integer (gdbarch
, struct_addr
, &argpos
);
1676 for (argno
= 0; argno
< nargs
; argno
++)
1678 struct value
*arg
= args
[argno
];
1679 struct type
*type
= check_typedef (value_type (arg
));
1680 const bfd_byte
*val
= value_contents (arg
).data ();
1682 if (type
->code () == TYPE_CODE_COMPLEX
)
1684 /* Complex types are passed as if two independent scalars. */
1685 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1687 ppc64_sysv_abi_push_param (gdbarch
, eltype
, val
, &argpos
);
1688 ppc64_sysv_abi_push_param (gdbarch
, eltype
,
1689 val
+ TYPE_LENGTH (eltype
), &argpos
);
1691 else if (type
->code () == TYPE_CODE_ARRAY
&& type
->is_vector ()
1694 /* OpenCL vectors shorter than 16 bytes are passed as if
1695 a series of independent scalars; OpenCL vectors 16 bytes
1696 or longer are passed as if a series of AltiVec vectors. */
1697 struct type
*eltype
;
1700 if (TYPE_LENGTH (type
) < 16)
1701 eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1703 eltype
= register_type (gdbarch
, tdep
->ppc_vr0_regnum
);
1705 nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
1706 for (i
= 0; i
< nelt
; i
++)
1708 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1710 ppc64_sysv_abi_push_param (gdbarch
, eltype
, elval
, &argpos
);
1715 /* All other types are passed as single arguments. */
1716 ppc64_sysv_abi_push_param (gdbarch
, type
, val
, &argpos
);
1722 /* Save the true region sizes ready for the second pass. */
1723 refparam_size
= argpos
.refparam
;
1724 /* Make certain that the general parameter save area is at
1725 least the minimum 8 registers (or doublewords) in size. */
1726 if (argpos
.greg
< 8)
1727 gparam_size
= 8 * tdep
->wordsize
;
1729 gparam_size
= argpos
.gparam
;
1734 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
1736 /* Write the backchain (it occupies WORDSIZED bytes). */
1737 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, back_chain
);
1739 /* Point the inferior function call's return address at the dummy's
1741 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
1743 /* In the ELFv1 ABI, use the func_addr to find the descriptor, and use
1744 that to find the TOC. If we're calling via a function pointer,
1745 the pointer itself identifies the descriptor. */
1746 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1748 struct type
*ftype
= check_typedef (value_type (function
));
1749 CORE_ADDR desc_addr
= value_as_address (function
);
1751 if (ftype
->code () == TYPE_CODE_PTR
1752 || convert_code_addr_to_desc_addr (func_addr
, &desc_addr
))
1754 /* The TOC is the second double word in the descriptor. */
1756 read_memory_unsigned_integer (desc_addr
+ tdep
->wordsize
,
1757 tdep
->wordsize
, byte_order
);
1759 regcache_cooked_write_unsigned (regcache
,
1760 tdep
->ppc_gp0_regnum
+ 2, toc
);
1764 /* In the ELFv2 ABI, we need to pass the target address in r12 since
1765 we may be calling a global entry point. */
1766 if (tdep
->elf_abi
== POWERPC_ELF_V2
)
1767 regcache_cooked_write_unsigned (regcache
,
1768 tdep
->ppc_gp0_regnum
+ 12, func_addr
);
1773 /* Subroutine of ppc64_sysv_abi_return_value that handles "base" types:
1774 integer, floating-point, and AltiVec vector types.
1776 This routine also handles components of aggregate return types;
1777 INDEX describes which part of the aggregate is to be handled.
1779 Returns true if VALTYPE is some such base type that could be handled,
1782 ppc64_sysv_abi_return_value_base (struct gdbarch
*gdbarch
, struct type
*valtype
,
1783 struct regcache
*regcache
, gdb_byte
*readbuf
,
1784 const gdb_byte
*writebuf
, int index
)
1786 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1788 /* Integers live in GPRs starting at r3. */
1789 if ((valtype
->code () == TYPE_CODE_INT
1790 || valtype
->code () == TYPE_CODE_ENUM
1791 || valtype
->code () == TYPE_CODE_CHAR
1792 || valtype
->code () == TYPE_CODE_BOOL
1793 || valtype
->code () == TYPE_CODE_RANGE
1794 || is_fixed_point_type (valtype
))
1795 && TYPE_LENGTH (valtype
) <= 8)
1797 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + index
;
1799 if (writebuf
!= NULL
)
1803 if (is_fixed_point_type (valtype
))
1805 /* Fixed point type values need to be returned unscaled. */
1808 unscaled
.read (gdb::make_array_view (writebuf
,
1809 TYPE_LENGTH (valtype
)),
1810 type_byte_order (valtype
),
1811 valtype
->is_unsigned ());
1812 return_val
= unscaled
.as_integer
<LONGEST
> ();
1815 return_val
= unpack_long (valtype
, writebuf
);
1817 /* Be careful to sign extend the value. */
1818 regcache_cooked_write_unsigned (regcache
, regnum
, return_val
);
1820 if (readbuf
!= NULL
)
1822 /* Extract the integer from GPR. Since this is truncating the
1823 value, there isn't a sign extension problem. */
1826 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
1827 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
),
1828 gdbarch_byte_order (gdbarch
), regval
);
1833 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1835 if (TYPE_LENGTH (valtype
) <= 8
1836 && valtype
->code () == TYPE_CODE_FLT
)
1838 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + index
;
1839 struct type
*regtype
= register_type (gdbarch
, regnum
);
1840 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
1842 if (writebuf
!= NULL
)
1844 target_float_convert (writebuf
, valtype
, regval
, regtype
);
1845 regcache
->cooked_write (regnum
, regval
);
1847 if (readbuf
!= NULL
)
1849 regcache
->cooked_read (regnum
, regval
);
1850 target_float_convert (regval
, regtype
, readbuf
, valtype
);
1855 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1856 placed in the least significant word. */
1857 if (TYPE_LENGTH (valtype
) <= 8
1858 && valtype
->code () == TYPE_CODE_DECFLOAT
)
1860 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + index
;
1863 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1864 offset
= 8 - TYPE_LENGTH (valtype
);
1866 if (writebuf
!= NULL
)
1867 regcache
->cooked_write_part (regnum
, offset
, TYPE_LENGTH (valtype
),
1869 if (readbuf
!= NULL
)
1870 regcache
->cooked_read_part (regnum
, offset
, TYPE_LENGTH (valtype
),
1875 /* IBM long double stored in two consecutive FPRs. */
1876 if (TYPE_LENGTH (valtype
) == 16
1877 && valtype
->code () == TYPE_CODE_FLT
1878 && (gdbarch_long_double_format (gdbarch
)
1879 == floatformats_ibm_long_double
))
1881 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + 2 * index
;
1883 if (writebuf
!= NULL
)
1885 regcache
->cooked_write (regnum
, writebuf
);
1886 regcache
->cooked_write (regnum
+ 1, writebuf
+ 8);
1888 if (readbuf
!= NULL
)
1890 regcache
->cooked_read (regnum
, readbuf
);
1891 regcache
->cooked_read (regnum
+ 1, readbuf
+ 8);
1896 /* 128-bit decimal floating-point values are stored in an even/odd
1897 pair of FPRs, with the even FPR holding the most significant half. */
1898 if (TYPE_LENGTH (valtype
) == 16
1899 && valtype
->code () == TYPE_CODE_DECFLOAT
)
1901 int regnum
= tdep
->ppc_fp0_regnum
+ 2 + 2 * index
;
1902 int lopart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 : 0;
1903 int hipart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 0 : 8;
1905 if (writebuf
!= NULL
)
1907 regcache
->cooked_write (regnum
, writebuf
+ hipart
);
1908 regcache
->cooked_write (regnum
+ 1, writebuf
+ lopart
);
1910 if (readbuf
!= NULL
)
1912 regcache
->cooked_read (regnum
, readbuf
+ hipart
);
1913 regcache
->cooked_read (regnum
+ 1, readbuf
+ lopart
);
1918 /* AltiVec vectors are returned in VRs starting at v2.
1919 IEEE FLOAT 128-bit are stored in vector register. */
1921 if (TYPE_LENGTH (valtype
) == 16
1922 && ((valtype
->code () == TYPE_CODE_ARRAY
1923 && valtype
->is_vector ()
1924 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1925 || (valtype
->code () == TYPE_CODE_FLT
1926 && (gdbarch_long_double_format (gdbarch
)
1927 == floatformats_ieee_quad
))))
1929 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + index
;
1931 if (writebuf
!= NULL
)
1932 regcache
->cooked_write (regnum
, writebuf
);
1933 if (readbuf
!= NULL
)
1934 regcache
->cooked_read (regnum
, readbuf
);
1938 /* Short vectors are returned in GPRs starting at r3. */
1939 if (TYPE_LENGTH (valtype
) <= 8
1940 && valtype
->code () == TYPE_CODE_ARRAY
&& valtype
->is_vector ())
1942 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + index
;
1945 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1946 offset
= 8 - TYPE_LENGTH (valtype
);
1948 if (writebuf
!= NULL
)
1949 regcache
->cooked_write_part (regnum
, offset
, TYPE_LENGTH (valtype
),
1951 if (readbuf
!= NULL
)
1952 regcache
->cooked_read_part (regnum
, offset
, TYPE_LENGTH (valtype
),
1960 /* The 64 bit ABI return value convention.
1962 Return non-zero if the return-value is stored in a register, return
1963 0 if the return-value is instead stored on the stack (a.k.a.,
1964 struct return convention).
1966 For a return-value stored in a register: when WRITEBUF is non-NULL,
1967 copy the buffer to the corresponding register return-value location
1968 location; when READBUF is non-NULL, fill the buffer from the
1969 corresponding register return-value location. */
1970 enum return_value_convention
1971 ppc64_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1972 struct type
*valtype
, struct regcache
*regcache
,
1973 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1975 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1976 struct type
*func_type
= function
? value_type (function
) : NULL
;
1977 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
1978 struct type
*eltype
;
1981 /* This function exists to support a calling convention that
1982 requires floating-point registers. It shouldn't be used on
1983 processors that lack them. */
1984 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1986 /* Complex types are returned as if two independent scalars. */
1987 if (valtype
->code () == TYPE_CODE_COMPLEX
)
1989 eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1991 for (int i
= 0; i
< 2; i
++)
1993 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
1994 readbuf
, writebuf
, i
);
1998 readbuf
+= TYPE_LENGTH (eltype
);
2000 writebuf
+= TYPE_LENGTH (eltype
);
2002 return RETURN_VALUE_REGISTER_CONVENTION
;
2005 /* OpenCL vectors shorter than 16 bytes are returned as if
2006 a series of independent scalars; OpenCL vectors 16 bytes
2007 or longer are returned as if a series of AltiVec vectors. */
2008 if (valtype
->code () == TYPE_CODE_ARRAY
&& valtype
->is_vector ()
2011 if (TYPE_LENGTH (valtype
) < 16)
2012 eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
2014 eltype
= register_type (gdbarch
, tdep
->ppc_vr0_regnum
);
2016 nelt
= TYPE_LENGTH (valtype
) / TYPE_LENGTH (eltype
);
2017 for (int i
= 0; i
< nelt
; i
++)
2019 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
2020 readbuf
, writebuf
, i
);
2024 readbuf
+= TYPE_LENGTH (eltype
);
2026 writebuf
+= TYPE_LENGTH (eltype
);
2028 return RETURN_VALUE_REGISTER_CONVENTION
;
2031 /* All pointers live in r3. */
2032 if (valtype
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (valtype
))
2034 int regnum
= tdep
->ppc_gp0_regnum
+ 3;
2036 if (writebuf
!= NULL
)
2037 regcache
->cooked_write (regnum
, writebuf
);
2038 if (readbuf
!= NULL
)
2039 regcache
->cooked_read (regnum
, readbuf
);
2040 return RETURN_VALUE_REGISTER_CONVENTION
;
2043 /* Small character arrays are returned, right justified, in r3. */
2044 if (valtype
->code () == TYPE_CODE_ARRAY
2045 && !valtype
->is_vector ()
2046 && TYPE_LENGTH (valtype
) <= 8
2047 && TYPE_TARGET_TYPE (valtype
)->code () == TYPE_CODE_INT
2048 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
2050 int regnum
= tdep
->ppc_gp0_regnum
+ 3;
2051 int offset
= (register_size (gdbarch
, regnum
) - TYPE_LENGTH (valtype
));
2053 if (writebuf
!= NULL
)
2054 regcache
->cooked_write_part (regnum
, offset
, TYPE_LENGTH (valtype
),
2056 if (readbuf
!= NULL
)
2057 regcache
->cooked_read_part (regnum
, offset
, TYPE_LENGTH (valtype
),
2059 return RETURN_VALUE_REGISTER_CONVENTION
;
2062 /* In the ELFv2 ABI, homogeneous floating-point or vector
2063 aggregates are returned in registers. */
2064 if (tdep
->elf_abi
== POWERPC_ELF_V2
2065 && ppc64_elfv2_abi_homogeneous_aggregate (valtype
, &eltype
, &nelt
,
2067 && (eltype
->code () == TYPE_CODE_FLT
2068 || eltype
->code () == TYPE_CODE_DECFLOAT
2069 || (eltype
->code () == TYPE_CODE_ARRAY
2070 && eltype
->is_vector ()
2071 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
2072 && TYPE_LENGTH (eltype
) == 16)))
2074 for (int i
= 0; i
< nelt
; i
++)
2076 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
2077 readbuf
, writebuf
, i
);
2081 readbuf
+= TYPE_LENGTH (eltype
);
2083 writebuf
+= TYPE_LENGTH (eltype
);
2086 return RETURN_VALUE_REGISTER_CONVENTION
;
2089 /* In the ELFv2 ABI, aggregate types of up to 16 bytes are
2090 returned in registers r3:r4. */
2091 if (tdep
->elf_abi
== POWERPC_ELF_V2
2092 && TYPE_LENGTH (valtype
) <= 16
2093 && (valtype
->code () == TYPE_CODE_STRUCT
2094 || valtype
->code () == TYPE_CODE_UNION
2095 || (valtype
->code () == TYPE_CODE_ARRAY
2096 && !valtype
->is_vector ())))
2098 int n_regs
= ((TYPE_LENGTH (valtype
) + tdep
->wordsize
- 1)
2101 for (int i
= 0; i
< n_regs
; i
++)
2103 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
2104 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
2105 int offset
= i
* tdep
->wordsize
;
2106 int len
= TYPE_LENGTH (valtype
) - offset
;
2108 if (len
> tdep
->wordsize
)
2109 len
= tdep
->wordsize
;
2111 if (writebuf
!= NULL
)
2113 memset (regval
, 0, sizeof regval
);
2114 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
2116 memcpy (regval
+ tdep
->wordsize
- len
, writebuf
, len
);
2118 memcpy (regval
, writebuf
+ offset
, len
);
2119 regcache
->cooked_write (regnum
, regval
);
2121 if (readbuf
!= NULL
)
2123 regcache
->cooked_read (regnum
, regval
);
2124 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
2126 memcpy (readbuf
, regval
+ tdep
->wordsize
- len
, len
);
2128 memcpy (readbuf
+ offset
, regval
, len
);
2131 return RETURN_VALUE_REGISTER_CONVENTION
;
2134 /* Handle plain base types. */
2135 if (ppc64_sysv_abi_return_value_base (gdbarch
, valtype
, regcache
,
2136 readbuf
, writebuf
, 0))
2137 return RETURN_VALUE_REGISTER_CONVENTION
;
2139 return RETURN_VALUE_STRUCT_CONVENTION
;