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