dummy commit before egcs merge
[deliverable/binutils-gdb.git] / bfd / archures.c
1 /* BFD library support routines for architectures.
2 Copyright (C) 1990, 91-97, 1998 Free Software Foundation, Inc.
3 Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program 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 2 of the License, or
10 (at your option) any later version.
11
12 This program 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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24 #include <ctype.h>
25
26 /*
27
28 SECTION
29 Architectures
30
31 BFD keeps one atom in a BFD describing the
32 architecture of the data attached to the BFD: a pointer to a
33 <<bfd_arch_info_type>>.
34
35 Pointers to structures can be requested independently of a BFD
36 so that an architecture's information can be interrogated
37 without access to an open BFD.
38
39 The architecture information is provided by each architecture package.
40 The set of default architectures is selected by the macro
41 <<SELECT_ARCHITECTURES>>. This is normally set up in the
42 @file{config/@var{target}.mt} file of your choice. If the name is not
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
47 insert as many items into the list of architectures as it wants to;
48 generally this would be one for each machine and one for the
49 default case (an item with a machine field of 0).
50
51 BFD's idea of an architecture is implemented in @file{archures.c}.
52 */
53
54 /*
55
56 SUBSECTION
57 bfd_architecture
58
59 DESCRIPTION
60 This enum gives the object file's CPU architecture, in a
61 global sense---i.e., what processor family does it belong to?
62 Another field indicates which processor within
63 the family is in use. The machine gives a number which
64 distinguishes different versions of the architecture,
65 containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
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 .#define bfd_mach_m68000 1
74 .#define bfd_mach_m68008 2
75 .#define bfd_mach_m68010 3
76 .#define bfd_mach_m68020 4
77 .#define bfd_mach_m68030 5
78 .#define bfd_mach_m68040 6
79 .#define bfd_mach_m68060 7
80 .#define bfd_mach_cpu32 8
81 . bfd_arch_vax, {* DEC Vax *}
82 . bfd_arch_i960, {* Intel 960 *}
83 . {* The order of the following is important.
84 . lower number indicates a machine type that
85 . only accepts a subset of the instructions
86 . available to machines with higher numbers.
87 . The exception is the "ca", which is
88 . incompatible with all other machines except
89 . "core". *}
90 .
91 .#define bfd_mach_i960_core 1
92 .#define bfd_mach_i960_ka_sa 2
93 .#define bfd_mach_i960_kb_sb 3
94 .#define bfd_mach_i960_mc 4
95 .#define bfd_mach_i960_xa 5
96 .#define bfd_mach_i960_ca 6
97 .#define bfd_mach_i960_jx 7
98 .#define bfd_mach_i960_hx 8
99 .
100 . bfd_arch_a29k, {* AMD 29000 *}
101 . bfd_arch_sparc, {* SPARC *}
102 .#define bfd_mach_sparc 1
103 .{* The difference between v8plus and v9 is that v9 is a true 64 bit env. *}
104 .#define bfd_mach_sparc_sparclet 2
105 .#define bfd_mach_sparc_sparclite 3
106 .#define bfd_mach_sparc_v8plus 4
107 .#define bfd_mach_sparc_v8plusa 5 {* with ultrasparc add'ns *}
108 .#define bfd_mach_sparc_sparclite_le 6
109 .#define bfd_mach_sparc_v9 7
110 .#define bfd_mach_sparc_v9a 8 {* with ultrasparc add'ns *}
111 .{* Nonzero if MACH has the v9 instruction set. *}
112 .#define bfd_mach_sparc_v9_p(mach) \
113 . ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a)
114 . bfd_arch_mips, {* MIPS Rxxxx *}
115 . {* start-sanitize-tx19 *}
116 .#define bfd_mach_mips1900 1900
117 . {* end-sanitize-tx19 *}
118 .#define bfd_mach_mips3000 3000
119 .#define bfd_mach_mips3900 3900
120 .#define bfd_mach_mips4000 4000
121 .#define bfd_mach_mips4010 4010
122 .#define bfd_mach_mips4100 4100
123 .#define bfd_mach_mips4300 4300
124 .#define bfd_mach_mips4400 4400
125 .#define bfd_mach_mips4600 4600
126 .#define bfd_mach_mips4650 4650
127 . {* start-sanitize-vr4320 *}
128 .#define bfd_mach_mips4320 4320
129 . {* end-sanitize-vr4320 *}
130 . {* start-sanitize-tx49 *}
131 .#define bfd_mach_mips4900 4900
132 . {* end-sanitize-tx49 *}
133 .#define bfd_mach_mips5000 5000
134 . {* start-sanitize-cygnus *} {* CYGNUS LOCAL vr5400/raeburn *}
135 .#define bfd_mach_mips5400 5400
136 . {* end-sanitize-cygnus *}
137 . {* start-sanitize-r5900 *}
138 .#define bfd_mach_mips5900 5900
139 . {* end-sanitize-r5900 *}
140 .#define bfd_mach_mips6000 6000
141 .#define bfd_mach_mips8000 8000
142 .#define bfd_mach_mips10000 10000
143 .#define bfd_mach_mips16 16
144 . {* start-sanitize-sky *}
145 . {* The DVP is a machine within the mips architecture. *}
146 .#define bfd_mach_dvp_dma 42000
147 .#define bfd_mach_dvp_vif 42001
148 .#define bfd_mach_dvp_vu 42002
149 .#define bfd_mach_dvp_gif 42003
150 .#define bfd_mach_dvp_p(mach) ((mach) >= 42000 && (mach) <= 42003)
151 . {* end-sanitize-sky *}
152 . bfd_arch_i386, {* Intel 386 *}
153 .#define bfd_mach_i386_i386 0
154 .#define bfd_mach_i386_i8086 1
155 . bfd_arch_we32k, {* AT&T WE32xxx *}
156 . bfd_arch_tahoe, {* CCI/Harris Tahoe *}
157 . bfd_arch_i860, {* Intel 860 *}
158 . bfd_arch_romp, {* IBM ROMP PC/RT *}
159 . bfd_arch_alliant, {* Alliant *}
160 . bfd_arch_convex, {* Convex *}
161 . bfd_arch_m88k, {* Motorola 88xxx *}
162 . bfd_arch_pyramid, {* Pyramid Technology *}
163 . bfd_arch_h8300, {* Hitachi H8/300 *}
164 .#define bfd_mach_h8300 1
165 .#define bfd_mach_h8300h 2
166 .#define bfd_mach_h8300s 3
167 . bfd_arch_powerpc, {* PowerPC *}
168 . bfd_arch_rs6000, {* IBM RS/6000 *}
169 . bfd_arch_hppa, {* HP PA RISC *}
170 . bfd_arch_d10v, {* Mitsubishi D10V *}
171 . bfd_arch_d30v, {* Mitsubishi D30V *}
172 . bfd_arch_z8k, {* Zilog Z8000 *}
173 .#define bfd_mach_z8001 1
174 .#define bfd_mach_z8002 2
175 . bfd_arch_h8500, {* Hitachi H8/500 *}
176 . bfd_arch_sh, {* Hitachi SH *}
177 .#define bfd_mach_sh 0
178 .#define bfd_mach_sh3 0x30
179 .#define bfd_mach_sh3e 0x3e
180 .#define bfd_mach_sh4 0x40
181 . bfd_arch_alpha, {* Dec Alpha *}
182 . bfd_arch_arm, {* Advanced Risc Machines ARM *}
183 .#define bfd_mach_arm_2 1
184 .#define bfd_mach_arm_2a 2
185 .#define bfd_mach_arm_3 3
186 .#define bfd_mach_arm_3M 4
187 .#define bfd_mach_arm_4 5
188 .#define bfd_mach_arm_4T 6
189 . bfd_arch_ns32k, {* National Semiconductors ns32000 *}
190 . bfd_arch_w65, {* WDC 65816 *}
191 . bfd_arch_tic30, {* Texas Instruments TMS320C30 *}
192 . {* start-sanitize-tic80 *}
193 . bfd_arch_tic80, {* TI TMS320c80 (MVP) *}
194 . {* end-sanitize-tic80 *}
195 . bfd_arch_v850, {* NEC V850 *}
196 .#define bfd_mach_v850 0
197 . {* start-sanitize-v850e *}
198 .#define bfd_mach_v850e 'E'
199 .#define bfd_mach_v850ea 'A'
200 . {* end-sanitize-v850e *}
201 . bfd_arch_arc, {* Argonaut RISC Core *}
202 .#define bfd_mach_arc_base 0
203 . bfd_arch_m32r, {* Mitsubishi M32R/D *}
204 .#define bfd_mach_m32r 0 {* backwards compatibility *}
205 . {* start-sanitize-m32rx *}
206 .#define bfd_mach_m32rx 'x'
207 . {* end-sanitize-m32rx *}
208 . bfd_arch_mn10200, {* Matsushita MN10200 *}
209 . bfd_arch_mn10300, {* Matsushita MN10300 *}
210 .#define bfd_mach_mn10300 300
211 . {* start-sanitize-am33 *}
212 .#define bfd_mach_am33 330
213 . {* end-sanitize-am33 *}
214 . bfd_arch_last
215 . };
216
217
218 */
219
220 /*
221
222 SUBSECTION
223 bfd_arch_info
224
225 DESCRIPTION
226 This structure contains information on architectures for use
227 within BFD.
228
229 .
230 .typedef struct bfd_arch_info
231 .{
232 . int bits_per_word;
233 . int bits_per_address;
234 . int bits_per_byte;
235 . enum bfd_architecture arch;
236 . unsigned long mach;
237 . const char *arch_name;
238 . const char *printable_name;
239 . unsigned int section_align_power;
240 . {* true if this is the default machine for the architecture *}
241 . boolean the_default;
242 . const struct bfd_arch_info * (*compatible)
243 . PARAMS ((const struct bfd_arch_info *a,
244 . const struct bfd_arch_info *b));
245 .
246 . boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
247 .
248 . const struct bfd_arch_info *next;
249 .} bfd_arch_info_type;
250 */
251
252 extern const bfd_arch_info_type bfd_a29k_arch;
253 extern const bfd_arch_info_type bfd_alpha_arch;
254 extern const bfd_arch_info_type bfd_arc_arch;
255 extern const bfd_arch_info_type bfd_arm_arch;
256 extern const bfd_arch_info_type bfd_d10v_arch;
257 extern const bfd_arch_info_type bfd_d30v_arch;
258 extern const bfd_arch_info_type bfd_h8300_arch;
259 extern const bfd_arch_info_type bfd_h8500_arch;
260 extern const bfd_arch_info_type bfd_hppa_arch;
261 extern const bfd_arch_info_type bfd_i386_arch;
262 extern const bfd_arch_info_type bfd_i860_arch;
263 extern const bfd_arch_info_type bfd_i960_arch;
264 extern const bfd_arch_info_type bfd_m32r_arch;
265 extern const bfd_arch_info_type bfd_m68k_arch;
266 extern const bfd_arch_info_type bfd_m88k_arch;
267 extern const bfd_arch_info_type bfd_mips_arch;
268 extern const bfd_arch_info_type bfd_mn10200_arch;
269 extern const bfd_arch_info_type bfd_mn10300_arch;
270 extern const bfd_arch_info_type bfd_powerpc_arch;
271 extern const bfd_arch_info_type bfd_rs6000_arch;
272 extern const bfd_arch_info_type bfd_sh_arch;
273 extern const bfd_arch_info_type bfd_sparc_arch;
274 extern const bfd_arch_info_type bfd_tic30_arch;
275 /* start-sanitize-tic80 */
276 extern const bfd_arch_info_type bfd_tic80_arch;
277 /* end-sanitize-tic80 */
278 extern const bfd_arch_info_type bfd_vax_arch;
279 extern const bfd_arch_info_type bfd_we32k_arch;
280 extern const bfd_arch_info_type bfd_z8k_arch;
281 extern const bfd_arch_info_type bfd_ns32k_arch;
282 extern const bfd_arch_info_type bfd_w65_arch;
283 extern const bfd_arch_info_type bfd_v850_arch;
284
285 static const bfd_arch_info_type * const bfd_archures_list[] =
286 {
287 #ifdef SELECT_ARCHITECTURES
288 SELECT_ARCHITECTURES,
289 #else
290 &bfd_a29k_arch,
291 &bfd_alpha_arch,
292 &bfd_arc_arch,
293 &bfd_arm_arch,
294 &bfd_d10v_arch,
295 &bfd_d30v_arch,
296 &bfd_h8300_arch,
297 &bfd_h8500_arch,
298 &bfd_hppa_arch,
299 &bfd_i386_arch,
300 &bfd_i860_arch,
301 &bfd_i960_arch,
302 &bfd_m32r_arch,
303 &bfd_m68k_arch,
304 &bfd_m88k_arch,
305 &bfd_mips_arch,
306 &bfd_mn10200_arch,
307 &bfd_mn10300_arch,
308 &bfd_powerpc_arch,
309 &bfd_rs6000_arch,
310 &bfd_sh_arch,
311 &bfd_sparc_arch,
312 &bfd_tic30_arch,
313 /* start-sanitize-tic80 */
314 &bfd_tic80_arch,
315 /* end-sanitize-tic80 */
316 &bfd_vax_arch,
317 &bfd_we32k_arch,
318 &bfd_z8k_arch,
319 &bfd_ns32k_arch,
320 &bfd_w65_arch,
321 &bfd_v850_arch,
322 #endif
323 0
324 };
325
326 /*
327 FUNCTION
328 bfd_printable_name
329
330 SYNOPSIS
331 const char *bfd_printable_name(bfd *abfd);
332
333 DESCRIPTION
334 Return a printable string representing the architecture and machine
335 from the pointer to the architecture info structure.
336
337 */
338
339 const char *
340 bfd_printable_name (abfd)
341 bfd *abfd;
342 {
343 return abfd->arch_info->printable_name;
344 }
345
346
347
348 /*
349 FUNCTION
350 bfd_scan_arch
351
352 SYNOPSIS
353 const bfd_arch_info_type *bfd_scan_arch(const char *string);
354
355 DESCRIPTION
356 Figure out if BFD supports any cpu which could be described with
357 the name @var{string}. Return a pointer to an <<arch_info>>
358 structure if a machine is found, otherwise NULL.
359
360 */
361
362 const bfd_arch_info_type *
363 bfd_scan_arch (string)
364 const char *string;
365 {
366 const bfd_arch_info_type * const *app, *ap;
367
368 /* Look through all the installed architectures */
369 for (app = bfd_archures_list; *app != NULL; app++)
370 {
371 for (ap = *app; ap != NULL; ap = ap->next)
372 {
373 if (ap->scan (ap, string))
374 return ap;
375 }
376 }
377
378 return NULL;
379 }
380
381
382
383 /*
384 FUNCTION
385 bfd_arch_list
386
387 SYNOPSIS
388 const char **bfd_arch_list(void);
389
390 DESCRIPTION
391 Return a freshly malloced NULL-terminated vector of the names
392 of all the valid BFD architectures. Do not modify the names.
393
394 */
395
396 const char **
397 bfd_arch_list ()
398 {
399 int vec_length = 0;
400 const char **name_ptr;
401 const char **name_list;
402 const bfd_arch_info_type * const *app;
403
404 /* Determine the number of architectures */
405 vec_length = 0;
406 for (app = bfd_archures_list; *app != NULL; app++)
407 {
408 const bfd_arch_info_type *ap;
409 for (ap = *app; ap != NULL; ap = ap->next)
410 {
411 vec_length++;
412 }
413 }
414
415 name_list = (CONST char **)
416 bfd_malloc ((vec_length + 1) * sizeof (char **));
417 if (name_list == NULL)
418 return NULL;
419
420 /* Point the list at each of the names */
421 name_ptr = name_list;
422 for (app = bfd_archures_list; *app != NULL; app++)
423 {
424 const bfd_arch_info_type *ap;
425 for (ap = *app; ap != NULL; ap = ap->next)
426 {
427 *name_ptr = ap->printable_name;
428 name_ptr++;
429 }
430 }
431 *name_ptr = NULL;
432
433 return name_list;
434 }
435
436
437
438 /*
439 FUNCTION
440 bfd_arch_get_compatible
441
442 SYNOPSIS
443 const bfd_arch_info_type *bfd_arch_get_compatible(
444 const bfd *abfd,
445 const bfd *bbfd);
446
447 DESCRIPTION
448 Determine whether two BFDs'
449 architectures and machine types are compatible. Calculates
450 the lowest common denominator between the two architectures
451 and machine types implied by the BFDs and returns a pointer to
452 an <<arch_info>> structure describing the compatible machine.
453 */
454
455 const bfd_arch_info_type *
456 bfd_arch_get_compatible (abfd, bbfd)
457 const bfd *abfd;
458 const bfd *bbfd;
459 {
460 /* If either architecture is unknown, then all we can do is assume
461 the user knows what he's doing. */
462 if (abfd->arch_info->arch == bfd_arch_unknown)
463 return bbfd->arch_info;
464 if (bbfd->arch_info->arch == bfd_arch_unknown)
465 return abfd->arch_info;
466
467 /* Otherwise architecture-specific code has to decide. */
468 return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
469 }
470
471
472 /*
473 INTERNAL_DEFINITION
474 bfd_default_arch_struct
475
476 DESCRIPTION
477 The <<bfd_default_arch_struct>> is an item of
478 <<bfd_arch_info_type>> which has been initialized to a fairly
479 generic state. A BFD starts life by pointing to this
480 structure, until the correct back end has determined the real
481 architecture of the file.
482
483 .extern const bfd_arch_info_type bfd_default_arch_struct;
484
485 */
486
487 const bfd_arch_info_type bfd_default_arch_struct =
488 {
489 32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
490 bfd_default_compatible,
491 bfd_default_scan,
492 0,
493 };
494
495 /*
496 FUNCTION
497 bfd_set_arch_info
498
499 SYNOPSIS
500 void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
501
502 DESCRIPTION
503 Set the architecture info of @var{abfd} to @var{arg}.
504 */
505
506 void
507 bfd_set_arch_info (abfd, arg)
508 bfd *abfd;
509 const bfd_arch_info_type *arg;
510 {
511 abfd->arch_info = arg;
512 }
513
514 /*
515 INTERNAL_FUNCTION
516 bfd_default_set_arch_mach
517
518 SYNOPSIS
519 boolean bfd_default_set_arch_mach(bfd *abfd,
520 enum bfd_architecture arch,
521 unsigned long mach);
522
523 DESCRIPTION
524 Set the architecture and machine type in BFD @var{abfd}
525 to @var{arch} and @var{mach}. Find the correct
526 pointer to a structure and insert it into the <<arch_info>>
527 pointer.
528 */
529
530 boolean
531 bfd_default_set_arch_mach (abfd, arch, mach)
532 bfd *abfd;
533 enum bfd_architecture arch;
534 unsigned long mach;
535 {
536 const bfd_arch_info_type * const *app, *ap;
537
538 for (app = bfd_archures_list; *app != NULL; app++)
539 {
540 for (ap = *app; ap != NULL; ap = ap->next)
541 {
542 if (ap->arch == arch
543 && (ap->mach == mach
544 || (mach == 0 && ap->the_default)))
545 {
546 abfd->arch_info = ap;
547 return true;
548 }
549 }
550 }
551
552 abfd->arch_info = &bfd_default_arch_struct;
553 bfd_set_error (bfd_error_bad_value);
554 return false;
555 }
556
557
558 /*
559 FUNCTION
560 bfd_get_arch
561
562 SYNOPSIS
563 enum bfd_architecture bfd_get_arch(bfd *abfd);
564
565 DESCRIPTION
566 Return the enumerated type which describes the BFD @var{abfd}'s
567 architecture.
568
569 */
570
571 enum bfd_architecture
572 bfd_get_arch (abfd)
573 bfd *abfd;
574 {
575 return abfd->arch_info->arch;
576 }
577
578 /*
579 FUNCTION
580 bfd_get_mach
581
582 SYNOPSIS
583 unsigned long bfd_get_mach(bfd *abfd);
584
585 DESCRIPTION
586 Return the long type which describes the BFD @var{abfd}'s
587 machine.
588 */
589
590 unsigned long
591 bfd_get_mach (abfd)
592 bfd *abfd;
593 {
594 return abfd->arch_info->mach;
595 }
596
597 /*
598 FUNCTION
599 bfd_arch_bits_per_byte
600
601 SYNOPSIS
602 unsigned int bfd_arch_bits_per_byte(bfd *abfd);
603
604 DESCRIPTION
605 Return the number of bits in one of the BFD @var{abfd}'s
606 architecture's bytes.
607
608 */
609
610 unsigned int
611 bfd_arch_bits_per_byte (abfd)
612 bfd *abfd;
613 {
614 return abfd->arch_info->bits_per_byte;
615 }
616
617 /*
618 FUNCTION
619 bfd_arch_bits_per_address
620
621 SYNOPSIS
622 unsigned int bfd_arch_bits_per_address(bfd *abfd);
623
624 DESCRIPTION
625 Return the number of bits in one of the BFD @var{abfd}'s
626 architecture's addresses.
627 */
628
629 unsigned int
630 bfd_arch_bits_per_address (abfd)
631 bfd *abfd;
632 {
633 return abfd->arch_info->bits_per_address;
634 }
635
636
637 /*
638 INTERNAL_FUNCTION
639 bfd_default_compatible
640
641 SYNOPSIS
642 const bfd_arch_info_type *bfd_default_compatible
643 (const bfd_arch_info_type *a,
644 const bfd_arch_info_type *b);
645
646 DESCRIPTION
647 The default function for testing for compatibility.
648 */
649
650 const bfd_arch_info_type *
651 bfd_default_compatible (a,b)
652 const bfd_arch_info_type *a;
653 const bfd_arch_info_type *b;
654 {
655 if (a->arch != b->arch)
656 return NULL;
657
658 if (a->mach > b->mach)
659 return a;
660
661 if (b->mach > a->mach)
662 return b;
663
664 return a;
665 }
666
667
668 /*
669 INTERNAL_FUNCTION
670 bfd_default_scan
671
672 SYNOPSIS
673 boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
674
675 DESCRIPTION
676 The default function for working out whether this is an
677 architecture hit and a machine hit.
678 */
679
680 boolean
681 bfd_default_scan (info, string)
682 const struct bfd_arch_info *info;
683 const char *string;
684 {
685 const char *ptr_src;
686 const char *ptr_tst;
687 unsigned long number;
688 enum bfd_architecture arch;
689 const char *printable_name_colon;
690
691 /* Exact match of the architecture name (ARCH_NAME) and also the
692 default architecture? */
693 if (strcasecmp (string, info->arch_name) == 0
694 && info->the_default)
695 return true;
696
697 /* Exact match of the machine name (PRINTABLE_NAME)? */
698 if (strcasecmp (string, info->printable_name) == 0)
699 return true;
700
701 /* Given that printable_name contains no colon, attempt to match:
702 ARCH_NAME [ ":" ] PRINTABLE_NAME? */
703 printable_name_colon = strchr (info->printable_name, ':');
704 if (printable_name_colon == NULL)
705 {
706 int strlen_arch_name = strlen (info->arch_name);
707 if (strncasecmp (string, info->arch_name, strlen_arch_name) == 0)
708 {
709 if (string[strlen_arch_name] == ':')
710 {
711 if (strcasecmp (string + strlen_arch_name + 1,
712 info->printable_name) == 0)
713 return true;
714 }
715 else
716 {
717 if (strcasecmp (string + strlen_arch_name,
718 info->printable_name) == 0)
719 return true;
720 }
721 }
722 }
723
724 /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>;
725 Attempt to match: <arch> <mach>? */
726 if (printable_name_colon != NULL)
727 {
728 int colon_index = printable_name_colon - info->printable_name;
729 if (strncasecmp (string, info->printable_name, colon_index) == 0
730 && strcasecmp (string + colon_index,
731 info->printable_name + colon_index + 1) == 0)
732 return true;
733 }
734
735 /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>; Do not
736 attempt to match just <mach>, it could be ambigious. This test
737 is left until later. */
738
739 /* NOTE: The below is retained for compatibility only. Please do not
740 add to this code */
741
742 /* See how much of the supplied string matches with the
743 architecture, eg the string m68k:68020 would match the 68k entry
744 up to the :, then we get left with the machine number */
745
746 for (ptr_src = string, ptr_tst = info->arch_name;
747 *ptr_src && *ptr_tst;
748 ptr_src++, ptr_tst++)
749 {
750 if (*ptr_src != *ptr_tst) break;
751 }
752
753 /* Chewed up as much of the architecture as will match, skip any
754 colons */
755 if (*ptr_src == ':')
756 ptr_src++;
757
758 if (*ptr_src == 0)
759 {
760 /* nothing more, then only keep this one if it is the default
761 machine for this architecture */
762 return info->the_default;
763 }
764
765 number = 0;
766 while (isdigit ((unsigned char) *ptr_src))
767 {
768 number = number * 10 + *ptr_src - '0';
769 ptr_src++;
770 }
771
772 /* NOTE: The below is retained for compatibility only.
773 PLEASE DO NOT ADD TO THIS CODE. */
774
775 switch (number)
776 {
777 /* FIXME: These are needed to parse IEEE objects. */
778 case 68000:
779 arch = bfd_arch_m68k;
780 number = bfd_mach_m68000;
781 break;
782 case 68010:
783 arch = bfd_arch_m68k;
784 number = bfd_mach_m68010;
785 break;
786 case 68020:
787 arch = bfd_arch_m68k;
788 number = bfd_mach_m68020;
789 break;
790 case 68030:
791 arch = bfd_arch_m68k;
792 number = bfd_mach_m68030;
793 break;
794 case 68040:
795 arch = bfd_arch_m68k;
796 number = bfd_mach_m68040;
797 break;
798 case 68060:
799 arch = bfd_arch_m68k;
800 number = bfd_mach_m68060;
801 break;
802 case 68332:
803 arch = bfd_arch_m68k;
804 number = bfd_mach_cpu32;
805 break;
806
807 case 32000:
808 arch = bfd_arch_we32k;
809 break;
810
811 case 3000:
812 arch = bfd_arch_mips;
813 number = bfd_mach_mips3000;
814 break;
815
816 case 4000:
817 arch = bfd_arch_mips;
818 number = bfd_mach_mips4000;
819 break;
820
821 case 6000:
822 arch = bfd_arch_rs6000;
823 break;
824
825 default:
826 return false;
827 }
828
829 if (arch != info->arch)
830 return false;
831
832 if (number != info->mach)
833 return false;
834
835 return true;
836 }
837
838
839 /*
840 FUNCTION
841 bfd_get_arch_info
842
843 SYNOPSIS
844 const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
845
846 DESCRIPTION
847 Return the architecture info struct in @var{abfd}.
848 */
849
850 const bfd_arch_info_type *
851 bfd_get_arch_info (abfd)
852 bfd *abfd;
853 {
854 return abfd->arch_info;
855 }
856
857
858 /*
859 FUNCTION
860 bfd_lookup_arch
861
862 SYNOPSIS
863 const bfd_arch_info_type *bfd_lookup_arch
864 (enum bfd_architecture
865 arch,
866 unsigned long machine);
867
868 DESCRIPTION
869 Look for the architecure info structure which matches the
870 arguments @var{arch} and @var{machine}. A machine of 0 matches the
871 machine/architecture structure which marks itself as the
872 default.
873 */
874
875 const bfd_arch_info_type *
876 bfd_lookup_arch (arch, machine)
877 enum bfd_architecture arch;
878 unsigned long machine;
879 {
880 const bfd_arch_info_type * const *app, *ap;
881
882 for (app = bfd_archures_list; *app != NULL; app++)
883 {
884 for (ap = *app; ap != NULL; ap = ap->next)
885 {
886 if (ap->arch == arch
887 && (ap->mach == machine
888 || (machine == 0 && ap->the_default)))
889 return ap;
890 }
891 }
892
893 return NULL;
894 }
895
896
897 /*
898 FUNCTION
899 bfd_printable_arch_mach
900
901 SYNOPSIS
902 const char *bfd_printable_arch_mach
903 (enum bfd_architecture arch, unsigned long machine);
904
905 DESCRIPTION
906 Return a printable string representing the architecture and
907 machine type.
908
909 This routine is depreciated.
910 */
911
912 const char *
913 bfd_printable_arch_mach (arch, machine)
914 enum bfd_architecture arch;
915 unsigned long machine;
916 {
917 const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
918
919 if (ap)
920 return ap->printable_name;
921 return "UNKNOWN!";
922 }
This page took 0.052735 seconds and 4 git commands to generate.