blob: ea8e3b98fa4cd69d28a881e392bdd55942e0561e [file] [log] [blame]
Kevin Buettnerc877c8e2000-02-22 01:20:32 +00001/* Target-dependent code for GDB, the GNU debugger.
Andrew Cagney4e052ed2001-03-01 01:39:22 +00002
Joel Brobecker3666a042021-01-01 12:03:39 +04003 Copyright (C) 1986-2021 Free Software Foundation, Inc.
Kevin Buettnerc877c8e2000-02-22 01:20:32 +00004
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
Joel Brobeckera9762ec2007-08-23 18:08:50 +00009 the Free Software Foundation; either version 3 of the License, or
Kevin Buettnerc877c8e2000-02-22 01:20:32 +000010 (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
Joel Brobeckera9762ec2007-08-23 18:08:50 +000018 along with this program. If not, see <http://www.gnu.org/licenses/>. */
Kevin Buettnerc877c8e2000-02-22 01:20:32 +000019
20#include "defs.h"
21#include "frame.h"
22#include "inferior.h"
23#include "symtab.h"
24#include "target.h"
25#include "gdbcore.h"
26#include "gdbcmd.h"
27#include "symfile.h"
28#include "objfiles.h"
Andrew Cagney4e052ed2001-03-01 01:39:22 +000029#include "regcache.h"
Andrew Cagneyfd0407d2001-10-21 17:19:38 +000030#include "value.h"
Daniel Jacobowitz4be87832003-01-04 23:38:46 +000031#include "osabi.h"
Andrew Cagneyf9be6842004-03-15 21:35:25 +000032#include "regset.h"
Kevin Buettner6ded7992001-12-01 00:25:08 +000033#include "solib-svr4.h"
Ulrich Weigandcc5f0d62009-07-31 15:31:08 +000034#include "solib.h"
35#include "solist.h"
Kevin Buettner9aa1e682000-07-31 20:56:44 +000036#include "ppc-tdep.h"
Andreas Toblerd78489b2013-02-01 20:54:18 +000037#include "ppc64-tdep.h"
Ulrich Weigand7284e1b2008-05-03 17:16:44 +000038#include "ppc-linux-tdep.h"
Pedro Franco de Carvalhobd646142018-05-22 11:09:05 -030039#include "arch/ppc-linux-common.h"
40#include "arch/ppc-linux-tdesc.h"
Michael Eager5d853002012-01-30 17:09:40 +000041#include "glibc-tdep.h"
Kevin Buettner61a65092004-03-20 04:51:21 +000042#include "trad-frame.h"
43#include "frame-unwind.h"
Andrew Cagneya8f60bf2005-01-25 22:43:45 +000044#include "tramp-frame.h"
Tom Tromey76727912016-10-02 10:50:20 -060045#include "observable.h"
Ulrich Weigand85e747d2009-07-31 15:28:27 +000046#include "auxv.h"
47#include "elf/common.h"
Ulrich Weigand591a12a2014-02-04 18:44:14 +010048#include "elf/ppc64.h"
Ulrich Weigandcc5f0d62009-07-31 15:31:08 +000049#include "arch-utils.h"
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +000050#include "xml-syscall.h"
Pedro Alvesa5ee0f02010-08-04 15:27:57 +000051#include "linux-tdep.h"
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +080052#include "linux-record.h"
53#include "record-full.h"
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +080054#include "infrun.h"
Tom Tromey4c5e7a92021-03-08 07:27:57 -070055#include "expop.h"
Kevin Buettner9aa1e682000-07-31 20:56:44 +000056
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +000057#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>
Maciej W. Rozyckia2f63b22017-10-11 15:01:40 +010064#include "elf-bfd.h"
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +000065
Ulrich Weigand7284e1b2008-05-03 17:16:44 +000066#include "features/rs6000/powerpc-32l.c"
67#include "features/rs6000/powerpc-altivec32l.c"
Luis Machado604c2f82008-08-15 15:18:34 +000068#include "features/rs6000/powerpc-vsx32l.c"
Thiago Jung Bauermann69abc512008-11-18 21:39:47 +000069#include "features/rs6000/powerpc-isa205-32l.c"
70#include "features/rs6000/powerpc-isa205-altivec32l.c"
71#include "features/rs6000/powerpc-isa205-vsx32l.c"
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -030072#include "features/rs6000/powerpc-isa205-ppr-dscr-vsx32l.c"
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -030073#include "features/rs6000/powerpc-isa207-vsx32l.c"
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -030074#include "features/rs6000/powerpc-isa207-htm-vsx32l.c"
Ulrich Weigand7284e1b2008-05-03 17:16:44 +000075#include "features/rs6000/powerpc-64l.c"
76#include "features/rs6000/powerpc-altivec64l.c"
Luis Machado604c2f82008-08-15 15:18:34 +000077#include "features/rs6000/powerpc-vsx64l.c"
Thiago Jung Bauermann69abc512008-11-18 21:39:47 +000078#include "features/rs6000/powerpc-isa205-64l.c"
79#include "features/rs6000/powerpc-isa205-altivec64l.c"
80#include "features/rs6000/powerpc-isa205-vsx64l.c"
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -030081#include "features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c"
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -030082#include "features/rs6000/powerpc-isa207-vsx64l.c"
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -030083#include "features/rs6000/powerpc-isa207-htm-vsx64l.c"
Ulrich Weigand7284e1b2008-05-03 17:16:44 +000084#include "features/rs6000/powerpc-e500l.c"
85
Michael Eager5d853002012-01-30 17:09:40 +000086/* Shared library operations for PowerPC-Linux. */
87static struct target_so_ops powerpc_so_ops;
88
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +000089/* 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"
Kevin Buettnerc877c8e2000-02-22 01:20:32 +000092
Kevin Buettner122a33d2000-02-26 09:25:50 +000093/* 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
97 removing it.
98
99 Here is the problem that we're trying to solve...
100
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
106 this platform.
107
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.
113
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.
120
121 We start the program shmain.
122
123 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
124 [...]
125
126 We place two breakpoints, one on shr1 and the other on main.
127
128 (gdb) b shr1
129 Breakpoint 1 at 0x100409d4
130 (gdb) b main
131 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
132
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.
136
137 (gdb) x/2i 0x100409d4
138 0x100409d4 <shr1>: .long 0x0
139 0x100409d8 <shr1+4>: .long 0x0
140
141 Now run 'til main.
142
143 (gdb) r
144 Starting program: gdb.base/shmain
145 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
146
147 Breakpoint 2, main ()
148 at gdb.base/shmain.c:44
149 44 g = 1;
150
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
Tom de Vries30baf672019-10-26 09:55:32 +0200154 branches a short distance to the code which actually does the
Kevin Buettner122a33d2000-02-26 09:25:50 +0000155 resolving.
156
157 (gdb) x/2i 0x100409d4
158 0x100409d4 <shr1>: li r11,4
159 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
160 (gdb) c
161 Continuing.
162
163 Breakpoint 1, shr1 (x=1)
164 at gdb.base/shr1.c:19
165 19 l = 1;
166
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
Michael Snyder0df8b412011-01-10 20:38:51 +0000170 resolved to contain a branch that takes us directly to shr1.
Kevin Buettner122a33d2000-02-26 09:25:50 +0000171 (The real one, not the PLT entry.)
172
173 (gdb) x/2i 0x100409d4
174 0x100409d4 <shr1>: b 0xffaf76c <shr1>
175 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
176
177 The thing to note here is that the PLT entry for shr1 has been
178 changed twice.
179
180 Now the problem should be obvious. GDB places a breakpoint (a
Michael Snyder0df8b412011-01-10 20:38:51 +0000181 trap instruction) on the zero value of the PLT entry for shr1.
Kevin Buettner122a33d2000-02-26 09:25:50 +0000182 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.
185
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
Michael Snyder766062f2011-02-27 16:25:38 +0000190 executed as an instruction an illegal instruction trap was
Kevin Buettner122a33d2000-02-26 09:25:50 +0000191 generated instead. (0 is not a legal instruction.)
192
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
197 function.
198
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
Michael Snyder0df8b412011-01-10 20:38:51 +0000204 a trap instruction, we allow the old contents to be written back.
Kevin Buettner122a33d2000-02-26 09:25:50 +0000205 Otherwise, we silently do nothing.
206
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.
211
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
216 code. */
Pedro Alves63807e12009-02-22 01:02:20 +0000217static int
Markus Deulingae4b2282008-02-20 14:31:40 +0000218ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
219 struct bp_target_info *bp_tgt)
Kevin Buettner482ca3f2000-02-24 23:06:48 +0000220{
Maciej W. Rozycki0d5ed152014-10-03 12:44:58 +0100221 CORE_ADDR addr = bp_tgt->reqstd_address;
Andrew Cagneyf4f97052002-04-18 18:09:09 +0000222 const unsigned char *bp;
Kevin Buettner482ca3f2000-02-24 23:06:48 +0000223 int val;
224 int bplen;
Andrew Cagney50fd1282005-05-25 03:12:13 +0000225 gdb_byte old_contents[BREAKPOINT_MAX];
Kevin Buettner482ca3f2000-02-24 23:06:48 +0000226
227 /* Determine appropriate breakpoint contents and size for this address. */
Markus Deulingae4b2282008-02-20 14:31:40 +0000228 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
Kevin Buettner482ca3f2000-02-24 23:06:48 +0000229
Daniel Jacobowitz8defab12008-03-13 12:22:14 +0000230 /* Make sure we see the memory breakpoints. */
Tom Tromeycb85b212017-09-09 10:47:10 -0600231 scoped_restore restore_memory
232 = make_scoped_restore_show_memory_breakpoints (1);
Kevin Buettner482ca3f2000-02-24 23:06:48 +0000233 val = target_read_memory (addr, old_contents, bplen);
234
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
Michael Snyder0df8b412011-01-10 20:38:51 +0000237 old value. */
Kevin Buettner482ca3f2000-02-24 23:06:48 +0000238 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
Pedro Alvesdd110ab2011-12-14 14:55:27 +0000239 val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
Kevin Buettner482ca3f2000-02-24 23:06:48 +0000240
241 return val;
242}
Kevin Buettner6ded7992001-12-01 00:25:08 +0000243
Andrew Cagneyb9ff3012003-09-16 23:33:17 +0000244/* 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. */
248
Andrew Cagney05580c62003-11-07 20:44:51 +0000249static enum return_value_convention
Maciej W. Rozycki6a3a0102012-05-16 14:35:09 +0000250ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
Corinna Vinschenc055b102008-04-22 11:03:42 +0000251 struct type *valtype, struct regcache *regcache,
252 gdb_byte *readbuf, const gdb_byte *writebuf)
Andrew Cagneyb9ff3012003-09-16 23:33:17 +0000253{
Simon Marchi78134372020-05-14 13:46:38 -0400254 if ((valtype->code () == TYPE_CODE_STRUCT
255 || valtype->code () == TYPE_CODE_UNION)
Andrew Cagney05580c62003-11-07 20:44:51 +0000256 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
Simon Marchibd63c872020-09-14 11:08:03 -0400257 && valtype->is_vector ()))
Andrew Cagney05580c62003-11-07 20:44:51 +0000258 return RETURN_VALUE_STRUCT_CONVENTION;
259 else
Maciej W. Rozycki6a3a0102012-05-16 14:35:09 +0000260 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
Corinna Vinschenc055b102008-04-22 11:03:42 +0000261 readbuf, writebuf);
Andrew Cagneyb9ff3012003-09-16 23:33:17 +0000262}
263
Alan Modra74334982018-01-24 15:22:17 +1030264/* PLT stub in an executable. */
265static const struct ppc_insn_pattern powerpc32_plt_stub[] =
Michael Eager5d853002012-01-30 17:09:40 +0000266 {
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 */
271 { 0, 0, 0 }
272 };
273
Alan Modra74334982018-01-24 15:22:17 +1030274/* 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). */
277static const struct ppc_insn_pattern powerpc32_plt_stub_so_1[] =
Michael Eager5d853002012-01-30 17:09:40 +0000278 {
279 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
280 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
281 { 0xffffffff, 0x4e800420, 0 }, /* bctr */
Michael Eager5d853002012-01-30 17:09:40 +0000282 { 0, 0, 0 }
283 };
Alan Modra74334982018-01-24 15:22:17 +1030284
285/* The second variant is used when the PLT entry is more than +/-32k
286 from the GOT pointer (r30). */
287static const struct ppc_insn_pattern powerpc32_plt_stub_so_2[] =
288 {
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 */
293 { 0, 0, 0 }
294 };
295
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)
Michael Eager5d853002012-01-30 17:09:40 +0000298
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. */
302
303static int
304powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
305{
Tom Tromey7cbd4a92013-04-08 19:59:09 +0000306 struct bound_minimal_symbol sym;
Michael Eager5d853002012-01-30 17:09:40 +0000307
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))
311 return 1;
312
313 /* Check if we are in the resolver. */
314 sym = lookup_minimal_symbol_by_pc (pc);
Tom Tromey7cbd4a92013-04-08 19:59:09 +0000315 if (sym.minsym != NULL
Christian Biesingerc9d95fa2019-11-22 12:05:14 -0600316 && (strcmp (sym.minsym->linkage_name (), "__glink") == 0
317 || strcmp (sym.minsym->linkage_name (), "__glink_PLTresolve") == 0))
Michael Eager5d853002012-01-30 17:09:40 +0000318 return 1;
319
320 return 0;
321}
322
Wei-cheng Wangddeca1d2015-01-19 23:34:07 +0800323/* Follow PLT stub to actual routine.
324
325 When the execution direction is EXEC_REVERSE, scan backward to
326 check whether we are in the middle of a PLT stub. Currently,
Alan Modra74334982018-01-24 15:22:17 +1030327 we only look-behind at most 4 instructions (the max length of a PLT
Wei-cheng Wangddeca1d2015-01-19 23:34:07 +0800328 stub sequence. */
Michael Eager5d853002012-01-30 17:09:40 +0000329
330static CORE_ADDR
331ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
332{
Alan Modra74334982018-01-24 15:22:17 +1030333 unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
Michael Eager5d853002012-01-30 17:09:40 +0000334 struct gdbarch *gdbarch = get_frame_arch (frame);
335 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
336 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
337 CORE_ADDR target = 0;
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800338 int scan_limit, i;
Michael Eager5d853002012-01-30 17:09:40 +0000339
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800340 scan_limit = 1;
341 /* When reverse-debugging, scan backward to check whether we are
342 in the middle of trampoline code. */
343 if (execution_direction == EXEC_REVERSE)
Alan Modra74334982018-01-24 15:22:17 +1030344 scan_limit = 4; /* At most 4 instructions. */
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800345
346 for (i = 0; i < scan_limit; i++)
Michael Eager5d853002012-01-30 17:09:40 +0000347 {
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800348 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
349 {
Alan Modra74334982018-01-24 15:22:17 +1030350 /* Calculate PLT entry address from
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800351 lis r11, xxxx
Alan Modra74334982018-01-24 15:22:17 +1030352 lwz r11, xxxx(r11). */
353 target = ((ppc_insn_d_field (insnbuf[0]) << 16)
354 + ppc_insn_d_field (insnbuf[1]));
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800355 }
Alan Modra74334982018-01-24 15:22:17 +1030356 else if (i < ARRAY_SIZE (powerpc32_plt_stub_so_1) - 1
357 && ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_1,
358 insnbuf))
359 {
360 /* Calculate PLT entry address from
361 lwz r11, xxxx(r30). */
362 target = (ppc_insn_d_field (insnbuf[0])
363 + get_frame_register_unsigned (frame,
364 tdep->ppc_gp0_regnum + 30));
365 }
366 else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_2,
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800367 insnbuf))
368 {
Alan Modra74334982018-01-24 15:22:17 +1030369 /* Calculate PLT entry address from
370 addis r11, r30, xxxx
371 lwz r11, xxxx(r11). */
372 target = ((ppc_insn_d_field (insnbuf[0]) << 16)
373 + ppc_insn_d_field (insnbuf[1])
374 + get_frame_register_unsigned (frame,
375 tdep->ppc_gp0_regnum + 30));
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800376 }
377 else
378 {
Alan Modra74334982018-01-24 15:22:17 +1030379 /* Scan backward one more instruction if it doesn't match. */
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800380 pc -= 4;
381 continue;
382 }
383
Alan Modra74334982018-01-24 15:22:17 +1030384 target = read_memory_unsigned_integer (target, 4, byte_order);
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800385 return target;
Michael Eager5d853002012-01-30 17:09:40 +0000386 }
387
Wei-cheng Wangcf90fd92015-01-17 14:30:59 +0800388 return 0;
Michael Eager5d853002012-01-30 17:09:40 +0000389}
Jim Blandyf470a702003-06-13 00:06:11 +0000390
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000391/* Wrappers to handle Linux-only registers. */
392
393static void
394ppc_linux_supply_gregset (const struct regset *regset,
395 struct regcache *regcache,
396 int regnum, const void *gregs, size_t len)
397{
Simon Marchi19ba03f2015-09-25 14:08:07 -0400398 const struct ppc_reg_offsets *offsets
399 = (const struct ppc_reg_offsets *) regset->regmap;
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000400
401 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
402
Yao Qiac7936d2017-10-25 16:37:03 +0100403 if (ppc_linux_trap_reg_p (regcache->arch ()))
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000404 {
405 /* "orig_r3" is stored 2 slots after "pc". */
406 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
Simon Marchi19ba03f2015-09-25 14:08:07 -0400407 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, (const gdb_byte *) gregs,
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000408 offsets->pc_offset + 2 * offsets->gpr_size,
409 offsets->gpr_size);
410
411 /* "trap" is stored 8 slots after "pc". */
412 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
Simon Marchi19ba03f2015-09-25 14:08:07 -0400413 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, (const gdb_byte *) gregs,
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000414 offsets->pc_offset + 8 * offsets->gpr_size,
415 offsets->gpr_size);
416 }
417}
Andrew Cagneyf9be6842004-03-15 21:35:25 +0000418
419static void
Alan Modraf2db2372007-08-30 13:13:59 +0000420ppc_linux_collect_gregset (const struct regset *regset,
421 const struct regcache *regcache,
422 int regnum, void *gregs, size_t len)
Andrew Cagneyf9be6842004-03-15 21:35:25 +0000423{
Simon Marchi19ba03f2015-09-25 14:08:07 -0400424 const struct ppc_reg_offsets *offsets
425 = (const struct ppc_reg_offsets *) regset->regmap;
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000426
427 /* Clear areas in the linux gregset not written elsewhere. */
Alan Modraf2db2372007-08-30 13:13:59 +0000428 if (regnum == -1)
429 memset (gregs, 0, len);
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000430
Alan Modraf2db2372007-08-30 13:13:59 +0000431 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000432
Yao Qiac7936d2017-10-25 16:37:03 +0100433 if (ppc_linux_trap_reg_p (regcache->arch ()))
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000434 {
435 /* "orig_r3" is stored 2 slots after "pc". */
436 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
Simon Marchi19ba03f2015-09-25 14:08:07 -0400437 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, (gdb_byte *) gregs,
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000438 offsets->pc_offset + 2 * offsets->gpr_size,
439 offsets->gpr_size);
440
441 /* "trap" is stored 8 slots after "pc". */
442 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
Simon Marchi19ba03f2015-09-25 14:08:07 -0400443 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, (gdb_byte *) gregs,
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000444 offsets->pc_offset + 8 * offsets->gpr_size,
445 offsets->gpr_size);
446 }
Andrew Cagneyf9be6842004-03-15 21:35:25 +0000447}
448
Alan Modraf2db2372007-08-30 13:13:59 +0000449/* Regset descriptions. */
450static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
451 {
452 /* General-purpose registers. */
453 /* .r0_offset = */ 0,
454 /* .gpr_size = */ 4,
455 /* .xr_size = */ 4,
456 /* .pc_offset = */ 128,
457 /* .ps_offset = */ 132,
458 /* .cr_offset = */ 152,
459 /* .lr_offset = */ 144,
460 /* .ctr_offset = */ 140,
461 /* .xer_offset = */ 148,
462 /* .mq_offset = */ 156,
463
464 /* Floating-point registers. */
465 /* .f0_offset = */ 0,
466 /* .fpscr_offset = */ 256,
Pedro Franco de Carvalho1d75a652018-05-22 11:09:05 -0300467 /* .fpscr_size = */ 8
Alan Modraf2db2372007-08-30 13:13:59 +0000468 };
469
470static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
471 {
472 /* General-purpose registers. */
473 /* .r0_offset = */ 0,
474 /* .gpr_size = */ 8,
475 /* .xr_size = */ 8,
476 /* .pc_offset = */ 256,
477 /* .ps_offset = */ 264,
478 /* .cr_offset = */ 304,
479 /* .lr_offset = */ 288,
480 /* .ctr_offset = */ 280,
481 /* .xer_offset = */ 296,
482 /* .mq_offset = */ 312,
483
484 /* Floating-point registers. */
485 /* .f0_offset = */ 0,
486 /* .fpscr_offset = */ 256,
Pedro Franco de Carvalho1d75a652018-05-22 11:09:05 -0300487 /* .fpscr_size = */ 8
Alan Modraf2db2372007-08-30 13:13:59 +0000488 };
489
490static const struct regset ppc32_linux_gregset = {
491 &ppc32_linux_reg_offsets,
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000492 ppc_linux_supply_gregset,
Andreas Arnez09424cf2014-05-13 11:05:57 +0000493 ppc_linux_collect_gregset
Andrew Cagneyf9be6842004-03-15 21:35:25 +0000494};
495
Alan Modraf2db2372007-08-30 13:13:59 +0000496static const struct regset ppc64_linux_gregset = {
497 &ppc64_linux_reg_offsets,
Ulrich Weigand7284e1b2008-05-03 17:16:44 +0000498 ppc_linux_supply_gregset,
Andreas Arnez09424cf2014-05-13 11:05:57 +0000499 ppc_linux_collect_gregset
Andrew Cagneyf9be6842004-03-15 21:35:25 +0000500};
501
Alan Modraf2db2372007-08-30 13:13:59 +0000502static const struct regset ppc32_linux_fpregset = {
503 &ppc32_linux_reg_offsets,
504 ppc_supply_fpregset,
Andreas Arnez09424cf2014-05-13 11:05:57 +0000505 ppc_collect_fpregset
Alan Modraf2db2372007-08-30 13:13:59 +0000506};
507
Pedro Franco de Carvalho1d75a652018-05-22 11:09:05 -0300508static const struct regcache_map_entry ppc32_le_linux_vrregmap[] =
509 {
510 { 32, PPC_VR0_REGNUM, 16 },
511 { 1, PPC_VSCR_REGNUM, 4 },
512 { 1, REGCACHE_MAP_SKIP, 12 },
513 { 1, PPC_VRSAVE_REGNUM, 4 },
514 { 1, REGCACHE_MAP_SKIP, 12 },
515 { 0 }
516 };
517
518static const struct regcache_map_entry ppc32_be_linux_vrregmap[] =
519 {
520 { 32, PPC_VR0_REGNUM, 16 },
521 { 1, REGCACHE_MAP_SKIP, 12},
522 { 1, PPC_VSCR_REGNUM, 4 },
523 { 1, PPC_VRSAVE_REGNUM, 4 },
524 { 1, REGCACHE_MAP_SKIP, 12 },
525 { 0 }
526 };
527
528static const struct regset ppc32_le_linux_vrregset = {
529 ppc32_le_linux_vrregmap,
530 regcache_supply_regset,
Pedro Franco de Carvalho5c849b22018-10-26 09:37:53 -0300531 regcache_collect_regset
Pedro Franco de Carvalho1d75a652018-05-22 11:09:05 -0300532};
533
534static const struct regset ppc32_be_linux_vrregset = {
535 ppc32_be_linux_vrregmap,
536 regcache_supply_regset,
Pedro Franco de Carvalho5c849b22018-10-26 09:37:53 -0300537 regcache_collect_regset
Carlos Eduardo Seo06caf7d2007-10-29 20:26:42 +0000538};
539
Pedro Franco de Carvalho2c3305f2018-05-22 11:09:05 -0300540static const struct regcache_map_entry ppc32_linux_vsxregmap[] =
541 {
542 { 32, PPC_VSR0_UPPER_REGNUM, 8 },
543 { 0 }
544 };
545
Luis Machado604c2f82008-08-15 15:18:34 +0000546static const struct regset ppc32_linux_vsxregset = {
Pedro Franco de Carvalho2c3305f2018-05-22 11:09:05 -0300547 ppc32_linux_vsxregmap,
548 regcache_supply_regset,
549 regcache_collect_regset
Luis Machado604c2f82008-08-15 15:18:34 +0000550};
551
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -0300552/* Program Priorty Register regmap. */
553
554static const struct regcache_map_entry ppc32_regmap_ppr[] =
555 {
556 { 1, PPC_PPR_REGNUM, 8 },
557 { 0 }
558 };
559
560/* Program Priorty Register regset. */
561
562const struct regset ppc32_linux_pprregset = {
563 ppc32_regmap_ppr,
564 regcache_supply_regset,
565 regcache_collect_regset
566};
567
568/* Data Stream Control Register regmap. */
569
570static const struct regcache_map_entry ppc32_regmap_dscr[] =
571 {
572 { 1, PPC_DSCR_REGNUM, 8 },
573 { 0 }
574 };
575
576/* Data Stream Control Register regset. */
577
578const struct regset ppc32_linux_dscrregset = {
579 ppc32_regmap_dscr,
580 regcache_supply_regset,
581 regcache_collect_regset
582};
583
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -0300584/* Target Address Register regmap. */
585
586static const struct regcache_map_entry ppc32_regmap_tar[] =
587 {
588 { 1, PPC_TAR_REGNUM, 8 },
589 { 0 }
590 };
591
592/* Target Address Register regset. */
593
594const struct regset ppc32_linux_tarregset = {
595 ppc32_regmap_tar,
596 regcache_supply_regset,
597 regcache_collect_regset
598};
599
Edjunior Barbosa Machado232bfb82018-10-26 09:37:54 -0300600/* Event-Based Branching regmap. */
601
602static const struct regcache_map_entry ppc32_regmap_ebb[] =
603 {
604 { 1, PPC_EBBRR_REGNUM, 8 },
605 { 1, PPC_EBBHR_REGNUM, 8 },
606 { 1, PPC_BESCR_REGNUM, 8 },
607 { 0 }
608 };
609
610/* Event-Based Branching regset. */
611
612const struct regset ppc32_linux_ebbregset = {
613 ppc32_regmap_ebb,
614 regcache_supply_regset,
615 regcache_collect_regset
616};
617
618/* Performance Monitoring Unit regmap. */
619
620static const struct regcache_map_entry ppc32_regmap_pmu[] =
621 {
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 },
627 { 0 }
628 };
629
630/* Performance Monitoring Unit regset. */
631
632const struct regset ppc32_linux_pmuregset = {
633 ppc32_regmap_pmu,
634 regcache_supply_regset,
635 regcache_collect_regset
636};
637
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -0300638/* Hardware Transactional Memory special-purpose register regmap. */
639
640static const struct regcache_map_entry ppc32_regmap_tm_spr[] =
641 {
642 { 1, PPC_TFHAR_REGNUM, 8 },
643 { 1, PPC_TEXASR_REGNUM, 8 },
644 { 1, PPC_TFIAR_REGNUM, 8 },
645 { 0 }
646 };
647
648/* Hardware Transactional Memory special-purpose register regset. */
649
650const struct regset ppc32_linux_tm_sprregset = {
651 ppc32_regmap_tm_spr,
652 regcache_supply_regset,
653 regcache_collect_regset
654};
655
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
Tom de Vries405feb72019-10-17 18:06:36 +0200660 position of the register in the fields depends on the endianness.
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -0300661 The 32-bit regmap is the same for both endian types because the
662 fields are all 4-byte long.
663
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). */
676
677static const struct regcache_map_entry ppc32_regmap_cgpr[] =
678 {
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. */
686 { 0 }
687 };
688
689static const struct regcache_map_entry ppc64_le_regmap_cgpr[] =
690 {
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},
700 { 0 }
701 };
702
703static const struct regcache_map_entry ppc64_be_regmap_cgpr[] =
704 {
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},
714 { 0 }
715 };
716
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.
720
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. */
725
726static const struct regset ppc32_linux_cgprregset = {
727 ppc32_regmap_cgpr,
728 regcache_supply_regset,
729 regcache_collect_regset,
730 REGSET_VARIABLE_SIZE
731};
732
733static const struct regset ppc64_be_linux_cgprregset = {
734 ppc64_be_regmap_cgpr,
735 regcache_supply_regset,
736 regcache_collect_regset
737};
738
739static const struct regset ppc64_le_linux_cgprregset = {
740 ppc64_le_regmap_cgpr,
741 regcache_supply_regset,
742 regcache_collect_regset
743};
744
745/* Hardware Transactional Memory checkpointed floating-point regmap. */
746
747static const struct regcache_map_entry ppc32_regmap_cfpr[] =
748 {
749 { 32, PPC_CF0_REGNUM, 8 },
750 { 1, PPC_CFPSCR_REGNUM, 8 },
751 { 0 }
752 };
753
754/* Hardware Transactional Memory checkpointed floating-point regset. */
755
756const struct regset ppc32_linux_cfprregset = {
757 ppc32_regmap_cfpr,
758 regcache_supply_regset,
759 regcache_collect_regset
760};
761
762/* Regmaps for the Hardware Transactional Memory checkpointed vector
763 regsets, for big and little endian targets. The position of the
Tom de Vries405feb72019-10-17 18:06:36 +0200764 4-byte VSCR in its 16-byte field depends on the endianness. */
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -0300765
766static const struct regcache_map_entry ppc32_le_regmap_cvmx[] =
767 {
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 },
773 { 0 }
774 };
775
776static const struct regcache_map_entry ppc32_be_regmap_cvmx[] =
777 {
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},
783 { 0 }
784 };
785
786/* Hardware Transactional Memory checkpointed vector regsets, for little
787 and big endian targets. */
788
789static const struct regset ppc32_le_linux_cvmxregset = {
790 ppc32_le_regmap_cvmx,
791 regcache_supply_regset,
792 regcache_collect_regset
793};
794
795static const struct regset ppc32_be_linux_cvmxregset = {
796 ppc32_be_regmap_cvmx,
797 regcache_supply_regset,
798 regcache_collect_regset
799};
800
801/* Hardware Transactional Memory checkpointed vector-scalar regmap. */
802
803static const struct regcache_map_entry ppc32_regmap_cvsx[] =
804 {
805 { 32, PPC_CVSR0_UPPER_REGNUM, 8 },
806 { 0 }
807 };
808
809/* Hardware Transactional Memory checkpointed vector-scalar regset. */
810
811const struct regset ppc32_linux_cvsxregset = {
812 ppc32_regmap_cvsx,
813 regcache_supply_regset,
814 regcache_collect_regset
815};
816
817/* Hardware Transactional Memory checkpointed Program Priority Register
818 regmap. */
819
820static const struct regcache_map_entry ppc32_regmap_cppr[] =
821 {
822 { 1, PPC_CPPR_REGNUM, 8 },
823 { 0 }
824 };
825
826/* Hardware Transactional Memory checkpointed Program Priority Register
827 regset. */
828
829const struct regset ppc32_linux_cpprregset = {
830 ppc32_regmap_cppr,
831 regcache_supply_regset,
832 regcache_collect_regset
833};
834
835/* Hardware Transactional Memory checkpointed Data Stream Control
836 Register regmap. */
837
838static const struct regcache_map_entry ppc32_regmap_cdscr[] =
839 {
840 { 1, PPC_CDSCR_REGNUM, 8 },
841 { 0 }
842 };
843
844/* Hardware Transactional Memory checkpointed Data Stream Control
845 Register regset. */
846
847const struct regset ppc32_linux_cdscrregset = {
848 ppc32_regmap_cdscr,
849 regcache_supply_regset,
850 regcache_collect_regset
851};
852
853/* Hardware Transactional Memory checkpointed Target Address Register
854 regmap. */
855
856static const struct regcache_map_entry ppc32_regmap_ctar[] =
857 {
858 { 1, PPC_CTAR_REGNUM, 8 },
859 { 0 }
860 };
861
862/* Hardware Transactional Memory checkpointed Target Address Register
863 regset. */
864
865const struct regset ppc32_linux_ctarregset = {
866 ppc32_regmap_ctar,
867 regcache_supply_regset,
868 regcache_collect_regset
869};
870
Alan Modraf2db2372007-08-30 13:13:59 +0000871const struct regset *
872ppc_linux_gregset (int wordsize)
Andrew Cagneyf9be6842004-03-15 21:35:25 +0000873{
Alan Modraf2db2372007-08-30 13:13:59 +0000874 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
Daniel Jacobowitz2fda4972002-07-30 19:03:49 +0000875}
876
Alan Modraf2db2372007-08-30 13:13:59 +0000877const struct regset *
878ppc_linux_fpregset (void)
879{
880 return &ppc32_linux_fpregset;
881}
Daniel Jacobowitz2fda4972002-07-30 19:03:49 +0000882
Pedro Franco de Carvalho1d75a652018-05-22 11:09:05 -0300883const struct regset *
884ppc_linux_vrregset (struct gdbarch *gdbarch)
885{
886 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
887 return &ppc32_be_linux_vrregset;
888 else
889 return &ppc32_le_linux_vrregset;
890}
891
Pedro Franco de Carvalho2c3305f2018-05-22 11:09:05 -0300892const struct regset *
893ppc_linux_vsxregset (void)
894{
895 return &ppc32_linux_vsxregset;
896}
897
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -0300898const struct regset *
899ppc_linux_cgprregset (struct gdbarch *gdbarch)
900{
901 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
902
903 if (tdep->wordsize == 4)
904 {
905 return &ppc32_linux_cgprregset;
906 }
907 else
908 {
909 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
910 return &ppc64_be_linux_cgprregset;
911 else
912 return &ppc64_le_linux_cgprregset;
913 }
914}
915
916const struct regset *
917ppc_linux_cvmxregset (struct gdbarch *gdbarch)
918{
919 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
920 return &ppc32_be_linux_cvmxregset;
921 else
922 return &ppc32_le_linux_cvmxregset;
923}
924
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
933 most cases. */
934
935static void
936ppc_linux_collect_core_cpgrregset (const struct regset *regset,
937 const struct regcache *regcache,
938 int regnum, void *buf, size_t len)
939{
940 struct gdbarch *gdbarch = regcache->arch ();
941 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
942
943 const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
944
945 /* We collect the checkpointed GPRs already defined in the regular
946 regmap, then overlay TFHAR/MSR on the checkpointed NIP/MSR
947 slots. */
948 cgprregset->collect_regset (cgprregset, regcache, regnum, buf, len);
949
950 /* Check that we are collecting all the registers, which should be
951 the case when generating a core file. */
952 if (regnum != -1)
953 return;
954
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
958 values. */
959 int pt_offset = 32;
960
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);
964
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));
972
973 pt_offset = 33;
974
975 (regcache->raw_collect_integer
976 (PPC_MSR_REGNUM, ((gdb_byte *) buf) + pt_offset * tdep->wordsize,
977 tdep->wordsize, false));
978}
979
Andreas Arnez5aa82d02014-09-04 15:26:43 +0000980/* Iterate over supported core file register note sections. */
981
982static void
983ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
984 iterate_over_regset_sections_cb *cb,
985 void *cb_data,
986 const struct regcache *regcache)
987{
988 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
989 int have_altivec = tdep->ppc_vr0_regnum != -1;
990 int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -0300991 int have_ppr = tdep->ppc_ppr_regnum != -1;
992 int have_dscr = tdep->ppc_dscr_regnum != -1;
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -0300993 int have_tar = tdep->ppc_tar_regnum != -1;
Andreas Arnez5aa82d02014-09-04 15:26:43 +0000994
Andreas Arnez8f0435f2014-09-12 08:42:48 +0000995 if (tdep->wordsize == 4)
Alan Haywarda616bb92018-08-13 10:04:11 +0100996 cb (".reg", 48 * 4, 48 * 4, &ppc32_linux_gregset, NULL, cb_data);
Andreas Arnez8f0435f2014-09-12 08:42:48 +0000997 else
Alan Haywarda616bb92018-08-13 10:04:11 +0100998 cb (".reg", 48 * 8, 48 * 8, &ppc64_linux_gregset, NULL, cb_data);
Andreas Arnez8f0435f2014-09-12 08:42:48 +0000999
Alan Haywarda616bb92018-08-13 10:04:11 +01001000 cb (".reg2", 264, 264, &ppc32_linux_fpregset, NULL, cb_data);
Andreas Arnez5aa82d02014-09-04 15:26:43 +00001001
1002 if (have_altivec)
Pedro Franco de Carvalho1d75a652018-05-22 11:09:05 -03001003 {
1004 const struct regset *vrregset = ppc_linux_vrregset (gdbarch);
Alan Haywarda616bb92018-08-13 10:04:11 +01001005 cb (".reg-ppc-vmx", PPC_LINUX_SIZEOF_VRREGSET, PPC_LINUX_SIZEOF_VRREGSET,
1006 vrregset, "ppc Altivec", cb_data);
Pedro Franco de Carvalho1d75a652018-05-22 11:09:05 -03001007 }
Andreas Arnez5aa82d02014-09-04 15:26:43 +00001008
1009 if (have_vsx)
Alan Haywarda616bb92018-08-13 10:04:11 +01001010 cb (".reg-ppc-vsx", PPC_LINUX_SIZEOF_VSXREGSET, PPC_LINUX_SIZEOF_VSXREGSET,
Pedro Franco de Carvalhod0783082018-05-22 11:09:05 -03001011 &ppc32_linux_vsxregset, "POWER7 VSX", cb_data);
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -03001012
1013 if (have_ppr)
1014 cb (".reg-ppc-ppr", PPC_LINUX_SIZEOF_PPRREGSET,
1015 PPC_LINUX_SIZEOF_PPRREGSET,
1016 &ppc32_linux_pprregset, "Priority Program Register", cb_data);
1017
1018 if (have_dscr)
1019 cb (".reg-ppc-dscr", PPC_LINUX_SIZEOF_DSCRREGSET,
1020 PPC_LINUX_SIZEOF_DSCRREGSET,
1021 &ppc32_linux_dscrregset, "Data Stream Control Register",
1022 cb_data);
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -03001023
1024 if (have_tar)
1025 cb (".reg-ppc-tar", PPC_LINUX_SIZEOF_TARREGSET,
1026 PPC_LINUX_SIZEOF_TARREGSET,
1027 &ppc32_linux_tarregset, "Target Address Register", cb_data);
Edjunior Barbosa Machado232bfb82018-10-26 09:37:54 -03001028
1029 /* EBB registers are unavailable when ptrace returns ENODATA. Check
1030 availability when generating a core file (regcache != NULL). */
1031 if (tdep->have_ebb)
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",
1037 cb_data);
1038
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",
1043 cb_data);
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -03001044
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",
1050 cb_data);
1051
1052 /* Checkpointed registers can be unavailable, don't call back if
1053 we are generating a core file. */
1054
1055 if (tdep->have_htm_core)
1056 {
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))
1064 {
1065 int cgpr_size = (tdep->wordsize == 4?
1066 PPC32_LINUX_SIZEOF_CGPRREGSET
1067 : PPC64_LINUX_SIZEOF_CGPRREGSET);
1068
1069 const struct regset *cgprregset =
1070 ppc_linux_cgprregset (gdbarch);
1071
1072 if (regcache != NULL)
1073 {
1074 struct regset core_cgprregset = *cgprregset;
1075
1076 core_cgprregset.collect_regset
1077 = ppc_linux_collect_core_cpgrregset;
1078
1079 cb (".reg-ppc-tm-cgpr",
1080 cgpr_size, cgpr_size,
1081 &core_cgprregset,
1082 "Checkpointed General Purpose Registers", cb_data);
1083 }
1084 else
1085 {
1086 cb (".reg-ppc-tm-cgpr",
1087 cgpr_size, cgpr_size,
1088 cgprregset,
1089 "Checkpointed General Purpose Registers", cb_data);
1090 }
1091 }
1092 }
1093
1094 if (tdep->have_htm_fpu)
1095 {
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);
1102 }
1103
1104 if (tdep->have_htm_altivec)
1105 {
1106 if (regcache == NULL ||
1107 REG_VALID == regcache->get_register_status (PPC_CVR0_REGNUM))
1108 {
1109 const struct regset *cvmxregset =
1110 ppc_linux_cvmxregset (gdbarch);
1111
1112 cb (".reg-ppc-tm-cvmx", PPC_LINUX_SIZEOF_CVMXREGSET,
1113 PPC_LINUX_SIZEOF_CVMXREGSET,
1114 cvmxregset,
1115 "Checkpointed Altivec (VMX) Registers", cb_data);
1116 }
1117 }
1118
1119 if (tdep->have_htm_vsx)
1120 {
1121 if (regcache == NULL ||
1122 (REG_VALID
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);
1128 }
1129
1130 if (tdep->ppc_cppr_regnum != -1)
1131 {
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);
1138 }
1139
1140 if (tdep->ppc_cdscr_regnum != -1)
1141 {
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);
1148 }
1149
1150 if (tdep->ppc_ctar_regnum)
1151 {
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);
1158 }
Andreas Arnez5aa82d02014-09-04 15:26:43 +00001159}
1160
Jason Thorpe7b112f92002-05-30 01:21:53 +00001161static void
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001162ppc_linux_sigtramp_cache (struct frame_info *this_frame,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001163 struct trad_frame_cache *this_cache,
1164 CORE_ADDR func, LONGEST offset,
1165 int bias)
1166{
1167 CORE_ADDR base;
1168 CORE_ADDR regs;
1169 CORE_ADDR gpregs;
1170 CORE_ADDR fpregs;
1171 int i;
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001172 struct gdbarch *gdbarch = get_frame_arch (this_frame);
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001173 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
Ulrich Weigande17a4112009-07-02 17:25:59 +00001174 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001175
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001176 base = get_frame_register_unsigned (this_frame,
1177 gdbarch_sp_regnum (gdbarch));
1178 if (bias > 0 && get_frame_pc (this_frame) != func)
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001179 /* See below, some signal trampolines increment the stack as their
1180 first instruction, need to compensate for that. */
1181 base -= bias;
1182
1183 /* Find the address of the register buffer pointer. */
1184 regs = base + offset;
1185 /* Use that to find the address of the corresponding register
1186 buffers. */
Ulrich Weigande17a4112009-07-02 17:25:59 +00001187 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001188 fpregs = gpregs + 48 * tdep->wordsize;
1189
1190 /* General purpose. */
1191 for (i = 0; i < 32; i++)
1192 {
1193 int regnum = i + tdep->ppc_gp0_regnum;
Michael Snyder0df8b412011-01-10 20:38:51 +00001194 trad_frame_set_reg_addr (this_cache,
1195 regnum, gpregs + i * tdep->wordsize);
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001196 }
Ulrich Weigand3e8c5682007-06-18 17:45:26 +00001197 trad_frame_set_reg_addr (this_cache,
Markus Deuling40a6adc2007-11-16 04:53:46 +00001198 gdbarch_pc_regnum (gdbarch),
Ulrich Weigand3e8c5682007-06-18 17:45:26 +00001199 gpregs + 32 * tdep->wordsize);
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001200 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);
1208
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001209 if (ppc_linux_trap_reg_p (gdbarch))
1210 {
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);
1215 }
1216
Paul Gilliam60f140f2006-11-13 18:50:11 +00001217 if (ppc_floating_point_unit_p (gdbarch))
1218 {
1219 /* Floating point registers. */
1220 for (i = 0; i < 32; i++)
1221 {
Markus Deuling40a6adc2007-11-16 04:53:46 +00001222 int regnum = i + gdbarch_fp0_regnum (gdbarch);
Paul Gilliam60f140f2006-11-13 18:50:11 +00001223 trad_frame_set_reg_addr (this_cache, regnum,
1224 fpregs + i * tdep->wordsize);
1225 }
1226 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
Simon Marchidda83cd2020-11-02 10:26:14 -05001227 fpregs + 32 * tdep->wordsize);
Paul Gilliam60f140f2006-11-13 18:50:11 +00001228 }
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001229 trad_frame_set_id (this_cache, frame_id_build (base, func));
1230}
1231
1232static void
1233ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001234 struct frame_info *this_frame,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001235 struct trad_frame_cache *this_cache,
1236 CORE_ADDR func)
1237{
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001238 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001239 0xd0 /* Offset to ucontext_t. */
1240 + 0x30 /* Offset to .reg. */,
1241 0);
1242}
1243
1244static void
1245ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001246 struct frame_info *this_frame,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001247 struct trad_frame_cache *this_cache,
1248 CORE_ADDR func)
1249{
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001250 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001251 0x80 /* Offset to ucontext_t. */
1252 + 0xe0 /* Offset to .reg. */,
1253 128);
1254}
1255
1256static void
1257ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001258 struct frame_info *this_frame,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001259 struct trad_frame_cache *this_cache,
1260 CORE_ADDR func)
1261{
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001262 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001263 0x40 /* Offset to ucontext_t. */
1264 + 0x1c /* Offset to .reg. */,
1265 0);
1266}
1267
1268static void
1269ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001270 struct frame_info *this_frame,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001271 struct trad_frame_cache *this_cache,
1272 CORE_ADDR func)
1273{
Daniel Jacobowitz53666532008-04-30 21:28:57 +00001274 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001275 0x80 /* Offset to struct sigcontext. */
1276 + 0x38 /* Offset to .reg. */,
1277 128);
1278}
1279
1280static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
1281 SIGTRAMP_FRAME,
1282 4,
1283 {
Tom Tromey7bc02702018-08-07 13:04:05 -06001284 { 0x380000ac, ULONGEST_MAX }, /* li r0, 172 */
1285 { 0x44000002, ULONGEST_MAX }, /* sc */
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001286 { TRAMP_SENTINEL_INSN },
1287 },
1288 ppc32_linux_sigaction_cache_init
1289};
1290static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
1291 SIGTRAMP_FRAME,
1292 4,
1293 {
Tom Tromey7bc02702018-08-07 13:04:05 -06001294 { 0x38210080, ULONGEST_MAX }, /* addi r1,r1,128 */
1295 { 0x380000ac, ULONGEST_MAX }, /* li r0, 172 */
1296 { 0x44000002, ULONGEST_MAX }, /* sc */
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001297 { TRAMP_SENTINEL_INSN },
1298 },
1299 ppc64_linux_sigaction_cache_init
1300};
1301static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
1302 SIGTRAMP_FRAME,
1303 4,
1304 {
Tom Tromey7bc02702018-08-07 13:04:05 -06001305 { 0x38000077, ULONGEST_MAX }, /* li r0,119 */
1306 { 0x44000002, ULONGEST_MAX }, /* sc */
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001307 { TRAMP_SENTINEL_INSN },
1308 },
1309 ppc32_linux_sighandler_cache_init
1310};
1311static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
1312 SIGTRAMP_FRAME,
1313 4,
1314 {
Tom Tromey7bc02702018-08-07 13:04:05 -06001315 { 0x38210080, ULONGEST_MAX }, /* addi r1,r1,128 */
1316 { 0x38000077, ULONGEST_MAX }, /* li r0,119 */
1317 { 0x44000002, ULONGEST_MAX }, /* sc */
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00001318 { TRAMP_SENTINEL_INSN },
1319 },
1320 ppc64_linux_sighandler_cache_init
1321};
1322
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001323/* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
1324int
1325ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
1326{
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)))
1330 return 0;
1331
1332 /* If we do, then it is safe to check the size. */
1333 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
Simon Marchidda83cd2020-11-02 10:26:14 -05001334 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001335}
1336
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00001337/* Return the current system call's number present in the
1338 r0 register. When the function fails, it returns -1. */
1339static LONGEST
1340ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
Pedro Alves00431a72018-06-21 17:09:31 +01001341 thread_info *thread)
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00001342{
Pedro Alves00431a72018-06-21 17:09:31 +01001343 struct regcache *regcache = get_thread_regcache (thread);
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00001344 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1345 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00001346
1347 /* Make sure we're in a 32- or 64-bit machine */
1348 gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
1349
Tom Tromey779bc382017-11-01 18:52:30 -06001350 /* The content of a register */
1351 gdb::byte_vector buf (tdep->wordsize);
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00001352
1353 /* Getting the system call number from the register.
1354 When dealing with PowerPC architecture, this information
1355 is stored at 0th register. */
Simon Marchidca08e12018-05-30 14:54:38 -04001356 regcache->cooked_read (tdep->ppc_gp0_regnum, buf.data ());
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00001357
Tom Tromey779bc382017-11-01 18:52:30 -06001358 return extract_signed_integer (buf.data (), tdep->wordsize, byte_order);
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00001359}
1360
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001361/* PPC process record-replay */
1362
1363static struct linux_record_tdep ppc_linux_record_tdep;
1364static struct linux_record_tdep ppc64_linux_record_tdep;
1365
Wei-cheng Wangddeca1d2015-01-19 23:34:07 +08001366/* 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.
Tom de Vries85102362019-10-18 02:48:08 +02001370 Otherwise, return the syscall number for process record of given
Wei-cheng Wangddeca1d2015-01-19 23:34:07 +08001371 SYSCALL. */
1372
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001373static enum gdb_syscall
1374ppc_canonicalize_syscall (int syscall)
1375{
Simon Marchiaead7602015-08-06 17:21:41 -04001376 int result = -1;
1377
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001378 if (syscall <= 165)
Simon Marchiaead7602015-08-06 17:21:41 -04001379 result = syscall;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001380 else if (syscall >= 167 && syscall <= 190) /* Skip query_module 166 */
Simon Marchiaead7602015-08-06 17:21:41 -04001381 result = syscall + 1;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001382 else if (syscall >= 192 && syscall <= 197) /* mmap2 */
Simon Marchiaead7602015-08-06 17:21:41 -04001383 result = syscall;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001384 else if (syscall == 208) /* tkill */
Simon Marchiaead7602015-08-06 17:21:41 -04001385 result = gdb_sys_tkill;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001386 else if (syscall >= 207 && syscall <= 220) /* gettid */
Simon Marchiaead7602015-08-06 17:21:41 -04001387 result = syscall + 224 - 207;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001388 else if (syscall >= 234 && syscall <= 239) /* exit_group */
Simon Marchiaead7602015-08-06 17:21:41 -04001389 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;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001394 else if (syscall == 336)
Simon Marchiaead7602015-08-06 17:21:41 -04001395 result = gdb_sys_recv;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001396 else if (syscall == 337)
Simon Marchiaead7602015-08-06 17:21:41 -04001397 result = gdb_sys_recvfrom;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001398 else if (syscall == 342)
Simon Marchiaead7602015-08-06 17:21:41 -04001399 result = gdb_sys_recvmsg;
1400
1401 return (enum gdb_syscall) result;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001402}
1403
Wei-cheng Wangddeca1d2015-01-19 23:34:07 +08001404/* Record registers which might be clobbered during system call.
1405 Return 0 if successful. */
1406
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001407static int
1408ppc_linux_syscall_record (struct regcache *regcache)
1409{
Yao Qiac7936d2017-10-25 16:37:03 +01001410 struct gdbarch *gdbarch = regcache->arch ();
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001411 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1412 ULONGEST scnum;
1413 enum gdb_syscall syscall_gdb;
1414 int ret;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001415
1416 regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum, &scnum);
1417 syscall_gdb = ppc_canonicalize_syscall (scnum);
1418
1419 if (syscall_gdb < 0)
1420 {
1421 printf_unfiltered (_("Process record and replay target doesn't "
1422 "support syscall number %d\n"), (int) scnum);
1423 return 0;
1424 }
1425
1426 if (syscall_gdb == gdb_sys_sigreturn
1427 || syscall_gdb == gdb_sys_rt_sigreturn)
1428 {
1429 int i, j;
1430 int regsets[] = { tdep->ppc_gp0_regnum,
1431 tdep->ppc_fp0_regnum,
1432 tdep->ppc_vr0_regnum,
1433 tdep->ppc_vsr0_upper_regnum };
1434
1435 for (j = 0; j < 4; j++)
1436 {
1437 if (regsets[j] == -1)
1438 continue;
1439 for (i = 0; i < 32; i++)
1440 {
1441 if (record_full_arch_list_add_reg (regcache, regsets[j] + i))
1442 return -1;
1443 }
1444 }
1445
1446 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1447 return -1;
1448 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1449 return -1;
1450 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1451 return -1;
1452 if (record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum))
1453 return -1;
1454
1455 return 0;
1456 }
1457
1458 if (tdep->wordsize == 8)
1459 ret = record_linux_system_call (syscall_gdb, regcache,
1460 &ppc64_linux_record_tdep);
1461 else
1462 ret = record_linux_system_call (syscall_gdb, regcache,
1463 &ppc_linux_record_tdep);
1464
1465 if (ret != 0)
1466 return ret;
1467
1468 /* Record registers clobbered during syscall. */
Tom Tromeyb9264172018-04-21 16:16:27 -06001469 for (int i = 3; i <= 12; i++)
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001470 {
1471 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
1472 return -1;
1473 }
1474 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + 0))
1475 return -1;
1476 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1477 return -1;
1478 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1479 return -1;
1480 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1481 return -1;
1482
1483 return 0;
1484}
1485
Wei-cheng Wangddeca1d2015-01-19 23:34:07 +08001486/* Record registers which might be clobbered during signal handling.
1487 Return 0 if successful. */
1488
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001489static int
1490ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
1491 enum gdb_signal signal)
1492{
1493 /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c
1494 handle_rt_signal32 in arch/powerpc/kernel/signal_32.c
1495 arch/powerpc/include/asm/ptrace.h
1496 for details. */
1497 const int SIGNAL_FRAMESIZE = 128;
1498 const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
1499 ULONGEST sp;
1500 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1501 int i;
1502
1503 for (i = 3; i <= 12; i++)
1504 {
1505 if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
1506 return -1;
1507 }
1508
1509 if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
1510 return -1;
1511 if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
1512 return -1;
1513 if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
1514 return -1;
1515 if (record_full_arch_list_add_reg (regcache, gdbarch_pc_regnum (gdbarch)))
1516 return -1;
1517 if (record_full_arch_list_add_reg (regcache, gdbarch_sp_regnum (gdbarch)))
1518 return -1;
1519
1520 /* Record the change in the stack.
1521 frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
1522 regcache_raw_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &sp);
1523 sp -= SIGNAL_FRAMESIZE;
1524 sp -= sizeof_rt_sigframe;
1525
1526 if (record_full_arch_list_add_mem (sp, SIGNAL_FRAMESIZE + sizeof_rt_sigframe))
1527 return -1;
1528
1529 if (record_full_arch_list_add_end ())
1530 return -1;
1531
1532 return 0;
1533}
1534
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001535static void
1536ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1537{
Yao Qiac7936d2017-10-25 16:37:03 +01001538 struct gdbarch *gdbarch = regcache->arch ();
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001539
1540 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
1541
1542 /* Set special TRAP register to -1 to prevent the kernel from
1543 messing with the PC we just installed, if we happen to be
1544 within an interrupted system call that the kernel wants to
1545 restart.
1546
1547 Note that after we return from the dummy call, the TRAP and
1548 ORIG_R3 registers will be automatically restored, and the
1549 kernel continues to restart the system call at this point. */
1550 if (ppc_linux_trap_reg_p (gdbarch))
1551 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
1552}
1553
1554static const struct target_desc *
1555ppc_linux_core_read_description (struct gdbarch *gdbarch,
1556 struct target_ops *target,
1557 bfd *abfd)
1558{
Pedro Franco de Carvalhobd646142018-05-22 11:09:05 -03001559 struct ppc_linux_features features = ppc_linux_no_features;
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001560 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
Luis Machado604c2f82008-08-15 15:18:34 +00001561 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001562 asection *section = bfd_get_section_by_name (abfd, ".reg");
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -03001563 asection *ppr = bfd_get_section_by_name (abfd, ".reg-ppc-ppr");
1564 asection *dscr = bfd_get_section_by_name (abfd, ".reg-ppc-dscr");
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -03001565 asection *tar = bfd_get_section_by_name (abfd, ".reg-ppc-tar");
Edjunior Barbosa Machado232bfb82018-10-26 09:37:54 -03001566 asection *pmu = bfd_get_section_by_name (abfd, ".reg-ppc-pmu");
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -03001567 asection *htmspr = bfd_get_section_by_name (abfd, ".reg-ppc-tm-spr");
Pedro Franco de Carvalhobd646142018-05-22 11:09:05 -03001568
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001569 if (! section)
1570 return NULL;
1571
Alan Modrafd361982019-09-16 20:25:17 +09301572 switch (bfd_section_size (section))
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001573 {
1574 case 48 * 4:
Pedro Franco de Carvalhobd646142018-05-22 11:09:05 -03001575 features.wordsize = 4;
1576 break;
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001577 case 48 * 8:
Pedro Franco de Carvalhobd646142018-05-22 11:09:05 -03001578 features.wordsize = 8;
1579 break;
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001580 default:
1581 return NULL;
1582 }
Pedro Franco de Carvalhobd646142018-05-22 11:09:05 -03001583
Pedro Franco de Carvalhobd646142018-05-22 11:09:05 -03001584 if (altivec)
1585 features.altivec = true;
1586
1587 if (vsx)
1588 features.vsx = true;
1589
Alan Hayward0f830122019-03-25 16:48:03 +00001590 CORE_ADDR hwcap = linux_get_hwcap (target);
Pedro Franco de Carvalho0ec848a2018-05-22 11:09:06 -03001591
1592 features.isa205 = ppc_linux_has_isa205 (hwcap);
1593
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -03001594 if (ppr && dscr)
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -03001595 {
1596 features.ppr_dscr = true;
Edjunior Barbosa Machado232bfb82018-10-26 09:37:54 -03001597
1598 /* We don't require the EBB note section to be present in the
1599 core file to select isa207 because these registers could have
1600 been unavailable when the core file was created. They will
1601 be in the tdep but will show as unavailable. */
1602 if (tar && pmu)
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -03001603 {
1604 features.isa207 = true;
1605 if (htmspr)
1606 features.htm = true;
1607 }
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -03001608 }
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -03001609
Pedro Franco de Carvalhobd646142018-05-22 11:09:05 -03001610 return ppc_linux_match_description (features);
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00001611}
1612
Ulrich Weigand591a12a2014-02-04 18:44:14 +01001613
1614/* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
1615 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1616
1617static void
1618ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
1619{
1620 elf_symbol_type *elf_sym = (elf_symbol_type *)sym;
1621
1622 /* If the symbol is marked as having a local entry point, set a target
1623 flag in the msymbol. We currently only support local entry point
1624 offsets of 8 bytes, which is the only entry point offset ever used
1625 by current compilers. If/when other offsets are ever used, we will
1626 have to use additional target flag bits to store them. */
1627 switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other))
1628 {
1629 default:
1630 break;
1631 case 8:
1632 MSYMBOL_TARGET_FLAG_1 (msym) = 1;
1633 break;
1634 }
1635}
1636
1637/* Implementation of `gdbarch_skip_entrypoint', as defined in
1638 gdbarch.h. This implementation is used for the ELFv2 ABI only. */
1639
1640static CORE_ADDR
1641ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc)
1642{
1643 struct bound_minimal_symbol fun;
1644 int local_entry_offset = 0;
1645
1646 fun = lookup_minimal_symbol_by_pc (pc);
1647 if (fun.minsym == NULL)
1648 return pc;
1649
1650 /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
1651 offset values are encoded. */
1652 if (MSYMBOL_TARGET_FLAG_1 (fun.minsym))
1653 local_entry_offset = 8;
1654
Tom Tromey77e371c2013-08-15 08:46:35 -06001655 if (BMSYMBOL_VALUE_ADDRESS (fun) <= pc
1656 && pc < BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset)
1657 return BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset;
Ulrich Weigand591a12a2014-02-04 18:44:14 +01001658
1659 return pc;
1660}
1661
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00001662/* Implementation of `gdbarch_stap_is_single_operand', as defined in
1663 gdbarch.h. */
1664
1665static int
1666ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
1667{
1668 return (*s == 'i' /* Literal number. */
1669 || (isdigit (*s) && s[1] == '('
1670 && isdigit (s[2])) /* Displacement. */
1671 || (*s == '(' && isdigit (s[1])) /* Register indirection. */
1672 || isdigit (*s)); /* Register value. */
1673}
1674
1675/* Implementation of `gdbarch_stap_parse_special_token', as defined in
1676 gdbarch.h. */
1677
Tom Tromey4c5e7a92021-03-08 07:27:57 -07001678static expr::operation_up
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00001679ppc_stap_parse_special_token (struct gdbarch *gdbarch,
1680 struct stap_parse_info *p)
1681{
1682 if (isdigit (*p->arg))
1683 {
1684 /* This temporary pointer is needed because we have to do a lookahead.
1685 We could be dealing with a register displacement, and in such case
1686 we would not need to do anything. */
1687 const char *s = p->arg;
1688 char *regname;
1689 int len;
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00001690
1691 while (isdigit (*s))
1692 ++s;
1693
1694 if (*s == '(')
1695 {
1696 /* It is a register displacement indeed. Returning 0 means we are
1697 deferring the treatment of this case to the generic parser. */
Tom Tromey4c5e7a92021-03-08 07:27:57 -07001698 return {};
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00001699 }
1700
1701 len = s - p->arg;
Simon Marchi224c3dd2015-09-25 14:08:06 -04001702 regname = (char *) alloca (len + 2);
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00001703 regname[0] = 'r';
1704
1705 strncpy (regname + 1, p->arg, len);
1706 ++len;
1707 regname[len] = '\0';
1708
1709 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
1710 error (_("Invalid register name `%s' on expression `%s'."),
1711 regname, p->saved_arg);
1712
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00001713 p->arg = s;
Tom Tromey4c5e7a92021-03-08 07:27:57 -07001714
1715 return expr::make_operation<expr::register_operation> (regname);
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00001716 }
1717
Tom Tromey4c5e7a92021-03-08 07:27:57 -07001718 /* All the other tokens should be handled correctly by the generic
1719 parser. */
1720 return {};
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00001721}
Ulrich Weigandcc5f0d62009-07-31 15:31:08 +00001722
Wei-cheng Wangddeca1d2015-01-19 23:34:07 +08001723/* Initialize linux_record_tdep if not initialized yet.
1724 WORDSIZE is 4 or 8 for 32- or 64-bit PowerPC Linux respectively.
1725 Sizes of data structures are initialized accordingly. */
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001726
1727static void
1728ppc_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
1729 int wordsize)
1730{
1731 /* Simply return if it had been initialized. */
1732 if (record_tdep->size_pointer != 0)
1733 return;
1734
1735 /* These values are the size of the type that will be used in a system
1736 call. They are obtained from Linux Kernel source. */
1737
1738 if (wordsize == 8)
1739 {
1740 record_tdep->size_pointer = 8;
1741 record_tdep->size__old_kernel_stat = 32;
1742 record_tdep->size_tms = 32;
1743 record_tdep->size_loff_t = 8;
1744 record_tdep->size_flock = 32;
1745 record_tdep->size_oldold_utsname = 45;
1746 record_tdep->size_ustat = 32;
Marcin Kościelnicki7571f7f2015-10-30 15:51:57 +00001747 record_tdep->size_old_sigaction = 32;
1748 record_tdep->size_old_sigset_t = 8;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001749 record_tdep->size_rlimit = 16;
1750 record_tdep->size_rusage = 144;
1751 record_tdep->size_timeval = 16;
1752 record_tdep->size_timezone = 8;
1753 record_tdep->size_old_gid_t = 4;
1754 record_tdep->size_old_uid_t = 4;
1755 record_tdep->size_fd_set = 128;
Marcin Kościelnicki72aded82015-10-30 15:51:58 +00001756 record_tdep->size_old_dirent = 280;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001757 record_tdep->size_statfs = 120;
1758 record_tdep->size_statfs64 = 120;
1759 record_tdep->size_sockaddr = 16;
1760 record_tdep->size_int = 4;
1761 record_tdep->size_long = 8;
1762 record_tdep->size_ulong = 8;
1763 record_tdep->size_msghdr = 56;
1764 record_tdep->size_itimerval = 32;
1765 record_tdep->size_stat = 144;
1766 record_tdep->size_old_utsname = 325;
1767 record_tdep->size_sysinfo = 112;
1768 record_tdep->size_msqid_ds = 120;
1769 record_tdep->size_shmid_ds = 112;
1770 record_tdep->size_new_utsname = 390;
1771 record_tdep->size_timex = 208;
1772 record_tdep->size_mem_dqinfo = 24;
1773 record_tdep->size_if_dqblk = 72;
1774 record_tdep->size_fs_quota_stat = 80;
1775 record_tdep->size_timespec = 16;
1776 record_tdep->size_pollfd = 8;
1777 record_tdep->size_NFS_FHSIZE = 32;
1778 record_tdep->size_knfsd_fh = 132;
Marcin Kościelnickic28ebe22015-10-30 15:52:01 +00001779 record_tdep->size_TASK_COMM_LEN = 16;
Marcin Kościelnicki7571f7f2015-10-30 15:51:57 +00001780 record_tdep->size_sigaction = 32;
1781 record_tdep->size_sigset_t = 8;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001782 record_tdep->size_siginfo_t = 128;
1783 record_tdep->size_cap_user_data_t = 8;
1784 record_tdep->size_stack_t = 24;
1785 record_tdep->size_off_t = 8;
1786 record_tdep->size_stat64 = 104;
1787 record_tdep->size_gid_t = 4;
1788 record_tdep->size_uid_t = 4;
1789 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
1790 record_tdep->size_flock64 = 32;
1791 record_tdep->size_io_event = 32;
1792 record_tdep->size_iocb = 64;
1793 record_tdep->size_epoll_event = 16;
1794 record_tdep->size_itimerspec = 32;
1795 record_tdep->size_mq_attr = 64;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001796 record_tdep->size_termios = 44;
1797 record_tdep->size_pid_t = 4;
1798 record_tdep->size_winsize = 8;
1799 record_tdep->size_serial_struct = 72;
1800 record_tdep->size_serial_icounter_struct = 80;
1801 record_tdep->size_size_t = 8;
1802 record_tdep->size_iovec = 16;
Marcin Kościelnickib80d0672015-10-30 15:51:59 +00001803 record_tdep->size_time_t = 8;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001804 }
1805 else if (wordsize == 4)
1806 {
1807 record_tdep->size_pointer = 4;
1808 record_tdep->size__old_kernel_stat = 32;
1809 record_tdep->size_tms = 16;
1810 record_tdep->size_loff_t = 8;
1811 record_tdep->size_flock = 16;
1812 record_tdep->size_oldold_utsname = 45;
1813 record_tdep->size_ustat = 20;
Marcin Kościelnicki7571f7f2015-10-30 15:51:57 +00001814 record_tdep->size_old_sigaction = 16;
1815 record_tdep->size_old_sigset_t = 4;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001816 record_tdep->size_rlimit = 8;
1817 record_tdep->size_rusage = 72;
1818 record_tdep->size_timeval = 8;
1819 record_tdep->size_timezone = 8;
1820 record_tdep->size_old_gid_t = 4;
1821 record_tdep->size_old_uid_t = 4;
1822 record_tdep->size_fd_set = 128;
Marcin Kościelnicki72aded82015-10-30 15:51:58 +00001823 record_tdep->size_old_dirent = 268;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001824 record_tdep->size_statfs = 64;
1825 record_tdep->size_statfs64 = 88;
1826 record_tdep->size_sockaddr = 16;
1827 record_tdep->size_int = 4;
1828 record_tdep->size_long = 4;
1829 record_tdep->size_ulong = 4;
1830 record_tdep->size_msghdr = 28;
1831 record_tdep->size_itimerval = 16;
1832 record_tdep->size_stat = 88;
1833 record_tdep->size_old_utsname = 325;
1834 record_tdep->size_sysinfo = 64;
1835 record_tdep->size_msqid_ds = 68;
1836 record_tdep->size_shmid_ds = 60;
1837 record_tdep->size_new_utsname = 390;
1838 record_tdep->size_timex = 128;
1839 record_tdep->size_mem_dqinfo = 24;
1840 record_tdep->size_if_dqblk = 72;
1841 record_tdep->size_fs_quota_stat = 80;
1842 record_tdep->size_timespec = 8;
1843 record_tdep->size_pollfd = 8;
1844 record_tdep->size_NFS_FHSIZE = 32;
1845 record_tdep->size_knfsd_fh = 132;
Marcin Kościelnickic28ebe22015-10-30 15:52:01 +00001846 record_tdep->size_TASK_COMM_LEN = 16;
Marcin Kościelnicki7571f7f2015-10-30 15:51:57 +00001847 record_tdep->size_sigaction = 20;
1848 record_tdep->size_sigset_t = 8;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001849 record_tdep->size_siginfo_t = 128;
1850 record_tdep->size_cap_user_data_t = 4;
1851 record_tdep->size_stack_t = 12;
1852 record_tdep->size_off_t = 4;
1853 record_tdep->size_stat64 = 104;
1854 record_tdep->size_gid_t = 4;
1855 record_tdep->size_uid_t = 4;
1856 record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
1857 record_tdep->size_flock64 = 32;
1858 record_tdep->size_io_event = 32;
1859 record_tdep->size_iocb = 64;
1860 record_tdep->size_epoll_event = 16;
1861 record_tdep->size_itimerspec = 16;
1862 record_tdep->size_mq_attr = 32;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001863 record_tdep->size_termios = 44;
1864 record_tdep->size_pid_t = 4;
1865 record_tdep->size_winsize = 8;
1866 record_tdep->size_serial_struct = 60;
1867 record_tdep->size_serial_icounter_struct = 80;
1868 record_tdep->size_size_t = 4;
1869 record_tdep->size_iovec = 8;
Marcin Kościelnickib80d0672015-10-30 15:51:59 +00001870 record_tdep->size_time_t = 4;
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08001871 }
1872 else
1873 internal_error (__FILE__, __LINE__, _("unexpected wordsize"));
1874
1875 /* These values are the second argument of system call "sys_fcntl"
1876 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1877 record_tdep->fcntl_F_GETLK = 5;
1878 record_tdep->fcntl_F_GETLK64 = 12;
1879 record_tdep->fcntl_F_SETLK64 = 13;
1880 record_tdep->fcntl_F_SETLKW64 = 14;
1881
1882 record_tdep->arg1 = PPC_R0_REGNUM + 3;
1883 record_tdep->arg2 = PPC_R0_REGNUM + 4;
1884 record_tdep->arg3 = PPC_R0_REGNUM + 5;
1885 record_tdep->arg4 = PPC_R0_REGNUM + 6;
1886 record_tdep->arg5 = PPC_R0_REGNUM + 7;
1887 record_tdep->arg6 = PPC_R0_REGNUM + 8;
1888
1889 /* These values are the second argument of system call "sys_ioctl".
1890 They are obtained from Linux Kernel source.
1891 See arch/powerpc/include/uapi/asm/ioctls.h. */
1892 record_tdep->ioctl_TCGETS = 0x403c7413;
1893 record_tdep->ioctl_TCSETS = 0x803c7414;
1894 record_tdep->ioctl_TCSETSW = 0x803c7415;
1895 record_tdep->ioctl_TCSETSF = 0x803c7416;
1896 record_tdep->ioctl_TCGETA = 0x40147417;
1897 record_tdep->ioctl_TCSETA = 0x80147418;
1898 record_tdep->ioctl_TCSETAW = 0x80147419;
1899 record_tdep->ioctl_TCSETAF = 0x8014741c;
1900 record_tdep->ioctl_TCSBRK = 0x2000741d;
1901 record_tdep->ioctl_TCXONC = 0x2000741e;
1902 record_tdep->ioctl_TCFLSH = 0x2000741f;
1903 record_tdep->ioctl_TIOCEXCL = 0x540c;
1904 record_tdep->ioctl_TIOCNXCL = 0x540d;
1905 record_tdep->ioctl_TIOCSCTTY = 0x540e;
1906 record_tdep->ioctl_TIOCGPGRP = 0x40047477;
1907 record_tdep->ioctl_TIOCSPGRP = 0x80047476;
1908 record_tdep->ioctl_TIOCOUTQ = 0x40047473;
1909 record_tdep->ioctl_TIOCSTI = 0x5412;
1910 record_tdep->ioctl_TIOCGWINSZ = 0x40087468;
1911 record_tdep->ioctl_TIOCSWINSZ = 0x80087467;
1912 record_tdep->ioctl_TIOCMGET = 0x5415;
1913 record_tdep->ioctl_TIOCMBIS = 0x5416;
1914 record_tdep->ioctl_TIOCMBIC = 0x5417;
1915 record_tdep->ioctl_TIOCMSET = 0x5418;
1916 record_tdep->ioctl_TIOCGSOFTCAR = 0x5419;
1917 record_tdep->ioctl_TIOCSSOFTCAR = 0x541a;
1918 record_tdep->ioctl_FIONREAD = 0x4004667f;
1919 record_tdep->ioctl_TIOCINQ = 0x4004667f;
1920 record_tdep->ioctl_TIOCLINUX = 0x541c;
1921 record_tdep->ioctl_TIOCCONS = 0x541d;
1922 record_tdep->ioctl_TIOCGSERIAL = 0x541e;
1923 record_tdep->ioctl_TIOCSSERIAL = 0x541f;
1924 record_tdep->ioctl_TIOCPKT = 0x5420;
1925 record_tdep->ioctl_FIONBIO = 0x8004667e;
1926 record_tdep->ioctl_TIOCNOTTY = 0x5422;
1927 record_tdep->ioctl_TIOCSETD = 0x5423;
1928 record_tdep->ioctl_TIOCGETD = 0x5424;
1929 record_tdep->ioctl_TCSBRKP = 0x5425;
1930 record_tdep->ioctl_TIOCSBRK = 0x5427;
1931 record_tdep->ioctl_TIOCCBRK = 0x5428;
1932 record_tdep->ioctl_TIOCGSID = 0x5429;
1933 record_tdep->ioctl_TIOCGPTN = 0x40045430;
1934 record_tdep->ioctl_TIOCSPTLCK = 0x80045431;
1935 record_tdep->ioctl_FIONCLEX = 0x20006602;
1936 record_tdep->ioctl_FIOCLEX = 0x20006601;
1937 record_tdep->ioctl_FIOASYNC = 0x8004667d;
1938 record_tdep->ioctl_TIOCSERCONFIG = 0x5453;
1939 record_tdep->ioctl_TIOCSERGWILD = 0x5454;
1940 record_tdep->ioctl_TIOCSERSWILD = 0x5455;
1941 record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456;
1942 record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457;
1943 record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458;
1944 record_tdep->ioctl_TIOCSERGETLSR = 0x5459;
1945 record_tdep->ioctl_TIOCSERGETMULTI = 0x545a;
1946 record_tdep->ioctl_TIOCSERSETMULTI = 0x545b;
1947 record_tdep->ioctl_TIOCMIWAIT = 0x545c;
1948 record_tdep->ioctl_TIOCGICOUNT = 0x545d;
1949 record_tdep->ioctl_FIOQSIZE = 0x40086680;
1950}
Ulrich Weigandcc5f0d62009-07-31 15:31:08 +00001951
Ulrich Weigand00d52152016-09-06 17:33:15 +02001952/* Return a floating-point format for a floating-point variable of
1953 length LEN in bits. If non-NULL, NAME is the name of its type.
1954 If no suitable type is found, return NULL. */
1955
Simon Marchicb8c24b2019-11-26 12:12:01 -05001956static const struct floatformat **
Ulrich Weigand00d52152016-09-06 17:33:15 +02001957ppc_floatformat_for_type (struct gdbarch *gdbarch,
Simon Marchidda83cd2020-11-02 10:26:14 -05001958 const char *name, int len)
Ulrich Weigand00d52152016-09-06 17:33:15 +02001959{
1960 if (len == 128 && name)
Ulrich Weiganded0f4272017-11-21 18:50:59 +01001961 {
1962 if (strcmp (name, "__float128") == 0
1963 || strcmp (name, "_Float128") == 0
1964 || strcmp (name, "_Float64x") == 0
1965 || strcmp (name, "complex _Float128") == 0
1966 || strcmp (name, "complex _Float64x") == 0)
1967 return floatformats_ia64_quad;
1968
1969 if (strcmp (name, "__ibm128") == 0)
1970 return floatformats_ibm_long_double;
1971 }
Ulrich Weigand00d52152016-09-06 17:33:15 +02001972
1973 return default_floatformat_for_type (gdbarch, name, len);
1974}
1975
Will Schmidtbc0df0f2021-08-18 11:43:45 -05001976/* Specify the powerpc64le target triplet.
1977 This can be variations of
1978 ppc64le-{distro}-linux-gcc
1979 and
1980 powerpc64le-{distro}-linux-gcc. */
1981
1982static const char *
1983ppc64le_gnu_triplet_regexp (struct gdbarch *gdbarch)
1984{
1985 return "p(ower)?pc64le";
1986}
1987
1988/* Specify the powerpc64 target triplet.
1989 This can be variations of
1990 ppc64-{distro}-linux-gcc
1991 and
1992 powerpc64-{distro}-linux-gcc. */
1993
1994static const char *
1995ppc64_gnu_triplet_regexp (struct gdbarch *gdbarch)
1996{
1997 return "p(ower)?pc64";
1998}
1999
Will Schmidt533f0402021-08-18 11:45:49 -05002000/* Implement the linux_gcc_target_options method. */
2001
2002static std::string
2003ppc64_linux_gcc_target_options (struct gdbarch *gdbarch)
2004{
2005 return "";
2006}
2007
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00002008static void
Jason Thorpe7b112f92002-05-30 01:21:53 +00002009ppc_linux_init_abi (struct gdbarch_info info,
Simon Marchidda83cd2020-11-02 10:26:14 -05002010 struct gdbarch *gdbarch)
Jason Thorpe7b112f92002-05-30 01:21:53 +00002011{
2012 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
Maciej W. Rozycki0dba2a62017-08-07 15:53:54 +01002013 struct tdesc_arch_data *tdesc_data = info.tdesc_data;
Sergio Durigan Junior05c04652013-12-19 18:53:40 -02002014 static const char *const stap_integer_prefixes[] = { "i", NULL };
2015 static const char *const stap_register_indirection_prefixes[] = { "(",
2016 NULL };
2017 static const char *const stap_register_indirection_suffixes[] = { ")",
2018 NULL };
Jason Thorpe7b112f92002-05-30 01:21:53 +00002019
Simon Marchi480af542020-12-04 16:43:56 -05002020 linux_init_abi (info, gdbarch, 0);
Pedro Alvesa5ee0f02010-08-04 15:27:57 +00002021
Joseph Myersb14d30e2007-11-08 00:08:48 +00002022 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
Ulrich Weiganded0f4272017-11-21 18:50:59 +01002023 128-bit, they can be either IBM long double or IEEE quad long double.
2024 The 64-bit long double case will be detected automatically using
2025 the size specified in debug info. We use a .gnu.attribute flag
2026 to distinguish between the IBM long double and IEEE quad cases. */
Joseph Myersb14d30e2007-11-08 00:08:48 +00002027 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
Ulrich Weiganded0f4272017-11-21 18:50:59 +01002028 if (tdep->long_double_abi == POWERPC_LONG_DOUBLE_IEEE128)
2029 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
2030 else
2031 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
Andrew Cagney0598a432005-01-25 22:06:59 +00002032
Ulrich Weigand00d52152016-09-06 17:33:15 +02002033 /* Support for floating-point data type variants. */
2034 set_gdbarch_floatformat_for_type (gdbarch, ppc_floatformat_for_type);
2035
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00002036 /* Handle inferior calls during interrupted system calls. */
2037 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
2038
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00002039 /* Get the syscall number from the arch's register. */
2040 set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
2041
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00002042 /* SystemTap functions. */
Sergio Durigan Junior05c04652013-12-19 18:53:40 -02002043 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
2044 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
2045 stap_register_indirection_prefixes);
2046 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
2047 stap_register_indirection_suffixes);
Sergio Durigan Junior55aa24f2012-04-27 20:47:57 +00002048 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
2049 set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
2050 set_gdbarch_stap_parse_special_token (gdbarch,
2051 ppc_stap_parse_special_token);
2052
Jason Thorpe7b112f92002-05-30 01:21:53 +00002053 if (tdep->wordsize == 4)
2054 {
Andrew Cagneyb9ff3012003-09-16 23:33:17 +00002055 /* Until November 2001, gcc did not comply with the 32 bit SysV
2056 R4 ABI requirement that structures less than or equal to 8
2057 bytes should be returned in registers. Instead GCC was using
Michael Snyderb021a222011-02-26 02:07:10 +00002058 the AIX/PowerOpen ABI - everything returned in memory
Andrew Cagneyb9ff3012003-09-16 23:33:17 +00002059 (well ignoring vectors that is). When this was corrected, it
2060 wasn't fixed for GNU/Linux native platform. Use the
2061 PowerOpen struct convention. */
Andrew Cagney05580c62003-11-07 20:44:51 +00002062 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
Andrew Cagneyb9ff3012003-09-16 23:33:17 +00002063
Jason Thorpe7b112f92002-05-30 01:21:53 +00002064 set_gdbarch_memory_remove_breakpoint (gdbarch,
Simon Marchidda83cd2020-11-02 10:26:14 -05002065 ppc_linux_memory_remove_breakpoint);
Kevin Buettner61a65092004-03-20 04:51:21 +00002066
Jim Blandyf470a702003-06-13 00:06:11 +00002067 /* Shared library handling. */
Michael Eager5d853002012-01-30 17:09:40 +00002068 set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
Jason Thorpe7b112f92002-05-30 01:21:53 +00002069 set_solib_svr4_fetch_link_map_offsets
H.J. Luc0154a42021-08-16 16:17:25 -07002070 (gdbarch, linux_ilp32_fetch_link_map_offsets);
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00002071
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00002072 /* Setting the correct XML syscall filename. */
Sergio Durigan Junior458c8db2014-11-20 12:28:18 -05002073 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC);
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00002074
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00002075 /* Trampolines. */
Michael Snyder0df8b412011-01-10 20:38:51 +00002076 tramp_frame_prepend_unwinder (gdbarch,
2077 &ppc32_linux_sigaction_tramp_frame);
2078 tramp_frame_prepend_unwinder (gdbarch,
2079 &ppc32_linux_sighandler_tramp_frame);
Ulrich Weiganda78c2d62009-06-17 18:48:26 +00002080
2081 /* BFD target for core files. */
2082 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
2083 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
2084 else
2085 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
Ulrich Weigand2f2241f2010-07-07 12:28:32 +00002086
Michael Eager5d853002012-01-30 17:09:40 +00002087 if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
2088 {
2089 powerpc_so_ops = svr4_so_ops;
2090 /* Override dynamic resolve function. */
2091 powerpc_so_ops.in_dynsym_resolve_code =
2092 powerpc_linux_in_dynsym_resolve_code;
2093 }
2094 set_solib_ops (gdbarch, &powerpc_so_ops);
2095
2096 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
Jason Thorpe7b112f92002-05-30 01:21:53 +00002097 }
Jim Blandyf470a702003-06-13 00:06:11 +00002098
2099 if (tdep->wordsize == 8)
2100 {
Ulrich Weigandd4094b62014-02-04 18:40:16 +01002101 if (tdep->elf_abi == POWERPC_ELF_V1)
2102 {
2103 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
2104 function descriptors). */
2105 set_gdbarch_convert_from_func_ptr_addr
2106 (gdbarch, ppc64_convert_from_func_ptr_addr);
Ulrich Weigand00d5f932008-05-14 18:28:59 +00002107
Ulrich Weigandd4094b62014-02-04 18:40:16 +01002108 set_gdbarch_elf_make_msymbol_special
2109 (gdbarch, ppc64_elf_make_msymbol_special);
2110 }
Ulrich Weigand591a12a2014-02-04 18:44:14 +01002111 else
2112 {
2113 set_gdbarch_elf_make_msymbol_special
2114 (gdbarch, ppc_elfv2_elf_make_msymbol_special);
2115
2116 set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint);
2117 }
Alan Modra24c274a2013-02-22 23:24:24 +00002118
Daniel Jacobowitzfb318ff2005-07-13 16:29:04 +00002119 /* Shared library handling. */
Daniel Jacobowitz2bbe3cc2007-07-03 15:58:42 +00002120 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
Daniel Jacobowitzfb318ff2005-07-13 16:29:04 +00002121 set_solib_svr4_fetch_link_map_offsets
H.J. Luc0154a42021-08-16 16:17:25 -07002122 (gdbarch, linux_lp64_fetch_link_map_offsets);
Daniel Jacobowitzfb318ff2005-07-13 16:29:04 +00002123
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00002124 /* Setting the correct XML syscall filename. */
Sergio Durigan Junior458c8db2014-11-20 12:28:18 -05002125 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC64);
Sergio Durigan Juniora96d9b22009-09-15 03:30:08 +00002126
Andrew Cagneya8f60bf2005-01-25 22:43:45 +00002127 /* Trampolines. */
Michael Snyder0df8b412011-01-10 20:38:51 +00002128 tramp_frame_prepend_unwinder (gdbarch,
2129 &ppc64_linux_sigaction_tramp_frame);
2130 tramp_frame_prepend_unwinder (gdbarch,
2131 &ppc64_linux_sighandler_tramp_frame);
Ulrich Weiganda78c2d62009-06-17 18:48:26 +00002132
2133 /* BFD target for core files. */
2134 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
2135 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
2136 else
2137 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
Will Schmidtbc0df0f2021-08-18 11:43:45 -05002138 /* Set compiler triplet. */
2139 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
2140 set_gdbarch_gnu_triplet_regexp (gdbarch, ppc64le_gnu_triplet_regexp);
2141 else
2142 set_gdbarch_gnu_triplet_regexp (gdbarch, ppc64_gnu_triplet_regexp);
Will Schmidt533f0402021-08-18 11:45:49 -05002143 /* Set GCC target options. */
2144 set_gdbarch_gcc_target_options (gdbarch, ppc64_linux_gcc_target_options);
Jim Blandyf470a702003-06-13 00:06:11 +00002145 }
Sergio Durigan Juniorb3ac9c72013-02-04 18:40:41 +00002146
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00002147 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
Andreas Arnez5aa82d02014-09-04 15:26:43 +00002148 set_gdbarch_iterate_over_regset_sections (gdbarch,
2149 ppc_linux_iterate_over_regset_sections);
Kevin Buettnerb2756932005-03-31 19:58:26 +00002150
2151 /* Enable TLS support. */
2152 set_gdbarch_fetch_tls_load_module_address (gdbarch,
Simon Marchidda83cd2020-11-02 10:26:14 -05002153 svr4_fetch_objfile_link_map);
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00002154
2155 if (tdesc_data)
2156 {
2157 const struct tdesc_feature *feature;
2158
2159 /* If we have target-described registers, then we can safely
Simon Marchidda83cd2020-11-02 10:26:14 -05002160 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00002161 (whether they are described or not). */
2162 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
2163 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
2164
2165 /* If they are present, then assign them to the reserved number. */
2166 feature = tdesc_find_feature (info.target_desc,
Simon Marchidda83cd2020-11-02 10:26:14 -05002167 "org.gnu.gdb.power.linux");
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00002168 if (feature != NULL)
2169 {
2170 tdesc_numbered_register (feature, tdesc_data,
2171 PPC_ORIG_R3_REGNUM, "orig_r3");
2172 tdesc_numbered_register (feature, tdesc_data,
2173 PPC_TRAP_REGNUM, "trap");
2174 }
2175 }
Ulrich Weigand85e747d2009-07-31 15:28:27 +00002176
Wei-cheng Wangb4cdae62015-01-17 14:30:33 +08002177 /* Support reverse debugging. */
2178 set_gdbarch_process_record (gdbarch, ppc_process_record);
2179 set_gdbarch_process_record_signal (gdbarch, ppc_linux_record_signal);
2180 tdep->ppc_syscall_record = ppc_linux_syscall_record;
2181
2182 ppc_init_linux_record_tdep (&ppc_linux_record_tdep, 4);
2183 ppc_init_linux_record_tdep (&ppc64_linux_record_tdep, 8);
Jason Thorpe7b112f92002-05-30 01:21:53 +00002184}
2185
Simon Marchi6c265982020-01-13 14:01:38 -05002186void _initialize_ppc_linux_tdep ();
Jason Thorpe7b112f92002-05-30 01:21:53 +00002187void
Simon Marchi6c265982020-01-13 14:01:38 -05002188_initialize_ppc_linux_tdep ()
Jason Thorpe7b112f92002-05-30 01:21:53 +00002189{
Tom de Vries85102362019-10-18 02:48:08 +02002190 /* Register for all sub-families of the POWER/PowerPC: 32-bit and
Andrew Cagney0a0a4ac2003-10-29 19:24:52 +00002191 64-bit PowerPC, and the older rs6k. */
2192 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
Simon Marchidda83cd2020-11-02 10:26:14 -05002193 ppc_linux_init_abi);
Andrew Cagney0a0a4ac2003-10-29 19:24:52 +00002194 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
Simon Marchidda83cd2020-11-02 10:26:14 -05002195 ppc_linux_init_abi);
Andrew Cagney0a0a4ac2003-10-29 19:24:52 +00002196 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
Simon Marchidda83cd2020-11-02 10:26:14 -05002197 ppc_linux_init_abi);
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00002198
2199 /* Initialize the Linux target descriptions. */
2200 initialize_tdesc_powerpc_32l ();
2201 initialize_tdesc_powerpc_altivec32l ();
Luis Machado604c2f82008-08-15 15:18:34 +00002202 initialize_tdesc_powerpc_vsx32l ();
Thiago Jung Bauermann69abc512008-11-18 21:39:47 +00002203 initialize_tdesc_powerpc_isa205_32l ();
2204 initialize_tdesc_powerpc_isa205_altivec32l ();
2205 initialize_tdesc_powerpc_isa205_vsx32l ();
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -03002206 initialize_tdesc_powerpc_isa205_ppr_dscr_vsx32l ();
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -03002207 initialize_tdesc_powerpc_isa207_vsx32l ();
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -03002208 initialize_tdesc_powerpc_isa207_htm_vsx32l ();
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00002209 initialize_tdesc_powerpc_64l ();
2210 initialize_tdesc_powerpc_altivec64l ();
Luis Machado604c2f82008-08-15 15:18:34 +00002211 initialize_tdesc_powerpc_vsx64l ();
Thiago Jung Bauermann69abc512008-11-18 21:39:47 +00002212 initialize_tdesc_powerpc_isa205_64l ();
2213 initialize_tdesc_powerpc_isa205_altivec64l ();
2214 initialize_tdesc_powerpc_isa205_vsx64l ();
Edjunior Barbosa Machado7ca18ed2018-10-26 09:37:54 -03002215 initialize_tdesc_powerpc_isa205_ppr_dscr_vsx64l ();
Edjunior Barbosa Machadof2cf6172018-10-26 09:37:54 -03002216 initialize_tdesc_powerpc_isa207_vsx64l ();
Edjunior Barbosa Machado8d619c02018-10-26 09:37:55 -03002217 initialize_tdesc_powerpc_isa207_htm_vsx64l ();
Ulrich Weigand7284e1b2008-05-03 17:16:44 +00002218 initialize_tdesc_powerpc_e500l ();
Jason Thorpe7b112f92002-05-30 01:21:53 +00002219}