db8282e31fbf2ff3c6c38632b882369ca1fbf925
[platform/upstream/binutils.git] / bfd / cpu-arm.c
1 /* BFD support for the ARM processor
2    Copyright 1994 Free Software Foundation, Inc.
3    Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4
5 This file is part of BFD, the Binary File Descriptor library.
6
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.
11
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.
16
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.  */
20
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24
25 /* This routine is provided two arch_infos and works out which ARM
26    machine which would be compatible with both and returns a pointer
27    to its info structure */
28
29 static const bfd_arch_info_type *
30 compatible (a,b)
31      const bfd_arch_info_type * a;
32      const bfd_arch_info_type * b;
33 {
34   /* For now keep things real simple - insist on matching architecture types */
35   
36   return (a->arch != b->arch || a->mach != b->mach ) ? NULL : a ;
37 }
38
39 static struct
40 {
41   enum bfd_architecture arch;
42   char *                name;
43 }
44 processors[] =
45 {
46   { bfd_mach_arm_2,  "arm2"     },
47   { bfd_mach_arm_2a, "arm250"   },
48   { bfd_mach_arm_2a, "arm3"     },
49   { bfd_mach_arm_3,  "arm6"     },
50   { bfd_mach_arm_3,  "arm60"    },
51   { bfd_mach_arm_3,  "arm600"   },
52   { bfd_mach_arm_3,  "arm610"   },
53   { bfd_mach_arm_3,  "arm7"     },
54   { bfd_mach_arm_3,  "arm710"   },
55   { bfd_mach_arm_3,  "arm7500"  },
56   { bfd_mach_arm_3,  "arm7d"    },
57   { bfd_mach_arm_3,  "arm7di"   },
58   { bfd_mach_arm_3M, "arm7dm"   },
59   { bfd_mach_arm_3M, "arm7dmi"  },
60   { bfd_mach_arm_4,  "arm8"     },
61   { bfd_mach_arm_4,  "arm810"   },
62   { bfd_mach_arm_4,  "sa1"      },
63   { bfd_mach_arm_4T, "arm7tdmi" }
64 };
65
66 static boolean 
67 scan (info, string)
68      const struct bfd_arch_info * info;
69      const char * string;
70 {
71   int  i;
72
73   /* First test for an exact match */
74   if (strcasecmp (string, info->printable_name) == 0)
75     return true;
76
77   /* Next check for a processor name instead of an Architecture name */
78   for (i = sizeof (processors) / sizeof (processors[0]); i--;)
79     {
80       if (strcasecmp (string, processors[ i ].name) == 0)
81         break;
82     }
83
84   if (i != -1 && info->arch == processors[ i ].arch)
85     return true;
86
87   /* Finally check for the default architecture */
88   if (strcasecmp (string, "arm") == 0)
89     return info->the_default;
90   
91   return false;
92 }
93
94
95 #define N(number, print, default, next)  \
96 {  32, 32, 8, bfd_arch_arm, number, "arm", print, 4, default, compatible, scan, next }
97
98 static const bfd_arch_info_type arch_info_struct[] =
99
100   N( bfd_mach_arm_2,  "ARMv2",  false, & arch_info_struct[1] ),
101   N( bfd_mach_arm_2a, "ARMv2a", false, & arch_info_struct[2] ),
102   N( bfd_mach_arm_3,  "ARMv3",  false, & arch_info_struct[3] ),
103   N( bfd_mach_arm_4,  "ARMv4",  false, & arch_info_struct[4] ),
104   N( bfd_mach_arm_4T, "ARMv4T", false, NULL )
105 };
106
107 const bfd_arch_info_type bfd_arm_arch =
108   N( bfd_mach_arm_3M, "ARMv3M", true, & arch_info_struct[0] );