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) */
394 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
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) */
425 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
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) */
450 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
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
);
651 if ((strcmp (SYMBOL_LINKAGE_NAME (sym
), "__glink") == 0)
652 || (strcmp (SYMBOL_LINKAGE_NAME (sym
), "__glink_PLTresolve") == 0))
658 /* Follow PLT stub to actual routine. */
661 ppc_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
663 int insnbuf
[POWERPC32_PLT_STUB_LEN
];
664 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
665 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
666 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
667 CORE_ADDR target
= 0;
669 if (insns_match_pattern (pc
, powerpc32_plt_stub
, insnbuf
))
674 Branch target is in r11. */
676 target
= (insn_d_field (insnbuf
[0]) << 16) | insn_d_field (insnbuf
[1]);
677 target
= read_memory_unsigned_integer (target
, 4, byte_order
);
680 if (insns_match_pattern (pc
, powerpc32_plt_stub_so
, insnbuf
))
684 Branch target is in r11. */
686 target
= get_frame_register_unsigned (frame
, tdep
->ppc_gp0_regnum
+ 30)
687 + insn_d_field (insnbuf
[0]);
688 target
= read_memory_unsigned_integer (target
, 4, byte_order
);
694 /* Given that we've begun executing a call trampoline at PC, return
695 the entry point of the function the trampoline will go to. */
697 ppc64_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
699 unsigned int ppc64_standard_linkage1_insn
[PPC64_STANDARD_LINKAGE1_LEN
];
700 unsigned int ppc64_standard_linkage2_insn
[PPC64_STANDARD_LINKAGE2_LEN
];
701 unsigned int ppc64_standard_linkage3_insn
[PPC64_STANDARD_LINKAGE3_LEN
];
704 if (insns_match_pattern (pc
, ppc64_standard_linkage1
,
705 ppc64_standard_linkage1_insn
))
706 pc
= ppc64_standard_linkage1_target (frame
, pc
,
707 ppc64_standard_linkage1_insn
);
708 else if (insns_match_pattern (pc
, ppc64_standard_linkage2
,
709 ppc64_standard_linkage2_insn
))
710 pc
= ppc64_standard_linkage2_target (frame
, pc
,
711 ppc64_standard_linkage2_insn
);
712 else if (insns_match_pattern (pc
, ppc64_standard_linkage3
,
713 ppc64_standard_linkage3_insn
))
714 pc
= ppc64_standard_linkage3_target (frame
, pc
,
715 ppc64_standard_linkage3_insn
);
719 /* The PLT descriptor will either point to the already resolved target
720 address, or else to a glink stub. As the latter carry synthetic @plt
721 symbols, find_solib_trampoline_target should be able to resolve them. */
722 target
= find_solib_trampoline_target (frame
, pc
);
723 return target
? target
: pc
;
727 /* Support for convert_from_func_ptr_addr (ARCH, ADDR, TARG) on PPC64
730 Usually a function pointer's representation is simply the address
731 of the function. On GNU/Linux on the PowerPC however, a function
732 pointer may be a pointer to a function descriptor.
734 For PPC64, a function descriptor is a TOC entry, in a data section,
735 which contains three words: the first word is the address of the
736 function, the second word is the TOC pointer (r2), and the third word
737 is the static chain value.
739 Throughout GDB it is currently assumed that a function pointer contains
740 the address of the function, which is not easy to fix. In addition, the
741 conversion of a function address to a function pointer would
742 require allocation of a TOC entry in the inferior's memory space,
743 with all its drawbacks. To be able to call C++ virtual methods in
744 the inferior (which are called via function pointers),
745 find_function_addr uses this function to get the function address
746 from a function pointer.
748 If ADDR points at what is clearly a function descriptor, transform
749 it into the address of the corresponding function, if needed. Be
750 conservative, otherwise GDB will do the transformation on any
751 random addresses such as occur when there is no symbol table. */
754 ppc64_linux_convert_from_func_ptr_addr (struct gdbarch
*gdbarch
,
756 struct target_ops
*targ
)
758 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
759 struct target_section
*s
= target_section_by_addr (targ
, addr
);
761 /* Check if ADDR points to a function descriptor. */
762 if (s
&& strcmp (s
->the_bfd_section
->name
, ".opd") == 0)
764 /* There may be relocations that need to be applied to the .opd
765 section. Unfortunately, this function may be called at a time
766 where these relocations have not yet been performed -- this can
767 happen for example shortly after a library has been loaded with
768 dlopen, but ld.so has not yet applied the relocations.
770 To cope with both the case where the relocation has been applied,
771 and the case where it has not yet been applied, we do *not* read
772 the (maybe) relocated value from target memory, but we instead
773 read the non-relocated value from the BFD, and apply the relocation
776 This makes the assumption that all .opd entries are always relocated
777 by the same offset the section itself was relocated. This should
778 always be the case for GNU/Linux executables and shared libraries.
779 Note that other kind of object files (e.g. those added via
780 add-symbol-files) will currently never end up here anyway, as this
781 function accesses *target* sections only; only the main exec and
782 shared libraries are ever added to the target. */
787 res
= bfd_get_section_contents (s
->bfd
, s
->the_bfd_section
,
788 &buf
, addr
- s
->addr
, 8);
790 return extract_unsigned_integer (buf
, 8, byte_order
)
791 - bfd_section_vma (s
->bfd
, s
->the_bfd_section
) + s
->addr
;
797 /* Wrappers to handle Linux-only registers. */
800 ppc_linux_supply_gregset (const struct regset
*regset
,
801 struct regcache
*regcache
,
802 int regnum
, const void *gregs
, size_t len
)
804 const struct ppc_reg_offsets
*offsets
= regset
->descr
;
806 ppc_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
808 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache
)))
810 /* "orig_r3" is stored 2 slots after "pc". */
811 if (regnum
== -1 || regnum
== PPC_ORIG_R3_REGNUM
)
812 ppc_supply_reg (regcache
, PPC_ORIG_R3_REGNUM
, gregs
,
813 offsets
->pc_offset
+ 2 * offsets
->gpr_size
,
816 /* "trap" is stored 8 slots after "pc". */
817 if (regnum
== -1 || regnum
== PPC_TRAP_REGNUM
)
818 ppc_supply_reg (regcache
, PPC_TRAP_REGNUM
, gregs
,
819 offsets
->pc_offset
+ 8 * offsets
->gpr_size
,
825 ppc_linux_collect_gregset (const struct regset
*regset
,
826 const struct regcache
*regcache
,
827 int regnum
, void *gregs
, size_t len
)
829 const struct ppc_reg_offsets
*offsets
= regset
->descr
;
831 /* Clear areas in the linux gregset not written elsewhere. */
833 memset (gregs
, 0, len
);
835 ppc_collect_gregset (regset
, regcache
, regnum
, gregs
, len
);
837 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache
)))
839 /* "orig_r3" is stored 2 slots after "pc". */
840 if (regnum
== -1 || regnum
== PPC_ORIG_R3_REGNUM
)
841 ppc_collect_reg (regcache
, PPC_ORIG_R3_REGNUM
, gregs
,
842 offsets
->pc_offset
+ 2 * offsets
->gpr_size
,
845 /* "trap" is stored 8 slots after "pc". */
846 if (regnum
== -1 || regnum
== PPC_TRAP_REGNUM
)
847 ppc_collect_reg (regcache
, PPC_TRAP_REGNUM
, gregs
,
848 offsets
->pc_offset
+ 8 * offsets
->gpr_size
,
853 /* Regset descriptions. */
854 static const struct ppc_reg_offsets ppc32_linux_reg_offsets
=
856 /* General-purpose registers. */
857 /* .r0_offset = */ 0,
860 /* .pc_offset = */ 128,
861 /* .ps_offset = */ 132,
862 /* .cr_offset = */ 152,
863 /* .lr_offset = */ 144,
864 /* .ctr_offset = */ 140,
865 /* .xer_offset = */ 148,
866 /* .mq_offset = */ 156,
868 /* Floating-point registers. */
869 /* .f0_offset = */ 0,
870 /* .fpscr_offset = */ 256,
871 /* .fpscr_size = */ 8,
873 /* AltiVec registers. */
874 /* .vr0_offset = */ 0,
875 /* .vscr_offset = */ 512 + 12,
876 /* .vrsave_offset = */ 528
879 static const struct ppc_reg_offsets ppc64_linux_reg_offsets
=
881 /* General-purpose registers. */
882 /* .r0_offset = */ 0,
885 /* .pc_offset = */ 256,
886 /* .ps_offset = */ 264,
887 /* .cr_offset = */ 304,
888 /* .lr_offset = */ 288,
889 /* .ctr_offset = */ 280,
890 /* .xer_offset = */ 296,
891 /* .mq_offset = */ 312,
893 /* Floating-point registers. */
894 /* .f0_offset = */ 0,
895 /* .fpscr_offset = */ 256,
896 /* .fpscr_size = */ 8,
898 /* AltiVec registers. */
899 /* .vr0_offset = */ 0,
900 /* .vscr_offset = */ 512 + 12,
901 /* .vrsave_offset = */ 528
904 static const struct regset ppc32_linux_gregset
= {
905 &ppc32_linux_reg_offsets
,
906 ppc_linux_supply_gregset
,
907 ppc_linux_collect_gregset
,
911 static const struct regset ppc64_linux_gregset
= {
912 &ppc64_linux_reg_offsets
,
913 ppc_linux_supply_gregset
,
914 ppc_linux_collect_gregset
,
918 static const struct regset ppc32_linux_fpregset
= {
919 &ppc32_linux_reg_offsets
,
921 ppc_collect_fpregset
,
925 static const struct regset ppc32_linux_vrregset
= {
926 &ppc32_linux_reg_offsets
,
928 ppc_collect_vrregset
,
932 static const struct regset ppc32_linux_vsxregset
= {
933 &ppc32_linux_reg_offsets
,
934 ppc_supply_vsxregset
,
935 ppc_collect_vsxregset
,
939 const struct regset
*
940 ppc_linux_gregset (int wordsize
)
942 return wordsize
== 8 ? &ppc64_linux_gregset
: &ppc32_linux_gregset
;
945 const struct regset
*
946 ppc_linux_fpregset (void)
948 return &ppc32_linux_fpregset
;
951 static const struct regset
*
952 ppc_linux_regset_from_core_section (struct gdbarch
*core_arch
,
953 const char *sect_name
, size_t sect_size
)
955 struct gdbarch_tdep
*tdep
= gdbarch_tdep (core_arch
);
956 if (strcmp (sect_name
, ".reg") == 0)
958 if (tdep
->wordsize
== 4)
959 return &ppc32_linux_gregset
;
961 return &ppc64_linux_gregset
;
963 if (strcmp (sect_name
, ".reg2") == 0)
964 return &ppc32_linux_fpregset
;
965 if (strcmp (sect_name
, ".reg-ppc-vmx") == 0)
966 return &ppc32_linux_vrregset
;
967 if (strcmp (sect_name
, ".reg-ppc-vsx") == 0)
968 return &ppc32_linux_vsxregset
;
973 ppc_linux_sigtramp_cache (struct frame_info
*this_frame
,
974 struct trad_frame_cache
*this_cache
,
975 CORE_ADDR func
, LONGEST offset
,
983 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
984 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
985 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
987 base
= get_frame_register_unsigned (this_frame
,
988 gdbarch_sp_regnum (gdbarch
));
989 if (bias
> 0 && get_frame_pc (this_frame
) != func
)
990 /* See below, some signal trampolines increment the stack as their
991 first instruction, need to compensate for that. */
994 /* Find the address of the register buffer pointer. */
995 regs
= base
+ offset
;
996 /* Use that to find the address of the corresponding register
998 gpregs
= read_memory_unsigned_integer (regs
, tdep
->wordsize
, byte_order
);
999 fpregs
= gpregs
+ 48 * tdep
->wordsize
;
1001 /* General purpose. */
1002 for (i
= 0; i
< 32; i
++)
1004 int regnum
= i
+ tdep
->ppc_gp0_regnum
;
1005 trad_frame_set_reg_addr (this_cache
,
1006 regnum
, gpregs
+ i
* tdep
->wordsize
);
1008 trad_frame_set_reg_addr (this_cache
,
1009 gdbarch_pc_regnum (gdbarch
),
1010 gpregs
+ 32 * tdep
->wordsize
);
1011 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_ctr_regnum
,
1012 gpregs
+ 35 * tdep
->wordsize
);
1013 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_lr_regnum
,
1014 gpregs
+ 36 * tdep
->wordsize
);
1015 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_xer_regnum
,
1016 gpregs
+ 37 * tdep
->wordsize
);
1017 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_cr_regnum
,
1018 gpregs
+ 38 * tdep
->wordsize
);
1020 if (ppc_linux_trap_reg_p (gdbarch
))
1022 trad_frame_set_reg_addr (this_cache
, PPC_ORIG_R3_REGNUM
,
1023 gpregs
+ 34 * tdep
->wordsize
);
1024 trad_frame_set_reg_addr (this_cache
, PPC_TRAP_REGNUM
,
1025 gpregs
+ 40 * tdep
->wordsize
);
1028 if (ppc_floating_point_unit_p (gdbarch
))
1030 /* Floating point registers. */
1031 for (i
= 0; i
< 32; i
++)
1033 int regnum
= i
+ gdbarch_fp0_regnum (gdbarch
);
1034 trad_frame_set_reg_addr (this_cache
, regnum
,
1035 fpregs
+ i
* tdep
->wordsize
);
1037 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_fpscr_regnum
,
1038 fpregs
+ 32 * tdep
->wordsize
);
1040 trad_frame_set_id (this_cache
, frame_id_build (base
, func
));
1044 ppc32_linux_sigaction_cache_init (const struct tramp_frame
*self
,
1045 struct frame_info
*this_frame
,
1046 struct trad_frame_cache
*this_cache
,
1049 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
1050 0xd0 /* Offset to ucontext_t. */
1051 + 0x30 /* Offset to .reg. */,
1056 ppc64_linux_sigaction_cache_init (const struct tramp_frame
*self
,
1057 struct frame_info
*this_frame
,
1058 struct trad_frame_cache
*this_cache
,
1061 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
1062 0x80 /* Offset to ucontext_t. */
1063 + 0xe0 /* Offset to .reg. */,
1068 ppc32_linux_sighandler_cache_init (const struct tramp_frame
*self
,
1069 struct frame_info
*this_frame
,
1070 struct trad_frame_cache
*this_cache
,
1073 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
1074 0x40 /* Offset to ucontext_t. */
1075 + 0x1c /* Offset to .reg. */,
1080 ppc64_linux_sighandler_cache_init (const struct tramp_frame
*self
,
1081 struct frame_info
*this_frame
,
1082 struct trad_frame_cache
*this_cache
,
1085 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
1086 0x80 /* Offset to struct sigcontext. */
1087 + 0x38 /* Offset to .reg. */,
1091 static struct tramp_frame ppc32_linux_sigaction_tramp_frame
= {
1095 { 0x380000ac, -1 }, /* li r0, 172 */
1096 { 0x44000002, -1 }, /* sc */
1097 { TRAMP_SENTINEL_INSN
},
1099 ppc32_linux_sigaction_cache_init
1101 static struct tramp_frame ppc64_linux_sigaction_tramp_frame
= {
1105 { 0x38210080, -1 }, /* addi r1,r1,128 */
1106 { 0x380000ac, -1 }, /* li r0, 172 */
1107 { 0x44000002, -1 }, /* sc */
1108 { TRAMP_SENTINEL_INSN
},
1110 ppc64_linux_sigaction_cache_init
1112 static struct tramp_frame ppc32_linux_sighandler_tramp_frame
= {
1116 { 0x38000077, -1 }, /* li r0,119 */
1117 { 0x44000002, -1 }, /* sc */
1118 { TRAMP_SENTINEL_INSN
},
1120 ppc32_linux_sighandler_cache_init
1122 static struct tramp_frame ppc64_linux_sighandler_tramp_frame
= {
1126 { 0x38210080, -1 }, /* addi r1,r1,128 */
1127 { 0x38000077, -1 }, /* li r0,119 */
1128 { 0x44000002, -1 }, /* sc */
1129 { TRAMP_SENTINEL_INSN
},
1131 ppc64_linux_sighandler_cache_init
1135 /* Address to use for displaced stepping. When debugging a stand-alone
1136 SPU executable, entry_point_address () will point to an SPU local-store
1137 address and is thus not usable as displaced stepping location. We use
1138 the auxiliary vector to determine the PowerPC-side entry point address
1141 static CORE_ADDR ppc_linux_entry_point_addr
= 0;
1144 ppc_linux_inferior_created (struct target_ops
*target
, int from_tty
)
1146 ppc_linux_entry_point_addr
= 0;
1150 ppc_linux_displaced_step_location (struct gdbarch
*gdbarch
)
1152 if (ppc_linux_entry_point_addr
== 0)
1156 /* Determine entry point from target auxiliary vector. */
1157 if (target_auxv_search (¤t_target
, AT_ENTRY
, &addr
) <= 0)
1158 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
1160 /* Make certain that the address points at real code, and not a
1161 function descriptor. */
1162 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
1165 /* Inferior calls also use the entry point as a breakpoint location.
1166 We don't want displaced stepping to interfere with those
1167 breakpoints, so leave space. */
1168 ppc_linux_entry_point_addr
= addr
+ 2 * PPC_INSN_SIZE
;
1171 return ppc_linux_entry_point_addr
;
1175 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
1177 ppc_linux_trap_reg_p (struct gdbarch
*gdbarch
)
1179 /* If we do not have a target description with registers, then
1180 the special registers will not be included in the register set. */
1181 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
1184 /* If we do, then it is safe to check the size. */
1185 return register_size (gdbarch
, PPC_ORIG_R3_REGNUM
) > 0
1186 && register_size (gdbarch
, PPC_TRAP_REGNUM
) > 0;
1189 /* Return the current system call's number present in the
1190 r0 register. When the function fails, it returns -1. */
1192 ppc_linux_get_syscall_number (struct gdbarch
*gdbarch
,
1195 struct regcache
*regcache
= get_thread_regcache (ptid
);
1196 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1197 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1198 struct cleanup
*cleanbuf
;
1199 /* The content of a register */
1204 /* Make sure we're in a 32- or 64-bit machine */
1205 gdb_assert (tdep
->wordsize
== 4 || tdep
->wordsize
== 8);
1207 buf
= (gdb_byte
*) xmalloc (tdep
->wordsize
* sizeof (gdb_byte
));
1209 cleanbuf
= make_cleanup (xfree
, buf
);
1211 /* Getting the system call number from the register.
1212 When dealing with PowerPC architecture, this information
1213 is stored at 0th register. */
1214 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
, buf
);
1216 ret
= extract_signed_integer (buf
, tdep
->wordsize
, byte_order
);
1217 do_cleanups (cleanbuf
);
1223 ppc_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1225 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1227 regcache_cooked_write_unsigned (regcache
, gdbarch_pc_regnum (gdbarch
), pc
);
1229 /* Set special TRAP register to -1 to prevent the kernel from
1230 messing with the PC we just installed, if we happen to be
1231 within an interrupted system call that the kernel wants to
1234 Note that after we return from the dummy call, the TRAP and
1235 ORIG_R3 registers will be automatically restored, and the
1236 kernel continues to restart the system call at this point. */
1237 if (ppc_linux_trap_reg_p (gdbarch
))
1238 regcache_cooked_write_unsigned (regcache
, PPC_TRAP_REGNUM
, -1);
1242 ppc_linux_spu_section (bfd
*abfd
, asection
*asect
, void *user_data
)
1244 return strncmp (bfd_section_name (abfd
, asect
), "SPU/", 4) == 0;
1247 static const struct target_desc
*
1248 ppc_linux_core_read_description (struct gdbarch
*gdbarch
,
1249 struct target_ops
*target
,
1252 asection
*cell
= bfd_sections_find_if (abfd
, ppc_linux_spu_section
, NULL
);
1253 asection
*altivec
= bfd_get_section_by_name (abfd
, ".reg-ppc-vmx");
1254 asection
*vsx
= bfd_get_section_by_name (abfd
, ".reg-ppc-vsx");
1255 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
1259 switch (bfd_section_size (abfd
, section
))
1263 return tdesc_powerpc_cell32l
;
1265 return tdesc_powerpc_vsx32l
;
1267 return tdesc_powerpc_altivec32l
;
1269 return tdesc_powerpc_32l
;
1273 return tdesc_powerpc_cell64l
;
1275 return tdesc_powerpc_vsx64l
;
1277 return tdesc_powerpc_altivec64l
;
1279 return tdesc_powerpc_64l
;
1286 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1290 ppc_stap_is_single_operand (struct gdbarch
*gdbarch
, const char *s
)
1292 return (*s
== 'i' /* Literal number. */
1293 || (isdigit (*s
) && s
[1] == '('
1294 && isdigit (s
[2])) /* Displacement. */
1295 || (*s
== '(' && isdigit (s
[1])) /* Register indirection. */
1296 || isdigit (*s
)); /* Register value. */
1299 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
1303 ppc_stap_parse_special_token (struct gdbarch
*gdbarch
,
1304 struct stap_parse_info
*p
)
1306 if (isdigit (*p
->arg
))
1308 /* This temporary pointer is needed because we have to do a lookahead.
1309 We could be dealing with a register displacement, and in such case
1310 we would not need to do anything. */
1311 const char *s
= p
->arg
;
1316 while (isdigit (*s
))
1321 /* It is a register displacement indeed. Returning 0 means we are
1322 deferring the treatment of this case to the generic parser. */
1327 regname
= alloca (len
+ 2);
1330 strncpy (regname
+ 1, p
->arg
, len
);
1332 regname
[len
] = '\0';
1334 if (user_reg_map_name_to_regnum (gdbarch
, regname
, len
) == -1)
1335 error (_("Invalid register name `%s' on expression `%s'."),
1336 regname
, p
->saved_arg
);
1338 write_exp_elt_opcode (OP_REGISTER
);
1341 write_exp_string (str
);
1342 write_exp_elt_opcode (OP_REGISTER
);
1348 /* All the other tokens should be handled correctly by the generic
1356 /* Cell/B.E. active SPE context tracking support. */
1358 static struct objfile
*spe_context_objfile
= NULL
;
1359 static CORE_ADDR spe_context_lm_addr
= 0;
1360 static CORE_ADDR spe_context_offset
= 0;
1362 static ptid_t spe_context_cache_ptid
;
1363 static CORE_ADDR spe_context_cache_address
;
1365 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
1366 to track whether we've loaded a version of libspe2 (as static or dynamic
1367 library) that provides the __spe_current_active_context variable. */
1369 ppc_linux_spe_context_lookup (struct objfile
*objfile
)
1371 struct minimal_symbol
*sym
;
1375 spe_context_objfile
= NULL
;
1376 spe_context_lm_addr
= 0;
1377 spe_context_offset
= 0;
1378 spe_context_cache_ptid
= minus_one_ptid
;
1379 spe_context_cache_address
= 0;
1383 sym
= lookup_minimal_symbol ("__spe_current_active_context", NULL
, objfile
);
1386 spe_context_objfile
= objfile
;
1387 spe_context_lm_addr
= svr4_fetch_objfile_link_map (objfile
);
1388 spe_context_offset
= SYMBOL_VALUE_ADDRESS (sym
);
1389 spe_context_cache_ptid
= minus_one_ptid
;
1390 spe_context_cache_address
= 0;
1396 ppc_linux_spe_context_inferior_created (struct target_ops
*t
, int from_tty
)
1398 struct objfile
*objfile
;
1400 ppc_linux_spe_context_lookup (NULL
);
1401 ALL_OBJFILES (objfile
)
1402 ppc_linux_spe_context_lookup (objfile
);
1406 ppc_linux_spe_context_solib_loaded (struct so_list
*so
)
1408 if (strstr (so
->so_original_name
, "/libspe") != NULL
)
1410 solib_read_symbols (so
, 0);
1411 ppc_linux_spe_context_lookup (so
->objfile
);
1416 ppc_linux_spe_context_solib_unloaded (struct so_list
*so
)
1418 if (so
->objfile
== spe_context_objfile
)
1419 ppc_linux_spe_context_lookup (NULL
);
1422 /* Retrieve contents of the N'th element in the current thread's
1423 linked SPE context list into ID and NPC. Return the address of
1424 said context element, or 0 if not found. */
1426 ppc_linux_spe_context (int wordsize
, enum bfd_endian byte_order
,
1427 int n
, int *id
, unsigned int *npc
)
1429 CORE_ADDR spe_context
= 0;
1433 /* Quick exit if we have not found __spe_current_active_context. */
1434 if (!spe_context_objfile
)
1437 /* Look up cached address of thread-local variable. */
1438 if (!ptid_equal (spe_context_cache_ptid
, inferior_ptid
))
1440 struct target_ops
*target
= ¤t_target
;
1441 volatile struct gdb_exception ex
;
1443 while (target
&& !target
->to_get_thread_local_address
)
1444 target
= find_target_beneath (target
);
1448 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1450 /* We do not call target_translate_tls_address here, because
1451 svr4_fetch_objfile_link_map may invalidate the frame chain,
1452 which must not do while inside a frame sniffer.
1454 Instead, we have cached the lm_addr value, and use that to
1455 directly call the target's to_get_thread_local_address. */
1456 spe_context_cache_address
1457 = target
->to_get_thread_local_address (target
, inferior_ptid
,
1458 spe_context_lm_addr
,
1459 spe_context_offset
);
1460 spe_context_cache_ptid
= inferior_ptid
;
1467 /* Read variable value. */
1468 if (target_read_memory (spe_context_cache_address
, buf
, wordsize
) == 0)
1469 spe_context
= extract_unsigned_integer (buf
, wordsize
, byte_order
);
1471 /* Cyle through to N'th linked list element. */
1472 for (i
= 0; i
< n
&& spe_context
; i
++)
1473 if (target_read_memory (spe_context
+ align_up (12, wordsize
),
1474 buf
, wordsize
) == 0)
1475 spe_context
= extract_unsigned_integer (buf
, wordsize
, byte_order
);
1479 /* Read current context. */
1481 && target_read_memory (spe_context
, buf
, 12) != 0)
1484 /* Extract data elements. */
1488 *id
= extract_signed_integer (buf
, 4, byte_order
);
1490 *npc
= extract_unsigned_integer (buf
+ 4, 4, byte_order
);
1497 /* Cell/B.E. cross-architecture unwinder support. */
1499 struct ppu2spu_cache
1501 struct frame_id frame_id
;
1502 struct regcache
*regcache
;
1505 static struct gdbarch
*
1506 ppu2spu_prev_arch (struct frame_info
*this_frame
, void **this_cache
)
1508 struct ppu2spu_cache
*cache
= *this_cache
;
1509 return get_regcache_arch (cache
->regcache
);
1513 ppu2spu_this_id (struct frame_info
*this_frame
,
1514 void **this_cache
, struct frame_id
*this_id
)
1516 struct ppu2spu_cache
*cache
= *this_cache
;
1517 *this_id
= cache
->frame_id
;
1520 static struct value
*
1521 ppu2spu_prev_register (struct frame_info
*this_frame
,
1522 void **this_cache
, int regnum
)
1524 struct ppu2spu_cache
*cache
= *this_cache
;
1525 struct gdbarch
*gdbarch
= get_regcache_arch (cache
->regcache
);
1528 buf
= alloca (register_size (gdbarch
, regnum
));
1530 if (regnum
< gdbarch_num_regs (gdbarch
))
1531 regcache_raw_read (cache
->regcache
, regnum
, buf
);
1533 gdbarch_pseudo_register_read (gdbarch
, cache
->regcache
, regnum
, buf
);
1535 return frame_unwind_got_bytes (this_frame
, regnum
, buf
);
1540 struct gdbarch
*gdbarch
;
1543 gdb_byte gprs
[128*16];
1547 ppu2spu_unwind_register (void *src
, int regnum
, gdb_byte
*buf
)
1549 struct ppu2spu_data
*data
= src
;
1550 enum bfd_endian byte_order
= gdbarch_byte_order (data
->gdbarch
);
1552 if (regnum
>= 0 && regnum
< SPU_NUM_GPRS
)
1553 memcpy (buf
, data
->gprs
+ 16*regnum
, 16);
1554 else if (regnum
== SPU_ID_REGNUM
)
1555 store_unsigned_integer (buf
, 4, byte_order
, data
->id
);
1556 else if (regnum
== SPU_PC_REGNUM
)
1557 store_unsigned_integer (buf
, 4, byte_order
, data
->npc
);
1559 return REG_UNAVAILABLE
;
1565 ppu2spu_sniffer (const struct frame_unwind
*self
,
1566 struct frame_info
*this_frame
, void **this_prologue_cache
)
1568 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1569 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1570 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1571 struct ppu2spu_data data
;
1572 struct frame_info
*fi
;
1573 CORE_ADDR base
, func
, backchain
, spe_context
;
1577 /* Count the number of SPU contexts already in the frame chain. */
1578 for (fi
= get_next_frame (this_frame
); fi
; fi
= get_next_frame (fi
))
1579 if (get_frame_type (fi
) == ARCH_FRAME
1580 && gdbarch_bfd_arch_info (get_frame_arch (fi
))->arch
== bfd_arch_spu
)
1583 base
= get_frame_sp (this_frame
);
1584 func
= get_frame_pc (this_frame
);
1585 if (target_read_memory (base
, buf
, tdep
->wordsize
))
1587 backchain
= extract_unsigned_integer (buf
, tdep
->wordsize
, byte_order
);
1589 spe_context
= ppc_linux_spe_context (tdep
->wordsize
, byte_order
,
1590 n
, &data
.id
, &data
.npc
);
1591 if (spe_context
&& base
<= spe_context
&& spe_context
< backchain
)
1595 /* Find gdbarch for SPU. */
1596 struct gdbarch_info info
;
1597 gdbarch_info_init (&info
);
1598 info
.bfd_arch_info
= bfd_lookup_arch (bfd_arch_spu
, bfd_mach_spu
);
1599 info
.byte_order
= BFD_ENDIAN_BIG
;
1600 info
.osabi
= GDB_OSABI_LINUX
;
1601 info
.tdep_info
= (void *) &data
.id
;
1602 data
.gdbarch
= gdbarch_find_by_info (info
);
1606 xsnprintf (annex
, sizeof annex
, "%d/regs", data
.id
);
1607 if (target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1608 data
.gprs
, 0, sizeof data
.gprs
)
1609 == sizeof data
.gprs
)
1611 struct ppu2spu_cache
*cache
1612 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache
);
1614 struct address_space
*aspace
= get_frame_address_space (this_frame
);
1615 struct regcache
*regcache
= regcache_xmalloc (data
.gdbarch
, aspace
);
1616 struct cleanup
*cleanups
= make_cleanup_regcache_xfree (regcache
);
1617 regcache_save (regcache
, ppu2spu_unwind_register
, &data
);
1618 discard_cleanups (cleanups
);
1620 cache
->frame_id
= frame_id_build (base
, func
);
1621 cache
->regcache
= regcache
;
1622 *this_prologue_cache
= cache
;
1631 ppu2spu_dealloc_cache (struct frame_info
*self
, void *this_cache
)
1633 struct ppu2spu_cache
*cache
= this_cache
;
1634 regcache_xfree (cache
->regcache
);
1637 static const struct frame_unwind ppu2spu_unwind
= {
1639 default_frame_unwind_stop_reason
,
1641 ppu2spu_prev_register
,
1644 ppu2spu_dealloc_cache
,
1650 ppc_linux_init_abi (struct gdbarch_info info
,
1651 struct gdbarch
*gdbarch
)
1653 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1654 struct tdesc_arch_data
*tdesc_data
= (void *) info
.tdep_info
;
1656 linux_init_abi (info
, gdbarch
);
1658 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1659 128-bit, they are IBM long double, not IEEE quad long double as
1660 in the System V ABI PowerPC Processor Supplement. We can safely
1661 let them default to 128-bit, since the debug info will give the
1662 size of type actually used in each case. */
1663 set_gdbarch_long_double_bit (gdbarch
, 16 * TARGET_CHAR_BIT
);
1664 set_gdbarch_long_double_format (gdbarch
, floatformats_ibm_long_double
);
1666 /* Handle inferior calls during interrupted system calls. */
1667 set_gdbarch_write_pc (gdbarch
, ppc_linux_write_pc
);
1669 /* Get the syscall number from the arch's register. */
1670 set_gdbarch_get_syscall_number (gdbarch
, ppc_linux_get_syscall_number
);
1672 /* SystemTap functions. */
1673 set_gdbarch_stap_integer_prefix (gdbarch
, "i");
1674 set_gdbarch_stap_register_indirection_prefix (gdbarch
, "(");
1675 set_gdbarch_stap_register_indirection_suffix (gdbarch
, ")");
1676 set_gdbarch_stap_gdb_register_prefix (gdbarch
, "r");
1677 set_gdbarch_stap_is_single_operand (gdbarch
, ppc_stap_is_single_operand
);
1678 set_gdbarch_stap_parse_special_token (gdbarch
,
1679 ppc_stap_parse_special_token
);
1681 if (tdep
->wordsize
== 4)
1683 /* Until November 2001, gcc did not comply with the 32 bit SysV
1684 R4 ABI requirement that structures less than or equal to 8
1685 bytes should be returned in registers. Instead GCC was using
1686 the AIX/PowerOpen ABI - everything returned in memory
1687 (well ignoring vectors that is). When this was corrected, it
1688 wasn't fixed for GNU/Linux native platform. Use the
1689 PowerOpen struct convention. */
1690 set_gdbarch_return_value (gdbarch
, ppc_linux_return_value
);
1692 set_gdbarch_memory_remove_breakpoint (gdbarch
,
1693 ppc_linux_memory_remove_breakpoint
);
1695 /* Shared library handling. */
1696 set_gdbarch_skip_trampoline_code (gdbarch
, ppc_skip_trampoline_code
);
1697 set_solib_svr4_fetch_link_map_offsets
1698 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1700 /* Setting the correct XML syscall filename. */
1701 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC
);
1704 tramp_frame_prepend_unwinder (gdbarch
,
1705 &ppc32_linux_sigaction_tramp_frame
);
1706 tramp_frame_prepend_unwinder (gdbarch
,
1707 &ppc32_linux_sighandler_tramp_frame
);
1709 /* BFD target for core files. */
1710 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
1711 set_gdbarch_gcore_bfd_target (gdbarch
, "elf32-powerpcle");
1713 set_gdbarch_gcore_bfd_target (gdbarch
, "elf32-powerpc");
1715 /* Supported register sections. */
1716 if (tdesc_find_feature (info
.target_desc
,
1717 "org.gnu.gdb.power.vsx"))
1718 set_gdbarch_core_regset_sections (gdbarch
,
1719 ppc_linux_vsx_regset_sections
);
1720 else if (tdesc_find_feature (info
.target_desc
,
1721 "org.gnu.gdb.power.altivec"))
1722 set_gdbarch_core_regset_sections (gdbarch
,
1723 ppc_linux_vmx_regset_sections
);
1725 set_gdbarch_core_regset_sections (gdbarch
,
1726 ppc_linux_fp_regset_sections
);
1728 if (powerpc_so_ops
.in_dynsym_resolve_code
== NULL
)
1730 powerpc_so_ops
= svr4_so_ops
;
1731 /* Override dynamic resolve function. */
1732 powerpc_so_ops
.in_dynsym_resolve_code
=
1733 powerpc_linux_in_dynsym_resolve_code
;
1735 set_solib_ops (gdbarch
, &powerpc_so_ops
);
1737 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
1740 if (tdep
->wordsize
== 8)
1742 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1743 function descriptors). */
1744 set_gdbarch_convert_from_func_ptr_addr
1745 (gdbarch
, ppc64_linux_convert_from_func_ptr_addr
);
1747 /* Shared library handling. */
1748 set_gdbarch_skip_trampoline_code (gdbarch
, ppc64_skip_trampoline_code
);
1749 set_solib_svr4_fetch_link_map_offsets
1750 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
1752 /* Setting the correct XML syscall filename. */
1753 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64
);
1756 tramp_frame_prepend_unwinder (gdbarch
,
1757 &ppc64_linux_sigaction_tramp_frame
);
1758 tramp_frame_prepend_unwinder (gdbarch
,
1759 &ppc64_linux_sighandler_tramp_frame
);
1761 /* BFD target for core files. */
1762 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
1763 set_gdbarch_gcore_bfd_target (gdbarch
, "elf64-powerpcle");
1765 set_gdbarch_gcore_bfd_target (gdbarch
, "elf64-powerpc");
1767 /* Supported register sections. */
1768 if (tdesc_find_feature (info
.target_desc
,
1769 "org.gnu.gdb.power.vsx"))
1770 set_gdbarch_core_regset_sections (gdbarch
,
1771 ppc64_linux_vsx_regset_sections
);
1772 else if (tdesc_find_feature (info
.target_desc
,
1773 "org.gnu.gdb.power.altivec"))
1774 set_gdbarch_core_regset_sections (gdbarch
,
1775 ppc64_linux_vmx_regset_sections
);
1777 set_gdbarch_core_regset_sections (gdbarch
,
1778 ppc64_linux_fp_regset_sections
);
1780 set_gdbarch_regset_from_core_section (gdbarch
,
1781 ppc_linux_regset_from_core_section
);
1782 set_gdbarch_core_read_description (gdbarch
, ppc_linux_core_read_description
);
1784 /* Enable TLS support. */
1785 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
1786 svr4_fetch_objfile_link_map
);
1790 const struct tdesc_feature
*feature
;
1792 /* If we have target-described registers, then we can safely
1793 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1794 (whether they are described or not). */
1795 gdb_assert (gdbarch_num_regs (gdbarch
) <= PPC_ORIG_R3_REGNUM
);
1796 set_gdbarch_num_regs (gdbarch
, PPC_TRAP_REGNUM
+ 1);
1798 /* If they are present, then assign them to the reserved number. */
1799 feature
= tdesc_find_feature (info
.target_desc
,
1800 "org.gnu.gdb.power.linux");
1801 if (feature
!= NULL
)
1803 tdesc_numbered_register (feature
, tdesc_data
,
1804 PPC_ORIG_R3_REGNUM
, "orig_r3");
1805 tdesc_numbered_register (feature
, tdesc_data
,
1806 PPC_TRAP_REGNUM
, "trap");
1810 /* Enable Cell/B.E. if supported by the target. */
1811 if (tdesc_compatible_p (info
.target_desc
,
1812 bfd_lookup_arch (bfd_arch_spu
, bfd_mach_spu
)))
1814 /* Cell/B.E. multi-architecture support. */
1815 set_spu_solib_ops (gdbarch
);
1817 /* Cell/B.E. cross-architecture unwinder support. */
1818 frame_unwind_prepend_unwinder (gdbarch
, &ppu2spu_unwind
);
1820 /* The default displaced_step_at_entry_point doesn't work for
1821 SPU stand-alone executables. */
1822 set_gdbarch_displaced_step_location (gdbarch
,
1823 ppc_linux_displaced_step_location
);
1826 set_gdbarch_get_siginfo_type (gdbarch
, linux_get_siginfo_type
);
1829 /* Provide a prototype to silence -Wmissing-prototypes. */
1830 extern initialize_file_ftype _initialize_ppc_linux_tdep
;
1833 _initialize_ppc_linux_tdep (void)
1835 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1836 64-bit PowerPC, and the older rs6k. */
1837 gdbarch_register_osabi (bfd_arch_powerpc
, bfd_mach_ppc
, GDB_OSABI_LINUX
,
1838 ppc_linux_init_abi
);
1839 gdbarch_register_osabi (bfd_arch_powerpc
, bfd_mach_ppc64
, GDB_OSABI_LINUX
,
1840 ppc_linux_init_abi
);
1841 gdbarch_register_osabi (bfd_arch_rs6000
, bfd_mach_rs6k
, GDB_OSABI_LINUX
,
1842 ppc_linux_init_abi
);
1844 /* Attach to inferior_created observer. */
1845 observer_attach_inferior_created (ppc_linux_inferior_created
);
1847 /* Attach to observers to track __spe_current_active_context. */
1848 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created
);
1849 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded
);
1850 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded
);
1852 /* Initialize the Linux target descriptions. */
1853 initialize_tdesc_powerpc_32l ();
1854 initialize_tdesc_powerpc_altivec32l ();
1855 initialize_tdesc_powerpc_cell32l ();
1856 initialize_tdesc_powerpc_vsx32l ();
1857 initialize_tdesc_powerpc_isa205_32l ();
1858 initialize_tdesc_powerpc_isa205_altivec32l ();
1859 initialize_tdesc_powerpc_isa205_vsx32l ();
1860 initialize_tdesc_powerpc_64l ();
1861 initialize_tdesc_powerpc_altivec64l ();
1862 initialize_tdesc_powerpc_cell64l ();
1863 initialize_tdesc_powerpc_vsx64l ();
1864 initialize_tdesc_powerpc_isa205_64l ();
1865 initialize_tdesc_powerpc_isa205_altivec64l ();
1866 initialize_tdesc_powerpc_isa205_vsx64l ();
1867 initialize_tdesc_powerpc_e500l ();