Commit | Line | Data |
---|---|---|
c618de01 | 1 | /* BFD library support routines for architectures. |
36df40e0 | 2 | Copyright (C) 1990, 91-97, 1998 Free Software Foundation, Inc. |
4e6f9223 SC |
3 | Hacked by John Gilmore and Steve Chamberlain of Cygnus Support. |
4 | ||
c618de01 | 5 | This file is part of BFD, the Binary File Descriptor library. |
4a81b561 | 6 | |
c618de01 | 7 | This program is free software; you can redistribute it and/or modify |
4a81b561 | 8 | it under the terms of the GNU General Public License as published by |
c618de01 SC |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
4a81b561 | 11 | |
c618de01 | 12 | This program is distributed in the hope that it will be useful, |
4a81b561 DHW |
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
c618de01 | 18 | along with this program; if not, write to the Free Software |
b7577823 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
c618de01 | 20 | |
5bc513b4 DE |
21 | #include "bfd.h" |
22 | #include "sysdep.h" | |
23 | #include "libbfd.h" | |
24 | #include <ctype.h> | |
25 | ||
9fda1a39 | 26 | /* |
4e6f9223 | 27 | |
9fda1a39 SC |
28 | SECTION |
29 | Architectures | |
30 | ||
c188b0be DM |
31 | BFD keeps one atom in a BFD describing the |
32 | architecture of the data attached to the BFD: a pointer to a | |
9fda1a39 SC |
33 | <<bfd_arch_info_type>>. |
34 | ||
c188b0be | 35 | Pointers to structures can be requested independently of a BFD |
9fda1a39 | 36 | so that an architecture's information can be interrogated |
c188b0be | 37 | without access to an open BFD. |
9fda1a39 | 38 | |
c188b0be DM |
39 | The architecture information is provided by each architecture package. |
40 | The set of default architectures is selected by the macro | |
9fda1a39 | 41 | <<SELECT_ARCHITECTURES>>. This is normally set up in the |
d94aca1a | 42 | @file{config/@var{target}.mt} file of your choice. If the name is not |
9fda1a39 SC |
43 | defined, then all the architectures supported are included. |
44 | ||
45 | When BFD starts up, all the architectures are called with an | |
46 | initialize method. It is up to the architecture back end to | |
71c0bae0 | 47 | insert as many items into the list of architectures as it wants to; |
9fda1a39 SC |
48 | generally this would be one for each machine and one for the |
49 | default case (an item with a machine field of 0). | |
c188b0be | 50 | |
d94aca1a | 51 | BFD's idea of an architecture is implemented in @file{archures.c}. |
c618de01 SC |
52 | */ |
53 | ||
9fda1a39 SC |
54 | /* |
55 | ||
56 | SUBSECTION | |
57 | bfd_architecture | |
58 | ||
59 | DESCRIPTION | |
60 | This enum gives the object file's CPU architecture, in a | |
c188b0be DM |
61 | global sense---i.e., what processor family does it belong to? |
62 | Another field indicates which processor within | |
9fda1a39 | 63 | the family is in use. The machine gives a number which |
c188b0be DM |
64 | distinguishes different versions of the architecture, |
65 | containing, for example, 2 and 3 for Intel i960 KA and i960 KB, | |
9fda1a39 SC |
66 | and 68020 and 68030 for Motorola 68020 and 68030. |
67 | ||
68 | .enum bfd_architecture | |
69 | .{ | |
70 | . bfd_arch_unknown, {* File arch not known *} | |
71 | . bfd_arch_obscure, {* Arch known, not one of these *} | |
72 | . bfd_arch_m68k, {* Motorola 68xxx *} | |
1a85826e KR |
73 | .#define bfd_mach_m68000 1 |
74 | .#define bfd_mach_m68008 2 | |
75 | .#define bfd_mach_m68010 3 | |
76 | .#define bfd_mach_m68020 4 | |
77 | .#define bfd_mach_m68030 5 | |
78 | .#define bfd_mach_m68040 6 | |
79 | .#define bfd_mach_m68060 7 | |
80 | .#define bfd_mach_cpu32 8 | |
9fda1a39 SC |
81 | . bfd_arch_vax, {* DEC Vax *} |
82 | . bfd_arch_i960, {* Intel 960 *} | |
83 | . {* The order of the following is important. | |
84 | . lower number indicates a machine type that | |
85 | . only accepts a subset of the instructions | |
86 | . available to machines with higher numbers. | |
87 | . The exception is the "ca", which is | |
88 | . incompatible with all other machines except | |
89 | . "core". *} | |
90 | . | |
91 | .#define bfd_mach_i960_core 1 | |
92 | .#define bfd_mach_i960_ka_sa 2 | |
93 | .#define bfd_mach_i960_kb_sb 3 | |
94 | .#define bfd_mach_i960_mc 4 | |
95 | .#define bfd_mach_i960_xa 5 | |
96 | .#define bfd_mach_i960_ca 6 | |
34255b70 | 97 | .#define bfd_mach_i960_jx 7 |
cbe75cb6 | 98 | .#define bfd_mach_i960_hx 8 |
9fda1a39 SC |
99 | . |
100 | . bfd_arch_a29k, {* AMD 29000 *} | |
101 | . bfd_arch_sparc, {* SPARC *} | |
5bc513b4 | 102 | .#define bfd_mach_sparc 1 |
cbe75cb6 | 103 | .{* The difference between v8plus and v9 is that v9 is a true 64 bit env. *} |
34255b70 JL |
104 | .#define bfd_mach_sparc_sparclet 2 |
105 | .#define bfd_mach_sparc_sparclite 3 | |
106 | .#define bfd_mach_sparc_v8plus 4 | |
107 | .#define bfd_mach_sparc_v8plusa 5 {* with ultrasparc add'ns *} | |
1a85826e KR |
108 | .#define bfd_mach_sparc_sparclite_le 6 |
109 | .#define bfd_mach_sparc_v9 7 | |
110 | .#define bfd_mach_sparc_v9a 8 {* with ultrasparc add'ns *} | |
049f3d4c | 111 | .{* Nonzero if MACH has the v9 instruction set. *} |
34255b70 JL |
112 | .#define bfd_mach_sparc_v9_p(mach) \ |
113 | . ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a) | |
36df40e0 | 114 | . bfd_arch_mips, {* MIPS Rxxxx *} |
29410c45 JL |
115 | . {* start-sanitize-tx19 *} |
116 | .#define bfd_mach_mips1900 1900 | |
117 | . {* end-sanitize-tx19 *} | |
cd66558c | 118 | .#define bfd_mach_mips3000 3000 |
29410c45 | 119 | .#define bfd_mach_mips3900 3900 |
cd66558c | 120 | .#define bfd_mach_mips4000 4000 |
29410c45 JL |
121 | .#define bfd_mach_mips4010 4010 |
122 | .#define bfd_mach_mips4100 4100 | |
123 | .#define bfd_mach_mips4300 4300 | |
124 | .#define bfd_mach_mips4400 4400 | |
125 | .#define bfd_mach_mips4600 4600 | |
126 | .#define bfd_mach_mips4650 4650 | |
ad4413e6 GRK |
127 | . {* start-sanitize-vr4320 *} |
128 | .#define bfd_mach_mips4320 4320 | |
f8ca1a47 | 129 | . {* end-sanitize-vr4320 *} |
29410c45 JL |
130 | . {* start-sanitize-tx49 *} |
131 | .#define bfd_mach_mips4900 4900 | |
132 | . {* end-sanitize-tx49 *} | |
133 | .#define bfd_mach_mips5000 5000 | |
1a85826e | 134 | . {* start-sanitize-cygnus *} {* CYGNUS LOCAL vr5400/raeburn *} |
29410c45 | 135 | .#define bfd_mach_mips5400 5400 |
1a85826e | 136 | . {* end-sanitize-cygnus *} |
29410c45 JL |
137 | . {* start-sanitize-r5900 *} |
138 | .#define bfd_mach_mips5900 5900 | |
139 | . {* end-sanitize-r5900 *} | |
140 | .#define bfd_mach_mips6000 6000 | |
141 | .#define bfd_mach_mips8000 8000 | |
142 | .#define bfd_mach_mips10000 10000 | |
143 | .#define bfd_mach_mips16 16 | |
36df40e0 DE |
144 | . {* start-sanitize-sky *} |
145 | . {* The DVP is a machine within the mips architecture. *} | |
146 | .#define bfd_mach_dvp_dma 42000 | |
ad4413e6 | 147 | .#define bfd_mach_dvp_vif 42001 |
36df40e0 | 148 | .#define bfd_mach_dvp_vu 42002 |
ad4413e6 | 149 | .#define bfd_mach_dvp_gif 42003 |
36df40e0 DE |
150 | .#define bfd_mach_dvp_p(mach) ((mach) >= 42000 && (mach) <= 42003) |
151 | . {* end-sanitize-sky *} | |
9fda1a39 | 152 | . bfd_arch_i386, {* Intel 386 *} |
9676e446 SG |
153 | .#define bfd_mach_i386_i386 0 |
154 | .#define bfd_mach_i386_i8086 1 | |
71c0bae0 | 155 | . bfd_arch_we32k, {* AT&T WE32xxx *} |
9fda1a39 SC |
156 | . bfd_arch_tahoe, {* CCI/Harris Tahoe *} |
157 | . bfd_arch_i860, {* Intel 860 *} | |
158 | . bfd_arch_romp, {* IBM ROMP PC/RT *} | |
159 | . bfd_arch_alliant, {* Alliant *} | |
160 | . bfd_arch_convex, {* Convex *} | |
161 | . bfd_arch_m88k, {* Motorola 88xxx *} | |
162 | . bfd_arch_pyramid, {* Pyramid Technology *} | |
163 | . bfd_arch_h8300, {* Hitachi H8/300 *} | |
2e235c93 ILT |
164 | .#define bfd_mach_h8300 1 |
165 | .#define bfd_mach_h8300h 2 | |
34255b70 | 166 | .#define bfd_mach_h8300s 3 |
d94aca1a | 167 | . bfd_arch_powerpc, {* PowerPC *} |
9fda1a39 | 168 | . bfd_arch_rs6000, {* IBM RS/6000 *} |
e3c01e92 | 169 | . bfd_arch_hppa, {* HP PA RISC *} |
efc2b064 | 170 | . bfd_arch_d10v, {* Mitsubishi D10V *} |
fd8d7c31 | 171 | . bfd_arch_d30v, {* Mitsubishi D30V *} |
71c0bae0 KR |
172 | . bfd_arch_z8k, {* Zilog Z8000 *} |
173 | .#define bfd_mach_z8001 1 | |
174 | .#define bfd_mach_z8002 2 | |
2e235c93 ILT |
175 | . bfd_arch_h8500, {* Hitachi H8/500 *} |
176 | . bfd_arch_sh, {* Hitachi SH *} | |
f40d28bf AC |
177 | .#define bfd_mach_sh 0 |
178 | .#define bfd_mach_sh3 0x30 | |
179 | .#define bfd_mach_sh3e 0x3e | |
f40d28bf | 180 | .#define bfd_mach_sh4 0x40 |
2e235c93 | 181 | . bfd_arch_alpha, {* Dec Alpha *} |
d94aca1a | 182 | . bfd_arch_arm, {* Advanced Risc Machines ARM *} |
76af94b9 DE |
183 | .#define bfd_mach_arm_2 1 |
184 | .#define bfd_mach_arm_2a 2 | |
185 | .#define bfd_mach_arm_3 3 | |
186 | .#define bfd_mach_arm_3M 4 | |
187 | .#define bfd_mach_arm_4 5 | |
188 | .#define bfd_mach_arm_4T 6 | |
d94aca1a | 189 | . bfd_arch_ns32k, {* National Semiconductors ns32000 *} |
b7577823 | 190 | . bfd_arch_w65, {* WDC 65816 *} |
ad4413e6 | 191 | . bfd_arch_tic30, {* Texas Instruments TMS320C30 *} |
fd8d7c31 MH |
192 | . {* start-sanitize-tic80 *} |
193 | . bfd_arch_tic80, {* TI TMS320c80 (MVP) *} | |
194 | . {* end-sanitize-tic80 *} | |
efc2b064 | 195 | . bfd_arch_v850, {* NEC V850 *} |
f40d28bf | 196 | .#define bfd_mach_v850 0 |
8988d935 | 197 | . {* start-sanitize-v850e *} |
f40d28bf | 198 | .#define bfd_mach_v850e 'E' |
cd66558c | 199 | .#define bfd_mach_v850ea 'A' |
8988d935 | 200 | . {* end-sanitize-v850e *} |
37648010 | 201 | . bfd_arch_arc, {* Argonaut RISC Core *} |
b7577823 | 202 | .#define bfd_mach_arc_base 0 |
76af94b9 | 203 | . bfd_arch_m32r, {* Mitsubishi M32R/D *} |
2e0a5c10 | 204 | .#define bfd_mach_m32r 0 {* backwards compatibility *} |
20b2c808 | 205 | . {* start-sanitize-m32rx *} |
2e0a5c10 | 206 | .#define bfd_mach_m32rx 'x' |
20b2c808 | 207 | . {* end-sanitize-m32rx *} |
cd6213ff FF |
208 | . bfd_arch_mn10200, {* Matsushita MN10200 *} |
209 | . bfd_arch_mn10300, {* Matsushita MN10300 *} | |
1a85826e KR |
210 | .#define bfd_mach_mn10300 300 |
211 | . {* start-sanitize-am33 *} | |
212 | .#define bfd_mach_am33 330 | |
213 | . {* end-sanitize-am33 *} | |
9fda1a39 SC |
214 | . bfd_arch_last |
215 | . }; | |
c618de01 | 216 | |
c618de01 SC |
217 | |
218 | */ | |
219 | ||
9fda1a39 SC |
220 | /* |
221 | ||
222 | SUBSECTION | |
223 | bfd_arch_info | |
224 | ||
225 | DESCRIPTION | |
226 | This structure contains information on architectures for use | |
227 | within BFD. | |
228 | ||
9fda1a39 SC |
229 | . |
230 | .typedef struct bfd_arch_info | |
231 | .{ | |
232 | . int bits_per_word; | |
233 | . int bits_per_address; | |
234 | . int bits_per_byte; | |
235 | . enum bfd_architecture arch; | |
ae115e51 | 236 | . unsigned long mach; |
5bc513b4 DE |
237 | . const char *arch_name; |
238 | . const char *printable_name; | |
ce07dd7c KR |
239 | . unsigned int section_align_power; |
240 | . {* true if this is the default machine for the architecture *} | |
9fda1a39 | 241 | . boolean the_default; |
5bc513b4 DE |
242 | . const struct bfd_arch_info * (*compatible) |
243 | . PARAMS ((const struct bfd_arch_info *a, | |
244 | . const struct bfd_arch_info *b)); | |
9fda1a39 | 245 | . |
5bc513b4 | 246 | . boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *)); |
9fda1a39 | 247 | . |
5bc513b4 | 248 | . const struct bfd_arch_info *next; |
9fda1a39 | 249 | .} bfd_arch_info_type; |
4e6f9223 SC |
250 | */ |
251 | ||
5bc513b4 DE |
252 | extern const bfd_arch_info_type bfd_a29k_arch; |
253 | extern const bfd_arch_info_type bfd_alpha_arch; | |
5bc513b4 | 254 | extern const bfd_arch_info_type bfd_arc_arch; |
5bc513b4 | 255 | extern const bfd_arch_info_type bfd_arm_arch; |
efc2b064 | 256 | extern const bfd_arch_info_type bfd_d10v_arch; |
fd8d7c31 | 257 | extern const bfd_arch_info_type bfd_d30v_arch; |
5bc513b4 DE |
258 | extern const bfd_arch_info_type bfd_h8300_arch; |
259 | extern const bfd_arch_info_type bfd_h8500_arch; | |
260 | extern const bfd_arch_info_type bfd_hppa_arch; | |
261 | extern const bfd_arch_info_type bfd_i386_arch; | |
262 | extern const bfd_arch_info_type bfd_i860_arch; | |
263 | extern const bfd_arch_info_type bfd_i960_arch; | |
efc2b064 | 264 | extern const bfd_arch_info_type bfd_m32r_arch; |
5bc513b4 DE |
265 | extern const bfd_arch_info_type bfd_m68k_arch; |
266 | extern const bfd_arch_info_type bfd_m88k_arch; | |
267 | extern const bfd_arch_info_type bfd_mips_arch; | |
cd6213ff FF |
268 | extern const bfd_arch_info_type bfd_mn10200_arch; |
269 | extern const bfd_arch_info_type bfd_mn10300_arch; | |
5bc513b4 DE |
270 | extern const bfd_arch_info_type bfd_powerpc_arch; |
271 | extern const bfd_arch_info_type bfd_rs6000_arch; | |
272 | extern const bfd_arch_info_type bfd_sh_arch; | |
5bc513b4 | 273 | extern const bfd_arch_info_type bfd_sparc_arch; |
ad4413e6 | 274 | extern const bfd_arch_info_type bfd_tic30_arch; |
cd6213ff FF |
275 | /* start-sanitize-tic80 */ |
276 | extern const bfd_arch_info_type bfd_tic80_arch; | |
277 | /* end-sanitize-tic80 */ | |
5bc513b4 DE |
278 | extern const bfd_arch_info_type bfd_vax_arch; |
279 | extern const bfd_arch_info_type bfd_we32k_arch; | |
280 | extern const bfd_arch_info_type bfd_z8k_arch; | |
281 | extern const bfd_arch_info_type bfd_ns32k_arch; | |
282 | extern const bfd_arch_info_type bfd_w65_arch; | |
efc2b064 | 283 | extern const bfd_arch_info_type bfd_v850_arch; |
5bc513b4 DE |
284 | |
285 | static const bfd_arch_info_type * const bfd_archures_list[] = | |
286 | { | |
287 | #ifdef SELECT_ARCHITECTURES | |
288 | SELECT_ARCHITECTURES, | |
289 | #else | |
290 | &bfd_a29k_arch, | |
291 | &bfd_alpha_arch, | |
5bc513b4 | 292 | &bfd_arc_arch, |
5bc513b4 | 293 | &bfd_arm_arch, |
efc2b064 | 294 | &bfd_d10v_arch, |
fd8d7c31 | 295 | &bfd_d30v_arch, |
5bc513b4 DE |
296 | &bfd_h8300_arch, |
297 | &bfd_h8500_arch, | |
298 | &bfd_hppa_arch, | |
299 | &bfd_i386_arch, | |
300 | &bfd_i860_arch, | |
301 | &bfd_i960_arch, | |
efc2b064 | 302 | &bfd_m32r_arch, |
5bc513b4 DE |
303 | &bfd_m68k_arch, |
304 | &bfd_m88k_arch, | |
305 | &bfd_mips_arch, | |
cd6213ff FF |
306 | &bfd_mn10200_arch, |
307 | &bfd_mn10300_arch, | |
5bc513b4 DE |
308 | &bfd_powerpc_arch, |
309 | &bfd_rs6000_arch, | |
310 | &bfd_sh_arch, | |
5bc513b4 | 311 | &bfd_sparc_arch, |
ad4413e6 | 312 | &bfd_tic30_arch, |
fd8d7c31 MH |
313 | /* start-sanitize-tic80 */ |
314 | &bfd_tic80_arch, | |
315 | /* end-sanitize-tic80 */ | |
5bc513b4 DE |
316 | &bfd_vax_arch, |
317 | &bfd_we32k_arch, | |
318 | &bfd_z8k_arch, | |
319 | &bfd_ns32k_arch, | |
320 | &bfd_w65_arch, | |
efc2b064 | 321 | &bfd_v850_arch, |
8988d935 | 322 | #endif |
2f88c324 | 323 | 0 |
5bc513b4 | 324 | }; |
4a81b561 | 325 | |
9fda1a39 | 326 | /* |
9fda1a39 SC |
327 | FUNCTION |
328 | bfd_printable_name | |
4e6f9223 | 329 | |
ce07dd7c | 330 | SYNOPSIS |
5bc513b4 | 331 | const char *bfd_printable_name(bfd *abfd); |
ce07dd7c | 332 | |
9fda1a39 SC |
333 | DESCRIPTION |
334 | Return a printable string representing the architecture and machine | |
c188b0be | 335 | from the pointer to the architecture info structure. |
4e6f9223 | 336 | |
4e6f9223 SC |
337 | */ |
338 | ||
5bc513b4 | 339 | const char * |
d94aca1a MT |
340 | bfd_printable_name (abfd) |
341 | bfd *abfd; | |
4e6f9223 SC |
342 | { |
343 | return abfd->arch_info->printable_name; | |
4a81b561 DHW |
344 | } |
345 | ||
4e6f9223 SC |
346 | |
347 | ||
9fda1a39 SC |
348 | /* |
349 | FUNCTION | |
350 | bfd_scan_arch | |
4e6f9223 | 351 | |
ce07dd7c | 352 | SYNOPSIS |
5bc513b4 | 353 | const bfd_arch_info_type *bfd_scan_arch(const char *string); |
ce07dd7c | 354 | |
9fda1a39 | 355 | DESCRIPTION |
c188b0be DM |
356 | Figure out if BFD supports any cpu which could be described with |
357 | the name @var{string}. Return a pointer to an <<arch_info>> | |
9fda1a39 SC |
358 | structure if a machine is found, otherwise NULL. |
359 | ||
c618de01 | 360 | */ |
4a81b561 | 361 | |
5bc513b4 | 362 | const bfd_arch_info_type * |
d94aca1a | 363 | bfd_scan_arch (string) |
5bc513b4 | 364 | const char *string; |
4a81b561 | 365 | { |
5bc513b4 | 366 | const bfd_arch_info_type * const *app, *ap; |
4e6f9223 SC |
367 | |
368 | /* Look through all the installed architectures */ | |
5bc513b4 DE |
369 | for (app = bfd_archures_list; *app != NULL; app++) |
370 | { | |
371 | for (ap = *app; ap != NULL; ap = ap->next) | |
372 | { | |
373 | if (ap->scan (ap, string)) | |
374 | return ap; | |
375 | } | |
376 | } | |
377 | ||
378 | return NULL; | |
4e6f9223 SC |
379 | } |
380 | ||
4a81b561 | 381 | |
4a81b561 | 382 | |
eaa9c2e7 AC |
383 | /* |
384 | FUNCTION | |
385 | bfd_arch_list | |
386 | ||
387 | SYNOPSIS | |
388 | const char **bfd_arch_list(void); | |
389 | ||
390 | DESCRIPTION | |
391 | Return a freshly malloced NULL-terminated vector of the names | |
392 | of all the valid BFD architectures. Do not modify the names. | |
393 | ||
394 | */ | |
395 | ||
396 | const char ** | |
397 | bfd_arch_list () | |
398 | { | |
399 | int vec_length = 0; | |
400 | const char **name_ptr; | |
401 | const char **name_list; | |
402 | const bfd_arch_info_type * const *app; | |
403 | ||
404 | /* Determine the number of architectures */ | |
405 | vec_length = 0; | |
406 | for (app = bfd_archures_list; *app != NULL; app++) | |
407 | { | |
408 | const bfd_arch_info_type *ap; | |
409 | for (ap = *app; ap != NULL; ap = ap->next) | |
410 | { | |
411 | vec_length++; | |
412 | } | |
413 | } | |
414 | ||
415 | name_list = (CONST char **) | |
416 | bfd_malloc ((vec_length + 1) * sizeof (char **)); | |
417 | if (name_list == NULL) | |
418 | return NULL; | |
419 | ||
420 | /* Point the list at each of the names */ | |
421 | name_ptr = name_list; | |
422 | for (app = bfd_archures_list; *app != NULL; app++) | |
423 | { | |
424 | const bfd_arch_info_type *ap; | |
425 | for (ap = *app; ap != NULL; ap = ap->next) | |
426 | { | |
427 | *name_ptr = ap->printable_name; | |
428 | name_ptr++; | |
429 | } | |
430 | } | |
431 | *name_ptr = NULL; | |
432 | ||
433 | return name_list; | |
434 | } | |
435 | ||
436 | ||
437 | ||
9fda1a39 SC |
438 | /* |
439 | FUNCTION | |
440 | bfd_arch_get_compatible | |
441 | ||
ce07dd7c | 442 | SYNOPSIS |
5bc513b4 DE |
443 | const bfd_arch_info_type *bfd_arch_get_compatible( |
444 | const bfd *abfd, | |
445 | const bfd *bbfd); | |
4e6f9223 | 446 | |
ce07dd7c | 447 | DESCRIPTION |
c188b0be DM |
448 | Determine whether two BFDs' |
449 | architectures and machine types are compatible. Calculates | |
9fda1a39 SC |
450 | the lowest common denominator between the two architectures |
451 | and machine types implied by the BFDs and returns a pointer to | |
c188b0be | 452 | an <<arch_info>> structure describing the compatible machine. |
4e6f9223 SC |
453 | */ |
454 | ||
5bc513b4 | 455 | const bfd_arch_info_type * |
d94aca1a | 456 | bfd_arch_get_compatible (abfd, bbfd) |
5bc513b4 DE |
457 | const bfd *abfd; |
458 | const bfd *bbfd; | |
4e6f9223 | 459 | { |
b7577823 ILT |
460 | /* If either architecture is unknown, then all we can do is assume |
461 | the user knows what he's doing. */ | |
462 | if (abfd->arch_info->arch == bfd_arch_unknown) | |
463 | return bbfd->arch_info; | |
464 | if (bbfd->arch_info->arch == bfd_arch_unknown) | |
465 | return abfd->arch_info; | |
466 | ||
467 | /* Otherwise architecture-specific code has to decide. */ | |
5bc513b4 | 468 | return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info); |
4a81b561 DHW |
469 | } |
470 | ||
4e6f9223 | 471 | |
9fda1a39 | 472 | /* |
ce07dd7c | 473 | INTERNAL_DEFINITION |
9fda1a39 | 474 | bfd_default_arch_struct |
4e6f9223 | 475 | |
9fda1a39 | 476 | DESCRIPTION |
ce07dd7c KR |
477 | The <<bfd_default_arch_struct>> is an item of |
478 | <<bfd_arch_info_type>> which has been initialized to a fairly | |
479 | generic state. A BFD starts life by pointing to this | |
480 | structure, until the correct back end has determined the real | |
481 | architecture of the file. | |
9fda1a39 | 482 | |
5bc513b4 | 483 | .extern const bfd_arch_info_type bfd_default_arch_struct; |
4e6f9223 | 484 | |
4e6f9223 SC |
485 | */ |
486 | ||
5bc513b4 | 487 | const bfd_arch_info_type bfd_default_arch_struct = |
9fda1a39 | 488 | { |
2e235c93 | 489 | 32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true, |
9fda1a39 SC |
490 | bfd_default_compatible, |
491 | bfd_default_scan, | |
492 | 0, | |
9fda1a39 | 493 | }; |
4e6f9223 | 494 | |
9fda1a39 SC |
495 | /* |
496 | FUNCTION | |
497 | bfd_set_arch_info | |
4e6f9223 | 498 | |
9fda1a39 | 499 | SYNOPSIS |
5bc513b4 | 500 | void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg); |
4e6f9223 | 501 | |
c188b0be DM |
502 | DESCRIPTION |
503 | Set the architecture info of @var{abfd} to @var{arg}. | |
4e6f9223 SC |
504 | */ |
505 | ||
d94aca1a MT |
506 | void |
507 | bfd_set_arch_info (abfd, arg) | |
508 | bfd *abfd; | |
5bc513b4 | 509 | const bfd_arch_info_type *arg; |
4a81b561 | 510 | { |
4e6f9223 SC |
511 | abfd->arch_info = arg; |
512 | } | |
513 | ||
9fda1a39 | 514 | /* |
ce07dd7c | 515 | INTERNAL_FUNCTION |
9fda1a39 SC |
516 | bfd_default_set_arch_mach |
517 | ||
9fda1a39 SC |
518 | SYNOPSIS |
519 | boolean bfd_default_set_arch_mach(bfd *abfd, | |
520 | enum bfd_architecture arch, | |
521 | unsigned long mach); | |
4e6f9223 | 522 | |
ce07dd7c | 523 | DESCRIPTION |
c188b0be DM |
524 | Set the architecture and machine type in BFD @var{abfd} |
525 | to @var{arch} and @var{mach}. Find the correct | |
526 | pointer to a structure and insert it into the <<arch_info>> | |
ce07dd7c | 527 | pointer. |
4e6f9223 SC |
528 | */ |
529 | ||
d94aca1a MT |
530 | boolean |
531 | bfd_default_set_arch_mach (abfd, arch, mach) | |
532 | bfd *abfd; | |
533 | enum bfd_architecture arch; | |
5bc513b4 | 534 | unsigned long mach; |
4e6f9223 | 535 | { |
5bc513b4 | 536 | const bfd_arch_info_type * const *app, *ap; |
4a81b561 | 537 | |
5bc513b4 DE |
538 | for (app = bfd_archures_list; *app != NULL; app++) |
539 | { | |
540 | for (ap = *app; ap != NULL; ap = ap->next) | |
541 | { | |
542 | if (ap->arch == arch | |
543 | && (ap->mach == mach | |
544 | || (mach == 0 && ap->the_default))) | |
545 | { | |
546 | abfd->arch_info = ap; | |
547 | return true; | |
548 | } | |
549 | } | |
550 | } | |
4e6f9223 | 551 | |
5bc513b4 DE |
552 | abfd->arch_info = &bfd_default_arch_struct; |
553 | bfd_set_error (bfd_error_bad_value); | |
554 | return false; | |
4a81b561 | 555 | } |
4a81b561 | 556 | |
4e6f9223 | 557 | |
9fda1a39 SC |
558 | /* |
559 | FUNCTION | |
560 | bfd_get_arch | |
4e6f9223 | 561 | |
ce07dd7c KR |
562 | SYNOPSIS |
563 | enum bfd_architecture bfd_get_arch(bfd *abfd); | |
564 | ||
9fda1a39 | 565 | DESCRIPTION |
c188b0be DM |
566 | Return the enumerated type which describes the BFD @var{abfd}'s |
567 | architecture. | |
4e6f9223 | 568 | |
4e6f9223 SC |
569 | */ |
570 | ||
d94aca1a MT |
571 | enum bfd_architecture |
572 | bfd_get_arch (abfd) | |
573 | bfd *abfd; | |
9fda1a39 | 574 | { |
4e6f9223 | 575 | return abfd->arch_info->arch; |
9fda1a39 | 576 | } |
4e6f9223 | 577 | |
9fda1a39 SC |
578 | /* |
579 | FUNCTION | |
580 | bfd_get_mach | |
4e6f9223 | 581 | |
ce07dd7c KR |
582 | SYNOPSIS |
583 | unsigned long bfd_get_mach(bfd *abfd); | |
584 | ||
9fda1a39 | 585 | DESCRIPTION |
c188b0be DM |
586 | Return the long type which describes the BFD @var{abfd}'s |
587 | machine. | |
4e6f9223 SC |
588 | */ |
589 | ||
9fda1a39 | 590 | unsigned long |
d94aca1a MT |
591 | bfd_get_mach (abfd) |
592 | bfd *abfd; | |
4a81b561 | 593 | { |
4e6f9223 | 594 | return abfd->arch_info->mach; |
9fda1a39 | 595 | } |
4e6f9223 | 596 | |
9fda1a39 SC |
597 | /* |
598 | FUNCTION | |
599 | bfd_arch_bits_per_byte | |
4e6f9223 | 600 | |
ce07dd7c KR |
601 | SYNOPSIS |
602 | unsigned int bfd_arch_bits_per_byte(bfd *abfd); | |
603 | ||
9fda1a39 | 604 | DESCRIPTION |
c188b0be DM |
605 | Return the number of bits in one of the BFD @var{abfd}'s |
606 | architecture's bytes. | |
4e6f9223 | 607 | |
4e6f9223 SC |
608 | */ |
609 | ||
d94aca1a MT |
610 | unsigned int |
611 | bfd_arch_bits_per_byte (abfd) | |
612 | bfd *abfd; | |
c188b0be DM |
613 | { |
614 | return abfd->arch_info->bits_per_byte; | |
615 | } | |
4e6f9223 | 616 | |
9fda1a39 SC |
617 | /* |
618 | FUNCTION | |
619 | bfd_arch_bits_per_address | |
4e6f9223 | 620 | |
9fda1a39 SC |
621 | SYNOPSIS |
622 | unsigned int bfd_arch_bits_per_address(bfd *abfd); | |
ce07dd7c KR |
623 | |
624 | DESCRIPTION | |
c188b0be DM |
625 | Return the number of bits in one of the BFD @var{abfd}'s |
626 | architecture's addresses. | |
4e6f9223 SC |
627 | */ |
628 | ||
d94aca1a MT |
629 | unsigned int |
630 | bfd_arch_bits_per_address (abfd) | |
631 | bfd *abfd; | |
c188b0be DM |
632 | { |
633 | return abfd->arch_info->bits_per_address; | |
634 | } | |
4e6f9223 SC |
635 | |
636 | ||
9fda1a39 | 637 | /* |
ce07dd7c | 638 | INTERNAL_FUNCTION |
9fda1a39 | 639 | bfd_default_compatible |
4e6f9223 | 640 | |
9fda1a39 | 641 | SYNOPSIS |
5bc513b4 DE |
642 | const bfd_arch_info_type *bfd_default_compatible |
643 | (const bfd_arch_info_type *a, | |
644 | const bfd_arch_info_type *b); | |
ce07dd7c KR |
645 | |
646 | DESCRIPTION | |
647 | The default function for testing for compatibility. | |
4e6f9223 SC |
648 | */ |
649 | ||
5bc513b4 | 650 | const bfd_arch_info_type * |
d94aca1a | 651 | bfd_default_compatible (a,b) |
5bc513b4 DE |
652 | const bfd_arch_info_type *a; |
653 | const bfd_arch_info_type *b; | |
4e6f9223 | 654 | { |
5bc513b4 DE |
655 | if (a->arch != b->arch) |
656 | return NULL; | |
4e6f9223 | 657 | |
5bc513b4 | 658 | if (a->mach > b->mach) |
4e6f9223 | 659 | return a; |
5bc513b4 DE |
660 | |
661 | if (b->mach > a->mach) | |
4e6f9223 | 662 | return b; |
5bc513b4 | 663 | |
4e6f9223 | 664 | return a; |
4a81b561 DHW |
665 | } |
666 | ||
667 | ||
9fda1a39 | 668 | /* |
ce07dd7c | 669 | INTERNAL_FUNCTION |
9fda1a39 SC |
670 | bfd_default_scan |
671 | ||
9fda1a39 | 672 | SYNOPSIS |
5bc513b4 | 673 | boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string); |
4e6f9223 | 674 | |
ce07dd7c KR |
675 | DESCRIPTION |
676 | The default function for working out whether this is an | |
677 | architecture hit and a machine hit. | |
4e6f9223 SC |
678 | */ |
679 | ||
680 | boolean | |
d94aca1a | 681 | bfd_default_scan (info, string) |
5bc513b4 DE |
682 | const struct bfd_arch_info *info; |
683 | const char *string; | |
4a81b561 | 684 | { |
5bc513b4 DE |
685 | const char *ptr_src; |
686 | const char *ptr_tst; | |
b7577823 ILT |
687 | unsigned long number; |
688 | enum bfd_architecture arch; | |
eaa9c2e7 AC |
689 | const char *printable_name_colon; |
690 | ||
691 | /* Exact match of the architecture name (ARCH_NAME) and also the | |
692 | default architecture? */ | |
693 | if (strcasecmp (string, info->arch_name) == 0 | |
694 | && info->the_default) | |
695 | return true; | |
5bc513b4 | 696 | |
eaa9c2e7 AC |
697 | /* Exact match of the machine name (PRINTABLE_NAME)? */ |
698 | if (strcasecmp (string, info->printable_name) == 0) | |
5bc513b4 | 699 | return true; |
eaa9c2e7 AC |
700 | |
701 | /* Given that printable_name contains no colon, attempt to match: | |
702 | ARCH_NAME [ ":" ] PRINTABLE_NAME? */ | |
703 | printable_name_colon = strchr (info->printable_name, ':'); | |
704 | if (printable_name_colon == NULL) | |
705 | { | |
706 | int strlen_arch_name = strlen (info->arch_name); | |
707 | if (strncasecmp (string, info->arch_name, strlen_arch_name) == 0) | |
1a85826e KR |
708 | { |
709 | if (string[strlen_arch_name] == ':') | |
710 | { | |
711 | if (strcasecmp (string + strlen_arch_name + 1, | |
712 | info->printable_name) == 0) | |
713 | return true; | |
714 | } | |
715 | else | |
716 | { | |
717 | if (strcasecmp (string + strlen_arch_name, | |
718 | info->printable_name) == 0) | |
719 | return true; | |
720 | } | |
721 | } | |
eaa9c2e7 AC |
722 | } |
723 | ||
724 | /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>; | |
725 | Attempt to match: <arch> <mach>? */ | |
726 | if (printable_name_colon != NULL) | |
727 | { | |
728 | int colon_index = printable_name_colon - info->printable_name; | |
729 | if (strncasecmp (string, info->printable_name, colon_index) == 0 | |
730 | && strcasecmp (string + colon_index, | |
731 | info->printable_name + colon_index + 1) == 0) | |
732 | return true; | |
733 | } | |
734 | ||
735 | /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>; Do not | |
736 | attempt to match just <mach>, it could be ambigious. This test | |
737 | is left until later. */ | |
738 | ||
739 | /* NOTE: The below is retained for compatibility only. Please do not | |
740 | add to this code */ | |
b7577823 ILT |
741 | |
742 | /* See how much of the supplied string matches with the | |
743 | architecture, eg the string m68k:68020 would match the 68k entry | |
744 | up to the :, then we get left with the machine number */ | |
745 | ||
5bc513b4 | 746 | for (ptr_src = string, ptr_tst = info->arch_name; |
b7577823 | 747 | *ptr_src && *ptr_tst; |
5bc513b4 | 748 | ptr_src++, ptr_tst++) |
9fda1a39 | 749 | { |
b7577823 | 750 | if (*ptr_src != *ptr_tst) break; |
9fda1a39 | 751 | } |
4e6f9223 | 752 | |
b7577823 ILT |
753 | /* Chewed up as much of the architecture as will match, skip any |
754 | colons */ | |
5bc513b4 DE |
755 | if (*ptr_src == ':') |
756 | ptr_src++; | |
4e6f9223 | 757 | |
5bc513b4 DE |
758 | if (*ptr_src == 0) |
759 | { | |
760 | /* nothing more, then only keep this one if it is the default | |
761 | machine for this architecture */ | |
762 | return info->the_default; | |
763 | } | |
764 | ||
b7577823 | 765 | number = 0; |
1a85826e | 766 | while (isdigit ((unsigned char) *ptr_src)) |
5bc513b4 DE |
767 | { |
768 | number = number * 10 + *ptr_src - '0'; | |
769 | ptr_src++; | |
770 | } | |
b7577823 | 771 | |
cd66558c NC |
772 | /* NOTE: The below is retained for compatibility only. |
773 | PLEASE DO NOT ADD TO THIS CODE. */ | |
eaa9c2e7 | 774 | |
b7577823 | 775 | switch (number) |
9fda1a39 | 776 | { |
1a85826e KR |
777 | /* FIXME: These are needed to parse IEEE objects. */ |
778 | case 68000: | |
779 | arch = bfd_arch_m68k; | |
780 | number = bfd_mach_m68000; | |
781 | break; | |
b7577823 | 782 | case 68010: |
1a85826e KR |
783 | arch = bfd_arch_m68k; |
784 | number = bfd_mach_m68010; | |
785 | break; | |
b7577823 | 786 | case 68020: |
1a85826e KR |
787 | arch = bfd_arch_m68k; |
788 | number = bfd_mach_m68020; | |
789 | break; | |
b7577823 | 790 | case 68030: |
1a85826e KR |
791 | arch = bfd_arch_m68k; |
792 | number = bfd_mach_m68030; | |
793 | break; | |
b7577823 | 794 | case 68040: |
1a85826e KR |
795 | arch = bfd_arch_m68k; |
796 | number = bfd_mach_m68040; | |
797 | break; | |
798 | case 68060: | |
799 | arch = bfd_arch_m68k; | |
800 | number = bfd_mach_m68060; | |
801 | break; | |
b7577823 | 802 | case 68332: |
1a85826e KR |
803 | arch = bfd_arch_m68k; |
804 | number = bfd_mach_cpu32; | |
b7577823 | 805 | break; |
5bc513b4 | 806 | |
b7577823 ILT |
807 | case 32000: |
808 | arch = bfd_arch_we32k; | |
809 | break; | |
4e6f9223 | 810 | |
b7577823 | 811 | case 3000: |
cd66558c NC |
812 | arch = bfd_arch_mips; |
813 | number = bfd_mach_mips3000; | |
814 | break; | |
815 | ||
b7577823 | 816 | case 4000: |
b7577823 | 817 | arch = bfd_arch_mips; |
cd66558c | 818 | number = bfd_mach_mips4000; |
b7577823 | 819 | break; |
4a81b561 | 820 | |
b7577823 ILT |
821 | case 6000: |
822 | arch = bfd_arch_rs6000; | |
823 | break; | |
9fda1a39 | 824 | |
b7577823 ILT |
825 | default: |
826 | return false; | |
9fda1a39 | 827 | } |
5bc513b4 | 828 | |
b7577823 ILT |
829 | if (arch != info->arch) |
830 | return false; | |
9fda1a39 | 831 | |
b7577823 ILT |
832 | if (number != info->mach) |
833 | return false; | |
9fda1a39 | 834 | |
b7577823 | 835 | return true; |
4a81b561 | 836 | } |
c618de01 SC |
837 | |
838 | ||
9fda1a39 SC |
839 | /* |
840 | FUNCTION | |
841 | bfd_get_arch_info | |
c618de01 | 842 | |
9fda1a39 | 843 | SYNOPSIS |
5bc513b4 | 844 | const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd); |
c618de01 | 845 | |
c188b0be DM |
846 | DESCRIPTION |
847 | Return the architecture info struct in @var{abfd}. | |
4e6f9223 | 848 | */ |
c618de01 | 849 | |
5bc513b4 | 850 | const bfd_arch_info_type * |
d94aca1a MT |
851 | bfd_get_arch_info (abfd) |
852 | bfd *abfd; | |
4e6f9223 | 853 | { |
5bc513b4 | 854 | return abfd->arch_info; |
4e6f9223 | 855 | } |
cbdc7909 JG |
856 | |
857 | ||
9fda1a39 SC |
858 | /* |
859 | FUNCTION | |
860 | bfd_lookup_arch | |
861 | ||
9fda1a39 | 862 | SYNOPSIS |
5bc513b4 | 863 | const bfd_arch_info_type *bfd_lookup_arch |
9fda1a39 SC |
864 | (enum bfd_architecture |
865 | arch, | |
ae115e51 | 866 | unsigned long machine); |
cbdc7909 | 867 | |
ce07dd7c | 868 | DESCRIPTION |
c188b0be DM |
869 | Look for the architecure info structure which matches the |
870 | arguments @var{arch} and @var{machine}. A machine of 0 matches the | |
ce07dd7c KR |
871 | machine/architecture structure which marks itself as the |
872 | default. | |
cbdc7909 JG |
873 | */ |
874 | ||
5bc513b4 | 875 | const bfd_arch_info_type * |
d94aca1a MT |
876 | bfd_lookup_arch (arch, machine) |
877 | enum bfd_architecture arch; | |
ae115e51 | 878 | unsigned long machine; |
cbdc7909 | 879 | { |
5bc513b4 DE |
880 | const bfd_arch_info_type * const *app, *ap; |
881 | ||
882 | for (app = bfd_archures_list; *app != NULL; app++) | |
883 | { | |
884 | for (ap = *app; ap != NULL; ap = ap->next) | |
885 | { | |
886 | if (ap->arch == arch | |
887 | && (ap->mach == machine | |
888 | || (machine == 0 && ap->the_default))) | |
889 | return ap; | |
9fda1a39 | 890 | } |
5bc513b4 DE |
891 | } |
892 | ||
893 | return NULL; | |
cbdc7909 JG |
894 | } |
895 | ||
896 | ||
9fda1a39 SC |
897 | /* |
898 | FUNCTION | |
899 | bfd_printable_arch_mach | |
900 | ||
ce07dd7c | 901 | SYNOPSIS |
5bc513b4 | 902 | const char *bfd_printable_arch_mach |
ce07dd7c KR |
903 | (enum bfd_architecture arch, unsigned long machine); |
904 | ||
9fda1a39 SC |
905 | DESCRIPTION |
906 | Return a printable string representing the architecture and | |
907 | machine type. | |
cbdc7909 | 908 | |
c188b0be | 909 | This routine is depreciated. |
cbdc7909 JG |
910 | */ |
911 | ||
5bc513b4 | 912 | const char * |
d94aca1a MT |
913 | bfd_printable_arch_mach (arch, machine) |
914 | enum bfd_architecture arch; | |
915 | unsigned long machine; | |
cbdc7909 | 916 | { |
5bc513b4 DE |
917 | const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine); |
918 | ||
919 | if (ap) | |
920 | return ap->printable_name; | |
9fda1a39 | 921 | return "UNKNOWN!"; |
cbdc7909 | 922 | } |