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