1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright (C) 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
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"
35 /* Pass the arguments in either registers, or in the stack. Using the
36 ppc sysv ABI, the first eight words of the argument list (that might
37 be less than eight parameters if some parameters occupy more than one
38 word) are passed in r3..r10 registers. float and double parameters are
39 passed in fpr's, in addition to that. Rest of the parameters if any
40 are passed in user stack.
42 If the function is returning a structure, then the return address is passed
43 in r3, then the first 7 words of the parametes can be passed in registers,
47 ppc_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
48 struct regcache
*regcache
, CORE_ADDR bp_addr
,
49 int nargs
, struct value
**args
, CORE_ADDR sp
,
50 int struct_return
, CORE_ADDR struct_addr
)
52 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
53 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
57 int argspace
= 0; /* 0 is an initial wrong guess. */
60 gdb_assert (tdep
->wordsize
== 4);
62 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
65 ftype
= check_typedef (value_type (function
));
66 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
)
67 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
68 if (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
69 && TYPE_CALLING_CONVENTION (ftype
) == DW_CC_GDB_IBM_OpenCL
)
72 /* Go through the argument list twice.
74 Pass 1: Figure out how much new stack space is required for
75 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
76 ABI doesn't reserve any extra space for parameters which are put
77 in registers, but does always push structures and then pass their
80 Pass 2: Replay the same computation but this time also write the
81 values out to the target. */
83 for (write_pass
= 0; write_pass
< 2; write_pass
++)
86 /* Next available floating point register for float and double
89 /* Next available general register for non-float, non-vector
92 /* Next available vector register for vector arguments. */
94 /* Arguments start above the "LR save word" and "Back chain". */
95 int argoffset
= 2 * tdep
->wordsize
;
96 /* Structures start after the arguments. */
97 int structoffset
= argoffset
+ argspace
;
99 /* If the function is returning a `struct', then the first word
100 (which will be passed in r3) is used for struct return
101 address. In that case we should advance one word and start
102 from r4 register to copy parameters. */
106 regcache_cooked_write_signed (regcache
,
107 tdep
->ppc_gp0_regnum
+ greg
,
112 for (argno
= 0; argno
< nargs
; argno
++)
114 struct value
*arg
= args
[argno
];
115 struct type
*type
= check_typedef (value_type (arg
));
116 int len
= TYPE_LENGTH (type
);
117 const bfd_byte
*val
= value_contents (arg
);
119 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& len
<= 8
120 && !tdep
->soft_float
)
122 /* Floating point value converted to "double" then
123 passed in an FP register, when the registers run out,
124 8 byte aligned stack is used. */
129 /* Always store the floating point value using
130 the register's floating-point format. */
131 gdb_byte regval
[MAX_REGISTER_SIZE
];
133 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
134 convert_typed_floating (val
, type
, regval
, regtype
);
135 regcache_cooked_write (regcache
,
136 tdep
->ppc_fp0_regnum
+ freg
,
143 /* The SysV ABI tells us to convert floats to
144 doubles before writing them to an 8 byte aligned
145 stack location. Unfortunately GCC does not do
146 that, and stores floats into 4 byte aligned
147 locations without converting them to doubles.
148 Since there is no know compiler that actually
149 follows the ABI here, we implement the GCC
152 /* Align to 4 bytes or 8 bytes depending on the type of
153 the argument (float or double). */
154 argoffset
= align_up (argoffset
, len
);
156 write_memory (sp
+ argoffset
, val
, len
);
160 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
163 && (gdbarch_long_double_format (gdbarch
)
164 == floatformats_ibm_long_double
))
166 /* IBM long double passed in two FP registers if
167 available, otherwise 8-byte aligned stack. */
172 regcache_cooked_write (regcache
,
173 tdep
->ppc_fp0_regnum
+ freg
,
175 regcache_cooked_write (regcache
,
176 tdep
->ppc_fp0_regnum
+ freg
+ 1,
183 argoffset
= align_up (argoffset
, 8);
185 write_memory (sp
+ argoffset
, val
, len
);
190 && (TYPE_CODE (type
) == TYPE_CODE_INT
/* long long */
191 || TYPE_CODE (type
) == TYPE_CODE_FLT
/* double */
192 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
193 && tdep
->soft_float
)))
195 /* "long long" or soft-float "double" or "_Decimal64"
196 passed in an odd/even register pair with the low
197 addressed word in the odd register and the high
198 addressed word in the even register, or when the
199 registers run out an 8 byte aligned stack
203 /* Just in case GREG was 10. */
205 argoffset
= align_up (argoffset
, 8);
207 write_memory (sp
+ argoffset
, val
, len
);
212 /* Must start on an odd register - r3/r4 etc. */
217 regcache_cooked_write (regcache
,
218 tdep
->ppc_gp0_regnum
+ greg
+ 0,
220 regcache_cooked_write (regcache
,
221 tdep
->ppc_gp0_regnum
+ greg
+ 1,
228 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
229 && (gdbarch_long_double_format (gdbarch
)
230 == floatformats_ibm_long_double
))
231 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
232 && tdep
->soft_float
)))
234 /* Soft-float IBM long double or _Decimal128 passed in
235 four consecutive registers, or on the stack. The
236 registers are not necessarily odd/even pairs. */
240 argoffset
= align_up (argoffset
, 8);
242 write_memory (sp
+ argoffset
, val
, len
);
249 regcache_cooked_write (regcache
,
250 tdep
->ppc_gp0_regnum
+ greg
+ 0,
252 regcache_cooked_write (regcache
,
253 tdep
->ppc_gp0_regnum
+ greg
+ 1,
255 regcache_cooked_write (regcache
,
256 tdep
->ppc_gp0_regnum
+ greg
+ 2,
258 regcache_cooked_write (regcache
,
259 tdep
->ppc_gp0_regnum
+ greg
+ 3,
265 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
<= 8
266 && !tdep
->soft_float
)
268 /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can
275 gdb_byte regval
[MAX_REGISTER_SIZE
];
278 /* 32-bit decimal floats are right aligned in the
280 if (TYPE_LENGTH (type
) == 4)
282 memcpy (regval
+ 4, val
, 4);
288 regcache_cooked_write (regcache
,
289 tdep
->ppc_fp0_regnum
+ freg
, p
);
296 argoffset
= align_up (argoffset
, len
);
299 /* Write value in the stack's parameter save area. */
300 write_memory (sp
+ argoffset
, val
, len
);
305 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
== 16
306 && !tdep
->soft_float
)
308 /* 128-bit decimal floats go in f2 .. f7, always in even/odd
309 pairs. They can end up in memory, using two doublewords. */
313 /* Make sure freg is even. */
318 regcache_cooked_write (regcache
,
319 tdep
->ppc_fp0_regnum
+ freg
, val
);
320 regcache_cooked_write (regcache
,
321 tdep
->ppc_fp0_regnum
+ freg
+ 1, val
+ 8);
326 argoffset
= align_up (argoffset
, 8);
329 write_memory (sp
+ argoffset
, val
, 16);
334 /* If a 128-bit decimal float goes to the stack because only f7
335 and f8 are free (thus there's no even/odd register pair
336 available), these registers should be marked as occupied.
337 Hence we increase freg even when writing to memory. */
341 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
342 && TYPE_VECTOR (type
)
345 /* OpenCL vectors shorter than 16 bytes are passed as if
346 a series of independent scalars. */
347 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
348 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
350 for (i
= 0; i
< nelt
; i
++)
352 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
354 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
&& !tdep
->soft_float
)
360 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
361 gdb_byte regval
[MAX_REGISTER_SIZE
];
363 = register_type (gdbarch
, regnum
);
364 convert_typed_floating (elval
, eltype
,
366 regcache_cooked_write (regcache
, regnum
, regval
);
372 argoffset
= align_up (argoffset
, len
);
374 write_memory (sp
+ argoffset
, val
, len
);
378 else if (TYPE_LENGTH (eltype
) == 8)
382 /* Just in case GREG was 10. */
384 argoffset
= align_up (argoffset
, 8);
386 write_memory (sp
+ argoffset
, elval
,
387 TYPE_LENGTH (eltype
));
392 /* Must start on an odd register - r3/r4 etc. */
397 int regnum
= tdep
->ppc_gp0_regnum
+ greg
;
398 regcache_cooked_write (regcache
,
399 regnum
+ 0, elval
+ 0);
400 regcache_cooked_write (regcache
,
401 regnum
+ 1, elval
+ 4);
408 gdb_byte word
[MAX_REGISTER_SIZE
];
409 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
410 unpack_long (eltype
, elval
));
415 regcache_cooked_write (regcache
,
416 tdep
->ppc_gp0_regnum
+ greg
,
422 argoffset
= align_up (argoffset
, tdep
->wordsize
);
424 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
425 argoffset
+= tdep
->wordsize
;
431 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
432 && TYPE_VECTOR (type
)
435 /* OpenCL vectors 16 bytes or longer are passed as if
436 a series of AltiVec vectors. */
439 for (i
= 0; i
< len
/ 16; i
++)
441 const gdb_byte
*elval
= val
+ i
* 16;
446 regcache_cooked_write (regcache
,
447 tdep
->ppc_vr0_regnum
+ vreg
,
453 argoffset
= align_up (argoffset
, 16);
455 write_memory (sp
+ argoffset
, elval
, 16);
461 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
462 && TYPE_VECTOR (type
)
463 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
465 /* Vector parameter passed in an Altivec register, or
466 when that runs out, 16 byte aligned stack location. */
470 regcache_cooked_write (regcache
,
471 tdep
->ppc_vr0_regnum
+ vreg
, val
);
476 argoffset
= align_up (argoffset
, 16);
478 write_memory (sp
+ argoffset
, val
, 16);
483 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
484 && TYPE_VECTOR (type
)
485 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
487 /* Vector parameter passed in an e500 register, or when
488 that runs out, 8 byte aligned stack location. Note
489 that since e500 vector and general purpose registers
490 both map onto the same underlying register set, a
491 "greg" and not a "vreg" is consumed here. A cooked
492 write stores the value in the correct locations
493 within the raw register cache. */
497 regcache_cooked_write (regcache
,
498 tdep
->ppc_ev0_regnum
+ greg
, val
);
503 argoffset
= align_up (argoffset
, 8);
505 write_memory (sp
+ argoffset
, val
, 8);
511 /* Reduce the parameter down to something that fits in a
513 gdb_byte word
[MAX_REGISTER_SIZE
];
514 memset (word
, 0, MAX_REGISTER_SIZE
);
515 if (len
> tdep
->wordsize
516 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
517 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
519 /* Structs and large values are put in an
520 aligned stack slot ... */
521 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
522 && TYPE_VECTOR (type
)
524 structoffset
= align_up (structoffset
, 16);
526 structoffset
= align_up (structoffset
, 8);
529 write_memory (sp
+ structoffset
, val
, len
);
530 /* ... and then a "word" pointing to that address is
531 passed as the parameter. */
532 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
536 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
537 /* Sign or zero extend the "int" into a "word". */
538 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
539 unpack_long (type
, val
));
541 /* Always goes in the low address. */
542 memcpy (word
, val
, len
);
543 /* Store that "word" in a register, or on the stack.
544 The words have "4" byte alignment. */
548 regcache_cooked_write (regcache
,
549 tdep
->ppc_gp0_regnum
+ greg
, word
);
554 argoffset
= align_up (argoffset
, tdep
->wordsize
);
556 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
557 argoffset
+= tdep
->wordsize
;
562 /* Compute the actual stack space requirements. */
565 /* Remember the amount of space needed by the arguments. */
566 argspace
= argoffset
;
567 /* Allocate space for both the arguments and the structures. */
568 sp
-= (argoffset
+ structoffset
);
569 /* Ensure that the stack is still 16 byte aligned. */
570 sp
= align_down (sp
, 16);
573 /* The psABI says that "A caller of a function that takes a
574 variable argument list shall set condition register bit 6 to
575 1 if it passes one or more arguments in the floating-point
576 registers. It is strongly recommended that the caller set the
577 bit to 0 otherwise..." Doing this for normal functions too
583 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_cr_regnum
, &cr
);
588 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_cr_regnum
, cr
);
593 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
595 /* Write the backchain (it occupies WORDSIZED bytes). */
596 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, saved_sp
);
598 /* Point the inferior function call's return address at the dummy's
600 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
605 /* Handle the return-value conventions for Decimal Floating Point values
606 in both ppc32 and ppc64, which are the same. */
608 get_decimal_float_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
609 struct regcache
*regcache
, gdb_byte
*readbuf
,
610 const gdb_byte
*writebuf
)
612 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
614 gdb_assert (TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
);
616 /* 32-bit and 64-bit decimal floats in f1. */
617 if (TYPE_LENGTH (valtype
) <= 8)
619 if (writebuf
!= NULL
)
621 gdb_byte regval
[MAX_REGISTER_SIZE
];
624 /* 32-bit decimal float is right aligned in the doubleword. */
625 if (TYPE_LENGTH (valtype
) == 4)
627 memcpy (regval
+ 4, writebuf
, 4);
633 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, p
);
637 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, readbuf
);
639 /* Left align 32-bit decimal float. */
640 if (TYPE_LENGTH (valtype
) == 4)
641 memcpy (readbuf
, readbuf
+ 4, 4);
644 /* 128-bit decimal floats in f2,f3. */
645 else if (TYPE_LENGTH (valtype
) == 16)
647 if (writebuf
!= NULL
|| readbuf
!= NULL
)
651 for (i
= 0; i
< 2; i
++)
653 if (writebuf
!= NULL
)
654 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 2 + i
,
657 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 2 + i
,
664 internal_error (__FILE__
, __LINE__
, _("Unknown decimal float size."));
666 return RETURN_VALUE_REGISTER_CONVENTION
;
669 /* Handle the return-value conventions specified by the SysV 32-bit
670 PowerPC ABI (including all the supplements):
672 no floating-point: floating-point values returned using 32-bit
673 general-purpose registers.
675 Altivec: 128-bit vectors returned using vector registers.
677 e500: 64-bit vectors returned using the full full 64 bit EV
678 register, floating-point values returned using 32-bit
679 general-purpose registers.
681 GCC (broken): Small struct values right (instead of left) aligned
682 when returned in general-purpose registers. */
684 static enum return_value_convention
685 do_ppc_sysv_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
686 struct type
*type
, struct regcache
*regcache
,
687 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
690 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
691 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
695 && TYPE_CALLING_CONVENTION (func_type
) == DW_CC_GDB_IBM_OpenCL
)
698 gdb_assert (tdep
->wordsize
== 4);
700 if (TYPE_CODE (type
) == TYPE_CODE_FLT
701 && TYPE_LENGTH (type
) <= 8
702 && !tdep
->soft_float
)
706 /* Floats and doubles stored in "f1". Convert the value to
707 the required type. */
708 gdb_byte regval
[MAX_REGISTER_SIZE
];
709 struct type
*regtype
= register_type (gdbarch
,
710 tdep
->ppc_fp0_regnum
+ 1);
711 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
712 convert_typed_floating (regval
, regtype
, readbuf
, type
);
716 /* Floats and doubles stored in "f1". Convert the value to
717 the register's "double" type. */
718 gdb_byte regval
[MAX_REGISTER_SIZE
];
719 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
720 convert_typed_floating (writebuf
, type
, regval
, regtype
);
721 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
723 return RETURN_VALUE_REGISTER_CONVENTION
;
725 if (TYPE_CODE (type
) == TYPE_CODE_FLT
726 && TYPE_LENGTH (type
) == 16
728 && (gdbarch_long_double_format (gdbarch
)
729 == floatformats_ibm_long_double
))
731 /* IBM long double stored in f1 and f2. */
734 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, readbuf
);
735 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 2,
740 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, writebuf
);
741 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 2,
744 return RETURN_VALUE_REGISTER_CONVENTION
;
746 if (TYPE_LENGTH (type
) == 16
747 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
748 && (gdbarch_long_double_format (gdbarch
)
749 == floatformats_ibm_long_double
))
750 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& tdep
->soft_float
)))
752 /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
756 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, readbuf
);
757 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
759 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 5,
761 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 6,
766 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
767 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
769 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 5,
771 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 6,
774 return RETURN_VALUE_REGISTER_CONVENTION
;
776 if ((TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
777 || (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8)
778 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& TYPE_LENGTH (type
) == 8
779 && tdep
->soft_float
))
783 /* A long long, double or _Decimal64 stored in the 32 bit
785 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
787 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
792 /* A long long, double or _Decimal64 stored in the 32 bit
794 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
796 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
799 return RETURN_VALUE_REGISTER_CONVENTION
;
801 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& !tdep
->soft_float
)
802 return get_decimal_float_return_value (gdbarch
, type
, regcache
, readbuf
,
804 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
805 || TYPE_CODE (type
) == TYPE_CODE_CHAR
806 || TYPE_CODE (type
) == TYPE_CODE_BOOL
807 || TYPE_CODE (type
) == TYPE_CODE_PTR
808 || TYPE_CODE (type
) == TYPE_CODE_REF
809 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
810 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
814 /* Some sort of integer stored in r3. Since TYPE isn't
815 bigger than the register, sign extension isn't a problem
816 - just do everything unsigned. */
818 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
820 store_unsigned_integer (readbuf
, TYPE_LENGTH (type
), byte_order
,
825 /* Some sort of integer stored in r3. Use unpack_long since
826 that should handle any required sign extension. */
827 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
828 unpack_long (type
, writebuf
));
830 return RETURN_VALUE_REGISTER_CONVENTION
;
832 /* OpenCL vectors < 16 bytes are returned as distinct
833 scalars in f1..f2 or r3..r10. */
834 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
835 && TYPE_VECTOR (type
)
836 && TYPE_LENGTH (type
) < 16
839 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
840 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
842 for (i
= 0; i
< nelt
; i
++)
844 int offset
= i
* TYPE_LENGTH (eltype
);
846 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
848 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
849 gdb_byte regval
[MAX_REGISTER_SIZE
];
850 struct type
*regtype
= register_type (gdbarch
, regnum
);
852 if (writebuf
!= NULL
)
854 convert_typed_floating (writebuf
+ offset
, eltype
,
856 regcache_cooked_write (regcache
, regnum
, regval
);
860 regcache_cooked_read (regcache
, regnum
, regval
);
861 convert_typed_floating (regval
, regtype
,
862 readbuf
+ offset
, eltype
);
867 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
870 if (writebuf
!= NULL
)
872 regval
= unpack_long (eltype
, writebuf
+ offset
);
873 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
877 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
878 store_unsigned_integer (readbuf
+ offset
,
879 TYPE_LENGTH (eltype
), byte_order
,
885 return RETURN_VALUE_REGISTER_CONVENTION
;
887 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
888 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
889 && TYPE_VECTOR (type
)
890 && TYPE_LENGTH (type
) >= 16
893 int n_regs
= TYPE_LENGTH (type
) / 16;
896 for (i
= 0; i
< n_regs
; i
++)
899 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
901 if (writebuf
!= NULL
)
902 regcache_cooked_write (regcache
, regnum
, writebuf
+ offset
);
904 regcache_cooked_read (regcache
, regnum
, readbuf
+ offset
);
907 return RETURN_VALUE_REGISTER_CONVENTION
;
909 if (TYPE_LENGTH (type
) == 16
910 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
911 && TYPE_VECTOR (type
)
912 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
916 /* Altivec places the return value in "v2". */
917 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
921 /* Altivec places the return value in "v2". */
922 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, writebuf
);
924 return RETURN_VALUE_REGISTER_CONVENTION
;
926 if (TYPE_LENGTH (type
) == 16
927 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
928 && TYPE_VECTOR (type
)
929 && tdep
->vector_abi
== POWERPC_VEC_GENERIC
)
931 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
932 GCC without AltiVec returns them in memory, but it warns about
933 ABI risks in that case; we don't try to support it. */
936 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
938 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
940 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 5,
942 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 6,
947 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
949 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
951 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 5,
953 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 6,
956 return RETURN_VALUE_REGISTER_CONVENTION
;
958 if (TYPE_LENGTH (type
) == 8
959 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
960 && TYPE_VECTOR (type
)
961 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
963 /* The e500 ABI places return values for the 64-bit DSP types
964 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
965 corresponds to the entire r3 value for e500, whereas GDB's r3
966 only corresponds to the least significant 32-bits. So place
967 the 64-bit DSP type's value in ev3. */
969 regcache_cooked_read (regcache
, tdep
->ppc_ev0_regnum
+ 3, readbuf
);
971 regcache_cooked_write (regcache
, tdep
->ppc_ev0_regnum
+ 3, writebuf
);
972 return RETURN_VALUE_REGISTER_CONVENTION
;
974 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
976 /* GCC screwed up for structures or unions whose size is less
977 than or equal to 8 bytes.. Instead of left-aligning, it
978 right-aligns the data into the buffer formed by r3, r4. */
979 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
980 int len
= TYPE_LENGTH (type
);
981 int offset
= (2 * tdep
->wordsize
- len
) % tdep
->wordsize
;
985 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
986 regvals
+ 0 * tdep
->wordsize
);
987 if (len
> tdep
->wordsize
)
988 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
989 regvals
+ 1 * tdep
->wordsize
);
990 memcpy (readbuf
, regvals
+ offset
, len
);
994 memset (regvals
, 0, sizeof regvals
);
995 memcpy (regvals
+ offset
, writebuf
, len
);
996 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
997 regvals
+ 0 * tdep
->wordsize
);
998 if (len
> tdep
->wordsize
)
999 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1000 regvals
+ 1 * tdep
->wordsize
);
1003 return RETURN_VALUE_REGISTER_CONVENTION
;
1005 if (TYPE_LENGTH (type
) <= 8)
1009 /* This matches SVr4 PPC, it does not match GCC. */
1010 /* The value is right-padded to 8 bytes and then loaded, as
1011 two "words", into r3/r4. */
1012 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
1013 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1014 regvals
+ 0 * tdep
->wordsize
);
1015 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1016 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1017 regvals
+ 1 * tdep
->wordsize
);
1018 memcpy (readbuf
, regvals
, TYPE_LENGTH (type
));
1022 /* This matches SVr4 PPC, it does not match GCC. */
1023 /* The value is padded out to 8 bytes and then loaded, as
1024 two "words" into r3/r4. */
1025 gdb_byte regvals
[MAX_REGISTER_SIZE
* 2];
1026 memset (regvals
, 0, sizeof regvals
);
1027 memcpy (regvals
, writebuf
, TYPE_LENGTH (type
));
1028 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1029 regvals
+ 0 * tdep
->wordsize
);
1030 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
1031 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
1032 regvals
+ 1 * tdep
->wordsize
);
1034 return RETURN_VALUE_REGISTER_CONVENTION
;
1036 return RETURN_VALUE_STRUCT_CONVENTION
;
1039 enum return_value_convention
1040 ppc_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
1041 struct type
*valtype
, struct regcache
*regcache
,
1042 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1044 return do_ppc_sysv_return_value (gdbarch
, func_type
, valtype
, regcache
,
1045 readbuf
, writebuf
, 0);
1048 enum return_value_convention
1049 ppc_sysv_abi_broken_return_value (struct gdbarch
*gdbarch
,
1050 struct type
*func_type
,
1051 struct type
*valtype
,
1052 struct regcache
*regcache
,
1053 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1055 return do_ppc_sysv_return_value (gdbarch
, func_type
, valtype
, regcache
,
1056 readbuf
, writebuf
, 1);
1059 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
1060 function's code address back into the function's descriptor
1063 Find a value for the TOC register. Every symbol should have both
1064 ".FN" and "FN" in the minimal symbol table. "FN" points at the
1065 FN's descriptor, while ".FN" points at the entry point (which
1066 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
1067 FN's descriptor address (while at the same time being careful to
1068 find "FN" in the same object file as ".FN"). */
1071 convert_code_addr_to_desc_addr (CORE_ADDR code_addr
, CORE_ADDR
*desc_addr
)
1073 struct obj_section
*dot_fn_section
;
1074 struct minimal_symbol
*dot_fn
;
1075 struct minimal_symbol
*fn
;
1077 /* Find the minimal symbol that corresponds to CODE_ADDR (should
1078 have a name of the form ".FN"). */
1079 dot_fn
= lookup_minimal_symbol_by_pc (code_addr
);
1080 if (dot_fn
== NULL
|| SYMBOL_LINKAGE_NAME (dot_fn
)[0] != '.')
1082 /* Get the section that contains CODE_ADDR. Need this for the
1083 "objfile" that it contains. */
1084 dot_fn_section
= find_pc_section (code_addr
);
1085 if (dot_fn_section
== NULL
|| dot_fn_section
->objfile
== NULL
)
1087 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
1088 address. Only look for the minimal symbol in ".FN"'s object file
1089 - avoids problems when two object files (i.e., shared libraries)
1090 contain a minimal symbol with the same name. */
1091 fn
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn
) + 1, NULL
,
1092 dot_fn_section
->objfile
);
1095 /* Found a descriptor. */
1096 (*desc_addr
) = SYMBOL_VALUE_ADDRESS (fn
);
1100 /* Pass the arguments in either registers, or in the stack. Using the
1101 ppc 64 bit SysV ABI.
1103 This implements a dumbed down version of the ABI. It always writes
1104 values to memory, GPR and FPR, even when not necessary. Doing this
1105 greatly simplifies the logic. */
1108 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
,
1109 struct value
*function
,
1110 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1111 int nargs
, struct value
**args
, CORE_ADDR sp
,
1112 int struct_return
, CORE_ADDR struct_addr
)
1114 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
1115 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1116 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1119 ULONGEST back_chain
;
1120 /* See for-loop comment below. */
1122 /* Size of the by-reference parameter copy region, the final value is
1123 computed in the for-loop below. */
1124 LONGEST refparam_size
= 0;
1125 /* Size of the general parameter region, the final value is computed
1126 in the for-loop below. */
1127 LONGEST gparam_size
= 0;
1128 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
1129 calls to align_up(), align_down(), etc. because this makes it
1130 easier to reuse this code (in a copy/paste sense) in the future,
1131 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
1132 at some point makes it easier to verify that this function is
1133 correct without having to do a non-local analysis to figure out
1134 the possible values of tdep->wordsize. */
1135 gdb_assert (tdep
->wordsize
== 8);
1137 /* This function exists to support a calling convention that
1138 requires floating-point registers. It shouldn't be used on
1139 processors that lack them. */
1140 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1142 /* By this stage in the proceedings, SP has been decremented by "red
1143 zone size" + "struct return size". Fetch the stack-pointer from
1144 before this and use that as the BACK_CHAIN. */
1145 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
1148 ftype
= check_typedef (value_type (function
));
1149 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
)
1150 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
1151 if (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
1152 && TYPE_CALLING_CONVENTION (ftype
) == DW_CC_GDB_IBM_OpenCL
)
1155 /* Go through the argument list twice.
1157 Pass 1: Compute the function call's stack space and register
1160 Pass 2: Replay the same computation but this time also write the
1161 values out to the target. */
1163 for (write_pass
= 0; write_pass
< 2; write_pass
++)
1166 /* Next available floating point register for float and double
1169 /* Next available general register for non-vector (but possibly
1170 float) arguments. */
1172 /* Next available vector register for vector arguments. */
1174 /* The address, at which the next general purpose parameter
1175 (integer, struct, float, vector, ...) should be saved. */
1177 /* The address, at which the next by-reference parameter
1178 (non-Altivec vector, variably-sized type) should be saved. */
1183 /* During the first pass, GPARAM and REFPARAM are more like
1184 offsets (start address zero) than addresses. That way
1185 they accumulate the total stack space each region
1192 /* Decrement the stack pointer making space for the Altivec
1193 and general on-stack parameters. Set refparam and gparam
1194 to their corresponding regions. */
1195 refparam
= align_down (sp
- refparam_size
, 16);
1196 gparam
= align_down (refparam
- gparam_size
, 16);
1197 /* Add in space for the TOC, link editor double word,
1198 compiler double word, LR save area, CR save area. */
1199 sp
= align_down (gparam
- 48, 16);
1202 /* If the function is returning a `struct', then there is an
1203 extra hidden parameter (which will be passed in r3)
1204 containing the address of that struct.. In that case we
1205 should advance one word and start from r4 register to copy
1206 parameters. This also consumes one on-stack parameter slot. */
1210 regcache_cooked_write_signed (regcache
,
1211 tdep
->ppc_gp0_regnum
+ greg
,
1214 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
1217 for (argno
= 0; argno
< nargs
; argno
++)
1219 struct value
*arg
= args
[argno
];
1220 struct type
*type
= check_typedef (value_type (arg
));
1221 const bfd_byte
*val
= value_contents (arg
);
1223 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) <= 8)
1225 /* Floats and Doubles go in f1 .. f13. They also
1226 consume a left aligned GREG,, and can end up in
1230 gdb_byte regval
[MAX_REGISTER_SIZE
];
1233 /* Version 1.7 of the 64-bit PowerPC ELF ABI says:
1235 "Single precision floating point values are mapped to
1236 the first word in a single doubleword."
1238 And version 1.9 says:
1240 "Single precision floating point values are mapped to
1241 the second word in a single doubleword."
1243 GDB then writes single precision floating point values
1244 at both words in a doubleword, to support both ABIs. */
1245 if (TYPE_LENGTH (type
) == 4)
1247 memcpy (regval
, val
, 4);
1248 memcpy (regval
+ 4, val
, 4);
1254 /* Write value in the stack's parameter save area. */
1255 write_memory (gparam
, p
, 8);
1259 struct type
*regtype
1260 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
1262 convert_typed_floating (val
, type
, regval
, regtype
);
1263 regcache_cooked_write (regcache
,
1264 tdep
->ppc_fp0_regnum
+ freg
,
1268 regcache_cooked_write (regcache
,
1269 tdep
->ppc_gp0_regnum
+ greg
,
1275 /* Always consume parameter stack space. */
1276 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1278 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
1279 && TYPE_LENGTH (type
) == 16
1280 && (gdbarch_long_double_format (gdbarch
)
1281 == floatformats_ibm_long_double
))
1283 /* IBM long double stored in two doublewords of the
1284 parameter save area and corresponding registers. */
1287 if (!tdep
->soft_float
&& freg
<= 13)
1289 regcache_cooked_write (regcache
,
1290 tdep
->ppc_fp0_regnum
+ freg
,
1293 regcache_cooked_write (regcache
,
1294 tdep
->ppc_fp0_regnum
+ freg
+ 1,
1299 regcache_cooked_write (regcache
,
1300 tdep
->ppc_gp0_regnum
+ greg
,
1303 regcache_cooked_write (regcache
,
1304 tdep
->ppc_gp0_regnum
+ greg
+ 1,
1307 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1311 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1313 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
1314 && TYPE_LENGTH (type
) <= 8)
1316 /* 32-bit and 64-bit decimal floats go in f1 .. f13. They can
1317 end up in memory. */
1320 gdb_byte regval
[MAX_REGISTER_SIZE
];
1323 /* 32-bit decimal floats are right aligned in the
1325 if (TYPE_LENGTH (type
) == 4)
1327 memcpy (regval
+ 4, val
, 4);
1333 /* Write value in the stack's parameter save area. */
1334 write_memory (gparam
, p
, 8);
1337 regcache_cooked_write (regcache
,
1338 tdep
->ppc_fp0_regnum
+ freg
, p
);
1343 /* Always consume parameter stack space. */
1344 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1346 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&&
1347 TYPE_LENGTH (type
) == 16)
1349 /* 128-bit decimal floats go in f2 .. f12, always in even/odd
1350 pairs. They can end up in memory, using two doublewords. */
1355 /* Make sure freg is even. */
1357 regcache_cooked_write (regcache
,
1358 tdep
->ppc_fp0_regnum
+ freg
, val
);
1359 regcache_cooked_write (regcache
,
1360 tdep
->ppc_fp0_regnum
+ freg
+ 1, val
+ 8);
1363 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1368 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1370 else if (TYPE_LENGTH (type
) < 16
1371 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1372 && TYPE_VECTOR (type
)
1375 /* OpenCL vectors shorter than 16 bytes are passed as if
1376 a series of independent scalars. */
1377 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1378 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
1380 for (i
= 0; i
< nelt
; i
++)
1382 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1384 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
1388 gdb_byte regval
[MAX_REGISTER_SIZE
];
1391 if (TYPE_LENGTH (eltype
) == 4)
1393 memcpy (regval
, elval
, 4);
1394 memcpy (regval
+ 4, elval
, 4);
1400 write_memory (gparam
, p
, 8);
1404 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
1405 struct type
*regtype
1406 = register_type (gdbarch
, regnum
);
1408 convert_typed_floating (elval
, eltype
,
1410 regcache_cooked_write (regcache
, regnum
, regval
);
1414 regcache_cooked_write (regcache
,
1415 tdep
->ppc_gp0_regnum
+ greg
,
1421 gparam
= align_up (gparam
+ 8, tdep
->wordsize
);
1427 ULONGEST word
= unpack_long (eltype
, elval
);
1429 regcache_cooked_write_unsigned
1430 (regcache
, tdep
->ppc_gp0_regnum
+ greg
, word
);
1432 write_memory_unsigned_integer
1433 (gparam
, tdep
->wordsize
, byte_order
, word
);
1437 gparam
= align_up (gparam
+ TYPE_LENGTH (eltype
),
1442 else if (TYPE_LENGTH (type
) >= 16
1443 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1444 && TYPE_VECTOR (type
)
1447 /* OpenCL vectors 16 bytes or longer are passed as if
1448 a series of AltiVec vectors. */
1451 for (i
= 0; i
< TYPE_LENGTH (type
) / 16; i
++)
1453 const gdb_byte
*elval
= val
+ i
* 16;
1455 gparam
= align_up (gparam
, 16);
1461 regcache_cooked_write (regcache
,
1462 tdep
->ppc_vr0_regnum
+ vreg
,
1465 write_memory (gparam
, elval
, 16);
1473 else if (TYPE_LENGTH (type
) == 16 && TYPE_VECTOR (type
)
1474 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
1475 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1477 /* In the Altivec ABI, vectors go in the vector registers
1478 v2 .. v13, as well as the parameter area -- always at
1479 16-byte aligned addresses. */
1481 gparam
= align_up (gparam
, 16);
1487 regcache_cooked_write (regcache
,
1488 tdep
->ppc_vr0_regnum
+ vreg
, val
);
1490 write_memory (gparam
, val
, TYPE_LENGTH (type
));
1497 else if (TYPE_LENGTH (type
) >= 16 && TYPE_VECTOR (type
)
1498 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1500 /* Non-Altivec vectors are passed by reference. */
1502 /* Copy value onto the stack ... */
1503 refparam
= align_up (refparam
, 16);
1505 write_memory (refparam
, val
, TYPE_LENGTH (type
));
1507 /* ... and pass a pointer to the copy as parameter. */
1511 regcache_cooked_write_unsigned (regcache
,
1512 tdep
->ppc_gp0_regnum
+
1514 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
1515 byte_order
, refparam
);
1518 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
1519 refparam
= align_up (refparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1521 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
1522 || TYPE_CODE (type
) == TYPE_CODE_ENUM
1523 || TYPE_CODE (type
) == TYPE_CODE_BOOL
1524 || TYPE_CODE (type
) == TYPE_CODE_CHAR
1525 || TYPE_CODE (type
) == TYPE_CODE_PTR
1526 || TYPE_CODE (type
) == TYPE_CODE_REF
)
1527 && TYPE_LENGTH (type
) <= 8)
1529 /* Scalars and Pointers get sign[un]extended and go in
1530 gpr3 .. gpr10. They can also end up in memory. */
1533 /* Sign extend the value, then store it unsigned. */
1534 ULONGEST word
= unpack_long (type
, val
);
1535 /* Convert any function code addresses into
1537 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1538 || TYPE_CODE (type
) == TYPE_CODE_REF
)
1540 struct type
*target_type
;
1541 target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1543 if (TYPE_CODE (target_type
) == TYPE_CODE_FUNC
1544 || TYPE_CODE (target_type
) == TYPE_CODE_METHOD
)
1546 CORE_ADDR desc
= word
;
1547 convert_code_addr_to_desc_addr (word
, &desc
);
1552 regcache_cooked_write_unsigned (regcache
,
1553 tdep
->ppc_gp0_regnum
+
1555 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
1559 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1564 for (byte
= 0; byte
< TYPE_LENGTH (type
);
1565 byte
+= tdep
->wordsize
)
1567 if (write_pass
&& greg
<= 10)
1569 gdb_byte regval
[MAX_REGISTER_SIZE
];
1570 int len
= TYPE_LENGTH (type
) - byte
;
1571 if (len
> tdep
->wordsize
)
1572 len
= tdep
->wordsize
;
1573 memset (regval
, 0, sizeof regval
);
1574 /* The ABI (version 1.9) specifies that values
1575 smaller than one doubleword are right-aligned
1576 and those larger are left-aligned. GCC
1577 versions before 3.4 implemented this
1579 <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */
1581 memcpy (regval
+ tdep
->wordsize
- len
,
1584 memcpy (regval
, val
+ byte
, len
);
1585 regcache_cooked_write (regcache
, greg
, regval
);
1591 /* WARNING: cagney/2003-09-21: Strictly speaking, this
1592 isn't necessary, unfortunately, GCC appears to get
1593 "struct convention" parameter passing wrong putting
1594 odd sized structures in memory instead of in a
1595 register. Work around this by always writing the
1596 value to memory. Fortunately, doing this
1597 simplifies the code. */
1598 int len
= TYPE_LENGTH (type
);
1599 if (len
< tdep
->wordsize
)
1600 write_memory (gparam
+ tdep
->wordsize
- len
, val
, len
);
1602 write_memory (gparam
, val
, len
);
1605 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
1606 && TYPE_NFIELDS (type
) == 1
1607 && TYPE_LENGTH (type
) <= 16)
1609 /* The ABI (version 1.9) specifies that structs
1610 containing a single floating-point value, at any
1611 level of nesting of single-member structs, are
1612 passed in floating-point registers. */
1613 while (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1614 && TYPE_NFIELDS (type
) == 1)
1615 type
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
1616 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1618 if (TYPE_LENGTH (type
) <= 8)
1622 gdb_byte regval
[MAX_REGISTER_SIZE
];
1623 struct type
*regtype
1624 = register_type (gdbarch
,
1625 tdep
->ppc_fp0_regnum
);
1626 convert_typed_floating (val
, type
, regval
,
1628 regcache_cooked_write (regcache
,
1629 (tdep
->ppc_fp0_regnum
1635 else if (TYPE_LENGTH (type
) == 16
1636 && (gdbarch_long_double_format (gdbarch
)
1637 == floatformats_ibm_long_double
))
1641 regcache_cooked_write (regcache
,
1642 (tdep
->ppc_fp0_regnum
1646 regcache_cooked_write (regcache
,
1647 (tdep
->ppc_fp0_regnum
1655 /* Always consume parameter stack space. */
1656 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1662 /* Save the true region sizes ready for the second pass. */
1663 refparam_size
= refparam
;
1664 /* Make certain that the general parameter save area is at
1665 least the minimum 8 registers (or doublewords) in size. */
1667 gparam_size
= 8 * tdep
->wordsize
;
1669 gparam_size
= gparam
;
1674 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
1676 /* Write the backchain (it occupies WORDSIZED bytes). */
1677 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, back_chain
);
1679 /* Point the inferior function call's return address at the dummy's
1681 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
1683 /* Use the func_addr to find the descriptor, and use that to find
1684 the TOC. If we're calling via a function pointer, the pointer
1685 itself identifies the descriptor. */
1687 struct type
*ftype
= check_typedef (value_type (function
));
1688 CORE_ADDR desc_addr
= value_as_address (function
);
1690 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
1691 || convert_code_addr_to_desc_addr (func_addr
, &desc_addr
))
1693 /* The TOC is the second double word in the descriptor. */
1695 read_memory_unsigned_integer (desc_addr
+ tdep
->wordsize
,
1696 tdep
->wordsize
, byte_order
);
1697 regcache_cooked_write_unsigned (regcache
,
1698 tdep
->ppc_gp0_regnum
+ 2, toc
);
1706 /* The 64 bit ABI return value convention.
1708 Return non-zero if the return-value is stored in a register, return
1709 0 if the return-value is instead stored on the stack (a.k.a.,
1710 struct return convention).
1712 For a return-value stored in a register: when WRITEBUF is non-NULL,
1713 copy the buffer to the corresponding register return-value location
1714 location; when READBUF is non-NULL, fill the buffer from the
1715 corresponding register return-value location. */
1716 enum return_value_convention
1717 ppc64_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
1718 struct type
*valtype
, struct regcache
*regcache
,
1719 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1721 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1722 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1726 && TYPE_CALLING_CONVENTION (func_type
) == DW_CC_GDB_IBM_OpenCL
)
1729 /* This function exists to support a calling convention that
1730 requires floating-point registers. It shouldn't be used on
1731 processors that lack them. */
1732 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1734 /* Floats and doubles in F1. */
1735 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
&& TYPE_LENGTH (valtype
) <= 8)
1737 gdb_byte regval
[MAX_REGISTER_SIZE
];
1738 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
1739 if (writebuf
!= NULL
)
1741 convert_typed_floating (writebuf
, valtype
, regval
, regtype
);
1742 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
1744 if (readbuf
!= NULL
)
1746 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
1747 convert_typed_floating (regval
, regtype
, readbuf
, valtype
);
1749 return RETURN_VALUE_REGISTER_CONVENTION
;
1751 if (TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
)
1752 return get_decimal_float_return_value (gdbarch
, valtype
, regcache
, readbuf
,
1754 /* Integers in r3. */
1755 if ((TYPE_CODE (valtype
) == TYPE_CODE_INT
1756 || TYPE_CODE (valtype
) == TYPE_CODE_ENUM
1757 || TYPE_CODE (valtype
) == TYPE_CODE_CHAR
1758 || TYPE_CODE (valtype
) == TYPE_CODE_BOOL
)
1759 && TYPE_LENGTH (valtype
) <= 8)
1761 if (writebuf
!= NULL
)
1763 /* Be careful to sign extend the value. */
1764 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1765 unpack_long (valtype
, writebuf
));
1767 if (readbuf
!= NULL
)
1769 /* Extract the integer from r3. Since this is truncating the
1770 value, there isn't a sign extension problem. */
1772 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1774 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
), byte_order
,
1777 return RETURN_VALUE_REGISTER_CONVENTION
;
1779 /* All pointers live in r3. */
1780 if (TYPE_CODE (valtype
) == TYPE_CODE_PTR
1781 || TYPE_CODE (valtype
) == TYPE_CODE_REF
)
1783 /* All pointers live in r3. */
1784 if (writebuf
!= NULL
)
1785 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
1786 if (readbuf
!= NULL
)
1787 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, readbuf
);
1788 return RETURN_VALUE_REGISTER_CONVENTION
;
1790 /* OpenCL vectors < 16 bytes are returned as distinct
1791 scalars in f1..f2 or r3..r10. */
1792 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1793 && TYPE_VECTOR (valtype
)
1794 && TYPE_LENGTH (valtype
) < 16
1797 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1798 int i
, nelt
= TYPE_LENGTH (valtype
) / TYPE_LENGTH (eltype
);
1800 for (i
= 0; i
< nelt
; i
++)
1802 int offset
= i
* TYPE_LENGTH (eltype
);
1804 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
1806 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
1807 gdb_byte regval
[MAX_REGISTER_SIZE
];
1808 struct type
*regtype
= register_type (gdbarch
, regnum
);
1810 if (writebuf
!= NULL
)
1812 convert_typed_floating (writebuf
+ offset
, eltype
,
1814 regcache_cooked_write (regcache
, regnum
, regval
);
1816 if (readbuf
!= NULL
)
1818 regcache_cooked_read (regcache
, regnum
, regval
);
1819 convert_typed_floating (regval
, regtype
,
1820 readbuf
+ offset
, eltype
);
1825 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
1828 if (writebuf
!= NULL
)
1830 regval
= unpack_long (eltype
, writebuf
+ offset
);
1831 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
1833 if (readbuf
!= NULL
)
1835 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
1836 store_unsigned_integer (readbuf
+ offset
,
1837 TYPE_LENGTH (eltype
), byte_order
,
1843 return RETURN_VALUE_REGISTER_CONVENTION
;
1845 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
1846 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1847 && TYPE_VECTOR (valtype
)
1848 && TYPE_LENGTH (valtype
) >= 16
1851 int n_regs
= TYPE_LENGTH (valtype
) / 16;
1854 for (i
= 0; i
< n_regs
; i
++)
1856 int offset
= i
* 16;
1857 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
1859 if (writebuf
!= NULL
)
1860 regcache_cooked_write (regcache
, regnum
, writebuf
+ offset
);
1861 if (readbuf
!= NULL
)
1862 regcache_cooked_read (regcache
, regnum
, readbuf
+ offset
);
1865 return RETURN_VALUE_REGISTER_CONVENTION
;
1867 /* Array type has more than one use. */
1868 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
)
1870 /* Small character arrays are returned, right justified, in r3. */
1871 if (TYPE_LENGTH (valtype
) <= 8
1872 && TYPE_CODE (TYPE_TARGET_TYPE (valtype
)) == TYPE_CODE_INT
1873 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
1875 int offset
= (register_size (gdbarch
, tdep
->ppc_gp0_regnum
+ 3)
1876 - TYPE_LENGTH (valtype
));
1877 if (writebuf
!= NULL
)
1878 regcache_cooked_write_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1879 offset
, TYPE_LENGTH (valtype
), writebuf
);
1880 if (readbuf
!= NULL
)
1881 regcache_cooked_read_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
1882 offset
, TYPE_LENGTH (valtype
), readbuf
);
1883 return RETURN_VALUE_REGISTER_CONVENTION
;
1885 /* A VMX vector is returned in v2. */
1886 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1887 && TYPE_VECTOR (valtype
)
1888 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1891 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
1893 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2,
1895 return RETURN_VALUE_REGISTER_CONVENTION
;
1898 /* Big floating point values get stored in adjacent floating
1899 point registers, starting with F1. */
1900 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
1901 && (TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 32))
1903 if (writebuf
|| readbuf
!= NULL
)
1906 for (i
= 0; i
< TYPE_LENGTH (valtype
) / 8; i
++)
1908 if (writebuf
!= NULL
)
1909 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1910 (const bfd_byte
*) writebuf
+ i
* 8);
1911 if (readbuf
!= NULL
)
1912 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1913 (bfd_byte
*) readbuf
+ i
* 8);
1916 return RETURN_VALUE_REGISTER_CONVENTION
;
1918 /* Complex values get returned in f1:f2, need to convert. */
1919 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
1920 && (TYPE_LENGTH (valtype
) == 8 || TYPE_LENGTH (valtype
) == 16))
1922 if (regcache
!= NULL
)
1925 for (i
= 0; i
< 2; i
++)
1927 gdb_byte regval
[MAX_REGISTER_SIZE
];
1928 struct type
*regtype
=
1929 register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
1930 if (writebuf
!= NULL
)
1932 convert_typed_floating ((const bfd_byte
*) writebuf
+
1933 i
* (TYPE_LENGTH (valtype
) / 2),
1934 valtype
, regval
, regtype
);
1935 regcache_cooked_write (regcache
,
1936 tdep
->ppc_fp0_regnum
+ 1 + i
,
1939 if (readbuf
!= NULL
)
1941 regcache_cooked_read (regcache
,
1942 tdep
->ppc_fp0_regnum
+ 1 + i
,
1944 convert_typed_floating (regval
, regtype
,
1945 (bfd_byte
*) readbuf
+
1946 i
* (TYPE_LENGTH (valtype
) / 2),
1951 return RETURN_VALUE_REGISTER_CONVENTION
;
1953 /* Big complex values get stored in f1:f4. */
1954 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
&& TYPE_LENGTH (valtype
) == 32)
1956 if (regcache
!= NULL
)
1959 for (i
= 0; i
< 4; i
++)
1961 if (writebuf
!= NULL
)
1962 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1963 (const bfd_byte
*) writebuf
+ i
* 8);
1964 if (readbuf
!= NULL
)
1965 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
1966 (bfd_byte
*) readbuf
+ i
* 8);
1969 return RETURN_VALUE_REGISTER_CONVENTION
;
1971 return RETURN_VALUE_STRUCT_CONVENTION
;