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