1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright (C) 2000-2018 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 #include "target-float.h"
35 /* Check whether FTPYE is a (pointer to) function type that should use
36 the OpenCL vector ABI. */
39 ppc_sysv_use_opencl_abi (struct type
*ftype
)
41 ftype
= check_typedef (ftype
);
43 if (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
[PPC_MAX_REGISTER_SIZE
];
140 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
141 target_float_convert (val
, type
, regval
, regtype
);
142 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
,
149 /* The SysV ABI tells us to convert floats to
150 doubles before writing them to an 8 byte aligned
151 stack location. Unfortunately GCC does not do
152 that, and stores floats into 4 byte aligned
153 locations without converting them to doubles.
154 Since there is no know compiler that actually
155 follows the ABI here, we implement the GCC
158 /* Align to 4 bytes or 8 bytes depending on the type of
159 the argument (float or double). */
160 argoffset
= align_up (argoffset
, len
);
162 write_memory (sp
+ argoffset
, val
, len
);
166 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
169 && (gdbarch_long_double_format (gdbarch
)
170 == floatformats_ibm_long_double
))
172 /* IBM long double passed in two FP registers if
173 available, otherwise 8-byte aligned stack. */
178 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
, val
);
179 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
+ 1,
186 argoffset
= align_up (argoffset
, 8);
188 write_memory (sp
+ argoffset
, val
, len
);
193 && (TYPE_CODE (type
) == TYPE_CODE_INT
/* long long */
194 || TYPE_CODE (type
) == TYPE_CODE_FLT
/* double */
195 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
196 && tdep
->soft_float
)))
198 /* "long long" or soft-float "double" or "_Decimal64"
199 passed in an odd/even register pair with the low
200 addressed word in the odd register and the high
201 addressed word in the even register, or when the
202 registers run out an 8 byte aligned stack
206 /* Just in case GREG was 10. */
208 argoffset
= align_up (argoffset
, 8);
210 write_memory (sp
+ argoffset
, val
, len
);
215 /* Must start on an odd register - r3/r4 etc. */
220 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 0,
222 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 1,
229 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
230 && (gdbarch_long_double_format (gdbarch
)
231 == floatformats_ibm_long_double
))
232 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
233 && tdep
->soft_float
)))
235 /* Soft-float IBM long double or _Decimal128 passed in
236 four consecutive registers, or on the stack. The
237 registers are not necessarily odd/even pairs. */
241 argoffset
= align_up (argoffset
, 8);
243 write_memory (sp
+ argoffset
, val
, len
);
250 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 0,
252 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 1,
254 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 2,
256 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
+ 3,
262 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
<= 8
263 && !tdep
->soft_float
)
265 /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can
272 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
275 /* 32-bit decimal floats are right aligned in the
277 if (TYPE_LENGTH (type
) == 4)
279 memcpy (regval
+ 4, val
, 4);
285 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
, p
);
292 argoffset
= align_up (argoffset
, len
);
295 /* Write value in the stack's parameter save area. */
296 write_memory (sp
+ argoffset
, val
, len
);
301 else if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& len
== 16
302 && !tdep
->soft_float
)
304 /* 128-bit decimal floats go in f2 .. f7, always in even/odd
305 pairs. They can end up in memory, using two doublewords. */
309 /* Make sure freg is even. */
314 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
, val
);
315 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ freg
+ 1,
321 argoffset
= align_up (argoffset
, 8);
324 write_memory (sp
+ argoffset
, val
, 16);
329 /* If a 128-bit decimal float goes to the stack because only f7
330 and f8 are free (thus there's no even/odd register pair
331 available), these registers should be marked as occupied.
332 Hence we increase freg even when writing to memory. */
336 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
337 && TYPE_VECTOR (type
)
340 /* OpenCL vectors shorter than 16 bytes are passed as if
341 a series of independent scalars. */
342 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
343 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
345 for (i
= 0; i
< nelt
; i
++)
347 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
349 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
&& !tdep
->soft_float
)
355 int regnum
= tdep
->ppc_fp0_regnum
+ freg
;
356 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
358 = register_type (gdbarch
, regnum
);
359 target_float_convert (elval
, eltype
,
361 regcache
->cooked_write (regnum
, regval
);
367 argoffset
= align_up (argoffset
, len
);
369 write_memory (sp
+ argoffset
, val
, len
);
373 else if (TYPE_LENGTH (eltype
) == 8)
377 /* Just in case GREG was 10. */
379 argoffset
= align_up (argoffset
, 8);
381 write_memory (sp
+ argoffset
, elval
,
382 TYPE_LENGTH (eltype
));
387 /* Must start on an odd register - r3/r4 etc. */
392 int regnum
= tdep
->ppc_gp0_regnum
+ greg
;
393 regcache
->cooked_write (regnum
+ 0, elval
+ 0);
394 regcache
->cooked_write (regnum
+ 1, elval
+ 4);
401 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
402 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
403 unpack_long (eltype
, elval
));
408 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
,
414 argoffset
= align_up (argoffset
, tdep
->wordsize
);
416 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
417 argoffset
+= tdep
->wordsize
;
423 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
424 && TYPE_VECTOR (type
)
427 /* OpenCL vectors 16 bytes or longer are passed as if
428 a series of AltiVec vectors. */
431 for (i
= 0; i
< len
/ 16; i
++)
433 const gdb_byte
*elval
= val
+ i
* 16;
438 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ vreg
,
444 argoffset
= align_up (argoffset
, 16);
446 write_memory (sp
+ argoffset
, elval
, 16);
452 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
453 && TYPE_VECTOR (type
)
454 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
456 /* Vector parameter passed in an Altivec register, or
457 when that runs out, 16 byte aligned stack location. */
461 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ vreg
, val
);
466 argoffset
= align_up (argoffset
, 16);
468 write_memory (sp
+ argoffset
, val
, 16);
473 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
474 && TYPE_VECTOR (type
)
475 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
477 /* Vector parameter passed in an e500 register, or when
478 that runs out, 8 byte aligned stack location. Note
479 that since e500 vector and general purpose registers
480 both map onto the same underlying register set, a
481 "greg" and not a "vreg" is consumed here. A cooked
482 write stores the value in the correct locations
483 within the raw register cache. */
487 regcache
->cooked_write (tdep
->ppc_ev0_regnum
+ greg
, val
);
492 argoffset
= align_up (argoffset
, 8);
494 write_memory (sp
+ argoffset
, val
, 8);
500 /* Reduce the parameter down to something that fits in a
502 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
503 memset (word
, 0, PPC_MAX_REGISTER_SIZE
);
504 if (len
> tdep
->wordsize
505 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
506 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
508 /* Structs and large values are put in an
509 aligned stack slot ... */
510 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
511 && TYPE_VECTOR (type
)
513 structoffset
= align_up (structoffset
, 16);
515 structoffset
= align_up (structoffset
, 8);
518 write_memory (sp
+ structoffset
, val
, len
);
519 /* ... and then a "word" pointing to that address is
520 passed as the parameter. */
521 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
525 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
526 /* Sign or zero extend the "int" into a "word". */
527 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
528 unpack_long (type
, val
));
530 /* Always goes in the low address. */
531 memcpy (word
, val
, len
);
532 /* Store that "word" in a register, or on the stack.
533 The words have "4" byte alignment. */
537 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ greg
, word
);
542 argoffset
= align_up (argoffset
, tdep
->wordsize
);
544 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
545 argoffset
+= tdep
->wordsize
;
550 /* Compute the actual stack space requirements. */
553 /* Remember the amount of space needed by the arguments. */
554 argspace
= argoffset
;
555 /* Allocate space for both the arguments and the structures. */
556 sp
-= (argoffset
+ structoffset
);
557 /* Ensure that the stack is still 16 byte aligned. */
558 sp
= align_down (sp
, 16);
561 /* The psABI says that "A caller of a function that takes a
562 variable argument list shall set condition register bit 6 to
563 1 if it passes one or more arguments in the floating-point
564 registers. It is strongly recommended that the caller set the
565 bit to 0 otherwise..." Doing this for normal functions too
571 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_cr_regnum
, &cr
);
576 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_cr_regnum
, cr
);
581 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
583 /* Write the backchain (it occupies WORDSIZED bytes). */
584 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, saved_sp
);
586 /* Point the inferior function call's return address at the dummy's
588 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
593 /* Handle the return-value conventions for Decimal Floating Point values. */
594 static enum return_value_convention
595 get_decimal_float_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
596 struct regcache
*regcache
, gdb_byte
*readbuf
,
597 const gdb_byte
*writebuf
)
599 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
601 gdb_assert (TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
);
603 /* 32-bit and 64-bit decimal floats in f1. */
604 if (TYPE_LENGTH (valtype
) <= 8)
606 if (writebuf
!= NULL
)
608 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
611 /* 32-bit decimal float is right aligned in the doubleword. */
612 if (TYPE_LENGTH (valtype
) == 4)
614 memcpy (regval
+ 4, writebuf
, 4);
620 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, p
);
624 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, readbuf
);
626 /* Left align 32-bit decimal float. */
627 if (TYPE_LENGTH (valtype
) == 4)
628 memcpy (readbuf
, readbuf
+ 4, 4);
631 /* 128-bit decimal floats in f2,f3. */
632 else if (TYPE_LENGTH (valtype
) == 16)
634 if (writebuf
!= NULL
|| readbuf
!= NULL
)
638 for (i
= 0; i
< 2; i
++)
640 if (writebuf
!= NULL
)
641 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 2 + i
,
644 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 2 + i
,
651 internal_error (__FILE__
, __LINE__
, _("Unknown decimal float size."));
653 return RETURN_VALUE_REGISTER_CONVENTION
;
656 /* Handle the return-value conventions specified by the SysV 32-bit
657 PowerPC ABI (including all the supplements):
659 no floating-point: floating-point values returned using 32-bit
660 general-purpose registers.
662 Altivec: 128-bit vectors returned using vector registers.
664 e500: 64-bit vectors returned using the full full 64 bit EV
665 register, floating-point values returned using 32-bit
666 general-purpose registers.
668 GCC (broken): Small struct values right (instead of left) aligned
669 when returned in general-purpose registers. */
671 static enum return_value_convention
672 do_ppc_sysv_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
673 struct type
*type
, struct regcache
*regcache
,
674 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
677 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
678 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
679 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
681 gdb_assert (tdep
->wordsize
== 4);
683 if (TYPE_CODE (type
) == TYPE_CODE_FLT
684 && TYPE_LENGTH (type
) <= 8
685 && !tdep
->soft_float
)
689 /* Floats and doubles stored in "f1". Convert the value to
690 the required type. */
691 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
692 struct type
*regtype
= register_type (gdbarch
,
693 tdep
->ppc_fp0_regnum
+ 1);
694 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, regval
);
695 target_float_convert (regval
, regtype
, readbuf
, type
);
699 /* Floats and doubles stored in "f1". Convert the value to
700 the register's "double" type. */
701 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
702 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
703 target_float_convert (writebuf
, type
, regval
, regtype
);
704 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, regval
);
706 return RETURN_VALUE_REGISTER_CONVENTION
;
708 if (TYPE_CODE (type
) == TYPE_CODE_FLT
709 && TYPE_LENGTH (type
) == 16
711 && (gdbarch_long_double_format (gdbarch
)
712 == floatformats_ibm_long_double
))
714 /* IBM long double stored in f1 and f2. */
717 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, readbuf
);
718 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 2, readbuf
+ 8);
722 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, writebuf
);
723 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 2, writebuf
+ 8);
725 return RETURN_VALUE_REGISTER_CONVENTION
;
727 if (TYPE_LENGTH (type
) == 16
728 && ((TYPE_CODE (type
) == TYPE_CODE_FLT
729 && (gdbarch_long_double_format (gdbarch
)
730 == floatformats_ibm_long_double
))
731 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& tdep
->soft_float
)))
733 /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
737 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
);
738 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
739 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 5, readbuf
+ 8);
740 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 6, readbuf
+ 12);
744 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
);
745 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
746 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 5, writebuf
+ 8);
747 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 6, writebuf
+ 12);
749 return RETURN_VALUE_REGISTER_CONVENTION
;
751 if ((TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
752 || (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8)
753 || (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& TYPE_LENGTH (type
) == 8
754 && tdep
->soft_float
))
758 /* A long long, double or _Decimal64 stored in the 32 bit
760 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
+ 0);
761 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
765 /* A long long, double or _Decimal64 stored in the 32 bit
767 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
+ 0);
768 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
770 return RETURN_VALUE_REGISTER_CONVENTION
;
772 if (TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
&& !tdep
->soft_float
)
773 return get_decimal_float_return_value (gdbarch
, type
, regcache
, readbuf
,
775 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
776 || TYPE_CODE (type
) == TYPE_CODE_CHAR
777 || TYPE_CODE (type
) == TYPE_CODE_BOOL
778 || TYPE_CODE (type
) == TYPE_CODE_PTR
779 || TYPE_IS_REFERENCE (type
)
780 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
781 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
785 /* Some sort of integer stored in r3. Since TYPE isn't
786 bigger than the register, sign extension isn't a problem
787 - just do everything unsigned. */
789 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
791 store_unsigned_integer (readbuf
, TYPE_LENGTH (type
), byte_order
,
796 /* Some sort of integer stored in r3. Use unpack_long since
797 that should handle any required sign extension. */
798 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
799 unpack_long (type
, writebuf
));
801 return RETURN_VALUE_REGISTER_CONVENTION
;
803 /* OpenCL vectors < 16 bytes are returned as distinct
804 scalars in f1..f2 or r3..r10. */
805 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
806 && TYPE_VECTOR (type
)
807 && TYPE_LENGTH (type
) < 16
810 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
811 int i
, nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
813 for (i
= 0; i
< nelt
; i
++)
815 int offset
= i
* TYPE_LENGTH (eltype
);
817 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
)
819 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + i
;
820 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
821 struct type
*regtype
= register_type (gdbarch
, regnum
);
823 if (writebuf
!= NULL
)
825 target_float_convert (writebuf
+ offset
, eltype
,
827 regcache
->cooked_write (regnum
, regval
);
831 regcache
->cooked_read (regnum
, regval
);
832 target_float_convert (regval
, regtype
,
833 readbuf
+ offset
, eltype
);
838 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
841 if (writebuf
!= NULL
)
843 regval
= unpack_long (eltype
, writebuf
+ offset
);
844 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
848 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
849 store_unsigned_integer (readbuf
+ offset
,
850 TYPE_LENGTH (eltype
), byte_order
,
856 return RETURN_VALUE_REGISTER_CONVENTION
;
858 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
859 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
860 && TYPE_VECTOR (type
)
861 && TYPE_LENGTH (type
) >= 16
864 int n_regs
= TYPE_LENGTH (type
) / 16;
867 for (i
= 0; i
< n_regs
; i
++)
870 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + i
;
872 if (writebuf
!= NULL
)
873 regcache
->cooked_write (regnum
, writebuf
+ offset
);
875 regcache
->cooked_read (regnum
, readbuf
+ offset
);
878 return RETURN_VALUE_REGISTER_CONVENTION
;
880 if (TYPE_LENGTH (type
) == 16
881 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
882 && TYPE_VECTOR (type
)
883 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
887 /* Altivec places the return value in "v2". */
888 regcache
->cooked_read (tdep
->ppc_vr0_regnum
+ 2, readbuf
);
892 /* Altivec places the return value in "v2". */
893 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ 2, writebuf
);
895 return RETURN_VALUE_REGISTER_CONVENTION
;
897 if (TYPE_LENGTH (type
) == 16
898 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
899 && TYPE_VECTOR (type
)
900 && tdep
->vector_abi
== POWERPC_VEC_GENERIC
)
902 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
903 GCC without AltiVec returns them in memory, but it warns about
904 ABI risks in that case; we don't try to support it. */
907 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, readbuf
+ 0);
908 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, readbuf
+ 4);
909 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 5, readbuf
+ 8);
910 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 6, readbuf
+ 12);
914 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
+ 0);
915 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
916 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 5, writebuf
+ 8);
917 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 6, writebuf
+ 12);
919 return RETURN_VALUE_REGISTER_CONVENTION
;
921 if (TYPE_LENGTH (type
) == 8
922 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
923 && TYPE_VECTOR (type
)
924 && tdep
->vector_abi
== POWERPC_VEC_SPE
)
926 /* The e500 ABI places return values for the 64-bit DSP types
927 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
928 corresponds to the entire r3 value for e500, whereas GDB's r3
929 only corresponds to the least significant 32-bits. So place
930 the 64-bit DSP type's value in ev3. */
932 regcache
->cooked_read (tdep
->ppc_ev0_regnum
+ 3, readbuf
);
934 regcache
->cooked_write (tdep
->ppc_ev0_regnum
+ 3, writebuf
);
935 return RETURN_VALUE_REGISTER_CONVENTION
;
937 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
939 /* GCC screwed up for structures or unions whose size is less
940 than or equal to 8 bytes.. Instead of left-aligning, it
941 right-aligns the data into the buffer formed by r3, r4. */
942 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
943 int len
= TYPE_LENGTH (type
);
944 int offset
= (2 * tdep
->wordsize
- len
) % tdep
->wordsize
;
948 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3,
949 regvals
+ 0 * tdep
->wordsize
);
950 if (len
> tdep
->wordsize
)
951 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4,
952 regvals
+ 1 * tdep
->wordsize
);
953 memcpy (readbuf
, regvals
+ offset
, len
);
957 memset (regvals
, 0, sizeof regvals
);
958 memcpy (regvals
+ offset
, writebuf
, len
);
959 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3,
960 regvals
+ 0 * tdep
->wordsize
);
961 if (len
> tdep
->wordsize
)
962 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4,
963 regvals
+ 1 * tdep
->wordsize
);
966 return RETURN_VALUE_REGISTER_CONVENTION
;
968 if (TYPE_LENGTH (type
) <= 8)
972 /* This matches SVr4 PPC, it does not match GCC. */
973 /* The value is right-padded to 8 bytes and then loaded, as
974 two "words", into r3/r4. */
975 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
976 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3,
977 regvals
+ 0 * tdep
->wordsize
);
978 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
979 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4,
980 regvals
+ 1 * tdep
->wordsize
);
981 memcpy (readbuf
, regvals
, TYPE_LENGTH (type
));
985 /* This matches SVr4 PPC, it does not match GCC. */
986 /* The value is padded out to 8 bytes and then loaded, as
987 two "words" into r3/r4. */
988 gdb_byte regvals
[PPC_MAX_REGISTER_SIZE
* 2];
989 memset (regvals
, 0, sizeof regvals
);
990 memcpy (regvals
, writebuf
, TYPE_LENGTH (type
));
991 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3,
992 regvals
+ 0 * tdep
->wordsize
);
993 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
994 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4,
995 regvals
+ 1 * tdep
->wordsize
);
997 return RETURN_VALUE_REGISTER_CONVENTION
;
999 return RETURN_VALUE_STRUCT_CONVENTION
;
1002 enum return_value_convention
1003 ppc_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1004 struct type
*valtype
, struct regcache
*regcache
,
1005 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1007 return do_ppc_sysv_return_value (gdbarch
,
1008 function
? value_type (function
) : NULL
,
1009 valtype
, regcache
, readbuf
, writebuf
, 0);
1012 enum return_value_convention
1013 ppc_sysv_abi_broken_return_value (struct gdbarch
*gdbarch
,
1014 struct value
*function
,
1015 struct type
*valtype
,
1016 struct regcache
*regcache
,
1017 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1019 return do_ppc_sysv_return_value (gdbarch
,
1020 function
? value_type (function
) : NULL
,
1021 valtype
, regcache
, readbuf
, writebuf
, 1);
1024 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
1025 function's code address back into the function's descriptor
1028 Find a value for the TOC register. Every symbol should have both
1029 ".FN" and "FN" in the minimal symbol table. "FN" points at the
1030 FN's descriptor, while ".FN" points at the entry point (which
1031 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
1032 FN's descriptor address (while at the same time being careful to
1033 find "FN" in the same object file as ".FN"). */
1036 convert_code_addr_to_desc_addr (CORE_ADDR code_addr
, CORE_ADDR
*desc_addr
)
1038 struct obj_section
*dot_fn_section
;
1039 struct bound_minimal_symbol dot_fn
;
1040 struct bound_minimal_symbol fn
;
1042 /* Find the minimal symbol that corresponds to CODE_ADDR (should
1043 have a name of the form ".FN"). */
1044 dot_fn
= lookup_minimal_symbol_by_pc (code_addr
);
1045 if (dot_fn
.minsym
== NULL
|| MSYMBOL_LINKAGE_NAME (dot_fn
.minsym
)[0] != '.')
1047 /* Get the section that contains CODE_ADDR. Need this for the
1048 "objfile" that it contains. */
1049 dot_fn_section
= find_pc_section (code_addr
);
1050 if (dot_fn_section
== NULL
|| dot_fn_section
->objfile
== NULL
)
1052 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
1053 address. Only look for the minimal symbol in ".FN"'s object file
1054 - avoids problems when two object files (i.e., shared libraries)
1055 contain a minimal symbol with the same name. */
1056 fn
= lookup_minimal_symbol (MSYMBOL_LINKAGE_NAME (dot_fn
.minsym
) + 1, NULL
,
1057 dot_fn_section
->objfile
);
1058 if (fn
.minsym
== NULL
)
1060 /* Found a descriptor. */
1061 (*desc_addr
) = BMSYMBOL_VALUE_ADDRESS (fn
);
1065 /* Walk down the type tree of TYPE counting consecutive base elements.
1066 If *FIELD_TYPE is NULL, then set it to the first valid floating point
1067 or vector type. If a non-floating point or vector type is found, or
1068 if a floating point or vector type that doesn't match a non-NULL
1069 *FIELD_TYPE is found, then return -1, otherwise return the count in the
1073 ppc64_aggregate_candidate (struct type
*type
,
1074 struct type
**field_type
)
1076 type
= check_typedef (type
);
1078 switch (TYPE_CODE (type
))
1081 case TYPE_CODE_DECFLOAT
:
1084 if (TYPE_CODE (*field_type
) == TYPE_CODE (type
)
1085 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1089 case TYPE_CODE_COMPLEX
:
1090 type
= TYPE_TARGET_TYPE (type
);
1091 if (TYPE_CODE (type
) == TYPE_CODE_FLT
1092 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1096 if (TYPE_CODE (*field_type
) == TYPE_CODE (type
)
1097 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1102 case TYPE_CODE_ARRAY
:
1103 if (TYPE_VECTOR (type
))
1107 if (TYPE_CODE (*field_type
) == TYPE_CODE (type
)
1108 && TYPE_LENGTH (*field_type
) == TYPE_LENGTH (type
))
1113 LONGEST count
, low_bound
, high_bound
;
1115 count
= ppc64_aggregate_candidate
1116 (TYPE_TARGET_TYPE (type
), field_type
);
1120 if (!get_array_bounds (type
, &low_bound
, &high_bound
))
1122 count
*= high_bound
- low_bound
;
1124 /* There must be no padding. */
1126 return TYPE_LENGTH (type
) == 0 ? 0 : -1;
1127 else if (TYPE_LENGTH (type
) != count
* TYPE_LENGTH (*field_type
))
1134 case TYPE_CODE_STRUCT
:
1135 case TYPE_CODE_UNION
:
1140 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
1144 if (field_is_static (&TYPE_FIELD (type
, i
)))
1147 sub_count
= ppc64_aggregate_candidate
1148 (TYPE_FIELD_TYPE (type
, i
), field_type
);
1149 if (sub_count
== -1)
1152 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1155 count
= std::max (count
, sub_count
);
1158 /* There must be no padding. */
1160 return TYPE_LENGTH (type
) == 0 ? 0 : -1;
1161 else if (TYPE_LENGTH (type
) != count
* TYPE_LENGTH (*field_type
))
1175 /* If an argument of type TYPE is a homogeneous float or vector aggregate
1176 that shall be passed in FP/vector registers according to the ELFv2 ABI,
1177 return the homogeneous element type in *ELT_TYPE and the number of
1178 elements in *N_ELTS, and return non-zero. Otherwise, return zero. */
1181 ppc64_elfv2_abi_homogeneous_aggregate (struct type
*type
,
1182 struct type
**elt_type
, int *n_elts
)
1184 /* Complex types at the top level are treated separately. However,
1185 complex types can be elements of homogeneous aggregates. */
1186 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1187 || TYPE_CODE (type
) == TYPE_CODE_UNION
1188 || (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& !TYPE_VECTOR (type
)))
1190 struct type
*field_type
= NULL
;
1191 LONGEST field_count
= ppc64_aggregate_candidate (type
, &field_type
);
1193 if (field_count
> 0)
1195 int n_regs
= ((TYPE_CODE (field_type
) == TYPE_CODE_FLT
1196 || TYPE_CODE (field_type
) == TYPE_CODE_DECFLOAT
)?
1197 (TYPE_LENGTH (field_type
) + 7) >> 3 : 1);
1199 /* The ELFv2 ABI allows homogeneous aggregates to occupy
1200 up to 8 registers. */
1201 if (field_count
* n_regs
<= 8)
1204 *elt_type
= field_type
;
1206 *n_elts
= (int) field_count
;
1207 /* Note that field_count is LONGEST since it may hold the size
1208 of an array, while *n_elts is int since its value is bounded
1209 by the number of registers used for argument passing. The
1210 cast cannot overflow due to the bounds checking above. */
1219 /* Structure holding the next argument position. */
1220 struct ppc64_sysv_argpos
1222 /* Register cache holding argument registers. If this is NULL,
1223 we only simulate argument processing without actually updating
1224 any registers or memory. */
1225 struct regcache
*regcache
;
1226 /* Next available general-purpose argument register. */
1228 /* Next available floating-point argument register. */
1230 /* Next available vector argument register. */
1232 /* The address, at which the next general purpose parameter
1233 (integer, struct, float, vector, ...) should be saved. */
1235 /* The address, at which the next by-reference parameter
1236 (non-Altivec vector, variably-sized type) should be saved. */
1240 /* VAL is a value of length LEN. Store it into the argument area on the
1241 stack and load it into the corresponding general-purpose registers
1242 required by the ABI, and update ARGPOS.
1244 If ALIGN is nonzero, it specifies the minimum alignment required
1245 for the on-stack copy of the argument. */
1248 ppc64_sysv_abi_push_val (struct gdbarch
*gdbarch
,
1249 const bfd_byte
*val
, int len
, int align
,
1250 struct ppc64_sysv_argpos
*argpos
)
1252 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1255 /* Enforce alignment of stack location, if requested. */
1256 if (align
> tdep
->wordsize
)
1258 CORE_ADDR aligned_gparam
= align_up (argpos
->gparam
, align
);
1260 argpos
->greg
+= (aligned_gparam
- argpos
->gparam
) / tdep
->wordsize
;
1261 argpos
->gparam
= aligned_gparam
;
1264 /* The ABI (version 1.9) specifies that values smaller than one
1265 doubleword are right-aligned and those larger are left-aligned.
1266 GCC versions before 3.4 implemented this incorrectly; see
1267 <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */
1268 if (len
< tdep
->wordsize
1269 && gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1270 offset
= tdep
->wordsize
- len
;
1272 if (argpos
->regcache
)
1273 write_memory (argpos
->gparam
+ offset
, val
, len
);
1274 argpos
->gparam
= align_up (argpos
->gparam
+ len
, tdep
->wordsize
);
1276 while (len
>= tdep
->wordsize
)
1278 if (argpos
->regcache
&& argpos
->greg
<= 10)
1279 argpos
->regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ argpos
->greg
,
1282 len
-= tdep
->wordsize
;
1283 val
+= tdep
->wordsize
;
1288 if (argpos
->regcache
&& argpos
->greg
<= 10)
1289 regcache_cooked_write_part (argpos
->regcache
,
1290 tdep
->ppc_gp0_regnum
+ argpos
->greg
,
1296 /* The same as ppc64_sysv_abi_push_val, but using a single-word integer
1297 value VAL as argument. */
1300 ppc64_sysv_abi_push_integer (struct gdbarch
*gdbarch
, ULONGEST val
,
1301 struct ppc64_sysv_argpos
*argpos
)
1303 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1304 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1305 gdb_byte buf
[PPC_MAX_REGISTER_SIZE
];
1307 if (argpos
->regcache
)
1308 store_unsigned_integer (buf
, tdep
->wordsize
, byte_order
, val
);
1309 ppc64_sysv_abi_push_val (gdbarch
, buf
, tdep
->wordsize
, 0, argpos
);
1312 /* VAL is a value of TYPE, a (binary or decimal) floating-point type.
1313 Load it into a floating-point register if required by the ABI,
1314 and update ARGPOS. */
1317 ppc64_sysv_abi_push_freg (struct gdbarch
*gdbarch
,
1318 struct type
*type
, const bfd_byte
*val
,
1319 struct ppc64_sysv_argpos
*argpos
)
1321 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1322 if (tdep
->soft_float
)
1325 if (TYPE_LENGTH (type
) <= 8
1326 && TYPE_CODE (type
) == TYPE_CODE_FLT
)
1328 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1330 if (argpos
->regcache
&& argpos
->freg
<= 13)
1332 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1333 struct type
*regtype
= register_type (gdbarch
, regnum
);
1334 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
1336 target_float_convert (val
, type
, regval
, regtype
);
1337 argpos
->regcache
->cooked_write (regnum
, regval
);
1342 else if (TYPE_LENGTH (type
) <= 8
1343 && TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1345 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1346 placed in the least significant word. */
1347 if (argpos
->regcache
&& argpos
->freg
<= 13)
1349 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1352 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1353 offset
= 8 - TYPE_LENGTH (type
);
1355 regcache_cooked_write_part (argpos
->regcache
, regnum
,
1356 offset
, TYPE_LENGTH (type
), val
);
1361 else if (TYPE_LENGTH (type
) == 16
1362 && TYPE_CODE (type
) == TYPE_CODE_FLT
1363 && (gdbarch_long_double_format (gdbarch
)
1364 == floatformats_ibm_long_double
))
1366 /* IBM long double stored in two consecutive FPRs. */
1367 if (argpos
->regcache
&& argpos
->freg
<= 13)
1369 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1371 argpos
->regcache
->cooked_write (regnum
, val
);
1372 if (argpos
->freg
<= 12)
1373 argpos
->regcache
->cooked_write (regnum
+ 1, val
+ 8);
1378 else if (TYPE_LENGTH (type
) == 16
1379 && TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1381 /* 128-bit decimal floating-point values are stored in and even/odd
1382 pair of FPRs, with the even FPR holding the most significant half. */
1383 argpos
->freg
+= argpos
->freg
& 1;
1385 if (argpos
->regcache
&& argpos
->freg
<= 12)
1387 int regnum
= tdep
->ppc_fp0_regnum
+ argpos
->freg
;
1388 int lopart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 : 0;
1389 int hipart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 0 : 8;
1391 argpos
->regcache
->cooked_write (regnum
, val
+ hipart
);
1392 argpos
->regcache
->cooked_write (regnum
+ 1, val
+ lopart
);
1399 /* VAL is a value of AltiVec vector type. Load it into a vector register
1400 if required by the ABI, and update ARGPOS. */
1403 ppc64_sysv_abi_push_vreg (struct gdbarch
*gdbarch
, const bfd_byte
*val
,
1404 struct ppc64_sysv_argpos
*argpos
)
1406 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1408 if (argpos
->regcache
&& argpos
->vreg
<= 13)
1409 argpos
->regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ argpos
->vreg
, val
);
1414 /* VAL is a value of TYPE. Load it into memory and/or registers
1415 as required by the ABI, and update ARGPOS. */
1418 ppc64_sysv_abi_push_param (struct gdbarch
*gdbarch
,
1419 struct type
*type
, const bfd_byte
*val
,
1420 struct ppc64_sysv_argpos
*argpos
)
1422 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1424 if (TYPE_CODE (type
) == TYPE_CODE_FLT
1425 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
1427 /* Floating-point scalars are passed in floating-point registers. */
1428 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 0, argpos
);
1429 ppc64_sysv_abi_push_freg (gdbarch
, type
, val
, argpos
);
1431 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
)
1432 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
1433 && TYPE_LENGTH (type
) == 16)
1435 /* AltiVec vectors are passed aligned, and in vector registers. */
1436 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 16, argpos
);
1437 ppc64_sysv_abi_push_vreg (gdbarch
, val
, argpos
);
1439 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
)
1440 && TYPE_LENGTH (type
) >= 16)
1442 /* Non-Altivec vectors are passed by reference. */
1444 /* Copy value onto the stack ... */
1445 CORE_ADDR addr
= align_up (argpos
->refparam
, 16);
1446 if (argpos
->regcache
)
1447 write_memory (addr
, val
, TYPE_LENGTH (type
));
1448 argpos
->refparam
= align_up (addr
+ TYPE_LENGTH (type
), tdep
->wordsize
);
1450 /* ... and pass a pointer to the copy as parameter. */
1451 ppc64_sysv_abi_push_integer (gdbarch
, addr
, argpos
);
1453 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
1454 || TYPE_CODE (type
) == TYPE_CODE_ENUM
1455 || TYPE_CODE (type
) == TYPE_CODE_BOOL
1456 || TYPE_CODE (type
) == TYPE_CODE_CHAR
1457 || TYPE_CODE (type
) == TYPE_CODE_PTR
1458 || TYPE_IS_REFERENCE (type
))
1459 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
1463 if (argpos
->regcache
)
1465 /* Sign extend the value, then store it unsigned. */
1466 word
= unpack_long (type
, val
);
1468 /* Convert any function code addresses into descriptors. */
1469 if (tdep
->elf_abi
== POWERPC_ELF_V1
1470 && (TYPE_CODE (type
) == TYPE_CODE_PTR
1471 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1473 struct type
*target_type
1474 = check_typedef (TYPE_TARGET_TYPE (type
));
1476 if (TYPE_CODE (target_type
) == TYPE_CODE_FUNC
1477 || TYPE_CODE (target_type
) == TYPE_CODE_METHOD
)
1479 CORE_ADDR desc
= word
;
1481 convert_code_addr_to_desc_addr (word
, &desc
);
1487 ppc64_sysv_abi_push_integer (gdbarch
, word
, argpos
);
1491 ppc64_sysv_abi_push_val (gdbarch
, val
, TYPE_LENGTH (type
), 0, argpos
);
1493 /* The ABI (version 1.9) specifies that structs containing a
1494 single floating-point value, at any level of nesting of
1495 single-member structs, are passed in floating-point registers. */
1496 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1497 && TYPE_NFIELDS (type
) == 1)
1499 while (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1500 && TYPE_NFIELDS (type
) == 1)
1501 type
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
1503 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
1504 ppc64_sysv_abi_push_freg (gdbarch
, type
, val
, argpos
);
1507 /* In the ELFv2 ABI, homogeneous floating-point or vector
1508 aggregates are passed in a series of registers. */
1509 if (tdep
->elf_abi
== POWERPC_ELF_V2
)
1511 struct type
*eltype
;
1514 if (ppc64_elfv2_abi_homogeneous_aggregate (type
, &eltype
, &nelt
))
1515 for (i
= 0; i
< nelt
; i
++)
1517 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1519 if (TYPE_CODE (eltype
) == TYPE_CODE_FLT
1520 || TYPE_CODE (eltype
) == TYPE_CODE_DECFLOAT
)
1521 ppc64_sysv_abi_push_freg (gdbarch
, eltype
, elval
, argpos
);
1522 else if (TYPE_CODE (eltype
) == TYPE_CODE_ARRAY
1523 && TYPE_VECTOR (eltype
)
1524 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
1525 && TYPE_LENGTH (eltype
) == 16)
1526 ppc64_sysv_abi_push_vreg (gdbarch
, elval
, argpos
);
1532 /* Pass the arguments in either registers, or in the stack. Using the
1533 ppc 64 bit SysV ABI.
1535 This implements a dumbed down version of the ABI. It always writes
1536 values to memory, GPR and FPR, even when not necessary. Doing this
1537 greatly simplifies the logic. */
1540 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
,
1541 struct value
*function
,
1542 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1543 int nargs
, struct value
**args
, CORE_ADDR sp
,
1544 int struct_return
, CORE_ADDR struct_addr
)
1546 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
1547 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1548 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1549 int opencl_abi
= ppc_sysv_use_opencl_abi (value_type (function
));
1550 ULONGEST back_chain
;
1551 /* See for-loop comment below. */
1553 /* Size of the by-reference parameter copy region, the final value is
1554 computed in the for-loop below. */
1555 LONGEST refparam_size
= 0;
1556 /* Size of the general parameter region, the final value is computed
1557 in the for-loop below. */
1558 LONGEST gparam_size
= 0;
1559 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
1560 calls to align_up(), align_down(), etc. because this makes it
1561 easier to reuse this code (in a copy/paste sense) in the future,
1562 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
1563 at some point makes it easier to verify that this function is
1564 correct without having to do a non-local analysis to figure out
1565 the possible values of tdep->wordsize. */
1566 gdb_assert (tdep
->wordsize
== 8);
1568 /* This function exists to support a calling convention that
1569 requires floating-point registers. It shouldn't be used on
1570 processors that lack them. */
1571 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1573 /* By this stage in the proceedings, SP has been decremented by "red
1574 zone size" + "struct return size". Fetch the stack-pointer from
1575 before this and use that as the BACK_CHAIN. */
1576 regcache_cooked_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
),
1579 /* Go through the argument list twice.
1581 Pass 1: Compute the function call's stack space and register
1584 Pass 2: Replay the same computation but this time also write the
1585 values out to the target. */
1587 for (write_pass
= 0; write_pass
< 2; write_pass
++)
1591 struct ppc64_sysv_argpos argpos
;
1598 /* During the first pass, GPARAM and REFPARAM are more like
1599 offsets (start address zero) than addresses. That way
1600 they accumulate the total stack space each region
1602 argpos
.regcache
= NULL
;
1604 argpos
.refparam
= 0;
1608 /* Decrement the stack pointer making space for the Altivec
1609 and general on-stack parameters. Set refparam and gparam
1610 to their corresponding regions. */
1611 argpos
.regcache
= regcache
;
1612 argpos
.refparam
= align_down (sp
- refparam_size
, 16);
1613 argpos
.gparam
= align_down (argpos
.refparam
- gparam_size
, 16);
1614 /* Add in space for the TOC, link editor double word (v1 only),
1615 compiler double word (v1 only), LR save area, CR save area,
1617 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1618 sp
= align_down (argpos
.gparam
- 48, 16);
1620 sp
= align_down (argpos
.gparam
- 32, 16);
1623 /* If the function is returning a `struct', then there is an
1624 extra hidden parameter (which will be passed in r3)
1625 containing the address of that struct.. In that case we
1626 should advance one word and start from r4 register to copy
1627 parameters. This also consumes one on-stack parameter slot. */
1629 ppc64_sysv_abi_push_integer (gdbarch
, struct_addr
, &argpos
);
1631 for (argno
= 0; argno
< nargs
; argno
++)
1633 struct value
*arg
= args
[argno
];
1634 struct type
*type
= check_typedef (value_type (arg
));
1635 const bfd_byte
*val
= value_contents (arg
);
1637 if (TYPE_CODE (type
) == TYPE_CODE_COMPLEX
)
1639 /* Complex types are passed as if two independent scalars. */
1640 struct type
*eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1642 ppc64_sysv_abi_push_param (gdbarch
, eltype
, val
, &argpos
);
1643 ppc64_sysv_abi_push_param (gdbarch
, eltype
,
1644 val
+ TYPE_LENGTH (eltype
), &argpos
);
1646 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
)
1649 /* OpenCL vectors shorter than 16 bytes are passed as if
1650 a series of independent scalars; OpenCL vectors 16 bytes
1651 or longer are passed as if a series of AltiVec vectors. */
1652 struct type
*eltype
;
1655 if (TYPE_LENGTH (type
) < 16)
1656 eltype
= check_typedef (TYPE_TARGET_TYPE (type
));
1658 eltype
= register_type (gdbarch
, tdep
->ppc_vr0_regnum
);
1660 nelt
= TYPE_LENGTH (type
) / TYPE_LENGTH (eltype
);
1661 for (i
= 0; i
< nelt
; i
++)
1663 const gdb_byte
*elval
= val
+ i
* TYPE_LENGTH (eltype
);
1665 ppc64_sysv_abi_push_param (gdbarch
, eltype
, elval
, &argpos
);
1670 /* All other types are passed as single arguments. */
1671 ppc64_sysv_abi_push_param (gdbarch
, type
, val
, &argpos
);
1677 /* Save the true region sizes ready for the second pass. */
1678 refparam_size
= argpos
.refparam
;
1679 /* Make certain that the general parameter save area is at
1680 least the minimum 8 registers (or doublewords) in size. */
1681 if (argpos
.greg
< 8)
1682 gparam_size
= 8 * tdep
->wordsize
;
1684 gparam_size
= argpos
.gparam
;
1689 regcache_cooked_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
1691 /* Write the backchain (it occupies WORDSIZED bytes). */
1692 write_memory_signed_integer (sp
, tdep
->wordsize
, byte_order
, back_chain
);
1694 /* Point the inferior function call's return address at the dummy's
1696 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
1698 /* In the ELFv1 ABI, use the func_addr to find the descriptor, and use
1699 that to find the TOC. If we're calling via a function pointer,
1700 the pointer itself identifies the descriptor. */
1701 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1703 struct type
*ftype
= check_typedef (value_type (function
));
1704 CORE_ADDR desc_addr
= value_as_address (function
);
1706 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
1707 || convert_code_addr_to_desc_addr (func_addr
, &desc_addr
))
1709 /* The TOC is the second double word in the descriptor. */
1711 read_memory_unsigned_integer (desc_addr
+ tdep
->wordsize
,
1712 tdep
->wordsize
, byte_order
);
1714 regcache_cooked_write_unsigned (regcache
,
1715 tdep
->ppc_gp0_regnum
+ 2, toc
);
1719 /* In the ELFv2 ABI, we need to pass the target address in r12 since
1720 we may be calling a global entry point. */
1721 if (tdep
->elf_abi
== POWERPC_ELF_V2
)
1722 regcache_cooked_write_unsigned (regcache
,
1723 tdep
->ppc_gp0_regnum
+ 12, func_addr
);
1728 /* Subroutine of ppc64_sysv_abi_return_value that handles "base" types:
1729 integer, floating-point, and AltiVec vector types.
1731 This routine also handles components of aggregate return types;
1732 INDEX describes which part of the aggregate is to be handled.
1734 Returns true if VALTYPE is some such base type that could be handled,
1737 ppc64_sysv_abi_return_value_base (struct gdbarch
*gdbarch
, struct type
*valtype
,
1738 struct regcache
*regcache
, gdb_byte
*readbuf
,
1739 const gdb_byte
*writebuf
, int index
)
1741 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1743 /* Integers live in GPRs starting at r3. */
1744 if ((TYPE_CODE (valtype
) == TYPE_CODE_INT
1745 || TYPE_CODE (valtype
) == TYPE_CODE_ENUM
1746 || TYPE_CODE (valtype
) == TYPE_CODE_CHAR
1747 || TYPE_CODE (valtype
) == TYPE_CODE_BOOL
)
1748 && TYPE_LENGTH (valtype
) <= 8)
1750 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + index
;
1752 if (writebuf
!= NULL
)
1754 /* Be careful to sign extend the value. */
1755 regcache_cooked_write_unsigned (regcache
, regnum
,
1756 unpack_long (valtype
, writebuf
));
1758 if (readbuf
!= NULL
)
1760 /* Extract the integer from GPR. Since this is truncating the
1761 value, there isn't a sign extension problem. */
1764 regcache_cooked_read_unsigned (regcache
, regnum
, ®val
);
1765 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
),
1766 gdbarch_byte_order (gdbarch
), regval
);
1771 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1773 if (TYPE_LENGTH (valtype
) <= 8
1774 && TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1776 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + index
;
1777 struct type
*regtype
= register_type (gdbarch
, regnum
);
1778 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
1780 if (writebuf
!= NULL
)
1782 target_float_convert (writebuf
, valtype
, regval
, regtype
);
1783 regcache
->cooked_write (regnum
, regval
);
1785 if (readbuf
!= NULL
)
1787 regcache
->cooked_read (regnum
, regval
);
1788 target_float_convert (regval
, regtype
, readbuf
, valtype
);
1793 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1794 placed in the least significant word. */
1795 if (TYPE_LENGTH (valtype
) <= 8
1796 && TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
)
1798 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + index
;
1801 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1802 offset
= 8 - TYPE_LENGTH (valtype
);
1804 if (writebuf
!= NULL
)
1805 regcache_cooked_write_part (regcache
, regnum
,
1806 offset
, TYPE_LENGTH (valtype
), writebuf
);
1807 if (readbuf
!= NULL
)
1808 regcache
->cooked_read_part (regnum
, offset
, TYPE_LENGTH (valtype
),
1813 /* IBM long double stored in two consecutive FPRs. */
1814 if (TYPE_LENGTH (valtype
) == 16
1815 && TYPE_CODE (valtype
) == TYPE_CODE_FLT
1816 && (gdbarch_long_double_format (gdbarch
)
1817 == floatformats_ibm_long_double
))
1819 int regnum
= tdep
->ppc_fp0_regnum
+ 1 + 2 * index
;
1821 if (writebuf
!= NULL
)
1823 regcache
->cooked_write (regnum
, writebuf
);
1824 regcache
->cooked_write (regnum
+ 1, writebuf
+ 8);
1826 if (readbuf
!= NULL
)
1828 regcache
->cooked_read (regnum
, readbuf
);
1829 regcache
->cooked_read (regnum
+ 1, readbuf
+ 8);
1834 /* 128-bit decimal floating-point values are stored in an even/odd
1835 pair of FPRs, with the even FPR holding the most significant half. */
1836 if (TYPE_LENGTH (valtype
) == 16
1837 && TYPE_CODE (valtype
) == TYPE_CODE_DECFLOAT
)
1839 int regnum
= tdep
->ppc_fp0_regnum
+ 2 + 2 * index
;
1840 int lopart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 : 0;
1841 int hipart
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 0 : 8;
1843 if (writebuf
!= NULL
)
1845 regcache
->cooked_write (regnum
, writebuf
+ hipart
);
1846 regcache
->cooked_write (regnum
+ 1, writebuf
+ lopart
);
1848 if (readbuf
!= NULL
)
1850 regcache
->cooked_read (regnum
, readbuf
+ hipart
);
1851 regcache
->cooked_read (regnum
+ 1, readbuf
+ lopart
);
1856 /* AltiVec vectors are returned in VRs starting at v2. */
1857 if (TYPE_LENGTH (valtype
) == 16
1858 && TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
)
1859 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
)
1861 int regnum
= tdep
->ppc_vr0_regnum
+ 2 + index
;
1863 if (writebuf
!= NULL
)
1864 regcache
->cooked_write (regnum
, writebuf
);
1865 if (readbuf
!= NULL
)
1866 regcache
->cooked_read (regnum
, readbuf
);
1870 /* Short vectors are returned in GPRs starting at r3. */
1871 if (TYPE_LENGTH (valtype
) <= 8
1872 && TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
))
1874 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + index
;
1877 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1878 offset
= 8 - TYPE_LENGTH (valtype
);
1880 if (writebuf
!= NULL
)
1881 regcache_cooked_write_part (regcache
, regnum
,
1882 offset
, TYPE_LENGTH (valtype
), writebuf
);
1883 if (readbuf
!= NULL
)
1884 regcache
->cooked_read_part (regnum
, offset
, TYPE_LENGTH (valtype
),
1892 /* The 64 bit ABI return value convention.
1894 Return non-zero if the return-value is stored in a register, return
1895 0 if the return-value is instead stored on the stack (a.k.a.,
1896 struct return convention).
1898 For a return-value stored in a register: when WRITEBUF is non-NULL,
1899 copy the buffer to the corresponding register return-value location
1900 location; when READBUF is non-NULL, fill the buffer from the
1901 corresponding register return-value location. */
1902 enum return_value_convention
1903 ppc64_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1904 struct type
*valtype
, struct regcache
*regcache
,
1905 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1907 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1908 struct type
*func_type
= function
? value_type (function
) : NULL
;
1909 int opencl_abi
= func_type
? ppc_sysv_use_opencl_abi (func_type
) : 0;
1910 struct type
*eltype
;
1913 /* This function exists to support a calling convention that
1914 requires floating-point registers. It shouldn't be used on
1915 processors that lack them. */
1916 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1918 /* Complex types are returned as if two independent scalars. */
1919 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
)
1921 eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1923 for (i
= 0; i
< 2; i
++)
1925 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
1926 readbuf
, writebuf
, i
);
1930 readbuf
+= TYPE_LENGTH (eltype
);
1932 writebuf
+= TYPE_LENGTH (eltype
);
1934 return RETURN_VALUE_REGISTER_CONVENTION
;
1937 /* OpenCL vectors shorter than 16 bytes are returned as if
1938 a series of independent scalars; OpenCL vectors 16 bytes
1939 or longer are returned as if a series of AltiVec vectors. */
1940 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
)
1943 if (TYPE_LENGTH (valtype
) < 16)
1944 eltype
= check_typedef (TYPE_TARGET_TYPE (valtype
));
1946 eltype
= register_type (gdbarch
, tdep
->ppc_vr0_regnum
);
1948 nelt
= TYPE_LENGTH (valtype
) / TYPE_LENGTH (eltype
);
1949 for (i
= 0; i
< nelt
; i
++)
1951 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
1952 readbuf
, writebuf
, i
);
1956 readbuf
+= TYPE_LENGTH (eltype
);
1958 writebuf
+= TYPE_LENGTH (eltype
);
1960 return RETURN_VALUE_REGISTER_CONVENTION
;
1963 /* All pointers live in r3. */
1964 if (TYPE_CODE (valtype
) == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (valtype
))
1966 int regnum
= tdep
->ppc_gp0_regnum
+ 3;
1968 if (writebuf
!= NULL
)
1969 regcache
->cooked_write (regnum
, writebuf
);
1970 if (readbuf
!= NULL
)
1971 regcache
->cooked_read (regnum
, readbuf
);
1972 return RETURN_VALUE_REGISTER_CONVENTION
;
1975 /* Small character arrays are returned, right justified, in r3. */
1976 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
1977 && !TYPE_VECTOR (valtype
)
1978 && TYPE_LENGTH (valtype
) <= 8
1979 && TYPE_CODE (TYPE_TARGET_TYPE (valtype
)) == TYPE_CODE_INT
1980 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
1982 int regnum
= tdep
->ppc_gp0_regnum
+ 3;
1983 int offset
= (register_size (gdbarch
, regnum
) - TYPE_LENGTH (valtype
));
1985 if (writebuf
!= NULL
)
1986 regcache_cooked_write_part (regcache
, regnum
,
1987 offset
, TYPE_LENGTH (valtype
), writebuf
);
1988 if (readbuf
!= NULL
)
1989 regcache
->cooked_read_part (regnum
, offset
, TYPE_LENGTH (valtype
),
1991 return RETURN_VALUE_REGISTER_CONVENTION
;
1994 /* In the ELFv2 ABI, homogeneous floating-point or vector
1995 aggregates are returned in registers. */
1996 if (tdep
->elf_abi
== POWERPC_ELF_V2
1997 && ppc64_elfv2_abi_homogeneous_aggregate (valtype
, &eltype
, &nelt
)
1998 && (TYPE_CODE (eltype
) == TYPE_CODE_FLT
1999 || TYPE_CODE (eltype
) == TYPE_CODE_DECFLOAT
2000 || (TYPE_CODE (eltype
) == TYPE_CODE_ARRAY
2001 && TYPE_VECTOR (eltype
)
2002 && tdep
->vector_abi
== POWERPC_VEC_ALTIVEC
2003 && TYPE_LENGTH (eltype
) == 16)))
2005 for (i
= 0; i
< nelt
; i
++)
2007 ok
= ppc64_sysv_abi_return_value_base (gdbarch
, eltype
, regcache
,
2008 readbuf
, writebuf
, i
);
2012 readbuf
+= TYPE_LENGTH (eltype
);
2014 writebuf
+= TYPE_LENGTH (eltype
);
2017 return RETURN_VALUE_REGISTER_CONVENTION
;
2020 /* In the ELFv2 ABI, aggregate types of up to 16 bytes are
2021 returned in registers r3:r4. */
2022 if (tdep
->elf_abi
== POWERPC_ELF_V2
2023 && TYPE_LENGTH (valtype
) <= 16
2024 && (TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
2025 || TYPE_CODE (valtype
) == TYPE_CODE_UNION
2026 || (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
2027 && !TYPE_VECTOR (valtype
))))
2029 int n_regs
= ((TYPE_LENGTH (valtype
) + tdep
->wordsize
- 1)
2033 for (i
= 0; i
< n_regs
; i
++)
2035 gdb_byte regval
[PPC_MAX_REGISTER_SIZE
];
2036 int regnum
= tdep
->ppc_gp0_regnum
+ 3 + i
;
2037 int offset
= i
* tdep
->wordsize
;
2038 int len
= TYPE_LENGTH (valtype
) - offset
;
2040 if (len
> tdep
->wordsize
)
2041 len
= tdep
->wordsize
;
2043 if (writebuf
!= NULL
)
2045 memset (regval
, 0, sizeof regval
);
2046 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
2048 memcpy (regval
+ tdep
->wordsize
- len
, writebuf
, len
);
2050 memcpy (regval
, writebuf
+ offset
, len
);
2051 regcache
->cooked_write (regnum
, regval
);
2053 if (readbuf
!= NULL
)
2055 regcache
->cooked_read (regnum
, regval
);
2056 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
2058 memcpy (readbuf
, regval
+ tdep
->wordsize
- len
, len
);
2060 memcpy (readbuf
+ offset
, regval
, len
);
2063 return RETURN_VALUE_REGISTER_CONVENTION
;
2066 /* Handle plain base types. */
2067 if (ppc64_sysv_abi_return_value_base (gdbarch
, valtype
, regcache
,
2068 readbuf
, writebuf
, 0))
2069 return RETURN_VALUE_REGISTER_CONVENTION
;
2071 return RETURN_VALUE_STRUCT_CONVENTION
;