1 /* BFD library support routines for architectures.
2 Copyright (C) 1990, 91, 92, 93, 94, 1995 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. */
26 BFD keeps one atom in a BFD describing the
27 architecture of the data attached to the BFD: a pointer to a
28 <<bfd_arch_info_type>>.
30 Pointers to structures can be requested independently of a BFD
31 so that an architecture's information can be interrogated
32 without access to an open BFD.
34 The architecture information is provided by each architecture package.
35 The set of default architectures is selected by the macro
36 <<SELECT_ARCHITECTURES>>. This is normally set up in the
37 @file{config/@var{target}.mt} file of your choice. If the name is not
38 defined, then all the architectures supported are included.
40 When BFD starts up, all the architectures are called with an
41 initialize method. It is up to the architecture back end to
42 insert as many items into the list of architectures as it wants to;
43 generally this would be one for each machine and one for the
44 default case (an item with a machine field of 0).
46 BFD's idea of an architecture is implemented in @file{archures.c}.
55 This enum gives the object file's CPU architecture, in a
56 global sense---i.e., what processor family does it belong to?
57 Another field indicates which processor within
58 the family is in use. The machine gives a number which
59 distinguishes different versions of the architecture,
60 containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
61 and 68020 and 68030 for Motorola 68020 and 68030.
63 .enum bfd_architecture
65 . bfd_arch_unknown, {* File arch not known *}
66 . bfd_arch_obscure, {* Arch known, not one of these *}
67 . bfd_arch_m68k, {* Motorola 68xxx *}
68 . bfd_arch_vax, {* DEC Vax *}
69 . bfd_arch_i960, {* Intel 960 *}
70 . {* The order of the following is important.
71 . lower number indicates a machine type that
72 . only accepts a subset of the instructions
73 . available to machines with higher numbers.
74 . The exception is the "ca", which is
75 . incompatible with all other machines except
78 .#define bfd_mach_i960_core 1
79 .#define bfd_mach_i960_ka_sa 2
80 .#define bfd_mach_i960_kb_sb 3
81 .#define bfd_mach_i960_mc 4
82 .#define bfd_mach_i960_xa 5
83 .#define bfd_mach_i960_ca 6
84 . {* start-sanitize-i960xl *}
85 .#define bfd_mach_i960_xl 7
86 . {* end-sanitize-i960xl *}
88 . bfd_arch_a29k, {* AMD 29000 *}
89 . bfd_arch_sparc, {* SPARC *}
90 .#define bfd_mach_sparc 1
91 .#define bfd_mach_sparc64 2
92 . bfd_arch_mips, {* MIPS Rxxxx *}
93 . bfd_arch_i386, {* Intel 386 *}
94 . bfd_arch_we32k, {* AT&T WE32xxx *}
95 . bfd_arch_tahoe, {* CCI/Harris Tahoe *}
96 . bfd_arch_i860, {* Intel 860 *}
97 . bfd_arch_romp, {* IBM ROMP PC/RT *}
98 . bfd_arch_alliant, {* Alliant *}
99 . bfd_arch_convex, {* Convex *}
100 . bfd_arch_m88k, {* Motorola 88xxx *}
101 . bfd_arch_pyramid, {* Pyramid Technology *}
102 . bfd_arch_h8300, {* Hitachi H8/300 *}
103 .#define bfd_mach_h8300 1
104 .#define bfd_mach_h8300h 2
105 . bfd_arch_powerpc, {* PowerPC *}
106 . bfd_arch_rs6000, {* IBM RS/6000 *}
107 . bfd_arch_hppa, {* HP PA RISC *}
108 . bfd_arch_z8k, {* Zilog Z8000 *}
109 .#define bfd_mach_z8001 1
110 .#define bfd_mach_z8002 2
111 . bfd_arch_h8500, {* Hitachi H8/500 *}
112 . bfd_arch_sh, {* Hitachi SH *}
113 . bfd_arch_alpha, {* Dec Alpha *}
114 . bfd_arch_arm, {* Advanced Risc Machines ARM *}
115 . bfd_arch_ns32k, {* National Semiconductors ns32000 *}
116 . bfd_arch_w65, {* WDC 65816 *}
117 . {* start-sanitize-rce *}
118 . bfd_arch_rce, {* Motorola RCE *}
119 . {* end-sanitize-rce *}
120 . {* start-sanitize-arc *}
121 . bfd_arch_arc, {* Argonaut RISC Core *}
122 .#define bfd_mach_arc_base 0
123 .#define bfd_mach_arc_host 1
124 .#define bfd_mach_arc_graphics 2
125 .#define bfd_mach_arc_audio 3
126 . {* end-sanitize-arc *}
144 This structure contains information on architectures for use
148 .typedef struct bfd_arch_info
151 . int bits_per_address;
153 . enum bfd_architecture arch;
154 . unsigned long mach;
156 . CONST char *printable_name;
157 . unsigned int section_align_power;
158 . {* true if this is the default machine for the architecture *}
159 . boolean the_default;
160 . CONST struct bfd_arch_info * (*compatible)
161 . PARAMS ((CONST struct bfd_arch_info *a,
162 . CONST struct bfd_arch_info *b));
164 . boolean (*scan) PARAMS ((CONST struct bfd_arch_info *, CONST char *));
165 . {* How to disassemble an instruction, producing a printable
166 . representation on a specified stdio stream. This isn't
167 . defined for most processors at present, because of the size
168 . of the additional tables it would drag in, and because gdb
169 . wants to use a different interface. *}
170 . unsigned int (*disassemble) PARAMS ((bfd_vma addr, CONST char *data,
173 . struct bfd_arch_info *next;
174 .} bfd_arch_info_type;
177 bfd_arch_info_type *bfd_arch_info_list;
185 CONST char *bfd_printable_name(bfd *abfd);
188 Return a printable string representing the architecture and machine
189 from the pointer to the architecture info structure.
194 bfd_printable_name (abfd)
197 return abfd->arch_info->printable_name;
207 bfd_arch_info_type *bfd_scan_arch(CONST char *string);
210 Figure out if BFD supports any cpu which could be described with
211 the name @var{string}. Return a pointer to an <<arch_info>>
212 structure if a machine is found, otherwise NULL.
217 bfd_scan_arch (string)
220 struct bfd_arch_info *ap;
222 /* Look through all the installed architectures */
223 for (ap = bfd_arch_info_list;
224 ap != (bfd_arch_info_type *)NULL;
227 if (ap->scan(ap, string))
230 return (bfd_arch_info_type *)NULL;
237 bfd_arch_get_compatible
240 CONST bfd_arch_info_type *bfd_arch_get_compatible(
245 Determine whether two BFDs'
246 architectures and machine types are compatible. Calculates
247 the lowest common denominator between the two architectures
248 and machine types implied by the BFDs and returns a pointer to
249 an <<arch_info>> structure describing the compatible machine.
252 CONST bfd_arch_info_type *
253 bfd_arch_get_compatible (abfd, bbfd)
257 /* If either architecture is unknown, then all we can do is assume
258 the user knows what he's doing. */
259 if (abfd->arch_info->arch == bfd_arch_unknown)
260 return bbfd->arch_info;
261 if (bbfd->arch_info->arch == bfd_arch_unknown)
262 return abfd->arch_info;
264 /* Otherwise architecture-specific code has to decide. */
265 return abfd->arch_info->compatible(abfd->arch_info,bbfd->arch_info);
271 bfd_default_arch_struct
274 The <<bfd_default_arch_struct>> is an item of
275 <<bfd_arch_info_type>> which has been initialized to a fairly
276 generic state. A BFD starts life by pointing to this
277 structure, until the correct back end has determined the real
278 architecture of the file.
280 .extern bfd_arch_info_type bfd_default_arch_struct;
284 bfd_arch_info_type bfd_default_arch_struct =
286 32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
287 bfd_default_compatible,
297 void bfd_set_arch_info(bfd *abfd, bfd_arch_info_type *arg);
300 Set the architecture info of @var{abfd} to @var{arg}.
304 bfd_set_arch_info (abfd, arg)
306 bfd_arch_info_type *arg;
308 abfd->arch_info = arg;
313 bfd_default_set_arch_mach
316 boolean bfd_default_set_arch_mach(bfd *abfd,
317 enum bfd_architecture arch,
321 Set the architecture and machine type in BFD @var{abfd}
322 to @var{arch} and @var{mach}. Find the correct
323 pointer to a structure and insert it into the <<arch_info>>
328 bfd_default_set_arch_mach (abfd, arch, mach)
330 enum bfd_architecture arch;
333 static struct bfd_arch_info *old_ptr = &bfd_default_arch_struct;
334 boolean found = false;
335 /* run through the table to find the one we want, we keep a little
336 cache to speed things up */
337 if (old_ptr == 0 || arch != old_ptr->arch || mach != old_ptr->mach) {
338 bfd_arch_info_type *ptr;
339 old_ptr = (bfd_arch_info_type *)NULL;
340 for (ptr = bfd_arch_info_list;
341 ptr != (bfd_arch_info_type *)NULL;
343 if (ptr->arch == arch &&
344 ((ptr->mach == mach) || (ptr->the_default && mach == 0))) {
351 /*looked for it and it wasn't there, so put in the default */
352 old_ptr = &bfd_default_arch_struct;
353 bfd_set_error (bfd_error_bad_value);
357 /* it was in the cache */
361 abfd->arch_info = old_ptr;
372 enum bfd_architecture bfd_get_arch(bfd *abfd);
375 Return the enumerated type which describes the BFD @var{abfd}'s
380 enum bfd_architecture
384 return abfd->arch_info->arch;
392 unsigned long bfd_get_mach(bfd *abfd);
395 Return the long type which describes the BFD @var{abfd}'s
403 return abfd->arch_info->mach;
408 bfd_arch_bits_per_byte
411 unsigned int bfd_arch_bits_per_byte(bfd *abfd);
414 Return the number of bits in one of the BFD @var{abfd}'s
415 architecture's bytes.
420 bfd_arch_bits_per_byte (abfd)
423 return abfd->arch_info->bits_per_byte;
428 bfd_arch_bits_per_address
431 unsigned int bfd_arch_bits_per_address(bfd *abfd);
434 Return the number of bits in one of the BFD @var{abfd}'s
435 architecture's addresses.
439 bfd_arch_bits_per_address (abfd)
442 return abfd->arch_info->bits_per_address;
446 extern void bfd_a29k_arch PARAMS ((void));
447 extern void bfd_alpha_arch PARAMS ((void));
448 /* start-sanitize-arc */
449 extern void bfd_arc_arch PARAMS ((void));
450 /* end-sanitize-arc */
451 extern void bfd_arm_arch PARAMS ((void));
452 extern void bfd_h8300_arch PARAMS ((void));
453 extern void bfd_h8500_arch PARAMS ((void));
454 extern void bfd_hppa_arch PARAMS ((void));
455 extern void bfd_i386_arch PARAMS ((void));
456 extern void bfd_i960_arch PARAMS ((void));
457 extern void bfd_m68k_arch PARAMS ((void));
458 extern void bfd_m88k_arch PARAMS ((void));
459 extern void bfd_mips_arch PARAMS ((void));
460 extern void bfd_powerpc_arch PARAMS ((void));
461 extern void bfd_rs6000_arch PARAMS ((void));
462 extern void bfd_sh_arch PARAMS ((void));
463 /* start-sanitize-rce */
464 extern void bfd_rce_arch PARAMS ((void));
465 /* end-sanitize-rce */
466 extern void bfd_sparc_arch PARAMS ((void));
467 extern void bfd_vax_arch PARAMS ((void));
468 extern void bfd_we32k_arch PARAMS ((void));
469 extern void bfd_z8k_arch PARAMS ((void));
470 extern void bfd_ns32k_arch PARAMS ((void));
471 extern void bfd_w65_arch PARAMS ((void));
473 static void (*const archures_init_table[]) PARAMS ((void)) =
475 #ifdef SELECT_ARCHITECTURES
476 SELECT_ARCHITECTURES,
480 /* start-sanitize-arc */
482 /* end-sanitize-arc */
495 /* start-sanitize-rce */
497 /* end-sanitize-rce */
515 void bfd_arch_init(void);
518 Initialize the architecture dispatch table by
519 calling all installed architecture packages and getting them
526 void (*const *ptable) PARAMS ((void));
527 for (ptable = archures_init_table; *ptable ; ptable++)
537 void bfd_arch_linkin(bfd_arch_info_type *ptr);
540 Link the architecture info structure @var{ptr} into the list.
544 bfd_arch_linkin (ptr)
545 bfd_arch_info_type *ptr;
547 ptr->next = bfd_arch_info_list;
548 bfd_arch_info_list = ptr;
554 bfd_default_compatible
557 CONST bfd_arch_info_type *bfd_default_compatible
558 (CONST bfd_arch_info_type *a,
559 CONST bfd_arch_info_type *b);
562 The default function for testing for compatibility.
565 CONST bfd_arch_info_type *
566 bfd_default_compatible (a,b)
567 CONST bfd_arch_info_type *a;
568 CONST bfd_arch_info_type *b;
570 if(a->arch != b->arch) return NULL;
572 if (a->mach > b->mach) {
575 if (b->mach > a->mach) {
587 boolean bfd_default_scan(CONST struct bfd_arch_info *info, CONST char *string);
590 The default function for working out whether this is an
591 architecture hit and a machine hit.
595 bfd_default_scan (info, string)
596 CONST struct bfd_arch_info *info;
601 unsigned long number;
602 enum bfd_architecture arch;
603 /* First test for an exact match */
604 if (strcmp(string, info->printable_name) == 0) return true;
606 /* See how much of the supplied string matches with the
607 architecture, eg the string m68k:68020 would match the 68k entry
608 up to the :, then we get left with the machine number */
610 for (ptr_src = string,
611 ptr_tst = info->arch_name;
612 *ptr_src && *ptr_tst;
616 if (*ptr_src != *ptr_tst) break;
619 /* Chewed up as much of the architecture as will match, skip any
621 if (*ptr_src == ':') ptr_src++;
624 /* nothing more, then only keep this one if it is the default
625 machine for this architecture */
626 return info->the_default;
629 while (isdigit(*ptr_src)) {
630 number = number * 10 + *ptr_src - '0';
641 arch = bfd_arch_h8300;
645 arch = bfd_arch_h8500;
655 arch = bfd_arch_m68k;
661 arch = bfd_arch_i386;
664 arch = bfd_arch_a29k;
672 arch = bfd_arch_we32k;
677 arch = bfd_arch_i860;
681 arch = bfd_arch_i960;
688 arch = bfd_arch_mips;
692 arch = bfd_arch_rs6000;
698 if (arch != info->arch)
701 if (number != info->mach)
713 bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
716 Return the architecture info struct in @var{abfd}.
720 bfd_get_arch_info (abfd)
723 return abfd->arch_info;
732 bfd_arch_info_type *bfd_lookup_arch
733 (enum bfd_architecture
735 unsigned long machine);
738 Look for the architecure info structure which matches the
739 arguments @var{arch} and @var{machine}. A machine of 0 matches the
740 machine/architecture structure which marks itself as the
745 bfd_lookup_arch (arch, machine)
746 enum bfd_architecture arch;
747 unsigned long machine;
749 bfd_arch_info_type *ap;
751 for (ap = bfd_arch_info_list;
752 ap != (bfd_arch_info_type *)NULL;
754 if (ap->arch == arch &&
755 ((ap->mach == machine)
756 || (ap->the_default && machine == 0))) {
760 return (bfd_arch_info_type *)NULL;
766 bfd_printable_arch_mach
769 CONST char *bfd_printable_arch_mach
770 (enum bfd_architecture arch, unsigned long machine);
773 Return a printable string representing the architecture and
776 This routine is depreciated.
780 bfd_printable_arch_mach (arch, machine)
781 enum bfd_architecture arch;
782 unsigned long machine;
784 bfd_arch_info_type *ap = bfd_lookup_arch(arch, machine);
785 if(ap) return ap->printable_name;