1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright (C) 2000-2024 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/>. */
32 #include "dwarf2/loc.h"
33 #include "target-float.h"
37 /* Check whether FTPYE is a (pointer to) function type that should use
38 the OpenCL vector ABI. */
41 ppc_sysv_use_opencl_abi (struct type
*ftype
)
43 ftype
= check_typedef (ftype
);
45 if (ftype
->code () == TYPE_CODE_PTR
)
46 ftype
= check_typedef (ftype
->target_type ());
48 return (ftype
->code () == TYPE_CODE_FUNC
49 && TYPE_CALLING_CONVENTION (ftype
) == DW_CC_GDB_IBM_OpenCL
);
52 /* Pass the arguments in either registers, or in the stack. Using the
53 ppc sysv ABI, the first eight words of the argument list (that might
54 be less than eight parameters if some parameters occupy more than one
55 word) are passed in r3..r10 registers. float and double parameters are
56 passed in fpr's, in addition to that. Rest of the parameters if any
57 are passed in user stack.
59 If the function is returning a structure, then the return address is passed
60 in r3, then the first 7 words of the parameters can be passed in registers,
64 ppc_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
65 struct regcache
*regcache
, CORE_ADDR bp_addr
,
66 int nargs
, struct value
**args
, CORE_ADDR sp
,
67 function_call_return_method return_method
,
68 CORE_ADDR struct_addr
)
70 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
71 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
72 int opencl_abi
= ppc_sysv_use_opencl_abi (function
->type ());
74 int argspace
= 0; /* 0 is an initial wrong guess. */
77 gdb_assert (tdep
->wordsize
== 4);
79 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
82 /* Go through the argument list twice.
84 Pass 1: Figure out how much new stack space is required for
85 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
86 ABI doesn't reserve any extra space for parameters which are put
87 in registers, but does always push structures and then pass their
90 Pass 2: Replay the same computation but this time also write the
91 values out to the target. */
93 for (write_pass
= 0; write_pass
< 2; write_pass
++)
96 /* Next available floating point register for float and double
99 /* Next available general register for non-float, non-vector
102 /* Next available vector register for vector arguments. */
104 /* Arguments start above the "LR save word" and "Back chain". */
105 int argoffset
= 2 * tdep
->wordsize
;
106 /* Structures start after the arguments. */
107 int structoffset
= argoffset
+ argspace
;
109 /* If the function is returning a `struct', then the first word
110 (which will be passed in r3) is used for struct return
111 address. In that case we should advance one word and start
112 from r4 register to copy parameters. */
113 if (return_method
== return_method_struct
)
116 regcache_cooked_write_signed (regcache
,
117 tdep
->ppc_gp0_regnum
+ greg
,
122 for (argno
= 0; argno
< nargs
; argno
++)
124 struct value
*arg
= args
[argno
];
125 struct type
*type
= check_typedef (arg
->type ());
126 int len
= type
->length ();
127 const bfd_byte
*val
= arg
->contents ().data ();
129 if (type
->code () == TYPE_CODE_FLT
&& len
<= 8
130 && !tdep
->soft_float
)
132 /* Floating point value converted to "double" then
133 passed in an FP register, when the registers run out,
134 8 byte aligned stack is used. */
139 /* Always store the floating point value using
140 the register's floating-point format. */
141 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
143 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
144 target_float_convert (val
, type
, regval
, regtype
);
145 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
,
152 /* The SysV ABI tells us to convert floats to
153 doubles before writing them to an 8 byte aligned
154 stack location. Unfortunately GCC does not do
155 that, and stores floats into 4 byte aligned
156 locations without converting them to doubles.
157 Since there is no know compiler that actually
158 follows the ABI here, we implement the GCC
161 /* Align to 4 bytes or 8 bytes depending on the type of
162 the argument (float or double). */
163 argoffset
= align_up (argoffset
, len
);
165 write_memory (sp
+ argoffset
, val
, len
);
169 else if (type
->code () == TYPE_CODE_FLT
172 && (gdbarch_long_double_format (gdbarch
)
173 == floatformats_ibm_long_double
))
175 /* IBM long double passed in two FP registers if
176 available, otherwise 8-byte aligned stack. */
181 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
, val
);
182 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
+ 1,
189 argoffset
= align_up (argoffset
, 8);
191 write_memory (sp
+ argoffset
, val
, len
);
196 && (type
->code () == TYPE_CODE_INT
/* long long */
197 || type
->code () == TYPE_CODE_FLT
/* double */
198 || (type
->code () == TYPE_CODE_DECFLOAT
199 && tdep
->soft_float
)))
201 /* "long long" or soft-float "double" or "_Decimal64"
202 passed in an odd/even register pair with the low
203 addressed word in the odd register and the high
204 addressed word in the even register, or when the
205 registers run out an 8 byte aligned stack
209 /* Just in case GREG was 10. */
211 argoffset
= align_up (argoffset
, 8);
213 write_memory (sp
+ argoffset
, val
, len
);
218 /* Must start on an odd register - r3/r4 etc. */
223 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 0,
225 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 1,
232 && ((type
->code () == TYPE_CODE_FLT
233 && (gdbarch_long_double_format (gdbarch
)
234 == floatformats_ibm_long_double
))
235 || (type
->code () == TYPE_CODE_DECFLOAT
236 && tdep
->soft_float
)))
238 /* Soft-float IBM long double or _Decimal128 passed in
239 four consecutive registers, or on the stack. The
240 registers are not necessarily odd/even pairs. */
244 argoffset
= align_up (argoffset
, 8);
246 write_memory (sp
+ argoffset
, val
, len
);
253 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 0,
255 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 1,
257 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 2,
259 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 3,
265 else if (type
->code () == TYPE_CODE_DECFLOAT
&& len
<= 8
266 && !tdep
->soft_float
)
268 /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can
275 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
278 /* 32-bit decimal floats are right aligned in the
280 if (type
->length () == 4)
282 memcpy (regval
+ 4, val
, 4);
288 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
, p
);
295 argoffset
= align_up (argoffset
, len
);
298 /* Write value in the stack's parameter save area. */
299 write_memory (sp
+ argoffset
, val
, len
);
304 else if (type
->code () == TYPE_CODE_DECFLOAT
&& len
== 16
305 && !tdep
->soft_float
)
307 /* 128-bit decimal floats go in f2 .. f7, always in even/odd
308 pairs. They can end up in memory, using two doublewords. */
312 /* Make sure freg is even. */
317 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
, val
);
318 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
+ 1,
324 argoffset
= align_up (argoffset
, 8);
327 write_memory (sp
+ argoffset
, val
, 16);
332 /* If a 128-bit decimal float goes to the stack because only f7
333 and f8 are free (thus there's no even/odd register pair
334 available), these registers should be marked as occupied.
335 Hence we increase freg even when writing to memory. */
339 && type
->code () == TYPE_CODE_ARRAY
340 && type
->is_vector ()
343 /* OpenCL vectors shorter than 16 bytes are passed as if
344 a series of independent scalars. */
345 struct type
*eltype
= check_typedef (type
->target_type ());
346 int i
, nelt
= type
->length () / eltype
->length ();
348 for (i
= 0; i
< nelt
; i
++)
350 const gdb_byte
*elval
= val
+ i
* eltype
->length ();
352 if (eltype
->code () == TYPE_CODE_FLT
&& !tdep
->soft_float
)
358 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
359 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
361 = register_type (gdbarch
, regnum
);
362 target_float_convert (elval
, eltype
,
364 regcache
->cooked_write (regnum
, regval
);
370 argoffset
= align_up (argoffset
, len
);
372 write_memory (sp
+ argoffset
, val
, len
);
376 else if (eltype
->length () == 8)
380 /* Just in case GREG was 10. */
382 argoffset
= align_up (argoffset
, 8);
384 write_memory (sp
+ argoffset
, elval
,
390 /* Must start on an odd register - r3/r4 etc. */
395 int regnum
= tdep
->ppc_gp0_regnum
+ greg
;
396 regcache
->cooked_write (regnum
+ 0, elval
+ 0);
397 regcache
->cooked_write (regnum
+ 1, elval
+ 4);
404 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
405 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
406 unpack_long (eltype
, elval
));
411 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
,
417 argoffset
= align_up (argoffset
, tdep
->wordsize
);
419 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
420 argoffset
+= tdep
->wordsize
;
426 && type
->code () == TYPE_CODE_ARRAY
427 && type
->is_vector ()
430 /* OpenCL vectors 16 bytes or longer are passed as if
431 a series of AltiVec vectors. */
434 for (i
= 0; i
< len
/ 16; i
++)
436 const gdb_byte
*elval
= val
+ i
* 16;
441 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ vreg
,
447 argoffset
= align_up (argoffset
, 16);
449 write_memory (sp
+ argoffset
, elval
, 16);
455 && ((type
->code () == TYPE_CODE_ARRAY
456 && type
->is_vector ()
457 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
458 || (type
->code () == TYPE_CODE_FLT
459 && (gdbarch_long_double_format (gdbarch
)
460 == floatformats_ieee_quad
))))
462 /* Vector parameter passed in an Altivec register, or
463 when that runs out, 16 byte aligned stack location.
464 IEEE FLOAT 128-bit also passes parameters in vector
469 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ vreg
, val
);
474 argoffset
= align_up (argoffset
, 16);
476 write_memory (sp
+ argoffset
, val
, 16);
481 && type
->code () == TYPE_CODE_ARRAY
482 && type
->is_vector ()
483 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
485 /* Vector parameter passed in an e500 register, or when
486 that runs out, 8 byte aligned stack location. Note
487 that since e500 vector and general purpose registers
488 both map onto the same underlying register set, a
489 "greg" and not a "vreg" is consumed here. A cooked
490 write stores the value in the correct locations
491 within the raw register cache. */
495 regcache
->cooked_write (tdep
->ppc_ev0_regnum
+ greg
, val
);
500 argoffset
= align_up (argoffset
, 8);
502 write_memory (sp
+ argoffset
, val
, 8);
508 /* Reduce the parameter down to something that fits in a
510 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
511 memset (word
, 0, PPC_MAX_REGISTER_SIZE
);
512 if (len
> tdep
->wordsize
513 || type
->code () == TYPE_CODE_STRUCT
514 || type
->code () == TYPE_CODE_UNION
)
516 /* Structs and large values are put in an
517 aligned stack slot ... */
518 if (type
->code () == TYPE_CODE_ARRAY
519 && type
->is_vector ()
521 structoffset
= align_up (structoffset
, 16);
523 structoffset
= align_up (structoffset
, 8);
526 write_memory (sp
+ structoffset
, val
, len
);
527 /* ... and then a "word" pointing to that address is
528 passed as the parameter. */
529 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
533 else if (type
->code () == TYPE_CODE_INT
)
534 /* Sign or zero extend the "int" into a "word". */
535 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
536 unpack_long (type
, val
));
538 /* Always goes in the low address. */
539 memcpy (word
, val
, len
);
540 /* Store that "word" in a register, or on the stack.
541 The words have "4" byte alignment. */
545 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
, word
);
550 argoffset
= align_up (argoffset
, tdep
->wordsize
);
552 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
553 argoffset
+= tdep
->wordsize
;
558 /* Compute the actual stack space requirements. */
561 /* Remember the amount of space needed by the arguments. */
562 argspace
= argoffset
;
563 /* Allocate space for both the arguments and the structures. */
564 sp
-= (argoffset
+ structoffset
);
565 /* Ensure that the stack is still 16 byte aligned. */
566 sp
= align_down (sp
, 16);
569 /* The psABI says that "A caller of a function that takes a
570 variable argument list shall set condition register bit 6 to
571 1 if it passes one or more arguments in the floating-point
572 registers. It is strongly recommended that the caller set the
573 bit to 0 otherwise..." Doing this for normal functions too
579 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_cr_regnum
, &cr
);
584 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_cr_regnum
, cr
);
589 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
591 /* Write the backchain (it occupies WORDSIZED bytes). */
592 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, saved_sp
);
594 /* Point the inferior function call's return address at the dummy's
596 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
601 /* Handle the return-value conventions for Decimal Floating Point values. */
602 static enum return_value_convention
603 get_decimal_float_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
604 struct regcache
*regcache
, gdb_byte
*readbuf
,
605 const gdb_byte
*writebuf
)
607 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
609 gdb_assert (valtype
->code () == TYPE_CODE_DECFLOAT
);
611 /* 32-bit and 64-bit decimal floats in f1. */
612 if (valtype
->length () <= 8)
614 if (writebuf
!= NULL
)
616 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
619 /* 32-bit decimal float is right aligned in the doubleword. */
620 if (valtype
->length () == 4)
622 memcpy (regval
+ 4, writebuf
, 4);
628 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, p
);
632 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, readbuf
);
634 /* Left align 32-bit decimal float. */
635 if (valtype
->length () == 4)
636 memcpy (readbuf
, readbuf
+ 4, 4);
639 /* 128-bit decimal floats in f2,f3. */
640 else if (valtype
->length () == 16)
642 if (writebuf
!= NULL
|| readbuf
!= NULL
)
646 for (i
= 0; i
< 2; i
++)
648 if (writebuf
!= NULL
)
649 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 2 + i
,
652 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 2 + i
,
659 internal_error (_("Unknown decimal float size."));
661 return RETURN_VALUE_REGISTER_CONVENTION
;
664 /* Handle the return-value conventions specified by the SysV 32-bit
665 PowerPC ABI (including all the supplements):
667 no floating-point: floating-point values returned using 32-bit
668 general-purpose registers.
670 Altivec: 128-bit vectors returned using vector registers.
672 e500: 64-bit vectors returned using the full full 64 bit EV
673 register, floating-point values returned using 32-bit
674 general-purpose registers.
676 GCC (broken): Small struct values right (instead of left) aligned
677 when returned in general-purpose registers. */
679 static enum return_value_convention
680 do_ppc_sysv_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
681 struct type
*type
, struct regcache
*regcache
,
682 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
685 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
686 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
687 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
689 gdb_assert (tdep
->wordsize
== 4);
691 if (type
->code () == TYPE_CODE_FLT
692 && type
->length () <= 8
693 && !tdep
->soft_float
)
697 /* Floats and doubles stored in "f1". Convert the value to
698 the required type. */
699 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
700 struct type
*regtype
= register_type (gdbarch
,
701 tdep
->ppc_fp0_regnum
+ 1);
702 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, regval
);
703 target_float_convert (regval
, regtype
, readbuf
, type
);
707 /* Floats and doubles stored in "f1". Convert the value to
708 the register's "double" type. */
709 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
710 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
711 target_float_convert (writebuf
, type
, regval
, regtype
);
712 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, regval
);
714 return RETURN_VALUE_REGISTER_CONVENTION
;
716 if (type
->code () == TYPE_CODE_FLT
717 && type
->length () == 16
719 && (gdbarch_long_double_format (gdbarch
)
720 == floatformats_ibm_long_double
))
722 /* IBM long double stored in f1 and f2. */
725 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, readbuf
);
726 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 2, readbuf
+ 8);
730 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, writebuf
);
731 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 2, writebuf
+ 8);
733 return RETURN_VALUE_REGISTER_CONVENTION
;
735 if (type
->length () == 16
736 && ((type
->code () == TYPE_CODE_FLT
737 && (gdbarch_long_double_format (gdbarch
)
738 == floatformats_ibm_long_double
))
739 || (type
->code () == TYPE_CODE_DECFLOAT
&& tdep
->soft_float
)))
741 /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
745 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
);
746 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
747 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 5, readbuf
+ 8);
748 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 6, readbuf
+ 12);
752 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
);
753 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
754 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 5, writebuf
+ 8);
755 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 6, writebuf
+ 12);
757 return RETURN_VALUE_REGISTER_CONVENTION
;
759 if ((type
->code () == TYPE_CODE_INT
&& type
->length () == 8)
760 || (type
->code () == TYPE_CODE_FLT
&& type
->length () == 8)
761 || (type
->code () == TYPE_CODE_DECFLOAT
&& type
->length () == 8
762 && tdep
->soft_float
))
766 /* A long long, double or _Decimal64 stored in the 32 bit
768 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
+ 0);
769 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
773 /* A long long, double or _Decimal64 stored in the 32 bit
775 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
+ 0);
776 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
778 return RETURN_VALUE_REGISTER_CONVENTION
;
780 if (type
->code () == TYPE_CODE_DECFLOAT
&& !tdep
->soft_float
)
781 return get_decimal_float_return_value (gdbarch
, type
, regcache
, readbuf
,
783 else if ((type
->code () == TYPE_CODE_INT
784 || type
->code () == TYPE_CODE_CHAR
785 || type
->code () == TYPE_CODE_BOOL
786 || type
->code () == TYPE_CODE_PTR
787 || TYPE_IS_REFERENCE (type
)
788 || type
->code () == TYPE_CODE_ENUM
)
789 && type
->length () <= tdep
->wordsize
)
793 /* Some sort of integer stored in r3. Since TYPE isn't
794 bigger than the register, sign extension isn't a problem
795 - just do everything unsigned. */
797 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
799 store_unsigned_integer (readbuf
, type
->length (), byte_order
,
804 /* Some sort of integer stored in r3. Use unpack_long since
805 that should handle any required sign extension. */
806 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
807 unpack_long (type
, writebuf
));
809 return RETURN_VALUE_REGISTER_CONVENTION
;
811 /* OpenCL vectors < 16 bytes are returned as distinct
812 scalars in f1..f2 or r3..r10. */
813 if (type
->code () == TYPE_CODE_ARRAY
814 && type
->is_vector ()
815 && type
->length () < 16
818 struct type
*eltype
= check_typedef (type
->target_type ());
819 int i
, nelt
= type
->length () / eltype
->length ();
821 for (i
= 0; i
< nelt
; i
++)
823 int offset
= i
* eltype
->length ();
825 if (eltype
->code () == TYPE_CODE_FLT
)
827 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
828 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
829 struct type
*regtype
= register_type (gdbarch
, regnum
);
831 if (writebuf
!= NULL
)
833 target_float_convert (writebuf
+ offset
, eltype
,
835 regcache
->cooked_write (regnum
, regval
);
839 regcache
->cooked_read (regnum
, regval
);
840 target_float_convert (regval
, regtype
,
841 readbuf
+ offset
, eltype
);
846 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
849 if (writebuf
!= NULL
)
851 regval
= unpack_long (eltype
, writebuf
+ offset
);
852 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
856 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
857 store_unsigned_integer (readbuf
+ offset
,
858 eltype
->length (), byte_order
,
864 return RETURN_VALUE_REGISTER_CONVENTION
;
866 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
867 if (type
->code () == TYPE_CODE_ARRAY
868 && type
->is_vector ()
869 && type
->length () >= 16
872 int n_regs
= type
->length () / 16;
875 for (i
= 0; i
< n_regs
; i
++)
878 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
880 if (writebuf
!= NULL
)
881 regcache
->cooked_write (regnum
, writebuf
+ offset
);
883 regcache
->cooked_read (regnum
, readbuf
+ offset
);
886 return RETURN_VALUE_REGISTER_CONVENTION
;
888 if (type
->length () == 16
889 && type
->code () == TYPE_CODE_ARRAY
890 && type
->is_vector ()
891 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
895 /* Altivec places the return value in "v2". */
896 regcache
->cooked_read (tdep
->ppc_vr0_regnum
+ 2, readbuf
);
900 /* Altivec places the return value in "v2". */
901 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ 2, writebuf
);
903 return RETURN_VALUE_REGISTER_CONVENTION
;
905 if (type
->length () == 16
906 && type
->code () == TYPE_CODE_ARRAY
907 && type
->is_vector ()
908 && tdep
->vector_abi
== POWERPC_VEC_GENERIC
)
910 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
911 GCC without AltiVec returns them in memory, but it warns about
912 ABI risks in that case; we don't try to support it. */
915 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
+ 0);
916 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
917 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 5, readbuf
+ 8);
918 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 6, readbuf
+ 12);
922 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
+ 0);
923 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
924 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 5, writebuf
+ 8);
925 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 6, writebuf
+ 12);
927 return RETURN_VALUE_REGISTER_CONVENTION
;
929 if (type
->length () == 8
930 && type
->code () == TYPE_CODE_ARRAY
931 && type
->is_vector ()
932 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
934 /* The e500 ABI places return values for the 64-bit DSP types
935 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
936 corresponds to the entire r3 value for e500, whereas GDB's r3
937 only corresponds to the least significant 32-bits. So place
938 the 64-bit DSP type's value in ev3. */
940 regcache
->cooked_read (tdep
->ppc_ev0_regnum
+ 3, readbuf
);
942 regcache
->cooked_write (tdep
->ppc_ev0_regnum
+ 3, writebuf
);
943 return RETURN_VALUE_REGISTER_CONVENTION
;
945 if (broken_gcc
&& type
->length () <= 8)
947 /* GCC screwed up for structures or unions whose size is less
948 than or equal to 8 bytes.. Instead of left-aligning, it
949 right-aligns the data into the buffer formed by r3, r4. */
950 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
951 int len
= type
->length ();
952 int offset
= (2 * tdep
->wordsize
- len
) % tdep
->wordsize
;
956 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3,
957 regvals
+ 0 * tdep
->wordsize
);
958 if (len
> tdep
->wordsize
)
959 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4,
960 regvals
+ 1 * tdep
->wordsize
);
961 memcpy (readbuf
, regvals
+ offset
, len
);
965 memset (regvals
, 0, sizeof regvals
);
966 memcpy (regvals
+ offset
, writebuf
, len
);
967 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3,
968 regvals
+ 0 * tdep
->wordsize
);
969 if (len
> tdep
->wordsize
)
970 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4,
971 regvals
+ 1 * tdep
->wordsize
);
974 return RETURN_VALUE_REGISTER_CONVENTION
;
976 if (type
->length () <= 8)
980 /* This matches SVr4 PPC, it does not match GCC. */
981 /* The value is right-padded to 8 bytes and then loaded, as
982 two "words", into r3/r4. */
983 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
984 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3,
985 regvals
+ 0 * tdep
->wordsize
);
986 if (type
->length () > tdep
->wordsize
)
987 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4,
988 regvals
+ 1 * tdep
->wordsize
);
989 memcpy (readbuf
, regvals
, type
->length ());
993 /* This matches SVr4 PPC, it does not match GCC. */
994 /* The value is padded out to 8 bytes and then loaded, as
995 two "words" into r3/r4. */
996 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
997 memset (regvals
, 0, sizeof regvals
);
998 memcpy (regvals
, writebuf
, type
->length ());
999 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3,
1000 regvals
+ 0 * tdep
->wordsize
);
1001 if (type
->length () > tdep
->wordsize
)
1002 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4,
1003 regvals
+ 1 * tdep
->wordsize
);
1005 return RETURN_VALUE_REGISTER_CONVENTION
;
1007 return RETURN_VALUE_STRUCT_CONVENTION
;
1010 enum return_value_convention
1011 ppc_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1012 struct type
*valtype
, struct regcache
*regcache
,
1013 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1015 return do_ppc_sysv_return_value (gdbarch
,
1016 function
? function
->type () : NULL
,
1017 valtype
, regcache
, readbuf
, writebuf
, 0);
1020 enum return_value_convention
1021 ppc_sysv_abi_broken_return_value (struct gdbarch
*gdbarch
,
1022 struct value
*function
,
1023 struct type
*valtype
,
1024 struct regcache
*regcache
,
1025 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1027 return do_ppc_sysv_return_value (gdbarch
,
1028 function
? function
->type () : NULL
,
1029 valtype
, regcache
, readbuf
, writebuf
, 1);
1032 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
1033 function's code address back into the function's descriptor
1036 Find a value for the TOC register. Every symbol should have both
1037 ".FN" and "FN" in the minimal symbol table. "FN" points at the
1038 FN's descriptor, while ".FN" points at the entry point (which
1039 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
1040 FN's descriptor address (while at the same time being careful to
1041 find "FN" in the same object file as ".FN"). */
1044 convert_code_addr_to_desc_addr (CORE_ADDR code_addr
, CORE_ADDR
*desc_addr
)
1046 struct obj_section
*dot_fn_section
;
1047 struct bound_minimal_symbol dot_fn
;
1048 struct bound_minimal_symbol fn
;
1050 /* Find the minimal symbol that corresponds to CODE_ADDR (should
1051 have a name of the form ".FN"). */
1052 dot_fn
= lookup_minimal_symbol_by_pc (code_addr
);
1053 if (dot_fn
.minsym
== NULL
|| dot_fn
.minsym
->linkage_name ()[0] != '.')
1055 /* Get the section that contains CODE_ADDR. Need this for the
1056 "objfile" that it contains. */
1057 dot_fn_section
= find_pc_section (code_addr
);
1058 if (dot_fn_section
== NULL
|| dot_fn_section
->objfile
== NULL
)
1060 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
1061 address. Only look for the minimal symbol in ".FN"'s object file
1062 - avoids problems when two object files (i.e., shared libraries)
1063 contain a minimal symbol with the same name. */
1064 fn
= lookup_minimal_symbol (dot_fn
.minsym
->linkage_name () + 1, NULL
,
1065 dot_fn_section
->objfile
);
1066 if (fn
.minsym
== NULL
)
1068 /* Found a descriptor. */
1069 (*desc_addr
) = fn
.value_address ();
1073 /* Walk down the type tree of TYPE counting consecutive base elements.
1074 If *FIELD_TYPE is NULL, then set it to the first valid floating point
1075 or vector type. If a non-floating point or vector type is found, or
1076 if a floating point or vector type that doesn't match a non-NULL
1077 *FIELD_TYPE is found, then return -1, otherwise return the count in the
1081 ppc64_aggregate_candidate (struct type
*type
,
1082 struct type
**field_type
)
1084 type
= check_typedef (type
);
1086 switch (type
->code ())
1089 case TYPE_CODE_DECFLOAT
:
1092 if ((*field_type
)->code () == type
->code ()
1093 && (*field_type
)->length () == type
->length ())
1097 case TYPE_CODE_COMPLEX
:
1098 type
= type
->target_type ();
1099 if (type
->code () == TYPE_CODE_FLT
1100 || type
->code () == TYPE_CODE_DECFLOAT
)
1104 if ((*field_type
)->code () == type
->code ()
1105 && (*field_type
)->length () == type
->length ())
1110 case TYPE_CODE_ARRAY
:
1111 if (type
->is_vector ())
1115 if ((*field_type
)->code () == type
->code ()
1116 && (*field_type
)->length () == type
->length ())
1121 LONGEST count
, low_bound
, high_bound
;
1123 count
= ppc64_aggregate_candidate
1124 (type
->target_type (), field_type
);
1128 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1131 LONGEST nr_array_elements
= (low_bound
> high_bound
1133 : (high_bound
- low_bound
+ 1));
1134 count
*= nr_array_elements
;
1136 /* There must be no padding. */
1138 return type
->length () == 0 ? 0 : -1;
1139 else if (type
->length () != count
* (*field_type
)->length ())
1146 case TYPE_CODE_STRUCT
:
1147 case TYPE_CODE_UNION
:
1152 for (i
= 0; i
< type
->num_fields (); i
++)
1156 if (type
->field (i
).is_static ())
1159 sub_count
= ppc64_aggregate_candidate
1160 (type
->field (i
).type (), field_type
);
1161 if (sub_count
== -1)
1164 if (type
->code () == TYPE_CODE_STRUCT
)
1167 count
= std::max (count
, sub_count
);
1170 /* There must be no padding. */
1172 return type
->length () == 0 ? 0 : -1;
1173 else if (type
->length () != count
* (*field_type
)->length ())
1187 /* If an argument of type TYPE is a homogeneous float or vector aggregate
1188 that shall be passed in FP/vector registers according to the ELFv2 ABI,
1189 return the homogeneous element type in *ELT_TYPE and the number of
1190 elements in *N_ELTS, and return non-zero. Otherwise, return zero. */
1193 ppc64_elfv2_abi_homogeneous_aggregate (struct type
*type
,
1194 struct type
**elt_type
, int *n_elts
,
1195 struct gdbarch
*gdbarch
)
1197 /* Complex types at the top level are treated separately. However,
1198 complex types can be elements of homogeneous aggregates. */
1199 if (type
->code () == TYPE_CODE_STRUCT
1200 || type
->code () == TYPE_CODE_UNION
1201 || (type
->code () == TYPE_CODE_ARRAY
&& !type
->is_vector ()))
1203 struct type
*field_type
= NULL
;
1204 LONGEST field_count
= ppc64_aggregate_candidate (type
, &field_type
);
1206 if (field_count
> 0)
1210 if (field_type
->code () == TYPE_CODE_FLT
1211 && (gdbarch_long_double_format (gdbarch
)
1212 == floatformats_ieee_quad
))
1213 /* IEEE Float 128-bit uses one vector register. */
1216 else if (field_type
->code () == TYPE_CODE_FLT
1217 || field_type
->code () == TYPE_CODE_DECFLOAT
)
1218 n_regs
= (field_type
->length () + 7) >> 3;
1223 /* The ELFv2 ABI allows homogeneous aggregates to occupy
1224 up to 8 registers. */
1225 if (field_count
* n_regs
<= 8)
1228 *elt_type
= field_type
;
1230 *n_elts
= (int) field_count
;
1231 /* Note that field_count is LONGEST since it may hold the size
1232 of an array, while *n_elts is int since its value is bounded
1233 by the number of registers used for argument passing. The
1234 cast cannot overflow due to the bounds checking above. */
1243 /* Structure holding the next argument position. */
1244 struct ppc64_sysv_argpos
1246 /* Register cache holding argument registers. If this is NULL,
1247 we only simulate argument processing without actually updating
1248 any registers or memory. */
1249 struct regcache
*regcache
;
1250 /* Next available general-purpose argument register. */
1252 /* Next available floating-point argument register. */
1254 /* Next available vector argument register. */
1256 /* The address, at which the next general purpose parameter
1257 (integer, struct, float, vector, ...) should be saved. */
1259 /* The address, at which the next by-reference parameter
1260 (non-Altivec vector, variably-sized type) should be saved. */
1264 /* VAL is a value of length LEN. Store it into the argument area on the
1265 stack and load it into the corresponding general-purpose registers
1266 required by the ABI, and update ARGPOS.
1268 If ALIGN is nonzero, it specifies the minimum alignment required
1269 for the on-stack copy of the argument. */
1272 ppc64_sysv_abi_push_val (struct gdbarch
*gdbarch
,
1273 const bfd_byte
*val
, int len
, int align
,
1274 struct ppc64_sysv_argpos
*argpos
)
1276 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1279 /* Enforce alignment of stack location, if requested. */
1280 if (align
> tdep
->wordsize
)
1282 CORE_ADDR aligned_gparam
= align_up (argpos
->gparam
, align
);
1284 argpos
->greg
+= (aligned_gparam
- argpos
->gparam
) / tdep
->wordsize
;
1285 argpos
->gparam
= aligned_gparam
;
1288 /* The ABI (version 1.9) specifies that values smaller than one
1289 doubleword are right-aligned and those larger are left-aligned.
1290 GCC versions before 3.4 implemented this incorrectly; see
1291 <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */
1292 if (len
< tdep
->wordsize
1293 && gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1294 offset
= tdep
->wordsize
- len
;
1296 if (argpos
->regcache
)
1297 write_memory (argpos
->gparam
+ offset
, val
, len
);
1298 argpos
->gparam
= align_up (argpos
->gparam
+ len
, tdep
->wordsize
);
1300 while (len
>= tdep
->wordsize
)
1302 if (argpos
->regcache
&& argpos
->greg
<= 10)
1303 argpos
->regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ argpos
->greg
,
1306 len
-= tdep
->wordsize
;
1307 val
+= tdep
->wordsize
;
1312 if (argpos
->regcache
&& argpos
->greg
<= 10)
1313 argpos
->regcache
->cooked_write_part
1314 (tdep
->ppc_gp0_regnum
+ argpos
->greg
, offset
, len
, val
);
1319 /* The same as ppc64_sysv_abi_push_val, but using a single-word integer
1320 value VAL as argument. */
1323 ppc64_sysv_abi_push_integer (struct gdbarch
*gdbarch
, ULONGEST val
,
1324 struct ppc64_sysv_argpos
*argpos
)
1326 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1327 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1328 gdb_byte buf
[PPC_MAX_REGISTER_SIZE
];
1330 if (argpos
->regcache
)
1331 store_unsigned_integer (buf
, tdep
->wordsize
, byte_order
, val
);
1332 ppc64_sysv_abi_push_val (gdbarch
, buf
, tdep
->wordsize
, 0, argpos
);
1335 /* VAL is a value of TYPE, a (binary or decimal) floating-point type.
1336 Load it into a floating-point register if required by the ABI,
1337 and update ARGPOS. */
1340 ppc64_sysv_abi_push_freg (struct gdbarch
*gdbarch
,
1341 struct type
*type
, const bfd_byte
*val
,
1342 struct ppc64_sysv_argpos
*argpos
)
1344 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1345 if (tdep
->soft_float
)
1348 if (type
->length () <= 8
1349 && type
->code () == TYPE_CODE_FLT
)
1351 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1353 if (argpos
->regcache
&& argpos
->freg
<= 13)
1355 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1356 struct type
*regtype
= register_type (gdbarch
, regnum
);
1357 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
1359 target_float_convert (val
, type
, regval
, regtype
);
1360 argpos
->regcache
->cooked_write (regnum
, regval
);
1365 else if (type
->length () <= 8
1366 && type
->code () == TYPE_CODE_DECFLOAT
)
1368 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1369 placed in the least significant word. */
1370 if (argpos
->regcache
&& argpos
->freg
<= 13)
1372 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1375 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1376 offset
= 8 - type
->length ();
1378 argpos
->regcache
->cooked_write_part (regnum
, offset
,
1379 type
->length (), val
);
1384 else if (type
->length () == 16
1385 && type
->code () == TYPE_CODE_FLT
1386 && (gdbarch_long_double_format (gdbarch
)
1387 == floatformats_ibm_long_double
))
1389 /* IBM long double stored in two consecutive FPRs. */
1390 if (argpos
->regcache
&& argpos
->freg
<= 13)
1392 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1394 argpos
->regcache
->cooked_write (regnum
, val
);
1395 if (argpos
->freg
<= 12)
1396 argpos
->regcache
->cooked_write (regnum
+ 1, val
+ 8);
1401 else if (type
->length () == 16
1402 && type
->code () == TYPE_CODE_DECFLOAT
)
1404 /* 128-bit decimal floating-point values are stored in and even/odd
1405 pair of FPRs, with the even FPR holding the most significant half. */
1406 argpos
->freg
+= argpos
->freg
& 1;
1408 if (argpos
->regcache
&& argpos
->freg
<= 12)
1410 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1411 int lopart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 : 0;
1412 int hipart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 0 : 8;
1414 argpos
->regcache
->cooked_write (regnum
, val
+ hipart
);
1415 argpos
->regcache
->cooked_write (regnum
+ 1, val
+ lopart
);
1422 /* VAL is a value of AltiVec vector type. Load it into a vector register
1423 if required by the ABI, and update ARGPOS. */
1426 ppc64_sysv_abi_push_vreg (struct gdbarch
*gdbarch
, const bfd_byte
*val
,
1427 struct ppc64_sysv_argpos
*argpos
)
1429 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1431 if (argpos
->regcache
&& argpos
->vreg
<= 13)
1432 argpos
->regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ argpos
->vreg
, val
);
1437 /* VAL is a value of TYPE. Load it into memory and/or registers
1438 as required by the ABI, and update ARGPOS. */
1441 ppc64_sysv_abi_push_param (struct gdbarch
*gdbarch
,
1442 struct type
*type
, const bfd_byte
*val
,
1443 struct ppc64_sysv_argpos
*argpos
)
1445 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1447 if (type
->code () == TYPE_CODE_FLT
1448 && type
->length () == 16
1449 && (gdbarch_long_double_format (gdbarch
)
1450 == floatformats_ieee_quad
))
1452 /* IEEE FLOAT128, args in vector registers. */
1453 ppc64_sysv_abi_push_val (gdbarch
, val
, type
->length (), 16, argpos
);
1454 ppc64_sysv_abi_push_vreg (gdbarch
, val
, argpos
);
1456 else if (type
->code () == TYPE_CODE_FLT
1457 || type
->code () == TYPE_CODE_DECFLOAT
)
1459 /* Floating-point scalars are passed in floating-point registers. */
1460 ppc64_sysv_abi_push_val (gdbarch
, val
, type
->length (), 0, argpos
);
1461 ppc64_sysv_abi_push_freg (gdbarch
, type
, val
, argpos
);
1463 else if (type
->code () == TYPE_CODE_ARRAY
&& type
->is_vector ()
1464 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
1465 && type
->length () == 16)
1467 /* AltiVec vectors are passed aligned, and in vector registers. */
1468 ppc64_sysv_abi_push_val (gdbarch
, val
, type
->length (), 16, argpos
);
1469 ppc64_sysv_abi_push_vreg (gdbarch
, val
, argpos
);
1471 else if (type
->code () == TYPE_CODE_ARRAY
&& type
->is_vector ()
1472 && type
->length () >= 16)
1474 /* Non-Altivec vectors are passed by reference. */
1476 /* Copy value onto the stack ... */
1477 CORE_ADDR addr
= align_up (argpos
->refparam
, 16);
1478 if (argpos
->regcache
)
1479 write_memory (addr
, val
, type
->length ());
1480 argpos
->refparam
= align_up (addr
+ type
->length (), tdep
->wordsize
);
1482 /* ... and pass a pointer to the copy as parameter. */
1483 ppc64_sysv_abi_push_integer (gdbarch
, addr
, argpos
);
1485 else if ((type
->code () == TYPE_CODE_INT
1486 || type
->code () == TYPE_CODE_ENUM
1487 || type
->code () == TYPE_CODE_BOOL
1488 || type
->code () == TYPE_CODE_CHAR
1489 || type
->code () == TYPE_CODE_PTR
1490 || TYPE_IS_REFERENCE (type
))
1491 && type
->length () <= tdep
->wordsize
)
1495 if (argpos
->regcache
)
1497 /* Sign extend the value, then store it unsigned. */
1498 word
= unpack_long (type
, val
);
1500 /* Convert any function code addresses into descriptors. */
1501 if (tdep
->elf_abi
== POWERPC_ELF_V1
1502 && (type
->code () == TYPE_CODE_PTR
1503 || type
->code () == TYPE_CODE_REF
))
1505 struct type
*target_type
1506 = check_typedef (type
->target_type ());
1508 if (target_type
->code () == TYPE_CODE_FUNC
1509 || target_type
->code () == TYPE_CODE_METHOD
)
1511 CORE_ADDR desc
= word
;
1513 convert_code_addr_to_desc_addr (word
, &desc
);
1519 ppc64_sysv_abi_push_integer (gdbarch
, word
, argpos
);
1523 /* Align == 0 is correct for ppc64_sysv_abi_push_freg,
1524 Align == 16 is correct for ppc64_sysv_abi_push_vreg.
1528 /* The ABI (version 1.9) specifies that structs containing a
1529 single floating-point value, at any level of nesting of
1530 single-member structs, are passed in floating-point registers. */
1531 if (type
->code () == TYPE_CODE_STRUCT
1532 && type
->num_fields () == 1 && tdep
->elf_abi
== POWERPC_ELF_V1
)
1534 while (type
->code () == TYPE_CODE_STRUCT
1535 && type
->num_fields () == 1)
1536 type
= check_typedef (type
->field (0).type ());
1538 if (type
->code () == TYPE_CODE_FLT
) {
1539 /* Handle the case of 128-bit floats for both IEEE and IBM long double
1541 if (type
->length () == 16
1542 && (gdbarch_long_double_format (gdbarch
)
1543 == floatformats_ieee_quad
))
1545 ppc64_sysv_abi_push_vreg (gdbarch
, val
, argpos
);
1549 ppc64_sysv_abi_push_freg (gdbarch
, type
, val
, argpos
);
1553 /* In the ELFv2 ABI, homogeneous floating-point or vector
1554 aggregates are passed in a series of registers. */
1555 if (tdep
->elf_abi
== POWERPC_ELF_V2
)
1557 struct type
*eltype
;
1560 if (ppc64_elfv2_abi_homogeneous_aggregate (type
, &eltype
, &nelt
,
1562 for (i
= 0; i
< nelt
; i
++)
1564 const gdb_byte
*elval
= val
+ i
* eltype
->length ();
1566 if (eltype
->code () == TYPE_CODE_FLT
1567 && eltype
->length () == 16
1568 && (gdbarch_long_double_format (gdbarch
)
1569 == floatformats_ieee_quad
))
1570 /* IEEE FLOAT128, args in vector registers. */
1572 ppc64_sysv_abi_push_vreg (gdbarch
, elval
, argpos
);
1575 else if (eltype
->code () == TYPE_CODE_FLT
1576 || eltype
->code () == TYPE_CODE_DECFLOAT
)
1577 /* IBM long double and all other floats and decfloats, args
1578 are in a pair of floating point registers. */
1579 ppc64_sysv_abi_push_freg (gdbarch
, eltype
, elval
, argpos
);
1580 else if (eltype
->code () == TYPE_CODE_ARRAY
1581 && eltype
->is_vector ()
1582 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
1583 && eltype
->length () == 16)
1585 ppc64_sysv_abi_push_vreg (gdbarch
, elval
, argpos
);
1591 ppc64_sysv_abi_push_val (gdbarch
, val
, type
->length (), align
, argpos
);
1595 /* Pass the arguments in either registers, or in the stack. Using the
1596 ppc 64 bit SysV ABI.
1598 This implements a dumbed down version of the ABI. It always writes
1599 values to memory, GPR and FPR, even when not necessary. Doing this
1600 greatly simplifies the logic. */
1603 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
,
1604 struct value
*function
,
1605 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1606 int nargs
, struct value
**args
, CORE_ADDR sp
,
1607 function_call_return_method return_method
,
1608 CORE_ADDR struct_addr
)
1610 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
1611 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1612 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1613 int opencl_abi
= ppc_sysv_use_opencl_abi (function
->type ());
1614 ULONGEST back_chain
;
1615 /* See for-loop comment below. */
1617 /* Size of the by-reference parameter copy region, the final value is
1618 computed in the for-loop below. */
1619 LONGEST refparam_size
= 0;
1620 /* Size of the general parameter region, the final value is computed
1621 in the for-loop below. */
1622 LONGEST gparam_size
= 0;
1623 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
1624 calls to align_up(), align_down(), etc. because this makes it
1625 easier to reuse this code (in a copy/paste sense) in the future,
1626 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
1627 at some point makes it easier to verify that this function is
1628 correct without having to do a non-local analysis to figure out
1629 the possible values of tdep->wordsize. */
1630 gdb_assert (tdep
->wordsize
== 8);
1632 /* This function exists to support a calling convention that
1633 requires floating-point registers. It shouldn't be used on
1634 processors that lack them. */
1635 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1637 /* By this stage in the proceedings, SP has been decremented by "red
1638 zone size" + "struct return size". Fetch the stack-pointer from
1639 before this and use that as the BACK_CHAIN. */
1640 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
1643 /* Go through the argument list twice.
1645 Pass 1: Compute the function call's stack space and register
1648 Pass 2: Replay the same computation but this time also write the
1649 values out to the target. */
1651 for (write_pass
= 0; write_pass
< 2; write_pass
++)
1655 struct ppc64_sysv_argpos argpos
;
1662 /* During the first pass, GPARAM and REFPARAM are more like
1663 offsets (start address zero) than addresses. That way
1664 they accumulate the total stack space each region
1666 argpos
.regcache
= NULL
;
1668 argpos
.refparam
= 0;
1672 /* Decrement the stack pointer making space for the Altivec
1673 and general on-stack parameters. Set refparam and gparam
1674 to their corresponding regions. */
1675 argpos
.regcache
= regcache
;
1676 argpos
.refparam
= align_down (sp
- refparam_size
, 16);
1677 argpos
.gparam
= align_down (argpos
.refparam
- gparam_size
, 16);
1678 /* Add in space for the TOC, link editor double word (v1 only),
1679 compiler double word (v1 only), LR save area, CR save area,
1681 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1682 sp
= align_down (argpos
.gparam
- 48, 16);
1684 sp
= align_down (argpos
.gparam
- 32, 16);
1687 /* If the function is returning a `struct', then there is an
1688 extra hidden parameter (which will be passed in r3)
1689 containing the address of that struct.. In that case we
1690 should advance one word and start from r4 register to copy
1691 parameters. This also consumes one on-stack parameter slot. */
1692 if (return_method
== return_method_struct
)
1693 ppc64_sysv_abi_push_integer (gdbarch
, struct_addr
, &argpos
);
1695 for (argno
= 0; argno
< nargs
; argno
++)
1697 struct value
*arg
= args
[argno
];
1698 struct type
*type
= check_typedef (arg
->type ());
1699 const bfd_byte
*val
= arg
->contents ().data ();
1701 if (type
->code () == TYPE_CODE_COMPLEX
)
1703 /* Complex types are passed as if two independent scalars. */
1704 struct type
*eltype
= check_typedef (type
->target_type ());
1706 ppc64_sysv_abi_push_param (gdbarch
, eltype
, val
, &argpos
);
1707 ppc64_sysv_abi_push_param (gdbarch
, eltype
,
1708 val
+ eltype
->length (), &argpos
);
1710 else if (type
->code () == TYPE_CODE_ARRAY
&& type
->is_vector ()
1713 /* OpenCL vectors shorter than 16 bytes are passed as if
1714 a series of independent scalars; OpenCL vectors 16 bytes
1715 or longer are passed as if a series of AltiVec vectors. */
1716 struct type
*eltype
;
1719 if (type
->length () < 16)
1720 eltype
= check_typedef (type
->target_type ());
1722 eltype
= register_type (gdbarch
, tdep
->ppc_vr0_regnum
);
1724 nelt
= type
->length () / eltype
->length ();
1725 for (i
= 0; i
< nelt
; i
++)
1727 const gdb_byte
*elval
= val
+ i
* eltype
->length ();
1729 ppc64_sysv_abi_push_param (gdbarch
, eltype
, elval
, &argpos
);
1734 /* All other types are passed as single arguments. */
1735 ppc64_sysv_abi_push_param (gdbarch
, type
, val
, &argpos
);
1741 /* Save the true region sizes ready for the second pass. */
1742 refparam_size
= argpos
.refparam
;
1743 /* Make certain that the general parameter save area is at
1744 least the minimum 8 registers (or doublewords) in size. */
1745 if (argpos
.greg
< 8)
1746 gparam_size
= 8 * tdep
->wordsize
;
1748 gparam_size
= argpos
.gparam
;
1753 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
1755 /* Write the backchain (it occupies WORDSIZED bytes). */
1756 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, back_chain
);
1758 /* Point the inferior function call's return address at the dummy's
1760 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
1762 /* In the ELFv1 ABI, use the func_addr to find the descriptor, and use
1763 that to find the TOC. If we're calling via a function pointer,
1764 the pointer itself identifies the descriptor. */
1765 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1767 struct type
*ftype
= check_typedef (function
->type ());
1768 CORE_ADDR desc_addr
= value_as_address (function
);
1770 if (ftype
->code () == TYPE_CODE_PTR
1771 || convert_code_addr_to_desc_addr (func_addr
, &desc_addr
))
1773 /* The TOC is the second double word in the descriptor. */
1775 read_memory_unsigned_integer (desc_addr
+ tdep
->wordsize
,
1776 tdep
->wordsize
, byte_order
);
1778 regcache_cooked_write_unsigned (regcache
,
1779 tdep
->ppc_gp0_regnum
+ 2, toc
);
1783 /* In the ELFv2 ABI, we need to pass the target address in r12 since
1784 we may be calling a global entry point. */
1785 if (tdep
->elf_abi
== POWERPC_ELF_V2
)
1786 regcache_cooked_write_unsigned (regcache
,
1787 tdep
->ppc_gp0_regnum
+ 12, func_addr
);
1792 /* Subroutine of ppc64_sysv_abi_return_value that handles "base" types:
1793 integer, floating-point, and AltiVec vector types.
1795 This routine also handles components of aggregate return types;
1796 INDEX describes which part of the aggregate is to be handled.
1798 Returns true if VALTYPE is some such base type that could be handled,
1801 ppc64_sysv_abi_return_value_base (struct gdbarch
*gdbarch
, struct type
*valtype
,
1802 struct regcache
*regcache
, gdb_byte
*readbuf
,
1803 const gdb_byte
*writebuf
, int index
)
1805 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1807 /* Integers live in GPRs starting at r3. */
1808 if ((valtype
->code () == TYPE_CODE_INT
1809 || valtype
->code () == TYPE_CODE_ENUM
1810 || valtype
->code () == TYPE_CODE_CHAR
1811 || valtype
->code () == TYPE_CODE_BOOL
1812 || valtype
->code () == TYPE_CODE_RANGE
1813 || is_fixed_point_type (valtype
))
1814 && valtype
->length () <= 8)
1816 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + index
;
1818 if (writebuf
!= NULL
)
1822 if (is_fixed_point_type (valtype
))
1824 /* Fixed point type values need to be returned unscaled. */
1827 unscaled
.read (gdb::make_array_view (writebuf
,
1828 valtype
->length ()),
1829 type_byte_order (valtype
),
1830 valtype
->is_unsigned ());
1831 return_val
= unscaled
.as_integer
<LONGEST
> ();
1834 return_val
= unpack_long (valtype
, writebuf
);
1836 /* Be careful to sign extend the value. */
1837 regcache_cooked_write_unsigned (regcache
, regnum
, return_val
);
1839 if (readbuf
!= NULL
)
1841 /* Extract the integer from GPR. Since this is truncating the
1842 value, there isn't a sign extension problem. */
1845 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
1846 store_unsigned_integer (readbuf
, valtype
->length (),
1847 gdbarch_byte_order (gdbarch
), regval
);
1852 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1854 if (valtype
->length () <= 8
1855 && valtype
->code () == TYPE_CODE_FLT
)
1857 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + index
;
1858 struct type
*regtype
= register_type (gdbarch
, regnum
);
1859 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
1861 if (writebuf
!= NULL
)
1863 target_float_convert (writebuf
, valtype
, regval
, regtype
);
1864 regcache
->cooked_write (regnum
, regval
);
1866 if (readbuf
!= NULL
)
1868 regcache
->cooked_read (regnum
, regval
);
1869 target_float_convert (regval
, regtype
, readbuf
, valtype
);
1874 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1875 placed in the least significant word. */
1876 if (valtype
->length () <= 8
1877 && valtype
->code () == TYPE_CODE_DECFLOAT
)
1879 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + index
;
1882 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1883 offset
= 8 - valtype
->length ();
1885 if (writebuf
!= NULL
)
1886 regcache
->cooked_write_part (regnum
, offset
, valtype
->length (),
1888 if (readbuf
!= NULL
)
1889 regcache
->cooked_read_part (regnum
, offset
, valtype
->length (),
1894 /* IBM long double stored in two consecutive FPRs. */
1895 if (valtype
->length () == 16
1896 && valtype
->code () == TYPE_CODE_FLT
1897 && (gdbarch_long_double_format (gdbarch
)
1898 == floatformats_ibm_long_double
))
1900 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + 2 * index
;
1902 if (writebuf
!= NULL
)
1904 regcache
->cooked_write (regnum
, writebuf
);
1905 regcache
->cooked_write (regnum
+ 1, writebuf
+ 8);
1907 if (readbuf
!= NULL
)
1909 regcache
->cooked_read (regnum
, readbuf
);
1910 regcache
->cooked_read (regnum
+ 1, readbuf
+ 8);
1915 /* 128-bit decimal floating-point values are stored in an even/odd
1916 pair of FPRs, with the even FPR holding the most significant half. */
1917 if (valtype
->length () == 16
1918 && valtype
->code () == TYPE_CODE_DECFLOAT
)
1920 int regnum
= tdep
->ppc_fp0_regnum
+ 2 + 2 * index
;
1921 int lopart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 : 0;
1922 int hipart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 0 : 8;
1924 if (writebuf
!= NULL
)
1926 regcache
->cooked_write (regnum
, writebuf
+ hipart
);
1927 regcache
->cooked_write (regnum
+ 1, writebuf
+ lopart
);
1929 if (readbuf
!= NULL
)
1931 regcache
->cooked_read (regnum
, readbuf
+ hipart
);
1932 regcache
->cooked_read (regnum
+ 1, readbuf
+ lopart
);
1937 /* AltiVec vectors are returned in VRs starting at v2.
1938 IEEE FLOAT 128-bit are stored in vector register. */
1940 if (valtype
->length () == 16
1941 && ((valtype
->code () == TYPE_CODE_ARRAY
1942 && valtype
->is_vector ()
1943 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1944 || (valtype
->code () == TYPE_CODE_FLT
1945 && (gdbarch_long_double_format (gdbarch
)
1946 == floatformats_ieee_quad
))))
1948 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + index
;
1950 if (writebuf
!= NULL
)
1951 regcache
->cooked_write (regnum
, writebuf
);
1952 if (readbuf
!= NULL
)
1953 regcache
->cooked_read (regnum
, readbuf
);
1957 /* Short vectors are returned in GPRs starting at r3. */
1958 if (valtype
->length () <= 8
1959 && valtype
->code () == TYPE_CODE_ARRAY
&& valtype
->is_vector ())
1961 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + index
;
1964 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1965 offset
= 8 - valtype
->length ();
1967 if (writebuf
!= NULL
)
1968 regcache
->cooked_write_part (regnum
, offset
, valtype
->length (),
1970 if (readbuf
!= NULL
)
1971 regcache
->cooked_read_part (regnum
, offset
, valtype
->length (),
1979 /* The 64 bit ABI return value convention.
1981 Return non-zero if the return-value is stored in a register, return
1982 0 if the return-value is instead stored on the stack (a.k.a.,
1983 struct return convention).
1985 For a return-value stored in a register: when WRITEBUF is non-NULL,
1986 copy the buffer to the corresponding register return-value location
1987 location; when READBUF is non-NULL, fill the buffer from the
1988 corresponding register return-value location. */
1989 enum return_value_convention
1990 ppc64_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1991 struct type
*valtype
, struct regcache
*regcache
,
1992 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1994 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1995 struct type
*func_type
= function
? function
->type () : NULL
;
1996 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
1997 struct type
*eltype
;
2000 /* This function exists to support a calling convention that
2001 requires floating-point registers. It shouldn't be used on
2002 processors that lack them. */
2003 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
2005 /* Complex types are returned as if two independent scalars. */
2006 if (valtype
->code () == TYPE_CODE_COMPLEX
)
2008 eltype
= check_typedef (valtype
->target_type ());
2010 for (int i
= 0; i
< 2; i
++)
2012 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
2013 readbuf
, writebuf
, i
);
2017 readbuf
+= eltype
->length ();
2019 writebuf
+= eltype
->length ();
2021 return RETURN_VALUE_REGISTER_CONVENTION
;
2024 /* OpenCL vectors shorter than 16 bytes are returned as if
2025 a series of independent scalars; OpenCL vectors 16 bytes
2026 or longer are returned as if a series of AltiVec vectors. */
2027 if (valtype
->code () == TYPE_CODE_ARRAY
&& valtype
->is_vector ()
2030 if (valtype
->length () < 16)
2031 eltype
= check_typedef (valtype
->target_type ());
2033 eltype
= register_type (gdbarch
, tdep
->ppc_vr0_regnum
);
2035 nelt
= valtype
->length () / eltype
->length ();
2036 for (int i
= 0; i
< nelt
; i
++)
2038 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
2039 readbuf
, writebuf
, i
);
2043 readbuf
+= eltype
->length ();
2045 writebuf
+= eltype
->length ();
2047 return RETURN_VALUE_REGISTER_CONVENTION
;
2050 /* All pointers live in r3. */
2051 if (valtype
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (valtype
))
2053 int regnum
= tdep
->ppc_gp0_regnum
+ 3;
2055 if (writebuf
!= NULL
)
2056 regcache
->cooked_write (regnum
, writebuf
);
2057 if (readbuf
!= NULL
)
2058 regcache
->cooked_read (regnum
, readbuf
);
2059 return RETURN_VALUE_REGISTER_CONVENTION
;
2062 /* Small character arrays are returned, right justified, in r3. */
2063 if (valtype
->code () == TYPE_CODE_ARRAY
2064 && !valtype
->is_vector ()
2065 && valtype
->length () <= 8
2066 && valtype
->target_type ()->code () == TYPE_CODE_INT
2067 && valtype
->target_type ()->length () == 1)
2069 int regnum
= tdep
->ppc_gp0_regnum
+ 3;
2070 int offset
= (register_size (gdbarch
, regnum
) - valtype
->length ());
2072 if (writebuf
!= NULL
)
2073 regcache
->cooked_write_part (regnum
, offset
, valtype
->length (),
2075 if (readbuf
!= NULL
)
2076 regcache
->cooked_read_part (regnum
, offset
, valtype
->length (),
2078 return RETURN_VALUE_REGISTER_CONVENTION
;
2081 /* In the ELFv2 ABI, homogeneous floating-point or vector
2082 aggregates are returned in registers. */
2083 if (tdep
->elf_abi
== POWERPC_ELF_V2
2084 && ppc64_elfv2_abi_homogeneous_aggregate (valtype
, &eltype
, &nelt
,
2086 && (eltype
->code () == TYPE_CODE_FLT
2087 || eltype
->code () == TYPE_CODE_DECFLOAT
2088 || (eltype
->code () == TYPE_CODE_ARRAY
2089 && eltype
->is_vector ()
2090 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
2091 && eltype
->length () == 16)))
2093 for (int i
= 0; i
< nelt
; i
++)
2095 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
2096 readbuf
, writebuf
, i
);
2100 readbuf
+= eltype
->length ();
2102 writebuf
+= eltype
->length ();
2105 return RETURN_VALUE_REGISTER_CONVENTION
;
2108 if (!language_pass_by_reference (valtype
).trivially_copyable
2109 && valtype
->code () == TYPE_CODE_STRUCT
)
2110 return RETURN_VALUE_STRUCT_CONVENTION
;
2112 /* In the ELFv2 ABI, aggregate types of up to 16 bytes are
2113 returned in registers r3:r4. */
2114 if (tdep
->elf_abi
== POWERPC_ELF_V2
2115 && valtype
->length () <= 16
2116 && (valtype
->code () == TYPE_CODE_STRUCT
2117 || valtype
->code () == TYPE_CODE_UNION
2118 || (valtype
->code () == TYPE_CODE_ARRAY
2119 && !valtype
->is_vector ())))
2121 int n_regs
= ((valtype
->length () + tdep
->wordsize
- 1)
2124 for (int i
= 0; i
< n_regs
; i
++)
2126 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
2127 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
2128 int offset
= i
* tdep
->wordsize
;
2129 int len
= valtype
->length () - offset
;
2131 if (len
> tdep
->wordsize
)
2132 len
= tdep
->wordsize
;
2134 if (writebuf
!= NULL
)
2136 memset (regval
, 0, sizeof regval
);
2137 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
2139 memcpy (regval
+ tdep
->wordsize
- len
, writebuf
, len
);
2141 memcpy (regval
, writebuf
+ offset
, len
);
2142 regcache
->cooked_write (regnum
, regval
);
2144 if (readbuf
!= NULL
)
2146 regcache
->cooked_read (regnum
, regval
);
2147 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
2149 memcpy (readbuf
, regval
+ tdep
->wordsize
- len
, len
);
2151 memcpy (readbuf
+ offset
, regval
, len
);
2154 return RETURN_VALUE_REGISTER_CONVENTION
;
2157 /* Handle plain base types. */
2158 if (ppc64_sysv_abi_return_value_base (gdbarch
, valtype
, regcache
,
2159 readbuf
, writebuf
, 0))
2160 return RETURN_VALUE_REGISTER_CONVENTION
;
2162 return RETURN_VALUE_STRUCT_CONVENTION
;
2166 ppc_sysv_get_return_buf_addr (struct type
*val_type
,
2167 const frame_info_ptr
&cur_frame
)
2169 /* The PowerPC ABI specifies aggregates that are not returned by value
2170 are returned in a storage buffer provided by the caller. The
2171 address of the storage buffer is provided as a hidden first input
2172 argument in register r3. The PowerPC ABI does not guarantee that
2173 register r3 will not be changed while executing the function. Hence, it
2174 cannot be assumed that r3 will still contain the address of the storage
2175 buffer when execution reaches the end of the function.
2177 This function attempts to determine the value of r3 on entry to the
2178 function using the DW_OP_entry_value DWARF entries. This requires
2179 compiling the user program with -fvar-tracking to resolve the
2180 DW_TAG_call_sites in the binary file. */
2182 union call_site_parameter_u kind_u
;
2183 enum call_site_parameter_kind kind
;
2184 CORE_ADDR return_val
= 0;
2186 kind_u
.dwarf_reg
= 3; /* First passed arg/return value is in r3. */
2187 kind
= CALL_SITE_PARAMETER_DWARF_REG
;
2189 /* val_type is the type of the return value. Need the pointer type
2190 to the return value. */
2191 val_type
= lookup_pointer_type (val_type
);
2195 return_val
= value_as_address (value_of_dwarf_reg_entry (val_type
,
2199 catch (const gdb_exception_error
&e
)
2201 warning ("Cannot determine the function return value.\n"
2202 "Try compiling with -fvar-tracking.");