1 /* Target-dependent code for PowerPC systems using the SVR4 ABI
2 for GDB, the GNU debugger.
4 Copyright (C) 2000, 2001, 2002, 2003, 2005, 2007
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 3 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, see <http://www.gnu.org/licenses/>. */
27 #include "gdb_string.h"
28 #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, struct value *function,
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);
53 int argspace = 0; /* 0 is an initial wrong guess. */
56 regcache_cooked_read_unsigned (regcache,
57 gdbarch_sp_regnum (current_gdbarch),
60 /* Go through the argument list twice.
62 Pass 1: Figure out how much new stack space is required for
63 arguments and pushed values. Unlike the PowerOpen ABI, the SysV
64 ABI doesn't reserve any extra space for parameters which are put
65 in registers, but does always push structures and then pass their
68 Pass 2: Replay the same computation but this time also write the
69 values out to the target. */
71 for (write_pass = 0; write_pass < 2; write_pass++)
74 /* Next available floating point register for float and double
77 /* Next available general register for non-float, non-vector
80 /* Next available vector register for vector arguments. */
82 /* Arguments start above the "LR save word" and "Back chain". */
83 int argoffset = 2 * tdep->wordsize;
84 /* Structures start after the arguments. */
85 int structoffset = argoffset + argspace;
87 /* If the function is returning a `struct', then the first word
88 (which will be passed in r3) is used for struct return
89 address. In that case we should advance one word and start
90 from r4 register to copy parameters. */
94 regcache_cooked_write_signed (regcache,
95 tdep->ppc_gp0_regnum + greg,
100 for (argno = 0; argno < nargs; argno++)
102 struct value *arg = args[argno];
103 struct type *type = check_typedef (value_type (arg));
104 int len = TYPE_LENGTH (type);
105 const bfd_byte *val = value_contents (arg);
107 if (TYPE_CODE (type) == TYPE_CODE_FLT && len <= 8
108 && !tdep->soft_float)
110 /* Floating point value converted to "double" then
111 passed in an FP register, when the registers run out,
112 8 byte aligned stack is used. */
117 /* Always store the floating point value using
118 the register's floating-point format. */
119 gdb_byte regval[MAX_REGISTER_SIZE];
121 = register_type (gdbarch, tdep->ppc_fp0_regnum + freg);
122 convert_typed_floating (val, type, regval, regtype);
123 regcache_cooked_write (regcache,
124 tdep->ppc_fp0_regnum + freg,
131 /* SysV ABI converts floats to doubles before
132 writing them to an 8 byte aligned stack location. */
133 argoffset = align_up (argoffset, 8);
137 convert_typed_floating (val, type, memval,
138 builtin_type_ieee_double);
139 write_memory (sp + argoffset, val, len);
145 && (TYPE_CODE (type) == TYPE_CODE_INT /* long long */
146 || TYPE_CODE (type) == TYPE_CODE_FLT)) /* double */
148 /* "long long" or soft-float "double" passed in an odd/even
149 register pair with the low addressed word in the odd
150 register and the high addressed word in the even
151 register, or when the registers run out an 8 byte
152 aligned stack location. */
155 /* Just in case GREG was 10. */
157 argoffset = align_up (argoffset, 8);
159 write_memory (sp + argoffset, val, len);
162 else if (tdep->wordsize == 8)
165 regcache_cooked_write (regcache,
166 tdep->ppc_gp0_regnum + greg, val);
171 /* Must start on an odd register - r3/r4 etc. */
176 regcache_cooked_write (regcache,
177 tdep->ppc_gp0_regnum + greg + 0,
179 regcache_cooked_write (regcache,
180 tdep->ppc_gp0_regnum + greg + 1,
187 && TYPE_CODE (type) == TYPE_CODE_ARRAY
188 && TYPE_VECTOR (type)
189 && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
191 /* Vector parameter passed in an Altivec register, or
192 when that runs out, 16 byte aligned stack location. */
196 regcache_cooked_write (regcache,
197 tdep->ppc_vr0_regnum + vreg, val);
202 argoffset = align_up (argoffset, 16);
204 write_memory (sp + argoffset, val, 16);
209 && TYPE_CODE (type) == TYPE_CODE_ARRAY
210 && TYPE_VECTOR (type)
211 && tdep->vector_abi == POWERPC_VEC_SPE)
213 /* Vector parameter passed in an e500 register, or when
214 that runs out, 8 byte aligned stack location. Note
215 that since e500 vector and general purpose registers
216 both map onto the same underlying register set, a
217 "greg" and not a "vreg" is consumed here. A cooked
218 write stores the value in the correct locations
219 within the raw register cache. */
223 regcache_cooked_write (regcache,
224 tdep->ppc_ev0_regnum + greg, val);
229 argoffset = align_up (argoffset, 8);
231 write_memory (sp + argoffset, val, 8);
237 /* Reduce the parameter down to something that fits in a
239 gdb_byte word[MAX_REGISTER_SIZE];
240 memset (word, 0, MAX_REGISTER_SIZE);
241 if (len > tdep->wordsize
242 || TYPE_CODE (type) == TYPE_CODE_STRUCT
243 || TYPE_CODE (type) == TYPE_CODE_UNION)
245 /* Structs and large values are put in an
246 aligned stack slot ... */
247 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
248 && TYPE_VECTOR (type)
250 structoffset = align_up (structoffset, 16);
252 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,
320 gdbarch_sp_regnum (current_gdbarch), sp);
322 /* Write the backchain (it occupies WORDSIZED bytes). */
323 write_memory_signed_integer (sp, tdep->wordsize, saved_sp);
325 /* Point the inferior function call's return address at the dummy's
327 regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
332 /* Handle the return-value conventions specified by the SysV 32-bit
333 PowerPC ABI (including all the supplements):
335 no floating-point: floating-point values returned using 32-bit
336 general-purpose registers.
338 Altivec: 128-bit vectors returned using vector registers.
340 e500: 64-bit vectors returned using the full full 64 bit EV
341 register, floating-point values returned using 32-bit
342 general-purpose registers.
344 GCC (broken): Small struct values right (instead of left) aligned
345 when returned in general-purpose registers. */
347 static enum return_value_convention
348 do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
349 struct regcache *regcache, gdb_byte *readbuf,
350 const gdb_byte *writebuf, int broken_gcc)
352 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
353 gdb_assert (tdep->wordsize == 4);
354 if (TYPE_CODE (type) == TYPE_CODE_FLT
355 && TYPE_LENGTH (type) <= 8
356 && !tdep->soft_float)
360 /* Floats and doubles stored in "f1". Convert the value to
361 the required type. */
362 gdb_byte regval[MAX_REGISTER_SIZE];
363 struct type *regtype = register_type (gdbarch,
364 tdep->ppc_fp0_regnum + 1);
365 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
366 convert_typed_floating (regval, regtype, readbuf, type);
370 /* Floats and doubles stored in "f1". Convert the value to
371 the register's "double" type. */
372 gdb_byte regval[MAX_REGISTER_SIZE];
373 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
374 convert_typed_floating (writebuf, type, regval, regtype);
375 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
377 return RETURN_VALUE_REGISTER_CONVENTION;
379 if ((TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 8)
380 || (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8))
384 /* A long long, or a double stored in the 32 bit r3/r4. */
385 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
387 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
392 /* A long long, or a double stored in the 32 bit r3/r4. */
393 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
395 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
398 return RETURN_VALUE_REGISTER_CONVENTION;
400 else if ((TYPE_CODE (type) == TYPE_CODE_INT
401 || TYPE_CODE (type) == TYPE_CODE_CHAR
402 || TYPE_CODE (type) == TYPE_CODE_BOOL
403 || TYPE_CODE (type) == TYPE_CODE_PTR
404 || TYPE_CODE (type) == TYPE_CODE_REF
405 || TYPE_CODE (type) == TYPE_CODE_ENUM)
406 && TYPE_LENGTH (type) <= tdep->wordsize)
410 /* Some sort of integer stored in r3. Since TYPE isn't
411 bigger than the register, sign extension isn't a problem
412 - just do everything unsigned. */
414 regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
416 store_unsigned_integer (readbuf, TYPE_LENGTH (type), regval);
420 /* Some sort of integer stored in r3. Use unpack_long since
421 that should handle any required sign extension. */
422 regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
423 unpack_long (type, writebuf));
425 return RETURN_VALUE_REGISTER_CONVENTION;
427 if (TYPE_LENGTH (type) == 16
428 && TYPE_CODE (type) == TYPE_CODE_ARRAY
429 && TYPE_VECTOR (type)
430 && tdep->vector_abi == POWERPC_VEC_ALTIVEC)
434 /* Altivec places the return value in "v2". */
435 regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
439 /* Altivec places the return value in "v2". */
440 regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf);
442 return RETURN_VALUE_REGISTER_CONVENTION;
444 if (TYPE_LENGTH (type) == 16
445 && TYPE_CODE (type) == TYPE_CODE_ARRAY
446 && TYPE_VECTOR (type)
447 && tdep->vector_abi == POWERPC_VEC_GENERIC)
449 /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6.
450 GCC without AltiVec returns them in memory, but it warns about
451 ABI risks in that case; we don't try to support it. */
454 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
456 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
458 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5,
460 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6,
465 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
467 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
469 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5,
471 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6,
474 return RETURN_VALUE_REGISTER_CONVENTION;
476 if (TYPE_LENGTH (type) == 8
477 && TYPE_CODE (type) == TYPE_CODE_ARRAY
478 && TYPE_VECTOR (type)
479 && tdep->vector_abi == POWERPC_VEC_SPE)
481 /* The e500 ABI places return values for the 64-bit DSP types
482 (__ev64_opaque__) in r3. However, in GDB-speak, ev3
483 corresponds to the entire r3 value for e500, whereas GDB's r3
484 only corresponds to the least significant 32-bits. So place
485 the 64-bit DSP type's value in ev3. */
487 regcache_cooked_read (regcache, tdep->ppc_ev0_regnum + 3, readbuf);
489 regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + 3, writebuf);
490 return RETURN_VALUE_REGISTER_CONVENTION;
492 if (broken_gcc && TYPE_LENGTH (type) <= 8)
494 /* GCC screwed up for structures or unions whose size is less
495 than or equal to 8 bytes.. Instead of left-aligning, it
496 right-aligns the data into the buffer formed by r3, r4. */
497 gdb_byte regvals[MAX_REGISTER_SIZE * 2];
498 int len = TYPE_LENGTH (type);
499 int offset = (2 * tdep->wordsize - len) % tdep->wordsize;
503 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
504 regvals + 0 * tdep->wordsize);
505 if (len > tdep->wordsize)
506 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
507 regvals + 1 * tdep->wordsize);
508 memcpy (readbuf, regvals + offset, len);
512 memset (regvals, 0, sizeof regvals);
513 memcpy (regvals + offset, writebuf, len);
514 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
515 regvals + 0 * tdep->wordsize);
516 if (len > tdep->wordsize)
517 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
518 regvals + 1 * tdep->wordsize);
521 return RETURN_VALUE_REGISTER_CONVENTION;
523 if (TYPE_LENGTH (type) <= 8)
527 /* This matches SVr4 PPC, it does not match GCC. */
528 /* The value is right-padded to 8 bytes and then loaded, as
529 two "words", into r3/r4. */
530 gdb_byte regvals[MAX_REGISTER_SIZE * 2];
531 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
532 regvals + 0 * tdep->wordsize);
533 if (TYPE_LENGTH (type) > tdep->wordsize)
534 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
535 regvals + 1 * tdep->wordsize);
536 memcpy (readbuf, regvals, TYPE_LENGTH (type));
540 /* This matches SVr4 PPC, it does not match GCC. */
541 /* The value is padded out to 8 bytes and then loaded, as
542 two "words" into r3/r4. */
543 gdb_byte regvals[MAX_REGISTER_SIZE * 2];
544 memset (regvals, 0, sizeof regvals);
545 memcpy (regvals, writebuf, TYPE_LENGTH (type));
546 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
547 regvals + 0 * tdep->wordsize);
548 if (TYPE_LENGTH (type) > tdep->wordsize)
549 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
550 regvals + 1 * tdep->wordsize);
552 return RETURN_VALUE_REGISTER_CONVENTION;
554 return RETURN_VALUE_STRUCT_CONVENTION;
557 enum return_value_convention
558 ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
559 struct regcache *regcache, gdb_byte *readbuf,
560 const gdb_byte *writebuf)
562 return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf,
566 enum return_value_convention
567 ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch,
568 struct type *valtype,
569 struct regcache *regcache,
570 gdb_byte *readbuf, const gdb_byte *writebuf)
572 return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf,
576 /* The helper function for 64-bit SYSV push_dummy_call. Converts the
577 function's code address back into the function's descriptor
580 Find a value for the TOC register. Every symbol should have both
581 ".FN" and "FN" in the minimal symbol table. "FN" points at the
582 FN's descriptor, while ".FN" points at the entry point (which
583 matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the
584 FN's descriptor address (while at the same time being careful to
585 find "FN" in the same object file as ".FN"). */
588 convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr)
590 struct obj_section *dot_fn_section;
591 struct minimal_symbol *dot_fn;
592 struct minimal_symbol *fn;
594 /* Find the minimal symbol that corresponds to CODE_ADDR (should
595 have a name of the form ".FN"). */
596 dot_fn = lookup_minimal_symbol_by_pc (code_addr);
597 if (dot_fn == NULL || SYMBOL_LINKAGE_NAME (dot_fn)[0] != '.')
599 /* Get the section that contains CODE_ADDR. Need this for the
600 "objfile" that it contains. */
601 dot_fn_section = find_pc_section (code_addr);
602 if (dot_fn_section == NULL || dot_fn_section->objfile == NULL)
604 /* Now find the corresponding "FN" (dropping ".") minimal symbol's
605 address. Only look for the minimal symbol in ".FN"'s object file
606 - avoids problems when two object files (i.e., shared libraries)
607 contain a minimal symbol with the same name. */
608 fn = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL,
609 dot_fn_section->objfile);
612 /* Found a descriptor. */
613 (*desc_addr) = SYMBOL_VALUE_ADDRESS (fn);
617 /* Pass the arguments in either registers, or in the stack. Using the
620 This implements a dumbed down version of the ABI. It always writes
621 values to memory, GPR and FPR, even when not necessary. Doing this
622 greatly simplifies the logic. */
625 ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
626 struct regcache *regcache, CORE_ADDR bp_addr,
627 int nargs, struct value **args, CORE_ADDR sp,
628 int struct_return, CORE_ADDR struct_addr)
630 CORE_ADDR func_addr = find_function_addr (function, NULL);
631 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
633 /* See for-loop comment below. */
635 /* Size of the Altivec's vector parameter region, the final value is
636 computed in the for-loop below. */
637 LONGEST vparam_size = 0;
638 /* Size of the general parameter region, the final value is computed
639 in the for-loop below. */
640 LONGEST gparam_size = 0;
641 /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
642 calls to align_up(), align_down(), etc. because this makes it
643 easier to reuse this code (in a copy/paste sense) in the future,
644 but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
645 at some point makes it easier to verify that this function is
646 correct without having to do a non-local analysis to figure out
647 the possible values of tdep->wordsize. */
648 gdb_assert (tdep->wordsize == 8);
650 /* This function exists to support a calling convention that
651 requires floating-point registers. It shouldn't be used on
652 processors that lack them. */
653 gdb_assert (ppc_floating_point_unit_p (gdbarch));
655 /* By this stage in the proceedings, SP has been decremented by "red
656 zone size" + "struct return size". Fetch the stack-pointer from
657 before this and use that as the BACK_CHAIN. */
658 regcache_cooked_read_unsigned (regcache,
659 gdbarch_sp_regnum (current_gdbarch),
662 /* Go through the argument list twice.
664 Pass 1: Compute the function call's stack space and register
667 Pass 2: Replay the same computation but this time also write the
668 values out to the target. */
670 for (write_pass = 0; write_pass < 2; write_pass++)
673 /* Next available floating point register for float and double
676 /* Next available general register for non-vector (but possibly
679 /* Next available vector register for vector arguments. */
681 /* The address, at which the next general purpose parameter
682 (integer, struct, float, ...) should be saved. */
684 /* Address, at which the next Altivec vector parameter should be
690 /* During the first pass, GPARAM and VPARAM are more like
691 offsets (start address zero) than addresses. That way
692 the accumulate the total stack space each region
699 /* Decrement the stack pointer making space for the Altivec
700 and general on-stack parameters. Set vparam and gparam
701 to their corresponding regions. */
702 vparam = align_down (sp - vparam_size, 16);
703 gparam = align_down (vparam - gparam_size, 16);
704 /* Add in space for the TOC, link editor double word,
705 compiler double word, LR save area, CR save area. */
706 sp = align_down (gparam - 48, 16);
709 /* If the function is returning a `struct', then there is an
710 extra hidden parameter (which will be passed in r3)
711 containing the address of that struct.. In that case we
712 should advance one word and start from r4 register to copy
713 parameters. This also consumes one on-stack parameter slot. */
717 regcache_cooked_write_signed (regcache,
718 tdep->ppc_gp0_regnum + greg,
721 gparam = align_up (gparam + tdep->wordsize, tdep->wordsize);
724 for (argno = 0; argno < nargs; argno++)
726 struct value *arg = args[argno];
727 struct type *type = check_typedef (value_type (arg));
728 const bfd_byte *val = value_contents (arg);
729 if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8)
731 /* Floats and Doubles go in f1 .. f13. They also
732 consume a left aligned GREG,, and can end up in
738 gdb_byte regval[MAX_REGISTER_SIZE];
740 = register_type (gdbarch, tdep->ppc_fp0_regnum);
741 convert_typed_floating (val, type, regval, regtype);
742 regcache_cooked_write (regcache,
743 tdep->ppc_fp0_regnum + freg,
748 /* The ABI states "Single precision floating
749 point values are mapped to the first word in
750 a single doubleword" and "... floating point
751 values mapped to the first eight doublewords
752 of the parameter save area are also passed in
755 This code interprets that to mean: store it,
756 left aligned, in the general register. */
757 gdb_byte regval[MAX_REGISTER_SIZE];
758 memset (regval, 0, sizeof regval);
759 memcpy (regval, val, TYPE_LENGTH (type));
760 regcache_cooked_write (regcache,
761 tdep->ppc_gp0_regnum + greg,
764 write_memory (gparam, val, TYPE_LENGTH (type));
766 /* Always consume parameter stack space. */
769 gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
771 else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type)
772 && TYPE_CODE (type) == TYPE_CODE_ARRAY
773 && tdep->ppc_vr0_regnum >= 0)
775 /* In the Altivec ABI, vectors go in the vector
776 registers v2 .. v13, or when that runs out, a vector
777 annex which goes above all the normal parameters.
778 NOTE: cagney/2003-09-21: This is a guess based on the
779 PowerOpen Altivec ABI. */
783 regcache_cooked_write (regcache,
784 tdep->ppc_vr0_regnum + vreg, val);
790 write_memory (vparam, val, TYPE_LENGTH (type));
791 vparam = align_up (vparam + TYPE_LENGTH (type), 16);
794 else if ((TYPE_CODE (type) == TYPE_CODE_INT
795 || TYPE_CODE (type) == TYPE_CODE_ENUM
796 || TYPE_CODE (type) == TYPE_CODE_PTR)
797 && TYPE_LENGTH (type) <= 8)
799 /* Scalars and Pointers get sign[un]extended and go in
800 gpr3 .. gpr10. They can also end up in memory. */
803 /* Sign extend the value, then store it unsigned. */
804 ULONGEST word = unpack_long (type, val);
805 /* Convert any function code addresses into
807 if (TYPE_CODE (type) == TYPE_CODE_PTR
808 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC)
810 CORE_ADDR desc = word;
811 convert_code_addr_to_desc_addr (word, &desc);
815 regcache_cooked_write_unsigned (regcache,
816 tdep->ppc_gp0_regnum +
818 write_memory_unsigned_integer (gparam, tdep->wordsize,
822 gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
827 for (byte = 0; byte < TYPE_LENGTH (type);
828 byte += tdep->wordsize)
830 if (write_pass && greg <= 10)
832 gdb_byte regval[MAX_REGISTER_SIZE];
833 int len = TYPE_LENGTH (type) - byte;
834 if (len > tdep->wordsize)
835 len = tdep->wordsize;
836 memset (regval, 0, sizeof regval);
837 /* WARNING: cagney/2003-09-21: As best I can
838 tell, the ABI specifies that the value should
839 be left aligned. Unfortunately, GCC doesn't
840 do this - it instead right aligns even sized
841 values and puts odd sized values on the
842 stack. Work around that by putting both a
843 left and right aligned value into the
844 register (hopefully no one notices :-^).
846 /* Left aligned (8 byte values such as pointers
848 memcpy (regval, val + byte, len);
849 /* Right aligned (but only if even). */
850 if (len == 1 || len == 2 || len == 4)
851 memcpy (regval + tdep->wordsize - len,
853 regcache_cooked_write (regcache, greg, regval);
858 /* WARNING: cagney/2003-09-21: Strictly speaking, this
859 isn't necessary, unfortunately, GCC appears to get
860 "struct convention" parameter passing wrong putting
861 odd sized structures in memory instead of in a
862 register. Work around this by always writing the
863 value to memory. Fortunately, doing this
864 simplifies the code. */
865 write_memory (gparam, val, TYPE_LENGTH (type));
867 /* WARNING: cagney/2004-06-20: It appears that GCC
868 likes to put structures containing a single
869 floating-point member in an FP register instead of
870 general general purpose. */
871 /* Always consume parameter stack space. */
872 gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
878 /* Save the true region sizes ready for the second pass. */
879 vparam_size = vparam;
880 /* Make certain that the general parameter save area is at
881 least the minimum 8 registers (or doublewords) in size. */
883 gparam_size = 8 * tdep->wordsize;
885 gparam_size = gparam;
890 regcache_cooked_write_signed (regcache,
891 gdbarch_sp_regnum (current_gdbarch), sp);
893 /* Write the backchain (it occupies WORDSIZED bytes). */
894 write_memory_signed_integer (sp, tdep->wordsize, back_chain);
896 /* Point the inferior function call's return address at the dummy's
898 regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
900 /* Use the func_addr to find the descriptor, and use that to find
904 if (convert_code_addr_to_desc_addr (func_addr, &desc_addr))
906 /* The TOC is the second double word in the descriptor. */
908 read_memory_unsigned_integer (desc_addr + tdep->wordsize,
910 regcache_cooked_write_unsigned (regcache,
911 tdep->ppc_gp0_regnum + 2, toc);
919 /* The 64 bit ABI return value convention.
921 Return non-zero if the return-value is stored in a register, return
922 0 if the return-value is instead stored on the stack (a.k.a.,
923 struct return convention).
925 For a return-value stored in a register: when WRITEBUF is non-NULL,
926 copy the buffer to the corresponding register return-value location
927 location; when READBUF is non-NULL, fill the buffer from the
928 corresponding register return-value location. */
929 enum return_value_convention
930 ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
931 struct regcache *regcache, gdb_byte *readbuf,
932 const gdb_byte *writebuf)
934 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
936 /* This function exists to support a calling convention that
937 requires floating-point registers. It shouldn't be used on
938 processors that lack them. */
939 gdb_assert (ppc_floating_point_unit_p (gdbarch));
941 /* Floats and doubles in F1. */
942 if (TYPE_CODE (valtype) == TYPE_CODE_FLT && TYPE_LENGTH (valtype) <= 8)
944 gdb_byte regval[MAX_REGISTER_SIZE];
945 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
946 if (writebuf != NULL)
948 convert_typed_floating (writebuf, valtype, regval, regtype);
949 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
953 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
954 convert_typed_floating (regval, regtype, readbuf, valtype);
956 return RETURN_VALUE_REGISTER_CONVENTION;
958 /* Integers in r3. */
959 if ((TYPE_CODE (valtype) == TYPE_CODE_INT
960 || TYPE_CODE (valtype) == TYPE_CODE_ENUM)
961 && TYPE_LENGTH (valtype) <= 8)
963 if (writebuf != NULL)
965 /* Be careful to sign extend the value. */
966 regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
967 unpack_long (valtype, writebuf));
971 /* Extract the integer from r3. Since this is truncating the
972 value, there isn't a sign extension problem. */
974 regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
976 store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), regval);
978 return RETURN_VALUE_REGISTER_CONVENTION;
980 /* All pointers live in r3. */
981 if (TYPE_CODE (valtype) == TYPE_CODE_PTR)
983 /* All pointers live in r3. */
984 if (writebuf != NULL)
985 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf);
987 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf);
988 return RETURN_VALUE_REGISTER_CONVENTION;
990 /* Array type has more than one use. */
991 if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
993 /* Small character arrays are returned, right justified, in r3. */
994 if (TYPE_LENGTH (valtype) <= 8
995 && TYPE_CODE (TYPE_TARGET_TYPE (valtype)) == TYPE_CODE_INT
996 && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype)) == 1)
998 int offset = (register_size (gdbarch, tdep->ppc_gp0_regnum + 3)
999 - TYPE_LENGTH (valtype));
1000 if (writebuf != NULL)
1001 regcache_cooked_write_part (regcache, tdep->ppc_gp0_regnum + 3,
1002 offset, TYPE_LENGTH (valtype), writebuf);
1003 if (readbuf != NULL)
1004 regcache_cooked_read_part (regcache, tdep->ppc_gp0_regnum + 3,
1005 offset, TYPE_LENGTH (valtype), readbuf);
1006 return RETURN_VALUE_REGISTER_CONVENTION;
1008 /* A VMX vector is returned in v2. */
1009 if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
1010 && TYPE_VECTOR (valtype) && tdep->ppc_vr0_regnum >= 0)
1013 regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
1015 regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf);
1016 return RETURN_VALUE_REGISTER_CONVENTION;
1019 /* Big floating point values get stored in adjacent floating
1020 point registers, starting with F1. */
1021 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
1022 && (TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 32))
1024 if (writebuf || readbuf != NULL)
1027 for (i = 0; i < TYPE_LENGTH (valtype) / 8; i++)
1029 if (writebuf != NULL)
1030 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i,
1031 (const bfd_byte *) writebuf + i * 8);
1032 if (readbuf != NULL)
1033 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i,
1034 (bfd_byte *) readbuf + i * 8);
1037 return RETURN_VALUE_REGISTER_CONVENTION;
1039 /* Complex values get returned in f1:f2, need to convert. */
1040 if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX
1041 && (TYPE_LENGTH (valtype) == 8 || TYPE_LENGTH (valtype) == 16))
1043 if (regcache != NULL)
1046 for (i = 0; i < 2; i++)
1048 gdb_byte regval[MAX_REGISTER_SIZE];
1049 struct type *regtype =
1050 register_type (current_gdbarch, tdep->ppc_fp0_regnum);
1051 if (writebuf != NULL)
1053 convert_typed_floating ((const bfd_byte *) writebuf +
1054 i * (TYPE_LENGTH (valtype) / 2),
1055 valtype, regval, regtype);
1056 regcache_cooked_write (regcache,
1057 tdep->ppc_fp0_regnum + 1 + i,
1060 if (readbuf != NULL)
1062 regcache_cooked_read (regcache,
1063 tdep->ppc_fp0_regnum + 1 + i,
1065 convert_typed_floating (regval, regtype,
1066 (bfd_byte *) readbuf +
1067 i * (TYPE_LENGTH (valtype) / 2),
1072 return RETURN_VALUE_REGISTER_CONVENTION;
1074 /* Big complex values get stored in f1:f4. */
1075 if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX && TYPE_LENGTH (valtype) == 32)
1077 if (regcache != NULL)
1080 for (i = 0; i < 4; i++)
1082 if (writebuf != NULL)
1083 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i,
1084 (const bfd_byte *) writebuf + i * 8);
1085 if (readbuf != NULL)
1086 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i,
1087 (bfd_byte *) readbuf + i * 8);
1090 return RETURN_VALUE_REGISTER_CONVENTION;
1092 return RETURN_VALUE_STRUCT_CONVENTION;
1096 ppc64_sysv_abi_adjust_breakpoint_address (struct gdbarch *gdbarch,
1099 /* PPC64 SYSV specifies that the minimal-symbol "FN" should point at
1100 a function-descriptor while the corresponding minimal-symbol
1101 ".FN" should point at the entry point. Consequently, a command
1102 like "break FN" applied to an object file with only minimal
1103 symbols, will insert the breakpoint into the descriptor at "FN"
1104 and not the function at ".FN". Avoid this confusion by adjusting
1105 any attempt to set a descriptor breakpoint into a corresponding
1106 function breakpoint. Note that GDB warns the user when this
1107 adjustment is applied - that's ok as otherwise the user will have
1108 no way of knowing why their breakpoint at "FN" resulted in the
1109 program stopping at ".FN". */
1110 return gdbarch_convert_from_func_ptr_addr (gdbarch, bpaddr, ¤t_target);