gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / bfd / cpu-m68k.c
CommitLineData
252b5132 1/* BFD library support routines for architectures.
b3adc24a 2 Copyright (C) 1990-2020 Free Software Foundation, Inc.
252b5132
RH
3 Hacked by Steve Chamberlain of Cygnus Support.
4
3e602632 5 This file is part of BFD, the Binary File Descriptor library.
252b5132 6
3e602632
NC
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
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
3e602632 10 (at your option) any later version.
252b5132 11
3e602632
NC
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.
252b5132 16
3e602632
NC
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
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
252b5132 21
252b5132 22#include "sysdep.h"
3db64b00 23#include "bfd.h"
252b5132 24#include "libbfd.h"
266abb8f 25#include "opcode/m68k.h"
f5c5b7c1 26#include "cpu-m68k.h"
252b5132 27
0b2e31dc
NS
28static const bfd_arch_info_type *
29bfd_m68k_compatible (const bfd_arch_info_type *a,
30 const bfd_arch_info_type *b);
31
252b5132 32#define N(name, print,d,next) \
b7761f11 33{ 32, 32, 8, bfd_arch_m68k, name, "m68k",print,2,d,bfd_m68k_compatible, \
aebcfb76 34 bfd_default_scan, bfd_arch_default_fill, next, 0 }
252b5132
RH
35
36static const bfd_arch_info_type arch_info_struct[] =
3cac17ae 37 {
3e602632
NC
38 N(bfd_mach_m68000, "m68k:68000", FALSE, &arch_info_struct[1]),
39 N(bfd_mach_m68008, "m68k:68008", FALSE, &arch_info_struct[2]),
40 N(bfd_mach_m68010, "m68k:68010", FALSE, &arch_info_struct[3]),
41 N(bfd_mach_m68020, "m68k:68020", FALSE, &arch_info_struct[4]),
42 N(bfd_mach_m68030, "m68k:68030", FALSE, &arch_info_struct[5]),
43 N(bfd_mach_m68040, "m68k:68040", FALSE, &arch_info_struct[6]),
266abb8f
NS
44 N(bfd_mach_m68060, "m68k:68060", FALSE, &arch_info_struct[7]),
45 N(bfd_mach_cpu32, "m68k:cpu32", FALSE, &arch_info_struct[8]),
3bdcfdf4 46 N(bfd_mach_fido, "m68k:fido", FALSE, &arch_info_struct[9]),
266abb8f
NS
47
48 /* Various combinations of CF architecture features */
0b2e31dc 49 N(bfd_mach_mcf_isa_a_nodiv, "m68k:isa-a:nodiv",
266abb8f 50 FALSE, &arch_info_struct[10]),
9840d27e 51 N(bfd_mach_mcf_isa_a, "m68k:isa-a",
266abb8f 52 FALSE, &arch_info_struct[11]),
9840d27e 53 N(bfd_mach_mcf_isa_a_mac, "m68k:isa-a:mac",
266abb8f 54 FALSE, &arch_info_struct[12]),
9840d27e 55 N(bfd_mach_mcf_isa_a_emac, "m68k:isa-a:emac",
266abb8f 56 FALSE, &arch_info_struct[13]),
9840d27e 57 N(bfd_mach_mcf_isa_aplus, "m68k:isa-aplus",
266abb8f 58 FALSE, &arch_info_struct[14]),
9840d27e 59 N(bfd_mach_mcf_isa_aplus_mac, "m68k:isa-aplus:mac",
266abb8f 60 FALSE, &arch_info_struct[15]),
9840d27e 61 N(bfd_mach_mcf_isa_aplus_emac, "m68k:isa-aplus:emac",
266abb8f 62 FALSE, &arch_info_struct[16]),
9840d27e 63 N(bfd_mach_mcf_isa_b_nousp, "m68k:isa-b:nousp",
266abb8f 64 FALSE, &arch_info_struct[17]),
9840d27e 65 N(bfd_mach_mcf_isa_b_nousp_mac, "m68k:isa-b:nousp:mac",
266abb8f 66 FALSE, &arch_info_struct[18]),
9840d27e 67 N(bfd_mach_mcf_isa_b_nousp_emac, "m68k:isa-b:nousp:emac",
266abb8f 68 FALSE, &arch_info_struct[19]),
9840d27e 69 N(bfd_mach_mcf_isa_b, "m68k:isa-b",
266abb8f 70 FALSE, &arch_info_struct[20]),
9840d27e 71 N(bfd_mach_mcf_isa_b_mac, "m68k:isa-b:mac",
266abb8f 72 FALSE, &arch_info_struct[21]),
9840d27e 73 N(bfd_mach_mcf_isa_b_emac, "m68k:isa-b:emac",
266abb8f 74 FALSE, &arch_info_struct[22]),
9840d27e 75 N(bfd_mach_mcf_isa_b_float, "m68k:isa-b:float",
266abb8f 76 FALSE, &arch_info_struct[23]),
9840d27e 77 N(bfd_mach_mcf_isa_b_float_mac, "m68k:isa-b:float:mac",
266abb8f 78 FALSE, &arch_info_struct[24]),
9840d27e
KH
79 N(bfd_mach_mcf_isa_b_float_emac, "m68k:isa-b:float:emac",
80 FALSE, &arch_info_struct[25]),
9a2e615a
NS
81 N(bfd_mach_mcf_isa_c, "m68k:isa-c",
82 FALSE, &arch_info_struct[26]),
83 N(bfd_mach_mcf_isa_c_mac, "m68k:isa-c:mac",
84 FALSE, &arch_info_struct[27]),
85 N(bfd_mach_mcf_isa_c_emac, "m68k:isa-c:emac",
86 FALSE, &arch_info_struct[28]),
8d100c32
KH
87 N(bfd_mach_mcf_isa_c_nodiv, "m68k:isa-c:nodiv",
88 FALSE, &arch_info_struct[29]),
89 N(bfd_mach_mcf_isa_c_nodiv_mac, "m68k:isa-c:nodiv:mac",
90 FALSE, &arch_info_struct[30]),
91 N(bfd_mach_mcf_isa_c_nodiv_emac, "m68k:isa-c:nodiv:emac",
92 FALSE, &arch_info_struct[31]),
266abb8f
NS
93
94 /* Legacy names for CF architectures */
8d100c32
KH
95 N(bfd_mach_mcf_isa_a_nodiv, "m68k:5200", FALSE, &arch_info_struct[32]),
96 N(bfd_mach_mcf_isa_a_mac,"m68k:5206e", FALSE, &arch_info_struct[33]),
97 N(bfd_mach_mcf_isa_a_mac, "m68k:5307", FALSE, &arch_info_struct[34]),
98 N(bfd_mach_mcf_isa_b_nousp_mac, "m68k:5407", FALSE, &arch_info_struct[35]),
99 N(bfd_mach_mcf_isa_aplus_emac, "m68k:528x", FALSE, &arch_info_struct[36]),
100 N(bfd_mach_mcf_isa_aplus_emac, "m68k:521x", FALSE, &arch_info_struct[37]),
101 N(bfd_mach_mcf_isa_a_emac, "m68k:5249", FALSE, &arch_info_struct[38]),
0b2e31dc 102 N(bfd_mach_mcf_isa_b_float_emac, "m68k:547x",
8d100c32 103 FALSE, &arch_info_struct[39]),
9840d27e 104 N(bfd_mach_mcf_isa_b_float_emac, "m68k:548x",
8d100c32 105 FALSE, &arch_info_struct[40]),
0b2e31dc 106 N(bfd_mach_mcf_isa_b_float_emac, "m68k:cfv4e", FALSE, 0),
3cac17ae 107 };
252b5132
RH
108
109const bfd_arch_info_type bfd_m68k_arch =
b34976b6 110 N(0, "m68k", TRUE, &arch_info_struct[0]);
266abb8f
NS
111
112/* Table indexed by bfd_mach_arch number indicating which
113 architectural features are supported. */
68ffbac6 114static const unsigned m68k_arch_features[] =
266abb8f
NS
115{
116 0,
117 m68000|m68881|m68851,
118 m68000|m68881|m68851,
119 m68010|m68881|m68851,
120 m68020|m68881|m68851,
121 m68030|m68881|m68851,
122 m68040|m68881|m68851,
123 m68060|m68881|m68851,
124 cpu32|m68881,
3bdcfdf4 125 fido_a|m68881,
266abb8f
NS
126 mcfisa_a,
127 mcfisa_a|mcfhwdiv,
128 mcfisa_a|mcfhwdiv|mcfmac,
129 mcfisa_a|mcfhwdiv|mcfemac,
266abb8f
NS
130 mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp,
131 mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp|mcfmac,
132 mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp|mcfemac,
133 mcfisa_a|mcfhwdiv|mcfisa_b,
134 mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac,
135 mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac,
0b2e31dc
NS
136 mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp,
137 mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp|mcfmac,
138 mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp|mcfemac,
266abb8f
NS
139 mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp|cfloat,
140 mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp|cfloat|mcfmac,
141 mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp|cfloat|mcfemac,
9a2e615a
NS
142 mcfisa_a|mcfhwdiv|mcfisa_c|mcfusp,
143 mcfisa_a|mcfhwdiv|mcfisa_c|mcfusp|mcfmac,
144 mcfisa_a|mcfhwdiv|mcfisa_c|mcfusp|mcfemac,
8d100c32
KH
145 mcfisa_a|mcfisa_c|mcfusp,
146 mcfisa_a|mcfisa_c|mcfusp|mcfmac,
147 mcfisa_a|mcfisa_c|mcfusp|mcfemac,
266abb8f
NS
148};
149
150/* Return the count of bits set in MASK */
151static unsigned
152bit_count (unsigned mask)
153{
154 unsigned ix;
155
156 for (ix = 0; mask; ix++)
157 /* Clear the LSB set */
158 mask ^= mask & -mask;
159 return ix;
160}
161
162/* Return the architectural features supported by MACH */
163
164unsigned
165bfd_m68k_mach_to_features (int mach)
166{
167 if ((unsigned)mach
168 >= sizeof (m68k_arch_features) / sizeof (m68k_arch_features[0]))
169 mach = 0;
170 return m68k_arch_features[mach];
171}
172
173/* Return the bfd machine that most closely represents the
174 architectural features. We find the machine with the smallest
175 number of additional features. If there is no such machine, we
176 find the one with the smallest number of missing features. */
177
178int bfd_m68k_features_to_mach (unsigned features)
179{
180 int superset = 0, subset = 0;
181 unsigned extra = 99, missing = 99;
182 unsigned ix;
183
184 for (ix = 0;
185 ix != sizeof (m68k_arch_features) / sizeof (m68k_arch_features[0]);
186 ix++)
187 {
188 unsigned this_extra, this_missing;
68ffbac6 189
266abb8f
NS
190 if (m68k_arch_features[ix] == features)
191 return ix;
192 this_extra = bit_count (m68k_arch_features[ix] & ~features);
193 if (this_extra < extra)
194 {
195 extra = this_extra;
196 superset = ix;
197 }
68ffbac6 198
266abb8f
NS
199 this_missing = bit_count (features & ~m68k_arch_features[ix]);
200 if (this_missing < missing)
201 {
202 missing = this_missing;
203 superset = ix;
204 }
205 }
206 return superset ? superset : subset;
207}
0b2e31dc
NS
208
209static const bfd_arch_info_type *
210bfd_m68k_compatible (const bfd_arch_info_type *a,
211 const bfd_arch_info_type *b)
212{
213 if (a->arch != b->arch)
214 return NULL;
215
216 if (a->bits_per_word != b->bits_per_word)
217 return NULL;
218
219 if (!a->mach)
220 return b;
221 if (!b->mach)
222 return a;
68ffbac6 223
0b2e31dc
NS
224 if (a->mach <= bfd_mach_m68060 && b->mach <= bfd_mach_m68060)
225 /* Merge m68k machine. */
226 return a->mach > b->mach ? a : b;
9840d27e 227 else if (a->mach >= bfd_mach_cpu32 && b->mach >= bfd_mach_cpu32)
0b2e31dc 228 {
9840d27e 229 /* Merge the machine features. */
0b2e31dc
NS
230 unsigned features = (bfd_m68k_mach_to_features (a->mach)
231 | bfd_m68k_mach_to_features (b->mach));
0b2e31dc 232
9840d27e
KH
233 /* CPU32 and Coldfire are incompatible. */
234 if ((~features & (cpu32 | mcfisa_a)) == 0)
235 return NULL;
236
3bdcfdf4
KH
237 /* Fido and Coldfire are incompatible. */
238 if ((~features & (fido_a | mcfisa_a)) == 0)
239 return NULL;
240
a9d34880
RS
241 /* ISA A+ and ISA B are incompatible. */
242 if ((~features & (mcfisa_aa | mcfisa_b)) == 0)
243 return NULL;
244
9a2e615a
NS
245 /* ISA B and ISA C are incompatible. */
246 if ((~features & (mcfisa_b | mcfisa_c)) == 0)
247 return NULL;
248
a9d34880
RS
249 /* MAC and EMAC code cannot be merged. */
250 if ((~features & (mcfmac | mcfemac)) == 0)
251 return NULL;
252
3bdcfdf4
KH
253 /* CPU32 is compatible with Fido except that Fido does not
254 support tbl instructions. Warn when the user wants to mix
255 the two. */
256 if ((a->mach == bfd_mach_cpu32 && b->mach == bfd_mach_fido)
257 || (a->mach == bfd_mach_fido && b->mach == bfd_mach_cpu32))
258 {
259 static int cpu32_fido_mix_warning;
260 if (!cpu32_fido_mix_warning)
261 {
262 cpu32_fido_mix_warning = 1;
4eca0228 263 _bfd_error_handler ("warning: linking CPU32 objects with fido objects");
3bdcfdf4
KH
264 }
265 return bfd_lookup_arch (a->arch,
266 bfd_m68k_features_to_mach (fido_a | m68881));
267 }
268
a9d34880 269 return bfd_lookup_arch (a->arch, bfd_m68k_features_to_mach (features));
0b2e31dc
NS
270 }
271 else
272 /* They are incompatible. */
273 return NULL;
274}
This page took 1.092731 seconds and 4 git commands to generate.