Add support for parallel instructions.
[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 105. bfd_arch_mips, {* MIPS Rxxxx *}
cd66558c
NC
106.#define bfd_mach_mips3000 3000
107.#define bfd_mach_mips6000 6000
108.#define bfd_mach_mips4000 4000
109.#define bfd_mach_mips8000 8000
110.#define bfd_mach_mips16 16
111. {* start-sanitize-vr5400 *}
112.#define bfd_mach_vr5400 5400
113.#define bfd_mach_vr5000 5000
114. {* end-sanitize-vr5400 *}
9fda1a39 115. bfd_arch_i386, {* Intel 386 *}
9676e446
SG
116.#define bfd_mach_i386_i386 0
117.#define bfd_mach_i386_i8086 1
71c0bae0 118. bfd_arch_we32k, {* AT&T WE32xxx *}
9fda1a39
SC
119. bfd_arch_tahoe, {* CCI/Harris Tahoe *}
120. bfd_arch_i860, {* Intel 860 *}
121. bfd_arch_romp, {* IBM ROMP PC/RT *}
122. bfd_arch_alliant, {* Alliant *}
123. bfd_arch_convex, {* Convex *}
124. bfd_arch_m88k, {* Motorola 88xxx *}
125. bfd_arch_pyramid, {* Pyramid Technology *}
126. bfd_arch_h8300, {* Hitachi H8/300 *}
2e235c93
ILT
127.#define bfd_mach_h8300 1
128.#define bfd_mach_h8300h 2
34255b70 129.#define bfd_mach_h8300s 3
d94aca1a 130. bfd_arch_powerpc, {* PowerPC *}
9fda1a39 131. bfd_arch_rs6000, {* IBM RS/6000 *}
e3c01e92 132. bfd_arch_hppa, {* HP PA RISC *}
efc2b064 133. bfd_arch_d10v, {* Mitsubishi D10V *}
fd8d7c31
MH
134. {* start-sanitize-d30v *}
135. bfd_arch_d30v, {* Mitsubishi D30V *}
136. {* end-sanitize-d30v *}
71c0bae0
KR
137. bfd_arch_z8k, {* Zilog Z8000 *}
138.#define bfd_mach_z8001 1
139.#define bfd_mach_z8002 2
2e235c93
ILT
140. bfd_arch_h8500, {* Hitachi H8/500 *}
141. bfd_arch_sh, {* Hitachi SH *}
f40d28bf
AC
142.#define bfd_mach_sh 0
143.#define bfd_mach_sh3 0x30
144.#define bfd_mach_sh3e 0x3e
145. {* start-sanitize-sh4 *}
146.#define bfd_mach_sh4 0x40
147. {* end-sanitize-sh4 *}
2e235c93 148. bfd_arch_alpha, {* Dec Alpha *}
d94aca1a 149. bfd_arch_arm, {* Advanced Risc Machines ARM *}
76af94b9
DE
150.#define bfd_mach_arm_2 1
151.#define bfd_mach_arm_2a 2
152.#define bfd_mach_arm_3 3
153.#define bfd_mach_arm_3M 4
154.#define bfd_mach_arm_4 5
155.#define bfd_mach_arm_4T 6
d94aca1a 156. bfd_arch_ns32k, {* National Semiconductors ns32000 *}
b7577823 157. bfd_arch_w65, {* WDC 65816 *}
fd8d7c31
MH
158. {* start-sanitize-tic80 *}
159. bfd_arch_tic80, {* TI TMS320c80 (MVP) *}
160. {* end-sanitize-tic80 *}
20b2c808
DE
161. {* start-sanitize-sky *}
162. bfd_arch_txvu, {* TX VU *}
163.#define bfd_mach_txvu 0
164. {* end-sanitize-sky *}
efc2b064 165. bfd_arch_v850, {* NEC V850 *}
f40d28bf 166.#define bfd_mach_v850 0
8988d935 167. {* start-sanitize-v850e *}
f40d28bf 168.#define bfd_mach_v850e 'E'
cd66558c 169.#define bfd_mach_v850ea 'A'
8988d935 170. {* end-sanitize-v850e *}
37648010 171. bfd_arch_arc, {* Argonaut RISC Core *}
b7577823 172.#define bfd_mach_arc_base 0
76af94b9 173. bfd_arch_m32r, {* Mitsubishi M32R/D *}
2e0a5c10 174.#define bfd_mach_m32r 0 {* backwards compatibility *}
20b2c808 175. {* start-sanitize-m32rx *}
2e0a5c10 176.#define bfd_mach_m32rx 'x'
20b2c808 177. {* end-sanitize-m32rx *}
cd6213ff
FF
178. bfd_arch_mn10200, {* Matsushita MN10200 *}
179. bfd_arch_mn10300, {* Matsushita MN10300 *}
9fda1a39
SC
180. bfd_arch_last
181. };
c618de01 182
c618de01
SC
183
184*/
185
9fda1a39
SC
186/*
187
188SUBSECTION
189 bfd_arch_info
190
191DESCRIPTION
192 This structure contains information on architectures for use
193 within BFD.
194
9fda1a39
SC
195.
196.typedef struct bfd_arch_info
197.{
198. int bits_per_word;
199. int bits_per_address;
200. int bits_per_byte;
201. enum bfd_architecture arch;
ae115e51 202. unsigned long mach;
5bc513b4
DE
203. const char *arch_name;
204. const char *printable_name;
ce07dd7c
KR
205. unsigned int section_align_power;
206. {* true if this is the default machine for the architecture *}
9fda1a39 207. boolean the_default;
5bc513b4
DE
208. const struct bfd_arch_info * (*compatible)
209. PARAMS ((const struct bfd_arch_info *a,
210. const struct bfd_arch_info *b));
9fda1a39 211.
5bc513b4 212. boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
9fda1a39 213.
5bc513b4 214. const struct bfd_arch_info *next;
9fda1a39 215.} bfd_arch_info_type;
4e6f9223
SC
216*/
217
5bc513b4
DE
218extern const bfd_arch_info_type bfd_a29k_arch;
219extern const bfd_arch_info_type bfd_alpha_arch;
5bc513b4 220extern const bfd_arch_info_type bfd_arc_arch;
5bc513b4 221extern const bfd_arch_info_type bfd_arm_arch;
efc2b064 222extern const bfd_arch_info_type bfd_d10v_arch;
fd8d7c31
MH
223/* start-sanitize-d30v */
224extern const bfd_arch_info_type bfd_d30v_arch;
225/* end-sanitize-d30v */
5bc513b4
DE
226extern const bfd_arch_info_type bfd_h8300_arch;
227extern const bfd_arch_info_type bfd_h8500_arch;
228extern const bfd_arch_info_type bfd_hppa_arch;
229extern const bfd_arch_info_type bfd_i386_arch;
230extern const bfd_arch_info_type bfd_i860_arch;
231extern const bfd_arch_info_type bfd_i960_arch;
efc2b064 232extern const bfd_arch_info_type bfd_m32r_arch;
5bc513b4
DE
233extern const bfd_arch_info_type bfd_m68k_arch;
234extern const bfd_arch_info_type bfd_m88k_arch;
235extern const bfd_arch_info_type bfd_mips_arch;
cd6213ff
FF
236extern const bfd_arch_info_type bfd_mn10200_arch;
237extern const bfd_arch_info_type bfd_mn10300_arch;
5bc513b4
DE
238extern const bfd_arch_info_type bfd_powerpc_arch;
239extern const bfd_arch_info_type bfd_rs6000_arch;
240extern const bfd_arch_info_type bfd_sh_arch;
5bc513b4 241extern const bfd_arch_info_type bfd_sparc_arch;
cd6213ff
FF
242/* start-sanitize-tic80 */
243extern const bfd_arch_info_type bfd_tic80_arch;
244/* end-sanitize-tic80 */
20b2c808
DE
245/* start-sanitize-sky */
246extern const bfd_arch_info_type bfd_txvu_arch;
247/* end-sanitize-sky */
5bc513b4
DE
248extern const bfd_arch_info_type bfd_vax_arch;
249extern const bfd_arch_info_type bfd_we32k_arch;
250extern const bfd_arch_info_type bfd_z8k_arch;
251extern const bfd_arch_info_type bfd_ns32k_arch;
252extern const bfd_arch_info_type bfd_w65_arch;
efc2b064 253extern const bfd_arch_info_type bfd_v850_arch;
5bc513b4
DE
254
255static const bfd_arch_info_type * const bfd_archures_list[] =
256{
257#ifdef SELECT_ARCHITECTURES
258 SELECT_ARCHITECTURES,
259#else
260 &bfd_a29k_arch,
261 &bfd_alpha_arch,
5bc513b4 262 &bfd_arc_arch,
5bc513b4 263 &bfd_arm_arch,
efc2b064 264 &bfd_d10v_arch,
fd8d7c31
MH
265/* start-sanitize-d30v */
266 &bfd_d30v_arch,
267/* end-sanitize-d30v */
5bc513b4
DE
268 &bfd_h8300_arch,
269 &bfd_h8500_arch,
270 &bfd_hppa_arch,
271 &bfd_i386_arch,
272 &bfd_i860_arch,
273 &bfd_i960_arch,
efc2b064 274 &bfd_m32r_arch,
5bc513b4
DE
275 &bfd_m68k_arch,
276 &bfd_m88k_arch,
277 &bfd_mips_arch,
cd6213ff
FF
278 &bfd_mn10200_arch,
279 &bfd_mn10300_arch,
5bc513b4
DE
280 &bfd_powerpc_arch,
281 &bfd_rs6000_arch,
282 &bfd_sh_arch,
5bc513b4 283 &bfd_sparc_arch,
fd8d7c31
MH
284/* start-sanitize-tic80 */
285 &bfd_tic80_arch,
286/* end-sanitize-tic80 */
20b2c808
DE
287/* start-sanitize-sky */
288 &bfd_txvu_arch,
289/* end-sanitize-sky */
5bc513b4
DE
290 &bfd_vax_arch,
291 &bfd_we32k_arch,
292 &bfd_z8k_arch,
293 &bfd_ns32k_arch,
294 &bfd_w65_arch,
efc2b064 295 &bfd_v850_arch,
8988d935 296#endif
2f88c324 297 0
5bc513b4 298};
4a81b561 299
9fda1a39 300/*
9fda1a39
SC
301FUNCTION
302 bfd_printable_name
4e6f9223 303
ce07dd7c 304SYNOPSIS
5bc513b4 305 const char *bfd_printable_name(bfd *abfd);
ce07dd7c 306
9fda1a39
SC
307DESCRIPTION
308 Return a printable string representing the architecture and machine
c188b0be 309 from the pointer to the architecture info structure.
4e6f9223 310
4e6f9223
SC
311*/
312
5bc513b4 313const char *
d94aca1a
MT
314bfd_printable_name (abfd)
315 bfd *abfd;
4e6f9223
SC
316{
317 return abfd->arch_info->printable_name;
4a81b561
DHW
318}
319
4e6f9223
SC
320
321
9fda1a39
SC
322/*
323FUNCTION
324 bfd_scan_arch
4e6f9223 325
ce07dd7c 326SYNOPSIS
5bc513b4 327 const bfd_arch_info_type *bfd_scan_arch(const char *string);
ce07dd7c 328
9fda1a39 329DESCRIPTION
c188b0be
DM
330 Figure out if BFD supports any cpu which could be described with
331 the name @var{string}. Return a pointer to an <<arch_info>>
9fda1a39
SC
332 structure if a machine is found, otherwise NULL.
333
c618de01 334*/
4a81b561 335
5bc513b4 336const bfd_arch_info_type *
d94aca1a 337bfd_scan_arch (string)
5bc513b4 338 const char *string;
4a81b561 339{
5bc513b4 340 const bfd_arch_info_type * const *app, *ap;
4e6f9223
SC
341
342 /* Look through all the installed architectures */
5bc513b4
DE
343 for (app = bfd_archures_list; *app != NULL; app++)
344 {
345 for (ap = *app; ap != NULL; ap = ap->next)
346 {
347 if (ap->scan (ap, string))
348 return ap;
349 }
350 }
351
352 return NULL;
4e6f9223
SC
353}
354
4a81b561 355
4a81b561 356
eaa9c2e7
AC
357/*
358FUNCTION
359 bfd_arch_list
360
361SYNOPSIS
362 const char **bfd_arch_list(void);
363
364DESCRIPTION
365 Return a freshly malloced NULL-terminated vector of the names
366 of all the valid BFD architectures. Do not modify the names.
367
368*/
369
370const char **
371bfd_arch_list ()
372{
373 int vec_length = 0;
374 const char **name_ptr;
375 const char **name_list;
376 const bfd_arch_info_type * const *app;
377
378 /* Determine the number of architectures */
379 vec_length = 0;
380 for (app = bfd_archures_list; *app != NULL; app++)
381 {
382 const bfd_arch_info_type *ap;
383 for (ap = *app; ap != NULL; ap = ap->next)
384 {
385 vec_length++;
386 }
387 }
388
389 name_list = (CONST char **)
390 bfd_malloc ((vec_length + 1) * sizeof (char **));
391 if (name_list == NULL)
392 return NULL;
393
394 /* Point the list at each of the names */
395 name_ptr = name_list;
396 for (app = bfd_archures_list; *app != NULL; app++)
397 {
398 const bfd_arch_info_type *ap;
399 for (ap = *app; ap != NULL; ap = ap->next)
400 {
401 *name_ptr = ap->printable_name;
402 name_ptr++;
403 }
404 }
405 *name_ptr = NULL;
406
407 return name_list;
408}
409
410
411
9fda1a39
SC
412/*
413FUNCTION
414 bfd_arch_get_compatible
415
ce07dd7c 416SYNOPSIS
5bc513b4
DE
417 const bfd_arch_info_type *bfd_arch_get_compatible(
418 const bfd *abfd,
419 const bfd *bbfd);
4e6f9223 420
ce07dd7c 421DESCRIPTION
c188b0be
DM
422 Determine whether two BFDs'
423 architectures and machine types are compatible. Calculates
9fda1a39
SC
424 the lowest common denominator between the two architectures
425 and machine types implied by the BFDs and returns a pointer to
c188b0be 426 an <<arch_info>> structure describing the compatible machine.
4e6f9223
SC
427*/
428
5bc513b4 429const bfd_arch_info_type *
d94aca1a 430bfd_arch_get_compatible (abfd, bbfd)
5bc513b4
DE
431 const bfd *abfd;
432 const bfd *bbfd;
4e6f9223 433{
b7577823
ILT
434 /* If either architecture is unknown, then all we can do is assume
435 the user knows what he's doing. */
436 if (abfd->arch_info->arch == bfd_arch_unknown)
437 return bbfd->arch_info;
438 if (bbfd->arch_info->arch == bfd_arch_unknown)
439 return abfd->arch_info;
440
441 /* Otherwise architecture-specific code has to decide. */
5bc513b4 442 return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
4a81b561
DHW
443}
444
4e6f9223 445
9fda1a39 446/*
ce07dd7c 447INTERNAL_DEFINITION
9fda1a39 448 bfd_default_arch_struct
4e6f9223 449
9fda1a39 450DESCRIPTION
ce07dd7c
KR
451 The <<bfd_default_arch_struct>> is an item of
452 <<bfd_arch_info_type>> which has been initialized to a fairly
453 generic state. A BFD starts life by pointing to this
454 structure, until the correct back end has determined the real
455 architecture of the file.
9fda1a39 456
5bc513b4 457.extern const bfd_arch_info_type bfd_default_arch_struct;
4e6f9223 458
4e6f9223
SC
459*/
460
5bc513b4 461const bfd_arch_info_type bfd_default_arch_struct =
9fda1a39 462{
2e235c93 463 32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
9fda1a39
SC
464 bfd_default_compatible,
465 bfd_default_scan,
466 0,
9fda1a39 467};
4e6f9223 468
9fda1a39
SC
469/*
470FUNCTION
471 bfd_set_arch_info
4e6f9223 472
9fda1a39 473SYNOPSIS
5bc513b4 474 void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
4e6f9223 475
c188b0be
DM
476DESCRIPTION
477 Set the architecture info of @var{abfd} to @var{arg}.
4e6f9223
SC
478*/
479
d94aca1a
MT
480void
481bfd_set_arch_info (abfd, arg)
482 bfd *abfd;
5bc513b4 483 const bfd_arch_info_type *arg;
4a81b561 484{
4e6f9223
SC
485 abfd->arch_info = arg;
486}
487
9fda1a39 488/*
ce07dd7c 489INTERNAL_FUNCTION
9fda1a39
SC
490 bfd_default_set_arch_mach
491
9fda1a39
SC
492SYNOPSIS
493 boolean bfd_default_set_arch_mach(bfd *abfd,
494 enum bfd_architecture arch,
495 unsigned long mach);
4e6f9223 496
ce07dd7c 497DESCRIPTION
c188b0be
DM
498 Set the architecture and machine type in BFD @var{abfd}
499 to @var{arch} and @var{mach}. Find the correct
500 pointer to a structure and insert it into the <<arch_info>>
ce07dd7c 501 pointer.
4e6f9223
SC
502*/
503
d94aca1a
MT
504boolean
505bfd_default_set_arch_mach (abfd, arch, mach)
506 bfd *abfd;
507 enum bfd_architecture arch;
5bc513b4 508 unsigned long mach;
4e6f9223 509{
5bc513b4 510 const bfd_arch_info_type * const *app, *ap;
4a81b561 511
5bc513b4
DE
512 for (app = bfd_archures_list; *app != NULL; app++)
513 {
514 for (ap = *app; ap != NULL; ap = ap->next)
515 {
516 if (ap->arch == arch
517 && (ap->mach == mach
518 || (mach == 0 && ap->the_default)))
519 {
520 abfd->arch_info = ap;
521 return true;
522 }
523 }
524 }
4e6f9223 525
5bc513b4
DE
526 abfd->arch_info = &bfd_default_arch_struct;
527 bfd_set_error (bfd_error_bad_value);
528 return false;
4a81b561 529}
4a81b561 530
4e6f9223 531
9fda1a39
SC
532/*
533FUNCTION
534 bfd_get_arch
4e6f9223 535
ce07dd7c
KR
536SYNOPSIS
537 enum bfd_architecture bfd_get_arch(bfd *abfd);
538
9fda1a39 539DESCRIPTION
c188b0be
DM
540 Return the enumerated type which describes the BFD @var{abfd}'s
541 architecture.
4e6f9223 542
4e6f9223
SC
543*/
544
d94aca1a
MT
545enum bfd_architecture
546bfd_get_arch (abfd)
547 bfd *abfd;
9fda1a39 548{
4e6f9223 549 return abfd->arch_info->arch;
9fda1a39 550}
4e6f9223 551
9fda1a39
SC
552/*
553FUNCTION
554 bfd_get_mach
4e6f9223 555
ce07dd7c
KR
556SYNOPSIS
557 unsigned long bfd_get_mach(bfd *abfd);
558
9fda1a39 559DESCRIPTION
c188b0be
DM
560 Return the long type which describes the BFD @var{abfd}'s
561 machine.
4e6f9223
SC
562*/
563
9fda1a39 564unsigned long
d94aca1a
MT
565bfd_get_mach (abfd)
566 bfd *abfd;
4a81b561 567{
4e6f9223 568 return abfd->arch_info->mach;
9fda1a39 569}
4e6f9223 570
9fda1a39
SC
571/*
572FUNCTION
573 bfd_arch_bits_per_byte
4e6f9223 574
ce07dd7c
KR
575SYNOPSIS
576 unsigned int bfd_arch_bits_per_byte(bfd *abfd);
577
9fda1a39 578DESCRIPTION
c188b0be
DM
579 Return the number of bits in one of the BFD @var{abfd}'s
580 architecture's bytes.
4e6f9223 581
4e6f9223
SC
582*/
583
d94aca1a
MT
584unsigned int
585bfd_arch_bits_per_byte (abfd)
586 bfd *abfd;
c188b0be
DM
587{
588 return abfd->arch_info->bits_per_byte;
589}
4e6f9223 590
9fda1a39
SC
591/*
592FUNCTION
593 bfd_arch_bits_per_address
4e6f9223 594
9fda1a39
SC
595SYNOPSIS
596 unsigned int bfd_arch_bits_per_address(bfd *abfd);
ce07dd7c
KR
597
598DESCRIPTION
c188b0be
DM
599 Return the number of bits in one of the BFD @var{abfd}'s
600 architecture's addresses.
4e6f9223
SC
601*/
602
d94aca1a
MT
603unsigned int
604bfd_arch_bits_per_address (abfd)
605 bfd *abfd;
c188b0be
DM
606{
607 return abfd->arch_info->bits_per_address;
608}
4e6f9223
SC
609
610
9fda1a39 611/*
ce07dd7c 612INTERNAL_FUNCTION
9fda1a39 613 bfd_default_compatible
4e6f9223 614
9fda1a39 615SYNOPSIS
5bc513b4
DE
616 const bfd_arch_info_type *bfd_default_compatible
617 (const bfd_arch_info_type *a,
618 const bfd_arch_info_type *b);
ce07dd7c
KR
619
620DESCRIPTION
621 The default function for testing for compatibility.
4e6f9223
SC
622*/
623
5bc513b4 624const bfd_arch_info_type *
d94aca1a 625bfd_default_compatible (a,b)
5bc513b4
DE
626 const bfd_arch_info_type *a;
627 const bfd_arch_info_type *b;
4e6f9223 628{
5bc513b4
DE
629 if (a->arch != b->arch)
630 return NULL;
4e6f9223 631
5bc513b4 632 if (a->mach > b->mach)
4e6f9223 633 return a;
5bc513b4
DE
634
635 if (b->mach > a->mach)
4e6f9223 636 return b;
5bc513b4 637
4e6f9223 638 return a;
4a81b561
DHW
639}
640
641
9fda1a39 642/*
ce07dd7c 643INTERNAL_FUNCTION
9fda1a39
SC
644 bfd_default_scan
645
9fda1a39 646SYNOPSIS
5bc513b4 647 boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
4e6f9223 648
ce07dd7c
KR
649DESCRIPTION
650 The default function for working out whether this is an
651 architecture hit and a machine hit.
4e6f9223
SC
652*/
653
654boolean
d94aca1a 655bfd_default_scan (info, string)
5bc513b4
DE
656 const struct bfd_arch_info *info;
657 const char *string;
4a81b561 658{
5bc513b4
DE
659 const char *ptr_src;
660 const char *ptr_tst;
b7577823
ILT
661 unsigned long number;
662 enum bfd_architecture arch;
eaa9c2e7
AC
663 const char *printable_name_colon;
664
665 /* Exact match of the architecture name (ARCH_NAME) and also the
666 default architecture? */
667 if (strcasecmp (string, info->arch_name) == 0
668 && info->the_default)
669 return true;
5bc513b4 670
eaa9c2e7
AC
671 /* Exact match of the machine name (PRINTABLE_NAME)? */
672 if (strcasecmp (string, info->printable_name) == 0)
5bc513b4 673 return true;
eaa9c2e7
AC
674
675 /* Given that printable_name contains no colon, attempt to match:
676 ARCH_NAME [ ":" ] PRINTABLE_NAME? */
677 printable_name_colon = strchr (info->printable_name, ':');
678 if (printable_name_colon == NULL)
679 {
680 int strlen_arch_name = strlen (info->arch_name);
681 if (strncasecmp (string, info->arch_name, strlen_arch_name) == 0)
682 if (string[strlen_arch_name] == ':')
683 {
684 if (strcasecmp (string + strlen_arch_name + 1,
685 info->printable_name) == 0)
686 return true;
687 }
688 else
689 {
690 if (strcasecmp (string + strlen_arch_name,
691 info->printable_name) == 0)
692 return true;
693 }
694 }
695
696 /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>;
697 Attempt to match: <arch> <mach>? */
698 if (printable_name_colon != NULL)
699 {
700 int colon_index = printable_name_colon - info->printable_name;
701 if (strncasecmp (string, info->printable_name, colon_index) == 0
702 && strcasecmp (string + colon_index,
703 info->printable_name + colon_index + 1) == 0)
704 return true;
705 }
706
707 /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>; Do not
708 attempt to match just <mach>, it could be ambigious. This test
709 is left until later. */
710
711 /* NOTE: The below is retained for compatibility only. Please do not
712 add to this code */
b7577823
ILT
713
714 /* See how much of the supplied string matches with the
715 architecture, eg the string m68k:68020 would match the 68k entry
716 up to the :, then we get left with the machine number */
717
5bc513b4 718 for (ptr_src = string, ptr_tst = info->arch_name;
b7577823 719 *ptr_src && *ptr_tst;
5bc513b4 720 ptr_src++, ptr_tst++)
9fda1a39 721 {
b7577823 722 if (*ptr_src != *ptr_tst) break;
9fda1a39 723 }
4e6f9223 724
b7577823
ILT
725 /* Chewed up as much of the architecture as will match, skip any
726 colons */
5bc513b4
DE
727 if (*ptr_src == ':')
728 ptr_src++;
4e6f9223 729
5bc513b4
DE
730 if (*ptr_src == 0)
731 {
732 /* nothing more, then only keep this one if it is the default
733 machine for this architecture */
734 return info->the_default;
735 }
736
b7577823 737 number = 0;
5bc513b4
DE
738 while (isdigit(*ptr_src))
739 {
740 number = number * 10 + *ptr_src - '0';
741 ptr_src++;
742 }
b7577823 743
cd66558c
NC
744 /* NOTE: The below is retained for compatibility only.
745 PLEASE DO NOT ADD TO THIS CODE. */
eaa9c2e7 746
b7577823 747 switch (number)
9fda1a39 748 {
b7577823
ILT
749 case 68010:
750 case 68020:
751 case 68030:
752 case 68040:
753 case 68332:
754 case 68050:
755 case 68000:
756 arch = bfd_arch_m68k;
757 break;
5bc513b4 758
b7577823
ILT
759 case 32000:
760 arch = bfd_arch_we32k;
761 break;
4e6f9223 762
b7577823 763 case 3000:
cd66558c
NC
764 arch = bfd_arch_mips;
765 number = bfd_mach_mips3000;
766 break;
767
b7577823 768 case 4000:
b7577823 769 arch = bfd_arch_mips;
cd66558c 770 number = bfd_mach_mips4000;
b7577823 771 break;
4a81b561 772
b7577823
ILT
773 case 6000:
774 arch = bfd_arch_rs6000;
775 break;
9fda1a39 776
b7577823
ILT
777 default:
778 return false;
9fda1a39 779 }
5bc513b4 780
b7577823
ILT
781 if (arch != info->arch)
782 return false;
9fda1a39 783
b7577823
ILT
784 if (number != info->mach)
785 return false;
9fda1a39 786
b7577823 787 return true;
4a81b561 788}
c618de01
SC
789
790
9fda1a39
SC
791/*
792FUNCTION
793 bfd_get_arch_info
c618de01 794
9fda1a39 795SYNOPSIS
5bc513b4 796 const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
c618de01 797
c188b0be
DM
798DESCRIPTION
799 Return the architecture info struct in @var{abfd}.
4e6f9223 800*/
c618de01 801
5bc513b4 802const bfd_arch_info_type *
d94aca1a
MT
803bfd_get_arch_info (abfd)
804 bfd *abfd;
4e6f9223 805{
5bc513b4 806 return abfd->arch_info;
4e6f9223 807}
cbdc7909
JG
808
809
9fda1a39
SC
810/*
811FUNCTION
812 bfd_lookup_arch
813
9fda1a39 814SYNOPSIS
5bc513b4 815 const bfd_arch_info_type *bfd_lookup_arch
9fda1a39
SC
816 (enum bfd_architecture
817 arch,
ae115e51 818 unsigned long machine);
cbdc7909 819
ce07dd7c 820DESCRIPTION
c188b0be
DM
821 Look for the architecure info structure which matches the
822 arguments @var{arch} and @var{machine}. A machine of 0 matches the
ce07dd7c
KR
823 machine/architecture structure which marks itself as the
824 default.
cbdc7909
JG
825*/
826
5bc513b4 827const bfd_arch_info_type *
d94aca1a
MT
828bfd_lookup_arch (arch, machine)
829 enum bfd_architecture arch;
ae115e51 830 unsigned long machine;
cbdc7909 831{
5bc513b4
DE
832 const bfd_arch_info_type * const *app, *ap;
833
834 for (app = bfd_archures_list; *app != NULL; app++)
835 {
836 for (ap = *app; ap != NULL; ap = ap->next)
837 {
838 if (ap->arch == arch
839 && (ap->mach == machine
840 || (machine == 0 && ap->the_default)))
841 return ap;
9fda1a39 842 }
5bc513b4
DE
843 }
844
845 return NULL;
cbdc7909
JG
846}
847
848
9fda1a39
SC
849/*
850FUNCTION
851 bfd_printable_arch_mach
852
ce07dd7c 853SYNOPSIS
5bc513b4 854 const char *bfd_printable_arch_mach
ce07dd7c
KR
855 (enum bfd_architecture arch, unsigned long machine);
856
9fda1a39
SC
857DESCRIPTION
858 Return a printable string representing the architecture and
859 machine type.
cbdc7909 860
c188b0be 861 This routine is depreciated.
cbdc7909
JG
862*/
863
5bc513b4 864const char *
d94aca1a
MT
865bfd_printable_arch_mach (arch, machine)
866 enum bfd_architecture arch;
867 unsigned long machine;
cbdc7909 868{
5bc513b4
DE
869 const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
870
871 if (ap)
872 return ap->printable_name;
9fda1a39 873 return "UNKNOWN!";
cbdc7909 874}
This page took 0.258384 seconds and 4 git commands to generate.