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