cpu-i960.c revision 1.2
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
21
22#include "bfd.h"
23#include "sysdep.h"
24#include "libbfd.h"
25
26
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
31static boolean
32scan_960_mach (ap, string)
33     const bfd_arch_info_type *ap;
34     const char *string;
35{
36  unsigned long machine;
37
38  /* Look for the string i960, or somesuch at the front of the string  */
39
40  if (strncmp("i960",string,4) == 0) {
41    string+=4;
42  }
43  else {
44    /* no match, can be us */
45    return false;
46  }
47  if (string[0] == 0) {
48    /* i960 on it's own means core to us*/
49    if (ap->mach == bfd_mach_i960_core) return true;
50    return false;
51  }
52
53  if (string[0] != ':') {
54    return false;
55  }
56  string++;
57  if (string[0] == '\0')
58    return false;
59  if (string[0] == 'c' && string[1] == 'o' && string[2] == 'r' &&
60      string[3] == 'e' && string[4] == '\0')
61    machine = bfd_mach_i960_core;
62  else if (string[1] == '\0' || string[2] != '\0') /* rest are 2-char */
63    return false;
64  else if (string[0] == 'k' && string[1] == 'b')
65    machine = bfd_mach_i960_kb_sb;
66  else if (string[0] == 's' && string[1] == 'b')
67    machine = bfd_mach_i960_kb_sb;
68  else if (string[0] == 'm' && string[1] == 'c')
69    machine = bfd_mach_i960_mc;
70  else if (string[0] == 'x' && string[1] == 'a')
71    machine = bfd_mach_i960_xa;
72  else if (string[0] == 'c' && string[1] == 'a')
73    machine = bfd_mach_i960_ca;
74  else if (string[0] == 'k' && string[1] == 'a')
75    machine = bfd_mach_i960_ka_sa;
76  else if (string[0] == 's' && string[1] == 'a')
77    machine = bfd_mach_i960_ka_sa;
78  else if (string[0] == 'j' && string[1] == 'x')
79    machine = bfd_mach_i960_jx;
80  else if (string[0] == 'h' && string[1] == 'x')
81    machine = bfd_mach_i960_hx;
82  else
83    return false;
84  if (machine == ap->mach)   return true;
85  return false;
86}
87
88
89
90/* This routine is provided two arch_infos and works out the i960
91   machine which would be compatible with both and returns a pointer
92   to its info structure */
93
94static const bfd_arch_info_type *
95compatible (a,b)
96     const bfd_arch_info_type *a;
97     const bfd_arch_info_type *b;
98{
99
100  /* The i960 has distinct subspecies which may not interbreed:
101	CORE CA
102	CORE KA KB MC XA
103	CORE HX JX
104     Any architecture on the same line is compatible, the one on
105     the right is the least restrictive.
106
107     We represent this information in an array, each machine to a side */
108
109#define ERROR	0
110#define CORE	bfd_mach_i960_core  /*1*/
111#define KA 	bfd_mach_i960_ka_sa /*2*/
112#define KB 	bfd_mach_i960_kb_sb /*3*/
113#define MC 	bfd_mach_i960_mc    /*4*/
114#define XA 	bfd_mach_i960_xa    /*5*/
115#define CA 	bfd_mach_i960_ca    /*6*/
116#define JX	bfd_mach_i960_jx    /*7*/
117#define HX	bfd_mach_i960_hx    /*8*/
118#define MAX_ARCH ((int)HX)
119
120  static CONST unsigned long matrix[MAX_ARCH+1][MAX_ARCH+1] =
121    {
122      { ERROR,	CORE,	KA,	KB,	MC,	XA,	CA,	JX,	HX },
123      { CORE,	CORE,	KA,	KB,	MC,	XA,	CA,	JX,	HX },
124      { KA,	KA,	KA,	KB,	MC,	XA,	ERROR,	ERROR,	ERROR},
125      { KB,	KB,	KB,	KB,	MC,	XA,	ERROR, 	ERROR,	ERROR},
126      { MC,	MC,	MC,	MC,	MC,	XA,	ERROR,	ERROR,	ERROR},
127      { XA,	XA,	XA,	XA,	XA,	XA,	ERROR,	ERROR,	ERROR},
128      { CA,	CA,	ERROR,	ERROR,	ERROR,	ERROR,	CA,	ERROR,	ERROR},
129      { JX,	JX,	ERROR,	ERROR,	ERROR,	ERROR,	ERROR,  JX,	HX },
130      { HX,	HX,	ERROR,	ERROR,	ERROR,	ERROR,	ERROR,	HX,	HX },
131    };
132
133
134  if (a->arch != b->arch || matrix[a->mach][b->mach] == ERROR)
135    {
136    return NULL;
137    }
138  else
139    {
140    return (a->mach  ==  matrix[a->mach][b->mach]) ?  a : b;
141    }
142}
143
144
145
146int bfd_default_scan_num_mach();
147#define N(a,b,d,n) \
148{ 32, 32, 8,bfd_arch_i960,a,"i960",b,3,d,compatible,scan_960_mach,n,}
149
150static const bfd_arch_info_type arch_info_struct[] =
151{
152  N(bfd_mach_i960_ka_sa,"i960:ka_sa",false, &arch_info_struct[1]),
153  N(bfd_mach_i960_kb_sb,"i960:kb_sb",false, &arch_info_struct[2]),
154  N(bfd_mach_i960_mc,   "i960:mc",   false, &arch_info_struct[3]),
155  N(bfd_mach_i960_xa,   "i960:xa",   false, &arch_info_struct[4]),
156  N(bfd_mach_i960_ca,   "i960:ca",   false, &arch_info_struct[5]),
157  N(bfd_mach_i960_jx,   "i960:jx",   false, &arch_info_struct[6]),
158  N(bfd_mach_i960_hx,	"i960:hx",   false, 0),
159};
160
161const bfd_arch_info_type bfd_i960_arch =
162  N(bfd_mach_i960_core, "i960:core", true, &arch_info_struct[0]);
163