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