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