]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - bfd/archures.c
ChangeLog:
[thirdparty/binutils-gdb.git] / bfd / archures.c
1 /* BFD library support routines for architectures.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
5 Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
6
7 This file is part of BFD, the Binary File Descriptor library.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libbfd.h"
26 #include "safe-ctype.h"
27
28 /*
29
30 SECTION
31 Architectures
32
33 BFD keeps one atom in a BFD describing the
34 architecture of the data attached to the BFD: a pointer to a
35 <<bfd_arch_info_type>>.
36
37 Pointers to structures can be requested independently of a BFD
38 so that an architecture's information can be interrogated
39 without access to an open BFD.
40
41 The architecture information is provided by each architecture package.
42 The set of default architectures is selected by the macro
43 <<SELECT_ARCHITECTURES>>. This is normally set up in the
44 @file{config/@var{target}.mt} file of your choice. If the name is not
45 defined, then all the architectures supported are included.
46
47 When BFD starts up, all the architectures are called with an
48 initialize method. It is up to the architecture back end to
49 insert as many items into the list of architectures as it wants to;
50 generally this would be one for each machine and one for the
51 default case (an item with a machine field of 0).
52
53 BFD's idea of an architecture is implemented in @file{archures.c}.
54 */
55
56 /*
57
58 SUBSECTION
59 bfd_architecture
60
61 DESCRIPTION
62 This enum gives the object file's CPU architecture, in a
63 global sense---i.e., what processor family does it belong to?
64 Another field indicates which processor within
65 the family is in use. The machine gives a number which
66 distinguishes different versions of the architecture,
67 containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
68 and 68020 and 68030 for Motorola 68020 and 68030.
69
70 .enum bfd_architecture
71 .{
72 . bfd_arch_unknown, {* File arch not known. *}
73 . bfd_arch_obscure, {* Arch known, not one of these. *}
74 . bfd_arch_m68k, {* Motorola 68xxx *}
75 .#define bfd_mach_m68000 1
76 .#define bfd_mach_m68008 2
77 .#define bfd_mach_m68010 3
78 .#define bfd_mach_m68020 4
79 .#define bfd_mach_m68030 5
80 .#define bfd_mach_m68040 6
81 .#define bfd_mach_m68060 7
82 .#define bfd_mach_cpu32 8
83 .#define bfd_mach_mcf5200 9
84 .#define bfd_mach_mcf5206e 10
85 .#define bfd_mach_mcf5307 11
86 .#define bfd_mach_mcf5407 12
87 .#define bfd_mach_mcf528x 13
88 .#define bfd_mach_mcfv4e 14
89 .#define bfd_mach_mcf521x 15
90 .#define bfd_mach_mcf5249 16
91 .#define bfd_mach_mcf547x 17
92 .#define bfd_mach_mcf548x 18
93 . bfd_arch_vax, {* DEC Vax *}
94 . bfd_arch_i960, {* Intel 960 *}
95 . {* The order of the following is important.
96 . lower number indicates a machine type that
97 . only accepts a subset of the instructions
98 . available to machines with higher numbers.
99 . The exception is the "ca", which is
100 . incompatible with all other machines except
101 . "core". *}
102 .
103 .#define bfd_mach_i960_core 1
104 .#define bfd_mach_i960_ka_sa 2
105 .#define bfd_mach_i960_kb_sb 3
106 .#define bfd_mach_i960_mc 4
107 .#define bfd_mach_i960_xa 5
108 .#define bfd_mach_i960_ca 6
109 .#define bfd_mach_i960_jx 7
110 .#define bfd_mach_i960_hx 8
111 .
112 . bfd_arch_or32, {* OpenRISC 32 *}
113 .
114 . bfd_arch_a29k, {* AMD 29000 *}
115 . bfd_arch_sparc, {* SPARC *}
116 .#define bfd_mach_sparc 1
117 .{* The difference between v8plus and v9 is that v9 is a true 64 bit env. *}
118 .#define bfd_mach_sparc_sparclet 2
119 .#define bfd_mach_sparc_sparclite 3
120 .#define bfd_mach_sparc_v8plus 4
121 .#define bfd_mach_sparc_v8plusa 5 {* with ultrasparc add'ns. *}
122 .#define bfd_mach_sparc_sparclite_le 6
123 .#define bfd_mach_sparc_v9 7
124 .#define bfd_mach_sparc_v9a 8 {* with ultrasparc add'ns. *}
125 .#define bfd_mach_sparc_v8plusb 9 {* with cheetah add'ns. *}
126 .#define bfd_mach_sparc_v9b 10 {* with cheetah add'ns. *}
127 .{* Nonzero if MACH has the v9 instruction set. *}
128 .#define bfd_mach_sparc_v9_p(mach) \
129 . ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9b \
130 . && (mach) != bfd_mach_sparc_sparclite_le)
131 .{* Nonzero if MACH is a 64 bit sparc architecture. *}
132 .#define bfd_mach_sparc_64bit_p(mach) \
133 . ((mach) >= bfd_mach_sparc_v9 && (mach) != bfd_mach_sparc_v8plusb)
134 . bfd_arch_mips, {* MIPS Rxxxx *}
135 .#define bfd_mach_mips3000 3000
136 .#define bfd_mach_mips3900 3900
137 .#define bfd_mach_mips4000 4000
138 .#define bfd_mach_mips4010 4010
139 .#define bfd_mach_mips4100 4100
140 .#define bfd_mach_mips4111 4111
141 .#define bfd_mach_mips4120 4120
142 .#define bfd_mach_mips4300 4300
143 .#define bfd_mach_mips4400 4400
144 .#define bfd_mach_mips4600 4600
145 .#define bfd_mach_mips4650 4650
146 .#define bfd_mach_mips5000 5000
147 .#define bfd_mach_mips5400 5400
148 .#define bfd_mach_mips5500 5500
149 .#define bfd_mach_mips6000 6000
150 .#define bfd_mach_mips7000 7000
151 .#define bfd_mach_mips8000 8000
152 .#define bfd_mach_mips9000 9000
153 .#define bfd_mach_mips10000 10000
154 .#define bfd_mach_mips12000 12000
155 .#define bfd_mach_mips16 16
156 .#define bfd_mach_mips5 5
157 .#define bfd_mach_mips_sb1 12310201 {* octal 'SB', 01 *}
158 .#define bfd_mach_mipsisa32 32
159 .#define bfd_mach_mipsisa32r2 33
160 .#define bfd_mach_mipsisa64 64
161 .#define bfd_mach_mipsisa64r2 65
162 . bfd_arch_i386, {* Intel 386 *}
163 .#define bfd_mach_i386_i386 1
164 .#define bfd_mach_i386_i8086 2
165 .#define bfd_mach_i386_i386_intel_syntax 3
166 .#define bfd_mach_x86_64 64
167 .#define bfd_mach_x86_64_intel_syntax 65
168 . bfd_arch_we32k, {* AT&T WE32xxx *}
169 . bfd_arch_tahoe, {* CCI/Harris Tahoe *}
170 . bfd_arch_i860, {* Intel 860 *}
171 . bfd_arch_i370, {* IBM 360/370 Mainframes *}
172 . bfd_arch_romp, {* IBM ROMP PC/RT *}
173 . bfd_arch_alliant, {* Alliant *}
174 . bfd_arch_convex, {* Convex *}
175 . bfd_arch_m88k, {* Motorola 88xxx *}
176 . bfd_arch_m98k, {* Motorola 98xxx *}
177 . bfd_arch_pyramid, {* Pyramid Technology *}
178 . bfd_arch_h8300, {* Renesas H8/300 (formerly Hitachi H8/300) *}
179 .#define bfd_mach_h8300 1
180 .#define bfd_mach_h8300h 2
181 .#define bfd_mach_h8300s 3
182 .#define bfd_mach_h8300hn 4
183 .#define bfd_mach_h8300sn 5
184 .#define bfd_mach_h8300sx 6
185 .#define bfd_mach_h8300sxn 7
186 . bfd_arch_pdp11, {* DEC PDP-11 *}
187 . bfd_arch_powerpc, {* PowerPC *}
188 .#define bfd_mach_ppc 32
189 .#define bfd_mach_ppc64 64
190 .#define bfd_mach_ppc_403 403
191 .#define bfd_mach_ppc_403gc 4030
192 .#define bfd_mach_ppc_505 505
193 .#define bfd_mach_ppc_601 601
194 .#define bfd_mach_ppc_602 602
195 .#define bfd_mach_ppc_603 603
196 .#define bfd_mach_ppc_ec603e 6031
197 .#define bfd_mach_ppc_604 604
198 .#define bfd_mach_ppc_620 620
199 .#define bfd_mach_ppc_630 630
200 .#define bfd_mach_ppc_750 750
201 .#define bfd_mach_ppc_860 860
202 .#define bfd_mach_ppc_a35 35
203 .#define bfd_mach_ppc_rs64ii 642
204 .#define bfd_mach_ppc_rs64iii 643
205 .#define bfd_mach_ppc_7400 7400
206 .#define bfd_mach_ppc_e500 500
207 . bfd_arch_rs6000, {* IBM RS/6000 *}
208 .#define bfd_mach_rs6k 6000
209 .#define bfd_mach_rs6k_rs1 6001
210 .#define bfd_mach_rs6k_rsc 6003
211 .#define bfd_mach_rs6k_rs2 6002
212 . bfd_arch_hppa, {* HP PA RISC *}
213 .#define bfd_mach_hppa10 10
214 .#define bfd_mach_hppa11 11
215 .#define bfd_mach_hppa20 20
216 .#define bfd_mach_hppa20w 25
217 . bfd_arch_d10v, {* Mitsubishi D10V *}
218 .#define bfd_mach_d10v 1
219 .#define bfd_mach_d10v_ts2 2
220 .#define bfd_mach_d10v_ts3 3
221 . bfd_arch_d30v, {* Mitsubishi D30V *}
222 . bfd_arch_dlx, {* DLX *}
223 . bfd_arch_m68hc11, {* Motorola 68HC11 *}
224 . bfd_arch_m68hc12, {* Motorola 68HC12 *}
225 .#define bfd_mach_m6812_default 0
226 .#define bfd_mach_m6812 1
227 .#define bfd_mach_m6812s 2
228 . bfd_arch_z8k, {* Zilog Z8000 *}
229 .#define bfd_mach_z8001 1
230 .#define bfd_mach_z8002 2
231 . bfd_arch_h8500, {* Renesas H8/500 (formerly Hitachi H8/500) *}
232 . bfd_arch_sh, {* Renesas / SuperH SH (formerly Hitachi SH) *}
233 .#define bfd_mach_sh 1
234 .#define bfd_mach_sh2 0x20
235 .#define bfd_mach_sh_dsp 0x2d
236 .#define bfd_mach_sh2a 0x2a
237 .#define bfd_mach_sh2a_nofpu 0x2b
238 .#define bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu 0x2a1
239 .#define bfd_mach_sh2a_nofpu_or_sh3_nommu 0x2a2
240 .#define bfd_mach_sh2a_or_sh4 0x2a3
241 .#define bfd_mach_sh2a_or_sh3e 0x2a4
242 .#define bfd_mach_sh2e 0x2e
243 .#define bfd_mach_sh3 0x30
244 .#define bfd_mach_sh3_nommu 0x31
245 .#define bfd_mach_sh3_dsp 0x3d
246 .#define bfd_mach_sh3e 0x3e
247 .#define bfd_mach_sh4 0x40
248 .#define bfd_mach_sh4_nofpu 0x41
249 .#define bfd_mach_sh4_nommu_nofpu 0x42
250 .#define bfd_mach_sh4a 0x4a
251 .#define bfd_mach_sh4a_nofpu 0x4b
252 .#define bfd_mach_sh4al_dsp 0x4d
253 .#define bfd_mach_sh5 0x50
254 . bfd_arch_alpha, {* Dec Alpha *}
255 .#define bfd_mach_alpha_ev4 0x10
256 .#define bfd_mach_alpha_ev5 0x20
257 .#define bfd_mach_alpha_ev6 0x30
258 . bfd_arch_arm, {* Advanced Risc Machines ARM. *}
259 .#define bfd_mach_arm_unknown 0
260 .#define bfd_mach_arm_2 1
261 .#define bfd_mach_arm_2a 2
262 .#define bfd_mach_arm_3 3
263 .#define bfd_mach_arm_3M 4
264 .#define bfd_mach_arm_4 5
265 .#define bfd_mach_arm_4T 6
266 .#define bfd_mach_arm_5 7
267 .#define bfd_mach_arm_5T 8
268 .#define bfd_mach_arm_5TE 9
269 .#define bfd_mach_arm_XScale 10
270 .#define bfd_mach_arm_ep9312 11
271 .#define bfd_mach_arm_iWMMXt 12
272 . bfd_arch_ns32k, {* National Semiconductors ns32000 *}
273 . bfd_arch_w65, {* WDC 65816 *}
274 . bfd_arch_tic30, {* Texas Instruments TMS320C30 *}
275 . bfd_arch_tic4x, {* Texas Instruments TMS320C3X/4X *}
276 .#define bfd_mach_tic3x 30
277 .#define bfd_mach_tic4x 40
278 . bfd_arch_tic54x, {* Texas Instruments TMS320C54X *}
279 . bfd_arch_tic80, {* TI TMS320c80 (MVP) *}
280 . bfd_arch_v850, {* NEC V850 *}
281 .#define bfd_mach_v850 1
282 .#define bfd_mach_v850e 'E'
283 .#define bfd_mach_v850e1 '1'
284 . bfd_arch_arc, {* ARC Cores *}
285 .#define bfd_mach_arc_5 5
286 .#define bfd_mach_arc_6 6
287 .#define bfd_mach_arc_7 7
288 .#define bfd_mach_arc_8 8
289 . bfd_arch_m32c, {* Renesas M16C/M32C. *}
290 .#define bfd_mach_m16c 0x75
291 .#define bfd_mach_m32c 0x78
292 . bfd_arch_m32r, {* Renesas M32R (formerly Mitsubishi M32R/D) *}
293 .#define bfd_mach_m32r 1 {* For backwards compatibility. *}
294 .#define bfd_mach_m32rx 'x'
295 .#define bfd_mach_m32r2 '2'
296 . bfd_arch_mn10200, {* Matsushita MN10200 *}
297 . bfd_arch_mn10300, {* Matsushita MN10300 *}
298 .#define bfd_mach_mn10300 300
299 .#define bfd_mach_am33 330
300 .#define bfd_mach_am33_2 332
301 . bfd_arch_fr30,
302 .#define bfd_mach_fr30 0x46523330
303 . bfd_arch_frv,
304 .#define bfd_mach_frv 1
305 .#define bfd_mach_frvsimple 2
306 .#define bfd_mach_fr300 300
307 .#define bfd_mach_fr400 400
308 .#define bfd_mach_fr450 450
309 .#define bfd_mach_frvtomcat 499 {* fr500 prototype *}
310 .#define bfd_mach_fr500 500
311 .#define bfd_mach_fr550 550
312 . bfd_arch_mcore,
313 . bfd_arch_ia64, {* HP/Intel ia64 *}
314 .#define bfd_mach_ia64_elf64 64
315 .#define bfd_mach_ia64_elf32 32
316 . bfd_arch_ip2k, {* Ubicom IP2K microcontrollers. *}
317 .#define bfd_mach_ip2022 1
318 .#define bfd_mach_ip2022ext 2
319 . bfd_arch_iq2000, {* Vitesse IQ2000. *}
320 .#define bfd_mach_iq2000 1
321 .#define bfd_mach_iq10 2
322 . bfd_arch_ms1,
323 .#define bfd_mach_ms1 1
324 .#define bfd_mach_mrisc2 2
325 . bfd_arch_pj,
326 . bfd_arch_avr, {* Atmel AVR microcontrollers. *}
327 .#define bfd_mach_avr1 1
328 .#define bfd_mach_avr2 2
329 .#define bfd_mach_avr3 3
330 .#define bfd_mach_avr4 4
331 .#define bfd_mach_avr5 5
332 . bfd_arch_cr16c, {* National Semiconductor CompactRISC. *}
333 .#define bfd_mach_cr16c 1
334 . bfd_arch_crx, {* National Semiconductor CRX. *}
335 .#define bfd_mach_crx 1
336 . bfd_arch_cris, {* Axis CRIS *}
337 .#define bfd_mach_cris_v0_v10 255
338 .#define bfd_mach_cris_v32 32
339 .#define bfd_mach_cris_v10_v32 1032
340 . bfd_arch_s390, {* IBM s390 *}
341 .#define bfd_mach_s390_31 31
342 .#define bfd_mach_s390_64 64
343 . bfd_arch_openrisc, {* OpenRISC *}
344 . bfd_arch_mmix, {* Donald Knuth's educational processor. *}
345 . bfd_arch_xstormy16,
346 .#define bfd_mach_xstormy16 1
347 . bfd_arch_msp430, {* Texas Instruments MSP430 architecture. *}
348 .#define bfd_mach_msp11 11
349 .#define bfd_mach_msp110 110
350 .#define bfd_mach_msp12 12
351 .#define bfd_mach_msp13 13
352 .#define bfd_mach_msp14 14
353 .#define bfd_mach_msp15 15
354 .#define bfd_mach_msp16 16
355 .#define bfd_mach_msp31 31
356 .#define bfd_mach_msp32 32
357 .#define bfd_mach_msp33 33
358 .#define bfd_mach_msp41 41
359 .#define bfd_mach_msp42 42
360 .#define bfd_mach_msp43 43
361 .#define bfd_mach_msp44 44
362 . bfd_arch_xtensa, {* Tensilica's Xtensa cores. *}
363 .#define bfd_mach_xtensa 1
364 . bfd_arch_maxq, {* Dallas MAXQ 10/20 *}
365 .#define bfd_mach_maxq10 10
366 .#define bfd_mach_maxq20 20
367 . bfd_arch_last
368 . };
369 */
370
371 /*
372 SUBSECTION
373 bfd_arch_info
374
375 DESCRIPTION
376 This structure contains information on architectures for use
377 within BFD.
378
379 .
380 .typedef struct bfd_arch_info
381 .{
382 . int bits_per_word;
383 . int bits_per_address;
384 . int bits_per_byte;
385 . enum bfd_architecture arch;
386 . unsigned long mach;
387 . const char *arch_name;
388 . const char *printable_name;
389 . unsigned int section_align_power;
390 . {* TRUE if this is the default machine for the architecture.
391 . The default arch should be the first entry for an arch so that
392 . all the entries for that arch can be accessed via <<next>>. *}
393 . bfd_boolean the_default;
394 . const struct bfd_arch_info * (*compatible)
395 . (const struct bfd_arch_info *a, const struct bfd_arch_info *b);
396 .
397 . bfd_boolean (*scan) (const struct bfd_arch_info *, const char *);
398 .
399 . const struct bfd_arch_info *next;
400 .}
401 .bfd_arch_info_type;
402 .
403 */
404
405 extern const bfd_arch_info_type bfd_a29k_arch;
406 extern const bfd_arch_info_type bfd_alpha_arch;
407 extern const bfd_arch_info_type bfd_arc_arch;
408 extern const bfd_arch_info_type bfd_arm_arch;
409 extern const bfd_arch_info_type bfd_avr_arch;
410 extern const bfd_arch_info_type bfd_cr16c_arch;
411 extern const bfd_arch_info_type bfd_cris_arch;
412 extern const bfd_arch_info_type bfd_crx_arch;
413 extern const bfd_arch_info_type bfd_d10v_arch;
414 extern const bfd_arch_info_type bfd_d30v_arch;
415 extern const bfd_arch_info_type bfd_dlx_arch;
416 extern const bfd_arch_info_type bfd_fr30_arch;
417 extern const bfd_arch_info_type bfd_frv_arch;
418 extern const bfd_arch_info_type bfd_h8300_arch;
419 extern const bfd_arch_info_type bfd_h8500_arch;
420 extern const bfd_arch_info_type bfd_hppa_arch;
421 extern const bfd_arch_info_type bfd_i370_arch;
422 extern const bfd_arch_info_type bfd_i386_arch;
423 extern const bfd_arch_info_type bfd_i860_arch;
424 extern const bfd_arch_info_type bfd_i960_arch;
425 extern const bfd_arch_info_type bfd_ia64_arch;
426 extern const bfd_arch_info_type bfd_ip2k_arch;
427 extern const bfd_arch_info_type bfd_iq2000_arch;
428 extern const bfd_arch_info_type bfd_m32c_arch;
429 extern const bfd_arch_info_type bfd_m32r_arch;
430 extern const bfd_arch_info_type bfd_m68hc11_arch;
431 extern const bfd_arch_info_type bfd_m68hc12_arch;
432 extern const bfd_arch_info_type bfd_m68k_arch;
433 extern const bfd_arch_info_type bfd_m88k_arch;
434 extern const bfd_arch_info_type bfd_maxq_arch;
435 extern const bfd_arch_info_type bfd_mcore_arch;
436 extern const bfd_arch_info_type bfd_mips_arch;
437 extern const bfd_arch_info_type bfd_mmix_arch;
438 extern const bfd_arch_info_type bfd_mn10200_arch;
439 extern const bfd_arch_info_type bfd_mn10300_arch;
440 extern const bfd_arch_info_type bfd_msp430_arch;
441 extern const bfd_arch_info_type bfd_ns32k_arch;
442 extern const bfd_arch_info_type bfd_openrisc_arch;
443 extern const bfd_arch_info_type bfd_or32_arch;
444 extern const bfd_arch_info_type bfd_pdp11_arch;
445 extern const bfd_arch_info_type bfd_pj_arch;
446 extern const bfd_arch_info_type bfd_powerpc_archs[];
447 #define bfd_powerpc_arch bfd_powerpc_archs[0]
448 extern const bfd_arch_info_type bfd_rs6000_arch;
449 extern const bfd_arch_info_type bfd_s390_arch;
450 extern const bfd_arch_info_type bfd_sh_arch;
451 extern const bfd_arch_info_type bfd_sparc_arch;
452 extern const bfd_arch_info_type bfd_tic30_arch;
453 extern const bfd_arch_info_type bfd_tic4x_arch;
454 extern const bfd_arch_info_type bfd_tic54x_arch;
455 extern const bfd_arch_info_type bfd_tic80_arch;
456 extern const bfd_arch_info_type bfd_v850_arch;
457 extern const bfd_arch_info_type bfd_vax_arch;
458 extern const bfd_arch_info_type bfd_we32k_arch;
459 extern const bfd_arch_info_type bfd_w65_arch;
460 extern const bfd_arch_info_type bfd_xstormy16_arch;
461 extern const bfd_arch_info_type bfd_xtensa_arch;
462 extern const bfd_arch_info_type bfd_z8k_arch;
463 extern const bfd_arch_info_type bfd_ms1_arch;
464
465 static const bfd_arch_info_type * const bfd_archures_list[] =
466 {
467 #ifdef SELECT_ARCHITECTURES
468 SELECT_ARCHITECTURES,
469 #else
470 &bfd_a29k_arch,
471 &bfd_alpha_arch,
472 &bfd_arc_arch,
473 &bfd_arm_arch,
474 &bfd_avr_arch,
475 &bfd_cr16c_arch,
476 &bfd_cris_arch,
477 &bfd_crx_arch,
478 &bfd_d10v_arch,
479 &bfd_d30v_arch,
480 &bfd_dlx_arch,
481 &bfd_fr30_arch,
482 &bfd_frv_arch,
483 &bfd_h8300_arch,
484 &bfd_h8500_arch,
485 &bfd_hppa_arch,
486 &bfd_i370_arch,
487 &bfd_i386_arch,
488 &bfd_i860_arch,
489 &bfd_i960_arch,
490 &bfd_ia64_arch,
491 &bfd_ip2k_arch,
492 &bfd_iq2000_arch,
493 &bfd_m32r_arch,
494 &bfd_m68hc11_arch,
495 &bfd_m68hc12_arch,
496 &bfd_m68k_arch,
497 &bfd_m88k_arch,
498 &bfd_maxq_arch,
499 &bfd_mcore_arch,
500 &bfd_mips_arch,
501 &bfd_mmix_arch,
502 &bfd_mn10200_arch,
503 &bfd_mn10300_arch,
504 &bfd_ms1_arch,
505 &bfd_msp430_arch,
506 &bfd_ns32k_arch,
507 &bfd_openrisc_arch,
508 &bfd_or32_arch,
509 &bfd_pdp11_arch,
510 &bfd_powerpc_arch,
511 &bfd_rs6000_arch,
512 &bfd_s390_arch,
513 &bfd_sh_arch,
514 &bfd_sparc_arch,
515 &bfd_tic30_arch,
516 &bfd_tic4x_arch,
517 &bfd_tic54x_arch,
518 &bfd_tic80_arch,
519 &bfd_v850_arch,
520 &bfd_vax_arch,
521 &bfd_w65_arch,
522 &bfd_we32k_arch,
523 &bfd_xstormy16_arch,
524 &bfd_xtensa_arch,
525 &bfd_z8k_arch,
526 &bfd_m32c_arch,
527 #endif
528 0
529 };
530
531 /*
532 FUNCTION
533 bfd_printable_name
534
535 SYNOPSIS
536 const char *bfd_printable_name (bfd *abfd);
537
538 DESCRIPTION
539 Return a printable string representing the architecture and machine
540 from the pointer to the architecture info structure.
541
542 */
543
544 const char *
545 bfd_printable_name (bfd *abfd)
546 {
547 return abfd->arch_info->printable_name;
548 }
549
550 /*
551 FUNCTION
552 bfd_scan_arch
553
554 SYNOPSIS
555 const bfd_arch_info_type *bfd_scan_arch (const char *string);
556
557 DESCRIPTION
558 Figure out if BFD supports any cpu which could be described with
559 the name @var{string}. Return a pointer to an <<arch_info>>
560 structure if a machine is found, otherwise NULL.
561 */
562
563 const bfd_arch_info_type *
564 bfd_scan_arch (const char *string)
565 {
566 const bfd_arch_info_type * const *app, *ap;
567
568 /* Look through all the installed architectures. */
569 for (app = bfd_archures_list; *app != NULL; app++)
570 {
571 for (ap = *app; ap != NULL; ap = ap->next)
572 {
573 if (ap->scan (ap, string))
574 return ap;
575 }
576 }
577
578 return NULL;
579 }
580
581 /*
582 FUNCTION
583 bfd_arch_list
584
585 SYNOPSIS
586 const char **bfd_arch_list (void);
587
588 DESCRIPTION
589 Return a freshly malloced NULL-terminated vector of the names
590 of all the valid BFD architectures. Do not modify the names.
591 */
592
593 const char **
594 bfd_arch_list (void)
595 {
596 int vec_length = 0;
597 const char **name_ptr;
598 const char **name_list;
599 const bfd_arch_info_type * const *app;
600 bfd_size_type amt;
601
602 /* Determine the number of architectures. */
603 vec_length = 0;
604 for (app = bfd_archures_list; *app != NULL; app++)
605 {
606 const bfd_arch_info_type *ap;
607 for (ap = *app; ap != NULL; ap = ap->next)
608 {
609 vec_length++;
610 }
611 }
612
613 amt = (vec_length + 1) * sizeof (char **);
614 name_list = bfd_malloc (amt);
615 if (name_list == NULL)
616 return NULL;
617
618 /* Point the list at each of the names. */
619 name_ptr = name_list;
620 for (app = bfd_archures_list; *app != NULL; app++)
621 {
622 const bfd_arch_info_type *ap;
623 for (ap = *app; ap != NULL; ap = ap->next)
624 {
625 *name_ptr = ap->printable_name;
626 name_ptr++;
627 }
628 }
629 *name_ptr = NULL;
630
631 return name_list;
632 }
633
634 /*
635 FUNCTION
636 bfd_arch_get_compatible
637
638 SYNOPSIS
639 const bfd_arch_info_type *bfd_arch_get_compatible
640 (const bfd *abfd, const bfd *bbfd, bfd_boolean accept_unknowns);
641
642 DESCRIPTION
643 Determine whether two BFDs' architectures and machine types
644 are compatible. Calculates the lowest common denominator
645 between the two architectures and machine types implied by
646 the BFDs and returns a pointer to an <<arch_info>> structure
647 describing the compatible machine.
648 */
649
650 const bfd_arch_info_type *
651 bfd_arch_get_compatible (const bfd *abfd,
652 const bfd *bbfd,
653 bfd_boolean accept_unknowns)
654 {
655 const bfd * ubfd = NULL;
656
657 /* Look for an unknown architecture. */
658 if (((ubfd = abfd) && ubfd->arch_info->arch == bfd_arch_unknown)
659 || ((ubfd = bbfd) && ubfd->arch_info->arch == bfd_arch_unknown))
660 {
661 /* We can allow an unknown architecture if accept_unknowns
662 is true, or if the target is the "binary" format, which
663 has an unknown architecture. Since the binary format can
664 only be set by explicit request from the user, it is safe
665 to assume that they know what they are doing. */
666 if (accept_unknowns
667 || strcmp (bfd_get_target (ubfd), "binary") == 0)
668 return ubfd->arch_info;
669 return NULL;
670 }
671
672 /* Otherwise architecture-specific code has to decide. */
673 return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
674 }
675
676 /*
677 INTERNAL_DEFINITION
678 bfd_default_arch_struct
679
680 DESCRIPTION
681 The <<bfd_default_arch_struct>> is an item of
682 <<bfd_arch_info_type>> which has been initialized to a fairly
683 generic state. A BFD starts life by pointing to this
684 structure, until the correct back end has determined the real
685 architecture of the file.
686
687 .extern const bfd_arch_info_type bfd_default_arch_struct;
688 */
689
690 const bfd_arch_info_type bfd_default_arch_struct = {
691 32, 32, 8, bfd_arch_unknown, 0, "unknown", "unknown", 2, TRUE,
692 bfd_default_compatible,
693 bfd_default_scan,
694 0,
695 };
696
697 /*
698 FUNCTION
699 bfd_set_arch_info
700
701 SYNOPSIS
702 void bfd_set_arch_info (bfd *abfd, const bfd_arch_info_type *arg);
703
704 DESCRIPTION
705 Set the architecture info of @var{abfd} to @var{arg}.
706 */
707
708 void
709 bfd_set_arch_info (bfd *abfd, const bfd_arch_info_type *arg)
710 {
711 abfd->arch_info = arg;
712 }
713
714 /*
715 INTERNAL_FUNCTION
716 bfd_default_set_arch_mach
717
718 SYNOPSIS
719 bfd_boolean bfd_default_set_arch_mach
720 (bfd *abfd, enum bfd_architecture arch, unsigned long mach);
721
722 DESCRIPTION
723 Set the architecture and machine type in BFD @var{abfd}
724 to @var{arch} and @var{mach}. Find the correct
725 pointer to a structure and insert it into the <<arch_info>>
726 pointer.
727 */
728
729 bfd_boolean
730 bfd_default_set_arch_mach (bfd *abfd,
731 enum bfd_architecture arch,
732 unsigned long mach)
733 {
734 abfd->arch_info = bfd_lookup_arch (arch, mach);
735 if (abfd->arch_info != NULL)
736 return TRUE;
737
738 abfd->arch_info = &bfd_default_arch_struct;
739 bfd_set_error (bfd_error_bad_value);
740 return FALSE;
741 }
742
743 /*
744 FUNCTION
745 bfd_get_arch
746
747 SYNOPSIS
748 enum bfd_architecture bfd_get_arch (bfd *abfd);
749
750 DESCRIPTION
751 Return the enumerated type which describes the BFD @var{abfd}'s
752 architecture.
753 */
754
755 enum bfd_architecture
756 bfd_get_arch (bfd *abfd)
757 {
758 return abfd->arch_info->arch;
759 }
760
761 /*
762 FUNCTION
763 bfd_get_mach
764
765 SYNOPSIS
766 unsigned long bfd_get_mach (bfd *abfd);
767
768 DESCRIPTION
769 Return the long type which describes the BFD @var{abfd}'s
770 machine.
771 */
772
773 unsigned long
774 bfd_get_mach (bfd *abfd)
775 {
776 return abfd->arch_info->mach;
777 }
778
779 /*
780 FUNCTION
781 bfd_arch_bits_per_byte
782
783 SYNOPSIS
784 unsigned int bfd_arch_bits_per_byte (bfd *abfd);
785
786 DESCRIPTION
787 Return the number of bits in one of the BFD @var{abfd}'s
788 architecture's bytes.
789 */
790
791 unsigned int
792 bfd_arch_bits_per_byte (bfd *abfd)
793 {
794 return abfd->arch_info->bits_per_byte;
795 }
796
797 /*
798 FUNCTION
799 bfd_arch_bits_per_address
800
801 SYNOPSIS
802 unsigned int bfd_arch_bits_per_address (bfd *abfd);
803
804 DESCRIPTION
805 Return the number of bits in one of the BFD @var{abfd}'s
806 architecture's addresses.
807 */
808
809 unsigned int
810 bfd_arch_bits_per_address (bfd *abfd)
811 {
812 return abfd->arch_info->bits_per_address;
813 }
814
815 /*
816 INTERNAL_FUNCTION
817 bfd_default_compatible
818
819 SYNOPSIS
820 const bfd_arch_info_type *bfd_default_compatible
821 (const bfd_arch_info_type *a, const bfd_arch_info_type *b);
822
823 DESCRIPTION
824 The default function for testing for compatibility.
825 */
826
827 const bfd_arch_info_type *
828 bfd_default_compatible (const bfd_arch_info_type *a,
829 const bfd_arch_info_type *b)
830 {
831 if (a->arch != b->arch)
832 return NULL;
833
834 if (a->bits_per_word != b->bits_per_word)
835 return NULL;
836
837 if (a->mach > b->mach)
838 return a;
839
840 if (b->mach > a->mach)
841 return b;
842
843 return a;
844 }
845
846 /*
847 INTERNAL_FUNCTION
848 bfd_default_scan
849
850 SYNOPSIS
851 bfd_boolean bfd_default_scan
852 (const struct bfd_arch_info *info, const char *string);
853
854 DESCRIPTION
855 The default function for working out whether this is an
856 architecture hit and a machine hit.
857 */
858
859 bfd_boolean
860 bfd_default_scan (const bfd_arch_info_type *info, const char *string)
861 {
862 const char *ptr_src;
863 const char *ptr_tst;
864 unsigned long number;
865 enum bfd_architecture arch;
866 const char *printable_name_colon;
867
868 /* Exact match of the architecture name (ARCH_NAME) and also the
869 default architecture? */
870 if (strcasecmp (string, info->arch_name) == 0
871 && info->the_default)
872 return TRUE;
873
874 /* Exact match of the machine name (PRINTABLE_NAME)? */
875 if (strcasecmp (string, info->printable_name) == 0)
876 return TRUE;
877
878 /* Given that printable_name contains no colon, attempt to match:
879 ARCH_NAME [ ":" ] PRINTABLE_NAME? */
880 printable_name_colon = strchr (info->printable_name, ':');
881 if (printable_name_colon == NULL)
882 {
883 size_t strlen_arch_name = strlen (info->arch_name);
884 if (strncasecmp (string, info->arch_name, strlen_arch_name) == 0)
885 {
886 if (string[strlen_arch_name] == ':')
887 {
888 if (strcasecmp (string + strlen_arch_name + 1,
889 info->printable_name) == 0)
890 return TRUE;
891 }
892 else
893 {
894 if (strcasecmp (string + strlen_arch_name,
895 info->printable_name) == 0)
896 return TRUE;
897 }
898 }
899 }
900
901 /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>;
902 Attempt to match: <arch> <mach>? */
903 if (printable_name_colon != NULL)
904 {
905 size_t colon_index = printable_name_colon - info->printable_name;
906 if (strncasecmp (string, info->printable_name, colon_index) == 0
907 && strcasecmp (string + colon_index,
908 info->printable_name + colon_index + 1) == 0)
909 return TRUE;
910 }
911
912 /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>; Do not
913 attempt to match just <mach>, it could be ambiguous. This test
914 is left until later. */
915
916 /* NOTE: The below is retained for compatibility only. Please do
917 not add to this code. */
918
919 /* See how much of the supplied string matches with the
920 architecture, eg the string m68k:68020 would match the 68k entry
921 up to the :, then we get left with the machine number. */
922
923 for (ptr_src = string, ptr_tst = info->arch_name;
924 *ptr_src && *ptr_tst;
925 ptr_src++, ptr_tst++)
926 {
927 if (*ptr_src != *ptr_tst)
928 break;
929 }
930
931 /* Chewed up as much of the architecture as will match, skip any
932 colons. */
933 if (*ptr_src == ':')
934 ptr_src++;
935
936 if (*ptr_src == 0)
937 {
938 /* Nothing more, then only keep this one if it is the default
939 machine for this architecture. */
940 return info->the_default;
941 }
942
943 number = 0;
944 while (ISDIGIT (*ptr_src))
945 {
946 number = number * 10 + *ptr_src - '0';
947 ptr_src++;
948 }
949
950 /* NOTE: The below is retained for compatibility only.
951 PLEASE DO NOT ADD TO THIS CODE. */
952
953 switch (number)
954 {
955 /* FIXME: These are needed to parse IEEE objects. */
956 /* The following seven case's are here only for compatibility with
957 older binutils (at least IEEE objects from binutils 2.9.1 require
958 them). */
959 case bfd_mach_m68000:
960 case bfd_mach_m68010:
961 case bfd_mach_m68020:
962 case bfd_mach_m68030:
963 case bfd_mach_m68040:
964 case bfd_mach_m68060:
965 case bfd_mach_cpu32:
966 arch = bfd_arch_m68k;
967 break;
968 case 68000:
969 arch = bfd_arch_m68k;
970 number = bfd_mach_m68000;
971 break;
972 case 68010:
973 arch = bfd_arch_m68k;
974 number = bfd_mach_m68010;
975 break;
976 case 68020:
977 arch = bfd_arch_m68k;
978 number = bfd_mach_m68020;
979 break;
980 case 68030:
981 arch = bfd_arch_m68k;
982 number = bfd_mach_m68030;
983 break;
984 case 68040:
985 arch = bfd_arch_m68k;
986 number = bfd_mach_m68040;
987 break;
988 case 68060:
989 arch = bfd_arch_m68k;
990 number = bfd_mach_m68060;
991 break;
992 case 68332:
993 arch = bfd_arch_m68k;
994 number = bfd_mach_cpu32;
995 break;
996 case 5200:
997 arch = bfd_arch_m68k;
998 number = bfd_mach_mcf5200;
999 break;
1000 case 5206:
1001 arch = bfd_arch_m68k;
1002 number = bfd_mach_mcf5206e;
1003 break;
1004 case 5307:
1005 arch = bfd_arch_m68k;
1006 number = bfd_mach_mcf5307;
1007 break;
1008 case 5407:
1009 arch = bfd_arch_m68k;
1010 number = bfd_mach_mcf5407;
1011 break;
1012 case 5282:
1013 arch = bfd_arch_m68k;
1014 number = bfd_mach_mcf528x;
1015 break;
1016
1017 case 32000:
1018 arch = bfd_arch_we32k;
1019 break;
1020
1021 case 3000:
1022 arch = bfd_arch_mips;
1023 number = bfd_mach_mips3000;
1024 break;
1025
1026 case 4000:
1027 arch = bfd_arch_mips;
1028 number = bfd_mach_mips4000;
1029 break;
1030
1031 case 6000:
1032 arch = bfd_arch_rs6000;
1033 break;
1034
1035 case 7410:
1036 arch = bfd_arch_sh;
1037 number = bfd_mach_sh_dsp;
1038 break;
1039
1040 case 7708:
1041 arch = bfd_arch_sh;
1042 number = bfd_mach_sh3;
1043 break;
1044
1045 case 7729:
1046 arch = bfd_arch_sh;
1047 number = bfd_mach_sh3_dsp;
1048 break;
1049
1050 case 7750:
1051 arch = bfd_arch_sh;
1052 number = bfd_mach_sh4;
1053 break;
1054
1055 default:
1056 return FALSE;
1057 }
1058
1059 if (arch != info->arch)
1060 return FALSE;
1061
1062 if (number != info->mach)
1063 return FALSE;
1064
1065 return TRUE;
1066 }
1067
1068 /*
1069 FUNCTION
1070 bfd_get_arch_info
1071
1072 SYNOPSIS
1073 const bfd_arch_info_type *bfd_get_arch_info (bfd *abfd);
1074
1075 DESCRIPTION
1076 Return the architecture info struct in @var{abfd}.
1077 */
1078
1079 const bfd_arch_info_type *
1080 bfd_get_arch_info (bfd *abfd)
1081 {
1082 return abfd->arch_info;
1083 }
1084
1085 /*
1086 FUNCTION
1087 bfd_lookup_arch
1088
1089 SYNOPSIS
1090 const bfd_arch_info_type *bfd_lookup_arch
1091 (enum bfd_architecture arch, unsigned long machine);
1092
1093 DESCRIPTION
1094 Look for the architecture info structure which matches the
1095 arguments @var{arch} and @var{machine}. A machine of 0 matches the
1096 machine/architecture structure which marks itself as the
1097 default.
1098 */
1099
1100 const bfd_arch_info_type *
1101 bfd_lookup_arch (enum bfd_architecture arch, unsigned long machine)
1102 {
1103 const bfd_arch_info_type * const *app, *ap;
1104
1105 for (app = bfd_archures_list; *app != NULL; app++)
1106 {
1107 for (ap = *app; ap != NULL; ap = ap->next)
1108 {
1109 if (ap->arch == arch
1110 && (ap->mach == machine
1111 || (machine == 0 && ap->the_default)))
1112 return ap;
1113 }
1114 }
1115
1116 return NULL;
1117 }
1118
1119 /*
1120 FUNCTION
1121 bfd_printable_arch_mach
1122
1123 SYNOPSIS
1124 const char *bfd_printable_arch_mach
1125 (enum bfd_architecture arch, unsigned long machine);
1126
1127 DESCRIPTION
1128 Return a printable string representing the architecture and
1129 machine type.
1130
1131 This routine is depreciated.
1132 */
1133
1134 const char *
1135 bfd_printable_arch_mach (enum bfd_architecture arch, unsigned long machine)
1136 {
1137 const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
1138
1139 if (ap)
1140 return ap->printable_name;
1141 return "UNKNOWN!";
1142 }
1143
1144 /*
1145 FUNCTION
1146 bfd_octets_per_byte
1147
1148 SYNOPSIS
1149 unsigned int bfd_octets_per_byte (bfd *abfd);
1150
1151 DESCRIPTION
1152 Return the number of octets (8-bit quantities) per target byte
1153 (minimum addressable unit). In most cases, this will be one, but some
1154 DSP targets have 16, 32, or even 48 bits per byte.
1155 */
1156
1157 unsigned int
1158 bfd_octets_per_byte (bfd *abfd)
1159 {
1160 return bfd_arch_mach_octets_per_byte (bfd_get_arch (abfd),
1161 bfd_get_mach (abfd));
1162 }
1163
1164 /*
1165 FUNCTION
1166 bfd_arch_mach_octets_per_byte
1167
1168 SYNOPSIS
1169 unsigned int bfd_arch_mach_octets_per_byte
1170 (enum bfd_architecture arch, unsigned long machine);
1171
1172 DESCRIPTION
1173 See bfd_octets_per_byte.
1174
1175 This routine is provided for those cases where a bfd * is not
1176 available
1177 */
1178
1179 unsigned int
1180 bfd_arch_mach_octets_per_byte (enum bfd_architecture arch,
1181 unsigned long mach)
1182 {
1183 const bfd_arch_info_type *ap = bfd_lookup_arch (arch, mach);
1184
1185 if (ap)
1186 return ap->bits_per_byte / 8;
1187 return 1;
1188 }