2007-10-30 Markus Deuling <deuling@de.ibm.com>
[deliverable/binutils-gdb.git] / gdb / rs6000-tdep.c
1 /* Target-dependent code for GDB, the GNU debugger.
2
3 Copyright (C) 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "symtab.h"
26 #include "target.h"
27 #include "gdbcore.h"
28 #include "gdbcmd.h"
29 #include "objfiles.h"
30 #include "arch-utils.h"
31 #include "regcache.h"
32 #include "regset.h"
33 #include "doublest.h"
34 #include "value.h"
35 #include "parser-defs.h"
36 #include "osabi.h"
37 #include "infcall.h"
38 #include "sim-regno.h"
39 #include "gdb/sim-ppc.h"
40 #include "reggroups.h"
41 #include "dwarf2-frame.h"
42 #include "target-descriptions.h"
43 #include "user-regs.h"
44
45 #include "libbfd.h" /* for bfd_default_set_arch_mach */
46 #include "coff/internal.h" /* for libcoff.h */
47 #include "libcoff.h" /* for xcoff_data */
48 #include "coff/xcoff.h"
49 #include "libxcoff.h"
50
51 #include "elf-bfd.h"
52 #include "elf/ppc.h"
53
54 #include "solib-svr4.h"
55 #include "ppc-tdep.h"
56
57 #include "gdb_assert.h"
58 #include "dis-asm.h"
59
60 #include "trad-frame.h"
61 #include "frame-unwind.h"
62 #include "frame-base.h"
63
64 #include "rs6000-tdep.h"
65
66 #include "features/rs6000/powerpc-32.c"
67 #include "features/rs6000/powerpc-403.c"
68 #include "features/rs6000/powerpc-403gc.c"
69 #include "features/rs6000/powerpc-505.c"
70 #include "features/rs6000/powerpc-601.c"
71 #include "features/rs6000/powerpc-602.c"
72 #include "features/rs6000/powerpc-603.c"
73 #include "features/rs6000/powerpc-604.c"
74 #include "features/rs6000/powerpc-64.c"
75 #include "features/rs6000/powerpc-7400.c"
76 #include "features/rs6000/powerpc-750.c"
77 #include "features/rs6000/powerpc-860.c"
78 #include "features/rs6000/powerpc-e500.c"
79 #include "features/rs6000/rs6000.c"
80
81 /* The list of available "set powerpc ..." and "show powerpc ..."
82 commands. */
83 static struct cmd_list_element *setpowerpccmdlist = NULL;
84 static struct cmd_list_element *showpowerpccmdlist = NULL;
85
86 static enum auto_boolean powerpc_soft_float_global = AUTO_BOOLEAN_AUTO;
87
88 /* The vector ABI to use. Keep this in sync with powerpc_vector_abi. */
89 static const char *powerpc_vector_strings[] =
90 {
91 "auto",
92 "generic",
93 "altivec",
94 "spe",
95 NULL
96 };
97
98 /* A variable that can be configured by the user. */
99 static enum powerpc_vector_abi powerpc_vector_abi_global = POWERPC_VEC_AUTO;
100 static const char *powerpc_vector_abi_string = "auto";
101
102 /* If the kernel has to deliver a signal, it pushes a sigcontext
103 structure on the stack and then calls the signal handler, passing
104 the address of the sigcontext in an argument register. Usually
105 the signal handler doesn't save this register, so we have to
106 access the sigcontext structure via an offset from the signal handler
107 frame.
108 The following constants were determined by experimentation on AIX 3.2. */
109 #define SIG_FRAME_PC_OFFSET 96
110 #define SIG_FRAME_LR_OFFSET 108
111 #define SIG_FRAME_FP_OFFSET 284
112
113 /* To be used by skip_prologue. */
114
115 struct rs6000_framedata
116 {
117 int offset; /* total size of frame --- the distance
118 by which we decrement sp to allocate
119 the frame */
120 int saved_gpr; /* smallest # of saved gpr */
121 int saved_fpr; /* smallest # of saved fpr */
122 int saved_vr; /* smallest # of saved vr */
123 int saved_ev; /* smallest # of saved ev */
124 int alloca_reg; /* alloca register number (frame ptr) */
125 char frameless; /* true if frameless functions. */
126 char nosavedpc; /* true if pc not saved. */
127 int gpr_offset; /* offset of saved gprs from prev sp */
128 int fpr_offset; /* offset of saved fprs from prev sp */
129 int vr_offset; /* offset of saved vrs from prev sp */
130 int ev_offset; /* offset of saved evs from prev sp */
131 int lr_offset; /* offset of saved lr */
132 int cr_offset; /* offset of saved cr */
133 int vrsave_offset; /* offset of saved vrsave register */
134 };
135
136 /* Description of a single register. */
137
138 struct reg
139 {
140 char *name; /* name of register */
141 unsigned char sz32; /* size on 32-bit arch, 0 if nonexistent */
142 unsigned char sz64; /* size on 64-bit arch, 0 if nonexistent */
143 unsigned char fpr; /* whether register is floating-point */
144 unsigned char pseudo; /* whether register is pseudo */
145 int spr_num; /* PowerPC SPR number, or -1 if not an SPR.
146 This is an ISA SPR number, not a GDB
147 register number. */
148 };
149
150 /* Hook for determining the TOC address when calling functions in the
151 inferior under AIX. The initialization code in rs6000-nat.c sets
152 this hook to point to find_toc_address. */
153
154 CORE_ADDR (*rs6000_find_toc_address_hook) (CORE_ADDR) = NULL;
155
156 /* Static function prototypes */
157
158 static CORE_ADDR branch_dest (struct frame_info *frame, int opcode,
159 int instr, CORE_ADDR pc, CORE_ADDR safety);
160 static CORE_ADDR skip_prologue (CORE_ADDR, CORE_ADDR,
161 struct rs6000_framedata *);
162
163 /* Is REGNO an AltiVec register? Return 1 if so, 0 otherwise. */
164 int
165 altivec_register_p (int regno)
166 {
167 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
168 if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
169 return 0;
170 else
171 return (regno >= tdep->ppc_vr0_regnum && regno <= tdep->ppc_vrsave_regnum);
172 }
173
174
175 /* Return true if REGNO is an SPE register, false otherwise. */
176 int
177 spe_register_p (int regno)
178 {
179 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
180
181 /* Is it a reference to EV0 -- EV31, and do we have those? */
182 if (tdep->ppc_ev0_regnum >= 0
183 && tdep->ppc_ev31_regnum >= 0
184 && tdep->ppc_ev0_regnum <= regno && regno <= tdep->ppc_ev31_regnum)
185 return 1;
186
187 /* Is it a reference to one of the raw upper GPR halves? */
188 if (tdep->ppc_ev0_upper_regnum >= 0
189 && tdep->ppc_ev0_upper_regnum <= regno
190 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
191 return 1;
192
193 /* Is it a reference to the 64-bit accumulator, and do we have that? */
194 if (tdep->ppc_acc_regnum >= 0
195 && tdep->ppc_acc_regnum == regno)
196 return 1;
197
198 /* Is it a reference to the SPE floating-point status and control register,
199 and do we have that? */
200 if (tdep->ppc_spefscr_regnum >= 0
201 && tdep->ppc_spefscr_regnum == regno)
202 return 1;
203
204 return 0;
205 }
206
207
208 /* Return non-zero if the architecture described by GDBARCH has
209 floating-point registers (f0 --- f31 and fpscr). */
210 int
211 ppc_floating_point_unit_p (struct gdbarch *gdbarch)
212 {
213 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
214
215 return (tdep->ppc_fp0_regnum >= 0
216 && tdep->ppc_fpscr_regnum >= 0);
217 }
218
219 /* Return non-zero if the architecture described by GDBARCH has
220 Altivec registers (vr0 --- vr31, vrsave and vscr). */
221 int
222 ppc_altivec_support_p (struct gdbarch *gdbarch)
223 {
224 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
225
226 return (tdep->ppc_vr0_regnum >= 0
227 && tdep->ppc_vrsave_regnum >= 0);
228 }
229
230 /* Check that TABLE[GDB_REGNO] is not already initialized, and then
231 set it to SIM_REGNO.
232
233 This is a helper function for init_sim_regno_table, constructing
234 the table mapping GDB register numbers to sim register numbers; we
235 initialize every element in that table to -1 before we start
236 filling it in. */
237 static void
238 set_sim_regno (int *table, int gdb_regno, int sim_regno)
239 {
240 /* Make sure we don't try to assign any given GDB register a sim
241 register number more than once. */
242 gdb_assert (table[gdb_regno] == -1);
243 table[gdb_regno] = sim_regno;
244 }
245
246
247 /* Initialize ARCH->tdep->sim_regno, the table mapping GDB register
248 numbers to simulator register numbers, based on the values placed
249 in the ARCH->tdep->ppc_foo_regnum members. */
250 static void
251 init_sim_regno_table (struct gdbarch *arch)
252 {
253 struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
254 int total_regs = gdbarch_num_regs (arch);
255 int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
256 int i;
257 static const char *const segment_regs[] = {
258 "sr0", "sr1", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7",
259 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15"
260 };
261
262 /* Presume that all registers not explicitly mentioned below are
263 unavailable from the sim. */
264 for (i = 0; i < total_regs; i++)
265 sim_regno[i] = -1;
266
267 /* General-purpose registers. */
268 for (i = 0; i < ppc_num_gprs; i++)
269 set_sim_regno (sim_regno, tdep->ppc_gp0_regnum + i, sim_ppc_r0_regnum + i);
270
271 /* Floating-point registers. */
272 if (tdep->ppc_fp0_regnum >= 0)
273 for (i = 0; i < ppc_num_fprs; i++)
274 set_sim_regno (sim_regno,
275 tdep->ppc_fp0_regnum + i,
276 sim_ppc_f0_regnum + i);
277 if (tdep->ppc_fpscr_regnum >= 0)
278 set_sim_regno (sim_regno, tdep->ppc_fpscr_regnum, sim_ppc_fpscr_regnum);
279
280 set_sim_regno (sim_regno, gdbarch_pc_regnum (arch), sim_ppc_pc_regnum);
281 set_sim_regno (sim_regno, tdep->ppc_ps_regnum, sim_ppc_ps_regnum);
282 set_sim_regno (sim_regno, tdep->ppc_cr_regnum, sim_ppc_cr_regnum);
283
284 /* Segment registers. */
285 for (i = 0; i < ppc_num_srs; i++)
286 {
287 int gdb_regno;
288
289 gdb_regno = user_reg_map_name_to_regnum (arch, segment_regs[i], -1);
290 if (gdb_regno >= 0)
291 set_sim_regno (sim_regno, gdb_regno, sim_ppc_sr0_regnum + i);
292 }
293
294 /* Altivec registers. */
295 if (tdep->ppc_vr0_regnum >= 0)
296 {
297 for (i = 0; i < ppc_num_vrs; i++)
298 set_sim_regno (sim_regno,
299 tdep->ppc_vr0_regnum + i,
300 sim_ppc_vr0_regnum + i);
301
302 /* FIXME: jimb/2004-07-15: when we have tdep->ppc_vscr_regnum,
303 we can treat this more like the other cases. */
304 set_sim_regno (sim_regno,
305 tdep->ppc_vr0_regnum + ppc_num_vrs,
306 sim_ppc_vscr_regnum);
307 }
308 /* vsave is a special-purpose register, so the code below handles it. */
309
310 /* SPE APU (E500) registers. */
311 if (tdep->ppc_ev0_upper_regnum >= 0)
312 for (i = 0; i < ppc_num_gprs; i++)
313 set_sim_regno (sim_regno,
314 tdep->ppc_ev0_upper_regnum + i,
315 sim_ppc_rh0_regnum + i);
316 if (tdep->ppc_acc_regnum >= 0)
317 set_sim_regno (sim_regno, tdep->ppc_acc_regnum, sim_ppc_acc_regnum);
318 /* spefscr is a special-purpose register, so the code below handles it. */
319
320 #ifdef WITH_SIM
321 /* Now handle all special-purpose registers. Verify that they
322 haven't mistakenly been assigned numbers by any of the above
323 code. */
324 for (i = 0; i < sim_ppc_num_sprs; i++)
325 {
326 const char *spr_name = sim_spr_register_name (i);
327 int gdb_regno = -1;
328
329 if (spr_name != NULL)
330 gdb_regno = user_reg_map_name_to_regnum (arch, spr_name, -1);
331
332 if (gdb_regno != -1)
333 set_sim_regno (sim_regno, gdb_regno, sim_ppc_spr0_regnum + i);
334 }
335 #endif
336
337 /* Drop the initialized array into place. */
338 tdep->sim_regno = sim_regno;
339 }
340
341
342 /* Given a GDB register number REG, return the corresponding SIM
343 register number. */
344 static int
345 rs6000_register_sim_regno (int reg)
346 {
347 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
348 int sim_regno;
349
350 if (tdep->sim_regno == NULL)
351 init_sim_regno_table (current_gdbarch);
352
353 gdb_assert (0 <= reg
354 && reg <= gdbarch_num_regs (current_gdbarch)
355 + gdbarch_num_pseudo_regs (current_gdbarch));
356 sim_regno = tdep->sim_regno[reg];
357
358 if (sim_regno >= 0)
359 return sim_regno;
360 else
361 return LEGACY_SIM_REGNO_IGNORE;
362 }
363
364 \f
365
366 /* Register set support functions. */
367
368 /* REGS + OFFSET contains register REGNUM in a field REGSIZE wide.
369 Write the register to REGCACHE. */
370
371 static void
372 ppc_supply_reg (struct regcache *regcache, int regnum,
373 const gdb_byte *regs, size_t offset, int regsize)
374 {
375 if (regnum != -1 && offset != -1)
376 {
377 if (regsize > 4)
378 {
379 struct gdbarch *gdbarch = get_regcache_arch (regcache);
380 int gdb_regsize = register_size (gdbarch, regnum);
381 if (gdb_regsize < regsize
382 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
383 offset += regsize - gdb_regsize;
384 }
385 regcache_raw_supply (regcache, regnum, regs + offset);
386 }
387 }
388
389 /* Read register REGNUM from REGCACHE and store to REGS + OFFSET
390 in a field REGSIZE wide. Zero pad as necessary. */
391
392 static void
393 ppc_collect_reg (const struct regcache *regcache, int regnum,
394 gdb_byte *regs, size_t offset, int regsize)
395 {
396 if (regnum != -1 && offset != -1)
397 {
398 if (regsize > 4)
399 {
400 struct gdbarch *gdbarch = get_regcache_arch (regcache);
401 int gdb_regsize = register_size (gdbarch, regnum);
402 if (gdb_regsize < regsize)
403 {
404 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
405 {
406 memset (regs + offset, 0, regsize - gdb_regsize);
407 offset += regsize - gdb_regsize;
408 }
409 else
410 memset (regs + offset + regsize - gdb_regsize, 0,
411 regsize - gdb_regsize);
412 }
413 }
414 regcache_raw_collect (regcache, regnum, regs + offset);
415 }
416 }
417
418 static int
419 ppc_greg_offset (struct gdbarch *gdbarch,
420 struct gdbarch_tdep *tdep,
421 const struct ppc_reg_offsets *offsets,
422 int regnum,
423 int *regsize)
424 {
425 *regsize = offsets->gpr_size;
426 if (regnum >= tdep->ppc_gp0_regnum
427 && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
428 return (offsets->r0_offset
429 + (regnum - tdep->ppc_gp0_regnum) * offsets->gpr_size);
430
431 if (regnum == gdbarch_pc_regnum (gdbarch))
432 return offsets->pc_offset;
433
434 if (regnum == tdep->ppc_ps_regnum)
435 return offsets->ps_offset;
436
437 if (regnum == tdep->ppc_lr_regnum)
438 return offsets->lr_offset;
439
440 if (regnum == tdep->ppc_ctr_regnum)
441 return offsets->ctr_offset;
442
443 *regsize = offsets->xr_size;
444 if (regnum == tdep->ppc_cr_regnum)
445 return offsets->cr_offset;
446
447 if (regnum == tdep->ppc_xer_regnum)
448 return offsets->xer_offset;
449
450 if (regnum == tdep->ppc_mq_regnum)
451 return offsets->mq_offset;
452
453 return -1;
454 }
455
456 static int
457 ppc_fpreg_offset (struct gdbarch_tdep *tdep,
458 const struct ppc_reg_offsets *offsets,
459 int regnum)
460 {
461 if (regnum >= tdep->ppc_fp0_regnum
462 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs)
463 return offsets->f0_offset + (regnum - tdep->ppc_fp0_regnum) * 8;
464
465 if (regnum == tdep->ppc_fpscr_regnum)
466 return offsets->fpscr_offset;
467
468 return -1;
469 }
470
471 static int
472 ppc_vrreg_offset (struct gdbarch_tdep *tdep,
473 const struct ppc_reg_offsets *offsets,
474 int regnum)
475 {
476 if (regnum >= tdep->ppc_vr0_regnum
477 && regnum < tdep->ppc_vr0_regnum + ppc_num_vrs)
478 return offsets->vr0_offset + (regnum - tdep->ppc_vr0_regnum) * 16;
479
480 if (regnum == tdep->ppc_vrsave_regnum - 1)
481 return offsets->vscr_offset;
482
483 if (regnum == tdep->ppc_vrsave_regnum)
484 return offsets->vrsave_offset;
485
486 return -1;
487 }
488
489 /* Supply register REGNUM in the general-purpose register set REGSET
490 from the buffer specified by GREGS and LEN to register cache
491 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
492
493 void
494 ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
495 int regnum, const void *gregs, size_t len)
496 {
497 struct gdbarch *gdbarch = get_regcache_arch (regcache);
498 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
499 const struct ppc_reg_offsets *offsets = regset->descr;
500 size_t offset;
501 int regsize;
502
503 if (regnum == -1)
504 {
505 int i;
506 int gpr_size = offsets->gpr_size;
507
508 for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset;
509 i < tdep->ppc_gp0_regnum + ppc_num_gprs;
510 i++, offset += gpr_size)
511 ppc_supply_reg (regcache, i, gregs, offset, gpr_size);
512
513 ppc_supply_reg (regcache, gdbarch_pc_regnum (gdbarch),
514 gregs, offsets->pc_offset, gpr_size);
515 ppc_supply_reg (regcache, tdep->ppc_ps_regnum,
516 gregs, offsets->ps_offset, gpr_size);
517 ppc_supply_reg (regcache, tdep->ppc_lr_regnum,
518 gregs, offsets->lr_offset, gpr_size);
519 ppc_supply_reg (regcache, tdep->ppc_ctr_regnum,
520 gregs, offsets->ctr_offset, gpr_size);
521 ppc_supply_reg (regcache, tdep->ppc_cr_regnum,
522 gregs, offsets->cr_offset, offsets->xr_size);
523 ppc_supply_reg (regcache, tdep->ppc_xer_regnum,
524 gregs, offsets->xer_offset, offsets->xr_size);
525 ppc_supply_reg (regcache, tdep->ppc_mq_regnum,
526 gregs, offsets->mq_offset, offsets->xr_size);
527 return;
528 }
529
530 offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, &regsize);
531 ppc_supply_reg (regcache, regnum, gregs, offset, regsize);
532 }
533
534 /* Supply register REGNUM in the floating-point register set REGSET
535 from the buffer specified by FPREGS and LEN to register cache
536 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
537
538 void
539 ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
540 int regnum, const void *fpregs, size_t len)
541 {
542 struct gdbarch *gdbarch = get_regcache_arch (regcache);
543 struct gdbarch_tdep *tdep;
544 const struct ppc_reg_offsets *offsets;
545 size_t offset;
546
547 if (!ppc_floating_point_unit_p (gdbarch))
548 return;
549
550 tdep = gdbarch_tdep (gdbarch);
551 offsets = regset->descr;
552 if (regnum == -1)
553 {
554 int i;
555
556 for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset;
557 i < tdep->ppc_fp0_regnum + ppc_num_fprs;
558 i++, offset += 8)
559 ppc_supply_reg (regcache, i, fpregs, offset, 8);
560
561 ppc_supply_reg (regcache, tdep->ppc_fpscr_regnum,
562 fpregs, offsets->fpscr_offset, offsets->fpscr_size);
563 return;
564 }
565
566 offset = ppc_fpreg_offset (tdep, offsets, regnum);
567 ppc_supply_reg (regcache, regnum, fpregs, offset,
568 regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8);
569 }
570
571 /* Supply register REGNUM in the Altivec register set REGSET
572 from the buffer specified by VRREGS and LEN to register cache
573 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
574
575 void
576 ppc_supply_vrregset (const struct regset *regset, struct regcache *regcache,
577 int regnum, const void *vrregs, size_t len)
578 {
579 struct gdbarch *gdbarch = get_regcache_arch (regcache);
580 struct gdbarch_tdep *tdep;
581 const struct ppc_reg_offsets *offsets;
582 size_t offset;
583
584 if (!ppc_altivec_support_p (gdbarch))
585 return;
586
587 tdep = gdbarch_tdep (gdbarch);
588 offsets = regset->descr;
589 if (regnum == -1)
590 {
591 int i;
592
593 for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset;
594 i < tdep->ppc_vr0_regnum + ppc_num_vrs;
595 i++, offset += 16)
596 ppc_supply_reg (regcache, i, vrregs, offset, 16);
597
598 ppc_supply_reg (regcache, (tdep->ppc_vrsave_regnum - 1),
599 vrregs, offsets->vscr_offset, 4);
600
601 ppc_supply_reg (regcache, tdep->ppc_vrsave_regnum,
602 vrregs, offsets->vrsave_offset, 4);
603 return;
604 }
605
606 offset = ppc_vrreg_offset (tdep, offsets, regnum);
607 if (regnum != tdep->ppc_vrsave_regnum
608 && regnum != tdep->ppc_vrsave_regnum - 1)
609 ppc_supply_reg (regcache, regnum, vrregs, offset, 16);
610 else
611 ppc_supply_reg (regcache, regnum,
612 vrregs, offset, 4);
613 }
614
615 /* Collect register REGNUM in the general-purpose register set
616 REGSET from register cache REGCACHE into the buffer specified by
617 GREGS and LEN. If REGNUM is -1, do this for all registers in
618 REGSET. */
619
620 void
621 ppc_collect_gregset (const struct regset *regset,
622 const struct regcache *regcache,
623 int regnum, void *gregs, size_t len)
624 {
625 struct gdbarch *gdbarch = get_regcache_arch (regcache);
626 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
627 const struct ppc_reg_offsets *offsets = regset->descr;
628 size_t offset;
629 int regsize;
630
631 if (regnum == -1)
632 {
633 int i;
634 int gpr_size = offsets->gpr_size;
635
636 for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset;
637 i < tdep->ppc_gp0_regnum + ppc_num_gprs;
638 i++, offset += gpr_size)
639 ppc_collect_reg (regcache, i, gregs, offset, gpr_size);
640
641 ppc_collect_reg (regcache, gdbarch_pc_regnum (gdbarch),
642 gregs, offsets->pc_offset, gpr_size);
643 ppc_collect_reg (regcache, tdep->ppc_ps_regnum,
644 gregs, offsets->ps_offset, gpr_size);
645 ppc_collect_reg (regcache, tdep->ppc_lr_regnum,
646 gregs, offsets->lr_offset, gpr_size);
647 ppc_collect_reg (regcache, tdep->ppc_ctr_regnum,
648 gregs, offsets->ctr_offset, gpr_size);
649 ppc_collect_reg (regcache, tdep->ppc_cr_regnum,
650 gregs, offsets->cr_offset, offsets->xr_size);
651 ppc_collect_reg (regcache, tdep->ppc_xer_regnum,
652 gregs, offsets->xer_offset, offsets->xr_size);
653 ppc_collect_reg (regcache, tdep->ppc_mq_regnum,
654 gregs, offsets->mq_offset, offsets->xr_size);
655 return;
656 }
657
658 offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, &regsize);
659 ppc_collect_reg (regcache, regnum, gregs, offset, regsize);
660 }
661
662 /* Collect register REGNUM in the floating-point register set
663 REGSET from register cache REGCACHE into the buffer specified by
664 FPREGS and LEN. If REGNUM is -1, do this for all registers in
665 REGSET. */
666
667 void
668 ppc_collect_fpregset (const struct regset *regset,
669 const struct regcache *regcache,
670 int regnum, void *fpregs, size_t len)
671 {
672 struct gdbarch *gdbarch = get_regcache_arch (regcache);
673 struct gdbarch_tdep *tdep;
674 const struct ppc_reg_offsets *offsets;
675 size_t offset;
676
677 if (!ppc_floating_point_unit_p (gdbarch))
678 return;
679
680 tdep = gdbarch_tdep (gdbarch);
681 offsets = regset->descr;
682 if (regnum == -1)
683 {
684 int i;
685
686 for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset;
687 i < tdep->ppc_fp0_regnum + ppc_num_fprs;
688 i++, offset += 8)
689 ppc_collect_reg (regcache, i, fpregs, offset, 8);
690
691 ppc_collect_reg (regcache, tdep->ppc_fpscr_regnum,
692 fpregs, offsets->fpscr_offset, offsets->fpscr_size);
693 return;
694 }
695
696 offset = ppc_fpreg_offset (tdep, offsets, regnum);
697 ppc_collect_reg (regcache, regnum, fpregs, offset,
698 regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8);
699 }
700
701 /* Collect register REGNUM in the Altivec register set
702 REGSET from register cache REGCACHE into the buffer specified by
703 VRREGS and LEN. If REGNUM is -1, do this for all registers in
704 REGSET. */
705
706 void
707 ppc_collect_vrregset (const struct regset *regset,
708 const struct regcache *regcache,
709 int regnum, void *vrregs, size_t len)
710 {
711 struct gdbarch *gdbarch = get_regcache_arch (regcache);
712 struct gdbarch_tdep *tdep;
713 const struct ppc_reg_offsets *offsets;
714 size_t offset;
715
716 if (!ppc_altivec_support_p (gdbarch))
717 return;
718
719 tdep = gdbarch_tdep (gdbarch);
720 offsets = regset->descr;
721 if (regnum == -1)
722 {
723 int i;
724
725 for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset;
726 i < tdep->ppc_vr0_regnum + ppc_num_vrs;
727 i++, offset += 16)
728 ppc_collect_reg (regcache, i, vrregs, offset, 16);
729
730 ppc_collect_reg (regcache, (tdep->ppc_vrsave_regnum - 1),
731 vrregs, offsets->vscr_offset, 4);
732
733 ppc_collect_reg (regcache, tdep->ppc_vrsave_regnum,
734 vrregs, offsets->vrsave_offset, 4);
735 return;
736 }
737
738 offset = ppc_vrreg_offset (tdep, offsets, regnum);
739 if (regnum != tdep->ppc_vrsave_regnum
740 && regnum != tdep->ppc_vrsave_regnum - 1)
741 ppc_collect_reg (regcache, regnum, vrregs, offset, 16);
742 else
743 ppc_collect_reg (regcache, regnum,
744 vrregs, offset, 4);
745 }
746 \f
747
748 /* Read a LEN-byte address from debugged memory address MEMADDR. */
749
750 static CORE_ADDR
751 read_memory_addr (CORE_ADDR memaddr, int len)
752 {
753 return read_memory_unsigned_integer (memaddr, len);
754 }
755
756 static CORE_ADDR
757 rs6000_skip_prologue (CORE_ADDR pc)
758 {
759 struct rs6000_framedata frame;
760 CORE_ADDR limit_pc, func_addr;
761
762 /* See if we can determine the end of the prologue via the symbol table.
763 If so, then return either PC, or the PC after the prologue, whichever
764 is greater. */
765 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
766 {
767 CORE_ADDR post_prologue_pc = skip_prologue_using_sal (func_addr);
768 if (post_prologue_pc != 0)
769 return max (pc, post_prologue_pc);
770 }
771
772 /* Can't determine prologue from the symbol table, need to examine
773 instructions. */
774
775 /* Find an upper limit on the function prologue using the debug
776 information. If the debug information could not be used to provide
777 that bound, then use an arbitrary large number as the upper bound. */
778 limit_pc = skip_prologue_using_sal (pc);
779 if (limit_pc == 0)
780 limit_pc = pc + 100; /* Magic. */
781
782 pc = skip_prologue (pc, limit_pc, &frame);
783 return pc;
784 }
785
786 static int
787 insn_changes_sp_or_jumps (unsigned long insn)
788 {
789 int opcode = (insn >> 26) & 0x03f;
790 int sd = (insn >> 21) & 0x01f;
791 int a = (insn >> 16) & 0x01f;
792 int subcode = (insn >> 1) & 0x3ff;
793
794 /* Changes the stack pointer. */
795
796 /* NOTE: There are many ways to change the value of a given register.
797 The ways below are those used when the register is R1, the SP,
798 in a funtion's epilogue. */
799
800 if (opcode == 31 && subcode == 444 && a == 1)
801 return 1; /* mr R1,Rn */
802 if (opcode == 14 && sd == 1)
803 return 1; /* addi R1,Rn,simm */
804 if (opcode == 58 && sd == 1)
805 return 1; /* ld R1,ds(Rn) */
806
807 /* Transfers control. */
808
809 if (opcode == 18)
810 return 1; /* b */
811 if (opcode == 16)
812 return 1; /* bc */
813 if (opcode == 19 && subcode == 16)
814 return 1; /* bclr */
815 if (opcode == 19 && subcode == 528)
816 return 1; /* bcctr */
817
818 return 0;
819 }
820
821 /* Return true if we are in the function's epilogue, i.e. after the
822 instruction that destroyed the function's stack frame.
823
824 1) scan forward from the point of execution:
825 a) If you find an instruction that modifies the stack pointer
826 or transfers control (except a return), execution is not in
827 an epilogue, return.
828 b) Stop scanning if you find a return instruction or reach the
829 end of the function or reach the hard limit for the size of
830 an epilogue.
831 2) scan backward from the point of execution:
832 a) If you find an instruction that modifies the stack pointer,
833 execution *is* in an epilogue, return.
834 b) Stop scanning if you reach an instruction that transfers
835 control or the beginning of the function or reach the hard
836 limit for the size of an epilogue. */
837
838 static int
839 rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
840 {
841 bfd_byte insn_buf[PPC_INSN_SIZE];
842 CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
843 unsigned long insn;
844 struct frame_info *curfrm;
845
846 /* Find the search limits based on function boundaries and hard limit. */
847
848 if (!find_pc_partial_function (pc, NULL, &func_start, &func_end))
849 return 0;
850
851 epilogue_start = pc - PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE;
852 if (epilogue_start < func_start) epilogue_start = func_start;
853
854 epilogue_end = pc + PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE;
855 if (epilogue_end > func_end) epilogue_end = func_end;
856
857 curfrm = get_current_frame ();
858
859 /* Scan forward until next 'blr'. */
860
861 for (scan_pc = pc; scan_pc < epilogue_end; scan_pc += PPC_INSN_SIZE)
862 {
863 if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE))
864 return 0;
865 insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE);
866 if (insn == 0x4e800020)
867 break;
868 if (insn_changes_sp_or_jumps (insn))
869 return 0;
870 }
871
872 /* Scan backward until adjustment to stack pointer (R1). */
873
874 for (scan_pc = pc - PPC_INSN_SIZE;
875 scan_pc >= epilogue_start;
876 scan_pc -= PPC_INSN_SIZE)
877 {
878 if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE))
879 return 0;
880 insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE);
881 if (insn_changes_sp_or_jumps (insn))
882 return 1;
883 }
884
885 return 0;
886 }
887
888 /* Get the ith function argument for the current function. */
889 static CORE_ADDR
890 rs6000_fetch_pointer_argument (struct frame_info *frame, int argi,
891 struct type *type)
892 {
893 return get_frame_register_unsigned (frame, 3 + argi);
894 }
895
896 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
897
898 static CORE_ADDR
899 branch_dest (struct frame_info *frame, int opcode, int instr,
900 CORE_ADDR pc, CORE_ADDR safety)
901 {
902 struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (frame));
903 CORE_ADDR dest;
904 int immediate;
905 int absolute;
906 int ext_op;
907
908 absolute = (int) ((instr >> 1) & 1);
909
910 switch (opcode)
911 {
912 case 18:
913 immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */
914 if (absolute)
915 dest = immediate;
916 else
917 dest = pc + immediate;
918 break;
919
920 case 16:
921 immediate = ((instr & ~3) << 16) >> 16; /* br conditional */
922 if (absolute)
923 dest = immediate;
924 else
925 dest = pc + immediate;
926 break;
927
928 case 19:
929 ext_op = (instr >> 1) & 0x3ff;
930
931 if (ext_op == 16) /* br conditional register */
932 {
933 dest = get_frame_register_unsigned (frame, tdep->ppc_lr_regnum) & ~3;
934
935 /* If we are about to return from a signal handler, dest is
936 something like 0x3c90. The current frame is a signal handler
937 caller frame, upon completion of the sigreturn system call
938 execution will return to the saved PC in the frame. */
939 if (dest < tdep->text_segment_base)
940 dest = read_memory_addr (get_frame_base (frame) + SIG_FRAME_PC_OFFSET,
941 tdep->wordsize);
942 }
943
944 else if (ext_op == 528) /* br cond to count reg */
945 {
946 dest = get_frame_register_unsigned (frame, tdep->ppc_ctr_regnum) & ~3;
947
948 /* If we are about to execute a system call, dest is something
949 like 0x22fc or 0x3b00. Upon completion the system call
950 will return to the address in the link register. */
951 if (dest < tdep->text_segment_base)
952 dest = get_frame_register_unsigned (frame, tdep->ppc_lr_regnum) & ~3;
953 }
954 else
955 return -1;
956 break;
957
958 default:
959 return -1;
960 }
961 return (dest < tdep->text_segment_base) ? safety : dest;
962 }
963
964
965 /* Sequence of bytes for breakpoint instruction. */
966
967 const static unsigned char *
968 rs6000_breakpoint_from_pc (CORE_ADDR *bp_addr, int *bp_size)
969 {
970 static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
971 static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
972 *bp_size = 4;
973 if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
974 return big_breakpoint;
975 else
976 return little_breakpoint;
977 }
978
979
980 /* Instruction masks used during single-stepping of atomic sequences. */
981 #define LWARX_MASK 0xfc0007fe
982 #define LWARX_INSTRUCTION 0x7c000028
983 #define LDARX_INSTRUCTION 0x7c0000A8
984 #define STWCX_MASK 0xfc0007ff
985 #define STWCX_INSTRUCTION 0x7c00012d
986 #define STDCX_INSTRUCTION 0x7c0001ad
987 #define BC_MASK 0xfc000000
988 #define BC_INSTRUCTION 0x40000000
989
990 /* Checks for an atomic sequence of instructions beginning with a LWARX/LDARX
991 instruction and ending with a STWCX/STDCX instruction. If such a sequence
992 is found, attempt to step through it. A breakpoint is placed at the end of
993 the sequence. */
994
995 static int
996 deal_with_atomic_sequence (struct frame_info *frame)
997 {
998 CORE_ADDR pc = get_frame_pc (frame);
999 CORE_ADDR breaks[2] = {-1, -1};
1000 CORE_ADDR loc = pc;
1001 CORE_ADDR branch_bp; /* Breakpoint at branch instruction's destination. */
1002 CORE_ADDR closing_insn; /* Instruction that closes the atomic sequence. */
1003 int insn = read_memory_integer (loc, PPC_INSN_SIZE);
1004 int insn_count;
1005 int index;
1006 int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
1007 const int atomic_sequence_length = 16; /* Instruction sequence length. */
1008 int opcode; /* Branch instruction's OPcode. */
1009 int bc_insn_count = 0; /* Conditional branch instruction count. */
1010
1011 /* Assume all atomic sequences start with a lwarx/ldarx instruction. */
1012 if ((insn & LWARX_MASK) != LWARX_INSTRUCTION
1013 && (insn & LWARX_MASK) != LDARX_INSTRUCTION)
1014 return 0;
1015
1016 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
1017 instructions. */
1018 for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
1019 {
1020 loc += PPC_INSN_SIZE;
1021 insn = read_memory_integer (loc, PPC_INSN_SIZE);
1022
1023 /* Assume that there is at most one conditional branch in the atomic
1024 sequence. If a conditional branch is found, put a breakpoint in
1025 its destination address. */
1026 if ((insn & BC_MASK) == BC_INSTRUCTION)
1027 {
1028 if (bc_insn_count >= 1)
1029 return 0; /* More than one conditional branch found, fallback
1030 to the standard single-step code. */
1031
1032 opcode = insn >> 26;
1033 branch_bp = branch_dest (frame, opcode, insn, pc, breaks[0]);
1034
1035 if (branch_bp != -1)
1036 {
1037 breaks[1] = branch_bp;
1038 bc_insn_count++;
1039 last_breakpoint++;
1040 }
1041 }
1042
1043 if ((insn & STWCX_MASK) == STWCX_INSTRUCTION
1044 || (insn & STWCX_MASK) == STDCX_INSTRUCTION)
1045 break;
1046 }
1047
1048 /* Assume that the atomic sequence ends with a stwcx/stdcx instruction. */
1049 if ((insn & STWCX_MASK) != STWCX_INSTRUCTION
1050 && (insn & STWCX_MASK) != STDCX_INSTRUCTION)
1051 return 0;
1052
1053 closing_insn = loc;
1054 loc += PPC_INSN_SIZE;
1055 insn = read_memory_integer (loc, PPC_INSN_SIZE);
1056
1057 /* Insert a breakpoint right after the end of the atomic sequence. */
1058 breaks[0] = loc;
1059
1060 /* Check for duplicated breakpoints. Check also for a breakpoint
1061 placed (branch instruction's destination) at the stwcx/stdcx
1062 instruction, this resets the reservation and take us back to the
1063 lwarx/ldarx instruction at the beginning of the atomic sequence. */
1064 if (last_breakpoint && ((breaks[1] == breaks[0])
1065 || (breaks[1] == closing_insn)))
1066 last_breakpoint = 0;
1067
1068 /* Effectively inserts the breakpoints. */
1069 for (index = 0; index <= last_breakpoint; index++)
1070 insert_single_step_breakpoint (breaks[index]);
1071
1072 return 1;
1073 }
1074
1075 /* AIX does not support PT_STEP. Simulate it. */
1076
1077 int
1078 rs6000_software_single_step (struct frame_info *frame)
1079 {
1080 CORE_ADDR dummy;
1081 int breakp_sz;
1082 const gdb_byte *breakp = rs6000_breakpoint_from_pc (&dummy, &breakp_sz);
1083 int ii, insn;
1084 CORE_ADDR loc;
1085 CORE_ADDR breaks[2];
1086 int opcode;
1087
1088 loc = get_frame_pc (frame);
1089
1090 insn = read_memory_integer (loc, 4);
1091
1092 if (deal_with_atomic_sequence (frame))
1093 return 1;
1094
1095 breaks[0] = loc + breakp_sz;
1096 opcode = insn >> 26;
1097 breaks[1] = branch_dest (frame, opcode, insn, loc, breaks[0]);
1098
1099 /* Don't put two breakpoints on the same address. */
1100 if (breaks[1] == breaks[0])
1101 breaks[1] = -1;
1102
1103 for (ii = 0; ii < 2; ++ii)
1104 {
1105 /* ignore invalid breakpoint. */
1106 if (breaks[ii] == -1)
1107 continue;
1108 insert_single_step_breakpoint (breaks[ii]);
1109 }
1110
1111 errno = 0; /* FIXME, don't ignore errors! */
1112 /* What errors? {read,write}_memory call error(). */
1113 return 1;
1114 }
1115
1116
1117 #define SIGNED_SHORT(x) \
1118 ((sizeof (short) == 2) \
1119 ? ((int)(short)(x)) \
1120 : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000)))
1121
1122 #define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
1123
1124 /* Limit the number of skipped non-prologue instructions, as the examining
1125 of the prologue is expensive. */
1126 static int max_skip_non_prologue_insns = 10;
1127
1128 /* Return nonzero if the given instruction OP can be part of the prologue
1129 of a function and saves a parameter on the stack. FRAMEP should be
1130 set if one of the previous instructions in the function has set the
1131 Frame Pointer. */
1132
1133 static int
1134 store_param_on_stack_p (unsigned long op, int framep, int *r0_contains_arg)
1135 {
1136 /* Move parameters from argument registers to temporary register. */
1137 if ((op & 0xfc0007fe) == 0x7c000378) /* mr(.) Rx,Ry */
1138 {
1139 /* Rx must be scratch register r0. */
1140 const int rx_regno = (op >> 16) & 31;
1141 /* Ry: Only r3 - r10 are used for parameter passing. */
1142 const int ry_regno = GET_SRC_REG (op);
1143
1144 if (rx_regno == 0 && ry_regno >= 3 && ry_regno <= 10)
1145 {
1146 *r0_contains_arg = 1;
1147 return 1;
1148 }
1149 else
1150 return 0;
1151 }
1152
1153 /* Save a General Purpose Register on stack. */
1154
1155 if ((op & 0xfc1f0003) == 0xf8010000 || /* std Rx,NUM(r1) */
1156 (op & 0xfc1f0000) == 0xd8010000) /* stfd Rx,NUM(r1) */
1157 {
1158 /* Rx: Only r3 - r10 are used for parameter passing. */
1159 const int rx_regno = GET_SRC_REG (op);
1160
1161 return (rx_regno >= 3 && rx_regno <= 10);
1162 }
1163
1164 /* Save a General Purpose Register on stack via the Frame Pointer. */
1165
1166 if (framep &&
1167 ((op & 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r31) */
1168 (op & 0xfc1f0000) == 0x981f0000 || /* stb Rx,NUM(r31) */
1169 (op & 0xfc1f0000) == 0xd81f0000)) /* stfd Rx,NUM(r31) */
1170 {
1171 /* Rx: Usually, only r3 - r10 are used for parameter passing.
1172 However, the compiler sometimes uses r0 to hold an argument. */
1173 const int rx_regno = GET_SRC_REG (op);
1174
1175 return ((rx_regno >= 3 && rx_regno <= 10)
1176 || (rx_regno == 0 && *r0_contains_arg));
1177 }
1178
1179 if ((op & 0xfc1f0000) == 0xfc010000) /* frsp, fp?,NUM(r1) */
1180 {
1181 /* Only f2 - f8 are used for parameter passing. */
1182 const int src_regno = GET_SRC_REG (op);
1183
1184 return (src_regno >= 2 && src_regno <= 8);
1185 }
1186
1187 if (framep && ((op & 0xfc1f0000) == 0xfc1f0000)) /* frsp, fp?,NUM(r31) */
1188 {
1189 /* Only f2 - f8 are used for parameter passing. */
1190 const int src_regno = GET_SRC_REG (op);
1191
1192 return (src_regno >= 2 && src_regno <= 8);
1193 }
1194
1195 /* Not an insn that saves a parameter on stack. */
1196 return 0;
1197 }
1198
1199 /* Assuming that INSN is a "bl" instruction located at PC, return
1200 nonzero if the destination of the branch is a "blrl" instruction.
1201
1202 This sequence is sometimes found in certain function prologues.
1203 It allows the function to load the LR register with a value that
1204 they can use to access PIC data using PC-relative offsets. */
1205
1206 static int
1207 bl_to_blrl_insn_p (CORE_ADDR pc, int insn)
1208 {
1209 CORE_ADDR dest;
1210 int immediate;
1211 int absolute;
1212 int dest_insn;
1213
1214 absolute = (int) ((insn >> 1) & 1);
1215 immediate = ((insn & ~3) << 6) >> 6;
1216 if (absolute)
1217 dest = immediate;
1218 else
1219 dest = pc + immediate;
1220
1221 dest_insn = read_memory_integer (dest, 4);
1222 if ((dest_insn & 0xfc00ffff) == 0x4c000021) /* blrl */
1223 return 1;
1224
1225 return 0;
1226 }
1227
1228 /* return pc value after skipping a function prologue and also return
1229 information about a function frame.
1230
1231 in struct rs6000_framedata fdata:
1232 - frameless is TRUE, if function does not have a frame.
1233 - nosavedpc is TRUE, if function does not save %pc value in its frame.
1234 - offset is the initial size of this stack frame --- the amount by
1235 which we decrement the sp to allocate the frame.
1236 - saved_gpr is the number of the first saved gpr.
1237 - saved_fpr is the number of the first saved fpr.
1238 - saved_vr is the number of the first saved vr.
1239 - saved_ev is the number of the first saved ev.
1240 - alloca_reg is the number of the register used for alloca() handling.
1241 Otherwise -1.
1242 - gpr_offset is the offset of the first saved gpr from the previous frame.
1243 - fpr_offset is the offset of the first saved fpr from the previous frame.
1244 - vr_offset is the offset of the first saved vr from the previous frame.
1245 - ev_offset is the offset of the first saved ev from the previous frame.
1246 - lr_offset is the offset of the saved lr
1247 - cr_offset is the offset of the saved cr
1248 - vrsave_offset is the offset of the saved vrsave register
1249 */
1250
1251 static CORE_ADDR
1252 skip_prologue (CORE_ADDR pc, CORE_ADDR lim_pc, struct rs6000_framedata *fdata)
1253 {
1254 CORE_ADDR orig_pc = pc;
1255 CORE_ADDR last_prologue_pc = pc;
1256 CORE_ADDR li_found_pc = 0;
1257 gdb_byte buf[4];
1258 unsigned long op;
1259 long offset = 0;
1260 long vr_saved_offset = 0;
1261 int lr_reg = -1;
1262 int cr_reg = -1;
1263 int vr_reg = -1;
1264 int ev_reg = -1;
1265 long ev_offset = 0;
1266 int vrsave_reg = -1;
1267 int reg;
1268 int framep = 0;
1269 int minimal_toc_loaded = 0;
1270 int prev_insn_was_prologue_insn = 1;
1271 int num_skip_non_prologue_insns = 0;
1272 int r0_contains_arg = 0;
1273 const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (current_gdbarch);
1274 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1275
1276 memset (fdata, 0, sizeof (struct rs6000_framedata));
1277 fdata->saved_gpr = -1;
1278 fdata->saved_fpr = -1;
1279 fdata->saved_vr = -1;
1280 fdata->saved_ev = -1;
1281 fdata->alloca_reg = -1;
1282 fdata->frameless = 1;
1283 fdata->nosavedpc = 1;
1284
1285 for (;; pc += 4)
1286 {
1287 /* Sometimes it isn't clear if an instruction is a prologue
1288 instruction or not. When we encounter one of these ambiguous
1289 cases, we'll set prev_insn_was_prologue_insn to 0 (false).
1290 Otherwise, we'll assume that it really is a prologue instruction. */
1291 if (prev_insn_was_prologue_insn)
1292 last_prologue_pc = pc;
1293
1294 /* Stop scanning if we've hit the limit. */
1295 if (pc >= lim_pc)
1296 break;
1297
1298 prev_insn_was_prologue_insn = 1;
1299
1300 /* Fetch the instruction and convert it to an integer. */
1301 if (target_read_memory (pc, buf, 4))
1302 break;
1303 op = extract_unsigned_integer (buf, 4);
1304
1305 if ((op & 0xfc1fffff) == 0x7c0802a6)
1306 { /* mflr Rx */
1307 /* Since shared library / PIC code, which needs to get its
1308 address at runtime, can appear to save more than one link
1309 register vis:
1310
1311 *INDENT-OFF*
1312 stwu r1,-304(r1)
1313 mflr r3
1314 bl 0xff570d0 (blrl)
1315 stw r30,296(r1)
1316 mflr r30
1317 stw r31,300(r1)
1318 stw r3,308(r1);
1319 ...
1320 *INDENT-ON*
1321
1322 remember just the first one, but skip over additional
1323 ones. */
1324 if (lr_reg == -1)
1325 lr_reg = (op & 0x03e00000);
1326 if (lr_reg == 0)
1327 r0_contains_arg = 0;
1328 continue;
1329 }
1330 else if ((op & 0xfc1fffff) == 0x7c000026)
1331 { /* mfcr Rx */
1332 cr_reg = (op & 0x03e00000);
1333 if (cr_reg == 0)
1334 r0_contains_arg = 0;
1335 continue;
1336
1337 }
1338 else if ((op & 0xfc1f0000) == 0xd8010000)
1339 { /* stfd Rx,NUM(r1) */
1340 reg = GET_SRC_REG (op);
1341 if (fdata->saved_fpr == -1 || fdata->saved_fpr > reg)
1342 {
1343 fdata->saved_fpr = reg;
1344 fdata->fpr_offset = SIGNED_SHORT (op) + offset;
1345 }
1346 continue;
1347
1348 }
1349 else if (((op & 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */
1350 (((op & 0xfc1f0000) == 0x90010000 || /* st rx,NUM(r1) */
1351 (op & 0xfc1f0003) == 0xf8010000) && /* std rx,NUM(r1) */
1352 (op & 0x03e00000) >= 0x01a00000)) /* rx >= r13 */
1353 {
1354
1355 reg = GET_SRC_REG (op);
1356 if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg)
1357 {
1358 fdata->saved_gpr = reg;
1359 if ((op & 0xfc1f0003) == 0xf8010000)
1360 op &= ~3UL;
1361 fdata->gpr_offset = SIGNED_SHORT (op) + offset;
1362 }
1363 continue;
1364
1365 }
1366 else if ((op & 0xffff0000) == 0x60000000)
1367 {
1368 /* nop */
1369 /* Allow nops in the prologue, but do not consider them to
1370 be part of the prologue unless followed by other prologue
1371 instructions. */
1372 prev_insn_was_prologue_insn = 0;
1373 continue;
1374
1375 }
1376 else if ((op & 0xffff0000) == 0x3c000000)
1377 { /* addis 0,0,NUM, used
1378 for >= 32k frames */
1379 fdata->offset = (op & 0x0000ffff) << 16;
1380 fdata->frameless = 0;
1381 r0_contains_arg = 0;
1382 continue;
1383
1384 }
1385 else if ((op & 0xffff0000) == 0x60000000)
1386 { /* ori 0,0,NUM, 2nd ha
1387 lf of >= 32k frames */
1388 fdata->offset |= (op & 0x0000ffff);
1389 fdata->frameless = 0;
1390 r0_contains_arg = 0;
1391 continue;
1392
1393 }
1394 else if (lr_reg >= 0 &&
1395 /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */
1396 (((op & 0xffff0000) == (lr_reg | 0xf8010000)) ||
1397 /* stw Rx, NUM(r1) */
1398 ((op & 0xffff0000) == (lr_reg | 0x90010000)) ||
1399 /* stwu Rx, NUM(r1) */
1400 ((op & 0xffff0000) == (lr_reg | 0x94010000))))
1401 { /* where Rx == lr */
1402 fdata->lr_offset = offset;
1403 fdata->nosavedpc = 0;
1404 /* Invalidate lr_reg, but don't set it to -1.
1405 That would mean that it had never been set. */
1406 lr_reg = -2;
1407 if ((op & 0xfc000003) == 0xf8000000 || /* std */
1408 (op & 0xfc000000) == 0x90000000) /* stw */
1409 {
1410 /* Does not update r1, so add displacement to lr_offset. */
1411 fdata->lr_offset += SIGNED_SHORT (op);
1412 }
1413 continue;
1414
1415 }
1416 else if (cr_reg >= 0 &&
1417 /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */
1418 (((op & 0xffff0000) == (cr_reg | 0xf8010000)) ||
1419 /* stw Rx, NUM(r1) */
1420 ((op & 0xffff0000) == (cr_reg | 0x90010000)) ||
1421 /* stwu Rx, NUM(r1) */
1422 ((op & 0xffff0000) == (cr_reg | 0x94010000))))
1423 { /* where Rx == cr */
1424 fdata->cr_offset = offset;
1425 /* Invalidate cr_reg, but don't set it to -1.
1426 That would mean that it had never been set. */
1427 cr_reg = -2;
1428 if ((op & 0xfc000003) == 0xf8000000 ||
1429 (op & 0xfc000000) == 0x90000000)
1430 {
1431 /* Does not update r1, so add displacement to cr_offset. */
1432 fdata->cr_offset += SIGNED_SHORT (op);
1433 }
1434 continue;
1435
1436 }
1437 else if ((op & 0xfe80ffff) == 0x42800005 && lr_reg != -1)
1438 {
1439 /* bcl 20,xx,.+4 is used to get the current PC, with or without
1440 prediction bits. If the LR has already been saved, we can
1441 skip it. */
1442 continue;
1443 }
1444 else if (op == 0x48000005)
1445 { /* bl .+4 used in
1446 -mrelocatable */
1447 continue;
1448
1449 }
1450 else if (op == 0x48000004)
1451 { /* b .+4 (xlc) */
1452 break;
1453
1454 }
1455 else if ((op & 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used
1456 in V.4 -mminimal-toc */
1457 (op & 0xffff0000) == 0x3bde0000)
1458 { /* addi 30,30,foo@l */
1459 continue;
1460
1461 }
1462 else if ((op & 0xfc000001) == 0x48000001)
1463 { /* bl foo,
1464 to save fprs??? */
1465
1466 fdata->frameless = 0;
1467
1468 /* If the return address has already been saved, we can skip
1469 calls to blrl (for PIC). */
1470 if (lr_reg != -1 && bl_to_blrl_insn_p (pc, op))
1471 continue;
1472
1473 /* Don't skip over the subroutine call if it is not within
1474 the first three instructions of the prologue and either
1475 we have no line table information or the line info tells
1476 us that the subroutine call is not part of the line
1477 associated with the prologue. */
1478 if ((pc - orig_pc) > 8)
1479 {
1480 struct symtab_and_line prologue_sal = find_pc_line (orig_pc, 0);
1481 struct symtab_and_line this_sal = find_pc_line (pc, 0);
1482
1483 if ((prologue_sal.line == 0) || (prologue_sal.line != this_sal.line))
1484 break;
1485 }
1486
1487 op = read_memory_integer (pc + 4, 4);
1488
1489 /* At this point, make sure this is not a trampoline
1490 function (a function that simply calls another functions,
1491 and nothing else). If the next is not a nop, this branch
1492 was part of the function prologue. */
1493
1494 if (op == 0x4def7b82 || op == 0) /* crorc 15, 15, 15 */
1495 break; /* don't skip over
1496 this branch */
1497 continue;
1498
1499 }
1500 /* update stack pointer */
1501 else if ((op & 0xfc1f0000) == 0x94010000)
1502 { /* stu rX,NUM(r1) || stwu rX,NUM(r1) */
1503 fdata->frameless = 0;
1504 fdata->offset = SIGNED_SHORT (op);
1505 offset = fdata->offset;
1506 continue;
1507 }
1508 else if ((op & 0xfc1f016a) == 0x7c01016e)
1509 { /* stwux rX,r1,rY */
1510 /* no way to figure out what r1 is going to be */
1511 fdata->frameless = 0;
1512 offset = fdata->offset;
1513 continue;
1514 }
1515 else if ((op & 0xfc1f0003) == 0xf8010001)
1516 { /* stdu rX,NUM(r1) */
1517 fdata->frameless = 0;
1518 fdata->offset = SIGNED_SHORT (op & ~3UL);
1519 offset = fdata->offset;
1520 continue;
1521 }
1522 else if ((op & 0xfc1f016a) == 0x7c01016a)
1523 { /* stdux rX,r1,rY */
1524 /* no way to figure out what r1 is going to be */
1525 fdata->frameless = 0;
1526 offset = fdata->offset;
1527 continue;
1528 }
1529 else if ((op & 0xffff0000) == 0x38210000)
1530 { /* addi r1,r1,SIMM */
1531 fdata->frameless = 0;
1532 fdata->offset += SIGNED_SHORT (op);
1533 offset = fdata->offset;
1534 continue;
1535 }
1536 /* Load up minimal toc pointer. Do not treat an epilogue restore
1537 of r31 as a minimal TOC load. */
1538 else if (((op >> 22) == 0x20f || /* l r31,... or l r30,... */
1539 (op >> 22) == 0x3af) /* ld r31,... or ld r30,... */
1540 && !framep
1541 && !minimal_toc_loaded)
1542 {
1543 minimal_toc_loaded = 1;
1544 continue;
1545
1546 /* move parameters from argument registers to local variable
1547 registers */
1548 }
1549 else if ((op & 0xfc0007fe) == 0x7c000378 && /* mr(.) Rx,Ry */
1550 (((op >> 21) & 31) >= 3) && /* R3 >= Ry >= R10 */
1551 (((op >> 21) & 31) <= 10) &&
1552 ((long) ((op >> 16) & 31) >= fdata->saved_gpr)) /* Rx: local var reg */
1553 {
1554 continue;
1555
1556 /* store parameters in stack */
1557 }
1558 /* Move parameters from argument registers to temporary register. */
1559 else if (store_param_on_stack_p (op, framep, &r0_contains_arg))
1560 {
1561 continue;
1562
1563 /* Set up frame pointer */
1564 }
1565 else if (op == 0x603f0000 /* oril r31, r1, 0x0 */
1566 || op == 0x7c3f0b78)
1567 { /* mr r31, r1 */
1568 fdata->frameless = 0;
1569 framep = 1;
1570 fdata->alloca_reg = (tdep->ppc_gp0_regnum + 31);
1571 continue;
1572
1573 /* Another way to set up the frame pointer. */
1574 }
1575 else if ((op & 0xfc1fffff) == 0x38010000)
1576 { /* addi rX, r1, 0x0 */
1577 fdata->frameless = 0;
1578 framep = 1;
1579 fdata->alloca_reg = (tdep->ppc_gp0_regnum
1580 + ((op & ~0x38010000) >> 21));
1581 continue;
1582 }
1583 /* AltiVec related instructions. */
1584 /* Store the vrsave register (spr 256) in another register for
1585 later manipulation, or load a register into the vrsave
1586 register. 2 instructions are used: mfvrsave and
1587 mtvrsave. They are shorthand notation for mfspr Rn, SPR256
1588 and mtspr SPR256, Rn. */
1589 /* mfspr Rn SPR256 == 011111 nnnnn 0000001000 01010100110
1590 mtspr SPR256 Rn == 011111 nnnnn 0000001000 01110100110 */
1591 else if ((op & 0xfc1fffff) == 0x7c0042a6) /* mfvrsave Rn */
1592 {
1593 vrsave_reg = GET_SRC_REG (op);
1594 continue;
1595 }
1596 else if ((op & 0xfc1fffff) == 0x7c0043a6) /* mtvrsave Rn */
1597 {
1598 continue;
1599 }
1600 /* Store the register where vrsave was saved to onto the stack:
1601 rS is the register where vrsave was stored in a previous
1602 instruction. */
1603 /* 100100 sssss 00001 dddddddd dddddddd */
1604 else if ((op & 0xfc1f0000) == 0x90010000) /* stw rS, d(r1) */
1605 {
1606 if (vrsave_reg == GET_SRC_REG (op))
1607 {
1608 fdata->vrsave_offset = SIGNED_SHORT (op) + offset;
1609 vrsave_reg = -1;
1610 }
1611 continue;
1612 }
1613 /* Compute the new value of vrsave, by modifying the register
1614 where vrsave was saved to. */
1615 else if (((op & 0xfc000000) == 0x64000000) /* oris Ra, Rs, UIMM */
1616 || ((op & 0xfc000000) == 0x60000000))/* ori Ra, Rs, UIMM */
1617 {
1618 continue;
1619 }
1620 /* li r0, SIMM (short for addi r0, 0, SIMM). This is the first
1621 in a pair of insns to save the vector registers on the
1622 stack. */
1623 /* 001110 00000 00000 iiii iiii iiii iiii */
1624 /* 001110 01110 00000 iiii iiii iiii iiii */
1625 else if ((op & 0xffff0000) == 0x38000000 /* li r0, SIMM */
1626 || (op & 0xffff0000) == 0x39c00000) /* li r14, SIMM */
1627 {
1628 if ((op & 0xffff0000) == 0x38000000)
1629 r0_contains_arg = 0;
1630 li_found_pc = pc;
1631 vr_saved_offset = SIGNED_SHORT (op);
1632
1633 /* This insn by itself is not part of the prologue, unless
1634 if part of the pair of insns mentioned above. So do not
1635 record this insn as part of the prologue yet. */
1636 prev_insn_was_prologue_insn = 0;
1637 }
1638 /* Store vector register S at (r31+r0) aligned to 16 bytes. */
1639 /* 011111 sssss 11111 00000 00111001110 */
1640 else if ((op & 0xfc1fffff) == 0x7c1f01ce) /* stvx Vs, R31, R0 */
1641 {
1642 if (pc == (li_found_pc + 4))
1643 {
1644 vr_reg = GET_SRC_REG (op);
1645 /* If this is the first vector reg to be saved, or if
1646 it has a lower number than others previously seen,
1647 reupdate the frame info. */
1648 if (fdata->saved_vr == -1 || fdata->saved_vr > vr_reg)
1649 {
1650 fdata->saved_vr = vr_reg;
1651 fdata->vr_offset = vr_saved_offset + offset;
1652 }
1653 vr_saved_offset = -1;
1654 vr_reg = -1;
1655 li_found_pc = 0;
1656 }
1657 }
1658 /* End AltiVec related instructions. */
1659
1660 /* Start BookE related instructions. */
1661 /* Store gen register S at (r31+uimm).
1662 Any register less than r13 is volatile, so we don't care. */
1663 /* 000100 sssss 11111 iiiii 01100100001 */
1664 else if (arch_info->mach == bfd_mach_ppc_e500
1665 && (op & 0xfc1f07ff) == 0x101f0321) /* evstdd Rs,uimm(R31) */
1666 {
1667 if ((op & 0x03e00000) >= 0x01a00000) /* Rs >= r13 */
1668 {
1669 unsigned int imm;
1670 ev_reg = GET_SRC_REG (op);
1671 imm = (op >> 11) & 0x1f;
1672 ev_offset = imm * 8;
1673 /* If this is the first vector reg to be saved, or if
1674 it has a lower number than others previously seen,
1675 reupdate the frame info. */
1676 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
1677 {
1678 fdata->saved_ev = ev_reg;
1679 fdata->ev_offset = ev_offset + offset;
1680 }
1681 }
1682 continue;
1683 }
1684 /* Store gen register rS at (r1+rB). */
1685 /* 000100 sssss 00001 bbbbb 01100100000 */
1686 else if (arch_info->mach == bfd_mach_ppc_e500
1687 && (op & 0xffe007ff) == 0x13e00320) /* evstddx RS,R1,Rb */
1688 {
1689 if (pc == (li_found_pc + 4))
1690 {
1691 ev_reg = GET_SRC_REG (op);
1692 /* If this is the first vector reg to be saved, or if
1693 it has a lower number than others previously seen,
1694 reupdate the frame info. */
1695 /* We know the contents of rB from the previous instruction. */
1696 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
1697 {
1698 fdata->saved_ev = ev_reg;
1699 fdata->ev_offset = vr_saved_offset + offset;
1700 }
1701 vr_saved_offset = -1;
1702 ev_reg = -1;
1703 li_found_pc = 0;
1704 }
1705 continue;
1706 }
1707 /* Store gen register r31 at (rA+uimm). */
1708 /* 000100 11111 aaaaa iiiii 01100100001 */
1709 else if (arch_info->mach == bfd_mach_ppc_e500
1710 && (op & 0xffe007ff) == 0x13e00321) /* evstdd R31,Ra,UIMM */
1711 {
1712 /* Wwe know that the source register is 31 already, but
1713 it can't hurt to compute it. */
1714 ev_reg = GET_SRC_REG (op);
1715 ev_offset = ((op >> 11) & 0x1f) * 8;
1716 /* If this is the first vector reg to be saved, or if
1717 it has a lower number than others previously seen,
1718 reupdate the frame info. */
1719 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
1720 {
1721 fdata->saved_ev = ev_reg;
1722 fdata->ev_offset = ev_offset + offset;
1723 }
1724
1725 continue;
1726 }
1727 /* Store gen register S at (r31+r0).
1728 Store param on stack when offset from SP bigger than 4 bytes. */
1729 /* 000100 sssss 11111 00000 01100100000 */
1730 else if (arch_info->mach == bfd_mach_ppc_e500
1731 && (op & 0xfc1fffff) == 0x101f0320) /* evstddx Rs,R31,R0 */
1732 {
1733 if (pc == (li_found_pc + 4))
1734 {
1735 if ((op & 0x03e00000) >= 0x01a00000)
1736 {
1737 ev_reg = GET_SRC_REG (op);
1738 /* If this is the first vector reg to be saved, or if
1739 it has a lower number than others previously seen,
1740 reupdate the frame info. */
1741 /* We know the contents of r0 from the previous
1742 instruction. */
1743 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
1744 {
1745 fdata->saved_ev = ev_reg;
1746 fdata->ev_offset = vr_saved_offset + offset;
1747 }
1748 ev_reg = -1;
1749 }
1750 vr_saved_offset = -1;
1751 li_found_pc = 0;
1752 continue;
1753 }
1754 }
1755 /* End BookE related instructions. */
1756
1757 else
1758 {
1759 /* Not a recognized prologue instruction.
1760 Handle optimizer code motions into the prologue by continuing
1761 the search if we have no valid frame yet or if the return
1762 address is not yet saved in the frame. */
1763 if (fdata->frameless == 0 && fdata->nosavedpc == 0)
1764 break;
1765
1766 if (op == 0x4e800020 /* blr */
1767 || op == 0x4e800420) /* bctr */
1768 /* Do not scan past epilogue in frameless functions or
1769 trampolines. */
1770 break;
1771 if ((op & 0xf4000000) == 0x40000000) /* bxx */
1772 /* Never skip branches. */
1773 break;
1774
1775 if (num_skip_non_prologue_insns++ > max_skip_non_prologue_insns)
1776 /* Do not scan too many insns, scanning insns is expensive with
1777 remote targets. */
1778 break;
1779
1780 /* Continue scanning. */
1781 prev_insn_was_prologue_insn = 0;
1782 continue;
1783 }
1784 }
1785
1786 #if 0
1787 /* I have problems with skipping over __main() that I need to address
1788 * sometime. Previously, I used to use misc_function_vector which
1789 * didn't work as well as I wanted to be. -MGO */
1790
1791 /* If the first thing after skipping a prolog is a branch to a function,
1792 this might be a call to an initializer in main(), introduced by gcc2.
1793 We'd like to skip over it as well. Fortunately, xlc does some extra
1794 work before calling a function right after a prologue, thus we can
1795 single out such gcc2 behaviour. */
1796
1797
1798 if ((op & 0xfc000001) == 0x48000001)
1799 { /* bl foo, an initializer function? */
1800 op = read_memory_integer (pc + 4, 4);
1801
1802 if (op == 0x4def7b82)
1803 { /* cror 0xf, 0xf, 0xf (nop) */
1804
1805 /* Check and see if we are in main. If so, skip over this
1806 initializer function as well. */
1807
1808 tmp = find_pc_misc_function (pc);
1809 if (tmp >= 0
1810 && strcmp (misc_function_vector[tmp].name, main_name ()) == 0)
1811 return pc + 8;
1812 }
1813 }
1814 #endif /* 0 */
1815
1816 fdata->offset = -fdata->offset;
1817 return last_prologue_pc;
1818 }
1819
1820
1821 /*************************************************************************
1822 Support for creating pushing a dummy frame into the stack, and popping
1823 frames, etc.
1824 *************************************************************************/
1825
1826
1827 /* All the ABI's require 16 byte alignment. */
1828 static CORE_ADDR
1829 rs6000_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
1830 {
1831 return (addr & -16);
1832 }
1833
1834 /* Pass the arguments in either registers, or in the stack. In RS/6000,
1835 the first eight words of the argument list (that might be less than
1836 eight parameters if some parameters occupy more than one word) are
1837 passed in r3..r10 registers. float and double parameters are
1838 passed in fpr's, in addition to that. Rest of the parameters if any
1839 are passed in user stack. There might be cases in which half of the
1840 parameter is copied into registers, the other half is pushed into
1841 stack.
1842
1843 Stack must be aligned on 64-bit boundaries when synthesizing
1844 function calls.
1845
1846 If the function is returning a structure, then the return address is passed
1847 in r3, then the first 7 words of the parameters can be passed in registers,
1848 starting from r4. */
1849
1850 static CORE_ADDR
1851 rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
1852 struct regcache *regcache, CORE_ADDR bp_addr,
1853 int nargs, struct value **args, CORE_ADDR sp,
1854 int struct_return, CORE_ADDR struct_addr)
1855 {
1856 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1857 int ii;
1858 int len = 0;
1859 int argno; /* current argument number */
1860 int argbytes; /* current argument byte */
1861 gdb_byte tmp_buffer[50];
1862 int f_argno = 0; /* current floating point argno */
1863 int wordsize = gdbarch_tdep (gdbarch)->wordsize;
1864 CORE_ADDR func_addr = find_function_addr (function, NULL);
1865
1866 struct value *arg = 0;
1867 struct type *type;
1868
1869 ULONGEST saved_sp;
1870
1871 /* The calling convention this function implements assumes the
1872 processor has floating-point registers. We shouldn't be using it
1873 on PPC variants that lack them. */
1874 gdb_assert (ppc_floating_point_unit_p (gdbarch));
1875
1876 /* The first eight words of ther arguments are passed in registers.
1877 Copy them appropriately. */
1878 ii = 0;
1879
1880 /* If the function is returning a `struct', then the first word
1881 (which will be passed in r3) is used for struct return address.
1882 In that case we should advance one word and start from r4
1883 register to copy parameters. */
1884 if (struct_return)
1885 {
1886 regcache_raw_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
1887 struct_addr);
1888 ii++;
1889 }
1890
1891 /*
1892 effectively indirect call... gcc does...
1893
1894 return_val example( float, int);
1895
1896 eabi:
1897 float in fp0, int in r3
1898 offset of stack on overflow 8/16
1899 for varargs, must go by type.
1900 power open:
1901 float in r3&r4, int in r5
1902 offset of stack on overflow different
1903 both:
1904 return in r3 or f0. If no float, must study how gcc emulates floats;
1905 pay attention to arg promotion.
1906 User may have to cast\args to handle promotion correctly
1907 since gdb won't know if prototype supplied or not.
1908 */
1909
1910 for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii)
1911 {
1912 int reg_size = register_size (gdbarch, ii + 3);
1913
1914 arg = args[argno];
1915 type = check_typedef (value_type (arg));
1916 len = TYPE_LENGTH (type);
1917
1918 if (TYPE_CODE (type) == TYPE_CODE_FLT)
1919 {
1920
1921 /* Floating point arguments are passed in fpr's, as well as gpr's.
1922 There are 13 fpr's reserved for passing parameters. At this point
1923 there is no way we would run out of them. */
1924
1925 gdb_assert (len <= 8);
1926
1927 regcache_cooked_write (regcache,
1928 tdep->ppc_fp0_regnum + 1 + f_argno,
1929 value_contents (arg));
1930 ++f_argno;
1931 }
1932
1933 if (len > reg_size)
1934 {
1935
1936 /* Argument takes more than one register. */
1937 while (argbytes < len)
1938 {
1939 gdb_byte word[MAX_REGISTER_SIZE];
1940 memset (word, 0, reg_size);
1941 memcpy (word,
1942 ((char *) value_contents (arg)) + argbytes,
1943 (len - argbytes) > reg_size
1944 ? reg_size : len - argbytes);
1945 regcache_cooked_write (regcache,
1946 tdep->ppc_gp0_regnum + 3 + ii,
1947 word);
1948 ++ii, argbytes += reg_size;
1949
1950 if (ii >= 8)
1951 goto ran_out_of_registers_for_arguments;
1952 }
1953 argbytes = 0;
1954 --ii;
1955 }
1956 else
1957 {
1958 /* Argument can fit in one register. No problem. */
1959 int adj = gdbarch_byte_order (gdbarch)
1960 == BFD_ENDIAN_BIG ? reg_size - len : 0;
1961 gdb_byte word[MAX_REGISTER_SIZE];
1962
1963 memset (word, 0, reg_size);
1964 memcpy (word, value_contents (arg), len);
1965 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3 +ii, word);
1966 }
1967 ++argno;
1968 }
1969
1970 ran_out_of_registers_for_arguments:
1971
1972 regcache_cooked_read_unsigned (regcache,
1973 gdbarch_sp_regnum (gdbarch),
1974 &saved_sp);
1975
1976 /* Location for 8 parameters are always reserved. */
1977 sp -= wordsize * 8;
1978
1979 /* Another six words for back chain, TOC register, link register, etc. */
1980 sp -= wordsize * 6;
1981
1982 /* Stack pointer must be quadword aligned. */
1983 sp &= -16;
1984
1985 /* If there are more arguments, allocate space for them in
1986 the stack, then push them starting from the ninth one. */
1987
1988 if ((argno < nargs) || argbytes)
1989 {
1990 int space = 0, jj;
1991
1992 if (argbytes)
1993 {
1994 space += ((len - argbytes + 3) & -4);
1995 jj = argno + 1;
1996 }
1997 else
1998 jj = argno;
1999
2000 for (; jj < nargs; ++jj)
2001 {
2002 struct value *val = args[jj];
2003 space += ((TYPE_LENGTH (value_type (val))) + 3) & -4;
2004 }
2005
2006 /* Add location required for the rest of the parameters. */
2007 space = (space + 15) & -16;
2008 sp -= space;
2009
2010 /* This is another instance we need to be concerned about
2011 securing our stack space. If we write anything underneath %sp
2012 (r1), we might conflict with the kernel who thinks he is free
2013 to use this area. So, update %sp first before doing anything
2014 else. */
2015
2016 regcache_raw_write_signed (regcache,
2017 gdbarch_sp_regnum (gdbarch), sp);
2018
2019 /* If the last argument copied into the registers didn't fit there
2020 completely, push the rest of it into stack. */
2021
2022 if (argbytes)
2023 {
2024 write_memory (sp + 24 + (ii * 4),
2025 value_contents (arg) + argbytes,
2026 len - argbytes);
2027 ++argno;
2028 ii += ((len - argbytes + 3) & -4) / 4;
2029 }
2030
2031 /* Push the rest of the arguments into stack. */
2032 for (; argno < nargs; ++argno)
2033 {
2034
2035 arg = args[argno];
2036 type = check_typedef (value_type (arg));
2037 len = TYPE_LENGTH (type);
2038
2039
2040 /* Float types should be passed in fpr's, as well as in the
2041 stack. */
2042 if (TYPE_CODE (type) == TYPE_CODE_FLT && f_argno < 13)
2043 {
2044
2045 gdb_assert (len <= 8);
2046
2047 regcache_cooked_write (regcache,
2048 tdep->ppc_fp0_regnum + 1 + f_argno,
2049 value_contents (arg));
2050 ++f_argno;
2051 }
2052
2053 write_memory (sp + 24 + (ii * 4), value_contents (arg), len);
2054 ii += ((len + 3) & -4) / 4;
2055 }
2056 }
2057
2058 /* Set the stack pointer. According to the ABI, the SP is meant to
2059 be set _before_ the corresponding stack space is used. On AIX,
2060 this even applies when the target has been completely stopped!
2061 Not doing this can lead to conflicts with the kernel which thinks
2062 that it still has control over this not-yet-allocated stack
2063 region. */
2064 regcache_raw_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp);
2065
2066 /* Set back chain properly. */
2067 store_unsigned_integer (tmp_buffer, wordsize, saved_sp);
2068 write_memory (sp, tmp_buffer, wordsize);
2069
2070 /* Point the inferior function call's return address at the dummy's
2071 breakpoint. */
2072 regcache_raw_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
2073
2074 /* Set the TOC register, get the value from the objfile reader
2075 which, in turn, gets it from the VMAP table. */
2076 if (rs6000_find_toc_address_hook != NULL)
2077 {
2078 CORE_ADDR tocvalue = (*rs6000_find_toc_address_hook) (func_addr);
2079 regcache_raw_write_signed (regcache, tdep->ppc_toc_regnum, tocvalue);
2080 }
2081
2082 target_store_registers (regcache, -1);
2083 return sp;
2084 }
2085
2086 static enum return_value_convention
2087 rs6000_return_value (struct gdbarch *gdbarch, struct type *valtype,
2088 struct regcache *regcache, gdb_byte *readbuf,
2089 const gdb_byte *writebuf)
2090 {
2091 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2092 gdb_byte buf[8];
2093
2094 /* The calling convention this function implements assumes the
2095 processor has floating-point registers. We shouldn't be using it
2096 on PowerPC variants that lack them. */
2097 gdb_assert (ppc_floating_point_unit_p (gdbarch));
2098
2099 /* AltiVec extension: Functions that declare a vector data type as a
2100 return value place that return value in VR2. */
2101 if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype)
2102 && TYPE_LENGTH (valtype) == 16)
2103 {
2104 if (readbuf)
2105 regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
2106 if (writebuf)
2107 regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf);
2108
2109 return RETURN_VALUE_REGISTER_CONVENTION;
2110 }
2111
2112 /* If the called subprogram returns an aggregate, there exists an
2113 implicit first argument, whose value is the address of a caller-
2114 allocated buffer into which the callee is assumed to store its
2115 return value. All explicit parameters are appropriately
2116 relabeled. */
2117 if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT
2118 || TYPE_CODE (valtype) == TYPE_CODE_UNION
2119 || TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
2120 return RETURN_VALUE_STRUCT_CONVENTION;
2121
2122 /* Scalar floating-point values are returned in FPR1 for float or
2123 double, and in FPR1:FPR2 for quadword precision. Fortran
2124 complex*8 and complex*16 are returned in FPR1:FPR2, and
2125 complex*32 is returned in FPR1:FPR4. */
2126 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
2127 && (TYPE_LENGTH (valtype) == 4 || TYPE_LENGTH (valtype) == 8))
2128 {
2129 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
2130 gdb_byte regval[8];
2131
2132 /* FIXME: kettenis/2007-01-01: Add support for quadword
2133 precision and complex. */
2134
2135 if (readbuf)
2136 {
2137 regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
2138 convert_typed_floating (regval, regtype, readbuf, valtype);
2139 }
2140 if (writebuf)
2141 {
2142 convert_typed_floating (writebuf, valtype, regval, regtype);
2143 regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
2144 }
2145
2146 return RETURN_VALUE_REGISTER_CONVENTION;
2147 }
2148
2149 /* Values of the types int, long, short, pointer, and char (length
2150 is less than or equal to four bytes), as well as bit values of
2151 lengths less than or equal to 32 bits, must be returned right
2152 justified in GPR3 with signed values sign extended and unsigned
2153 values zero extended, as necessary. */
2154 if (TYPE_LENGTH (valtype) <= tdep->wordsize)
2155 {
2156 if (readbuf)
2157 {
2158 ULONGEST regval;
2159
2160 /* For reading we don't have to worry about sign extension. */
2161 regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
2162 &regval);
2163 store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), regval);
2164 }
2165 if (writebuf)
2166 {
2167 /* For writing, use unpack_long since that should handle any
2168 required sign extension. */
2169 regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
2170 unpack_long (valtype, writebuf));
2171 }
2172
2173 return RETURN_VALUE_REGISTER_CONVENTION;
2174 }
2175
2176 /* Eight-byte non-floating-point scalar values must be returned in
2177 GPR3:GPR4. */
2178
2179 if (TYPE_LENGTH (valtype) == 8)
2180 {
2181 gdb_assert (TYPE_CODE (valtype) != TYPE_CODE_FLT);
2182 gdb_assert (tdep->wordsize == 4);
2183
2184 if (readbuf)
2185 {
2186 gdb_byte regval[8];
2187
2188 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, regval);
2189 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
2190 regval + 4);
2191 memcpy (readbuf, regval, 8);
2192 }
2193 if (writebuf)
2194 {
2195 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf);
2196 regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
2197 writebuf + 4);
2198 }
2199
2200 return RETURN_VALUE_REGISTER_CONVENTION;
2201 }
2202
2203 return RETURN_VALUE_STRUCT_CONVENTION;
2204 }
2205
2206 /* Return whether handle_inferior_event() should proceed through code
2207 starting at PC in function NAME when stepping.
2208
2209 The AIX -bbigtoc linker option generates functions @FIX0, @FIX1, etc. to
2210 handle memory references that are too distant to fit in instructions
2211 generated by the compiler. For example, if 'foo' in the following
2212 instruction:
2213
2214 lwz r9,foo(r2)
2215
2216 is greater than 32767, the linker might replace the lwz with a branch to
2217 somewhere in @FIX1 that does the load in 2 instructions and then branches
2218 back to where execution should continue.
2219
2220 GDB should silently step over @FIX code, just like AIX dbx does.
2221 Unfortunately, the linker uses the "b" instruction for the
2222 branches, meaning that the link register doesn't get set.
2223 Therefore, GDB's usual step_over_function () mechanism won't work.
2224
2225 Instead, use the gdbarch_skip_trampoline_code and
2226 gdbarch_skip_trampoline_code hooks in handle_inferior_event() to skip past
2227 @FIX code. */
2228
2229 int
2230 rs6000_in_solib_return_trampoline (CORE_ADDR pc, char *name)
2231 {
2232 return name && !strncmp (name, "@FIX", 4);
2233 }
2234
2235 /* Skip code that the user doesn't want to see when stepping:
2236
2237 1. Indirect function calls use a piece of trampoline code to do context
2238 switching, i.e. to set the new TOC table. Skip such code if we are on
2239 its first instruction (as when we have single-stepped to here).
2240
2241 2. Skip shared library trampoline code (which is different from
2242 indirect function call trampolines).
2243
2244 3. Skip bigtoc fixup code.
2245
2246 Result is desired PC to step until, or NULL if we are not in
2247 code that should be skipped. */
2248
2249 CORE_ADDR
2250 rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
2251 {
2252 unsigned int ii, op;
2253 int rel;
2254 CORE_ADDR solib_target_pc;
2255 struct minimal_symbol *msymbol;
2256
2257 static unsigned trampoline_code[] =
2258 {
2259 0x800b0000, /* l r0,0x0(r11) */
2260 0x90410014, /* st r2,0x14(r1) */
2261 0x7c0903a6, /* mtctr r0 */
2262 0x804b0004, /* l r2,0x4(r11) */
2263 0x816b0008, /* l r11,0x8(r11) */
2264 0x4e800420, /* bctr */
2265 0x4e800020, /* br */
2266 0
2267 };
2268
2269 /* Check for bigtoc fixup code. */
2270 msymbol = lookup_minimal_symbol_by_pc (pc);
2271 if (msymbol
2272 && rs6000_in_solib_return_trampoline (pc,
2273 DEPRECATED_SYMBOL_NAME (msymbol)))
2274 {
2275 /* Double-check that the third instruction from PC is relative "b". */
2276 op = read_memory_integer (pc + 8, 4);
2277 if ((op & 0xfc000003) == 0x48000000)
2278 {
2279 /* Extract bits 6-29 as a signed 24-bit relative word address and
2280 add it to the containing PC. */
2281 rel = ((int)(op << 6) >> 6);
2282 return pc + 8 + rel;
2283 }
2284 }
2285
2286 /* If pc is in a shared library trampoline, return its target. */
2287 solib_target_pc = find_solib_trampoline_target (frame, pc);
2288 if (solib_target_pc)
2289 return solib_target_pc;
2290
2291 for (ii = 0; trampoline_code[ii]; ++ii)
2292 {
2293 op = read_memory_integer (pc + (ii * 4), 4);
2294 if (op != trampoline_code[ii])
2295 return 0;
2296 }
2297 ii = get_frame_register_unsigned (frame, 11); /* r11 holds destination addr */
2298 pc = read_memory_addr (ii,
2299 gdbarch_tdep (get_frame_arch (frame))->wordsize); /* (r11) value */
2300 return pc;
2301 }
2302
2303 /* ISA-specific vector types. */
2304
2305 static struct type *
2306 rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
2307 {
2308 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2309
2310 if (!tdep->ppc_builtin_type_vec64)
2311 {
2312 /* The type we're building is this: */
2313 #if 0
2314 union __gdb_builtin_type_vec64
2315 {
2316 int64_t uint64;
2317 float v2_float[2];
2318 int32_t v2_int32[2];
2319 int16_t v4_int16[4];
2320 int8_t v8_int8[8];
2321 };
2322 #endif
2323
2324 struct type *t;
2325
2326 t = init_composite_type ("__ppc_builtin_type_vec64", TYPE_CODE_UNION);
2327 append_composite_type_field (t, "uint64", builtin_type_int64);
2328 append_composite_type_field (t, "v2_float",
2329 init_vector_type (builtin_type_float, 2));
2330 append_composite_type_field (t, "v2_int32",
2331 init_vector_type (builtin_type_int32, 2));
2332 append_composite_type_field (t, "v4_int16",
2333 init_vector_type (builtin_type_int16, 4));
2334 append_composite_type_field (t, "v8_int8",
2335 init_vector_type (builtin_type_int8, 8));
2336
2337 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
2338 TYPE_NAME (t) = "ppc_builtin_type_vec64";
2339 tdep->ppc_builtin_type_vec64 = t;
2340 }
2341
2342 return tdep->ppc_builtin_type_vec64;
2343 }
2344
2345 /* Return the size of register REG when words are WORDSIZE bytes long. If REG
2346 isn't available with that word size, return 0. */
2347
2348 static int
2349 regsize (const struct reg *reg, int wordsize)
2350 {
2351 return wordsize == 8 ? reg->sz64 : reg->sz32;
2352 }
2353
2354 /* Return the name of register number REGNO, or the empty string if it
2355 is an anonymous register. */
2356
2357 static const char *
2358 rs6000_register_name (int regno)
2359 {
2360 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2361
2362 /* The upper half "registers" have names in the XML description,
2363 but we present only the low GPRs and the full 64-bit registers
2364 to the user. */
2365 if (tdep->ppc_ev0_upper_regnum >= 0
2366 && tdep->ppc_ev0_upper_regnum <= regno
2367 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
2368 return "";
2369
2370 /* Check if the SPE pseudo registers are available. */
2371 if (tdep->ppc_ev0_regnum >= 0
2372 && tdep->ppc_ev0_regnum <= regno
2373 && regno < tdep->ppc_ev0_regnum + ppc_num_gprs)
2374 {
2375 static const char *const spe_regnames[] = {
2376 "ev0", "ev1", "ev2", "ev3", "ev4", "ev5", "ev6", "ev7",
2377 "ev8", "ev9", "ev10", "ev11", "ev12", "ev13", "ev14", "ev15",
2378 "ev16", "ev17", "ev18", "ev19", "ev20", "ev21", "ev22", "ev23",
2379 "ev24", "ev25", "ev26", "ev27", "ev28", "ev29", "ev30", "ev31",
2380 };
2381 return spe_regnames[regno - tdep->ppc_ev0_regnum];
2382 }
2383
2384 return tdesc_register_name (regno);
2385 }
2386
2387 /* Return the GDB type object for the "standard" data type of data in
2388 register N. */
2389
2390 static struct type *
2391 rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
2392 {
2393 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2394
2395 /* These are the only pseudo-registers we support. */
2396 gdb_assert (tdep->ppc_ev0_regnum >= 0
2397 && regnum >= tdep->ppc_ev0_regnum
2398 && regnum < tdep->ppc_ev0_regnum + 32);
2399
2400 return rs6000_builtin_type_vec64 (gdbarch);
2401 }
2402
2403 /* Is REGNUM a member of REGGROUP? */
2404 static int
2405 rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
2406 struct reggroup *group)
2407 {
2408 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2409
2410 /* These are the only pseudo-registers we support. */
2411 gdb_assert (tdep->ppc_ev0_regnum >= 0
2412 && regnum >= tdep->ppc_ev0_regnum
2413 && regnum < tdep->ppc_ev0_regnum + 32);
2414
2415 if (group == all_reggroup || group == vector_reggroup)
2416 return 1;
2417 else
2418 return 0;
2419 }
2420
2421 /* The register format for RS/6000 floating point registers is always
2422 double, we need a conversion if the memory format is float. */
2423
2424 static int
2425 rs6000_convert_register_p (int regnum, struct type *type)
2426 {
2427 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2428
2429 return (tdep->ppc_fp0_regnum >= 0
2430 && regnum >= tdep->ppc_fp0_regnum
2431 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs
2432 && TYPE_CODE (type) == TYPE_CODE_FLT
2433 && TYPE_LENGTH (type) != TYPE_LENGTH (builtin_type_double));
2434 }
2435
2436 static void
2437 rs6000_register_to_value (struct frame_info *frame,
2438 int regnum,
2439 struct type *type,
2440 gdb_byte *to)
2441 {
2442 gdb_byte from[MAX_REGISTER_SIZE];
2443
2444 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
2445
2446 get_frame_register (frame, regnum, from);
2447 convert_typed_floating (from, builtin_type_double, to, type);
2448 }
2449
2450 static void
2451 rs6000_value_to_register (struct frame_info *frame,
2452 int regnum,
2453 struct type *type,
2454 const gdb_byte *from)
2455 {
2456 gdb_byte to[MAX_REGISTER_SIZE];
2457
2458 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
2459
2460 convert_typed_floating (from, type, to, builtin_type_double);
2461 put_frame_register (frame, regnum, to);
2462 }
2463
2464 /* Move SPE vector register values between a 64-bit buffer and the two
2465 32-bit raw register halves in a regcache. This function handles
2466 both splitting a 64-bit value into two 32-bit halves, and joining
2467 two halves into a whole 64-bit value, depending on the function
2468 passed as the MOVE argument.
2469
2470 EV_REG must be the number of an SPE evN vector register --- a
2471 pseudoregister. REGCACHE must be a regcache, and BUFFER must be a
2472 64-bit buffer.
2473
2474 Call MOVE once for each 32-bit half of that register, passing
2475 REGCACHE, the number of the raw register corresponding to that
2476 half, and the address of the appropriate half of BUFFER.
2477
2478 For example, passing 'regcache_raw_read' as the MOVE function will
2479 fill BUFFER with the full 64-bit contents of EV_REG. Or, passing
2480 'regcache_raw_supply' will supply the contents of BUFFER to the
2481 appropriate pair of raw registers in REGCACHE.
2482
2483 You may need to cast away some 'const' qualifiers when passing
2484 MOVE, since this function can't tell at compile-time which of
2485 REGCACHE or BUFFER is acting as the source of the data. If C had
2486 co-variant type qualifiers, ... */
2487 static void
2488 e500_move_ev_register (void (*move) (struct regcache *regcache,
2489 int regnum, gdb_byte *buf),
2490 struct regcache *regcache, int ev_reg,
2491 gdb_byte *buffer)
2492 {
2493 struct gdbarch *arch = get_regcache_arch (regcache);
2494 struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
2495 int reg_index;
2496 gdb_byte *byte_buffer = buffer;
2497
2498 gdb_assert (tdep->ppc_ev0_regnum <= ev_reg
2499 && ev_reg < tdep->ppc_ev0_regnum + ppc_num_gprs);
2500
2501 reg_index = ev_reg - tdep->ppc_ev0_regnum;
2502
2503 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
2504 {
2505 move (regcache, tdep->ppc_ev0_upper_regnum + reg_index, byte_buffer);
2506 move (regcache, tdep->ppc_gp0_regnum + reg_index, byte_buffer + 4);
2507 }
2508 else
2509 {
2510 move (regcache, tdep->ppc_gp0_regnum + reg_index, byte_buffer);
2511 move (regcache, tdep->ppc_ev0_upper_regnum + reg_index, byte_buffer + 4);
2512 }
2513 }
2514
2515 static void
2516 e500_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
2517 int reg_nr, gdb_byte *buffer)
2518 {
2519 struct gdbarch *regcache_arch = get_regcache_arch (regcache);
2520 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2521
2522 gdb_assert (regcache_arch == gdbarch);
2523
2524 if (tdep->ppc_ev0_regnum <= reg_nr
2525 && reg_nr < tdep->ppc_ev0_regnum + ppc_num_gprs)
2526 e500_move_ev_register (regcache_raw_read, regcache, reg_nr, buffer);
2527 else
2528 internal_error (__FILE__, __LINE__,
2529 _("e500_pseudo_register_read: "
2530 "called on unexpected register '%s' (%d)"),
2531 gdbarch_register_name (gdbarch, reg_nr), reg_nr);
2532 }
2533
2534 static void
2535 e500_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
2536 int reg_nr, const gdb_byte *buffer)
2537 {
2538 struct gdbarch *regcache_arch = get_regcache_arch (regcache);
2539 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2540
2541 gdb_assert (regcache_arch == gdbarch);
2542
2543 if (tdep->ppc_ev0_regnum <= reg_nr
2544 && reg_nr < tdep->ppc_ev0_regnum + ppc_num_gprs)
2545 e500_move_ev_register ((void (*) (struct regcache *, int, gdb_byte *))
2546 regcache_raw_write,
2547 regcache, reg_nr, (gdb_byte *) buffer);
2548 else
2549 internal_error (__FILE__, __LINE__,
2550 _("e500_pseudo_register_read: "
2551 "called on unexpected register '%s' (%d)"),
2552 gdbarch_register_name (gdbarch, reg_nr), reg_nr);
2553 }
2554
2555 /* Convert a DBX STABS register number to a GDB register number. */
2556 static int
2557 rs6000_stab_reg_to_regnum (int num)
2558 {
2559 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2560
2561 if (0 <= num && num <= 31)
2562 return tdep->ppc_gp0_regnum + num;
2563 else if (32 <= num && num <= 63)
2564 /* FIXME: jimb/2004-05-05: What should we do when the debug info
2565 specifies registers the architecture doesn't have? Our
2566 callers don't check the value we return. */
2567 return tdep->ppc_fp0_regnum + (num - 32);
2568 else if (77 <= num && num <= 108)
2569 return tdep->ppc_vr0_regnum + (num - 77);
2570 else if (1200 <= num && num < 1200 + 32)
2571 return tdep->ppc_ev0_regnum + (num - 1200);
2572 else
2573 switch (num)
2574 {
2575 case 64:
2576 return tdep->ppc_mq_regnum;
2577 case 65:
2578 return tdep->ppc_lr_regnum;
2579 case 66:
2580 return tdep->ppc_ctr_regnum;
2581 case 76:
2582 return tdep->ppc_xer_regnum;
2583 case 109:
2584 return tdep->ppc_vrsave_regnum;
2585 case 110:
2586 return tdep->ppc_vrsave_regnum - 1; /* vscr */
2587 case 111:
2588 return tdep->ppc_acc_regnum;
2589 case 112:
2590 return tdep->ppc_spefscr_regnum;
2591 default:
2592 return num;
2593 }
2594 }
2595
2596
2597 /* Convert a Dwarf 2 register number to a GDB register number. */
2598 static int
2599 rs6000_dwarf2_reg_to_regnum (int num)
2600 {
2601 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2602
2603 if (0 <= num && num <= 31)
2604 return tdep->ppc_gp0_regnum + num;
2605 else if (32 <= num && num <= 63)
2606 /* FIXME: jimb/2004-05-05: What should we do when the debug info
2607 specifies registers the architecture doesn't have? Our
2608 callers don't check the value we return. */
2609 return tdep->ppc_fp0_regnum + (num - 32);
2610 else if (1124 <= num && num < 1124 + 32)
2611 return tdep->ppc_vr0_regnum + (num - 1124);
2612 else if (1200 <= num && num < 1200 + 32)
2613 return tdep->ppc_ev0_regnum + (num - 1200);
2614 else
2615 switch (num)
2616 {
2617 case 64:
2618 return tdep->ppc_cr_regnum;
2619 case 67:
2620 return tdep->ppc_vrsave_regnum - 1; /* vscr */
2621 case 99:
2622 return tdep->ppc_acc_regnum;
2623 case 100:
2624 return tdep->ppc_mq_regnum;
2625 case 101:
2626 return tdep->ppc_xer_regnum;
2627 case 108:
2628 return tdep->ppc_lr_regnum;
2629 case 109:
2630 return tdep->ppc_ctr_regnum;
2631 case 356:
2632 return tdep->ppc_vrsave_regnum;
2633 case 612:
2634 return tdep->ppc_spefscr_regnum;
2635 default:
2636 return num;
2637 }
2638 }
2639
2640 /* Translate a .eh_frame register to DWARF register, or adjust a
2641 .debug_frame register. */
2642
2643 static int
2644 rs6000_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p)
2645 {
2646 /* GCC releases before 3.4 use GCC internal register numbering in
2647 .debug_frame (and .debug_info, et cetera). The numbering is
2648 different from the standard SysV numbering for everything except
2649 for GPRs and FPRs. We can not detect this problem in most cases
2650 - to get accurate debug info for variables living in lr, ctr, v0,
2651 et cetera, use a newer version of GCC. But we must detect
2652 one important case - lr is in column 65 in .debug_frame output,
2653 instead of 108.
2654
2655 GCC 3.4, and the "hammer" branch, have a related problem. They
2656 record lr register saves in .debug_frame as 108, but still record
2657 the return column as 65. We fix that up too.
2658
2659 We can do this because 65 is assigned to fpsr, and GCC never
2660 generates debug info referring to it. To add support for
2661 handwritten debug info that restores fpsr, we would need to add a
2662 producer version check to this. */
2663 if (!eh_frame_p)
2664 {
2665 if (num == 65)
2666 return 108;
2667 else
2668 return num;
2669 }
2670
2671 /* .eh_frame is GCC specific. For binary compatibility, it uses GCC
2672 internal register numbering; translate that to the standard DWARF2
2673 register numbering. */
2674 if (0 <= num && num <= 63) /* r0-r31,fp0-fp31 */
2675 return num;
2676 else if (68 <= num && num <= 75) /* cr0-cr8 */
2677 return num - 68 + 86;
2678 else if (77 <= num && num <= 108) /* vr0-vr31 */
2679 return num - 77 + 1124;
2680 else
2681 switch (num)
2682 {
2683 case 64: /* mq */
2684 return 100;
2685 case 65: /* lr */
2686 return 108;
2687 case 66: /* ctr */
2688 return 109;
2689 case 76: /* xer */
2690 return 101;
2691 case 109: /* vrsave */
2692 return 356;
2693 case 110: /* vscr */
2694 return 67;
2695 case 111: /* spe_acc */
2696 return 99;
2697 case 112: /* spefscr */
2698 return 612;
2699 default:
2700 return num;
2701 }
2702 }
2703 \f
2704 /* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
2705
2706 Usually a function pointer's representation is simply the address
2707 of the function. On the RS/6000 however, a function pointer is
2708 represented by a pointer to an OPD entry. This OPD entry contains
2709 three words, the first word is the address of the function, the
2710 second word is the TOC pointer (r2), and the third word is the
2711 static chain value. Throughout GDB it is currently assumed that a
2712 function pointer contains the address of the function, which is not
2713 easy to fix. In addition, the conversion of a function address to
2714 a function pointer would require allocation of an OPD entry in the
2715 inferior's memory space, with all its drawbacks. To be able to
2716 call C++ virtual methods in the inferior (which are called via
2717 function pointers), find_function_addr uses this function to get the
2718 function address from a function pointer. */
2719
2720 /* Return real function address if ADDR (a function pointer) is in the data
2721 space and is therefore a special function pointer. */
2722
2723 static CORE_ADDR
2724 rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
2725 CORE_ADDR addr,
2726 struct target_ops *targ)
2727 {
2728 struct obj_section *s;
2729
2730 s = find_pc_section (addr);
2731 if (s && s->the_bfd_section->flags & SEC_CODE)
2732 return addr;
2733
2734 /* ADDR is in the data space, so it's a special function pointer. */
2735 return read_memory_addr (addr, gdbarch_tdep (gdbarch)->wordsize);
2736 }
2737 \f
2738
2739 /* Handling the various POWER/PowerPC variants. */
2740
2741 /* Information about a particular processor variant. */
2742
2743 struct variant
2744 {
2745 /* Name of this variant. */
2746 char *name;
2747
2748 /* English description of the variant. */
2749 char *description;
2750
2751 /* bfd_arch_info.arch corresponding to variant. */
2752 enum bfd_architecture arch;
2753
2754 /* bfd_arch_info.mach corresponding to variant. */
2755 unsigned long mach;
2756
2757 /* Target description for this variant. */
2758 struct target_desc **tdesc;
2759 };
2760
2761 static struct variant variants[] =
2762 {
2763 {"powerpc", "PowerPC user-level", bfd_arch_powerpc,
2764 bfd_mach_ppc, &tdesc_powerpc_32},
2765 {"power", "POWER user-level", bfd_arch_rs6000,
2766 bfd_mach_rs6k, &tdesc_rs6000},
2767 {"403", "IBM PowerPC 403", bfd_arch_powerpc,
2768 bfd_mach_ppc_403, &tdesc_powerpc_403},
2769 {"601", "Motorola PowerPC 601", bfd_arch_powerpc,
2770 bfd_mach_ppc_601, &tdesc_powerpc_601},
2771 {"602", "Motorola PowerPC 602", bfd_arch_powerpc,
2772 bfd_mach_ppc_602, &tdesc_powerpc_602},
2773 {"603", "Motorola/IBM PowerPC 603 or 603e", bfd_arch_powerpc,
2774 bfd_mach_ppc_603, &tdesc_powerpc_603},
2775 {"604", "Motorola PowerPC 604 or 604e", bfd_arch_powerpc,
2776 604, &tdesc_powerpc_604},
2777 {"403GC", "IBM PowerPC 403GC", bfd_arch_powerpc,
2778 bfd_mach_ppc_403gc, &tdesc_powerpc_403gc},
2779 {"505", "Motorola PowerPC 505", bfd_arch_powerpc,
2780 bfd_mach_ppc_505, &tdesc_powerpc_505},
2781 {"860", "Motorola PowerPC 860 or 850", bfd_arch_powerpc,
2782 bfd_mach_ppc_860, &tdesc_powerpc_860},
2783 {"750", "Motorola/IBM PowerPC 750 or 740", bfd_arch_powerpc,
2784 bfd_mach_ppc_750, &tdesc_powerpc_750},
2785 {"7400", "Motorola/IBM PowerPC 7400 (G4)", bfd_arch_powerpc,
2786 bfd_mach_ppc_7400, &tdesc_powerpc_7400},
2787 {"e500", "Motorola PowerPC e500", bfd_arch_powerpc,
2788 bfd_mach_ppc_e500, &tdesc_powerpc_e500},
2789
2790 /* 64-bit */
2791 {"powerpc64", "PowerPC 64-bit user-level", bfd_arch_powerpc,
2792 bfd_mach_ppc64, &tdesc_powerpc_64},
2793 {"620", "Motorola PowerPC 620", bfd_arch_powerpc,
2794 bfd_mach_ppc_620, &tdesc_powerpc_64},
2795 {"630", "Motorola PowerPC 630", bfd_arch_powerpc,
2796 bfd_mach_ppc_630, &tdesc_powerpc_64},
2797 {"a35", "PowerPC A35", bfd_arch_powerpc,
2798 bfd_mach_ppc_a35, &tdesc_powerpc_64},
2799 {"rs64ii", "PowerPC rs64ii", bfd_arch_powerpc,
2800 bfd_mach_ppc_rs64ii, &tdesc_powerpc_64},
2801 {"rs64iii", "PowerPC rs64iii", bfd_arch_powerpc,
2802 bfd_mach_ppc_rs64iii, &tdesc_powerpc_64},
2803
2804 /* FIXME: I haven't checked the register sets of the following. */
2805 {"rs1", "IBM POWER RS1", bfd_arch_rs6000,
2806 bfd_mach_rs6k_rs1, &tdesc_rs6000},
2807 {"rsc", "IBM POWER RSC", bfd_arch_rs6000,
2808 bfd_mach_rs6k_rsc, &tdesc_rs6000},
2809 {"rs2", "IBM POWER RS2", bfd_arch_rs6000,
2810 bfd_mach_rs6k_rs2, &tdesc_rs6000},
2811
2812 {0, 0, 0, 0, 0}
2813 };
2814
2815 /* Return the variant corresponding to architecture ARCH and machine number
2816 MACH. If no such variant exists, return null. */
2817
2818 static const struct variant *
2819 find_variant_by_arch (enum bfd_architecture arch, unsigned long mach)
2820 {
2821 const struct variant *v;
2822
2823 for (v = variants; v->name; v++)
2824 if (arch == v->arch && mach == v->mach)
2825 return v;
2826
2827 return NULL;
2828 }
2829
2830 static int
2831 gdb_print_insn_powerpc (bfd_vma memaddr, disassemble_info *info)
2832 {
2833 if (!info->disassembler_options)
2834 info->disassembler_options = "any";
2835
2836 if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
2837 return print_insn_big_powerpc (memaddr, info);
2838 else
2839 return print_insn_little_powerpc (memaddr, info);
2840 }
2841 \f
2842 static CORE_ADDR
2843 rs6000_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
2844 {
2845 return frame_unwind_register_unsigned (next_frame,
2846 gdbarch_pc_regnum (gdbarch));
2847 }
2848
2849 static struct frame_id
2850 rs6000_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
2851 {
2852 return frame_id_build (frame_unwind_register_unsigned
2853 (next_frame, gdbarch_sp_regnum (gdbarch)),
2854 frame_pc_unwind (next_frame));
2855 }
2856
2857 struct rs6000_frame_cache
2858 {
2859 CORE_ADDR base;
2860 CORE_ADDR initial_sp;
2861 struct trad_frame_saved_reg *saved_regs;
2862 };
2863
2864 static struct rs6000_frame_cache *
2865 rs6000_frame_cache (struct frame_info *next_frame, void **this_cache)
2866 {
2867 struct rs6000_frame_cache *cache;
2868 struct gdbarch *gdbarch = get_frame_arch (next_frame);
2869 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2870 struct rs6000_framedata fdata;
2871 int wordsize = tdep->wordsize;
2872 CORE_ADDR func, pc;
2873
2874 if ((*this_cache) != NULL)
2875 return (*this_cache);
2876 cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache);
2877 (*this_cache) = cache;
2878 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
2879
2880 func = frame_func_unwind (next_frame, NORMAL_FRAME);
2881 pc = frame_pc_unwind (next_frame);
2882 skip_prologue (func, pc, &fdata);
2883
2884 /* Figure out the parent's stack pointer. */
2885
2886 /* NOTE: cagney/2002-04-14: The ->frame points to the inner-most
2887 address of the current frame. Things might be easier if the
2888 ->frame pointed to the outer-most address of the frame. In
2889 the mean time, the address of the prev frame is used as the
2890 base address of this frame. */
2891 cache->base = frame_unwind_register_unsigned
2892 (next_frame, gdbarch_sp_regnum (gdbarch));
2893
2894 /* If the function appears to be frameless, check a couple of likely
2895 indicators that we have simply failed to find the frame setup.
2896 Two common cases of this are missing symbols (i.e.
2897 frame_func_unwind returns the wrong address or 0), and assembly
2898 stubs which have a fast exit path but set up a frame on the slow
2899 path.
2900
2901 If the LR appears to return to this function, then presume that
2902 we have an ABI compliant frame that we failed to find. */
2903 if (fdata.frameless && fdata.lr_offset == 0)
2904 {
2905 CORE_ADDR saved_lr;
2906 int make_frame = 0;
2907
2908 saved_lr = frame_unwind_register_unsigned (next_frame,
2909 tdep->ppc_lr_regnum);
2910 if (func == 0 && saved_lr == pc)
2911 make_frame = 1;
2912 else if (func != 0)
2913 {
2914 CORE_ADDR saved_func = get_pc_function_start (saved_lr);
2915 if (func == saved_func)
2916 make_frame = 1;
2917 }
2918
2919 if (make_frame)
2920 {
2921 fdata.frameless = 0;
2922 fdata.lr_offset = tdep->lr_frame_offset;
2923 }
2924 }
2925
2926 if (!fdata.frameless)
2927 /* Frameless really means stackless. */
2928 cache->base = read_memory_addr (cache->base, wordsize);
2929
2930 trad_frame_set_value (cache->saved_regs,
2931 gdbarch_sp_regnum (gdbarch), cache->base);
2932
2933 /* if != -1, fdata.saved_fpr is the smallest number of saved_fpr.
2934 All fpr's from saved_fpr to fp31 are saved. */
2935
2936 if (fdata.saved_fpr >= 0)
2937 {
2938 int i;
2939 CORE_ADDR fpr_addr = cache->base + fdata.fpr_offset;
2940
2941 /* If skip_prologue says floating-point registers were saved,
2942 but the current architecture has no floating-point registers,
2943 then that's strange. But we have no indices to even record
2944 the addresses under, so we just ignore it. */
2945 if (ppc_floating_point_unit_p (gdbarch))
2946 for (i = fdata.saved_fpr; i < ppc_num_fprs; i++)
2947 {
2948 cache->saved_regs[tdep->ppc_fp0_regnum + i].addr = fpr_addr;
2949 fpr_addr += 8;
2950 }
2951 }
2952
2953 /* if != -1, fdata.saved_gpr is the smallest number of saved_gpr.
2954 All gpr's from saved_gpr to gpr31 are saved. */
2955
2956 if (fdata.saved_gpr >= 0)
2957 {
2958 int i;
2959 CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset;
2960 for (i = fdata.saved_gpr; i < ppc_num_gprs; i++)
2961 {
2962 cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = gpr_addr;
2963 gpr_addr += wordsize;
2964 }
2965 }
2966
2967 /* if != -1, fdata.saved_vr is the smallest number of saved_vr.
2968 All vr's from saved_vr to vr31 are saved. */
2969 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
2970 {
2971 if (fdata.saved_vr >= 0)
2972 {
2973 int i;
2974 CORE_ADDR vr_addr = cache->base + fdata.vr_offset;
2975 for (i = fdata.saved_vr; i < 32; i++)
2976 {
2977 cache->saved_regs[tdep->ppc_vr0_regnum + i].addr = vr_addr;
2978 vr_addr += register_size (gdbarch, tdep->ppc_vr0_regnum);
2979 }
2980 }
2981 }
2982
2983 /* if != -1, fdata.saved_ev is the smallest number of saved_ev.
2984 All vr's from saved_ev to ev31 are saved. ????? */
2985 if (tdep->ppc_ev0_regnum != -1 && tdep->ppc_ev31_regnum != -1)
2986 {
2987 if (fdata.saved_ev >= 0)
2988 {
2989 int i;
2990 CORE_ADDR ev_addr = cache->base + fdata.ev_offset;
2991 for (i = fdata.saved_ev; i < ppc_num_gprs; i++)
2992 {
2993 cache->saved_regs[tdep->ppc_ev0_regnum + i].addr = ev_addr;
2994 cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = ev_addr + 4;
2995 ev_addr += register_size (gdbarch, tdep->ppc_ev0_regnum);
2996 }
2997 }
2998 }
2999
3000 /* If != 0, fdata.cr_offset is the offset from the frame that
3001 holds the CR. */
3002 if (fdata.cr_offset != 0)
3003 cache->saved_regs[tdep->ppc_cr_regnum].addr = cache->base + fdata.cr_offset;
3004
3005 /* If != 0, fdata.lr_offset is the offset from the frame that
3006 holds the LR. */
3007 if (fdata.lr_offset != 0)
3008 cache->saved_regs[tdep->ppc_lr_regnum].addr = cache->base + fdata.lr_offset;
3009 /* The PC is found in the link register. */
3010 cache->saved_regs[gdbarch_pc_regnum (gdbarch)] =
3011 cache->saved_regs[tdep->ppc_lr_regnum];
3012
3013 /* If != 0, fdata.vrsave_offset is the offset from the frame that
3014 holds the VRSAVE. */
3015 if (fdata.vrsave_offset != 0)
3016 cache->saved_regs[tdep->ppc_vrsave_regnum].addr = cache->base + fdata.vrsave_offset;
3017
3018 if (fdata.alloca_reg < 0)
3019 /* If no alloca register used, then fi->frame is the value of the
3020 %sp for this frame, and it is good enough. */
3021 cache->initial_sp = frame_unwind_register_unsigned
3022 (next_frame, gdbarch_sp_regnum (gdbarch));
3023 else
3024 cache->initial_sp = frame_unwind_register_unsigned (next_frame,
3025 fdata.alloca_reg);
3026
3027 return cache;
3028 }
3029
3030 static void
3031 rs6000_frame_this_id (struct frame_info *next_frame, void **this_cache,
3032 struct frame_id *this_id)
3033 {
3034 struct rs6000_frame_cache *info = rs6000_frame_cache (next_frame,
3035 this_cache);
3036 (*this_id) = frame_id_build (info->base,
3037 frame_func_unwind (next_frame, NORMAL_FRAME));
3038 }
3039
3040 static void
3041 rs6000_frame_prev_register (struct frame_info *next_frame,
3042 void **this_cache,
3043 int regnum, int *optimizedp,
3044 enum lval_type *lvalp, CORE_ADDR *addrp,
3045 int *realnump, gdb_byte *valuep)
3046 {
3047 struct rs6000_frame_cache *info = rs6000_frame_cache (next_frame,
3048 this_cache);
3049 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
3050 optimizedp, lvalp, addrp, realnump, valuep);
3051 }
3052
3053 static const struct frame_unwind rs6000_frame_unwind =
3054 {
3055 NORMAL_FRAME,
3056 rs6000_frame_this_id,
3057 rs6000_frame_prev_register
3058 };
3059
3060 static const struct frame_unwind *
3061 rs6000_frame_sniffer (struct frame_info *next_frame)
3062 {
3063 return &rs6000_frame_unwind;
3064 }
3065
3066 \f
3067
3068 static CORE_ADDR
3069 rs6000_frame_base_address (struct frame_info *next_frame,
3070 void **this_cache)
3071 {
3072 struct rs6000_frame_cache *info = rs6000_frame_cache (next_frame,
3073 this_cache);
3074 return info->initial_sp;
3075 }
3076
3077 static const struct frame_base rs6000_frame_base = {
3078 &rs6000_frame_unwind,
3079 rs6000_frame_base_address,
3080 rs6000_frame_base_address,
3081 rs6000_frame_base_address
3082 };
3083
3084 static const struct frame_base *
3085 rs6000_frame_base_sniffer (struct frame_info *next_frame)
3086 {
3087 return &rs6000_frame_base;
3088 }
3089
3090 /* DWARF-2 frame support. Used to handle the detection of
3091 clobbered registers during function calls. */
3092
3093 static void
3094 ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
3095 struct dwarf2_frame_state_reg *reg,
3096 struct frame_info *next_frame)
3097 {
3098 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3099
3100 /* PPC32 and PPC64 ABI's are the same regarding volatile and
3101 non-volatile registers. We will use the same code for both. */
3102
3103 /* Call-saved GP registers. */
3104 if ((regnum >= tdep->ppc_gp0_regnum + 14
3105 && regnum <= tdep->ppc_gp0_regnum + 31)
3106 || (regnum == tdep->ppc_gp0_regnum + 1))
3107 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3108
3109 /* Call-clobbered GP registers. */
3110 if ((regnum >= tdep->ppc_gp0_regnum + 3
3111 && regnum <= tdep->ppc_gp0_regnum + 12)
3112 || (regnum == tdep->ppc_gp0_regnum))
3113 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3114
3115 /* Deal with FP registers, if supported. */
3116 if (tdep->ppc_fp0_regnum >= 0)
3117 {
3118 /* Call-saved FP registers. */
3119 if ((regnum >= tdep->ppc_fp0_regnum + 14
3120 && regnum <= tdep->ppc_fp0_regnum + 31))
3121 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3122
3123 /* Call-clobbered FP registers. */
3124 if ((regnum >= tdep->ppc_fp0_regnum
3125 && regnum <= tdep->ppc_fp0_regnum + 13))
3126 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3127 }
3128
3129 /* Deal with ALTIVEC registers, if supported. */
3130 if (tdep->ppc_vr0_regnum > 0 && tdep->ppc_vrsave_regnum > 0)
3131 {
3132 /* Call-saved Altivec registers. */
3133 if ((regnum >= tdep->ppc_vr0_regnum + 20
3134 && regnum <= tdep->ppc_vr0_regnum + 31)
3135 || regnum == tdep->ppc_vrsave_regnum)
3136 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3137
3138 /* Call-clobbered Altivec registers. */
3139 if ((regnum >= tdep->ppc_vr0_regnum
3140 && regnum <= tdep->ppc_vr0_regnum + 19))
3141 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3142 }
3143
3144 /* Handle PC register and Stack Pointer correctly. */
3145 if (regnum == gdbarch_pc_regnum (current_gdbarch))
3146 reg->how = DWARF2_FRAME_REG_RA;
3147 else if (regnum == gdbarch_sp_regnum (current_gdbarch))
3148 reg->how = DWARF2_FRAME_REG_CFA;
3149 }
3150
3151
3152 /* Initialize the current architecture based on INFO. If possible, re-use an
3153 architecture from ARCHES, which is a list of architectures already created
3154 during this debugging session.
3155
3156 Called e.g. at program startup, when reading a core file, and when reading
3157 a binary file. */
3158
3159 static struct gdbarch *
3160 rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3161 {
3162 struct gdbarch *gdbarch;
3163 struct gdbarch_tdep *tdep;
3164 int wordsize, from_xcoff_exec, from_elf_exec;
3165 enum bfd_architecture arch;
3166 unsigned long mach;
3167 bfd abfd;
3168 int sysv_abi;
3169 asection *sect;
3170 enum auto_boolean soft_float_flag = powerpc_soft_float_global;
3171 int soft_float;
3172 enum powerpc_vector_abi vector_abi = powerpc_vector_abi_global;
3173 int have_fpu = 1, have_spe = 0, have_mq = 0, have_altivec = 0;
3174 int tdesc_wordsize = -1;
3175 const struct target_desc *tdesc = info.target_desc;
3176 struct tdesc_arch_data *tdesc_data = NULL;
3177 int num_sprs = 0;
3178
3179 from_xcoff_exec = info.abfd && info.abfd->format == bfd_object &&
3180 bfd_get_flavour (info.abfd) == bfd_target_xcoff_flavour;
3181
3182 from_elf_exec = info.abfd && info.abfd->format == bfd_object &&
3183 bfd_get_flavour (info.abfd) == bfd_target_elf_flavour;
3184
3185 sysv_abi = info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour;
3186
3187 /* Check word size. If INFO is from a binary file, infer it from
3188 that, else choose a likely default. */
3189 if (from_xcoff_exec)
3190 {
3191 if (bfd_xcoff_is_xcoff64 (info.abfd))
3192 wordsize = 8;
3193 else
3194 wordsize = 4;
3195 }
3196 else if (from_elf_exec)
3197 {
3198 if (elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
3199 wordsize = 8;
3200 else
3201 wordsize = 4;
3202 }
3203 else if (tdesc_has_registers (tdesc))
3204 wordsize = -1;
3205 else
3206 {
3207 if (info.bfd_arch_info != NULL && info.bfd_arch_info->bits_per_word != 0)
3208 wordsize = info.bfd_arch_info->bits_per_word /
3209 info.bfd_arch_info->bits_per_byte;
3210 else
3211 wordsize = 4;
3212 }
3213
3214 if (!from_xcoff_exec)
3215 {
3216 arch = info.bfd_arch_info->arch;
3217 mach = info.bfd_arch_info->mach;
3218 }
3219 else
3220 {
3221 arch = bfd_arch_powerpc;
3222 bfd_default_set_arch_mach (&abfd, arch, 0);
3223 info.bfd_arch_info = bfd_get_arch_info (&abfd);
3224 mach = info.bfd_arch_info->mach;
3225 }
3226
3227 /* For e500 executables, the apuinfo section is of help here. Such
3228 section contains the identifier and revision number of each
3229 Application-specific Processing Unit that is present on the
3230 chip. The content of the section is determined by the assembler
3231 which looks at each instruction and determines which unit (and
3232 which version of it) can execute it. In our case we just look for
3233 the existance of the section. */
3234
3235 if (info.abfd)
3236 {
3237 sect = bfd_get_section_by_name (info.abfd, ".PPC.EMB.apuinfo");
3238 if (sect)
3239 {
3240 arch = info.bfd_arch_info->arch;
3241 mach = bfd_mach_ppc_e500;
3242 bfd_default_set_arch_mach (&abfd, arch, mach);
3243 info.bfd_arch_info = bfd_get_arch_info (&abfd);
3244 }
3245 }
3246
3247 /* Find a default target description which describes our register
3248 layout, if we do not already have one. */
3249 if (! tdesc_has_registers (tdesc))
3250 {
3251 const struct variant *v;
3252
3253 /* Choose variant. */
3254 v = find_variant_by_arch (arch, mach);
3255 if (!v)
3256 return NULL;
3257
3258 tdesc = *v->tdesc;
3259 }
3260
3261 gdb_assert (tdesc_has_registers (tdesc));
3262
3263 /* Check any target description for validity. */
3264 if (tdesc_has_registers (tdesc))
3265 {
3266 static const char *const gprs[] = {
3267 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
3268 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
3269 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
3270 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
3271 };
3272 static const char *const segment_regs[] = {
3273 "sr0", "sr1", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7",
3274 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15"
3275 };
3276 const struct tdesc_feature *feature;
3277 int i, valid_p;
3278 static const char *const msr_names[] = { "msr", "ps" };
3279 static const char *const cr_names[] = { "cr", "cnd" };
3280 static const char *const ctr_names[] = { "ctr", "cnt" };
3281
3282 feature = tdesc_find_feature (tdesc,
3283 "org.gnu.gdb.power.core");
3284 if (feature == NULL)
3285 return NULL;
3286
3287 tdesc_data = tdesc_data_alloc ();
3288
3289 valid_p = 1;
3290 for (i = 0; i < ppc_num_gprs; i++)
3291 valid_p &= tdesc_numbered_register (feature, tdesc_data, i, gprs[i]);
3292 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_PC_REGNUM,
3293 "pc");
3294 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_LR_REGNUM,
3295 "lr");
3296 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_XER_REGNUM,
3297 "xer");
3298
3299 /* Allow alternate names for these registers, to accomodate GDB's
3300 historic naming. */
3301 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3302 PPC_MSR_REGNUM, msr_names);
3303 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3304 PPC_CR_REGNUM, cr_names);
3305 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
3306 PPC_CTR_REGNUM, ctr_names);
3307
3308 if (!valid_p)
3309 {
3310 tdesc_data_cleanup (tdesc_data);
3311 return NULL;
3312 }
3313
3314 have_mq = tdesc_numbered_register (feature, tdesc_data, PPC_MQ_REGNUM,
3315 "mq");
3316
3317 tdesc_wordsize = tdesc_register_size (feature, "pc") / 8;
3318 if (wordsize == -1)
3319 wordsize = tdesc_wordsize;
3320
3321 feature = tdesc_find_feature (tdesc,
3322 "org.gnu.gdb.power.fpu");
3323 if (feature != NULL)
3324 {
3325 static const char *const fprs[] = {
3326 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
3327 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
3328 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
3329 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
3330 };
3331 valid_p = 1;
3332 for (i = 0; i < ppc_num_fprs; i++)
3333 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3334 PPC_F0_REGNUM + i, fprs[i]);
3335 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3336 PPC_FPSCR_REGNUM, "fpscr");
3337
3338 if (!valid_p)
3339 {
3340 tdesc_data_cleanup (tdesc_data);
3341 return NULL;
3342 }
3343 have_fpu = 1;
3344 }
3345 else
3346 have_fpu = 0;
3347
3348 feature = tdesc_find_feature (tdesc,
3349 "org.gnu.gdb.power.altivec");
3350 if (feature != NULL)
3351 {
3352 static const char *const vector_regs[] = {
3353 "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7",
3354 "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15",
3355 "vr16", "vr17", "vr18", "vr19", "vr20", "vr21", "vr22", "vr23",
3356 "vr24", "vr25", "vr26", "vr27", "vr28", "vr29", "vr30", "vr31"
3357 };
3358
3359 valid_p = 1;
3360 for (i = 0; i < ppc_num_gprs; i++)
3361 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3362 PPC_VR0_REGNUM + i,
3363 vector_regs[i]);
3364 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3365 PPC_VSCR_REGNUM, "vscr");
3366 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3367 PPC_VRSAVE_REGNUM, "vrsave");
3368
3369 if (have_spe || !valid_p)
3370 {
3371 tdesc_data_cleanup (tdesc_data);
3372 return NULL;
3373 }
3374 have_altivec = 1;
3375 }
3376 else
3377 have_altivec = 0;
3378
3379 /* On machines supporting the SPE APU, the general-purpose registers
3380 are 64 bits long. There are SIMD vector instructions to treat them
3381 as pairs of floats, but the rest of the instruction set treats them
3382 as 32-bit registers, and only operates on their lower halves.
3383
3384 In the GDB regcache, we treat their high and low halves as separate
3385 registers. The low halves we present as the general-purpose
3386 registers, and then we have pseudo-registers that stitch together
3387 the upper and lower halves and present them as pseudo-registers.
3388
3389 Thus, the target description is expected to supply the upper
3390 halves separately. */
3391
3392 feature = tdesc_find_feature (tdesc,
3393 "org.gnu.gdb.power.spe");
3394 if (feature != NULL)
3395 {
3396 static const char *const upper_spe[] = {
3397 "ev0h", "ev1h", "ev2h", "ev3h",
3398 "ev4h", "ev5h", "ev6h", "ev7h",
3399 "ev8h", "ev9h", "ev10h", "ev11h",
3400 "ev12h", "ev13h", "ev14h", "ev15h",
3401 "ev16h", "ev17h", "ev18h", "ev19h",
3402 "ev20h", "ev21h", "ev22h", "ev23h",
3403 "ev24h", "ev25h", "ev26h", "ev27h",
3404 "ev28h", "ev29h", "ev30h", "ev31h"
3405 };
3406
3407 valid_p = 1;
3408 for (i = 0; i < ppc_num_gprs; i++)
3409 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3410 PPC_SPE_UPPER_GP0_REGNUM + i,
3411 upper_spe[i]);
3412 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3413 PPC_SPE_ACC_REGNUM, "acc");
3414 valid_p &= tdesc_numbered_register (feature, tdesc_data,
3415 PPC_SPE_FSCR_REGNUM, "spefscr");
3416
3417 if (have_mq || have_fpu || !valid_p)
3418 {
3419 tdesc_data_cleanup (tdesc_data);
3420 return NULL;
3421 }
3422 have_spe = 1;
3423 }
3424 else
3425 have_spe = 0;
3426 }
3427
3428 /* If we have a 64-bit binary on a 32-bit target, complain. Also
3429 complain for a 32-bit binary on a 64-bit target; we do not yet
3430 support that. For instance, the 32-bit ABI routines expect
3431 32-bit GPRs.
3432
3433 As long as there isn't an explicit target description, we'll
3434 choose one based on the BFD architecture and get a word size
3435 matching the binary (probably powerpc:common or
3436 powerpc:common64). So there is only trouble if a 64-bit target
3437 supplies a 64-bit description while debugging a 32-bit
3438 binary. */
3439 if (tdesc_wordsize != -1 && tdesc_wordsize != wordsize)
3440 {
3441 tdesc_data_cleanup (tdesc_data);
3442 return NULL;
3443 }
3444
3445 #ifdef HAVE_ELF
3446 if (soft_float_flag == AUTO_BOOLEAN_AUTO && from_elf_exec)
3447 {
3448 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
3449 Tag_GNU_Power_ABI_FP))
3450 {
3451 case 1:
3452 soft_float_flag = AUTO_BOOLEAN_FALSE;
3453 break;
3454 case 2:
3455 soft_float_flag = AUTO_BOOLEAN_TRUE;
3456 break;
3457 default:
3458 break;
3459 }
3460 }
3461
3462 if (vector_abi == POWERPC_VEC_AUTO && from_elf_exec)
3463 {
3464 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
3465 Tag_GNU_Power_ABI_Vector))
3466 {
3467 case 1:
3468 vector_abi = POWERPC_VEC_GENERIC;
3469 break;
3470 case 2:
3471 vector_abi = POWERPC_VEC_ALTIVEC;
3472 break;
3473 case 3:
3474 vector_abi = POWERPC_VEC_SPE;
3475 break;
3476 default:
3477 break;
3478 }
3479 }
3480 #endif
3481
3482 if (soft_float_flag == AUTO_BOOLEAN_TRUE)
3483 soft_float = 1;
3484 else if (soft_float_flag == AUTO_BOOLEAN_FALSE)
3485 soft_float = 0;
3486 else
3487 soft_float = !have_fpu;
3488
3489 /* If we have a hard float binary or setting but no floating point
3490 registers, downgrade to soft float anyway. We're still somewhat
3491 useful in this scenario. */
3492 if (!soft_float && !have_fpu)
3493 soft_float = 1;
3494
3495 /* Similarly for vector registers. */
3496 if (vector_abi == POWERPC_VEC_ALTIVEC && !have_altivec)
3497 vector_abi = POWERPC_VEC_GENERIC;
3498
3499 if (vector_abi == POWERPC_VEC_SPE && !have_spe)
3500 vector_abi = POWERPC_VEC_GENERIC;
3501
3502 if (vector_abi == POWERPC_VEC_AUTO)
3503 {
3504 if (have_altivec)
3505 vector_abi = POWERPC_VEC_ALTIVEC;
3506 else if (have_spe)
3507 vector_abi = POWERPC_VEC_SPE;
3508 else
3509 vector_abi = POWERPC_VEC_GENERIC;
3510 }
3511
3512 /* Do not limit the vector ABI based on available hardware, since we
3513 do not yet know what hardware we'll decide we have. Yuck! FIXME! */
3514
3515 /* Find a candidate among extant architectures. */
3516 for (arches = gdbarch_list_lookup_by_info (arches, &info);
3517 arches != NULL;
3518 arches = gdbarch_list_lookup_by_info (arches->next, &info))
3519 {
3520 /* Word size in the various PowerPC bfd_arch_info structs isn't
3521 meaningful, because 64-bit CPUs can run in 32-bit mode. So, perform
3522 separate word size check. */
3523 tdep = gdbarch_tdep (arches->gdbarch);
3524 if (tdep && tdep->soft_float != soft_float)
3525 continue;
3526 if (tdep && tdep->vector_abi != vector_abi)
3527 continue;
3528 if (tdep && tdep->wordsize == wordsize)
3529 {
3530 if (tdesc_data != NULL)
3531 tdesc_data_cleanup (tdesc_data);
3532 return arches->gdbarch;
3533 }
3534 }
3535
3536 /* None found, create a new architecture from INFO, whose bfd_arch_info
3537 validity depends on the source:
3538 - executable useless
3539 - rs6000_host_arch() good
3540 - core file good
3541 - "set arch" trust blindly
3542 - GDB startup useless but harmless */
3543
3544 tdep = XCALLOC (1, struct gdbarch_tdep);
3545 tdep->wordsize = wordsize;
3546 tdep->soft_float = soft_float;
3547 tdep->vector_abi = vector_abi;
3548
3549 gdbarch = gdbarch_alloc (&info, tdep);
3550
3551 tdep->ppc_gp0_regnum = PPC_R0_REGNUM;
3552 tdep->ppc_toc_regnum = PPC_R0_REGNUM + 2;
3553 tdep->ppc_ps_regnum = PPC_MSR_REGNUM;
3554 tdep->ppc_cr_regnum = PPC_CR_REGNUM;
3555 tdep->ppc_lr_regnum = PPC_LR_REGNUM;
3556 tdep->ppc_ctr_regnum = PPC_CTR_REGNUM;
3557 tdep->ppc_xer_regnum = PPC_XER_REGNUM;
3558 tdep->ppc_mq_regnum = have_mq ? PPC_MQ_REGNUM : -1;
3559
3560 tdep->ppc_fp0_regnum = have_fpu ? PPC_F0_REGNUM : -1;
3561 tdep->ppc_fpscr_regnum = have_fpu ? PPC_FPSCR_REGNUM : -1;
3562 tdep->ppc_vr0_regnum = have_altivec ? PPC_VR0_REGNUM : -1;
3563 tdep->ppc_vrsave_regnum = have_altivec ? PPC_VRSAVE_REGNUM : -1;
3564 tdep->ppc_ev0_upper_regnum = have_spe ? PPC_SPE_UPPER_GP0_REGNUM : -1;
3565 tdep->ppc_acc_regnum = have_spe ? PPC_SPE_ACC_REGNUM : -1;
3566 tdep->ppc_spefscr_regnum = have_spe ? PPC_SPE_FSCR_REGNUM : -1;
3567
3568 set_gdbarch_pc_regnum (gdbarch, PPC_PC_REGNUM);
3569 set_gdbarch_sp_regnum (gdbarch, PPC_R0_REGNUM + 1);
3570 set_gdbarch_deprecated_fp_regnum (gdbarch, PPC_R0_REGNUM + 1);
3571 set_gdbarch_fp0_regnum (gdbarch, tdep->ppc_fp0_regnum);
3572 set_gdbarch_register_sim_regno (gdbarch, rs6000_register_sim_regno);
3573
3574 /* The XML specification for PowerPC sensibly calls the MSR "msr".
3575 GDB traditionally called it "ps", though, so let GDB add an
3576 alias. */
3577 set_gdbarch_ps_regnum (gdbarch, tdep->ppc_ps_regnum);
3578
3579 if (sysv_abi && wordsize == 8)
3580 set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value);
3581 else if (sysv_abi && wordsize == 4)
3582 set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value);
3583 else
3584 set_gdbarch_return_value (gdbarch, rs6000_return_value);
3585
3586 /* Set lr_frame_offset. */
3587 if (wordsize == 8)
3588 tdep->lr_frame_offset = 16;
3589 else if (sysv_abi)
3590 tdep->lr_frame_offset = 4;
3591 else
3592 tdep->lr_frame_offset = 8;
3593
3594 if (have_spe)
3595 {
3596 set_gdbarch_pseudo_register_read (gdbarch, e500_pseudo_register_read);
3597 set_gdbarch_pseudo_register_write (gdbarch, e500_pseudo_register_write);
3598 }
3599
3600 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
3601
3602 /* Select instruction printer. */
3603 if (arch == bfd_arch_rs6000)
3604 set_gdbarch_print_insn (gdbarch, print_insn_rs6000);
3605 else
3606 set_gdbarch_print_insn (gdbarch, gdb_print_insn_powerpc);
3607
3608 set_gdbarch_num_regs (gdbarch, PPC_NUM_REGS + num_sprs);
3609 set_gdbarch_num_pseudo_regs (gdbarch, have_spe ? 32 : 0);
3610
3611 set_gdbarch_ptr_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
3612 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
3613 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
3614 set_gdbarch_long_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
3615 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
3616 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
3617 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
3618 if (sysv_abi)
3619 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
3620 else
3621 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
3622 set_gdbarch_char_signed (gdbarch, 0);
3623
3624 set_gdbarch_frame_align (gdbarch, rs6000_frame_align);
3625 if (sysv_abi && wordsize == 8)
3626 /* PPC64 SYSV. */
3627 set_gdbarch_frame_red_zone_size (gdbarch, 288);
3628 else if (!sysv_abi && wordsize == 4)
3629 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
3630 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
3631 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
3632 224. */
3633 set_gdbarch_frame_red_zone_size (gdbarch, 224);
3634
3635 set_gdbarch_convert_register_p (gdbarch, rs6000_convert_register_p);
3636 set_gdbarch_register_to_value (gdbarch, rs6000_register_to_value);
3637 set_gdbarch_value_to_register (gdbarch, rs6000_value_to_register);
3638
3639 set_gdbarch_stab_reg_to_regnum (gdbarch, rs6000_stab_reg_to_regnum);
3640 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rs6000_dwarf2_reg_to_regnum);
3641
3642 if (sysv_abi && wordsize == 4)
3643 set_gdbarch_push_dummy_call (gdbarch, ppc_sysv_abi_push_dummy_call);
3644 else if (sysv_abi && wordsize == 8)
3645 set_gdbarch_push_dummy_call (gdbarch, ppc64_sysv_abi_push_dummy_call);
3646 else
3647 set_gdbarch_push_dummy_call (gdbarch, rs6000_push_dummy_call);
3648
3649 set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue);
3650 set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilogue_p);
3651
3652 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
3653 set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);
3654
3655 /* The value of symbols of type N_SO and N_FUN maybe null when
3656 it shouldn't be. */
3657 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
3658
3659 /* Handles single stepping of atomic sequences. */
3660 set_gdbarch_software_single_step (gdbarch, deal_with_atomic_sequence);
3661
3662 /* Handle the 64-bit SVR4 minimal-symbol convention of using "FN"
3663 for the descriptor and ".FN" for the entry-point -- a user
3664 specifying "break FN" will unexpectedly end up with a breakpoint
3665 on the descriptor and not the function. This architecture method
3666 transforms any breakpoints on descriptors into breakpoints on the
3667 corresponding entry point. */
3668 if (sysv_abi && wordsize == 8)
3669 set_gdbarch_adjust_breakpoint_address (gdbarch, ppc64_sysv_abi_adjust_breakpoint_address);
3670
3671 /* Not sure on this. FIXMEmgo */
3672 set_gdbarch_frame_args_skip (gdbarch, 8);
3673
3674 if (!sysv_abi)
3675 {
3676 /* Handle RS/6000 function pointers (which are really function
3677 descriptors). */
3678 set_gdbarch_convert_from_func_ptr_addr (gdbarch,
3679 rs6000_convert_from_func_ptr_addr);
3680 }
3681
3682 /* Helpers for function argument information. */
3683 set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument);
3684
3685 /* Trampoline. */
3686 set_gdbarch_in_solib_return_trampoline
3687 (gdbarch, rs6000_in_solib_return_trampoline);
3688 set_gdbarch_skip_trampoline_code (gdbarch, rs6000_skip_trampoline_code);
3689
3690 /* Hook in the DWARF CFI frame unwinder. */
3691 frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
3692 dwarf2_frame_set_adjust_regnum (gdbarch, rs6000_adjust_frame_regnum);
3693
3694 /* Frame handling. */
3695 dwarf2_frame_set_init_reg (gdbarch, ppc_dwarf2_frame_init_reg);
3696
3697 /* Hook in ABI-specific overrides, if they have been registered. */
3698 gdbarch_init_osabi (info, gdbarch);
3699
3700 switch (info.osabi)
3701 {
3702 case GDB_OSABI_LINUX:
3703 case GDB_OSABI_NETBSD_AOUT:
3704 case GDB_OSABI_NETBSD_ELF:
3705 case GDB_OSABI_UNKNOWN:
3706 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
3707 frame_unwind_append_sniffer (gdbarch, rs6000_frame_sniffer);
3708 set_gdbarch_unwind_dummy_id (gdbarch, rs6000_unwind_dummy_id);
3709 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
3710 break;
3711 default:
3712 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
3713
3714 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
3715 frame_unwind_append_sniffer (gdbarch, rs6000_frame_sniffer);
3716 set_gdbarch_unwind_dummy_id (gdbarch, rs6000_unwind_dummy_id);
3717 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
3718 }
3719
3720 set_tdesc_pseudo_register_type (gdbarch, rs6000_pseudo_register_type);
3721 set_tdesc_pseudo_register_reggroup_p (gdbarch,
3722 rs6000_pseudo_register_reggroup_p);
3723 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
3724
3725 /* Override the normal target description method to make the SPE upper
3726 halves anonymous. */
3727 set_gdbarch_register_name (gdbarch, rs6000_register_name);
3728
3729 /* Recording the numbering of pseudo registers. */
3730 tdep->ppc_ev0_regnum = have_spe ? gdbarch_num_regs (gdbarch) : -1;
3731 tdep->ppc_ev31_regnum = have_spe ? tdep->ppc_ev0_regnum + 31 : -1;
3732
3733 return gdbarch;
3734 }
3735
3736 static void
3737 rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3738 {
3739 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3740
3741 if (tdep == NULL)
3742 return;
3743
3744 /* FIXME: Dump gdbarch_tdep. */
3745 }
3746
3747 /* PowerPC-specific commands. */
3748
3749 static void
3750 set_powerpc_command (char *args, int from_tty)
3751 {
3752 printf_unfiltered (_("\
3753 \"set powerpc\" must be followed by an appropriate subcommand.\n"));
3754 help_list (setpowerpccmdlist, "set powerpc ", all_commands, gdb_stdout);
3755 }
3756
3757 static void
3758 show_powerpc_command (char *args, int from_tty)
3759 {
3760 cmd_show_list (showpowerpccmdlist, from_tty, "");
3761 }
3762
3763 static void
3764 powerpc_set_soft_float (char *args, int from_tty,
3765 struct cmd_list_element *c)
3766 {
3767 struct gdbarch_info info;
3768
3769 /* Update the architecture. */
3770 gdbarch_info_init (&info);
3771 if (!gdbarch_update_p (info))
3772 internal_error (__FILE__, __LINE__, "could not update architecture");
3773 }
3774
3775 static void
3776 powerpc_set_vector_abi (char *args, int from_tty,
3777 struct cmd_list_element *c)
3778 {
3779 struct gdbarch_info info;
3780 enum powerpc_vector_abi vector_abi;
3781
3782 for (vector_abi = POWERPC_VEC_AUTO;
3783 vector_abi != POWERPC_VEC_LAST;
3784 vector_abi++)
3785 if (strcmp (powerpc_vector_abi_string,
3786 powerpc_vector_strings[vector_abi]) == 0)
3787 {
3788 powerpc_vector_abi_global = vector_abi;
3789 break;
3790 }
3791
3792 if (vector_abi == POWERPC_VEC_LAST)
3793 internal_error (__FILE__, __LINE__, _("Invalid vector ABI accepted: %s."),
3794 powerpc_vector_abi_string);
3795
3796 /* Update the architecture. */
3797 gdbarch_info_init (&info);
3798 if (!gdbarch_update_p (info))
3799 internal_error (__FILE__, __LINE__, "could not update architecture");
3800 }
3801
3802 /* Initialization code. */
3803
3804 extern initialize_file_ftype _initialize_rs6000_tdep; /* -Wmissing-prototypes */
3805
3806 void
3807 _initialize_rs6000_tdep (void)
3808 {
3809 gdbarch_register (bfd_arch_rs6000, rs6000_gdbarch_init, rs6000_dump_tdep);
3810 gdbarch_register (bfd_arch_powerpc, rs6000_gdbarch_init, rs6000_dump_tdep);
3811
3812 /* Initialize the standard target descriptions. */
3813 initialize_tdesc_powerpc_32 ();
3814 initialize_tdesc_powerpc_403 ();
3815 initialize_tdesc_powerpc_403gc ();
3816 initialize_tdesc_powerpc_505 ();
3817 initialize_tdesc_powerpc_601 ();
3818 initialize_tdesc_powerpc_602 ();
3819 initialize_tdesc_powerpc_603 ();
3820 initialize_tdesc_powerpc_604 ();
3821 initialize_tdesc_powerpc_64 ();
3822 initialize_tdesc_powerpc_7400 ();
3823 initialize_tdesc_powerpc_750 ();
3824 initialize_tdesc_powerpc_860 ();
3825 initialize_tdesc_powerpc_e500 ();
3826 initialize_tdesc_rs6000 ();
3827
3828 /* Add root prefix command for all "set powerpc"/"show powerpc"
3829 commands. */
3830 add_prefix_cmd ("powerpc", no_class, set_powerpc_command,
3831 _("Various PowerPC-specific commands."),
3832 &setpowerpccmdlist, "set powerpc ", 0, &setlist);
3833
3834 add_prefix_cmd ("powerpc", no_class, show_powerpc_command,
3835 _("Various PowerPC-specific commands."),
3836 &showpowerpccmdlist, "show powerpc ", 0, &showlist);
3837
3838 /* Add a command to allow the user to force the ABI. */
3839 add_setshow_auto_boolean_cmd ("soft-float", class_support,
3840 &powerpc_soft_float_global,
3841 _("Set whether to use a soft-float ABI."),
3842 _("Show whether to use a soft-float ABI."),
3843 NULL,
3844 powerpc_set_soft_float, NULL,
3845 &setpowerpccmdlist, &showpowerpccmdlist);
3846
3847 add_setshow_enum_cmd ("vector-abi", class_support, powerpc_vector_strings,
3848 &powerpc_vector_abi_string,
3849 _("Set the vector ABI."),
3850 _("Show the vector ABI."),
3851 NULL, powerpc_set_vector_abi, NULL,
3852 &setpowerpccmdlist, &showpowerpccmdlist);
3853 }
This page took 0.114552 seconds and 4 git commands to generate.