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