1 /* BFD library support routines for architectures.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3 Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 @section Architectures
24 BFD's idea of an architecture is implimented in @code{archures.c}. BFD
25 keeps one atoms in a BFD describing the architecture of the data
26 attached to the BFD; a pointer to a @code{bfd_arch_info_struct}.
28 Pointers to structures can be requested independently of a bfd so that
29 an archictectures information can be interrogated without access to an
32 The arch information is provided by each architecture package. The
33 set of default architectures is selected by the #define
34 @code{SELECT_ARCHITECTURES}. This is normally set up in the
35 @code{config\/h\-} file of your choice. If the name is not defined,
36 then all the architectures supported are included.
38 When BFD starts up, all the architectures are called with an
39 initialize method. It is up to the architecture back end to insert as
40 many items into the list of arches as it wants to, generally this
41 would be one for each machine and one for the default case (an item
42 with a machine field of 0).
46 /*proto* bfd_architecture
47 This enum gives the object file's CPU
48 architecture, in a global sense. E.g. what processor family does it
49 belong to? There is another field, which indicates what processor
50 within the family is in use. The machine gives a number which
51 distingushes different versions of the architecture, containing for
52 example 2 and 3 for Intel i960 KA and i960 KB, and 68020 and 68030 for
53 Motorola 68020 and 68030.
58 bfd_arch_unknown, {* File arch not known *}
59 bfd_arch_obscure, {* Arch known, not one of these *}
60 bfd_arch_m68k, {* Motorola 68xxx *}
61 bfd_arch_vax, {* DEC Vax *}
62 bfd_arch_i960, {* Intel 960 *}
63 {* The order of the following is important.
64 lower number indicates a machine type that
65 only accepts a subset of the instructions
66 available to machines with higher numbers.
67 The exception is the "ca", which is
68 incompatible with all other machines except
71 #define bfd_mach_i960_core 1
72 #define bfd_mach_i960_ka_sa 2
73 #define bfd_mach_i960_kb_sb 3
74 #define bfd_mach_i960_mc 4
75 #define bfd_mach_i960_xa 5
76 #define bfd_mach_i960_ca 6
78 bfd_arch_a29k, {* AMD 29000 *}
79 bfd_arch_sparc, {* SPARC *}
80 bfd_arch_mips, {* MIPS Rxxxx *}
81 bfd_arch_i386, {* Intel 386 *}
82 bfd_arch_ns32k, {* National Semiconductor 32xxx *}
83 bfd_arch_tahoe, {* CCI/Harris Tahoe *}
84 bfd_arch_i860, {* Intel 860 *}
85 bfd_arch_romp, {* IBM ROMP RS/6000 *}
86 bfd_arch_alliant, {* Alliant *}
87 bfd_arch_convex, {* Convex *}
88 bfd_arch_m88k, {* Motorola 88xxx *}
89 bfd_arch_pyramid, {* Pyramid Technology *}
90 bfd_arch_h8300, {* Hitachi H8/300 *}
107 /*proto* bfd_arch_info_struct
108 This structure contains information on architectures.
110 typedef int bfd_reloc_code_enum_type;
112 typedef struct bfd_arch_info_struct
115 int bits_per_address;
117 enum bfd_architecture arch;
120 CONST char *printable_name;
121 {* true if this is the default machine for the architecture *}
123 CONST struct bfd_arch_info_struct * EXFUN((*compatible),(CONST struct bfd_arch_info_struct *a,
124 CONST struct bfd_arch_info_struct *b));
127 boolean EXFUN((*scan),(CONST struct bfd_arch_info_struct *,CONST char *));
128 unsigned int EXFUN((*disassemble),(bfd_vma addr, CONST char *data,
130 CONST struct reloc_howto_struct *EXFUN((*reloc_type_lookup), (bfd_reloc_code_enum_type code));
132 struct bfd_arch_info_struct *next;
134 } bfd_arch_info_struct_type;
140 bfd_arch_info_struct_type *bfd_arch_info_list;
142 /*proto* bfd_printable_arch_mach
143 Return a printable string representing the architecture and machine
146 NB. The use of this routine is depreciated.
148 *; PROTO(CONST char *,bfd_printable_arch_mach,
149 (enum bfd_architecture arch, unsigned long machine));
153 DEFUN(bfd_printable_arch_mach,(arch, machine),
154 enum bfd_architecture arch AND
155 unsigned long machine)
157 bfd_arch_info_struct_type *ap;
159 for (ap = bfd_arch_info_list;
160 ap != (bfd_arch_info_struct_type *)NULL;
162 if (ap->arch == arch &&
163 ((ap->mach == machine) || (ap->the_default && machine == 0))) {
164 return ap->printable_name;
171 /*proto* bfd_printable_name
173 Return a printable string representing the architecture and machine
174 from the pointer to the arch info structure
176 *; CONST char *EXFUN(bfd_printable_name,(bfd *abfd));
181 DEFUN(bfd_printable_name, (abfd),
184 return abfd->arch_info->printable_name;
191 This routine is provided with a string and tries to work out if bfd
192 supports any cpu which could be described with the name provided. The
193 routine returns a pointer to an arch_info structure if a machine is
194 found, otherwise NULL.
196 *; bfd_arch_info_struct_type *EXFUN(bfd_scan_arch,(CONST char *));
199 bfd_arch_info_struct_type *
200 DEFUN(bfd_scan_arch,(string),
203 struct bfd_arch_info_struct *ap;
205 /* Look through all the installed architectures */
206 for (ap = bfd_arch_info_list;
207 ap != (bfd_arch_info_struct_type *)NULL;
209 /* Don't bother with anything if the first chars don't match */
210 if (ap->arch_name[0] != string[0])
212 if (ap->scan(ap, string))
215 return (bfd_arch_info_struct_type *)NULL;
220 /*proto* bfd_arch_get_compatible
221 This routine is used to determine whether two BFDs' architectures and
222 machine types are compatible. It calculates the lowest common
223 denominator between the two architectures and machine types implied by
224 the BFDs and returns a pointer to an arch_info structure describing
225 the compatible machine.
227 *; CONST bfd_arch_info_struct_type *EXFUN(bfd_arch_get_compatible,
232 CONST bfd_arch_info_struct_type *
233 DEFUN(bfd_arch_get_compatible,(abfd, bbfd),
238 return abfd->arch_info->compatible(abfd->arch_info,bbfd->arch_info);
242 /*proto-internal* bfd_default_arch_struct
244 What bfds are seeded with
247 extern bfd_arch_info_struct_type bfd_default_arch_struct;
251 bfd_arch_info_struct_type bfd_default_arch_struct =
253 32,32,8,bfd_arch_unknown,0,"unknown","unknown",true,
254 bfd_default_compatible, bfd_default_scan,
258 /*proto* bfd_set_arch_info
260 *; void EXFUN(bfd_set_arch_info,(bfd *, bfd_arch_info_struct_type *));
264 void DEFUN(bfd_set_arch_info,(abfd, arg),
266 bfd_arch_info_struct_type *arg)
268 abfd->arch_info = arg;
271 /*proto-internal* bfd_default_set_arch_mach
273 Set the architecture and machine type in a bfd. This finds the correct
274 pointer to structure and inserts it into the arch_info pointer.
276 *; boolean EXFUN(bfd_default_set_arch_mach,(bfd *abfd,
277 enum bfd_architecture arch,
278 unsigned long mach));
282 boolean DEFUN(bfd_default_set_arch_mach,(abfd, arch, mach),
284 enum bfd_architecture arch AND
287 static struct bfd_arch_info_struct *old_ptr = &bfd_default_arch_struct;
288 boolean found = false;
289 /* run through the table to find the one we want, we keep a little
290 cache to speed things up */
291 if (old_ptr == 0 || arch != old_ptr->arch || mach != old_ptr->mach) {
292 bfd_arch_info_struct_type *ptr;
293 old_ptr = (bfd_arch_info_struct_type *)NULL;
294 for (ptr = bfd_arch_info_list;
295 ptr != (bfd_arch_info_struct_type *)NULL;
297 if (ptr->arch == arch &&
298 ((ptr->mach == mach) || (ptr->the_default && mach == 0))) {
305 /*looked for it and it wasn't there, so put in the default */
306 old_ptr = &bfd_default_arch_struct;
311 /* it was in the cache */
315 abfd->arch_info = old_ptr;
324 /*proto* bfd_get_arch
326 Returns the enumerated type which describes the supplied bfd's
329 *; enum bfd_architecture EXFUN(bfd_get_arch, (bfd *abfd));
332 enum bfd_architecture DEFUN(bfd_get_arch, (abfd), bfd *abfd)
334 return abfd->arch_info->arch;
339 /*proto* bfd_get_mach
341 Returns the long type which describes the supplied bfd's
344 *; unsigned long EXFUN(bfd_get_mach, (bfd *abfd));
347 unsigned long DEFUN(bfd_get_mach, (abfd), bfd *abfd)
349 return abfd->arch_info->mach;
352 /*proto* bfd_arch_bits_per_byte
354 Returns the number of bits in one of the architectures bytes
356 *; unsigned int EXFUN(bfd_arch_bits_per_byte, (bfd *abfd));
359 unsigned int DEFUN(bfd_arch_bits_per_byte, (abfd), bfd *abfd)
361 return abfd->arch_info->bits_per_byte;
364 /*proto* bfd_arch_bits_per_address
366 Returns the number of bits in one of the architectures addresses
368 *; unsigned int EXFUN(bfd_arch_bits_per_address, (bfd *abfd));
371 unsigned int DEFUN(bfd_arch_bits_per_address, (abfd), bfd *abfd)
373 return abfd->arch_info->bits_per_address;
378 extern void EXFUN(bfd_h8300_arch,(void));
379 extern void EXFUN(bfd_i960_arch,(void));
380 extern void EXFUN(bfd_empty_arch,(void));
381 extern void EXFUN(bfd_sparc_arch,(void));
382 extern void EXFUN(bfd_m88k_arch,(void));
383 extern void EXFUN(bfd_m68k_arch,(void));
384 extern void EXFUN(bfd_vax_arch,(void));
385 extern void EXFUN(bfd_a29k_arch,(void));
386 extern void EXFUN(bfd_mips_arch,(void));
387 extern void EXFUN(bfd_i386_arch,(void));
391 static void EXFUN((*archures_init_table[]),()) =
393 #ifdef SELECT_ARCHITECTURES
394 SELECT_ARCHITECTURES,
413 This routine initializes the architecture dispatch table by calling
414 all installed architecture packages and getting them to poke around.
416 *; PROTO(void, bfd_arch_init,(void));
421 DEFUN_VOID(bfd_arch_init)
423 void EXFUN((**ptable),());
424 for (ptable = archures_init_table;
433 /*proto-internal* bfd_arch_linkin
435 Link the provided arch info structure into the list
437 *; void EXFUN(bfd_arch_linkin,(bfd_arch_info_struct_type *));
441 void DEFUN(bfd_arch_linkin,(ptr),
442 bfd_arch_info_struct_type *ptr)
444 ptr->next = bfd_arch_info_list;
445 bfd_arch_info_list = ptr;
449 /*proto-internal* bfd_default_compatible
451 The default function for testing for compatibility
453 *; CONST bfd_arch_info_struct_type *EXFUN(bfd_default_compatible,
454 (CONST bfd_arch_info_struct_type *a,
455 CONST bfd_arch_info_struct_type *b));
458 CONST bfd_arch_info_struct_type *
459 DEFUN(bfd_default_compatible,(a,b),
460 CONST bfd_arch_info_struct_type *a AND
461 CONST bfd_arch_info_struct_type *b)
463 if(a->arch != b->arch) return (bfd_arch_info_struct_type *)NULL;
465 if (a->mach > b->mach) {
468 if (b->mach > a->mach) {
474 /*proto-internal* bfd_default_scan
475 The default function for working out whether this is an architecture
476 hit and a machine hit
478 *; boolean EXFUN(bfd_default_scan,(CONST struct bfd_arch_info_struct *, CONST char *));
483 DEFUN(bfd_default_scan,(info, string),
484 CONST struct bfd_arch_info_struct *info AND
489 unsigned long number;
490 enum bfd_architecture arch;
491 /* First test for an exact match */
492 if (strcmp(string, info->printable_name) == 0) return true;
494 /* See how much of the supplied string matches with the
495 architecture, eg the string m68k:68020 would match the 68k entry
496 up to the :, then we get left with the machine number */
498 for (ptr_src = string,
499 ptr_tst = info->arch_name;
500 *ptr_src && *ptr_tst;
504 if (*ptr_src != *ptr_tst) break;
507 /* Chewed up as much of the architecture as will match, skip any
509 if (*ptr_src == ':') ptr_src++;
512 /* nothing more, then only keep this one if it is the default
513 machine for this architecture */
514 return info->the_default;
517 while (isdigit(*ptr_src)) {
518 number = number * 10 + *ptr_src - '0';
530 arch = bfd_arch_m68k;
535 arch = bfd_arch_i386;
538 arch = bfd_arch_a29k;
549 arch = bfd_arch_ns32k;
554 arch = bfd_arch_i860;
560 if (arch != info->arch)
563 if (number != info->mach)
572 /*proto* bfd_get_arch_info
574 *; bfd_arch_info_struct_type * EXFUN(bfd_get_arch_info,(bfd *));
578 bfd_arch_info_struct_type *
579 DEFUN(bfd_get_arch_info,(abfd),
582 return abfd->arch_info;