1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 1986-1987, 1989, 1991-1997, 2000-2012 Free Software
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "solib-svr4.h"
35 #include "solib-spu.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"
61 #include "features/rs6000/powerpc-32l.c"
62 #include "features/rs6000/powerpc-altivec32l.c"
63 #include "features/rs6000/powerpc-cell32l.c"
64 #include "features/rs6000/powerpc-vsx32l.c"
65 #include "features/rs6000/powerpc-isa205-32l.c"
66 #include "features/rs6000/powerpc-isa205-altivec32l.c"
67 #include "features/rs6000/powerpc-isa205-vsx32l.c"
68 #include "features/rs6000/powerpc-64l.c"
69 #include "features/rs6000/powerpc-altivec64l.c"
70 #include "features/rs6000/powerpc-cell64l.c"
71 #include "features/rs6000/powerpc-vsx64l.c"
72 #include "features/rs6000/powerpc-isa205-64l.c"
73 #include "features/rs6000/powerpc-isa205-altivec64l.c"
74 #include "features/rs6000/powerpc-isa205-vsx64l.c"
75 #include "features/rs6000/powerpc-e500l.c"
77 /* Shared library operations for PowerPC-Linux. */
78 static struct target_so_ops powerpc_so_ops;
80 /* The syscall's XML filename for PPC and PPC64. */
81 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
82 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
84 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
85 in much the same fashion as memory_remove_breakpoint in mem-break.c,
86 but is careful not to write back the previous contents if the code
87 in question has changed in between inserting the breakpoint and
90 Here is the problem that we're trying to solve...
92 Once upon a time, before introducing this function to remove
93 breakpoints from the inferior, setting a breakpoint on a shared
94 library function prior to running the program would not work
95 properly. In order to understand the problem, it is first
96 necessary to understand a little bit about dynamic linking on
99 A call to a shared library function is accomplished via a bl
100 (branch-and-link) instruction whose branch target is an entry
101 in the procedure linkage table (PLT). The PLT in the object
102 file is uninitialized. To gdb, prior to running the program, the
103 entries in the PLT are all zeros.
105 Once the program starts running, the shared libraries are loaded
106 and the procedure linkage table is initialized, but the entries in
107 the table are not (necessarily) resolved. Once a function is
108 actually called, the code in the PLT is hit and the function is
109 resolved. In order to better illustrate this, an example is in
110 order; the following example is from the gdb testsuite.
112 We start the program shmain.
114 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
117 We place two breakpoints, one on shr1 and the other on main.
120 Breakpoint 1 at 0x100409d4
122 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
124 Examine the instruction (and the immediatly following instruction)
125 upon which the breakpoint was placed. Note that the PLT entry
126 for shr1 contains zeros.
128 (gdb) x/2i 0x100409d4
129 0x100409d4 <shr1>: .long 0x0
130 0x100409d8 <shr1+4>: .long 0x0
135 Starting program: gdb.base/shmain
136 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
138 Breakpoint 2, main ()
139 at gdb.base/shmain.c:44
142 Examine the PLT again. Note that the loading of the shared
143 library has initialized the PLT to code which loads a constant
144 (which I think is an index into the GOT) into r11 and then
145 branchs a short distance to the code which actually does the
148 (gdb) x/2i 0x100409d4
149 0x100409d4 <shr1>: li r11,4
150 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
154 Breakpoint 1, shr1 (x=1)
155 at gdb.base/shr1.c:19
158 Now we've hit the breakpoint at shr1. (The breakpoint was
159 reset from the PLT entry to the actual shr1 function after the
160 shared library was loaded.) Note that the PLT entry has been
161 resolved to contain a branch that takes us directly to shr1.
162 (The real one, not the PLT entry.)
164 (gdb) x/2i 0x100409d4
165 0x100409d4 <shr1>: b 0xffaf76c <shr1>
166 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
168 The thing to note here is that the PLT entry for shr1 has been
171 Now the problem should be obvious. GDB places a breakpoint (a
172 trap instruction) on the zero value of the PLT entry for shr1.
173 Later on, after the shared library had been loaded and the PLT
174 initialized, GDB gets a signal indicating this fact and attempts
175 (as it always does when it stops) to remove all the breakpoints.
177 The breakpoint removal was causing the former contents (a zero
178 word) to be written back to the now initialized PLT entry thus
179 destroying a portion of the initialization that had occurred only a
180 short time ago. When execution continued, the zero word would be
181 executed as an instruction an illegal instruction trap was
182 generated instead. (0 is not a legal instruction.)
184 The fix for this problem was fairly straightforward. The function
185 memory_remove_breakpoint from mem-break.c was copied to this file,
186 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
187 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
190 The differences between ppc_linux_memory_remove_breakpoint () and
191 memory_remove_breakpoint () are minor. All that the former does
192 that the latter does not is check to make sure that the breakpoint
193 location actually contains a breakpoint (trap instruction) prior
194 to attempting to write back the old contents. If it does contain
195 a trap instruction, we allow the old contents to be written back.
196 Otherwise, we silently do nothing.
198 The big question is whether memory_remove_breakpoint () should be
199 changed to have the same functionality. The downside is that more
200 traffic is generated for remote targets since we'll have an extra
201 fetch of a memory word each time a breakpoint is removed.
203 For the time being, we'll leave this self-modifying-code-friendly
204 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
205 else in the event that some other platform has similar needs with
206 regard to removing breakpoints in some potentially self modifying
209 ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
210 struct bp_target_info *bp_tgt)
212 CORE_ADDR addr = bp_tgt->placed_address;
213 const unsigned char *bp;
216 gdb_byte old_contents[BREAKPOINT_MAX];
217 struct cleanup *cleanup;
219 /* Determine appropriate breakpoint contents and size for this address. */
220 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
222 error (_("Software breakpoints not implemented for this target."));
224 /* Make sure we see the memory breakpoints. */
225 cleanup = make_show_memory_breakpoints_cleanup (1);
226 val = target_read_memory (addr, old_contents, bplen);
228 /* If our breakpoint is no longer at the address, this means that the
229 program modified the code on us, so it is wrong to put back the
231 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
232 val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
234 do_cleanups (cleanup);
238 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
239 than the 32 bit SYSV R4 ABI structure return convention - all
240 structures, no matter their size, are put in memory. Vectors,
241 which were added later, do get returned in a register though. */
243 static enum return_value_convention
244 ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
245 struct type *valtype, struct regcache *regcache,
246 gdb_byte *readbuf, const gdb_byte *writebuf)
248 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
249 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
250 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
251 && TYPE_VECTOR (valtype)))
252 return RETURN_VALUE_STRUCT_CONVENTION;
254 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
258 /* Macros for matching instructions. Note that, since all the
259 operands are masked off before they're or-ed into the instruction,
260 you can use -1 to make masks. */
262 #define insn_d(opcd, rts, ra, d) \
263 ((((opcd) & 0x3f) << 26) \
264 | (((rts) & 0x1f) << 21) \
265 | (((ra) & 0x1f) << 16) \
268 #define insn_ds(opcd, rts, ra, d, xo) \
269 ((((opcd) & 0x3f) << 26) \
270 | (((rts) & 0x1f) << 21) \
271 | (((ra) & 0x1f) << 16) \
275 #define insn_xfx(opcd, rts, spr, xo) \
276 ((((opcd) & 0x3f) << 26) \
277 | (((rts) & 0x1f) << 21) \
278 | (((spr) & 0x1f) << 16) \
279 | (((spr) & 0x3e0) << 6) \
280 | (((xo) & 0x3ff) << 1))
282 /* Read a PPC instruction from memory. PPC instructions are always
283 big-endian, no matter what endianness the program is running in, so
284 we can't use read_memory_integer or one of its friends here. */
286 read_insn (CORE_ADDR pc)
288 unsigned char buf[4];
290 read_memory (pc, buf, 4);
291 return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
295 /* An instruction to match. */
298 unsigned int mask; /* mask the insn with this... */
299 unsigned int data; /* ...and see if it matches this. */
300 int optional; /* If non-zero, this insn may be absent. */
303 /* Return non-zero if the instructions at PC match the series
304 described in PATTERN, or zero otherwise. PATTERN is an array of
305 'struct insn_pattern' objects, terminated by an entry whose mask is
308 When the match is successful, fill INSN[i] with what PATTERN[i]
309 matched. If PATTERN[i] is optional, and the instruction wasn't
310 present, set INSN[i] to 0 (which is not a valid PPC instruction).
311 INSN should have as many elements as PATTERN. Note that, if
312 PATTERN contains optional instructions which aren't present in
313 memory, then INSN will have holes, so INSN[i] isn't necessarily the
314 i'th instruction in memory. */
316 insns_match_pattern (CORE_ADDR pc,
317 struct insn_pattern *pattern,
322 for (i = 0; pattern[i].mask; i++)
324 insn[i] = read_insn (pc);
325 if ((insn[i] & pattern[i].mask) == pattern[i].data)
327 else if (pattern[i].optional)
337 /* Return the 'd' field of the d-form instruction INSN, properly
340 insn_d_field (unsigned int insn)
342 return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000);
346 /* Return the 'ds' field of the ds-form instruction INSN, with the two
347 zero bits concatenated at the right, and properly
350 insn_ds_field (unsigned int insn)
352 return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000);
356 /* If DESC is the address of a 64-bit PowerPC GNU/Linux function
357 descriptor, return the descriptor's entry point. */
359 ppc64_desc_entry_point (struct gdbarch *gdbarch, CORE_ADDR desc)
361 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
362 /* The first word of the descriptor is the entry point. */
363 return (CORE_ADDR) read_memory_unsigned_integer (desc, 8, byte_order);
367 /* Pattern for the standard linkage function. These are built by
368 build_plt_stub in elf64-ppc.c, whose GLINK argument is always
370 static struct insn_pattern ppc64_standard_linkage1[] =
372 /* addis r12, r2, <any> */
373 { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
376 { -1, insn_ds (62, 2, 1, 40, 0), 0 },
378 /* ld r11, <any>(r12) */
379 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
381 /* addis r12, r12, 1 <optional> */
382 { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },
384 /* ld r2, <any>(r12) */
385 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
387 /* addis r12, r12, 1 <optional> */
388 { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },
391 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
393 /* ld r11, <any>(r12) <optional> */
394 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },
397 { -1, 0x4e800420, 0 },
401 #define PPC64_STANDARD_LINKAGE1_LEN \
402 (sizeof (ppc64_standard_linkage1) / sizeof (ppc64_standard_linkage1[0]))
404 static struct insn_pattern ppc64_standard_linkage2[] =
406 /* addis r12, r2, <any> */
407 { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
410 { -1, insn_ds (62, 2, 1, 40, 0), 0 },
412 /* ld r11, <any>(r12) */
413 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
415 /* addi r12, r12, <any> <optional> */
416 { insn_d (-1, -1, -1, 0), insn_d (14, 12, 12, 0), 1 },
419 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
421 /* ld r2, <any>(r12) */
422 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
424 /* ld r11, <any>(r12) <optional> */
425 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },
428 { -1, 0x4e800420, 0 },
432 #define PPC64_STANDARD_LINKAGE2_LEN \
433 (sizeof (ppc64_standard_linkage2) / sizeof (ppc64_standard_linkage2[0]))
435 static struct insn_pattern ppc64_standard_linkage3[] =
438 { -1, insn_ds (62, 2, 1, 40, 0), 0 },
440 /* ld r11, <any>(r2) */
441 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
443 /* addi r2, r2, <any> <optional> */
444 { insn_d (-1, -1, -1, 0), insn_d (14, 2, 2, 0), 1 },
447 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
449 /* ld r11, <any>(r2) <optional> */
450 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 1 },
452 /* ld r2, <any>(r2) */
453 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },
456 { -1, 0x4e800420, 0 },
460 #define PPC64_STANDARD_LINKAGE3_LEN \
461 (sizeof (ppc64_standard_linkage3) / sizeof (ppc64_standard_linkage3[0]))
464 /* When the dynamic linker is doing lazy symbol resolution, the first
465 call to a function in another object will go like this:
467 - The user's function calls the linkage function:
469 100007c4: 4b ff fc d5 bl 10000498
470 100007c8: e8 41 00 28 ld r2,40(r1)
472 - The linkage function loads the entry point (and other stuff) from
473 the function descriptor in the PLT, and jumps to it:
475 10000498: 3d 82 00 00 addis r12,r2,0
476 1000049c: f8 41 00 28 std r2,40(r1)
477 100004a0: e9 6c 80 98 ld r11,-32616(r12)
478 100004a4: e8 4c 80 a0 ld r2,-32608(r12)
479 100004a8: 7d 69 03 a6 mtctr r11
480 100004ac: e9 6c 80 a8 ld r11,-32600(r12)
481 100004b0: 4e 80 04 20 bctr
483 - But since this is the first time that PLT entry has been used, it
484 sends control to its glink entry. That loads the number of the
485 PLT entry and jumps to the common glink0 code:
487 10000c98: 38 00 00 00 li r0,0
488 10000c9c: 4b ff ff dc b 10000c78
490 - The common glink0 code then transfers control to the dynamic
493 10000c78: e8 41 00 28 ld r2,40(r1)
494 10000c7c: 3d 82 00 00 addis r12,r2,0
495 10000c80: e9 6c 80 80 ld r11,-32640(r12)
496 10000c84: e8 4c 80 88 ld r2,-32632(r12)
497 10000c88: 7d 69 03 a6 mtctr r11
498 10000c8c: e9 6c 80 90 ld r11,-32624(r12)
499 10000c90: 4e 80 04 20 bctr
501 Eventually, this code will figure out how to skip all of this,
502 including the dynamic linker. At the moment, we just get through
503 the linkage function. */
505 /* If the current thread is about to execute a series of instructions
506 at PC matching the ppc64_standard_linkage pattern, and INSN is the result
507 from that pattern match, return the code address to which the
508 standard linkage function will send them. (This doesn't deal with
509 dynamic linker lazy symbol resolution stubs.) */
511 ppc64_standard_linkage1_target (struct frame_info *frame,
512 CORE_ADDR pc, unsigned int *insn)
514 struct gdbarch *gdbarch = get_frame_arch (frame);
515 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
517 /* The address of the function descriptor this linkage function
520 = ((CORE_ADDR) get_frame_register_unsigned (frame,
521 tdep->ppc_gp0_regnum + 2)
522 + (insn_d_field (insn[0]) << 16)
523 + insn_ds_field (insn[2]));
525 /* The first word of the descriptor is the entry point. Return that. */
526 return ppc64_desc_entry_point (gdbarch, desc);
529 static struct core_regset_section ppc_linux_vsx_regset_sections[] =
531 { ".reg", 48 * 4, "general-purpose" },
532 { ".reg2", 264, "floating-point" },
533 { ".reg-ppc-vmx", 544, "ppc Altivec" },
534 { ".reg-ppc-vsx", 256, "POWER7 VSX" },
538 static struct core_regset_section ppc_linux_vmx_regset_sections[] =
540 { ".reg", 48 * 4, "general-purpose" },
541 { ".reg2", 264, "floating-point" },
542 { ".reg-ppc-vmx", 544, "ppc Altivec" },
546 static struct core_regset_section ppc_linux_fp_regset_sections[] =
548 { ".reg", 48 * 4, "general-purpose" },
549 { ".reg2", 264, "floating-point" },
553 static struct core_regset_section ppc64_linux_vsx_regset_sections[] =
555 { ".reg", 48 * 8, "general-purpose" },
556 { ".reg2", 264, "floating-point" },
557 { ".reg-ppc-vmx", 544, "ppc Altivec" },
558 { ".reg-ppc-vsx", 256, "POWER7 VSX" },
562 static struct core_regset_section ppc64_linux_vmx_regset_sections[] =
564 { ".reg", 48 * 8, "general-purpose" },
565 { ".reg2", 264, "floating-point" },
566 { ".reg-ppc-vmx", 544, "ppc Altivec" },
570 static struct core_regset_section ppc64_linux_fp_regset_sections[] =
572 { ".reg", 48 * 8, "general-purpose" },
573 { ".reg2", 264, "floating-point" },
578 ppc64_standard_linkage2_target (struct frame_info *frame,
579 CORE_ADDR pc, unsigned int *insn)
581 struct gdbarch *gdbarch = get_frame_arch (frame);
582 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
584 /* The address of the function descriptor this linkage function
587 = ((CORE_ADDR) get_frame_register_unsigned (frame,
588 tdep->ppc_gp0_regnum + 2)
589 + (insn_d_field (insn[0]) << 16)
590 + insn_ds_field (insn[2]));
592 /* The first word of the descriptor is the entry point. Return that. */
593 return ppc64_desc_entry_point (gdbarch, desc);
597 ppc64_standard_linkage3_target (struct frame_info *frame,
598 CORE_ADDR pc, unsigned int *insn)
600 struct gdbarch *gdbarch = get_frame_arch (frame);
601 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
603 /* The address of the function descriptor this linkage function
606 = ((CORE_ADDR) get_frame_register_unsigned (frame,
607 tdep->ppc_gp0_regnum + 2)
608 + insn_ds_field (insn[1]));
610 /* The first word of the descriptor is the entry point. Return that. */
611 return ppc64_desc_entry_point (gdbarch, desc);
614 /* PLT stub in executable. */
615 static struct insn_pattern powerpc32_plt_stub[] =
617 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
618 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
619 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
620 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
624 /* PLT stub in shared library. */
625 static struct insn_pattern powerpc32_plt_stub_so[] =
627 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
628 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
629 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
630 { 0xffffffff, 0x60000000, 0 }, /* nop */
633 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub)
635 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
636 section. For secure PLT, stub is in .text and we need to check
637 instruction patterns. */
640 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
642 struct minimal_symbol *sym;
644 /* Check whether PC is in the dynamic linker. This also checks
645 whether it is in the .plt section, used by non-PIC executables. */
646 if (svr4_in_dynsym_resolve_code (pc))
649 /* Check if we are in the resolver. */
650 sym = lookup_minimal_symbol_by_pc (pc);
652 && (strcmp (SYMBOL_LINKAGE_NAME (sym), "__glink") == 0
653 || strcmp (SYMBOL_LINKAGE_NAME (sym), "__glink_PLTresolve") == 0))
659 /* Follow PLT stub to actual routine. */
662 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
664 int insnbuf[POWERPC32_PLT_STUB_LEN];
665 struct gdbarch *gdbarch = get_frame_arch (frame);
666 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
667 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
668 CORE_ADDR target = 0;
670 if (insns_match_pattern (pc, powerpc32_plt_stub, insnbuf))
675 Branch target is in r11. */
677 target = (insn_d_field (insnbuf[0]) << 16) | insn_d_field (insnbuf[1]);
678 target = read_memory_unsigned_integer (target, 4, byte_order);
681 if (insns_match_pattern (pc, powerpc32_plt_stub_so, insnbuf))
685 Branch target is in r11. */
687 target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30)
688 + insn_d_field (insnbuf[0]);
689 target = read_memory_unsigned_integer (target, 4, byte_order);
695 /* Given that we've begun executing a call trampoline at PC, return
696 the entry point of the function the trampoline will go to. */
698 ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
700 unsigned int ppc64_standard_linkage1_insn[PPC64_STANDARD_LINKAGE1_LEN];
701 unsigned int ppc64_standard_linkage2_insn[PPC64_STANDARD_LINKAGE2_LEN];
702 unsigned int ppc64_standard_linkage3_insn[PPC64_STANDARD_LINKAGE3_LEN];
705 if (insns_match_pattern (pc, ppc64_standard_linkage1,
706 ppc64_standard_linkage1_insn))
707 pc = ppc64_standard_linkage1_target (frame, pc,
708 ppc64_standard_linkage1_insn);
709 else if (insns_match_pattern (pc, ppc64_standard_linkage2,
710 ppc64_standard_linkage2_insn))
711 pc = ppc64_standard_linkage2_target (frame, pc,
712 ppc64_standard_linkage2_insn);
713 else if (insns_match_pattern (pc, ppc64_standard_linkage3,
714 ppc64_standard_linkage3_insn))
715 pc = ppc64_standard_linkage3_target (frame, pc,
716 ppc64_standard_linkage3_insn);
720 /* The PLT descriptor will either point to the already resolved target
721 address, or else to a glink stub. As the latter carry synthetic @plt
722 symbols, find_solib_trampoline_target should be able to resolve them. */
723 target = find_solib_trampoline_target (frame, pc);
724 return target? target : pc;
728 /* Support for convert_from_func_ptr_addr (ARCH, ADDR, TARG) on PPC64
731 Usually a function pointer's representation is simply the address
732 of the function. On GNU/Linux on the PowerPC however, a function
733 pointer may be a pointer to a function descriptor.
735 For PPC64, a function descriptor is a TOC entry, in a data section,
736 which contains three words: the first word is the address of the
737 function, the second word is the TOC pointer (r2), and the third word
738 is the static chain value.
740 Throughout GDB it is currently assumed that a function pointer contains
741 the address of the function, which is not easy to fix. In addition, the
742 conversion of a function address to a function pointer would
743 require allocation of a TOC entry in the inferior's memory space,
744 with all its drawbacks. To be able to call C++ virtual methods in
745 the inferior (which are called via function pointers),
746 find_function_addr uses this function to get the function address
747 from a function pointer.
749 If ADDR points at what is clearly a function descriptor, transform
750 it into the address of the corresponding function, if needed. Be
751 conservative, otherwise GDB will do the transformation on any
752 random addresses such as occur when there is no symbol table. */
755 ppc64_linux_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
757 struct target_ops *targ)
759 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
760 struct target_section *s = target_section_by_addr (targ, addr);
762 /* Check if ADDR points to a function descriptor. */
763 if (s && strcmp (s->the_bfd_section->name, ".opd") == 0)
765 /* There may be relocations that need to be applied to the .opd
766 section. Unfortunately, this function may be called at a time
767 where these relocations have not yet been performed -- this can
768 happen for example shortly after a library has been loaded with
769 dlopen, but ld.so has not yet applied the relocations.
771 To cope with both the case where the relocation has been applied,
772 and the case where it has not yet been applied, we do *not* read
773 the (maybe) relocated value from target memory, but we instead
774 read the non-relocated value from the BFD, and apply the relocation
777 This makes the assumption that all .opd entries are always relocated
778 by the same offset the section itself was relocated. This should
779 always be the case for GNU/Linux executables and shared libraries.
780 Note that other kind of object files (e.g. those added via
781 add-symbol-files) will currently never end up here anyway, as this
782 function accesses *target* sections only; only the main exec and
783 shared libraries are ever added to the target. */
788 res = bfd_get_section_contents (s->bfd, s->the_bfd_section,
789 &buf, addr - s->addr, 8);
791 return extract_unsigned_integer (buf, 8, byte_order)
792 - bfd_section_vma (s->bfd, s->the_bfd_section) + s->addr;
798 /* Wrappers to handle Linux-only registers. */
801 ppc_linux_supply_gregset (const struct regset *regset,
802 struct regcache *regcache,
803 int regnum, const void *gregs, size_t len)
805 const struct ppc_reg_offsets *offsets = regset->descr;
807 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
809 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
811 /* "orig_r3" is stored 2 slots after "pc". */
812 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
813 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
814 offsets->pc_offset + 2 * offsets->gpr_size,
817 /* "trap" is stored 8 slots after "pc". */
818 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
819 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, gregs,
820 offsets->pc_offset + 8 * offsets->gpr_size,
826 ppc_linux_collect_gregset (const struct regset *regset,
827 const struct regcache *regcache,
828 int regnum, void *gregs, size_t len)
830 const struct ppc_reg_offsets *offsets = regset->descr;
832 /* Clear areas in the linux gregset not written elsewhere. */
834 memset (gregs, 0, len);
836 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
838 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
840 /* "orig_r3" is stored 2 slots after "pc". */
841 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
842 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
843 offsets->pc_offset + 2 * offsets->gpr_size,
846 /* "trap" is stored 8 slots after "pc". */
847 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
848 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, gregs,
849 offsets->pc_offset + 8 * offsets->gpr_size,
854 /* Regset descriptions. */
855 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
857 /* General-purpose registers. */
858 /* .r0_offset = */ 0,
861 /* .pc_offset = */ 128,
862 /* .ps_offset = */ 132,
863 /* .cr_offset = */ 152,
864 /* .lr_offset = */ 144,
865 /* .ctr_offset = */ 140,
866 /* .xer_offset = */ 148,
867 /* .mq_offset = */ 156,
869 /* Floating-point registers. */
870 /* .f0_offset = */ 0,
871 /* .fpscr_offset = */ 256,
872 /* .fpscr_size = */ 8,
874 /* AltiVec registers. */
875 /* .vr0_offset = */ 0,
876 /* .vscr_offset = */ 512 + 12,
877 /* .vrsave_offset = */ 528
880 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
882 /* General-purpose registers. */
883 /* .r0_offset = */ 0,
886 /* .pc_offset = */ 256,
887 /* .ps_offset = */ 264,
888 /* .cr_offset = */ 304,
889 /* .lr_offset = */ 288,
890 /* .ctr_offset = */ 280,
891 /* .xer_offset = */ 296,
892 /* .mq_offset = */ 312,
894 /* Floating-point registers. */
895 /* .f0_offset = */ 0,
896 /* .fpscr_offset = */ 256,
897 /* .fpscr_size = */ 8,
899 /* AltiVec registers. */
900 /* .vr0_offset = */ 0,
901 /* .vscr_offset = */ 512 + 12,
902 /* .vrsave_offset = */ 528
905 static const struct regset ppc32_linux_gregset = {
906 &ppc32_linux_reg_offsets,
907 ppc_linux_supply_gregset,
908 ppc_linux_collect_gregset,
912 static const struct regset ppc64_linux_gregset = {
913 &ppc64_linux_reg_offsets,
914 ppc_linux_supply_gregset,
915 ppc_linux_collect_gregset,
919 static const struct regset ppc32_linux_fpregset = {
920 &ppc32_linux_reg_offsets,
922 ppc_collect_fpregset,
926 static const struct regset ppc32_linux_vrregset = {
927 &ppc32_linux_reg_offsets,
929 ppc_collect_vrregset,
933 static const struct regset ppc32_linux_vsxregset = {
934 &ppc32_linux_reg_offsets,
935 ppc_supply_vsxregset,
936 ppc_collect_vsxregset,
940 const struct regset *
941 ppc_linux_gregset (int wordsize)
943 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
946 const struct regset *
947 ppc_linux_fpregset (void)
949 return &ppc32_linux_fpregset;
952 static const struct regset *
953 ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
954 const char *sect_name, size_t sect_size)
956 struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
957 if (strcmp (sect_name, ".reg") == 0)
959 if (tdep->wordsize == 4)
960 return &ppc32_linux_gregset;
962 return &ppc64_linux_gregset;
964 if (strcmp (sect_name, ".reg2") == 0)
965 return &ppc32_linux_fpregset;
966 if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
967 return &ppc32_linux_vrregset;
968 if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
969 return &ppc32_linux_vsxregset;
974 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
975 struct trad_frame_cache *this_cache,
976 CORE_ADDR func, LONGEST offset,
984 struct gdbarch *gdbarch = get_frame_arch (this_frame);
985 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
986 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
988 base = get_frame_register_unsigned (this_frame,
989 gdbarch_sp_regnum (gdbarch));
990 if (bias > 0 && get_frame_pc (this_frame) != func)
991 /* See below, some signal trampolines increment the stack as their
992 first instruction, need to compensate for that. */
995 /* Find the address of the register buffer pointer. */
996 regs = base + offset;
997 /* Use that to find the address of the corresponding register
999 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
1000 fpregs = gpregs + 48 * tdep->wordsize;
1002 /* General purpose. */
1003 for (i = 0; i < 32; i++)
1005 int regnum = i + tdep->ppc_gp0_regnum;
1006 trad_frame_set_reg_addr (this_cache,
1007 regnum, gpregs + i * tdep->wordsize);
1009 trad_frame_set_reg_addr (this_cache,
1010 gdbarch_pc_regnum (gdbarch),
1011 gpregs + 32 * tdep->wordsize);
1012 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
1013 gpregs + 35 * tdep->wordsize);
1014 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
1015 gpregs + 36 * tdep->wordsize);
1016 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
1017 gpregs + 37 * tdep->wordsize);
1018 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
1019 gpregs + 38 * tdep->wordsize);
1021 if (ppc_linux_trap_reg_p (gdbarch))
1023 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
1024 gpregs + 34 * tdep->wordsize);
1025 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
1026 gpregs + 40 * tdep->wordsize);
1029 if (ppc_floating_point_unit_p (gdbarch))
1031 /* Floating point registers. */
1032 for (i = 0; i < 32; i++)
1034 int regnum = i + gdbarch_fp0_regnum (gdbarch);
1035 trad_frame_set_reg_addr (this_cache, regnum,
1036 fpregs + i * tdep->wordsize);
1038 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
1039 fpregs + 32 * tdep->wordsize);
1041 trad_frame_set_id (this_cache, frame_id_build (base, func));
1045 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
1046 struct frame_info *this_frame,
1047 struct trad_frame_cache *this_cache,
1050 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1051 0xd0 /* Offset to ucontext_t. */
1052 + 0x30 /* Offset to .reg. */,
1057 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
1058 struct frame_info *this_frame,
1059 struct trad_frame_cache *this_cache,
1062 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1063 0x80 /* Offset to ucontext_t. */
1064 + 0xe0 /* Offset to .reg. */,
1069 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
1070 struct frame_info *this_frame,
1071 struct trad_frame_cache *this_cache,
1074 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1075 0x40 /* Offset to ucontext_t. */
1076 + 0x1c /* Offset to .reg. */,
1081 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
1082 struct frame_info *this_frame,
1083 struct trad_frame_cache *this_cache,
1086 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1087 0x80 /* Offset to struct sigcontext. */
1088 + 0x38 /* Offset to .reg. */,
1092 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
1096 { 0x380000ac, -1 }, /* li r0, 172 */
1097 { 0x44000002, -1 }, /* sc */
1098 { TRAMP_SENTINEL_INSN },
1100 ppc32_linux_sigaction_cache_init
1102 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
1106 { 0x38210080, -1 }, /* addi r1,r1,128 */
1107 { 0x380000ac, -1 }, /* li r0, 172 */
1108 { 0x44000002, -1 }, /* sc */
1109 { TRAMP_SENTINEL_INSN },
1111 ppc64_linux_sigaction_cache_init
1113 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
1117 { 0x38000077, -1 }, /* li r0,119 */
1118 { 0x44000002, -1 }, /* sc */
1119 { TRAMP_SENTINEL_INSN },
1121 ppc32_linux_sighandler_cache_init
1123 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
1127 { 0x38210080, -1 }, /* addi r1,r1,128 */
1128 { 0x38000077, -1 }, /* li r0,119 */
1129 { 0x44000002, -1 }, /* sc */
1130 { TRAMP_SENTINEL_INSN },
1132 ppc64_linux_sighandler_cache_init
1136 /* Address to use for displaced stepping. When debugging a stand-alone
1137 SPU executable, entry_point_address () will point to an SPU local-store
1138 address and is thus not usable as displaced stepping location. We use
1139 the auxiliary vector to determine the PowerPC-side entry point address
1142 static CORE_ADDR ppc_linux_entry_point_addr = 0;
1145 ppc_linux_inferior_created (struct target_ops *target, int from_tty)
1147 ppc_linux_entry_point_addr = 0;
1151 ppc_linux_displaced_step_location (struct gdbarch *gdbarch)
1153 if (ppc_linux_entry_point_addr == 0)
1157 /* Determine entry point from target auxiliary vector. */
1158 if (target_auxv_search (¤t_target, AT_ENTRY, &addr) <= 0)
1159 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
1161 /* Make certain that the address points at real code, and not a
1162 function descriptor. */
1163 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
1166 /* Inferior calls also use the entry point as a breakpoint location.
1167 We don't want displaced stepping to interfere with those
1168 breakpoints, so leave space. */
1169 ppc_linux_entry_point_addr = addr + 2 * PPC_INSN_SIZE;
1172 return ppc_linux_entry_point_addr;
1176 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
1178 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
1180 /* If we do not have a target description with registers, then
1181 the special registers will not be included in the register set. */
1182 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1185 /* If we do, then it is safe to check the size. */
1186 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
1187 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
1190 /* Return the current system call's number present in the
1191 r0 register. When the function fails, it returns -1. */
1193 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
1196 struct regcache *regcache = get_thread_regcache (ptid);
1197 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1198 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1199 struct cleanup *cleanbuf;
1200 /* The content of a register */
1205 /* Make sure we're in a 32- or 64-bit machine */
1206 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
1208 buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte));
1210 cleanbuf = make_cleanup (xfree, buf);
1212 /* Getting the system call number from the register.
1213 When dealing with PowerPC architecture, this information
1214 is stored at 0th register. */
1215 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf);
1217 ret = extract_signed_integer (buf, tdep->wordsize, byte_order);
1218 do_cleanups (cleanbuf);
1224 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1226 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1228 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
1230 /* Set special TRAP register to -1 to prevent the kernel from
1231 messing with the PC we just installed, if we happen to be
1232 within an interrupted system call that the kernel wants to
1235 Note that after we return from the dummy call, the TRAP and
1236 ORIG_R3 registers will be automatically restored, and the
1237 kernel continues to restart the system call at this point. */
1238 if (ppc_linux_trap_reg_p (gdbarch))
1239 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
1243 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
1245 return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
1248 static const struct target_desc *
1249 ppc_linux_core_read_description (struct gdbarch *gdbarch,
1250 struct target_ops *target,
1253 asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
1254 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
1255 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
1256 asection *section = bfd_get_section_by_name (abfd, ".reg");
1260 switch (bfd_section_size (abfd, section))
1264 return tdesc_powerpc_cell32l;
1266 return tdesc_powerpc_vsx32l;
1268 return tdesc_powerpc_altivec32l;
1270 return tdesc_powerpc_32l;
1274 return tdesc_powerpc_cell64l;
1276 return tdesc_powerpc_vsx64l;
1278 return tdesc_powerpc_altivec64l;
1280 return tdesc_powerpc_64l;
1287 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1291 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
1293 return (*s == 'i' /* Literal number. */
1294 || (isdigit (*s) && s[1] == '('
1295 && isdigit (s[2])) /* Displacement. */
1296 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
1297 || isdigit (*s)); /* Register value. */
1300 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
1304 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
1305 struct stap_parse_info *p)
1307 if (isdigit (*p->arg))
1309 /* This temporary pointer is needed because we have to do a lookahead.
1310 We could be dealing with a register displacement, and in such case
1311 we would not need to do anything. */
1312 const char *s = p->arg;
1317 while (isdigit (*s))
1322 /* It is a register displacement indeed. Returning 0 means we are
1323 deferring the treatment of this case to the generic parser. */
1328 regname = alloca (len + 2);
1331 strncpy (regname + 1, p->arg, len);
1333 regname[len] = '\0';
1335 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
1336 error (_("Invalid register name `%s' on expression `%s'."),
1337 regname, p->saved_arg);
1339 write_exp_elt_opcode (OP_REGISTER);
1342 write_exp_string (str);
1343 write_exp_elt_opcode (OP_REGISTER);
1349 /* All the other tokens should be handled correctly by the generic
1357 /* Cell/B.E. active SPE context tracking support. */
1359 static struct objfile *spe_context_objfile = NULL;
1360 static CORE_ADDR spe_context_lm_addr = 0;
1361 static CORE_ADDR spe_context_offset = 0;
1363 static ptid_t spe_context_cache_ptid;
1364 static CORE_ADDR spe_context_cache_address;
1366 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
1367 to track whether we've loaded a version of libspe2 (as static or dynamic
1368 library) that provides the __spe_current_active_context variable. */
1370 ppc_linux_spe_context_lookup (struct objfile *objfile)
1372 struct minimal_symbol *sym;
1376 spe_context_objfile = NULL;
1377 spe_context_lm_addr = 0;
1378 spe_context_offset = 0;
1379 spe_context_cache_ptid = minus_one_ptid;
1380 spe_context_cache_address = 0;
1384 sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
1387 spe_context_objfile = objfile;
1388 spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
1389 spe_context_offset = SYMBOL_VALUE_ADDRESS (sym);
1390 spe_context_cache_ptid = minus_one_ptid;
1391 spe_context_cache_address = 0;
1397 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
1399 struct objfile *objfile;
1401 ppc_linux_spe_context_lookup (NULL);
1402 ALL_OBJFILES (objfile)
1403 ppc_linux_spe_context_lookup (objfile);
1407 ppc_linux_spe_context_solib_loaded (struct so_list *so)
1409 if (strstr (so->so_original_name, "/libspe") != NULL)
1411 solib_read_symbols (so, 0);
1412 ppc_linux_spe_context_lookup (so->objfile);
1417 ppc_linux_spe_context_solib_unloaded (struct so_list *so)
1419 if (so->objfile == spe_context_objfile)
1420 ppc_linux_spe_context_lookup (NULL);
1423 /* Retrieve contents of the N'th element in the current thread's
1424 linked SPE context list into ID and NPC. Return the address of
1425 said context element, or 0 if not found. */
1427 ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
1428 int n, int *id, unsigned int *npc)
1430 CORE_ADDR spe_context = 0;
1434 /* Quick exit if we have not found __spe_current_active_context. */
1435 if (!spe_context_objfile)
1438 /* Look up cached address of thread-local variable. */
1439 if (!ptid_equal (spe_context_cache_ptid, inferior_ptid))
1441 struct target_ops *target = ¤t_target;
1442 volatile struct gdb_exception ex;
1444 while (target && !target->to_get_thread_local_address)
1445 target = find_target_beneath (target);
1449 TRY_CATCH (ex, RETURN_MASK_ERROR)
1451 /* We do not call target_translate_tls_address here, because
1452 svr4_fetch_objfile_link_map may invalidate the frame chain,
1453 which must not do while inside a frame sniffer.
1455 Instead, we have cached the lm_addr value, and use that to
1456 directly call the target's to_get_thread_local_address. */
1457 spe_context_cache_address
1458 = target->to_get_thread_local_address (target, inferior_ptid,
1459 spe_context_lm_addr,
1460 spe_context_offset);
1461 spe_context_cache_ptid = inferior_ptid;
1468 /* Read variable value. */
1469 if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
1470 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1472 /* Cyle through to N'th linked list element. */
1473 for (i = 0; i < n && spe_context; i++)
1474 if (target_read_memory (spe_context + align_up (12, wordsize),
1475 buf, wordsize) == 0)
1476 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1480 /* Read current context. */
1482 && target_read_memory (spe_context, buf, 12) != 0)
1485 /* Extract data elements. */
1489 *id = extract_signed_integer (buf, 4, byte_order);
1491 *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
1498 /* Cell/B.E. cross-architecture unwinder support. */
1500 struct ppu2spu_cache
1502 struct frame_id frame_id;
1503 struct regcache *regcache;
1506 static struct gdbarch *
1507 ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
1509 struct ppu2spu_cache *cache = *this_cache;
1510 return get_regcache_arch (cache->regcache);
1514 ppu2spu_this_id (struct frame_info *this_frame,
1515 void **this_cache, struct frame_id *this_id)
1517 struct ppu2spu_cache *cache = *this_cache;
1518 *this_id = cache->frame_id;
1521 static struct value *
1522 ppu2spu_prev_register (struct frame_info *this_frame,
1523 void **this_cache, int regnum)
1525 struct ppu2spu_cache *cache = *this_cache;
1526 struct gdbarch *gdbarch = get_regcache_arch (cache->regcache);
1529 buf = alloca (register_size (gdbarch, regnum));
1531 if (regnum < gdbarch_num_regs (gdbarch))
1532 regcache_raw_read (cache->regcache, regnum, buf);
1534 gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf);
1536 return frame_unwind_got_bytes (this_frame, regnum, buf);
1541 struct gdbarch *gdbarch;
1544 gdb_byte gprs[128*16];
1548 ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf)
1550 struct ppu2spu_data *data = src;
1551 enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
1553 if (regnum >= 0 && regnum < SPU_NUM_GPRS)
1554 memcpy (buf, data->gprs + 16*regnum, 16);
1555 else if (regnum == SPU_ID_REGNUM)
1556 store_unsigned_integer (buf, 4, byte_order, data->id);
1557 else if (regnum == SPU_PC_REGNUM)
1558 store_unsigned_integer (buf, 4, byte_order, data->npc);
1560 return REG_UNAVAILABLE;
1566 ppu2spu_sniffer (const struct frame_unwind *self,
1567 struct frame_info *this_frame, void **this_prologue_cache)
1569 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1570 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1571 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1572 struct ppu2spu_data data;
1573 struct frame_info *fi;
1574 CORE_ADDR base, func, backchain, spe_context;
1578 /* Count the number of SPU contexts already in the frame chain. */
1579 for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
1580 if (get_frame_type (fi) == ARCH_FRAME
1581 && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
1584 base = get_frame_sp (this_frame);
1585 func = get_frame_pc (this_frame);
1586 if (target_read_memory (base, buf, tdep->wordsize))
1588 backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
1590 spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
1591 n, &data.id, &data.npc);
1592 if (spe_context && base <= spe_context && spe_context < backchain)
1596 /* Find gdbarch for SPU. */
1597 struct gdbarch_info info;
1598 gdbarch_info_init (&info);
1599 info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
1600 info.byte_order = BFD_ENDIAN_BIG;
1601 info.osabi = GDB_OSABI_LINUX;
1602 info.tdep_info = (void *) &data.id;
1603 data.gdbarch = gdbarch_find_by_info (info);
1607 xsnprintf (annex, sizeof annex, "%d/regs", data.id);
1608 if (target_read (¤t_target, TARGET_OBJECT_SPU, annex,
1609 data.gprs, 0, sizeof data.gprs)
1610 == sizeof data.gprs)
1612 struct ppu2spu_cache *cache
1613 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
1615 struct address_space *aspace = get_frame_address_space (this_frame);
1616 struct regcache *regcache = regcache_xmalloc (data.gdbarch, aspace);
1617 struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
1618 regcache_save (regcache, ppu2spu_unwind_register, &data);
1619 discard_cleanups (cleanups);
1621 cache->frame_id = frame_id_build (base, func);
1622 cache->regcache = regcache;
1623 *this_prologue_cache = cache;
1632 ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
1634 struct ppu2spu_cache *cache = this_cache;
1635 regcache_xfree (cache->regcache);
1638 static const struct frame_unwind ppu2spu_unwind = {
1640 default_frame_unwind_stop_reason,
1642 ppu2spu_prev_register,
1645 ppu2spu_dealloc_cache,
1651 ppc_linux_init_abi (struct gdbarch_info info,
1652 struct gdbarch *gdbarch)
1654 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1655 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
1657 linux_init_abi (info, gdbarch);
1659 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1660 128-bit, they are IBM long double, not IEEE quad long double as
1661 in the System V ABI PowerPC Processor Supplement. We can safely
1662 let them default to 128-bit, since the debug info will give the
1663 size of type actually used in each case. */
1664 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
1665 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
1667 /* Handle inferior calls during interrupted system calls. */
1668 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
1670 /* Get the syscall number from the arch's register. */
1671 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
1673 /* SystemTap functions. */
1674 set_gdbarch_stap_integer_prefix (gdbarch, "i");
1675 set_gdbarch_stap_register_indirection_prefix (gdbarch, "(");
1676 set_gdbarch_stap_register_indirection_suffix (gdbarch, ")");
1677 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
1678 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
1679 set_gdbarch_stap_parse_special_token (gdbarch,
1680 ppc_stap_parse_special_token);
1682 if (tdep->wordsize == 4)
1684 /* Until November 2001, gcc did not comply with the 32 bit SysV
1685 R4 ABI requirement that structures less than or equal to 8
1686 bytes should be returned in registers. Instead GCC was using
1687 the AIX/PowerOpen ABI - everything returned in memory
1688 (well ignoring vectors that is). When this was corrected, it
1689 wasn't fixed for GNU/Linux native platform. Use the
1690 PowerOpen struct convention. */
1691 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
1693 set_gdbarch_memory_remove_breakpoint (gdbarch,
1694 ppc_linux_memory_remove_breakpoint);
1696 /* Shared library handling. */
1697 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
1698 set_solib_svr4_fetch_link_map_offsets
1699 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1701 /* Setting the correct XML syscall filename. */
1702 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC);
1705 tramp_frame_prepend_unwinder (gdbarch,
1706 &ppc32_linux_sigaction_tramp_frame);
1707 tramp_frame_prepend_unwinder (gdbarch,
1708 &ppc32_linux_sighandler_tramp_frame);
1710 /* BFD target for core files. */
1711 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1712 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
1714 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
1716 /* Supported register sections. */
1717 if (tdesc_find_feature (info.target_desc,
1718 "org.gnu.gdb.power.vsx"))
1719 set_gdbarch_core_regset_sections (gdbarch,
1720 ppc_linux_vsx_regset_sections);
1721 else if (tdesc_find_feature (info.target_desc,
1722 "org.gnu.gdb.power.altivec"))
1723 set_gdbarch_core_regset_sections (gdbarch,
1724 ppc_linux_vmx_regset_sections);
1726 set_gdbarch_core_regset_sections (gdbarch,
1727 ppc_linux_fp_regset_sections);
1729 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
1731 powerpc_so_ops = svr4_so_ops;
1732 /* Override dynamic resolve function. */
1733 powerpc_so_ops.in_dynsym_resolve_code =
1734 powerpc_linux_in_dynsym_resolve_code;
1736 set_solib_ops (gdbarch, &powerpc_so_ops);
1738 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1741 if (tdep->wordsize == 8)
1743 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1744 function descriptors). */
1745 set_gdbarch_convert_from_func_ptr_addr
1746 (gdbarch, ppc64_linux_convert_from_func_ptr_addr);
1748 /* Shared library handling. */
1749 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
1750 set_solib_svr4_fetch_link_map_offsets
1751 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1753 /* Setting the correct XML syscall filename. */
1754 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64);
1757 tramp_frame_prepend_unwinder (gdbarch,
1758 &ppc64_linux_sigaction_tramp_frame);
1759 tramp_frame_prepend_unwinder (gdbarch,
1760 &ppc64_linux_sighandler_tramp_frame);
1762 /* BFD target for core files. */
1763 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1764 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
1766 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
1768 /* Supported register sections. */
1769 if (tdesc_find_feature (info.target_desc,
1770 "org.gnu.gdb.power.vsx"))
1771 set_gdbarch_core_regset_sections (gdbarch,
1772 ppc64_linux_vsx_regset_sections);
1773 else if (tdesc_find_feature (info.target_desc,
1774 "org.gnu.gdb.power.altivec"))
1775 set_gdbarch_core_regset_sections (gdbarch,
1776 ppc64_linux_vmx_regset_sections);
1778 set_gdbarch_core_regset_sections (gdbarch,
1779 ppc64_linux_fp_regset_sections);
1781 set_gdbarch_regset_from_core_section (gdbarch,
1782 ppc_linux_regset_from_core_section);
1783 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
1785 /* Enable TLS support. */
1786 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1787 svr4_fetch_objfile_link_map);
1791 const struct tdesc_feature *feature;
1793 /* If we have target-described registers, then we can safely
1794 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1795 (whether they are described or not). */
1796 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
1797 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
1799 /* If they are present, then assign them to the reserved number. */
1800 feature = tdesc_find_feature (info.target_desc,
1801 "org.gnu.gdb.power.linux");
1802 if (feature != NULL)
1804 tdesc_numbered_register (feature, tdesc_data,
1805 PPC_ORIG_R3_REGNUM, "orig_r3");
1806 tdesc_numbered_register (feature, tdesc_data,
1807 PPC_TRAP_REGNUM, "trap");
1811 /* Enable Cell/B.E. if supported by the target. */
1812 if (tdesc_compatible_p (info.target_desc,
1813 bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
1815 /* Cell/B.E. multi-architecture support. */
1816 set_spu_solib_ops (gdbarch);
1818 /* Cell/B.E. cross-architecture unwinder support. */
1819 frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
1821 /* The default displaced_step_at_entry_point doesn't work for
1822 SPU stand-alone executables. */
1823 set_gdbarch_displaced_step_location (gdbarch,
1824 ppc_linux_displaced_step_location);
1827 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
1830 /* Provide a prototype to silence -Wmissing-prototypes. */
1831 extern initialize_file_ftype _initialize_ppc_linux_tdep;
1834 _initialize_ppc_linux_tdep (void)
1836 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1837 64-bit PowerPC, and the older rs6k. */
1838 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
1839 ppc_linux_init_abi);
1840 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
1841 ppc_linux_init_abi);
1842 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
1843 ppc_linux_init_abi);
1845 /* Attach to inferior_created observer. */
1846 observer_attach_inferior_created (ppc_linux_inferior_created);
1848 /* Attach to observers to track __spe_current_active_context. */
1849 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created);
1850 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded);
1851 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded);
1853 /* Initialize the Linux target descriptions. */
1854 initialize_tdesc_powerpc_32l ();
1855 initialize_tdesc_powerpc_altivec32l ();
1856 initialize_tdesc_powerpc_cell32l ();
1857 initialize_tdesc_powerpc_vsx32l ();
1858 initialize_tdesc_powerpc_isa205_32l ();
1859 initialize_tdesc_powerpc_isa205_altivec32l ();
1860 initialize_tdesc_powerpc_isa205_vsx32l ();
1861 initialize_tdesc_powerpc_64l ();
1862 initialize_tdesc_powerpc_altivec64l ();
1863 initialize_tdesc_powerpc_cell64l ();
1864 initialize_tdesc_powerpc_vsx64l ();
1865 initialize_tdesc_powerpc_isa205_64l ();
1866 initialize_tdesc_powerpc_isa205_altivec64l ();
1867 initialize_tdesc_powerpc_isa205_vsx64l ();
1868 initialize_tdesc_powerpc_e500l ();