1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 1986-2014 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 "elf/ppc64.h"
48 #include "exceptions.h"
49 #include "arch-utils.h"
51 #include "xml-syscall.h"
52 #include "linux-tdep.h"
54 #include "stap-probe.h"
57 #include "cli/cli-utils.h"
58 #include "parser-defs.h"
59 #include "user-regs.h"
61 #include "elf-bfd.h" /* for elfcore_write_* */
63 #include "features/rs6000/powerpc-32l.c"
64 #include "features/rs6000/powerpc-altivec32l.c"
65 #include "features/rs6000/powerpc-cell32l.c"
66 #include "features/rs6000/powerpc-vsx32l.c"
67 #include "features/rs6000/powerpc-isa205-32l.c"
68 #include "features/rs6000/powerpc-isa205-altivec32l.c"
69 #include "features/rs6000/powerpc-isa205-vsx32l.c"
70 #include "features/rs6000/powerpc-64l.c"
71 #include "features/rs6000/powerpc-altivec64l.c"
72 #include "features/rs6000/powerpc-cell64l.c"
73 #include "features/rs6000/powerpc-vsx64l.c"
74 #include "features/rs6000/powerpc-isa205-64l.c"
75 #include "features/rs6000/powerpc-isa205-altivec64l.c"
76 #include "features/rs6000/powerpc-isa205-vsx64l.c"
77 #include "features/rs6000/powerpc-e500l.c"
79 /* Shared library operations for PowerPC-Linux. */
80 static struct target_so_ops powerpc_so_ops;
82 /* The syscall's XML filename for PPC and PPC64. */
83 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
84 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
86 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
87 in much the same fashion as memory_remove_breakpoint in mem-break.c,
88 but is careful not to write back the previous contents if the code
89 in question has changed in between inserting the breakpoint and
92 Here is the problem that we're trying to solve...
94 Once upon a time, before introducing this function to remove
95 breakpoints from the inferior, setting a breakpoint on a shared
96 library function prior to running the program would not work
97 properly. In order to understand the problem, it is first
98 necessary to understand a little bit about dynamic linking on
101 A call to a shared library function is accomplished via a bl
102 (branch-and-link) instruction whose branch target is an entry
103 in the procedure linkage table (PLT). The PLT in the object
104 file is uninitialized. To gdb, prior to running the program, the
105 entries in the PLT are all zeros.
107 Once the program starts running, the shared libraries are loaded
108 and the procedure linkage table is initialized, but the entries in
109 the table are not (necessarily) resolved. Once a function is
110 actually called, the code in the PLT is hit and the function is
111 resolved. In order to better illustrate this, an example is in
112 order; the following example is from the gdb testsuite.
114 We start the program shmain.
116 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
119 We place two breakpoints, one on shr1 and the other on main.
122 Breakpoint 1 at 0x100409d4
124 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
126 Examine the instruction (and the immediatly following instruction)
127 upon which the breakpoint was placed. Note that the PLT entry
128 for shr1 contains zeros.
130 (gdb) x/2i 0x100409d4
131 0x100409d4 <shr1>: .long 0x0
132 0x100409d8 <shr1+4>: .long 0x0
137 Starting program: gdb.base/shmain
138 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
140 Breakpoint 2, main ()
141 at gdb.base/shmain.c:44
144 Examine the PLT again. Note that the loading of the shared
145 library has initialized the PLT to code which loads a constant
146 (which I think is an index into the GOT) into r11 and then
147 branchs a short distance to the code which actually does the
150 (gdb) x/2i 0x100409d4
151 0x100409d4 <shr1>: li r11,4
152 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
156 Breakpoint 1, shr1 (x=1)
157 at gdb.base/shr1.c:19
160 Now we've hit the breakpoint at shr1. (The breakpoint was
161 reset from the PLT entry to the actual shr1 function after the
162 shared library was loaded.) Note that the PLT entry has been
163 resolved to contain a branch that takes us directly to shr1.
164 (The real one, not the PLT entry.)
166 (gdb) x/2i 0x100409d4
167 0x100409d4 <shr1>: b 0xffaf76c <shr1>
168 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
170 The thing to note here is that the PLT entry for shr1 has been
173 Now the problem should be obvious. GDB places a breakpoint (a
174 trap instruction) on the zero value of the PLT entry for shr1.
175 Later on, after the shared library had been loaded and the PLT
176 initialized, GDB gets a signal indicating this fact and attempts
177 (as it always does when it stops) to remove all the breakpoints.
179 The breakpoint removal was causing the former contents (a zero
180 word) to be written back to the now initialized PLT entry thus
181 destroying a portion of the initialization that had occurred only a
182 short time ago. When execution continued, the zero word would be
183 executed as an instruction an illegal instruction trap was
184 generated instead. (0 is not a legal instruction.)
186 The fix for this problem was fairly straightforward. The function
187 memory_remove_breakpoint from mem-break.c was copied to this file,
188 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
189 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
192 The differences between ppc_linux_memory_remove_breakpoint () and
193 memory_remove_breakpoint () are minor. All that the former does
194 that the latter does not is check to make sure that the breakpoint
195 location actually contains a breakpoint (trap instruction) prior
196 to attempting to write back the old contents. If it does contain
197 a trap instruction, we allow the old contents to be written back.
198 Otherwise, we silently do nothing.
200 The big question is whether memory_remove_breakpoint () should be
201 changed to have the same functionality. The downside is that more
202 traffic is generated for remote targets since we'll have an extra
203 fetch of a memory word each time a breakpoint is removed.
205 For the time being, we'll leave this self-modifying-code-friendly
206 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
207 else in the event that some other platform has similar needs with
208 regard to removing breakpoints in some potentially self modifying
211 ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
212 struct bp_target_info *bp_tgt)
214 CORE_ADDR addr = bp_tgt->placed_address;
215 const unsigned char *bp;
218 gdb_byte old_contents[BREAKPOINT_MAX];
219 struct cleanup *cleanup;
221 /* Determine appropriate breakpoint contents and size for this address. */
222 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
224 error (_("Software breakpoints not implemented for this target."));
226 /* Make sure we see the memory breakpoints. */
227 cleanup = make_show_memory_breakpoints_cleanup (1);
228 val = target_read_memory (addr, old_contents, bplen);
230 /* If our breakpoint is no longer at the address, this means that the
231 program modified the code on us, so it is wrong to put back the
233 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
234 val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
236 do_cleanups (cleanup);
240 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
241 than the 32 bit SYSV R4 ABI structure return convention - all
242 structures, no matter their size, are put in memory. Vectors,
243 which were added later, do get returned in a register though. */
245 static enum return_value_convention
246 ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
247 struct type *valtype, struct regcache *regcache,
248 gdb_byte *readbuf, const gdb_byte *writebuf)
250 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
251 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
252 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
253 && TYPE_VECTOR (valtype)))
254 return RETURN_VALUE_STRUCT_CONVENTION;
256 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
260 static struct core_regset_section ppc_linux_vsx_regset_sections[] =
262 { ".reg", 48 * 4, "general-purpose" },
263 { ".reg2", 264, "floating-point" },
264 { ".reg-ppc-vmx", 544, "ppc Altivec" },
265 { ".reg-ppc-vsx", 256, "POWER7 VSX" },
269 static struct core_regset_section ppc_linux_vmx_regset_sections[] =
271 { ".reg", 48 * 4, "general-purpose" },
272 { ".reg2", 264, "floating-point" },
273 { ".reg-ppc-vmx", 544, "ppc Altivec" },
277 static struct core_regset_section ppc_linux_fp_regset_sections[] =
279 { ".reg", 48 * 4, "general-purpose" },
280 { ".reg2", 264, "floating-point" },
284 static struct core_regset_section ppc64_linux_vsx_regset_sections[] =
286 { ".reg", 48 * 8, "general-purpose" },
287 { ".reg2", 264, "floating-point" },
288 { ".reg-ppc-vmx", 544, "ppc Altivec" },
289 { ".reg-ppc-vsx", 256, "POWER7 VSX" },
293 static struct core_regset_section ppc64_linux_vmx_regset_sections[] =
295 { ".reg", 48 * 8, "general-purpose" },
296 { ".reg2", 264, "floating-point" },
297 { ".reg-ppc-vmx", 544, "ppc Altivec" },
301 static struct core_regset_section ppc64_linux_fp_regset_sections[] =
303 { ".reg", 48 * 8, "general-purpose" },
304 { ".reg2", 264, "floating-point" },
308 /* PLT stub in executable. */
309 static struct ppc_insn_pattern powerpc32_plt_stub[] =
311 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
312 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
313 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
314 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
318 /* PLT stub in shared library. */
319 static struct ppc_insn_pattern powerpc32_plt_stub_so[] =
321 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
322 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
323 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
324 { 0xffffffff, 0x60000000, 0 }, /* nop */
327 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub)
329 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
330 section. For secure PLT, stub is in .text and we need to check
331 instruction patterns. */
334 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
336 struct bound_minimal_symbol sym;
338 /* Check whether PC is in the dynamic linker. This also checks
339 whether it is in the .plt section, used by non-PIC executables. */
340 if (svr4_in_dynsym_resolve_code (pc))
343 /* Check if we are in the resolver. */
344 sym = lookup_minimal_symbol_by_pc (pc);
345 if (sym.minsym != NULL
346 && (strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0
347 || strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym),
348 "__glink_PLTresolve") == 0))
354 /* Follow PLT stub to actual routine. */
357 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
359 unsigned int insnbuf[POWERPC32_PLT_STUB_LEN];
360 struct gdbarch *gdbarch = get_frame_arch (frame);
361 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
362 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
363 CORE_ADDR target = 0;
365 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
370 Branch target is in r11. */
372 target = (ppc_insn_d_field (insnbuf[0]) << 16)
373 | ppc_insn_d_field (insnbuf[1]);
374 target = read_memory_unsigned_integer (target, 4, byte_order);
377 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, insnbuf))
381 Branch target is in r11. */
383 target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30)
384 + ppc_insn_d_field (insnbuf[0]);
385 target = read_memory_unsigned_integer (target, 4, byte_order);
391 /* Wrappers to handle Linux-only registers. */
394 ppc_linux_supply_gregset (const struct regset *regset,
395 struct regcache *regcache,
396 int regnum, const void *gregs, size_t len)
398 const struct ppc_reg_offsets *offsets = regset->descr;
400 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
402 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
404 /* "orig_r3" is stored 2 slots after "pc". */
405 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
406 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
407 offsets->pc_offset + 2 * offsets->gpr_size,
410 /* "trap" is stored 8 slots after "pc". */
411 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
412 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, gregs,
413 offsets->pc_offset + 8 * offsets->gpr_size,
419 ppc_linux_collect_gregset (const struct regset *regset,
420 const struct regcache *regcache,
421 int regnum, void *gregs, size_t len)
423 const struct ppc_reg_offsets *offsets = regset->descr;
425 /* Clear areas in the linux gregset not written elsewhere. */
427 memset (gregs, 0, len);
429 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
431 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
433 /* "orig_r3" is stored 2 slots after "pc". */
434 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
435 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
436 offsets->pc_offset + 2 * offsets->gpr_size,
439 /* "trap" is stored 8 slots after "pc". */
440 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
441 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, gregs,
442 offsets->pc_offset + 8 * offsets->gpr_size,
447 /* Regset descriptions. */
448 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
450 /* General-purpose registers. */
451 /* .r0_offset = */ 0,
454 /* .pc_offset = */ 128,
455 /* .ps_offset = */ 132,
456 /* .cr_offset = */ 152,
457 /* .lr_offset = */ 144,
458 /* .ctr_offset = */ 140,
459 /* .xer_offset = */ 148,
460 /* .mq_offset = */ 156,
462 /* Floating-point registers. */
463 /* .f0_offset = */ 0,
464 /* .fpscr_offset = */ 256,
465 /* .fpscr_size = */ 8,
467 /* AltiVec registers. */
468 /* .vr0_offset = */ 0,
469 /* .vscr_offset = */ 512 + 12,
470 /* .vrsave_offset = */ 528
473 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
475 /* General-purpose registers. */
476 /* .r0_offset = */ 0,
479 /* .pc_offset = */ 256,
480 /* .ps_offset = */ 264,
481 /* .cr_offset = */ 304,
482 /* .lr_offset = */ 288,
483 /* .ctr_offset = */ 280,
484 /* .xer_offset = */ 296,
485 /* .mq_offset = */ 312,
487 /* Floating-point registers. */
488 /* .f0_offset = */ 0,
489 /* .fpscr_offset = */ 256,
490 /* .fpscr_size = */ 8,
492 /* AltiVec registers. */
493 /* .vr0_offset = */ 0,
494 /* .vscr_offset = */ 512 + 12,
495 /* .vrsave_offset = */ 528
498 static const struct regset ppc32_linux_gregset = {
499 &ppc32_linux_reg_offsets,
500 ppc_linux_supply_gregset,
501 ppc_linux_collect_gregset,
505 static const struct regset ppc64_linux_gregset = {
506 &ppc64_linux_reg_offsets,
507 ppc_linux_supply_gregset,
508 ppc_linux_collect_gregset,
512 static const struct regset ppc32_linux_fpregset = {
513 &ppc32_linux_reg_offsets,
515 ppc_collect_fpregset,
519 static const struct regset ppc32_linux_vrregset = {
520 &ppc32_linux_reg_offsets,
522 ppc_collect_vrregset,
526 static const struct regset ppc32_linux_vsxregset = {
527 &ppc32_linux_reg_offsets,
528 ppc_supply_vsxregset,
529 ppc_collect_vsxregset,
533 const struct regset *
534 ppc_linux_gregset (int wordsize)
536 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
539 const struct regset *
540 ppc_linux_fpregset (void)
542 return &ppc32_linux_fpregset;
545 static const struct regset *
546 ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
547 const char *sect_name, size_t sect_size)
549 struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
550 if (strcmp (sect_name, ".reg") == 0)
552 if (tdep->wordsize == 4)
553 return &ppc32_linux_gregset;
555 return &ppc64_linux_gregset;
557 if (strcmp (sect_name, ".reg2") == 0)
558 return &ppc32_linux_fpregset;
559 if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
560 return &ppc32_linux_vrregset;
561 if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
562 return &ppc32_linux_vsxregset;
567 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
568 struct trad_frame_cache *this_cache,
569 CORE_ADDR func, LONGEST offset,
577 struct gdbarch *gdbarch = get_frame_arch (this_frame);
578 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
579 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
581 base = get_frame_register_unsigned (this_frame,
582 gdbarch_sp_regnum (gdbarch));
583 if (bias > 0 && get_frame_pc (this_frame) != func)
584 /* See below, some signal trampolines increment the stack as their
585 first instruction, need to compensate for that. */
588 /* Find the address of the register buffer pointer. */
589 regs = base + offset;
590 /* Use that to find the address of the corresponding register
592 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
593 fpregs = gpregs + 48 * tdep->wordsize;
595 /* General purpose. */
596 for (i = 0; i < 32; i++)
598 int regnum = i + tdep->ppc_gp0_regnum;
599 trad_frame_set_reg_addr (this_cache,
600 regnum, gpregs + i * tdep->wordsize);
602 trad_frame_set_reg_addr (this_cache,
603 gdbarch_pc_regnum (gdbarch),
604 gpregs + 32 * tdep->wordsize);
605 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
606 gpregs + 35 * tdep->wordsize);
607 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
608 gpregs + 36 * tdep->wordsize);
609 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
610 gpregs + 37 * tdep->wordsize);
611 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
612 gpregs + 38 * tdep->wordsize);
614 if (ppc_linux_trap_reg_p (gdbarch))
616 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
617 gpregs + 34 * tdep->wordsize);
618 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
619 gpregs + 40 * tdep->wordsize);
622 if (ppc_floating_point_unit_p (gdbarch))
624 /* Floating point registers. */
625 for (i = 0; i < 32; i++)
627 int regnum = i + gdbarch_fp0_regnum (gdbarch);
628 trad_frame_set_reg_addr (this_cache, regnum,
629 fpregs + i * tdep->wordsize);
631 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
632 fpregs + 32 * tdep->wordsize);
634 trad_frame_set_id (this_cache, frame_id_build (base, func));
638 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
639 struct frame_info *this_frame,
640 struct trad_frame_cache *this_cache,
643 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
644 0xd0 /* Offset to ucontext_t. */
645 + 0x30 /* Offset to .reg. */,
650 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
651 struct frame_info *this_frame,
652 struct trad_frame_cache *this_cache,
655 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
656 0x80 /* Offset to ucontext_t. */
657 + 0xe0 /* Offset to .reg. */,
662 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
663 struct frame_info *this_frame,
664 struct trad_frame_cache *this_cache,
667 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
668 0x40 /* Offset to ucontext_t. */
669 + 0x1c /* Offset to .reg. */,
674 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
675 struct frame_info *this_frame,
676 struct trad_frame_cache *this_cache,
679 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
680 0x80 /* Offset to struct sigcontext. */
681 + 0x38 /* Offset to .reg. */,
685 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
689 { 0x380000ac, -1 }, /* li r0, 172 */
690 { 0x44000002, -1 }, /* sc */
691 { TRAMP_SENTINEL_INSN },
693 ppc32_linux_sigaction_cache_init
695 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
699 { 0x38210080, -1 }, /* addi r1,r1,128 */
700 { 0x380000ac, -1 }, /* li r0, 172 */
701 { 0x44000002, -1 }, /* sc */
702 { TRAMP_SENTINEL_INSN },
704 ppc64_linux_sigaction_cache_init
706 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
710 { 0x38000077, -1 }, /* li r0,119 */
711 { 0x44000002, -1 }, /* sc */
712 { TRAMP_SENTINEL_INSN },
714 ppc32_linux_sighandler_cache_init
716 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
720 { 0x38210080, -1 }, /* addi r1,r1,128 */
721 { 0x38000077, -1 }, /* li r0,119 */
722 { 0x44000002, -1 }, /* sc */
723 { TRAMP_SENTINEL_INSN },
725 ppc64_linux_sighandler_cache_init
729 /* Address to use for displaced stepping. When debugging a stand-alone
730 SPU executable, entry_point_address () will point to an SPU local-store
731 address and is thus not usable as displaced stepping location. We use
732 the auxiliary vector to determine the PowerPC-side entry point address
735 static CORE_ADDR ppc_linux_entry_point_addr = 0;
738 ppc_linux_inferior_created (struct target_ops *target, int from_tty)
740 ppc_linux_entry_point_addr = 0;
744 ppc_linux_displaced_step_location (struct gdbarch *gdbarch)
746 if (ppc_linux_entry_point_addr == 0)
750 /* Determine entry point from target auxiliary vector. */
751 if (target_auxv_search (¤t_target, AT_ENTRY, &addr) <= 0)
752 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
754 /* Make certain that the address points at real code, and not a
755 function descriptor. */
756 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
759 /* Inferior calls also use the entry point as a breakpoint location.
760 We don't want displaced stepping to interfere with those
761 breakpoints, so leave space. */
762 ppc_linux_entry_point_addr = addr + 2 * PPC_INSN_SIZE;
765 return ppc_linux_entry_point_addr;
769 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
771 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
773 /* If we do not have a target description with registers, then
774 the special registers will not be included in the register set. */
775 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
778 /* If we do, then it is safe to check the size. */
779 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
780 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
783 /* Return the current system call's number present in the
784 r0 register. When the function fails, it returns -1. */
786 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
789 struct regcache *regcache = get_thread_regcache (ptid);
790 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
791 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
792 struct cleanup *cleanbuf;
793 /* The content of a register */
798 /* Make sure we're in a 32- or 64-bit machine */
799 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
801 buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte));
803 cleanbuf = make_cleanup (xfree, buf);
805 /* Getting the system call number from the register.
806 When dealing with PowerPC architecture, this information
807 is stored at 0th register. */
808 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf);
810 ret = extract_signed_integer (buf, tdep->wordsize, byte_order);
811 do_cleanups (cleanbuf);
817 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
819 struct gdbarch *gdbarch = get_regcache_arch (regcache);
821 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
823 /* Set special TRAP register to -1 to prevent the kernel from
824 messing with the PC we just installed, if we happen to be
825 within an interrupted system call that the kernel wants to
828 Note that after we return from the dummy call, the TRAP and
829 ORIG_R3 registers will be automatically restored, and the
830 kernel continues to restart the system call at this point. */
831 if (ppc_linux_trap_reg_p (gdbarch))
832 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
836 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
838 return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
841 static const struct target_desc *
842 ppc_linux_core_read_description (struct gdbarch *gdbarch,
843 struct target_ops *target,
846 asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
847 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
848 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
849 asection *section = bfd_get_section_by_name (abfd, ".reg");
853 switch (bfd_section_size (abfd, section))
857 return tdesc_powerpc_cell32l;
859 return tdesc_powerpc_vsx32l;
861 return tdesc_powerpc_altivec32l;
863 return tdesc_powerpc_32l;
867 return tdesc_powerpc_cell64l;
869 return tdesc_powerpc_vsx64l;
871 return tdesc_powerpc_altivec64l;
873 return tdesc_powerpc_64l;
881 /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
882 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
885 ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
887 elf_symbol_type *elf_sym = (elf_symbol_type *)sym;
889 /* If the symbol is marked as having a local entry point, set a target
890 flag in the msymbol. We currently only support local entry point
891 offsets of 8 bytes, which is the only entry point offset ever used
892 by current compilers. If/when other offsets are ever used, we will
893 have to use additional target flag bits to store them. */
894 switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other))
899 MSYMBOL_TARGET_FLAG_1 (msym) = 1;
904 /* Implementation of `gdbarch_skip_entrypoint', as defined in
905 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
908 ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc)
910 struct bound_minimal_symbol fun;
911 int local_entry_offset = 0;
913 fun = lookup_minimal_symbol_by_pc (pc);
914 if (fun.minsym == NULL)
917 /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
918 offset values are encoded. */
919 if (MSYMBOL_TARGET_FLAG_1 (fun.minsym))
920 local_entry_offset = 8;
922 if (MSYMBOL_VALUE_ADDRESS (fun.minsym) <= pc
923 && pc < MSYMBOL_VALUE_ADDRESS (fun.minsym) + local_entry_offset)
924 return MSYMBOL_VALUE_ADDRESS (fun.minsym) + local_entry_offset;
929 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
933 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
935 return (*s == 'i' /* Literal number. */
936 || (isdigit (*s) && s[1] == '('
937 && isdigit (s[2])) /* Displacement. */
938 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
939 || isdigit (*s)); /* Register value. */
942 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
946 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
947 struct stap_parse_info *p)
949 if (isdigit (*p->arg))
951 /* This temporary pointer is needed because we have to do a lookahead.
952 We could be dealing with a register displacement, and in such case
953 we would not need to do anything. */
954 const char *s = p->arg;
964 /* It is a register displacement indeed. Returning 0 means we are
965 deferring the treatment of this case to the generic parser. */
970 regname = alloca (len + 2);
973 strncpy (regname + 1, p->arg, len);
977 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
978 error (_("Invalid register name `%s' on expression `%s'."),
979 regname, p->saved_arg);
981 write_exp_elt_opcode (OP_REGISTER);
984 write_exp_string (str);
985 write_exp_elt_opcode (OP_REGISTER);
991 /* All the other tokens should be handled correctly by the generic
999 /* Cell/B.E. active SPE context tracking support. */
1001 static struct objfile *spe_context_objfile = NULL;
1002 static CORE_ADDR spe_context_lm_addr = 0;
1003 static CORE_ADDR spe_context_offset = 0;
1005 static ptid_t spe_context_cache_ptid;
1006 static CORE_ADDR spe_context_cache_address;
1008 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
1009 to track whether we've loaded a version of libspe2 (as static or dynamic
1010 library) that provides the __spe_current_active_context variable. */
1012 ppc_linux_spe_context_lookup (struct objfile *objfile)
1014 struct minimal_symbol *sym;
1018 spe_context_objfile = NULL;
1019 spe_context_lm_addr = 0;
1020 spe_context_offset = 0;
1021 spe_context_cache_ptid = minus_one_ptid;
1022 spe_context_cache_address = 0;
1026 sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
1029 spe_context_objfile = objfile;
1030 spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
1031 spe_context_offset = MSYMBOL_VALUE_ADDRESS (sym);
1032 spe_context_cache_ptid = minus_one_ptid;
1033 spe_context_cache_address = 0;
1039 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
1041 struct objfile *objfile;
1043 ppc_linux_spe_context_lookup (NULL);
1044 ALL_OBJFILES (objfile)
1045 ppc_linux_spe_context_lookup (objfile);
1049 ppc_linux_spe_context_solib_loaded (struct so_list *so)
1051 if (strstr (so->so_original_name, "/libspe") != NULL)
1053 solib_read_symbols (so, 0);
1054 ppc_linux_spe_context_lookup (so->objfile);
1059 ppc_linux_spe_context_solib_unloaded (struct so_list *so)
1061 if (so->objfile == spe_context_objfile)
1062 ppc_linux_spe_context_lookup (NULL);
1065 /* Retrieve contents of the N'th element in the current thread's
1066 linked SPE context list into ID and NPC. Return the address of
1067 said context element, or 0 if not found. */
1069 ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
1070 int n, int *id, unsigned int *npc)
1072 CORE_ADDR spe_context = 0;
1076 /* Quick exit if we have not found __spe_current_active_context. */
1077 if (!spe_context_objfile)
1080 /* Look up cached address of thread-local variable. */
1081 if (!ptid_equal (spe_context_cache_ptid, inferior_ptid))
1083 struct target_ops *target = ¤t_target;
1084 volatile struct gdb_exception ex;
1086 while (target && !target->to_get_thread_local_address)
1087 target = find_target_beneath (target);
1091 TRY_CATCH (ex, RETURN_MASK_ERROR)
1093 /* We do not call target_translate_tls_address here, because
1094 svr4_fetch_objfile_link_map may invalidate the frame chain,
1095 which must not do while inside a frame sniffer.
1097 Instead, we have cached the lm_addr value, and use that to
1098 directly call the target's to_get_thread_local_address. */
1099 spe_context_cache_address
1100 = target->to_get_thread_local_address (target, inferior_ptid,
1101 spe_context_lm_addr,
1102 spe_context_offset);
1103 spe_context_cache_ptid = inferior_ptid;
1110 /* Read variable value. */
1111 if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
1112 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1114 /* Cyle through to N'th linked list element. */
1115 for (i = 0; i < n && spe_context; i++)
1116 if (target_read_memory (spe_context + align_up (12, wordsize),
1117 buf, wordsize) == 0)
1118 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1122 /* Read current context. */
1124 && target_read_memory (spe_context, buf, 12) != 0)
1127 /* Extract data elements. */
1131 *id = extract_signed_integer (buf, 4, byte_order);
1133 *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
1140 /* Cell/B.E. cross-architecture unwinder support. */
1142 struct ppu2spu_cache
1144 struct frame_id frame_id;
1145 struct regcache *regcache;
1148 static struct gdbarch *
1149 ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
1151 struct ppu2spu_cache *cache = *this_cache;
1152 return get_regcache_arch (cache->regcache);
1156 ppu2spu_this_id (struct frame_info *this_frame,
1157 void **this_cache, struct frame_id *this_id)
1159 struct ppu2spu_cache *cache = *this_cache;
1160 *this_id = cache->frame_id;
1163 static struct value *
1164 ppu2spu_prev_register (struct frame_info *this_frame,
1165 void **this_cache, int regnum)
1167 struct ppu2spu_cache *cache = *this_cache;
1168 struct gdbarch *gdbarch = get_regcache_arch (cache->regcache);
1171 buf = alloca (register_size (gdbarch, regnum));
1173 if (regnum < gdbarch_num_regs (gdbarch))
1174 regcache_raw_read (cache->regcache, regnum, buf);
1176 gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf);
1178 return frame_unwind_got_bytes (this_frame, regnum, buf);
1183 struct gdbarch *gdbarch;
1186 gdb_byte gprs[128*16];
1190 ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf)
1192 struct ppu2spu_data *data = src;
1193 enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
1195 if (regnum >= 0 && regnum < SPU_NUM_GPRS)
1196 memcpy (buf, data->gprs + 16*regnum, 16);
1197 else if (regnum == SPU_ID_REGNUM)
1198 store_unsigned_integer (buf, 4, byte_order, data->id);
1199 else if (regnum == SPU_PC_REGNUM)
1200 store_unsigned_integer (buf, 4, byte_order, data->npc);
1202 return REG_UNAVAILABLE;
1208 ppu2spu_sniffer (const struct frame_unwind *self,
1209 struct frame_info *this_frame, void **this_prologue_cache)
1211 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1212 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1213 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1214 struct ppu2spu_data data;
1215 struct frame_info *fi;
1216 CORE_ADDR base, func, backchain, spe_context;
1220 /* Count the number of SPU contexts already in the frame chain. */
1221 for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
1222 if (get_frame_type (fi) == ARCH_FRAME
1223 && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
1226 base = get_frame_sp (this_frame);
1227 func = get_frame_pc (this_frame);
1228 if (target_read_memory (base, buf, tdep->wordsize))
1230 backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
1232 spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
1233 n, &data.id, &data.npc);
1234 if (spe_context && base <= spe_context && spe_context < backchain)
1238 /* Find gdbarch for SPU. */
1239 struct gdbarch_info info;
1240 gdbarch_info_init (&info);
1241 info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
1242 info.byte_order = BFD_ENDIAN_BIG;
1243 info.osabi = GDB_OSABI_LINUX;
1244 info.tdep_info = (void *) &data.id;
1245 data.gdbarch = gdbarch_find_by_info (info);
1249 xsnprintf (annex, sizeof annex, "%d/regs", data.id);
1250 if (target_read (¤t_target, TARGET_OBJECT_SPU, annex,
1251 data.gprs, 0, sizeof data.gprs)
1252 == sizeof data.gprs)
1254 struct ppu2spu_cache *cache
1255 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
1257 struct address_space *aspace = get_frame_address_space (this_frame);
1258 struct regcache *regcache = regcache_xmalloc (data.gdbarch, aspace);
1259 struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
1260 regcache_save (regcache, ppu2spu_unwind_register, &data);
1261 discard_cleanups (cleanups);
1263 cache->frame_id = frame_id_build (base, func);
1264 cache->regcache = regcache;
1265 *this_prologue_cache = cache;
1274 ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
1276 struct ppu2spu_cache *cache = this_cache;
1277 regcache_xfree (cache->regcache);
1280 static const struct frame_unwind ppu2spu_unwind = {
1282 default_frame_unwind_stop_reason,
1284 ppu2spu_prev_register,
1287 ppu2spu_dealloc_cache,
1293 ppc_linux_init_abi (struct gdbarch_info info,
1294 struct gdbarch *gdbarch)
1296 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1297 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
1298 static const char *const stap_integer_prefixes[] = { "i", NULL };
1299 static const char *const stap_register_indirection_prefixes[] = { "(",
1301 static const char *const stap_register_indirection_suffixes[] = { ")",
1304 linux_init_abi (info, gdbarch);
1306 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1307 128-bit, they are IBM long double, not IEEE quad long double as
1308 in the System V ABI PowerPC Processor Supplement. We can safely
1309 let them default to 128-bit, since the debug info will give the
1310 size of type actually used in each case. */
1311 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
1312 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
1314 /* Handle inferior calls during interrupted system calls. */
1315 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
1317 /* Get the syscall number from the arch's register. */
1318 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
1320 /* SystemTap functions. */
1321 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
1322 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
1323 stap_register_indirection_prefixes);
1324 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
1325 stap_register_indirection_suffixes);
1326 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
1327 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
1328 set_gdbarch_stap_parse_special_token (gdbarch,
1329 ppc_stap_parse_special_token);
1331 if (tdep->wordsize == 4)
1333 /* Until November 2001, gcc did not comply with the 32 bit SysV
1334 R4 ABI requirement that structures less than or equal to 8
1335 bytes should be returned in registers. Instead GCC was using
1336 the AIX/PowerOpen ABI - everything returned in memory
1337 (well ignoring vectors that is). When this was corrected, it
1338 wasn't fixed for GNU/Linux native platform. Use the
1339 PowerOpen struct convention. */
1340 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
1342 set_gdbarch_memory_remove_breakpoint (gdbarch,
1343 ppc_linux_memory_remove_breakpoint);
1345 /* Shared library handling. */
1346 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
1347 set_solib_svr4_fetch_link_map_offsets
1348 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1350 /* Setting the correct XML syscall filename. */
1351 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC);
1354 tramp_frame_prepend_unwinder (gdbarch,
1355 &ppc32_linux_sigaction_tramp_frame);
1356 tramp_frame_prepend_unwinder (gdbarch,
1357 &ppc32_linux_sighandler_tramp_frame);
1359 /* BFD target for core files. */
1360 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1361 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
1363 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
1365 /* Supported register sections. */
1366 if (tdesc_find_feature (info.target_desc,
1367 "org.gnu.gdb.power.vsx"))
1368 set_gdbarch_core_regset_sections (gdbarch,
1369 ppc_linux_vsx_regset_sections);
1370 else if (tdesc_find_feature (info.target_desc,
1371 "org.gnu.gdb.power.altivec"))
1372 set_gdbarch_core_regset_sections (gdbarch,
1373 ppc_linux_vmx_regset_sections);
1375 set_gdbarch_core_regset_sections (gdbarch,
1376 ppc_linux_fp_regset_sections);
1378 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
1380 powerpc_so_ops = svr4_so_ops;
1381 /* Override dynamic resolve function. */
1382 powerpc_so_ops.in_dynsym_resolve_code =
1383 powerpc_linux_in_dynsym_resolve_code;
1385 set_solib_ops (gdbarch, &powerpc_so_ops);
1387 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1390 if (tdep->wordsize == 8)
1392 if (tdep->elf_abi == POWERPC_ELF_V1)
1394 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1395 function descriptors). */
1396 set_gdbarch_convert_from_func_ptr_addr
1397 (gdbarch, ppc64_convert_from_func_ptr_addr);
1399 set_gdbarch_elf_make_msymbol_special
1400 (gdbarch, ppc64_elf_make_msymbol_special);
1404 set_gdbarch_elf_make_msymbol_special
1405 (gdbarch, ppc_elfv2_elf_make_msymbol_special);
1407 set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint);
1410 /* Shared library handling. */
1411 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
1412 set_solib_svr4_fetch_link_map_offsets
1413 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1415 /* Setting the correct XML syscall filename. */
1416 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64);
1419 tramp_frame_prepend_unwinder (gdbarch,
1420 &ppc64_linux_sigaction_tramp_frame);
1421 tramp_frame_prepend_unwinder (gdbarch,
1422 &ppc64_linux_sighandler_tramp_frame);
1424 /* BFD target for core files. */
1425 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1426 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
1428 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
1430 /* Supported register sections. */
1431 if (tdesc_find_feature (info.target_desc,
1432 "org.gnu.gdb.power.vsx"))
1433 set_gdbarch_core_regset_sections (gdbarch,
1434 ppc64_linux_vsx_regset_sections);
1435 else if (tdesc_find_feature (info.target_desc,
1436 "org.gnu.gdb.power.altivec"))
1437 set_gdbarch_core_regset_sections (gdbarch,
1438 ppc64_linux_vmx_regset_sections);
1440 set_gdbarch_core_regset_sections (gdbarch,
1441 ppc64_linux_fp_regset_sections);
1444 /* PPC32 uses a different prpsinfo32 compared to most other Linux
1446 if (tdep->wordsize == 4)
1447 set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch,
1448 elfcore_write_ppc_linux_prpsinfo32);
1450 set_gdbarch_regset_from_core_section (gdbarch,
1451 ppc_linux_regset_from_core_section);
1452 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
1454 /* Enable TLS support. */
1455 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1456 svr4_fetch_objfile_link_map);
1460 const struct tdesc_feature *feature;
1462 /* If we have target-described registers, then we can safely
1463 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1464 (whether they are described or not). */
1465 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
1466 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
1468 /* If they are present, then assign them to the reserved number. */
1469 feature = tdesc_find_feature (info.target_desc,
1470 "org.gnu.gdb.power.linux");
1471 if (feature != NULL)
1473 tdesc_numbered_register (feature, tdesc_data,
1474 PPC_ORIG_R3_REGNUM, "orig_r3");
1475 tdesc_numbered_register (feature, tdesc_data,
1476 PPC_TRAP_REGNUM, "trap");
1480 /* Enable Cell/B.E. if supported by the target. */
1481 if (tdesc_compatible_p (info.target_desc,
1482 bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
1484 /* Cell/B.E. multi-architecture support. */
1485 set_spu_solib_ops (gdbarch);
1487 /* Cell/B.E. cross-architecture unwinder support. */
1488 frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
1490 /* The default displaced_step_at_entry_point doesn't work for
1491 SPU stand-alone executables. */
1492 set_gdbarch_displaced_step_location (gdbarch,
1493 ppc_linux_displaced_step_location);
1496 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
1499 /* Provide a prototype to silence -Wmissing-prototypes. */
1500 extern initialize_file_ftype _initialize_ppc_linux_tdep;
1503 _initialize_ppc_linux_tdep (void)
1505 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1506 64-bit PowerPC, and the older rs6k. */
1507 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
1508 ppc_linux_init_abi);
1509 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
1510 ppc_linux_init_abi);
1511 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
1512 ppc_linux_init_abi);
1514 /* Attach to inferior_created observer. */
1515 observer_attach_inferior_created (ppc_linux_inferior_created);
1517 /* Attach to observers to track __spe_current_active_context. */
1518 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created);
1519 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded);
1520 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded);
1522 /* Initialize the Linux target descriptions. */
1523 initialize_tdesc_powerpc_32l ();
1524 initialize_tdesc_powerpc_altivec32l ();
1525 initialize_tdesc_powerpc_cell32l ();
1526 initialize_tdesc_powerpc_vsx32l ();
1527 initialize_tdesc_powerpc_isa205_32l ();
1528 initialize_tdesc_powerpc_isa205_altivec32l ();
1529 initialize_tdesc_powerpc_isa205_vsx32l ();
1530 initialize_tdesc_powerpc_64l ();
1531 initialize_tdesc_powerpc_altivec64l ();
1532 initialize_tdesc_powerpc_cell64l ();
1533 initialize_tdesc_powerpc_vsx64l ();
1534 initialize_tdesc_powerpc_isa205_64l ();
1535 initialize_tdesc_powerpc_isa205_altivec64l ();
1536 initialize_tdesc_powerpc_isa205_vsx64l ();
1537 initialize_tdesc_powerpc_e500l ();