archures.c revision 38889
133965Sjdp/* BFD library support routines for architectures.
238889Sjdp   Copyright (C) 1990, 91-97, 1998 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 *}
7338889Sjdp.#define bfd_mach_m68000 1
7438889Sjdp.#define bfd_mach_m68008 2
7538889Sjdp.#define bfd_mach_m68010 3
7638889Sjdp.#define bfd_mach_m68020 4
7738889Sjdp.#define bfd_mach_m68030 5
7838889Sjdp.#define bfd_mach_m68040 6
7938889Sjdp.#define bfd_mach_m68060 7
8033965Sjdp.  bfd_arch_vax,       {* DEC Vax *}
8133965Sjdp.  bfd_arch_i960,      {* Intel 960 *}
8233965Sjdp.    {* The order of the following is important.
8333965Sjdp.       lower number indicates a machine type that
8433965Sjdp.       only accepts a subset of the instructions
8533965Sjdp.       available to machines with higher numbers.
8633965Sjdp.       The exception is the "ca", which is
8733965Sjdp.       incompatible with all other machines except
8833965Sjdp.       "core". *}
8933965Sjdp.
9033965Sjdp.#define bfd_mach_i960_core      1
9133965Sjdp.#define bfd_mach_i960_ka_sa     2
9233965Sjdp.#define bfd_mach_i960_kb_sb     3
9333965Sjdp.#define bfd_mach_i960_mc        4
9433965Sjdp.#define bfd_mach_i960_xa        5
9533965Sjdp.#define bfd_mach_i960_ca        6
9633965Sjdp.#define bfd_mach_i960_jx	 7
9733965Sjdp.#define bfd_mach_i960_hx        8
9833965Sjdp.
9933965Sjdp.  bfd_arch_a29k,      {* AMD 29000 *}
10033965Sjdp.  bfd_arch_sparc,     {* SPARC *}
10133965Sjdp.#define bfd_mach_sparc			1
10233965Sjdp.{* The difference between v8plus and v9 is that v9 is a true 64 bit env.  *}
10333965Sjdp.#define bfd_mach_sparc_sparclet	2
10433965Sjdp.#define bfd_mach_sparc_sparclite	3
10533965Sjdp.#define bfd_mach_sparc_v8plus		4
10633965Sjdp.#define bfd_mach_sparc_v8plusa		5 {* with ultrasparc add'ns *}
10733965Sjdp.#define bfd_mach_sparc_v9		6
10833965Sjdp.#define bfd_mach_sparc_v9a		7 {* with ultrasparc add'ns *}
10933965Sjdp.{* Nonzero if MACH has the v9 instruction set.  *}
11033965Sjdp.#define bfd_mach_sparc_v9_p(mach) \
11133965Sjdp.  ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a)
11233965Sjdp.  bfd_arch_mips,      {* MIPS Rxxxx *}
11338889Sjdp.#define bfd_mach_mips3000		3000
11438889Sjdp.#define bfd_mach_mips3900		3900
11538889Sjdp.#define bfd_mach_mips4000		4000
11638889Sjdp.#define bfd_mach_mips4010		4010
11738889Sjdp.#define bfd_mach_mips4100		4100
11838889Sjdp.#define bfd_mach_mips4300		4300
11938889Sjdp.#define bfd_mach_mips4400		4400
12038889Sjdp.#define bfd_mach_mips4600		4600
12138889Sjdp.#define bfd_mach_mips4650		4650
12238889Sjdp.#define bfd_mach_mips5000		5000
12338889Sjdp.#define bfd_mach_mips6000		6000
12438889Sjdp.#define bfd_mach_mips8000		8000
12538889Sjdp.#define bfd_mach_mips10000		10000
12638889Sjdp.#define bfd_mach_mips16		16
12733965Sjdp.  bfd_arch_i386,      {* Intel 386 *}
12833965Sjdp.#define bfd_mach_i386_i386 0
12933965Sjdp.#define bfd_mach_i386_i8086 1
13033965Sjdp.  bfd_arch_we32k,     {* AT&T WE32xxx *}
13133965Sjdp.  bfd_arch_tahoe,     {* CCI/Harris Tahoe *}
13233965Sjdp.  bfd_arch_i860,      {* Intel 860 *}
13333965Sjdp.  bfd_arch_romp,      {* IBM ROMP PC/RT *}
13433965Sjdp.  bfd_arch_alliant,   {* Alliant *}
13533965Sjdp.  bfd_arch_convex,    {* Convex *}
13633965Sjdp.  bfd_arch_m88k,      {* Motorola 88xxx *}
13733965Sjdp.  bfd_arch_pyramid,   {* Pyramid Technology *}
13833965Sjdp.  bfd_arch_h8300,     {* Hitachi H8/300 *}
13933965Sjdp.#define bfd_mach_h8300   1
14033965Sjdp.#define bfd_mach_h8300h  2
14133965Sjdp.#define bfd_mach_h8300s  3
14233965Sjdp.  bfd_arch_powerpc,   {* PowerPC *}
14333965Sjdp.  bfd_arch_rs6000,    {* IBM RS/6000 *}
14433965Sjdp.  bfd_arch_hppa,      {* HP PA RISC *}
14533965Sjdp.  bfd_arch_d10v,      {* Mitsubishi D10V *}
14633965Sjdp.  bfd_arch_z8k,       {* Zilog Z8000 *}
14733965Sjdp.#define bfd_mach_z8001		1
14833965Sjdp.#define bfd_mach_z8002		2
14933965Sjdp.  bfd_arch_h8500,     {* Hitachi H8/500 *}
15033965Sjdp.  bfd_arch_sh,        {* Hitachi SH *}
15138889Sjdp.#define bfd_mach_sh            0
15238889Sjdp.#define bfd_mach_sh3        0x30
15338889Sjdp.#define bfd_mach_sh3e       0x3e
15438889Sjdp.#define bfd_mach_sh4        0x40
15533965Sjdp.  bfd_arch_alpha,     {* Dec Alpha *}
15633965Sjdp.  bfd_arch_arm,       {* Advanced Risc Machines ARM *}
15738889Sjdp.#define bfd_mach_arm_2		1
15838889Sjdp.#define bfd_mach_arm_2a		2
15938889Sjdp.#define bfd_mach_arm_3		3
16038889Sjdp.#define bfd_mach_arm_3M 	4
16138889Sjdp.#define bfd_mach_arm_4 		5
16238889Sjdp.#define bfd_mach_arm_4T 	6
16333965Sjdp.  bfd_arch_ns32k,     {* National Semiconductors ns32000 *}
16433965Sjdp.  bfd_arch_w65,       {* WDC 65816 *}
16538889Sjdp.  bfd_arch_tic30,     {* Texas Instruments TMS320C30 *}
16638889Sjdp.  bfd_arch_v850,      {* NEC V850 *}
16738889Sjdp.#define bfd_mach_v850          0
16838889Sjdp.  bfd_arch_arc,       {* Argonaut RISC Core *}
16938889Sjdp.#define bfd_mach_arc_base 0
17033965Sjdp.  bfd_arch_m32r,      {* Mitsubishi M32R/D *}
17138889Sjdp.#define bfd_mach_m32r		0 {* backwards compatibility *}
17233965Sjdp.  bfd_arch_mn10200,   {* Matsushita MN10200 *}
17333965Sjdp.  bfd_arch_mn10300,   {* Matsushita MN10300 *}
17433965Sjdp.  bfd_arch_last
17533965Sjdp.  };
17633965Sjdp
17733965Sjdp
17833965Sjdp*/
17933965Sjdp
18033965Sjdp/*
18133965Sjdp
18233965SjdpSUBSECTION
18333965Sjdp	bfd_arch_info
18433965Sjdp
18533965SjdpDESCRIPTION
18633965Sjdp	This structure contains information on architectures for use
18733965Sjdp	within BFD.
18833965Sjdp
18933965Sjdp.
19033965Sjdp.typedef struct bfd_arch_info
19133965Sjdp.{
19233965Sjdp.  int bits_per_word;
19333965Sjdp.  int bits_per_address;
19433965Sjdp.  int bits_per_byte;
19533965Sjdp.  enum bfd_architecture arch;
19633965Sjdp.  unsigned long mach;
19733965Sjdp.  const char *arch_name;
19833965Sjdp.  const char *printable_name;
19933965Sjdp.  unsigned int section_align_power;
20033965Sjdp. {* true if this is the default machine for the architecture *}
20133965Sjdp.  boolean the_default;
20233965Sjdp.  const struct bfd_arch_info * (*compatible)
20333965Sjdp.	PARAMS ((const struct bfd_arch_info *a,
20433965Sjdp.	         const struct bfd_arch_info *b));
20533965Sjdp.
20633965Sjdp.  boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
20733965Sjdp.
20833965Sjdp.  const struct bfd_arch_info *next;
20933965Sjdp.} bfd_arch_info_type;
21033965Sjdp*/
21133965Sjdp
21233965Sjdpextern const bfd_arch_info_type bfd_a29k_arch;
21333965Sjdpextern const bfd_arch_info_type bfd_alpha_arch;
21438889Sjdpextern const bfd_arch_info_type bfd_arc_arch;
21533965Sjdpextern const bfd_arch_info_type bfd_arm_arch;
21633965Sjdpextern const bfd_arch_info_type bfd_d10v_arch;
21733965Sjdpextern const bfd_arch_info_type bfd_h8300_arch;
21833965Sjdpextern const bfd_arch_info_type bfd_h8500_arch;
21933965Sjdpextern const bfd_arch_info_type bfd_hppa_arch;
22033965Sjdpextern const bfd_arch_info_type bfd_i386_arch;
22133965Sjdpextern const bfd_arch_info_type bfd_i860_arch;
22233965Sjdpextern const bfd_arch_info_type bfd_i960_arch;
22333965Sjdpextern const bfd_arch_info_type bfd_m32r_arch;
22433965Sjdpextern const bfd_arch_info_type bfd_m68k_arch;
22533965Sjdpextern const bfd_arch_info_type bfd_m88k_arch;
22633965Sjdpextern const bfd_arch_info_type bfd_mips_arch;
22733965Sjdpextern const bfd_arch_info_type bfd_mn10200_arch;
22833965Sjdpextern const bfd_arch_info_type bfd_mn10300_arch;
22933965Sjdpextern const bfd_arch_info_type bfd_powerpc_arch;
23033965Sjdpextern const bfd_arch_info_type bfd_rs6000_arch;
23133965Sjdpextern const bfd_arch_info_type bfd_sh_arch;
23233965Sjdpextern const bfd_arch_info_type bfd_sparc_arch;
23338889Sjdpextern const bfd_arch_info_type bfd_tic30_arch;
23433965Sjdpextern const bfd_arch_info_type bfd_vax_arch;
23533965Sjdpextern const bfd_arch_info_type bfd_we32k_arch;
23633965Sjdpextern const bfd_arch_info_type bfd_z8k_arch;
23733965Sjdpextern const bfd_arch_info_type bfd_ns32k_arch;
23833965Sjdpextern const bfd_arch_info_type bfd_w65_arch;
23938889Sjdpextern const bfd_arch_info_type bfd_v850_arch;
24033965Sjdp
24133965Sjdpstatic const bfd_arch_info_type * const bfd_archures_list[] =
24233965Sjdp{
24333965Sjdp#ifdef SELECT_ARCHITECTURES
24433965Sjdp  SELECT_ARCHITECTURES,
24533965Sjdp#else
24633965Sjdp  &bfd_a29k_arch,
24733965Sjdp  &bfd_alpha_arch,
24838889Sjdp  &bfd_arc_arch,
24933965Sjdp  &bfd_arm_arch,
25033965Sjdp  &bfd_d10v_arch,
25133965Sjdp  &bfd_h8300_arch,
25233965Sjdp  &bfd_h8500_arch,
25333965Sjdp  &bfd_hppa_arch,
25433965Sjdp  &bfd_i386_arch,
25533965Sjdp  &bfd_i860_arch,
25633965Sjdp  &bfd_i960_arch,
25733965Sjdp  &bfd_m32r_arch,
25833965Sjdp  &bfd_m68k_arch,
25933965Sjdp  &bfd_m88k_arch,
26033965Sjdp  &bfd_mips_arch,
26133965Sjdp  &bfd_mn10200_arch,
26233965Sjdp  &bfd_mn10300_arch,
26333965Sjdp  &bfd_powerpc_arch,
26433965Sjdp  &bfd_rs6000_arch,
26533965Sjdp  &bfd_sh_arch,
26633965Sjdp  &bfd_sparc_arch,
26738889Sjdp  &bfd_tic30_arch,
26833965Sjdp  &bfd_vax_arch,
26933965Sjdp  &bfd_we32k_arch,
27033965Sjdp  &bfd_z8k_arch,
27133965Sjdp  &bfd_ns32k_arch,
27233965Sjdp  &bfd_w65_arch,
27338889Sjdp  &bfd_v850_arch,
27433965Sjdp#endif
27533965Sjdp  0
27633965Sjdp};
27733965Sjdp
27833965Sjdp/*
27933965SjdpFUNCTION
28033965Sjdp	bfd_printable_name
28133965Sjdp
28233965SjdpSYNOPSIS
28333965Sjdp	const char *bfd_printable_name(bfd *abfd);
28433965Sjdp
28533965SjdpDESCRIPTION
28633965Sjdp	Return a printable string representing the architecture and machine
28733965Sjdp	from the pointer to the architecture info structure.
28833965Sjdp
28933965Sjdp*/
29033965Sjdp
29133965Sjdpconst char *
29233965Sjdpbfd_printable_name (abfd)
29333965Sjdp     bfd *abfd;
29433965Sjdp{
29533965Sjdp  return abfd->arch_info->printable_name;
29633965Sjdp}
29733965Sjdp
29833965Sjdp
29933965Sjdp
30033965Sjdp/*
30133965SjdpFUNCTION
30233965Sjdp	bfd_scan_arch
30333965Sjdp
30433965SjdpSYNOPSIS
30533965Sjdp	const bfd_arch_info_type *bfd_scan_arch(const char *string);
30633965Sjdp
30733965SjdpDESCRIPTION
30833965Sjdp	Figure out if BFD supports any cpu which could be described with
30933965Sjdp	the name @var{string}.  Return a pointer to an <<arch_info>>
31033965Sjdp	structure if a machine is found, otherwise NULL.
31133965Sjdp
31233965Sjdp*/
31333965Sjdp
31433965Sjdpconst bfd_arch_info_type *
31533965Sjdpbfd_scan_arch (string)
31633965Sjdp     const char *string;
31733965Sjdp{
31833965Sjdp  const bfd_arch_info_type * const *app, *ap;
31933965Sjdp
32033965Sjdp  /* Look through all the installed architectures */
32133965Sjdp  for (app = bfd_archures_list; *app != NULL; app++)
32233965Sjdp    {
32333965Sjdp      for (ap = *app; ap != NULL; ap = ap->next)
32433965Sjdp	{
32533965Sjdp	  if (ap->scan (ap, string))
32633965Sjdp	    return ap;
32733965Sjdp	}
32833965Sjdp    }
32933965Sjdp
33033965Sjdp  return NULL;
33133965Sjdp}
33233965Sjdp
33333965Sjdp
33433965Sjdp
33533965Sjdp/*
33633965SjdpFUNCTION
33738889Sjdp	bfd_arch_list
33838889Sjdp
33938889SjdpSYNOPSIS
34038889Sjdp	const char **bfd_arch_list(void);
34138889Sjdp
34238889SjdpDESCRIPTION
34338889Sjdp	Return a freshly malloced NULL-terminated vector of the names
34438889Sjdp	of all the valid BFD architectures.  Do not modify the names.
34538889Sjdp
34638889Sjdp*/
34738889Sjdp
34838889Sjdpconst char **
34938889Sjdpbfd_arch_list ()
35038889Sjdp{
35138889Sjdp  int vec_length = 0;
35238889Sjdp  const char **name_ptr;
35338889Sjdp  const char **name_list;
35438889Sjdp  const bfd_arch_info_type * const *app;
35538889Sjdp
35638889Sjdp  /* Determine the number of architectures */
35738889Sjdp  vec_length = 0;
35838889Sjdp  for (app = bfd_archures_list; *app != NULL; app++)
35938889Sjdp    {
36038889Sjdp      const bfd_arch_info_type *ap;
36138889Sjdp      for (ap = *app; ap != NULL; ap = ap->next)
36238889Sjdp	{
36338889Sjdp	  vec_length++;
36438889Sjdp	}
36538889Sjdp    }
36638889Sjdp
36738889Sjdp  name_list = (CONST char **)
36838889Sjdp    bfd_malloc ((vec_length + 1) * sizeof (char **));
36938889Sjdp  if (name_list == NULL)
37038889Sjdp    return NULL;
37138889Sjdp
37238889Sjdp  /* Point the list at each of the names */
37338889Sjdp  name_ptr = name_list;
37438889Sjdp  for (app = bfd_archures_list; *app != NULL; app++)
37538889Sjdp    {
37638889Sjdp      const bfd_arch_info_type *ap;
37738889Sjdp      for (ap = *app; ap != NULL; ap = ap->next)
37838889Sjdp	{
37938889Sjdp	  *name_ptr = ap->printable_name;
38038889Sjdp	  name_ptr++;
38138889Sjdp	}
38238889Sjdp    }
38338889Sjdp  *name_ptr = NULL;
38438889Sjdp
38538889Sjdp  return name_list;
38638889Sjdp}
38738889Sjdp
38838889Sjdp
38938889Sjdp
39038889Sjdp/*
39138889SjdpFUNCTION
39233965Sjdp	bfd_arch_get_compatible
39333965Sjdp
39433965SjdpSYNOPSIS
39533965Sjdp	const bfd_arch_info_type *bfd_arch_get_compatible(
39633965Sjdp		const bfd *abfd,
39733965Sjdp	        const bfd *bbfd);
39833965Sjdp
39933965SjdpDESCRIPTION
40033965Sjdp	Determine whether two BFDs'
40133965Sjdp	architectures and machine types are compatible.  Calculates
40233965Sjdp	the lowest common denominator between the two architectures
40333965Sjdp	and machine types implied by the BFDs and returns a pointer to
40433965Sjdp	an <<arch_info>> structure describing the compatible machine.
40533965Sjdp*/
40633965Sjdp
40733965Sjdpconst bfd_arch_info_type *
40833965Sjdpbfd_arch_get_compatible (abfd, bbfd)
40933965Sjdp     const bfd *abfd;
41033965Sjdp     const bfd *bbfd;
41133965Sjdp{
41233965Sjdp  /* If either architecture is unknown, then all we can do is assume
41333965Sjdp     the user knows what he's doing.  */
41433965Sjdp  if (abfd->arch_info->arch == bfd_arch_unknown)
41533965Sjdp  	return bbfd->arch_info;
41633965Sjdp  if (bbfd->arch_info->arch == bfd_arch_unknown)
41733965Sjdp  	return abfd->arch_info;
41833965Sjdp
41933965Sjdp  /* Otherwise architecture-specific code has to decide.  */
42033965Sjdp  return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
42133965Sjdp}
42233965Sjdp
42333965Sjdp
42433965Sjdp/*
42533965SjdpINTERNAL_DEFINITION
42633965Sjdp	bfd_default_arch_struct
42733965Sjdp
42833965SjdpDESCRIPTION
42933965Sjdp	The <<bfd_default_arch_struct>> is an item of
43033965Sjdp	<<bfd_arch_info_type>> which has been initialized to a fairly
43133965Sjdp	generic state.  A BFD starts life by pointing to this
43233965Sjdp	structure, until the correct back end has determined the real
43333965Sjdp	architecture of the file.
43433965Sjdp
43533965Sjdp.extern const bfd_arch_info_type bfd_default_arch_struct;
43633965Sjdp
43733965Sjdp*/
43833965Sjdp
43933965Sjdpconst bfd_arch_info_type bfd_default_arch_struct =
44033965Sjdp{
44133965Sjdp    32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
44233965Sjdp    bfd_default_compatible,
44333965Sjdp    bfd_default_scan,
44433965Sjdp    0,
44533965Sjdp};
44633965Sjdp
44733965Sjdp/*
44833965SjdpFUNCTION
44933965Sjdp	bfd_set_arch_info
45033965Sjdp
45133965SjdpSYNOPSIS
45233965Sjdp	void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
45333965Sjdp
45433965SjdpDESCRIPTION
45533965Sjdp	Set the architecture info of @var{abfd} to @var{arg}.
45633965Sjdp*/
45733965Sjdp
45833965Sjdpvoid
45933965Sjdpbfd_set_arch_info (abfd, arg)
46033965Sjdp     bfd *abfd;
46133965Sjdp     const bfd_arch_info_type *arg;
46233965Sjdp{
46333965Sjdp  abfd->arch_info = arg;
46433965Sjdp}
46533965Sjdp
46633965Sjdp/*
46733965SjdpINTERNAL_FUNCTION
46833965Sjdp	bfd_default_set_arch_mach
46933965Sjdp
47033965SjdpSYNOPSIS
47133965Sjdp	boolean bfd_default_set_arch_mach(bfd *abfd,
47233965Sjdp		enum bfd_architecture arch,
47333965Sjdp		unsigned long mach);
47433965Sjdp
47533965SjdpDESCRIPTION
47633965Sjdp	Set the architecture and machine type in BFD @var{abfd}
47733965Sjdp	to @var{arch} and @var{mach}.  Find the correct
47833965Sjdp	pointer to a structure and insert it into the <<arch_info>>
47933965Sjdp	pointer.
48033965Sjdp*/
48133965Sjdp
48233965Sjdpboolean
48333965Sjdpbfd_default_set_arch_mach (abfd, arch, mach)
48433965Sjdp     bfd *abfd;
48533965Sjdp     enum bfd_architecture arch;
48633965Sjdp     unsigned long mach;
48733965Sjdp{
48833965Sjdp  const bfd_arch_info_type * const *app, *ap;
48933965Sjdp
49033965Sjdp  for (app = bfd_archures_list; *app != NULL; app++)
49133965Sjdp    {
49233965Sjdp      for (ap = *app; ap != NULL; ap = ap->next)
49333965Sjdp	{
49433965Sjdp	  if (ap->arch == arch
49533965Sjdp	      && (ap->mach == mach
49633965Sjdp		  || (mach == 0 && ap->the_default)))
49733965Sjdp	    {
49833965Sjdp	      abfd->arch_info = ap;
49933965Sjdp	      return true;
50033965Sjdp	    }
50133965Sjdp	}
50233965Sjdp    }
50333965Sjdp
50433965Sjdp  abfd->arch_info = &bfd_default_arch_struct;
50533965Sjdp  bfd_set_error (bfd_error_bad_value);
50633965Sjdp  return false;
50733965Sjdp}
50833965Sjdp
50933965Sjdp
51033965Sjdp/*
51133965SjdpFUNCTION
51233965Sjdp	bfd_get_arch
51333965Sjdp
51433965SjdpSYNOPSIS
51533965Sjdp	enum bfd_architecture bfd_get_arch(bfd *abfd);
51633965Sjdp
51733965SjdpDESCRIPTION
51833965Sjdp	Return the enumerated type which describes the BFD @var{abfd}'s
51933965Sjdp	architecture.
52033965Sjdp
52133965Sjdp*/
52233965Sjdp
52333965Sjdpenum bfd_architecture
52433965Sjdpbfd_get_arch (abfd)
52533965Sjdp     bfd *abfd;
52633965Sjdp{
52733965Sjdp    return abfd->arch_info->arch;
52833965Sjdp}
52933965Sjdp
53033965Sjdp/*
53133965SjdpFUNCTION
53233965Sjdp	bfd_get_mach
53333965Sjdp
53433965SjdpSYNOPSIS
53533965Sjdp	unsigned long bfd_get_mach(bfd *abfd);
53633965Sjdp
53733965SjdpDESCRIPTION
53833965Sjdp	Return the long type which describes the BFD @var{abfd}'s
53933965Sjdp	machine.
54033965Sjdp*/
54133965Sjdp
54233965Sjdpunsigned long
54333965Sjdpbfd_get_mach (abfd)
54433965Sjdp     bfd *abfd;
54533965Sjdp{
54633965Sjdp    return abfd->arch_info->mach;
54733965Sjdp}
54833965Sjdp
54933965Sjdp/*
55033965SjdpFUNCTION
55133965Sjdp	bfd_arch_bits_per_byte
55233965Sjdp
55333965SjdpSYNOPSIS
55433965Sjdp	unsigned int bfd_arch_bits_per_byte(bfd *abfd);
55533965Sjdp
55633965SjdpDESCRIPTION
55733965Sjdp	Return the number of bits in one of the BFD @var{abfd}'s
55833965Sjdp	architecture's bytes.
55933965Sjdp
56033965Sjdp*/
56133965Sjdp
56233965Sjdpunsigned int
56333965Sjdpbfd_arch_bits_per_byte (abfd)
56433965Sjdp     bfd *abfd;
56533965Sjdp{
56633965Sjdp  return abfd->arch_info->bits_per_byte;
56733965Sjdp}
56833965Sjdp
56933965Sjdp/*
57033965SjdpFUNCTION
57133965Sjdp	bfd_arch_bits_per_address
57233965Sjdp
57333965SjdpSYNOPSIS
57433965Sjdp	unsigned int bfd_arch_bits_per_address(bfd *abfd);
57533965Sjdp
57633965SjdpDESCRIPTION
57733965Sjdp	Return the number of bits in one of the BFD @var{abfd}'s
57833965Sjdp	architecture's addresses.
57933965Sjdp*/
58033965Sjdp
58133965Sjdpunsigned int
58233965Sjdpbfd_arch_bits_per_address (abfd)
58333965Sjdp     bfd *abfd;
58433965Sjdp{
58533965Sjdp  return abfd->arch_info->bits_per_address;
58633965Sjdp}
58733965Sjdp
58833965Sjdp
58933965Sjdp/*
59033965SjdpINTERNAL_FUNCTION
59133965Sjdp	bfd_default_compatible
59233965Sjdp
59333965SjdpSYNOPSIS
59433965Sjdp	const bfd_arch_info_type *bfd_default_compatible
59533965Sjdp	(const bfd_arch_info_type *a,
59633965Sjdp	const bfd_arch_info_type *b);
59733965Sjdp
59833965SjdpDESCRIPTION
59933965Sjdp	The default function for testing for compatibility.
60033965Sjdp*/
60133965Sjdp
60233965Sjdpconst bfd_arch_info_type *
60333965Sjdpbfd_default_compatible (a,b)
60433965Sjdp     const bfd_arch_info_type *a;
60533965Sjdp     const bfd_arch_info_type *b;
60633965Sjdp{
60733965Sjdp  if (a->arch != b->arch)
60833965Sjdp    return NULL;
60933965Sjdp
61033965Sjdp  if (a->mach > b->mach)
61133965Sjdp    return a;
61233965Sjdp
61333965Sjdp  if (b->mach > a->mach)
61433965Sjdp    return b;
61533965Sjdp
61633965Sjdp  return a;
61733965Sjdp}
61833965Sjdp
61933965Sjdp
62033965Sjdp/*
62133965SjdpINTERNAL_FUNCTION
62233965Sjdp	bfd_default_scan
62333965Sjdp
62433965SjdpSYNOPSIS
62533965Sjdp	boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
62633965Sjdp
62733965SjdpDESCRIPTION
62833965Sjdp	The default function for working out whether this is an
62933965Sjdp	architecture hit and a machine hit.
63033965Sjdp*/
63133965Sjdp
63233965Sjdpboolean
63333965Sjdpbfd_default_scan (info, string)
63433965Sjdp     const struct bfd_arch_info *info;
63533965Sjdp     const char *string;
63633965Sjdp{
63733965Sjdp  const char *ptr_src;
63833965Sjdp  const char *ptr_tst;
63933965Sjdp  unsigned long number;
64033965Sjdp  enum bfd_architecture arch;
64138889Sjdp  const char *printable_name_colon;
64233965Sjdp
64338889Sjdp  /* Exact match of the architecture name (ARCH_NAME) and also the
64438889Sjdp     default architecture? */
64538889Sjdp  if (strcasecmp (string, info->arch_name) == 0
64638889Sjdp      && info->the_default)
64733965Sjdp    return true;
64833965Sjdp
64938889Sjdp  /* Exact match of the machine name (PRINTABLE_NAME)? */
65038889Sjdp  if (strcasecmp (string, info->printable_name) == 0)
65138889Sjdp    return true;
65238889Sjdp
65338889Sjdp  /* Given that printable_name contains no colon, attempt to match:
65438889Sjdp     ARCH_NAME [ ":" ] PRINTABLE_NAME? */
65538889Sjdp  printable_name_colon = strchr (info->printable_name, ':');
65638889Sjdp  if (printable_name_colon == NULL)
65738889Sjdp    {
65838889Sjdp      int strlen_arch_name = strlen (info->arch_name);
65938889Sjdp      if (strncasecmp (string, info->arch_name, strlen_arch_name) == 0)
66038889Sjdp	{
66138889Sjdp	  if (string[strlen_arch_name] == ':')
66238889Sjdp	    {
66338889Sjdp	      if (strcasecmp (string + strlen_arch_name + 1,
66438889Sjdp			      info->printable_name) == 0)
66538889Sjdp		return true;
66638889Sjdp	    }
66738889Sjdp	  else
66838889Sjdp	    {
66938889Sjdp	      if (strcasecmp (string + strlen_arch_name,
67038889Sjdp			      info->printable_name) == 0)
67138889Sjdp		return true;
67238889Sjdp	    }
67338889Sjdp	}
67438889Sjdp    }
67538889Sjdp
67638889Sjdp  /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>;
67738889Sjdp     Attempt to match: <arch> <mach>? */
67838889Sjdp  if (printable_name_colon != NULL)
67938889Sjdp    {
68038889Sjdp      int colon_index = printable_name_colon - info->printable_name;
68138889Sjdp      if (strncasecmp (string, info->printable_name, colon_index) == 0
68238889Sjdp	  && strcasecmp (string + colon_index,
68338889Sjdp			 info->printable_name + colon_index + 1) == 0)
68438889Sjdp	return true;
68538889Sjdp    }
68638889Sjdp
68738889Sjdp  /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>; Do not
68838889Sjdp     attempt to match just <mach>, it could be ambigious.  This test
68938889Sjdp     is left until later. */
69038889Sjdp
69138889Sjdp  /* NOTE: The below is retained for compatibility only. Please do not
69238889Sjdp     add to this code */
69338889Sjdp
69433965Sjdp  /* See how much of the supplied string matches with the
69533965Sjdp     architecture, eg the string m68k:68020 would match the 68k entry
69633965Sjdp     up to the :, then we get left with the machine number */
69733965Sjdp
69833965Sjdp  for (ptr_src = string, ptr_tst = info->arch_name;
69933965Sjdp       *ptr_src && *ptr_tst;
70033965Sjdp       ptr_src++, ptr_tst++)
70133965Sjdp    {
70233965Sjdp      if (*ptr_src != *ptr_tst) break;
70333965Sjdp    }
70433965Sjdp
70533965Sjdp  /* Chewed up as much of the architecture as will match, skip any
70633965Sjdp     colons */
70733965Sjdp  if (*ptr_src == ':')
70833965Sjdp    ptr_src++;
70933965Sjdp
71033965Sjdp  if (*ptr_src == 0)
71133965Sjdp    {
71233965Sjdp      /* nothing more, then only keep this one if it is the default
71333965Sjdp	 machine for this architecture */
71433965Sjdp      return info->the_default;
71533965Sjdp    }
71633965Sjdp
71733965Sjdp  number = 0;
71838889Sjdp  while (isdigit ((unsigned char) *ptr_src))
71933965Sjdp    {
72033965Sjdp      number = number * 10 + *ptr_src  - '0';
72133965Sjdp      ptr_src++;
72233965Sjdp    }
72333965Sjdp
72438889Sjdp  /* NOTE: The below is retained for compatibility only.
72538889Sjdp     PLEASE DO NOT ADD TO THIS CODE. */
72638889Sjdp
72733965Sjdp  switch (number)
72833965Sjdp    {
72938889Sjdp      /* FIXME: These are needed to parse IEEE objects.  */
73038889Sjdp    case 68000:
73138889Sjdp      arch = bfd_arch_m68k;
73238889Sjdp      number = bfd_mach_m68000;
73333965Sjdp      break;
73438889Sjdp    case 68010:
73538889Sjdp      arch = bfd_arch_m68k;
73638889Sjdp      number = bfd_mach_m68010;
73733965Sjdp      break;
73838889Sjdp    case 68020:
73938889Sjdp      arch = bfd_arch_m68k;
74038889Sjdp      number = bfd_mach_m68020;
74133965Sjdp      break;
74233965Sjdp    case 68030:
74338889Sjdp      arch = bfd_arch_m68k;
74438889Sjdp      number = bfd_mach_m68030;
74538889Sjdp      break;
74633965Sjdp    case 68040:
74738889Sjdp      arch = bfd_arch_m68k;
74838889Sjdp      number = bfd_mach_m68040;
74938889Sjdp      break;
75033965Sjdp    case 68332:
75138889Sjdp      arch = bfd_arch_m68k;
75238889Sjdp      /* FIXME: This should be cpu32.  */
75338889Sjdp      number = bfd_mach_m68020;
75433965Sjdp      break;
75533965Sjdp
75633965Sjdp    case 32000:
75733965Sjdp      arch = bfd_arch_we32k;
75833965Sjdp      break;
75933965Sjdp
76038889Sjdp    case 3000:
76138889Sjdp      arch = bfd_arch_mips;
76238889Sjdp      number = bfd_mach_mips3000;
76333965Sjdp      break;
76433965Sjdp
76533965Sjdp    case 4000:
76633965Sjdp      arch = bfd_arch_mips;
76738889Sjdp      number = bfd_mach_mips4000;
76833965Sjdp      break;
76933965Sjdp
77033965Sjdp    case 6000:
77133965Sjdp      arch = bfd_arch_rs6000;
77233965Sjdp      break;
77333965Sjdp
77433965Sjdp    default:
77533965Sjdp      return false;
77633965Sjdp    }
77733965Sjdp
77833965Sjdp  if (arch != info->arch)
77933965Sjdp    return false;
78033965Sjdp
78133965Sjdp  if (number != info->mach)
78233965Sjdp    return false;
78333965Sjdp
78433965Sjdp  return true;
78533965Sjdp}
78633965Sjdp
78733965Sjdp
78833965Sjdp/*
78933965SjdpFUNCTION
79033965Sjdp	bfd_get_arch_info
79133965Sjdp
79233965SjdpSYNOPSIS
79333965Sjdp	const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
79433965Sjdp
79533965SjdpDESCRIPTION
79633965Sjdp	Return the architecture info struct in @var{abfd}.
79733965Sjdp*/
79833965Sjdp
79933965Sjdpconst bfd_arch_info_type *
80033965Sjdpbfd_get_arch_info (abfd)
80133965Sjdp     bfd *abfd;
80233965Sjdp{
80333965Sjdp  return abfd->arch_info;
80433965Sjdp}
80533965Sjdp
80633965Sjdp
80733965Sjdp/*
80833965SjdpFUNCTION
80933965Sjdp	bfd_lookup_arch
81033965Sjdp
81133965SjdpSYNOPSIS
81233965Sjdp	const bfd_arch_info_type *bfd_lookup_arch
81333965Sjdp		(enum bfd_architecture
81433965Sjdp		arch,
81533965Sjdp		unsigned long machine);
81633965Sjdp
81733965SjdpDESCRIPTION
81833965Sjdp	Look for the architecure info structure which matches the
81933965Sjdp	arguments @var{arch} and @var{machine}. A machine of 0 matches the
82033965Sjdp	machine/architecture structure which marks itself as the
82133965Sjdp	default.
82233965Sjdp*/
82333965Sjdp
82433965Sjdpconst bfd_arch_info_type *
82533965Sjdpbfd_lookup_arch (arch, machine)
82633965Sjdp     enum bfd_architecture arch;
82733965Sjdp     unsigned long machine;
82833965Sjdp{
82933965Sjdp  const bfd_arch_info_type * const *app, *ap;
83033965Sjdp
83133965Sjdp  for (app = bfd_archures_list; *app != NULL; app++)
83233965Sjdp    {
83333965Sjdp      for (ap = *app; ap != NULL; ap = ap->next)
83433965Sjdp	{
83533965Sjdp	  if (ap->arch == arch
83633965Sjdp	      && (ap->mach == machine
83733965Sjdp		  || (machine == 0 && ap->the_default)))
83833965Sjdp	    return ap;
83933965Sjdp	}
84033965Sjdp    }
84133965Sjdp
84233965Sjdp  return NULL;
84333965Sjdp}
84433965Sjdp
84533965Sjdp
84633965Sjdp/*
84733965SjdpFUNCTION
84833965Sjdp	bfd_printable_arch_mach
84933965Sjdp
85033965SjdpSYNOPSIS
85133965Sjdp	const char *bfd_printable_arch_mach
85233965Sjdp		(enum bfd_architecture arch, unsigned long machine);
85333965Sjdp
85433965SjdpDESCRIPTION
85533965Sjdp	Return a printable string representing the architecture and
85633965Sjdp	machine type.
85733965Sjdp
85833965Sjdp	This routine is depreciated.
85933965Sjdp*/
86033965Sjdp
86133965Sjdpconst char *
86233965Sjdpbfd_printable_arch_mach (arch, machine)
86333965Sjdp     enum bfd_architecture arch;
86433965Sjdp     unsigned long machine;
86533965Sjdp{
86633965Sjdp    const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
86733965Sjdp
86833965Sjdp    if (ap)
86933965Sjdp      return ap->printable_name;
87033965Sjdp    return "UNKNOWN!";
87133965Sjdp}
872