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