1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "solib-svr4.h"
34 #include "solib-spu.h"
38 #include "ppc64-tdep.h"
39 #include "ppc-linux-tdep.h"
40 #include "glibc-tdep.h"
41 #include "trad-frame.h"
42 #include "frame-unwind.h"
43 #include "tramp-frame.h"
46 #include "elf/common.h"
47 #include "elf/ppc64.h"
48 #include "arch-utils.h"
50 #include "xml-syscall.h"
51 #include "linux-tdep.h"
52 #include "linux-record.h"
53 #include "record-full.h"
56 #include "stap-probe.h"
59 #include "cli/cli-utils.h"
60 #include "parser-defs.h"
61 #include "user-regs.h"
63 #include "elf-bfd.h" /* for elfcore_write_* */
65 #include "features/rs6000/powerpc-32l.c"
66 #include "features/rs6000/powerpc-altivec32l.c"
67 #include "features/rs6000/powerpc-cell32l.c"
68 #include "features/rs6000/powerpc-vsx32l.c"
69 #include "features/rs6000/powerpc-isa205-32l.c"
70 #include "features/rs6000/powerpc-isa205-altivec32l.c"
71 #include "features/rs6000/powerpc-isa205-vsx32l.c"
72 #include "features/rs6000/powerpc-64l.c"
73 #include "features/rs6000/powerpc-altivec64l.c"
74 #include "features/rs6000/powerpc-cell64l.c"
75 #include "features/rs6000/powerpc-vsx64l.c"
76 #include "features/rs6000/powerpc-isa205-64l.c"
77 #include "features/rs6000/powerpc-isa205-altivec64l.c"
78 #include "features/rs6000/powerpc-isa205-vsx64l.c"
79 #include "features/rs6000/powerpc-e500l.c"
81 /* Shared library operations for PowerPC-Linux. */
82 static struct target_so_ops powerpc_so_ops
;
84 /* The syscall's XML filename for PPC and PPC64. */
85 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
86 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
88 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
89 in much the same fashion as memory_remove_breakpoint in mem-break.c,
90 but is careful not to write back the previous contents if the code
91 in question has changed in between inserting the breakpoint and
94 Here is the problem that we're trying to solve...
96 Once upon a time, before introducing this function to remove
97 breakpoints from the inferior, setting a breakpoint on a shared
98 library function prior to running the program would not work
99 properly. In order to understand the problem, it is first
100 necessary to understand a little bit about dynamic linking on
103 A call to a shared library function is accomplished via a bl
104 (branch-and-link) instruction whose branch target is an entry
105 in the procedure linkage table (PLT). The PLT in the object
106 file is uninitialized. To gdb, prior to running the program, the
107 entries in the PLT are all zeros.
109 Once the program starts running, the shared libraries are loaded
110 and the procedure linkage table is initialized, but the entries in
111 the table are not (necessarily) resolved. Once a function is
112 actually called, the code in the PLT is hit and the function is
113 resolved. In order to better illustrate this, an example is in
114 order; the following example is from the gdb testsuite.
116 We start the program shmain.
118 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
121 We place two breakpoints, one on shr1 and the other on main.
124 Breakpoint 1 at 0x100409d4
126 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
128 Examine the instruction (and the immediatly following instruction)
129 upon which the breakpoint was placed. Note that the PLT entry
130 for shr1 contains zeros.
132 (gdb) x/2i 0x100409d4
133 0x100409d4 <shr1>: .long 0x0
134 0x100409d8 <shr1+4>: .long 0x0
139 Starting program: gdb.base/shmain
140 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
142 Breakpoint 2, main ()
143 at gdb.base/shmain.c:44
146 Examine the PLT again. Note that the loading of the shared
147 library has initialized the PLT to code which loads a constant
148 (which I think is an index into the GOT) into r11 and then
149 branchs a short distance to the code which actually does the
152 (gdb) x/2i 0x100409d4
153 0x100409d4 <shr1>: li r11,4
154 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
158 Breakpoint 1, shr1 (x=1)
159 at gdb.base/shr1.c:19
162 Now we've hit the breakpoint at shr1. (The breakpoint was
163 reset from the PLT entry to the actual shr1 function after the
164 shared library was loaded.) Note that the PLT entry has been
165 resolved to contain a branch that takes us directly to shr1.
166 (The real one, not the PLT entry.)
168 (gdb) x/2i 0x100409d4
169 0x100409d4 <shr1>: b 0xffaf76c <shr1>
170 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
172 The thing to note here is that the PLT entry for shr1 has been
175 Now the problem should be obvious. GDB places a breakpoint (a
176 trap instruction) on the zero value of the PLT entry for shr1.
177 Later on, after the shared library had been loaded and the PLT
178 initialized, GDB gets a signal indicating this fact and attempts
179 (as it always does when it stops) to remove all the breakpoints.
181 The breakpoint removal was causing the former contents (a zero
182 word) to be written back to the now initialized PLT entry thus
183 destroying a portion of the initialization that had occurred only a
184 short time ago. When execution continued, the zero word would be
185 executed as an instruction an illegal instruction trap was
186 generated instead. (0 is not a legal instruction.)
188 The fix for this problem was fairly straightforward. The function
189 memory_remove_breakpoint from mem-break.c was copied to this file,
190 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
191 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
194 The differences between ppc_linux_memory_remove_breakpoint () and
195 memory_remove_breakpoint () are minor. All that the former does
196 that the latter does not is check to make sure that the breakpoint
197 location actually contains a breakpoint (trap instruction) prior
198 to attempting to write back the old contents. If it does contain
199 a trap instruction, we allow the old contents to be written back.
200 Otherwise, we silently do nothing.
202 The big question is whether memory_remove_breakpoint () should be
203 changed to have the same functionality. The downside is that more
204 traffic is generated for remote targets since we'll have an extra
205 fetch of a memory word each time a breakpoint is removed.
207 For the time being, we'll leave this self-modifying-code-friendly
208 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
209 else in the event that some other platform has similar needs with
210 regard to removing breakpoints in some potentially self modifying
213 ppc_linux_memory_remove_breakpoint (struct gdbarch
*gdbarch
,
214 struct bp_target_info
*bp_tgt
)
216 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
217 const unsigned char *bp
;
220 gdb_byte old_contents
[BREAKPOINT_MAX
];
221 struct cleanup
*cleanup
;
223 /* Determine appropriate breakpoint contents and size for this address. */
224 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &bplen
);
226 error (_("Software breakpoints not implemented for this target."));
228 /* Make sure we see the memory breakpoints. */
229 cleanup
= make_show_memory_breakpoints_cleanup (1);
230 val
= target_read_memory (addr
, old_contents
, bplen
);
232 /* If our breakpoint is no longer at the address, this means that the
233 program modified the code on us, so it is wrong to put back the
235 if (val
== 0 && memcmp (bp
, old_contents
, bplen
) == 0)
236 val
= target_write_raw_memory (addr
, bp_tgt
->shadow_contents
, bplen
);
238 do_cleanups (cleanup
);
242 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
243 than the 32 bit SYSV R4 ABI structure return convention - all
244 structures, no matter their size, are put in memory. Vectors,
245 which were added later, do get returned in a register though. */
247 static enum return_value_convention
248 ppc_linux_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
249 struct type
*valtype
, struct regcache
*regcache
,
250 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
252 if ((TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
253 || TYPE_CODE (valtype
) == TYPE_CODE_UNION
)
254 && !((TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 8)
255 && TYPE_VECTOR (valtype
)))
256 return RETURN_VALUE_STRUCT_CONVENTION
;
258 return ppc_sysv_abi_return_value (gdbarch
, function
, valtype
, regcache
,
262 /* PLT stub in executable. */
263 static struct ppc_insn_pattern powerpc32_plt_stub
[] =
265 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
266 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
267 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
268 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
272 /* PLT stub in shared library. */
273 static struct ppc_insn_pattern powerpc32_plt_stub_so
[] =
275 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
276 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
277 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
278 { 0xffffffff, 0x60000000, 0 }, /* nop */
281 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub)
283 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
284 section. For secure PLT, stub is in .text and we need to check
285 instruction patterns. */
288 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc
)
290 struct bound_minimal_symbol sym
;
292 /* Check whether PC is in the dynamic linker. This also checks
293 whether it is in the .plt section, used by non-PIC executables. */
294 if (svr4_in_dynsym_resolve_code (pc
))
297 /* Check if we are in the resolver. */
298 sym
= lookup_minimal_symbol_by_pc (pc
);
299 if (sym
.minsym
!= NULL
300 && (strcmp (MSYMBOL_LINKAGE_NAME (sym
.minsym
), "__glink") == 0
301 || strcmp (MSYMBOL_LINKAGE_NAME (sym
.minsym
),
302 "__glink_PLTresolve") == 0))
308 /* Follow PLT stub to actual routine. */
311 ppc_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
313 unsigned int insnbuf
[POWERPC32_PLT_STUB_LEN
];
314 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
315 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
316 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
317 CORE_ADDR target
= 0;
321 /* When reverse-debugging, scan backward to check whether we are
322 in the middle of trampoline code. */
323 if (execution_direction
== EXEC_REVERSE
)
324 scan_limit
= 4; /* At more 4 instructions. */
326 for (i
= 0; i
< scan_limit
; i
++)
328 if (ppc_insns_match_pattern (frame
, pc
, powerpc32_plt_stub
, insnbuf
))
333 Branch target is in r11. */
335 target
= (ppc_insn_d_field (insnbuf
[0]) << 16)
336 | ppc_insn_d_field (insnbuf
[1]);
337 target
= read_memory_unsigned_integer (target
, 4, byte_order
);
339 else if (ppc_insns_match_pattern (frame
, pc
, powerpc32_plt_stub_so
,
344 Branch target is in r11. */
346 target
= get_frame_register_unsigned (frame
,
347 tdep
->ppc_gp0_regnum
+ 30)
348 + ppc_insn_d_field (insnbuf
[0]);
349 target
= read_memory_unsigned_integer (target
, 4, byte_order
);
353 /* Scan backward one more instructions if doesn't match. */
364 /* Wrappers to handle Linux-only registers. */
367 ppc_linux_supply_gregset (const struct regset
*regset
,
368 struct regcache
*regcache
,
369 int regnum
, const void *gregs
, size_t len
)
371 const struct ppc_reg_offsets
*offsets
= regset
->regmap
;
373 ppc_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
375 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache
)))
377 /* "orig_r3" is stored 2 slots after "pc". */
378 if (regnum
== -1 || regnum
== PPC_ORIG_R3_REGNUM
)
379 ppc_supply_reg (regcache
, PPC_ORIG_R3_REGNUM
, gregs
,
380 offsets
->pc_offset
+ 2 * offsets
->gpr_size
,
383 /* "trap" is stored 8 slots after "pc". */
384 if (regnum
== -1 || regnum
== PPC_TRAP_REGNUM
)
385 ppc_supply_reg (regcache
, PPC_TRAP_REGNUM
, gregs
,
386 offsets
->pc_offset
+ 8 * offsets
->gpr_size
,
392 ppc_linux_collect_gregset (const struct regset
*regset
,
393 const struct regcache
*regcache
,
394 int regnum
, void *gregs
, size_t len
)
396 const struct ppc_reg_offsets
*offsets
= regset
->regmap
;
398 /* Clear areas in the linux gregset not written elsewhere. */
400 memset (gregs
, 0, len
);
402 ppc_collect_gregset (regset
, regcache
, regnum
, gregs
, len
);
404 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache
)))
406 /* "orig_r3" is stored 2 slots after "pc". */
407 if (regnum
== -1 || regnum
== PPC_ORIG_R3_REGNUM
)
408 ppc_collect_reg (regcache
, PPC_ORIG_R3_REGNUM
, gregs
,
409 offsets
->pc_offset
+ 2 * offsets
->gpr_size
,
412 /* "trap" is stored 8 slots after "pc". */
413 if (regnum
== -1 || regnum
== PPC_TRAP_REGNUM
)
414 ppc_collect_reg (regcache
, PPC_TRAP_REGNUM
, gregs
,
415 offsets
->pc_offset
+ 8 * offsets
->gpr_size
,
420 /* Regset descriptions. */
421 static const struct ppc_reg_offsets ppc32_linux_reg_offsets
=
423 /* General-purpose registers. */
424 /* .r0_offset = */ 0,
427 /* .pc_offset = */ 128,
428 /* .ps_offset = */ 132,
429 /* .cr_offset = */ 152,
430 /* .lr_offset = */ 144,
431 /* .ctr_offset = */ 140,
432 /* .xer_offset = */ 148,
433 /* .mq_offset = */ 156,
435 /* Floating-point registers. */
436 /* .f0_offset = */ 0,
437 /* .fpscr_offset = */ 256,
438 /* .fpscr_size = */ 8,
440 /* AltiVec registers. */
441 /* .vr0_offset = */ 0,
442 /* .vscr_offset = */ 512 + 12,
443 /* .vrsave_offset = */ 528
446 static const struct ppc_reg_offsets ppc64_linux_reg_offsets
=
448 /* General-purpose registers. */
449 /* .r0_offset = */ 0,
452 /* .pc_offset = */ 256,
453 /* .ps_offset = */ 264,
454 /* .cr_offset = */ 304,
455 /* .lr_offset = */ 288,
456 /* .ctr_offset = */ 280,
457 /* .xer_offset = */ 296,
458 /* .mq_offset = */ 312,
460 /* Floating-point registers. */
461 /* .f0_offset = */ 0,
462 /* .fpscr_offset = */ 256,
463 /* .fpscr_size = */ 8,
465 /* AltiVec registers. */
466 /* .vr0_offset = */ 0,
467 /* .vscr_offset = */ 512 + 12,
468 /* .vrsave_offset = */ 528
471 static const struct regset ppc32_linux_gregset
= {
472 &ppc32_linux_reg_offsets
,
473 ppc_linux_supply_gregset
,
474 ppc_linux_collect_gregset
477 static const struct regset ppc64_linux_gregset
= {
478 &ppc64_linux_reg_offsets
,
479 ppc_linux_supply_gregset
,
480 ppc_linux_collect_gregset
483 static const struct regset ppc32_linux_fpregset
= {
484 &ppc32_linux_reg_offsets
,
489 static const struct regset ppc32_linux_vrregset
= {
490 &ppc32_linux_reg_offsets
,
495 static const struct regset ppc32_linux_vsxregset
= {
496 &ppc32_linux_reg_offsets
,
497 ppc_supply_vsxregset
,
498 ppc_collect_vsxregset
501 const struct regset
*
502 ppc_linux_gregset (int wordsize
)
504 return wordsize
== 8 ? &ppc64_linux_gregset
: &ppc32_linux_gregset
;
507 const struct regset
*
508 ppc_linux_fpregset (void)
510 return &ppc32_linux_fpregset
;
513 /* Iterate over supported core file register note sections. */
516 ppc_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
517 iterate_over_regset_sections_cb
*cb
,
519 const struct regcache
*regcache
)
521 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
522 int have_altivec
= tdep
->ppc_vr0_regnum
!= -1;
523 int have_vsx
= tdep
->ppc_vsr0_upper_regnum
!= -1;
525 if (tdep
->wordsize
== 4)
526 cb (".reg", 48 * 4, &ppc32_linux_gregset
, NULL
, cb_data
);
528 cb (".reg", 48 * 8, &ppc64_linux_gregset
, NULL
, cb_data
);
530 cb (".reg2", 264, &ppc32_linux_fpregset
, NULL
, cb_data
);
533 cb (".reg-ppc-vmx", 544, &ppc32_linux_vrregset
, "ppc Altivec", cb_data
);
536 cb (".reg-ppc-vsx", 256, &ppc32_linux_vsxregset
, "POWER7 VSX", cb_data
);
540 ppc_linux_sigtramp_cache (struct frame_info
*this_frame
,
541 struct trad_frame_cache
*this_cache
,
542 CORE_ADDR func
, LONGEST offset
,
550 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
551 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
552 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
554 base
= get_frame_register_unsigned (this_frame
,
555 gdbarch_sp_regnum (gdbarch
));
556 if (bias
> 0 && get_frame_pc (this_frame
) != func
)
557 /* See below, some signal trampolines increment the stack as their
558 first instruction, need to compensate for that. */
561 /* Find the address of the register buffer pointer. */
562 regs
= base
+ offset
;
563 /* Use that to find the address of the corresponding register
565 gpregs
= read_memory_unsigned_integer (regs
, tdep
->wordsize
, byte_order
);
566 fpregs
= gpregs
+ 48 * tdep
->wordsize
;
568 /* General purpose. */
569 for (i
= 0; i
< 32; i
++)
571 int regnum
= i
+ tdep
->ppc_gp0_regnum
;
572 trad_frame_set_reg_addr (this_cache
,
573 regnum
, gpregs
+ i
* tdep
->wordsize
);
575 trad_frame_set_reg_addr (this_cache
,
576 gdbarch_pc_regnum (gdbarch
),
577 gpregs
+ 32 * tdep
->wordsize
);
578 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_ctr_regnum
,
579 gpregs
+ 35 * tdep
->wordsize
);
580 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_lr_regnum
,
581 gpregs
+ 36 * tdep
->wordsize
);
582 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_xer_regnum
,
583 gpregs
+ 37 * tdep
->wordsize
);
584 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_cr_regnum
,
585 gpregs
+ 38 * tdep
->wordsize
);
587 if (ppc_linux_trap_reg_p (gdbarch
))
589 trad_frame_set_reg_addr (this_cache
, PPC_ORIG_R3_REGNUM
,
590 gpregs
+ 34 * tdep
->wordsize
);
591 trad_frame_set_reg_addr (this_cache
, PPC_TRAP_REGNUM
,
592 gpregs
+ 40 * tdep
->wordsize
);
595 if (ppc_floating_point_unit_p (gdbarch
))
597 /* Floating point registers. */
598 for (i
= 0; i
< 32; i
++)
600 int regnum
= i
+ gdbarch_fp0_regnum (gdbarch
);
601 trad_frame_set_reg_addr (this_cache
, regnum
,
602 fpregs
+ i
* tdep
->wordsize
);
604 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_fpscr_regnum
,
605 fpregs
+ 32 * tdep
->wordsize
);
607 trad_frame_set_id (this_cache
, frame_id_build (base
, func
));
611 ppc32_linux_sigaction_cache_init (const struct tramp_frame
*self
,
612 struct frame_info
*this_frame
,
613 struct trad_frame_cache
*this_cache
,
616 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
617 0xd0 /* Offset to ucontext_t. */
618 + 0x30 /* Offset to .reg. */,
623 ppc64_linux_sigaction_cache_init (const struct tramp_frame
*self
,
624 struct frame_info
*this_frame
,
625 struct trad_frame_cache
*this_cache
,
628 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
629 0x80 /* Offset to ucontext_t. */
630 + 0xe0 /* Offset to .reg. */,
635 ppc32_linux_sighandler_cache_init (const struct tramp_frame
*self
,
636 struct frame_info
*this_frame
,
637 struct trad_frame_cache
*this_cache
,
640 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
641 0x40 /* Offset to ucontext_t. */
642 + 0x1c /* Offset to .reg. */,
647 ppc64_linux_sighandler_cache_init (const struct tramp_frame
*self
,
648 struct frame_info
*this_frame
,
649 struct trad_frame_cache
*this_cache
,
652 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
653 0x80 /* Offset to struct sigcontext. */
654 + 0x38 /* Offset to .reg. */,
658 static struct tramp_frame ppc32_linux_sigaction_tramp_frame
= {
662 { 0x380000ac, -1 }, /* li r0, 172 */
663 { 0x44000002, -1 }, /* sc */
664 { TRAMP_SENTINEL_INSN
},
666 ppc32_linux_sigaction_cache_init
668 static struct tramp_frame ppc64_linux_sigaction_tramp_frame
= {
672 { 0x38210080, -1 }, /* addi r1,r1,128 */
673 { 0x380000ac, -1 }, /* li r0, 172 */
674 { 0x44000002, -1 }, /* sc */
675 { TRAMP_SENTINEL_INSN
},
677 ppc64_linux_sigaction_cache_init
679 static struct tramp_frame ppc32_linux_sighandler_tramp_frame
= {
683 { 0x38000077, -1 }, /* li r0,119 */
684 { 0x44000002, -1 }, /* sc */
685 { TRAMP_SENTINEL_INSN
},
687 ppc32_linux_sighandler_cache_init
689 static struct tramp_frame ppc64_linux_sighandler_tramp_frame
= {
693 { 0x38210080, -1 }, /* addi r1,r1,128 */
694 { 0x38000077, -1 }, /* li r0,119 */
695 { 0x44000002, -1 }, /* sc */
696 { TRAMP_SENTINEL_INSN
},
698 ppc64_linux_sighandler_cache_init
702 /* Address to use for displaced stepping. When debugging a stand-alone
703 SPU executable, entry_point_address () will point to an SPU local-store
704 address and is thus not usable as displaced stepping location. We use
705 the auxiliary vector to determine the PowerPC-side entry point address
708 static CORE_ADDR ppc_linux_entry_point_addr
= 0;
711 ppc_linux_inferior_created (struct target_ops
*target
, int from_tty
)
713 ppc_linux_entry_point_addr
= 0;
717 ppc_linux_displaced_step_location (struct gdbarch
*gdbarch
)
719 if (ppc_linux_entry_point_addr
== 0)
723 /* Determine entry point from target auxiliary vector. */
724 if (target_auxv_search (¤t_target
, AT_ENTRY
, &addr
) <= 0)
725 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
727 /* Make certain that the address points at real code, and not a
728 function descriptor. */
729 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
732 /* Inferior calls also use the entry point as a breakpoint location.
733 We don't want displaced stepping to interfere with those
734 breakpoints, so leave space. */
735 ppc_linux_entry_point_addr
= addr
+ 2 * PPC_INSN_SIZE
;
738 return ppc_linux_entry_point_addr
;
742 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
744 ppc_linux_trap_reg_p (struct gdbarch
*gdbarch
)
746 /* If we do not have a target description with registers, then
747 the special registers will not be included in the register set. */
748 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
751 /* If we do, then it is safe to check the size. */
752 return register_size (gdbarch
, PPC_ORIG_R3_REGNUM
) > 0
753 && register_size (gdbarch
, PPC_TRAP_REGNUM
) > 0;
756 /* Return the current system call's number present in the
757 r0 register. When the function fails, it returns -1. */
759 ppc_linux_get_syscall_number (struct gdbarch
*gdbarch
,
762 struct regcache
*regcache
= get_thread_regcache (ptid
);
763 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
764 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
765 struct cleanup
*cleanbuf
;
766 /* The content of a register */
771 /* Make sure we're in a 32- or 64-bit machine */
772 gdb_assert (tdep
->wordsize
== 4 || tdep
->wordsize
== 8);
774 buf
= (gdb_byte
*) xmalloc (tdep
->wordsize
* sizeof (gdb_byte
));
776 cleanbuf
= make_cleanup (xfree
, buf
);
778 /* Getting the system call number from the register.
779 When dealing with PowerPC architecture, this information
780 is stored at 0th register. */
781 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
, buf
);
783 ret
= extract_signed_integer (buf
, tdep
->wordsize
, byte_order
);
784 do_cleanups (cleanbuf
);
789 /* PPC process record-replay */
791 static struct linux_record_tdep ppc_linux_record_tdep
;
792 static struct linux_record_tdep ppc64_linux_record_tdep
;
794 static enum gdb_syscall
795 ppc_canonicalize_syscall (int syscall
)
797 /* See arch/powerpc/include/uapi/asm/unistd.h */
801 else if (syscall
>= 167 && syscall
<= 190) /* Skip query_module 166 */
803 else if (syscall
>= 192 && syscall
<= 197) /* mmap2 */
805 else if (syscall
== 208) /* tkill */
806 return gdb_sys_tkill
;
807 else if (syscall
>= 207 && syscall
<= 220) /* gettid */
808 return syscall
+ 224 - 207;
809 else if (syscall
>= 234 && syscall
<= 239) /* exit_group */
810 return syscall
+ 252 - 234;
811 else if (syscall
>= 240 && syscall
<=248) /* timer_create */
812 return syscall
+= 259 - 240;
813 else if (syscall
>= 250 && syscall
<=251) /* tgkill */
814 return syscall
+ 270 - 250;
815 else if (syscall
== 336)
817 else if (syscall
== 337)
818 return gdb_sys_recvfrom
;
819 else if (syscall
== 342)
820 return gdb_sys_recvmsg
;
825 ppc_linux_syscall_record (struct regcache
*regcache
)
827 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
828 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
830 enum gdb_syscall syscall_gdb
;
834 regcache_raw_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
, &scnum
);
835 syscall_gdb
= ppc_canonicalize_syscall (scnum
);
839 printf_unfiltered (_("Process record and replay target doesn't "
840 "support syscall number %d\n"), (int) scnum
);
844 if (syscall_gdb
== gdb_sys_sigreturn
845 || syscall_gdb
== gdb_sys_rt_sigreturn
)
848 int regsets
[] = { tdep
->ppc_gp0_regnum
,
849 tdep
->ppc_fp0_regnum
,
850 tdep
->ppc_vr0_regnum
,
851 tdep
->ppc_vsr0_upper_regnum
};
853 for (j
= 0; j
< 4; j
++)
855 if (regsets
[j
] == -1)
857 for (i
= 0; i
< 32; i
++)
859 if (record_full_arch_list_add_reg (regcache
, regsets
[j
] + i
))
864 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_cr_regnum
))
866 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_ctr_regnum
))
868 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_lr_regnum
))
870 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_xer_regnum
))
876 if (tdep
->wordsize
== 8)
877 ret
= record_linux_system_call (syscall_gdb
, regcache
,
878 &ppc64_linux_record_tdep
);
880 ret
= record_linux_system_call (syscall_gdb
, regcache
,
881 &ppc_linux_record_tdep
);
886 /* Record registers clobbered during syscall. */
887 for (i
= 3; i
<= 12; i
++)
889 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_gp0_regnum
+ i
))
892 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_gp0_regnum
+ 0))
894 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_cr_regnum
))
896 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_ctr_regnum
))
898 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_lr_regnum
))
905 ppc_linux_record_signal (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
906 enum gdb_signal signal
)
908 /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c
909 handle_rt_signal32 in arch/powerpc/kernel/signal_32.c
910 arch/powerpc/include/asm/ptrace.h
912 const int SIGNAL_FRAMESIZE
= 128;
913 const int sizeof_rt_sigframe
= 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
915 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
918 for (i
= 3; i
<= 12; i
++)
920 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_gp0_regnum
+ i
))
924 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_lr_regnum
))
926 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_cr_regnum
))
928 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_ctr_regnum
))
930 if (record_full_arch_list_add_reg (regcache
, gdbarch_pc_regnum (gdbarch
)))
932 if (record_full_arch_list_add_reg (regcache
, gdbarch_sp_regnum (gdbarch
)))
935 /* Record the change in the stack.
936 frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
937 regcache_raw_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
), &sp
);
938 sp
-= SIGNAL_FRAMESIZE
;
939 sp
-= sizeof_rt_sigframe
;
941 if (record_full_arch_list_add_mem (sp
, SIGNAL_FRAMESIZE
+ sizeof_rt_sigframe
))
944 if (record_full_arch_list_add_end ())
951 ppc_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
953 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
955 regcache_cooked_write_unsigned (regcache
, gdbarch_pc_regnum (gdbarch
), pc
);
957 /* Set special TRAP register to -1 to prevent the kernel from
958 messing with the PC we just installed, if we happen to be
959 within an interrupted system call that the kernel wants to
962 Note that after we return from the dummy call, the TRAP and
963 ORIG_R3 registers will be automatically restored, and the
964 kernel continues to restart the system call at this point. */
965 if (ppc_linux_trap_reg_p (gdbarch
))
966 regcache_cooked_write_unsigned (regcache
, PPC_TRAP_REGNUM
, -1);
970 ppc_linux_spu_section (bfd
*abfd
, asection
*asect
, void *user_data
)
972 return strncmp (bfd_section_name (abfd
, asect
), "SPU/", 4) == 0;
975 static const struct target_desc
*
976 ppc_linux_core_read_description (struct gdbarch
*gdbarch
,
977 struct target_ops
*target
,
980 asection
*cell
= bfd_sections_find_if (abfd
, ppc_linux_spu_section
, NULL
);
981 asection
*altivec
= bfd_get_section_by_name (abfd
, ".reg-ppc-vmx");
982 asection
*vsx
= bfd_get_section_by_name (abfd
, ".reg-ppc-vsx");
983 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
987 switch (bfd_section_size (abfd
, section
))
991 return tdesc_powerpc_cell32l
;
993 return tdesc_powerpc_vsx32l
;
995 return tdesc_powerpc_altivec32l
;
997 return tdesc_powerpc_32l
;
1001 return tdesc_powerpc_cell64l
;
1003 return tdesc_powerpc_vsx64l
;
1005 return tdesc_powerpc_altivec64l
;
1007 return tdesc_powerpc_64l
;
1015 /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
1016 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1019 ppc_elfv2_elf_make_msymbol_special (asymbol
*sym
, struct minimal_symbol
*msym
)
1021 elf_symbol_type
*elf_sym
= (elf_symbol_type
*)sym
;
1023 /* If the symbol is marked as having a local entry point, set a target
1024 flag in the msymbol. We currently only support local entry point
1025 offsets of 8 bytes, which is the only entry point offset ever used
1026 by current compilers. If/when other offsets are ever used, we will
1027 have to use additional target flag bits to store them. */
1028 switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym
->internal_elf_sym
.st_other
))
1033 MSYMBOL_TARGET_FLAG_1 (msym
) = 1;
1038 /* Implementation of `gdbarch_skip_entrypoint', as defined in
1039 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1042 ppc_elfv2_skip_entrypoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1044 struct bound_minimal_symbol fun
;
1045 int local_entry_offset
= 0;
1047 fun
= lookup_minimal_symbol_by_pc (pc
);
1048 if (fun
.minsym
== NULL
)
1051 /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
1052 offset values are encoded. */
1053 if (MSYMBOL_TARGET_FLAG_1 (fun
.minsym
))
1054 local_entry_offset
= 8;
1056 if (BMSYMBOL_VALUE_ADDRESS (fun
) <= pc
1057 && pc
< BMSYMBOL_VALUE_ADDRESS (fun
) + local_entry_offset
)
1058 return BMSYMBOL_VALUE_ADDRESS (fun
) + local_entry_offset
;
1063 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1067 ppc_stap_is_single_operand (struct gdbarch
*gdbarch
, const char *s
)
1069 return (*s
== 'i' /* Literal number. */
1070 || (isdigit (*s
) && s
[1] == '('
1071 && isdigit (s
[2])) /* Displacement. */
1072 || (*s
== '(' && isdigit (s
[1])) /* Register indirection. */
1073 || isdigit (*s
)); /* Register value. */
1076 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
1080 ppc_stap_parse_special_token (struct gdbarch
*gdbarch
,
1081 struct stap_parse_info
*p
)
1083 if (isdigit (*p
->arg
))
1085 /* This temporary pointer is needed because we have to do a lookahead.
1086 We could be dealing with a register displacement, and in such case
1087 we would not need to do anything. */
1088 const char *s
= p
->arg
;
1093 while (isdigit (*s
))
1098 /* It is a register displacement indeed. Returning 0 means we are
1099 deferring the treatment of this case to the generic parser. */
1104 regname
= alloca (len
+ 2);
1107 strncpy (regname
+ 1, p
->arg
, len
);
1109 regname
[len
] = '\0';
1111 if (user_reg_map_name_to_regnum (gdbarch
, regname
, len
) == -1)
1112 error (_("Invalid register name `%s' on expression `%s'."),
1113 regname
, p
->saved_arg
);
1115 write_exp_elt_opcode (&p
->pstate
, OP_REGISTER
);
1118 write_exp_string (&p
->pstate
, str
);
1119 write_exp_elt_opcode (&p
->pstate
, OP_REGISTER
);
1125 /* All the other tokens should be handled correctly by the generic
1133 /* Cell/B.E. active SPE context tracking support. */
1135 static struct objfile
*spe_context_objfile
= NULL
;
1136 static CORE_ADDR spe_context_lm_addr
= 0;
1137 static CORE_ADDR spe_context_offset
= 0;
1139 static ptid_t spe_context_cache_ptid
;
1140 static CORE_ADDR spe_context_cache_address
;
1142 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
1143 to track whether we've loaded a version of libspe2 (as static or dynamic
1144 library) that provides the __spe_current_active_context variable. */
1146 ppc_linux_spe_context_lookup (struct objfile
*objfile
)
1148 struct bound_minimal_symbol sym
;
1152 spe_context_objfile
= NULL
;
1153 spe_context_lm_addr
= 0;
1154 spe_context_offset
= 0;
1155 spe_context_cache_ptid
= minus_one_ptid
;
1156 spe_context_cache_address
= 0;
1160 sym
= lookup_minimal_symbol ("__spe_current_active_context", NULL
, objfile
);
1163 spe_context_objfile
= objfile
;
1164 spe_context_lm_addr
= svr4_fetch_objfile_link_map (objfile
);
1165 spe_context_offset
= BMSYMBOL_VALUE_ADDRESS (sym
);
1166 spe_context_cache_ptid
= minus_one_ptid
;
1167 spe_context_cache_address
= 0;
1173 ppc_linux_spe_context_inferior_created (struct target_ops
*t
, int from_tty
)
1175 struct objfile
*objfile
;
1177 ppc_linux_spe_context_lookup (NULL
);
1178 ALL_OBJFILES (objfile
)
1179 ppc_linux_spe_context_lookup (objfile
);
1183 ppc_linux_spe_context_solib_loaded (struct so_list
*so
)
1185 if (strstr (so
->so_original_name
, "/libspe") != NULL
)
1187 solib_read_symbols (so
, 0);
1188 ppc_linux_spe_context_lookup (so
->objfile
);
1193 ppc_linux_spe_context_solib_unloaded (struct so_list
*so
)
1195 if (so
->objfile
== spe_context_objfile
)
1196 ppc_linux_spe_context_lookup (NULL
);
1199 /* Retrieve contents of the N'th element in the current thread's
1200 linked SPE context list into ID and NPC. Return the address of
1201 said context element, or 0 if not found. */
1203 ppc_linux_spe_context (int wordsize
, enum bfd_endian byte_order
,
1204 int n
, int *id
, unsigned int *npc
)
1206 CORE_ADDR spe_context
= 0;
1210 /* Quick exit if we have not found __spe_current_active_context. */
1211 if (!spe_context_objfile
)
1214 /* Look up cached address of thread-local variable. */
1215 if (!ptid_equal (spe_context_cache_ptid
, inferior_ptid
))
1217 struct target_ops
*target
= ¤t_target
;
1218 volatile struct gdb_exception ex
;
1220 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1222 /* We do not call target_translate_tls_address here, because
1223 svr4_fetch_objfile_link_map may invalidate the frame chain,
1224 which must not do while inside a frame sniffer.
1226 Instead, we have cached the lm_addr value, and use that to
1227 directly call the target's to_get_thread_local_address. */
1228 spe_context_cache_address
1229 = target
->to_get_thread_local_address (target
, inferior_ptid
,
1230 spe_context_lm_addr
,
1231 spe_context_offset
);
1232 spe_context_cache_ptid
= inferior_ptid
;
1239 /* Read variable value. */
1240 if (target_read_memory (spe_context_cache_address
, buf
, wordsize
) == 0)
1241 spe_context
= extract_unsigned_integer (buf
, wordsize
, byte_order
);
1243 /* Cyle through to N'th linked list element. */
1244 for (i
= 0; i
< n
&& spe_context
; i
++)
1245 if (target_read_memory (spe_context
+ align_up (12, wordsize
),
1246 buf
, wordsize
) == 0)
1247 spe_context
= extract_unsigned_integer (buf
, wordsize
, byte_order
);
1251 /* Read current context. */
1253 && target_read_memory (spe_context
, buf
, 12) != 0)
1256 /* Extract data elements. */
1260 *id
= extract_signed_integer (buf
, 4, byte_order
);
1262 *npc
= extract_unsigned_integer (buf
+ 4, 4, byte_order
);
1269 /* Cell/B.E. cross-architecture unwinder support. */
1271 struct ppu2spu_cache
1273 struct frame_id frame_id
;
1274 struct regcache
*regcache
;
1277 static struct gdbarch
*
1278 ppu2spu_prev_arch (struct frame_info
*this_frame
, void **this_cache
)
1280 struct ppu2spu_cache
*cache
= *this_cache
;
1281 return get_regcache_arch (cache
->regcache
);
1285 ppu2spu_this_id (struct frame_info
*this_frame
,
1286 void **this_cache
, struct frame_id
*this_id
)
1288 struct ppu2spu_cache
*cache
= *this_cache
;
1289 *this_id
= cache
->frame_id
;
1292 static struct value
*
1293 ppu2spu_prev_register (struct frame_info
*this_frame
,
1294 void **this_cache
, int regnum
)
1296 struct ppu2spu_cache
*cache
= *this_cache
;
1297 struct gdbarch
*gdbarch
= get_regcache_arch (cache
->regcache
);
1300 buf
= alloca (register_size (gdbarch
, regnum
));
1302 if (regnum
< gdbarch_num_regs (gdbarch
))
1303 regcache_raw_read (cache
->regcache
, regnum
, buf
);
1305 gdbarch_pseudo_register_read (gdbarch
, cache
->regcache
, regnum
, buf
);
1307 return frame_unwind_got_bytes (this_frame
, regnum
, buf
);
1312 struct gdbarch
*gdbarch
;
1315 gdb_byte gprs
[128*16];
1319 ppu2spu_unwind_register (void *src
, int regnum
, gdb_byte
*buf
)
1321 struct ppu2spu_data
*data
= src
;
1322 enum bfd_endian byte_order
= gdbarch_byte_order (data
->gdbarch
);
1324 if (regnum
>= 0 && regnum
< SPU_NUM_GPRS
)
1325 memcpy (buf
, data
->gprs
+ 16*regnum
, 16);
1326 else if (regnum
== SPU_ID_REGNUM
)
1327 store_unsigned_integer (buf
, 4, byte_order
, data
->id
);
1328 else if (regnum
== SPU_PC_REGNUM
)
1329 store_unsigned_integer (buf
, 4, byte_order
, data
->npc
);
1331 return REG_UNAVAILABLE
;
1337 ppu2spu_sniffer (const struct frame_unwind
*self
,
1338 struct frame_info
*this_frame
, void **this_prologue_cache
)
1340 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1341 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1342 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1343 struct ppu2spu_data data
;
1344 struct frame_info
*fi
;
1345 CORE_ADDR base
, func
, backchain
, spe_context
;
1349 /* Count the number of SPU contexts already in the frame chain. */
1350 for (fi
= get_next_frame (this_frame
); fi
; fi
= get_next_frame (fi
))
1351 if (get_frame_type (fi
) == ARCH_FRAME
1352 && gdbarch_bfd_arch_info (get_frame_arch (fi
))->arch
== bfd_arch_spu
)
1355 base
= get_frame_sp (this_frame
);
1356 func
= get_frame_pc (this_frame
);
1357 if (target_read_memory (base
, buf
, tdep
->wordsize
))
1359 backchain
= extract_unsigned_integer (buf
, tdep
->wordsize
, byte_order
);
1361 spe_context
= ppc_linux_spe_context (tdep
->wordsize
, byte_order
,
1362 n
, &data
.id
, &data
.npc
);
1363 if (spe_context
&& base
<= spe_context
&& spe_context
< backchain
)
1367 /* Find gdbarch for SPU. */
1368 struct gdbarch_info info
;
1369 gdbarch_info_init (&info
);
1370 info
.bfd_arch_info
= bfd_lookup_arch (bfd_arch_spu
, bfd_mach_spu
);
1371 info
.byte_order
= BFD_ENDIAN_BIG
;
1372 info
.osabi
= GDB_OSABI_LINUX
;
1373 info
.tdep_info
= (void *) &data
.id
;
1374 data
.gdbarch
= gdbarch_find_by_info (info
);
1378 xsnprintf (annex
, sizeof annex
, "%d/regs", data
.id
);
1379 if (target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1380 data
.gprs
, 0, sizeof data
.gprs
)
1381 == sizeof data
.gprs
)
1383 struct ppu2spu_cache
*cache
1384 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache
);
1386 struct address_space
*aspace
= get_frame_address_space (this_frame
);
1387 struct regcache
*regcache
= regcache_xmalloc (data
.gdbarch
, aspace
);
1388 struct cleanup
*cleanups
= make_cleanup_regcache_xfree (regcache
);
1389 regcache_save (regcache
, ppu2spu_unwind_register
, &data
);
1390 discard_cleanups (cleanups
);
1392 cache
->frame_id
= frame_id_build (base
, func
);
1393 cache
->regcache
= regcache
;
1394 *this_prologue_cache
= cache
;
1403 ppu2spu_dealloc_cache (struct frame_info
*self
, void *this_cache
)
1405 struct ppu2spu_cache
*cache
= this_cache
;
1406 regcache_xfree (cache
->regcache
);
1409 static const struct frame_unwind ppu2spu_unwind
= {
1411 default_frame_unwind_stop_reason
,
1413 ppu2spu_prev_register
,
1416 ppu2spu_dealloc_cache
,
1420 /* Initialize linux_record_tdep if not initialized yet. */
1423 ppc_init_linux_record_tdep (struct linux_record_tdep
*record_tdep
,
1426 /* Simply return if it had been initialized. */
1427 if (record_tdep
->size_pointer
!= 0)
1430 /* These values are the size of the type that will be used in a system
1431 call. They are obtained from Linux Kernel source. */
1435 record_tdep
->size_pointer
= 8;
1436 record_tdep
->size__old_kernel_stat
= 32;
1437 record_tdep
->size_tms
= 32;
1438 record_tdep
->size_loff_t
= 8;
1439 record_tdep
->size_flock
= 32;
1440 record_tdep
->size_oldold_utsname
= 45;
1441 record_tdep
->size_ustat
= 32;
1442 record_tdep
->size_old_sigaction
= 152;
1443 record_tdep
->size_old_sigset_t
= 128;
1444 record_tdep
->size_rlimit
= 16;
1445 record_tdep
->size_rusage
= 144;
1446 record_tdep
->size_timeval
= 16;
1447 record_tdep
->size_timezone
= 8;
1448 record_tdep
->size_old_gid_t
= 4;
1449 record_tdep
->size_old_uid_t
= 4;
1450 record_tdep
->size_fd_set
= 128;
1451 record_tdep
->size_dirent
= 280;
1452 record_tdep
->size_dirent64
= 280;
1453 record_tdep
->size_statfs
= 120;
1454 record_tdep
->size_statfs64
= 120;
1455 record_tdep
->size_sockaddr
= 16;
1456 record_tdep
->size_int
= 4;
1457 record_tdep
->size_long
= 8;
1458 record_tdep
->size_ulong
= 8;
1459 record_tdep
->size_msghdr
= 56;
1460 record_tdep
->size_itimerval
= 32;
1461 record_tdep
->size_stat
= 144;
1462 record_tdep
->size_old_utsname
= 325;
1463 record_tdep
->size_sysinfo
= 112;
1464 record_tdep
->size_msqid_ds
= 120;
1465 record_tdep
->size_shmid_ds
= 112;
1466 record_tdep
->size_new_utsname
= 390;
1467 record_tdep
->size_timex
= 208;
1468 record_tdep
->size_mem_dqinfo
= 24;
1469 record_tdep
->size_if_dqblk
= 72;
1470 record_tdep
->size_fs_quota_stat
= 80;
1471 record_tdep
->size_timespec
= 16;
1472 record_tdep
->size_pollfd
= 8;
1473 record_tdep
->size_NFS_FHSIZE
= 32;
1474 record_tdep
->size_knfsd_fh
= 132;
1475 record_tdep
->size_TASK_COMM_LEN
= 32;
1476 record_tdep
->size_sigaction
= 152;
1477 record_tdep
->size_sigset_t
= 128;
1478 record_tdep
->size_siginfo_t
= 128;
1479 record_tdep
->size_cap_user_data_t
= 8;
1480 record_tdep
->size_stack_t
= 24;
1481 record_tdep
->size_off_t
= 8;
1482 record_tdep
->size_stat64
= 104;
1483 record_tdep
->size_gid_t
= 4;
1484 record_tdep
->size_uid_t
= 4;
1485 record_tdep
->size_PAGE_SIZE
= 0x10000; /* 64KB */
1486 record_tdep
->size_flock64
= 32;
1487 record_tdep
->size_io_event
= 32;
1488 record_tdep
->size_iocb
= 64;
1489 record_tdep
->size_epoll_event
= 16;
1490 record_tdep
->size_itimerspec
= 32;
1491 record_tdep
->size_mq_attr
= 64;
1492 record_tdep
->size_siginfo
= 128;
1493 record_tdep
->size_termios
= 44;
1494 record_tdep
->size_pid_t
= 4;
1495 record_tdep
->size_winsize
= 8;
1496 record_tdep
->size_serial_struct
= 72;
1497 record_tdep
->size_serial_icounter_struct
= 80;
1498 record_tdep
->size_size_t
= 8;
1499 record_tdep
->size_iovec
= 16;
1501 else if (wordsize
== 4)
1503 record_tdep
->size_pointer
= 4;
1504 record_tdep
->size__old_kernel_stat
= 32;
1505 record_tdep
->size_tms
= 16;
1506 record_tdep
->size_loff_t
= 8;
1507 record_tdep
->size_flock
= 16;
1508 record_tdep
->size_oldold_utsname
= 45;
1509 record_tdep
->size_ustat
= 20;
1510 record_tdep
->size_old_sigaction
= 152;
1511 record_tdep
->size_old_sigset_t
= 128;
1512 record_tdep
->size_rlimit
= 8;
1513 record_tdep
->size_rusage
= 72;
1514 record_tdep
->size_timeval
= 8;
1515 record_tdep
->size_timezone
= 8;
1516 record_tdep
->size_old_gid_t
= 4;
1517 record_tdep
->size_old_uid_t
= 4;
1518 record_tdep
->size_fd_set
= 128;
1519 record_tdep
->size_dirent
= 268;
1520 record_tdep
->size_dirent64
= 280;
1521 record_tdep
->size_statfs
= 64;
1522 record_tdep
->size_statfs64
= 88;
1523 record_tdep
->size_sockaddr
= 16;
1524 record_tdep
->size_int
= 4;
1525 record_tdep
->size_long
= 4;
1526 record_tdep
->size_ulong
= 4;
1527 record_tdep
->size_msghdr
= 28;
1528 record_tdep
->size_itimerval
= 16;
1529 record_tdep
->size_stat
= 88;
1530 record_tdep
->size_old_utsname
= 325;
1531 record_tdep
->size_sysinfo
= 64;
1532 record_tdep
->size_msqid_ds
= 68;
1533 record_tdep
->size_shmid_ds
= 60;
1534 record_tdep
->size_new_utsname
= 390;
1535 record_tdep
->size_timex
= 128;
1536 record_tdep
->size_mem_dqinfo
= 24;
1537 record_tdep
->size_if_dqblk
= 72;
1538 record_tdep
->size_fs_quota_stat
= 80;
1539 record_tdep
->size_timespec
= 8;
1540 record_tdep
->size_pollfd
= 8;
1541 record_tdep
->size_NFS_FHSIZE
= 32;
1542 record_tdep
->size_knfsd_fh
= 132;
1543 record_tdep
->size_TASK_COMM_LEN
= 32;
1544 record_tdep
->size_sigaction
= 140;
1545 record_tdep
->size_sigset_t
= 128;
1546 record_tdep
->size_siginfo_t
= 128;
1547 record_tdep
->size_cap_user_data_t
= 4;
1548 record_tdep
->size_stack_t
= 12;
1549 record_tdep
->size_off_t
= 4;
1550 record_tdep
->size_stat64
= 104;
1551 record_tdep
->size_gid_t
= 4;
1552 record_tdep
->size_uid_t
= 4;
1553 record_tdep
->size_PAGE_SIZE
= 0x10000; /* 64KB */
1554 record_tdep
->size_flock64
= 32;
1555 record_tdep
->size_io_event
= 32;
1556 record_tdep
->size_iocb
= 64;
1557 record_tdep
->size_epoll_event
= 16;
1558 record_tdep
->size_itimerspec
= 16;
1559 record_tdep
->size_mq_attr
= 32;
1560 record_tdep
->size_siginfo
= 128;
1561 record_tdep
->size_termios
= 44;
1562 record_tdep
->size_pid_t
= 4;
1563 record_tdep
->size_winsize
= 8;
1564 record_tdep
->size_serial_struct
= 60;
1565 record_tdep
->size_serial_icounter_struct
= 80;
1566 record_tdep
->size_size_t
= 4;
1567 record_tdep
->size_iovec
= 8;
1570 internal_error (__FILE__
, __LINE__
, _("unexpected wordsize"));
1572 /* These values are the second argument of system call "sys_fcntl"
1573 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1574 record_tdep
->fcntl_F_GETLK
= 5;
1575 record_tdep
->fcntl_F_GETLK64
= 12;
1576 record_tdep
->fcntl_F_SETLK64
= 13;
1577 record_tdep
->fcntl_F_SETLKW64
= 14;
1579 record_tdep
->arg1
= PPC_R0_REGNUM
+ 3;
1580 record_tdep
->arg2
= PPC_R0_REGNUM
+ 4;
1581 record_tdep
->arg3
= PPC_R0_REGNUM
+ 5;
1582 record_tdep
->arg4
= PPC_R0_REGNUM
+ 6;
1583 record_tdep
->arg5
= PPC_R0_REGNUM
+ 7;
1584 record_tdep
->arg6
= PPC_R0_REGNUM
+ 8;
1586 /* These values are the second argument of system call "sys_ioctl".
1587 They are obtained from Linux Kernel source.
1588 See arch/powerpc/include/uapi/asm/ioctls.h. */
1589 record_tdep
->ioctl_TCGETS
= 0x403c7413;
1590 record_tdep
->ioctl_TCSETS
= 0x803c7414;
1591 record_tdep
->ioctl_TCSETSW
= 0x803c7415;
1592 record_tdep
->ioctl_TCSETSF
= 0x803c7416;
1593 record_tdep
->ioctl_TCGETA
= 0x40147417;
1594 record_tdep
->ioctl_TCSETA
= 0x80147418;
1595 record_tdep
->ioctl_TCSETAW
= 0x80147419;
1596 record_tdep
->ioctl_TCSETAF
= 0x8014741c;
1597 record_tdep
->ioctl_TCSBRK
= 0x2000741d;
1598 record_tdep
->ioctl_TCXONC
= 0x2000741e;
1599 record_tdep
->ioctl_TCFLSH
= 0x2000741f;
1600 record_tdep
->ioctl_TIOCEXCL
= 0x540c;
1601 record_tdep
->ioctl_TIOCNXCL
= 0x540d;
1602 record_tdep
->ioctl_TIOCSCTTY
= 0x540e;
1603 record_tdep
->ioctl_TIOCGPGRP
= 0x40047477;
1604 record_tdep
->ioctl_TIOCSPGRP
= 0x80047476;
1605 record_tdep
->ioctl_TIOCOUTQ
= 0x40047473;
1606 record_tdep
->ioctl_TIOCSTI
= 0x5412;
1607 record_tdep
->ioctl_TIOCGWINSZ
= 0x40087468;
1608 record_tdep
->ioctl_TIOCSWINSZ
= 0x80087467;
1609 record_tdep
->ioctl_TIOCMGET
= 0x5415;
1610 record_tdep
->ioctl_TIOCMBIS
= 0x5416;
1611 record_tdep
->ioctl_TIOCMBIC
= 0x5417;
1612 record_tdep
->ioctl_TIOCMSET
= 0x5418;
1613 record_tdep
->ioctl_TIOCGSOFTCAR
= 0x5419;
1614 record_tdep
->ioctl_TIOCSSOFTCAR
= 0x541a;
1615 record_tdep
->ioctl_FIONREAD
= 0x4004667f;
1616 record_tdep
->ioctl_TIOCINQ
= 0x4004667f;
1617 record_tdep
->ioctl_TIOCLINUX
= 0x541c;
1618 record_tdep
->ioctl_TIOCCONS
= 0x541d;
1619 record_tdep
->ioctl_TIOCGSERIAL
= 0x541e;
1620 record_tdep
->ioctl_TIOCSSERIAL
= 0x541f;
1621 record_tdep
->ioctl_TIOCPKT
= 0x5420;
1622 record_tdep
->ioctl_FIONBIO
= 0x8004667e;
1623 record_tdep
->ioctl_TIOCNOTTY
= 0x5422;
1624 record_tdep
->ioctl_TIOCSETD
= 0x5423;
1625 record_tdep
->ioctl_TIOCGETD
= 0x5424;
1626 record_tdep
->ioctl_TCSBRKP
= 0x5425;
1627 record_tdep
->ioctl_TIOCSBRK
= 0x5427;
1628 record_tdep
->ioctl_TIOCCBRK
= 0x5428;
1629 record_tdep
->ioctl_TIOCGSID
= 0x5429;
1630 record_tdep
->ioctl_TIOCGPTN
= 0x40045430;
1631 record_tdep
->ioctl_TIOCSPTLCK
= 0x80045431;
1632 record_tdep
->ioctl_FIONCLEX
= 0x20006602;
1633 record_tdep
->ioctl_FIOCLEX
= 0x20006601;
1634 record_tdep
->ioctl_FIOASYNC
= 0x8004667d;
1635 record_tdep
->ioctl_TIOCSERCONFIG
= 0x5453;
1636 record_tdep
->ioctl_TIOCSERGWILD
= 0x5454;
1637 record_tdep
->ioctl_TIOCSERSWILD
= 0x5455;
1638 record_tdep
->ioctl_TIOCGLCKTRMIOS
= 0x5456;
1639 record_tdep
->ioctl_TIOCSLCKTRMIOS
= 0x5457;
1640 record_tdep
->ioctl_TIOCSERGSTRUCT
= 0x5458;
1641 record_tdep
->ioctl_TIOCSERGETLSR
= 0x5459;
1642 record_tdep
->ioctl_TIOCSERGETMULTI
= 0x545a;
1643 record_tdep
->ioctl_TIOCSERSETMULTI
= 0x545b;
1644 record_tdep
->ioctl_TIOCMIWAIT
= 0x545c;
1645 record_tdep
->ioctl_TIOCGICOUNT
= 0x545d;
1646 record_tdep
->ioctl_FIOQSIZE
= 0x40086680;
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
;
1655 static const char *const stap_integer_prefixes
[] = { "i", NULL
};
1656 static const char *const stap_register_indirection_prefixes
[] = { "(",
1658 static const char *const stap_register_indirection_suffixes
[] = { ")",
1661 linux_init_abi (info
, gdbarch
);
1663 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1664 128-bit, they are IBM long double, not IEEE quad long double as
1665 in the System V ABI PowerPC Processor Supplement. We can safely
1666 let them default to 128-bit, since the debug info will give the
1667 size of type actually used in each case. */
1668 set_gdbarch_long_double_bit (gdbarch
, 16 * TARGET_CHAR_BIT
);
1669 set_gdbarch_long_double_format (gdbarch
, floatformats_ibm_long_double
);
1671 /* Handle inferior calls during interrupted system calls. */
1672 set_gdbarch_write_pc (gdbarch
, ppc_linux_write_pc
);
1674 /* Get the syscall number from the arch's register. */
1675 set_gdbarch_get_syscall_number (gdbarch
, ppc_linux_get_syscall_number
);
1677 /* SystemTap functions. */
1678 set_gdbarch_stap_integer_prefixes (gdbarch
, stap_integer_prefixes
);
1679 set_gdbarch_stap_register_indirection_prefixes (gdbarch
,
1680 stap_register_indirection_prefixes
);
1681 set_gdbarch_stap_register_indirection_suffixes (gdbarch
,
1682 stap_register_indirection_suffixes
);
1683 set_gdbarch_stap_gdb_register_prefix (gdbarch
, "r");
1684 set_gdbarch_stap_is_single_operand (gdbarch
, ppc_stap_is_single_operand
);
1685 set_gdbarch_stap_parse_special_token (gdbarch
,
1686 ppc_stap_parse_special_token
);
1688 if (tdep
->wordsize
== 4)
1690 /* Until November 2001, gcc did not comply with the 32 bit SysV
1691 R4 ABI requirement that structures less than or equal to 8
1692 bytes should be returned in registers. Instead GCC was using
1693 the AIX/PowerOpen ABI - everything returned in memory
1694 (well ignoring vectors that is). When this was corrected, it
1695 wasn't fixed for GNU/Linux native platform. Use the
1696 PowerOpen struct convention. */
1697 set_gdbarch_return_value (gdbarch
, ppc_linux_return_value
);
1699 set_gdbarch_memory_remove_breakpoint (gdbarch
,
1700 ppc_linux_memory_remove_breakpoint
);
1702 /* Shared library handling. */
1703 set_gdbarch_skip_trampoline_code (gdbarch
, ppc_skip_trampoline_code
);
1704 set_solib_svr4_fetch_link_map_offsets
1705 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1707 /* Setting the correct XML syscall filename. */
1708 set_xml_syscall_file_name (gdbarch
, XML_SYSCALL_FILENAME_PPC
);
1711 tramp_frame_prepend_unwinder (gdbarch
,
1712 &ppc32_linux_sigaction_tramp_frame
);
1713 tramp_frame_prepend_unwinder (gdbarch
,
1714 &ppc32_linux_sighandler_tramp_frame
);
1716 /* BFD target for core files. */
1717 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
1718 set_gdbarch_gcore_bfd_target (gdbarch
, "elf32-powerpcle");
1720 set_gdbarch_gcore_bfd_target (gdbarch
, "elf32-powerpc");
1722 if (powerpc_so_ops
.in_dynsym_resolve_code
== NULL
)
1724 powerpc_so_ops
= svr4_so_ops
;
1725 /* Override dynamic resolve function. */
1726 powerpc_so_ops
.in_dynsym_resolve_code
=
1727 powerpc_linux_in_dynsym_resolve_code
;
1729 set_solib_ops (gdbarch
, &powerpc_so_ops
);
1731 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
1734 if (tdep
->wordsize
== 8)
1736 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
1738 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1739 function descriptors). */
1740 set_gdbarch_convert_from_func_ptr_addr
1741 (gdbarch
, ppc64_convert_from_func_ptr_addr
);
1743 set_gdbarch_elf_make_msymbol_special
1744 (gdbarch
, ppc64_elf_make_msymbol_special
);
1748 set_gdbarch_elf_make_msymbol_special
1749 (gdbarch
, ppc_elfv2_elf_make_msymbol_special
);
1751 set_gdbarch_skip_entrypoint (gdbarch
, ppc_elfv2_skip_entrypoint
);
1754 /* Shared library handling. */
1755 set_gdbarch_skip_trampoline_code (gdbarch
, ppc64_skip_trampoline_code
);
1756 set_solib_svr4_fetch_link_map_offsets
1757 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
1759 /* Setting the correct XML syscall filename. */
1760 set_xml_syscall_file_name (gdbarch
, XML_SYSCALL_FILENAME_PPC64
);
1763 tramp_frame_prepend_unwinder (gdbarch
,
1764 &ppc64_linux_sigaction_tramp_frame
);
1765 tramp_frame_prepend_unwinder (gdbarch
,
1766 &ppc64_linux_sighandler_tramp_frame
);
1768 /* BFD target for core files. */
1769 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
1770 set_gdbarch_gcore_bfd_target (gdbarch
, "elf64-powerpcle");
1772 set_gdbarch_gcore_bfd_target (gdbarch
, "elf64-powerpc");
1775 /* PPC32 uses a different prpsinfo32 compared to most other Linux
1777 if (tdep
->wordsize
== 4)
1778 set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch
,
1779 elfcore_write_ppc_linux_prpsinfo32
);
1781 set_gdbarch_core_read_description (gdbarch
, ppc_linux_core_read_description
);
1782 set_gdbarch_iterate_over_regset_sections (gdbarch
,
1783 ppc_linux_iterate_over_regset_sections
);
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
);
1829 /* Support reverse debugging. */
1830 set_gdbarch_process_record (gdbarch
, ppc_process_record
);
1831 set_gdbarch_process_record_signal (gdbarch
, ppc_linux_record_signal
);
1832 tdep
->ppc_syscall_record
= ppc_linux_syscall_record
;
1834 ppc_init_linux_record_tdep (&ppc_linux_record_tdep
, 4);
1835 ppc_init_linux_record_tdep (&ppc64_linux_record_tdep
, 8);
1838 /* Provide a prototype to silence -Wmissing-prototypes. */
1839 extern initialize_file_ftype _initialize_ppc_linux_tdep
;
1842 _initialize_ppc_linux_tdep (void)
1844 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1845 64-bit PowerPC, and the older rs6k. */
1846 gdbarch_register_osabi (bfd_arch_powerpc
, bfd_mach_ppc
, GDB_OSABI_LINUX
,
1847 ppc_linux_init_abi
);
1848 gdbarch_register_osabi (bfd_arch_powerpc
, bfd_mach_ppc64
, GDB_OSABI_LINUX
,
1849 ppc_linux_init_abi
);
1850 gdbarch_register_osabi (bfd_arch_rs6000
, bfd_mach_rs6k
, GDB_OSABI_LINUX
,
1851 ppc_linux_init_abi
);
1853 /* Attach to inferior_created observer. */
1854 observer_attach_inferior_created (ppc_linux_inferior_created
);
1856 /* Attach to observers to track __spe_current_active_context. */
1857 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created
);
1858 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded
);
1859 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded
);
1861 /* Initialize the Linux target descriptions. */
1862 initialize_tdesc_powerpc_32l ();
1863 initialize_tdesc_powerpc_altivec32l ();
1864 initialize_tdesc_powerpc_cell32l ();
1865 initialize_tdesc_powerpc_vsx32l ();
1866 initialize_tdesc_powerpc_isa205_32l ();
1867 initialize_tdesc_powerpc_isa205_altivec32l ();
1868 initialize_tdesc_powerpc_isa205_vsx32l ();
1869 initialize_tdesc_powerpc_64l ();
1870 initialize_tdesc_powerpc_altivec64l ();
1871 initialize_tdesc_powerpc_cell64l ();
1872 initialize_tdesc_powerpc_vsx64l ();
1873 initialize_tdesc_powerpc_isa205_64l ();
1874 initialize_tdesc_powerpc_isa205_altivec64l ();
1875 initialize_tdesc_powerpc_isa205_vsx64l ();
1876 initialize_tdesc_powerpc_e500l ();