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