1 /* BFD library support routines for architectures. */
3 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Diddler.
7 BFD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
12 BFD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with BFD; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 static char *prt_num_mach ();
28 static boolean scan_num_mach ();
29 static char *prt_960_mach ();
30 static boolean scan_960_mach ();
33 enum bfd_architecture arch;
35 char *(*mach_print)();
36 boolean (*mach_scan)();
39 {bfd_arch_unknown, "unknown", prt_num_mach, scan_num_mach},
40 {bfd_arch_obscure, "obscure", prt_num_mach, scan_num_mach},
41 {bfd_arch_m68k, "m68k", prt_num_mach, scan_num_mach},
42 {bfd_arch_vax, "vax", prt_num_mach, scan_num_mach},
43 {bfd_arch_i960, "i960", prt_960_mach, scan_960_mach},
44 {bfd_arch_a29k, "a29k", prt_num_mach, scan_num_mach},
45 {bfd_arch_sparc, "sparc", prt_num_mach, scan_num_mach},
46 {bfd_arch_mips, "mips", prt_num_mach, scan_num_mach},
47 {bfd_arch_i386, "i386", prt_num_mach, scan_num_mach},
48 {bfd_arch_ns32k, "ns32k", prt_num_mach, scan_num_mach},
49 {bfd_arch_tahoe, "tahoe", prt_num_mach, scan_num_mach},
50 {bfd_arch_i860, "i860", prt_num_mach, scan_num_mach},
51 {bfd_arch_romp, "romp", prt_num_mach, scan_num_mach},
52 {bfd_arch_alliant, "alliant", prt_num_mach, scan_num_mach},
53 {bfd_arch_convex, "convex", prt_num_mach, scan_num_mach},
54 {bfd_arch_m88k, "m88k", prt_num_mach, scan_num_mach},
55 {bfd_arch_pyramid, "pyramid", prt_num_mach, scan_num_mach},
56 {bfd_arch_unknown, (char *)0, prt_num_mach, scan_num_mach},
59 /* Return a printable string representing the architecture and machine
60 type. The result is only good until the next call to
61 bfd_printable_arch_mach. */
64 bfd_printable_arch_mach (arch, machine)
65 enum bfd_architecture arch;
66 unsigned long machine;
68 struct arch_print *ap;
70 for (ap = arch_print; ap->astr; ap++) {
71 if (ap->arch == arch) {
74 return (*ap->mach_print)(ap, machine);
81 prt_num_mach (ap, machine)
82 struct arch_print *ap;
83 unsigned long machine;
85 static char result[20];
87 sprintf(result, "%s:%ld", ap->astr, (long) machine);
91 /* Scan a string and attempt to turn it into an archive and machine type
95 bfd_scan_arch_mach (string, archp, machinep)
97 enum bfd_architecture *archp;
98 unsigned long *machinep;
100 struct arch_print *ap;
103 /* First look for an architecture, possibly followed by machtype. */
104 for (ap = arch_print; ap->astr; ap++) {
105 if (ap->astr[0] != string[0])
107 len = strlen (ap->astr);
108 if (!strncmp (ap->astr, string, len)) {
109 /* We found the architecture, now see about the machine type */
112 if (string[len] != '\0') {
113 if (ap->mach_scan (string+len, ap, archp, machinep, 1))
122 /* Couldn't find an architecture -- try for just a machine type */
123 for (ap = arch_print; ap->astr; ap++) {
124 if (ap->mach_scan (string, ap, archp, machinep, 0))
132 scan_num_mach (string, ap, archp, machinep, archspec)
134 struct arch_print *ap;
135 enum bfd_architecture *archp;
136 unsigned long *machinep;
139 enum bfd_architecture arch;
140 unsigned long machine;
145 /* Architecture already specified, now go for machine type. */
146 if (string[0] != ':')
148 /* We'll take any valid number that occupies the entire string */
149 if (1 != sscanf (string+1, "%lu%c", &machine, &achar))
155 /* We couldn't identify an architecture prefix. Perhaps the entire
156 thing is a machine type. Be a lot picker. */
157 if (1 != sscanf (string, "%lu%c", &machine, &achar))
165 case 68050: arch = bfd_arch_m68k; break;
166 case 68000: arch = bfd_arch_m68k; machine = 0; break;
169 case 960: arch = bfd_arch_i960; machine = 0; break;
172 case 80386: arch = bfd_arch_i386; machine = 0; break;
173 case 486: arch = bfd_arch_i386; break;
175 case 29000: arch = bfd_arch_a29k; machine = 0; break;
183 case 32532: arch = bfd_arch_ns32k; break;
184 case 32000: arch = bfd_arch_ns32k; machine = 0; break;
187 case 80860: arch = bfd_arch_i860; machine = 0; break;
189 default: return false;
200 /* Intel 960 machine variants. */
203 prt_960_mach (ap, machine)
204 struct arch_print *ap;
205 unsigned long machine;
207 static char result[20];
211 case bfd_mach_i960_core: str = "core"; break;
212 case bfd_mach_i960_kb_sb: str = "kb"; break;
213 case bfd_mach_i960_mc: str = "mc"; break;
214 case bfd_mach_i960_xa: str = "xa"; break;
215 case bfd_mach_i960_ca: str = "ca"; break;
216 case bfd_mach_i960_ka_sa: str = "ka"; break;
218 return prt_num_mach (ap, machine);
220 sprintf (result, "%s:%s", ap->astr, str);
225 scan_960_mach (string, ap, archp, machinep, archspec)
227 struct arch_print *ap;
228 enum bfd_architecture *archp;
229 unsigned long *machinep;
232 unsigned long machine;
236 if (string[0] != ':')
239 if (string[0] == '\0')
241 if (string[0] == 'c' && string[1] == 'o' && string[2] == 'r' &&
242 string[3] == 'e' && string[4] == '\0')
243 machine = bfd_mach_i960_core;
244 else if (string[1] == '\0' || string[2] != '\0') /* rest are 2-char */
246 else if (string[0] == 'k' && string[1] == 'b')
247 machine = bfd_mach_i960_kb_sb;
248 else if (string[0] == 's' && string[1] == 'b')
249 machine = bfd_mach_i960_kb_sb;
250 else if (string[0] == 'm' && string[1] == 'c')
251 machine = bfd_mach_i960_mc;
252 else if (string[0] == 'x' && string[1] == 'a')
253 machine = bfd_mach_i960_xa;
254 else if (string[0] == 'c' && string[1] == 'a')
255 machine = bfd_mach_i960_ca;
256 else if (string[0] == 'k' && string[1] == 'a')
257 machine = bfd_mach_i960_ka_sa;
258 else if (string[0] == 's' && string[1] == 'a')
259 machine = bfd_mach_i960_ka_sa;
272 /* Determine whether two BFDs' architectures and machine types are
273 compatible. Return merged architecture and machine type if nonnull
277 bfd_arch_compatible (abfd, bbfd, archp, machinep)
280 enum bfd_architecture *archp;
281 unsigned long *machinep;
283 enum bfd_architecture archa, archb;
284 unsigned long macha, machb;
287 archa = bfd_get_architecture (abfd);
288 archb = bfd_get_architecture (bbfd);
289 macha = bfd_get_machine (abfd);
290 machb = bfd_get_machine (bbfd);
292 if (archb == bfd_arch_unknown)
294 else if (archa == bfd_arch_unknown)
296 else if (archa != archb)
297 return false; /* Not compatible */
299 /* Architectures are the same. Check machine types. */
300 if (macha == machb) /* Same machine type */
302 else if (machb == 0) /* B is default */
304 else if (macha == 0) /* A is default */
306 else switch (archa) {
307 /* If particular machine types of one architecture are not
308 compatible with each other, this is the place to put those tests
309 (returning false if incompatible). */
311 /* The i960 has to distinct subspecies which may not interbreed:
314 Any architecture on the same line is compatible, the one on
315 the right is the least restrictive.
317 /* So, if either is a ca then the other must be a be core or ca */
318 if (macha == bfd_mach_i960_ca) {
319 if (machb != bfd_mach_i960_ca &&
320 machb != bfd_mach_i960_core) {
325 else if (machb == bfd_mach_i960_ca) {
326 if (macha != bfd_mach_i960_ca &&
327 macha != bfd_mach_i960_core) {
333 /* This must be from the bottom row, so take the higest */
334 pick_a = (macha > machb);
341 /* For these chips, as far as we care, "lower" numbers are included
342 by "higher" numbers, e.g. merge 68010 and 68020 into 68020,
343 386 and 486 into 486, etc. This will need to change
344 if&when we care about things like 68332. */
348 pick_a = (macha > machb);
351 /* By default, pick first file's type, for lack of something better. */
357 /* Set result based on our pick */