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