1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright (C) 2000-2013 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/>. */
26 #include "gdb_string.h"
27 #include "gdb_assert.h"
35 /* Check whether FTPYE is a (pointer to) function type that should use
36 the OpenCL vector ABI. */
39 ppc_sysv_use_opencl_abi (struct type
*ftype
)
41 ftype
= check_typedef (ftype
);
43 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
)
44 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
46 return (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
47 && TYPE_CALLING_CONVENTION (ftype
) == DW_CC_GDB_IBM_OpenCL
);
50 /* Pass the arguments in either registers, or in the stack. Using the
51 ppc sysv ABI, the first eight words of the argument list (that might
52 be less than eight parameters if some parameters occupy more than one
53 word) are passed in r3..r10 registers. float and double parameters are
54 passed in fpr's, in addition to that. Rest of the parameters if any
55 are passed in user stack.
57 If the function is returning a structure, then the return address is passed
58 in r3, then the first 7 words of the parametes can be passed in registers,
62 ppc_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
63 struct regcache
*regcache
, CORE_ADDR bp_addr
,
64 int nargs
, struct value
**args
, CORE_ADDR sp
,
65 int struct_return
, CORE_ADDR struct_addr
)
67 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
68 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
69 int opencl_abi
= ppc_sysv_use_opencl_abi (value_type (function
));
71 int argspace
= 0; /* 0 is an initial wrong guess. */
74 gdb_assert (tdep
->wordsize
== 4);
76 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
79 /* Go through the argument list twice.
81 Pass 1: Figure out how much new stack space is required for
82 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
83 ABI doesn't reserve any extra space for parameters which are put
84 in registers, but does always push structures and then pass their
87 Pass 2: Replay the same computation but this time also write the
88 values out to the target. */
90 for (write_pass
= 0; write_pass
< 2; write_pass
++)
93 /* Next available floating point register for float and double
96 /* Next available general register for non-float, non-vector
99 /* Next available vector register for vector arguments. */
101 /* Arguments start above the "LR save word" and "Back chain". */
102 int argoffset
= 2 * tdep
->wordsize
;
103 /* Structures start after the arguments. */
104 int structoffset
= argoffset
+ argspace
;
106 /* If the function is returning a `struct', then the first word
107 (which will be passed in r3) is used for struct return
108 address. In that case we should advance one word and start
109 from r4 register to copy parameters. */
113 regcache_cooked_write_signed (regcache
,
114 tdep
->ppc_gp0_regnum
+ greg
,
119 for (argno
= 0; argno
< nargs
; argno
++)
121 struct value
*arg
= args
[argno
];
122 struct type
*type
= check_typedef (value_type (arg
));
123 int len
= TYPE_LENGTH (type
);
124 const bfd_byte
*val
= value_contents (arg
);
126 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& len
<= 8
127 && !tdep
->soft_float
)
129 /* Floating point value converted to "double" then
130 passed in an FP register, when the registers run out,
131 8 byte aligned stack is used. */
136 /* Always store the floating point value using
137 the register's floating-point format. */
138 gdb_byte regval
[MAX_REGISTER_SIZE
];
140 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
141 convert_typed_floating (val
, type
, regval
, regtype
);
142 regcache_cooked_write (regcache
,
143 tdep
->ppc_fp0_regnum
+ freg
,
150 /* The SysV ABI tells us to convert floats to
151 doubles before writing them to an 8 byte aligned
152 stack location. Unfortunately GCC does not do
153 that, and stores floats into 4 byte aligned
154 locations without converting them to doubles.
155 Since there is no know compiler that actually
156 follows the ABI here, we implement the GCC
159 /* Align to 4 bytes or 8 bytes depending on the type of
160 the argument (float or double). */
161 argoffset
= align_up (argoffset
, len
);
163 write_memory (sp
+ argoffset
, val
, len
);
167 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
170 && (gdbarch_long_double_format (gdbarch
)
171 == floatformats_ibm_long_double
))
173 /* IBM long double passed in two FP registers if
174 available, otherwise 8-byte aligned stack. */
179 regcache_cooked_write (regcache
,
180 tdep
->ppc_fp0_regnum
+ freg
,
182 regcache_cooked_write (regcache
,
183 tdep
->ppc_fp0_regnum
+ freg
+ 1,
190 argoffset
= align_up (argoffset
, 8);
192 write_memory (sp
+ argoffset
, val
, len
);
197 && (TYPE_CODE (type
) == TYPE_CODE_INT
/* long long */
198 || TYPE_CODE (type
) == TYPE_CODE_FLT
/* double */
199 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
200 && tdep
->soft_float
)))
202 /* "long long" or soft-float "double" or "_Decimal64"
203 passed in an odd/even register pair with the low
204 addressed word in the odd register and the high
205 addressed word in the even register, or when the
206 registers run out an 8 byte aligned stack
210 /* Just in case GREG was 10. */
212 argoffset
= align_up (argoffset
, 8);
214 write_memory (sp
+ argoffset
, val
, len
);
219 /* Must start on an odd register - r3/r4 etc. */
224 regcache_cooked_write (regcache
,
225 tdep
->ppc_gp0_regnum
+ greg
+ 0,
227 regcache_cooked_write (regcache
,
228 tdep
->ppc_gp0_regnum
+ greg
+ 1,
235 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
236 && (gdbarch_long_double_format (gdbarch
)
237 == floatformats_ibm_long_double
))
238 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
239 && tdep
->soft_float
)))
241 /* Soft-float IBM long double or _Decimal128 passed in
242 four consecutive registers, or on the stack. The
243 registers are not necessarily odd/even pairs. */
247 argoffset
= align_up (argoffset
, 8);
249 write_memory (sp
+ argoffset
, val
, len
);
256 regcache_cooked_write (regcache
,
257 tdep
->ppc_gp0_regnum
+ greg
+ 0,
259 regcache_cooked_write (regcache
,
260 tdep
->ppc_gp0_regnum
+ greg
+ 1,
262 regcache_cooked_write (regcache
,
263 tdep
->ppc_gp0_regnum
+ greg
+ 2,
265 regcache_cooked_write (regcache
,
266 tdep
->ppc_gp0_regnum
+ greg
+ 3,
272 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
<= 8
273 && !tdep
->soft_float
)
275 /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can
282 gdb_byte regval
[MAX_REGISTER_SIZE
];
285 /* 32-bit decimal floats are right aligned in the
287 if (TYPE_LENGTH (type
) == 4)
289 memcpy (regval
+ 4, val
, 4);
295 regcache_cooked_write (regcache
,
296 tdep
->ppc_fp0_regnum
+ freg
, p
);
303 argoffset
= align_up (argoffset
, len
);
306 /* Write value in the stack's parameter save area. */
307 write_memory (sp
+ argoffset
, val
, len
);
312 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
== 16
313 && !tdep
->soft_float
)
315 /* 128-bit decimal floats go in f2 .. f7, always in even/odd
316 pairs. They can end up in memory, using two doublewords. */
320 /* Make sure freg is even. */
325 regcache_cooked_write (regcache
,
326 tdep
->ppc_fp0_regnum
+ freg
, val
);
327 regcache_cooked_write (regcache
,
328 tdep
->ppc_fp0_regnum
+ freg
+ 1, val
+ 8);
333 argoffset
= align_up (argoffset
, 8);
336 write_memory (sp
+ argoffset
, val
, 16);
341 /* If a 128-bit decimal float goes to the stack because only f7
342 and f8 are free (thus there's no even/odd register pair
343 available), these registers should be marked as occupied.
344 Hence we increase freg even when writing to memory. */
348 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
349 && TYPE_VECTOR (type
)
352 /* OpenCL vectors shorter than 16 bytes are passed as if
353 a series of independent scalars. */
354 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
355 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
357 for (i
= 0; i
< nelt
; i
++)
359 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
361 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
&& !tdep
->soft_float
)
367 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
368 gdb_byte regval
[MAX_REGISTER_SIZE
];
370 = register_type (gdbarch
, regnum
);
371 convert_typed_floating (elval
, eltype
,
373 regcache_cooked_write (regcache
, regnum
, regval
);
379 argoffset
= align_up (argoffset
, len
);
381 write_memory (sp
+ argoffset
, val
, len
);
385 else if (TYPE_LENGTH (eltype
) == 8)
389 /* Just in case GREG was 10. */
391 argoffset
= align_up (argoffset
, 8);
393 write_memory (sp
+ argoffset
, elval
,
394 TYPE_LENGTH (eltype
));
399 /* Must start on an odd register - r3/r4 etc. */
404 int regnum
= tdep
->ppc_gp0_regnum
+ greg
;
405 regcache_cooked_write (regcache
,
406 regnum
+ 0, elval
+ 0);
407 regcache_cooked_write (regcache
,
408 regnum
+ 1, elval
+ 4);
415 gdb_byte word
[MAX_REGISTER_SIZE
];
416 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
417 unpack_long (eltype
, elval
));
422 regcache_cooked_write (regcache
,
423 tdep
->ppc_gp0_regnum
+ greg
,
429 argoffset
= align_up (argoffset
, tdep
->wordsize
);
431 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
432 argoffset
+= tdep
->wordsize
;
438 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
439 && TYPE_VECTOR (type
)
442 /* OpenCL vectors 16 bytes or longer are passed as if
443 a series of AltiVec vectors. */
446 for (i
= 0; i
< len
/ 16; i
++)
448 const gdb_byte
*elval
= val
+ i
* 16;
453 regcache_cooked_write (regcache
,
454 tdep
->ppc_vr0_regnum
+ vreg
,
460 argoffset
= align_up (argoffset
, 16);
462 write_memory (sp
+ argoffset
, elval
, 16);
468 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
469 && TYPE_VECTOR (type
)
470 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
472 /* Vector parameter passed in an Altivec register, or
473 when that runs out, 16 byte aligned stack location. */
477 regcache_cooked_write (regcache
,
478 tdep
->ppc_vr0_regnum
+ vreg
, val
);
483 argoffset
= align_up (argoffset
, 16);
485 write_memory (sp
+ argoffset
, val
, 16);
490 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
491 && TYPE_VECTOR (type
)
492 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
494 /* Vector parameter passed in an e500 register, or when
495 that runs out, 8 byte aligned stack location. Note
496 that since e500 vector and general purpose registers
497 both map onto the same underlying register set, a
498 "greg" and not a "vreg" is consumed here. A cooked
499 write stores the value in the correct locations
500 within the raw register cache. */
504 regcache_cooked_write (regcache
,
505 tdep
->ppc_ev0_regnum
+ greg
, val
);
510 argoffset
= align_up (argoffset
, 8);
512 write_memory (sp
+ argoffset
, val
, 8);
518 /* Reduce the parameter down to something that fits in a
520 gdb_byte word
[MAX_REGISTER_SIZE
];
521 memset (word
, 0, MAX_REGISTER_SIZE
);
522 if (len
> tdep
->wordsize
523 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
524 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
526 /* Structs and large values are put in an
527 aligned stack slot ... */
528 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
529 && TYPE_VECTOR (type
)
531 structoffset
= align_up (structoffset
, 16);
533 structoffset
= align_up (structoffset
, 8);
536 write_memory (sp
+ structoffset
, val
, len
);
537 /* ... and then a "word" pointing to that address is
538 passed as the parameter. */
539 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
543 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
544 /* Sign or zero extend the "int" into a "word". */
545 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
546 unpack_long (type
, val
));
548 /* Always goes in the low address. */
549 memcpy (word
, val
, len
);
550 /* Store that "word" in a register, or on the stack.
551 The words have "4" byte alignment. */
555 regcache_cooked_write (regcache
,
556 tdep
->ppc_gp0_regnum
+ greg
, word
);
561 argoffset
= align_up (argoffset
, tdep
->wordsize
);
563 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
564 argoffset
+= tdep
->wordsize
;
569 /* Compute the actual stack space requirements. */
572 /* Remember the amount of space needed by the arguments. */
573 argspace
= argoffset
;
574 /* Allocate space for both the arguments and the structures. */
575 sp
-= (argoffset
+ structoffset
);
576 /* Ensure that the stack is still 16 byte aligned. */
577 sp
= align_down (sp
, 16);
580 /* The psABI says that "A caller of a function that takes a
581 variable argument list shall set condition register bit 6 to
582 1 if it passes one or more arguments in the floating-point
583 registers. It is strongly recommended that the caller set the
584 bit to 0 otherwise..." Doing this for normal functions too
590 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_cr_regnum
, &cr
);
595 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_cr_regnum
, cr
);
600 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
602 /* Write the backchain (it occupies WORDSIZED bytes). */
603 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, saved_sp
);
605 /* Point the inferior function call's return address at the dummy's
607 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
612 /* Handle the return-value conventions for Decimal Floating Point values
613 in both ppc32 and ppc64, which are the same. */
615 get_decimal_float_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
616 struct regcache
*regcache
, gdb_byte
*readbuf
,
617 const gdb_byte
*writebuf
)
619 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
621 gdb_assert (TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
);
623 /* 32-bit and 64-bit decimal floats in f1. */
624 if (TYPE_LENGTH (valtype
) <= 8)
626 if (writebuf
!= NULL
)
628 gdb_byte regval
[MAX_REGISTER_SIZE
];
631 /* 32-bit decimal float is right aligned in the doubleword. */
632 if (TYPE_LENGTH (valtype
) == 4)
634 memcpy (regval
+ 4, writebuf
, 4);
640 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, p
);
644 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, readbuf
);
646 /* Left align 32-bit decimal float. */
647 if (TYPE_LENGTH (valtype
) == 4)
648 memcpy (readbuf
, readbuf
+ 4, 4);
651 /* 128-bit decimal floats in f2,f3. */
652 else if (TYPE_LENGTH (valtype
) == 16)
654 if (writebuf
!= NULL
|| readbuf
!= NULL
)
658 for (i
= 0; i
< 2; i
++)
660 if (writebuf
!= NULL
)
661 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 2 + i
,
664 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 2 + i
,
671 internal_error (__FILE__
, __LINE__
, _("Unknown decimal float size."));
673 return RETURN_VALUE_REGISTER_CONVENTION
;
676 /* Handle the return-value conventions specified by the SysV 32-bit
677 PowerPC ABI (including all the supplements):
679 no floating-point: floating-point values returned using 32-bit
680 general-purpose registers.
682 Altivec: 128-bit vectors returned using vector registers.
684 e500: 64-bit vectors returned using the full full 64 bit EV
685 register, floating-point values returned using 32-bit
686 general-purpose registers.
688 GCC (broken): Small struct values right (instead of left) aligned
689 when returned in general-purpose registers. */
691 static enum return_value_convention
692 do_ppc_sysv_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
693 struct type
*type
, struct regcache
*regcache
,
694 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
697 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
698 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
699 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
701 gdb_assert (tdep
->wordsize
== 4);
703 if (TYPE_CODE (type
) == TYPE_CODE_FLT
704 && TYPE_LENGTH (type
) <= 8
705 && !tdep
->soft_float
)
709 /* Floats and doubles stored in "f1". Convert the value to
710 the required type. */
711 gdb_byte regval
[MAX_REGISTER_SIZE
];
712 struct type
*regtype
= register_type (gdbarch
,
713 tdep
->ppc_fp0_regnum
+ 1);
714 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
715 convert_typed_floating (regval
, regtype
, readbuf
, type
);
719 /* Floats and doubles stored in "f1". Convert the value to
720 the register's "double" type. */
721 gdb_byte regval
[MAX_REGISTER_SIZE
];
722 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
723 convert_typed_floating (writebuf
, type
, regval
, regtype
);
724 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
726 return RETURN_VALUE_REGISTER_CONVENTION
;
728 if (TYPE_CODE (type
) == TYPE_CODE_FLT
729 && TYPE_LENGTH (type
) == 16
731 && (gdbarch_long_double_format (gdbarch
)
732 == floatformats_ibm_long_double
))
734 /* IBM long double stored in f1 and f2. */
737 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, readbuf
);
738 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 2,
743 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, writebuf
);
744 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 2,
747 return RETURN_VALUE_REGISTER_CONVENTION
;
749 if (TYPE_LENGTH (type
) == 16
750 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
751 && (gdbarch_long_double_format (gdbarch
)
752 == floatformats_ibm_long_double
))
753 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& tdep
->soft_float
)))
755 /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
759 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, readbuf
);
760 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
762 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 5,
764 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 6,
769 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
770 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
772 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 5,
774 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 6,
777 return RETURN_VALUE_REGISTER_CONVENTION
;
779 if ((TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
780 || (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8)
781 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& TYPE_LENGTH (type
) == 8
782 && tdep
->soft_float
))
786 /* A long long, double or _Decimal64 stored in the 32 bit
788 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
790 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
795 /* A long long, double or _Decimal64 stored in the 32 bit
797 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
799 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
802 return RETURN_VALUE_REGISTER_CONVENTION
;
804 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& !tdep
->soft_float
)
805 return get_decimal_float_return_value (gdbarch
, type
, regcache
, readbuf
,
807 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
808 || TYPE_CODE (type
) == TYPE_CODE_CHAR
809 || TYPE_CODE (type
) == TYPE_CODE_BOOL
810 || TYPE_CODE (type
) == TYPE_CODE_PTR
811 || TYPE_CODE (type
) == TYPE_CODE_REF
812 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
813 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
817 /* Some sort of integer stored in r3. Since TYPE isn't
818 bigger than the register, sign extension isn't a problem
819 - just do everything unsigned. */
821 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
823 store_unsigned_integer (readbuf
, TYPE_LENGTH (type
), byte_order
,
828 /* Some sort of integer stored in r3. Use unpack_long since
829 that should handle any required sign extension. */
830 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
831 unpack_long (type
, writebuf
));
833 return RETURN_VALUE_REGISTER_CONVENTION
;
835 /* OpenCL vectors < 16 bytes are returned as distinct
836 scalars in f1..f2 or r3..r10. */
837 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
838 && TYPE_VECTOR (type
)
839 && TYPE_LENGTH (type
) < 16
842 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
843 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
845 for (i
= 0; i
< nelt
; i
++)
847 int offset
= i
* TYPE_LENGTH (eltype
);
849 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
851 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
852 gdb_byte regval
[MAX_REGISTER_SIZE
];
853 struct type
*regtype
= register_type (gdbarch
, regnum
);
855 if (writebuf
!= NULL
)
857 convert_typed_floating (writebuf
+ offset
, eltype
,
859 regcache_cooked_write (regcache
, regnum
, regval
);
863 regcache_cooked_read (regcache
, regnum
, regval
);
864 convert_typed_floating (regval
, regtype
,
865 readbuf
+ offset
, eltype
);
870 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
873 if (writebuf
!= NULL
)
875 regval
= unpack_long (eltype
, writebuf
+ offset
);
876 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
880 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
881 store_unsigned_integer (readbuf
+ offset
,
882 TYPE_LENGTH (eltype
), byte_order
,
888 return RETURN_VALUE_REGISTER_CONVENTION
;
890 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
891 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
892 && TYPE_VECTOR (type
)
893 && TYPE_LENGTH (type
) >= 16
896 int n_regs
= TYPE_LENGTH (type
) / 16;
899 for (i
= 0; i
< n_regs
; i
++)
902 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
904 if (writebuf
!= NULL
)
905 regcache_cooked_write (regcache
, regnum
, writebuf
+ offset
);
907 regcache_cooked_read (regcache
, regnum
, readbuf
+ offset
);
910 return RETURN_VALUE_REGISTER_CONVENTION
;
912 if (TYPE_LENGTH (type
) == 16
913 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
914 && TYPE_VECTOR (type
)
915 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
919 /* Altivec places the return value in "v2". */
920 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
924 /* Altivec places the return value in "v2". */
925 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, writebuf
);
927 return RETURN_VALUE_REGISTER_CONVENTION
;
929 if (TYPE_LENGTH (type
) == 16
930 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
931 && TYPE_VECTOR (type
)
932 && tdep
->vector_abi
== POWERPC_VEC_GENERIC
)
934 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
935 GCC without AltiVec returns them in memory, but it warns about
936 ABI risks in that case; we don't try to support it. */
939 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
941 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
943 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 5,
945 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 6,
950 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
952 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
954 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 5,
956 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 6,
959 return RETURN_VALUE_REGISTER_CONVENTION
;
961 if (TYPE_LENGTH (type
) == 8
962 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
963 && TYPE_VECTOR (type
)
964 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
966 /* The e500 ABI places return values for the 64-bit DSP types
967 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
968 corresponds to the entire r3 value for e500, whereas GDB's r3
969 only corresponds to the least significant 32-bits. So place
970 the 64-bit DSP type's value in ev3. */
972 regcache_cooked_read (regcache
, tdep
->ppc_ev0_regnum
+ 3, readbuf
);
974 regcache_cooked_write (regcache
, tdep
->ppc_ev0_regnum
+ 3, writebuf
);
975 return RETURN_VALUE_REGISTER_CONVENTION
;
977 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
979 /* GCC screwed up for structures or unions whose size is less
980 than or equal to 8 bytes.. Instead of left-aligning, it
981 right-aligns the data into the buffer formed by r3, r4. */
982 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
983 int len
= TYPE_LENGTH (type
);
984 int offset
= (2 * tdep
->wordsize
- len
) % tdep
->wordsize
;
988 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
989 regvals
+ 0 * tdep
->wordsize
);
990 if (len
> tdep
->wordsize
)
991 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
992 regvals
+ 1 * tdep
->wordsize
);
993 memcpy (readbuf
, regvals
+ offset
, len
);
997 memset (regvals
, 0, sizeof regvals
);
998 memcpy (regvals
+ offset
, writebuf
, len
);
999 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1000 regvals
+ 0 * tdep
->wordsize
);
1001 if (len
> tdep
->wordsize
)
1002 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1003 regvals
+ 1 * tdep
->wordsize
);
1006 return RETURN_VALUE_REGISTER_CONVENTION
;
1008 if (TYPE_LENGTH (type
) <= 8)
1012 /* This matches SVr4 PPC, it does not match GCC. */
1013 /* The value is right-padded to 8 bytes and then loaded, as
1014 two "words", into r3/r4. */
1015 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
1016 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1017 regvals
+ 0 * tdep
->wordsize
);
1018 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1019 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1020 regvals
+ 1 * tdep
->wordsize
);
1021 memcpy (readbuf
, regvals
, TYPE_LENGTH (type
));
1025 /* This matches SVr4 PPC, it does not match GCC. */
1026 /* The value is padded out to 8 bytes and then loaded, as
1027 two "words" into r3/r4. */
1028 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
1029 memset (regvals
, 0, sizeof regvals
);
1030 memcpy (regvals
, writebuf
, TYPE_LENGTH (type
));
1031 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1032 regvals
+ 0 * tdep
->wordsize
);
1033 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1034 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1035 regvals
+ 1 * tdep
->wordsize
);
1037 return RETURN_VALUE_REGISTER_CONVENTION
;
1039 return RETURN_VALUE_STRUCT_CONVENTION
;
1042 enum return_value_convention
1043 ppc_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1044 struct type
*valtype
, struct regcache
*regcache
,
1045 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1047 return do_ppc_sysv_return_value (gdbarch
,
1048 function
? value_type (function
) : NULL
,
1049 valtype
, regcache
, readbuf
, writebuf
, 0);
1052 enum return_value_convention
1053 ppc_sysv_abi_broken_return_value (struct gdbarch
*gdbarch
,
1054 struct value
*function
,
1055 struct type
*valtype
,
1056 struct regcache
*regcache
,
1057 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1059 return do_ppc_sysv_return_value (gdbarch
,
1060 function
? value_type (function
) : NULL
,
1061 valtype
, regcache
, readbuf
, writebuf
, 1);
1064 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
1065 function's code address back into the function's descriptor
1068 Find a value for the TOC register. Every symbol should have both
1069 ".FN" and "FN" in the minimal symbol table. "FN" points at the
1070 FN's descriptor, while ".FN" points at the entry point (which
1071 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
1072 FN's descriptor address (while at the same time being careful to
1073 find "FN" in the same object file as ".FN"). */
1076 convert_code_addr_to_desc_addr (CORE_ADDR code_addr
, CORE_ADDR
*desc_addr
)
1078 struct obj_section
*dot_fn_section
;
1079 struct minimal_symbol
*dot_fn
;
1080 struct minimal_symbol
*fn
;
1081 /* Find the minimal symbol that corresponds to CODE_ADDR (should
1082 have a name of the form ".FN"). */
1083 dot_fn
= lookup_minimal_symbol_by_pc (code_addr
);
1084 if (dot_fn
== NULL
|| SYMBOL_LINKAGE_NAME (dot_fn
)[0] != '.')
1086 /* Get the section that contains CODE_ADDR. Need this for the
1087 "objfile" that it contains. */
1088 dot_fn_section
= find_pc_section (code_addr
);
1089 if (dot_fn_section
== NULL
|| dot_fn_section
->objfile
== NULL
)
1091 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
1092 address. Only look for the minimal symbol in ".FN"'s object file
1093 - avoids problems when two object files (i.e., shared libraries)
1094 contain a minimal symbol with the same name. */
1095 fn
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn
) + 1, NULL
,
1096 dot_fn_section
->objfile
);
1099 /* Found a descriptor. */
1100 (*desc_addr
) = SYMBOL_VALUE_ADDRESS (fn
);
1104 /* Push a float in either registers, or in the stack. Using the ppc 64 bit
1107 This implements a dumbed down version of the ABI. It always writes
1108 values to memory, GPR and FPR, even when not necessary. Doing this
1109 greatly simplifies the logic. */
1112 ppc64_sysv_abi_push_float (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1113 struct gdbarch_tdep
*tdep
, struct type
*type
,
1114 const bfd_byte
*val
, int freg
, int greg
,
1117 gdb_byte regval
[MAX_REGISTER_SIZE
];
1120 if (TYPE_LENGTH (type
) <= 8)
1122 /* Version 1.7 of the 64-bit PowerPC ELF ABI says:
1124 "Single precision floating point values are mapped to
1125 the first word in a single doubleword."
1127 And version 1.9 says:
1129 "Single precision floating point values are mapped to
1130 the second word in a single doubleword."
1132 GDB then writes single precision floating point values
1133 at both words in a doubleword, to support both ABIs. */
1134 if (TYPE_LENGTH (type
) == 4)
1136 memcpy (regval
, val
, 4);
1137 memcpy (regval
+ 4, val
, 4);
1143 /* Write value in the stack's parameter save area. */
1144 write_memory (gparam
, p
, 8);
1146 /* Floats and Doubles go in f1 .. f13. They also consume a left aligned
1147 GREG, and can end up in memory. */
1150 struct type
*regtype
;
1152 regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
1153 convert_typed_floating (val
, type
, regval
, regtype
);
1154 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ freg
, regval
);
1157 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ greg
, regval
);
1161 /* IBM long double stored in two doublewords of the
1162 parameter save area and corresponding registers. */
1163 if (!tdep
->soft_float
&& freg
<= 13)
1165 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ freg
, val
);
1167 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ freg
+ 1,
1172 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ greg
, val
);
1174 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ greg
+ 1,
1177 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1181 /* Pass the arguments in either registers, or in the stack. Using the
1182 ppc 64 bit SysV ABI.
1184 This implements a dumbed down version of the ABI. It always writes
1185 values to memory, GPR and FPR, even when not necessary. Doing this
1186 greatly simplifies the logic. */
1189 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
,
1190 struct value
*function
,
1191 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1192 int nargs
, struct value
**args
, CORE_ADDR sp
,
1193 int struct_return
, CORE_ADDR struct_addr
)
1195 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
1196 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1197 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1198 int opencl_abi
= ppc_sysv_use_opencl_abi (value_type (function
));
1199 ULONGEST back_chain
;
1200 /* See for-loop comment below. */
1202 /* Size of the by-reference parameter copy region, the final value is
1203 computed in the for-loop below. */
1204 LONGEST refparam_size
= 0;
1205 /* Size of the general parameter region, the final value is computed
1206 in the for-loop below. */
1207 LONGEST gparam_size
= 0;
1208 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
1209 calls to align_up(), align_down(), etc. because this makes it
1210 easier to reuse this code (in a copy/paste sense) in the future,
1211 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
1212 at some point makes it easier to verify that this function is
1213 correct without having to do a non-local analysis to figure out
1214 the possible values of tdep->wordsize. */
1215 gdb_assert (tdep
->wordsize
== 8);
1217 /* This function exists to support a calling convention that
1218 requires floating-point registers. It shouldn't be used on
1219 processors that lack them. */
1220 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1222 /* By this stage in the proceedings, SP has been decremented by "red
1223 zone size" + "struct return size". Fetch the stack-pointer from
1224 before this and use that as the BACK_CHAIN. */
1225 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
1228 /* Go through the argument list twice.
1230 Pass 1: Compute the function call's stack space and register
1233 Pass 2: Replay the same computation but this time also write the
1234 values out to the target. */
1236 for (write_pass
= 0; write_pass
< 2; write_pass
++)
1239 /* Next available floating point register for float and double
1242 /* Next available general register for non-vector (but possibly
1243 float) arguments. */
1245 /* Next available vector register for vector arguments. */
1247 /* The address, at which the next general purpose parameter
1248 (integer, struct, float, vector, ...) should be saved. */
1250 /* The address, at which the next by-reference parameter
1251 (non-Altivec vector, variably-sized type) should be saved. */
1256 /* During the first pass, GPARAM and REFPARAM are more like
1257 offsets (start address zero) than addresses. That way
1258 they accumulate the total stack space each region
1265 /* Decrement the stack pointer making space for the Altivec
1266 and general on-stack parameters. Set refparam and gparam
1267 to their corresponding regions. */
1268 refparam
= align_down (sp
- refparam_size
, 16);
1269 gparam
= align_down (refparam
- gparam_size
, 16);
1270 /* Add in space for the TOC, link editor double word,
1271 compiler double word, LR save area, CR save area. */
1272 sp
= align_down (gparam
- 48, 16);
1275 /* If the function is returning a `struct', then there is an
1276 extra hidden parameter (which will be passed in r3)
1277 containing the address of that struct.. In that case we
1278 should advance one word and start from r4 register to copy
1279 parameters. This also consumes one on-stack parameter slot. */
1283 regcache_cooked_write_signed (regcache
,
1284 tdep
->ppc_gp0_regnum
+ greg
,
1287 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
1290 for (argno
= 0; argno
< nargs
; argno
++)
1292 struct value
*arg
= args
[argno
];
1293 struct type
*type
= check_typedef (value_type (arg
));
1294 const bfd_byte
*val
= value_contents (arg
);
1296 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) <= 8)
1299 ppc64_sysv_abi_push_float (gdbarch
, regcache
, tdep
, type
,
1300 val
, freg
, greg
, gparam
);
1304 /* Always consume parameter stack space. */
1305 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1307 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
1308 && TYPE_LENGTH (type
) == 16
1309 && (gdbarch_long_double_format (gdbarch
)
1310 == floatformats_ibm_long_double
))
1313 ppc64_sysv_abi_push_float (gdbarch
, regcache
, tdep
, type
,
1314 val
, freg
, greg
, gparam
);
1317 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1319 else if (TYPE_CODE (type
) == TYPE_CODE_COMPLEX
1320 && (TYPE_LENGTH (type
) == 8 || TYPE_LENGTH (type
) == 16))
1324 for (i
= 0; i
< 2; i
++)
1328 struct type
*target_type
;
1330 target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1331 ppc64_sysv_abi_push_float (gdbarch
, regcache
, tdep
,
1332 target_type
, val
+ i
*
1333 TYPE_LENGTH (target_type
),
1334 freg
, greg
, gparam
);
1338 /* Always consume parameter stack space. */
1339 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1342 else if (TYPE_CODE (type
) == TYPE_CODE_COMPLEX
1343 && TYPE_LENGTH (type
) == 32
1344 && (gdbarch_long_double_format (gdbarch
)
1345 == floatformats_ibm_long_double
))
1349 for (i
= 0; i
< 2; i
++)
1351 struct type
*target_type
;
1353 target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1355 ppc64_sysv_abi_push_float (gdbarch
, regcache
, tdep
,
1356 target_type
, val
+ i
*
1357 TYPE_LENGTH (target_type
),
1358 freg
, greg
, gparam
);
1361 gparam
= align_up (gparam
+ TYPE_LENGTH (target_type
),
1365 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
1366 && TYPE_LENGTH (type
) <= 8)
1368 /* 32-bit and 64-bit decimal floats go in f1 .. f13. They can
1369 end up in memory. */
1372 gdb_byte regval
[MAX_REGISTER_SIZE
];
1375 /* 32-bit decimal floats are right aligned in the
1377 if (TYPE_LENGTH (type
) == 4)
1379 memcpy (regval
+ 4, val
, 4);
1385 /* Write value in the stack's parameter save area. */
1386 write_memory (gparam
, p
, 8);
1389 regcache_cooked_write (regcache
,
1390 tdep
->ppc_fp0_regnum
+ freg
, p
);
1395 /* Always consume parameter stack space. */
1396 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1398 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&&
1399 TYPE_LENGTH (type
) == 16)
1401 /* 128-bit decimal floats go in f2 .. f12, always in even/odd
1402 pairs. They can end up in memory, using two doublewords. */
1407 /* Make sure freg is even. */
1409 regcache_cooked_write (regcache
,
1410 tdep
->ppc_fp0_regnum
+ freg
, val
);
1411 regcache_cooked_write (regcache
,
1412 tdep
->ppc_fp0_regnum
+ freg
+ 1, val
+ 8);
1415 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1420 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1422 else if (TYPE_LENGTH (type
) < 16
1423 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1424 && TYPE_VECTOR (type
)
1427 /* OpenCL vectors shorter than 16 bytes are passed as if
1428 a series of independent scalars. */
1429 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1430 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
1432 for (i
= 0; i
< nelt
; i
++)
1434 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1436 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
1440 gdb_byte regval
[MAX_REGISTER_SIZE
];
1443 if (TYPE_LENGTH (eltype
) == 4)
1445 memcpy (regval
, elval
, 4);
1446 memcpy (regval
+ 4, elval
, 4);
1452 write_memory (gparam
, p
, 8);
1456 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
1457 struct type
*regtype
1458 = register_type (gdbarch
, regnum
);
1460 convert_typed_floating (elval
, eltype
,
1462 regcache_cooked_write (regcache
, regnum
, regval
);
1466 regcache_cooked_write (regcache
,
1467 tdep
->ppc_gp0_regnum
+ greg
,
1473 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1479 ULONGEST word
= unpack_long (eltype
, elval
);
1481 regcache_cooked_write_unsigned
1482 (regcache
, tdep
->ppc_gp0_regnum
+ greg
, word
);
1484 write_memory_unsigned_integer
1485 (gparam
, tdep
->wordsize
, byte_order
, word
);
1489 gparam
= align_up (gparam
+ TYPE_LENGTH (eltype
),
1494 else if (TYPE_LENGTH (type
) >= 16
1495 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1496 && TYPE_VECTOR (type
)
1499 /* OpenCL vectors 16 bytes or longer are passed as if
1500 a series of AltiVec vectors. */
1503 for (i
= 0; i
< TYPE_LENGTH (type
) / 16; i
++)
1505 const gdb_byte
*elval
= val
+ i
* 16;
1507 gparam
= align_up (gparam
, 16);
1513 regcache_cooked_write (regcache
,
1514 tdep
->ppc_vr0_regnum
+ vreg
,
1517 write_memory (gparam
, elval
, 16);
1525 else if (TYPE_LENGTH (type
) == 16 && TYPE_VECTOR (type
)
1526 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1527 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1529 /* In the Altivec ABI, vectors go in the vector registers
1530 v2 .. v13, as well as the parameter area -- always at
1531 16-byte aligned addresses. */
1533 gparam
= align_up (gparam
, 16);
1539 regcache_cooked_write (regcache
,
1540 tdep
->ppc_vr0_regnum
+ vreg
, val
);
1542 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1549 else if (TYPE_LENGTH (type
) >= 16 && TYPE_VECTOR (type
)
1550 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1552 /* Non-Altivec vectors are passed by reference. */
1554 /* Copy value onto the stack ... */
1555 refparam
= align_up (refparam
, 16);
1557 write_memory (refparam
, val
, TYPE_LENGTH (type
));
1559 /* ... and pass a pointer to the copy as parameter. */
1563 regcache_cooked_write_unsigned (regcache
,
1564 tdep
->ppc_gp0_regnum
+
1566 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
1567 byte_order
, refparam
);
1570 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
1571 refparam
= align_up (refparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1573 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
1574 || TYPE_CODE (type
) == TYPE_CODE_ENUM
1575 || TYPE_CODE (type
) == TYPE_CODE_BOOL
1576 || TYPE_CODE (type
) == TYPE_CODE_CHAR
1577 || TYPE_CODE (type
) == TYPE_CODE_PTR
1578 || TYPE_CODE (type
) == TYPE_CODE_REF
)
1579 && TYPE_LENGTH (type
) <= 8)
1581 /* Scalars and Pointers get sign[un]extended and go in
1582 gpr3 .. gpr10. They can also end up in memory. */
1585 /* Sign extend the value, then store it unsigned. */
1586 ULONGEST word
= unpack_long (type
, val
);
1587 /* Convert any function code addresses into
1589 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1590 || TYPE_CODE (type
) == TYPE_CODE_REF
)
1592 struct type
*target_type
;
1593 target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1595 if (TYPE_CODE (target_type
) == TYPE_CODE_FUNC
1596 || TYPE_CODE (target_type
) == TYPE_CODE_METHOD
)
1598 CORE_ADDR desc
= word
;
1599 convert_code_addr_to_desc_addr (word
, &desc
);
1604 regcache_cooked_write_unsigned (regcache
,
1605 tdep
->ppc_gp0_regnum
+
1607 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
1611 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1616 for (byte
= 0; byte
< TYPE_LENGTH (type
);
1617 byte
+= tdep
->wordsize
)
1619 if (write_pass
&& greg
<= 10)
1621 gdb_byte regval
[MAX_REGISTER_SIZE
];
1622 int len
= TYPE_LENGTH (type
) - byte
;
1623 if (len
> tdep
->wordsize
)
1624 len
= tdep
->wordsize
;
1625 memset (regval
, 0, sizeof regval
);
1626 /* The ABI (version 1.9) specifies that values
1627 smaller than one doubleword are right-aligned
1628 and those larger are left-aligned. GCC
1629 versions before 3.4 implemented this
1631 <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */
1633 memcpy (regval
+ tdep
->wordsize
- len
,
1636 memcpy (regval
, val
+ byte
, len
);
1637 regcache_cooked_write (regcache
, greg
, regval
);
1643 /* WARNING: cagney/2003-09-21: Strictly speaking, this
1644 isn't necessary, unfortunately, GCC appears to get
1645 "struct convention" parameter passing wrong putting
1646 odd sized structures in memory instead of in a
1647 register. Work around this by always writing the
1648 value to memory. Fortunately, doing this
1649 simplifies the code. */
1650 int len
= TYPE_LENGTH (type
);
1651 if (len
< tdep
->wordsize
)
1652 write_memory (gparam
+ tdep
->wordsize
- len
, val
, len
);
1654 write_memory (gparam
, val
, len
);
1657 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
1658 && TYPE_NFIELDS (type
) == 1
1659 && TYPE_LENGTH (type
) <= 16)
1661 /* The ABI (version 1.9) specifies that structs
1662 containing a single floating-point value, at any
1663 level of nesting of single-member structs, are
1664 passed in floating-point registers. */
1665 while (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1666 && TYPE_NFIELDS (type
) == 1)
1667 type
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
1668 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1670 if (TYPE_LENGTH (type
) <= 8)
1674 gdb_byte regval
[MAX_REGISTER_SIZE
];
1675 struct type
*regtype
1676 = register_type (gdbarch
,
1677 tdep
->ppc_fp0_regnum
);
1678 convert_typed_floating (val
, type
, regval
,
1680 regcache_cooked_write (regcache
,
1681 (tdep
->ppc_fp0_regnum
1687 else if (TYPE_LENGTH (type
) == 16
1688 && (gdbarch_long_double_format (gdbarch
)
1689 == floatformats_ibm_long_double
))
1693 regcache_cooked_write (regcache
,
1694 (tdep
->ppc_fp0_regnum
1698 regcache_cooked_write (regcache
,
1699 (tdep
->ppc_fp0_regnum
1707 /* Always consume parameter stack space. */
1708 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1714 /* Save the true region sizes ready for the second pass. */
1715 refparam_size
= refparam
;
1716 /* Make certain that the general parameter save area is at
1717 least the minimum 8 registers (or doublewords) in size. */
1719 gparam_size
= 8 * tdep
->wordsize
;
1721 gparam_size
= gparam
;
1726 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
1728 /* Write the backchain (it occupies WORDSIZED bytes). */
1729 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, back_chain
);
1731 /* Point the inferior function call's return address at the dummy's
1733 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
1735 /* Use the func_addr to find the descriptor, and use that to find
1736 the TOC. If we're calling via a function pointer, the pointer
1737 itself identifies the descriptor. */
1739 struct type
*ftype
= check_typedef (value_type (function
));
1740 CORE_ADDR desc_addr
= value_as_address (function
);
1742 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
1743 || convert_code_addr_to_desc_addr (func_addr
, &desc_addr
))
1745 /* The TOC is the second double word in the descriptor. */
1747 read_memory_unsigned_integer (desc_addr
+ tdep
->wordsize
,
1748 tdep
->wordsize
, byte_order
);
1749 regcache_cooked_write_unsigned (regcache
,
1750 tdep
->ppc_gp0_regnum
+ 2, toc
);
1758 /* The 64 bit ABI return value convention.
1760 Return non-zero if the return-value is stored in a register, return
1761 0 if the return-value is instead stored on the stack (a.k.a.,
1762 struct return convention).
1764 For a return-value stored in a register: when WRITEBUF is non-NULL,
1765 copy the buffer to the corresponding register return-value location
1766 location; when READBUF is non-NULL, fill the buffer from the
1767 corresponding register return-value location. */
1768 enum return_value_convention
1769 ppc64_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1770 struct type
*valtype
, struct regcache
*regcache
,
1771 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1773 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1774 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1775 struct type
*func_type
= function
? value_type (function
) : NULL
;
1776 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
1778 /* This function exists to support a calling convention that
1779 requires floating-point registers. It shouldn't be used on
1780 processors that lack them. */
1781 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1783 /* Floats and doubles in F1. */
1784 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
&& TYPE_LENGTH (valtype
) <= 8)
1786 gdb_byte regval
[MAX_REGISTER_SIZE
];
1787 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
1788 if (writebuf
!= NULL
)
1790 convert_typed_floating (writebuf
, valtype
, regval
, regtype
);
1791 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
1793 if (readbuf
!= NULL
)
1795 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
1796 convert_typed_floating (regval
, regtype
, readbuf
, valtype
);
1798 return RETURN_VALUE_REGISTER_CONVENTION
;
1800 if (TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
)
1801 return get_decimal_float_return_value (gdbarch
, valtype
, regcache
, readbuf
,
1803 /* Integers in r3. */
1804 if ((TYPE_CODE (valtype
) == TYPE_CODE_INT
1805 || TYPE_CODE (valtype
) == TYPE_CODE_ENUM
1806 || TYPE_CODE (valtype
) == TYPE_CODE_CHAR
1807 || TYPE_CODE (valtype
) == TYPE_CODE_BOOL
)
1808 && TYPE_LENGTH (valtype
) <= 8)
1810 if (writebuf
!= NULL
)
1812 /* Be careful to sign extend the value. */
1813 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1814 unpack_long (valtype
, writebuf
));
1816 if (readbuf
!= NULL
)
1818 /* Extract the integer from r3. Since this is truncating the
1819 value, there isn't a sign extension problem. */
1821 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1823 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
), byte_order
,
1826 return RETURN_VALUE_REGISTER_CONVENTION
;
1828 /* All pointers live in r3. */
1829 if (TYPE_CODE (valtype
) == TYPE_CODE_PTR
1830 || TYPE_CODE (valtype
) == TYPE_CODE_REF
)
1832 /* All pointers live in r3. */
1833 if (writebuf
!= NULL
)
1834 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
1835 if (readbuf
!= NULL
)
1836 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, readbuf
);
1837 return RETURN_VALUE_REGISTER_CONVENTION
;
1839 /* OpenCL vectors < 16 bytes are returned as distinct
1840 scalars in f1..f2 or r3..r10. */
1841 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1842 && TYPE_VECTOR (valtype
)
1843 && TYPE_LENGTH (valtype
) < 16
1846 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1847 int i
, nelt
= TYPE_LENGTH (valtype
) / TYPE_LENGTH (eltype
);
1849 for (i
= 0; i
< nelt
; i
++)
1851 int offset
= i
* TYPE_LENGTH (eltype
);
1853 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
1855 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
1856 gdb_byte regval
[MAX_REGISTER_SIZE
];
1857 struct type
*regtype
= register_type (gdbarch
, regnum
);
1859 if (writebuf
!= NULL
)
1861 convert_typed_floating (writebuf
+ offset
, eltype
,
1863 regcache_cooked_write (regcache
, regnum
, regval
);
1865 if (readbuf
!= NULL
)
1867 regcache_cooked_read (regcache
, regnum
, regval
);
1868 convert_typed_floating (regval
, regtype
,
1869 readbuf
+ offset
, eltype
);
1874 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
1877 if (writebuf
!= NULL
)
1879 regval
= unpack_long (eltype
, writebuf
+ offset
);
1880 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
1882 if (readbuf
!= NULL
)
1884 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
1885 store_unsigned_integer (readbuf
+ offset
,
1886 TYPE_LENGTH (eltype
), byte_order
,
1892 return RETURN_VALUE_REGISTER_CONVENTION
;
1894 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
1895 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1896 && TYPE_VECTOR (valtype
)
1897 && TYPE_LENGTH (valtype
) >= 16
1900 int n_regs
= TYPE_LENGTH (valtype
) / 16;
1903 for (i
= 0; i
< n_regs
; i
++)
1905 int offset
= i
* 16;
1906 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
1908 if (writebuf
!= NULL
)
1909 regcache_cooked_write (regcache
, regnum
, writebuf
+ offset
);
1910 if (readbuf
!= NULL
)
1911 regcache_cooked_read (regcache
, regnum
, readbuf
+ offset
);
1914 return RETURN_VALUE_REGISTER_CONVENTION
;
1916 /* Array type has more than one use. */
1917 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
)
1919 /* Small character arrays are returned, right justified, in r3. */
1920 if (TYPE_LENGTH (valtype
) <= 8
1921 && TYPE_CODE (TYPE_TARGET_TYPE (valtype
)) == TYPE_CODE_INT
1922 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
1924 int offset
= (register_size (gdbarch
, tdep
->ppc_gp0_regnum
+ 3)
1925 - TYPE_LENGTH (valtype
));
1926 if (writebuf
!= NULL
)
1927 regcache_cooked_write_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1928 offset
, TYPE_LENGTH (valtype
), writebuf
);
1929 if (readbuf
!= NULL
)
1930 regcache_cooked_read_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1931 offset
, TYPE_LENGTH (valtype
), readbuf
);
1932 return RETURN_VALUE_REGISTER_CONVENTION
;
1934 /* A VMX vector is returned in v2. */
1935 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1936 && TYPE_VECTOR (valtype
)
1937 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1940 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
1942 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2,
1944 return RETURN_VALUE_REGISTER_CONVENTION
;
1947 /* Big floating point values get stored in adjacent floating
1948 point registers, starting with F1. */
1949 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
1950 && (TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 32))
1952 if (writebuf
|| readbuf
!= NULL
)
1955 for (i
= 0; i
< TYPE_LENGTH (valtype
) / 8; i
++)
1957 if (writebuf
!= NULL
)
1958 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1959 (const bfd_byte
*) writebuf
+ i
* 8);
1960 if (readbuf
!= NULL
)
1961 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1962 (bfd_byte
*) readbuf
+ i
* 8);
1965 return RETURN_VALUE_REGISTER_CONVENTION
;
1967 /* Complex values get returned in f1:f2, need to convert. */
1968 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
1969 && (TYPE_LENGTH (valtype
) == 8 || TYPE_LENGTH (valtype
) == 16))
1971 if (regcache
!= NULL
)
1974 for (i
= 0; i
< 2; i
++)
1976 gdb_byte regval
[MAX_REGISTER_SIZE
];
1977 struct type
*regtype
=
1978 register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
1979 struct type
*target_type
;
1980 target_type
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1981 if (writebuf
!= NULL
)
1983 convert_typed_floating ((const bfd_byte
*) writebuf
+
1984 i
* TYPE_LENGTH (target_type
),
1985 target_type
, regval
, regtype
);
1986 regcache_cooked_write (regcache
,
1987 tdep
->ppc_fp0_regnum
+ 1 + i
,
1990 if (readbuf
!= NULL
)
1992 regcache_cooked_read (regcache
,
1993 tdep
->ppc_fp0_regnum
+ 1 + i
,
1995 convert_typed_floating (regval
, regtype
,
1996 (bfd_byte
*) readbuf
+
1997 i
* TYPE_LENGTH (target_type
),
2002 return RETURN_VALUE_REGISTER_CONVENTION
;
2004 /* Big complex values get stored in f1:f4. */
2005 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
&& TYPE_LENGTH (valtype
) == 32)
2007 if (regcache
!= NULL
)
2010 for (i
= 0; i
< 4; i
++)
2012 if (writebuf
!= NULL
)
2013 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
2014 (const bfd_byte
*) writebuf
+ i
* 8);
2015 if (readbuf
!= NULL
)
2016 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
2017 (bfd_byte
*) readbuf
+ i
* 8);
2020 return RETURN_VALUE_REGISTER_CONVENTION
;
2022 return RETURN_VALUE_STRUCT_CONVENTION
;