* defs.h (extract_signed_integer, extract_unsigned_integer,
[deliverable/binutils-gdb.git] / gdb / ppc-linux-tdep.c
CommitLineData
c877c8e6 1/* Target-dependent code for GDB, the GNU debugger.
4e052eda 2
6aba47ca 3 Copyright (C) 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
0fb0cc75 4 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
76a9d10f 5 Free Software Foundation, Inc.
c877c8e6
KB
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c877c8e6
KB
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c877c8e6
KB
21
22#include "defs.h"
23#include "frame.h"
24#include "inferior.h"
25#include "symtab.h"
26#include "target.h"
27#include "gdbcore.h"
28#include "gdbcmd.h"
29#include "symfile.h"
30#include "objfiles.h"
4e052eda 31#include "regcache.h"
fd0407d6 32#include "value.h"
4be87837 33#include "osabi.h"
f9be684a 34#include "regset.h"
6ded7999 35#include "solib-svr4.h"
9aa1e687 36#include "ppc-tdep.h"
7284e1be 37#include "ppc-linux-tdep.h"
61a65099
KB
38#include "trad-frame.h"
39#include "frame-unwind.h"
a8f60bfc 40#include "tramp-frame.h"
9aa1e687 41
7284e1be
UW
42#include "features/rs6000/powerpc-32l.c"
43#include "features/rs6000/powerpc-altivec32l.c"
604c2f83 44#include "features/rs6000/powerpc-vsx32l.c"
69abc51c
TJB
45#include "features/rs6000/powerpc-isa205-32l.c"
46#include "features/rs6000/powerpc-isa205-altivec32l.c"
47#include "features/rs6000/powerpc-isa205-vsx32l.c"
7284e1be
UW
48#include "features/rs6000/powerpc-64l.c"
49#include "features/rs6000/powerpc-altivec64l.c"
604c2f83 50#include "features/rs6000/powerpc-vsx64l.c"
69abc51c
TJB
51#include "features/rs6000/powerpc-isa205-64l.c"
52#include "features/rs6000/powerpc-isa205-altivec64l.c"
53#include "features/rs6000/powerpc-isa205-vsx64l.c"
7284e1be
UW
54#include "features/rs6000/powerpc-e500l.c"
55
c877c8e6 56
122a33de
KB
57/* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
58 in much the same fashion as memory_remove_breakpoint in mem-break.c,
59 but is careful not to write back the previous contents if the code
60 in question has changed in between inserting the breakpoint and
61 removing it.
62
63 Here is the problem that we're trying to solve...
64
65 Once upon a time, before introducing this function to remove
66 breakpoints from the inferior, setting a breakpoint on a shared
67 library function prior to running the program would not work
68 properly. In order to understand the problem, it is first
69 necessary to understand a little bit about dynamic linking on
70 this platform.
71
72 A call to a shared library function is accomplished via a bl
73 (branch-and-link) instruction whose branch target is an entry
74 in the procedure linkage table (PLT). The PLT in the object
75 file is uninitialized. To gdb, prior to running the program, the
76 entries in the PLT are all zeros.
77
78 Once the program starts running, the shared libraries are loaded
79 and the procedure linkage table is initialized, but the entries in
80 the table are not (necessarily) resolved. Once a function is
81 actually called, the code in the PLT is hit and the function is
82 resolved. In order to better illustrate this, an example is in
83 order; the following example is from the gdb testsuite.
84
85 We start the program shmain.
86
87 [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
88 [...]
89
90 We place two breakpoints, one on shr1 and the other on main.
91
92 (gdb) b shr1
93 Breakpoint 1 at 0x100409d4
94 (gdb) b main
95 Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
96
97 Examine the instruction (and the immediatly following instruction)
98 upon which the breakpoint was placed. Note that the PLT entry
99 for shr1 contains zeros.
100
101 (gdb) x/2i 0x100409d4
102 0x100409d4 <shr1>: .long 0x0
103 0x100409d8 <shr1+4>: .long 0x0
104
105 Now run 'til main.
106
107 (gdb) r
108 Starting program: gdb.base/shmain
109 Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
110
111 Breakpoint 2, main ()
112 at gdb.base/shmain.c:44
113 44 g = 1;
114
115 Examine the PLT again. Note that the loading of the shared
116 library has initialized the PLT to code which loads a constant
117 (which I think is an index into the GOT) into r11 and then
118 branchs a short distance to the code which actually does the
119 resolving.
120
121 (gdb) x/2i 0x100409d4
122 0x100409d4 <shr1>: li r11,4
123 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
124 (gdb) c
125 Continuing.
126
127 Breakpoint 1, shr1 (x=1)
128 at gdb.base/shr1.c:19
129 19 l = 1;
130
131 Now we've hit the breakpoint at shr1. (The breakpoint was
132 reset from the PLT entry to the actual shr1 function after the
133 shared library was loaded.) Note that the PLT entry has been
134 resolved to contain a branch that takes us directly to shr1.
135 (The real one, not the PLT entry.)
136
137 (gdb) x/2i 0x100409d4
138 0x100409d4 <shr1>: b 0xffaf76c <shr1>
139 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
140
141 The thing to note here is that the PLT entry for shr1 has been
142 changed twice.
143
144 Now the problem should be obvious. GDB places a breakpoint (a
145 trap instruction) on the zero value of the PLT entry for shr1.
146 Later on, after the shared library had been loaded and the PLT
147 initialized, GDB gets a signal indicating this fact and attempts
148 (as it always does when it stops) to remove all the breakpoints.
149
150 The breakpoint removal was causing the former contents (a zero
151 word) to be written back to the now initialized PLT entry thus
152 destroying a portion of the initialization that had occurred only a
153 short time ago. When execution continued, the zero word would be
154 executed as an instruction an an illegal instruction trap was
155 generated instead. (0 is not a legal instruction.)
156
157 The fix for this problem was fairly straightforward. The function
158 memory_remove_breakpoint from mem-break.c was copied to this file,
159 modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
160 In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
161 function.
162
163 The differences between ppc_linux_memory_remove_breakpoint () and
164 memory_remove_breakpoint () are minor. All that the former does
165 that the latter does not is check to make sure that the breakpoint
166 location actually contains a breakpoint (trap instruction) prior
167 to attempting to write back the old contents. If it does contain
168 a trap instruction, we allow the old contents to be written back.
169 Otherwise, we silently do nothing.
170
171 The big question is whether memory_remove_breakpoint () should be
172 changed to have the same functionality. The downside is that more
173 traffic is generated for remote targets since we'll have an extra
174 fetch of a memory word each time a breakpoint is removed.
175
176 For the time being, we'll leave this self-modifying-code-friendly
177 version in ppc-linux-tdep.c, but it ought to be migrated somewhere
178 else in the event that some other platform has similar needs with
179 regard to removing breakpoints in some potentially self modifying
180 code. */
63807e1d 181static int
ae4b2284
MD
182ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
183 struct bp_target_info *bp_tgt)
482ca3f5 184{
8181d85f 185 CORE_ADDR addr = bp_tgt->placed_address;
f4f9705a 186 const unsigned char *bp;
482ca3f5
KB
187 int val;
188 int bplen;
50fd1280 189 gdb_byte old_contents[BREAKPOINT_MAX];
8defab1a 190 struct cleanup *cleanup;
482ca3f5
KB
191
192 /* Determine appropriate breakpoint contents and size for this address. */
ae4b2284 193 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
482ca3f5 194 if (bp == NULL)
8a3fe4f8 195 error (_("Software breakpoints not implemented for this target."));
482ca3f5 196
8defab1a
DJ
197 /* Make sure we see the memory breakpoints. */
198 cleanup = make_show_memory_breakpoints_cleanup (1);
482ca3f5
KB
199 val = target_read_memory (addr, old_contents, bplen);
200
201 /* If our breakpoint is no longer at the address, this means that the
202 program modified the code on us, so it is wrong to put back the
203 old value */
204 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
8181d85f 205 val = target_write_memory (addr, bp_tgt->shadow_contents, bplen);
482ca3f5 206
8defab1a 207 do_cleanups (cleanup);
482ca3f5
KB
208 return val;
209}
6ded7999 210
b9ff3018
AC
211/* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
212 than the 32 bit SYSV R4 ABI structure return convention - all
213 structures, no matter their size, are put in memory. Vectors,
214 which were added later, do get returned in a register though. */
215
05580c65 216static enum return_value_convention
c055b101
CV
217ppc_linux_return_value (struct gdbarch *gdbarch, struct type *func_type,
218 struct type *valtype, struct regcache *regcache,
219 gdb_byte *readbuf, const gdb_byte *writebuf)
b9ff3018 220{
05580c65
AC
221 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
222 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
223 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
224 && TYPE_VECTOR (valtype)))
225 return RETURN_VALUE_STRUCT_CONVENTION;
226 else
c055b101
CV
227 return ppc_sysv_abi_return_value (gdbarch, func_type, valtype, regcache,
228 readbuf, writebuf);
b9ff3018
AC
229}
230
f470a70a
JB
231/* Macros for matching instructions. Note that, since all the
232 operands are masked off before they're or-ed into the instruction,
233 you can use -1 to make masks. */
234
235#define insn_d(opcd, rts, ra, d) \
236 ((((opcd) & 0x3f) << 26) \
237 | (((rts) & 0x1f) << 21) \
238 | (((ra) & 0x1f) << 16) \
239 | ((d) & 0xffff))
240
241#define insn_ds(opcd, rts, ra, d, xo) \
242 ((((opcd) & 0x3f) << 26) \
243 | (((rts) & 0x1f) << 21) \
244 | (((ra) & 0x1f) << 16) \
245 | ((d) & 0xfffc) \
246 | ((xo) & 0x3))
247
248#define insn_xfx(opcd, rts, spr, xo) \
249 ((((opcd) & 0x3f) << 26) \
250 | (((rts) & 0x1f) << 21) \
251 | (((spr) & 0x1f) << 16) \
252 | (((spr) & 0x3e0) << 6) \
253 | (((xo) & 0x3ff) << 1))
254
255/* Read a PPC instruction from memory. PPC instructions are always
256 big-endian, no matter what endianness the program is running in, so
257 we can't use read_memory_integer or one of its friends here. */
258static unsigned int
259read_insn (CORE_ADDR pc)
260{
261 unsigned char buf[4];
262
263 read_memory (pc, buf, 4);
264 return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
265}
266
267
268/* An instruction to match. */
269struct insn_pattern
270{
271 unsigned int mask; /* mask the insn with this... */
272 unsigned int data; /* ...and see if it matches this. */
273 int optional; /* If non-zero, this insn may be absent. */
274};
275
276/* Return non-zero if the instructions at PC match the series
277 described in PATTERN, or zero otherwise. PATTERN is an array of
278 'struct insn_pattern' objects, terminated by an entry whose mask is
279 zero.
280
281 When the match is successful, fill INSN[i] with what PATTERN[i]
282 matched. If PATTERN[i] is optional, and the instruction wasn't
283 present, set INSN[i] to 0 (which is not a valid PPC instruction).
284 INSN should have as many elements as PATTERN. Note that, if
285 PATTERN contains optional instructions which aren't present in
286 memory, then INSN will have holes, so INSN[i] isn't necessarily the
287 i'th instruction in memory. */
288static int
289insns_match_pattern (CORE_ADDR pc,
290 struct insn_pattern *pattern,
291 unsigned int *insn)
292{
293 int i;
294
295 for (i = 0; pattern[i].mask; i++)
296 {
297 insn[i] = read_insn (pc);
298 if ((insn[i] & pattern[i].mask) == pattern[i].data)
299 pc += 4;
300 else if (pattern[i].optional)
301 insn[i] = 0;
302 else
303 return 0;
304 }
305
306 return 1;
307}
308
309
310/* Return the 'd' field of the d-form instruction INSN, properly
311 sign-extended. */
312static CORE_ADDR
313insn_d_field (unsigned int insn)
314{
315 return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000);
316}
317
318
319/* Return the 'ds' field of the ds-form instruction INSN, with the two
320 zero bits concatenated at the right, and properly
321 sign-extended. */
322static CORE_ADDR
323insn_ds_field (unsigned int insn)
324{
325 return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000);
326}
327
328
e538d2d7 329/* If DESC is the address of a 64-bit PowerPC GNU/Linux function
d64558a5
JB
330 descriptor, return the descriptor's entry point. */
331static CORE_ADDR
e17a4113 332ppc64_desc_entry_point (struct gdbarch *gdbarch, CORE_ADDR desc)
d64558a5 333{
e17a4113 334 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
d64558a5 335 /* The first word of the descriptor is the entry point. */
e17a4113 336 return (CORE_ADDR) read_memory_unsigned_integer (desc, 8, byte_order);
d64558a5
JB
337}
338
339
f470a70a
JB
340/* Pattern for the standard linkage function. These are built by
341 build_plt_stub in elf64-ppc.c, whose GLINK argument is always
342 zero. */
42848c96 343static struct insn_pattern ppc64_standard_linkage1[] =
f470a70a
JB
344 {
345 /* addis r12, r2, <any> */
346 { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
347
348 /* std r2, 40(r1) */
349 { -1, insn_ds (62, 2, 1, 40, 0), 0 },
350
351 /* ld r11, <any>(r12) */
352 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
353
354 /* addis r12, r12, 1 <optional> */
42848c96 355 { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },
f470a70a
JB
356
357 /* ld r2, <any>(r12) */
358 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
359
360 /* addis r12, r12, 1 <optional> */
42848c96 361 { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },
f470a70a
JB
362
363 /* mtctr r11 */
42848c96 364 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
f470a70a
JB
365
366 /* ld r11, <any>(r12) */
367 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
368
369 /* bctr */
370 { -1, 0x4e800420, 0 },
371
372 { 0, 0, 0 }
373 };
42848c96
UW
374#define PPC64_STANDARD_LINKAGE1_LEN \
375 (sizeof (ppc64_standard_linkage1) / sizeof (ppc64_standard_linkage1[0]))
376
377static struct insn_pattern ppc64_standard_linkage2[] =
378 {
379 /* addis r12, r2, <any> */
380 { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
381
382 /* std r2, 40(r1) */
383 { -1, insn_ds (62, 2, 1, 40, 0), 0 },
384
385 /* ld r11, <any>(r12) */
386 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
387
388 /* addi r12, r12, <any> <optional> */
389 { insn_d (-1, -1, -1, 0), insn_d (14, 12, 12, 0), 1 },
390
391 /* mtctr r11 */
392 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
393
394 /* ld r2, <any>(r12) */
395 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
396
397 /* ld r11, <any>(r12) */
398 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
399
400 /* bctr */
401 { -1, 0x4e800420, 0 },
402
403 { 0, 0, 0 }
404 };
405#define PPC64_STANDARD_LINKAGE2_LEN \
406 (sizeof (ppc64_standard_linkage2) / sizeof (ppc64_standard_linkage2[0]))
407
408static struct insn_pattern ppc64_standard_linkage3[] =
409 {
410 /* std r2, 40(r1) */
411 { -1, insn_ds (62, 2, 1, 40, 0), 0 },
412
413 /* ld r11, <any>(r2) */
414 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
415
416 /* addi r2, r2, <any> <optional> */
417 { insn_d (-1, -1, -1, 0), insn_d (14, 2, 2, 0), 1 },
418
419 /* mtctr r11 */
420 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
421
422 /* ld r11, <any>(r2) */
423 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
424
425 /* ld r2, <any>(r2) */
426 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },
427
428 /* bctr */
429 { -1, 0x4e800420, 0 },
430
431 { 0, 0, 0 }
432 };
433#define PPC64_STANDARD_LINKAGE3_LEN \
434 (sizeof (ppc64_standard_linkage3) / sizeof (ppc64_standard_linkage3[0]))
435
f470a70a 436
f470a70a
JB
437/* When the dynamic linker is doing lazy symbol resolution, the first
438 call to a function in another object will go like this:
439
440 - The user's function calls the linkage function:
441
442 100007c4: 4b ff fc d5 bl 10000498
443 100007c8: e8 41 00 28 ld r2,40(r1)
444
445 - The linkage function loads the entry point (and other stuff) from
446 the function descriptor in the PLT, and jumps to it:
447
448 10000498: 3d 82 00 00 addis r12,r2,0
449 1000049c: f8 41 00 28 std r2,40(r1)
450 100004a0: e9 6c 80 98 ld r11,-32616(r12)
451 100004a4: e8 4c 80 a0 ld r2,-32608(r12)
452 100004a8: 7d 69 03 a6 mtctr r11
453 100004ac: e9 6c 80 a8 ld r11,-32600(r12)
454 100004b0: 4e 80 04 20 bctr
455
456 - But since this is the first time that PLT entry has been used, it
457 sends control to its glink entry. That loads the number of the
458 PLT entry and jumps to the common glink0 code:
459
460 10000c98: 38 00 00 00 li r0,0
461 10000c9c: 4b ff ff dc b 10000c78
462
463 - The common glink0 code then transfers control to the dynamic
464 linker's fixup code:
465
466 10000c78: e8 41 00 28 ld r2,40(r1)
467 10000c7c: 3d 82 00 00 addis r12,r2,0
468 10000c80: e9 6c 80 80 ld r11,-32640(r12)
469 10000c84: e8 4c 80 88 ld r2,-32632(r12)
470 10000c88: 7d 69 03 a6 mtctr r11
471 10000c8c: e9 6c 80 90 ld r11,-32624(r12)
472 10000c90: 4e 80 04 20 bctr
473
474 Eventually, this code will figure out how to skip all of this,
475 including the dynamic linker. At the moment, we just get through
476 the linkage function. */
477
478/* If the current thread is about to execute a series of instructions
479 at PC matching the ppc64_standard_linkage pattern, and INSN is the result
480 from that pattern match, return the code address to which the
481 standard linkage function will send them. (This doesn't deal with
482 dynamic linker lazy symbol resolution stubs.) */
483static CORE_ADDR
42848c96
UW
484ppc64_standard_linkage1_target (struct frame_info *frame,
485 CORE_ADDR pc, unsigned int *insn)
f470a70a 486{
e17a4113
UW
487 struct gdbarch *gdbarch = get_frame_arch (frame);
488 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
f470a70a
JB
489
490 /* The address of the function descriptor this linkage function
491 references. */
492 CORE_ADDR desc
52f729a7
UW
493 = ((CORE_ADDR) get_frame_register_unsigned (frame,
494 tdep->ppc_gp0_regnum + 2)
f470a70a
JB
495 + (insn_d_field (insn[0]) << 16)
496 + insn_ds_field (insn[2]));
497
498 /* The first word of the descriptor is the entry point. Return that. */
e17a4113 499 return ppc64_desc_entry_point (gdbarch, desc);
f470a70a
JB
500}
501
6207416c 502static struct core_regset_section ppc_linux_vsx_regset_sections[] =
17ea7499
CES
503{
504 { ".reg", 268 },
505 { ".reg2", 264 },
506 { ".reg-ppc-vmx", 544 },
604c2f83 507 { ".reg-ppc-vsx", 256 },
17ea7499
CES
508 { NULL, 0}
509};
510
6207416c
LM
511static struct core_regset_section ppc_linux_vmx_regset_sections[] =
512{
513 { ".reg", 268 },
514 { ".reg2", 264 },
515 { ".reg-ppc-vmx", 544 },
516 { NULL, 0}
517};
518
519static struct core_regset_section ppc_linux_fp_regset_sections[] =
520{
521 { ".reg", 268 },
522 { ".reg2", 264 },
523 { NULL, 0}
524};
525
42848c96
UW
526static CORE_ADDR
527ppc64_standard_linkage2_target (struct frame_info *frame,
528 CORE_ADDR pc, unsigned int *insn)
529{
e17a4113
UW
530 struct gdbarch *gdbarch = get_frame_arch (frame);
531 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
42848c96
UW
532
533 /* The address of the function descriptor this linkage function
534 references. */
535 CORE_ADDR desc
536 = ((CORE_ADDR) get_frame_register_unsigned (frame,
537 tdep->ppc_gp0_regnum + 2)
538 + (insn_d_field (insn[0]) << 16)
539 + insn_ds_field (insn[2]));
540
541 /* The first word of the descriptor is the entry point. Return that. */
e17a4113 542 return ppc64_desc_entry_point (gdbarch, desc);
42848c96
UW
543}
544
545static CORE_ADDR
546ppc64_standard_linkage3_target (struct frame_info *frame,
547 CORE_ADDR pc, unsigned int *insn)
548{
e17a4113
UW
549 struct gdbarch *gdbarch = get_frame_arch (frame);
550 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
42848c96
UW
551
552 /* The address of the function descriptor this linkage function
553 references. */
554 CORE_ADDR desc
555 = ((CORE_ADDR) get_frame_register_unsigned (frame,
556 tdep->ppc_gp0_regnum + 2)
557 + insn_ds_field (insn[1]));
558
559 /* The first word of the descriptor is the entry point. Return that. */
e17a4113 560 return ppc64_desc_entry_point (gdbarch, desc);
42848c96
UW
561}
562
f470a70a
JB
563
564/* Given that we've begun executing a call trampoline at PC, return
565 the entry point of the function the trampoline will go to. */
566static CORE_ADDR
52f729a7 567ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
f470a70a 568{
42848c96
UW
569 unsigned int ppc64_standard_linkage1_insn[PPC64_STANDARD_LINKAGE1_LEN];
570 unsigned int ppc64_standard_linkage2_insn[PPC64_STANDARD_LINKAGE2_LEN];
571 unsigned int ppc64_standard_linkage3_insn[PPC64_STANDARD_LINKAGE3_LEN];
572 CORE_ADDR target;
573
574 if (insns_match_pattern (pc, ppc64_standard_linkage1,
575 ppc64_standard_linkage1_insn))
576 pc = ppc64_standard_linkage1_target (frame, pc,
577 ppc64_standard_linkage1_insn);
578 else if (insns_match_pattern (pc, ppc64_standard_linkage2,
579 ppc64_standard_linkage2_insn))
580 pc = ppc64_standard_linkage2_target (frame, pc,
581 ppc64_standard_linkage2_insn);
582 else if (insns_match_pattern (pc, ppc64_standard_linkage3,
583 ppc64_standard_linkage3_insn))
584 pc = ppc64_standard_linkage3_target (frame, pc,
585 ppc64_standard_linkage3_insn);
f470a70a
JB
586 else
587 return 0;
42848c96
UW
588
589 /* The PLT descriptor will either point to the already resolved target
590 address, or else to a glink stub. As the latter carry synthetic @plt
591 symbols, find_solib_trampoline_target should be able to resolve them. */
592 target = find_solib_trampoline_target (frame, pc);
593 return target? target : pc;
f470a70a
JB
594}
595
596
00d5f93a 597/* Support for convert_from_func_ptr_addr (ARCH, ADDR, TARG) on PPC64
e2d0e7eb 598 GNU/Linux.
02631ec0
JB
599
600 Usually a function pointer's representation is simply the address
2bbe3cc1
DJ
601 of the function. On GNU/Linux on the PowerPC however, a function
602 pointer may be a pointer to a function descriptor.
603
604 For PPC64, a function descriptor is a TOC entry, in a data section,
605 which contains three words: the first word is the address of the
606 function, the second word is the TOC pointer (r2), and the third word
607 is the static chain value.
608
2bbe3cc1
DJ
609 Throughout GDB it is currently assumed that a function pointer contains
610 the address of the function, which is not easy to fix. In addition, the
e538d2d7
JB
611 conversion of a function address to a function pointer would
612 require allocation of a TOC entry in the inferior's memory space,
613 with all its drawbacks. To be able to call C++ virtual methods in
614 the inferior (which are called via function pointers),
615 find_function_addr uses this function to get the function address
2bbe3cc1 616 from a function pointer.
02631ec0 617
2bbe3cc1
DJ
618 If ADDR points at what is clearly a function descriptor, transform
619 it into the address of the corresponding function, if needed. Be
620 conservative, otherwise GDB will do the transformation on any
621 random addresses such as occur when there is no symbol table. */
02631ec0
JB
622
623static CORE_ADDR
00d5f93a
UW
624ppc64_linux_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
625 CORE_ADDR addr,
626 struct target_ops *targ)
02631ec0 627{
e17a4113 628 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
0542c86d 629 struct target_section *s = target_section_by_addr (targ, addr);
02631ec0 630
9b540880 631 /* Check if ADDR points to a function descriptor. */
00d5f93a 632 if (s && strcmp (s->the_bfd_section->name, ".opd") == 0)
e84ee240
UW
633 {
634 /* There may be relocations that need to be applied to the .opd
635 section. Unfortunately, this function may be called at a time
636 where these relocations have not yet been performed -- this can
637 happen for example shortly after a library has been loaded with
638 dlopen, but ld.so has not yet applied the relocations.
639
640 To cope with both the case where the relocation has been applied,
641 and the case where it has not yet been applied, we do *not* read
642 the (maybe) relocated value from target memory, but we instead
643 read the non-relocated value from the BFD, and apply the relocation
644 offset manually.
645
646 This makes the assumption that all .opd entries are always relocated
647 by the same offset the section itself was relocated. This should
648 always be the case for GNU/Linux executables and shared libraries.
649 Note that other kind of object files (e.g. those added via
650 add-symbol-files) will currently never end up here anyway, as this
651 function accesses *target* sections only; only the main exec and
652 shared libraries are ever added to the target. */
653
654 gdb_byte buf[8];
655 int res;
656
657 res = bfd_get_section_contents (s->bfd, s->the_bfd_section,
658 &buf, addr - s->addr, 8);
659 if (res != 0)
e17a4113 660 return extract_unsigned_integer (buf, 8, byte_order)
e84ee240
UW
661 - bfd_section_vma (s->bfd, s->the_bfd_section) + s->addr;
662 }
9b540880
AC
663
664 return addr;
02631ec0
JB
665}
666
7284e1be
UW
667/* Wrappers to handle Linux-only registers. */
668
669static void
670ppc_linux_supply_gregset (const struct regset *regset,
671 struct regcache *regcache,
672 int regnum, const void *gregs, size_t len)
673{
674 const struct ppc_reg_offsets *offsets = regset->descr;
675
676 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
677
678 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
679 {
680 /* "orig_r3" is stored 2 slots after "pc". */
681 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
682 ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
683 offsets->pc_offset + 2 * offsets->gpr_size,
684 offsets->gpr_size);
685
686 /* "trap" is stored 8 slots after "pc". */
687 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
688 ppc_supply_reg (regcache, PPC_TRAP_REGNUM, gregs,
689 offsets->pc_offset + 8 * offsets->gpr_size,
690 offsets->gpr_size);
691 }
692}
f2db237a 693
f9be684a 694static void
f2db237a
AM
695ppc_linux_collect_gregset (const struct regset *regset,
696 const struct regcache *regcache,
697 int regnum, void *gregs, size_t len)
f9be684a 698{
7284e1be
UW
699 const struct ppc_reg_offsets *offsets = regset->descr;
700
701 /* Clear areas in the linux gregset not written elsewhere. */
f2db237a
AM
702 if (regnum == -1)
703 memset (gregs, 0, len);
7284e1be 704
f2db237a 705 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
7284e1be
UW
706
707 if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
708 {
709 /* "orig_r3" is stored 2 slots after "pc". */
710 if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
711 ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
712 offsets->pc_offset + 2 * offsets->gpr_size,
713 offsets->gpr_size);
714
715 /* "trap" is stored 8 slots after "pc". */
716 if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
717 ppc_collect_reg (regcache, PPC_TRAP_REGNUM, gregs,
718 offsets->pc_offset + 8 * offsets->gpr_size,
719 offsets->gpr_size);
720 }
f9be684a
AC
721}
722
f2db237a
AM
723/* Regset descriptions. */
724static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
725 {
726 /* General-purpose registers. */
727 /* .r0_offset = */ 0,
728 /* .gpr_size = */ 4,
729 /* .xr_size = */ 4,
730 /* .pc_offset = */ 128,
731 /* .ps_offset = */ 132,
732 /* .cr_offset = */ 152,
733 /* .lr_offset = */ 144,
734 /* .ctr_offset = */ 140,
735 /* .xer_offset = */ 148,
736 /* .mq_offset = */ 156,
737
738 /* Floating-point registers. */
739 /* .f0_offset = */ 0,
740 /* .fpscr_offset = */ 256,
741 /* .fpscr_size = */ 8,
742
743 /* AltiVec registers. */
744 /* .vr0_offset = */ 0,
06caf7d2
CES
745 /* .vscr_offset = */ 512 + 12,
746 /* .vrsave_offset = */ 528
f2db237a 747 };
f9be684a 748
f2db237a
AM
749static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
750 {
751 /* General-purpose registers. */
752 /* .r0_offset = */ 0,
753 /* .gpr_size = */ 8,
754 /* .xr_size = */ 8,
755 /* .pc_offset = */ 256,
756 /* .ps_offset = */ 264,
757 /* .cr_offset = */ 304,
758 /* .lr_offset = */ 288,
759 /* .ctr_offset = */ 280,
760 /* .xer_offset = */ 296,
761 /* .mq_offset = */ 312,
762
763 /* Floating-point registers. */
764 /* .f0_offset = */ 0,
765 /* .fpscr_offset = */ 256,
766 /* .fpscr_size = */ 8,
767
768 /* AltiVec registers. */
769 /* .vr0_offset = */ 0,
06caf7d2
CES
770 /* .vscr_offset = */ 512 + 12,
771 /* .vrsave_offset = */ 528
f2db237a 772 };
2fda4977 773
f2db237a
AM
774static const struct regset ppc32_linux_gregset = {
775 &ppc32_linux_reg_offsets,
7284e1be 776 ppc_linux_supply_gregset,
f2db237a
AM
777 ppc_linux_collect_gregset,
778 NULL
f9be684a
AC
779};
780
f2db237a
AM
781static const struct regset ppc64_linux_gregset = {
782 &ppc64_linux_reg_offsets,
7284e1be 783 ppc_linux_supply_gregset,
f2db237a
AM
784 ppc_linux_collect_gregset,
785 NULL
786};
f9be684a 787
f2db237a
AM
788static const struct regset ppc32_linux_fpregset = {
789 &ppc32_linux_reg_offsets,
790 ppc_supply_fpregset,
791 ppc_collect_fpregset,
792 NULL
f9be684a
AC
793};
794
06caf7d2
CES
795static const struct regset ppc32_linux_vrregset = {
796 &ppc32_linux_reg_offsets,
797 ppc_supply_vrregset,
798 ppc_collect_vrregset,
799 NULL
800};
801
604c2f83
LM
802static const struct regset ppc32_linux_vsxregset = {
803 &ppc32_linux_reg_offsets,
804 ppc_supply_vsxregset,
805 ppc_collect_vsxregset,
806 NULL
807};
808
f2db237a
AM
809const struct regset *
810ppc_linux_gregset (int wordsize)
2fda4977 811{
f2db237a 812 return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
2fda4977
DJ
813}
814
f2db237a
AM
815const struct regset *
816ppc_linux_fpregset (void)
817{
818 return &ppc32_linux_fpregset;
819}
2fda4977 820
f9be684a
AC
821static const struct regset *
822ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
823 const char *sect_name, size_t sect_size)
2fda4977 824{
f9be684a
AC
825 struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
826 if (strcmp (sect_name, ".reg") == 0)
2fda4977 827 {
f9be684a
AC
828 if (tdep->wordsize == 4)
829 return &ppc32_linux_gregset;
2fda4977 830 else
f9be684a 831 return &ppc64_linux_gregset;
2fda4977 832 }
f9be684a 833 if (strcmp (sect_name, ".reg2") == 0)
f2db237a 834 return &ppc32_linux_fpregset;
06caf7d2
CES
835 if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
836 return &ppc32_linux_vrregset;
604c2f83
LM
837 if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
838 return &ppc32_linux_vsxregset;
f9be684a 839 return NULL;
2fda4977
DJ
840}
841
a8f60bfc 842static void
5366653e 843ppc_linux_sigtramp_cache (struct frame_info *this_frame,
a8f60bfc
AC
844 struct trad_frame_cache *this_cache,
845 CORE_ADDR func, LONGEST offset,
846 int bias)
847{
848 CORE_ADDR base;
849 CORE_ADDR regs;
850 CORE_ADDR gpregs;
851 CORE_ADDR fpregs;
852 int i;
5366653e 853 struct gdbarch *gdbarch = get_frame_arch (this_frame);
a8f60bfc 854 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
e17a4113 855 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
a8f60bfc 856
5366653e
DJ
857 base = get_frame_register_unsigned (this_frame,
858 gdbarch_sp_regnum (gdbarch));
859 if (bias > 0 && get_frame_pc (this_frame) != func)
a8f60bfc
AC
860 /* See below, some signal trampolines increment the stack as their
861 first instruction, need to compensate for that. */
862 base -= bias;
863
864 /* Find the address of the register buffer pointer. */
865 regs = base + offset;
866 /* Use that to find the address of the corresponding register
867 buffers. */
e17a4113 868 gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
a8f60bfc
AC
869 fpregs = gpregs + 48 * tdep->wordsize;
870
871 /* General purpose. */
872 for (i = 0; i < 32; i++)
873 {
874 int regnum = i + tdep->ppc_gp0_regnum;
875 trad_frame_set_reg_addr (this_cache, regnum, gpregs + i * tdep->wordsize);
876 }
3e8c568d 877 trad_frame_set_reg_addr (this_cache,
40a6adc1 878 gdbarch_pc_regnum (gdbarch),
3e8c568d 879 gpregs + 32 * tdep->wordsize);
a8f60bfc
AC
880 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
881 gpregs + 35 * tdep->wordsize);
882 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
883 gpregs + 36 * tdep->wordsize);
884 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
885 gpregs + 37 * tdep->wordsize);
886 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
887 gpregs + 38 * tdep->wordsize);
888
7284e1be
UW
889 if (ppc_linux_trap_reg_p (gdbarch))
890 {
891 trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
892 gpregs + 34 * tdep->wordsize);
893 trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
894 gpregs + 40 * tdep->wordsize);
895 }
896
60f140f9
PG
897 if (ppc_floating_point_unit_p (gdbarch))
898 {
899 /* Floating point registers. */
900 for (i = 0; i < 32; i++)
901 {
40a6adc1 902 int regnum = i + gdbarch_fp0_regnum (gdbarch);
60f140f9
PG
903 trad_frame_set_reg_addr (this_cache, regnum,
904 fpregs + i * tdep->wordsize);
905 }
906 trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
4019046a 907 fpregs + 32 * tdep->wordsize);
60f140f9 908 }
a8f60bfc
AC
909 trad_frame_set_id (this_cache, frame_id_build (base, func));
910}
911
912static void
913ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
5366653e 914 struct frame_info *this_frame,
a8f60bfc
AC
915 struct trad_frame_cache *this_cache,
916 CORE_ADDR func)
917{
5366653e 918 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
a8f60bfc
AC
919 0xd0 /* Offset to ucontext_t. */
920 + 0x30 /* Offset to .reg. */,
921 0);
922}
923
924static void
925ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
5366653e 926 struct frame_info *this_frame,
a8f60bfc
AC
927 struct trad_frame_cache *this_cache,
928 CORE_ADDR func)
929{
5366653e 930 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
a8f60bfc
AC
931 0x80 /* Offset to ucontext_t. */
932 + 0xe0 /* Offset to .reg. */,
933 128);
934}
935
936static void
937ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
5366653e 938 struct frame_info *this_frame,
a8f60bfc
AC
939 struct trad_frame_cache *this_cache,
940 CORE_ADDR func)
941{
5366653e 942 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
a8f60bfc
AC
943 0x40 /* Offset to ucontext_t. */
944 + 0x1c /* Offset to .reg. */,
945 0);
946}
947
948static void
949ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
5366653e 950 struct frame_info *this_frame,
a8f60bfc
AC
951 struct trad_frame_cache *this_cache,
952 CORE_ADDR func)
953{
5366653e 954 ppc_linux_sigtramp_cache (this_frame, this_cache, func,
a8f60bfc
AC
955 0x80 /* Offset to struct sigcontext. */
956 + 0x38 /* Offset to .reg. */,
957 128);
958}
959
960static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
961 SIGTRAMP_FRAME,
962 4,
963 {
964 { 0x380000ac, -1 }, /* li r0, 172 */
965 { 0x44000002, -1 }, /* sc */
966 { TRAMP_SENTINEL_INSN },
967 },
968 ppc32_linux_sigaction_cache_init
969};
970static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
971 SIGTRAMP_FRAME,
972 4,
973 {
974 { 0x38210080, -1 }, /* addi r1,r1,128 */
975 { 0x380000ac, -1 }, /* li r0, 172 */
976 { 0x44000002, -1 }, /* sc */
977 { TRAMP_SENTINEL_INSN },
978 },
979 ppc64_linux_sigaction_cache_init
980};
981static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
982 SIGTRAMP_FRAME,
983 4,
984 {
985 { 0x38000077, -1 }, /* li r0,119 */
986 { 0x44000002, -1 }, /* sc */
987 { TRAMP_SENTINEL_INSN },
988 },
989 ppc32_linux_sighandler_cache_init
990};
991static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
992 SIGTRAMP_FRAME,
993 4,
994 {
995 { 0x38210080, -1 }, /* addi r1,r1,128 */
996 { 0x38000077, -1 }, /* li r0,119 */
997 { 0x44000002, -1 }, /* sc */
998 { TRAMP_SENTINEL_INSN },
999 },
1000 ppc64_linux_sighandler_cache_init
1001};
1002
7284e1be
UW
1003
1004/* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
1005int
1006ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
1007{
1008 /* If we do not have a target description with registers, then
1009 the special registers will not be included in the register set. */
1010 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1011 return 0;
1012
1013 /* If we do, then it is safe to check the size. */
1014 return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
1015 && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
1016}
1017
1018static void
1019ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1020{
1021 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1022
1023 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
1024
1025 /* Set special TRAP register to -1 to prevent the kernel from
1026 messing with the PC we just installed, if we happen to be
1027 within an interrupted system call that the kernel wants to
1028 restart.
1029
1030 Note that after we return from the dummy call, the TRAP and
1031 ORIG_R3 registers will be automatically restored, and the
1032 kernel continues to restart the system call at this point. */
1033 if (ppc_linux_trap_reg_p (gdbarch))
1034 regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
1035}
1036
1037static const struct target_desc *
1038ppc_linux_core_read_description (struct gdbarch *gdbarch,
1039 struct target_ops *target,
1040 bfd *abfd)
1041{
1042 asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
604c2f83 1043 asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
7284e1be
UW
1044 asection *section = bfd_get_section_by_name (abfd, ".reg");
1045 if (! section)
1046 return NULL;
1047
1048 switch (bfd_section_size (abfd, section))
1049 {
1050 case 48 * 4:
604c2f83
LM
1051 if (vsx)
1052 return tdesc_powerpc_vsx32l;
1053 else if (altivec)
1054 return tdesc_powerpc_altivec32l;
1055 else
1056 return tdesc_powerpc_32l;
7284e1be
UW
1057
1058 case 48 * 8:
604c2f83
LM
1059 if (vsx)
1060 return tdesc_powerpc_vsx64l;
1061 else if (altivec)
1062 return tdesc_powerpc_altivec64l;
1063 else
1064 return tdesc_powerpc_64l;
7284e1be
UW
1065
1066 default:
1067 return NULL;
1068 }
1069}
1070
7b112f9c
JT
1071static void
1072ppc_linux_init_abi (struct gdbarch_info info,
1073 struct gdbarch *gdbarch)
1074{
1075 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7284e1be 1076 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
7b112f9c 1077
b14d30e1
JM
1078 /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
1079 128-bit, they are IBM long double, not IEEE quad long double as
1080 in the System V ABI PowerPC Processor Supplement. We can safely
1081 let them default to 128-bit, since the debug info will give the
1082 size of type actually used in each case. */
1083 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
1084 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
0598a43c 1085
7284e1be
UW
1086 /* Handle inferior calls during interrupted system calls. */
1087 set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
1088
7b112f9c
JT
1089 if (tdep->wordsize == 4)
1090 {
b9ff3018
AC
1091 /* Until November 2001, gcc did not comply with the 32 bit SysV
1092 R4 ABI requirement that structures less than or equal to 8
1093 bytes should be returned in registers. Instead GCC was using
1094 the the AIX/PowerOpen ABI - everything returned in memory
1095 (well ignoring vectors that is). When this was corrected, it
1096 wasn't fixed for GNU/Linux native platform. Use the
1097 PowerOpen struct convention. */
05580c65 1098 set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
b9ff3018 1099
7b112f9c
JT
1100 set_gdbarch_memory_remove_breakpoint (gdbarch,
1101 ppc_linux_memory_remove_breakpoint);
61a65099 1102
f470a70a 1103 /* Shared library handling. */
8526f328 1104 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
7b112f9c 1105 set_solib_svr4_fetch_link_map_offsets
76a9d10f 1106 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
a8f60bfc
AC
1107
1108 /* Trampolines. */
1109 tramp_frame_prepend_unwinder (gdbarch, &ppc32_linux_sigaction_tramp_frame);
1110 tramp_frame_prepend_unwinder (gdbarch, &ppc32_linux_sighandler_tramp_frame);
a78c2d62
UW
1111
1112 /* BFD target for core files. */
1113 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1114 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
1115 else
1116 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
7b112f9c 1117 }
f470a70a
JB
1118
1119 if (tdep->wordsize == 8)
1120 {
00d5f93a
UW
1121 /* Handle PPC GNU/Linux 64-bit function pointers (which are really
1122 function descriptors). */
1123 set_gdbarch_convert_from_func_ptr_addr
1124 (gdbarch, ppc64_linux_convert_from_func_ptr_addr);
1125
fb318ff7 1126 /* Shared library handling. */
2bbe3cc1 1127 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
fb318ff7
DJ
1128 set_solib_svr4_fetch_link_map_offsets
1129 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1130
a8f60bfc
AC
1131 /* Trampolines. */
1132 tramp_frame_prepend_unwinder (gdbarch, &ppc64_linux_sigaction_tramp_frame);
1133 tramp_frame_prepend_unwinder (gdbarch, &ppc64_linux_sighandler_tramp_frame);
a78c2d62
UW
1134
1135 /* BFD target for core files. */
1136 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1137 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
1138 else
1139 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
f470a70a 1140 }
f9be684a 1141 set_gdbarch_regset_from_core_section (gdbarch, ppc_linux_regset_from_core_section);
7284e1be 1142 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
b2756930 1143
17ea7499 1144 /* Supported register sections. */
6207416c
LM
1145 if (tdesc_find_feature (info.target_desc,
1146 "org.gnu.gdb.power.vsx"))
1147 set_gdbarch_core_regset_sections (gdbarch, ppc_linux_vsx_regset_sections);
1148 else if (tdesc_find_feature (info.target_desc,
1149 "org.gnu.gdb.power.altivec"))
1150 set_gdbarch_core_regset_sections (gdbarch, ppc_linux_vmx_regset_sections);
1151 else
1152 set_gdbarch_core_regset_sections (gdbarch, ppc_linux_fp_regset_sections);
17ea7499 1153
b2756930
KB
1154 /* Enable TLS support. */
1155 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1156 svr4_fetch_objfile_link_map);
7284e1be
UW
1157
1158 if (tdesc_data)
1159 {
1160 const struct tdesc_feature *feature;
1161
1162 /* If we have target-described registers, then we can safely
1163 reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
1164 (whether they are described or not). */
1165 gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
1166 set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
1167
1168 /* If they are present, then assign them to the reserved number. */
1169 feature = tdesc_find_feature (info.target_desc,
1170 "org.gnu.gdb.power.linux");
1171 if (feature != NULL)
1172 {
1173 tdesc_numbered_register (feature, tdesc_data,
1174 PPC_ORIG_R3_REGNUM, "orig_r3");
1175 tdesc_numbered_register (feature, tdesc_data,
1176 PPC_TRAP_REGNUM, "trap");
1177 }
1178 }
7b112f9c
JT
1179}
1180
63807e1d
PA
1181/* Provide a prototype to silence -Wmissing-prototypes. */
1182extern initialize_file_ftype _initialize_ppc_linux_tdep;
1183
7b112f9c
JT
1184void
1185_initialize_ppc_linux_tdep (void)
1186{
0a0a4ac3
AC
1187 /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
1188 64-bit PowerPC, and the older rs6k. */
1189 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
1190 ppc_linux_init_abi);
1191 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
1192 ppc_linux_init_abi);
1193 gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
1194 ppc_linux_init_abi);
7284e1be
UW
1195
1196 /* Initialize the Linux target descriptions. */
1197 initialize_tdesc_powerpc_32l ();
1198 initialize_tdesc_powerpc_altivec32l ();
604c2f83 1199 initialize_tdesc_powerpc_vsx32l ();
69abc51c
TJB
1200 initialize_tdesc_powerpc_isa205_32l ();
1201 initialize_tdesc_powerpc_isa205_altivec32l ();
1202 initialize_tdesc_powerpc_isa205_vsx32l ();
7284e1be
UW
1203 initialize_tdesc_powerpc_64l ();
1204 initialize_tdesc_powerpc_altivec64l ();
604c2f83 1205 initialize_tdesc_powerpc_vsx64l ();
69abc51c
TJB
1206 initialize_tdesc_powerpc_isa205_64l ();
1207 initialize_tdesc_powerpc_isa205_altivec64l ();
1208 initialize_tdesc_powerpc_isa205_vsx64l ();
7284e1be 1209 initialize_tdesc_powerpc_e500l ();
7b112f9c 1210}
This page took 0.870793 seconds and 4 git commands to generate.