From 8f2d3ea0006e69b704208e27f31171c135a6e473 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Fri, 30 Apr 2004 23:28:52 +0000 Subject: [PATCH] Add OpenBSD/m68k support. * NEWS (New native configurations): Mention OpenBSD/m68k. * m68kbsd-tdep.c: New file. * m68kbsd-nat.c: New file. * Makefile.in (ALLDEPFILES): Add m68kbsd-nat.c and m68kbsd-tdep.c. (m68kbsd-nat.o, m68kbsd-tdep.o): New dependencies. * configure.host: Add m68k-*-openbsd. * configure.tgt: Add m68k-*-openbsd. * config/m68k/tm-obsd.h: New file. * config/m68k/obsd.mt: New file. * config/m68k/obsd.mh: New file. * config/djgpp/fnchange.lst: Add entries for m68kbsd-nat.c and m68kbsd-tdep.c. --- gdb/ChangeLog | 16 +++ gdb/Makefile.in | 6 + gdb/NEWS | 1 + gdb/config/djgpp/fnchange.lst | 2 + gdb/config/m68k/obsd.mh | 4 + gdb/config/m68k/obsd.mt | 3 + gdb/config/m68k/tm-obsd.h | 27 ++++ gdb/configure.host | 1 + gdb/configure.tgt | 1 + gdb/m68kbsd-nat.c | 170 +++++++++++++++++++++++++ gdb/m68kbsd-tdep.c | 226 ++++++++++++++++++++++++++++++++++ 11 files changed, 457 insertions(+) create mode 100644 gdb/config/m68k/obsd.mh create mode 100644 gdb/config/m68k/obsd.mt create mode 100644 gdb/config/m68k/tm-obsd.h create mode 100644 gdb/m68kbsd-nat.c create mode 100644 gdb/m68kbsd-tdep.c diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3a2f2d5acfd..a164857a436 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,19 @@ +2004-05-01 Mark Kettenis + + Add OpenBSD/m68k support. + * NEWS (New native configurations): Mention OpenBSD/m68k. + * m68kbsd-tdep.c: New file. + * m68kbsd-nat.c: New file. + * Makefile.in (ALLDEPFILES): Add m68kbsd-nat.c and m68kbsd-tdep.c. + (m68kbsd-nat.o, m68kbsd-tdep.o): New dependencies. + * configure.host: Add m68k-*-openbsd. + * configure.tgt: Add m68k-*-openbsd. + * config/m68k/tm-obsd.h: New file. + * config/m68k/obsd.mt: New file. + * config/m68k/obsd.mh: New file. + * config/djgpp/fnchange.lst: Add entries for m68kbsd-nat.c and + m68kbsd-tdep.c. + 2004-04-30 Andrew Cagney * mipsnbsd-tdep.c (mipsnbsd_pc_in_sigtramp): Delete function. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 0262409f5b7..b4fd7281eb1 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1340,6 +1340,7 @@ ALLDEPFILES = \ lynx-nat.c m3-nat.c \ m68hc11-tdep.c \ m68k-tdep.c \ + m68kbsd-nat.c m68kbsd-tdep.c \ mcore-tdep.c \ mips-linux-nat.c mips-linux-tdep.c \ mips-nat.c \ @@ -2017,6 +2018,11 @@ m68klinux-tdep.o: m68klinux-tdep.c $(defs_h) $(gdbcore_h) $(doublest_h) \ $(floatformat_h) $(frame_h) $(target_h) $(gdb_string_h) \ $(gdbtypes_h) $(osabi_h) $(regcache_h) $(objfiles_h) $(symtab_h) \ $(m68k_tdep_h) +m68kbsd-nat.o: m68kbsd-nat.c $(defs_h) $(inferior_h) $(regcache_h) \ + $(gdb_assert_h) $(m68k_tdep_h) +m68kbsd-tdep.o: m68kbsd-tdep.c $(defs_h) $(arch_utils_h) $(osabi_h) \ + $(regcache_h) $(regset_h) $(gdb_assert_h) $(gdb_string_h) \ + $(m68k_tdep_h) $(solib_svr4_h) m68knbsd-nat.o: m68knbsd-nat.c $(defs_h) $(inferior_h) $(gdbcore_h) \ $(regcache_h) m68knbsd-tdep.o: m68knbsd-tdep.c $(defs_h) $(gdbtypes_h) $(regcache_h) diff --git a/gdb/NEWS b/gdb/NEWS index 546b67c2a96..a858668a880 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -16,6 +16,7 @@ systems (Solaris, IRIX). Ref: server/519. * New native configurations +OpenBSD/m68k m68k-*-openbsd* OpenBSD/powerpc powerpc-*-openbsd* NetBSD/vax vax-*-netbsd* OpenBSD/vax vax-*-openbsd* diff --git a/gdb/config/djgpp/fnchange.lst b/gdb/config/djgpp/fnchange.lst index 4950a63be9b..6ab5c7e6220 100644 --- a/gdb/config/djgpp/fnchange.lst +++ b/gdb/config/djgpp/fnchange.lst @@ -141,6 +141,8 @@ @V@/gdb/m2-exp.tab.c @V@/gdb/m2-exp_tab.c @V@/gdb/m68klinux-nat.c @V@/gdb/m68kl-nat.c @V@/gdb/m68klinux-tdep.c @V@/gdb/m68kl-tdep.c +@V@/gdb/m68kbsd-nat.c @V@/gdb/m68bsd-nat.c +@V@/gdb/m68kbsd-tdep.c @V@/gdb/m68bsd-tdep.c @V@/gdb/m68knbsd-nat.c @V@/gdb/m6nbsd-nat.c @V@/gdb/m68knbsd-tdep.c @V@/gdb/m6nbsd-tdep.c @V@/gdb/mips-linux-nat.c @V@/gdb/mipslnxnat.c diff --git a/gdb/config/m68k/obsd.mh b/gdb/config/m68k/obsd.mh new file mode 100644 index 00000000000..e1885387080 --- /dev/null +++ b/gdb/config/m68k/obsd.mh @@ -0,0 +1,4 @@ +# Host: OpenBSD/m68k +NATDEPFILES= m68kbsd-nat.o fork-child.o infptrace.o inftarg.o \ + solib.o solib-sunos.o +NAT_FILE= nm-nbsdaout.h diff --git a/gdb/config/m68k/obsd.mt b/gdb/config/m68k/obsd.mt new file mode 100644 index 00000000000..7021c7f60ce --- /dev/null +++ b/gdb/config/m68k/obsd.mt @@ -0,0 +1,3 @@ +# Target: OpenBSD/m68k +TDEPFILES= m68k-tdep.o m68kbsd-tdep.o corelow.o solib.o solib-svr4.o +TM_FILE= tm-obsd.h diff --git a/gdb/config/m68k/tm-obsd.h b/gdb/config/m68k/tm-obsd.h new file mode 100644 index 00000000000..993b49ed69c --- /dev/null +++ b/gdb/config/m68k/tm-obsd.h @@ -0,0 +1,27 @@ +/* Target-dependent definitions for OpenBSD/m68k. + + Copyright 2004 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 TM_OBSD_H +#define TM_OBSD_H + +#include "solib.h" + +#endif /* tm-obsd.h */ diff --git a/gdb/configure.host b/gdb/configure.host index 8839dc4395a..831e7861afe 100644 --- a/gdb/configure.host +++ b/gdb/configure.host @@ -85,6 +85,7 @@ ia64-*-linux*) gdb_host=linux ;; m68*-*-linux*) gdb_host=linux ;; m68*-*-netbsd*) gdb_host=nbsdaout ;; +m68*-*-openbsd*) gdb_host=obsd ;; mips-sgi-irix5*) gdb_host=irix5 ;; mips-sgi-irix6*) gdb_host=irix6 ;; diff --git a/gdb/configure.tgt b/gdb/configure.tgt index 646b2588f25..5e6e85e0455 100644 --- a/gdb/configure.tgt +++ b/gdb/configure.tgt @@ -114,6 +114,7 @@ m68*-*-linux*) gdb_target=linux build_gdbserver=yes ;; m68*-*-netbsd*) gdb_target=nbsdaout ;; +m68*-*-openbsd*) gdb_target=obsd ;; m68*-*-os68k*) gdb_target=os68k ;; m68*-*-uclinux*) gdb_target=monitor ;; m68*-*-vxworks*) gdb_target=vxworks68 ;; diff --git a/gdb/m68kbsd-nat.c b/gdb/m68kbsd-nat.c new file mode 100644 index 00000000000..a53707cf0ef --- /dev/null +++ b/gdb/m68kbsd-nat.c @@ -0,0 +1,170 @@ +/* Native-dependent code for Motorola 68000 BSD's. + + Copyright 2004 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. */ + +#include "defs.h" +#include "inferior.h" +#include "regcache.h" + +#include "gdb_assert.h" +#include +#include +#include + +#include "m68k-tdep.h" + +static int +m68kbsd_gregset_supplies_p (int regnum) +{ + return (regnum >= M68K_D0_REGNUM && regnum <= M68K_PC_REGNUM); +} + +static int +m68kbsd_fpregset_supplies_p (int regnum) +{ + return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM); +} + +/* Supply the general-purpose registers stored in GREGS to REGCACHE. */ + +static void +m68kbsd_supply_gregset (struct regcache *regcache, const void *gregs) +{ + const char *regs = gregs; + int regnum; + + for (regnum = M68K_D0_REGNUM; regnum <= M68K_PC_REGNUM; regnum++) + regcache_raw_supply (regcache, regnum, regs + regnum * 4); +} + +/* Supply the floating-point registers stored in FPREGS to REGCACHE. */ + +static void +m68kbsd_supply_fpregset (struct regcache *regcache, const void *fpregs) +{ + const char *regs = fpregs; + int regnum; + + for (regnum = M68K_FP0_REGNUM; regnum <= M68K_FPI_REGNUM; regnum++) + regcache_raw_supply (regcache, regnum, + regs + m68kbsd_fpreg_offset (regnum)); +} + +/* Collect the general-purpose registers from REGCACHE and store them + in GREGS. */ + +static void +m68kbsd_collect_gregset (const struct regcache *regcache, + void *gregs, int regnum) +{ + char *regs = gregs; + int i; + + for (i = M68K_D0_REGNUM; i <= M68K_PC_REGNUM; i++) + { + if (regnum == -1 || regnum == i) + regcache_raw_collect (regcache, regnum, regs + i * 4); + } +} + +/* Collect the floating-point registers from REGCACHE and store them + in FPREGS. */ + +static void +m68kbsd_collect_fpregset (struct regcache *regcache, + void *fpregs, int regnum) +{ + char *regs = fpregs; + int i; + + for (i = M68K_FP0_REGNUM; i <= M68K_FPI_REGNUM; i++) + { + if (regnum == -1 || regnum == i) + regcache_raw_collect (regcache, regnum, + regs + m68kbsd_fpreg_offset (i)); + } +} + + +/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this + for all registers (including the floating-point registers). */ + +void +fetch_inferior_registers (int regnum) +{ + if (regnum == -1 || m68kbsd_gregset_supplies_p (regnum)) + { + struct reg regs; + + if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), + (PTRACE_ARG3_TYPE) ®s, 0) == -1) + perror_with_name ("Couldn't get registers"); + + m68kbsd_supply_gregset (current_regcache, ®s); + } + + if (regnum == -1 || m68kbsd_fpregset_supplies_p (regnum)) + { + struct fpreg fpregs; + + if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), + (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) + perror_with_name ("Couldn't get floating point status"); + + m68kbsd_supply_fpregset (current_regcache, &fpregs); + } +} + +/* Store register REGNUM back into the inferior. If REGNUM is -1, do + this for all registers (including the floating-point registers). */ + +void +store_inferior_registers (int regnum) +{ + if (regnum == -1 || m68kbsd_gregset_supplies_p (regnum)) + { + struct reg regs; + + if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), + (PTRACE_ARG3_TYPE) ®s, 0) == -1) + perror_with_name ("Couldn't get registers"); + + m68kbsd_collect_gregset (current_regcache, ®s, regnum); + + if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), + (PTRACE_ARG3_TYPE) ®s, 0) == -1) + perror_with_name ("Couldn't write registers"); + } + + if (regnum == -1 || m68kbsd_fpregset_supplies_p (regnum)) + { + struct fpreg fpregs; + + if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), + (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) + perror_with_name ("Couldn't get floating point status"); + + m68kbsd_collect_fpregset (current_regcache, &fpregs, regnum); + + if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), + (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) + perror_with_name ("Couldn't write floating point status"); + } +} diff --git a/gdb/m68kbsd-tdep.c b/gdb/m68kbsd-tdep.c new file mode 100644 index 00000000000..a9a5b4e564f --- /dev/null +++ b/gdb/m68kbsd-tdep.c @@ -0,0 +1,226 @@ +/* Target-dependent code for Motorola 68000 BSD's. + + Copyright 2004 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. */ + +#include "defs.h" +#include "arch-utils.h" +#include "osabi.h" +#include "regcache.h" +#include "regset.h" + +#include "gdb_assert.h" +#include "gdb_string.h" + +#include "m68k-tdep.h" +#include "solib-svr4.h" + +/* Core file support. */ + +/* Sizeof `struct reg' in . */ +#define M68KBSD_SIZEOF_GREGS (18 * 4) + +/* Sizeof `struct fpreg' in = M68K_FPC_REGNUM) + return 8 * 12 + (regnum - M68K_FPC_REGNUM) * 4; + + return (regnum - M68K_FP0_REGNUM) * 12; +} + +/* Supply register REGNUM from the buffer specified by FPREGS and LEN + in the floating-point register set REGSET to register cache + REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ + +static void +m68kbsd_supply_fpregset (const struct regset *regset, + struct regcache *regcache, + int regnum, const void *fpregs, size_t len) +{ + const char *regs = fpregs; + int i; + + gdb_assert (len >= M68KBSD_SIZEOF_FPREGS); + + for (i = M68K_FP0_REGNUM; i <= M68K_PC_REGNUM; i++) + { + if (regnum == i || regnum == -1) + regcache_raw_supply (regcache, i, regs + m68kbsd_fpreg_offset (i)); + } +} + +/* Supply register REGNUM from the buffer specified by GREGS and LEN + in the general-purpose register set REGSET to register cache + REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ + +static void +m68kbsd_supply_gregset (const struct regset *regset, + struct regcache *regcache, + int regnum, const void *gregs, size_t len) +{ + const char *regs = gregs; + int i; + + gdb_assert (len >= M68KBSD_SIZEOF_GREGS); + + for (i = M68K_D0_REGNUM; i <= M68K_PC_REGNUM; i++) + { + if (regnum == i || regnum == -1) + regcache_raw_supply (regcache, i, regs + i * 4); + } + + if (len >= M68KBSD_SIZEOF_GREGS + M68KBSD_SIZEOF_FPREGS) + { + regs += M68KBSD_SIZEOF_GREGS; + len -= M68KBSD_SIZEOF_GREGS; + m68kbsd_supply_fpregset (regset, regcache, regnum, regs, len); + } +} + +/* Motorola 68000 register sets. */ + +static struct regset m68kbsd_gregset = +{ + NULL, + m68kbsd_supply_gregset +}; + +static struct regset m68kbsd_fpregset = +{ + NULL, + m68kbsd_supply_fpregset +}; + +/* Return the appropriate register set for the core section identified + by SECT_NAME and SECT_SIZE. */ + +static const struct regset * +m68kbsd_regset_from_core_section (struct gdbarch *gdbarch, + const char *sect_name, size_t sect_size) +{ + if (strcmp (sect_name, ".reg") == 0 && sect_size >= M68KBSD_SIZEOF_GREGS) + return &m68kbsd_gregset; + + if (strcmp (sect_name, ".reg2") == 0 && sect_size >= M68KBSD_SIZEOF_FPREGS) + return &m68kbsd_fpregset; + + return NULL; +} + + +/* Support for shared libraries. */ + +/* Return non-zero if we are in a shared library trampoline code stub. */ + +int +m68kbsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name) +{ + return (name && !strcmp (name, "_DYNAMIC")); +} + + +static void +m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + tdep->jb_pc = 5; + tdep->jb_elt_size = 4; + + set_gdbarch_regset_from_core_section + (gdbarch, m68kbsd_regset_from_core_section); +} + +/* OpenBSD and NetBSD a.out. */ + +static void +m68kbsd_aout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + m68kbsd_init_abi (info, gdbarch); + + tdep->struct_return = reg_struct_return; + + /* Assume SunOS-style shared libraries. */ + set_gdbarch_in_solib_call_trampoline + (gdbarch, m68kbsd_aout_in_solib_call_trampoline); +} + +/* NetBSD ELF. */ + +static void +m68kbsd_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + m68kbsd_init_abi (info, gdbarch); + + tdep->struct_return = pcc_struct_return; + + /* NetBSD ELF uses SVR4-style shared libraries. */ + set_gdbarch_in_solib_call_trampoline + (gdbarch, generic_in_solib_call_trampoline); + set_solib_svr4_fetch_link_map_offsets + (gdbarch, svr4_ilp32_fetch_link_map_offsets); +} + + +static enum gdb_osabi +m68kbsd_aout_osabi_sniffer (bfd *abfd) +{ + if (strcmp (bfd_get_target (abfd), "a.out-m68k-netbsd") == 0 + || strcmp (bfd_get_target (abfd), "a.out-m68k4k-netbsd") == 0) + return GDB_OSABI_NETBSD_AOUT; + + return GDB_OSABI_UNKNOWN; +} + +static enum gdb_osabi +m68kbsd_core_osabi_sniffer (bfd *abfd) +{ + if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0) + return GDB_OSABI_NETBSD_AOUT; + + return GDB_OSABI_UNKNOWN; +} + + +/* Provide a prototype to silence -Wmissing-prototypes. */ +void _initialize_m68kbsd_tdep (void); + +void +_initialize_m68kbsd_tdep (void) +{ + gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_aout_flavour, + m68kbsd_aout_osabi_sniffer); + + /* BFD doesn't set a flavour for NetBSD style a.out core files. */ + gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_unknown_flavour, + m68kbsd_core_osabi_sniffer); + + gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD_AOUT, + m68kbsd_aout_init_abi); + gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD_ELF, + m68kbsd_elf_init_abi); +} -- 2.30.2