GDB (xrefs)
Loading...
Searching...
No Matches
ppc-sysv-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
3
4 Copyright (C) 2000-2023 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
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.
12
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.
17
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/>. */
20
21#include "defs.h"
22#include "language.h"
23#include "gdbcore.h"
24#include "inferior.h"
25#include "regcache.h"
26#include "value.h"
27#include "ppc-tdep.h"
28#include "target.h"
29#include "objfiles.h"
30#include "infcall.h"
31#include "dwarf2.h"
32#include "dwarf2/loc.h"
33#include "target-float.h"
34#include <algorithm>
35
36
37/* Check whether FTPYE is a (pointer to) function type that should use
38 the OpenCL vector ABI. */
39
40static int
42{
43 ftype = check_typedef (ftype);
44
45 if (ftype->code () == TYPE_CODE_PTR)
46 ftype = check_typedef (ftype->target_type ());
47
48 return (ftype->code () == TYPE_CODE_FUNC
49 && TYPE_CALLING_CONVENTION (ftype) == DW_CC_GDB_IBM_OpenCL);
50}
51
52/* Pass the arguments in either registers, or in the stack. Using the
53 ppc sysv ABI, the first eight words of the argument list (that might
54 be less than eight parameters if some parameters occupy more than one
55 word) are passed in r3..r10 registers. float and double parameters are
56 passed in fpr's, in addition to that. Rest of the parameters if any
57 are passed in user stack.
58
59 If the function is returning a structure, then the return address is passed
60 in r3, then the first 7 words of the parameters can be passed in registers,
61 starting from r4. */
62
63CORE_ADDR
65 struct regcache *regcache, CORE_ADDR bp_addr,
66 int nargs, struct value **args, CORE_ADDR sp,
67 function_call_return_method return_method,
68 CORE_ADDR struct_addr)
69{
70 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
71 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
72 int opencl_abi = ppc_sysv_use_opencl_abi (function->type ());
73 ULONGEST saved_sp;
74 int argspace = 0; /* 0 is an initial wrong guess. */
75 int write_pass;
76
77 gdb_assert (tdep->wordsize == 4);
78
80 &saved_sp);
81
82 /* Go through the argument list twice.
83
84 Pass 1: Figure out how much new stack space is required for
85 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
86 ABI doesn't reserve any extra space for parameters which are put
87 in registers, but does always push structures and then pass their
88 address.
89
90 Pass 2: Replay the same computation but this time also write the
91 values out to the target. */
92
93 for (write_pass = 0; write_pass < 2; write_pass++)
94 {
95 int argno;
96 /* Next available floating point register for float and double
97 arguments. */
98 int freg = 1;
99 /* Next available general register for non-float, non-vector
100 arguments. */
101 int greg = 3;
102 /* Next available vector register for vector arguments. */
103 int vreg = 2;
104 /* Arguments start above the "LR save word" and "Back chain". */
105 int argoffset = 2 * tdep->wordsize;
106 /* Structures start after the arguments. */
107 int structoffset = argoffset + argspace;
108
109 /* If the function is returning a `struct', then the first word
110 (which will be passed in r3) is used for struct return
111 address. In that case we should advance one word and start
112 from r4 register to copy parameters. */
113 if (return_method == return_method_struct)
114 {
115 if (write_pass)
117 tdep->ppc_gp0_regnum + greg,
118 struct_addr);
119 greg++;
120 }
121
122 for (argno = 0; argno < nargs; argno++)
123 {
124 struct value *arg = args[argno];
125 struct type *type = check_typedef (arg->type ());
126 int len = type->length ();
127 const bfd_byte *val = arg->contents ().data ();
128
129 if (type->code () == TYPE_CODE_FLT && len <= 8
130 && !tdep->soft_float)
131 {
132 /* Floating point value converted to "double" then
133 passed in an FP register, when the registers run out,
134 8 byte aligned stack is used. */
135 if (freg <= 8)
136 {
137 if (write_pass)
138 {
139 /* Always store the floating point value using
140 the register's floating-point format. */
141 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
142 struct type *regtype
143 = register_type (gdbarch, tdep->ppc_fp0_regnum + freg);
144 target_float_convert (val, type, regval, regtype);
145 regcache->cooked_write (tdep->ppc_fp0_regnum + freg,
146 regval);
147 }
148 freg++;
149 }
150 else
151 {
152 /* The SysV ABI tells us to convert floats to
153 doubles before writing them to an 8 byte aligned
154 stack location. Unfortunately GCC does not do
155 that, and stores floats into 4 byte aligned
156 locations without converting them to doubles.
157 Since there is no know compiler that actually
158 follows the ABI here, we implement the GCC
159 convention. */
160
161 /* Align to 4 bytes or 8 bytes depending on the type of
162 the argument (float or double). */
163 argoffset = align_up (argoffset, len);
164 if (write_pass)
165 write_memory (sp + argoffset, val, len);
166 argoffset += len;
167 }
168 }
169 else if (type->code () == TYPE_CODE_FLT
170 && len == 16
171 && !tdep->soft_float
174 {
175 /* IBM long double passed in two FP registers if
176 available, otherwise 8-byte aligned stack. */
177 if (freg <= 7)
178 {
179 if (write_pass)
180 {
181 regcache->cooked_write (tdep->ppc_fp0_regnum + freg, val);
182 regcache->cooked_write (tdep->ppc_fp0_regnum + freg + 1,
183 val + 8);
184 }
185 freg += 2;
186 }
187 else
188 {
189 argoffset = align_up (argoffset, 8);
190 if (write_pass)
191 write_memory (sp + argoffset, val, len);
192 argoffset += 16;
193 }
194 }
195 else if (len == 8
196 && (type->code () == TYPE_CODE_INT /* long long */
197 || type->code () == TYPE_CODE_FLT /* double */
198 || (type->code () == TYPE_CODE_DECFLOAT
199 && tdep->soft_float)))
200 {
201 /* "long long" or soft-float "double" or "_Decimal64"
202 passed in an odd/even register pair with the low
203 addressed word in the odd register and the high
204 addressed word in the even register, or when the
205 registers run out an 8 byte aligned stack
206 location. */
207 if (greg > 9)
208 {
209 /* Just in case GREG was 10. */
210 greg = 11;
211 argoffset = align_up (argoffset, 8);
212 if (write_pass)
213 write_memory (sp + argoffset, val, len);
214 argoffset += 8;
215 }
216 else
217 {
218 /* Must start on an odd register - r3/r4 etc. */
219 if ((greg & 1) == 0)
220 greg++;
221 if (write_pass)
222 {
223 regcache->cooked_write (tdep->ppc_gp0_regnum + greg + 0,
224 val + 0);
225 regcache->cooked_write (tdep->ppc_gp0_regnum + greg + 1,
226 val + 4);
227 }
228 greg += 2;
229 }
230 }
231 else if (len == 16
232 && ((type->code () == TYPE_CODE_FLT
235 || (type->code () == TYPE_CODE_DECFLOAT
236 && tdep->soft_float)))
237 {
238 /* Soft-float IBM long double or _Decimal128 passed in
239 four consecutive registers, or on the stack. The
240 registers are not necessarily odd/even pairs. */
241 if (greg > 7)
242 {
243 greg = 11;
244 argoffset = align_up (argoffset, 8);
245 if (write_pass)
246 write_memory (sp + argoffset, val, len);
247 argoffset += 16;
248 }
249 else
250 {
251 if (write_pass)
252 {
253 regcache->cooked_write (tdep->ppc_gp0_regnum + greg + 0,
254 val + 0);
255 regcache->cooked_write (tdep->ppc_gp0_regnum + greg + 1,
256 val + 4);
257 regcache->cooked_write (tdep->ppc_gp0_regnum + greg + 2,
258 val + 8);
259 regcache->cooked_write (tdep->ppc_gp0_regnum + greg + 3,
260 val + 12);
261 }
262 greg += 4;
263 }
264 }
265 else if (type->code () == TYPE_CODE_DECFLOAT && len <= 8
266 && !tdep->soft_float)
267 {
268 /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can
269 end up in memory. */
270
271 if (freg <= 8)
272 {
273 if (write_pass)
274 {
275 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
276 const gdb_byte *p;
277
278 /* 32-bit decimal floats are right aligned in the
279 doubleword. */
280 if (type->length () == 4)
281 {
282 memcpy (regval + 4, val, 4);
283 p = regval;
284 }
285 else
286 p = val;
287
288 regcache->cooked_write (tdep->ppc_fp0_regnum + freg, p);
289 }
290
291 freg++;
292 }
293 else
294 {
295 argoffset = align_up (argoffset, len);
296
297 if (write_pass)
298 /* Write value in the stack's parameter save area. */
299 write_memory (sp + argoffset, val, len);
300
301 argoffset += len;
302 }
303 }
304 else if (type->code () == TYPE_CODE_DECFLOAT && len == 16
305 && !tdep->soft_float)
306 {
307 /* 128-bit decimal floats go in f2 .. f7, always in even/odd
308 pairs. They can end up in memory, using two doublewords. */
309
310 if (freg <= 6)
311 {
312 /* Make sure freg is even. */
313 freg += freg & 1;
314
315 if (write_pass)
316 {
317 regcache->cooked_write (tdep->ppc_fp0_regnum + freg, val);
318 regcache->cooked_write (tdep->ppc_fp0_regnum + freg + 1,
319 val + 8);
320 }
321 }
322 else
323 {
324 argoffset = align_up (argoffset, 8);
325
326 if (write_pass)
327 write_memory (sp + argoffset, val, 16);
328
329 argoffset += 16;
330 }
331
332 /* If a 128-bit decimal float goes to the stack because only f7
333 and f8 are free (thus there's no even/odd register pair
334 available), these registers should be marked as occupied.
335 Hence we increase freg even when writing to memory. */
336 freg += 2;
337 }
338 else if (len < 16
339 && type->code () == TYPE_CODE_ARRAY
340 && type->is_vector ()
341 && opencl_abi)
342 {
343 /* OpenCL vectors shorter than 16 bytes are passed as if
344 a series of independent scalars. */
345 struct type *eltype = check_typedef (type->target_type ());
346 int i, nelt = type->length () / eltype->length ();
347
348 for (i = 0; i < nelt; i++)
349 {
350 const gdb_byte *elval = val + i * eltype->length ();
351
352 if (eltype->code () == TYPE_CODE_FLT && !tdep->soft_float)
353 {
354 if (freg <= 8)
355 {
356 if (write_pass)
357 {
358 int regnum = tdep->ppc_fp0_regnum + freg;
359 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
360 struct type *regtype
362 target_float_convert (elval, eltype,
363 regval, regtype);
364 regcache->cooked_write (regnum, regval);
365 }
366 freg++;
367 }
368 else
369 {
370 argoffset = align_up (argoffset, len);
371 if (write_pass)
372 write_memory (sp + argoffset, val, len);
373 argoffset += len;
374 }
375 }
376 else if (eltype->length () == 8)
377 {
378 if (greg > 9)
379 {
380 /* Just in case GREG was 10. */
381 greg = 11;
382 argoffset = align_up (argoffset, 8);
383 if (write_pass)
384 write_memory (sp + argoffset, elval,
385 eltype->length ());
386 argoffset += 8;
387 }
388 else
389 {
390 /* Must start on an odd register - r3/r4 etc. */
391 if ((greg & 1) == 0)
392 greg++;
393 if (write_pass)
394 {
395 int regnum = tdep->ppc_gp0_regnum + greg;
396 regcache->cooked_write (regnum + 0, elval + 0);
397 regcache->cooked_write (regnum + 1, elval + 4);
398 }
399 greg += 2;
400 }
401 }
402 else
403 {
404 gdb_byte word[PPC_MAX_REGISTER_SIZE];
405 store_unsigned_integer (word, tdep->wordsize, byte_order,
406 unpack_long (eltype, elval));
407
408 if (greg <= 10)
409 {
410 if (write_pass)
411 regcache->cooked_write (tdep->ppc_gp0_regnum + greg,
412 word);
413 greg++;
414 }
415 else
416 {
417 argoffset = align_up (argoffset, tdep->wordsize);
418 if (write_pass)
419 write_memory (sp + argoffset, word, tdep->wordsize);
420 argoffset += tdep->wordsize;
421 }
422 }
423 }
424 }
425 else if (len >= 16
426 && type->code () == TYPE_CODE_ARRAY
427 && type->is_vector ()
428 && opencl_abi)
429 {
430 /* OpenCL vectors 16 bytes or longer are passed as if
431 a series of AltiVec vectors. */
432 int i;
433
434 for (i = 0; i < len / 16; i++)
435 {
436 const gdb_byte *elval = val + i * 16;
437
438 if (vreg <= 13)
439 {
440 if (write_pass)
441 regcache->cooked_write (tdep->ppc_vr0_regnum + vreg,
442 elval);
443 vreg++;
444 }
445 else
446 {
447 argoffset = align_up (argoffset, 16);
448 if (write_pass)
449 write_memory (sp + argoffset, elval, 16);
450 argoffset += 16;
451 }
452 }
453 }
454 else if (len == 16
455 && ((type->code () == TYPE_CODE_ARRAY
456 && type->is_vector ()
457 && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
458 || (type->code () == TYPE_CODE_FLT
461 {
462 /* Vector parameter passed in an Altivec register, or
463 when that runs out, 16 byte aligned stack location.
464 IEEE FLOAT 128-bit also passes parameters in vector
465 registers. */
466 if (vreg <= 13)
467 {
468 if (write_pass)
469 regcache->cooked_write (tdep->ppc_vr0_regnum + vreg, val);
470 vreg++;
471 }
472 else
473 {
474 argoffset = align_up (argoffset, 16);
475 if (write_pass)
476 write_memory (sp + argoffset, val, 16);
477 argoffset += 16;
478 }
479 }
480 else if (len == 8
481 && type->code () == TYPE_CODE_ARRAY
482 && type->is_vector ()
483 && tdep->vector_abi == POWERPC_VEC_SPE)
484 {
485 /* Vector parameter passed in an e500 register, or when
486 that runs out, 8 byte aligned stack location. Note
487 that since e500 vector and general purpose registers
488 both map onto the same underlying register set, a
489 "greg" and not a "vreg" is consumed here. A cooked
490 write stores the value in the correct locations
491 within the raw register cache. */
492 if (greg <= 10)
493 {
494 if (write_pass)
495 regcache->cooked_write (tdep->ppc_ev0_regnum + greg, val);
496 greg++;
497 }
498 else
499 {
500 argoffset = align_up (argoffset, 8);
501 if (write_pass)
502 write_memory (sp + argoffset, val, 8);
503 argoffset += 8;
504 }
505 }
506 else
507 {
508 /* Reduce the parameter down to something that fits in a
509 "word". */
510 gdb_byte word[PPC_MAX_REGISTER_SIZE];
511 memset (word, 0, PPC_MAX_REGISTER_SIZE);
512 if (len > tdep->wordsize
513 || type->code () == TYPE_CODE_STRUCT
514 || type->code () == TYPE_CODE_UNION)
515 {
516 /* Structs and large values are put in an
517 aligned stack slot ... */
518 if (type->code () == TYPE_CODE_ARRAY
519 && type->is_vector ()
520 && len >= 16)
521 structoffset = align_up (structoffset, 16);
522 else
523 structoffset = align_up (structoffset, 8);
524
525 if (write_pass)
526 write_memory (sp + structoffset, val, len);
527 /* ... and then a "word" pointing to that address is
528 passed as the parameter. */
529 store_unsigned_integer (word, tdep->wordsize, byte_order,
530 sp + structoffset);
531 structoffset += len;
532 }
533 else if (type->code () == TYPE_CODE_INT)
534 /* Sign or zero extend the "int" into a "word". */
535 store_unsigned_integer (word, tdep->wordsize, byte_order,
536 unpack_long (type, val));
537 else
538 /* Always goes in the low address. */
539 memcpy (word, val, len);
540 /* Store that "word" in a register, or on the stack.
541 The words have "4" byte alignment. */
542 if (greg <= 10)
543 {
544 if (write_pass)
545 regcache->cooked_write (tdep->ppc_gp0_regnum + greg, word);
546 greg++;
547 }
548 else
549 {
550 argoffset = align_up (argoffset, tdep->wordsize);
551 if (write_pass)
552 write_memory (sp + argoffset, word, tdep->wordsize);
553 argoffset += tdep->wordsize;
554 }
555 }
556 }
557
558 /* Compute the actual stack space requirements. */
559 if (!write_pass)
560 {
561 /* Remember the amount of space needed by the arguments. */
562 argspace = argoffset;
563 /* Allocate space for both the arguments and the structures. */
564 sp -= (argoffset + structoffset);
565 /* Ensure that the stack is still 16 byte aligned. */
566 sp = align_down (sp, 16);
567 }
568
569 /* The psABI says that "A caller of a function that takes a
570 variable argument list shall set condition register bit 6 to
571 1 if it passes one or more arguments in the floating-point
572 registers. It is strongly recommended that the caller set the
573 bit to 0 otherwise..." Doing this for normal functions too
574 shouldn't hurt. */
575 if (write_pass)
576 {
577 ULONGEST cr;
578
580 if (freg > 1)
581 cr |= 0x02000000;
582 else
583 cr &= ~0x02000000;
585 }
586 }
587
588 /* Update %sp. */
590
591 /* Write the backchain (it occupies WORDSIZED bytes). */
592 write_memory_signed_integer (sp, tdep->wordsize, byte_order, saved_sp);
593
594 /* Point the inferior function call's return address at the dummy's
595 breakpoint. */
597
598 return sp;
599}
600
601/* Handle the return-value conventions for Decimal Floating Point values. */
602static enum return_value_convention
604 struct regcache *regcache, gdb_byte *readbuf,
605 const gdb_byte *writebuf)
606{
607 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
608
609 gdb_assert (valtype->code () == TYPE_CODE_DECFLOAT);
610
611 /* 32-bit and 64-bit decimal floats in f1. */
612 if (valtype->length () <= 8)
613 {
614 if (writebuf != NULL)
615 {
616 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
617 const gdb_byte *p;
618
619 /* 32-bit decimal float is right aligned in the doubleword. */
620 if (valtype->length () == 4)
621 {
622 memcpy (regval + 4, writebuf, 4);
623 p = regval;
624 }
625 else
626 p = writebuf;
627
628 regcache->cooked_write (tdep->ppc_fp0_regnum + 1, p);
629 }
630 if (readbuf != NULL)
631 {
632 regcache->cooked_read (tdep->ppc_fp0_regnum + 1, readbuf);
633
634 /* Left align 32-bit decimal float. */
635 if (valtype->length () == 4)
636 memcpy (readbuf, readbuf + 4, 4);
637 }
638 }
639 /* 128-bit decimal floats in f2,f3. */
640 else if (valtype->length () == 16)
641 {
642 if (writebuf != NULL || readbuf != NULL)
643 {
644 int i;
645
646 for (i = 0; i < 2; i++)
647 {
648 if (writebuf != NULL)
649 regcache->cooked_write (tdep->ppc_fp0_regnum + 2 + i,
650 writebuf + i * 8);
651 if (readbuf != NULL)
652 regcache->cooked_read (tdep->ppc_fp0_regnum + 2 + i,
653 readbuf + i * 8);
654 }
655 }
656 }
657 else
658 /* Can't happen. */
659 internal_error (_("Unknown decimal float size."));
660
662}
663
664/* Handle the return-value conventions specified by the SysV 32-bit
665 PowerPC ABI (including all the supplements):
666
667 no floating-point: floating-point values returned using 32-bit
668 general-purpose registers.
669
670 Altivec: 128-bit vectors returned using vector registers.
671
672 e500: 64-bit vectors returned using the full full 64 bit EV
673 register, floating-point values returned using 32-bit
674 general-purpose registers.
675
676 GCC (broken): Small struct values right (instead of left) aligned
677 when returned in general-purpose registers. */
678
679static enum return_value_convention
681 struct type *type, struct regcache *regcache,
682 gdb_byte *readbuf, const gdb_byte *writebuf,
683 int broken_gcc)
684{
685 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
686 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
687 int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
688
689 gdb_assert (tdep->wordsize == 4);
690
691 if (type->code () == TYPE_CODE_FLT
692 && type->length () <= 8
693 && !tdep->soft_float)
694 {
695 if (readbuf)
696 {
697 /* Floats and doubles stored in "f1". Convert the value to
698 the required type. */
699 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
700 struct type *regtype = register_type (gdbarch,
701 tdep->ppc_fp0_regnum + 1);
702 regcache->cooked_read (tdep->ppc_fp0_regnum + 1, regval);
703 target_float_convert (regval, regtype, readbuf, type);
704 }
705 if (writebuf)
706 {
707 /* Floats and doubles stored in "f1". Convert the value to
708 the register's "double" type. */
709 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
710 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
711 target_float_convert (writebuf, type, regval, regtype);
712 regcache->cooked_write (tdep->ppc_fp0_regnum + 1, regval);
713 }
715 }
716 if (type->code () == TYPE_CODE_FLT
717 && type->length () == 16
718 && !tdep->soft_float
721 {
722 /* IBM long double stored in f1 and f2. */
723 if (readbuf)
724 {
725 regcache->cooked_read (tdep->ppc_fp0_regnum + 1, readbuf);
726 regcache->cooked_read (tdep->ppc_fp0_regnum + 2, readbuf + 8);
727 }
728 if (writebuf)
729 {
730 regcache->cooked_write (tdep->ppc_fp0_regnum + 1, writebuf);
731 regcache->cooked_write (tdep->ppc_fp0_regnum + 2, writebuf + 8);
732 }
734 }
735 if (type->length () == 16
736 && ((type->code () == TYPE_CODE_FLT
739 || (type->code () == TYPE_CODE_DECFLOAT && tdep->soft_float)))
740 {
741 /* Soft-float IBM long double or _Decimal128 stored in r3, r4,
742 r5, r6. */
743 if (readbuf)
744 {
745 regcache->cooked_read (tdep->ppc_gp0_regnum + 3, readbuf);
746 regcache->cooked_read (tdep->ppc_gp0_regnum + 4, readbuf + 4);
747 regcache->cooked_read (tdep->ppc_gp0_regnum + 5, readbuf + 8);
748 regcache->cooked_read (tdep->ppc_gp0_regnum + 6, readbuf + 12);
749 }
750 if (writebuf)
751 {
752 regcache->cooked_write (tdep->ppc_gp0_regnum + 3, writebuf);
753 regcache->cooked_write (tdep->ppc_gp0_regnum + 4, writebuf + 4);
754 regcache->cooked_write (tdep->ppc_gp0_regnum + 5, writebuf + 8);
755 regcache->cooked_write (tdep->ppc_gp0_regnum + 6, writebuf + 12);
756 }
758 }
759 if ((type->code () == TYPE_CODE_INT && type->length () == 8)
760 || (type->code () == TYPE_CODE_FLT && type->length () == 8)
761 || (type->code () == TYPE_CODE_DECFLOAT && type->length () == 8
762 && tdep->soft_float))
763 {
764 if (readbuf)
765 {
766 /* A long long, double or _Decimal64 stored in the 32 bit
767 r3/r4. */
768 regcache->cooked_read (tdep->ppc_gp0_regnum + 3, readbuf + 0);
769 regcache->cooked_read (tdep->ppc_gp0_regnum + 4, readbuf + 4);
770 }
771 if (writebuf)
772 {
773 /* A long long, double or _Decimal64 stored in the 32 bit
774 r3/r4. */
775 regcache->cooked_write (tdep->ppc_gp0_regnum + 3, writebuf + 0);
776 regcache->cooked_write (tdep->ppc_gp0_regnum + 4, writebuf + 4);
777 }
779 }
780 if (type->code () == TYPE_CODE_DECFLOAT && !tdep->soft_float)
782 writebuf);
783 else if ((type->code () == TYPE_CODE_INT
784 || type->code () == TYPE_CODE_CHAR
785 || type->code () == TYPE_CODE_BOOL
786 || type->code () == TYPE_CODE_PTR
788 || type->code () == TYPE_CODE_ENUM)
789 && type->length () <= tdep->wordsize)
790 {
791 if (readbuf)
792 {
793 /* Some sort of integer stored in r3. Since TYPE isn't
794 bigger than the register, sign extension isn't a problem
795 - just do everything unsigned. */
796 ULONGEST regval;
798 &regval);
799 store_unsigned_integer (readbuf, type->length (), byte_order,
800 regval);
801 }
802 if (writebuf)
803 {
804 /* Some sort of integer stored in r3. Use unpack_long since
805 that should handle any required sign extension. */
807 unpack_long (type, writebuf));
808 }
810 }
811 /* OpenCL vectors < 16 bytes are returned as distinct
812 scalars in f1..f2 or r3..r10. */
813 if (type->code () == TYPE_CODE_ARRAY
814 && type->is_vector ()
815 && type->length () < 16
816 && opencl_abi)
817 {
818 struct type *eltype = check_typedef (type->target_type ());
819 int i, nelt = type->length () / eltype->length ();
820
821 for (i = 0; i < nelt; i++)
822 {
823 int offset = i * eltype->length ();
824
825 if (eltype->code () == TYPE_CODE_FLT)
826 {
827 int regnum = tdep->ppc_fp0_regnum + 1 + i;
828 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
829 struct type *regtype = register_type (gdbarch, regnum);
830
831 if (writebuf != NULL)
832 {
833 target_float_convert (writebuf + offset, eltype,
834 regval, regtype);
835 regcache->cooked_write (regnum, regval);
836 }
837 if (readbuf != NULL)
838 {
839 regcache->cooked_read (regnum, regval);
840 target_float_convert (regval, regtype,
841 readbuf + offset, eltype);
842 }
843 }
844 else
845 {
846 int regnum = tdep->ppc_gp0_regnum + 3 + i;
847 ULONGEST regval;
848
849 if (writebuf != NULL)
850 {
851 regval = unpack_long (eltype, writebuf + offset);
853 }
854 if (readbuf != NULL)
855 {
857 store_unsigned_integer (readbuf + offset,
858 eltype->length (), byte_order,
859 regval);
860 }
861 }
862 }
863
865 }
866 /* OpenCL vectors >= 16 bytes are returned in v2..v9. */
867 if (type->code () == TYPE_CODE_ARRAY
868 && type->is_vector ()
869 && type->length () >= 16
870 && opencl_abi)
871 {
872 int n_regs = type->length () / 16;
873 int i;
874
875 for (i = 0; i < n_regs; i++)
876 {
877 int offset = i * 16;
878 int regnum = tdep->ppc_vr0_regnum + 2 + i;
879
880 if (writebuf != NULL)
881 regcache->cooked_write (regnum, writebuf + offset);
882 if (readbuf != NULL)
883 regcache->cooked_read (regnum, readbuf + offset);
884 }
885
887 }
888 if (type->length () == 16
889 && type->code () == TYPE_CODE_ARRAY
890 && type->is_vector ()
891 && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
892 {
893 if (readbuf)
894 {
895 /* Altivec places the return value in "v2". */
896 regcache->cooked_read (tdep->ppc_vr0_regnum + 2, readbuf);
897 }
898 if (writebuf)
899 {
900 /* Altivec places the return value in "v2". */
901 regcache->cooked_write (tdep->ppc_vr0_regnum + 2, writebuf);
902 }
904 }
905 if (type->length () == 16
906 && type->code () == TYPE_CODE_ARRAY
907 && type->is_vector ()
908 && tdep->vector_abi == POWERPC_VEC_GENERIC)
909 {
910 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
911 GCC without AltiVec returns them in memory, but it warns about
912 ABI risks in that case; we don't try to support it. */
913 if (readbuf)
914 {
915 regcache->cooked_read (tdep->ppc_gp0_regnum + 3, readbuf + 0);
916 regcache->cooked_read (tdep->ppc_gp0_regnum + 4, readbuf + 4);
917 regcache->cooked_read (tdep->ppc_gp0_regnum + 5, readbuf + 8);
918 regcache->cooked_read (tdep->ppc_gp0_regnum + 6, readbuf + 12);
919 }
920 if (writebuf)
921 {
922 regcache->cooked_write (tdep->ppc_gp0_regnum + 3, writebuf + 0);
923 regcache->cooked_write (tdep->ppc_gp0_regnum + 4, writebuf + 4);
924 regcache->cooked_write (tdep->ppc_gp0_regnum + 5, writebuf + 8);
925 regcache->cooked_write (tdep->ppc_gp0_regnum + 6, writebuf + 12);
926 }
928 }
929 if (type->length () == 8
930 && type->code () == TYPE_CODE_ARRAY
931 && type->is_vector ()
932 && tdep->vector_abi == POWERPC_VEC_SPE)
933 {
934 /* The e500 ABI places return values for the 64-bit DSP types
935 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
936 corresponds to the entire r3 value for e500, whereas GDB's r3
937 only corresponds to the least significant 32-bits. So place
938 the 64-bit DSP type's value in ev3. */
939 if (readbuf)
940 regcache->cooked_read (tdep->ppc_ev0_regnum + 3, readbuf);
941 if (writebuf)
942 regcache->cooked_write (tdep->ppc_ev0_regnum + 3, writebuf);
944 }
945 if (broken_gcc && type->length () <= 8)
946 {
947 /* GCC screwed up for structures or unions whose size is less
948 than or equal to 8 bytes.. Instead of left-aligning, it
949 right-aligns the data into the buffer formed by r3, r4. */
950 gdb_byte regvals[PPC_MAX_REGISTER_SIZE * 2];
951 int len = type->length ();
952 int offset = (2 * tdep->wordsize - len) % tdep->wordsize;
953
954 if (readbuf)
955 {
957 regvals + 0 * tdep->wordsize);
958 if (len > tdep->wordsize)
960 regvals + 1 * tdep->wordsize);
961 memcpy (readbuf, regvals + offset, len);
962 }
963 if (writebuf)
964 {
965 memset (regvals, 0, sizeof regvals);
966 memcpy (regvals + offset, writebuf, len);
968 regvals + 0 * tdep->wordsize);
969 if (len > tdep->wordsize)
971 regvals + 1 * tdep->wordsize);
972 }
973
975 }
976 if (type->length () <= 8)
977 {
978 if (readbuf)
979 {
980 /* This matches SVr4 PPC, it does not match GCC. */
981 /* The value is right-padded to 8 bytes and then loaded, as
982 two "words", into r3/r4. */
983 gdb_byte regvals[PPC_MAX_REGISTER_SIZE * 2];
985 regvals + 0 * tdep->wordsize);
986 if (type->length () > tdep->wordsize)
988 regvals + 1 * tdep->wordsize);
989 memcpy (readbuf, regvals, type->length ());
990 }
991 if (writebuf)
992 {
993 /* This matches SVr4 PPC, it does not match GCC. */
994 /* The value is padded out to 8 bytes and then loaded, as
995 two "words" into r3/r4. */
996 gdb_byte regvals[PPC_MAX_REGISTER_SIZE * 2];
997 memset (regvals, 0, sizeof regvals);
998 memcpy (regvals, writebuf, type->length ());
1000 regvals + 0 * tdep->wordsize);
1001 if (type->length () > tdep->wordsize)
1003 regvals + 1 * tdep->wordsize);
1004 }
1006 }
1008}
1009
1012 struct type *valtype, struct regcache *regcache,
1013 gdb_byte *readbuf, const gdb_byte *writebuf)
1014{
1016 function ? function->type () : NULL,
1017 valtype, regcache, readbuf, writebuf, 0);
1018}
1019
1022 struct value *function,
1023 struct type *valtype,
1024 struct regcache *regcache,
1025 gdb_byte *readbuf, const gdb_byte *writebuf)
1026{
1028 function ? function->type () : NULL,
1029 valtype, regcache, readbuf, writebuf, 1);
1030}
1031
1032/* The helper function for 64-bit SYSV push_dummy_call. Converts the
1033 function's code address back into the function's descriptor
1034 address.
1035
1036 Find a value for the TOC register. Every symbol should have both
1037 ".FN" and "FN" in the minimal symbol table. "FN" points at the
1038 FN's descriptor, while ".FN" points at the entry point (which
1039 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
1040 FN's descriptor address (while at the same time being careful to
1041 find "FN" in the same object file as ".FN"). */
1042
1043static int
1044convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr)
1045{
1046 struct obj_section *dot_fn_section;
1047 struct bound_minimal_symbol dot_fn;
1048 struct bound_minimal_symbol fn;
1049
1050 /* Find the minimal symbol that corresponds to CODE_ADDR (should
1051 have a name of the form ".FN"). */
1052 dot_fn = lookup_minimal_symbol_by_pc (code_addr);
1053 if (dot_fn.minsym == NULL || dot_fn.minsym->linkage_name ()[0] != '.')
1054 return 0;
1055 /* Get the section that contains CODE_ADDR. Need this for the
1056 "objfile" that it contains. */
1057 dot_fn_section = find_pc_section (code_addr);
1058 if (dot_fn_section == NULL || dot_fn_section->objfile == NULL)
1059 return 0;
1060 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
1061 address. Only look for the minimal symbol in ".FN"'s object file
1062 - avoids problems when two object files (i.e., shared libraries)
1063 contain a minimal symbol with the same name. */
1064 fn = lookup_minimal_symbol (dot_fn.minsym->linkage_name () + 1, NULL,
1065 dot_fn_section->objfile);
1066 if (fn.minsym == NULL)
1067 return 0;
1068 /* Found a descriptor. */
1069 (*desc_addr) = fn.value_address ();
1070 return 1;
1071}
1072
1073/* Walk down the type tree of TYPE counting consecutive base elements.
1074 If *FIELD_TYPE is NULL, then set it to the first valid floating point
1075 or vector type. If a non-floating point or vector type is found, or
1076 if a floating point or vector type that doesn't match a non-NULL
1077 *FIELD_TYPE is found, then return -1, otherwise return the count in the
1078 sub-tree. */
1079
1080static LONGEST
1082 struct type **field_type)
1083{
1085
1086 switch (type->code ())
1087 {
1088 case TYPE_CODE_FLT:
1089 case TYPE_CODE_DECFLOAT:
1090 if (!*field_type)
1091 *field_type = type;
1092 if ((*field_type)->code () == type->code ()
1093 && (*field_type)->length () == type->length ())
1094 return 1;
1095 break;
1096
1097 case TYPE_CODE_COMPLEX:
1098 type = type->target_type ();
1099 if (type->code () == TYPE_CODE_FLT
1100 || type->code () == TYPE_CODE_DECFLOAT)
1101 {
1102 if (!*field_type)
1103 *field_type = type;
1104 if ((*field_type)->code () == type->code ()
1105 && (*field_type)->length () == type->length ())
1106 return 2;
1107 }
1108 break;
1109
1110 case TYPE_CODE_ARRAY:
1111 if (type->is_vector ())
1112 {
1113 if (!*field_type)
1114 *field_type = type;
1115 if ((*field_type)->code () == type->code ()
1116 && (*field_type)->length () == type->length ())
1117 return 1;
1118 }
1119 else
1120 {
1121 LONGEST count, low_bound, high_bound;
1122
1124 (type->target_type (), field_type);
1125 if (count == -1)
1126 return -1;
1127
1128 if (!get_array_bounds (type, &low_bound, &high_bound))
1129 return -1;
1130 count *= high_bound - low_bound;
1131
1132 /* There must be no padding. */
1133 if (count == 0)
1134 return type->length () == 0 ? 0 : -1;
1135 else if (type->length () != count * (*field_type)->length ())
1136 return -1;
1137
1138 return count;
1139 }
1140 break;
1141
1142 case TYPE_CODE_STRUCT:
1143 case TYPE_CODE_UNION:
1144 {
1145 LONGEST count = 0;
1146 int i;
1147
1148 for (i = 0; i < type->num_fields (); i++)
1149 {
1150 LONGEST sub_count;
1151
1152 if (type->field (i).is_static ())
1153 continue;
1154
1155 sub_count = ppc64_aggregate_candidate
1156 (type->field (i).type (), field_type);
1157 if (sub_count == -1)
1158 return -1;
1159
1160 if (type->code () == TYPE_CODE_STRUCT)
1161 count += sub_count;
1162 else
1163 count = std::max (count, sub_count);
1164 }
1165
1166 /* There must be no padding. */
1167 if (count == 0)
1168 return type->length () == 0 ? 0 : -1;
1169 else if (type->length () != count * (*field_type)->length ())
1170 return -1;
1171
1172 return count;
1173 }
1174 break;
1175
1176 default:
1177 break;
1178 }
1179
1180 return -1;
1181}
1182
1183/* If an argument of type TYPE is a homogeneous float or vector aggregate
1184 that shall be passed in FP/vector registers according to the ELFv2 ABI,
1185 return the homogeneous element type in *ELT_TYPE and the number of
1186 elements in *N_ELTS, and return non-zero. Otherwise, return zero. */
1187
1188static int
1190 struct type **elt_type, int *n_elts,
1191 struct gdbarch *gdbarch)
1192{
1193 /* Complex types at the top level are treated separately. However,
1194 complex types can be elements of homogeneous aggregates. */
1195 if (type->code () == TYPE_CODE_STRUCT
1196 || type->code () == TYPE_CODE_UNION
1197 || (type->code () == TYPE_CODE_ARRAY && !type->is_vector ()))
1198 {
1199 struct type *field_type = NULL;
1200 LONGEST field_count = ppc64_aggregate_candidate (type, &field_type);
1201
1202 if (field_count > 0)
1203 {
1204 int n_regs;
1205
1206 if (field_type->code () == TYPE_CODE_FLT
1209 /* IEEE Float 128-bit uses one vector register. */
1210 n_regs = 1;
1211
1212 else if (field_type->code () == TYPE_CODE_FLT
1213 || field_type->code () == TYPE_CODE_DECFLOAT)
1214 n_regs = (field_type->length () + 7) >> 3;
1215
1216 else
1217 n_regs = 1;
1218
1219 /* The ELFv2 ABI allows homogeneous aggregates to occupy
1220 up to 8 registers. */
1221 if (field_count * n_regs <= 8)
1222 {
1223 if (elt_type)
1224 *elt_type = field_type;
1225 if (n_elts)
1226 *n_elts = (int) field_count;
1227 /* Note that field_count is LONGEST since it may hold the size
1228 of an array, while *n_elts is int since its value is bounded
1229 by the number of registers used for argument passing. The
1230 cast cannot overflow due to the bounds checking above. */
1231 return 1;
1232 }
1233 }
1234 }
1235
1236 return 0;
1237}
1238
1239/* Structure holding the next argument position. */
1241 {
1242 /* Register cache holding argument registers. If this is NULL,
1243 we only simulate argument processing without actually updating
1244 any registers or memory. */
1246 /* Next available general-purpose argument register. */
1247 int greg;
1248 /* Next available floating-point argument register. */
1249 int freg;
1250 /* Next available vector argument register. */
1251 int vreg;
1252 /* The address, at which the next general purpose parameter
1253 (integer, struct, float, vector, ...) should be saved. */
1254 CORE_ADDR gparam;
1255 /* The address, at which the next by-reference parameter
1256 (non-Altivec vector, variably-sized type) should be saved. */
1257 CORE_ADDR refparam;
1258 };
1259
1260/* VAL is a value of length LEN. Store it into the argument area on the
1261 stack and load it into the corresponding general-purpose registers
1262 required by the ABI, and update ARGPOS.
1263
1264 If ALIGN is nonzero, it specifies the minimum alignment required
1265 for the on-stack copy of the argument. */
1266
1267static void
1269 const bfd_byte *val, int len, int align,
1270 struct ppc64_sysv_argpos *argpos)
1271{
1272 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1273 int offset = 0;
1274
1275 /* Enforce alignment of stack location, if requested. */
1276 if (align > tdep->wordsize)
1277 {
1278 CORE_ADDR aligned_gparam = align_up (argpos->gparam, align);
1279
1280 argpos->greg += (aligned_gparam - argpos->gparam) / tdep->wordsize;
1281 argpos->gparam = aligned_gparam;
1282 }
1283
1284 /* The ABI (version 1.9) specifies that values smaller than one
1285 doubleword are right-aligned and those larger are left-aligned.
1286 GCC versions before 3.4 implemented this incorrectly; see
1287 <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */
1288 if (len < tdep->wordsize
1289 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1290 offset = tdep->wordsize - len;
1291
1292 if (argpos->regcache)
1293 write_memory (argpos->gparam + offset, val, len);
1294 argpos->gparam = align_up (argpos->gparam + len, tdep->wordsize);
1295
1296 while (len >= tdep->wordsize)
1297 {
1298 if (argpos->regcache && argpos->greg <= 10)
1299 argpos->regcache->cooked_write (tdep->ppc_gp0_regnum + argpos->greg,
1300 val);
1301 argpos->greg++;
1302 len -= tdep->wordsize;
1303 val += tdep->wordsize;
1304 }
1305
1306 if (len > 0)
1307 {
1308 if (argpos->regcache && argpos->greg <= 10)
1310 (tdep->ppc_gp0_regnum + argpos->greg, offset, len, val);
1311 argpos->greg++;
1312 }
1313}
1314
1315/* The same as ppc64_sysv_abi_push_val, but using a single-word integer
1316 value VAL as argument. */
1317
1318static void
1320 struct ppc64_sysv_argpos *argpos)
1321{
1322 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1323 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1324 gdb_byte buf[PPC_MAX_REGISTER_SIZE];
1325
1326 if (argpos->regcache)
1327 store_unsigned_integer (buf, tdep->wordsize, byte_order, val);
1328 ppc64_sysv_abi_push_val (gdbarch, buf, tdep->wordsize, 0, argpos);
1329}
1330
1331/* VAL is a value of TYPE, a (binary or decimal) floating-point type.
1332 Load it into a floating-point register if required by the ABI,
1333 and update ARGPOS. */
1334
1335static void
1337 struct type *type, const bfd_byte *val,
1338 struct ppc64_sysv_argpos *argpos)
1339{
1340 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1341 if (tdep->soft_float)
1342 return;
1343
1344 if (type->length () <= 8
1345 && type->code () == TYPE_CODE_FLT)
1346 {
1347 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1348 to double first. */
1349 if (argpos->regcache && argpos->freg <= 13)
1350 {
1351 int regnum = tdep->ppc_fp0_regnum + argpos->freg;
1352 struct type *regtype = register_type (gdbarch, regnum);
1353 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
1354
1355 target_float_convert (val, type, regval, regtype);
1356 argpos->regcache->cooked_write (regnum, regval);
1357 }
1358
1359 argpos->freg++;
1360 }
1361 else if (type->length () <= 8
1362 && type->code () == TYPE_CODE_DECFLOAT)
1363 {
1364 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1365 placed in the least significant word. */
1366 if (argpos->regcache && argpos->freg <= 13)
1367 {
1368 int regnum = tdep->ppc_fp0_regnum + argpos->freg;
1369 int offset = 0;
1370
1371 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1372 offset = 8 - type->length ();
1373
1374 argpos->regcache->cooked_write_part (regnum, offset,
1375 type->length (), val);
1376 }
1377
1378 argpos->freg++;
1379 }
1380 else if (type->length () == 16
1381 && type->code () == TYPE_CODE_FLT
1384 {
1385 /* IBM long double stored in two consecutive FPRs. */
1386 if (argpos->regcache && argpos->freg <= 13)
1387 {
1388 int regnum = tdep->ppc_fp0_regnum + argpos->freg;
1389
1390 argpos->regcache->cooked_write (regnum, val);
1391 if (argpos->freg <= 12)
1392 argpos->regcache->cooked_write (regnum + 1, val + 8);
1393 }
1394
1395 argpos->freg += 2;
1396 }
1397 else if (type->length () == 16
1398 && type->code () == TYPE_CODE_DECFLOAT)
1399 {
1400 /* 128-bit decimal floating-point values are stored in and even/odd
1401 pair of FPRs, with the even FPR holding the most significant half. */
1402 argpos->freg += argpos->freg & 1;
1403
1404 if (argpos->regcache && argpos->freg <= 12)
1405 {
1406 int regnum = tdep->ppc_fp0_regnum + argpos->freg;
1407 int lopart = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 8 : 0;
1408 int hipart = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
1409
1410 argpos->regcache->cooked_write (regnum, val + hipart);
1411 argpos->regcache->cooked_write (regnum + 1, val + lopart);
1412 }
1413
1414 argpos->freg += 2;
1415 }
1416}
1417
1418/* VAL is a value of AltiVec vector type. Load it into a vector register
1419 if required by the ABI, and update ARGPOS. */
1420
1421static void
1422ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val,
1423 struct ppc64_sysv_argpos *argpos)
1424{
1425 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1426
1427 if (argpos->regcache && argpos->vreg <= 13)
1428 argpos->regcache->cooked_write (tdep->ppc_vr0_regnum + argpos->vreg, val);
1429
1430 argpos->vreg++;
1431}
1432
1433/* VAL is a value of TYPE. Load it into memory and/or registers
1434 as required by the ABI, and update ARGPOS. */
1435
1436static void
1438 struct type *type, const bfd_byte *val,
1439 struct ppc64_sysv_argpos *argpos)
1440{
1441 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1442
1443 if (type->code () == TYPE_CODE_FLT
1444 && type->length () == 16
1447 {
1448 /* IEEE FLOAT128, args in vector registers. */
1449 ppc64_sysv_abi_push_val (gdbarch, val, type->length (), 16, argpos);
1450 ppc64_sysv_abi_push_vreg (gdbarch, val, argpos);
1451 }
1452 else if (type->code () == TYPE_CODE_FLT
1453 || type->code () == TYPE_CODE_DECFLOAT)
1454 {
1455 /* Floating-point scalars are passed in floating-point registers. */
1456 ppc64_sysv_abi_push_val (gdbarch, val, type->length (), 0, argpos);
1457 ppc64_sysv_abi_push_freg (gdbarch, type, val, argpos);
1458 }
1459 else if (type->code () == TYPE_CODE_ARRAY && type->is_vector ()
1460 && tdep->vector_abi == POWERPC_VEC_ALTIVEC
1461 && type->length () == 16)
1462 {
1463 /* AltiVec vectors are passed aligned, and in vector registers. */
1464 ppc64_sysv_abi_push_val (gdbarch, val, type->length (), 16, argpos);
1465 ppc64_sysv_abi_push_vreg (gdbarch, val, argpos);
1466 }
1467 else if (type->code () == TYPE_CODE_ARRAY && type->is_vector ()
1468 && type->length () >= 16)
1469 {
1470 /* Non-Altivec vectors are passed by reference. */
1471
1472 /* Copy value onto the stack ... */
1473 CORE_ADDR addr = align_up (argpos->refparam, 16);
1474 if (argpos->regcache)
1475 write_memory (addr, val, type->length ());
1476 argpos->refparam = align_up (addr + type->length (), tdep->wordsize);
1477
1478 /* ... and pass a pointer to the copy as parameter. */
1479 ppc64_sysv_abi_push_integer (gdbarch, addr, argpos);
1480 }
1481 else if ((type->code () == TYPE_CODE_INT
1482 || type->code () == TYPE_CODE_ENUM
1483 || type->code () == TYPE_CODE_BOOL
1484 || type->code () == TYPE_CODE_CHAR
1485 || type->code () == TYPE_CODE_PTR
1487 && type->length () <= tdep->wordsize)
1488 {
1489 ULONGEST word = 0;
1490
1491 if (argpos->regcache)
1492 {
1493 /* Sign extend the value, then store it unsigned. */
1494 word = unpack_long (type, val);
1495
1496 /* Convert any function code addresses into descriptors. */
1497 if (tdep->elf_abi == POWERPC_ELF_V1
1498 && (type->code () == TYPE_CODE_PTR
1499 || type->code () == TYPE_CODE_REF))
1500 {
1501 struct type *target_type
1503
1504 if (target_type->code () == TYPE_CODE_FUNC
1505 || target_type->code () == TYPE_CODE_METHOD)
1506 {
1507 CORE_ADDR desc = word;
1508
1509 convert_code_addr_to_desc_addr (word, &desc);
1510 word = desc;
1511 }
1512 }
1513 }
1514
1515 ppc64_sysv_abi_push_integer (gdbarch, word, argpos);
1516 }
1517 else
1518 {
1519 /* Align == 0 is correct for ppc64_sysv_abi_push_freg,
1520 Align == 16 is correct for ppc64_sysv_abi_push_vreg.
1521 Default to 0. */
1522 int align = 0;
1523
1524 /* The ABI (version 1.9) specifies that structs containing a
1525 single floating-point value, at any level of nesting of
1526 single-member structs, are passed in floating-point registers. */
1527 if (type->code () == TYPE_CODE_STRUCT
1528 && type->num_fields () == 1 && tdep->elf_abi == POWERPC_ELF_V1)
1529 {
1530 while (type->code () == TYPE_CODE_STRUCT
1531 && type->num_fields () == 1)
1532 type = check_typedef (type->field (0).type ());
1533
1534 if (type->code () == TYPE_CODE_FLT) {
1535 /* Handle the case of 128-bit floats for both IEEE and IBM long double
1536 formats. */
1537 if (type->length () == 16
1540 {
1541 ppc64_sysv_abi_push_vreg (gdbarch, val, argpos);
1542 align = 16;
1543 }
1544 else
1545 ppc64_sysv_abi_push_freg (gdbarch, type, val, argpos);
1546 }
1547 }
1548
1549 /* In the ELFv2 ABI, homogeneous floating-point or vector
1550 aggregates are passed in a series of registers. */
1551 if (tdep->elf_abi == POWERPC_ELF_V2)
1552 {
1553 struct type *eltype;
1554 int i, nelt;
1555
1556 if (ppc64_elfv2_abi_homogeneous_aggregate (type, &eltype, &nelt,
1557 gdbarch))
1558 for (i = 0; i < nelt; i++)
1559 {
1560 const gdb_byte *elval = val + i * eltype->length ();
1561
1562 if (eltype->code () == TYPE_CODE_FLT
1563 && eltype->length () == 16
1566 /* IEEE FLOAT128, args in vector registers. */
1567 {
1568 ppc64_sysv_abi_push_vreg (gdbarch, elval, argpos);
1569 align = 16;
1570 }
1571 else if (eltype->code () == TYPE_CODE_FLT
1572 || eltype->code () == TYPE_CODE_DECFLOAT)
1573 /* IBM long double and all other floats and decfloats, args
1574 are in a pair of floating point registers. */
1575 ppc64_sysv_abi_push_freg (gdbarch, eltype, elval, argpos);
1576 else if (eltype->code () == TYPE_CODE_ARRAY
1577 && eltype->is_vector ()
1578 && tdep->vector_abi == POWERPC_VEC_ALTIVEC
1579 && eltype->length () == 16)
1580 {
1581 ppc64_sysv_abi_push_vreg (gdbarch, elval, argpos);
1582 align = 16;
1583 }
1584 }
1585 }
1586
1587 ppc64_sysv_abi_push_val (gdbarch, val, type->length (), align, argpos);
1588 }
1589}
1590
1591/* Pass the arguments in either registers, or in the stack. Using the
1592 ppc 64 bit SysV ABI.
1593
1594 This implements a dumbed down version of the ABI. It always writes
1595 values to memory, GPR and FPR, even when not necessary. Doing this
1596 greatly simplifies the logic. */
1597
1598CORE_ADDR
1600 struct value *function,
1601 struct regcache *regcache, CORE_ADDR bp_addr,
1602 int nargs, struct value **args, CORE_ADDR sp,
1603 function_call_return_method return_method,
1604 CORE_ADDR struct_addr)
1605{
1606 CORE_ADDR func_addr = find_function_addr (function, NULL);
1607 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1608 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1609 int opencl_abi = ppc_sysv_use_opencl_abi (function->type ());
1610 ULONGEST back_chain;
1611 /* See for-loop comment below. */
1612 int write_pass;
1613 /* Size of the by-reference parameter copy region, the final value is
1614 computed in the for-loop below. */
1615 LONGEST refparam_size = 0;
1616 /* Size of the general parameter region, the final value is computed
1617 in the for-loop below. */
1618 LONGEST gparam_size = 0;
1619 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
1620 calls to align_up(), align_down(), etc. because this makes it
1621 easier to reuse this code (in a copy/paste sense) in the future,
1622 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
1623 at some point makes it easier to verify that this function is
1624 correct without having to do a non-local analysis to figure out
1625 the possible values of tdep->wordsize. */
1626 gdb_assert (tdep->wordsize == 8);
1627
1628 /* This function exists to support a calling convention that
1629 requires floating-point registers. It shouldn't be used on
1630 processors that lack them. */
1631 gdb_assert (ppc_floating_point_unit_p (gdbarch));
1632
1633 /* By this stage in the proceedings, SP has been decremented by "red
1634 zone size" + "struct return size". Fetch the stack-pointer from
1635 before this and use that as the BACK_CHAIN. */
1637 &back_chain);
1638
1639 /* Go through the argument list twice.
1640
1641 Pass 1: Compute the function call's stack space and register
1642 requirements.
1643
1644 Pass 2: Replay the same computation but this time also write the
1645 values out to the target. */
1646
1647 for (write_pass = 0; write_pass < 2; write_pass++)
1648 {
1649 int argno;
1650
1651 struct ppc64_sysv_argpos argpos;
1652 argpos.greg = 3;
1653 argpos.freg = 1;
1654 argpos.vreg = 2;
1655
1656 if (!write_pass)
1657 {
1658 /* During the first pass, GPARAM and REFPARAM are more like
1659 offsets (start address zero) than addresses. That way
1660 they accumulate the total stack space each region
1661 requires. */
1662 argpos.regcache = NULL;
1663 argpos.gparam = 0;
1664 argpos.refparam = 0;
1665 }
1666 else
1667 {
1668 /* Decrement the stack pointer making space for the Altivec
1669 and general on-stack parameters. Set refparam and gparam
1670 to their corresponding regions. */
1671 argpos.regcache = regcache;
1672 argpos.refparam = align_down (sp - refparam_size, 16);
1673 argpos.gparam = align_down (argpos.refparam - gparam_size, 16);
1674 /* Add in space for the TOC, link editor double word (v1 only),
1675 compiler double word (v1 only), LR save area, CR save area,
1676 and backchain. */
1677 if (tdep->elf_abi == POWERPC_ELF_V1)
1678 sp = align_down (argpos.gparam - 48, 16);
1679 else
1680 sp = align_down (argpos.gparam - 32, 16);
1681 }
1682
1683 /* If the function is returning a `struct', then there is an
1684 extra hidden parameter (which will be passed in r3)
1685 containing the address of that struct.. In that case we
1686 should advance one word and start from r4 register to copy
1687 parameters. This also consumes one on-stack parameter slot. */
1688 if (return_method == return_method_struct)
1689 ppc64_sysv_abi_push_integer (gdbarch, struct_addr, &argpos);
1690
1691 for (argno = 0; argno < nargs; argno++)
1692 {
1693 struct value *arg = args[argno];
1694 struct type *type = check_typedef (arg->type ());
1695 const bfd_byte *val = arg->contents ().data ();
1696
1697 if (type->code () == TYPE_CODE_COMPLEX)
1698 {
1699 /* Complex types are passed as if two independent scalars. */
1700 struct type *eltype = check_typedef (type->target_type ());
1701
1702 ppc64_sysv_abi_push_param (gdbarch, eltype, val, &argpos);
1704 val + eltype->length (), &argpos);
1705 }
1706 else if (type->code () == TYPE_CODE_ARRAY && type->is_vector ()
1707 && opencl_abi)
1708 {
1709 /* OpenCL vectors shorter than 16 bytes are passed as if
1710 a series of independent scalars; OpenCL vectors 16 bytes
1711 or longer are passed as if a series of AltiVec vectors. */
1712 struct type *eltype;
1713 int i, nelt;
1714
1715 if (type->length () < 16)
1716 eltype = check_typedef (type->target_type ());
1717 else
1718 eltype = register_type (gdbarch, tdep->ppc_vr0_regnum);
1719
1720 nelt = type->length () / eltype->length ();
1721 for (i = 0; i < nelt; i++)
1722 {
1723 const gdb_byte *elval = val + i * eltype->length ();
1724
1725 ppc64_sysv_abi_push_param (gdbarch, eltype, elval, &argpos);
1726 }
1727 }
1728 else
1729 {
1730 /* All other types are passed as single arguments. */
1731 ppc64_sysv_abi_push_param (gdbarch, type, val, &argpos);
1732 }
1733 }
1734
1735 if (!write_pass)
1736 {
1737 /* Save the true region sizes ready for the second pass. */
1738 refparam_size = argpos.refparam;
1739 /* Make certain that the general parameter save area is at
1740 least the minimum 8 registers (or doublewords) in size. */
1741 if (argpos.greg < 8)
1742 gparam_size = 8 * tdep->wordsize;
1743 else
1744 gparam_size = argpos.gparam;
1745 }
1746 }
1747
1748 /* Update %sp. */
1750
1751 /* Write the backchain (it occupies WORDSIZED bytes). */
1752 write_memory_signed_integer (sp, tdep->wordsize, byte_order, back_chain);
1753
1754 /* Point the inferior function call's return address at the dummy's
1755 breakpoint. */
1757
1758 /* In the ELFv1 ABI, use the func_addr to find the descriptor, and use
1759 that to find the TOC. If we're calling via a function pointer,
1760 the pointer itself identifies the descriptor. */
1761 if (tdep->elf_abi == POWERPC_ELF_V1)
1762 {
1763 struct type *ftype = check_typedef (function->type ());
1764 CORE_ADDR desc_addr = value_as_address (function);
1765
1766 if (ftype->code () == TYPE_CODE_PTR
1767 || convert_code_addr_to_desc_addr (func_addr, &desc_addr))
1768 {
1769 /* The TOC is the second double word in the descriptor. */
1770 CORE_ADDR toc =
1771 read_memory_unsigned_integer (desc_addr + tdep->wordsize,
1772 tdep->wordsize, byte_order);
1773
1775 tdep->ppc_gp0_regnum + 2, toc);
1776 }
1777 }
1778
1779 /* In the ELFv2 ABI, we need to pass the target address in r12 since
1780 we may be calling a global entry point. */
1781 if (tdep->elf_abi == POWERPC_ELF_V2)
1783 tdep->ppc_gp0_regnum + 12, func_addr);
1784
1785 return sp;
1786}
1787
1788/* Subroutine of ppc64_sysv_abi_return_value that handles "base" types:
1789 integer, floating-point, and AltiVec vector types.
1790
1791 This routine also handles components of aggregate return types;
1792 INDEX describes which part of the aggregate is to be handled.
1793
1794 Returns true if VALTYPE is some such base type that could be handled,
1795 false otherwise. */
1796static int
1798 struct regcache *regcache, gdb_byte *readbuf,
1799 const gdb_byte *writebuf, int index)
1800{
1801 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1802
1803 /* Integers live in GPRs starting at r3. */
1804 if ((valtype->code () == TYPE_CODE_INT
1805 || valtype->code () == TYPE_CODE_ENUM
1806 || valtype->code () == TYPE_CODE_CHAR
1807 || valtype->code () == TYPE_CODE_BOOL
1808 || valtype->code () == TYPE_CODE_RANGE
1809 || is_fixed_point_type (valtype))
1810 && valtype->length () <= 8)
1811 {
1812 int regnum = tdep->ppc_gp0_regnum + 3 + index;
1813
1814 if (writebuf != NULL)
1815 {
1816 LONGEST return_val;
1817
1818 if (is_fixed_point_type (valtype))
1819 {
1820 /* Fixed point type values need to be returned unscaled. */
1821 gdb_mpz unscaled;
1822
1823 unscaled.read (gdb::make_array_view (writebuf,
1824 valtype->length ()),
1825 type_byte_order (valtype),
1826 valtype->is_unsigned ());
1827 return_val = unscaled.as_integer<LONGEST> ();
1828 }
1829 else
1830 return_val = unpack_long (valtype, writebuf);
1831
1832 /* Be careful to sign extend the value. */
1834 }
1835 if (readbuf != NULL)
1836 {
1837 /* Extract the integer from GPR. Since this is truncating the
1838 value, there isn't a sign extension problem. */
1839 ULONGEST regval;
1840
1842 store_unsigned_integer (readbuf, valtype->length (),
1843 gdbarch_byte_order (gdbarch), regval);
1844 }
1845 return 1;
1846 }
1847
1848 /* Floats and doubles go in f1 .. f13. 32-bit floats are converted
1849 to double first. */
1850 if (valtype->length () <= 8
1851 && valtype->code () == TYPE_CODE_FLT)
1852 {
1853 int regnum = tdep->ppc_fp0_regnum + 1 + index;
1854 struct type *regtype = register_type (gdbarch, regnum);
1855 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
1856
1857 if (writebuf != NULL)
1858 {
1859 target_float_convert (writebuf, valtype, regval, regtype);
1860 regcache->cooked_write (regnum, regval);
1861 }
1862 if (readbuf != NULL)
1863 {
1864 regcache->cooked_read (regnum, regval);
1865 target_float_convert (regval, regtype, readbuf, valtype);
1866 }
1867 return 1;
1868 }
1869
1870 /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are
1871 placed in the least significant word. */
1872 if (valtype->length () <= 8
1873 && valtype->code () == TYPE_CODE_DECFLOAT)
1874 {
1875 int regnum = tdep->ppc_fp0_regnum + 1 + index;
1876 int offset = 0;
1877
1878 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1879 offset = 8 - valtype->length ();
1880
1881 if (writebuf != NULL)
1882 regcache->cooked_write_part (regnum, offset, valtype->length (),
1883 writebuf);
1884 if (readbuf != NULL)
1885 regcache->cooked_read_part (regnum, offset, valtype->length (),
1886 readbuf);
1887 return 1;
1888 }
1889
1890 /* IBM long double stored in two consecutive FPRs. */
1891 if (valtype->length () == 16
1892 && valtype->code () == TYPE_CODE_FLT
1895 {
1896 int regnum = tdep->ppc_fp0_regnum + 1 + 2 * index;
1897
1898 if (writebuf != NULL)
1899 {
1900 regcache->cooked_write (regnum, writebuf);
1901 regcache->cooked_write (regnum + 1, writebuf + 8);
1902 }
1903 if (readbuf != NULL)
1904 {
1905 regcache->cooked_read (regnum, readbuf);
1906 regcache->cooked_read (regnum + 1, readbuf + 8);
1907 }
1908 return 1;
1909 }
1910
1911 /* 128-bit decimal floating-point values are stored in an even/odd
1912 pair of FPRs, with the even FPR holding the most significant half. */
1913 if (valtype->length () == 16
1914 && valtype->code () == TYPE_CODE_DECFLOAT)
1915 {
1916 int regnum = tdep->ppc_fp0_regnum + 2 + 2 * index;
1917 int lopart = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 8 : 0;
1918 int hipart = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
1919
1920 if (writebuf != NULL)
1921 {
1922 regcache->cooked_write (regnum, writebuf + hipart);
1923 regcache->cooked_write (regnum + 1, writebuf + lopart);
1924 }
1925 if (readbuf != NULL)
1926 {
1927 regcache->cooked_read (regnum, readbuf + hipart);
1928 regcache->cooked_read (regnum + 1, readbuf + lopart);
1929 }
1930 return 1;
1931 }
1932
1933 /* AltiVec vectors are returned in VRs starting at v2.
1934 IEEE FLOAT 128-bit are stored in vector register. */
1935
1936 if (valtype->length () == 16
1937 && ((valtype->code () == TYPE_CODE_ARRAY
1938 && valtype->is_vector ()
1939 && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
1940 || (valtype->code () == TYPE_CODE_FLT
1943 {
1944 int regnum = tdep->ppc_vr0_regnum + 2 + index;
1945
1946 if (writebuf != NULL)
1947 regcache->cooked_write (regnum, writebuf);
1948 if (readbuf != NULL)
1949 regcache->cooked_read (regnum, readbuf);
1950 return 1;
1951 }
1952
1953 /* Short vectors are returned in GPRs starting at r3. */
1954 if (valtype->length () <= 8
1955 && valtype->code () == TYPE_CODE_ARRAY && valtype->is_vector ())
1956 {
1957 int regnum = tdep->ppc_gp0_regnum + 3 + index;
1958 int offset = 0;
1959
1960 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1961 offset = 8 - valtype->length ();
1962
1963 if (writebuf != NULL)
1964 regcache->cooked_write_part (regnum, offset, valtype->length (),
1965 writebuf);
1966 if (readbuf != NULL)
1967 regcache->cooked_read_part (regnum, offset, valtype->length (),
1968 readbuf);
1969 return 1;
1970 }
1971
1972 return 0;
1973}
1974
1975/* The 64 bit ABI return value convention.
1976
1977 Return non-zero if the return-value is stored in a register, return
1978 0 if the return-value is instead stored on the stack (a.k.a.,
1979 struct return convention).
1980
1981 For a return-value stored in a register: when WRITEBUF is non-NULL,
1982 copy the buffer to the corresponding register return-value location
1983 location; when READBUF is non-NULL, fill the buffer from the
1984 corresponding register return-value location. */
1987 struct type *valtype, struct regcache *regcache,
1988 gdb_byte *readbuf, const gdb_byte *writebuf)
1989{
1990 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1991 struct type *func_type = function ? function->type () : NULL;
1992 int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
1993 struct type *eltype;
1994 int nelt, ok;
1995
1996 /* This function exists to support a calling convention that
1997 requires floating-point registers. It shouldn't be used on
1998 processors that lack them. */
1999 gdb_assert (ppc_floating_point_unit_p (gdbarch));
2000
2001 /* Complex types are returned as if two independent scalars. */
2002 if (valtype->code () == TYPE_CODE_COMPLEX)
2003 {
2004 eltype = check_typedef (valtype->target_type ());
2005
2006 for (int i = 0; i < 2; i++)
2007 {
2009 readbuf, writebuf, i);
2010 gdb_assert (ok);
2011
2012 if (readbuf)
2013 readbuf += eltype->length ();
2014 if (writebuf)
2015 writebuf += eltype->length ();
2016 }
2018 }
2019
2020 /* OpenCL vectors shorter than 16 bytes are returned as if
2021 a series of independent scalars; OpenCL vectors 16 bytes
2022 or longer are returned as if a series of AltiVec vectors. */
2023 if (valtype->code () == TYPE_CODE_ARRAY && valtype->is_vector ()
2024 && opencl_abi)
2025 {
2026 if (valtype->length () < 16)
2027 eltype = check_typedef (valtype->target_type ());
2028 else
2029 eltype = register_type (gdbarch, tdep->ppc_vr0_regnum);
2030
2031 nelt = valtype->length () / eltype->length ();
2032 for (int i = 0; i < nelt; i++)
2033 {
2035 readbuf, writebuf, i);
2036 gdb_assert (ok);
2037
2038 if (readbuf)
2039 readbuf += eltype->length ();
2040 if (writebuf)
2041 writebuf += eltype->length ();
2042 }
2044 }
2045
2046 /* All pointers live in r3. */
2047 if (valtype->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (valtype))
2048 {
2049 int regnum = tdep->ppc_gp0_regnum + 3;
2050
2051 if (writebuf != NULL)
2052 regcache->cooked_write (regnum, writebuf);
2053 if (readbuf != NULL)
2054 regcache->cooked_read (regnum, readbuf);
2056 }
2057
2058 /* Small character arrays are returned, right justified, in r3. */
2059 if (valtype->code () == TYPE_CODE_ARRAY
2060 && !valtype->is_vector ()
2061 && valtype->length () <= 8
2062 && valtype->target_type ()->code () == TYPE_CODE_INT
2063 && valtype->target_type ()->length () == 1)
2064 {
2065 int regnum = tdep->ppc_gp0_regnum + 3;
2066 int offset = (register_size (gdbarch, regnum) - valtype->length ());
2067
2068 if (writebuf != NULL)
2069 regcache->cooked_write_part (regnum, offset, valtype->length (),
2070 writebuf);
2071 if (readbuf != NULL)
2072 regcache->cooked_read_part (regnum, offset, valtype->length (),
2073 readbuf);
2075 }
2076
2077 /* In the ELFv2 ABI, homogeneous floating-point or vector
2078 aggregates are returned in registers. */
2079 if (tdep->elf_abi == POWERPC_ELF_V2
2080 && ppc64_elfv2_abi_homogeneous_aggregate (valtype, &eltype, &nelt,
2081 gdbarch)
2082 && (eltype->code () == TYPE_CODE_FLT
2083 || eltype->code () == TYPE_CODE_DECFLOAT
2084 || (eltype->code () == TYPE_CODE_ARRAY
2085 && eltype->is_vector ()
2086 && tdep->vector_abi == POWERPC_VEC_ALTIVEC
2087 && eltype->length () == 16)))
2088 {
2089 for (int i = 0; i < nelt; i++)
2090 {
2092 readbuf, writebuf, i);
2093 gdb_assert (ok);
2094
2095 if (readbuf)
2096 readbuf += eltype->length ();
2097 if (writebuf)
2098 writebuf += eltype->length ();
2099 }
2100
2102 }
2103
2104 if (!language_pass_by_reference (valtype).trivially_copyable
2105 && valtype->code () == TYPE_CODE_STRUCT)
2107
2108 /* In the ELFv2 ABI, aggregate types of up to 16 bytes are
2109 returned in registers r3:r4. */
2110 if (tdep->elf_abi == POWERPC_ELF_V2
2111 && valtype->length () <= 16
2112 && (valtype->code () == TYPE_CODE_STRUCT
2113 || valtype->code () == TYPE_CODE_UNION
2114 || (valtype->code () == TYPE_CODE_ARRAY
2115 && !valtype->is_vector ())))
2116 {
2117 int n_regs = ((valtype->length () + tdep->wordsize - 1)
2118 / tdep->wordsize);
2119
2120 for (int i = 0; i < n_regs; i++)
2121 {
2122 gdb_byte regval[PPC_MAX_REGISTER_SIZE];
2123 int regnum = tdep->ppc_gp0_regnum + 3 + i;
2124 int offset = i * tdep->wordsize;
2125 int len = valtype->length () - offset;
2126
2127 if (len > tdep->wordsize)
2128 len = tdep->wordsize;
2129
2130 if (writebuf != NULL)
2131 {
2132 memset (regval, 0, sizeof regval);
2133 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
2134 && offset == 0)
2135 memcpy (regval + tdep->wordsize - len, writebuf, len);
2136 else
2137 memcpy (regval, writebuf + offset, len);
2138 regcache->cooked_write (regnum, regval);
2139 }
2140 if (readbuf != NULL)
2141 {
2142 regcache->cooked_read (regnum, regval);
2143 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
2144 && offset == 0)
2145 memcpy (readbuf, regval + tdep->wordsize - len, len);
2146 else
2147 memcpy (readbuf + offset, regval, len);
2148 }
2149 }
2151 }
2152
2153 /* Handle plain base types. */
2155 readbuf, writebuf, 0))
2157
2159}
2160
2161CORE_ADDR
2163{
2164 /* The PowerPC ABI specifies aggregates that are not returned by value
2165 are returned in a storage buffer provided by the caller. The
2166 address of the storage buffer is provided as a hidden first input
2167 argument in register r3. The PowerPC ABI does not guarantee that
2168 register r3 will not be changed while executing the function. Hence, it
2169 cannot be assumed that r3 will still contain the address of the storage
2170 buffer when execution reaches the end of the function.
2171
2172 This function attempts to determine the value of r3 on entry to the
2173 function using the DW_OP_entry_value DWARF entries. This requires
2174 compiling the user program with -fvar-tracking to resolve the
2175 DW_TAG_call_sites in the binary file. */
2176
2177 union call_site_parameter_u kind_u;
2178 enum call_site_parameter_kind kind;
2179 CORE_ADDR return_val = 0;
2180
2181 kind_u.dwarf_reg = 3; /* First passed arg/return value is in r3. */
2183
2184 /* val_type is the type of the return value. Need the pointer type
2185 to the return value. */
2186 val_type = lookup_pointer_type (val_type);
2187
2188 try
2189 {
2190 return_val = value_as_address (value_of_dwarf_reg_entry (val_type,
2191 cur_frame,
2192 kind, kind_u));
2193 }
2194 catch (const gdb_exception_error &e)
2195 {
2196 warning ("Cannot determine the function return value.\n"
2197 "Try compiling with -fvar-tracking.");
2198 }
2199 return return_val;
2200}
int regnum
call_site_parameter_kind
Definition call-site.h:36
@ CALL_SITE_PARAMETER_DWARF_REG
Definition call-site.h:38
enum register_status cooked_read_part(int regnum, int offset, int len, gdb_byte *buf)
Definition regcache.c:1042
enum register_status cooked_read(int regnum, gdb_byte *buf)
Definition regcache.c:698
void cooked_write(int regnum, const gdb_byte *buf)
Definition regcache.c:870
void cooked_write_part(int regnum, int offset, int len, const gdb_byte *buf)
Definition regcache.c:1052
void write_memory(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
Definition corefile.c:347
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition corefile.c:306
void write_memory_signed_integer(CORE_ADDR addr, int len, enum bfd_endian byte_order, LONGEST value)
Definition corefile.c:393
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition defs.h:515
return_value_convention
Definition defs.h:257
@ RETURN_VALUE_REGISTER_CONVENTION
Definition defs.h:260
@ RETURN_VALUE_STRUCT_CONVENTION
Definition defs.h:267
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2037
const struct floatformat ** gdbarch_long_double_format(struct gdbarch *gdbarch)
Definition gdbarch.c:1653
function_call_return_method
Definition gdbarch.h:114
@ return_method_struct
Definition gdbarch.h:126
enum bfd_endian type_byte_order(const struct type *type)
Definition gdbtypes.c:3900
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:430
const struct floatformat * floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN]
Definition gdbtypes.c:125
const struct floatformat * floatformats_ieee_quad[BFD_ENDIAN_UNKNOWN]
Definition gdbtypes.c:93
bool get_array_bounds(struct type *type, LONGEST *low_bound, LONGEST *high_bound)
Definition gdbtypes.c:1211
bool is_fixed_point_type(struct type *type)
Definition gdbtypes.c:5861
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:2966
#define TYPE_IS_REFERENCE(t)
Definition gdbtypes.h:139
#define TYPE_CALLING_CONVENTION(thistype)
Definition gdbtypes.h:1943
CORE_ADDR find_function_addr(struct value *function, struct type **retval_type, struct type **function_type)
Definition infcall.c:278
struct language_pass_by_ref_info language_pass_by_reference(struct type *type)
Definition language.c:543
struct value * value_of_dwarf_reg_entry(struct type *type, frame_info_ptr frame, enum call_site_parameter_kind kind, union call_site_parameter_u kind_u)
Definition loc.c:1342
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
Definition minsyms.c:996
struct obj_section * find_pc_section(CORE_ADDR pc)
Definition objfiles.c:1128
CORE_ADDR ppc_sysv_abi_push_dummy_call(struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, function_call_return_method return_method, CORE_ADDR struct_addr)
static enum return_value_convention get_decimal_float_return_value(struct gdbarch *gdbarch, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
CORE_ADDR ppc64_sysv_abi_push_dummy_call(struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, function_call_return_method return_method, CORE_ADDR struct_addr)
static int ppc_sysv_use_opencl_abi(struct type *ftype)
enum return_value_convention ppc64_sysv_abi_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
static enum return_value_convention do_ppc_sysv_return_value(struct gdbarch *gdbarch, struct type *func_type, struct type *type, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf, int broken_gcc)
static void ppc64_sysv_abi_push_integer(struct gdbarch *gdbarch, ULONGEST val, struct ppc64_sysv_argpos *argpos)
static void ppc64_sysv_abi_push_param(struct gdbarch *gdbarch, struct type *type, const bfd_byte *val, struct ppc64_sysv_argpos *argpos)
CORE_ADDR ppc_sysv_get_return_buf_addr(struct type *val_type, frame_info_ptr cur_frame)
static int convert_code_addr_to_desc_addr(CORE_ADDR code_addr, CORE_ADDR *desc_addr)
enum return_value_convention ppc_sysv_abi_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
static void ppc64_sysv_abi_push_val(struct gdbarch *gdbarch, const bfd_byte *val, int len, int align, struct ppc64_sysv_argpos *argpos)
static void ppc64_sysv_abi_push_vreg(struct gdbarch *gdbarch, const bfd_byte *val, struct ppc64_sysv_argpos *argpos)
static LONGEST ppc64_aggregate_candidate(struct type *type, struct type **field_type)
enum return_value_convention ppc_sysv_abi_broken_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
static int ppc64_elfv2_abi_homogeneous_aggregate(struct type *type, struct type **elt_type, int *n_elts, struct gdbarch *gdbarch)
static int ppc64_sysv_abi_return_value_base(struct gdbarch *gdbarch, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf, int index)
static void ppc64_sysv_abi_push_freg(struct gdbarch *gdbarch, struct type *type, const bfd_byte *val, struct ppc64_sysv_argpos *argpos)
@ POWERPC_ELF_V1
Definition ppc-tdep.h:188
@ POWERPC_ELF_V2
Definition ppc-tdep.h:189
#define PPC_MAX_REGISTER_SIZE
Definition ppc-tdep.h:395
int ppc_floating_point_unit_p(struct gdbarch *gdbarch)
@ POWERPC_VEC_SPE
Definition ppc-tdep.h:199
@ POWERPC_VEC_GENERIC
Definition ppc-tdep.h:197
@ POWERPC_VEC_ALTIVEC
Definition ppc-tdep.h:198
int register_size(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:170
void regcache_cooked_write_signed(struct regcache *regcache, int regnum, LONGEST val)
Definition regcache.c:804
enum register_status regcache_cooked_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
Definition regcache.c:796
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition regcache.c:825
struct type * register_type(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:158
enum var_types type
Definition scm-param.c:142
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
struct type * type() const
Definition gdbtypes.h:547
bool is_static() const
Definition gdbtypes.h:593
void read(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order, bool unsigned_p)
Definition gmp-utils.c:46
T as_integer() const
Definition gmp-utils.h:625
const char * linkage_name() const
Definition symtab.h:460
struct objfile * objfile
Definition objfiles.h:401
struct regcache * regcache
struct type * target_type() const
Definition gdbtypes.h:1037
type_code code() const
Definition gdbtypes.h:956
ULONGEST length() const
Definition gdbtypes.h:983
struct field & field(int idx) const
Definition gdbtypes.h:1012
bool is_unsigned() const
Definition gdbtypes.h:1100
bool is_vector() const
Definition gdbtypes.h:1186
unsigned int num_fields() const
Definition gdbtypes.h:994
Definition value.h:130
gdb::array_view< const gdb_byte > contents()
Definition value.c:1262
struct type * type() const
Definition value.h:180
void target_float_convert(const gdb_byte *from, const struct type *from_type, gdb_byte *to, const struct type *to_type)
CORE_ADDR value_as_address(struct value *val)
Definition value.c:2636
LONGEST unpack_long(struct type *type, const gdb_byte *valaddr)
Definition value.c:2753