]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/ppc-linux-tdep.c
PowerPC64 ELFv2 ABI: no function descriptors
[thirdparty/binutils-gdb.git] / gdb / ppc-linux-tdep.c
1 /* Target-dependent code for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2014 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "inferior.h"
23 #include "symtab.h"
24 #include "target.h"
25 #include "gdbcore.h"
26 #include "gdbcmd.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "regcache.h"
30 #include "value.h"
31 #include "osabi.h"
32 #include "regset.h"
33 #include "solib-svr4.h"
34 #include "solib-spu.h"
35 #include "solib.h"
36 #include "solist.h"
37 #include "ppc-tdep.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"
44 #include "observer.h"
45 #include "auxv.h"
46 #include "elf/common.h"
47 #include "exceptions.h"
48 #include "arch-utils.h"
49 #include "spu-tdep.h"
50 #include "xml-syscall.h"
51 #include "linux-tdep.h"
52
53 #include "stap-probe.h"
54 #include "ax.h"
55 #include "ax-gdb.h"
56 #include "cli/cli-utils.h"
57 #include "parser-defs.h"
58 #include "user-regs.h"
59 #include <ctype.h>
60 #include "elf-bfd.h" /* for elfcore_write_* */
61
62 #include "features/rs6000/powerpc-32l.c"
63 #include "features/rs6000/powerpc-altivec32l.c"
64 #include "features/rs6000/powerpc-cell32l.c"
65 #include "features/rs6000/powerpc-vsx32l.c"
66 #include "features/rs6000/powerpc-isa205-32l.c"
67 #include "features/rs6000/powerpc-isa205-altivec32l.c"
68 #include "features/rs6000/powerpc-isa205-vsx32l.c"
69 #include "features/rs6000/powerpc-64l.c"
70 #include "features/rs6000/powerpc-altivec64l.c"
71 #include "features/rs6000/powerpc-cell64l.c"
72 #include "features/rs6000/powerpc-vsx64l.c"
73 #include "features/rs6000/powerpc-isa205-64l.c"
74 #include "features/rs6000/powerpc-isa205-altivec64l.c"
75 #include "features/rs6000/powerpc-isa205-vsx64l.c"
76 #include "features/rs6000/powerpc-e500l.c"
77
78 /* Shared library operations for PowerPC-Linux. */
79 static struct target_so_ops powerpc_so_ops;
80
81 /* The syscall's XML filename for PPC and PPC64. */
82 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
83 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
84
85 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
86 in much the same fashion as memory_remove_breakpoint in mem-break.c,
87 but is careful not to write back the previous contents if the code
88 in question has changed in between inserting the breakpoint and
89 removing it.
90
91 Here is the problem that we're trying to solve...
92
93 Once upon a time, before introducing this function to remove
94 breakpoints from the inferior, setting a breakpoint on a shared
95 library function prior to running the program would not work
96 properly. In order to understand the problem, it is first
97 necessary to understand a little bit about dynamic linking on
98 this platform.
99
100 A call to a shared library function is accomplished via a bl
101 (branch-and-link) instruction whose branch target is an entry
102 in the procedure linkage table (PLT). The PLT in the object
103 file is uninitialized. To gdb, prior to running the program, the
104 entries in the PLT are all zeros.
105
106 Once the program starts running, the shared libraries are loaded
107 and the procedure linkage table is initialized, but the entries in
108 the table are not (necessarily) resolved. Once a function is
109 actually called, the code in the PLT is hit and the function is
110 resolved. In order to better illustrate this, an example is in
111 order; the following example is from the gdb testsuite.
112
113 We start the program shmain.
114
115 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
116 [...]
117
118 We place two breakpoints, one on shr1 and the other on main.
119
120 (gdb) b shr1
121 Breakpoint 1 at 0x100409d4
122 (gdb) b main
123 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
124
125 Examine the instruction (and the immediatly following instruction)
126 upon which the breakpoint was placed. Note that the PLT entry
127 for shr1 contains zeros.
128
129 (gdb) x/2i 0x100409d4
130 0x100409d4 <shr1>: .long 0x0
131 0x100409d8 <shr1+4>: .long 0x0
132
133 Now run 'til main.
134
135 (gdb) r
136 Starting program: gdb.base/shmain
137 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
138
139 Breakpoint 2, main ()
140 at gdb.base/shmain.c:44
141 44 g = 1;
142
143 Examine the PLT again. Note that the loading of the shared
144 library has initialized the PLT to code which loads a constant
145 (which I think is an index into the GOT) into r11 and then
146 branchs a short distance to the code which actually does the
147 resolving.
148
149 (gdb) x/2i 0x100409d4
150 0x100409d4 <shr1>: li r11,4
151 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
152 (gdb) c
153 Continuing.
154
155 Breakpoint 1, shr1 (x=1)
156 at gdb.base/shr1.c:19
157 19 l = 1;
158
159 Now we've hit the breakpoint at shr1. (The breakpoint was
160 reset from the PLT entry to the actual shr1 function after the
161 shared library was loaded.) Note that the PLT entry has been
162 resolved to contain a branch that takes us directly to shr1.
163 (The real one, not the PLT entry.)
164
165 (gdb) x/2i 0x100409d4
166 0x100409d4 <shr1>: b 0xffaf76c <shr1>
167 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
168
169 The thing to note here is that the PLT entry for shr1 has been
170 changed twice.
171
172 Now the problem should be obvious. GDB places a breakpoint (a
173 trap instruction) on the zero value of the PLT entry for shr1.
174 Later on, after the shared library had been loaded and the PLT
175 initialized, GDB gets a signal indicating this fact and attempts
176 (as it always does when it stops) to remove all the breakpoints.
177
178 The breakpoint removal was causing the former contents (a zero
179 word) to be written back to the now initialized PLT entry thus
180 destroying a portion of the initialization that had occurred only a
181 short time ago. When execution continued, the zero word would be
182 executed as an instruction an illegal instruction trap was
183 generated instead. (0 is not a legal instruction.)
184
185 The fix for this problem was fairly straightforward. The function
186 memory_remove_breakpoint from mem-break.c was copied to this file,
187 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
188 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
189 function.
190
191 The differences between ppc_linux_memory_remove_breakpoint () and
192 memory_remove_breakpoint () are minor. All that the former does
193 that the latter does not is check to make sure that the breakpoint
194 location actually contains a breakpoint (trap instruction) prior
195 to attempting to write back the old contents. If it does contain
196 a trap instruction, we allow the old contents to be written back.
197 Otherwise, we silently do nothing.
198
199 The big question is whether memory_remove_breakpoint () should be
200 changed to have the same functionality. The downside is that more
201 traffic is generated for remote targets since we'll have an extra
202 fetch of a memory word each time a breakpoint is removed.
203
204 For the time being, we'll leave this self-modifying-code-friendly
205 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
206 else in the event that some other platform has similar needs with
207 regard to removing breakpoints in some potentially self modifying
208 code. */
209 static int
210 ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
211 struct bp_target_info *bp_tgt)
212 {
213 CORE_ADDR addr = bp_tgt->placed_address;
214 const unsigned char *bp;
215 int val;
216 int bplen;
217 gdb_byte old_contents[BREAKPOINT_MAX];
218 struct cleanup *cleanup;
219
220 /* Determine appropriate breakpoint contents and size for this address. */
221 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
222 if (bp == NULL)
223 error (_("Software breakpoints not implemented for this target."));
224
225 /* Make sure we see the memory breakpoints. */
226 cleanup = make_show_memory_breakpoints_cleanup (1);
227 val = target_read_memory (addr, old_contents, bplen);
228
229 /* If our breakpoint is no longer at the address, this means that the
230 program modified the code on us, so it is wrong to put back the
231 old value. */
232 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
233 val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
234
235 do_cleanups (cleanup);
236 return val;
237 }
238
239 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
240 than the 32 bit SYSV R4 ABI structure return convention - all
241 structures, no matter their size, are put in memory. Vectors,
242 which were added later, do get returned in a register though. */
243
244 static enum return_value_convention
245 ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
246 struct type *valtype, struct regcache *regcache,
247 gdb_byte *readbuf, const gdb_byte *writebuf)
248 {
249 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
250 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
251 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
252 && TYPE_VECTOR (valtype)))
253 return RETURN_VALUE_STRUCT_CONVENTION;
254 else
255 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
256 readbuf, writebuf);
257 }
258
259 static struct core_regset_section ppc_linux_vsx_regset_sections[] =
260 {
261 { ".reg", 48 * 4, "general-purpose" },
262 { ".reg2", 264, "floating-point" },
263 { ".reg-ppc-vmx", 544, "ppc Altivec" },
264 { ".reg-ppc-vsx", 256, "POWER7 VSX" },
265 { NULL, 0}
266 };
267
268 static struct core_regset_section ppc_linux_vmx_regset_sections[] =
269 {
270 { ".reg", 48 * 4, "general-purpose" },
271 { ".reg2", 264, "floating-point" },
272 { ".reg-ppc-vmx", 544, "ppc Altivec" },
273 { NULL, 0}
274 };
275
276 static struct core_regset_section ppc_linux_fp_regset_sections[] =
277 {
278 { ".reg", 48 * 4, "general-purpose" },
279 { ".reg2", 264, "floating-point" },
280 { NULL, 0}
281 };
282
283 static struct core_regset_section ppc64_linux_vsx_regset_sections[] =
284 {
285 { ".reg", 48 * 8, "general-purpose" },
286 { ".reg2", 264, "floating-point" },
287 { ".reg-ppc-vmx", 544, "ppc Altivec" },
288 { ".reg-ppc-vsx", 256, "POWER7 VSX" },
289 { NULL, 0}
290 };
291
292 static struct core_regset_section ppc64_linux_vmx_regset_sections[] =
293 {
294 { ".reg", 48 * 8, "general-purpose" },
295 { ".reg2", 264, "floating-point" },
296 { ".reg-ppc-vmx", 544, "ppc Altivec" },
297 { NULL, 0}
298 };
299
300 static struct core_regset_section ppc64_linux_fp_regset_sections[] =
301 {
302 { ".reg", 48 * 8, "general-purpose" },
303 { ".reg2", 264, "floating-point" },
304 { NULL, 0}
305 };
306
307 /* PLT stub in executable. */
308 static struct ppc_insn_pattern powerpc32_plt_stub[] =
309 {
310 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
311 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
312 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
313 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
314 { 0, 0, 0 }
315 };
316
317 /* PLT stub in shared library. */
318 static struct ppc_insn_pattern powerpc32_plt_stub_so[] =
319 {
320 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
321 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
322 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
323 { 0xffffffff, 0x60000000, 0 }, /* nop */
324 { 0, 0, 0 }
325 };
326 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub)
327
328 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
329 section. For secure PLT, stub is in .text and we need to check
330 instruction patterns. */
331
332 static int
333 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
334 {
335 struct bound_minimal_symbol sym;
336
337 /* Check whether PC is in the dynamic linker. This also checks
338 whether it is in the .plt section, used by non-PIC executables. */
339 if (svr4_in_dynsym_resolve_code (pc))
340 return 1;
341
342 /* Check if we are in the resolver. */
343 sym = lookup_minimal_symbol_by_pc (pc);
344 if (sym.minsym != NULL
345 && (strcmp (SYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0
346 || strcmp (SYMBOL_LINKAGE_NAME (sym.minsym),
347 "__glink_PLTresolve") == 0))
348 return 1;
349
350 return 0;
351 }
352
353 /* Follow PLT stub to actual routine. */
354
355 static CORE_ADDR
356 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
357 {
358 unsigned int insnbuf[POWERPC32_PLT_STUB_LEN];
359 struct gdbarch *gdbarch = get_frame_arch (frame);
360 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
361 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
362 CORE_ADDR target = 0;
363
364 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
365 {
366 /* Insn pattern is
367 lis r11, xxxx
368 lwz r11, xxxx(r11)
369 Branch target is in r11. */
370
371 target = (ppc_insn_d_field (insnbuf[0]) << 16)
372 | ppc_insn_d_field (insnbuf[1]);
373 target = read_memory_unsigned_integer (target, 4, byte_order);
374 }
375
376 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, insnbuf))
377 {
378 /* Insn pattern is
379 lwz r11, xxxx(r30)
380 Branch target is in r11. */
381
382 target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30)
383 + ppc_insn_d_field (insnbuf[0]);
384 target = read_memory_unsigned_integer (target, 4, byte_order);
385 }
386
387 return target;
388 }
389
390 /* Wrappers to handle Linux-only registers. */
391
392 static void
393 ppc_linux_supply_gregset (const struct regset *regset,
394 struct regcache *regcache,
395 int regnum, const void *gregs, size_t len)
396 {
397 const struct ppc_reg_offsets *offsets = regset->descr;
398
399 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
400
401 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
402 {
403 /* "orig_r3" is stored 2 slots after "pc". */
404 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
405 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
406 offsets->pc_offset + 2 * offsets->gpr_size,
407 offsets->gpr_size);
408
409 /* "trap" is stored 8 slots after "pc". */
410 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
411 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, gregs,
412 offsets->pc_offset + 8 * offsets->gpr_size,
413 offsets->gpr_size);
414 }
415 }
416
417 static void
418 ppc_linux_collect_gregset (const struct regset *regset,
419 const struct regcache *regcache,
420 int regnum, void *gregs, size_t len)
421 {
422 const struct ppc_reg_offsets *offsets = regset->descr;
423
424 /* Clear areas in the linux gregset not written elsewhere. */
425 if (regnum == -1)
426 memset (gregs, 0, len);
427
428 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
429
430 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
431 {
432 /* "orig_r3" is stored 2 slots after "pc". */
433 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
434 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
435 offsets->pc_offset + 2 * offsets->gpr_size,
436 offsets->gpr_size);
437
438 /* "trap" is stored 8 slots after "pc". */
439 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
440 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, gregs,
441 offsets->pc_offset + 8 * offsets->gpr_size,
442 offsets->gpr_size);
443 }
444 }
445
446 /* Regset descriptions. */
447 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
448 {
449 /* General-purpose registers. */
450 /* .r0_offset = */ 0,
451 /* .gpr_size = */ 4,
452 /* .xr_size = */ 4,
453 /* .pc_offset = */ 128,
454 /* .ps_offset = */ 132,
455 /* .cr_offset = */ 152,
456 /* .lr_offset = */ 144,
457 /* .ctr_offset = */ 140,
458 /* .xer_offset = */ 148,
459 /* .mq_offset = */ 156,
460
461 /* Floating-point registers. */
462 /* .f0_offset = */ 0,
463 /* .fpscr_offset = */ 256,
464 /* .fpscr_size = */ 8,
465
466 /* AltiVec registers. */
467 /* .vr0_offset = */ 0,
468 /* .vscr_offset = */ 512 + 12,
469 /* .vrsave_offset = */ 528
470 };
471
472 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
473 {
474 /* General-purpose registers. */
475 /* .r0_offset = */ 0,
476 /* .gpr_size = */ 8,
477 /* .xr_size = */ 8,
478 /* .pc_offset = */ 256,
479 /* .ps_offset = */ 264,
480 /* .cr_offset = */ 304,
481 /* .lr_offset = */ 288,
482 /* .ctr_offset = */ 280,
483 /* .xer_offset = */ 296,
484 /* .mq_offset = */ 312,
485
486 /* Floating-point registers. */
487 /* .f0_offset = */ 0,
488 /* .fpscr_offset = */ 256,
489 /* .fpscr_size = */ 8,
490
491 /* AltiVec registers. */
492 /* .vr0_offset = */ 0,
493 /* .vscr_offset = */ 512 + 12,
494 /* .vrsave_offset = */ 528
495 };
496
497 static const struct regset ppc32_linux_gregset = {
498 &ppc32_linux_reg_offsets,
499 ppc_linux_supply_gregset,
500 ppc_linux_collect_gregset,
501 NULL
502 };
503
504 static const struct regset ppc64_linux_gregset = {
505 &ppc64_linux_reg_offsets,
506 ppc_linux_supply_gregset,
507 ppc_linux_collect_gregset,
508 NULL
509 };
510
511 static const struct regset ppc32_linux_fpregset = {
512 &ppc32_linux_reg_offsets,
513 ppc_supply_fpregset,
514 ppc_collect_fpregset,
515 NULL
516 };
517
518 static const struct regset ppc32_linux_vrregset = {
519 &ppc32_linux_reg_offsets,
520 ppc_supply_vrregset,
521 ppc_collect_vrregset,
522 NULL
523 };
524
525 static const struct regset ppc32_linux_vsxregset = {
526 &ppc32_linux_reg_offsets,
527 ppc_supply_vsxregset,
528 ppc_collect_vsxregset,
529 NULL
530 };
531
532 const struct regset *
533 ppc_linux_gregset (int wordsize)
534 {
535 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
536 }
537
538 const struct regset *
539 ppc_linux_fpregset (void)
540 {
541 return &ppc32_linux_fpregset;
542 }
543
544 static const struct regset *
545 ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
546 const char *sect_name, size_t sect_size)
547 {
548 struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
549 if (strcmp (sect_name, ".reg") == 0)
550 {
551 if (tdep->wordsize == 4)
552 return &ppc32_linux_gregset;
553 else
554 return &ppc64_linux_gregset;
555 }
556 if (strcmp (sect_name, ".reg2") == 0)
557 return &ppc32_linux_fpregset;
558 if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
559 return &ppc32_linux_vrregset;
560 if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
561 return &ppc32_linux_vsxregset;
562 return NULL;
563 }
564
565 static void
566 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
567 struct trad_frame_cache *this_cache,
568 CORE_ADDR func, LONGEST offset,
569 int bias)
570 {
571 CORE_ADDR base;
572 CORE_ADDR regs;
573 CORE_ADDR gpregs;
574 CORE_ADDR fpregs;
575 int i;
576 struct gdbarch *gdbarch = get_frame_arch (this_frame);
577 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
578 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
579
580 base = get_frame_register_unsigned (this_frame,
581 gdbarch_sp_regnum (gdbarch));
582 if (bias > 0 && get_frame_pc (this_frame) != func)
583 /* See below, some signal trampolines increment the stack as their
584 first instruction, need to compensate for that. */
585 base -= bias;
586
587 /* Find the address of the register buffer pointer. */
588 regs = base + offset;
589 /* Use that to find the address of the corresponding register
590 buffers. */
591 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
592 fpregs = gpregs + 48 * tdep->wordsize;
593
594 /* General purpose. */
595 for (i = 0; i < 32; i++)
596 {
597 int regnum = i + tdep->ppc_gp0_regnum;
598 trad_frame_set_reg_addr (this_cache,
599 regnum, gpregs + i * tdep->wordsize);
600 }
601 trad_frame_set_reg_addr (this_cache,
602 gdbarch_pc_regnum (gdbarch),
603 gpregs + 32 * tdep->wordsize);
604 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
605 gpregs + 35 * tdep->wordsize);
606 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
607 gpregs + 36 * tdep->wordsize);
608 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
609 gpregs + 37 * tdep->wordsize);
610 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
611 gpregs + 38 * tdep->wordsize);
612
613 if (ppc_linux_trap_reg_p (gdbarch))
614 {
615 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
616 gpregs + 34 * tdep->wordsize);
617 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
618 gpregs + 40 * tdep->wordsize);
619 }
620
621 if (ppc_floating_point_unit_p (gdbarch))
622 {
623 /* Floating point registers. */
624 for (i = 0; i < 32; i++)
625 {
626 int regnum = i + gdbarch_fp0_regnum (gdbarch);
627 trad_frame_set_reg_addr (this_cache, regnum,
628 fpregs + i * tdep->wordsize);
629 }
630 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
631 fpregs + 32 * tdep->wordsize);
632 }
633 trad_frame_set_id (this_cache, frame_id_build (base, func));
634 }
635
636 static void
637 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
638 struct frame_info *this_frame,
639 struct trad_frame_cache *this_cache,
640 CORE_ADDR func)
641 {
642 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
643 0xd0 /* Offset to ucontext_t. */
644 + 0x30 /* Offset to .reg. */,
645 0);
646 }
647
648 static void
649 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
650 struct frame_info *this_frame,
651 struct trad_frame_cache *this_cache,
652 CORE_ADDR func)
653 {
654 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
655 0x80 /* Offset to ucontext_t. */
656 + 0xe0 /* Offset to .reg. */,
657 128);
658 }
659
660 static void
661 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
662 struct frame_info *this_frame,
663 struct trad_frame_cache *this_cache,
664 CORE_ADDR func)
665 {
666 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
667 0x40 /* Offset to ucontext_t. */
668 + 0x1c /* Offset to .reg. */,
669 0);
670 }
671
672 static void
673 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
674 struct frame_info *this_frame,
675 struct trad_frame_cache *this_cache,
676 CORE_ADDR func)
677 {
678 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
679 0x80 /* Offset to struct sigcontext. */
680 + 0x38 /* Offset to .reg. */,
681 128);
682 }
683
684 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
685 SIGTRAMP_FRAME,
686 4,
687 {
688 { 0x380000ac, -1 }, /* li r0, 172 */
689 { 0x44000002, -1 }, /* sc */
690 { TRAMP_SENTINEL_INSN },
691 },
692 ppc32_linux_sigaction_cache_init
693 };
694 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
695 SIGTRAMP_FRAME,
696 4,
697 {
698 { 0x38210080, -1 }, /* addi r1,r1,128 */
699 { 0x380000ac, -1 }, /* li r0, 172 */
700 { 0x44000002, -1 }, /* sc */
701 { TRAMP_SENTINEL_INSN },
702 },
703 ppc64_linux_sigaction_cache_init
704 };
705 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
706 SIGTRAMP_FRAME,
707 4,
708 {
709 { 0x38000077, -1 }, /* li r0,119 */
710 { 0x44000002, -1 }, /* sc */
711 { TRAMP_SENTINEL_INSN },
712 },
713 ppc32_linux_sighandler_cache_init
714 };
715 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
716 SIGTRAMP_FRAME,
717 4,
718 {
719 { 0x38210080, -1 }, /* addi r1,r1,128 */
720 { 0x38000077, -1 }, /* li r0,119 */
721 { 0x44000002, -1 }, /* sc */
722 { TRAMP_SENTINEL_INSN },
723 },
724 ppc64_linux_sighandler_cache_init
725 };
726
727
728 /* Address to use for displaced stepping. When debugging a stand-alone
729 SPU executable, entry_point_address () will point to an SPU local-store
730 address and is thus not usable as displaced stepping location. We use
731 the auxiliary vector to determine the PowerPC-side entry point address
732 instead. */
733
734 static CORE_ADDR ppc_linux_entry_point_addr = 0;
735
736 static void
737 ppc_linux_inferior_created (struct target_ops *target, int from_tty)
738 {
739 ppc_linux_entry_point_addr = 0;
740 }
741
742 static CORE_ADDR
743 ppc_linux_displaced_step_location (struct gdbarch *gdbarch)
744 {
745 if (ppc_linux_entry_point_addr == 0)
746 {
747 CORE_ADDR addr;
748
749 /* Determine entry point from target auxiliary vector. */
750 if (target_auxv_search (&current_target, AT_ENTRY, &addr) <= 0)
751 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
752
753 /* Make certain that the address points at real code, and not a
754 function descriptor. */
755 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
756 &current_target);
757
758 /* Inferior calls also use the entry point as a breakpoint location.
759 We don't want displaced stepping to interfere with those
760 breakpoints, so leave space. */
761 ppc_linux_entry_point_addr = addr + 2 * PPC_INSN_SIZE;
762 }
763
764 return ppc_linux_entry_point_addr;
765 }
766
767
768 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
769 int
770 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
771 {
772 /* If we do not have a target description with registers, then
773 the special registers will not be included in the register set. */
774 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
775 return 0;
776
777 /* If we do, then it is safe to check the size. */
778 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
779 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
780 }
781
782 /* Return the current system call's number present in the
783 r0 register. When the function fails, it returns -1. */
784 static LONGEST
785 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
786 ptid_t ptid)
787 {
788 struct regcache *regcache = get_thread_regcache (ptid);
789 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
790 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
791 struct cleanup *cleanbuf;
792 /* The content of a register */
793 gdb_byte *buf;
794 /* The result */
795 LONGEST ret;
796
797 /* Make sure we're in a 32- or 64-bit machine */
798 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
799
800 buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte));
801
802 cleanbuf = make_cleanup (xfree, buf);
803
804 /* Getting the system call number from the register.
805 When dealing with PowerPC architecture, this information
806 is stored at 0th register. */
807 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf);
808
809 ret = extract_signed_integer (buf, tdep->wordsize, byte_order);
810 do_cleanups (cleanbuf);
811
812 return ret;
813 }
814
815 static void
816 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
817 {
818 struct gdbarch *gdbarch = get_regcache_arch (regcache);
819
820 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
821
822 /* Set special TRAP register to -1 to prevent the kernel from
823 messing with the PC we just installed, if we happen to be
824 within an interrupted system call that the kernel wants to
825 restart.
826
827 Note that after we return from the dummy call, the TRAP and
828 ORIG_R3 registers will be automatically restored, and the
829 kernel continues to restart the system call at this point. */
830 if (ppc_linux_trap_reg_p (gdbarch))
831 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
832 }
833
834 static int
835 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
836 {
837 return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
838 }
839
840 static const struct target_desc *
841 ppc_linux_core_read_description (struct gdbarch *gdbarch,
842 struct target_ops *target,
843 bfd *abfd)
844 {
845 asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
846 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
847 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
848 asection *section = bfd_get_section_by_name (abfd, ".reg");
849 if (! section)
850 return NULL;
851
852 switch (bfd_section_size (abfd, section))
853 {
854 case 48 * 4:
855 if (cell)
856 return tdesc_powerpc_cell32l;
857 else if (vsx)
858 return tdesc_powerpc_vsx32l;
859 else if (altivec)
860 return tdesc_powerpc_altivec32l;
861 else
862 return tdesc_powerpc_32l;
863
864 case 48 * 8:
865 if (cell)
866 return tdesc_powerpc_cell64l;
867 else if (vsx)
868 return tdesc_powerpc_vsx64l;
869 else if (altivec)
870 return tdesc_powerpc_altivec64l;
871 else
872 return tdesc_powerpc_64l;
873
874 default:
875 return NULL;
876 }
877 }
878
879 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
880 gdbarch.h. */
881
882 static int
883 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
884 {
885 return (*s == 'i' /* Literal number. */
886 || (isdigit (*s) && s[1] == '('
887 && isdigit (s[2])) /* Displacement. */
888 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
889 || isdigit (*s)); /* Register value. */
890 }
891
892 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
893 gdbarch.h. */
894
895 static int
896 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
897 struct stap_parse_info *p)
898 {
899 if (isdigit (*p->arg))
900 {
901 /* This temporary pointer is needed because we have to do a lookahead.
902 We could be dealing with a register displacement, and in such case
903 we would not need to do anything. */
904 const char *s = p->arg;
905 char *regname;
906 int len;
907 struct stoken str;
908
909 while (isdigit (*s))
910 ++s;
911
912 if (*s == '(')
913 {
914 /* It is a register displacement indeed. Returning 0 means we are
915 deferring the treatment of this case to the generic parser. */
916 return 0;
917 }
918
919 len = s - p->arg;
920 regname = alloca (len + 2);
921 regname[0] = 'r';
922
923 strncpy (regname + 1, p->arg, len);
924 ++len;
925 regname[len] = '\0';
926
927 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
928 error (_("Invalid register name `%s' on expression `%s'."),
929 regname, p->saved_arg);
930
931 write_exp_elt_opcode (OP_REGISTER);
932 str.ptr = regname;
933 str.length = len;
934 write_exp_string (str);
935 write_exp_elt_opcode (OP_REGISTER);
936
937 p->arg = s;
938 }
939 else
940 {
941 /* All the other tokens should be handled correctly by the generic
942 parser. */
943 return 0;
944 }
945
946 return 1;
947 }
948
949 /* Cell/B.E. active SPE context tracking support. */
950
951 static struct objfile *spe_context_objfile = NULL;
952 static CORE_ADDR spe_context_lm_addr = 0;
953 static CORE_ADDR spe_context_offset = 0;
954
955 static ptid_t spe_context_cache_ptid;
956 static CORE_ADDR spe_context_cache_address;
957
958 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
959 to track whether we've loaded a version of libspe2 (as static or dynamic
960 library) that provides the __spe_current_active_context variable. */
961 static void
962 ppc_linux_spe_context_lookup (struct objfile *objfile)
963 {
964 struct minimal_symbol *sym;
965
966 if (!objfile)
967 {
968 spe_context_objfile = NULL;
969 spe_context_lm_addr = 0;
970 spe_context_offset = 0;
971 spe_context_cache_ptid = minus_one_ptid;
972 spe_context_cache_address = 0;
973 return;
974 }
975
976 sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
977 if (sym)
978 {
979 spe_context_objfile = objfile;
980 spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
981 spe_context_offset = SYMBOL_VALUE_ADDRESS (sym);
982 spe_context_cache_ptid = minus_one_ptid;
983 spe_context_cache_address = 0;
984 return;
985 }
986 }
987
988 static void
989 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
990 {
991 struct objfile *objfile;
992
993 ppc_linux_spe_context_lookup (NULL);
994 ALL_OBJFILES (objfile)
995 ppc_linux_spe_context_lookup (objfile);
996 }
997
998 static void
999 ppc_linux_spe_context_solib_loaded (struct so_list *so)
1000 {
1001 if (strstr (so->so_original_name, "/libspe") != NULL)
1002 {
1003 solib_read_symbols (so, 0);
1004 ppc_linux_spe_context_lookup (so->objfile);
1005 }
1006 }
1007
1008 static void
1009 ppc_linux_spe_context_solib_unloaded (struct so_list *so)
1010 {
1011 if (so->objfile == spe_context_objfile)
1012 ppc_linux_spe_context_lookup (NULL);
1013 }
1014
1015 /* Retrieve contents of the N'th element in the current thread's
1016 linked SPE context list into ID and NPC. Return the address of
1017 said context element, or 0 if not found. */
1018 static CORE_ADDR
1019 ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
1020 int n, int *id, unsigned int *npc)
1021 {
1022 CORE_ADDR spe_context = 0;
1023 gdb_byte buf[16];
1024 int i;
1025
1026 /* Quick exit if we have not found __spe_current_active_context. */
1027 if (!spe_context_objfile)
1028 return 0;
1029
1030 /* Look up cached address of thread-local variable. */
1031 if (!ptid_equal (spe_context_cache_ptid, inferior_ptid))
1032 {
1033 struct target_ops *target = &current_target;
1034 volatile struct gdb_exception ex;
1035
1036 while (target && !target->to_get_thread_local_address)
1037 target = find_target_beneath (target);
1038 if (!target)
1039 return 0;
1040
1041 TRY_CATCH (ex, RETURN_MASK_ERROR)
1042 {
1043 /* We do not call target_translate_tls_address here, because
1044 svr4_fetch_objfile_link_map may invalidate the frame chain,
1045 which must not do while inside a frame sniffer.
1046
1047 Instead, we have cached the lm_addr value, and use that to
1048 directly call the target's to_get_thread_local_address. */
1049 spe_context_cache_address
1050 = target->to_get_thread_local_address (target, inferior_ptid,
1051 spe_context_lm_addr,
1052 spe_context_offset);
1053 spe_context_cache_ptid = inferior_ptid;
1054 }
1055
1056 if (ex.reason < 0)
1057 return 0;
1058 }
1059
1060 /* Read variable value. */
1061 if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
1062 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1063
1064 /* Cyle through to N'th linked list element. */
1065 for (i = 0; i < n && spe_context; i++)
1066 if (target_read_memory (spe_context + align_up (12, wordsize),
1067 buf, wordsize) == 0)
1068 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1069 else
1070 spe_context = 0;
1071
1072 /* Read current context. */
1073 if (spe_context
1074 && target_read_memory (spe_context, buf, 12) != 0)
1075 spe_context = 0;
1076
1077 /* Extract data elements. */
1078 if (spe_context)
1079 {
1080 if (id)
1081 *id = extract_signed_integer (buf, 4, byte_order);
1082 if (npc)
1083 *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
1084 }
1085
1086 return spe_context;
1087 }
1088
1089
1090 /* Cell/B.E. cross-architecture unwinder support. */
1091
1092 struct ppu2spu_cache
1093 {
1094 struct frame_id frame_id;
1095 struct regcache *regcache;
1096 };
1097
1098 static struct gdbarch *
1099 ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
1100 {
1101 struct ppu2spu_cache *cache = *this_cache;
1102 return get_regcache_arch (cache->regcache);
1103 }
1104
1105 static void
1106 ppu2spu_this_id (struct frame_info *this_frame,
1107 void **this_cache, struct frame_id *this_id)
1108 {
1109 struct ppu2spu_cache *cache = *this_cache;
1110 *this_id = cache->frame_id;
1111 }
1112
1113 static struct value *
1114 ppu2spu_prev_register (struct frame_info *this_frame,
1115 void **this_cache, int regnum)
1116 {
1117 struct ppu2spu_cache *cache = *this_cache;
1118 struct gdbarch *gdbarch = get_regcache_arch (cache->regcache);
1119 gdb_byte *buf;
1120
1121 buf = alloca (register_size (gdbarch, regnum));
1122
1123 if (regnum < gdbarch_num_regs (gdbarch))
1124 regcache_raw_read (cache->regcache, regnum, buf);
1125 else
1126 gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf);
1127
1128 return frame_unwind_got_bytes (this_frame, regnum, buf);
1129 }
1130
1131 struct ppu2spu_data
1132 {
1133 struct gdbarch *gdbarch;
1134 int id;
1135 unsigned int npc;
1136 gdb_byte gprs[128*16];
1137 };
1138
1139 static int
1140 ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf)
1141 {
1142 struct ppu2spu_data *data = src;
1143 enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
1144
1145 if (regnum >= 0 && regnum < SPU_NUM_GPRS)
1146 memcpy (buf, data->gprs + 16*regnum, 16);
1147 else if (regnum == SPU_ID_REGNUM)
1148 store_unsigned_integer (buf, 4, byte_order, data->id);
1149 else if (regnum == SPU_PC_REGNUM)
1150 store_unsigned_integer (buf, 4, byte_order, data->npc);
1151 else
1152 return REG_UNAVAILABLE;
1153
1154 return REG_VALID;
1155 }
1156
1157 static int
1158 ppu2spu_sniffer (const struct frame_unwind *self,
1159 struct frame_info *this_frame, void **this_prologue_cache)
1160 {
1161 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1162 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1163 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1164 struct ppu2spu_data data;
1165 struct frame_info *fi;
1166 CORE_ADDR base, func, backchain, spe_context;
1167 gdb_byte buf[8];
1168 int n = 0;
1169
1170 /* Count the number of SPU contexts already in the frame chain. */
1171 for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
1172 if (get_frame_type (fi) == ARCH_FRAME
1173 && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
1174 n++;
1175
1176 base = get_frame_sp (this_frame);
1177 func = get_frame_pc (this_frame);
1178 if (target_read_memory (base, buf, tdep->wordsize))
1179 return 0;
1180 backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
1181
1182 spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
1183 n, &data.id, &data.npc);
1184 if (spe_context && base <= spe_context && spe_context < backchain)
1185 {
1186 char annex[32];
1187
1188 /* Find gdbarch for SPU. */
1189 struct gdbarch_info info;
1190 gdbarch_info_init (&info);
1191 info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
1192 info.byte_order = BFD_ENDIAN_BIG;
1193 info.osabi = GDB_OSABI_LINUX;
1194 info.tdep_info = (void *) &data.id;
1195 data.gdbarch = gdbarch_find_by_info (info);
1196 if (!data.gdbarch)
1197 return 0;
1198
1199 xsnprintf (annex, sizeof annex, "%d/regs", data.id);
1200 if (target_read (&current_target, TARGET_OBJECT_SPU, annex,
1201 data.gprs, 0, sizeof data.gprs)
1202 == sizeof data.gprs)
1203 {
1204 struct ppu2spu_cache *cache
1205 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
1206
1207 struct address_space *aspace = get_frame_address_space (this_frame);
1208 struct regcache *regcache = regcache_xmalloc (data.gdbarch, aspace);
1209 struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
1210 regcache_save (regcache, ppu2spu_unwind_register, &data);
1211 discard_cleanups (cleanups);
1212
1213 cache->frame_id = frame_id_build (base, func);
1214 cache->regcache = regcache;
1215 *this_prologue_cache = cache;
1216 return 1;
1217 }
1218 }
1219
1220 return 0;
1221 }
1222
1223 static void
1224 ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
1225 {
1226 struct ppu2spu_cache *cache = this_cache;
1227 regcache_xfree (cache->regcache);
1228 }
1229
1230 static const struct frame_unwind ppu2spu_unwind = {
1231 ARCH_FRAME,
1232 default_frame_unwind_stop_reason,
1233 ppu2spu_this_id,
1234 ppu2spu_prev_register,
1235 NULL,
1236 ppu2spu_sniffer,
1237 ppu2spu_dealloc_cache,
1238 ppu2spu_prev_arch,
1239 };
1240
1241
1242 static void
1243 ppc_linux_init_abi (struct gdbarch_info info,
1244 struct gdbarch *gdbarch)
1245 {
1246 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1247 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
1248 static const char *const stap_integer_prefixes[] = { "i", NULL };
1249 static const char *const stap_register_indirection_prefixes[] = { "(",
1250 NULL };
1251 static const char *const stap_register_indirection_suffixes[] = { ")",
1252 NULL };
1253
1254 linux_init_abi (info, gdbarch);
1255
1256 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1257 128-bit, they are IBM long double, not IEEE quad long double as
1258 in the System V ABI PowerPC Processor Supplement. We can safely
1259 let them default to 128-bit, since the debug info will give the
1260 size of type actually used in each case. */
1261 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
1262 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
1263
1264 /* Handle inferior calls during interrupted system calls. */
1265 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
1266
1267 /* Get the syscall number from the arch's register. */
1268 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
1269
1270 /* SystemTap functions. */
1271 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
1272 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
1273 stap_register_indirection_prefixes);
1274 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
1275 stap_register_indirection_suffixes);
1276 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
1277 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
1278 set_gdbarch_stap_parse_special_token (gdbarch,
1279 ppc_stap_parse_special_token);
1280
1281 if (tdep->wordsize == 4)
1282 {
1283 /* Until November 2001, gcc did not comply with the 32 bit SysV
1284 R4 ABI requirement that structures less than or equal to 8
1285 bytes should be returned in registers. Instead GCC was using
1286 the AIX/PowerOpen ABI - everything returned in memory
1287 (well ignoring vectors that is). When this was corrected, it
1288 wasn't fixed for GNU/Linux native platform. Use the
1289 PowerOpen struct convention. */
1290 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
1291
1292 set_gdbarch_memory_remove_breakpoint (gdbarch,
1293 ppc_linux_memory_remove_breakpoint);
1294
1295 /* Shared library handling. */
1296 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
1297 set_solib_svr4_fetch_link_map_offsets
1298 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1299
1300 /* Setting the correct XML syscall filename. */
1301 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC);
1302
1303 /* Trampolines. */
1304 tramp_frame_prepend_unwinder (gdbarch,
1305 &ppc32_linux_sigaction_tramp_frame);
1306 tramp_frame_prepend_unwinder (gdbarch,
1307 &ppc32_linux_sighandler_tramp_frame);
1308
1309 /* BFD target for core files. */
1310 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1311 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
1312 else
1313 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
1314
1315 /* Supported register sections. */
1316 if (tdesc_find_feature (info.target_desc,
1317 "org.gnu.gdb.power.vsx"))
1318 set_gdbarch_core_regset_sections (gdbarch,
1319 ppc_linux_vsx_regset_sections);
1320 else if (tdesc_find_feature (info.target_desc,
1321 "org.gnu.gdb.power.altivec"))
1322 set_gdbarch_core_regset_sections (gdbarch,
1323 ppc_linux_vmx_regset_sections);
1324 else
1325 set_gdbarch_core_regset_sections (gdbarch,
1326 ppc_linux_fp_regset_sections);
1327
1328 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
1329 {
1330 powerpc_so_ops = svr4_so_ops;
1331 /* Override dynamic resolve function. */
1332 powerpc_so_ops.in_dynsym_resolve_code =
1333 powerpc_linux_in_dynsym_resolve_code;
1334 }
1335 set_solib_ops (gdbarch, &powerpc_so_ops);
1336
1337 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1338 }
1339
1340 if (tdep->wordsize == 8)
1341 {
1342 if (tdep->elf_abi == POWERPC_ELF_V1)
1343 {
1344 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1345 function descriptors). */
1346 set_gdbarch_convert_from_func_ptr_addr
1347 (gdbarch, ppc64_convert_from_func_ptr_addr);
1348
1349 set_gdbarch_elf_make_msymbol_special
1350 (gdbarch, ppc64_elf_make_msymbol_special);
1351 }
1352
1353 /* Shared library handling. */
1354 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
1355 set_solib_svr4_fetch_link_map_offsets
1356 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1357
1358 /* Setting the correct XML syscall filename. */
1359 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64);
1360
1361 /* Trampolines. */
1362 tramp_frame_prepend_unwinder (gdbarch,
1363 &ppc64_linux_sigaction_tramp_frame);
1364 tramp_frame_prepend_unwinder (gdbarch,
1365 &ppc64_linux_sighandler_tramp_frame);
1366
1367 /* BFD target for core files. */
1368 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1369 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
1370 else
1371 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
1372
1373 /* Supported register sections. */
1374 if (tdesc_find_feature (info.target_desc,
1375 "org.gnu.gdb.power.vsx"))
1376 set_gdbarch_core_regset_sections (gdbarch,
1377 ppc64_linux_vsx_regset_sections);
1378 else if (tdesc_find_feature (info.target_desc,
1379 "org.gnu.gdb.power.altivec"))
1380 set_gdbarch_core_regset_sections (gdbarch,
1381 ppc64_linux_vmx_regset_sections);
1382 else
1383 set_gdbarch_core_regset_sections (gdbarch,
1384 ppc64_linux_fp_regset_sections);
1385 }
1386
1387 /* PPC32 uses a different prpsinfo32 compared to most other Linux
1388 archs. */
1389 if (tdep->wordsize == 4)
1390 set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch,
1391 elfcore_write_ppc_linux_prpsinfo32);
1392
1393 set_gdbarch_regset_from_core_section (gdbarch,
1394 ppc_linux_regset_from_core_section);
1395 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
1396
1397 /* Enable TLS support. */
1398 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1399 svr4_fetch_objfile_link_map);
1400
1401 if (tdesc_data)
1402 {
1403 const struct tdesc_feature *feature;
1404
1405 /* If we have target-described registers, then we can safely
1406 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1407 (whether they are described or not). */
1408 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
1409 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
1410
1411 /* If they are present, then assign them to the reserved number. */
1412 feature = tdesc_find_feature (info.target_desc,
1413 "org.gnu.gdb.power.linux");
1414 if (feature != NULL)
1415 {
1416 tdesc_numbered_register (feature, tdesc_data,
1417 PPC_ORIG_R3_REGNUM, "orig_r3");
1418 tdesc_numbered_register (feature, tdesc_data,
1419 PPC_TRAP_REGNUM, "trap");
1420 }
1421 }
1422
1423 /* Enable Cell/B.E. if supported by the target. */
1424 if (tdesc_compatible_p (info.target_desc,
1425 bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
1426 {
1427 /* Cell/B.E. multi-architecture support. */
1428 set_spu_solib_ops (gdbarch);
1429
1430 /* Cell/B.E. cross-architecture unwinder support. */
1431 frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
1432
1433 /* The default displaced_step_at_entry_point doesn't work for
1434 SPU stand-alone executables. */
1435 set_gdbarch_displaced_step_location (gdbarch,
1436 ppc_linux_displaced_step_location);
1437 }
1438
1439 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
1440 }
1441
1442 /* Provide a prototype to silence -Wmissing-prototypes. */
1443 extern initialize_file_ftype _initialize_ppc_linux_tdep;
1444
1445 void
1446 _initialize_ppc_linux_tdep (void)
1447 {
1448 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1449 64-bit PowerPC, and the older rs6k. */
1450 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
1451 ppc_linux_init_abi);
1452 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
1453 ppc_linux_init_abi);
1454 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
1455 ppc_linux_init_abi);
1456
1457 /* Attach to inferior_created observer. */
1458 observer_attach_inferior_created (ppc_linux_inferior_created);
1459
1460 /* Attach to observers to track __spe_current_active_context. */
1461 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created);
1462 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded);
1463 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded);
1464
1465 /* Initialize the Linux target descriptions. */
1466 initialize_tdesc_powerpc_32l ();
1467 initialize_tdesc_powerpc_altivec32l ();
1468 initialize_tdesc_powerpc_cell32l ();
1469 initialize_tdesc_powerpc_vsx32l ();
1470 initialize_tdesc_powerpc_isa205_32l ();
1471 initialize_tdesc_powerpc_isa205_altivec32l ();
1472 initialize_tdesc_powerpc_isa205_vsx32l ();
1473 initialize_tdesc_powerpc_64l ();
1474 initialize_tdesc_powerpc_altivec64l ();
1475 initialize_tdesc_powerpc_cell64l ();
1476 initialize_tdesc_powerpc_vsx64l ();
1477 initialize_tdesc_powerpc_isa205_64l ();
1478 initialize_tdesc_powerpc_isa205_altivec64l ();
1479 initialize_tdesc_powerpc_isa205_vsx64l ();
1480 initialize_tdesc_powerpc_e500l ();
1481 }