2000-02-29 H.J. Lu <hjl@gnu.org>
[binutils.git] / bfd / cpu-arm.c
blobbda9c4489a665f4b960602f1660be703f63b856b
1 /* BFD support for the ARM processor
2 Copyright 1994, 95, 97, 1999 Free Software Foundation, Inc.
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
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. */
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
25 static const bfd_arch_info_type *compatible
26 PARAMS ((const bfd_arch_info_type *, const bfd_arch_info_type *));
27 static boolean scan PARAMS ((const struct bfd_arch_info *, const char *));
29 /* This routine is provided two arch_infos and works out which ARM
30 machine which would be compatible with both and returns a pointer
31 to its info structure */
33 static const bfd_arch_info_type *
34 compatible (a,b)
35 const bfd_arch_info_type * a;
36 const bfd_arch_info_type * b;
38 /* If a & b are for different architecture we can do nothing */
39 if (a->arch != b->arch)
40 return NULL;
42 /* If a & b are for the same machine then all is well */
43 if (a->mach == b->mach)
44 return a;
46 /* Otherwise if either a or b is the 'default' machine then
47 it can be polymorphed into the other */
48 if (a->the_default)
49 return b;
51 if (b->the_default)
52 return a;
54 /* So far all newer ARM architecture cores are supersets of previous cores */
55 if (a->mach < b->mach)
56 return b;
57 else if (a->mach > b->mach)
58 return a;
60 /* Never reached! */
61 return NULL;
64 static struct
66 enum bfd_architecture arch;
67 char * name;
69 processors[] =
71 { bfd_mach_arm_2, "arm2" },
72 { bfd_mach_arm_2a, "arm250" },
73 { bfd_mach_arm_2a, "arm3" },
74 { bfd_mach_arm_3, "arm6" },
75 { bfd_mach_arm_3, "arm60" },
76 { bfd_mach_arm_3, "arm600" },
77 { bfd_mach_arm_3, "arm610" },
78 { bfd_mach_arm_3, "arm7" },
79 { bfd_mach_arm_3, "arm710" },
80 { bfd_mach_arm_3, "arm7500" },
81 { bfd_mach_arm_3, "arm7d" },
82 { bfd_mach_arm_3, "arm7di" },
83 { bfd_mach_arm_3M, "arm7dm" },
84 { bfd_mach_arm_3M, "arm7dmi" },
85 { bfd_mach_arm_4T, "arm7tdmi" },
86 { bfd_mach_arm_4, "arm8" },
87 { bfd_mach_arm_4, "arm810" },
88 { bfd_mach_arm_4, "arm9" },
89 { bfd_mach_arm_4, "arm920" },
90 { bfd_mach_arm_4T, "arm920t" },
91 { bfd_mach_arm_4T, "arm9tdmi" },
92 { bfd_mach_arm_4, "sa1" },
93 { bfd_mach_arm_4, "strongarm"},
94 { bfd_mach_arm_4, "strongarm110" },
95 { bfd_mach_arm_4, "strongarm1100" },
98 static boolean
99 scan (info, string)
100 const struct bfd_arch_info * info;
101 const char * string;
103 int i;
105 /* First test for an exact match */
106 if (strcasecmp (string, info->printable_name) == 0)
107 return true;
109 /* Next check for a processor name instead of an Architecture name */
110 for (i = sizeof (processors) / sizeof (processors[0]); i--;)
112 if (strcasecmp (string, processors[ i ].name) == 0)
113 break;
116 if (i != -1 && info->arch == processors[ i ].arch)
117 return true;
119 /* Finally check for the default architecture */
120 if (strcasecmp (string, "arm") == 0)
121 return info->the_default;
123 return false;
127 #define N(number, print, default, next) \
128 { 32, 32, 8, bfd_arch_arm, number, "arm", print, 4, default, compatible, scan, next }
130 static const bfd_arch_info_type arch_info_struct[] =
132 N( bfd_mach_arm_2, "armv2", false, & arch_info_struct[1] ),
133 N( bfd_mach_arm_2a, "armv2a", false, & arch_info_struct[2] ),
134 N( bfd_mach_arm_3, "armv3", false, & arch_info_struct[3] ),
135 N( bfd_mach_arm_3M, "armv3m", false, & arch_info_struct[4] ),
136 N( bfd_mach_arm_4, "armv4", false, & arch_info_struct[5] ),
137 N( bfd_mach_arm_4T, "armv4t", false, & arch_info_struct[6] ),
138 N( bfd_mach_arm_5, "armv5", false, & arch_info_struct[7] ),
139 N( bfd_mach_arm_5T, "armv5t", false, NULL )
142 const bfd_arch_info_type bfd_arm_arch =
143 N( 0, "arm", true, & arch_info_struct[0] );