[PowerPC] Add support for TAR
[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) */
7ca18ed6
EBM
4415
4416 if (ext == 444 && tdep->ppc_ppr_regnum >= 0
4417 && (PPC_RS (insn) == PPC_RA (insn))
4418 && (PPC_RA (insn) == PPC_RB (insn))
4419 && !PPC_RC (insn))
4420 {
4421 /* or Rx,Rx,Rx alters PRI in PPR. */
4422 record_full_arch_list_add_reg (regcache, tdep->ppc_ppr_regnum);
4423 return 0;
4424 }
4425
b4cdae6f
WW
4426 if (PPC_RC (insn))
4427 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4428 record_full_arch_list_add_reg (regcache,
4429 tdep->ppc_gp0_regnum + PPC_RA (insn));
4430 return 0;
4431
4432 /* Store memory. */
4433 case 181: /* Store Doubleword with Update Indexed */
4434 case 183: /* Store Word with Update Indexed */
4435 case 247: /* Store Byte with Update Indexed */
4436 case 439: /* Store Half Word with Update Indexed */
4437 case 695: /* Store Floating-Point Single with Update Indexed */
4438 case 759: /* Store Floating-Point Double with Update Indexed */
4439 record_full_arch_list_add_reg (regcache,
4440 tdep->ppc_gp0_regnum + PPC_RA (insn));
4441 /* FALL-THROUGH */
4442 case 135: /* Store Vector Element Byte Indexed */
4443 case 167: /* Store Vector Element Halfword Indexed */
4444 case 199: /* Store Vector Element Word Indexed */
4445 case 231: /* Store Vector Indexed */
4446 case 487: /* Store Vector Indexed LRU */
4447 case 716: /* Store VSX Scalar Doubleword Indexed */
4448 case 140: /* Store VSX Scalar as Integer Word Indexed */
4449 case 652: /* Store VSX Scalar Single-Precision Indexed */
4450 case 972: /* Store VSX Vector Doubleword*2 Indexed */
4451 case 908: /* Store VSX Vector Word*4 Indexed */
4452 case 149: /* Store Doubleword Indexed */
4453 case 151: /* Store Word Indexed */
4454 case 215: /* Store Byte Indexed */
4455 case 407: /* Store Half Word Indexed */
4456 case 694: /* Store Byte Conditional Indexed */
4457 case 726: /* Store Halfword Conditional Indexed */
4458 case 150: /* Store Word Conditional Indexed */
4459 case 214: /* Store Doubleword Conditional Indexed */
4460 case 182: /* Store Quadword Conditional Indexed */
4461 case 662: /* Store Word Byte-Reverse Indexed */
4462 case 918: /* Store Halfword Byte-Reverse Indexed */
4463 case 660: /* Store Doubleword Byte-Reverse Indexed */
4464 case 663: /* Store Floating-Point Single Indexed */
4465 case 727: /* Store Floating-Point Double Indexed */
4466 case 919: /* Store Floating-Point Double Pair Indexed */
4467 case 983: /* Store Floating-Point as Integer Word Indexed */
6ec2b213
EBM
4468 case 396: /* Store VSX Vector Indexed */
4469 case 940: /* Store VSX Vector Halfword*8 Indexed */
4470 case 1004: /* Store VSX Vector Byte*16 Indexed */
4471 case 909: /* Store VSX Scalar as Integer Byte Indexed */
4472 case 941: /* Store VSX Scalar as Integer Halfword Indexed */
b4cdae6f
WW
4473 if (ext == 694 || ext == 726 || ext == 150 || ext == 214 || ext == 182)
4474 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4475
4476 ra = 0;
4477 if (PPC_RA (insn) != 0)
4478 regcache_raw_read_unsigned (regcache,
4479 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
4480 regcache_raw_read_unsigned (regcache,
4481 tdep->ppc_gp0_regnum + PPC_RB (insn), &rb);
4482 ea = ra + rb;
4483
4484 switch (ext)
4485 {
4486 case 183: /* Store Word with Update Indexed */
4487 case 199: /* Store Vector Element Word Indexed */
4488 case 140: /* Store VSX Scalar as Integer Word Indexed */
4489 case 652: /* Store VSX Scalar Single-Precision Indexed */
4490 case 151: /* Store Word Indexed */
4491 case 150: /* Store Word Conditional Indexed */
4492 case 662: /* Store Word Byte-Reverse Indexed */
4493 case 663: /* Store Floating-Point Single Indexed */
4494 case 695: /* Store Floating-Point Single with Update Indexed */
4495 case 983: /* Store Floating-Point as Integer Word Indexed */
4496 size = 4;
4497 break;
4498 case 247: /* Store Byte with Update Indexed */
4499 case 135: /* Store Vector Element Byte Indexed */
4500 case 215: /* Store Byte Indexed */
4501 case 694: /* Store Byte Conditional Indexed */
6ec2b213 4502 case 909: /* Store VSX Scalar as Integer Byte Indexed */
b4cdae6f
WW
4503 size = 1;
4504 break;
4505 case 439: /* Store Halfword with Update Indexed */
4506 case 167: /* Store Vector Element Halfword Indexed */
4507 case 407: /* Store Halfword Indexed */
4508 case 726: /* Store Halfword Conditional Indexed */
4509 case 918: /* Store Halfword Byte-Reverse Indexed */
6ec2b213 4510 case 941: /* Store VSX Scalar as Integer Halfword Indexed */
b4cdae6f
WW
4511 size = 2;
4512 break;
4513 case 181: /* Store Doubleword with Update Indexed */
4514 case 716: /* Store VSX Scalar Doubleword Indexed */
4515 case 149: /* Store Doubleword Indexed */
4516 case 214: /* Store Doubleword Conditional Indexed */
4517 case 660: /* Store Doubleword Byte-Reverse Indexed */
4518 case 727: /* Store Floating-Point Double Indexed */
4519 case 759: /* Store Floating-Point Double with Update Indexed */
4520 size = 8;
4521 break;
4522 case 972: /* Store VSX Vector Doubleword*2 Indexed */
4523 case 908: /* Store VSX Vector Word*4 Indexed */
4524 case 182: /* Store Quadword Conditional Indexed */
4525 case 231: /* Store Vector Indexed */
4526 case 487: /* Store Vector Indexed LRU */
4527 case 919: /* Store Floating-Point Double Pair Indexed */
6ec2b213
EBM
4528 case 396: /* Store VSX Vector Indexed */
4529 case 940: /* Store VSX Vector Halfword*8 Indexed */
4530 case 1004: /* Store VSX Vector Byte*16 Indexed */
b4cdae6f
WW
4531 size = 16;
4532 break;
4533 default:
4534 gdb_assert (0);
4535 }
4536
4537 /* Align address for Store Vector instructions. */
4538 switch (ext)
4539 {
4540 case 167: /* Store Vector Element Halfword Indexed */
4541 addr = addr & ~0x1ULL;
4542 break;
4543
4544 case 199: /* Store Vector Element Word Indexed */
4545 addr = addr & ~0x3ULL;
4546 break;
4547
4548 case 231: /* Store Vector Indexed */
4549 case 487: /* Store Vector Indexed LRU */
4550 addr = addr & ~0xfULL;
4551 break;
4552 }
4553
4554 record_full_arch_list_add_mem (addr, size);
4555 return 0;
4556
6ec2b213
EBM
4557 case 397: /* Store VSX Vector with Length */
4558 case 429: /* Store VSX Vector Left-justified with Length */
de678454 4559 ra = 0;
6ec2b213
EBM
4560 if (PPC_RA (insn) != 0)
4561 regcache_raw_read_unsigned (regcache,
de678454
EBM
4562 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
4563 ea = ra;
6ec2b213
EBM
4564 regcache_raw_read_unsigned (regcache,
4565 tdep->ppc_gp0_regnum + PPC_RB (insn), &rb);
4566 /* Store up to 16 bytes. */
4567 nb = (rb & 0xff) > 16 ? 16 : (rb & 0xff);
4568 if (nb > 0)
4569 record_full_arch_list_add_mem (ea, nb);
4570 return 0;
4571
4572 case 710: /* Store Word Atomic */
4573 case 742: /* Store Doubleword Atomic */
de678454 4574 ra = 0;
6ec2b213
EBM
4575 if (PPC_RA (insn) != 0)
4576 regcache_raw_read_unsigned (regcache,
de678454
EBM
4577 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
4578 ea = ra;
6ec2b213
EBM
4579 switch (ext)
4580 {
4581 case 710: /* Store Word Atomic */
4582 size = 8;
4583 break;
4584 case 742: /* Store Doubleword Atomic */
4585 size = 16;
4586 break;
4587 default:
4588 gdb_assert (0);
4589 }
4590 record_full_arch_list_add_mem (ea, size);
4591 return 0;
4592
b4cdae6f
WW
4593 case 725: /* Store String Word Immediate */
4594 ra = 0;
4595 if (PPC_RA (insn) != 0)
9f7efd5b
EBM
4596 regcache_raw_read_unsigned (regcache,
4597 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
b4cdae6f
WW
4598 ea += ra;
4599
4600 nb = PPC_NB (insn);
4601 if (nb == 0)
4602 nb = 32;
4603
4604 record_full_arch_list_add_mem (ea, nb);
4605
4606 return 0;
4607
4608 case 661: /* Store String Word Indexed */
4609 ra = 0;
4610 if (PPC_RA (insn) != 0)
9f7efd5b
EBM
4611 regcache_raw_read_unsigned (regcache,
4612 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
b4cdae6f
WW
4613 ea += ra;
4614
4615 regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &xer);
4616 nb = PPC_XER_NB (xer);
4617
4618 if (nb != 0)
4619 {
9f7efd5b
EBM
4620 regcache_raw_read_unsigned (regcache,
4621 tdep->ppc_gp0_regnum + PPC_RB (insn),
4622 &rb);
b4cdae6f
WW
4623 ea += rb;
4624 record_full_arch_list_add_mem (ea, nb);
4625 }
4626
4627 return 0;
4628
4629 case 467: /* Move To Special Purpose Register */
4630 switch (PPC_SPR (insn))
4631 {
4632 case 1: /* XER */
4633 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4634 return 0;
7ca18ed6
EBM
4635 case 3: /* DSCR */
4636 if (tdep->ppc_dscr_regnum >= 0)
4637 record_full_arch_list_add_reg (regcache, tdep->ppc_dscr_regnum);
4638 return 0;
b4cdae6f
WW
4639 case 8: /* LR */
4640 record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum);
4641 return 0;
4642 case 9: /* CTR */
4643 record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum);
4644 return 0;
4645 case 256: /* VRSAVE */
4646 record_full_arch_list_add_reg (regcache, tdep->ppc_vrsave_regnum);
4647 return 0;
f2cf6173
EBM
4648 case 815: /* TAR */
4649 if (tdep->ppc_tar_regnum >= 0)
4650 record_full_arch_list_add_reg (regcache, tdep->ppc_tar_regnum);
4651 return 0;
7ca18ed6
EBM
4652 case 896:
4653 case 898: /* PPR */
4654 if (tdep->ppc_ppr_regnum >= 0)
4655 record_full_arch_list_add_reg (regcache, tdep->ppc_ppr_regnum);
4656 return 0;
b4cdae6f
WW
4657 }
4658
4659 goto UNKNOWN_OP;
4660
4661 case 147: /* Move To Split Little Endian */
4662 record_full_arch_list_add_reg (regcache, tdep->ppc_ps_regnum);
4663 return 0;
4664
4665 case 512: /* Move to Condition Register from XER */
4666 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4667 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
4668 return 0;
4669
4670 case 4: /* Trap Word */
4671 case 68: /* Trap Doubleword */
4672 case 430: /* Clear BHRB */
4673 case 598: /* Synchronize */
4674 case 62: /* Wait for Interrupt */
6ec2b213 4675 case 30: /* Wait */
b4cdae6f
WW
4676 case 22: /* Instruction Cache Block Touch */
4677 case 854: /* Enforce In-order Execution of I/O */
4678 case 246: /* Data Cache Block Touch for Store */
4679 case 54: /* Data Cache Block Store */
4680 case 86: /* Data Cache Block Flush */
4681 case 278: /* Data Cache Block Touch */
4682 case 758: /* Data Cache Block Allocate */
4683 case 982: /* Instruction Cache Block Invalidate */
6ec2b213
EBM
4684 case 774: /* Copy */
4685 case 838: /* CP_Abort */
b4cdae6f
WW
4686 return 0;
4687
4688 case 654: /* Transaction Begin */
4689 case 686: /* Transaction End */
b4cdae6f
WW
4690 case 750: /* Transaction Suspend or Resume */
4691 case 782: /* Transaction Abort Word Conditional */
4692 case 814: /* Transaction Abort Doubleword Conditional */
4693 case 846: /* Transaction Abort Word Conditional Immediate */
4694 case 878: /* Transaction Abort Doubleword Conditional Immediate */
4695 case 910: /* Transaction Abort */
d44c67f3
EBM
4696 record_full_arch_list_add_reg (regcache, tdep->ppc_ps_regnum);
4697 /* FALL-THROUGH */
4698 case 718: /* Transaction Check */
4699 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4700 return 0;
b4cdae6f
WW
4701
4702 case 1014: /* Data Cache Block set to Zero */
8b88a78e 4703 if (target_auxv_search (current_top_target (), AT_DCACHEBSIZE, &at_dcsz) <= 0
b4cdae6f
WW
4704 || at_dcsz == 0)
4705 at_dcsz = 128; /* Assume 128-byte cache line size (POWER8) */
4706
bec734b2 4707 ra = 0;
b4cdae6f
WW
4708 if (PPC_RA (insn) != 0)
4709 regcache_raw_read_unsigned (regcache,
4710 tdep->ppc_gp0_regnum + PPC_RA (insn), &ra);
4711 regcache_raw_read_unsigned (regcache,
4712 tdep->ppc_gp0_regnum + PPC_RB (insn), &rb);
4713 ea = (ra + rb) & ~((ULONGEST) (at_dcsz - 1));
4714 record_full_arch_list_add_mem (ea, at_dcsz);
4715 return 0;
4716 }
4717
4718UNKNOWN_OP:
810c1026
WW
4719 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4720 "at %s, 31-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4721 return -1;
4722}
4723
ddeca1df
WW
4724/* Parse and record instructions of primary opcode-59 at ADDR.
4725 Return 0 if successful. */
b4cdae6f
WW
4726
4727static int
4728ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
4729 CORE_ADDR addr, uint32_t insn)
4730{
4731 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4732 int ext = PPC_EXTOP (insn);
4733
4734 switch (ext & 0x1f)
4735 {
4736 case 18: /* Floating Divide */
4737 case 20: /* Floating Subtract */
4738 case 21: /* Floating Add */
4739 case 22: /* Floating Square Root */
4740 case 24: /* Floating Reciprocal Estimate */
4741 case 25: /* Floating Multiply */
4742 case 26: /* Floating Reciprocal Square Root Estimate */
4743 case 28: /* Floating Multiply-Subtract */
4744 case 29: /* Floating Multiply-Add */
4745 case 30: /* Floating Negative Multiply-Subtract */
4746 case 31: /* Floating Negative Multiply-Add */
4747 record_full_arch_list_add_reg (regcache,
4748 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4749 if (PPC_RC (insn))
4750 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4751 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4752
4753 return 0;
4754 }
4755
4756 switch (ext)
4757 {
4758 case 2: /* DFP Add */
4759 case 3: /* DFP Quantize */
4760 case 34: /* DFP Multiply */
4761 case 35: /* DFP Reround */
4762 case 67: /* DFP Quantize Immediate */
4763 case 99: /* DFP Round To FP Integer With Inexact */
4764 case 227: /* DFP Round To FP Integer Without Inexact */
4765 case 258: /* DFP Convert To DFP Long! */
4766 case 290: /* DFP Convert To Fixed */
4767 case 514: /* DFP Subtract */
4768 case 546: /* DFP Divide */
4769 case 770: /* DFP Round To DFP Short! */
4770 case 802: /* DFP Convert From Fixed */
4771 case 834: /* DFP Encode BCD To DPD */
4772 if (PPC_RC (insn))
4773 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4774 record_full_arch_list_add_reg (regcache,
4775 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4776 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4777 return 0;
4778
4779 case 130: /* DFP Compare Ordered */
4780 case 162: /* DFP Test Exponent */
4781 case 194: /* DFP Test Data Class */
4782 case 226: /* DFP Test Data Group */
4783 case 642: /* DFP Compare Unordered */
4784 case 674: /* DFP Test Significance */
6ec2b213 4785 case 675: /* DFP Test Significance Immediate */
b4cdae6f
WW
4786 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4787 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4788 return 0;
4789
4790 case 66: /* DFP Shift Significand Left Immediate */
4791 case 98: /* DFP Shift Significand Right Immediate */
4792 case 322: /* DFP Decode DPD To BCD */
4793 case 354: /* DFP Extract Biased Exponent */
4794 case 866: /* DFP Insert Biased Exponent */
4795 record_full_arch_list_add_reg (regcache,
4796 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4797 if (PPC_RC (insn))
4798 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4799 return 0;
4800
4801 case 846: /* Floating Convert From Integer Doubleword Single */
4802 case 974: /* Floating Convert From Integer Doubleword Unsigned
4803 Single */
4804 record_full_arch_list_add_reg (regcache,
4805 tdep->ppc_fp0_regnum + PPC_FRT (insn));
4806 if (PPC_RC (insn))
4807 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4808 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4809
4810 return 0;
4811 }
4812
810c1026
WW
4813 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
4814 "at %s, 59-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
4815 return -1;
4816}
4817
ddeca1df
WW
4818/* Parse and record instructions of primary opcode-60 at ADDR.
4819 Return 0 if successful. */
b4cdae6f
WW
4820
4821static int
4822ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
4823 CORE_ADDR addr, uint32_t insn)
4824{
4825 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4826 int ext = PPC_EXTOP (insn);
b4cdae6f
WW
4827
4828 switch (ext >> 2)
4829 {
4830 case 0: /* VSX Scalar Add Single-Precision */
4831 case 32: /* VSX Scalar Add Double-Precision */
4832 case 24: /* VSX Scalar Divide Single-Precision */
4833 case 56: /* VSX Scalar Divide Double-Precision */
4834 case 176: /* VSX Scalar Copy Sign Double-Precision */
4835 case 33: /* VSX Scalar Multiply-Add Double-Precision */
4836 case 41: /* ditto */
4837 case 1: /* VSX Scalar Multiply-Add Single-Precision */
4838 case 9: /* ditto */
4839 case 160: /* VSX Scalar Maximum Double-Precision */
4840 case 168: /* VSX Scalar Minimum Double-Precision */
4841 case 49: /* VSX Scalar Multiply-Subtract Double-Precision */
4842 case 57: /* ditto */
4843 case 17: /* VSX Scalar Multiply-Subtract Single-Precision */
4844 case 25: /* ditto */
4845 case 48: /* VSX Scalar Multiply Double-Precision */
4846 case 16: /* VSX Scalar Multiply Single-Precision */
4847 case 161: /* VSX Scalar Negative Multiply-Add Double-Precision */
4848 case 169: /* ditto */
4849 case 129: /* VSX Scalar Negative Multiply-Add Single-Precision */
4850 case 137: /* ditto */
4851 case 177: /* VSX Scalar Negative Multiply-Subtract Double-Precision */
4852 case 185: /* ditto */
4853 case 145: /* VSX Scalar Negative Multiply-Subtract Single-Precision */
4854 case 153: /* ditto */
4855 case 40: /* VSX Scalar Subtract Double-Precision */
4856 case 8: /* VSX Scalar Subtract Single-Precision */
4857 case 96: /* VSX Vector Add Double-Precision */
4858 case 64: /* VSX Vector Add Single-Precision */
4859 case 120: /* VSX Vector Divide Double-Precision */
4860 case 88: /* VSX Vector Divide Single-Precision */
4861 case 97: /* VSX Vector Multiply-Add Double-Precision */
4862 case 105: /* ditto */
4863 case 65: /* VSX Vector Multiply-Add Single-Precision */
4864 case 73: /* ditto */
4865 case 224: /* VSX Vector Maximum Double-Precision */
4866 case 192: /* VSX Vector Maximum Single-Precision */
4867 case 232: /* VSX Vector Minimum Double-Precision */
4868 case 200: /* VSX Vector Minimum Single-Precision */
4869 case 113: /* VSX Vector Multiply-Subtract Double-Precision */
4870 case 121: /* ditto */
4871 case 81: /* VSX Vector Multiply-Subtract Single-Precision */
4872 case 89: /* ditto */
4873 case 112: /* VSX Vector Multiply Double-Precision */
4874 case 80: /* VSX Vector Multiply Single-Precision */
4875 case 225: /* VSX Vector Negative Multiply-Add Double-Precision */
4876 case 233: /* ditto */
4877 case 193: /* VSX Vector Negative Multiply-Add Single-Precision */
4878 case 201: /* ditto */
4879 case 241: /* VSX Vector Negative Multiply-Subtract Double-Precision */
4880 case 249: /* ditto */
4881 case 209: /* VSX Vector Negative Multiply-Subtract Single-Precision */
4882 case 217: /* ditto */
4883 case 104: /* VSX Vector Subtract Double-Precision */
4884 case 72: /* VSX Vector Subtract Single-Precision */
6ec2b213
EBM
4885 case 128: /* VSX Scalar Maximum Type-C Double-Precision */
4886 case 136: /* VSX Scalar Minimum Type-C Double-Precision */
4887 case 144: /* VSX Scalar Maximum Type-J Double-Precision */
4888 case 152: /* VSX Scalar Minimum Type-J Double-Precision */
4889 case 3: /* VSX Scalar Compare Equal Double-Precision */
4890 case 11: /* VSX Scalar Compare Greater Than Double-Precision */
4891 case 19: /* VSX Scalar Compare Greater Than or Equal
4892 Double-Precision */
b4cdae6f 4893 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
6ec2b213 4894 /* FALL-THROUGH */
b4cdae6f
WW
4895 case 240: /* VSX Vector Copy Sign Double-Precision */
4896 case 208: /* VSX Vector Copy Sign Single-Precision */
4897 case 130: /* VSX Logical AND */
4898 case 138: /* VSX Logical AND with Complement */
4899 case 186: /* VSX Logical Equivalence */
4900 case 178: /* VSX Logical NAND */
4901 case 170: /* VSX Logical OR with Complement */
4902 case 162: /* VSX Logical NOR */
4903 case 146: /* VSX Logical OR */
4904 case 154: /* VSX Logical XOR */
4905 case 18: /* VSX Merge High Word */
4906 case 50: /* VSX Merge Low Word */
4907 case 10: /* VSX Permute Doubleword Immediate (DM=0) */
4908 case 10 | 0x20: /* VSX Permute Doubleword Immediate (DM=1) */
4909 case 10 | 0x40: /* VSX Permute Doubleword Immediate (DM=2) */
4910 case 10 | 0x60: /* VSX Permute Doubleword Immediate (DM=3) */
4911 case 2: /* VSX Shift Left Double by Word Immediate (SHW=0) */
4912 case 2 | 0x20: /* VSX Shift Left Double by Word Immediate (SHW=1) */
4913 case 2 | 0x40: /* VSX Shift Left Double by Word Immediate (SHW=2) */
4914 case 2 | 0x60: /* VSX Shift Left Double by Word Immediate (SHW=3) */
6ec2b213
EBM
4915 case 216: /* VSX Vector Insert Exponent Single-Precision */
4916 case 248: /* VSX Vector Insert Exponent Double-Precision */
4917 case 26: /* VSX Vector Permute */
4918 case 58: /* VSX Vector Permute Right-indexed */
4919 case 213: /* VSX Vector Test Data Class Single-Precision (DC=0) */
4920 case 213 | 0x8: /* VSX Vector Test Data Class Single-Precision (DC=1) */
4921 case 245: /* VSX Vector Test Data Class Double-Precision (DC=0) */
4922 case 245 | 0x8: /* VSX Vector Test Data Class Double-Precision (DC=1) */
b4cdae6f
WW
4923 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4924 return 0;
4925
4926 case 61: /* VSX Scalar Test for software Divide Double-Precision */
4927 case 125: /* VSX Vector Test for software Divide Double-Precision */
4928 case 93: /* VSX Vector Test for software Divide Single-Precision */
4929 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4930 return 0;
4931
4932 case 35: /* VSX Scalar Compare Unordered Double-Precision */
4933 case 43: /* VSX Scalar Compare Ordered Double-Precision */
6ec2b213 4934 case 59: /* VSX Scalar Compare Exponents Double-Precision */
b4cdae6f
WW
4935 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4936 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4937 return 0;
4938 }
4939
4940 switch ((ext >> 2) & 0x7f) /* Mask out Rc-bit. */
4941 {
4942 case 99: /* VSX Vector Compare Equal To Double-Precision */
4943 case 67: /* VSX Vector Compare Equal To Single-Precision */
4944 case 115: /* VSX Vector Compare Greater Than or
4945 Equal To Double-Precision */
4946 case 83: /* VSX Vector Compare Greater Than or
4947 Equal To Single-Precision */
4948 case 107: /* VSX Vector Compare Greater Than Double-Precision */
4949 case 75: /* VSX Vector Compare Greater Than Single-Precision */
4950 if (PPC_Rc (insn))
4951 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
4952 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
4953 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
4954 return 0;
4955 }
4956
4957 switch (ext >> 1)
4958 {
4959 case 265: /* VSX Scalar round Double-Precision to
4960 Single-Precision and Convert to
4961 Single-Precision format */
4962 case 344: /* VSX Scalar truncate Double-Precision to
4963 Integer and Convert to Signed Integer
4964 Doubleword format with Saturate */
4965 case 88: /* VSX Scalar truncate Double-Precision to
4966 Integer and Convert to Signed Integer Word
4967 Format with Saturate */
4968 case 328: /* VSX Scalar truncate Double-Precision integer
4969 and Convert to Unsigned Integer Doubleword
4970 Format with Saturate */
4971 case 72: /* VSX Scalar truncate Double-Precision to
4972 Integer and Convert to Unsigned Integer Word
4973 Format with Saturate */
4974 case 329: /* VSX Scalar Convert Single-Precision to
4975 Double-Precision format */
4976 case 376: /* VSX Scalar Convert Signed Integer
4977 Doubleword to floating-point format and
4978 Round to Double-Precision format */
4979 case 312: /* VSX Scalar Convert Signed Integer
4980 Doubleword to floating-point format and
4981 round to Single-Precision */
4982 case 360: /* VSX Scalar Convert Unsigned Integer
4983 Doubleword to floating-point format and
4984 Round to Double-Precision format */
4985 case 296: /* VSX Scalar Convert Unsigned Integer
4986 Doubleword to floating-point format and
4987 Round to Single-Precision */
4988 case 73: /* VSX Scalar Round to Double-Precision Integer
4989 Using Round to Nearest Away */
4990 case 107: /* VSX Scalar Round to Double-Precision Integer
4991 Exact using Current rounding mode */
4992 case 121: /* VSX Scalar Round to Double-Precision Integer
4993 Using Round toward -Infinity */
4994 case 105: /* VSX Scalar Round to Double-Precision Integer
4995 Using Round toward +Infinity */
4996 case 89: /* VSX Scalar Round to Double-Precision Integer
4997 Using Round toward Zero */
4998 case 90: /* VSX Scalar Reciprocal Estimate Double-Precision */
4999 case 26: /* VSX Scalar Reciprocal Estimate Single-Precision */
5000 case 281: /* VSX Scalar Round to Single-Precision */
5001 case 74: /* VSX Scalar Reciprocal Square Root Estimate
5002 Double-Precision */
5003 case 10: /* VSX Scalar Reciprocal Square Root Estimate
5004 Single-Precision */
5005 case 75: /* VSX Scalar Square Root Double-Precision */
5006 case 11: /* VSX Scalar Square Root Single-Precision */
5007 case 393: /* VSX Vector round Double-Precision to
5008 Single-Precision and Convert to
5009 Single-Precision format */
5010 case 472: /* VSX Vector truncate Double-Precision to
5011 Integer and Convert to Signed Integer
5012 Doubleword format with Saturate */
5013 case 216: /* VSX Vector truncate Double-Precision to
5014 Integer and Convert to Signed Integer Word
5015 Format with Saturate */
5016 case 456: /* VSX Vector truncate Double-Precision to
5017 Integer and Convert to Unsigned Integer
5018 Doubleword format with Saturate */
5019 case 200: /* VSX Vector truncate Double-Precision to
5020 Integer and Convert to Unsigned Integer Word
5021 Format with Saturate */
5022 case 457: /* VSX Vector Convert Single-Precision to
5023 Double-Precision format */
5024 case 408: /* VSX Vector truncate Single-Precision to
5025 Integer and Convert to Signed Integer
5026 Doubleword format with Saturate */
5027 case 152: /* VSX Vector truncate Single-Precision to
5028 Integer and Convert to Signed Integer Word
5029 Format with Saturate */
5030 case 392: /* VSX Vector truncate Single-Precision to
5031 Integer and Convert to Unsigned Integer
5032 Doubleword format with Saturate */
5033 case 136: /* VSX Vector truncate Single-Precision to
5034 Integer and Convert to Unsigned Integer Word
5035 Format with Saturate */
5036 case 504: /* VSX Vector Convert and round Signed Integer
5037 Doubleword to Double-Precision format */
5038 case 440: /* VSX Vector Convert and round Signed Integer
5039 Doubleword to Single-Precision format */
5040 case 248: /* VSX Vector Convert Signed Integer Word to
5041 Double-Precision format */
5042 case 184: /* VSX Vector Convert and round Signed Integer
5043 Word to Single-Precision format */
5044 case 488: /* VSX Vector Convert and round Unsigned
5045 Integer Doubleword to Double-Precision format */
5046 case 424: /* VSX Vector Convert and round Unsigned
5047 Integer Doubleword to Single-Precision format */
5048 case 232: /* VSX Vector Convert and round Unsigned
5049 Integer Word to Double-Precision format */
5050 case 168: /* VSX Vector Convert and round Unsigned
5051 Integer Word to Single-Precision format */
5052 case 201: /* VSX Vector Round to Double-Precision
5053 Integer using round to Nearest Away */
5054 case 235: /* VSX Vector Round to Double-Precision
5055 Integer Exact using Current rounding mode */
5056 case 249: /* VSX Vector Round to Double-Precision
5057 Integer using round toward -Infinity */
5058 case 233: /* VSX Vector Round to Double-Precision
5059 Integer using round toward +Infinity */
5060 case 217: /* VSX Vector Round to Double-Precision
5061 Integer using round toward Zero */
5062 case 218: /* VSX Vector Reciprocal Estimate Double-Precision */
5063 case 154: /* VSX Vector Reciprocal Estimate Single-Precision */
5064 case 137: /* VSX Vector Round to Single-Precision Integer
5065 Using Round to Nearest Away */
5066 case 171: /* VSX Vector Round to Single-Precision Integer
5067 Exact Using Current rounding mode */
5068 case 185: /* VSX Vector Round to Single-Precision Integer
5069 Using Round toward -Infinity */
5070 case 169: /* VSX Vector Round to Single-Precision Integer
5071 Using Round toward +Infinity */
5072 case 153: /* VSX Vector Round to Single-Precision Integer
5073 Using round toward Zero */
5074 case 202: /* VSX Vector Reciprocal Square Root Estimate
5075 Double-Precision */
5076 case 138: /* VSX Vector Reciprocal Square Root Estimate
5077 Single-Precision */
5078 case 203: /* VSX Vector Square Root Double-Precision */
5079 case 139: /* VSX Vector Square Root Single-Precision */
5080 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
6ec2b213 5081 /* FALL-THROUGH */
b4cdae6f
WW
5082 case 345: /* VSX Scalar Absolute Value Double-Precision */
5083 case 267: /* VSX Scalar Convert Scalar Single-Precision to
5084 Vector Single-Precision format Non-signalling */
5085 case 331: /* VSX Scalar Convert Single-Precision to
5086 Double-Precision format Non-signalling */
5087 case 361: /* VSX Scalar Negative Absolute Value Double-Precision */
5088 case 377: /* VSX Scalar Negate Double-Precision */
5089 case 473: /* VSX Vector Absolute Value Double-Precision */
5090 case 409: /* VSX Vector Absolute Value Single-Precision */
5091 case 489: /* VSX Vector Negative Absolute Value Double-Precision */
5092 case 425: /* VSX Vector Negative Absolute Value Single-Precision */
5093 case 505: /* VSX Vector Negate Double-Precision */
5094 case 441: /* VSX Vector Negate Single-Precision */
5095 case 164: /* VSX Splat Word */
6ec2b213
EBM
5096 case 165: /* VSX Vector Extract Unsigned Word */
5097 case 181: /* VSX Vector Insert Word */
b4cdae6f
WW
5098 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
5099 return 0;
5100
6ec2b213
EBM
5101 case 298: /* VSX Scalar Test Data Class Single-Precision */
5102 case 362: /* VSX Scalar Test Data Class Double-Precision */
5103 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5104 /* FALL-THROUGH */
b4cdae6f
WW
5105 case 106: /* VSX Scalar Test for software Square Root
5106 Double-Precision */
5107 case 234: /* VSX Vector Test for software Square Root
5108 Double-Precision */
5109 case 170: /* VSX Vector Test for software Square Root
5110 Single-Precision */
5111 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5112 return 0;
6ec2b213
EBM
5113
5114 case 347:
5115 switch (PPC_FIELD (insn, 11, 5))
5116 {
5117 case 0: /* VSX Scalar Extract Exponent Double-Precision */
5118 case 1: /* VSX Scalar Extract Significand Double-Precision */
5119 record_full_arch_list_add_reg (regcache,
5120 tdep->ppc_gp0_regnum + PPC_RT (insn));
5121 return 0;
5122 case 16: /* VSX Scalar Convert Half-Precision format to
5123 Double-Precision format */
5124 case 17: /* VSX Scalar round & Convert Double-Precision format
5125 to Half-Precision format */
5126 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5127 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
5128 return 0;
5129 }
5130 break;
5131
5132 case 475:
5133 switch (PPC_FIELD (insn, 11, 5))
5134 {
5135 case 24: /* VSX Vector Convert Half-Precision format to
5136 Single-Precision format */
5137 case 25: /* VSX Vector round and Convert Single-Precision format
5138 to Half-Precision format */
5139 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5140 /* FALL-THROUGH */
5141 case 0: /* VSX Vector Extract Exponent Double-Precision */
5142 case 1: /* VSX Vector Extract Significand Double-Precision */
5143 case 7: /* VSX Vector Byte-Reverse Halfword */
5144 case 8: /* VSX Vector Extract Exponent Single-Precision */
5145 case 9: /* VSX Vector Extract Significand Single-Precision */
5146 case 15: /* VSX Vector Byte-Reverse Word */
5147 case 23: /* VSX Vector Byte-Reverse Doubleword */
5148 case 31: /* VSX Vector Byte-Reverse Quadword */
5149 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
5150 return 0;
5151 }
5152 break;
5153 }
5154
5155 switch (ext)
5156 {
5157 case 360: /* VSX Vector Splat Immediate Byte */
5158 if (PPC_FIELD (insn, 11, 2) == 0)
5159 {
5160 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
5161 return 0;
5162 }
5163 break;
5164 case 918: /* VSX Scalar Insert Exponent Double-Precision */
5165 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
5166 return 0;
b4cdae6f
WW
5167 }
5168
5169 if (((ext >> 3) & 0x3) == 3) /* VSX Select */
5170 {
5171 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
5172 return 0;
5173 }
5174
810c1026
WW
5175 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
5176 "at %s, 60-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
5177 return -1;
5178}
5179
6ec2b213
EBM
5180/* Parse and record instructions of primary opcode-61 at ADDR.
5181 Return 0 if successful. */
5182
5183static int
5184ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache,
5185 CORE_ADDR addr, uint32_t insn)
5186{
5187 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
5188 ULONGEST ea = 0;
5189 int size;
5190
5191 switch (insn & 0x3)
5192 {
5193 case 0: /* Store Floating-Point Double Pair */
5194 case 2: /* Store VSX Scalar Doubleword */
5195 case 3: /* Store VSX Scalar Single */
5196 if (PPC_RA (insn) != 0)
5197 regcache_raw_read_unsigned (regcache,
5198 tdep->ppc_gp0_regnum + PPC_RA (insn),
5199 &ea);
5200 ea += PPC_DS (insn) << 2;
5201 switch (insn & 0x3)
5202 {
5203 case 0: /* Store Floating-Point Double Pair */
5204 size = 16;
5205 break;
5206 case 2: /* Store VSX Scalar Doubleword */
5207 size = 8;
5208 break;
5209 case 3: /* Store VSX Scalar Single */
5210 size = 4;
5211 break;
5212 default:
5213 gdb_assert (0);
5214 }
5215 record_full_arch_list_add_mem (ea, size);
5216 return 0;
5217 }
5218
5219 switch (insn & 0x7)
5220 {
5221 case 1: /* Load VSX Vector */
5222 ppc_record_vsr (regcache, tdep, PPC_XT (insn));
5223 return 0;
5224 case 5: /* Store VSX Vector */
5225 if (PPC_RA (insn) != 0)
5226 regcache_raw_read_unsigned (regcache,
5227 tdep->ppc_gp0_regnum + PPC_RA (insn),
5228 &ea);
5229 ea += PPC_DQ (insn) << 4;
5230 record_full_arch_list_add_mem (ea, 16);
5231 return 0;
5232 }
5233
5234 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
5235 "at %s.\n", insn, paddress (gdbarch, addr));
5236 return -1;
5237}
5238
ddeca1df
WW
5239/* Parse and record instructions of primary opcode-63 at ADDR.
5240 Return 0 if successful. */
b4cdae6f
WW
5241
5242static int
5243ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
5244 CORE_ADDR addr, uint32_t insn)
5245{
5246 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
5247 int ext = PPC_EXTOP (insn);
5248 int tmp;
5249
5250 switch (ext & 0x1f)
5251 {
5252 case 18: /* Floating Divide */
5253 case 20: /* Floating Subtract */
5254 case 21: /* Floating Add */
5255 case 22: /* Floating Square Root */
5256 case 24: /* Floating Reciprocal Estimate */
5257 case 25: /* Floating Multiply */
5258 case 26: /* Floating Reciprocal Square Root Estimate */
5259 case 28: /* Floating Multiply-Subtract */
5260 case 29: /* Floating Multiply-Add */
5261 case 30: /* Floating Negative Multiply-Subtract */
5262 case 31: /* Floating Negative Multiply-Add */
5263 record_full_arch_list_add_reg (regcache,
5264 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5265 if (PPC_RC (insn))
5266 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5267 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5268 return 0;
5269
5270 case 23: /* Floating Select */
5271 record_full_arch_list_add_reg (regcache,
5272 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5273 if (PPC_RC (insn))
5274 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
8aabe2e2 5275 return 0;
b4cdae6f
WW
5276 }
5277
6ec2b213
EBM
5278 switch (ext & 0xff)
5279 {
5280 case 5: /* VSX Scalar Round to Quad-Precision Integer */
5281 case 37: /* VSX Scalar Round Quad-Precision to Double-Extended
5282 Precision */
5283 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5284 ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32);
5285 return 0;
5286 }
5287
b4cdae6f
WW
5288 switch (ext)
5289 {
5290 case 2: /* DFP Add Quad */
5291 case 3: /* DFP Quantize Quad */
5292 case 34: /* DFP Multiply Quad */
5293 case 35: /* DFP Reround Quad */
5294 case 67: /* DFP Quantize Immediate Quad */
5295 case 99: /* DFP Round To FP Integer With Inexact Quad */
5296 case 227: /* DFP Round To FP Integer Without Inexact Quad */
5297 case 258: /* DFP Convert To DFP Extended Quad */
5298 case 514: /* DFP Subtract Quad */
5299 case 546: /* DFP Divide Quad */
5300 case 770: /* DFP Round To DFP Long Quad */
5301 case 802: /* DFP Convert From Fixed Quad */
5302 case 834: /* DFP Encode BCD To DPD Quad */
5303 if (PPC_RC (insn))
5304 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5305 tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1);
5306 record_full_arch_list_add_reg (regcache, tmp);
5307 record_full_arch_list_add_reg (regcache, tmp + 1);
5308 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5309 return 0;
5310
5311 case 130: /* DFP Compare Ordered Quad */
5312 case 162: /* DFP Test Exponent Quad */
5313 case 194: /* DFP Test Data Class Quad */
5314 case 226: /* DFP Test Data Group Quad */
5315 case 642: /* DFP Compare Unordered Quad */
5316 case 674: /* DFP Test Significance Quad */
6ec2b213 5317 case 675: /* DFP Test Significance Immediate Quad */
b4cdae6f
WW
5318 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5319 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5320 return 0;
5321
5322 case 66: /* DFP Shift Significand Left Immediate Quad */
5323 case 98: /* DFP Shift Significand Right Immediate Quad */
5324 case 322: /* DFP Decode DPD To BCD Quad */
5325 case 866: /* DFP Insert Biased Exponent Quad */
5326 tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1);
5327 record_full_arch_list_add_reg (regcache, tmp);
5328 record_full_arch_list_add_reg (regcache, tmp + 1);
5329 if (PPC_RC (insn))
5330 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5331 return 0;
5332
5333 case 290: /* DFP Convert To Fixed Quad */
5334 record_full_arch_list_add_reg (regcache,
5335 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5336 if (PPC_RC (insn))
5337 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5338 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
8aabe2e2 5339 return 0;
b4cdae6f
WW
5340
5341 case 354: /* DFP Extract Biased Exponent Quad */
5342 record_full_arch_list_add_reg (regcache,
5343 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5344 if (PPC_RC (insn))
5345 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5346 return 0;
5347
5348 case 12: /* Floating Round to Single-Precision */
5349 case 14: /* Floating Convert To Integer Word */
5350 case 15: /* Floating Convert To Integer Word
5351 with round toward Zero */
5352 case 142: /* Floating Convert To Integer Word Unsigned */
5353 case 143: /* Floating Convert To Integer Word Unsigned
5354 with round toward Zero */
5355 case 392: /* Floating Round to Integer Nearest */
5356 case 424: /* Floating Round to Integer Toward Zero */
5357 case 456: /* Floating Round to Integer Plus */
5358 case 488: /* Floating Round to Integer Minus */
5359 case 814: /* Floating Convert To Integer Doubleword */
5360 case 815: /* Floating Convert To Integer Doubleword
5361 with round toward Zero */
5362 case 846: /* Floating Convert From Integer Doubleword */
5363 case 942: /* Floating Convert To Integer Doubleword Unsigned */
5364 case 943: /* Floating Convert To Integer Doubleword Unsigned
5365 with round toward Zero */
5366 case 974: /* Floating Convert From Integer Doubleword Unsigned */
5367 record_full_arch_list_add_reg (regcache,
5368 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5369 if (PPC_RC (insn))
5370 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5371 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5372 return 0;
5373
6ec2b213
EBM
5374 case 583:
5375 switch (PPC_FIELD (insn, 11, 5))
5376 {
5377 case 1: /* Move From FPSCR & Clear Enables */
5378 case 20: /* Move From FPSCR Control & set DRN */
5379 case 21: /* Move From FPSCR Control & set DRN Immediate */
5380 case 22: /* Move From FPSCR Control & set RN */
5381 case 23: /* Move From FPSCR Control & set RN Immediate */
5382 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
e3829d13 5383 /* Fall through. */
6ec2b213
EBM
5384 case 0: /* Move From FPSCR */
5385 case 24: /* Move From FPSCR Lightweight */
5386 if (PPC_FIELD (insn, 11, 5) == 0 && PPC_RC (insn))
5387 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5388 record_full_arch_list_add_reg (regcache,
5389 tdep->ppc_fp0_regnum
5390 + PPC_FRT (insn));
5391 return 0;
5392 }
5393 break;
5394
b4cdae6f
WW
5395 case 8: /* Floating Copy Sign */
5396 case 40: /* Floating Negate */
5397 case 72: /* Floating Move Register */
5398 case 136: /* Floating Negative Absolute Value */
5399 case 264: /* Floating Absolute Value */
5400 record_full_arch_list_add_reg (regcache,
5401 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5402 if (PPC_RC (insn))
5403 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5404 return 0;
5405
5406 case 838: /* Floating Merge Odd Word */
5407 case 966: /* Floating Merge Even Word */
5408 record_full_arch_list_add_reg (regcache,
5409 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5410 return 0;
5411
5412 case 38: /* Move To FPSCR Bit 1 */
5413 case 70: /* Move To FPSCR Bit 0 */
5414 case 134: /* Move To FPSCR Field Immediate */
5415 case 711: /* Move To FPSCR Fields */
5416 if (PPC_RC (insn))
5417 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5418 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
8aabe2e2 5419 return 0;
b4cdae6f
WW
5420
5421 case 0: /* Floating Compare Unordered */
5422 case 32: /* Floating Compare Ordered */
5423 case 64: /* Move to Condition Register from FPSCR */
6ec2b213
EBM
5424 case 132: /* VSX Scalar Compare Ordered Quad-Precision */
5425 case 164: /* VSX Scalar Compare Exponents Quad-Precision */
5426 case 644: /* VSX Scalar Compare Unordered Quad-Precision */
5427 case 708: /* VSX Scalar Test Data Class Quad-Precision */
b4cdae6f
WW
5428 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5429 /* FALL-THROUGH */
5430 case 128: /* Floating Test for software Divide */
5431 case 160: /* Floating Test for software Square Root */
5432 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5433 return 0;
5434
6ec2b213
EBM
5435 case 4: /* VSX Scalar Add Quad-Precision */
5436 case 36: /* VSX Scalar Multiply Quad-Precision */
5437 case 388: /* VSX Scalar Multiply-Add Quad-Precision */
5438 case 420: /* VSX Scalar Multiply-Subtract Quad-Precision */
5439 case 452: /* VSX Scalar Negative Multiply-Add Quad-Precision */
5440 case 484: /* VSX Scalar Negative Multiply-Subtract
5441 Quad-Precision */
5442 case 516: /* VSX Scalar Subtract Quad-Precision */
5443 case 548: /* VSX Scalar Divide Quad-Precision */
5444 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5445 /* FALL-THROUGH */
5446 case 100: /* VSX Scalar Copy Sign Quad-Precision */
5447 case 868: /* VSX Scalar Insert Exponent Quad-Precision */
5448 ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32);
5449 return 0;
5450
5451 case 804:
5452 switch (PPC_FIELD (insn, 11, 5))
5453 {
5454 case 27: /* VSX Scalar Square Root Quad-Precision */
5455 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5456 /* FALL-THROUGH */
5457 case 0: /* VSX Scalar Absolute Quad-Precision */
5458 case 2: /* VSX Scalar Extract Exponent Quad-Precision */
5459 case 8: /* VSX Scalar Negative Absolute Quad-Precision */
5460 case 16: /* VSX Scalar Negate Quad-Precision */
5461 case 18: /* VSX Scalar Extract Significand Quad-Precision */
5462 ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32);
5463 return 0;
5464 }
5465 break;
5466
5467 case 836:
5468 switch (PPC_FIELD (insn, 11, 5))
5469 {
5470 case 1: /* VSX Scalar truncate & Convert Quad-Precision format
5471 to Unsigned Word format */
5472 case 2: /* VSX Scalar Convert Unsigned Doubleword format to
5473 Quad-Precision format */
5474 case 9: /* VSX Scalar truncate & Convert Quad-Precision format
5475 to Signed Word format */
5476 case 10: /* VSX Scalar Convert Signed Doubleword format to
5477 Quad-Precision format */
5478 case 17: /* VSX Scalar truncate & Convert Quad-Precision format
5479 to Unsigned Doubleword format */
5480 case 20: /* VSX Scalar round & Convert Quad-Precision format to
5481 Double-Precision format */
5482 case 22: /* VSX Scalar Convert Double-Precision format to
5483 Quad-Precision format */
5484 case 25: /* VSX Scalar truncate & Convert Quad-Precision format
5485 to Signed Doubleword format */
5486 record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum);
5487 ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32);
5488 return 0;
5489 }
b4cdae6f
WW
5490 }
5491
810c1026 5492 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
6ec2b213 5493 "at %s, 63-%d.\n", insn, paddress (gdbarch, addr), ext);
b4cdae6f
WW
5494 return -1;
5495}
5496
5497/* Parse the current instruction and record the values of the registers and
5498 memory that will be changed in current instruction to "record_arch_list".
5499 Return -1 if something wrong. */
5500
5501int
5502ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
5503 CORE_ADDR addr)
5504{
5505 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
5506 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
5507 uint32_t insn;
5508 int op6, tmp, i;
5509
5510 insn = read_memory_unsigned_integer (addr, 4, byte_order);
5511 op6 = PPC_OP6 (insn);
5512
5513 switch (op6)
5514 {
5515 case 2: /* Trap Doubleword Immediate */
5516 case 3: /* Trap Word Immediate */
5517 /* Do nothing. */
5518 break;
5519
5520 case 4:
5521 if (ppc_process_record_op4 (gdbarch, regcache, addr, insn) != 0)
5522 return -1;
5523 break;
5524
5525 case 17: /* System call */
5526 if (PPC_LEV (insn) != 0)
5527 goto UNKNOWN_OP;
5528
5529 if (tdep->ppc_syscall_record != NULL)
5530 {
5531 if (tdep->ppc_syscall_record (regcache) != 0)
5532 return -1;
5533 }
5534 else
5535 {
5536 printf_unfiltered (_("no syscall record support\n"));
5537 return -1;
5538 }
5539 break;
5540
5541 case 7: /* Multiply Low Immediate */
5542 record_full_arch_list_add_reg (regcache,
5543 tdep->ppc_gp0_regnum + PPC_RT (insn));
5544 break;
5545
5546 case 8: /* Subtract From Immediate Carrying */
5547 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
5548 record_full_arch_list_add_reg (regcache,
5549 tdep->ppc_gp0_regnum + PPC_RT (insn));
5550 break;
5551
5552 case 10: /* Compare Logical Immediate */
5553 case 11: /* Compare Immediate */
5554 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5555 break;
5556
5557 case 13: /* Add Immediate Carrying and Record */
5558 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5559 /* FALL-THROUGH */
5560 case 12: /* Add Immediate Carrying */
5561 record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum);
5562 /* FALL-THROUGH */
5563 case 14: /* Add Immediate */
5564 case 15: /* Add Immediate Shifted */
5565 record_full_arch_list_add_reg (regcache,
5566 tdep->ppc_gp0_regnum + PPC_RT (insn));
5567 break;
5568
5569 case 16: /* Branch Conditional */
5570 if ((PPC_BO (insn) & 0x4) == 0)
5571 record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum);
5572 /* FALL-THROUGH */
5573 case 18: /* Branch */
5574 if (PPC_LK (insn))
5575 record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum);
5576 break;
5577
5578 case 19:
5579 if (ppc_process_record_op19 (gdbarch, regcache, addr, insn) != 0)
5580 return -1;
5581 break;
5582
5583 case 20: /* Rotate Left Word Immediate then Mask Insert */
5584 case 21: /* Rotate Left Word Immediate then AND with Mask */
5585 case 23: /* Rotate Left Word then AND with Mask */
5586 case 30: /* Rotate Left Doubleword Immediate then Clear Left */
5587 /* Rotate Left Doubleword Immediate then Clear Right */
5588 /* Rotate Left Doubleword Immediate then Clear */
5589 /* Rotate Left Doubleword then Clear Left */
5590 /* Rotate Left Doubleword then Clear Right */
5591 /* Rotate Left Doubleword Immediate then Mask Insert */
5592 if (PPC_RC (insn))
5593 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5594 record_full_arch_list_add_reg (regcache,
5595 tdep->ppc_gp0_regnum + PPC_RA (insn));
5596 break;
5597
5598 case 28: /* AND Immediate */
5599 case 29: /* AND Immediate Shifted */
5600 record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum);
5601 /* FALL-THROUGH */
5602 case 24: /* OR Immediate */
5603 case 25: /* OR Immediate Shifted */
5604 case 26: /* XOR Immediate */
5605 case 27: /* XOR Immediate Shifted */
5606 record_full_arch_list_add_reg (regcache,
5607 tdep->ppc_gp0_regnum + PPC_RA (insn));
5608 break;
5609
5610 case 31:
5611 if (ppc_process_record_op31 (gdbarch, regcache, addr, insn) != 0)
5612 return -1;
5613 break;
5614
5615 case 33: /* Load Word and Zero with Update */
5616 case 35: /* Load Byte and Zero with Update */
5617 case 41: /* Load Halfword and Zero with Update */
5618 case 43: /* Load Halfword Algebraic with Update */
5619 record_full_arch_list_add_reg (regcache,
5620 tdep->ppc_gp0_regnum + PPC_RA (insn));
5621 /* FALL-THROUGH */
5622 case 32: /* Load Word and Zero */
5623 case 34: /* Load Byte and Zero */
5624 case 40: /* Load Halfword and Zero */
5625 case 42: /* Load Halfword Algebraic */
5626 record_full_arch_list_add_reg (regcache,
5627 tdep->ppc_gp0_regnum + PPC_RT (insn));
5628 break;
5629
5630 case 46: /* Load Multiple Word */
5631 for (i = PPC_RT (insn); i < 32; i++)
5632 record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i);
5633 break;
5634
5635 case 56: /* Load Quadword */
5636 tmp = tdep->ppc_gp0_regnum + (PPC_RT (insn) & ~1);
5637 record_full_arch_list_add_reg (regcache, tmp);
5638 record_full_arch_list_add_reg (regcache, tmp + 1);
5639 break;
5640
5641 case 49: /* Load Floating-Point Single with Update */
5642 case 51: /* Load Floating-Point Double with Update */
5643 record_full_arch_list_add_reg (regcache,
5644 tdep->ppc_gp0_regnum + PPC_RA (insn));
5645 /* FALL-THROUGH */
5646 case 48: /* Load Floating-Point Single */
5647 case 50: /* Load Floating-Point Double */
5648 record_full_arch_list_add_reg (regcache,
5649 tdep->ppc_fp0_regnum + PPC_FRT (insn));
5650 break;
5651
5652 case 47: /* Store Multiple Word */
5653 {
b926417a 5654 ULONGEST iaddr = 0;
b4cdae6f
WW
5655
5656 if (PPC_RA (insn) != 0)
5657 regcache_raw_read_unsigned (regcache,
5658 tdep->ppc_gp0_regnum + PPC_RA (insn),
b926417a 5659 &iaddr);
b4cdae6f 5660
b926417a
TT
5661 iaddr += PPC_D (insn);
5662 record_full_arch_list_add_mem (iaddr, 4 * (32 - PPC_RS (insn)));
b4cdae6f
WW
5663 }
5664 break;
5665
5666 case 37: /* Store Word with Update */
5667 case 39: /* Store Byte with Update */
5668 case 45: /* Store Halfword with Update */
5669 case 53: /* Store Floating-Point Single with Update */
5670 case 55: /* Store Floating-Point Double with Update */
5671 record_full_arch_list_add_reg (regcache,
5672 tdep->ppc_gp0_regnum + PPC_RA (insn));
5673 /* FALL-THROUGH */
5674 case 36: /* Store Word */
5675 case 38: /* Store Byte */
5676 case 44: /* Store Halfword */
5677 case 52: /* Store Floating-Point Single */
5678 case 54: /* Store Floating-Point Double */
5679 {
b926417a 5680 ULONGEST iaddr = 0;
b4cdae6f
WW
5681 int size = -1;
5682
5683 if (PPC_RA (insn) != 0)
5684 regcache_raw_read_unsigned (regcache,
5685 tdep->ppc_gp0_regnum + PPC_RA (insn),
b926417a
TT
5686 &iaddr);
5687 iaddr += PPC_D (insn);
b4cdae6f
WW
5688
5689 if (op6 == 36 || op6 == 37 || op6 == 52 || op6 == 53)
5690 size = 4;
5691 else if (op6 == 54 || op6 == 55)
5692 size = 8;
5693 else if (op6 == 44 || op6 == 45)
5694 size = 2;
5695 else if (op6 == 38 || op6 == 39)
5696 size = 1;
5697 else
5698 gdb_assert (0);
5699
b926417a 5700 record_full_arch_list_add_mem (iaddr, size);
b4cdae6f
WW
5701 }
5702 break;
5703
6ec2b213
EBM
5704 case 57:
5705 switch (insn & 0x3)
5706 {
5707 case 0: /* Load Floating-Point Double Pair */
5708 tmp = tdep->ppc_fp0_regnum + (PPC_RT (insn) & ~1);
5709 record_full_arch_list_add_reg (regcache, tmp);
5710 record_full_arch_list_add_reg (regcache, tmp + 1);
5711 break;
5712 case 2: /* Load VSX Scalar Doubleword */
5713 case 3: /* Load VSX Scalar Single */
5714 ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32);
5715 break;
5716 default:
5717 goto UNKNOWN_OP;
5718 }
b4cdae6f
WW
5719 break;
5720
5721 case 58: /* Load Doubleword */
5722 /* Load Doubleword with Update */
5723 /* Load Word Algebraic */
5724 if (PPC_FIELD (insn, 30, 2) > 2)
5725 goto UNKNOWN_OP;
5726
5727 record_full_arch_list_add_reg (regcache,
5728 tdep->ppc_gp0_regnum + PPC_RT (insn));
5729 if (PPC_BIT (insn, 31))
5730 record_full_arch_list_add_reg (regcache,
5731 tdep->ppc_gp0_regnum + PPC_RA (insn));
5732 break;
5733
5734 case 59:
5735 if (ppc_process_record_op59 (gdbarch, regcache, addr, insn) != 0)
5736 return -1;
5737 break;
5738
5739 case 60:
5740 if (ppc_process_record_op60 (gdbarch, regcache, addr, insn) != 0)
5741 return -1;
5742 break;
5743
6ec2b213
EBM
5744 case 61:
5745 if (ppc_process_record_op61 (gdbarch, regcache, addr, insn) != 0)
5746 return -1;
5747 break;
5748
b4cdae6f
WW
5749 case 62: /* Store Doubleword */
5750 /* Store Doubleword with Update */
5751 /* Store Quadword with Update */
5752 {
b926417a 5753 ULONGEST iaddr = 0;
b4cdae6f
WW
5754 int size;
5755 int sub2 = PPC_FIELD (insn, 30, 2);
5756
6ec2b213 5757 if (sub2 > 2)
b4cdae6f
WW
5758 goto UNKNOWN_OP;
5759
5760 if (PPC_RA (insn) != 0)
5761 regcache_raw_read_unsigned (regcache,
5762 tdep->ppc_gp0_regnum + PPC_RA (insn),
b926417a 5763 &iaddr);
b4cdae6f 5764
6ec2b213 5765 size = (sub2 == 2) ? 16 : 8;
b4cdae6f 5766
b926417a
TT
5767 iaddr += PPC_DS (insn) << 2;
5768 record_full_arch_list_add_mem (iaddr, size);
b4cdae6f
WW
5769
5770 if (op6 == 62 && sub2 == 1)
5771 record_full_arch_list_add_reg (regcache,
5772 tdep->ppc_gp0_regnum +
5773 PPC_RA (insn));
5774
5775 break;
5776 }
5777
5778 case 63:
5779 if (ppc_process_record_op63 (gdbarch, regcache, addr, insn) != 0)
5780 return -1;
5781 break;
5782
5783 default:
5784UNKNOWN_OP:
810c1026
WW
5785 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %08x "
5786 "at %s, %d.\n", insn, paddress (gdbarch, addr), op6);
b4cdae6f
WW
5787 return -1;
5788 }
5789
5790 if (record_full_arch_list_add_reg (regcache, PPC_PC_REGNUM))
5791 return -1;
5792 if (record_full_arch_list_add_end ())
5793 return -1;
5794 return 0;
5795}
5796
7a78ae4e
ND
5797/* Initialize the current architecture based on INFO. If possible, re-use an
5798 architecture from ARCHES, which is a list of architectures already created
5799 during this debugging session.
c906108c 5800
7a78ae4e 5801 Called e.g. at program startup, when reading a core file, and when reading
64366f1c 5802 a binary file. */
c906108c 5803
7a78ae4e
ND
5804static struct gdbarch *
5805rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
5806{
5807 struct gdbarch *gdbarch;
5808 struct gdbarch_tdep *tdep;
7cc46491 5809 int wordsize, from_xcoff_exec, from_elf_exec;
7a78ae4e
ND
5810 enum bfd_architecture arch;
5811 unsigned long mach;
5812 bfd abfd;
55eddb0f
DJ
5813 enum auto_boolean soft_float_flag = powerpc_soft_float_global;
5814 int soft_float;
ed0f4273 5815 enum powerpc_long_double_abi long_double_abi = POWERPC_LONG_DOUBLE_AUTO;
55eddb0f 5816 enum powerpc_vector_abi vector_abi = powerpc_vector_abi_global;
cd453cd0 5817 enum powerpc_elf_abi elf_abi = POWERPC_ELF_AUTO;
93b4691f 5818 int have_fpu = 0, have_spe = 0, have_mq = 0, have_altivec = 0;
7ca18ed6 5819 int have_dfp = 0, have_vsx = 0, have_ppr = 0, have_dscr = 0;
f2cf6173 5820 int have_tar = 0;
7cc46491
DJ
5821 int tdesc_wordsize = -1;
5822 const struct target_desc *tdesc = info.target_desc;
5823 struct tdesc_arch_data *tdesc_data = NULL;
f949c649 5824 int num_pseudoregs = 0;
604c2f83 5825 int cur_reg;
7a78ae4e 5826
f4d9bade
UW
5827 /* INFO may refer to a binary that is not of the PowerPC architecture,
5828 e.g. when debugging a stand-alone SPE executable on a Cell/B.E. system.
5829 In this case, we must not attempt to infer properties of the (PowerPC
5830 side) of the target system from properties of that executable. Trust
5831 the target description instead. */
5832 if (info.abfd
5833 && bfd_get_arch (info.abfd) != bfd_arch_powerpc
5834 && bfd_get_arch (info.abfd) != bfd_arch_rs6000)
5835 info.abfd = NULL;
5836
9aa1e687 5837 from_xcoff_exec = info.abfd && info.abfd->format == bfd_object &&
7a78ae4e
ND
5838 bfd_get_flavour (info.abfd) == bfd_target_xcoff_flavour;
5839
9aa1e687
KB
5840 from_elf_exec = info.abfd && info.abfd->format == bfd_object &&
5841 bfd_get_flavour (info.abfd) == bfd_target_elf_flavour;
5842
e712c1cf 5843 /* Check word size. If INFO is from a binary file, infer it from
64366f1c 5844 that, else choose a likely default. */
9aa1e687 5845 if (from_xcoff_exec)
c906108c 5846 {
11ed25ac 5847 if (bfd_xcoff_is_xcoff64 (info.abfd))
7a78ae4e
ND
5848 wordsize = 8;
5849 else
5850 wordsize = 4;
c906108c 5851 }
9aa1e687
KB
5852 else if (from_elf_exec)
5853 {
5854 if (elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5855 wordsize = 8;
5856 else
5857 wordsize = 4;
5858 }
7cc46491
DJ
5859 else if (tdesc_has_registers (tdesc))
5860 wordsize = -1;
c906108c 5861 else
7a78ae4e 5862 {
27b15785 5863 if (info.bfd_arch_info != NULL && info.bfd_arch_info->bits_per_word != 0)
16d8013c
JB
5864 wordsize = (info.bfd_arch_info->bits_per_word
5865 / info.bfd_arch_info->bits_per_byte);
27b15785
KB
5866 else
5867 wordsize = 4;
7a78ae4e 5868 }
c906108c 5869
475bbd17
JB
5870 /* Get the architecture and machine from the BFD. */
5871 arch = info.bfd_arch_info->arch;
5872 mach = info.bfd_arch_info->mach;
5bf1c677
EZ
5873
5874 /* For e500 executables, the apuinfo section is of help here. Such
5875 section contains the identifier and revision number of each
5876 Application-specific Processing Unit that is present on the
5877 chip. The content of the section is determined by the assembler
5878 which looks at each instruction and determines which unit (and
74af9197
NF
5879 which version of it) can execute it. Grovel through the section
5880 looking for relevant e500 APUs. */
5bf1c677 5881
74af9197 5882 if (bfd_uses_spe_extensions (info.abfd))
5bf1c677 5883 {
74af9197
NF
5884 arch = info.bfd_arch_info->arch;
5885 mach = bfd_mach_ppc_e500;
5886 bfd_default_set_arch_mach (&abfd, arch, mach);
5887 info.bfd_arch_info = bfd_get_arch_info (&abfd);
5bf1c677
EZ
5888 }
5889
7cc46491
DJ
5890 /* Find a default target description which describes our register
5891 layout, if we do not already have one. */
5892 if (! tdesc_has_registers (tdesc))
5893 {
5894 const struct variant *v;
5895
5896 /* Choose variant. */
5897 v = find_variant_by_arch (arch, mach);
5898 if (!v)
5899 return NULL;
5900
5901 tdesc = *v->tdesc;
5902 }
5903
5904 gdb_assert (tdesc_has_registers (tdesc));
5905
5906 /* Check any target description for validity. */
5907 if (tdesc_has_registers (tdesc))
5908 {
5909 static const char *const gprs[] = {
5910 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
5911 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
5912 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
5913 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
5914 };
7cc46491
DJ
5915 const struct tdesc_feature *feature;
5916 int i, valid_p;
5917 static const char *const msr_names[] = { "msr", "ps" };
5918 static const char *const cr_names[] = { "cr", "cnd" };
5919 static const char *const ctr_names[] = { "ctr", "cnt" };
5920
5921 feature = tdesc_find_feature (tdesc,
5922 "org.gnu.gdb.power.core");
5923 if (feature == NULL)
5924 return NULL;
5925
5926 tdesc_data = tdesc_data_alloc ();
5927
5928 valid_p = 1;
5929 for (i = 0; i < ppc_num_gprs; i++)
5930 valid_p &= tdesc_numbered_register (feature, tdesc_data, i, gprs[i]);
5931 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_PC_REGNUM,
5932 "pc");
5933 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_LR_REGNUM,
5934 "lr");
5935 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_XER_REGNUM,
5936 "xer");
5937
5938 /* Allow alternate names for these registers, to accomodate GDB's
5939 historic naming. */
5940 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5941 PPC_MSR_REGNUM, msr_names);
5942 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5943 PPC_CR_REGNUM, cr_names);
5944 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
5945 PPC_CTR_REGNUM, ctr_names);
5946
5947 if (!valid_p)
5948 {
5949 tdesc_data_cleanup (tdesc_data);
5950 return NULL;
5951 }
5952
5953 have_mq = tdesc_numbered_register (feature, tdesc_data, PPC_MQ_REGNUM,
5954 "mq");
5955
12863263 5956 tdesc_wordsize = tdesc_register_bitsize (feature, "pc") / 8;
7cc46491
DJ
5957 if (wordsize == -1)
5958 wordsize = tdesc_wordsize;
5959
5960 feature = tdesc_find_feature (tdesc,
5961 "org.gnu.gdb.power.fpu");
5962 if (feature != NULL)
5963 {
5964 static const char *const fprs[] = {
5965 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
5966 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
5967 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
5968 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
5969 };
5970 valid_p = 1;
5971 for (i = 0; i < ppc_num_fprs; i++)
5972 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5973 PPC_F0_REGNUM + i, fprs[i]);
5974 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5975 PPC_FPSCR_REGNUM, "fpscr");
5976
5977 if (!valid_p)
5978 {
5979 tdesc_data_cleanup (tdesc_data);
5980 return NULL;
5981 }
5982 have_fpu = 1;
0fb2aaa1
PFC
5983
5984 /* The fpscr register was expanded in isa 2.05 to 64 bits
5985 along with the addition of the decimal floating point
5986 facility. */
12863263 5987 if (tdesc_register_bitsize (feature, "fpscr") > 32)
0fb2aaa1 5988 have_dfp = 1;
7cc46491
DJ
5989 }
5990 else
5991 have_fpu = 0;
5992
5993 feature = tdesc_find_feature (tdesc,
5994 "org.gnu.gdb.power.altivec");
5995 if (feature != NULL)
5996 {
5997 static const char *const vector_regs[] = {
5998 "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7",
5999 "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15",
6000 "vr16", "vr17", "vr18", "vr19", "vr20", "vr21", "vr22", "vr23",
6001 "vr24", "vr25", "vr26", "vr27", "vr28", "vr29", "vr30", "vr31"
6002 };
6003
6004 valid_p = 1;
6005 for (i = 0; i < ppc_num_gprs; i++)
6006 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6007 PPC_VR0_REGNUM + i,
6008 vector_regs[i]);
6009 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6010 PPC_VSCR_REGNUM, "vscr");
6011 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6012 PPC_VRSAVE_REGNUM, "vrsave");
6013
6014 if (have_spe || !valid_p)
6015 {
6016 tdesc_data_cleanup (tdesc_data);
6017 return NULL;
6018 }
6019 have_altivec = 1;
6020 }
6021 else
6022 have_altivec = 0;
6023
604c2f83
LM
6024 /* Check for POWER7 VSX registers support. */
6025 feature = tdesc_find_feature (tdesc,
6026 "org.gnu.gdb.power.vsx");
6027
6028 if (feature != NULL)
6029 {
6030 static const char *const vsx_regs[] = {
6031 "vs0h", "vs1h", "vs2h", "vs3h", "vs4h", "vs5h",
6032 "vs6h", "vs7h", "vs8h", "vs9h", "vs10h", "vs11h",
6033 "vs12h", "vs13h", "vs14h", "vs15h", "vs16h", "vs17h",
6034 "vs18h", "vs19h", "vs20h", "vs21h", "vs22h", "vs23h",
6035 "vs24h", "vs25h", "vs26h", "vs27h", "vs28h", "vs29h",
6036 "vs30h", "vs31h"
6037 };
6038
6039 valid_p = 1;
6040
6041 for (i = 0; i < ppc_num_vshrs; i++)
6042 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6043 PPC_VSR0_UPPER_REGNUM + i,
6044 vsx_regs[i]);
6045 if (!valid_p)
6046 {
6047 tdesc_data_cleanup (tdesc_data);
6048 return NULL;
6049 }
6050
6051 have_vsx = 1;
6052 }
6053 else
6054 have_vsx = 0;
6055
7cc46491
DJ
6056 /* On machines supporting the SPE APU, the general-purpose registers
6057 are 64 bits long. There are SIMD vector instructions to treat them
6058 as pairs of floats, but the rest of the instruction set treats them
6059 as 32-bit registers, and only operates on their lower halves.
6060
6061 In the GDB regcache, we treat their high and low halves as separate
6062 registers. The low halves we present as the general-purpose
6063 registers, and then we have pseudo-registers that stitch together
6064 the upper and lower halves and present them as pseudo-registers.
6065
6066 Thus, the target description is expected to supply the upper
6067 halves separately. */
6068
6069 feature = tdesc_find_feature (tdesc,
6070 "org.gnu.gdb.power.spe");
6071 if (feature != NULL)
6072 {
6073 static const char *const upper_spe[] = {
6074 "ev0h", "ev1h", "ev2h", "ev3h",
6075 "ev4h", "ev5h", "ev6h", "ev7h",
6076 "ev8h", "ev9h", "ev10h", "ev11h",
6077 "ev12h", "ev13h", "ev14h", "ev15h",
6078 "ev16h", "ev17h", "ev18h", "ev19h",
6079 "ev20h", "ev21h", "ev22h", "ev23h",
6080 "ev24h", "ev25h", "ev26h", "ev27h",
6081 "ev28h", "ev29h", "ev30h", "ev31h"
6082 };
6083
6084 valid_p = 1;
6085 for (i = 0; i < ppc_num_gprs; i++)
6086 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6087 PPC_SPE_UPPER_GP0_REGNUM + i,
6088 upper_spe[i]);
6089 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6090 PPC_SPE_ACC_REGNUM, "acc");
6091 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6092 PPC_SPE_FSCR_REGNUM, "spefscr");
6093
6094 if (have_mq || have_fpu || !valid_p)
6095 {
6096 tdesc_data_cleanup (tdesc_data);
6097 return NULL;
6098 }
6099 have_spe = 1;
6100 }
6101 else
6102 have_spe = 0;
7ca18ed6
EBM
6103
6104 /* Program Priority Register. */
6105 feature = tdesc_find_feature (tdesc,
6106 "org.gnu.gdb.power.ppr");
6107 if (feature != NULL)
6108 {
6109 valid_p = 1;
6110 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6111 PPC_PPR_REGNUM, "ppr");
6112
6113 if (!valid_p)
6114 {
6115 tdesc_data_cleanup (tdesc_data);
6116 return NULL;
6117 }
6118 have_ppr = 1;
6119 }
6120 else
6121 have_ppr = 0;
6122
6123 /* Data Stream Control Register. */
6124 feature = tdesc_find_feature (tdesc,
6125 "org.gnu.gdb.power.dscr");
6126 if (feature != NULL)
6127 {
6128 valid_p = 1;
6129 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6130 PPC_DSCR_REGNUM, "dscr");
6131
6132 if (!valid_p)
6133 {
6134 tdesc_data_cleanup (tdesc_data);
6135 return NULL;
6136 }
6137 have_dscr = 1;
6138 }
6139 else
6140 have_dscr = 0;
f2cf6173
EBM
6141
6142 /* Target Address Register. */
6143 feature = tdesc_find_feature (tdesc,
6144 "org.gnu.gdb.power.tar");
6145 if (feature != NULL)
6146 {
6147 valid_p = 1;
6148 valid_p &= tdesc_numbered_register (feature, tdesc_data,
6149 PPC_TAR_REGNUM, "tar");
6150
6151 if (!valid_p)
6152 {
6153 tdesc_data_cleanup (tdesc_data);
6154 return NULL;
6155 }
6156 have_tar = 1;
6157 }
6158 else
6159 have_tar = 0;
7cc46491
DJ
6160 }
6161
6162 /* If we have a 64-bit binary on a 32-bit target, complain. Also
6163 complain for a 32-bit binary on a 64-bit target; we do not yet
6164 support that. For instance, the 32-bit ABI routines expect
6165 32-bit GPRs.
6166
6167 As long as there isn't an explicit target description, we'll
6168 choose one based on the BFD architecture and get a word size
6169 matching the binary (probably powerpc:common or
6170 powerpc:common64). So there is only trouble if a 64-bit target
6171 supplies a 64-bit description while debugging a 32-bit
6172 binary. */
6173 if (tdesc_wordsize != -1 && tdesc_wordsize != wordsize)
6174 {
6175 tdesc_data_cleanup (tdesc_data);
6176 return NULL;
6177 }
6178
55eddb0f 6179#ifdef HAVE_ELF
cd453cd0
UW
6180 if (from_elf_exec)
6181 {
6182 switch (elf_elfheader (info.abfd)->e_flags & EF_PPC64_ABI)
6183 {
6184 case 1:
6185 elf_abi = POWERPC_ELF_V1;
6186 break;
6187 case 2:
6188 elf_abi = POWERPC_ELF_V2;
6189 break;
6190 default:
6191 break;
6192 }
6193 }
6194
55eddb0f
DJ
6195 if (soft_float_flag == AUTO_BOOLEAN_AUTO && from_elf_exec)
6196 {
6197 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
ed0f4273 6198 Tag_GNU_Power_ABI_FP) & 3)
55eddb0f
DJ
6199 {
6200 case 1:
6201 soft_float_flag = AUTO_BOOLEAN_FALSE;
6202 break;
6203 case 2:
6204 soft_float_flag = AUTO_BOOLEAN_TRUE;
6205 break;
6206 default:
6207 break;
6208 }
6209 }
6210
ed0f4273
UW
6211 if (long_double_abi == POWERPC_LONG_DOUBLE_AUTO && from_elf_exec)
6212 {
6213 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
6214 Tag_GNU_Power_ABI_FP) >> 2)
6215 {
6216 case 1:
6217 long_double_abi = POWERPC_LONG_DOUBLE_IBM128;
6218 break;
6219 case 3:
6220 long_double_abi = POWERPC_LONG_DOUBLE_IEEE128;
6221 break;
6222 default:
6223 break;
6224 }
6225 }
6226
55eddb0f
DJ
6227 if (vector_abi == POWERPC_VEC_AUTO && from_elf_exec)
6228 {
6229 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
6230 Tag_GNU_Power_ABI_Vector))
6231 {
6232 case 1:
6233 vector_abi = POWERPC_VEC_GENERIC;
6234 break;
6235 case 2:
6236 vector_abi = POWERPC_VEC_ALTIVEC;
6237 break;
6238 case 3:
6239 vector_abi = POWERPC_VEC_SPE;
6240 break;
6241 default:
6242 break;
6243 }
6244 }
6245#endif
6246
cd453cd0
UW
6247 /* At this point, the only supported ELF-based 64-bit little-endian
6248 operating system is GNU/Linux, and this uses the ELFv2 ABI by
6249 default. All other supported ELF-based operating systems use the
6250 ELFv1 ABI by default. Therefore, if the ABI marker is missing,
6251 e.g. because we run a legacy binary, or have attached to a process
6252 and have not found any associated binary file, set the default
6253 according to this heuristic. */
6254 if (elf_abi == POWERPC_ELF_AUTO)
6255 {
6256 if (wordsize == 8 && info.byte_order == BFD_ENDIAN_LITTLE)
6257 elf_abi = POWERPC_ELF_V2;
6258 else
6259 elf_abi = POWERPC_ELF_V1;
6260 }
6261
55eddb0f
DJ
6262 if (soft_float_flag == AUTO_BOOLEAN_TRUE)
6263 soft_float = 1;
6264 else if (soft_float_flag == AUTO_BOOLEAN_FALSE)
6265 soft_float = 0;
6266 else
6267 soft_float = !have_fpu;
6268
6269 /* If we have a hard float binary or setting but no floating point
6270 registers, downgrade to soft float anyway. We're still somewhat
6271 useful in this scenario. */
6272 if (!soft_float && !have_fpu)
6273 soft_float = 1;
6274
6275 /* Similarly for vector registers. */
6276 if (vector_abi == POWERPC_VEC_ALTIVEC && !have_altivec)
6277 vector_abi = POWERPC_VEC_GENERIC;
6278
6279 if (vector_abi == POWERPC_VEC_SPE && !have_spe)
6280 vector_abi = POWERPC_VEC_GENERIC;
6281
6282 if (vector_abi == POWERPC_VEC_AUTO)
6283 {
6284 if (have_altivec)
6285 vector_abi = POWERPC_VEC_ALTIVEC;
6286 else if (have_spe)
6287 vector_abi = POWERPC_VEC_SPE;
6288 else
6289 vector_abi = POWERPC_VEC_GENERIC;
6290 }
6291
6292 /* Do not limit the vector ABI based on available hardware, since we
6293 do not yet know what hardware we'll decide we have. Yuck! FIXME! */
6294
7cc46491
DJ
6295 /* Find a candidate among extant architectures. */
6296 for (arches = gdbarch_list_lookup_by_info (arches, &info);
6297 arches != NULL;
6298 arches = gdbarch_list_lookup_by_info (arches->next, &info))
6299 {
6300 /* Word size in the various PowerPC bfd_arch_info structs isn't
6301 meaningful, because 64-bit CPUs can run in 32-bit mode. So, perform
6302 separate word size check. */
6303 tdep = gdbarch_tdep (arches->gdbarch);
cd453cd0
UW
6304 if (tdep && tdep->elf_abi != elf_abi)
6305 continue;
55eddb0f
DJ
6306 if (tdep && tdep->soft_float != soft_float)
6307 continue;
ed0f4273
UW
6308 if (tdep && tdep->long_double_abi != long_double_abi)
6309 continue;
55eddb0f
DJ
6310 if (tdep && tdep->vector_abi != vector_abi)
6311 continue;
7cc46491
DJ
6312 if (tdep && tdep->wordsize == wordsize)
6313 {
6314 if (tdesc_data != NULL)
6315 tdesc_data_cleanup (tdesc_data);
6316 return arches->gdbarch;
6317 }
6318 }
6319
6320 /* None found, create a new architecture from INFO, whose bfd_arch_info
6321 validity depends on the source:
6322 - executable useless
6323 - rs6000_host_arch() good
6324 - core file good
6325 - "set arch" trust blindly
6326 - GDB startup useless but harmless */
6327
fc270c35 6328 tdep = XCNEW (struct gdbarch_tdep);
7cc46491 6329 tdep->wordsize = wordsize;
cd453cd0 6330 tdep->elf_abi = elf_abi;
55eddb0f 6331 tdep->soft_float = soft_float;
ed0f4273 6332 tdep->long_double_abi = long_double_abi;
55eddb0f 6333 tdep->vector_abi = vector_abi;
7cc46491 6334
7a78ae4e 6335 gdbarch = gdbarch_alloc (&info, tdep);
7a78ae4e 6336
7cc46491
DJ
6337 tdep->ppc_gp0_regnum = PPC_R0_REGNUM;
6338 tdep->ppc_toc_regnum = PPC_R0_REGNUM + 2;
6339 tdep->ppc_ps_regnum = PPC_MSR_REGNUM;
6340 tdep->ppc_cr_regnum = PPC_CR_REGNUM;
6341 tdep->ppc_lr_regnum = PPC_LR_REGNUM;
6342 tdep->ppc_ctr_regnum = PPC_CTR_REGNUM;
6343 tdep->ppc_xer_regnum = PPC_XER_REGNUM;
6344 tdep->ppc_mq_regnum = have_mq ? PPC_MQ_REGNUM : -1;
6345
6346 tdep->ppc_fp0_regnum = have_fpu ? PPC_F0_REGNUM : -1;
6347 tdep->ppc_fpscr_regnum = have_fpu ? PPC_FPSCR_REGNUM : -1;
604c2f83 6348 tdep->ppc_vsr0_upper_regnum = have_vsx ? PPC_VSR0_UPPER_REGNUM : -1;
7cc46491
DJ
6349 tdep->ppc_vr0_regnum = have_altivec ? PPC_VR0_REGNUM : -1;
6350 tdep->ppc_vrsave_regnum = have_altivec ? PPC_VRSAVE_REGNUM : -1;
6351 tdep->ppc_ev0_upper_regnum = have_spe ? PPC_SPE_UPPER_GP0_REGNUM : -1;
6352 tdep->ppc_acc_regnum = have_spe ? PPC_SPE_ACC_REGNUM : -1;
6353 tdep->ppc_spefscr_regnum = have_spe ? PPC_SPE_FSCR_REGNUM : -1;
7ca18ed6
EBM
6354 tdep->ppc_ppr_regnum = have_ppr ? PPC_PPR_REGNUM : -1;
6355 tdep->ppc_dscr_regnum = have_dscr ? PPC_DSCR_REGNUM : -1;
f2cf6173 6356 tdep->ppc_tar_regnum = have_tar ? PPC_TAR_REGNUM : -1;
7cc46491
DJ
6357
6358 set_gdbarch_pc_regnum (gdbarch, PPC_PC_REGNUM);
6359 set_gdbarch_sp_regnum (gdbarch, PPC_R0_REGNUM + 1);
7cc46491 6360 set_gdbarch_fp0_regnum (gdbarch, tdep->ppc_fp0_regnum);
9f643768 6361 set_gdbarch_register_sim_regno (gdbarch, rs6000_register_sim_regno);
7cc46491
DJ
6362
6363 /* The XML specification for PowerPC sensibly calls the MSR "msr".
6364 GDB traditionally called it "ps", though, so let GDB add an
6365 alias. */
6366 set_gdbarch_ps_regnum (gdbarch, tdep->ppc_ps_regnum);
6367
4a7622d1 6368 if (wordsize == 8)
05580c65 6369 set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value);
afd48b75 6370 else
4a7622d1 6371 set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value);
c8001721 6372
baffbae0
JB
6373 /* Set lr_frame_offset. */
6374 if (wordsize == 8)
6375 tdep->lr_frame_offset = 16;
baffbae0 6376 else
4a7622d1 6377 tdep->lr_frame_offset = 4;
baffbae0 6378
604c2f83 6379 if (have_spe || have_dfp || have_vsx)
7cc46491 6380 {
f949c649 6381 set_gdbarch_pseudo_register_read (gdbarch, rs6000_pseudo_register_read);
0df8b418
MS
6382 set_gdbarch_pseudo_register_write (gdbarch,
6383 rs6000_pseudo_register_write);
2a2fa07b
MK
6384 set_gdbarch_ax_pseudo_register_collect (gdbarch,
6385 rs6000_ax_pseudo_register_collect);
7cc46491 6386 }
1fcc0bb8 6387
a67914de
MK
6388 set_gdbarch_gen_return_address (gdbarch, rs6000_gen_return_address);
6389
e0d24f8d
WZ
6390 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
6391
5a9e69ba 6392 set_gdbarch_num_regs (gdbarch, PPC_NUM_REGS);
f949c649
TJB
6393
6394 if (have_spe)
6395 num_pseudoregs += 32;
6396 if (have_dfp)
6397 num_pseudoregs += 16;
604c2f83
LM
6398 if (have_vsx)
6399 /* Include both VSX and Extended FP registers. */
6400 num_pseudoregs += 96;
f949c649
TJB
6401
6402 set_gdbarch_num_pseudo_regs (gdbarch, num_pseudoregs);
7a78ae4e
ND
6403
6404 set_gdbarch_ptr_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
6405 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
6406 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
6407 set_gdbarch_long_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
6408 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
6409 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
6410 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
4a7622d1 6411 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
4e409299 6412 set_gdbarch_char_signed (gdbarch, 0);
7a78ae4e 6413
11269d7e 6414 set_gdbarch_frame_align (gdbarch, rs6000_frame_align);
4a7622d1 6415 if (wordsize == 8)
8b148df9
AC
6416 /* PPC64 SYSV. */
6417 set_gdbarch_frame_red_zone_size (gdbarch, 288);
7a78ae4e 6418
691d145a
JB
6419 set_gdbarch_convert_register_p (gdbarch, rs6000_convert_register_p);
6420 set_gdbarch_register_to_value (gdbarch, rs6000_register_to_value);
6421 set_gdbarch_value_to_register (gdbarch, rs6000_value_to_register);
6422
18ed0c4e
JB
6423 set_gdbarch_stab_reg_to_regnum (gdbarch, rs6000_stab_reg_to_regnum);
6424 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rs6000_dwarf2_reg_to_regnum);
d217aaed 6425
4a7622d1 6426 if (wordsize == 4)
77b2b6d4 6427 set_gdbarch_push_dummy_call (gdbarch, ppc_sysv_abi_push_dummy_call);
4a7622d1 6428 else if (wordsize == 8)
8be9034a 6429 set_gdbarch_push_dummy_call (gdbarch, ppc64_sysv_abi_push_dummy_call);
7a78ae4e 6430
7a78ae4e 6431 set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue);
c9cf6e20 6432 set_gdbarch_stack_frame_destroyed_p (gdbarch, rs6000_stack_frame_destroyed_p);
8ab3d180 6433 set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue);
0d1243d9 6434
7a78ae4e 6435 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
04180708
YQ
6436
6437 set_gdbarch_breakpoint_kind_from_pc (gdbarch,
6438 rs6000_breakpoint::kind_from_pc);
6439 set_gdbarch_sw_breakpoint_from_kind (gdbarch,
6440 rs6000_breakpoint::bp_from_kind);
7a78ae4e 6441
203c3895 6442 /* The value of symbols of type N_SO and N_FUN maybe null when
0df8b418 6443 it shouldn't be. */
203c3895
UW
6444 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
6445
ce5eab59 6446 /* Handles single stepping of atomic sequences. */
4a7622d1 6447 set_gdbarch_software_single_step (gdbarch, ppc_deal_with_atomic_sequence);
ce5eab59 6448
0df8b418 6449 /* Not sure on this. FIXMEmgo */
7a78ae4e
ND
6450 set_gdbarch_frame_args_skip (gdbarch, 8);
6451
143985b7
AF
6452 /* Helpers for function argument information. */
6453 set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument);
6454
6f7f3f0d
UW
6455 /* Trampoline. */
6456 set_gdbarch_in_solib_return_trampoline
6457 (gdbarch, rs6000_in_solib_return_trampoline);
6458 set_gdbarch_skip_trampoline_code (gdbarch, rs6000_skip_trampoline_code);
6459
4fc771b8 6460 /* Hook in the DWARF CFI frame unwinder. */
1af5d7ce 6461 dwarf2_append_unwinders (gdbarch);
4fc771b8
DJ
6462 dwarf2_frame_set_adjust_regnum (gdbarch, rs6000_adjust_frame_regnum);
6463
9274a07c
LM
6464 /* Frame handling. */
6465 dwarf2_frame_set_init_reg (gdbarch, ppc_dwarf2_frame_init_reg);
6466
2454a024
UW
6467 /* Setup displaced stepping. */
6468 set_gdbarch_displaced_step_copy_insn (gdbarch,
7f03bd92 6469 ppc_displaced_step_copy_insn);
99e40580
UW
6470 set_gdbarch_displaced_step_hw_singlestep (gdbarch,
6471 ppc_displaced_step_hw_singlestep);
2454a024 6472 set_gdbarch_displaced_step_fixup (gdbarch, ppc_displaced_step_fixup);
2454a024
UW
6473 set_gdbarch_displaced_step_location (gdbarch,
6474 displaced_step_at_entry_point);
6475
6476 set_gdbarch_max_insn_length (gdbarch, PPC_INSN_SIZE);
6477
7b112f9c 6478 /* Hook in ABI-specific overrides, if they have been registered. */
8a4c2d24 6479 info.target_desc = tdesc;
0dba2a6c 6480 info.tdesc_data = tdesc_data;
4be87837 6481 gdbarch_init_osabi (info, gdbarch);
7b112f9c 6482
61a65099
KB
6483 switch (info.osabi)
6484 {
f5aecab8 6485 case GDB_OSABI_LINUX:
1736a7bd 6486 case GDB_OSABI_NETBSD:
61a65099 6487 case GDB_OSABI_UNKNOWN:
61a65099 6488 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
2608dbf8 6489 frame_unwind_append_unwinder (gdbarch, &rs6000_epilogue_frame_unwind);
1af5d7ce
UW
6490 frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind);
6491 set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id);
61a65099
KB
6492 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
6493 break;
6494 default:
61a65099 6495 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
81332287
KB
6496
6497 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
2608dbf8 6498 frame_unwind_append_unwinder (gdbarch, &rs6000_epilogue_frame_unwind);
1af5d7ce
UW
6499 frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind);
6500 set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id);
81332287 6501 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
61a65099
KB
6502 }
6503
7cc46491 6504 set_tdesc_pseudo_register_type (gdbarch, rs6000_pseudo_register_type);
7cc46491
DJ
6505 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
6506
6507 /* Override the normal target description method to make the SPE upper
6508 halves anonymous. */
6509 set_gdbarch_register_name (gdbarch, rs6000_register_name);
6510
604c2f83
LM
6511 /* Choose register numbers for all supported pseudo-registers. */
6512 tdep->ppc_ev0_regnum = -1;
6513 tdep->ppc_dl0_regnum = -1;
6514 tdep->ppc_vsr0_regnum = -1;
6515 tdep->ppc_efpr0_regnum = -1;
9f643768 6516
604c2f83
LM
6517 cur_reg = gdbarch_num_regs (gdbarch);
6518
6519 if (have_spe)
6520 {
6521 tdep->ppc_ev0_regnum = cur_reg;
6522 cur_reg += 32;
6523 }
6524 if (have_dfp)
6525 {
6526 tdep->ppc_dl0_regnum = cur_reg;
6527 cur_reg += 16;
6528 }
6529 if (have_vsx)
6530 {
6531 tdep->ppc_vsr0_regnum = cur_reg;
6532 cur_reg += 64;
6533 tdep->ppc_efpr0_regnum = cur_reg;
6534 cur_reg += 32;
6535 }
f949c649 6536
f6efe3f8 6537 gdb_assert (gdbarch_num_cooked_regs (gdbarch) == cur_reg);
f949c649 6538
debb1f09
JB
6539 /* Register the ravenscar_arch_ops. */
6540 if (mach == bfd_mach_ppc_e500)
6541 register_e500_ravenscar_ops (gdbarch);
6542 else
6543 register_ppc_ravenscar_ops (gdbarch);
6544
65b48a81
PB
6545 set_gdbarch_disassembler_options (gdbarch, &powerpc_disassembler_options);
6546 set_gdbarch_valid_disassembler_options (gdbarch,
6547 disassembler_options_powerpc ());
6548
7a78ae4e 6549 return gdbarch;
c906108c
SS
6550}
6551
7b112f9c 6552static void
8b164abb 6553rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
7b112f9c 6554{
8b164abb 6555 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7b112f9c
JT
6556
6557 if (tdep == NULL)
6558 return;
6559
4be87837 6560 /* FIXME: Dump gdbarch_tdep. */
7b112f9c
JT
6561}
6562
55eddb0f
DJ
6563/* PowerPC-specific commands. */
6564
6565static void
981a3fb3 6566set_powerpc_command (const char *args, int from_tty)
55eddb0f
DJ
6567{
6568 printf_unfiltered (_("\
6569\"set powerpc\" must be followed by an appropriate subcommand.\n"));
6570 help_list (setpowerpccmdlist, "set powerpc ", all_commands, gdb_stdout);
6571}
6572
6573static void
981a3fb3 6574show_powerpc_command (const char *args, int from_tty)
55eddb0f
DJ
6575{
6576 cmd_show_list (showpowerpccmdlist, from_tty, "");
6577}
6578
6579static void
eb4c3f4a 6580powerpc_set_soft_float (const char *args, int from_tty,
55eddb0f
DJ
6581 struct cmd_list_element *c)
6582{
6583 struct gdbarch_info info;
6584
6585 /* Update the architecture. */
6586 gdbarch_info_init (&info);
6587 if (!gdbarch_update_p (info))
9b20d036 6588 internal_error (__FILE__, __LINE__, _("could not update architecture"));
55eddb0f
DJ
6589}
6590
6591static void
eb4c3f4a 6592powerpc_set_vector_abi (const char *args, int from_tty,
55eddb0f
DJ
6593 struct cmd_list_element *c)
6594{
6595 struct gdbarch_info info;
570dc176 6596 int vector_abi;
55eddb0f
DJ
6597
6598 for (vector_abi = POWERPC_VEC_AUTO;
6599 vector_abi != POWERPC_VEC_LAST;
6600 vector_abi++)
6601 if (strcmp (powerpc_vector_abi_string,
6602 powerpc_vector_strings[vector_abi]) == 0)
6603 {
aead7601 6604 powerpc_vector_abi_global = (enum powerpc_vector_abi) vector_abi;
55eddb0f
DJ
6605 break;
6606 }
6607
6608 if (vector_abi == POWERPC_VEC_LAST)
6609 internal_error (__FILE__, __LINE__, _("Invalid vector ABI accepted: %s."),
6610 powerpc_vector_abi_string);
6611
6612 /* Update the architecture. */
6613 gdbarch_info_init (&info);
6614 if (!gdbarch_update_p (info))
9b20d036 6615 internal_error (__FILE__, __LINE__, _("could not update architecture"));
55eddb0f
DJ
6616}
6617
e09342b5
TJB
6618/* Show the current setting of the exact watchpoints flag. */
6619
6620static void
6621show_powerpc_exact_watchpoints (struct ui_file *file, int from_tty,
6622 struct cmd_list_element *c,
6623 const char *value)
6624{
6625 fprintf_filtered (file, _("Use of exact watchpoints is %s.\n"), value);
6626}
6627
845d4708 6628/* Read a PPC instruction from memory. */
d78489bf
AT
6629
6630static unsigned int
845d4708 6631read_insn (struct frame_info *frame, CORE_ADDR pc)
d78489bf 6632{
845d4708
AM
6633 struct gdbarch *gdbarch = get_frame_arch (frame);
6634 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
6635
6636 return read_memory_unsigned_integer (pc, 4, byte_order);
d78489bf
AT
6637}
6638
6639/* Return non-zero if the instructions at PC match the series
6640 described in PATTERN, or zero otherwise. PATTERN is an array of
6641 'struct ppc_insn_pattern' objects, terminated by an entry whose
6642 mask is zero.
6643
7433498b 6644 When the match is successful, fill INSNS[i] with what PATTERN[i]
d78489bf 6645 matched. If PATTERN[i] is optional, and the instruction wasn't
7433498b
AM
6646 present, set INSNS[i] to 0 (which is not a valid PPC instruction).
6647 INSNS should have as many elements as PATTERN, minus the terminator.
6648 Note that, if PATTERN contains optional instructions which aren't
6649 present in memory, then INSNS will have holes, so INSNS[i] isn't
6650 necessarily the i'th instruction in memory. */
d78489bf
AT
6651
6652int
845d4708 6653ppc_insns_match_pattern (struct frame_info *frame, CORE_ADDR pc,
7433498b 6654 const struct ppc_insn_pattern *pattern,
845d4708 6655 unsigned int *insns)
d78489bf
AT
6656{
6657 int i;
845d4708 6658 unsigned int insn;
d78489bf 6659
845d4708 6660 for (i = 0, insn = 0; pattern[i].mask; i++)
d78489bf 6661 {
845d4708
AM
6662 if (insn == 0)
6663 insn = read_insn (frame, pc);
6664 insns[i] = 0;
6665 if ((insn & pattern[i].mask) == pattern[i].data)
6666 {
6667 insns[i] = insn;
6668 pc += 4;
6669 insn = 0;
6670 }
6671 else if (!pattern[i].optional)
d78489bf
AT
6672 return 0;
6673 }
6674
6675 return 1;
6676}
6677
6678/* Return the 'd' field of the d-form instruction INSN, properly
6679 sign-extended. */
6680
6681CORE_ADDR
6682ppc_insn_d_field (unsigned int insn)
6683{
6684 return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000);
6685}
6686
6687/* Return the 'ds' field of the ds-form instruction INSN, with the two
6688 zero bits concatenated at the right, and properly
6689 sign-extended. */
6690
6691CORE_ADDR
6692ppc_insn_ds_field (unsigned int insn)
6693{
6694 return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000);
6695}
6696
c906108c
SS
6697/* Initialization code. */
6698
6699void
fba45db2 6700_initialize_rs6000_tdep (void)
c906108c 6701{
7b112f9c
JT
6702 gdbarch_register (bfd_arch_rs6000, rs6000_gdbarch_init, rs6000_dump_tdep);
6703 gdbarch_register (bfd_arch_powerpc, rs6000_gdbarch_init, rs6000_dump_tdep);
7cc46491
DJ
6704
6705 /* Initialize the standard target descriptions. */
6706 initialize_tdesc_powerpc_32 ();
7284e1be 6707 initialize_tdesc_powerpc_altivec32 ();
604c2f83 6708 initialize_tdesc_powerpc_vsx32 ();
7cc46491
DJ
6709 initialize_tdesc_powerpc_403 ();
6710 initialize_tdesc_powerpc_403gc ();
4d09ffea 6711 initialize_tdesc_powerpc_405 ();
7cc46491
DJ
6712 initialize_tdesc_powerpc_505 ();
6713 initialize_tdesc_powerpc_601 ();
6714 initialize_tdesc_powerpc_602 ();
6715 initialize_tdesc_powerpc_603 ();
6716 initialize_tdesc_powerpc_604 ();
6717 initialize_tdesc_powerpc_64 ();
7284e1be 6718 initialize_tdesc_powerpc_altivec64 ();
604c2f83 6719 initialize_tdesc_powerpc_vsx64 ();
7cc46491
DJ
6720 initialize_tdesc_powerpc_7400 ();
6721 initialize_tdesc_powerpc_750 ();
6722 initialize_tdesc_powerpc_860 ();
6723 initialize_tdesc_powerpc_e500 ();
6724 initialize_tdesc_rs6000 ();
55eddb0f
DJ
6725
6726 /* Add root prefix command for all "set powerpc"/"show powerpc"
6727 commands. */
6728 add_prefix_cmd ("powerpc", no_class, set_powerpc_command,
6729 _("Various PowerPC-specific commands."),
6730 &setpowerpccmdlist, "set powerpc ", 0, &setlist);
6731
6732 add_prefix_cmd ("powerpc", no_class, show_powerpc_command,
6733 _("Various PowerPC-specific commands."),
6734 &showpowerpccmdlist, "show powerpc ", 0, &showlist);
6735
6736 /* Add a command to allow the user to force the ABI. */
6737 add_setshow_auto_boolean_cmd ("soft-float", class_support,
6738 &powerpc_soft_float_global,
6739 _("Set whether to use a soft-float ABI."),
6740 _("Show whether to use a soft-float ABI."),
6741 NULL,
6742 powerpc_set_soft_float, NULL,
6743 &setpowerpccmdlist, &showpowerpccmdlist);
6744
6745 add_setshow_enum_cmd ("vector-abi", class_support, powerpc_vector_strings,
6746 &powerpc_vector_abi_string,
6747 _("Set the vector ABI."),
6748 _("Show the vector ABI."),
6749 NULL, powerpc_set_vector_abi, NULL,
6750 &setpowerpccmdlist, &showpowerpccmdlist);
e09342b5
TJB
6751
6752 add_setshow_boolean_cmd ("exact-watchpoints", class_support,
6753 &target_exact_watchpoints,
6754 _("\
6755Set whether to use just one debug register for watchpoints on scalars."),
6756 _("\
6757Show whether to use just one debug register for watchpoints on scalars."),
6758 _("\
6759If true, GDB will use only one debug register when watching a variable of\n\
6760scalar type, thus assuming that the variable is accessed through the address\n\
6761of its first byte."),
6762 NULL, show_powerpc_exact_watchpoints,
6763 &setpowerpccmdlist, &showpowerpccmdlist);
c906108c 6764}
This page took 2.957379 seconds and 4 git commands to generate.