GDB (API)
/home/stan/gdb/src/gdb/ppc-linux-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for GDB, the GNU debugger.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "frame.h"
00022 #include "inferior.h"
00023 #include "symtab.h"
00024 #include "target.h"
00025 #include "gdbcore.h"
00026 #include "gdbcmd.h"
00027 #include "symfile.h"
00028 #include "objfiles.h"
00029 #include "regcache.h"
00030 #include "value.h"
00031 #include "osabi.h"
00032 #include "regset.h"
00033 #include "solib-svr4.h"
00034 #include "solib-spu.h"
00035 #include "solib.h"
00036 #include "solist.h"
00037 #include "ppc-tdep.h"
00038 #include "ppc64-tdep.h"
00039 #include "ppc-linux-tdep.h"
00040 #include "glibc-tdep.h"
00041 #include "trad-frame.h"
00042 #include "frame-unwind.h"
00043 #include "tramp-frame.h"
00044 #include "observer.h"
00045 #include "auxv.h"
00046 #include "elf/common.h"
00047 #include "exceptions.h"
00048 #include "arch-utils.h"
00049 #include "spu-tdep.h"
00050 #include "xml-syscall.h"
00051 #include "linux-tdep.h"
00052 
00053 #include "stap-probe.h"
00054 #include "ax.h"
00055 #include "ax-gdb.h"
00056 #include "cli/cli-utils.h"
00057 #include "parser-defs.h"
00058 #include "user-regs.h"
00059 #include <ctype.h>
00060 #include "elf-bfd.h"            /* for elfcore_write_* */
00061 
00062 #include "features/rs6000/powerpc-32l.c"
00063 #include "features/rs6000/powerpc-altivec32l.c"
00064 #include "features/rs6000/powerpc-cell32l.c"
00065 #include "features/rs6000/powerpc-vsx32l.c"
00066 #include "features/rs6000/powerpc-isa205-32l.c"
00067 #include "features/rs6000/powerpc-isa205-altivec32l.c"
00068 #include "features/rs6000/powerpc-isa205-vsx32l.c"
00069 #include "features/rs6000/powerpc-64l.c"
00070 #include "features/rs6000/powerpc-altivec64l.c"
00071 #include "features/rs6000/powerpc-cell64l.c"
00072 #include "features/rs6000/powerpc-vsx64l.c"
00073 #include "features/rs6000/powerpc-isa205-64l.c"
00074 #include "features/rs6000/powerpc-isa205-altivec64l.c"
00075 #include "features/rs6000/powerpc-isa205-vsx64l.c"
00076 #include "features/rs6000/powerpc-e500l.c"
00077 
00078 /* Shared library operations for PowerPC-Linux.  */
00079 static struct target_so_ops powerpc_so_ops;
00080 
00081 /* The syscall's XML filename for PPC and PPC64.  */
00082 #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
00083 #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
00084 
00085 /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
00086    in much the same fashion as memory_remove_breakpoint in mem-break.c,
00087    but is careful not to write back the previous contents if the code
00088    in question has changed in between inserting the breakpoint and
00089    removing it.
00090 
00091    Here is the problem that we're trying to solve...
00092 
00093    Once upon a time, before introducing this function to remove
00094    breakpoints from the inferior, setting a breakpoint on a shared
00095    library function prior to running the program would not work
00096    properly.  In order to understand the problem, it is first
00097    necessary to understand a little bit about dynamic linking on
00098    this platform.
00099 
00100    A call to a shared library function is accomplished via a bl
00101    (branch-and-link) instruction whose branch target is an entry
00102    in the procedure linkage table (PLT).  The PLT in the object
00103    file is uninitialized.  To gdb, prior to running the program, the
00104    entries in the PLT are all zeros.
00105 
00106    Once the program starts running, the shared libraries are loaded
00107    and the procedure linkage table is initialized, but the entries in
00108    the table are not (necessarily) resolved.  Once a function is
00109    actually called, the code in the PLT is hit and the function is
00110    resolved.  In order to better illustrate this, an example is in
00111    order; the following example is from the gdb testsuite.
00112             
00113         We start the program shmain.
00114 
00115             [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
00116             [...]
00117 
00118         We place two breakpoints, one on shr1 and the other on main.
00119 
00120             (gdb) b shr1
00121             Breakpoint 1 at 0x100409d4
00122             (gdb) b main
00123             Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
00124 
00125         Examine the instruction (and the immediatly following instruction)
00126         upon which the breakpoint was placed.  Note that the PLT entry
00127         for shr1 contains zeros.
00128 
00129             (gdb) x/2i 0x100409d4
00130             0x100409d4 <shr1>:      .long 0x0
00131             0x100409d8 <shr1+4>:    .long 0x0
00132 
00133         Now run 'til main.
00134 
00135             (gdb) r
00136             Starting program: gdb.base/shmain 
00137             Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
00138 
00139             Breakpoint 2, main ()
00140                 at gdb.base/shmain.c:44
00141             44        g = 1;
00142 
00143         Examine the PLT again.  Note that the loading of the shared
00144         library has initialized the PLT to code which loads a constant
00145         (which I think is an index into the GOT) into r11 and then
00146         branchs a short distance to the code which actually does the
00147         resolving.
00148 
00149             (gdb) x/2i 0x100409d4
00150             0x100409d4 <shr1>:      li      r11,4
00151             0x100409d8 <shr1+4>:    b       0x10040984 <sg+4>
00152             (gdb) c
00153             Continuing.
00154 
00155             Breakpoint 1, shr1 (x=1)
00156                 at gdb.base/shr1.c:19
00157             19        l = 1;
00158 
00159         Now we've hit the breakpoint at shr1.  (The breakpoint was
00160         reset from the PLT entry to the actual shr1 function after the
00161         shared library was loaded.) Note that the PLT entry has been
00162         resolved to contain a branch that takes us directly to shr1.
00163         (The real one, not the PLT entry.)
00164 
00165             (gdb) x/2i 0x100409d4
00166             0x100409d4 <shr1>:      b       0xffaf76c <shr1>
00167             0x100409d8 <shr1+4>:    b       0x10040984 <sg+4>
00168 
00169    The thing to note here is that the PLT entry for shr1 has been
00170    changed twice.
00171 
00172    Now the problem should be obvious.  GDB places a breakpoint (a
00173    trap instruction) on the zero value of the PLT entry for shr1.
00174    Later on, after the shared library had been loaded and the PLT
00175    initialized, GDB gets a signal indicating this fact and attempts
00176    (as it always does when it stops) to remove all the breakpoints.
00177 
00178    The breakpoint removal was causing the former contents (a zero
00179    word) to be written back to the now initialized PLT entry thus
00180    destroying a portion of the initialization that had occurred only a
00181    short time ago.  When execution continued, the zero word would be
00182    executed as an instruction an illegal instruction trap was
00183    generated instead.  (0 is not a legal instruction.)
00184 
00185    The fix for this problem was fairly straightforward.  The function
00186    memory_remove_breakpoint from mem-break.c was copied to this file,
00187    modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
00188    In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
00189    function.
00190 
00191    The differences between ppc_linux_memory_remove_breakpoint () and
00192    memory_remove_breakpoint () are minor.  All that the former does
00193    that the latter does not is check to make sure that the breakpoint
00194    location actually contains a breakpoint (trap instruction) prior
00195    to attempting to write back the old contents.  If it does contain
00196    a trap instruction, we allow the old contents to be written back.
00197    Otherwise, we silently do nothing.
00198 
00199    The big question is whether memory_remove_breakpoint () should be
00200    changed to have the same functionality.  The downside is that more
00201    traffic is generated for remote targets since we'll have an extra
00202    fetch of a memory word each time a breakpoint is removed.
00203 
00204    For the time being, we'll leave this self-modifying-code-friendly
00205    version in ppc-linux-tdep.c, but it ought to be migrated somewhere
00206    else in the event that some other platform has similar needs with
00207    regard to removing breakpoints in some potentially self modifying
00208    code.  */
00209 static int
00210 ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
00211                                     struct bp_target_info *bp_tgt)
00212 {
00213   CORE_ADDR addr = bp_tgt->placed_address;
00214   const unsigned char *bp;
00215   int val;
00216   int bplen;
00217   gdb_byte old_contents[BREAKPOINT_MAX];
00218   struct cleanup *cleanup;
00219 
00220   /* Determine appropriate breakpoint contents and size for this address.  */
00221   bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
00222   if (bp == NULL)
00223     error (_("Software breakpoints not implemented for this target."));
00224 
00225   /* Make sure we see the memory breakpoints.  */
00226   cleanup = make_show_memory_breakpoints_cleanup (1);
00227   val = target_read_memory (addr, old_contents, bplen);
00228 
00229   /* If our breakpoint is no longer at the address, this means that the
00230      program modified the code on us, so it is wrong to put back the
00231      old value.  */
00232   if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
00233     val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
00234 
00235   do_cleanups (cleanup);
00236   return val;
00237 }
00238 
00239 /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
00240    than the 32 bit SYSV R4 ABI structure return convention - all
00241    structures, no matter their size, are put in memory.  Vectors,
00242    which were added later, do get returned in a register though.  */
00243 
00244 static enum return_value_convention
00245 ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
00246                         struct type *valtype, struct regcache *regcache,
00247                         gdb_byte *readbuf, const gdb_byte *writebuf)
00248 {  
00249   if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
00250        || TYPE_CODE (valtype) == TYPE_CODE_UNION)
00251       && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
00252            && TYPE_VECTOR (valtype)))
00253     return RETURN_VALUE_STRUCT_CONVENTION;
00254   else
00255     return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
00256                                       readbuf, writebuf);
00257 }
00258 
00259 static struct core_regset_section ppc_linux_vsx_regset_sections[] =
00260 {
00261   { ".reg", 48 * 4, "general-purpose" },
00262   { ".reg2", 264, "floating-point" },
00263   { ".reg-ppc-vmx", 544, "ppc Altivec" },
00264   { ".reg-ppc-vsx", 256, "POWER7 VSX" },
00265   { NULL, 0}
00266 };
00267 
00268 static struct core_regset_section ppc_linux_vmx_regset_sections[] =
00269 {
00270   { ".reg", 48 * 4, "general-purpose" },
00271   { ".reg2", 264, "floating-point" },
00272   { ".reg-ppc-vmx", 544, "ppc Altivec" },
00273   { NULL, 0}
00274 };
00275 
00276 static struct core_regset_section ppc_linux_fp_regset_sections[] =
00277 {
00278   { ".reg", 48 * 4, "general-purpose" },
00279   { ".reg2", 264, "floating-point" },
00280   { NULL, 0}
00281 };
00282 
00283 static struct core_regset_section ppc64_linux_vsx_regset_sections[] =
00284 {
00285   { ".reg", 48 * 8, "general-purpose" },
00286   { ".reg2", 264, "floating-point" },
00287   { ".reg-ppc-vmx", 544, "ppc Altivec" },
00288   { ".reg-ppc-vsx", 256, "POWER7 VSX" },
00289   { NULL, 0}
00290 };
00291 
00292 static struct core_regset_section ppc64_linux_vmx_regset_sections[] =
00293 {
00294   { ".reg", 48 * 8, "general-purpose" },
00295   { ".reg2", 264, "floating-point" },
00296   { ".reg-ppc-vmx", 544, "ppc Altivec" },
00297   { NULL, 0}
00298 };
00299 
00300 static struct core_regset_section ppc64_linux_fp_regset_sections[] =
00301 {
00302   { ".reg", 48 * 8, "general-purpose" },
00303   { ".reg2", 264, "floating-point" },
00304   { NULL, 0}
00305 };
00306 
00307 /* PLT stub in executable.  */
00308 static struct ppc_insn_pattern powerpc32_plt_stub[] =
00309   {
00310     { 0xffff0000, 0x3d600000, 0 },      /* lis   r11, xxxx       */
00311     { 0xffff0000, 0x816b0000, 0 },      /* lwz   r11, xxxx(r11)  */
00312     { 0xffffffff, 0x7d6903a6, 0 },      /* mtctr r11             */
00313     { 0xffffffff, 0x4e800420, 0 },      /* bctr                  */
00314     {          0,          0, 0 }
00315   };
00316 
00317 /* PLT stub in shared library.  */
00318 static struct ppc_insn_pattern powerpc32_plt_stub_so[] =
00319   {
00320     { 0xffff0000, 0x817e0000, 0 },      /* lwz   r11, xxxx(r30)  */
00321     { 0xffffffff, 0x7d6903a6, 0 },      /* mtctr r11             */
00322     { 0xffffffff, 0x4e800420, 0 },      /* bctr                  */
00323     { 0xffffffff, 0x60000000, 0 },      /* nop                   */
00324     {          0,          0, 0 }
00325   };
00326 #define POWERPC32_PLT_STUB_LEN  ARRAY_SIZE (powerpc32_plt_stub)
00327 
00328 /* Check if PC is in PLT stub.  For non-secure PLT, stub is in .plt
00329    section.  For secure PLT, stub is in .text and we need to check
00330    instruction patterns.  */
00331 
00332 static int
00333 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
00334 {
00335   struct bound_minimal_symbol sym;
00336 
00337   /* Check whether PC is in the dynamic linker.  This also checks
00338      whether it is in the .plt section, used by non-PIC executables.  */
00339   if (svr4_in_dynsym_resolve_code (pc))
00340     return 1;
00341 
00342   /* Check if we are in the resolver.  */
00343   sym = lookup_minimal_symbol_by_pc (pc);
00344   if (sym.minsym != NULL
00345       && (strcmp (SYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0
00346           || strcmp (SYMBOL_LINKAGE_NAME (sym.minsym),
00347                      "__glink_PLTresolve") == 0))
00348     return 1;
00349 
00350   return 0;
00351 }
00352 
00353 /* Follow PLT stub to actual routine.  */
00354 
00355 static CORE_ADDR
00356 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
00357 {
00358   unsigned int insnbuf[POWERPC32_PLT_STUB_LEN];
00359   struct gdbarch *gdbarch = get_frame_arch (frame);
00360   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00361   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00362   CORE_ADDR target = 0;
00363 
00364   if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
00365     {
00366       /* Insn pattern is
00367                 lis   r11, xxxx
00368                 lwz   r11, xxxx(r11)
00369          Branch target is in r11.  */
00370 
00371       target = (ppc_insn_d_field (insnbuf[0]) << 16)
00372         | ppc_insn_d_field (insnbuf[1]);
00373       target = read_memory_unsigned_integer (target, 4, byte_order);
00374     }
00375 
00376   if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, insnbuf))
00377     {
00378       /* Insn pattern is
00379                 lwz   r11, xxxx(r30)
00380          Branch target is in r11.  */
00381 
00382       target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30)
00383                + ppc_insn_d_field (insnbuf[0]);
00384       target = read_memory_unsigned_integer (target, 4, byte_order);
00385     }
00386 
00387   return target;
00388 }
00389 
00390 /* Wrappers to handle Linux-only registers.  */
00391 
00392 static void
00393 ppc_linux_supply_gregset (const struct regset *regset,
00394                           struct regcache *regcache,
00395                           int regnum, const void *gregs, size_t len)
00396 {
00397   const struct ppc_reg_offsets *offsets = regset->descr;
00398 
00399   ppc_supply_gregset (regset, regcache, regnum, gregs, len);
00400 
00401   if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
00402     {
00403       /* "orig_r3" is stored 2 slots after "pc".  */
00404       if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
00405         ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
00406                         offsets->pc_offset + 2 * offsets->gpr_size,
00407                         offsets->gpr_size);
00408 
00409       /* "trap" is stored 8 slots after "pc".  */
00410       if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
00411         ppc_supply_reg (regcache, PPC_TRAP_REGNUM, gregs,
00412                         offsets->pc_offset + 8 * offsets->gpr_size,
00413                         offsets->gpr_size);
00414     }
00415 }
00416 
00417 static void
00418 ppc_linux_collect_gregset (const struct regset *regset,
00419                            const struct regcache *regcache,
00420                            int regnum, void *gregs, size_t len)
00421 {
00422   const struct ppc_reg_offsets *offsets = regset->descr;
00423 
00424   /* Clear areas in the linux gregset not written elsewhere.  */
00425   if (regnum == -1)
00426     memset (gregs, 0, len);
00427 
00428   ppc_collect_gregset (regset, regcache, regnum, gregs, len);
00429 
00430   if (ppc_linux_trap_reg_p (get_regcache_arch (regcache)))
00431     {
00432       /* "orig_r3" is stored 2 slots after "pc".  */
00433       if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
00434         ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, gregs,
00435                          offsets->pc_offset + 2 * offsets->gpr_size,
00436                          offsets->gpr_size);
00437 
00438       /* "trap" is stored 8 slots after "pc".  */
00439       if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
00440         ppc_collect_reg (regcache, PPC_TRAP_REGNUM, gregs,
00441                          offsets->pc_offset + 8 * offsets->gpr_size,
00442                          offsets->gpr_size);
00443     }
00444 }
00445 
00446 /* Regset descriptions.  */
00447 static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
00448   {
00449     /* General-purpose registers.  */
00450     /* .r0_offset = */ 0,
00451     /* .gpr_size = */ 4,
00452     /* .xr_size = */ 4,
00453     /* .pc_offset = */ 128,
00454     /* .ps_offset = */ 132,
00455     /* .cr_offset = */ 152,
00456     /* .lr_offset = */ 144,
00457     /* .ctr_offset = */ 140,
00458     /* .xer_offset = */ 148,
00459     /* .mq_offset = */ 156,
00460 
00461     /* Floating-point registers.  */
00462     /* .f0_offset = */ 0,
00463     /* .fpscr_offset = */ 256,
00464     /* .fpscr_size = */ 8,
00465 
00466     /* AltiVec registers.  */
00467     /* .vr0_offset = */ 0,
00468     /* .vscr_offset = */ 512 + 12,
00469     /* .vrsave_offset = */ 528
00470   };
00471 
00472 static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
00473   {
00474     /* General-purpose registers.  */
00475     /* .r0_offset = */ 0,
00476     /* .gpr_size = */ 8,
00477     /* .xr_size = */ 8,
00478     /* .pc_offset = */ 256,
00479     /* .ps_offset = */ 264,
00480     /* .cr_offset = */ 304,
00481     /* .lr_offset = */ 288,
00482     /* .ctr_offset = */ 280,
00483     /* .xer_offset = */ 296,
00484     /* .mq_offset = */ 312,
00485 
00486     /* Floating-point registers.  */
00487     /* .f0_offset = */ 0,
00488     /* .fpscr_offset = */ 256,
00489     /* .fpscr_size = */ 8,
00490 
00491     /* AltiVec registers.  */
00492     /* .vr0_offset = */ 0,
00493     /* .vscr_offset = */ 512 + 12,
00494     /* .vrsave_offset = */ 528
00495   };
00496 
00497 static const struct regset ppc32_linux_gregset = {
00498   &ppc32_linux_reg_offsets,
00499   ppc_linux_supply_gregset,
00500   ppc_linux_collect_gregset,
00501   NULL
00502 };
00503 
00504 static const struct regset ppc64_linux_gregset = {
00505   &ppc64_linux_reg_offsets,
00506   ppc_linux_supply_gregset,
00507   ppc_linux_collect_gregset,
00508   NULL
00509 };
00510 
00511 static const struct regset ppc32_linux_fpregset = {
00512   &ppc32_linux_reg_offsets,
00513   ppc_supply_fpregset,
00514   ppc_collect_fpregset,
00515   NULL
00516 };
00517 
00518 static const struct regset ppc32_linux_vrregset = {
00519   &ppc32_linux_reg_offsets,
00520   ppc_supply_vrregset,
00521   ppc_collect_vrregset,
00522   NULL
00523 };
00524 
00525 static const struct regset ppc32_linux_vsxregset = {
00526   &ppc32_linux_reg_offsets,
00527   ppc_supply_vsxregset,
00528   ppc_collect_vsxregset,
00529   NULL
00530 };
00531 
00532 const struct regset *
00533 ppc_linux_gregset (int wordsize)
00534 {
00535   return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
00536 }
00537 
00538 const struct regset *
00539 ppc_linux_fpregset (void)
00540 {
00541   return &ppc32_linux_fpregset;
00542 }
00543 
00544 static const struct regset *
00545 ppc_linux_regset_from_core_section (struct gdbarch *core_arch,
00546                                     const char *sect_name, size_t sect_size)
00547 {
00548   struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch);
00549   if (strcmp (sect_name, ".reg") == 0)
00550     {
00551       if (tdep->wordsize == 4)
00552         return &ppc32_linux_gregset;
00553       else
00554         return &ppc64_linux_gregset;
00555     }
00556   if (strcmp (sect_name, ".reg2") == 0)
00557     return &ppc32_linux_fpregset;
00558   if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
00559     return &ppc32_linux_vrregset;
00560   if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
00561     return &ppc32_linux_vsxregset;
00562   return NULL;
00563 }
00564 
00565 static void
00566 ppc_linux_sigtramp_cache (struct frame_info *this_frame,
00567                           struct trad_frame_cache *this_cache,
00568                           CORE_ADDR func, LONGEST offset,
00569                           int bias)
00570 {
00571   CORE_ADDR base;
00572   CORE_ADDR regs;
00573   CORE_ADDR gpregs;
00574   CORE_ADDR fpregs;
00575   int i;
00576   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00577   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00578   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00579 
00580   base = get_frame_register_unsigned (this_frame,
00581                                       gdbarch_sp_regnum (gdbarch));
00582   if (bias > 0 && get_frame_pc (this_frame) != func)
00583     /* See below, some signal trampolines increment the stack as their
00584        first instruction, need to compensate for that.  */
00585     base -= bias;
00586 
00587   /* Find the address of the register buffer pointer.  */
00588   regs = base + offset;
00589   /* Use that to find the address of the corresponding register
00590      buffers.  */
00591   gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
00592   fpregs = gpregs + 48 * tdep->wordsize;
00593 
00594   /* General purpose.  */
00595   for (i = 0; i < 32; i++)
00596     {
00597       int regnum = i + tdep->ppc_gp0_regnum;
00598       trad_frame_set_reg_addr (this_cache,
00599                                regnum, gpregs + i * tdep->wordsize);
00600     }
00601   trad_frame_set_reg_addr (this_cache,
00602                            gdbarch_pc_regnum (gdbarch),
00603                            gpregs + 32 * tdep->wordsize);
00604   trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
00605                            gpregs + 35 * tdep->wordsize);
00606   trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
00607                            gpregs + 36 * tdep->wordsize);
00608   trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
00609                            gpregs + 37 * tdep->wordsize);
00610   trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
00611                            gpregs + 38 * tdep->wordsize);
00612 
00613   if (ppc_linux_trap_reg_p (gdbarch))
00614     {
00615       trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
00616                                gpregs + 34 * tdep->wordsize);
00617       trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
00618                                gpregs + 40 * tdep->wordsize);
00619     }
00620 
00621   if (ppc_floating_point_unit_p (gdbarch))
00622     {
00623       /* Floating point registers.  */
00624       for (i = 0; i < 32; i++)
00625         {
00626           int regnum = i + gdbarch_fp0_regnum (gdbarch);
00627           trad_frame_set_reg_addr (this_cache, regnum,
00628                                    fpregs + i * tdep->wordsize);
00629         }
00630       trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
00631                          fpregs + 32 * tdep->wordsize);
00632     }
00633   trad_frame_set_id (this_cache, frame_id_build (base, func));
00634 }
00635 
00636 static void
00637 ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
00638                                   struct frame_info *this_frame,
00639                                   struct trad_frame_cache *this_cache,
00640                                   CORE_ADDR func)
00641 {
00642   ppc_linux_sigtramp_cache (this_frame, this_cache, func,
00643                             0xd0 /* Offset to ucontext_t.  */
00644                             + 0x30 /* Offset to .reg.  */,
00645                             0);
00646 }
00647 
00648 static void
00649 ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
00650                                   struct frame_info *this_frame,
00651                                   struct trad_frame_cache *this_cache,
00652                                   CORE_ADDR func)
00653 {
00654   ppc_linux_sigtramp_cache (this_frame, this_cache, func,
00655                             0x80 /* Offset to ucontext_t.  */
00656                             + 0xe0 /* Offset to .reg.  */,
00657                             128);
00658 }
00659 
00660 static void
00661 ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
00662                                    struct frame_info *this_frame,
00663                                    struct trad_frame_cache *this_cache,
00664                                    CORE_ADDR func)
00665 {
00666   ppc_linux_sigtramp_cache (this_frame, this_cache, func,
00667                             0x40 /* Offset to ucontext_t.  */
00668                             + 0x1c /* Offset to .reg.  */,
00669                             0);
00670 }
00671 
00672 static void
00673 ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
00674                                    struct frame_info *this_frame,
00675                                    struct trad_frame_cache *this_cache,
00676                                    CORE_ADDR func)
00677 {
00678   ppc_linux_sigtramp_cache (this_frame, this_cache, func,
00679                             0x80 /* Offset to struct sigcontext.  */
00680                             + 0x38 /* Offset to .reg.  */,
00681                             128);
00682 }
00683 
00684 static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
00685   SIGTRAMP_FRAME,
00686   4,
00687   { 
00688     { 0x380000ac, -1 }, /* li r0, 172 */
00689     { 0x44000002, -1 }, /* sc */
00690     { TRAMP_SENTINEL_INSN },
00691   },
00692   ppc32_linux_sigaction_cache_init
00693 };
00694 static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
00695   SIGTRAMP_FRAME,
00696   4,
00697   {
00698     { 0x38210080, -1 }, /* addi r1,r1,128 */
00699     { 0x380000ac, -1 }, /* li r0, 172 */
00700     { 0x44000002, -1 }, /* sc */
00701     { TRAMP_SENTINEL_INSN },
00702   },
00703   ppc64_linux_sigaction_cache_init
00704 };
00705 static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
00706   SIGTRAMP_FRAME,
00707   4,
00708   { 
00709     { 0x38000077, -1 }, /* li r0,119 */
00710     { 0x44000002, -1 }, /* sc */
00711     { TRAMP_SENTINEL_INSN },
00712   },
00713   ppc32_linux_sighandler_cache_init
00714 };
00715 static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
00716   SIGTRAMP_FRAME,
00717   4,
00718   { 
00719     { 0x38210080, -1 }, /* addi r1,r1,128 */
00720     { 0x38000077, -1 }, /* li r0,119 */
00721     { 0x44000002, -1 }, /* sc */
00722     { TRAMP_SENTINEL_INSN },
00723   },
00724   ppc64_linux_sighandler_cache_init
00725 };
00726 
00727 
00728 /* Address to use for displaced stepping.  When debugging a stand-alone
00729    SPU executable, entry_point_address () will point to an SPU local-store
00730    address and is thus not usable as displaced stepping location.  We use
00731    the auxiliary vector to determine the PowerPC-side entry point address
00732    instead.  */
00733 
00734 static CORE_ADDR ppc_linux_entry_point_addr = 0;
00735 
00736 static void
00737 ppc_linux_inferior_created (struct target_ops *target, int from_tty)
00738 {
00739   ppc_linux_entry_point_addr = 0;
00740 }
00741 
00742 static CORE_ADDR
00743 ppc_linux_displaced_step_location (struct gdbarch *gdbarch)
00744 {
00745   if (ppc_linux_entry_point_addr == 0)
00746     {
00747       CORE_ADDR addr;
00748 
00749       /* Determine entry point from target auxiliary vector.  */
00750       if (target_auxv_search (&current_target, AT_ENTRY, &addr) <= 0)
00751         error (_("Cannot find AT_ENTRY auxiliary vector entry."));
00752 
00753       /* Make certain that the address points at real code, and not a
00754          function descriptor.  */
00755       addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
00756                                                  &current_target);
00757 
00758       /* Inferior calls also use the entry point as a breakpoint location.
00759          We don't want displaced stepping to interfere with those
00760          breakpoints, so leave space.  */
00761       ppc_linux_entry_point_addr = addr + 2 * PPC_INSN_SIZE;
00762     }
00763 
00764   return ppc_linux_entry_point_addr;
00765 }
00766 
00767 
00768 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable.  */
00769 int
00770 ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
00771 {
00772   /* If we do not have a target description with registers, then
00773      the special registers will not be included in the register set.  */
00774   if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
00775     return 0;
00776 
00777   /* If we do, then it is safe to check the size.  */
00778   return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
00779          && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
00780 }
00781 
00782 /* Return the current system call's number present in the
00783    r0 register.  When the function fails, it returns -1.  */
00784 static LONGEST
00785 ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
00786                               ptid_t ptid)
00787 {
00788   struct regcache *regcache = get_thread_regcache (ptid);
00789   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00790   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00791   struct cleanup *cleanbuf;
00792   /* The content of a register */
00793   gdb_byte *buf;
00794   /* The result */
00795   LONGEST ret;
00796 
00797   /* Make sure we're in a 32- or 64-bit machine */
00798   gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
00799 
00800   buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte));
00801 
00802   cleanbuf = make_cleanup (xfree, buf);
00803 
00804   /* Getting the system call number from the register.
00805      When dealing with PowerPC architecture, this information
00806      is stored at 0th register.  */
00807   regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf);
00808 
00809   ret = extract_signed_integer (buf, tdep->wordsize, byte_order);
00810   do_cleanups (cleanbuf);
00811 
00812   return ret;
00813 }
00814 
00815 static void
00816 ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
00817 {
00818   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00819 
00820   regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
00821 
00822   /* Set special TRAP register to -1 to prevent the kernel from
00823      messing with the PC we just installed, if we happen to be
00824      within an interrupted system call that the kernel wants to
00825      restart.
00826 
00827      Note that after we return from the dummy call, the TRAP and
00828      ORIG_R3 registers will be automatically restored, and the
00829      kernel continues to restart the system call at this point.  */
00830   if (ppc_linux_trap_reg_p (gdbarch))
00831     regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
00832 }
00833 
00834 static int
00835 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
00836 {
00837   return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
00838 }
00839 
00840 static const struct target_desc *
00841 ppc_linux_core_read_description (struct gdbarch *gdbarch,
00842                                  struct target_ops *target,
00843                                  bfd *abfd)
00844 {
00845   asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
00846   asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
00847   asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
00848   asection *section = bfd_get_section_by_name (abfd, ".reg");
00849   if (! section)
00850     return NULL;
00851 
00852   switch (bfd_section_size (abfd, section))
00853     {
00854     case 48 * 4:
00855       if (cell)
00856         return tdesc_powerpc_cell32l;
00857       else if (vsx)
00858         return tdesc_powerpc_vsx32l;
00859       else if (altivec)
00860         return tdesc_powerpc_altivec32l;
00861       else
00862         return tdesc_powerpc_32l;
00863 
00864     case 48 * 8:
00865       if (cell)
00866         return tdesc_powerpc_cell64l;
00867       else if (vsx)
00868         return tdesc_powerpc_vsx64l;
00869       else if (altivec)
00870         return tdesc_powerpc_altivec64l;
00871       else
00872         return tdesc_powerpc_64l;
00873 
00874     default:
00875       return NULL;
00876     }
00877 }
00878 
00879 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
00880    gdbarch.h.  */
00881 
00882 static int
00883 ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
00884 {
00885   return (*s == 'i' /* Literal number.  */
00886           || (isdigit (*s) && s[1] == '('
00887               && isdigit (s[2])) /* Displacement.  */
00888           || (*s == '(' && isdigit (s[1])) /* Register indirection.  */
00889           || isdigit (*s)); /* Register value.  */
00890 }
00891 
00892 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
00893    gdbarch.h.  */
00894 
00895 static int
00896 ppc_stap_parse_special_token (struct gdbarch *gdbarch,
00897                               struct stap_parse_info *p)
00898 {
00899   if (isdigit (*p->arg))
00900     {
00901       /* This temporary pointer is needed because we have to do a lookahead.
00902           We could be dealing with a register displacement, and in such case
00903           we would not need to do anything.  */
00904       const char *s = p->arg;
00905       char *regname;
00906       int len;
00907       struct stoken str;
00908 
00909       while (isdigit (*s))
00910         ++s;
00911 
00912       if (*s == '(')
00913         {
00914           /* It is a register displacement indeed.  Returning 0 means we are
00915              deferring the treatment of this case to the generic parser.  */
00916           return 0;
00917         }
00918 
00919       len = s - p->arg;
00920       regname = alloca (len + 2);
00921       regname[0] = 'r';
00922 
00923       strncpy (regname + 1, p->arg, len);
00924       ++len;
00925       regname[len] = '\0';
00926 
00927       if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
00928         error (_("Invalid register name `%s' on expression `%s'."),
00929                regname, p->saved_arg);
00930 
00931       write_exp_elt_opcode (OP_REGISTER);
00932       str.ptr = regname;
00933       str.length = len;
00934       write_exp_string (str);
00935       write_exp_elt_opcode (OP_REGISTER);
00936 
00937       p->arg = s;
00938     }
00939   else
00940     {
00941       /* All the other tokens should be handled correctly by the generic
00942          parser.  */
00943       return 0;
00944     }
00945 
00946   return 1;
00947 }
00948 
00949 /* Cell/B.E. active SPE context tracking support.  */
00950 
00951 static struct objfile *spe_context_objfile = NULL;
00952 static CORE_ADDR spe_context_lm_addr = 0;
00953 static CORE_ADDR spe_context_offset = 0;
00954 
00955 static ptid_t spe_context_cache_ptid;
00956 static CORE_ADDR spe_context_cache_address;
00957 
00958 /* Hook into inferior_created, solib_loaded, and solib_unloaded observers
00959    to track whether we've loaded a version of libspe2 (as static or dynamic
00960    library) that provides the __spe_current_active_context variable.  */
00961 static void
00962 ppc_linux_spe_context_lookup (struct objfile *objfile)
00963 {
00964   struct minimal_symbol *sym;
00965 
00966   if (!objfile)
00967     {
00968       spe_context_objfile = NULL;
00969       spe_context_lm_addr = 0;
00970       spe_context_offset = 0;
00971       spe_context_cache_ptid = minus_one_ptid;
00972       spe_context_cache_address = 0;
00973       return;
00974     }
00975 
00976   sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
00977   if (sym)
00978     {
00979       spe_context_objfile = objfile;
00980       spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
00981       spe_context_offset = SYMBOL_VALUE_ADDRESS (sym);
00982       spe_context_cache_ptid = minus_one_ptid;
00983       spe_context_cache_address = 0;
00984       return;
00985     }
00986 }
00987 
00988 static void
00989 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
00990 {
00991   struct objfile *objfile;
00992 
00993   ppc_linux_spe_context_lookup (NULL);
00994   ALL_OBJFILES (objfile)
00995     ppc_linux_spe_context_lookup (objfile);
00996 }
00997 
00998 static void
00999 ppc_linux_spe_context_solib_loaded (struct so_list *so)
01000 {
01001   if (strstr (so->so_original_name, "/libspe") != NULL)
01002     {
01003       solib_read_symbols (so, 0);
01004       ppc_linux_spe_context_lookup (so->objfile);
01005     }
01006 }
01007 
01008 static void
01009 ppc_linux_spe_context_solib_unloaded (struct so_list *so)
01010 {
01011   if (so->objfile == spe_context_objfile)
01012     ppc_linux_spe_context_lookup (NULL);
01013 }
01014 
01015 /* Retrieve contents of the N'th element in the current thread's
01016    linked SPE context list into ID and NPC.  Return the address of
01017    said context element, or 0 if not found.  */
01018 static CORE_ADDR
01019 ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
01020                        int n, int *id, unsigned int *npc)
01021 {
01022   CORE_ADDR spe_context = 0;
01023   gdb_byte buf[16];
01024   int i;
01025 
01026   /* Quick exit if we have not found __spe_current_active_context.  */
01027   if (!spe_context_objfile)
01028     return 0;
01029 
01030   /* Look up cached address of thread-local variable.  */
01031   if (!ptid_equal (spe_context_cache_ptid, inferior_ptid))
01032     {
01033       struct target_ops *target = &current_target;
01034       volatile struct gdb_exception ex;
01035 
01036       while (target && !target->to_get_thread_local_address)
01037         target = find_target_beneath (target);
01038       if (!target)
01039         return 0;
01040 
01041       TRY_CATCH (ex, RETURN_MASK_ERROR)
01042         {
01043           /* We do not call target_translate_tls_address here, because
01044              svr4_fetch_objfile_link_map may invalidate the frame chain,
01045              which must not do while inside a frame sniffer.
01046 
01047              Instead, we have cached the lm_addr value, and use that to
01048              directly call the target's to_get_thread_local_address.  */
01049           spe_context_cache_address
01050             = target->to_get_thread_local_address (target, inferior_ptid,
01051                                                    spe_context_lm_addr,
01052                                                    spe_context_offset);
01053           spe_context_cache_ptid = inferior_ptid;
01054         }
01055 
01056       if (ex.reason < 0)
01057         return 0;
01058     }
01059 
01060   /* Read variable value.  */
01061   if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
01062     spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
01063 
01064   /* Cyle through to N'th linked list element.  */
01065   for (i = 0; i < n && spe_context; i++)
01066     if (target_read_memory (spe_context + align_up (12, wordsize),
01067                             buf, wordsize) == 0)
01068       spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
01069     else
01070       spe_context = 0;
01071 
01072   /* Read current context.  */
01073   if (spe_context
01074       && target_read_memory (spe_context, buf, 12) != 0)
01075     spe_context = 0;
01076 
01077   /* Extract data elements.  */
01078   if (spe_context)
01079     {
01080       if (id)
01081         *id = extract_signed_integer (buf, 4, byte_order);
01082       if (npc)
01083         *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
01084     }
01085 
01086   return spe_context;
01087 }
01088 
01089 
01090 /* Cell/B.E. cross-architecture unwinder support.  */
01091 
01092 struct ppu2spu_cache
01093 {
01094   struct frame_id frame_id;
01095   struct regcache *regcache;
01096 };
01097 
01098 static struct gdbarch *
01099 ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
01100 {
01101   struct ppu2spu_cache *cache = *this_cache;
01102   return get_regcache_arch (cache->regcache);
01103 }
01104 
01105 static void
01106 ppu2spu_this_id (struct frame_info *this_frame,
01107                  void **this_cache, struct frame_id *this_id)
01108 {
01109   struct ppu2spu_cache *cache = *this_cache;
01110   *this_id = cache->frame_id;
01111 }
01112 
01113 static struct value *
01114 ppu2spu_prev_register (struct frame_info *this_frame,
01115                        void **this_cache, int regnum)
01116 {
01117   struct ppu2spu_cache *cache = *this_cache;
01118   struct gdbarch *gdbarch = get_regcache_arch (cache->regcache);
01119   gdb_byte *buf;
01120 
01121   buf = alloca (register_size (gdbarch, regnum));
01122 
01123   if (regnum < gdbarch_num_regs (gdbarch))
01124     regcache_raw_read (cache->regcache, regnum, buf);
01125   else
01126     gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf);
01127 
01128   return frame_unwind_got_bytes (this_frame, regnum, buf);
01129 }
01130 
01131 struct ppu2spu_data
01132 {
01133   struct gdbarch *gdbarch;
01134   int id;
01135   unsigned int npc;
01136   gdb_byte gprs[128*16];
01137 };
01138 
01139 static int
01140 ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf)
01141 {
01142   struct ppu2spu_data *data = src;
01143   enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
01144 
01145   if (regnum >= 0 && regnum < SPU_NUM_GPRS)
01146     memcpy (buf, data->gprs + 16*regnum, 16);
01147   else if (regnum == SPU_ID_REGNUM)
01148     store_unsigned_integer (buf, 4, byte_order, data->id);
01149   else if (regnum == SPU_PC_REGNUM)
01150     store_unsigned_integer (buf, 4, byte_order, data->npc);
01151   else
01152     return REG_UNAVAILABLE;
01153 
01154   return REG_VALID;
01155 }
01156 
01157 static int
01158 ppu2spu_sniffer (const struct frame_unwind *self,
01159                  struct frame_info *this_frame, void **this_prologue_cache)
01160 {
01161   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01162   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01163   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01164   struct ppu2spu_data data;
01165   struct frame_info *fi;
01166   CORE_ADDR base, func, backchain, spe_context;
01167   gdb_byte buf[8];
01168   int n = 0;
01169 
01170   /* Count the number of SPU contexts already in the frame chain.  */
01171   for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
01172     if (get_frame_type (fi) == ARCH_FRAME
01173         && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
01174       n++;
01175 
01176   base = get_frame_sp (this_frame);
01177   func = get_frame_pc (this_frame);
01178   if (target_read_memory (base, buf, tdep->wordsize))
01179     return 0;
01180   backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
01181 
01182   spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
01183                                        n, &data.id, &data.npc);
01184   if (spe_context && base <= spe_context && spe_context < backchain)
01185     {
01186       char annex[32];
01187 
01188       /* Find gdbarch for SPU.  */
01189       struct gdbarch_info info;
01190       gdbarch_info_init (&info);
01191       info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
01192       info.byte_order = BFD_ENDIAN_BIG;
01193       info.osabi = GDB_OSABI_LINUX;
01194       info.tdep_info = (void *) &data.id;
01195       data.gdbarch = gdbarch_find_by_info (info);
01196       if (!data.gdbarch)
01197         return 0;
01198 
01199       xsnprintf (annex, sizeof annex, "%d/regs", data.id);
01200       if (target_read (&current_target, TARGET_OBJECT_SPU, annex,
01201                        data.gprs, 0, sizeof data.gprs)
01202           == sizeof data.gprs)
01203         {
01204           struct ppu2spu_cache *cache
01205             = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
01206 
01207           struct address_space *aspace = get_frame_address_space (this_frame);
01208           struct regcache *regcache = regcache_xmalloc (data.gdbarch, aspace);
01209           struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
01210           regcache_save (regcache, ppu2spu_unwind_register, &data);
01211           discard_cleanups (cleanups);
01212 
01213           cache->frame_id = frame_id_build (base, func);
01214           cache->regcache = regcache;
01215           *this_prologue_cache = cache;
01216           return 1;
01217         }
01218     }
01219 
01220   return 0;
01221 }
01222 
01223 static void
01224 ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
01225 {
01226   struct ppu2spu_cache *cache = this_cache;
01227   regcache_xfree (cache->regcache);
01228 }
01229 
01230 static const struct frame_unwind ppu2spu_unwind = {
01231   ARCH_FRAME,
01232   default_frame_unwind_stop_reason,
01233   ppu2spu_this_id,
01234   ppu2spu_prev_register,
01235   NULL,
01236   ppu2spu_sniffer,
01237   ppu2spu_dealloc_cache,
01238   ppu2spu_prev_arch,
01239 };
01240 
01241 
01242 static void
01243 ppc_linux_init_abi (struct gdbarch_info info,
01244                     struct gdbarch *gdbarch)
01245 {
01246   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01247   struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
01248 
01249   linux_init_abi (info, gdbarch);
01250 
01251   /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
01252      128-bit, they are IBM long double, not IEEE quad long double as
01253      in the System V ABI PowerPC Processor Supplement.  We can safely
01254      let them default to 128-bit, since the debug info will give the
01255      size of type actually used in each case.  */
01256   set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
01257   set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
01258 
01259   /* Handle inferior calls during interrupted system calls.  */
01260   set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
01261 
01262   /* Get the syscall number from the arch's register.  */
01263   set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
01264 
01265   /* SystemTap functions.  */
01266   set_gdbarch_stap_integer_prefix (gdbarch, "i");
01267   set_gdbarch_stap_register_indirection_prefix (gdbarch, "(");
01268   set_gdbarch_stap_register_indirection_suffix (gdbarch, ")");
01269   set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
01270   set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
01271   set_gdbarch_stap_parse_special_token (gdbarch,
01272                                         ppc_stap_parse_special_token);
01273 
01274   if (tdep->wordsize == 4)
01275     {
01276       /* Until November 2001, gcc did not comply with the 32 bit SysV
01277          R4 ABI requirement that structures less than or equal to 8
01278          bytes should be returned in registers.  Instead GCC was using
01279          the AIX/PowerOpen ABI - everything returned in memory
01280          (well ignoring vectors that is).  When this was corrected, it
01281          wasn't fixed for GNU/Linux native platform.  Use the
01282          PowerOpen struct convention.  */
01283       set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
01284 
01285       set_gdbarch_memory_remove_breakpoint (gdbarch,
01286                                             ppc_linux_memory_remove_breakpoint);
01287 
01288       /* Shared library handling.  */
01289       set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
01290       set_solib_svr4_fetch_link_map_offsets
01291         (gdbarch, svr4_ilp32_fetch_link_map_offsets);
01292 
01293       /* Setting the correct XML syscall filename.  */
01294       set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC);
01295 
01296       /* Trampolines.  */
01297       tramp_frame_prepend_unwinder (gdbarch,
01298                                     &ppc32_linux_sigaction_tramp_frame);
01299       tramp_frame_prepend_unwinder (gdbarch,
01300                                     &ppc32_linux_sighandler_tramp_frame);
01301 
01302       /* BFD target for core files.  */
01303       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
01304         set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
01305       else
01306         set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
01307 
01308       /* Supported register sections.  */
01309       if (tdesc_find_feature (info.target_desc,
01310                               "org.gnu.gdb.power.vsx"))
01311         set_gdbarch_core_regset_sections (gdbarch,
01312                                           ppc_linux_vsx_regset_sections);
01313       else if (tdesc_find_feature (info.target_desc,
01314                                "org.gnu.gdb.power.altivec"))
01315         set_gdbarch_core_regset_sections (gdbarch,
01316                                           ppc_linux_vmx_regset_sections);
01317       else
01318         set_gdbarch_core_regset_sections (gdbarch,
01319                                           ppc_linux_fp_regset_sections);
01320 
01321       if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
01322         {
01323           powerpc_so_ops = svr4_so_ops;
01324           /* Override dynamic resolve function.  */
01325           powerpc_so_ops.in_dynsym_resolve_code =
01326             powerpc_linux_in_dynsym_resolve_code;
01327         }
01328       set_solib_ops (gdbarch, &powerpc_so_ops);
01329 
01330       set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
01331     }
01332   
01333   if (tdep->wordsize == 8)
01334     {
01335       /* Handle PPC GNU/Linux 64-bit function pointers (which are really
01336          function descriptors).  */
01337       set_gdbarch_convert_from_func_ptr_addr
01338         (gdbarch, ppc64_convert_from_func_ptr_addr);
01339 
01340       set_gdbarch_elf_make_msymbol_special (gdbarch,
01341                                             ppc64_elf_make_msymbol_special);
01342 
01343       /* Shared library handling.  */
01344       set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
01345       set_solib_svr4_fetch_link_map_offsets
01346         (gdbarch, svr4_lp64_fetch_link_map_offsets);
01347 
01348       /* Setting the correct XML syscall filename.  */
01349       set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64);
01350 
01351       /* Trampolines.  */
01352       tramp_frame_prepend_unwinder (gdbarch,
01353                                     &ppc64_linux_sigaction_tramp_frame);
01354       tramp_frame_prepend_unwinder (gdbarch,
01355                                     &ppc64_linux_sighandler_tramp_frame);
01356 
01357       /* BFD target for core files.  */
01358       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
01359         set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
01360       else
01361         set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
01362 
01363       /* Supported register sections.  */
01364       if (tdesc_find_feature (info.target_desc,
01365                               "org.gnu.gdb.power.vsx"))
01366         set_gdbarch_core_regset_sections (gdbarch,
01367                                           ppc64_linux_vsx_regset_sections);
01368       else if (tdesc_find_feature (info.target_desc,
01369                                "org.gnu.gdb.power.altivec"))
01370         set_gdbarch_core_regset_sections (gdbarch,
01371                                           ppc64_linux_vmx_regset_sections);
01372       else
01373         set_gdbarch_core_regset_sections (gdbarch,
01374                                           ppc64_linux_fp_regset_sections);
01375     }
01376 
01377   /* PPC32 uses a different prpsinfo32 compared to most other Linux
01378      archs.  */
01379   if (tdep->wordsize == 4)
01380     set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch,
01381                                               elfcore_write_ppc_linux_prpsinfo32);
01382 
01383   set_gdbarch_regset_from_core_section (gdbarch,
01384                                         ppc_linux_regset_from_core_section);
01385   set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
01386 
01387   /* Enable TLS support.  */
01388   set_gdbarch_fetch_tls_load_module_address (gdbarch,
01389                                              svr4_fetch_objfile_link_map);
01390 
01391   if (tdesc_data)
01392     {
01393       const struct tdesc_feature *feature;
01394 
01395       /* If we have target-described registers, then we can safely
01396          reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
01397          (whether they are described or not).  */
01398       gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
01399       set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
01400 
01401       /* If they are present, then assign them to the reserved number.  */
01402       feature = tdesc_find_feature (info.target_desc,
01403                                     "org.gnu.gdb.power.linux");
01404       if (feature != NULL)
01405         {
01406           tdesc_numbered_register (feature, tdesc_data,
01407                                    PPC_ORIG_R3_REGNUM, "orig_r3");
01408           tdesc_numbered_register (feature, tdesc_data,
01409                                    PPC_TRAP_REGNUM, "trap");
01410         }
01411     }
01412 
01413   /* Enable Cell/B.E. if supported by the target.  */
01414   if (tdesc_compatible_p (info.target_desc,
01415                           bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
01416     {
01417       /* Cell/B.E. multi-architecture support.  */
01418       set_spu_solib_ops (gdbarch);
01419 
01420       /* Cell/B.E. cross-architecture unwinder support.  */
01421       frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
01422 
01423       /* The default displaced_step_at_entry_point doesn't work for
01424          SPU stand-alone executables.  */
01425       set_gdbarch_displaced_step_location (gdbarch,
01426                                            ppc_linux_displaced_step_location);
01427     }
01428 
01429   set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
01430 }
01431 
01432 /* Provide a prototype to silence -Wmissing-prototypes.  */
01433 extern initialize_file_ftype _initialize_ppc_linux_tdep;
01434 
01435 void
01436 _initialize_ppc_linux_tdep (void)
01437 {
01438   /* Register for all sub-familes of the POWER/PowerPC: 32-bit and
01439      64-bit PowerPC, and the older rs6k.  */
01440   gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
01441                          ppc_linux_init_abi);
01442   gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
01443                          ppc_linux_init_abi);
01444   gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
01445                          ppc_linux_init_abi);
01446 
01447   /* Attach to inferior_created observer.  */
01448   observer_attach_inferior_created (ppc_linux_inferior_created);
01449 
01450   /* Attach to observers to track __spe_current_active_context.  */
01451   observer_attach_inferior_created (ppc_linux_spe_context_inferior_created);
01452   observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded);
01453   observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded);
01454 
01455   /* Initialize the Linux target descriptions.  */
01456   initialize_tdesc_powerpc_32l ();
01457   initialize_tdesc_powerpc_altivec32l ();
01458   initialize_tdesc_powerpc_cell32l ();
01459   initialize_tdesc_powerpc_vsx32l ();
01460   initialize_tdesc_powerpc_isa205_32l ();
01461   initialize_tdesc_powerpc_isa205_altivec32l ();
01462   initialize_tdesc_powerpc_isa205_vsx32l ();
01463   initialize_tdesc_powerpc_64l ();
01464   initialize_tdesc_powerpc_altivec64l ();
01465   initialize_tdesc_powerpc_cell64l ();
01466   initialize_tdesc_powerpc_vsx64l ();
01467   initialize_tdesc_powerpc_isa205_64l ();
01468   initialize_tdesc_powerpc_isa205_altivec64l ();
01469   initialize_tdesc_powerpc_isa205_vsx64l ();
01470   initialize_tdesc_powerpc_e500l ();
01471 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines