1 /* BFD library support routines for architectures.
2 Copyright (C) 1990, 91-97, 1998 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 .#define bfd_mach_m68000 1
74 .#define bfd_mach_m68008 2
75 .#define bfd_mach_m68010 3
76 .#define bfd_mach_m68020 4
77 .#define bfd_mach_m68030 5
78 .#define bfd_mach_m68040 6
79 .#define bfd_mach_m68060 7
80 .#define bfd_mach_cpu32 8
81 . bfd_arch_vax, {* DEC Vax *}
82 . bfd_arch_i960, {* Intel 960 *}
83 . {* The order of the following is important.
84 . lower number indicates a machine type that
85 . only accepts a subset of the instructions
86 . available to machines with higher numbers.
87 . The exception is the "ca", which is
88 . incompatible with all other machines except
91 .#define bfd_mach_i960_core 1
92 .#define bfd_mach_i960_ka_sa 2
93 .#define bfd_mach_i960_kb_sb 3
94 .#define bfd_mach_i960_mc 4
95 .#define bfd_mach_i960_xa 5
96 .#define bfd_mach_i960_ca 6
97 .#define bfd_mach_i960_jx 7
98 .#define bfd_mach_i960_hx 8
100 . bfd_arch_a29k, {* AMD 29000 *}
101 . bfd_arch_sparc, {* SPARC *}
102 .#define bfd_mach_sparc 1
103 .{* The difference between v8plus and v9 is that v9 is a true 64 bit env. *}
104 .#define bfd_mach_sparc_sparclet 2
105 .#define bfd_mach_sparc_sparclite 3
106 .#define bfd_mach_sparc_v8plus 4
107 .#define bfd_mach_sparc_v8plusa 5 {* with ultrasparc add'ns *}
108 .#define bfd_mach_sparc_sparclite_le 6
109 .#define bfd_mach_sparc_v9 7
110 .#define bfd_mach_sparc_v9a 8 {* with ultrasparc add'ns *}
111 .{* Nonzero if MACH has the v9 instruction set. *}
112 .#define bfd_mach_sparc_v9_p(mach) \
113 . ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a)
114 . bfd_arch_mips, {* MIPS Rxxxx *}
115 . {* start-sanitize-tx19 *}
116 .#define bfd_mach_mips1900 1900
117 . {* end-sanitize-tx19 *}
118 .#define bfd_mach_mips3000 3000
119 .#define bfd_mach_mips3900 3900
120 .#define bfd_mach_mips4000 4000
121 .#define bfd_mach_mips4010 4010
122 .#define bfd_mach_mips4100 4100
123 .#define bfd_mach_mips4300 4300
124 .#define bfd_mach_mips4400 4400
125 .#define bfd_mach_mips4600 4600
126 .#define bfd_mach_mips4650 4650
127 . {* start-sanitize-vr4320 *}
128 .#define bfd_mach_mips4320 4320
129 . {* end-sanitize-vr4320 *}
130 . {* start-sanitize-tx49 *}
131 .#define bfd_mach_mips4900 4900
132 . {* end-sanitize-tx49 *}
133 .#define bfd_mach_mips5000 5000
134 . {* start-sanitize-cygnus *} {* CYGNUS LOCAL vr5400/raeburn *}
135 .#define bfd_mach_mips5400 5400
136 . {* end-sanitize-cygnus *}
137 . {* start-sanitize-r5900 *}
138 .#define bfd_mach_mips5900 5900
139 . {* end-sanitize-r5900 *}
140 .#define bfd_mach_mips6000 6000
141 .#define bfd_mach_mips8000 8000
142 .#define bfd_mach_mips10000 10000
143 .#define bfd_mach_mips16 16
144 . {* start-sanitize-sky *}
145 . {* The DVP is a machine within the mips architecture. *}
146 .#define bfd_mach_dvp_dma 42000
147 .#define bfd_mach_dvp_vif 42001
148 .#define bfd_mach_dvp_vu 42002
149 .#define bfd_mach_dvp_gif 42003
150 .#define bfd_mach_dvp_p(mach) ((mach) >= 42000 && (mach) <= 42003)
151 . {* end-sanitize-sky *}
152 . bfd_arch_i386, {* Intel 386 *}
153 .#define bfd_mach_i386_i386 0
154 .#define bfd_mach_i386_i8086 1
155 . bfd_arch_we32k, {* AT&T WE32xxx *}
156 . bfd_arch_tahoe, {* CCI/Harris Tahoe *}
157 . bfd_arch_i860, {* Intel 860 *}
158 . bfd_arch_romp, {* IBM ROMP PC/RT *}
159 . bfd_arch_alliant, {* Alliant *}
160 . bfd_arch_convex, {* Convex *}
161 . bfd_arch_m88k, {* Motorola 88xxx *}
162 . bfd_arch_pyramid, {* Pyramid Technology *}
163 . bfd_arch_h8300, {* Hitachi H8/300 *}
164 .#define bfd_mach_h8300 1
165 .#define bfd_mach_h8300h 2
166 .#define bfd_mach_h8300s 3
167 . bfd_arch_powerpc, {* PowerPC *}
168 . bfd_arch_rs6000, {* IBM RS/6000 *}
169 . bfd_arch_hppa, {* HP PA RISC *}
170 . bfd_arch_d10v, {* Mitsubishi D10V *}
171 . bfd_arch_d30v, {* Mitsubishi D30V *}
172 . bfd_arch_z8k, {* Zilog Z8000 *}
173 .#define bfd_mach_z8001 1
174 .#define bfd_mach_z8002 2
175 . bfd_arch_h8500, {* Hitachi H8/500 *}
176 . bfd_arch_sh, {* Hitachi SH *}
177 .#define bfd_mach_sh 0
178 .#define bfd_mach_sh3 0x30
179 .#define bfd_mach_sh3e 0x3e
180 .#define bfd_mach_sh4 0x40
181 . bfd_arch_alpha, {* Dec Alpha *}
182 . bfd_arch_arm, {* Advanced Risc Machines ARM *}
183 .#define bfd_mach_arm_2 1
184 .#define bfd_mach_arm_2a 2
185 .#define bfd_mach_arm_3 3
186 .#define bfd_mach_arm_3M 4
187 .#define bfd_mach_arm_4 5
188 .#define bfd_mach_arm_4T 6
189 . bfd_arch_ns32k, {* National Semiconductors ns32000 *}
190 . bfd_arch_w65, {* WDC 65816 *}
191 . bfd_arch_tic30, {* Texas Instruments TMS320C30 *}
192 . {* start-sanitize-tic80 *}
193 . bfd_arch_tic80, {* TI TMS320c80 (MVP) *}
194 . {* end-sanitize-tic80 *}
195 . bfd_arch_v850, {* NEC V850 *}
196 .#define bfd_mach_v850 0
197 . {* start-sanitize-v850e *}
198 .#define bfd_mach_v850e 'E'
199 .#define bfd_mach_v850ea 'A'
200 . {* end-sanitize-v850e *}
201 . bfd_arch_arc, {* Argonaut RISC Core *}
202 .#define bfd_mach_arc_base 0
203 . bfd_arch_m32r, {* Mitsubishi M32R/D *}
204 .#define bfd_mach_m32r 0 {* backwards compatibility *}
205 . {* start-sanitize-m32rx *}
206 .#define bfd_mach_m32rx 'x'
207 . {* end-sanitize-m32rx *}
208 . bfd_arch_mn10200, {* Matsushita MN10200 *}
209 . bfd_arch_mn10300, {* Matsushita MN10300 *}
210 .#define bfd_mach_mn10300 300
211 . {* start-sanitize-am33 *}
212 .#define bfd_mach_am33 330
213 . {* end-sanitize-am33 *}
226 This structure contains information on architectures for use
230 .typedef struct bfd_arch_info
233 . int bits_per_address;
235 . enum bfd_architecture arch;
236 . unsigned long mach;
237 . const char *arch_name;
238 . const char *printable_name;
239 . unsigned int section_align_power;
240 . {* true if this is the default machine for the architecture *}
241 . boolean the_default;
242 . const struct bfd_arch_info * (*compatible)
243 . PARAMS ((const struct bfd_arch_info *a,
244 . const struct bfd_arch_info *b));
246 . boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
248 . const struct bfd_arch_info *next;
249 .} bfd_arch_info_type;
252 extern const bfd_arch_info_type bfd_a29k_arch
;
253 extern const bfd_arch_info_type bfd_alpha_arch
;
254 extern const bfd_arch_info_type bfd_arc_arch
;
255 extern const bfd_arch_info_type bfd_arm_arch
;
256 extern const bfd_arch_info_type bfd_d10v_arch
;
257 extern const bfd_arch_info_type bfd_d30v_arch
;
258 extern const bfd_arch_info_type bfd_h8300_arch
;
259 extern const bfd_arch_info_type bfd_h8500_arch
;
260 extern const bfd_arch_info_type bfd_hppa_arch
;
261 extern const bfd_arch_info_type bfd_i386_arch
;
262 extern const bfd_arch_info_type bfd_i860_arch
;
263 extern const bfd_arch_info_type bfd_i960_arch
;
264 extern const bfd_arch_info_type bfd_m32r_arch
;
265 extern const bfd_arch_info_type bfd_m68k_arch
;
266 extern const bfd_arch_info_type bfd_m88k_arch
;
267 extern const bfd_arch_info_type bfd_mips_arch
;
268 extern const bfd_arch_info_type bfd_mn10200_arch
;
269 extern const bfd_arch_info_type bfd_mn10300_arch
;
270 extern const bfd_arch_info_type bfd_powerpc_arch
;
271 extern const bfd_arch_info_type bfd_rs6000_arch
;
272 extern const bfd_arch_info_type bfd_sh_arch
;
273 extern const bfd_arch_info_type bfd_sparc_arch
;
274 extern const bfd_arch_info_type bfd_tic30_arch
;
275 /* start-sanitize-tic80 */
276 extern const bfd_arch_info_type bfd_tic80_arch
;
277 /* end-sanitize-tic80 */
278 extern const bfd_arch_info_type bfd_vax_arch
;
279 extern const bfd_arch_info_type bfd_we32k_arch
;
280 extern const bfd_arch_info_type bfd_z8k_arch
;
281 extern const bfd_arch_info_type bfd_ns32k_arch
;
282 extern const bfd_arch_info_type bfd_w65_arch
;
283 extern const bfd_arch_info_type bfd_v850_arch
;
285 static const bfd_arch_info_type
* const bfd_archures_list
[] =
287 #ifdef SELECT_ARCHITECTURES
288 SELECT_ARCHITECTURES
,
313 /* start-sanitize-tic80 */
315 /* end-sanitize-tic80 */
331 const char *bfd_printable_name(bfd *abfd);
334 Return a printable string representing the architecture and machine
335 from the pointer to the architecture info structure.
340 bfd_printable_name (abfd
)
343 return abfd
->arch_info
->printable_name
;
353 const bfd_arch_info_type *bfd_scan_arch(const char *string);
356 Figure out if BFD supports any cpu which could be described with
357 the name @var{string}. Return a pointer to an <<arch_info>>
358 structure if a machine is found, otherwise NULL.
362 const bfd_arch_info_type
*
363 bfd_scan_arch (string
)
366 const bfd_arch_info_type
* const *app
, *ap
;
368 /* Look through all the installed architectures */
369 for (app
= bfd_archures_list
; *app
!= NULL
; app
++)
371 for (ap
= *app
; ap
!= NULL
; ap
= ap
->next
)
373 if (ap
->scan (ap
, string
))
388 const char **bfd_arch_list(void);
391 Return a freshly malloced NULL-terminated vector of the names
392 of all the valid BFD architectures. Do not modify the names.
400 const char **name_ptr
;
401 const char **name_list
;
402 const bfd_arch_info_type
* const *app
;
404 /* Determine the number of architectures */
406 for (app
= bfd_archures_list
; *app
!= NULL
; app
++)
408 const bfd_arch_info_type
*ap
;
409 for (ap
= *app
; ap
!= NULL
; ap
= ap
->next
)
415 name_list
= (CONST
char **)
416 bfd_malloc ((vec_length
+ 1) * sizeof (char **));
417 if (name_list
== NULL
)
420 /* Point the list at each of the names */
421 name_ptr
= name_list
;
422 for (app
= bfd_archures_list
; *app
!= NULL
; app
++)
424 const bfd_arch_info_type
*ap
;
425 for (ap
= *app
; ap
!= NULL
; ap
= ap
->next
)
427 *name_ptr
= ap
->printable_name
;
440 bfd_arch_get_compatible
443 const bfd_arch_info_type *bfd_arch_get_compatible(
448 Determine whether two BFDs'
449 architectures and machine types are compatible. Calculates
450 the lowest common denominator between the two architectures
451 and machine types implied by the BFDs and returns a pointer to
452 an <<arch_info>> structure describing the compatible machine.
455 const bfd_arch_info_type
*
456 bfd_arch_get_compatible (abfd
, bbfd
)
460 /* If either architecture is unknown, then all we can do is assume
461 the user knows what he's doing. */
462 if (abfd
->arch_info
->arch
== bfd_arch_unknown
)
463 return bbfd
->arch_info
;
464 if (bbfd
->arch_info
->arch
== bfd_arch_unknown
)
465 return abfd
->arch_info
;
467 /* Otherwise architecture-specific code has to decide. */
468 return abfd
->arch_info
->compatible (abfd
->arch_info
, bbfd
->arch_info
);
474 bfd_default_arch_struct
477 The <<bfd_default_arch_struct>> is an item of
478 <<bfd_arch_info_type>> which has been initialized to a fairly
479 generic state. A BFD starts life by pointing to this
480 structure, until the correct back end has determined the real
481 architecture of the file.
483 .extern const bfd_arch_info_type bfd_default_arch_struct;
487 const bfd_arch_info_type bfd_default_arch_struct
=
489 32,32,8,bfd_arch_unknown
,0,"unknown","unknown",2,true,
490 bfd_default_compatible
,
500 void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
503 Set the architecture info of @var{abfd} to @var{arg}.
507 bfd_set_arch_info (abfd
, arg
)
509 const bfd_arch_info_type
*arg
;
511 abfd
->arch_info
= arg
;
516 bfd_default_set_arch_mach
519 boolean bfd_default_set_arch_mach(bfd *abfd,
520 enum bfd_architecture arch,
524 Set the architecture and machine type in BFD @var{abfd}
525 to @var{arch} and @var{mach}. Find the correct
526 pointer to a structure and insert it into the <<arch_info>>
531 bfd_default_set_arch_mach (abfd
, arch
, mach
)
533 enum bfd_architecture arch
;
536 const bfd_arch_info_type
* const *app
, *ap
;
538 for (app
= bfd_archures_list
; *app
!= NULL
; app
++)
540 for (ap
= *app
; ap
!= NULL
; ap
= ap
->next
)
544 || (mach
== 0 && ap
->the_default
)))
546 abfd
->arch_info
= ap
;
552 abfd
->arch_info
= &bfd_default_arch_struct
;
553 bfd_set_error (bfd_error_bad_value
);
563 enum bfd_architecture bfd_get_arch(bfd *abfd);
566 Return the enumerated type which describes the BFD @var{abfd}'s
571 enum bfd_architecture
575 return abfd
->arch_info
->arch
;
583 unsigned long bfd_get_mach(bfd *abfd);
586 Return the long type which describes the BFD @var{abfd}'s
594 return abfd
->arch_info
->mach
;
599 bfd_arch_bits_per_byte
602 unsigned int bfd_arch_bits_per_byte(bfd *abfd);
605 Return the number of bits in one of the BFD @var{abfd}'s
606 architecture's bytes.
611 bfd_arch_bits_per_byte (abfd
)
614 return abfd
->arch_info
->bits_per_byte
;
619 bfd_arch_bits_per_address
622 unsigned int bfd_arch_bits_per_address(bfd *abfd);
625 Return the number of bits in one of the BFD @var{abfd}'s
626 architecture's addresses.
630 bfd_arch_bits_per_address (abfd
)
633 return abfd
->arch_info
->bits_per_address
;
639 bfd_default_compatible
642 const bfd_arch_info_type *bfd_default_compatible
643 (const bfd_arch_info_type *a,
644 const bfd_arch_info_type *b);
647 The default function for testing for compatibility.
650 const bfd_arch_info_type
*
651 bfd_default_compatible (a
,b
)
652 const bfd_arch_info_type
*a
;
653 const bfd_arch_info_type
*b
;
655 if (a
->arch
!= b
->arch
)
658 if (a
->mach
> b
->mach
)
661 if (b
->mach
> a
->mach
)
673 boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
676 The default function for working out whether this is an
677 architecture hit and a machine hit.
681 bfd_default_scan (info
, string
)
682 const struct bfd_arch_info
*info
;
687 unsigned long number
;
688 enum bfd_architecture arch
;
689 const char *printable_name_colon
;
691 /* Exact match of the architecture name (ARCH_NAME) and also the
692 default architecture? */
693 if (strcasecmp (string
, info
->arch_name
) == 0
694 && info
->the_default
)
697 /* Exact match of the machine name (PRINTABLE_NAME)? */
698 if (strcasecmp (string
, info
->printable_name
) == 0)
701 /* Given that printable_name contains no colon, attempt to match:
702 ARCH_NAME [ ":" ] PRINTABLE_NAME? */
703 printable_name_colon
= strchr (info
->printable_name
, ':');
704 if (printable_name_colon
== NULL
)
706 int strlen_arch_name
= strlen (info
->arch_name
);
707 if (strncasecmp (string
, info
->arch_name
, strlen_arch_name
) == 0)
709 if (string
[strlen_arch_name
] == ':')
711 if (strcasecmp (string
+ strlen_arch_name
+ 1,
712 info
->printable_name
) == 0)
717 if (strcasecmp (string
+ strlen_arch_name
,
718 info
->printable_name
) == 0)
724 /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>;
725 Attempt to match: <arch> <mach>? */
726 if (printable_name_colon
!= NULL
)
728 int colon_index
= printable_name_colon
- info
->printable_name
;
729 if (strncasecmp (string
, info
->printable_name
, colon_index
) == 0
730 && strcasecmp (string
+ colon_index
,
731 info
->printable_name
+ colon_index
+ 1) == 0)
735 /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>; Do not
736 attempt to match just <mach>, it could be ambigious. This test
737 is left until later. */
739 /* NOTE: The below is retained for compatibility only. Please do not
742 /* See how much of the supplied string matches with the
743 architecture, eg the string m68k:68020 would match the 68k entry
744 up to the :, then we get left with the machine number */
746 for (ptr_src
= string
, ptr_tst
= info
->arch_name
;
747 *ptr_src
&& *ptr_tst
;
748 ptr_src
++, ptr_tst
++)
750 if (*ptr_src
!= *ptr_tst
) break;
753 /* Chewed up as much of the architecture as will match, skip any
760 /* nothing more, then only keep this one if it is the default
761 machine for this architecture */
762 return info
->the_default
;
766 while (isdigit ((unsigned char) *ptr_src
))
768 number
= number
* 10 + *ptr_src
- '0';
772 /* NOTE: The below is retained for compatibility only.
773 PLEASE DO NOT ADD TO THIS CODE. */
777 /* FIXME: These are needed to parse IEEE objects. */
779 arch
= bfd_arch_m68k
;
780 number
= bfd_mach_m68000
;
783 arch
= bfd_arch_m68k
;
784 number
= bfd_mach_m68010
;
787 arch
= bfd_arch_m68k
;
788 number
= bfd_mach_m68020
;
791 arch
= bfd_arch_m68k
;
792 number
= bfd_mach_m68030
;
795 arch
= bfd_arch_m68k
;
796 number
= bfd_mach_m68040
;
799 arch
= bfd_arch_m68k
;
800 number
= bfd_mach_m68060
;
803 arch
= bfd_arch_m68k
;
804 number
= bfd_mach_cpu32
;
808 arch
= bfd_arch_we32k
;
812 arch
= bfd_arch_mips
;
813 number
= bfd_mach_mips3000
;
817 arch
= bfd_arch_mips
;
818 number
= bfd_mach_mips4000
;
822 arch
= bfd_arch_rs6000
;
829 if (arch
!= info
->arch
)
832 if (number
!= info
->mach
)
844 const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
847 Return the architecture info struct in @var{abfd}.
850 const bfd_arch_info_type
*
851 bfd_get_arch_info (abfd
)
854 return abfd
->arch_info
;
863 const bfd_arch_info_type *bfd_lookup_arch
864 (enum bfd_architecture
866 unsigned long machine);
869 Look for the architecure info structure which matches the
870 arguments @var{arch} and @var{machine}. A machine of 0 matches the
871 machine/architecture structure which marks itself as the
875 const bfd_arch_info_type
*
876 bfd_lookup_arch (arch
, machine
)
877 enum bfd_architecture arch
;
878 unsigned long machine
;
880 const bfd_arch_info_type
* const *app
, *ap
;
882 for (app
= bfd_archures_list
; *app
!= NULL
; app
++)
884 for (ap
= *app
; ap
!= NULL
; ap
= ap
->next
)
887 && (ap
->mach
== machine
888 || (machine
== 0 && ap
->the_default
)))
899 bfd_printable_arch_mach
902 const char *bfd_printable_arch_mach
903 (enum bfd_architecture arch, unsigned long machine);
906 Return a printable string representing the architecture and
909 This routine is depreciated.
913 bfd_printable_arch_mach (arch
, machine
)
914 enum bfd_architecture arch
;
915 unsigned long machine
;
917 const bfd_arch_info_type
*ap
= bfd_lookup_arch (arch
, machine
);
920 return ap
->printable_name
;