quit_force: Replace TRY_CATCH wrapper macros
[deliverable/binutils-gdb.git] / gdb / rs6000-aix-tdep.c
CommitLineData
1f82754b
JB
1/* Native support code for PPC AIX, for GDB the GNU debugger.
2
32d0add0 3 Copyright (C) 2006-2015 Free Software Foundation, Inc.
1f82754b
JB
4
5 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
1f82754b
JB
12 (at your option) any later version.
13
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.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1f82754b
JB
21
22#include "defs.h"
23#include "osabi.h"
7a61a01c
UW
24#include "regcache.h"
25#include "regset.h"
4a7622d1
UW
26#include "gdbtypes.h"
27#include "gdbcore.h"
28#include "target.h"
29#include "value.h"
30#include "infcall.h"
31#include "objfiles.h"
32#include "breakpoint.h"
1f82754b 33#include "rs6000-tdep.h"
6f7f3f0d 34#include "ppc-tdep.h"
356a5233 35#include "rs6000-aix-tdep.h"
d5367fe1 36#include "xcoffread.h"
4d1eb6b4
JB
37#include "solib.h"
38#include "solib-aix.h"
356a5233 39#include "xml-utils.h"
4a7622d1
UW
40
41/* If the kernel has to deliver a signal, it pushes a sigcontext
42 structure on the stack and then calls the signal handler, passing
0df8b418 43 the address of the sigcontext in an argument register. Usually
4a7622d1
UW
44 the signal handler doesn't save this register, so we have to
45 access the sigcontext structure via an offset from the signal handler
46 frame.
47 The following constants were determined by experimentation on AIX 3.2. */
48#define SIG_FRAME_PC_OFFSET 96
49#define SIG_FRAME_LR_OFFSET 108
50#define SIG_FRAME_FP_OFFSET 284
51
7a61a01c
UW
52
53/* Core file support. */
54
55static struct ppc_reg_offsets rs6000_aix32_reg_offsets =
56{
57 /* General-purpose registers. */
58 208, /* r0_offset */
f2db237a
AM
59 4, /* gpr_size */
60 4, /* xr_size */
7a61a01c
UW
61 24, /* pc_offset */
62 28, /* ps_offset */
63 32, /* cr_offset */
64 36, /* lr_offset */
65 40, /* ctr_offset */
66 44, /* xer_offset */
67 48, /* mq_offset */
68
69 /* Floating-point registers. */
70 336, /* f0_offset */
71 56, /* fpscr_offset */
f2db237a 72 4, /* fpscr_size */
7a61a01c
UW
73
74 /* AltiVec registers. */
75 -1, /* vr0_offset */
76 -1, /* vscr_offset */
77 -1 /* vrsave_offset */
78};
79
80static struct ppc_reg_offsets rs6000_aix64_reg_offsets =
81{
82 /* General-purpose registers. */
83 0, /* r0_offset */
f2db237a
AM
84 8, /* gpr_size */
85 4, /* xr_size */
7a61a01c
UW
86 264, /* pc_offset */
87 256, /* ps_offset */
88 288, /* cr_offset */
89 272, /* lr_offset */
90 280, /* ctr_offset */
91 292, /* xer_offset */
92 -1, /* mq_offset */
93
94 /* Floating-point registers. */
95 312, /* f0_offset */
96 296, /* fpscr_offset */
f2db237a 97 4, /* fpscr_size */
7a61a01c
UW
98
99 /* AltiVec registers. */
100 -1, /* vr0_offset */
101 -1, /* vscr_offset */
102 -1 /* vrsave_offset */
103};
104
105
106/* Supply register REGNUM in the general-purpose register set REGSET
107 from the buffer specified by GREGS and LEN to register cache
108 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
109
110static void
111rs6000_aix_supply_regset (const struct regset *regset,
112 struct regcache *regcache, int regnum,
113 const void *gregs, size_t len)
114{
115 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
f2db237a 116 ppc_supply_fpregset (regset, regcache, regnum, gregs, len);
7a61a01c
UW
117}
118
119/* Collect register REGNUM in the general-purpose register set
0df8b418 120 REGSET, from register cache REGCACHE into the buffer specified by
7a61a01c
UW
121 GREGS and LEN. If REGNUM is -1, do this for all registers in
122 REGSET. */
123
124static void
125rs6000_aix_collect_regset (const struct regset *regset,
126 const struct regcache *regcache, int regnum,
127 void *gregs, size_t len)
128{
129 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
f2db237a 130 ppc_collect_fpregset (regset, regcache, regnum, gregs, len);
7a61a01c
UW
131}
132
133/* AIX register set. */
134
3ca7dae4 135static const struct regset rs6000_aix32_regset =
7a61a01c
UW
136{
137 &rs6000_aix32_reg_offsets,
138 rs6000_aix_supply_regset,
139 rs6000_aix_collect_regset,
140};
141
3ca7dae4 142static const struct regset rs6000_aix64_regset =
7a61a01c
UW
143{
144 &rs6000_aix64_reg_offsets,
145 rs6000_aix_supply_regset,
146 rs6000_aix_collect_regset,
147};
148
23ea9aeb 149/* Iterate over core file register note sections. */
7a61a01c 150
23ea9aeb
AA
151static void
152rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
153 iterate_over_regset_sections_cb *cb,
154 void *cb_data,
155 const struct regcache *regcache)
7a61a01c
UW
156{
157 if (gdbarch_tdep (gdbarch)->wordsize == 4)
23ea9aeb 158 cb (".reg", 592, &rs6000_aix32_regset, NULL, cb_data);
7a61a01c 159 else
23ea9aeb 160 cb (".reg", 576, &rs6000_aix64_regset, NULL, cb_data);
7a61a01c
UW
161}
162
163
0df8b418 164/* Pass the arguments in either registers, or in the stack. In RS/6000,
4a7622d1
UW
165 the first eight words of the argument list (that might be less than
166 eight parameters if some parameters occupy more than one word) are
0df8b418 167 passed in r3..r10 registers. Float and double parameters are
4a7622d1
UW
168 passed in fpr's, in addition to that. Rest of the parameters if any
169 are passed in user stack. There might be cases in which half of the
170 parameter is copied into registers, the other half is pushed into
171 stack.
172
173 Stack must be aligned on 64-bit boundaries when synthesizing
174 function calls.
175
176 If the function is returning a structure, then the return address is passed
177 in r3, then the first 7 words of the parameters can be passed in registers,
178 starting from r4. */
179
180static CORE_ADDR
181rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
182 struct regcache *regcache, CORE_ADDR bp_addr,
183 int nargs, struct value **args, CORE_ADDR sp,
184 int struct_return, CORE_ADDR struct_addr)
185{
186 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
e17a4113 187 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4a7622d1
UW
188 int ii;
189 int len = 0;
190 int argno; /* current argument number */
191 int argbytes; /* current argument byte */
192 gdb_byte tmp_buffer[50];
193 int f_argno = 0; /* current floating point argno */
194 int wordsize = gdbarch_tdep (gdbarch)->wordsize;
195 CORE_ADDR func_addr = find_function_addr (function, NULL);
196
197 struct value *arg = 0;
198 struct type *type;
199
200 ULONGEST saved_sp;
201
202 /* The calling convention this function implements assumes the
203 processor has floating-point registers. We shouldn't be using it
204 on PPC variants that lack them. */
205 gdb_assert (ppc_floating_point_unit_p (gdbarch));
206
207 /* The first eight words of ther arguments are passed in registers.
208 Copy them appropriately. */
209 ii = 0;
210
211 /* If the function is returning a `struct', then the first word
212 (which will be passed in r3) is used for struct return address.
213 In that case we should advance one word and start from r4
214 register to copy parameters. */
215 if (struct_return)
216 {
217 regcache_raw_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
218 struct_addr);
219 ii++;
220 }
221
0df8b418 222/* effectively indirect call... gcc does...
4a7622d1
UW
223
224 return_val example( float, int);
225
226 eabi:
227 float in fp0, int in r3
228 offset of stack on overflow 8/16
229 for varargs, must go by type.
230 power open:
231 float in r3&r4, int in r5
232 offset of stack on overflow different
233 both:
234 return in r3 or f0. If no float, must study how gcc emulates floats;
0df8b418 235 pay attention to arg promotion.
4a7622d1 236 User may have to cast\args to handle promotion correctly
0df8b418 237 since gdb won't know if prototype supplied or not. */
4a7622d1
UW
238
239 for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii)
240 {
241 int reg_size = register_size (gdbarch, ii + 3);
242
243 arg = args[argno];
244 type = check_typedef (value_type (arg));
245 len = TYPE_LENGTH (type);
246
247 if (TYPE_CODE (type) == TYPE_CODE_FLT)
248 {
4a7622d1 249 /* Floating point arguments are passed in fpr's, as well as gpr's.
0df8b418 250 There are 13 fpr's reserved for passing parameters. At this point
36d1c68c
JB
251 there is no way we would run out of them.
252
253 Always store the floating point value using the register's
254 floating-point format. */
255 const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno;
256 gdb_byte reg_val[MAX_REGISTER_SIZE];
257 struct type *reg_type = register_type (gdbarch, fp_regnum);
4a7622d1
UW
258
259 gdb_assert (len <= 8);
260
36d1c68c
JB
261 convert_typed_floating (value_contents (arg), type,
262 reg_val, reg_type);
263 regcache_cooked_write (regcache, fp_regnum, reg_val);
4a7622d1
UW
264 ++f_argno;
265 }
266
267 if (len > reg_size)
268 {
269
270 /* Argument takes more than one register. */
271 while (argbytes < len)
272 {
273 gdb_byte word[MAX_REGISTER_SIZE];
274 memset (word, 0, reg_size);
275 memcpy (word,
276 ((char *) value_contents (arg)) + argbytes,
277 (len - argbytes) > reg_size
278 ? reg_size : len - argbytes);
279 regcache_cooked_write (regcache,
280 tdep->ppc_gp0_regnum + 3 + ii,
281 word);
282 ++ii, argbytes += reg_size;
283
284 if (ii >= 8)
285 goto ran_out_of_registers_for_arguments;
286 }
287 argbytes = 0;
288 --ii;
289 }
290 else
291 {
292 /* Argument can fit in one register. No problem. */
293 int adj = gdbarch_byte_order (gdbarch)
294 == BFD_ENDIAN_BIG ? reg_size - len : 0;
295 gdb_byte word[MAX_REGISTER_SIZE];
296
297 memset (word, 0, reg_size);
298 memcpy (word, value_contents (arg), len);
299 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3 +ii, word);
300 }
301 ++argno;
302 }
303
304ran_out_of_registers_for_arguments:
305
306 regcache_cooked_read_unsigned (regcache,
307 gdbarch_sp_regnum (gdbarch),
308 &saved_sp);
309
310 /* Location for 8 parameters are always reserved. */
311 sp -= wordsize * 8;
312
313 /* Another six words for back chain, TOC register, link register, etc. */
314 sp -= wordsize * 6;
315
316 /* Stack pointer must be quadword aligned. */
317 sp &= -16;
318
319 /* If there are more arguments, allocate space for them in
320 the stack, then push them starting from the ninth one. */
321
322 if ((argno < nargs) || argbytes)
323 {
324 int space = 0, jj;
325
326 if (argbytes)
327 {
328 space += ((len - argbytes + 3) & -4);
329 jj = argno + 1;
330 }
331 else
332 jj = argno;
333
334 for (; jj < nargs; ++jj)
335 {
336 struct value *val = args[jj];
337 space += ((TYPE_LENGTH (value_type (val))) + 3) & -4;
338 }
339
340 /* Add location required for the rest of the parameters. */
341 space = (space + 15) & -16;
342 sp -= space;
343
344 /* This is another instance we need to be concerned about
0df8b418 345 securing our stack space. If we write anything underneath %sp
4a7622d1
UW
346 (r1), we might conflict with the kernel who thinks he is free
347 to use this area. So, update %sp first before doing anything
348 else. */
349
350 regcache_raw_write_signed (regcache,
351 gdbarch_sp_regnum (gdbarch), sp);
352
353 /* If the last argument copied into the registers didn't fit there
354 completely, push the rest of it into stack. */
355
356 if (argbytes)
357 {
358 write_memory (sp + 24 + (ii * 4),
359 value_contents (arg) + argbytes,
360 len - argbytes);
361 ++argno;
362 ii += ((len - argbytes + 3) & -4) / 4;
363 }
364
365 /* Push the rest of the arguments into stack. */
366 for (; argno < nargs; ++argno)
367 {
368
369 arg = args[argno];
370 type = check_typedef (value_type (arg));
371 len = TYPE_LENGTH (type);
372
373
374 /* Float types should be passed in fpr's, as well as in the
375 stack. */
376 if (TYPE_CODE (type) == TYPE_CODE_FLT && f_argno < 13)
377 {
378
379 gdb_assert (len <= 8);
380
381 regcache_cooked_write (regcache,
382 tdep->ppc_fp0_regnum + 1 + f_argno,
383 value_contents (arg));
384 ++f_argno;
385 }
386
387 write_memory (sp + 24 + (ii * 4), value_contents (arg), len);
388 ii += ((len + 3) & -4) / 4;
389 }
390 }
391
392 /* Set the stack pointer. According to the ABI, the SP is meant to
393 be set _before_ the corresponding stack space is used. On AIX,
394 this even applies when the target has been completely stopped!
395 Not doing this can lead to conflicts with the kernel which thinks
396 that it still has control over this not-yet-allocated stack
397 region. */
398 regcache_raw_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp);
399
400 /* Set back chain properly. */
e17a4113 401 store_unsigned_integer (tmp_buffer, wordsize, byte_order, saved_sp);
4a7622d1
UW
402 write_memory (sp, tmp_buffer, wordsize);
403
404 /* Point the inferior function call's return address at the dummy's
405 breakpoint. */
406 regcache_raw_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
407
4d1eb6b4
JB
408 /* Set the TOC register value. */
409 regcache_raw_write_signed (regcache, tdep->ppc_toc_regnum,
410 solib_aix_get_toc_value (func_addr));
4a7622d1
UW
411
412 target_store_registers (regcache, -1);
413 return sp;
414}
415
416static enum return_value_convention
6a3a010b 417rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
4a7622d1
UW
418 struct type *valtype, struct regcache *regcache,
419 gdb_byte *readbuf, const gdb_byte *writebuf)
420{
421 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
e17a4113 422 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4a7622d1
UW
423
424 /* The calling convention this function implements assumes the
425 processor has floating-point registers. We shouldn't be using it
426 on PowerPC variants that lack them. */
427 gdb_assert (ppc_floating_point_unit_p (gdbarch));
428
429 /* AltiVec extension: Functions that declare a vector data type as a
430 return value place that return value in VR2. */
431 if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype)
432 && TYPE_LENGTH (valtype) == 16)
433 {
434 if (readbuf)
435 regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
436 if (writebuf)
437 regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf);
438
439 return RETURN_VALUE_REGISTER_CONVENTION;
440 }
441
442 /* If the called subprogram returns an aggregate, there exists an
443 implicit first argument, whose value is the address of a caller-
444 allocated buffer into which the callee is assumed to store its
0df8b418 445 return value. All explicit parameters are appropriately
4a7622d1
UW
446 relabeled. */
447 if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT
448 || TYPE_CODE (valtype) == TYPE_CODE_UNION
449 || TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
450 return RETURN_VALUE_STRUCT_CONVENTION;
451
452 /* Scalar floating-point values are returned in FPR1 for float or
453 double, and in FPR1:FPR2 for quadword precision. Fortran
454 complex*8 and complex*16 are returned in FPR1:FPR2, and
455 complex*32 is returned in FPR1:FPR4. */
456 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
457 && (TYPE_LENGTH (valtype) == 4 || TYPE_LENGTH (valtype) == 8))
458 {
459 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
460 gdb_byte regval[8];
461
462 /* FIXME: kettenis/2007-01-01: Add support for quadword
463 precision and complex. */
464
465 if (readbuf)
466 {
467 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
468 convert_typed_floating (regval, regtype, readbuf, valtype);
469 }
470 if (writebuf)
471 {
472 convert_typed_floating (writebuf, valtype, regval, regtype);
473 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
474 }
475
476 return RETURN_VALUE_REGISTER_CONVENTION;
477 }
478
479 /* Values of the types int, long, short, pointer, and char (length
480 is less than or equal to four bytes), as well as bit values of
481 lengths less than or equal to 32 bits, must be returned right
482 justified in GPR3 with signed values sign extended and unsigned
483 values zero extended, as necessary. */
484 if (TYPE_LENGTH (valtype) <= tdep->wordsize)
485 {
486 if (readbuf)
487 {
488 ULONGEST regval;
489
490 /* For reading we don't have to worry about sign extension. */
491 regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
492 &regval);
e17a4113
UW
493 store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), byte_order,
494 regval);
4a7622d1
UW
495 }
496 if (writebuf)
497 {
498 /* For writing, use unpack_long since that should handle any
499 required sign extension. */
500 regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
501 unpack_long (valtype, writebuf));
502 }
503
504 return RETURN_VALUE_REGISTER_CONVENTION;
505 }
506
507 /* Eight-byte non-floating-point scalar values must be returned in
508 GPR3:GPR4. */
509
510 if (TYPE_LENGTH (valtype) == 8)
511 {
512 gdb_assert (TYPE_CODE (valtype) != TYPE_CODE_FLT);
513 gdb_assert (tdep->wordsize == 4);
514
515 if (readbuf)
516 {
517 gdb_byte regval[8];
518
519 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, regval);
520 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
521 regval + 4);
522 memcpy (readbuf, regval, 8);
523 }
524 if (writebuf)
525 {
526 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf);
527 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
528 writebuf + 4);
529 }
530
531 return RETURN_VALUE_REGISTER_CONVENTION;
532 }
533
534 return RETURN_VALUE_STRUCT_CONVENTION;
535}
536
537/* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
538
539 Usually a function pointer's representation is simply the address
0df8b418
MS
540 of the function. On the RS/6000 however, a function pointer is
541 represented by a pointer to an OPD entry. This OPD entry contains
4a7622d1
UW
542 three words, the first word is the address of the function, the
543 second word is the TOC pointer (r2), and the third word is the
544 static chain value. Throughout GDB it is currently assumed that a
545 function pointer contains the address of the function, which is not
546 easy to fix. In addition, the conversion of a function address to
547 a function pointer would require allocation of an OPD entry in the
548 inferior's memory space, with all its drawbacks. To be able to
549 call C++ virtual methods in the inferior (which are called via
550 function pointers), find_function_addr uses this function to get the
551 function address from a function pointer. */
552
553/* Return real function address if ADDR (a function pointer) is in the data
554 space and is therefore a special function pointer. */
555
556static CORE_ADDR
557rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
558 CORE_ADDR addr,
559 struct target_ops *targ)
560{
e17a4113
UW
561 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
562 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4a7622d1
UW
563 struct obj_section *s;
564
565 s = find_pc_section (addr);
4a7622d1 566
40adab56
JB
567 /* Normally, functions live inside a section that is executable.
568 So, if ADDR points to a non-executable section, then treat it
569 as a function descriptor and return the target address iff
570 the target address itself points to a section that is executable. */
571 if (s && (s->the_bfd_section->flags & SEC_CODE) == 0)
572 {
57174f31 573 CORE_ADDR pc = 0;
2971b56b 574 struct obj_section *pc_section;
bfd189b1 575 volatile struct gdb_exception e;
2971b56b
JB
576
577 TRY_CATCH (e, RETURN_MASK_ERROR)
578 {
579 pc = read_memory_unsigned_integer (addr, tdep->wordsize, byte_order);
580 }
581 if (e.reason < 0)
582 {
583 /* An error occured during reading. Probably a memory error
584 due to the section not being loaded yet. This address
585 cannot be a function descriptor. */
586 return addr;
587 }
588 pc_section = find_pc_section (pc);
40adab56
JB
589
590 if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE))
591 return pc;
592 }
593
594 return addr;
4a7622d1
UW
595}
596
597
598/* Calculate the destination of a branch/jump. Return -1 if not a branch. */
599
600static CORE_ADDR
601branch_dest (struct frame_info *frame, int opcode, int instr,
602 CORE_ADDR pc, CORE_ADDR safety)
603{
e17a4113
UW
604 struct gdbarch *gdbarch = get_frame_arch (frame);
605 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
606 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4a7622d1
UW
607 CORE_ADDR dest;
608 int immediate;
609 int absolute;
610 int ext_op;
611
612 absolute = (int) ((instr >> 1) & 1);
613
614 switch (opcode)
615 {
616 case 18:
617 immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */
618 if (absolute)
619 dest = immediate;
620 else
621 dest = pc + immediate;
622 break;
623
624 case 16:
625 immediate = ((instr & ~3) << 16) >> 16; /* br conditional */
626 if (absolute)
627 dest = immediate;
628 else
629 dest = pc + immediate;
630 break;
631
632 case 19:
633 ext_op = (instr >> 1) & 0x3ff;
634
635 if (ext_op == 16) /* br conditional register */
636 {
637 dest = get_frame_register_unsigned (frame, tdep->ppc_lr_regnum) & ~3;
638
639 /* If we are about to return from a signal handler, dest is
640 something like 0x3c90. The current frame is a signal handler
641 caller frame, upon completion of the sigreturn system call
642 execution will return to the saved PC in the frame. */
643 if (dest < AIX_TEXT_SEGMENT_BASE)
644 dest = read_memory_unsigned_integer
645 (get_frame_base (frame) + SIG_FRAME_PC_OFFSET,
e17a4113 646 tdep->wordsize, byte_order);
4a7622d1
UW
647 }
648
649 else if (ext_op == 528) /* br cond to count reg */
650 {
0df8b418
MS
651 dest = get_frame_register_unsigned (frame,
652 tdep->ppc_ctr_regnum) & ~3;
4a7622d1
UW
653
654 /* If we are about to execute a system call, dest is something
655 like 0x22fc or 0x3b00. Upon completion the system call
656 will return to the address in the link register. */
657 if (dest < AIX_TEXT_SEGMENT_BASE)
0df8b418
MS
658 dest = get_frame_register_unsigned (frame,
659 tdep->ppc_lr_regnum) & ~3;
4a7622d1
UW
660 }
661 else
662 return -1;
663 break;
664
665 default:
666 return -1;
667 }
668 return (dest < AIX_TEXT_SEGMENT_BASE) ? safety : dest;
669}
670
671/* AIX does not support PT_STEP. Simulate it. */
672
673static int
674rs6000_software_single_step (struct frame_info *frame)
675{
a6d9a66e 676 struct gdbarch *gdbarch = get_frame_arch (frame);
6c95b8df 677 struct address_space *aspace = get_frame_address_space (frame);
e17a4113 678 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4a7622d1
UW
679 int ii, insn;
680 CORE_ADDR loc;
681 CORE_ADDR breaks[2];
682 int opcode;
683
684 loc = get_frame_pc (frame);
685
e17a4113 686 insn = read_memory_integer (loc, 4, byte_order);
4a7622d1
UW
687
688 if (ppc_deal_with_atomic_sequence (frame))
689 return 1;
690
691 breaks[0] = loc + PPC_INSN_SIZE;
692 opcode = insn >> 26;
693 breaks[1] = branch_dest (frame, opcode, insn, loc, breaks[0]);
694
0df8b418 695 /* Don't put two breakpoints on the same address. */
4a7622d1
UW
696 if (breaks[1] == breaks[0])
697 breaks[1] = -1;
698
699 for (ii = 0; ii < 2; ++ii)
700 {
0df8b418 701 /* ignore invalid breakpoint. */
4a7622d1
UW
702 if (breaks[ii] == -1)
703 continue;
6c95b8df 704 insert_single_step_breakpoint (gdbarch, aspace, breaks[ii]);
4a7622d1
UW
705 }
706
0df8b418 707 errno = 0; /* FIXME, don't ignore errors! */
4a7622d1
UW
708 /* What errors? {read,write}_memory call error(). */
709 return 1;
710}
711
38a69d0a
JB
712/* Implement the "auto_wide_charset" gdbarch method for this platform. */
713
714static const char *
715rs6000_aix_auto_wide_charset (void)
716{
717 return "UTF-16";
718}
719
beb4b03c
JB
720/* Implement an osabi sniffer for RS6000/AIX.
721
722 This function assumes that ABFD's flavour is XCOFF. In other words,
723 it should be registered as a sniffer for bfd_target_xcoff_flavour
724 objfiles only. A failed assertion will be raised if this condition
725 is not met. */
726
1f82754b
JB
727static enum gdb_osabi
728rs6000_aix_osabi_sniffer (bfd *abfd)
729{
beb4b03c 730 gdb_assert (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
1f82754b 731
d5367fe1
JB
732 /* The only noticeable difference between Lynx178 XCOFF files and
733 AIX XCOFF files comes from the fact that there are no shared
734 libraries on Lynx178. On AIX, we are betting that an executable
735 linked with no shared library will never exist. */
736 if (xcoff_get_n_import_files (abfd) <= 0)
737 return GDB_OSABI_UNKNOWN;
738
beb4b03c 739 return GDB_OSABI_AIX;
1f82754b
JB
740}
741
356a5233
JB
742/* A structure encoding the offset and size of a field within
743 a struct. */
744
745struct field_info
746{
747 int offset;
748 int size;
749};
750
751/* A structure describing the layout of all the fields of interest
752 in AIX's struct ld_info. Each field in this struct corresponds
753 to the field of the same name in struct ld_info. */
754
755struct ld_info_desc
756{
757 struct field_info ldinfo_next;
758 struct field_info ldinfo_fd;
759 struct field_info ldinfo_textorg;
760 struct field_info ldinfo_textsize;
761 struct field_info ldinfo_dataorg;
762 struct field_info ldinfo_datasize;
763 struct field_info ldinfo_filename;
764};
765
766/* The following data has been generated by compiling and running
767 the following program on AIX 5.3. */
768
769#if 0
1c432e72
JB
770#include <stddef.h>
771#include <stdio.h>
772#define __LDINFO_PTRACE32__
773#define __LDINFO_PTRACE64__
774#include <sys/ldr.h>
775
776#define pinfo(type,member) \
777 { \
778 struct type ldi = {0}; \
779 \
780 printf (" {%d, %d},\t/* %s */\n", \
781 offsetof (struct type, member), \
782 sizeof (ldi.member), \
783 #member); \
784 } \
785 while (0)
786
787int
788main (void)
789{
790 printf ("static const struct ld_info_desc ld_info32_desc =\n{\n");
791 pinfo (__ld_info32, ldinfo_next);
792 pinfo (__ld_info32, ldinfo_fd);
793 pinfo (__ld_info32, ldinfo_textorg);
794 pinfo (__ld_info32, ldinfo_textsize);
795 pinfo (__ld_info32, ldinfo_dataorg);
796 pinfo (__ld_info32, ldinfo_datasize);
797 pinfo (__ld_info32, ldinfo_filename);
798 printf ("};\n");
799
800 printf ("\n");
801
802 printf ("static const struct ld_info_desc ld_info64_desc =\n{\n");
803 pinfo (__ld_info64, ldinfo_next);
804 pinfo (__ld_info64, ldinfo_fd);
805 pinfo (__ld_info64, ldinfo_textorg);
806 pinfo (__ld_info64, ldinfo_textsize);
807 pinfo (__ld_info64, ldinfo_dataorg);
808 pinfo (__ld_info64, ldinfo_datasize);
809 pinfo (__ld_info64, ldinfo_filename);
810 printf ("};\n");
811
812 return 0;
813}
356a5233
JB
814#endif /* 0 */
815
816/* Layout of the 32bit version of struct ld_info. */
817
818static const struct ld_info_desc ld_info32_desc =
819{
820 {0, 4}, /* ldinfo_next */
821 {4, 4}, /* ldinfo_fd */
822 {8, 4}, /* ldinfo_textorg */
823 {12, 4}, /* ldinfo_textsize */
824 {16, 4}, /* ldinfo_dataorg */
825 {20, 4}, /* ldinfo_datasize */
826 {24, 2}, /* ldinfo_filename */
827};
828
829/* Layout of the 64bit version of struct ld_info. */
830
831static const struct ld_info_desc ld_info64_desc =
832{
833 {0, 4}, /* ldinfo_next */
834 {8, 4}, /* ldinfo_fd */
835 {16, 8}, /* ldinfo_textorg */
836 {24, 8}, /* ldinfo_textsize */
837 {32, 8}, /* ldinfo_dataorg */
838 {40, 8}, /* ldinfo_datasize */
839 {48, 2}, /* ldinfo_filename */
840};
841
842/* A structured representation of one entry read from the ld_info
843 binary data provided by the AIX loader. */
844
845struct ld_info
846{
847 ULONGEST next;
848 int fd;
849 CORE_ADDR textorg;
850 ULONGEST textsize;
851 CORE_ADDR dataorg;
852 ULONGEST datasize;
853 char *filename;
854 char *member_name;
855};
856
857/* Return a struct ld_info object corresponding to the entry at
858 LDI_BUF.
859
860 Note that the filename and member_name strings still point
861 to the data in LDI_BUF. So LDI_BUF must not be deallocated
862 while the struct ld_info object returned is in use. */
863
864static struct ld_info
865rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
866 const gdb_byte *ldi_buf)
867{
868 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
869 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
870 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
871 const struct ld_info_desc desc
872 = tdep->wordsize == 8 ? ld_info64_desc : ld_info32_desc;
873 struct ld_info info;
874
875 info.next = extract_unsigned_integer (ldi_buf + desc.ldinfo_next.offset,
876 desc.ldinfo_next.size,
877 byte_order);
878 info.fd = extract_signed_integer (ldi_buf + desc.ldinfo_fd.offset,
879 desc.ldinfo_fd.size,
880 byte_order);
881 info.textorg = extract_typed_address (ldi_buf + desc.ldinfo_textorg.offset,
882 ptr_type);
883 info.textsize
884 = extract_unsigned_integer (ldi_buf + desc.ldinfo_textsize.offset,
885 desc.ldinfo_textsize.size,
886 byte_order);
887 info.dataorg = extract_typed_address (ldi_buf + desc.ldinfo_dataorg.offset,
888 ptr_type);
889 info.datasize
890 = extract_unsigned_integer (ldi_buf + desc.ldinfo_datasize.offset,
891 desc.ldinfo_datasize.size,
892 byte_order);
893 info.filename = (char *) ldi_buf + desc.ldinfo_filename.offset;
894 info.member_name = info.filename + strlen (info.filename) + 1;
895
896 return info;
897}
898
899/* Append to OBJSTACK an XML string description of the shared library
900 corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
901 format. */
902
903static void
904rs6000_aix_shared_library_to_xml (struct ld_info *ldi,
905 struct obstack *obstack)
906{
907 char *p;
908
909 obstack_grow_str (obstack, "<library name=\"");
910 p = xml_escape_text (ldi->filename);
911 obstack_grow_str (obstack, p);
912 xfree (p);
913 obstack_grow_str (obstack, "\"");
914
915 if (ldi->member_name[0] != '\0')
916 {
917 obstack_grow_str (obstack, " member=\"");
918 p = xml_escape_text (ldi->member_name);
919 obstack_grow_str (obstack, p);
920 xfree (p);
921 obstack_grow_str (obstack, "\"");
922 }
923
924 obstack_grow_str (obstack, " text_addr=\"");
925 obstack_grow_str (obstack, core_addr_to_string (ldi->textorg));
926 obstack_grow_str (obstack, "\"");
927
928 obstack_grow_str (obstack, " text_size=\"");
929 obstack_grow_str (obstack, pulongest (ldi->textsize));
930 obstack_grow_str (obstack, "\"");
931
932 obstack_grow_str (obstack, " data_addr=\"");
933 obstack_grow_str (obstack, core_addr_to_string (ldi->dataorg));
934 obstack_grow_str (obstack, "\"");
935
936 obstack_grow_str (obstack, " data_size=\"");
937 obstack_grow_str (obstack, pulongest (ldi->datasize));
938 obstack_grow_str (obstack, "\"");
939
940 obstack_grow_str (obstack, "></library>");
941}
942
943/* Convert the ld_info binary data provided by the AIX loader into
944 an XML representation following the TARGET_OBJECT_LIBRARIES_AIX
945 format.
946
947 LDI_BUF is a buffer containing the ld_info data.
948 READBUF, OFFSET and LEN follow the same semantics as target_ops'
949 to_xfer_partial target_ops method.
950
951 If CLOSE_LDINFO_FD is nonzero, then this routine also closes
952 the ldinfo_fd file descriptor. This is useful when the ldinfo
953 data is obtained via ptrace, as ptrace opens a file descriptor
954 for each and every entry; but we cannot use this descriptor
955 as the consumer of the XML library list might live in a different
956 process. */
957
c09f20e4 958ULONGEST
356a5233 959rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
b55e14c7 960 gdb_byte *readbuf, ULONGEST offset, ULONGEST len,
356a5233
JB
961 int close_ldinfo_fd)
962{
963 struct obstack obstack;
964 const char *buf;
c09f20e4 965 ULONGEST len_avail;
356a5233
JB
966
967 obstack_init (&obstack);
968 obstack_grow_str (&obstack, "<library-list-aix version=\"1.0\">\n");
969
970 while (1)
971 {
972 struct ld_info ldi = rs6000_aix_extract_ld_info (gdbarch, ldi_buf);
973
974 rs6000_aix_shared_library_to_xml (&ldi, &obstack);
975 if (close_ldinfo_fd)
976 close (ldi.fd);
977
978 if (!ldi.next)
979 break;
980 ldi_buf = ldi_buf + ldi.next;
981 }
982
983 obstack_grow_str0 (&obstack, "</library-list-aix>\n");
984
985 buf = obstack_finish (&obstack);
986 len_avail = strlen (buf);
987 if (offset >= len_avail)
988 len= 0;
989 else
990 {
991 if (len > len_avail - offset)
992 len = len_avail - offset;
993 memcpy (readbuf, buf + offset, len);
994 }
995
996 obstack_free (&obstack, NULL);
997 return len;
998}
999
1000/* Implement the core_xfer_shared_libraries_aix gdbarch method. */
1001
c09f20e4 1002static ULONGEST
356a5233
JB
1003rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
1004 gdb_byte *readbuf,
1005 ULONGEST offset,
7ec1862d 1006 ULONGEST len)
356a5233
JB
1007{
1008 struct bfd_section *ldinfo_sec;
1009 int ldinfo_size;
1010 gdb_byte *ldinfo_buf;
1011 struct cleanup *cleanup;
1012 LONGEST result;
1013
1014 ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo");
1015 if (ldinfo_sec == NULL)
1016 error (_("cannot find .ldinfo section from core file: %s"),
1017 bfd_errmsg (bfd_get_error ()));
1018 ldinfo_size = bfd_get_section_size (ldinfo_sec);
1019
1020 ldinfo_buf = xmalloc (ldinfo_size);
1021 cleanup = make_cleanup (xfree, ldinfo_buf);
1022
1023 if (! bfd_get_section_contents (core_bfd, ldinfo_sec,
1024 ldinfo_buf, 0, ldinfo_size))
1025 error (_("unable to read .ldinfo section from core file: %s"),
1026 bfd_errmsg (bfd_get_error ()));
1027
1028 result = rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf, readbuf,
1029 offset, len, 0);
1030
1031 do_cleanups (cleanup);
1032 return result;
1033}
1034
1f82754b
JB
1035static void
1036rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
1037{
4a7622d1
UW
1038 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1039
1f82754b
JB
1040 /* RS6000/AIX does not support PT_STEP. Has to be simulated. */
1041 set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
6f7f3f0d 1042
2454a024
UW
1043 /* Displaced stepping is currently not supported in combination with
1044 software single-stepping. */
1045 set_gdbarch_displaced_step_copy_insn (gdbarch, NULL);
1046 set_gdbarch_displaced_step_fixup (gdbarch, NULL);
1047 set_gdbarch_displaced_step_free_closure (gdbarch, NULL);
1048 set_gdbarch_displaced_step_location (gdbarch, NULL);
1049
4a7622d1
UW
1050 set_gdbarch_push_dummy_call (gdbarch, rs6000_push_dummy_call);
1051 set_gdbarch_return_value (gdbarch, rs6000_return_value);
1052 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
1053
1054 /* Handle RS/6000 function pointers (which are really function
1055 descriptors). */
1056 set_gdbarch_convert_from_func_ptr_addr
1057 (gdbarch, rs6000_convert_from_func_ptr_addr);
1058
7a61a01c 1059 /* Core file support. */
23ea9aeb
AA
1060 set_gdbarch_iterate_over_regset_sections
1061 (gdbarch, rs6000_aix_iterate_over_regset_sections);
356a5233
JB
1062 set_gdbarch_core_xfer_shared_libraries_aix
1063 (gdbarch, rs6000_aix_core_xfer_shared_libraries_aix);
7a61a01c 1064
4a7622d1
UW
1065 if (tdep->wordsize == 8)
1066 tdep->lr_frame_offset = 16;
1067 else
1068 tdep->lr_frame_offset = 8;
1069
1070 if (tdep->wordsize == 4)
1071 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
1072 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
1073 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
1074 224. */
1075 set_gdbarch_frame_red_zone_size (gdbarch, 224);
1076 else
1077 set_gdbarch_frame_red_zone_size (gdbarch, 0);
38a69d0a
JB
1078
1079 set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset);
4d1eb6b4
JB
1080
1081 set_solib_ops (gdbarch, &solib_aix_so_ops);
1f82754b
JB
1082}
1083
63807e1d
PA
1084/* Provide a prototype to silence -Wmissing-prototypes. */
1085extern initialize_file_ftype _initialize_rs6000_aix_tdep;
1086
1f82754b
JB
1087void
1088_initialize_rs6000_aix_tdep (void)
1089{
1090 gdbarch_register_osabi_sniffer (bfd_arch_rs6000,
1091 bfd_target_xcoff_flavour,
1092 rs6000_aix_osabi_sniffer);
7a61a01c
UW
1093 gdbarch_register_osabi_sniffer (bfd_arch_powerpc,
1094 bfd_target_xcoff_flavour,
1095 rs6000_aix_osabi_sniffer);
1f82754b
JB
1096
1097 gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_AIX,
1098 rs6000_aix_init_osabi);
7a61a01c
UW
1099 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_AIX,
1100 rs6000_aix_init_osabi);
1f82754b
JB
1101}
1102
This page took 0.879912 seconds and 4 git commands to generate.