1 /* Target-dependent code for Motorola 68000 BSD's.
3 Copyright 2004, 2005 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 gdb_byte *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 gdb_byte *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 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
133 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
136 tdep->jb_elt_size = 4;
138 set_gdbarch_regset_from_core_section
139 (gdbarch, m68kbsd_regset_from_core_section);
142 /* OpenBSD and NetBSD a.out. */
145 m68kbsd_aout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
147 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
149 m68kbsd_init_abi (info, gdbarch);
151 tdep->struct_return = reg_struct_return;
157 m68kbsd_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
159 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
161 m68kbsd_init_abi (info, gdbarch);
163 /* NetBSD ELF uses the SVR4 ABI. */
164 m68k_svr4_init_abi (info, gdbarch);
165 tdep->struct_return = pcc_struct_return;
167 /* NetBSD ELF uses SVR4-style shared libraries. */
168 set_solib_svr4_fetch_link_map_offsets
169 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
173 static enum gdb_osabi
174 m68kbsd_aout_osabi_sniffer (bfd *abfd)
176 if (strcmp (bfd_get_target (abfd), "a.out-m68k-netbsd") == 0
177 || strcmp (bfd_get_target (abfd), "a.out-m68k4k-netbsd") == 0)
178 return GDB_OSABI_NETBSD_AOUT;
180 return GDB_OSABI_UNKNOWN;
183 static enum gdb_osabi
184 m68kbsd_core_osabi_sniffer (bfd *abfd)
186 if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
187 return GDB_OSABI_NETBSD_AOUT;
189 return GDB_OSABI_UNKNOWN;
193 /* Provide a prototype to silence -Wmissing-prototypes. */
194 void _initialize_m68kbsd_tdep (void);
197 _initialize_m68kbsd_tdep (void)
199 gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_aout_flavour,
200 m68kbsd_aout_osabi_sniffer);
202 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
203 gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_unknown_flavour,
204 m68kbsd_core_osabi_sniffer);
206 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD_AOUT,
207 m68kbsd_aout_init_abi);
208 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD_ELF,
209 m68kbsd_elf_init_abi);