Reverse debugging for PowerPC.
[deliverable/binutils-gdb.git] / gdb / ppc-linux-tdep.c
1 /* Target-dependent code for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "inferior.h"
23 #include "symtab.h"
24 #include "target.h"
25 #include "gdbcore.h"
26 #include "gdbcmd.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "regcache.h"
30 #include "value.h"
31 #include "osabi.h"
32 #include "regset.h"
33 #include "solib-svr4.h"
34 #include "solib-spu.h"
35 #include "solib.h"
36 #include "solist.h"
37 #include "ppc-tdep.h"
38 #include "ppc64-tdep.h"
39 #include "ppc-linux-tdep.h"
40 #include "glibc-tdep.h"
41 #include "trad-frame.h"
42 #include "frame-unwind.h"
43 #include "tramp-frame.h"
44 #include "observer.h"
45 #include "auxv.h"
46 #include "elf/common.h"
47 #include "elf/ppc64.h"
48 #include "arch-utils.h"
49 #include "spu-tdep.h"
50 #include "xml-syscall.h"
51 #include "linux-tdep.h"
52 #include "linux-record.h"
53 #include "record-full.h"
54
55 #include "stap-probe.h"
56 #include "ax.h"
57 #include "ax-gdb.h"
58 #include "cli/cli-utils.h"
59 #include "parser-defs.h"
60 #include "user-regs.h"
61 #include <ctype.h>
62 #include "elf-bfd.h" /* for elfcore_write_* */
63
64 #include "features/rs6000/powerpc-32l.c"
65 #include "features/rs6000/powerpc-altivec32l.c"
66 #include "features/rs6000/powerpc-cell32l.c"
67 #include "features/rs6000/powerpc-vsx32l.c"
68 #include "features/rs6000/powerpc-isa205-32l.c"
69 #include "features/rs6000/powerpc-isa205-altivec32l.c"
70 #include "features/rs6000/powerpc-isa205-vsx32l.c"
71 #include "features/rs6000/powerpc-64l.c"
72 #include "features/rs6000/powerpc-altivec64l.c"
73 #include "features/rs6000/powerpc-cell64l.c"
74 #include "features/rs6000/powerpc-vsx64l.c"
75 #include "features/rs6000/powerpc-isa205-64l.c"
76 #include "features/rs6000/powerpc-isa205-altivec64l.c"
77 #include "features/rs6000/powerpc-isa205-vsx64l.c"
78 #include "features/rs6000/powerpc-e500l.c"
79
80 /* Shared library operations for PowerPC-Linux. */
81 static struct target_so_ops powerpc_so_ops;
82
83 /* The syscall's XML filename for PPC and PPC64. */
84 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
85 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
86
87 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
88 in much the same fashion as memory_remove_breakpoint in mem-break.c,
89 but is careful not to write back the previous contents if the code
90 in question has changed in between inserting the breakpoint and
91 removing it.
92
93 Here is the problem that we're trying to solve...
94
95 Once upon a time, before introducing this function to remove
96 breakpoints from the inferior, setting a breakpoint on a shared
97 library function prior to running the program would not work
98 properly. In order to understand the problem, it is first
99 necessary to understand a little bit about dynamic linking on
100 this platform.
101
102 A call to a shared library function is accomplished via a bl
103 (branch-and-link) instruction whose branch target is an entry
104 in the procedure linkage table (PLT). The PLT in the object
105 file is uninitialized. To gdb, prior to running the program, the
106 entries in the PLT are all zeros.
107
108 Once the program starts running, the shared libraries are loaded
109 and the procedure linkage table is initialized, but the entries in
110 the table are not (necessarily) resolved. Once a function is
111 actually called, the code in the PLT is hit and the function is
112 resolved. In order to better illustrate this, an example is in
113 order; the following example is from the gdb testsuite.
114
115 We start the program shmain.
116
117 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
118 [...]
119
120 We place two breakpoints, one on shr1 and the other on main.
121
122 (gdb) b shr1
123 Breakpoint 1 at 0x100409d4
124 (gdb) b main
125 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
126
127 Examine the instruction (and the immediatly following instruction)
128 upon which the breakpoint was placed. Note that the PLT entry
129 for shr1 contains zeros.
130
131 (gdb) x/2i 0x100409d4
132 0x100409d4 <shr1>: .long 0x0
133 0x100409d8 <shr1+4>: .long 0x0
134
135 Now run 'til main.
136
137 (gdb) r
138 Starting program: gdb.base/shmain
139 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
140
141 Breakpoint 2, main ()
142 at gdb.base/shmain.c:44
143 44 g = 1;
144
145 Examine the PLT again. Note that the loading of the shared
146 library has initialized the PLT to code which loads a constant
147 (which I think is an index into the GOT) into r11 and then
148 branchs a short distance to the code which actually does the
149 resolving.
150
151 (gdb) x/2i 0x100409d4
152 0x100409d4 <shr1>: li r11,4
153 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
154 (gdb) c
155 Continuing.
156
157 Breakpoint 1, shr1 (x=1)
158 at gdb.base/shr1.c:19
159 19 l = 1;
160
161 Now we've hit the breakpoint at shr1. (The breakpoint was
162 reset from the PLT entry to the actual shr1 function after the
163 shared library was loaded.) Note that the PLT entry has been
164 resolved to contain a branch that takes us directly to shr1.
165 (The real one, not the PLT entry.)
166
167 (gdb) x/2i 0x100409d4
168 0x100409d4 <shr1>: b 0xffaf76c <shr1>
169 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
170
171 The thing to note here is that the PLT entry for shr1 has been
172 changed twice.
173
174 Now the problem should be obvious. GDB places a breakpoint (a
175 trap instruction) on the zero value of the PLT entry for shr1.
176 Later on, after the shared library had been loaded and the PLT
177 initialized, GDB gets a signal indicating this fact and attempts
178 (as it always does when it stops) to remove all the breakpoints.
179
180 The breakpoint removal was causing the former contents (a zero
181 word) to be written back to the now initialized PLT entry thus
182 destroying a portion of the initialization that had occurred only a
183 short time ago. When execution continued, the zero word would be
184 executed as an instruction an illegal instruction trap was
185 generated instead. (0 is not a legal instruction.)
186
187 The fix for this problem was fairly straightforward. The function
188 memory_remove_breakpoint from mem-break.c was copied to this file,
189 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
190 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
191 function.
192
193 The differences between ppc_linux_memory_remove_breakpoint () and
194 memory_remove_breakpoint () are minor. All that the former does
195 that the latter does not is check to make sure that the breakpoint
196 location actually contains a breakpoint (trap instruction) prior
197 to attempting to write back the old contents. If it does contain
198 a trap instruction, we allow the old contents to be written back.
199 Otherwise, we silently do nothing.
200
201 The big question is whether memory_remove_breakpoint () should be
202 changed to have the same functionality. The downside is that more
203 traffic is generated for remote targets since we'll have an extra
204 fetch of a memory word each time a breakpoint is removed.
205
206 For the time being, we'll leave this self-modifying-code-friendly
207 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
208 else in the event that some other platform has similar needs with
209 regard to removing breakpoints in some potentially self modifying
210 code. */
211 static int
212 ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
213 struct bp_target_info *bp_tgt)
214 {
215 CORE_ADDR addr = bp_tgt->reqstd_address;
216 const unsigned char *bp;
217 int val;
218 int bplen;
219 gdb_byte old_contents[BREAKPOINT_MAX];
220 struct cleanup *cleanup;
221
222 /* Determine appropriate breakpoint contents and size for this address. */
223 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
224 if (bp == NULL)
225 error (_("Software breakpoints not implemented for this target."));
226
227 /* Make sure we see the memory breakpoints. */
228 cleanup = make_show_memory_breakpoints_cleanup (1);
229 val = target_read_memory (addr, old_contents, bplen);
230
231 /* If our breakpoint is no longer at the address, this means that the
232 program modified the code on us, so it is wrong to put back the
233 old value. */
234 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
235 val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
236
237 do_cleanups (cleanup);
238 return val;
239 }
240
241 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
242 than the 32 bit SYSV R4 ABI structure return convention - all
243 structures, no matter their size, are put in memory. Vectors,
244 which were added later, do get returned in a register though. */
245
246 static enum return_value_convention
247 ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
248 struct type *valtype, struct regcache *regcache,
249 gdb_byte *readbuf, const gdb_byte *writebuf)
250 {
251 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
252 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
253 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
254 && TYPE_VECTOR (valtype)))
255 return RETURN_VALUE_STRUCT_CONVENTION;
256 else
257 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
258 readbuf, writebuf);
259 }
260
261 /* PLT stub in executable. */
262 static struct ppc_insn_pattern powerpc32_plt_stub[] =
263 {
264 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
265 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
266 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
267 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
268 { 0, 0, 0 }
269 };
270
271 /* PLT stub in shared library. */
272 static struct ppc_insn_pattern powerpc32_plt_stub_so[] =
273 {
274 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
275 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
276 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
277 { 0xffffffff, 0x60000000, 0 }, /* nop */
278 { 0, 0, 0 }
279 };
280 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub)
281
282 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
283 section. For secure PLT, stub is in .text and we need to check
284 instruction patterns. */
285
286 static int
287 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
288 {
289 struct bound_minimal_symbol sym;
290
291 /* Check whether PC is in the dynamic linker. This also checks
292 whether it is in the .plt section, used by non-PIC executables. */
293 if (svr4_in_dynsym_resolve_code (pc))
294 return 1;
295
296 /* Check if we are in the resolver. */
297 sym = lookup_minimal_symbol_by_pc (pc);
298 if (sym.minsym != NULL
299 && (strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0
300 || strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym),
301 "__glink_PLTresolve") == 0))
302 return 1;
303
304 return 0;
305 }
306
307 /* Follow PLT stub to actual routine. */
308
309 static CORE_ADDR
310 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
311 {
312 unsigned int insnbuf[POWERPC32_PLT_STUB_LEN];
313 struct gdbarch *gdbarch = get_frame_arch (frame);
314 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
315 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
316 CORE_ADDR target = 0;
317
318 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
319 {
320 /* Insn pattern is
321 lis r11, xxxx
322 lwz r11, xxxx(r11)
323 Branch target is in r11. */
324
325 target = (ppc_insn_d_field (insnbuf[0]) << 16)
326 | ppc_insn_d_field (insnbuf[1]);
327 target = read_memory_unsigned_integer (target, 4, byte_order);
328 }
329
330 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, insnbuf))
331 {
332 /* Insn pattern is
333 lwz r11, xxxx(r30)
334 Branch target is in r11. */
335
336 target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30)
337 + ppc_insn_d_field (insnbuf[0]);
338 target = read_memory_unsigned_integer (target, 4, byte_order);
339 }
340
341 return target;
342 }
343
344 /* Wrappers to handle Linux-only registers. */
345
346 static void
347 ppc_linux_supply_gregset (const struct regset *regset,
348 struct regcache *regcache,
349 int regnum, const void *gregs, size_t len)
350 {
351 const struct ppc_reg_offsets *offsets = regset->regmap;
352
353 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
354
355 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
356 {
357 /* "orig_r3" is stored 2 slots after "pc". */
358 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
359 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
360 offsets->pc_offset + 2 * offsets->gpr_size,
361 offsets->gpr_size);
362
363 /* "trap" is stored 8 slots after "pc". */
364 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
365 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, gregs,
366 offsets->pc_offset + 8 * offsets->gpr_size,
367 offsets->gpr_size);
368 }
369 }
370
371 static void
372 ppc_linux_collect_gregset (const struct regset *regset,
373 const struct regcache *regcache,
374 int regnum, void *gregs, size_t len)
375 {
376 const struct ppc_reg_offsets *offsets = regset->regmap;
377
378 /* Clear areas in the linux gregset not written elsewhere. */
379 if (regnum == -1)
380 memset (gregs, 0, len);
381
382 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
383
384 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
385 {
386 /* "orig_r3" is stored 2 slots after "pc". */
387 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
388 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
389 offsets->pc_offset + 2 * offsets->gpr_size,
390 offsets->gpr_size);
391
392 /* "trap" is stored 8 slots after "pc". */
393 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
394 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, gregs,
395 offsets->pc_offset + 8 * offsets->gpr_size,
396 offsets->gpr_size);
397 }
398 }
399
400 /* Regset descriptions. */
401 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
402 {
403 /* General-purpose registers. */
404 /* .r0_offset = */ 0,
405 /* .gpr_size = */ 4,
406 /* .xr_size = */ 4,
407 /* .pc_offset = */ 128,
408 /* .ps_offset = */ 132,
409 /* .cr_offset = */ 152,
410 /* .lr_offset = */ 144,
411 /* .ctr_offset = */ 140,
412 /* .xer_offset = */ 148,
413 /* .mq_offset = */ 156,
414
415 /* Floating-point registers. */
416 /* .f0_offset = */ 0,
417 /* .fpscr_offset = */ 256,
418 /* .fpscr_size = */ 8,
419
420 /* AltiVec registers. */
421 /* .vr0_offset = */ 0,
422 /* .vscr_offset = */ 512 + 12,
423 /* .vrsave_offset = */ 528
424 };
425
426 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
427 {
428 /* General-purpose registers. */
429 /* .r0_offset = */ 0,
430 /* .gpr_size = */ 8,
431 /* .xr_size = */ 8,
432 /* .pc_offset = */ 256,
433 /* .ps_offset = */ 264,
434 /* .cr_offset = */ 304,
435 /* .lr_offset = */ 288,
436 /* .ctr_offset = */ 280,
437 /* .xer_offset = */ 296,
438 /* .mq_offset = */ 312,
439
440 /* Floating-point registers. */
441 /* .f0_offset = */ 0,
442 /* .fpscr_offset = */ 256,
443 /* .fpscr_size = */ 8,
444
445 /* AltiVec registers. */
446 /* .vr0_offset = */ 0,
447 /* .vscr_offset = */ 512 + 12,
448 /* .vrsave_offset = */ 528
449 };
450
451 static const struct regset ppc32_linux_gregset = {
452 &ppc32_linux_reg_offsets,
453 ppc_linux_supply_gregset,
454 ppc_linux_collect_gregset
455 };
456
457 static const struct regset ppc64_linux_gregset = {
458 &ppc64_linux_reg_offsets,
459 ppc_linux_supply_gregset,
460 ppc_linux_collect_gregset
461 };
462
463 static const struct regset ppc32_linux_fpregset = {
464 &ppc32_linux_reg_offsets,
465 ppc_supply_fpregset,
466 ppc_collect_fpregset
467 };
468
469 static const struct regset ppc32_linux_vrregset = {
470 &ppc32_linux_reg_offsets,
471 ppc_supply_vrregset,
472 ppc_collect_vrregset
473 };
474
475 static const struct regset ppc32_linux_vsxregset = {
476 &ppc32_linux_reg_offsets,
477 ppc_supply_vsxregset,
478 ppc_collect_vsxregset
479 };
480
481 const struct regset *
482 ppc_linux_gregset (int wordsize)
483 {
484 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
485 }
486
487 const struct regset *
488 ppc_linux_fpregset (void)
489 {
490 return &ppc32_linux_fpregset;
491 }
492
493 /* Iterate over supported core file register note sections. */
494
495 static void
496 ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
497 iterate_over_regset_sections_cb *cb,
498 void *cb_data,
499 const struct regcache *regcache)
500 {
501 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
502 int have_altivec = tdep->ppc_vr0_regnum != -1;
503 int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
504
505 if (tdep->wordsize == 4)
506 cb (".reg", 48 * 4, &ppc32_linux_gregset, NULL, cb_data);
507 else
508 cb (".reg", 48 * 8, &ppc64_linux_gregset, NULL, cb_data);
509
510 cb (".reg2", 264, &ppc32_linux_fpregset, NULL, cb_data);
511
512 if (have_altivec)
513 cb (".reg-ppc-vmx", 544, &ppc32_linux_vrregset, "ppc Altivec", cb_data);
514
515 if (have_vsx)
516 cb (".reg-ppc-vsx", 256, &ppc32_linux_vsxregset, "POWER7 VSX", cb_data);
517 }
518
519 static void
520 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
521 struct trad_frame_cache *this_cache,
522 CORE_ADDR func, LONGEST offset,
523 int bias)
524 {
525 CORE_ADDR base;
526 CORE_ADDR regs;
527 CORE_ADDR gpregs;
528 CORE_ADDR fpregs;
529 int i;
530 struct gdbarch *gdbarch = get_frame_arch (this_frame);
531 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
532 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
533
534 base = get_frame_register_unsigned (this_frame,
535 gdbarch_sp_regnum (gdbarch));
536 if (bias > 0 && get_frame_pc (this_frame) != func)
537 /* See below, some signal trampolines increment the stack as their
538 first instruction, need to compensate for that. */
539 base -= bias;
540
541 /* Find the address of the register buffer pointer. */
542 regs = base + offset;
543 /* Use that to find the address of the corresponding register
544 buffers. */
545 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
546 fpregs = gpregs + 48 * tdep->wordsize;
547
548 /* General purpose. */
549 for (i = 0; i < 32; i++)
550 {
551 int regnum = i + tdep->ppc_gp0_regnum;
552 trad_frame_set_reg_addr (this_cache,
553 regnum, gpregs + i * tdep->wordsize);
554 }
555 trad_frame_set_reg_addr (this_cache,
556 gdbarch_pc_regnum (gdbarch),
557 gpregs + 32 * tdep->wordsize);
558 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
559 gpregs + 35 * tdep->wordsize);
560 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
561 gpregs + 36 * tdep->wordsize);
562 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
563 gpregs + 37 * tdep->wordsize);
564 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
565 gpregs + 38 * tdep->wordsize);
566
567 if (ppc_linux_trap_reg_p (gdbarch))
568 {
569 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
570 gpregs + 34 * tdep->wordsize);
571 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
572 gpregs + 40 * tdep->wordsize);
573 }
574
575 if (ppc_floating_point_unit_p (gdbarch))
576 {
577 /* Floating point registers. */
578 for (i = 0; i < 32; i++)
579 {
580 int regnum = i + gdbarch_fp0_regnum (gdbarch);
581 trad_frame_set_reg_addr (this_cache, regnum,
582 fpregs + i * tdep->wordsize);
583 }
584 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
585 fpregs + 32 * tdep->wordsize);
586 }
587 trad_frame_set_id (this_cache, frame_id_build (base, func));
588 }
589
590 static void
591 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
592 struct frame_info *this_frame,
593 struct trad_frame_cache *this_cache,
594 CORE_ADDR func)
595 {
596 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
597 0xd0 /* Offset to ucontext_t. */
598 + 0x30 /* Offset to .reg. */,
599 0);
600 }
601
602 static void
603 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
604 struct frame_info *this_frame,
605 struct trad_frame_cache *this_cache,
606 CORE_ADDR func)
607 {
608 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
609 0x80 /* Offset to ucontext_t. */
610 + 0xe0 /* Offset to .reg. */,
611 128);
612 }
613
614 static void
615 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
616 struct frame_info *this_frame,
617 struct trad_frame_cache *this_cache,
618 CORE_ADDR func)
619 {
620 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
621 0x40 /* Offset to ucontext_t. */
622 + 0x1c /* Offset to .reg. */,
623 0);
624 }
625
626 static void
627 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
628 struct frame_info *this_frame,
629 struct trad_frame_cache *this_cache,
630 CORE_ADDR func)
631 {
632 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
633 0x80 /* Offset to struct sigcontext. */
634 + 0x38 /* Offset to .reg. */,
635 128);
636 }
637
638 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
639 SIGTRAMP_FRAME,
640 4,
641 {
642 { 0x380000ac, -1 }, /* li r0, 172 */
643 { 0x44000002, -1 }, /* sc */
644 { TRAMP_SENTINEL_INSN },
645 },
646 ppc32_linux_sigaction_cache_init
647 };
648 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
649 SIGTRAMP_FRAME,
650 4,
651 {
652 { 0x38210080, -1 }, /* addi r1,r1,128 */
653 { 0x380000ac, -1 }, /* li r0, 172 */
654 { 0x44000002, -1 }, /* sc */
655 { TRAMP_SENTINEL_INSN },
656 },
657 ppc64_linux_sigaction_cache_init
658 };
659 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
660 SIGTRAMP_FRAME,
661 4,
662 {
663 { 0x38000077, -1 }, /* li r0,119 */
664 { 0x44000002, -1 }, /* sc */
665 { TRAMP_SENTINEL_INSN },
666 },
667 ppc32_linux_sighandler_cache_init
668 };
669 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
670 SIGTRAMP_FRAME,
671 4,
672 {
673 { 0x38210080, -1 }, /* addi r1,r1,128 */
674 { 0x38000077, -1 }, /* li r0,119 */
675 { 0x44000002, -1 }, /* sc */
676 { TRAMP_SENTINEL_INSN },
677 },
678 ppc64_linux_sighandler_cache_init
679 };
680
681
682 /* Address to use for displaced stepping. When debugging a stand-alone
683 SPU executable, entry_point_address () will point to an SPU local-store
684 address and is thus not usable as displaced stepping location. We use
685 the auxiliary vector to determine the PowerPC-side entry point address
686 instead. */
687
688 static CORE_ADDR ppc_linux_entry_point_addr = 0;
689
690 static void
691 ppc_linux_inferior_created (struct target_ops *target, int from_tty)
692 {
693 ppc_linux_entry_point_addr = 0;
694 }
695
696 static CORE_ADDR
697 ppc_linux_displaced_step_location (struct gdbarch *gdbarch)
698 {
699 if (ppc_linux_entry_point_addr == 0)
700 {
701 CORE_ADDR addr;
702
703 /* Determine entry point from target auxiliary vector. */
704 if (target_auxv_search (&current_target, AT_ENTRY, &addr) <= 0)
705 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
706
707 /* Make certain that the address points at real code, and not a
708 function descriptor. */
709 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
710 &current_target);
711
712 /* Inferior calls also use the entry point as a breakpoint location.
713 We don't want displaced stepping to interfere with those
714 breakpoints, so leave space. */
715 ppc_linux_entry_point_addr = addr + 2 * PPC_INSN_SIZE;
716 }
717
718 return ppc_linux_entry_point_addr;
719 }
720
721
722 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
723 int
724 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
725 {
726 /* If we do not have a target description with registers, then
727 the special registers will not be included in the register set. */
728 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
729 return 0;
730
731 /* If we do, then it is safe to check the size. */
732 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
733 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
734 }
735
736 /* Return the current system call's number present in the
737 r0 register. When the function fails, it returns -1. */
738 static LONGEST
739 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
740 ptid_t ptid)
741 {
742 struct regcache *regcache = get_thread_regcache (ptid);
743 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
744 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
745 struct cleanup *cleanbuf;
746 /* The content of a register */
747 gdb_byte *buf;
748 /* The result */
749 LONGEST ret;
750
751 /* Make sure we're in a 32- or 64-bit machine */
752 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
753
754 buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte));
755
756 cleanbuf = make_cleanup (xfree, buf);
757
758 /* Getting the system call number from the register.
759 When dealing with PowerPC architecture, this information
760 is stored at 0th register. */
761 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf);
762
763 ret = extract_signed_integer (buf, tdep->wordsize, byte_order);
764 do_cleanups (cleanbuf);
765
766 return ret;
767 }
768
769 /* PPC process record-replay */
770
771 static struct linux_record_tdep ppc_linux_record_tdep;
772 static struct linux_record_tdep ppc64_linux_record_tdep;
773
774 static enum gdb_syscall
775 ppc_canonicalize_syscall (int syscall)
776 {
777 /* See arch/powerpc/include/uapi/asm/unistd.h */
778
779 if (syscall <= 165)
780 return syscall;
781 else if (syscall >= 167 && syscall <= 190) /* Skip query_module 166 */
782 return syscall + 1;
783 else if (syscall >= 192 && syscall <= 197) /* mmap2 */
784 return syscall;
785 else if (syscall == 208) /* tkill */
786 return gdb_sys_tkill;
787 else if (syscall >= 207 && syscall <= 220) /* gettid */
788 return syscall + 224 - 207;
789 else if (syscall >= 234 && syscall <= 239) /* exit_group */
790 return syscall + 252 - 234;
791 else if (syscall >= 240 && syscall <=248) /* timer_create */
792 return syscall += 259 - 240;
793 else if (syscall >= 250 && syscall <=251) /* tgkill */
794 return syscall + 270 - 250;
795 else if (syscall == 336)
796 return gdb_sys_recv;
797 else if (syscall == 337)
798 return gdb_sys_recvfrom;
799 else if (syscall == 342)
800 return gdb_sys_recvmsg;
801 return -1;
802 }
803
804 static int
805 ppc_linux_syscall_record (struct regcache *regcache)
806 {
807 struct gdbarch *gdbarch = get_regcache_arch (regcache);
808 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
809 ULONGEST scnum;
810 enum gdb_syscall syscall_gdb;
811 int ret;
812 int i;
813
814 regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum, &scnum);
815 syscall_gdb = ppc_canonicalize_syscall (scnum);
816
817 if (syscall_gdb < 0)
818 {
819 printf_unfiltered (_("Process record and replay target doesn't "
820 "support syscall number %d\n"), (int) scnum);
821 return 0;
822 }
823
824 if (syscall_gdb == gdb_sys_sigreturn
825 || syscall_gdb == gdb_sys_rt_sigreturn)
826 {
827 int i, j;
828 int regsets[] = { tdep->ppc_gp0_regnum,
829 tdep->ppc_fp0_regnum,
830 tdep->ppc_vr0_regnum,
831 tdep->ppc_vsr0_upper_regnum };
832
833 for (j = 0; j < 4; j++)
834 {
835 if (regsets[j] == -1)
836 continue;
837 for (i = 0; i < 32; i++)
838 {
839 if (record_full_arch_list_add_reg (regcache, regsets[j] + i))
840 return -1;
841 }
842 }
843
844 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
845 return -1;
846 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
847 return -1;
848 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
849 return -1;
850 if (record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum))
851 return -1;
852
853 return 0;
854 }
855
856 if (tdep->wordsize == 8)
857 ret = record_linux_system_call (syscall_gdb, regcache,
858 &ppc64_linux_record_tdep);
859 else
860 ret = record_linux_system_call (syscall_gdb, regcache,
861 &ppc_linux_record_tdep);
862
863 if (ret != 0)
864 return ret;
865
866 /* Record registers clobbered during syscall. */
867 for (i = 3; i <= 12; i++)
868 {
869 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
870 return -1;
871 }
872 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + 0))
873 return -1;
874 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
875 return -1;
876 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
877 return -1;
878 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
879 return -1;
880
881 return 0;
882 }
883
884 static int
885 ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
886 enum gdb_signal signal)
887 {
888 /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c
889 handle_rt_signal32 in arch/powerpc/kernel/signal_32.c
890 arch/powerpc/include/asm/ptrace.h
891 for details. */
892 const int SIGNAL_FRAMESIZE = 128;
893 const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
894 ULONGEST sp;
895 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
896 int i;
897
898 for (i = 3; i <= 12; i++)
899 {
900 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
901 return -1;
902 }
903
904 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
905 return -1;
906 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
907 return -1;
908 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
909 return -1;
910 if (record_full_arch_list_add_reg (regcache, gdbarch_pc_regnum (gdbarch)))
911 return -1;
912 if (record_full_arch_list_add_reg (regcache, gdbarch_sp_regnum (gdbarch)))
913 return -1;
914
915 /* Record the change in the stack.
916 frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
917 regcache_raw_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &sp);
918 sp -= SIGNAL_FRAMESIZE;
919 sp -= sizeof_rt_sigframe;
920
921 if (record_full_arch_list_add_mem (sp, SIGNAL_FRAMESIZE + sizeof_rt_sigframe))
922 return -1;
923
924 if (record_full_arch_list_add_end ())
925 return -1;
926
927 return 0;
928 }
929
930 static void
931 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
932 {
933 struct gdbarch *gdbarch = get_regcache_arch (regcache);
934
935 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
936
937 /* Set special TRAP register to -1 to prevent the kernel from
938 messing with the PC we just installed, if we happen to be
939 within an interrupted system call that the kernel wants to
940 restart.
941
942 Note that after we return from the dummy call, the TRAP and
943 ORIG_R3 registers will be automatically restored, and the
944 kernel continues to restart the system call at this point. */
945 if (ppc_linux_trap_reg_p (gdbarch))
946 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
947 }
948
949 static int
950 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
951 {
952 return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
953 }
954
955 static const struct target_desc *
956 ppc_linux_core_read_description (struct gdbarch *gdbarch,
957 struct target_ops *target,
958 bfd *abfd)
959 {
960 asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
961 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
962 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
963 asection *section = bfd_get_section_by_name (abfd, ".reg");
964 if (! section)
965 return NULL;
966
967 switch (bfd_section_size (abfd, section))
968 {
969 case 48 * 4:
970 if (cell)
971 return tdesc_powerpc_cell32l;
972 else if (vsx)
973 return tdesc_powerpc_vsx32l;
974 else if (altivec)
975 return tdesc_powerpc_altivec32l;
976 else
977 return tdesc_powerpc_32l;
978
979 case 48 * 8:
980 if (cell)
981 return tdesc_powerpc_cell64l;
982 else if (vsx)
983 return tdesc_powerpc_vsx64l;
984 else if (altivec)
985 return tdesc_powerpc_altivec64l;
986 else
987 return tdesc_powerpc_64l;
988
989 default:
990 return NULL;
991 }
992 }
993
994
995 /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
996 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
997
998 static void
999 ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
1000 {
1001 elf_symbol_type *elf_sym = (elf_symbol_type *)sym;
1002
1003 /* If the symbol is marked as having a local entry point, set a target
1004 flag in the msymbol. We currently only support local entry point
1005 offsets of 8 bytes, which is the only entry point offset ever used
1006 by current compilers. If/when other offsets are ever used, we will
1007 have to use additional target flag bits to store them. */
1008 switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other))
1009 {
1010 default:
1011 break;
1012 case 8:
1013 MSYMBOL_TARGET_FLAG_1 (msym) = 1;
1014 break;
1015 }
1016 }
1017
1018 /* Implementation of `gdbarch_skip_entrypoint', as defined in
1019 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1020
1021 static CORE_ADDR
1022 ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc)
1023 {
1024 struct bound_minimal_symbol fun;
1025 int local_entry_offset = 0;
1026
1027 fun = lookup_minimal_symbol_by_pc (pc);
1028 if (fun.minsym == NULL)
1029 return pc;
1030
1031 /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
1032 offset values are encoded. */
1033 if (MSYMBOL_TARGET_FLAG_1 (fun.minsym))
1034 local_entry_offset = 8;
1035
1036 if (BMSYMBOL_VALUE_ADDRESS (fun) <= pc
1037 && pc < BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset)
1038 return BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset;
1039
1040 return pc;
1041 }
1042
1043 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1044 gdbarch.h. */
1045
1046 static int
1047 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
1048 {
1049 return (*s == 'i' /* Literal number. */
1050 || (isdigit (*s) && s[1] == '('
1051 && isdigit (s[2])) /* Displacement. */
1052 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
1053 || isdigit (*s)); /* Register value. */
1054 }
1055
1056 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
1057 gdbarch.h. */
1058
1059 static int
1060 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
1061 struct stap_parse_info *p)
1062 {
1063 if (isdigit (*p->arg))
1064 {
1065 /* This temporary pointer is needed because we have to do a lookahead.
1066 We could be dealing with a register displacement, and in such case
1067 we would not need to do anything. */
1068 const char *s = p->arg;
1069 char *regname;
1070 int len;
1071 struct stoken str;
1072
1073 while (isdigit (*s))
1074 ++s;
1075
1076 if (*s == '(')
1077 {
1078 /* It is a register displacement indeed. Returning 0 means we are
1079 deferring the treatment of this case to the generic parser. */
1080 return 0;
1081 }
1082
1083 len = s - p->arg;
1084 regname = alloca (len + 2);
1085 regname[0] = 'r';
1086
1087 strncpy (regname + 1, p->arg, len);
1088 ++len;
1089 regname[len] = '\0';
1090
1091 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
1092 error (_("Invalid register name `%s' on expression `%s'."),
1093 regname, p->saved_arg);
1094
1095 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
1096 str.ptr = regname;
1097 str.length = len;
1098 write_exp_string (&p->pstate, str);
1099 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
1100
1101 p->arg = s;
1102 }
1103 else
1104 {
1105 /* All the other tokens should be handled correctly by the generic
1106 parser. */
1107 return 0;
1108 }
1109
1110 return 1;
1111 }
1112
1113 /* Cell/B.E. active SPE context tracking support. */
1114
1115 static struct objfile *spe_context_objfile = NULL;
1116 static CORE_ADDR spe_context_lm_addr = 0;
1117 static CORE_ADDR spe_context_offset = 0;
1118
1119 static ptid_t spe_context_cache_ptid;
1120 static CORE_ADDR spe_context_cache_address;
1121
1122 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
1123 to track whether we've loaded a version of libspe2 (as static or dynamic
1124 library) that provides the __spe_current_active_context variable. */
1125 static void
1126 ppc_linux_spe_context_lookup (struct objfile *objfile)
1127 {
1128 struct bound_minimal_symbol sym;
1129
1130 if (!objfile)
1131 {
1132 spe_context_objfile = NULL;
1133 spe_context_lm_addr = 0;
1134 spe_context_offset = 0;
1135 spe_context_cache_ptid = minus_one_ptid;
1136 spe_context_cache_address = 0;
1137 return;
1138 }
1139
1140 sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
1141 if (sym.minsym)
1142 {
1143 spe_context_objfile = objfile;
1144 spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
1145 spe_context_offset = BMSYMBOL_VALUE_ADDRESS (sym);
1146 spe_context_cache_ptid = minus_one_ptid;
1147 spe_context_cache_address = 0;
1148 return;
1149 }
1150 }
1151
1152 static void
1153 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
1154 {
1155 struct objfile *objfile;
1156
1157 ppc_linux_spe_context_lookup (NULL);
1158 ALL_OBJFILES (objfile)
1159 ppc_linux_spe_context_lookup (objfile);
1160 }
1161
1162 static void
1163 ppc_linux_spe_context_solib_loaded (struct so_list *so)
1164 {
1165 if (strstr (so->so_original_name, "/libspe") != NULL)
1166 {
1167 solib_read_symbols (so, 0);
1168 ppc_linux_spe_context_lookup (so->objfile);
1169 }
1170 }
1171
1172 static void
1173 ppc_linux_spe_context_solib_unloaded (struct so_list *so)
1174 {
1175 if (so->objfile == spe_context_objfile)
1176 ppc_linux_spe_context_lookup (NULL);
1177 }
1178
1179 /* Retrieve contents of the N'th element in the current thread's
1180 linked SPE context list into ID and NPC. Return the address of
1181 said context element, or 0 if not found. */
1182 static CORE_ADDR
1183 ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
1184 int n, int *id, unsigned int *npc)
1185 {
1186 CORE_ADDR spe_context = 0;
1187 gdb_byte buf[16];
1188 int i;
1189
1190 /* Quick exit if we have not found __spe_current_active_context. */
1191 if (!spe_context_objfile)
1192 return 0;
1193
1194 /* Look up cached address of thread-local variable. */
1195 if (!ptid_equal (spe_context_cache_ptid, inferior_ptid))
1196 {
1197 struct target_ops *target = &current_target;
1198 volatile struct gdb_exception ex;
1199
1200 TRY_CATCH (ex, RETURN_MASK_ERROR)
1201 {
1202 /* We do not call target_translate_tls_address here, because
1203 svr4_fetch_objfile_link_map may invalidate the frame chain,
1204 which must not do while inside a frame sniffer.
1205
1206 Instead, we have cached the lm_addr value, and use that to
1207 directly call the target's to_get_thread_local_address. */
1208 spe_context_cache_address
1209 = target->to_get_thread_local_address (target, inferior_ptid,
1210 spe_context_lm_addr,
1211 spe_context_offset);
1212 spe_context_cache_ptid = inferior_ptid;
1213 }
1214
1215 if (ex.reason < 0)
1216 return 0;
1217 }
1218
1219 /* Read variable value. */
1220 if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
1221 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1222
1223 /* Cyle through to N'th linked list element. */
1224 for (i = 0; i < n && spe_context; i++)
1225 if (target_read_memory (spe_context + align_up (12, wordsize),
1226 buf, wordsize) == 0)
1227 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1228 else
1229 spe_context = 0;
1230
1231 /* Read current context. */
1232 if (spe_context
1233 && target_read_memory (spe_context, buf, 12) != 0)
1234 spe_context = 0;
1235
1236 /* Extract data elements. */
1237 if (spe_context)
1238 {
1239 if (id)
1240 *id = extract_signed_integer (buf, 4, byte_order);
1241 if (npc)
1242 *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
1243 }
1244
1245 return spe_context;
1246 }
1247
1248
1249 /* Cell/B.E. cross-architecture unwinder support. */
1250
1251 struct ppu2spu_cache
1252 {
1253 struct frame_id frame_id;
1254 struct regcache *regcache;
1255 };
1256
1257 static struct gdbarch *
1258 ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
1259 {
1260 struct ppu2spu_cache *cache = *this_cache;
1261 return get_regcache_arch (cache->regcache);
1262 }
1263
1264 static void
1265 ppu2spu_this_id (struct frame_info *this_frame,
1266 void **this_cache, struct frame_id *this_id)
1267 {
1268 struct ppu2spu_cache *cache = *this_cache;
1269 *this_id = cache->frame_id;
1270 }
1271
1272 static struct value *
1273 ppu2spu_prev_register (struct frame_info *this_frame,
1274 void **this_cache, int regnum)
1275 {
1276 struct ppu2spu_cache *cache = *this_cache;
1277 struct gdbarch *gdbarch = get_regcache_arch (cache->regcache);
1278 gdb_byte *buf;
1279
1280 buf = alloca (register_size (gdbarch, regnum));
1281
1282 if (regnum < gdbarch_num_regs (gdbarch))
1283 regcache_raw_read (cache->regcache, regnum, buf);
1284 else
1285 gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf);
1286
1287 return frame_unwind_got_bytes (this_frame, regnum, buf);
1288 }
1289
1290 struct ppu2spu_data
1291 {
1292 struct gdbarch *gdbarch;
1293 int id;
1294 unsigned int npc;
1295 gdb_byte gprs[128*16];
1296 };
1297
1298 static int
1299 ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf)
1300 {
1301 struct ppu2spu_data *data = src;
1302 enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
1303
1304 if (regnum >= 0 && regnum < SPU_NUM_GPRS)
1305 memcpy (buf, data->gprs + 16*regnum, 16);
1306 else if (regnum == SPU_ID_REGNUM)
1307 store_unsigned_integer (buf, 4, byte_order, data->id);
1308 else if (regnum == SPU_PC_REGNUM)
1309 store_unsigned_integer (buf, 4, byte_order, data->npc);
1310 else
1311 return REG_UNAVAILABLE;
1312
1313 return REG_VALID;
1314 }
1315
1316 static int
1317 ppu2spu_sniffer (const struct frame_unwind *self,
1318 struct frame_info *this_frame, void **this_prologue_cache)
1319 {
1320 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1321 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1322 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1323 struct ppu2spu_data data;
1324 struct frame_info *fi;
1325 CORE_ADDR base, func, backchain, spe_context;
1326 gdb_byte buf[8];
1327 int n = 0;
1328
1329 /* Count the number of SPU contexts already in the frame chain. */
1330 for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
1331 if (get_frame_type (fi) == ARCH_FRAME
1332 && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
1333 n++;
1334
1335 base = get_frame_sp (this_frame);
1336 func = get_frame_pc (this_frame);
1337 if (target_read_memory (base, buf, tdep->wordsize))
1338 return 0;
1339 backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
1340
1341 spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
1342 n, &data.id, &data.npc);
1343 if (spe_context && base <= spe_context && spe_context < backchain)
1344 {
1345 char annex[32];
1346
1347 /* Find gdbarch for SPU. */
1348 struct gdbarch_info info;
1349 gdbarch_info_init (&info);
1350 info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
1351 info.byte_order = BFD_ENDIAN_BIG;
1352 info.osabi = GDB_OSABI_LINUX;
1353 info.tdep_info = (void *) &data.id;
1354 data.gdbarch = gdbarch_find_by_info (info);
1355 if (!data.gdbarch)
1356 return 0;
1357
1358 xsnprintf (annex, sizeof annex, "%d/regs", data.id);
1359 if (target_read (&current_target, TARGET_OBJECT_SPU, annex,
1360 data.gprs, 0, sizeof data.gprs)
1361 == sizeof data.gprs)
1362 {
1363 struct ppu2spu_cache *cache
1364 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
1365
1366 struct address_space *aspace = get_frame_address_space (this_frame);
1367 struct regcache *regcache = regcache_xmalloc (data.gdbarch, aspace);
1368 struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
1369 regcache_save (regcache, ppu2spu_unwind_register, &data);
1370 discard_cleanups (cleanups);
1371
1372 cache->frame_id = frame_id_build (base, func);
1373 cache->regcache = regcache;
1374 *this_prologue_cache = cache;
1375 return 1;
1376 }
1377 }
1378
1379 return 0;
1380 }
1381
1382 static void
1383 ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
1384 {
1385 struct ppu2spu_cache *cache = this_cache;
1386 regcache_xfree (cache->regcache);
1387 }
1388
1389 static const struct frame_unwind ppu2spu_unwind = {
1390 ARCH_FRAME,
1391 default_frame_unwind_stop_reason,
1392 ppu2spu_this_id,
1393 ppu2spu_prev_register,
1394 NULL,
1395 ppu2spu_sniffer,
1396 ppu2spu_dealloc_cache,
1397 ppu2spu_prev_arch,
1398 };
1399
1400 /* Initialize linux_record_tdep if not initialized yet. */
1401
1402 static void
1403 ppc_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
1404 int wordsize)
1405 {
1406 /* Simply return if it had been initialized. */
1407 if (record_tdep->size_pointer != 0)
1408 return;
1409
1410 /* These values are the size of the type that will be used in a system
1411 call. They are obtained from Linux Kernel source. */
1412
1413 if (wordsize == 8)
1414 {
1415 record_tdep->size_pointer = 8;
1416 record_tdep->size__old_kernel_stat = 32;
1417 record_tdep->size_tms = 32;
1418 record_tdep->size_loff_t = 8;
1419 record_tdep->size_flock = 32;
1420 record_tdep->size_oldold_utsname = 45;
1421 record_tdep->size_ustat = 32;
1422 record_tdep->size_old_sigaction = 152;
1423 record_tdep->size_old_sigset_t = 128;
1424 record_tdep->size_rlimit = 16;
1425 record_tdep->size_rusage = 144;
1426 record_tdep->size_timeval = 16;
1427 record_tdep->size_timezone = 8;
1428 record_tdep->size_old_gid_t = 4;
1429 record_tdep->size_old_uid_t = 4;
1430 record_tdep->size_fd_set = 128;
1431 record_tdep->size_dirent = 280;
1432 record_tdep->size_dirent64 = 280;
1433 record_tdep->size_statfs = 120;
1434 record_tdep->size_statfs64 = 120;
1435 record_tdep->size_sockaddr = 16;
1436 record_tdep->size_int = 4;
1437 record_tdep->size_long = 8;
1438 record_tdep->size_ulong = 8;
1439 record_tdep->size_msghdr = 56;
1440 record_tdep->size_itimerval = 32;
1441 record_tdep->size_stat = 144;
1442 record_tdep->size_old_utsname = 325;
1443 record_tdep->size_sysinfo = 112;
1444 record_tdep->size_msqid_ds = 120;
1445 record_tdep->size_shmid_ds = 112;
1446 record_tdep->size_new_utsname = 390;
1447 record_tdep->size_timex = 208;
1448 record_tdep->size_mem_dqinfo = 24;
1449 record_tdep->size_if_dqblk = 72;
1450 record_tdep->size_fs_quota_stat = 80;
1451 record_tdep->size_timespec = 16;
1452 record_tdep->size_pollfd = 8;
1453 record_tdep->size_NFS_FHSIZE = 32;
1454 record_tdep->size_knfsd_fh = 132;
1455 record_tdep->size_TASK_COMM_LEN = 32;
1456 record_tdep->size_sigaction = 152;
1457 record_tdep->size_sigset_t = 128;
1458 record_tdep->size_siginfo_t = 128;
1459 record_tdep->size_cap_user_data_t = 8;
1460 record_tdep->size_stack_t = 24;
1461 record_tdep->size_off_t = 8;
1462 record_tdep->size_stat64 = 104;
1463 record_tdep->size_gid_t = 4;
1464 record_tdep->size_uid_t = 4;
1465 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
1466 record_tdep->size_flock64 = 32;
1467 record_tdep->size_io_event = 32;
1468 record_tdep->size_iocb = 64;
1469 record_tdep->size_epoll_event = 16;
1470 record_tdep->size_itimerspec = 32;
1471 record_tdep->size_mq_attr = 64;
1472 record_tdep->size_siginfo = 128;
1473 record_tdep->size_termios = 44;
1474 record_tdep->size_pid_t = 4;
1475 record_tdep->size_winsize = 8;
1476 record_tdep->size_serial_struct = 72;
1477 record_tdep->size_serial_icounter_struct = 80;
1478 record_tdep->size_size_t = 8;
1479 record_tdep->size_iovec = 16;
1480 }
1481 else if (wordsize == 4)
1482 {
1483 record_tdep->size_pointer = 4;
1484 record_tdep->size__old_kernel_stat = 32;
1485 record_tdep->size_tms = 16;
1486 record_tdep->size_loff_t = 8;
1487 record_tdep->size_flock = 16;
1488 record_tdep->size_oldold_utsname = 45;
1489 record_tdep->size_ustat = 20;
1490 record_tdep->size_old_sigaction = 152;
1491 record_tdep->size_old_sigset_t = 128;
1492 record_tdep->size_rlimit = 8;
1493 record_tdep->size_rusage = 72;
1494 record_tdep->size_timeval = 8;
1495 record_tdep->size_timezone = 8;
1496 record_tdep->size_old_gid_t = 4;
1497 record_tdep->size_old_uid_t = 4;
1498 record_tdep->size_fd_set = 128;
1499 record_tdep->size_dirent = 268;
1500 record_tdep->size_dirent64 = 280;
1501 record_tdep->size_statfs = 64;
1502 record_tdep->size_statfs64 = 88;
1503 record_tdep->size_sockaddr = 16;
1504 record_tdep->size_int = 4;
1505 record_tdep->size_long = 4;
1506 record_tdep->size_ulong = 4;
1507 record_tdep->size_msghdr = 28;
1508 record_tdep->size_itimerval = 16;
1509 record_tdep->size_stat = 88;
1510 record_tdep->size_old_utsname = 325;
1511 record_tdep->size_sysinfo = 64;
1512 record_tdep->size_msqid_ds = 68;
1513 record_tdep->size_shmid_ds = 60;
1514 record_tdep->size_new_utsname = 390;
1515 record_tdep->size_timex = 128;
1516 record_tdep->size_mem_dqinfo = 24;
1517 record_tdep->size_if_dqblk = 72;
1518 record_tdep->size_fs_quota_stat = 80;
1519 record_tdep->size_timespec = 8;
1520 record_tdep->size_pollfd = 8;
1521 record_tdep->size_NFS_FHSIZE = 32;
1522 record_tdep->size_knfsd_fh = 132;
1523 record_tdep->size_TASK_COMM_LEN = 32;
1524 record_tdep->size_sigaction = 140;
1525 record_tdep->size_sigset_t = 128;
1526 record_tdep->size_siginfo_t = 128;
1527 record_tdep->size_cap_user_data_t = 4;
1528 record_tdep->size_stack_t = 12;
1529 record_tdep->size_off_t = 4;
1530 record_tdep->size_stat64 = 104;
1531 record_tdep->size_gid_t = 4;
1532 record_tdep->size_uid_t = 4;
1533 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
1534 record_tdep->size_flock64 = 32;
1535 record_tdep->size_io_event = 32;
1536 record_tdep->size_iocb = 64;
1537 record_tdep->size_epoll_event = 16;
1538 record_tdep->size_itimerspec = 16;
1539 record_tdep->size_mq_attr = 32;
1540 record_tdep->size_siginfo = 128;
1541 record_tdep->size_termios = 44;
1542 record_tdep->size_pid_t = 4;
1543 record_tdep->size_winsize = 8;
1544 record_tdep->size_serial_struct = 60;
1545 record_tdep->size_serial_icounter_struct = 80;
1546 record_tdep->size_size_t = 4;
1547 record_tdep->size_iovec = 8;
1548 }
1549 else
1550 internal_error (__FILE__, __LINE__, _("unexpected wordsize"));
1551
1552 /* These values are the second argument of system call "sys_fcntl"
1553 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1554 record_tdep->fcntl_F_GETLK = 5;
1555 record_tdep->fcntl_F_GETLK64 = 12;
1556 record_tdep->fcntl_F_SETLK64 = 13;
1557 record_tdep->fcntl_F_SETLKW64 = 14;
1558
1559 record_tdep->arg1 = PPC_R0_REGNUM + 3;
1560 record_tdep->arg2 = PPC_R0_REGNUM + 4;
1561 record_tdep->arg3 = PPC_R0_REGNUM + 5;
1562 record_tdep->arg4 = PPC_R0_REGNUM + 6;
1563 record_tdep->arg5 = PPC_R0_REGNUM + 7;
1564 record_tdep->arg6 = PPC_R0_REGNUM + 8;
1565
1566 /* These values are the second argument of system call "sys_ioctl".
1567 They are obtained from Linux Kernel source.
1568 See arch/powerpc/include/uapi/asm/ioctls.h. */
1569 record_tdep->ioctl_TCGETS = 0x403c7413;
1570 record_tdep->ioctl_TCSETS = 0x803c7414;
1571 record_tdep->ioctl_TCSETSW = 0x803c7415;
1572 record_tdep->ioctl_TCSETSF = 0x803c7416;
1573 record_tdep->ioctl_TCGETA = 0x40147417;
1574 record_tdep->ioctl_TCSETA = 0x80147418;
1575 record_tdep->ioctl_TCSETAW = 0x80147419;
1576 record_tdep->ioctl_TCSETAF = 0x8014741c;
1577 record_tdep->ioctl_TCSBRK = 0x2000741d;
1578 record_tdep->ioctl_TCXONC = 0x2000741e;
1579 record_tdep->ioctl_TCFLSH = 0x2000741f;
1580 record_tdep->ioctl_TIOCEXCL = 0x540c;
1581 record_tdep->ioctl_TIOCNXCL = 0x540d;
1582 record_tdep->ioctl_TIOCSCTTY = 0x540e;
1583 record_tdep->ioctl_TIOCGPGRP = 0x40047477;
1584 record_tdep->ioctl_TIOCSPGRP = 0x80047476;
1585 record_tdep->ioctl_TIOCOUTQ = 0x40047473;
1586 record_tdep->ioctl_TIOCSTI = 0x5412;
1587 record_tdep->ioctl_TIOCGWINSZ = 0x40087468;
1588 record_tdep->ioctl_TIOCSWINSZ = 0x80087467;
1589 record_tdep->ioctl_TIOCMGET = 0x5415;
1590 record_tdep->ioctl_TIOCMBIS = 0x5416;
1591 record_tdep->ioctl_TIOCMBIC = 0x5417;
1592 record_tdep->ioctl_TIOCMSET = 0x5418;
1593 record_tdep->ioctl_TIOCGSOFTCAR = 0x5419;
1594 record_tdep->ioctl_TIOCSSOFTCAR = 0x541a;
1595 record_tdep->ioctl_FIONREAD = 0x4004667f;
1596 record_tdep->ioctl_TIOCINQ = 0x4004667f;
1597 record_tdep->ioctl_TIOCLINUX = 0x541c;
1598 record_tdep->ioctl_TIOCCONS = 0x541d;
1599 record_tdep->ioctl_TIOCGSERIAL = 0x541e;
1600 record_tdep->ioctl_TIOCSSERIAL = 0x541f;
1601 record_tdep->ioctl_TIOCPKT = 0x5420;
1602 record_tdep->ioctl_FIONBIO = 0x8004667e;
1603 record_tdep->ioctl_TIOCNOTTY = 0x5422;
1604 record_tdep->ioctl_TIOCSETD = 0x5423;
1605 record_tdep->ioctl_TIOCGETD = 0x5424;
1606 record_tdep->ioctl_TCSBRKP = 0x5425;
1607 record_tdep->ioctl_TIOCSBRK = 0x5427;
1608 record_tdep->ioctl_TIOCCBRK = 0x5428;
1609 record_tdep->ioctl_TIOCGSID = 0x5429;
1610 record_tdep->ioctl_TIOCGPTN = 0x40045430;
1611 record_tdep->ioctl_TIOCSPTLCK = 0x80045431;
1612 record_tdep->ioctl_FIONCLEX = 0x20006602;
1613 record_tdep->ioctl_FIOCLEX = 0x20006601;
1614 record_tdep->ioctl_FIOASYNC = 0x8004667d;
1615 record_tdep->ioctl_TIOCSERCONFIG = 0x5453;
1616 record_tdep->ioctl_TIOCSERGWILD = 0x5454;
1617 record_tdep->ioctl_TIOCSERSWILD = 0x5455;
1618 record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456;
1619 record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457;
1620 record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458;
1621 record_tdep->ioctl_TIOCSERGETLSR = 0x5459;
1622 record_tdep->ioctl_TIOCSERGETMULTI = 0x545a;
1623 record_tdep->ioctl_TIOCSERSETMULTI = 0x545b;
1624 record_tdep->ioctl_TIOCMIWAIT = 0x545c;
1625 record_tdep->ioctl_TIOCGICOUNT = 0x545d;
1626 record_tdep->ioctl_FIOQSIZE = 0x40086680;
1627 }
1628
1629 static void
1630 ppc_linux_init_abi (struct gdbarch_info info,
1631 struct gdbarch *gdbarch)
1632 {
1633 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1634 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
1635 static const char *const stap_integer_prefixes[] = { "i", NULL };
1636 static const char *const stap_register_indirection_prefixes[] = { "(",
1637 NULL };
1638 static const char *const stap_register_indirection_suffixes[] = { ")",
1639 NULL };
1640
1641 linux_init_abi (info, gdbarch);
1642
1643 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1644 128-bit, they are IBM long double, not IEEE quad long double as
1645 in the System V ABI PowerPC Processor Supplement. We can safely
1646 let them default to 128-bit, since the debug info will give the
1647 size of type actually used in each case. */
1648 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
1649 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
1650
1651 /* Handle inferior calls during interrupted system calls. */
1652 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
1653
1654 /* Get the syscall number from the arch's register. */
1655 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
1656
1657 /* SystemTap functions. */
1658 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
1659 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
1660 stap_register_indirection_prefixes);
1661 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
1662 stap_register_indirection_suffixes);
1663 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
1664 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
1665 set_gdbarch_stap_parse_special_token (gdbarch,
1666 ppc_stap_parse_special_token);
1667
1668 if (tdep->wordsize == 4)
1669 {
1670 /* Until November 2001, gcc did not comply with the 32 bit SysV
1671 R4 ABI requirement that structures less than or equal to 8
1672 bytes should be returned in registers. Instead GCC was using
1673 the AIX/PowerOpen ABI - everything returned in memory
1674 (well ignoring vectors that is). When this was corrected, it
1675 wasn't fixed for GNU/Linux native platform. Use the
1676 PowerOpen struct convention. */
1677 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
1678
1679 set_gdbarch_memory_remove_breakpoint (gdbarch,
1680 ppc_linux_memory_remove_breakpoint);
1681
1682 /* Shared library handling. */
1683 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
1684 set_solib_svr4_fetch_link_map_offsets
1685 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1686
1687 /* Setting the correct XML syscall filename. */
1688 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC);
1689
1690 /* Trampolines. */
1691 tramp_frame_prepend_unwinder (gdbarch,
1692 &ppc32_linux_sigaction_tramp_frame);
1693 tramp_frame_prepend_unwinder (gdbarch,
1694 &ppc32_linux_sighandler_tramp_frame);
1695
1696 /* BFD target for core files. */
1697 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1698 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
1699 else
1700 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
1701
1702 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
1703 {
1704 powerpc_so_ops = svr4_so_ops;
1705 /* Override dynamic resolve function. */
1706 powerpc_so_ops.in_dynsym_resolve_code =
1707 powerpc_linux_in_dynsym_resolve_code;
1708 }
1709 set_solib_ops (gdbarch, &powerpc_so_ops);
1710
1711 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1712 }
1713
1714 if (tdep->wordsize == 8)
1715 {
1716 if (tdep->elf_abi == POWERPC_ELF_V1)
1717 {
1718 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1719 function descriptors). */
1720 set_gdbarch_convert_from_func_ptr_addr
1721 (gdbarch, ppc64_convert_from_func_ptr_addr);
1722
1723 set_gdbarch_elf_make_msymbol_special
1724 (gdbarch, ppc64_elf_make_msymbol_special);
1725 }
1726 else
1727 {
1728 set_gdbarch_elf_make_msymbol_special
1729 (gdbarch, ppc_elfv2_elf_make_msymbol_special);
1730
1731 set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint);
1732 }
1733
1734 /* Shared library handling. */
1735 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
1736 set_solib_svr4_fetch_link_map_offsets
1737 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1738
1739 /* Setting the correct XML syscall filename. */
1740 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC64);
1741
1742 /* Trampolines. */
1743 tramp_frame_prepend_unwinder (gdbarch,
1744 &ppc64_linux_sigaction_tramp_frame);
1745 tramp_frame_prepend_unwinder (gdbarch,
1746 &ppc64_linux_sighandler_tramp_frame);
1747
1748 /* BFD target for core files. */
1749 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1750 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
1751 else
1752 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
1753 }
1754
1755 /* PPC32 uses a different prpsinfo32 compared to most other Linux
1756 archs. */
1757 if (tdep->wordsize == 4)
1758 set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch,
1759 elfcore_write_ppc_linux_prpsinfo32);
1760
1761 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
1762 set_gdbarch_iterate_over_regset_sections (gdbarch,
1763 ppc_linux_iterate_over_regset_sections);
1764
1765 /* Enable TLS support. */
1766 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1767 svr4_fetch_objfile_link_map);
1768
1769 if (tdesc_data)
1770 {
1771 const struct tdesc_feature *feature;
1772
1773 /* If we have target-described registers, then we can safely
1774 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1775 (whether they are described or not). */
1776 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
1777 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
1778
1779 /* If they are present, then assign them to the reserved number. */
1780 feature = tdesc_find_feature (info.target_desc,
1781 "org.gnu.gdb.power.linux");
1782 if (feature != NULL)
1783 {
1784 tdesc_numbered_register (feature, tdesc_data,
1785 PPC_ORIG_R3_REGNUM, "orig_r3");
1786 tdesc_numbered_register (feature, tdesc_data,
1787 PPC_TRAP_REGNUM, "trap");
1788 }
1789 }
1790
1791 /* Enable Cell/B.E. if supported by the target. */
1792 if (tdesc_compatible_p (info.target_desc,
1793 bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
1794 {
1795 /* Cell/B.E. multi-architecture support. */
1796 set_spu_solib_ops (gdbarch);
1797
1798 /* Cell/B.E. cross-architecture unwinder support. */
1799 frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
1800
1801 /* The default displaced_step_at_entry_point doesn't work for
1802 SPU stand-alone executables. */
1803 set_gdbarch_displaced_step_location (gdbarch,
1804 ppc_linux_displaced_step_location);
1805 }
1806
1807 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
1808
1809 /* Support reverse debugging. */
1810 set_gdbarch_process_record (gdbarch, ppc_process_record);
1811 set_gdbarch_process_record_signal (gdbarch, ppc_linux_record_signal);
1812 tdep->ppc_syscall_record = ppc_linux_syscall_record;
1813
1814 ppc_init_linux_record_tdep (&ppc_linux_record_tdep, 4);
1815 ppc_init_linux_record_tdep (&ppc64_linux_record_tdep, 8);
1816 }
1817
1818 /* Provide a prototype to silence -Wmissing-prototypes. */
1819 extern initialize_file_ftype _initialize_ppc_linux_tdep;
1820
1821 void
1822 _initialize_ppc_linux_tdep (void)
1823 {
1824 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1825 64-bit PowerPC, and the older rs6k. */
1826 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
1827 ppc_linux_init_abi);
1828 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
1829 ppc_linux_init_abi);
1830 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
1831 ppc_linux_init_abi);
1832
1833 /* Attach to inferior_created observer. */
1834 observer_attach_inferior_created (ppc_linux_inferior_created);
1835
1836 /* Attach to observers to track __spe_current_active_context. */
1837 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created);
1838 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded);
1839 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded);
1840
1841 /* Initialize the Linux target descriptions. */
1842 initialize_tdesc_powerpc_32l ();
1843 initialize_tdesc_powerpc_altivec32l ();
1844 initialize_tdesc_powerpc_cell32l ();
1845 initialize_tdesc_powerpc_vsx32l ();
1846 initialize_tdesc_powerpc_isa205_32l ();
1847 initialize_tdesc_powerpc_isa205_altivec32l ();
1848 initialize_tdesc_powerpc_isa205_vsx32l ();
1849 initialize_tdesc_powerpc_64l ();
1850 initialize_tdesc_powerpc_altivec64l ();
1851 initialize_tdesc_powerpc_cell64l ();
1852 initialize_tdesc_powerpc_vsx64l ();
1853 initialize_tdesc_powerpc_isa205_64l ();
1854 initialize_tdesc_powerpc_isa205_altivec64l ();
1855 initialize_tdesc_powerpc_isa205_vsx64l ();
1856 initialize_tdesc_powerpc_e500l ();
1857 }
This page took 0.091987 seconds and 5 git commands to generate.