1 /* BFD library support routines for architectures.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1997, 1998, 2000, 2001, 2002,
3 2003, 2004, 2006 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 #include "opcode/m68k.h"
27 #define N(name, print,d,next) \
28 { 32, 32, 8, bfd_arch_m68k, name, "m68k",print,2,d,bfd_default_compatible,bfd_default_scan, next, }
30 static const bfd_arch_info_type arch_info_struct
[] =
32 N(bfd_mach_m68000
, "m68k:68000", FALSE
, &arch_info_struct
[1]),
33 N(bfd_mach_m68008
, "m68k:68008", FALSE
, &arch_info_struct
[2]),
34 N(bfd_mach_m68010
, "m68k:68010", FALSE
, &arch_info_struct
[3]),
35 N(bfd_mach_m68020
, "m68k:68020", FALSE
, &arch_info_struct
[4]),
36 N(bfd_mach_m68030
, "m68k:68030", FALSE
, &arch_info_struct
[5]),
37 N(bfd_mach_m68040
, "m68k:68040", FALSE
, &arch_info_struct
[6]),
38 N(bfd_mach_m68060
, "m68k:68060", FALSE
, &arch_info_struct
[7]),
39 N(bfd_mach_cpu32
, "m68k:cpu32", FALSE
, &arch_info_struct
[8]),
41 /* Various combinations of CF architecture features */
42 N(bfd_mach_mcf_isa_a
, "m68k:isa-a",
43 FALSE
, &arch_info_struct
[9]),
44 N(bfd_mach_mcf_isa_a_div
, "m68k:isa-a:div",
45 FALSE
, &arch_info_struct
[10]),
46 N(bfd_mach_mcf_isa_a_div_mac
, "m68k:isa-a:div:mac",
47 FALSE
, &arch_info_struct
[11]),
48 N(bfd_mach_mcf_isa_a_div_emac
, "m68k:isa-a:div:emac",
49 FALSE
, &arch_info_struct
[12]),
50 N(bfd_mach_mcf_isa_aplus
, "m68k:isa-a+",
51 FALSE
, &arch_info_struct
[13]),
52 N(bfd_mach_mcf_isa_aplus_mac
, "m68k:isa-a+:mac",
53 FALSE
, &arch_info_struct
[14]),
54 N(bfd_mach_mcf_isa_aplus_emac
, "m68k:isa-a+:emac",
55 FALSE
, &arch_info_struct
[15]),
56 N(bfd_mach_mcf_isa_aplus_usp
, "m68k:isa-a+:usp",
57 FALSE
, &arch_info_struct
[16]),
58 N(bfd_mach_mcf_isa_aplus_usp_mac
, "m68k:isa-a+:usp:mac",
59 FALSE
, &arch_info_struct
[17]),
60 N(bfd_mach_mcf_isa_aplus_usp_emac
, "m68k:isa-a+:usp:emac",
61 FALSE
, &arch_info_struct
[18]),
62 N(bfd_mach_mcf_isa_b
, "m68k:isa-b",
63 FALSE
, &arch_info_struct
[19]),
64 N(bfd_mach_mcf_isa_b_mac
, "m68k:isa-b:mac",
65 FALSE
, &arch_info_struct
[20]),
66 N(bfd_mach_mcf_isa_b_emac
, "m68k:isa-b:emac",
67 FALSE
, &arch_info_struct
[21]),
68 N(bfd_mach_mcf_isa_b_usp_float
, "m68k:isa-b:usp:float",
69 FALSE
, &arch_info_struct
[22]),
70 N(bfd_mach_mcf_isa_b_usp_float_mac
, "m68k:isa-b:usp:float:mac",
71 FALSE
, &arch_info_struct
[23]),
72 N(bfd_mach_mcf_isa_b_usp_float_emac
, "m68k:isa-b:usp:float:emac",
73 FALSE
, &arch_info_struct
[24]),
75 /* Legacy names for CF architectures */
76 N(bfd_mach_mcf_isa_a
, "m68k:5200", FALSE
, &arch_info_struct
[25]),
77 N(bfd_mach_mcf_isa_a_div_mac
,"m68k:5206e", FALSE
, &arch_info_struct
[26]),
78 N(bfd_mach_mcf_isa_a_div_mac
, "m68k:5307", FALSE
, &arch_info_struct
[27]),
79 N(bfd_mach_mcf_isa_b_mac
, "m68k:5407", FALSE
, &arch_info_struct
[28]),
80 N(bfd_mach_mcf_isa_aplus_usp_emac
, "m68k:528x",
81 FALSE
, &arch_info_struct
[29]),
82 N(bfd_mach_mcf_isa_aplus_usp_emac
, "m68k:521x",
83 FALSE
, &arch_info_struct
[30]),
84 N(bfd_mach_mcf_isa_a_div_emac
, "m68k:5249", FALSE
, &arch_info_struct
[31]),
85 N(bfd_mach_mcf_isa_b_usp_float_emac
, "m68k:547x",
86 FALSE
, &arch_info_struct
[32]),
87 N(bfd_mach_mcf_isa_b_usp_float_emac
, "m68k:548x",
88 FALSE
, &arch_info_struct
[33]),
89 N(bfd_mach_mcf_isa_b_usp_float_emac
, "m68k:cfv4e", FALSE
, 0),
92 const bfd_arch_info_type bfd_m68k_arch
=
93 N(0, "m68k", TRUE
, &arch_info_struct
[0]);
95 /* Table indexed by bfd_mach_arch number indicating which
96 architectural features are supported. */
97 static const unsigned m68k_arch_features
[] =
100 m68000
|m68881
|m68851
,
101 m68000
|m68881
|m68851
,
102 m68010
|m68881
|m68851
,
103 m68020
|m68881
|m68851
,
104 m68030
|m68881
|m68851
,
105 m68040
|m68881
|m68851
,
106 m68060
|m68881
|m68851
,
110 mcfisa_a
|mcfhwdiv
|mcfmac
,
111 mcfisa_a
|mcfhwdiv
|mcfemac
,
112 mcfisa_a
|mcfisa_aa
|mcfhwdiv
,
113 mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
,
114 mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
,
115 mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
,
116 mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
|mcfmac
,
117 mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
|mcfemac
,
118 mcfisa_a
|mcfhwdiv
|mcfisa_b
,
119 mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfmac
,
120 mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
,
121 mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfusp
|cfloat
,
122 mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfusp
|cfloat
|mcfmac
,
123 mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfusp
|cfloat
|mcfemac
,
126 /* Return the count of bits set in MASK */
128 bit_count (unsigned mask
)
132 for (ix
= 0; mask
; ix
++)
133 /* Clear the LSB set */
134 mask
^= mask
& -mask
;
138 /* Return the architectural features supported by MACH */
141 bfd_m68k_mach_to_features (int mach
)
144 >= sizeof (m68k_arch_features
) / sizeof (m68k_arch_features
[0]))
146 return m68k_arch_features
[mach
];
149 /* Return the bfd machine that most closely represents the
150 architectural features. We find the machine with the smallest
151 number of additional features. If there is no such machine, we
152 find the one with the smallest number of missing features. */
154 int bfd_m68k_features_to_mach (unsigned features
)
156 int superset
= 0, subset
= 0;
157 unsigned extra
= 99, missing
= 99;
161 ix
!= sizeof (m68k_arch_features
) / sizeof (m68k_arch_features
[0]);
164 unsigned this_extra
, this_missing
;
166 if (m68k_arch_features
[ix
] == features
)
168 this_extra
= bit_count (m68k_arch_features
[ix
] & ~features
);
169 if (this_extra
< extra
)
175 this_missing
= bit_count (features
& ~m68k_arch_features
[ix
]);
176 if (this_missing
< missing
)
178 missing
= this_missing
;
182 return superset
? superset
: subset
;