archures.c revision 33965
133965Sjdp/* BFD library support routines for architectures.
233965Sjdp   Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
333965Sjdp   Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
433965Sjdp
533965SjdpThis file is part of BFD, the Binary File Descriptor library.
633965Sjdp
733965SjdpThis program is free software; you can redistribute it and/or modify
833965Sjdpit under the terms of the GNU General Public License as published by
933965Sjdpthe Free Software Foundation; either version 2 of the License, or
1033965Sjdp(at your option) any later version.
1133965Sjdp
1233965SjdpThis program is distributed in the hope that it will be useful,
1333965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1433965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1533965SjdpGNU General Public License for more details.
1633965Sjdp
1733965SjdpYou should have received a copy of the GNU General Public License
1833965Sjdpalong with this program; if not, write to the Free Software
1933965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2033965Sjdp
2133965Sjdp#include "bfd.h"
2233965Sjdp#include "sysdep.h"
2333965Sjdp#include "libbfd.h"
2433965Sjdp#include <ctype.h>
2533965Sjdp
2633965Sjdp/*
2733965Sjdp
2833965SjdpSECTION
2933965Sjdp	Architectures
3033965Sjdp
3133965Sjdp	BFD keeps one atom in a BFD describing the
3233965Sjdp	architecture of the data attached to the BFD: a pointer to a
3333965Sjdp	<<bfd_arch_info_type>>.
3433965Sjdp
3533965Sjdp	Pointers to structures can be requested independently of a BFD
3633965Sjdp	so that an architecture's information can be interrogated
3733965Sjdp	without access to an open BFD.
3833965Sjdp
3933965Sjdp	The architecture information is provided by each architecture package.
4033965Sjdp	The set of default architectures is selected by the macro
4133965Sjdp	<<SELECT_ARCHITECTURES>>.  This is normally set up in the
4233965Sjdp	@file{config/@var{target}.mt} file of your choice.  If the name is not
4333965Sjdp	defined, then all the architectures supported are included.
4433965Sjdp
4533965Sjdp	When BFD starts up, all the architectures are called with an
4633965Sjdp	initialize method.  It is up to the architecture back end to
4733965Sjdp	insert as many items into the list of architectures as it wants to;
4833965Sjdp	generally this would be one for each machine and one for the
4933965Sjdp	default case (an item with a machine field of 0).
5033965Sjdp
5133965Sjdp	BFD's idea of an architecture is implemented in	@file{archures.c}.
5233965Sjdp*/
5333965Sjdp
5433965Sjdp/*
5533965Sjdp
5633965SjdpSUBSECTION
5733965Sjdp	bfd_architecture
5833965Sjdp
5933965SjdpDESCRIPTION
6033965Sjdp	This enum gives the object file's CPU architecture, in a
6133965Sjdp	global sense---i.e., what processor family does it belong to?
6233965Sjdp	Another field indicates which processor within
6333965Sjdp	the family is in use.  The machine gives a number which
6433965Sjdp	distinguishes different versions of the architecture,
6533965Sjdp	containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
6633965Sjdp	and 68020 and 68030 for Motorola 68020 and 68030.
6733965Sjdp
6833965Sjdp.enum bfd_architecture
6933965Sjdp.{
7033965Sjdp.  bfd_arch_unknown,   {* File arch not known *}
7133965Sjdp.  bfd_arch_obscure,   {* Arch known, not one of these *}
7233965Sjdp.  bfd_arch_m68k,      {* Motorola 68xxx *}
7333965Sjdp.  bfd_arch_vax,       {* DEC Vax *}
7433965Sjdp.  bfd_arch_i960,      {* Intel 960 *}
7533965Sjdp.    {* The order of the following is important.
7633965Sjdp.       lower number indicates a machine type that
7733965Sjdp.       only accepts a subset of the instructions
7833965Sjdp.       available to machines with higher numbers.
7933965Sjdp.       The exception is the "ca", which is
8033965Sjdp.       incompatible with all other machines except
8133965Sjdp.       "core". *}
8233965Sjdp.
8333965Sjdp.#define bfd_mach_i960_core      1
8433965Sjdp.#define bfd_mach_i960_ka_sa     2
8533965Sjdp.#define bfd_mach_i960_kb_sb     3
8633965Sjdp.#define bfd_mach_i960_mc        4
8733965Sjdp.#define bfd_mach_i960_xa        5
8833965Sjdp.#define bfd_mach_i960_ca        6
8933965Sjdp.#define bfd_mach_i960_jx	 7
9033965Sjdp.#define bfd_mach_i960_hx        8
9133965Sjdp.
9233965Sjdp.  bfd_arch_a29k,      {* AMD 29000 *}
9333965Sjdp.  bfd_arch_sparc,     {* SPARC *}
9433965Sjdp.#define bfd_mach_sparc			1
9533965Sjdp.{* The difference between v8plus and v9 is that v9 is a true 64 bit env.  *}
9633965Sjdp.#define bfd_mach_sparc_sparclet	2
9733965Sjdp.#define bfd_mach_sparc_sparclite	3
9833965Sjdp.#define bfd_mach_sparc_v8plus		4
9933965Sjdp.#define bfd_mach_sparc_v8plusa		5 {* with ultrasparc add'ns *}
10033965Sjdp.#define bfd_mach_sparc_v9		6
10133965Sjdp.#define bfd_mach_sparc_v9a		7 {* with ultrasparc add'ns *}
10233965Sjdp.{* Nonzero if MACH has the v9 instruction set.  *}
10333965Sjdp.#define bfd_mach_sparc_v9_p(mach) \
10433965Sjdp.  ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a)
10533965Sjdp.  bfd_arch_mips,      {* MIPS Rxxxx *}
10633965Sjdp.  bfd_arch_i386,      {* Intel 386 *}
10733965Sjdp.#define bfd_mach_i386_i386 0
10833965Sjdp.#define bfd_mach_i386_i8086 1
10933965Sjdp.  bfd_arch_we32k,     {* AT&T WE32xxx *}
11033965Sjdp.  bfd_arch_tahoe,     {* CCI/Harris Tahoe *}
11133965Sjdp.  bfd_arch_i860,      {* Intel 860 *}
11233965Sjdp.  bfd_arch_romp,      {* IBM ROMP PC/RT *}
11333965Sjdp.  bfd_arch_alliant,   {* Alliant *}
11433965Sjdp.  bfd_arch_convex,    {* Convex *}
11533965Sjdp.  bfd_arch_m88k,      {* Motorola 88xxx *}
11633965Sjdp.  bfd_arch_pyramid,   {* Pyramid Technology *}
11733965Sjdp.  bfd_arch_h8300,     {* Hitachi H8/300 *}
11833965Sjdp.#define bfd_mach_h8300   1
11933965Sjdp.#define bfd_mach_h8300h  2
12033965Sjdp.#define bfd_mach_h8300s  3
12133965Sjdp.  bfd_arch_powerpc,   {* PowerPC *}
12233965Sjdp.  bfd_arch_rs6000,    {* IBM RS/6000 *}
12333965Sjdp.  bfd_arch_hppa,      {* HP PA RISC *}
12433965Sjdp.  bfd_arch_d10v,      {* Mitsubishi D10V *}
12533965Sjdp.  bfd_arch_z8k,       {* Zilog Z8000 *}
12633965Sjdp.#define bfd_mach_z8001		1
12733965Sjdp.#define bfd_mach_z8002		2
12833965Sjdp.  bfd_arch_h8500,     {* Hitachi H8/500 *}
12933965Sjdp.  bfd_arch_sh,        {* Hitachi SH *}
13033965Sjdp.  bfd_arch_alpha,     {* Dec Alpha *}
13133965Sjdp.  bfd_arch_arm,       {* Advanced Risc Machines ARM *}
13233965Sjdp.  bfd_arch_ns32k,     {* National Semiconductors ns32000 *}
13333965Sjdp.  bfd_arch_w65,       {* WDC 65816 *}
13433965Sjdp.  bfd_arch_m32r,      {* Mitsubishi M32R/D *}
13533965Sjdp.  bfd_arch_mn10200,   {* Matsushita MN10200 *}
13633965Sjdp.  bfd_arch_mn10300,   {* Matsushita MN10300 *}
13733965Sjdp.  bfd_arch_last
13833965Sjdp.  };
13933965Sjdp
14033965Sjdp
14133965Sjdp*/
14233965Sjdp
14333965Sjdp/*
14433965Sjdp
14533965SjdpSUBSECTION
14633965Sjdp	bfd_arch_info
14733965Sjdp
14833965SjdpDESCRIPTION
14933965Sjdp	This structure contains information on architectures for use
15033965Sjdp	within BFD.
15133965Sjdp
15233965Sjdp.
15333965Sjdp.typedef struct bfd_arch_info
15433965Sjdp.{
15533965Sjdp.  int bits_per_word;
15633965Sjdp.  int bits_per_address;
15733965Sjdp.  int bits_per_byte;
15833965Sjdp.  enum bfd_architecture arch;
15933965Sjdp.  unsigned long mach;
16033965Sjdp.  const char *arch_name;
16133965Sjdp.  const char *printable_name;
16233965Sjdp.  unsigned int section_align_power;
16333965Sjdp. {* true if this is the default machine for the architecture *}
16433965Sjdp.  boolean the_default;
16533965Sjdp.  const struct bfd_arch_info * (*compatible)
16633965Sjdp.	PARAMS ((const struct bfd_arch_info *a,
16733965Sjdp.	         const struct bfd_arch_info *b));
16833965Sjdp.
16933965Sjdp.  boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
17033965Sjdp.
17133965Sjdp.  const struct bfd_arch_info *next;
17233965Sjdp.} bfd_arch_info_type;
17333965Sjdp*/
17433965Sjdp
17533965Sjdpextern const bfd_arch_info_type bfd_a29k_arch;
17633965Sjdpextern const bfd_arch_info_type bfd_alpha_arch;
17733965Sjdpextern const bfd_arch_info_type bfd_arm_arch;
17833965Sjdpextern const bfd_arch_info_type bfd_d10v_arch;
17933965Sjdpextern const bfd_arch_info_type bfd_h8300_arch;
18033965Sjdpextern const bfd_arch_info_type bfd_h8500_arch;
18133965Sjdpextern const bfd_arch_info_type bfd_hppa_arch;
18233965Sjdpextern const bfd_arch_info_type bfd_i386_arch;
18333965Sjdpextern const bfd_arch_info_type bfd_i860_arch;
18433965Sjdpextern const bfd_arch_info_type bfd_i960_arch;
18533965Sjdpextern const bfd_arch_info_type bfd_m32r_arch;
18633965Sjdpextern const bfd_arch_info_type bfd_m68k_arch;
18733965Sjdpextern const bfd_arch_info_type bfd_m88k_arch;
18833965Sjdpextern const bfd_arch_info_type bfd_mips_arch;
18933965Sjdpextern const bfd_arch_info_type bfd_mn10200_arch;
19033965Sjdpextern const bfd_arch_info_type bfd_mn10300_arch;
19133965Sjdpextern const bfd_arch_info_type bfd_powerpc_arch;
19233965Sjdpextern const bfd_arch_info_type bfd_rs6000_arch;
19333965Sjdpextern const bfd_arch_info_type bfd_sh_arch;
19433965Sjdpextern const bfd_arch_info_type bfd_sparc_arch;
19533965Sjdpextern const bfd_arch_info_type bfd_vax_arch;
19633965Sjdpextern const bfd_arch_info_type bfd_we32k_arch;
19733965Sjdpextern const bfd_arch_info_type bfd_z8k_arch;
19833965Sjdpextern const bfd_arch_info_type bfd_ns32k_arch;
19933965Sjdpextern const bfd_arch_info_type bfd_w65_arch;
20033965Sjdp
20133965Sjdpstatic const bfd_arch_info_type * const bfd_archures_list[] =
20233965Sjdp{
20333965Sjdp#ifdef SELECT_ARCHITECTURES
20433965Sjdp  SELECT_ARCHITECTURES,
20533965Sjdp#else
20633965Sjdp  &bfd_a29k_arch,
20733965Sjdp  &bfd_alpha_arch,
20833965Sjdp  &bfd_arm_arch,
20933965Sjdp  &bfd_d10v_arch,
21033965Sjdp  &bfd_h8300_arch,
21133965Sjdp  &bfd_h8500_arch,
21233965Sjdp  &bfd_hppa_arch,
21333965Sjdp  &bfd_i386_arch,
21433965Sjdp  &bfd_i860_arch,
21533965Sjdp  &bfd_i960_arch,
21633965Sjdp  &bfd_m32r_arch,
21733965Sjdp  &bfd_m68k_arch,
21833965Sjdp  &bfd_m88k_arch,
21933965Sjdp  &bfd_mips_arch,
22033965Sjdp  &bfd_mn10200_arch,
22133965Sjdp  &bfd_mn10300_arch,
22233965Sjdp  &bfd_powerpc_arch,
22333965Sjdp  &bfd_rs6000_arch,
22433965Sjdp  &bfd_sh_arch,
22533965Sjdp  &bfd_sparc_arch,
22633965Sjdp  &bfd_vax_arch,
22733965Sjdp  &bfd_we32k_arch,
22833965Sjdp  &bfd_z8k_arch,
22933965Sjdp  &bfd_ns32k_arch,
23033965Sjdp  &bfd_w65_arch,
23133965Sjdp#endif
23233965Sjdp  0
23333965Sjdp};
23433965Sjdp
23533965Sjdp/*
23633965SjdpFUNCTION
23733965Sjdp	bfd_printable_name
23833965Sjdp
23933965SjdpSYNOPSIS
24033965Sjdp	const char *bfd_printable_name(bfd *abfd);
24133965Sjdp
24233965SjdpDESCRIPTION
24333965Sjdp	Return a printable string representing the architecture and machine
24433965Sjdp	from the pointer to the architecture info structure.
24533965Sjdp
24633965Sjdp*/
24733965Sjdp
24833965Sjdpconst char *
24933965Sjdpbfd_printable_name (abfd)
25033965Sjdp     bfd *abfd;
25133965Sjdp{
25233965Sjdp  return abfd->arch_info->printable_name;
25333965Sjdp}
25433965Sjdp
25533965Sjdp
25633965Sjdp
25733965Sjdp/*
25833965SjdpFUNCTION
25933965Sjdp	bfd_scan_arch
26033965Sjdp
26133965SjdpSYNOPSIS
26233965Sjdp	const bfd_arch_info_type *bfd_scan_arch(const char *string);
26333965Sjdp
26433965SjdpDESCRIPTION
26533965Sjdp	Figure out if BFD supports any cpu which could be described with
26633965Sjdp	the name @var{string}.  Return a pointer to an <<arch_info>>
26733965Sjdp	structure if a machine is found, otherwise NULL.
26833965Sjdp
26933965Sjdp*/
27033965Sjdp
27133965Sjdpconst bfd_arch_info_type *
27233965Sjdpbfd_scan_arch (string)
27333965Sjdp     const char *string;
27433965Sjdp{
27533965Sjdp  const bfd_arch_info_type * const *app, *ap;
27633965Sjdp
27733965Sjdp  /* Look through all the installed architectures */
27833965Sjdp  for (app = bfd_archures_list; *app != NULL; app++)
27933965Sjdp    {
28033965Sjdp      for (ap = *app; ap != NULL; ap = ap->next)
28133965Sjdp	{
28233965Sjdp	  if (ap->scan (ap, string))
28333965Sjdp	    return ap;
28433965Sjdp	}
28533965Sjdp    }
28633965Sjdp
28733965Sjdp  return NULL;
28833965Sjdp}
28933965Sjdp
29033965Sjdp
29133965Sjdp
29233965Sjdp/*
29333965SjdpFUNCTION
29433965Sjdp	bfd_arch_get_compatible
29533965Sjdp
29633965SjdpSYNOPSIS
29733965Sjdp	const bfd_arch_info_type *bfd_arch_get_compatible(
29833965Sjdp		const bfd *abfd,
29933965Sjdp	        const bfd *bbfd);
30033965Sjdp
30133965SjdpDESCRIPTION
30233965Sjdp	Determine whether two BFDs'
30333965Sjdp	architectures and machine types are compatible.  Calculates
30433965Sjdp	the lowest common denominator between the two architectures
30533965Sjdp	and machine types implied by the BFDs and returns a pointer to
30633965Sjdp	an <<arch_info>> structure describing the compatible machine.
30733965Sjdp*/
30833965Sjdp
30933965Sjdpconst bfd_arch_info_type *
31033965Sjdpbfd_arch_get_compatible (abfd, bbfd)
31133965Sjdp     const bfd *abfd;
31233965Sjdp     const bfd *bbfd;
31333965Sjdp{
31433965Sjdp  /* If either architecture is unknown, then all we can do is assume
31533965Sjdp     the user knows what he's doing.  */
31633965Sjdp  if (abfd->arch_info->arch == bfd_arch_unknown)
31733965Sjdp  	return bbfd->arch_info;
31833965Sjdp  if (bbfd->arch_info->arch == bfd_arch_unknown)
31933965Sjdp  	return abfd->arch_info;
32033965Sjdp
32133965Sjdp  /* Otherwise architecture-specific code has to decide.  */
32233965Sjdp  return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
32333965Sjdp}
32433965Sjdp
32533965Sjdp
32633965Sjdp/*
32733965SjdpINTERNAL_DEFINITION
32833965Sjdp	bfd_default_arch_struct
32933965Sjdp
33033965SjdpDESCRIPTION
33133965Sjdp	The <<bfd_default_arch_struct>> is an item of
33233965Sjdp	<<bfd_arch_info_type>> which has been initialized to a fairly
33333965Sjdp	generic state.  A BFD starts life by pointing to this
33433965Sjdp	structure, until the correct back end has determined the real
33533965Sjdp	architecture of the file.
33633965Sjdp
33733965Sjdp.extern const bfd_arch_info_type bfd_default_arch_struct;
33833965Sjdp
33933965Sjdp*/
34033965Sjdp
34133965Sjdpconst bfd_arch_info_type bfd_default_arch_struct =
34233965Sjdp{
34333965Sjdp    32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
34433965Sjdp    bfd_default_compatible,
34533965Sjdp    bfd_default_scan,
34633965Sjdp    0,
34733965Sjdp};
34833965Sjdp
34933965Sjdp/*
35033965SjdpFUNCTION
35133965Sjdp	bfd_set_arch_info
35233965Sjdp
35333965SjdpSYNOPSIS
35433965Sjdp	void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
35533965Sjdp
35633965SjdpDESCRIPTION
35733965Sjdp	Set the architecture info of @var{abfd} to @var{arg}.
35833965Sjdp*/
35933965Sjdp
36033965Sjdpvoid
36133965Sjdpbfd_set_arch_info (abfd, arg)
36233965Sjdp     bfd *abfd;
36333965Sjdp     const bfd_arch_info_type *arg;
36433965Sjdp{
36533965Sjdp  abfd->arch_info = arg;
36633965Sjdp}
36733965Sjdp
36833965Sjdp/*
36933965SjdpINTERNAL_FUNCTION
37033965Sjdp	bfd_default_set_arch_mach
37133965Sjdp
37233965SjdpSYNOPSIS
37333965Sjdp	boolean bfd_default_set_arch_mach(bfd *abfd,
37433965Sjdp		enum bfd_architecture arch,
37533965Sjdp		unsigned long mach);
37633965Sjdp
37733965SjdpDESCRIPTION
37833965Sjdp	Set the architecture and machine type in BFD @var{abfd}
37933965Sjdp	to @var{arch} and @var{mach}.  Find the correct
38033965Sjdp	pointer to a structure and insert it into the <<arch_info>>
38133965Sjdp	pointer.
38233965Sjdp*/
38333965Sjdp
38433965Sjdpboolean
38533965Sjdpbfd_default_set_arch_mach (abfd, arch, mach)
38633965Sjdp     bfd *abfd;
38733965Sjdp     enum bfd_architecture arch;
38833965Sjdp     unsigned long mach;
38933965Sjdp{
39033965Sjdp  const bfd_arch_info_type * const *app, *ap;
39133965Sjdp
39233965Sjdp  for (app = bfd_archures_list; *app != NULL; app++)
39333965Sjdp    {
39433965Sjdp      for (ap = *app; ap != NULL; ap = ap->next)
39533965Sjdp	{
39633965Sjdp	  if (ap->arch == arch
39733965Sjdp	      && (ap->mach == mach
39833965Sjdp		  || (mach == 0 && ap->the_default)))
39933965Sjdp	    {
40033965Sjdp	      abfd->arch_info = ap;
40133965Sjdp	      return true;
40233965Sjdp	    }
40333965Sjdp	}
40433965Sjdp    }
40533965Sjdp
40633965Sjdp  abfd->arch_info = &bfd_default_arch_struct;
40733965Sjdp  bfd_set_error (bfd_error_bad_value);
40833965Sjdp  return false;
40933965Sjdp}
41033965Sjdp
41133965Sjdp
41233965Sjdp/*
41333965SjdpFUNCTION
41433965Sjdp	bfd_get_arch
41533965Sjdp
41633965SjdpSYNOPSIS
41733965Sjdp	enum bfd_architecture bfd_get_arch(bfd *abfd);
41833965Sjdp
41933965SjdpDESCRIPTION
42033965Sjdp	Return the enumerated type which describes the BFD @var{abfd}'s
42133965Sjdp	architecture.
42233965Sjdp
42333965Sjdp*/
42433965Sjdp
42533965Sjdpenum bfd_architecture
42633965Sjdpbfd_get_arch (abfd)
42733965Sjdp     bfd *abfd;
42833965Sjdp{
42933965Sjdp    return abfd->arch_info->arch;
43033965Sjdp}
43133965Sjdp
43233965Sjdp/*
43333965SjdpFUNCTION
43433965Sjdp	bfd_get_mach
43533965Sjdp
43633965SjdpSYNOPSIS
43733965Sjdp	unsigned long bfd_get_mach(bfd *abfd);
43833965Sjdp
43933965SjdpDESCRIPTION
44033965Sjdp	Return the long type which describes the BFD @var{abfd}'s
44133965Sjdp	machine.
44233965Sjdp*/
44333965Sjdp
44433965Sjdpunsigned long
44533965Sjdpbfd_get_mach (abfd)
44633965Sjdp     bfd *abfd;
44733965Sjdp{
44833965Sjdp    return abfd->arch_info->mach;
44933965Sjdp}
45033965Sjdp
45133965Sjdp/*
45233965SjdpFUNCTION
45333965Sjdp	bfd_arch_bits_per_byte
45433965Sjdp
45533965SjdpSYNOPSIS
45633965Sjdp	unsigned int bfd_arch_bits_per_byte(bfd *abfd);
45733965Sjdp
45833965SjdpDESCRIPTION
45933965Sjdp	Return the number of bits in one of the BFD @var{abfd}'s
46033965Sjdp	architecture's bytes.
46133965Sjdp
46233965Sjdp*/
46333965Sjdp
46433965Sjdpunsigned int
46533965Sjdpbfd_arch_bits_per_byte (abfd)
46633965Sjdp     bfd *abfd;
46733965Sjdp{
46833965Sjdp  return abfd->arch_info->bits_per_byte;
46933965Sjdp}
47033965Sjdp
47133965Sjdp/*
47233965SjdpFUNCTION
47333965Sjdp	bfd_arch_bits_per_address
47433965Sjdp
47533965SjdpSYNOPSIS
47633965Sjdp	unsigned int bfd_arch_bits_per_address(bfd *abfd);
47733965Sjdp
47833965SjdpDESCRIPTION
47933965Sjdp	Return the number of bits in one of the BFD @var{abfd}'s
48033965Sjdp	architecture's addresses.
48133965Sjdp*/
48233965Sjdp
48333965Sjdpunsigned int
48433965Sjdpbfd_arch_bits_per_address (abfd)
48533965Sjdp     bfd *abfd;
48633965Sjdp{
48733965Sjdp  return abfd->arch_info->bits_per_address;
48833965Sjdp}
48933965Sjdp
49033965Sjdp
49133965Sjdp/*
49233965SjdpINTERNAL_FUNCTION
49333965Sjdp	bfd_default_compatible
49433965Sjdp
49533965SjdpSYNOPSIS
49633965Sjdp	const bfd_arch_info_type *bfd_default_compatible
49733965Sjdp	(const bfd_arch_info_type *a,
49833965Sjdp	const bfd_arch_info_type *b);
49933965Sjdp
50033965SjdpDESCRIPTION
50133965Sjdp	The default function for testing for compatibility.
50233965Sjdp*/
50333965Sjdp
50433965Sjdpconst bfd_arch_info_type *
50533965Sjdpbfd_default_compatible (a,b)
50633965Sjdp     const bfd_arch_info_type *a;
50733965Sjdp     const bfd_arch_info_type *b;
50833965Sjdp{
50933965Sjdp  if (a->arch != b->arch)
51033965Sjdp    return NULL;
51133965Sjdp
51233965Sjdp  if (a->mach > b->mach)
51333965Sjdp    return a;
51433965Sjdp
51533965Sjdp  if (b->mach > a->mach)
51633965Sjdp    return b;
51733965Sjdp
51833965Sjdp  return a;
51933965Sjdp}
52033965Sjdp
52133965Sjdp
52233965Sjdp/*
52333965SjdpINTERNAL_FUNCTION
52433965Sjdp	bfd_default_scan
52533965Sjdp
52633965SjdpSYNOPSIS
52733965Sjdp	boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
52833965Sjdp
52933965SjdpDESCRIPTION
53033965Sjdp	The default function for working out whether this is an
53133965Sjdp	architecture hit and a machine hit.
53233965Sjdp*/
53333965Sjdp
53433965Sjdpboolean
53533965Sjdpbfd_default_scan (info, string)
53633965Sjdp     const struct bfd_arch_info *info;
53733965Sjdp     const char *string;
53833965Sjdp{
53933965Sjdp  const char *ptr_src;
54033965Sjdp  const char *ptr_tst;
54133965Sjdp  unsigned long number;
54233965Sjdp  enum bfd_architecture arch;
54333965Sjdp
54433965Sjdp  /* First test for an exact match */
54533965Sjdp  if (strcmp (string, info->printable_name) == 0)
54633965Sjdp    return true;
54733965Sjdp
54833965Sjdp  /* See how much of the supplied string matches with the
54933965Sjdp     architecture, eg the string m68k:68020 would match the 68k entry
55033965Sjdp     up to the :, then we get left with the machine number */
55133965Sjdp
55233965Sjdp  for (ptr_src = string, ptr_tst = info->arch_name;
55333965Sjdp       *ptr_src && *ptr_tst;
55433965Sjdp       ptr_src++, ptr_tst++)
55533965Sjdp    {
55633965Sjdp      if (*ptr_src != *ptr_tst) break;
55733965Sjdp    }
55833965Sjdp
55933965Sjdp  /* Chewed up as much of the architecture as will match, skip any
56033965Sjdp     colons */
56133965Sjdp  if (*ptr_src == ':')
56233965Sjdp    ptr_src++;
56333965Sjdp
56433965Sjdp  if (*ptr_src == 0)
56533965Sjdp    {
56633965Sjdp      /* nothing more, then only keep this one if it is the default
56733965Sjdp	 machine for this architecture */
56833965Sjdp      return info->the_default;
56933965Sjdp    }
57033965Sjdp
57133965Sjdp  number = 0;
57233965Sjdp  while (isdigit(*ptr_src))
57333965Sjdp    {
57433965Sjdp      number = number * 10 + *ptr_src  - '0';
57533965Sjdp      ptr_src++;
57633965Sjdp    }
57733965Sjdp
57833965Sjdp  switch (number)
57933965Sjdp    {
58033965Sjdp    case 65:
58133965Sjdp      arch = bfd_arch_w65;
58233965Sjdp      break;
58333965Sjdp
58433965Sjdp    case 300:
58533965Sjdp      arch = bfd_arch_h8300;
58633965Sjdp      break;
58733965Sjdp
58833965Sjdp    case 500:
58933965Sjdp      arch = bfd_arch_h8500;
59033965Sjdp      break;
59133965Sjdp
59233965Sjdp    case 68010:
59333965Sjdp    case 68020:
59433965Sjdp    case 68030:
59533965Sjdp    case 68040:
59633965Sjdp    case 68332:
59733965Sjdp    case 68050:
59833965Sjdp    case 68000:
59933965Sjdp      arch = bfd_arch_m68k;
60033965Sjdp      break;
60133965Sjdp
60233965Sjdp    case 386:
60333965Sjdp    case 80386:
60433965Sjdp    case 486:
60533965Sjdp    case 80486:
60633965Sjdp      arch = bfd_arch_i386;
60733965Sjdp      break;
60833965Sjdp
60933965Sjdp    case 29000:
61033965Sjdp      arch = bfd_arch_a29k;
61133965Sjdp      break;
61233965Sjdp
61333965Sjdp    case 8000:
61433965Sjdp      arch = bfd_arch_z8k;
61533965Sjdp      break;
61633965Sjdp
61733965Sjdp    case 32000:
61833965Sjdp      arch = bfd_arch_we32k;
61933965Sjdp      break;
62033965Sjdp
62133965Sjdp    case 860:
62233965Sjdp    case 80860:
62333965Sjdp      arch = bfd_arch_i860;
62433965Sjdp      break;
62533965Sjdp    case 960:
62633965Sjdp    case 80960:
62733965Sjdp      arch = bfd_arch_i960;
62833965Sjdp      break;
62933965Sjdp
63033965Sjdp    case 2000:
63133965Sjdp    case 3000:
63233965Sjdp    case 4000:
63333965Sjdp    case 4400:
63433965Sjdp      arch = bfd_arch_mips;
63533965Sjdp      break;
63633965Sjdp
63733965Sjdp    case 6000:
63833965Sjdp      arch = bfd_arch_rs6000;
63933965Sjdp      break;
64033965Sjdp
64133965Sjdp    default:
64233965Sjdp      return false;
64333965Sjdp    }
64433965Sjdp
64533965Sjdp  if (arch != info->arch)
64633965Sjdp    return false;
64733965Sjdp
64833965Sjdp  if (number != info->mach)
64933965Sjdp    return false;
65033965Sjdp
65133965Sjdp  return true;
65233965Sjdp}
65333965Sjdp
65433965Sjdp
65533965Sjdp/*
65633965SjdpFUNCTION
65733965Sjdp	bfd_get_arch_info
65833965Sjdp
65933965SjdpSYNOPSIS
66033965Sjdp	const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
66133965Sjdp
66233965SjdpDESCRIPTION
66333965Sjdp	Return the architecture info struct in @var{abfd}.
66433965Sjdp*/
66533965Sjdp
66633965Sjdpconst bfd_arch_info_type *
66733965Sjdpbfd_get_arch_info (abfd)
66833965Sjdp     bfd *abfd;
66933965Sjdp{
67033965Sjdp  return abfd->arch_info;
67133965Sjdp}
67233965Sjdp
67333965Sjdp
67433965Sjdp/*
67533965SjdpFUNCTION
67633965Sjdp	bfd_lookup_arch
67733965Sjdp
67833965SjdpSYNOPSIS
67933965Sjdp	const bfd_arch_info_type *bfd_lookup_arch
68033965Sjdp		(enum bfd_architecture
68133965Sjdp		arch,
68233965Sjdp		unsigned long machine);
68333965Sjdp
68433965SjdpDESCRIPTION
68533965Sjdp	Look for the architecure info structure which matches the
68633965Sjdp	arguments @var{arch} and @var{machine}. A machine of 0 matches the
68733965Sjdp	machine/architecture structure which marks itself as the
68833965Sjdp	default.
68933965Sjdp*/
69033965Sjdp
69133965Sjdpconst bfd_arch_info_type *
69233965Sjdpbfd_lookup_arch (arch, machine)
69333965Sjdp     enum bfd_architecture arch;
69433965Sjdp     unsigned long machine;
69533965Sjdp{
69633965Sjdp  const bfd_arch_info_type * const *app, *ap;
69733965Sjdp
69833965Sjdp  for (app = bfd_archures_list; *app != NULL; app++)
69933965Sjdp    {
70033965Sjdp      for (ap = *app; ap != NULL; ap = ap->next)
70133965Sjdp	{
70233965Sjdp	  if (ap->arch == arch
70333965Sjdp	      && (ap->mach == machine
70433965Sjdp		  || (machine == 0 && ap->the_default)))
70533965Sjdp	    return ap;
70633965Sjdp	}
70733965Sjdp    }
70833965Sjdp
70933965Sjdp  return NULL;
71033965Sjdp}
71133965Sjdp
71233965Sjdp
71333965Sjdp/*
71433965SjdpFUNCTION
71533965Sjdp	bfd_printable_arch_mach
71633965Sjdp
71733965SjdpSYNOPSIS
71833965Sjdp	const char *bfd_printable_arch_mach
71933965Sjdp		(enum bfd_architecture arch, unsigned long machine);
72033965Sjdp
72133965SjdpDESCRIPTION
72233965Sjdp	Return a printable string representing the architecture and
72333965Sjdp	machine type.
72433965Sjdp
72533965Sjdp	This routine is depreciated.
72633965Sjdp*/
72733965Sjdp
72833965Sjdpconst char *
72933965Sjdpbfd_printable_arch_mach (arch, machine)
73033965Sjdp     enum bfd_architecture arch;
73133965Sjdp     unsigned long machine;
73233965Sjdp{
73333965Sjdp    const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
73433965Sjdp
73533965Sjdp    if (ap)
73633965Sjdp      return ap->printable_name;
73733965Sjdp    return "UNKNOWN!";
73833965Sjdp}
739