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