1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 1986-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
33 #include "solib-svr4.h"
34 #include "solib-spu.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"
46 #include "elf/common.h"
47 #include "exceptions.h"
48 #include "arch-utils.h"
50 #include "xml-syscall.h"
51 #include "linux-tdep.h"
53 #include "stap-probe.h"
56 #include "cli/cli-utils.h"
57 #include "parser-defs.h"
58 #include "user-regs.h"
60 #include "elf-bfd.h" /* for elfcore_write_* */
62 #include "features/rs6000/powerpc-32l.c"
63 #include "features/rs6000/powerpc-altivec32l.c"
64 #include "features/rs6000/powerpc-cell32l.c"
65 #include "features/rs6000/powerpc-vsx32l.c"
66 #include "features/rs6000/powerpc-isa205-32l.c"
67 #include "features/rs6000/powerpc-isa205-altivec32l.c"
68 #include "features/rs6000/powerpc-isa205-vsx32l.c"
69 #include "features/rs6000/powerpc-64l.c"
70 #include "features/rs6000/powerpc-altivec64l.c"
71 #include "features/rs6000/powerpc-cell64l.c"
72 #include "features/rs6000/powerpc-vsx64l.c"
73 #include "features/rs6000/powerpc-isa205-64l.c"
74 #include "features/rs6000/powerpc-isa205-altivec64l.c"
75 #include "features/rs6000/powerpc-isa205-vsx64l.c"
76 #include "features/rs6000/powerpc-e500l.c"
78 /* Shared library operations for PowerPC-Linux. */
79 static struct target_so_ops powerpc_so_ops
;
81 /* The syscall's XML filename for PPC and PPC64. */
82 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
83 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
85 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
86 in much the same fashion as memory_remove_breakpoint in mem-break.c,
87 but is careful not to write back the previous contents if the code
88 in question has changed in between inserting the breakpoint and
91 Here is the problem that we're trying to solve...
93 Once upon a time, before introducing this function to remove
94 breakpoints from the inferior, setting a breakpoint on a shared
95 library function prior to running the program would not work
96 properly. In order to understand the problem, it is first
97 necessary to understand a little bit about dynamic linking on
100 A call to a shared library function is accomplished via a bl
101 (branch-and-link) instruction whose branch target is an entry
102 in the procedure linkage table (PLT). The PLT in the object
103 file is uninitialized. To gdb, prior to running the program, the
104 entries in the PLT are all zeros.
106 Once the program starts running, the shared libraries are loaded
107 and the procedure linkage table is initialized, but the entries in
108 the table are not (necessarily) resolved. Once a function is
109 actually called, the code in the PLT is hit and the function is
110 resolved. In order to better illustrate this, an example is in
111 order; the following example is from the gdb testsuite.
113 We start the program shmain.
115 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
118 We place two breakpoints, one on shr1 and the other on main.
121 Breakpoint 1 at 0x100409d4
123 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
125 Examine the instruction (and the immediatly following instruction)
126 upon which the breakpoint was placed. Note that the PLT entry
127 for shr1 contains zeros.
129 (gdb) x/2i 0x100409d4
130 0x100409d4 <shr1>: .long 0x0
131 0x100409d8 <shr1+4>: .long 0x0
136 Starting program: gdb.base/shmain
137 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
139 Breakpoint 2, main ()
140 at gdb.base/shmain.c:44
143 Examine the PLT again. Note that the loading of the shared
144 library has initialized the PLT to code which loads a constant
145 (which I think is an index into the GOT) into r11 and then
146 branchs a short distance to the code which actually does the
149 (gdb) x/2i 0x100409d4
150 0x100409d4 <shr1>: li r11,4
151 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
155 Breakpoint 1, shr1 (x=1)
156 at gdb.base/shr1.c:19
159 Now we've hit the breakpoint at shr1. (The breakpoint was
160 reset from the PLT entry to the actual shr1 function after the
161 shared library was loaded.) Note that the PLT entry has been
162 resolved to contain a branch that takes us directly to shr1.
163 (The real one, not the PLT entry.)
165 (gdb) x/2i 0x100409d4
166 0x100409d4 <shr1>: b 0xffaf76c <shr1>
167 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
169 The thing to note here is that the PLT entry for shr1 has been
172 Now the problem should be obvious. GDB places a breakpoint (a
173 trap instruction) on the zero value of the PLT entry for shr1.
174 Later on, after the shared library had been loaded and the PLT
175 initialized, GDB gets a signal indicating this fact and attempts
176 (as it always does when it stops) to remove all the breakpoints.
178 The breakpoint removal was causing the former contents (a zero
179 word) to be written back to the now initialized PLT entry thus
180 destroying a portion of the initialization that had occurred only a
181 short time ago. When execution continued, the zero word would be
182 executed as an instruction an illegal instruction trap was
183 generated instead. (0 is not a legal instruction.)
185 The fix for this problem was fairly straightforward. The function
186 memory_remove_breakpoint from mem-break.c was copied to this file,
187 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
188 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
191 The differences between ppc_linux_memory_remove_breakpoint () and
192 memory_remove_breakpoint () are minor. All that the former does
193 that the latter does not is check to make sure that the breakpoint
194 location actually contains a breakpoint (trap instruction) prior
195 to attempting to write back the old contents. If it does contain
196 a trap instruction, we allow the old contents to be written back.
197 Otherwise, we silently do nothing.
199 The big question is whether memory_remove_breakpoint () should be
200 changed to have the same functionality. The downside is that more
201 traffic is generated for remote targets since we'll have an extra
202 fetch of a memory word each time a breakpoint is removed.
204 For the time being, we'll leave this self-modifying-code-friendly
205 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
206 else in the event that some other platform has similar needs with
207 regard to removing breakpoints in some potentially self modifying
210 ppc_linux_memory_remove_breakpoint (struct gdbarch
*gdbarch
,
211 struct bp_target_info
*bp_tgt
)
213 CORE_ADDR addr
= bp_tgt
->placed_address
;
214 const unsigned char *bp
;
217 gdb_byte old_contents
[BREAKPOINT_MAX
];
218 struct cleanup
*cleanup
;
220 /* Determine appropriate breakpoint contents and size for this address. */
221 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &bplen
);
223 error (_("Software breakpoints not implemented for this target."));
225 /* Make sure we see the memory breakpoints. */
226 cleanup
= make_show_memory_breakpoints_cleanup (1);
227 val
= target_read_memory (addr
, old_contents
, bplen
);
229 /* If our breakpoint is no longer at the address, this means that the
230 program modified the code on us, so it is wrong to put back the
232 if (val
== 0 && memcmp (bp
, old_contents
, bplen
) == 0)
233 val
= target_write_raw_memory (addr
, bp_tgt
->shadow_contents
, bplen
);
235 do_cleanups (cleanup
);
239 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
240 than the 32 bit SYSV R4 ABI structure return convention - all
241 structures, no matter their size, are put in memory. Vectors,
242 which were added later, do get returned in a register though. */
244 static enum return_value_convention
245 ppc_linux_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
246 struct type
*valtype
, struct regcache
*regcache
,
247 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
249 if ((TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
250 || TYPE_CODE (valtype
) == TYPE_CODE_UNION
)
251 && !((TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 8)
252 && TYPE_VECTOR (valtype
)))
253 return RETURN_VALUE_STRUCT_CONVENTION
;
255 return ppc_sysv_abi_return_value (gdbarch
, function
, valtype
, regcache
,
259 static struct core_regset_section ppc_linux_vsx_regset_sections
[] =
261 { ".reg", 48 * 4, "general-purpose" },
262 { ".reg2", 264, "floating-point" },
263 { ".reg-ppc-vmx", 544, "ppc Altivec" },
264 { ".reg-ppc-vsx", 256, "POWER7 VSX" },
268 static struct core_regset_section ppc_linux_vmx_regset_sections
[] =
270 { ".reg", 48 * 4, "general-purpose" },
271 { ".reg2", 264, "floating-point" },
272 { ".reg-ppc-vmx", 544, "ppc Altivec" },
276 static struct core_regset_section ppc_linux_fp_regset_sections
[] =
278 { ".reg", 48 * 4, "general-purpose" },
279 { ".reg2", 264, "floating-point" },
283 static struct core_regset_section ppc64_linux_vsx_regset_sections
[] =
285 { ".reg", 48 * 8, "general-purpose" },
286 { ".reg2", 264, "floating-point" },
287 { ".reg-ppc-vmx", 544, "ppc Altivec" },
288 { ".reg-ppc-vsx", 256, "POWER7 VSX" },
292 static struct core_regset_section ppc64_linux_vmx_regset_sections
[] =
294 { ".reg", 48 * 8, "general-purpose" },
295 { ".reg2", 264, "floating-point" },
296 { ".reg-ppc-vmx", 544, "ppc Altivec" },
300 static struct core_regset_section ppc64_linux_fp_regset_sections
[] =
302 { ".reg", 48 * 8, "general-purpose" },
303 { ".reg2", 264, "floating-point" },
307 /* PLT stub in executable. */
308 static struct ppc_insn_pattern powerpc32_plt_stub
[] =
310 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
311 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
312 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
313 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
317 /* PLT stub in shared library. */
318 static struct ppc_insn_pattern powerpc32_plt_stub_so
[] =
320 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
321 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
322 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
323 { 0xffffffff, 0x60000000, 0 }, /* nop */
326 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub)
328 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
329 section. For secure PLT, stub is in .text and we need to check
330 instruction patterns. */
333 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc
)
335 struct bound_minimal_symbol sym
;
337 /* Check whether PC is in the dynamic linker. This also checks
338 whether it is in the .plt section, used by non-PIC executables. */
339 if (svr4_in_dynsym_resolve_code (pc
))
342 /* Check if we are in the resolver. */
343 sym
= lookup_minimal_symbol_by_pc (pc
);
344 if (sym
.minsym
!= NULL
345 && (strcmp (SYMBOL_LINKAGE_NAME (sym
.minsym
), "__glink") == 0
346 || strcmp (SYMBOL_LINKAGE_NAME (sym
.minsym
),
347 "__glink_PLTresolve") == 0))
353 /* Follow PLT stub to actual routine. */
356 ppc_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
358 unsigned int insnbuf
[POWERPC32_PLT_STUB_LEN
];
359 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
360 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
361 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
362 CORE_ADDR target
= 0;
364 if (ppc_insns_match_pattern (frame
, pc
, powerpc32_plt_stub
, insnbuf
))
369 Branch target is in r11. */
371 target
= (ppc_insn_d_field (insnbuf
[0]) << 16)
372 | ppc_insn_d_field (insnbuf
[1]);
373 target
= read_memory_unsigned_integer (target
, 4, byte_order
);
376 if (ppc_insns_match_pattern (frame
, pc
, powerpc32_plt_stub_so
, insnbuf
))
380 Branch target is in r11. */
382 target
= get_frame_register_unsigned (frame
, tdep
->ppc_gp0_regnum
+ 30)
383 + ppc_insn_d_field (insnbuf
[0]);
384 target
= read_memory_unsigned_integer (target
, 4, byte_order
);
390 /* Wrappers to handle Linux-only registers. */
393 ppc_linux_supply_gregset (const struct regset
*regset
,
394 struct regcache
*regcache
,
395 int regnum
, const void *gregs
, size_t len
)
397 const struct ppc_reg_offsets
*offsets
= regset
->descr
;
399 ppc_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
401 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache
)))
403 /* "orig_r3" is stored 2 slots after "pc". */
404 if (regnum
== -1 || regnum
== PPC_ORIG_R3_REGNUM
)
405 ppc_supply_reg (regcache
, PPC_ORIG_R3_REGNUM
, gregs
,
406 offsets
->pc_offset
+ 2 * offsets
->gpr_size
,
409 /* "trap" is stored 8 slots after "pc". */
410 if (regnum
== -1 || regnum
== PPC_TRAP_REGNUM
)
411 ppc_supply_reg (regcache
, PPC_TRAP_REGNUM
, gregs
,
412 offsets
->pc_offset
+ 8 * offsets
->gpr_size
,
418 ppc_linux_collect_gregset (const struct regset
*regset
,
419 const struct regcache
*regcache
,
420 int regnum
, void *gregs
, size_t len
)
422 const struct ppc_reg_offsets
*offsets
= regset
->descr
;
424 /* Clear areas in the linux gregset not written elsewhere. */
426 memset (gregs
, 0, len
);
428 ppc_collect_gregset (regset
, regcache
, regnum
, gregs
, len
);
430 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache
)))
432 /* "orig_r3" is stored 2 slots after "pc". */
433 if (regnum
== -1 || regnum
== PPC_ORIG_R3_REGNUM
)
434 ppc_collect_reg (regcache
, PPC_ORIG_R3_REGNUM
, gregs
,
435 offsets
->pc_offset
+ 2 * offsets
->gpr_size
,
438 /* "trap" is stored 8 slots after "pc". */
439 if (regnum
== -1 || regnum
== PPC_TRAP_REGNUM
)
440 ppc_collect_reg (regcache
, PPC_TRAP_REGNUM
, gregs
,
441 offsets
->pc_offset
+ 8 * offsets
->gpr_size
,
446 /* Regset descriptions. */
447 static const struct ppc_reg_offsets ppc32_linux_reg_offsets
=
449 /* General-purpose registers. */
450 /* .r0_offset = */ 0,
453 /* .pc_offset = */ 128,
454 /* .ps_offset = */ 132,
455 /* .cr_offset = */ 152,
456 /* .lr_offset = */ 144,
457 /* .ctr_offset = */ 140,
458 /* .xer_offset = */ 148,
459 /* .mq_offset = */ 156,
461 /* Floating-point registers. */
462 /* .f0_offset = */ 0,
463 /* .fpscr_offset = */ 256,
464 /* .fpscr_size = */ 8,
466 /* AltiVec registers. */
467 /* .vr0_offset = */ 0,
468 /* .vscr_offset = */ 512 + 12,
469 /* .vrsave_offset = */ 528
472 static const struct ppc_reg_offsets ppc64_linux_reg_offsets
=
474 /* General-purpose registers. */
475 /* .r0_offset = */ 0,
478 /* .pc_offset = */ 256,
479 /* .ps_offset = */ 264,
480 /* .cr_offset = */ 304,
481 /* .lr_offset = */ 288,
482 /* .ctr_offset = */ 280,
483 /* .xer_offset = */ 296,
484 /* .mq_offset = */ 312,
486 /* Floating-point registers. */
487 /* .f0_offset = */ 0,
488 /* .fpscr_offset = */ 256,
489 /* .fpscr_size = */ 8,
491 /* AltiVec registers. */
492 /* .vr0_offset = */ 0,
493 /* .vscr_offset = */ 512 + 12,
494 /* .vrsave_offset = */ 528
497 static const struct regset ppc32_linux_gregset
= {
498 &ppc32_linux_reg_offsets
,
499 ppc_linux_supply_gregset
,
500 ppc_linux_collect_gregset
,
504 static const struct regset ppc64_linux_gregset
= {
505 &ppc64_linux_reg_offsets
,
506 ppc_linux_supply_gregset
,
507 ppc_linux_collect_gregset
,
511 static const struct regset ppc32_linux_fpregset
= {
512 &ppc32_linux_reg_offsets
,
514 ppc_collect_fpregset
,
518 static const struct regset ppc32_linux_vrregset
= {
519 &ppc32_linux_reg_offsets
,
521 ppc_collect_vrregset
,
525 static const struct regset ppc32_linux_vsxregset
= {
526 &ppc32_linux_reg_offsets
,
527 ppc_supply_vsxregset
,
528 ppc_collect_vsxregset
,
532 const struct regset
*
533 ppc_linux_gregset (int wordsize
)
535 return wordsize
== 8 ? &ppc64_linux_gregset
: &ppc32_linux_gregset
;
538 const struct regset
*
539 ppc_linux_fpregset (void)
541 return &ppc32_linux_fpregset
;
544 static const struct regset
*
545 ppc_linux_regset_from_core_section (struct gdbarch
*core_arch
,
546 const char *sect_name
, size_t sect_size
)
548 struct gdbarch_tdep
*tdep
= gdbarch_tdep (core_arch
);
549 if (strcmp (sect_name
, ".reg") == 0)
551 if (tdep
->wordsize
== 4)
552 return &ppc32_linux_gregset
;
554 return &ppc64_linux_gregset
;
556 if (strcmp (sect_name
, ".reg2") == 0)
557 return &ppc32_linux_fpregset
;
558 if (strcmp (sect_name
, ".reg-ppc-vmx") == 0)
559 return &ppc32_linux_vrregset
;
560 if (strcmp (sect_name
, ".reg-ppc-vsx") == 0)
561 return &ppc32_linux_vsxregset
;
566 ppc_linux_sigtramp_cache (struct frame_info
*this_frame
,
567 struct trad_frame_cache
*this_cache
,
568 CORE_ADDR func
, LONGEST offset
,
576 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
577 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
578 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
580 base
= get_frame_register_unsigned (this_frame
,
581 gdbarch_sp_regnum (gdbarch
));
582 if (bias
> 0 && get_frame_pc (this_frame
) != func
)
583 /* See below, some signal trampolines increment the stack as their
584 first instruction, need to compensate for that. */
587 /* Find the address of the register buffer pointer. */
588 regs
= base
+ offset
;
589 /* Use that to find the address of the corresponding register
591 gpregs
= read_memory_unsigned_integer (regs
, tdep
->wordsize
, byte_order
);
592 fpregs
= gpregs
+ 48 * tdep
->wordsize
;
594 /* General purpose. */
595 for (i
= 0; i
< 32; i
++)
597 int regnum
= i
+ tdep
->ppc_gp0_regnum
;
598 trad_frame_set_reg_addr (this_cache
,
599 regnum
, gpregs
+ i
* tdep
->wordsize
);
601 trad_frame_set_reg_addr (this_cache
,
602 gdbarch_pc_regnum (gdbarch
),
603 gpregs
+ 32 * tdep
->wordsize
);
604 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_ctr_regnum
,
605 gpregs
+ 35 * tdep
->wordsize
);
606 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_lr_regnum
,
607 gpregs
+ 36 * tdep
->wordsize
);
608 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_xer_regnum
,
609 gpregs
+ 37 * tdep
->wordsize
);
610 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_cr_regnum
,
611 gpregs
+ 38 * tdep
->wordsize
);
613 if (ppc_linux_trap_reg_p (gdbarch
))
615 trad_frame_set_reg_addr (this_cache
, PPC_ORIG_R3_REGNUM
,
616 gpregs
+ 34 * tdep
->wordsize
);
617 trad_frame_set_reg_addr (this_cache
, PPC_TRAP_REGNUM
,
618 gpregs
+ 40 * tdep
->wordsize
);
621 if (ppc_floating_point_unit_p (gdbarch
))
623 /* Floating point registers. */
624 for (i
= 0; i
< 32; i
++)
626 int regnum
= i
+ gdbarch_fp0_regnum (gdbarch
);
627 trad_frame_set_reg_addr (this_cache
, regnum
,
628 fpregs
+ i
* tdep
->wordsize
);
630 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_fpscr_regnum
,
631 fpregs
+ 32 * tdep
->wordsize
);
633 trad_frame_set_id (this_cache
, frame_id_build (base
, func
));
637 ppc32_linux_sigaction_cache_init (const struct tramp_frame
*self
,
638 struct frame_info
*this_frame
,
639 struct trad_frame_cache
*this_cache
,
642 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
643 0xd0 /* Offset to ucontext_t. */
644 + 0x30 /* Offset to .reg. */,
649 ppc64_linux_sigaction_cache_init (const struct tramp_frame
*self
,
650 struct frame_info
*this_frame
,
651 struct trad_frame_cache
*this_cache
,
654 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
655 0x80 /* Offset to ucontext_t. */
656 + 0xe0 /* Offset to .reg. */,
661 ppc32_linux_sighandler_cache_init (const struct tramp_frame
*self
,
662 struct frame_info
*this_frame
,
663 struct trad_frame_cache
*this_cache
,
666 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
667 0x40 /* Offset to ucontext_t. */
668 + 0x1c /* Offset to .reg. */,
673 ppc64_linux_sighandler_cache_init (const struct tramp_frame
*self
,
674 struct frame_info
*this_frame
,
675 struct trad_frame_cache
*this_cache
,
678 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
679 0x80 /* Offset to struct sigcontext. */
680 + 0x38 /* Offset to .reg. */,
684 static struct tramp_frame ppc32_linux_sigaction_tramp_frame
= {
688 { 0x380000ac, -1 }, /* li r0, 172 */
689 { 0x44000002, -1 }, /* sc */
690 { TRAMP_SENTINEL_INSN
},
692 ppc32_linux_sigaction_cache_init
694 static struct tramp_frame ppc64_linux_sigaction_tramp_frame
= {
698 { 0x38210080, -1 }, /* addi r1,r1,128 */
699 { 0x380000ac, -1 }, /* li r0, 172 */
700 { 0x44000002, -1 }, /* sc */
701 { TRAMP_SENTINEL_INSN
},
703 ppc64_linux_sigaction_cache_init
705 static struct tramp_frame ppc32_linux_sighandler_tramp_frame
= {
709 { 0x38000077, -1 }, /* li r0,119 */
710 { 0x44000002, -1 }, /* sc */
711 { TRAMP_SENTINEL_INSN
},
713 ppc32_linux_sighandler_cache_init
715 static struct tramp_frame ppc64_linux_sighandler_tramp_frame
= {
719 { 0x38210080, -1 }, /* addi r1,r1,128 */
720 { 0x38000077, -1 }, /* li r0,119 */
721 { 0x44000002, -1 }, /* sc */
722 { TRAMP_SENTINEL_INSN
},
724 ppc64_linux_sighandler_cache_init
728 /* Address to use for displaced stepping. When debugging a stand-alone
729 SPU executable, entry_point_address () will point to an SPU local-store
730 address and is thus not usable as displaced stepping location. We use
731 the auxiliary vector to determine the PowerPC-side entry point address
734 static CORE_ADDR ppc_linux_entry_point_addr
= 0;
737 ppc_linux_inferior_created (struct target_ops
*target
, int from_tty
)
739 ppc_linux_entry_point_addr
= 0;
743 ppc_linux_displaced_step_location (struct gdbarch
*gdbarch
)
745 if (ppc_linux_entry_point_addr
== 0)
749 /* Determine entry point from target auxiliary vector. */
750 if (target_auxv_search (¤t_target
, AT_ENTRY
, &addr
) <= 0)
751 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
753 /* Make certain that the address points at real code, and not a
754 function descriptor. */
755 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
758 /* Inferior calls also use the entry point as a breakpoint location.
759 We don't want displaced stepping to interfere with those
760 breakpoints, so leave space. */
761 ppc_linux_entry_point_addr
= addr
+ 2 * PPC_INSN_SIZE
;
764 return ppc_linux_entry_point_addr
;
768 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
770 ppc_linux_trap_reg_p (struct gdbarch
*gdbarch
)
772 /* If we do not have a target description with registers, then
773 the special registers will not be included in the register set. */
774 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
777 /* If we do, then it is safe to check the size. */
778 return register_size (gdbarch
, PPC_ORIG_R3_REGNUM
) > 0
779 && register_size (gdbarch
, PPC_TRAP_REGNUM
) > 0;
782 /* Return the current system call's number present in the
783 r0 register. When the function fails, it returns -1. */
785 ppc_linux_get_syscall_number (struct gdbarch
*gdbarch
,
788 struct regcache
*regcache
= get_thread_regcache (ptid
);
789 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
790 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
791 struct cleanup
*cleanbuf
;
792 /* The content of a register */
797 /* Make sure we're in a 32- or 64-bit machine */
798 gdb_assert (tdep
->wordsize
== 4 || tdep
->wordsize
== 8);
800 buf
= (gdb_byte
*) xmalloc (tdep
->wordsize
* sizeof (gdb_byte
));
802 cleanbuf
= make_cleanup (xfree
, buf
);
804 /* Getting the system call number from the register.
805 When dealing with PowerPC architecture, this information
806 is stored at 0th register. */
807 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
, buf
);
809 ret
= extract_signed_integer (buf
, tdep
->wordsize
, byte_order
);
810 do_cleanups (cleanbuf
);
816 ppc_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
818 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
820 regcache_cooked_write_unsigned (regcache
, gdbarch_pc_regnum (gdbarch
), pc
);
822 /* Set special TRAP register to -1 to prevent the kernel from
823 messing with the PC we just installed, if we happen to be
824 within an interrupted system call that the kernel wants to
827 Note that after we return from the dummy call, the TRAP and
828 ORIG_R3 registers will be automatically restored, and the
829 kernel continues to restart the system call at this point. */
830 if (ppc_linux_trap_reg_p (gdbarch
))
831 regcache_cooked_write_unsigned (regcache
, PPC_TRAP_REGNUM
, -1);
835 ppc_linux_spu_section (bfd
*abfd
, asection
*asect
, void *user_data
)
837 return strncmp (bfd_section_name (abfd
, asect
), "SPU/", 4) == 0;
840 static const struct target_desc
*
841 ppc_linux_core_read_description (struct gdbarch
*gdbarch
,
842 struct target_ops
*target
,
845 asection
*cell
= bfd_sections_find_if (abfd
, ppc_linux_spu_section
, NULL
);
846 asection
*altivec
= bfd_get_section_by_name (abfd
, ".reg-ppc-vmx");
847 asection
*vsx
= bfd_get_section_by_name (abfd
, ".reg-ppc-vsx");
848 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
852 switch (bfd_section_size (abfd
, section
))
856 return tdesc_powerpc_cell32l
;
858 return tdesc_powerpc_vsx32l
;
860 return tdesc_powerpc_altivec32l
;
862 return tdesc_powerpc_32l
;
866 return tdesc_powerpc_cell64l
;
868 return tdesc_powerpc_vsx64l
;
870 return tdesc_powerpc_altivec64l
;
872 return tdesc_powerpc_64l
;
879 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
883 ppc_stap_is_single_operand (struct gdbarch
*gdbarch
, const char *s
)
885 return (*s
== 'i' /* Literal number. */
886 || (isdigit (*s
) && s
[1] == '('
887 && isdigit (s
[2])) /* Displacement. */
888 || (*s
== '(' && isdigit (s
[1])) /* Register indirection. */
889 || isdigit (*s
)); /* Register value. */
892 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
896 ppc_stap_parse_special_token (struct gdbarch
*gdbarch
,
897 struct stap_parse_info
*p
)
899 if (isdigit (*p
->arg
))
901 /* This temporary pointer is needed because we have to do a lookahead.
902 We could be dealing with a register displacement, and in such case
903 we would not need to do anything. */
904 const char *s
= p
->arg
;
914 /* It is a register displacement indeed. Returning 0 means we are
915 deferring the treatment of this case to the generic parser. */
920 regname
= alloca (len
+ 2);
923 strncpy (regname
+ 1, p
->arg
, len
);
927 if (user_reg_map_name_to_regnum (gdbarch
, regname
, len
) == -1)
928 error (_("Invalid register name `%s' on expression `%s'."),
929 regname
, p
->saved_arg
);
931 write_exp_elt_opcode (OP_REGISTER
);
934 write_exp_string (str
);
935 write_exp_elt_opcode (OP_REGISTER
);
941 /* All the other tokens should be handled correctly by the generic
949 /* Cell/B.E. active SPE context tracking support. */
951 static struct objfile
*spe_context_objfile
= NULL
;
952 static CORE_ADDR spe_context_lm_addr
= 0;
953 static CORE_ADDR spe_context_offset
= 0;
955 static ptid_t spe_context_cache_ptid
;
956 static CORE_ADDR spe_context_cache_address
;
958 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
959 to track whether we've loaded a version of libspe2 (as static or dynamic
960 library) that provides the __spe_current_active_context variable. */
962 ppc_linux_spe_context_lookup (struct objfile
*objfile
)
964 struct minimal_symbol
*sym
;
968 spe_context_objfile
= NULL
;
969 spe_context_lm_addr
= 0;
970 spe_context_offset
= 0;
971 spe_context_cache_ptid
= minus_one_ptid
;
972 spe_context_cache_address
= 0;
976 sym
= lookup_minimal_symbol ("__spe_current_active_context", NULL
, objfile
);
979 spe_context_objfile
= objfile
;
980 spe_context_lm_addr
= svr4_fetch_objfile_link_map (objfile
);
981 spe_context_offset
= SYMBOL_VALUE_ADDRESS (sym
);
982 spe_context_cache_ptid
= minus_one_ptid
;
983 spe_context_cache_address
= 0;
989 ppc_linux_spe_context_inferior_created (struct target_ops
*t
, int from_tty
)
991 struct objfile
*objfile
;
993 ppc_linux_spe_context_lookup (NULL
);
994 ALL_OBJFILES (objfile
)
995 ppc_linux_spe_context_lookup (objfile
);
999 ppc_linux_spe_context_solib_loaded (struct so_list
*so
)
1001 if (strstr (so
->so_original_name
, "/libspe") != NULL
)
1003 solib_read_symbols (so
, 0);
1004 ppc_linux_spe_context_lookup (so
->objfile
);
1009 ppc_linux_spe_context_solib_unloaded (struct so_list
*so
)
1011 if (so
->objfile
== spe_context_objfile
)
1012 ppc_linux_spe_context_lookup (NULL
);
1015 /* Retrieve contents of the N'th element in the current thread's
1016 linked SPE context list into ID and NPC. Return the address of
1017 said context element, or 0 if not found. */
1019 ppc_linux_spe_context (int wordsize
, enum bfd_endian byte_order
,
1020 int n
, int *id
, unsigned int *npc
)
1022 CORE_ADDR spe_context
= 0;
1026 /* Quick exit if we have not found __spe_current_active_context. */
1027 if (!spe_context_objfile
)
1030 /* Look up cached address of thread-local variable. */
1031 if (!ptid_equal (spe_context_cache_ptid
, inferior_ptid
))
1033 struct target_ops
*target
= ¤t_target
;
1034 volatile struct gdb_exception ex
;
1036 while (target
&& !target
->to_get_thread_local_address
)
1037 target
= find_target_beneath (target
);
1041 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1043 /* We do not call target_translate_tls_address here, because
1044 svr4_fetch_objfile_link_map may invalidate the frame chain,
1045 which must not do while inside a frame sniffer.
1047 Instead, we have cached the lm_addr value, and use that to
1048 directly call the target's to_get_thread_local_address. */
1049 spe_context_cache_address
1050 = target
->to_get_thread_local_address (target
, inferior_ptid
,
1051 spe_context_lm_addr
,
1052 spe_context_offset
);
1053 spe_context_cache_ptid
= inferior_ptid
;
1060 /* Read variable value. */
1061 if (target_read_memory (spe_context_cache_address
, buf
, wordsize
) == 0)
1062 spe_context
= extract_unsigned_integer (buf
, wordsize
, byte_order
);
1064 /* Cyle through to N'th linked list element. */
1065 for (i
= 0; i
< n
&& spe_context
; i
++)
1066 if (target_read_memory (spe_context
+ align_up (12, wordsize
),
1067 buf
, wordsize
) == 0)
1068 spe_context
= extract_unsigned_integer (buf
, wordsize
, byte_order
);
1072 /* Read current context. */
1074 && target_read_memory (spe_context
, buf
, 12) != 0)
1077 /* Extract data elements. */
1081 *id
= extract_signed_integer (buf
, 4, byte_order
);
1083 *npc
= extract_unsigned_integer (buf
+ 4, 4, byte_order
);
1090 /* Cell/B.E. cross-architecture unwinder support. */
1092 struct ppu2spu_cache
1094 struct frame_id frame_id
;
1095 struct regcache
*regcache
;
1098 static struct gdbarch
*
1099 ppu2spu_prev_arch (struct frame_info
*this_frame
, void **this_cache
)
1101 struct ppu2spu_cache
*cache
= *this_cache
;
1102 return get_regcache_arch (cache
->regcache
);
1106 ppu2spu_this_id (struct frame_info
*this_frame
,
1107 void **this_cache
, struct frame_id
*this_id
)
1109 struct ppu2spu_cache
*cache
= *this_cache
;
1110 *this_id
= cache
->frame_id
;
1113 static struct value
*
1114 ppu2spu_prev_register (struct frame_info
*this_frame
,
1115 void **this_cache
, int regnum
)
1117 struct ppu2spu_cache
*cache
= *this_cache
;
1118 struct gdbarch
*gdbarch
= get_regcache_arch (cache
->regcache
);
1121 buf
= alloca (register_size (gdbarch
, regnum
));
1123 if (regnum
< gdbarch_num_regs (gdbarch
))
1124 regcache_raw_read (cache
->regcache
, regnum
, buf
);
1126 gdbarch_pseudo_register_read (gdbarch
, cache
->regcache
, regnum
, buf
);
1128 return frame_unwind_got_bytes (this_frame
, regnum
, buf
);
1133 struct gdbarch
*gdbarch
;
1136 gdb_byte gprs
[128*16];
1140 ppu2spu_unwind_register (void *src
, int regnum
, gdb_byte
*buf
)
1142 struct ppu2spu_data
*data
= src
;
1143 enum bfd_endian byte_order
= gdbarch_byte_order (data
->gdbarch
);
1145 if (regnum
>= 0 && regnum
< SPU_NUM_GPRS
)
1146 memcpy (buf
, data
->gprs
+ 16*regnum
, 16);
1147 else if (regnum
== SPU_ID_REGNUM
)
1148 store_unsigned_integer (buf
, 4, byte_order
, data
->id
);
1149 else if (regnum
== SPU_PC_REGNUM
)
1150 store_unsigned_integer (buf
, 4, byte_order
, data
->npc
);
1152 return REG_UNAVAILABLE
;
1158 ppu2spu_sniffer (const struct frame_unwind
*self
,
1159 struct frame_info
*this_frame
, void **this_prologue_cache
)
1161 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1162 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1163 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1164 struct ppu2spu_data data
;
1165 struct frame_info
*fi
;
1166 CORE_ADDR base
, func
, backchain
, spe_context
;
1170 /* Count the number of SPU contexts already in the frame chain. */
1171 for (fi
= get_next_frame (this_frame
); fi
; fi
= get_next_frame (fi
))
1172 if (get_frame_type (fi
) == ARCH_FRAME
1173 && gdbarch_bfd_arch_info (get_frame_arch (fi
))->arch
== bfd_arch_spu
)
1176 base
= get_frame_sp (this_frame
);
1177 func
= get_frame_pc (this_frame
);
1178 if (target_read_memory (base
, buf
, tdep
->wordsize
))
1180 backchain
= extract_unsigned_integer (buf
, tdep
->wordsize
, byte_order
);
1182 spe_context
= ppc_linux_spe_context (tdep
->wordsize
, byte_order
,
1183 n
, &data
.id
, &data
.npc
);
1184 if (spe_context
&& base
<= spe_context
&& spe_context
< backchain
)
1188 /* Find gdbarch for SPU. */
1189 struct gdbarch_info info
;
1190 gdbarch_info_init (&info
);
1191 info
.bfd_arch_info
= bfd_lookup_arch (bfd_arch_spu
, bfd_mach_spu
);
1192 info
.byte_order
= BFD_ENDIAN_BIG
;
1193 info
.osabi
= GDB_OSABI_LINUX
;
1194 info
.tdep_info
= (void *) &data
.id
;
1195 data
.gdbarch
= gdbarch_find_by_info (info
);
1199 xsnprintf (annex
, sizeof annex
, "%d/regs", data
.id
);
1200 if (target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1201 data
.gprs
, 0, sizeof data
.gprs
)
1202 == sizeof data
.gprs
)
1204 struct ppu2spu_cache
*cache
1205 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache
);
1207 struct address_space
*aspace
= get_frame_address_space (this_frame
);
1208 struct regcache
*regcache
= regcache_xmalloc (data
.gdbarch
, aspace
);
1209 struct cleanup
*cleanups
= make_cleanup_regcache_xfree (regcache
);
1210 regcache_save (regcache
, ppu2spu_unwind_register
, &data
);
1211 discard_cleanups (cleanups
);
1213 cache
->frame_id
= frame_id_build (base
, func
);
1214 cache
->regcache
= regcache
;
1215 *this_prologue_cache
= cache
;
1224 ppu2spu_dealloc_cache (struct frame_info
*self
, void *this_cache
)
1226 struct ppu2spu_cache
*cache
= this_cache
;
1227 regcache_xfree (cache
->regcache
);
1230 static const struct frame_unwind ppu2spu_unwind
= {
1232 default_frame_unwind_stop_reason
,
1234 ppu2spu_prev_register
,
1237 ppu2spu_dealloc_cache
,
1243 ppc_linux_init_abi (struct gdbarch_info info
,
1244 struct gdbarch
*gdbarch
)
1246 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1247 struct tdesc_arch_data
*tdesc_data
= (void *) info
.tdep_info
;
1249 linux_init_abi (info
, gdbarch
);
1251 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1252 128-bit, they are IBM long double, not IEEE quad long double as
1253 in the System V ABI PowerPC Processor Supplement. We can safely
1254 let them default to 128-bit, since the debug info will give the
1255 size of type actually used in each case. */
1256 set_gdbarch_long_double_bit (gdbarch
, 16 * TARGET_CHAR_BIT
);
1257 set_gdbarch_long_double_format (gdbarch
, floatformats_ibm_long_double
);
1259 /* Handle inferior calls during interrupted system calls. */
1260 set_gdbarch_write_pc (gdbarch
, ppc_linux_write_pc
);
1262 /* Get the syscall number from the arch's register. */
1263 set_gdbarch_get_syscall_number (gdbarch
, ppc_linux_get_syscall_number
);
1265 /* SystemTap functions. */
1266 set_gdbarch_stap_integer_prefix (gdbarch
, "i");
1267 set_gdbarch_stap_register_indirection_prefix (gdbarch
, "(");
1268 set_gdbarch_stap_register_indirection_suffix (gdbarch
, ")");
1269 set_gdbarch_stap_gdb_register_prefix (gdbarch
, "r");
1270 set_gdbarch_stap_is_single_operand (gdbarch
, ppc_stap_is_single_operand
);
1271 set_gdbarch_stap_parse_special_token (gdbarch
,
1272 ppc_stap_parse_special_token
);
1274 if (tdep
->wordsize
== 4)
1276 /* Until November 2001, gcc did not comply with the 32 bit SysV
1277 R4 ABI requirement that structures less than or equal to 8
1278 bytes should be returned in registers. Instead GCC was using
1279 the AIX/PowerOpen ABI - everything returned in memory
1280 (well ignoring vectors that is). When this was corrected, it
1281 wasn't fixed for GNU/Linux native platform. Use the
1282 PowerOpen struct convention. */
1283 set_gdbarch_return_value (gdbarch
, ppc_linux_return_value
);
1285 set_gdbarch_memory_remove_breakpoint (gdbarch
,
1286 ppc_linux_memory_remove_breakpoint
);
1288 /* Shared library handling. */
1289 set_gdbarch_skip_trampoline_code (gdbarch
, ppc_skip_trampoline_code
);
1290 set_solib_svr4_fetch_link_map_offsets
1291 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1293 /* Setting the correct XML syscall filename. */
1294 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC
);
1297 tramp_frame_prepend_unwinder (gdbarch
,
1298 &ppc32_linux_sigaction_tramp_frame
);
1299 tramp_frame_prepend_unwinder (gdbarch
,
1300 &ppc32_linux_sighandler_tramp_frame
);
1302 /* BFD target for core files. */
1303 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
1304 set_gdbarch_gcore_bfd_target (gdbarch
, "elf32-powerpcle");
1306 set_gdbarch_gcore_bfd_target (gdbarch
, "elf32-powerpc");
1308 /* Supported register sections. */
1309 if (tdesc_find_feature (info
.target_desc
,
1310 "org.gnu.gdb.power.vsx"))
1311 set_gdbarch_core_regset_sections (gdbarch
,
1312 ppc_linux_vsx_regset_sections
);
1313 else if (tdesc_find_feature (info
.target_desc
,
1314 "org.gnu.gdb.power.altivec"))
1315 set_gdbarch_core_regset_sections (gdbarch
,
1316 ppc_linux_vmx_regset_sections
);
1318 set_gdbarch_core_regset_sections (gdbarch
,
1319 ppc_linux_fp_regset_sections
);
1321 if (powerpc_so_ops
.in_dynsym_resolve_code
== NULL
)
1323 powerpc_so_ops
= svr4_so_ops
;
1324 /* Override dynamic resolve function. */
1325 powerpc_so_ops
.in_dynsym_resolve_code
=
1326 powerpc_linux_in_dynsym_resolve_code
;
1328 set_solib_ops (gdbarch
, &powerpc_so_ops
);
1330 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
1333 if (tdep
->wordsize
== 8)
1335 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1336 function descriptors). */
1337 set_gdbarch_convert_from_func_ptr_addr
1338 (gdbarch
, ppc64_convert_from_func_ptr_addr
);
1340 set_gdbarch_elf_make_msymbol_special (gdbarch
,
1341 ppc64_elf_make_msymbol_special
);
1343 /* Shared library handling. */
1344 set_gdbarch_skip_trampoline_code (gdbarch
, ppc64_skip_trampoline_code
);
1345 set_solib_svr4_fetch_link_map_offsets
1346 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
1348 /* Setting the correct XML syscall filename. */
1349 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64
);
1352 tramp_frame_prepend_unwinder (gdbarch
,
1353 &ppc64_linux_sigaction_tramp_frame
);
1354 tramp_frame_prepend_unwinder (gdbarch
,
1355 &ppc64_linux_sighandler_tramp_frame
);
1357 /* BFD target for core files. */
1358 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
1359 set_gdbarch_gcore_bfd_target (gdbarch
, "elf64-powerpcle");
1361 set_gdbarch_gcore_bfd_target (gdbarch
, "elf64-powerpc");
1363 /* Supported register sections. */
1364 if (tdesc_find_feature (info
.target_desc
,
1365 "org.gnu.gdb.power.vsx"))
1366 set_gdbarch_core_regset_sections (gdbarch
,
1367 ppc64_linux_vsx_regset_sections
);
1368 else if (tdesc_find_feature (info
.target_desc
,
1369 "org.gnu.gdb.power.altivec"))
1370 set_gdbarch_core_regset_sections (gdbarch
,
1371 ppc64_linux_vmx_regset_sections
);
1373 set_gdbarch_core_regset_sections (gdbarch
,
1374 ppc64_linux_fp_regset_sections
);
1377 /* PPC32 uses a different prpsinfo32 compared to most other Linux
1379 if (tdep
->wordsize
== 4)
1380 set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch
,
1381 elfcore_write_ppc_linux_prpsinfo32
);
1383 set_gdbarch_regset_from_core_section (gdbarch
,
1384 ppc_linux_regset_from_core_section
);
1385 set_gdbarch_core_read_description (gdbarch
, ppc_linux_core_read_description
);
1387 /* Enable TLS support. */
1388 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
1389 svr4_fetch_objfile_link_map
);
1393 const struct tdesc_feature
*feature
;
1395 /* If we have target-described registers, then we can safely
1396 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1397 (whether they are described or not). */
1398 gdb_assert (gdbarch_num_regs (gdbarch
) <= PPC_ORIG_R3_REGNUM
);
1399 set_gdbarch_num_regs (gdbarch
, PPC_TRAP_REGNUM
+ 1);
1401 /* If they are present, then assign them to the reserved number. */
1402 feature
= tdesc_find_feature (info
.target_desc
,
1403 "org.gnu.gdb.power.linux");
1404 if (feature
!= NULL
)
1406 tdesc_numbered_register (feature
, tdesc_data
,
1407 PPC_ORIG_R3_REGNUM
, "orig_r3");
1408 tdesc_numbered_register (feature
, tdesc_data
,
1409 PPC_TRAP_REGNUM
, "trap");
1413 /* Enable Cell/B.E. if supported by the target. */
1414 if (tdesc_compatible_p (info
.target_desc
,
1415 bfd_lookup_arch (bfd_arch_spu
, bfd_mach_spu
)))
1417 /* Cell/B.E. multi-architecture support. */
1418 set_spu_solib_ops (gdbarch
);
1420 /* Cell/B.E. cross-architecture unwinder support. */
1421 frame_unwind_prepend_unwinder (gdbarch
, &ppu2spu_unwind
);
1423 /* The default displaced_step_at_entry_point doesn't work for
1424 SPU stand-alone executables. */
1425 set_gdbarch_displaced_step_location (gdbarch
,
1426 ppc_linux_displaced_step_location
);
1429 set_gdbarch_get_siginfo_type (gdbarch
, linux_get_siginfo_type
);
1432 /* Provide a prototype to silence -Wmissing-prototypes. */
1433 extern initialize_file_ftype _initialize_ppc_linux_tdep
;
1436 _initialize_ppc_linux_tdep (void)
1438 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1439 64-bit PowerPC, and the older rs6k. */
1440 gdbarch_register_osabi (bfd_arch_powerpc
, bfd_mach_ppc
, GDB_OSABI_LINUX
,
1441 ppc_linux_init_abi
);
1442 gdbarch_register_osabi (bfd_arch_powerpc
, bfd_mach_ppc64
, GDB_OSABI_LINUX
,
1443 ppc_linux_init_abi
);
1444 gdbarch_register_osabi (bfd_arch_rs6000
, bfd_mach_rs6k
, GDB_OSABI_LINUX
,
1445 ppc_linux_init_abi
);
1447 /* Attach to inferior_created observer. */
1448 observer_attach_inferior_created (ppc_linux_inferior_created
);
1450 /* Attach to observers to track __spe_current_active_context. */
1451 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created
);
1452 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded
);
1453 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded
);
1455 /* Initialize the Linux target descriptions. */
1456 initialize_tdesc_powerpc_32l ();
1457 initialize_tdesc_powerpc_altivec32l ();
1458 initialize_tdesc_powerpc_cell32l ();
1459 initialize_tdesc_powerpc_vsx32l ();
1460 initialize_tdesc_powerpc_isa205_32l ();
1461 initialize_tdesc_powerpc_isa205_altivec32l ();
1462 initialize_tdesc_powerpc_isa205_vsx32l ();
1463 initialize_tdesc_powerpc_64l ();
1464 initialize_tdesc_powerpc_altivec64l ();
1465 initialize_tdesc_powerpc_cell64l ();
1466 initialize_tdesc_powerpc_vsx64l ();
1467 initialize_tdesc_powerpc_isa205_64l ();
1468 initialize_tdesc_powerpc_isa205_altivec64l ();
1469 initialize_tdesc_powerpc_isa205_vsx64l ();
1470 initialize_tdesc_powerpc_e500l ();