OSDN Git Service

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