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