Update description of macro keyword argument assignment in assembler documentation.
[binutils-gdb.git] / gdb / rs6000-aix-tdep.c
blob5111f4f55c0ad86f9dd80e484e8c5f6f49a103bf
1 /* Native support code for PPC AIX, for GDB the GNU debugger.
3 Copyright (C) 2006-2024 Free Software Foundation, Inc.
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/>. */
22 #include "osabi.h"
23 #include "regcache.h"
24 #include "regset.h"
25 #include "gdbtypes.h"
26 #include "gdbcore.h"
27 #include "target.h"
28 #include "value.h"
29 #include "infcall.h"
30 #include "objfiles.h"
31 #include "breakpoint.h"
32 #include "ppc-tdep.h"
33 #include "rs6000-aix-tdep.h"
34 #include "xcoffread.h"
35 #include "solib.h"
36 #include "solib-aix.h"
37 #include "target-float.h"
38 #include "gdbsupport/xml-utils.h"
39 #include "trad-frame.h"
40 #include "frame-unwind.h"
42 /* If the kernel has to deliver a signal, it pushes a sigcontext
43 structure on the stack and then calls the signal handler, passing
44 the address of the sigcontext in an argument register. Usually
45 the signal handler doesn't save this register, so we have to
46 access the sigcontext structure via an offset from the signal handler
47 frame.
48 The following constants were determined by experimentation on AIX 3.2.
50 sigcontext structure have the mstsave saved under the
51 sc_jmpbuf.jmp_context. STKMIN(minimum stack size) is 56 for 32-bit
52 processes, and iar offset under sc_jmpbuf.jmp_context is 40.
53 ie offsetof(struct sigcontext, sc_jmpbuf.jmp_context.iar).
54 so PC offset in this case is STKMIN+iar offset, which is 96. */
56 #define SIG_FRAME_PC_OFFSET 96
57 #define SIG_FRAME_LR_OFFSET 108
58 /* STKMIN+grp1 offset, which is 56+228=284 */
59 #define SIG_FRAME_FP_OFFSET 284
61 /* 64 bit process.
62 STKMIN64 is 112 and iar offset is 312. So 112+312=424 */
63 #define SIG_FRAME_LR_OFFSET64 424
64 /* STKMIN64+grp1 offset. 112+56=168 */
65 #define SIG_FRAME_FP_OFFSET64 168
67 /* Minimum possible text address in AIX. */
68 #define AIX_TEXT_SEGMENT_BASE 0x10000000
70 struct rs6000_aix_reg_vrreg_offset
72 int vr0_offset;
73 int vscr_offset;
74 int vrsave_offset;
77 static struct rs6000_aix_reg_vrreg_offset rs6000_aix_vrreg_offset =
79 /* AltiVec registers. */
80 32, /* vr0_offset */
81 544, /* vscr_offset. */
82 560 /* vrsave_offset */
85 static int
86 rs6000_aix_get_vrreg_offset (ppc_gdbarch_tdep *tdep,
87 const struct rs6000_aix_reg_vrreg_offset *offsets,
88 int regnum)
90 if (regnum >= tdep->ppc_vr0_regnum &&
91 regnum < tdep->ppc_vr0_regnum + ppc_num_vrs)
92 return offsets->vr0_offset + (regnum - tdep->ppc_vr0_regnum) * 16;
94 if (regnum == tdep->ppc_vrsave_regnum - 1)
95 return offsets->vscr_offset;
97 if (regnum == tdep->ppc_vrsave_regnum)
98 return offsets->vrsave_offset;
100 return -1;
103 static void
104 rs6000_aix_supply_vrregset (const struct regset *regset, struct regcache *regcache,
105 int regnum, const void *vrregs, size_t len)
107 struct gdbarch *gdbarch = regcache->arch ();
108 const struct rs6000_aix_reg_vrreg_offset *offsets;
109 size_t offset;
110 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
111 if (!(tdep->ppc_vr0_regnum >= 0 && tdep->ppc_vrsave_regnum >= 0))
112 return;
114 offsets = (const struct rs6000_aix_reg_vrreg_offset *) regset->regmap;
115 if (regnum == -1)
117 int i;
119 for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset;
120 i < tdep->ppc_vr0_regnum + ppc_num_vrs;
121 i++, offset += 16)
122 ppc_supply_reg (regcache, i, (const gdb_byte *) vrregs, offset, 16);
124 ppc_supply_reg (regcache, (tdep->ppc_vrsave_regnum - 1),
125 (const gdb_byte *) vrregs, offsets->vscr_offset, 4);
127 ppc_supply_reg (regcache, tdep->ppc_vrsave_regnum,
128 (const gdb_byte *) vrregs, offsets->vrsave_offset, 4);
130 return;
132 offset = rs6000_aix_get_vrreg_offset (tdep, offsets, regnum);
133 if (regnum != tdep->ppc_vrsave_regnum &&
134 regnum != tdep->ppc_vrsave_regnum - 1)
135 ppc_supply_reg (regcache, regnum, (const gdb_byte *) vrregs, offset, 16);
136 else
137 ppc_supply_reg (regcache, regnum,
138 (const gdb_byte *) vrregs, offset, 4);
142 static void
143 rs6000_aix_supply_vsxregset (const struct regset *regset, struct regcache *regcache,
144 int regnum, const void *vsxregs, size_t len)
146 struct gdbarch *gdbarch = regcache->arch ();
147 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
148 if (!(tdep->ppc_vsr0_regnum >= 0))
149 return;
151 if (regnum == -1)
153 int i, offset = 0;
155 for (i = tdep->ppc_vsr0_upper_regnum; i < tdep->ppc_vsr0_upper_regnum
156 + 32; i++, offset += 8)
157 ppc_supply_reg (regcache, i, (const gdb_byte *) vsxregs, offset, 8);
159 return;
161 else
162 ppc_supply_reg (regcache, regnum, (const gdb_byte *) vsxregs, 0, 8);
165 static void
166 rs6000_aix_collect_vsxregset (const struct regset *regset,
167 const struct regcache *regcache,
168 int regnum, void *vsxregs, size_t len)
170 struct gdbarch *gdbarch = regcache->arch ();
171 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
172 if (!(tdep->ppc_vsr0_regnum >= 0))
173 return;
175 if (regnum == -1)
177 int i;
178 int offset = 0;
179 for (i = tdep->ppc_vsr0_upper_regnum; i < tdep->ppc_vsr0_upper_regnum
180 + 32; i++, offset += 8)
181 ppc_collect_reg (regcache, i, (gdb_byte *) vsxregs, offset, 8);
183 return;
185 else
186 ppc_collect_reg (regcache, regnum, (gdb_byte *) vsxregs, 0, 8);
189 static void
190 rs6000_aix_collect_vrregset (const struct regset *regset,
191 const struct regcache *regcache,
192 int regnum, void *vrregs, size_t len)
194 struct gdbarch *gdbarch = regcache->arch ();
195 const struct rs6000_aix_reg_vrreg_offset *offsets;
196 size_t offset;
198 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
199 if (!(tdep->ppc_vr0_regnum >= 0 && tdep->ppc_vrsave_regnum >= 0))
200 return;
202 offsets = (const struct rs6000_aix_reg_vrreg_offset *) regset->regmap;
203 if (regnum == -1)
205 int i;
207 for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset; i <
208 tdep->ppc_vr0_regnum + ppc_num_vrs; i++, offset += 16)
209 ppc_collect_reg (regcache, i, (gdb_byte *) vrregs, offset, 16);
211 ppc_collect_reg (regcache, (tdep->ppc_vrsave_regnum - 1),
212 (gdb_byte *) vrregs, offsets->vscr_offset, 4);
214 ppc_collect_reg (regcache, tdep->ppc_vrsave_regnum,
215 (gdb_byte *) vrregs, offsets->vrsave_offset, 4);
217 return;
220 offset = rs6000_aix_get_vrreg_offset (tdep, offsets, regnum);
221 if (regnum != tdep->ppc_vrsave_regnum
222 && regnum != tdep->ppc_vrsave_regnum - 1)
223 ppc_collect_reg (regcache, regnum, (gdb_byte *) vrregs, offset, 16);
224 else
225 ppc_collect_reg (regcache, regnum,
226 (gdb_byte *) vrregs, offset, 4);
229 static const struct regset rs6000_aix_vrregset = {
230 &rs6000_aix_vrreg_offset,
231 rs6000_aix_supply_vrregset,
232 rs6000_aix_collect_vrregset
235 static const struct regset rs6000_aix_vsxregset = {
236 &rs6000_aix_vrreg_offset,
237 rs6000_aix_supply_vsxregset,
238 rs6000_aix_collect_vsxregset
241 static struct trad_frame_cache *
242 aix_sighandle_frame_cache (const frame_info_ptr &this_frame,
243 void **this_cache)
245 LONGEST backchain;
246 CORE_ADDR base, base_orig, func;
247 struct gdbarch *gdbarch = get_frame_arch (this_frame);
248 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
249 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
250 struct trad_frame_cache *this_trad_cache;
252 if ((*this_cache) != NULL)
253 return (struct trad_frame_cache *) (*this_cache);
255 this_trad_cache = trad_frame_cache_zalloc (this_frame);
256 (*this_cache) = this_trad_cache;
258 base = get_frame_register_unsigned (this_frame,
259 gdbarch_sp_regnum (gdbarch));
260 base_orig = base;
262 if (tdep->wordsize == 4)
264 func = read_memory_unsigned_integer (base_orig +
265 SIG_FRAME_PC_OFFSET + 8,
266 tdep->wordsize, byte_order);
267 safe_read_memory_integer (base_orig + SIG_FRAME_FP_OFFSET + 8,
268 tdep->wordsize, byte_order, &backchain);
269 base = (CORE_ADDR)backchain;
271 else
273 func = read_memory_unsigned_integer (base_orig +
274 SIG_FRAME_LR_OFFSET64,
275 tdep->wordsize, byte_order);
276 safe_read_memory_integer (base_orig + SIG_FRAME_FP_OFFSET64,
277 tdep->wordsize, byte_order, &backchain);
278 base = (CORE_ADDR)backchain;
281 trad_frame_set_reg_value (this_trad_cache, gdbarch_pc_regnum (gdbarch), func);
282 trad_frame_set_reg_value (this_trad_cache, gdbarch_sp_regnum (gdbarch), base);
284 if (tdep->wordsize == 4)
285 trad_frame_set_reg_addr (this_trad_cache, tdep->ppc_lr_regnum,
286 base_orig + 0x38 + 52 + 8);
287 else
288 trad_frame_set_reg_addr (this_trad_cache, tdep->ppc_lr_regnum,
289 base_orig + 0x70 + 320);
291 trad_frame_set_id (this_trad_cache, frame_id_build (base, func));
292 trad_frame_set_this_base (this_trad_cache, base);
294 return this_trad_cache;
297 static void
298 aix_sighandle_frame_this_id (const frame_info_ptr &this_frame,
299 void **this_prologue_cache,
300 struct frame_id *this_id)
302 struct trad_frame_cache *this_trad_cache
303 = aix_sighandle_frame_cache (this_frame, this_prologue_cache);
304 trad_frame_get_id (this_trad_cache, this_id);
307 static struct value *
308 aix_sighandle_frame_prev_register (const frame_info_ptr &this_frame,
309 void **this_prologue_cache, int regnum)
311 struct trad_frame_cache *this_trad_cache
312 = aix_sighandle_frame_cache (this_frame, this_prologue_cache);
313 return trad_frame_get_register (this_trad_cache, this_frame, regnum);
316 static int
317 aix_sighandle_frame_sniffer (const struct frame_unwind *self,
318 const frame_info_ptr &this_frame,
319 void **this_prologue_cache)
321 CORE_ADDR pc = get_frame_pc (this_frame);
322 if (pc && pc < AIX_TEXT_SEGMENT_BASE)
323 return 1;
325 return 0;
328 /* AIX signal handler frame unwinder */
330 static const struct frame_unwind aix_sighandle_frame_unwind = {
331 "rs6000 aix sighandle",
332 SIGTRAMP_FRAME,
333 default_frame_unwind_stop_reason,
334 aix_sighandle_frame_this_id,
335 aix_sighandle_frame_prev_register,
336 NULL,
337 aix_sighandle_frame_sniffer
340 /* Core file support. */
342 static struct ppc_reg_offsets rs6000_aix32_reg_offsets =
344 /* General-purpose registers. */
345 208, /* r0_offset */
346 4, /* gpr_size */
347 4, /* xr_size */
348 24, /* pc_offset */
349 28, /* ps_offset */
350 32, /* cr_offset */
351 36, /* lr_offset */
352 40, /* ctr_offset */
353 44, /* xer_offset */
354 48, /* mq_offset */
356 /* Floating-point registers. */
357 336, /* f0_offset */
358 56, /* fpscr_offset */
359 4 /* fpscr_size */
362 static struct ppc_reg_offsets rs6000_aix64_reg_offsets =
364 /* General-purpose registers. */
365 0, /* r0_offset */
366 8, /* gpr_size */
367 4, /* xr_size */
368 264, /* pc_offset */
369 256, /* ps_offset */
370 288, /* cr_offset */
371 272, /* lr_offset */
372 280, /* ctr_offset */
373 292, /* xer_offset */
374 -1, /* mq_offset */
376 /* Floating-point registers. */
377 312, /* f0_offset */
378 296, /* fpscr_offset */
379 4 /* fpscr_size */
383 /* Supply register REGNUM in the general-purpose register set REGSET
384 from the buffer specified by GREGS and LEN to register cache
385 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
387 static void
388 rs6000_aix_supply_regset (const struct regset *regset,
389 struct regcache *regcache, int regnum,
390 const void *gregs, size_t len)
392 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
393 ppc_supply_fpregset (regset, regcache, regnum, gregs, len);
396 /* Collect register REGNUM in the general-purpose register set
397 REGSET, from register cache REGCACHE into the buffer specified by
398 GREGS and LEN. If REGNUM is -1, do this for all registers in
399 REGSET. */
401 static void
402 rs6000_aix_collect_regset (const struct regset *regset,
403 const struct regcache *regcache, int regnum,
404 void *gregs, size_t len)
406 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
407 ppc_collect_fpregset (regset, regcache, regnum, gregs, len);
410 /* AIX register set. */
412 static const struct regset rs6000_aix32_regset =
414 &rs6000_aix32_reg_offsets,
415 rs6000_aix_supply_regset,
416 rs6000_aix_collect_regset,
419 static const struct regset rs6000_aix64_regset =
421 &rs6000_aix64_reg_offsets,
422 rs6000_aix_supply_regset,
423 rs6000_aix_collect_regset,
426 /* Iterate over core file register note sections. */
428 static void
429 rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
430 iterate_over_regset_sections_cb *cb,
431 void *cb_data,
432 const struct regcache *regcache)
434 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
435 int have_altivec = tdep->ppc_vr0_regnum != -1;
436 int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
438 if (tdep->wordsize == 4)
439 cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
440 else
441 cb (".reg", 576, 576, &rs6000_aix64_regset, NULL, cb_data);
443 if (have_altivec)
444 cb (".aix-vmx", 560, 560, &rs6000_aix_vrregset, "AIX altivec", cb_data);
446 if (have_vsx)
447 cb (".aix-vsx", 256, 256, &rs6000_aix_vsxregset, "AIX vsx", cb_data);
451 /* Read core file description for AIX. */
453 static const struct target_desc *
454 ppc_aix_core_read_description (struct gdbarch *gdbarch,
455 struct target_ops *target,
456 bfd *abfd)
458 asection *altivec = bfd_get_section_by_name (abfd, ".aix-vmx");
459 asection *vsx = bfd_get_section_by_name (abfd, ".aix-vsx");
460 asection *section = bfd_get_section_by_name (abfd, ".reg");
461 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
463 if (!section)
464 return NULL;
466 int arch64 = 0;
467 if (tdep->wordsize == 8)
468 arch64 = 1;
470 if (vsx && arch64)
471 return tdesc_powerpc_vsx64;
472 else if (vsx && !arch64)
473 return tdesc_powerpc_vsx32;
474 else if (altivec && arch64)
475 return tdesc_powerpc_altivec64;
476 else if (altivec && !arch64)
477 return tdesc_powerpc_altivec32;
479 return NULL;
482 /* Pass the arguments in either registers, or in the stack. In RS/6000,
483 the first eight words of the argument list (that might be less than
484 eight parameters if some parameters occupy more than one word) are
485 passed in r3..r10 registers. Float and double parameters are
486 passed in fpr's, in addition to that. Rest of the parameters if any
487 are passed in user stack. There might be cases in which half of the
488 parameter is copied into registers, the other half is pushed into
489 stack.
491 Stack must be aligned on 64-bit boundaries when synthesizing
492 function calls.
494 If the function is returning a structure, then the return address is passed
495 in r3, then the first 7 words of the parameters can be passed in registers,
496 starting from r4. */
498 static CORE_ADDR
499 rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
500 struct regcache *regcache, CORE_ADDR bp_addr,
501 int nargs, struct value **args, CORE_ADDR sp,
502 function_call_return_method return_method,
503 CORE_ADDR struct_addr)
505 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
506 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
507 int ii;
508 int len = 0;
509 int argno; /* current argument number */
510 int argbytes; /* current argument byte */
511 gdb_byte tmp_buffer[50];
512 int f_argno = 0; /* current floating point argno */
513 int wordsize = tdep->wordsize;
514 CORE_ADDR func_addr = find_function_addr (function, NULL);
516 struct value *arg = 0;
517 struct type *type;
519 ULONGEST saved_sp;
521 /* The calling convention this function implements assumes the
522 processor has floating-point registers. We shouldn't be using it
523 on PPC variants that lack them. */
524 gdb_assert (ppc_floating_point_unit_p (gdbarch));
526 /* The first eight words of ther arguments are passed in registers.
527 Copy them appropriately. */
528 ii = 0;
530 /* If the function is returning a `struct', then the first word
531 (which will be passed in r3) is used for struct return address.
532 In that case we should advance one word and start from r4
533 register to copy parameters. */
534 if (return_method == return_method_struct)
536 regcache_raw_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
537 struct_addr);
538 ii++;
541 /* effectively indirect call... gcc does...
543 return_val example( float, int);
545 eabi:
546 float in fp0, int in r3
547 offset of stack on overflow 8/16
548 for varargs, must go by type.
549 power open:
550 float in r3&r4, int in r5
551 offset of stack on overflow different
552 both:
553 return in r3 or f0. If no float, must study how gcc emulates floats;
554 pay attention to arg promotion.
555 User may have to cast\args to handle promotion correctly
556 since gdb won't know if prototype supplied or not. */
558 for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii)
560 int reg_size = register_size (gdbarch, ii + 3);
562 arg = args[argno];
563 type = check_typedef (arg->type ());
564 len = type->length ();
566 if (type->code () == TYPE_CODE_FLT)
568 /* Floating point arguments are passed in fpr's, as well as gpr's.
569 There are 13 fpr's reserved for passing parameters. At this point
570 there is no way we would run out of them.
572 Always store the floating point value using the register's
573 floating-point format. */
574 const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno;
575 gdb_byte reg_val[PPC_MAX_REGISTER_SIZE];
576 struct type *reg_type = register_type (gdbarch, fp_regnum);
578 gdb_assert (len <= 8);
580 target_float_convert (arg->contents ().data (), type, reg_val,
581 reg_type);
582 regcache->cooked_write (fp_regnum, reg_val);
583 ++f_argno;
586 if (len > reg_size)
589 /* Argument takes more than one register. */
590 while (argbytes < len)
592 gdb_byte word[PPC_MAX_REGISTER_SIZE];
593 memset (word, 0, reg_size);
594 memcpy (word,
595 ((char *) arg->contents ().data ()) + argbytes,
596 (len - argbytes) > reg_size
597 ? reg_size : len - argbytes);
598 regcache->cooked_write (tdep->ppc_gp0_regnum + 3 + ii, word);
599 ++ii, argbytes += reg_size;
601 if (ii >= 8)
602 goto ran_out_of_registers_for_arguments;
604 argbytes = 0;
605 --ii;
607 else
609 /* Argument can fit in one register. No problem. */
610 gdb_byte word[PPC_MAX_REGISTER_SIZE];
612 memset (word, 0, reg_size);
613 if (type->code () == TYPE_CODE_INT
614 || type->code () == TYPE_CODE_ENUM
615 || type->code () == TYPE_CODE_BOOL
616 || type->code () == TYPE_CODE_CHAR)
617 /* Sign or zero extend the "int" into a "word". */
618 store_unsigned_integer (word, reg_size, byte_order,
619 unpack_long (type, arg->contents ().data ()));
620 else
621 memcpy (word, arg->contents ().data (), len);
622 regcache->cooked_write (tdep->ppc_gp0_regnum + 3 +ii, word);
624 ++argno;
627 ran_out_of_registers_for_arguments:
629 regcache_cooked_read_unsigned (regcache,
630 gdbarch_sp_regnum (gdbarch),
631 &saved_sp);
633 /* Location for 8 parameters are always reserved. */
634 sp -= wordsize * 8;
636 /* Another six words for back chain, TOC register, link register, etc. */
637 sp -= wordsize * 6;
639 /* Stack pointer must be quadword aligned. */
640 sp &= -16;
642 /* If there are more arguments, allocate space for them in
643 the stack, then push them starting from the ninth one. */
645 if ((argno < nargs) || argbytes)
647 int space = 0, jj;
649 if (argbytes)
651 space += ((len - argbytes + wordsize -1) & -wordsize);
652 jj = argno + 1;
654 else
655 jj = argno;
657 for (; jj < nargs; ++jj)
659 struct value *val = args[jj];
660 space += ((val->type ()->length () + wordsize -1) & -wordsize);
663 /* Add location required for the rest of the parameters. */
664 space = (space + 15) & -16;
665 sp -= space;
667 /* This is another instance we need to be concerned about
668 securing our stack space. If we write anything underneath %sp
669 (r1), we might conflict with the kernel who thinks he is free
670 to use this area. So, update %sp first before doing anything
671 else. */
673 regcache_raw_write_signed (regcache,
674 gdbarch_sp_regnum (gdbarch), sp);
676 /* If the last argument copied into the registers didn't fit there
677 completely, push the rest of it into stack. */
679 if (argbytes)
681 write_memory (sp + 6 * wordsize + (ii * wordsize),
682 arg->contents ().data () + argbytes,
683 len - argbytes);
684 ++argno;
685 ii += ((len - argbytes + wordsize - 1) & -wordsize) / wordsize;
688 /* Push the rest of the arguments into stack. */
689 for (; argno < nargs; ++argno)
692 arg = args[argno];
693 type = check_typedef (arg->type ());
694 len = type->length ();
697 /* Float types should be passed in fpr's, as well as in the
698 stack. */
699 if (type->code () == TYPE_CODE_FLT && f_argno < 13)
702 gdb_assert (len <= 8);
704 regcache->cooked_write (tdep->ppc_fp0_regnum + 1 + f_argno,
705 arg->contents ().data ());
706 ++f_argno;
709 if (type->code () == TYPE_CODE_INT
710 || type->code () == TYPE_CODE_ENUM
711 || type->code () == TYPE_CODE_BOOL
712 || type->code () == TYPE_CODE_CHAR )
714 gdb_byte word[PPC_MAX_REGISTER_SIZE];
715 memset (word, 0, PPC_MAX_REGISTER_SIZE);
716 store_unsigned_integer (word, tdep->wordsize, byte_order,
717 unpack_long (type, arg->contents ().data ()));
718 write_memory (sp + 6 * wordsize + (ii * wordsize), word, PPC_MAX_REGISTER_SIZE);
720 else
721 write_memory (sp + 6 * wordsize + (ii * wordsize), arg->contents ().data (), len);
722 ii += ((len + wordsize -1) & -wordsize) / wordsize;
726 /* Set the stack pointer. According to the ABI, the SP is meant to
727 be set _before_ the corresponding stack space is used. On AIX,
728 this even applies when the target has been completely stopped!
729 Not doing this can lead to conflicts with the kernel which thinks
730 that it still has control over this not-yet-allocated stack
731 region. */
732 regcache_raw_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp);
734 /* Set back chain properly. */
735 store_unsigned_integer (tmp_buffer, wordsize, byte_order, saved_sp);
736 write_memory (sp, tmp_buffer, wordsize);
738 /* Point the inferior function call's return address at the dummy's
739 breakpoint. */
740 regcache_raw_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
742 /* Set the TOC register value. */
743 regcache_raw_write_signed (regcache, tdep->ppc_toc_regnum,
744 solib_aix_get_toc_value (func_addr));
746 target_store_registers (regcache, -1);
747 return sp;
750 static enum return_value_convention
751 rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
752 struct type *valtype, struct regcache *regcache,
753 gdb_byte *readbuf, const gdb_byte *writebuf)
755 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
756 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
758 /* The calling convention this function implements assumes the
759 processor has floating-point registers. We shouldn't be using it
760 on PowerPC variants that lack them. */
761 gdb_assert (ppc_floating_point_unit_p (gdbarch));
763 /* AltiVec extension: Functions that declare a vector data type as a
764 return value place that return value in VR2. */
765 if (valtype->code () == TYPE_CODE_ARRAY && valtype->is_vector ()
766 && valtype->length () == 16)
768 if (readbuf)
769 regcache->cooked_read (tdep->ppc_vr0_regnum + 2, readbuf);
770 if (writebuf)
771 regcache->cooked_write (tdep->ppc_vr0_regnum + 2, writebuf);
773 return RETURN_VALUE_REGISTER_CONVENTION;
776 /* If the called subprogram returns an aggregate, there exists an
777 implicit first argument, whose value is the address of a caller-
778 allocated buffer into which the callee is assumed to store its
779 return value. All explicit parameters are appropriately
780 relabeled. */
781 if (valtype->code () == TYPE_CODE_STRUCT
782 || valtype->code () == TYPE_CODE_UNION
783 || valtype->code () == TYPE_CODE_ARRAY)
784 return RETURN_VALUE_STRUCT_CONVENTION;
786 /* Scalar floating-point values are returned in FPR1 for float or
787 double, and in FPR1:FPR2 for quadword precision. Fortran
788 complex*8 and complex*16 are returned in FPR1:FPR2, and
789 complex*32 is returned in FPR1:FPR4. */
790 if (valtype->code () == TYPE_CODE_FLT
791 && (valtype->length () == 4 || valtype->length () == 8))
793 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
794 gdb_byte regval[8];
796 /* FIXME: kettenis/2007-01-01: Add support for quadword
797 precision and complex. */
799 if (readbuf)
801 regcache->cooked_read (tdep->ppc_fp0_regnum + 1, regval);
802 target_float_convert (regval, regtype, readbuf, valtype);
804 if (writebuf)
806 target_float_convert (writebuf, valtype, regval, regtype);
807 regcache->cooked_write (tdep->ppc_fp0_regnum + 1, regval);
810 return RETURN_VALUE_REGISTER_CONVENTION;
813 /* Values of the types int, long, short, pointer, and char (length
814 is less than or equal to four bytes), as well as bit values of
815 lengths less than or equal to 32 bits, must be returned right
816 justified in GPR3 with signed values sign extended and unsigned
817 values zero extended, as necessary. */
818 if (valtype->length () <= tdep->wordsize)
820 if (readbuf)
822 ULONGEST regval;
824 /* For reading we don't have to worry about sign extension. */
825 regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
826 &regval);
827 store_unsigned_integer (readbuf, valtype->length (), byte_order,
828 regval);
830 if (writebuf)
832 /* For writing, use unpack_long since that should handle any
833 required sign extension. */
834 regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
835 unpack_long (valtype, writebuf));
838 return RETURN_VALUE_REGISTER_CONVENTION;
841 /* Eight-byte non-floating-point scalar values must be returned in
842 GPR3:GPR4. */
844 if (valtype->length () == 8)
846 gdb_assert (valtype->code () != TYPE_CODE_FLT);
847 gdb_assert (tdep->wordsize == 4);
849 if (readbuf)
851 gdb_byte regval[8];
853 regcache->cooked_read (tdep->ppc_gp0_regnum + 3, regval);
854 regcache->cooked_read (tdep->ppc_gp0_regnum + 4, regval + 4);
855 memcpy (readbuf, regval, 8);
857 if (writebuf)
859 regcache->cooked_write (tdep->ppc_gp0_regnum + 3, writebuf);
860 regcache->cooked_write (tdep->ppc_gp0_regnum + 4, writebuf + 4);
863 return RETURN_VALUE_REGISTER_CONVENTION;
866 return RETURN_VALUE_STRUCT_CONVENTION;
869 /* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
871 Usually a function pointer's representation is simply the address
872 of the function. On the RS/6000 however, a function pointer is
873 represented by a pointer to an OPD entry. This OPD entry contains
874 three words, the first word is the address of the function, the
875 second word is the TOC pointer (r2), and the third word is the
876 static chain value. Throughout GDB it is currently assumed that a
877 function pointer contains the address of the function, which is not
878 easy to fix. In addition, the conversion of a function address to
879 a function pointer would require allocation of an OPD entry in the
880 inferior's memory space, with all its drawbacks. To be able to
881 call C++ virtual methods in the inferior (which are called via
882 function pointers), find_function_addr uses this function to get the
883 function address from a function pointer. */
885 /* Return real function address if ADDR (a function pointer) is in the data
886 space and is therefore a special function pointer. */
888 static CORE_ADDR
889 rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
890 CORE_ADDR addr,
891 struct target_ops *targ)
893 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
894 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
895 struct obj_section *s;
897 s = find_pc_section (addr);
899 /* Normally, functions live inside a section that is executable.
900 So, if ADDR points to a non-executable section, then treat it
901 as a function descriptor and return the target address iff
902 the target address itself points to a section that is executable. */
903 if (s && (s->the_bfd_section->flags & SEC_CODE) == 0)
905 CORE_ADDR pc = 0;
906 struct obj_section *pc_section;
910 pc = read_memory_unsigned_integer (addr, tdep->wordsize, byte_order);
912 catch (const gdb_exception_error &e)
914 /* An error occurred during reading. Probably a memory error
915 due to the section not being loaded yet. This address
916 cannot be a function descriptor. */
917 return addr;
920 pc_section = find_pc_section (pc);
922 if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE))
923 return pc;
926 return addr;
930 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
932 static CORE_ADDR
933 branch_dest (struct regcache *regcache, int opcode, int instr,
934 CORE_ADDR pc, CORE_ADDR safety)
936 struct gdbarch *gdbarch = regcache->arch ();
937 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
938 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
939 CORE_ADDR dest;
940 int immediate;
941 int absolute;
942 int ext_op;
944 absolute = (int) ((instr >> 1) & 1);
946 switch (opcode)
948 case 18:
949 immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */
950 if (absolute)
951 dest = immediate;
952 else
953 dest = pc + immediate;
954 break;
956 case 16:
957 immediate = ((instr & ~3) << 16) >> 16; /* br conditional */
958 if (absolute)
959 dest = immediate;
960 else
961 dest = pc + immediate;
962 break;
964 case 19:
965 ext_op = (instr >> 1) & 0x3ff;
967 if (ext_op == 16) /* br conditional register */
969 dest = regcache_raw_get_unsigned (regcache, tdep->ppc_lr_regnum) & ~3;
971 /* If we are about to return from a signal handler, dest is
972 something like 0x3c90. The current frame is a signal handler
973 caller frame, upon completion of the sigreturn system call
974 execution will return to the saved PC in the frame. */
975 if (dest < AIX_TEXT_SEGMENT_BASE)
977 frame_info_ptr frame = get_current_frame ();
979 dest = read_memory_unsigned_integer
980 (get_frame_base (frame) + SIG_FRAME_PC_OFFSET,
981 tdep->wordsize, byte_order);
985 else if (ext_op == 528) /* br cond to count reg */
987 dest = regcache_raw_get_unsigned (regcache,
988 tdep->ppc_ctr_regnum) & ~3;
990 /* If we are about to execute a system call, dest is something
991 like 0x22fc or 0x3b00. Upon completion the system call
992 will return to the address in the link register. */
993 if (dest < AIX_TEXT_SEGMENT_BASE)
994 dest = regcache_raw_get_unsigned (regcache,
995 tdep->ppc_lr_regnum) & ~3;
997 else
998 return -1;
999 break;
1001 default:
1002 return -1;
1004 return (dest < AIX_TEXT_SEGMENT_BASE) ? safety : dest;
1007 /* AIX does not support PT_STEP. Simulate it. */
1009 static std::vector<CORE_ADDR>
1010 rs6000_software_single_step (struct regcache *regcache)
1012 struct gdbarch *gdbarch = regcache->arch ();
1013 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1014 int ii, insn;
1015 CORE_ADDR loc;
1016 CORE_ADDR breaks[2];
1017 int opcode;
1019 loc = regcache_read_pc (regcache);
1021 insn = read_memory_integer (loc, 4, byte_order);
1023 std::vector<CORE_ADDR> next_pcs = ppc_deal_with_atomic_sequence (regcache);
1024 if (!next_pcs.empty ())
1025 return next_pcs;
1027 /* Here 0xfc000000 is the opcode mask to detect a P10 prefix instruction. */
1028 if ((insn & 0xfc000000) == 1 << 26)
1029 breaks[0] = loc + 2 * PPC_INSN_SIZE;
1030 else
1031 breaks[0] = loc + PPC_INSN_SIZE;
1032 opcode = insn >> 26;
1033 breaks[1] = branch_dest (regcache, opcode, insn, loc, breaks[0]);
1035 /* Don't put two breakpoints on the same address. */
1036 if (breaks[1] == breaks[0])
1037 breaks[1] = -1;
1039 for (ii = 0; ii < 2; ++ii)
1041 /* ignore invalid breakpoint. */
1042 if (breaks[ii] == -1)
1043 continue;
1045 next_pcs.push_back (breaks[ii]);
1048 errno = 0; /* FIXME, don't ignore errors! */
1049 /* What errors? {read,write}_memory call error(). */
1050 return next_pcs;
1053 /* Implement the "auto_wide_charset" gdbarch method for this platform. */
1055 static const char *
1056 rs6000_aix_auto_wide_charset (void)
1058 return "UTF-16";
1061 /* Implement an osabi sniffer for RS6000/AIX.
1063 This function assumes that ABFD's flavour is XCOFF. In other words,
1064 it should be registered as a sniffer for bfd_target_xcoff_flavour
1065 objfiles only. A failed assertion will be raised if this condition
1066 is not met. */
1068 static enum gdb_osabi
1069 rs6000_aix_osabi_sniffer (bfd *abfd)
1071 gdb_assert (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
1073 /* The only noticeable difference between Lynx178 XCOFF files and
1074 AIX XCOFF files comes from the fact that there are no shared
1075 libraries on Lynx178. On AIX, we are betting that an executable
1076 linked with no shared library will never exist. */
1077 if (xcoff_get_n_import_files (abfd) <= 0)
1078 return GDB_OSABI_UNKNOWN;
1080 return GDB_OSABI_AIX;
1083 /* A structure encoding the offset and size of a field within
1084 a struct. */
1086 struct ldinfo_field
1088 int offset;
1089 int size;
1092 /* A structure describing the layout of all the fields of interest
1093 in AIX's struct ld_info. Each field in this struct corresponds
1094 to the field of the same name in struct ld_info. */
1096 struct ld_info_desc
1098 struct ldinfo_field ldinfo_next;
1099 struct ldinfo_field ldinfo_fd;
1100 struct ldinfo_field ldinfo_textorg;
1101 struct ldinfo_field ldinfo_textsize;
1102 struct ldinfo_field ldinfo_dataorg;
1103 struct ldinfo_field ldinfo_datasize;
1104 struct ldinfo_field ldinfo_filename;
1107 /* The following data has been generated by compiling and running
1108 the following program on AIX 5.3. */
1110 #if 0
1111 #include <stddef.h>
1112 #include <stdio.h>
1113 #define __LDINFO_PTRACE32__
1114 #define __LDINFO_PTRACE64__
1115 #include <sys/ldr.h>
1117 #define pinfo(type,member) \
1119 struct type ldi = {0}; \
1121 printf (" {%d, %d},\t/* %s */\n", \
1122 offsetof (struct type, member), \
1123 sizeof (ldi.member), \
1124 #member); \
1126 while (0)
1129 main (void)
1131 printf ("static const struct ld_info_desc ld_info32_desc =\n{\n");
1132 pinfo (__ld_info32, ldinfo_next);
1133 pinfo (__ld_info32, ldinfo_fd);
1134 pinfo (__ld_info32, ldinfo_textorg);
1135 pinfo (__ld_info32, ldinfo_textsize);
1136 pinfo (__ld_info32, ldinfo_dataorg);
1137 pinfo (__ld_info32, ldinfo_datasize);
1138 pinfo (__ld_info32, ldinfo_filename);
1139 printf ("};\n");
1141 printf ("\n");
1143 printf ("static const struct ld_info_desc ld_info64_desc =\n{\n");
1144 pinfo (__ld_info64, ldinfo_next);
1145 pinfo (__ld_info64, ldinfo_fd);
1146 pinfo (__ld_info64, ldinfo_textorg);
1147 pinfo (__ld_info64, ldinfo_textsize);
1148 pinfo (__ld_info64, ldinfo_dataorg);
1149 pinfo (__ld_info64, ldinfo_datasize);
1150 pinfo (__ld_info64, ldinfo_filename);
1151 printf ("};\n");
1153 return 0;
1155 #endif /* 0 */
1157 /* Layout of the 32bit version of struct ld_info. */
1159 static const struct ld_info_desc ld_info32_desc =
1161 {0, 4}, /* ldinfo_next */
1162 {4, 4}, /* ldinfo_fd */
1163 {8, 4}, /* ldinfo_textorg */
1164 {12, 4}, /* ldinfo_textsize */
1165 {16, 4}, /* ldinfo_dataorg */
1166 {20, 4}, /* ldinfo_datasize */
1167 {24, 2}, /* ldinfo_filename */
1170 /* Layout of the 64bit version of struct ld_info. */
1172 static const struct ld_info_desc ld_info64_desc =
1174 {0, 4}, /* ldinfo_next */
1175 {8, 4}, /* ldinfo_fd */
1176 {16, 8}, /* ldinfo_textorg */
1177 {24, 8}, /* ldinfo_textsize */
1178 {32, 8}, /* ldinfo_dataorg */
1179 {40, 8}, /* ldinfo_datasize */
1180 {48, 2}, /* ldinfo_filename */
1183 /* A structured representation of one entry read from the ld_info
1184 binary data provided by the AIX loader. */
1186 struct ld_info
1188 ULONGEST next;
1189 int fd;
1190 CORE_ADDR textorg;
1191 ULONGEST textsize;
1192 CORE_ADDR dataorg;
1193 ULONGEST datasize;
1194 char *filename;
1195 char *member_name;
1198 /* Return a struct ld_info object corresponding to the entry at
1199 LDI_BUF.
1201 Note that the filename and member_name strings still point
1202 to the data in LDI_BUF. So LDI_BUF must not be deallocated
1203 while the struct ld_info object returned is in use. */
1205 static struct ld_info
1206 rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
1207 const gdb_byte *ldi_buf)
1209 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1210 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1211 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
1212 const struct ld_info_desc desc
1213 = tdep->wordsize == 8 ? ld_info64_desc : ld_info32_desc;
1214 struct ld_info info;
1216 info.next = extract_unsigned_integer (ldi_buf + desc.ldinfo_next.offset,
1217 desc.ldinfo_next.size,
1218 byte_order);
1219 info.fd = extract_signed_integer (ldi_buf + desc.ldinfo_fd.offset,
1220 desc.ldinfo_fd.size,
1221 byte_order);
1222 info.textorg = extract_typed_address (ldi_buf + desc.ldinfo_textorg.offset,
1223 ptr_type);
1224 info.textsize
1225 = extract_unsigned_integer (ldi_buf + desc.ldinfo_textsize.offset,
1226 desc.ldinfo_textsize.size,
1227 byte_order);
1228 info.dataorg = extract_typed_address (ldi_buf + desc.ldinfo_dataorg.offset,
1229 ptr_type);
1230 info.datasize
1231 = extract_unsigned_integer (ldi_buf + desc.ldinfo_datasize.offset,
1232 desc.ldinfo_datasize.size,
1233 byte_order);
1234 info.filename = (char *) ldi_buf + desc.ldinfo_filename.offset;
1235 info.member_name = info.filename + strlen (info.filename) + 1;
1237 return info;
1240 /* Append to XML an XML string description of the shared library
1241 corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
1242 format. */
1244 static void
1245 rs6000_aix_shared_library_to_xml (struct ld_info *ldi, std::string &xml)
1247 xml += "<library name=\"";
1248 xml_escape_text_append (xml, ldi->filename);
1249 xml += '"';
1251 if (ldi->member_name[0] != '\0')
1253 xml += " member=\"";
1254 xml_escape_text_append (xml, ldi->member_name);
1255 xml += '"';
1258 xml += " text_addr=\"";
1259 xml += core_addr_to_string (ldi->textorg);
1260 xml += '"';
1262 xml += " text_size=\"";
1263 xml += pulongest (ldi->textsize);
1264 xml += '"';
1266 xml += " data_addr=\"";
1267 xml += core_addr_to_string (ldi->dataorg);
1268 xml += '"';
1270 xml += " data_size=\"";
1271 xml += pulongest (ldi->datasize);
1272 xml += '"';
1274 xml += "></library>";
1277 /* Convert the ld_info binary data provided by the AIX loader into
1278 an XML representation following the TARGET_OBJECT_LIBRARIES_AIX
1279 format.
1281 LDI_BUF is a buffer containing the ld_info data.
1282 READBUF, OFFSET and LEN follow the same semantics as target_ops'
1283 to_xfer_partial target_ops method.
1285 If CLOSE_LDINFO_FD is nonzero, then this routine also closes
1286 the ldinfo_fd file descriptor. This is useful when the ldinfo
1287 data is obtained via ptrace, as ptrace opens a file descriptor
1288 for each and every entry; but we cannot use this descriptor
1289 as the consumer of the XML library list might live in a different
1290 process. */
1292 ULONGEST
1293 rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
1294 gdb_byte *readbuf, ULONGEST offset, ULONGEST len,
1295 int close_ldinfo_fd)
1297 std::string xml = "<library-list-aix version=\"1.0\">\n";
1299 while (1)
1301 struct ld_info ldi = rs6000_aix_extract_ld_info (gdbarch, ldi_buf);
1303 rs6000_aix_shared_library_to_xml (&ldi, xml);
1304 if (close_ldinfo_fd)
1305 close (ldi.fd);
1307 if (!ldi.next)
1308 break;
1309 ldi_buf = ldi_buf + ldi.next;
1312 xml += "</library-list-aix>\n";
1314 ULONGEST len_avail = xml.length ();
1315 if (offset >= len_avail)
1316 len= 0;
1317 else
1319 if (len > len_avail - offset)
1320 len = len_avail - offset;
1321 memcpy (readbuf, xml.data () + offset, len);
1324 return len;
1327 /* Implement the core_xfer_shared_libraries_aix gdbarch method. */
1329 static ULONGEST
1330 rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
1331 gdb_byte *readbuf,
1332 ULONGEST offset,
1333 ULONGEST len)
1335 struct bfd_section *ldinfo_sec;
1336 int ldinfo_size;
1338 ldinfo_sec = bfd_get_section_by_name (current_program_space->core_bfd (),
1339 ".ldinfo");
1340 if (ldinfo_sec == NULL)
1341 error (_("cannot find .ldinfo section from core file: %s"),
1342 bfd_errmsg (bfd_get_error ()));
1343 ldinfo_size = bfd_section_size (ldinfo_sec);
1345 gdb::byte_vector ldinfo_buf (ldinfo_size);
1347 if (! bfd_get_section_contents (current_program_space->core_bfd (),
1348 ldinfo_sec, ldinfo_buf.data (), 0,
1349 ldinfo_size))
1350 error (_("unable to read .ldinfo section from core file: %s"),
1351 bfd_errmsg (bfd_get_error ()));
1353 return rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf.data (), readbuf,
1354 offset, len, 0);
1357 static void
1358 rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
1360 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1362 /* RS6000/AIX does not support PT_STEP. Has to be simulated. */
1363 set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
1365 /* Displaced stepping is currently not supported in combination with
1366 software single-stepping. These override the values set by
1367 rs6000_gdbarch_init. */
1368 set_gdbarch_displaced_step_copy_insn (gdbarch, NULL);
1369 set_gdbarch_displaced_step_fixup (gdbarch, NULL);
1370 set_gdbarch_displaced_step_prepare (gdbarch, NULL);
1371 set_gdbarch_displaced_step_finish (gdbarch, NULL);
1373 set_gdbarch_push_dummy_call (gdbarch, rs6000_push_dummy_call);
1374 set_gdbarch_return_value (gdbarch, rs6000_return_value);
1375 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
1377 /* Handle RS/6000 function pointers (which are really function
1378 descriptors). */
1379 set_gdbarch_convert_from_func_ptr_addr
1380 (gdbarch, rs6000_convert_from_func_ptr_addr);
1382 /* Core file support. */
1383 set_gdbarch_iterate_over_regset_sections
1384 (gdbarch, rs6000_aix_iterate_over_regset_sections);
1385 set_gdbarch_core_xfer_shared_libraries_aix
1386 (gdbarch, rs6000_aix_core_xfer_shared_libraries_aix);
1387 set_gdbarch_core_read_description (gdbarch, ppc_aix_core_read_description);
1389 if (tdep->wordsize == 8)
1390 tdep->lr_frame_offset = 16;
1391 else
1392 tdep->lr_frame_offset = 8;
1394 if (tdep->wordsize == 4)
1395 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
1396 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
1397 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
1398 224. */
1399 set_gdbarch_frame_red_zone_size (gdbarch, 224);
1400 else
1401 /* In 64 bit mode the red zone should have 18 8 byte GPRS + 18 8 byte
1402 FPRS making it 288 bytes. This is 16 byte aligned as well. */
1403 set_gdbarch_frame_red_zone_size (gdbarch, 288);
1405 if (tdep->wordsize == 8)
1406 set_gdbarch_wchar_bit (gdbarch, 32);
1407 else
1408 set_gdbarch_wchar_bit (gdbarch, 16);
1409 set_gdbarch_wchar_signed (gdbarch, 0);
1410 set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset);
1412 set_gdbarch_so_ops (gdbarch, &solib_aix_so_ops);
1413 frame_unwind_append_unwinder (gdbarch, &aix_sighandle_frame_unwind);
1416 void _initialize_rs6000_aix_tdep ();
1417 void
1418 _initialize_rs6000_aix_tdep ()
1420 gdbarch_register_osabi_sniffer (bfd_arch_rs6000,
1421 bfd_target_xcoff_flavour,
1422 rs6000_aix_osabi_sniffer);
1423 gdbarch_register_osabi_sniffer (bfd_arch_powerpc,
1424 bfd_target_xcoff_flavour,
1425 rs6000_aix_osabi_sniffer);
1427 gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_AIX,
1428 rs6000_aix_init_osabi);
1429 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_AIX,
1430 rs6000_aix_init_osabi);