1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 1986-2018 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
33 #include "solib-svr4.h"
34 #include "solib-spu.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"
48 #include "elf/common.h"
49 #include "elf/ppc64.h"
50 #include "arch-utils.h"
52 #include "xml-syscall.h"
53 #include "linux-tdep.h"
54 #include "linux-record.h"
55 #include "record-full.h"
58 #include "stap-probe.h"
61 #include "cli/cli-utils.h"
62 #include "parser-defs.h"
63 #include "user-regs.h"
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-isa207-htm-vsx32l.c"
77 #include "features/rs6000/powerpc-64l.c"
78 #include "features/rs6000/powerpc-altivec64l.c"
79 #include "features/rs6000/powerpc-cell64l.c"
80 #include "features/rs6000/powerpc-vsx64l.c"
81 #include "features/rs6000/powerpc-isa205-64l.c"
82 #include "features/rs6000/powerpc-isa205-altivec64l.c"
83 #include "features/rs6000/powerpc-isa205-vsx64l.c"
84 #include "features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c"
85 #include "features/rs6000/powerpc-isa207-vsx64l.c"
86 #include "features/rs6000/powerpc-isa207-htm-vsx64l.c"
87 #include "features/rs6000/powerpc-e500l.c"
89 /* Shared library operations for PowerPC-Linux. */
90 static struct target_so_ops powerpc_so_ops;
92 /* The syscall's XML filename for PPC and PPC64. */
93 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
94 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
96 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
97 in much the same fashion as memory_remove_breakpoint in mem-break.c,
98 but is careful not to write back the previous contents if the code
99 in question has changed in between inserting the breakpoint and
102 Here is the problem that we're trying to solve...
104 Once upon a time, before introducing this function to remove
105 breakpoints from the inferior, setting a breakpoint on a shared
106 library function prior to running the program would not work
107 properly. In order to understand the problem, it is first
108 necessary to understand a little bit about dynamic linking on
111 A call to a shared library function is accomplished via a bl
112 (branch-and-link) instruction whose branch target is an entry
113 in the procedure linkage table (PLT). The PLT in the object
114 file is uninitialized. To gdb, prior to running the program, the
115 entries in the PLT are all zeros.
117 Once the program starts running, the shared libraries are loaded
118 and the procedure linkage table is initialized, but the entries in
119 the table are not (necessarily) resolved. Once a function is
120 actually called, the code in the PLT is hit and the function is
121 resolved. In order to better illustrate this, an example is in
122 order; the following example is from the gdb testsuite.
124 We start the program shmain.
126 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
129 We place two breakpoints, one on shr1 and the other on main.
132 Breakpoint 1 at 0x100409d4
134 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
136 Examine the instruction (and the immediatly following instruction)
137 upon which the breakpoint was placed. Note that the PLT entry
138 for shr1 contains zeros.
140 (gdb) x/2i 0x100409d4
141 0x100409d4 <shr1>: .long 0x0
142 0x100409d8 <shr1+4>: .long 0x0
147 Starting program: gdb.base/shmain
148 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
150 Breakpoint 2, main ()
151 at gdb.base/shmain.c:44
154 Examine the PLT again. Note that the loading of the shared
155 library has initialized the PLT to code which loads a constant
156 (which I think is an index into the GOT) into r11 and then
157 branchs a short distance to the code which actually does the
160 (gdb) x/2i 0x100409d4
161 0x100409d4 <shr1>: li r11,4
162 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
166 Breakpoint 1, shr1 (x=1)
167 at gdb.base/shr1.c:19
170 Now we've hit the breakpoint at shr1. (The breakpoint was
171 reset from the PLT entry to the actual shr1 function after the
172 shared library was loaded.) Note that the PLT entry has been
173 resolved to contain a branch that takes us directly to shr1.
174 (The real one, not the PLT entry.)
176 (gdb) x/2i 0x100409d4
177 0x100409d4 <shr1>: b 0xffaf76c <shr1>
178 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
180 The thing to note here is that the PLT entry for shr1 has been
183 Now the problem should be obvious. GDB places a breakpoint (a
184 trap instruction) on the zero value of the PLT entry for shr1.
185 Later on, after the shared library had been loaded and the PLT
186 initialized, GDB gets a signal indicating this fact and attempts
187 (as it always does when it stops) to remove all the breakpoints.
189 The breakpoint removal was causing the former contents (a zero
190 word) to be written back to the now initialized PLT entry thus
191 destroying a portion of the initialization that had occurred only a
192 short time ago. When execution continued, the zero word would be
193 executed as an instruction an illegal instruction trap was
194 generated instead. (0 is not a legal instruction.)
196 The fix for this problem was fairly straightforward. The function
197 memory_remove_breakpoint from mem-break.c was copied to this file,
198 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
199 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
202 The differences between ppc_linux_memory_remove_breakpoint () and
203 memory_remove_breakpoint () are minor. All that the former does
204 that the latter does not is check to make sure that the breakpoint
205 location actually contains a breakpoint (trap instruction) prior
206 to attempting to write back the old contents. If it does contain
207 a trap instruction, we allow the old contents to be written back.
208 Otherwise, we silently do nothing.
210 The big question is whether memory_remove_breakpoint () should be
211 changed to have the same functionality. The downside is that more
212 traffic is generated for remote targets since we'll have an extra
213 fetch of a memory word each time a breakpoint is removed.
215 For the time being, we'll leave this self-modifying-code-friendly
216 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
217 else in the event that some other platform has similar needs with
218 regard to removing breakpoints in some potentially self modifying
221 ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
222 struct bp_target_info *bp_tgt)
224 CORE_ADDR addr = bp_tgt->reqstd_address;
225 const unsigned char *bp;
228 gdb_byte old_contents[BREAKPOINT_MAX];
230 /* Determine appropriate breakpoint contents and size for this address. */
231 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
233 /* Make sure we see the memory breakpoints. */
234 scoped_restore restore_memory
235 = make_scoped_restore_show_memory_breakpoints (1);
236 val = target_read_memory (addr, old_contents, bplen);
238 /* If our breakpoint is no longer at the address, this means that the
239 program modified the code on us, so it is wrong to put back the
241 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
242 val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
247 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
248 than the 32 bit SYSV R4 ABI structure return convention - all
249 structures, no matter their size, are put in memory. Vectors,
250 which were added later, do get returned in a register though. */
252 static enum return_value_convention
253 ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
254 struct type *valtype, struct regcache *regcache,
255 gdb_byte *readbuf, const gdb_byte *writebuf)
257 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
258 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
259 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
260 && TYPE_VECTOR (valtype)))
261 return RETURN_VALUE_STRUCT_CONVENTION;
263 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
267 /* PLT stub in an executable. */
268 static const struct ppc_insn_pattern powerpc32_plt_stub[] =
270 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
271 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
272 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
273 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
277 /* PLT stubs in a shared library or PIE.
278 The first variant is used when the PLT entry is within +/-32k of
279 the GOT pointer (r30). */
280 static const struct ppc_insn_pattern powerpc32_plt_stub_so_1[] =
282 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
283 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
284 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
288 /* The second variant is used when the PLT entry is more than +/-32k
289 from the GOT pointer (r30). */
290 static const struct ppc_insn_pattern powerpc32_plt_stub_so_2[] =
292 { 0xffff0000, 0x3d7e0000, 0 }, /* addis r11, r30, xxxx */
293 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
294 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
295 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
299 /* The max number of insns we check using ppc_insns_match_pattern. */
300 #define POWERPC32_PLT_CHECK_LEN (ARRAY_SIZE (powerpc32_plt_stub) - 1)
302 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
303 section. For secure PLT, stub is in .text and we need to check
304 instruction patterns. */
307 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
309 struct bound_minimal_symbol sym;
311 /* Check whether PC is in the dynamic linker. This also checks
312 whether it is in the .plt section, used by non-PIC executables. */
313 if (svr4_in_dynsym_resolve_code (pc))
316 /* Check if we are in the resolver. */
317 sym = lookup_minimal_symbol_by_pc (pc);
318 if (sym.minsym != NULL
319 && (strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0
320 || strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym),
321 "__glink_PLTresolve") == 0))
327 /* Follow PLT stub to actual routine.
329 When the execution direction is EXEC_REVERSE, scan backward to
330 check whether we are in the middle of a PLT stub. Currently,
331 we only look-behind at most 4 instructions (the max length of a PLT
335 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
337 unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
338 struct gdbarch *gdbarch = get_frame_arch (frame);
339 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
340 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
341 CORE_ADDR target = 0;
345 /* When reverse-debugging, scan backward to check whether we are
346 in the middle of trampoline code. */
347 if (execution_direction == EXEC_REVERSE)
348 scan_limit = 4; /* At most 4 instructions. */
350 for (i = 0; i < scan_limit; i++)
352 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
354 /* Calculate PLT entry address from
356 lwz r11, xxxx(r11). */
357 target = ((ppc_insn_d_field (insnbuf[0]) << 16)
358 + ppc_insn_d_field (insnbuf[1]));
360 else if (i < ARRAY_SIZE (powerpc32_plt_stub_so_1) - 1
361 && ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_1,
364 /* Calculate PLT entry address from
365 lwz r11, xxxx(r30). */
366 target = (ppc_insn_d_field (insnbuf[0])
367 + get_frame_register_unsigned (frame,
368 tdep->ppc_gp0_regnum + 30));
370 else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_2,
373 /* Calculate PLT entry address from
375 lwz r11, xxxx(r11). */
376 target = ((ppc_insn_d_field (insnbuf[0]) << 16)
377 + ppc_insn_d_field (insnbuf[1])
378 + get_frame_register_unsigned (frame,
379 tdep->ppc_gp0_regnum + 30));
383 /* Scan backward one more instruction if it doesn't match. */
388 target = read_memory_unsigned_integer (target, 4, byte_order);
395 /* Wrappers to handle Linux-only registers. */
398 ppc_linux_supply_gregset (const struct regset *regset,
399 struct regcache *regcache,
400 int regnum, const void *gregs, size_t len)
402 const struct ppc_reg_offsets *offsets
403 = (const struct ppc_reg_offsets *) regset->regmap;
405 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
407 if (ppc_linux_trap_reg_p (regcache->arch ()))
409 /* "orig_r3" is stored 2 slots after "pc". */
410 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
411 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, (const gdb_byte *) gregs,
412 offsets->pc_offset + 2 * offsets->gpr_size,
415 /* "trap" is stored 8 slots after "pc". */
416 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
417 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, (const gdb_byte *) gregs,
418 offsets->pc_offset + 8 * offsets->gpr_size,
424 ppc_linux_collect_gregset (const struct regset *regset,
425 const struct regcache *regcache,
426 int regnum, void *gregs, size_t len)
428 const struct ppc_reg_offsets *offsets
429 = (const struct ppc_reg_offsets *) regset->regmap;
431 /* Clear areas in the linux gregset not written elsewhere. */
433 memset (gregs, 0, len);
435 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
437 if (ppc_linux_trap_reg_p (regcache->arch ()))
439 /* "orig_r3" is stored 2 slots after "pc". */
440 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
441 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, (gdb_byte *) gregs,
442 offsets->pc_offset + 2 * offsets->gpr_size,
445 /* "trap" is stored 8 slots after "pc". */
446 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
447 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, (gdb_byte *) gregs,
448 offsets->pc_offset + 8 * offsets->gpr_size,
453 /* Regset descriptions. */
454 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
456 /* General-purpose registers. */
457 /* .r0_offset = */ 0,
460 /* .pc_offset = */ 128,
461 /* .ps_offset = */ 132,
462 /* .cr_offset = */ 152,
463 /* .lr_offset = */ 144,
464 /* .ctr_offset = */ 140,
465 /* .xer_offset = */ 148,
466 /* .mq_offset = */ 156,
468 /* Floating-point registers. */
469 /* .f0_offset = */ 0,
470 /* .fpscr_offset = */ 256,
471 /* .fpscr_size = */ 8
474 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
476 /* General-purpose registers. */
477 /* .r0_offset = */ 0,
480 /* .pc_offset = */ 256,
481 /* .ps_offset = */ 264,
482 /* .cr_offset = */ 304,
483 /* .lr_offset = */ 288,
484 /* .ctr_offset = */ 280,
485 /* .xer_offset = */ 296,
486 /* .mq_offset = */ 312,
488 /* Floating-point registers. */
489 /* .f0_offset = */ 0,
490 /* .fpscr_offset = */ 256,
491 /* .fpscr_size = */ 8
494 static const struct regset ppc32_linux_gregset = {
495 &ppc32_linux_reg_offsets,
496 ppc_linux_supply_gregset,
497 ppc_linux_collect_gregset
500 static const struct regset ppc64_linux_gregset = {
501 &ppc64_linux_reg_offsets,
502 ppc_linux_supply_gregset,
503 ppc_linux_collect_gregset
506 static const struct regset ppc32_linux_fpregset = {
507 &ppc32_linux_reg_offsets,
512 static const struct regcache_map_entry ppc32_le_linux_vrregmap[] =
514 { 32, PPC_VR0_REGNUM, 16 },
515 { 1, PPC_VSCR_REGNUM, 4 },
516 { 1, REGCACHE_MAP_SKIP, 12 },
517 { 1, PPC_VRSAVE_REGNUM, 4 },
518 { 1, REGCACHE_MAP_SKIP, 12 },
522 static const struct regcache_map_entry ppc32_be_linux_vrregmap[] =
524 { 32, PPC_VR0_REGNUM, 16 },
525 { 1, REGCACHE_MAP_SKIP, 12},
526 { 1, PPC_VSCR_REGNUM, 4 },
527 { 1, PPC_VRSAVE_REGNUM, 4 },
528 { 1, REGCACHE_MAP_SKIP, 12 },
532 static const struct regset ppc32_le_linux_vrregset = {
533 ppc32_le_linux_vrregmap,
534 regcache_supply_regset,
535 regcache_collect_regset
538 static const struct regset ppc32_be_linux_vrregset = {
539 ppc32_be_linux_vrregmap,
540 regcache_supply_regset,
541 regcache_collect_regset
544 static const struct regcache_map_entry ppc32_linux_vsxregmap[] =
546 { 32, PPC_VSR0_UPPER_REGNUM, 8 },
550 static const struct regset ppc32_linux_vsxregset = {
551 ppc32_linux_vsxregmap,
552 regcache_supply_regset,
553 regcache_collect_regset
556 /* Program Priorty Register regmap. */
558 static const struct regcache_map_entry ppc32_regmap_ppr[] =
560 { 1, PPC_PPR_REGNUM, 8 },
564 /* Program Priorty Register regset. */
566 const struct regset ppc32_linux_pprregset = {
568 regcache_supply_regset,
569 regcache_collect_regset
572 /* Data Stream Control Register regmap. */
574 static const struct regcache_map_entry ppc32_regmap_dscr[] =
576 { 1, PPC_DSCR_REGNUM, 8 },
580 /* Data Stream Control Register regset. */
582 const struct regset ppc32_linux_dscrregset = {
584 regcache_supply_regset,
585 regcache_collect_regset
588 /* Target Address Register regmap. */
590 static const struct regcache_map_entry ppc32_regmap_tar[] =
592 { 1, PPC_TAR_REGNUM, 8 },
596 /* Target Address Register regset. */
598 const struct regset ppc32_linux_tarregset = {
600 regcache_supply_regset,
601 regcache_collect_regset
604 /* Event-Based Branching regmap. */
606 static const struct regcache_map_entry ppc32_regmap_ebb[] =
608 { 1, PPC_EBBRR_REGNUM, 8 },
609 { 1, PPC_EBBHR_REGNUM, 8 },
610 { 1, PPC_BESCR_REGNUM, 8 },
614 /* Event-Based Branching regset. */
616 const struct regset ppc32_linux_ebbregset = {
618 regcache_supply_regset,
619 regcache_collect_regset
622 /* Performance Monitoring Unit regmap. */
624 static const struct regcache_map_entry ppc32_regmap_pmu[] =
626 { 1, PPC_SIAR_REGNUM, 8 },
627 { 1, PPC_SDAR_REGNUM, 8 },
628 { 1, PPC_SIER_REGNUM, 8 },
629 { 1, PPC_MMCR2_REGNUM, 8 },
630 { 1, PPC_MMCR0_REGNUM, 8 },
634 /* Performance Monitoring Unit regset. */
636 const struct regset ppc32_linux_pmuregset = {
638 regcache_supply_regset,
639 regcache_collect_regset
642 /* Hardware Transactional Memory special-purpose register regmap. */
644 static const struct regcache_map_entry ppc32_regmap_tm_spr[] =
646 { 1, PPC_TFHAR_REGNUM, 8 },
647 { 1, PPC_TEXASR_REGNUM, 8 },
648 { 1, PPC_TFIAR_REGNUM, 8 },
652 /* Hardware Transactional Memory special-purpose register regset. */
654 const struct regset ppc32_linux_tm_sprregset = {
656 regcache_supply_regset,
657 regcache_collect_regset
660 /* Regmaps for the Hardware Transactional Memory checkpointed
661 general-purpose regsets for 32-bit, 64-bit big-endian, and 64-bit
662 little endian targets. The ptrace and core file buffers for 64-bit
663 targets use 8-byte fields for the 4-byte registers, and the
664 position of the register in the fields depends on the endianess.
665 The 32-bit regmap is the same for both endian types because the
666 fields are all 4-byte long.
668 The layout of checkpointed GPR regset is the same as a regular
669 struct pt_regs, but we skip all registers that are not actually
670 checkpointed by the processor (e.g. msr, nip), except when
671 generating a core file. The 64-bit regset is 48 * 8 bytes long.
672 In some 64-bit kernels, the regset for a 32-bit inferior has the
673 same length, but all the registers are squeezed in the first half
674 (48 * 4 bytes). The pt_regs struct calls the regular cr ccr, but
675 we use ccr for "checkpointed condition register". Note that CR
676 (condition register) field 0 is not checkpointed, but the kernel
677 returns all 4 bytes. The skipped registers should not be touched
678 when writing the regset to the inferior (with
679 PTRACE_SETREGSET). */
681 static const struct regcache_map_entry ppc32_regmap_cgpr[] =
683 { 32, PPC_CR0_REGNUM, 4 },
684 { 3, REGCACHE_MAP_SKIP, 4 }, /* nip, msr, orig_gpr3. */
685 { 1, PPC_CCTR_REGNUM, 4 },
686 { 1, PPC_CLR_REGNUM, 4 },
687 { 1, PPC_CXER_REGNUM, 4 },
688 { 1, PPC_CCR_REGNUM, 4 },
689 { 9, REGCACHE_MAP_SKIP, 4 }, /* All the rest. */
693 static const struct regcache_map_entry ppc64_le_regmap_cgpr[] =
695 { 32, PPC_CR0_REGNUM, 8 },
696 { 3, REGCACHE_MAP_SKIP, 8 },
697 { 1, PPC_CCTR_REGNUM, 8 },
698 { 1, PPC_CLR_REGNUM, 8 },
699 { 1, PPC_CXER_REGNUM, 4 },
700 { 1, REGCACHE_MAP_SKIP, 4 }, /* CXER padding. */
701 { 1, PPC_CCR_REGNUM, 4 },
702 { 1, REGCACHE_MAP_SKIP, 4}, /* CCR padding. */
703 { 9, REGCACHE_MAP_SKIP, 8},
707 static const struct regcache_map_entry ppc64_be_regmap_cgpr[] =
709 { 32, PPC_CR0_REGNUM, 8 },
710 { 3, REGCACHE_MAP_SKIP, 8 },
711 { 1, PPC_CCTR_REGNUM, 8 },
712 { 1, PPC_CLR_REGNUM, 8 },
713 { 1, REGCACHE_MAP_SKIP, 4}, /* CXER padding. */
714 { 1, PPC_CXER_REGNUM, 4 },
715 { 1, REGCACHE_MAP_SKIP, 4}, /* CCR padding. */
716 { 1, PPC_CCR_REGNUM, 4 },
717 { 9, REGCACHE_MAP_SKIP, 8},
721 /* Regsets for the Hardware Transactional Memory checkpointed
722 general-purpose registers for 32-bit, 64-bit big-endian, and 64-bit
723 little endian targets.
725 Some 64-bit kernels generate a checkpointed gpr note section with
726 48*8 bytes for a 32-bit thread, of which only 48*4 are actually
727 used, so we set the variable size flag in the corresponding regset
728 to accept this case. */
730 static const struct regset ppc32_linux_cgprregset = {
732 regcache_supply_regset,
733 regcache_collect_regset,
737 static const struct regset ppc64_be_linux_cgprregset = {
738 ppc64_be_regmap_cgpr,
739 regcache_supply_regset,
740 regcache_collect_regset
743 static const struct regset ppc64_le_linux_cgprregset = {
744 ppc64_le_regmap_cgpr,
745 regcache_supply_regset,
746 regcache_collect_regset
749 /* Hardware Transactional Memory checkpointed floating-point regmap. */
751 static const struct regcache_map_entry ppc32_regmap_cfpr[] =
753 { 32, PPC_CF0_REGNUM, 8 },
754 { 1, PPC_CFPSCR_REGNUM, 8 },
758 /* Hardware Transactional Memory checkpointed floating-point regset. */
760 const struct regset ppc32_linux_cfprregset = {
762 regcache_supply_regset,
763 regcache_collect_regset
766 /* Regmaps for the Hardware Transactional Memory checkpointed vector
767 regsets, for big and little endian targets. The position of the
768 4-byte VSCR in its 16-byte field depends on the endianess. */
770 static const struct regcache_map_entry ppc32_le_regmap_cvmx[] =
772 { 32, PPC_CVR0_REGNUM, 16 },
773 { 1, PPC_CVSCR_REGNUM, 4 },
774 { 1, REGCACHE_MAP_SKIP, 12 },
775 { 1, PPC_CVRSAVE_REGNUM, 4 },
776 { 1, REGCACHE_MAP_SKIP, 12 },
780 static const struct regcache_map_entry ppc32_be_regmap_cvmx[] =
782 { 32, PPC_CVR0_REGNUM, 16 },
783 { 1, REGCACHE_MAP_SKIP, 12 },
784 { 1, PPC_CVSCR_REGNUM, 4 },
785 { 1, PPC_CVRSAVE_REGNUM, 4 },
786 { 1, REGCACHE_MAP_SKIP, 12},
790 /* Hardware Transactional Memory checkpointed vector regsets, for little
791 and big endian targets. */
793 static const struct regset ppc32_le_linux_cvmxregset = {
794 ppc32_le_regmap_cvmx,
795 regcache_supply_regset,
796 regcache_collect_regset
799 static const struct regset ppc32_be_linux_cvmxregset = {
800 ppc32_be_regmap_cvmx,
801 regcache_supply_regset,
802 regcache_collect_regset
805 /* Hardware Transactional Memory checkpointed vector-scalar regmap. */
807 static const struct regcache_map_entry ppc32_regmap_cvsx[] =
809 { 32, PPC_CVSR0_UPPER_REGNUM, 8 },
813 /* Hardware Transactional Memory checkpointed vector-scalar regset. */
815 const struct regset ppc32_linux_cvsxregset = {
817 regcache_supply_regset,
818 regcache_collect_regset
821 /* Hardware Transactional Memory checkpointed Program Priority Register
824 static const struct regcache_map_entry ppc32_regmap_cppr[] =
826 { 1, PPC_CPPR_REGNUM, 8 },
830 /* Hardware Transactional Memory checkpointed Program Priority Register
833 const struct regset ppc32_linux_cpprregset = {
835 regcache_supply_regset,
836 regcache_collect_regset
839 /* Hardware Transactional Memory checkpointed Data Stream Control
842 static const struct regcache_map_entry ppc32_regmap_cdscr[] =
844 { 1, PPC_CDSCR_REGNUM, 8 },
848 /* Hardware Transactional Memory checkpointed Data Stream Control
851 const struct regset ppc32_linux_cdscrregset = {
853 regcache_supply_regset,
854 regcache_collect_regset
857 /* Hardware Transactional Memory checkpointed Target Address Register
860 static const struct regcache_map_entry ppc32_regmap_ctar[] =
862 { 1, PPC_CTAR_REGNUM, 8 },
866 /* Hardware Transactional Memory checkpointed Target Address Register
869 const struct regset ppc32_linux_ctarregset = {
871 regcache_supply_regset,
872 regcache_collect_regset
875 const struct regset *
876 ppc_linux_gregset (int wordsize)
878 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
881 const struct regset *
882 ppc_linux_fpregset (void)
884 return &ppc32_linux_fpregset;
887 const struct regset *
888 ppc_linux_vrregset (struct gdbarch *gdbarch)
890 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
891 return &ppc32_be_linux_vrregset;
893 return &ppc32_le_linux_vrregset;
896 const struct regset *
897 ppc_linux_vsxregset (void)
899 return &ppc32_linux_vsxregset;
902 const struct regset *
903 ppc_linux_cgprregset (struct gdbarch *gdbarch)
905 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
907 if (tdep->wordsize == 4)
909 return &ppc32_linux_cgprregset;
913 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
914 return &ppc64_be_linux_cgprregset;
916 return &ppc64_le_linux_cgprregset;
920 const struct regset *
921 ppc_linux_cvmxregset (struct gdbarch *gdbarch)
923 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
924 return &ppc32_be_linux_cvmxregset;
926 return &ppc32_le_linux_cvmxregset;
929 /* Collect function used to generate the core note for the
930 checkpointed GPR regset. Here, we don't want to skip the
931 "checkpointed" NIP and MSR, so that the note section we generate is
932 similar to the one generated by the kernel. To avoid having to
933 define additional registers in GDB which are not actually
934 checkpointed in the architecture, we copy TFHAR to the checkpointed
935 NIP slot, which is what the kernel does, and copy the regular MSR
936 to the checkpointed MSR slot, which will have a similar value in
940 ppc_linux_collect_core_cpgrregset (const struct regset *regset,
941 const struct regcache *regcache,
942 int regnum, void *buf, size_t len)
944 struct gdbarch *gdbarch = regcache->arch ();
945 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
947 const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
949 /* We collect the checkpointed GPRs already defined in the regular
950 regmap, then overlay TFHAR/MSR on the checkpointed NIP/MSR
952 cgprregset->collect_regset (cgprregset, regcache, regnum, buf, len);
954 /* Check that we are collecting all the registers, which should be
955 the case when generating a core file. */
959 /* PT_NIP and PT_MSR are 32 and 33 for powerpc. Don't redefine
960 these symbols since this file can run on clients in other
961 architectures where they can already be defined to other
965 /* Check that our buffer is long enough to hold two slots at
966 pt_offset * wordsize, one for NIP and one for MSR. */
967 gdb_assert ((pt_offset + 2) * tdep->wordsize <= len);
969 /* TFHAR is 8 bytes wide, but the NIP slot for a 32-bit thread is
970 4-bytes long. We use raw_collect_integer which handles
971 differences in the sizes for the source and destination buffers
972 for both endian modes. */
973 (regcache->raw_collect_integer
974 (PPC_TFHAR_REGNUM, ((gdb_byte *) buf) + pt_offset * tdep->wordsize,
975 tdep->wordsize, false));
979 (regcache->raw_collect_integer
980 (PPC_MSR_REGNUM, ((gdb_byte *) buf) + pt_offset * tdep->wordsize,
981 tdep->wordsize, false));
984 /* Iterate over supported core file register note sections. */
987 ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
988 iterate_over_regset_sections_cb *cb,
990 const struct regcache *regcache)
992 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
993 int have_altivec = tdep->ppc_vr0_regnum != -1;
994 int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
995 int have_ppr = tdep->ppc_ppr_regnum != -1;
996 int have_dscr = tdep->ppc_dscr_regnum != -1;
997 int have_tar = tdep->ppc_tar_regnum != -1;
999 if (tdep->wordsize == 4)
1000 cb (".reg", 48 * 4, 48 * 4, &ppc32_linux_gregset, NULL, cb_data);
1002 cb (".reg", 48 * 8, 48 * 8, &ppc64_linux_gregset, NULL, cb_data);
1004 cb (".reg2", 264, 264, &ppc32_linux_fpregset, NULL, cb_data);
1008 const struct regset *vrregset = ppc_linux_vrregset (gdbarch);
1009 cb (".reg-ppc-vmx", PPC_LINUX_SIZEOF_VRREGSET, PPC_LINUX_SIZEOF_VRREGSET,
1010 vrregset, "ppc Altivec", cb_data);
1014 cb (".reg-ppc-vsx", PPC_LINUX_SIZEOF_VSXREGSET, PPC_LINUX_SIZEOF_VSXREGSET,
1015 &ppc32_linux_vsxregset, "POWER7 VSX", cb_data);
1018 cb (".reg-ppc-ppr", PPC_LINUX_SIZEOF_PPRREGSET,
1019 PPC_LINUX_SIZEOF_PPRREGSET,
1020 &ppc32_linux_pprregset, "Priority Program Register", cb_data);
1023 cb (".reg-ppc-dscr", PPC_LINUX_SIZEOF_DSCRREGSET,
1024 PPC_LINUX_SIZEOF_DSCRREGSET,
1025 &ppc32_linux_dscrregset, "Data Stream Control Register",
1029 cb (".reg-ppc-tar", PPC_LINUX_SIZEOF_TARREGSET,
1030 PPC_LINUX_SIZEOF_TARREGSET,
1031 &ppc32_linux_tarregset, "Target Address Register", cb_data);
1033 /* EBB registers are unavailable when ptrace returns ENODATA. Check
1034 availability when generating a core file (regcache != NULL). */
1036 if (regcache == NULL
1037 || REG_VALID == regcache->get_register_status (PPC_BESCR_REGNUM))
1038 cb (".reg-ppc-ebb", PPC_LINUX_SIZEOF_EBBREGSET,
1039 PPC_LINUX_SIZEOF_EBBREGSET,
1040 &ppc32_linux_ebbregset, "Event-based Branching Registers",
1043 if (tdep->ppc_mmcr0_regnum != -1)
1044 cb (".reg-ppc-pmu", PPC_LINUX_SIZEOF_PMUREGSET,
1045 PPC_LINUX_SIZEOF_PMUREGSET,
1046 &ppc32_linux_pmuregset, "Performance Monitor Registers",
1049 if (tdep->have_htm_spr)
1050 cb (".reg-ppc-tm-spr", PPC_LINUX_SIZEOF_TM_SPRREGSET,
1051 PPC_LINUX_SIZEOF_TM_SPRREGSET,
1052 &ppc32_linux_tm_sprregset,
1053 "Hardware Transactional Memory Special Purpose Registers",
1056 /* Checkpointed registers can be unavailable, don't call back if
1057 we are generating a core file. */
1059 if (tdep->have_htm_core)
1061 /* Only generate the checkpointed GPR core note if we also have
1062 access to the HTM SPRs, because we need TFHAR to fill the
1063 "checkpointed" NIP slot. We can read a core file without it
1064 since GDB is not aware of this NIP as a visible register. */
1065 if (regcache == NULL ||
1066 (REG_VALID == regcache->get_register_status (PPC_CR0_REGNUM)
1067 && tdep->have_htm_spr))
1069 int cgpr_size = (tdep->wordsize == 4?
1070 PPC32_LINUX_SIZEOF_CGPRREGSET
1071 : PPC64_LINUX_SIZEOF_CGPRREGSET);
1073 const struct regset *cgprregset =
1074 ppc_linux_cgprregset (gdbarch);
1076 if (regcache != NULL)
1078 struct regset core_cgprregset = *cgprregset;
1080 core_cgprregset.collect_regset
1081 = ppc_linux_collect_core_cpgrregset;
1083 cb (".reg-ppc-tm-cgpr",
1084 cgpr_size, cgpr_size,
1086 "Checkpointed General Purpose Registers", cb_data);
1090 cb (".reg-ppc-tm-cgpr",
1091 cgpr_size, cgpr_size,
1093 "Checkpointed General Purpose Registers", cb_data);
1098 if (tdep->have_htm_fpu)
1100 if (regcache == NULL ||
1101 REG_VALID == regcache->get_register_status (PPC_CF0_REGNUM))
1102 cb (".reg-ppc-tm-cfpr", PPC_LINUX_SIZEOF_CFPRREGSET,
1103 PPC_LINUX_SIZEOF_CFPRREGSET,
1104 &ppc32_linux_cfprregset,
1105 "Checkpointed Floating Point Registers", cb_data);
1108 if (tdep->have_htm_altivec)
1110 if (regcache == NULL ||
1111 REG_VALID == regcache->get_register_status (PPC_CVR0_REGNUM))
1113 const struct regset *cvmxregset =
1114 ppc_linux_cvmxregset (gdbarch);
1116 cb (".reg-ppc-tm-cvmx", PPC_LINUX_SIZEOF_CVMXREGSET,
1117 PPC_LINUX_SIZEOF_CVMXREGSET,
1119 "Checkpointed Altivec (VMX) Registers", cb_data);
1123 if (tdep->have_htm_vsx)
1125 if (regcache == NULL ||
1127 == regcache->get_register_status (PPC_CVSR0_UPPER_REGNUM)))
1128 cb (".reg-ppc-tm-cvsx", PPC_LINUX_SIZEOF_CVSXREGSET,
1129 PPC_LINUX_SIZEOF_CVSXREGSET,
1130 &ppc32_linux_cvsxregset,
1131 "Checkpointed VSX Registers", cb_data);
1134 if (tdep->ppc_cppr_regnum != -1)
1136 if (regcache == NULL ||
1137 REG_VALID == regcache->get_register_status (PPC_CPPR_REGNUM))
1138 cb (".reg-ppc-tm-cppr", PPC_LINUX_SIZEOF_CPPRREGSET,
1139 PPC_LINUX_SIZEOF_CPPRREGSET,
1140 &ppc32_linux_cpprregset,
1141 "Checkpointed Priority Program Register", cb_data);
1144 if (tdep->ppc_cdscr_regnum != -1)
1146 if (regcache == NULL ||
1147 REG_VALID == regcache->get_register_status (PPC_CDSCR_REGNUM))
1148 cb (".reg-ppc-tm-cdscr", PPC_LINUX_SIZEOF_CDSCRREGSET,
1149 PPC_LINUX_SIZEOF_CDSCRREGSET,
1150 &ppc32_linux_cdscrregset,
1151 "Checkpointed Data Stream Control Register", cb_data);
1154 if (tdep->ppc_ctar_regnum)
1156 if ( regcache == NULL ||
1157 REG_VALID == regcache->get_register_status (PPC_CTAR_REGNUM))
1158 cb (".reg-ppc-tm-ctar", PPC_LINUX_SIZEOF_CTARREGSET,
1159 PPC_LINUX_SIZEOF_CTARREGSET,
1160 &ppc32_linux_ctarregset,
1161 "Checkpointed Target Address Register", cb_data);
1166 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
1167 struct trad_frame_cache *this_cache,
1168 CORE_ADDR func, LONGEST offset,
1176 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1177 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1178 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1180 base = get_frame_register_unsigned (this_frame,
1181 gdbarch_sp_regnum (gdbarch));
1182 if (bias > 0 && get_frame_pc (this_frame) != func)
1183 /* See below, some signal trampolines increment the stack as their
1184 first instruction, need to compensate for that. */
1187 /* Find the address of the register buffer pointer. */
1188 regs = base + offset;
1189 /* Use that to find the address of the corresponding register
1191 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
1192 fpregs = gpregs + 48 * tdep->wordsize;
1194 /* General purpose. */
1195 for (i = 0; i < 32; i++)
1197 int regnum = i + tdep->ppc_gp0_regnum;
1198 trad_frame_set_reg_addr (this_cache,
1199 regnum, gpregs + i * tdep->wordsize);
1201 trad_frame_set_reg_addr (this_cache,
1202 gdbarch_pc_regnum (gdbarch),
1203 gpregs + 32 * tdep->wordsize);
1204 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
1205 gpregs + 35 * tdep->wordsize);
1206 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
1207 gpregs + 36 * tdep->wordsize);
1208 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
1209 gpregs + 37 * tdep->wordsize);
1210 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
1211 gpregs + 38 * tdep->wordsize);
1213 if (ppc_linux_trap_reg_p (gdbarch))
1215 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
1216 gpregs + 34 * tdep->wordsize);
1217 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
1218 gpregs + 40 * tdep->wordsize);
1221 if (ppc_floating_point_unit_p (gdbarch))
1223 /* Floating point registers. */
1224 for (i = 0; i < 32; i++)
1226 int regnum = i + gdbarch_fp0_regnum (gdbarch);
1227 trad_frame_set_reg_addr (this_cache, regnum,
1228 fpregs + i * tdep->wordsize);
1230 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
1231 fpregs + 32 * tdep->wordsize);
1233 trad_frame_set_id (this_cache, frame_id_build (base, func));
1237 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
1238 struct frame_info *this_frame,
1239 struct trad_frame_cache *this_cache,
1242 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1243 0xd0 /* Offset to ucontext_t. */
1244 + 0x30 /* Offset to .reg. */,
1249 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
1250 struct frame_info *this_frame,
1251 struct trad_frame_cache *this_cache,
1254 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1255 0x80 /* Offset to ucontext_t. */
1256 + 0xe0 /* Offset to .reg. */,
1261 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
1262 struct frame_info *this_frame,
1263 struct trad_frame_cache *this_cache,
1266 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1267 0x40 /* Offset to ucontext_t. */
1268 + 0x1c /* Offset to .reg. */,
1273 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
1274 struct frame_info *this_frame,
1275 struct trad_frame_cache *this_cache,
1278 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1279 0x80 /* Offset to struct sigcontext. */
1280 + 0x38 /* Offset to .reg. */,
1284 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
1288 { 0x380000ac, ULONGEST_MAX }, /* li r0, 172 */
1289 { 0x44000002, ULONGEST_MAX }, /* sc */
1290 { TRAMP_SENTINEL_INSN },
1292 ppc32_linux_sigaction_cache_init
1294 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
1298 { 0x38210080, ULONGEST_MAX }, /* addi r1,r1,128 */
1299 { 0x380000ac, ULONGEST_MAX }, /* li r0, 172 */
1300 { 0x44000002, ULONGEST_MAX }, /* sc */
1301 { TRAMP_SENTINEL_INSN },
1303 ppc64_linux_sigaction_cache_init
1305 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
1309 { 0x38000077, ULONGEST_MAX }, /* li r0,119 */
1310 { 0x44000002, ULONGEST_MAX }, /* sc */
1311 { TRAMP_SENTINEL_INSN },
1313 ppc32_linux_sighandler_cache_init
1315 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
1319 { 0x38210080, ULONGEST_MAX }, /* addi r1,r1,128 */
1320 { 0x38000077, ULONGEST_MAX }, /* li r0,119 */
1321 { 0x44000002, ULONGEST_MAX }, /* sc */
1322 { TRAMP_SENTINEL_INSN },
1324 ppc64_linux_sighandler_cache_init
1327 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
1329 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
1331 /* If we do not have a target description with registers, then
1332 the special registers will not be included in the register set. */
1333 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1336 /* If we do, then it is safe to check the size. */
1337 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
1338 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
1341 /* Return the current system call's number present in the
1342 r0 register. When the function fails, it returns -1. */
1344 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
1345 thread_info *thread)
1347 struct regcache *regcache = get_thread_regcache (thread);
1348 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1349 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1351 /* Make sure we're in a 32- or 64-bit machine */
1352 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
1354 /* The content of a register */
1355 gdb::byte_vector buf (tdep->wordsize);
1357 /* Getting the system call number from the register.
1358 When dealing with PowerPC architecture, this information
1359 is stored at 0th register. */
1360 regcache->cooked_read (tdep->ppc_gp0_regnum, buf.data ());
1362 return extract_signed_integer (buf.data (), tdep->wordsize, byte_order);
1365 /* PPC process record-replay */
1367 static struct linux_record_tdep ppc_linux_record_tdep;
1368 static struct linux_record_tdep ppc64_linux_record_tdep;
1370 /* ppc_canonicalize_syscall maps from the native PowerPC Linux set of
1371 syscall ids into a canonical set of syscall ids used by process
1372 record. (See arch/powerpc/include/uapi/asm/unistd.h in kernel tree.)
1373 Return -1 if this system call is not supported by process record.
1374 Otherwise, return the syscall number for preocess reocrd of given
1377 static enum gdb_syscall
1378 ppc_canonicalize_syscall (int syscall)
1384 else if (syscall >= 167 && syscall <= 190) /* Skip query_module 166 */
1385 result = syscall + 1;
1386 else if (syscall >= 192 && syscall <= 197) /* mmap2 */
1388 else if (syscall == 208) /* tkill */
1389 result = gdb_sys_tkill;
1390 else if (syscall >= 207 && syscall <= 220) /* gettid */
1391 result = syscall + 224 - 207;
1392 else if (syscall >= 234 && syscall <= 239) /* exit_group */
1393 result = syscall + 252 - 234;
1394 else if (syscall >= 240 && syscall <= 248) /* timer_create */
1395 result = syscall += 259 - 240;
1396 else if (syscall >= 250 && syscall <= 251) /* tgkill */
1397 result = syscall + 270 - 250;
1398 else if (syscall == 336)
1399 result = gdb_sys_recv;
1400 else if (syscall == 337)
1401 result = gdb_sys_recvfrom;
1402 else if (syscall == 342)
1403 result = gdb_sys_recvmsg;
1405 return (enum gdb_syscall) result;
1408 /* Record registers which might be clobbered during system call.
1409 Return 0 if successful. */
1412 ppc_linux_syscall_record (struct regcache *regcache)
1414 struct gdbarch *gdbarch = regcache->arch ();
1415 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1417 enum gdb_syscall syscall_gdb;
1420 regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum, &scnum);
1421 syscall_gdb = ppc_canonicalize_syscall (scnum);
1423 if (syscall_gdb < 0)
1425 printf_unfiltered (_("Process record and replay target doesn't "
1426 "support syscall number %d\n"), (int) scnum);
1430 if (syscall_gdb == gdb_sys_sigreturn
1431 || syscall_gdb == gdb_sys_rt_sigreturn)
1434 int regsets[] = { tdep->ppc_gp0_regnum,
1435 tdep->ppc_fp0_regnum,
1436 tdep->ppc_vr0_regnum,
1437 tdep->ppc_vsr0_upper_regnum };
1439 for (j = 0; j < 4; j++)
1441 if (regsets[j] == -1)
1443 for (i = 0; i < 32; i++)
1445 if (record_full_arch_list_add_reg (regcache, regsets[j] + i))
1450 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1452 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1454 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1456 if (record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum))
1462 if (tdep->wordsize == 8)
1463 ret = record_linux_system_call (syscall_gdb, regcache,
1464 &ppc64_linux_record_tdep);
1466 ret = record_linux_system_call (syscall_gdb, regcache,
1467 &ppc_linux_record_tdep);
1472 /* Record registers clobbered during syscall. */
1473 for (int i = 3; i <= 12; i++)
1475 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
1478 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + 0))
1480 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1482 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1484 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1490 /* Record registers which might be clobbered during signal handling.
1491 Return 0 if successful. */
1494 ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
1495 enum gdb_signal signal)
1497 /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c
1498 handle_rt_signal32 in arch/powerpc/kernel/signal_32.c
1499 arch/powerpc/include/asm/ptrace.h
1501 const int SIGNAL_FRAMESIZE = 128;
1502 const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
1504 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1507 for (i = 3; i <= 12; i++)
1509 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
1513 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1515 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1517 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1519 if (record_full_arch_list_add_reg (regcache, gdbarch_pc_regnum (gdbarch)))
1521 if (record_full_arch_list_add_reg (regcache, gdbarch_sp_regnum (gdbarch)))
1524 /* Record the change in the stack.
1525 frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
1526 regcache_raw_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &sp);
1527 sp -= SIGNAL_FRAMESIZE;
1528 sp -= sizeof_rt_sigframe;
1530 if (record_full_arch_list_add_mem (sp, SIGNAL_FRAMESIZE + sizeof_rt_sigframe))
1533 if (record_full_arch_list_add_end ())
1540 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1542 struct gdbarch *gdbarch = regcache->arch ();
1544 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
1546 /* Set special TRAP register to -1 to prevent the kernel from
1547 messing with the PC we just installed, if we happen to be
1548 within an interrupted system call that the kernel wants to
1551 Note that after we return from the dummy call, the TRAP and
1552 ORIG_R3 registers will be automatically restored, and the
1553 kernel continues to restart the system call at this point. */
1554 if (ppc_linux_trap_reg_p (gdbarch))
1555 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
1559 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
1561 return startswith (bfd_section_name (abfd, asect), "SPU/");
1564 static const struct target_desc *
1565 ppc_linux_core_read_description (struct gdbarch *gdbarch,
1566 struct target_ops *target,
1569 struct ppc_linux_features features = ppc_linux_no_features;
1570 asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
1571 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
1572 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
1573 asection *section = bfd_get_section_by_name (abfd, ".reg");
1574 asection *ppr = bfd_get_section_by_name (abfd, ".reg-ppc-ppr");
1575 asection *dscr = bfd_get_section_by_name (abfd, ".reg-ppc-dscr");
1576 asection *tar = bfd_get_section_by_name (abfd, ".reg-ppc-tar");
1577 asection *pmu = bfd_get_section_by_name (abfd, ".reg-ppc-pmu");
1578 asection *htmspr = bfd_get_section_by_name (abfd, ".reg-ppc-tm-spr");
1583 switch (bfd_section_size (abfd, section))
1586 features.wordsize = 4;
1589 features.wordsize = 8;
1596 features.cell = true;
1599 features.altivec = true;
1602 features.vsx = true;
1606 if (target_auxv_search (target, AT_HWCAP, &hwcap) != 1)
1609 features.isa205 = ppc_linux_has_isa205 (hwcap);
1613 features.ppr_dscr = true;
1615 /* We don't require the EBB note section to be present in the
1616 core file to select isa207 because these registers could have
1617 been unavailable when the core file was created. They will
1618 be in the tdep but will show as unavailable. */
1621 features.isa207 = true;
1623 features.htm = true;
1627 return ppc_linux_match_description (features);
1631 /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
1632 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1635 ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
1637 elf_symbol_type *elf_sym = (elf_symbol_type *)sym;
1639 /* If the symbol is marked as having a local entry point, set a target
1640 flag in the msymbol. We currently only support local entry point
1641 offsets of 8 bytes, which is the only entry point offset ever used
1642 by current compilers. If/when other offsets are ever used, we will
1643 have to use additional target flag bits to store them. */
1644 switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other))
1649 MSYMBOL_TARGET_FLAG_1 (msym) = 1;
1654 /* Implementation of `gdbarch_skip_entrypoint', as defined in
1655 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1658 ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc)
1660 struct bound_minimal_symbol fun;
1661 int local_entry_offset = 0;
1663 fun = lookup_minimal_symbol_by_pc (pc);
1664 if (fun.minsym == NULL)
1667 /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
1668 offset values are encoded. */
1669 if (MSYMBOL_TARGET_FLAG_1 (fun.minsym))
1670 local_entry_offset = 8;
1672 if (BMSYMBOL_VALUE_ADDRESS (fun) <= pc
1673 && pc < BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset)
1674 return BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset;
1679 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1683 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
1685 return (*s == 'i' /* Literal number. */
1686 || (isdigit (*s) && s[1] == '('
1687 && isdigit (s[2])) /* Displacement. */
1688 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
1689 || isdigit (*s)); /* Register value. */
1692 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
1696 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
1697 struct stap_parse_info *p)
1699 if (isdigit (*p->arg))
1701 /* This temporary pointer is needed because we have to do a lookahead.
1702 We could be dealing with a register displacement, and in such case
1703 we would not need to do anything. */
1704 const char *s = p->arg;
1709 while (isdigit (*s))
1714 /* It is a register displacement indeed. Returning 0 means we are
1715 deferring the treatment of this case to the generic parser. */
1720 regname = (char *) alloca (len + 2);
1723 strncpy (regname + 1, p->arg, len);
1725 regname[len] = '\0';
1727 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
1728 error (_("Invalid register name `%s' on expression `%s'."),
1729 regname, p->saved_arg);
1731 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
1734 write_exp_string (&p->pstate, str);
1735 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
1741 /* All the other tokens should be handled correctly by the generic
1749 /* Cell/B.E. active SPE context tracking support. */
1751 static struct objfile *spe_context_objfile = NULL;
1752 static CORE_ADDR spe_context_lm_addr = 0;
1753 static CORE_ADDR spe_context_offset = 0;
1755 static ptid_t spe_context_cache_ptid;
1756 static CORE_ADDR spe_context_cache_address;
1758 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
1759 to track whether we've loaded a version of libspe2 (as static or dynamic
1760 library) that provides the __spe_current_active_context variable. */
1762 ppc_linux_spe_context_lookup (struct objfile *objfile)
1764 struct bound_minimal_symbol sym;
1768 spe_context_objfile = NULL;
1769 spe_context_lm_addr = 0;
1770 spe_context_offset = 0;
1771 spe_context_cache_ptid = minus_one_ptid;
1772 spe_context_cache_address = 0;
1776 sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
1779 spe_context_objfile = objfile;
1780 spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
1781 spe_context_offset = MSYMBOL_VALUE_RAW_ADDRESS (sym.minsym);
1782 spe_context_cache_ptid = minus_one_ptid;
1783 spe_context_cache_address = 0;
1789 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
1791 struct objfile *objfile;
1793 ppc_linux_spe_context_lookup (NULL);
1794 ALL_OBJFILES (objfile)
1795 ppc_linux_spe_context_lookup (objfile);
1799 ppc_linux_spe_context_solib_loaded (struct so_list *so)
1801 if (strstr (so->so_original_name, "/libspe") != NULL)
1803 solib_read_symbols (so, 0);
1804 ppc_linux_spe_context_lookup (so->objfile);
1809 ppc_linux_spe_context_solib_unloaded (struct so_list *so)
1811 if (so->objfile == spe_context_objfile)
1812 ppc_linux_spe_context_lookup (NULL);
1815 /* Retrieve contents of the N'th element in the current thread's
1816 linked SPE context list into ID and NPC. Return the address of
1817 said context element, or 0 if not found. */
1819 ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
1820 int n, int *id, unsigned int *npc)
1822 CORE_ADDR spe_context = 0;
1826 /* Quick exit if we have not found __spe_current_active_context. */
1827 if (!spe_context_objfile)
1830 /* Look up cached address of thread-local variable. */
1831 if (spe_context_cache_ptid != inferior_ptid)
1833 struct target_ops *target = current_top_target ();
1837 /* We do not call target_translate_tls_address here, because
1838 svr4_fetch_objfile_link_map may invalidate the frame chain,
1839 which must not do while inside a frame sniffer.
1841 Instead, we have cached the lm_addr value, and use that to
1842 directly call the target's to_get_thread_local_address. */
1843 spe_context_cache_address
1844 = target->get_thread_local_address (inferior_ptid,
1845 spe_context_lm_addr,
1846 spe_context_offset);
1847 spe_context_cache_ptid = inferior_ptid;
1850 CATCH (ex, RETURN_MASK_ERROR)
1857 /* Read variable value. */
1858 if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
1859 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1861 /* Cyle through to N'th linked list element. */
1862 for (i = 0; i < n && spe_context; i++)
1863 if (target_read_memory (spe_context + align_up (12, wordsize),
1864 buf, wordsize) == 0)
1865 spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
1869 /* Read current context. */
1871 && target_read_memory (spe_context, buf, 12) != 0)
1874 /* Extract data elements. */
1878 *id = extract_signed_integer (buf, 4, byte_order);
1880 *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
1887 /* Cell/B.E. cross-architecture unwinder support. */
1889 struct ppu2spu_cache
1891 struct frame_id frame_id;
1892 readonly_detached_regcache *regcache;
1895 static struct gdbarch *
1896 ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
1898 struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache;
1899 return cache->regcache->arch ();
1903 ppu2spu_this_id (struct frame_info *this_frame,
1904 void **this_cache, struct frame_id *this_id)
1906 struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache;
1907 *this_id = cache->frame_id;
1910 static struct value *
1911 ppu2spu_prev_register (struct frame_info *this_frame,
1912 void **this_cache, int regnum)
1914 struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache;
1915 struct gdbarch *gdbarch = cache->regcache->arch ();
1918 buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
1920 cache->regcache->cooked_read (regnum, buf);
1921 return frame_unwind_got_bytes (this_frame, regnum, buf);
1926 struct gdbarch *gdbarch;
1929 gdb_byte gprs[128*16];
1932 static enum register_status
1933 ppu2spu_unwind_register (ppu2spu_data *data, int regnum, gdb_byte *buf)
1935 enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
1937 if (regnum >= 0 && regnum < SPU_NUM_GPRS)
1938 memcpy (buf, data->gprs + 16*regnum, 16);
1939 else if (regnum == SPU_ID_REGNUM)
1940 store_unsigned_integer (buf, 4, byte_order, data->id);
1941 else if (regnum == SPU_PC_REGNUM)
1942 store_unsigned_integer (buf, 4, byte_order, data->npc);
1944 return REG_UNAVAILABLE;
1950 ppu2spu_sniffer (const struct frame_unwind *self,
1951 struct frame_info *this_frame, void **this_prologue_cache)
1953 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1954 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1955 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1956 struct ppu2spu_data data;
1957 struct frame_info *fi;
1958 CORE_ADDR base, func, backchain, spe_context;
1962 /* Count the number of SPU contexts already in the frame chain. */
1963 for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
1964 if (get_frame_type (fi) == ARCH_FRAME
1965 && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
1968 base = get_frame_sp (this_frame);
1969 func = get_frame_pc (this_frame);
1970 if (target_read_memory (base, buf, tdep->wordsize))
1972 backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
1974 spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
1975 n, &data.id, &data.npc);
1976 if (spe_context && base <= spe_context && spe_context < backchain)
1980 /* Find gdbarch for SPU. */
1981 struct gdbarch_info info;
1982 gdbarch_info_init (&info);
1983 info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
1984 info.byte_order = BFD_ENDIAN_BIG;
1985 info.osabi = GDB_OSABI_LINUX;
1987 data.gdbarch = gdbarch_find_by_info (info);
1991 xsnprintf (annex, sizeof annex, "%d/regs", data.id);
1992 if (target_read (current_top_target (), TARGET_OBJECT_SPU, annex,
1993 data.gprs, 0, sizeof data.gprs)
1994 == sizeof data.gprs)
1996 auto cooked_read = [&data] (int regnum, gdb_byte *out_buf)
1998 return ppu2spu_unwind_register (&data, regnum, out_buf);
2000 struct ppu2spu_cache *cache
2001 = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
2002 std::unique_ptr<readonly_detached_regcache> regcache
2003 (new readonly_detached_regcache (data.gdbarch, cooked_read));
2005 cache->frame_id = frame_id_build (base, func);
2006 cache->regcache = regcache.release ();
2007 *this_prologue_cache = cache;
2016 ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
2018 struct ppu2spu_cache *cache = (struct ppu2spu_cache *) this_cache;
2019 delete cache->regcache;
2022 static const struct frame_unwind ppu2spu_unwind = {
2024 default_frame_unwind_stop_reason,
2026 ppu2spu_prev_register,
2029 ppu2spu_dealloc_cache,
2033 /* Initialize linux_record_tdep if not initialized yet.
2034 WORDSIZE is 4 or 8 for 32- or 64-bit PowerPC Linux respectively.
2035 Sizes of data structures are initialized accordingly. */
2038 ppc_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
2041 /* Simply return if it had been initialized. */
2042 if (record_tdep->size_pointer != 0)
2045 /* These values are the size of the type that will be used in a system
2046 call. They are obtained from Linux Kernel source. */
2050 record_tdep->size_pointer = 8;
2051 record_tdep->size__old_kernel_stat = 32;
2052 record_tdep->size_tms = 32;
2053 record_tdep->size_loff_t = 8;
2054 record_tdep->size_flock = 32;
2055 record_tdep->size_oldold_utsname = 45;
2056 record_tdep->size_ustat = 32;
2057 record_tdep->size_old_sigaction = 32;
2058 record_tdep->size_old_sigset_t = 8;
2059 record_tdep->size_rlimit = 16;
2060 record_tdep->size_rusage = 144;
2061 record_tdep->size_timeval = 16;
2062 record_tdep->size_timezone = 8;
2063 record_tdep->size_old_gid_t = 4;
2064 record_tdep->size_old_uid_t = 4;
2065 record_tdep->size_fd_set = 128;
2066 record_tdep->size_old_dirent = 280;
2067 record_tdep->size_statfs = 120;
2068 record_tdep->size_statfs64 = 120;
2069 record_tdep->size_sockaddr = 16;
2070 record_tdep->size_int = 4;
2071 record_tdep->size_long = 8;
2072 record_tdep->size_ulong = 8;
2073 record_tdep->size_msghdr = 56;
2074 record_tdep->size_itimerval = 32;
2075 record_tdep->size_stat = 144;
2076 record_tdep->size_old_utsname = 325;
2077 record_tdep->size_sysinfo = 112;
2078 record_tdep->size_msqid_ds = 120;
2079 record_tdep->size_shmid_ds = 112;
2080 record_tdep->size_new_utsname = 390;
2081 record_tdep->size_timex = 208;
2082 record_tdep->size_mem_dqinfo = 24;
2083 record_tdep->size_if_dqblk = 72;
2084 record_tdep->size_fs_quota_stat = 80;
2085 record_tdep->size_timespec = 16;
2086 record_tdep->size_pollfd = 8;
2087 record_tdep->size_NFS_FHSIZE = 32;
2088 record_tdep->size_knfsd_fh = 132;
2089 record_tdep->size_TASK_COMM_LEN = 16;
2090 record_tdep->size_sigaction = 32;
2091 record_tdep->size_sigset_t = 8;
2092 record_tdep->size_siginfo_t = 128;
2093 record_tdep->size_cap_user_data_t = 8;
2094 record_tdep->size_stack_t = 24;
2095 record_tdep->size_off_t = 8;
2096 record_tdep->size_stat64 = 104;
2097 record_tdep->size_gid_t = 4;
2098 record_tdep->size_uid_t = 4;
2099 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
2100 record_tdep->size_flock64 = 32;
2101 record_tdep->size_io_event = 32;
2102 record_tdep->size_iocb = 64;
2103 record_tdep->size_epoll_event = 16;
2104 record_tdep->size_itimerspec = 32;
2105 record_tdep->size_mq_attr = 64;
2106 record_tdep->size_termios = 44;
2107 record_tdep->size_pid_t = 4;
2108 record_tdep->size_winsize = 8;
2109 record_tdep->size_serial_struct = 72;
2110 record_tdep->size_serial_icounter_struct = 80;
2111 record_tdep->size_size_t = 8;
2112 record_tdep->size_iovec = 16;
2113 record_tdep->size_time_t = 8;
2115 else if (wordsize == 4)
2117 record_tdep->size_pointer = 4;
2118 record_tdep->size__old_kernel_stat = 32;
2119 record_tdep->size_tms = 16;
2120 record_tdep->size_loff_t = 8;
2121 record_tdep->size_flock = 16;
2122 record_tdep->size_oldold_utsname = 45;
2123 record_tdep->size_ustat = 20;
2124 record_tdep->size_old_sigaction = 16;
2125 record_tdep->size_old_sigset_t = 4;
2126 record_tdep->size_rlimit = 8;
2127 record_tdep->size_rusage = 72;
2128 record_tdep->size_timeval = 8;
2129 record_tdep->size_timezone = 8;
2130 record_tdep->size_old_gid_t = 4;
2131 record_tdep->size_old_uid_t = 4;
2132 record_tdep->size_fd_set = 128;
2133 record_tdep->size_old_dirent = 268;
2134 record_tdep->size_statfs = 64;
2135 record_tdep->size_statfs64 = 88;
2136 record_tdep->size_sockaddr = 16;
2137 record_tdep->size_int = 4;
2138 record_tdep->size_long = 4;
2139 record_tdep->size_ulong = 4;
2140 record_tdep->size_msghdr = 28;
2141 record_tdep->size_itimerval = 16;
2142 record_tdep->size_stat = 88;
2143 record_tdep->size_old_utsname = 325;
2144 record_tdep->size_sysinfo = 64;
2145 record_tdep->size_msqid_ds = 68;
2146 record_tdep->size_shmid_ds = 60;
2147 record_tdep->size_new_utsname = 390;
2148 record_tdep->size_timex = 128;
2149 record_tdep->size_mem_dqinfo = 24;
2150 record_tdep->size_if_dqblk = 72;
2151 record_tdep->size_fs_quota_stat = 80;
2152 record_tdep->size_timespec = 8;
2153 record_tdep->size_pollfd = 8;
2154 record_tdep->size_NFS_FHSIZE = 32;
2155 record_tdep->size_knfsd_fh = 132;
2156 record_tdep->size_TASK_COMM_LEN = 16;
2157 record_tdep->size_sigaction = 20;
2158 record_tdep->size_sigset_t = 8;
2159 record_tdep->size_siginfo_t = 128;
2160 record_tdep->size_cap_user_data_t = 4;
2161 record_tdep->size_stack_t = 12;
2162 record_tdep->size_off_t = 4;
2163 record_tdep->size_stat64 = 104;
2164 record_tdep->size_gid_t = 4;
2165 record_tdep->size_uid_t = 4;
2166 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
2167 record_tdep->size_flock64 = 32;
2168 record_tdep->size_io_event = 32;
2169 record_tdep->size_iocb = 64;
2170 record_tdep->size_epoll_event = 16;
2171 record_tdep->size_itimerspec = 16;
2172 record_tdep->size_mq_attr = 32;
2173 record_tdep->size_termios = 44;
2174 record_tdep->size_pid_t = 4;
2175 record_tdep->size_winsize = 8;
2176 record_tdep->size_serial_struct = 60;
2177 record_tdep->size_serial_icounter_struct = 80;
2178 record_tdep->size_size_t = 4;
2179 record_tdep->size_iovec = 8;
2180 record_tdep->size_time_t = 4;
2183 internal_error (__FILE__, __LINE__, _("unexpected wordsize"));
2185 /* These values are the second argument of system call "sys_fcntl"
2186 and "sys_fcntl64". They are obtained from Linux Kernel source. */
2187 record_tdep->fcntl_F_GETLK = 5;
2188 record_tdep->fcntl_F_GETLK64 = 12;
2189 record_tdep->fcntl_F_SETLK64 = 13;
2190 record_tdep->fcntl_F_SETLKW64 = 14;
2192 record_tdep->arg1 = PPC_R0_REGNUM + 3;
2193 record_tdep->arg2 = PPC_R0_REGNUM + 4;
2194 record_tdep->arg3 = PPC_R0_REGNUM + 5;
2195 record_tdep->arg4 = PPC_R0_REGNUM + 6;
2196 record_tdep->arg5 = PPC_R0_REGNUM + 7;
2197 record_tdep->arg6 = PPC_R0_REGNUM + 8;
2199 /* These values are the second argument of system call "sys_ioctl".
2200 They are obtained from Linux Kernel source.
2201 See arch/powerpc/include/uapi/asm/ioctls.h. */
2202 record_tdep->ioctl_TCGETS = 0x403c7413;
2203 record_tdep->ioctl_TCSETS = 0x803c7414;
2204 record_tdep->ioctl_TCSETSW = 0x803c7415;
2205 record_tdep->ioctl_TCSETSF = 0x803c7416;
2206 record_tdep->ioctl_TCGETA = 0x40147417;
2207 record_tdep->ioctl_TCSETA = 0x80147418;
2208 record_tdep->ioctl_TCSETAW = 0x80147419;
2209 record_tdep->ioctl_TCSETAF = 0x8014741c;
2210 record_tdep->ioctl_TCSBRK = 0x2000741d;
2211 record_tdep->ioctl_TCXONC = 0x2000741e;
2212 record_tdep->ioctl_TCFLSH = 0x2000741f;
2213 record_tdep->ioctl_TIOCEXCL = 0x540c;
2214 record_tdep->ioctl_TIOCNXCL = 0x540d;
2215 record_tdep->ioctl_TIOCSCTTY = 0x540e;
2216 record_tdep->ioctl_TIOCGPGRP = 0x40047477;
2217 record_tdep->ioctl_TIOCSPGRP = 0x80047476;
2218 record_tdep->ioctl_TIOCOUTQ = 0x40047473;
2219 record_tdep->ioctl_TIOCSTI = 0x5412;
2220 record_tdep->ioctl_TIOCGWINSZ = 0x40087468;
2221 record_tdep->ioctl_TIOCSWINSZ = 0x80087467;
2222 record_tdep->ioctl_TIOCMGET = 0x5415;
2223 record_tdep->ioctl_TIOCMBIS = 0x5416;
2224 record_tdep->ioctl_TIOCMBIC = 0x5417;
2225 record_tdep->ioctl_TIOCMSET = 0x5418;
2226 record_tdep->ioctl_TIOCGSOFTCAR = 0x5419;
2227 record_tdep->ioctl_TIOCSSOFTCAR = 0x541a;
2228 record_tdep->ioctl_FIONREAD = 0x4004667f;
2229 record_tdep->ioctl_TIOCINQ = 0x4004667f;
2230 record_tdep->ioctl_TIOCLINUX = 0x541c;
2231 record_tdep->ioctl_TIOCCONS = 0x541d;
2232 record_tdep->ioctl_TIOCGSERIAL = 0x541e;
2233 record_tdep->ioctl_TIOCSSERIAL = 0x541f;
2234 record_tdep->ioctl_TIOCPKT = 0x5420;
2235 record_tdep->ioctl_FIONBIO = 0x8004667e;
2236 record_tdep->ioctl_TIOCNOTTY = 0x5422;
2237 record_tdep->ioctl_TIOCSETD = 0x5423;
2238 record_tdep->ioctl_TIOCGETD = 0x5424;
2239 record_tdep->ioctl_TCSBRKP = 0x5425;
2240 record_tdep->ioctl_TIOCSBRK = 0x5427;
2241 record_tdep->ioctl_TIOCCBRK = 0x5428;
2242 record_tdep->ioctl_TIOCGSID = 0x5429;
2243 record_tdep->ioctl_TIOCGPTN = 0x40045430;
2244 record_tdep->ioctl_TIOCSPTLCK = 0x80045431;
2245 record_tdep->ioctl_FIONCLEX = 0x20006602;
2246 record_tdep->ioctl_FIOCLEX = 0x20006601;
2247 record_tdep->ioctl_FIOASYNC = 0x8004667d;
2248 record_tdep->ioctl_TIOCSERCONFIG = 0x5453;
2249 record_tdep->ioctl_TIOCSERGWILD = 0x5454;
2250 record_tdep->ioctl_TIOCSERSWILD = 0x5455;
2251 record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456;
2252 record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457;
2253 record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458;
2254 record_tdep->ioctl_TIOCSERGETLSR = 0x5459;
2255 record_tdep->ioctl_TIOCSERGETMULTI = 0x545a;
2256 record_tdep->ioctl_TIOCSERSETMULTI = 0x545b;
2257 record_tdep->ioctl_TIOCMIWAIT = 0x545c;
2258 record_tdep->ioctl_TIOCGICOUNT = 0x545d;
2259 record_tdep->ioctl_FIOQSIZE = 0x40086680;
2262 /* Return a floating-point format for a floating-point variable of
2263 length LEN in bits. If non-NULL, NAME is the name of its type.
2264 If no suitable type is found, return NULL. */
2266 const struct floatformat **
2267 ppc_floatformat_for_type (struct gdbarch *gdbarch,
2268 const char *name, int len)
2270 if (len == 128 && name)
2272 if (strcmp (name, "__float128") == 0
2273 || strcmp (name, "_Float128") == 0
2274 || strcmp (name, "_Float64x") == 0
2275 || strcmp (name, "complex _Float128") == 0
2276 || strcmp (name, "complex _Float64x") == 0)
2277 return floatformats_ia64_quad;
2279 if (strcmp (name, "__ibm128") == 0)
2280 return floatformats_ibm_long_double;
2283 return default_floatformat_for_type (gdbarch, name, len);
2287 ppc_linux_init_abi (struct gdbarch_info info,
2288 struct gdbarch *gdbarch)
2290 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2291 struct tdesc_arch_data *tdesc_data = info.tdesc_data;
2292 static const char *const stap_integer_prefixes[] = { "i", NULL };
2293 static const char *const stap_register_indirection_prefixes[] = { "(",
2295 static const char *const stap_register_indirection_suffixes[] = { ")",
2298 linux_init_abi (info, gdbarch);
2300 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
2301 128-bit, they can be either IBM long double or IEEE quad long double.
2302 The 64-bit long double case will be detected automatically using
2303 the size specified in debug info. We use a .gnu.attribute flag
2304 to distinguish between the IBM long double and IEEE quad cases. */
2305 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
2306 if (tdep->long_double_abi == POWERPC_LONG_DOUBLE_IEEE128)
2307 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
2309 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
2311 /* Support for floating-point data type variants. */
2312 set_gdbarch_floatformat_for_type (gdbarch, ppc_floatformat_for_type);
2314 /* Handle inferior calls during interrupted system calls. */
2315 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
2317 /* Get the syscall number from the arch's register. */
2318 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
2320 /* SystemTap functions. */
2321 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
2322 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
2323 stap_register_indirection_prefixes);
2324 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
2325 stap_register_indirection_suffixes);
2326 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
2327 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
2328 set_gdbarch_stap_parse_special_token (gdbarch,
2329 ppc_stap_parse_special_token);
2331 if (tdep->wordsize == 4)
2333 /* Until November 2001, gcc did not comply with the 32 bit SysV
2334 R4 ABI requirement that structures less than or equal to 8
2335 bytes should be returned in registers. Instead GCC was using
2336 the AIX/PowerOpen ABI - everything returned in memory
2337 (well ignoring vectors that is). When this was corrected, it
2338 wasn't fixed for GNU/Linux native platform. Use the
2339 PowerOpen struct convention. */
2340 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
2342 set_gdbarch_memory_remove_breakpoint (gdbarch,
2343 ppc_linux_memory_remove_breakpoint);
2345 /* Shared library handling. */
2346 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
2347 set_solib_svr4_fetch_link_map_offsets
2348 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
2350 /* Setting the correct XML syscall filename. */
2351 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC);
2354 tramp_frame_prepend_unwinder (gdbarch,
2355 &ppc32_linux_sigaction_tramp_frame);
2356 tramp_frame_prepend_unwinder (gdbarch,
2357 &ppc32_linux_sighandler_tramp_frame);
2359 /* BFD target for core files. */
2360 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
2361 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
2363 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
2365 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
2367 powerpc_so_ops = svr4_so_ops;
2368 /* Override dynamic resolve function. */
2369 powerpc_so_ops.in_dynsym_resolve_code =
2370 powerpc_linux_in_dynsym_resolve_code;
2372 set_solib_ops (gdbarch, &powerpc_so_ops);
2374 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
2377 if (tdep->wordsize == 8)
2379 if (tdep->elf_abi == POWERPC_ELF_V1)
2381 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
2382 function descriptors). */
2383 set_gdbarch_convert_from_func_ptr_addr
2384 (gdbarch, ppc64_convert_from_func_ptr_addr);
2386 set_gdbarch_elf_make_msymbol_special
2387 (gdbarch, ppc64_elf_make_msymbol_special);
2391 set_gdbarch_elf_make_msymbol_special
2392 (gdbarch, ppc_elfv2_elf_make_msymbol_special);
2394 set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint);
2397 /* Shared library handling. */
2398 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
2399 set_solib_svr4_fetch_link_map_offsets
2400 (gdbarch, svr4_lp64_fetch_link_map_offsets);
2402 /* Setting the correct XML syscall filename. */
2403 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC64);
2406 tramp_frame_prepend_unwinder (gdbarch,
2407 &ppc64_linux_sigaction_tramp_frame);
2408 tramp_frame_prepend_unwinder (gdbarch,
2409 &ppc64_linux_sighandler_tramp_frame);
2411 /* BFD target for core files. */
2412 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
2413 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
2415 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
2418 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
2419 set_gdbarch_iterate_over_regset_sections (gdbarch,
2420 ppc_linux_iterate_over_regset_sections);
2422 /* Enable TLS support. */
2423 set_gdbarch_fetch_tls_load_module_address (gdbarch,
2424 svr4_fetch_objfile_link_map);
2428 const struct tdesc_feature *feature;
2430 /* If we have target-described registers, then we can safely
2431 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
2432 (whether they are described or not). */
2433 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
2434 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
2436 /* If they are present, then assign them to the reserved number. */
2437 feature = tdesc_find_feature (info.target_desc,
2438 "org.gnu.gdb.power.linux");
2439 if (feature != NULL)
2441 tdesc_numbered_register (feature, tdesc_data,
2442 PPC_ORIG_R3_REGNUM, "orig_r3");
2443 tdesc_numbered_register (feature, tdesc_data,
2444 PPC_TRAP_REGNUM, "trap");
2448 /* Enable Cell/B.E. if supported by the target. */
2449 if (tdesc_compatible_p (info.target_desc,
2450 bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
2452 /* Cell/B.E. multi-architecture support. */
2453 set_spu_solib_ops (gdbarch);
2455 /* Cell/B.E. cross-architecture unwinder support. */
2456 frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
2458 /* We need to support more than "addr_bit" significant address bits
2459 in order to support SPUADDR_ADDR encoded values. */
2460 set_gdbarch_significant_addr_bit (gdbarch, 64);
2463 set_gdbarch_displaced_step_location (gdbarch,
2464 linux_displaced_step_location);
2466 /* Support reverse debugging. */
2467 set_gdbarch_process_record (gdbarch, ppc_process_record);
2468 set_gdbarch_process_record_signal (gdbarch, ppc_linux_record_signal);
2469 tdep->ppc_syscall_record = ppc_linux_syscall_record;
2471 ppc_init_linux_record_tdep (&ppc_linux_record_tdep, 4);
2472 ppc_init_linux_record_tdep (&ppc64_linux_record_tdep, 8);
2476 _initialize_ppc_linux_tdep (void)
2478 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
2479 64-bit PowerPC, and the older rs6k. */
2480 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
2481 ppc_linux_init_abi);
2482 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
2483 ppc_linux_init_abi);
2484 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
2485 ppc_linux_init_abi);
2487 /* Attach to observers to track __spe_current_active_context. */
2488 gdb::observers::inferior_created.attach (ppc_linux_spe_context_inferior_created);
2489 gdb::observers::solib_loaded.attach (ppc_linux_spe_context_solib_loaded);
2490 gdb::observers::solib_unloaded.attach (ppc_linux_spe_context_solib_unloaded);
2492 /* Initialize the Linux target descriptions. */
2493 initialize_tdesc_powerpc_32l ();
2494 initialize_tdesc_powerpc_altivec32l ();
2495 initialize_tdesc_powerpc_cell32l ();
2496 initialize_tdesc_powerpc_vsx32l ();
2497 initialize_tdesc_powerpc_isa205_32l ();
2498 initialize_tdesc_powerpc_isa205_altivec32l ();
2499 initialize_tdesc_powerpc_isa205_vsx32l ();
2500 initialize_tdesc_powerpc_isa205_ppr_dscr_vsx32l ();
2501 initialize_tdesc_powerpc_isa207_vsx32l ();
2502 initialize_tdesc_powerpc_isa207_htm_vsx32l ();
2503 initialize_tdesc_powerpc_64l ();
2504 initialize_tdesc_powerpc_altivec64l ();
2505 initialize_tdesc_powerpc_cell64l ();
2506 initialize_tdesc_powerpc_vsx64l ();
2507 initialize_tdesc_powerpc_isa205_64l ();
2508 initialize_tdesc_powerpc_isa205_altivec64l ();
2509 initialize_tdesc_powerpc_isa205_vsx64l ();
2510 initialize_tdesc_powerpc_isa205_ppr_dscr_vsx64l ();
2511 initialize_tdesc_powerpc_isa207_vsx64l ();
2512 initialize_tdesc_powerpc_isa207_htm_vsx64l ();
2513 initialize_tdesc_powerpc_e500l ();