1 /* BFD library support routines for the Renesas / SuperH SH architecture.
2 Copyright (C) 1993-2019 Free Software Foundation, Inc.
3 Hacked by Steve Chamberlain of Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
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
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, 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 SH2A_NEXT arch_info_struct + 14
42 #define SH2A_NOFPU_NEXT arch_info_struct + 15
43 #define SH2A_NOFPU_OR_SH4_NOMMU_NOFPU_NEXT arch_info_struct + 16
44 #define SH2A_NOFPU_OR_SH3_NOMMU_NEXT arch_info_struct + 17
45 #define SH2A_OR_SH4_NEXT arch_info_struct + 18
46 #define SH2A_OR_SH3E_NEXT NULL
48 static const bfd_arch_info_type arch_info_struct[] =
51 32, /* 32 bits in a word. */
52 32, /* 32 bits in an address. */
53 8, /* 8 bits in a byte. */
56 "sh", /* Architecture name. */
57 "sh2", /* Machine name. */
59 FALSE, /* Not the default. */
60 bfd_default_compatible,
62 bfd_arch_default_fill,
66 32, /* 32 bits in a word. */
67 32, /* 32 bits in an address. */
68 8, /* 8 bits in a byte. */
71 "sh", /* Architecture name. */
72 "sh2e", /* Machine name. */
74 FALSE, /* Not the default. */
75 bfd_default_compatible,
77 bfd_arch_default_fill,
81 32, /* 32 bits in a word. */
82 32, /* 32 bits in an address. */
83 8, /* 8 bits in a byte. */
86 "sh", /* Architecture name. */
87 "sh-dsp", /* Machine name. */
89 FALSE, /* Not the default. */
90 bfd_default_compatible,
92 bfd_arch_default_fill,
96 32, /* 32 bits in a word. */
97 32, /* 32 bits in an address. */
98 8, /* 8 bits in a byte. */
101 "sh", /* Architecture name. */
102 "sh3", /* Machine name. */
104 FALSE, /* Not the default. */
105 bfd_default_compatible,
107 bfd_arch_default_fill,
111 32, /* 32 bits in a word. */
112 32, /* 32 bits in an address. */
113 8, /* 8 bits in a byte. */
116 "sh", /* Architecture name. */
117 "sh3-nommu", /* Machine name. */
119 FALSE, /* Not the default. */
120 bfd_default_compatible,
122 bfd_arch_default_fill,
126 32, /* 32 bits in a word. */
127 32, /* 32 bits in an address. */
128 8, /* 8 bits in a byte. */
131 "sh", /* Architecture name. */
132 "sh3-dsp", /* Machine name. */
134 FALSE, /* Not the default. */
135 bfd_default_compatible,
137 bfd_arch_default_fill,
141 32, /* 32 bits in a word. */
142 32, /* 32 bits in an address. */
143 8, /* 8 bits in a byte. */
146 "sh", /* Architecture name. */
147 "sh3e", /* Machine name. */
149 FALSE, /* Not the default. */
150 bfd_default_compatible,
152 bfd_arch_default_fill,
156 32, /* 32 bits in a word. */
157 32, /* 32 bits in an address. */
158 8, /* 8 bits in a byte. */
161 "sh", /* Architecture name. */
162 "sh4", /* Machine name. */
164 FALSE, /* Not the default. */
165 bfd_default_compatible,
167 bfd_arch_default_fill,
171 32, /* 32 bits in a word. */
172 32, /* 32 bits in an address. */
173 8, /* 8 bits in a byte. */
176 "sh", /* Architecture name. */
177 "sh4a", /* Machine name. */
179 FALSE, /* Not the default. */
180 bfd_default_compatible,
182 bfd_arch_default_fill,
186 32, /* 32 bits in a word. */
187 32, /* 32 bits in an address. */
188 8, /* 8 bits in a byte. */
191 "sh", /* Architecture name. */
192 "sh4al-dsp", /* Machine name. */
194 FALSE, /* Not the default. */
195 bfd_default_compatible,
197 bfd_arch_default_fill,
201 32, /* 32 bits in a word. */
202 32, /* 32 bits in an address. */
203 8, /* 8 bits in a byte. */
206 "sh", /* Architecture name. */
207 "sh4-nofpu", /* Machine name. */
209 FALSE, /* Not the default. */
210 bfd_default_compatible,
212 bfd_arch_default_fill,
216 32, /* 32 bits in a word. */
217 32, /* 32 bits in an address. */
218 8, /* 8 bits in a byte. */
220 bfd_mach_sh4_nommu_nofpu,
221 "sh", /* Architecture name. */
222 "sh4-nommu-nofpu", /* Machine name. */
224 FALSE, /* Not the default. */
225 bfd_default_compatible,
227 bfd_arch_default_fill,
231 32, /* 32 bits in a word. */
232 32, /* 32 bits in an address. */
233 8, /* 8 bits in a byte. */
236 "sh", /* Architecture name. */
237 "sh4a-nofpu", /* Machine name. */
239 FALSE, /* Not the default. */
240 bfd_default_compatible,
242 bfd_arch_default_fill,
246 32, /* 32 bits in a word. */
247 32, /* 32 bits in an address. */
248 8, /* 8 bits in a byte. */
251 "sh", /* Architecture name. */
252 "sh2a", /* Machine name. */
254 FALSE, /* Not the default. */
255 bfd_default_compatible,
257 bfd_arch_default_fill,
261 32, /* 32 bits in a word. */
262 32, /* 32 bits in an address. */
263 8, /* 8 bits in a byte. */
266 "sh", /* Architecture name. */
267 "sh2a-nofpu", /* Machine name. */
269 FALSE, /* Not the default. */
270 bfd_default_compatible,
272 bfd_arch_default_fill,
276 32, /* 32 bits in a word. */
277 32, /* 32 bits in an address. */
278 8, /* 8 bits in a byte. */
280 bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu,
281 "sh", /* Architecture name. */
282 "sh2a-nofpu-or-sh4-nommu-nofpu", /* Machine name. */
284 FALSE, /* Not the default. */
285 bfd_default_compatible,
287 bfd_arch_default_fill,
288 SH2A_NOFPU_OR_SH4_NOMMU_NOFPU_NEXT
291 32, /* 32 bits in a word. */
292 32, /* 32 bits in an address. */
293 8, /* 8 bits in a byte. */
295 bfd_mach_sh2a_nofpu_or_sh3_nommu,
296 "sh", /* Architecture name. . */
297 "sh2a-nofpu-or-sh3-nommu", /* Machine name. */
299 FALSE, /* Not the default. */
300 bfd_default_compatible,
302 bfd_arch_default_fill,
303 SH2A_NOFPU_OR_SH3_NOMMU_NEXT
306 32, /* 32 bits in a word. */
307 32, /* 32 bits in an address. */
308 8, /* 8 bits in a byte. */
310 bfd_mach_sh2a_or_sh4,
311 "sh", /* Architecture name. */
312 "sh2a-or-sh4", /* Machine name. */
314 FALSE, /* Not the default. */
315 bfd_default_compatible,
317 bfd_arch_default_fill,
321 32, /* 32 bits in a word. */
322 32, /* 32 bits in an address. */
323 8, /* 8 bits in a byte. */
325 bfd_mach_sh2a_or_sh3e,
326 "sh", /* Architecture name. */
327 "sh2a-or-sh3e", /* Machine name. */
329 FALSE, /* Not the default. */
330 bfd_default_compatible,
332 bfd_arch_default_fill,
337 const bfd_arch_info_type bfd_sh_arch =
339 32, /* 32 bits in a word. */
340 32, /* 32 bits in an address. */
341 8, /* 8 bits in a byte. */
344 "sh", /* Architecture name. */
345 "sh", /* Machine name. */
347 TRUE, /* The default machine. */
348 bfd_default_compatible,
350 bfd_arch_default_fill,
355 /* This table defines the mappings from the BFD internal numbering
356 system to the opcodes internal flags system.
357 It is used by the functions defined below.
358 The prototypes for these SH specific functions are found in
361 static struct { unsigned long bfd_mach, arch, arch_up; } bfd_to_arch_table[] =
363 { bfd_mach_sh, arch_sh1, arch_sh_up },
364 { bfd_mach_sh2, arch_sh2, arch_sh2_up },
365 { bfd_mach_sh2e, arch_sh2e, arch_sh2e_up },
366 { bfd_mach_sh_dsp, arch_sh_dsp, arch_sh_dsp_up },
367 { bfd_mach_sh2a, arch_sh2a, arch_sh2a_up },
368 { bfd_mach_sh2a_nofpu, arch_sh2a_nofpu, arch_sh2a_nofpu_up },
370 { bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu, arch_sh2a_nofpu_or_sh4_nommu_nofpu, arch_sh2a_nofpu_or_sh4_nommu_nofpu_up },
371 { bfd_mach_sh2a_nofpu_or_sh3_nommu, arch_sh2a_nofpu_or_sh3_nommu, arch_sh2a_nofpu_or_sh3_nommu_up },
372 { bfd_mach_sh2a_or_sh4, arch_sh2a_or_sh4, arch_sh2a_or_sh4_up },
373 { bfd_mach_sh2a_or_sh3e, arch_sh2a_or_sh3e, arch_sh2a_or_sh3e_up },
375 { bfd_mach_sh3, arch_sh3, arch_sh3_up },
376 { bfd_mach_sh3_nommu, arch_sh3_nommu, arch_sh3_nommu_up },
377 { bfd_mach_sh3_dsp, arch_sh3_dsp, arch_sh3_dsp_up },
378 { bfd_mach_sh3e, arch_sh3e, arch_sh3e_up },
379 { bfd_mach_sh4, arch_sh4, arch_sh4_up },
380 { bfd_mach_sh4a, arch_sh4a, arch_sh4a_up },
381 { bfd_mach_sh4al_dsp, arch_sh4al_dsp, arch_sh4al_dsp_up },
382 { bfd_mach_sh4_nofpu, arch_sh4_nofpu, arch_sh4_nofpu_up },
383 { bfd_mach_sh4_nommu_nofpu, arch_sh4_nommu_nofpu, arch_sh4_nommu_nofpu_up },
384 { bfd_mach_sh4a_nofpu, arch_sh4a_nofpu, arch_sh4a_nofpu_up },
385 { 0, 0, 0 } /* Terminator. */
389 /* Convert a BFD mach number into the right opcodes arch flags
390 using the table above. */
393 sh_get_arch_from_bfd_mach (unsigned long mach)
397 while (bfd_to_arch_table[i].bfd_mach != 0)
398 if (bfd_to_arch_table[i].bfd_mach == mach)
399 return bfd_to_arch_table[i].arch;
403 /* Machine not found. */
406 return SH_ARCH_UNKNOWN_ARCH;
410 /* Convert a BFD mach number into a set of opcodes arch flags
411 describing all the compatible architectures (i.e. arch_up)
412 using the table above. */
415 sh_get_arch_up_from_bfd_mach (unsigned long mach)
419 while (bfd_to_arch_table[i].bfd_mach != 0)
420 if (bfd_to_arch_table[i].bfd_mach == mach)
421 return bfd_to_arch_table[i].arch_up;
425 /* Machine not found. */
428 return SH_ARCH_UNKNOWN_ARCH;
432 /* Convert an arbitary arch_set - not necessarily corresponding
433 directly to anything in the table above - to the most generic
434 architecture which supports all the required features, and
435 return the corresponding BFD mach. */
438 sh_get_bfd_mach_from_arch_set (unsigned int arch_set)
440 unsigned long result = 0;
441 unsigned int best = ~arch_set;
442 unsigned int co_mask = ~0;
445 /* If arch_set permits variants with no coprocessor then do not allow
446 the other irrelevant co-processor bits to influence the choice:
447 e.g. if dsp is disallowed by arch_set, then the algorithm would
448 prefer fpu variants over nofpu variants because they also disallow
449 dsp - even though the nofpu would be the most correct choice.
450 This assumes that EVERY fpu/dsp variant has a no-coprocessor
451 counter-part, or their non-fpu/dsp instructions do not have the
452 no co-processor bit set. */
453 if (arch_set & arch_sh_no_co)
454 co_mask = ~(arch_sh_sp_fpu | arch_sh_dp_fpu | arch_sh_has_dsp);
456 while (bfd_to_arch_table[i].bfd_mach != 0)
458 unsigned int try = bfd_to_arch_table[i].arch_up & co_mask;
460 /* Conceptually: Find the architecture with the least number
461 of extra features or, if they have the same number, then
462 the greatest number of required features. Disregard
463 architectures where the required features alone do
464 not describe a valid architecture. */
465 if (((try & ~arch_set) < (best & ~arch_set)
466 || ((try & ~arch_set) == (best & ~arch_set)
467 && (~try & arch_set) < (~best & arch_set)))
468 && SH_MERGE_ARCH_SET_VALID (try, arch_set))
470 result = bfd_to_arch_table[i].bfd_mach;
477 /* This might happen if a new variant is added to sh-opc.h
478 but no corresponding entry is added to the table above. */
479 BFD_ASSERT (result != 0);