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"
34 /* Pass the arguments in either registers, or in the stack. Using the
35 ppc sysv ABI, the first eight words of the argument list (that might
36 be less than eight parameters if some parameters occupy more than one
37 word) are passed in r3..r10 registers. float and double parameters are
38 passed in fpr's, in addition to that. Rest of the parameters if any
39 are passed in user stack.
41 If the function is returning a structure, then the return address is passed
42 in r3, then the first 7 words of the parametes can be passed in registers,
46 ppc_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
47 struct regcache
*regcache
, CORE_ADDR bp_addr
,
48 int nargs
, struct value
**args
, CORE_ADDR sp
,
49 int struct_return
, CORE_ADDR struct_addr
)
51 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
52 const CORE_ADDR saved_sp
= read_sp ();
53 int argspace
= 0; /* 0 is an initial wrong guess. */
56 /* Go through the argument list twice.
58 Pass 1: Figure out how much new stack space is required for
59 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
60 ABI doesn't reserve any extra space for parameters which are put
61 in registers, but does always push structures and then pass their
64 Pass 2: Replay the same computation but this time also write the
65 values out to the target. */
67 for (write_pass
= 0; write_pass
< 2; write_pass
++)
70 /* Next available floating point register for float and double
73 /* Next available general register for non-float, non-vector
76 /* Next available vector register for vector arguments. */
78 /* Arguments start above the "LR save word" and "Back chain". */
79 int argoffset
= 2 * tdep
->wordsize
;
80 /* Structures start after the arguments. */
81 int structoffset
= argoffset
+ argspace
;
83 /* If the function is returning a `struct', then the first word
84 (which will be passed in r3) is used for struct return
85 address. In that case we should advance one word and start
86 from r4 register to copy parameters. */
90 regcache_cooked_write_signed (regcache
,
91 tdep
->ppc_gp0_regnum
+ greg
,
96 for (argno
= 0; argno
< nargs
; argno
++)
98 struct value
*arg
= args
[argno
];
99 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
100 int len
= TYPE_LENGTH (type
);
101 char *val
= VALUE_CONTENTS (arg
);
103 if (TYPE_CODE (type
) == TYPE_CODE_FLT
104 && ppc_floating_point_unit_p (current_gdbarch
) && len
<= 8)
106 /* Floating point value converted to "double" then
107 passed in an FP register, when the registers run out,
108 8 byte aligned stack is used. */
113 /* Always store the floating point value using
114 the register's floating-point format. */
115 char regval
[MAX_REGISTER_SIZE
];
117 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
+ freg
);
118 convert_typed_floating (val
, type
, regval
, regtype
);
119 regcache_cooked_write (regcache
,
120 tdep
->ppc_fp0_regnum
+ freg
,
127 /* SysV ABI converts floats to doubles before
128 writing them to an 8 byte aligned stack location. */
129 argoffset
= align_up (argoffset
, 8);
133 struct type
*memtype
;
134 switch (TARGET_BYTE_ORDER
)
137 memtype
= builtin_type_ieee_double_big
;
139 case BFD_ENDIAN_LITTLE
:
140 memtype
= builtin_type_ieee_double_little
;
143 internal_error (__FILE__
, __LINE__
, "bad switch");
145 convert_typed_floating (val
, type
, memval
, memtype
);
146 write_memory (sp
+ argoffset
, val
, len
);
151 else if (len
== 8 && (TYPE_CODE (type
) == TYPE_CODE_INT
/* long long */
152 || (!ppc_floating_point_unit_p (current_gdbarch
) && TYPE_CODE (type
) == TYPE_CODE_FLT
))) /* double */
154 /* "long long" or "double" passed in an odd/even
155 register pair with the low addressed word in the odd
156 register and the high addressed word in the even
157 register, or when the registers run out an 8 byte
158 aligned stack location. */
161 /* Just in case GREG was 10. */
163 argoffset
= align_up (argoffset
, 8);
165 write_memory (sp
+ argoffset
, val
, len
);
168 else if (tdep
->wordsize
== 8)
171 regcache_cooked_write (regcache
,
172 tdep
->ppc_gp0_regnum
+ greg
, val
);
177 /* Must start on an odd register - r3/r4 etc. */
182 regcache_cooked_write (regcache
,
183 tdep
->ppc_gp0_regnum
+ greg
+ 0,
185 regcache_cooked_write (regcache
,
186 tdep
->ppc_gp0_regnum
+ greg
+ 1,
193 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
194 && TYPE_VECTOR (type
) && tdep
->ppc_vr0_regnum
>= 0)
196 /* Vector parameter passed in an Altivec register, or
197 when that runs out, 16 byte aligned stack location. */
201 regcache_cooked_write (current_regcache
,
202 tdep
->ppc_vr0_regnum
+ vreg
, val
);
207 argoffset
= align_up (argoffset
, 16);
209 write_memory (sp
+ argoffset
, val
, 16);
214 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
215 && TYPE_VECTOR (type
) && tdep
->ppc_ev0_regnum
>= 0)
217 /* Vector parameter passed in an e500 register, or when
218 that runs out, 8 byte aligned stack location. Note
219 that since e500 vector and general purpose registers
220 both map onto the same underlying register set, a
221 "greg" and not a "vreg" is consumed here. A cooked
222 write stores the value in the correct locations
223 within the raw register cache. */
227 regcache_cooked_write (current_regcache
,
228 tdep
->ppc_ev0_regnum
+ greg
, val
);
233 argoffset
= align_up (argoffset
, 8);
235 write_memory (sp
+ argoffset
, val
, 8);
241 /* Reduce the parameter down to something that fits in a
243 char word
[MAX_REGISTER_SIZE
];
244 memset (word
, 0, MAX_REGISTER_SIZE
);
245 if (len
> tdep
->wordsize
246 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
247 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
249 /* Structs and large values are put on an 8 byte
251 structoffset
= align_up (structoffset
, 8);
253 write_memory (sp
+ structoffset
, val
, len
);
254 /* ... and then a "word" pointing to that address is
255 passed as the parameter. */
256 store_unsigned_integer (word
, tdep
->wordsize
,
260 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
261 /* Sign or zero extend the "int" into a "word". */
262 store_unsigned_integer (word
, tdep
->wordsize
,
263 unpack_long (type
, val
));
265 /* Always goes in the low address. */
266 memcpy (word
, val
, len
);
267 /* Store that "word" in a register, or on the stack.
268 The words have "4" byte alignment. */
272 regcache_cooked_write (regcache
,
273 tdep
->ppc_gp0_regnum
+ greg
, word
);
278 argoffset
= align_up (argoffset
, tdep
->wordsize
);
280 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
281 argoffset
+= tdep
->wordsize
;
286 /* Compute the actual stack space requirements. */
289 /* Remember the amount of space needed by the arguments. */
290 argspace
= argoffset
;
291 /* Allocate space for both the arguments and the structures. */
292 sp
-= (argoffset
+ structoffset
);
293 /* Ensure that the stack is still 16 byte aligned. */
294 sp
= align_down (sp
, 16);
299 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
301 /* Write the backchain (it occupies WORDSIZED bytes). */
302 write_memory_signed_integer (sp
, tdep
->wordsize
, saved_sp
);
304 /* Point the inferior function call's return address at the dummy's
306 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
311 /* Handle the return-value conventions specified by the SysV 32-bit
312 PowerPC ABI (including all the supplements):
314 no floating-point: floating-point values returned using 32-bit
315 general-purpose registers.
317 Altivec: 128-bit vectors returned using vector registers.
319 e500: 64-bit vectors returned using the full full 64 bit EV
320 register, floating-point values returned using 32-bit
321 general-purpose registers.
323 GCC (broken): Small struct values right (instead of left) aligned
324 when returned in general-purpose registers. */
326 static enum return_value_convention
327 do_ppc_sysv_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
328 struct regcache
*regcache
, void *readbuf
,
329 const void *writebuf
, int broken_gcc
)
331 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
332 gdb_assert (tdep
->wordsize
== 4);
333 if (TYPE_CODE (type
) == TYPE_CODE_FLT
334 && TYPE_LENGTH (type
) <= 8
335 && ppc_floating_point_unit_p (gdbarch
))
339 /* Floats and doubles stored in "f1". Convert the value to
340 the required type. */
341 char regval
[MAX_REGISTER_SIZE
];
342 struct type
*regtype
= register_type (gdbarch
,
343 tdep
->ppc_fp0_regnum
+ 1);
344 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
345 convert_typed_floating (regval
, regtype
, readbuf
, type
);
349 /* Floats and doubles stored in "f1". Convert the value to
350 the register's "double" type. */
351 char regval
[MAX_REGISTER_SIZE
];
352 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
353 convert_typed_floating (writebuf
, type
, regval
, regtype
);
354 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
356 return RETURN_VALUE_REGISTER_CONVENTION
;
358 if ((TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
359 || (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8))
363 /* A long long, or a double stored in the 32 bit r3/r4. */
364 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
365 (bfd_byte
*) readbuf
+ 0);
366 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
367 (bfd_byte
*) readbuf
+ 4);
371 /* A long long, or a double stored in the 32 bit r3/r4. */
372 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
373 (const bfd_byte
*) writebuf
+ 0);
374 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
375 (const bfd_byte
*) writebuf
+ 4);
377 return RETURN_VALUE_REGISTER_CONVENTION
;
379 if (TYPE_CODE (type
) == TYPE_CODE_INT
380 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
384 /* Some sort of integer stored in r3. Since TYPE isn't
385 bigger than the register, sign extension isn't a problem
386 - just do everything unsigned. */
388 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
390 store_unsigned_integer (readbuf
, TYPE_LENGTH (type
), regval
);
394 /* Some sort of integer stored in r3. Use unpack_long since
395 that should handle any required sign extension. */
396 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
397 unpack_long (type
, writebuf
));
399 return RETURN_VALUE_REGISTER_CONVENTION
;
401 if (TYPE_LENGTH (type
) == 16
402 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
403 && TYPE_VECTOR (type
) && tdep
->ppc_vr0_regnum
>= 0)
407 /* Altivec places the return value in "v2". */
408 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
412 /* Altivec places the return value in "v2". */
413 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, writebuf
);
415 return RETURN_VALUE_REGISTER_CONVENTION
;
417 if (TYPE_LENGTH (type
) == 8
418 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
419 && TYPE_VECTOR (type
) && tdep
->ppc_ev0_regnum
>= 0)
421 /* The e500 ABI places return values for the 64-bit DSP types
422 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
423 corresponds to the entire r3 value for e500, whereas GDB's r3
424 only corresponds to the least significant 32-bits. So place
425 the 64-bit DSP type's value in ev3. */
427 regcache_cooked_read (regcache
, tdep
->ppc_ev0_regnum
+ 3, readbuf
);
429 regcache_cooked_write (regcache
, tdep
->ppc_ev0_regnum
+ 3, writebuf
);
430 return RETURN_VALUE_REGISTER_CONVENTION
;
432 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
436 /* GCC screwed up. The last register isn't "left" aligned.
437 Need to extract the least significant part of each
438 register and then store that. */
439 /* Transfer any full words. */
444 int len
= TYPE_LENGTH (type
) - word
* tdep
->wordsize
;
447 if (len
> tdep
->wordsize
)
448 len
= tdep
->wordsize
;
449 regcache_cooked_read_unsigned (regcache
,
450 tdep
->ppc_gp0_regnum
+ 3 + word
,
452 store_unsigned_integer (((bfd_byte
*) readbuf
453 + word
* tdep
->wordsize
), len
, reg
);
459 /* GCC screwed up. The last register isn't "left" aligned.
460 Need to extract the least significant part of each
461 register and then store that. */
462 /* Transfer any full words. */
467 int len
= TYPE_LENGTH (type
) - word
* tdep
->wordsize
;
470 if (len
> tdep
->wordsize
)
471 len
= tdep
->wordsize
;
472 reg
= extract_unsigned_integer (((const bfd_byte
*) writebuf
473 + word
* tdep
->wordsize
), len
);
474 regcache_cooked_write_unsigned (regcache
,
475 tdep
->ppc_gp0_regnum
+ 3 + word
,
480 return RETURN_VALUE_REGISTER_CONVENTION
;
482 if (TYPE_LENGTH (type
) <= 8)
486 /* This matches SVr4 PPC, it does not match GCC. */
487 /* The value is right-padded to 8 bytes and then loaded, as
488 two "words", into r3/r4. */
489 char regvals
[MAX_REGISTER_SIZE
* 2];
490 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
491 regvals
+ 0 * tdep
->wordsize
);
492 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
493 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
494 regvals
+ 1 * tdep
->wordsize
);
495 memcpy (readbuf
, regvals
, TYPE_LENGTH (type
));
499 /* This matches SVr4 PPC, it does not match GCC. */
500 /* The value is padded out to 8 bytes and then loaded, as
501 two "words" into r3/r4. */
502 char regvals
[MAX_REGISTER_SIZE
* 2];
503 memset (regvals
, 0, sizeof regvals
);
504 memcpy (regvals
, writebuf
, TYPE_LENGTH (type
));
505 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
506 regvals
+ 0 * tdep
->wordsize
);
507 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
508 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
509 regvals
+ 1 * tdep
->wordsize
);
511 return RETURN_VALUE_REGISTER_CONVENTION
;
513 return RETURN_VALUE_STRUCT_CONVENTION
;
516 enum return_value_convention
517 ppc_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
518 struct regcache
*regcache
, void *readbuf
,
519 const void *writebuf
)
521 return do_ppc_sysv_return_value (gdbarch
, valtype
, regcache
, readbuf
,
525 enum return_value_convention
526 ppc_sysv_abi_broken_return_value (struct gdbarch
*gdbarch
,
527 struct type
*valtype
,
528 struct regcache
*regcache
,
529 void *readbuf
, const void *writebuf
)
531 return do_ppc_sysv_return_value (gdbarch
, valtype
, regcache
, readbuf
,
535 /* Pass the arguments in either registers, or in the stack. Using the
538 This implements a dumbed down version of the ABI. It always writes
539 values to memory, GPR and FPR, even when not necessary. Doing this
540 greatly simplifies the logic. */
543 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
544 struct regcache
*regcache
, CORE_ADDR bp_addr
,
545 int nargs
, struct value
**args
, CORE_ADDR sp
,
546 int struct_return
, CORE_ADDR struct_addr
)
548 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
549 /* By this stage in the proceedings, SP has been decremented by "red
550 zone size" + "struct return size". Fetch the stack-pointer from
551 before this and use that as the BACK_CHAIN. */
552 const CORE_ADDR back_chain
= read_sp ();
553 /* See for-loop comment below. */
555 /* Size of the Altivec's vector parameter region, the final value is
556 computed in the for-loop below. */
557 LONGEST vparam_size
= 0;
558 /* Size of the general parameter region, the final value is computed
559 in the for-loop below. */
560 LONGEST gparam_size
= 0;
561 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
562 calls to align_up(), align_down(), etc. because this makes it
563 easier to reuse this code (in a copy/paste sense) in the future,
564 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
565 at some point makes it easier to verify that this function is
566 correct without having to do a non-local analysis to figure out
567 the possible values of tdep->wordsize. */
568 gdb_assert (tdep
->wordsize
== 8);
570 /* Go through the argument list twice.
572 Pass 1: Compute the function call's stack space and register
575 Pass 2: Replay the same computation but this time also write the
576 values out to the target. */
578 for (write_pass
= 0; write_pass
< 2; write_pass
++)
581 /* Next available floating point register for float and double
584 /* Next available general register for non-vector (but possibly
587 /* Next available vector register for vector arguments. */
589 /* The address, at which the next general purpose parameter
590 (integer, struct, float, ...) should be saved. */
592 /* Address, at which the next Altivec vector parameter should be
598 /* During the first pass, GPARAM and VPARAM are more like
599 offsets (start address zero) than addresses. That way
600 the accumulate the total stack space each region
607 /* Decrement the stack pointer making space for the Altivec
608 and general on-stack parameters. Set vparam and gparam
609 to their corresponding regions. */
610 vparam
= align_down (sp
- vparam_size
, 16);
611 gparam
= align_down (vparam
- gparam_size
, 16);
612 /* Add in space for the TOC, link editor double word,
613 compiler double word, LR save area, CR save area. */
614 sp
= align_down (gparam
- 48, 16);
617 /* If the function is returning a `struct', then there is an
618 extra hidden parameter (which will be passed in r3)
619 containing the address of that struct.. In that case we
620 should advance one word and start from r4 register to copy
621 parameters. This also consumes one on-stack parameter slot. */
625 regcache_cooked_write_signed (regcache
,
626 tdep
->ppc_gp0_regnum
+ greg
,
629 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
632 for (argno
= 0; argno
< nargs
; argno
++)
634 struct value
*arg
= args
[argno
];
635 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
636 char *val
= VALUE_CONTENTS (arg
);
637 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) <= 8)
639 /* Floats and Doubles go in f1 .. f13. They also
640 consume a left aligned GREG,, and can end up in
644 if (ppc_floating_point_unit_p (current_gdbarch
)
647 char regval
[MAX_REGISTER_SIZE
];
649 = register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
650 convert_typed_floating (val
, type
, regval
, regtype
);
651 regcache_cooked_write (regcache
,
652 tdep
->ppc_fp0_regnum
+ freg
,
657 /* The ABI states "Single precision floating
658 point values are mapped to the first word in
659 a single doubleword" and "... floating point
660 values mapped to the first eight doublewords
661 of the parameter save area are also passed in
664 This code interprets that to mean: store it,
665 left aligned, in the general register. */
666 char regval
[MAX_REGISTER_SIZE
];
667 memset (regval
, 0, sizeof regval
);
668 memcpy (regval
, val
, TYPE_LENGTH (type
));
669 regcache_cooked_write (regcache
,
670 tdep
->ppc_gp0_regnum
+ greg
,
673 write_memory (gparam
, val
, TYPE_LENGTH (type
));
675 /* Always consume parameter stack space. */
678 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
680 else if (TYPE_LENGTH (type
) == 16 && TYPE_VECTOR (type
)
681 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
682 && tdep
->ppc_vr0_regnum
>= 0)
684 /* In the Altivec ABI, vectors go in the vector
685 registers v2 .. v13, or when that runs out, a vector
686 annex which goes above all the normal parameters.
687 NOTE: cagney/2003-09-21: This is a guess based on the
688 PowerOpen Altivec ABI. */
692 regcache_cooked_write (regcache
,
693 tdep
->ppc_vr0_regnum
+ vreg
, val
);
699 write_memory (vparam
, val
, TYPE_LENGTH (type
));
700 vparam
= align_up (vparam
+ TYPE_LENGTH (type
), 16);
703 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
704 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
705 && TYPE_LENGTH (type
) <= 8)
707 /* Scalars get sign[un]extended and go in gpr3 .. gpr10.
708 They can also end up in memory. */
711 /* Sign extend the value, then store it unsigned. */
712 ULONGEST word
= unpack_long (type
, val
);
714 regcache_cooked_write_unsigned (regcache
,
715 tdep
->ppc_gp0_regnum
+
717 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
721 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
726 for (byte
= 0; byte
< TYPE_LENGTH (type
);
727 byte
+= tdep
->wordsize
)
729 if (write_pass
&& greg
<= 10)
731 char regval
[MAX_REGISTER_SIZE
];
732 int len
= TYPE_LENGTH (type
) - byte
;
733 if (len
> tdep
->wordsize
)
734 len
= tdep
->wordsize
;
735 memset (regval
, 0, sizeof regval
);
736 /* WARNING: cagney/2003-09-21: As best I can
737 tell, the ABI specifies that the value should
738 be left aligned. Unfortunately, GCC doesn't
739 do this - it instead right aligns even sized
740 values and puts odd sized values on the
741 stack. Work around that by putting both a
742 left and right aligned value into the
743 register (hopefully no one notices :-^).
745 /* Left aligned (8 byte values such as pointers
747 memcpy (regval
, val
+ byte
, len
);
748 /* Right aligned (but only if even). */
749 if (len
== 1 || len
== 2 || len
== 4)
750 memcpy (regval
+ tdep
->wordsize
- len
,
752 regcache_cooked_write (regcache
, greg
, regval
);
757 /* WARNING: cagney/2003-09-21: Strictly speaking, this
758 isn't necessary, unfortunately, GCC appears to get
759 "struct convention" parameter passing wrong putting
760 odd sized structures in memory instead of in a
761 register. Work around this by always writing the
762 value to memory. Fortunately, doing this
763 simplifies the code. */
764 write_memory (gparam
, val
, TYPE_LENGTH (type
));
765 /* Always consume parameter stack space. */
766 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
772 /* Save the true region sizes ready for the second pass. */
773 vparam_size
= vparam
;
774 /* Make certain that the general parameter save area is at
775 least the minimum 8 registers (or doublewords) in size. */
777 gparam_size
= 8 * tdep
->wordsize
;
779 gparam_size
= gparam
;
784 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
786 /* Write the backchain (it occupies WORDSIZED bytes). */
787 write_memory_signed_integer (sp
, tdep
->wordsize
, back_chain
);
789 /* Point the inferior function call's return address at the dummy's
791 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
793 /* Find a value for the TOC register. Every symbol should have both
794 ".FN" and "FN" in the minimal symbol table. "FN" points at the
795 FN's descriptor, while ".FN" points at the entry point (which
796 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
797 FN's descriptor address (while at the same time being careful to
798 find "FN" in the same object file as ".FN"). */
800 /* Find the minimal symbol that corresponds to FUNC_ADDR (should
801 have the name ".FN"). */
802 struct minimal_symbol
*dot_fn
= lookup_minimal_symbol_by_pc (func_addr
);
803 if (dot_fn
!= NULL
&& SYMBOL_LINKAGE_NAME (dot_fn
)[0] == '.')
805 /* Get the section that contains FUNC_ADR. Need this for the
806 "objfile" that it contains. */
807 struct obj_section
*dot_fn_section
= find_pc_section (func_addr
);
808 if (dot_fn_section
!= NULL
&& dot_fn_section
->objfile
!= NULL
)
810 /* Now find the corresponding "FN" (dropping ".") minimal
811 symbol's address. Only look for the minimal symbol in
812 ".FN"'s object file - avoids problems when two object
813 files (i.e., shared libraries) contain a minimal symbol
814 with the same name. */
815 struct minimal_symbol
*fn
=
816 lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn
) + 1, NULL
,
817 dot_fn_section
->objfile
);
820 /* Got the address of that descriptor. The TOC is the
821 second double word. */
823 read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn
)
826 regcache_cooked_write_unsigned (regcache
,
827 tdep
->ppc_gp0_regnum
+ 2, toc
);
837 /* The 64 bit ABI retun value convention.
839 Return non-zero if the return-value is stored in a register, return
840 0 if the return-value is instead stored on the stack (a.k.a.,
841 struct return convention).
843 For a return-value stored in a register: when WRITEBUF is non-NULL,
844 copy the buffer to the corresponding register return-value location
845 location; when READBUF is non-NULL, fill the buffer from the
846 corresponding register return-value location. */
847 enum return_value_convention
848 ppc64_sysv_abi_return_value (struct gdbarch
*gdbarch
, struct type
*valtype
,
849 struct regcache
*regcache
, void *readbuf
,
850 const void *writebuf
)
852 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
854 /* This function exists to support a calling convention that
855 requires floating-point registers. It shouldn't be used on
856 processors that lack them. */
857 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
859 /* Floats and doubles in F1. */
860 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
&& TYPE_LENGTH (valtype
) <= 8)
862 char regval
[MAX_REGISTER_SIZE
];
863 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
864 if (writebuf
!= NULL
)
866 convert_typed_floating (writebuf
, valtype
, regval
, regtype
);
867 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
871 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
872 convert_typed_floating (regval
, regtype
, readbuf
, valtype
);
874 return RETURN_VALUE_REGISTER_CONVENTION
;
876 if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 8)
878 /* Integers in r3. */
879 if (writebuf
!= NULL
)
881 /* Be careful to sign extend the value. */
882 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
883 unpack_long (valtype
, writebuf
));
887 /* Extract the integer from r3. Since this is truncating the
888 value, there isn't a sign extension problem. */
890 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
892 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
), regval
);
894 return RETURN_VALUE_REGISTER_CONVENTION
;
896 /* All pointers live in r3. */
897 if (TYPE_CODE (valtype
) == TYPE_CODE_PTR
)
899 /* All pointers live in r3. */
900 if (writebuf
!= NULL
)
901 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
903 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, readbuf
);
904 return RETURN_VALUE_REGISTER_CONVENTION
;
906 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
907 && TYPE_LENGTH (valtype
) <= 8
908 && TYPE_CODE (TYPE_TARGET_TYPE (valtype
)) == TYPE_CODE_INT
909 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
911 /* Small character arrays are returned, right justified, in r3. */
912 int offset
= (register_size (gdbarch
, tdep
->ppc_gp0_regnum
+ 3)
913 - TYPE_LENGTH (valtype
));
914 if (writebuf
!= NULL
)
915 regcache_cooked_write_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
916 offset
, TYPE_LENGTH (valtype
), writebuf
);
918 regcache_cooked_read_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
919 offset
, TYPE_LENGTH (valtype
), readbuf
);
920 return RETURN_VALUE_REGISTER_CONVENTION
;
922 /* Big floating point values get stored in adjacent floating
924 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
925 && (TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 32))
927 if (writebuf
|| readbuf
!= NULL
)
930 for (i
= 0; i
< TYPE_LENGTH (valtype
) / 8; i
++)
932 if (writebuf
!= NULL
)
933 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
934 (const bfd_byte
*) writebuf
+ i
* 8);
936 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
937 (bfd_byte
*) readbuf
+ i
* 8);
940 return RETURN_VALUE_REGISTER_CONVENTION
;
942 /* Complex values get returned in f1:f2, need to convert. */
943 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
944 && (TYPE_LENGTH (valtype
) == 8 || TYPE_LENGTH (valtype
) == 16))
946 if (regcache
!= NULL
)
949 for (i
= 0; i
< 2; i
++)
951 char regval
[MAX_REGISTER_SIZE
];
952 struct type
*regtype
=
953 register_type (current_gdbarch
, tdep
->ppc_fp0_regnum
);
954 if (writebuf
!= NULL
)
956 convert_typed_floating ((const bfd_byte
*) writebuf
+
957 i
* (TYPE_LENGTH (valtype
) / 2),
958 valtype
, regval
, regtype
);
959 regcache_cooked_write (regcache
,
960 tdep
->ppc_fp0_regnum
+ 1 + i
,
965 regcache_cooked_read (regcache
,
966 tdep
->ppc_fp0_regnum
+ 1 + i
,
968 convert_typed_floating (regval
, regtype
,
969 (bfd_byte
*) readbuf
+
970 i
* (TYPE_LENGTH (valtype
) / 2),
975 return RETURN_VALUE_REGISTER_CONVENTION
;
977 /* Big complex values get stored in f1:f4. */
978 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
&& TYPE_LENGTH (valtype
) == 32)
980 if (regcache
!= NULL
)
983 for (i
= 0; i
< 4; i
++)
985 if (writebuf
!= NULL
)
986 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
987 (const bfd_byte
*) writebuf
+ i
* 8);
989 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1 + i
,
990 (bfd_byte
*) readbuf
+ i
* 8);
993 return RETURN_VALUE_REGISTER_CONVENTION
;
995 return RETURN_VALUE_STRUCT_CONVENTION
;
999 ppc64_sysv_abi_adjust_breakpoint_address (struct gdbarch
*gdbarch
,
1002 /* PPC64 SYSV specifies that the minimal-symbol "FN" should point at
1003 a function-descriptor while the corresponding minimal-symbol
1004 ".FN" should point at the entry point. Consequently, a command
1005 like "break FN" applied to an object file with only minimal
1006 symbols, will insert the breakpoint into the descriptor at "FN"
1007 and not the function at ".FN". Avoid this confusion by adjusting
1008 any attempt to set a descriptor breakpoint into a corresponding
1009 function breakpoint. Note that GDB warns the user when this
1010 adjustment is applied - that's ok as otherwise the user will have
1011 no way of knowing why their breakpoint at "FN" resulted in the
1012 program stopping at ".FN". */
1013 return gdbarch_convert_from_func_ptr_addr (gdbarch
, bpaddr
, ¤t_target
);