gdb, testsuite: Fix return value in gdb.base/foll-fork.exp
[binutils-gdb.git] / gdb / m68k-bsd-tdep.c
blobfaec4713143a329e7b5a7a73bb53c753faad855b
1 /* Target-dependent code for Motorola 68000 BSD's.
3 Copyright (C) 2004-2024 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 3 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, see <http://www.gnu.org/licenses/>. */
20 #include "arch-utils.h"
21 #include "frame.h"
22 #include "osabi.h"
23 #include "regcache.h"
24 #include "regset.h"
25 #include "trad-frame.h"
26 #include "tramp-frame.h"
27 #include "gdbtypes.h"
29 #include "m68k-tdep.h"
30 #include "solib-svr4.h"
32 /* Core file support. */
34 /* Sizeof `struct reg' in <machine/reg.h>. */
35 #define M68KBSD_SIZEOF_GREGS (18 * 4)
37 /* Sizeof `struct fpreg' in <machine/reg.h. */
38 #define M68KBSD_SIZEOF_FPREGS (((8 * 3) + 3) * 4)
40 int
41 m68kbsd_fpreg_offset (struct gdbarch *gdbarch, int regnum)
43 int fp_len = gdbarch_register_type (gdbarch, regnum)->length ();
45 if (regnum >= M68K_FPC_REGNUM)
46 return 8 * fp_len + (regnum - M68K_FPC_REGNUM) * 4;
48 return (regnum - M68K_FP0_REGNUM) * fp_len;
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. */
55 static void
56 m68kbsd_supply_fpregset (const struct regset *regset,
57 struct regcache *regcache,
58 int regnum, const void *fpregs, size_t len)
60 struct gdbarch *gdbarch = regcache->arch ();
61 const gdb_byte *regs = (const gdb_byte *) fpregs;
62 int i;
64 gdb_assert (len >= M68KBSD_SIZEOF_FPREGS);
66 for (i = M68K_FP0_REGNUM; i <= M68K_PC_REGNUM; i++)
68 if (regnum == i || regnum == -1)
69 regcache->raw_supply (i, regs + m68kbsd_fpreg_offset (gdbarch, i));
73 /* Supply register REGNUM from the buffer specified by GREGS and LEN
74 in the general-purpose register set REGSET to register cache
75 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
77 static void
78 m68kbsd_supply_gregset (const struct regset *regset,
79 struct regcache *regcache,
80 int regnum, const void *gregs, size_t len)
82 const gdb_byte *regs = (const gdb_byte *) gregs;
83 int i;
85 gdb_assert (len >= M68KBSD_SIZEOF_GREGS);
87 for (i = M68K_D0_REGNUM; i <= M68K_PC_REGNUM; i++)
89 if (regnum == i || regnum == -1)
90 regcache->raw_supply (i, regs + i * 4);
93 if (len >= M68KBSD_SIZEOF_GREGS + M68KBSD_SIZEOF_FPREGS)
95 regs += M68KBSD_SIZEOF_GREGS;
96 len -= M68KBSD_SIZEOF_GREGS;
97 m68kbsd_supply_fpregset (regset, regcache, regnum, regs, len);
101 /* Motorola 68000 register sets. */
103 static const struct regset m68kbsd_gregset =
105 NULL,
106 m68kbsd_supply_gregset,
107 NULL,
108 REGSET_VARIABLE_SIZE
111 static const struct regset m68kbsd_fpregset =
113 NULL,
114 m68kbsd_supply_fpregset
117 /* Iterate over core file register note sections. */
119 static void
120 m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
121 iterate_over_regset_sections_cb *cb,
122 void *cb_data,
123 const struct regcache *regcache)
125 cb (".reg", M68KBSD_SIZEOF_GREGS, M68KBSD_SIZEOF_GREGS, &m68kbsd_gregset,
126 NULL, cb_data);
127 cb (".reg2", M68KBSD_SIZEOF_FPREGS, M68KBSD_SIZEOF_FPREGS, &m68kbsd_fpregset,
128 NULL, cb_data);
132 static void
133 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
135 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
137 tdep->jb_pc = 5;
138 tdep->jb_elt_size = 4;
140 set_gdbarch_decr_pc_after_break (gdbarch, 2);
142 set_gdbarch_iterate_over_regset_sections
143 (gdbarch, m68kbsd_iterate_over_regset_sections);
145 /* NetBSD ELF uses the SVR4 ABI. */
146 m68k_svr4_init_abi (info, gdbarch);
147 tdep->struct_return = pcc_struct_return;
149 /* NetBSD ELF uses SVR4-style shared libraries. */
150 set_solib_svr4_fetch_link_map_offsets
151 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
154 void _initialize_m68kbsd_tdep ();
155 void
156 _initialize_m68kbsd_tdep ()
158 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD,
159 m68kbsd_init_abi);