1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 1986-2022 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"
37 #include "ppc64-tdep.h"
38 #include "ppc-linux-tdep.h"
39 #include "arch/ppc-linux-common.h"
40 #include "arch/ppc-linux-tdesc.h"
41 #include "glibc-tdep.h"
42 #include "trad-frame.h"
43 #include "frame-unwind.h"
44 #include "tramp-frame.h"
45 #include "observable.h"
47 #include "elf/common.h"
48 #include "elf/ppc64.h"
49 #include "arch-utils.h"
50 #include "xml-syscall.h"
51 #include "linux-tdep.h"
52 #include "linux-record.h"
53 #include "record-full.h"
57 #include "stap-probe.h"
60 #include "cli/cli-utils.h"
61 #include "parser-defs.h"
62 #include "user-regs.h"
66 #include "features/rs6000/powerpc-32l.c"
67 #include "features/rs6000/powerpc-altivec32l.c"
68 #include "features/rs6000/powerpc-vsx32l.c"
69 #include "features/rs6000/powerpc-isa205-32l.c"
70 #include "features/rs6000/powerpc-isa205-altivec32l.c"
71 #include "features/rs6000/powerpc-isa205-vsx32l.c"
72 #include "features/rs6000/powerpc-isa205-ppr-dscr-vsx32l.c"
73 #include "features/rs6000/powerpc-isa207-vsx32l.c"
74 #include "features/rs6000/powerpc-isa207-htm-vsx32l.c"
75 #include "features/rs6000/powerpc-64l.c"
76 #include "features/rs6000/powerpc-altivec64l.c"
77 #include "features/rs6000/powerpc-vsx64l.c"
78 #include "features/rs6000/powerpc-isa205-64l.c"
79 #include "features/rs6000/powerpc-isa205-altivec64l.c"
80 #include "features/rs6000/powerpc-isa205-vsx64l.c"
81 #include "features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c"
82 #include "features/rs6000/powerpc-isa207-vsx64l.c"
83 #include "features/rs6000/powerpc-isa207-htm-vsx64l.c"
84 #include "features/rs6000/powerpc-e500l.c"
86 /* Shared library operations for PowerPC-Linux. */
87 static struct target_so_ops powerpc_so_ops
;
89 /* The syscall's XML filename for PPC and PPC64. */
90 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
91 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
93 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
94 in much the same fashion as memory_remove_breakpoint in mem-break.c,
95 but is careful not to write back the previous contents if the code
96 in question has changed in between inserting the breakpoint and
99 Here is the problem that we're trying to solve...
101 Once upon a time, before introducing this function to remove
102 breakpoints from the inferior, setting a breakpoint on a shared
103 library function prior to running the program would not work
104 properly. In order to understand the problem, it is first
105 necessary to understand a little bit about dynamic linking on
108 A call to a shared library function is accomplished via a bl
109 (branch-and-link) instruction whose branch target is an entry
110 in the procedure linkage table (PLT). The PLT in the object
111 file is uninitialized. To gdb, prior to running the program, the
112 entries in the PLT are all zeros.
114 Once the program starts running, the shared libraries are loaded
115 and the procedure linkage table is initialized, but the entries in
116 the table are not (necessarily) resolved. Once a function is
117 actually called, the code in the PLT is hit and the function is
118 resolved. In order to better illustrate this, an example is in
119 order; the following example is from the gdb testsuite.
121 We start the program shmain.
123 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
126 We place two breakpoints, one on shr1 and the other on main.
129 Breakpoint 1 at 0x100409d4
131 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
133 Examine the instruction (and the immediatly following instruction)
134 upon which the breakpoint was placed. Note that the PLT entry
135 for shr1 contains zeros.
137 (gdb) x/2i 0x100409d4
138 0x100409d4 <shr1>: .long 0x0
139 0x100409d8 <shr1+4>: .long 0x0
144 Starting program: gdb.base/shmain
145 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
147 Breakpoint 2, main ()
148 at gdb.base/shmain.c:44
151 Examine the PLT again. Note that the loading of the shared
152 library has initialized the PLT to code which loads a constant
153 (which I think is an index into the GOT) into r11 and then
154 branches a short distance to the code which actually does the
157 (gdb) x/2i 0x100409d4
158 0x100409d4 <shr1>: li r11,4
159 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
163 Breakpoint 1, shr1 (x=1)
164 at gdb.base/shr1.c:19
167 Now we've hit the breakpoint at shr1. (The breakpoint was
168 reset from the PLT entry to the actual shr1 function after the
169 shared library was loaded.) Note that the PLT entry has been
170 resolved to contain a branch that takes us directly to shr1.
171 (The real one, not the PLT entry.)
173 (gdb) x/2i 0x100409d4
174 0x100409d4 <shr1>: b 0xffaf76c <shr1>
175 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
177 The thing to note here is that the PLT entry for shr1 has been
180 Now the problem should be obvious. GDB places a breakpoint (a
181 trap instruction) on the zero value of the PLT entry for shr1.
182 Later on, after the shared library had been loaded and the PLT
183 initialized, GDB gets a signal indicating this fact and attempts
184 (as it always does when it stops) to remove all the breakpoints.
186 The breakpoint removal was causing the former contents (a zero
187 word) to be written back to the now initialized PLT entry thus
188 destroying a portion of the initialization that had occurred only a
189 short time ago. When execution continued, the zero word would be
190 executed as an instruction an illegal instruction trap was
191 generated instead. (0 is not a legal instruction.)
193 The fix for this problem was fairly straightforward. The function
194 memory_remove_breakpoint from mem-break.c was copied to this file,
195 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
196 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
199 The differences between ppc_linux_memory_remove_breakpoint () and
200 memory_remove_breakpoint () are minor. All that the former does
201 that the latter does not is check to make sure that the breakpoint
202 location actually contains a breakpoint (trap instruction) prior
203 to attempting to write back the old contents. If it does contain
204 a trap instruction, we allow the old contents to be written back.
205 Otherwise, we silently do nothing.
207 The big question is whether memory_remove_breakpoint () should be
208 changed to have the same functionality. The downside is that more
209 traffic is generated for remote targets since we'll have an extra
210 fetch of a memory word each time a breakpoint is removed.
212 For the time being, we'll leave this self-modifying-code-friendly
213 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
214 else in the event that some other platform has similar needs with
215 regard to removing breakpoints in some potentially self modifying
218 ppc_linux_memory_remove_breakpoint (struct gdbarch
*gdbarch
,
219 struct bp_target_info
*bp_tgt
)
221 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
222 const unsigned char *bp
;
225 gdb_byte old_contents
[BREAKPOINT_MAX
];
227 /* Determine appropriate breakpoint contents and size for this address. */
228 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &bplen
);
230 /* Make sure we see the memory breakpoints. */
231 scoped_restore restore_memory
232 = make_scoped_restore_show_memory_breakpoints (1);
233 val
= target_read_memory (addr
, old_contents
, bplen
);
235 /* If our breakpoint is no longer at the address, this means that the
236 program modified the code on us, so it is wrong to put back the
238 if (val
== 0 && memcmp (bp
, old_contents
, bplen
) == 0)
239 val
= target_write_raw_memory (addr
, bp_tgt
->shadow_contents
, bplen
);
244 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
245 than the 32 bit SYSV R4 ABI structure return convention - all
246 structures, no matter their size, are put in memory. Vectors,
247 which were added later, do get returned in a register though. */
249 static enum return_value_convention
250 ppc_linux_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
251 struct type
*valtype
, struct regcache
*regcache
,
252 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
254 if ((valtype
->code () == TYPE_CODE_STRUCT
255 || valtype
->code () == TYPE_CODE_UNION
)
256 && !((TYPE_LENGTH (valtype
) == 16 || TYPE_LENGTH (valtype
) == 8)
257 && valtype
->is_vector ()))
258 return RETURN_VALUE_STRUCT_CONVENTION
;
260 return ppc_sysv_abi_return_value (gdbarch
, function
, valtype
, regcache
,
264 /* PLT stub in an executable. */
265 static const struct ppc_insn_pattern powerpc32_plt_stub
[] =
267 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
268 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
269 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
270 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
274 /* PLT stubs in a shared library or PIE.
275 The first variant is used when the PLT entry is within +/-32k of
276 the GOT pointer (r30). */
277 static const struct ppc_insn_pattern powerpc32_plt_stub_so_1
[] =
279 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
280 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
281 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
285 /* The second variant is used when the PLT entry is more than +/-32k
286 from the GOT pointer (r30). */
287 static const struct ppc_insn_pattern powerpc32_plt_stub_so_2
[] =
289 { 0xffff0000, 0x3d7e0000, 0 }, /* addis r11, r30, xxxx */
290 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
291 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
292 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
296 /* The max number of insns we check using ppc_insns_match_pattern. */
297 #define POWERPC32_PLT_CHECK_LEN (ARRAY_SIZE (powerpc32_plt_stub) - 1)
299 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
300 section. For secure PLT, stub is in .text and we need to check
301 instruction patterns. */
304 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc
)
306 struct bound_minimal_symbol sym
;
308 /* Check whether PC is in the dynamic linker. This also checks
309 whether it is in the .plt section, used by non-PIC executables. */
310 if (svr4_in_dynsym_resolve_code (pc
))
313 /* Check if we are in the resolver. */
314 sym
= lookup_minimal_symbol_by_pc (pc
);
315 if (sym
.minsym
!= NULL
316 && (strcmp (sym
.minsym
->linkage_name (), "__glink") == 0
317 || strcmp (sym
.minsym
->linkage_name (), "__glink_PLTresolve") == 0))
323 /* Follow PLT stub to actual routine.
325 When the execution direction is EXEC_REVERSE, scan backward to
326 check whether we are in the middle of a PLT stub. Currently,
327 we only look-behind at most 4 instructions (the max length of a PLT
331 ppc_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
333 unsigned int insnbuf
[POWERPC32_PLT_CHECK_LEN
];
334 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
335 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
336 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
337 CORE_ADDR target
= 0;
341 /* When reverse-debugging, scan backward to check whether we are
342 in the middle of trampoline code. */
343 if (execution_direction
== EXEC_REVERSE
)
344 scan_limit
= 4; /* At most 4 instructions. */
346 for (i
= 0; i
< scan_limit
; i
++)
348 if (ppc_insns_match_pattern (frame
, pc
, powerpc32_plt_stub
, insnbuf
))
350 /* Calculate PLT entry address from
352 lwz r11, xxxx(r11). */
353 target
= ((ppc_insn_d_field (insnbuf
[0]) << 16)
354 + ppc_insn_d_field (insnbuf
[1]));
356 else if (i
< ARRAY_SIZE (powerpc32_plt_stub_so_1
) - 1
357 && ppc_insns_match_pattern (frame
, pc
, powerpc32_plt_stub_so_1
,
360 /* Calculate PLT entry address from
361 lwz r11, xxxx(r30). */
362 target
= (ppc_insn_d_field (insnbuf
[0])
363 + get_frame_register_unsigned (frame
,
364 tdep
->ppc_gp0_regnum
+ 30));
366 else if (ppc_insns_match_pattern (frame
, pc
, powerpc32_plt_stub_so_2
,
369 /* Calculate PLT entry address from
371 lwz r11, xxxx(r11). */
372 target
= ((ppc_insn_d_field (insnbuf
[0]) << 16)
373 + ppc_insn_d_field (insnbuf
[1])
374 + get_frame_register_unsigned (frame
,
375 tdep
->ppc_gp0_regnum
+ 30));
379 /* Scan backward one more instruction if it doesn't match. */
384 target
= read_memory_unsigned_integer (target
, 4, byte_order
);
391 /* Wrappers to handle Linux-only registers. */
394 ppc_linux_supply_gregset (const struct regset
*regset
,
395 struct regcache
*regcache
,
396 int regnum
, const void *gregs
, size_t len
)
398 const struct ppc_reg_offsets
*offsets
399 = (const struct ppc_reg_offsets
*) regset
->regmap
;
401 ppc_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
403 if (ppc_linux_trap_reg_p (regcache
->arch ()))
405 /* "orig_r3" is stored 2 slots after "pc". */
406 if (regnum
== -1 || regnum
== PPC_ORIG_R3_REGNUM
)
407 ppc_supply_reg (regcache
, PPC_ORIG_R3_REGNUM
, (const gdb_byte
*) gregs
,
408 offsets
->pc_offset
+ 2 * offsets
->gpr_size
,
411 /* "trap" is stored 8 slots after "pc". */
412 if (regnum
== -1 || regnum
== PPC_TRAP_REGNUM
)
413 ppc_supply_reg (regcache
, PPC_TRAP_REGNUM
, (const gdb_byte
*) gregs
,
414 offsets
->pc_offset
+ 8 * offsets
->gpr_size
,
420 ppc_linux_collect_gregset (const struct regset
*regset
,
421 const struct regcache
*regcache
,
422 int regnum
, void *gregs
, size_t len
)
424 const struct ppc_reg_offsets
*offsets
425 = (const struct ppc_reg_offsets
*) regset
->regmap
;
427 /* Clear areas in the linux gregset not written elsewhere. */
429 memset (gregs
, 0, len
);
431 ppc_collect_gregset (regset
, regcache
, regnum
, gregs
, len
);
433 if (ppc_linux_trap_reg_p (regcache
->arch ()))
435 /* "orig_r3" is stored 2 slots after "pc". */
436 if (regnum
== -1 || regnum
== PPC_ORIG_R3_REGNUM
)
437 ppc_collect_reg (regcache
, PPC_ORIG_R3_REGNUM
, (gdb_byte
*) gregs
,
438 offsets
->pc_offset
+ 2 * offsets
->gpr_size
,
441 /* "trap" is stored 8 slots after "pc". */
442 if (regnum
== -1 || regnum
== PPC_TRAP_REGNUM
)
443 ppc_collect_reg (regcache
, PPC_TRAP_REGNUM
, (gdb_byte
*) gregs
,
444 offsets
->pc_offset
+ 8 * offsets
->gpr_size
,
449 /* Regset descriptions. */
450 static const struct ppc_reg_offsets ppc32_linux_reg_offsets
=
452 /* General-purpose registers. */
453 /* .r0_offset = */ 0,
456 /* .pc_offset = */ 128,
457 /* .ps_offset = */ 132,
458 /* .cr_offset = */ 152,
459 /* .lr_offset = */ 144,
460 /* .ctr_offset = */ 140,
461 /* .xer_offset = */ 148,
462 /* .mq_offset = */ 156,
464 /* Floating-point registers. */
465 /* .f0_offset = */ 0,
466 /* .fpscr_offset = */ 256,
467 /* .fpscr_size = */ 8
470 static const struct ppc_reg_offsets ppc64_linux_reg_offsets
=
472 /* General-purpose registers. */
473 /* .r0_offset = */ 0,
476 /* .pc_offset = */ 256,
477 /* .ps_offset = */ 264,
478 /* .cr_offset = */ 304,
479 /* .lr_offset = */ 288,
480 /* .ctr_offset = */ 280,
481 /* .xer_offset = */ 296,
482 /* .mq_offset = */ 312,
484 /* Floating-point registers. */
485 /* .f0_offset = */ 0,
486 /* .fpscr_offset = */ 256,
487 /* .fpscr_size = */ 8
490 static const struct regset ppc32_linux_gregset
= {
491 &ppc32_linux_reg_offsets
,
492 ppc_linux_supply_gregset
,
493 ppc_linux_collect_gregset
496 static const struct regset ppc64_linux_gregset
= {
497 &ppc64_linux_reg_offsets
,
498 ppc_linux_supply_gregset
,
499 ppc_linux_collect_gregset
502 static const struct regset ppc32_linux_fpregset
= {
503 &ppc32_linux_reg_offsets
,
508 static const struct regcache_map_entry ppc32_le_linux_vrregmap
[] =
510 { 32, PPC_VR0_REGNUM
, 16 },
511 { 1, PPC_VSCR_REGNUM
, 4 },
512 { 1, REGCACHE_MAP_SKIP
, 12 },
513 { 1, PPC_VRSAVE_REGNUM
, 4 },
514 { 1, REGCACHE_MAP_SKIP
, 12 },
518 static const struct regcache_map_entry ppc32_be_linux_vrregmap
[] =
520 { 32, PPC_VR0_REGNUM
, 16 },
521 { 1, REGCACHE_MAP_SKIP
, 12},
522 { 1, PPC_VSCR_REGNUM
, 4 },
523 { 1, PPC_VRSAVE_REGNUM
, 4 },
524 { 1, REGCACHE_MAP_SKIP
, 12 },
528 static const struct regset ppc32_le_linux_vrregset
= {
529 ppc32_le_linux_vrregmap
,
530 regcache_supply_regset
,
531 regcache_collect_regset
534 static const struct regset ppc32_be_linux_vrregset
= {
535 ppc32_be_linux_vrregmap
,
536 regcache_supply_regset
,
537 regcache_collect_regset
540 static const struct regcache_map_entry ppc32_linux_vsxregmap
[] =
542 { 32, PPC_VSR0_UPPER_REGNUM
, 8 },
546 static const struct regset ppc32_linux_vsxregset
= {
547 ppc32_linux_vsxregmap
,
548 regcache_supply_regset
,
549 regcache_collect_regset
552 /* Program Priorty Register regmap. */
554 static const struct regcache_map_entry ppc32_regmap_ppr
[] =
556 { 1, PPC_PPR_REGNUM
, 8 },
560 /* Program Priorty Register regset. */
562 const struct regset ppc32_linux_pprregset
= {
564 regcache_supply_regset
,
565 regcache_collect_regset
568 /* Data Stream Control Register regmap. */
570 static const struct regcache_map_entry ppc32_regmap_dscr
[] =
572 { 1, PPC_DSCR_REGNUM
, 8 },
576 /* Data Stream Control Register regset. */
578 const struct regset ppc32_linux_dscrregset
= {
580 regcache_supply_regset
,
581 regcache_collect_regset
584 /* Target Address Register regmap. */
586 static const struct regcache_map_entry ppc32_regmap_tar
[] =
588 { 1, PPC_TAR_REGNUM
, 8 },
592 /* Target Address Register regset. */
594 const struct regset ppc32_linux_tarregset
= {
596 regcache_supply_regset
,
597 regcache_collect_regset
600 /* Event-Based Branching regmap. */
602 static const struct regcache_map_entry ppc32_regmap_ebb
[] =
604 { 1, PPC_EBBRR_REGNUM
, 8 },
605 { 1, PPC_EBBHR_REGNUM
, 8 },
606 { 1, PPC_BESCR_REGNUM
, 8 },
610 /* Event-Based Branching regset. */
612 const struct regset ppc32_linux_ebbregset
= {
614 regcache_supply_regset
,
615 regcache_collect_regset
618 /* Performance Monitoring Unit regmap. */
620 static const struct regcache_map_entry ppc32_regmap_pmu
[] =
622 { 1, PPC_SIAR_REGNUM
, 8 },
623 { 1, PPC_SDAR_REGNUM
, 8 },
624 { 1, PPC_SIER_REGNUM
, 8 },
625 { 1, PPC_MMCR2_REGNUM
, 8 },
626 { 1, PPC_MMCR0_REGNUM
, 8 },
630 /* Performance Monitoring Unit regset. */
632 const struct regset ppc32_linux_pmuregset
= {
634 regcache_supply_regset
,
635 regcache_collect_regset
638 /* Hardware Transactional Memory special-purpose register regmap. */
640 static const struct regcache_map_entry ppc32_regmap_tm_spr
[] =
642 { 1, PPC_TFHAR_REGNUM
, 8 },
643 { 1, PPC_TEXASR_REGNUM
, 8 },
644 { 1, PPC_TFIAR_REGNUM
, 8 },
648 /* Hardware Transactional Memory special-purpose register regset. */
650 const struct regset ppc32_linux_tm_sprregset
= {
652 regcache_supply_regset
,
653 regcache_collect_regset
656 /* Regmaps for the Hardware Transactional Memory checkpointed
657 general-purpose regsets for 32-bit, 64-bit big-endian, and 64-bit
658 little endian targets. The ptrace and core file buffers for 64-bit
659 targets use 8-byte fields for the 4-byte registers, and the
660 position of the register in the fields depends on the endianness.
661 The 32-bit regmap is the same for both endian types because the
662 fields are all 4-byte long.
664 The layout of checkpointed GPR regset is the same as a regular
665 struct pt_regs, but we skip all registers that are not actually
666 checkpointed by the processor (e.g. msr, nip), except when
667 generating a core file. The 64-bit regset is 48 * 8 bytes long.
668 In some 64-bit kernels, the regset for a 32-bit inferior has the
669 same length, but all the registers are squeezed in the first half
670 (48 * 4 bytes). The pt_regs struct calls the regular cr ccr, but
671 we use ccr for "checkpointed condition register". Note that CR
672 (condition register) field 0 is not checkpointed, but the kernel
673 returns all 4 bytes. The skipped registers should not be touched
674 when writing the regset to the inferior (with
675 PTRACE_SETREGSET). */
677 static const struct regcache_map_entry ppc32_regmap_cgpr
[] =
679 { 32, PPC_CR0_REGNUM
, 4 },
680 { 3, REGCACHE_MAP_SKIP
, 4 }, /* nip, msr, orig_gpr3. */
681 { 1, PPC_CCTR_REGNUM
, 4 },
682 { 1, PPC_CLR_REGNUM
, 4 },
683 { 1, PPC_CXER_REGNUM
, 4 },
684 { 1, PPC_CCR_REGNUM
, 4 },
685 { 9, REGCACHE_MAP_SKIP
, 4 }, /* All the rest. */
689 static const struct regcache_map_entry ppc64_le_regmap_cgpr
[] =
691 { 32, PPC_CR0_REGNUM
, 8 },
692 { 3, REGCACHE_MAP_SKIP
, 8 },
693 { 1, PPC_CCTR_REGNUM
, 8 },
694 { 1, PPC_CLR_REGNUM
, 8 },
695 { 1, PPC_CXER_REGNUM
, 4 },
696 { 1, REGCACHE_MAP_SKIP
, 4 }, /* CXER padding. */
697 { 1, PPC_CCR_REGNUM
, 4 },
698 { 1, REGCACHE_MAP_SKIP
, 4}, /* CCR padding. */
699 { 9, REGCACHE_MAP_SKIP
, 8},
703 static const struct regcache_map_entry ppc64_be_regmap_cgpr
[] =
705 { 32, PPC_CR0_REGNUM
, 8 },
706 { 3, REGCACHE_MAP_SKIP
, 8 },
707 { 1, PPC_CCTR_REGNUM
, 8 },
708 { 1, PPC_CLR_REGNUM
, 8 },
709 { 1, REGCACHE_MAP_SKIP
, 4}, /* CXER padding. */
710 { 1, PPC_CXER_REGNUM
, 4 },
711 { 1, REGCACHE_MAP_SKIP
, 4}, /* CCR padding. */
712 { 1, PPC_CCR_REGNUM
, 4 },
713 { 9, REGCACHE_MAP_SKIP
, 8},
717 /* Regsets for the Hardware Transactional Memory checkpointed
718 general-purpose registers for 32-bit, 64-bit big-endian, and 64-bit
719 little endian targets.
721 Some 64-bit kernels generate a checkpointed gpr note section with
722 48*8 bytes for a 32-bit thread, of which only 48*4 are actually
723 used, so we set the variable size flag in the corresponding regset
724 to accept this case. */
726 static const struct regset ppc32_linux_cgprregset
= {
728 regcache_supply_regset
,
729 regcache_collect_regset
,
733 static const struct regset ppc64_be_linux_cgprregset
= {
734 ppc64_be_regmap_cgpr
,
735 regcache_supply_regset
,
736 regcache_collect_regset
739 static const struct regset ppc64_le_linux_cgprregset
= {
740 ppc64_le_regmap_cgpr
,
741 regcache_supply_regset
,
742 regcache_collect_regset
745 /* Hardware Transactional Memory checkpointed floating-point regmap. */
747 static const struct regcache_map_entry ppc32_regmap_cfpr
[] =
749 { 32, PPC_CF0_REGNUM
, 8 },
750 { 1, PPC_CFPSCR_REGNUM
, 8 },
754 /* Hardware Transactional Memory checkpointed floating-point regset. */
756 const struct regset ppc32_linux_cfprregset
= {
758 regcache_supply_regset
,
759 regcache_collect_regset
762 /* Regmaps for the Hardware Transactional Memory checkpointed vector
763 regsets, for big and little endian targets. The position of the
764 4-byte VSCR in its 16-byte field depends on the endianness. */
766 static const struct regcache_map_entry ppc32_le_regmap_cvmx
[] =
768 { 32, PPC_CVR0_REGNUM
, 16 },
769 { 1, PPC_CVSCR_REGNUM
, 4 },
770 { 1, REGCACHE_MAP_SKIP
, 12 },
771 { 1, PPC_CVRSAVE_REGNUM
, 4 },
772 { 1, REGCACHE_MAP_SKIP
, 12 },
776 static const struct regcache_map_entry ppc32_be_regmap_cvmx
[] =
778 { 32, PPC_CVR0_REGNUM
, 16 },
779 { 1, REGCACHE_MAP_SKIP
, 12 },
780 { 1, PPC_CVSCR_REGNUM
, 4 },
781 { 1, PPC_CVRSAVE_REGNUM
, 4 },
782 { 1, REGCACHE_MAP_SKIP
, 12},
786 /* Hardware Transactional Memory checkpointed vector regsets, for little
787 and big endian targets. */
789 static const struct regset ppc32_le_linux_cvmxregset
= {
790 ppc32_le_regmap_cvmx
,
791 regcache_supply_regset
,
792 regcache_collect_regset
795 static const struct regset ppc32_be_linux_cvmxregset
= {
796 ppc32_be_regmap_cvmx
,
797 regcache_supply_regset
,
798 regcache_collect_regset
801 /* Hardware Transactional Memory checkpointed vector-scalar regmap. */
803 static const struct regcache_map_entry ppc32_regmap_cvsx
[] =
805 { 32, PPC_CVSR0_UPPER_REGNUM
, 8 },
809 /* Hardware Transactional Memory checkpointed vector-scalar regset. */
811 const struct regset ppc32_linux_cvsxregset
= {
813 regcache_supply_regset
,
814 regcache_collect_regset
817 /* Hardware Transactional Memory checkpointed Program Priority Register
820 static const struct regcache_map_entry ppc32_regmap_cppr
[] =
822 { 1, PPC_CPPR_REGNUM
, 8 },
826 /* Hardware Transactional Memory checkpointed Program Priority Register
829 const struct regset ppc32_linux_cpprregset
= {
831 regcache_supply_regset
,
832 regcache_collect_regset
835 /* Hardware Transactional Memory checkpointed Data Stream Control
838 static const struct regcache_map_entry ppc32_regmap_cdscr
[] =
840 { 1, PPC_CDSCR_REGNUM
, 8 },
844 /* Hardware Transactional Memory checkpointed Data Stream Control
847 const struct regset ppc32_linux_cdscrregset
= {
849 regcache_supply_regset
,
850 regcache_collect_regset
853 /* Hardware Transactional Memory checkpointed Target Address Register
856 static const struct regcache_map_entry ppc32_regmap_ctar
[] =
858 { 1, PPC_CTAR_REGNUM
, 8 },
862 /* Hardware Transactional Memory checkpointed Target Address Register
865 const struct regset ppc32_linux_ctarregset
= {
867 regcache_supply_regset
,
868 regcache_collect_regset
871 const struct regset
*
872 ppc_linux_gregset (int wordsize
)
874 return wordsize
== 8 ? &ppc64_linux_gregset
: &ppc32_linux_gregset
;
877 const struct regset
*
878 ppc_linux_fpregset (void)
880 return &ppc32_linux_fpregset
;
883 const struct regset
*
884 ppc_linux_vrregset (struct gdbarch
*gdbarch
)
886 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
887 return &ppc32_be_linux_vrregset
;
889 return &ppc32_le_linux_vrregset
;
892 const struct regset
*
893 ppc_linux_vsxregset (void)
895 return &ppc32_linux_vsxregset
;
898 const struct regset
*
899 ppc_linux_cgprregset (struct gdbarch
*gdbarch
)
901 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
903 if (tdep
->wordsize
== 4)
905 return &ppc32_linux_cgprregset
;
909 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
910 return &ppc64_be_linux_cgprregset
;
912 return &ppc64_le_linux_cgprregset
;
916 const struct regset
*
917 ppc_linux_cvmxregset (struct gdbarch
*gdbarch
)
919 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
920 return &ppc32_be_linux_cvmxregset
;
922 return &ppc32_le_linux_cvmxregset
;
925 /* Collect function used to generate the core note for the
926 checkpointed GPR regset. Here, we don't want to skip the
927 "checkpointed" NIP and MSR, so that the note section we generate is
928 similar to the one generated by the kernel. To avoid having to
929 define additional registers in GDB which are not actually
930 checkpointed in the architecture, we copy TFHAR to the checkpointed
931 NIP slot, which is what the kernel does, and copy the regular MSR
932 to the checkpointed MSR slot, which will have a similar value in
936 ppc_linux_collect_core_cpgrregset (const struct regset
*regset
,
937 const struct regcache
*regcache
,
938 int regnum
, void *buf
, size_t len
)
940 struct gdbarch
*gdbarch
= regcache
->arch ();
941 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
943 const struct regset
*cgprregset
= ppc_linux_cgprregset (gdbarch
);
945 /* We collect the checkpointed GPRs already defined in the regular
946 regmap, then overlay TFHAR/MSR on the checkpointed NIP/MSR
948 cgprregset
->collect_regset (cgprregset
, regcache
, regnum
, buf
, len
);
950 /* Check that we are collecting all the registers, which should be
951 the case when generating a core file. */
955 /* PT_NIP and PT_MSR are 32 and 33 for powerpc. Don't redefine
956 these symbols since this file can run on clients in other
957 architectures where they can already be defined to other
961 /* Check that our buffer is long enough to hold two slots at
962 pt_offset * wordsize, one for NIP and one for MSR. */
963 gdb_assert ((pt_offset
+ 2) * tdep
->wordsize
<= len
);
965 /* TFHAR is 8 bytes wide, but the NIP slot for a 32-bit thread is
966 4-bytes long. We use raw_collect_integer which handles
967 differences in the sizes for the source and destination buffers
968 for both endian modes. */
969 (regcache
->raw_collect_integer
970 (PPC_TFHAR_REGNUM
, ((gdb_byte
*) buf
) + pt_offset
* tdep
->wordsize
,
971 tdep
->wordsize
, false));
975 (regcache
->raw_collect_integer
976 (PPC_MSR_REGNUM
, ((gdb_byte
*) buf
) + pt_offset
* tdep
->wordsize
,
977 tdep
->wordsize
, false));
980 /* Iterate over supported core file register note sections. */
983 ppc_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
984 iterate_over_regset_sections_cb
*cb
,
986 const struct regcache
*regcache
)
988 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
989 int have_altivec
= tdep
->ppc_vr0_regnum
!= -1;
990 int have_vsx
= tdep
->ppc_vsr0_upper_regnum
!= -1;
991 int have_ppr
= tdep
->ppc_ppr_regnum
!= -1;
992 int have_dscr
= tdep
->ppc_dscr_regnum
!= -1;
993 int have_tar
= tdep
->ppc_tar_regnum
!= -1;
995 if (tdep
->wordsize
== 4)
996 cb (".reg", 48 * 4, 48 * 4, &ppc32_linux_gregset
, NULL
, cb_data
);
998 cb (".reg", 48 * 8, 48 * 8, &ppc64_linux_gregset
, NULL
, cb_data
);
1000 cb (".reg2", 264, 264, &ppc32_linux_fpregset
, NULL
, cb_data
);
1004 const struct regset
*vrregset
= ppc_linux_vrregset (gdbarch
);
1005 cb (".reg-ppc-vmx", PPC_LINUX_SIZEOF_VRREGSET
, PPC_LINUX_SIZEOF_VRREGSET
,
1006 vrregset
, "ppc Altivec", cb_data
);
1010 cb (".reg-ppc-vsx", PPC_LINUX_SIZEOF_VSXREGSET
, PPC_LINUX_SIZEOF_VSXREGSET
,
1011 &ppc32_linux_vsxregset
, "POWER7 VSX", cb_data
);
1014 cb (".reg-ppc-ppr", PPC_LINUX_SIZEOF_PPRREGSET
,
1015 PPC_LINUX_SIZEOF_PPRREGSET
,
1016 &ppc32_linux_pprregset
, "Priority Program Register", cb_data
);
1019 cb (".reg-ppc-dscr", PPC_LINUX_SIZEOF_DSCRREGSET
,
1020 PPC_LINUX_SIZEOF_DSCRREGSET
,
1021 &ppc32_linux_dscrregset
, "Data Stream Control Register",
1025 cb (".reg-ppc-tar", PPC_LINUX_SIZEOF_TARREGSET
,
1026 PPC_LINUX_SIZEOF_TARREGSET
,
1027 &ppc32_linux_tarregset
, "Target Address Register", cb_data
);
1029 /* EBB registers are unavailable when ptrace returns ENODATA. Check
1030 availability when generating a core file (regcache != NULL). */
1032 if (regcache
== NULL
1033 || REG_VALID
== regcache
->get_register_status (PPC_BESCR_REGNUM
))
1034 cb (".reg-ppc-ebb", PPC_LINUX_SIZEOF_EBBREGSET
,
1035 PPC_LINUX_SIZEOF_EBBREGSET
,
1036 &ppc32_linux_ebbregset
, "Event-based Branching Registers",
1039 if (tdep
->ppc_mmcr0_regnum
!= -1)
1040 cb (".reg-ppc-pmu", PPC_LINUX_SIZEOF_PMUREGSET
,
1041 PPC_LINUX_SIZEOF_PMUREGSET
,
1042 &ppc32_linux_pmuregset
, "Performance Monitor Registers",
1045 if (tdep
->have_htm_spr
)
1046 cb (".reg-ppc-tm-spr", PPC_LINUX_SIZEOF_TM_SPRREGSET
,
1047 PPC_LINUX_SIZEOF_TM_SPRREGSET
,
1048 &ppc32_linux_tm_sprregset
,
1049 "Hardware Transactional Memory Special Purpose Registers",
1052 /* Checkpointed registers can be unavailable, don't call back if
1053 we are generating a core file. */
1055 if (tdep
->have_htm_core
)
1057 /* Only generate the checkpointed GPR core note if we also have
1058 access to the HTM SPRs, because we need TFHAR to fill the
1059 "checkpointed" NIP slot. We can read a core file without it
1060 since GDB is not aware of this NIP as a visible register. */
1061 if (regcache
== NULL
||
1062 (REG_VALID
== regcache
->get_register_status (PPC_CR0_REGNUM
)
1063 && tdep
->have_htm_spr
))
1065 int cgpr_size
= (tdep
->wordsize
== 4?
1066 PPC32_LINUX_SIZEOF_CGPRREGSET
1067 : PPC64_LINUX_SIZEOF_CGPRREGSET
);
1069 const struct regset
*cgprregset
=
1070 ppc_linux_cgprregset (gdbarch
);
1072 if (regcache
!= NULL
)
1074 struct regset core_cgprregset
= *cgprregset
;
1076 core_cgprregset
.collect_regset
1077 = ppc_linux_collect_core_cpgrregset
;
1079 cb (".reg-ppc-tm-cgpr",
1080 cgpr_size
, cgpr_size
,
1082 "Checkpointed General Purpose Registers", cb_data
);
1086 cb (".reg-ppc-tm-cgpr",
1087 cgpr_size
, cgpr_size
,
1089 "Checkpointed General Purpose Registers", cb_data
);
1094 if (tdep
->have_htm_fpu
)
1096 if (regcache
== NULL
||
1097 REG_VALID
== regcache
->get_register_status (PPC_CF0_REGNUM
))
1098 cb (".reg-ppc-tm-cfpr", PPC_LINUX_SIZEOF_CFPRREGSET
,
1099 PPC_LINUX_SIZEOF_CFPRREGSET
,
1100 &ppc32_linux_cfprregset
,
1101 "Checkpointed Floating Point Registers", cb_data
);
1104 if (tdep
->have_htm_altivec
)
1106 if (regcache
== NULL
||
1107 REG_VALID
== regcache
->get_register_status (PPC_CVR0_REGNUM
))
1109 const struct regset
*cvmxregset
=
1110 ppc_linux_cvmxregset (gdbarch
);
1112 cb (".reg-ppc-tm-cvmx", PPC_LINUX_SIZEOF_CVMXREGSET
,
1113 PPC_LINUX_SIZEOF_CVMXREGSET
,
1115 "Checkpointed Altivec (VMX) Registers", cb_data
);
1119 if (tdep
->have_htm_vsx
)
1121 if (regcache
== NULL
||
1123 == regcache
->get_register_status (PPC_CVSR0_UPPER_REGNUM
)))
1124 cb (".reg-ppc-tm-cvsx", PPC_LINUX_SIZEOF_CVSXREGSET
,
1125 PPC_LINUX_SIZEOF_CVSXREGSET
,
1126 &ppc32_linux_cvsxregset
,
1127 "Checkpointed VSX Registers", cb_data
);
1130 if (tdep
->ppc_cppr_regnum
!= -1)
1132 if (regcache
== NULL
||
1133 REG_VALID
== regcache
->get_register_status (PPC_CPPR_REGNUM
))
1134 cb (".reg-ppc-tm-cppr", PPC_LINUX_SIZEOF_CPPRREGSET
,
1135 PPC_LINUX_SIZEOF_CPPRREGSET
,
1136 &ppc32_linux_cpprregset
,
1137 "Checkpointed Priority Program Register", cb_data
);
1140 if (tdep
->ppc_cdscr_regnum
!= -1)
1142 if (regcache
== NULL
||
1143 REG_VALID
== regcache
->get_register_status (PPC_CDSCR_REGNUM
))
1144 cb (".reg-ppc-tm-cdscr", PPC_LINUX_SIZEOF_CDSCRREGSET
,
1145 PPC_LINUX_SIZEOF_CDSCRREGSET
,
1146 &ppc32_linux_cdscrregset
,
1147 "Checkpointed Data Stream Control Register", cb_data
);
1150 if (tdep
->ppc_ctar_regnum
)
1152 if ( regcache
== NULL
||
1153 REG_VALID
== regcache
->get_register_status (PPC_CTAR_REGNUM
))
1154 cb (".reg-ppc-tm-ctar", PPC_LINUX_SIZEOF_CTARREGSET
,
1155 PPC_LINUX_SIZEOF_CTARREGSET
,
1156 &ppc32_linux_ctarregset
,
1157 "Checkpointed Target Address Register", cb_data
);
1162 ppc_linux_sigtramp_cache (struct frame_info
*this_frame
,
1163 struct trad_frame_cache
*this_cache
,
1164 CORE_ADDR func
, LONGEST offset
,
1172 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1173 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1174 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1176 base
= get_frame_register_unsigned (this_frame
,
1177 gdbarch_sp_regnum (gdbarch
));
1178 if (bias
> 0 && get_frame_pc (this_frame
) != func
)
1179 /* See below, some signal trampolines increment the stack as their
1180 first instruction, need to compensate for that. */
1183 /* Find the address of the register buffer pointer. */
1184 regs
= base
+ offset
;
1185 /* Use that to find the address of the corresponding register
1187 gpregs
= read_memory_unsigned_integer (regs
, tdep
->wordsize
, byte_order
);
1188 fpregs
= gpregs
+ 48 * tdep
->wordsize
;
1190 /* General purpose. */
1191 for (i
= 0; i
< 32; i
++)
1193 int regnum
= i
+ tdep
->ppc_gp0_regnum
;
1194 trad_frame_set_reg_addr (this_cache
,
1195 regnum
, gpregs
+ i
* tdep
->wordsize
);
1197 trad_frame_set_reg_addr (this_cache
,
1198 gdbarch_pc_regnum (gdbarch
),
1199 gpregs
+ 32 * tdep
->wordsize
);
1200 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_ctr_regnum
,
1201 gpregs
+ 35 * tdep
->wordsize
);
1202 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_lr_regnum
,
1203 gpregs
+ 36 * tdep
->wordsize
);
1204 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_xer_regnum
,
1205 gpregs
+ 37 * tdep
->wordsize
);
1206 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_cr_regnum
,
1207 gpregs
+ 38 * tdep
->wordsize
);
1209 if (ppc_linux_trap_reg_p (gdbarch
))
1211 trad_frame_set_reg_addr (this_cache
, PPC_ORIG_R3_REGNUM
,
1212 gpregs
+ 34 * tdep
->wordsize
);
1213 trad_frame_set_reg_addr (this_cache
, PPC_TRAP_REGNUM
,
1214 gpregs
+ 40 * tdep
->wordsize
);
1217 if (ppc_floating_point_unit_p (gdbarch
))
1219 /* Floating point registers. */
1220 for (i
= 0; i
< 32; i
++)
1222 int regnum
= i
+ gdbarch_fp0_regnum (gdbarch
);
1223 trad_frame_set_reg_addr (this_cache
, regnum
,
1224 fpregs
+ i
* tdep
->wordsize
);
1226 trad_frame_set_reg_addr (this_cache
, tdep
->ppc_fpscr_regnum
,
1227 fpregs
+ 32 * tdep
->wordsize
);
1229 trad_frame_set_id (this_cache
, frame_id_build (base
, func
));
1233 ppc32_linux_sigaction_cache_init (const struct tramp_frame
*self
,
1234 struct frame_info
*this_frame
,
1235 struct trad_frame_cache
*this_cache
,
1238 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
1239 0xd0 /* Offset to ucontext_t. */
1240 + 0x30 /* Offset to .reg. */,
1245 ppc64_linux_sigaction_cache_init (const struct tramp_frame
*self
,
1246 struct frame_info
*this_frame
,
1247 struct trad_frame_cache
*this_cache
,
1250 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
1251 0x80 /* Offset to ucontext_t. */
1252 + 0xe0 /* Offset to .reg. */,
1257 ppc32_linux_sighandler_cache_init (const struct tramp_frame
*self
,
1258 struct frame_info
*this_frame
,
1259 struct trad_frame_cache
*this_cache
,
1262 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
1263 0x40 /* Offset to ucontext_t. */
1264 + 0x1c /* Offset to .reg. */,
1269 ppc64_linux_sighandler_cache_init (const struct tramp_frame
*self
,
1270 struct frame_info
*this_frame
,
1271 struct trad_frame_cache
*this_cache
,
1274 ppc_linux_sigtramp_cache (this_frame
, this_cache
, func
,
1275 0x80 /* Offset to struct sigcontext. */
1276 + 0x38 /* Offset to .reg. */,
1280 static struct tramp_frame ppc32_linux_sigaction_tramp_frame
= {
1284 { 0x380000ac, ULONGEST_MAX
}, /* li r0, 172 */
1285 { 0x44000002, ULONGEST_MAX
}, /* sc */
1286 { TRAMP_SENTINEL_INSN
},
1288 ppc32_linux_sigaction_cache_init
1290 static struct tramp_frame ppc64_linux_sigaction_tramp_frame
= {
1294 { 0x38210080, ULONGEST_MAX
}, /* addi r1,r1,128 */
1295 { 0x380000ac, ULONGEST_MAX
}, /* li r0, 172 */
1296 { 0x44000002, ULONGEST_MAX
}, /* sc */
1297 { TRAMP_SENTINEL_INSN
},
1299 ppc64_linux_sigaction_cache_init
1301 static struct tramp_frame ppc32_linux_sighandler_tramp_frame
= {
1305 { 0x38000077, ULONGEST_MAX
}, /* li r0,119 */
1306 { 0x44000002, ULONGEST_MAX
}, /* sc */
1307 { TRAMP_SENTINEL_INSN
},
1309 ppc32_linux_sighandler_cache_init
1311 static struct tramp_frame ppc64_linux_sighandler_tramp_frame
= {
1315 { 0x38210080, ULONGEST_MAX
}, /* addi r1,r1,128 */
1316 { 0x38000077, ULONGEST_MAX
}, /* li r0,119 */
1317 { 0x44000002, ULONGEST_MAX
}, /* sc */
1318 { TRAMP_SENTINEL_INSN
},
1320 ppc64_linux_sighandler_cache_init
1323 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
1325 ppc_linux_trap_reg_p (struct gdbarch
*gdbarch
)
1327 /* If we do not have a target description with registers, then
1328 the special registers will not be included in the register set. */
1329 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
1332 /* If we do, then it is safe to check the size. */
1333 return register_size (gdbarch
, PPC_ORIG_R3_REGNUM
) > 0
1334 && register_size (gdbarch
, PPC_TRAP_REGNUM
) > 0;
1337 /* Return the current system call's number present in the
1338 r0 register. When the function fails, it returns -1. */
1340 ppc_linux_get_syscall_number (struct gdbarch
*gdbarch
,
1341 thread_info
*thread
)
1343 struct regcache
*regcache
= get_thread_regcache (thread
);
1344 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1345 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1347 /* Make sure we're in a 32- or 64-bit machine */
1348 gdb_assert (tdep
->wordsize
== 4 || tdep
->wordsize
== 8);
1350 /* The content of a register */
1351 gdb::byte_vector
buf (tdep
->wordsize
);
1353 /* Getting the system call number from the register.
1354 When dealing with PowerPC architecture, this information
1355 is stored at 0th register. */
1356 regcache
->cooked_read (tdep
->ppc_gp0_regnum
, buf
.data ());
1358 return extract_signed_integer (buf
.data (), tdep
->wordsize
, byte_order
);
1361 /* PPC process record-replay */
1363 static struct linux_record_tdep ppc_linux_record_tdep
;
1364 static struct linux_record_tdep ppc64_linux_record_tdep
;
1366 /* ppc_canonicalize_syscall maps from the native PowerPC Linux set of
1367 syscall ids into a canonical set of syscall ids used by process
1368 record. (See arch/powerpc/include/uapi/asm/unistd.h in kernel tree.)
1369 Return -1 if this system call is not supported by process record.
1370 Otherwise, return the syscall number for process record of given
1373 static enum gdb_syscall
1374 ppc_canonicalize_syscall (int syscall
, int wordsize
)
1380 else if (syscall
>= 167 && syscall
<= 190) /* Skip query_module 166 */
1381 result
= syscall
+ 1;
1382 else if (syscall
>= 192 && syscall
<= 197) /* mmap2 */
1384 else if (syscall
== 208) /* tkill */
1385 result
= gdb_sys_tkill
;
1386 else if (syscall
>= 207 && syscall
<= 220) /* gettid */
1387 result
= syscall
+ 224 - 207;
1388 else if (syscall
>= 234 && syscall
<= 239) /* exit_group */
1389 result
= syscall
+ 252 - 234;
1390 else if (syscall
>= 240 && syscall
<= 248) /* timer_create */
1391 result
= syscall
+= 259 - 240;
1392 else if (syscall
>= 250 && syscall
<= 251) /* tgkill */
1393 result
= syscall
+ 270 - 250;
1394 else if (syscall
== 286)
1395 result
= gdb_sys_openat
;
1396 else if (syscall
== 291)
1399 result
= gdb_sys_newfstatat
;
1401 result
= gdb_sys_fstatat64
;
1403 else if (syscall
== 336)
1404 result
= gdb_sys_recv
;
1405 else if (syscall
== 337)
1406 result
= gdb_sys_recvfrom
;
1407 else if (syscall
== 342)
1408 result
= gdb_sys_recvmsg
;
1410 return (enum gdb_syscall
) result
;
1413 /* Record registers which might be clobbered during system call.
1414 Return 0 if successful. */
1417 ppc_linux_syscall_record (struct regcache
*regcache
)
1419 struct gdbarch
*gdbarch
= regcache
->arch ();
1420 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1422 enum gdb_syscall syscall_gdb
;
1425 regcache_raw_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
, &scnum
);
1426 syscall_gdb
= ppc_canonicalize_syscall (scnum
, tdep
->wordsize
);
1428 if (syscall_gdb
< 0)
1430 gdb_printf (gdb_stderr
,
1431 _("Process record and replay target doesn't "
1432 "support syscall number %d\n"), (int) scnum
);
1436 if (syscall_gdb
== gdb_sys_sigreturn
1437 || syscall_gdb
== gdb_sys_rt_sigreturn
)
1440 int regsets
[] = { tdep
->ppc_gp0_regnum
,
1441 tdep
->ppc_fp0_regnum
,
1442 tdep
->ppc_vr0_regnum
,
1443 tdep
->ppc_vsr0_upper_regnum
};
1445 for (j
= 0; j
< 4; j
++)
1447 if (regsets
[j
] == -1)
1449 for (i
= 0; i
< 32; i
++)
1451 if (record_full_arch_list_add_reg (regcache
, regsets
[j
] + i
))
1456 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_cr_regnum
))
1458 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_ctr_regnum
))
1460 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_lr_regnum
))
1462 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_xer_regnum
))
1468 if (tdep
->wordsize
== 8)
1469 ret
= record_linux_system_call (syscall_gdb
, regcache
,
1470 &ppc64_linux_record_tdep
);
1472 ret
= record_linux_system_call (syscall_gdb
, regcache
,
1473 &ppc_linux_record_tdep
);
1478 /* Record registers clobbered during syscall. */
1479 for (int i
= 3; i
<= 12; i
++)
1481 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_gp0_regnum
+ i
))
1484 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_gp0_regnum
+ 0))
1486 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_cr_regnum
))
1488 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_ctr_regnum
))
1490 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_lr_regnum
))
1496 /* Record registers which might be clobbered during signal handling.
1497 Return 0 if successful. */
1500 ppc_linux_record_signal (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1501 enum gdb_signal signal
)
1503 /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c
1504 handle_rt_signal32 in arch/powerpc/kernel/signal_32.c
1505 arch/powerpc/include/asm/ptrace.h
1507 const int SIGNAL_FRAMESIZE
= 128;
1508 const int sizeof_rt_sigframe
= 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
1510 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
1513 for (i
= 3; i
<= 12; i
++)
1515 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_gp0_regnum
+ i
))
1519 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_lr_regnum
))
1521 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_cr_regnum
))
1523 if (record_full_arch_list_add_reg (regcache
, tdep
->ppc_ctr_regnum
))
1525 if (record_full_arch_list_add_reg (regcache
, gdbarch_pc_regnum (gdbarch
)))
1527 if (record_full_arch_list_add_reg (regcache
, gdbarch_sp_regnum (gdbarch
)))
1530 /* Record the change in the stack.
1531 frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
1532 regcache_raw_read_unsigned (regcache
, gdbarch_sp_regnum (gdbarch
), &sp
);
1533 sp
-= SIGNAL_FRAMESIZE
;
1534 sp
-= sizeof_rt_sigframe
;
1536 if (record_full_arch_list_add_mem (sp
, SIGNAL_FRAMESIZE
+ sizeof_rt_sigframe
))
1539 if (record_full_arch_list_add_end ())
1546 ppc_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1548 struct gdbarch
*gdbarch
= regcache
->arch ();
1550 regcache_cooked_write_unsigned (regcache
, gdbarch_pc_regnum (gdbarch
), pc
);
1552 /* Set special TRAP register to -1 to prevent the kernel from
1553 messing with the PC we just installed, if we happen to be
1554 within an interrupted system call that the kernel wants to
1557 Note that after we return from the dummy call, the TRAP and
1558 ORIG_R3 registers will be automatically restored, and the
1559 kernel continues to restart the system call at this point. */
1560 if (ppc_linux_trap_reg_p (gdbarch
))
1561 regcache_cooked_write_unsigned (regcache
, PPC_TRAP_REGNUM
, -1);
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
*altivec
= bfd_get_section_by_name (abfd
, ".reg-ppc-vmx");
1571 asection
*vsx
= bfd_get_section_by_name (abfd
, ".reg-ppc-vsx");
1572 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
1573 asection
*ppr
= bfd_get_section_by_name (abfd
, ".reg-ppc-ppr");
1574 asection
*dscr
= bfd_get_section_by_name (abfd
, ".reg-ppc-dscr");
1575 asection
*tar
= bfd_get_section_by_name (abfd
, ".reg-ppc-tar");
1576 asection
*pmu
= bfd_get_section_by_name (abfd
, ".reg-ppc-pmu");
1577 asection
*htmspr
= bfd_get_section_by_name (abfd
, ".reg-ppc-tm-spr");
1582 switch (bfd_section_size (section
))
1585 features
.wordsize
= 4;
1588 features
.wordsize
= 8;
1595 features
.altivec
= true;
1598 features
.vsx
= true;
1600 CORE_ADDR hwcap
= linux_get_hwcap (target
);
1602 features
.isa205
= ppc_linux_has_isa205 (hwcap
);
1606 features
.ppr_dscr
= true;
1608 /* We don't require the EBB note section to be present in the
1609 core file to select isa207 because these registers could have
1610 been unavailable when the core file was created. They will
1611 be in the tdep but will show as unavailable. */
1614 features
.isa207
= true;
1616 features
.htm
= true;
1620 return ppc_linux_match_description (features
);
1624 /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
1625 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1628 ppc_elfv2_elf_make_msymbol_special (asymbol
*sym
, struct minimal_symbol
*msym
)
1630 elf_symbol_type
*elf_sym
= (elf_symbol_type
*)sym
;
1632 /* If the symbol is marked as having a local entry point, set a target
1633 flag in the msymbol. We currently only support local entry point
1634 offsets of 8 bytes, which is the only entry point offset ever used
1635 by current compilers. If/when other offsets are ever used, we will
1636 have to use additional target flag bits to store them. */
1637 switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym
->internal_elf_sym
.st_other
))
1642 msym
->set_target_flag_1 (true);
1647 /* Implementation of `gdbarch_skip_entrypoint', as defined in
1648 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1651 ppc_elfv2_skip_entrypoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1653 struct bound_minimal_symbol fun
;
1654 int local_entry_offset
= 0;
1656 fun
= lookup_minimal_symbol_by_pc (pc
);
1657 if (fun
.minsym
== NULL
)
1660 /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
1661 offset values are encoded. */
1662 if (fun
.minsym
->target_flag_1 ())
1663 local_entry_offset
= 8;
1665 if (fun
.value_address () <= pc
1666 && pc
< fun
.value_address () + local_entry_offset
)
1667 return fun
.value_address () + local_entry_offset
;
1672 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1676 ppc_stap_is_single_operand (struct gdbarch
*gdbarch
, const char *s
)
1678 return (*s
== 'i' /* Literal number. */
1679 || (isdigit (*s
) && s
[1] == '('
1680 && isdigit (s
[2])) /* Displacement. */
1681 || (*s
== '(' && isdigit (s
[1])) /* Register indirection. */
1682 || isdigit (*s
)); /* Register value. */
1685 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
1688 static expr::operation_up
1689 ppc_stap_parse_special_token (struct gdbarch
*gdbarch
,
1690 struct stap_parse_info
*p
)
1692 if (isdigit (*p
->arg
))
1694 /* This temporary pointer is needed because we have to do a lookahead.
1695 We could be dealing with a register displacement, and in such case
1696 we would not need to do anything. */
1697 const char *s
= p
->arg
;
1701 while (isdigit (*s
))
1706 /* It is a register displacement indeed. Returning 0 means we are
1707 deferring the treatment of this case to the generic parser. */
1712 regname
= (char *) alloca (len
+ 2);
1715 strncpy (regname
+ 1, p
->arg
, len
);
1717 regname
[len
] = '\0';
1719 if (user_reg_map_name_to_regnum (gdbarch
, regname
, len
) == -1)
1720 error (_("Invalid register name `%s' on expression `%s'."),
1721 regname
, p
->saved_arg
);
1725 return expr::make_operation
<expr::register_operation
> (regname
);
1728 /* All the other tokens should be handled correctly by the generic
1733 /* Initialize linux_record_tdep if not initialized yet.
1734 WORDSIZE is 4 or 8 for 32- or 64-bit PowerPC Linux respectively.
1735 Sizes of data structures are initialized accordingly. */
1738 ppc_init_linux_record_tdep (struct linux_record_tdep
*record_tdep
,
1741 /* The values for TCGETS, TCSETS, TCSETSW, TCSETSF are based on the
1742 size of struct termios in the kernel source.
1743 include/uapi/asm-generic/termbits.h */
1744 #define SIZE_OF_STRUCT_TERMIOS 0x2c
1746 /* Simply return if it had been initialized. */
1747 if (record_tdep
->size_pointer
!= 0)
1750 /* These values are the size of the type that will be used in a system
1751 call. They are obtained from Linux Kernel source. */
1755 record_tdep
->size_pointer
= 8;
1756 record_tdep
->size__old_kernel_stat
= 32;
1757 record_tdep
->size_tms
= 32;
1758 record_tdep
->size_loff_t
= 8;
1759 record_tdep
->size_flock
= 32;
1760 record_tdep
->size_oldold_utsname
= 45;
1761 record_tdep
->size_ustat
= 32;
1762 record_tdep
->size_old_sigaction
= 32;
1763 record_tdep
->size_old_sigset_t
= 8;
1764 record_tdep
->size_rlimit
= 16;
1765 record_tdep
->size_rusage
= 144;
1766 record_tdep
->size_timeval
= 16;
1767 record_tdep
->size_timezone
= 8;
1768 record_tdep
->size_old_gid_t
= 4;
1769 record_tdep
->size_old_uid_t
= 4;
1770 record_tdep
->size_fd_set
= 128;
1771 record_tdep
->size_old_dirent
= 280;
1772 record_tdep
->size_statfs
= 120;
1773 record_tdep
->size_statfs64
= 120;
1774 record_tdep
->size_sockaddr
= 16;
1775 record_tdep
->size_int
= 4;
1776 record_tdep
->size_long
= 8;
1777 record_tdep
->size_ulong
= 8;
1778 record_tdep
->size_msghdr
= 56;
1779 record_tdep
->size_itimerval
= 32;
1780 record_tdep
->size_stat
= 144;
1781 record_tdep
->size_old_utsname
= 325;
1782 record_tdep
->size_sysinfo
= 112;
1783 record_tdep
->size_msqid_ds
= 120;
1784 record_tdep
->size_shmid_ds
= 112;
1785 record_tdep
->size_new_utsname
= 390;
1786 record_tdep
->size_timex
= 208;
1787 record_tdep
->size_mem_dqinfo
= 24;
1788 record_tdep
->size_if_dqblk
= 72;
1789 record_tdep
->size_fs_quota_stat
= 80;
1790 record_tdep
->size_timespec
= 16;
1791 record_tdep
->size_pollfd
= 8;
1792 record_tdep
->size_NFS_FHSIZE
= 32;
1793 record_tdep
->size_knfsd_fh
= 132;
1794 record_tdep
->size_TASK_COMM_LEN
= 16;
1795 record_tdep
->size_sigaction
= 32;
1796 record_tdep
->size_sigset_t
= 8;
1797 record_tdep
->size_siginfo_t
= 128;
1798 record_tdep
->size_cap_user_data_t
= 8;
1799 record_tdep
->size_stack_t
= 24;
1800 record_tdep
->size_off_t
= 8;
1801 record_tdep
->size_stat64
= 104;
1802 record_tdep
->size_gid_t
= 4;
1803 record_tdep
->size_uid_t
= 4;
1804 record_tdep
->size_PAGE_SIZE
= 0x10000; /* 64KB */
1805 record_tdep
->size_flock64
= 32;
1806 record_tdep
->size_io_event
= 32;
1807 record_tdep
->size_iocb
= 64;
1808 record_tdep
->size_epoll_event
= 16;
1809 record_tdep
->size_itimerspec
= 32;
1810 record_tdep
->size_mq_attr
= 64;
1811 record_tdep
->size_termios
= 44;
1812 record_tdep
->size_pid_t
= 4;
1813 record_tdep
->size_winsize
= 8;
1814 record_tdep
->size_serial_struct
= 72;
1815 record_tdep
->size_serial_icounter_struct
= 80;
1816 record_tdep
->size_size_t
= 8;
1817 record_tdep
->size_iovec
= 16;
1818 record_tdep
->size_time_t
= 8;
1820 else if (wordsize
== 4)
1822 record_tdep
->size_pointer
= 4;
1823 record_tdep
->size__old_kernel_stat
= 32;
1824 record_tdep
->size_tms
= 16;
1825 record_tdep
->size_loff_t
= 8;
1826 record_tdep
->size_flock
= 16;
1827 record_tdep
->size_oldold_utsname
= 45;
1828 record_tdep
->size_ustat
= 20;
1829 record_tdep
->size_old_sigaction
= 16;
1830 record_tdep
->size_old_sigset_t
= 4;
1831 record_tdep
->size_rlimit
= 8;
1832 record_tdep
->size_rusage
= 72;
1833 record_tdep
->size_timeval
= 8;
1834 record_tdep
->size_timezone
= 8;
1835 record_tdep
->size_old_gid_t
= 4;
1836 record_tdep
->size_old_uid_t
= 4;
1837 record_tdep
->size_fd_set
= 128;
1838 record_tdep
->size_old_dirent
= 268;
1839 record_tdep
->size_statfs
= 64;
1840 record_tdep
->size_statfs64
= 88;
1841 record_tdep
->size_sockaddr
= 16;
1842 record_tdep
->size_int
= 4;
1843 record_tdep
->size_long
= 4;
1844 record_tdep
->size_ulong
= 4;
1845 record_tdep
->size_msghdr
= 28;
1846 record_tdep
->size_itimerval
= 16;
1847 record_tdep
->size_stat
= 88;
1848 record_tdep
->size_old_utsname
= 325;
1849 record_tdep
->size_sysinfo
= 64;
1850 record_tdep
->size_msqid_ds
= 68;
1851 record_tdep
->size_shmid_ds
= 60;
1852 record_tdep
->size_new_utsname
= 390;
1853 record_tdep
->size_timex
= 128;
1854 record_tdep
->size_mem_dqinfo
= 24;
1855 record_tdep
->size_if_dqblk
= 72;
1856 record_tdep
->size_fs_quota_stat
= 80;
1857 record_tdep
->size_timespec
= 8;
1858 record_tdep
->size_pollfd
= 8;
1859 record_tdep
->size_NFS_FHSIZE
= 32;
1860 record_tdep
->size_knfsd_fh
= 132;
1861 record_tdep
->size_TASK_COMM_LEN
= 16;
1862 record_tdep
->size_sigaction
= 20;
1863 record_tdep
->size_sigset_t
= 8;
1864 record_tdep
->size_siginfo_t
= 128;
1865 record_tdep
->size_cap_user_data_t
= 4;
1866 record_tdep
->size_stack_t
= 12;
1867 record_tdep
->size_off_t
= 4;
1868 record_tdep
->size_stat64
= 104;
1869 record_tdep
->size_gid_t
= 4;
1870 record_tdep
->size_uid_t
= 4;
1871 record_tdep
->size_PAGE_SIZE
= 0x10000; /* 64KB */
1872 record_tdep
->size_flock64
= 32;
1873 record_tdep
->size_io_event
= 32;
1874 record_tdep
->size_iocb
= 64;
1875 record_tdep
->size_epoll_event
= 16;
1876 record_tdep
->size_itimerspec
= 16;
1877 record_tdep
->size_mq_attr
= 32;
1878 record_tdep
->size_termios
= 44;
1879 record_tdep
->size_pid_t
= 4;
1880 record_tdep
->size_winsize
= 8;
1881 record_tdep
->size_serial_struct
= 60;
1882 record_tdep
->size_serial_icounter_struct
= 80;
1883 record_tdep
->size_size_t
= 4;
1884 record_tdep
->size_iovec
= 8;
1885 record_tdep
->size_time_t
= 4;
1888 internal_error (__FILE__
, __LINE__
, _("unexpected wordsize"));
1890 /* These values are the second argument of system call "sys_fcntl"
1891 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1892 record_tdep
->fcntl_F_GETLK
= 5;
1893 record_tdep
->fcntl_F_GETLK64
= 12;
1894 record_tdep
->fcntl_F_SETLK64
= 13;
1895 record_tdep
->fcntl_F_SETLKW64
= 14;
1897 record_tdep
->arg1
= PPC_R0_REGNUM
+ 3;
1898 record_tdep
->arg2
= PPC_R0_REGNUM
+ 4;
1899 record_tdep
->arg3
= PPC_R0_REGNUM
+ 5;
1900 record_tdep
->arg4
= PPC_R0_REGNUM
+ 6;
1901 record_tdep
->arg5
= PPC_R0_REGNUM
+ 7;
1902 record_tdep
->arg6
= PPC_R0_REGNUM
+ 8;
1904 /* These values are the second argument of system call "sys_ioctl".
1905 They are obtained from Linux Kernel source.
1906 See arch/powerpc/include/uapi/asm/ioctls.h. */
1907 record_tdep
->ioctl_TCGETA
= 0x40147417;
1908 record_tdep
->ioctl_TCSETA
= 0x80147418;
1909 record_tdep
->ioctl_TCSETAW
= 0x80147419;
1910 record_tdep
->ioctl_TCSETAF
= 0x8014741c;
1911 record_tdep
->ioctl_TCGETS
= 0x40007413 | (SIZE_OF_STRUCT_TERMIOS
<< 16);
1912 record_tdep
->ioctl_TCSETS
= 0x80007414 | (SIZE_OF_STRUCT_TERMIOS
<< 16);
1913 record_tdep
->ioctl_TCSETSW
= 0x80007415 | (SIZE_OF_STRUCT_TERMIOS
<< 16);
1914 record_tdep
->ioctl_TCSETSF
= 0x80007416 | (SIZE_OF_STRUCT_TERMIOS
<< 16);
1916 record_tdep
->ioctl_TCSBRK
= 0x2000741d;
1917 record_tdep
->ioctl_TCXONC
= 0x2000741e;
1918 record_tdep
->ioctl_TCFLSH
= 0x2000741f;
1919 record_tdep
->ioctl_TIOCEXCL
= 0x540c;
1920 record_tdep
->ioctl_TIOCNXCL
= 0x540d;
1921 record_tdep
->ioctl_TIOCSCTTY
= 0x540e;
1922 record_tdep
->ioctl_TIOCGPGRP
= 0x40047477;
1923 record_tdep
->ioctl_TIOCSPGRP
= 0x80047476;
1924 record_tdep
->ioctl_TIOCOUTQ
= 0x40047473;
1925 record_tdep
->ioctl_TIOCSTI
= 0x5412;
1926 record_tdep
->ioctl_TIOCGWINSZ
= 0x40087468;
1927 record_tdep
->ioctl_TIOCSWINSZ
= 0x80087467;
1928 record_tdep
->ioctl_TIOCMGET
= 0x5415;
1929 record_tdep
->ioctl_TIOCMBIS
= 0x5416;
1930 record_tdep
->ioctl_TIOCMBIC
= 0x5417;
1931 record_tdep
->ioctl_TIOCMSET
= 0x5418;
1932 record_tdep
->ioctl_TIOCGSOFTCAR
= 0x5419;
1933 record_tdep
->ioctl_TIOCSSOFTCAR
= 0x541a;
1934 record_tdep
->ioctl_FIONREAD
= 0x4004667f;
1935 record_tdep
->ioctl_TIOCINQ
= 0x4004667f;
1936 record_tdep
->ioctl_TIOCLINUX
= 0x541c;
1937 record_tdep
->ioctl_TIOCCONS
= 0x541d;
1938 record_tdep
->ioctl_TIOCGSERIAL
= 0x541e;
1939 record_tdep
->ioctl_TIOCSSERIAL
= 0x541f;
1940 record_tdep
->ioctl_TIOCPKT
= 0x5420;
1941 record_tdep
->ioctl_FIONBIO
= 0x8004667e;
1942 record_tdep
->ioctl_TIOCNOTTY
= 0x5422;
1943 record_tdep
->ioctl_TIOCSETD
= 0x5423;
1944 record_tdep
->ioctl_TIOCGETD
= 0x5424;
1945 record_tdep
->ioctl_TCSBRKP
= 0x5425;
1946 record_tdep
->ioctl_TIOCSBRK
= 0x5427;
1947 record_tdep
->ioctl_TIOCCBRK
= 0x5428;
1948 record_tdep
->ioctl_TIOCGSID
= 0x5429;
1949 record_tdep
->ioctl_TIOCGPTN
= 0x40045430;
1950 record_tdep
->ioctl_TIOCSPTLCK
= 0x80045431;
1951 record_tdep
->ioctl_FIONCLEX
= 0x20006602;
1952 record_tdep
->ioctl_FIOCLEX
= 0x20006601;
1953 record_tdep
->ioctl_FIOASYNC
= 0x8004667d;
1954 record_tdep
->ioctl_TIOCSERCONFIG
= 0x5453;
1955 record_tdep
->ioctl_TIOCSERGWILD
= 0x5454;
1956 record_tdep
->ioctl_TIOCSERSWILD
= 0x5455;
1957 record_tdep
->ioctl_TIOCGLCKTRMIOS
= 0x5456;
1958 record_tdep
->ioctl_TIOCSLCKTRMIOS
= 0x5457;
1959 record_tdep
->ioctl_TIOCSERGSTRUCT
= 0x5458;
1960 record_tdep
->ioctl_TIOCSERGETLSR
= 0x5459;
1961 record_tdep
->ioctl_TIOCSERGETMULTI
= 0x545a;
1962 record_tdep
->ioctl_TIOCSERSETMULTI
= 0x545b;
1963 record_tdep
->ioctl_TIOCMIWAIT
= 0x545c;
1964 record_tdep
->ioctl_TIOCGICOUNT
= 0x545d;
1965 record_tdep
->ioctl_FIOQSIZE
= 0x40086680;
1968 /* Return a floating-point format for a floating-point variable of
1969 length LEN in bits. If non-NULL, NAME is the name of its type.
1970 If no suitable type is found, return NULL. */
1972 static const struct floatformat
**
1973 ppc_floatformat_for_type (struct gdbarch
*gdbarch
,
1974 const char *name
, int len
)
1976 if (len
== 128 && name
)
1978 if (strcmp (name
, "__float128") == 0
1979 || strcmp (name
, "_Float128") == 0
1980 || strcmp (name
, "_Float64x") == 0
1981 || strcmp (name
, "complex _Float128") == 0
1982 || strcmp (name
, "complex _Float64x") == 0)
1983 return floatformats_ieee_quad
;
1985 if (strcmp (name
, "__ibm128") == 0)
1986 return floatformats_ibm_long_double
;
1989 return default_floatformat_for_type (gdbarch
, name
, len
);
1992 /* Specify the powerpc64le target triplet.
1993 This can be variations of
1994 ppc64le-{distro}-linux-gcc
1996 powerpc64le-{distro}-linux-gcc. */
1999 ppc64le_gnu_triplet_regexp (struct gdbarch
*gdbarch
)
2001 return "p(ower)?pc64le";
2004 /* Specify the powerpc64 target triplet.
2005 This can be variations of
2006 ppc64-{distro}-linux-gcc
2008 powerpc64-{distro}-linux-gcc. */
2011 ppc64_gnu_triplet_regexp (struct gdbarch
*gdbarch
)
2013 return "p(ower)?pc64";
2016 /* Implement the linux_gcc_target_options method. */
2019 ppc64_linux_gcc_target_options (struct gdbarch
*gdbarch
)
2024 static displaced_step_prepare_status
2025 ppc_linux_displaced_step_prepare (gdbarch
*arch
, thread_info
*thread
,
2026 CORE_ADDR
&displaced_pc
)
2028 ppc_inferior_data
*per_inferior
= get_ppc_per_inferior (thread
->inf
);
2029 if (!per_inferior
->disp_step_buf
.has_value ())
2031 /* Figure out where the displaced step buffer is. */
2032 CORE_ADDR disp_step_buf_addr
2033 = linux_displaced_step_location (thread
->inf
->gdbarch
);
2035 per_inferior
->disp_step_buf
.emplace (disp_step_buf_addr
);
2038 return per_inferior
->disp_step_buf
->prepare (thread
, displaced_pc
);
2042 ppc_linux_init_abi (struct gdbarch_info info
,
2043 struct gdbarch
*gdbarch
)
2045 ppc_gdbarch_tdep
*tdep
= (ppc_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
2046 struct tdesc_arch_data
*tdesc_data
= info
.tdesc_data
;
2047 static const char *const stap_integer_prefixes
[] = { "i", NULL
};
2048 static const char *const stap_register_indirection_prefixes
[] = { "(",
2050 static const char *const stap_register_indirection_suffixes
[] = { ")",
2053 linux_init_abi (info
, gdbarch
, 0);
2055 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
2056 128-bit, they can be either IBM long double or IEEE quad long double.
2057 The 64-bit long double case will be detected automatically using
2058 the size specified in debug info. We use a .gnu.attribute flag
2059 to distinguish between the IBM long double and IEEE quad cases. */
2060 set_gdbarch_long_double_bit (gdbarch
, 16 * TARGET_CHAR_BIT
);
2061 if (tdep
->long_double_abi
== POWERPC_LONG_DOUBLE_IEEE128
)
2062 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_quad
);
2064 set_gdbarch_long_double_format (gdbarch
, floatformats_ibm_long_double
);
2066 /* Support for floating-point data type variants. */
2067 set_gdbarch_floatformat_for_type (gdbarch
, ppc_floatformat_for_type
);
2069 /* Handle inferior calls during interrupted system calls. */
2070 set_gdbarch_write_pc (gdbarch
, ppc_linux_write_pc
);
2072 /* Get the syscall number from the arch's register. */
2073 set_gdbarch_get_syscall_number (gdbarch
, ppc_linux_get_syscall_number
);
2075 /* SystemTap functions. */
2076 set_gdbarch_stap_integer_prefixes (gdbarch
, stap_integer_prefixes
);
2077 set_gdbarch_stap_register_indirection_prefixes (gdbarch
,
2078 stap_register_indirection_prefixes
);
2079 set_gdbarch_stap_register_indirection_suffixes (gdbarch
,
2080 stap_register_indirection_suffixes
);
2081 set_gdbarch_stap_gdb_register_prefix (gdbarch
, "r");
2082 set_gdbarch_stap_is_single_operand (gdbarch
, ppc_stap_is_single_operand
);
2083 set_gdbarch_stap_parse_special_token (gdbarch
,
2084 ppc_stap_parse_special_token
);
2086 if (tdep
->wordsize
== 4)
2088 /* Until November 2001, gcc did not comply with the 32 bit SysV
2089 R4 ABI requirement that structures less than or equal to 8
2090 bytes should be returned in registers. Instead GCC was using
2091 the AIX/PowerOpen ABI - everything returned in memory
2092 (well ignoring vectors that is). When this was corrected, it
2093 wasn't fixed for GNU/Linux native platform. Use the
2094 PowerOpen struct convention. */
2095 set_gdbarch_return_value (gdbarch
, ppc_linux_return_value
);
2097 set_gdbarch_memory_remove_breakpoint (gdbarch
,
2098 ppc_linux_memory_remove_breakpoint
);
2100 /* Shared library handling. */
2101 set_gdbarch_skip_trampoline_code (gdbarch
, ppc_skip_trampoline_code
);
2102 set_solib_svr4_fetch_link_map_offsets
2103 (gdbarch
, linux_ilp32_fetch_link_map_offsets
);
2105 /* Setting the correct XML syscall filename. */
2106 set_xml_syscall_file_name (gdbarch
, XML_SYSCALL_FILENAME_PPC
);
2109 tramp_frame_prepend_unwinder (gdbarch
,
2110 &ppc32_linux_sigaction_tramp_frame
);
2111 tramp_frame_prepend_unwinder (gdbarch
,
2112 &ppc32_linux_sighandler_tramp_frame
);
2114 /* BFD target for core files. */
2115 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
2116 set_gdbarch_gcore_bfd_target (gdbarch
, "elf32-powerpcle");
2118 set_gdbarch_gcore_bfd_target (gdbarch
, "elf32-powerpc");
2120 if (powerpc_so_ops
.in_dynsym_resolve_code
== NULL
)
2122 powerpc_so_ops
= svr4_so_ops
;
2123 /* Override dynamic resolve function. */
2124 powerpc_so_ops
.in_dynsym_resolve_code
=
2125 powerpc_linux_in_dynsym_resolve_code
;
2127 set_solib_ops (gdbarch
, &powerpc_so_ops
);
2129 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
2132 if (tdep
->wordsize
== 8)
2134 if (tdep
->elf_abi
== POWERPC_ELF_V1
)
2136 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
2137 function descriptors). */
2138 set_gdbarch_convert_from_func_ptr_addr
2139 (gdbarch
, ppc64_convert_from_func_ptr_addr
);
2141 set_gdbarch_elf_make_msymbol_special
2142 (gdbarch
, ppc64_elf_make_msymbol_special
);
2146 set_gdbarch_elf_make_msymbol_special
2147 (gdbarch
, ppc_elfv2_elf_make_msymbol_special
);
2149 set_gdbarch_skip_entrypoint (gdbarch
, ppc_elfv2_skip_entrypoint
);
2152 /* Shared library handling. */
2153 set_gdbarch_skip_trampoline_code (gdbarch
, ppc64_skip_trampoline_code
);
2154 set_solib_svr4_fetch_link_map_offsets
2155 (gdbarch
, linux_lp64_fetch_link_map_offsets
);
2157 /* Setting the correct XML syscall filename. */
2158 set_xml_syscall_file_name (gdbarch
, XML_SYSCALL_FILENAME_PPC64
);
2161 tramp_frame_prepend_unwinder (gdbarch
,
2162 &ppc64_linux_sigaction_tramp_frame
);
2163 tramp_frame_prepend_unwinder (gdbarch
,
2164 &ppc64_linux_sighandler_tramp_frame
);
2166 /* BFD target for core files. */
2167 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
2168 set_gdbarch_gcore_bfd_target (gdbarch
, "elf64-powerpcle");
2170 set_gdbarch_gcore_bfd_target (gdbarch
, "elf64-powerpc");
2171 /* Set compiler triplet. */
2172 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
2173 set_gdbarch_gnu_triplet_regexp (gdbarch
, ppc64le_gnu_triplet_regexp
);
2175 set_gdbarch_gnu_triplet_regexp (gdbarch
, ppc64_gnu_triplet_regexp
);
2176 /* Set GCC target options. */
2177 set_gdbarch_gcc_target_options (gdbarch
, ppc64_linux_gcc_target_options
);
2180 set_gdbarch_core_read_description (gdbarch
, ppc_linux_core_read_description
);
2181 set_gdbarch_iterate_over_regset_sections (gdbarch
,
2182 ppc_linux_iterate_over_regset_sections
);
2184 /* Enable TLS support. */
2185 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
2186 svr4_fetch_objfile_link_map
);
2190 const struct tdesc_feature
*feature
;
2192 /* If we have target-described registers, then we can safely
2193 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
2194 (whether they are described or not). */
2195 gdb_assert (gdbarch_num_regs (gdbarch
) <= PPC_ORIG_R3_REGNUM
);
2196 set_gdbarch_num_regs (gdbarch
, PPC_TRAP_REGNUM
+ 1);
2198 /* If they are present, then assign them to the reserved number. */
2199 feature
= tdesc_find_feature (info
.target_desc
,
2200 "org.gnu.gdb.power.linux");
2201 if (feature
!= NULL
)
2203 tdesc_numbered_register (feature
, tdesc_data
,
2204 PPC_ORIG_R3_REGNUM
, "orig_r3");
2205 tdesc_numbered_register (feature
, tdesc_data
,
2206 PPC_TRAP_REGNUM
, "trap");
2210 /* Support reverse debugging. */
2211 set_gdbarch_process_record (gdbarch
, ppc_process_record
);
2212 set_gdbarch_process_record_signal (gdbarch
, ppc_linux_record_signal
);
2213 tdep
->ppc_syscall_record
= ppc_linux_syscall_record
;
2215 ppc_init_linux_record_tdep (&ppc_linux_record_tdep
, 4);
2216 ppc_init_linux_record_tdep (&ppc64_linux_record_tdep
, 8);
2218 /* Setup displaced stepping. */
2219 set_gdbarch_displaced_step_prepare (gdbarch
,
2220 ppc_linux_displaced_step_prepare
);
2224 void _initialize_ppc_linux_tdep ();
2226 _initialize_ppc_linux_tdep ()
2228 /* Register for all sub-families of the POWER/PowerPC: 32-bit and
2229 64-bit PowerPC, and the older rs6k. */
2230 gdbarch_register_osabi (bfd_arch_powerpc
, bfd_mach_ppc
, GDB_OSABI_LINUX
,
2231 ppc_linux_init_abi
);
2232 gdbarch_register_osabi (bfd_arch_powerpc
, bfd_mach_ppc64
, GDB_OSABI_LINUX
,
2233 ppc_linux_init_abi
);
2234 gdbarch_register_osabi (bfd_arch_rs6000
, bfd_mach_rs6k
, GDB_OSABI_LINUX
,
2235 ppc_linux_init_abi
);
2237 /* Initialize the Linux target descriptions. */
2238 initialize_tdesc_powerpc_32l ();
2239 initialize_tdesc_powerpc_altivec32l ();
2240 initialize_tdesc_powerpc_vsx32l ();
2241 initialize_tdesc_powerpc_isa205_32l ();
2242 initialize_tdesc_powerpc_isa205_altivec32l ();
2243 initialize_tdesc_powerpc_isa205_vsx32l ();
2244 initialize_tdesc_powerpc_isa205_ppr_dscr_vsx32l ();
2245 initialize_tdesc_powerpc_isa207_vsx32l ();
2246 initialize_tdesc_powerpc_isa207_htm_vsx32l ();
2247 initialize_tdesc_powerpc_64l ();
2248 initialize_tdesc_powerpc_altivec64l ();
2249 initialize_tdesc_powerpc_vsx64l ();
2250 initialize_tdesc_powerpc_isa205_64l ();
2251 initialize_tdesc_powerpc_isa205_altivec64l ();
2252 initialize_tdesc_powerpc_isa205_vsx64l ();
2253 initialize_tdesc_powerpc_isa205_ppr_dscr_vsx64l ();
2254 initialize_tdesc_powerpc_isa207_vsx64l ();
2255 initialize_tdesc_powerpc_isa207_htm_vsx64l ();
2256 initialize_tdesc_powerpc_e500l ();