1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright (C) 2000-2003, 2005, 2007-2012 Free Software Foundation,
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
36 /* Check whether FTPYE is a (pointer to) function type that should use
37 the OpenCL vector ABI. */
40 ppc_sysv_use_opencl_abi (struct type
*ftype
)
42 ftype
= check_typedef (ftype
);
44 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
)
45 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
47 return (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
48 && TYPE_CALLING_CONVENTION (ftype
) == DW_CC_GDB_IBM_OpenCL
);
51 /* Pass the arguments in either registers, or in the stack. Using the
52 ppc sysv ABI, the first eight words of the argument list (that might
53 be less than eight parameters if some parameters occupy more than one
54 word) are passed in r3..r10 registers. float and double parameters are
55 passed in fpr's, in addition to that. Rest of the parameters if any
56 are passed in user stack.
58 If the function is returning a structure, then the return address is passed
59 in r3, then the first 7 words of the parametes can be passed in registers,
63 ppc_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
64 struct regcache
*regcache
, CORE_ADDR bp_addr
,
65 int nargs
, struct value
**args
, CORE_ADDR sp
,
66 int struct_return
, CORE_ADDR struct_addr
)
68 struct gdbarch_tdep
*tdep
= 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. */
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
);
127 if (TYPE_CODE (type
) == 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
[MAX_REGISTER_SIZE
];
141 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
142 convert_typed_floating (val
, type
, regval
, regtype
);
143 regcache_cooked_write (regcache
,
144 tdep
->ppc_fp0_regnum
+ freg
,
151 /* The SysV ABI tells us to convert floats to
152 doubles before writing them to an 8 byte aligned
153 stack location. Unfortunately GCC does not do
154 that, and stores floats into 4 byte aligned
155 locations without converting them to doubles.
156 Since there is no know compiler that actually
157 follows the ABI here, we implement the GCC
160 /* Align to 4 bytes or 8 bytes depending on the type of
161 the argument (float or double). */
162 argoffset
= align_up (argoffset
, len
);
164 write_memory (sp
+ argoffset
, val
, len
);
168 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
171 && (gdbarch_long_double_format (gdbarch
)
172 == floatformats_ibm_long_double
))
174 /* IBM long double passed in two FP registers if
175 available, otherwise 8-byte aligned stack. */
180 regcache_cooked_write (regcache
,
181 tdep
->ppc_fp0_regnum
+ freg
,
183 regcache_cooked_write (regcache
,
184 tdep
->ppc_fp0_regnum
+ freg
+ 1,
191 argoffset
= align_up (argoffset
, 8);
193 write_memory (sp
+ argoffset
, val
, len
);
198 && (TYPE_CODE (type
) == TYPE_CODE_INT
/* long long */
199 || TYPE_CODE (type
) == TYPE_CODE_FLT
/* double */
200 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
201 && tdep
->soft_float
)))
203 /* "long long" or soft-float "double" or "_Decimal64"
204 passed in an odd/even register pair with the low
205 addressed word in the odd register and the high
206 addressed word in the even register, or when the
207 registers run out an 8 byte aligned stack
211 /* Just in case GREG was 10. */
213 argoffset
= align_up (argoffset
, 8);
215 write_memory (sp
+ argoffset
, val
, len
);
220 /* Must start on an odd register - r3/r4 etc. */
225 regcache_cooked_write (regcache
,
226 tdep
->ppc_gp0_regnum
+ greg
+ 0,
228 regcache_cooked_write (regcache
,
229 tdep
->ppc_gp0_regnum
+ greg
+ 1,
236 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
237 && (gdbarch_long_double_format (gdbarch
)
238 == floatformats_ibm_long_double
))
239 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
240 && tdep
->soft_float
)))
242 /* Soft-float IBM long double or _Decimal128 passed in
243 four consecutive registers, or on the stack. The
244 registers are not necessarily odd/even pairs. */
248 argoffset
= align_up (argoffset
, 8);
250 write_memory (sp
+ argoffset
, val
, len
);
257 regcache_cooked_write (regcache
,
258 tdep
->ppc_gp0_regnum
+ greg
+ 0,
260 regcache_cooked_write (regcache
,
261 tdep
->ppc_gp0_regnum
+ greg
+ 1,
263 regcache_cooked_write (regcache
,
264 tdep
->ppc_gp0_regnum
+ greg
+ 2,
266 regcache_cooked_write (regcache
,
267 tdep
->ppc_gp0_regnum
+ greg
+ 3,
273 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
<= 8
274 && !tdep
->soft_float
)
276 /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can
283 gdb_byte regval
[MAX_REGISTER_SIZE
];
286 /* 32-bit decimal floats are right aligned in the
288 if (TYPE_LENGTH (type
) == 4)
290 memcpy (regval
+ 4, val
, 4);
296 regcache_cooked_write (regcache
,
297 tdep
->ppc_fp0_regnum
+ freg
, p
);
304 argoffset
= align_up (argoffset
, len
);
307 /* Write value in the stack's parameter save area. */
308 write_memory (sp
+ argoffset
, val
, len
);
313 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
== 16
314 && !tdep
->soft_float
)
316 /* 128-bit decimal floats go in f2 .. f7, always in even/odd
317 pairs. They can end up in memory, using two doublewords. */
321 /* Make sure freg is even. */
326 regcache_cooked_write (regcache
,
327 tdep
->ppc_fp0_regnum
+ freg
, val
);
328 regcache_cooked_write (regcache
,
329 tdep
->ppc_fp0_regnum
+ freg
+ 1, val
+ 8);
334 argoffset
= align_up (argoffset
, 8);
337 write_memory (sp
+ argoffset
, val
, 16);
342 /* If a 128-bit decimal float goes to the stack because only f7
343 and f8 are free (thus there's no even/odd register pair
344 available), these registers should be marked as occupied.
345 Hence we increase freg even when writing to memory. */
349 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
350 && TYPE_VECTOR (type
)
353 /* OpenCL vectors shorter than 16 bytes are passed as if
354 a series of independent scalars. */
355 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
356 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
358 for (i
= 0; i
< nelt
; i
++)
360 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
362 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
&& !tdep
->soft_float
)
368 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
369 gdb_byte regval
[MAX_REGISTER_SIZE
];
371 = register_type (gdbarch
, regnum
);
372 convert_typed_floating (elval
, eltype
,
374 regcache_cooked_write (regcache
, regnum
, regval
);
380 argoffset
= align_up (argoffset
, len
);
382 write_memory (sp
+ argoffset
, val
, len
);
386 else if (TYPE_LENGTH (eltype
) == 8)
390 /* Just in case GREG was 10. */
392 argoffset
= align_up (argoffset
, 8);
394 write_memory (sp
+ argoffset
, elval
,
395 TYPE_LENGTH (eltype
));
400 /* Must start on an odd register - r3/r4 etc. */
405 int regnum
= tdep
->ppc_gp0_regnum
+ greg
;
406 regcache_cooked_write (regcache
,
407 regnum
+ 0, elval
+ 0);
408 regcache_cooked_write (regcache
,
409 regnum
+ 1, elval
+ 4);
416 gdb_byte word
[MAX_REGISTER_SIZE
];
417 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
418 unpack_long (eltype
, elval
));
423 regcache_cooked_write (regcache
,
424 tdep
->ppc_gp0_regnum
+ greg
,
430 argoffset
= align_up (argoffset
, tdep
->wordsize
);
432 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
433 argoffset
+= tdep
->wordsize
;
439 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
440 && TYPE_VECTOR (type
)
443 /* OpenCL vectors 16 bytes or longer are passed as if
444 a series of AltiVec vectors. */
447 for (i
= 0; i
< len
/ 16; i
++)
449 const gdb_byte
*elval
= val
+ i
* 16;
454 regcache_cooked_write (regcache
,
455 tdep
->ppc_vr0_regnum
+ vreg
,
461 argoffset
= align_up (argoffset
, 16);
463 write_memory (sp
+ argoffset
, elval
, 16);
469 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
470 && TYPE_VECTOR (type
)
471 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
473 /* Vector parameter passed in an Altivec register, or
474 when that runs out, 16 byte aligned stack location. */
478 regcache_cooked_write (regcache
,
479 tdep
->ppc_vr0_regnum
+ vreg
, val
);
484 argoffset
= align_up (argoffset
, 16);
486 write_memory (sp
+ argoffset
, val
, 16);
491 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
492 && TYPE_VECTOR (type
)
493 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
495 /* Vector parameter passed in an e500 register, or when
496 that runs out, 8 byte aligned stack location. Note
497 that since e500 vector and general purpose registers
498 both map onto the same underlying register set, a
499 "greg" and not a "vreg" is consumed here. A cooked
500 write stores the value in the correct locations
501 within the raw register cache. */
505 regcache_cooked_write (regcache
,
506 tdep
->ppc_ev0_regnum
+ greg
, val
);
511 argoffset
= align_up (argoffset
, 8);
513 write_memory (sp
+ argoffset
, val
, 8);
519 /* Reduce the parameter down to something that fits in a
521 gdb_byte word
[MAX_REGISTER_SIZE
];
522 memset (word
, 0, MAX_REGISTER_SIZE
);
523 if (len
> tdep
->wordsize
524 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
525 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
527 /* Structs and large values are put in an
528 aligned stack slot ... */
529 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
530 && TYPE_VECTOR (type
)
532 structoffset
= align_up (structoffset
, 16);
534 structoffset
= align_up (structoffset
, 8);
537 write_memory (sp
+ structoffset
, val
, len
);
538 /* ... and then a "word" pointing to that address is
539 passed as the parameter. */
540 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
544 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
545 /* Sign or zero extend the "int" into a "word". */
546 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
547 unpack_long (type
, val
));
549 /* Always goes in the low address. */
550 memcpy (word
, val
, len
);
551 /* Store that "word" in a register, or on the stack.
552 The words have "4" byte alignment. */
556 regcache_cooked_write (regcache
,
557 tdep
->ppc_gp0_regnum
+ greg
, word
);
562 argoffset
= align_up (argoffset
, tdep
->wordsize
);
564 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
565 argoffset
+= tdep
->wordsize
;
570 /* Compute the actual stack space requirements. */
573 /* Remember the amount of space needed by the arguments. */
574 argspace
= argoffset
;
575 /* Allocate space for both the arguments and the structures. */
576 sp
-= (argoffset
+ structoffset
);
577 /* Ensure that the stack is still 16 byte aligned. */
578 sp
= align_down (sp
, 16);
581 /* The psABI says that "A caller of a function that takes a
582 variable argument list shall set condition register bit 6 to
583 1 if it passes one or more arguments in the floating-point
584 registers. It is strongly recommended that the caller set the
585 bit to 0 otherwise..." Doing this for normal functions too
591 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_cr_regnum
, &cr
);
596 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_cr_regnum
, cr
);
601 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
603 /* Write the backchain (it occupies WORDSIZED bytes). */
604 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, saved_sp
);
606 /* Point the inferior function call's return address at the dummy's
608 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
613 /* Handle the return-value conventions for Decimal Floating Point values
614 in both ppc32 and ppc64, which are the same. */
616 get_decimal_float_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
617 struct regcache
*regcache
, gdb_byte
*readbuf
,
618 const gdb_byte
*writebuf
)
620 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
622 gdb_assert (TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
);
624 /* 32-bit and 64-bit decimal floats in f1. */
625 if (TYPE_LENGTH (valtype
) <= 8)
627 if (writebuf
!= NULL
)
629 gdb_byte regval
[MAX_REGISTER_SIZE
];
632 /* 32-bit decimal float is right aligned in the doubleword. */
633 if (TYPE_LENGTH (valtype
) == 4)
635 memcpy (regval
+ 4, writebuf
, 4);
641 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, p
);
645 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, readbuf
);
647 /* Left align 32-bit decimal float. */
648 if (TYPE_LENGTH (valtype
) == 4)
649 memcpy (readbuf
, readbuf
+ 4, 4);
652 /* 128-bit decimal floats in f2,f3. */
653 else if (TYPE_LENGTH (valtype
) == 16)
655 if (writebuf
!= NULL
|| readbuf
!= NULL
)
659 for (i
= 0; i
< 2; i
++)
661 if (writebuf
!= NULL
)
662 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 2 + i
,
665 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 2 + i
,
672 internal_error (__FILE__
, __LINE__
, _("Unknown decimal float size."));
674 return RETURN_VALUE_REGISTER_CONVENTION
;
677 /* Handle the return-value conventions specified by the SysV 32-bit
678 PowerPC ABI (including all the supplements):
680 no floating-point: floating-point values returned using 32-bit
681 general-purpose registers.
683 Altivec: 128-bit vectors returned using vector registers.
685 e500: 64-bit vectors returned using the full full 64 bit EV
686 register, floating-point values returned using 32-bit
687 general-purpose registers.
689 GCC (broken): Small struct values right (instead of left) aligned
690 when returned in general-purpose registers. */
692 static enum return_value_convention
693 do_ppc_sysv_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
694 struct type
*type
, struct regcache
*regcache
,
695 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
698 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
699 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
700 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
702 gdb_assert (tdep
->wordsize
== 4);
704 if (TYPE_CODE (type
) == TYPE_CODE_FLT
705 && TYPE_LENGTH (type
) <= 8
706 && !tdep
->soft_float
)
710 /* Floats and doubles stored in "f1". Convert the value to
711 the required type. */
712 gdb_byte regval
[MAX_REGISTER_SIZE
];
713 struct type
*regtype
= register_type (gdbarch
,
714 tdep
->ppc_fp0_regnum
+ 1);
715 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
716 convert_typed_floating (regval
, regtype
, readbuf
, type
);
720 /* Floats and doubles stored in "f1". Convert the value to
721 the register's "double" type. */
722 gdb_byte regval
[MAX_REGISTER_SIZE
];
723 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
724 convert_typed_floating (writebuf
, type
, regval
, regtype
);
725 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
727 return RETURN_VALUE_REGISTER_CONVENTION
;
729 if (TYPE_CODE (type
) == TYPE_CODE_FLT
730 && TYPE_LENGTH (type
) == 16
732 && (gdbarch_long_double_format (gdbarch
)
733 == floatformats_ibm_long_double
))
735 /* IBM long double stored in f1 and f2. */
738 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, readbuf
);
739 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 2,
744 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, writebuf
);
745 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 2,
748 return RETURN_VALUE_REGISTER_CONVENTION
;
750 if (TYPE_LENGTH (type
) == 16
751 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
752 && (gdbarch_long_double_format (gdbarch
)
753 == floatformats_ibm_long_double
))
754 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& tdep
->soft_float
)))
756 /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
760 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, readbuf
);
761 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
763 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 5,
765 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 6,
770 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
771 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
773 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 5,
775 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 6,
778 return RETURN_VALUE_REGISTER_CONVENTION
;
780 if ((TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
781 || (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8)
782 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& TYPE_LENGTH (type
) == 8
783 && tdep
->soft_float
))
787 /* A long long, double or _Decimal64 stored in the 32 bit
789 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
791 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
796 /* A long long, double or _Decimal64 stored in the 32 bit
798 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
800 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
803 return RETURN_VALUE_REGISTER_CONVENTION
;
805 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& !tdep
->soft_float
)
806 return get_decimal_float_return_value (gdbarch
, type
, regcache
, readbuf
,
808 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
809 || TYPE_CODE (type
) == TYPE_CODE_CHAR
810 || TYPE_CODE (type
) == TYPE_CODE_BOOL
811 || TYPE_CODE (type
) == TYPE_CODE_PTR
812 || TYPE_CODE (type
) == TYPE_CODE_REF
813 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
814 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
818 /* Some sort of integer stored in r3. Since TYPE isn't
819 bigger than the register, sign extension isn't a problem
820 - just do everything unsigned. */
822 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
824 store_unsigned_integer (readbuf
, TYPE_LENGTH (type
), byte_order
,
829 /* Some sort of integer stored in r3. Use unpack_long since
830 that should handle any required sign extension. */
831 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
832 unpack_long (type
, writebuf
));
834 return RETURN_VALUE_REGISTER_CONVENTION
;
836 /* OpenCL vectors < 16 bytes are returned as distinct
837 scalars in f1..f2 or r3..r10. */
838 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
839 && TYPE_VECTOR (type
)
840 && TYPE_LENGTH (type
) < 16
843 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
844 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
846 for (i
= 0; i
< nelt
; i
++)
848 int offset
= i
* TYPE_LENGTH (eltype
);
850 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
852 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
853 gdb_byte regval
[MAX_REGISTER_SIZE
];
854 struct type
*regtype
= register_type (gdbarch
, regnum
);
856 if (writebuf
!= NULL
)
858 convert_typed_floating (writebuf
+ offset
, eltype
,
860 regcache_cooked_write (regcache
, regnum
, regval
);
864 regcache_cooked_read (regcache
, regnum
, regval
);
865 convert_typed_floating (regval
, regtype
,
866 readbuf
+ offset
, eltype
);
871 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
874 if (writebuf
!= NULL
)
876 regval
= unpack_long (eltype
, writebuf
+ offset
);
877 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
881 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
882 store_unsigned_integer (readbuf
+ offset
,
883 TYPE_LENGTH (eltype
), byte_order
,
889 return RETURN_VALUE_REGISTER_CONVENTION
;
891 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
892 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
893 && TYPE_VECTOR (type
)
894 && TYPE_LENGTH (type
) >= 16
897 int n_regs
= TYPE_LENGTH (type
) / 16;
900 for (i
= 0; i
< n_regs
; i
++)
903 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
905 if (writebuf
!= NULL
)
906 regcache_cooked_write (regcache
, regnum
, writebuf
+ offset
);
908 regcache_cooked_read (regcache
, regnum
, readbuf
+ offset
);
911 return RETURN_VALUE_REGISTER_CONVENTION
;
913 if (TYPE_LENGTH (type
) == 16
914 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
915 && TYPE_VECTOR (type
)
916 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
920 /* Altivec places the return value in "v2". */
921 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
925 /* Altivec places the return value in "v2". */
926 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, writebuf
);
928 return RETURN_VALUE_REGISTER_CONVENTION
;
930 if (TYPE_LENGTH (type
) == 16
931 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
932 && TYPE_VECTOR (type
)
933 && tdep
->vector_abi
== POWERPC_VEC_GENERIC
)
935 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
936 GCC without AltiVec returns them in memory, but it warns about
937 ABI risks in that case; we don't try to support it. */
940 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
942 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
944 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 5,
946 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 6,
951 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
953 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
955 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 5,
957 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 6,
960 return RETURN_VALUE_REGISTER_CONVENTION
;
962 if (TYPE_LENGTH (type
) == 8
963 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
964 && TYPE_VECTOR (type
)
965 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
967 /* The e500 ABI places return values for the 64-bit DSP types
968 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
969 corresponds to the entire r3 value for e500, whereas GDB's r3
970 only corresponds to the least significant 32-bits. So place
971 the 64-bit DSP type's value in ev3. */
973 regcache_cooked_read (regcache
, tdep
->ppc_ev0_regnum
+ 3, readbuf
);
975 regcache_cooked_write (regcache
, tdep
->ppc_ev0_regnum
+ 3, writebuf
);
976 return RETURN_VALUE_REGISTER_CONVENTION
;
978 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
980 /* GCC screwed up for structures or unions whose size is less
981 than or equal to 8 bytes.. Instead of left-aligning, it
982 right-aligns the data into the buffer formed by r3, r4. */
983 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
984 int len
= TYPE_LENGTH (type
);
985 int offset
= (2 * tdep
->wordsize
- len
) % tdep
->wordsize
;
989 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
990 regvals
+ 0 * tdep
->wordsize
);
991 if (len
> tdep
->wordsize
)
992 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
993 regvals
+ 1 * tdep
->wordsize
);
994 memcpy (readbuf
, regvals
+ offset
, len
);
998 memset (regvals
, 0, sizeof regvals
);
999 memcpy (regvals
+ offset
, writebuf
, len
);
1000 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1001 regvals
+ 0 * tdep
->wordsize
);
1002 if (len
> tdep
->wordsize
)
1003 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1004 regvals
+ 1 * tdep
->wordsize
);
1007 return RETURN_VALUE_REGISTER_CONVENTION
;
1009 if (TYPE_LENGTH (type
) <= 8)
1013 /* This matches SVr4 PPC, it does not match GCC. */
1014 /* The value is right-padded to 8 bytes and then loaded, as
1015 two "words", into r3/r4. */
1016 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
1017 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1018 regvals
+ 0 * tdep
->wordsize
);
1019 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1020 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1021 regvals
+ 1 * tdep
->wordsize
);
1022 memcpy (readbuf
, regvals
, TYPE_LENGTH (type
));
1026 /* This matches SVr4 PPC, it does not match GCC. */
1027 /* The value is padded out to 8 bytes and then loaded, as
1028 two "words" into r3/r4. */
1029 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
1030 memset (regvals
, 0, sizeof regvals
);
1031 memcpy (regvals
, writebuf
, TYPE_LENGTH (type
));
1032 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1033 regvals
+ 0 * tdep
->wordsize
);
1034 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1035 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1036 regvals
+ 1 * tdep
->wordsize
);
1038 return RETURN_VALUE_REGISTER_CONVENTION
;
1040 return RETURN_VALUE_STRUCT_CONVENTION
;
1043 enum return_value_convention
1044 ppc_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1045 struct type
*valtype
, struct regcache
*regcache
,
1046 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1048 return do_ppc_sysv_return_value (gdbarch
,
1049 function
? value_type (function
) : NULL
,
1050 valtype
, regcache
, readbuf
, writebuf
, 0);
1053 enum return_value_convention
1054 ppc_sysv_abi_broken_return_value (struct gdbarch
*gdbarch
,
1055 struct value
*function
,
1056 struct type
*valtype
,
1057 struct regcache
*regcache
,
1058 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1060 return do_ppc_sysv_return_value (gdbarch
,
1061 function
? value_type (function
) : NULL
,
1062 valtype
, regcache
, readbuf
, writebuf
, 1);
1065 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
1066 function's code address back into the function's descriptor
1069 Find a value for the TOC register. Every symbol should have both
1070 ".FN" and "FN" in the minimal symbol table. "FN" points at the
1071 FN's descriptor, while ".FN" points at the entry point (which
1072 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
1073 FN's descriptor address (while at the same time being careful to
1074 find "FN" in the same object file as ".FN"). */
1077 convert_code_addr_to_desc_addr (CORE_ADDR code_addr
, CORE_ADDR
*desc_addr
)
1079 struct obj_section
*dot_fn_section
;
1080 struct minimal_symbol
*dot_fn
;
1081 struct minimal_symbol
*fn
;
1083 /* Find the minimal symbol that corresponds to CODE_ADDR (should
1084 have a name of the form ".FN"). */
1085 dot_fn
= lookup_minimal_symbol_by_pc (code_addr
);
1086 if (dot_fn
== NULL
|| SYMBOL_LINKAGE_NAME (dot_fn
)[0] != '.')
1088 /* Get the section that contains CODE_ADDR. Need this for the
1089 "objfile" that it contains. */
1090 dot_fn_section
= find_pc_section (code_addr
);
1091 if (dot_fn_section
== NULL
|| dot_fn_section
->objfile
== NULL
)
1093 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
1094 address. Only look for the minimal symbol in ".FN"'s object file
1095 - avoids problems when two object files (i.e., shared libraries)
1096 contain a minimal symbol with the same name. */
1097 fn
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn
) + 1, NULL
,
1098 dot_fn_section
->objfile
);
1101 /* Found a descriptor. */
1102 (*desc_addr
) = SYMBOL_VALUE_ADDRESS (fn
);
1106 /* Pass the arguments in either registers, or in the stack. Using the
1107 ppc 64 bit SysV ABI.
1109 This implements a dumbed down version of the ABI. It always writes
1110 values to memory, GPR and FPR, even when not necessary. Doing this
1111 greatly simplifies the logic. */
1114 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
,
1115 struct value
*function
,
1116 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1117 int nargs
, struct value
**args
, CORE_ADDR sp
,
1118 int struct_return
, CORE_ADDR struct_addr
)
1120 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
1121 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1122 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1123 int opencl_abi
= ppc_sysv_use_opencl_abi (value_type (function
));
1124 ULONGEST back_chain
;
1125 /* See for-loop comment below. */
1127 /* Size of the by-reference parameter copy region, the final value is
1128 computed in the for-loop below. */
1129 LONGEST refparam_size
= 0;
1130 /* Size of the general parameter region, the final value is computed
1131 in the for-loop below. */
1132 LONGEST gparam_size
= 0;
1133 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
1134 calls to align_up(), align_down(), etc. because this makes it
1135 easier to reuse this code (in a copy/paste sense) in the future,
1136 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
1137 at some point makes it easier to verify that this function is
1138 correct without having to do a non-local analysis to figure out
1139 the possible values of tdep->wordsize. */
1140 gdb_assert (tdep
->wordsize
== 8);
1142 /* This function exists to support a calling convention that
1143 requires floating-point registers. It shouldn't be used on
1144 processors that lack them. */
1145 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1147 /* By this stage in the proceedings, SP has been decremented by "red
1148 zone size" + "struct return size". Fetch the stack-pointer from
1149 before this and use that as the BACK_CHAIN. */
1150 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
1153 /* Go through the argument list twice.
1155 Pass 1: Compute the function call's stack space and register
1158 Pass 2: Replay the same computation but this time also write the
1159 values out to the target. */
1161 for (write_pass
= 0; write_pass
< 2; write_pass
++)
1164 /* Next available floating point register for float and double
1167 /* Next available general register for non-vector (but possibly
1168 float) arguments. */
1170 /* Next available vector register for vector arguments. */
1172 /* The address, at which the next general purpose parameter
1173 (integer, struct, float, vector, ...) should be saved. */
1175 /* The address, at which the next by-reference parameter
1176 (non-Altivec vector, variably-sized type) should be saved. */
1181 /* During the first pass, GPARAM and REFPARAM are more like
1182 offsets (start address zero) than addresses. That way
1183 they accumulate the total stack space each region
1190 /* Decrement the stack pointer making space for the Altivec
1191 and general on-stack parameters. Set refparam and gparam
1192 to their corresponding regions. */
1193 refparam
= align_down (sp
- refparam_size
, 16);
1194 gparam
= align_down (refparam
- gparam_size
, 16);
1195 /* Add in space for the TOC, link editor double word,
1196 compiler double word, LR save area, CR save area. */
1197 sp
= align_down (gparam
- 48, 16);
1200 /* If the function is returning a `struct', then there is an
1201 extra hidden parameter (which will be passed in r3)
1202 containing the address of that struct.. In that case we
1203 should advance one word and start from r4 register to copy
1204 parameters. This also consumes one on-stack parameter slot. */
1208 regcache_cooked_write_signed (regcache
,
1209 tdep
->ppc_gp0_regnum
+ greg
,
1212 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
1215 for (argno
= 0; argno
< nargs
; argno
++)
1217 struct value
*arg
= args
[argno
];
1218 struct type
*type
= check_typedef (value_type (arg
));
1219 const bfd_byte
*val
= value_contents (arg
);
1221 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) <= 8)
1223 /* Floats and Doubles go in f1 .. f13. They also
1224 consume a left aligned GREG,, and can end up in
1228 gdb_byte regval
[MAX_REGISTER_SIZE
];
1231 /* Version 1.7 of the 64-bit PowerPC ELF ABI says:
1233 "Single precision floating point values are mapped to
1234 the first word in a single doubleword."
1236 And version 1.9 says:
1238 "Single precision floating point values are mapped to
1239 the second word in a single doubleword."
1241 GDB then writes single precision floating point values
1242 at both words in a doubleword, to support both ABIs. */
1243 if (TYPE_LENGTH (type
) == 4)
1245 memcpy (regval
, val
, 4);
1246 memcpy (regval
+ 4, val
, 4);
1252 /* Write value in the stack's parameter save area. */
1253 write_memory (gparam
, p
, 8);
1257 struct type
*regtype
1258 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
1260 convert_typed_floating (val
, type
, regval
, regtype
);
1261 regcache_cooked_write (regcache
,
1262 tdep
->ppc_fp0_regnum
+ freg
,
1266 regcache_cooked_write (regcache
,
1267 tdep
->ppc_gp0_regnum
+ greg
,
1273 /* Always consume parameter stack space. */
1274 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1276 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
1277 && TYPE_LENGTH (type
) == 16
1278 && (gdbarch_long_double_format (gdbarch
)
1279 == floatformats_ibm_long_double
))
1281 /* IBM long double stored in two doublewords of the
1282 parameter save area and corresponding registers. */
1285 if (!tdep
->soft_float
&& freg
<= 13)
1287 regcache_cooked_write (regcache
,
1288 tdep
->ppc_fp0_regnum
+ freg
,
1291 regcache_cooked_write (regcache
,
1292 tdep
->ppc_fp0_regnum
+ freg
+ 1,
1297 regcache_cooked_write (regcache
,
1298 tdep
->ppc_gp0_regnum
+ greg
,
1301 regcache_cooked_write (regcache
,
1302 tdep
->ppc_gp0_regnum
+ greg
+ 1,
1305 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1309 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1311 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
1312 && TYPE_LENGTH (type
) <= 8)
1314 /* 32-bit and 64-bit decimal floats go in f1 .. f13. They can
1315 end up in memory. */
1318 gdb_byte regval
[MAX_REGISTER_SIZE
];
1321 /* 32-bit decimal floats are right aligned in the
1323 if (TYPE_LENGTH (type
) == 4)
1325 memcpy (regval
+ 4, val
, 4);
1331 /* Write value in the stack's parameter save area. */
1332 write_memory (gparam
, p
, 8);
1335 regcache_cooked_write (regcache
,
1336 tdep
->ppc_fp0_regnum
+ freg
, p
);
1341 /* Always consume parameter stack space. */
1342 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1344 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&&
1345 TYPE_LENGTH (type
) == 16)
1347 /* 128-bit decimal floats go in f2 .. f12, always in even/odd
1348 pairs. They can end up in memory, using two doublewords. */
1353 /* Make sure freg is even. */
1355 regcache_cooked_write (regcache
,
1356 tdep
->ppc_fp0_regnum
+ freg
, val
);
1357 regcache_cooked_write (regcache
,
1358 tdep
->ppc_fp0_regnum
+ freg
+ 1, val
+ 8);
1361 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1366 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1368 else if (TYPE_LENGTH (type
) < 16
1369 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1370 && TYPE_VECTOR (type
)
1373 /* OpenCL vectors shorter than 16 bytes are passed as if
1374 a series of independent scalars. */
1375 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1376 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
1378 for (i
= 0; i
< nelt
; i
++)
1380 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1382 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
1386 gdb_byte regval
[MAX_REGISTER_SIZE
];
1389 if (TYPE_LENGTH (eltype
) == 4)
1391 memcpy (regval
, elval
, 4);
1392 memcpy (regval
+ 4, elval
, 4);
1398 write_memory (gparam
, p
, 8);
1402 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
1403 struct type
*regtype
1404 = register_type (gdbarch
, regnum
);
1406 convert_typed_floating (elval
, eltype
,
1408 regcache_cooked_write (regcache
, regnum
, regval
);
1412 regcache_cooked_write (regcache
,
1413 tdep
->ppc_gp0_regnum
+ greg
,
1419 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1425 ULONGEST word
= unpack_long (eltype
, elval
);
1427 regcache_cooked_write_unsigned
1428 (regcache
, tdep
->ppc_gp0_regnum
+ greg
, word
);
1430 write_memory_unsigned_integer
1431 (gparam
, tdep
->wordsize
, byte_order
, word
);
1435 gparam
= align_up (gparam
+ TYPE_LENGTH (eltype
),
1440 else if (TYPE_LENGTH (type
) >= 16
1441 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1442 && TYPE_VECTOR (type
)
1445 /* OpenCL vectors 16 bytes or longer are passed as if
1446 a series of AltiVec vectors. */
1449 for (i
= 0; i
< TYPE_LENGTH (type
) / 16; i
++)
1451 const gdb_byte
*elval
= val
+ i
* 16;
1453 gparam
= align_up (gparam
, 16);
1459 regcache_cooked_write (regcache
,
1460 tdep
->ppc_vr0_regnum
+ vreg
,
1463 write_memory (gparam
, elval
, 16);
1471 else if (TYPE_LENGTH (type
) == 16 && TYPE_VECTOR (type
)
1472 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1473 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1475 /* In the Altivec ABI, vectors go in the vector registers
1476 v2 .. v13, as well as the parameter area -- always at
1477 16-byte aligned addresses. */
1479 gparam
= align_up (gparam
, 16);
1485 regcache_cooked_write (regcache
,
1486 tdep
->ppc_vr0_regnum
+ vreg
, val
);
1488 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1495 else if (TYPE_LENGTH (type
) >= 16 && TYPE_VECTOR (type
)
1496 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1498 /* Non-Altivec vectors are passed by reference. */
1500 /* Copy value onto the stack ... */
1501 refparam
= align_up (refparam
, 16);
1503 write_memory (refparam
, val
, TYPE_LENGTH (type
));
1505 /* ... and pass a pointer to the copy as parameter. */
1509 regcache_cooked_write_unsigned (regcache
,
1510 tdep
->ppc_gp0_regnum
+
1512 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
1513 byte_order
, refparam
);
1516 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
1517 refparam
= align_up (refparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1519 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
1520 || TYPE_CODE (type
) == TYPE_CODE_ENUM
1521 || TYPE_CODE (type
) == TYPE_CODE_BOOL
1522 || TYPE_CODE (type
) == TYPE_CODE_CHAR
1523 || TYPE_CODE (type
) == TYPE_CODE_PTR
1524 || TYPE_CODE (type
) == TYPE_CODE_REF
)
1525 && TYPE_LENGTH (type
) <= 8)
1527 /* Scalars and Pointers get sign[un]extended and go in
1528 gpr3 .. gpr10. They can also end up in memory. */
1531 /* Sign extend the value, then store it unsigned. */
1532 ULONGEST word
= unpack_long (type
, val
);
1533 /* Convert any function code addresses into
1535 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1536 || TYPE_CODE (type
) == TYPE_CODE_REF
)
1538 struct type
*target_type
;
1539 target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1541 if (TYPE_CODE (target_type
) == TYPE_CODE_FUNC
1542 || TYPE_CODE (target_type
) == TYPE_CODE_METHOD
)
1544 CORE_ADDR desc
= word
;
1545 convert_code_addr_to_desc_addr (word
, &desc
);
1550 regcache_cooked_write_unsigned (regcache
,
1551 tdep
->ppc_gp0_regnum
+
1553 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
1557 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1562 for (byte
= 0; byte
< TYPE_LENGTH (type
);
1563 byte
+= tdep
->wordsize
)
1565 if (write_pass
&& greg
<= 10)
1567 gdb_byte regval
[MAX_REGISTER_SIZE
];
1568 int len
= TYPE_LENGTH (type
) - byte
;
1569 if (len
> tdep
->wordsize
)
1570 len
= tdep
->wordsize
;
1571 memset (regval
, 0, sizeof regval
);
1572 /* The ABI (version 1.9) specifies that values
1573 smaller than one doubleword are right-aligned
1574 and those larger are left-aligned. GCC
1575 versions before 3.4 implemented this
1577 <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */
1579 memcpy (regval
+ tdep
->wordsize
- len
,
1582 memcpy (regval
, val
+ byte
, len
);
1583 regcache_cooked_write (regcache
, greg
, regval
);
1589 /* WARNING: cagney/2003-09-21: Strictly speaking, this
1590 isn't necessary, unfortunately, GCC appears to get
1591 "struct convention" parameter passing wrong putting
1592 odd sized structures in memory instead of in a
1593 register. Work around this by always writing the
1594 value to memory. Fortunately, doing this
1595 simplifies the code. */
1596 int len
= TYPE_LENGTH (type
);
1597 if (len
< tdep
->wordsize
)
1598 write_memory (gparam
+ tdep
->wordsize
- len
, val
, len
);
1600 write_memory (gparam
, val
, len
);
1603 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
1604 && TYPE_NFIELDS (type
) == 1
1605 && TYPE_LENGTH (type
) <= 16)
1607 /* The ABI (version 1.9) specifies that structs
1608 containing a single floating-point value, at any
1609 level of nesting of single-member structs, are
1610 passed in floating-point registers. */
1611 while (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1612 && TYPE_NFIELDS (type
) == 1)
1613 type
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
1614 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1616 if (TYPE_LENGTH (type
) <= 8)
1620 gdb_byte regval
[MAX_REGISTER_SIZE
];
1621 struct type
*regtype
1622 = register_type (gdbarch
,
1623 tdep
->ppc_fp0_regnum
);
1624 convert_typed_floating (val
, type
, regval
,
1626 regcache_cooked_write (regcache
,
1627 (tdep
->ppc_fp0_regnum
1633 else if (TYPE_LENGTH (type
) == 16
1634 && (gdbarch_long_double_format (gdbarch
)
1635 == floatformats_ibm_long_double
))
1639 regcache_cooked_write (regcache
,
1640 (tdep
->ppc_fp0_regnum
1644 regcache_cooked_write (regcache
,
1645 (tdep
->ppc_fp0_regnum
1653 /* Always consume parameter stack space. */
1654 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1660 /* Save the true region sizes ready for the second pass. */
1661 refparam_size
= refparam
;
1662 /* Make certain that the general parameter save area is at
1663 least the minimum 8 registers (or doublewords) in size. */
1665 gparam_size
= 8 * tdep
->wordsize
;
1667 gparam_size
= gparam
;
1672 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
1674 /* Write the backchain (it occupies WORDSIZED bytes). */
1675 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, back_chain
);
1677 /* Point the inferior function call's return address at the dummy's
1679 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
1681 /* Use the func_addr to find the descriptor, and use that to find
1682 the TOC. If we're calling via a function pointer, the pointer
1683 itself identifies the descriptor. */
1685 struct type
*ftype
= check_typedef (value_type (function
));
1686 CORE_ADDR desc_addr
= value_as_address (function
);
1688 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
1689 || convert_code_addr_to_desc_addr (func_addr
, &desc_addr
))
1691 /* The TOC is the second double word in the descriptor. */
1693 read_memory_unsigned_integer (desc_addr
+ tdep
->wordsize
,
1694 tdep
->wordsize
, byte_order
);
1695 regcache_cooked_write_unsigned (regcache
,
1696 tdep
->ppc_gp0_regnum
+ 2, toc
);
1704 /* The 64 bit ABI return value convention.
1706 Return non-zero if the return-value is stored in a register, return
1707 0 if the return-value is instead stored on the stack (a.k.a.,
1708 struct return convention).
1710 For a return-value stored in a register: when WRITEBUF is non-NULL,
1711 copy the buffer to the corresponding register return-value location
1712 location; when READBUF is non-NULL, fill the buffer from the
1713 corresponding register return-value location. */
1714 enum return_value_convention
1715 ppc64_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1716 struct type
*valtype
, struct regcache
*regcache
,
1717 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1719 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1720 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1721 struct type
*func_type
= function
? value_type (function
) : NULL
;
1722 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
1724 /* This function exists to support a calling convention that
1725 requires floating-point registers. It shouldn't be used on
1726 processors that lack them. */
1727 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1729 /* Floats and doubles in F1. */
1730 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
&& TYPE_LENGTH (valtype
) <= 8)
1732 gdb_byte regval
[MAX_REGISTER_SIZE
];
1733 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
1734 if (writebuf
!= NULL
)
1736 convert_typed_floating (writebuf
, valtype
, regval
, regtype
);
1737 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
1739 if (readbuf
!= NULL
)
1741 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
1742 convert_typed_floating (regval
, regtype
, readbuf
, valtype
);
1744 return RETURN_VALUE_REGISTER_CONVENTION
;
1746 if (TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
)
1747 return get_decimal_float_return_value (gdbarch
, valtype
, regcache
, readbuf
,
1749 /* Integers in r3. */
1750 if ((TYPE_CODE (valtype
) == TYPE_CODE_INT
1751 || TYPE_CODE (valtype
) == TYPE_CODE_ENUM
1752 || TYPE_CODE (valtype
) == TYPE_CODE_CHAR
1753 || TYPE_CODE (valtype
) == TYPE_CODE_BOOL
)
1754 && TYPE_LENGTH (valtype
) <= 8)
1756 if (writebuf
!= NULL
)
1758 /* Be careful to sign extend the value. */
1759 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1760 unpack_long (valtype
, writebuf
));
1762 if (readbuf
!= NULL
)
1764 /* Extract the integer from r3. Since this is truncating the
1765 value, there isn't a sign extension problem. */
1767 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1769 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
), byte_order
,
1772 return RETURN_VALUE_REGISTER_CONVENTION
;
1774 /* All pointers live in r3. */
1775 if (TYPE_CODE (valtype
) == TYPE_CODE_PTR
1776 || TYPE_CODE (valtype
) == TYPE_CODE_REF
)
1778 /* All pointers live in r3. */
1779 if (writebuf
!= NULL
)
1780 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
1781 if (readbuf
!= NULL
)
1782 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, readbuf
);
1783 return RETURN_VALUE_REGISTER_CONVENTION
;
1785 /* OpenCL vectors < 16 bytes are returned as distinct
1786 scalars in f1..f2 or r3..r10. */
1787 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1788 && TYPE_VECTOR (valtype
)
1789 && TYPE_LENGTH (valtype
) < 16
1792 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1793 int i
, nelt
= TYPE_LENGTH (valtype
) / TYPE_LENGTH (eltype
);
1795 for (i
= 0; i
< nelt
; i
++)
1797 int offset
= i
* TYPE_LENGTH (eltype
);
1799 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
1801 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
1802 gdb_byte regval
[MAX_REGISTER_SIZE
];
1803 struct type
*regtype
= register_type (gdbarch
, regnum
);
1805 if (writebuf
!= NULL
)
1807 convert_typed_floating (writebuf
+ offset
, eltype
,
1809 regcache_cooked_write (regcache
, regnum
, regval
);
1811 if (readbuf
!= NULL
)
1813 regcache_cooked_read (regcache
, regnum
, regval
);
1814 convert_typed_floating (regval
, regtype
,
1815 readbuf
+ offset
, eltype
);
1820 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
1823 if (writebuf
!= NULL
)
1825 regval
= unpack_long (eltype
, writebuf
+ offset
);
1826 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
1828 if (readbuf
!= NULL
)
1830 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
1831 store_unsigned_integer (readbuf
+ offset
,
1832 TYPE_LENGTH (eltype
), byte_order
,
1838 return RETURN_VALUE_REGISTER_CONVENTION
;
1840 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
1841 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1842 && TYPE_VECTOR (valtype
)
1843 && TYPE_LENGTH (valtype
) >= 16
1846 int n_regs
= TYPE_LENGTH (valtype
) / 16;
1849 for (i
= 0; i
< n_regs
; i
++)
1851 int offset
= i
* 16;
1852 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
1854 if (writebuf
!= NULL
)
1855 regcache_cooked_write (regcache
, regnum
, writebuf
+ offset
);
1856 if (readbuf
!= NULL
)
1857 regcache_cooked_read (regcache
, regnum
, readbuf
+ offset
);
1860 return RETURN_VALUE_REGISTER_CONVENTION
;
1862 /* Array type has more than one use. */
1863 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
)
1865 /* Small character arrays are returned, right justified, in r3. */
1866 if (TYPE_LENGTH (valtype
) <= 8
1867 && TYPE_CODE (TYPE_TARGET_TYPE (valtype
)) == TYPE_CODE_INT
1868 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
1870 int offset
= (register_size (gdbarch
, tdep
->ppc_gp0_regnum
+ 3)
1871 - TYPE_LENGTH (valtype
));
1872 if (writebuf
!= NULL
)
1873 regcache_cooked_write_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1874 offset
, TYPE_LENGTH (valtype
), writebuf
);
1875 if (readbuf
!= NULL
)
1876 regcache_cooked_read_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1877 offset
, TYPE_LENGTH (valtype
), readbuf
);
1878 return RETURN_VALUE_REGISTER_CONVENTION
;
1880 /* A VMX vector is returned in v2. */
1881 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1882 && TYPE_VECTOR (valtype
)
1883 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1886 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
1888 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2,
1890 return RETURN_VALUE_REGISTER_CONVENTION
;
1893 /* Big floating point values get stored in adjacent floating
1894 point registers, starting with F1. */
1895 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
1896 && (TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 32))
1898 if (writebuf
|| readbuf
!= NULL
)
1901 for (i
= 0; i
< TYPE_LENGTH (valtype
) / 8; i
++)
1903 if (writebuf
!= NULL
)
1904 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1905 (const bfd_byte
*) writebuf
+ i
* 8);
1906 if (readbuf
!= NULL
)
1907 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1908 (bfd_byte
*) readbuf
+ i
* 8);
1911 return RETURN_VALUE_REGISTER_CONVENTION
;
1913 /* Complex values get returned in f1:f2, need to convert. */
1914 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
1915 && (TYPE_LENGTH (valtype
) == 8 || TYPE_LENGTH (valtype
) == 16))
1917 if (regcache
!= NULL
)
1920 for (i
= 0; i
< 2; i
++)
1922 gdb_byte regval
[MAX_REGISTER_SIZE
];
1923 struct type
*regtype
=
1924 register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
1925 if (writebuf
!= NULL
)
1927 convert_typed_floating ((const bfd_byte
*) writebuf
+
1928 i
* (TYPE_LENGTH (valtype
) / 2),
1929 valtype
, regval
, regtype
);
1930 regcache_cooked_write (regcache
,
1931 tdep
->ppc_fp0_regnum
+ 1 + i
,
1934 if (readbuf
!= NULL
)
1936 regcache_cooked_read (regcache
,
1937 tdep
->ppc_fp0_regnum
+ 1 + i
,
1939 convert_typed_floating (regval
, regtype
,
1940 (bfd_byte
*) readbuf
+
1941 i
* (TYPE_LENGTH (valtype
) / 2),
1946 return RETURN_VALUE_REGISTER_CONVENTION
;
1948 /* Big complex values get stored in f1:f4. */
1949 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
&& TYPE_LENGTH (valtype
) == 32)
1951 if (regcache
!= NULL
)
1954 for (i
= 0; i
< 4; i
++)
1956 if (writebuf
!= NULL
)
1957 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1958 (const bfd_byte
*) writebuf
+ i
* 8);
1959 if (readbuf
!= NULL
)
1960 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1961 (bfd_byte
*) readbuf
+ i
* 8);
1964 return RETURN_VALUE_REGISTER_CONVENTION
;
1966 return RETURN_VALUE_STRUCT_CONVENTION
;