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 "extract-store-integer.h"
32 #include "breakpoint.h"
34 #include "rs6000-aix-tdep.h"
35 #include "xcoffread.h"
37 #include "solib-aix.h"
38 #include "target-float.h"
39 #include "gdbsupport/xml-utils.h"
40 #include "trad-frame.h"
41 #include "frame-unwind.h"
43 /* If the kernel has to deliver a signal, it pushes a sigcontext
44 structure on the stack and then calls the signal handler, passing
45 the address of the sigcontext in an argument register. Usually
46 the signal handler doesn't save this register, so we have to
47 access the sigcontext structure via an offset from the signal handler
49 The following constants were determined by experimentation on AIX 3.2.
51 sigcontext structure have the mstsave saved under the
52 sc_jmpbuf.jmp_context. STKMIN(minimum stack size) is 56 for 32-bit
53 processes, and iar offset under sc_jmpbuf.jmp_context is 40.
54 ie offsetof(struct sigcontext, sc_jmpbuf.jmp_context.iar).
55 so PC offset in this case is STKMIN+iar offset, which is 96. */
57 #define SIG_FRAME_PC_OFFSET 96
58 #define SIG_FRAME_LR_OFFSET 108
59 /* STKMIN+grp1 offset, which is 56+228=284 */
60 #define SIG_FRAME_FP_OFFSET 284
63 STKMIN64 is 112 and iar offset is 312. So 112+312=424 */
64 #define SIG_FRAME_LR_OFFSET64 424
65 /* STKMIN64+grp1 offset. 112+56=168 */
66 #define SIG_FRAME_FP_OFFSET64 168
68 /* Minimum possible text address in AIX. */
69 #define AIX_TEXT_SEGMENT_BASE 0x10000000
71 struct rs6000_aix_reg_vrreg_offset
78 static struct rs6000_aix_reg_vrreg_offset rs6000_aix_vrreg_offset
=
80 /* AltiVec registers. */
82 544, /* vscr_offset. */
83 560 /* vrsave_offset */
87 rs6000_aix_get_vrreg_offset (ppc_gdbarch_tdep
*tdep
,
88 const struct rs6000_aix_reg_vrreg_offset
*offsets
,
91 if (regnum
>= tdep
->ppc_vr0_regnum
&&
92 regnum
< tdep
->ppc_vr0_regnum
+ ppc_num_vrs
)
93 return offsets
->vr0_offset
+ (regnum
- tdep
->ppc_vr0_regnum
) * 16;
95 if (regnum
== tdep
->ppc_vrsave_regnum
- 1)
96 return offsets
->vscr_offset
;
98 if (regnum
== tdep
->ppc_vrsave_regnum
)
99 return offsets
->vrsave_offset
;
105 rs6000_aix_supply_vrregset (const struct regset
*regset
, struct regcache
*regcache
,
106 int regnum
, const void *vrregs
, size_t len
)
108 struct gdbarch
*gdbarch
= regcache
->arch ();
109 const struct rs6000_aix_reg_vrreg_offset
*offsets
;
111 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
112 if (!(tdep
->ppc_vr0_regnum
>= 0 && tdep
->ppc_vrsave_regnum
>= 0))
115 offsets
= (const struct rs6000_aix_reg_vrreg_offset
*) regset
->regmap
;
120 for (i
= tdep
->ppc_vr0_regnum
, offset
= offsets
->vr0_offset
;
121 i
< tdep
->ppc_vr0_regnum
+ ppc_num_vrs
;
123 ppc_supply_reg (regcache
, i
, (const gdb_byte
*) vrregs
, offset
, 16);
125 ppc_supply_reg (regcache
, (tdep
->ppc_vrsave_regnum
- 1),
126 (const gdb_byte
*) vrregs
, offsets
->vscr_offset
, 4);
128 ppc_supply_reg (regcache
, tdep
->ppc_vrsave_regnum
,
129 (const gdb_byte
*) vrregs
, offsets
->vrsave_offset
, 4);
133 offset
= rs6000_aix_get_vrreg_offset (tdep
, offsets
, regnum
);
134 if (regnum
!= tdep
->ppc_vrsave_regnum
&&
135 regnum
!= tdep
->ppc_vrsave_regnum
- 1)
136 ppc_supply_reg (regcache
, regnum
, (const gdb_byte
*) vrregs
, offset
, 16);
138 ppc_supply_reg (regcache
, regnum
,
139 (const gdb_byte
*) vrregs
, offset
, 4);
144 rs6000_aix_supply_vsxregset (const struct regset
*regset
, struct regcache
*regcache
,
145 int regnum
, const void *vsxregs
, size_t len
)
147 struct gdbarch
*gdbarch
= regcache
->arch ();
148 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
149 if (!(tdep
->ppc_vsr0_regnum
>= 0))
156 for (i
= tdep
->ppc_vsr0_upper_regnum
; i
< tdep
->ppc_vsr0_upper_regnum
157 + 32; i
++, offset
+= 8)
158 ppc_supply_reg (regcache
, i
, (const gdb_byte
*) vsxregs
, offset
, 8);
163 ppc_supply_reg (regcache
, regnum
, (const gdb_byte
*) vsxregs
, 0, 8);
167 rs6000_aix_collect_vsxregset (const struct regset
*regset
,
168 const struct regcache
*regcache
,
169 int regnum
, void *vsxregs
, size_t len
)
171 struct gdbarch
*gdbarch
= regcache
->arch ();
172 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
173 if (!(tdep
->ppc_vsr0_regnum
>= 0))
180 for (i
= tdep
->ppc_vsr0_upper_regnum
; i
< tdep
->ppc_vsr0_upper_regnum
181 + 32; i
++, offset
+= 8)
182 ppc_collect_reg (regcache
, i
, (gdb_byte
*) vsxregs
, offset
, 8);
187 ppc_collect_reg (regcache
, regnum
, (gdb_byte
*) vsxregs
, 0, 8);
191 rs6000_aix_collect_vrregset (const struct regset
*regset
,
192 const struct regcache
*regcache
,
193 int regnum
, void *vrregs
, size_t len
)
195 struct gdbarch
*gdbarch
= regcache
->arch ();
196 const struct rs6000_aix_reg_vrreg_offset
*offsets
;
199 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
200 if (!(tdep
->ppc_vr0_regnum
>= 0 && tdep
->ppc_vrsave_regnum
>= 0))
203 offsets
= (const struct rs6000_aix_reg_vrreg_offset
*) regset
->regmap
;
208 for (i
= tdep
->ppc_vr0_regnum
, offset
= offsets
->vr0_offset
; i
<
209 tdep
->ppc_vr0_regnum
+ ppc_num_vrs
; i
++, offset
+= 16)
210 ppc_collect_reg (regcache
, i
, (gdb_byte
*) vrregs
, offset
, 16);
212 ppc_collect_reg (regcache
, (tdep
->ppc_vrsave_regnum
- 1),
213 (gdb_byte
*) vrregs
, offsets
->vscr_offset
, 4);
215 ppc_collect_reg (regcache
, tdep
->ppc_vrsave_regnum
,
216 (gdb_byte
*) vrregs
, offsets
->vrsave_offset
, 4);
221 offset
= rs6000_aix_get_vrreg_offset (tdep
, offsets
, regnum
);
222 if (regnum
!= tdep
->ppc_vrsave_regnum
223 && regnum
!= tdep
->ppc_vrsave_regnum
- 1)
224 ppc_collect_reg (regcache
, regnum
, (gdb_byte
*) vrregs
, offset
, 16);
226 ppc_collect_reg (regcache
, regnum
,
227 (gdb_byte
*) vrregs
, offset
, 4);
230 static const struct regset rs6000_aix_vrregset
= {
231 &rs6000_aix_vrreg_offset
,
232 rs6000_aix_supply_vrregset
,
233 rs6000_aix_collect_vrregset
236 static const struct regset rs6000_aix_vsxregset
= {
237 &rs6000_aix_vrreg_offset
,
238 rs6000_aix_supply_vsxregset
,
239 rs6000_aix_collect_vsxregset
242 static struct trad_frame_cache
*
243 aix_sighandle_frame_cache (const frame_info_ptr
&this_frame
,
247 CORE_ADDR base
, base_orig
, func
;
248 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
249 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
250 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
251 struct trad_frame_cache
*this_trad_cache
;
253 if ((*this_cache
) != NULL
)
254 return (struct trad_frame_cache
*) (*this_cache
);
256 this_trad_cache
= trad_frame_cache_zalloc (this_frame
);
257 (*this_cache
) = this_trad_cache
;
259 base
= get_frame_register_unsigned (this_frame
,
260 gdbarch_sp_regnum (gdbarch
));
263 if (tdep
->wordsize
== 4)
265 func
= read_memory_unsigned_integer (base_orig
+
266 SIG_FRAME_PC_OFFSET
+ 8,
267 tdep
->wordsize
, byte_order
);
268 safe_read_memory_integer (base_orig
+ SIG_FRAME_FP_OFFSET
+ 8,
269 tdep
->wordsize
, byte_order
, &backchain
);
270 base
= (CORE_ADDR
)backchain
;
274 func
= read_memory_unsigned_integer (base_orig
+
275 SIG_FRAME_LR_OFFSET64
,
276 tdep
->wordsize
, byte_order
);
277 safe_read_memory_integer (base_orig
+ SIG_FRAME_FP_OFFSET64
,
278 tdep
->wordsize
, byte_order
, &backchain
);
279 base
= (CORE_ADDR
)backchain
;
282 trad_frame_set_reg_value (this_trad_cache
, gdbarch_pc_regnum (gdbarch
), func
);
283 trad_frame_set_reg_value (this_trad_cache
, gdbarch_sp_regnum (gdbarch
), base
);
285 if (tdep
->wordsize
== 4)
286 trad_frame_set_reg_addr (this_trad_cache
, tdep
->ppc_lr_regnum
,
287 base_orig
+ 0x38 + 52 + 8);
289 trad_frame_set_reg_addr (this_trad_cache
, tdep
->ppc_lr_regnum
,
290 base_orig
+ 0x70 + 320);
292 trad_frame_set_id (this_trad_cache
, frame_id_build (base
, func
));
293 trad_frame_set_this_base (this_trad_cache
, base
);
295 return this_trad_cache
;
299 aix_sighandle_frame_this_id (const frame_info_ptr
&this_frame
,
300 void **this_prologue_cache
,
301 struct frame_id
*this_id
)
303 struct trad_frame_cache
*this_trad_cache
304 = aix_sighandle_frame_cache (this_frame
, this_prologue_cache
);
305 trad_frame_get_id (this_trad_cache
, this_id
);
308 static struct value
*
309 aix_sighandle_frame_prev_register (const frame_info_ptr
&this_frame
,
310 void **this_prologue_cache
, int regnum
)
312 struct trad_frame_cache
*this_trad_cache
313 = aix_sighandle_frame_cache (this_frame
, this_prologue_cache
);
314 return trad_frame_get_register (this_trad_cache
, this_frame
, regnum
);
318 aix_sighandle_frame_sniffer (const struct frame_unwind
*self
,
319 const frame_info_ptr
&this_frame
,
320 void **this_prologue_cache
)
322 CORE_ADDR pc
= get_frame_pc (this_frame
);
323 if (pc
&& pc
< AIX_TEXT_SEGMENT_BASE
)
329 /* AIX signal handler frame unwinder */
331 static const struct frame_unwind_legacy
aix_sighandle_frame_unwind (
332 "rs6000 aix sighandle",
335 default_frame_unwind_stop_reason
,
336 aix_sighandle_frame_this_id
,
337 aix_sighandle_frame_prev_register
,
339 aix_sighandle_frame_sniffer
342 /* Core file support. */
344 static struct ppc_reg_offsets rs6000_aix32_reg_offsets
=
346 /* General-purpose registers. */
358 /* Floating-point registers. */
360 56, /* fpscr_offset */
364 static struct ppc_reg_offsets rs6000_aix64_reg_offsets
=
366 /* General-purpose registers. */
374 280, /* ctr_offset */
375 292, /* xer_offset */
378 /* Floating-point registers. */
380 296, /* fpscr_offset */
385 /* Supply register REGNUM in the general-purpose register set REGSET
386 from the buffer specified by GREGS and LEN to register cache
387 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
390 rs6000_aix_supply_regset (const struct regset
*regset
,
391 struct regcache
*regcache
, int regnum
,
392 const void *gregs
, size_t len
)
394 ppc_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
395 ppc_supply_fpregset (regset
, regcache
, regnum
, gregs
, len
);
398 /* Collect register REGNUM in the general-purpose register set
399 REGSET, from register cache REGCACHE into the buffer specified by
400 GREGS and LEN. If REGNUM is -1, do this for all registers in
404 rs6000_aix_collect_regset (const struct regset
*regset
,
405 const struct regcache
*regcache
, int regnum
,
406 void *gregs
, size_t len
)
408 ppc_collect_gregset (regset
, regcache
, regnum
, gregs
, len
);
409 ppc_collect_fpregset (regset
, regcache
, regnum
, gregs
, len
);
412 /* AIX register set. */
414 static const struct regset rs6000_aix32_regset
=
416 &rs6000_aix32_reg_offsets
,
417 rs6000_aix_supply_regset
,
418 rs6000_aix_collect_regset
,
421 static const struct regset rs6000_aix64_regset
=
423 &rs6000_aix64_reg_offsets
,
424 rs6000_aix_supply_regset
,
425 rs6000_aix_collect_regset
,
428 /* Iterate over core file register note sections. */
431 rs6000_aix_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
432 iterate_over_regset_sections_cb
*cb
,
434 const struct regcache
*regcache
)
436 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
437 int have_altivec
= tdep
->ppc_vr0_regnum
!= -1;
438 int have_vsx
= tdep
->ppc_vsr0_upper_regnum
!= -1;
440 if (tdep
->wordsize
== 4)
441 cb (".reg", 592, 592, &rs6000_aix32_regset
, NULL
, cb_data
);
443 cb (".reg", 576, 576, &rs6000_aix64_regset
, NULL
, cb_data
);
446 cb (".aix-vmx", 560, 560, &rs6000_aix_vrregset
, "AIX altivec", cb_data
);
449 cb (".aix-vsx", 256, 256, &rs6000_aix_vsxregset
, "AIX vsx", cb_data
);
453 /* Read core file description for AIX. */
455 static const struct target_desc
*
456 ppc_aix_core_read_description (struct gdbarch
*gdbarch
,
457 struct target_ops
*target
,
460 asection
*altivec
= bfd_get_section_by_name (abfd
, ".aix-vmx");
461 asection
*vsx
= bfd_get_section_by_name (abfd
, ".aix-vsx");
462 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
463 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
469 if (tdep
->wordsize
== 8)
473 return tdesc_powerpc_vsx64
;
474 else if (vsx
&& !arch64
)
475 return tdesc_powerpc_vsx32
;
476 else if (altivec
&& arch64
)
477 return tdesc_powerpc_altivec64
;
478 else if (altivec
&& !arch64
)
479 return tdesc_powerpc_altivec32
;
484 /* Pass the arguments in either registers, or in the stack. In RS/6000,
485 the first eight words of the argument list (that might be less than
486 eight parameters if some parameters occupy more than one word) are
487 passed in r3..r10 registers. Float and double parameters are
488 passed in fpr's, in addition to that. Rest of the parameters if any
489 are passed in user stack. There might be cases in which half of the
490 parameter is copied into registers, the other half is pushed into
493 Stack must be aligned on 64-bit boundaries when synthesizing
496 If the function is returning a structure, then the return address is passed
497 in r3, then the first 7 words of the parameters can be passed in registers,
501 rs6000_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
502 struct regcache
*regcache
, CORE_ADDR bp_addr
,
503 int nargs
, struct value
**args
, CORE_ADDR sp
,
504 function_call_return_method return_method
,
505 CORE_ADDR struct_addr
)
507 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
508 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
511 int argno
; /* current argument number */
512 int argbytes
; /* current argument byte */
513 gdb_byte tmp_buffer
[50];
514 int f_argno
= 0; /* current floating point argno */
515 int wordsize
= tdep
->wordsize
;
516 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
518 struct value
*arg
= 0;
523 /* The calling convention this function implements assumes the
524 processor has floating-point registers. We shouldn't be using it
525 on PPC variants that lack them. */
526 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
528 /* The first eight words of the arguments are passed in registers.
529 Copy them appropriately. */
532 /* If the function is returning a `struct', then the first word
533 (which will be passed in r3) is used for struct return address.
534 In that case we should advance one word and start from r4
535 register to copy parameters. */
536 if (return_method
== return_method_struct
)
538 regcache_raw_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
543 /* effectively indirect call... gcc does...
545 return_val example( float, int);
548 float in fp0, int in r3
549 offset of stack on overflow 8/16
550 for varargs, must go by type.
552 float in r3&r4, int in r5
553 offset of stack on overflow different
555 return in r3 or f0. If no float, must study how gcc emulates floats;
556 pay attention to arg promotion.
557 User may have to cast\args to handle promotion correctly
558 since gdb won't know if prototype supplied or not. */
560 for (argno
= 0, argbytes
= 0; argno
< nargs
&& ii
< 8; ++ii
)
562 int reg_size
= register_size (gdbarch
, ii
+ 3);
565 type
= check_typedef (arg
->type ());
566 len
= type
->length ();
568 if (type
->code () == TYPE_CODE_FLT
)
570 /* Floating point arguments are passed in fpr's, as well as gpr's.
571 There are 13 fpr's reserved for passing parameters. At this point
572 there is no way we would run out of them.
574 Always store the floating point value using the register's
575 floating-point format. */
576 const int fp_regnum
= tdep
->ppc_fp0_regnum
+ 1 + f_argno
;
577 gdb_byte reg_val
[PPC_MAX_REGISTER_SIZE
];
578 struct type
*reg_type
= register_type (gdbarch
, fp_regnum
);
580 gdb_assert (len
<= 8);
582 target_float_convert (arg
->contents ().data (), type
, reg_val
,
584 regcache
->cooked_write (fp_regnum
, reg_val
);
591 /* Argument takes more than one register. */
592 while (argbytes
< len
)
594 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
595 memset (word
, 0, reg_size
);
597 ((char *) arg
->contents ().data ()) + argbytes
,
598 (len
- argbytes
) > reg_size
599 ? reg_size
: len
- argbytes
);
600 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3 + ii
, word
);
601 ++ii
, argbytes
+= reg_size
;
604 goto ran_out_of_registers_for_arguments
;
611 /* Argument can fit in one register. No problem. */
612 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
614 memset (word
, 0, reg_size
);
615 if (type
->code () == TYPE_CODE_INT
616 || type
->code () == TYPE_CODE_ENUM
617 || type
->code () == TYPE_CODE_BOOL
618 || type
->code () == TYPE_CODE_CHAR
)
619 /* Sign or zero extend the "int" into a "word". */
620 store_unsigned_integer (word
, reg_size
, byte_order
,
621 unpack_long (type
, arg
->contents ().data ()));
623 memcpy (word
, arg
->contents ().data (), len
);
624 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3 +ii
, word
);
629 ran_out_of_registers_for_arguments
:
631 regcache_cooked_read_unsigned (regcache
,
632 gdbarch_sp_regnum (gdbarch
),
635 /* Location for 8 parameters are always reserved. */
638 /* Another six words for back chain, TOC register, link register, etc. */
641 /* Stack pointer must be quadword aligned. */
644 /* If there are more arguments, allocate space for them in
645 the stack, then push them starting from the ninth one. */
647 if ((argno
< nargs
) || argbytes
)
653 space
+= ((len
- argbytes
+ wordsize
-1) & -wordsize
);
659 for (; jj
< nargs
; ++jj
)
661 struct value
*val
= args
[jj
];
662 space
+= ((val
->type ()->length () + wordsize
-1) & -wordsize
);
665 /* Add location required for the rest of the parameters. */
666 space
= (space
+ 15) & -16;
669 /* This is another instance we need to be concerned about
670 securing our stack space. If we write anything underneath %sp
671 (r1), we might conflict with the kernel who thinks he is free
672 to use this area. So, update %sp first before doing anything
675 regcache_raw_write_signed (regcache
,
676 gdbarch_sp_regnum (gdbarch
), sp
);
678 /* If the last argument copied into the registers didn't fit there
679 completely, push the rest of it into stack. */
683 write_memory (sp
+ 6 * wordsize
+ (ii
* wordsize
),
684 arg
->contents ().data () + argbytes
,
687 ii
+= ((len
- argbytes
+ wordsize
- 1) & -wordsize
) / wordsize
;
690 /* Push the rest of the arguments into stack. */
691 for (; argno
< nargs
; ++argno
)
695 type
= check_typedef (arg
->type ());
696 len
= type
->length ();
699 /* Float types should be passed in fpr's, as well as in the
701 if (type
->code () == TYPE_CODE_FLT
&& f_argno
< 13)
704 gdb_assert (len
<= 8);
706 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1 + f_argno
,
707 arg
->contents ().data ());
711 if (type
->code () == TYPE_CODE_INT
712 || type
->code () == TYPE_CODE_ENUM
713 || type
->code () == TYPE_CODE_BOOL
714 || type
->code () == TYPE_CODE_CHAR
)
716 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
717 memset (word
, 0, PPC_MAX_REGISTER_SIZE
);
718 store_unsigned_integer (word
, tdep
->wordsize
, byte_order
,
719 unpack_long (type
, arg
->contents ().data ()));
720 write_memory (sp
+ 6 * wordsize
+ (ii
* wordsize
), word
, PPC_MAX_REGISTER_SIZE
);
723 write_memory (sp
+ 6 * wordsize
+ (ii
* wordsize
), arg
->contents ().data (), len
);
724 ii
+= ((len
+ wordsize
-1) & -wordsize
) / wordsize
;
728 /* Set the stack pointer. According to the ABI, the SP is meant to
729 be set _before_ the corresponding stack space is used. On AIX,
730 this even applies when the target has been completely stopped!
731 Not doing this can lead to conflicts with the kernel which thinks
732 that it still has control over this not-yet-allocated stack
734 regcache_raw_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
736 /* Set back chain properly. */
737 store_unsigned_integer (tmp_buffer
, wordsize
, byte_order
, saved_sp
);
738 write_memory (sp
, tmp_buffer
, wordsize
);
740 /* Point the inferior function call's return address at the dummy's
742 regcache_raw_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
744 /* Set the TOC register value. */
745 regcache_raw_write_signed (regcache
, tdep
->ppc_toc_regnum
,
746 solib_aix_get_toc_value (func_addr
));
748 target_store_registers (regcache
, -1);
752 static enum return_value_convention
753 rs6000_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
754 struct type
*valtype
, struct regcache
*regcache
,
755 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
757 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
758 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
760 /* The calling convention this function implements assumes the
761 processor has floating-point registers. We shouldn't be using it
762 on PowerPC variants that lack them. */
763 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
765 /* AltiVec extension: Functions that declare a vector data type as a
766 return value place that return value in VR2. */
767 if (valtype
->code () == TYPE_CODE_ARRAY
&& valtype
->is_vector ()
768 && valtype
->length () == 16)
771 regcache
->cooked_read (tdep
->ppc_vr0_regnum
+ 2, readbuf
);
773 regcache
->cooked_write (tdep
->ppc_vr0_regnum
+ 2, writebuf
);
775 return RETURN_VALUE_REGISTER_CONVENTION
;
778 /* If the called subprogram returns an aggregate, there exists an
779 implicit first argument, whose value is the address of a caller-
780 allocated buffer into which the callee is assumed to store its
781 return value. All explicit parameters are appropriately
783 if (valtype
->code () == TYPE_CODE_STRUCT
784 || valtype
->code () == TYPE_CODE_UNION
785 || valtype
->code () == TYPE_CODE_ARRAY
)
786 return RETURN_VALUE_STRUCT_CONVENTION
;
788 /* Scalar floating-point values are returned in FPR1 for float or
789 double, and in FPR1:FPR2 for quadword precision. Fortran
790 complex*8 and complex*16 are returned in FPR1:FPR2, and
791 complex*32 is returned in FPR1:FPR4. */
792 if (valtype
->code () == TYPE_CODE_FLT
793 && (valtype
->length () == 4 || valtype
->length () == 8))
795 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
798 /* FIXME: kettenis/2007-01-01: Add support for quadword
799 precision and complex. */
803 regcache
->cooked_read (tdep
->ppc_fp0_regnum
+ 1, regval
);
804 target_float_convert (regval
, regtype
, readbuf
, valtype
);
808 target_float_convert (writebuf
, valtype
, regval
, regtype
);
809 regcache
->cooked_write (tdep
->ppc_fp0_regnum
+ 1, regval
);
812 return RETURN_VALUE_REGISTER_CONVENTION
;
815 /* Values of the types int, long, short, pointer, and char (length
816 is less than or equal to four bytes), as well as bit values of
817 lengths less than or equal to 32 bits, must be returned right
818 justified in GPR3 with signed values sign extended and unsigned
819 values zero extended, as necessary. */
820 if (valtype
->length () <= tdep
->wordsize
)
826 /* For reading we don't have to worry about sign extension. */
827 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
829 store_unsigned_integer (readbuf
, valtype
->length (), byte_order
,
834 /* For writing, use unpack_long since that should handle any
835 required sign extension. */
836 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
837 unpack_long (valtype
, writebuf
));
840 return RETURN_VALUE_REGISTER_CONVENTION
;
843 /* Eight-byte non-floating-point scalar values must be returned in
846 if (valtype
->length () == 8)
848 gdb_assert (valtype
->code () != TYPE_CODE_FLT
);
849 gdb_assert (tdep
->wordsize
== 4);
855 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 3, regval
);
856 regcache
->cooked_read (tdep
->ppc_gp0_regnum
+ 4, regval
+ 4);
857 memcpy (readbuf
, regval
, 8);
861 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 3, writebuf
);
862 regcache
->cooked_write (tdep
->ppc_gp0_regnum
+ 4, writebuf
+ 4);
865 return RETURN_VALUE_REGISTER_CONVENTION
;
868 return RETURN_VALUE_STRUCT_CONVENTION
;
871 /* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
873 Usually a function pointer's representation is simply the address
874 of the function. On the RS/6000 however, a function pointer is
875 represented by a pointer to an OPD entry. This OPD entry contains
876 three words, the first word is the address of the function, the
877 second word is the TOC pointer (r2), and the third word is the
878 static chain value. Throughout GDB it is currently assumed that a
879 function pointer contains the address of the function, which is not
880 easy to fix. In addition, the conversion of a function address to
881 a function pointer would require allocation of an OPD entry in the
882 inferior's memory space, with all its drawbacks. To be able to
883 call C++ virtual methods in the inferior (which are called via
884 function pointers), find_function_addr uses this function to get the
885 function address from a function pointer. */
887 /* Return real function address if ADDR (a function pointer) is in the data
888 space and is therefore a special function pointer. */
891 rs6000_convert_from_func_ptr_addr (struct gdbarch
*gdbarch
,
893 struct target_ops
*targ
)
895 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
896 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
897 struct obj_section
*s
;
899 s
= find_pc_section (addr
);
901 /* Normally, functions live inside a section that is executable.
902 So, if ADDR points to a non-executable section, then treat it
903 as a function descriptor and return the target address iff
904 the target address itself points to a section that is executable. */
905 if (s
&& (s
->the_bfd_section
->flags
& SEC_CODE
) == 0)
908 struct obj_section
*pc_section
;
912 pc
= read_memory_unsigned_integer (addr
, tdep
->wordsize
, byte_order
);
914 catch (const gdb_exception_error
&e
)
916 /* An error occurred during reading. Probably a memory error
917 due to the section not being loaded yet. This address
918 cannot be a function descriptor. */
922 pc_section
= find_pc_section (pc
);
924 if (pc_section
&& (pc_section
->the_bfd_section
->flags
& SEC_CODE
))
932 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
935 branch_dest (struct regcache
*regcache
, int opcode
, int instr
,
936 CORE_ADDR pc
, CORE_ADDR safety
)
938 struct gdbarch
*gdbarch
= regcache
->arch ();
939 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
940 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
946 absolute
= (int) ((instr
>> 1) & 1);
951 immediate
= ((instr
& ~3) << 6) >> 6; /* br unconditional */
955 dest
= pc
+ immediate
;
959 immediate
= ((instr
& ~3) << 16) >> 16; /* br conditional */
963 dest
= pc
+ immediate
;
967 ext_op
= (instr
>> 1) & 0x3ff;
969 if (ext_op
== 16) /* br conditional register */
971 dest
= regcache_raw_get_unsigned (regcache
, tdep
->ppc_lr_regnum
) & ~3;
973 /* If we are about to return from a signal handler, dest is
974 something like 0x3c90. The current frame is a signal handler
975 caller frame, upon completion of the sigreturn system call
976 execution will return to the saved PC in the frame. */
977 if (dest
< AIX_TEXT_SEGMENT_BASE
)
979 frame_info_ptr frame
= get_current_frame ();
981 dest
= read_memory_unsigned_integer
982 (get_frame_base (frame
) + SIG_FRAME_PC_OFFSET
,
983 tdep
->wordsize
, byte_order
);
987 else if (ext_op
== 528) /* br cond to count reg */
989 dest
= regcache_raw_get_unsigned (regcache
,
990 tdep
->ppc_ctr_regnum
) & ~3;
992 /* If we are about to execute a system call, dest is something
993 like 0x22fc or 0x3b00. Upon completion the system call
994 will return to the address in the link register. */
995 if (dest
< AIX_TEXT_SEGMENT_BASE
)
996 dest
= regcache_raw_get_unsigned (regcache
,
997 tdep
->ppc_lr_regnum
) & ~3;
1006 return (dest
< AIX_TEXT_SEGMENT_BASE
) ? safety
: dest
;
1009 /* AIX does not support PT_STEP. Simulate it. */
1011 static std::vector
<CORE_ADDR
>
1012 rs6000_software_single_step (struct regcache
*regcache
)
1014 struct gdbarch
*gdbarch
= regcache
->arch ();
1015 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1018 CORE_ADDR breaks
[2];
1021 loc
= regcache_read_pc (regcache
);
1023 insn
= read_memory_integer (loc
, 4, byte_order
);
1025 std::vector
<CORE_ADDR
> next_pcs
= ppc_deal_with_atomic_sequence (regcache
);
1026 if (!next_pcs
.empty ())
1029 /* Here 0xfc000000 is the opcode mask to detect a P10 prefix instruction. */
1030 if ((insn
& 0xfc000000) == 1 << 26)
1031 breaks
[0] = loc
+ 2 * PPC_INSN_SIZE
;
1033 breaks
[0] = loc
+ PPC_INSN_SIZE
;
1034 opcode
= insn
>> 26;
1035 breaks
[1] = branch_dest (regcache
, opcode
, insn
, loc
, breaks
[0]);
1037 /* Don't put two breakpoints on the same address. */
1038 if (breaks
[1] == breaks
[0])
1041 for (ii
= 0; ii
< 2; ++ii
)
1043 /* ignore invalid breakpoint. */
1044 if (breaks
[ii
] == -1)
1047 next_pcs
.push_back (breaks
[ii
]);
1050 errno
= 0; /* FIXME, don't ignore errors! */
1051 /* What errors? {read,write}_memory call error(). */
1055 /* Implement the "auto_wide_charset" gdbarch method for this platform. */
1058 rs6000_aix_auto_wide_charset (void)
1063 /* Implement an osabi sniffer for RS6000/AIX.
1065 This function assumes that ABFD's flavour is XCOFF. In other words,
1066 it should be registered as a sniffer for bfd_target_xcoff_flavour
1067 objfiles only. A failed assertion will be raised if this condition
1070 static enum gdb_osabi
1071 rs6000_aix_osabi_sniffer (bfd
*abfd
)
1073 gdb_assert (bfd_get_flavour (abfd
) == bfd_target_xcoff_flavour
);
1075 /* The only noticeable difference between Lynx178 XCOFF files and
1076 AIX XCOFF files comes from the fact that there are no shared
1077 libraries on Lynx178. On AIX, we are betting that an executable
1078 linked with no shared library will never exist. */
1079 if (xcoff_get_n_import_files (abfd
) <= 0)
1080 return GDB_OSABI_UNKNOWN
;
1082 return GDB_OSABI_AIX
;
1085 /* A structure encoding the offset and size of a field within
1094 /* A structure describing the layout of all the fields of interest
1095 in AIX's struct ld_info. Each field in this struct corresponds
1096 to the field of the same name in struct ld_info. */
1100 struct ldinfo_field ldinfo_next
;
1101 struct ldinfo_field ldinfo_fd
;
1102 struct ldinfo_field ldinfo_textorg
;
1103 struct ldinfo_field ldinfo_textsize
;
1104 struct ldinfo_field ldinfo_dataorg
;
1105 struct ldinfo_field ldinfo_datasize
;
1106 struct ldinfo_field ldinfo_filename
;
1109 /* The following data has been generated by compiling and running
1110 the following program on AIX 5.3. */
1115 #define __LDINFO_PTRACE32__
1116 #define __LDINFO_PTRACE64__
1117 #include <sys/ldr.h>
1119 #define pinfo(type,member) \
1121 struct type ldi = {0}; \
1123 printf (" {%d, %d},\t/* %s */\n", \
1124 offsetof (struct type, member), \
1125 sizeof (ldi.member), \
1133 printf ("static const struct ld_info_desc ld_info32_desc =\n{\n");
1134 pinfo (__ld_info32
, ldinfo_next
);
1135 pinfo (__ld_info32
, ldinfo_fd
);
1136 pinfo (__ld_info32
, ldinfo_textorg
);
1137 pinfo (__ld_info32
, ldinfo_textsize
);
1138 pinfo (__ld_info32
, ldinfo_dataorg
);
1139 pinfo (__ld_info32
, ldinfo_datasize
);
1140 pinfo (__ld_info32
, ldinfo_filename
);
1145 printf ("static const struct ld_info_desc ld_info64_desc =\n{\n");
1146 pinfo (__ld_info64
, ldinfo_next
);
1147 pinfo (__ld_info64
, ldinfo_fd
);
1148 pinfo (__ld_info64
, ldinfo_textorg
);
1149 pinfo (__ld_info64
, ldinfo_textsize
);
1150 pinfo (__ld_info64
, ldinfo_dataorg
);
1151 pinfo (__ld_info64
, ldinfo_datasize
);
1152 pinfo (__ld_info64
, ldinfo_filename
);
1159 /* Layout of the 32bit version of struct ld_info. */
1161 static const struct ld_info_desc ld_info32_desc
=
1163 {0, 4}, /* ldinfo_next */
1164 {4, 4}, /* ldinfo_fd */
1165 {8, 4}, /* ldinfo_textorg */
1166 {12, 4}, /* ldinfo_textsize */
1167 {16, 4}, /* ldinfo_dataorg */
1168 {20, 4}, /* ldinfo_datasize */
1169 {24, 2}, /* ldinfo_filename */
1172 /* Layout of the 64bit version of struct ld_info. */
1174 static const struct ld_info_desc ld_info64_desc
=
1176 {0, 4}, /* ldinfo_next */
1177 {8, 4}, /* ldinfo_fd */
1178 {16, 8}, /* ldinfo_textorg */
1179 {24, 8}, /* ldinfo_textsize */
1180 {32, 8}, /* ldinfo_dataorg */
1181 {40, 8}, /* ldinfo_datasize */
1182 {48, 2}, /* ldinfo_filename */
1185 /* A structured representation of one entry read from the ld_info
1186 binary data provided by the AIX loader. */
1200 /* Return a struct ld_info object corresponding to the entry at
1203 Note that the filename and member_name strings still point
1204 to the data in LDI_BUF. So LDI_BUF must not be deallocated
1205 while the struct ld_info object returned is in use. */
1207 static struct ld_info
1208 rs6000_aix_extract_ld_info (struct gdbarch
*gdbarch
,
1209 const gdb_byte
*ldi_buf
)
1211 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1212 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1213 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
1214 const struct ld_info_desc desc
1215 = tdep
->wordsize
== 8 ? ld_info64_desc
: ld_info32_desc
;
1216 struct ld_info info
;
1218 info
.next
= extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_next
.offset
,
1219 desc
.ldinfo_next
.size
,
1221 info
.fd
= extract_signed_integer (ldi_buf
+ desc
.ldinfo_fd
.offset
,
1222 desc
.ldinfo_fd
.size
,
1224 info
.textorg
= extract_typed_address (ldi_buf
+ desc
.ldinfo_textorg
.offset
,
1227 = extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_textsize
.offset
,
1228 desc
.ldinfo_textsize
.size
,
1230 info
.dataorg
= extract_typed_address (ldi_buf
+ desc
.ldinfo_dataorg
.offset
,
1233 = extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_datasize
.offset
,
1234 desc
.ldinfo_datasize
.size
,
1236 info
.filename
= (char *) ldi_buf
+ desc
.ldinfo_filename
.offset
;
1237 info
.member_name
= info
.filename
+ strlen (info
.filename
) + 1;
1242 /* Append to XML an XML string description of the shared library
1243 corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
1247 rs6000_aix_shared_library_to_xml (struct ld_info
*ldi
, std::string
&xml
)
1249 xml
+= "<library name=\"";
1250 xml_escape_text_append (xml
, ldi
->filename
);
1253 if (ldi
->member_name
[0] != '\0')
1255 xml
+= " member=\"";
1256 xml_escape_text_append (xml
, ldi
->member_name
);
1260 xml
+= " text_addr=\"";
1261 xml
+= core_addr_to_string (ldi
->textorg
);
1264 xml
+= " text_size=\"";
1265 xml
+= pulongest (ldi
->textsize
);
1268 xml
+= " data_addr=\"";
1269 xml
+= core_addr_to_string (ldi
->dataorg
);
1272 xml
+= " data_size=\"";
1273 xml
+= pulongest (ldi
->datasize
);
1276 xml
+= "></library>";
1279 /* Convert the ld_info binary data provided by the AIX loader into
1280 an XML representation following the TARGET_OBJECT_LIBRARIES_AIX
1283 LDI_BUF is a buffer containing the ld_info data.
1284 READBUF, OFFSET and LEN follow the same semantics as target_ops'
1285 to_xfer_partial target_ops method.
1287 If CLOSE_LDINFO_FD is nonzero, then this routine also closes
1288 the ldinfo_fd file descriptor. This is useful when the ldinfo
1289 data is obtained via ptrace, as ptrace opens a file descriptor
1290 for each and every entry; but we cannot use this descriptor
1291 as the consumer of the XML library list might live in a different
1295 rs6000_aix_ld_info_to_xml (struct gdbarch
*gdbarch
, const gdb_byte
*ldi_buf
,
1296 gdb_byte
*readbuf
, ULONGEST offset
, ULONGEST len
,
1297 int close_ldinfo_fd
)
1299 std::string xml
= "<library-list-aix version=\"1.0\">\n";
1303 struct ld_info ldi
= rs6000_aix_extract_ld_info (gdbarch
, ldi_buf
);
1305 rs6000_aix_shared_library_to_xml (&ldi
, xml
);
1306 if (close_ldinfo_fd
)
1311 ldi_buf
= ldi_buf
+ ldi
.next
;
1314 xml
+= "</library-list-aix>\n";
1316 ULONGEST len_avail
= xml
.length ();
1317 if (offset
>= len_avail
)
1321 if (len
> len_avail
- offset
)
1322 len
= len_avail
- offset
;
1323 memcpy (readbuf
, xml
.data () + offset
, len
);
1329 /* Implement the core_xfer_shared_libraries_aix gdbarch method. */
1332 rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch
*gdbarch
,
1337 struct bfd_section
*ldinfo_sec
;
1340 ldinfo_sec
= bfd_get_section_by_name (current_program_space
->core_bfd (),
1342 if (ldinfo_sec
== NULL
)
1343 error (_("cannot find .ldinfo section from core file: %s"),
1344 bfd_errmsg (bfd_get_error ()));
1345 ldinfo_size
= bfd_section_size (ldinfo_sec
);
1347 gdb::byte_vector
ldinfo_buf (ldinfo_size
);
1349 if (! bfd_get_section_contents (current_program_space
->core_bfd (),
1350 ldinfo_sec
, ldinfo_buf
.data (), 0,
1352 error (_("unable to read .ldinfo section from core file: %s"),
1353 bfd_errmsg (bfd_get_error ()));
1355 return rs6000_aix_ld_info_to_xml (gdbarch
, ldinfo_buf
.data (), readbuf
,
1360 rs6000_aix_init_osabi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1362 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1364 /* RS6000/AIX does not support PT_STEP. Has to be simulated. */
1365 set_gdbarch_software_single_step (gdbarch
, rs6000_software_single_step
);
1367 /* Displaced stepping is currently not supported in combination with
1368 software single-stepping. These override the values set by
1369 rs6000_gdbarch_init. */
1370 set_gdbarch_displaced_step_copy_insn (gdbarch
, NULL
);
1371 set_gdbarch_displaced_step_fixup (gdbarch
, NULL
);
1372 set_gdbarch_displaced_step_prepare (gdbarch
, NULL
);
1373 set_gdbarch_displaced_step_finish (gdbarch
, NULL
);
1375 set_gdbarch_push_dummy_call (gdbarch
, rs6000_push_dummy_call
);
1376 set_gdbarch_return_value (gdbarch
, rs6000_return_value
);
1377 set_gdbarch_long_double_bit (gdbarch
, 8 * TARGET_CHAR_BIT
);
1379 /* Handle RS/6000 function pointers (which are really function
1381 set_gdbarch_convert_from_func_ptr_addr
1382 (gdbarch
, rs6000_convert_from_func_ptr_addr
);
1384 /* Core file support. */
1385 set_gdbarch_iterate_over_regset_sections
1386 (gdbarch
, rs6000_aix_iterate_over_regset_sections
);
1387 set_gdbarch_core_xfer_shared_libraries_aix
1388 (gdbarch
, rs6000_aix_core_xfer_shared_libraries_aix
);
1389 set_gdbarch_core_read_description (gdbarch
, ppc_aix_core_read_description
);
1391 if (tdep
->wordsize
== 8)
1392 tdep
->lr_frame_offset
= 16;
1394 tdep
->lr_frame_offset
= 8;
1396 if (tdep
->wordsize
== 4)
1397 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
1398 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
1399 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
1401 set_gdbarch_frame_red_zone_size (gdbarch
, 224);
1403 /* In 64 bit mode the red zone should have 18 8 byte GPRS + 18 8 byte
1404 FPRS making it 288 bytes. This is 16 byte aligned as well. */
1405 set_gdbarch_frame_red_zone_size (gdbarch
, 288);
1407 if (tdep
->wordsize
== 8)
1408 set_gdbarch_wchar_bit (gdbarch
, 32);
1410 set_gdbarch_wchar_bit (gdbarch
, 16);
1411 set_gdbarch_wchar_signed (gdbarch
, 0);
1412 set_gdbarch_auto_wide_charset (gdbarch
, rs6000_aix_auto_wide_charset
);
1414 set_gdbarch_so_ops (gdbarch
, &solib_aix_so_ops
);
1415 frame_unwind_append_unwinder (gdbarch
, &aix_sighandle_frame_unwind
);
1418 void _initialize_rs6000_aix_tdep ();
1420 _initialize_rs6000_aix_tdep ()
1422 gdbarch_register_osabi_sniffer (bfd_arch_rs6000
,
1423 bfd_target_xcoff_flavour
,
1424 rs6000_aix_osabi_sniffer
);
1425 gdbarch_register_osabi_sniffer (bfd_arch_powerpc
,
1426 bfd_target_xcoff_flavour
,
1427 rs6000_aix_osabi_sniffer
);
1429 gdbarch_register_osabi (bfd_arch_rs6000
, 0, GDB_OSABI_AIX
,
1430 rs6000_aix_init_osabi
);
1431 gdbarch_register_osabi (bfd_arch_powerpc
, 0, GDB_OSABI_AIX
,
1432 rs6000_aix_init_osabi
);