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