New file - generic implementation of sim_load for hardware only
[deliverable/binutils-gdb.git] / bfd / archures.c
CommitLineData
c618de01 1/* BFD library support routines for architectures.
fd8d7c31 2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 1997 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 124. bfd_arch_d10v, {* Mitsubishi D10V *}
fd8d7c31
MH
125. {* start-sanitize-d30v *}
126. bfd_arch_d30v, {* Mitsubishi D30V *}
127. {* end-sanitize-d30v *}
71c0bae0
KR
128. bfd_arch_z8k, {* Zilog Z8000 *}
129.#define bfd_mach_z8001 1
130.#define bfd_mach_z8002 2
2e235c93
ILT
131. bfd_arch_h8500, {* Hitachi H8/500 *}
132. bfd_arch_sh, {* Hitachi SH *}
133. bfd_arch_alpha, {* Dec Alpha *}
d94aca1a 134. bfd_arch_arm, {* Advanced Risc Machines ARM *}
76af94b9
DE
135.#define bfd_mach_arm_2 1
136.#define bfd_mach_arm_2a 2
137.#define bfd_mach_arm_3 3
138.#define bfd_mach_arm_3M 4
139.#define bfd_mach_arm_4 5
140.#define bfd_mach_arm_4T 6
d94aca1a 141. bfd_arch_ns32k, {* National Semiconductors ns32000 *}
b7577823 142. bfd_arch_w65, {* WDC 65816 *}
fd8d7c31
MH
143. {* start-sanitize-tic80 *}
144. bfd_arch_tic80, {* TI TMS320c80 (MVP) *}
145. {* end-sanitize-tic80 *}
efc2b064
JL
146. {* start-sanitize-v850 *}
147. bfd_arch_v850, {* NEC V850 *}
8988d935 148. {* start-sanitize-v850e *}
aa7bd5a5 149.#define bfd_mach_v850e 'E'
8988d935
NC
150. {* end-sanitize-v850e *}
151. {* start-sanitize-v850eq *}
aa7bd5a5 152.#define bfd_mach_v850eq 'Q'
8988d935 153. {* end-sanitize-v850eq *}
efc2b064 154. {* end-sanitize-v850 *}
37648010 155. bfd_arch_arc, {* Argonaut RISC Core *}
b7577823 156.#define bfd_mach_arc_base 0
76af94b9 157. bfd_arch_m32r, {* Mitsubishi M32R/D *}
cd6213ff
FF
158. bfd_arch_mn10200, {* Matsushita MN10200 *}
159. bfd_arch_mn10300, {* Matsushita MN10300 *}
9fda1a39
SC
160. bfd_arch_last
161. };
c618de01 162
c618de01
SC
163
164*/
165
9fda1a39
SC
166/*
167
168SUBSECTION
169 bfd_arch_info
170
171DESCRIPTION
172 This structure contains information on architectures for use
173 within BFD.
174
9fda1a39
SC
175.
176.typedef struct bfd_arch_info
177.{
178. int bits_per_word;
179. int bits_per_address;
180. int bits_per_byte;
181. enum bfd_architecture arch;
ae115e51 182. unsigned long mach;
5bc513b4
DE
183. const char *arch_name;
184. const char *printable_name;
ce07dd7c
KR
185. unsigned int section_align_power;
186. {* true if this is the default machine for the architecture *}
9fda1a39 187. boolean the_default;
5bc513b4
DE
188. const struct bfd_arch_info * (*compatible)
189. PARAMS ((const struct bfd_arch_info *a,
190. const struct bfd_arch_info *b));
9fda1a39 191.
5bc513b4 192. boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
9fda1a39 193.
5bc513b4 194. const struct bfd_arch_info *next;
9fda1a39 195.} bfd_arch_info_type;
4e6f9223
SC
196*/
197
5bc513b4
DE
198extern const bfd_arch_info_type bfd_a29k_arch;
199extern const bfd_arch_info_type bfd_alpha_arch;
5bc513b4 200extern const bfd_arch_info_type bfd_arc_arch;
5bc513b4 201extern const bfd_arch_info_type bfd_arm_arch;
efc2b064 202extern const bfd_arch_info_type bfd_d10v_arch;
fd8d7c31
MH
203/* start-sanitize-d30v */
204extern const bfd_arch_info_type bfd_d30v_arch;
205/* end-sanitize-d30v */
5bc513b4
DE
206extern const bfd_arch_info_type bfd_h8300_arch;
207extern const bfd_arch_info_type bfd_h8500_arch;
208extern const bfd_arch_info_type bfd_hppa_arch;
209extern const bfd_arch_info_type bfd_i386_arch;
210extern const bfd_arch_info_type bfd_i860_arch;
211extern const bfd_arch_info_type bfd_i960_arch;
efc2b064 212extern const bfd_arch_info_type bfd_m32r_arch;
5bc513b4
DE
213extern const bfd_arch_info_type bfd_m68k_arch;
214extern const bfd_arch_info_type bfd_m88k_arch;
215extern const bfd_arch_info_type bfd_mips_arch;
cd6213ff
FF
216extern const bfd_arch_info_type bfd_mn10200_arch;
217extern const bfd_arch_info_type bfd_mn10300_arch;
5bc513b4
DE
218extern const bfd_arch_info_type bfd_powerpc_arch;
219extern const bfd_arch_info_type bfd_rs6000_arch;
220extern const bfd_arch_info_type bfd_sh_arch;
5bc513b4 221extern const bfd_arch_info_type bfd_sparc_arch;
cd6213ff
FF
222/* start-sanitize-tic80 */
223extern const bfd_arch_info_type bfd_tic80_arch;
224/* end-sanitize-tic80 */
5bc513b4
DE
225extern const bfd_arch_info_type bfd_vax_arch;
226extern const bfd_arch_info_type bfd_we32k_arch;
227extern const bfd_arch_info_type bfd_z8k_arch;
228extern const bfd_arch_info_type bfd_ns32k_arch;
229extern const bfd_arch_info_type bfd_w65_arch;
efc2b064
JL
230/* start-sanitize-v850 */
231extern const bfd_arch_info_type bfd_v850_arch;
232/* end-sanitize-v850 */
5bc513b4
DE
233
234static const bfd_arch_info_type * const bfd_archures_list[] =
235{
236#ifdef SELECT_ARCHITECTURES
237 SELECT_ARCHITECTURES,
238#else
239 &bfd_a29k_arch,
240 &bfd_alpha_arch,
5bc513b4 241 &bfd_arc_arch,
5bc513b4 242 &bfd_arm_arch,
efc2b064 243 &bfd_d10v_arch,
fd8d7c31
MH
244/* start-sanitize-d30v */
245 &bfd_d30v_arch,
246/* end-sanitize-d30v */
5bc513b4
DE
247 &bfd_h8300_arch,
248 &bfd_h8500_arch,
249 &bfd_hppa_arch,
250 &bfd_i386_arch,
251 &bfd_i860_arch,
252 &bfd_i960_arch,
efc2b064 253 &bfd_m32r_arch,
5bc513b4
DE
254 &bfd_m68k_arch,
255 &bfd_m88k_arch,
256 &bfd_mips_arch,
cd6213ff
FF
257 &bfd_mn10200_arch,
258 &bfd_mn10300_arch,
5bc513b4
DE
259 &bfd_powerpc_arch,
260 &bfd_rs6000_arch,
261 &bfd_sh_arch,
5bc513b4 262 &bfd_sparc_arch,
fd8d7c31
MH
263/* start-sanitize-tic80 */
264 &bfd_tic80_arch,
265/* end-sanitize-tic80 */
5bc513b4
DE
266 &bfd_vax_arch,
267 &bfd_we32k_arch,
268 &bfd_z8k_arch,
269 &bfd_ns32k_arch,
270 &bfd_w65_arch,
efc2b064
JL
271/* start-sanitize-v850*/
272 &bfd_v850_arch,
273/* end-sanitize-v850 */
5bc513b4 274 0
8988d935 275#endif
5bc513b4 276};
4a81b561 277
9fda1a39 278/*
9fda1a39
SC
279FUNCTION
280 bfd_printable_name
4e6f9223 281
ce07dd7c 282SYNOPSIS
5bc513b4 283 const char *bfd_printable_name(bfd *abfd);
ce07dd7c 284
9fda1a39
SC
285DESCRIPTION
286 Return a printable string representing the architecture and machine
c188b0be 287 from the pointer to the architecture info structure.
4e6f9223 288
4e6f9223
SC
289*/
290
5bc513b4 291const char *
d94aca1a
MT
292bfd_printable_name (abfd)
293 bfd *abfd;
4e6f9223
SC
294{
295 return abfd->arch_info->printable_name;
4a81b561
DHW
296}
297
4e6f9223
SC
298
299
9fda1a39
SC
300/*
301FUNCTION
302 bfd_scan_arch
4e6f9223 303
ce07dd7c 304SYNOPSIS
5bc513b4 305 const bfd_arch_info_type *bfd_scan_arch(const char *string);
ce07dd7c 306
9fda1a39 307DESCRIPTION
c188b0be
DM
308 Figure out if BFD supports any cpu which could be described with
309 the name @var{string}. Return a pointer to an <<arch_info>>
9fda1a39
SC
310 structure if a machine is found, otherwise NULL.
311
c618de01 312*/
4a81b561 313
5bc513b4 314const bfd_arch_info_type *
d94aca1a 315bfd_scan_arch (string)
5bc513b4 316 const char *string;
4a81b561 317{
5bc513b4 318 const bfd_arch_info_type * const *app, *ap;
4e6f9223
SC
319
320 /* Look through all the installed architectures */
5bc513b4
DE
321 for (app = bfd_archures_list; *app != NULL; app++)
322 {
323 for (ap = *app; ap != NULL; ap = ap->next)
324 {
325 if (ap->scan (ap, string))
326 return ap;
327 }
328 }
329
330 return NULL;
4e6f9223
SC
331}
332
4a81b561 333
4a81b561 334
9fda1a39
SC
335/*
336FUNCTION
337 bfd_arch_get_compatible
338
ce07dd7c 339SYNOPSIS
5bc513b4
DE
340 const bfd_arch_info_type *bfd_arch_get_compatible(
341 const bfd *abfd,
342 const bfd *bbfd);
4e6f9223 343
ce07dd7c 344DESCRIPTION
c188b0be
DM
345 Determine whether two BFDs'
346 architectures and machine types are compatible. Calculates
9fda1a39
SC
347 the lowest common denominator between the two architectures
348 and machine types implied by the BFDs and returns a pointer to
c188b0be 349 an <<arch_info>> structure describing the compatible machine.
4e6f9223
SC
350*/
351
5bc513b4 352const bfd_arch_info_type *
d94aca1a 353bfd_arch_get_compatible (abfd, bbfd)
5bc513b4
DE
354 const bfd *abfd;
355 const bfd *bbfd;
4e6f9223 356{
b7577823
ILT
357 /* If either architecture is unknown, then all we can do is assume
358 the user knows what he's doing. */
359 if (abfd->arch_info->arch == bfd_arch_unknown)
360 return bbfd->arch_info;
361 if (bbfd->arch_info->arch == bfd_arch_unknown)
362 return abfd->arch_info;
363
364 /* Otherwise architecture-specific code has to decide. */
5bc513b4 365 return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
4a81b561
DHW
366}
367
4e6f9223 368
9fda1a39 369/*
ce07dd7c 370INTERNAL_DEFINITION
9fda1a39 371 bfd_default_arch_struct
4e6f9223 372
9fda1a39 373DESCRIPTION
ce07dd7c
KR
374 The <<bfd_default_arch_struct>> is an item of
375 <<bfd_arch_info_type>> which has been initialized to a fairly
376 generic state. A BFD starts life by pointing to this
377 structure, until the correct back end has determined the real
378 architecture of the file.
9fda1a39 379
5bc513b4 380.extern const bfd_arch_info_type bfd_default_arch_struct;
4e6f9223 381
4e6f9223
SC
382*/
383
5bc513b4 384const bfd_arch_info_type bfd_default_arch_struct =
9fda1a39 385{
2e235c93 386 32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
9fda1a39
SC
387 bfd_default_compatible,
388 bfd_default_scan,
389 0,
9fda1a39 390};
4e6f9223 391
9fda1a39
SC
392/*
393FUNCTION
394 bfd_set_arch_info
4e6f9223 395
9fda1a39 396SYNOPSIS
5bc513b4 397 void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
4e6f9223 398
c188b0be
DM
399DESCRIPTION
400 Set the architecture info of @var{abfd} to @var{arg}.
4e6f9223
SC
401*/
402
d94aca1a
MT
403void
404bfd_set_arch_info (abfd, arg)
405 bfd *abfd;
5bc513b4 406 const bfd_arch_info_type *arg;
4a81b561 407{
4e6f9223
SC
408 abfd->arch_info = arg;
409}
410
9fda1a39 411/*
ce07dd7c 412INTERNAL_FUNCTION
9fda1a39
SC
413 bfd_default_set_arch_mach
414
9fda1a39
SC
415SYNOPSIS
416 boolean bfd_default_set_arch_mach(bfd *abfd,
417 enum bfd_architecture arch,
418 unsigned long mach);
4e6f9223 419
ce07dd7c 420DESCRIPTION
c188b0be
DM
421 Set the architecture and machine type in BFD @var{abfd}
422 to @var{arch} and @var{mach}. Find the correct
423 pointer to a structure and insert it into the <<arch_info>>
ce07dd7c 424 pointer.
4e6f9223
SC
425*/
426
d94aca1a
MT
427boolean
428bfd_default_set_arch_mach (abfd, arch, mach)
429 bfd *abfd;
430 enum bfd_architecture arch;
5bc513b4 431 unsigned long mach;
4e6f9223 432{
5bc513b4 433 const bfd_arch_info_type * const *app, *ap;
4a81b561 434
5bc513b4
DE
435 for (app = bfd_archures_list; *app != NULL; app++)
436 {
437 for (ap = *app; ap != NULL; ap = ap->next)
438 {
439 if (ap->arch == arch
440 && (ap->mach == mach
441 || (mach == 0 && ap->the_default)))
442 {
443 abfd->arch_info = ap;
444 return true;
445 }
446 }
447 }
4e6f9223 448
5bc513b4
DE
449 abfd->arch_info = &bfd_default_arch_struct;
450 bfd_set_error (bfd_error_bad_value);
451 return false;
4a81b561 452}
4a81b561 453
4e6f9223 454
9fda1a39
SC
455/*
456FUNCTION
457 bfd_get_arch
4e6f9223 458
ce07dd7c
KR
459SYNOPSIS
460 enum bfd_architecture bfd_get_arch(bfd *abfd);
461
9fda1a39 462DESCRIPTION
c188b0be
DM
463 Return the enumerated type which describes the BFD @var{abfd}'s
464 architecture.
4e6f9223 465
4e6f9223
SC
466*/
467
d94aca1a
MT
468enum bfd_architecture
469bfd_get_arch (abfd)
470 bfd *abfd;
9fda1a39 471{
4e6f9223 472 return abfd->arch_info->arch;
9fda1a39 473}
4e6f9223 474
9fda1a39
SC
475/*
476FUNCTION
477 bfd_get_mach
4e6f9223 478
ce07dd7c
KR
479SYNOPSIS
480 unsigned long bfd_get_mach(bfd *abfd);
481
9fda1a39 482DESCRIPTION
c188b0be
DM
483 Return the long type which describes the BFD @var{abfd}'s
484 machine.
4e6f9223
SC
485*/
486
9fda1a39 487unsigned long
d94aca1a
MT
488bfd_get_mach (abfd)
489 bfd *abfd;
4a81b561 490{
4e6f9223 491 return abfd->arch_info->mach;
9fda1a39 492}
4e6f9223 493
9fda1a39
SC
494/*
495FUNCTION
496 bfd_arch_bits_per_byte
4e6f9223 497
ce07dd7c
KR
498SYNOPSIS
499 unsigned int bfd_arch_bits_per_byte(bfd *abfd);
500
9fda1a39 501DESCRIPTION
c188b0be
DM
502 Return the number of bits in one of the BFD @var{abfd}'s
503 architecture's bytes.
4e6f9223 504
4e6f9223
SC
505*/
506
d94aca1a
MT
507unsigned int
508bfd_arch_bits_per_byte (abfd)
509 bfd *abfd;
c188b0be
DM
510{
511 return abfd->arch_info->bits_per_byte;
512}
4e6f9223 513
9fda1a39
SC
514/*
515FUNCTION
516 bfd_arch_bits_per_address
4e6f9223 517
9fda1a39
SC
518SYNOPSIS
519 unsigned int bfd_arch_bits_per_address(bfd *abfd);
ce07dd7c
KR
520
521DESCRIPTION
c188b0be
DM
522 Return the number of bits in one of the BFD @var{abfd}'s
523 architecture's addresses.
4e6f9223
SC
524*/
525
d94aca1a
MT
526unsigned int
527bfd_arch_bits_per_address (abfd)
528 bfd *abfd;
c188b0be
DM
529{
530 return abfd->arch_info->bits_per_address;
531}
4e6f9223
SC
532
533
9fda1a39 534/*
ce07dd7c 535INTERNAL_FUNCTION
9fda1a39 536 bfd_default_compatible
4e6f9223 537
9fda1a39 538SYNOPSIS
5bc513b4
DE
539 const bfd_arch_info_type *bfd_default_compatible
540 (const bfd_arch_info_type *a,
541 const bfd_arch_info_type *b);
ce07dd7c
KR
542
543DESCRIPTION
544 The default function for testing for compatibility.
4e6f9223
SC
545*/
546
5bc513b4 547const bfd_arch_info_type *
d94aca1a 548bfd_default_compatible (a,b)
5bc513b4
DE
549 const bfd_arch_info_type *a;
550 const bfd_arch_info_type *b;
4e6f9223 551{
5bc513b4
DE
552 if (a->arch != b->arch)
553 return NULL;
4e6f9223 554
5bc513b4 555 if (a->mach > b->mach)
4e6f9223 556 return a;
5bc513b4
DE
557
558 if (b->mach > a->mach)
4e6f9223 559 return b;
5bc513b4 560
4e6f9223 561 return a;
4a81b561
DHW
562}
563
564
9fda1a39 565/*
ce07dd7c 566INTERNAL_FUNCTION
9fda1a39
SC
567 bfd_default_scan
568
9fda1a39 569SYNOPSIS
5bc513b4 570 boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
4e6f9223 571
ce07dd7c
KR
572DESCRIPTION
573 The default function for working out whether this is an
574 architecture hit and a machine hit.
4e6f9223
SC
575*/
576
577boolean
d94aca1a 578bfd_default_scan (info, string)
5bc513b4
DE
579 const struct bfd_arch_info *info;
580 const char *string;
4a81b561 581{
5bc513b4
DE
582 const char *ptr_src;
583 const char *ptr_tst;
b7577823
ILT
584 unsigned long number;
585 enum bfd_architecture arch;
5bc513b4 586
b7577823 587 /* First test for an exact match */
5bc513b4
DE
588 if (strcmp (string, info->printable_name) == 0)
589 return true;
b7577823
ILT
590
591 /* See how much of the supplied string matches with the
592 architecture, eg the string m68k:68020 would match the 68k entry
593 up to the :, then we get left with the machine number */
594
5bc513b4 595 for (ptr_src = string, ptr_tst = info->arch_name;
b7577823 596 *ptr_src && *ptr_tst;
5bc513b4 597 ptr_src++, ptr_tst++)
9fda1a39 598 {
b7577823 599 if (*ptr_src != *ptr_tst) break;
9fda1a39 600 }
4e6f9223 601
b7577823
ILT
602 /* Chewed up as much of the architecture as will match, skip any
603 colons */
5bc513b4
DE
604 if (*ptr_src == ':')
605 ptr_src++;
4e6f9223 606
5bc513b4
DE
607 if (*ptr_src == 0)
608 {
609 /* nothing more, then only keep this one if it is the default
610 machine for this architecture */
611 return info->the_default;
612 }
613
b7577823 614 number = 0;
5bc513b4
DE
615 while (isdigit(*ptr_src))
616 {
617 number = number * 10 + *ptr_src - '0';
618 ptr_src++;
619 }
b7577823
ILT
620
621 switch (number)
9fda1a39 622 {
b7577823
ILT
623 case 65:
624 arch = bfd_arch_w65;
625 break;
626
627 case 300:
2e235c93
ILT
628 arch = bfd_arch_h8300;
629 break;
630
b7577823 631 case 500:
2e235c93
ILT
632 arch = bfd_arch_h8500;
633 break;
634
b7577823
ILT
635 case 68010:
636 case 68020:
637 case 68030:
638 case 68040:
639 case 68332:
640 case 68050:
641 case 68000:
642 arch = bfd_arch_m68k;
643 break;
5bc513b4 644
b7577823
ILT
645 case 386:
646 case 80386:
647 case 486:
648 case 80486:
649 arch = bfd_arch_i386;
650 break;
5bc513b4 651
b7577823
ILT
652 case 29000:
653 arch = bfd_arch_a29k;
654 break;
4a81b561 655
b7577823
ILT
656 case 8000:
657 arch = bfd_arch_z8k;
658 break;
71c0bae0 659
b7577823
ILT
660 case 32000:
661 arch = bfd_arch_we32k;
662 break;
4e6f9223 663
b7577823
ILT
664 case 860:
665 case 80860:
666 arch = bfd_arch_i860;
667 break;
668 case 960:
669 case 80960:
670 arch = bfd_arch_i960;
671 break;
71c0bae0 672
b7577823
ILT
673 case 2000:
674 case 3000:
675 case 4000:
676 case 4400:
677 arch = bfd_arch_mips;
678 break;
4a81b561 679
b7577823
ILT
680 case 6000:
681 arch = bfd_arch_rs6000;
682 break;
9fda1a39 683
b7577823
ILT
684 default:
685 return false;
9fda1a39 686 }
5bc513b4 687
b7577823
ILT
688 if (arch != info->arch)
689 return false;
9fda1a39 690
b7577823
ILT
691 if (number != info->mach)
692 return false;
9fda1a39 693
b7577823 694 return true;
4a81b561 695}
c618de01
SC
696
697
9fda1a39
SC
698/*
699FUNCTION
700 bfd_get_arch_info
c618de01 701
9fda1a39 702SYNOPSIS
5bc513b4 703 const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
c618de01 704
c188b0be
DM
705DESCRIPTION
706 Return the architecture info struct in @var{abfd}.
4e6f9223 707*/
c618de01 708
5bc513b4 709const bfd_arch_info_type *
d94aca1a
MT
710bfd_get_arch_info (abfd)
711 bfd *abfd;
4e6f9223 712{
5bc513b4 713 return abfd->arch_info;
4e6f9223 714}
cbdc7909
JG
715
716
9fda1a39
SC
717/*
718FUNCTION
719 bfd_lookup_arch
720
9fda1a39 721SYNOPSIS
5bc513b4 722 const bfd_arch_info_type *bfd_lookup_arch
9fda1a39
SC
723 (enum bfd_architecture
724 arch,
ae115e51 725 unsigned long machine);
cbdc7909 726
ce07dd7c 727DESCRIPTION
c188b0be
DM
728 Look for the architecure info structure which matches the
729 arguments @var{arch} and @var{machine}. A machine of 0 matches the
ce07dd7c
KR
730 machine/architecture structure which marks itself as the
731 default.
cbdc7909
JG
732*/
733
5bc513b4 734const bfd_arch_info_type *
d94aca1a
MT
735bfd_lookup_arch (arch, machine)
736 enum bfd_architecture arch;
ae115e51 737 unsigned long machine;
cbdc7909 738{
5bc513b4
DE
739 const bfd_arch_info_type * const *app, *ap;
740
741 for (app = bfd_archures_list; *app != NULL; app++)
742 {
743 for (ap = *app; ap != NULL; ap = ap->next)
744 {
745 if (ap->arch == arch
746 && (ap->mach == machine
747 || (machine == 0 && ap->the_default)))
748 return ap;
9fda1a39 749 }
5bc513b4
DE
750 }
751
752 return NULL;
cbdc7909
JG
753}
754
755
9fda1a39
SC
756/*
757FUNCTION
758 bfd_printable_arch_mach
759
ce07dd7c 760SYNOPSIS
5bc513b4 761 const char *bfd_printable_arch_mach
ce07dd7c
KR
762 (enum bfd_architecture arch, unsigned long machine);
763
9fda1a39
SC
764DESCRIPTION
765 Return a printable string representing the architecture and
766 machine type.
cbdc7909 767
c188b0be 768 This routine is depreciated.
cbdc7909
JG
769*/
770
5bc513b4 771const char *
d94aca1a
MT
772bfd_printable_arch_mach (arch, machine)
773 enum bfd_architecture arch;
774 unsigned long machine;
cbdc7909 775{
5bc513b4
DE
776 const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
777
778 if (ap)
779 return ap->printable_name;
9fda1a39 780 return "UNKNOWN!";
cbdc7909 781}
This page took 0.237392 seconds and 4 git commands to generate.