1 /* BFD library support routines for the Renesas / SuperH SH architecture.
2 Copyright 1993, 1994, 1997, 1998, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Hacked by Steve Chamberlain of Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "../opcodes/sh-opc.h"
27 #define SH_NEXT &arch_info_struct[0]
28 #define SH2_NEXT &arch_info_struct[1]
29 #define SH2E_NEXT &arch_info_struct[2]
30 #define SH_DSP_NEXT &arch_info_struct[3]
31 #define SH3_NEXT &arch_info_struct[4]
32 #define SH3_NOMMU_NEXT &arch_info_struct[5]
33 #define SH3_DSP_NEXT &arch_info_struct[6]
34 #define SH3E_NEXT &arch_info_struct[7]
35 #define SH4_NEXT &arch_info_struct[8]
36 #define SH4A_NEXT &arch_info_struct[9]
37 #define SH4AL_DSP_NEXT &arch_info_struct[10]
38 #define SH4_NOFPU_NEXT &arch_info_struct[11]
39 #define SH4_NOMMU_NOFPU_NEXT &arch_info_struct[12]
40 #define SH4A_NOFPU_NEXT &arch_info_struct[13]
41 #define SH64_NEXT NULL
43 static const bfd_arch_info_type arch_info_struct
[] =
46 32, /* 32 bits in a word */
47 32, /* 32 bits in an address */
48 8, /* 8 bits in a byte */
52 "sh2", /* printable name */
54 FALSE
, /* not the default */
55 bfd_default_compatible
,
60 32, /* 32 bits in a word */
61 32, /* 32 bits in an address */
62 8, /* 8 bits in a byte */
66 "sh2e", /* printable name */
68 FALSE
, /* not the default */
69 bfd_default_compatible
,
74 32, /* 32 bits in a word */
75 32, /* 32 bits in an address */
76 8, /* 8 bits in a byte */
80 "sh-dsp", /* printable name */
82 FALSE
, /* not the default */
83 bfd_default_compatible
,
88 32, /* 32 bits in a word */
89 32, /* 32 bits in an address */
90 8, /* 8 bits in a byte */
94 "sh3", /* printable name */
96 FALSE
, /* not the default */
97 bfd_default_compatible
,
102 32, /* 32 bits in a word */
103 32, /* 32 bits in an address */
104 8, /* 8 bits in a byte */
107 "sh", /* arch_name */
108 "sh3-nommu", /* printable name */
110 FALSE
, /* not the default */
111 bfd_default_compatible
,
116 32, /* 32 bits in a word */
117 32, /* 32 bits in an address */
118 8, /* 8 bits in a byte */
121 "sh", /* arch_name */
122 "sh3-dsp", /* printable name */
124 FALSE
, /* not the default */
125 bfd_default_compatible
,
130 32, /* 32 bits in a word */
131 32, /* 32 bits in an address */
132 8, /* 8 bits in a byte */
135 "sh", /* arch_name */
136 "sh3e", /* printable name */
138 FALSE
, /* not the default */
139 bfd_default_compatible
,
144 32, /* 32 bits in a word */
145 32, /* 32 bits in an address */
146 8, /* 8 bits in a byte */
149 "sh", /* arch_name */
150 "sh4", /* printable name */
152 FALSE
, /* not the default */
153 bfd_default_compatible
,
158 32, /* 32 bits in a word */
159 32, /* 32 bits in an address */
160 8, /* 8 bits in a byte */
163 "sh", /* arch_name */
164 "sh4a", /* printable name */
166 FALSE
, /* not the default */
167 bfd_default_compatible
,
172 32, /* 32 bits in a word */
173 32, /* 32 bits in an address */
174 8, /* 8 bits in a byte */
177 "sh", /* arch_name */
178 "sh4al-dsp", /* printable name */
180 FALSE
, /* not the default */
181 bfd_default_compatible
,
186 32, /* 32 bits in a word */
187 32, /* 32 bits in an address */
188 8, /* 8 bits in a byte */
191 "sh", /* arch_name */
192 "sh4-nofpu", /* printable name */
194 FALSE
, /* not the default */
195 bfd_default_compatible
,
200 32, /* 32 bits in a word */
201 32, /* 32 bits in an address */
202 8, /* 8 bits in a byte */
204 bfd_mach_sh4_nommu_nofpu
,
205 "sh", /* arch_name */
206 "sh4-nommu-nofpu", /* printable name */
208 FALSE
, /* not the default */
209 bfd_default_compatible
,
214 32, /* 32 bits in a word */
215 32, /* 32 bits in an address */
216 8, /* 8 bits in a byte */
219 "sh", /* arch_name */
220 "sh4a-nofpu", /* printable name */
222 FALSE
, /* not the default */
223 bfd_default_compatible
,
228 64, /* 64 bits in a word */
229 64, /* 64 bits in an address */
230 8, /* 8 bits in a byte */
233 "sh", /* arch_name */
234 "sh5", /* printable name */
236 FALSE
, /* not the default */
237 bfd_default_compatible
,
243 const bfd_arch_info_type bfd_sh_arch
=
245 32, /* 32 bits in a word */
246 32, /* 32 bits in an address */
247 8, /* 8 bits in a byte */
250 "sh", /* arch_name */
251 "sh", /* printable name */
253 TRUE
, /* the default machine */
254 bfd_default_compatible
,
260 /* This table defines the mappings from the BFD internal numbering
261 system to the opcodes internal flags system.
262 It is used by the functions defined below.
263 The prototypes for these SH specific functions are found in
266 static struct { unsigned long bfd_mach
, arch
, arch_up
; } bfd_to_arch_table
[] =
268 { bfd_mach_sh
, arch_sh1
, arch_sh1_up
},
269 { bfd_mach_sh2
, arch_sh2
, arch_sh2_up
},
270 { bfd_mach_sh2e
, arch_sh2e
, arch_sh2e_up
},
271 { bfd_mach_sh_dsp
, arch_sh_dsp
, arch_sh_dsp_up
},
272 { bfd_mach_sh3
, arch_sh3
, arch_sh3_up
},
273 { bfd_mach_sh3_nommu
, arch_sh3_nommu
, arch_sh3_nommu_up
},
274 { bfd_mach_sh3_dsp
, arch_sh3_dsp
, arch_sh3_dsp_up
},
275 { bfd_mach_sh3e
, arch_sh3e
, arch_sh3e_up
},
276 { bfd_mach_sh4
, arch_sh4
, arch_sh4_up
},
277 { bfd_mach_sh4a
, arch_sh4a
, arch_sh4a_up
},
278 { bfd_mach_sh4al_dsp
, arch_sh4al_dsp
, arch_sh4al_dsp_up
},
279 { bfd_mach_sh4_nofpu
, arch_sh4_nofpu
, arch_sh4_nofp_up
},
280 { bfd_mach_sh4_nommu_nofpu
, arch_sh4_nommu_nofpu
, arch_sh4_nommu_nofpu_up
},
281 { bfd_mach_sh4a_nofpu
, arch_sh4a_nofpu
, arch_sh4a_nofp_up
},
282 { 0, 0, 0 } /* Terminator. */
286 /* Convert a BFD mach number into the right opcodes arch flags
287 using the table above. */
290 sh_get_arch_from_bfd_mach (unsigned long mach
)
294 while (bfd_to_arch_table
[i
].bfd_mach
!= 0)
295 if (bfd_to_arch_table
[i
].bfd_mach
== mach
)
296 return bfd_to_arch_table
[i
].arch
;
300 /* mach not found. */
303 return SH_ARCH_UNKNOWN_ARCH
;
307 /* Convert a BFD mach number into a set of opcodes arch flags
308 describing all the compatible architectures (i.e. arch_up)
309 using the table above. */
312 sh_get_arch_up_from_bfd_mach (unsigned long mach
)
316 while (bfd_to_arch_table
[i
].bfd_mach
!= 0)
317 if (bfd_to_arch_table
[i
].bfd_mach
== mach
)
318 return bfd_to_arch_table
[i
].arch_up
;
322 /* mach not found. */
325 return SH_ARCH_UNKNOWN_ARCH
;
329 /* Convert an arbitary arch_set - not necessarily corresponding
330 directly to anything in the table above - to the most generic
331 architecture which supports all the required features, and
332 return the corresponding BFD mach. */
335 sh_get_bfd_mach_from_arch_set (unsigned int arch_set
)
337 unsigned long result
= 0;
338 unsigned int best
= ~arch_set
;
339 unsigned int co_mask
= ~0;
342 /* If arch_set permits variants with no coprocessor then do not allow
343 the other irrelevant co-processor bits to influence the choice:
344 e.g. if dsp is disallowed by arch_set, then the algorithm would
345 prefer fpu variants over nofpu variants because they also disallow
346 dsp - even though the nofpu would be the most correct choice.
347 This assumes that EVERY fpu/dsp variant has a no-coprocessor
348 counter-part, or their non-fpu/dsp instructions do not have the
349 no co-processor bit set. */
350 if (arch_set
& arch_sh_no_co
)
351 co_mask
= ~(arch_sh_sp_fpu
| arch_sh_dp_fpu
| arch_sh_has_dsp
);
353 while (bfd_to_arch_table
[i
].bfd_mach
!= 0)
355 unsigned int try = bfd_to_arch_table
[i
].arch_up
& co_mask
;
357 /* Conceptually: Find the architecture with the least number
358 of extra features or, if they have the same number, then
359 the greatest number of required features. Disregard
360 architectures where the required features alone do
361 not describe a valid architecture. */
362 if (((try & ~arch_set
) < (best
& ~arch_set
)
363 || ((try & ~arch_set
) == (best
& ~arch_set
)
364 && (~try & arch_set
) < (~best
& arch_set
)))
365 && SH_MERGE_ARCH_SET_VALID (try, arch_set
))
367 result
= bfd_to_arch_table
[i
].bfd_mach
;
374 /* This might happen if a new variant is added to sh-opc.h
375 but no corresponding entry is added to the table above. */
376 BFD_ASSERT (result
!= 0);
382 /* Merge the architecture type of two BFD files, such that the
383 resultant architecture supports all the features required
384 by the two input BFDs.
385 If the input BFDs are multually incompatible - i.e. one uses
386 DSP while the other uses FPU - or there is no known architecture
387 that fits the requirements then an error is emitted. */
390 sh_merge_bfd_arch (bfd
*ibfd
, bfd
*obfd
)
392 unsigned int old_arch
, new_arch
, merged_arch
;
394 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
397 old_arch
= sh_get_arch_up_from_bfd_mach (bfd_get_mach (obfd
));
398 new_arch
= sh_get_arch_up_from_bfd_mach (bfd_get_mach (ibfd
));
400 merged_arch
= SH_MERGE_ARCH_SET (old_arch
, new_arch
);
402 if (!SH_VALID_CO_ARCH_SET (merged_arch
))
404 (*_bfd_error_handler
)
405 ("%s: uses %s instructions while previous modules use %s instructions",
406 bfd_archive_filename (ibfd
),
407 SH_ARCH_SET_HAS_DSP (new_arch
) ? "dsp" : "floating point",
408 SH_ARCH_SET_HAS_DSP (new_arch
) ? "floating point" : "dsp");
409 bfd_set_error (bfd_error_bad_value
);
412 else if (!SH_VALID_ARCH_SET (merged_arch
))
414 (*_bfd_error_handler
)
415 ("internal error: merge of architecture '%s' with architecture '%s' produced unknown architecture\n",
416 bfd_printable_name (obfd
),
417 bfd_printable_name (ibfd
));
418 bfd_set_error (bfd_error_bad_value
);
422 bfd_default_set_arch_mach (obfd
, bfd_arch_sh
,
423 sh_get_bfd_mach_from_arch_set (merged_arch
));