1 /* Target-dependent code for Motorola 68000 BSD's.
3 Copyright 2004 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "arch-utils.h"
28 #include "gdb_assert.h"
29 #include "gdb_string.h"
31 #include "m68k-tdep.h"
32 #include "solib-svr4.h"
34 /* Core file support. */
36 /* Sizeof `struct reg' in <machine/reg.h>. */
37 #define M68KBSD_SIZEOF_GREGS (18 * 4)
39 /* Sizeof `struct fpreg' in <machine/reg.h. */
40 #define M68KBSD_SIZEOF_FPREGS (((8 * 3) + 3) * 4)
43 m68kbsd_fpreg_offset (int regnum)
45 if (regnum >= M68K_FPC_REGNUM)
46 return 8 * 12 + (regnum - M68K_FPC_REGNUM) * 4;
48 return (regnum - M68K_FP0_REGNUM) * 12;
51 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
52 in the floating-point register set REGSET to register cache
53 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
56 m68kbsd_supply_fpregset (const struct regset *regset,
57 struct regcache *regcache,
58 int regnum, const void *fpregs, size_t len)
60 const char *regs = fpregs;
63 gdb_assert (len >= M68KBSD_SIZEOF_FPREGS);
65 for (i = M68K_FP0_REGNUM; i <= M68K_PC_REGNUM; i++)
67 if (regnum == i || regnum == -1)
68 regcache_raw_supply (regcache, i, regs + m68kbsd_fpreg_offset (i));
72 /* Supply register REGNUM from the buffer specified by GREGS and LEN
73 in the general-purpose register set REGSET to register cache
74 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
77 m68kbsd_supply_gregset (const struct regset *regset,
78 struct regcache *regcache,
79 int regnum, const void *gregs, size_t len)
81 const char *regs = gregs;
84 gdb_assert (len >= M68KBSD_SIZEOF_GREGS);
86 for (i = M68K_D0_REGNUM; i <= M68K_PC_REGNUM; i++)
88 if (regnum == i || regnum == -1)
89 regcache_raw_supply (regcache, i, regs + i * 4);
92 if (len >= M68KBSD_SIZEOF_GREGS + M68KBSD_SIZEOF_FPREGS)
94 regs += M68KBSD_SIZEOF_GREGS;
95 len -= M68KBSD_SIZEOF_GREGS;
96 m68kbsd_supply_fpregset (regset, regcache, regnum, regs, len);
100 /* Motorola 68000 register sets. */
102 static struct regset m68kbsd_gregset =
105 m68kbsd_supply_gregset
108 static struct regset m68kbsd_fpregset =
111 m68kbsd_supply_fpregset
114 /* Return the appropriate register set for the core section identified
115 by SECT_NAME and SECT_SIZE. */
117 static const struct regset *
118 m68kbsd_regset_from_core_section (struct gdbarch *gdbarch,
119 const char *sect_name, size_t sect_size)
121 if (strcmp (sect_name, ".reg") == 0 && sect_size >= M68KBSD_SIZEOF_GREGS)
122 return &m68kbsd_gregset;
124 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= M68KBSD_SIZEOF_FPREGS)
125 return &m68kbsd_fpregset;
131 /* Support for shared libraries. */
133 /* Return non-zero if we are in a shared library trampoline code stub. */
136 m68kbsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
138 return (name && !strcmp (name, "_DYNAMIC"));
143 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
145 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
148 tdep->jb_elt_size = 4;
150 set_gdbarch_regset_from_core_section
151 (gdbarch, m68kbsd_regset_from_core_section);
154 /* OpenBSD and NetBSD a.out. */
157 m68kbsd_aout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
159 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
161 m68kbsd_init_abi (info, gdbarch);
163 tdep->struct_return = reg_struct_return;
165 /* Assume SunOS-style shared libraries. */
166 set_gdbarch_in_solib_call_trampoline
167 (gdbarch, m68kbsd_aout_in_solib_call_trampoline);
173 m68kbsd_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
175 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
177 m68kbsd_init_abi (info, gdbarch);
179 /* NetBSD ELF uses the SVR4 ABI. */
180 m68k_svr4_init_abi (info, gdbarch);
181 tdep->struct_return = pcc_struct_return;
183 /* NetBSD ELF uses SVR4-style shared libraries. */
184 set_gdbarch_in_solib_call_trampoline
185 (gdbarch, generic_in_solib_call_trampoline);
186 set_solib_svr4_fetch_link_map_offsets
187 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
191 static enum gdb_osabi
192 m68kbsd_aout_osabi_sniffer (bfd *abfd)
194 if (strcmp (bfd_get_target (abfd), "a.out-m68k-netbsd") == 0
195 || strcmp (bfd_get_target (abfd), "a.out-m68k4k-netbsd") == 0)
196 return GDB_OSABI_NETBSD_AOUT;
198 return GDB_OSABI_UNKNOWN;
201 static enum gdb_osabi
202 m68kbsd_core_osabi_sniffer (bfd *abfd)
204 if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
205 return GDB_OSABI_NETBSD_AOUT;
207 return GDB_OSABI_UNKNOWN;
211 /* Provide a prototype to silence -Wmissing-prototypes. */
212 void _initialize_m68kbsd_tdep (void);
215 _initialize_m68kbsd_tdep (void)
217 gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_aout_flavour,
218 m68kbsd_aout_osabi_sniffer);
220 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
221 gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_unknown_flavour,
222 m68kbsd_core_osabi_sniffer);
224 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD_AOUT,
225 m68kbsd_aout_init_abi);
226 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD_ELF,
227 m68kbsd_elf_init_abi);