1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright 2000, 2001, 2002, 2003, 2005
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
29 #include "gdb_string.h"
30 #include "gdb_assert.h"
36 /* Pass the arguments in either registers, or in the stack. Using the
37 ppc sysv ABI, the first eight words of the argument list (that might
38 be less than eight parameters if some parameters occupy more than one
39 word) are passed in r3..r10 registers. float and double parameters are
40 passed in fpr's, in addition to that. Rest of the parameters if any
41 are passed in user stack.
43 If the function is returning a structure, then the return address is passed
44 in r3, then the first 7 words of the parametes can be passed in registers,
48 ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
49 struct regcache *regcache, CORE_ADDR bp_addr,
50 int nargs, struct value **args, CORE_ADDR sp,
51 int struct_return, CORE_ADDR struct_addr)
53 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
54 const CORE_ADDR saved_sp = read_sp ();
55 int argspace = 0; /* 0 is an initial wrong guess. */
58 /* Go through the argument list twice.
60 Pass 1: Figure out how much new stack space is required for
61 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
62 ABI doesn't reserve any extra space for parameters which are put
63 in registers, but does always push structures and then pass their
66 Pass 2: Replay the same computation but this time also write the
67 values out to the target. */
69 for (write_pass = 0; write_pass < 2; write_pass++)
72 /* Next available floating point register for float and double
75 /* Next available general register for non-float, non-vector
78 /* Next available vector register for vector arguments. */
80 /* Arguments start above the "LR save word" and "Back chain". */
81 int argoffset = 2 * tdep->wordsize;
82 /* Structures start after the arguments. */
83 int structoffset = argoffset + argspace;
85 /* If the function is returning a `struct', then the first word
86 (which will be passed in r3) is used for struct return
87 address. In that case we should advance one word and start
88 from r4 register to copy parameters. */
92 regcache_cooked_write_signed (regcache,
93 tdep->ppc_gp0_regnum + greg,
98 for (argno = 0; argno < nargs; argno++)
100 struct value *arg = args[argno];
101 struct type *type = check_typedef (value_type (arg));
102 int len = TYPE_LENGTH (type);
103 const bfd_byte *val = value_contents (arg);
105 if (TYPE_CODE (type) == TYPE_CODE_FLT
106 && ppc_floating_point_unit_p (current_gdbarch) && len <= 8)
108 /* Floating point value converted to "double" then
109 passed in an FP register, when the registers run out,
110 8 byte aligned stack is used. */
115 /* Always store the floating point value using
116 the register's floating-point format. */
117 gdb_byte regval[MAX_REGISTER_SIZE];
119 = register_type (gdbarch, tdep->ppc_fp0_regnum + freg);
120 convert_typed_floating (val, type, regval, regtype);
121 regcache_cooked_write (regcache,
122 tdep->ppc_fp0_regnum + freg,
129 /* SysV ABI converts floats to doubles before
130 writing them to an 8 byte aligned stack location. */
131 argoffset = align_up (argoffset, 8);
135 struct type *memtype;
136 switch (TARGET_BYTE_ORDER)
139 memtype = builtin_type_ieee_double_big;
141 case BFD_ENDIAN_LITTLE:
142 memtype = builtin_type_ieee_double_little;
145 internal_error (__FILE__, __LINE__, _("bad switch"));
147 convert_typed_floating (val, type, memval, memtype);
148 write_memory (sp + argoffset, val, len);
153 else if (len == 8 && (TYPE_CODE (type) == TYPE_CODE_INT /* long long */
154 || (!ppc_floating_point_unit_p (current_gdbarch) && TYPE_CODE (type) == TYPE_CODE_FLT))) /* double */
156 /* "long long" or "double" passed in an odd/even
157 register pair with the low addressed word in the odd
158 register and the high addressed word in the even
159 register, or when the registers run out an 8 byte
160 aligned stack location. */
163 /* Just in case GREG was 10. */
165 argoffset = align_up (argoffset, 8);
167 write_memory (sp + argoffset, val, len);
170 else if (tdep->wordsize == 8)
173 regcache_cooked_write (regcache,
174 tdep->ppc_gp0_regnum + greg, val);
179 /* Must start on an odd register - r3/r4 etc. */
184 regcache_cooked_write (regcache,
185 tdep->ppc_gp0_regnum + greg + 0,
187 regcache_cooked_write (regcache,
188 tdep->ppc_gp0_regnum + greg + 1,
195 && TYPE_CODE (type) == TYPE_CODE_ARRAY
196 && TYPE_VECTOR (type) && tdep->ppc_vr0_regnum >= 0)
198 /* Vector parameter passed in an Altivec register, or
199 when that runs out, 16 byte aligned stack location. */
203 regcache_cooked_write (current_regcache,
204 tdep->ppc_vr0_regnum + vreg, val);
209 argoffset = align_up (argoffset, 16);
211 write_memory (sp + argoffset, val, 16);
216 && TYPE_CODE (type) == TYPE_CODE_ARRAY
217 && TYPE_VECTOR (type) && tdep->ppc_ev0_regnum >= 0)
219 /* Vector parameter passed in an e500 register, or when
220 that runs out, 8 byte aligned stack location. Note
221 that since e500 vector and general purpose registers
222 both map onto the same underlying register set, a
223 "greg" and not a "vreg" is consumed here. A cooked
224 write stores the value in the correct locations
225 within the raw register cache. */
229 regcache_cooked_write (current_regcache,
230 tdep->ppc_ev0_regnum + greg, val);
235 argoffset = align_up (argoffset, 8);
237 write_memory (sp + argoffset, val, 8);
243 /* Reduce the parameter down to something that fits in a
245 gdb_byte word[MAX_REGISTER_SIZE];
246 memset (word, 0, MAX_REGISTER_SIZE);
247 if (len > tdep->wordsize
248 || TYPE_CODE (type) == TYPE_CODE_STRUCT
249 || TYPE_CODE (type) == TYPE_CODE_UNION)
251 /* Structs and large values are put on an 8 byte
253 structoffset = align_up (structoffset, 8);
255 write_memory (sp + structoffset, val, len);
256 /* ... and then a "word" pointing to that address is
257 passed as the parameter. */
258 store_unsigned_integer (word, tdep->wordsize,
262 else if (TYPE_CODE (type) == TYPE_CODE_INT)
263 /* Sign or zero extend the "int" into a "word". */
264 store_unsigned_integer (word, tdep->wordsize,
265 unpack_long (type, val));
267 /* Always goes in the low address. */
268 memcpy (word, val, len);
269 /* Store that "word" in a register, or on the stack.
270 The words have "4" byte alignment. */
274 regcache_cooked_write (regcache,
275 tdep->ppc_gp0_regnum + greg, word);
280 argoffset = align_up (argoffset, tdep->wordsize);
282 write_memory (sp + argoffset, word, tdep->wordsize);
283 argoffset += tdep->wordsize;
288 /* Compute the actual stack space requirements. */
291 /* Remember the amount of space needed by the arguments. */
292 argspace = argoffset;
293 /* Allocate space for both the arguments and the structures. */
294 sp -= (argoffset + structoffset);
295 /* Ensure that the stack is still 16 byte aligned. */
296 sp = align_down (sp, 16);
299 /* The psABI says that "A caller of a function that takes a
300 variable argument list shall set condition register bit 6 to
301 1 if it passes one or more arguments in the floating-point
302 registers. It is strongly recommended that the caller set the
303 bit to 0 otherwise..." Doing this for normal functions too
309 regcache_cooked_read_unsigned (regcache, tdep->ppc_cr_regnum, &cr);
314 regcache_cooked_write_unsigned (regcache, tdep->ppc_cr_regnum, cr);
319 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
321 /* Write the backchain (it occupies WORDSIZED bytes). */
322 write_memory_signed_integer (sp, tdep->wordsize, saved_sp);
324 /* Point the inferior function call's return address at the dummy's
326 regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
331 /* Handle the return-value conventions specified by the SysV 32-bit
332 PowerPC ABI (including all the supplements):
334 no floating-point: floating-point values returned using 32-bit
335 general-purpose registers.
337 Altivec: 128-bit vectors returned using vector registers.
339 e500: 64-bit vectors returned using the full full 64 bit EV
340 register, floating-point values returned using 32-bit
341 general-purpose registers.
343 GCC (broken): Small struct values right (instead of left) aligned
344 when returned in general-purpose registers. */
346 static enum return_value_convention
347 do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
348 struct regcache *regcache, void *readbuf,
349 const void *writebuf, int broken_gcc)
351 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
352 gdb_assert (tdep->wordsize == 4);
353 if (TYPE_CODE (type) == TYPE_CODE_FLT
354 && TYPE_LENGTH (type) <= 8
355 && ppc_floating_point_unit_p (gdbarch))
359 /* Floats and doubles stored in "f1". Convert the value to
360 the required type. */
361 gdb_byte regval[MAX_REGISTER_SIZE];
362 struct type *regtype = register_type (gdbarch,
363 tdep->ppc_fp0_regnum + 1);
364 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
365 convert_typed_floating (regval, regtype, readbuf, type);
369 /* Floats and doubles stored in "f1". Convert the value to
370 the register's "double" type. */
371 gdb_byte regval[MAX_REGISTER_SIZE];
372 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
373 convert_typed_floating (writebuf, type, regval, regtype);
374 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
376 return RETURN_VALUE_REGISTER_CONVENTION;
378 if ((TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 8)
379 || (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8))
383 /* A long long, or a double stored in the 32 bit r3/r4. */
384 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
385 (bfd_byte *) readbuf + 0);
386 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
387 (bfd_byte *) readbuf + 4);
391 /* A long long, or a double stored in the 32 bit r3/r4. */
392 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
393 (const bfd_byte *) writebuf + 0);
394 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
395 (const bfd_byte *) writebuf + 4);
397 return RETURN_VALUE_REGISTER_CONVENTION;
399 if (TYPE_CODE (type) == TYPE_CODE_INT
400 && TYPE_LENGTH (type) <= tdep->wordsize)
404 /* Some sort of integer stored in r3. Since TYPE isn't
405 bigger than the register, sign extension isn't a problem
406 - just do everything unsigned. */
408 regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
410 store_unsigned_integer (readbuf, TYPE_LENGTH (type), regval);
414 /* Some sort of integer stored in r3. Use unpack_long since
415 that should handle any required sign extension. */
416 regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
417 unpack_long (type, writebuf));
419 return RETURN_VALUE_REGISTER_CONVENTION;
421 if (TYPE_LENGTH (type) == 16
422 && TYPE_CODE (type) == TYPE_CODE_ARRAY
423 && TYPE_VECTOR (type) && tdep->ppc_vr0_regnum >= 0)
427 /* Altivec places the return value in "v2". */
428 regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
432 /* Altivec places the return value in "v2". */
433 regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf);
435 return RETURN_VALUE_REGISTER_CONVENTION;
437 if (TYPE_LENGTH (type) == 8
438 && TYPE_CODE (type) == TYPE_CODE_ARRAY
439 && TYPE_VECTOR (type) && tdep->ppc_ev0_regnum >= 0)
441 /* The e500 ABI places return values for the 64-bit DSP types
442 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
443 corresponds to the entire r3 value for e500, whereas GDB's r3
444 only corresponds to the least significant 32-bits. So place
445 the 64-bit DSP type's value in ev3. */
447 regcache_cooked_read (regcache, tdep->ppc_ev0_regnum + 3, readbuf);
449 regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + 3, writebuf);
450 return RETURN_VALUE_REGISTER_CONVENTION;
452 if (broken_gcc && TYPE_LENGTH (type) <= 8)
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 regcache_cooked_read_unsigned (regcache,
470 tdep->ppc_gp0_regnum + 3 + word,
472 store_unsigned_integer (((bfd_byte *) readbuf
473 + word * tdep->wordsize), len, reg);
479 /* GCC screwed up. The last register isn't "left" aligned.
480 Need to extract the least significant part of each
481 register and then store that. */
482 /* Transfer any full words. */
487 int len = TYPE_LENGTH (type) - word * tdep->wordsize;
490 if (len > tdep->wordsize)
491 len = tdep->wordsize;
492 reg = extract_unsigned_integer (((const bfd_byte *) writebuf
493 + word * tdep->wordsize), len);
494 regcache_cooked_write_unsigned (regcache,
495 tdep->ppc_gp0_regnum + 3 + word,
500 return RETURN_VALUE_REGISTER_CONVENTION;
502 if (TYPE_LENGTH (type) <= 8)
506 /* This matches SVr4 PPC, it does not match GCC. */
507 /* The value is right-padded to 8 bytes and then loaded, as
508 two "words", into r3/r4. */
509 gdb_byte regvals[MAX_REGISTER_SIZE * 2];
510 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
511 regvals + 0 * tdep->wordsize);
512 if (TYPE_LENGTH (type) > tdep->wordsize)
513 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
514 regvals + 1 * tdep->wordsize);
515 memcpy (readbuf, regvals, TYPE_LENGTH (type));
519 /* This matches SVr4 PPC, it does not match GCC. */
520 /* The value is padded out to 8 bytes and then loaded, as
521 two "words" into r3/r4. */
522 gdb_byte regvals[MAX_REGISTER_SIZE * 2];
523 memset (regvals, 0, sizeof regvals);
524 memcpy (regvals, writebuf, TYPE_LENGTH (type));
525 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
526 regvals + 0 * tdep->wordsize);
527 if (TYPE_LENGTH (type) > tdep->wordsize)
528 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
529 regvals + 1 * tdep->wordsize);
531 return RETURN_VALUE_REGISTER_CONVENTION;
533 return RETURN_VALUE_STRUCT_CONVENTION;
536 enum return_value_convention
537 ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
538 struct regcache *regcache, gdb_byte *readbuf,
539 const gdb_byte *writebuf)
541 return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf,
545 enum return_value_convention
546 ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch,
547 struct type *valtype,
548 struct regcache *regcache,
549 gdb_byte *readbuf, const gdb_byte *writebuf)
551 return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf,
555 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
556 function's code address back into the function's descriptor
559 Find a value for the TOC register. Every symbol should have both
560 ".FN" and "FN" in the minimal symbol table. "FN" points at the
561 FN's descriptor, while ".FN" points at the entry point (which
562 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
563 FN's descriptor address (while at the same time being careful to
564 find "FN" in the same object file as ".FN"). */
567 convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr)
569 struct obj_section *dot_fn_section;
570 struct minimal_symbol *dot_fn;
571 struct minimal_symbol *fn;
573 /* Find the minimal symbol that corresponds to CODE_ADDR (should
574 have a name of the form ".FN"). */
575 dot_fn = lookup_minimal_symbol_by_pc (code_addr);
576 if (dot_fn == NULL || SYMBOL_LINKAGE_NAME (dot_fn)[0] != '.')
578 /* Get the section that contains CODE_ADDR. Need this for the
579 "objfile" that it contains. */
580 dot_fn_section = find_pc_section (code_addr);
581 if (dot_fn_section == NULL || dot_fn_section->objfile == NULL)
583 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
584 address. Only look for the minimal symbol in ".FN"'s object file
585 - avoids problems when two object files (i.e., shared libraries)
586 contain a minimal symbol with the same name. */
587 fn = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL,
588 dot_fn_section->objfile);
591 /* Found a descriptor. */
592 (*desc_addr) = SYMBOL_VALUE_ADDRESS (fn);
596 /* Pass the arguments in either registers, or in the stack. Using the
599 This implements a dumbed down version of the ABI. It always writes
600 values to memory, GPR and FPR, even when not necessary. Doing this
601 greatly simplifies the logic. */
604 ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
605 struct regcache *regcache, CORE_ADDR bp_addr,
606 int nargs, struct value **args, CORE_ADDR sp,
607 int struct_return, CORE_ADDR struct_addr)
609 CORE_ADDR func_addr = find_function_addr (function, NULL);
610 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
611 /* By this stage in the proceedings, SP has been decremented by "red
612 zone size" + "struct return size". Fetch the stack-pointer from
613 before this and use that as the BACK_CHAIN. */
614 const CORE_ADDR back_chain = read_sp ();
615 /* See for-loop comment below. */
617 /* Size of the Altivec's vector parameter region, the final value is
618 computed in the for-loop below. */
619 LONGEST vparam_size = 0;
620 /* Size of the general parameter region, the final value is computed
621 in the for-loop below. */
622 LONGEST gparam_size = 0;
623 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
624 calls to align_up(), align_down(), etc. because this makes it
625 easier to reuse this code (in a copy/paste sense) in the future,
626 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
627 at some point makes it easier to verify that this function is
628 correct without having to do a non-local analysis to figure out
629 the possible values of tdep->wordsize. */
630 gdb_assert (tdep->wordsize == 8);
632 /* Go through the argument list twice.
634 Pass 1: Compute the function call's stack space and register
637 Pass 2: Replay the same computation but this time also write the
638 values out to the target. */
640 for (write_pass = 0; write_pass < 2; write_pass++)
643 /* Next available floating point register for float and double
646 /* Next available general register for non-vector (but possibly
649 /* Next available vector register for vector arguments. */
651 /* The address, at which the next general purpose parameter
652 (integer, struct, float, ...) should be saved. */
654 /* Address, at which the next Altivec vector parameter should be
660 /* During the first pass, GPARAM and VPARAM are more like
661 offsets (start address zero) than addresses. That way
662 the accumulate the total stack space each region
669 /* Decrement the stack pointer making space for the Altivec
670 and general on-stack parameters. Set vparam and gparam
671 to their corresponding regions. */
672 vparam = align_down (sp - vparam_size, 16);
673 gparam = align_down (vparam - gparam_size, 16);
674 /* Add in space for the TOC, link editor double word,
675 compiler double word, LR save area, CR save area. */
676 sp = align_down (gparam - 48, 16);
679 /* If the function is returning a `struct', then there is an
680 extra hidden parameter (which will be passed in r3)
681 containing the address of that struct.. In that case we
682 should advance one word and start from r4 register to copy
683 parameters. This also consumes one on-stack parameter slot. */
687 regcache_cooked_write_signed (regcache,
688 tdep->ppc_gp0_regnum + greg,
691 gparam = align_up (gparam + tdep->wordsize, tdep->wordsize);
694 for (argno = 0; argno < nargs; argno++)
696 struct value *arg = args[argno];
697 struct type *type = check_typedef (value_type (arg));
698 const bfd_byte *val = value_contents (arg);
699 if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8)
701 /* Floats and Doubles go in f1 .. f13. They also
702 consume a left aligned GREG,, and can end up in
706 if (ppc_floating_point_unit_p (current_gdbarch)
709 gdb_byte regval[MAX_REGISTER_SIZE];
711 = register_type (gdbarch, tdep->ppc_fp0_regnum);
712 convert_typed_floating (val, type, regval, regtype);
713 regcache_cooked_write (regcache,
714 tdep->ppc_fp0_regnum + freg,
719 /* The ABI states "Single precision floating
720 point values are mapped to the first word in
721 a single doubleword" and "... floating point
722 values mapped to the first eight doublewords
723 of the parameter save area are also passed in
726 This code interprets that to mean: store it,
727 left aligned, in the general register. */
728 gdb_byte regval[MAX_REGISTER_SIZE];
729 memset (regval, 0, sizeof regval);
730 memcpy (regval, val, TYPE_LENGTH (type));
731 regcache_cooked_write (regcache,
732 tdep->ppc_gp0_regnum + greg,
735 write_memory (gparam, val, TYPE_LENGTH (type));
737 /* Always consume parameter stack space. */
740 gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
742 else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type)
743 && TYPE_CODE (type) == TYPE_CODE_ARRAY
744 && tdep->ppc_vr0_regnum >= 0)
746 /* In the Altivec ABI, vectors go in the vector
747 registers v2 .. v13, or when that runs out, a vector
748 annex which goes above all the normal parameters.
749 NOTE: cagney/2003-09-21: This is a guess based on the
750 PowerOpen Altivec ABI. */
754 regcache_cooked_write (regcache,
755 tdep->ppc_vr0_regnum + vreg, val);
761 write_memory (vparam, val, TYPE_LENGTH (type));
762 vparam = align_up (vparam + TYPE_LENGTH (type), 16);
765 else if ((TYPE_CODE (type) == TYPE_CODE_INT
766 || TYPE_CODE (type) == TYPE_CODE_ENUM
767 || TYPE_CODE (type) == TYPE_CODE_PTR)
768 && TYPE_LENGTH (type) <= 8)
770 /* Scalars and Pointers get sign[un]extended and go in
771 gpr3 .. gpr10. They can also end up in memory. */
774 /* Sign extend the value, then store it unsigned. */
775 ULONGEST word = unpack_long (type, val);
776 /* Convert any function code addresses into
778 if (TYPE_CODE (type) == TYPE_CODE_PTR
779 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC)
781 CORE_ADDR desc = word;
782 convert_code_addr_to_desc_addr (word, &desc);
786 regcache_cooked_write_unsigned (regcache,
787 tdep->ppc_gp0_regnum +
789 write_memory_unsigned_integer (gparam, tdep->wordsize,
793 gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
798 for (byte = 0; byte < TYPE_LENGTH (type);
799 byte += tdep->wordsize)
801 if (write_pass && greg <= 10)
803 gdb_byte regval[MAX_REGISTER_SIZE];
804 int len = TYPE_LENGTH (type) - byte;
805 if (len > tdep->wordsize)
806 len = tdep->wordsize;
807 memset (regval, 0, sizeof regval);
808 /* WARNING: cagney/2003-09-21: As best I can
809 tell, the ABI specifies that the value should
810 be left aligned. Unfortunately, GCC doesn't
811 do this - it instead right aligns even sized
812 values and puts odd sized values on the
813 stack. Work around that by putting both a
814 left and right aligned value into the
815 register (hopefully no one notices :-^).
817 /* Left aligned (8 byte values such as pointers
819 memcpy (regval, val + byte, len);
820 /* Right aligned (but only if even). */
821 if (len == 1 || len == 2 || len == 4)
822 memcpy (regval + tdep->wordsize - len,
824 regcache_cooked_write (regcache, greg, regval);
829 /* WARNING: cagney/2003-09-21: Strictly speaking, this
830 isn't necessary, unfortunately, GCC appears to get
831 "struct convention" parameter passing wrong putting
832 odd sized structures in memory instead of in a
833 register. Work around this by always writing the
834 value to memory. Fortunately, doing this
835 simplifies the code. */
836 write_memory (gparam, val, TYPE_LENGTH (type));
838 /* WARNING: cagney/2004-06-20: It appears that GCC
839 likes to put structures containing a single
840 floating-point member in an FP register instead of
841 general general purpose. */
842 /* Always consume parameter stack space. */
843 gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
849 /* Save the true region sizes ready for the second pass. */
850 vparam_size = vparam;
851 /* Make certain that the general parameter save area is at
852 least the minimum 8 registers (or doublewords) in size. */
854 gparam_size = 8 * tdep->wordsize;
856 gparam_size = gparam;
861 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
863 /* Write the backchain (it occupies WORDSIZED bytes). */
864 write_memory_signed_integer (sp, tdep->wordsize, back_chain);
866 /* Point the inferior function call's return address at the dummy's
868 regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
870 /* Use the func_addr to find the descriptor, and use that to find
874 if (convert_code_addr_to_desc_addr (func_addr, &desc_addr))
876 /* The TOC is the second double word in the descriptor. */
878 read_memory_unsigned_integer (desc_addr + tdep->wordsize,
880 regcache_cooked_write_unsigned (regcache,
881 tdep->ppc_gp0_regnum + 2, toc);
889 /* The 64 bit ABI retun value convention.
891 Return non-zero if the return-value is stored in a register, return
892 0 if the return-value is instead stored on the stack (a.k.a.,
893 struct return convention).
895 For a return-value stored in a register: when WRITEBUF is non-NULL,
896 copy the buffer to the corresponding register return-value location
897 location; when READBUF is non-NULL, fill the buffer from the
898 corresponding register return-value location. */
899 enum return_value_convention
900 ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
901 struct regcache *regcache, gdb_byte *readbuf,
902 const gdb_byte *writebuf)
904 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
906 /* This function exists to support a calling convention that
907 requires floating-point registers. It shouldn't be used on
908 processors that lack them. */
909 gdb_assert (ppc_floating_point_unit_p (gdbarch));
911 /* Floats and doubles in F1. */
912 if (TYPE_CODE (valtype) == TYPE_CODE_FLT && TYPE_LENGTH (valtype) <= 8)
914 gdb_byte regval[MAX_REGISTER_SIZE];
915 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
916 if (writebuf != NULL)
918 convert_typed_floating (writebuf, valtype, regval, regtype);
919 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
923 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
924 convert_typed_floating (regval, regtype, readbuf, valtype);
926 return RETURN_VALUE_REGISTER_CONVENTION;
928 if ((TYPE_CODE (valtype) == TYPE_CODE_INT
929 || TYPE_CODE (valtype) == TYPE_CODE_ENUM)
930 && TYPE_LENGTH (valtype) <= 8)
932 /* Integers in r3. */
933 if (writebuf != NULL)
935 /* Be careful to sign extend the value. */
936 regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
937 unpack_long (valtype, writebuf));
941 /* Extract the integer from r3. Since this is truncating the
942 value, there isn't a sign extension problem. */
944 regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
946 store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), regval);
948 return RETURN_VALUE_REGISTER_CONVENTION;
950 /* All pointers live in r3. */
951 if (TYPE_CODE (valtype) == TYPE_CODE_PTR)
953 /* All pointers live in r3. */
954 if (writebuf != NULL)
955 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf);
957 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf);
958 return RETURN_VALUE_REGISTER_CONVENTION;
960 if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
961 && TYPE_LENGTH (valtype) <= 8
962 && TYPE_CODE (TYPE_TARGET_TYPE (valtype)) == TYPE_CODE_INT
963 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype)) == 1)
965 /* Small character arrays are returned, right justified, in r3. */
966 int offset = (register_size (gdbarch, tdep->ppc_gp0_regnum + 3)
967 - TYPE_LENGTH (valtype));
968 if (writebuf != NULL)
969 regcache_cooked_write_part (regcache, tdep->ppc_gp0_regnum + 3,
970 offset, TYPE_LENGTH (valtype), writebuf);
972 regcache_cooked_read_part (regcache, tdep->ppc_gp0_regnum + 3,
973 offset, TYPE_LENGTH (valtype), readbuf);
974 return RETURN_VALUE_REGISTER_CONVENTION;
976 /* Big floating point values get stored in adjacent floating
978 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
979 && (TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 32))
981 if (writebuf || readbuf != NULL)
984 for (i = 0; i < TYPE_LENGTH (valtype) / 8; i++)
986 if (writebuf != NULL)
987 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i,
988 (const bfd_byte *) writebuf + i * 8);
990 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i,
991 (bfd_byte *) readbuf + i * 8);
994 return RETURN_VALUE_REGISTER_CONVENTION;
996 /* Complex values get returned in f1:f2, need to convert. */
997 if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX
998 && (TYPE_LENGTH (valtype) == 8 || TYPE_LENGTH (valtype) == 16))
1000 if (regcache != NULL)
1003 for (i = 0; i < 2; i++)
1005 gdb_byte regval[MAX_REGISTER_SIZE];
1006 struct type *regtype =
1007 register_type (current_gdbarch, tdep->ppc_fp0_regnum);
1008 if (writebuf != NULL)
1010 convert_typed_floating ((const bfd_byte *) writebuf +
1011 i * (TYPE_LENGTH (valtype) / 2),
1012 valtype, regval, regtype);
1013 regcache_cooked_write (regcache,
1014 tdep->ppc_fp0_regnum + 1 + i,
1017 if (readbuf != NULL)
1019 regcache_cooked_read (regcache,
1020 tdep->ppc_fp0_regnum + 1 + i,
1022 convert_typed_floating (regval, regtype,
1023 (bfd_byte *) readbuf +
1024 i * (TYPE_LENGTH (valtype) / 2),
1029 return RETURN_VALUE_REGISTER_CONVENTION;
1031 /* Big complex values get stored in f1:f4. */
1032 if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX && TYPE_LENGTH (valtype) == 32)
1034 if (regcache != NULL)
1037 for (i = 0; i < 4; i++)
1039 if (writebuf != NULL)
1040 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i,
1041 (const bfd_byte *) writebuf + i * 8);
1042 if (readbuf != NULL)
1043 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i,
1044 (bfd_byte *) readbuf + i * 8);
1047 return RETURN_VALUE_REGISTER_CONVENTION;
1049 return RETURN_VALUE_STRUCT_CONVENTION;
1053 ppc64_sysv_abi_adjust_breakpoint_address (struct gdbarch *gdbarch,
1056 /* PPC64 SYSV specifies that the minimal-symbol "FN" should point at
1057 a function-descriptor while the corresponding minimal-symbol
1058 ".FN" should point at the entry point. Consequently, a command
1059 like "break FN" applied to an object file with only minimal
1060 symbols, will insert the breakpoint into the descriptor at "FN"
1061 and not the function at ".FN". Avoid this confusion by adjusting
1062 any attempt to set a descriptor breakpoint into a corresponding
1063 function breakpoint. Note that GDB warns the user when this
1064 adjustment is applied - that's ok as otherwise the user will have
1065 no way of knowing why their breakpoint at "FN" resulted in the
1066 program stopping at ".FN". */
1067 return gdbarch_convert_from_func_ptr_addr (gdbarch, bpaddr, ¤t_target);