Add self to ARM Maintainers
[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
ND
2222{
2223 return name && !strncmp (name, "@FIX", 4);
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
WW
3351
3352static struct rs6000_frame_cache *
3353rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
3354{
3355 volatile struct gdb_exception ex;
3356 struct rs6000_frame_cache *cache;
3357 struct gdbarch *gdbarch = get_frame_arch (this_frame);
3358 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2608dbf8
WW
3359
3360 if (*this_cache)
3361 return *this_cache;
3362
3363 cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache);
3364 (*this_cache) = cache;
3365 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
3366
3367 TRY_CATCH (ex, RETURN_MASK_ERROR)
3368 {
3369 /* At this point the stack looks as if we just entered the
3370 function, and the return address is stored in LR. */
3371 CORE_ADDR sp, lr;
3372
3373 sp = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
3374 lr = get_frame_register_unsigned (this_frame, tdep->ppc_lr_regnum);
3375
3376 cache->base = sp;
3377 cache->initial_sp = sp;
3378
3379 trad_frame_set_value (cache->saved_regs,
3380 gdbarch_pc_regnum (gdbarch), lr);
3381 }
3382 if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
3383 throw_exception (ex);
3384
3385 return cache;
3386}
3387
3388static void
3389rs6000_epilogue_frame_this_id (struct frame_info *this_frame,
3390 void **this_cache, struct frame_id *this_id)
3391{
3392 CORE_ADDR pc;
3393 struct rs6000_frame_cache *info =
3394 rs6000_epilogue_frame_cache (this_frame, this_cache);
3395
3396 pc = get_frame_func (this_frame);
3397 if (info->base == 0)
3398 (*this_id) = frame_id_build_unavailable_stack (pc);
3399 else
3400 (*this_id) = frame_id_build (info->base, pc);
3401}
3402
3403static struct value *
3404rs6000_epilogue_frame_prev_register (struct frame_info *this_frame,
3405 void **this_cache, int regnum)
3406{
3407 struct rs6000_frame_cache *info =
3408 rs6000_epilogue_frame_cache (this_frame, this_cache);
3409 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
3410}
3411
3412static int
3413rs6000_epilogue_frame_sniffer (const struct frame_unwind *self,
3414 struct frame_info *this_frame,
3415 void **this_prologue_cache)
3416{
3417 if (frame_relative_level (this_frame) == 0)
3418 return rs6000_in_function_epilogue_frame_p (this_frame,
3419 get_frame_arch (this_frame),
3420 get_frame_pc (this_frame));
3421 else
3422 return 0;
3423}
3424
3425static const struct frame_unwind rs6000_epilogue_frame_unwind =
3426{
3427 NORMAL_FRAME,
3428 default_frame_unwind_stop_reason,
3429 rs6000_epilogue_frame_this_id, rs6000_epilogue_frame_prev_register,
3430 NULL,
3431 rs6000_epilogue_frame_sniffer
3432};
61a65099
KB
3433\f
3434
3435static CORE_ADDR
1af5d7ce 3436rs6000_frame_base_address (struct frame_info *this_frame, void **this_cache)
61a65099 3437{
1af5d7ce 3438 struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame,
61a65099
KB
3439 this_cache);
3440 return info->initial_sp;
3441}
3442
3443static const struct frame_base rs6000_frame_base = {
3444 &rs6000_frame_unwind,
3445 rs6000_frame_base_address,
3446 rs6000_frame_base_address,
3447 rs6000_frame_base_address
3448};
3449
3450static const struct frame_base *
1af5d7ce 3451rs6000_frame_base_sniffer (struct frame_info *this_frame)
61a65099
KB
3452{
3453 return &rs6000_frame_base;
3454}
3455
9274a07c
LM
3456/* DWARF-2 frame support. Used to handle the detection of
3457 clobbered registers during function calls. */
3458
3459static void
3460ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
3461 struct dwarf2_frame_state_reg *reg,
4a4e5149 3462 struct frame_info *this_frame)
9274a07c
LM
3463{
3464 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3465
3466 /* PPC32 and PPC64 ABI's are the same regarding volatile and
3467 non-volatile registers. We will use the same code for both. */
3468
3469 /* Call-saved GP registers. */
3470 if ((regnum >= tdep->ppc_gp0_regnum + 14
3471 && regnum <= tdep->ppc_gp0_regnum + 31)
3472 || (regnum == tdep->ppc_gp0_regnum + 1))
3473 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3474
3475 /* Call-clobbered GP registers. */
3476 if ((regnum >= tdep->ppc_gp0_regnum + 3
3477 && regnum <= tdep->ppc_gp0_regnum + 12)
3478 || (regnum == tdep->ppc_gp0_regnum))
3479 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3480
3481 /* Deal with FP registers, if supported. */
3482 if (tdep->ppc_fp0_regnum >= 0)
3483 {
3484 /* Call-saved FP registers. */
3485 if ((regnum >= tdep->ppc_fp0_regnum + 14
3486 && regnum <= tdep->ppc_fp0_regnum + 31))
3487 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3488
3489 /* Call-clobbered FP registers. */
3490 if ((regnum >= tdep->ppc_fp0_regnum
3491 && regnum <= tdep->ppc_fp0_regnum + 13))
3492 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3493 }
3494
3495 /* Deal with ALTIVEC registers, if supported. */
3496 if (tdep->ppc_vr0_regnum > 0 && tdep->ppc_vrsave_regnum > 0)
3497 {
3498 /* Call-saved Altivec registers. */
3499 if ((regnum >= tdep->ppc_vr0_regnum + 20
3500 && regnum <= tdep->ppc_vr0_regnum + 31)
3501 || regnum == tdep->ppc_vrsave_regnum)
3502 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3503
3504 /* Call-clobbered Altivec registers. */
3505 if ((regnum >= tdep->ppc_vr0_regnum
3506 && regnum <= tdep->ppc_vr0_regnum + 19))
3507 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3508 }
3509
3510 /* Handle PC register and Stack Pointer correctly. */
40a6adc1 3511 if (regnum == gdbarch_pc_regnum (gdbarch))
9274a07c 3512 reg->how = DWARF2_FRAME_REG_RA;
40a6adc1 3513 else if (regnum == gdbarch_sp_regnum (gdbarch))
9274a07c
LM
3514 reg->how = DWARF2_FRAME_REG_CFA;
3515}
3516
3517
74af9197
NF
3518/* Return true if a .gnu_attributes section exists in BFD and it
3519 indicates we are using SPE extensions OR if a .PPC.EMB.apuinfo
3520 section exists in BFD and it indicates that SPE extensions are in
3521 use. Check the .gnu.attributes section first, as the binary might be
3522 compiled for SPE, but not actually using SPE instructions. */
3523
3524static int
3525bfd_uses_spe_extensions (bfd *abfd)
3526{
3527 asection *sect;
3528 gdb_byte *contents = NULL;
3529 bfd_size_type size;
3530 gdb_byte *ptr;
3531 int success = 0;
3532 int vector_abi;
3533
3534 if (!abfd)
3535 return 0;
3536
50a99728 3537#ifdef HAVE_ELF
74af9197
NF
3538 /* Using Tag_GNU_Power_ABI_Vector here is a bit of a hack, as the user
3539 could be using the SPE vector abi without actually using any spe
3540 bits whatsoever. But it's close enough for now. */
3541 vector_abi = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_GNU,
3542 Tag_GNU_Power_ABI_Vector);
3543 if (vector_abi == 3)
3544 return 1;
50a99728 3545#endif
74af9197
NF
3546
3547 sect = bfd_get_section_by_name (abfd, ".PPC.EMB.apuinfo");
3548 if (!sect)
3549 return 0;
3550
3551 size = bfd_get_section_size (sect);
3552 contents = xmalloc (size);
3553 if (!bfd_get_section_contents (abfd, sect, contents, 0, size))
3554 {
3555 xfree (contents);
3556 return 0;
3557 }
3558
3559 /* Parse the .PPC.EMB.apuinfo section. The layout is as follows:
3560
3561 struct {
3562 uint32 name_len;
3563 uint32 data_len;
3564 uint32 type;
3565 char name[name_len rounded up to 4-byte alignment];
3566 char data[data_len];
3567 };
3568
3569 Technically, there's only supposed to be one such structure in a
3570 given apuinfo section, but the linker is not always vigilant about
3571 merging apuinfo sections from input files. Just go ahead and parse
3572 them all, exiting early when we discover the binary uses SPE
3573 insns.
3574
3575 It's not specified in what endianness the information in this
3576 section is stored. Assume that it's the endianness of the BFD. */
3577 ptr = contents;
3578 while (1)
3579 {
3580 unsigned int name_len;
3581 unsigned int data_len;
3582 unsigned int type;
3583
3584 /* If we can't read the first three fields, we're done. */
3585 if (size < 12)
3586 break;
3587
3588 name_len = bfd_get_32 (abfd, ptr);
3589 name_len = (name_len + 3) & ~3U; /* Round to 4 bytes. */
3590 data_len = bfd_get_32 (abfd, ptr + 4);
3591 type = bfd_get_32 (abfd, ptr + 8);
3592 ptr += 12;
3593
3594 /* The name must be "APUinfo\0". */
3595 if (name_len != 8
3596 && strcmp ((const char *) ptr, "APUinfo") != 0)
3597 break;
3598 ptr += name_len;
3599
3600 /* The type must be 2. */
3601 if (type != 2)
3602 break;
3603
3604 /* The data is stored as a series of uint32. The upper half of
3605 each uint32 indicates the particular APU used and the lower
3606 half indicates the revision of that APU. We just care about
3607 the upper half. */
3608
3609 /* Not 4-byte quantities. */
3610 if (data_len & 3U)
3611 break;
3612
3613 while (data_len)
3614 {
3615 unsigned int apuinfo = bfd_get_32 (abfd, ptr);
3616 unsigned int apu = apuinfo >> 16;
3617 ptr += 4;
3618 data_len -= 4;
3619
3620 /* The SPE APU is 0x100; the SPEFP APU is 0x101. Accept
3621 either. */
3622 if (apu == 0x100 || apu == 0x101)
3623 {
3624 success = 1;
3625 data_len = 0;
3626 }
3627 }
3628
3629 if (success)
3630 break;
3631 }
3632
3633 xfree (contents);
3634 return success;
3635}
3636
b4cdae6f
WW
3637/* These are macros for parsing instruction fields (I.1.6.28) */
3638
3639#define PPC_FIELD(value, from, len) \
3640 (((value) >> (32 - (from) - (len))) & ((1 << (len)) - 1))
3641#define PPC_SEXT(v, bs) \
3642 ((((CORE_ADDR) (v) & (((CORE_ADDR) 1 << (bs)) - 1)) \
3643 ^ ((CORE_ADDR) 1 << ((bs) - 1))) \
3644 - ((CORE_ADDR) 1 << ((bs) - 1)))
3645#define PPC_OP6(insn) PPC_FIELD (insn, 0, 6)
3646#define PPC_EXTOP(insn) PPC_FIELD (insn, 21, 10)
3647#define PPC_RT(insn) PPC_FIELD (insn, 6, 5)
3648#define PPC_RS(insn) PPC_FIELD (insn, 6, 5)
3649#define PPC_RA(insn) PPC_FIELD (insn, 11, 5)
3650#define PPC_RB(insn) PPC_FIELD (insn, 16, 5)
3651#define PPC_NB(insn) PPC_FIELD (insn, 16, 5)
3652#define PPC_VRT(insn) PPC_FIELD (insn, 6, 5)
3653#define PPC_FRT(insn) PPC_FIELD (insn, 6, 5)
3654#define PPC_SPR(insn) (PPC_FIELD (insn, 11, 5) \
3655 | (PPC_FIELD (insn, 16, 5) << 5))
3656#define PPC_BO(insn) PPC_FIELD (insn, 6, 5)
3657#define PPC_T(insn) PPC_FIELD (insn, 6, 5)
3658#define PPC_D(insn) PPC_SEXT (PPC_FIELD (insn, 16, 16), 16)
3659#define PPC_DS(insn) PPC_SEXT (PPC_FIELD (insn, 16, 14), 14)
3660#define PPC_BIT(insn,n) ((insn & (1 << (31 - (n)))) ? 1 : 0)
3661#define PPC_OE(insn) PPC_BIT (insn, 21)
3662#define PPC_RC(insn) PPC_BIT (insn, 31)
3663#define PPC_Rc(insn) PPC_BIT (insn, 21)
3664#define PPC_LK(insn) PPC_BIT (insn, 31)
3665#define PPC_TX(insn) PPC_BIT (insn, 31)
3666#define PPC_LEV(insn) PPC_FIELD (insn, 20, 7)
3667
3668#define PPC_XT(insn) ((PPC_TX (insn) << 5) | PPC_T (insn))
3669#define PPC_XER_NB(xer) (xer & 0x7f)
3670
3671/* Record Vector-Scalar Registers. */
3672
3673static int
3674ppc_record_vsr (struct regcache *regcache, struct gdbarch_tdep *tdep, int vsr)
3675{
3676 if (vsr < 0 || vsr >= 64)
3677 return -1;
3678
3679 if (vsr >= 32)
3680 {
3681 if (tdep->ppc_vr0_regnum >= 0)
3682 record_full_arch_list_add_reg (regcache, tdep->ppc_vr0_regnum + vsr - 32);
3683 }
3684 else
3685 {
3686 if (tdep->ppc_fp0_regnum >= 0)
3687 record_full_arch_list_add_reg (regcache, tdep->ppc_fp0_regnum + vsr);
3688 if (tdep->ppc_vsr0_upper_regnum >= 0)
3689 record_full_arch_list_add_reg (regcache,
3690 tdep->ppc_vsr0_upper_regnum + vsr);
3691 }
3692
3693 return 0;
3694}
3695
3696/* Parse instructions of primary opcode-4. */
3697
3698static int
3699ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
3700 CORE_ADDR addr, uint32_t insn)
3701{
3702 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3703 int ext = PPC_FIELD (insn, 21, 11);
3704
3705 switch (ext & 0x3f)
3706 {
3707 case 32: /* Vector Multiply-High-Add Signed Halfword Saturate */
3708 case 33: /* Vector Multiply-High-Round-Add Signed Halfword Saturate */
3709 case 39: /* Vector Multiply-Sum Unsigned Halfword Saturate */
3710 case 41: /* Vector Multiply-Sum Signed Halfword Saturate */
3711 record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM);
3712 /* FALL-THROUGH */
3713 case 42: /* Vector Select */
3714 case 43: /* Vector Permute */
3715 case 44: /* Vector Shift Left Double by Octet Immediate */
3716 case 45: /* Vector Permute and Exclusive-OR */
3717 case 60: /* Vector Add Extended Unsigned Quadword Modulo */
3718 case 61: /* Vector Add Extended & write Carry Unsigned Quadword */
3719 case 62: /* Vector Subtract Extended Unsigned Quadword Modulo */
3720 case 63: /* Vector Subtract Extended & write Carry Unsigned Quadword */
3721 case 34: /* Vector Multiply-Low-Add Unsigned Halfword Modulo */
3722 case 36: /* Vector Multiply-Sum Unsigned Byte Modulo */
3723 case 37: /* Vector Multiply-Sum Mixed Byte Modulo */
3724 case 38: /* Vector Multiply-Sum Unsigned Halfword Modulo */
3725 case 40: /* Vector Multiply-Sum Signed Halfword Modulo */
3726 case 46: /* Vector Multiply-Add Single-Precision */
3727 case 47: /* Vector Negative Multiply-Subtract Single-Precision */
3728 record_full_arch_list_add_reg (regcache,
3729 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3730 return 0;
3731 }
3732
3733 switch ((ext & 0x1ff))
3734 {
3735 /* 5.16 Decimal Integer Arithmetic Instructions */
3736 case 1: /* Decimal Add Modulo */
3737 case 65: /* Decimal Subtract Modulo */
3738
3739 /* Bit-21 should be set. */
3740 if (!PPC_BIT (insn, 21))
3741 break;
3742
3743 record_full_arch_list_add_reg (regcache,
3744 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3745 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
3746 return 0;
3747 }
3748
3749 /* Bit-21 is used for RC */
3750 switch (ext & 0x3ff)
3751 {
3752 case 6: /* Vector Compare Equal To Unsigned Byte */
3753 case 70: /* Vector Compare Equal To Unsigned Halfword */
3754 case 134: /* Vector Compare Equal To Unsigned Word */
3755 case 199: /* Vector Compare Equal To Unsigned Doubleword */
3756 case 774: /* Vector Compare Greater Than Signed Byte */
3757 case 838: /* Vector Compare Greater Than Signed Halfword */
3758 case 902: /* Vector Compare Greater Than Signed Word */
3759 case 967: /* Vector Compare Greater Than Signed Doubleword */
3760 case 518: /* Vector Compare Greater Than Unsigned Byte */
3761 case 646: /* Vector Compare Greater Than Unsigned Word */
3762 case 582: /* Vector Compare Greater Than Unsigned Halfword */
3763 case 711: /* Vector Compare Greater Than Unsigned Doubleword */
3764 case 966: /* Vector Compare Bounds Single-Precision */
3765 case 198: /* Vector Compare Equal To Single-Precision */
3766 case 454: /* Vector Compare Greater Than or Equal To Single-Precision */
3767 case 710: /* Vector Compare Greater Than Single-Precision */
3768 if (PPC_Rc (insn))
3769 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
3770 record_full_arch_list_add_reg (regcache,
3771 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3772 return 0;
3773 }
3774
3775 switch (ext)
3776 {
3777 case 142: /* Vector Pack Unsigned Halfword Unsigned Saturate */
3778 case 206: /* Vector Pack Unsigned Word Unsigned Saturate */
3779 case 270: /* Vector Pack Signed Halfword Unsigned Saturate */
3780 case 334: /* Vector Pack Signed Word Unsigned Saturate */
3781 case 398: /* Vector Pack Signed Halfword Signed Saturate */
3782 case 462: /* Vector Pack Signed Word Signed Saturate */
3783 case 1230: /* Vector Pack Unsigned Doubleword Unsigned Saturate */
3784 case 1358: /* Vector Pack Signed Doubleword Unsigned Saturate */
3785 case 1486: /* Vector Pack Signed Doubleword Signed Saturate */
3786 case 512: /* Vector Add Unsigned Byte Saturate */
3787 case 576: /* Vector Add Unsigned Halfword Saturate */
3788 case 640: /* Vector Add Unsigned Word Saturate */
3789 case 768: /* Vector Add Signed Byte Saturate */
3790 case 832: /* Vector Add Signed Halfword Saturate */
3791 case 896: /* Vector Add Signed Word Saturate */
3792 case 1536: /* Vector Subtract Unsigned Byte Saturate */
3793 case 1600: /* Vector Subtract Unsigned Halfword Saturate */
3794 case 1664: /* Vector Subtract Unsigned Word Saturate */
3795 case 1792: /* Vector Subtract Signed Byte Saturate */
3796 case 1856: /* Vector Subtract Signed Halfword Saturate */
3797 case 1920: /* Vector Subtract Signed Word Saturate */
3798
3799 case 1544: /* Vector Sum across Quarter Unsigned Byte Saturate */
3800 case 1800: /* Vector Sum across Quarter Signed Byte Saturate */
3801 case 1608: /* Vector Sum across Quarter Signed Halfword Saturate */
3802 case 1672: /* Vector Sum across Half Signed Word Saturate */
3803 case 1928: /* Vector Sum across Signed Word Saturate */
3804 case 970: /* Vector Convert To Signed Fixed-Point Word Saturate */
3805 case 906: /* Vector Convert To Unsigned Fixed-Point Word Saturate */
3806 record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM);
3807 /* FALL-THROUGH */
3808 case 12: /* Vector Merge High Byte */
3809 case 14: /* Vector Pack Unsigned Halfword Unsigned Modulo */
3810 case 76: /* Vector Merge High Halfword */
3811 case 78: /* Vector Pack Unsigned Word Unsigned Modulo */
3812 case 140: /* Vector Merge High Word */
3813 case 268: /* Vector Merge Low Byte */
3814 case 332: /* Vector Merge Low Halfword */
3815 case 396: /* Vector Merge Low Word */
3816 case 526: /* Vector Unpack High Signed Byte */
3817 case 590: /* Vector Unpack High Signed Halfword */
3818 case 654: /* Vector Unpack Low Signed Byte */
3819 case 718: /* Vector Unpack Low Signed Halfword */
3820 case 782: /* Vector Pack Pixel */
3821 case 846: /* Vector Unpack High Pixel */
3822 case 974: /* Vector Unpack Low Pixel */
3823 case 1102: /* Vector Pack Unsigned Doubleword Unsigned Modulo */
3824 case 1614: /* Vector Unpack High Signed Word */
3825 case 1676: /* Vector Merge Odd Word */
3826 case 1742: /* Vector Unpack Low Signed Word */
3827 case 1932: /* Vector Merge Even Word */
3828 case 524: /* Vector Splat Byte */
3829 case 588: /* Vector Splat Halfword */
3830 case 652: /* Vector Splat Word */
3831 case 780: /* Vector Splat Immediate Signed Byte */
3832 case 844: /* Vector Splat Immediate Signed Halfword */
3833 case 908: /* Vector Splat Immediate Signed Word */
3834 case 452: /* Vector Shift Left */
3835 case 708: /* Vector Shift Right */
3836 case 1036: /* Vector Shift Left by Octet */
3837 case 1100: /* Vector Shift Right by Octet */
3838 case 0: /* Vector Add Unsigned Byte Modulo */
3839 case 64: /* Vector Add Unsigned Halfword Modulo */
3840 case 128: /* Vector Add Unsigned Word Modulo */
3841 case 192: /* Vector Add Unsigned Doubleword Modulo */
3842 case 256: /* Vector Add Unsigned Quadword Modulo */
3843 case 320: /* Vector Add & write Carry Unsigned Quadword */
3844 case 384: /* Vector Add and Write Carry-Out Unsigned Word */
3845 case 8: /* Vector Multiply Odd Unsigned Byte */
3846 case 72: /* Vector Multiply Odd Unsigned Halfword */
3847 case 136: /* Vector Multiply Odd Unsigned Word */
3848 case 264: /* Vector Multiply Odd Signed Byte */
3849 case 328: /* Vector Multiply Odd Signed Halfword */
3850 case 392: /* Vector Multiply Odd Signed Word */
3851 case 520: /* Vector Multiply Even Unsigned Byte */
3852 case 584: /* Vector Multiply Even Unsigned Halfword */
3853 case 648: /* Vector Multiply Even Unsigned Word */
3854 case 776: /* Vector Multiply Even Signed Byte */
3855 case 840: /* Vector Multiply Even Signed Halfword */
3856 case 904: /* Vector Multiply Even Signed Word */
3857 case 137: /* Vector Multiply Unsigned Word Modulo */
3858 case 1024: /* Vector Subtract Unsigned Byte Modulo */
3859 case 1088: /* Vector Subtract Unsigned Halfword Modulo */
3860 case 1152: /* Vector Subtract Unsigned Word Modulo */
3861 case 1216: /* Vector Subtract Unsigned Doubleword Modulo */
3862 case 1280: /* Vector Subtract Unsigned Quadword Modulo */
3863 case 1344: /* Vector Subtract & write Carry Unsigned Quadword */
3864 case 1408: /* Vector Subtract and Write Carry-Out Unsigned Word */
3865 case 1282: /* Vector Average Signed Byte */
3866 case 1346: /* Vector Average Signed Halfword */
3867 case 1410: /* Vector Average Signed Word */
3868 case 1026: /* Vector Average Unsigned Byte */
3869 case 1090: /* Vector Average Unsigned Halfword */
3870 case 1154: /* Vector Average Unsigned Word */
3871 case 258: /* Vector Maximum Signed Byte */
3872 case 322: /* Vector Maximum Signed Halfword */
3873 case 386: /* Vector Maximum Signed Word */
3874 case 450: /* Vector Maximum Signed Doubleword */
3875 case 2: /* Vector Maximum Unsigned Byte */
3876 case 66: /* Vector Maximum Unsigned Halfword */
3877 case 130: /* Vector Maximum Unsigned Word */
3878 case 194: /* Vector Maximum Unsigned Doubleword */
3879 case 770: /* Vector Minimum Signed Byte */
3880 case 834: /* Vector Minimum Signed Halfword */
3881 case 898: /* Vector Minimum Signed Word */
3882 case 962: /* Vector Minimum Signed Doubleword */
3883 case 514: /* Vector Minimum Unsigned Byte */
3884 case 578: /* Vector Minimum Unsigned Halfword */
3885 case 642: /* Vector Minimum Unsigned Word */
3886 case 706: /* Vector Minimum Unsigned Doubleword */
3887 case 1028: /* Vector Logical AND */
3888 case 1668: /* Vector Logical Equivalent */
3889 case 1092: /* Vector Logical AND with Complement */
3890 case 1412: /* Vector Logical NAND */
3891 case 1348: /* Vector Logical OR with Complement */
3892 case 1156: /* Vector Logical OR */
3893 case 1284: /* Vector Logical NOR */
3894 case 1220: /* Vector Logical XOR */
3895 case 4: /* Vector Rotate Left Byte */
3896 case 132: /* Vector Rotate Left Word VX-form */
3897 case 68: /* Vector Rotate Left Halfword */
3898 case 196: /* Vector Rotate Left Doubleword */
3899 case 260: /* Vector Shift Left Byte */
3900 case 388: /* Vector Shift Left Word */
3901 case 324: /* Vector Shift Left Halfword */
3902 case 1476: /* Vector Shift Left Doubleword */
3903 case 516: /* Vector Shift Right Byte */
3904 case 644: /* Vector Shift Right Word */
3905 case 580: /* Vector Shift Right Halfword */
3906 case 1732: /* Vector Shift Right Doubleword */
3907 case 772: /* Vector Shift Right Algebraic Byte */
3908 case 900: /* Vector Shift Right Algebraic Word */
3909 case 836: /* Vector Shift Right Algebraic Halfword */
3910 case 964: /* Vector Shift Right Algebraic Doubleword */
3911 case 10: /* Vector Add Single-Precision */
3912 case 74: /* Vector Subtract Single-Precision */
3913 case 1034: /* Vector Maximum Single-Precision */
3914 case 1098: /* Vector Minimum Single-Precision */
3915 case 842: /* Vector Convert From Signed Fixed-Point Word */
3916 case 778: /* Vector Convert From Unsigned Fixed-Point Word */
3917 case 714: /* Vector Round to Single-Precision Integer toward -Infinity */
3918 case 522: /* Vector Round to Single-Precision Integer Nearest */
3919 case 650: /* Vector Round to Single-Precision Integer toward +Infinity */
3920 case 586: /* Vector Round to Single-Precision Integer toward Zero */
3921 case 394: /* Vector 2 Raised to the Exponent Estimate Floating-Point */
3922 case 458: /* Vector Log Base 2 Estimate Floating-Point */
3923 case 266: /* Vector Reciprocal Estimate Single-Precision */
3924 case 330: /* Vector Reciprocal Square Root Estimate Single-Precision */
3925 case 1288: /* Vector AES Cipher */
3926 case 1289: /* Vector AES Cipher Last */
3927 case 1352: /* Vector AES Inverse Cipher */
3928 case 1353: /* Vector AES Inverse Cipher Last */
3929 case 1480: /* Vector AES SubBytes */
3930 case 1730: /* Vector SHA-512 Sigma Doubleword */
3931 case 1666: /* Vector SHA-256 Sigma Word */
3932 case 1032: /* Vector Polynomial Multiply-Sum Byte */
3933 case 1160: /* Vector Polynomial Multiply-Sum Word */
3934 case 1096: /* Vector Polynomial Multiply-Sum Halfword */
3935 case 1224: /* Vector Polynomial Multiply-Sum Doubleword */
3936 case 1292: /* Vector Gather Bits by Bytes by Doubleword */
3937 case 1794: /* Vector Count Leading Zeros Byte */
3938 case 1858: /* Vector Count Leading Zeros Halfword */
3939 case 1922: /* Vector Count Leading Zeros Word */
3940 case 1986: /* Vector Count Leading Zeros Doubleword */
3941 case 1795: /* Vector Population Count Byte */
3942 case 1859: /* Vector Population Count Halfword */
3943 case 1923: /* Vector Population Count Word */
3944 case 1987: /* Vector Population Count Doubleword */
3945 case 1356: /* Vector Bit Permute Quadword */
3946 record_full_arch_list_add_reg (regcache,
3947 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3948 return 0;
3949
3950 case 1604: /* Move To Vector Status and Control Register */
3951 record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM);
3952 return 0;
3953 case 1540: /* Move From Vector Status and Control Register */
3954 record_full_arch_list_add_reg (regcache,
3955 tdep->ppc_vr0_regnum + PPC_VRT (insn));
3956 return 0;
3957 }
3958
810c1026
WW
3959 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
3960 "at %s, 4-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
3961 return -1;
3962}
3963
3964/* Parse instructions of primary opcode-19. */
3965
3966static int
3967ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
3968 CORE_ADDR addr, uint32_t insn)
3969{
3970 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3971 int ext = PPC_EXTOP (insn);
3972
3973 switch (ext)
3974 {
3975 case 0: /* Move Condition Register Field */
3976 case 33: /* Condition Register NOR */
3977 case 129: /* Condition Register AND with Complement */
3978 case 193: /* Condition Register XOR */
3979 case 225: /* Condition Register NAND */
3980 case 257: /* Condition Register AND */
3981 case 289: /* Condition Register Equivalent */
3982 case 417: /* Condition Register OR with Complement */
3983 case 449: /* Condition Register OR */
3984 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
3985 return 0;
3986
3987 case 16: /* Branch Conditional */
3988 case 560: /* Branch Conditional to Branch Target Address Register */
3989 if ((PPC_BO (insn) & 0x4) == 0)
3990 record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum);
3991 /* FALL-THROUGH */
3992 case 528: /* Branch Conditional to Count Register */
3993 if (PPC_LK (insn))
3994 record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum);
3995 return 0;
3996
3997 case 150: /* Instruction Synchronize */
3998 /* Do nothing. */
3999 return 0;
4000 }
4001
810c1026
WW
4002 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4003 "at %s, 19-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4004 return -1;
4005}
4006
4007/* Parse instructions of primary opcode-31. */
4008
4009static int
4010ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
4011 CORE_ADDR addr, uint32_t insn)
4012{
4013 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4014 int ext = PPC_EXTOP (insn);
4015 int tmp, nr, nb, i;
4016 CORE_ADDR at_dcsz, ea = 0;
4017 ULONGEST rb, ra, xer;
4018 int size = 0;
4019
4020 /* These instructions have OE bit. */
4021 switch (ext & 0x1ff)
4022 {
4023 /* These write RT and XER. Update CR if RC is set. */
4024 case 8: /* Subtract from carrying */
4025 case 10: /* Add carrying */
4026 case 136: /* Subtract from extended */
4027 case 138: /* Add extended */
4028 case 200: /* Subtract from zero extended */
4029 case 202: /* Add to zero extended */
4030 case 232: /* Subtract from minus one extended */
4031 case 234: /* Add to minus one extended */
4032 /* CA is always altered, but SO/OV are only altered when OE=1.
4033 In any case, XER is always altered. */
4034 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4035 if (PPC_RC (insn))
4036 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4037 record_full_arch_list_add_reg (regcache,
4038 tdep->ppc_gp0_regnum + PPC_RT (insn));
4039 return 0;
4040
4041 /* These write RT. Update CR if RC is set and update XER if OE is set. */
4042 case 40: /* Subtract from */
4043 case 104: /* Negate */
4044 case 233: /* Multiply low doubleword */
4045 case 235: /* Multiply low word */
4046 case 266: /* Add */
4047 case 393: /* Divide Doubleword Extended Unsigned */
4048 case 395: /* Divide Word Extended Unsigned */
4049 case 425: /* Divide Doubleword Extended */
4050 case 427: /* Divide Word Extended */
4051 case 457: /* Divide Doubleword Unsigned */
4052 case 459: /* Divide Word Unsigned */
4053 case 489: /* Divide Doubleword */
4054 case 491: /* Divide Word */
4055 if (PPC_OE (insn))
4056 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4057 /* FALL-THROUGH */
4058 case 9: /* Multiply High Doubleword Unsigned */
4059 case 11: /* Multiply High Word Unsigned */
4060 case 73: /* Multiply High Doubleword */
4061 case 75: /* Multiply High Word */
4062 if (PPC_RC (insn))
4063 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4064 record_full_arch_list_add_reg (regcache,
4065 tdep->ppc_gp0_regnum + PPC_RT (insn));
4066 return 0;
4067 }
4068
4069 if ((ext & 0x1f) == 15)
4070 {
4071 /* Integer Select. bit[16:20] is used for BC. */
4072 record_full_arch_list_add_reg (regcache,
4073 tdep->ppc_gp0_regnum + PPC_RT (insn));
4074 return 0;
4075 }
4076
4077 switch (ext)
4078 {
4079 case 78: /* Determine Leftmost Zero Byte */
4080 if (PPC_RC (insn))
4081 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4082 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4083 record_full_arch_list_add_reg (regcache,
4084 tdep->ppc_gp0_regnum + PPC_RT (insn));
4085 return 0;
4086
4087 /* These only write RT. */
4088 case 19: /* Move from condition register */
4089 /* Move From One Condition Register Field */
4090 case 74: /* Add and Generate Sixes */
4091 case 74 | 0x200: /* Add and Generate Sixes (bit-21 dont-care) */
4092 case 302: /* Move From Branch History Rolling Buffer */
4093 case 339: /* Move From Special Purpose Register */
4094 case 371: /* Move From Time Base [Phased-Out] */
4095 record_full_arch_list_add_reg (regcache,
4096 tdep->ppc_gp0_regnum + PPC_RT (insn));
4097 return 0;
4098
4099 /* These only write to RA. */
4100 case 51: /* Move From VSR Doubleword */
4101 case 115: /* Move From VSR Word and Zero */
4102 case 122: /* Population count bytes */
4103 case 378: /* Population count words */
4104 case 506: /* Population count doublewords */
4105 case 154: /* Parity Word */
4106 case 186: /* Parity Doubleword */
4107 case 252: /* Bit Permute Doubleword */
4108 case 282: /* Convert Declets To Binary Coded Decimal */
4109 case 314: /* Convert Binary Coded Decimal To Declets */
4110 case 508: /* Compare bytes */
4111 record_full_arch_list_add_reg (regcache,
4112 tdep->ppc_gp0_regnum + PPC_RA (insn));
4113 return 0;
4114
4115 /* These write CR and optional RA. */
4116 case 792: /* Shift Right Algebraic Word */
4117 case 794: /* Shift Right Algebraic Doubleword */
4118 case 824: /* Shift Right Algebraic Word Immediate */
4119 case 826: /* Shift Right Algebraic Doubleword Immediate (413) */
4120 case 826 | 1: /* Shift Right Algebraic Doubleword Immediate (413) */
4121 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4122 record_full_arch_list_add_reg (regcache,
4123 tdep->ppc_gp0_regnum + PPC_RA (insn));
4124 /* FALL-THROUGH */
4125 case 0: /* Compare */
4126 case 32: /* Compare logical */
4127 case 144: /* Move To Condition Register Fields */
4128 /* Move To One Condition Register Field */
4129 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4130 return 0;
4131
4132 /* These write to RT. Update RA if 'update indexed.' */
4133 case 53: /* Load Doubleword with Update Indexed */
4134 case 119: /* Load Byte and Zero with Update Indexed */
4135 case 311: /* Load Halfword and Zero with Update Indexed */
4136 case 55: /* Load Word and Zero with Update Indexed */
4137 case 375: /* Load Halfword Algebraic with Update Indexed */
4138 case 373: /* Load Word Algebraic with Update Indexed */
4139 record_full_arch_list_add_reg (regcache,
4140 tdep->ppc_gp0_regnum + PPC_RA (insn));
4141 /* FALL-THROUGH */
4142 case 21: /* Load Doubleword Indexed */
4143 case 52: /* Load Byte And Reserve Indexed */
4144 case 116: /* Load Halfword And Reserve Indexed */
4145 case 20: /* Load Word And Reserve Indexed */
4146 case 84: /* Load Doubleword And Reserve Indexed */
4147 case 87: /* Load Byte and Zero Indexed */
4148 case 279: /* Load Halfword and Zero Indexed */
4149 case 23: /* Load Word and Zero Indexed */
4150 case 343: /* Load Halfword Algebraic Indexed */
4151 case 341: /* Load Word Algebraic Indexed */
4152 case 790: /* Load Halfword Byte-Reverse Indexed */
4153 case 534: /* Load Word Byte-Reverse Indexed */
4154 case 532: /* Load Doubleword Byte-Reverse Indexed */
4155 record_full_arch_list_add_reg (regcache,
4156 tdep->ppc_gp0_regnum + PPC_RT (insn));
4157 return 0;
4158
4159 case 597: /* Load String Word Immediate */
4160 case 533: /* Load String Word Indexed */
4161 if (ext == 597)
4162 {
4163 nr = PPC_NB (insn);
4164 if (nr == 0)
4165 nr = 32;
4166 }
4167 else
4168 {
4169 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &xer);
4170 nr = PPC_XER_NB (xer);
4171 }
4172
4173 nr = (nr + 3) >> 2;
4174
4175 /* If n=0, the contents of register RT are undefined. */
4176 if (nr == 0)
4177 nr = 1;
4178
4179 for (i = 0; i < nr; i++)
4180 record_full_arch_list_add_reg (regcache,
4181 tdep->ppc_gp0_regnum
4182 + ((PPC_RT (insn) + i) & 0x1f));
4183 return 0;
4184
4185 case 276: /* Load Quadword And Reserve Indexed */
4186 tmp = tdep->ppc_gp0_regnum + (PPC_RT (insn) & ~1);
4187 record_full_arch_list_add_reg (regcache, tmp);
4188 record_full_arch_list_add_reg (regcache, tmp + 1);
4189 return 0;
4190
4191 /* These write VRT. */
4192 case 6: /* Load Vector for Shift Left Indexed */
4193 case 38: /* Load Vector for Shift Right Indexed */
4194 case 7: /* Load Vector Element Byte Indexed */
4195 case 39: /* Load Vector Element Halfword Indexed */
4196 case 71: /* Load Vector Element Word Indexed */
4197 case 103: /* Load Vector Indexed */
4198 case 359: /* Load Vector Indexed LRU */
4199 record_full_arch_list_add_reg (regcache,
4200 tdep->ppc_vr0_regnum + PPC_VRT (insn));
4201 return 0;
4202
4203 /* These write FRT. Update RA if 'update indexed.' */
4204 case 567: /* Load Floating-Point Single with Update Indexed */
4205 case 631: /* Load Floating-Point Double with Update Indexed */
4206 record_full_arch_list_add_reg (regcache,
4207 tdep->ppc_gp0_regnum + PPC_RA (insn));
4208 /* FALL-THROUGH */
4209 case 535: /* Load Floating-Point Single Indexed */
4210 case 599: /* Load Floating-Point Double Indexed */
4211 case 855: /* Load Floating-Point as Integer Word Algebraic Indexed */
4212 case 887: /* Load Floating-Point as Integer Word and Zero Indexed */
4213 record_full_arch_list_add_reg (regcache,
4214 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4215 return 0;
4216
4217 case 791: /* Load Floating-Point Double Pair Indexed */
4218 tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1);
4219 record_full_arch_list_add_reg (regcache, tmp);
4220 record_full_arch_list_add_reg (regcache, tmp + 1);
4221 return 0;
4222
4223 case 179: /* Move To VSR Doubleword */
4224 case 211: /* Move To VSR Word Algebraic */
4225 case 243: /* Move To VSR Word and Zero */
4226 case 588: /* Load VSX Scalar Doubleword Indexed */
4227 case 524: /* Load VSX Scalar Single-Precision Indexed */
4228 case 76: /* Load VSX Scalar as Integer Word Algebraic Indexed */
4229 case 12: /* Load VSX Scalar as Integer Word and Zero Indexed */
4230 case 844: /* Load VSX Vector Doubleword*2 Indexed */
4231 case 332: /* Load VSX Vector Doubleword & Splat Indexed */
4232 case 780: /* Load VSX Vector Word*4 Indexed */
4233 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4234 return 0;
4235
4236 /* These write RA. Update CR if RC is set. */
4237 case 24: /* Shift Left Word */
4238 case 26: /* Count Leading Zeros Word */
4239 case 27: /* Shift Left Doubleword */
4240 case 28: /* AND */
4241 case 58: /* Count Leading Zeros Doubleword */
4242 case 60: /* AND with Complement */
4243 case 124: /* NOR */
4244 case 284: /* Equivalent */
4245 case 316: /* XOR */
4246 case 476: /* NAND */
4247 case 412: /* OR with Complement */
4248 case 444: /* OR */
4249 case 536: /* Shift Right Word */
4250 case 539: /* Shift Right Doubleword */
4251 case 922: /* Extend Sign Halfword */
4252 case 954: /* Extend Sign Byte */
4253 case 986: /* Extend Sign Word */
4254 if (PPC_RC (insn))
4255 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4256 record_full_arch_list_add_reg (regcache,
4257 tdep->ppc_gp0_regnum + PPC_RA (insn));
4258 return 0;
4259
4260 /* Store memory. */
4261 case 181: /* Store Doubleword with Update Indexed */
4262 case 183: /* Store Word with Update Indexed */
4263 case 247: /* Store Byte with Update Indexed */
4264 case 439: /* Store Half Word with Update Indexed */
4265 case 695: /* Store Floating-Point Single with Update Indexed */
4266 case 759: /* Store Floating-Point Double with Update Indexed */
4267 record_full_arch_list_add_reg (regcache,
4268 tdep->ppc_gp0_regnum + PPC_RA (insn));
4269 /* FALL-THROUGH */
4270 case 135: /* Store Vector Element Byte Indexed */
4271 case 167: /* Store Vector Element Halfword Indexed */
4272 case 199: /* Store Vector Element Word Indexed */
4273 case 231: /* Store Vector Indexed */
4274 case 487: /* Store Vector Indexed LRU */
4275 case 716: /* Store VSX Scalar Doubleword Indexed */
4276 case 140: /* Store VSX Scalar as Integer Word Indexed */
4277 case 652: /* Store VSX Scalar Single-Precision Indexed */
4278 case 972: /* Store VSX Vector Doubleword*2 Indexed */
4279 case 908: /* Store VSX Vector Word*4 Indexed */
4280 case 149: /* Store Doubleword Indexed */
4281 case 151: /* Store Word Indexed */
4282 case 215: /* Store Byte Indexed */
4283 case 407: /* Store Half Word Indexed */
4284 case 694: /* Store Byte Conditional Indexed */
4285 case 726: /* Store Halfword Conditional Indexed */
4286 case 150: /* Store Word Conditional Indexed */
4287 case 214: /* Store Doubleword Conditional Indexed */
4288 case 182: /* Store Quadword Conditional Indexed */
4289 case 662: /* Store Word Byte-Reverse Indexed */
4290 case 918: /* Store Halfword Byte-Reverse Indexed */
4291 case 660: /* Store Doubleword Byte-Reverse Indexed */
4292 case 663: /* Store Floating-Point Single Indexed */
4293 case 727: /* Store Floating-Point Double Indexed */
4294 case 919: /* Store Floating-Point Double Pair Indexed */
4295 case 983: /* Store Floating-Point as Integer Word Indexed */
4296 if (ext == 694 || ext == 726 || ext == 150 || ext == 214 || ext == 182)
4297 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4298
4299 ra = 0;
4300 if (PPC_RA (insn) != 0)
4301 regcache_raw_read_unsigned (regcache,
4302 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
4303 regcache_raw_read_unsigned (regcache,
4304 tdep->ppc_gp0_regnum + PPC_RB (insn), &rb);
4305 ea = ra + rb;
4306
4307 switch (ext)
4308 {
4309 case 183: /* Store Word with Update Indexed */
4310 case 199: /* Store Vector Element Word Indexed */
4311 case 140: /* Store VSX Scalar as Integer Word Indexed */
4312 case 652: /* Store VSX Scalar Single-Precision Indexed */
4313 case 151: /* Store Word Indexed */
4314 case 150: /* Store Word Conditional Indexed */
4315 case 662: /* Store Word Byte-Reverse Indexed */
4316 case 663: /* Store Floating-Point Single Indexed */
4317 case 695: /* Store Floating-Point Single with Update Indexed */
4318 case 983: /* Store Floating-Point as Integer Word Indexed */
4319 size = 4;
4320 break;
4321 case 247: /* Store Byte with Update Indexed */
4322 case 135: /* Store Vector Element Byte Indexed */
4323 case 215: /* Store Byte Indexed */
4324 case 694: /* Store Byte Conditional Indexed */
4325 size = 1;
4326 break;
4327 case 439: /* Store Halfword with Update Indexed */
4328 case 167: /* Store Vector Element Halfword Indexed */
4329 case 407: /* Store Halfword Indexed */
4330 case 726: /* Store Halfword Conditional Indexed */
4331 case 918: /* Store Halfword Byte-Reverse Indexed */
4332 size = 2;
4333 break;
4334 case 181: /* Store Doubleword with Update Indexed */
4335 case 716: /* Store VSX Scalar Doubleword Indexed */
4336 case 149: /* Store Doubleword Indexed */
4337 case 214: /* Store Doubleword Conditional Indexed */
4338 case 660: /* Store Doubleword Byte-Reverse Indexed */
4339 case 727: /* Store Floating-Point Double Indexed */
4340 case 759: /* Store Floating-Point Double with Update Indexed */
4341 size = 8;
4342 break;
4343 case 972: /* Store VSX Vector Doubleword*2 Indexed */
4344 case 908: /* Store VSX Vector Word*4 Indexed */
4345 case 182: /* Store Quadword Conditional Indexed */
4346 case 231: /* Store Vector Indexed */
4347 case 487: /* Store Vector Indexed LRU */
4348 case 919: /* Store Floating-Point Double Pair Indexed */
4349 size = 16;
4350 break;
4351 default:
4352 gdb_assert (0);
4353 }
4354
4355 /* Align address for Store Vector instructions. */
4356 switch (ext)
4357 {
4358 case 167: /* Store Vector Element Halfword Indexed */
4359 addr = addr & ~0x1ULL;
4360 break;
4361
4362 case 199: /* Store Vector Element Word Indexed */
4363 addr = addr & ~0x3ULL;
4364 break;
4365
4366 case 231: /* Store Vector Indexed */
4367 case 487: /* Store Vector Indexed LRU */
4368 addr = addr & ~0xfULL;
4369 break;
4370 }
4371
4372 record_full_arch_list_add_mem (addr, size);
4373 return 0;
4374
4375 case 725: /* Store String Word Immediate */
4376 ra = 0;
4377 if (PPC_RA (insn) != 0)
4378 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &ra);
4379 ea += ra;
4380
4381 nb = PPC_NB (insn);
4382 if (nb == 0)
4383 nb = 32;
4384
4385 record_full_arch_list_add_mem (ea, nb);
4386
4387 return 0;
4388
4389 case 661: /* Store String Word Indexed */
4390 ra = 0;
4391 if (PPC_RA (insn) != 0)
4392 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &ra);
4393 ea += ra;
4394
4395 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &xer);
4396 nb = PPC_XER_NB (xer);
4397
4398 if (nb != 0)
4399 {
4400 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &rb);
4401 ea += rb;
4402 record_full_arch_list_add_mem (ea, nb);
4403 }
4404
4405 return 0;
4406
4407 case 467: /* Move To Special Purpose Register */
4408 switch (PPC_SPR (insn))
4409 {
4410 case 1: /* XER */
4411 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4412 return 0;
4413 case 8: /* LR */
4414 record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum);
4415 return 0;
4416 case 9: /* CTR */
4417 record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum);
4418 return 0;
4419 case 256: /* VRSAVE */
4420 record_full_arch_list_add_reg (regcache, tdep->ppc_vrsave_regnum);
4421 return 0;
4422 }
4423
4424 goto UNKNOWN_OP;
4425
4426 case 147: /* Move To Split Little Endian */
4427 record_full_arch_list_add_reg (regcache, tdep->ppc_ps_regnum);
4428 return 0;
4429
4430 case 512: /* Move to Condition Register from XER */
4431 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4432 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4433 return 0;
4434
4435 case 4: /* Trap Word */
4436 case 68: /* Trap Doubleword */
4437 case 430: /* Clear BHRB */
4438 case 598: /* Synchronize */
4439 case 62: /* Wait for Interrupt */
4440 case 22: /* Instruction Cache Block Touch */
4441 case 854: /* Enforce In-order Execution of I/O */
4442 case 246: /* Data Cache Block Touch for Store */
4443 case 54: /* Data Cache Block Store */
4444 case 86: /* Data Cache Block Flush */
4445 case 278: /* Data Cache Block Touch */
4446 case 758: /* Data Cache Block Allocate */
4447 case 982: /* Instruction Cache Block Invalidate */
4448 return 0;
4449
4450 case 654: /* Transaction Begin */
4451 case 686: /* Transaction End */
4452 case 718: /* Transaction Check */
4453 case 750: /* Transaction Suspend or Resume */
4454 case 782: /* Transaction Abort Word Conditional */
4455 case 814: /* Transaction Abort Doubleword Conditional */
4456 case 846: /* Transaction Abort Word Conditional Immediate */
4457 case 878: /* Transaction Abort Doubleword Conditional Immediate */
4458 case 910: /* Transaction Abort */
4459 fprintf_unfiltered (gdb_stdlog, "Cannot record Transaction instructions. "
810c1026
WW
4460 "%08x at %s, 31-%d.\n",
4461 insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4462 return -1;
4463
4464 case 1014: /* Data Cache Block set to Zero */
4465 if (target_auxv_search (&current_target, AT_DCACHEBSIZE, &at_dcsz) <= 0
4466 || at_dcsz == 0)
4467 at_dcsz = 128; /* Assume 128-byte cache line size (POWER8) */
4468
4469 if (PPC_RA (insn) != 0)
4470 regcache_raw_read_unsigned (regcache,
4471 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
4472 regcache_raw_read_unsigned (regcache,
4473 tdep->ppc_gp0_regnum + PPC_RB (insn), &rb);
4474 ea = (ra + rb) & ~((ULONGEST) (at_dcsz - 1));
4475 record_full_arch_list_add_mem (ea, at_dcsz);
4476 return 0;
4477 }
4478
4479UNKNOWN_OP:
810c1026
WW
4480 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4481 "at %s, 31-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4482 return -1;
4483}
4484
4485/* Parse instructions of primary opcode-59. */
4486
4487static int
4488ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
4489 CORE_ADDR addr, uint32_t insn)
4490{
4491 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4492 int ext = PPC_EXTOP (insn);
4493
4494 switch (ext & 0x1f)
4495 {
4496 case 18: /* Floating Divide */
4497 case 20: /* Floating Subtract */
4498 case 21: /* Floating Add */
4499 case 22: /* Floating Square Root */
4500 case 24: /* Floating Reciprocal Estimate */
4501 case 25: /* Floating Multiply */
4502 case 26: /* Floating Reciprocal Square Root Estimate */
4503 case 28: /* Floating Multiply-Subtract */
4504 case 29: /* Floating Multiply-Add */
4505 case 30: /* Floating Negative Multiply-Subtract */
4506 case 31: /* Floating Negative Multiply-Add */
4507 record_full_arch_list_add_reg (regcache,
4508 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4509 if (PPC_RC (insn))
4510 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4511 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4512
4513 return 0;
4514 }
4515
4516 switch (ext)
4517 {
4518 case 2: /* DFP Add */
4519 case 3: /* DFP Quantize */
4520 case 34: /* DFP Multiply */
4521 case 35: /* DFP Reround */
4522 case 67: /* DFP Quantize Immediate */
4523 case 99: /* DFP Round To FP Integer With Inexact */
4524 case 227: /* DFP Round To FP Integer Without Inexact */
4525 case 258: /* DFP Convert To DFP Long! */
4526 case 290: /* DFP Convert To Fixed */
4527 case 514: /* DFP Subtract */
4528 case 546: /* DFP Divide */
4529 case 770: /* DFP Round To DFP Short! */
4530 case 802: /* DFP Convert From Fixed */
4531 case 834: /* DFP Encode BCD To DPD */
4532 if (PPC_RC (insn))
4533 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4534 record_full_arch_list_add_reg (regcache,
4535 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4536 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4537 return 0;
4538
4539 case 130: /* DFP Compare Ordered */
4540 case 162: /* DFP Test Exponent */
4541 case 194: /* DFP Test Data Class */
4542 case 226: /* DFP Test Data Group */
4543 case 642: /* DFP Compare Unordered */
4544 case 674: /* DFP Test Significance */
4545 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4546 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4547 return 0;
4548
4549 case 66: /* DFP Shift Significand Left Immediate */
4550 case 98: /* DFP Shift Significand Right Immediate */
4551 case 322: /* DFP Decode DPD To BCD */
4552 case 354: /* DFP Extract Biased Exponent */
4553 case 866: /* DFP Insert Biased Exponent */
4554 record_full_arch_list_add_reg (regcache,
4555 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4556 if (PPC_RC (insn))
4557 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4558 return 0;
4559
4560 case 846: /* Floating Convert From Integer Doubleword Single */
4561 case 974: /* Floating Convert From Integer Doubleword Unsigned
4562 Single */
4563 record_full_arch_list_add_reg (regcache,
4564 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4565 if (PPC_RC (insn))
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
4569 return 0;
4570 }
4571
810c1026
WW
4572 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4573 "at %s, 59-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4574 return -1;
4575}
4576
4577/* Parse instructions of primary opcode-60. */
4578
4579static int
4580ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
4581 CORE_ADDR addr, uint32_t insn)
4582{
4583 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4584 int ext = PPC_EXTOP (insn);
b4cdae6f
WW
4585
4586 switch (ext >> 2)
4587 {
4588 case 0: /* VSX Scalar Add Single-Precision */
4589 case 32: /* VSX Scalar Add Double-Precision */
4590 case 24: /* VSX Scalar Divide Single-Precision */
4591 case 56: /* VSX Scalar Divide Double-Precision */
4592 case 176: /* VSX Scalar Copy Sign Double-Precision */
4593 case 33: /* VSX Scalar Multiply-Add Double-Precision */
4594 case 41: /* ditto */
4595 case 1: /* VSX Scalar Multiply-Add Single-Precision */
4596 case 9: /* ditto */
4597 case 160: /* VSX Scalar Maximum Double-Precision */
4598 case 168: /* VSX Scalar Minimum Double-Precision */
4599 case 49: /* VSX Scalar Multiply-Subtract Double-Precision */
4600 case 57: /* ditto */
4601 case 17: /* VSX Scalar Multiply-Subtract Single-Precision */
4602 case 25: /* ditto */
4603 case 48: /* VSX Scalar Multiply Double-Precision */
4604 case 16: /* VSX Scalar Multiply Single-Precision */
4605 case 161: /* VSX Scalar Negative Multiply-Add Double-Precision */
4606 case 169: /* ditto */
4607 case 129: /* VSX Scalar Negative Multiply-Add Single-Precision */
4608 case 137: /* ditto */
4609 case 177: /* VSX Scalar Negative Multiply-Subtract Double-Precision */
4610 case 185: /* ditto */
4611 case 145: /* VSX Scalar Negative Multiply-Subtract Single-Precision */
4612 case 153: /* ditto */
4613 case 40: /* VSX Scalar Subtract Double-Precision */
4614 case 8: /* VSX Scalar Subtract Single-Precision */
4615 case 96: /* VSX Vector Add Double-Precision */
4616 case 64: /* VSX Vector Add Single-Precision */
4617 case 120: /* VSX Vector Divide Double-Precision */
4618 case 88: /* VSX Vector Divide Single-Precision */
4619 case 97: /* VSX Vector Multiply-Add Double-Precision */
4620 case 105: /* ditto */
4621 case 65: /* VSX Vector Multiply-Add Single-Precision */
4622 case 73: /* ditto */
4623 case 224: /* VSX Vector Maximum Double-Precision */
4624 case 192: /* VSX Vector Maximum Single-Precision */
4625 case 232: /* VSX Vector Minimum Double-Precision */
4626 case 200: /* VSX Vector Minimum Single-Precision */
4627 case 113: /* VSX Vector Multiply-Subtract Double-Precision */
4628 case 121: /* ditto */
4629 case 81: /* VSX Vector Multiply-Subtract Single-Precision */
4630 case 89: /* ditto */
4631 case 112: /* VSX Vector Multiply Double-Precision */
4632 case 80: /* VSX Vector Multiply Single-Precision */
4633 case 225: /* VSX Vector Negative Multiply-Add Double-Precision */
4634 case 233: /* ditto */
4635 case 193: /* VSX Vector Negative Multiply-Add Single-Precision */
4636 case 201: /* ditto */
4637 case 241: /* VSX Vector Negative Multiply-Subtract Double-Precision */
4638 case 249: /* ditto */
4639 case 209: /* VSX Vector Negative Multiply-Subtract Single-Precision */
4640 case 217: /* ditto */
4641 case 104: /* VSX Vector Subtract Double-Precision */
4642 case 72: /* VSX Vector Subtract Single-Precision */
4643 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4644 case 240: /* VSX Vector Copy Sign Double-Precision */
4645 case 208: /* VSX Vector Copy Sign Single-Precision */
4646 case 130: /* VSX Logical AND */
4647 case 138: /* VSX Logical AND with Complement */
4648 case 186: /* VSX Logical Equivalence */
4649 case 178: /* VSX Logical NAND */
4650 case 170: /* VSX Logical OR with Complement */
4651 case 162: /* VSX Logical NOR */
4652 case 146: /* VSX Logical OR */
4653 case 154: /* VSX Logical XOR */
4654 case 18: /* VSX Merge High Word */
4655 case 50: /* VSX Merge Low Word */
4656 case 10: /* VSX Permute Doubleword Immediate (DM=0) */
4657 case 10 | 0x20: /* VSX Permute Doubleword Immediate (DM=1) */
4658 case 10 | 0x40: /* VSX Permute Doubleword Immediate (DM=2) */
4659 case 10 | 0x60: /* VSX Permute Doubleword Immediate (DM=3) */
4660 case 2: /* VSX Shift Left Double by Word Immediate (SHW=0) */
4661 case 2 | 0x20: /* VSX Shift Left Double by Word Immediate (SHW=1) */
4662 case 2 | 0x40: /* VSX Shift Left Double by Word Immediate (SHW=2) */
4663 case 2 | 0x60: /* VSX Shift Left Double by Word Immediate (SHW=3) */
4664 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4665 return 0;
4666
4667 case 61: /* VSX Scalar Test for software Divide Double-Precision */
4668 case 125: /* VSX Vector Test for software Divide Double-Precision */
4669 case 93: /* VSX Vector Test for software Divide Single-Precision */
4670 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4671 return 0;
4672
4673 case 35: /* VSX Scalar Compare Unordered Double-Precision */
4674 case 43: /* VSX Scalar Compare Ordered Double-Precision */
4675 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4676 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4677 return 0;
4678 }
4679
4680 switch ((ext >> 2) & 0x7f) /* Mask out Rc-bit. */
4681 {
4682 case 99: /* VSX Vector Compare Equal To Double-Precision */
4683 case 67: /* VSX Vector Compare Equal To Single-Precision */
4684 case 115: /* VSX Vector Compare Greater Than or
4685 Equal To Double-Precision */
4686 case 83: /* VSX Vector Compare Greater Than or
4687 Equal To Single-Precision */
4688 case 107: /* VSX Vector Compare Greater Than Double-Precision */
4689 case 75: /* VSX Vector Compare Greater Than Single-Precision */
4690 if (PPC_Rc (insn))
4691 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4692 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4693 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4694 return 0;
4695 }
4696
4697 switch (ext >> 1)
4698 {
4699 case 265: /* VSX Scalar round Double-Precision to
4700 Single-Precision and Convert to
4701 Single-Precision format */
4702 case 344: /* VSX Scalar truncate Double-Precision to
4703 Integer and Convert to Signed Integer
4704 Doubleword format with Saturate */
4705 case 88: /* VSX Scalar truncate Double-Precision to
4706 Integer and Convert to Signed Integer Word
4707 Format with Saturate */
4708 case 328: /* VSX Scalar truncate Double-Precision integer
4709 and Convert to Unsigned Integer Doubleword
4710 Format with Saturate */
4711 case 72: /* VSX Scalar truncate Double-Precision to
4712 Integer and Convert to Unsigned Integer Word
4713 Format with Saturate */
4714 case 329: /* VSX Scalar Convert Single-Precision to
4715 Double-Precision format */
4716 case 376: /* VSX Scalar Convert Signed Integer
4717 Doubleword to floating-point format and
4718 Round to Double-Precision format */
4719 case 312: /* VSX Scalar Convert Signed Integer
4720 Doubleword to floating-point format and
4721 round to Single-Precision */
4722 case 360: /* VSX Scalar Convert Unsigned Integer
4723 Doubleword to floating-point format and
4724 Round to Double-Precision format */
4725 case 296: /* VSX Scalar Convert Unsigned Integer
4726 Doubleword to floating-point format and
4727 Round to Single-Precision */
4728 case 73: /* VSX Scalar Round to Double-Precision Integer
4729 Using Round to Nearest Away */
4730 case 107: /* VSX Scalar Round to Double-Precision Integer
4731 Exact using Current rounding mode */
4732 case 121: /* VSX Scalar Round to Double-Precision Integer
4733 Using Round toward -Infinity */
4734 case 105: /* VSX Scalar Round to Double-Precision Integer
4735 Using Round toward +Infinity */
4736 case 89: /* VSX Scalar Round to Double-Precision Integer
4737 Using Round toward Zero */
4738 case 90: /* VSX Scalar Reciprocal Estimate Double-Precision */
4739 case 26: /* VSX Scalar Reciprocal Estimate Single-Precision */
4740 case 281: /* VSX Scalar Round to Single-Precision */
4741 case 74: /* VSX Scalar Reciprocal Square Root Estimate
4742 Double-Precision */
4743 case 10: /* VSX Scalar Reciprocal Square Root Estimate
4744 Single-Precision */
4745 case 75: /* VSX Scalar Square Root Double-Precision */
4746 case 11: /* VSX Scalar Square Root Single-Precision */
4747 case 393: /* VSX Vector round Double-Precision to
4748 Single-Precision and Convert to
4749 Single-Precision format */
4750 case 472: /* VSX Vector truncate Double-Precision to
4751 Integer and Convert to Signed Integer
4752 Doubleword format with Saturate */
4753 case 216: /* VSX Vector truncate Double-Precision to
4754 Integer and Convert to Signed Integer Word
4755 Format with Saturate */
4756 case 456: /* VSX Vector truncate Double-Precision to
4757 Integer and Convert to Unsigned Integer
4758 Doubleword format with Saturate */
4759 case 200: /* VSX Vector truncate Double-Precision to
4760 Integer and Convert to Unsigned Integer Word
4761 Format with Saturate */
4762 case 457: /* VSX Vector Convert Single-Precision to
4763 Double-Precision format */
4764 case 408: /* VSX Vector truncate Single-Precision to
4765 Integer and Convert to Signed Integer
4766 Doubleword format with Saturate */
4767 case 152: /* VSX Vector truncate Single-Precision to
4768 Integer and Convert to Signed Integer Word
4769 Format with Saturate */
4770 case 392: /* VSX Vector truncate Single-Precision to
4771 Integer and Convert to Unsigned Integer
4772 Doubleword format with Saturate */
4773 case 136: /* VSX Vector truncate Single-Precision to
4774 Integer and Convert to Unsigned Integer Word
4775 Format with Saturate */
4776 case 504: /* VSX Vector Convert and round Signed Integer
4777 Doubleword to Double-Precision format */
4778 case 440: /* VSX Vector Convert and round Signed Integer
4779 Doubleword to Single-Precision format */
4780 case 248: /* VSX Vector Convert Signed Integer Word to
4781 Double-Precision format */
4782 case 184: /* VSX Vector Convert and round Signed Integer
4783 Word to Single-Precision format */
4784 case 488: /* VSX Vector Convert and round Unsigned
4785 Integer Doubleword to Double-Precision format */
4786 case 424: /* VSX Vector Convert and round Unsigned
4787 Integer Doubleword to Single-Precision format */
4788 case 232: /* VSX Vector Convert and round Unsigned
4789 Integer Word to Double-Precision format */
4790 case 168: /* VSX Vector Convert and round Unsigned
4791 Integer Word to Single-Precision format */
4792 case 201: /* VSX Vector Round to Double-Precision
4793 Integer using round to Nearest Away */
4794 case 235: /* VSX Vector Round to Double-Precision
4795 Integer Exact using Current rounding mode */
4796 case 249: /* VSX Vector Round to Double-Precision
4797 Integer using round toward -Infinity */
4798 case 233: /* VSX Vector Round to Double-Precision
4799 Integer using round toward +Infinity */
4800 case 217: /* VSX Vector Round to Double-Precision
4801 Integer using round toward Zero */
4802 case 218: /* VSX Vector Reciprocal Estimate Double-Precision */
4803 case 154: /* VSX Vector Reciprocal Estimate Single-Precision */
4804 case 137: /* VSX Vector Round to Single-Precision Integer
4805 Using Round to Nearest Away */
4806 case 171: /* VSX Vector Round to Single-Precision Integer
4807 Exact Using Current rounding mode */
4808 case 185: /* VSX Vector Round to Single-Precision Integer
4809 Using Round toward -Infinity */
4810 case 169: /* VSX Vector Round to Single-Precision Integer
4811 Using Round toward +Infinity */
4812 case 153: /* VSX Vector Round to Single-Precision Integer
4813 Using round toward Zero */
4814 case 202: /* VSX Vector Reciprocal Square Root Estimate
4815 Double-Precision */
4816 case 138: /* VSX Vector Reciprocal Square Root Estimate
4817 Single-Precision */
4818 case 203: /* VSX Vector Square Root Double-Precision */
4819 case 139: /* VSX Vector Square Root Single-Precision */
4820 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4821 case 345: /* VSX Scalar Absolute Value Double-Precision */
4822 case 267: /* VSX Scalar Convert Scalar Single-Precision to
4823 Vector Single-Precision format Non-signalling */
4824 case 331: /* VSX Scalar Convert Single-Precision to
4825 Double-Precision format Non-signalling */
4826 case 361: /* VSX Scalar Negative Absolute Value Double-Precision */
4827 case 377: /* VSX Scalar Negate Double-Precision */
4828 case 473: /* VSX Vector Absolute Value Double-Precision */
4829 case 409: /* VSX Vector Absolute Value Single-Precision */
4830 case 489: /* VSX Vector Negative Absolute Value Double-Precision */
4831 case 425: /* VSX Vector Negative Absolute Value Single-Precision */
4832 case 505: /* VSX Vector Negate Double-Precision */
4833 case 441: /* VSX Vector Negate Single-Precision */
4834 case 164: /* VSX Splat Word */
4835 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4836 return 0;
4837
4838 case 106: /* VSX Scalar Test for software Square Root
4839 Double-Precision */
4840 case 234: /* VSX Vector Test for software Square Root
4841 Double-Precision */
4842 case 170: /* VSX Vector Test for software Square Root
4843 Single-Precision */
4844 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4845 return 0;
4846 }
4847
4848 if (((ext >> 3) & 0x3) == 3) /* VSX Select */
4849 {
4850 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4851 return 0;
4852 }
4853
810c1026
WW
4854 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4855 "at %s, 60-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4856 return -1;
4857}
4858
4859/* Parse instructions of primary opcode-63. */
4860
4861static int
4862ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
4863 CORE_ADDR addr, uint32_t insn)
4864{
4865 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4866 int ext = PPC_EXTOP (insn);
4867 int tmp;
4868
4869 switch (ext & 0x1f)
4870 {
4871 case 18: /* Floating Divide */
4872 case 20: /* Floating Subtract */
4873 case 21: /* Floating Add */
4874 case 22: /* Floating Square Root */
4875 case 24: /* Floating Reciprocal Estimate */
4876 case 25: /* Floating Multiply */
4877 case 26: /* Floating Reciprocal Square Root Estimate */
4878 case 28: /* Floating Multiply-Subtract */
4879 case 29: /* Floating Multiply-Add */
4880 case 30: /* Floating Negative Multiply-Subtract */
4881 case 31: /* Floating Negative Multiply-Add */
4882 record_full_arch_list_add_reg (regcache,
4883 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4884 if (PPC_RC (insn))
4885 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4886 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4887 return 0;
4888
4889 case 23: /* Floating Select */
4890 record_full_arch_list_add_reg (regcache,
4891 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4892 if (PPC_RC (insn))
4893 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4894 }
4895
4896 switch (ext)
4897 {
4898 case 2: /* DFP Add Quad */
4899 case 3: /* DFP Quantize Quad */
4900 case 34: /* DFP Multiply Quad */
4901 case 35: /* DFP Reround Quad */
4902 case 67: /* DFP Quantize Immediate Quad */
4903 case 99: /* DFP Round To FP Integer With Inexact Quad */
4904 case 227: /* DFP Round To FP Integer Without Inexact Quad */
4905 case 258: /* DFP Convert To DFP Extended Quad */
4906 case 514: /* DFP Subtract Quad */
4907 case 546: /* DFP Divide Quad */
4908 case 770: /* DFP Round To DFP Long Quad */
4909 case 802: /* DFP Convert From Fixed Quad */
4910 case 834: /* DFP Encode BCD To DPD Quad */
4911 if (PPC_RC (insn))
4912 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4913 tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1);
4914 record_full_arch_list_add_reg (regcache, tmp);
4915 record_full_arch_list_add_reg (regcache, tmp + 1);
4916 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4917 return 0;
4918
4919 case 130: /* DFP Compare Ordered Quad */
4920 case 162: /* DFP Test Exponent Quad */
4921 case 194: /* DFP Test Data Class Quad */
4922 case 226: /* DFP Test Data Group Quad */
4923 case 642: /* DFP Compare Unordered Quad */
4924 case 674: /* DFP Test Significance Quad */
4925 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4926 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4927 return 0;
4928
4929 case 66: /* DFP Shift Significand Left Immediate Quad */
4930 case 98: /* DFP Shift Significand Right Immediate Quad */
4931 case 322: /* DFP Decode DPD To BCD Quad */
4932 case 866: /* DFP Insert Biased Exponent Quad */
4933 tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1);
4934 record_full_arch_list_add_reg (regcache, tmp);
4935 record_full_arch_list_add_reg (regcache, tmp + 1);
4936 if (PPC_RC (insn))
4937 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4938 return 0;
4939
4940 case 290: /* DFP Convert To Fixed Quad */
4941 record_full_arch_list_add_reg (regcache,
4942 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4943 if (PPC_RC (insn))
4944 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4945 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4946 break;
4947
4948 case 354: /* DFP Extract Biased Exponent Quad */
4949 record_full_arch_list_add_reg (regcache,
4950 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4951 if (PPC_RC (insn))
4952 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4953 return 0;
4954
4955 case 12: /* Floating Round to Single-Precision */
4956 case 14: /* Floating Convert To Integer Word */
4957 case 15: /* Floating Convert To Integer Word
4958 with round toward Zero */
4959 case 142: /* Floating Convert To Integer Word Unsigned */
4960 case 143: /* Floating Convert To Integer Word Unsigned
4961 with round toward Zero */
4962 case 392: /* Floating Round to Integer Nearest */
4963 case 424: /* Floating Round to Integer Toward Zero */
4964 case 456: /* Floating Round to Integer Plus */
4965 case 488: /* Floating Round to Integer Minus */
4966 case 814: /* Floating Convert To Integer Doubleword */
4967 case 815: /* Floating Convert To Integer Doubleword
4968 with round toward Zero */
4969 case 846: /* Floating Convert From Integer Doubleword */
4970 case 942: /* Floating Convert To Integer Doubleword Unsigned */
4971 case 943: /* Floating Convert To Integer Doubleword Unsigned
4972 with round toward Zero */
4973 case 974: /* Floating Convert From Integer Doubleword Unsigned */
4974 record_full_arch_list_add_reg (regcache,
4975 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4976 if (PPC_RC (insn))
4977 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4978 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4979 return 0;
4980
4981 case 583: /* Move From FPSCR */
4982 case 8: /* Floating Copy Sign */
4983 case 40: /* Floating Negate */
4984 case 72: /* Floating Move Register */
4985 case 136: /* Floating Negative Absolute Value */
4986 case 264: /* Floating Absolute Value */
4987 record_full_arch_list_add_reg (regcache,
4988 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4989 if (PPC_RC (insn))
4990 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4991 return 0;
4992
4993 case 838: /* Floating Merge Odd Word */
4994 case 966: /* Floating Merge Even Word */
4995 record_full_arch_list_add_reg (regcache,
4996 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4997 return 0;
4998
4999 case 38: /* Move To FPSCR Bit 1 */
5000 case 70: /* Move To FPSCR Bit 0 */
5001 case 134: /* Move To FPSCR Field Immediate */
5002 case 711: /* Move To FPSCR Fields */
5003 if (PPC_RC (insn))
5004 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5005 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5006 break;
5007
5008 case 0: /* Floating Compare Unordered */
5009 case 32: /* Floating Compare Ordered */
5010 case 64: /* Move to Condition Register from FPSCR */
5011 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5012 /* FALL-THROUGH */
5013 case 128: /* Floating Test for software Divide */
5014 case 160: /* Floating Test for software Square Root */
5015 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5016 return 0;
5017
5018 }
5019
810c1026
WW
5020 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
5021 "at %s, 59-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
5022 return -1;
5023}
5024
5025/* Parse the current instruction and record the values of the registers and
5026 memory that will be changed in current instruction to "record_arch_list".
5027 Return -1 if something wrong. */
5028
5029int
5030ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
5031 CORE_ADDR addr)
5032{
5033 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
5034 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
5035 uint32_t insn;
5036 int op6, tmp, i;
5037
5038 insn = read_memory_unsigned_integer (addr, 4, byte_order);
5039 op6 = PPC_OP6 (insn);
5040
5041 switch (op6)
5042 {
5043 case 2: /* Trap Doubleword Immediate */
5044 case 3: /* Trap Word Immediate */
5045 /* Do nothing. */
5046 break;
5047
5048 case 4:
5049 if (ppc_process_record_op4 (gdbarch, regcache, addr, insn) != 0)
5050 return -1;
5051 break;
5052
5053 case 17: /* System call */
5054 if (PPC_LEV (insn) != 0)
5055 goto UNKNOWN_OP;
5056
5057 if (tdep->ppc_syscall_record != NULL)
5058 {
5059 if (tdep->ppc_syscall_record (regcache) != 0)
5060 return -1;
5061 }
5062 else
5063 {
5064 printf_unfiltered (_("no syscall record support\n"));
5065 return -1;
5066 }
5067 break;
5068
5069 case 7: /* Multiply Low Immediate */
5070 record_full_arch_list_add_reg (regcache,
5071 tdep->ppc_gp0_regnum + PPC_RT (insn));
5072 break;
5073
5074 case 8: /* Subtract From Immediate Carrying */
5075 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
5076 record_full_arch_list_add_reg (regcache,
5077 tdep->ppc_gp0_regnum + PPC_RT (insn));
5078 break;
5079
5080 case 10: /* Compare Logical Immediate */
5081 case 11: /* Compare Immediate */
5082 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5083 break;
5084
5085 case 13: /* Add Immediate Carrying and Record */
5086 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5087 /* FALL-THROUGH */
5088 case 12: /* Add Immediate Carrying */
5089 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
5090 /* FALL-THROUGH */
5091 case 14: /* Add Immediate */
5092 case 15: /* Add Immediate Shifted */
5093 record_full_arch_list_add_reg (regcache,
5094 tdep->ppc_gp0_regnum + PPC_RT (insn));
5095 break;
5096
5097 case 16: /* Branch Conditional */
5098 if ((PPC_BO (insn) & 0x4) == 0)
5099 record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum);
5100 /* FALL-THROUGH */
5101 case 18: /* Branch */
5102 if (PPC_LK (insn))
5103 record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum);
5104 break;
5105
5106 case 19:
5107 if (ppc_process_record_op19 (gdbarch, regcache, addr, insn) != 0)
5108 return -1;
5109 break;
5110
5111 case 20: /* Rotate Left Word Immediate then Mask Insert */
5112 case 21: /* Rotate Left Word Immediate then AND with Mask */
5113 case 23: /* Rotate Left Word then AND with Mask */
5114 case 30: /* Rotate Left Doubleword Immediate then Clear Left */
5115 /* Rotate Left Doubleword Immediate then Clear Right */
5116 /* Rotate Left Doubleword Immediate then Clear */
5117 /* Rotate Left Doubleword then Clear Left */
5118 /* Rotate Left Doubleword then Clear Right */
5119 /* Rotate Left Doubleword Immediate then Mask Insert */
5120 if (PPC_RC (insn))
5121 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5122 record_full_arch_list_add_reg (regcache,
5123 tdep->ppc_gp0_regnum + PPC_RA (insn));
5124 break;
5125
5126 case 28: /* AND Immediate */
5127 case 29: /* AND Immediate Shifted */
5128 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5129 /* FALL-THROUGH */
5130 case 24: /* OR Immediate */
5131 case 25: /* OR Immediate Shifted */
5132 case 26: /* XOR Immediate */
5133 case 27: /* XOR Immediate Shifted */
5134 record_full_arch_list_add_reg (regcache,
5135 tdep->ppc_gp0_regnum + PPC_RA (insn));
5136 break;
5137
5138 case 31:
5139 if (ppc_process_record_op31 (gdbarch, regcache, addr, insn) != 0)
5140 return -1;
5141 break;
5142
5143 case 33: /* Load Word and Zero with Update */
5144 case 35: /* Load Byte and Zero with Update */
5145 case 41: /* Load Halfword and Zero with Update */
5146 case 43: /* Load Halfword Algebraic with Update */
5147 record_full_arch_list_add_reg (regcache,
5148 tdep->ppc_gp0_regnum + PPC_RA (insn));
5149 /* FALL-THROUGH */
5150 case 32: /* Load Word and Zero */
5151 case 34: /* Load Byte and Zero */
5152 case 40: /* Load Halfword and Zero */
5153 case 42: /* Load Halfword Algebraic */
5154 record_full_arch_list_add_reg (regcache,
5155 tdep->ppc_gp0_regnum + PPC_RT (insn));
5156 break;
5157
5158 case 46: /* Load Multiple Word */
5159 for (i = PPC_RT (insn); i < 32; i++)
5160 record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i);
5161 break;
5162
5163 case 56: /* Load Quadword */
5164 tmp = tdep->ppc_gp0_regnum + (PPC_RT (insn) & ~1);
5165 record_full_arch_list_add_reg (regcache, tmp);
5166 record_full_arch_list_add_reg (regcache, tmp + 1);
5167 break;
5168
5169 case 49: /* Load Floating-Point Single with Update */
5170 case 51: /* Load Floating-Point Double with Update */
5171 record_full_arch_list_add_reg (regcache,
5172 tdep->ppc_gp0_regnum + PPC_RA (insn));
5173 /* FALL-THROUGH */
5174 case 48: /* Load Floating-Point Single */
5175 case 50: /* Load Floating-Point Double */
5176 record_full_arch_list_add_reg (regcache,
5177 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5178 break;
5179
5180 case 47: /* Store Multiple Word */
5181 {
5182 ULONGEST addr = 0;
5183
5184 if (PPC_RA (insn) != 0)
5185 regcache_raw_read_unsigned (regcache,
5186 tdep->ppc_gp0_regnum + PPC_RA (insn),
5187 &addr);
5188
5189 addr += PPC_D (insn);
5190 record_full_arch_list_add_mem (addr, 4 * (32 - PPC_RS (insn)));
5191 }
5192 break;
5193
5194 case 37: /* Store Word with Update */
5195 case 39: /* Store Byte with Update */
5196 case 45: /* Store Halfword with Update */
5197 case 53: /* Store Floating-Point Single with Update */
5198 case 55: /* Store Floating-Point Double with Update */
5199 record_full_arch_list_add_reg (regcache,
5200 tdep->ppc_gp0_regnum + PPC_RA (insn));
5201 /* FALL-THROUGH */
5202 case 36: /* Store Word */
5203 case 38: /* Store Byte */
5204 case 44: /* Store Halfword */
5205 case 52: /* Store Floating-Point Single */
5206 case 54: /* Store Floating-Point Double */
5207 {
5208 ULONGEST addr = 0;
5209 int size = -1;
5210
5211 if (PPC_RA (insn) != 0)
5212 regcache_raw_read_unsigned (regcache,
5213 tdep->ppc_gp0_regnum + PPC_RA (insn),
5214 &addr);
5215 addr += PPC_D (insn);
5216
5217 if (op6 == 36 || op6 == 37 || op6 == 52 || op6 == 53)
5218 size = 4;
5219 else if (op6 == 54 || op6 == 55)
5220 size = 8;
5221 else if (op6 == 44 || op6 == 45)
5222 size = 2;
5223 else if (op6 == 38 || op6 == 39)
5224 size = 1;
5225 else
5226 gdb_assert (0);
5227
5228 record_full_arch_list_add_mem (addr, size);
5229 }
5230 break;
5231
5232 case 57: /* Load Floating-Point Double Pair */
5233 if (PPC_FIELD (insn, 30, 2) != 0)
5234 goto UNKNOWN_OP;
5235 tmp = tdep->ppc_fp0_regnum + (PPC_RT (insn) & ~1);
5236 record_full_arch_list_add_reg (regcache, tmp);
5237 record_full_arch_list_add_reg (regcache, tmp + 1);
5238 break;
5239
5240 case 58: /* Load Doubleword */
5241 /* Load Doubleword with Update */
5242 /* Load Word Algebraic */
5243 if (PPC_FIELD (insn, 30, 2) > 2)
5244 goto UNKNOWN_OP;
5245
5246 record_full_arch_list_add_reg (regcache,
5247 tdep->ppc_gp0_regnum + PPC_RT (insn));
5248 if (PPC_BIT (insn, 31))
5249 record_full_arch_list_add_reg (regcache,
5250 tdep->ppc_gp0_regnum + PPC_RA (insn));
5251 break;
5252
5253 case 59:
5254 if (ppc_process_record_op59 (gdbarch, regcache, addr, insn) != 0)
5255 return -1;
5256 break;
5257
5258 case 60:
5259 if (ppc_process_record_op60 (gdbarch, regcache, addr, insn) != 0)
5260 return -1;
5261 break;
5262
5263 case 61: /* Store Floating-Point Double Pair */
5264 case 62: /* Store Doubleword */
5265 /* Store Doubleword with Update */
5266 /* Store Quadword with Update */
5267 {
5268 ULONGEST addr = 0;
5269 int size;
5270 int sub2 = PPC_FIELD (insn, 30, 2);
5271
5272 if ((op6 == 61 && sub2 != 0) || (op6 == 62 && sub2 > 2))
5273 goto UNKNOWN_OP;
5274
5275 if (PPC_RA (insn) != 0)
5276 regcache_raw_read_unsigned (regcache,
5277 tdep->ppc_gp0_regnum + PPC_RA (insn),
5278 &addr);
5279
5280 size = ((op6 == 61) || sub2 == 2) ? 16 : 8;
5281
5282 addr += PPC_DS (insn) << 2;
5283 record_full_arch_list_add_mem (addr, size);
5284
5285 if (op6 == 62 && sub2 == 1)
5286 record_full_arch_list_add_reg (regcache,
5287 tdep->ppc_gp0_regnum +
5288 PPC_RA (insn));
5289
5290 break;
5291 }
5292
5293 case 63:
5294 if (ppc_process_record_op63 (gdbarch, regcache, addr, insn) != 0)
5295 return -1;
5296 break;
5297
5298 default:
5299UNKNOWN_OP:
810c1026
WW
5300 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
5301 "at %s, %d.\n", insn, paddress (gdbarch, addr), op6);
b4cdae6f
WW
5302 return -1;
5303 }
5304
5305 if (record_full_arch_list_add_reg (regcache, PPC_PC_REGNUM))
5306 return -1;
5307 if (record_full_arch_list_add_end ())
5308 return -1;
5309 return 0;
5310}
5311
7a78ae4e
ND
5312/* Initialize the current architecture based on INFO. If possible, re-use an
5313 architecture from ARCHES, which is a list of architectures already created
5314 during this debugging session.
c906108c 5315
7a78ae4e 5316 Called e.g. at program startup, when reading a core file, and when reading
64366f1c 5317 a binary file. */
c906108c 5318
7a78ae4e
ND
5319static struct gdbarch *
5320rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
5321{
5322 struct gdbarch *gdbarch;
5323 struct gdbarch_tdep *tdep;
7cc46491 5324 int wordsize, from_xcoff_exec, from_elf_exec;
7a78ae4e
ND
5325 enum bfd_architecture arch;
5326 unsigned long mach;
5327 bfd abfd;
55eddb0f
DJ
5328 enum auto_boolean soft_float_flag = powerpc_soft_float_global;
5329 int soft_float;
5330 enum powerpc_vector_abi vector_abi = powerpc_vector_abi_global;
cd453cd0 5331 enum powerpc_elf_abi elf_abi = POWERPC_ELF_AUTO;
604c2f83
LM
5332 int have_fpu = 1, have_spe = 0, have_mq = 0, have_altivec = 0, have_dfp = 0,
5333 have_vsx = 0;
7cc46491
DJ
5334 int tdesc_wordsize = -1;
5335 const struct target_desc *tdesc = info.target_desc;
5336 struct tdesc_arch_data *tdesc_data = NULL;
f949c649 5337 int num_pseudoregs = 0;
604c2f83 5338 int cur_reg;
7a78ae4e 5339
f4d9bade
UW
5340 /* INFO may refer to a binary that is not of the PowerPC architecture,
5341 e.g. when debugging a stand-alone SPE executable on a Cell/B.E. system.
5342 In this case, we must not attempt to infer properties of the (PowerPC
5343 side) of the target system from properties of that executable. Trust
5344 the target description instead. */
5345 if (info.abfd
5346 && bfd_get_arch (info.abfd) != bfd_arch_powerpc
5347 && bfd_get_arch (info.abfd) != bfd_arch_rs6000)
5348 info.abfd = NULL;
5349
9aa1e687 5350 from_xcoff_exec = info.abfd && info.abfd->format == bfd_object &&
7a78ae4e
ND
5351 bfd_get_flavour (info.abfd) == bfd_target_xcoff_flavour;
5352
9aa1e687
KB
5353 from_elf_exec = info.abfd && info.abfd->format == bfd_object &&
5354 bfd_get_flavour (info.abfd) == bfd_target_elf_flavour;
5355
e712c1cf 5356 /* Check word size. If INFO is from a binary file, infer it from
64366f1c 5357 that, else choose a likely default. */
9aa1e687 5358 if (from_xcoff_exec)
c906108c 5359 {
11ed25ac 5360 if (bfd_xcoff_is_xcoff64 (info.abfd))
7a78ae4e
ND
5361 wordsize = 8;
5362 else
5363 wordsize = 4;
c906108c 5364 }
9aa1e687
KB
5365 else if (from_elf_exec)
5366 {
5367 if (elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5368 wordsize = 8;
5369 else
5370 wordsize = 4;
5371 }
7cc46491
DJ
5372 else if (tdesc_has_registers (tdesc))
5373 wordsize = -1;
c906108c 5374 else
7a78ae4e 5375 {
27b15785 5376 if (info.bfd_arch_info != NULL && info.bfd_arch_info->bits_per_word != 0)
16d8013c
JB
5377 wordsize = (info.bfd_arch_info->bits_per_word
5378 / info.bfd_arch_info->bits_per_byte);
27b15785
KB
5379 else
5380 wordsize = 4;
7a78ae4e 5381 }
c906108c 5382
475bbd17
JB
5383 /* Get the architecture and machine from the BFD. */
5384 arch = info.bfd_arch_info->arch;
5385 mach = info.bfd_arch_info->mach;
5bf1c677
EZ
5386
5387 /* For e500 executables, the apuinfo section is of help here. Such
5388 section contains the identifier and revision number of each
5389 Application-specific Processing Unit that is present on the
5390 chip. The content of the section is determined by the assembler
5391 which looks at each instruction and determines which unit (and
74af9197
NF
5392 which version of it) can execute it. Grovel through the section
5393 looking for relevant e500 APUs. */
5bf1c677 5394
74af9197 5395 if (bfd_uses_spe_extensions (info.abfd))
5bf1c677 5396 {
74af9197
NF
5397 arch = info.bfd_arch_info->arch;
5398 mach = bfd_mach_ppc_e500;
5399 bfd_default_set_arch_mach (&abfd, arch, mach);
5400 info.bfd_arch_info = bfd_get_arch_info (&abfd);
5bf1c677
EZ
5401 }
5402
7cc46491
DJ
5403 /* Find a default target description which describes our register
5404 layout, if we do not already have one. */
5405 if (! tdesc_has_registers (tdesc))
5406 {
5407 const struct variant *v;
5408
5409 /* Choose variant. */
5410 v = find_variant_by_arch (arch, mach);
5411 if (!v)
5412 return NULL;
5413
5414 tdesc = *v->tdesc;
5415 }
5416
5417 gdb_assert (tdesc_has_registers (tdesc));
5418
5419 /* Check any target description for validity. */
5420 if (tdesc_has_registers (tdesc))
5421 {
5422 static const char *const gprs[] = {
5423 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
5424 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
5425 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
5426 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
5427 };
7cc46491
DJ
5428 const struct tdesc_feature *feature;
5429 int i, valid_p;
5430 static const char *const msr_names[] = { "msr", "ps" };
5431 static const char *const cr_names[] = { "cr", "cnd" };
5432 static const char *const ctr_names[] = { "ctr", "cnt" };
5433
5434 feature = tdesc_find_feature (tdesc,
5435 "org.gnu.gdb.power.core");
5436 if (feature == NULL)
5437 return NULL;
5438
5439 tdesc_data = tdesc_data_alloc ();
5440
5441 valid_p = 1;
5442 for (i = 0; i < ppc_num_gprs; i++)
5443 valid_p &= tdesc_numbered_register (feature, tdesc_data, i, gprs[i]);
5444 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_PC_REGNUM,
5445 "pc");
5446 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_LR_REGNUM,
5447 "lr");
5448 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_XER_REGNUM,
5449 "xer");
5450
5451 /* Allow alternate names for these registers, to accomodate GDB's
5452 historic naming. */
5453 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5454 PPC_MSR_REGNUM, msr_names);
5455 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5456 PPC_CR_REGNUM, cr_names);
5457 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5458 PPC_CTR_REGNUM, ctr_names);
5459
5460 if (!valid_p)
5461 {
5462 tdesc_data_cleanup (tdesc_data);
5463 return NULL;
5464 }
5465
5466 have_mq = tdesc_numbered_register (feature, tdesc_data, PPC_MQ_REGNUM,
5467 "mq");
5468
5469 tdesc_wordsize = tdesc_register_size (feature, "pc") / 8;
5470 if (wordsize == -1)
5471 wordsize = tdesc_wordsize;
5472
5473 feature = tdesc_find_feature (tdesc,
5474 "org.gnu.gdb.power.fpu");
5475 if (feature != NULL)
5476 {
5477 static const char *const fprs[] = {
5478 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
5479 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
5480 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
5481 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
5482 };
5483 valid_p = 1;
5484 for (i = 0; i < ppc_num_fprs; i++)
5485 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5486 PPC_F0_REGNUM + i, fprs[i]);
5487 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5488 PPC_FPSCR_REGNUM, "fpscr");
5489
5490 if (!valid_p)
5491 {
5492 tdesc_data_cleanup (tdesc_data);
5493 return NULL;
5494 }
5495 have_fpu = 1;
5496 }
5497 else
5498 have_fpu = 0;
5499
f949c649
TJB
5500 /* The DFP pseudo-registers will be available when there are floating
5501 point registers. */
5502 have_dfp = have_fpu;
5503
7cc46491
DJ
5504 feature = tdesc_find_feature (tdesc,
5505 "org.gnu.gdb.power.altivec");
5506 if (feature != NULL)
5507 {
5508 static const char *const vector_regs[] = {
5509 "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7",
5510 "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15",
5511 "vr16", "vr17", "vr18", "vr19", "vr20", "vr21", "vr22", "vr23",
5512 "vr24", "vr25", "vr26", "vr27", "vr28", "vr29", "vr30", "vr31"
5513 };
5514
5515 valid_p = 1;
5516 for (i = 0; i < ppc_num_gprs; i++)
5517 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5518 PPC_VR0_REGNUM + i,
5519 vector_regs[i]);
5520 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5521 PPC_VSCR_REGNUM, "vscr");
5522 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5523 PPC_VRSAVE_REGNUM, "vrsave");
5524
5525 if (have_spe || !valid_p)
5526 {
5527 tdesc_data_cleanup (tdesc_data);
5528 return NULL;
5529 }
5530 have_altivec = 1;
5531 }
5532 else
5533 have_altivec = 0;
5534
604c2f83
LM
5535 /* Check for POWER7 VSX registers support. */
5536 feature = tdesc_find_feature (tdesc,
5537 "org.gnu.gdb.power.vsx");
5538
5539 if (feature != NULL)
5540 {
5541 static const char *const vsx_regs[] = {
5542 "vs0h", "vs1h", "vs2h", "vs3h", "vs4h", "vs5h",
5543 "vs6h", "vs7h", "vs8h", "vs9h", "vs10h", "vs11h",
5544 "vs12h", "vs13h", "vs14h", "vs15h", "vs16h", "vs17h",
5545 "vs18h", "vs19h", "vs20h", "vs21h", "vs22h", "vs23h",
5546 "vs24h", "vs25h", "vs26h", "vs27h", "vs28h", "vs29h",
5547 "vs30h", "vs31h"
5548 };
5549
5550 valid_p = 1;
5551
5552 for (i = 0; i < ppc_num_vshrs; i++)
5553 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5554 PPC_VSR0_UPPER_REGNUM + i,
5555 vsx_regs[i]);
5556 if (!valid_p)
5557 {
5558 tdesc_data_cleanup (tdesc_data);
5559 return NULL;
5560 }
5561
5562 have_vsx = 1;
5563 }
5564 else
5565 have_vsx = 0;
5566
7cc46491
DJ
5567 /* On machines supporting the SPE APU, the general-purpose registers
5568 are 64 bits long. There are SIMD vector instructions to treat them
5569 as pairs of floats, but the rest of the instruction set treats them
5570 as 32-bit registers, and only operates on their lower halves.
5571
5572 In the GDB regcache, we treat their high and low halves as separate
5573 registers. The low halves we present as the general-purpose
5574 registers, and then we have pseudo-registers that stitch together
5575 the upper and lower halves and present them as pseudo-registers.
5576
5577 Thus, the target description is expected to supply the upper
5578 halves separately. */
5579
5580 feature = tdesc_find_feature (tdesc,
5581 "org.gnu.gdb.power.spe");
5582 if (feature != NULL)
5583 {
5584 static const char *const upper_spe[] = {
5585 "ev0h", "ev1h", "ev2h", "ev3h",
5586 "ev4h", "ev5h", "ev6h", "ev7h",
5587 "ev8h", "ev9h", "ev10h", "ev11h",
5588 "ev12h", "ev13h", "ev14h", "ev15h",
5589 "ev16h", "ev17h", "ev18h", "ev19h",
5590 "ev20h", "ev21h", "ev22h", "ev23h",
5591 "ev24h", "ev25h", "ev26h", "ev27h",
5592 "ev28h", "ev29h", "ev30h", "ev31h"
5593 };
5594
5595 valid_p = 1;
5596 for (i = 0; i < ppc_num_gprs; i++)
5597 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5598 PPC_SPE_UPPER_GP0_REGNUM + i,
5599 upper_spe[i]);
5600 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5601 PPC_SPE_ACC_REGNUM, "acc");
5602 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5603 PPC_SPE_FSCR_REGNUM, "spefscr");
5604
5605 if (have_mq || have_fpu || !valid_p)
5606 {
5607 tdesc_data_cleanup (tdesc_data);
5608 return NULL;
5609 }
5610 have_spe = 1;
5611 }
5612 else
5613 have_spe = 0;
5614 }
5615
5616 /* If we have a 64-bit binary on a 32-bit target, complain. Also
5617 complain for a 32-bit binary on a 64-bit target; we do not yet
5618 support that. For instance, the 32-bit ABI routines expect
5619 32-bit GPRs.
5620
5621 As long as there isn't an explicit target description, we'll
5622 choose one based on the BFD architecture and get a word size
5623 matching the binary (probably powerpc:common or
5624 powerpc:common64). So there is only trouble if a 64-bit target
5625 supplies a 64-bit description while debugging a 32-bit
5626 binary. */
5627 if (tdesc_wordsize != -1 && tdesc_wordsize != wordsize)
5628 {
5629 tdesc_data_cleanup (tdesc_data);
5630 return NULL;
5631 }
5632
55eddb0f 5633#ifdef HAVE_ELF
cd453cd0
UW
5634 if (from_elf_exec)
5635 {
5636 switch (elf_elfheader (info.abfd)->e_flags & EF_PPC64_ABI)
5637 {
5638 case 1:
5639 elf_abi = POWERPC_ELF_V1;
5640 break;
5641 case 2:
5642 elf_abi = POWERPC_ELF_V2;
5643 break;
5644 default:
5645 break;
5646 }
5647 }
5648
55eddb0f
DJ
5649 if (soft_float_flag == AUTO_BOOLEAN_AUTO && from_elf_exec)
5650 {
5651 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
5652 Tag_GNU_Power_ABI_FP))
5653 {
5654 case 1:
5655 soft_float_flag = AUTO_BOOLEAN_FALSE;
5656 break;
5657 case 2:
5658 soft_float_flag = AUTO_BOOLEAN_TRUE;
5659 break;
5660 default:
5661 break;
5662 }
5663 }
5664
5665 if (vector_abi == POWERPC_VEC_AUTO && from_elf_exec)
5666 {
5667 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
5668 Tag_GNU_Power_ABI_Vector))
5669 {
5670 case 1:
5671 vector_abi = POWERPC_VEC_GENERIC;
5672 break;
5673 case 2:
5674 vector_abi = POWERPC_VEC_ALTIVEC;
5675 break;
5676 case 3:
5677 vector_abi = POWERPC_VEC_SPE;
5678 break;
5679 default:
5680 break;
5681 }
5682 }
5683#endif
5684
cd453cd0
UW
5685 /* At this point, the only supported ELF-based 64-bit little-endian
5686 operating system is GNU/Linux, and this uses the ELFv2 ABI by
5687 default. All other supported ELF-based operating systems use the
5688 ELFv1 ABI by default. Therefore, if the ABI marker is missing,
5689 e.g. because we run a legacy binary, or have attached to a process
5690 and have not found any associated binary file, set the default
5691 according to this heuristic. */
5692 if (elf_abi == POWERPC_ELF_AUTO)
5693 {
5694 if (wordsize == 8 && info.byte_order == BFD_ENDIAN_LITTLE)
5695 elf_abi = POWERPC_ELF_V2;
5696 else
5697 elf_abi = POWERPC_ELF_V1;
5698 }
5699
55eddb0f
DJ
5700 if (soft_float_flag == AUTO_BOOLEAN_TRUE)
5701 soft_float = 1;
5702 else if (soft_float_flag == AUTO_BOOLEAN_FALSE)
5703 soft_float = 0;
5704 else
5705 soft_float = !have_fpu;
5706
5707 /* If we have a hard float binary or setting but no floating point
5708 registers, downgrade to soft float anyway. We're still somewhat
5709 useful in this scenario. */
5710 if (!soft_float && !have_fpu)
5711 soft_float = 1;
5712
5713 /* Similarly for vector registers. */
5714 if (vector_abi == POWERPC_VEC_ALTIVEC && !have_altivec)
5715 vector_abi = POWERPC_VEC_GENERIC;
5716
5717 if (vector_abi == POWERPC_VEC_SPE && !have_spe)
5718 vector_abi = POWERPC_VEC_GENERIC;
5719
5720 if (vector_abi == POWERPC_VEC_AUTO)
5721 {
5722 if (have_altivec)
5723 vector_abi = POWERPC_VEC_ALTIVEC;
5724 else if (have_spe)
5725 vector_abi = POWERPC_VEC_SPE;
5726 else
5727 vector_abi = POWERPC_VEC_GENERIC;
5728 }
5729
5730 /* Do not limit the vector ABI based on available hardware, since we
5731 do not yet know what hardware we'll decide we have. Yuck! FIXME! */
5732
7cc46491
DJ
5733 /* Find a candidate among extant architectures. */
5734 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5735 arches != NULL;
5736 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5737 {
5738 /* Word size in the various PowerPC bfd_arch_info structs isn't
5739 meaningful, because 64-bit CPUs can run in 32-bit mode. So, perform
5740 separate word size check. */
5741 tdep = gdbarch_tdep (arches->gdbarch);
cd453cd0
UW
5742 if (tdep && tdep->elf_abi != elf_abi)
5743 continue;
55eddb0f
DJ
5744 if (tdep && tdep->soft_float != soft_float)
5745 continue;
5746 if (tdep && tdep->vector_abi != vector_abi)
5747 continue;
7cc46491
DJ
5748 if (tdep && tdep->wordsize == wordsize)
5749 {
5750 if (tdesc_data != NULL)
5751 tdesc_data_cleanup (tdesc_data);
5752 return arches->gdbarch;
5753 }
5754 }
5755
5756 /* None found, create a new architecture from INFO, whose bfd_arch_info
5757 validity depends on the source:
5758 - executable useless
5759 - rs6000_host_arch() good
5760 - core file good
5761 - "set arch" trust blindly
5762 - GDB startup useless but harmless */
5763
fc270c35 5764 tdep = XCNEW (struct gdbarch_tdep);
7cc46491 5765 tdep->wordsize = wordsize;
cd453cd0 5766 tdep->elf_abi = elf_abi;
55eddb0f
DJ
5767 tdep->soft_float = soft_float;
5768 tdep->vector_abi = vector_abi;
7cc46491 5769
7a78ae4e 5770 gdbarch = gdbarch_alloc (&info, tdep);
7a78ae4e 5771
7cc46491
DJ
5772 tdep->ppc_gp0_regnum = PPC_R0_REGNUM;
5773 tdep->ppc_toc_regnum = PPC_R0_REGNUM + 2;
5774 tdep->ppc_ps_regnum = PPC_MSR_REGNUM;
5775 tdep->ppc_cr_regnum = PPC_CR_REGNUM;
5776 tdep->ppc_lr_regnum = PPC_LR_REGNUM;
5777 tdep->ppc_ctr_regnum = PPC_CTR_REGNUM;
5778 tdep->ppc_xer_regnum = PPC_XER_REGNUM;
5779 tdep->ppc_mq_regnum = have_mq ? PPC_MQ_REGNUM : -1;
5780
5781 tdep->ppc_fp0_regnum = have_fpu ? PPC_F0_REGNUM : -1;
5782 tdep->ppc_fpscr_regnum = have_fpu ? PPC_FPSCR_REGNUM : -1;
604c2f83 5783 tdep->ppc_vsr0_upper_regnum = have_vsx ? PPC_VSR0_UPPER_REGNUM : -1;
7cc46491
DJ
5784 tdep->ppc_vr0_regnum = have_altivec ? PPC_VR0_REGNUM : -1;
5785 tdep->ppc_vrsave_regnum = have_altivec ? PPC_VRSAVE_REGNUM : -1;
5786 tdep->ppc_ev0_upper_regnum = have_spe ? PPC_SPE_UPPER_GP0_REGNUM : -1;
5787 tdep->ppc_acc_regnum = have_spe ? PPC_SPE_ACC_REGNUM : -1;
5788 tdep->ppc_spefscr_regnum = have_spe ? PPC_SPE_FSCR_REGNUM : -1;
5789
5790 set_gdbarch_pc_regnum (gdbarch, PPC_PC_REGNUM);
5791 set_gdbarch_sp_regnum (gdbarch, PPC_R0_REGNUM + 1);
5792 set_gdbarch_deprecated_fp_regnum (gdbarch, PPC_R0_REGNUM + 1);
5793 set_gdbarch_fp0_regnum (gdbarch, tdep->ppc_fp0_regnum);
9f643768 5794 set_gdbarch_register_sim_regno (gdbarch, rs6000_register_sim_regno);
7cc46491
DJ
5795
5796 /* The XML specification for PowerPC sensibly calls the MSR "msr".
5797 GDB traditionally called it "ps", though, so let GDB add an
5798 alias. */
5799 set_gdbarch_ps_regnum (gdbarch, tdep->ppc_ps_regnum);
5800
4a7622d1 5801 if (wordsize == 8)
05580c65 5802 set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value);
afd48b75 5803 else
4a7622d1 5804 set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value);
c8001721 5805
baffbae0
JB
5806 /* Set lr_frame_offset. */
5807 if (wordsize == 8)
5808 tdep->lr_frame_offset = 16;
baffbae0 5809 else
4a7622d1 5810 tdep->lr_frame_offset = 4;
baffbae0 5811
604c2f83 5812 if (have_spe || have_dfp || have_vsx)
7cc46491 5813 {
f949c649 5814 set_gdbarch_pseudo_register_read (gdbarch, rs6000_pseudo_register_read);
0df8b418
MS
5815 set_gdbarch_pseudo_register_write (gdbarch,
5816 rs6000_pseudo_register_write);
7cc46491 5817 }
1fcc0bb8 5818
e0d24f8d
WZ
5819 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
5820
56a6dfb9 5821 /* Select instruction printer. */
708ff411 5822 if (arch == bfd_arch_rs6000)
9364a0ef 5823 set_gdbarch_print_insn (gdbarch, print_insn_rs6000);
56a6dfb9 5824 else
9364a0ef 5825 set_gdbarch_print_insn (gdbarch, gdb_print_insn_powerpc);
7495d1dc 5826
5a9e69ba 5827 set_gdbarch_num_regs (gdbarch, PPC_NUM_REGS);
f949c649
TJB
5828
5829 if (have_spe)
5830 num_pseudoregs += 32;
5831 if (have_dfp)
5832 num_pseudoregs += 16;
604c2f83
LM
5833 if (have_vsx)
5834 /* Include both VSX and Extended FP registers. */
5835 num_pseudoregs += 96;
f949c649
TJB
5836
5837 set_gdbarch_num_pseudo_regs (gdbarch, num_pseudoregs);
7a78ae4e
ND
5838
5839 set_gdbarch_ptr_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
5840 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
5841 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
5842 set_gdbarch_long_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
5843 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
5844 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
5845 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
4a7622d1 5846 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
4e409299 5847 set_gdbarch_char_signed (gdbarch, 0);
7a78ae4e 5848
11269d7e 5849 set_gdbarch_frame_align (gdbarch, rs6000_frame_align);
4a7622d1 5850 if (wordsize == 8)
8b148df9
AC
5851 /* PPC64 SYSV. */
5852 set_gdbarch_frame_red_zone_size (gdbarch, 288);
7a78ae4e 5853
691d145a
JB
5854 set_gdbarch_convert_register_p (gdbarch, rs6000_convert_register_p);
5855 set_gdbarch_register_to_value (gdbarch, rs6000_register_to_value);
5856 set_gdbarch_value_to_register (gdbarch, rs6000_value_to_register);
5857
18ed0c4e
JB
5858 set_gdbarch_stab_reg_to_regnum (gdbarch, rs6000_stab_reg_to_regnum);
5859 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rs6000_dwarf2_reg_to_regnum);
d217aaed 5860
4a7622d1 5861 if (wordsize == 4)
77b2b6d4 5862 set_gdbarch_push_dummy_call (gdbarch, ppc_sysv_abi_push_dummy_call);
4a7622d1 5863 else if (wordsize == 8)
8be9034a 5864 set_gdbarch_push_dummy_call (gdbarch, ppc64_sysv_abi_push_dummy_call);
7a78ae4e 5865
7a78ae4e 5866 set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue);
0d1243d9 5867 set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilogue_p);
8ab3d180 5868 set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue);
0d1243d9 5869
7a78ae4e 5870 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
7a78ae4e
ND
5871 set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);
5872
203c3895 5873 /* The value of symbols of type N_SO and N_FUN maybe null when
0df8b418 5874 it shouldn't be. */
203c3895
UW
5875 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
5876
ce5eab59 5877 /* Handles single stepping of atomic sequences. */
4a7622d1 5878 set_gdbarch_software_single_step (gdbarch, ppc_deal_with_atomic_sequence);
ce5eab59 5879
0df8b418 5880 /* Not sure on this. FIXMEmgo */
7a78ae4e
ND
5881 set_gdbarch_frame_args_skip (gdbarch, 8);
5882
143985b7
AF
5883 /* Helpers for function argument information. */
5884 set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument);
5885
6f7f3f0d
UW
5886 /* Trampoline. */
5887 set_gdbarch_in_solib_return_trampoline
5888 (gdbarch, rs6000_in_solib_return_trampoline);
5889 set_gdbarch_skip_trampoline_code (gdbarch, rs6000_skip_trampoline_code);
5890
4fc771b8 5891 /* Hook in the DWARF CFI frame unwinder. */
1af5d7ce 5892 dwarf2_append_unwinders (gdbarch);
4fc771b8
DJ
5893 dwarf2_frame_set_adjust_regnum (gdbarch, rs6000_adjust_frame_regnum);
5894
9274a07c
LM
5895 /* Frame handling. */
5896 dwarf2_frame_set_init_reg (gdbarch, ppc_dwarf2_frame_init_reg);
5897
2454a024
UW
5898 /* Setup displaced stepping. */
5899 set_gdbarch_displaced_step_copy_insn (gdbarch,
5900 simple_displaced_step_copy_insn);
99e40580
UW
5901 set_gdbarch_displaced_step_hw_singlestep (gdbarch,
5902 ppc_displaced_step_hw_singlestep);
2454a024
UW
5903 set_gdbarch_displaced_step_fixup (gdbarch, ppc_displaced_step_fixup);
5904 set_gdbarch_displaced_step_free_closure (gdbarch,
5905 simple_displaced_step_free_closure);
5906 set_gdbarch_displaced_step_location (gdbarch,
5907 displaced_step_at_entry_point);
5908
5909 set_gdbarch_max_insn_length (gdbarch, PPC_INSN_SIZE);
5910
7b112f9c 5911 /* Hook in ABI-specific overrides, if they have been registered. */
8a4c2d24
UW
5912 info.target_desc = tdesc;
5913 info.tdep_info = (void *) tdesc_data;
4be87837 5914 gdbarch_init_osabi (info, gdbarch);
7b112f9c 5915
61a65099
KB
5916 switch (info.osabi)
5917 {
f5aecab8 5918 case GDB_OSABI_LINUX:
61a65099
KB
5919 case GDB_OSABI_NETBSD_AOUT:
5920 case GDB_OSABI_NETBSD_ELF:
5921 case GDB_OSABI_UNKNOWN:
61a65099 5922 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
2608dbf8 5923 frame_unwind_append_unwinder (gdbarch, &rs6000_epilogue_frame_unwind);
1af5d7ce
UW
5924 frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind);
5925 set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id);
61a65099
KB
5926 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
5927 break;
5928 default:
61a65099 5929 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
81332287
KB
5930
5931 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
2608dbf8 5932 frame_unwind_append_unwinder (gdbarch, &rs6000_epilogue_frame_unwind);
1af5d7ce
UW
5933 frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind);
5934 set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id);
81332287 5935 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
61a65099
KB
5936 }
5937
7cc46491
DJ
5938 set_tdesc_pseudo_register_type (gdbarch, rs6000_pseudo_register_type);
5939 set_tdesc_pseudo_register_reggroup_p (gdbarch,
5940 rs6000_pseudo_register_reggroup_p);
5941 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
5942
5943 /* Override the normal target description method to make the SPE upper
5944 halves anonymous. */
5945 set_gdbarch_register_name (gdbarch, rs6000_register_name);
5946
604c2f83
LM
5947 /* Choose register numbers for all supported pseudo-registers. */
5948 tdep->ppc_ev0_regnum = -1;
5949 tdep->ppc_dl0_regnum = -1;
5950 tdep->ppc_vsr0_regnum = -1;
5951 tdep->ppc_efpr0_regnum = -1;
9f643768 5952
604c2f83
LM
5953 cur_reg = gdbarch_num_regs (gdbarch);
5954
5955 if (have_spe)
5956 {
5957 tdep->ppc_ev0_regnum = cur_reg;
5958 cur_reg += 32;
5959 }
5960 if (have_dfp)
5961 {
5962 tdep->ppc_dl0_regnum = cur_reg;
5963 cur_reg += 16;
5964 }
5965 if (have_vsx)
5966 {
5967 tdep->ppc_vsr0_regnum = cur_reg;
5968 cur_reg += 64;
5969 tdep->ppc_efpr0_regnum = cur_reg;
5970 cur_reg += 32;
5971 }
f949c649 5972
604c2f83
LM
5973 gdb_assert (gdbarch_num_regs (gdbarch)
5974 + gdbarch_num_pseudo_regs (gdbarch) == cur_reg);
f949c649 5975
debb1f09
JB
5976 /* Register the ravenscar_arch_ops. */
5977 if (mach == bfd_mach_ppc_e500)
5978 register_e500_ravenscar_ops (gdbarch);
5979 else
5980 register_ppc_ravenscar_ops (gdbarch);
5981
7a78ae4e 5982 return gdbarch;
c906108c
SS
5983}
5984
7b112f9c 5985static void
8b164abb 5986rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
7b112f9c 5987{
8b164abb 5988 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7b112f9c
JT
5989
5990 if (tdep == NULL)
5991 return;
5992
4be87837 5993 /* FIXME: Dump gdbarch_tdep. */
7b112f9c
JT
5994}
5995
55eddb0f
DJ
5996/* PowerPC-specific commands. */
5997
5998static void
5999set_powerpc_command (char *args, int from_tty)
6000{
6001 printf_unfiltered (_("\
6002\"set powerpc\" must be followed by an appropriate subcommand.\n"));
6003 help_list (setpowerpccmdlist, "set powerpc ", all_commands, gdb_stdout);
6004}
6005
6006static void
6007show_powerpc_command (char *args, int from_tty)
6008{
6009 cmd_show_list (showpowerpccmdlist, from_tty, "");
6010}
6011
6012static void
6013powerpc_set_soft_float (char *args, int from_tty,
6014 struct cmd_list_element *c)
6015{
6016 struct gdbarch_info info;
6017
6018 /* Update the architecture. */
6019 gdbarch_info_init (&info);
6020 if (!gdbarch_update_p (info))
9b20d036 6021 internal_error (__FILE__, __LINE__, _("could not update architecture"));
55eddb0f
DJ
6022}
6023
6024static void
6025powerpc_set_vector_abi (char *args, int from_tty,
6026 struct cmd_list_element *c)
6027{
6028 struct gdbarch_info info;
6029 enum powerpc_vector_abi vector_abi;
6030
6031 for (vector_abi = POWERPC_VEC_AUTO;
6032 vector_abi != POWERPC_VEC_LAST;
6033 vector_abi++)
6034 if (strcmp (powerpc_vector_abi_string,
6035 powerpc_vector_strings[vector_abi]) == 0)
6036 {
6037 powerpc_vector_abi_global = vector_abi;
6038 break;
6039 }
6040
6041 if (vector_abi == POWERPC_VEC_LAST)
6042 internal_error (__FILE__, __LINE__, _("Invalid vector ABI accepted: %s."),
6043 powerpc_vector_abi_string);
6044
6045 /* Update the architecture. */
6046 gdbarch_info_init (&info);
6047 if (!gdbarch_update_p (info))
9b20d036 6048 internal_error (__FILE__, __LINE__, _("could not update architecture"));
55eddb0f
DJ
6049}
6050
e09342b5
TJB
6051/* Show the current setting of the exact watchpoints flag. */
6052
6053static void
6054show_powerpc_exact_watchpoints (struct ui_file *file, int from_tty,
6055 struct cmd_list_element *c,
6056 const char *value)
6057{
6058 fprintf_filtered (file, _("Use of exact watchpoints is %s.\n"), value);
6059}
6060
845d4708 6061/* Read a PPC instruction from memory. */
d78489bf
AT
6062
6063static unsigned int
845d4708 6064read_insn (struct frame_info *frame, CORE_ADDR pc)
d78489bf 6065{
845d4708
AM
6066 struct gdbarch *gdbarch = get_frame_arch (frame);
6067 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
6068
6069 return read_memory_unsigned_integer (pc, 4, byte_order);
d78489bf
AT
6070}
6071
6072/* Return non-zero if the instructions at PC match the series
6073 described in PATTERN, or zero otherwise. PATTERN is an array of
6074 'struct ppc_insn_pattern' objects, terminated by an entry whose
6075 mask is zero.
6076
6077 When the match is successful, fill INSN[i] with what PATTERN[i]
6078 matched. If PATTERN[i] is optional, and the instruction wasn't
6079 present, set INSN[i] to 0 (which is not a valid PPC instruction).
6080 INSN should have as many elements as PATTERN. Note that, if
6081 PATTERN contains optional instructions which aren't present in
6082 memory, then INSN will have holes, so INSN[i] isn't necessarily the
6083 i'th instruction in memory. */
6084
6085int
845d4708
AM
6086ppc_insns_match_pattern (struct frame_info *frame, CORE_ADDR pc,
6087 struct ppc_insn_pattern *pattern,
6088 unsigned int *insns)
d78489bf
AT
6089{
6090 int i;
845d4708 6091 unsigned int insn;
d78489bf 6092
845d4708 6093 for (i = 0, insn = 0; pattern[i].mask; i++)
d78489bf 6094 {
845d4708
AM
6095 if (insn == 0)
6096 insn = read_insn (frame, pc);
6097 insns[i] = 0;
6098 if ((insn & pattern[i].mask) == pattern[i].data)
6099 {
6100 insns[i] = insn;
6101 pc += 4;
6102 insn = 0;
6103 }
6104 else if (!pattern[i].optional)
d78489bf
AT
6105 return 0;
6106 }
6107
6108 return 1;
6109}
6110
6111/* Return the 'd' field of the d-form instruction INSN, properly
6112 sign-extended. */
6113
6114CORE_ADDR
6115ppc_insn_d_field (unsigned int insn)
6116{
6117 return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000);
6118}
6119
6120/* Return the 'ds' field of the ds-form instruction INSN, with the two
6121 zero bits concatenated at the right, and properly
6122 sign-extended. */
6123
6124CORE_ADDR
6125ppc_insn_ds_field (unsigned int insn)
6126{
6127 return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000);
6128}
6129
c906108c
SS
6130/* Initialization code. */
6131
0df8b418
MS
6132/* -Wmissing-prototypes */
6133extern initialize_file_ftype _initialize_rs6000_tdep;
b9362cc7 6134
c906108c 6135void
fba45db2 6136_initialize_rs6000_tdep (void)
c906108c 6137{
7b112f9c
JT
6138 gdbarch_register (bfd_arch_rs6000, rs6000_gdbarch_init, rs6000_dump_tdep);
6139 gdbarch_register (bfd_arch_powerpc, rs6000_gdbarch_init, rs6000_dump_tdep);
7cc46491
DJ
6140
6141 /* Initialize the standard target descriptions. */
6142 initialize_tdesc_powerpc_32 ();
7284e1be 6143 initialize_tdesc_powerpc_altivec32 ();
604c2f83 6144 initialize_tdesc_powerpc_vsx32 ();
7cc46491
DJ
6145 initialize_tdesc_powerpc_403 ();
6146 initialize_tdesc_powerpc_403gc ();
4d09ffea 6147 initialize_tdesc_powerpc_405 ();
7cc46491
DJ
6148 initialize_tdesc_powerpc_505 ();
6149 initialize_tdesc_powerpc_601 ();
6150 initialize_tdesc_powerpc_602 ();
6151 initialize_tdesc_powerpc_603 ();
6152 initialize_tdesc_powerpc_604 ();
6153 initialize_tdesc_powerpc_64 ();
7284e1be 6154 initialize_tdesc_powerpc_altivec64 ();
604c2f83 6155 initialize_tdesc_powerpc_vsx64 ();
7cc46491
DJ
6156 initialize_tdesc_powerpc_7400 ();
6157 initialize_tdesc_powerpc_750 ();
6158 initialize_tdesc_powerpc_860 ();
6159 initialize_tdesc_powerpc_e500 ();
6160 initialize_tdesc_rs6000 ();
55eddb0f
DJ
6161
6162 /* Add root prefix command for all "set powerpc"/"show powerpc"
6163 commands. */
6164 add_prefix_cmd ("powerpc", no_class, set_powerpc_command,
6165 _("Various PowerPC-specific commands."),
6166 &setpowerpccmdlist, "set powerpc ", 0, &setlist);
6167
6168 add_prefix_cmd ("powerpc", no_class, show_powerpc_command,
6169 _("Various PowerPC-specific commands."),
6170 &showpowerpccmdlist, "show powerpc ", 0, &showlist);
6171
6172 /* Add a command to allow the user to force the ABI. */
6173 add_setshow_auto_boolean_cmd ("soft-float", class_support,
6174 &powerpc_soft_float_global,
6175 _("Set whether to use a soft-float ABI."),
6176 _("Show whether to use a soft-float ABI."),
6177 NULL,
6178 powerpc_set_soft_float, NULL,
6179 &setpowerpccmdlist, &showpowerpccmdlist);
6180
6181 add_setshow_enum_cmd ("vector-abi", class_support, powerpc_vector_strings,
6182 &powerpc_vector_abi_string,
6183 _("Set the vector ABI."),
6184 _("Show the vector ABI."),
6185 NULL, powerpc_set_vector_abi, NULL,
6186 &setpowerpccmdlist, &showpowerpccmdlist);
e09342b5
TJB
6187
6188 add_setshow_boolean_cmd ("exact-watchpoints", class_support,
6189 &target_exact_watchpoints,
6190 _("\
6191Set whether to use just one debug register for watchpoints on scalars."),
6192 _("\
6193Show whether to use just one debug register for watchpoints on scalars."),
6194 _("\
6195If true, GDB will use only one debug register when watching a variable of\n\
6196scalar type, thus assuming that the variable is accessed through the address\n\
6197of its first byte."),
6198 NULL, show_powerpc_exact_watchpoints,
6199 &setpowerpccmdlist, &showpowerpccmdlist);
c906108c 6200}
This page took 2.379898 seconds and 4 git commands to generate.