1 /* Target-dependent code for Motorola 68000 BSD's. 2 3 Copyright (C) 2004-2023 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 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. 11 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. 16 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/>. */ 19 20 #include "defs.h" 21 #include "arch-utils.h" 22 #include "frame.h" 23 #include "osabi.h" 24 #include "regcache.h" 25 #include "regset.h" 26 #include "trad-frame.h" 27 #include "tramp-frame.h" 28 #include "gdbtypes.h" 29 30 #include "m68k-tdep.h" 31 #include "netbsd-tdep.h" 32 #include "solib-svr4.h" 33 34 /* Core file support. */ 35 36 /* Sizeof `struct reg' in <machine/reg.h>. */ 37 #define M68KBSD_SIZEOF_GREGS (18 * 4) 38 39 /* Sizeof `struct fpreg' in <machine/reg.h. */ 40 #define M68KBSD_SIZEOF_FPREGS (((8 * 3) + 3) * 4) 41 42 int 43 m68kbsd_fpreg_offset (struct gdbarch *gdbarch, int regnum) 44 { 45 int fp_len = gdbarch_register_type (gdbarch, regnum)->length (); 46 47 if (regnum >= M68K_FPC_REGNUM) 48 return 8 * fp_len + (regnum - M68K_FPC_REGNUM) * 4; 49 50 return (regnum - M68K_FP0_REGNUM) * fp_len; 51 } 52 53 /* Supply register REGNUM from the buffer specified by FPREGS and LEN 54 in the floating-point register set REGSET to register cache 55 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 56 57 static void 58 m68kbsd_supply_fpregset (const struct regset *regset, 59 struct regcache *regcache, 60 int regnum, const void *fpregs, size_t len) 61 { 62 struct gdbarch *gdbarch = regcache->arch (); 63 const gdb_byte *regs = (const gdb_byte *) fpregs; 64 int i; 65 66 gdb_assert (len >= M68KBSD_SIZEOF_FPREGS); 67 68 for (i = M68K_FP0_REGNUM; i <= M68K_PC_REGNUM; i++) 69 { 70 if (regnum == i || regnum == -1) 71 regcache->raw_supply (i, regs + m68kbsd_fpreg_offset (gdbarch, i)); 72 } 73 } 74 75 /* Supply register REGNUM from the buffer specified by GREGS and LEN 76 in the general-purpose register set REGSET to register cache 77 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 78 79 static void 80 m68kbsd_supply_gregset (const struct regset *regset, 81 struct regcache *regcache, 82 int regnum, const void *gregs, size_t len) 83 { 84 const gdb_byte *regs = (const gdb_byte *) gregs; 85 int i; 86 87 gdb_assert (len >= M68KBSD_SIZEOF_GREGS); 88 89 for (i = M68K_D0_REGNUM; i <= M68K_PC_REGNUM; i++) 90 { 91 if (regnum == i || regnum == -1) 92 regcache->raw_supply (i, regs + i * 4); 93 } 94 95 if (len >= M68KBSD_SIZEOF_GREGS + M68KBSD_SIZEOF_FPREGS) 96 { 97 regs += M68KBSD_SIZEOF_GREGS; 98 len -= M68KBSD_SIZEOF_GREGS; 99 m68kbsd_supply_fpregset (regset, regcache, regnum, regs, len); 100 } 101 } 102 103 /* Motorola 68000 register sets. */ 104 105 static const struct regset m68kbsd_gregset = 106 { 107 NULL, 108 m68kbsd_supply_gregset, 109 NULL, 110 REGSET_VARIABLE_SIZE 111 }; 112 113 static const struct regset m68kbsd_fpregset = 114 { 115 NULL, 116 m68kbsd_supply_fpregset 117 }; 118 119 /* Iterate over core file register note sections. */ 120 121 static void 122 m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, 123 iterate_over_regset_sections_cb *cb, 124 void *cb_data, 125 const struct regcache *regcache) 126 { 127 cb (".reg", M68KBSD_SIZEOF_GREGS, M68KBSD_SIZEOF_GREGS, &m68kbsd_gregset, 128 NULL, cb_data); 129 cb (".reg2", M68KBSD_SIZEOF_FPREGS, M68KBSD_SIZEOF_FPREGS, &m68kbsd_fpregset, 130 NULL, cb_data); 131 } 132 133 134 static void 135 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 136 { 137 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch); 138 139 nbsd_init_abi (info, gdbarch); 140 141 tdep->jb_pc = 5; 142 tdep->jb_elt_size = 4; 143 144 set_gdbarch_decr_pc_after_break (gdbarch, 2); 145 146 set_gdbarch_iterate_over_regset_sections 147 (gdbarch, m68kbsd_iterate_over_regset_sections); 148 149 /* NetBSD ELF uses the SVR4 ABI. */ 150 m68k_svr4_init_abi (info, gdbarch); 151 tdep->struct_return = pcc_struct_return; 152 153 /* NetBSD ELF uses SVR4-style shared libraries. */ 154 set_solib_svr4_fetch_link_map_offsets 155 (gdbarch, svr4_ilp32_fetch_link_map_offsets); 156 } 157 158 void _initialize_m68kbsd_tdep (); 159 void 160 _initialize_m68kbsd_tdep () 161 { 162 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD, 163 m68kbsd_init_abi); 164 } 165