/* Target-dependent code for GDB, the GNU debugger.
Copyright (C) 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
- 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
This file is part of GDB.
#include "osabi.h"
#include "regset.h"
#include "solib-svr4.h"
+#include "solib-spu.h"
+#include "solib.h"
+#include "solist.h"
#include "ppc-tdep.h"
#include "ppc-linux-tdep.h"
#include "trad-frame.h"
#include "frame-unwind.h"
#include "tramp-frame.h"
+#include "observer.h"
+#include "auxv.h"
+#include "elf/common.h"
+#include "exceptions.h"
+#include "arch-utils.h"
+#include "spu-tdep.h"
#include "features/rs6000/powerpc-32l.c"
#include "features/rs6000/powerpc-altivec32l.c"
+#include "features/rs6000/powerpc-cell32l.c"
+#include "features/rs6000/powerpc-vsx32l.c"
+#include "features/rs6000/powerpc-isa205-32l.c"
+#include "features/rs6000/powerpc-isa205-altivec32l.c"
+#include "features/rs6000/powerpc-isa205-vsx32l.c"
#include "features/rs6000/powerpc-64l.c"
#include "features/rs6000/powerpc-altivec64l.c"
+#include "features/rs6000/powerpc-cell64l.c"
+#include "features/rs6000/powerpc-vsx64l.c"
+#include "features/rs6000/powerpc-isa205-64l.c"
+#include "features/rs6000/powerpc-isa205-altivec64l.c"
+#include "features/rs6000/powerpc-isa205-vsx64l.c"
#include "features/rs6000/powerpc-e500l.c"
else in the event that some other platform has similar needs with
regard to removing breakpoints in some potentially self modifying
code. */
-int
+static int
ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
struct bp_target_info *bp_tgt)
{
/* If DESC is the address of a 64-bit PowerPC GNU/Linux function
descriptor, return the descriptor's entry point. */
static CORE_ADDR
-ppc64_desc_entry_point (CORE_ADDR desc)
+ppc64_desc_entry_point (struct gdbarch *gdbarch, CORE_ADDR desc)
{
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* The first word of the descriptor is the entry point. */
- return (CORE_ADDR) read_memory_unsigned_integer (desc, 8);
+ return (CORE_ADDR) read_memory_unsigned_integer (desc, 8, byte_order);
}
/* Pattern for the standard linkage function. These are built by
build_plt_stub in elf64-ppc.c, whose GLINK argument is always
zero. */
-static struct insn_pattern ppc64_standard_linkage[] =
+static struct insn_pattern ppc64_standard_linkage1[] =
{
/* addis r12, r2, <any> */
{ insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
/* addis r12, r12, 1 <optional> */
- { insn_d (-1, -1, -1, -1), insn_d (15, 12, 2, 1), 1 },
+ { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },
/* ld r2, <any>(r12) */
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
/* addis r12, r12, 1 <optional> */
- { insn_d (-1, -1, -1, -1), insn_d (15, 12, 2, 1), 1 },
+ { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },
+
+ /* mtctr r11 */
+ { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
+
+ /* ld r11, <any>(r12) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
+
+ /* bctr */
+ { -1, 0x4e800420, 0 },
+
+ { 0, 0, 0 }
+ };
+#define PPC64_STANDARD_LINKAGE1_LEN \
+ (sizeof (ppc64_standard_linkage1) / sizeof (ppc64_standard_linkage1[0]))
+
+static struct insn_pattern ppc64_standard_linkage2[] =
+ {
+ /* addis r12, r2, <any> */
+ { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
+
+ /* std r2, 40(r1) */
+ { -1, insn_ds (62, 2, 1, 40, 0), 0 },
+
+ /* ld r11, <any>(r12) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
+
+ /* addi r12, r12, <any> <optional> */
+ { insn_d (-1, -1, -1, 0), insn_d (14, 12, 12, 0), 1 },
/* mtctr r11 */
- { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467),
- 0 },
+ { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
+
+ /* ld r2, <any>(r12) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
/* ld r11, <any>(r12) */
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
{ 0, 0, 0 }
};
-#define PPC64_STANDARD_LINKAGE_LEN \
- (sizeof (ppc64_standard_linkage) / sizeof (ppc64_standard_linkage[0]))
+#define PPC64_STANDARD_LINKAGE2_LEN \
+ (sizeof (ppc64_standard_linkage2) / sizeof (ppc64_standard_linkage2[0]))
+
+static struct insn_pattern ppc64_standard_linkage3[] =
+ {
+ /* std r2, 40(r1) */
+ { -1, insn_ds (62, 2, 1, 40, 0), 0 },
+
+ /* ld r11, <any>(r2) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
+
+ /* addi r2, r2, <any> <optional> */
+ { insn_d (-1, -1, -1, 0), insn_d (14, 2, 2, 0), 1 },
+
+ /* mtctr r11 */
+ { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
+
+ /* ld r11, <any>(r2) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
+
+ /* ld r2, <any>(r2) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },
+
+ /* bctr */
+ { -1, 0x4e800420, 0 },
+
+ { 0, 0, 0 }
+ };
+#define PPC64_STANDARD_LINKAGE3_LEN \
+ (sizeof (ppc64_standard_linkage3) / sizeof (ppc64_standard_linkage3[0]))
+
/* When the dynamic linker is doing lazy symbol resolution, the first
call to a function in another object will go like this:
standard linkage function will send them. (This doesn't deal with
dynamic linker lazy symbol resolution stubs.) */
static CORE_ADDR
-ppc64_standard_linkage_target (struct frame_info *frame,
- CORE_ADDR pc, unsigned int *insn)
+ppc64_standard_linkage1_target (struct frame_info *frame,
+ CORE_ADDR pc, unsigned int *insn)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (frame));
+ struct gdbarch *gdbarch = get_frame_arch (frame);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
/* The address of the function descriptor this linkage function
references. */
+ insn_ds_field (insn[2]));
/* The first word of the descriptor is the entry point. Return that. */
- return ppc64_desc_entry_point (desc);
+ return ppc64_desc_entry_point (gdbarch, desc);
+}
+
+static struct core_regset_section ppc_linux_vsx_regset_sections[] =
+{
+ { ".reg", 268 },
+ { ".reg2", 264 },
+ { ".reg-ppc-vmx", 544 },
+ { ".reg-ppc-vsx", 256 },
+ { NULL, 0}
+};
+
+static struct core_regset_section ppc_linux_vmx_regset_sections[] =
+{
+ { ".reg", 268 },
+ { ".reg2", 264 },
+ { ".reg-ppc-vmx", 544 },
+ { NULL, 0}
+};
+
+static struct core_regset_section ppc_linux_fp_regset_sections[] =
+{
+ { ".reg", 268 },
+ { ".reg2", 264 },
+ { NULL, 0}
+};
+
+static CORE_ADDR
+ppc64_standard_linkage2_target (struct frame_info *frame,
+ CORE_ADDR pc, unsigned int *insn)
+{
+ struct gdbarch *gdbarch = get_frame_arch (frame);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+ /* The address of the function descriptor this linkage function
+ references. */
+ CORE_ADDR desc
+ = ((CORE_ADDR) get_frame_register_unsigned (frame,
+ tdep->ppc_gp0_regnum + 2)
+ + (insn_d_field (insn[0]) << 16)
+ + insn_ds_field (insn[2]));
+
+ /* The first word of the descriptor is the entry point. Return that. */
+ return ppc64_desc_entry_point (gdbarch, desc);
+}
+
+static CORE_ADDR
+ppc64_standard_linkage3_target (struct frame_info *frame,
+ CORE_ADDR pc, unsigned int *insn)
+{
+ struct gdbarch *gdbarch = get_frame_arch (frame);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+ /* The address of the function descriptor this linkage function
+ references. */
+ CORE_ADDR desc
+ = ((CORE_ADDR) get_frame_register_unsigned (frame,
+ tdep->ppc_gp0_regnum + 2)
+ + insn_ds_field (insn[1]));
+
+ /* The first word of the descriptor is the entry point. Return that. */
+ return ppc64_desc_entry_point (gdbarch, desc);
}
static CORE_ADDR
ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
{
- unsigned int ppc64_standard_linkage_insn[PPC64_STANDARD_LINKAGE_LEN];
-
- if (insns_match_pattern (pc, ppc64_standard_linkage,
- ppc64_standard_linkage_insn))
- return ppc64_standard_linkage_target (frame, pc,
- ppc64_standard_linkage_insn);
+ unsigned int ppc64_standard_linkage1_insn[PPC64_STANDARD_LINKAGE1_LEN];
+ unsigned int ppc64_standard_linkage2_insn[PPC64_STANDARD_LINKAGE2_LEN];
+ unsigned int ppc64_standard_linkage3_insn[PPC64_STANDARD_LINKAGE3_LEN];
+ CORE_ADDR target;
+
+ if (insns_match_pattern (pc, ppc64_standard_linkage1,
+ ppc64_standard_linkage1_insn))
+ pc = ppc64_standard_linkage1_target (frame, pc,
+ ppc64_standard_linkage1_insn);
+ else if (insns_match_pattern (pc, ppc64_standard_linkage2,
+ ppc64_standard_linkage2_insn))
+ pc = ppc64_standard_linkage2_target (frame, pc,
+ ppc64_standard_linkage2_insn);
+ else if (insns_match_pattern (pc, ppc64_standard_linkage3,
+ ppc64_standard_linkage3_insn))
+ pc = ppc64_standard_linkage3_target (frame, pc,
+ ppc64_standard_linkage3_insn);
else
return 0;
+
+ /* The PLT descriptor will either point to the already resolved target
+ address, or else to a glink stub. As the latter carry synthetic @plt
+ symbols, find_solib_trampoline_target should be able to resolve them. */
+ target = find_solib_trampoline_target (frame, pc);
+ return target? target : pc;
}
CORE_ADDR addr,
struct target_ops *targ)
{
- struct section_table *s = target_section_by_addr (targ, addr);
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ struct target_section *s = target_section_by_addr (targ, addr);
/* Check if ADDR points to a function descriptor. */
if (s && strcmp (s->the_bfd_section->name, ".opd") == 0)
- return get_target_memory_unsigned (targ, addr, 8);
+ {
+ /* There may be relocations that need to be applied to the .opd
+ section. Unfortunately, this function may be called at a time
+ where these relocations have not yet been performed -- this can
+ happen for example shortly after a library has been loaded with
+ dlopen, but ld.so has not yet applied the relocations.
+
+ To cope with both the case where the relocation has been applied,
+ and the case where it has not yet been applied, we do *not* read
+ the (maybe) relocated value from target memory, but we instead
+ read the non-relocated value from the BFD, and apply the relocation
+ offset manually.
+
+ This makes the assumption that all .opd entries are always relocated
+ by the same offset the section itself was relocated. This should
+ always be the case for GNU/Linux executables and shared libraries.
+ Note that other kind of object files (e.g. those added via
+ add-symbol-files) will currently never end up here anyway, as this
+ function accesses *target* sections only; only the main exec and
+ shared libraries are ever added to the target. */
+
+ gdb_byte buf[8];
+ int res;
+
+ res = bfd_get_section_contents (s->bfd, s->the_bfd_section,
+ &buf, addr - s->addr, 8);
+ if (res != 0)
+ return extract_unsigned_integer (buf, 8, byte_order)
+ - bfd_section_vma (s->bfd, s->the_bfd_section) + s->addr;
+ }
return addr;
}
NULL
};
+static const struct regset ppc32_linux_vsxregset = {
+ &ppc32_linux_reg_offsets,
+ ppc_supply_vsxregset,
+ ppc_collect_vsxregset,
+ NULL
+};
+
const struct regset *
ppc_linux_gregset (int wordsize)
{
return &ppc32_linux_fpregset;
if (strcmp (sect_name, ".reg-ppc-vmx") == 0)
return &ppc32_linux_vrregset;
+ if (strcmp (sect_name, ".reg-ppc-vsx") == 0)
+ return &ppc32_linux_vsxregset;
return NULL;
}
int i;
struct gdbarch *gdbarch = get_frame_arch (this_frame);
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
base = get_frame_register_unsigned (this_frame,
gdbarch_sp_regnum (gdbarch));
regs = base + offset;
/* Use that to find the address of the corresponding register
buffers. */
- gpregs = read_memory_unsigned_integer (regs, tdep->wordsize);
+ gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
fpregs = gpregs + 48 * tdep->wordsize;
/* General purpose. */
};
+/* Address to use for displaced stepping. When debugging a stand-alone
+ SPU executable, entry_point_address () will point to an SPU local-store
+ address and is thus not usable as displaced stepping location. We use
+ the auxiliary vector to determine the PowerPC-side entry point address
+ instead. */
+
+static CORE_ADDR ppc_linux_entry_point_addr = 0;
+
+static void
+ppc_linux_inferior_created (struct target_ops *target, int from_tty)
+{
+ ppc_linux_entry_point_addr = 0;
+}
+
+static CORE_ADDR
+ppc_linux_displaced_step_location (struct gdbarch *gdbarch)
+{
+ if (ppc_linux_entry_point_addr == 0)
+ {
+ CORE_ADDR addr;
+
+ /* Determine entry point from target auxiliary vector. */
+ if (target_auxv_search (¤t_target, AT_ENTRY, &addr) <= 0)
+ error (_("Cannot find AT_ENTRY auxiliary vector entry."));
+
+ /* Make certain that the address points at real code, and not a
+ function descriptor. */
+ addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
+ ¤t_target);
+
+ /* Inferior calls also use the entry point as a breakpoint location.
+ We don't want displaced stepping to interfere with those
+ breakpoints, so leave space. */
+ ppc_linux_entry_point_addr = addr + 2 * PPC_INSN_SIZE;
+ }
+
+ return ppc_linux_entry_point_addr;
+}
+
+
/* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
int
ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
}
+static int
+ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
+{
+ return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
+}
+
static const struct target_desc *
ppc_linux_core_read_description (struct gdbarch *gdbarch,
struct target_ops *target,
bfd *abfd)
{
+ asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
+ asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
asection *section = bfd_get_section_by_name (abfd, ".reg");
if (! section)
return NULL;
switch (bfd_section_size (abfd, section))
{
case 48 * 4:
- return altivec? tdesc_powerpc_altivec32l : tdesc_powerpc_32l;
+ if (cell)
+ return tdesc_powerpc_cell32l;
+ else if (vsx)
+ return tdesc_powerpc_vsx32l;
+ else if (altivec)
+ return tdesc_powerpc_altivec32l;
+ else
+ return tdesc_powerpc_32l;
case 48 * 8:
- return altivec? tdesc_powerpc_altivec64l : tdesc_powerpc_64l;
+ if (cell)
+ return tdesc_powerpc_cell64l;
+ else if (vsx)
+ return tdesc_powerpc_vsx64l;
+ else if (altivec)
+ return tdesc_powerpc_altivec64l;
+ else
+ return tdesc_powerpc_64l;
default:
return NULL;
}
}
+
+/* Cell/B.E. active SPE context tracking support. */
+
+static struct objfile *spe_context_objfile = NULL;
+static CORE_ADDR spe_context_lm_addr = 0;
+static CORE_ADDR spe_context_offset = 0;
+
+static ptid_t spe_context_cache_ptid;
+static CORE_ADDR spe_context_cache_address;
+
+/* Hook into inferior_created, solib_loaded, and solib_unloaded observers
+ to track whether we've loaded a version of libspe2 (as static or dynamic
+ library) that provides the __spe_current_active_context variable. */
+static void
+ppc_linux_spe_context_lookup (struct objfile *objfile)
+{
+ struct minimal_symbol *sym;
+
+ if (!objfile)
+ {
+ spe_context_objfile = NULL;
+ spe_context_lm_addr = 0;
+ spe_context_offset = 0;
+ spe_context_cache_ptid = minus_one_ptid;
+ spe_context_cache_address = 0;
+ return;
+ }
+
+ sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile);
+ if (sym)
+ {
+ spe_context_objfile = objfile;
+ spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile);
+ spe_context_offset = SYMBOL_VALUE_ADDRESS (sym);
+ spe_context_cache_ptid = minus_one_ptid;
+ spe_context_cache_address = 0;
+ return;
+ }
+}
+
+static void
+ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
+{
+ struct objfile *objfile;
+
+ ppc_linux_spe_context_lookup (NULL);
+ ALL_OBJFILES (objfile)
+ ppc_linux_spe_context_lookup (objfile);
+}
+
+static void
+ppc_linux_spe_context_solib_loaded (struct so_list *so)
+{
+ if (strstr (so->so_original_name, "/libspe") != NULL)
+ {
+ solib_read_symbols (so, so->from_tty ? SYMFILE_VERBOSE : 0);
+ ppc_linux_spe_context_lookup (so->objfile);
+ }
+}
+
+static void
+ppc_linux_spe_context_solib_unloaded (struct so_list *so)
+{
+ if (so->objfile == spe_context_objfile)
+ ppc_linux_spe_context_lookup (NULL);
+}
+
+/* Retrieve contents of the N'th element in the current thread's
+ linked SPE context list into ID and NPC. Return the address of
+ said context element, or 0 if not found. */
+static CORE_ADDR
+ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
+ int n, int *id, unsigned int *npc)
+{
+ CORE_ADDR spe_context = 0;
+ gdb_byte buf[16];
+ int i;
+
+ /* Quick exit if we have not found __spe_current_active_context. */
+ if (!spe_context_objfile)
+ return 0;
+
+ /* Look up cached address of thread-local variable. */
+ if (!ptid_equal (spe_context_cache_ptid, inferior_ptid))
+ {
+ struct target_ops *target = ¤t_target;
+ volatile struct gdb_exception ex;
+
+ while (target && !target->to_get_thread_local_address)
+ target = find_target_beneath (target);
+ if (!target)
+ return 0;
+
+ TRY_CATCH (ex, RETURN_MASK_ERROR)
+ {
+ /* We do not call target_translate_tls_address here, because
+ svr4_fetch_objfile_link_map may invalidate the frame chain,
+ which must not do while inside a frame sniffer.
+
+ Instead, we have cached the lm_addr value, and use that to
+ directly call the target's to_get_thread_local_address. */
+ spe_context_cache_address
+ = target->to_get_thread_local_address (target, inferior_ptid,
+ spe_context_lm_addr,
+ spe_context_offset);
+ spe_context_cache_ptid = inferior_ptid;
+ }
+
+ if (ex.reason < 0)
+ return 0;
+ }
+
+ /* Read variable value. */
+ if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0)
+ spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
+
+ /* Cyle through to N'th linked list element. */
+ for (i = 0; i < n && spe_context; i++)
+ if (target_read_memory (spe_context + align_up (12, wordsize),
+ buf, wordsize) == 0)
+ spe_context = extract_unsigned_integer (buf, wordsize, byte_order);
+ else
+ spe_context = 0;
+
+ /* Read current context. */
+ if (spe_context
+ && target_read_memory (spe_context, buf, 12) != 0)
+ spe_context = 0;
+
+ /* Extract data elements. */
+ if (spe_context)
+ {
+ if (id)
+ *id = extract_signed_integer (buf, 4, byte_order);
+ if (npc)
+ *npc = extract_unsigned_integer (buf + 4, 4, byte_order);
+ }
+
+ return spe_context;
+}
+
+
+/* Cell/B.E. cross-architecture unwinder support. */
+
+struct ppu2spu_cache
+{
+ struct frame_id frame_id;
+ struct regcache *regcache;
+};
+
+static struct gdbarch *
+ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache)
+{
+ struct ppu2spu_cache *cache = *this_cache;
+ return get_regcache_arch (cache->regcache);
+}
+
+static void
+ppu2spu_this_id (struct frame_info *this_frame,
+ void **this_cache, struct frame_id *this_id)
+{
+ struct ppu2spu_cache *cache = *this_cache;
+ *this_id = cache->frame_id;
+}
+
+static struct value *
+ppu2spu_prev_register (struct frame_info *this_frame,
+ void **this_cache, int regnum)
+{
+ struct ppu2spu_cache *cache = *this_cache;
+ struct gdbarch *gdbarch = get_regcache_arch (cache->regcache);
+ gdb_byte *buf;
+
+ buf = alloca (register_size (gdbarch, regnum));
+ regcache_cooked_read (cache->regcache, regnum, buf);
+ return frame_unwind_got_bytes (this_frame, regnum, buf);
+}
+
+struct ppu2spu_data
+{
+ struct gdbarch *gdbarch;
+ int id;
+ unsigned int npc;
+ gdb_byte gprs[128*16];
+};
+
+static int
+ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf)
+{
+ struct ppu2spu_data *data = src;
+ enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch);
+
+ if (regnum >= 0 && regnum < SPU_NUM_GPRS)
+ memcpy (buf, data->gprs + 16*regnum, 16);
+ else if (regnum == SPU_ID_REGNUM)
+ store_unsigned_integer (buf, 4, byte_order, data->id);
+ else if (regnum == SPU_PC_REGNUM)
+ store_unsigned_integer (buf, 4, byte_order, data->npc);
+ else
+ return 0;
+
+ return 1;
+}
+
+static int
+ppu2spu_sniffer (const struct frame_unwind *self,
+ struct frame_info *this_frame, void **this_prologue_cache)
+{
+ struct gdbarch *gdbarch = get_frame_arch (this_frame);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ struct ppu2spu_data data;
+ struct frame_info *fi;
+ CORE_ADDR base, func, backchain, spe_context;
+ gdb_byte buf[8];
+ int n = 0;
+
+ /* Count the number of SPU contexts already in the frame chain. */
+ for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
+ if (get_frame_type (fi) == ARCH_FRAME
+ && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu)
+ n++;
+
+ base = get_frame_sp (this_frame);
+ func = get_frame_pc (this_frame);
+ if (target_read_memory (base, buf, tdep->wordsize))
+ return 0;
+ backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order);
+
+ spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order,
+ n, &data.id, &data.npc);
+ if (spe_context && base <= spe_context && spe_context < backchain)
+ {
+ char annex[32];
+
+ /* Find gdbarch for SPU. */
+ struct gdbarch_info info;
+ gdbarch_info_init (&info);
+ info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
+ info.byte_order = BFD_ENDIAN_BIG;
+ info.osabi = GDB_OSABI_LINUX;
+ info.tdep_info = (void *) &data.id;
+ data.gdbarch = gdbarch_find_by_info (info);
+ if (!data.gdbarch)
+ return 0;
+
+ xsnprintf (annex, sizeof annex, "%d/regs", data.id);
+ if (target_read (¤t_target, TARGET_OBJECT_SPU, annex,
+ data.gprs, 0, sizeof data.gprs)
+ == sizeof data.gprs)
+ {
+ struct ppu2spu_cache *cache
+ = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache);
+
+ struct regcache *regcache = regcache_xmalloc (data.gdbarch);
+ struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
+ regcache_save (regcache, ppu2spu_unwind_register, &data);
+ discard_cleanups (cleanups);
+
+ cache->frame_id = frame_id_build (base, func);
+ cache->regcache = regcache;
+ *this_prologue_cache = cache;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static void
+ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache)
+{
+ struct ppu2spu_cache *cache = this_cache;
+ regcache_xfree (cache->regcache);
+}
+
+static const struct frame_unwind ppu2spu_unwind = {
+ ARCH_FRAME,
+ ppu2spu_this_id,
+ ppu2spu_prev_register,
+ NULL,
+ ppu2spu_sniffer,
+ ppu2spu_dealloc_cache,
+ ppu2spu_prev_arch,
+};
+
+
static void
ppc_linux_init_abi (struct gdbarch_info info,
struct gdbarch *gdbarch)
/* Trampolines. */
tramp_frame_prepend_unwinder (gdbarch, &ppc32_linux_sigaction_tramp_frame);
tramp_frame_prepend_unwinder (gdbarch, &ppc32_linux_sighandler_tramp_frame);
+
+ /* BFD target for core files. */
+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
+ set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
+ else
+ set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
}
if (tdep->wordsize == 8)
/* Trampolines. */
tramp_frame_prepend_unwinder (gdbarch, &ppc64_linux_sigaction_tramp_frame);
tramp_frame_prepend_unwinder (gdbarch, &ppc64_linux_sighandler_tramp_frame);
+
+ /* BFD target for core files. */
+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
+ set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
+ else
+ set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
}
set_gdbarch_regset_from_core_section (gdbarch, ppc_linux_regset_from_core_section);
set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
+ /* Supported register sections. */
+ if (tdesc_find_feature (info.target_desc,
+ "org.gnu.gdb.power.vsx"))
+ set_gdbarch_core_regset_sections (gdbarch, ppc_linux_vsx_regset_sections);
+ else if (tdesc_find_feature (info.target_desc,
+ "org.gnu.gdb.power.altivec"))
+ set_gdbarch_core_regset_sections (gdbarch, ppc_linux_vmx_regset_sections);
+ else
+ set_gdbarch_core_regset_sections (gdbarch, ppc_linux_fp_regset_sections);
+
/* Enable TLS support. */
set_gdbarch_fetch_tls_load_module_address (gdbarch,
svr4_fetch_objfile_link_map);
PPC_TRAP_REGNUM, "trap");
}
}
+
+ /* Enable Cell/B.E. if supported by the target. */
+ if (tdesc_compatible_p (info.target_desc,
+ bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu)))
+ {
+ /* Cell/B.E. multi-architecture support. */
+ set_spu_solib_ops (gdbarch);
+
+ /* Cell/B.E. cross-architecture unwinder support. */
+ frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind);
+
+ /* The default displaced_step_at_entry_point doesn't work for
+ SPU stand-alone executables. */
+ set_gdbarch_displaced_step_location (gdbarch,
+ ppc_linux_displaced_step_location);
+ }
}
+/* Provide a prototype to silence -Wmissing-prototypes. */
+extern initialize_file_ftype _initialize_ppc_linux_tdep;
+
void
_initialize_ppc_linux_tdep (void)
{
gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
ppc_linux_init_abi);
+ /* Attach to inferior_created observer. */
+ observer_attach_inferior_created (ppc_linux_inferior_created);
+
+ /* Attach to observers to track __spe_current_active_context. */
+ observer_attach_inferior_created (ppc_linux_spe_context_inferior_created);
+ observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded);
+ observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded);
+
/* Initialize the Linux target descriptions. */
initialize_tdesc_powerpc_32l ();
initialize_tdesc_powerpc_altivec32l ();
+ initialize_tdesc_powerpc_cell32l ();
+ initialize_tdesc_powerpc_vsx32l ();
+ initialize_tdesc_powerpc_isa205_32l ();
+ initialize_tdesc_powerpc_isa205_altivec32l ();
+ initialize_tdesc_powerpc_isa205_vsx32l ();
initialize_tdesc_powerpc_64l ();
initialize_tdesc_powerpc_altivec64l ();
+ initialize_tdesc_powerpc_cell64l ();
+ initialize_tdesc_powerpc_vsx64l ();
+ initialize_tdesc_powerpc_isa205_64l ();
+ initialize_tdesc_powerpc_isa205_altivec64l ();
+ initialize_tdesc_powerpc_isa205_vsx64l ();
initialize_tdesc_powerpc_e500l ();
}