daily update
[binutils.git] / bfd / cpu-i960.c
blobc7d9231b674dabf278447bdf861c5f98a3aefe2d
1 /* BFD library support routines for the i960 architecture.
2 Copyright 1990, 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2005, 2006,
3 2007 Free Software Foundation, Inc.
4 Hacked by Steve Chamberlain of Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 #include "sysdep.h"
24 #include "bfd.h"
25 #include "libbfd.h"
27 static bfd_boolean scan_960_mach
28 PARAMS ((const bfd_arch_info_type *, const char *));
29 static const bfd_arch_info_type *compatible
30 PARAMS ((const bfd_arch_info_type *, const bfd_arch_info_type *));
32 /* This routine is provided a string, and tries to work out if it
33 could possibly refer to the i960 machine pointed at in the
34 info_struct pointer */
36 static bfd_boolean
37 scan_960_mach (ap, string)
38 const bfd_arch_info_type *ap;
39 const char *string;
41 unsigned long machine;
42 int fail_because_not_80960 = FALSE;
44 /* Look for the string i960 at the front of the string. */
45 if (strncasecmp ("i960", string, 4) == 0)
47 string += 4;
49 /* i960 on it's own means core to us. */
50 if (* string == 0)
51 return ap->mach == bfd_mach_i960_core;
53 /* "i960:*" is valid, anything else is not. */
54 if (* string != ':')
55 return FALSE;
57 string ++;
59 /* In some bfds the cpu-id is written as "80960KA", "80960KB",
60 "80960CA" or "80960MC". */
61 else if (CONST_STRNEQ (string, "80960"))
63 string += 5;
65 /* Set this to TRUE here. If a correct matching postfix
66 is detected below it will be reset to FALSE. */
67 fail_because_not_80960 = TRUE;
69 /* No match, can't be us. */
70 else
71 return FALSE;
73 if (* string == '\0')
74 return FALSE;
76 if (string[0] == 'c' && string[1] == 'o' && string[2] == 'r' &&
77 string[3] == 'e' && string[4] == '\0')
78 machine = bfd_mach_i960_core;
79 else if (strcasecmp (string, "ka_sa") == 0)
80 machine = bfd_mach_i960_ka_sa;
81 else if (strcasecmp (string, "kb_sb") == 0)
82 machine = bfd_mach_i960_kb_sb;
83 else if (string[1] == '\0' || string[2] != '\0') /* rest are 2-char. */
84 return FALSE;
85 else if (string[0] == 'k' && string[1] == 'b')
86 { machine = bfd_mach_i960_kb_sb; fail_because_not_80960 = FALSE; }
87 else if (string[0] == 's' && string[1] == 'b')
88 machine = bfd_mach_i960_kb_sb;
89 else if (string[0] == 'm' && string[1] == 'c')
90 { machine = bfd_mach_i960_mc; fail_because_not_80960 = FALSE; }
91 else if (string[0] == 'x' && string[1] == 'a')
92 machine = bfd_mach_i960_xa;
93 else if (string[0] == 'c' && string[1] == 'a')
94 { machine = bfd_mach_i960_ca; fail_because_not_80960 = FALSE; }
95 else if (string[0] == 'k' && string[1] == 'a')
96 { machine = bfd_mach_i960_ka_sa; fail_because_not_80960 = FALSE; }
97 else if (string[0] == 's' && string[1] == 'a')
98 machine = bfd_mach_i960_ka_sa;
99 else if (string[0] == 'j' && string[1] == 'x')
100 machine = bfd_mach_i960_jx;
101 else if (string[0] == 'h' && string[1] == 'x')
102 machine = bfd_mach_i960_hx;
103 else
104 return FALSE;
106 if (fail_because_not_80960)
107 return FALSE;
109 if (machine == ap->mach)
110 return TRUE;
112 return FALSE;
115 /* This routine is provided two arch_infos and works out the i960
116 machine which would be compatible with both and returns a pointer
117 to its info structure */
119 static const bfd_arch_info_type *
120 compatible (a,b)
121 const bfd_arch_info_type *a;
122 const bfd_arch_info_type *b;
125 /* The i960 has distinct subspecies which may not interbreed:
126 CORE CA
127 CORE KA KB MC XA
128 CORE HX JX
129 Any architecture on the same line is compatible, the one on
130 the right is the least restrictive.
132 We represent this information in an array, each machine to a side */
134 #define ERROR 0
135 #define CORE bfd_mach_i960_core /*1*/
136 #define KA bfd_mach_i960_ka_sa /*2*/
137 #define KB bfd_mach_i960_kb_sb /*3*/
138 #define MC bfd_mach_i960_mc /*4*/
139 #define XA bfd_mach_i960_xa /*5*/
140 #define CA bfd_mach_i960_ca /*6*/
141 #define JX bfd_mach_i960_jx /*7*/
142 #define HX bfd_mach_i960_hx /*8*/
143 #define MAX_ARCH ((int)HX)
145 static const unsigned long matrix[MAX_ARCH+1][MAX_ARCH+1] =
147 { ERROR, CORE, KA, KB, MC, XA, CA, JX, HX },
148 { CORE, CORE, KA, KB, MC, XA, CA, JX, HX },
149 { KA, KA, KA, KB, MC, XA, ERROR, ERROR, ERROR},
150 { KB, KB, KB, KB, MC, XA, ERROR, ERROR, ERROR},
151 { MC, MC, MC, MC, MC, XA, ERROR, ERROR, ERROR},
152 { XA, XA, XA, XA, XA, XA, ERROR, ERROR, ERROR},
153 { CA, CA, ERROR, ERROR, ERROR, ERROR, CA, ERROR, ERROR},
154 { JX, JX, ERROR, ERROR, ERROR, ERROR, ERROR, JX, HX },
155 { HX, HX, ERROR, ERROR, ERROR, ERROR, ERROR, HX, HX },
158 if (a->arch != b->arch || matrix[a->mach][b->mach] == ERROR)
160 return NULL;
162 else
164 return (a->mach == matrix[a->mach][b->mach]) ? a : b;
168 #define N(a,b,d,n) \
169 { 32, 32, 8,bfd_arch_i960,a,"i960",b,3,d,compatible,scan_960_mach,n,}
171 static const bfd_arch_info_type arch_info_struct[] =
173 N(bfd_mach_i960_ka_sa,"i960:ka_sa",FALSE, &arch_info_struct[1]),
174 N(bfd_mach_i960_kb_sb,"i960:kb_sb",FALSE, &arch_info_struct[2]),
175 N(bfd_mach_i960_mc, "i960:mc", FALSE, &arch_info_struct[3]),
176 N(bfd_mach_i960_xa, "i960:xa", FALSE, &arch_info_struct[4]),
177 N(bfd_mach_i960_ca, "i960:ca", FALSE, &arch_info_struct[5]),
178 N(bfd_mach_i960_jx, "i960:jx", FALSE, &arch_info_struct[6]),
179 N(bfd_mach_i960_hx, "i960:hx", FALSE, 0),
182 const bfd_arch_info_type bfd_i960_arch =
183 N(bfd_mach_i960_core, "i960:core", TRUE, &arch_info_struct[0]);