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. */
29 BFD's idea of an architecture is implimented in
30 <<archures.c>>. BFD keeps one atom in a BFD describing the
31 architecture of the data attached to the BFD; a pointer to a
32 <<bfd_arch_info_type>>.
34 Pointers to structures can be requested independently of a bfd
35 so that an architecture's information can be interrogated
36 without access to an open bfd.
38 The arch information is provided by each architecture package.
39 The set of default architectures is selected by the #define
40 <<SELECT_ARCHITECTURES>>. This is normally set up in the
41 <<config\/h\->> file of your choice. If the name is not
42 defined, then all the architectures supported are included.
44 When BFD starts up, all the architectures are called with an
45 initialize method. It is up to the architecture back end to
46 insert as many items into the list of arches as it wants to,
47 generally this would be one for each machine and one for the
48 default case (an item with a machine field of 0).
57 This enum gives the object file's CPU architecture, in a
58 global sense. E.g. what processor family does it belong to?
59 There is another field, which indicates what processor within
60 the family is in use. The machine gives a number which
61 distingushes different versions of the architecture,
62 containing for example 2 and 3 for Intel i960 KA and i960 KB,
63 and 68020 and 68030 for Motorola 68020 and 68030.
65 .enum bfd_architecture
67 . bfd_arch_unknown, {* File arch not known *}
68 . bfd_arch_obscure, {* Arch known, not one of these *}
69 . bfd_arch_m68k, {* Motorola 68xxx *}
70 . bfd_arch_vax, {* DEC Vax *}
71 . bfd_arch_i960, {* Intel 960 *}
72 . {* The order of the following is important.
73 . lower number indicates a machine type that
74 . only accepts a subset of the instructions
75 . available to machines with higher numbers.
76 . The exception is the "ca", which is
77 . incompatible with all other machines except
80 .#define bfd_mach_i960_core 1
81 .#define bfd_mach_i960_ka_sa 2
82 .#define bfd_mach_i960_kb_sb 3
83 .#define bfd_mach_i960_mc 4
84 .#define bfd_mach_i960_xa 5
85 .#define bfd_mach_i960_ca 6
87 . bfd_arch_a29k, {* AMD 29000 *}
88 . bfd_arch_sparc, {* SPARC *}
89 . bfd_arch_mips, {* MIPS Rxxxx *}
90 . bfd_arch_i386, {* Intel 386 *}
91 . bfd_arch_ns32k, {* National Semiconductor 32xxx *}
92 . bfd_arch_tahoe, {* CCI/Harris Tahoe *}
93 . bfd_arch_i860, {* Intel 860 *}
94 . bfd_arch_romp, {* IBM ROMP PC/RT *}
95 . bfd_arch_alliant, {* Alliant *}
96 . bfd_arch_convex, {* Convex *}
97 . bfd_arch_m88k, {* Motorola 88xxx *}
98 . bfd_arch_pyramid, {* Pyramid Technology *}
99 . bfd_arch_h8300, {* Hitachi H8/300 *}
100 . bfd_arch_rs6000, {* IBM RS/6000 *}
121 This structure contains information on architectures for use
124 .typedef int bfd_reloc_code_type;
126 .typedef struct bfd_arch_info
129 . int bits_per_address;
131 . enum bfd_architecture arch;
134 . CONST char *printable_name;
135 .{* true if this is the default machine for the architecture *}
136 . boolean the_default;
137 . CONST struct bfd_arch_info * EXFUN((*compatible),
138 . (CONST struct bfd_arch_info *a,
139 . CONST struct bfd_arch_info *b));
141 . boolean EXFUN((*scan),(CONST struct bfd_arch_info *,CONST char *));
142 . unsigned int EXFUN((*disassemble),(bfd_vma addr, CONST char *data,
144 . CONST struct reloc_howto_struct *EXFUN((*reloc_type_lookup),
145 . (CONST struct bfd_arch_info *,
146 . bfd_reloc_code_type code));
148 . struct bfd_arch_info *next;
150 .} bfd_arch_info_type;
153 bfd_arch_info_type *bfd_arch_info_list;
162 Return a printable string representing the architecture and machine
163 from the pointer to the arch info structure
166 CONST char *bfd_printable_name(bfd *abfd);
171 DEFUN(bfd_printable_name, (abfd),
174 return abfd->arch_info->printable_name;
184 This routine is provided with a string and tries to work out
185 if bfd supports any cpu which could be described with the name
186 provided. The routine returns a pointer to an arch_info
187 structure if a machine is found, otherwise NULL.
190 bfd_arch_info_type *bfd_scan_arch(CONST char *);
194 DEFUN(bfd_scan_arch,(string),
197 struct bfd_arch_info *ap;
199 /* Look through all the installed architectures */
200 for (ap = bfd_arch_info_list;
201 ap != (bfd_arch_info_type *)NULL;
204 if (ap->scan(ap, string))
207 return (bfd_arch_info_type *)NULL;
214 bfd_arch_get_compatible
218 This routine is used to determine whether two BFDs'
219 architectures and achine types are compatible. It calculates
220 the lowest common denominator between the two architectures
221 and machine types implied by the BFDs and returns a pointer to
222 an arch_info structure describing the compatible machine.
226 CONST bfd_arch_info_type *bfd_arch_get_compatible(
231 CONST bfd_arch_info_type *
232 DEFUN(bfd_arch_get_compatible,(abfd, bbfd),
237 return abfd->arch_info->compatible(abfd->arch_info,bbfd->arch_info);
245 bfd_default_arch_struct
248 What bfds are seeded with
251 .extern bfd_arch_info_type bfd_default_arch_struct;
255 bfd_arch_info_type bfd_default_arch_struct =
257 32,32,8,bfd_arch_unknown,0,"unknown","unknown",true,
258 bfd_default_compatible,
261 bfd_default_reloc_type_lookup
270 void bfd_set_arch_info(bfd *, bfd_arch_info_type *);
274 void DEFUN(bfd_set_arch_info,(abfd, arg),
276 bfd_arch_info_type *arg)
278 abfd->arch_info = arg;
283 bfd_default_set_arch_mach
286 Set the architecture and machine type in a bfd. This finds the
287 correct pointer to structure and inserts it into the arch_info
292 boolean bfd_default_set_arch_mach(bfd *abfd,
293 enum bfd_architecture arch,
298 boolean DEFUN(bfd_default_set_arch_mach,(abfd, arch, mach),
300 enum bfd_architecture arch AND
303 static struct bfd_arch_info *old_ptr = &bfd_default_arch_struct;
304 boolean found = false;
305 /* run through the table to find the one we want, we keep a little
306 cache to speed things up */
307 if (old_ptr == 0 || arch != old_ptr->arch || mach != old_ptr->mach) {
308 bfd_arch_info_type *ptr;
309 old_ptr = (bfd_arch_info_type *)NULL;
310 for (ptr = bfd_arch_info_list;
311 ptr != (bfd_arch_info_type *)NULL;
313 if (ptr->arch == arch &&
314 ((ptr->mach == mach) || (ptr->the_default && mach == 0))) {
321 /*looked for it and it wasn't there, so put in the default */
322 old_ptr = &bfd_default_arch_struct;
327 /* it was in the cache */
331 abfd->arch_info = old_ptr;
345 Returns the enumerated type which describes the supplied bfd's
349 enum bfd_architecture bfd_get_arch(bfd *abfd);
352 enum bfd_architecture DEFUN(bfd_get_arch, (abfd), bfd *abfd)
354 return abfd->arch_info->arch;
362 Returns the long type which describes the supplied bfd's
366 unsigned long bfd_get_mach(bfd *abfd);
370 DEFUN(bfd_get_mach, (abfd), bfd *abfd)
372 return abfd->arch_info->mach;
377 bfd_arch_bits_per_byte
380 Returns the number of bits in one of the architectures bytes
383 unsigned int bfd_arch_bits_per_byte(bfd *abfd);
386 unsigned int DEFUN(bfd_arch_bits_per_byte, (abfd), bfd *abfd)
388 return abfd->arch_info->bits_per_byte;
393 bfd_arch_bits_per_address
396 Returns the number of bits in one of the architectures addresses
399 unsigned int bfd_arch_bits_per_address(bfd *abfd);
402 unsigned int DEFUN(bfd_arch_bits_per_address, (abfd), bfd *abfd)
404 return abfd->arch_info->bits_per_address;
409 extern void EXFUN(bfd_h8300_arch,(void));
410 extern void EXFUN(bfd_i960_arch,(void));
411 extern void EXFUN(bfd_empty_arch,(void));
412 extern void EXFUN(bfd_sparc_arch,(void));
413 extern void EXFUN(bfd_m88k_arch,(void));
414 extern void EXFUN(bfd_m68k_arch,(void));
415 extern void EXFUN(bfd_vax_arch,(void));
416 extern void EXFUN(bfd_a29k_arch,(void));
417 extern void EXFUN(bfd_mips_arch,(void));
418 extern void EXFUN(bfd_i386_arch,(void));
419 extern void EXFUN(bfd_rs6000_arch,(void));
423 static void EXFUN((*archures_init_table[]),()) =
425 #ifdef SELECT_ARCHITECTURES
426 SELECT_ARCHITECTURES,
449 This routine initializes the architecture dispatch table by
450 calling all installed architecture packages and getting them
454 void bfd_arch_init(void);
459 DEFUN_VOID(bfd_arch_init)
461 void EXFUN((**ptable),());
462 for (ptable = archures_init_table;
476 Link the provided arch info structure into the list
479 void bfd_arch_linkin(bfd_arch_info_type *);
483 void DEFUN(bfd_arch_linkin,(ptr),
484 bfd_arch_info_type *ptr)
486 ptr->next = bfd_arch_info_list;
487 bfd_arch_info_list = ptr;
493 bfd_default_compatible
496 The default function for testing for compatibility.
499 CONST bfd_arch_info_type *bfd_default_compatible
500 (CONST bfd_arch_info_type *a,
501 CONST bfd_arch_info_type *b);
504 CONST bfd_arch_info_type *
505 DEFUN(bfd_default_compatible,(a,b),
506 CONST bfd_arch_info_type *a AND
507 CONST bfd_arch_info_type *b)
509 if(a->arch != b->arch) return NULL;
511 if (a->mach > b->mach) {
514 if (b->mach > a->mach) {
526 The default function for working out whether this is an
527 architecture hit and a machine hit.
530 boolean bfd_default_scan(CONST struct bfd_arch_info *, CONST char *);
535 DEFUN(bfd_default_scan,(info, string),
536 CONST struct bfd_arch_info *info AND
541 unsigned long number;
542 enum bfd_architecture arch;
543 /* First test for an exact match */
544 if (strcmp(string, info->printable_name) == 0) return true;
546 /* See how much of the supplied string matches with the
547 architecture, eg the string m68k:68020 would match the 68k entry
548 up to the :, then we get left with the machine number */
550 for (ptr_src = string,
551 ptr_tst = info->arch_name;
552 *ptr_src && *ptr_tst;
556 if (*ptr_src != *ptr_tst) break;
559 /* Chewed up as much of the architecture as will match, skip any
561 if (*ptr_src == ':') ptr_src++;
564 /* nothing more, then only keep this one if it is the default
565 machine for this architecture */
566 return info->the_default;
569 while (isdigit(*ptr_src)) {
570 number = number * 10 + *ptr_src - '0';
583 arch = bfd_arch_m68k;
588 arch = bfd_arch_i386;
591 arch = bfd_arch_a29k;
602 arch = bfd_arch_ns32k;
607 arch = bfd_arch_i860;
611 arch = bfd_arch_rs6000;
617 if (arch != info->arch)
620 if (number != info->mach)
635 bfd_arch_info_type * bfd_get_arch_info(bfd *);
640 DEFUN(bfd_get_arch_info,(abfd),
643 return abfd->arch_info;
653 Look for the architecure info struct which matches the
654 arguments given. A machine of 0 will match the
655 machine/architecture structure which marks itself as the
660 bfd_arch_info_type *bfd_lookup_arch
661 (enum bfd_architecture
669 DEFUN(bfd_lookup_arch,(arch, machine),
670 enum bfd_architecture arch AND
673 bfd_arch_info_type *ap;
675 for (ap = bfd_arch_info_list;
676 ap != (bfd_arch_info_type *)NULL;
678 if (ap->arch == arch &&
679 ((ap->mach == machine)
680 || (ap->the_default && machine == 0))) {
684 return (bfd_arch_info_type *)NULL;
691 bfd_printable_arch_mach
694 Return a printable string representing the architecture and
697 NB. The use of this routine is depreciated.
700 CONST char * bfd_printable_arch_mach
701 (enum bfd_architecture arch, unsigned long machine);
705 DEFUN(bfd_printable_arch_mach,(arch, machine),
706 enum bfd_architecture arch AND
707 unsigned long machine)
709 bfd_arch_info_type *ap = bfd_lookup_arch(arch, machine);
710 if(ap) return ap->printable_name;