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