Fix mail address format of a couple recent ChangeLog entries
[deliverable/binutils-gdb.git] / gdb / rs6000-tdep.c
CommitLineData
c906108c 1/* Target-dependent code for GDB, the GNU debugger.
7aea86e6 2
32d0add0 3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "defs.h"
21#include "frame.h"
22#include "inferior.h"
45741a9c 23#include "infrun.h"
c906108c
SS
24#include "symtab.h"
25#include "target.h"
26#include "gdbcore.h"
27#include "gdbcmd.h"
c906108c 28#include "objfiles.h"
7a78ae4e 29#include "arch-utils.h"
4e052eda 30#include "regcache.h"
d195bc9f 31#include "regset.h"
d16aafd8 32#include "doublest.h"
fd0407d6 33#include "value.h"
1fcc0bb8 34#include "parser-defs.h"
4be87837 35#include "osabi.h"
7d9b040b 36#include "infcall.h"
9f643768
JB
37#include "sim-regno.h"
38#include "gdb/sim-ppc.h"
6ced10dd 39#include "reggroups.h"
4fc771b8 40#include "dwarf2-frame.h"
7cc46491
DJ
41#include "target-descriptions.h"
42#include "user-regs.h"
b4cdae6f
WW
43#include "record-full.h"
44#include "auxv.h"
7a78ae4e 45
2fccf04a 46#include "libbfd.h" /* for bfd_default_set_arch_mach */
7a78ae4e 47#include "coff/internal.h" /* for libcoff.h */
2fccf04a 48#include "libcoff.h" /* for xcoff_data */
11ed25ac
KB
49#include "coff/xcoff.h"
50#include "libxcoff.h"
7a78ae4e 51
9aa1e687 52#include "elf-bfd.h"
55eddb0f 53#include "elf/ppc.h"
cd453cd0 54#include "elf/ppc64.h"
7a78ae4e 55
6ded7999 56#include "solib-svr4.h"
9aa1e687 57#include "ppc-tdep.h"
debb1f09 58#include "ppc-ravenscar-thread.h"
7a78ae4e 59
a89aa300 60#include "dis-asm.h"
338ef23d 61
61a65099
KB
62#include "trad-frame.h"
63#include "frame-unwind.h"
64#include "frame-base.h"
65
7cc46491 66#include "features/rs6000/powerpc-32.c"
7284e1be 67#include "features/rs6000/powerpc-altivec32.c"
604c2f83 68#include "features/rs6000/powerpc-vsx32.c"
7cc46491
DJ
69#include "features/rs6000/powerpc-403.c"
70#include "features/rs6000/powerpc-403gc.c"
4d09ffea 71#include "features/rs6000/powerpc-405.c"
7cc46491
DJ
72#include "features/rs6000/powerpc-505.c"
73#include "features/rs6000/powerpc-601.c"
74#include "features/rs6000/powerpc-602.c"
75#include "features/rs6000/powerpc-603.c"
76#include "features/rs6000/powerpc-604.c"
77#include "features/rs6000/powerpc-64.c"
7284e1be 78#include "features/rs6000/powerpc-altivec64.c"
604c2f83 79#include "features/rs6000/powerpc-vsx64.c"
7cc46491
DJ
80#include "features/rs6000/powerpc-7400.c"
81#include "features/rs6000/powerpc-750.c"
82#include "features/rs6000/powerpc-860.c"
83#include "features/rs6000/powerpc-e500.c"
84#include "features/rs6000/rs6000.c"
85
5a9e69ba
TJB
86/* Determine if regnum is an SPE pseudo-register. */
87#define IS_SPE_PSEUDOREG(tdep, regnum) ((tdep)->ppc_ev0_regnum >= 0 \
88 && (regnum) >= (tdep)->ppc_ev0_regnum \
89 && (regnum) < (tdep)->ppc_ev0_regnum + 32)
90
f949c649
TJB
91/* Determine if regnum is a decimal float pseudo-register. */
92#define IS_DFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_dl0_regnum >= 0 \
93 && (regnum) >= (tdep)->ppc_dl0_regnum \
94 && (regnum) < (tdep)->ppc_dl0_regnum + 16)
95
604c2f83
LM
96/* Determine if regnum is a POWER7 VSX register. */
97#define IS_VSX_PSEUDOREG(tdep, regnum) ((tdep)->ppc_vsr0_regnum >= 0 \
98 && (regnum) >= (tdep)->ppc_vsr0_regnum \
99 && (regnum) < (tdep)->ppc_vsr0_regnum + ppc_num_vsrs)
100
101/* Determine if regnum is a POWER7 Extended FP register. */
102#define IS_EFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_efpr0_regnum >= 0 \
103 && (regnum) >= (tdep)->ppc_efpr0_regnum \
d9492458 104 && (regnum) < (tdep)->ppc_efpr0_regnum + ppc_num_efprs)
604c2f83 105
55eddb0f
DJ
106/* The list of available "set powerpc ..." and "show powerpc ..."
107 commands. */
108static struct cmd_list_element *setpowerpccmdlist = NULL;
109static struct cmd_list_element *showpowerpccmdlist = NULL;
110
111static enum auto_boolean powerpc_soft_float_global = AUTO_BOOLEAN_AUTO;
112
113/* The vector ABI to use. Keep this in sync with powerpc_vector_abi. */
40478521 114static const char *const powerpc_vector_strings[] =
55eddb0f
DJ
115{
116 "auto",
117 "generic",
118 "altivec",
119 "spe",
120 NULL
121};
122
123/* A variable that can be configured by the user. */
124static enum powerpc_vector_abi powerpc_vector_abi_global = POWERPC_VEC_AUTO;
125static const char *powerpc_vector_abi_string = "auto";
126
0df8b418 127/* To be used by skip_prologue. */
7a78ae4e
ND
128
129struct rs6000_framedata
130 {
131 int offset; /* total size of frame --- the distance
132 by which we decrement sp to allocate
133 the frame */
134 int saved_gpr; /* smallest # of saved gpr */
46a9b8ed 135 unsigned int gpr_mask; /* Each bit is an individual saved GPR. */
7a78ae4e 136 int saved_fpr; /* smallest # of saved fpr */
6be8bc0c 137 int saved_vr; /* smallest # of saved vr */
96ff0de4 138 int saved_ev; /* smallest # of saved ev */
7a78ae4e 139 int alloca_reg; /* alloca register number (frame ptr) */
0df8b418
MS
140 char frameless; /* true if frameless functions. */
141 char nosavedpc; /* true if pc not saved. */
46a9b8ed 142 char used_bl; /* true if link register clobbered */
7a78ae4e
ND
143 int gpr_offset; /* offset of saved gprs from prev sp */
144 int fpr_offset; /* offset of saved fprs from prev sp */
6be8bc0c 145 int vr_offset; /* offset of saved vrs from prev sp */
96ff0de4 146 int ev_offset; /* offset of saved evs from prev sp */
7a78ae4e 147 int lr_offset; /* offset of saved lr */
46a9b8ed 148 int lr_register; /* register of saved lr, if trustworthy */
7a78ae4e 149 int cr_offset; /* offset of saved cr */
6be8bc0c 150 int vrsave_offset; /* offset of saved vrsave register */
7a78ae4e
ND
151 };
152
c906108c 153
604c2f83
LM
154/* Is REGNO a VSX register? Return 1 if so, 0 otherwise. */
155int
156vsx_register_p (struct gdbarch *gdbarch, int regno)
157{
158 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
159 if (tdep->ppc_vsr0_regnum < 0)
160 return 0;
161 else
162 return (regno >= tdep->ppc_vsr0_upper_regnum && regno
163 <= tdep->ppc_vsr0_upper_regnum + 31);
164}
165
64b84175
KB
166/* Is REGNO an AltiVec register? Return 1 if so, 0 otherwise. */
167int
be8626e0 168altivec_register_p (struct gdbarch *gdbarch, int regno)
64b84175 169{
be8626e0 170 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
64b84175
KB
171 if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
172 return 0;
173 else
174 return (regno >= tdep->ppc_vr0_regnum && regno <= tdep->ppc_vrsave_regnum);
175}
176
383f0f5b 177
867e2dc5
JB
178/* Return true if REGNO is an SPE register, false otherwise. */
179int
be8626e0 180spe_register_p (struct gdbarch *gdbarch, int regno)
867e2dc5 181{
be8626e0 182 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
867e2dc5
JB
183
184 /* Is it a reference to EV0 -- EV31, and do we have those? */
5a9e69ba 185 if (IS_SPE_PSEUDOREG (tdep, regno))
867e2dc5
JB
186 return 1;
187
6ced10dd
JB
188 /* Is it a reference to one of the raw upper GPR halves? */
189 if (tdep->ppc_ev0_upper_regnum >= 0
190 && tdep->ppc_ev0_upper_regnum <= regno
191 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
192 return 1;
193
867e2dc5
JB
194 /* Is it a reference to the 64-bit accumulator, and do we have that? */
195 if (tdep->ppc_acc_regnum >= 0
196 && tdep->ppc_acc_regnum == regno)
197 return 1;
198
199 /* Is it a reference to the SPE floating-point status and control register,
200 and do we have that? */
201 if (tdep->ppc_spefscr_regnum >= 0
202 && tdep->ppc_spefscr_regnum == regno)
203 return 1;
204
205 return 0;
206}
207
208
383f0f5b
JB
209/* Return non-zero if the architecture described by GDBARCH has
210 floating-point registers (f0 --- f31 and fpscr). */
0a613259
AC
211int
212ppc_floating_point_unit_p (struct gdbarch *gdbarch)
213{
383f0f5b
JB
214 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
215
216 return (tdep->ppc_fp0_regnum >= 0
217 && tdep->ppc_fpscr_regnum >= 0);
0a613259 218}
9f643768 219
604c2f83
LM
220/* Return non-zero if the architecture described by GDBARCH has
221 VSX registers (vsr0 --- vsr63). */
63807e1d 222static int
604c2f83
LM
223ppc_vsx_support_p (struct gdbarch *gdbarch)
224{
225 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
226
227 return tdep->ppc_vsr0_regnum >= 0;
228}
229
06caf7d2
CES
230/* Return non-zero if the architecture described by GDBARCH has
231 Altivec registers (vr0 --- vr31, vrsave and vscr). */
232int
233ppc_altivec_support_p (struct gdbarch *gdbarch)
234{
235 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
236
237 return (tdep->ppc_vr0_regnum >= 0
238 && tdep->ppc_vrsave_regnum >= 0);
239}
09991fa0
JB
240
241/* Check that TABLE[GDB_REGNO] is not already initialized, and then
242 set it to SIM_REGNO.
243
244 This is a helper function for init_sim_regno_table, constructing
245 the table mapping GDB register numbers to sim register numbers; we
246 initialize every element in that table to -1 before we start
247 filling it in. */
9f643768
JB
248static void
249set_sim_regno (int *table, int gdb_regno, int sim_regno)
250{
251 /* Make sure we don't try to assign any given GDB register a sim
252 register number more than once. */
253 gdb_assert (table[gdb_regno] == -1);
254 table[gdb_regno] = sim_regno;
255}
256
09991fa0
JB
257
258/* Initialize ARCH->tdep->sim_regno, the table mapping GDB register
259 numbers to simulator register numbers, based on the values placed
260 in the ARCH->tdep->ppc_foo_regnum members. */
9f643768
JB
261static void
262init_sim_regno_table (struct gdbarch *arch)
263{
264 struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
7cc46491 265 int total_regs = gdbarch_num_regs (arch);
9f643768
JB
266 int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
267 int i;
7cc46491
DJ
268 static const char *const segment_regs[] = {
269 "sr0", "sr1", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7",
270 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15"
271 };
9f643768
JB
272
273 /* Presume that all registers not explicitly mentioned below are
274 unavailable from the sim. */
275 for (i = 0; i < total_regs; i++)
276 sim_regno[i] = -1;
277
278 /* General-purpose registers. */
279 for (i = 0; i < ppc_num_gprs; i++)
280 set_sim_regno (sim_regno, tdep->ppc_gp0_regnum + i, sim_ppc_r0_regnum + i);
281
282 /* Floating-point registers. */
283 if (tdep->ppc_fp0_regnum >= 0)
284 for (i = 0; i < ppc_num_fprs; i++)
285 set_sim_regno (sim_regno,
286 tdep->ppc_fp0_regnum + i,
287 sim_ppc_f0_regnum + i);
288 if (tdep->ppc_fpscr_regnum >= 0)
289 set_sim_regno (sim_regno, tdep->ppc_fpscr_regnum, sim_ppc_fpscr_regnum);
290
291 set_sim_regno (sim_regno, gdbarch_pc_regnum (arch), sim_ppc_pc_regnum);
292 set_sim_regno (sim_regno, tdep->ppc_ps_regnum, sim_ppc_ps_regnum);
293 set_sim_regno (sim_regno, tdep->ppc_cr_regnum, sim_ppc_cr_regnum);
294
295 /* Segment registers. */
7cc46491
DJ
296 for (i = 0; i < ppc_num_srs; i++)
297 {
298 int gdb_regno;
299
300 gdb_regno = user_reg_map_name_to_regnum (arch, segment_regs[i], -1);
301 if (gdb_regno >= 0)
302 set_sim_regno (sim_regno, gdb_regno, sim_ppc_sr0_regnum + i);
303 }
9f643768
JB
304
305 /* Altivec registers. */
306 if (tdep->ppc_vr0_regnum >= 0)
307 {
308 for (i = 0; i < ppc_num_vrs; i++)
309 set_sim_regno (sim_regno,
310 tdep->ppc_vr0_regnum + i,
311 sim_ppc_vr0_regnum + i);
312
313 /* FIXME: jimb/2004-07-15: when we have tdep->ppc_vscr_regnum,
314 we can treat this more like the other cases. */
315 set_sim_regno (sim_regno,
316 tdep->ppc_vr0_regnum + ppc_num_vrs,
317 sim_ppc_vscr_regnum);
318 }
319 /* vsave is a special-purpose register, so the code below handles it. */
320
321 /* SPE APU (E500) registers. */
6ced10dd
JB
322 if (tdep->ppc_ev0_upper_regnum >= 0)
323 for (i = 0; i < ppc_num_gprs; i++)
324 set_sim_regno (sim_regno,
325 tdep->ppc_ev0_upper_regnum + i,
326 sim_ppc_rh0_regnum + i);
9f643768
JB
327 if (tdep->ppc_acc_regnum >= 0)
328 set_sim_regno (sim_regno, tdep->ppc_acc_regnum, sim_ppc_acc_regnum);
329 /* spefscr is a special-purpose register, so the code below handles it. */
330
7cc46491 331#ifdef WITH_SIM
9f643768
JB
332 /* Now handle all special-purpose registers. Verify that they
333 haven't mistakenly been assigned numbers by any of the above
7cc46491
DJ
334 code. */
335 for (i = 0; i < sim_ppc_num_sprs; i++)
336 {
337 const char *spr_name = sim_spr_register_name (i);
338 int gdb_regno = -1;
339
340 if (spr_name != NULL)
341 gdb_regno = user_reg_map_name_to_regnum (arch, spr_name, -1);
342
343 if (gdb_regno != -1)
344 set_sim_regno (sim_regno, gdb_regno, sim_ppc_spr0_regnum + i);
345 }
346#endif
9f643768
JB
347
348 /* Drop the initialized array into place. */
349 tdep->sim_regno = sim_regno;
350}
351
09991fa0
JB
352
353/* Given a GDB register number REG, return the corresponding SIM
354 register number. */
9f643768 355static int
e7faf938 356rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
9f643768 357{
e7faf938 358 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
9f643768
JB
359 int sim_regno;
360
7cc46491 361 if (tdep->sim_regno == NULL)
e7faf938 362 init_sim_regno_table (gdbarch);
7cc46491 363
f57d151a 364 gdb_assert (0 <= reg
e7faf938
MD
365 && reg <= gdbarch_num_regs (gdbarch)
366 + gdbarch_num_pseudo_regs (gdbarch));
9f643768
JB
367 sim_regno = tdep->sim_regno[reg];
368
369 if (sim_regno >= 0)
370 return sim_regno;
371 else
372 return LEGACY_SIM_REGNO_IGNORE;
373}
374
d195bc9f
MK
375\f
376
377/* Register set support functions. */
378
f2db237a
AM
379/* REGS + OFFSET contains register REGNUM in a field REGSIZE wide.
380 Write the register to REGCACHE. */
381
7284e1be 382void
d195bc9f 383ppc_supply_reg (struct regcache *regcache, int regnum,
f2db237a 384 const gdb_byte *regs, size_t offset, int regsize)
d195bc9f
MK
385{
386 if (regnum != -1 && offset != -1)
f2db237a
AM
387 {
388 if (regsize > 4)
389 {
390 struct gdbarch *gdbarch = get_regcache_arch (regcache);
391 int gdb_regsize = register_size (gdbarch, regnum);
392 if (gdb_regsize < regsize
393 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
394 offset += regsize - gdb_regsize;
395 }
396 regcache_raw_supply (regcache, regnum, regs + offset);
397 }
d195bc9f
MK
398}
399
f2db237a
AM
400/* Read register REGNUM from REGCACHE and store to REGS + OFFSET
401 in a field REGSIZE wide. Zero pad as necessary. */
402
7284e1be 403void
d195bc9f 404ppc_collect_reg (const struct regcache *regcache, int regnum,
f2db237a 405 gdb_byte *regs, size_t offset, int regsize)
d195bc9f
MK
406{
407 if (regnum != -1 && offset != -1)
f2db237a
AM
408 {
409 if (regsize > 4)
410 {
411 struct gdbarch *gdbarch = get_regcache_arch (regcache);
412 int gdb_regsize = register_size (gdbarch, regnum);
413 if (gdb_regsize < regsize)
414 {
415 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
416 {
417 memset (regs + offset, 0, regsize - gdb_regsize);
418 offset += regsize - gdb_regsize;
419 }
420 else
421 memset (regs + offset + regsize - gdb_regsize, 0,
422 regsize - gdb_regsize);
423 }
424 }
425 regcache_raw_collect (regcache, regnum, regs + offset);
426 }
d195bc9f
MK
427}
428
f2db237a
AM
429static int
430ppc_greg_offset (struct gdbarch *gdbarch,
431 struct gdbarch_tdep *tdep,
432 const struct ppc_reg_offsets *offsets,
433 int regnum,
434 int *regsize)
435{
436 *regsize = offsets->gpr_size;
437 if (regnum >= tdep->ppc_gp0_regnum
438 && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
439 return (offsets->r0_offset
440 + (regnum - tdep->ppc_gp0_regnum) * offsets->gpr_size);
441
442 if (regnum == gdbarch_pc_regnum (gdbarch))
443 return offsets->pc_offset;
444
445 if (regnum == tdep->ppc_ps_regnum)
446 return offsets->ps_offset;
447
448 if (regnum == tdep->ppc_lr_regnum)
449 return offsets->lr_offset;
450
451 if (regnum == tdep->ppc_ctr_regnum)
452 return offsets->ctr_offset;
453
454 *regsize = offsets->xr_size;
455 if (regnum == tdep->ppc_cr_regnum)
456 return offsets->cr_offset;
457
458 if (regnum == tdep->ppc_xer_regnum)
459 return offsets->xer_offset;
460
461 if (regnum == tdep->ppc_mq_regnum)
462 return offsets->mq_offset;
463
464 return -1;
465}
466
467static int
468ppc_fpreg_offset (struct gdbarch_tdep *tdep,
469 const struct ppc_reg_offsets *offsets,
470 int regnum)
471{
472 if (regnum >= tdep->ppc_fp0_regnum
473 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs)
474 return offsets->f0_offset + (regnum - tdep->ppc_fp0_regnum) * 8;
475
476 if (regnum == tdep->ppc_fpscr_regnum)
477 return offsets->fpscr_offset;
478
479 return -1;
480}
481
06caf7d2
CES
482static int
483ppc_vrreg_offset (struct gdbarch_tdep *tdep,
484 const struct ppc_reg_offsets *offsets,
485 int regnum)
486{
487 if (regnum >= tdep->ppc_vr0_regnum
488 && regnum < tdep->ppc_vr0_regnum + ppc_num_vrs)
489 return offsets->vr0_offset + (regnum - tdep->ppc_vr0_regnum) * 16;
490
491 if (regnum == tdep->ppc_vrsave_regnum - 1)
492 return offsets->vscr_offset;
493
494 if (regnum == tdep->ppc_vrsave_regnum)
495 return offsets->vrsave_offset;
496
497 return -1;
498}
499
d195bc9f
MK
500/* Supply register REGNUM in the general-purpose register set REGSET
501 from the buffer specified by GREGS and LEN to register cache
502 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
503
504void
505ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
506 int regnum, const void *gregs, size_t len)
507{
508 struct gdbarch *gdbarch = get_regcache_arch (regcache);
509 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7fefa8d7 510 const struct ppc_reg_offsets *offsets = regset->regmap;
d195bc9f 511 size_t offset;
f2db237a 512 int regsize;
d195bc9f 513
f2db237a 514 if (regnum == -1)
d195bc9f 515 {
f2db237a
AM
516 int i;
517 int gpr_size = offsets->gpr_size;
518
519 for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset;
520 i < tdep->ppc_gp0_regnum + ppc_num_gprs;
521 i++, offset += gpr_size)
522 ppc_supply_reg (regcache, i, gregs, offset, gpr_size);
523
524 ppc_supply_reg (regcache, gdbarch_pc_regnum (gdbarch),
525 gregs, offsets->pc_offset, gpr_size);
526 ppc_supply_reg (regcache, tdep->ppc_ps_regnum,
527 gregs, offsets->ps_offset, gpr_size);
528 ppc_supply_reg (regcache, tdep->ppc_lr_regnum,
529 gregs, offsets->lr_offset, gpr_size);
530 ppc_supply_reg (regcache, tdep->ppc_ctr_regnum,
531 gregs, offsets->ctr_offset, gpr_size);
532 ppc_supply_reg (regcache, tdep->ppc_cr_regnum,
533 gregs, offsets->cr_offset, offsets->xr_size);
534 ppc_supply_reg (regcache, tdep->ppc_xer_regnum,
535 gregs, offsets->xer_offset, offsets->xr_size);
536 ppc_supply_reg (regcache, tdep->ppc_mq_regnum,
537 gregs, offsets->mq_offset, offsets->xr_size);
538 return;
d195bc9f
MK
539 }
540
f2db237a
AM
541 offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, &regsize);
542 ppc_supply_reg (regcache, regnum, gregs, offset, regsize);
d195bc9f
MK
543}
544
545/* Supply register REGNUM in the floating-point register set REGSET
546 from the buffer specified by FPREGS and LEN to register cache
547 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
548
549void
550ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
551 int regnum, const void *fpregs, size_t len)
552{
553 struct gdbarch *gdbarch = get_regcache_arch (regcache);
f2db237a
AM
554 struct gdbarch_tdep *tdep;
555 const struct ppc_reg_offsets *offsets;
d195bc9f 556 size_t offset;
d195bc9f 557
f2db237a
AM
558 if (!ppc_floating_point_unit_p (gdbarch))
559 return;
383f0f5b 560
f2db237a 561 tdep = gdbarch_tdep (gdbarch);
7fefa8d7 562 offsets = regset->regmap;
f2db237a 563 if (regnum == -1)
d195bc9f 564 {
f2db237a
AM
565 int i;
566
567 for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset;
568 i < tdep->ppc_fp0_regnum + ppc_num_fprs;
569 i++, offset += 8)
570 ppc_supply_reg (regcache, i, fpregs, offset, 8);
571
572 ppc_supply_reg (regcache, tdep->ppc_fpscr_regnum,
573 fpregs, offsets->fpscr_offset, offsets->fpscr_size);
574 return;
d195bc9f
MK
575 }
576
f2db237a
AM
577 offset = ppc_fpreg_offset (tdep, offsets, regnum);
578 ppc_supply_reg (regcache, regnum, fpregs, offset,
579 regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8);
d195bc9f
MK
580}
581
604c2f83
LM
582/* Supply register REGNUM in the VSX register set REGSET
583 from the buffer specified by VSXREGS and LEN to register cache
584 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
585
586void
587ppc_supply_vsxregset (const struct regset *regset, struct regcache *regcache,
588 int regnum, const void *vsxregs, size_t len)
589{
590 struct gdbarch *gdbarch = get_regcache_arch (regcache);
591 struct gdbarch_tdep *tdep;
592
593 if (!ppc_vsx_support_p (gdbarch))
594 return;
595
596 tdep = gdbarch_tdep (gdbarch);
597
598 if (regnum == -1)
599 {
600 int i;
601
602 for (i = tdep->ppc_vsr0_upper_regnum;
603 i < tdep->ppc_vsr0_upper_regnum + 32;
604 i++)
605 ppc_supply_reg (regcache, i, vsxregs, 0, 8);
606
607 return;
608 }
609 else
610 ppc_supply_reg (regcache, regnum, vsxregs, 0, 8);
611}
612
06caf7d2
CES
613/* Supply register REGNUM in the Altivec register set REGSET
614 from the buffer specified by VRREGS and LEN to register cache
615 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
616
617void
618ppc_supply_vrregset (const struct regset *regset, struct regcache *regcache,
619 int regnum, const void *vrregs, size_t len)
620{
621 struct gdbarch *gdbarch = get_regcache_arch (regcache);
622 struct gdbarch_tdep *tdep;
623 const struct ppc_reg_offsets *offsets;
624 size_t offset;
625
626 if (!ppc_altivec_support_p (gdbarch))
627 return;
628
629 tdep = gdbarch_tdep (gdbarch);
7fefa8d7 630 offsets = regset->regmap;
06caf7d2
CES
631 if (regnum == -1)
632 {
633 int i;
634
635 for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset;
636 i < tdep->ppc_vr0_regnum + ppc_num_vrs;
637 i++, offset += 16)
638 ppc_supply_reg (regcache, i, vrregs, offset, 16);
639
640 ppc_supply_reg (regcache, (tdep->ppc_vrsave_regnum - 1),
641 vrregs, offsets->vscr_offset, 4);
642
643 ppc_supply_reg (regcache, tdep->ppc_vrsave_regnum,
644 vrregs, offsets->vrsave_offset, 4);
645 return;
646 }
647
648 offset = ppc_vrreg_offset (tdep, offsets, regnum);
649 if (regnum != tdep->ppc_vrsave_regnum
650 && regnum != tdep->ppc_vrsave_regnum - 1)
651 ppc_supply_reg (regcache, regnum, vrregs, offset, 16);
652 else
653 ppc_supply_reg (regcache, regnum,
654 vrregs, offset, 4);
655}
656
d195bc9f 657/* Collect register REGNUM in the general-purpose register set
f2db237a 658 REGSET from register cache REGCACHE into the buffer specified by
d195bc9f
MK
659 GREGS and LEN. If REGNUM is -1, do this for all registers in
660 REGSET. */
661
662void
663ppc_collect_gregset (const struct regset *regset,
664 const struct regcache *regcache,
665 int regnum, void *gregs, size_t len)
666{
667 struct gdbarch *gdbarch = get_regcache_arch (regcache);
668 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7fefa8d7 669 const struct ppc_reg_offsets *offsets = regset->regmap;
d195bc9f 670 size_t offset;
f2db237a 671 int regsize;
d195bc9f 672
f2db237a 673 if (regnum == -1)
d195bc9f 674 {
f2db237a
AM
675 int i;
676 int gpr_size = offsets->gpr_size;
677
678 for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset;
679 i < tdep->ppc_gp0_regnum + ppc_num_gprs;
680 i++, offset += gpr_size)
681 ppc_collect_reg (regcache, i, gregs, offset, gpr_size);
682
683 ppc_collect_reg (regcache, gdbarch_pc_regnum (gdbarch),
684 gregs, offsets->pc_offset, gpr_size);
685 ppc_collect_reg (regcache, tdep->ppc_ps_regnum,
686 gregs, offsets->ps_offset, gpr_size);
687 ppc_collect_reg (regcache, tdep->ppc_lr_regnum,
688 gregs, offsets->lr_offset, gpr_size);
689 ppc_collect_reg (regcache, tdep->ppc_ctr_regnum,
690 gregs, offsets->ctr_offset, gpr_size);
691 ppc_collect_reg (regcache, tdep->ppc_cr_regnum,
692 gregs, offsets->cr_offset, offsets->xr_size);
693 ppc_collect_reg (regcache, tdep->ppc_xer_regnum,
694 gregs, offsets->xer_offset, offsets->xr_size);
695 ppc_collect_reg (regcache, tdep->ppc_mq_regnum,
696 gregs, offsets->mq_offset, offsets->xr_size);
697 return;
d195bc9f
MK
698 }
699
f2db237a
AM
700 offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, &regsize);
701 ppc_collect_reg (regcache, regnum, gregs, offset, regsize);
d195bc9f
MK
702}
703
704/* Collect register REGNUM in the floating-point register set
f2db237a 705 REGSET from register cache REGCACHE into the buffer specified by
d195bc9f
MK
706 FPREGS and LEN. If REGNUM is -1, do this for all registers in
707 REGSET. */
708
709void
710ppc_collect_fpregset (const struct regset *regset,
711 const struct regcache *regcache,
712 int regnum, void *fpregs, size_t len)
713{
714 struct gdbarch *gdbarch = get_regcache_arch (regcache);
f2db237a
AM
715 struct gdbarch_tdep *tdep;
716 const struct ppc_reg_offsets *offsets;
d195bc9f 717 size_t offset;
d195bc9f 718
f2db237a
AM
719 if (!ppc_floating_point_unit_p (gdbarch))
720 return;
383f0f5b 721
f2db237a 722 tdep = gdbarch_tdep (gdbarch);
7fefa8d7 723 offsets = regset->regmap;
f2db237a 724 if (regnum == -1)
d195bc9f 725 {
f2db237a
AM
726 int i;
727
728 for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset;
729 i < tdep->ppc_fp0_regnum + ppc_num_fprs;
730 i++, offset += 8)
731 ppc_collect_reg (regcache, i, fpregs, offset, 8);
732
733 ppc_collect_reg (regcache, tdep->ppc_fpscr_regnum,
734 fpregs, offsets->fpscr_offset, offsets->fpscr_size);
735 return;
d195bc9f
MK
736 }
737
f2db237a
AM
738 offset = ppc_fpreg_offset (tdep, offsets, regnum);
739 ppc_collect_reg (regcache, regnum, fpregs, offset,
740 regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8);
d195bc9f 741}
06caf7d2 742
604c2f83
LM
743/* Collect register REGNUM in the VSX register set
744 REGSET from register cache REGCACHE into the buffer specified by
745 VSXREGS and LEN. If REGNUM is -1, do this for all registers in
746 REGSET. */
747
748void
749ppc_collect_vsxregset (const struct regset *regset,
750 const struct regcache *regcache,
751 int regnum, void *vsxregs, size_t len)
752{
753 struct gdbarch *gdbarch = get_regcache_arch (regcache);
754 struct gdbarch_tdep *tdep;
755
756 if (!ppc_vsx_support_p (gdbarch))
757 return;
758
759 tdep = gdbarch_tdep (gdbarch);
760
761 if (regnum == -1)
762 {
763 int i;
764
765 for (i = tdep->ppc_vsr0_upper_regnum;
766 i < tdep->ppc_vsr0_upper_regnum + 32;
767 i++)
768 ppc_collect_reg (regcache, i, vsxregs, 0, 8);
769
770 return;
771 }
772 else
773 ppc_collect_reg (regcache, regnum, vsxregs, 0, 8);
774}
775
776
06caf7d2
CES
777/* Collect register REGNUM in the Altivec register set
778 REGSET from register cache REGCACHE into the buffer specified by
779 VRREGS and LEN. If REGNUM is -1, do this for all registers in
780 REGSET. */
781
782void
783ppc_collect_vrregset (const struct regset *regset,
784 const struct regcache *regcache,
785 int regnum, void *vrregs, size_t len)
786{
787 struct gdbarch *gdbarch = get_regcache_arch (regcache);
788 struct gdbarch_tdep *tdep;
789 const struct ppc_reg_offsets *offsets;
790 size_t offset;
791
792 if (!ppc_altivec_support_p (gdbarch))
793 return;
794
795 tdep = gdbarch_tdep (gdbarch);
7fefa8d7 796 offsets = regset->regmap;
06caf7d2
CES
797 if (regnum == -1)
798 {
799 int i;
800
801 for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset;
802 i < tdep->ppc_vr0_regnum + ppc_num_vrs;
803 i++, offset += 16)
804 ppc_collect_reg (regcache, i, vrregs, offset, 16);
805
806 ppc_collect_reg (regcache, (tdep->ppc_vrsave_regnum - 1),
807 vrregs, offsets->vscr_offset, 4);
808
809 ppc_collect_reg (regcache, tdep->ppc_vrsave_regnum,
810 vrregs, offsets->vrsave_offset, 4);
811 return;
812 }
813
814 offset = ppc_vrreg_offset (tdep, offsets, regnum);
815 if (regnum != tdep->ppc_vrsave_regnum
816 && regnum != tdep->ppc_vrsave_regnum - 1)
817 ppc_collect_reg (regcache, regnum, vrregs, offset, 16);
818 else
819 ppc_collect_reg (regcache, regnum,
820 vrregs, offset, 4);
821}
d195bc9f 822\f
0a613259 823
0d1243d9
PG
824static int
825insn_changes_sp_or_jumps (unsigned long insn)
826{
827 int opcode = (insn >> 26) & 0x03f;
828 int sd = (insn >> 21) & 0x01f;
829 int a = (insn >> 16) & 0x01f;
830 int subcode = (insn >> 1) & 0x3ff;
831
832 /* Changes the stack pointer. */
833
834 /* NOTE: There are many ways to change the value of a given register.
835 The ways below are those used when the register is R1, the SP,
836 in a funtion's epilogue. */
837
838 if (opcode == 31 && subcode == 444 && a == 1)
839 return 1; /* mr R1,Rn */
840 if (opcode == 14 && sd == 1)
841 return 1; /* addi R1,Rn,simm */
842 if (opcode == 58 && sd == 1)
843 return 1; /* ld R1,ds(Rn) */
844
845 /* Transfers control. */
846
847 if (opcode == 18)
848 return 1; /* b */
849 if (opcode == 16)
850 return 1; /* bc */
851 if (opcode == 19 && subcode == 16)
852 return 1; /* bclr */
853 if (opcode == 19 && subcode == 528)
854 return 1; /* bcctr */
855
856 return 0;
857}
858
859/* Return true if we are in the function's epilogue, i.e. after the
860 instruction that destroyed the function's stack frame.
861
862 1) scan forward from the point of execution:
863 a) If you find an instruction that modifies the stack pointer
864 or transfers control (except a return), execution is not in
865 an epilogue, return.
866 b) Stop scanning if you find a return instruction or reach the
867 end of the function or reach the hard limit for the size of
868 an epilogue.
869 2) scan backward from the point of execution:
870 a) If you find an instruction that modifies the stack pointer,
871 execution *is* in an epilogue, return.
872 b) Stop scanning if you reach an instruction that transfers
873 control or the beginning of the function or reach the hard
874 limit for the size of an epilogue. */
875
876static int
2608dbf8
WW
877rs6000_in_function_epilogue_frame_p (struct frame_info *curfrm,
878 struct gdbarch *gdbarch, CORE_ADDR pc)
0d1243d9 879{
46a9b8ed 880 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
e17a4113 881 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
0d1243d9
PG
882 bfd_byte insn_buf[PPC_INSN_SIZE];
883 CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
884 unsigned long insn;
0d1243d9
PG
885
886 /* Find the search limits based on function boundaries and hard limit. */
887
888 if (!find_pc_partial_function (pc, NULL, &func_start, &func_end))
889 return 0;
890
891 epilogue_start = pc - PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE;
892 if (epilogue_start < func_start) epilogue_start = func_start;
893
894 epilogue_end = pc + PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE;
895 if (epilogue_end > func_end) epilogue_end = func_end;
896
0d1243d9
PG
897 /* Scan forward until next 'blr'. */
898
899 for (scan_pc = pc; scan_pc < epilogue_end; scan_pc += PPC_INSN_SIZE)
900 {
901 if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE))
902 return 0;
e17a4113 903 insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE, byte_order);
0d1243d9
PG
904 if (insn == 0x4e800020)
905 break;
46a9b8ed
DJ
906 /* Assume a bctr is a tail call unless it points strictly within
907 this function. */
908 if (insn == 0x4e800420)
909 {
910 CORE_ADDR ctr = get_frame_register_unsigned (curfrm,
911 tdep->ppc_ctr_regnum);
912 if (ctr > func_start && ctr < func_end)
913 return 0;
914 else
915 break;
916 }
0d1243d9
PG
917 if (insn_changes_sp_or_jumps (insn))
918 return 0;
919 }
920
921 /* Scan backward until adjustment to stack pointer (R1). */
922
923 for (scan_pc = pc - PPC_INSN_SIZE;
924 scan_pc >= epilogue_start;
925 scan_pc -= PPC_INSN_SIZE)
926 {
927 if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE))
928 return 0;
e17a4113 929 insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE, byte_order);
0d1243d9
PG
930 if (insn_changes_sp_or_jumps (insn))
931 return 1;
932 }
933
934 return 0;
935}
936
2608dbf8
WW
937/* Implementation of gdbarch_in_function_epilogue_p. */
938
939static int
940rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
941{
942 return rs6000_in_function_epilogue_frame_p (get_current_frame (),
943 gdbarch, pc);
944}
945
143985b7 946/* Get the ith function argument for the current function. */
b9362cc7 947static CORE_ADDR
143985b7
AF
948rs6000_fetch_pointer_argument (struct frame_info *frame, int argi,
949 struct type *type)
950{
50fd1280 951 return get_frame_register_unsigned (frame, 3 + argi);
143985b7
AF
952}
953
c906108c
SS
954/* Sequence of bytes for breakpoint instruction. */
955
44d100c3 956static const unsigned char *
67d57894
MD
957rs6000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
958 int *bp_size)
c906108c 959{
aaab4dba
AC
960 static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
961 static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
c906108c 962 *bp_size = 4;
67d57894 963 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
c906108c
SS
964 return big_breakpoint;
965 else
966 return little_breakpoint;
967}
968
f74c6cad
LM
969/* Instruction masks for displaced stepping. */
970#define BRANCH_MASK 0xfc000000
971#define BP_MASK 0xFC0007FE
972#define B_INSN 0x48000000
973#define BC_INSN 0x40000000
974#define BXL_INSN 0x4c000000
975#define BP_INSN 0x7C000008
976
977/* Fix up the state of registers and memory after having single-stepped
978 a displaced instruction. */
63807e1d 979static void
f74c6cad 980ppc_displaced_step_fixup (struct gdbarch *gdbarch,
63807e1d
PA
981 struct displaced_step_closure *closure,
982 CORE_ADDR from, CORE_ADDR to,
983 struct regcache *regs)
f74c6cad 984{
e17a4113 985 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
f74c6cad
LM
986 /* Since we use simple_displaced_step_copy_insn, our closure is a
987 copy of the instruction. */
988 ULONGEST insn = extract_unsigned_integer ((gdb_byte *) closure,
e17a4113 989 PPC_INSN_SIZE, byte_order);
f74c6cad
LM
990 ULONGEST opcode = 0;
991 /* Offset for non PC-relative instructions. */
992 LONGEST offset = PPC_INSN_SIZE;
993
994 opcode = insn & BRANCH_MASK;
995
996 if (debug_displaced)
997 fprintf_unfiltered (gdb_stdlog,
5af949e3
UW
998 "displaced: (ppc) fixup (%s, %s)\n",
999 paddress (gdbarch, from), paddress (gdbarch, to));
f74c6cad
LM
1000
1001
1002 /* Handle PC-relative branch instructions. */
1003 if (opcode == B_INSN || opcode == BC_INSN || opcode == BXL_INSN)
1004 {
a4fafde3 1005 ULONGEST current_pc;
f74c6cad
LM
1006
1007 /* Read the current PC value after the instruction has been executed
1008 in a displaced location. Calculate the offset to be applied to the
1009 original PC value before the displaced stepping. */
1010 regcache_cooked_read_unsigned (regs, gdbarch_pc_regnum (gdbarch),
1011 &current_pc);
1012 offset = current_pc - to;
1013
1014 if (opcode != BXL_INSN)
1015 {
1016 /* Check for AA bit indicating whether this is an absolute
1017 addressing or PC-relative (1: absolute, 0: relative). */
1018 if (!(insn & 0x2))
1019 {
1020 /* PC-relative addressing is being used in the branch. */
1021 if (debug_displaced)
1022 fprintf_unfiltered
1023 (gdb_stdlog,
5af949e3
UW
1024 "displaced: (ppc) branch instruction: %s\n"
1025 "displaced: (ppc) adjusted PC from %s to %s\n",
1026 paddress (gdbarch, insn), paddress (gdbarch, current_pc),
1027 paddress (gdbarch, from + offset));
f74c6cad 1028
0df8b418
MS
1029 regcache_cooked_write_unsigned (regs,
1030 gdbarch_pc_regnum (gdbarch),
f74c6cad
LM
1031 from + offset);
1032 }
1033 }
1034 else
1035 {
1036 /* If we're here, it means we have a branch to LR or CTR. If the
1037 branch was taken, the offset is probably greater than 4 (the next
1038 instruction), so it's safe to assume that an offset of 4 means we
1039 did not take the branch. */
1040 if (offset == PPC_INSN_SIZE)
1041 regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch),
1042 from + PPC_INSN_SIZE);
1043 }
1044
1045 /* Check for LK bit indicating whether we should set the link
1046 register to point to the next instruction
1047 (1: Set, 0: Don't set). */
1048 if (insn & 0x1)
1049 {
1050 /* Link register needs to be set to the next instruction's PC. */
1051 regcache_cooked_write_unsigned (regs,
1052 gdbarch_tdep (gdbarch)->ppc_lr_regnum,
1053 from + PPC_INSN_SIZE);
1054 if (debug_displaced)
1055 fprintf_unfiltered (gdb_stdlog,
5af949e3
UW
1056 "displaced: (ppc) adjusted LR to %s\n",
1057 paddress (gdbarch, from + PPC_INSN_SIZE));
f74c6cad
LM
1058
1059 }
1060 }
1061 /* Check for breakpoints in the inferior. If we've found one, place the PC
1062 right at the breakpoint instruction. */
1063 else if ((insn & BP_MASK) == BP_INSN)
1064 regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), from);
1065 else
1066 /* Handle any other instructions that do not fit in the categories above. */
1067 regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch),
1068 from + offset);
1069}
c906108c 1070
99e40580
UW
1071/* Always use hardware single-stepping to execute the
1072 displaced instruction. */
1073static int
1074ppc_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
1075 struct displaced_step_closure *closure)
1076{
1077 return 1;
1078}
1079
ce5eab59
UW
1080/* Instruction masks used during single-stepping of atomic sequences. */
1081#define LWARX_MASK 0xfc0007fe
1082#define LWARX_INSTRUCTION 0x7c000028
1083#define LDARX_INSTRUCTION 0x7c0000A8
1084#define STWCX_MASK 0xfc0007ff
1085#define STWCX_INSTRUCTION 0x7c00012d
1086#define STDCX_INSTRUCTION 0x7c0001ad
ce5eab59
UW
1087
1088/* Checks for an atomic sequence of instructions beginning with a LWARX/LDARX
1089 instruction and ending with a STWCX/STDCX instruction. If such a sequence
1090 is found, attempt to step through it. A breakpoint is placed at the end of
1091 the sequence. */
1092
4a7622d1
UW
1093int
1094ppc_deal_with_atomic_sequence (struct frame_info *frame)
ce5eab59 1095{
a6d9a66e 1096 struct gdbarch *gdbarch = get_frame_arch (frame);
6c95b8df 1097 struct address_space *aspace = get_frame_address_space (frame);
e17a4113 1098 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
0b1b3e42 1099 CORE_ADDR pc = get_frame_pc (frame);
ce5eab59
UW
1100 CORE_ADDR breaks[2] = {-1, -1};
1101 CORE_ADDR loc = pc;
24d45690 1102 CORE_ADDR closing_insn; /* Instruction that closes the atomic sequence. */
e17a4113 1103 int insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order);
ce5eab59
UW
1104 int insn_count;
1105 int index;
1106 int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
1107 const int atomic_sequence_length = 16; /* Instruction sequence length. */
24d45690 1108 int opcode; /* Branch instruction's OPcode. */
ce5eab59
UW
1109 int bc_insn_count = 0; /* Conditional branch instruction count. */
1110
1111 /* Assume all atomic sequences start with a lwarx/ldarx instruction. */
1112 if ((insn & LWARX_MASK) != LWARX_INSTRUCTION
1113 && (insn & LWARX_MASK) != LDARX_INSTRUCTION)
1114 return 0;
1115
1116 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
1117 instructions. */
1118 for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
1119 {
1120 loc += PPC_INSN_SIZE;
e17a4113 1121 insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order);
ce5eab59
UW
1122
1123 /* Assume that there is at most one conditional branch in the atomic
1124 sequence. If a conditional branch is found, put a breakpoint in
1125 its destination address. */
f74c6cad 1126 if ((insn & BRANCH_MASK) == BC_INSN)
ce5eab59 1127 {
a3769e0c
AM
1128 int immediate = ((insn & 0xfffc) ^ 0x8000) - 0x8000;
1129 int absolute = insn & 2;
4a7622d1 1130
ce5eab59
UW
1131 if (bc_insn_count >= 1)
1132 return 0; /* More than one conditional branch found, fallback
1133 to the standard single-step code. */
4a7622d1
UW
1134
1135 if (absolute)
1136 breaks[1] = immediate;
1137 else
a3769e0c 1138 breaks[1] = loc + immediate;
4a7622d1
UW
1139
1140 bc_insn_count++;
1141 last_breakpoint++;
ce5eab59
UW
1142 }
1143
1144 if ((insn & STWCX_MASK) == STWCX_INSTRUCTION
1145 || (insn & STWCX_MASK) == STDCX_INSTRUCTION)
1146 break;
1147 }
1148
1149 /* Assume that the atomic sequence ends with a stwcx/stdcx instruction. */
1150 if ((insn & STWCX_MASK) != STWCX_INSTRUCTION
1151 && (insn & STWCX_MASK) != STDCX_INSTRUCTION)
1152 return 0;
1153
24d45690 1154 closing_insn = loc;
ce5eab59 1155 loc += PPC_INSN_SIZE;
e17a4113 1156 insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order);
ce5eab59
UW
1157
1158 /* Insert a breakpoint right after the end of the atomic sequence. */
1159 breaks[0] = loc;
1160
24d45690 1161 /* Check for duplicated breakpoints. Check also for a breakpoint
a3769e0c
AM
1162 placed (branch instruction's destination) anywhere in sequence. */
1163 if (last_breakpoint
1164 && (breaks[1] == breaks[0]
1165 || (breaks[1] >= pc && breaks[1] <= closing_insn)))
ce5eab59
UW
1166 last_breakpoint = 0;
1167
1168 /* Effectively inserts the breakpoints. */
1169 for (index = 0; index <= last_breakpoint; index++)
6c95b8df 1170 insert_single_step_breakpoint (gdbarch, aspace, breaks[index]);
ce5eab59
UW
1171
1172 return 1;
1173}
1174
c906108c 1175
c906108c
SS
1176#define SIGNED_SHORT(x) \
1177 ((sizeof (short) == 2) \
1178 ? ((int)(short)(x)) \
1179 : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000)))
1180
1181#define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
1182
55d05f3b
KB
1183/* Limit the number of skipped non-prologue instructions, as the examining
1184 of the prologue is expensive. */
1185static int max_skip_non_prologue_insns = 10;
1186
773df3e5
JB
1187/* Return nonzero if the given instruction OP can be part of the prologue
1188 of a function and saves a parameter on the stack. FRAMEP should be
1189 set if one of the previous instructions in the function has set the
1190 Frame Pointer. */
1191
1192static int
1193store_param_on_stack_p (unsigned long op, int framep, int *r0_contains_arg)
1194{
1195 /* Move parameters from argument registers to temporary register. */
1196 if ((op & 0xfc0007fe) == 0x7c000378) /* mr(.) Rx,Ry */
1197 {
1198 /* Rx must be scratch register r0. */
1199 const int rx_regno = (op >> 16) & 31;
1200 /* Ry: Only r3 - r10 are used for parameter passing. */
1201 const int ry_regno = GET_SRC_REG (op);
1202
1203 if (rx_regno == 0 && ry_regno >= 3 && ry_regno <= 10)
1204 {
1205 *r0_contains_arg = 1;
1206 return 1;
1207 }
1208 else
1209 return 0;
1210 }
1211
1212 /* Save a General Purpose Register on stack. */
1213
1214 if ((op & 0xfc1f0003) == 0xf8010000 || /* std Rx,NUM(r1) */
1215 (op & 0xfc1f0000) == 0xd8010000) /* stfd Rx,NUM(r1) */
1216 {
1217 /* Rx: Only r3 - r10 are used for parameter passing. */
1218 const int rx_regno = GET_SRC_REG (op);
1219
1220 return (rx_regno >= 3 && rx_regno <= 10);
1221 }
1222
1223 /* Save a General Purpose Register on stack via the Frame Pointer. */
1224
1225 if (framep &&
1226 ((op & 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r31) */
1227 (op & 0xfc1f0000) == 0x981f0000 || /* stb Rx,NUM(r31) */
1228 (op & 0xfc1f0000) == 0xd81f0000)) /* stfd Rx,NUM(r31) */
1229 {
1230 /* Rx: Usually, only r3 - r10 are used for parameter passing.
1231 However, the compiler sometimes uses r0 to hold an argument. */
1232 const int rx_regno = GET_SRC_REG (op);
1233
1234 return ((rx_regno >= 3 && rx_regno <= 10)
1235 || (rx_regno == 0 && *r0_contains_arg));
1236 }
1237
1238 if ((op & 0xfc1f0000) == 0xfc010000) /* frsp, fp?,NUM(r1) */
1239 {
1240 /* Only f2 - f8 are used for parameter passing. */
1241 const int src_regno = GET_SRC_REG (op);
1242
1243 return (src_regno >= 2 && src_regno <= 8);
1244 }
1245
1246 if (framep && ((op & 0xfc1f0000) == 0xfc1f0000)) /* frsp, fp?,NUM(r31) */
1247 {
1248 /* Only f2 - f8 are used for parameter passing. */
1249 const int src_regno = GET_SRC_REG (op);
1250
1251 return (src_regno >= 2 && src_regno <= 8);
1252 }
1253
1254 /* Not an insn that saves a parameter on stack. */
1255 return 0;
1256}
55d05f3b 1257
3c77c82a
DJ
1258/* Assuming that INSN is a "bl" instruction located at PC, return
1259 nonzero if the destination of the branch is a "blrl" instruction.
1260
1261 This sequence is sometimes found in certain function prologues.
1262 It allows the function to load the LR register with a value that
1263 they can use to access PIC data using PC-relative offsets. */
1264
1265static int
e17a4113 1266bl_to_blrl_insn_p (CORE_ADDR pc, int insn, enum bfd_endian byte_order)
3c77c82a 1267{
0b1b3e42
UW
1268 CORE_ADDR dest;
1269 int immediate;
1270 int absolute;
3c77c82a
DJ
1271 int dest_insn;
1272
0b1b3e42
UW
1273 absolute = (int) ((insn >> 1) & 1);
1274 immediate = ((insn & ~3) << 6) >> 6;
1275 if (absolute)
1276 dest = immediate;
1277 else
1278 dest = pc + immediate;
1279
e17a4113 1280 dest_insn = read_memory_integer (dest, 4, byte_order);
3c77c82a
DJ
1281 if ((dest_insn & 0xfc00ffff) == 0x4c000021) /* blrl */
1282 return 1;
1283
1284 return 0;
1285}
1286
0df8b418 1287/* Masks for decoding a branch-and-link (bl) instruction.
8ab3d180
KB
1288
1289 BL_MASK and BL_INSTRUCTION are used in combination with each other.
1290 The former is anded with the opcode in question; if the result of
1291 this masking operation is equal to BL_INSTRUCTION, then the opcode in
1292 question is a ``bl'' instruction.
1293
1294 BL_DISPLACMENT_MASK is anded with the opcode in order to extract
1295 the branch displacement. */
1296
1297#define BL_MASK 0xfc000001
1298#define BL_INSTRUCTION 0x48000001
1299#define BL_DISPLACEMENT_MASK 0x03fffffc
1300
de9f48f0 1301static unsigned long
e17a4113 1302rs6000_fetch_instruction (struct gdbarch *gdbarch, const CORE_ADDR pc)
de9f48f0 1303{
e17a4113 1304 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
de9f48f0
JG
1305 gdb_byte buf[4];
1306 unsigned long op;
1307
1308 /* Fetch the instruction and convert it to an integer. */
1309 if (target_read_memory (pc, buf, 4))
1310 return 0;
e17a4113 1311 op = extract_unsigned_integer (buf, 4, byte_order);
de9f48f0
JG
1312
1313 return op;
1314}
1315
1316/* GCC generates several well-known sequences of instructions at the begining
1317 of each function prologue when compiling with -fstack-check. If one of
1318 such sequences starts at START_PC, then return the address of the
1319 instruction immediately past this sequence. Otherwise, return START_PC. */
1320
1321static CORE_ADDR
e17a4113 1322rs6000_skip_stack_check (struct gdbarch *gdbarch, const CORE_ADDR start_pc)
de9f48f0
JG
1323{
1324 CORE_ADDR pc = start_pc;
e17a4113 1325 unsigned long op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1326
1327 /* First possible sequence: A small number of probes.
1328 stw 0, -<some immediate>(1)
0df8b418 1329 [repeat this instruction any (small) number of times]. */
de9f48f0
JG
1330
1331 if ((op & 0xffff0000) == 0x90010000)
1332 {
1333 while ((op & 0xffff0000) == 0x90010000)
1334 {
1335 pc = pc + 4;
e17a4113 1336 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1337 }
1338 return pc;
1339 }
1340
1341 /* Second sequence: A probing loop.
1342 addi 12,1,-<some immediate>
1343 lis 0,-<some immediate>
1344 [possibly ori 0,0,<some immediate>]
1345 add 0,12,0
1346 cmpw 0,12,0
1347 beq 0,<disp>
1348 addi 12,12,-<some immediate>
1349 stw 0,0(12)
1350 b <disp>
0df8b418 1351 [possibly one last probe: stw 0,<some immediate>(12)]. */
de9f48f0
JG
1352
1353 while (1)
1354 {
1355 /* addi 12,1,-<some immediate> */
1356 if ((op & 0xffff0000) != 0x39810000)
1357 break;
1358
1359 /* lis 0,-<some immediate> */
1360 pc = pc + 4;
e17a4113 1361 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1362 if ((op & 0xffff0000) != 0x3c000000)
1363 break;
1364
1365 pc = pc + 4;
e17a4113 1366 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1367 /* [possibly ori 0,0,<some immediate>] */
1368 if ((op & 0xffff0000) == 0x60000000)
1369 {
1370 pc = pc + 4;
e17a4113 1371 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1372 }
1373 /* add 0,12,0 */
1374 if (op != 0x7c0c0214)
1375 break;
1376
1377 /* cmpw 0,12,0 */
1378 pc = pc + 4;
e17a4113 1379 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1380 if (op != 0x7c0c0000)
1381 break;
1382
1383 /* beq 0,<disp> */
1384 pc = pc + 4;
e17a4113 1385 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1386 if ((op & 0xff9f0001) != 0x41820000)
1387 break;
1388
1389 /* addi 12,12,-<some immediate> */
1390 pc = pc + 4;
e17a4113 1391 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1392 if ((op & 0xffff0000) != 0x398c0000)
1393 break;
1394
1395 /* stw 0,0(12) */
1396 pc = pc + 4;
e17a4113 1397 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1398 if (op != 0x900c0000)
1399 break;
1400
1401 /* b <disp> */
1402 pc = pc + 4;
e17a4113 1403 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1404 if ((op & 0xfc000001) != 0x48000000)
1405 break;
1406
0df8b418 1407 /* [possibly one last probe: stw 0,<some immediate>(12)]. */
de9f48f0 1408 pc = pc + 4;
e17a4113 1409 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1410 if ((op & 0xffff0000) == 0x900c0000)
1411 {
1412 pc = pc + 4;
e17a4113 1413 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1414 }
1415
1416 /* We found a valid stack-check sequence, return the new PC. */
1417 return pc;
1418 }
1419
1420 /* Third sequence: No probe; instead, a comparizon between the stack size
1421 limit (saved in a run-time global variable) and the current stack
1422 pointer:
1423
1424 addi 0,1,-<some immediate>
1425 lis 12,__gnat_stack_limit@ha
1426 lwz 12,__gnat_stack_limit@l(12)
1427 twllt 0,12
1428
1429 or, with a small variant in the case of a bigger stack frame:
1430 addis 0,1,<some immediate>
1431 addic 0,0,-<some immediate>
1432 lis 12,__gnat_stack_limit@ha
1433 lwz 12,__gnat_stack_limit@l(12)
1434 twllt 0,12
1435 */
1436 while (1)
1437 {
1438 /* addi 0,1,-<some immediate> */
1439 if ((op & 0xffff0000) != 0x38010000)
1440 {
1441 /* small stack frame variant not recognized; try the
1442 big stack frame variant: */
1443
1444 /* addis 0,1,<some immediate> */
1445 if ((op & 0xffff0000) != 0x3c010000)
1446 break;
1447
1448 /* addic 0,0,-<some immediate> */
1449 pc = pc + 4;
e17a4113 1450 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1451 if ((op & 0xffff0000) != 0x30000000)
1452 break;
1453 }
1454
1455 /* lis 12,<some immediate> */
1456 pc = pc + 4;
e17a4113 1457 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1458 if ((op & 0xffff0000) != 0x3d800000)
1459 break;
1460
1461 /* lwz 12,<some immediate>(12) */
1462 pc = pc + 4;
e17a4113 1463 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1464 if ((op & 0xffff0000) != 0x818c0000)
1465 break;
1466
1467 /* twllt 0,12 */
1468 pc = pc + 4;
e17a4113 1469 op = rs6000_fetch_instruction (gdbarch, pc);
de9f48f0
JG
1470 if ((op & 0xfffffffe) != 0x7c406008)
1471 break;
1472
1473 /* We found a valid stack-check sequence, return the new PC. */
1474 return pc;
1475 }
1476
1477 /* No stack check code in our prologue, return the start_pc. */
1478 return start_pc;
1479}
1480
6a16c029
TJB
1481/* return pc value after skipping a function prologue and also return
1482 information about a function frame.
1483
1484 in struct rs6000_framedata fdata:
1485 - frameless is TRUE, if function does not have a frame.
1486 - nosavedpc is TRUE, if function does not save %pc value in its frame.
1487 - offset is the initial size of this stack frame --- the amount by
1488 which we decrement the sp to allocate the frame.
1489 - saved_gpr is the number of the first saved gpr.
1490 - saved_fpr is the number of the first saved fpr.
1491 - saved_vr is the number of the first saved vr.
1492 - saved_ev is the number of the first saved ev.
1493 - alloca_reg is the number of the register used for alloca() handling.
1494 Otherwise -1.
1495 - gpr_offset is the offset of the first saved gpr from the previous frame.
1496 - fpr_offset is the offset of the first saved fpr from the previous frame.
1497 - vr_offset is the offset of the first saved vr from the previous frame.
1498 - ev_offset is the offset of the first saved ev from the previous frame.
1499 - lr_offset is the offset of the saved lr
1500 - cr_offset is the offset of the saved cr
0df8b418 1501 - vrsave_offset is the offset of the saved vrsave register. */
6a16c029 1502
7a78ae4e 1503static CORE_ADDR
be8626e0
MD
1504skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
1505 struct rs6000_framedata *fdata)
c906108c
SS
1506{
1507 CORE_ADDR orig_pc = pc;
55d05f3b 1508 CORE_ADDR last_prologue_pc = pc;
6be8bc0c 1509 CORE_ADDR li_found_pc = 0;
50fd1280 1510 gdb_byte buf[4];
c906108c
SS
1511 unsigned long op;
1512 long offset = 0;
6be8bc0c 1513 long vr_saved_offset = 0;
482ca3f5
KB
1514 int lr_reg = -1;
1515 int cr_reg = -1;
6be8bc0c 1516 int vr_reg = -1;
96ff0de4
EZ
1517 int ev_reg = -1;
1518 long ev_offset = 0;
6be8bc0c 1519 int vrsave_reg = -1;
c906108c
SS
1520 int reg;
1521 int framep = 0;
1522 int minimal_toc_loaded = 0;
ddb20c56 1523 int prev_insn_was_prologue_insn = 1;
55d05f3b 1524 int num_skip_non_prologue_insns = 0;
773df3e5 1525 int r0_contains_arg = 0;
be8626e0
MD
1526 const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
1527 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
e17a4113 1528 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
c906108c 1529
ddb20c56 1530 memset (fdata, 0, sizeof (struct rs6000_framedata));
c906108c
SS
1531 fdata->saved_gpr = -1;
1532 fdata->saved_fpr = -1;
6be8bc0c 1533 fdata->saved_vr = -1;
96ff0de4 1534 fdata->saved_ev = -1;
c906108c
SS
1535 fdata->alloca_reg = -1;
1536 fdata->frameless = 1;
1537 fdata->nosavedpc = 1;
46a9b8ed 1538 fdata->lr_register = -1;
c906108c 1539
e17a4113 1540 pc = rs6000_skip_stack_check (gdbarch, pc);
de9f48f0
JG
1541 if (pc >= lim_pc)
1542 pc = lim_pc;
1543
55d05f3b 1544 for (;; pc += 4)
c906108c 1545 {
ddb20c56
KB
1546 /* Sometimes it isn't clear if an instruction is a prologue
1547 instruction or not. When we encounter one of these ambiguous
1548 cases, we'll set prev_insn_was_prologue_insn to 0 (false).
0df8b418 1549 Otherwise, we'll assume that it really is a prologue instruction. */
ddb20c56
KB
1550 if (prev_insn_was_prologue_insn)
1551 last_prologue_pc = pc;
55d05f3b
KB
1552
1553 /* Stop scanning if we've hit the limit. */
4e463ff5 1554 if (pc >= lim_pc)
55d05f3b
KB
1555 break;
1556
ddb20c56
KB
1557 prev_insn_was_prologue_insn = 1;
1558
55d05f3b 1559 /* Fetch the instruction and convert it to an integer. */
ddb20c56
KB
1560 if (target_read_memory (pc, buf, 4))
1561 break;
e17a4113 1562 op = extract_unsigned_integer (buf, 4, byte_order);
c906108c 1563
c5aa993b
JM
1564 if ((op & 0xfc1fffff) == 0x7c0802a6)
1565 { /* mflr Rx */
43b1ab88
AC
1566 /* Since shared library / PIC code, which needs to get its
1567 address at runtime, can appear to save more than one link
1568 register vis:
1569
1570 *INDENT-OFF*
1571 stwu r1,-304(r1)
1572 mflr r3
1573 bl 0xff570d0 (blrl)
1574 stw r30,296(r1)
1575 mflr r30
1576 stw r31,300(r1)
1577 stw r3,308(r1);
1578 ...
1579 *INDENT-ON*
1580
1581 remember just the first one, but skip over additional
1582 ones. */
721d14ba 1583 if (lr_reg == -1)
46a9b8ed 1584 lr_reg = (op & 0x03e00000) >> 21;
773df3e5
JB
1585 if (lr_reg == 0)
1586 r0_contains_arg = 0;
c5aa993b 1587 continue;
c5aa993b
JM
1588 }
1589 else if ((op & 0xfc1fffff) == 0x7c000026)
1590 { /* mfcr Rx */
98f08d3d 1591 cr_reg = (op & 0x03e00000);
773df3e5
JB
1592 if (cr_reg == 0)
1593 r0_contains_arg = 0;
c5aa993b 1594 continue;
c906108c 1595
c906108c 1596 }
c5aa993b
JM
1597 else if ((op & 0xfc1f0000) == 0xd8010000)
1598 { /* stfd Rx,NUM(r1) */
1599 reg = GET_SRC_REG (op);
1600 if (fdata->saved_fpr == -1 || fdata->saved_fpr > reg)
1601 {
1602 fdata->saved_fpr = reg;
1603 fdata->fpr_offset = SIGNED_SHORT (op) + offset;
1604 }
1605 continue;
c906108c 1606
c5aa993b
JM
1607 }
1608 else if (((op & 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */
7a78ae4e
ND
1609 (((op & 0xfc1f0000) == 0x90010000 || /* st rx,NUM(r1) */
1610 (op & 0xfc1f0003) == 0xf8010000) && /* std rx,NUM(r1) */
1611 (op & 0x03e00000) >= 0x01a00000)) /* rx >= r13 */
c5aa993b
JM
1612 {
1613
1614 reg = GET_SRC_REG (op);
46a9b8ed
DJ
1615 if ((op & 0xfc1f0000) == 0xbc010000)
1616 fdata->gpr_mask |= ~((1U << reg) - 1);
1617 else
1618 fdata->gpr_mask |= 1U << reg;
c5aa993b
JM
1619 if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg)
1620 {
1621 fdata->saved_gpr = reg;
7a78ae4e 1622 if ((op & 0xfc1f0003) == 0xf8010000)
98f08d3d 1623 op &= ~3UL;
c5aa993b
JM
1624 fdata->gpr_offset = SIGNED_SHORT (op) + offset;
1625 }
1626 continue;
c906108c 1627
ddb20c56 1628 }
ef1bc9e7
AM
1629 else if ((op & 0xffff0000) == 0x3c4c0000
1630 || (op & 0xffff0000) == 0x3c400000
1631 || (op & 0xffff0000) == 0x38420000)
1632 {
1633 /* . 0: addis 2,12,.TOC.-0b@ha
1634 . addi 2,2,.TOC.-0b@l
1635 or
1636 . lis 2,.TOC.@ha
1637 . addi 2,2,.TOC.@l
1638 used by ELFv2 global entry points to set up r2. */
1639 continue;
1640 }
1641 else if (op == 0x60000000)
ddb20c56 1642 {
96ff0de4 1643 /* nop */
ddb20c56
KB
1644 /* Allow nops in the prologue, but do not consider them to
1645 be part of the prologue unless followed by other prologue
0df8b418 1646 instructions. */
ddb20c56
KB
1647 prev_insn_was_prologue_insn = 0;
1648 continue;
1649
c906108c 1650 }
c5aa993b 1651 else if ((op & 0xffff0000) == 0x3c000000)
ef1bc9e7 1652 { /* addis 0,0,NUM, used for >= 32k frames */
c5aa993b
JM
1653 fdata->offset = (op & 0x0000ffff) << 16;
1654 fdata->frameless = 0;
773df3e5 1655 r0_contains_arg = 0;
c5aa993b
JM
1656 continue;
1657
1658 }
1659 else if ((op & 0xffff0000) == 0x60000000)
ef1bc9e7 1660 { /* ori 0,0,NUM, 2nd half of >= 32k frames */
c5aa993b
JM
1661 fdata->offset |= (op & 0x0000ffff);
1662 fdata->frameless = 0;
773df3e5 1663 r0_contains_arg = 0;
c5aa993b
JM
1664 continue;
1665
1666 }
be723e22 1667 else if (lr_reg >= 0 &&
98f08d3d
KB
1668 /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */
1669 (((op & 0xffff0000) == (lr_reg | 0xf8010000)) ||
1670 /* stw Rx, NUM(r1) */
1671 ((op & 0xffff0000) == (lr_reg | 0x90010000)) ||
1672 /* stwu Rx, NUM(r1) */
1673 ((op & 0xffff0000) == (lr_reg | 0x94010000))))
1674 { /* where Rx == lr */
1675 fdata->lr_offset = offset;
c5aa993b 1676 fdata->nosavedpc = 0;
be723e22
MS
1677 /* Invalidate lr_reg, but don't set it to -1.
1678 That would mean that it had never been set. */
1679 lr_reg = -2;
98f08d3d
KB
1680 if ((op & 0xfc000003) == 0xf8000000 || /* std */
1681 (op & 0xfc000000) == 0x90000000) /* stw */
1682 {
1683 /* Does not update r1, so add displacement to lr_offset. */
1684 fdata->lr_offset += SIGNED_SHORT (op);
1685 }
c5aa993b
JM
1686 continue;
1687
1688 }
be723e22 1689 else if (cr_reg >= 0 &&
98f08d3d
KB
1690 /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */
1691 (((op & 0xffff0000) == (cr_reg | 0xf8010000)) ||
1692 /* stw Rx, NUM(r1) */
1693 ((op & 0xffff0000) == (cr_reg | 0x90010000)) ||
1694 /* stwu Rx, NUM(r1) */
1695 ((op & 0xffff0000) == (cr_reg | 0x94010000))))
1696 { /* where Rx == cr */
1697 fdata->cr_offset = offset;
be723e22
MS
1698 /* Invalidate cr_reg, but don't set it to -1.
1699 That would mean that it had never been set. */
1700 cr_reg = -2;
98f08d3d
KB
1701 if ((op & 0xfc000003) == 0xf8000000 ||
1702 (op & 0xfc000000) == 0x90000000)
1703 {
1704 /* Does not update r1, so add displacement to cr_offset. */
1705 fdata->cr_offset += SIGNED_SHORT (op);
1706 }
c5aa993b
JM
1707 continue;
1708
1709 }
721d14ba
DJ
1710 else if ((op & 0xfe80ffff) == 0x42800005 && lr_reg != -1)
1711 {
1712 /* bcl 20,xx,.+4 is used to get the current PC, with or without
1713 prediction bits. If the LR has already been saved, we can
1714 skip it. */
1715 continue;
1716 }
c5aa993b
JM
1717 else if (op == 0x48000005)
1718 { /* bl .+4 used in
1719 -mrelocatable */
46a9b8ed 1720 fdata->used_bl = 1;
c5aa993b
JM
1721 continue;
1722
1723 }
1724 else if (op == 0x48000004)
1725 { /* b .+4 (xlc) */
1726 break;
1727
c5aa993b 1728 }
6be8bc0c
EZ
1729 else if ((op & 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used
1730 in V.4 -mminimal-toc */
c5aa993b
JM
1731 (op & 0xffff0000) == 0x3bde0000)
1732 { /* addi 30,30,foo@l */
1733 continue;
c906108c 1734
c5aa993b
JM
1735 }
1736 else if ((op & 0xfc000001) == 0x48000001)
1737 { /* bl foo,
0df8b418 1738 to save fprs??? */
c906108c 1739
c5aa993b 1740 fdata->frameless = 0;
3c77c82a
DJ
1741
1742 /* If the return address has already been saved, we can skip
1743 calls to blrl (for PIC). */
e17a4113 1744 if (lr_reg != -1 && bl_to_blrl_insn_p (pc, op, byte_order))
46a9b8ed
DJ
1745 {
1746 fdata->used_bl = 1;
1747 continue;
1748 }
3c77c82a 1749
6be8bc0c 1750 /* Don't skip over the subroutine call if it is not within
ebd98106
FF
1751 the first three instructions of the prologue and either
1752 we have no line table information or the line info tells
1753 us that the subroutine call is not part of the line
1754 associated with the prologue. */
c5aa993b 1755 if ((pc - orig_pc) > 8)
ebd98106
FF
1756 {
1757 struct symtab_and_line prologue_sal = find_pc_line (orig_pc, 0);
1758 struct symtab_and_line this_sal = find_pc_line (pc, 0);
1759
0df8b418
MS
1760 if ((prologue_sal.line == 0)
1761 || (prologue_sal.line != this_sal.line))
ebd98106
FF
1762 break;
1763 }
c5aa993b 1764
e17a4113 1765 op = read_memory_integer (pc + 4, 4, byte_order);
c5aa993b 1766
6be8bc0c
EZ
1767 /* At this point, make sure this is not a trampoline
1768 function (a function that simply calls another functions,
1769 and nothing else). If the next is not a nop, this branch
0df8b418 1770 was part of the function prologue. */
c5aa993b
JM
1771
1772 if (op == 0x4def7b82 || op == 0) /* crorc 15, 15, 15 */
0df8b418
MS
1773 break; /* Don't skip over
1774 this branch. */
c5aa993b 1775
46a9b8ed
DJ
1776 fdata->used_bl = 1;
1777 continue;
c5aa993b 1778 }
98f08d3d
KB
1779 /* update stack pointer */
1780 else if ((op & 0xfc1f0000) == 0x94010000)
1781 { /* stu rX,NUM(r1) || stwu rX,NUM(r1) */
c5aa993b
JM
1782 fdata->frameless = 0;
1783 fdata->offset = SIGNED_SHORT (op);
1784 offset = fdata->offset;
1785 continue;
c5aa993b 1786 }
98f08d3d
KB
1787 else if ((op & 0xfc1f016a) == 0x7c01016e)
1788 { /* stwux rX,r1,rY */
0df8b418 1789 /* No way to figure out what r1 is going to be. */
98f08d3d
KB
1790 fdata->frameless = 0;
1791 offset = fdata->offset;
1792 continue;
1793 }
1794 else if ((op & 0xfc1f0003) == 0xf8010001)
1795 { /* stdu rX,NUM(r1) */
1796 fdata->frameless = 0;
1797 fdata->offset = SIGNED_SHORT (op & ~3UL);
1798 offset = fdata->offset;
1799 continue;
1800 }
1801 else if ((op & 0xfc1f016a) == 0x7c01016a)
1802 { /* stdux rX,r1,rY */
0df8b418 1803 /* No way to figure out what r1 is going to be. */
c5aa993b
JM
1804 fdata->frameless = 0;
1805 offset = fdata->offset;
1806 continue;
c5aa993b 1807 }
7313566f
FF
1808 else if ((op & 0xffff0000) == 0x38210000)
1809 { /* addi r1,r1,SIMM */
1810 fdata->frameless = 0;
1811 fdata->offset += SIGNED_SHORT (op);
1812 offset = fdata->offset;
1813 continue;
1814 }
4e463ff5
DJ
1815 /* Load up minimal toc pointer. Do not treat an epilogue restore
1816 of r31 as a minimal TOC load. */
0df8b418
MS
1817 else if (((op >> 22) == 0x20f || /* l r31,... or l r30,... */
1818 (op >> 22) == 0x3af) /* ld r31,... or ld r30,... */
4e463ff5 1819 && !framep
c5aa993b 1820 && !minimal_toc_loaded)
98f08d3d 1821 {
c5aa993b
JM
1822 minimal_toc_loaded = 1;
1823 continue;
1824
f6077098
KB
1825 /* move parameters from argument registers to local variable
1826 registers */
1827 }
1828 else if ((op & 0xfc0007fe) == 0x7c000378 && /* mr(.) Rx,Ry */
1829 (((op >> 21) & 31) >= 3) && /* R3 >= Ry >= R10 */
1830 (((op >> 21) & 31) <= 10) &&
0df8b418
MS
1831 ((long) ((op >> 16) & 31)
1832 >= fdata->saved_gpr)) /* Rx: local var reg */
f6077098
KB
1833 {
1834 continue;
1835
c5aa993b
JM
1836 /* store parameters in stack */
1837 }
e802b915 1838 /* Move parameters from argument registers to temporary register. */
773df3e5 1839 else if (store_param_on_stack_p (op, framep, &r0_contains_arg))
e802b915 1840 {
c5aa993b
JM
1841 continue;
1842
1843 /* Set up frame pointer */
1844 }
76219d77
JB
1845 else if (op == 0x603d0000) /* oril r29, r1, 0x0 */
1846 {
1847 fdata->frameless = 0;
1848 framep = 1;
1849 fdata->alloca_reg = (tdep->ppc_gp0_regnum + 29);
1850 continue;
1851
1852 /* Another way to set up the frame pointer. */
1853 }
c5aa993b
JM
1854 else if (op == 0x603f0000 /* oril r31, r1, 0x0 */
1855 || op == 0x7c3f0b78)
1856 { /* mr r31, r1 */
1857 fdata->frameless = 0;
1858 framep = 1;
6f99cb26 1859 fdata->alloca_reg = (tdep->ppc_gp0_regnum + 31);
c5aa993b
JM
1860 continue;
1861
1862 /* Another way to set up the frame pointer. */
1863 }
1864 else if ((op & 0xfc1fffff) == 0x38010000)
1865 { /* addi rX, r1, 0x0 */
1866 fdata->frameless = 0;
1867 framep = 1;
6f99cb26
AC
1868 fdata->alloca_reg = (tdep->ppc_gp0_regnum
1869 + ((op & ~0x38010000) >> 21));
c5aa993b 1870 continue;
c5aa993b 1871 }
6be8bc0c
EZ
1872 /* AltiVec related instructions. */
1873 /* Store the vrsave register (spr 256) in another register for
1874 later manipulation, or load a register into the vrsave
1875 register. 2 instructions are used: mfvrsave and
1876 mtvrsave. They are shorthand notation for mfspr Rn, SPR256
1877 and mtspr SPR256, Rn. */
1878 /* mfspr Rn SPR256 == 011111 nnnnn 0000001000 01010100110
1879 mtspr SPR256 Rn == 011111 nnnnn 0000001000 01110100110 */
1880 else if ((op & 0xfc1fffff) == 0x7c0042a6) /* mfvrsave Rn */
1881 {
1882 vrsave_reg = GET_SRC_REG (op);
1883 continue;
1884 }
1885 else if ((op & 0xfc1fffff) == 0x7c0043a6) /* mtvrsave Rn */
1886 {
1887 continue;
1888 }
1889 /* Store the register where vrsave was saved to onto the stack:
1890 rS is the register where vrsave was stored in a previous
1891 instruction. */
1892 /* 100100 sssss 00001 dddddddd dddddddd */
1893 else if ((op & 0xfc1f0000) == 0x90010000) /* stw rS, d(r1) */
1894 {
1895 if (vrsave_reg == GET_SRC_REG (op))
1896 {
1897 fdata->vrsave_offset = SIGNED_SHORT (op) + offset;
1898 vrsave_reg = -1;
1899 }
1900 continue;
1901 }
1902 /* Compute the new value of vrsave, by modifying the register
1903 where vrsave was saved to. */
1904 else if (((op & 0xfc000000) == 0x64000000) /* oris Ra, Rs, UIMM */
1905 || ((op & 0xfc000000) == 0x60000000))/* ori Ra, Rs, UIMM */
1906 {
1907 continue;
1908 }
1909 /* li r0, SIMM (short for addi r0, 0, SIMM). This is the first
1910 in a pair of insns to save the vector registers on the
1911 stack. */
1912 /* 001110 00000 00000 iiii iiii iiii iiii */
96ff0de4
EZ
1913 /* 001110 01110 00000 iiii iiii iiii iiii */
1914 else if ((op & 0xffff0000) == 0x38000000 /* li r0, SIMM */
1915 || (op & 0xffff0000) == 0x39c00000) /* li r14, SIMM */
6be8bc0c 1916 {
773df3e5
JB
1917 if ((op & 0xffff0000) == 0x38000000)
1918 r0_contains_arg = 0;
6be8bc0c
EZ
1919 li_found_pc = pc;
1920 vr_saved_offset = SIGNED_SHORT (op);
773df3e5
JB
1921
1922 /* This insn by itself is not part of the prologue, unless
0df8b418 1923 if part of the pair of insns mentioned above. So do not
773df3e5
JB
1924 record this insn as part of the prologue yet. */
1925 prev_insn_was_prologue_insn = 0;
6be8bc0c
EZ
1926 }
1927 /* Store vector register S at (r31+r0) aligned to 16 bytes. */
1928 /* 011111 sssss 11111 00000 00111001110 */
1929 else if ((op & 0xfc1fffff) == 0x7c1f01ce) /* stvx Vs, R31, R0 */
1930 {
1931 if (pc == (li_found_pc + 4))
1932 {
1933 vr_reg = GET_SRC_REG (op);
1934 /* If this is the first vector reg to be saved, or if
1935 it has a lower number than others previously seen,
1936 reupdate the frame info. */
1937 if (fdata->saved_vr == -1 || fdata->saved_vr > vr_reg)
1938 {
1939 fdata->saved_vr = vr_reg;
1940 fdata->vr_offset = vr_saved_offset + offset;
1941 }
1942 vr_saved_offset = -1;
1943 vr_reg = -1;
1944 li_found_pc = 0;
1945 }
1946 }
1947 /* End AltiVec related instructions. */
96ff0de4
EZ
1948
1949 /* Start BookE related instructions. */
1950 /* Store gen register S at (r31+uimm).
1951 Any register less than r13 is volatile, so we don't care. */
1952 /* 000100 sssss 11111 iiiii 01100100001 */
1953 else if (arch_info->mach == bfd_mach_ppc_e500
1954 && (op & 0xfc1f07ff) == 0x101f0321) /* evstdd Rs,uimm(R31) */
1955 {
1956 if ((op & 0x03e00000) >= 0x01a00000) /* Rs >= r13 */
1957 {
1958 unsigned int imm;
1959 ev_reg = GET_SRC_REG (op);
1960 imm = (op >> 11) & 0x1f;
1961 ev_offset = imm * 8;
1962 /* If this is the first vector reg to be saved, or if
1963 it has a lower number than others previously seen,
1964 reupdate the frame info. */
1965 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
1966 {
1967 fdata->saved_ev = ev_reg;
1968 fdata->ev_offset = ev_offset + offset;
1969 }
1970 }
1971 continue;
1972 }
1973 /* Store gen register rS at (r1+rB). */
1974 /* 000100 sssss 00001 bbbbb 01100100000 */
1975 else if (arch_info->mach == bfd_mach_ppc_e500
1976 && (op & 0xffe007ff) == 0x13e00320) /* evstddx RS,R1,Rb */
1977 {
1978 if (pc == (li_found_pc + 4))
1979 {
1980 ev_reg = GET_SRC_REG (op);
1981 /* If this is the first vector reg to be saved, or if
1982 it has a lower number than others previously seen,
1983 reupdate the frame info. */
1984 /* We know the contents of rB from the previous instruction. */
1985 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
1986 {
1987 fdata->saved_ev = ev_reg;
1988 fdata->ev_offset = vr_saved_offset + offset;
1989 }
1990 vr_saved_offset = -1;
1991 ev_reg = -1;
1992 li_found_pc = 0;
1993 }
1994 continue;
1995 }
1996 /* Store gen register r31 at (rA+uimm). */
1997 /* 000100 11111 aaaaa iiiii 01100100001 */
1998 else if (arch_info->mach == bfd_mach_ppc_e500
1999 && (op & 0xffe007ff) == 0x13e00321) /* evstdd R31,Ra,UIMM */
2000 {
2001 /* Wwe know that the source register is 31 already, but
2002 it can't hurt to compute it. */
2003 ev_reg = GET_SRC_REG (op);
2004 ev_offset = ((op >> 11) & 0x1f) * 8;
2005 /* If this is the first vector reg to be saved, or if
2006 it has a lower number than others previously seen,
2007 reupdate the frame info. */
2008 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
2009 {
2010 fdata->saved_ev = ev_reg;
2011 fdata->ev_offset = ev_offset + offset;
2012 }
2013
2014 continue;
2015 }
2016 /* Store gen register S at (r31+r0).
2017 Store param on stack when offset from SP bigger than 4 bytes. */
2018 /* 000100 sssss 11111 00000 01100100000 */
2019 else if (arch_info->mach == bfd_mach_ppc_e500
2020 && (op & 0xfc1fffff) == 0x101f0320) /* evstddx Rs,R31,R0 */
2021 {
2022 if (pc == (li_found_pc + 4))
2023 {
2024 if ((op & 0x03e00000) >= 0x01a00000)
2025 {
2026 ev_reg = GET_SRC_REG (op);
2027 /* If this is the first vector reg to be saved, or if
2028 it has a lower number than others previously seen,
2029 reupdate the frame info. */
2030 /* We know the contents of r0 from the previous
2031 instruction. */
2032 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
2033 {
2034 fdata->saved_ev = ev_reg;
2035 fdata->ev_offset = vr_saved_offset + offset;
2036 }
2037 ev_reg = -1;
2038 }
2039 vr_saved_offset = -1;
2040 li_found_pc = 0;
2041 continue;
2042 }
2043 }
2044 /* End BookE related instructions. */
2045
c5aa993b
JM
2046 else
2047 {
46a9b8ed
DJ
2048 unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);
2049
55d05f3b
KB
2050 /* Not a recognized prologue instruction.
2051 Handle optimizer code motions into the prologue by continuing
2052 the search if we have no valid frame yet or if the return
46a9b8ed
DJ
2053 address is not yet saved in the frame. Also skip instructions
2054 if some of the GPRs expected to be saved are not yet saved. */
2055 if (fdata->frameless == 0 && fdata->nosavedpc == 0
2056 && (fdata->gpr_mask & all_mask) == all_mask)
55d05f3b
KB
2057 break;
2058
2059 if (op == 0x4e800020 /* blr */
2060 || op == 0x4e800420) /* bctr */
2061 /* Do not scan past epilogue in frameless functions or
2062 trampolines. */
2063 break;
2064 if ((op & 0xf4000000) == 0x40000000) /* bxx */
64366f1c 2065 /* Never skip branches. */
55d05f3b
KB
2066 break;
2067
2068 if (num_skip_non_prologue_insns++ > max_skip_non_prologue_insns)
2069 /* Do not scan too many insns, scanning insns is expensive with
2070 remote targets. */
2071 break;
2072
2073 /* Continue scanning. */
2074 prev_insn_was_prologue_insn = 0;
2075 continue;
c5aa993b 2076 }
c906108c
SS
2077 }
2078
2079#if 0
2080/* I have problems with skipping over __main() that I need to address
0df8b418 2081 * sometime. Previously, I used to use misc_function_vector which
c906108c
SS
2082 * didn't work as well as I wanted to be. -MGO */
2083
2084 /* If the first thing after skipping a prolog is a branch to a function,
2085 this might be a call to an initializer in main(), introduced by gcc2.
64366f1c 2086 We'd like to skip over it as well. Fortunately, xlc does some extra
c906108c 2087 work before calling a function right after a prologue, thus we can
64366f1c 2088 single out such gcc2 behaviour. */
c906108c 2089
c906108c 2090
c5aa993b 2091 if ((op & 0xfc000001) == 0x48000001)
0df8b418 2092 { /* bl foo, an initializer function? */
e17a4113 2093 op = read_memory_integer (pc + 4, 4, byte_order);
c5aa993b
JM
2094
2095 if (op == 0x4def7b82)
2096 { /* cror 0xf, 0xf, 0xf (nop) */
c906108c 2097
64366f1c
EZ
2098 /* Check and see if we are in main. If so, skip over this
2099 initializer function as well. */
c906108c 2100
c5aa993b 2101 tmp = find_pc_misc_function (pc);
6314a349
AC
2102 if (tmp >= 0
2103 && strcmp (misc_function_vector[tmp].name, main_name ()) == 0)
c5aa993b
JM
2104 return pc + 8;
2105 }
c906108c 2106 }
c906108c 2107#endif /* 0 */
c5aa993b 2108
46a9b8ed
DJ
2109 if (pc == lim_pc && lr_reg >= 0)
2110 fdata->lr_register = lr_reg;
2111
c5aa993b 2112 fdata->offset = -fdata->offset;
ddb20c56 2113 return last_prologue_pc;
c906108c
SS
2114}
2115
7a78ae4e 2116static CORE_ADDR
4a7622d1 2117rs6000_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
c906108c 2118{
4a7622d1 2119 struct rs6000_framedata frame;
e3acb115 2120 CORE_ADDR limit_pc, func_addr, func_end_addr = 0;
c906108c 2121
4a7622d1
UW
2122 /* See if we can determine the end of the prologue via the symbol table.
2123 If so, then return either PC, or the PC after the prologue, whichever
2124 is greater. */
e3acb115 2125 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr))
c5aa993b 2126 {
d80b854b
UW
2127 CORE_ADDR post_prologue_pc
2128 = skip_prologue_using_sal (gdbarch, func_addr);
4a7622d1
UW
2129 if (post_prologue_pc != 0)
2130 return max (pc, post_prologue_pc);
c906108c 2131 }
c906108c 2132
4a7622d1
UW
2133 /* Can't determine prologue from the symbol table, need to examine
2134 instructions. */
c906108c 2135
4a7622d1
UW
2136 /* Find an upper limit on the function prologue using the debug
2137 information. If the debug information could not be used to provide
2138 that bound, then use an arbitrary large number as the upper bound. */
d80b854b 2139 limit_pc = skip_prologue_using_sal (gdbarch, pc);
4a7622d1
UW
2140 if (limit_pc == 0)
2141 limit_pc = pc + 100; /* Magic. */
794a477a 2142
e3acb115
JB
2143 /* Do not allow limit_pc to be past the function end, if we know
2144 where that end is... */
2145 if (func_end_addr && limit_pc > func_end_addr)
2146 limit_pc = func_end_addr;
2147
4a7622d1
UW
2148 pc = skip_prologue (gdbarch, pc, limit_pc, &frame);
2149 return pc;
c906108c 2150}
c906108c 2151
8ab3d180
KB
2152/* When compiling for EABI, some versions of GCC emit a call to __eabi
2153 in the prologue of main().
2154
2155 The function below examines the code pointed at by PC and checks to
2156 see if it corresponds to a call to __eabi. If so, it returns the
2157 address of the instruction following that call. Otherwise, it simply
2158 returns PC. */
2159
63807e1d 2160static CORE_ADDR
8ab3d180
KB
2161rs6000_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
2162{
e17a4113 2163 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
8ab3d180
KB
2164 gdb_byte buf[4];
2165 unsigned long op;
2166
2167 if (target_read_memory (pc, buf, 4))
2168 return pc;
e17a4113 2169 op = extract_unsigned_integer (buf, 4, byte_order);
8ab3d180
KB
2170
2171 if ((op & BL_MASK) == BL_INSTRUCTION)
2172 {
2173 CORE_ADDR displ = op & BL_DISPLACEMENT_MASK;
2174 CORE_ADDR call_dest = pc + 4 + displ;
7cbd4a93 2175 struct bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest);
8ab3d180
KB
2176
2177 /* We check for ___eabi (three leading underscores) in addition
2178 to __eabi in case the GCC option "-fleading-underscore" was
2179 used to compile the program. */
7cbd4a93 2180 if (s.minsym != NULL
efd66ac6
TT
2181 && MSYMBOL_LINKAGE_NAME (s.minsym) != NULL
2182 && (strcmp (MSYMBOL_LINKAGE_NAME (s.minsym), "__eabi") == 0
2183 || strcmp (MSYMBOL_LINKAGE_NAME (s.minsym), "___eabi") == 0))
8ab3d180
KB
2184 pc += 4;
2185 }
2186 return pc;
2187}
383f0f5b 2188
4a7622d1
UW
2189/* All the ABI's require 16 byte alignment. */
2190static CORE_ADDR
2191rs6000_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2192{
2193 return (addr & -16);
c906108c
SS
2194}
2195
977adac5
ND
2196/* Return whether handle_inferior_event() should proceed through code
2197 starting at PC in function NAME when stepping.
2198
2199 The AIX -bbigtoc linker option generates functions @FIX0, @FIX1, etc. to
2200 handle memory references that are too distant to fit in instructions
2201 generated by the compiler. For example, if 'foo' in the following
2202 instruction:
2203
2204 lwz r9,foo(r2)
2205
2206 is greater than 32767, the linker might replace the lwz with a branch to
2207 somewhere in @FIX1 that does the load in 2 instructions and then branches
2208 back to where execution should continue.
2209
2210 GDB should silently step over @FIX code, just like AIX dbx does.
2ec664f5
MS
2211 Unfortunately, the linker uses the "b" instruction for the
2212 branches, meaning that the link register doesn't get set.
2213 Therefore, GDB's usual step_over_function () mechanism won't work.
977adac5 2214
e76f05fa
UW
2215 Instead, use the gdbarch_skip_trampoline_code and
2216 gdbarch_skip_trampoline_code hooks in handle_inferior_event() to skip past
2ec664f5 2217 @FIX code. */
977adac5 2218
63807e1d 2219static int
e17a4113 2220rs6000_in_solib_return_trampoline (struct gdbarch *gdbarch,
2c02bd72 2221 CORE_ADDR pc, const char *name)
977adac5 2222{
61012eef 2223 return name && startswith (name, "@FIX");
977adac5
ND
2224}
2225
2226/* Skip code that the user doesn't want to see when stepping:
2227
2228 1. Indirect function calls use a piece of trampoline code to do context
2229 switching, i.e. to set the new TOC table. Skip such code if we are on
2230 its first instruction (as when we have single-stepped to here).
2231
2232 2. Skip shared library trampoline code (which is different from
c906108c 2233 indirect function call trampolines).
977adac5
ND
2234
2235 3. Skip bigtoc fixup code.
2236
c906108c 2237 Result is desired PC to step until, or NULL if we are not in
977adac5 2238 code that should be skipped. */
c906108c 2239
63807e1d 2240static CORE_ADDR
52f729a7 2241rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
c906108c 2242{
e17a4113
UW
2243 struct gdbarch *gdbarch = get_frame_arch (frame);
2244 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2245 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
52f0bd74 2246 unsigned int ii, op;
977adac5 2247 int rel;
c906108c 2248 CORE_ADDR solib_target_pc;
7cbd4a93 2249 struct bound_minimal_symbol msymbol;
c906108c 2250
c5aa993b
JM
2251 static unsigned trampoline_code[] =
2252 {
2253 0x800b0000, /* l r0,0x0(r11) */
2254 0x90410014, /* st r2,0x14(r1) */
2255 0x7c0903a6, /* mtctr r0 */
2256 0x804b0004, /* l r2,0x4(r11) */
2257 0x816b0008, /* l r11,0x8(r11) */
2258 0x4e800420, /* bctr */
2259 0x4e800020, /* br */
2260 0
c906108c
SS
2261 };
2262
977adac5
ND
2263 /* Check for bigtoc fixup code. */
2264 msymbol = lookup_minimal_symbol_by_pc (pc);
7cbd4a93 2265 if (msymbol.minsym
e17a4113 2266 && rs6000_in_solib_return_trampoline (gdbarch, pc,
efd66ac6 2267 MSYMBOL_LINKAGE_NAME (msymbol.minsym)))
977adac5
ND
2268 {
2269 /* Double-check that the third instruction from PC is relative "b". */
e17a4113 2270 op = read_memory_integer (pc + 8, 4, byte_order);
977adac5
ND
2271 if ((op & 0xfc000003) == 0x48000000)
2272 {
2273 /* Extract bits 6-29 as a signed 24-bit relative word address and
2274 add it to the containing PC. */
2275 rel = ((int)(op << 6) >> 6);
2276 return pc + 8 + rel;
2277 }
2278 }
2279
c906108c 2280 /* If pc is in a shared library trampoline, return its target. */
52f729a7 2281 solib_target_pc = find_solib_trampoline_target (frame, pc);
c906108c
SS
2282 if (solib_target_pc)
2283 return solib_target_pc;
2284
c5aa993b
JM
2285 for (ii = 0; trampoline_code[ii]; ++ii)
2286 {
e17a4113 2287 op = read_memory_integer (pc + (ii * 4), 4, byte_order);
c5aa993b
JM
2288 if (op != trampoline_code[ii])
2289 return 0;
2290 }
0df8b418
MS
2291 ii = get_frame_register_unsigned (frame, 11); /* r11 holds destination
2292 addr. */
e17a4113 2293 pc = read_memory_unsigned_integer (ii, tdep->wordsize, byte_order);
c906108c
SS
2294 return pc;
2295}
2296
794ac428
UW
2297/* ISA-specific vector types. */
2298
2299static struct type *
2300rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
2301{
2302 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2303
2304 if (!tdep->ppc_builtin_type_vec64)
2305 {
df4df182
UW
2306 const struct builtin_type *bt = builtin_type (gdbarch);
2307
794ac428
UW
2308 /* The type we're building is this: */
2309#if 0
2310 union __gdb_builtin_type_vec64
2311 {
2312 int64_t uint64;
2313 float v2_float[2];
2314 int32_t v2_int32[2];
2315 int16_t v4_int16[4];
2316 int8_t v8_int8[8];
2317 };
2318#endif
2319
2320 struct type *t;
2321
e9bb382b
UW
2322 t = arch_composite_type (gdbarch,
2323 "__ppc_builtin_type_vec64", TYPE_CODE_UNION);
df4df182 2324 append_composite_type_field (t, "uint64", bt->builtin_int64);
794ac428 2325 append_composite_type_field (t, "v2_float",
df4df182 2326 init_vector_type (bt->builtin_float, 2));
794ac428 2327 append_composite_type_field (t, "v2_int32",
df4df182 2328 init_vector_type (bt->builtin_int32, 2));
794ac428 2329 append_composite_type_field (t, "v4_int16",
df4df182 2330 init_vector_type (bt->builtin_int16, 4));
794ac428 2331 append_composite_type_field (t, "v8_int8",
df4df182 2332 init_vector_type (bt->builtin_int8, 8));
794ac428 2333
876cecd0 2334 TYPE_VECTOR (t) = 1;
794ac428
UW
2335 TYPE_NAME (t) = "ppc_builtin_type_vec64";
2336 tdep->ppc_builtin_type_vec64 = t;
2337 }
2338
2339 return tdep->ppc_builtin_type_vec64;
2340}
2341
604c2f83
LM
2342/* Vector 128 type. */
2343
2344static struct type *
2345rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
2346{
2347 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2348
2349 if (!tdep->ppc_builtin_type_vec128)
2350 {
df4df182
UW
2351 const struct builtin_type *bt = builtin_type (gdbarch);
2352
604c2f83
LM
2353 /* The type we're building is this
2354
2355 type = union __ppc_builtin_type_vec128 {
2356 uint128_t uint128;
db9f5df8 2357 double v2_double[2];
604c2f83
LM
2358 float v4_float[4];
2359 int32_t v4_int32[4];
2360 int16_t v8_int16[8];
2361 int8_t v16_int8[16];
2362 }
2363 */
2364
2365 struct type *t;
2366
e9bb382b
UW
2367 t = arch_composite_type (gdbarch,
2368 "__ppc_builtin_type_vec128", TYPE_CODE_UNION);
df4df182 2369 append_composite_type_field (t, "uint128", bt->builtin_uint128);
db9f5df8
UW
2370 append_composite_type_field (t, "v2_double",
2371 init_vector_type (bt->builtin_double, 2));
604c2f83 2372 append_composite_type_field (t, "v4_float",
df4df182 2373 init_vector_type (bt->builtin_float, 4));
604c2f83 2374 append_composite_type_field (t, "v4_int32",
df4df182 2375 init_vector_type (bt->builtin_int32, 4));
604c2f83 2376 append_composite_type_field (t, "v8_int16",
df4df182 2377 init_vector_type (bt->builtin_int16, 8));
604c2f83 2378 append_composite_type_field (t, "v16_int8",
df4df182 2379 init_vector_type (bt->builtin_int8, 16));
604c2f83 2380
803e1097 2381 TYPE_VECTOR (t) = 1;
604c2f83
LM
2382 TYPE_NAME (t) = "ppc_builtin_type_vec128";
2383 tdep->ppc_builtin_type_vec128 = t;
2384 }
2385
2386 return tdep->ppc_builtin_type_vec128;
2387}
2388
7cc46491
DJ
2389/* Return the name of register number REGNO, or the empty string if it
2390 is an anonymous register. */
7a78ae4e 2391
fa88f677 2392static const char *
d93859e2 2393rs6000_register_name (struct gdbarch *gdbarch, int regno)
7a78ae4e 2394{
d93859e2 2395 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7a78ae4e 2396
7cc46491
DJ
2397 /* The upper half "registers" have names in the XML description,
2398 but we present only the low GPRs and the full 64-bit registers
2399 to the user. */
2400 if (tdep->ppc_ev0_upper_regnum >= 0
2401 && tdep->ppc_ev0_upper_regnum <= regno
2402 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
2403 return "";
2404
604c2f83
LM
2405 /* Hide the upper halves of the vs0~vs31 registers. */
2406 if (tdep->ppc_vsr0_regnum >= 0
2407 && tdep->ppc_vsr0_upper_regnum <= regno
2408 && regno < tdep->ppc_vsr0_upper_regnum + ppc_num_gprs)
2409 return "";
2410
7cc46491 2411 /* Check if the SPE pseudo registers are available. */
5a9e69ba 2412 if (IS_SPE_PSEUDOREG (tdep, regno))
7cc46491
DJ
2413 {
2414 static const char *const spe_regnames[] = {
2415 "ev0", "ev1", "ev2", "ev3", "ev4", "ev5", "ev6", "ev7",
2416 "ev8", "ev9", "ev10", "ev11", "ev12", "ev13", "ev14", "ev15",
2417 "ev16", "ev17", "ev18", "ev19", "ev20", "ev21", "ev22", "ev23",
2418 "ev24", "ev25", "ev26", "ev27", "ev28", "ev29", "ev30", "ev31",
2419 };
2420 return spe_regnames[regno - tdep->ppc_ev0_regnum];
2421 }
2422
f949c649
TJB
2423 /* Check if the decimal128 pseudo-registers are available. */
2424 if (IS_DFP_PSEUDOREG (tdep, regno))
2425 {
2426 static const char *const dfp128_regnames[] = {
2427 "dl0", "dl1", "dl2", "dl3",
2428 "dl4", "dl5", "dl6", "dl7",
2429 "dl8", "dl9", "dl10", "dl11",
2430 "dl12", "dl13", "dl14", "dl15"
2431 };
2432 return dfp128_regnames[regno - tdep->ppc_dl0_regnum];
2433 }
2434
604c2f83
LM
2435 /* Check if this is a VSX pseudo-register. */
2436 if (IS_VSX_PSEUDOREG (tdep, regno))
2437 {
2438 static const char *const vsx_regnames[] = {
2439 "vs0", "vs1", "vs2", "vs3", "vs4", "vs5", "vs6", "vs7",
2440 "vs8", "vs9", "vs10", "vs11", "vs12", "vs13", "vs14",
2441 "vs15", "vs16", "vs17", "vs18", "vs19", "vs20", "vs21",
2442 "vs22", "vs23", "vs24", "vs25", "vs26", "vs27", "vs28",
2443 "vs29", "vs30", "vs31", "vs32", "vs33", "vs34", "vs35",
2444 "vs36", "vs37", "vs38", "vs39", "vs40", "vs41", "vs42",
2445 "vs43", "vs44", "vs45", "vs46", "vs47", "vs48", "vs49",
2446 "vs50", "vs51", "vs52", "vs53", "vs54", "vs55", "vs56",
2447 "vs57", "vs58", "vs59", "vs60", "vs61", "vs62", "vs63"
2448 };
2449 return vsx_regnames[regno - tdep->ppc_vsr0_regnum];
2450 }
2451
2452 /* Check if the this is a Extended FP pseudo-register. */
2453 if (IS_EFP_PSEUDOREG (tdep, regno))
2454 {
2455 static const char *const efpr_regnames[] = {
2456 "f32", "f33", "f34", "f35", "f36", "f37", "f38",
2457 "f39", "f40", "f41", "f42", "f43", "f44", "f45",
2458 "f46", "f47", "f48", "f49", "f50", "f51",
2459 "f52", "f53", "f54", "f55", "f56", "f57",
2460 "f58", "f59", "f60", "f61", "f62", "f63"
2461 };
2462 return efpr_regnames[regno - tdep->ppc_efpr0_regnum];
2463 }
2464
d93859e2 2465 return tdesc_register_name (gdbarch, regno);
7a78ae4e
ND
2466}
2467
7cc46491
DJ
2468/* Return the GDB type object for the "standard" data type of data in
2469 register N. */
7a78ae4e
ND
2470
2471static struct type *
7cc46491 2472rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
7a78ae4e 2473{
691d145a 2474 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7a78ae4e 2475
7cc46491 2476 /* These are the only pseudo-registers we support. */
f949c649 2477 gdb_assert (IS_SPE_PSEUDOREG (tdep, regnum)
604c2f83
LM
2478 || IS_DFP_PSEUDOREG (tdep, regnum)
2479 || IS_VSX_PSEUDOREG (tdep, regnum)
2480 || IS_EFP_PSEUDOREG (tdep, regnum));
7cc46491 2481
f949c649
TJB
2482 /* These are the e500 pseudo-registers. */
2483 if (IS_SPE_PSEUDOREG (tdep, regnum))
2484 return rs6000_builtin_type_vec64 (gdbarch);
604c2f83
LM
2485 else if (IS_DFP_PSEUDOREG (tdep, regnum))
2486 /* PPC decimal128 pseudo-registers. */
f949c649 2487 return builtin_type (gdbarch)->builtin_declong;
604c2f83
LM
2488 else if (IS_VSX_PSEUDOREG (tdep, regnum))
2489 /* POWER7 VSX pseudo-registers. */
2490 return rs6000_builtin_type_vec128 (gdbarch);
2491 else
2492 /* POWER7 Extended FP pseudo-registers. */
2493 return builtin_type (gdbarch)->builtin_double;
7a78ae4e
ND
2494}
2495
c44ca51c
AC
2496/* Is REGNUM a member of REGGROUP? */
2497static int
7cc46491
DJ
2498rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
2499 struct reggroup *group)
c44ca51c
AC
2500{
2501 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
c44ca51c 2502
7cc46491 2503 /* These are the only pseudo-registers we support. */
f949c649 2504 gdb_assert (IS_SPE_PSEUDOREG (tdep, regnum)
604c2f83
LM
2505 || IS_DFP_PSEUDOREG (tdep, regnum)
2506 || IS_VSX_PSEUDOREG (tdep, regnum)
2507 || IS_EFP_PSEUDOREG (tdep, regnum));
c44ca51c 2508
604c2f83
LM
2509 /* These are the e500 pseudo-registers or the POWER7 VSX registers. */
2510 if (IS_SPE_PSEUDOREG (tdep, regnum) || IS_VSX_PSEUDOREG (tdep, regnum))
f949c649 2511 return group == all_reggroup || group == vector_reggroup;
7cc46491 2512 else
604c2f83 2513 /* PPC decimal128 or Extended FP pseudo-registers. */
f949c649 2514 return group == all_reggroup || group == float_reggroup;
c44ca51c
AC
2515}
2516
691d145a 2517/* The register format for RS/6000 floating point registers is always
64366f1c 2518 double, we need a conversion if the memory format is float. */
7a78ae4e
ND
2519
2520static int
0abe36f5
MD
2521rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
2522 struct type *type)
7a78ae4e 2523{
0abe36f5 2524 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7cc46491
DJ
2525
2526 return (tdep->ppc_fp0_regnum >= 0
2527 && regnum >= tdep->ppc_fp0_regnum
2528 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs
2529 && TYPE_CODE (type) == TYPE_CODE_FLT
0dfff4cb
UW
2530 && TYPE_LENGTH (type)
2531 != TYPE_LENGTH (builtin_type (gdbarch)->builtin_double));
7a78ae4e
ND
2532}
2533
8dccd430 2534static int
691d145a
JB
2535rs6000_register_to_value (struct frame_info *frame,
2536 int regnum,
2537 struct type *type,
8dccd430
PA
2538 gdb_byte *to,
2539 int *optimizedp, int *unavailablep)
7a78ae4e 2540{
0dfff4cb 2541 struct gdbarch *gdbarch = get_frame_arch (frame);
50fd1280 2542 gdb_byte from[MAX_REGISTER_SIZE];
691d145a 2543
691d145a 2544 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
7a78ae4e 2545
8dccd430
PA
2546 if (!get_frame_register_bytes (frame, regnum, 0,
2547 register_size (gdbarch, regnum),
2548 from, optimizedp, unavailablep))
2549 return 0;
2550
0dfff4cb
UW
2551 convert_typed_floating (from, builtin_type (gdbarch)->builtin_double,
2552 to, type);
8dccd430
PA
2553 *optimizedp = *unavailablep = 0;
2554 return 1;
691d145a 2555}
7a292a7a 2556
7a78ae4e 2557static void
691d145a
JB
2558rs6000_value_to_register (struct frame_info *frame,
2559 int regnum,
2560 struct type *type,
50fd1280 2561 const gdb_byte *from)
7a78ae4e 2562{
0dfff4cb 2563 struct gdbarch *gdbarch = get_frame_arch (frame);
50fd1280 2564 gdb_byte to[MAX_REGISTER_SIZE];
691d145a 2565
691d145a
JB
2566 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
2567
0dfff4cb
UW
2568 convert_typed_floating (from, type,
2569 to, builtin_type (gdbarch)->builtin_double);
691d145a 2570 put_frame_register (frame, regnum, to);
7a78ae4e 2571}
c906108c 2572
05d1431c
PA
2573 /* The type of a function that moves the value of REG between CACHE
2574 or BUF --- in either direction. */
2575typedef enum register_status (*move_ev_register_func) (struct regcache *,
2576 int, void *);
2577
6ced10dd
JB
2578/* Move SPE vector register values between a 64-bit buffer and the two
2579 32-bit raw register halves in a regcache. This function handles
2580 both splitting a 64-bit value into two 32-bit halves, and joining
2581 two halves into a whole 64-bit value, depending on the function
2582 passed as the MOVE argument.
2583
2584 EV_REG must be the number of an SPE evN vector register --- a
2585 pseudoregister. REGCACHE must be a regcache, and BUFFER must be a
2586 64-bit buffer.
2587
2588 Call MOVE once for each 32-bit half of that register, passing
2589 REGCACHE, the number of the raw register corresponding to that
2590 half, and the address of the appropriate half of BUFFER.
2591
2592 For example, passing 'regcache_raw_read' as the MOVE function will
2593 fill BUFFER with the full 64-bit contents of EV_REG. Or, passing
2594 'regcache_raw_supply' will supply the contents of BUFFER to the
2595 appropriate pair of raw registers in REGCACHE.
2596
2597 You may need to cast away some 'const' qualifiers when passing
2598 MOVE, since this function can't tell at compile-time which of
2599 REGCACHE or BUFFER is acting as the source of the data. If C had
2600 co-variant type qualifiers, ... */
05d1431c
PA
2601
2602static enum register_status
2603e500_move_ev_register (move_ev_register_func move,
2604 struct regcache *regcache, int ev_reg, void *buffer)
6ced10dd
JB
2605{
2606 struct gdbarch *arch = get_regcache_arch (regcache);
2607 struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
2608 int reg_index;
50fd1280 2609 gdb_byte *byte_buffer = buffer;
05d1431c 2610 enum register_status status;
6ced10dd 2611
5a9e69ba 2612 gdb_assert (IS_SPE_PSEUDOREG (tdep, ev_reg));
6ced10dd
JB
2613
2614 reg_index = ev_reg - tdep->ppc_ev0_regnum;
2615
8b164abb 2616 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
6ced10dd 2617 {
05d1431c
PA
2618 status = move (regcache, tdep->ppc_ev0_upper_regnum + reg_index,
2619 byte_buffer);
2620 if (status == REG_VALID)
2621 status = move (regcache, tdep->ppc_gp0_regnum + reg_index,
2622 byte_buffer + 4);
6ced10dd
JB
2623 }
2624 else
2625 {
05d1431c
PA
2626 status = move (regcache, tdep->ppc_gp0_regnum + reg_index, byte_buffer);
2627 if (status == REG_VALID)
2628 status = move (regcache, tdep->ppc_ev0_upper_regnum + reg_index,
2629 byte_buffer + 4);
6ced10dd 2630 }
05d1431c
PA
2631
2632 return status;
6ced10dd
JB
2633}
2634
05d1431c
PA
2635static enum register_status
2636do_regcache_raw_read (struct regcache *regcache, int regnum, void *buffer)
2637{
2638 return regcache_raw_read (regcache, regnum, buffer);
2639}
2640
2641static enum register_status
2642do_regcache_raw_write (struct regcache *regcache, int regnum, void *buffer)
2643{
2644 regcache_raw_write (regcache, regnum, buffer);
2645
2646 return REG_VALID;
2647}
2648
2649static enum register_status
c8001721 2650e500_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
50fd1280 2651 int reg_nr, gdb_byte *buffer)
f949c649 2652{
05d1431c 2653 return e500_move_ev_register (do_regcache_raw_read, regcache, reg_nr, buffer);
f949c649
TJB
2654}
2655
2656static void
2657e500_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
2658 int reg_nr, const gdb_byte *buffer)
2659{
05d1431c
PA
2660 e500_move_ev_register (do_regcache_raw_write, regcache,
2661 reg_nr, (void *) buffer);
f949c649
TJB
2662}
2663
604c2f83 2664/* Read method for DFP pseudo-registers. */
05d1431c 2665static enum register_status
604c2f83 2666dfp_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
f949c649
TJB
2667 int reg_nr, gdb_byte *buffer)
2668{
2669 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2670 int reg_index = reg_nr - tdep->ppc_dl0_regnum;
05d1431c 2671 enum register_status status;
f949c649
TJB
2672
2673 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
2674 {
2675 /* Read two FP registers to form a whole dl register. */
05d1431c
PA
2676 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
2677 2 * reg_index, buffer);
2678 if (status == REG_VALID)
2679 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
2680 2 * reg_index + 1, buffer + 8);
f949c649
TJB
2681 }
2682 else
2683 {
05d1431c 2684 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
0ff3e01f 2685 2 * reg_index + 1, buffer);
05d1431c
PA
2686 if (status == REG_VALID)
2687 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
0ff3e01f 2688 2 * reg_index, buffer + 8);
f949c649 2689 }
05d1431c
PA
2690
2691 return status;
f949c649
TJB
2692}
2693
604c2f83 2694/* Write method for DFP pseudo-registers. */
f949c649 2695static void
604c2f83 2696dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
f949c649
TJB
2697 int reg_nr, const gdb_byte *buffer)
2698{
2699 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2700 int reg_index = reg_nr - tdep->ppc_dl0_regnum;
2701
2702 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
2703 {
2704 /* Write each half of the dl register into a separate
2705 FP register. */
2706 regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
2707 2 * reg_index, buffer);
2708 regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
2709 2 * reg_index + 1, buffer + 8);
2710 }
2711 else
2712 {
2713 regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
0ff3e01f 2714 2 * reg_index + 1, buffer);
f949c649 2715 regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
0ff3e01f 2716 2 * reg_index, buffer + 8);
f949c649
TJB
2717 }
2718}
2719
604c2f83 2720/* Read method for POWER7 VSX pseudo-registers. */
05d1431c 2721static enum register_status
604c2f83
LM
2722vsx_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
2723 int reg_nr, gdb_byte *buffer)
2724{
2725 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2726 int reg_index = reg_nr - tdep->ppc_vsr0_regnum;
05d1431c 2727 enum register_status status;
604c2f83
LM
2728
2729 /* Read the portion that overlaps the VMX registers. */
2730 if (reg_index > 31)
05d1431c
PA
2731 status = regcache_raw_read (regcache, tdep->ppc_vr0_regnum +
2732 reg_index - 32, buffer);
604c2f83
LM
2733 else
2734 /* Read the portion that overlaps the FPR registers. */
2735 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
2736 {
05d1431c
PA
2737 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
2738 reg_index, buffer);
2739 if (status == REG_VALID)
2740 status = regcache_raw_read (regcache, tdep->ppc_vsr0_upper_regnum +
2741 reg_index, buffer + 8);
604c2f83
LM
2742 }
2743 else
2744 {
05d1431c
PA
2745 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
2746 reg_index, buffer + 8);
2747 if (status == REG_VALID)
2748 status = regcache_raw_read (regcache, tdep->ppc_vsr0_upper_regnum +
2749 reg_index, buffer);
604c2f83 2750 }
05d1431c
PA
2751
2752 return status;
604c2f83
LM
2753}
2754
2755/* Write method for POWER7 VSX pseudo-registers. */
2756static void
2757vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
2758 int reg_nr, const gdb_byte *buffer)
2759{
2760 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2761 int reg_index = reg_nr - tdep->ppc_vsr0_regnum;
2762
2763 /* Write the portion that overlaps the VMX registers. */
2764 if (reg_index > 31)
2765 regcache_raw_write (regcache, tdep->ppc_vr0_regnum +
2766 reg_index - 32, buffer);
2767 else
2768 /* Write the portion that overlaps the FPR registers. */
2769 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
2770 {
2771 regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
2772 reg_index, buffer);
2773 regcache_raw_write (regcache, tdep->ppc_vsr0_upper_regnum +
2774 reg_index, buffer + 8);
2775 }
2776 else
2777 {
2778 regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
2779 reg_index, buffer + 8);
2780 regcache_raw_write (regcache, tdep->ppc_vsr0_upper_regnum +
2781 reg_index, buffer);
2782 }
2783}
2784
2785/* Read method for POWER7 Extended FP pseudo-registers. */
05d1431c 2786static enum register_status
604c2f83
LM
2787efpr_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
2788 int reg_nr, gdb_byte *buffer)
2789{
2790 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2791 int reg_index = reg_nr - tdep->ppc_efpr0_regnum;
084ee545 2792 int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
604c2f83 2793
d9492458 2794 /* Read the portion that overlaps the VMX register. */
084ee545
UW
2795 return regcache_raw_read_part (regcache, tdep->ppc_vr0_regnum + reg_index,
2796 offset, register_size (gdbarch, reg_nr),
2797 buffer);
604c2f83
LM
2798}
2799
2800/* Write method for POWER7 Extended FP pseudo-registers. */
2801static void
2802efpr_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
2803 int reg_nr, const gdb_byte *buffer)
2804{
2805 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2806 int reg_index = reg_nr - tdep->ppc_efpr0_regnum;
084ee545 2807 int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
604c2f83 2808
d9492458 2809 /* Write the portion that overlaps the VMX register. */
084ee545
UW
2810 regcache_raw_write_part (regcache, tdep->ppc_vr0_regnum + reg_index,
2811 offset, register_size (gdbarch, reg_nr),
2812 buffer);
604c2f83
LM
2813}
2814
05d1431c 2815static enum register_status
0df8b418
MS
2816rs6000_pseudo_register_read (struct gdbarch *gdbarch,
2817 struct regcache *regcache,
f949c649 2818 int reg_nr, gdb_byte *buffer)
c8001721 2819{
6ced10dd 2820 struct gdbarch *regcache_arch = get_regcache_arch (regcache);
c8001721
EZ
2821 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2822
6ced10dd 2823 gdb_assert (regcache_arch == gdbarch);
f949c649 2824
5a9e69ba 2825 if (IS_SPE_PSEUDOREG (tdep, reg_nr))
05d1431c 2826 return e500_pseudo_register_read (gdbarch, regcache, reg_nr, buffer);
f949c649 2827 else if (IS_DFP_PSEUDOREG (tdep, reg_nr))
05d1431c 2828 return dfp_pseudo_register_read (gdbarch, regcache, reg_nr, buffer);
604c2f83 2829 else if (IS_VSX_PSEUDOREG (tdep, reg_nr))
05d1431c 2830 return vsx_pseudo_register_read (gdbarch, regcache, reg_nr, buffer);
604c2f83 2831 else if (IS_EFP_PSEUDOREG (tdep, reg_nr))
05d1431c 2832 return efpr_pseudo_register_read (gdbarch, regcache, reg_nr, buffer);
6ced10dd 2833 else
a44bddec 2834 internal_error (__FILE__, __LINE__,
f949c649
TJB
2835 _("rs6000_pseudo_register_read: "
2836 "called on unexpected register '%s' (%d)"),
2837 gdbarch_register_name (gdbarch, reg_nr), reg_nr);
c8001721
EZ
2838}
2839
2840static void
f949c649
TJB
2841rs6000_pseudo_register_write (struct gdbarch *gdbarch,
2842 struct regcache *regcache,
2843 int reg_nr, const gdb_byte *buffer)
c8001721 2844{
6ced10dd 2845 struct gdbarch *regcache_arch = get_regcache_arch (regcache);
c8001721
EZ
2846 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2847
6ced10dd 2848 gdb_assert (regcache_arch == gdbarch);
f949c649 2849
5a9e69ba 2850 if (IS_SPE_PSEUDOREG (tdep, reg_nr))
f949c649
TJB
2851 e500_pseudo_register_write (gdbarch, regcache, reg_nr, buffer);
2852 else if (IS_DFP_PSEUDOREG (tdep, reg_nr))
604c2f83
LM
2853 dfp_pseudo_register_write (gdbarch, regcache, reg_nr, buffer);
2854 else if (IS_VSX_PSEUDOREG (tdep, reg_nr))
2855 vsx_pseudo_register_write (gdbarch, regcache, reg_nr, buffer);
2856 else if (IS_EFP_PSEUDOREG (tdep, reg_nr))
2857 efpr_pseudo_register_write (gdbarch, regcache, reg_nr, buffer);
6ced10dd 2858 else
a44bddec 2859 internal_error (__FILE__, __LINE__,
f949c649
TJB
2860 _("rs6000_pseudo_register_write: "
2861 "called on unexpected register '%s' (%d)"),
2862 gdbarch_register_name (gdbarch, reg_nr), reg_nr);
6ced10dd
JB
2863}
2864
18ed0c4e 2865/* Convert a DBX STABS register number to a GDB register number. */
c8001721 2866static int
d3f73121 2867rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
c8001721 2868{
d3f73121 2869 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
c8001721 2870
9f744501
JB
2871 if (0 <= num && num <= 31)
2872 return tdep->ppc_gp0_regnum + num;
2873 else if (32 <= num && num <= 63)
383f0f5b
JB
2874 /* FIXME: jimb/2004-05-05: What should we do when the debug info
2875 specifies registers the architecture doesn't have? Our
2876 callers don't check the value we return. */
366f009f 2877 return tdep->ppc_fp0_regnum + (num - 32);
18ed0c4e
JB
2878 else if (77 <= num && num <= 108)
2879 return tdep->ppc_vr0_regnum + (num - 77);
9f744501 2880 else if (1200 <= num && num < 1200 + 32)
e1ec1b42 2881 return tdep->ppc_ev0_upper_regnum + (num - 1200);
9f744501
JB
2882 else
2883 switch (num)
2884 {
2885 case 64:
2886 return tdep->ppc_mq_regnum;
2887 case 65:
2888 return tdep->ppc_lr_regnum;
2889 case 66:
2890 return tdep->ppc_ctr_regnum;
2891 case 76:
2892 return tdep->ppc_xer_regnum;
2893 case 109:
2894 return tdep->ppc_vrsave_regnum;
18ed0c4e
JB
2895 case 110:
2896 return tdep->ppc_vrsave_regnum - 1; /* vscr */
867e2dc5 2897 case 111:
18ed0c4e 2898 return tdep->ppc_acc_regnum;
867e2dc5 2899 case 112:
18ed0c4e 2900 return tdep->ppc_spefscr_regnum;
9f744501
JB
2901 default:
2902 return num;
2903 }
18ed0c4e 2904}
9f744501 2905
9f744501 2906
18ed0c4e
JB
2907/* Convert a Dwarf 2 register number to a GDB register number. */
2908static int
d3f73121 2909rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
18ed0c4e 2910{
d3f73121 2911 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
9f744501 2912
18ed0c4e
JB
2913 if (0 <= num && num <= 31)
2914 return tdep->ppc_gp0_regnum + num;
2915 else if (32 <= num && num <= 63)
2916 /* FIXME: jimb/2004-05-05: What should we do when the debug info
2917 specifies registers the architecture doesn't have? Our
2918 callers don't check the value we return. */
2919 return tdep->ppc_fp0_regnum + (num - 32);
2920 else if (1124 <= num && num < 1124 + 32)
2921 return tdep->ppc_vr0_regnum + (num - 1124);
2922 else if (1200 <= num && num < 1200 + 32)
e1ec1b42 2923 return tdep->ppc_ev0_upper_regnum + (num - 1200);
18ed0c4e
JB
2924 else
2925 switch (num)
2926 {
a489f789
AS
2927 case 64:
2928 return tdep->ppc_cr_regnum;
18ed0c4e
JB
2929 case 67:
2930 return tdep->ppc_vrsave_regnum - 1; /* vscr */
2931 case 99:
2932 return tdep->ppc_acc_regnum;
2933 case 100:
2934 return tdep->ppc_mq_regnum;
2935 case 101:
2936 return tdep->ppc_xer_regnum;
2937 case 108:
2938 return tdep->ppc_lr_regnum;
2939 case 109:
2940 return tdep->ppc_ctr_regnum;
2941 case 356:
2942 return tdep->ppc_vrsave_regnum;
2943 case 612:
2944 return tdep->ppc_spefscr_regnum;
2945 default:
2946 return num;
2947 }
2188cbdd
EZ
2948}
2949
4fc771b8
DJ
2950/* Translate a .eh_frame register to DWARF register, or adjust a
2951 .debug_frame register. */
2952
2953static int
2954rs6000_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p)
2955{
2956 /* GCC releases before 3.4 use GCC internal register numbering in
2957 .debug_frame (and .debug_info, et cetera). The numbering is
2958 different from the standard SysV numbering for everything except
2959 for GPRs and FPRs. We can not detect this problem in most cases
2960 - to get accurate debug info for variables living in lr, ctr, v0,
2961 et cetera, use a newer version of GCC. But we must detect
2962 one important case - lr is in column 65 in .debug_frame output,
2963 instead of 108.
2964
2965 GCC 3.4, and the "hammer" branch, have a related problem. They
2966 record lr register saves in .debug_frame as 108, but still record
2967 the return column as 65. We fix that up too.
2968
2969 We can do this because 65 is assigned to fpsr, and GCC never
2970 generates debug info referring to it. To add support for
2971 handwritten debug info that restores fpsr, we would need to add a
2972 producer version check to this. */
2973 if (!eh_frame_p)
2974 {
2975 if (num == 65)
2976 return 108;
2977 else
2978 return num;
2979 }
2980
2981 /* .eh_frame is GCC specific. For binary compatibility, it uses GCC
2982 internal register numbering; translate that to the standard DWARF2
2983 register numbering. */
2984 if (0 <= num && num <= 63) /* r0-r31,fp0-fp31 */
2985 return num;
2986 else if (68 <= num && num <= 75) /* cr0-cr8 */
2987 return num - 68 + 86;
2988 else if (77 <= num && num <= 108) /* vr0-vr31 */
2989 return num - 77 + 1124;
2990 else
2991 switch (num)
2992 {
2993 case 64: /* mq */
2994 return 100;
2995 case 65: /* lr */
2996 return 108;
2997 case 66: /* ctr */
2998 return 109;
2999 case 76: /* xer */
3000 return 101;
3001 case 109: /* vrsave */
3002 return 356;
3003 case 110: /* vscr */
3004 return 67;
3005 case 111: /* spe_acc */
3006 return 99;
3007 case 112: /* spefscr */
3008 return 612;
3009 default:
3010 return num;
3011 }
3012}
c906108c 3013\f
c5aa993b 3014
7a78ae4e 3015/* Handling the various POWER/PowerPC variants. */
c906108c 3016
c906108c 3017/* Information about a particular processor variant. */
7a78ae4e 3018
c906108c 3019struct variant
c5aa993b
JM
3020 {
3021 /* Name of this variant. */
3022 char *name;
c906108c 3023
c5aa993b
JM
3024 /* English description of the variant. */
3025 char *description;
c906108c 3026
64366f1c 3027 /* bfd_arch_info.arch corresponding to variant. */
7a78ae4e
ND
3028 enum bfd_architecture arch;
3029
64366f1c 3030 /* bfd_arch_info.mach corresponding to variant. */
7a78ae4e
ND
3031 unsigned long mach;
3032
7cc46491
DJ
3033 /* Target description for this variant. */
3034 struct target_desc **tdesc;
c5aa993b 3035 };
c906108c 3036
489461e2 3037static struct variant variants[] =
c906108c 3038{
7a78ae4e 3039 {"powerpc", "PowerPC user-level", bfd_arch_powerpc,
7284e1be 3040 bfd_mach_ppc, &tdesc_powerpc_altivec32},
7a78ae4e 3041 {"power", "POWER user-level", bfd_arch_rs6000,
7cc46491 3042 bfd_mach_rs6k, &tdesc_rs6000},
7a78ae4e 3043 {"403", "IBM PowerPC 403", bfd_arch_powerpc,
7cc46491 3044 bfd_mach_ppc_403, &tdesc_powerpc_403},
4d09ffea
MS
3045 {"405", "IBM PowerPC 405", bfd_arch_powerpc,
3046 bfd_mach_ppc_405, &tdesc_powerpc_405},
7a78ae4e 3047 {"601", "Motorola PowerPC 601", bfd_arch_powerpc,
7cc46491 3048 bfd_mach_ppc_601, &tdesc_powerpc_601},
7a78ae4e 3049 {"602", "Motorola PowerPC 602", bfd_arch_powerpc,
7cc46491 3050 bfd_mach_ppc_602, &tdesc_powerpc_602},
7a78ae4e 3051 {"603", "Motorola/IBM PowerPC 603 or 603e", bfd_arch_powerpc,
7cc46491 3052 bfd_mach_ppc_603, &tdesc_powerpc_603},
7a78ae4e 3053 {"604", "Motorola PowerPC 604 or 604e", bfd_arch_powerpc,
7cc46491 3054 604, &tdesc_powerpc_604},
7a78ae4e 3055 {"403GC", "IBM PowerPC 403GC", bfd_arch_powerpc,
7cc46491 3056 bfd_mach_ppc_403gc, &tdesc_powerpc_403gc},
7a78ae4e 3057 {"505", "Motorola PowerPC 505", bfd_arch_powerpc,
7cc46491 3058 bfd_mach_ppc_505, &tdesc_powerpc_505},
7a78ae4e 3059 {"860", "Motorola PowerPC 860 or 850", bfd_arch_powerpc,
7cc46491 3060 bfd_mach_ppc_860, &tdesc_powerpc_860},
7a78ae4e 3061 {"750", "Motorola/IBM PowerPC 750 or 740", bfd_arch_powerpc,
7cc46491 3062 bfd_mach_ppc_750, &tdesc_powerpc_750},
1fcc0bb8 3063 {"7400", "Motorola/IBM PowerPC 7400 (G4)", bfd_arch_powerpc,
7cc46491 3064 bfd_mach_ppc_7400, &tdesc_powerpc_7400},
c8001721 3065 {"e500", "Motorola PowerPC e500", bfd_arch_powerpc,
7cc46491 3066 bfd_mach_ppc_e500, &tdesc_powerpc_e500},
7a78ae4e 3067
5d57ee30
KB
3068 /* 64-bit */
3069 {"powerpc64", "PowerPC 64-bit user-level", bfd_arch_powerpc,
7284e1be 3070 bfd_mach_ppc64, &tdesc_powerpc_altivec64},
7a78ae4e 3071 {"620", "Motorola PowerPC 620", bfd_arch_powerpc,
7cc46491 3072 bfd_mach_ppc_620, &tdesc_powerpc_64},
5d57ee30 3073 {"630", "Motorola PowerPC 630", bfd_arch_powerpc,
7cc46491 3074 bfd_mach_ppc_630, &tdesc_powerpc_64},
7a78ae4e 3075 {"a35", "PowerPC A35", bfd_arch_powerpc,
7cc46491 3076 bfd_mach_ppc_a35, &tdesc_powerpc_64},
5d57ee30 3077 {"rs64ii", "PowerPC rs64ii", bfd_arch_powerpc,
7cc46491 3078 bfd_mach_ppc_rs64ii, &tdesc_powerpc_64},
5d57ee30 3079 {"rs64iii", "PowerPC rs64iii", bfd_arch_powerpc,
7cc46491 3080 bfd_mach_ppc_rs64iii, &tdesc_powerpc_64},
5d57ee30 3081
64366f1c 3082 /* FIXME: I haven't checked the register sets of the following. */
7a78ae4e 3083 {"rs1", "IBM POWER RS1", bfd_arch_rs6000,
7cc46491 3084 bfd_mach_rs6k_rs1, &tdesc_rs6000},
7a78ae4e 3085 {"rsc", "IBM POWER RSC", bfd_arch_rs6000,
7cc46491 3086 bfd_mach_rs6k_rsc, &tdesc_rs6000},
7a78ae4e 3087 {"rs2", "IBM POWER RS2", bfd_arch_rs6000,
7cc46491 3088 bfd_mach_rs6k_rs2, &tdesc_rs6000},
7a78ae4e 3089
7cc46491 3090 {0, 0, 0, 0, 0}
c906108c
SS
3091};
3092
7a78ae4e 3093/* Return the variant corresponding to architecture ARCH and machine number
64366f1c 3094 MACH. If no such variant exists, return null. */
c906108c 3095
7a78ae4e
ND
3096static const struct variant *
3097find_variant_by_arch (enum bfd_architecture arch, unsigned long mach)
c906108c 3098{
7a78ae4e 3099 const struct variant *v;
c5aa993b 3100
7a78ae4e
ND
3101 for (v = variants; v->name; v++)
3102 if (arch == v->arch && mach == v->mach)
3103 return v;
c906108c 3104
7a78ae4e 3105 return NULL;
c906108c 3106}
9364a0ef
EZ
3107
3108static int
3109gdb_print_insn_powerpc (bfd_vma memaddr, disassemble_info *info)
3110{
40887e1a 3111 if (info->endian == BFD_ENDIAN_BIG)
9364a0ef
EZ
3112 return print_insn_big_powerpc (memaddr, info);
3113 else
3114 return print_insn_little_powerpc (memaddr, info);
3115}
7a78ae4e 3116\f
61a65099
KB
3117static CORE_ADDR
3118rs6000_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
3119{
3e8c568d 3120 return frame_unwind_register_unsigned (next_frame,
8b164abb 3121 gdbarch_pc_regnum (gdbarch));
61a65099
KB
3122}
3123
3124static struct frame_id
1af5d7ce 3125rs6000_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
61a65099 3126{
1af5d7ce
UW
3127 return frame_id_build (get_frame_register_unsigned
3128 (this_frame, gdbarch_sp_regnum (gdbarch)),
3129 get_frame_pc (this_frame));
61a65099
KB
3130}
3131
3132struct rs6000_frame_cache
3133{
3134 CORE_ADDR base;
3135 CORE_ADDR initial_sp;
3136 struct trad_frame_saved_reg *saved_regs;
3137};
3138
3139static struct rs6000_frame_cache *
1af5d7ce 3140rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
61a65099
KB
3141{
3142 struct rs6000_frame_cache *cache;
1af5d7ce 3143 struct gdbarch *gdbarch = get_frame_arch (this_frame);
61a65099 3144 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
e17a4113 3145 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
61a65099
KB
3146 struct rs6000_framedata fdata;
3147 int wordsize = tdep->wordsize;
e10b1c4c 3148 CORE_ADDR func, pc;
61a65099
KB
3149
3150 if ((*this_cache) != NULL)
3151 return (*this_cache);
3152 cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache);
3153 (*this_cache) = cache;
1af5d7ce 3154 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
61a65099 3155
1af5d7ce
UW
3156 func = get_frame_func (this_frame);
3157 pc = get_frame_pc (this_frame);
be8626e0 3158 skip_prologue (gdbarch, func, pc, &fdata);
e10b1c4c
DJ
3159
3160 /* Figure out the parent's stack pointer. */
3161
3162 /* NOTE: cagney/2002-04-14: The ->frame points to the inner-most
3163 address of the current frame. Things might be easier if the
3164 ->frame pointed to the outer-most address of the frame. In
3165 the mean time, the address of the prev frame is used as the
3166 base address of this frame. */
1af5d7ce
UW
3167 cache->base = get_frame_register_unsigned
3168 (this_frame, gdbarch_sp_regnum (gdbarch));
e10b1c4c
DJ
3169
3170 /* If the function appears to be frameless, check a couple of likely
3171 indicators that we have simply failed to find the frame setup.
3172 Two common cases of this are missing symbols (i.e.
ef02daa9 3173 get_frame_func returns the wrong address or 0), and assembly
e10b1c4c
DJ
3174 stubs which have a fast exit path but set up a frame on the slow
3175 path.
3176
3177 If the LR appears to return to this function, then presume that
3178 we have an ABI compliant frame that we failed to find. */
3179 if (fdata.frameless && fdata.lr_offset == 0)
61a65099 3180 {
e10b1c4c
DJ
3181 CORE_ADDR saved_lr;
3182 int make_frame = 0;
3183
1af5d7ce 3184 saved_lr = get_frame_register_unsigned (this_frame, tdep->ppc_lr_regnum);
e10b1c4c
DJ
3185 if (func == 0 && saved_lr == pc)
3186 make_frame = 1;
3187 else if (func != 0)
3188 {
3189 CORE_ADDR saved_func = get_pc_function_start (saved_lr);
3190 if (func == saved_func)
3191 make_frame = 1;
3192 }
3193
3194 if (make_frame)
3195 {
3196 fdata.frameless = 0;
de6a76fd 3197 fdata.lr_offset = tdep->lr_frame_offset;
e10b1c4c 3198 }
61a65099 3199 }
e10b1c4c
DJ
3200
3201 if (!fdata.frameless)
9d9bf2df
EBM
3202 {
3203 /* Frameless really means stackless. */
3204 LONGEST backchain;
3205
3206 if (safe_read_memory_integer (cache->base, wordsize,
3207 byte_order, &backchain))
3208 cache->base = (CORE_ADDR) backchain;
3209 }
e10b1c4c 3210
3e8c568d 3211 trad_frame_set_value (cache->saved_regs,
8b164abb 3212 gdbarch_sp_regnum (gdbarch), cache->base);
61a65099
KB
3213
3214 /* if != -1, fdata.saved_fpr is the smallest number of saved_fpr.
3215 All fpr's from saved_fpr to fp31 are saved. */
3216
3217 if (fdata.saved_fpr >= 0)
3218 {
3219 int i;
3220 CORE_ADDR fpr_addr = cache->base + fdata.fpr_offset;
383f0f5b
JB
3221
3222 /* If skip_prologue says floating-point registers were saved,
3223 but the current architecture has no floating-point registers,
3224 then that's strange. But we have no indices to even record
3225 the addresses under, so we just ignore it. */
3226 if (ppc_floating_point_unit_p (gdbarch))
063715bf 3227 for (i = fdata.saved_fpr; i < ppc_num_fprs; i++)
383f0f5b
JB
3228 {
3229 cache->saved_regs[tdep->ppc_fp0_regnum + i].addr = fpr_addr;
3230 fpr_addr += 8;
3231 }
61a65099
KB
3232 }
3233
3234 /* if != -1, fdata.saved_gpr is the smallest number of saved_gpr.
46a9b8ed
DJ
3235 All gpr's from saved_gpr to gpr31 are saved (except during the
3236 prologue). */
61a65099
KB
3237
3238 if (fdata.saved_gpr >= 0)
3239 {
3240 int i;
3241 CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset;
063715bf 3242 for (i = fdata.saved_gpr; i < ppc_num_gprs; i++)
61a65099 3243 {
46a9b8ed
DJ
3244 if (fdata.gpr_mask & (1U << i))
3245 cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = gpr_addr;
61a65099
KB
3246 gpr_addr += wordsize;
3247 }
3248 }
3249
3250 /* if != -1, fdata.saved_vr is the smallest number of saved_vr.
3251 All vr's from saved_vr to vr31 are saved. */
3252 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
3253 {
3254 if (fdata.saved_vr >= 0)
3255 {
3256 int i;
3257 CORE_ADDR vr_addr = cache->base + fdata.vr_offset;
3258 for (i = fdata.saved_vr; i < 32; i++)
3259 {
3260 cache->saved_regs[tdep->ppc_vr0_regnum + i].addr = vr_addr;
3261 vr_addr += register_size (gdbarch, tdep->ppc_vr0_regnum);
3262 }
3263 }
3264 }
3265
3266 /* if != -1, fdata.saved_ev is the smallest number of saved_ev.
0df8b418 3267 All vr's from saved_ev to ev31 are saved. ????? */
5a9e69ba 3268 if (tdep->ppc_ev0_regnum != -1)
61a65099
KB
3269 {
3270 if (fdata.saved_ev >= 0)
3271 {
3272 int i;
3273 CORE_ADDR ev_addr = cache->base + fdata.ev_offset;
dea80df0
MR
3274 CORE_ADDR off = (byte_order == BFD_ENDIAN_BIG ? 4 : 0);
3275
063715bf 3276 for (i = fdata.saved_ev; i < ppc_num_gprs; i++)
61a65099
KB
3277 {
3278 cache->saved_regs[tdep->ppc_ev0_regnum + i].addr = ev_addr;
dea80df0 3279 cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = ev_addr + off;
61a65099 3280 ev_addr += register_size (gdbarch, tdep->ppc_ev0_regnum);
dea80df0 3281 }
61a65099
KB
3282 }
3283 }
3284
3285 /* If != 0, fdata.cr_offset is the offset from the frame that
3286 holds the CR. */
3287 if (fdata.cr_offset != 0)
0df8b418
MS
3288 cache->saved_regs[tdep->ppc_cr_regnum].addr
3289 = cache->base + fdata.cr_offset;
61a65099
KB
3290
3291 /* If != 0, fdata.lr_offset is the offset from the frame that
3292 holds the LR. */
3293 if (fdata.lr_offset != 0)
0df8b418
MS
3294 cache->saved_regs[tdep->ppc_lr_regnum].addr
3295 = cache->base + fdata.lr_offset;
46a9b8ed
DJ
3296 else if (fdata.lr_register != -1)
3297 cache->saved_regs[tdep->ppc_lr_regnum].realreg = fdata.lr_register;
61a65099 3298 /* The PC is found in the link register. */
8b164abb 3299 cache->saved_regs[gdbarch_pc_regnum (gdbarch)] =
3e8c568d 3300 cache->saved_regs[tdep->ppc_lr_regnum];
61a65099
KB
3301
3302 /* If != 0, fdata.vrsave_offset is the offset from the frame that
3303 holds the VRSAVE. */
3304 if (fdata.vrsave_offset != 0)
0df8b418
MS
3305 cache->saved_regs[tdep->ppc_vrsave_regnum].addr
3306 = cache->base + fdata.vrsave_offset;
61a65099
KB
3307
3308 if (fdata.alloca_reg < 0)
3309 /* If no alloca register used, then fi->frame is the value of the
3310 %sp for this frame, and it is good enough. */
1af5d7ce
UW
3311 cache->initial_sp
3312 = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
61a65099 3313 else
1af5d7ce
UW
3314 cache->initial_sp
3315 = get_frame_register_unsigned (this_frame, fdata.alloca_reg);
61a65099
KB
3316
3317 return cache;
3318}
3319
3320static void
1af5d7ce 3321rs6000_frame_this_id (struct frame_info *this_frame, void **this_cache,
61a65099
KB
3322 struct frame_id *this_id)
3323{
1af5d7ce 3324 struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame,
61a65099 3325 this_cache);
5b197912
UW
3326 /* This marks the outermost frame. */
3327 if (info->base == 0)
3328 return;
3329
1af5d7ce 3330 (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
61a65099
KB
3331}
3332
1af5d7ce
UW
3333static struct value *
3334rs6000_frame_prev_register (struct frame_info *this_frame,
3335 void **this_cache, int regnum)
61a65099 3336{
1af5d7ce 3337 struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame,
61a65099 3338 this_cache);
1af5d7ce 3339 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
61a65099
KB
3340}
3341
3342static const struct frame_unwind rs6000_frame_unwind =
3343{
3344 NORMAL_FRAME,
8fbca658 3345 default_frame_unwind_stop_reason,
61a65099 3346 rs6000_frame_this_id,
1af5d7ce
UW
3347 rs6000_frame_prev_register,
3348 NULL,
3349 default_frame_sniffer
61a65099 3350};
2608dbf8 3351
ddeca1df
WW
3352/* Allocate and initialize a frame cache for an epilogue frame.
3353 SP is restored and prev-PC is stored in LR. */
3354
2608dbf8
WW
3355static struct rs6000_frame_cache *
3356rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
3357{
3358 volatile struct gdb_exception ex;
3359 struct rs6000_frame_cache *cache;
3360 struct gdbarch *gdbarch = get_frame_arch (this_frame);
3361 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2608dbf8
WW
3362
3363 if (*this_cache)
3364 return *this_cache;
3365
3366 cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache);
3367 (*this_cache) = cache;
3368 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
3369
3370 TRY_CATCH (ex, RETURN_MASK_ERROR)
3371 {
3372 /* At this point the stack looks as if we just entered the
3373 function, and the return address is stored in LR. */
3374 CORE_ADDR sp, lr;
3375
3376 sp = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
3377 lr = get_frame_register_unsigned (this_frame, tdep->ppc_lr_regnum);
3378
3379 cache->base = sp;
3380 cache->initial_sp = sp;
3381
3382 trad_frame_set_value (cache->saved_regs,
3383 gdbarch_pc_regnum (gdbarch), lr);
3384 }
3385 if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
3386 throw_exception (ex);
3387
3388 return cache;
3389}
3390
ddeca1df
WW
3391/* Implementation of frame_unwind.this_id, as defined in frame_unwind.h.
3392 Return the frame ID of an epilogue frame. */
3393
2608dbf8
WW
3394static void
3395rs6000_epilogue_frame_this_id (struct frame_info *this_frame,
3396 void **this_cache, struct frame_id *this_id)
3397{
3398 CORE_ADDR pc;
3399 struct rs6000_frame_cache *info =
3400 rs6000_epilogue_frame_cache (this_frame, this_cache);
3401
3402 pc = get_frame_func (this_frame);
3403 if (info->base == 0)
3404 (*this_id) = frame_id_build_unavailable_stack (pc);
3405 else
3406 (*this_id) = frame_id_build (info->base, pc);
3407}
3408
ddeca1df
WW
3409/* Implementation of frame_unwind.prev_register, as defined in frame_unwind.h.
3410 Return the register value of REGNUM in previous frame. */
3411
2608dbf8
WW
3412static struct value *
3413rs6000_epilogue_frame_prev_register (struct frame_info *this_frame,
3414 void **this_cache, int regnum)
3415{
3416 struct rs6000_frame_cache *info =
3417 rs6000_epilogue_frame_cache (this_frame, this_cache);
3418 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
3419}
3420
ddeca1df
WW
3421/* Implementation of frame_unwind.sniffer, as defined in frame_unwind.h.
3422 Check whether this an epilogue frame. */
3423
2608dbf8
WW
3424static int
3425rs6000_epilogue_frame_sniffer (const struct frame_unwind *self,
3426 struct frame_info *this_frame,
3427 void **this_prologue_cache)
3428{
3429 if (frame_relative_level (this_frame) == 0)
3430 return rs6000_in_function_epilogue_frame_p (this_frame,
3431 get_frame_arch (this_frame),
3432 get_frame_pc (this_frame));
3433 else
3434 return 0;
3435}
3436
ddeca1df
WW
3437/* Frame unwinder for epilogue frame. This is required for reverse step-over
3438 a function without debug information. */
3439
2608dbf8
WW
3440static const struct frame_unwind rs6000_epilogue_frame_unwind =
3441{
3442 NORMAL_FRAME,
3443 default_frame_unwind_stop_reason,
3444 rs6000_epilogue_frame_this_id, rs6000_epilogue_frame_prev_register,
3445 NULL,
3446 rs6000_epilogue_frame_sniffer
3447};
61a65099
KB
3448\f
3449
3450static CORE_ADDR
1af5d7ce 3451rs6000_frame_base_address (struct frame_info *this_frame, void **this_cache)
61a65099 3452{
1af5d7ce 3453 struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame,
61a65099
KB
3454 this_cache);
3455 return info->initial_sp;
3456}
3457
3458static const struct frame_base rs6000_frame_base = {
3459 &rs6000_frame_unwind,
3460 rs6000_frame_base_address,
3461 rs6000_frame_base_address,
3462 rs6000_frame_base_address
3463};
3464
3465static const struct frame_base *
1af5d7ce 3466rs6000_frame_base_sniffer (struct frame_info *this_frame)
61a65099
KB
3467{
3468 return &rs6000_frame_base;
3469}
3470
9274a07c
LM
3471/* DWARF-2 frame support. Used to handle the detection of
3472 clobbered registers during function calls. */
3473
3474static void
3475ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
3476 struct dwarf2_frame_state_reg *reg,
4a4e5149 3477 struct frame_info *this_frame)
9274a07c
LM
3478{
3479 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3480
3481 /* PPC32 and PPC64 ABI's are the same regarding volatile and
3482 non-volatile registers. We will use the same code for both. */
3483
3484 /* Call-saved GP registers. */
3485 if ((regnum >= tdep->ppc_gp0_regnum + 14
3486 && regnum <= tdep->ppc_gp0_regnum + 31)
3487 || (regnum == tdep->ppc_gp0_regnum + 1))
3488 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3489
3490 /* Call-clobbered GP registers. */
3491 if ((regnum >= tdep->ppc_gp0_regnum + 3
3492 && regnum <= tdep->ppc_gp0_regnum + 12)
3493 || (regnum == tdep->ppc_gp0_regnum))
3494 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3495
3496 /* Deal with FP registers, if supported. */
3497 if (tdep->ppc_fp0_regnum >= 0)
3498 {
3499 /* Call-saved FP registers. */
3500 if ((regnum >= tdep->ppc_fp0_regnum + 14
3501 && regnum <= tdep->ppc_fp0_regnum + 31))
3502 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3503
3504 /* Call-clobbered FP registers. */
3505 if ((regnum >= tdep->ppc_fp0_regnum
3506 && regnum <= tdep->ppc_fp0_regnum + 13))
3507 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3508 }
3509
3510 /* Deal with ALTIVEC registers, if supported. */
3511 if (tdep->ppc_vr0_regnum > 0 && tdep->ppc_vrsave_regnum > 0)
3512 {
3513 /* Call-saved Altivec registers. */
3514 if ((regnum >= tdep->ppc_vr0_regnum + 20
3515 && regnum <= tdep->ppc_vr0_regnum + 31)
3516 || regnum == tdep->ppc_vrsave_regnum)
3517 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3518
3519 /* Call-clobbered Altivec registers. */
3520 if ((regnum >= tdep->ppc_vr0_regnum
3521 && regnum <= tdep->ppc_vr0_regnum + 19))
3522 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3523 }
3524
3525 /* Handle PC register and Stack Pointer correctly. */
40a6adc1 3526 if (regnum == gdbarch_pc_regnum (gdbarch))
9274a07c 3527 reg->how = DWARF2_FRAME_REG_RA;
40a6adc1 3528 else if (regnum == gdbarch_sp_regnum (gdbarch))
9274a07c
LM
3529 reg->how = DWARF2_FRAME_REG_CFA;
3530}
3531
3532
74af9197
NF
3533/* Return true if a .gnu_attributes section exists in BFD and it
3534 indicates we are using SPE extensions OR if a .PPC.EMB.apuinfo
3535 section exists in BFD and it indicates that SPE extensions are in
3536 use. Check the .gnu.attributes section first, as the binary might be
3537 compiled for SPE, but not actually using SPE instructions. */
3538
3539static int
3540bfd_uses_spe_extensions (bfd *abfd)
3541{
3542 asection *sect;
3543 gdb_byte *contents = NULL;
3544 bfd_size_type size;
3545 gdb_byte *ptr;
3546 int success = 0;
3547 int vector_abi;
3548
3549 if (!abfd)
3550 return 0;
3551
50a99728 3552#ifdef HAVE_ELF
74af9197
NF
3553 /* Using Tag_GNU_Power_ABI_Vector here is a bit of a hack, as the user
3554 could be using the SPE vector abi without actually using any spe
3555 bits whatsoever. But it's close enough for now. */
3556 vector_abi = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_GNU,
3557 Tag_GNU_Power_ABI_Vector);
3558 if (vector_abi == 3)
3559 return 1;
50a99728 3560#endif
74af9197
NF
3561
3562 sect = bfd_get_section_by_name (abfd, ".PPC.EMB.apuinfo");
3563 if (!sect)
3564 return 0;
3565
3566 size = bfd_get_section_size (sect);
3567 contents = xmalloc (size);
3568 if (!bfd_get_section_contents (abfd, sect, contents, 0, size))
3569 {
3570 xfree (contents);
3571 return 0;
3572 }
3573
3574 /* Parse the .PPC.EMB.apuinfo section. The layout is as follows:
3575
3576 struct {
3577 uint32 name_len;
3578 uint32 data_len;
3579 uint32 type;
3580 char name[name_len rounded up to 4-byte alignment];
3581 char data[data_len];
3582 };
3583
3584 Technically, there's only supposed to be one such structure in a
3585 given apuinfo section, but the linker is not always vigilant about
3586 merging apuinfo sections from input files. Just go ahead and parse
3587 them all, exiting early when we discover the binary uses SPE
3588 insns.
3589
3590 It's not specified in what endianness the information in this
3591 section is stored. Assume that it's the endianness of the BFD. */
3592 ptr = contents;
3593 while (1)
3594 {
3595 unsigned int name_len;
3596 unsigned int data_len;
3597 unsigned int type;
3598
3599 /* If we can't read the first three fields, we're done. */
3600 if (size < 12)
3601 break;
3602
3603 name_len = bfd_get_32 (abfd, ptr);
3604 name_len = (name_len + 3) & ~3U; /* Round to 4 bytes. */
3605 data_len = bfd_get_32 (abfd, ptr + 4);
3606 type = bfd_get_32 (abfd, ptr + 8);
3607 ptr += 12;
3608
3609 /* The name must be "APUinfo\0". */
3610 if (name_len != 8
3611 && strcmp ((const char *) ptr, "APUinfo") != 0)
3612 break;
3613 ptr += name_len;
3614
3615 /* The type must be 2. */
3616 if (type != 2)
3617 break;
3618
3619 /* The data is stored as a series of uint32. The upper half of
3620 each uint32 indicates the particular APU used and the lower
3621 half indicates the revision of that APU. We just care about
3622 the upper half. */
3623
3624 /* Not 4-byte quantities. */
3625 if (data_len & 3U)
3626 break;
3627
3628 while (data_len)
3629 {
3630 unsigned int apuinfo = bfd_get_32 (abfd, ptr);
3631 unsigned int apu = apuinfo >> 16;
3632 ptr += 4;
3633 data_len -= 4;
3634
3635 /* The SPE APU is 0x100; the SPEFP APU is 0x101. Accept
3636 either. */
3637 if (apu == 0x100 || apu == 0x101)
3638 {
3639 success = 1;
3640 data_len = 0;
3641 }
3642 }
3643
3644 if (success)
3645 break;
3646 }
3647
3648 xfree (contents);
3649 return success;
3650}
3651
b4cdae6f
WW
3652/* These are macros for parsing instruction fields (I.1.6.28) */
3653
3654#define PPC_FIELD(value, from, len) \
3655 (((value) >> (32 - (from) - (len))) & ((1 << (len)) - 1))
3656#define PPC_SEXT(v, bs) \
3657 ((((CORE_ADDR) (v) & (((CORE_ADDR) 1 << (bs)) - 1)) \
3658 ^ ((CORE_ADDR) 1 << ((bs) - 1))) \
3659 - ((CORE_ADDR) 1 << ((bs) - 1)))
3660#define PPC_OP6(insn) PPC_FIELD (insn, 0, 6)
3661#define PPC_EXTOP(insn) PPC_FIELD (insn, 21, 10)
3662#define PPC_RT(insn) PPC_FIELD (insn, 6, 5)
3663#define PPC_RS(insn) PPC_FIELD (insn, 6, 5)
3664#define PPC_RA(insn) PPC_FIELD (insn, 11, 5)
3665#define PPC_RB(insn) PPC_FIELD (insn, 16, 5)
3666#define PPC_NB(insn) PPC_FIELD (insn, 16, 5)
3667#define PPC_VRT(insn) PPC_FIELD (insn, 6, 5)
3668#define PPC_FRT(insn) PPC_FIELD (insn, 6, 5)
3669#define PPC_SPR(insn) (PPC_FIELD (insn, 11, 5) \
3670 | (PPC_FIELD (insn, 16, 5) << 5))
3671#define PPC_BO(insn) PPC_FIELD (insn, 6, 5)
3672#define PPC_T(insn) PPC_FIELD (insn, 6, 5)
3673#define PPC_D(insn) PPC_SEXT (PPC_FIELD (insn, 16, 16), 16)
3674#define PPC_DS(insn) PPC_SEXT (PPC_FIELD (insn, 16, 14), 14)
3675#define PPC_BIT(insn,n) ((insn & (1 << (31 - (n)))) ? 1 : 0)
3676#define PPC_OE(insn) PPC_BIT (insn, 21)
3677#define PPC_RC(insn) PPC_BIT (insn, 31)
3678#define PPC_Rc(insn) PPC_BIT (insn, 21)
3679#define PPC_LK(insn) PPC_BIT (insn, 31)
3680#define PPC_TX(insn) PPC_BIT (insn, 31)
3681#define PPC_LEV(insn) PPC_FIELD (insn, 20, 7)
3682
3683#define PPC_XT(insn) ((PPC_TX (insn) << 5) | PPC_T (insn))
3684#define PPC_XER_NB(xer) (xer & 0x7f)
3685
ddeca1df
WW
3686/* Record Vector-Scalar Registers.
3687 For VSR less than 32, it's represented by an FPR and an VSR-upper register.
3688 Otherwise, it's just a VR register. Record them accordingly. */
b4cdae6f
WW
3689
3690static int
3691ppc_record_vsr (struct regcache *regcache, struct gdbarch_tdep *tdep, int vsr)
3692{
3693 if (vsr < 0 || vsr >= 64)
3694 return -1;
3695
3696 if (vsr >= 32)
3697 {
3698 if (tdep->ppc_vr0_regnum >= 0)
3699 record_full_arch_list_add_reg (regcache, tdep->ppc_vr0_regnum + vsr - 32);
3700 }
3701 else
3702 {
3703 if (tdep->ppc_fp0_regnum >= 0)
3704 record_full_arch_list_add_reg (regcache, tdep->ppc_fp0_regnum + vsr);
3705 if (tdep->ppc_vsr0_upper_regnum >= 0)
3706 record_full_arch_list_add_reg (regcache,
3707 tdep->ppc_vsr0_upper_regnum + vsr);
3708 }
3709
3710 return 0;
3711}
3712
ddeca1df
WW
3713/* Parse and record instructions primary opcode-4 at ADDR.
3714 Return 0 if successful. */
b4cdae6f
WW
3715
3716static int
3717ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
ddeca1df 3718 CORE_ADDR addr, uint32_t insn)
b4cdae6f
WW
3719{
3720 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3721 int ext = PPC_FIELD (insn, 21, 11);
3722
3723 switch (ext & 0x3f)
3724 {
3725 case 32: /* Vector Multiply-High-Add Signed Halfword Saturate */
3726 case 33: /* Vector Multiply-High-Round-Add Signed Halfword Saturate */
3727 case 39: /* Vector Multiply-Sum Unsigned Halfword Saturate */
3728 case 41: /* Vector Multiply-Sum Signed Halfword Saturate */
3729 record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM);
3730 /* FALL-THROUGH */
3731 case 42: /* Vector Select */
3732 case 43: /* Vector Permute */
3733 case 44: /* Vector Shift Left Double by Octet Immediate */
3734 case 45: /* Vector Permute and Exclusive-OR */
3735 case 60: /* Vector Add Extended Unsigned Quadword Modulo */
3736 case 61: /* Vector Add Extended & write Carry Unsigned Quadword */
3737 case 62: /* Vector Subtract Extended Unsigned Quadword Modulo */
3738 case 63: /* Vector Subtract Extended & write Carry Unsigned Quadword */
3739 case 34: /* Vector Multiply-Low-Add Unsigned Halfword Modulo */
3740 case 36: /* Vector Multiply-Sum Unsigned Byte Modulo */
3741 case 37: /* Vector Multiply-Sum Mixed Byte Modulo */
3742 case 38: /* Vector Multiply-Sum Unsigned Halfword Modulo */
3743 case 40: /* Vector Multiply-Sum Signed Halfword Modulo */
3744 case 46: /* Vector Multiply-Add Single-Precision */
3745 case 47: /* Vector Negative Multiply-Subtract Single-Precision */
3746 record_full_arch_list_add_reg (regcache,
3747 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3748 return 0;
3749 }
3750
3751 switch ((ext & 0x1ff))
3752 {
3753 /* 5.16 Decimal Integer Arithmetic Instructions */
3754 case 1: /* Decimal Add Modulo */
3755 case 65: /* Decimal Subtract Modulo */
3756
3757 /* Bit-21 should be set. */
3758 if (!PPC_BIT (insn, 21))
3759 break;
3760
3761 record_full_arch_list_add_reg (regcache,
3762 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3763 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
3764 return 0;
3765 }
3766
3767 /* Bit-21 is used for RC */
3768 switch (ext & 0x3ff)
3769 {
3770 case 6: /* Vector Compare Equal To Unsigned Byte */
3771 case 70: /* Vector Compare Equal To Unsigned Halfword */
3772 case 134: /* Vector Compare Equal To Unsigned Word */
3773 case 199: /* Vector Compare Equal To Unsigned Doubleword */
3774 case 774: /* Vector Compare Greater Than Signed Byte */
3775 case 838: /* Vector Compare Greater Than Signed Halfword */
3776 case 902: /* Vector Compare Greater Than Signed Word */
3777 case 967: /* Vector Compare Greater Than Signed Doubleword */
3778 case 518: /* Vector Compare Greater Than Unsigned Byte */
3779 case 646: /* Vector Compare Greater Than Unsigned Word */
3780 case 582: /* Vector Compare Greater Than Unsigned Halfword */
3781 case 711: /* Vector Compare Greater Than Unsigned Doubleword */
3782 case 966: /* Vector Compare Bounds Single-Precision */
3783 case 198: /* Vector Compare Equal To Single-Precision */
3784 case 454: /* Vector Compare Greater Than or Equal To Single-Precision */
3785 case 710: /* Vector Compare Greater Than Single-Precision */
3786 if (PPC_Rc (insn))
3787 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
3788 record_full_arch_list_add_reg (regcache,
3789 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3790 return 0;
3791 }
3792
3793 switch (ext)
3794 {
3795 case 142: /* Vector Pack Unsigned Halfword Unsigned Saturate */
3796 case 206: /* Vector Pack Unsigned Word Unsigned Saturate */
3797 case 270: /* Vector Pack Signed Halfword Unsigned Saturate */
3798 case 334: /* Vector Pack Signed Word Unsigned Saturate */
3799 case 398: /* Vector Pack Signed Halfword Signed Saturate */
3800 case 462: /* Vector Pack Signed Word Signed Saturate */
3801 case 1230: /* Vector Pack Unsigned Doubleword Unsigned Saturate */
3802 case 1358: /* Vector Pack Signed Doubleword Unsigned Saturate */
3803 case 1486: /* Vector Pack Signed Doubleword Signed Saturate */
3804 case 512: /* Vector Add Unsigned Byte Saturate */
3805 case 576: /* Vector Add Unsigned Halfword Saturate */
3806 case 640: /* Vector Add Unsigned Word Saturate */
3807 case 768: /* Vector Add Signed Byte Saturate */
3808 case 832: /* Vector Add Signed Halfword Saturate */
3809 case 896: /* Vector Add Signed Word Saturate */
3810 case 1536: /* Vector Subtract Unsigned Byte Saturate */
3811 case 1600: /* Vector Subtract Unsigned Halfword Saturate */
3812 case 1664: /* Vector Subtract Unsigned Word Saturate */
3813 case 1792: /* Vector Subtract Signed Byte Saturate */
3814 case 1856: /* Vector Subtract Signed Halfword Saturate */
3815 case 1920: /* Vector Subtract Signed Word Saturate */
3816
3817 case 1544: /* Vector Sum across Quarter Unsigned Byte Saturate */
3818 case 1800: /* Vector Sum across Quarter Signed Byte Saturate */
3819 case 1608: /* Vector Sum across Quarter Signed Halfword Saturate */
3820 case 1672: /* Vector Sum across Half Signed Word Saturate */
3821 case 1928: /* Vector Sum across Signed Word Saturate */
3822 case 970: /* Vector Convert To Signed Fixed-Point Word Saturate */
3823 case 906: /* Vector Convert To Unsigned Fixed-Point Word Saturate */
3824 record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM);
3825 /* FALL-THROUGH */
3826 case 12: /* Vector Merge High Byte */
3827 case 14: /* Vector Pack Unsigned Halfword Unsigned Modulo */
3828 case 76: /* Vector Merge High Halfword */
3829 case 78: /* Vector Pack Unsigned Word Unsigned Modulo */
3830 case 140: /* Vector Merge High Word */
3831 case 268: /* Vector Merge Low Byte */
3832 case 332: /* Vector Merge Low Halfword */
3833 case 396: /* Vector Merge Low Word */
3834 case 526: /* Vector Unpack High Signed Byte */
3835 case 590: /* Vector Unpack High Signed Halfword */
3836 case 654: /* Vector Unpack Low Signed Byte */
3837 case 718: /* Vector Unpack Low Signed Halfword */
3838 case 782: /* Vector Pack Pixel */
3839 case 846: /* Vector Unpack High Pixel */
3840 case 974: /* Vector Unpack Low Pixel */
3841 case 1102: /* Vector Pack Unsigned Doubleword Unsigned Modulo */
3842 case 1614: /* Vector Unpack High Signed Word */
3843 case 1676: /* Vector Merge Odd Word */
3844 case 1742: /* Vector Unpack Low Signed Word */
3845 case 1932: /* Vector Merge Even Word */
3846 case 524: /* Vector Splat Byte */
3847 case 588: /* Vector Splat Halfword */
3848 case 652: /* Vector Splat Word */
3849 case 780: /* Vector Splat Immediate Signed Byte */
3850 case 844: /* Vector Splat Immediate Signed Halfword */
3851 case 908: /* Vector Splat Immediate Signed Word */
3852 case 452: /* Vector Shift Left */
3853 case 708: /* Vector Shift Right */
3854 case 1036: /* Vector Shift Left by Octet */
3855 case 1100: /* Vector Shift Right by Octet */
3856 case 0: /* Vector Add Unsigned Byte Modulo */
3857 case 64: /* Vector Add Unsigned Halfword Modulo */
3858 case 128: /* Vector Add Unsigned Word Modulo */
3859 case 192: /* Vector Add Unsigned Doubleword Modulo */
3860 case 256: /* Vector Add Unsigned Quadword Modulo */
3861 case 320: /* Vector Add & write Carry Unsigned Quadword */
3862 case 384: /* Vector Add and Write Carry-Out Unsigned Word */
3863 case 8: /* Vector Multiply Odd Unsigned Byte */
3864 case 72: /* Vector Multiply Odd Unsigned Halfword */
3865 case 136: /* Vector Multiply Odd Unsigned Word */
3866 case 264: /* Vector Multiply Odd Signed Byte */
3867 case 328: /* Vector Multiply Odd Signed Halfword */
3868 case 392: /* Vector Multiply Odd Signed Word */
3869 case 520: /* Vector Multiply Even Unsigned Byte */
3870 case 584: /* Vector Multiply Even Unsigned Halfword */
3871 case 648: /* Vector Multiply Even Unsigned Word */
3872 case 776: /* Vector Multiply Even Signed Byte */
3873 case 840: /* Vector Multiply Even Signed Halfword */
3874 case 904: /* Vector Multiply Even Signed Word */
3875 case 137: /* Vector Multiply Unsigned Word Modulo */
3876 case 1024: /* Vector Subtract Unsigned Byte Modulo */
3877 case 1088: /* Vector Subtract Unsigned Halfword Modulo */
3878 case 1152: /* Vector Subtract Unsigned Word Modulo */
3879 case 1216: /* Vector Subtract Unsigned Doubleword Modulo */
3880 case 1280: /* Vector Subtract Unsigned Quadword Modulo */
3881 case 1344: /* Vector Subtract & write Carry Unsigned Quadword */
3882 case 1408: /* Vector Subtract and Write Carry-Out Unsigned Word */
3883 case 1282: /* Vector Average Signed Byte */
3884 case 1346: /* Vector Average Signed Halfword */
3885 case 1410: /* Vector Average Signed Word */
3886 case 1026: /* Vector Average Unsigned Byte */
3887 case 1090: /* Vector Average Unsigned Halfword */
3888 case 1154: /* Vector Average Unsigned Word */
3889 case 258: /* Vector Maximum Signed Byte */
3890 case 322: /* Vector Maximum Signed Halfword */
3891 case 386: /* Vector Maximum Signed Word */
3892 case 450: /* Vector Maximum Signed Doubleword */
3893 case 2: /* Vector Maximum Unsigned Byte */
3894 case 66: /* Vector Maximum Unsigned Halfword */
3895 case 130: /* Vector Maximum Unsigned Word */
3896 case 194: /* Vector Maximum Unsigned Doubleword */
3897 case 770: /* Vector Minimum Signed Byte */
3898 case 834: /* Vector Minimum Signed Halfword */
3899 case 898: /* Vector Minimum Signed Word */
3900 case 962: /* Vector Minimum Signed Doubleword */
3901 case 514: /* Vector Minimum Unsigned Byte */
3902 case 578: /* Vector Minimum Unsigned Halfword */
3903 case 642: /* Vector Minimum Unsigned Word */
3904 case 706: /* Vector Minimum Unsigned Doubleword */
3905 case 1028: /* Vector Logical AND */
3906 case 1668: /* Vector Logical Equivalent */
3907 case 1092: /* Vector Logical AND with Complement */
3908 case 1412: /* Vector Logical NAND */
3909 case 1348: /* Vector Logical OR with Complement */
3910 case 1156: /* Vector Logical OR */
3911 case 1284: /* Vector Logical NOR */
3912 case 1220: /* Vector Logical XOR */
3913 case 4: /* Vector Rotate Left Byte */
3914 case 132: /* Vector Rotate Left Word VX-form */
3915 case 68: /* Vector Rotate Left Halfword */
3916 case 196: /* Vector Rotate Left Doubleword */
3917 case 260: /* Vector Shift Left Byte */
3918 case 388: /* Vector Shift Left Word */
3919 case 324: /* Vector Shift Left Halfword */
3920 case 1476: /* Vector Shift Left Doubleword */
3921 case 516: /* Vector Shift Right Byte */
3922 case 644: /* Vector Shift Right Word */
3923 case 580: /* Vector Shift Right Halfword */
3924 case 1732: /* Vector Shift Right Doubleword */
3925 case 772: /* Vector Shift Right Algebraic Byte */
3926 case 900: /* Vector Shift Right Algebraic Word */
3927 case 836: /* Vector Shift Right Algebraic Halfword */
3928 case 964: /* Vector Shift Right Algebraic Doubleword */
3929 case 10: /* Vector Add Single-Precision */
3930 case 74: /* Vector Subtract Single-Precision */
3931 case 1034: /* Vector Maximum Single-Precision */
3932 case 1098: /* Vector Minimum Single-Precision */
3933 case 842: /* Vector Convert From Signed Fixed-Point Word */
3934 case 778: /* Vector Convert From Unsigned Fixed-Point Word */
3935 case 714: /* Vector Round to Single-Precision Integer toward -Infinity */
3936 case 522: /* Vector Round to Single-Precision Integer Nearest */
3937 case 650: /* Vector Round to Single-Precision Integer toward +Infinity */
3938 case 586: /* Vector Round to Single-Precision Integer toward Zero */
3939 case 394: /* Vector 2 Raised to the Exponent Estimate Floating-Point */
3940 case 458: /* Vector Log Base 2 Estimate Floating-Point */
3941 case 266: /* Vector Reciprocal Estimate Single-Precision */
3942 case 330: /* Vector Reciprocal Square Root Estimate Single-Precision */
3943 case 1288: /* Vector AES Cipher */
3944 case 1289: /* Vector AES Cipher Last */
3945 case 1352: /* Vector AES Inverse Cipher */
3946 case 1353: /* Vector AES Inverse Cipher Last */
3947 case 1480: /* Vector AES SubBytes */
3948 case 1730: /* Vector SHA-512 Sigma Doubleword */
3949 case 1666: /* Vector SHA-256 Sigma Word */
3950 case 1032: /* Vector Polynomial Multiply-Sum Byte */
3951 case 1160: /* Vector Polynomial Multiply-Sum Word */
3952 case 1096: /* Vector Polynomial Multiply-Sum Halfword */
3953 case 1224: /* Vector Polynomial Multiply-Sum Doubleword */
3954 case 1292: /* Vector Gather Bits by Bytes by Doubleword */
3955 case 1794: /* Vector Count Leading Zeros Byte */
3956 case 1858: /* Vector Count Leading Zeros Halfword */
3957 case 1922: /* Vector Count Leading Zeros Word */
3958 case 1986: /* Vector Count Leading Zeros Doubleword */
3959 case 1795: /* Vector Population Count Byte */
3960 case 1859: /* Vector Population Count Halfword */
3961 case 1923: /* Vector Population Count Word */
3962 case 1987: /* Vector Population Count Doubleword */
3963 case 1356: /* Vector Bit Permute Quadword */
3964 record_full_arch_list_add_reg (regcache,
3965 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3966 return 0;
3967
3968 case 1604: /* Move To Vector Status and Control Register */
3969 record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM);
3970 return 0;
3971 case 1540: /* Move From Vector Status and Control Register */
3972 record_full_arch_list_add_reg (regcache,
3973 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3974 return 0;
3975 }
3976
810c1026
WW
3977 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
3978 "at %s, 4-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
3979 return -1;
3980}
3981
ddeca1df
WW
3982/* Parse and record instructions of primary opcode-19 at ADDR.
3983 Return 0 if successful. */
b4cdae6f
WW
3984
3985static int
3986ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
3987 CORE_ADDR addr, uint32_t insn)
3988{
3989 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3990 int ext = PPC_EXTOP (insn);
3991
3992 switch (ext)
3993 {
3994 case 0: /* Move Condition Register Field */
3995 case 33: /* Condition Register NOR */
3996 case 129: /* Condition Register AND with Complement */
3997 case 193: /* Condition Register XOR */
3998 case 225: /* Condition Register NAND */
3999 case 257: /* Condition Register AND */
4000 case 289: /* Condition Register Equivalent */
4001 case 417: /* Condition Register OR with Complement */
4002 case 449: /* Condition Register OR */
4003 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4004 return 0;
4005
4006 case 16: /* Branch Conditional */
4007 case 560: /* Branch Conditional to Branch Target Address Register */
4008 if ((PPC_BO (insn) & 0x4) == 0)
4009 record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum);
4010 /* FALL-THROUGH */
4011 case 528: /* Branch Conditional to Count Register */
4012 if (PPC_LK (insn))
4013 record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum);
4014 return 0;
4015
4016 case 150: /* Instruction Synchronize */
4017 /* Do nothing. */
4018 return 0;
4019 }
4020
810c1026
WW
4021 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4022 "at %s, 19-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4023 return -1;
4024}
4025
ddeca1df
WW
4026/* Parse and record instructions of primary opcode-31 at ADDR.
4027 Return 0 if successful. */
b4cdae6f
WW
4028
4029static int
4030ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
4031 CORE_ADDR addr, uint32_t insn)
4032{
4033 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4034 int ext = PPC_EXTOP (insn);
4035 int tmp, nr, nb, i;
4036 CORE_ADDR at_dcsz, ea = 0;
4037 ULONGEST rb, ra, xer;
4038 int size = 0;
4039
4040 /* These instructions have OE bit. */
4041 switch (ext & 0x1ff)
4042 {
4043 /* These write RT and XER. Update CR if RC is set. */
4044 case 8: /* Subtract from carrying */
4045 case 10: /* Add carrying */
4046 case 136: /* Subtract from extended */
4047 case 138: /* Add extended */
4048 case 200: /* Subtract from zero extended */
4049 case 202: /* Add to zero extended */
4050 case 232: /* Subtract from minus one extended */
4051 case 234: /* Add to minus one extended */
4052 /* CA is always altered, but SO/OV are only altered when OE=1.
4053 In any case, XER is always altered. */
4054 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4055 if (PPC_RC (insn))
4056 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4057 record_full_arch_list_add_reg (regcache,
4058 tdep->ppc_gp0_regnum + PPC_RT (insn));
4059 return 0;
4060
4061 /* These write RT. Update CR if RC is set and update XER if OE is set. */
4062 case 40: /* Subtract from */
4063 case 104: /* Negate */
4064 case 233: /* Multiply low doubleword */
4065 case 235: /* Multiply low word */
4066 case 266: /* Add */
4067 case 393: /* Divide Doubleword Extended Unsigned */
4068 case 395: /* Divide Word Extended Unsigned */
4069 case 425: /* Divide Doubleword Extended */
4070 case 427: /* Divide Word Extended */
4071 case 457: /* Divide Doubleword Unsigned */
4072 case 459: /* Divide Word Unsigned */
4073 case 489: /* Divide Doubleword */
4074 case 491: /* Divide Word */
4075 if (PPC_OE (insn))
4076 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4077 /* FALL-THROUGH */
4078 case 9: /* Multiply High Doubleword Unsigned */
4079 case 11: /* Multiply High Word Unsigned */
4080 case 73: /* Multiply High Doubleword */
4081 case 75: /* Multiply High Word */
4082 if (PPC_RC (insn))
4083 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4084 record_full_arch_list_add_reg (regcache,
4085 tdep->ppc_gp0_regnum + PPC_RT (insn));
4086 return 0;
4087 }
4088
4089 if ((ext & 0x1f) == 15)
4090 {
4091 /* Integer Select. bit[16:20] is used for BC. */
4092 record_full_arch_list_add_reg (regcache,
4093 tdep->ppc_gp0_regnum + PPC_RT (insn));
4094 return 0;
4095 }
4096
4097 switch (ext)
4098 {
4099 case 78: /* Determine Leftmost Zero Byte */
4100 if (PPC_RC (insn))
4101 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4102 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4103 record_full_arch_list_add_reg (regcache,
4104 tdep->ppc_gp0_regnum + PPC_RT (insn));
4105 return 0;
4106
4107 /* These only write RT. */
4108 case 19: /* Move from condition register */
4109 /* Move From One Condition Register Field */
4110 case 74: /* Add and Generate Sixes */
4111 case 74 | 0x200: /* Add and Generate Sixes (bit-21 dont-care) */
4112 case 302: /* Move From Branch History Rolling Buffer */
4113 case 339: /* Move From Special Purpose Register */
4114 case 371: /* Move From Time Base [Phased-Out] */
4115 record_full_arch_list_add_reg (regcache,
4116 tdep->ppc_gp0_regnum + PPC_RT (insn));
4117 return 0;
4118
4119 /* These only write to RA. */
4120 case 51: /* Move From VSR Doubleword */
4121 case 115: /* Move From VSR Word and Zero */
4122 case 122: /* Population count bytes */
4123 case 378: /* Population count words */
4124 case 506: /* Population count doublewords */
4125 case 154: /* Parity Word */
4126 case 186: /* Parity Doubleword */
4127 case 252: /* Bit Permute Doubleword */
4128 case 282: /* Convert Declets To Binary Coded Decimal */
4129 case 314: /* Convert Binary Coded Decimal To Declets */
4130 case 508: /* Compare bytes */
4131 record_full_arch_list_add_reg (regcache,
4132 tdep->ppc_gp0_regnum + PPC_RA (insn));
4133 return 0;
4134
4135 /* These write CR and optional RA. */
4136 case 792: /* Shift Right Algebraic Word */
4137 case 794: /* Shift Right Algebraic Doubleword */
4138 case 824: /* Shift Right Algebraic Word Immediate */
4139 case 826: /* Shift Right Algebraic Doubleword Immediate (413) */
4140 case 826 | 1: /* Shift Right Algebraic Doubleword Immediate (413) */
4141 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4142 record_full_arch_list_add_reg (regcache,
4143 tdep->ppc_gp0_regnum + PPC_RA (insn));
4144 /* FALL-THROUGH */
4145 case 0: /* Compare */
4146 case 32: /* Compare logical */
4147 case 144: /* Move To Condition Register Fields */
4148 /* Move To One Condition Register Field */
4149 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4150 return 0;
4151
4152 /* These write to RT. Update RA if 'update indexed.' */
4153 case 53: /* Load Doubleword with Update Indexed */
4154 case 119: /* Load Byte and Zero with Update Indexed */
4155 case 311: /* Load Halfword and Zero with Update Indexed */
4156 case 55: /* Load Word and Zero with Update Indexed */
4157 case 375: /* Load Halfword Algebraic with Update Indexed */
4158 case 373: /* Load Word Algebraic with Update Indexed */
4159 record_full_arch_list_add_reg (regcache,
4160 tdep->ppc_gp0_regnum + PPC_RA (insn));
4161 /* FALL-THROUGH */
4162 case 21: /* Load Doubleword Indexed */
4163 case 52: /* Load Byte And Reserve Indexed */
4164 case 116: /* Load Halfword And Reserve Indexed */
4165 case 20: /* Load Word And Reserve Indexed */
4166 case 84: /* Load Doubleword And Reserve Indexed */
4167 case 87: /* Load Byte and Zero Indexed */
4168 case 279: /* Load Halfword and Zero Indexed */
4169 case 23: /* Load Word and Zero Indexed */
4170 case 343: /* Load Halfword Algebraic Indexed */
4171 case 341: /* Load Word Algebraic Indexed */
4172 case 790: /* Load Halfword Byte-Reverse Indexed */
4173 case 534: /* Load Word Byte-Reverse Indexed */
4174 case 532: /* Load Doubleword Byte-Reverse Indexed */
4175 record_full_arch_list_add_reg (regcache,
4176 tdep->ppc_gp0_regnum + PPC_RT (insn));
4177 return 0;
4178
4179 case 597: /* Load String Word Immediate */
4180 case 533: /* Load String Word Indexed */
4181 if (ext == 597)
4182 {
4183 nr = PPC_NB (insn);
4184 if (nr == 0)
4185 nr = 32;
4186 }
4187 else
4188 {
4189 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &xer);
4190 nr = PPC_XER_NB (xer);
4191 }
4192
4193 nr = (nr + 3) >> 2;
4194
4195 /* If n=0, the contents of register RT are undefined. */
4196 if (nr == 0)
4197 nr = 1;
4198
4199 for (i = 0; i < nr; i++)
4200 record_full_arch_list_add_reg (regcache,
4201 tdep->ppc_gp0_regnum
4202 + ((PPC_RT (insn) + i) & 0x1f));
4203 return 0;
4204
4205 case 276: /* Load Quadword And Reserve Indexed */
4206 tmp = tdep->ppc_gp0_regnum + (PPC_RT (insn) & ~1);
4207 record_full_arch_list_add_reg (regcache, tmp);
4208 record_full_arch_list_add_reg (regcache, tmp + 1);
4209 return 0;
4210
4211 /* These write VRT. */
4212 case 6: /* Load Vector for Shift Left Indexed */
4213 case 38: /* Load Vector for Shift Right Indexed */
4214 case 7: /* Load Vector Element Byte Indexed */
4215 case 39: /* Load Vector Element Halfword Indexed */
4216 case 71: /* Load Vector Element Word Indexed */
4217 case 103: /* Load Vector Indexed */
4218 case 359: /* Load Vector Indexed LRU */
4219 record_full_arch_list_add_reg (regcache,
4220 tdep->ppc_vr0_regnum + PPC_VRT (insn));
4221 return 0;
4222
4223 /* These write FRT. Update RA if 'update indexed.' */
4224 case 567: /* Load Floating-Point Single with Update Indexed */
4225 case 631: /* Load Floating-Point Double with Update Indexed */
4226 record_full_arch_list_add_reg (regcache,
4227 tdep->ppc_gp0_regnum + PPC_RA (insn));
4228 /* FALL-THROUGH */
4229 case 535: /* Load Floating-Point Single Indexed */
4230 case 599: /* Load Floating-Point Double Indexed */
4231 case 855: /* Load Floating-Point as Integer Word Algebraic Indexed */
4232 case 887: /* Load Floating-Point as Integer Word and Zero Indexed */
4233 record_full_arch_list_add_reg (regcache,
4234 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4235 return 0;
4236
4237 case 791: /* Load Floating-Point Double Pair Indexed */
4238 tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1);
4239 record_full_arch_list_add_reg (regcache, tmp);
4240 record_full_arch_list_add_reg (regcache, tmp + 1);
4241 return 0;
4242
4243 case 179: /* Move To VSR Doubleword */
4244 case 211: /* Move To VSR Word Algebraic */
4245 case 243: /* Move To VSR Word and Zero */
4246 case 588: /* Load VSX Scalar Doubleword Indexed */
4247 case 524: /* Load VSX Scalar Single-Precision Indexed */
4248 case 76: /* Load VSX Scalar as Integer Word Algebraic Indexed */
4249 case 12: /* Load VSX Scalar as Integer Word and Zero Indexed */
4250 case 844: /* Load VSX Vector Doubleword*2 Indexed */
4251 case 332: /* Load VSX Vector Doubleword & Splat Indexed */
4252 case 780: /* Load VSX Vector Word*4 Indexed */
4253 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4254 return 0;
4255
4256 /* These write RA. Update CR if RC is set. */
4257 case 24: /* Shift Left Word */
4258 case 26: /* Count Leading Zeros Word */
4259 case 27: /* Shift Left Doubleword */
4260 case 28: /* AND */
4261 case 58: /* Count Leading Zeros Doubleword */
4262 case 60: /* AND with Complement */
4263 case 124: /* NOR */
4264 case 284: /* Equivalent */
4265 case 316: /* XOR */
4266 case 476: /* NAND */
4267 case 412: /* OR with Complement */
4268 case 444: /* OR */
4269 case 536: /* Shift Right Word */
4270 case 539: /* Shift Right Doubleword */
4271 case 922: /* Extend Sign Halfword */
4272 case 954: /* Extend Sign Byte */
4273 case 986: /* Extend Sign Word */
4274 if (PPC_RC (insn))
4275 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4276 record_full_arch_list_add_reg (regcache,
4277 tdep->ppc_gp0_regnum + PPC_RA (insn));
4278 return 0;
4279
4280 /* Store memory. */
4281 case 181: /* Store Doubleword with Update Indexed */
4282 case 183: /* Store Word with Update Indexed */
4283 case 247: /* Store Byte with Update Indexed */
4284 case 439: /* Store Half Word with Update Indexed */
4285 case 695: /* Store Floating-Point Single with Update Indexed */
4286 case 759: /* Store Floating-Point Double with Update Indexed */
4287 record_full_arch_list_add_reg (regcache,
4288 tdep->ppc_gp0_regnum + PPC_RA (insn));
4289 /* FALL-THROUGH */
4290 case 135: /* Store Vector Element Byte Indexed */
4291 case 167: /* Store Vector Element Halfword Indexed */
4292 case 199: /* Store Vector Element Word Indexed */
4293 case 231: /* Store Vector Indexed */
4294 case 487: /* Store Vector Indexed LRU */
4295 case 716: /* Store VSX Scalar Doubleword Indexed */
4296 case 140: /* Store VSX Scalar as Integer Word Indexed */
4297 case 652: /* Store VSX Scalar Single-Precision Indexed */
4298 case 972: /* Store VSX Vector Doubleword*2 Indexed */
4299 case 908: /* Store VSX Vector Word*4 Indexed */
4300 case 149: /* Store Doubleword Indexed */
4301 case 151: /* Store Word Indexed */
4302 case 215: /* Store Byte Indexed */
4303 case 407: /* Store Half Word Indexed */
4304 case 694: /* Store Byte Conditional Indexed */
4305 case 726: /* Store Halfword Conditional Indexed */
4306 case 150: /* Store Word Conditional Indexed */
4307 case 214: /* Store Doubleword Conditional Indexed */
4308 case 182: /* Store Quadword Conditional Indexed */
4309 case 662: /* Store Word Byte-Reverse Indexed */
4310 case 918: /* Store Halfword Byte-Reverse Indexed */
4311 case 660: /* Store Doubleword Byte-Reverse Indexed */
4312 case 663: /* Store Floating-Point Single Indexed */
4313 case 727: /* Store Floating-Point Double Indexed */
4314 case 919: /* Store Floating-Point Double Pair Indexed */
4315 case 983: /* Store Floating-Point as Integer Word Indexed */
4316 if (ext == 694 || ext == 726 || ext == 150 || ext == 214 || ext == 182)
4317 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4318
4319 ra = 0;
4320 if (PPC_RA (insn) != 0)
4321 regcache_raw_read_unsigned (regcache,
4322 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
4323 regcache_raw_read_unsigned (regcache,
4324 tdep->ppc_gp0_regnum + PPC_RB (insn), &rb);
4325 ea = ra + rb;
4326
4327 switch (ext)
4328 {
4329 case 183: /* Store Word with Update Indexed */
4330 case 199: /* Store Vector Element Word Indexed */
4331 case 140: /* Store VSX Scalar as Integer Word Indexed */
4332 case 652: /* Store VSX Scalar Single-Precision Indexed */
4333 case 151: /* Store Word Indexed */
4334 case 150: /* Store Word Conditional Indexed */
4335 case 662: /* Store Word Byte-Reverse Indexed */
4336 case 663: /* Store Floating-Point Single Indexed */
4337 case 695: /* Store Floating-Point Single with Update Indexed */
4338 case 983: /* Store Floating-Point as Integer Word Indexed */
4339 size = 4;
4340 break;
4341 case 247: /* Store Byte with Update Indexed */
4342 case 135: /* Store Vector Element Byte Indexed */
4343 case 215: /* Store Byte Indexed */
4344 case 694: /* Store Byte Conditional Indexed */
4345 size = 1;
4346 break;
4347 case 439: /* Store Halfword with Update Indexed */
4348 case 167: /* Store Vector Element Halfword Indexed */
4349 case 407: /* Store Halfword Indexed */
4350 case 726: /* Store Halfword Conditional Indexed */
4351 case 918: /* Store Halfword Byte-Reverse Indexed */
4352 size = 2;
4353 break;
4354 case 181: /* Store Doubleword with Update Indexed */
4355 case 716: /* Store VSX Scalar Doubleword Indexed */
4356 case 149: /* Store Doubleword Indexed */
4357 case 214: /* Store Doubleword Conditional Indexed */
4358 case 660: /* Store Doubleword Byte-Reverse Indexed */
4359 case 727: /* Store Floating-Point Double Indexed */
4360 case 759: /* Store Floating-Point Double with Update Indexed */
4361 size = 8;
4362 break;
4363 case 972: /* Store VSX Vector Doubleword*2 Indexed */
4364 case 908: /* Store VSX Vector Word*4 Indexed */
4365 case 182: /* Store Quadword Conditional Indexed */
4366 case 231: /* Store Vector Indexed */
4367 case 487: /* Store Vector Indexed LRU */
4368 case 919: /* Store Floating-Point Double Pair Indexed */
4369 size = 16;
4370 break;
4371 default:
4372 gdb_assert (0);
4373 }
4374
4375 /* Align address for Store Vector instructions. */
4376 switch (ext)
4377 {
4378 case 167: /* Store Vector Element Halfword Indexed */
4379 addr = addr & ~0x1ULL;
4380 break;
4381
4382 case 199: /* Store Vector Element Word Indexed */
4383 addr = addr & ~0x3ULL;
4384 break;
4385
4386 case 231: /* Store Vector Indexed */
4387 case 487: /* Store Vector Indexed LRU */
4388 addr = addr & ~0xfULL;
4389 break;
4390 }
4391
4392 record_full_arch_list_add_mem (addr, size);
4393 return 0;
4394
4395 case 725: /* Store String Word Immediate */
4396 ra = 0;
4397 if (PPC_RA (insn) != 0)
4398 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &ra);
4399 ea += ra;
4400
4401 nb = PPC_NB (insn);
4402 if (nb == 0)
4403 nb = 32;
4404
4405 record_full_arch_list_add_mem (ea, nb);
4406
4407 return 0;
4408
4409 case 661: /* Store String Word Indexed */
4410 ra = 0;
4411 if (PPC_RA (insn) != 0)
4412 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &ra);
4413 ea += ra;
4414
4415 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &xer);
4416 nb = PPC_XER_NB (xer);
4417
4418 if (nb != 0)
4419 {
4420 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &rb);
4421 ea += rb;
4422 record_full_arch_list_add_mem (ea, nb);
4423 }
4424
4425 return 0;
4426
4427 case 467: /* Move To Special Purpose Register */
4428 switch (PPC_SPR (insn))
4429 {
4430 case 1: /* XER */
4431 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4432 return 0;
4433 case 8: /* LR */
4434 record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum);
4435 return 0;
4436 case 9: /* CTR */
4437 record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum);
4438 return 0;
4439 case 256: /* VRSAVE */
4440 record_full_arch_list_add_reg (regcache, tdep->ppc_vrsave_regnum);
4441 return 0;
4442 }
4443
4444 goto UNKNOWN_OP;
4445
4446 case 147: /* Move To Split Little Endian */
4447 record_full_arch_list_add_reg (regcache, tdep->ppc_ps_regnum);
4448 return 0;
4449
4450 case 512: /* Move to Condition Register from XER */
4451 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4452 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4453 return 0;
4454
4455 case 4: /* Trap Word */
4456 case 68: /* Trap Doubleword */
4457 case 430: /* Clear BHRB */
4458 case 598: /* Synchronize */
4459 case 62: /* Wait for Interrupt */
4460 case 22: /* Instruction Cache Block Touch */
4461 case 854: /* Enforce In-order Execution of I/O */
4462 case 246: /* Data Cache Block Touch for Store */
4463 case 54: /* Data Cache Block Store */
4464 case 86: /* Data Cache Block Flush */
4465 case 278: /* Data Cache Block Touch */
4466 case 758: /* Data Cache Block Allocate */
4467 case 982: /* Instruction Cache Block Invalidate */
4468 return 0;
4469
4470 case 654: /* Transaction Begin */
4471 case 686: /* Transaction End */
4472 case 718: /* Transaction Check */
4473 case 750: /* Transaction Suspend or Resume */
4474 case 782: /* Transaction Abort Word Conditional */
4475 case 814: /* Transaction Abort Doubleword Conditional */
4476 case 846: /* Transaction Abort Word Conditional Immediate */
4477 case 878: /* Transaction Abort Doubleword Conditional Immediate */
4478 case 910: /* Transaction Abort */
4479 fprintf_unfiltered (gdb_stdlog, "Cannot record Transaction instructions. "
810c1026
WW
4480 "%08x at %s, 31-%d.\n",
4481 insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4482 return -1;
4483
4484 case 1014: /* Data Cache Block set to Zero */
4485 if (target_auxv_search (&current_target, AT_DCACHEBSIZE, &at_dcsz) <= 0
4486 || at_dcsz == 0)
4487 at_dcsz = 128; /* Assume 128-byte cache line size (POWER8) */
4488
4489 if (PPC_RA (insn) != 0)
4490 regcache_raw_read_unsigned (regcache,
4491 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
4492 regcache_raw_read_unsigned (regcache,
4493 tdep->ppc_gp0_regnum + PPC_RB (insn), &rb);
4494 ea = (ra + rb) & ~((ULONGEST) (at_dcsz - 1));
4495 record_full_arch_list_add_mem (ea, at_dcsz);
4496 return 0;
4497 }
4498
4499UNKNOWN_OP:
810c1026
WW
4500 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4501 "at %s, 31-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4502 return -1;
4503}
4504
ddeca1df
WW
4505/* Parse and record instructions of primary opcode-59 at ADDR.
4506 Return 0 if successful. */
b4cdae6f
WW
4507
4508static int
4509ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
4510 CORE_ADDR addr, uint32_t insn)
4511{
4512 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4513 int ext = PPC_EXTOP (insn);
4514
4515 switch (ext & 0x1f)
4516 {
4517 case 18: /* Floating Divide */
4518 case 20: /* Floating Subtract */
4519 case 21: /* Floating Add */
4520 case 22: /* Floating Square Root */
4521 case 24: /* Floating Reciprocal Estimate */
4522 case 25: /* Floating Multiply */
4523 case 26: /* Floating Reciprocal Square Root Estimate */
4524 case 28: /* Floating Multiply-Subtract */
4525 case 29: /* Floating Multiply-Add */
4526 case 30: /* Floating Negative Multiply-Subtract */
4527 case 31: /* Floating Negative Multiply-Add */
4528 record_full_arch_list_add_reg (regcache,
4529 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4530 if (PPC_RC (insn))
4531 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4532 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4533
4534 return 0;
4535 }
4536
4537 switch (ext)
4538 {
4539 case 2: /* DFP Add */
4540 case 3: /* DFP Quantize */
4541 case 34: /* DFP Multiply */
4542 case 35: /* DFP Reround */
4543 case 67: /* DFP Quantize Immediate */
4544 case 99: /* DFP Round To FP Integer With Inexact */
4545 case 227: /* DFP Round To FP Integer Without Inexact */
4546 case 258: /* DFP Convert To DFP Long! */
4547 case 290: /* DFP Convert To Fixed */
4548 case 514: /* DFP Subtract */
4549 case 546: /* DFP Divide */
4550 case 770: /* DFP Round To DFP Short! */
4551 case 802: /* DFP Convert From Fixed */
4552 case 834: /* DFP Encode BCD To DPD */
4553 if (PPC_RC (insn))
4554 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4555 record_full_arch_list_add_reg (regcache,
4556 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4557 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4558 return 0;
4559
4560 case 130: /* DFP Compare Ordered */
4561 case 162: /* DFP Test Exponent */
4562 case 194: /* DFP Test Data Class */
4563 case 226: /* DFP Test Data Group */
4564 case 642: /* DFP Compare Unordered */
4565 case 674: /* DFP Test Significance */
4566 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4567 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4568 return 0;
4569
4570 case 66: /* DFP Shift Significand Left Immediate */
4571 case 98: /* DFP Shift Significand Right Immediate */
4572 case 322: /* DFP Decode DPD To BCD */
4573 case 354: /* DFP Extract Biased Exponent */
4574 case 866: /* DFP Insert Biased Exponent */
4575 record_full_arch_list_add_reg (regcache,
4576 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4577 if (PPC_RC (insn))
4578 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4579 return 0;
4580
4581 case 846: /* Floating Convert From Integer Doubleword Single */
4582 case 974: /* Floating Convert From Integer Doubleword Unsigned
4583 Single */
4584 record_full_arch_list_add_reg (regcache,
4585 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4586 if (PPC_RC (insn))
4587 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4588 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4589
4590 return 0;
4591 }
4592
810c1026
WW
4593 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4594 "at %s, 59-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4595 return -1;
4596}
4597
ddeca1df
WW
4598/* Parse and record instructions of primary opcode-60 at ADDR.
4599 Return 0 if successful. */
b4cdae6f
WW
4600
4601static int
4602ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
4603 CORE_ADDR addr, uint32_t insn)
4604{
4605 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4606 int ext = PPC_EXTOP (insn);
b4cdae6f
WW
4607
4608 switch (ext >> 2)
4609 {
4610 case 0: /* VSX Scalar Add Single-Precision */
4611 case 32: /* VSX Scalar Add Double-Precision */
4612 case 24: /* VSX Scalar Divide Single-Precision */
4613 case 56: /* VSX Scalar Divide Double-Precision */
4614 case 176: /* VSX Scalar Copy Sign Double-Precision */
4615 case 33: /* VSX Scalar Multiply-Add Double-Precision */
4616 case 41: /* ditto */
4617 case 1: /* VSX Scalar Multiply-Add Single-Precision */
4618 case 9: /* ditto */
4619 case 160: /* VSX Scalar Maximum Double-Precision */
4620 case 168: /* VSX Scalar Minimum Double-Precision */
4621 case 49: /* VSX Scalar Multiply-Subtract Double-Precision */
4622 case 57: /* ditto */
4623 case 17: /* VSX Scalar Multiply-Subtract Single-Precision */
4624 case 25: /* ditto */
4625 case 48: /* VSX Scalar Multiply Double-Precision */
4626 case 16: /* VSX Scalar Multiply Single-Precision */
4627 case 161: /* VSX Scalar Negative Multiply-Add Double-Precision */
4628 case 169: /* ditto */
4629 case 129: /* VSX Scalar Negative Multiply-Add Single-Precision */
4630 case 137: /* ditto */
4631 case 177: /* VSX Scalar Negative Multiply-Subtract Double-Precision */
4632 case 185: /* ditto */
4633 case 145: /* VSX Scalar Negative Multiply-Subtract Single-Precision */
4634 case 153: /* ditto */
4635 case 40: /* VSX Scalar Subtract Double-Precision */
4636 case 8: /* VSX Scalar Subtract Single-Precision */
4637 case 96: /* VSX Vector Add Double-Precision */
4638 case 64: /* VSX Vector Add Single-Precision */
4639 case 120: /* VSX Vector Divide Double-Precision */
4640 case 88: /* VSX Vector Divide Single-Precision */
4641 case 97: /* VSX Vector Multiply-Add Double-Precision */
4642 case 105: /* ditto */
4643 case 65: /* VSX Vector Multiply-Add Single-Precision */
4644 case 73: /* ditto */
4645 case 224: /* VSX Vector Maximum Double-Precision */
4646 case 192: /* VSX Vector Maximum Single-Precision */
4647 case 232: /* VSX Vector Minimum Double-Precision */
4648 case 200: /* VSX Vector Minimum Single-Precision */
4649 case 113: /* VSX Vector Multiply-Subtract Double-Precision */
4650 case 121: /* ditto */
4651 case 81: /* VSX Vector Multiply-Subtract Single-Precision */
4652 case 89: /* ditto */
4653 case 112: /* VSX Vector Multiply Double-Precision */
4654 case 80: /* VSX Vector Multiply Single-Precision */
4655 case 225: /* VSX Vector Negative Multiply-Add Double-Precision */
4656 case 233: /* ditto */
4657 case 193: /* VSX Vector Negative Multiply-Add Single-Precision */
4658 case 201: /* ditto */
4659 case 241: /* VSX Vector Negative Multiply-Subtract Double-Precision */
4660 case 249: /* ditto */
4661 case 209: /* VSX Vector Negative Multiply-Subtract Single-Precision */
4662 case 217: /* ditto */
4663 case 104: /* VSX Vector Subtract Double-Precision */
4664 case 72: /* VSX Vector Subtract Single-Precision */
4665 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4666 case 240: /* VSX Vector Copy Sign Double-Precision */
4667 case 208: /* VSX Vector Copy Sign Single-Precision */
4668 case 130: /* VSX Logical AND */
4669 case 138: /* VSX Logical AND with Complement */
4670 case 186: /* VSX Logical Equivalence */
4671 case 178: /* VSX Logical NAND */
4672 case 170: /* VSX Logical OR with Complement */
4673 case 162: /* VSX Logical NOR */
4674 case 146: /* VSX Logical OR */
4675 case 154: /* VSX Logical XOR */
4676 case 18: /* VSX Merge High Word */
4677 case 50: /* VSX Merge Low Word */
4678 case 10: /* VSX Permute Doubleword Immediate (DM=0) */
4679 case 10 | 0x20: /* VSX Permute Doubleword Immediate (DM=1) */
4680 case 10 | 0x40: /* VSX Permute Doubleword Immediate (DM=2) */
4681 case 10 | 0x60: /* VSX Permute Doubleword Immediate (DM=3) */
4682 case 2: /* VSX Shift Left Double by Word Immediate (SHW=0) */
4683 case 2 | 0x20: /* VSX Shift Left Double by Word Immediate (SHW=1) */
4684 case 2 | 0x40: /* VSX Shift Left Double by Word Immediate (SHW=2) */
4685 case 2 | 0x60: /* VSX Shift Left Double by Word Immediate (SHW=3) */
4686 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4687 return 0;
4688
4689 case 61: /* VSX Scalar Test for software Divide Double-Precision */
4690 case 125: /* VSX Vector Test for software Divide Double-Precision */
4691 case 93: /* VSX Vector Test for software Divide Single-Precision */
4692 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4693 return 0;
4694
4695 case 35: /* VSX Scalar Compare Unordered Double-Precision */
4696 case 43: /* VSX Scalar Compare Ordered Double-Precision */
4697 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4698 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4699 return 0;
4700 }
4701
4702 switch ((ext >> 2) & 0x7f) /* Mask out Rc-bit. */
4703 {
4704 case 99: /* VSX Vector Compare Equal To Double-Precision */
4705 case 67: /* VSX Vector Compare Equal To Single-Precision */
4706 case 115: /* VSX Vector Compare Greater Than or
4707 Equal To Double-Precision */
4708 case 83: /* VSX Vector Compare Greater Than or
4709 Equal To Single-Precision */
4710 case 107: /* VSX Vector Compare Greater Than Double-Precision */
4711 case 75: /* VSX Vector Compare Greater Than Single-Precision */
4712 if (PPC_Rc (insn))
4713 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4714 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4715 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4716 return 0;
4717 }
4718
4719 switch (ext >> 1)
4720 {
4721 case 265: /* VSX Scalar round Double-Precision to
4722 Single-Precision and Convert to
4723 Single-Precision format */
4724 case 344: /* VSX Scalar truncate Double-Precision to
4725 Integer and Convert to Signed Integer
4726 Doubleword format with Saturate */
4727 case 88: /* VSX Scalar truncate Double-Precision to
4728 Integer and Convert to Signed Integer Word
4729 Format with Saturate */
4730 case 328: /* VSX Scalar truncate Double-Precision integer
4731 and Convert to Unsigned Integer Doubleword
4732 Format with Saturate */
4733 case 72: /* VSX Scalar truncate Double-Precision to
4734 Integer and Convert to Unsigned Integer Word
4735 Format with Saturate */
4736 case 329: /* VSX Scalar Convert Single-Precision to
4737 Double-Precision format */
4738 case 376: /* VSX Scalar Convert Signed Integer
4739 Doubleword to floating-point format and
4740 Round to Double-Precision format */
4741 case 312: /* VSX Scalar Convert Signed Integer
4742 Doubleword to floating-point format and
4743 round to Single-Precision */
4744 case 360: /* VSX Scalar Convert Unsigned Integer
4745 Doubleword to floating-point format and
4746 Round to Double-Precision format */
4747 case 296: /* VSX Scalar Convert Unsigned Integer
4748 Doubleword to floating-point format and
4749 Round to Single-Precision */
4750 case 73: /* VSX Scalar Round to Double-Precision Integer
4751 Using Round to Nearest Away */
4752 case 107: /* VSX Scalar Round to Double-Precision Integer
4753 Exact using Current rounding mode */
4754 case 121: /* VSX Scalar Round to Double-Precision Integer
4755 Using Round toward -Infinity */
4756 case 105: /* VSX Scalar Round to Double-Precision Integer
4757 Using Round toward +Infinity */
4758 case 89: /* VSX Scalar Round to Double-Precision Integer
4759 Using Round toward Zero */
4760 case 90: /* VSX Scalar Reciprocal Estimate Double-Precision */
4761 case 26: /* VSX Scalar Reciprocal Estimate Single-Precision */
4762 case 281: /* VSX Scalar Round to Single-Precision */
4763 case 74: /* VSX Scalar Reciprocal Square Root Estimate
4764 Double-Precision */
4765 case 10: /* VSX Scalar Reciprocal Square Root Estimate
4766 Single-Precision */
4767 case 75: /* VSX Scalar Square Root Double-Precision */
4768 case 11: /* VSX Scalar Square Root Single-Precision */
4769 case 393: /* VSX Vector round Double-Precision to
4770 Single-Precision and Convert to
4771 Single-Precision format */
4772 case 472: /* VSX Vector truncate Double-Precision to
4773 Integer and Convert to Signed Integer
4774 Doubleword format with Saturate */
4775 case 216: /* VSX Vector truncate Double-Precision to
4776 Integer and Convert to Signed Integer Word
4777 Format with Saturate */
4778 case 456: /* VSX Vector truncate Double-Precision to
4779 Integer and Convert to Unsigned Integer
4780 Doubleword format with Saturate */
4781 case 200: /* VSX Vector truncate Double-Precision to
4782 Integer and Convert to Unsigned Integer Word
4783 Format with Saturate */
4784 case 457: /* VSX Vector Convert Single-Precision to
4785 Double-Precision format */
4786 case 408: /* VSX Vector truncate Single-Precision to
4787 Integer and Convert to Signed Integer
4788 Doubleword format with Saturate */
4789 case 152: /* VSX Vector truncate Single-Precision to
4790 Integer and Convert to Signed Integer Word
4791 Format with Saturate */
4792 case 392: /* VSX Vector truncate Single-Precision to
4793 Integer and Convert to Unsigned Integer
4794 Doubleword format with Saturate */
4795 case 136: /* VSX Vector truncate Single-Precision to
4796 Integer and Convert to Unsigned Integer Word
4797 Format with Saturate */
4798 case 504: /* VSX Vector Convert and round Signed Integer
4799 Doubleword to Double-Precision format */
4800 case 440: /* VSX Vector Convert and round Signed Integer
4801 Doubleword to Single-Precision format */
4802 case 248: /* VSX Vector Convert Signed Integer Word to
4803 Double-Precision format */
4804 case 184: /* VSX Vector Convert and round Signed Integer
4805 Word to Single-Precision format */
4806 case 488: /* VSX Vector Convert and round Unsigned
4807 Integer Doubleword to Double-Precision format */
4808 case 424: /* VSX Vector Convert and round Unsigned
4809 Integer Doubleword to Single-Precision format */
4810 case 232: /* VSX Vector Convert and round Unsigned
4811 Integer Word to Double-Precision format */
4812 case 168: /* VSX Vector Convert and round Unsigned
4813 Integer Word to Single-Precision format */
4814 case 201: /* VSX Vector Round to Double-Precision
4815 Integer using round to Nearest Away */
4816 case 235: /* VSX Vector Round to Double-Precision
4817 Integer Exact using Current rounding mode */
4818 case 249: /* VSX Vector Round to Double-Precision
4819 Integer using round toward -Infinity */
4820 case 233: /* VSX Vector Round to Double-Precision
4821 Integer using round toward +Infinity */
4822 case 217: /* VSX Vector Round to Double-Precision
4823 Integer using round toward Zero */
4824 case 218: /* VSX Vector Reciprocal Estimate Double-Precision */
4825 case 154: /* VSX Vector Reciprocal Estimate Single-Precision */
4826 case 137: /* VSX Vector Round to Single-Precision Integer
4827 Using Round to Nearest Away */
4828 case 171: /* VSX Vector Round to Single-Precision Integer
4829 Exact Using Current rounding mode */
4830 case 185: /* VSX Vector Round to Single-Precision Integer
4831 Using Round toward -Infinity */
4832 case 169: /* VSX Vector Round to Single-Precision Integer
4833 Using Round toward +Infinity */
4834 case 153: /* VSX Vector Round to Single-Precision Integer
4835 Using round toward Zero */
4836 case 202: /* VSX Vector Reciprocal Square Root Estimate
4837 Double-Precision */
4838 case 138: /* VSX Vector Reciprocal Square Root Estimate
4839 Single-Precision */
4840 case 203: /* VSX Vector Square Root Double-Precision */
4841 case 139: /* VSX Vector Square Root Single-Precision */
4842 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4843 case 345: /* VSX Scalar Absolute Value Double-Precision */
4844 case 267: /* VSX Scalar Convert Scalar Single-Precision to
4845 Vector Single-Precision format Non-signalling */
4846 case 331: /* VSX Scalar Convert Single-Precision to
4847 Double-Precision format Non-signalling */
4848 case 361: /* VSX Scalar Negative Absolute Value Double-Precision */
4849 case 377: /* VSX Scalar Negate Double-Precision */
4850 case 473: /* VSX Vector Absolute Value Double-Precision */
4851 case 409: /* VSX Vector Absolute Value Single-Precision */
4852 case 489: /* VSX Vector Negative Absolute Value Double-Precision */
4853 case 425: /* VSX Vector Negative Absolute Value Single-Precision */
4854 case 505: /* VSX Vector Negate Double-Precision */
4855 case 441: /* VSX Vector Negate Single-Precision */
4856 case 164: /* VSX Splat Word */
4857 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4858 return 0;
4859
4860 case 106: /* VSX Scalar Test for software Square Root
4861 Double-Precision */
4862 case 234: /* VSX Vector Test for software Square Root
4863 Double-Precision */
4864 case 170: /* VSX Vector Test for software Square Root
4865 Single-Precision */
4866 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4867 return 0;
4868 }
4869
4870 if (((ext >> 3) & 0x3) == 3) /* VSX Select */
4871 {
4872 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4873 return 0;
4874 }
4875
810c1026
WW
4876 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4877 "at %s, 60-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4878 return -1;
4879}
4880
ddeca1df
WW
4881/* Parse and record instructions of primary opcode-63 at ADDR.
4882 Return 0 if successful. */
b4cdae6f
WW
4883
4884static int
4885ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
4886 CORE_ADDR addr, uint32_t insn)
4887{
4888 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4889 int ext = PPC_EXTOP (insn);
4890 int tmp;
4891
4892 switch (ext & 0x1f)
4893 {
4894 case 18: /* Floating Divide */
4895 case 20: /* Floating Subtract */
4896 case 21: /* Floating Add */
4897 case 22: /* Floating Square Root */
4898 case 24: /* Floating Reciprocal Estimate */
4899 case 25: /* Floating Multiply */
4900 case 26: /* Floating Reciprocal Square Root Estimate */
4901 case 28: /* Floating Multiply-Subtract */
4902 case 29: /* Floating Multiply-Add */
4903 case 30: /* Floating Negative Multiply-Subtract */
4904 case 31: /* Floating Negative Multiply-Add */
4905 record_full_arch_list_add_reg (regcache,
4906 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4907 if (PPC_RC (insn))
4908 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4909 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4910 return 0;
4911
4912 case 23: /* Floating Select */
4913 record_full_arch_list_add_reg (regcache,
4914 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4915 if (PPC_RC (insn))
4916 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4917 }
4918
4919 switch (ext)
4920 {
4921 case 2: /* DFP Add Quad */
4922 case 3: /* DFP Quantize Quad */
4923 case 34: /* DFP Multiply Quad */
4924 case 35: /* DFP Reround Quad */
4925 case 67: /* DFP Quantize Immediate Quad */
4926 case 99: /* DFP Round To FP Integer With Inexact Quad */
4927 case 227: /* DFP Round To FP Integer Without Inexact Quad */
4928 case 258: /* DFP Convert To DFP Extended Quad */
4929 case 514: /* DFP Subtract Quad */
4930 case 546: /* DFP Divide Quad */
4931 case 770: /* DFP Round To DFP Long Quad */
4932 case 802: /* DFP Convert From Fixed Quad */
4933 case 834: /* DFP Encode BCD To DPD Quad */
4934 if (PPC_RC (insn))
4935 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4936 tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1);
4937 record_full_arch_list_add_reg (regcache, tmp);
4938 record_full_arch_list_add_reg (regcache, tmp + 1);
4939 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4940 return 0;
4941
4942 case 130: /* DFP Compare Ordered Quad */
4943 case 162: /* DFP Test Exponent Quad */
4944 case 194: /* DFP Test Data Class Quad */
4945 case 226: /* DFP Test Data Group Quad */
4946 case 642: /* DFP Compare Unordered Quad */
4947 case 674: /* DFP Test Significance Quad */
4948 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4949 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4950 return 0;
4951
4952 case 66: /* DFP Shift Significand Left Immediate Quad */
4953 case 98: /* DFP Shift Significand Right Immediate Quad */
4954 case 322: /* DFP Decode DPD To BCD Quad */
4955 case 866: /* DFP Insert Biased Exponent Quad */
4956 tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1);
4957 record_full_arch_list_add_reg (regcache, tmp);
4958 record_full_arch_list_add_reg (regcache, tmp + 1);
4959 if (PPC_RC (insn))
4960 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4961 return 0;
4962
4963 case 290: /* DFP Convert To Fixed Quad */
4964 record_full_arch_list_add_reg (regcache,
4965 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4966 if (PPC_RC (insn))
4967 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4968 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4969 break;
4970
4971 case 354: /* DFP Extract Biased Exponent Quad */
4972 record_full_arch_list_add_reg (regcache,
4973 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4974 if (PPC_RC (insn))
4975 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4976 return 0;
4977
4978 case 12: /* Floating Round to Single-Precision */
4979 case 14: /* Floating Convert To Integer Word */
4980 case 15: /* Floating Convert To Integer Word
4981 with round toward Zero */
4982 case 142: /* Floating Convert To Integer Word Unsigned */
4983 case 143: /* Floating Convert To Integer Word Unsigned
4984 with round toward Zero */
4985 case 392: /* Floating Round to Integer Nearest */
4986 case 424: /* Floating Round to Integer Toward Zero */
4987 case 456: /* Floating Round to Integer Plus */
4988 case 488: /* Floating Round to Integer Minus */
4989 case 814: /* Floating Convert To Integer Doubleword */
4990 case 815: /* Floating Convert To Integer Doubleword
4991 with round toward Zero */
4992 case 846: /* Floating Convert From Integer Doubleword */
4993 case 942: /* Floating Convert To Integer Doubleword Unsigned */
4994 case 943: /* Floating Convert To Integer Doubleword Unsigned
4995 with round toward Zero */
4996 case 974: /* Floating Convert From Integer Doubleword Unsigned */
4997 record_full_arch_list_add_reg (regcache,
4998 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4999 if (PPC_RC (insn))
5000 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5001 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5002 return 0;
5003
5004 case 583: /* Move From FPSCR */
5005 case 8: /* Floating Copy Sign */
5006 case 40: /* Floating Negate */
5007 case 72: /* Floating Move Register */
5008 case 136: /* Floating Negative Absolute Value */
5009 case 264: /* Floating Absolute Value */
5010 record_full_arch_list_add_reg (regcache,
5011 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5012 if (PPC_RC (insn))
5013 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5014 return 0;
5015
5016 case 838: /* Floating Merge Odd Word */
5017 case 966: /* Floating Merge Even Word */
5018 record_full_arch_list_add_reg (regcache,
5019 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5020 return 0;
5021
5022 case 38: /* Move To FPSCR Bit 1 */
5023 case 70: /* Move To FPSCR Bit 0 */
5024 case 134: /* Move To FPSCR Field Immediate */
5025 case 711: /* Move To FPSCR Fields */
5026 if (PPC_RC (insn))
5027 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5028 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5029 break;
5030
5031 case 0: /* Floating Compare Unordered */
5032 case 32: /* Floating Compare Ordered */
5033 case 64: /* Move to Condition Register from FPSCR */
5034 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5035 /* FALL-THROUGH */
5036 case 128: /* Floating Test for software Divide */
5037 case 160: /* Floating Test for software Square Root */
5038 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5039 return 0;
5040
5041 }
5042
810c1026
WW
5043 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
5044 "at %s, 59-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
5045 return -1;
5046}
5047
5048/* Parse the current instruction and record the values of the registers and
5049 memory that will be changed in current instruction to "record_arch_list".
5050 Return -1 if something wrong. */
5051
5052int
5053ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
5054 CORE_ADDR addr)
5055{
5056 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
5057 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
5058 uint32_t insn;
5059 int op6, tmp, i;
5060
5061 insn = read_memory_unsigned_integer (addr, 4, byte_order);
5062 op6 = PPC_OP6 (insn);
5063
5064 switch (op6)
5065 {
5066 case 2: /* Trap Doubleword Immediate */
5067 case 3: /* Trap Word Immediate */
5068 /* Do nothing. */
5069 break;
5070
5071 case 4:
5072 if (ppc_process_record_op4 (gdbarch, regcache, addr, insn) != 0)
5073 return -1;
5074 break;
5075
5076 case 17: /* System call */
5077 if (PPC_LEV (insn) != 0)
5078 goto UNKNOWN_OP;
5079
5080 if (tdep->ppc_syscall_record != NULL)
5081 {
5082 if (tdep->ppc_syscall_record (regcache) != 0)
5083 return -1;
5084 }
5085 else
5086 {
5087 printf_unfiltered (_("no syscall record support\n"));
5088 return -1;
5089 }
5090 break;
5091
5092 case 7: /* Multiply Low Immediate */
5093 record_full_arch_list_add_reg (regcache,
5094 tdep->ppc_gp0_regnum + PPC_RT (insn));
5095 break;
5096
5097 case 8: /* Subtract From Immediate Carrying */
5098 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
5099 record_full_arch_list_add_reg (regcache,
5100 tdep->ppc_gp0_regnum + PPC_RT (insn));
5101 break;
5102
5103 case 10: /* Compare Logical Immediate */
5104 case 11: /* Compare Immediate */
5105 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5106 break;
5107
5108 case 13: /* Add Immediate Carrying and Record */
5109 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5110 /* FALL-THROUGH */
5111 case 12: /* Add Immediate Carrying */
5112 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
5113 /* FALL-THROUGH */
5114 case 14: /* Add Immediate */
5115 case 15: /* Add Immediate Shifted */
5116 record_full_arch_list_add_reg (regcache,
5117 tdep->ppc_gp0_regnum + PPC_RT (insn));
5118 break;
5119
5120 case 16: /* Branch Conditional */
5121 if ((PPC_BO (insn) & 0x4) == 0)
5122 record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum);
5123 /* FALL-THROUGH */
5124 case 18: /* Branch */
5125 if (PPC_LK (insn))
5126 record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum);
5127 break;
5128
5129 case 19:
5130 if (ppc_process_record_op19 (gdbarch, regcache, addr, insn) != 0)
5131 return -1;
5132 break;
5133
5134 case 20: /* Rotate Left Word Immediate then Mask Insert */
5135 case 21: /* Rotate Left Word Immediate then AND with Mask */
5136 case 23: /* Rotate Left Word then AND with Mask */
5137 case 30: /* Rotate Left Doubleword Immediate then Clear Left */
5138 /* Rotate Left Doubleword Immediate then Clear Right */
5139 /* Rotate Left Doubleword Immediate then Clear */
5140 /* Rotate Left Doubleword then Clear Left */
5141 /* Rotate Left Doubleword then Clear Right */
5142 /* Rotate Left Doubleword Immediate then Mask Insert */
5143 if (PPC_RC (insn))
5144 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5145 record_full_arch_list_add_reg (regcache,
5146 tdep->ppc_gp0_regnum + PPC_RA (insn));
5147 break;
5148
5149 case 28: /* AND Immediate */
5150 case 29: /* AND Immediate Shifted */
5151 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5152 /* FALL-THROUGH */
5153 case 24: /* OR Immediate */
5154 case 25: /* OR Immediate Shifted */
5155 case 26: /* XOR Immediate */
5156 case 27: /* XOR Immediate Shifted */
5157 record_full_arch_list_add_reg (regcache,
5158 tdep->ppc_gp0_regnum + PPC_RA (insn));
5159 break;
5160
5161 case 31:
5162 if (ppc_process_record_op31 (gdbarch, regcache, addr, insn) != 0)
5163 return -1;
5164 break;
5165
5166 case 33: /* Load Word and Zero with Update */
5167 case 35: /* Load Byte and Zero with Update */
5168 case 41: /* Load Halfword and Zero with Update */
5169 case 43: /* Load Halfword Algebraic with Update */
5170 record_full_arch_list_add_reg (regcache,
5171 tdep->ppc_gp0_regnum + PPC_RA (insn));
5172 /* FALL-THROUGH */
5173 case 32: /* Load Word and Zero */
5174 case 34: /* Load Byte and Zero */
5175 case 40: /* Load Halfword and Zero */
5176 case 42: /* Load Halfword Algebraic */
5177 record_full_arch_list_add_reg (regcache,
5178 tdep->ppc_gp0_regnum + PPC_RT (insn));
5179 break;
5180
5181 case 46: /* Load Multiple Word */
5182 for (i = PPC_RT (insn); i < 32; i++)
5183 record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i);
5184 break;
5185
5186 case 56: /* Load Quadword */
5187 tmp = tdep->ppc_gp0_regnum + (PPC_RT (insn) & ~1);
5188 record_full_arch_list_add_reg (regcache, tmp);
5189 record_full_arch_list_add_reg (regcache, tmp + 1);
5190 break;
5191
5192 case 49: /* Load Floating-Point Single with Update */
5193 case 51: /* Load Floating-Point Double with Update */
5194 record_full_arch_list_add_reg (regcache,
5195 tdep->ppc_gp0_regnum + PPC_RA (insn));
5196 /* FALL-THROUGH */
5197 case 48: /* Load Floating-Point Single */
5198 case 50: /* Load Floating-Point Double */
5199 record_full_arch_list_add_reg (regcache,
5200 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5201 break;
5202
5203 case 47: /* Store Multiple Word */
5204 {
5205 ULONGEST addr = 0;
5206
5207 if (PPC_RA (insn) != 0)
5208 regcache_raw_read_unsigned (regcache,
5209 tdep->ppc_gp0_regnum + PPC_RA (insn),
5210 &addr);
5211
5212 addr += PPC_D (insn);
5213 record_full_arch_list_add_mem (addr, 4 * (32 - PPC_RS (insn)));
5214 }
5215 break;
5216
5217 case 37: /* Store Word with Update */
5218 case 39: /* Store Byte with Update */
5219 case 45: /* Store Halfword with Update */
5220 case 53: /* Store Floating-Point Single with Update */
5221 case 55: /* Store Floating-Point Double with Update */
5222 record_full_arch_list_add_reg (regcache,
5223 tdep->ppc_gp0_regnum + PPC_RA (insn));
5224 /* FALL-THROUGH */
5225 case 36: /* Store Word */
5226 case 38: /* Store Byte */
5227 case 44: /* Store Halfword */
5228 case 52: /* Store Floating-Point Single */
5229 case 54: /* Store Floating-Point Double */
5230 {
5231 ULONGEST addr = 0;
5232 int size = -1;
5233
5234 if (PPC_RA (insn) != 0)
5235 regcache_raw_read_unsigned (regcache,
5236 tdep->ppc_gp0_regnum + PPC_RA (insn),
5237 &addr);
5238 addr += PPC_D (insn);
5239
5240 if (op6 == 36 || op6 == 37 || op6 == 52 || op6 == 53)
5241 size = 4;
5242 else if (op6 == 54 || op6 == 55)
5243 size = 8;
5244 else if (op6 == 44 || op6 == 45)
5245 size = 2;
5246 else if (op6 == 38 || op6 == 39)
5247 size = 1;
5248 else
5249 gdb_assert (0);
5250
5251 record_full_arch_list_add_mem (addr, size);
5252 }
5253 break;
5254
5255 case 57: /* Load Floating-Point Double Pair */
5256 if (PPC_FIELD (insn, 30, 2) != 0)
5257 goto UNKNOWN_OP;
5258 tmp = tdep->ppc_fp0_regnum + (PPC_RT (insn) & ~1);
5259 record_full_arch_list_add_reg (regcache, tmp);
5260 record_full_arch_list_add_reg (regcache, tmp + 1);
5261 break;
5262
5263 case 58: /* Load Doubleword */
5264 /* Load Doubleword with Update */
5265 /* Load Word Algebraic */
5266 if (PPC_FIELD (insn, 30, 2) > 2)
5267 goto UNKNOWN_OP;
5268
5269 record_full_arch_list_add_reg (regcache,
5270 tdep->ppc_gp0_regnum + PPC_RT (insn));
5271 if (PPC_BIT (insn, 31))
5272 record_full_arch_list_add_reg (regcache,
5273 tdep->ppc_gp0_regnum + PPC_RA (insn));
5274 break;
5275
5276 case 59:
5277 if (ppc_process_record_op59 (gdbarch, regcache, addr, insn) != 0)
5278 return -1;
5279 break;
5280
5281 case 60:
5282 if (ppc_process_record_op60 (gdbarch, regcache, addr, insn) != 0)
5283 return -1;
5284 break;
5285
5286 case 61: /* Store Floating-Point Double Pair */
5287 case 62: /* Store Doubleword */
5288 /* Store Doubleword with Update */
5289 /* Store Quadword with Update */
5290 {
5291 ULONGEST addr = 0;
5292 int size;
5293 int sub2 = PPC_FIELD (insn, 30, 2);
5294
5295 if ((op6 == 61 && sub2 != 0) || (op6 == 62 && sub2 > 2))
5296 goto UNKNOWN_OP;
5297
5298 if (PPC_RA (insn) != 0)
5299 regcache_raw_read_unsigned (regcache,
5300 tdep->ppc_gp0_regnum + PPC_RA (insn),
5301 &addr);
5302
5303 size = ((op6 == 61) || sub2 == 2) ? 16 : 8;
5304
5305 addr += PPC_DS (insn) << 2;
5306 record_full_arch_list_add_mem (addr, size);
5307
5308 if (op6 == 62 && sub2 == 1)
5309 record_full_arch_list_add_reg (regcache,
5310 tdep->ppc_gp0_regnum +
5311 PPC_RA (insn));
5312
5313 break;
5314 }
5315
5316 case 63:
5317 if (ppc_process_record_op63 (gdbarch, regcache, addr, insn) != 0)
5318 return -1;
5319 break;
5320
5321 default:
5322UNKNOWN_OP:
810c1026
WW
5323 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
5324 "at %s, %d.\n", insn, paddress (gdbarch, addr), op6);
b4cdae6f
WW
5325 return -1;
5326 }
5327
5328 if (record_full_arch_list_add_reg (regcache, PPC_PC_REGNUM))
5329 return -1;
5330 if (record_full_arch_list_add_end ())
5331 return -1;
5332 return 0;
5333}
5334
7a78ae4e
ND
5335/* Initialize the current architecture based on INFO. If possible, re-use an
5336 architecture from ARCHES, which is a list of architectures already created
5337 during this debugging session.
c906108c 5338
7a78ae4e 5339 Called e.g. at program startup, when reading a core file, and when reading
64366f1c 5340 a binary file. */
c906108c 5341
7a78ae4e
ND
5342static struct gdbarch *
5343rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
5344{
5345 struct gdbarch *gdbarch;
5346 struct gdbarch_tdep *tdep;
7cc46491 5347 int wordsize, from_xcoff_exec, from_elf_exec;
7a78ae4e
ND
5348 enum bfd_architecture arch;
5349 unsigned long mach;
5350 bfd abfd;
55eddb0f
DJ
5351 enum auto_boolean soft_float_flag = powerpc_soft_float_global;
5352 int soft_float;
5353 enum powerpc_vector_abi vector_abi = powerpc_vector_abi_global;
cd453cd0 5354 enum powerpc_elf_abi elf_abi = POWERPC_ELF_AUTO;
604c2f83
LM
5355 int have_fpu = 1, have_spe = 0, have_mq = 0, have_altivec = 0, have_dfp = 0,
5356 have_vsx = 0;
7cc46491
DJ
5357 int tdesc_wordsize = -1;
5358 const struct target_desc *tdesc = info.target_desc;
5359 struct tdesc_arch_data *tdesc_data = NULL;
f949c649 5360 int num_pseudoregs = 0;
604c2f83 5361 int cur_reg;
7a78ae4e 5362
f4d9bade
UW
5363 /* INFO may refer to a binary that is not of the PowerPC architecture,
5364 e.g. when debugging a stand-alone SPE executable on a Cell/B.E. system.
5365 In this case, we must not attempt to infer properties of the (PowerPC
5366 side) of the target system from properties of that executable. Trust
5367 the target description instead. */
5368 if (info.abfd
5369 && bfd_get_arch (info.abfd) != bfd_arch_powerpc
5370 && bfd_get_arch (info.abfd) != bfd_arch_rs6000)
5371 info.abfd = NULL;
5372
9aa1e687 5373 from_xcoff_exec = info.abfd && info.abfd->format == bfd_object &&
7a78ae4e
ND
5374 bfd_get_flavour (info.abfd) == bfd_target_xcoff_flavour;
5375
9aa1e687
KB
5376 from_elf_exec = info.abfd && info.abfd->format == bfd_object &&
5377 bfd_get_flavour (info.abfd) == bfd_target_elf_flavour;
5378
e712c1cf 5379 /* Check word size. If INFO is from a binary file, infer it from
64366f1c 5380 that, else choose a likely default. */
9aa1e687 5381 if (from_xcoff_exec)
c906108c 5382 {
11ed25ac 5383 if (bfd_xcoff_is_xcoff64 (info.abfd))
7a78ae4e
ND
5384 wordsize = 8;
5385 else
5386 wordsize = 4;
c906108c 5387 }
9aa1e687
KB
5388 else if (from_elf_exec)
5389 {
5390 if (elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5391 wordsize = 8;
5392 else
5393 wordsize = 4;
5394 }
7cc46491
DJ
5395 else if (tdesc_has_registers (tdesc))
5396 wordsize = -1;
c906108c 5397 else
7a78ae4e 5398 {
27b15785 5399 if (info.bfd_arch_info != NULL && info.bfd_arch_info->bits_per_word != 0)
16d8013c
JB
5400 wordsize = (info.bfd_arch_info->bits_per_word
5401 / info.bfd_arch_info->bits_per_byte);
27b15785
KB
5402 else
5403 wordsize = 4;
7a78ae4e 5404 }
c906108c 5405
475bbd17
JB
5406 /* Get the architecture and machine from the BFD. */
5407 arch = info.bfd_arch_info->arch;
5408 mach = info.bfd_arch_info->mach;
5bf1c677
EZ
5409
5410 /* For e500 executables, the apuinfo section is of help here. Such
5411 section contains the identifier and revision number of each
5412 Application-specific Processing Unit that is present on the
5413 chip. The content of the section is determined by the assembler
5414 which looks at each instruction and determines which unit (and
74af9197
NF
5415 which version of it) can execute it. Grovel through the section
5416 looking for relevant e500 APUs. */
5bf1c677 5417
74af9197 5418 if (bfd_uses_spe_extensions (info.abfd))
5bf1c677 5419 {
74af9197
NF
5420 arch = info.bfd_arch_info->arch;
5421 mach = bfd_mach_ppc_e500;
5422 bfd_default_set_arch_mach (&abfd, arch, mach);
5423 info.bfd_arch_info = bfd_get_arch_info (&abfd);
5bf1c677
EZ
5424 }
5425
7cc46491
DJ
5426 /* Find a default target description which describes our register
5427 layout, if we do not already have one. */
5428 if (! tdesc_has_registers (tdesc))
5429 {
5430 const struct variant *v;
5431
5432 /* Choose variant. */
5433 v = find_variant_by_arch (arch, mach);
5434 if (!v)
5435 return NULL;
5436
5437 tdesc = *v->tdesc;
5438 }
5439
5440 gdb_assert (tdesc_has_registers (tdesc));
5441
5442 /* Check any target description for validity. */
5443 if (tdesc_has_registers (tdesc))
5444 {
5445 static const char *const gprs[] = {
5446 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
5447 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
5448 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
5449 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
5450 };
7cc46491
DJ
5451 const struct tdesc_feature *feature;
5452 int i, valid_p;
5453 static const char *const msr_names[] = { "msr", "ps" };
5454 static const char *const cr_names[] = { "cr", "cnd" };
5455 static const char *const ctr_names[] = { "ctr", "cnt" };
5456
5457 feature = tdesc_find_feature (tdesc,
5458 "org.gnu.gdb.power.core");
5459 if (feature == NULL)
5460 return NULL;
5461
5462 tdesc_data = tdesc_data_alloc ();
5463
5464 valid_p = 1;
5465 for (i = 0; i < ppc_num_gprs; i++)
5466 valid_p &= tdesc_numbered_register (feature, tdesc_data, i, gprs[i]);
5467 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_PC_REGNUM,
5468 "pc");
5469 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_LR_REGNUM,
5470 "lr");
5471 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_XER_REGNUM,
5472 "xer");
5473
5474 /* Allow alternate names for these registers, to accomodate GDB's
5475 historic naming. */
5476 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5477 PPC_MSR_REGNUM, msr_names);
5478 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5479 PPC_CR_REGNUM, cr_names);
5480 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5481 PPC_CTR_REGNUM, ctr_names);
5482
5483 if (!valid_p)
5484 {
5485 tdesc_data_cleanup (tdesc_data);
5486 return NULL;
5487 }
5488
5489 have_mq = tdesc_numbered_register (feature, tdesc_data, PPC_MQ_REGNUM,
5490 "mq");
5491
5492 tdesc_wordsize = tdesc_register_size (feature, "pc") / 8;
5493 if (wordsize == -1)
5494 wordsize = tdesc_wordsize;
5495
5496 feature = tdesc_find_feature (tdesc,
5497 "org.gnu.gdb.power.fpu");
5498 if (feature != NULL)
5499 {
5500 static const char *const fprs[] = {
5501 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
5502 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
5503 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
5504 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
5505 };
5506 valid_p = 1;
5507 for (i = 0; i < ppc_num_fprs; i++)
5508 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5509 PPC_F0_REGNUM + i, fprs[i]);
5510 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5511 PPC_FPSCR_REGNUM, "fpscr");
5512
5513 if (!valid_p)
5514 {
5515 tdesc_data_cleanup (tdesc_data);
5516 return NULL;
5517 }
5518 have_fpu = 1;
5519 }
5520 else
5521 have_fpu = 0;
5522
f949c649
TJB
5523 /* The DFP pseudo-registers will be available when there are floating
5524 point registers. */
5525 have_dfp = have_fpu;
5526
7cc46491
DJ
5527 feature = tdesc_find_feature (tdesc,
5528 "org.gnu.gdb.power.altivec");
5529 if (feature != NULL)
5530 {
5531 static const char *const vector_regs[] = {
5532 "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7",
5533 "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15",
5534 "vr16", "vr17", "vr18", "vr19", "vr20", "vr21", "vr22", "vr23",
5535 "vr24", "vr25", "vr26", "vr27", "vr28", "vr29", "vr30", "vr31"
5536 };
5537
5538 valid_p = 1;
5539 for (i = 0; i < ppc_num_gprs; i++)
5540 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5541 PPC_VR0_REGNUM + i,
5542 vector_regs[i]);
5543 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5544 PPC_VSCR_REGNUM, "vscr");
5545 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5546 PPC_VRSAVE_REGNUM, "vrsave");
5547
5548 if (have_spe || !valid_p)
5549 {
5550 tdesc_data_cleanup (tdesc_data);
5551 return NULL;
5552 }
5553 have_altivec = 1;
5554 }
5555 else
5556 have_altivec = 0;
5557
604c2f83
LM
5558 /* Check for POWER7 VSX registers support. */
5559 feature = tdesc_find_feature (tdesc,
5560 "org.gnu.gdb.power.vsx");
5561
5562 if (feature != NULL)
5563 {
5564 static const char *const vsx_regs[] = {
5565 "vs0h", "vs1h", "vs2h", "vs3h", "vs4h", "vs5h",
5566 "vs6h", "vs7h", "vs8h", "vs9h", "vs10h", "vs11h",
5567 "vs12h", "vs13h", "vs14h", "vs15h", "vs16h", "vs17h",
5568 "vs18h", "vs19h", "vs20h", "vs21h", "vs22h", "vs23h",
5569 "vs24h", "vs25h", "vs26h", "vs27h", "vs28h", "vs29h",
5570 "vs30h", "vs31h"
5571 };
5572
5573 valid_p = 1;
5574
5575 for (i = 0; i < ppc_num_vshrs; i++)
5576 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5577 PPC_VSR0_UPPER_REGNUM + i,
5578 vsx_regs[i]);
5579 if (!valid_p)
5580 {
5581 tdesc_data_cleanup (tdesc_data);
5582 return NULL;
5583 }
5584
5585 have_vsx = 1;
5586 }
5587 else
5588 have_vsx = 0;
5589
7cc46491
DJ
5590 /* On machines supporting the SPE APU, the general-purpose registers
5591 are 64 bits long. There are SIMD vector instructions to treat them
5592 as pairs of floats, but the rest of the instruction set treats them
5593 as 32-bit registers, and only operates on their lower halves.
5594
5595 In the GDB regcache, we treat their high and low halves as separate
5596 registers. The low halves we present as the general-purpose
5597 registers, and then we have pseudo-registers that stitch together
5598 the upper and lower halves and present them as pseudo-registers.
5599
5600 Thus, the target description is expected to supply the upper
5601 halves separately. */
5602
5603 feature = tdesc_find_feature (tdesc,
5604 "org.gnu.gdb.power.spe");
5605 if (feature != NULL)
5606 {
5607 static const char *const upper_spe[] = {
5608 "ev0h", "ev1h", "ev2h", "ev3h",
5609 "ev4h", "ev5h", "ev6h", "ev7h",
5610 "ev8h", "ev9h", "ev10h", "ev11h",
5611 "ev12h", "ev13h", "ev14h", "ev15h",
5612 "ev16h", "ev17h", "ev18h", "ev19h",
5613 "ev20h", "ev21h", "ev22h", "ev23h",
5614 "ev24h", "ev25h", "ev26h", "ev27h",
5615 "ev28h", "ev29h", "ev30h", "ev31h"
5616 };
5617
5618 valid_p = 1;
5619 for (i = 0; i < ppc_num_gprs; i++)
5620 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5621 PPC_SPE_UPPER_GP0_REGNUM + i,
5622 upper_spe[i]);
5623 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5624 PPC_SPE_ACC_REGNUM, "acc");
5625 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5626 PPC_SPE_FSCR_REGNUM, "spefscr");
5627
5628 if (have_mq || have_fpu || !valid_p)
5629 {
5630 tdesc_data_cleanup (tdesc_data);
5631 return NULL;
5632 }
5633 have_spe = 1;
5634 }
5635 else
5636 have_spe = 0;
5637 }
5638
5639 /* If we have a 64-bit binary on a 32-bit target, complain. Also
5640 complain for a 32-bit binary on a 64-bit target; we do not yet
5641 support that. For instance, the 32-bit ABI routines expect
5642 32-bit GPRs.
5643
5644 As long as there isn't an explicit target description, we'll
5645 choose one based on the BFD architecture and get a word size
5646 matching the binary (probably powerpc:common or
5647 powerpc:common64). So there is only trouble if a 64-bit target
5648 supplies a 64-bit description while debugging a 32-bit
5649 binary. */
5650 if (tdesc_wordsize != -1 && tdesc_wordsize != wordsize)
5651 {
5652 tdesc_data_cleanup (tdesc_data);
5653 return NULL;
5654 }
5655
55eddb0f 5656#ifdef HAVE_ELF
cd453cd0
UW
5657 if (from_elf_exec)
5658 {
5659 switch (elf_elfheader (info.abfd)->e_flags & EF_PPC64_ABI)
5660 {
5661 case 1:
5662 elf_abi = POWERPC_ELF_V1;
5663 break;
5664 case 2:
5665 elf_abi = POWERPC_ELF_V2;
5666 break;
5667 default:
5668 break;
5669 }
5670 }
5671
55eddb0f
DJ
5672 if (soft_float_flag == AUTO_BOOLEAN_AUTO && from_elf_exec)
5673 {
5674 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
5675 Tag_GNU_Power_ABI_FP))
5676 {
5677 case 1:
5678 soft_float_flag = AUTO_BOOLEAN_FALSE;
5679 break;
5680 case 2:
5681 soft_float_flag = AUTO_BOOLEAN_TRUE;
5682 break;
5683 default:
5684 break;
5685 }
5686 }
5687
5688 if (vector_abi == POWERPC_VEC_AUTO && from_elf_exec)
5689 {
5690 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
5691 Tag_GNU_Power_ABI_Vector))
5692 {
5693 case 1:
5694 vector_abi = POWERPC_VEC_GENERIC;
5695 break;
5696 case 2:
5697 vector_abi = POWERPC_VEC_ALTIVEC;
5698 break;
5699 case 3:
5700 vector_abi = POWERPC_VEC_SPE;
5701 break;
5702 default:
5703 break;
5704 }
5705 }
5706#endif
5707
cd453cd0
UW
5708 /* At this point, the only supported ELF-based 64-bit little-endian
5709 operating system is GNU/Linux, and this uses the ELFv2 ABI by
5710 default. All other supported ELF-based operating systems use the
5711 ELFv1 ABI by default. Therefore, if the ABI marker is missing,
5712 e.g. because we run a legacy binary, or have attached to a process
5713 and have not found any associated binary file, set the default
5714 according to this heuristic. */
5715 if (elf_abi == POWERPC_ELF_AUTO)
5716 {
5717 if (wordsize == 8 && info.byte_order == BFD_ENDIAN_LITTLE)
5718 elf_abi = POWERPC_ELF_V2;
5719 else
5720 elf_abi = POWERPC_ELF_V1;
5721 }
5722
55eddb0f
DJ
5723 if (soft_float_flag == AUTO_BOOLEAN_TRUE)
5724 soft_float = 1;
5725 else if (soft_float_flag == AUTO_BOOLEAN_FALSE)
5726 soft_float = 0;
5727 else
5728 soft_float = !have_fpu;
5729
5730 /* If we have a hard float binary or setting but no floating point
5731 registers, downgrade to soft float anyway. We're still somewhat
5732 useful in this scenario. */
5733 if (!soft_float && !have_fpu)
5734 soft_float = 1;
5735
5736 /* Similarly for vector registers. */
5737 if (vector_abi == POWERPC_VEC_ALTIVEC && !have_altivec)
5738 vector_abi = POWERPC_VEC_GENERIC;
5739
5740 if (vector_abi == POWERPC_VEC_SPE && !have_spe)
5741 vector_abi = POWERPC_VEC_GENERIC;
5742
5743 if (vector_abi == POWERPC_VEC_AUTO)
5744 {
5745 if (have_altivec)
5746 vector_abi = POWERPC_VEC_ALTIVEC;
5747 else if (have_spe)
5748 vector_abi = POWERPC_VEC_SPE;
5749 else
5750 vector_abi = POWERPC_VEC_GENERIC;
5751 }
5752
5753 /* Do not limit the vector ABI based on available hardware, since we
5754 do not yet know what hardware we'll decide we have. Yuck! FIXME! */
5755
7cc46491
DJ
5756 /* Find a candidate among extant architectures. */
5757 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5758 arches != NULL;
5759 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5760 {
5761 /* Word size in the various PowerPC bfd_arch_info structs isn't
5762 meaningful, because 64-bit CPUs can run in 32-bit mode. So, perform
5763 separate word size check. */
5764 tdep = gdbarch_tdep (arches->gdbarch);
cd453cd0
UW
5765 if (tdep && tdep->elf_abi != elf_abi)
5766 continue;
55eddb0f
DJ
5767 if (tdep && tdep->soft_float != soft_float)
5768 continue;
5769 if (tdep && tdep->vector_abi != vector_abi)
5770 continue;
7cc46491
DJ
5771 if (tdep && tdep->wordsize == wordsize)
5772 {
5773 if (tdesc_data != NULL)
5774 tdesc_data_cleanup (tdesc_data);
5775 return arches->gdbarch;
5776 }
5777 }
5778
5779 /* None found, create a new architecture from INFO, whose bfd_arch_info
5780 validity depends on the source:
5781 - executable useless
5782 - rs6000_host_arch() good
5783 - core file good
5784 - "set arch" trust blindly
5785 - GDB startup useless but harmless */
5786
fc270c35 5787 tdep = XCNEW (struct gdbarch_tdep);
7cc46491 5788 tdep->wordsize = wordsize;
cd453cd0 5789 tdep->elf_abi = elf_abi;
55eddb0f
DJ
5790 tdep->soft_float = soft_float;
5791 tdep->vector_abi = vector_abi;
7cc46491 5792
7a78ae4e 5793 gdbarch = gdbarch_alloc (&info, tdep);
7a78ae4e 5794
7cc46491
DJ
5795 tdep->ppc_gp0_regnum = PPC_R0_REGNUM;
5796 tdep->ppc_toc_regnum = PPC_R0_REGNUM + 2;
5797 tdep->ppc_ps_regnum = PPC_MSR_REGNUM;
5798 tdep->ppc_cr_regnum = PPC_CR_REGNUM;
5799 tdep->ppc_lr_regnum = PPC_LR_REGNUM;
5800 tdep->ppc_ctr_regnum = PPC_CTR_REGNUM;
5801 tdep->ppc_xer_regnum = PPC_XER_REGNUM;
5802 tdep->ppc_mq_regnum = have_mq ? PPC_MQ_REGNUM : -1;
5803
5804 tdep->ppc_fp0_regnum = have_fpu ? PPC_F0_REGNUM : -1;
5805 tdep->ppc_fpscr_regnum = have_fpu ? PPC_FPSCR_REGNUM : -1;
604c2f83 5806 tdep->ppc_vsr0_upper_regnum = have_vsx ? PPC_VSR0_UPPER_REGNUM : -1;
7cc46491
DJ
5807 tdep->ppc_vr0_regnum = have_altivec ? PPC_VR0_REGNUM : -1;
5808 tdep->ppc_vrsave_regnum = have_altivec ? PPC_VRSAVE_REGNUM : -1;
5809 tdep->ppc_ev0_upper_regnum = have_spe ? PPC_SPE_UPPER_GP0_REGNUM : -1;
5810 tdep->ppc_acc_regnum = have_spe ? PPC_SPE_ACC_REGNUM : -1;
5811 tdep->ppc_spefscr_regnum = have_spe ? PPC_SPE_FSCR_REGNUM : -1;
5812
5813 set_gdbarch_pc_regnum (gdbarch, PPC_PC_REGNUM);
5814 set_gdbarch_sp_regnum (gdbarch, PPC_R0_REGNUM + 1);
5815 set_gdbarch_deprecated_fp_regnum (gdbarch, PPC_R0_REGNUM + 1);
5816 set_gdbarch_fp0_regnum (gdbarch, tdep->ppc_fp0_regnum);
9f643768 5817 set_gdbarch_register_sim_regno (gdbarch, rs6000_register_sim_regno);
7cc46491
DJ
5818
5819 /* The XML specification for PowerPC sensibly calls the MSR "msr".
5820 GDB traditionally called it "ps", though, so let GDB add an
5821 alias. */
5822 set_gdbarch_ps_regnum (gdbarch, tdep->ppc_ps_regnum);
5823
4a7622d1 5824 if (wordsize == 8)
05580c65 5825 set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value);
afd48b75 5826 else
4a7622d1 5827 set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value);
c8001721 5828
baffbae0
JB
5829 /* Set lr_frame_offset. */
5830 if (wordsize == 8)
5831 tdep->lr_frame_offset = 16;
baffbae0 5832 else
4a7622d1 5833 tdep->lr_frame_offset = 4;
baffbae0 5834
604c2f83 5835 if (have_spe || have_dfp || have_vsx)
7cc46491 5836 {
f949c649 5837 set_gdbarch_pseudo_register_read (gdbarch, rs6000_pseudo_register_read);
0df8b418
MS
5838 set_gdbarch_pseudo_register_write (gdbarch,
5839 rs6000_pseudo_register_write);
7cc46491 5840 }
1fcc0bb8 5841
e0d24f8d
WZ
5842 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
5843
56a6dfb9 5844 /* Select instruction printer. */
708ff411 5845 if (arch == bfd_arch_rs6000)
9364a0ef 5846 set_gdbarch_print_insn (gdbarch, print_insn_rs6000);
56a6dfb9 5847 else
9364a0ef 5848 set_gdbarch_print_insn (gdbarch, gdb_print_insn_powerpc);
7495d1dc 5849
5a9e69ba 5850 set_gdbarch_num_regs (gdbarch, PPC_NUM_REGS);
f949c649
TJB
5851
5852 if (have_spe)
5853 num_pseudoregs += 32;
5854 if (have_dfp)
5855 num_pseudoregs += 16;
604c2f83
LM
5856 if (have_vsx)
5857 /* Include both VSX and Extended FP registers. */
5858 num_pseudoregs += 96;
f949c649
TJB
5859
5860 set_gdbarch_num_pseudo_regs (gdbarch, num_pseudoregs);
7a78ae4e
ND
5861
5862 set_gdbarch_ptr_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
5863 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
5864 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
5865 set_gdbarch_long_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
5866 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
5867 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
5868 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
4a7622d1 5869 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
4e409299 5870 set_gdbarch_char_signed (gdbarch, 0);
7a78ae4e 5871
11269d7e 5872 set_gdbarch_frame_align (gdbarch, rs6000_frame_align);
4a7622d1 5873 if (wordsize == 8)
8b148df9
AC
5874 /* PPC64 SYSV. */
5875 set_gdbarch_frame_red_zone_size (gdbarch, 288);
7a78ae4e 5876
691d145a
JB
5877 set_gdbarch_convert_register_p (gdbarch, rs6000_convert_register_p);
5878 set_gdbarch_register_to_value (gdbarch, rs6000_register_to_value);
5879 set_gdbarch_value_to_register (gdbarch, rs6000_value_to_register);
5880
18ed0c4e
JB
5881 set_gdbarch_stab_reg_to_regnum (gdbarch, rs6000_stab_reg_to_regnum);
5882 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rs6000_dwarf2_reg_to_regnum);
d217aaed 5883
4a7622d1 5884 if (wordsize == 4)
77b2b6d4 5885 set_gdbarch_push_dummy_call (gdbarch, ppc_sysv_abi_push_dummy_call);
4a7622d1 5886 else if (wordsize == 8)
8be9034a 5887 set_gdbarch_push_dummy_call (gdbarch, ppc64_sysv_abi_push_dummy_call);
7a78ae4e 5888
7a78ae4e 5889 set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue);
0d1243d9 5890 set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilogue_p);
8ab3d180 5891 set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue);
0d1243d9 5892
7a78ae4e 5893 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
7a78ae4e
ND
5894 set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);
5895
203c3895 5896 /* The value of symbols of type N_SO and N_FUN maybe null when
0df8b418 5897 it shouldn't be. */
203c3895
UW
5898 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
5899
ce5eab59 5900 /* Handles single stepping of atomic sequences. */
4a7622d1 5901 set_gdbarch_software_single_step (gdbarch, ppc_deal_with_atomic_sequence);
ce5eab59 5902
0df8b418 5903 /* Not sure on this. FIXMEmgo */
7a78ae4e
ND
5904 set_gdbarch_frame_args_skip (gdbarch, 8);
5905
143985b7
AF
5906 /* Helpers for function argument information. */
5907 set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument);
5908
6f7f3f0d
UW
5909 /* Trampoline. */
5910 set_gdbarch_in_solib_return_trampoline
5911 (gdbarch, rs6000_in_solib_return_trampoline);
5912 set_gdbarch_skip_trampoline_code (gdbarch, rs6000_skip_trampoline_code);
5913
4fc771b8 5914 /* Hook in the DWARF CFI frame unwinder. */
1af5d7ce 5915 dwarf2_append_unwinders (gdbarch);
4fc771b8
DJ
5916 dwarf2_frame_set_adjust_regnum (gdbarch, rs6000_adjust_frame_regnum);
5917
9274a07c
LM
5918 /* Frame handling. */
5919 dwarf2_frame_set_init_reg (gdbarch, ppc_dwarf2_frame_init_reg);
5920
2454a024
UW
5921 /* Setup displaced stepping. */
5922 set_gdbarch_displaced_step_copy_insn (gdbarch,
5923 simple_displaced_step_copy_insn);
99e40580
UW
5924 set_gdbarch_displaced_step_hw_singlestep (gdbarch,
5925 ppc_displaced_step_hw_singlestep);
2454a024
UW
5926 set_gdbarch_displaced_step_fixup (gdbarch, ppc_displaced_step_fixup);
5927 set_gdbarch_displaced_step_free_closure (gdbarch,
5928 simple_displaced_step_free_closure);
5929 set_gdbarch_displaced_step_location (gdbarch,
5930 displaced_step_at_entry_point);
5931
5932 set_gdbarch_max_insn_length (gdbarch, PPC_INSN_SIZE);
5933
7b112f9c 5934 /* Hook in ABI-specific overrides, if they have been registered. */
8a4c2d24
UW
5935 info.target_desc = tdesc;
5936 info.tdep_info = (void *) tdesc_data;
4be87837 5937 gdbarch_init_osabi (info, gdbarch);
7b112f9c 5938
61a65099
KB
5939 switch (info.osabi)
5940 {
f5aecab8 5941 case GDB_OSABI_LINUX:
61a65099
KB
5942 case GDB_OSABI_NETBSD_AOUT:
5943 case GDB_OSABI_NETBSD_ELF:
5944 case GDB_OSABI_UNKNOWN:
61a65099 5945 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
2608dbf8 5946 frame_unwind_append_unwinder (gdbarch, &rs6000_epilogue_frame_unwind);
1af5d7ce
UW
5947 frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind);
5948 set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id);
61a65099
KB
5949 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
5950 break;
5951 default:
61a65099 5952 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
81332287
KB
5953
5954 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
2608dbf8 5955 frame_unwind_append_unwinder (gdbarch, &rs6000_epilogue_frame_unwind);
1af5d7ce
UW
5956 frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind);
5957 set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id);
81332287 5958 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
61a65099
KB
5959 }
5960
7cc46491
DJ
5961 set_tdesc_pseudo_register_type (gdbarch, rs6000_pseudo_register_type);
5962 set_tdesc_pseudo_register_reggroup_p (gdbarch,
5963 rs6000_pseudo_register_reggroup_p);
5964 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
5965
5966 /* Override the normal target description method to make the SPE upper
5967 halves anonymous. */
5968 set_gdbarch_register_name (gdbarch, rs6000_register_name);
5969
604c2f83
LM
5970 /* Choose register numbers for all supported pseudo-registers. */
5971 tdep->ppc_ev0_regnum = -1;
5972 tdep->ppc_dl0_regnum = -1;
5973 tdep->ppc_vsr0_regnum = -1;
5974 tdep->ppc_efpr0_regnum = -1;
9f643768 5975
604c2f83
LM
5976 cur_reg = gdbarch_num_regs (gdbarch);
5977
5978 if (have_spe)
5979 {
5980 tdep->ppc_ev0_regnum = cur_reg;
5981 cur_reg += 32;
5982 }
5983 if (have_dfp)
5984 {
5985 tdep->ppc_dl0_regnum = cur_reg;
5986 cur_reg += 16;
5987 }
5988 if (have_vsx)
5989 {
5990 tdep->ppc_vsr0_regnum = cur_reg;
5991 cur_reg += 64;
5992 tdep->ppc_efpr0_regnum = cur_reg;
5993 cur_reg += 32;
5994 }
f949c649 5995
604c2f83
LM
5996 gdb_assert (gdbarch_num_regs (gdbarch)
5997 + gdbarch_num_pseudo_regs (gdbarch) == cur_reg);
f949c649 5998
debb1f09
JB
5999 /* Register the ravenscar_arch_ops. */
6000 if (mach == bfd_mach_ppc_e500)
6001 register_e500_ravenscar_ops (gdbarch);
6002 else
6003 register_ppc_ravenscar_ops (gdbarch);
6004
7a78ae4e 6005 return gdbarch;
c906108c
SS
6006}
6007
7b112f9c 6008static void
8b164abb 6009rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
7b112f9c 6010{
8b164abb 6011 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7b112f9c
JT
6012
6013 if (tdep == NULL)
6014 return;
6015
4be87837 6016 /* FIXME: Dump gdbarch_tdep. */
7b112f9c
JT
6017}
6018
55eddb0f
DJ
6019/* PowerPC-specific commands. */
6020
6021static void
6022set_powerpc_command (char *args, int from_tty)
6023{
6024 printf_unfiltered (_("\
6025\"set powerpc\" must be followed by an appropriate subcommand.\n"));
6026 help_list (setpowerpccmdlist, "set powerpc ", all_commands, gdb_stdout);
6027}
6028
6029static void
6030show_powerpc_command (char *args, int from_tty)
6031{
6032 cmd_show_list (showpowerpccmdlist, from_tty, "");
6033}
6034
6035static void
6036powerpc_set_soft_float (char *args, int from_tty,
6037 struct cmd_list_element *c)
6038{
6039 struct gdbarch_info info;
6040
6041 /* Update the architecture. */
6042 gdbarch_info_init (&info);
6043 if (!gdbarch_update_p (info))
9b20d036 6044 internal_error (__FILE__, __LINE__, _("could not update architecture"));
55eddb0f
DJ
6045}
6046
6047static void
6048powerpc_set_vector_abi (char *args, int from_tty,
6049 struct cmd_list_element *c)
6050{
6051 struct gdbarch_info info;
570dc176 6052 int vector_abi;
55eddb0f
DJ
6053
6054 for (vector_abi = POWERPC_VEC_AUTO;
6055 vector_abi != POWERPC_VEC_LAST;
6056 vector_abi++)
6057 if (strcmp (powerpc_vector_abi_string,
6058 powerpc_vector_strings[vector_abi]) == 0)
6059 {
6060 powerpc_vector_abi_global = vector_abi;
6061 break;
6062 }
6063
6064 if (vector_abi == POWERPC_VEC_LAST)
6065 internal_error (__FILE__, __LINE__, _("Invalid vector ABI accepted: %s."),
6066 powerpc_vector_abi_string);
6067
6068 /* Update the architecture. */
6069 gdbarch_info_init (&info);
6070 if (!gdbarch_update_p (info))
9b20d036 6071 internal_error (__FILE__, __LINE__, _("could not update architecture"));
55eddb0f
DJ
6072}
6073
e09342b5
TJB
6074/* Show the current setting of the exact watchpoints flag. */
6075
6076static void
6077show_powerpc_exact_watchpoints (struct ui_file *file, int from_tty,
6078 struct cmd_list_element *c,
6079 const char *value)
6080{
6081 fprintf_filtered (file, _("Use of exact watchpoints is %s.\n"), value);
6082}
6083
845d4708 6084/* Read a PPC instruction from memory. */
d78489bf
AT
6085
6086static unsigned int
845d4708 6087read_insn (struct frame_info *frame, CORE_ADDR pc)
d78489bf 6088{
845d4708
AM
6089 struct gdbarch *gdbarch = get_frame_arch (frame);
6090 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
6091
6092 return read_memory_unsigned_integer (pc, 4, byte_order);
d78489bf
AT
6093}
6094
6095/* Return non-zero if the instructions at PC match the series
6096 described in PATTERN, or zero otherwise. PATTERN is an array of
6097 'struct ppc_insn_pattern' objects, terminated by an entry whose
6098 mask is zero.
6099
6100 When the match is successful, fill INSN[i] with what PATTERN[i]
6101 matched. If PATTERN[i] is optional, and the instruction wasn't
6102 present, set INSN[i] to 0 (which is not a valid PPC instruction).
6103 INSN should have as many elements as PATTERN. Note that, if
6104 PATTERN contains optional instructions which aren't present in
6105 memory, then INSN will have holes, so INSN[i] isn't necessarily the
6106 i'th instruction in memory. */
6107
6108int
845d4708
AM
6109ppc_insns_match_pattern (struct frame_info *frame, CORE_ADDR pc,
6110 struct ppc_insn_pattern *pattern,
6111 unsigned int *insns)
d78489bf
AT
6112{
6113 int i;
845d4708 6114 unsigned int insn;
d78489bf 6115
845d4708 6116 for (i = 0, insn = 0; pattern[i].mask; i++)
d78489bf 6117 {
845d4708
AM
6118 if (insn == 0)
6119 insn = read_insn (frame, pc);
6120 insns[i] = 0;
6121 if ((insn & pattern[i].mask) == pattern[i].data)
6122 {
6123 insns[i] = insn;
6124 pc += 4;
6125 insn = 0;
6126 }
6127 else if (!pattern[i].optional)
d78489bf
AT
6128 return 0;
6129 }
6130
6131 return 1;
6132}
6133
6134/* Return the 'd' field of the d-form instruction INSN, properly
6135 sign-extended. */
6136
6137CORE_ADDR
6138ppc_insn_d_field (unsigned int insn)
6139{
6140 return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000);
6141}
6142
6143/* Return the 'ds' field of the ds-form instruction INSN, with the two
6144 zero bits concatenated at the right, and properly
6145 sign-extended. */
6146
6147CORE_ADDR
6148ppc_insn_ds_field (unsigned int insn)
6149{
6150 return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000);
6151}
6152
c906108c
SS
6153/* Initialization code. */
6154
0df8b418
MS
6155/* -Wmissing-prototypes */
6156extern initialize_file_ftype _initialize_rs6000_tdep;
b9362cc7 6157
c906108c 6158void
fba45db2 6159_initialize_rs6000_tdep (void)
c906108c 6160{
7b112f9c
JT
6161 gdbarch_register (bfd_arch_rs6000, rs6000_gdbarch_init, rs6000_dump_tdep);
6162 gdbarch_register (bfd_arch_powerpc, rs6000_gdbarch_init, rs6000_dump_tdep);
7cc46491
DJ
6163
6164 /* Initialize the standard target descriptions. */
6165 initialize_tdesc_powerpc_32 ();
7284e1be 6166 initialize_tdesc_powerpc_altivec32 ();
604c2f83 6167 initialize_tdesc_powerpc_vsx32 ();
7cc46491
DJ
6168 initialize_tdesc_powerpc_403 ();
6169 initialize_tdesc_powerpc_403gc ();
4d09ffea 6170 initialize_tdesc_powerpc_405 ();
7cc46491
DJ
6171 initialize_tdesc_powerpc_505 ();
6172 initialize_tdesc_powerpc_601 ();
6173 initialize_tdesc_powerpc_602 ();
6174 initialize_tdesc_powerpc_603 ();
6175 initialize_tdesc_powerpc_604 ();
6176 initialize_tdesc_powerpc_64 ();
7284e1be 6177 initialize_tdesc_powerpc_altivec64 ();
604c2f83 6178 initialize_tdesc_powerpc_vsx64 ();
7cc46491
DJ
6179 initialize_tdesc_powerpc_7400 ();
6180 initialize_tdesc_powerpc_750 ();
6181 initialize_tdesc_powerpc_860 ();
6182 initialize_tdesc_powerpc_e500 ();
6183 initialize_tdesc_rs6000 ();
55eddb0f
DJ
6184
6185 /* Add root prefix command for all "set powerpc"/"show powerpc"
6186 commands. */
6187 add_prefix_cmd ("powerpc", no_class, set_powerpc_command,
6188 _("Various PowerPC-specific commands."),
6189 &setpowerpccmdlist, "set powerpc ", 0, &setlist);
6190
6191 add_prefix_cmd ("powerpc", no_class, show_powerpc_command,
6192 _("Various PowerPC-specific commands."),
6193 &showpowerpccmdlist, "show powerpc ", 0, &showlist);
6194
6195 /* Add a command to allow the user to force the ABI. */
6196 add_setshow_auto_boolean_cmd ("soft-float", class_support,
6197 &powerpc_soft_float_global,
6198 _("Set whether to use a soft-float ABI."),
6199 _("Show whether to use a soft-float ABI."),
6200 NULL,
6201 powerpc_set_soft_float, NULL,
6202 &setpowerpccmdlist, &showpowerpccmdlist);
6203
6204 add_setshow_enum_cmd ("vector-abi", class_support, powerpc_vector_strings,
6205 &powerpc_vector_abi_string,
6206 _("Set the vector ABI."),
6207 _("Show the vector ABI."),
6208 NULL, powerpc_set_vector_abi, NULL,
6209 &setpowerpccmdlist, &showpowerpccmdlist);
e09342b5
TJB
6210
6211 add_setshow_boolean_cmd ("exact-watchpoints", class_support,
6212 &target_exact_watchpoints,
6213 _("\
6214Set whether to use just one debug register for watchpoints on scalars."),
6215 _("\
6216Show whether to use just one debug register for watchpoints on scalars."),
6217 _("\
6218If true, GDB will use only one debug register when watching a variable of\n\
6219scalar type, thus assuming that the variable is accessed through the address\n\
6220of its first byte."),
6221 NULL, show_powerpc_exact_watchpoints,
6222 &setpowerpccmdlist, &showpowerpccmdlist);
c906108c 6223}
This page took 2.005368 seconds and 4 git commands to generate.