--- ./gdb/ppcfbsd-nat.c.orig 2009-09-14 10:22:36.000000000 +0200 +++ ./gdb/ppcfbsd-nat.c 2009-09-14 10:22:36.000000000 +0200 @@ -0,0 +1,159 @@ +/* Native-dependent code for PowerPC's running FreeBSD, for GDB. + Copyright 2002, 2004 Free Software Foundation, Inc. + Contributed by Wasabi Systems, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include +#include + +#include "defs.h" +#include "inferior.h" +#include "inf-ptrace.h" +#include "gdb_assert.h" +#include "gdbcore.h" +#include "regcache.h" + +#include "ppc-tdep.h" +#include "ppcfbsd-tdep.h" + + +static int +getfpregs_supplies (int regno) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); + + /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating + point registers. Traditionally, GDB's register set has still + listed the floating point registers for such machines, so this + code is harmless. However, the new E500 port actually omits the + floating point registers entirely from the register set --- they + don't even have register numbers assigned to them. + + It's not clear to me how best to update this code, so this assert + will alert the first person to encounter the NetBSD/E500 + combination to the problem. */ + gdb_assert (ppc_floating_point_unit_p (current_gdbarch)); + + return ((regno >= tdep->ppc_fp0_regnum + && regno < tdep->ppc_fp0_regnum + ppc_num_fprs) + || regno == tdep->ppc_fpscr_regnum); +} + +static void +ppcfbsd_fetch_inferior_registers (int regno) +{ + struct reg regs; + + if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), + (PTRACE_TYPE_ARG3) ®s, 0) == -1) + perror_with_name (_("Couldn't get registers")); + + ppc_supply_gregset (&ppcfbsd_gregset, current_regcache, regno, + ®s, sizeof regs); + + if (regno == -1 || getfpregs_supplies (regno)) + { + struct fpreg fpregs; + + if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) + perror_with_name (_("Couldn't get FP registers")); + + ppc_supply_fpregset (&ppcfbsd_fpregset, current_regcache, regno, + &fpregs, sizeof fpregs); + } +} + +static void +ppcfbsd_store_inferior_registers (int regno) +{ + struct reg regs; + + if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), + (PTRACE_TYPE_ARG3) ®s, 0) == -1) + perror_with_name (_("Couldn't get registers")); + + ppc_collect_gregset (&ppcfbsd_gregset, current_regcache, + regno, ®s, sizeof regs); + + if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), + (PTRACE_TYPE_ARG3) ®s, 0) == -1) + perror_with_name (_("Couldn't write registers")); + + + if (regno == -1 || getfpregs_supplies (regno)) + { + struct fpreg fpregs; + + if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) + perror_with_name (_("Couldn't get FP registers")); + + ppc_collect_fpregset (&ppcfbsd_fpregset, current_regcache, + regno, &fpregs, sizeof fpregs); + + if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) + perror_with_name (_("Couldn't set FP registers")); + } +} + +/* Provide a prototype to silence -Wmissing-prototypes. */ +void _initialize_ppcfbsd_nat (void); + +void +_initialize_ppcfbsd_nat (void) +{ + struct target_ops *t; + /* Support debugging kernel virtual memory images. */ + /* bsd_kvm_add_target (ppcnbsd_supply_pcb); */ + + /* Add in local overrides. */ + t = inf_ptrace_target (); + t->to_fetch_registers = ppcfbsd_fetch_inferior_registers; + t->to_store_registers = ppcfbsd_store_inferior_registers; + add_target (t); + + /* General-purpose registers. */ + ppcfbsd_reg_offsets.r0_offset = offsetof (struct reg, fixreg); + ppcfbsd_reg_offsets.lr_offset = offsetof (struct reg, lr); + ppcfbsd_reg_offsets.cr_offset = offsetof (struct reg, cr); + /* ppcfbsd_reg_offsets.ps_offset = offsetof (struct reg, ps); */ + ppcfbsd_reg_offsets.xer_offset = offsetof (struct reg, xer); + ppcfbsd_reg_offsets.ctr_offset = offsetof (struct reg, ctr); + ppcfbsd_reg_offsets.pc_offset = offsetof (struct reg, pc); + + /* ppcfbsd_reg_offsets.mq_offset = offsetof (struct reg, mq); */ + + /* Floating-point registers. */ + /* ppcfbsd_reg_offsets.f0_offset = offsetof (struct reg, fpreg); */ + /* ppcfbsd_reg_offsets.fpscr_offset = -1; */ + +#ifdef PT_GETFPREGS + ppcfbsd_fpreg_offsets.f0_offset = offsetof (struct fpreg, fpreg); + ppcfbsd_fpreg_offsets.fpscr_offset = offsetof (struct fpreg, fpscr); +#endif + + /* AltiVec registers. */ + /* ppcfbsd_reg_offsets.vr0_offset = offsetof (struct vreg, vreg); */ + /* ppcfbsd_reg_offsets.vscr_offset = offsetof (struct vreg, vscr); */ + /* ppcfbsd_reg_offsets.vrsave_offset = offsetof (struct vreg, vrsave); */ +} --- ./gdb/ppcfbsd-tdep.h.orig 2009-09-14 10:22:36.000000000 +0200 +++ ./gdb/ppcfbsd-tdep.h 2009-09-14 10:22:36.000000000 +0200 @@ -0,0 +1,37 @@ +/* Common target dependent code for GDB on PowerPC systems running FreeBSD. + Copyright 2002 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef PPCFBSD_TDEP_H +#define PPCFBSD_TDEP_H + +#include + +struct regset; +struct regcache; + +/* Register offsets for FreeBSD/powerpc. */ +extern struct ppc_reg_offsets ppcfbsd_reg_offsets; +extern struct ppc_reg_offsets ppcfbsd_fpreg_offsets; + +/* Register sets for FreeBSD/powerpc. */ +extern struct regset ppcfbsd_gregset; +extern struct regset ppcfbsd_fpregset; + +#endif /* PPCFBSD_TDEP_H */ --- ./gdb/ppcfbsd-tdep.c.orig 2009-09-14 10:22:36.000000000 +0200 +++ ./gdb/ppcfbsd-tdep.c 2009-09-14 10:22:36.000000000 +0200 @@ -0,0 +1,233 @@ +/* Target-dependent code for PowerPC systems running FreeBSD. + + Copyright 2002, 2003, 2004 Free Software Foundation, Inc. + + Contributed by Wasabi Systems, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include "defs.h" +#include "arch-utils.h" +#include "floatformat.h" +#include "frame.h" +#include "trad-frame.h" +#include "osabi.h" +#include "regcache.h" +#include "regset.h" +#include "symtab.h" +#include "frame-unwind.h" +#include "tramp-frame.h" + +#include "gdb_assert.h" +#include "gdb_string.h" + +#include "ppc-tdep.h" +#include "ppcfbsd-tdep.h" +#include "solib-svr4.h" + +/* Register offsets from . */ +struct ppc_reg_offsets ppcfbsd_reg_offsets; +struct ppc_reg_offsets ppcfbsd_fpreg_offsets; + +/* FreeBSD/powerpc register set. */ + +struct regset ppcfbsd_gregset = +{ + &ppcfbsd_reg_offsets, + ppc_supply_gregset +}; + +struct regset ppcfbsd_fpregset = +{ + &ppcfbsd_fpreg_offsets, + ppc_supply_fpregset +}; + +/* Return the appropriate register set for the core section identified + by SECT_NAME and SECT_SIZE. */ + +static const struct regset * +ppcfbsd_regset_from_core_section (struct gdbarch *gdbarch, + const char *sect_name, size_t sect_size) +{ + if (strcmp (sect_name, ".reg") == 0 && sect_size >= 148) + return &ppcfbsd_gregset; + + if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 264) + return &ppcfbsd_fpregset; + + return NULL; +} + +/* Default page size. */ +static const int ppcfbsd_page_size = 2048; + +/* Offset for sigreturn(2). */ +static const int ppcfbsd_sigreturn_offset[] = { + 0x0c, /* FreeBSD */ + -1 +}; + +static int +ppcfbsd_sigtramp_p (struct frame_info *next_frame) +{ + CORE_ADDR pc = frame_pc_unwind (next_frame); + CORE_ADDR start_pc = (pc & ~(ppcfbsd_page_size - 1)); + const int *offset; + char *name; + + find_pc_partial_function (pc, &name, NULL, NULL); + if (name) + return 0; + + for (offset = ppcfbsd_sigreturn_offset; *offset != -1; offset++) + { + gdb_byte buf[2 * PPC_INSN_SIZE]; + unsigned long insn; + + if (!safe_frame_unwind_memory (next_frame, start_pc + *offset, + buf, sizeof buf)) + continue; + + /* Check for "li r0,SYS_sigreturn". */ + insn = extract_unsigned_integer (buf, PPC_INSN_SIZE); + if (insn != 0x380001a1) + continue; + + /* Check for "sc". */ + insn = extract_unsigned_integer (buf + PPC_INSN_SIZE, PPC_INSN_SIZE); + if (insn != 0x44000002) + continue; + + return 1; + } + + return 0; +} + +/* Signal trampolines. */ + +static void +ppcfbsd_sigtramp_cache_init (const struct tramp_frame *self, + struct frame_info *next_frame, + struct trad_frame_cache *this_cache, + CORE_ADDR func) +{ + struct gdbarch *gdbarch = get_frame_arch (next_frame); + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + CORE_ADDR addr, base; + int i; + + base = frame_unwind_register_unsigned (next_frame, SP_REGNUM); + addr = base + 0x10 + 2 * tdep->wordsize; + for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize) + { + int regnum = i + tdep->ppc_gp0_regnum; + trad_frame_set_reg_addr (this_cache, regnum, addr); + } + trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, addr); + addr += tdep->wordsize; + trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, addr); + addr += tdep->wordsize; + trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, addr); + addr += tdep->wordsize; + trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, addr); + addr += tdep->wordsize; + trad_frame_set_reg_addr (this_cache, PC_REGNUM, addr); /* SRR0? */ + addr += tdep->wordsize; + + /* Construct the frame ID using the function start. */ + trad_frame_set_id (this_cache, frame_id_build (base, func)); +} + +static const struct tramp_frame ppcfbsd_sigtramp = +{ + SIGTRAMP_FRAME, + 4, + { + { 0x3821fff0, -1 }, /* add r1,r1,-16 */ + { 0x4e800021, -1 }, /* blrl */ + { 0x38610018, -1 }, /* addi r3,r1,24 */ + { 0x380001a1, -1 }, /* li r0,417 */ + { 0x44000002, -1 }, /* sc */ + { 0x38000001, -1 }, /* li r0,1 */ + { 0x44000002, -1 }, /* sc */ + { TRAMP_SENTINEL_INSN, -1 } + }, + ppcfbsd_sigtramp_cache_init +}; + +static void +ppcfbsd_init_abi (struct gdbarch_info info, + struct gdbarch *gdbarch) +{ + + /* FreeBSD doesn't support the 128-bit `long double' from the psABI. */ + set_gdbarch_long_double_bit (gdbarch, 64); + set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big); + + /* FreeBSD currently uses a broken GCC. */ + set_gdbarch_return_value (gdbarch, ppc_sysv_abi_broken_return_value); + + set_solib_svr4_fetch_link_map_offsets (gdbarch, + svr4_ilp32_fetch_link_map_offsets); + set_gdbarch_regset_from_core_section + (gdbarch, ppcfbsd_regset_from_core_section); + + tramp_frame_prepend_unwinder (gdbarch, &ppcfbsd_sigtramp); + + +} + +/* Provide a prototype to silence -Wmissing-prototypes. */ +void _initialize_ppcfbsd_tdep (void); + +void +_initialize_ppcfbsd_tdep (void) +{ + gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_FREEBSD_ELF, + ppcfbsd_init_abi); + gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_FREEBSD_ELF, + ppcfbsd_init_abi); + + /* Avoid initializing the register offsets again if they were + already initailized by ppcnbsd-nat.c. */ + if (ppcfbsd_reg_offsets.pc_offset == 0) + { + /* General-purpose registers. */ + ppcfbsd_reg_offsets.r0_offset = 0; + ppcfbsd_reg_offsets.lr_offset = 128; + ppcfbsd_reg_offsets.cr_offset = 132; + ppcfbsd_reg_offsets.xer_offset = 136; + ppcfbsd_reg_offsets.ctr_offset = 140; + ppcfbsd_reg_offsets.pc_offset = 144; + ppcfbsd_reg_offsets.ps_offset = -1; + ppcfbsd_reg_offsets.mq_offset = -1; + + if (ppcfbsd_fpreg_offsets.fpscr_offset == 0) + { + /* Floating-point registers. */ + ppcfbsd_reg_offsets.f0_offset = 0; + ppcfbsd_reg_offsets.fpscr_offset = 256; + } + /* AltiVec registers. */ + ppcfbsd_reg_offsets.vr0_offset = -1; + ppcfbsd_reg_offsets.vrsave_offset = -1; + ppcfbsd_reg_offsets.vscr_offset = -1; + } +} --- ./gdb/config/powerpc/nm-fbsd.h.orig 2009-09-14 10:24:03.000000000 +0200 +++ ./gdb/config/powerpc/nm-fbsd.h 2009-09-14 10:24:03.000000000 +0200 @@ -0,0 +1,20 @@ +/* GNU GPL */ + +#ifndef NM_FBSD_H +#define NM_FBSD_H + +/* Type of the third argument to the `ptrace' system call. */ +/* #define PTRACE_ARG3_TYPE caddr_t */ + +/* Override copies of {fetch,store}_inferior_registers in `infptrace.c'. */ +/* #define FETCH_INFERIOR_REGISTERS */ + +/* We can attach and detach. */ +/* #define ATTACH_DETACH */ + +/* Override child_pid_to_exec_file in 'inftarg.c'. */ +/*#define CHILD_PID_TO_EXEC_FILE */ + +#define TEXT_SEGMENT_BASE 0x10000000 + +#endif /* NM_FBSD_H */ --- ./gdb/config/powerpc/fbsd.mh.orig 2009-09-14 10:23:26.000000000 +0200 +++ ./gdb/config/powerpc/fbsd.mh 2009-09-14 10:23:26.000000000 +0200 @@ -0,0 +1,6 @@ +# Host: FreeBSD/powerpc +NATDEPFILES= fork-child.o gcore.o \ + inf-ptrace.o ppcfbsd-nat.o bsd-kvm.o + +NAT_FILE = nm-fbsd.h +LOADLIBES= -lkvm --- ./gdb/config/powerpc/fbsd.mt.orig 2009-09-14 10:23:25.000000000 +0200 +++ ./gdb/config/powerpc/fbsd.mt 2009-09-14 10:23:26.000000000 +0200 @@ -0,0 +1,5 @@ +# Target: FreeBSD/powerpc +TDEPFILES= rs6000-tdep.o ppc-sysv-tdep.o ppcfbsd-tdep.o \ + corelow.o solib.o solib-svr4.o + +TM_FILE= tm-ppc-eabi.h \ No newline at end of file