1 /* BFD library support routines for architectures.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 BFD keeps one atom in a BFD describing the
32 architecture of the data attached to the BFD: a pointer to a
33 <<bfd_arch_info_type>>.
35 Pointers to structures can be requested independently of a BFD
36 so that an architecture's information can be interrogated
37 without access to an open BFD.
39 The architecture information is provided by each architecture package.
40 The set of default architectures is selected by the macro
41 <<SELECT_ARCHITECTURES>>. This is normally set up in the
42 @file{config/@var{target}.mt} file of your choice. If the name is not
43 defined, then all the architectures supported are included.
45 When BFD starts up, all the architectures are called with an
46 initialize method. It is up to the architecture back end to
47 insert as many items into the list of architectures as it wants to;
48 generally this would be one for each machine and one for the
49 default case (an item with a machine field of 0).
51 BFD's idea of an architecture is implemented in @file{archures.c}.
60 This enum gives the object file's CPU architecture, in a
61 global sense---i.e., what processor family does it belong to?
62 Another field indicates which processor within
63 the family is in use. The machine gives a number which
64 distinguishes different versions of the architecture,
65 containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
66 and 68020 and 68030 for Motorola 68020 and 68030.
68 .enum bfd_architecture
70 . bfd_arch_unknown, {* File arch not known *}
71 . bfd_arch_obscure, {* Arch known, not one of these *}
72 . bfd_arch_m68k, {* Motorola 68xxx *}
73 . bfd_arch_vax, {* DEC Vax *}
74 . bfd_arch_i960, {* Intel 960 *}
75 . {* The order of the following is important.
76 . lower number indicates a machine type that
77 . only accepts a subset of the instructions
78 . available to machines with higher numbers.
79 . The exception is the "ca", which is
80 . incompatible with all other machines except
83 .#define bfd_mach_i960_core 1
84 .#define bfd_mach_i960_ka_sa 2
85 .#define bfd_mach_i960_kb_sb 3
86 .#define bfd_mach_i960_mc 4
87 .#define bfd_mach_i960_xa 5
88 .#define bfd_mach_i960_ca 6
89 .#define bfd_mach_i960_jx 7
90 .#define bfd_mach_i960_hx 8
92 . bfd_arch_a29k, {* AMD 29000 *}
93 . bfd_arch_sparc, {* SPARC *}
94 .#define bfd_mach_sparc 1
95 .{* The difference between v8plus and v9 is that v9 is a true 64 bit env. *}
96 .#define bfd_mach_sparc_v8plus 2
97 .#define bfd_mach_sparc_v8plusa 3 {* with ultrasparc add'ns *}
98 .#define bfd_mach_sparc_v9 4
99 .#define bfd_mach_sparc_v9a 5 {* with ultrasparc add'ns *}
100 .{* Nonzero if MACH has the v9 instruction set. *}
101 .#define bfd_mach_sparc_v9_p(mach) ((mach) != bfd_mach_sparc)
102 . bfd_arch_mips, {* MIPS Rxxxx *}
103 . bfd_arch_i386, {* Intel 386 *}
104 . bfd_arch_we32k, {* AT&T WE32xxx *}
105 . bfd_arch_tahoe, {* CCI/Harris Tahoe *}
106 . bfd_arch_i860, {* Intel 860 *}
107 . bfd_arch_romp, {* IBM ROMP PC/RT *}
108 . bfd_arch_alliant, {* Alliant *}
109 . bfd_arch_convex, {* Convex *}
110 . bfd_arch_m88k, {* Motorola 88xxx *}
111 . bfd_arch_pyramid, {* Pyramid Technology *}
112 . bfd_arch_h8300, {* Hitachi H8/300 *}
113 .#define bfd_mach_h8300 1
114 .#define bfd_mach_h8300h 2
115 . bfd_arch_powerpc, {* PowerPC *}
116 . bfd_arch_rs6000, {* IBM RS/6000 *}
117 . bfd_arch_hppa, {* HP PA RISC *}
118 . bfd_arch_z8k, {* Zilog Z8000 *}
119 .#define bfd_mach_z8001 1
120 .#define bfd_mach_z8002 2
121 . bfd_arch_h8500, {* Hitachi H8/500 *}
122 . bfd_arch_sh, {* Hitachi SH *}
123 . bfd_arch_alpha, {* Dec Alpha *}
124 . bfd_arch_arm, {* Advanced Risc Machines ARM *}
125 . bfd_arch_ns32k, {* National Semiconductors ns32000 *}
126 . bfd_arch_w65, {* WDC 65816 *}
139 This structure contains information on architectures for use
143 .typedef struct bfd_arch_info
146 . int bits_per_address;
148 . enum bfd_architecture arch;
149 . unsigned long mach;
150 . const char *arch_name;
151 . const char *printable_name;
152 . unsigned int section_align_power;
153 . {* true if this is the default machine for the architecture *}
154 . boolean the_default;
155 . const struct bfd_arch_info * (*compatible)
156 . PARAMS ((const struct bfd_arch_info *a,
157 . const struct bfd_arch_info *b));
159 . boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
161 . const struct bfd_arch_info *next;
162 .} bfd_arch_info_type;
165 extern const bfd_arch_info_type bfd_a29k_arch;
166 extern const bfd_arch_info_type bfd_alpha_arch;
167 extern const bfd_arch_info_type bfd_arm_arch;
168 extern const bfd_arch_info_type bfd_h8300_arch;
169 extern const bfd_arch_info_type bfd_h8500_arch;
170 extern const bfd_arch_info_type bfd_hppa_arch;
171 extern const bfd_arch_info_type bfd_i386_arch;
172 extern const bfd_arch_info_type bfd_i860_arch;
173 extern const bfd_arch_info_type bfd_i960_arch;
174 extern const bfd_arch_info_type bfd_m68k_arch;
175 extern const bfd_arch_info_type bfd_m88k_arch;
176 extern const bfd_arch_info_type bfd_mips_arch;
177 extern const bfd_arch_info_type bfd_powerpc_arch;
178 extern const bfd_arch_info_type bfd_rs6000_arch;
179 extern const bfd_arch_info_type bfd_sh_arch;
180 extern const bfd_arch_info_type bfd_sparc_arch;
181 extern const bfd_arch_info_type bfd_vax_arch;
182 extern const bfd_arch_info_type bfd_we32k_arch;
183 extern const bfd_arch_info_type bfd_z8k_arch;
184 extern const bfd_arch_info_type bfd_ns32k_arch;
185 extern const bfd_arch_info_type bfd_w65_arch;
187 static const bfd_arch_info_type * const bfd_archures_list[] =
189 #ifdef SELECT_ARCHITECTURES
190 SELECT_ARCHITECTURES,
222 const char *bfd_printable_name(bfd *abfd);
225 Return a printable string representing the architecture and machine
226 from the pointer to the architecture info structure.
231 bfd_printable_name (abfd)
234 return abfd->arch_info->printable_name;
244 const bfd_arch_info_type *bfd_scan_arch(const char *string);
247 Figure out if BFD supports any cpu which could be described with
248 the name @var{string}. Return a pointer to an <<arch_info>>
249 structure if a machine is found, otherwise NULL.
253 const bfd_arch_info_type *
254 bfd_scan_arch (string)
257 const bfd_arch_info_type * const *app, *ap;
259 /* Look through all the installed architectures */
260 for (app = bfd_archures_list; *app != NULL; app++)
262 for (ap = *app; ap != NULL; ap = ap->next)
264 if (ap->scan (ap, string))
276 bfd_arch_get_compatible
279 const bfd_arch_info_type *bfd_arch_get_compatible(
284 Determine whether two BFDs'
285 architectures and machine types are compatible. Calculates
286 the lowest common denominator between the two architectures
287 and machine types implied by the BFDs and returns a pointer to
288 an <<arch_info>> structure describing the compatible machine.
291 const bfd_arch_info_type *
292 bfd_arch_get_compatible (abfd, bbfd)
296 /* If either architecture is unknown, then all we can do is assume
297 the user knows what he's doing. */
298 if (abfd->arch_info->arch == bfd_arch_unknown)
299 return bbfd->arch_info;
300 if (bbfd->arch_info->arch == bfd_arch_unknown)
301 return abfd->arch_info;
303 /* Otherwise architecture-specific code has to decide. */
304 return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
310 bfd_default_arch_struct
313 The <<bfd_default_arch_struct>> is an item of
314 <<bfd_arch_info_type>> which has been initialized to a fairly
315 generic state. A BFD starts life by pointing to this
316 structure, until the correct back end has determined the real
317 architecture of the file.
319 .extern const bfd_arch_info_type bfd_default_arch_struct;
323 const bfd_arch_info_type bfd_default_arch_struct =
325 32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
326 bfd_default_compatible,
336 void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
339 Set the architecture info of @var{abfd} to @var{arg}.
343 bfd_set_arch_info (abfd, arg)
345 const bfd_arch_info_type *arg;
347 abfd->arch_info = arg;
352 bfd_default_set_arch_mach
355 boolean bfd_default_set_arch_mach(bfd *abfd,
356 enum bfd_architecture arch,
360 Set the architecture and machine type in BFD @var{abfd}
361 to @var{arch} and @var{mach}. Find the correct
362 pointer to a structure and insert it into the <<arch_info>>
367 bfd_default_set_arch_mach (abfd, arch, mach)
369 enum bfd_architecture arch;
372 const bfd_arch_info_type * const *app, *ap;
374 for (app = bfd_archures_list; *app != NULL; app++)
376 for (ap = *app; ap != NULL; ap = ap->next)
380 || (mach == 0 && ap->the_default)))
382 abfd->arch_info = ap;
388 abfd->arch_info = &bfd_default_arch_struct;
389 bfd_set_error (bfd_error_bad_value);
399 enum bfd_architecture bfd_get_arch(bfd *abfd);
402 Return the enumerated type which describes the BFD @var{abfd}'s
407 enum bfd_architecture
411 return abfd->arch_info->arch;
419 unsigned long bfd_get_mach(bfd *abfd);
422 Return the long type which describes the BFD @var{abfd}'s
430 return abfd->arch_info->mach;
435 bfd_arch_bits_per_byte
438 unsigned int bfd_arch_bits_per_byte(bfd *abfd);
441 Return the number of bits in one of the BFD @var{abfd}'s
442 architecture's bytes.
447 bfd_arch_bits_per_byte (abfd)
450 return abfd->arch_info->bits_per_byte;
455 bfd_arch_bits_per_address
458 unsigned int bfd_arch_bits_per_address(bfd *abfd);
461 Return the number of bits in one of the BFD @var{abfd}'s
462 architecture's addresses.
466 bfd_arch_bits_per_address (abfd)
469 return abfd->arch_info->bits_per_address;
475 bfd_default_compatible
478 const bfd_arch_info_type *bfd_default_compatible
479 (const bfd_arch_info_type *a,
480 const bfd_arch_info_type *b);
483 The default function for testing for compatibility.
486 const bfd_arch_info_type *
487 bfd_default_compatible (a,b)
488 const bfd_arch_info_type *a;
489 const bfd_arch_info_type *b;
491 if (a->arch != b->arch)
494 if (a->mach > b->mach)
497 if (b->mach > a->mach)
509 boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
512 The default function for working out whether this is an
513 architecture hit and a machine hit.
517 bfd_default_scan (info, string)
518 const struct bfd_arch_info *info;
523 unsigned long number;
524 enum bfd_architecture arch;
526 /* First test for an exact match */
527 if (strcmp (string, info->printable_name) == 0)
530 /* See how much of the supplied string matches with the
531 architecture, eg the string m68k:68020 would match the 68k entry
532 up to the :, then we get left with the machine number */
534 for (ptr_src = string, ptr_tst = info->arch_name;
535 *ptr_src && *ptr_tst;
536 ptr_src++, ptr_tst++)
538 if (*ptr_src != *ptr_tst) break;
541 /* Chewed up as much of the architecture as will match, skip any
548 /* nothing more, then only keep this one if it is the default
549 machine for this architecture */
550 return info->the_default;
554 while (isdigit(*ptr_src))
556 number = number * 10 + *ptr_src - '0';
567 arch = bfd_arch_h8300;
571 arch = bfd_arch_h8500;
581 arch = bfd_arch_m68k;
588 arch = bfd_arch_i386;
592 arch = bfd_arch_a29k;
600 arch = bfd_arch_we32k;
605 arch = bfd_arch_i860;
609 arch = bfd_arch_i960;
616 arch = bfd_arch_mips;
620 arch = bfd_arch_rs6000;
627 if (arch != info->arch)
630 if (number != info->mach)
642 const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
645 Return the architecture info struct in @var{abfd}.
648 const bfd_arch_info_type *
649 bfd_get_arch_info (abfd)
652 return abfd->arch_info;
661 const bfd_arch_info_type *bfd_lookup_arch
662 (enum bfd_architecture
664 unsigned long machine);
667 Look for the architecure info structure which matches the
668 arguments @var{arch} and @var{machine}. A machine of 0 matches the
669 machine/architecture structure which marks itself as the
673 const bfd_arch_info_type *
674 bfd_lookup_arch (arch, machine)
675 enum bfd_architecture arch;
676 unsigned long machine;
678 const bfd_arch_info_type * const *app, *ap;
680 for (app = bfd_archures_list; *app != NULL; app++)
682 for (ap = *app; ap != NULL; ap = ap->next)
685 && (ap->mach == machine
686 || (machine == 0 && ap->the_default)))
697 bfd_printable_arch_mach
700 const char *bfd_printable_arch_mach
701 (enum bfd_architecture arch, unsigned long machine);
704 Return a printable string representing the architecture and
707 This routine is depreciated.
711 bfd_printable_arch_mach (arch, machine)
712 enum bfd_architecture arch;
713 unsigned long machine;
715 const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
718 return ap->printable_name;