Commit Andrew Cagney's rs6000 / PPC framification patch.
[deliverable/binutils-gdb.git] / gdb / rs6000-tdep.c
CommitLineData
c906108c 1/* Target-dependent code for GDB, the GNU debugger.
7aea86e6
AC
2
3 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
5 Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
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.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
c906108c
SS
23
24#include "defs.h"
25#include "frame.h"
26#include "inferior.h"
27#include "symtab.h"
28#include "target.h"
29#include "gdbcore.h"
30#include "gdbcmd.h"
c906108c 31#include "objfiles.h"
7a78ae4e 32#include "arch-utils.h"
4e052eda 33#include "regcache.h"
d16aafd8 34#include "doublest.h"
fd0407d6 35#include "value.h"
1fcc0bb8 36#include "parser-defs.h"
4be87837 37#include "osabi.h"
7a78ae4e 38
2fccf04a 39#include "libbfd.h" /* for bfd_default_set_arch_mach */
7a78ae4e 40#include "coff/internal.h" /* for libcoff.h */
2fccf04a 41#include "libcoff.h" /* for xcoff_data */
11ed25ac
KB
42#include "coff/xcoff.h"
43#include "libxcoff.h"
7a78ae4e 44
9aa1e687 45#include "elf-bfd.h"
7a78ae4e 46
6ded7999 47#include "solib-svr4.h"
9aa1e687 48#include "ppc-tdep.h"
7a78ae4e 49
338ef23d 50#include "gdb_assert.h"
a89aa300 51#include "dis-asm.h"
338ef23d 52
61a65099
KB
53#include "trad-frame.h"
54#include "frame-unwind.h"
55#include "frame-base.h"
56
7a78ae4e
ND
57/* If the kernel has to deliver a signal, it pushes a sigcontext
58 structure on the stack and then calls the signal handler, passing
59 the address of the sigcontext in an argument register. Usually
60 the signal handler doesn't save this register, so we have to
61 access the sigcontext structure via an offset from the signal handler
62 frame.
63 The following constants were determined by experimentation on AIX 3.2. */
64#define SIG_FRAME_PC_OFFSET 96
65#define SIG_FRAME_LR_OFFSET 108
66#define SIG_FRAME_FP_OFFSET 284
67
7a78ae4e
ND
68/* To be used by skip_prologue. */
69
70struct rs6000_framedata
71 {
72 int offset; /* total size of frame --- the distance
73 by which we decrement sp to allocate
74 the frame */
75 int saved_gpr; /* smallest # of saved gpr */
76 int saved_fpr; /* smallest # of saved fpr */
6be8bc0c 77 int saved_vr; /* smallest # of saved vr */
96ff0de4 78 int saved_ev; /* smallest # of saved ev */
7a78ae4e
ND
79 int alloca_reg; /* alloca register number (frame ptr) */
80 char frameless; /* true if frameless functions. */
81 char nosavedpc; /* true if pc not saved. */
82 int gpr_offset; /* offset of saved gprs from prev sp */
83 int fpr_offset; /* offset of saved fprs from prev sp */
6be8bc0c 84 int vr_offset; /* offset of saved vrs from prev sp */
96ff0de4 85 int ev_offset; /* offset of saved evs from prev sp */
7a78ae4e
ND
86 int lr_offset; /* offset of saved lr */
87 int cr_offset; /* offset of saved cr */
6be8bc0c 88 int vrsave_offset; /* offset of saved vrsave register */
7a78ae4e
ND
89 };
90
91/* Description of a single register. */
92
93struct reg
94 {
95 char *name; /* name of register */
96 unsigned char sz32; /* size on 32-bit arch, 0 if nonextant */
97 unsigned char sz64; /* size on 64-bit arch, 0 if nonextant */
98 unsigned char fpr; /* whether register is floating-point */
489461e2 99 unsigned char pseudo; /* whether register is pseudo */
7a78ae4e
ND
100 };
101
c906108c
SS
102/* Breakpoint shadows for the single step instructions will be kept here. */
103
c5aa993b
JM
104static struct sstep_breaks
105 {
106 /* Address, or 0 if this is not in use. */
107 CORE_ADDR address;
108 /* Shadow contents. */
109 char data[4];
110 }
111stepBreaks[2];
c906108c
SS
112
113/* Hook for determining the TOC address when calling functions in the
114 inferior under AIX. The initialization code in rs6000-nat.c sets
115 this hook to point to find_toc_address. */
116
7a78ae4e
ND
117CORE_ADDR (*rs6000_find_toc_address_hook) (CORE_ADDR) = NULL;
118
119/* Hook to set the current architecture when starting a child process.
120 rs6000-nat.c sets this. */
121
122void (*rs6000_set_host_arch_hook) (int) = NULL;
c906108c
SS
123
124/* Static function prototypes */
125
a14ed312
KB
126static CORE_ADDR branch_dest (int opcode, int instr, CORE_ADDR pc,
127 CORE_ADDR safety);
077276e8
KB
128static CORE_ADDR skip_prologue (CORE_ADDR, CORE_ADDR,
129 struct rs6000_framedata *);
7a78ae4e
ND
130static void frame_get_saved_regs (struct frame_info * fi,
131 struct rs6000_framedata * fdatap);
132static CORE_ADDR frame_initial_stack_address (struct frame_info *);
c906108c 133
64b84175
KB
134/* Is REGNO an AltiVec register? Return 1 if so, 0 otherwise. */
135int
136altivec_register_p (int regno)
137{
138 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
139 if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
140 return 0;
141 else
142 return (regno >= tdep->ppc_vr0_regnum && regno <= tdep->ppc_vrsave_regnum);
143}
144
0a613259
AC
145/* Use the architectures FP registers? */
146int
147ppc_floating_point_unit_p (struct gdbarch *gdbarch)
148{
149 const struct bfd_arch_info *info = gdbarch_bfd_arch_info (gdbarch);
150 if (info->arch == bfd_arch_powerpc)
151 return (info->mach != bfd_mach_ppc_e500);
152 if (info->arch == bfd_arch_rs6000)
153 return 1;
154 return 0;
155}
156
7a78ae4e 157/* Read a LEN-byte address from debugged memory address MEMADDR. */
c906108c 158
7a78ae4e
ND
159static CORE_ADDR
160read_memory_addr (CORE_ADDR memaddr, int len)
161{
162 return read_memory_unsigned_integer (memaddr, len);
163}
c906108c 164
7a78ae4e
ND
165static CORE_ADDR
166rs6000_skip_prologue (CORE_ADDR pc)
b83266a0
SS
167{
168 struct rs6000_framedata frame;
077276e8 169 pc = skip_prologue (pc, 0, &frame);
b83266a0
SS
170 return pc;
171}
172
173
c906108c
SS
174/* Fill in fi->saved_regs */
175
176struct frame_extra_info
177{
178 /* Functions calling alloca() change the value of the stack
179 pointer. We need to use initial stack pointer (which is saved in
180 r31 by gcc) in such cases. If a compiler emits traceback table,
181 then we should use the alloca register specified in traceback
182 table. FIXME. */
c5aa993b 183 CORE_ADDR initial_sp; /* initial stack pointer. */
c906108c
SS
184};
185
9aa1e687 186void
7a78ae4e 187rs6000_init_extra_frame_info (int fromleaf, struct frame_info *fi)
c906108c 188{
c9012c71
AC
189 struct frame_extra_info *extra_info =
190 frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
191 extra_info->initial_sp = 0;
bdd78e62
AC
192 if (get_next_frame (fi) != NULL
193 && get_frame_pc (fi) < TEXT_SEGMENT_BASE)
7a292a7a 194 /* We're in get_prev_frame */
c906108c
SS
195 /* and this is a special signal frame. */
196 /* (fi->pc will be some low address in the kernel, */
197 /* to which the signal handler returns). */
5a203e44 198 deprecated_set_frame_type (fi, SIGTRAMP_FRAME);
c906108c
SS
199}
200
7a78ae4e
ND
201/* Put here the code to store, into a struct frame_saved_regs,
202 the addresses of the saved registers of frame described by FRAME_INFO.
203 This includes special registers such as pc and fp saved in special
204 ways in the stack frame. sp is even more special:
205 the address we return for it IS the sp for the next frame. */
c906108c 206
7a78ae4e
ND
207/* In this implementation for RS/6000, we do *not* save sp. I am
208 not sure if it will be needed. The following function takes care of gpr's
209 and fpr's only. */
210
9aa1e687 211void
7a78ae4e 212rs6000_frame_init_saved_regs (struct frame_info *fi)
c906108c
SS
213{
214 frame_get_saved_regs (fi, NULL);
215}
216
3ce2bf18
AC
217static CORE_ADDR
218rs6000_init_frame_pc_first (int fromleaf, struct frame_info *prev)
219{
d4715e41
AC
220 return (fromleaf
221 ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev))
222 : frame_relative_level (prev) > 0
223 ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
224 : read_pc ());
3ce2bf18
AC
225}
226
7a78ae4e
ND
227static CORE_ADDR
228rs6000_frame_args_address (struct frame_info *fi)
c906108c 229{
c9012c71
AC
230 struct frame_extra_info *extra_info = get_frame_extra_info (fi);
231 if (extra_info->initial_sp != 0)
232 return extra_info->initial_sp;
c906108c
SS
233 else
234 return frame_initial_stack_address (fi);
235}
236
7a78ae4e
ND
237/* Immediately after a function call, return the saved pc.
238 Can't go through the frames for this because on some machines
239 the new frame is not set up until the new function executes
240 some instructions. */
241
242static CORE_ADDR
243rs6000_saved_pc_after_call (struct frame_info *fi)
244{
2188cbdd 245 return read_register (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum);
7a78ae4e 246}
c906108c 247
143985b7 248/* Get the ith function argument for the current function. */
b9362cc7 249static CORE_ADDR
143985b7
AF
250rs6000_fetch_pointer_argument (struct frame_info *frame, int argi,
251 struct type *type)
252{
253 CORE_ADDR addr;
7f5f525d 254 get_frame_register (frame, 3 + argi, &addr);
143985b7
AF
255 return addr;
256}
257
c906108c
SS
258/* Calculate the destination of a branch/jump. Return -1 if not a branch. */
259
260static CORE_ADDR
7a78ae4e 261branch_dest (int opcode, int instr, CORE_ADDR pc, CORE_ADDR safety)
c906108c
SS
262{
263 CORE_ADDR dest;
264 int immediate;
265 int absolute;
266 int ext_op;
267
268 absolute = (int) ((instr >> 1) & 1);
269
c5aa993b
JM
270 switch (opcode)
271 {
272 case 18:
273 immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */
274 if (absolute)
275 dest = immediate;
276 else
277 dest = pc + immediate;
278 break;
279
280 case 16:
281 immediate = ((instr & ~3) << 16) >> 16; /* br conditional */
282 if (absolute)
283 dest = immediate;
284 else
285 dest = pc + immediate;
286 break;
287
288 case 19:
289 ext_op = (instr >> 1) & 0x3ff;
290
291 if (ext_op == 16) /* br conditional register */
292 {
2188cbdd 293 dest = read_register (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum) & ~3;
c5aa993b
JM
294
295 /* If we are about to return from a signal handler, dest is
296 something like 0x3c90. The current frame is a signal handler
297 caller frame, upon completion of the sigreturn system call
298 execution will return to the saved PC in the frame. */
299 if (dest < TEXT_SEGMENT_BASE)
300 {
301 struct frame_info *fi;
302
303 fi = get_current_frame ();
304 if (fi != NULL)
8b36eed8 305 dest = read_memory_addr (get_frame_base (fi) + SIG_FRAME_PC_OFFSET,
21283beb 306 gdbarch_tdep (current_gdbarch)->wordsize);
c5aa993b
JM
307 }
308 }
309
310 else if (ext_op == 528) /* br cond to count reg */
311 {
2188cbdd 312 dest = read_register (gdbarch_tdep (current_gdbarch)->ppc_ctr_regnum) & ~3;
c5aa993b
JM
313
314 /* If we are about to execute a system call, dest is something
315 like 0x22fc or 0x3b00. Upon completion the system call
316 will return to the address in the link register. */
317 if (dest < TEXT_SEGMENT_BASE)
2188cbdd 318 dest = read_register (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum) & ~3;
c5aa993b
JM
319 }
320 else
321 return -1;
322 break;
c906108c 323
c5aa993b
JM
324 default:
325 return -1;
326 }
c906108c
SS
327 return (dest < TEXT_SEGMENT_BASE) ? safety : dest;
328}
329
330
331/* Sequence of bytes for breakpoint instruction. */
332
f4f9705a 333const static unsigned char *
7a78ae4e 334rs6000_breakpoint_from_pc (CORE_ADDR *bp_addr, int *bp_size)
c906108c 335{
aaab4dba
AC
336 static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
337 static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
c906108c 338 *bp_size = 4;
d7449b42 339 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c906108c
SS
340 return big_breakpoint;
341 else
342 return little_breakpoint;
343}
344
345
346/* AIX does not support PT_STEP. Simulate it. */
347
348void
379d08a1
AC
349rs6000_software_single_step (enum target_signal signal,
350 int insert_breakpoints_p)
c906108c 351{
7c40d541
KB
352 CORE_ADDR dummy;
353 int breakp_sz;
f4f9705a 354 const char *breakp = rs6000_breakpoint_from_pc (&dummy, &breakp_sz);
c906108c
SS
355 int ii, insn;
356 CORE_ADDR loc;
357 CORE_ADDR breaks[2];
358 int opcode;
359
c5aa993b
JM
360 if (insert_breakpoints_p)
361 {
c906108c 362
c5aa993b 363 loc = read_pc ();
c906108c 364
c5aa993b 365 insn = read_memory_integer (loc, 4);
c906108c 366
7c40d541 367 breaks[0] = loc + breakp_sz;
c5aa993b
JM
368 opcode = insn >> 26;
369 breaks[1] = branch_dest (opcode, insn, loc, breaks[0]);
c906108c 370
c5aa993b
JM
371 /* Don't put two breakpoints on the same address. */
372 if (breaks[1] == breaks[0])
373 breaks[1] = -1;
c906108c 374
c5aa993b 375 stepBreaks[1].address = 0;
c906108c 376
c5aa993b
JM
377 for (ii = 0; ii < 2; ++ii)
378 {
c906108c 379
c5aa993b
JM
380 /* ignore invalid breakpoint. */
381 if (breaks[ii] == -1)
382 continue;
7c40d541 383 target_insert_breakpoint (breaks[ii], stepBreaks[ii].data);
c5aa993b
JM
384 stepBreaks[ii].address = breaks[ii];
385 }
c906108c 386
c5aa993b
JM
387 }
388 else
389 {
c906108c 390
c5aa993b
JM
391 /* remove step breakpoints. */
392 for (ii = 0; ii < 2; ++ii)
393 if (stepBreaks[ii].address != 0)
7c40d541
KB
394 target_remove_breakpoint (stepBreaks[ii].address,
395 stepBreaks[ii].data);
c5aa993b 396 }
c906108c 397 errno = 0; /* FIXME, don't ignore errors! */
c5aa993b 398 /* What errors? {read,write}_memory call error(). */
c906108c
SS
399}
400
401
402/* return pc value after skipping a function prologue and also return
403 information about a function frame.
404
405 in struct rs6000_framedata fdata:
c5aa993b
JM
406 - frameless is TRUE, if function does not have a frame.
407 - nosavedpc is TRUE, if function does not save %pc value in its frame.
408 - offset is the initial size of this stack frame --- the amount by
409 which we decrement the sp to allocate the frame.
410 - saved_gpr is the number of the first saved gpr.
411 - saved_fpr is the number of the first saved fpr.
6be8bc0c 412 - saved_vr is the number of the first saved vr.
96ff0de4 413 - saved_ev is the number of the first saved ev.
c5aa993b
JM
414 - alloca_reg is the number of the register used for alloca() handling.
415 Otherwise -1.
416 - gpr_offset is the offset of the first saved gpr from the previous frame.
417 - fpr_offset is the offset of the first saved fpr from the previous frame.
6be8bc0c 418 - vr_offset is the offset of the first saved vr from the previous frame.
96ff0de4 419 - ev_offset is the offset of the first saved ev from the previous frame.
c5aa993b
JM
420 - lr_offset is the offset of the saved lr
421 - cr_offset is the offset of the saved cr
6be8bc0c 422 - vrsave_offset is the offset of the saved vrsave register
c5aa993b 423 */
c906108c
SS
424
425#define SIGNED_SHORT(x) \
426 ((sizeof (short) == 2) \
427 ? ((int)(short)(x)) \
428 : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000)))
429
430#define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
431
55d05f3b
KB
432/* Limit the number of skipped non-prologue instructions, as the examining
433 of the prologue is expensive. */
434static int max_skip_non_prologue_insns = 10;
435
436/* Given PC representing the starting address of a function, and
437 LIM_PC which is the (sloppy) limit to which to scan when looking
438 for a prologue, attempt to further refine this limit by using
439 the line data in the symbol table. If successful, a better guess
440 on where the prologue ends is returned, otherwise the previous
441 value of lim_pc is returned. */
634aa483
AC
442
443/* FIXME: cagney/2004-02-14: This function and logic have largely been
444 superseded by skip_prologue_using_sal. */
445
55d05f3b
KB
446static CORE_ADDR
447refine_prologue_limit (CORE_ADDR pc, CORE_ADDR lim_pc)
448{
449 struct symtab_and_line prologue_sal;
450
451 prologue_sal = find_pc_line (pc, 0);
452 if (prologue_sal.line != 0)
453 {
454 int i;
455 CORE_ADDR addr = prologue_sal.end;
456
457 /* Handle the case in which compiler's optimizer/scheduler
458 has moved instructions into the prologue. We scan ahead
459 in the function looking for address ranges whose corresponding
460 line number is less than or equal to the first one that we
461 found for the function. (It can be less than when the
462 scheduler puts a body instruction before the first prologue
463 instruction.) */
464 for (i = 2 * max_skip_non_prologue_insns;
465 i > 0 && (lim_pc == 0 || addr < lim_pc);
466 i--)
467 {
468 struct symtab_and_line sal;
469
470 sal = find_pc_line (addr, 0);
471 if (sal.line == 0)
472 break;
473 if (sal.line <= prologue_sal.line
474 && sal.symtab == prologue_sal.symtab)
475 {
476 prologue_sal = sal;
477 }
478 addr = sal.end;
479 }
480
481 if (lim_pc == 0 || prologue_sal.end < lim_pc)
482 lim_pc = prologue_sal.end;
483 }
484 return lim_pc;
485}
486
487
7a78ae4e 488static CORE_ADDR
077276e8 489skip_prologue (CORE_ADDR pc, CORE_ADDR lim_pc, struct rs6000_framedata *fdata)
c906108c
SS
490{
491 CORE_ADDR orig_pc = pc;
55d05f3b 492 CORE_ADDR last_prologue_pc = pc;
6be8bc0c 493 CORE_ADDR li_found_pc = 0;
c906108c
SS
494 char buf[4];
495 unsigned long op;
496 long offset = 0;
6be8bc0c 497 long vr_saved_offset = 0;
482ca3f5
KB
498 int lr_reg = -1;
499 int cr_reg = -1;
6be8bc0c 500 int vr_reg = -1;
96ff0de4
EZ
501 int ev_reg = -1;
502 long ev_offset = 0;
6be8bc0c 503 int vrsave_reg = -1;
c906108c
SS
504 int reg;
505 int framep = 0;
506 int minimal_toc_loaded = 0;
ddb20c56 507 int prev_insn_was_prologue_insn = 1;
55d05f3b 508 int num_skip_non_prologue_insns = 0;
96ff0de4 509 const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (current_gdbarch);
6f99cb26 510 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
96ff0de4 511
55d05f3b
KB
512 /* Attempt to find the end of the prologue when no limit is specified.
513 Note that refine_prologue_limit() has been written so that it may
514 be used to "refine" the limits of non-zero PC values too, but this
515 is only safe if we 1) trust the line information provided by the
516 compiler and 2) iterate enough to actually find the end of the
517 prologue.
518
519 It may become a good idea at some point (for both performance and
520 accuracy) to unconditionally call refine_prologue_limit(). But,
521 until we can make a clear determination that this is beneficial,
522 we'll play it safe and only use it to obtain a limit when none
523 has been specified. */
524 if (lim_pc == 0)
525 lim_pc = refine_prologue_limit (pc, lim_pc);
c906108c 526
ddb20c56 527 memset (fdata, 0, sizeof (struct rs6000_framedata));
c906108c
SS
528 fdata->saved_gpr = -1;
529 fdata->saved_fpr = -1;
6be8bc0c 530 fdata->saved_vr = -1;
96ff0de4 531 fdata->saved_ev = -1;
c906108c
SS
532 fdata->alloca_reg = -1;
533 fdata->frameless = 1;
534 fdata->nosavedpc = 1;
535
55d05f3b 536 for (;; pc += 4)
c906108c 537 {
ddb20c56
KB
538 /* Sometimes it isn't clear if an instruction is a prologue
539 instruction or not. When we encounter one of these ambiguous
540 cases, we'll set prev_insn_was_prologue_insn to 0 (false).
541 Otherwise, we'll assume that it really is a prologue instruction. */
542 if (prev_insn_was_prologue_insn)
543 last_prologue_pc = pc;
55d05f3b
KB
544
545 /* Stop scanning if we've hit the limit. */
546 if (lim_pc != 0 && pc >= lim_pc)
547 break;
548
ddb20c56
KB
549 prev_insn_was_prologue_insn = 1;
550
55d05f3b 551 /* Fetch the instruction and convert it to an integer. */
ddb20c56
KB
552 if (target_read_memory (pc, buf, 4))
553 break;
554 op = extract_signed_integer (buf, 4);
c906108c 555
c5aa993b
JM
556 if ((op & 0xfc1fffff) == 0x7c0802a6)
557 { /* mflr Rx */
43b1ab88
AC
558 /* Since shared library / PIC code, which needs to get its
559 address at runtime, can appear to save more than one link
560 register vis:
561
562 *INDENT-OFF*
563 stwu r1,-304(r1)
564 mflr r3
565 bl 0xff570d0 (blrl)
566 stw r30,296(r1)
567 mflr r30
568 stw r31,300(r1)
569 stw r3,308(r1);
570 ...
571 *INDENT-ON*
572
573 remember just the first one, but skip over additional
574 ones. */
575 if (lr_reg < 0)
576 lr_reg = (op & 0x03e00000);
c5aa993b 577 continue;
c5aa993b
JM
578 }
579 else if ((op & 0xfc1fffff) == 0x7c000026)
580 { /* mfcr Rx */
98f08d3d 581 cr_reg = (op & 0x03e00000);
c5aa993b 582 continue;
c906108c 583
c906108c 584 }
c5aa993b
JM
585 else if ((op & 0xfc1f0000) == 0xd8010000)
586 { /* stfd Rx,NUM(r1) */
587 reg = GET_SRC_REG (op);
588 if (fdata->saved_fpr == -1 || fdata->saved_fpr > reg)
589 {
590 fdata->saved_fpr = reg;
591 fdata->fpr_offset = SIGNED_SHORT (op) + offset;
592 }
593 continue;
c906108c 594
c5aa993b
JM
595 }
596 else if (((op & 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */
7a78ae4e
ND
597 (((op & 0xfc1f0000) == 0x90010000 || /* st rx,NUM(r1) */
598 (op & 0xfc1f0003) == 0xf8010000) && /* std rx,NUM(r1) */
599 (op & 0x03e00000) >= 0x01a00000)) /* rx >= r13 */
c5aa993b
JM
600 {
601
602 reg = GET_SRC_REG (op);
603 if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg)
604 {
605 fdata->saved_gpr = reg;
7a78ae4e 606 if ((op & 0xfc1f0003) == 0xf8010000)
98f08d3d 607 op &= ~3UL;
c5aa993b
JM
608 fdata->gpr_offset = SIGNED_SHORT (op) + offset;
609 }
610 continue;
c906108c 611
ddb20c56
KB
612 }
613 else if ((op & 0xffff0000) == 0x60000000)
614 {
96ff0de4 615 /* nop */
ddb20c56
KB
616 /* Allow nops in the prologue, but do not consider them to
617 be part of the prologue unless followed by other prologue
618 instructions. */
619 prev_insn_was_prologue_insn = 0;
620 continue;
621
c906108c 622 }
c5aa993b
JM
623 else if ((op & 0xffff0000) == 0x3c000000)
624 { /* addis 0,0,NUM, used
625 for >= 32k frames */
626 fdata->offset = (op & 0x0000ffff) << 16;
627 fdata->frameless = 0;
628 continue;
629
630 }
631 else if ((op & 0xffff0000) == 0x60000000)
632 { /* ori 0,0,NUM, 2nd ha
633 lf of >= 32k frames */
634 fdata->offset |= (op & 0x0000ffff);
635 fdata->frameless = 0;
636 continue;
637
638 }
98f08d3d
KB
639 else if (lr_reg != -1 &&
640 /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */
641 (((op & 0xffff0000) == (lr_reg | 0xf8010000)) ||
642 /* stw Rx, NUM(r1) */
643 ((op & 0xffff0000) == (lr_reg | 0x90010000)) ||
644 /* stwu Rx, NUM(r1) */
645 ((op & 0xffff0000) == (lr_reg | 0x94010000))))
646 { /* where Rx == lr */
647 fdata->lr_offset = offset;
c5aa993b
JM
648 fdata->nosavedpc = 0;
649 lr_reg = 0;
98f08d3d
KB
650 if ((op & 0xfc000003) == 0xf8000000 || /* std */
651 (op & 0xfc000000) == 0x90000000) /* stw */
652 {
653 /* Does not update r1, so add displacement to lr_offset. */
654 fdata->lr_offset += SIGNED_SHORT (op);
655 }
c5aa993b
JM
656 continue;
657
658 }
98f08d3d
KB
659 else if (cr_reg != -1 &&
660 /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */
661 (((op & 0xffff0000) == (cr_reg | 0xf8010000)) ||
662 /* stw Rx, NUM(r1) */
663 ((op & 0xffff0000) == (cr_reg | 0x90010000)) ||
664 /* stwu Rx, NUM(r1) */
665 ((op & 0xffff0000) == (cr_reg | 0x94010000))))
666 { /* where Rx == cr */
667 fdata->cr_offset = offset;
c5aa993b 668 cr_reg = 0;
98f08d3d
KB
669 if ((op & 0xfc000003) == 0xf8000000 ||
670 (op & 0xfc000000) == 0x90000000)
671 {
672 /* Does not update r1, so add displacement to cr_offset. */
673 fdata->cr_offset += SIGNED_SHORT (op);
674 }
c5aa993b
JM
675 continue;
676
677 }
678 else if (op == 0x48000005)
679 { /* bl .+4 used in
680 -mrelocatable */
681 continue;
682
683 }
684 else if (op == 0x48000004)
685 { /* b .+4 (xlc) */
686 break;
687
c5aa993b 688 }
6be8bc0c
EZ
689 else if ((op & 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used
690 in V.4 -mminimal-toc */
c5aa993b
JM
691 (op & 0xffff0000) == 0x3bde0000)
692 { /* addi 30,30,foo@l */
693 continue;
c906108c 694
c5aa993b
JM
695 }
696 else if ((op & 0xfc000001) == 0x48000001)
697 { /* bl foo,
698 to save fprs??? */
c906108c 699
c5aa993b 700 fdata->frameless = 0;
6be8bc0c
EZ
701 /* Don't skip over the subroutine call if it is not within
702 the first three instructions of the prologue. */
c5aa993b
JM
703 if ((pc - orig_pc) > 8)
704 break;
705
706 op = read_memory_integer (pc + 4, 4);
707
6be8bc0c
EZ
708 /* At this point, make sure this is not a trampoline
709 function (a function that simply calls another functions,
710 and nothing else). If the next is not a nop, this branch
711 was part of the function prologue. */
c5aa993b
JM
712
713 if (op == 0x4def7b82 || op == 0) /* crorc 15, 15, 15 */
714 break; /* don't skip over
715 this branch */
716 continue;
717
c5aa993b 718 }
98f08d3d
KB
719 /* update stack pointer */
720 else if ((op & 0xfc1f0000) == 0x94010000)
721 { /* stu rX,NUM(r1) || stwu rX,NUM(r1) */
c5aa993b
JM
722 fdata->frameless = 0;
723 fdata->offset = SIGNED_SHORT (op);
724 offset = fdata->offset;
725 continue;
c5aa993b 726 }
98f08d3d
KB
727 else if ((op & 0xfc1f016a) == 0x7c01016e)
728 { /* stwux rX,r1,rY */
729 /* no way to figure out what r1 is going to be */
730 fdata->frameless = 0;
731 offset = fdata->offset;
732 continue;
733 }
734 else if ((op & 0xfc1f0003) == 0xf8010001)
735 { /* stdu rX,NUM(r1) */
736 fdata->frameless = 0;
737 fdata->offset = SIGNED_SHORT (op & ~3UL);
738 offset = fdata->offset;
739 continue;
740 }
741 else if ((op & 0xfc1f016a) == 0x7c01016a)
742 { /* stdux rX,r1,rY */
743 /* no way to figure out what r1 is going to be */
c5aa993b
JM
744 fdata->frameless = 0;
745 offset = fdata->offset;
746 continue;
c5aa993b 747 }
98f08d3d
KB
748 /* Load up minimal toc pointer */
749 else if (((op >> 22) == 0x20f || /* l r31,... or l r30,... */
750 (op >> 22) == 0x3af) /* ld r31,... or ld r30,... */
c5aa993b 751 && !minimal_toc_loaded)
98f08d3d 752 {
c5aa993b
JM
753 minimal_toc_loaded = 1;
754 continue;
755
f6077098
KB
756 /* move parameters from argument registers to local variable
757 registers */
758 }
759 else if ((op & 0xfc0007fe) == 0x7c000378 && /* mr(.) Rx,Ry */
760 (((op >> 21) & 31) >= 3) && /* R3 >= Ry >= R10 */
761 (((op >> 21) & 31) <= 10) &&
96ff0de4 762 ((long) ((op >> 16) & 31) >= fdata->saved_gpr)) /* Rx: local var reg */
f6077098
KB
763 {
764 continue;
765
c5aa993b
JM
766 /* store parameters in stack */
767 }
6be8bc0c 768 else if ((op & 0xfc1f0003) == 0xf8010000 || /* std rx,NUM(r1) */
c5aa993b 769 (op & 0xfc1f0000) == 0xd8010000 || /* stfd Rx,NUM(r1) */
7a78ae4e
ND
770 (op & 0xfc1f0000) == 0xfc010000) /* frsp, fp?,NUM(r1) */
771 {
c5aa993b 772 continue;
c906108c 773
c5aa993b
JM
774 /* store parameters in stack via frame pointer */
775 }
776 else if (framep &&
777 ((op & 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r1) */
778 (op & 0xfc1f0000) == 0xd81f0000 || /* stfd Rx,NUM(r1) */
779 (op & 0xfc1f0000) == 0xfc1f0000))
780 { /* frsp, fp?,NUM(r1) */
781 continue;
782
783 /* Set up frame pointer */
784 }
785 else if (op == 0x603f0000 /* oril r31, r1, 0x0 */
786 || op == 0x7c3f0b78)
787 { /* mr r31, r1 */
788 fdata->frameless = 0;
789 framep = 1;
6f99cb26 790 fdata->alloca_reg = (tdep->ppc_gp0_regnum + 31);
c5aa993b
JM
791 continue;
792
793 /* Another way to set up the frame pointer. */
794 }
795 else if ((op & 0xfc1fffff) == 0x38010000)
796 { /* addi rX, r1, 0x0 */
797 fdata->frameless = 0;
798 framep = 1;
6f99cb26
AC
799 fdata->alloca_reg = (tdep->ppc_gp0_regnum
800 + ((op & ~0x38010000) >> 21));
c5aa993b 801 continue;
c5aa993b 802 }
6be8bc0c
EZ
803 /* AltiVec related instructions. */
804 /* Store the vrsave register (spr 256) in another register for
805 later manipulation, or load a register into the vrsave
806 register. 2 instructions are used: mfvrsave and
807 mtvrsave. They are shorthand notation for mfspr Rn, SPR256
808 and mtspr SPR256, Rn. */
809 /* mfspr Rn SPR256 == 011111 nnnnn 0000001000 01010100110
810 mtspr SPR256 Rn == 011111 nnnnn 0000001000 01110100110 */
811 else if ((op & 0xfc1fffff) == 0x7c0042a6) /* mfvrsave Rn */
812 {
813 vrsave_reg = GET_SRC_REG (op);
814 continue;
815 }
816 else if ((op & 0xfc1fffff) == 0x7c0043a6) /* mtvrsave Rn */
817 {
818 continue;
819 }
820 /* Store the register where vrsave was saved to onto the stack:
821 rS is the register where vrsave was stored in a previous
822 instruction. */
823 /* 100100 sssss 00001 dddddddd dddddddd */
824 else if ((op & 0xfc1f0000) == 0x90010000) /* stw rS, d(r1) */
825 {
826 if (vrsave_reg == GET_SRC_REG (op))
827 {
828 fdata->vrsave_offset = SIGNED_SHORT (op) + offset;
829 vrsave_reg = -1;
830 }
831 continue;
832 }
833 /* Compute the new value of vrsave, by modifying the register
834 where vrsave was saved to. */
835 else if (((op & 0xfc000000) == 0x64000000) /* oris Ra, Rs, UIMM */
836 || ((op & 0xfc000000) == 0x60000000))/* ori Ra, Rs, UIMM */
837 {
838 continue;
839 }
840 /* li r0, SIMM (short for addi r0, 0, SIMM). This is the first
841 in a pair of insns to save the vector registers on the
842 stack. */
843 /* 001110 00000 00000 iiii iiii iiii iiii */
96ff0de4
EZ
844 /* 001110 01110 00000 iiii iiii iiii iiii */
845 else if ((op & 0xffff0000) == 0x38000000 /* li r0, SIMM */
846 || (op & 0xffff0000) == 0x39c00000) /* li r14, SIMM */
6be8bc0c
EZ
847 {
848 li_found_pc = pc;
849 vr_saved_offset = SIGNED_SHORT (op);
850 }
851 /* Store vector register S at (r31+r0) aligned to 16 bytes. */
852 /* 011111 sssss 11111 00000 00111001110 */
853 else if ((op & 0xfc1fffff) == 0x7c1f01ce) /* stvx Vs, R31, R0 */
854 {
855 if (pc == (li_found_pc + 4))
856 {
857 vr_reg = GET_SRC_REG (op);
858 /* If this is the first vector reg to be saved, or if
859 it has a lower number than others previously seen,
860 reupdate the frame info. */
861 if (fdata->saved_vr == -1 || fdata->saved_vr > vr_reg)
862 {
863 fdata->saved_vr = vr_reg;
864 fdata->vr_offset = vr_saved_offset + offset;
865 }
866 vr_saved_offset = -1;
867 vr_reg = -1;
868 li_found_pc = 0;
869 }
870 }
871 /* End AltiVec related instructions. */
96ff0de4
EZ
872
873 /* Start BookE related instructions. */
874 /* Store gen register S at (r31+uimm).
875 Any register less than r13 is volatile, so we don't care. */
876 /* 000100 sssss 11111 iiiii 01100100001 */
877 else if (arch_info->mach == bfd_mach_ppc_e500
878 && (op & 0xfc1f07ff) == 0x101f0321) /* evstdd Rs,uimm(R31) */
879 {
880 if ((op & 0x03e00000) >= 0x01a00000) /* Rs >= r13 */
881 {
882 unsigned int imm;
883 ev_reg = GET_SRC_REG (op);
884 imm = (op >> 11) & 0x1f;
885 ev_offset = imm * 8;
886 /* If this is the first vector reg to be saved, or if
887 it has a lower number than others previously seen,
888 reupdate the frame info. */
889 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
890 {
891 fdata->saved_ev = ev_reg;
892 fdata->ev_offset = ev_offset + offset;
893 }
894 }
895 continue;
896 }
897 /* Store gen register rS at (r1+rB). */
898 /* 000100 sssss 00001 bbbbb 01100100000 */
899 else if (arch_info->mach == bfd_mach_ppc_e500
900 && (op & 0xffe007ff) == 0x13e00320) /* evstddx RS,R1,Rb */
901 {
902 if (pc == (li_found_pc + 4))
903 {
904 ev_reg = GET_SRC_REG (op);
905 /* If this is the first vector reg to be saved, or if
906 it has a lower number than others previously seen,
907 reupdate the frame info. */
908 /* We know the contents of rB from the previous instruction. */
909 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
910 {
911 fdata->saved_ev = ev_reg;
912 fdata->ev_offset = vr_saved_offset + offset;
913 }
914 vr_saved_offset = -1;
915 ev_reg = -1;
916 li_found_pc = 0;
917 }
918 continue;
919 }
920 /* Store gen register r31 at (rA+uimm). */
921 /* 000100 11111 aaaaa iiiii 01100100001 */
922 else if (arch_info->mach == bfd_mach_ppc_e500
923 && (op & 0xffe007ff) == 0x13e00321) /* evstdd R31,Ra,UIMM */
924 {
925 /* Wwe know that the source register is 31 already, but
926 it can't hurt to compute it. */
927 ev_reg = GET_SRC_REG (op);
928 ev_offset = ((op >> 11) & 0x1f) * 8;
929 /* If this is the first vector reg to be saved, or if
930 it has a lower number than others previously seen,
931 reupdate the frame info. */
932 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
933 {
934 fdata->saved_ev = ev_reg;
935 fdata->ev_offset = ev_offset + offset;
936 }
937
938 continue;
939 }
940 /* Store gen register S at (r31+r0).
941 Store param on stack when offset from SP bigger than 4 bytes. */
942 /* 000100 sssss 11111 00000 01100100000 */
943 else if (arch_info->mach == bfd_mach_ppc_e500
944 && (op & 0xfc1fffff) == 0x101f0320) /* evstddx Rs,R31,R0 */
945 {
946 if (pc == (li_found_pc + 4))
947 {
948 if ((op & 0x03e00000) >= 0x01a00000)
949 {
950 ev_reg = GET_SRC_REG (op);
951 /* If this is the first vector reg to be saved, or if
952 it has a lower number than others previously seen,
953 reupdate the frame info. */
954 /* We know the contents of r0 from the previous
955 instruction. */
956 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
957 {
958 fdata->saved_ev = ev_reg;
959 fdata->ev_offset = vr_saved_offset + offset;
960 }
961 ev_reg = -1;
962 }
963 vr_saved_offset = -1;
964 li_found_pc = 0;
965 continue;
966 }
967 }
968 /* End BookE related instructions. */
969
c5aa993b
JM
970 else
971 {
55d05f3b
KB
972 /* Not a recognized prologue instruction.
973 Handle optimizer code motions into the prologue by continuing
974 the search if we have no valid frame yet or if the return
975 address is not yet saved in the frame. */
976 if (fdata->frameless == 0
977 && (lr_reg == -1 || fdata->nosavedpc == 0))
978 break;
979
980 if (op == 0x4e800020 /* blr */
981 || op == 0x4e800420) /* bctr */
982 /* Do not scan past epilogue in frameless functions or
983 trampolines. */
984 break;
985 if ((op & 0xf4000000) == 0x40000000) /* bxx */
64366f1c 986 /* Never skip branches. */
55d05f3b
KB
987 break;
988
989 if (num_skip_non_prologue_insns++ > max_skip_non_prologue_insns)
990 /* Do not scan too many insns, scanning insns is expensive with
991 remote targets. */
992 break;
993
994 /* Continue scanning. */
995 prev_insn_was_prologue_insn = 0;
996 continue;
c5aa993b 997 }
c906108c
SS
998 }
999
1000#if 0
1001/* I have problems with skipping over __main() that I need to address
1002 * sometime. Previously, I used to use misc_function_vector which
1003 * didn't work as well as I wanted to be. -MGO */
1004
1005 /* If the first thing after skipping a prolog is a branch to a function,
1006 this might be a call to an initializer in main(), introduced by gcc2.
64366f1c 1007 We'd like to skip over it as well. Fortunately, xlc does some extra
c906108c 1008 work before calling a function right after a prologue, thus we can
64366f1c 1009 single out such gcc2 behaviour. */
c906108c 1010
c906108c 1011
c5aa993b
JM
1012 if ((op & 0xfc000001) == 0x48000001)
1013 { /* bl foo, an initializer function? */
1014 op = read_memory_integer (pc + 4, 4);
1015
1016 if (op == 0x4def7b82)
1017 { /* cror 0xf, 0xf, 0xf (nop) */
c906108c 1018
64366f1c
EZ
1019 /* Check and see if we are in main. If so, skip over this
1020 initializer function as well. */
c906108c 1021
c5aa993b 1022 tmp = find_pc_misc_function (pc);
6314a349
AC
1023 if (tmp >= 0
1024 && strcmp (misc_function_vector[tmp].name, main_name ()) == 0)
c5aa993b
JM
1025 return pc + 8;
1026 }
c906108c 1027 }
c906108c 1028#endif /* 0 */
c5aa993b
JM
1029
1030 fdata->offset = -fdata->offset;
ddb20c56 1031 return last_prologue_pc;
c906108c
SS
1032}
1033
1034
1035/*************************************************************************
f6077098 1036 Support for creating pushing a dummy frame into the stack, and popping
c906108c
SS
1037 frames, etc.
1038*************************************************************************/
1039
c906108c 1040
64366f1c 1041/* Pop the innermost frame, go back to the caller. */
c5aa993b 1042
c906108c 1043static void
7a78ae4e 1044rs6000_pop_frame (void)
c906108c 1045{
470d5666 1046 CORE_ADDR pc, lr, sp, prev_sp, addr; /* %pc, %lr, %sp */
c906108c
SS
1047 struct rs6000_framedata fdata;
1048 struct frame_info *frame = get_current_frame ();
470d5666 1049 int ii, wordsize;
c906108c
SS
1050
1051 pc = read_pc ();
c193f6ac 1052 sp = get_frame_base (frame);
c906108c 1053
bdd78e62 1054 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame),
8b36eed8
AC
1055 get_frame_base (frame),
1056 get_frame_base (frame)))
c906108c 1057 {
7a78ae4e
ND
1058 generic_pop_dummy_frame ();
1059 flush_cached_frames ();
1060 return;
c906108c
SS
1061 }
1062
1063 /* Make sure that all registers are valid. */
b8b527c5 1064 deprecated_read_register_bytes (0, NULL, DEPRECATED_REGISTER_BYTES);
c906108c 1065
64366f1c 1066 /* Figure out previous %pc value. If the function is frameless, it is
c906108c 1067 still in the link register, otherwise walk the frames and retrieve the
64366f1c 1068 saved %pc value in the previous frame. */
c906108c 1069
be41e9f4 1070 addr = get_frame_func (frame);
bdd78e62 1071 (void) skip_prologue (addr, get_frame_pc (frame), &fdata);
c906108c 1072
21283beb 1073 wordsize = gdbarch_tdep (current_gdbarch)->wordsize;
c906108c
SS
1074 if (fdata.frameless)
1075 prev_sp = sp;
1076 else
7a78ae4e 1077 prev_sp = read_memory_addr (sp, wordsize);
c906108c 1078 if (fdata.lr_offset == 0)
2188cbdd 1079 lr = read_register (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum);
c906108c 1080 else
7a78ae4e 1081 lr = read_memory_addr (prev_sp + fdata.lr_offset, wordsize);
c906108c
SS
1082
1083 /* reset %pc value. */
1084 write_register (PC_REGNUM, lr);
1085
64366f1c 1086 /* reset register values if any was saved earlier. */
c906108c
SS
1087
1088 if (fdata.saved_gpr != -1)
1089 {
1090 addr = prev_sp + fdata.gpr_offset;
c5aa993b
JM
1091 for (ii = fdata.saved_gpr; ii <= 31; ++ii)
1092 {
62700349 1093 read_memory (addr, &deprecated_registers[DEPRECATED_REGISTER_BYTE (ii)],
524d7c18 1094 wordsize);
7a78ae4e 1095 addr += wordsize;
c5aa993b 1096 }
c906108c
SS
1097 }
1098
1099 if (fdata.saved_fpr != -1)
1100 {
1101 addr = prev_sp + fdata.fpr_offset;
c5aa993b
JM
1102 for (ii = fdata.saved_fpr; ii <= 31; ++ii)
1103 {
62700349 1104 read_memory (addr, &deprecated_registers[DEPRECATED_REGISTER_BYTE (ii + FP0_REGNUM)], 8);
c5aa993b
JM
1105 addr += 8;
1106 }
c906108c
SS
1107 }
1108
1109 write_register (SP_REGNUM, prev_sp);
1110 target_store_registers (-1);
1111 flush_cached_frames ();
1112}
1113
11269d7e
AC
1114/* All the ABI's require 16 byte alignment. */
1115static CORE_ADDR
1116rs6000_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
1117{
1118 return (addr & -16);
1119}
1120
7a78ae4e 1121/* Pass the arguments in either registers, or in the stack. In RS/6000,
c906108c
SS
1122 the first eight words of the argument list (that might be less than
1123 eight parameters if some parameters occupy more than one word) are
7a78ae4e 1124 passed in r3..r10 registers. float and double parameters are
64366f1c
EZ
1125 passed in fpr's, in addition to that. Rest of the parameters if any
1126 are passed in user stack. There might be cases in which half of the
c906108c
SS
1127 parameter is copied into registers, the other half is pushed into
1128 stack.
1129
7a78ae4e
ND
1130 Stack must be aligned on 64-bit boundaries when synthesizing
1131 function calls.
1132
c906108c
SS
1133 If the function is returning a structure, then the return address is passed
1134 in r3, then the first 7 words of the parameters can be passed in registers,
64366f1c 1135 starting from r4. */
c906108c 1136
7a78ae4e 1137static CORE_ADDR
77b2b6d4
AC
1138rs6000_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
1139 struct regcache *regcache, CORE_ADDR bp_addr,
1140 int nargs, struct value **args, CORE_ADDR sp,
1141 int struct_return, CORE_ADDR struct_addr)
c906108c 1142{
7a41266b 1143 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
c906108c
SS
1144 int ii;
1145 int len = 0;
c5aa993b
JM
1146 int argno; /* current argument number */
1147 int argbytes; /* current argument byte */
1148 char tmp_buffer[50];
1149 int f_argno = 0; /* current floating point argno */
21283beb 1150 int wordsize = gdbarch_tdep (current_gdbarch)->wordsize;
c906108c 1151
ea7c478f 1152 struct value *arg = 0;
c906108c
SS
1153 struct type *type;
1154
1155 CORE_ADDR saved_sp;
1156
64366f1c 1157 /* The first eight words of ther arguments are passed in registers.
7a41266b
AC
1158 Copy them appropriately. */
1159 ii = 0;
1160
1161 /* If the function is returning a `struct', then the first word
1162 (which will be passed in r3) is used for struct return address.
1163 In that case we should advance one word and start from r4
1164 register to copy parameters. */
1165 if (struct_return)
1166 {
1167 regcache_raw_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
1168 struct_addr);
1169 ii++;
1170 }
c906108c
SS
1171
1172/*
c5aa993b
JM
1173 effectively indirect call... gcc does...
1174
1175 return_val example( float, int);
1176
1177 eabi:
1178 float in fp0, int in r3
1179 offset of stack on overflow 8/16
1180 for varargs, must go by type.
1181 power open:
1182 float in r3&r4, int in r5
1183 offset of stack on overflow different
1184 both:
1185 return in r3 or f0. If no float, must study how gcc emulates floats;
1186 pay attention to arg promotion.
1187 User may have to cast\args to handle promotion correctly
1188 since gdb won't know if prototype supplied or not.
1189 */
c906108c 1190
c5aa993b
JM
1191 for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii)
1192 {
12c266ea 1193 int reg_size = DEPRECATED_REGISTER_RAW_SIZE (ii + 3);
c5aa993b
JM
1194
1195 arg = args[argno];
1196 type = check_typedef (VALUE_TYPE (arg));
1197 len = TYPE_LENGTH (type);
1198
1199 if (TYPE_CODE (type) == TYPE_CODE_FLT)
1200 {
1201
64366f1c 1202 /* Floating point arguments are passed in fpr's, as well as gpr's.
c5aa993b 1203 There are 13 fpr's reserved for passing parameters. At this point
64366f1c 1204 there is no way we would run out of them. */
c5aa993b
JM
1205
1206 if (len > 8)
1207 printf_unfiltered (
1208 "Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno);
1209
62700349 1210 memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM + 1 + f_argno)],
c5aa993b
JM
1211 VALUE_CONTENTS (arg),
1212 len);
1213 ++f_argno;
1214 }
1215
f6077098 1216 if (len > reg_size)
c5aa993b
JM
1217 {
1218
64366f1c 1219 /* Argument takes more than one register. */
c5aa993b
JM
1220 while (argbytes < len)
1221 {
62700349 1222 memset (&deprecated_registers[DEPRECATED_REGISTER_BYTE (ii + 3)], 0,
524d7c18 1223 reg_size);
62700349 1224 memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (ii + 3)],
c5aa993b 1225 ((char *) VALUE_CONTENTS (arg)) + argbytes,
f6077098
KB
1226 (len - argbytes) > reg_size
1227 ? reg_size : len - argbytes);
1228 ++ii, argbytes += reg_size;
c5aa993b
JM
1229
1230 if (ii >= 8)
1231 goto ran_out_of_registers_for_arguments;
1232 }
1233 argbytes = 0;
1234 --ii;
1235 }
1236 else
64366f1c
EZ
1237 {
1238 /* Argument can fit in one register. No problem. */
d7449b42 1239 int adj = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? reg_size - len : 0;
62700349
AC
1240 memset (&deprecated_registers[DEPRECATED_REGISTER_BYTE (ii + 3)], 0, reg_size);
1241 memcpy ((char *)&deprecated_registers[DEPRECATED_REGISTER_BYTE (ii + 3)] + adj,
f6077098 1242 VALUE_CONTENTS (arg), len);
c5aa993b
JM
1243 }
1244 ++argno;
c906108c 1245 }
c906108c
SS
1246
1247ran_out_of_registers_for_arguments:
1248
7a78ae4e 1249 saved_sp = read_sp ();
cc9836a8 1250
64366f1c 1251 /* Location for 8 parameters are always reserved. */
7a78ae4e 1252 sp -= wordsize * 8;
f6077098 1253
64366f1c 1254 /* Another six words for back chain, TOC register, link register, etc. */
7a78ae4e 1255 sp -= wordsize * 6;
f6077098 1256
64366f1c 1257 /* Stack pointer must be quadword aligned. */
7a78ae4e 1258 sp &= -16;
c906108c 1259
64366f1c
EZ
1260 /* If there are more arguments, allocate space for them in
1261 the stack, then push them starting from the ninth one. */
c906108c 1262
c5aa993b
JM
1263 if ((argno < nargs) || argbytes)
1264 {
1265 int space = 0, jj;
c906108c 1266
c5aa993b
JM
1267 if (argbytes)
1268 {
1269 space += ((len - argbytes + 3) & -4);
1270 jj = argno + 1;
1271 }
1272 else
1273 jj = argno;
c906108c 1274
c5aa993b
JM
1275 for (; jj < nargs; ++jj)
1276 {
ea7c478f 1277 struct value *val = args[jj];
c5aa993b
JM
1278 space += ((TYPE_LENGTH (VALUE_TYPE (val))) + 3) & -4;
1279 }
c906108c 1280
64366f1c 1281 /* Add location required for the rest of the parameters. */
f6077098 1282 space = (space + 15) & -16;
c5aa993b 1283 sp -= space;
c906108c 1284
7aea86e6
AC
1285 /* This is another instance we need to be concerned about
1286 securing our stack space. If we write anything underneath %sp
1287 (r1), we might conflict with the kernel who thinks he is free
1288 to use this area. So, update %sp first before doing anything
1289 else. */
1290
1291 regcache_raw_write_signed (regcache, SP_REGNUM, sp);
1292
64366f1c
EZ
1293 /* If the last argument copied into the registers didn't fit there
1294 completely, push the rest of it into stack. */
c906108c 1295
c5aa993b
JM
1296 if (argbytes)
1297 {
1298 write_memory (sp + 24 + (ii * 4),
1299 ((char *) VALUE_CONTENTS (arg)) + argbytes,
1300 len - argbytes);
1301 ++argno;
1302 ii += ((len - argbytes + 3) & -4) / 4;
1303 }
c906108c 1304
64366f1c 1305 /* Push the rest of the arguments into stack. */
c5aa993b
JM
1306 for (; argno < nargs; ++argno)
1307 {
c906108c 1308
c5aa993b
JM
1309 arg = args[argno];
1310 type = check_typedef (VALUE_TYPE (arg));
1311 len = TYPE_LENGTH (type);
c906108c
SS
1312
1313
64366f1c
EZ
1314 /* Float types should be passed in fpr's, as well as in the
1315 stack. */
c5aa993b
JM
1316 if (TYPE_CODE (type) == TYPE_CODE_FLT && f_argno < 13)
1317 {
c906108c 1318
c5aa993b
JM
1319 if (len > 8)
1320 printf_unfiltered (
1321 "Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno);
c906108c 1322
62700349 1323 memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM + 1 + f_argno)],
c5aa993b
JM
1324 VALUE_CONTENTS (arg),
1325 len);
1326 ++f_argno;
1327 }
c906108c 1328
c5aa993b
JM
1329 write_memory (sp + 24 + (ii * 4), (char *) VALUE_CONTENTS (arg), len);
1330 ii += ((len + 3) & -4) / 4;
1331 }
c906108c 1332 }
c906108c 1333
69517000 1334 /* Set the stack pointer. According to the ABI, the SP is meant to
7aea86e6
AC
1335 be set _before_ the corresponding stack space is used. On AIX,
1336 this even applies when the target has been completely stopped!
1337 Not doing this can lead to conflicts with the kernel which thinks
1338 that it still has control over this not-yet-allocated stack
1339 region. */
33a7c2fc
AC
1340 regcache_raw_write_signed (regcache, SP_REGNUM, sp);
1341
7aea86e6
AC
1342 /* Set back chain properly. */
1343 store_unsigned_integer (tmp_buffer, 4, saved_sp);
1344 write_memory (sp, tmp_buffer, 4);
1345
e56a0ecc
AC
1346 /* Point the inferior function call's return address at the dummy's
1347 breakpoint. */
1348 regcache_raw_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
1349
794a477a
AC
1350 /* Set the TOC register, get the value from the objfile reader
1351 which, in turn, gets it from the VMAP table. */
1352 if (rs6000_find_toc_address_hook != NULL)
1353 {
1354 CORE_ADDR tocvalue = (*rs6000_find_toc_address_hook) (func_addr);
1355 regcache_raw_write_signed (regcache, tdep->ppc_toc_regnum, tocvalue);
1356 }
1357
c906108c
SS
1358 target_store_registers (-1);
1359 return sp;
1360}
c906108c 1361
b9ff3018
AC
1362/* PowerOpen always puts structures in memory. Vectors, which were
1363 added later, do get returned in a register though. */
1364
1365static int
1366rs6000_use_struct_convention (int gcc_p, struct type *value_type)
1367{
1368 if ((TYPE_LENGTH (value_type) == 16 || TYPE_LENGTH (value_type) == 8)
1369 && TYPE_VECTOR (value_type))
1370 return 0;
1371 return 1;
1372}
1373
7a78ae4e
ND
1374static void
1375rs6000_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
c906108c
SS
1376{
1377 int offset = 0;
ace1378a 1378 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
c906108c 1379
c5aa993b
JM
1380 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1381 {
c906108c 1382
c5aa993b
JM
1383 double dd;
1384 float ff;
1385 /* floats and doubles are returned in fpr1. fpr's have a size of 8 bytes.
1386 We need to truncate the return value into float size (4 byte) if
64366f1c 1387 necessary. */
c906108c 1388
c5aa993b
JM
1389 if (TYPE_LENGTH (valtype) > 4) /* this is a double */
1390 memcpy (valbuf,
62700349 1391 &regbuf[DEPRECATED_REGISTER_BYTE (FP0_REGNUM + 1)],
c5aa993b
JM
1392 TYPE_LENGTH (valtype));
1393 else
1394 { /* float */
62700349 1395 memcpy (&dd, &regbuf[DEPRECATED_REGISTER_BYTE (FP0_REGNUM + 1)], 8);
c5aa993b
JM
1396 ff = (float) dd;
1397 memcpy (valbuf, &ff, sizeof (float));
1398 }
1399 }
ace1378a
EZ
1400 else if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
1401 && TYPE_LENGTH (valtype) == 16
1402 && TYPE_VECTOR (valtype))
1403 {
62700349 1404 memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (tdep->ppc_vr0_regnum + 2),
ace1378a
EZ
1405 TYPE_LENGTH (valtype));
1406 }
c5aa993b
JM
1407 else
1408 {
1409 /* return value is copied starting from r3. */
d7449b42 1410 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
12c266ea
AC
1411 && TYPE_LENGTH (valtype) < DEPRECATED_REGISTER_RAW_SIZE (3))
1412 offset = DEPRECATED_REGISTER_RAW_SIZE (3) - TYPE_LENGTH (valtype);
c5aa993b
JM
1413
1414 memcpy (valbuf,
62700349 1415 regbuf + DEPRECATED_REGISTER_BYTE (3) + offset,
c906108c 1416 TYPE_LENGTH (valtype));
c906108c 1417 }
c906108c
SS
1418}
1419
977adac5
ND
1420/* Return whether handle_inferior_event() should proceed through code
1421 starting at PC in function NAME when stepping.
1422
1423 The AIX -bbigtoc linker option generates functions @FIX0, @FIX1, etc. to
1424 handle memory references that are too distant to fit in instructions
1425 generated by the compiler. For example, if 'foo' in the following
1426 instruction:
1427
1428 lwz r9,foo(r2)
1429
1430 is greater than 32767, the linker might replace the lwz with a branch to
1431 somewhere in @FIX1 that does the load in 2 instructions and then branches
1432 back to where execution should continue.
1433
1434 GDB should silently step over @FIX code, just like AIX dbx does.
1435 Unfortunately, the linker uses the "b" instruction for the branches,
1436 meaning that the link register doesn't get set. Therefore, GDB's usual
1437 step_over_function() mechanism won't work.
1438
1439 Instead, use the IN_SOLIB_RETURN_TRAMPOLINE and SKIP_TRAMPOLINE_CODE hooks
1440 in handle_inferior_event() to skip past @FIX code. */
1441
1442int
1443rs6000_in_solib_return_trampoline (CORE_ADDR pc, char *name)
1444{
1445 return name && !strncmp (name, "@FIX", 4);
1446}
1447
1448/* Skip code that the user doesn't want to see when stepping:
1449
1450 1. Indirect function calls use a piece of trampoline code to do context
1451 switching, i.e. to set the new TOC table. Skip such code if we are on
1452 its first instruction (as when we have single-stepped to here).
1453
1454 2. Skip shared library trampoline code (which is different from
c906108c 1455 indirect function call trampolines).
977adac5
ND
1456
1457 3. Skip bigtoc fixup code.
1458
c906108c 1459 Result is desired PC to step until, or NULL if we are not in
977adac5 1460 code that should be skipped. */
c906108c
SS
1461
1462CORE_ADDR
7a78ae4e 1463rs6000_skip_trampoline_code (CORE_ADDR pc)
c906108c 1464{
52f0bd74 1465 unsigned int ii, op;
977adac5 1466 int rel;
c906108c 1467 CORE_ADDR solib_target_pc;
977adac5 1468 struct minimal_symbol *msymbol;
c906108c 1469
c5aa993b
JM
1470 static unsigned trampoline_code[] =
1471 {
1472 0x800b0000, /* l r0,0x0(r11) */
1473 0x90410014, /* st r2,0x14(r1) */
1474 0x7c0903a6, /* mtctr r0 */
1475 0x804b0004, /* l r2,0x4(r11) */
1476 0x816b0008, /* l r11,0x8(r11) */
1477 0x4e800420, /* bctr */
1478 0x4e800020, /* br */
1479 0
c906108c
SS
1480 };
1481
977adac5
ND
1482 /* Check for bigtoc fixup code. */
1483 msymbol = lookup_minimal_symbol_by_pc (pc);
22abf04a 1484 if (msymbol && rs6000_in_solib_return_trampoline (pc, DEPRECATED_SYMBOL_NAME (msymbol)))
977adac5
ND
1485 {
1486 /* Double-check that the third instruction from PC is relative "b". */
1487 op = read_memory_integer (pc + 8, 4);
1488 if ((op & 0xfc000003) == 0x48000000)
1489 {
1490 /* Extract bits 6-29 as a signed 24-bit relative word address and
1491 add it to the containing PC. */
1492 rel = ((int)(op << 6) >> 6);
1493 return pc + 8 + rel;
1494 }
1495 }
1496
c906108c
SS
1497 /* If pc is in a shared library trampoline, return its target. */
1498 solib_target_pc = find_solib_trampoline_target (pc);
1499 if (solib_target_pc)
1500 return solib_target_pc;
1501
c5aa993b
JM
1502 for (ii = 0; trampoline_code[ii]; ++ii)
1503 {
1504 op = read_memory_integer (pc + (ii * 4), 4);
1505 if (op != trampoline_code[ii])
1506 return 0;
1507 }
1508 ii = read_register (11); /* r11 holds destination addr */
21283beb 1509 pc = read_memory_addr (ii, gdbarch_tdep (current_gdbarch)->wordsize); /* (r11) value */
c906108c
SS
1510 return pc;
1511}
1512
1513/* Determines whether the function FI has a frame on the stack or not. */
1514
9aa1e687 1515int
c877c8e6 1516rs6000_frameless_function_invocation (struct frame_info *fi)
c906108c
SS
1517{
1518 CORE_ADDR func_start;
1519 struct rs6000_framedata fdata;
1520
1521 /* Don't even think about framelessness except on the innermost frame
1522 or if the function was interrupted by a signal. */
75e3c1f9
AC
1523 if (get_next_frame (fi) != NULL
1524 && !(get_frame_type (get_next_frame (fi)) == SIGTRAMP_FRAME))
c906108c 1525 return 0;
c5aa993b 1526
be41e9f4 1527 func_start = get_frame_func (fi);
c906108c
SS
1528
1529 /* If we failed to find the start of the function, it is a mistake
64366f1c 1530 to inspect the instructions. */
c906108c
SS
1531
1532 if (!func_start)
1533 {
1534 /* A frame with a zero PC is usually created by dereferencing a NULL
c5aa993b 1535 function pointer, normally causing an immediate core dump of the
64366f1c 1536 inferior. Mark function as frameless, as the inferior has no chance
c5aa993b 1537 of setting up a stack frame. */
bdd78e62 1538 if (get_frame_pc (fi) == 0)
c906108c
SS
1539 return 1;
1540 else
1541 return 0;
1542 }
1543
bdd78e62 1544 (void) skip_prologue (func_start, get_frame_pc (fi), &fdata);
c906108c
SS
1545 return fdata.frameless;
1546}
1547
64366f1c 1548/* Return the PC saved in a frame. */
c906108c 1549
9aa1e687 1550CORE_ADDR
c877c8e6 1551rs6000_frame_saved_pc (struct frame_info *fi)
c906108c
SS
1552{
1553 CORE_ADDR func_start;
1554 struct rs6000_framedata fdata;
21283beb 1555 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
a88376a3 1556 int wordsize = tdep->wordsize;
c906108c 1557
5a203e44 1558 if ((get_frame_type (fi) == SIGTRAMP_FRAME))
8b36eed8
AC
1559 return read_memory_addr (get_frame_base (fi) + SIG_FRAME_PC_OFFSET,
1560 wordsize);
c906108c 1561
bdd78e62 1562 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi),
8b36eed8
AC
1563 get_frame_base (fi),
1564 get_frame_base (fi)))
bdd78e62 1565 return deprecated_read_register_dummy (get_frame_pc (fi),
8b36eed8 1566 get_frame_base (fi), PC_REGNUM);
c906108c 1567
be41e9f4 1568 func_start = get_frame_func (fi);
c906108c
SS
1569
1570 /* If we failed to find the start of the function, it is a mistake
64366f1c 1571 to inspect the instructions. */
c906108c
SS
1572 if (!func_start)
1573 return 0;
1574
bdd78e62 1575 (void) skip_prologue (func_start, get_frame_pc (fi), &fdata);
c906108c 1576
75e3c1f9 1577 if (fdata.lr_offset == 0 && get_next_frame (fi) != NULL)
c906108c 1578 {
75e3c1f9 1579 if ((get_frame_type (get_next_frame (fi)) == SIGTRAMP_FRAME))
8b36eed8
AC
1580 return read_memory_addr ((get_frame_base (get_next_frame (fi))
1581 + SIG_FRAME_LR_OFFSET),
7a78ae4e 1582 wordsize);
bdd78e62 1583 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (get_next_frame (fi)), 0, 0))
8b69000d
AC
1584 /* The link register wasn't saved by this frame and the next
1585 (inner, newer) frame is a dummy. Get the link register
1586 value by unwinding it from that [dummy] frame. */
1587 {
1588 ULONGEST lr;
1589 frame_unwind_unsigned_register (get_next_frame (fi),
1590 tdep->ppc_lr_regnum, &lr);
1591 return lr;
1592 }
c906108c 1593 else
618ce49f
AC
1594 return read_memory_addr (DEPRECATED_FRAME_CHAIN (fi)
1595 + tdep->lr_frame_offset,
7a78ae4e 1596 wordsize);
c906108c
SS
1597 }
1598
1599 if (fdata.lr_offset == 0)
2188cbdd 1600 return read_register (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum);
c906108c 1601
618ce49f
AC
1602 return read_memory_addr (DEPRECATED_FRAME_CHAIN (fi) + fdata.lr_offset,
1603 wordsize);
c906108c
SS
1604}
1605
1606/* If saved registers of frame FI are not known yet, read and cache them.
1607 &FDATAP contains rs6000_framedata; TDATAP can be NULL,
1608 in which case the framedata are read. */
1609
1610static void
7a78ae4e 1611frame_get_saved_regs (struct frame_info *fi, struct rs6000_framedata *fdatap)
c906108c 1612{
c5aa993b 1613 CORE_ADDR frame_addr;
c906108c 1614 struct rs6000_framedata work_fdata;
6be8bc0c
EZ
1615 struct gdbarch_tdep * tdep = gdbarch_tdep (current_gdbarch);
1616 int wordsize = tdep->wordsize;
c906108c 1617
1b1d3794 1618 if (deprecated_get_frame_saved_regs (fi))
c906108c 1619 return;
c5aa993b 1620
c906108c
SS
1621 if (fdatap == NULL)
1622 {
1623 fdatap = &work_fdata;
be41e9f4 1624 (void) skip_prologue (get_frame_func (fi), get_frame_pc (fi), fdatap);
c906108c
SS
1625 }
1626
1627 frame_saved_regs_zalloc (fi);
1628
1629 /* If there were any saved registers, figure out parent's stack
64366f1c 1630 pointer. */
c906108c 1631 /* The following is true only if the frame doesn't have a call to
64366f1c 1632 alloca(), FIXME. */
c906108c 1633
6be8bc0c
EZ
1634 if (fdatap->saved_fpr == 0
1635 && fdatap->saved_gpr == 0
1636 && fdatap->saved_vr == 0
96ff0de4 1637 && fdatap->saved_ev == 0
6be8bc0c
EZ
1638 && fdatap->lr_offset == 0
1639 && fdatap->cr_offset == 0
96ff0de4
EZ
1640 && fdatap->vr_offset == 0
1641 && fdatap->ev_offset == 0)
c906108c 1642 frame_addr = 0;
c906108c 1643 else
bf75c8c1
AC
1644 /* NOTE: cagney/2002-04-14: The ->frame points to the inner-most
1645 address of the current frame. Things might be easier if the
1646 ->frame pointed to the outer-most address of the frame. In the
1647 mean time, the address of the prev frame is used as the base
1648 address of this frame. */
618ce49f 1649 frame_addr = DEPRECATED_FRAME_CHAIN (fi);
c5aa993b 1650
c906108c
SS
1651 /* if != -1, fdatap->saved_fpr is the smallest number of saved_fpr.
1652 All fpr's from saved_fpr to fp31 are saved. */
1653
1654 if (fdatap->saved_fpr >= 0)
1655 {
1656 int i;
7a78ae4e 1657 CORE_ADDR fpr_addr = frame_addr + fdatap->fpr_offset;
c906108c
SS
1658 for (i = fdatap->saved_fpr; i < 32; i++)
1659 {
1b1d3794 1660 deprecated_get_frame_saved_regs (fi)[FP0_REGNUM + i] = fpr_addr;
7a78ae4e 1661 fpr_addr += 8;
c906108c
SS
1662 }
1663 }
1664
1665 /* if != -1, fdatap->saved_gpr is the smallest number of saved_gpr.
1666 All gpr's from saved_gpr to gpr31 are saved. */
1667
1668 if (fdatap->saved_gpr >= 0)
1669 {
1670 int i;
7a78ae4e 1671 CORE_ADDR gpr_addr = frame_addr + fdatap->gpr_offset;
c906108c
SS
1672 for (i = fdatap->saved_gpr; i < 32; i++)
1673 {
1b1d3794 1674 deprecated_get_frame_saved_regs (fi)[tdep->ppc_gp0_regnum + i] = gpr_addr;
7a78ae4e 1675 gpr_addr += wordsize;
c906108c
SS
1676 }
1677 }
1678
6be8bc0c
EZ
1679 /* if != -1, fdatap->saved_vr is the smallest number of saved_vr.
1680 All vr's from saved_vr to vr31 are saved. */
1681 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
1682 {
1683 if (fdatap->saved_vr >= 0)
1684 {
1685 int i;
1686 CORE_ADDR vr_addr = frame_addr + fdatap->vr_offset;
1687 for (i = fdatap->saved_vr; i < 32; i++)
1688 {
1b1d3794 1689 deprecated_get_frame_saved_regs (fi)[tdep->ppc_vr0_regnum + i] = vr_addr;
12c266ea 1690 vr_addr += DEPRECATED_REGISTER_RAW_SIZE (tdep->ppc_vr0_regnum);
6be8bc0c
EZ
1691 }
1692 }
1693 }
1694
96ff0de4
EZ
1695 /* if != -1, fdatap->saved_ev is the smallest number of saved_ev.
1696 All vr's from saved_ev to ev31 are saved. ????? */
1697 if (tdep->ppc_ev0_regnum != -1 && tdep->ppc_ev31_regnum != -1)
1698 {
1699 if (fdatap->saved_ev >= 0)
1700 {
1701 int i;
1702 CORE_ADDR ev_addr = frame_addr + fdatap->ev_offset;
1703 for (i = fdatap->saved_ev; i < 32; i++)
1704 {
1b1d3794
AC
1705 deprecated_get_frame_saved_regs (fi)[tdep->ppc_ev0_regnum + i] = ev_addr;
1706 deprecated_get_frame_saved_regs (fi)[tdep->ppc_gp0_regnum + i] = ev_addr + 4;
12c266ea 1707 ev_addr += DEPRECATED_REGISTER_RAW_SIZE (tdep->ppc_ev0_regnum);
96ff0de4
EZ
1708 }
1709 }
1710 }
1711
c906108c
SS
1712 /* If != 0, fdatap->cr_offset is the offset from the frame that holds
1713 the CR. */
1714 if (fdatap->cr_offset != 0)
1b1d3794 1715 deprecated_get_frame_saved_regs (fi)[tdep->ppc_cr_regnum] = frame_addr + fdatap->cr_offset;
c906108c
SS
1716
1717 /* If != 0, fdatap->lr_offset is the offset from the frame that holds
1718 the LR. */
1719 if (fdatap->lr_offset != 0)
1b1d3794 1720 deprecated_get_frame_saved_regs (fi)[tdep->ppc_lr_regnum] = frame_addr + fdatap->lr_offset;
6be8bc0c
EZ
1721
1722 /* If != 0, fdatap->vrsave_offset is the offset from the frame that holds
1723 the VRSAVE. */
1724 if (fdatap->vrsave_offset != 0)
1b1d3794 1725 deprecated_get_frame_saved_regs (fi)[tdep->ppc_vrsave_regnum] = frame_addr + fdatap->vrsave_offset;
c906108c
SS
1726}
1727
1728/* Return the address of a frame. This is the inital %sp value when the frame
64366f1c
EZ
1729 was first allocated. For functions calling alloca(), it might be saved in
1730 an alloca register. */
c906108c
SS
1731
1732static CORE_ADDR
7a78ae4e 1733frame_initial_stack_address (struct frame_info *fi)
c906108c
SS
1734{
1735 CORE_ADDR tmpaddr;
1736 struct rs6000_framedata fdata;
1737 struct frame_info *callee_fi;
1738
64366f1c
EZ
1739 /* If the initial stack pointer (frame address) of this frame is known,
1740 just return it. */
c906108c 1741
c9012c71
AC
1742 if (get_frame_extra_info (fi)->initial_sp)
1743 return get_frame_extra_info (fi)->initial_sp;
c906108c 1744
64366f1c 1745 /* Find out if this function is using an alloca register. */
c906108c 1746
be41e9f4 1747 (void) skip_prologue (get_frame_func (fi), get_frame_pc (fi), &fdata);
c906108c 1748
64366f1c
EZ
1749 /* If saved registers of this frame are not known yet, read and
1750 cache them. */
c906108c 1751
1b1d3794 1752 if (!deprecated_get_frame_saved_regs (fi))
c906108c
SS
1753 frame_get_saved_regs (fi, &fdata);
1754
1755 /* If no alloca register used, then fi->frame is the value of the %sp for
64366f1c 1756 this frame, and it is good enough. */
c906108c
SS
1757
1758 if (fdata.alloca_reg < 0)
1759 {
c9012c71
AC
1760 get_frame_extra_info (fi)->initial_sp = get_frame_base (fi);
1761 return get_frame_extra_info (fi)->initial_sp;
c906108c
SS
1762 }
1763
953836b2
AC
1764 /* There is an alloca register, use its value, in the current frame,
1765 as the initial stack pointer. */
1766 {
d9d9c31f 1767 char tmpbuf[MAX_REGISTER_SIZE];
953836b2
AC
1768 if (frame_register_read (fi, fdata.alloca_reg, tmpbuf))
1769 {
c9012c71 1770 get_frame_extra_info (fi)->initial_sp
953836b2 1771 = extract_unsigned_integer (tmpbuf,
12c266ea 1772 DEPRECATED_REGISTER_RAW_SIZE (fdata.alloca_reg));
953836b2
AC
1773 }
1774 else
1775 /* NOTE: cagney/2002-04-17: At present the only time
1776 frame_register_read will fail is when the register isn't
1777 available. If that does happen, use the frame. */
c9012c71 1778 get_frame_extra_info (fi)->initial_sp = get_frame_base (fi);
953836b2 1779 }
c9012c71 1780 return get_frame_extra_info (fi)->initial_sp;
c906108c
SS
1781}
1782
7a78ae4e
ND
1783/* Describe the pointer in each stack frame to the previous stack frame
1784 (its caller). */
1785
618ce49f
AC
1786/* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and produces
1787 the frame's chain-pointer. */
7a78ae4e
ND
1788
1789/* In the case of the RS/6000, the frame's nominal address
1790 is the address of a 4-byte word containing the calling frame's address. */
1791
9aa1e687 1792CORE_ADDR
7a78ae4e 1793rs6000_frame_chain (struct frame_info *thisframe)
c906108c 1794{
7a78ae4e 1795 CORE_ADDR fp, fpp, lr;
21283beb 1796 int wordsize = gdbarch_tdep (current_gdbarch)->wordsize;
c906108c 1797
bdd78e62 1798 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (thisframe),
8b36eed8
AC
1799 get_frame_base (thisframe),
1800 get_frame_base (thisframe)))
9f3b7f07
AC
1801 /* A dummy frame always correctly chains back to the previous
1802 frame. */
8b36eed8 1803 return read_memory_addr (get_frame_base (thisframe), wordsize);
c906108c 1804
627b3ba2 1805 if (deprecated_inside_entry_file (get_frame_pc (thisframe))
bdd78e62 1806 || get_frame_pc (thisframe) == entry_point_address ())
c906108c
SS
1807 return 0;
1808
5a203e44 1809 if ((get_frame_type (thisframe) == SIGTRAMP_FRAME))
8b36eed8
AC
1810 fp = read_memory_addr (get_frame_base (thisframe) + SIG_FRAME_FP_OFFSET,
1811 wordsize);
75e3c1f9
AC
1812 else if (get_next_frame (thisframe) != NULL
1813 && (get_frame_type (get_next_frame (thisframe)) == SIGTRAMP_FRAME)
19772a2c
AC
1814 && (DEPRECATED_FRAMELESS_FUNCTION_INVOCATION_P ()
1815 && DEPRECATED_FRAMELESS_FUNCTION_INVOCATION (thisframe)))
c906108c
SS
1816 /* A frameless function interrupted by a signal did not change the
1817 frame pointer. */
c193f6ac 1818 fp = get_frame_base (thisframe);
c906108c 1819 else
8b36eed8 1820 fp = read_memory_addr (get_frame_base (thisframe), wordsize);
7a78ae4e
ND
1821 return fp;
1822}
1823
1824/* Return the size of register REG when words are WORDSIZE bytes long. If REG
64366f1c 1825 isn't available with that word size, return 0. */
7a78ae4e
ND
1826
1827static int
1828regsize (const struct reg *reg, int wordsize)
1829{
1830 return wordsize == 8 ? reg->sz64 : reg->sz32;
1831}
1832
1833/* Return the name of register number N, or null if no such register exists
64366f1c 1834 in the current architecture. */
7a78ae4e 1835
fa88f677 1836static const char *
7a78ae4e
ND
1837rs6000_register_name (int n)
1838{
21283beb 1839 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
7a78ae4e
ND
1840 const struct reg *reg = tdep->regs + n;
1841
1842 if (!regsize (reg, tdep->wordsize))
1843 return NULL;
1844 return reg->name;
1845}
1846
1847/* Index within `registers' of the first byte of the space for
1848 register N. */
1849
1850static int
1851rs6000_register_byte (int n)
1852{
21283beb 1853 return gdbarch_tdep (current_gdbarch)->regoff[n];
7a78ae4e
ND
1854}
1855
1856/* Return the number of bytes of storage in the actual machine representation
64366f1c 1857 for register N if that register is available, else return 0. */
7a78ae4e
ND
1858
1859static int
1860rs6000_register_raw_size (int n)
1861{
21283beb 1862 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
7a78ae4e
ND
1863 const struct reg *reg = tdep->regs + n;
1864 return regsize (reg, tdep->wordsize);
1865}
1866
7a78ae4e
ND
1867/* Return the GDB type object for the "standard" data type
1868 of data in register N. */
1869
1870static struct type *
fba45db2 1871rs6000_register_virtual_type (int n)
7a78ae4e 1872{
21283beb 1873 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
7a78ae4e
ND
1874 const struct reg *reg = tdep->regs + n;
1875
1fcc0bb8
EZ
1876 if (reg->fpr)
1877 return builtin_type_double;
1878 else
1879 {
1880 int size = regsize (reg, tdep->wordsize);
1881 switch (size)
1882 {
449a5da4
AC
1883 case 0:
1884 return builtin_type_int0;
1885 case 4:
ed6edd9b 1886 return builtin_type_uint32;
1fcc0bb8 1887 case 8:
c8001721
EZ
1888 if (tdep->ppc_ev0_regnum <= n && n <= tdep->ppc_ev31_regnum)
1889 return builtin_type_vec64;
1890 else
ed6edd9b 1891 return builtin_type_uint64;
1fcc0bb8
EZ
1892 break;
1893 case 16:
08cf96df 1894 return builtin_type_vec128;
1fcc0bb8
EZ
1895 break;
1896 default:
449a5da4
AC
1897 internal_error (__FILE__, __LINE__, "Register %d size %d unknown",
1898 n, size);
1fcc0bb8
EZ
1899 }
1900 }
7a78ae4e
ND
1901}
1902
7a78ae4e
ND
1903/* Return whether register N requires conversion when moving from raw format
1904 to virtual format.
1905
1906 The register format for RS/6000 floating point registers is always
64366f1c 1907 double, we need a conversion if the memory format is float. */
7a78ae4e
ND
1908
1909static int
1910rs6000_register_convertible (int n)
1911{
21283beb 1912 const struct reg *reg = gdbarch_tdep (current_gdbarch)->regs + n;
7a78ae4e
ND
1913 return reg->fpr;
1914}
1915
1916/* Convert data from raw format for register N in buffer FROM
64366f1c 1917 to virtual format with type TYPE in buffer TO. */
7a78ae4e
ND
1918
1919static void
1920rs6000_register_convert_to_virtual (int n, struct type *type,
1921 char *from, char *to)
1922{
12c266ea 1923 if (TYPE_LENGTH (type) != DEPRECATED_REGISTER_RAW_SIZE (n))
7a292a7a 1924 {
12c266ea 1925 double val = deprecated_extract_floating (from, DEPRECATED_REGISTER_RAW_SIZE (n));
f1908289 1926 deprecated_store_floating (to, TYPE_LENGTH (type), val);
7a78ae4e
ND
1927 }
1928 else
12c266ea 1929 memcpy (to, from, DEPRECATED_REGISTER_RAW_SIZE (n));
7a78ae4e
ND
1930}
1931
1932/* Convert data from virtual format with type TYPE in buffer FROM
64366f1c 1933 to raw format for register N in buffer TO. */
7a292a7a 1934
7a78ae4e
ND
1935static void
1936rs6000_register_convert_to_raw (struct type *type, int n,
781a750d 1937 const char *from, char *to)
7a78ae4e 1938{
12c266ea 1939 if (TYPE_LENGTH (type) != DEPRECATED_REGISTER_RAW_SIZE (n))
7a78ae4e 1940 {
f1908289 1941 double val = deprecated_extract_floating (from, TYPE_LENGTH (type));
12c266ea 1942 deprecated_store_floating (to, DEPRECATED_REGISTER_RAW_SIZE (n), val);
7a292a7a 1943 }
7a78ae4e 1944 else
12c266ea 1945 memcpy (to, from, DEPRECATED_REGISTER_RAW_SIZE (n));
7a78ae4e 1946}
c906108c 1947
c8001721
EZ
1948static void
1949e500_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
1950 int reg_nr, void *buffer)
1951{
1952 int base_regnum;
1953 int offset = 0;
d9d9c31f 1954 char temp_buffer[MAX_REGISTER_SIZE];
c8001721
EZ
1955 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1956
1957 if (reg_nr >= tdep->ppc_gp0_regnum
1958 && reg_nr <= tdep->ppc_gplast_regnum)
1959 {
1960 base_regnum = reg_nr - tdep->ppc_gp0_regnum + tdep->ppc_ev0_regnum;
1961
1962 /* Build the value in the provided buffer. */
1963 /* Read the raw register of which this one is the lower portion. */
1964 regcache_raw_read (regcache, base_regnum, temp_buffer);
1965 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1966 offset = 4;
1967 memcpy ((char *) buffer, temp_buffer + offset, 4);
1968 }
1969}
1970
1971static void
1972e500_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
1973 int reg_nr, const void *buffer)
1974{
1975 int base_regnum;
1976 int offset = 0;
d9d9c31f 1977 char temp_buffer[MAX_REGISTER_SIZE];
c8001721
EZ
1978 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1979
1980 if (reg_nr >= tdep->ppc_gp0_regnum
1981 && reg_nr <= tdep->ppc_gplast_regnum)
1982 {
1983 base_regnum = reg_nr - tdep->ppc_gp0_regnum + tdep->ppc_ev0_regnum;
1984 /* reg_nr is 32 bit here, and base_regnum is 64 bits. */
1985 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1986 offset = 4;
1987
1988 /* Let's read the value of the base register into a temporary
1989 buffer, so that overwriting the last four bytes with the new
1990 value of the pseudo will leave the upper 4 bytes unchanged. */
1991 regcache_raw_read (regcache, base_regnum, temp_buffer);
1992
1993 /* Write as an 8 byte quantity. */
1994 memcpy (temp_buffer + offset, (char *) buffer, 4);
1995 regcache_raw_write (regcache, base_regnum, temp_buffer);
1996 }
1997}
1998
1999/* Convert a dwarf2 register number to a gdb REGNUM. */
2000static int
2001e500_dwarf2_reg_to_regnum (int num)
2002{
2003 int regnum;
2004 if (0 <= num && num <= 31)
2005 return num + gdbarch_tdep (current_gdbarch)->ppc_gp0_regnum;
2006 else
2007 return num;
2008}
2009
2188cbdd 2010/* Convert a dbx stab register number (from `r' declaration) to a gdb
64366f1c 2011 REGNUM. */
2188cbdd
EZ
2012static int
2013rs6000_stab_reg_to_regnum (int num)
2014{
2015 int regnum;
2016 switch (num)
2017 {
2018 case 64:
2019 regnum = gdbarch_tdep (current_gdbarch)->ppc_mq_regnum;
2020 break;
2021 case 65:
2022 regnum = gdbarch_tdep (current_gdbarch)->ppc_lr_regnum;
2023 break;
2024 case 66:
2025 regnum = gdbarch_tdep (current_gdbarch)->ppc_ctr_regnum;
2026 break;
2027 case 76:
2028 regnum = gdbarch_tdep (current_gdbarch)->ppc_xer_regnum;
2029 break;
2030 default:
2031 regnum = num;
2032 break;
2033 }
2034 return regnum;
2035}
2036
7a78ae4e
ND
2037static void
2038rs6000_store_return_value (struct type *type, char *valbuf)
2039{
ace1378a
EZ
2040 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2041
7a78ae4e
ND
2042 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2043
2044 /* Floating point values are returned starting from FPR1 and up.
2045 Say a double_double_double type could be returned in
64366f1c 2046 FPR1/FPR2/FPR3 triple. */
7a78ae4e 2047
62700349 2048 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (FP0_REGNUM + 1), valbuf,
73937e03 2049 TYPE_LENGTH (type));
ace1378a
EZ
2050 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
2051 {
2052 if (TYPE_LENGTH (type) == 16
2053 && TYPE_VECTOR (type))
62700349 2054 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (tdep->ppc_vr0_regnum + 2),
73937e03 2055 valbuf, TYPE_LENGTH (type));
ace1378a 2056 }
7a78ae4e 2057 else
64366f1c 2058 /* Everything else is returned in GPR3 and up. */
62700349 2059 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (gdbarch_tdep (current_gdbarch)->ppc_gp0_regnum + 3),
73937e03 2060 valbuf, TYPE_LENGTH (type));
7a78ae4e
ND
2061}
2062
2063/* Extract from an array REGBUF containing the (raw) register state
2064 the address in which a function should return its structure value,
2065 as a CORE_ADDR (or an expression that can be used as one). */
2066
2067static CORE_ADDR
11269d7e
AC
2068rs6000_extract_struct_value_address (struct regcache *regcache)
2069{
2070 /* FIXME: cagney/2002-09-26: PR gdb/724: When making an inferior
2071 function call GDB knows the address of the struct return value
2072 and hence, should not need to call this function. Unfortunately,
e8a8712a
AC
2073 the current call_function_by_hand() code only saves the most
2074 recent struct address leading to occasional calls. The code
2075 should instead maintain a stack of such addresses (in the dummy
2076 frame object). */
11269d7e
AC
2077 /* NOTE: cagney/2002-09-26: Return 0 which indicates that we've
2078 really got no idea where the return value is being stored. While
2079 r3, on function entry, contained the address it will have since
2080 been reused (scratch) and hence wouldn't be valid */
2081 return 0;
7a78ae4e
ND
2082}
2083
64366f1c 2084/* Hook called when a new child process is started. */
7a78ae4e
ND
2085
2086void
2087rs6000_create_inferior (int pid)
2088{
2089 if (rs6000_set_host_arch_hook)
2090 rs6000_set_host_arch_hook (pid);
c906108c
SS
2091}
2092\f
e2d0e7eb 2093/* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
7a78ae4e
ND
2094
2095 Usually a function pointer's representation is simply the address
2096 of the function. On the RS/6000 however, a function pointer is
2097 represented by a pointer to a TOC entry. This TOC entry contains
2098 three words, the first word is the address of the function, the
2099 second word is the TOC pointer (r2), and the third word is the
2100 static chain value. Throughout GDB it is currently assumed that a
2101 function pointer contains the address of the function, which is not
2102 easy to fix. In addition, the conversion of a function address to
2103 a function pointer would require allocation of a TOC entry in the
2104 inferior's memory space, with all its drawbacks. To be able to
2105 call C++ virtual methods in the inferior (which are called via
f517ea4e 2106 function pointers), find_function_addr uses this function to get the
7a78ae4e
ND
2107 function address from a function pointer. */
2108
f517ea4e
PS
2109/* Return real function address if ADDR (a function pointer) is in the data
2110 space and is therefore a special function pointer. */
c906108c 2111
b9362cc7 2112static CORE_ADDR
e2d0e7eb
AC
2113rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
2114 CORE_ADDR addr,
2115 struct target_ops *targ)
c906108c
SS
2116{
2117 struct obj_section *s;
2118
2119 s = find_pc_section (addr);
2120 if (s && s->the_bfd_section->flags & SEC_CODE)
7a78ae4e 2121 return addr;
c906108c 2122
7a78ae4e 2123 /* ADDR is in the data space, so it's a special function pointer. */
21283beb 2124 return read_memory_addr (addr, gdbarch_tdep (current_gdbarch)->wordsize);
c906108c 2125}
c906108c 2126\f
c5aa993b 2127
7a78ae4e 2128/* Handling the various POWER/PowerPC variants. */
c906108c
SS
2129
2130
7a78ae4e
ND
2131/* The arrays here called registers_MUMBLE hold information about available
2132 registers.
c906108c
SS
2133
2134 For each family of PPC variants, I've tried to isolate out the
2135 common registers and put them up front, so that as long as you get
2136 the general family right, GDB will correctly identify the registers
2137 common to that family. The common register sets are:
2138
2139 For the 60x family: hid0 hid1 iabr dabr pir
2140
2141 For the 505 and 860 family: eie eid nri
2142
2143 For the 403 and 403GC: icdbdr esr dear evpr cdbcr tsr tcr pit tbhi
c5aa993b
JM
2144 tblo srr2 srr3 dbsr dbcr iac1 iac2 dac1 dac2 dccr iccr pbl1
2145 pbu1 pbl2 pbu2
c906108c
SS
2146
2147 Most of these register groups aren't anything formal. I arrived at
2148 them by looking at the registers that occurred in more than one
6f5987a6
KB
2149 processor.
2150
2151 Note: kevinb/2002-04-30: Support for the fpscr register was added
2152 during April, 2002. Slot 70 is being used for PowerPC and slot 71
2153 for Power. For PowerPC, slot 70 was unused and was already in the
2154 PPC_UISA_SPRS which is ideally where fpscr should go. For Power,
2155 slot 70 was being used for "mq", so the next available slot (71)
2156 was chosen. It would have been nice to be able to make the
2157 register numbers the same across processor cores, but this wasn't
2158 possible without either 1) renumbering some registers for some
2159 processors or 2) assigning fpscr to a really high slot that's
2160 larger than any current register number. Doing (1) is bad because
2161 existing stubs would break. Doing (2) is undesirable because it
2162 would introduce a really large gap between fpscr and the rest of
2163 the registers for most processors. */
7a78ae4e 2164
64366f1c 2165/* Convenience macros for populating register arrays. */
7a78ae4e 2166
64366f1c 2167/* Within another macro, convert S to a string. */
7a78ae4e
ND
2168
2169#define STR(s) #s
2170
2171/* Return a struct reg defining register NAME that's 32 bits on 32-bit systems
64366f1c 2172 and 64 bits on 64-bit systems. */
489461e2 2173#define R(name) { STR(name), 4, 8, 0, 0 }
7a78ae4e
ND
2174
2175/* Return a struct reg defining register NAME that's 32 bits on all
64366f1c 2176 systems. */
489461e2 2177#define R4(name) { STR(name), 4, 4, 0, 0 }
7a78ae4e
ND
2178
2179/* Return a struct reg defining register NAME that's 64 bits on all
64366f1c 2180 systems. */
489461e2 2181#define R8(name) { STR(name), 8, 8, 0, 0 }
7a78ae4e 2182
1fcc0bb8 2183/* Return a struct reg defining register NAME that's 128 bits on all
64366f1c 2184 systems. */
489461e2 2185#define R16(name) { STR(name), 16, 16, 0, 0 }
1fcc0bb8 2186
64366f1c 2187/* Return a struct reg defining floating-point register NAME. */
489461e2
EZ
2188#define F(name) { STR(name), 8, 8, 1, 0 }
2189
64366f1c 2190/* Return a struct reg defining a pseudo register NAME. */
489461e2 2191#define P(name) { STR(name), 4, 8, 0, 1}
7a78ae4e
ND
2192
2193/* Return a struct reg defining register NAME that's 32 bits on 32-bit
64366f1c 2194 systems and that doesn't exist on 64-bit systems. */
489461e2 2195#define R32(name) { STR(name), 4, 0, 0, 0 }
7a78ae4e
ND
2196
2197/* Return a struct reg defining register NAME that's 64 bits on 64-bit
64366f1c 2198 systems and that doesn't exist on 32-bit systems. */
489461e2 2199#define R64(name) { STR(name), 0, 8, 0, 0 }
7a78ae4e 2200
64366f1c 2201/* Return a struct reg placeholder for a register that doesn't exist. */
489461e2 2202#define R0 { 0, 0, 0, 0, 0 }
7a78ae4e
ND
2203
2204/* UISA registers common across all architectures, including POWER. */
2205
2206#define COMMON_UISA_REGS \
2207 /* 0 */ R(r0), R(r1), R(r2), R(r3), R(r4), R(r5), R(r6), R(r7), \
2208 /* 8 */ R(r8), R(r9), R(r10),R(r11),R(r12),R(r13),R(r14),R(r15), \
2209 /* 16 */ R(r16),R(r17),R(r18),R(r19),R(r20),R(r21),R(r22),R(r23), \
2210 /* 24 */ R(r24),R(r25),R(r26),R(r27),R(r28),R(r29),R(r30),R(r31), \
2211 /* 32 */ F(f0), F(f1), F(f2), F(f3), F(f4), F(f5), F(f6), F(f7), \
2212 /* 40 */ F(f8), F(f9), F(f10),F(f11),F(f12),F(f13),F(f14),F(f15), \
2213 /* 48 */ F(f16),F(f17),F(f18),F(f19),F(f20),F(f21),F(f22),F(f23), \
2214 /* 56 */ F(f24),F(f25),F(f26),F(f27),F(f28),F(f29),F(f30),F(f31), \
2215 /* 64 */ R(pc), R(ps)
2216
ebeac11a
EZ
2217#define COMMON_UISA_NOFP_REGS \
2218 /* 0 */ R(r0), R(r1), R(r2), R(r3), R(r4), R(r5), R(r6), R(r7), \
2219 /* 8 */ R(r8), R(r9), R(r10),R(r11),R(r12),R(r13),R(r14),R(r15), \
2220 /* 16 */ R(r16),R(r17),R(r18),R(r19),R(r20),R(r21),R(r22),R(r23), \
2221 /* 24 */ R(r24),R(r25),R(r26),R(r27),R(r28),R(r29),R(r30),R(r31), \
2222 /* 32 */ R0, R0, R0, R0, R0, R0, R0, R0, \
2223 /* 40 */ R0, R0, R0, R0, R0, R0, R0, R0, \
2224 /* 48 */ R0, R0, R0, R0, R0, R0, R0, R0, \
2225 /* 56 */ R0, R0, R0, R0, R0, R0, R0, R0, \
2226 /* 64 */ R(pc), R(ps)
2227
7a78ae4e
ND
2228/* UISA-level SPRs for PowerPC. */
2229#define PPC_UISA_SPRS \
e3f36dbd 2230 /* 66 */ R4(cr), R(lr), R(ctr), R4(xer), R4(fpscr)
7a78ae4e 2231
c8001721
EZ
2232/* UISA-level SPRs for PowerPC without floating point support. */
2233#define PPC_UISA_NOFP_SPRS \
2234 /* 66 */ R4(cr), R(lr), R(ctr), R4(xer), R0
2235
7a78ae4e
ND
2236/* Segment registers, for PowerPC. */
2237#define PPC_SEGMENT_REGS \
2238 /* 71 */ R32(sr0), R32(sr1), R32(sr2), R32(sr3), \
2239 /* 75 */ R32(sr4), R32(sr5), R32(sr6), R32(sr7), \
2240 /* 79 */ R32(sr8), R32(sr9), R32(sr10), R32(sr11), \
2241 /* 83 */ R32(sr12), R32(sr13), R32(sr14), R32(sr15)
2242
2243/* OEA SPRs for PowerPC. */
2244#define PPC_OEA_SPRS \
2245 /* 87 */ R4(pvr), \
2246 /* 88 */ R(ibat0u), R(ibat0l), R(ibat1u), R(ibat1l), \
2247 /* 92 */ R(ibat2u), R(ibat2l), R(ibat3u), R(ibat3l), \
2248 /* 96 */ R(dbat0u), R(dbat0l), R(dbat1u), R(dbat1l), \
2249 /* 100 */ R(dbat2u), R(dbat2l), R(dbat3u), R(dbat3l), \
2250 /* 104 */ R(sdr1), R64(asr), R(dar), R4(dsisr), \
2251 /* 108 */ R(sprg0), R(sprg1), R(sprg2), R(sprg3), \
2252 /* 112 */ R(srr0), R(srr1), R(tbl), R(tbu), \
2253 /* 116 */ R4(dec), R(dabr), R4(ear)
2254
64366f1c 2255/* AltiVec registers. */
1fcc0bb8
EZ
2256#define PPC_ALTIVEC_REGS \
2257 /*119*/R16(vr0), R16(vr1), R16(vr2), R16(vr3), R16(vr4), R16(vr5), R16(vr6), R16(vr7), \
2258 /*127*/R16(vr8), R16(vr9), R16(vr10),R16(vr11),R16(vr12),R16(vr13),R16(vr14),R16(vr15), \
2259 /*135*/R16(vr16),R16(vr17),R16(vr18),R16(vr19),R16(vr20),R16(vr21),R16(vr22),R16(vr23), \
2260 /*143*/R16(vr24),R16(vr25),R16(vr26),R16(vr27),R16(vr28),R16(vr29),R16(vr30),R16(vr31), \
2261 /*151*/R4(vscr), R4(vrsave)
2262
c8001721
EZ
2263/* Vectors of hi-lo general purpose registers. */
2264#define PPC_EV_REGS \
2265 /* 0*/R8(ev0), R8(ev1), R8(ev2), R8(ev3), R8(ev4), R8(ev5), R8(ev6), R8(ev7), \
2266 /* 8*/R8(ev8), R8(ev9), R8(ev10),R8(ev11),R8(ev12),R8(ev13),R8(ev14),R8(ev15), \
2267 /*16*/R8(ev16),R8(ev17),R8(ev18),R8(ev19),R8(ev20),R8(ev21),R8(ev22),R8(ev23), \
2268 /*24*/R8(ev24),R8(ev25),R8(ev26),R8(ev27),R8(ev28),R8(ev29),R8(ev30),R8(ev31)
2269
2270/* Lower half of the EV registers. */
2271#define PPC_GPRS_PSEUDO_REGS \
2272 /* 0 */ P(r0), P(r1), P(r2), P(r3), P(r4), P(r5), P(r6), P(r7), \
2273 /* 8 */ P(r8), P(r9), P(r10),P(r11),P(r12),P(r13),P(r14),P(r15), \
2274 /* 16 */ P(r16),P(r17),P(r18),P(r19),P(r20),P(r21),P(r22),P(r23), \
338ef23d 2275 /* 24 */ P(r24),P(r25),P(r26),P(r27),P(r28),P(r29),P(r30),P(r31)
c8001721 2276
7a78ae4e 2277/* IBM POWER (pre-PowerPC) architecture, user-level view. We only cover
64366f1c 2278 user-level SPR's. */
7a78ae4e 2279static const struct reg registers_power[] =
c906108c 2280{
7a78ae4e 2281 COMMON_UISA_REGS,
e3f36dbd
KB
2282 /* 66 */ R4(cnd), R(lr), R(cnt), R4(xer), R4(mq),
2283 /* 71 */ R4(fpscr)
c906108c
SS
2284};
2285
7a78ae4e 2286/* PowerPC UISA - a PPC processor as viewed by user-level code. A UISA-only
64366f1c 2287 view of the PowerPC. */
7a78ae4e 2288static const struct reg registers_powerpc[] =
c906108c 2289{
7a78ae4e 2290 COMMON_UISA_REGS,
1fcc0bb8
EZ
2291 PPC_UISA_SPRS,
2292 PPC_ALTIVEC_REGS
c906108c
SS
2293};
2294
ebeac11a
EZ
2295/* PowerPC UISA - a PPC processor as viewed by user-level
2296 code, but without floating point registers. */
2297static const struct reg registers_powerpc_nofp[] =
2298{
2299 COMMON_UISA_NOFP_REGS,
2300 PPC_UISA_SPRS
2301};
2302
64366f1c 2303/* IBM PowerPC 403. */
7a78ae4e 2304static const struct reg registers_403[] =
c5aa993b 2305{
7a78ae4e
ND
2306 COMMON_UISA_REGS,
2307 PPC_UISA_SPRS,
2308 PPC_SEGMENT_REGS,
2309 PPC_OEA_SPRS,
2310 /* 119 */ R(icdbdr), R(esr), R(dear), R(evpr),
2311 /* 123 */ R(cdbcr), R(tsr), R(tcr), R(pit),
2312 /* 127 */ R(tbhi), R(tblo), R(srr2), R(srr3),
2313 /* 131 */ R(dbsr), R(dbcr), R(iac1), R(iac2),
2314 /* 135 */ R(dac1), R(dac2), R(dccr), R(iccr),
2315 /* 139 */ R(pbl1), R(pbu1), R(pbl2), R(pbu2)
c906108c
SS
2316};
2317
64366f1c 2318/* IBM PowerPC 403GC. */
7a78ae4e 2319static const struct reg registers_403GC[] =
c5aa993b 2320{
7a78ae4e
ND
2321 COMMON_UISA_REGS,
2322 PPC_UISA_SPRS,
2323 PPC_SEGMENT_REGS,
2324 PPC_OEA_SPRS,
2325 /* 119 */ R(icdbdr), R(esr), R(dear), R(evpr),
2326 /* 123 */ R(cdbcr), R(tsr), R(tcr), R(pit),
2327 /* 127 */ R(tbhi), R(tblo), R(srr2), R(srr3),
2328 /* 131 */ R(dbsr), R(dbcr), R(iac1), R(iac2),
2329 /* 135 */ R(dac1), R(dac2), R(dccr), R(iccr),
2330 /* 139 */ R(pbl1), R(pbu1), R(pbl2), R(pbu2),
2331 /* 143 */ R(zpr), R(pid), R(sgr), R(dcwr),
2332 /* 147 */ R(tbhu), R(tblu)
c906108c
SS
2333};
2334
64366f1c 2335/* Motorola PowerPC 505. */
7a78ae4e 2336static const struct reg registers_505[] =
c5aa993b 2337{
7a78ae4e
ND
2338 COMMON_UISA_REGS,
2339 PPC_UISA_SPRS,
2340 PPC_SEGMENT_REGS,
2341 PPC_OEA_SPRS,
2342 /* 119 */ R(eie), R(eid), R(nri)
c906108c
SS
2343};
2344
64366f1c 2345/* Motorola PowerPC 860 or 850. */
7a78ae4e 2346static const struct reg registers_860[] =
c5aa993b 2347{
7a78ae4e
ND
2348 COMMON_UISA_REGS,
2349 PPC_UISA_SPRS,
2350 PPC_SEGMENT_REGS,
2351 PPC_OEA_SPRS,
2352 /* 119 */ R(eie), R(eid), R(nri), R(cmpa),
2353 /* 123 */ R(cmpb), R(cmpc), R(cmpd), R(icr),
2354 /* 127 */ R(der), R(counta), R(countb), R(cmpe),
2355 /* 131 */ R(cmpf), R(cmpg), R(cmph), R(lctrl1),
2356 /* 135 */ R(lctrl2), R(ictrl), R(bar), R(ic_cst),
2357 /* 139 */ R(ic_adr), R(ic_dat), R(dc_cst), R(dc_adr),
2358 /* 143 */ R(dc_dat), R(dpdr), R(dpir), R(immr),
2359 /* 147 */ R(mi_ctr), R(mi_ap), R(mi_epn), R(mi_twc),
2360 /* 151 */ R(mi_rpn), R(md_ctr), R(m_casid), R(md_ap),
2361 /* 155 */ R(md_epn), R(md_twb), R(md_twc), R(md_rpn),
2362 /* 159 */ R(m_tw), R(mi_dbcam), R(mi_dbram0), R(mi_dbram1),
2363 /* 163 */ R(md_dbcam), R(md_dbram0), R(md_dbram1)
c906108c
SS
2364};
2365
7a78ae4e
ND
2366/* Motorola PowerPC 601. Note that the 601 has different register numbers
2367 for reading and writing RTCU and RTCL. However, how one reads and writes a
c906108c 2368 register is the stub's problem. */
7a78ae4e 2369static const struct reg registers_601[] =
c5aa993b 2370{
7a78ae4e
ND
2371 COMMON_UISA_REGS,
2372 PPC_UISA_SPRS,
2373 PPC_SEGMENT_REGS,
2374 PPC_OEA_SPRS,
2375 /* 119 */ R(hid0), R(hid1), R(iabr), R(dabr),
2376 /* 123 */ R(pir), R(mq), R(rtcu), R(rtcl)
c906108c
SS
2377};
2378
64366f1c 2379/* Motorola PowerPC 602. */
7a78ae4e 2380static const struct reg registers_602[] =
c5aa993b 2381{
7a78ae4e
ND
2382 COMMON_UISA_REGS,
2383 PPC_UISA_SPRS,
2384 PPC_SEGMENT_REGS,
2385 PPC_OEA_SPRS,
2386 /* 119 */ R(hid0), R(hid1), R(iabr), R0,
2387 /* 123 */ R0, R(tcr), R(ibr), R(esassr),
2388 /* 127 */ R(sebr), R(ser), R(sp), R(lt)
c906108c
SS
2389};
2390
64366f1c 2391/* Motorola/IBM PowerPC 603 or 603e. */
7a78ae4e 2392static const struct reg registers_603[] =
c5aa993b 2393{
7a78ae4e
ND
2394 COMMON_UISA_REGS,
2395 PPC_UISA_SPRS,
2396 PPC_SEGMENT_REGS,
2397 PPC_OEA_SPRS,
2398 /* 119 */ R(hid0), R(hid1), R(iabr), R0,
2399 /* 123 */ R0, R(dmiss), R(dcmp), R(hash1),
2400 /* 127 */ R(hash2), R(imiss), R(icmp), R(rpa)
c906108c
SS
2401};
2402
64366f1c 2403/* Motorola PowerPC 604 or 604e. */
7a78ae4e 2404static const struct reg registers_604[] =
c5aa993b 2405{
7a78ae4e
ND
2406 COMMON_UISA_REGS,
2407 PPC_UISA_SPRS,
2408 PPC_SEGMENT_REGS,
2409 PPC_OEA_SPRS,
2410 /* 119 */ R(hid0), R(hid1), R(iabr), R(dabr),
2411 /* 123 */ R(pir), R(mmcr0), R(pmc1), R(pmc2),
2412 /* 127 */ R(sia), R(sda)
c906108c
SS
2413};
2414
64366f1c 2415/* Motorola/IBM PowerPC 750 or 740. */
7a78ae4e 2416static const struct reg registers_750[] =
c5aa993b 2417{
7a78ae4e
ND
2418 COMMON_UISA_REGS,
2419 PPC_UISA_SPRS,
2420 PPC_SEGMENT_REGS,
2421 PPC_OEA_SPRS,
2422 /* 119 */ R(hid0), R(hid1), R(iabr), R(dabr),
2423 /* 123 */ R0, R(ummcr0), R(upmc1), R(upmc2),
2424 /* 127 */ R(usia), R(ummcr1), R(upmc3), R(upmc4),
2425 /* 131 */ R(mmcr0), R(pmc1), R(pmc2), R(sia),
2426 /* 135 */ R(mmcr1), R(pmc3), R(pmc4), R(l2cr),
2427 /* 139 */ R(ictc), R(thrm1), R(thrm2), R(thrm3)
c906108c
SS
2428};
2429
2430
64366f1c 2431/* Motorola PowerPC 7400. */
1fcc0bb8
EZ
2432static const struct reg registers_7400[] =
2433{
2434 /* gpr0-gpr31, fpr0-fpr31 */
2435 COMMON_UISA_REGS,
2436 /* ctr, xre, lr, cr */
2437 PPC_UISA_SPRS,
2438 /* sr0-sr15 */
2439 PPC_SEGMENT_REGS,
2440 PPC_OEA_SPRS,
2441 /* vr0-vr31, vrsave, vscr */
2442 PPC_ALTIVEC_REGS
2443 /* FIXME? Add more registers? */
2444};
2445
c8001721
EZ
2446/* Motorola e500. */
2447static const struct reg registers_e500[] =
2448{
2449 R(pc), R(ps),
2450 /* cr, lr, ctr, xer, "" */
2451 PPC_UISA_NOFP_SPRS,
2452 /* 7...38 */
2453 PPC_EV_REGS,
338ef23d
AC
2454 R8(acc), R(spefscr),
2455 /* NOTE: Add new registers here the end of the raw register
2456 list and just before the first pseudo register. */
c8001721
EZ
2457 /* 39...70 */
2458 PPC_GPRS_PSEUDO_REGS
2459};
2460
c906108c 2461/* Information about a particular processor variant. */
7a78ae4e 2462
c906108c 2463struct variant
c5aa993b
JM
2464 {
2465 /* Name of this variant. */
2466 char *name;
c906108c 2467
c5aa993b
JM
2468 /* English description of the variant. */
2469 char *description;
c906108c 2470
64366f1c 2471 /* bfd_arch_info.arch corresponding to variant. */
7a78ae4e
ND
2472 enum bfd_architecture arch;
2473
64366f1c 2474 /* bfd_arch_info.mach corresponding to variant. */
7a78ae4e
ND
2475 unsigned long mach;
2476
489461e2
EZ
2477 /* Number of real registers. */
2478 int nregs;
2479
2480 /* Number of pseudo registers. */
2481 int npregs;
2482
2483 /* Number of total registers (the sum of nregs and npregs). */
2484 int num_tot_regs;
2485
c5aa993b
JM
2486 /* Table of register names; registers[R] is the name of the register
2487 number R. */
7a78ae4e 2488 const struct reg *regs;
c5aa993b 2489 };
c906108c 2490
489461e2
EZ
2491#define tot_num_registers(list) (sizeof (list) / sizeof((list)[0]))
2492
2493static int
2494num_registers (const struct reg *reg_list, int num_tot_regs)
2495{
2496 int i;
2497 int nregs = 0;
2498
2499 for (i = 0; i < num_tot_regs; i++)
2500 if (!reg_list[i].pseudo)
2501 nregs++;
2502
2503 return nregs;
2504}
2505
2506static int
2507num_pseudo_registers (const struct reg *reg_list, int num_tot_regs)
2508{
2509 int i;
2510 int npregs = 0;
2511
2512 for (i = 0; i < num_tot_regs; i++)
2513 if (reg_list[i].pseudo)
2514 npregs ++;
2515
2516 return npregs;
2517}
c906108c 2518
c906108c
SS
2519/* Information in this table comes from the following web sites:
2520 IBM: http://www.chips.ibm.com:80/products/embedded/
2521 Motorola: http://www.mot.com/SPS/PowerPC/
2522
2523 I'm sure I've got some of the variant descriptions not quite right.
2524 Please report any inaccuracies you find to GDB's maintainer.
2525
2526 If you add entries to this table, please be sure to allow the new
2527 value as an argument to the --with-cpu flag, in configure.in. */
2528
489461e2 2529static struct variant variants[] =
c906108c 2530{
489461e2 2531
7a78ae4e 2532 {"powerpc", "PowerPC user-level", bfd_arch_powerpc,
489461e2
EZ
2533 bfd_mach_ppc, -1, -1, tot_num_registers (registers_powerpc),
2534 registers_powerpc},
7a78ae4e 2535 {"power", "POWER user-level", bfd_arch_rs6000,
489461e2
EZ
2536 bfd_mach_rs6k, -1, -1, tot_num_registers (registers_power),
2537 registers_power},
7a78ae4e 2538 {"403", "IBM PowerPC 403", bfd_arch_powerpc,
489461e2
EZ
2539 bfd_mach_ppc_403, -1, -1, tot_num_registers (registers_403),
2540 registers_403},
7a78ae4e 2541 {"601", "Motorola PowerPC 601", bfd_arch_powerpc,
489461e2
EZ
2542 bfd_mach_ppc_601, -1, -1, tot_num_registers (registers_601),
2543 registers_601},
7a78ae4e 2544 {"602", "Motorola PowerPC 602", bfd_arch_powerpc,
489461e2
EZ
2545 bfd_mach_ppc_602, -1, -1, tot_num_registers (registers_602),
2546 registers_602},
7a78ae4e 2547 {"603", "Motorola/IBM PowerPC 603 or 603e", bfd_arch_powerpc,
489461e2
EZ
2548 bfd_mach_ppc_603, -1, -1, tot_num_registers (registers_603),
2549 registers_603},
7a78ae4e 2550 {"604", "Motorola PowerPC 604 or 604e", bfd_arch_powerpc,
489461e2
EZ
2551 604, -1, -1, tot_num_registers (registers_604),
2552 registers_604},
7a78ae4e 2553 {"403GC", "IBM PowerPC 403GC", bfd_arch_powerpc,
489461e2
EZ
2554 bfd_mach_ppc_403gc, -1, -1, tot_num_registers (registers_403GC),
2555 registers_403GC},
7a78ae4e 2556 {"505", "Motorola PowerPC 505", bfd_arch_powerpc,
489461e2
EZ
2557 bfd_mach_ppc_505, -1, -1, tot_num_registers (registers_505),
2558 registers_505},
7a78ae4e 2559 {"860", "Motorola PowerPC 860 or 850", bfd_arch_powerpc,
489461e2
EZ
2560 bfd_mach_ppc_860, -1, -1, tot_num_registers (registers_860),
2561 registers_860},
7a78ae4e 2562 {"750", "Motorola/IBM PowerPC 750 or 740", bfd_arch_powerpc,
489461e2
EZ
2563 bfd_mach_ppc_750, -1, -1, tot_num_registers (registers_750),
2564 registers_750},
1fcc0bb8 2565 {"7400", "Motorola/IBM PowerPC 7400 (G4)", bfd_arch_powerpc,
489461e2
EZ
2566 bfd_mach_ppc_7400, -1, -1, tot_num_registers (registers_7400),
2567 registers_7400},
c8001721
EZ
2568 {"e500", "Motorola PowerPC e500", bfd_arch_powerpc,
2569 bfd_mach_ppc_e500, -1, -1, tot_num_registers (registers_e500),
2570 registers_e500},
7a78ae4e 2571
5d57ee30
KB
2572 /* 64-bit */
2573 {"powerpc64", "PowerPC 64-bit user-level", bfd_arch_powerpc,
489461e2
EZ
2574 bfd_mach_ppc64, -1, -1, tot_num_registers (registers_powerpc),
2575 registers_powerpc},
7a78ae4e 2576 {"620", "Motorola PowerPC 620", bfd_arch_powerpc,
489461e2
EZ
2577 bfd_mach_ppc_620, -1, -1, tot_num_registers (registers_powerpc),
2578 registers_powerpc},
5d57ee30 2579 {"630", "Motorola PowerPC 630", bfd_arch_powerpc,
489461e2
EZ
2580 bfd_mach_ppc_630, -1, -1, tot_num_registers (registers_powerpc),
2581 registers_powerpc},
7a78ae4e 2582 {"a35", "PowerPC A35", bfd_arch_powerpc,
489461e2
EZ
2583 bfd_mach_ppc_a35, -1, -1, tot_num_registers (registers_powerpc),
2584 registers_powerpc},
5d57ee30 2585 {"rs64ii", "PowerPC rs64ii", bfd_arch_powerpc,
489461e2
EZ
2586 bfd_mach_ppc_rs64ii, -1, -1, tot_num_registers (registers_powerpc),
2587 registers_powerpc},
5d57ee30 2588 {"rs64iii", "PowerPC rs64iii", bfd_arch_powerpc,
489461e2
EZ
2589 bfd_mach_ppc_rs64iii, -1, -1, tot_num_registers (registers_powerpc),
2590 registers_powerpc},
5d57ee30 2591
64366f1c 2592 /* FIXME: I haven't checked the register sets of the following. */
7a78ae4e 2593 {"rs1", "IBM POWER RS1", bfd_arch_rs6000,
489461e2
EZ
2594 bfd_mach_rs6k_rs1, -1, -1, tot_num_registers (registers_power),
2595 registers_power},
7a78ae4e 2596 {"rsc", "IBM POWER RSC", bfd_arch_rs6000,
489461e2
EZ
2597 bfd_mach_rs6k_rsc, -1, -1, tot_num_registers (registers_power),
2598 registers_power},
7a78ae4e 2599 {"rs2", "IBM POWER RS2", bfd_arch_rs6000,
489461e2
EZ
2600 bfd_mach_rs6k_rs2, -1, -1, tot_num_registers (registers_power),
2601 registers_power},
7a78ae4e 2602
489461e2 2603 {0, 0, 0, 0, 0, 0, 0, 0}
c906108c
SS
2604};
2605
64366f1c 2606/* Initialize the number of registers and pseudo registers in each variant. */
489461e2
EZ
2607
2608static void
2609init_variants (void)
2610{
2611 struct variant *v;
2612
2613 for (v = variants; v->name; v++)
2614 {
2615 if (v->nregs == -1)
2616 v->nregs = num_registers (v->regs, v->num_tot_regs);
2617 if (v->npregs == -1)
2618 v->npregs = num_pseudo_registers (v->regs, v->num_tot_regs);
2619 }
2620}
c906108c 2621
7a78ae4e 2622/* Return the variant corresponding to architecture ARCH and machine number
64366f1c 2623 MACH. If no such variant exists, return null. */
c906108c 2624
7a78ae4e
ND
2625static const struct variant *
2626find_variant_by_arch (enum bfd_architecture arch, unsigned long mach)
c906108c 2627{
7a78ae4e 2628 const struct variant *v;
c5aa993b 2629
7a78ae4e
ND
2630 for (v = variants; v->name; v++)
2631 if (arch == v->arch && mach == v->mach)
2632 return v;
c906108c 2633
7a78ae4e 2634 return NULL;
c906108c 2635}
9364a0ef
EZ
2636
2637static int
2638gdb_print_insn_powerpc (bfd_vma memaddr, disassemble_info *info)
2639{
2640 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2641 return print_insn_big_powerpc (memaddr, info);
2642 else
2643 return print_insn_little_powerpc (memaddr, info);
2644}
7a78ae4e 2645\f
61a65099
KB
2646static CORE_ADDR
2647rs6000_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
2648{
2649 return frame_unwind_register_unsigned (next_frame, PC_REGNUM);
2650}
2651
2652static struct frame_id
2653rs6000_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
2654{
2655 return frame_id_build (frame_unwind_register_unsigned (next_frame,
2656 SP_REGNUM),
2657 frame_pc_unwind (next_frame));
2658}
2659
2660struct rs6000_frame_cache
2661{
2662 CORE_ADDR base;
2663 CORE_ADDR initial_sp;
2664 struct trad_frame_saved_reg *saved_regs;
2665};
2666
2667static struct rs6000_frame_cache *
2668rs6000_frame_cache (struct frame_info *next_frame, void **this_cache)
2669{
2670 struct rs6000_frame_cache *cache;
2671 struct gdbarch *gdbarch = get_frame_arch (next_frame);
2672 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2673 struct rs6000_framedata fdata;
2674 int wordsize = tdep->wordsize;
2675
2676 if ((*this_cache) != NULL)
2677 return (*this_cache);
2678 cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache);
2679 (*this_cache) = cache;
2680 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
2681
2682 skip_prologue (frame_func_unwind (next_frame), frame_pc_unwind (next_frame),
2683 &fdata);
2684
2685 /* If there were any saved registers, figure out parent's stack
2686 pointer. */
2687 /* The following is true only if the frame doesn't have a call to
2688 alloca(), FIXME. */
2689
2690 if (fdata.saved_fpr == 0
2691 && fdata.saved_gpr == 0
2692 && fdata.saved_vr == 0
2693 && fdata.saved_ev == 0
2694 && fdata.lr_offset == 0
2695 && fdata.cr_offset == 0
2696 && fdata.vr_offset == 0
2697 && fdata.ev_offset == 0)
2698 cache->base = frame_unwind_register_unsigned (next_frame, SP_REGNUM);
2699 else
2700 {
2701 /* NOTE: cagney/2002-04-14: The ->frame points to the inner-most
2702 address of the current frame. Things might be easier if the
2703 ->frame pointed to the outer-most address of the frame. In
2704 the mean time, the address of the prev frame is used as the
2705 base address of this frame. */
2706 cache->base = frame_unwind_register_unsigned (next_frame, SP_REGNUM);
2707 if (!fdata.frameless)
2708 /* Frameless really means stackless. */
2709 cache->base = read_memory_addr (cache->base, wordsize);
2710 }
2711 trad_frame_set_value (cache->saved_regs, SP_REGNUM, cache->base);
2712
2713 /* if != -1, fdata.saved_fpr is the smallest number of saved_fpr.
2714 All fpr's from saved_fpr to fp31 are saved. */
2715
2716 if (fdata.saved_fpr >= 0)
2717 {
2718 int i;
2719 CORE_ADDR fpr_addr = cache->base + fdata.fpr_offset;
2720 for (i = fdata.saved_fpr; i < 32; i++)
2721 {
2722 cache->saved_regs[FP0_REGNUM + i].addr = fpr_addr;
2723 fpr_addr += 8;
2724 }
2725 }
2726
2727 /* if != -1, fdata.saved_gpr is the smallest number of saved_gpr.
2728 All gpr's from saved_gpr to gpr31 are saved. */
2729
2730 if (fdata.saved_gpr >= 0)
2731 {
2732 int i;
2733 CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset;
2734 for (i = fdata.saved_gpr; i < 32; i++)
2735 {
2736 cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = gpr_addr;
2737 gpr_addr += wordsize;
2738 }
2739 }
2740
2741 /* if != -1, fdata.saved_vr is the smallest number of saved_vr.
2742 All vr's from saved_vr to vr31 are saved. */
2743 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
2744 {
2745 if (fdata.saved_vr >= 0)
2746 {
2747 int i;
2748 CORE_ADDR vr_addr = cache->base + fdata.vr_offset;
2749 for (i = fdata.saved_vr; i < 32; i++)
2750 {
2751 cache->saved_regs[tdep->ppc_vr0_regnum + i].addr = vr_addr;
2752 vr_addr += register_size (gdbarch, tdep->ppc_vr0_regnum);
2753 }
2754 }
2755 }
2756
2757 /* if != -1, fdata.saved_ev is the smallest number of saved_ev.
2758 All vr's from saved_ev to ev31 are saved. ????? */
2759 if (tdep->ppc_ev0_regnum != -1 && tdep->ppc_ev31_regnum != -1)
2760 {
2761 if (fdata.saved_ev >= 0)
2762 {
2763 int i;
2764 CORE_ADDR ev_addr = cache->base + fdata.ev_offset;
2765 for (i = fdata.saved_ev; i < 32; i++)
2766 {
2767 cache->saved_regs[tdep->ppc_ev0_regnum + i].addr = ev_addr;
2768 cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = ev_addr + 4;
2769 ev_addr += register_size (gdbarch, tdep->ppc_ev0_regnum);
2770 }
2771 }
2772 }
2773
2774 /* If != 0, fdata.cr_offset is the offset from the frame that
2775 holds the CR. */
2776 if (fdata.cr_offset != 0)
2777 cache->saved_regs[tdep->ppc_cr_regnum].addr = cache->base + fdata.cr_offset;
2778
2779 /* If != 0, fdata.lr_offset is the offset from the frame that
2780 holds the LR. */
2781 if (fdata.lr_offset != 0)
2782 cache->saved_regs[tdep->ppc_lr_regnum].addr = cache->base + fdata.lr_offset;
2783 /* The PC is found in the link register. */
2784 cache->saved_regs[PC_REGNUM] = cache->saved_regs[tdep->ppc_lr_regnum];
2785
2786 /* If != 0, fdata.vrsave_offset is the offset from the frame that
2787 holds the VRSAVE. */
2788 if (fdata.vrsave_offset != 0)
2789 cache->saved_regs[tdep->ppc_vrsave_regnum].addr = cache->base + fdata.vrsave_offset;
2790
2791 if (fdata.alloca_reg < 0)
2792 /* If no alloca register used, then fi->frame is the value of the
2793 %sp for this frame, and it is good enough. */
2794 cache->initial_sp = frame_unwind_register_unsigned (next_frame, SP_REGNUM);
2795 else
2796 cache->initial_sp = frame_unwind_register_unsigned (next_frame,
2797 fdata.alloca_reg);
2798
2799 return cache;
2800}
2801
2802static void
2803rs6000_frame_this_id (struct frame_info *next_frame, void **this_cache,
2804 struct frame_id *this_id)
2805{
2806 struct rs6000_frame_cache *info = rs6000_frame_cache (next_frame,
2807 this_cache);
2808 (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame));
2809}
2810
2811static void
2812rs6000_frame_prev_register (struct frame_info *next_frame,
2813 void **this_cache,
2814 int regnum, int *optimizedp,
2815 enum lval_type *lvalp, CORE_ADDR *addrp,
2816 int *realnump, void *valuep)
2817{
2818 struct rs6000_frame_cache *info = rs6000_frame_cache (next_frame,
2819 this_cache);
2820 trad_frame_prev_register (next_frame, info->saved_regs, regnum,
2821 optimizedp, lvalp, addrp, realnump, valuep);
2822}
2823
2824static const struct frame_unwind rs6000_frame_unwind =
2825{
2826 NORMAL_FRAME,
2827 rs6000_frame_this_id,
2828 rs6000_frame_prev_register
2829};
2830
2831static const struct frame_unwind *
2832rs6000_frame_sniffer (struct frame_info *next_frame)
2833{
2834 return &rs6000_frame_unwind;
2835}
2836
2837\f
2838
2839static CORE_ADDR
2840rs6000_frame_base_address (struct frame_info *next_frame,
2841 void **this_cache)
2842{
2843 struct rs6000_frame_cache *info = rs6000_frame_cache (next_frame,
2844 this_cache);
2845 return info->initial_sp;
2846}
2847
2848static const struct frame_base rs6000_frame_base = {
2849 &rs6000_frame_unwind,
2850 rs6000_frame_base_address,
2851 rs6000_frame_base_address,
2852 rs6000_frame_base_address
2853};
2854
2855static const struct frame_base *
2856rs6000_frame_base_sniffer (struct frame_info *next_frame)
2857{
2858 return &rs6000_frame_base;
2859}
2860
7a78ae4e
ND
2861/* Initialize the current architecture based on INFO. If possible, re-use an
2862 architecture from ARCHES, which is a list of architectures already created
2863 during this debugging session.
c906108c 2864
7a78ae4e 2865 Called e.g. at program startup, when reading a core file, and when reading
64366f1c 2866 a binary file. */
c906108c 2867
7a78ae4e
ND
2868static struct gdbarch *
2869rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2870{
2871 struct gdbarch *gdbarch;
2872 struct gdbarch_tdep *tdep;
9aa1e687 2873 int wordsize, from_xcoff_exec, from_elf_exec, power, i, off;
7a78ae4e
ND
2874 struct reg *regs;
2875 const struct variant *v;
2876 enum bfd_architecture arch;
2877 unsigned long mach;
2878 bfd abfd;
7b112f9c 2879 int sysv_abi;
5bf1c677 2880 asection *sect;
7a78ae4e 2881
9aa1e687 2882 from_xcoff_exec = info.abfd && info.abfd->format == bfd_object &&
7a78ae4e
ND
2883 bfd_get_flavour (info.abfd) == bfd_target_xcoff_flavour;
2884
9aa1e687
KB
2885 from_elf_exec = info.abfd && info.abfd->format == bfd_object &&
2886 bfd_get_flavour (info.abfd) == bfd_target_elf_flavour;
2887
2888 sysv_abi = info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour;
2889
e712c1cf 2890 /* Check word size. If INFO is from a binary file, infer it from
64366f1c 2891 that, else choose a likely default. */
9aa1e687 2892 if (from_xcoff_exec)
c906108c 2893 {
11ed25ac 2894 if (bfd_xcoff_is_xcoff64 (info.abfd))
7a78ae4e
ND
2895 wordsize = 8;
2896 else
2897 wordsize = 4;
c906108c 2898 }
9aa1e687
KB
2899 else if (from_elf_exec)
2900 {
2901 if (elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
2902 wordsize = 8;
2903 else
2904 wordsize = 4;
2905 }
c906108c 2906 else
7a78ae4e 2907 {
27b15785
KB
2908 if (info.bfd_arch_info != NULL && info.bfd_arch_info->bits_per_word != 0)
2909 wordsize = info.bfd_arch_info->bits_per_word /
2910 info.bfd_arch_info->bits_per_byte;
2911 else
2912 wordsize = 4;
7a78ae4e 2913 }
c906108c 2914
64366f1c 2915 /* Find a candidate among extant architectures. */
7a78ae4e
ND
2916 for (arches = gdbarch_list_lookup_by_info (arches, &info);
2917 arches != NULL;
2918 arches = gdbarch_list_lookup_by_info (arches->next, &info))
2919 {
2920 /* Word size in the various PowerPC bfd_arch_info structs isn't
2921 meaningful, because 64-bit CPUs can run in 32-bit mode. So, perform
64366f1c 2922 separate word size check. */
7a78ae4e 2923 tdep = gdbarch_tdep (arches->gdbarch);
4be87837 2924 if (tdep && tdep->wordsize == wordsize)
7a78ae4e
ND
2925 return arches->gdbarch;
2926 }
c906108c 2927
7a78ae4e
ND
2928 /* None found, create a new architecture from INFO, whose bfd_arch_info
2929 validity depends on the source:
2930 - executable useless
2931 - rs6000_host_arch() good
2932 - core file good
2933 - "set arch" trust blindly
2934 - GDB startup useless but harmless */
c906108c 2935
9aa1e687 2936 if (!from_xcoff_exec)
c906108c 2937 {
b732d07d 2938 arch = info.bfd_arch_info->arch;
7a78ae4e 2939 mach = info.bfd_arch_info->mach;
c906108c 2940 }
7a78ae4e 2941 else
c906108c 2942 {
7a78ae4e 2943 arch = bfd_arch_powerpc;
35cec841 2944 bfd_default_set_arch_mach (&abfd, arch, 0);
7a78ae4e 2945 info.bfd_arch_info = bfd_get_arch_info (&abfd);
35cec841 2946 mach = info.bfd_arch_info->mach;
7a78ae4e
ND
2947 }
2948 tdep = xmalloc (sizeof (struct gdbarch_tdep));
2949 tdep->wordsize = wordsize;
5bf1c677
EZ
2950
2951 /* For e500 executables, the apuinfo section is of help here. Such
2952 section contains the identifier and revision number of each
2953 Application-specific Processing Unit that is present on the
2954 chip. The content of the section is determined by the assembler
2955 which looks at each instruction and determines which unit (and
2956 which version of it) can execute it. In our case we just look for
2957 the existance of the section. */
2958
2959 if (info.abfd)
2960 {
2961 sect = bfd_get_section_by_name (info.abfd, ".PPC.EMB.apuinfo");
2962 if (sect)
2963 {
2964 arch = info.bfd_arch_info->arch;
2965 mach = bfd_mach_ppc_e500;
2966 bfd_default_set_arch_mach (&abfd, arch, mach);
2967 info.bfd_arch_info = bfd_get_arch_info (&abfd);
2968 }
2969 }
2970
7a78ae4e
ND
2971 gdbarch = gdbarch_alloc (&info, tdep);
2972 power = arch == bfd_arch_rs6000;
2973
489461e2
EZ
2974 /* Initialize the number of real and pseudo registers in each variant. */
2975 init_variants ();
2976
64366f1c 2977 /* Choose variant. */
7a78ae4e
ND
2978 v = find_variant_by_arch (arch, mach);
2979 if (!v)
dd47e6fd
EZ
2980 return NULL;
2981
7a78ae4e
ND
2982 tdep->regs = v->regs;
2983
2188cbdd
EZ
2984 tdep->ppc_gp0_regnum = 0;
2985 tdep->ppc_gplast_regnum = 31;
2986 tdep->ppc_toc_regnum = 2;
2987 tdep->ppc_ps_regnum = 65;
2988 tdep->ppc_cr_regnum = 66;
2989 tdep->ppc_lr_regnum = 67;
2990 tdep->ppc_ctr_regnum = 68;
2991 tdep->ppc_xer_regnum = 69;
2992 if (v->mach == bfd_mach_ppc_601)
2993 tdep->ppc_mq_regnum = 124;
e3f36dbd 2994 else if (power)
2188cbdd 2995 tdep->ppc_mq_regnum = 70;
e3f36dbd
KB
2996 else
2997 tdep->ppc_mq_regnum = -1;
2998 tdep->ppc_fpscr_regnum = power ? 71 : 70;
2188cbdd 2999
c8001721
EZ
3000 set_gdbarch_pc_regnum (gdbarch, 64);
3001 set_gdbarch_sp_regnum (gdbarch, 1);
0ba6dca9 3002 set_gdbarch_deprecated_fp_regnum (gdbarch, 1);
afd48b75 3003 if (sysv_abi && wordsize == 8)
05580c65 3004 set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value);
e754ae69 3005 else if (sysv_abi && wordsize == 4)
05580c65 3006 set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value);
afd48b75
AC
3007 else
3008 {
3009 set_gdbarch_deprecated_extract_return_value (gdbarch, rs6000_extract_return_value);
3010 set_gdbarch_deprecated_store_return_value (gdbarch, rs6000_store_return_value);
3011 }
c8001721 3012
1fcc0bb8
EZ
3013 if (v->arch == bfd_arch_powerpc)
3014 switch (v->mach)
3015 {
3016 case bfd_mach_ppc:
3017 tdep->ppc_vr0_regnum = 71;
3018 tdep->ppc_vrsave_regnum = 104;
c8001721
EZ
3019 tdep->ppc_ev0_regnum = -1;
3020 tdep->ppc_ev31_regnum = -1;
1fcc0bb8
EZ
3021 break;
3022 case bfd_mach_ppc_7400:
3023 tdep->ppc_vr0_regnum = 119;
54c2a1e6 3024 tdep->ppc_vrsave_regnum = 152;
c8001721
EZ
3025 tdep->ppc_ev0_regnum = -1;
3026 tdep->ppc_ev31_regnum = -1;
3027 break;
3028 case bfd_mach_ppc_e500:
338ef23d
AC
3029 tdep->ppc_gp0_regnum = 41;
3030 tdep->ppc_gplast_regnum = tdep->ppc_gp0_regnum + 32 - 1;
c8001721
EZ
3031 tdep->ppc_toc_regnum = -1;
3032 tdep->ppc_ps_regnum = 1;
3033 tdep->ppc_cr_regnum = 2;
3034 tdep->ppc_lr_regnum = 3;
3035 tdep->ppc_ctr_regnum = 4;
3036 tdep->ppc_xer_regnum = 5;
3037 tdep->ppc_ev0_regnum = 7;
3038 tdep->ppc_ev31_regnum = 38;
3039 set_gdbarch_pc_regnum (gdbarch, 0);
338ef23d 3040 set_gdbarch_sp_regnum (gdbarch, tdep->ppc_gp0_regnum + 1);
0ba6dca9 3041 set_gdbarch_deprecated_fp_regnum (gdbarch, tdep->ppc_gp0_regnum + 1);
c8001721
EZ
3042 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, e500_dwarf2_reg_to_regnum);
3043 set_gdbarch_pseudo_register_read (gdbarch, e500_pseudo_register_read);
3044 set_gdbarch_pseudo_register_write (gdbarch, e500_pseudo_register_write);
1fcc0bb8
EZ
3045 break;
3046 default:
3047 tdep->ppc_vr0_regnum = -1;
3048 tdep->ppc_vrsave_regnum = -1;
c8001721
EZ
3049 tdep->ppc_ev0_regnum = -1;
3050 tdep->ppc_ev31_regnum = -1;
1fcc0bb8
EZ
3051 break;
3052 }
3053
338ef23d
AC
3054 /* Sanity check on registers. */
3055 gdb_assert (strcmp (tdep->regs[tdep->ppc_gp0_regnum].name, "r0") == 0);
3056
a88376a3
KB
3057 /* Set lr_frame_offset. */
3058 if (wordsize == 8)
3059 tdep->lr_frame_offset = 16;
3060 else if (sysv_abi)
3061 tdep->lr_frame_offset = 4;
3062 else
3063 tdep->lr_frame_offset = 8;
3064
3065 /* Calculate byte offsets in raw register array. */
489461e2
EZ
3066 tdep->regoff = xmalloc (v->num_tot_regs * sizeof (int));
3067 for (i = off = 0; i < v->num_tot_regs; i++)
7a78ae4e
ND
3068 {
3069 tdep->regoff[i] = off;
3070 off += regsize (v->regs + i, wordsize);
c906108c
SS
3071 }
3072
56a6dfb9
KB
3073 /* Select instruction printer. */
3074 if (arch == power)
9364a0ef 3075 set_gdbarch_print_insn (gdbarch, print_insn_rs6000);
56a6dfb9 3076 else
9364a0ef 3077 set_gdbarch_print_insn (gdbarch, gdb_print_insn_powerpc);
7495d1dc 3078
7a78ae4e 3079 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
7a78ae4e
ND
3080
3081 set_gdbarch_num_regs (gdbarch, v->nregs);
c8001721 3082 set_gdbarch_num_pseudo_regs (gdbarch, v->npregs);
7a78ae4e 3083 set_gdbarch_register_name (gdbarch, rs6000_register_name);
b1e29e33 3084 set_gdbarch_deprecated_register_size (gdbarch, wordsize);
b8b527c5 3085 set_gdbarch_deprecated_register_bytes (gdbarch, off);
9c04cab7
AC
3086 set_gdbarch_deprecated_register_byte (gdbarch, rs6000_register_byte);
3087 set_gdbarch_deprecated_register_raw_size (gdbarch, rs6000_register_raw_size);
9c04cab7 3088 set_gdbarch_deprecated_register_virtual_type (gdbarch, rs6000_register_virtual_type);
7a78ae4e
ND
3089
3090 set_gdbarch_ptr_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
3091 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
3092 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
3093 set_gdbarch_long_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
3094 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
3095 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
3096 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
ab9fe00e
KB
3097 if (sysv_abi)
3098 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
3099 else
3100 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
4e409299 3101 set_gdbarch_char_signed (gdbarch, 0);
7a78ae4e 3102
11269d7e 3103 set_gdbarch_frame_align (gdbarch, rs6000_frame_align);
8b148df9
AC
3104 if (sysv_abi && wordsize == 8)
3105 /* PPC64 SYSV. */
3106 set_gdbarch_frame_red_zone_size (gdbarch, 288);
3107 else if (!sysv_abi && wordsize == 4)
5bffac25
AC
3108 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
3109 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
3110 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
3111 224. */
3112 set_gdbarch_frame_red_zone_size (gdbarch, 224);
7a78ae4e 3113
781a750d
AC
3114 set_gdbarch_deprecated_register_convertible (gdbarch, rs6000_register_convertible);
3115 set_gdbarch_deprecated_register_convert_to_virtual (gdbarch, rs6000_register_convert_to_virtual);
3116 set_gdbarch_deprecated_register_convert_to_raw (gdbarch, rs6000_register_convert_to_raw);
2188cbdd 3117 set_gdbarch_stab_reg_to_regnum (gdbarch, rs6000_stab_reg_to_regnum);
2ea5f656
KB
3118 /* Note: kevinb/2002-04-12: I'm not convinced that rs6000_push_arguments()
3119 is correct for the SysV ABI when the wordsize is 8, but I'm also
3120 fairly certain that ppc_sysv_abi_push_arguments() will give even
3121 worse results since it only works for 32-bit code. So, for the moment,
3122 we're better off calling rs6000_push_arguments() since it works for
3123 64-bit code. At some point in the future, this matter needs to be
3124 revisited. */
3125 if (sysv_abi && wordsize == 4)
77b2b6d4 3126 set_gdbarch_push_dummy_call (gdbarch, ppc_sysv_abi_push_dummy_call);
8be9034a
AC
3127 else if (sysv_abi && wordsize == 8)
3128 set_gdbarch_push_dummy_call (gdbarch, ppc64_sysv_abi_push_dummy_call);
9aa1e687 3129 else
77b2b6d4 3130 set_gdbarch_push_dummy_call (gdbarch, rs6000_push_dummy_call);
7a78ae4e 3131
74055713 3132 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, rs6000_extract_struct_value_address);
7a78ae4e
ND
3133
3134 set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue);
3135 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
7a78ae4e
ND
3136 set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);
3137
6066c3de
AC
3138 /* Handle the 64-bit SVR4 minimal-symbol convention of using "FN"
3139 for the descriptor and ".FN" for the entry-point -- a user
3140 specifying "break FN" will unexpectedly end up with a breakpoint
3141 on the descriptor and not the function. This architecture method
3142 transforms any breakpoints on descriptors into breakpoints on the
3143 corresponding entry point. */
3144 if (sysv_abi && wordsize == 8)
3145 set_gdbarch_adjust_breakpoint_address (gdbarch, ppc64_sysv_abi_adjust_breakpoint_address);
3146
7a78ae4e
ND
3147 /* Not sure on this. FIXMEmgo */
3148 set_gdbarch_frame_args_skip (gdbarch, 8);
3149
05580c65 3150 if (!sysv_abi)
7b112f9c 3151 set_gdbarch_use_struct_convention (gdbarch,
b9ff3018 3152 rs6000_use_struct_convention);
8e0662df 3153
15813d3f
AC
3154 if (!sysv_abi)
3155 {
3156 /* Handle RS/6000 function pointers (which are really function
3157 descriptors). */
f517ea4e
PS
3158 set_gdbarch_convert_from_func_ptr_addr (gdbarch,
3159 rs6000_convert_from_func_ptr_addr);
9aa1e687 3160 }
7a78ae4e 3161
143985b7
AF
3162 /* Helpers for function argument information. */
3163 set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument);
3164
7b112f9c 3165 /* Hook in ABI-specific overrides, if they have been registered. */
4be87837 3166 gdbarch_init_osabi (info, gdbarch);
7b112f9c 3167
61a65099
KB
3168 switch (info.osabi)
3169 {
3170 case GDB_OSABI_NETBSD_AOUT:
3171 case GDB_OSABI_NETBSD_ELF:
3172 case GDB_OSABI_UNKNOWN:
3173 case GDB_OSABI_LINUX:
3174 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
3175 frame_unwind_append_sniffer (gdbarch, rs6000_frame_sniffer);
3176 set_gdbarch_unwind_dummy_id (gdbarch, rs6000_unwind_dummy_id);
3177 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
3178 break;
3179 default:
3180 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
3181 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
3182 set_gdbarch_deprecated_pop_frame (gdbarch, rs6000_pop_frame);
3183 set_gdbarch_deprecated_frame_args_address (gdbarch, rs6000_frame_args_address);
3184 set_gdbarch_deprecated_frame_locals_address (gdbarch, rs6000_frame_args_address);
3185 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, rs6000_saved_pc_after_call);
3186 set_gdbarch_deprecated_frameless_function_invocation (gdbarch, rs6000_frameless_function_invocation);
3187 set_gdbarch_deprecated_frame_chain (gdbarch, rs6000_frame_chain);
3188 set_gdbarch_deprecated_frame_saved_pc (gdbarch, rs6000_frame_saved_pc);
3189 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, rs6000_frame_init_saved_regs);
3190 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, rs6000_init_extra_frame_info);
3191 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, rs6000_init_frame_pc_first);
3192 }
3193
ef5200c1
AC
3194 if (from_xcoff_exec)
3195 {
3196 /* NOTE: jimix/2003-06-09: This test should really check for
3197 GDB_OSABI_AIX when that is defined and becomes
3198 available. (Actually, once things are properly split apart,
3199 the test goes away.) */
3200 /* RS6000/AIX does not support PT_STEP. Has to be simulated. */
3201 set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
3202 }
3203
7a78ae4e 3204 return gdbarch;
c906108c
SS
3205}
3206
7b112f9c
JT
3207static void
3208rs6000_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
3209{
3210 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3211
3212 if (tdep == NULL)
3213 return;
3214
4be87837 3215 /* FIXME: Dump gdbarch_tdep. */
7b112f9c
JT
3216}
3217
1fcc0bb8
EZ
3218static struct cmd_list_element *info_powerpc_cmdlist = NULL;
3219
3220static void
3221rs6000_info_powerpc_command (char *args, int from_tty)
3222{
3223 help_list (info_powerpc_cmdlist, "info powerpc ", class_info, gdb_stdout);
3224}
3225
c906108c
SS
3226/* Initialization code. */
3227
a78f21af 3228extern initialize_file_ftype _initialize_rs6000_tdep; /* -Wmissing-prototypes */
b9362cc7 3229
c906108c 3230void
fba45db2 3231_initialize_rs6000_tdep (void)
c906108c 3232{
7b112f9c
JT
3233 gdbarch_register (bfd_arch_rs6000, rs6000_gdbarch_init, rs6000_dump_tdep);
3234 gdbarch_register (bfd_arch_powerpc, rs6000_gdbarch_init, rs6000_dump_tdep);
1fcc0bb8
EZ
3235
3236 /* Add root prefix command for "info powerpc" commands */
3237 add_prefix_cmd ("powerpc", class_info, rs6000_info_powerpc_command,
3238 "Various POWERPC info specific commands.",
3239 &info_powerpc_cmdlist, "info powerpc ", 0, &infolist);
c906108c 3240}
This page took 0.652182 seconds and 4 git commands to generate.