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