const-fy regcache::m_aspace
[deliverable/binutils-gdb.git] / gdb / ppc-linux-tdep.c
1 /* Target-dependent code for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2017 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 "elf/ppc64.h"
48 #include "arch-utils.h"
49 #include "spu-tdep.h"
50 #include "xml-syscall.h"
51 #include "linux-tdep.h"
52 #include "linux-record.h"
53 #include "record-full.h"
54 #include "infrun.h"
55
56 #include "stap-probe.h"
57 #include "ax.h"
58 #include "ax-gdb.h"
59 #include "cli/cli-utils.h"
60 #include "parser-defs.h"
61 #include "user-regs.h"
62 #include <ctype.h>
63 #include "elf-bfd.h"
64
65 #include "features/rs6000/powerpc-32l.c"
66 #include "features/rs6000/powerpc-altivec32l.c"
67 #include "features/rs6000/powerpc-cell32l.c"
68 #include "features/rs6000/powerpc-vsx32l.c"
69 #include "features/rs6000/powerpc-isa205-32l.c"
70 #include "features/rs6000/powerpc-isa205-altivec32l.c"
71 #include "features/rs6000/powerpc-isa205-vsx32l.c"
72 #include "features/rs6000/powerpc-64l.c"
73 #include "features/rs6000/powerpc-altivec64l.c"
74 #include "features/rs6000/powerpc-cell64l.c"
75 #include "features/rs6000/powerpc-vsx64l.c"
76 #include "features/rs6000/powerpc-isa205-64l.c"
77 #include "features/rs6000/powerpc-isa205-altivec64l.c"
78 #include "features/rs6000/powerpc-isa205-vsx64l.c"
79 #include "features/rs6000/powerpc-e500l.c"
80
81 /* Shared library operations for PowerPC-Linux. */
82 static struct target_so_ops powerpc_so_ops;
83
84 /* The syscall's XML filename for PPC and PPC64. */
85 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
86 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
87
88 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
89 in much the same fashion as memory_remove_breakpoint in mem-break.c,
90 but is careful not to write back the previous contents if the code
91 in question has changed in between inserting the breakpoint and
92 removing it.
93
94 Here is the problem that we're trying to solve...
95
96 Once upon a time, before introducing this function to remove
97 breakpoints from the inferior, setting a breakpoint on a shared
98 library function prior to running the program would not work
99 properly. In order to understand the problem, it is first
100 necessary to understand a little bit about dynamic linking on
101 this platform.
102
103 A call to a shared library function is accomplished via a bl
104 (branch-and-link) instruction whose branch target is an entry
105 in the procedure linkage table (PLT). The PLT in the object
106 file is uninitialized. To gdb, prior to running the program, the
107 entries in the PLT are all zeros.
108
109 Once the program starts running, the shared libraries are loaded
110 and the procedure linkage table is initialized, but the entries in
111 the table are not (necessarily) resolved. Once a function is
112 actually called, the code in the PLT is hit and the function is
113 resolved. In order to better illustrate this, an example is in
114 order; the following example is from the gdb testsuite.
115
116 We start the program shmain.
117
118 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
119 [...]
120
121 We place two breakpoints, one on shr1 and the other on main.
122
123 (gdb) b shr1
124 Breakpoint 1 at 0x100409d4
125 (gdb) b main
126 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
127
128 Examine the instruction (and the immediatly following instruction)
129 upon which the breakpoint was placed. Note that the PLT entry
130 for shr1 contains zeros.
131
132 (gdb) x/2i 0x100409d4
133 0x100409d4 <shr1>: .long 0x0
134 0x100409d8 <shr1+4>: .long 0x0
135
136 Now run 'til main.
137
138 (gdb) r
139 Starting program: gdb.base/shmain
140 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
141
142 Breakpoint 2, main ()
143 at gdb.base/shmain.c:44
144 44 g = 1;
145
146 Examine the PLT again. Note that the loading of the shared
147 library has initialized the PLT to code which loads a constant
148 (which I think is an index into the GOT) into r11 and then
149 branchs a short distance to the code which actually does the
150 resolving.
151
152 (gdb) x/2i 0x100409d4
153 0x100409d4 <shr1>: li r11,4
154 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
155 (gdb) c
156 Continuing.
157
158 Breakpoint 1, shr1 (x=1)
159 at gdb.base/shr1.c:19
160 19 l = 1;
161
162 Now we've hit the breakpoint at shr1. (The breakpoint was
163 reset from the PLT entry to the actual shr1 function after the
164 shared library was loaded.) Note that the PLT entry has been
165 resolved to contain a branch that takes us directly to shr1.
166 (The real one, not the PLT entry.)
167
168 (gdb) x/2i 0x100409d4
169 0x100409d4 <shr1>: b 0xffaf76c <shr1>
170 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
171
172 The thing to note here is that the PLT entry for shr1 has been
173 changed twice.
174
175 Now the problem should be obvious. GDB places a breakpoint (a
176 trap instruction) on the zero value of the PLT entry for shr1.
177 Later on, after the shared library had been loaded and the PLT
178 initialized, GDB gets a signal indicating this fact and attempts
179 (as it always does when it stops) to remove all the breakpoints.
180
181 The breakpoint removal was causing the former contents (a zero
182 word) to be written back to the now initialized PLT entry thus
183 destroying a portion of the initialization that had occurred only a
184 short time ago. When execution continued, the zero word would be
185 executed as an instruction an illegal instruction trap was
186 generated instead. (0 is not a legal instruction.)
187
188 The fix for this problem was fairly straightforward. The function
189 memory_remove_breakpoint from mem-break.c was copied to this file,
190 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
191 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
192 function.
193
194 The differences between ppc_linux_memory_remove_breakpoint () and
195 memory_remove_breakpoint () are minor. All that the former does
196 that the latter does not is check to make sure that the breakpoint
197 location actually contains a breakpoint (trap instruction) prior
198 to attempting to write back the old contents. If it does contain
199 a trap instruction, we allow the old contents to be written back.
200 Otherwise, we silently do nothing.
201
202 The big question is whether memory_remove_breakpoint () should be
203 changed to have the same functionality. The downside is that more
204 traffic is generated for remote targets since we'll have an extra
205 fetch of a memory word each time a breakpoint is removed.
206
207 For the time being, we'll leave this self-modifying-code-friendly
208 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
209 else in the event that some other platform has similar needs with
210 regard to removing breakpoints in some potentially self modifying
211 code. */
212 static int
213 ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
214 struct bp_target_info *bp_tgt)
215 {
216 CORE_ADDR addr = bp_tgt->reqstd_address;
217 const unsigned char *bp;
218 int val;
219 int bplen;
220 gdb_byte old_contents[BREAKPOINT_MAX];
221
222 /* Determine appropriate breakpoint contents and size for this address. */
223 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
224
225 /* Make sure we see the memory breakpoints. */
226 scoped_restore restore_memory
227 = make_scoped_restore_show_memory_breakpoints (1);
228 val = target_read_memory (addr, old_contents, bplen);
229
230 /* If our breakpoint is no longer at the address, this means that the
231 program modified the code on us, so it is wrong to put back the
232 old value. */
233 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
234 val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
235
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 /* PLT stub in executable. */
260 static struct ppc_insn_pattern powerpc32_plt_stub[] =
261 {
262 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
263 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
264 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
265 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
266 { 0, 0, 0 }
267 };
268
269 /* PLT stub in shared library. */
270 static struct ppc_insn_pattern powerpc32_plt_stub_so[] =
271 {
272 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
273 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
274 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
275 { 0xffffffff, 0x60000000, 0 }, /* nop */
276 { 0, 0, 0 }
277 };
278 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub)
279
280 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
281 section. For secure PLT, stub is in .text and we need to check
282 instruction patterns. */
283
284 static int
285 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
286 {
287 struct bound_minimal_symbol sym;
288
289 /* Check whether PC is in the dynamic linker. This also checks
290 whether it is in the .plt section, used by non-PIC executables. */
291 if (svr4_in_dynsym_resolve_code (pc))
292 return 1;
293
294 /* Check if we are in the resolver. */
295 sym = lookup_minimal_symbol_by_pc (pc);
296 if (sym.minsym != NULL
297 && (strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0
298 || strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym),
299 "__glink_PLTresolve") == 0))
300 return 1;
301
302 return 0;
303 }
304
305 /* Follow PLT stub to actual routine.
306
307 When the execution direction is EXEC_REVERSE, scan backward to
308 check whether we are in the middle of a PLT stub. Currently,
309 we only look-behind at most 4 instructions (the max length of PLT
310 stub sequence. */
311
312 static CORE_ADDR
313 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
314 {
315 unsigned int insnbuf[POWERPC32_PLT_STUB_LEN];
316 struct gdbarch *gdbarch = get_frame_arch (frame);
317 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
318 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
319 CORE_ADDR target = 0;
320 int scan_limit, i;
321
322 scan_limit = 1;
323 /* When reverse-debugging, scan backward to check whether we are
324 in the middle of trampoline code. */
325 if (execution_direction == EXEC_REVERSE)
326 scan_limit = 4; /* At more 4 instructions. */
327
328 for (i = 0; i < scan_limit; i++)
329 {
330 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
331 {
332 /* Insn pattern is
333 lis r11, xxxx
334 lwz r11, xxxx(r11)
335 Branch target is in r11. */
336
337 target = (ppc_insn_d_field (insnbuf[0]) << 16)
338 | ppc_insn_d_field (insnbuf[1]);
339 target = read_memory_unsigned_integer (target, 4, byte_order);
340 }
341 else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so,
342 insnbuf))
343 {
344 /* Insn pattern is
345 lwz r11, xxxx(r30)
346 Branch target is in r11. */
347
348 target = get_frame_register_unsigned (frame,
349 tdep->ppc_gp0_regnum + 30)
350 + ppc_insn_d_field (insnbuf[0]);
351 target = read_memory_unsigned_integer (target, 4, byte_order);
352 }
353 else
354 {
355 /* Scan backward one more instructions if doesn't match. */
356 pc -= 4;
357 continue;
358 }
359
360 return target;
361 }
362
363 return 0;
364 }
365
366 /* Wrappers to handle Linux-only registers. */
367
368 static void
369 ppc_linux_supply_gregset (const struct regset *regset,
370 struct regcache *regcache,
371 int regnum, const void *gregs, size_t len)
372 {
373 const struct ppc_reg_offsets *offsets
374 = (const struct ppc_reg_offsets *) regset->regmap;
375
376 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
377
378 if (ppc_linux_trap_reg_p (regcache->arch ()))
379 {
380 /* "orig_r3" is stored 2 slots after "pc". */
381 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
382 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, (const gdb_byte *) gregs,
383 offsets->pc_offset + 2 * offsets->gpr_size,
384 offsets->gpr_size);
385
386 /* "trap" is stored 8 slots after "pc". */
387 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
388 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, (const gdb_byte *) gregs,
389 offsets->pc_offset + 8 * offsets->gpr_size,
390 offsets->gpr_size);
391 }
392 }
393
394 static void
395 ppc_linux_collect_gregset (const struct regset *regset,
396 const struct regcache *regcache,
397 int regnum, void *gregs, size_t len)
398 {
399 const struct ppc_reg_offsets *offsets
400 = (const struct ppc_reg_offsets *) regset->regmap;
401
402 /* Clear areas in the linux gregset not written elsewhere. */
403 if (regnum == -1)
404 memset (gregs, 0, len);
405
406 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
407
408 if (ppc_linux_trap_reg_p (regcache->arch ()))
409 {
410 /* "orig_r3" is stored 2 slots after "pc". */
411 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
412 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, (gdb_byte *) gregs,
413 offsets->pc_offset + 2 * offsets->gpr_size,
414 offsets->gpr_size);
415
416 /* "trap" is stored 8 slots after "pc". */
417 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
418 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, (gdb_byte *) gregs,
419 offsets->pc_offset + 8 * offsets->gpr_size,
420 offsets->gpr_size);
421 }
422 }
423
424 /* Regset descriptions. */
425 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
426 {
427 /* General-purpose registers. */
428 /* .r0_offset = */ 0,
429 /* .gpr_size = */ 4,
430 /* .xr_size = */ 4,
431 /* .pc_offset = */ 128,
432 /* .ps_offset = */ 132,
433 /* .cr_offset = */ 152,
434 /* .lr_offset = */ 144,
435 /* .ctr_offset = */ 140,
436 /* .xer_offset = */ 148,
437 /* .mq_offset = */ 156,
438
439 /* Floating-point registers. */
440 /* .f0_offset = */ 0,
441 /* .fpscr_offset = */ 256,
442 /* .fpscr_size = */ 8,
443
444 /* AltiVec registers. */
445 /* .vr0_offset = */ 0,
446 /* .vscr_offset = */ 512 + 12,
447 /* .vrsave_offset = */ 528
448 };
449
450 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
451 {
452 /* General-purpose registers. */
453 /* .r0_offset = */ 0,
454 /* .gpr_size = */ 8,
455 /* .xr_size = */ 8,
456 /* .pc_offset = */ 256,
457 /* .ps_offset = */ 264,
458 /* .cr_offset = */ 304,
459 /* .lr_offset = */ 288,
460 /* .ctr_offset = */ 280,
461 /* .xer_offset = */ 296,
462 /* .mq_offset = */ 312,
463
464 /* Floating-point registers. */
465 /* .f0_offset = */ 0,
466 /* .fpscr_offset = */ 256,
467 /* .fpscr_size = */ 8,
468
469 /* AltiVec registers. */
470 /* .vr0_offset = */ 0,
471 /* .vscr_offset = */ 512 + 12,
472 /* .vrsave_offset = */ 528
473 };
474
475 static const struct regset ppc32_linux_gregset = {
476 &ppc32_linux_reg_offsets,
477 ppc_linux_supply_gregset,
478 ppc_linux_collect_gregset
479 };
480
481 static const struct regset ppc64_linux_gregset = {
482 &ppc64_linux_reg_offsets,
483 ppc_linux_supply_gregset,
484 ppc_linux_collect_gregset
485 };
486
487 static const struct regset ppc32_linux_fpregset = {
488 &ppc32_linux_reg_offsets,
489 ppc_supply_fpregset,
490 ppc_collect_fpregset
491 };
492
493 static const struct regset ppc32_linux_vrregset = {
494 &ppc32_linux_reg_offsets,
495 ppc_supply_vrregset,
496 ppc_collect_vrregset
497 };
498
499 static const struct regset ppc32_linux_vsxregset = {
500 &ppc32_linux_reg_offsets,
501 ppc_supply_vsxregset,
502 ppc_collect_vsxregset
503 };
504
505 const struct regset *
506 ppc_linux_gregset (int wordsize)
507 {
508 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
509 }
510
511 const struct regset *
512 ppc_linux_fpregset (void)
513 {
514 return &ppc32_linux_fpregset;
515 }
516
517 /* Iterate over supported core file register note sections. */
518
519 static void
520 ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
521 iterate_over_regset_sections_cb *cb,
522 void *cb_data,
523 const struct regcache *regcache)
524 {
525 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
526 int have_altivec = tdep->ppc_vr0_regnum != -1;
527 int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
528
529 if (tdep->wordsize == 4)
530 cb (".reg", 48 * 4, &ppc32_linux_gregset, NULL, cb_data);
531 else
532 cb (".reg", 48 * 8, &ppc64_linux_gregset, NULL, cb_data);
533
534 cb (".reg2", 264, &ppc32_linux_fpregset, NULL, cb_data);
535
536 if (have_altivec)
537 cb (".reg-ppc-vmx", 544, &ppc32_linux_vrregset, "ppc Altivec", cb_data);
538
539 if (have_vsx)
540 cb (".reg-ppc-vsx", 256, &ppc32_linux_vsxregset, "POWER7 VSX", cb_data);
541 }
542
543 static void
544 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
545 struct trad_frame_cache *this_cache,
546 CORE_ADDR func, LONGEST offset,
547 int bias)
548 {
549 CORE_ADDR base;
550 CORE_ADDR regs;
551 CORE_ADDR gpregs;
552 CORE_ADDR fpregs;
553 int i;
554 struct gdbarch *gdbarch = get_frame_arch (this_frame);
555 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
556 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
557
558 base = get_frame_register_unsigned (this_frame,
559 gdbarch_sp_regnum (gdbarch));
560 if (bias > 0 && get_frame_pc (this_frame) != func)
561 /* See below, some signal trampolines increment the stack as their
562 first instruction, need to compensate for that. */
563 base -= bias;
564
565 /* Find the address of the register buffer pointer. */
566 regs = base + offset;
567 /* Use that to find the address of the corresponding register
568 buffers. */
569 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
570 fpregs = gpregs + 48 * tdep->wordsize;
571
572 /* General purpose. */
573 for (i = 0; i < 32; i++)
574 {
575 int regnum = i + tdep->ppc_gp0_regnum;
576 trad_frame_set_reg_addr (this_cache,
577 regnum, gpregs + i * tdep->wordsize);
578 }
579 trad_frame_set_reg_addr (this_cache,
580 gdbarch_pc_regnum (gdbarch),
581 gpregs + 32 * tdep->wordsize);
582 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
583 gpregs + 35 * tdep->wordsize);
584 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
585 gpregs + 36 * tdep->wordsize);
586 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
587 gpregs + 37 * tdep->wordsize);
588 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
589 gpregs + 38 * tdep->wordsize);
590
591 if (ppc_linux_trap_reg_p (gdbarch))
592 {
593 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
594 gpregs + 34 * tdep->wordsize);
595 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
596 gpregs + 40 * tdep->wordsize);
597 }
598
599 if (ppc_floating_point_unit_p (gdbarch))
600 {
601 /* Floating point registers. */
602 for (i = 0; i < 32; i++)
603 {
604 int regnum = i + gdbarch_fp0_regnum (gdbarch);
605 trad_frame_set_reg_addr (this_cache, regnum,
606 fpregs + i * tdep->wordsize);
607 }
608 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
609 fpregs + 32 * tdep->wordsize);
610 }
611 trad_frame_set_id (this_cache, frame_id_build (base, func));
612 }
613
614 static void
615 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
616 struct frame_info *this_frame,
617 struct trad_frame_cache *this_cache,
618 CORE_ADDR func)
619 {
620 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
621 0xd0 /* Offset to ucontext_t. */
622 + 0x30 /* Offset to .reg. */,
623 0);
624 }
625
626 static void
627 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
628 struct frame_info *this_frame,
629 struct trad_frame_cache *this_cache,
630 CORE_ADDR func)
631 {
632 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
633 0x80 /* Offset to ucontext_t. */
634 + 0xe0 /* Offset to .reg. */,
635 128);
636 }
637
638 static void
639 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
640 struct frame_info *this_frame,
641 struct trad_frame_cache *this_cache,
642 CORE_ADDR func)
643 {
644 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
645 0x40 /* Offset to ucontext_t. */
646 + 0x1c /* Offset to .reg. */,
647 0);
648 }
649
650 static void
651 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
652 struct frame_info *this_frame,
653 struct trad_frame_cache *this_cache,
654 CORE_ADDR func)
655 {
656 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
657 0x80 /* Offset to struct sigcontext. */
658 + 0x38 /* Offset to .reg. */,
659 128);
660 }
661
662 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
663 SIGTRAMP_FRAME,
664 4,
665 {
666 { 0x380000ac, -1 }, /* li r0, 172 */
667 { 0x44000002, -1 }, /* sc */
668 { TRAMP_SENTINEL_INSN },
669 },
670 ppc32_linux_sigaction_cache_init
671 };
672 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
673 SIGTRAMP_FRAME,
674 4,
675 {
676 { 0x38210080, -1 }, /* addi r1,r1,128 */
677 { 0x380000ac, -1 }, /* li r0, 172 */
678 { 0x44000002, -1 }, /* sc */
679 { TRAMP_SENTINEL_INSN },
680 },
681 ppc64_linux_sigaction_cache_init
682 };
683 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
684 SIGTRAMP_FRAME,
685 4,
686 {
687 { 0x38000077, -1 }, /* li r0,119 */
688 { 0x44000002, -1 }, /* sc */
689 { TRAMP_SENTINEL_INSN },
690 },
691 ppc32_linux_sighandler_cache_init
692 };
693 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
694 SIGTRAMP_FRAME,
695 4,
696 {
697 { 0x38210080, -1 }, /* addi r1,r1,128 */
698 { 0x38000077, -1 }, /* li r0,119 */
699 { 0x44000002, -1 }, /* sc */
700 { TRAMP_SENTINEL_INSN },
701 },
702 ppc64_linux_sighandler_cache_init
703 };
704
705 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
706 int
707 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
708 {
709 /* If we do not have a target description with registers, then
710 the special registers will not be included in the register set. */
711 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
712 return 0;
713
714 /* If we do, then it is safe to check the size. */
715 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
716 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
717 }
718
719 /* Return the current system call's number present in the
720 r0 register. When the function fails, it returns -1. */
721 static LONGEST
722 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
723 ptid_t ptid)
724 {
725 struct regcache *regcache = get_thread_regcache (ptid);
726 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
727 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
728 struct cleanup *cleanbuf;
729 /* The content of a register */
730 gdb_byte *buf;
731 /* The result */
732 LONGEST ret;
733
734 /* Make sure we're in a 32- or 64-bit machine */
735 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
736
737 buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte));
738
739 cleanbuf = make_cleanup (xfree, buf);
740
741 /* Getting the system call number from the register.
742 When dealing with PowerPC architecture, this information
743 is stored at 0th register. */
744 regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf);
745
746 ret = extract_signed_integer (buf, tdep->wordsize, byte_order);
747 do_cleanups (cleanbuf);
748
749 return ret;
750 }
751
752 /* PPC process record-replay */
753
754 static struct linux_record_tdep ppc_linux_record_tdep;
755 static struct linux_record_tdep ppc64_linux_record_tdep;
756
757 /* ppc_canonicalize_syscall maps from the native PowerPC Linux set of
758 syscall ids into a canonical set of syscall ids used by process
759 record. (See arch/powerpc/include/uapi/asm/unistd.h in kernel tree.)
760 Return -1 if this system call is not supported by process record.
761 Otherwise, return the syscall number for preocess reocrd of given
762 SYSCALL. */
763
764 static enum gdb_syscall
765 ppc_canonicalize_syscall (int syscall)
766 {
767 int result = -1;
768
769 if (syscall <= 165)
770 result = syscall;
771 else if (syscall >= 167 && syscall <= 190) /* Skip query_module 166 */
772 result = syscall + 1;
773 else if (syscall >= 192 && syscall <= 197) /* mmap2 */
774 result = syscall;
775 else if (syscall == 208) /* tkill */
776 result = gdb_sys_tkill;
777 else if (syscall >= 207 && syscall <= 220) /* gettid */
778 result = syscall + 224 - 207;
779 else if (syscall >= 234 && syscall <= 239) /* exit_group */
780 result = syscall + 252 - 234;
781 else if (syscall >= 240 && syscall <= 248) /* timer_create */
782 result = syscall += 259 - 240;
783 else if (syscall >= 250 && syscall <= 251) /* tgkill */
784 result = syscall + 270 - 250;
785 else if (syscall == 336)
786 result = gdb_sys_recv;
787 else if (syscall == 337)
788 result = gdb_sys_recvfrom;
789 else if (syscall == 342)
790 result = gdb_sys_recvmsg;
791
792 return (enum gdb_syscall) result;
793 }
794
795 /* Record registers which might be clobbered during system call.
796 Return 0 if successful. */
797
798 static int
799 ppc_linux_syscall_record (struct regcache *regcache)
800 {
801 struct gdbarch *gdbarch = regcache->arch ();
802 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
803 ULONGEST scnum;
804 enum gdb_syscall syscall_gdb;
805 int ret;
806 int i;
807
808 regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum, &scnum);
809 syscall_gdb = ppc_canonicalize_syscall (scnum);
810
811 if (syscall_gdb < 0)
812 {
813 printf_unfiltered (_("Process record and replay target doesn't "
814 "support syscall number %d\n"), (int) scnum);
815 return 0;
816 }
817
818 if (syscall_gdb == gdb_sys_sigreturn
819 || syscall_gdb == gdb_sys_rt_sigreturn)
820 {
821 int i, j;
822 int regsets[] = { tdep->ppc_gp0_regnum,
823 tdep->ppc_fp0_regnum,
824 tdep->ppc_vr0_regnum,
825 tdep->ppc_vsr0_upper_regnum };
826
827 for (j = 0; j < 4; j++)
828 {
829 if (regsets[j] == -1)
830 continue;
831 for (i = 0; i < 32; i++)
832 {
833 if (record_full_arch_list_add_reg (regcache, regsets[j] + i))
834 return -1;
835 }
836 }
837
838 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
839 return -1;
840 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
841 return -1;
842 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
843 return -1;
844 if (record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum))
845 return -1;
846
847 return 0;
848 }
849
850 if (tdep->wordsize == 8)
851 ret = record_linux_system_call (syscall_gdb, regcache,
852 &ppc64_linux_record_tdep);
853 else
854 ret = record_linux_system_call (syscall_gdb, regcache,
855 &ppc_linux_record_tdep);
856
857 if (ret != 0)
858 return ret;
859
860 /* Record registers clobbered during syscall. */
861 for (i = 3; i <= 12; i++)
862 {
863 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
864 return -1;
865 }
866 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + 0))
867 return -1;
868 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
869 return -1;
870 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
871 return -1;
872 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
873 return -1;
874
875 return 0;
876 }
877
878 /* Record registers which might be clobbered during signal handling.
879 Return 0 if successful. */
880
881 static int
882 ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
883 enum gdb_signal signal)
884 {
885 /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c
886 handle_rt_signal32 in arch/powerpc/kernel/signal_32.c
887 arch/powerpc/include/asm/ptrace.h
888 for details. */
889 const int SIGNAL_FRAMESIZE = 128;
890 const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
891 ULONGEST sp;
892 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
893 int i;
894
895 for (i = 3; i <= 12; i++)
896 {
897 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
898 return -1;
899 }
900
901 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
902 return -1;
903 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
904 return -1;
905 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
906 return -1;
907 if (record_full_arch_list_add_reg (regcache, gdbarch_pc_regnum (gdbarch)))
908 return -1;
909 if (record_full_arch_list_add_reg (regcache, gdbarch_sp_regnum (gdbarch)))
910 return -1;
911
912 /* Record the change in the stack.
913 frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
914 regcache_raw_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &sp);
915 sp -= SIGNAL_FRAMESIZE;
916 sp -= sizeof_rt_sigframe;
917
918 if (record_full_arch_list_add_mem (sp, SIGNAL_FRAMESIZE + sizeof_rt_sigframe))
919 return -1;
920
921 if (record_full_arch_list_add_end ())
922 return -1;
923
924 return 0;
925 }
926
927 static void
928 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
929 {
930 struct gdbarch *gdbarch = regcache->arch ();
931
932 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
933
934 /* Set special TRAP register to -1 to prevent the kernel from
935 messing with the PC we just installed, if we happen to be
936 within an interrupted system call that the kernel wants to
937 restart.
938
939 Note that after we return from the dummy call, the TRAP and
940 ORIG_R3 registers will be automatically restored, and the
941 kernel continues to restart the system call at this point. */
942 if (ppc_linux_trap_reg_p (gdbarch))
943 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
944 }
945
946 static int
947 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
948 {
949 return startswith (bfd_section_name (abfd, asect), "SPU/");
950 }
951
952 static const struct target_desc *
953 ppc_linux_core_read_description (struct gdbarch *gdbarch,
954 struct target_ops *target,
955 bfd *abfd)
956 {
957 asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
958 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
959 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
960 asection *section = bfd_get_section_by_name (abfd, ".reg");
961 if (! section)
962 return NULL;
963
964 switch (bfd_section_size (abfd, section))
965 {
966 case 48 * 4:
967 if (cell)
968 return tdesc_powerpc_cell32l;
969 else if (vsx)
970 return tdesc_powerpc_vsx32l;
971 else if (altivec)
972 return tdesc_powerpc_altivec32l;
973 else
974 return tdesc_powerpc_32l;
975
976 case 48 * 8:
977 if (cell)
978 return tdesc_powerpc_cell64l;
979 else if (vsx)
980 return tdesc_powerpc_vsx64l;
981 else if (altivec)
982 return tdesc_powerpc_altivec64l;
983 else
984 return tdesc_powerpc_64l;
985
986 default:
987 return NULL;
988 }
989 }
990
991
992 /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
993 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
994
995 static void
996 ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
997 {
998 elf_symbol_type *elf_sym = (elf_symbol_type *)sym;
999
1000 /* If the symbol is marked as having a local entry point, set a target
1001 flag in the msymbol. We currently only support local entry point
1002 offsets of 8 bytes, which is the only entry point offset ever used
1003 by current compilers. If/when other offsets are ever used, we will
1004 have to use additional target flag bits to store them. */
1005 switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other))
1006 {
1007 default:
1008 break;
1009 case 8:
1010 MSYMBOL_TARGET_FLAG_1 (msym) = 1;
1011 break;
1012 }
1013 }
1014
1015 /* Implementation of `gdbarch_skip_entrypoint', as defined in
1016 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1017
1018 static CORE_ADDR
1019 ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc)
1020 {
1021 struct bound_minimal_symbol fun;
1022 int local_entry_offset = 0;
1023
1024 fun = lookup_minimal_symbol_by_pc (pc);
1025 if (fun.minsym == NULL)
1026 return pc;
1027
1028 /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
1029 offset values are encoded. */
1030 if (MSYMBOL_TARGET_FLAG_1 (fun.minsym))
1031 local_entry_offset = 8;
1032
1033 if (BMSYMBOL_VALUE_ADDRESS (fun) <= pc
1034 && pc < BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset)
1035 return BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset;
1036
1037 return pc;
1038 }
1039
1040 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1041 gdbarch.h. */
1042
1043 static int
1044 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
1045 {
1046 return (*s == 'i' /* Literal number. */
1047 || (isdigit (*s) && s[1] == '('
1048 && isdigit (s[2])) /* Displacement. */
1049 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
1050 || isdigit (*s)); /* Register value. */
1051 }
1052
1053 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
1054 gdbarch.h. */
1055
1056 static int
1057 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
1058 struct stap_parse_info *p)
1059 {
1060 if (isdigit (*p->arg))
1061 {
1062 /* This temporary pointer is needed because we have to do a lookahead.
1063 We could be dealing with a register displacement, and in such case
1064 we would not need to do anything. */
1065 const char *s = p->arg;
1066 char *regname;
1067 int len;
1068 struct stoken str;
1069
1070 while (isdigit (*s))
1071 ++s;
1072
1073 if (*s == '(')
1074 {
1075 /* It is a register displacement indeed. Returning 0 means we are
1076 deferring the treatment of this case to the generic parser. */
1077 return 0;
1078 }
1079
1080 len = s - p->arg;
1081 regname = (char *) alloca (len + 2);
1082 regname[0] = 'r';
1083
1084 strncpy (regname + 1, p->arg, len);
1085 ++len;
1086 regname[len] = '\0';
1087
1088 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
1089 error (_("Invalid register name `%s' on expression `%s'."),
1090 regname, p->saved_arg);
1091
1092 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
1093 str.ptr = regname;
1094 str.length = len;
1095 write_exp_string (&p->pstate, str);
1096 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
1097
1098 p->arg = s;
1099 }
1100 else
1101 {
1102 /* All the other tokens should be handled correctly by the generic
1103 parser. */
1104 return 0;
1105 }
1106
1107 return 1;
1108 }
1109
1110 /* Cell/B.E. active SPE context tracking support. */
1111
1112 static struct objfile *spe_context_objfile = NULL;
1113 static CORE_ADDR spe_context_lm_addr = 0;
1114 static CORE_ADDR spe_context_offset = 0;
1115
1116 static ptid_t spe_context_cache_ptid;
1117 static CORE_ADDR spe_context_cache_address;
1118
1119 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
1120 to track whether we've loaded a version of libspe2 (as static or dynamic
1121 library) that provides the __spe_current_active_context variable. */
1122 static void
1123 ppc_linux_spe_context_lookup (struct objfile *objfile)
1124 {
1125 struct bound_minimal_symbol sym;
1126
1127 if (!objfile)
1128 {
1129 spe_context_objfile = NULL;
1130 spe_context_lm_addr = 0;
1131 spe_context_offset = 0;
1132 spe_context_cache_ptid = minus_one_ptid;
1133 spe_context_cache_address = 0;
1134 return;
1135 }
1136
1137 sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
1138 if (sym.minsym)
1139 {
1140 spe_context_objfile = objfile;
1141 spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
1142 spe_context_offset = MSYMBOL_VALUE_RAW_ADDRESS (sym.minsym);
1143 spe_context_cache_ptid = minus_one_ptid;
1144 spe_context_cache_address = 0;
1145 return;
1146 }
1147 }
1148
1149 static void
1150 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
1151 {
1152 struct objfile *objfile;
1153
1154 ppc_linux_spe_context_lookup (NULL);
1155 ALL_OBJFILES (objfile)
1156 ppc_linux_spe_context_lookup (objfile);
1157 }
1158
1159 static void
1160 ppc_linux_spe_context_solib_loaded (struct so_list *so)
1161 {
1162 if (strstr (so->so_original_name, "/libspe") != NULL)
1163 {
1164 solib_read_symbols (so, 0);
1165 ppc_linux_spe_context_lookup (so->objfile);
1166 }
1167 }
1168
1169 static void
1170 ppc_linux_spe_context_solib_unloaded (struct so_list *so)
1171 {
1172 if (so->objfile == spe_context_objfile)
1173 ppc_linux_spe_context_lookup (NULL);
1174 }
1175
1176 /* Retrieve contents of the N'th element in the current thread's
1177 linked SPE context list into ID and NPC. Return the address of
1178 said context element, or 0 if not found. */
1179 static CORE_ADDR
1180 ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
1181 int n, int *id, unsigned int *npc)
1182 {
1183 CORE_ADDR spe_context = 0;
1184 gdb_byte buf[16];
1185 int i;
1186
1187 /* Quick exit if we have not found __spe_current_active_context. */
1188 if (!spe_context_objfile)
1189 return 0;
1190
1191 /* Look up cached address of thread-local variable. */
1192 if (!ptid_equal (spe_context_cache_ptid, inferior_ptid))
1193 {
1194 struct target_ops *target = &current_target;
1195
1196 TRY
1197 {
1198 /* We do not call target_translate_tls_address here, because
1199 svr4_fetch_objfile_link_map may invalidate the frame chain,
1200 which must not do while inside a frame sniffer.
1201
1202 Instead, we have cached the lm_addr value, and use that to
1203 directly call the target's to_get_thread_local_address. */
1204 spe_context_cache_address
1205 = target->to_get_thread_local_address (target, inferior_ptid,
1206 spe_context_lm_addr,
1207 spe_context_offset);
1208 spe_context_cache_ptid = inferior_ptid;
1209 }
1210
1211 CATCH (ex, RETURN_MASK_ERROR)
1212 {
1213 return 0;
1214 }
1215 END_CATCH
1216 }
1217
1218 /* Read variable value. */
1219 if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
1220 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1221
1222 /* Cyle through to N'th linked list element. */
1223 for (i = 0; i < n && spe_context; i++)
1224 if (target_read_memory (spe_context + align_up (12, wordsize),
1225 buf, wordsize) == 0)
1226 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1227 else
1228 spe_context = 0;
1229
1230 /* Read current context. */
1231 if (spe_context
1232 && target_read_memory (spe_context, buf, 12) != 0)
1233 spe_context = 0;
1234
1235 /* Extract data elements. */
1236 if (spe_context)
1237 {
1238 if (id)
1239 *id = extract_signed_integer (buf, 4, byte_order);
1240 if (npc)
1241 *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
1242 }
1243
1244 return spe_context;
1245 }
1246
1247
1248 /* Cell/B.E. cross-architecture unwinder support. */
1249
1250 struct ppu2spu_cache
1251 {
1252 struct frame_id frame_id;
1253 struct regcache *regcache;
1254 };
1255
1256 static struct gdbarch *
1257 ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
1258 {
1259 struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache;
1260 return cache->regcache->arch ();
1261 }
1262
1263 static void
1264 ppu2spu_this_id (struct frame_info *this_frame,
1265 void **this_cache, struct frame_id *this_id)
1266 {
1267 struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache;
1268 *this_id = cache->frame_id;
1269 }
1270
1271 static struct value *
1272 ppu2spu_prev_register (struct frame_info *this_frame,
1273 void **this_cache, int regnum)
1274 {
1275 struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache;
1276 struct gdbarch *gdbarch = cache->regcache->arch ();
1277 gdb_byte *buf;
1278
1279 buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
1280
1281 if (regnum < gdbarch_num_regs (gdbarch))
1282 regcache_raw_read (cache->regcache, regnum, buf);
1283 else
1284 gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf);
1285
1286 return frame_unwind_got_bytes (this_frame, regnum, buf);
1287 }
1288
1289 struct ppu2spu_data
1290 {
1291 struct gdbarch *gdbarch;
1292 int id;
1293 unsigned int npc;
1294 gdb_byte gprs[128*16];
1295 };
1296
1297 static enum register_status
1298 ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf)
1299 {
1300 struct ppu2spu_data *data = (struct ppu2spu_data *) src;
1301 enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
1302
1303 if (regnum >= 0 && regnum < SPU_NUM_GPRS)
1304 memcpy (buf, data->gprs + 16*regnum, 16);
1305 else if (regnum == SPU_ID_REGNUM)
1306 store_unsigned_integer (buf, 4, byte_order, data->id);
1307 else if (regnum == SPU_PC_REGNUM)
1308 store_unsigned_integer (buf, 4, byte_order, data->npc);
1309 else
1310 return REG_UNAVAILABLE;
1311
1312 return REG_VALID;
1313 }
1314
1315 static int
1316 ppu2spu_sniffer (const struct frame_unwind *self,
1317 struct frame_info *this_frame, void **this_prologue_cache)
1318 {
1319 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1320 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1321 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1322 struct ppu2spu_data data;
1323 struct frame_info *fi;
1324 CORE_ADDR base, func, backchain, spe_context;
1325 gdb_byte buf[8];
1326 int n = 0;
1327
1328 /* Count the number of SPU contexts already in the frame chain. */
1329 for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
1330 if (get_frame_type (fi) == ARCH_FRAME
1331 && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
1332 n++;
1333
1334 base = get_frame_sp (this_frame);
1335 func = get_frame_pc (this_frame);
1336 if (target_read_memory (base, buf, tdep->wordsize))
1337 return 0;
1338 backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
1339
1340 spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
1341 n, &data.id, &data.npc);
1342 if (spe_context && base <= spe_context && spe_context < backchain)
1343 {
1344 char annex[32];
1345
1346 /* Find gdbarch for SPU. */
1347 struct gdbarch_info info;
1348 gdbarch_info_init (&info);
1349 info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
1350 info.byte_order = BFD_ENDIAN_BIG;
1351 info.osabi = GDB_OSABI_LINUX;
1352 info.id = &data.id;
1353 data.gdbarch = gdbarch_find_by_info (info);
1354 if (!data.gdbarch)
1355 return 0;
1356
1357 xsnprintf (annex, sizeof annex, "%d/regs", data.id);
1358 if (target_read (&current_target, TARGET_OBJECT_SPU, annex,
1359 data.gprs, 0, sizeof data.gprs)
1360 == sizeof data.gprs)
1361 {
1362 struct ppu2spu_cache *cache
1363 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
1364
1365 const address_space *aspace = get_frame_address_space (this_frame);
1366 std::unique_ptr<struct regcache> regcache
1367 (new struct regcache (data.gdbarch, aspace));
1368 regcache_save (regcache.get (), ppu2spu_unwind_register, &data);
1369
1370 cache->frame_id = frame_id_build (base, func);
1371 cache->regcache = regcache.release ();
1372 *this_prologue_cache = cache;
1373 return 1;
1374 }
1375 }
1376
1377 return 0;
1378 }
1379
1380 static void
1381 ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
1382 {
1383 struct ppu2spu_cache *cache = (struct ppu2spu_cache *) this_cache;
1384 delete cache->regcache;
1385 }
1386
1387 static const struct frame_unwind ppu2spu_unwind = {
1388 ARCH_FRAME,
1389 default_frame_unwind_stop_reason,
1390 ppu2spu_this_id,
1391 ppu2spu_prev_register,
1392 NULL,
1393 ppu2spu_sniffer,
1394 ppu2spu_dealloc_cache,
1395 ppu2spu_prev_arch,
1396 };
1397
1398 /* Initialize linux_record_tdep if not initialized yet.
1399 WORDSIZE is 4 or 8 for 32- or 64-bit PowerPC Linux respectively.
1400 Sizes of data structures are initialized accordingly. */
1401
1402 static void
1403 ppc_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
1404 int wordsize)
1405 {
1406 /* Simply return if it had been initialized. */
1407 if (record_tdep->size_pointer != 0)
1408 return;
1409
1410 /* These values are the size of the type that will be used in a system
1411 call. They are obtained from Linux Kernel source. */
1412
1413 if (wordsize == 8)
1414 {
1415 record_tdep->size_pointer = 8;
1416 record_tdep->size__old_kernel_stat = 32;
1417 record_tdep->size_tms = 32;
1418 record_tdep->size_loff_t = 8;
1419 record_tdep->size_flock = 32;
1420 record_tdep->size_oldold_utsname = 45;
1421 record_tdep->size_ustat = 32;
1422 record_tdep->size_old_sigaction = 32;
1423 record_tdep->size_old_sigset_t = 8;
1424 record_tdep->size_rlimit = 16;
1425 record_tdep->size_rusage = 144;
1426 record_tdep->size_timeval = 16;
1427 record_tdep->size_timezone = 8;
1428 record_tdep->size_old_gid_t = 4;
1429 record_tdep->size_old_uid_t = 4;
1430 record_tdep->size_fd_set = 128;
1431 record_tdep->size_old_dirent = 280;
1432 record_tdep->size_statfs = 120;
1433 record_tdep->size_statfs64 = 120;
1434 record_tdep->size_sockaddr = 16;
1435 record_tdep->size_int = 4;
1436 record_tdep->size_long = 8;
1437 record_tdep->size_ulong = 8;
1438 record_tdep->size_msghdr = 56;
1439 record_tdep->size_itimerval = 32;
1440 record_tdep->size_stat = 144;
1441 record_tdep->size_old_utsname = 325;
1442 record_tdep->size_sysinfo = 112;
1443 record_tdep->size_msqid_ds = 120;
1444 record_tdep->size_shmid_ds = 112;
1445 record_tdep->size_new_utsname = 390;
1446 record_tdep->size_timex = 208;
1447 record_tdep->size_mem_dqinfo = 24;
1448 record_tdep->size_if_dqblk = 72;
1449 record_tdep->size_fs_quota_stat = 80;
1450 record_tdep->size_timespec = 16;
1451 record_tdep->size_pollfd = 8;
1452 record_tdep->size_NFS_FHSIZE = 32;
1453 record_tdep->size_knfsd_fh = 132;
1454 record_tdep->size_TASK_COMM_LEN = 16;
1455 record_tdep->size_sigaction = 32;
1456 record_tdep->size_sigset_t = 8;
1457 record_tdep->size_siginfo_t = 128;
1458 record_tdep->size_cap_user_data_t = 8;
1459 record_tdep->size_stack_t = 24;
1460 record_tdep->size_off_t = 8;
1461 record_tdep->size_stat64 = 104;
1462 record_tdep->size_gid_t = 4;
1463 record_tdep->size_uid_t = 4;
1464 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
1465 record_tdep->size_flock64 = 32;
1466 record_tdep->size_io_event = 32;
1467 record_tdep->size_iocb = 64;
1468 record_tdep->size_epoll_event = 16;
1469 record_tdep->size_itimerspec = 32;
1470 record_tdep->size_mq_attr = 64;
1471 record_tdep->size_termios = 44;
1472 record_tdep->size_pid_t = 4;
1473 record_tdep->size_winsize = 8;
1474 record_tdep->size_serial_struct = 72;
1475 record_tdep->size_serial_icounter_struct = 80;
1476 record_tdep->size_size_t = 8;
1477 record_tdep->size_iovec = 16;
1478 record_tdep->size_time_t = 8;
1479 }
1480 else if (wordsize == 4)
1481 {
1482 record_tdep->size_pointer = 4;
1483 record_tdep->size__old_kernel_stat = 32;
1484 record_tdep->size_tms = 16;
1485 record_tdep->size_loff_t = 8;
1486 record_tdep->size_flock = 16;
1487 record_tdep->size_oldold_utsname = 45;
1488 record_tdep->size_ustat = 20;
1489 record_tdep->size_old_sigaction = 16;
1490 record_tdep->size_old_sigset_t = 4;
1491 record_tdep->size_rlimit = 8;
1492 record_tdep->size_rusage = 72;
1493 record_tdep->size_timeval = 8;
1494 record_tdep->size_timezone = 8;
1495 record_tdep->size_old_gid_t = 4;
1496 record_tdep->size_old_uid_t = 4;
1497 record_tdep->size_fd_set = 128;
1498 record_tdep->size_old_dirent = 268;
1499 record_tdep->size_statfs = 64;
1500 record_tdep->size_statfs64 = 88;
1501 record_tdep->size_sockaddr = 16;
1502 record_tdep->size_int = 4;
1503 record_tdep->size_long = 4;
1504 record_tdep->size_ulong = 4;
1505 record_tdep->size_msghdr = 28;
1506 record_tdep->size_itimerval = 16;
1507 record_tdep->size_stat = 88;
1508 record_tdep->size_old_utsname = 325;
1509 record_tdep->size_sysinfo = 64;
1510 record_tdep->size_msqid_ds = 68;
1511 record_tdep->size_shmid_ds = 60;
1512 record_tdep->size_new_utsname = 390;
1513 record_tdep->size_timex = 128;
1514 record_tdep->size_mem_dqinfo = 24;
1515 record_tdep->size_if_dqblk = 72;
1516 record_tdep->size_fs_quota_stat = 80;
1517 record_tdep->size_timespec = 8;
1518 record_tdep->size_pollfd = 8;
1519 record_tdep->size_NFS_FHSIZE = 32;
1520 record_tdep->size_knfsd_fh = 132;
1521 record_tdep->size_TASK_COMM_LEN = 16;
1522 record_tdep->size_sigaction = 20;
1523 record_tdep->size_sigset_t = 8;
1524 record_tdep->size_siginfo_t = 128;
1525 record_tdep->size_cap_user_data_t = 4;
1526 record_tdep->size_stack_t = 12;
1527 record_tdep->size_off_t = 4;
1528 record_tdep->size_stat64 = 104;
1529 record_tdep->size_gid_t = 4;
1530 record_tdep->size_uid_t = 4;
1531 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
1532 record_tdep->size_flock64 = 32;
1533 record_tdep->size_io_event = 32;
1534 record_tdep->size_iocb = 64;
1535 record_tdep->size_epoll_event = 16;
1536 record_tdep->size_itimerspec = 16;
1537 record_tdep->size_mq_attr = 32;
1538 record_tdep->size_termios = 44;
1539 record_tdep->size_pid_t = 4;
1540 record_tdep->size_winsize = 8;
1541 record_tdep->size_serial_struct = 60;
1542 record_tdep->size_serial_icounter_struct = 80;
1543 record_tdep->size_size_t = 4;
1544 record_tdep->size_iovec = 8;
1545 record_tdep->size_time_t = 4;
1546 }
1547 else
1548 internal_error (__FILE__, __LINE__, _("unexpected wordsize"));
1549
1550 /* These values are the second argument of system call "sys_fcntl"
1551 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1552 record_tdep->fcntl_F_GETLK = 5;
1553 record_tdep->fcntl_F_GETLK64 = 12;
1554 record_tdep->fcntl_F_SETLK64 = 13;
1555 record_tdep->fcntl_F_SETLKW64 = 14;
1556
1557 record_tdep->arg1 = PPC_R0_REGNUM + 3;
1558 record_tdep->arg2 = PPC_R0_REGNUM + 4;
1559 record_tdep->arg3 = PPC_R0_REGNUM + 5;
1560 record_tdep->arg4 = PPC_R0_REGNUM + 6;
1561 record_tdep->arg5 = PPC_R0_REGNUM + 7;
1562 record_tdep->arg6 = PPC_R0_REGNUM + 8;
1563
1564 /* These values are the second argument of system call "sys_ioctl".
1565 They are obtained from Linux Kernel source.
1566 See arch/powerpc/include/uapi/asm/ioctls.h. */
1567 record_tdep->ioctl_TCGETS = 0x403c7413;
1568 record_tdep->ioctl_TCSETS = 0x803c7414;
1569 record_tdep->ioctl_TCSETSW = 0x803c7415;
1570 record_tdep->ioctl_TCSETSF = 0x803c7416;
1571 record_tdep->ioctl_TCGETA = 0x40147417;
1572 record_tdep->ioctl_TCSETA = 0x80147418;
1573 record_tdep->ioctl_TCSETAW = 0x80147419;
1574 record_tdep->ioctl_TCSETAF = 0x8014741c;
1575 record_tdep->ioctl_TCSBRK = 0x2000741d;
1576 record_tdep->ioctl_TCXONC = 0x2000741e;
1577 record_tdep->ioctl_TCFLSH = 0x2000741f;
1578 record_tdep->ioctl_TIOCEXCL = 0x540c;
1579 record_tdep->ioctl_TIOCNXCL = 0x540d;
1580 record_tdep->ioctl_TIOCSCTTY = 0x540e;
1581 record_tdep->ioctl_TIOCGPGRP = 0x40047477;
1582 record_tdep->ioctl_TIOCSPGRP = 0x80047476;
1583 record_tdep->ioctl_TIOCOUTQ = 0x40047473;
1584 record_tdep->ioctl_TIOCSTI = 0x5412;
1585 record_tdep->ioctl_TIOCGWINSZ = 0x40087468;
1586 record_tdep->ioctl_TIOCSWINSZ = 0x80087467;
1587 record_tdep->ioctl_TIOCMGET = 0x5415;
1588 record_tdep->ioctl_TIOCMBIS = 0x5416;
1589 record_tdep->ioctl_TIOCMBIC = 0x5417;
1590 record_tdep->ioctl_TIOCMSET = 0x5418;
1591 record_tdep->ioctl_TIOCGSOFTCAR = 0x5419;
1592 record_tdep->ioctl_TIOCSSOFTCAR = 0x541a;
1593 record_tdep->ioctl_FIONREAD = 0x4004667f;
1594 record_tdep->ioctl_TIOCINQ = 0x4004667f;
1595 record_tdep->ioctl_TIOCLINUX = 0x541c;
1596 record_tdep->ioctl_TIOCCONS = 0x541d;
1597 record_tdep->ioctl_TIOCGSERIAL = 0x541e;
1598 record_tdep->ioctl_TIOCSSERIAL = 0x541f;
1599 record_tdep->ioctl_TIOCPKT = 0x5420;
1600 record_tdep->ioctl_FIONBIO = 0x8004667e;
1601 record_tdep->ioctl_TIOCNOTTY = 0x5422;
1602 record_tdep->ioctl_TIOCSETD = 0x5423;
1603 record_tdep->ioctl_TIOCGETD = 0x5424;
1604 record_tdep->ioctl_TCSBRKP = 0x5425;
1605 record_tdep->ioctl_TIOCSBRK = 0x5427;
1606 record_tdep->ioctl_TIOCCBRK = 0x5428;
1607 record_tdep->ioctl_TIOCGSID = 0x5429;
1608 record_tdep->ioctl_TIOCGPTN = 0x40045430;
1609 record_tdep->ioctl_TIOCSPTLCK = 0x80045431;
1610 record_tdep->ioctl_FIONCLEX = 0x20006602;
1611 record_tdep->ioctl_FIOCLEX = 0x20006601;
1612 record_tdep->ioctl_FIOASYNC = 0x8004667d;
1613 record_tdep->ioctl_TIOCSERCONFIG = 0x5453;
1614 record_tdep->ioctl_TIOCSERGWILD = 0x5454;
1615 record_tdep->ioctl_TIOCSERSWILD = 0x5455;
1616 record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456;
1617 record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457;
1618 record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458;
1619 record_tdep->ioctl_TIOCSERGETLSR = 0x5459;
1620 record_tdep->ioctl_TIOCSERGETMULTI = 0x545a;
1621 record_tdep->ioctl_TIOCSERSETMULTI = 0x545b;
1622 record_tdep->ioctl_TIOCMIWAIT = 0x545c;
1623 record_tdep->ioctl_TIOCGICOUNT = 0x545d;
1624 record_tdep->ioctl_FIOQSIZE = 0x40086680;
1625 }
1626
1627 /* Return a floating-point format for a floating-point variable of
1628 length LEN in bits. If non-NULL, NAME is the name of its type.
1629 If no suitable type is found, return NULL. */
1630
1631 const struct floatformat **
1632 ppc_floatformat_for_type (struct gdbarch *gdbarch,
1633 const char *name, int len)
1634 {
1635 if (len == 128 && name)
1636 if (strcmp (name, "__float128") == 0
1637 || strcmp (name, "_Float128") == 0
1638 || strcmp (name, "_Float64x") == 0
1639 || strcmp (name, "complex _Float128") == 0
1640 || strcmp (name, "complex _Float64x") == 0)
1641 return floatformats_ia64_quad;
1642
1643 return default_floatformat_for_type (gdbarch, name, len);
1644 }
1645
1646 static void
1647 ppc_linux_init_abi (struct gdbarch_info info,
1648 struct gdbarch *gdbarch)
1649 {
1650 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1651 struct tdesc_arch_data *tdesc_data = info.tdesc_data;
1652 static const char *const stap_integer_prefixes[] = { "i", NULL };
1653 static const char *const stap_register_indirection_prefixes[] = { "(",
1654 NULL };
1655 static const char *const stap_register_indirection_suffixes[] = { ")",
1656 NULL };
1657
1658 linux_init_abi (info, gdbarch);
1659
1660 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1661 128-bit, they are IBM long double, not IEEE quad long double as
1662 in the System V ABI PowerPC Processor Supplement. We can safely
1663 let them default to 128-bit, since the debug info will give the
1664 size of type actually used in each case. */
1665 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
1666 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
1667
1668 /* Support for floating-point data type variants. */
1669 set_gdbarch_floatformat_for_type (gdbarch, ppc_floatformat_for_type);
1670
1671 /* Handle inferior calls during interrupted system calls. */
1672 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
1673
1674 /* Get the syscall number from the arch's register. */
1675 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
1676
1677 /* SystemTap functions. */
1678 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
1679 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
1680 stap_register_indirection_prefixes);
1681 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
1682 stap_register_indirection_suffixes);
1683 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
1684 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
1685 set_gdbarch_stap_parse_special_token (gdbarch,
1686 ppc_stap_parse_special_token);
1687
1688 if (tdep->wordsize == 4)
1689 {
1690 /* Until November 2001, gcc did not comply with the 32 bit SysV
1691 R4 ABI requirement that structures less than or equal to 8
1692 bytes should be returned in registers. Instead GCC was using
1693 the AIX/PowerOpen ABI - everything returned in memory
1694 (well ignoring vectors that is). When this was corrected, it
1695 wasn't fixed for GNU/Linux native platform. Use the
1696 PowerOpen struct convention. */
1697 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
1698
1699 set_gdbarch_memory_remove_breakpoint (gdbarch,
1700 ppc_linux_memory_remove_breakpoint);
1701
1702 /* Shared library handling. */
1703 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
1704 set_solib_svr4_fetch_link_map_offsets
1705 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1706
1707 /* Setting the correct XML syscall filename. */
1708 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC);
1709
1710 /* Trampolines. */
1711 tramp_frame_prepend_unwinder (gdbarch,
1712 &ppc32_linux_sigaction_tramp_frame);
1713 tramp_frame_prepend_unwinder (gdbarch,
1714 &ppc32_linux_sighandler_tramp_frame);
1715
1716 /* BFD target for core files. */
1717 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1718 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
1719 else
1720 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
1721
1722 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
1723 {
1724 powerpc_so_ops = svr4_so_ops;
1725 /* Override dynamic resolve function. */
1726 powerpc_so_ops.in_dynsym_resolve_code =
1727 powerpc_linux_in_dynsym_resolve_code;
1728 }
1729 set_solib_ops (gdbarch, &powerpc_so_ops);
1730
1731 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1732 }
1733
1734 if (tdep->wordsize == 8)
1735 {
1736 if (tdep->elf_abi == POWERPC_ELF_V1)
1737 {
1738 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1739 function descriptors). */
1740 set_gdbarch_convert_from_func_ptr_addr
1741 (gdbarch, ppc64_convert_from_func_ptr_addr);
1742
1743 set_gdbarch_elf_make_msymbol_special
1744 (gdbarch, ppc64_elf_make_msymbol_special);
1745 }
1746 else
1747 {
1748 set_gdbarch_elf_make_msymbol_special
1749 (gdbarch, ppc_elfv2_elf_make_msymbol_special);
1750
1751 set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint);
1752 }
1753
1754 /* Shared library handling. */
1755 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
1756 set_solib_svr4_fetch_link_map_offsets
1757 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1758
1759 /* Setting the correct XML syscall filename. */
1760 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC64);
1761
1762 /* Trampolines. */
1763 tramp_frame_prepend_unwinder (gdbarch,
1764 &ppc64_linux_sigaction_tramp_frame);
1765 tramp_frame_prepend_unwinder (gdbarch,
1766 &ppc64_linux_sighandler_tramp_frame);
1767
1768 /* BFD target for core files. */
1769 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1770 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
1771 else
1772 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
1773 }
1774
1775 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
1776 set_gdbarch_iterate_over_regset_sections (gdbarch,
1777 ppc_linux_iterate_over_regset_sections);
1778
1779 /* Enable TLS support. */
1780 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1781 svr4_fetch_objfile_link_map);
1782
1783 if (tdesc_data)
1784 {
1785 const struct tdesc_feature *feature;
1786
1787 /* If we have target-described registers, then we can safely
1788 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1789 (whether they are described or not). */
1790 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
1791 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
1792
1793 /* If they are present, then assign them to the reserved number. */
1794 feature = tdesc_find_feature (info.target_desc,
1795 "org.gnu.gdb.power.linux");
1796 if (feature != NULL)
1797 {
1798 tdesc_numbered_register (feature, tdesc_data,
1799 PPC_ORIG_R3_REGNUM, "orig_r3");
1800 tdesc_numbered_register (feature, tdesc_data,
1801 PPC_TRAP_REGNUM, "trap");
1802 }
1803 }
1804
1805 /* Enable Cell/B.E. if supported by the target. */
1806 if (tdesc_compatible_p (info.target_desc,
1807 bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
1808 {
1809 /* Cell/B.E. multi-architecture support. */
1810 set_spu_solib_ops (gdbarch);
1811
1812 /* Cell/B.E. cross-architecture unwinder support. */
1813 frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
1814 }
1815
1816 set_gdbarch_displaced_step_location (gdbarch,
1817 linux_displaced_step_location);
1818
1819 /* Support reverse debugging. */
1820 set_gdbarch_process_record (gdbarch, ppc_process_record);
1821 set_gdbarch_process_record_signal (gdbarch, ppc_linux_record_signal);
1822 tdep->ppc_syscall_record = ppc_linux_syscall_record;
1823
1824 ppc_init_linux_record_tdep (&ppc_linux_record_tdep, 4);
1825 ppc_init_linux_record_tdep (&ppc64_linux_record_tdep, 8);
1826 }
1827
1828 void
1829 _initialize_ppc_linux_tdep (void)
1830 {
1831 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1832 64-bit PowerPC, and the older rs6k. */
1833 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
1834 ppc_linux_init_abi);
1835 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
1836 ppc_linux_init_abi);
1837 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
1838 ppc_linux_init_abi);
1839
1840 /* Attach to observers to track __spe_current_active_context. */
1841 observer_attach_inferior_created (ppc_linux_spe_context_inferior_created);
1842 observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded);
1843 observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded);
1844
1845 /* Initialize the Linux target descriptions. */
1846 initialize_tdesc_powerpc_32l ();
1847 initialize_tdesc_powerpc_altivec32l ();
1848 initialize_tdesc_powerpc_cell32l ();
1849 initialize_tdesc_powerpc_vsx32l ();
1850 initialize_tdesc_powerpc_isa205_32l ();
1851 initialize_tdesc_powerpc_isa205_altivec32l ();
1852 initialize_tdesc_powerpc_isa205_vsx32l ();
1853 initialize_tdesc_powerpc_64l ();
1854 initialize_tdesc_powerpc_altivec64l ();
1855 initialize_tdesc_powerpc_cell64l ();
1856 initialize_tdesc_powerpc_vsx64l ();
1857 initialize_tdesc_powerpc_isa205_64l ();
1858 initialize_tdesc_powerpc_isa205_altivec64l ();
1859 initialize_tdesc_powerpc_isa205_vsx64l ();
1860 initialize_tdesc_powerpc_e500l ();
1861 }
This page took 0.067391 seconds and 5 git commands to generate.