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