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