Grrr. The mn10200 and mn10300 are _not_ similar enough to easily support
[deliverable/binutils-gdb.git] / bfd / archures.c
CommitLineData
c618de01 1/* BFD library support routines for architectures.
34255b70 2 Copyright (C) 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
4e6f9223
SC
3 Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
4
c618de01 5This file is part of BFD, the Binary File Descriptor library.
4a81b561 6
c618de01 7This program is free software; you can redistribute it and/or modify
4a81b561 8it under the terms of the GNU General Public License as published by
c618de01
SC
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
4a81b561 11
c618de01 12This program is distributed in the hope that it will be useful,
4a81b561
DHW
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
c618de01 18along with this program; if not, write to the Free Software
b7577823 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
c618de01 20
5bc513b4
DE
21#include "bfd.h"
22#include "sysdep.h"
23#include "libbfd.h"
24#include <ctype.h>
25
9fda1a39 26/*
4e6f9223 27
9fda1a39
SC
28SECTION
29 Architectures
30
c188b0be
DM
31 BFD keeps one atom in a BFD describing the
32 architecture of the data attached to the BFD: a pointer to a
9fda1a39
SC
33 <<bfd_arch_info_type>>.
34
c188b0be 35 Pointers to structures can be requested independently of a BFD
9fda1a39 36 so that an architecture's information can be interrogated
c188b0be 37 without access to an open BFD.
9fda1a39 38
c188b0be
DM
39 The architecture information is provided by each architecture package.
40 The set of default architectures is selected by the macro
9fda1a39 41 <<SELECT_ARCHITECTURES>>. This is normally set up in the
d94aca1a 42 @file{config/@var{target}.mt} file of your choice. If the name is not
9fda1a39
SC
43 defined, then all the architectures supported are included.
44
45 When BFD starts up, all the architectures are called with an
46 initialize method. It is up to the architecture back end to
71c0bae0 47 insert as many items into the list of architectures as it wants to;
9fda1a39
SC
48 generally this would be one for each machine and one for the
49 default case (an item with a machine field of 0).
c188b0be 50
d94aca1a 51 BFD's idea of an architecture is implemented in @file{archures.c}.
c618de01
SC
52*/
53
9fda1a39
SC
54/*
55
56SUBSECTION
57 bfd_architecture
58
59DESCRIPTION
60 This enum gives the object file's CPU architecture, in a
c188b0be
DM
61 global sense---i.e., what processor family does it belong to?
62 Another field indicates which processor within
9fda1a39 63 the family is in use. The machine gives a number which
c188b0be
DM
64 distinguishes different versions of the architecture,
65 containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
9fda1a39
SC
66 and 68020 and 68030 for Motorola 68020 and 68030.
67
68.enum bfd_architecture
69.{
70. bfd_arch_unknown, {* File arch not known *}
71. bfd_arch_obscure, {* Arch known, not one of these *}
72. bfd_arch_m68k, {* Motorola 68xxx *}
73. bfd_arch_vax, {* DEC Vax *}
74. bfd_arch_i960, {* Intel 960 *}
75. {* The order of the following is important.
76. lower number indicates a machine type that
77. only accepts a subset of the instructions
78. available to machines with higher numbers.
79. The exception is the "ca", which is
80. incompatible with all other machines except
81. "core". *}
82.
83.#define bfd_mach_i960_core 1
84.#define bfd_mach_i960_ka_sa 2
85.#define bfd_mach_i960_kb_sb 3
86.#define bfd_mach_i960_mc 4
87.#define bfd_mach_i960_xa 5
88.#define bfd_mach_i960_ca 6
34255b70 89.#define bfd_mach_i960_jx 7
cbe75cb6 90.#define bfd_mach_i960_hx 8
9fda1a39
SC
91.
92. bfd_arch_a29k, {* AMD 29000 *}
93. bfd_arch_sparc, {* SPARC *}
5bc513b4 94.#define bfd_mach_sparc 1
cbe75cb6 95.{* The difference between v8plus and v9 is that v9 is a true 64 bit env. *}
34255b70
JL
96.#define bfd_mach_sparc_sparclet 2
97.#define bfd_mach_sparc_sparclite 3
98.#define bfd_mach_sparc_v8plus 4
99.#define bfd_mach_sparc_v8plusa 5 {* with ultrasparc add'ns *}
100.#define bfd_mach_sparc_v9 6
101.#define bfd_mach_sparc_v9a 7 {* with ultrasparc add'ns *}
049f3d4c 102.{* Nonzero if MACH has the v9 instruction set. *}
34255b70
JL
103.#define bfd_mach_sparc_v9_p(mach) \
104. ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a)
9fda1a39
SC
105. bfd_arch_mips, {* MIPS Rxxxx *}
106. bfd_arch_i386, {* Intel 386 *}
9676e446
SG
107.#define bfd_mach_i386_i386 0
108.#define bfd_mach_i386_i8086 1
71c0bae0 109. bfd_arch_we32k, {* AT&T WE32xxx *}
9fda1a39
SC
110. bfd_arch_tahoe, {* CCI/Harris Tahoe *}
111. bfd_arch_i860, {* Intel 860 *}
112. bfd_arch_romp, {* IBM ROMP PC/RT *}
113. bfd_arch_alliant, {* Alliant *}
114. bfd_arch_convex, {* Convex *}
115. bfd_arch_m88k, {* Motorola 88xxx *}
116. bfd_arch_pyramid, {* Pyramid Technology *}
117. bfd_arch_h8300, {* Hitachi H8/300 *}
2e235c93
ILT
118.#define bfd_mach_h8300 1
119.#define bfd_mach_h8300h 2
34255b70 120.#define bfd_mach_h8300s 3
d94aca1a 121. bfd_arch_powerpc, {* PowerPC *}
9fda1a39 122. bfd_arch_rs6000, {* IBM RS/6000 *}
e3c01e92 123. bfd_arch_hppa, {* HP PA RISC *}
efc2b064
JL
124. {* start-sanitize-d10v *}
125. bfd_arch_d10v, {* Mitsubishi D10V *}
126. {* end-sanitize-d10v *}
71c0bae0
KR
127. bfd_arch_z8k, {* Zilog Z8000 *}
128.#define bfd_mach_z8001 1
129.#define bfd_mach_z8002 2
2e235c93
ILT
130. bfd_arch_h8500, {* Hitachi H8/500 *}
131. bfd_arch_sh, {* Hitachi SH *}
132. bfd_arch_alpha, {* Dec Alpha *}
d94aca1a
MT
133. bfd_arch_arm, {* Advanced Risc Machines ARM *}
134. bfd_arch_ns32k, {* National Semiconductors ns32000 *}
b7577823 135. bfd_arch_w65, {* WDC 65816 *}
efc2b064
JL
136. {* start-sanitize-v850 *}
137. bfd_arch_v850, {* NEC V850 *}
138. {* end-sanitize-v850 *}
37648010
KR
139. {* start-sanitize-arc *}
140. bfd_arch_arc, {* Argonaut RISC Core *}
b7577823
ILT
141.#define bfd_mach_arc_base 0
142.#define bfd_mach_arc_host 1
143.#define bfd_mach_arc_graphics 2
144.#define bfd_mach_arc_audio 3
37648010 145. {* end-sanitize-arc *}
efc2b064
JL
146. {* start-sanitize-m32r *}
147. bfd_arch_m32r, {* Mitsubishi M32R *}
148. {* end-sanitize-m32r *}
149. bfd_arch_mn10x00, {* Matsushita MN10x00 *}
9fda1a39
SC
150. bfd_arch_last
151. };
c618de01 152
c618de01
SC
153
154*/
155
9fda1a39
SC
156/*
157
158SUBSECTION
159 bfd_arch_info
160
161DESCRIPTION
162 This structure contains information on architectures for use
163 within BFD.
164
9fda1a39
SC
165.
166.typedef struct bfd_arch_info
167.{
168. int bits_per_word;
169. int bits_per_address;
170. int bits_per_byte;
171. enum bfd_architecture arch;
ae115e51 172. unsigned long mach;
5bc513b4
DE
173. const char *arch_name;
174. const char *printable_name;
ce07dd7c
KR
175. unsigned int section_align_power;
176. {* true if this is the default machine for the architecture *}
9fda1a39 177. boolean the_default;
5bc513b4
DE
178. const struct bfd_arch_info * (*compatible)
179. PARAMS ((const struct bfd_arch_info *a,
180. const struct bfd_arch_info *b));
9fda1a39 181.
5bc513b4 182. boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
9fda1a39 183.
5bc513b4 184. const struct bfd_arch_info *next;
9fda1a39 185.} bfd_arch_info_type;
4e6f9223
SC
186*/
187
5bc513b4
DE
188extern const bfd_arch_info_type bfd_a29k_arch;
189extern const bfd_arch_info_type bfd_alpha_arch;
190/* start-sanitize-arc */
191extern const bfd_arch_info_type bfd_arc_arch;
192/* end-sanitize-arc */
193extern const bfd_arch_info_type bfd_arm_arch;
efc2b064
JL
194/* start-sanitize-d10v */
195extern const bfd_arch_info_type bfd_d10v_arch;
196/* end-sanitize-d10v */
5bc513b4
DE
197extern const bfd_arch_info_type bfd_h8300_arch;
198extern const bfd_arch_info_type bfd_h8500_arch;
199extern const bfd_arch_info_type bfd_hppa_arch;
200extern const bfd_arch_info_type bfd_i386_arch;
201extern const bfd_arch_info_type bfd_i860_arch;
202extern const bfd_arch_info_type bfd_i960_arch;
efc2b064
JL
203/* start-sanitize-m32r */
204extern const bfd_arch_info_type bfd_m32r_arch;
205/* end-sanitize-m32r */
5bc513b4
DE
206extern const bfd_arch_info_type bfd_m68k_arch;
207extern const bfd_arch_info_type bfd_m88k_arch;
208extern const bfd_arch_info_type bfd_mips_arch;
efc2b064 209extern const bfd_arch_info_type bfd_mn10x00_arch;
5bc513b4
DE
210extern const bfd_arch_info_type bfd_powerpc_arch;
211extern const bfd_arch_info_type bfd_rs6000_arch;
212extern const bfd_arch_info_type bfd_sh_arch;
5bc513b4
DE
213extern const bfd_arch_info_type bfd_sparc_arch;
214extern const bfd_arch_info_type bfd_vax_arch;
215extern const bfd_arch_info_type bfd_we32k_arch;
216extern const bfd_arch_info_type bfd_z8k_arch;
217extern const bfd_arch_info_type bfd_ns32k_arch;
218extern const bfd_arch_info_type bfd_w65_arch;
efc2b064
JL
219/* start-sanitize-v850 */
220extern const bfd_arch_info_type bfd_v850_arch;
221/* end-sanitize-v850 */
5bc513b4
DE
222
223static const bfd_arch_info_type * const bfd_archures_list[] =
224{
225#ifdef SELECT_ARCHITECTURES
226 SELECT_ARCHITECTURES,
227#else
228 &bfd_a29k_arch,
229 &bfd_alpha_arch,
230/* start-sanitize-arc */
231 &bfd_arc_arch,
232/* end-sanitize-arc */
233 &bfd_arm_arch,
efc2b064
JL
234/* start-sanitize-d10v */
235 &bfd_d10v_arch,
236/* end-sanitize-d10v */
5bc513b4
DE
237 &bfd_h8300_arch,
238 &bfd_h8500_arch,
239 &bfd_hppa_arch,
240 &bfd_i386_arch,
241 &bfd_i860_arch,
242 &bfd_i960_arch,
efc2b064
JL
243/* start-sanitize-m32r */
244 &bfd_m32r_arch,
245/* end-sanitize-m32r */
5bc513b4
DE
246 &bfd_m68k_arch,
247 &bfd_m88k_arch,
248 &bfd_mips_arch,
efc2b064 249 &bfd_mn10x00_arch,
5bc513b4
DE
250 &bfd_powerpc_arch,
251 &bfd_rs6000_arch,
252 &bfd_sh_arch,
5bc513b4
DE
253 &bfd_sparc_arch,
254 &bfd_vax_arch,
255 &bfd_we32k_arch,
256 &bfd_z8k_arch,
257 &bfd_ns32k_arch,
258 &bfd_w65_arch,
efc2b064
JL
259/* start-sanitize-v850*/
260 &bfd_v850_arch,
261/* end-sanitize-v850 */
5bc513b4
DE
262#endif
263 0
264};
4a81b561 265
9fda1a39 266/*
9fda1a39
SC
267FUNCTION
268 bfd_printable_name
4e6f9223 269
ce07dd7c 270SYNOPSIS
5bc513b4 271 const char *bfd_printable_name(bfd *abfd);
ce07dd7c 272
9fda1a39
SC
273DESCRIPTION
274 Return a printable string representing the architecture and machine
c188b0be 275 from the pointer to the architecture info structure.
4e6f9223 276
4e6f9223
SC
277*/
278
5bc513b4 279const char *
d94aca1a
MT
280bfd_printable_name (abfd)
281 bfd *abfd;
4e6f9223
SC
282{
283 return abfd->arch_info->printable_name;
4a81b561
DHW
284}
285
4e6f9223
SC
286
287
9fda1a39
SC
288/*
289FUNCTION
290 bfd_scan_arch
4e6f9223 291
ce07dd7c 292SYNOPSIS
5bc513b4 293 const bfd_arch_info_type *bfd_scan_arch(const char *string);
ce07dd7c 294
9fda1a39 295DESCRIPTION
c188b0be
DM
296 Figure out if BFD supports any cpu which could be described with
297 the name @var{string}. Return a pointer to an <<arch_info>>
9fda1a39
SC
298 structure if a machine is found, otherwise NULL.
299
c618de01 300*/
4a81b561 301
5bc513b4 302const bfd_arch_info_type *
d94aca1a 303bfd_scan_arch (string)
5bc513b4 304 const char *string;
4a81b561 305{
5bc513b4 306 const bfd_arch_info_type * const *app, *ap;
4e6f9223
SC
307
308 /* Look through all the installed architectures */
5bc513b4
DE
309 for (app = bfd_archures_list; *app != NULL; app++)
310 {
311 for (ap = *app; ap != NULL; ap = ap->next)
312 {
313 if (ap->scan (ap, string))
314 return ap;
315 }
316 }
317
318 return NULL;
4e6f9223
SC
319}
320
4a81b561 321
4a81b561 322
9fda1a39
SC
323/*
324FUNCTION
325 bfd_arch_get_compatible
326
ce07dd7c 327SYNOPSIS
5bc513b4
DE
328 const bfd_arch_info_type *bfd_arch_get_compatible(
329 const bfd *abfd,
330 const bfd *bbfd);
4e6f9223 331
ce07dd7c 332DESCRIPTION
c188b0be
DM
333 Determine whether two BFDs'
334 architectures and machine types are compatible. Calculates
9fda1a39
SC
335 the lowest common denominator between the two architectures
336 and machine types implied by the BFDs and returns a pointer to
c188b0be 337 an <<arch_info>> structure describing the compatible machine.
4e6f9223
SC
338*/
339
5bc513b4 340const bfd_arch_info_type *
d94aca1a 341bfd_arch_get_compatible (abfd, bbfd)
5bc513b4
DE
342 const bfd *abfd;
343 const bfd *bbfd;
4e6f9223 344{
b7577823
ILT
345 /* If either architecture is unknown, then all we can do is assume
346 the user knows what he's doing. */
347 if (abfd->arch_info->arch == bfd_arch_unknown)
348 return bbfd->arch_info;
349 if (bbfd->arch_info->arch == bfd_arch_unknown)
350 return abfd->arch_info;
351
352 /* Otherwise architecture-specific code has to decide. */
5bc513b4 353 return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
4a81b561
DHW
354}
355
4e6f9223 356
9fda1a39 357/*
ce07dd7c 358INTERNAL_DEFINITION
9fda1a39 359 bfd_default_arch_struct
4e6f9223 360
9fda1a39 361DESCRIPTION
ce07dd7c
KR
362 The <<bfd_default_arch_struct>> is an item of
363 <<bfd_arch_info_type>> which has been initialized to a fairly
364 generic state. A BFD starts life by pointing to this
365 structure, until the correct back end has determined the real
366 architecture of the file.
9fda1a39 367
5bc513b4 368.extern const bfd_arch_info_type bfd_default_arch_struct;
4e6f9223 369
4e6f9223
SC
370*/
371
5bc513b4 372const bfd_arch_info_type bfd_default_arch_struct =
9fda1a39 373{
2e235c93 374 32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
9fda1a39
SC
375 bfd_default_compatible,
376 bfd_default_scan,
377 0,
9fda1a39 378};
4e6f9223 379
9fda1a39
SC
380/*
381FUNCTION
382 bfd_set_arch_info
4e6f9223 383
9fda1a39 384SYNOPSIS
5bc513b4 385 void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
4e6f9223 386
c188b0be
DM
387DESCRIPTION
388 Set the architecture info of @var{abfd} to @var{arg}.
4e6f9223
SC
389*/
390
d94aca1a
MT
391void
392bfd_set_arch_info (abfd, arg)
393 bfd *abfd;
5bc513b4 394 const bfd_arch_info_type *arg;
4a81b561 395{
4e6f9223
SC
396 abfd->arch_info = arg;
397}
398
9fda1a39 399/*
ce07dd7c 400INTERNAL_FUNCTION
9fda1a39
SC
401 bfd_default_set_arch_mach
402
9fda1a39
SC
403SYNOPSIS
404 boolean bfd_default_set_arch_mach(bfd *abfd,
405 enum bfd_architecture arch,
406 unsigned long mach);
4e6f9223 407
ce07dd7c 408DESCRIPTION
c188b0be
DM
409 Set the architecture and machine type in BFD @var{abfd}
410 to @var{arch} and @var{mach}. Find the correct
411 pointer to a structure and insert it into the <<arch_info>>
ce07dd7c 412 pointer.
4e6f9223
SC
413*/
414
d94aca1a
MT
415boolean
416bfd_default_set_arch_mach (abfd, arch, mach)
417 bfd *abfd;
418 enum bfd_architecture arch;
5bc513b4 419 unsigned long mach;
4e6f9223 420{
5bc513b4 421 const bfd_arch_info_type * const *app, *ap;
4a81b561 422
5bc513b4
DE
423 for (app = bfd_archures_list; *app != NULL; app++)
424 {
425 for (ap = *app; ap != NULL; ap = ap->next)
426 {
427 if (ap->arch == arch
428 && (ap->mach == mach
429 || (mach == 0 && ap->the_default)))
430 {
431 abfd->arch_info = ap;
432 return true;
433 }
434 }
435 }
4e6f9223 436
5bc513b4
DE
437 abfd->arch_info = &bfd_default_arch_struct;
438 bfd_set_error (bfd_error_bad_value);
439 return false;
4a81b561 440}
4a81b561 441
4e6f9223 442
9fda1a39
SC
443/*
444FUNCTION
445 bfd_get_arch
4e6f9223 446
ce07dd7c
KR
447SYNOPSIS
448 enum bfd_architecture bfd_get_arch(bfd *abfd);
449
9fda1a39 450DESCRIPTION
c188b0be
DM
451 Return the enumerated type which describes the BFD @var{abfd}'s
452 architecture.
4e6f9223 453
4e6f9223
SC
454*/
455
d94aca1a
MT
456enum bfd_architecture
457bfd_get_arch (abfd)
458 bfd *abfd;
9fda1a39 459{
4e6f9223 460 return abfd->arch_info->arch;
9fda1a39 461}
4e6f9223 462
9fda1a39
SC
463/*
464FUNCTION
465 bfd_get_mach
4e6f9223 466
ce07dd7c
KR
467SYNOPSIS
468 unsigned long bfd_get_mach(bfd *abfd);
469
9fda1a39 470DESCRIPTION
c188b0be
DM
471 Return the long type which describes the BFD @var{abfd}'s
472 machine.
4e6f9223
SC
473*/
474
9fda1a39 475unsigned long
d94aca1a
MT
476bfd_get_mach (abfd)
477 bfd *abfd;
4a81b561 478{
4e6f9223 479 return abfd->arch_info->mach;
9fda1a39 480}
4e6f9223 481
9fda1a39
SC
482/*
483FUNCTION
484 bfd_arch_bits_per_byte
4e6f9223 485
ce07dd7c
KR
486SYNOPSIS
487 unsigned int bfd_arch_bits_per_byte(bfd *abfd);
488
9fda1a39 489DESCRIPTION
c188b0be
DM
490 Return the number of bits in one of the BFD @var{abfd}'s
491 architecture's bytes.
4e6f9223 492
4e6f9223
SC
493*/
494
d94aca1a
MT
495unsigned int
496bfd_arch_bits_per_byte (abfd)
497 bfd *abfd;
c188b0be
DM
498{
499 return abfd->arch_info->bits_per_byte;
500}
4e6f9223 501
9fda1a39
SC
502/*
503FUNCTION
504 bfd_arch_bits_per_address
4e6f9223 505
9fda1a39
SC
506SYNOPSIS
507 unsigned int bfd_arch_bits_per_address(bfd *abfd);
ce07dd7c
KR
508
509DESCRIPTION
c188b0be
DM
510 Return the number of bits in one of the BFD @var{abfd}'s
511 architecture's addresses.
4e6f9223
SC
512*/
513
d94aca1a
MT
514unsigned int
515bfd_arch_bits_per_address (abfd)
516 bfd *abfd;
c188b0be
DM
517{
518 return abfd->arch_info->bits_per_address;
519}
4e6f9223
SC
520
521
9fda1a39 522/*
ce07dd7c 523INTERNAL_FUNCTION
9fda1a39 524 bfd_default_compatible
4e6f9223 525
9fda1a39 526SYNOPSIS
5bc513b4
DE
527 const bfd_arch_info_type *bfd_default_compatible
528 (const bfd_arch_info_type *a,
529 const bfd_arch_info_type *b);
ce07dd7c
KR
530
531DESCRIPTION
532 The default function for testing for compatibility.
4e6f9223
SC
533*/
534
5bc513b4 535const bfd_arch_info_type *
d94aca1a 536bfd_default_compatible (a,b)
5bc513b4
DE
537 const bfd_arch_info_type *a;
538 const bfd_arch_info_type *b;
4e6f9223 539{
5bc513b4
DE
540 if (a->arch != b->arch)
541 return NULL;
4e6f9223 542
5bc513b4 543 if (a->mach > b->mach)
4e6f9223 544 return a;
5bc513b4
DE
545
546 if (b->mach > a->mach)
4e6f9223 547 return b;
5bc513b4 548
4e6f9223 549 return a;
4a81b561
DHW
550}
551
552
9fda1a39 553/*
ce07dd7c 554INTERNAL_FUNCTION
9fda1a39
SC
555 bfd_default_scan
556
9fda1a39 557SYNOPSIS
5bc513b4 558 boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
4e6f9223 559
ce07dd7c
KR
560DESCRIPTION
561 The default function for working out whether this is an
562 architecture hit and a machine hit.
4e6f9223
SC
563*/
564
565boolean
d94aca1a 566bfd_default_scan (info, string)
5bc513b4
DE
567 const struct bfd_arch_info *info;
568 const char *string;
4a81b561 569{
5bc513b4
DE
570 const char *ptr_src;
571 const char *ptr_tst;
b7577823
ILT
572 unsigned long number;
573 enum bfd_architecture arch;
5bc513b4 574
b7577823 575 /* First test for an exact match */
5bc513b4
DE
576 if (strcmp (string, info->printable_name) == 0)
577 return true;
b7577823
ILT
578
579 /* See how much of the supplied string matches with the
580 architecture, eg the string m68k:68020 would match the 68k entry
581 up to the :, then we get left with the machine number */
582
5bc513b4 583 for (ptr_src = string, ptr_tst = info->arch_name;
b7577823 584 *ptr_src && *ptr_tst;
5bc513b4 585 ptr_src++, ptr_tst++)
9fda1a39 586 {
b7577823 587 if (*ptr_src != *ptr_tst) break;
9fda1a39 588 }
4e6f9223 589
b7577823
ILT
590 /* Chewed up as much of the architecture as will match, skip any
591 colons */
5bc513b4
DE
592 if (*ptr_src == ':')
593 ptr_src++;
4e6f9223 594
5bc513b4
DE
595 if (*ptr_src == 0)
596 {
597 /* nothing more, then only keep this one if it is the default
598 machine for this architecture */
599 return info->the_default;
600 }
601
b7577823 602 number = 0;
5bc513b4
DE
603 while (isdigit(*ptr_src))
604 {
605 number = number * 10 + *ptr_src - '0';
606 ptr_src++;
607 }
b7577823
ILT
608
609 switch (number)
9fda1a39 610 {
b7577823
ILT
611 case 65:
612 arch = bfd_arch_w65;
613 break;
614
615 case 300:
2e235c93
ILT
616 arch = bfd_arch_h8300;
617 break;
618
b7577823 619 case 500:
2e235c93
ILT
620 arch = bfd_arch_h8500;
621 break;
622
b7577823
ILT
623 case 68010:
624 case 68020:
625 case 68030:
626 case 68040:
627 case 68332:
628 case 68050:
629 case 68000:
630 arch = bfd_arch_m68k;
631 break;
5bc513b4 632
b7577823
ILT
633 case 386:
634 case 80386:
635 case 486:
636 case 80486:
637 arch = bfd_arch_i386;
638 break;
5bc513b4 639
b7577823
ILT
640 case 29000:
641 arch = bfd_arch_a29k;
642 break;
4a81b561 643
b7577823
ILT
644 case 8000:
645 arch = bfd_arch_z8k;
646 break;
71c0bae0 647
b7577823
ILT
648 case 32000:
649 arch = bfd_arch_we32k;
650 break;
4e6f9223 651
b7577823
ILT
652 case 860:
653 case 80860:
654 arch = bfd_arch_i860;
655 break;
656 case 960:
657 case 80960:
658 arch = bfd_arch_i960;
659 break;
71c0bae0 660
b7577823
ILT
661 case 2000:
662 case 3000:
663 case 4000:
664 case 4400:
665 arch = bfd_arch_mips;
666 break;
4a81b561 667
b7577823
ILT
668 case 6000:
669 arch = bfd_arch_rs6000;
670 break;
9fda1a39 671
b7577823
ILT
672 default:
673 return false;
9fda1a39 674 }
5bc513b4 675
b7577823
ILT
676 if (arch != info->arch)
677 return false;
9fda1a39 678
b7577823
ILT
679 if (number != info->mach)
680 return false;
9fda1a39 681
b7577823 682 return true;
4a81b561 683}
c618de01
SC
684
685
9fda1a39
SC
686/*
687FUNCTION
688 bfd_get_arch_info
c618de01 689
9fda1a39 690SYNOPSIS
5bc513b4 691 const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
c618de01 692
c188b0be
DM
693DESCRIPTION
694 Return the architecture info struct in @var{abfd}.
4e6f9223 695*/
c618de01 696
5bc513b4 697const bfd_arch_info_type *
d94aca1a
MT
698bfd_get_arch_info (abfd)
699 bfd *abfd;
4e6f9223 700{
5bc513b4 701 return abfd->arch_info;
4e6f9223 702}
cbdc7909
JG
703
704
9fda1a39
SC
705/*
706FUNCTION
707 bfd_lookup_arch
708
9fda1a39 709SYNOPSIS
5bc513b4 710 const bfd_arch_info_type *bfd_lookup_arch
9fda1a39
SC
711 (enum bfd_architecture
712 arch,
ae115e51 713 unsigned long machine);
cbdc7909 714
ce07dd7c 715DESCRIPTION
c188b0be
DM
716 Look for the architecure info structure which matches the
717 arguments @var{arch} and @var{machine}. A machine of 0 matches the
ce07dd7c
KR
718 machine/architecture structure which marks itself as the
719 default.
cbdc7909
JG
720*/
721
5bc513b4 722const bfd_arch_info_type *
d94aca1a
MT
723bfd_lookup_arch (arch, machine)
724 enum bfd_architecture arch;
ae115e51 725 unsigned long machine;
cbdc7909 726{
5bc513b4
DE
727 const bfd_arch_info_type * const *app, *ap;
728
729 for (app = bfd_archures_list; *app != NULL; app++)
730 {
731 for (ap = *app; ap != NULL; ap = ap->next)
732 {
733 if (ap->arch == arch
734 && (ap->mach == machine
735 || (machine == 0 && ap->the_default)))
736 return ap;
9fda1a39 737 }
5bc513b4
DE
738 }
739
740 return NULL;
cbdc7909
JG
741}
742
743
9fda1a39
SC
744/*
745FUNCTION
746 bfd_printable_arch_mach
747
ce07dd7c 748SYNOPSIS
5bc513b4 749 const char *bfd_printable_arch_mach
ce07dd7c
KR
750 (enum bfd_architecture arch, unsigned long machine);
751
9fda1a39
SC
752DESCRIPTION
753 Return a printable string representing the architecture and
754 machine type.
cbdc7909 755
c188b0be 756 This routine is depreciated.
cbdc7909
JG
757*/
758
5bc513b4 759const char *
d94aca1a
MT
760bfd_printable_arch_mach (arch, machine)
761 enum bfd_architecture arch;
762 unsigned long machine;
cbdc7909 763{
5bc513b4
DE
764 const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
765
766 if (ap)
767 return ap->printable_name;
9fda1a39 768 return "UNKNOWN!";
cbdc7909 769}
This page took 0.239296 seconds and 4 git commands to generate.