1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright 2000, 2001, 2002 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"
32 /* Pass the arguments in either registers, or in the stack. Using the
33 ppc sysv ABI, the first eight words of the argument list (that might
34 be less than eight parameters if some parameters occupy more than one
35 word) are passed in r3..r10 registers. float and double parameters are
36 passed in fpr's, in addition to that. Rest of the parameters if any
37 are passed in user stack.
39 If the function is returning a structure, then the return address is passed
40 in r3, then the first 7 words of the parametes can be passed in registers,
44 ppc_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
45 struct regcache
*regcache
, CORE_ADDR bp_addr
,
46 int nargs
, struct value
**args
, CORE_ADDR sp
,
47 int struct_return
, CORE_ADDR struct_addr
)
49 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
50 const CORE_ADDR saved_sp
= read_sp ();
51 int argspace
= 0; /* 0 is an initial wrong guess. */
54 /* Go through the argument list twice.
56 Pass 1: Figure out how much new stack space is required for
57 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
58 ABI doesn't reserve any extra space for parameters which are put
59 in registers, but does always push structures and then pass their
62 Pass 2: Replay the same computation but this time also write the
63 values out to the target. */
65 for (write_pass
= 0; write_pass
< 2; write_pass
++)
68 /* Next available floating point register for float and double
71 /* Next available general register for non-float, non-vector
74 /* Next available vector register for vector arguments. */
76 /* Arguments start above the "LR save word" and "Back chain". */
77 int argoffset
= 2 * tdep
->wordsize
;
78 /* Structures start after the arguments. */
79 int structoffset
= argoffset
+ argspace
;
81 /* If the function is returning a `struct', then the first word
82 (which will be passed in r3) is used for struct return
83 address. In that case we should advance one word and start
84 from r4 register to copy parameters. */
88 regcache_cooked_write_signed (regcache
,
89 tdep
->ppc_gp0_regnum
+ greg
,
94 for (argno
= 0; argno
< nargs
; argno
++)
96 struct value
*arg
= args
[argno
];
97 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
98 int len
= TYPE_LENGTH (type
);
99 char *val
= VALUE_CONTENTS (arg
);
101 if (TYPE_CODE (type
) == TYPE_CODE_FLT
102 && ppc_floating_point_unit_p (current_gdbarch
) && len
<= 8)
104 /* Floating point value converted to "double" then
105 passed in an FP register, when the registers run out,
106 8 byte aligned stack is used. */
111 /* Always store the floating point value using
112 the register's floating-point format. */
113 char regval
[MAX_REGISTER_SIZE
];
115 = register_type (gdbarch
, FP0_REGNUM
+ freg
);
116 convert_typed_floating (val
, type
, regval
, regtype
);
117 regcache_cooked_write (regcache
, FP0_REGNUM
+ freg
,
124 /* SysV ABI converts floats to doubles before
125 writing them to an 8 byte aligned stack location. */
126 argoffset
= align_up (argoffset
, 8);
130 struct type
*memtype
;
131 switch (TARGET_BYTE_ORDER
)
134 memtype
= builtin_type_ieee_double_big
;
136 case BFD_ENDIAN_LITTLE
:
137 memtype
= builtin_type_ieee_double_little
;
140 internal_error (__FILE__
, __LINE__
, "bad switch");
142 convert_typed_floating (val
, type
, memval
, memtype
);
143 write_memory (sp
+ argoffset
, val
, len
);
148 else if (len
== 8 && (TYPE_CODE (type
) == TYPE_CODE_INT
/* long long */
149 || (!ppc_floating_point_unit_p (current_gdbarch
) && TYPE_CODE (type
) == TYPE_CODE_FLT
))) /* double */
151 /* "long long" or "double" passed in an odd/even
152 register pair with the low addressed word in the odd
153 register and the high addressed word in the even
154 register, or when the registers run out an 8 byte
155 aligned stack location. */
158 /* Just in case GREG was 10. */
160 argoffset
= align_up (argoffset
, 8);
162 write_memory (sp
+ argoffset
, val
, len
);
165 else if (tdep
->wordsize
== 8)
168 regcache_cooked_write (regcache
,
169 tdep
->ppc_gp0_regnum
+ greg
, val
);
174 /* Must start on an odd register - r3/r4 etc. */
179 regcache_cooked_write (regcache
,
180 tdep
->ppc_gp0_regnum
+ greg
+ 0,
182 regcache_cooked_write (regcache
,
183 tdep
->ppc_gp0_regnum
+ greg
+ 1,
190 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
191 && TYPE_VECTOR (type
) && tdep
->ppc_vr0_regnum
>= 0)
193 /* Vector parameter passed in an Altivec register, or
194 when that runs out, 16 byte aligned stack location. */
198 regcache_cooked_write (current_regcache
,
199 tdep
->ppc_vr0_regnum
+ vreg
, val
);
204 argoffset
= align_up (argoffset
, 16);
206 write_memory (sp
+ argoffset
, val
, 16);
211 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
212 && TYPE_VECTOR (type
) && tdep
->ppc_ev0_regnum
>= 0)
214 /* Vector parameter passed in an e500 register, or when
215 that runs out, 8 byte aligned stack location. Note
216 that since e500 vector and general purpose registers
217 both map onto the same underlying register set, a
218 "greg" and not a "vreg" is consumed here. A cooked
219 write stores the value in the correct locations
220 within the raw register cache. */
224 regcache_cooked_write (current_regcache
,
225 tdep
->ppc_ev0_regnum
+ greg
, val
);
230 argoffset
= align_up (argoffset
, 8);
232 write_memory (sp
+ argoffset
, val
, 8);
238 /* Reduce the parameter down to something that fits in a
240 char word
[MAX_REGISTER_SIZE
];
241 memset (word
, 0, MAX_REGISTER_SIZE
);
242 if (len
> tdep
->wordsize
243 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
244 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
246 /* Structs and large values are put on an 8 byte
248 structoffset
= align_up (structoffset
, 8);
250 write_memory (sp
+ structoffset
, val
, len
);
251 /* ... and then a "word" pointing to that address is
252 passed as the parameter. */
253 store_unsigned_integer (word
, tdep
->wordsize
,
257 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
258 /* Sign or zero extend the "int" into a "word". */
259 store_unsigned_integer (word
, tdep
->wordsize
,
260 unpack_long (type
, val
));
262 /* Always goes in the low address. */
263 memcpy (word
, val
, len
);
264 /* Store that "word" in a register, or on the stack.
265 The words have "4" byte alignment. */
269 regcache_cooked_write (regcache
,
270 tdep
->ppc_gp0_regnum
+ greg
, word
);
275 argoffset
= align_up (argoffset
, tdep
->wordsize
);
277 write_memory (sp
+ argoffset
, word
, tdep
->wordsize
);
278 argoffset
+= tdep
->wordsize
;
283 /* Compute the actual stack space requirements. */
286 /* Remember the amount of space needed by the arguments. */
287 argspace
= argoffset
;
288 /* Allocate space for both the arguments and the structures. */
289 sp
-= (argoffset
+ structoffset
);
290 /* Ensure that the stack is still 16 byte aligned. */
291 sp
= align_down (sp
, 16);
296 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
298 /* Write the backchain (it occupies WORDSIZED bytes). */
299 write_memory_signed_integer (sp
, tdep
->wordsize
, saved_sp
);
301 /* Point the inferior function call's return address at the dummy's
303 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
308 /* Handle the return-value conventions specified by the SysV 32-bit
309 PowerPC ABI (including all the supplements):
311 no floating-point: floating-point values returned using 32-bit
312 general-purpose registers.
314 Altivec: 128-bit vectors returned using vector registers.
316 e500: 64-bit vectors returned using the full full 64 bit EV
317 register, floating-point values returned using 32-bit
318 general-purpose registers.
320 GCC (broken): Small struct values right (instead of left) aligned
321 when returned in general-purpose registers. */
323 static enum return_value_convention
324 do_ppc_sysv_return_value (struct type
*type
, struct regcache
*regcache
,
325 const void *inval
, void *outval
, int broken_gcc
)
327 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
328 gdb_assert (tdep
->wordsize
== 4);
329 if (TYPE_CODE (type
) == TYPE_CODE_FLT
330 && TYPE_LENGTH (type
) <= 8
331 && ppc_floating_point_unit_p (current_gdbarch
))
335 /* Floats and doubles stored in "f1". Convert the value to
336 the required type. */
337 char regval
[MAX_REGISTER_SIZE
];
338 struct type
*regtype
= register_type (current_gdbarch
,
340 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1, regval
);
341 convert_typed_floating (regval
, regtype
, outval
, type
);
345 /* Floats and doubles stored in "f1". Convert the value to
346 the register's "double" type. */
347 char regval
[MAX_REGISTER_SIZE
];
348 struct type
*regtype
= register_type (current_gdbarch
, FP0_REGNUM
);
349 convert_typed_floating (inval
, type
, regval
, regtype
);
350 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1, regval
);
352 return RETURN_VALUE_REGISTER_CONVENTION
;
354 if ((TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_LENGTH (type
) == 8)
355 || (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8))
359 /* A long long, or a double stored in the 32 bit r3/r4. */
360 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
361 (bfd_byte
*) outval
+ 0);
362 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
363 (bfd_byte
*) outval
+ 4);
367 /* A long long, or a double stored in the 32 bit r3/r4. */
368 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
369 (bfd_byte
*) inval
+ 0);
370 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
371 (bfd_byte
*) inval
+ 4);
373 return RETURN_VALUE_REGISTER_CONVENTION
;
375 if (TYPE_CODE (type
) == TYPE_CODE_INT
376 && TYPE_LENGTH (type
) <= tdep
->wordsize
)
380 /* Some sort of integer stored in r3. Since TYPE isn't
381 bigger than the register, sign extension isn't a problem
382 - just do everything unsigned. */
384 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
386 store_unsigned_integer (outval
, TYPE_LENGTH (type
), regval
);
390 /* Some sort of integer stored in r3. Use unpack_long since
391 that should handle any required sign extension. */
392 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
393 unpack_long (type
, inval
));
395 return RETURN_VALUE_REGISTER_CONVENTION
;
397 if (TYPE_LENGTH (type
) == 16
398 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
399 && TYPE_VECTOR (type
) && tdep
->ppc_vr0_regnum
>= 0)
403 /* Altivec places the return value in "v2". */
404 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, outval
);
408 /* Altivec places the return value in "v2". */
409 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, inval
);
411 return RETURN_VALUE_REGISTER_CONVENTION
;
413 if (TYPE_LENGTH (type
) == 8
414 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
415 && TYPE_VECTOR (type
) && tdep
->ppc_ev0_regnum
>= 0)
417 /* The e500 ABI places return values for the 64-bit DSP types
418 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
419 corresponds to the entire r3 value for e500, whereas GDB's r3
420 only corresponds to the least significant 32-bits. So place
421 the 64-bit DSP type's value in ev3. */
423 regcache_cooked_read (regcache
, tdep
->ppc_ev0_regnum
+ 3, outval
);
425 regcache_cooked_write (regcache
, tdep
->ppc_ev0_regnum
+ 3, inval
);
426 return RETURN_VALUE_REGISTER_CONVENTION
;
428 if (broken_gcc
&& TYPE_LENGTH (type
) <= 8)
432 /* GCC screwed up. The last register isn't "left" aligned.
433 Need to extract the least significant part of each
434 register and then store that. */
435 /* Transfer any full words. */
440 int len
= TYPE_LENGTH (type
) - word
* tdep
->wordsize
;
443 if (len
> tdep
->wordsize
)
444 len
= tdep
->wordsize
;
445 regcache_cooked_read_unsigned (regcache
,
446 tdep
->ppc_gp0_regnum
+ 3 + word
,
448 store_unsigned_integer (((bfd_byte
*) outval
449 + word
* tdep
->wordsize
), len
, reg
);
455 /* GCC screwed up. The last register isn't "left" aligned.
456 Need to extract the least significant part of each
457 register and then store that. */
458 /* Transfer any full words. */
463 int len
= TYPE_LENGTH (type
) - word
* tdep
->wordsize
;
466 if (len
> tdep
->wordsize
)
467 len
= tdep
->wordsize
;
468 reg
= extract_unsigned_integer (((bfd_byte
*) inval
469 + word
* tdep
->wordsize
), len
);
470 regcache_cooked_write_unsigned (regcache
,
471 tdep
->ppc_gp0_regnum
+ 3 + word
,
476 return RETURN_VALUE_REGISTER_CONVENTION
;
478 if (TYPE_LENGTH (type
) <= 8)
482 /* This matches SVr4 PPC, it does not match GCC. */
483 /* The value is right-padded to 8 bytes and then loaded, as
484 two "words", into r3/r4. */
485 char regvals
[MAX_REGISTER_SIZE
* 2];
486 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3,
487 regvals
+ 0 * tdep
->wordsize
);
488 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
489 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
490 regvals
+ 1 * tdep
->wordsize
);
491 memcpy (outval
, regvals
, TYPE_LENGTH (type
));
495 /* This matches SVr4 PPC, it does not match GCC. */
496 /* The value is padded out to 8 bytes and then loaded, as
497 two "words" into r3/r4. */
498 char regvals
[MAX_REGISTER_SIZE
* 2];
499 memset (regvals
, 0, sizeof regvals
);
500 memcpy (regvals
, inval
, TYPE_LENGTH (type
));
501 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3,
502 regvals
+ 0 * tdep
->wordsize
);
503 if (TYPE_LENGTH (type
) > tdep
->wordsize
)
504 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
505 regvals
+ 1 * tdep
->wordsize
);
507 return RETURN_VALUE_REGISTER_CONVENTION
;
509 return RETURN_VALUE_STRUCT_CONVENTION
;
513 ppc_sysv_abi_extract_return_value (struct type
*type
,
514 struct regcache
*regcache
, void *valbuf
)
516 do_ppc_sysv_return_value (type
, regcache
, NULL
, valbuf
, 0);
520 ppc_sysv_abi_broken_extract_return_value (struct type
*type
,
521 struct regcache
*regcache
,
524 do_ppc_sysv_return_value (type
, regcache
, NULL
, valbuf
, 1);
528 ppc_sysv_abi_store_return_value (struct type
*type
, struct regcache
*regcache
,
531 do_ppc_sysv_return_value (type
, regcache
, valbuf
, NULL
, 0);
535 ppc_sysv_abi_broken_store_return_value (struct type
*type
,
536 struct regcache
*regcache
,
539 do_ppc_sysv_return_value (type
, regcache
, valbuf
, NULL
, 1);
542 /* Structures 8 bytes or less long are returned in the r3 & r4
543 registers, according to the SYSV ABI. */
545 ppc_sysv_abi_use_struct_convention (int gcc_p
, struct type
*value_type
)
547 return (do_ppc_sysv_return_value (value_type
, NULL
, NULL
, NULL
, 0)
548 == RETURN_VALUE_STRUCT_CONVENTION
);
551 /* Pass the arguments in either registers, or in the stack. Using the
554 This implements a dumbed down version of the ABI. It always writes
555 values to memory, GPR and FPR, even when not necessary. Doing this
556 greatly simplifies the logic. */
559 ppc64_sysv_abi_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
560 struct regcache
*regcache
, CORE_ADDR bp_addr
,
561 int nargs
, struct value
**args
, CORE_ADDR sp
,
562 int struct_return
, CORE_ADDR struct_addr
)
564 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
565 /* By this stage in the proceedings, SP has been decremented by "red
566 zone size" + "struct return size". Fetch the stack-pointer from
567 before this and use that as the BACK_CHAIN. */
568 const CORE_ADDR back_chain
= read_sp ();
569 /* See for-loop comment below. */
571 /* Size of the Altivec's vector parameter region, the final value is
572 computed in the for-loop below. */
573 LONGEST vparam_size
= 0;
574 /* Size of the general parameter region, the final value is computed
575 in the for-loop below. */
576 LONGEST gparam_size
= 0;
577 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
578 calls to align_up(), align_down(), etc. because this makes it
579 easier to reuse this code (in a copy/paste sense) in the future,
580 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
581 at some point makes it easier to verify that this function is
582 correct without having to do a non-local analysis to figure out
583 the possible values of tdep->wordsize. */
584 gdb_assert (tdep
->wordsize
== 8);
586 /* Go through the argument list twice.
588 Pass 1: Compute the function call's stack space and register
591 Pass 2: Replay the same computation but this time also write the
592 values out to the target. */
594 for (write_pass
= 0; write_pass
< 2; write_pass
++)
597 /* Next available floating point register for float and double
600 /* Next available general register for non-vector (but possibly
603 /* Next available vector register for vector arguments. */
605 /* The address, at which the next general purpose parameter
606 (integer, struct, float, ...) should be saved. */
608 /* Address, at which the next Altivec vector parameter should be
614 /* During the first pass, GPARAM and VPARAM are more like
615 offsets (start address zero) than addresses. That way
616 the accumulate the total stack space each region
623 /* Decrement the stack pointer making space for the Altivec
624 and general on-stack parameters. Set vparam and gparam
625 to their corresponding regions. */
626 vparam
= align_down (sp
- vparam_size
, 16);
627 gparam
= align_down (vparam
- gparam_size
, 16);
628 /* Add in space for the TOC, link editor double word,
629 compiler double word, LR save area, CR save area. */
630 sp
= align_down (gparam
- 48, 16);
633 /* If the function is returning a `struct', then there is an
634 extra hidden parameter (which will be passed in r3)
635 containing the address of that struct.. In that case we
636 should advance one word and start from r4 register to copy
637 parameters. This also consumes one on-stack parameter slot. */
641 regcache_cooked_write_signed (regcache
,
642 tdep
->ppc_gp0_regnum
+ greg
,
645 gparam
= align_up (gparam
+ tdep
->wordsize
, tdep
->wordsize
);
648 for (argno
= 0; argno
< nargs
; argno
++)
650 struct value
*arg
= args
[argno
];
651 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
652 char *val
= VALUE_CONTENTS (arg
);
653 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) <= 8)
655 /* Floats and Doubles go in f1 .. f13. They also
656 consume a left aligned GREG,, and can end up in
660 if (ppc_floating_point_unit_p (current_gdbarch
)
663 char regval
[MAX_REGISTER_SIZE
];
664 struct type
*regtype
= register_type (gdbarch
,
666 convert_typed_floating (val
, type
, regval
, regtype
);
667 regcache_cooked_write (regcache
, FP0_REGNUM
+ freg
,
672 /* The ABI states "Single precision floating
673 point values are mapped to the first word in
674 a single doubleword" and "... floating point
675 values mapped to the first eight doublewords
676 of the parameter save area are also passed in
679 This code interprets that to mean: store it,
680 left aligned, in the general register. */
681 char regval
[MAX_REGISTER_SIZE
];
682 memset (regval
, 0, sizeof regval
);
683 memcpy (regval
, val
, TYPE_LENGTH (type
));
684 regcache_cooked_write (regcache
,
685 tdep
->ppc_gp0_regnum
+ greg
,
688 write_memory (gparam
, val
, TYPE_LENGTH (type
));
690 /* Always consume parameter stack space. */
693 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
695 else if (TYPE_LENGTH (type
) == 16 && TYPE_VECTOR (type
)
696 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
697 && tdep
->ppc_vr0_regnum
>= 0)
699 /* In the Altivec ABI, vectors go in the vector
700 registers v2 .. v13, or when that runs out, a vector
701 annex which goes above all the normal parameters.
702 NOTE: cagney/2003-09-21: This is a guess based on the
703 PowerOpen Altivec ABI. */
707 regcache_cooked_write (regcache
,
708 tdep
->ppc_vr0_regnum
+ vreg
, val
);
714 write_memory (vparam
, val
, TYPE_LENGTH (type
));
715 vparam
= align_up (vparam
+ TYPE_LENGTH (type
), 16);
718 else if ((TYPE_CODE (type
) == TYPE_CODE_INT
719 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
720 && TYPE_LENGTH (type
) <= 8)
722 /* Scalars get sign[un]extended and go in gpr3 .. gpr10.
723 They can also end up in memory. */
726 /* Sign extend the value, then store it unsigned. */
727 ULONGEST word
= unpack_long (type
, val
);
729 regcache_cooked_write_unsigned (regcache
,
730 tdep
->ppc_gp0_regnum
+
732 write_memory_unsigned_integer (gparam
, tdep
->wordsize
,
736 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
741 for (byte
= 0; byte
< TYPE_LENGTH (type
);
742 byte
+= tdep
->wordsize
)
744 if (write_pass
&& greg
<= 10)
746 char regval
[MAX_REGISTER_SIZE
];
747 int len
= TYPE_LENGTH (type
) - byte
;
748 if (len
> tdep
->wordsize
)
749 len
= tdep
->wordsize
;
750 memset (regval
, 0, sizeof regval
);
751 /* WARNING: cagney/2003-09-21: As best I can
752 tell, the ABI specifies that the value should
753 be left aligned. Unfortunately, GCC doesn't
754 do this - it instead right aligns even sized
755 values and puts odd sized values on the
756 stack. Work around that by putting both a
757 left and right aligned value into the
758 register (hopefully no one notices :-^).
760 /* Left aligned (8 byte values such as pointers
762 memcpy (regval
, val
+ byte
, len
);
763 /* Right aligned (but only if even). */
764 if (len
== 1 || len
== 2 || len
== 4)
765 memcpy (regval
+ tdep
->wordsize
- len
,
767 regcache_cooked_write (regcache
, greg
, regval
);
772 /* WARNING: cagney/2003-09-21: Strictly speaking, this
773 isn't necessary, unfortunately, GCC appears to get
774 "struct convention" parameter passing wrong putting
775 odd sized structures in memory instead of in a
776 register. Work around this by always writing the
777 value to memory. Fortunately, doing this
778 simplifies the code. */
779 write_memory (gparam
, val
, TYPE_LENGTH (type
));
780 /* Always consume parameter stack space. */
781 gparam
= align_up (gparam
+ TYPE_LENGTH (type
), tdep
->wordsize
);
787 /* Save the true region sizes ready for the second pass. */
788 vparam_size
= vparam
;
789 /* Make certain that the general parameter save area is at
790 least the minimum 8 registers (or doublewords) in size. */
792 gparam_size
= 8 * tdep
->wordsize
;
794 gparam_size
= gparam
;
799 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
801 /* Write the backchain (it occupies WORDSIZED bytes). */
802 write_memory_signed_integer (sp
, tdep
->wordsize
, back_chain
);
804 /* Point the inferior function call's return address at the dummy's
806 regcache_cooked_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
808 /* Find a value for the TOC register. Every symbol should have both
809 ".FN" and "FN" in the minimal symbol table. "FN" points at the
810 FN's descriptor, while ".FN" points at the entry point (which
811 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
812 FN's descriptor address. */
814 /* Find the minimal symbol that corresponds to FUNC_ADDR (should
815 have the name ".FN"). */
816 struct minimal_symbol
*dot_fn
= lookup_minimal_symbol_by_pc (func_addr
);
817 if (dot_fn
!= NULL
&& SYMBOL_LINKAGE_NAME (dot_fn
)[0] == '.')
819 /* Now find the corresponding "FN" (dropping ".") minimal
821 struct minimal_symbol
*fn
=
822 lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn
) + 1, NULL
,
826 /* Got the address of that descriptor. The TOC is the
827 second double word. */
829 read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn
) +
830 tdep
->wordsize
, tdep
->wordsize
);
831 regcache_cooked_write_unsigned (regcache
,
832 tdep
->ppc_gp0_regnum
+ 2, toc
);
841 /* The 64 bit ABI retun value convention.
843 Return non-zero if the return-value is stored in a register, return
844 0 if the return-value is instead stored on the stack (a.k.a.,
845 struct return convention).
847 For a return-value stored in a register: when INVAL is non-NULL,
848 copy the buffer to the corresponding register return-value location
849 location; when OUTVAL is non-NULL, fill the buffer from the
850 corresponding register return-value location. */
851 static enum return_value_convention
852 ppc64_sysv_abi_return_value (struct type
*valtype
, struct regcache
*regcache
,
853 const void *inval
, void *outval
)
855 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
856 /* Floats and doubles in F1. */
857 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
&& TYPE_LENGTH (valtype
) <= 8)
859 char regval
[MAX_REGISTER_SIZE
];
860 struct type
*regtype
= register_type (current_gdbarch
, FP0_REGNUM
);
863 convert_typed_floating (inval
, valtype
, regval
, regtype
);
864 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1, regval
);
868 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1, regval
);
869 convert_typed_floating (regval
, regtype
, outval
, valtype
);
871 return RETURN_VALUE_REGISTER_CONVENTION
;
873 if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 8)
875 /* Integers in r3. */
878 /* Be careful to sign extend the value. */
879 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
880 unpack_long (valtype
, inval
));
884 /* Extract the integer from r3. Since this is truncating the
885 value, there isn't a sign extension problem. */
887 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
889 store_unsigned_integer (outval
, TYPE_LENGTH (valtype
), regval
);
891 return RETURN_VALUE_REGISTER_CONVENTION
;
893 /* All pointers live in r3. */
894 if (TYPE_CODE (valtype
) == TYPE_CODE_PTR
)
896 /* All pointers live in r3. */
898 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, inval
);
900 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, outval
);
901 return RETURN_VALUE_REGISTER_CONVENTION
;
903 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
904 && TYPE_LENGTH (valtype
) <= 8
905 && TYPE_CODE (TYPE_TARGET_TYPE (valtype
)) == TYPE_CODE_INT
906 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype
)) == 1)
908 /* Small character arrays are returned, right justified, in r3. */
909 int offset
= (register_size (current_gdbarch
, tdep
->ppc_gp0_regnum
+ 3)
910 - TYPE_LENGTH (valtype
));
912 regcache_cooked_write_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
913 offset
, TYPE_LENGTH (valtype
), inval
);
915 regcache_cooked_read_part (regcache
, tdep
->ppc_gp0_regnum
+ 3,
916 offset
, TYPE_LENGTH (valtype
), outval
);
917 return RETURN_VALUE_REGISTER_CONVENTION
;
919 /* Big floating point values get stored in adjacent floating
921 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
922 && (TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 32))
924 if (inval
|| outval
!= NULL
)
927 for (i
= 0; i
< TYPE_LENGTH (valtype
) / 8; i
++)
930 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1 + i
,
931 (const bfd_byte
*) inval
+ i
* 8);
933 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1 + i
,
934 (bfd_byte
*) outval
+ i
* 8);
937 return RETURN_VALUE_REGISTER_CONVENTION
;
939 /* Complex values get returned in f1:f2, need to convert. */
940 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
941 && (TYPE_LENGTH (valtype
) == 8 || TYPE_LENGTH (valtype
) == 16))
943 if (regcache
!= NULL
)
946 for (i
= 0; i
< 2; i
++)
948 char regval
[MAX_REGISTER_SIZE
];
949 struct type
*regtype
=
950 register_type (current_gdbarch
, FP0_REGNUM
);
953 convert_typed_floating ((const bfd_byte
*) inval
+
954 i
* (TYPE_LENGTH (valtype
) / 2),
955 valtype
, regval
, regtype
);
956 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1 + i
,
961 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1 + i
, regval
);
962 convert_typed_floating (regval
, regtype
,
963 (bfd_byte
*) outval
+
964 i
* (TYPE_LENGTH (valtype
) / 2),
969 return RETURN_VALUE_REGISTER_CONVENTION
;
971 /* Big complex values get stored in f1:f4. */
972 if (TYPE_CODE (valtype
) == TYPE_CODE_COMPLEX
&& TYPE_LENGTH (valtype
) == 32)
974 if (regcache
!= NULL
)
977 for (i
= 0; i
< 4; i
++)
980 regcache_cooked_write (regcache
, FP0_REGNUM
+ 1 + i
,
981 (const bfd_byte
*) inval
+ i
* 8);
983 regcache_cooked_read (regcache
, FP0_REGNUM
+ 1 + i
,
984 (bfd_byte
*) outval
+ i
* 8);
987 return RETURN_VALUE_REGISTER_CONVENTION
;
989 return RETURN_VALUE_STRUCT_CONVENTION
;
993 ppc64_sysv_abi_use_struct_convention (int gcc_p
, struct type
*value_type
)
995 return (ppc64_sysv_abi_return_value (value_type
, NULL
, NULL
, NULL
)
996 == RETURN_VALUE_STRUCT_CONVENTION
);
1000 ppc64_sysv_abi_extract_return_value (struct type
*valtype
,
1001 struct regcache
*regbuf
, void *valbuf
)
1003 if (ppc64_sysv_abi_return_value (valtype
, regbuf
, NULL
, valbuf
)
1004 != RETURN_VALUE_REGISTER_CONVENTION
)
1005 error ("Function return value unknown");
1009 ppc64_sysv_abi_store_return_value (struct type
*valtype
,
1010 struct regcache
*regbuf
,
1013 if (!ppc64_sysv_abi_return_value (valtype
, regbuf
, valbuf
, NULL
))
1014 error ("Function return value location unknown");