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