1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright 2000, 2001, 2002, 2003 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 2 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, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
29 #include "gdb_assert.h"
33 /* Pass the arguments in either registers, or in the stack. Using the
34 ppc sysv ABI, the first eight words of the argument list (that might
35 be less than eight parameters if some parameters occupy more than one
36 word) are passed in r3..r10 registers. float and double parameters are
37 passed in fpr's, in addition to that. Rest of the parameters if any
38 are passed in user stack.
40 If the function is returning a structure, then the return address is passed
41 in r3, then the first 7 words of the parametes can be passed in registers,
45 ppc_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
46 struct regcache
*regcache
, CORE_ADDR bp_addr
,
47 int nargs
, struct value
**args
, CORE_ADDR sp
,
48 int struct_return
, CORE_ADDR struct_addr
)
50 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
51 const CORE_ADDR saved_sp
= read_sp ();
52 int argspace
= 0; /* 0 is an initial wrong guess. */
55 /* Go through the argument list twice.
57 Pass 1: Figure out how much new stack space is required for
58 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
59 ABI doesn't reserve any extra space for parameters which are put
60 in registers, but does always push structures and then pass their
63 Pass 2: Replay the same computation but this time also write the
64 values out to the target. */
66 for (write_pass
= 0; write_pass
< 2; write_pass
++)
69 /* Next available floating point register for float and double
72 /* Next available general register for non-float, non-vector
75 /* Next available vector register for vector arguments. */
77 /* Arguments start above the "LR save word" and "Back chain". */
78 int argoffset
= 2 * tdep
->wordsize
;
79 /* Structures start after the arguments. */
80 int structoffset
= argoffset
+ argspace
;
82 /* If the function is returning a `struct', then the first word
83 (which will be passed in r3) is used for struct return
84 address. In that case we should advance one word and start
85 from r4 register to copy parameters. */
89 regcache_cooked_write_signed (regcache
,
90 tdep
->ppc_gp0_regnum
+ greg
,
95 for (argno
= 0; argno
< nargs
; argno
++)
97 struct value
*arg
= args
[argno
];
98 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
99 int len
= TYPE_LENGTH (type
);
100 char *val
= VALUE_CONTENTS (arg
);
102 if (TYPE_CODE (type
) == TYPE_CODE_FLT
103 && ppc_floating_point_unit_p (current_gdbarch
) && len
<= 8)
105 /* Floating point value converted to "double" then
106 passed in an FP register, when the registers run out,
107 8 byte aligned stack is used. */
112 /* Always store the floating point value using
113 the register's floating-point format. */
114 char regval
[MAX_REGISTER_SIZE
];
116 = register_type (gdbarch
, FP0_REGNUM
+ freg
);
117 convert_typed_floating (val
, type
, regval
, regtype
);
118 regcache_cooked_write (regcache
, FP0_REGNUM
+ freg
,
125 /* SysV ABI converts floats to doubles before
126 writing them to an 8 byte aligned stack location. */
127 argoffset
= align_up (argoffset
, 8);
131 struct type
*memtype
;
132 switch (TARGET_BYTE_ORDER
)
135 memtype
= builtin_type_ieee_double_big
;
137 case BFD_ENDIAN_LITTLE
:
138 memtype
= builtin_type_ieee_double_little
;
141 internal_error (__FILE__
, __LINE__
, "bad switch");
143 convert_typed_floating (val
, type
, memval
, memtype
);
144 write_memory (sp
+ argoffset
, val
, len
);
149 else if (len
== 8 && (TYPE_CODE (type
) == TYPE_CODE_INT
/* long long */
150 || (!ppc_floating_point_unit_p (current_gdbarch
) && TYPE_CODE (type
) == TYPE_CODE_FLT
))) /* double */
152 /* "long long" or "double" passed in an odd/even
153 register pair with the low addressed word in the odd
154 register and the high addressed word in the even
155 register, or when the registers run out an 8 byte
156 aligned stack location. */
159 /* Just in case GREG was 10. */
161 argoffset
= align_up (argoffset
, 8);
163 write_memory (sp
+ argoffset
, val
, len
);
166 else if (tdep
->wordsize
== 8)
169 regcache_cooked_write (regcache
,
170 tdep
->ppc_gp0_regnum
+ greg
, val
);
175 /* Must start on an odd register - r3/r4 etc. */
180 regcache_cooked_write (regcache
,
181 tdep
->ppc_gp0_regnum
+ greg
+ 0,
183 regcache_cooked_write (regcache
,
184 tdep
->ppc_gp0_regnum
+ greg
+ 1,
191 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
192 && TYPE_VECTOR (type
) && tdep
->ppc_vr0_regnum
>= 0)
194 /* Vector parameter passed in an Altivec register, or
195 when that runs out, 16 byte aligned stack location. */
199 regcache_cooked_write (current_regcache
,
200 tdep
->ppc_vr0_regnum
+ vreg
, val
);
205 argoffset
= align_up (argoffset
, 16);
207 write_memory (sp
+ argoffset
, val
, 16);
212 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
213 && TYPE_VECTOR (type
) && tdep
->ppc_ev0_regnum
>= 0)
215 /* Vector parameter passed in an e500 register, or when
216 that runs out, 8 byte aligned stack location. Note
217 that since e500 vector and general purpose registers
218 both map onto the same underlying register set, a
219 "greg" and not a "vreg" is consumed here. A cooked
220 write stores the value in the correct locations
221 within the raw register cache. */
225 regcache_cooked_write (current_regcache
,
226 tdep
->ppc_ev0_regnum
+ greg
, val
);
231 argoffset
= align_up (argoffset
, 8);
233 write_memory (sp
+ argoffset
, val
, 8);
239 /* Reduce the parameter down to something that fits in a
241 char word
[MAX_REGISTER_SIZE
];
242 memset (word
, 0, MAX_REGISTER_SIZE
);
243 if (len
> tdep
->wordsize
244 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
245 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
247 /* Structs and large values are put on an 8 byte
249 structoffset
= align_up (structoffset
, 8);
251 write_memory (sp
+ structoffset
, val
, len
);
252 /* ... and then a "word" pointing to that address is
253 passed as the parameter. */
254 store_unsigned_integer (word
, tdep
->wordsize
,
258 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
259 /* Sign or zero extend the "int" into a "word". */
260 store_unsigned_integer (word
, tdep
->wordsize
,
261 unpack_long (type
, val
));
263 /* Always goes in the low address. */
264 memcpy (word
, val
, len
);
265 /* Store that "word" in a register, or on the stack.
266 The words have "4" byte alignment. */
270 regcache_cooked_write (regcache
,
271 tdep
->ppc_gp0_regnum
+ greg
, word
);
276 argoffset
= align_up (argoffset
, tdep
->wordsize
);
278 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
279 argoffset
+= tdep
->wordsize
;
284 /* Compute the actual stack space requirements. */
287 /* Remember the amount of space needed by the arguments. */
288 argspace
= argoffset
;
289 /* Allocate space for both the arguments and the structures. */
290 sp
-= (argoffset
+ structoffset
);
291 /* Ensure that the stack is still 16 byte aligned. */
292 sp
= align_down (sp
, 16);
297 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
299 /* Write the backchain (it occupies WORDSIZED bytes). */
300 write_memory_signed_integer (sp
, tdep
->wordsize
, saved_sp
);
302 /* Point the inferior function call's return address at the dummy's
304 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
309 /* Handle the return-value conventions specified by the SysV 32-bit
310 PowerPC ABI (including all the supplements):
312 no floating-point: floating-point values returned using 32-bit
313 general-purpose registers.
315 Altivec: 128-bit vectors returned using vector registers.
317 e500: 64-bit vectors returned using the full full 64 bit EV
318 register, floating-point values returned using 32-bit
319 general-purpose registers.
321 GCC (broken): Small struct values right (instead of left) aligned
322 when returned in general-purpose registers. */
324 static enum return_value_convention
325 do_ppc_sysv_return_value (struct type
*type
, struct regcache
*regcache
,
326 const void *inval
, void *outval
, int broken_gcc
)
328 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
329 gdb_assert (tdep
->wordsize
== 4);
330 if (TYPE_CODE (type
) == TYPE_CODE_FLT
331 && TYPE_LENGTH (type
) <= 8
332 && ppc_floating_point_unit_p (current_gdbarch
))
336 /* Floats and doubles stored in "f1". Convert the value to
337 the required type. */
338 char regval
[MAX_REGISTER_SIZE
];
339 struct type
*regtype
= register_type (current_gdbarch
,
341 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1, regval
);
342 convert_typed_floating (regval
, regtype
, outval
, type
);
346 /* Floats and doubles stored in "f1". Convert the value to
347 the register's "double" type. */
348 char regval
[MAX_REGISTER_SIZE
];
349 struct type
*regtype
= register_type (current_gdbarch
, FP0_REGNUM
);
350 convert_typed_floating (inval
, type
, regval
, regtype
);
351 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1, regval
);
353 return RETURN_VALUE_REGISTER_CONVENTION
;
355 if ((TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
356 || (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8))
360 /* A long long, or a double stored in the 32 bit r3/r4. */
361 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
362 (bfd_byte
*) outval
+ 0);
363 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
364 (bfd_byte
*) outval
+ 4);
368 /* A long long, or a double stored in the 32 bit r3/r4. */
369 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
370 (bfd_byte
*) inval
+ 0);
371 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
372 (bfd_byte
*) inval
+ 4);
374 return RETURN_VALUE_REGISTER_CONVENTION
;
376 if (TYPE_CODE (type
) == TYPE_CODE_INT
377 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
381 /* Some sort of integer stored in r3. Since TYPE isn't
382 bigger than the register, sign extension isn't a problem
383 - just do everything unsigned. */
385 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
387 store_unsigned_integer (outval
, TYPE_LENGTH (type
), regval
);
391 /* Some sort of integer stored in r3. Use unpack_long since
392 that should handle any required sign extension. */
393 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
394 unpack_long (type
, inval
));
396 return RETURN_VALUE_REGISTER_CONVENTION
;
398 if (TYPE_LENGTH (type
) == 16
399 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
400 && TYPE_VECTOR (type
) && tdep
->ppc_vr0_regnum
>= 0)
404 /* Altivec places the return value in "v2". */
405 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, outval
);
409 /* Altivec places the return value in "v2". */
410 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, inval
);
412 return RETURN_VALUE_REGISTER_CONVENTION
;
414 if (TYPE_LENGTH (type
) == 8
415 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
416 && TYPE_VECTOR (type
) && tdep
->ppc_ev0_regnum
>= 0)
418 /* The e500 ABI places return values for the 64-bit DSP types
419 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
420 corresponds to the entire r3 value for e500, whereas GDB's r3
421 only corresponds to the least significant 32-bits. So place
422 the 64-bit DSP type's value in ev3. */
424 regcache_cooked_read (regcache
, tdep
->ppc_ev0_regnum
+ 3, outval
);
426 regcache_cooked_write (regcache
, tdep
->ppc_ev0_regnum
+ 3, inval
);
427 return RETURN_VALUE_REGISTER_CONVENTION
;
429 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
433 /* GCC screwed up. The last register isn't "left" aligned.
434 Need to extract the least significant part of each
435 register and then store that. */
436 /* Transfer any full words. */
441 int len
= TYPE_LENGTH (type
) - word
* tdep
->wordsize
;
444 if (len
> tdep
->wordsize
)
445 len
= tdep
->wordsize
;
446 regcache_cooked_read_unsigned (regcache
,
447 tdep
->ppc_gp0_regnum
+ 3 + word
,
449 store_unsigned_integer (((bfd_byte
*) outval
450 + word
* tdep
->wordsize
), len
, reg
);
456 /* GCC screwed up. The last register isn't "left" aligned.
457 Need to extract the least significant part of each
458 register and then store that. */
459 /* Transfer any full words. */
464 int len
= TYPE_LENGTH (type
) - word
* tdep
->wordsize
;
467 if (len
> tdep
->wordsize
)
468 len
= tdep
->wordsize
;
469 reg
= extract_unsigned_integer (((bfd_byte
*) inval
470 + word
* tdep
->wordsize
), len
);
471 regcache_cooked_write_unsigned (regcache
,
472 tdep
->ppc_gp0_regnum
+ 3 + word
,
477 return RETURN_VALUE_REGISTER_CONVENTION
;
479 if (TYPE_LENGTH (type
) <= 8)
483 /* This matches SVr4 PPC, it does not match GCC. */
484 /* The value is right-padded to 8 bytes and then loaded, as
485 two "words", into r3/r4. */
486 char regvals
[MAX_REGISTER_SIZE
* 2];
487 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
488 regvals
+ 0 * tdep
->wordsize
);
489 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
490 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
491 regvals
+ 1 * tdep
->wordsize
);
492 memcpy (outval
, regvals
, TYPE_LENGTH (type
));
496 /* This matches SVr4 PPC, it does not match GCC. */
497 /* The value is padded out to 8 bytes and then loaded, as
498 two "words" into r3/r4. */
499 char regvals
[MAX_REGISTER_SIZE
* 2];
500 memset (regvals
, 0, sizeof regvals
);
501 memcpy (regvals
, inval
, TYPE_LENGTH (type
));
502 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
503 regvals
+ 0 * tdep
->wordsize
);
504 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
505 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
506 regvals
+ 1 * tdep
->wordsize
);
508 return RETURN_VALUE_REGISTER_CONVENTION
;
510 return RETURN_VALUE_STRUCT_CONVENTION
;
514 ppc_sysv_abi_extract_return_value (struct type
*type
,
515 struct regcache
*regcache
, void *valbuf
)
517 do_ppc_sysv_return_value (type
, regcache
, NULL
, valbuf
, 0);
521 ppc_sysv_abi_broken_extract_return_value (struct type
*type
,
522 struct regcache
*regcache
,
525 do_ppc_sysv_return_value (type
, regcache
, NULL
, valbuf
, 1);
529 ppc_sysv_abi_store_return_value (struct type
*type
, struct regcache
*regcache
,
532 do_ppc_sysv_return_value (type
, regcache
, valbuf
, NULL
, 0);
536 ppc_sysv_abi_broken_store_return_value (struct type
*type
,
537 struct regcache
*regcache
,
540 do_ppc_sysv_return_value (type
, regcache
, valbuf
, NULL
, 1);
543 /* Structures 8 bytes or less long are returned in the r3 & r4
544 registers, according to the SYSV ABI. */
546 ppc_sysv_abi_use_struct_convention (int gcc_p
, struct type
*value_type
)
548 return (do_ppc_sysv_return_value (value_type
, NULL
, NULL
, NULL
, 0)
549 == RETURN_VALUE_STRUCT_CONVENTION
);
552 /* Pass the arguments in either registers, or in the stack. Using the
555 This implements a dumbed down version of the ABI. It always writes
556 values to memory, GPR and FPR, even when not necessary. Doing this
557 greatly simplifies the logic. */
560 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
561 struct regcache
*regcache
, CORE_ADDR bp_addr
,
562 int nargs
, struct value
**args
, CORE_ADDR sp
,
563 int struct_return
, CORE_ADDR struct_addr
)
565 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
566 /* By this stage in the proceedings, SP has been decremented by "red
567 zone size" + "struct return size". Fetch the stack-pointer from
568 before this and use that as the BACK_CHAIN. */
569 const CORE_ADDR back_chain
= read_sp ();
570 /* See for-loop comment below. */
572 /* Size of the Altivec's vector parameter region, the final value is
573 computed in the for-loop below. */
574 LONGEST vparam_size
= 0;
575 /* Size of the general parameter region, the final value is computed
576 in the for-loop below. */
577 LONGEST gparam_size
= 0;
578 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
579 calls to align_up(), align_down(), etc. because this makes it
580 easier to reuse this code (in a copy/paste sense) in the future,
581 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
582 at some point makes it easier to verify that this function is
583 correct without having to do a non-local analysis to figure out
584 the possible values of tdep->wordsize. */
585 gdb_assert (tdep
->wordsize
== 8);
587 /* Go through the argument list twice.
589 Pass 1: Compute the function call's stack space and register
592 Pass 2: Replay the same computation but this time also write the
593 values out to the target. */
595 for (write_pass
= 0; write_pass
< 2; write_pass
++)
598 /* Next available floating point register for float and double
601 /* Next available general register for non-vector (but possibly
604 /* Next available vector register for vector arguments. */
606 /* The address, at which the next general purpose parameter
607 (integer, struct, float, ...) should be saved. */
609 /* Address, at which the next Altivec vector parameter should be
615 /* During the first pass, GPARAM and VPARAM are more like
616 offsets (start address zero) than addresses. That way
617 the accumulate the total stack space each region
624 /* Decrement the stack pointer making space for the Altivec
625 and general on-stack parameters. Set vparam and gparam
626 to their corresponding regions. */
627 vparam
= align_down (sp
- vparam_size
, 16);
628 gparam
= align_down (vparam
- gparam_size
, 16);
629 /* Add in space for the TOC, link editor double word,
630 compiler double word, LR save area, CR save area. */
631 sp
= align_down (gparam
- 48, 16);
634 /* If the function is returning a `struct', then there is an
635 extra hidden parameter (which will be passed in r3)
636 containing the address of that struct.. In that case we
637 should advance one word and start from r4 register to copy
638 parameters. This also consumes one on-stack parameter slot. */
642 regcache_cooked_write_signed (regcache
,
643 tdep
->ppc_gp0_regnum
+ greg
,
646 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
649 for (argno
= 0; argno
< nargs
; argno
++)
651 struct value
*arg
= args
[argno
];
652 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
653 char *val
= VALUE_CONTENTS (arg
);
654 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) <= 8)
656 /* Floats and Doubles go in f1 .. f13. They also
657 consume a left aligned GREG,, and can end up in
661 if (ppc_floating_point_unit_p (current_gdbarch
)
664 char regval
[MAX_REGISTER_SIZE
];
665 struct type
*regtype
= register_type (gdbarch
,
667 convert_typed_floating (val
, type
, regval
, regtype
);
668 regcache_cooked_write (regcache
, FP0_REGNUM
+ freg
,
673 /* The ABI states "Single precision floating
674 point values are mapped to the first word in
675 a single doubleword" and "... floating point
676 values mapped to the first eight doublewords
677 of the parameter save area are also passed in
680 This code interprets that to mean: store it,
681 left aligned, in the general register. */
682 char regval
[MAX_REGISTER_SIZE
];
683 memset (regval
, 0, sizeof regval
);
684 memcpy (regval
, val
, TYPE_LENGTH (type
));
685 regcache_cooked_write (regcache
,
686 tdep
->ppc_gp0_regnum
+ greg
,
689 write_memory (gparam
, val
, TYPE_LENGTH (type
));
691 /* Always consume parameter stack space. */
694 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
696 else if (TYPE_LENGTH (type
) == 16 && TYPE_VECTOR (type
)
697 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
698 && tdep
->ppc_vr0_regnum
>= 0)
700 /* In the Altivec ABI, vectors go in the vector
701 registers v2 .. v13, or when that runs out, a vector
702 annex which goes above all the normal parameters.
703 NOTE: cagney/2003-09-21: This is a guess based on the
704 PowerOpen Altivec ABI. */
708 regcache_cooked_write (regcache
,
709 tdep
->ppc_vr0_regnum
+ vreg
, val
);
715 write_memory (vparam
, val
, TYPE_LENGTH (type
));
716 vparam
= align_up (vparam
+ TYPE_LENGTH (type
), 16);
719 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
720 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
721 && TYPE_LENGTH (type
) <= 8)
723 /* Scalars get sign[un]extended and go in gpr3 .. gpr10.
724 They can also end up in memory. */
727 /* Sign extend the value, then store it unsigned. */
728 ULONGEST word
= unpack_long (type
, val
);
730 regcache_cooked_write_unsigned (regcache
,
731 tdep
->ppc_gp0_regnum
+
733 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
737 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
742 for (byte
= 0; byte
< TYPE_LENGTH (type
);
743 byte
+= tdep
->wordsize
)
745 if (write_pass
&& greg
<= 10)
747 char regval
[MAX_REGISTER_SIZE
];
748 int len
= TYPE_LENGTH (type
) - byte
;
749 if (len
> tdep
->wordsize
)
750 len
= tdep
->wordsize
;
751 memset (regval
, 0, sizeof regval
);
752 /* WARNING: cagney/2003-09-21: As best I can
753 tell, the ABI specifies that the value should
754 be left aligned. Unfortunately, GCC doesn't
755 do this - it instead right aligns even sized
756 values and puts odd sized values on the
757 stack. Work around that by putting both a
758 left and right aligned value into the
759 register (hopefully no one notices :-^).
761 /* Left aligned (8 byte values such as pointers
763 memcpy (regval
, val
+ byte
, len
);
764 /* Right aligned (but only if even). */
765 if (len
== 1 || len
== 2 || len
== 4)
766 memcpy (regval
+ tdep
->wordsize
- len
,
768 regcache_cooked_write (regcache
, greg
, regval
);
773 /* WARNING: cagney/2003-09-21: Strictly speaking, this
774 isn't necessary, unfortunately, GCC appears to get
775 "struct convention" parameter passing wrong putting
776 odd sized structures in memory instead of in a
777 register. Work around this by always writing the
778 value to memory. Fortunately, doing this
779 simplifies the code. */
780 write_memory (gparam
, val
, TYPE_LENGTH (type
));
781 /* Always consume parameter stack space. */
782 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
788 /* Save the true region sizes ready for the second pass. */
789 vparam_size
= vparam
;
790 /* Make certain that the general parameter save area is at
791 least the minimum 8 registers (or doublewords) in size. */
793 gparam_size
= 8 * tdep
->wordsize
;
795 gparam_size
= gparam
;
800 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
802 /* Write the backchain (it occupies WORDSIZED bytes). */
803 write_memory_signed_integer (sp
, tdep
->wordsize
, back_chain
);
805 /* Point the inferior function call's return address at the dummy's
807 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
809 /* Find a value for the TOC register. Every symbol should have both
810 ".FN" and "FN" in the minimal symbol table. "FN" points at the
811 FN's descriptor, while ".FN" points at the entry point (which
812 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
813 FN's descriptor address. */
815 /* Find the minimal symbol that corresponds to FUNC_ADDR (should
816 have the name ".FN"). */
817 struct minimal_symbol
*dot_fn
= lookup_minimal_symbol_by_pc (func_addr
);
818 if (dot_fn
!= NULL
&& SYMBOL_LINKAGE_NAME (dot_fn
)[0] == '.')
820 /* Now find the corresponding "FN" (dropping ".") minimal
822 struct minimal_symbol
*fn
=
823 lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn
) + 1, NULL
,
827 /* Got the address of that descriptor. The TOC is the
828 second double word. */
830 read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn
) +
831 tdep
->wordsize
, tdep
->wordsize
);
832 regcache_cooked_write_unsigned (regcache
,
833 tdep
->ppc_gp0_regnum
+ 2, toc
);
842 /* The 64 bit ABI retun value convention.
844 Return non-zero if the return-value is stored in a register, return
845 0 if the return-value is instead stored on the stack (a.k.a.,
846 struct return convention).
848 For a return-value stored in a register: when INVAL is non-NULL,
849 copy the buffer to the corresponding register return-value location
850 location; when OUTVAL is non-NULL, fill the buffer from the
851 corresponding register return-value location. */
852 static enum return_value_convention
853 ppc64_sysv_abi_return_value (struct type
*valtype
, struct regcache
*regcache
,
854 const void *inval
, void *outval
)
856 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
857 /* Floats and doubles in F1. */
858 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
&& TYPE_LENGTH (valtype
) <= 8)
860 char regval
[MAX_REGISTER_SIZE
];
861 struct type
*regtype
= register_type (current_gdbarch
, FP0_REGNUM
);
864 convert_typed_floating (inval
, valtype
, regval
, regtype
);
865 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1, regval
);
869 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1, regval
);
870 convert_typed_floating (regval
, regtype
, outval
, valtype
);
872 return RETURN_VALUE_REGISTER_CONVENTION
;
874 if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 8)
876 /* Integers in r3. */
879 /* Be careful to sign extend the value. */
880 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
881 unpack_long (valtype
, inval
));
885 /* Extract the integer from r3. Since this is truncating the
886 value, there isn't a sign extension problem. */
888 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
890 store_unsigned_integer (outval
, TYPE_LENGTH (valtype
), regval
);
892 return RETURN_VALUE_REGISTER_CONVENTION
;
894 /* All pointers live in r3. */
895 if (TYPE_CODE (valtype
) == TYPE_CODE_PTR
)
897 /* All pointers live in r3. */
899 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, inval
);
901 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, outval
);
902 return RETURN_VALUE_REGISTER_CONVENTION
;
904 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
905 && TYPE_LENGTH (valtype
) <= 8
906 && TYPE_CODE (TYPE_TARGET_TYPE (valtype
)) == TYPE_CODE_INT
907 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
909 /* Small character arrays are returned, right justified, in r3. */
910 int offset
= (register_size (current_gdbarch
, tdep
->ppc_gp0_regnum
+ 3)
911 - TYPE_LENGTH (valtype
));
913 regcache_cooked_write_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
914 offset
, TYPE_LENGTH (valtype
), inval
);
916 regcache_cooked_read_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
917 offset
, TYPE_LENGTH (valtype
), outval
);
918 return RETURN_VALUE_REGISTER_CONVENTION
;
920 /* Big floating point values get stored in adjacent floating
922 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
923 && (TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 32))
925 if (inval
|| outval
!= NULL
)
928 for (i
= 0; i
< TYPE_LENGTH (valtype
) / 8; i
++)
931 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1 + i
,
932 (const bfd_byte
*) inval
+ i
* 8);
934 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1 + i
,
935 (bfd_byte
*) outval
+ i
* 8);
938 return RETURN_VALUE_REGISTER_CONVENTION
;
940 /* Complex values get returned in f1:f2, need to convert. */
941 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
942 && (TYPE_LENGTH (valtype
) == 8 || TYPE_LENGTH (valtype
) == 16))
944 if (regcache
!= NULL
)
947 for (i
= 0; i
< 2; i
++)
949 char regval
[MAX_REGISTER_SIZE
];
950 struct type
*regtype
=
951 register_type (current_gdbarch
, FP0_REGNUM
);
954 convert_typed_floating ((const bfd_byte
*) inval
+
955 i
* (TYPE_LENGTH (valtype
) / 2),
956 valtype
, regval
, regtype
);
957 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1 + i
,
962 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1 + i
, regval
);
963 convert_typed_floating (regval
, regtype
,
964 (bfd_byte
*) outval
+
965 i
* (TYPE_LENGTH (valtype
) / 2),
970 return RETURN_VALUE_REGISTER_CONVENTION
;
972 /* Big complex values get stored in f1:f4. */
973 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
&& TYPE_LENGTH (valtype
) == 32)
975 if (regcache
!= NULL
)
978 for (i
= 0; i
< 4; i
++)
981 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1 + i
,
982 (const bfd_byte
*) inval
+ i
* 8);
984 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1 + i
,
985 (bfd_byte
*) outval
+ i
* 8);
988 return RETURN_VALUE_REGISTER_CONVENTION
;
990 return RETURN_VALUE_STRUCT_CONVENTION
;
994 ppc64_sysv_abi_use_struct_convention (int gcc_p
, struct type
*value_type
)
996 return (ppc64_sysv_abi_return_value (value_type
, NULL
, NULL
, NULL
)
997 == RETURN_VALUE_STRUCT_CONVENTION
);
1001 ppc64_sysv_abi_extract_return_value (struct type
*valtype
,
1002 struct regcache
*regbuf
, void *valbuf
)
1004 if (ppc64_sysv_abi_return_value (valtype
, regbuf
, NULL
, valbuf
)
1005 != RETURN_VALUE_REGISTER_CONVENTION
)
1006 error ("Function return value unknown");
1010 ppc64_sysv_abi_store_return_value (struct type
*valtype
,
1011 struct regcache
*regbuf
,
1014 if (!ppc64_sysv_abi_return_value (valtype
, regbuf
, valbuf
, NULL
))
1015 error ("Function return value location unknown");
1019 ppc64_sysv_abi_adjust_breakpoint_address (struct gdbarch
*gdbarch
,
1022 /* PPC64 SYSV specifies that the minimal-symbol "FN" should point at
1023 a function-descriptor while the corresponding minimal-symbol
1024 ".FN" should point at the entry point. Consequently, a command
1025 like "break FN" applied to an object file with only minimal
1026 symbols, will insert the breakpoint into the descriptor at "FN"
1027 and not the function at ".FN". Avoid this confusion by adjusting
1028 any attempt to set a descriptor breakpoint into a corresponding
1029 function breakpoint. Note that GDB warns the user when this
1030 adjustment is applied - that's ok as otherwise the user will have
1031 no way of knowing why their breakpoint at "FN" resulted in the
1032 program stopping at ".FN". */
1033 return gdbarch_convert_from_func_ptr_addr (gdbarch
, bpaddr
, ¤t_target
);