* elfread.c (elf_symtab_read): Do not use udata.p here to find
[deliverable/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 #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 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 != NULL
345 && (strcmp (SYMBOL_LINKAGE_NAME (sym), "__glink") == 0
346 || strcmp (SYMBOL_LINKAGE_NAME (sym), "__glink_PLTresolve") == 0))
347 return 1;
348
349 return 0;
350 }
351
352 /* Follow PLT stub to actual routine. */
353
354 static CORE_ADDR
355 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
356 {
357 int insnbuf[POWERPC32_PLT_STUB_LEN];
358 struct gdbarch *gdbarch = get_frame_arch (frame);
359 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
360 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
361 CORE_ADDR target = 0;
362
363 if (ppc_insns_match_pattern (pc, powerpc32_plt_stub, insnbuf))
364 {
365 /* Insn pattern is
366 lis r11, xxxx
367 lwz r11, xxxx(r11)
368 Branch target is in r11. */
369
370 target = (ppc_insn_d_field (insnbuf[0]) << 16)
371 | ppc_insn_d_field (insnbuf[1]);
372 target = read_memory_unsigned_integer (target, 4, byte_order);
373 }
374
375 if (ppc_insns_match_pattern (pc, powerpc32_plt_stub_so, insnbuf))
376 {
377 /* Insn pattern is
378 lwz r11, xxxx(r30)
379 Branch target is in r11. */
380
381 target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30)
382 + ppc_insn_d_field (insnbuf[0]);
383 target = read_memory_unsigned_integer (target, 4, byte_order);
384 }
385
386 return target;
387 }
388
389 /* Wrappers to handle Linux-only registers. */
390
391 static void
392 ppc_linux_supply_gregset (const struct regset *regset,
393 struct regcache *regcache,
394 int regnum, const void *gregs, size_t len)
395 {
396 const struct ppc_reg_offsets *offsets = regset->descr;
397
398 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
399
400 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
401 {
402 /* "orig_r3" is stored 2 slots after "pc". */
403 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
404 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
405 offsets->pc_offset + 2 * offsets->gpr_size,
406 offsets->gpr_size);
407
408 /* "trap" is stored 8 slots after "pc". */
409 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
410 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, gregs,
411 offsets->pc_offset + 8 * offsets->gpr_size,
412 offsets->gpr_size);
413 }
414 }
415
416 static void
417 ppc_linux_collect_gregset (const struct regset *regset,
418 const struct regcache *regcache,
419 int regnum, void *gregs, size_t len)
420 {
421 const struct ppc_reg_offsets *offsets = regset->descr;
422
423 /* Clear areas in the linux gregset not written elsewhere. */
424 if (regnum == -1)
425 memset (gregs, 0, len);
426
427 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
428
429 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
430 {
431 /* "orig_r3" is stored 2 slots after "pc". */
432 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
433 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
434 offsets->pc_offset + 2 * offsets->gpr_size,
435 offsets->gpr_size);
436
437 /* "trap" is stored 8 slots after "pc". */
438 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
439 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, gregs,
440 offsets->pc_offset + 8 * offsets->gpr_size,
441 offsets->gpr_size);
442 }
443 }
444
445 /* Regset descriptions. */
446 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
447 {
448 /* General-purpose registers. */
449 /* .r0_offset = */ 0,
450 /* .gpr_size = */ 4,
451 /* .xr_size = */ 4,
452 /* .pc_offset = */ 128,
453 /* .ps_offset = */ 132,
454 /* .cr_offset = */ 152,
455 /* .lr_offset = */ 144,
456 /* .ctr_offset = */ 140,
457 /* .xer_offset = */ 148,
458 /* .mq_offset = */ 156,
459
460 /* Floating-point registers. */
461 /* .f0_offset = */ 0,
462 /* .fpscr_offset = */ 256,
463 /* .fpscr_size = */ 8,
464
465 /* AltiVec registers. */
466 /* .vr0_offset = */ 0,
467 /* .vscr_offset = */ 512 + 12,
468 /* .vrsave_offset = */ 528
469 };
470
471 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
472 {
473 /* General-purpose registers. */
474 /* .r0_offset = */ 0,
475 /* .gpr_size = */ 8,
476 /* .xr_size = */ 8,
477 /* .pc_offset = */ 256,
478 /* .ps_offset = */ 264,
479 /* .cr_offset = */ 304,
480 /* .lr_offset = */ 288,
481 /* .ctr_offset = */ 280,
482 /* .xer_offset = */ 296,
483 /* .mq_offset = */ 312,
484
485 /* Floating-point registers. */
486 /* .f0_offset = */ 0,
487 /* .fpscr_offset = */ 256,
488 /* .fpscr_size = */ 8,
489
490 /* AltiVec registers. */
491 /* .vr0_offset = */ 0,
492 /* .vscr_offset = */ 512 + 12,
493 /* .vrsave_offset = */ 528
494 };
495
496 static const struct regset ppc32_linux_gregset = {
497 &ppc32_linux_reg_offsets,
498 ppc_linux_supply_gregset,
499 ppc_linux_collect_gregset,
500 NULL
501 };
502
503 static const struct regset ppc64_linux_gregset = {
504 &ppc64_linux_reg_offsets,
505 ppc_linux_supply_gregset,
506 ppc_linux_collect_gregset,
507 NULL
508 };
509
510 static const struct regset ppc32_linux_fpregset = {
511 &ppc32_linux_reg_offsets,
512 ppc_supply_fpregset,
513 ppc_collect_fpregset,
514 NULL
515 };
516
517 static const struct regset ppc32_linux_vrregset = {
518 &ppc32_linux_reg_offsets,
519 ppc_supply_vrregset,
520 ppc_collect_vrregset,
521 NULL
522 };
523
524 static const struct regset ppc32_linux_vsxregset = {
525 &ppc32_linux_reg_offsets,
526 ppc_supply_vsxregset,
527 ppc_collect_vsxregset,
528 NULL
529 };
530
531 const struct regset *
532 ppc_linux_gregset (int wordsize)
533 {
534 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
535 }
536
537 const struct regset *
538 ppc_linux_fpregset (void)
539 {
540 return &ppc32_linux_fpregset;
541 }
542
543 static const struct regset *
544 ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
545 const char *sect_name, size_t sect_size)
546 {
547 struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
548 if (strcmp (sect_name, ".reg") == 0)
549 {
550 if (tdep->wordsize == 4)
551 return &ppc32_linux_gregset;
552 else
553 return &ppc64_linux_gregset;
554 }
555 if (strcmp (sect_name, ".reg2") == 0)
556 return &ppc32_linux_fpregset;
557 if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
558 return &ppc32_linux_vrregset;
559 if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
560 return &ppc32_linux_vsxregset;
561 return NULL;
562 }
563
564 static void
565 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
566 struct trad_frame_cache *this_cache,
567 CORE_ADDR func, LONGEST offset,
568 int bias)
569 {
570 CORE_ADDR base;
571 CORE_ADDR regs;
572 CORE_ADDR gpregs;
573 CORE_ADDR fpregs;
574 int i;
575 struct gdbarch *gdbarch = get_frame_arch (this_frame);
576 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
577 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
578
579 base = get_frame_register_unsigned (this_frame,
580 gdbarch_sp_regnum (gdbarch));
581 if (bias > 0 && get_frame_pc (this_frame) != func)
582 /* See below, some signal trampolines increment the stack as their
583 first instruction, need to compensate for that. */
584 base -= bias;
585
586 /* Find the address of the register buffer pointer. */
587 regs = base + offset;
588 /* Use that to find the address of the corresponding register
589 buffers. */
590 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
591 fpregs = gpregs + 48 * tdep->wordsize;
592
593 /* General purpose. */
594 for (i = 0; i < 32; i++)
595 {
596 int regnum = i + tdep->ppc_gp0_regnum;
597 trad_frame_set_reg_addr (this_cache,
598 regnum, gpregs + i * tdep->wordsize);
599 }
600 trad_frame_set_reg_addr (this_cache,
601 gdbarch_pc_regnum (gdbarch),
602 gpregs + 32 * tdep->wordsize);
603 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
604 gpregs + 35 * tdep->wordsize);
605 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
606 gpregs + 36 * tdep->wordsize);
607 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
608 gpregs + 37 * tdep->wordsize);
609 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
610 gpregs + 38 * tdep->wordsize);
611
612 if (ppc_linux_trap_reg_p (gdbarch))
613 {
614 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
615 gpregs + 34 * tdep->wordsize);
616 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
617 gpregs + 40 * tdep->wordsize);
618 }
619
620 if (ppc_floating_point_unit_p (gdbarch))
621 {
622 /* Floating point registers. */
623 for (i = 0; i < 32; i++)
624 {
625 int regnum = i + gdbarch_fp0_regnum (gdbarch);
626 trad_frame_set_reg_addr (this_cache, regnum,
627 fpregs + i * tdep->wordsize);
628 }
629 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
630 fpregs + 32 * tdep->wordsize);
631 }
632 trad_frame_set_id (this_cache, frame_id_build (base, func));
633 }
634
635 static void
636 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
637 struct frame_info *this_frame,
638 struct trad_frame_cache *this_cache,
639 CORE_ADDR func)
640 {
641 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
642 0xd0 /* Offset to ucontext_t. */
643 + 0x30 /* Offset to .reg. */,
644 0);
645 }
646
647 static void
648 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
649 struct frame_info *this_frame,
650 struct trad_frame_cache *this_cache,
651 CORE_ADDR func)
652 {
653 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
654 0x80 /* Offset to ucontext_t. */
655 + 0xe0 /* Offset to .reg. */,
656 128);
657 }
658
659 static void
660 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
661 struct frame_info *this_frame,
662 struct trad_frame_cache *this_cache,
663 CORE_ADDR func)
664 {
665 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
666 0x40 /* Offset to ucontext_t. */
667 + 0x1c /* Offset to .reg. */,
668 0);
669 }
670
671 static void
672 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
673 struct frame_info *this_frame,
674 struct trad_frame_cache *this_cache,
675 CORE_ADDR func)
676 {
677 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
678 0x80 /* Offset to struct sigcontext. */
679 + 0x38 /* Offset to .reg. */,
680 128);
681 }
682
683 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
684 SIGTRAMP_FRAME,
685 4,
686 {
687 { 0x380000ac, -1 }, /* li r0, 172 */
688 { 0x44000002, -1 }, /* sc */
689 { TRAMP_SENTINEL_INSN },
690 },
691 ppc32_linux_sigaction_cache_init
692 };
693 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
694 SIGTRAMP_FRAME,
695 4,
696 {
697 { 0x38210080, -1 }, /* addi r1,r1,128 */
698 { 0x380000ac, -1 }, /* li r0, 172 */
699 { 0x44000002, -1 }, /* sc */
700 { TRAMP_SENTINEL_INSN },
701 },
702 ppc64_linux_sigaction_cache_init
703 };
704 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
705 SIGTRAMP_FRAME,
706 4,
707 {
708 { 0x38000077, -1 }, /* li r0,119 */
709 { 0x44000002, -1 }, /* sc */
710 { TRAMP_SENTINEL_INSN },
711 },
712 ppc32_linux_sighandler_cache_init
713 };
714 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
715 SIGTRAMP_FRAME,
716 4,
717 {
718 { 0x38210080, -1 }, /* addi r1,r1,128 */
719 { 0x38000077, -1 }, /* li r0,119 */
720 { 0x44000002, -1 }, /* sc */
721 { TRAMP_SENTINEL_INSN },
722 },
723 ppc64_linux_sighandler_cache_init
724 };
725
726
727 /* Address to use for displaced stepping. When debugging a stand-alone
728 SPU executable, entry_point_address () will point to an SPU local-store
729 address and is thus not usable as displaced stepping location. We use
730 the auxiliary vector to determine the PowerPC-side entry point address
731 instead. */
732
733 static CORE_ADDR ppc_linux_entry_point_addr = 0;
734
735 static void
736 ppc_linux_inferior_created (struct target_ops *target, int from_tty)
737 {
738 ppc_linux_entry_point_addr = 0;
739 }
740
741 static CORE_ADDR
742 ppc_linux_displaced_step_location (struct gdbarch *gdbarch)
743 {
744 if (ppc_linux_entry_point_addr == 0)
745 {
746 CORE_ADDR addr;
747
748 /* Determine entry point from target auxiliary vector. */
749 if (target_auxv_search (&current_target, AT_ENTRY, &addr) <= 0)
750 error (_("Cannot find AT_ENTRY auxiliary vector entry."));
751
752 /* Make certain that the address points at real code, and not a
753 function descriptor. */
754 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
755 &current_target);
756
757 /* Inferior calls also use the entry point as a breakpoint location.
758 We don't want displaced stepping to interfere with those
759 breakpoints, so leave space. */
760 ppc_linux_entry_point_addr = addr + 2 * PPC_INSN_SIZE;
761 }
762
763 return ppc_linux_entry_point_addr;
764 }
765
766
767 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
768 int
769 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
770 {
771 /* If we do not have a target description with registers, then
772 the special registers will not be included in the register set. */
773 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
774 return 0;
775
776 /* If we do, then it is safe to check the size. */
777 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
778 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
779 }
780
781 /* Return the current system call's number present in the
782 r0 register. When the function fails, it returns -1. */
783 static LONGEST
784 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
785 ptid_t ptid)
786 {
787 struct regcache *regcache = get_thread_regcache (ptid);
788 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
789 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
790 struct cleanup *cleanbuf;
791 /* The content of a register */
792 gdb_byte *buf;
793 /* The result */
794 LONGEST ret;
795
796 /* Make sure we're in a 32- or 64-bit machine */
797 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
798
799 buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte));
800
801 cleanbuf = make_cleanup (xfree, buf);
802
803 /* Getting the system call number from the register.
804 When dealing with PowerPC architecture, this information
805 is stored at 0th register. */
806 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf);
807
808 ret = extract_signed_integer (buf, tdep->wordsize, byte_order);
809 do_cleanups (cleanbuf);
810
811 return ret;
812 }
813
814 static void
815 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
816 {
817 struct gdbarch *gdbarch = get_regcache_arch (regcache);
818
819 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
820
821 /* Set special TRAP register to -1 to prevent the kernel from
822 messing with the PC we just installed, if we happen to be
823 within an interrupted system call that the kernel wants to
824 restart.
825
826 Note that after we return from the dummy call, the TRAP and
827 ORIG_R3 registers will be automatically restored, and the
828 kernel continues to restart the system call at this point. */
829 if (ppc_linux_trap_reg_p (gdbarch))
830 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
831 }
832
833 static int
834 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
835 {
836 return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
837 }
838
839 static const struct target_desc *
840 ppc_linux_core_read_description (struct gdbarch *gdbarch,
841 struct target_ops *target,
842 bfd *abfd)
843 {
844 asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
845 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
846 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
847 asection *section = bfd_get_section_by_name (abfd, ".reg");
848 if (! section)
849 return NULL;
850
851 switch (bfd_section_size (abfd, section))
852 {
853 case 48 * 4:
854 if (cell)
855 return tdesc_powerpc_cell32l;
856 else if (vsx)
857 return tdesc_powerpc_vsx32l;
858 else if (altivec)
859 return tdesc_powerpc_altivec32l;
860 else
861 return tdesc_powerpc_32l;
862
863 case 48 * 8:
864 if (cell)
865 return tdesc_powerpc_cell64l;
866 else if (vsx)
867 return tdesc_powerpc_vsx64l;
868 else if (altivec)
869 return tdesc_powerpc_altivec64l;
870 else
871 return tdesc_powerpc_64l;
872
873 default:
874 return NULL;
875 }
876 }
877
878 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
879 gdbarch.h. */
880
881 static int
882 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
883 {
884 return (*s == 'i' /* Literal number. */
885 || (isdigit (*s) && s[1] == '('
886 && isdigit (s[2])) /* Displacement. */
887 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
888 || isdigit (*s)); /* Register value. */
889 }
890
891 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
892 gdbarch.h. */
893
894 static int
895 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
896 struct stap_parse_info *p)
897 {
898 if (isdigit (*p->arg))
899 {
900 /* This temporary pointer is needed because we have to do a lookahead.
901 We could be dealing with a register displacement, and in such case
902 we would not need to do anything. */
903 const char *s = p->arg;
904 char *regname;
905 int len;
906 struct stoken str;
907
908 while (isdigit (*s))
909 ++s;
910
911 if (*s == '(')
912 {
913 /* It is a register displacement indeed. Returning 0 means we are
914 deferring the treatment of this case to the generic parser. */
915 return 0;
916 }
917
918 len = s - p->arg;
919 regname = alloca (len + 2);
920 regname[0] = 'r';
921
922 strncpy (regname + 1, p->arg, len);
923 ++len;
924 regname[len] = '\0';
925
926 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
927 error (_("Invalid register name `%s' on expression `%s'."),
928 regname, p->saved_arg);
929
930 write_exp_elt_opcode (OP_REGISTER);
931 str.ptr = regname;
932 str.length = len;
933 write_exp_string (str);
934 write_exp_elt_opcode (OP_REGISTER);
935
936 p->arg = s;
937 }
938 else
939 {
940 /* All the other tokens should be handled correctly by the generic
941 parser. */
942 return 0;
943 }
944
945 return 1;
946 }
947
948 /* Cell/B.E. active SPE context tracking support. */
949
950 static struct objfile *spe_context_objfile = NULL;
951 static CORE_ADDR spe_context_lm_addr = 0;
952 static CORE_ADDR spe_context_offset = 0;
953
954 static ptid_t spe_context_cache_ptid;
955 static CORE_ADDR spe_context_cache_address;
956
957 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
958 to track whether we've loaded a version of libspe2 (as static or dynamic
959 library) that provides the __spe_current_active_context variable. */
960 static void
961 ppc_linux_spe_context_lookup (struct objfile *objfile)
962 {
963 struct minimal_symbol *sym;
964
965 if (!objfile)
966 {
967 spe_context_objfile = NULL;
968 spe_context_lm_addr = 0;
969 spe_context_offset = 0;
970 spe_context_cache_ptid = minus_one_ptid;
971 spe_context_cache_address = 0;
972 return;
973 }
974
975 sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
976 if (sym)
977 {
978 spe_context_objfile = objfile;
979 spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
980 spe_context_offset = SYMBOL_VALUE_ADDRESS (sym);
981 spe_context_cache_ptid = minus_one_ptid;
982 spe_context_cache_address = 0;
983 return;
984 }
985 }
986
987 static void
988 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
989 {
990 struct objfile *objfile;
991
992 ppc_linux_spe_context_lookup (NULL);
993 ALL_OBJFILES (objfile)
994 ppc_linux_spe_context_lookup (objfile);
995 }
996
997 static void
998 ppc_linux_spe_context_solib_loaded (struct so_list *so)
999 {
1000 if (strstr (so->so_original_name, "/libspe") != NULL)
1001 {
1002 solib_read_symbols (so, 0);
1003 ppc_linux_spe_context_lookup (so->objfile);
1004 }
1005 }
1006
1007 static void
1008 ppc_linux_spe_context_solib_unloaded (struct so_list *so)
1009 {
1010 if (so->objfile == spe_context_objfile)
1011 ppc_linux_spe_context_lookup (NULL);
1012 }
1013
1014 /* Retrieve contents of the N'th element in the current thread's
1015 linked SPE context list into ID and NPC. Return the address of
1016 said context element, or 0 if not found. */
1017 static CORE_ADDR
1018 ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
1019 int n, int *id, unsigned int *npc)
1020 {
1021 CORE_ADDR spe_context = 0;
1022 gdb_byte buf[16];
1023 int i;
1024
1025 /* Quick exit if we have not found __spe_current_active_context. */
1026 if (!spe_context_objfile)
1027 return 0;
1028
1029 /* Look up cached address of thread-local variable. */
1030 if (!ptid_equal (spe_context_cache_ptid, inferior_ptid))
1031 {
1032 struct target_ops *target = &current_target;
1033 volatile struct gdb_exception ex;
1034
1035 while (target && !target->to_get_thread_local_address)
1036 target = find_target_beneath (target);
1037 if (!target)
1038 return 0;
1039
1040 TRY_CATCH (ex, RETURN_MASK_ERROR)
1041 {
1042 /* We do not call target_translate_tls_address here, because
1043 svr4_fetch_objfile_link_map may invalidate the frame chain,
1044 which must not do while inside a frame sniffer.
1045
1046 Instead, we have cached the lm_addr value, and use that to
1047 directly call the target's to_get_thread_local_address. */
1048 spe_context_cache_address
1049 = target->to_get_thread_local_address (target, inferior_ptid,
1050 spe_context_lm_addr,
1051 spe_context_offset);
1052 spe_context_cache_ptid = inferior_ptid;
1053 }
1054
1055 if (ex.reason < 0)
1056 return 0;
1057 }
1058
1059 /* Read variable value. */
1060 if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
1061 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1062
1063 /* Cyle through to N'th linked list element. */
1064 for (i = 0; i < n && spe_context; i++)
1065 if (target_read_memory (spe_context + align_up (12, wordsize),
1066 buf, wordsize) == 0)
1067 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1068 else
1069 spe_context = 0;
1070
1071 /* Read current context. */
1072 if (spe_context
1073 && target_read_memory (spe_context, buf, 12) != 0)
1074 spe_context = 0;
1075
1076 /* Extract data elements. */
1077 if (spe_context)
1078 {
1079 if (id)
1080 *id = extract_signed_integer (buf, 4, byte_order);
1081 if (npc)
1082 *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
1083 }
1084
1085 return spe_context;
1086 }
1087
1088
1089 /* Cell/B.E. cross-architecture unwinder support. */
1090
1091 struct ppu2spu_cache
1092 {
1093 struct frame_id frame_id;
1094 struct regcache *regcache;
1095 };
1096
1097 static struct gdbarch *
1098 ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
1099 {
1100 struct ppu2spu_cache *cache = *this_cache;
1101 return get_regcache_arch (cache->regcache);
1102 }
1103
1104 static void
1105 ppu2spu_this_id (struct frame_info *this_frame,
1106 void **this_cache, struct frame_id *this_id)
1107 {
1108 struct ppu2spu_cache *cache = *this_cache;
1109 *this_id = cache->frame_id;
1110 }
1111
1112 static struct value *
1113 ppu2spu_prev_register (struct frame_info *this_frame,
1114 void **this_cache, int regnum)
1115 {
1116 struct ppu2spu_cache *cache = *this_cache;
1117 struct gdbarch *gdbarch = get_regcache_arch (cache->regcache);
1118 gdb_byte *buf;
1119
1120 buf = alloca (register_size (gdbarch, regnum));
1121
1122 if (regnum < gdbarch_num_regs (gdbarch))
1123 regcache_raw_read (cache->regcache, regnum, buf);
1124 else
1125 gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf);
1126
1127 return frame_unwind_got_bytes (this_frame, regnum, buf);
1128 }
1129
1130 struct ppu2spu_data
1131 {
1132 struct gdbarch *gdbarch;
1133 int id;
1134 unsigned int npc;
1135 gdb_byte gprs[128*16];
1136 };
1137
1138 static int
1139 ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf)
1140 {
1141 struct ppu2spu_data *data = src;
1142 enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
1143
1144 if (regnum >= 0 && regnum < SPU_NUM_GPRS)
1145 memcpy (buf, data->gprs + 16*regnum, 16);
1146 else if (regnum == SPU_ID_REGNUM)
1147 store_unsigned_integer (buf, 4, byte_order, data->id);
1148 else if (regnum == SPU_PC_REGNUM)
1149 store_unsigned_integer (buf, 4, byte_order, data->npc);
1150 else
1151 return REG_UNAVAILABLE;
1152
1153 return REG_VALID;
1154 }
1155
1156 static int
1157 ppu2spu_sniffer (const struct frame_unwind *self,
1158 struct frame_info *this_frame, void **this_prologue_cache)
1159 {
1160 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1161 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1162 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1163 struct ppu2spu_data data;
1164 struct frame_info *fi;
1165 CORE_ADDR base, func, backchain, spe_context;
1166 gdb_byte buf[8];
1167 int n = 0;
1168
1169 /* Count the number of SPU contexts already in the frame chain. */
1170 for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
1171 if (get_frame_type (fi) == ARCH_FRAME
1172 && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
1173 n++;
1174
1175 base = get_frame_sp (this_frame);
1176 func = get_frame_pc (this_frame);
1177 if (target_read_memory (base, buf, tdep->wordsize))
1178 return 0;
1179 backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
1180
1181 spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
1182 n, &data.id, &data.npc);
1183 if (spe_context && base <= spe_context && spe_context < backchain)
1184 {
1185 char annex[32];
1186
1187 /* Find gdbarch for SPU. */
1188 struct gdbarch_info info;
1189 gdbarch_info_init (&info);
1190 info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
1191 info.byte_order = BFD_ENDIAN_BIG;
1192 info.osabi = GDB_OSABI_LINUX;
1193 info.tdep_info = (void *) &data.id;
1194 data.gdbarch = gdbarch_find_by_info (info);
1195 if (!data.gdbarch)
1196 return 0;
1197
1198 xsnprintf (annex, sizeof annex, "%d/regs", data.id);
1199 if (target_read (&current_target, TARGET_OBJECT_SPU, annex,
1200 data.gprs, 0, sizeof data.gprs)
1201 == sizeof data.gprs)
1202 {
1203 struct ppu2spu_cache *cache
1204 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
1205
1206 struct address_space *aspace = get_frame_address_space (this_frame);
1207 struct regcache *regcache = regcache_xmalloc (data.gdbarch, aspace);
1208 struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
1209 regcache_save (regcache, ppu2spu_unwind_register, &data);
1210 discard_cleanups (cleanups);
1211
1212 cache->frame_id = frame_id_build (base, func);
1213 cache->regcache = regcache;
1214 *this_prologue_cache = cache;
1215 return 1;
1216 }
1217 }
1218
1219 return 0;
1220 }
1221
1222 static void
1223 ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
1224 {
1225 struct ppu2spu_cache *cache = this_cache;
1226 regcache_xfree (cache->regcache);
1227 }
1228
1229 static const struct frame_unwind ppu2spu_unwind = {
1230 ARCH_FRAME,
1231 default_frame_unwind_stop_reason,
1232 ppu2spu_this_id,
1233 ppu2spu_prev_register,
1234 NULL,
1235 ppu2spu_sniffer,
1236 ppu2spu_dealloc_cache,
1237 ppu2spu_prev_arch,
1238 };
1239
1240
1241 static void
1242 ppc_linux_init_abi (struct gdbarch_info info,
1243 struct gdbarch *gdbarch)
1244 {
1245 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1246 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
1247
1248 linux_init_abi (info, gdbarch);
1249
1250 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1251 128-bit, they are IBM long double, not IEEE quad long double as
1252 in the System V ABI PowerPC Processor Supplement. We can safely
1253 let them default to 128-bit, since the debug info will give the
1254 size of type actually used in each case. */
1255 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
1256 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
1257
1258 /* Handle inferior calls during interrupted system calls. */
1259 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
1260
1261 /* Get the syscall number from the arch's register. */
1262 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
1263
1264 /* SystemTap functions. */
1265 set_gdbarch_stap_integer_prefix (gdbarch, "i");
1266 set_gdbarch_stap_register_indirection_prefix (gdbarch, "(");
1267 set_gdbarch_stap_register_indirection_suffix (gdbarch, ")");
1268 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
1269 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
1270 set_gdbarch_stap_parse_special_token (gdbarch,
1271 ppc_stap_parse_special_token);
1272
1273 if (tdep->wordsize == 4)
1274 {
1275 /* Until November 2001, gcc did not comply with the 32 bit SysV
1276 R4 ABI requirement that structures less than or equal to 8
1277 bytes should be returned in registers. Instead GCC was using
1278 the AIX/PowerOpen ABI - everything returned in memory
1279 (well ignoring vectors that is). When this was corrected, it
1280 wasn't fixed for GNU/Linux native platform. Use the
1281 PowerOpen struct convention. */
1282 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
1283
1284 set_gdbarch_memory_remove_breakpoint (gdbarch,
1285 ppc_linux_memory_remove_breakpoint);
1286
1287 /* Shared library handling. */
1288 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
1289 set_solib_svr4_fetch_link_map_offsets
1290 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1291
1292 /* Setting the correct XML syscall filename. */
1293 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC);
1294
1295 /* Trampolines. */
1296 tramp_frame_prepend_unwinder (gdbarch,
1297 &ppc32_linux_sigaction_tramp_frame);
1298 tramp_frame_prepend_unwinder (gdbarch,
1299 &ppc32_linux_sighandler_tramp_frame);
1300
1301 /* BFD target for core files. */
1302 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1303 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
1304 else
1305 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
1306
1307 /* Supported register sections. */
1308 if (tdesc_find_feature (info.target_desc,
1309 "org.gnu.gdb.power.vsx"))
1310 set_gdbarch_core_regset_sections (gdbarch,
1311 ppc_linux_vsx_regset_sections);
1312 else if (tdesc_find_feature (info.target_desc,
1313 "org.gnu.gdb.power.altivec"))
1314 set_gdbarch_core_regset_sections (gdbarch,
1315 ppc_linux_vmx_regset_sections);
1316 else
1317 set_gdbarch_core_regset_sections (gdbarch,
1318 ppc_linux_fp_regset_sections);
1319
1320 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
1321 {
1322 powerpc_so_ops = svr4_so_ops;
1323 /* Override dynamic resolve function. */
1324 powerpc_so_ops.in_dynsym_resolve_code =
1325 powerpc_linux_in_dynsym_resolve_code;
1326 }
1327 set_solib_ops (gdbarch, &powerpc_so_ops);
1328
1329 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1330 }
1331
1332 if (tdep->wordsize == 8)
1333 {
1334 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1335 function descriptors). */
1336 set_gdbarch_convert_from_func_ptr_addr
1337 (gdbarch, ppc64_convert_from_func_ptr_addr);
1338
1339 set_gdbarch_elf_make_msymbol_special (gdbarch,
1340 ppc64_elf_make_msymbol_special);
1341
1342 /* Shared library handling. */
1343 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
1344 set_solib_svr4_fetch_link_map_offsets
1345 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1346
1347 /* Setting the correct XML syscall filename. */
1348 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64);
1349
1350 /* Trampolines. */
1351 tramp_frame_prepend_unwinder (gdbarch,
1352 &ppc64_linux_sigaction_tramp_frame);
1353 tramp_frame_prepend_unwinder (gdbarch,
1354 &ppc64_linux_sighandler_tramp_frame);
1355
1356 /* BFD target for core files. */
1357 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1358 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
1359 else
1360 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
1361
1362 /* Supported register sections. */
1363 if (tdesc_find_feature (info.target_desc,
1364 "org.gnu.gdb.power.vsx"))
1365 set_gdbarch_core_regset_sections (gdbarch,
1366 ppc64_linux_vsx_regset_sections);
1367 else if (tdesc_find_feature (info.target_desc,
1368 "org.gnu.gdb.power.altivec"))
1369 set_gdbarch_core_regset_sections (gdbarch,
1370 ppc64_linux_vmx_regset_sections);
1371 else
1372 set_gdbarch_core_regset_sections (gdbarch,
1373 ppc64_linux_fp_regset_sections);
1374 }
1375
1376 /* PPC32 uses a different prpsinfo32 compared to most other Linux
1377 archs. */
1378 if (tdep->wordsize == 4)
1379 set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch,
1380 elfcore_write_ppc_linux_prpsinfo32);
1381
1382 set_gdbarch_regset_from_core_section (gdbarch,
1383 ppc_linux_regset_from_core_section);
1384 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
1385
1386 /* Enable TLS support. */
1387 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1388 svr4_fetch_objfile_link_map);
1389
1390 if (tdesc_data)
1391 {
1392 const struct tdesc_feature *feature;
1393
1394 /* If we have target-described registers, then we can safely
1395 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1396 (whether they are described or not). */
1397 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
1398 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
1399
1400 /* If they are present, then assign them to the reserved number. */
1401 feature = tdesc_find_feature (info.target_desc,
1402 "org.gnu.gdb.power.linux");
1403 if (feature != NULL)
1404 {
1405 tdesc_numbered_register (feature, tdesc_data,
1406 PPC_ORIG_R3_REGNUM, "orig_r3");
1407 tdesc_numbered_register (feature, tdesc_data,
1408 PPC_TRAP_REGNUM, "trap");
1409 }
1410 }
1411
1412 /* Enable Cell/B.E. if supported by the target. */
1413 if (tdesc_compatible_p (info.target_desc,
1414 bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
1415 {
1416 /* Cell/B.E. multi-architecture support. */
1417 set_spu_solib_ops (gdbarch);
1418
1419 /* Cell/B.E. cross-architecture unwinder support. */
1420 frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
1421
1422 /* The default displaced_step_at_entry_point doesn't work for
1423 SPU stand-alone executables. */
1424 set_gdbarch_displaced_step_location (gdbarch,
1425 ppc_linux_displaced_step_location);
1426 }
1427
1428 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
1429 }
1430
1431 /* Provide a prototype to silence -Wmissing-prototypes. */
1432 extern initialize_file_ftype _initialize_ppc_linux_tdep;
1433
1434 void
1435 _initialize_ppc_linux_tdep (void)
1436 {
1437 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1438 64-bit PowerPC, and the older rs6k. */
1439 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
1440 ppc_linux_init_abi);
1441 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
1442 ppc_linux_init_abi);
1443 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
1444 ppc_linux_init_abi);
1445
1446 /* Attach to inferior_created observer. */
1447 observer_attach_inferior_created (ppc_linux_inferior_created);
1448
1449 /* Attach to observers to track __spe_current_active_context. */
1450 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created);
1451 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded);
1452 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded);
1453
1454 /* Initialize the Linux target descriptions. */
1455 initialize_tdesc_powerpc_32l ();
1456 initialize_tdesc_powerpc_altivec32l ();
1457 initialize_tdesc_powerpc_cell32l ();
1458 initialize_tdesc_powerpc_vsx32l ();
1459 initialize_tdesc_powerpc_isa205_32l ();
1460 initialize_tdesc_powerpc_isa205_altivec32l ();
1461 initialize_tdesc_powerpc_isa205_vsx32l ();
1462 initialize_tdesc_powerpc_64l ();
1463 initialize_tdesc_powerpc_altivec64l ();
1464 initialize_tdesc_powerpc_cell64l ();
1465 initialize_tdesc_powerpc_vsx64l ();
1466 initialize_tdesc_powerpc_isa205_64l ();
1467 initialize_tdesc_powerpc_isa205_altivec64l ();
1468 initialize_tdesc_powerpc_isa205_vsx64l ();
1469 initialize_tdesc_powerpc_e500l ();
1470 }
This page took 0.062196 seconds and 5 git commands to generate.