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