]>
Commit | Line | Data |
---|---|---|
ef230218 | 1 | /* BFD library support routines for the Renesas / SuperH SH architecture. |
3db64b00 AM |
2 | Copyright 1993, 1994, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, |
3 | 2007 Free Software Foundation, Inc. | |
252b5132 RH |
4 | Hacked by Steve Chamberlain of Cygnus Support. |
5 | ||
5177500f | 6 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 7 | |
5177500f 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 |
5177500f | 11 | (at your option) any later version. |
252b5132 | 12 | |
5177500f 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 | |
5177500f 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" |
f6f9408f | 26 | #include "../opcodes/sh-opc.h" |
252b5132 | 27 | |
e38bc3b5 NC |
28 | #define SH_NEXT arch_info_struct + 0 |
29 | #define SH2_NEXT arch_info_struct + 1 | |
30 | #define SH2E_NEXT arch_info_struct + 2 | |
31 | #define SH_DSP_NEXT arch_info_struct + 3 | |
32 | #define SH3_NEXT arch_info_struct + 4 | |
33 | #define SH3_NOMMU_NEXT arch_info_struct + 5 | |
34 | #define SH3_DSP_NEXT arch_info_struct + 6 | |
35 | #define SH3E_NEXT arch_info_struct + 7 | |
36 | #define SH4_NEXT arch_info_struct + 8 | |
37 | #define SH4A_NEXT arch_info_struct + 9 | |
38 | #define SH4AL_DSP_NEXT arch_info_struct + 10 | |
39 | #define SH4_NOFPU_NEXT arch_info_struct + 11 | |
40 | #define SH4_NOMMU_NOFPU_NEXT arch_info_struct + 12 | |
41 | #define SH4A_NOFPU_NEXT arch_info_struct + 13 | |
42 | #define SH2A_NEXT arch_info_struct + 14 | |
43 | #define SH2A_NOFPU_NEXT arch_info_struct + 15 | |
44 | #define SH2A_NOFPU_OR_SH4_NOMMU_NOFPU_NEXT arch_info_struct + 16 | |
45 | #define SH2A_NOFPU_OR_SH3_NOMMU_NEXT arch_info_struct + 17 | |
46 | #define SH2A_OR_SH4_NEXT arch_info_struct + 18 | |
47 | #define SH2A_OR_SH3E_NEXT arch_info_struct + 19 | |
48 | #define SH64_NEXT NULL | |
252b5132 | 49 | |
71f6b586 | 50 | static const bfd_arch_info_type arch_info_struct[] = |
252b5132 | 51 | { |
d4845d57 | 52 | { |
e38bc3b5 NC |
53 | 32, /* 32 bits in a word. */ |
54 | 32, /* 32 bits in an address. */ | |
55 | 8, /* 8 bits in a byte. */ | |
d4845d57 JR |
56 | bfd_arch_sh, |
57 | bfd_mach_sh2, | |
e38bc3b5 NC |
58 | "sh", /* Architecture name. */ |
59 | "sh2", /* Machine name. */ | |
d4845d57 | 60 | 1, |
e38bc3b5 | 61 | FALSE, /* Not the default. */ |
d4845d57 | 62 | bfd_default_compatible, |
a44d7f9c | 63 | bfd_default_scan, |
d4845d57 JR |
64 | SH2_NEXT |
65 | }, | |
5177500f | 66 | { |
e38bc3b5 NC |
67 | 32, /* 32 bits in a word. */ |
68 | 32, /* 32 bits in an address. */ | |
69 | 8, /* 8 bits in a byte. */ | |
5177500f NC |
70 | bfd_arch_sh, |
71 | bfd_mach_sh2e, | |
e38bc3b5 NC |
72 | "sh", /* Architecture name. */ |
73 | "sh2e", /* Machine name. */ | |
5177500f | 74 | 1, |
e38bc3b5 | 75 | FALSE, /* Not the default. */ |
5177500f NC |
76 | bfd_default_compatible, |
77 | bfd_default_scan, | |
78 | SH2E_NEXT | |
79 | }, | |
d4845d57 | 80 | { |
e38bc3b5 NC |
81 | 32, /* 32 bits in a word. */ |
82 | 32, /* 32 bits in an address. */ | |
83 | 8, /* 8 bits in a byte. */ | |
d4845d57 JR |
84 | bfd_arch_sh, |
85 | bfd_mach_sh_dsp, | |
e38bc3b5 NC |
86 | "sh", /* Architecture name. */ |
87 | "sh-dsp", /* Machine name. */ | |
d4845d57 | 88 | 1, |
e38bc3b5 | 89 | FALSE, /* Not the default. */ |
d4845d57 | 90 | bfd_default_compatible, |
a44d7f9c | 91 | bfd_default_scan, |
d4845d57 JR |
92 | SH_DSP_NEXT |
93 | }, | |
252b5132 | 94 | { |
e38bc3b5 NC |
95 | 32, /* 32 bits in a word. */ |
96 | 32, /* 32 bits in an address. */ | |
97 | 8, /* 8 bits in a byte. */ | |
252b5132 RH |
98 | bfd_arch_sh, |
99 | bfd_mach_sh3, | |
e38bc3b5 NC |
100 | "sh", /* Architecture name. */ |
101 | "sh3", /* Machine name. */ | |
252b5132 | 102 | 1, |
e38bc3b5 | 103 | FALSE, /* Not the default. */ |
252b5132 | 104 | bfd_default_compatible, |
a44d7f9c | 105 | bfd_default_scan, |
252b5132 RH |
106 | SH3_NEXT |
107 | }, | |
f6f9408f | 108 | { |
e38bc3b5 NC |
109 | 32, /* 32 bits in a word. */ |
110 | 32, /* 32 bits in an address. */ | |
111 | 8, /* 8 bits in a byte. */ | |
f6f9408f JR |
112 | bfd_arch_sh, |
113 | bfd_mach_sh3_nommu, | |
e38bc3b5 NC |
114 | "sh", /* Architecture name. */ |
115 | "sh3-nommu", /* Machine name. */ | |
f6f9408f | 116 | 1, |
e38bc3b5 | 117 | FALSE, /* Not the default. */ |
f6f9408f JR |
118 | bfd_default_compatible, |
119 | bfd_default_scan, | |
120 | SH3_NOMMU_NEXT | |
121 | }, | |
d4845d57 | 122 | { |
e38bc3b5 NC |
123 | 32, /* 32 bits in a word. */ |
124 | 32, /* 32 bits in an address. */ | |
125 | 8, /* 8 bits in a byte. */ | |
d4845d57 JR |
126 | bfd_arch_sh, |
127 | bfd_mach_sh3_dsp, | |
e38bc3b5 NC |
128 | "sh", /* Architecture name. */ |
129 | "sh3-dsp", /* Machine name. */ | |
d4845d57 | 130 | 1, |
e38bc3b5 | 131 | FALSE, /* Not the default. */ |
d4845d57 | 132 | bfd_default_compatible, |
a44d7f9c | 133 | bfd_default_scan, |
d4845d57 JR |
134 | SH3_DSP_NEXT |
135 | }, | |
252b5132 | 136 | { |
e38bc3b5 NC |
137 | 32, /* 32 bits in a word. */ |
138 | 32, /* 32 bits in an address. */ | |
139 | 8, /* 8 bits in a byte. */ | |
252b5132 RH |
140 | bfd_arch_sh, |
141 | bfd_mach_sh3e, | |
e38bc3b5 NC |
142 | "sh", /* Architecture name. */ |
143 | "sh3e", /* Machine name. */ | |
252b5132 | 144 | 1, |
e38bc3b5 | 145 | FALSE, /* Not the default. */ |
252b5132 | 146 | bfd_default_compatible, |
a44d7f9c | 147 | bfd_default_scan, |
252b5132 RH |
148 | SH3E_NEXT |
149 | }, | |
d4845d57 | 150 | { |
e38bc3b5 NC |
151 | 32, /* 32 bits in a word. */ |
152 | 32, /* 32 bits in an address. */ | |
153 | 8, /* 8 bits in a byte. */ | |
d4845d57 JR |
154 | bfd_arch_sh, |
155 | bfd_mach_sh4, | |
e38bc3b5 NC |
156 | "sh", /* Architecture name. */ |
157 | "sh4", /* Machine name. */ | |
d4845d57 | 158 | 1, |
e38bc3b5 | 159 | FALSE, /* Not the default. */ |
d4845d57 | 160 | bfd_default_compatible, |
a44d7f9c | 161 | bfd_default_scan, |
d4845d57 JR |
162 | SH4_NEXT |
163 | }, | |
af9ba621 | 164 | { |
e38bc3b5 NC |
165 | 32, /* 32 bits in a word. */ |
166 | 32, /* 32 bits in an address. */ | |
167 | 8, /* 8 bits in a byte. */ | |
af9ba621 CV |
168 | bfd_arch_sh, |
169 | bfd_mach_sh4a, | |
e38bc3b5 NC |
170 | "sh", /* Architecture name. */ |
171 | "sh4a", /* Machine name. */ | |
af9ba621 | 172 | 1, |
e38bc3b5 | 173 | FALSE, /* Not the default. */ |
af9ba621 CV |
174 | bfd_default_compatible, |
175 | bfd_default_scan, | |
176 | SH4A_NEXT | |
177 | }, | |
178 | { | |
e38bc3b5 NC |
179 | 32, /* 32 bits in a word. */ |
180 | 32, /* 32 bits in an address. */ | |
181 | 8, /* 8 bits in a byte. */ | |
af9ba621 CV |
182 | bfd_arch_sh, |
183 | bfd_mach_sh4al_dsp, | |
e38bc3b5 NC |
184 | "sh", /* Architecture name. */ |
185 | "sh4al-dsp", /* Machine name. */ | |
af9ba621 | 186 | 1, |
e38bc3b5 | 187 | FALSE, /* Not the default. */ |
af9ba621 CV |
188 | bfd_default_compatible, |
189 | bfd_default_scan, | |
190 | SH4AL_DSP_NEXT | |
191 | }, | |
192 | { | |
e38bc3b5 NC |
193 | 32, /* 32 bits in a word. */ |
194 | 32, /* 32 bits in an address. */ | |
195 | 8, /* 8 bits in a byte. */ | |
af9ba621 CV |
196 | bfd_arch_sh, |
197 | bfd_mach_sh4_nofpu, | |
e38bc3b5 NC |
198 | "sh", /* Architecture name. */ |
199 | "sh4-nofpu", /* Machine name. */ | |
af9ba621 | 200 | 1, |
e38bc3b5 | 201 | FALSE, /* Not the default. */ |
af9ba621 CV |
202 | bfd_default_compatible, |
203 | bfd_default_scan, | |
204 | SH4_NOFPU_NEXT | |
205 | }, | |
ae51a426 | 206 | { |
e38bc3b5 NC |
207 | 32, /* 32 bits in a word. */ |
208 | 32, /* 32 bits in an address. */ | |
209 | 8, /* 8 bits in a byte. */ | |
ae51a426 JR |
210 | bfd_arch_sh, |
211 | bfd_mach_sh4_nommu_nofpu, | |
e38bc3b5 NC |
212 | "sh", /* Architecture name. */ |
213 | "sh4-nommu-nofpu", /* Machine name. */ | |
ae51a426 | 214 | 1, |
e38bc3b5 | 215 | FALSE, /* Not the default. */ |
ae51a426 JR |
216 | bfd_default_compatible, |
217 | bfd_default_scan, | |
218 | SH4_NOMMU_NOFPU_NEXT | |
219 | }, | |
af9ba621 | 220 | { |
e38bc3b5 NC |
221 | 32, /* 32 bits in a word. */ |
222 | 32, /* 32 bits in an address. */ | |
223 | 8, /* 8 bits in a byte. */ | |
af9ba621 CV |
224 | bfd_arch_sh, |
225 | bfd_mach_sh4a_nofpu, | |
e38bc3b5 NC |
226 | "sh", /* Architecture name. */ |
227 | "sh4a-nofpu", /* Machine name. */ | |
af9ba621 | 228 | 1, |
e38bc3b5 | 229 | FALSE, /* Not the default. */ |
af9ba621 CV |
230 | bfd_default_compatible, |
231 | bfd_default_scan, | |
232 | SH4A_NOFPU_NEXT | |
233 | }, | |
1d70c7fb AO |
234 | { |
235 | 32, /* 32 bits in a word. */ | |
236 | 32, /* 32 bits in an address. */ | |
237 | 8, /* 8 bits in a byte. */ | |
238 | bfd_arch_sh, | |
239 | bfd_mach_sh2a, | |
e38bc3b5 NC |
240 | "sh", /* Architecture name. */ |
241 | "sh2a", /* Machine name. */ | |
1d70c7fb AO |
242 | 1, |
243 | FALSE, /* Not the default. */ | |
244 | bfd_default_compatible, | |
245 | bfd_default_scan, | |
246 | SH2A_NEXT | |
247 | }, | |
248 | { | |
249 | 32, /* 32 bits in a word. */ | |
250 | 32, /* 32 bits in an address. */ | |
251 | 8, /* 8 bits in a byte. */ | |
252 | bfd_arch_sh, | |
253 | bfd_mach_sh2a_nofpu, | |
e38bc3b5 NC |
254 | "sh", /* Architecture name. */ |
255 | "sh2a-nofpu", /* Machine name. */ | |
1d70c7fb AO |
256 | 1, |
257 | FALSE, /* Not the default. */ | |
258 | bfd_default_compatible, | |
259 | bfd_default_scan, | |
260 | SH2A_NOFPU_NEXT | |
261 | }, | |
fbca6ad9 | 262 | { |
e38bc3b5 NC |
263 | 32, /* 32 bits in a word. */ |
264 | 32, /* 32 bits in an address. */ | |
265 | 8, /* 8 bits in a byte. */ | |
266 | bfd_arch_sh, | |
267 | bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu, | |
268 | "sh", /* Architecture name. */ | |
269 | "sh2a-nofpu-or-sh4-nommu-nofpu", /* Machine name. */ | |
270 | 1, | |
271 | FALSE, /* Not the default. */ | |
272 | bfd_default_compatible, | |
273 | bfd_default_scan, | |
274 | SH2A_NOFPU_OR_SH4_NOMMU_NOFPU_NEXT | |
275 | }, | |
276 | { | |
277 | 32, /* 32 bits in a word. */ | |
278 | 32, /* 32 bits in an address. */ | |
279 | 8, /* 8 bits in a byte. */ | |
280 | bfd_arch_sh, | |
281 | bfd_mach_sh2a_nofpu_or_sh3_nommu, | |
282 | "sh", /* Architecture name. . */ | |
283 | "sh2a-nofpu-or-sh3-nommu", /* Machine name. */ | |
284 | 1, | |
285 | FALSE, /* Not the default. */ | |
286 | bfd_default_compatible, | |
287 | bfd_default_scan, | |
288 | SH2A_NOFPU_OR_SH3_NOMMU_NEXT | |
289 | }, | |
290 | { | |
291 | 32, /* 32 bits in a word. */ | |
292 | 32, /* 32 bits in an address. */ | |
293 | 8, /* 8 bits in a byte. */ | |
294 | bfd_arch_sh, | |
295 | bfd_mach_sh2a_or_sh4, | |
296 | "sh", /* Architecture name. */ | |
297 | "sh2a-or-sh4", /* Machine name. */ | |
298 | 1, | |
299 | FALSE, /* Not the default. */ | |
300 | bfd_default_compatible, | |
301 | bfd_default_scan, | |
302 | SH2A_OR_SH4_NEXT | |
303 | }, | |
304 | { | |
305 | 32, /* 32 bits in a word. */ | |
306 | 32, /* 32 bits in an address. */ | |
307 | 8, /* 8 bits in a byte. */ | |
308 | bfd_arch_sh, | |
309 | bfd_mach_sh2a_or_sh3e, | |
310 | "sh", /* Architecture name. */ | |
311 | "sh2a-or-sh3e", /* Machine name. */ | |
312 | 1, | |
313 | FALSE, /* Not the default. */ | |
314 | bfd_default_compatible, | |
315 | bfd_default_scan, | |
316 | SH2A_OR_SH3E_NEXT | |
317 | }, | |
318 | { | |
319 | 64, /* 64 bits in a word. */ | |
320 | 64, /* 64 bits in an address. */ | |
321 | 8, /* 8 bits in a byte. */ | |
fbca6ad9 AO |
322 | bfd_arch_sh, |
323 | bfd_mach_sh5, | |
e38bc3b5 NC |
324 | "sh", /* Architecture name. */ |
325 | "sh5", /* Machine name. */ | |
fbca6ad9 | 326 | 1, |
e38bc3b5 | 327 | FALSE, /* Not the default. */ |
fbca6ad9 | 328 | bfd_default_compatible, |
a44d7f9c | 329 | bfd_default_scan, |
fbca6ad9 AO |
330 | SH64_NEXT |
331 | }, | |
252b5132 RH |
332 | }; |
333 | ||
334 | const bfd_arch_info_type bfd_sh_arch = | |
335 | { | |
e38bc3b5 NC |
336 | 32, /* 32 bits in a word. */ |
337 | 32, /* 32 bits in an address. */ | |
338 | 8, /* 8 bits in a byte. */ | |
252b5132 RH |
339 | bfd_arch_sh, |
340 | bfd_mach_sh, | |
e38bc3b5 NC |
341 | "sh", /* Architecture name. */ |
342 | "sh", /* Machine name. */ | |
252b5132 | 343 | 1, |
e38bc3b5 | 344 | TRUE, /* The default machine. */ |
252b5132 | 345 | bfd_default_compatible, |
a44d7f9c | 346 | bfd_default_scan, |
252b5132 RH |
347 | SH_NEXT |
348 | }; | |
f6f9408f JR |
349 | |
350 | ||
351 | /* This table defines the mappings from the BFD internal numbering | |
352 | system to the opcodes internal flags system. | |
353 | It is used by the functions defined below. | |
354 | The prototypes for these SH specific functions are found in | |
355 | sh-opc.h . */ | |
356 | ||
357 | static struct { unsigned long bfd_mach, arch, arch_up; } bfd_to_arch_table[] = | |
358 | { | |
e38bc3b5 | 359 | { bfd_mach_sh, arch_sh1, arch_sh_up }, |
f6f9408f JR |
360 | { bfd_mach_sh2, arch_sh2, arch_sh2_up }, |
361 | { bfd_mach_sh2e, arch_sh2e, arch_sh2e_up }, | |
362 | { bfd_mach_sh_dsp, arch_sh_dsp, arch_sh_dsp_up }, | |
1d70c7fb AO |
363 | { bfd_mach_sh2a, arch_sh2a, arch_sh2a_up }, |
364 | { bfd_mach_sh2a_nofpu, arch_sh2a_nofpu, arch_sh2a_nofpu_up }, | |
e38bc3b5 NC |
365 | |
366 | { bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu, arch_sh2a_nofpu_or_sh4_nommu_nofpu, arch_sh2a_nofpu_or_sh4_nommu_nofpu_up }, | |
367 | { bfd_mach_sh2a_nofpu_or_sh3_nommu, arch_sh2a_nofpu_or_sh3_nommu, arch_sh2a_nofpu_or_sh3_nommu_up }, | |
368 | { bfd_mach_sh2a_or_sh4, arch_sh2a_or_sh4, arch_sh2a_or_sh4_up }, | |
369 | { bfd_mach_sh2a_or_sh3e, arch_sh2a_or_sh3e, arch_sh2a_or_sh3e_up }, | |
370 | ||
f6f9408f JR |
371 | { bfd_mach_sh3, arch_sh3, arch_sh3_up }, |
372 | { bfd_mach_sh3_nommu, arch_sh3_nommu, arch_sh3_nommu_up }, | |
373 | { bfd_mach_sh3_dsp, arch_sh3_dsp, arch_sh3_dsp_up }, | |
374 | { bfd_mach_sh3e, arch_sh3e, arch_sh3e_up }, | |
375 | { bfd_mach_sh4, arch_sh4, arch_sh4_up }, | |
376 | { bfd_mach_sh4a, arch_sh4a, arch_sh4a_up }, | |
377 | { bfd_mach_sh4al_dsp, arch_sh4al_dsp, arch_sh4al_dsp_up }, | |
e38bc3b5 | 378 | { bfd_mach_sh4_nofpu, arch_sh4_nofpu, arch_sh4_nofpu_up }, |
f6f9408f | 379 | { bfd_mach_sh4_nommu_nofpu, arch_sh4_nommu_nofpu, arch_sh4_nommu_nofpu_up }, |
e38bc3b5 | 380 | { bfd_mach_sh4a_nofpu, arch_sh4a_nofpu, arch_sh4a_nofpu_up }, |
f6f9408f JR |
381 | { 0, 0, 0 } /* Terminator. */ |
382 | }; | |
383 | ||
384 | ||
385 | /* Convert a BFD mach number into the right opcodes arch flags | |
386 | using the table above. */ | |
387 | ||
388 | unsigned int | |
389 | sh_get_arch_from_bfd_mach (unsigned long mach) | |
390 | { | |
391 | int i = 0; | |
e38bc3b5 | 392 | |
f6f9408f JR |
393 | while (bfd_to_arch_table[i].bfd_mach != 0) |
394 | if (bfd_to_arch_table[i].bfd_mach == mach) | |
395 | return bfd_to_arch_table[i].arch; | |
396 | else | |
397 | i++; | |
398 | ||
e38bc3b5 | 399 | /* Machine not found. */ |
f6f9408f JR |
400 | BFD_FAIL(); |
401 | ||
402 | return SH_ARCH_UNKNOWN_ARCH; | |
403 | } | |
404 | ||
405 | ||
406 | /* Convert a BFD mach number into a set of opcodes arch flags | |
407 | describing all the compatible architectures (i.e. arch_up) | |
408 | using the table above. */ | |
409 | ||
410 | unsigned int | |
411 | sh_get_arch_up_from_bfd_mach (unsigned long mach) | |
412 | { | |
413 | int i = 0; | |
e38bc3b5 | 414 | |
f6f9408f JR |
415 | while (bfd_to_arch_table[i].bfd_mach != 0) |
416 | if (bfd_to_arch_table[i].bfd_mach == mach) | |
417 | return bfd_to_arch_table[i].arch_up; | |
418 | else | |
419 | i++; | |
420 | ||
e38bc3b5 | 421 | /* Machine not found. */ |
f6f9408f JR |
422 | BFD_FAIL(); |
423 | ||
424 | return SH_ARCH_UNKNOWN_ARCH; | |
425 | } | |
426 | ||
427 | ||
428 | /* Convert an arbitary arch_set - not necessarily corresponding | |
429 | directly to anything in the table above - to the most generic | |
430 | architecture which supports all the required features, and | |
431 | return the corresponding BFD mach. */ | |
432 | ||
433 | unsigned long | |
434 | sh_get_bfd_mach_from_arch_set (unsigned int arch_set) | |
435 | { | |
436 | unsigned long result = 0; | |
437 | unsigned int best = ~arch_set; | |
438 | unsigned int co_mask = ~0; | |
439 | int i = 0; | |
440 | ||
441 | /* If arch_set permits variants with no coprocessor then do not allow | |
442 | the other irrelevant co-processor bits to influence the choice: | |
443 | e.g. if dsp is disallowed by arch_set, then the algorithm would | |
444 | prefer fpu variants over nofpu variants because they also disallow | |
445 | dsp - even though the nofpu would be the most correct choice. | |
446 | This assumes that EVERY fpu/dsp variant has a no-coprocessor | |
447 | counter-part, or their non-fpu/dsp instructions do not have the | |
448 | no co-processor bit set. */ | |
449 | if (arch_set & arch_sh_no_co) | |
450 | co_mask = ~(arch_sh_sp_fpu | arch_sh_dp_fpu | arch_sh_has_dsp); | |
451 | ||
452 | while (bfd_to_arch_table[i].bfd_mach != 0) | |
453 | { | |
454 | unsigned int try = bfd_to_arch_table[i].arch_up & co_mask; | |
455 | ||
456 | /* Conceptually: Find the architecture with the least number | |
457 | of extra features or, if they have the same number, then | |
458 | the greatest number of required features. Disregard | |
459 | architectures where the required features alone do | |
460 | not describe a valid architecture. */ | |
461 | if (((try & ~arch_set) < (best & ~arch_set) | |
462 | || ((try & ~arch_set) == (best & ~arch_set) | |
463 | && (~try & arch_set) < (~best & arch_set))) | |
464 | && SH_MERGE_ARCH_SET_VALID (try, arch_set)) | |
465 | { | |
466 | result = bfd_to_arch_table[i].bfd_mach; | |
467 | best = try; | |
468 | } | |
469 | ||
470 | i++; | |
471 | } | |
472 | ||
473 | /* This might happen if a new variant is added to sh-opc.h | |
474 | but no corresponding entry is added to the table above. */ | |
475 | BFD_ASSERT (result != 0); | |
476 | ||
477 | return result; | |
478 | } | |
479 | ||
480 | ||
481 | /* Merge the architecture type of two BFD files, such that the | |
482 | resultant architecture supports all the features required | |
483 | by the two input BFDs. | |
484 | If the input BFDs are multually incompatible - i.e. one uses | |
485 | DSP while the other uses FPU - or there is no known architecture | |
486 | that fits the requirements then an error is emitted. */ | |
487 | ||
488 | bfd_boolean | |
489 | sh_merge_bfd_arch (bfd *ibfd, bfd *obfd) | |
490 | { | |
491 | unsigned int old_arch, new_arch, merged_arch; | |
492 | ||
493 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) | |
494 | return FALSE; | |
495 | ||
496 | old_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (obfd)); | |
497 | new_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (ibfd)); | |
498 | ||
499 | merged_arch = SH_MERGE_ARCH_SET (old_arch, new_arch); | |
500 | ||
501 | if (!SH_VALID_CO_ARCH_SET (merged_arch)) | |
502 | { | |
503 | (*_bfd_error_handler) | |
d003868e AM |
504 | ("%B: uses %s instructions while previous modules use %s instructions", |
505 | ibfd, | |
f6f9408f JR |
506 | SH_ARCH_SET_HAS_DSP (new_arch) ? "dsp" : "floating point", |
507 | SH_ARCH_SET_HAS_DSP (new_arch) ? "floating point" : "dsp"); | |
508 | bfd_set_error (bfd_error_bad_value); | |
509 | return FALSE; | |
510 | } | |
511 | else if (!SH_VALID_ARCH_SET (merged_arch)) | |
512 | { | |
513 | (*_bfd_error_handler) | |
514 | ("internal error: merge of architecture '%s' with architecture '%s' produced unknown architecture\n", | |
515 | bfd_printable_name (obfd), | |
516 | bfd_printable_name (ibfd)); | |
517 | bfd_set_error (bfd_error_bad_value); | |
518 | return FALSE; | |
519 | } | |
520 | ||
521 | bfd_default_set_arch_mach (obfd, bfd_arch_sh, | |
522 | sh_get_bfd_mach_from_arch_set (merged_arch)); | |
523 | ||
524 | return TRUE; | |
525 | } |