]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/ppc-linux-tdep.c
[gdb/python] Make gdb.UnwindInfo.add_saved_register more robust (fixup)
[thirdparty/binutils-gdb.git] / gdb / ppc-linux-tdep.c
1 /* Target-dependent code for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2024 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "extract-store-integer.h"
21 #include "frame.h"
22 #include "inferior.h"
23 #include "symtab.h"
24 #include "target.h"
25 #include "gdbcore.h"
26 #include "cli/cli-cmds.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "regcache.h"
30 #include "value.h"
31 #include "osabi.h"
32 #include "regset.h"
33 #include "solib-svr4.h"
34 #include "solib.h"
35 #include "solist.h"
36 #include "ppc-tdep.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"
46 #include "auxv.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"
54 #include "infrun.h"
55 #include "expop.h"
56
57 #include "stap-probe.h"
58 #include "ax.h"
59 #include "ax-gdb.h"
60 #include "cli/cli-utils.h"
61 #include "parser-defs.h"
62 #include "user-regs.h"
63 #include <ctype.h>
64 #include "elf-bfd.h"
65 #include "producer.h"
66 #include "target-float.h"
67
68 #include "features/rs6000/powerpc-32l.c"
69 #include "features/rs6000/powerpc-altivec32l.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-vsx64l.c"
80 #include "features/rs6000/powerpc-isa205-64l.c"
81 #include "features/rs6000/powerpc-isa205-altivec64l.c"
82 #include "features/rs6000/powerpc-isa205-vsx64l.c"
83 #include "features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c"
84 #include "features/rs6000/powerpc-isa207-vsx64l.c"
85 #include "features/rs6000/powerpc-isa207-htm-vsx64l.c"
86 #include "features/rs6000/powerpc-e500l.c"
87 #include "dwarf2/frame.h"
88
89 /* Shared library operations for PowerPC-Linux. */
90 static solib_ops powerpc_so_ops;
91
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"
95
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
100 removing it.
101
102 Here is the problem that we're trying to solve...
103
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
109 this platform.
110
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.
116
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.
123
124 We start the program shmain.
125
126 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
127 [...]
128
129 We place two breakpoints, one on shr1 and the other on main.
130
131 (gdb) b shr1
132 Breakpoint 1 at 0x100409d4
133 (gdb) b main
134 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
135
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.
139
140 (gdb) x/2i 0x100409d4
141 0x100409d4 <shr1>: .long 0x0
142 0x100409d8 <shr1+4>: .long 0x0
143
144 Now run 'til main.
145
146 (gdb) r
147 Starting program: gdb.base/shmain
148 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
149
150 Breakpoint 2, main ()
151 at gdb.base/shmain.c:44
152 44 g = 1;
153
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 branches a short distance to the code which actually does the
158 resolving.
159
160 (gdb) x/2i 0x100409d4
161 0x100409d4 <shr1>: li r11,4
162 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
163 (gdb) c
164 Continuing.
165
166 Breakpoint 1, shr1 (x=1)
167 at gdb.base/shr1.c:19
168 19 l = 1;
169
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.)
175
176 (gdb) x/2i 0x100409d4
177 0x100409d4 <shr1>: b 0xffaf76c <shr1>
178 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
179
180 The thing to note here is that the PLT entry for shr1 has been
181 changed twice.
182
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.
188
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.)
195
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
200 function.
201
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.
209
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.
214
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
219 code. */
220 static int
221 ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
222 struct bp_target_info *bp_tgt)
223 {
224 CORE_ADDR addr = bp_tgt->reqstd_address;
225 const unsigned char *bp;
226 int val;
227 int bplen;
228 gdb_byte old_contents[BREAKPOINT_MAX];
229
230 /* Determine appropriate breakpoint contents and size for this address. */
231 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
232
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);
237
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
240 old value. */
241 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
242 val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
243
244 return val;
245 }
246
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. */
251
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 struct value **read_value, const gdb_byte *writebuf)
256 {
257 gdb_byte *readbuf = nullptr;
258 if (read_value != nullptr)
259 {
260 *read_value = value::allocate (valtype);
261 readbuf = (*read_value)->contents_raw ().data ();
262 }
263
264 if ((valtype->code () == TYPE_CODE_STRUCT
265 || valtype->code () == TYPE_CODE_UNION)
266 && !((valtype->length () == 16 || valtype->length () == 8)
267 && valtype->is_vector ()))
268 return RETURN_VALUE_STRUCT_CONVENTION;
269 else
270 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
271 readbuf, writebuf);
272 }
273
274 /* PLT stub in an executable. */
275 static const struct ppc_insn_pattern powerpc32_plt_stub[] =
276 {
277 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
278 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
279 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
280 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
281 { 0, 0, 0 }
282 };
283
284 /* PLT stubs in a shared library or PIE.
285 The first variant is used when the PLT entry is within +/-32k of
286 the GOT pointer (r30). */
287 static const struct ppc_insn_pattern powerpc32_plt_stub_so_1[] =
288 {
289 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
290 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
291 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
292 { 0, 0, 0 }
293 };
294
295 /* The second variant is used when the PLT entry is more than +/-32k
296 from the GOT pointer (r30). */
297 static const struct ppc_insn_pattern powerpc32_plt_stub_so_2[] =
298 {
299 { 0xffff0000, 0x3d7e0000, 0 }, /* addis r11, r30, xxxx */
300 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
301 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
302 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
303 { 0, 0, 0 }
304 };
305
306 /* The max number of insns we check using ppc_insns_match_pattern. */
307 #define POWERPC32_PLT_CHECK_LEN (ARRAY_SIZE (powerpc32_plt_stub) - 1)
308
309 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
310 section. For secure PLT, stub is in .text and we need to check
311 instruction patterns. */
312
313 static int
314 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
315 {
316 struct bound_minimal_symbol sym;
317
318 /* Check whether PC is in the dynamic linker. This also checks
319 whether it is in the .plt section, used by non-PIC executables. */
320 if (svr4_in_dynsym_resolve_code (pc))
321 return 1;
322
323 /* Check if we are in the resolver. */
324 sym = lookup_minimal_symbol_by_pc (pc);
325 if (sym.minsym != NULL
326 && (strcmp (sym.minsym->linkage_name (), "__glink") == 0
327 || strcmp (sym.minsym->linkage_name (), "__glink_PLTresolve") == 0))
328 return 1;
329
330 return 0;
331 }
332
333 /* Follow PLT stub to actual routine.
334
335 When the execution direction is EXEC_REVERSE, scan backward to
336 check whether we are in the middle of a PLT stub. Currently,
337 we only look-behind at most 4 instructions (the max length of a PLT
338 stub sequence. */
339
340 static CORE_ADDR
341 ppc_skip_trampoline_code (const frame_info_ptr &frame, CORE_ADDR pc)
342 {
343 unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
344 struct gdbarch *gdbarch = get_frame_arch (frame);
345 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
346 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
347 CORE_ADDR target = 0;
348 int scan_limit, i;
349
350 scan_limit = 1;
351 /* When reverse-debugging, scan backward to check whether we are
352 in the middle of trampoline code. */
353 if (execution_direction == EXEC_REVERSE)
354 scan_limit = 4; /* At most 4 instructions. */
355
356 for (i = 0; i < scan_limit; i++)
357 {
358 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
359 {
360 /* Calculate PLT entry address from
361 lis r11, xxxx
362 lwz r11, xxxx(r11). */
363 target = ((ppc_insn_d_field (insnbuf[0]) << 16)
364 + ppc_insn_d_field (insnbuf[1]));
365 }
366 else if (i < ARRAY_SIZE (powerpc32_plt_stub_so_1) - 1
367 && ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_1,
368 insnbuf))
369 {
370 /* Calculate PLT entry address from
371 lwz r11, xxxx(r30). */
372 target = (ppc_insn_d_field (insnbuf[0])
373 + get_frame_register_unsigned (frame,
374 tdep->ppc_gp0_regnum + 30));
375 }
376 else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_2,
377 insnbuf))
378 {
379 /* Calculate PLT entry address from
380 addis r11, r30, xxxx
381 lwz r11, xxxx(r11). */
382 target = ((ppc_insn_d_field (insnbuf[0]) << 16)
383 + ppc_insn_d_field (insnbuf[1])
384 + get_frame_register_unsigned (frame,
385 tdep->ppc_gp0_regnum + 30));
386 }
387 else
388 {
389 /* Scan backward one more instruction if it doesn't match. */
390 pc -= 4;
391 continue;
392 }
393
394 target = read_memory_unsigned_integer (target, 4, byte_order);
395 return target;
396 }
397
398 return 0;
399 }
400
401 /* Wrappers to handle Linux-only registers. */
402
403 static void
404 ppc_linux_supply_gregset (const struct regset *regset,
405 struct regcache *regcache,
406 int regnum, const void *gregs, size_t len)
407 {
408 const struct ppc_reg_offsets *offsets
409 = (const struct ppc_reg_offsets *) regset->regmap;
410
411 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
412
413 if (ppc_linux_trap_reg_p (regcache->arch ()))
414 {
415 /* "orig_r3" is stored 2 slots after "pc". */
416 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
417 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, (const gdb_byte *) gregs,
418 offsets->pc_offset + 2 * offsets->gpr_size,
419 offsets->gpr_size);
420
421 /* "trap" is stored 8 slots after "pc". */
422 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
423 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, (const gdb_byte *) gregs,
424 offsets->pc_offset + 8 * offsets->gpr_size,
425 offsets->gpr_size);
426 }
427 }
428
429 static void
430 ppc_linux_collect_gregset (const struct regset *regset,
431 const struct regcache *regcache,
432 int regnum, void *gregs, size_t len)
433 {
434 const struct ppc_reg_offsets *offsets
435 = (const struct ppc_reg_offsets *) regset->regmap;
436
437 /* Clear areas in the linux gregset not written elsewhere. */
438 if (regnum == -1)
439 memset (gregs, 0, len);
440
441 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
442
443 if (ppc_linux_trap_reg_p (regcache->arch ()))
444 {
445 /* "orig_r3" is stored 2 slots after "pc". */
446 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
447 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, (gdb_byte *) gregs,
448 offsets->pc_offset + 2 * offsets->gpr_size,
449 offsets->gpr_size);
450
451 /* "trap" is stored 8 slots after "pc". */
452 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
453 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, (gdb_byte *) gregs,
454 offsets->pc_offset + 8 * offsets->gpr_size,
455 offsets->gpr_size);
456 }
457 }
458
459 /* Regset descriptions. */
460 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
461 {
462 /* General-purpose registers. */
463 /* .r0_offset = */ 0,
464 /* .gpr_size = */ 4,
465 /* .xr_size = */ 4,
466 /* .pc_offset = */ 128,
467 /* .ps_offset = */ 132,
468 /* .cr_offset = */ 152,
469 /* .lr_offset = */ 144,
470 /* .ctr_offset = */ 140,
471 /* .xer_offset = */ 148,
472 /* .mq_offset = */ 156,
473
474 /* Floating-point registers. */
475 /* .f0_offset = */ 0,
476 /* .fpscr_offset = */ 256,
477 /* .fpscr_size = */ 8
478 };
479
480 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
481 {
482 /* General-purpose registers. */
483 /* .r0_offset = */ 0,
484 /* .gpr_size = */ 8,
485 /* .xr_size = */ 8,
486 /* .pc_offset = */ 256,
487 /* .ps_offset = */ 264,
488 /* .cr_offset = */ 304,
489 /* .lr_offset = */ 288,
490 /* .ctr_offset = */ 280,
491 /* .xer_offset = */ 296,
492 /* .mq_offset = */ 312,
493
494 /* Floating-point registers. */
495 /* .f0_offset = */ 0,
496 /* .fpscr_offset = */ 256,
497 /* .fpscr_size = */ 8
498 };
499
500 static const struct regset ppc32_linux_gregset = {
501 &ppc32_linux_reg_offsets,
502 ppc_linux_supply_gregset,
503 ppc_linux_collect_gregset
504 };
505
506 static const struct regset ppc64_linux_gregset = {
507 &ppc64_linux_reg_offsets,
508 ppc_linux_supply_gregset,
509 ppc_linux_collect_gregset
510 };
511
512 static const struct regset ppc32_linux_fpregset = {
513 &ppc32_linux_reg_offsets,
514 ppc_supply_fpregset,
515 ppc_collect_fpregset
516 };
517
518 static const struct regcache_map_entry ppc32_le_linux_vrregmap[] =
519 {
520 { 32, PPC_VR0_REGNUM, 16 },
521 { 1, PPC_VSCR_REGNUM, 4 },
522 { 1, REGCACHE_MAP_SKIP, 12 },
523 { 1, PPC_VRSAVE_REGNUM, 4 },
524 { 1, REGCACHE_MAP_SKIP, 12 },
525 { 0 }
526 };
527
528 static const struct regcache_map_entry ppc32_be_linux_vrregmap[] =
529 {
530 { 32, PPC_VR0_REGNUM, 16 },
531 { 1, REGCACHE_MAP_SKIP, 12},
532 { 1, PPC_VSCR_REGNUM, 4 },
533 { 1, PPC_VRSAVE_REGNUM, 4 },
534 { 1, REGCACHE_MAP_SKIP, 12 },
535 { 0 }
536 };
537
538 static const struct regset ppc32_le_linux_vrregset = {
539 ppc32_le_linux_vrregmap,
540 regcache_supply_regset,
541 regcache_collect_regset
542 };
543
544 static const struct regset ppc32_be_linux_vrregset = {
545 ppc32_be_linux_vrregmap,
546 regcache_supply_regset,
547 regcache_collect_regset
548 };
549
550 static const struct regcache_map_entry ppc32_linux_vsxregmap[] =
551 {
552 { 32, PPC_VSR0_UPPER_REGNUM, 8 },
553 { 0 }
554 };
555
556 static const struct regset ppc32_linux_vsxregset = {
557 ppc32_linux_vsxregmap,
558 regcache_supply_regset,
559 regcache_collect_regset
560 };
561
562 /* Program Priorty Register regmap. */
563
564 static const struct regcache_map_entry ppc32_regmap_ppr[] =
565 {
566 { 1, PPC_PPR_REGNUM, 8 },
567 { 0 }
568 };
569
570 /* Program Priorty Register regset. */
571
572 const struct regset ppc32_linux_pprregset = {
573 ppc32_regmap_ppr,
574 regcache_supply_regset,
575 regcache_collect_regset
576 };
577
578 /* Data Stream Control Register regmap. */
579
580 static const struct regcache_map_entry ppc32_regmap_dscr[] =
581 {
582 { 1, PPC_DSCR_REGNUM, 8 },
583 { 0 }
584 };
585
586 /* Data Stream Control Register regset. */
587
588 const struct regset ppc32_linux_dscrregset = {
589 ppc32_regmap_dscr,
590 regcache_supply_regset,
591 regcache_collect_regset
592 };
593
594 /* Target Address Register regmap. */
595
596 static const struct regcache_map_entry ppc32_regmap_tar[] =
597 {
598 { 1, PPC_TAR_REGNUM, 8 },
599 { 0 }
600 };
601
602 /* Target Address Register regset. */
603
604 const struct regset ppc32_linux_tarregset = {
605 ppc32_regmap_tar,
606 regcache_supply_regset,
607 regcache_collect_regset
608 };
609
610 /* Event-Based Branching regmap. */
611
612 static const struct regcache_map_entry ppc32_regmap_ebb[] =
613 {
614 { 1, PPC_EBBRR_REGNUM, 8 },
615 { 1, PPC_EBBHR_REGNUM, 8 },
616 { 1, PPC_BESCR_REGNUM, 8 },
617 { 0 }
618 };
619
620 /* Event-Based Branching regset. */
621
622 const struct regset ppc32_linux_ebbregset = {
623 ppc32_regmap_ebb,
624 regcache_supply_regset,
625 regcache_collect_regset
626 };
627
628 /* Performance Monitoring Unit regmap. */
629
630 static const struct regcache_map_entry ppc32_regmap_pmu[] =
631 {
632 { 1, PPC_SIAR_REGNUM, 8 },
633 { 1, PPC_SDAR_REGNUM, 8 },
634 { 1, PPC_SIER_REGNUM, 8 },
635 { 1, PPC_MMCR2_REGNUM, 8 },
636 { 1, PPC_MMCR0_REGNUM, 8 },
637 { 0 }
638 };
639
640 /* Performance Monitoring Unit regset. */
641
642 const struct regset ppc32_linux_pmuregset = {
643 ppc32_regmap_pmu,
644 regcache_supply_regset,
645 regcache_collect_regset
646 };
647
648 /* Hardware Transactional Memory special-purpose register regmap. */
649
650 static const struct regcache_map_entry ppc32_regmap_tm_spr[] =
651 {
652 { 1, PPC_TFHAR_REGNUM, 8 },
653 { 1, PPC_TEXASR_REGNUM, 8 },
654 { 1, PPC_TFIAR_REGNUM, 8 },
655 { 0 }
656 };
657
658 /* Hardware Transactional Memory special-purpose register regset. */
659
660 const struct regset ppc32_linux_tm_sprregset = {
661 ppc32_regmap_tm_spr,
662 regcache_supply_regset,
663 regcache_collect_regset
664 };
665
666 /* Regmaps for the Hardware Transactional Memory checkpointed
667 general-purpose regsets for 32-bit, 64-bit big-endian, and 64-bit
668 little endian targets. The ptrace and core file buffers for 64-bit
669 targets use 8-byte fields for the 4-byte registers, and the
670 position of the register in the fields depends on the endianness.
671 The 32-bit regmap is the same for both endian types because the
672 fields are all 4-byte long.
673
674 The layout of checkpointed GPR regset is the same as a regular
675 struct pt_regs, but we skip all registers that are not actually
676 checkpointed by the processor (e.g. msr, nip), except when
677 generating a core file. The 64-bit regset is 48 * 8 bytes long.
678 In some 64-bit kernels, the regset for a 32-bit inferior has the
679 same length, but all the registers are squeezed in the first half
680 (48 * 4 bytes). The pt_regs struct calls the regular cr ccr, but
681 we use ccr for "checkpointed condition register". Note that CR
682 (condition register) field 0 is not checkpointed, but the kernel
683 returns all 4 bytes. The skipped registers should not be touched
684 when writing the regset to the inferior (with
685 PTRACE_SETREGSET). */
686
687 static const struct regcache_map_entry ppc32_regmap_cgpr[] =
688 {
689 { 32, PPC_CR0_REGNUM, 4 },
690 { 3, REGCACHE_MAP_SKIP, 4 }, /* nip, msr, orig_gpr3. */
691 { 1, PPC_CCTR_REGNUM, 4 },
692 { 1, PPC_CLR_REGNUM, 4 },
693 { 1, PPC_CXER_REGNUM, 4 },
694 { 1, PPC_CCR_REGNUM, 4 },
695 { 9, REGCACHE_MAP_SKIP, 4 }, /* All the rest. */
696 { 0 }
697 };
698
699 static const struct regcache_map_entry ppc64_le_regmap_cgpr[] =
700 {
701 { 32, PPC_CR0_REGNUM, 8 },
702 { 3, REGCACHE_MAP_SKIP, 8 },
703 { 1, PPC_CCTR_REGNUM, 8 },
704 { 1, PPC_CLR_REGNUM, 8 },
705 { 1, PPC_CXER_REGNUM, 4 },
706 { 1, REGCACHE_MAP_SKIP, 4 }, /* CXER padding. */
707 { 1, PPC_CCR_REGNUM, 4 },
708 { 1, REGCACHE_MAP_SKIP, 4}, /* CCR padding. */
709 { 9, REGCACHE_MAP_SKIP, 8},
710 { 0 }
711 };
712
713 static const struct regcache_map_entry ppc64_be_regmap_cgpr[] =
714 {
715 { 32, PPC_CR0_REGNUM, 8 },
716 { 3, REGCACHE_MAP_SKIP, 8 },
717 { 1, PPC_CCTR_REGNUM, 8 },
718 { 1, PPC_CLR_REGNUM, 8 },
719 { 1, REGCACHE_MAP_SKIP, 4}, /* CXER padding. */
720 { 1, PPC_CXER_REGNUM, 4 },
721 { 1, REGCACHE_MAP_SKIP, 4}, /* CCR padding. */
722 { 1, PPC_CCR_REGNUM, 4 },
723 { 9, REGCACHE_MAP_SKIP, 8},
724 { 0 }
725 };
726
727 /* Regsets for the Hardware Transactional Memory checkpointed
728 general-purpose registers for 32-bit, 64-bit big-endian, and 64-bit
729 little endian targets.
730
731 Some 64-bit kernels generate a checkpointed gpr note section with
732 48*8 bytes for a 32-bit thread, of which only 48*4 are actually
733 used, so we set the variable size flag in the corresponding regset
734 to accept this case. */
735
736 static const struct regset ppc32_linux_cgprregset = {
737 ppc32_regmap_cgpr,
738 regcache_supply_regset,
739 regcache_collect_regset,
740 REGSET_VARIABLE_SIZE
741 };
742
743 static const struct regset ppc64_be_linux_cgprregset = {
744 ppc64_be_regmap_cgpr,
745 regcache_supply_regset,
746 regcache_collect_regset
747 };
748
749 static const struct regset ppc64_le_linux_cgprregset = {
750 ppc64_le_regmap_cgpr,
751 regcache_supply_regset,
752 regcache_collect_regset
753 };
754
755 /* Hardware Transactional Memory checkpointed floating-point regmap. */
756
757 static const struct regcache_map_entry ppc32_regmap_cfpr[] =
758 {
759 { 32, PPC_CF0_REGNUM, 8 },
760 { 1, PPC_CFPSCR_REGNUM, 8 },
761 { 0 }
762 };
763
764 /* Hardware Transactional Memory checkpointed floating-point regset. */
765
766 const struct regset ppc32_linux_cfprregset = {
767 ppc32_regmap_cfpr,
768 regcache_supply_regset,
769 regcache_collect_regset
770 };
771
772 /* Regmaps for the Hardware Transactional Memory checkpointed vector
773 regsets, for big and little endian targets. The position of the
774 4-byte VSCR in its 16-byte field depends on the endianness. */
775
776 static const struct regcache_map_entry ppc32_le_regmap_cvmx[] =
777 {
778 { 32, PPC_CVR0_REGNUM, 16 },
779 { 1, PPC_CVSCR_REGNUM, 4 },
780 { 1, REGCACHE_MAP_SKIP, 12 },
781 { 1, PPC_CVRSAVE_REGNUM, 4 },
782 { 1, REGCACHE_MAP_SKIP, 12 },
783 { 0 }
784 };
785
786 static const struct regcache_map_entry ppc32_be_regmap_cvmx[] =
787 {
788 { 32, PPC_CVR0_REGNUM, 16 },
789 { 1, REGCACHE_MAP_SKIP, 12 },
790 { 1, PPC_CVSCR_REGNUM, 4 },
791 { 1, PPC_CVRSAVE_REGNUM, 4 },
792 { 1, REGCACHE_MAP_SKIP, 12},
793 { 0 }
794 };
795
796 /* Hardware Transactional Memory checkpointed vector regsets, for little
797 and big endian targets. */
798
799 static const struct regset ppc32_le_linux_cvmxregset = {
800 ppc32_le_regmap_cvmx,
801 regcache_supply_regset,
802 regcache_collect_regset
803 };
804
805 static const struct regset ppc32_be_linux_cvmxregset = {
806 ppc32_be_regmap_cvmx,
807 regcache_supply_regset,
808 regcache_collect_regset
809 };
810
811 /* Hardware Transactional Memory checkpointed vector-scalar regmap. */
812
813 static const struct regcache_map_entry ppc32_regmap_cvsx[] =
814 {
815 { 32, PPC_CVSR0_UPPER_REGNUM, 8 },
816 { 0 }
817 };
818
819 /* Hardware Transactional Memory checkpointed vector-scalar regset. */
820
821 const struct regset ppc32_linux_cvsxregset = {
822 ppc32_regmap_cvsx,
823 regcache_supply_regset,
824 regcache_collect_regset
825 };
826
827 /* Hardware Transactional Memory checkpointed Program Priority Register
828 regmap. */
829
830 static const struct regcache_map_entry ppc32_regmap_cppr[] =
831 {
832 { 1, PPC_CPPR_REGNUM, 8 },
833 { 0 }
834 };
835
836 /* Hardware Transactional Memory checkpointed Program Priority Register
837 regset. */
838
839 const struct regset ppc32_linux_cpprregset = {
840 ppc32_regmap_cppr,
841 regcache_supply_regset,
842 regcache_collect_regset
843 };
844
845 /* Hardware Transactional Memory checkpointed Data Stream Control
846 Register regmap. */
847
848 static const struct regcache_map_entry ppc32_regmap_cdscr[] =
849 {
850 { 1, PPC_CDSCR_REGNUM, 8 },
851 { 0 }
852 };
853
854 /* Hardware Transactional Memory checkpointed Data Stream Control
855 Register regset. */
856
857 const struct regset ppc32_linux_cdscrregset = {
858 ppc32_regmap_cdscr,
859 regcache_supply_regset,
860 regcache_collect_regset
861 };
862
863 /* Hardware Transactional Memory checkpointed Target Address Register
864 regmap. */
865
866 static const struct regcache_map_entry ppc32_regmap_ctar[] =
867 {
868 { 1, PPC_CTAR_REGNUM, 8 },
869 { 0 }
870 };
871
872 /* Hardware Transactional Memory checkpointed Target Address Register
873 regset. */
874
875 const struct regset ppc32_linux_ctarregset = {
876 ppc32_regmap_ctar,
877 regcache_supply_regset,
878 regcache_collect_regset
879 };
880
881 const struct regset *
882 ppc_linux_gregset (int wordsize)
883 {
884 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
885 }
886
887 const struct regset *
888 ppc_linux_fpregset (void)
889 {
890 return &ppc32_linux_fpregset;
891 }
892
893 const struct regset *
894 ppc_linux_vrregset (struct gdbarch *gdbarch)
895 {
896 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
897 return &ppc32_be_linux_vrregset;
898 else
899 return &ppc32_le_linux_vrregset;
900 }
901
902 const struct regset *
903 ppc_linux_vsxregset (void)
904 {
905 return &ppc32_linux_vsxregset;
906 }
907
908 const struct regset *
909 ppc_linux_cgprregset (struct gdbarch *gdbarch)
910 {
911 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
912
913 if (tdep->wordsize == 4)
914 {
915 return &ppc32_linux_cgprregset;
916 }
917 else
918 {
919 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
920 return &ppc64_be_linux_cgprregset;
921 else
922 return &ppc64_le_linux_cgprregset;
923 }
924 }
925
926 const struct regset *
927 ppc_linux_cvmxregset (struct gdbarch *gdbarch)
928 {
929 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
930 return &ppc32_be_linux_cvmxregset;
931 else
932 return &ppc32_le_linux_cvmxregset;
933 }
934
935 /* Collect function used to generate the core note for the
936 checkpointed GPR regset. Here, we don't want to skip the
937 "checkpointed" NIP and MSR, so that the note section we generate is
938 similar to the one generated by the kernel. To avoid having to
939 define additional registers in GDB which are not actually
940 checkpointed in the architecture, we copy TFHAR to the checkpointed
941 NIP slot, which is what the kernel does, and copy the regular MSR
942 to the checkpointed MSR slot, which will have a similar value in
943 most cases. */
944
945 static void
946 ppc_linux_collect_core_cpgrregset (const struct regset *regset,
947 const struct regcache *regcache,
948 int regnum, void *buf, size_t len)
949 {
950 struct gdbarch *gdbarch = regcache->arch ();
951 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
952
953 const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
954
955 /* We collect the checkpointed GPRs already defined in the regular
956 regmap, then overlay TFHAR/MSR on the checkpointed NIP/MSR
957 slots. */
958 cgprregset->collect_regset (cgprregset, regcache, regnum, buf, len);
959
960 /* Check that we are collecting all the registers, which should be
961 the case when generating a core file. */
962 if (regnum != -1)
963 return;
964
965 /* PT_NIP and PT_MSR are 32 and 33 for powerpc. Don't redefine
966 these symbols since this file can run on clients in other
967 architectures where they can already be defined to other
968 values. */
969 int pt_offset = 32;
970
971 /* Check that our buffer is long enough to hold two slots at
972 pt_offset * wordsize, one for NIP and one for MSR. */
973 gdb_assert ((pt_offset + 2) * tdep->wordsize <= len);
974
975 /* TFHAR is 8 bytes wide, but the NIP slot for a 32-bit thread is
976 4-bytes long. We use raw_collect_integer which handles
977 differences in the sizes for the source and destination buffers
978 for both endian modes. */
979 (regcache->raw_collect_integer
980 (PPC_TFHAR_REGNUM, ((gdb_byte *) buf) + pt_offset * tdep->wordsize,
981 tdep->wordsize, false));
982
983 pt_offset = 33;
984
985 (regcache->raw_collect_integer
986 (PPC_MSR_REGNUM, ((gdb_byte *) buf) + pt_offset * tdep->wordsize,
987 tdep->wordsize, false));
988 }
989
990 /* Iterate over supported core file register note sections. */
991
992 static void
993 ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
994 iterate_over_regset_sections_cb *cb,
995 void *cb_data,
996 const struct regcache *regcache)
997 {
998 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
999 int have_altivec = tdep->ppc_vr0_regnum != -1;
1000 int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
1001 int have_ppr = tdep->ppc_ppr_regnum != -1;
1002 int have_dscr = tdep->ppc_dscr_regnum != -1;
1003 int have_tar = tdep->ppc_tar_regnum != -1;
1004
1005 if (tdep->wordsize == 4)
1006 cb (".reg", 48 * 4, 48 * 4, &ppc32_linux_gregset, NULL, cb_data);
1007 else
1008 cb (".reg", 48 * 8, 48 * 8, &ppc64_linux_gregset, NULL, cb_data);
1009
1010 cb (".reg2", 264, 264, &ppc32_linux_fpregset, NULL, cb_data);
1011
1012 if (have_altivec)
1013 {
1014 const struct regset *vrregset = ppc_linux_vrregset (gdbarch);
1015 cb (".reg-ppc-vmx", PPC_LINUX_SIZEOF_VRREGSET, PPC_LINUX_SIZEOF_VRREGSET,
1016 vrregset, "ppc Altivec", cb_data);
1017 }
1018
1019 if (have_vsx)
1020 cb (".reg-ppc-vsx", PPC_LINUX_SIZEOF_VSXREGSET, PPC_LINUX_SIZEOF_VSXREGSET,
1021 &ppc32_linux_vsxregset, "POWER7 VSX", cb_data);
1022
1023 if (have_ppr)
1024 cb (".reg-ppc-ppr", PPC_LINUX_SIZEOF_PPRREGSET,
1025 PPC_LINUX_SIZEOF_PPRREGSET,
1026 &ppc32_linux_pprregset, "Priority Program Register", cb_data);
1027
1028 if (have_dscr)
1029 cb (".reg-ppc-dscr", PPC_LINUX_SIZEOF_DSCRREGSET,
1030 PPC_LINUX_SIZEOF_DSCRREGSET,
1031 &ppc32_linux_dscrregset, "Data Stream Control Register",
1032 cb_data);
1033
1034 if (have_tar)
1035 cb (".reg-ppc-tar", PPC_LINUX_SIZEOF_TARREGSET,
1036 PPC_LINUX_SIZEOF_TARREGSET,
1037 &ppc32_linux_tarregset, "Target Address Register", cb_data);
1038
1039 /* EBB registers are unavailable when ptrace returns ENODATA. Check
1040 availability when generating a core file (regcache != NULL). */
1041 if (tdep->have_ebb)
1042 if (regcache == NULL
1043 || REG_VALID == regcache->get_register_status (PPC_BESCR_REGNUM))
1044 cb (".reg-ppc-ebb", PPC_LINUX_SIZEOF_EBBREGSET,
1045 PPC_LINUX_SIZEOF_EBBREGSET,
1046 &ppc32_linux_ebbregset, "Event-based Branching Registers",
1047 cb_data);
1048
1049 if (tdep->ppc_mmcr0_regnum != -1)
1050 cb (".reg-ppc-pmu", PPC_LINUX_SIZEOF_PMUREGSET,
1051 PPC_LINUX_SIZEOF_PMUREGSET,
1052 &ppc32_linux_pmuregset, "Performance Monitor Registers",
1053 cb_data);
1054
1055 if (tdep->have_htm_spr)
1056 cb (".reg-ppc-tm-spr", PPC_LINUX_SIZEOF_TM_SPRREGSET,
1057 PPC_LINUX_SIZEOF_TM_SPRREGSET,
1058 &ppc32_linux_tm_sprregset,
1059 "Hardware Transactional Memory Special Purpose Registers",
1060 cb_data);
1061
1062 /* Checkpointed registers can be unavailable, don't call back if
1063 we are generating a core file. */
1064
1065 if (tdep->have_htm_core)
1066 {
1067 /* Only generate the checkpointed GPR core note if we also have
1068 access to the HTM SPRs, because we need TFHAR to fill the
1069 "checkpointed" NIP slot. We can read a core file without it
1070 since GDB is not aware of this NIP as a visible register. */
1071 if (regcache == NULL ||
1072 (REG_VALID == regcache->get_register_status (PPC_CR0_REGNUM)
1073 && tdep->have_htm_spr))
1074 {
1075 int cgpr_size = (tdep->wordsize == 4?
1076 PPC32_LINUX_SIZEOF_CGPRREGSET
1077 : PPC64_LINUX_SIZEOF_CGPRREGSET);
1078
1079 const struct regset *cgprregset =
1080 ppc_linux_cgprregset (gdbarch);
1081
1082 if (regcache != NULL)
1083 {
1084 struct regset core_cgprregset = *cgprregset;
1085
1086 core_cgprregset.collect_regset
1087 = ppc_linux_collect_core_cpgrregset;
1088
1089 cb (".reg-ppc-tm-cgpr",
1090 cgpr_size, cgpr_size,
1091 &core_cgprregset,
1092 "Checkpointed General Purpose Registers", cb_data);
1093 }
1094 else
1095 {
1096 cb (".reg-ppc-tm-cgpr",
1097 cgpr_size, cgpr_size,
1098 cgprregset,
1099 "Checkpointed General Purpose Registers", cb_data);
1100 }
1101 }
1102 }
1103
1104 if (tdep->have_htm_fpu)
1105 {
1106 if (regcache == NULL ||
1107 REG_VALID == regcache->get_register_status (PPC_CF0_REGNUM))
1108 cb (".reg-ppc-tm-cfpr", PPC_LINUX_SIZEOF_CFPRREGSET,
1109 PPC_LINUX_SIZEOF_CFPRREGSET,
1110 &ppc32_linux_cfprregset,
1111 "Checkpointed Floating Point Registers", cb_data);
1112 }
1113
1114 if (tdep->have_htm_altivec)
1115 {
1116 if (regcache == NULL ||
1117 REG_VALID == regcache->get_register_status (PPC_CVR0_REGNUM))
1118 {
1119 const struct regset *cvmxregset =
1120 ppc_linux_cvmxregset (gdbarch);
1121
1122 cb (".reg-ppc-tm-cvmx", PPC_LINUX_SIZEOF_CVMXREGSET,
1123 PPC_LINUX_SIZEOF_CVMXREGSET,
1124 cvmxregset,
1125 "Checkpointed Altivec (VMX) Registers", cb_data);
1126 }
1127 }
1128
1129 if (tdep->have_htm_vsx)
1130 {
1131 if (regcache == NULL ||
1132 (REG_VALID
1133 == regcache->get_register_status (PPC_CVSR0_UPPER_REGNUM)))
1134 cb (".reg-ppc-tm-cvsx", PPC_LINUX_SIZEOF_CVSXREGSET,
1135 PPC_LINUX_SIZEOF_CVSXREGSET,
1136 &ppc32_linux_cvsxregset,
1137 "Checkpointed VSX Registers", cb_data);
1138 }
1139
1140 if (tdep->ppc_cppr_regnum != -1)
1141 {
1142 if (regcache == NULL ||
1143 REG_VALID == regcache->get_register_status (PPC_CPPR_REGNUM))
1144 cb (".reg-ppc-tm-cppr", PPC_LINUX_SIZEOF_CPPRREGSET,
1145 PPC_LINUX_SIZEOF_CPPRREGSET,
1146 &ppc32_linux_cpprregset,
1147 "Checkpointed Priority Program Register", cb_data);
1148 }
1149
1150 if (tdep->ppc_cdscr_regnum != -1)
1151 {
1152 if (regcache == NULL ||
1153 REG_VALID == regcache->get_register_status (PPC_CDSCR_REGNUM))
1154 cb (".reg-ppc-tm-cdscr", PPC_LINUX_SIZEOF_CDSCRREGSET,
1155 PPC_LINUX_SIZEOF_CDSCRREGSET,
1156 &ppc32_linux_cdscrregset,
1157 "Checkpointed Data Stream Control Register", cb_data);
1158 }
1159
1160 if (tdep->ppc_ctar_regnum)
1161 {
1162 if ( regcache == NULL ||
1163 REG_VALID == regcache->get_register_status (PPC_CTAR_REGNUM))
1164 cb (".reg-ppc-tm-ctar", PPC_LINUX_SIZEOF_CTARREGSET,
1165 PPC_LINUX_SIZEOF_CTARREGSET,
1166 &ppc32_linux_ctarregset,
1167 "Checkpointed Target Address Register", cb_data);
1168 }
1169 }
1170
1171 static void
1172 ppc_linux_sigtramp_cache (const frame_info_ptr &this_frame,
1173 struct trad_frame_cache *this_cache,
1174 CORE_ADDR func, LONGEST offset,
1175 int bias)
1176 {
1177 CORE_ADDR base;
1178 CORE_ADDR regs;
1179 CORE_ADDR gpregs;
1180 CORE_ADDR fpregs;
1181 int i;
1182 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1183 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1184 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1185
1186 base = get_frame_register_unsigned (this_frame,
1187 gdbarch_sp_regnum (gdbarch));
1188 if (bias > 0 && get_frame_pc (this_frame) != func)
1189 /* See below, some signal trampolines increment the stack as their
1190 first instruction, need to compensate for that. */
1191 base -= bias;
1192
1193 /* Find the address of the register buffer pointer. */
1194 regs = base + offset;
1195 /* Use that to find the address of the corresponding register
1196 buffers. */
1197 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
1198 fpregs = gpregs + 48 * tdep->wordsize;
1199
1200 /* General purpose. */
1201 for (i = 0; i < 32; i++)
1202 {
1203 int regnum = i + tdep->ppc_gp0_regnum;
1204 trad_frame_set_reg_addr (this_cache,
1205 regnum, gpregs + i * tdep->wordsize);
1206 }
1207 trad_frame_set_reg_addr (this_cache,
1208 gdbarch_pc_regnum (gdbarch),
1209 gpregs + 32 * tdep->wordsize);
1210 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
1211 gpregs + 35 * tdep->wordsize);
1212 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
1213 gpregs + 36 * tdep->wordsize);
1214 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
1215 gpregs + 37 * tdep->wordsize);
1216 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
1217 gpregs + 38 * tdep->wordsize);
1218
1219 if (ppc_linux_trap_reg_p (gdbarch))
1220 {
1221 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
1222 gpregs + 34 * tdep->wordsize);
1223 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
1224 gpregs + 40 * tdep->wordsize);
1225 }
1226
1227 if (ppc_floating_point_unit_p (gdbarch))
1228 {
1229 /* Floating point registers. */
1230 for (i = 0; i < 32; i++)
1231 {
1232 int regnum = i + gdbarch_fp0_regnum (gdbarch);
1233 trad_frame_set_reg_addr (this_cache, regnum,
1234 fpregs + i * tdep->wordsize);
1235 }
1236 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
1237 fpregs + 32 * tdep->wordsize);
1238 }
1239 trad_frame_set_id (this_cache, frame_id_build (base, func));
1240 }
1241
1242 static void
1243 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
1244 const frame_info_ptr &this_frame,
1245 struct trad_frame_cache *this_cache,
1246 CORE_ADDR func)
1247 {
1248 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1249 0xd0 /* Offset to ucontext_t. */
1250 + 0x30 /* Offset to .reg. */,
1251 0);
1252 }
1253
1254 static void
1255 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
1256 const frame_info_ptr &this_frame,
1257 struct trad_frame_cache *this_cache,
1258 CORE_ADDR func)
1259 {
1260 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1261 0x80 /* Offset to ucontext_t. */
1262 + 0xe0 /* Offset to .reg. */,
1263 128);
1264 }
1265
1266 static void
1267 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
1268 const frame_info_ptr &this_frame,
1269 struct trad_frame_cache *this_cache,
1270 CORE_ADDR func)
1271 {
1272 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1273 0x40 /* Offset to ucontext_t. */
1274 + 0x1c /* Offset to .reg. */,
1275 0);
1276 }
1277
1278 static void
1279 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
1280 const frame_info_ptr &this_frame,
1281 struct trad_frame_cache *this_cache,
1282 CORE_ADDR func)
1283 {
1284 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
1285 0x80 /* Offset to struct sigcontext. */
1286 + 0x38 /* Offset to .reg. */,
1287 128);
1288 }
1289
1290 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
1291 SIGTRAMP_FRAME,
1292 4,
1293 {
1294 { 0x380000ac, ULONGEST_MAX }, /* li r0, 172 */
1295 { 0x44000002, ULONGEST_MAX }, /* sc */
1296 { TRAMP_SENTINEL_INSN },
1297 },
1298 ppc32_linux_sigaction_cache_init
1299 };
1300 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
1301 SIGTRAMP_FRAME,
1302 4,
1303 {
1304 { 0x38210080, ULONGEST_MAX }, /* addi r1,r1,128 */
1305 { 0x380000ac, ULONGEST_MAX }, /* li r0, 172 */
1306 { 0x44000002, ULONGEST_MAX }, /* sc */
1307 { TRAMP_SENTINEL_INSN },
1308 },
1309 ppc64_linux_sigaction_cache_init
1310 };
1311 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
1312 SIGTRAMP_FRAME,
1313 4,
1314 {
1315 { 0x38000077, ULONGEST_MAX }, /* li r0,119 */
1316 { 0x44000002, ULONGEST_MAX }, /* sc */
1317 { TRAMP_SENTINEL_INSN },
1318 },
1319 ppc32_linux_sighandler_cache_init
1320 };
1321 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
1322 SIGTRAMP_FRAME,
1323 4,
1324 {
1325 { 0x38210080, ULONGEST_MAX }, /* addi r1,r1,128 */
1326 { 0x38000077, ULONGEST_MAX }, /* li r0,119 */
1327 { 0x44000002, ULONGEST_MAX }, /* sc */
1328 { TRAMP_SENTINEL_INSN },
1329 },
1330 ppc64_linux_sighandler_cache_init
1331 };
1332
1333 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
1334 int
1335 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
1336 {
1337 /* If we do not have a target description with registers, then
1338 the special registers will not be included in the register set. */
1339 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1340 return 0;
1341
1342 /* If we do, then it is safe to check the size. */
1343 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
1344 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
1345 }
1346
1347 /* Return the current system call's number present in the
1348 r0 register. When the function fails, it returns -1. */
1349 static LONGEST
1350 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
1351 thread_info *thread)
1352 {
1353 struct regcache *regcache = get_thread_regcache (thread);
1354 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1355 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1356
1357 /* Make sure we're in a 32- or 64-bit machine */
1358 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
1359
1360 /* The content of a register */
1361 gdb::byte_vector buf (tdep->wordsize);
1362
1363 /* Getting the system call number from the register.
1364 When dealing with PowerPC architecture, this information
1365 is stored at 0th register. */
1366 regcache->cooked_read (tdep->ppc_gp0_regnum, buf.data ());
1367
1368 return extract_signed_integer (buf.data (), tdep->wordsize, byte_order);
1369 }
1370
1371 /* PPC process record-replay */
1372
1373 static struct linux_record_tdep ppc_linux_record_tdep;
1374 static struct linux_record_tdep ppc64_linux_record_tdep;
1375
1376 /* ppc_canonicalize_syscall maps from the native PowerPC Linux set of
1377 syscall ids into a canonical set of syscall ids used by process
1378 record. (See arch/powerpc/include/uapi/asm/unistd.h in kernel tree.)
1379 Return -1 if this system call is not supported by process record.
1380 Otherwise, return the syscall number for process record of given
1381 SYSCALL. */
1382
1383 static enum gdb_syscall
1384 ppc_canonicalize_syscall (int syscall, int wordsize)
1385 {
1386 int result = -1;
1387
1388 if (syscall <= 165)
1389 result = syscall;
1390 else if (syscall >= 167 && syscall <= 190) /* Skip query_module 166 */
1391 result = syscall + 1;
1392 else if (syscall >= 192 && syscall <= 197) /* mmap2 */
1393 result = syscall;
1394 else if (syscall == 208) /* tkill */
1395 result = gdb_sys_tkill;
1396 else if (syscall >= 207 && syscall <= 220) /* gettid */
1397 result = syscall + 224 - 207;
1398 else if (syscall >= 234 && syscall <= 239) /* exit_group */
1399 result = syscall + 252 - 234;
1400 else if (syscall >= 240 && syscall <= 248) /* timer_create */
1401 result = syscall += 259 - 240;
1402 else if (syscall >= 250 && syscall <= 251) /* tgkill */
1403 result = syscall + 270 - 250;
1404 else if (syscall == 286)
1405 result = gdb_sys_openat;
1406 else if (syscall == 291)
1407 {
1408 if (wordsize == 64)
1409 result = gdb_sys_newfstatat;
1410 else
1411 result = gdb_sys_fstatat64;
1412 }
1413 else if (syscall == 317)
1414 result = gdb_sys_pipe2;
1415 else if (syscall == 336)
1416 result = gdb_sys_recv;
1417 else if (syscall == 337)
1418 result = gdb_sys_recvfrom;
1419 else if (syscall == 342)
1420 result = gdb_sys_recvmsg;
1421 else if (syscall == 359)
1422 result = gdb_sys_getrandom;
1423
1424 return (enum gdb_syscall) result;
1425 }
1426
1427 /* Record registers which might be clobbered during system call.
1428 Return 0 if successful. */
1429
1430 static int
1431 ppc_linux_syscall_record (struct regcache *regcache)
1432 {
1433 struct gdbarch *gdbarch = regcache->arch ();
1434 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1435 ULONGEST scnum;
1436 enum gdb_syscall syscall_gdb;
1437 int ret;
1438
1439 regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum, &scnum);
1440 syscall_gdb = ppc_canonicalize_syscall (scnum, tdep->wordsize);
1441
1442 if (syscall_gdb < 0)
1443 {
1444 gdb_printf (gdb_stderr,
1445 _("Process record and replay target doesn't "
1446 "support syscall number %d\n"), (int) scnum);
1447 return 0;
1448 }
1449
1450 if (syscall_gdb == gdb_sys_sigreturn
1451 || syscall_gdb == gdb_sys_rt_sigreturn)
1452 {
1453 int i, j;
1454 int regsets[] = { tdep->ppc_gp0_regnum,
1455 tdep->ppc_fp0_regnum,
1456 tdep->ppc_vr0_regnum,
1457 tdep->ppc_vsr0_upper_regnum };
1458
1459 for (j = 0; j < 4; j++)
1460 {
1461 if (regsets[j] == -1)
1462 continue;
1463 for (i = 0; i < 32; i++)
1464 {
1465 if (record_full_arch_list_add_reg (regcache, regsets[j] + i))
1466 return -1;
1467 }
1468 }
1469
1470 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1471 return -1;
1472 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1473 return -1;
1474 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1475 return -1;
1476 if (record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum))
1477 return -1;
1478
1479 return 0;
1480 }
1481
1482 if (tdep->wordsize == 8)
1483 ret = record_linux_system_call (syscall_gdb, regcache,
1484 &ppc64_linux_record_tdep);
1485 else
1486 ret = record_linux_system_call (syscall_gdb, regcache,
1487 &ppc_linux_record_tdep);
1488
1489 if (ret != 0)
1490 return ret;
1491
1492 /* Record registers clobbered during syscall. */
1493 for (int i = 3; i <= 12; i++)
1494 {
1495 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
1496 return -1;
1497 }
1498 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + 0))
1499 return -1;
1500 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1501 return -1;
1502 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1503 return -1;
1504 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1505 return -1;
1506
1507 return 0;
1508 }
1509
1510 /* Record registers which might be clobbered during signal handling.
1511 Return 0 if successful. */
1512
1513 static int
1514 ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
1515 enum gdb_signal signal)
1516 {
1517 /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c
1518 handle_rt_signal32 in arch/powerpc/kernel/signal_32.c
1519 arch/powerpc/include/asm/ptrace.h
1520 for details. */
1521 const int SIGNAL_FRAMESIZE = 128;
1522 const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
1523 ULONGEST sp;
1524 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1525 int i;
1526
1527 for (i = 3; i <= 12; i++)
1528 {
1529 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
1530 return -1;
1531 }
1532
1533 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1534 return -1;
1535 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1536 return -1;
1537 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1538 return -1;
1539 if (record_full_arch_list_add_reg (regcache, gdbarch_pc_regnum (gdbarch)))
1540 return -1;
1541 if (record_full_arch_list_add_reg (regcache, gdbarch_sp_regnum (gdbarch)))
1542 return -1;
1543
1544 /* Record the change in the stack.
1545 frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
1546 regcache_raw_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &sp);
1547 sp -= SIGNAL_FRAMESIZE;
1548 sp -= sizeof_rt_sigframe;
1549
1550 if (record_full_arch_list_add_mem (sp, SIGNAL_FRAMESIZE + sizeof_rt_sigframe))
1551 return -1;
1552
1553 if (record_full_arch_list_add_end ())
1554 return -1;
1555
1556 return 0;
1557 }
1558
1559 static void
1560 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1561 {
1562 struct gdbarch *gdbarch = regcache->arch ();
1563
1564 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
1565
1566 /* Set special TRAP register to -1 to prevent the kernel from
1567 messing with the PC we just installed, if we happen to be
1568 within an interrupted system call that the kernel wants to
1569 restart.
1570
1571 Note that after we return from the dummy call, the TRAP and
1572 ORIG_R3 registers will be automatically restored, and the
1573 kernel continues to restart the system call at this point. */
1574 if (ppc_linux_trap_reg_p (gdbarch))
1575 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
1576 }
1577
1578 static const struct target_desc *
1579 ppc_linux_core_read_description (struct gdbarch *gdbarch,
1580 struct target_ops *target,
1581 bfd *abfd)
1582 {
1583 struct ppc_linux_features features = ppc_linux_no_features;
1584 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
1585 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
1586 asection *section = bfd_get_section_by_name (abfd, ".reg");
1587 asection *ppr = bfd_get_section_by_name (abfd, ".reg-ppc-ppr");
1588 asection *dscr = bfd_get_section_by_name (abfd, ".reg-ppc-dscr");
1589 asection *tar = bfd_get_section_by_name (abfd, ".reg-ppc-tar");
1590 asection *pmu = bfd_get_section_by_name (abfd, ".reg-ppc-pmu");
1591 asection *htmspr = bfd_get_section_by_name (abfd, ".reg-ppc-tm-spr");
1592
1593 if (! section)
1594 return NULL;
1595
1596 switch (bfd_section_size (section))
1597 {
1598 case 48 * 4:
1599 features.wordsize = 4;
1600 break;
1601 case 48 * 8:
1602 features.wordsize = 8;
1603 break;
1604 default:
1605 return NULL;
1606 }
1607
1608 if (altivec)
1609 features.altivec = true;
1610
1611 if (vsx)
1612 features.vsx = true;
1613
1614 std::optional<gdb::byte_vector> auxv = target_read_auxv_raw (target);
1615 CORE_ADDR hwcap = linux_get_hwcap (auxv, target, gdbarch);
1616
1617 features.isa205 = ppc_linux_has_isa205 (hwcap);
1618
1619 if (ppr && dscr)
1620 {
1621 features.ppr_dscr = true;
1622
1623 /* We don't require the EBB note section to be present in the
1624 core file to select isa207 because these registers could have
1625 been unavailable when the core file was created. They will
1626 be in the tdep but will show as unavailable. */
1627 if (tar && pmu)
1628 {
1629 features.isa207 = true;
1630 if (htmspr)
1631 features.htm = true;
1632 }
1633 }
1634
1635 return ppc_linux_match_description (features);
1636 }
1637
1638
1639 /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
1640 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1641
1642 static void
1643 ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
1644 {
1645 if ((sym->flags & BSF_SYNTHETIC) != 0)
1646 /* ELFv2 synthetic symbols (the PLT stubs and the __glink_PLTresolve
1647 trampoline) do not have a local entry point. */
1648 return;
1649
1650 elf_symbol_type *elf_sym = (elf_symbol_type *)sym;
1651
1652 /* If the symbol is marked as having a local entry point, set a target
1653 flag in the msymbol. We currently only support local entry point
1654 offsets of 8 bytes, which is the only entry point offset ever used
1655 by current compilers. If/when other offsets are ever used, we will
1656 have to use additional target flag bits to store them. */
1657 switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other))
1658 {
1659 default:
1660 break;
1661 case 8:
1662 msym->set_target_flag_1 (true);
1663 break;
1664 }
1665 }
1666
1667 /* Implementation of `gdbarch_skip_entrypoint', as defined in
1668 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1669
1670 static CORE_ADDR
1671 ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc)
1672 {
1673 struct bound_minimal_symbol fun;
1674 int local_entry_offset = 0;
1675
1676 fun = lookup_minimal_symbol_by_pc (pc);
1677 if (fun.minsym == NULL)
1678 return pc;
1679
1680 /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
1681 offset values are encoded. */
1682 if (fun.minsym->target_flag_1 ())
1683 local_entry_offset = 8;
1684
1685 if (fun.value_address () <= pc
1686 && pc < fun.value_address () + local_entry_offset)
1687 return fun.value_address () + local_entry_offset;
1688
1689 return pc;
1690 }
1691
1692 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1693 gdbarch.h. */
1694
1695 static int
1696 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
1697 {
1698 return (*s == 'i' /* Literal number. */
1699 || (isdigit (*s) && s[1] == '('
1700 && isdigit (s[2])) /* Displacement. */
1701 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
1702 || isdigit (*s)); /* Register value. */
1703 }
1704
1705 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
1706 gdbarch.h. */
1707
1708 static expr::operation_up
1709 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
1710 struct stap_parse_info *p)
1711 {
1712 if (isdigit (*p->arg))
1713 {
1714 /* This temporary pointer is needed because we have to do a lookahead.
1715 We could be dealing with a register displacement, and in such case
1716 we would not need to do anything. */
1717 const char *s = p->arg;
1718 char *regname;
1719 int len;
1720
1721 while (isdigit (*s))
1722 ++s;
1723
1724 if (*s == '(')
1725 {
1726 /* It is a register displacement indeed. Returning 0 means we are
1727 deferring the treatment of this case to the generic parser. */
1728 return {};
1729 }
1730
1731 len = s - p->arg;
1732 regname = (char *) alloca (len + 2);
1733 regname[0] = 'r';
1734
1735 strncpy (regname + 1, p->arg, len);
1736 ++len;
1737 regname[len] = '\0';
1738
1739 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
1740 error (_("Invalid register name `%s' on expression `%s'."),
1741 regname, p->saved_arg);
1742
1743 p->arg = s;
1744
1745 return expr::make_operation<expr::register_operation> (regname);
1746 }
1747
1748 /* All the other tokens should be handled correctly by the generic
1749 parser. */
1750 return {};
1751 }
1752
1753 /* Initialize linux_record_tdep if not initialized yet.
1754 WORDSIZE is 4 or 8 for 32- or 64-bit PowerPC Linux respectively.
1755 Sizes of data structures are initialized accordingly. */
1756
1757 static void
1758 ppc_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
1759 int wordsize)
1760 {
1761 /* The values for TCGETS, TCSETS, TCSETSW, TCSETSF are based on the
1762 size of struct termios in the kernel source.
1763 include/uapi/asm-generic/termbits.h */
1764 #define SIZE_OF_STRUCT_TERMIOS 0x2c
1765
1766 /* Simply return if it had been initialized. */
1767 if (record_tdep->size_pointer != 0)
1768 return;
1769
1770 /* These values are the size of the type that will be used in a system
1771 call. They are obtained from Linux Kernel source. */
1772
1773 if (wordsize == 8)
1774 {
1775 record_tdep->size_pointer = 8;
1776 record_tdep->size__old_kernel_stat = 32;
1777 record_tdep->size_tms = 32;
1778 record_tdep->size_loff_t = 8;
1779 record_tdep->size_flock = 32;
1780 record_tdep->size_oldold_utsname = 45;
1781 record_tdep->size_ustat = 32;
1782 record_tdep->size_old_sigaction = 32;
1783 record_tdep->size_old_sigset_t = 8;
1784 record_tdep->size_rlimit = 16;
1785 record_tdep->size_rusage = 144;
1786 record_tdep->size_timeval = 16;
1787 record_tdep->size_timezone = 8;
1788 record_tdep->size_old_gid_t = 4;
1789 record_tdep->size_old_uid_t = 4;
1790 record_tdep->size_fd_set = 128;
1791 record_tdep->size_old_dirent = 280;
1792 record_tdep->size_statfs = 120;
1793 record_tdep->size_statfs64 = 120;
1794 record_tdep->size_sockaddr = 16;
1795 record_tdep->size_int = 4;
1796 record_tdep->size_long = 8;
1797 record_tdep->size_ulong = 8;
1798 record_tdep->size_msghdr = 56;
1799 record_tdep->size_itimerval = 32;
1800 record_tdep->size_stat = 144;
1801 record_tdep->size_old_utsname = 325;
1802 record_tdep->size_sysinfo = 112;
1803 record_tdep->size_msqid_ds = 120;
1804 record_tdep->size_shmid_ds = 112;
1805 record_tdep->size_new_utsname = 390;
1806 record_tdep->size_timex = 208;
1807 record_tdep->size_mem_dqinfo = 24;
1808 record_tdep->size_if_dqblk = 72;
1809 record_tdep->size_fs_quota_stat = 80;
1810 record_tdep->size_timespec = 16;
1811 record_tdep->size_pollfd = 8;
1812 record_tdep->size_NFS_FHSIZE = 32;
1813 record_tdep->size_knfsd_fh = 132;
1814 record_tdep->size_TASK_COMM_LEN = 16;
1815 record_tdep->size_sigaction = 32;
1816 record_tdep->size_sigset_t = 8;
1817 record_tdep->size_siginfo_t = 128;
1818 record_tdep->size_cap_user_data_t = 8;
1819 record_tdep->size_stack_t = 24;
1820 record_tdep->size_off_t = 8;
1821 record_tdep->size_stat64 = 104;
1822 record_tdep->size_gid_t = 4;
1823 record_tdep->size_uid_t = 4;
1824 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
1825 record_tdep->size_flock64 = 32;
1826 record_tdep->size_io_event = 32;
1827 record_tdep->size_iocb = 64;
1828 record_tdep->size_epoll_event = 16;
1829 record_tdep->size_itimerspec = 32;
1830 record_tdep->size_mq_attr = 64;
1831 record_tdep->size_termios = 44;
1832 record_tdep->size_pid_t = 4;
1833 record_tdep->size_winsize = 8;
1834 record_tdep->size_serial_struct = 72;
1835 record_tdep->size_serial_icounter_struct = 80;
1836 record_tdep->size_size_t = 8;
1837 record_tdep->size_iovec = 16;
1838 record_tdep->size_time_t = 8;
1839 }
1840 else if (wordsize == 4)
1841 {
1842 record_tdep->size_pointer = 4;
1843 record_tdep->size__old_kernel_stat = 32;
1844 record_tdep->size_tms = 16;
1845 record_tdep->size_loff_t = 8;
1846 record_tdep->size_flock = 16;
1847 record_tdep->size_oldold_utsname = 45;
1848 record_tdep->size_ustat = 20;
1849 record_tdep->size_old_sigaction = 16;
1850 record_tdep->size_old_sigset_t = 4;
1851 record_tdep->size_rlimit = 8;
1852 record_tdep->size_rusage = 72;
1853 record_tdep->size_timeval = 8;
1854 record_tdep->size_timezone = 8;
1855 record_tdep->size_old_gid_t = 4;
1856 record_tdep->size_old_uid_t = 4;
1857 record_tdep->size_fd_set = 128;
1858 record_tdep->size_old_dirent = 268;
1859 record_tdep->size_statfs = 64;
1860 record_tdep->size_statfs64 = 88;
1861 record_tdep->size_sockaddr = 16;
1862 record_tdep->size_int = 4;
1863 record_tdep->size_long = 4;
1864 record_tdep->size_ulong = 4;
1865 record_tdep->size_msghdr = 28;
1866 record_tdep->size_itimerval = 16;
1867 record_tdep->size_stat = 88;
1868 record_tdep->size_old_utsname = 325;
1869 record_tdep->size_sysinfo = 64;
1870 record_tdep->size_msqid_ds = 68;
1871 record_tdep->size_shmid_ds = 60;
1872 record_tdep->size_new_utsname = 390;
1873 record_tdep->size_timex = 128;
1874 record_tdep->size_mem_dqinfo = 24;
1875 record_tdep->size_if_dqblk = 72;
1876 record_tdep->size_fs_quota_stat = 80;
1877 record_tdep->size_timespec = 8;
1878 record_tdep->size_pollfd = 8;
1879 record_tdep->size_NFS_FHSIZE = 32;
1880 record_tdep->size_knfsd_fh = 132;
1881 record_tdep->size_TASK_COMM_LEN = 16;
1882 record_tdep->size_sigaction = 20;
1883 record_tdep->size_sigset_t = 8;
1884 record_tdep->size_siginfo_t = 128;
1885 record_tdep->size_cap_user_data_t = 4;
1886 record_tdep->size_stack_t = 12;
1887 record_tdep->size_off_t = 4;
1888 record_tdep->size_stat64 = 104;
1889 record_tdep->size_gid_t = 4;
1890 record_tdep->size_uid_t = 4;
1891 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
1892 record_tdep->size_flock64 = 32;
1893 record_tdep->size_io_event = 32;
1894 record_tdep->size_iocb = 64;
1895 record_tdep->size_epoll_event = 16;
1896 record_tdep->size_itimerspec = 16;
1897 record_tdep->size_mq_attr = 32;
1898 record_tdep->size_termios = 44;
1899 record_tdep->size_pid_t = 4;
1900 record_tdep->size_winsize = 8;
1901 record_tdep->size_serial_struct = 60;
1902 record_tdep->size_serial_icounter_struct = 80;
1903 record_tdep->size_size_t = 4;
1904 record_tdep->size_iovec = 8;
1905 record_tdep->size_time_t = 4;
1906 }
1907 else
1908 internal_error (_("unexpected wordsize"));
1909
1910 /* These values are the second argument of system call "sys_fcntl"
1911 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1912 record_tdep->fcntl_F_GETLK = 5;
1913 record_tdep->fcntl_F_GETLK64 = 12;
1914 record_tdep->fcntl_F_SETLK64 = 13;
1915 record_tdep->fcntl_F_SETLKW64 = 14;
1916
1917 record_tdep->arg1 = PPC_R0_REGNUM + 3;
1918 record_tdep->arg2 = PPC_R0_REGNUM + 4;
1919 record_tdep->arg3 = PPC_R0_REGNUM + 5;
1920 record_tdep->arg4 = PPC_R0_REGNUM + 6;
1921 record_tdep->arg5 = PPC_R0_REGNUM + 7;
1922 record_tdep->arg6 = PPC_R0_REGNUM + 8;
1923
1924 /* These values are the second argument of system call "sys_ioctl".
1925 They are obtained from Linux Kernel source.
1926 See arch/powerpc/include/uapi/asm/ioctls.h. */
1927 record_tdep->ioctl_TCGETA = 0x40147417;
1928 record_tdep->ioctl_TCSETA = 0x80147418;
1929 record_tdep->ioctl_TCSETAW = 0x80147419;
1930 record_tdep->ioctl_TCSETAF = 0x8014741c;
1931 record_tdep->ioctl_TCGETS = 0x40007413 | (SIZE_OF_STRUCT_TERMIOS << 16);
1932 record_tdep->ioctl_TCSETS = 0x80007414 | (SIZE_OF_STRUCT_TERMIOS << 16);
1933 record_tdep->ioctl_TCSETSW = 0x80007415 | (SIZE_OF_STRUCT_TERMIOS << 16);
1934 record_tdep->ioctl_TCSETSF = 0x80007416 | (SIZE_OF_STRUCT_TERMIOS << 16);
1935
1936 record_tdep->ioctl_TCSBRK = 0x2000741d;
1937 record_tdep->ioctl_TCXONC = 0x2000741e;
1938 record_tdep->ioctl_TCFLSH = 0x2000741f;
1939 record_tdep->ioctl_TIOCEXCL = 0x540c;
1940 record_tdep->ioctl_TIOCNXCL = 0x540d;
1941 record_tdep->ioctl_TIOCSCTTY = 0x540e;
1942 record_tdep->ioctl_TIOCGPGRP = 0x40047477;
1943 record_tdep->ioctl_TIOCSPGRP = 0x80047476;
1944 record_tdep->ioctl_TIOCOUTQ = 0x40047473;
1945 record_tdep->ioctl_TIOCSTI = 0x5412;
1946 record_tdep->ioctl_TIOCGWINSZ = 0x40087468;
1947 record_tdep->ioctl_TIOCSWINSZ = 0x80087467;
1948 record_tdep->ioctl_TIOCMGET = 0x5415;
1949 record_tdep->ioctl_TIOCMBIS = 0x5416;
1950 record_tdep->ioctl_TIOCMBIC = 0x5417;
1951 record_tdep->ioctl_TIOCMSET = 0x5418;
1952 record_tdep->ioctl_TIOCGSOFTCAR = 0x5419;
1953 record_tdep->ioctl_TIOCSSOFTCAR = 0x541a;
1954 record_tdep->ioctl_FIONREAD = 0x4004667f;
1955 record_tdep->ioctl_TIOCINQ = 0x4004667f;
1956 record_tdep->ioctl_TIOCLINUX = 0x541c;
1957 record_tdep->ioctl_TIOCCONS = 0x541d;
1958 record_tdep->ioctl_TIOCGSERIAL = 0x541e;
1959 record_tdep->ioctl_TIOCSSERIAL = 0x541f;
1960 record_tdep->ioctl_TIOCPKT = 0x5420;
1961 record_tdep->ioctl_FIONBIO = 0x8004667e;
1962 record_tdep->ioctl_TIOCNOTTY = 0x5422;
1963 record_tdep->ioctl_TIOCSETD = 0x5423;
1964 record_tdep->ioctl_TIOCGETD = 0x5424;
1965 record_tdep->ioctl_TCSBRKP = 0x5425;
1966 record_tdep->ioctl_TIOCSBRK = 0x5427;
1967 record_tdep->ioctl_TIOCCBRK = 0x5428;
1968 record_tdep->ioctl_TIOCGSID = 0x5429;
1969 record_tdep->ioctl_TIOCGPTN = 0x40045430;
1970 record_tdep->ioctl_TIOCSPTLCK = 0x80045431;
1971 record_tdep->ioctl_FIONCLEX = 0x20006602;
1972 record_tdep->ioctl_FIOCLEX = 0x20006601;
1973 record_tdep->ioctl_FIOASYNC = 0x8004667d;
1974 record_tdep->ioctl_TIOCSERCONFIG = 0x5453;
1975 record_tdep->ioctl_TIOCSERGWILD = 0x5454;
1976 record_tdep->ioctl_TIOCSERSWILD = 0x5455;
1977 record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456;
1978 record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457;
1979 record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458;
1980 record_tdep->ioctl_TIOCSERGETLSR = 0x5459;
1981 record_tdep->ioctl_TIOCSERGETMULTI = 0x545a;
1982 record_tdep->ioctl_TIOCSERSETMULTI = 0x545b;
1983 record_tdep->ioctl_TIOCMIWAIT = 0x545c;
1984 record_tdep->ioctl_TIOCGICOUNT = 0x545d;
1985 record_tdep->ioctl_FIOQSIZE = 0x40086680;
1986 }
1987
1988 /* Return a floating-point format for a floating-point variable of
1989 length LEN in bits. If non-NULL, NAME is the name of its type.
1990 If no suitable type is found, return NULL. */
1991
1992 static const struct floatformat **
1993 ppc_floatformat_for_type (struct gdbarch *gdbarch,
1994 const char *name, int len)
1995 {
1996 if (len == 128 && name)
1997 {
1998 if (strcmp (name, "__float128") == 0
1999 || strcmp (name, "_Float128") == 0
2000 || strcmp (name, "_Float64x") == 0
2001 || strcmp (name, "complex _Float128") == 0
2002 || strcmp (name, "complex _Float64x") == 0)
2003 return floatformats_ieee_quad;
2004
2005 if (strcmp (name, "__ibm128") == 0)
2006 return floatformats_ibm_long_double;
2007 }
2008
2009 return default_floatformat_for_type (gdbarch, name, len);
2010 }
2011
2012 static bool
2013 linux_dwarf2_omit_typedef_p (struct type *target_type,
2014 const char *producer, const char *name)
2015 {
2016 int gcc_major, gcc_minor;
2017
2018 if (producer_is_gcc (producer, &gcc_major, &gcc_minor))
2019 {
2020 if ((target_type->code () == TYPE_CODE_FLT
2021 || target_type->code () == TYPE_CODE_COMPLEX)
2022 && (strcmp (name, "long double") == 0
2023 || strcmp (name, "complex long double") == 0))
2024 {
2025 /* IEEE 128-bit floating point and IBM long double are two
2026 encodings for 128-bit values. The DWARF debug data can't
2027 distinguish between them. See bugzilla:
2028 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104194
2029
2030 A GCC hack was introduced to still allow the debugger to identify
2031 the case where "long double" uses the IEEE 128-bit floating point
2032 format: GCC will emit a bogus DWARF type record pretending that
2033 "long double" is a typedef alias for the _Float128 type.
2034
2035 This hack should not be visible to the GDB user, so we replace
2036 this bogus typedef by a normal floating-point type, copying the
2037 format information from the target type of the bogus typedef. */
2038 return true;
2039 }
2040 }
2041 return false;
2042 }
2043
2044 /* Specify the powerpc64le target triplet.
2045 This can be variations of
2046 ppc64le-{distro}-linux-gcc
2047 and
2048 powerpc64le-{distro}-linux-gcc. */
2049
2050 static const char *
2051 ppc64le_gnu_triplet_regexp (struct gdbarch *gdbarch)
2052 {
2053 return "p(ower)?pc64le";
2054 }
2055
2056 /* Specify the powerpc64 target triplet.
2057 This can be variations of
2058 ppc64-{distro}-linux-gcc
2059 and
2060 powerpc64-{distro}-linux-gcc. */
2061
2062 static const char *
2063 ppc64_gnu_triplet_regexp (struct gdbarch *gdbarch)
2064 {
2065 return "p(ower)?pc64";
2066 }
2067
2068 /* Implement the linux_gcc_target_options method. */
2069
2070 static std::string
2071 ppc64_linux_gcc_target_options (struct gdbarch *gdbarch)
2072 {
2073 return "";
2074 }
2075
2076 static displaced_step_prepare_status
2077 ppc_linux_displaced_step_prepare (gdbarch *arch, thread_info *thread,
2078 CORE_ADDR &displaced_pc)
2079 {
2080 ppc_inferior_data *per_inferior = get_ppc_per_inferior (thread->inf);
2081 if (!per_inferior->disp_step_buf.has_value ())
2082 {
2083 /* Figure out where the displaced step buffer is. */
2084 CORE_ADDR disp_step_buf_addr
2085 = linux_displaced_step_location (thread->inf->arch ());
2086
2087 per_inferior->disp_step_buf.emplace (disp_step_buf_addr);
2088 }
2089
2090 return per_inferior->disp_step_buf->prepare (thread, displaced_pc);
2091 }
2092
2093 /* Convert a Dwarf 2 register number to a GDB register number for Linux. */
2094
2095 static int
2096 rs6000_linux_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
2097 {
2098 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep>(gdbarch);
2099
2100 if (0 <= num && num <= 31)
2101 return tdep->ppc_gp0_regnum + num;
2102 else if (32 <= num && num <= 63)
2103 /* Map dwarf register numbers for floating point, double, IBM double and
2104 IEEE 128-bit floating point to the fpr range. Will have to fix the
2105 mapping for the IEEE 128-bit register numbers later. */
2106 return tdep->ppc_fp0_regnum + (num - 32);
2107 else if (77 <= num && num < 77 + 32)
2108 return tdep->ppc_vr0_regnum + (num - 77);
2109 else
2110 switch (num)
2111 {
2112 case 65:
2113 return tdep->ppc_lr_regnum;
2114 case 66:
2115 return tdep->ppc_ctr_regnum;
2116 case 76:
2117 return tdep->ppc_xer_regnum;
2118 case 109:
2119 return tdep->ppc_vrsave_regnum;
2120 case 110:
2121 return tdep->ppc_vrsave_regnum - 1; /* vscr */
2122 }
2123
2124 /* Unknown DWARF register number. */
2125 return -1;
2126 }
2127
2128 /* Translate a .eh_frame register to DWARF register, or adjust a
2129 .debug_frame register. */
2130
2131 static int
2132 rs6000_linux_adjust_frame_regnum (struct gdbarch *gdbarch, int num,
2133 int eh_frame_p)
2134 {
2135 /* Linux uses the same numbering for .debug_frame numbering as .eh_frame. */
2136 return num;
2137 }
2138
2139 static void
2140 ppc_linux_init_abi (struct gdbarch_info info,
2141 struct gdbarch *gdbarch)
2142 {
2143 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
2144 struct tdesc_arch_data *tdesc_data = info.tdesc_data;
2145 static const char *const stap_integer_prefixes[] = { "i", NULL };
2146 static const char *const stap_register_indirection_prefixes[] = { "(",
2147 NULL };
2148 static const char *const stap_register_indirection_suffixes[] = { ")",
2149 NULL };
2150
2151 linux_init_abi (info, gdbarch, 0);
2152
2153 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
2154 128-bit, they can be either IBM long double or IEEE quad long double.
2155 The 64-bit long double case will be detected automatically using
2156 the size specified in debug info. We use a .gnu.attribute flag
2157 to distinguish between the IBM long double and IEEE quad cases. */
2158 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
2159 if (tdep->long_double_abi == POWERPC_LONG_DOUBLE_IEEE128)
2160 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_quad);
2161 else
2162 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
2163
2164 /* Support for floating-point data type variants. */
2165 set_gdbarch_floatformat_for_type (gdbarch, ppc_floatformat_for_type);
2166
2167 /* Support for replacing typedef record. */
2168 set_gdbarch_dwarf2_omit_typedef_p (gdbarch, linux_dwarf2_omit_typedef_p);
2169
2170 /* Handle inferior calls during interrupted system calls. */
2171 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
2172
2173 /* Get the syscall number from the arch's register. */
2174 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
2175
2176 /* SystemTap functions. */
2177 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
2178 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
2179 stap_register_indirection_prefixes);
2180 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
2181 stap_register_indirection_suffixes);
2182 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
2183 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
2184 set_gdbarch_stap_parse_special_token (gdbarch,
2185 ppc_stap_parse_special_token);
2186 /* Linux DWARF register mapping is different from the other OSes. */
2187 set_gdbarch_dwarf2_reg_to_regnum (gdbarch,
2188 rs6000_linux_dwarf2_reg_to_regnum);
2189 /* Note on Linux the mapping for the DWARF registers and the stab registers
2190 use the same numbers. Install rs6000_linux_dwarf2_reg_to_regnum for the
2191 stab register mappings as well. */
2192 set_gdbarch_stab_reg_to_regnum (gdbarch,
2193 rs6000_linux_dwarf2_reg_to_regnum);
2194 dwarf2_frame_set_adjust_regnum (gdbarch, rs6000_linux_adjust_frame_regnum);
2195
2196 if (tdep->wordsize == 4)
2197 {
2198 /* Until November 2001, gcc did not comply with the 32 bit SysV
2199 R4 ABI requirement that structures less than or equal to 8
2200 bytes should be returned in registers. Instead GCC was using
2201 the AIX/PowerOpen ABI - everything returned in memory
2202 (well ignoring vectors that is). When this was corrected, it
2203 wasn't fixed for GNU/Linux native platform. Use the
2204 PowerOpen struct convention. */
2205 set_gdbarch_return_value_as_value (gdbarch, ppc_linux_return_value);
2206 set_gdbarch_return_value (gdbarch, nullptr);
2207
2208 set_gdbarch_memory_remove_breakpoint (gdbarch,
2209 ppc_linux_memory_remove_breakpoint);
2210
2211 /* Shared library handling. */
2212 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
2213 set_solib_svr4_fetch_link_map_offsets
2214 (gdbarch, linux_ilp32_fetch_link_map_offsets);
2215
2216 /* Setting the correct XML syscall filename. */
2217 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC);
2218
2219 /* Trampolines. */
2220 tramp_frame_prepend_unwinder (gdbarch,
2221 &ppc32_linux_sigaction_tramp_frame);
2222 tramp_frame_prepend_unwinder (gdbarch,
2223 &ppc32_linux_sighandler_tramp_frame);
2224
2225 /* BFD target for core files. */
2226 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
2227 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
2228 else
2229 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
2230
2231 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
2232 {
2233 powerpc_so_ops = svr4_so_ops;
2234 /* Override dynamic resolve function. */
2235 powerpc_so_ops.in_dynsym_resolve_code =
2236 powerpc_linux_in_dynsym_resolve_code;
2237 }
2238 set_gdbarch_so_ops (gdbarch, &powerpc_so_ops);
2239
2240 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
2241 }
2242
2243 if (tdep->wordsize == 8)
2244 {
2245 if (tdep->elf_abi == POWERPC_ELF_V1)
2246 {
2247 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
2248 function descriptors). */
2249 set_gdbarch_convert_from_func_ptr_addr
2250 (gdbarch, ppc64_convert_from_func_ptr_addr);
2251
2252 set_gdbarch_elf_make_msymbol_special
2253 (gdbarch, ppc64_elf_make_msymbol_special);
2254 }
2255 else
2256 {
2257 set_gdbarch_elf_make_msymbol_special
2258 (gdbarch, ppc_elfv2_elf_make_msymbol_special);
2259
2260 set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint);
2261 }
2262
2263 /* Shared library handling. */
2264 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
2265 set_solib_svr4_fetch_link_map_offsets
2266 (gdbarch, linux_lp64_fetch_link_map_offsets);
2267
2268 /* Setting the correct XML syscall filename. */
2269 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC64);
2270
2271 /* Trampolines. */
2272 tramp_frame_prepend_unwinder (gdbarch,
2273 &ppc64_linux_sigaction_tramp_frame);
2274 tramp_frame_prepend_unwinder (gdbarch,
2275 &ppc64_linux_sighandler_tramp_frame);
2276
2277 /* BFD target for core files. */
2278 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
2279 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
2280 else
2281 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
2282 /* Set compiler triplet. */
2283 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
2284 set_gdbarch_gnu_triplet_regexp (gdbarch, ppc64le_gnu_triplet_regexp);
2285 else
2286 set_gdbarch_gnu_triplet_regexp (gdbarch, ppc64_gnu_triplet_regexp);
2287 /* Set GCC target options. */
2288 set_gdbarch_gcc_target_options (gdbarch, ppc64_linux_gcc_target_options);
2289 }
2290
2291 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
2292 set_gdbarch_iterate_over_regset_sections (gdbarch,
2293 ppc_linux_iterate_over_regset_sections);
2294
2295 /* Enable TLS support. */
2296 set_gdbarch_fetch_tls_load_module_address (gdbarch,
2297 svr4_fetch_objfile_link_map);
2298
2299 if (tdesc_data)
2300 {
2301 const struct tdesc_feature *feature;
2302
2303 /* If we have target-described registers, then we can safely
2304 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
2305 (whether they are described or not). */
2306 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
2307 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
2308
2309 /* If they are present, then assign them to the reserved number. */
2310 feature = tdesc_find_feature (info.target_desc,
2311 "org.gnu.gdb.power.linux");
2312 if (feature != NULL)
2313 {
2314 tdesc_numbered_register (feature, tdesc_data,
2315 PPC_ORIG_R3_REGNUM, "orig_r3");
2316 tdesc_numbered_register (feature, tdesc_data,
2317 PPC_TRAP_REGNUM, "trap");
2318 }
2319 }
2320
2321 /* Support reverse debugging. */
2322 set_gdbarch_process_record (gdbarch, ppc_process_record);
2323 set_gdbarch_process_record_signal (gdbarch, ppc_linux_record_signal);
2324 tdep->ppc_syscall_record = ppc_linux_syscall_record;
2325
2326 ppc_init_linux_record_tdep (&ppc_linux_record_tdep, 4);
2327 ppc_init_linux_record_tdep (&ppc64_linux_record_tdep, 8);
2328
2329 /* Setup displaced stepping. */
2330 set_gdbarch_displaced_step_prepare (gdbarch,
2331 ppc_linux_displaced_step_prepare);
2332
2333 }
2334
2335 void _initialize_ppc_linux_tdep ();
2336 void
2337 _initialize_ppc_linux_tdep ()
2338 {
2339 /* Register for all sub-families of the POWER/PowerPC: 32-bit and
2340 64-bit PowerPC, and the older rs6k. */
2341 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
2342 ppc_linux_init_abi);
2343 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
2344 ppc_linux_init_abi);
2345 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
2346 ppc_linux_init_abi);
2347
2348 /* Initialize the Linux target descriptions. */
2349 initialize_tdesc_powerpc_32l ();
2350 initialize_tdesc_powerpc_altivec32l ();
2351 initialize_tdesc_powerpc_vsx32l ();
2352 initialize_tdesc_powerpc_isa205_32l ();
2353 initialize_tdesc_powerpc_isa205_altivec32l ();
2354 initialize_tdesc_powerpc_isa205_vsx32l ();
2355 initialize_tdesc_powerpc_isa205_ppr_dscr_vsx32l ();
2356 initialize_tdesc_powerpc_isa207_vsx32l ();
2357 initialize_tdesc_powerpc_isa207_htm_vsx32l ();
2358 initialize_tdesc_powerpc_64l ();
2359 initialize_tdesc_powerpc_altivec64l ();
2360 initialize_tdesc_powerpc_vsx64l ();
2361 initialize_tdesc_powerpc_isa205_64l ();
2362 initialize_tdesc_powerpc_isa205_altivec64l ();
2363 initialize_tdesc_powerpc_isa205_vsx64l ();
2364 initialize_tdesc_powerpc_isa205_ppr_dscr_vsx64l ();
2365 initialize_tdesc_powerpc_isa207_vsx64l ();
2366 initialize_tdesc_powerpc_isa207_htm_vsx64l ();
2367 initialize_tdesc_powerpc_e500l ();
2368 }