OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [bfd/] [archures.c] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* BFD library support routines for architectures.
2
   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3
   2000, 2001
4
   Free Software Foundation, Inc.
5
   Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
6
 
7
This file is part of BFD, the Binary File Descriptor library.
8
 
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
13
 
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
GNU General Public License for more details.
18
 
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
22
 
23
#include "bfd.h"
24
#include "sysdep.h"
25
#include "libbfd.h"
26
#include <ctype.h>
27
 
28
/*
29
 
30
SECTION
31
        Architectures
32
 
33
        BFD keeps one atom in a BFD describing the
34
        architecture of the data attached to the BFD: a pointer to a
35
        <<bfd_arch_info_type>>.
36
 
37
        Pointers to structures can be requested independently of a BFD
38
        so that an architecture's information can be interrogated
39
        without access to an open BFD.
40
 
41
        The architecture information is provided by each architecture package.
42
        The set of default architectures is selected by the macro
43
        <<SELECT_ARCHITECTURES>>.  This is normally set up in the
44
        @file{config/@var{target}.mt} file of your choice.  If the name is not
45
        defined, then all the architectures supported are included.
46
 
47
        When BFD starts up, all the architectures are called with an
48
        initialize method.  It is up to the architecture back end to
49
        insert as many items into the list of architectures as it wants to;
50
        generally this would be one for each machine and one for the
51
        default case (an item with a machine field of 0).
52
 
53
        BFD's idea of an architecture is implemented in @file{archures.c}.
54
*/
55
 
56
/*
57
 
58
SUBSECTION
59
        bfd_architecture
60
 
61
DESCRIPTION
62
        This enum gives the object file's CPU architecture, in a
63
        global sense---i.e., what processor family does it belong to?
64
        Another field indicates which processor within
65
        the family is in use.  The machine gives a number which
66
        distinguishes different versions of the architecture,
67
        containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
68
        and 68020 and 68030 for Motorola 68020 and 68030.
69
 
70
.enum bfd_architecture
71
.{
72
.  bfd_arch_unknown,   {* File arch not known *}
73
.  bfd_arch_obscure,   {* Arch known, not one of these *}
74
.  bfd_arch_m68k,      {* Motorola 68xxx *}
75
.#define bfd_mach_m68000 1
76
.#define bfd_mach_m68008 2
77
.#define bfd_mach_m68010 3
78
.#define bfd_mach_m68020 4
79
.#define bfd_mach_m68030 5
80
.#define bfd_mach_m68040 6
81
.#define bfd_mach_m68060 7
82
.#define bfd_mach_cpu32  8
83
.#define bfd_mach_mcf5200  9
84
.#define bfd_mach_mcf5206e 10
85
.#define bfd_mach_mcf5307  11
86
.#define bfd_mach_mcf5407  12
87
.  bfd_arch_vax,       {* DEC Vax *}
88
.  bfd_arch_i960,      {* Intel 960 *}
89
.    {* The order of the following is important.
90
.       lower number indicates a machine type that
91
.       only accepts a subset of the instructions
92
.       available to machines with higher numbers.
93
.       The exception is the "ca", which is
94
.       incompatible with all other machines except
95
.       "core". *}
96
.
97
.#define bfd_mach_i960_core      1
98
.#define bfd_mach_i960_ka_sa     2
99
.#define bfd_mach_i960_kb_sb     3
100
.#define bfd_mach_i960_mc        4
101
.#define bfd_mach_i960_xa        5
102
.#define bfd_mach_i960_ca        6
103
.#define bfd_mach_i960_jx        7
104
.#define bfd_mach_i960_hx        8
105
.
106
.  bfd_arch_a29k,      {* AMD 29000 *}
107
.  bfd_arch_sparc,     {* SPARC *}
108
.#define bfd_mach_sparc                 1
109
.{* The difference between v8plus and v9 is that v9 is a true 64 bit env.  *}
110
.#define bfd_mach_sparc_sparclet        2
111
.#define bfd_mach_sparc_sparclite       3
112
.#define bfd_mach_sparc_v8plus          4
113
.#define bfd_mach_sparc_v8plusa         5 {* with ultrasparc add'ns *}
114
.#define bfd_mach_sparc_sparclite_le    6
115
.#define bfd_mach_sparc_v9              7
116
.#define bfd_mach_sparc_v9a             8 {* with ultrasparc add'ns *}
117
.#define bfd_mach_sparc_v8plusb         9 {* with cheetah add'ns *}
118
.#define bfd_mach_sparc_v9b             10 {* with cheetah add'ns *}
119
.{* Nonzero if MACH has the v9 instruction set.  *}
120
.#define bfd_mach_sparc_v9_p(mach) \
121
.  ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9b \
122
.   && (mach) != bfd_mach_sparc_sparclite_le)
123
.  bfd_arch_mips,      {* MIPS Rxxxx *}
124
.#define bfd_mach_mips3000              3000
125
.#define bfd_mach_mips3900              3900
126
.#define bfd_mach_mips4000              4000
127
.#define bfd_mach_mips4010              4010
128
.#define bfd_mach_mips4100              4100
129
.#define bfd_mach_mips4111              4111
130
.#define bfd_mach_mips4300              4300
131
.#define bfd_mach_mips4400              4400
132
.#define bfd_mach_mips4600              4600
133
.#define bfd_mach_mips4650              4650
134
.#define bfd_mach_mips5000              5000
135
.#define bfd_mach_mips6000              6000
136
.#define bfd_mach_mips8000              8000
137
.#define bfd_mach_mips10000             10000
138
.#define bfd_mach_mips12000             12000
139
.#define bfd_mach_mips16                16
140
.#define bfd_mach_mips32                32
141
.#define bfd_mach_mips32_4k             3204113 {* 32, 04, octal 'K' *}
142
.#define bfd_mach_mips5                 5
143
.#define bfd_mach_mips64                64
144
.#define bfd_mach_mips_sb1              12310201 {* octal 'SB', 01 *}
145
.  bfd_arch_i386,      {* Intel 386 *}
146
.#define bfd_mach_i386_i386 0
147
.#define bfd_mach_i386_i8086 1
148
.#define bfd_mach_i386_i386_intel_syntax 2
149
.#define bfd_mach_x86_64 3
150
.#define bfd_mach_x86_64_intel_syntax 4
151
.  bfd_arch_we32k,     {* AT&T WE32xxx *}
152
.  bfd_arch_tahoe,     {* CCI/Harris Tahoe *}
153
.  bfd_arch_i860,      {* Intel 860 *}
154
.  bfd_arch_i370,      {* IBM 360/370 Mainframes *}
155
.  bfd_arch_romp,      {* IBM ROMP PC/RT *}
156
.  bfd_arch_alliant,   {* Alliant *}
157
.  bfd_arch_convex,    {* Convex *}
158
.  bfd_arch_m88k,      {* Motorola 88xxx *}
159
.  bfd_arch_pyramid,   {* Pyramid Technology *}
160
.  bfd_arch_h8300,     {* Hitachi H8/300 *}
161
.#define bfd_mach_h8300   1
162
.#define bfd_mach_h8300h  2
163
.#define bfd_mach_h8300s  3
164
.  bfd_arch_pdp11,     {* DEC PDP-11 *}
165
.  bfd_arch_powerpc,   {* PowerPC *}
166
.#define bfd_mach_ppc           0
167
.#define bfd_mach_ppc_403       403
168
.#define bfd_mach_ppc_403gc     4030
169
.#define bfd_mach_ppc_505       505
170
.#define bfd_mach_ppc_601       601
171
.#define bfd_mach_ppc_602       602
172
.#define bfd_mach_ppc_603       603
173
.#define bfd_mach_ppc_ec603e    6031
174
.#define bfd_mach_ppc_604       604
175
.#define bfd_mach_ppc_620       620
176
.#define bfd_mach_ppc_630       630
177
.#define bfd_mach_ppc_750       750
178
.#define bfd_mach_ppc_860       860
179
.#define bfd_mach_ppc_a35       35
180
.#define bfd_mach_ppc_rs64ii    642
181
.#define bfd_mach_ppc_rs64iii   643
182
.#define bfd_mach_ppc_7400      7400
183
.  bfd_arch_rs6000,    {* IBM RS/6000 *}
184
.#define bfd_mach_rs6k          0
185
.#define bfd_mach_rs6k_rs1      6001
186
.#define bfd_mach_rs6k_rsc      6003
187
.#define bfd_mach_rs6k_rs2      6002
188
.  bfd_arch_hppa,      {* HP PA RISC *}
189
.  bfd_arch_d10v,      {* Mitsubishi D10V *}
190
.#define bfd_mach_d10v          0
191
.#define bfd_mach_d10v_ts2      2
192
.#define bfd_mach_d10v_ts3      3
193
.  bfd_arch_d30v,      {* Mitsubishi D30V *}
194
.  bfd_arch_m68hc11,   {* Motorola 68HC11 *}
195
.  bfd_arch_m68hc12,   {* Motorola 68HC12 *}
196
.  bfd_arch_z8k,       {* Zilog Z8000 *}
197
.#define bfd_mach_z8001         1
198
.#define bfd_mach_z8002         2
199
.  bfd_arch_h8500,     {* Hitachi H8/500 *}
200
.  bfd_arch_sh,        {* Hitachi SH *}
201
.#define bfd_mach_sh            0
202
.#define bfd_mach_sh2        0x20
203
.#define bfd_mach_sh_dsp     0x2d
204
.#define bfd_mach_sh3        0x30
205
.#define bfd_mach_sh3_dsp    0x3d
206
.#define bfd_mach_sh3e       0x3e
207
.#define bfd_mach_sh4        0x40
208
.  bfd_arch_alpha,     {* Dec Alpha *}
209
.#define bfd_mach_alpha_ev4  0x10
210
.#define bfd_mach_alpha_ev5  0x20
211
.#define bfd_mach_alpha_ev6  0x30
212
.  bfd_arch_arm,       {* Advanced Risc Machines ARM *}
213
.#define bfd_mach_arm_2         1
214
.#define bfd_mach_arm_2a        2
215
.#define bfd_mach_arm_3         3
216
.#define bfd_mach_arm_3M        4
217
.#define bfd_mach_arm_4         5
218
.#define bfd_mach_arm_4T        6
219
.#define bfd_mach_arm_5         7
220
.#define bfd_mach_arm_5T        8
221
.#define bfd_mach_arm_5TE       9
222
.#define bfd_mach_arm_XScale    10
223
.  bfd_arch_ns32k,     {* National Semiconductors ns32000 *}
224
.  bfd_arch_w65,       {* WDC 65816 *}
225
.  bfd_arch_tic30,     {* Texas Instruments TMS320C30 *}
226
.  bfd_arch_tic54x,    {* Texas Instruments TMS320C54X *}
227
.  bfd_arch_tic80,     {* TI TMS320c80 (MVP) *}
228
.  bfd_arch_v850,      {* NEC V850 *}
229
.#define bfd_mach_v850          0
230
.#define bfd_mach_v850e         'E'
231
.#define bfd_mach_v850ea        'A'
232
.  bfd_arch_arc,       {* ARC Cores *}
233
.#define bfd_mach_arc_5         0
234
.#define bfd_mach_arc_6         1
235
.#define bfd_mach_arc_7         2
236
.#define bfd_mach_arc_8         3
237
.  bfd_arch_m32r,      {* Mitsubishi M32R/D *}
238
.#define bfd_mach_m32r          0 {* backwards compatibility *}
239
.#define bfd_mach_m32rx         'x'
240
.  bfd_arch_mn10200,   {* Matsushita MN10200 *}
241
.  bfd_arch_mn10300,   {* Matsushita MN10300 *}
242
.#define bfd_mach_mn10300               300
243
.#define bfd_mach_am33          330
244
.  bfd_arch_fr30,
245
.#define bfd_mach_fr30          0x46523330
246
.  bfd_arch_mcore,
247
.  bfd_arch_ia64,      {* HP/Intel ia64 *}
248
.#define bfd_mach_ia64_elf64    0
249
.#define bfd_mach_ia64_elf32    1
250
.  bfd_arch_pj,
251
.  bfd_arch_avr,       {* Atmel AVR microcontrollers *}
252
.#define bfd_mach_avr1          1
253
.#define bfd_mach_avr2          2
254
.#define bfd_mach_avr3          3
255
.#define bfd_mach_avr4          4
256
.#define bfd_mach_avr5          5
257
.  bfd_arch_cris,      {* Axis CRIS *}
258
.  bfd_arch_s390,      {* IBM s390 *}
259
.#define bfd_mach_s390_esa      0
260
.#define bfd_mach_s390_esame    1
261
.  bfd_arch_openrisc,  {* OpenRISC *}
262
.  bfd_arch_last
263
.  };
264
*/
265
 
266
/*
267
SUBSECTION
268
        bfd_arch_info
269
 
270
DESCRIPTION
271
        This structure contains information on architectures for use
272
        within BFD.
273
 
274
.
275
.typedef struct bfd_arch_info
276
.{
277
.  int bits_per_word;
278
.  int bits_per_address;
279
.  int bits_per_byte;
280
.  enum bfd_architecture arch;
281
.  unsigned long mach;
282
.  const char *arch_name;
283
.  const char *printable_name;
284
.  unsigned int section_align_power;
285
.  {* True if this is the default machine for the architecture.  *}
286
.  boolean the_default;
287
.  const struct bfd_arch_info * (*compatible)
288
.       PARAMS ((const struct bfd_arch_info *a,
289
.                const struct bfd_arch_info *b));
290
.
291
.  boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
292
.
293
.  const struct bfd_arch_info *next;
294
.} bfd_arch_info_type;
295
*/
296
 
297
extern const bfd_arch_info_type bfd_or32_arch;
298
extern const bfd_arch_info_type bfd_a29k_arch;
299
extern const bfd_arch_info_type bfd_alpha_arch;
300
extern const bfd_arch_info_type bfd_arc_arch;
301
extern const bfd_arch_info_type bfd_arm_arch;
302
extern const bfd_arch_info_type bfd_cris_arch;
303
extern const bfd_arch_info_type bfd_d10v_arch;
304
extern const bfd_arch_info_type bfd_d30v_arch;
305
extern const bfd_arch_info_type bfd_h8300_arch;
306
extern const bfd_arch_info_type bfd_h8500_arch;
307
extern const bfd_arch_info_type bfd_hppa_arch;
308
extern const bfd_arch_info_type bfd_i370_arch;
309
extern const bfd_arch_info_type bfd_i386_arch;
310
extern const bfd_arch_info_type bfd_i860_arch;
311
extern const bfd_arch_info_type bfd_i960_arch;
312
extern const bfd_arch_info_type bfd_m32r_arch;
313
extern const bfd_arch_info_type bfd_m68hc11_arch;
314
extern const bfd_arch_info_type bfd_m68hc12_arch;
315
extern const bfd_arch_info_type bfd_m68k_arch;
316
extern const bfd_arch_info_type bfd_m88k_arch;
317
extern const bfd_arch_info_type bfd_mips_arch;
318
extern const bfd_arch_info_type bfd_mn10200_arch;
319
extern const bfd_arch_info_type bfd_mn10300_arch;
320
extern const bfd_arch_info_type bfd_pdp11_arch;
321
extern const bfd_arch_info_type bfd_powerpc_arch;
322
extern const bfd_arch_info_type bfd_rs6000_arch;
323
extern const bfd_arch_info_type bfd_pj_arch;
324
extern const bfd_arch_info_type bfd_sh_arch;
325
extern const bfd_arch_info_type bfd_sparc_arch;
326
extern const bfd_arch_info_type bfd_tic30_arch;
327
extern const bfd_arch_info_type bfd_tic54x_arch;
328
extern const bfd_arch_info_type bfd_tic80_arch;
329
extern const bfd_arch_info_type bfd_vax_arch;
330
extern const bfd_arch_info_type bfd_we32k_arch;
331
extern const bfd_arch_info_type bfd_z8k_arch;
332
extern const bfd_arch_info_type bfd_ns32k_arch;
333
extern const bfd_arch_info_type bfd_w65_arch;
334
extern const bfd_arch_info_type bfd_v850_arch;
335
extern const bfd_arch_info_type bfd_fr30_arch;
336
extern const bfd_arch_info_type bfd_mcore_arch;
337
extern const bfd_arch_info_type bfd_avr_arch;
338
extern const bfd_arch_info_type bfd_ia64_arch;
339
extern const bfd_arch_info_type bfd_s390_arch;
340
extern const bfd_arch_info_type bfd_openrisc_arch;
341
 
342
static const bfd_arch_info_type * const bfd_archures_list[] = {
343
#ifdef SELECT_ARCHITECTURES
344
  SELECT_ARCHITECTURES,
345
#else
346
  &bfd_or32_arch,
347
  &bfd_a29k_arch,
348
  &bfd_alpha_arch,
349
  &bfd_arc_arch,
350
  &bfd_arm_arch,
351
  &bfd_cris_arch,
352
  &bfd_d10v_arch,
353
  &bfd_d30v_arch,
354
  &bfd_h8300_arch,
355
  &bfd_h8500_arch,
356
  &bfd_hppa_arch,
357
  &bfd_i370_arch,
358
  &bfd_i386_arch,
359
  &bfd_i860_arch,
360
  &bfd_i960_arch,
361
  &bfd_m32r_arch,
362
  &bfd_m68hc11_arch,
363
  &bfd_m68hc12_arch,
364
  &bfd_m68k_arch,
365
  &bfd_m88k_arch,
366
  &bfd_mips_arch,
367
  &bfd_mn10200_arch,
368
  &bfd_mn10300_arch,
369
  &bfd_pdp11_arch,
370
  &bfd_powerpc_arch,
371
  &bfd_rs6000_arch,
372
  &bfd_sh_arch,
373
  &bfd_sparc_arch,
374
  &bfd_tic30_arch,
375
  &bfd_tic54x_arch,
376
  &bfd_tic80_arch,
377
  &bfd_vax_arch,
378
  &bfd_we32k_arch,
379
  &bfd_z8k_arch,
380
  &bfd_ns32k_arch,
381
  &bfd_w65_arch,
382
  &bfd_v850_arch,
383
  &bfd_fr30_arch,
384
  &bfd_mcore_arch,
385
  &bfd_avr_arch,
386
  &bfd_ia64_arch,
387
  &bfd_s390_arch,
388
  &bfd_openrisc_arch,
389
#endif
390
 
391
};
392
 
393
/*
394
FUNCTION
395
        bfd_printable_name
396
 
397
SYNOPSIS
398
        const char *bfd_printable_name(bfd *abfd);
399
 
400
DESCRIPTION
401
        Return a printable string representing the architecture and machine
402
        from the pointer to the architecture info structure.
403
 
404
*/
405
 
406
const char *
407
bfd_printable_name (abfd)
408
     bfd *abfd;
409
{
410
  return abfd->arch_info->printable_name;
411
}
412
 
413
/*
414
FUNCTION
415
        bfd_scan_arch
416
 
417
SYNOPSIS
418
        const bfd_arch_info_type *bfd_scan_arch(const char *string);
419
 
420
DESCRIPTION
421
        Figure out if BFD supports any cpu which could be described with
422
        the name @var{string}.  Return a pointer to an <<arch_info>>
423
        structure if a machine is found, otherwise NULL.
424
*/
425
 
426
const bfd_arch_info_type *
427
bfd_scan_arch (string)
428
     const char *string;
429
{
430
  const bfd_arch_info_type * const *app, *ap;
431
 
432
  /* Look through all the installed architectures.  */
433
  for (app = bfd_archures_list; *app != NULL; app++)
434
    {
435
      for (ap = *app; ap != NULL; ap = ap->next)
436
        {
437
          if (ap->scan (ap, string))
438
            return ap;
439
        }
440
    }
441
 
442
  return NULL;
443
}
444
 
445
/*
446
FUNCTION
447
        bfd_arch_list
448
 
449
SYNOPSIS
450
        const char **bfd_arch_list(void);
451
 
452
DESCRIPTION
453
        Return a freshly malloced NULL-terminated vector of the names
454
        of all the valid BFD architectures.  Do not modify the names.
455
*/
456
 
457
const char **
458
bfd_arch_list ()
459
{
460
  int vec_length = 0;
461
  const char **name_ptr;
462
  const char **name_list;
463
  const bfd_arch_info_type * const *app;
464
 
465
  /* Determine the number of architectures.  */
466
  vec_length = 0;
467
  for (app = bfd_archures_list; *app != NULL; app++)
468
    {
469
      const bfd_arch_info_type *ap;
470
      for (ap = *app; ap != NULL; ap = ap->next)
471
        {
472
          vec_length++;
473
        }
474
    }
475
 
476
  name_list = (const char **)
477
    bfd_malloc ((vec_length + 1) * sizeof (char **));
478
  if (name_list == NULL)
479
    return NULL;
480
 
481
  /* Point the list at each of the names.  */
482
  name_ptr = name_list;
483
  for (app = bfd_archures_list; *app != NULL; app++)
484
    {
485
      const bfd_arch_info_type *ap;
486
      for (ap = *app; ap != NULL; ap = ap->next)
487
        {
488
          *name_ptr = ap->printable_name;
489
          name_ptr++;
490
        }
491
    }
492
  *name_ptr = NULL;
493
 
494
  return name_list;
495
}
496
 
497
/*
498
FUNCTION
499
        bfd_arch_get_compatible
500
 
501
SYNOPSIS
502
        const bfd_arch_info_type *bfd_arch_get_compatible(
503
                const bfd *abfd,
504
                const bfd *bbfd);
505
 
506
DESCRIPTION
507
        Determine whether two BFDs'
508
        architectures and machine types are compatible.  Calculates
509
        the lowest common denominator between the two architectures
510
        and machine types implied by the BFDs and returns a pointer to
511
        an <<arch_info>> structure describing the compatible machine.
512
*/
513
 
514
const bfd_arch_info_type *
515
bfd_arch_get_compatible (abfd, bbfd)
516
     const bfd *abfd;
517
     const bfd *bbfd;
518
{
519
  /* If either architecture is unknown, then all we can do is assume
520
     the user knows what he's doing.  */
521
  if (abfd->arch_info->arch == bfd_arch_unknown)
522
    return bbfd->arch_info;
523
  if (bbfd->arch_info->arch == bfd_arch_unknown)
524
    return abfd->arch_info;
525
 
526
  /* Otherwise architecture-specific code has to decide.  */
527
  return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
528
}
529
 
530
/*
531
INTERNAL_DEFINITION
532
        bfd_default_arch_struct
533
 
534
DESCRIPTION
535
        The <<bfd_default_arch_struct>> is an item of
536
        <<bfd_arch_info_type>> which has been initialized to a fairly
537
        generic state.  A BFD starts life by pointing to this
538
        structure, until the correct back end has determined the real
539
        architecture of the file.
540
 
541
.extern const bfd_arch_info_type bfd_default_arch_struct;
542
*/
543
 
544
const bfd_arch_info_type bfd_default_arch_struct = {
545
  32, 32, 8, bfd_arch_unknown, 0, "unknown", "unknown", 2, true,
546
  bfd_default_compatible,
547
  bfd_default_scan,
548
  0,
549
};
550
 
551
/*
552
FUNCTION
553
        bfd_set_arch_info
554
 
555
SYNOPSIS
556
        void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
557
 
558
DESCRIPTION
559
        Set the architecture info of @var{abfd} to @var{arg}.
560
*/
561
 
562
void
563
bfd_set_arch_info (abfd, arg)
564
     bfd *abfd;
565
     const bfd_arch_info_type *arg;
566
{
567
  abfd->arch_info = arg;
568
}
569
 
570
/*
571
INTERNAL_FUNCTION
572
        bfd_default_set_arch_mach
573
 
574
SYNOPSIS
575
        boolean bfd_default_set_arch_mach(bfd *abfd,
576
                enum bfd_architecture arch,
577
                unsigned long mach);
578
 
579
DESCRIPTION
580
        Set the architecture and machine type in BFD @var{abfd}
581
        to @var{arch} and @var{mach}.  Find the correct
582
        pointer to a structure and insert it into the <<arch_info>>
583
        pointer.
584
*/
585
 
586
boolean
587
bfd_default_set_arch_mach (abfd, arch, mach)
588
     bfd *abfd;
589
     enum bfd_architecture arch;
590
     unsigned long mach;
591
{
592
  const bfd_arch_info_type * const *app, *ap;
593
 
594
  for (app = bfd_archures_list; *app != NULL; app++)
595
    {
596
      for (ap = *app; ap != NULL; ap = ap->next)
597
        {
598
          if (ap->arch == arch
599
              && (ap->mach == mach
600
                  || (mach == 0 && ap->the_default)))
601
            {
602
              abfd->arch_info = ap;
603
              return true;
604
            }
605
        }
606
    }
607
 
608
  abfd->arch_info = &bfd_default_arch_struct;
609
  bfd_set_error (bfd_error_bad_value);
610
  return false;
611
}
612
 
613
/*
614
FUNCTION
615
        bfd_get_arch
616
 
617
SYNOPSIS
618
        enum bfd_architecture bfd_get_arch(bfd *abfd);
619
 
620
DESCRIPTION
621
        Return the enumerated type which describes the BFD @var{abfd}'s
622
        architecture.
623
*/
624
 
625
enum bfd_architecture
626
bfd_get_arch (abfd)
627
     bfd *abfd;
628
{
629
  return abfd->arch_info->arch;
630
}
631
 
632
/*
633
FUNCTION
634
        bfd_get_mach
635
 
636
SYNOPSIS
637
        unsigned long bfd_get_mach(bfd *abfd);
638
 
639
DESCRIPTION
640
        Return the long type which describes the BFD @var{abfd}'s
641
        machine.
642
*/
643
 
644
unsigned long
645
bfd_get_mach (abfd)
646
     bfd *abfd;
647
{
648
  return abfd->arch_info->mach;
649
}
650
 
651
/*
652
FUNCTION
653
        bfd_arch_bits_per_byte
654
 
655
SYNOPSIS
656
        unsigned int bfd_arch_bits_per_byte(bfd *abfd);
657
 
658
DESCRIPTION
659
        Return the number of bits in one of the BFD @var{abfd}'s
660
        architecture's bytes.
661
*/
662
 
663
unsigned int
664
bfd_arch_bits_per_byte (abfd)
665
     bfd *abfd;
666
{
667
  return abfd->arch_info->bits_per_byte;
668
}
669
 
670
/*
671
FUNCTION
672
        bfd_arch_bits_per_address
673
 
674
SYNOPSIS
675
        unsigned int bfd_arch_bits_per_address(bfd *abfd);
676
 
677
DESCRIPTION
678
        Return the number of bits in one of the BFD @var{abfd}'s
679
        architecture's addresses.
680
*/
681
 
682
unsigned int
683
bfd_arch_bits_per_address (abfd)
684
     bfd *abfd;
685
{
686
  return abfd->arch_info->bits_per_address;
687
}
688
 
689
/*
690
INTERNAL_FUNCTION
691
        bfd_default_compatible
692
 
693
SYNOPSIS
694
        const bfd_arch_info_type *bfd_default_compatible
695
        (const bfd_arch_info_type *a,
696
        const bfd_arch_info_type *b);
697
 
698
DESCRIPTION
699
        The default function for testing for compatibility.
700
*/
701
 
702
const bfd_arch_info_type *
703
bfd_default_compatible (a, b)
704
     const bfd_arch_info_type *a;
705
     const bfd_arch_info_type *b;
706
{
707
  if (a->arch != b->arch)
708
    return NULL;
709
 
710
  if (a->mach > b->mach)
711
    return a;
712
 
713
  if (b->mach > a->mach)
714
    return b;
715
 
716
  return a;
717
}
718
 
719
/*
720
INTERNAL_FUNCTION
721
        bfd_default_scan
722
 
723
SYNOPSIS
724
        boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
725
 
726
DESCRIPTION
727
        The default function for working out whether this is an
728
        architecture hit and a machine hit.
729
*/
730
 
731
boolean
732
bfd_default_scan (info, string)
733
     const bfd_arch_info_type *info;
734
     const char *string;
735
{
736
  const char *ptr_src;
737
  const char *ptr_tst;
738
  unsigned long number;
739
  enum bfd_architecture arch;
740
  const char *printable_name_colon;
741
 
742
  /* Exact match of the architecture name (ARCH_NAME) and also the
743
     default architecture?  */
744
  if (strcasecmp (string, info->arch_name) == 0
745
      && info->the_default)
746
    return true;
747
 
748
  /* Exact match of the machine name (PRINTABLE_NAME)?  */
749
  if (strcasecmp (string, info->printable_name) == 0)
750
    return true;
751
 
752
  /* Given that printable_name contains no colon, attempt to match:
753
     ARCH_NAME [ ":" ] PRINTABLE_NAME?  */
754
  printable_name_colon = strchr (info->printable_name, ':');
755
  if (printable_name_colon == NULL)
756
    {
757
      int strlen_arch_name = strlen (info->arch_name);
758
      if (strncasecmp (string, info->arch_name, strlen_arch_name) == 0)
759
        {
760
          if (string[strlen_arch_name] == ':')
761
            {
762
              if (strcasecmp (string + strlen_arch_name + 1,
763
                              info->printable_name) == 0)
764
                return true;
765
            }
766
          else
767
            {
768
              if (strcasecmp (string + strlen_arch_name,
769
                              info->printable_name) == 0)
770
                return true;
771
            }
772
        }
773
    }
774
 
775
  /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>;
776
     Attempt to match: <arch> <mach>?  */
777
  if (printable_name_colon != NULL)
778
    {
779
      int colon_index = printable_name_colon - info->printable_name;
780
      if (strncasecmp (string, info->printable_name, colon_index) == 0
781
          && strcasecmp (string + colon_index,
782
                         info->printable_name + colon_index + 1) == 0)
783
        return true;
784
    }
785
 
786
  /* Given that PRINTABLE_NAME has the form: <arch> ":" <mach>; Do not
787
     attempt to match just <mach>, it could be ambigious.  This test
788
     is left until later.  */
789
 
790
  /* NOTE: The below is retained for compatibility only.  Please do
791
     not add to this code.  */
792
 
793
  /* See how much of the supplied string matches with the
794
     architecture, eg the string m68k:68020 would match the 68k entry
795
     up to the :, then we get left with the machine number.  */
796
 
797
  for (ptr_src = string, ptr_tst = info->arch_name;
798
       *ptr_src && *ptr_tst;
799
       ptr_src++, ptr_tst++)
800
    {
801
      if (*ptr_src != *ptr_tst)
802
        break;
803
    }
804
 
805
  /* Chewed up as much of the architecture as will match, skip any
806
     colons.  */
807
  if (*ptr_src == ':')
808
    ptr_src++;
809
 
810
  if (*ptr_src == 0)
811
    {
812
      /* Nothing more, then only keep this one if it is the default
813
         machine for this architecture.  */
814
      return info->the_default;
815
    }
816
 
817
  number = 0;
818
  while (isdigit ((unsigned char) *ptr_src))
819
    {
820
      number = number * 10 + *ptr_src - '0';
821
      ptr_src++;
822
    }
823
 
824
  /* NOTE: The below is retained for compatibility only.
825
     PLEASE DO NOT ADD TO THIS CODE.  */
826
 
827
  switch (number)
828
    {
829
      /* FIXME: These are needed to parse IEEE objects.  */
830
      /* The following seven case's are here only for compatibility with
831
         older binutils (at least IEEE objects from binutils 2.9.1 require
832
         them).  */
833
    case bfd_mach_m68000:
834
    case bfd_mach_m68010:
835
    case bfd_mach_m68020:
836
    case bfd_mach_m68030:
837
    case bfd_mach_m68040:
838
    case bfd_mach_m68060:
839
    case bfd_mach_cpu32:
840
      arch = bfd_arch_m68k;
841
      break;
842
    case 68000:
843
      arch = bfd_arch_m68k;
844
      number = bfd_mach_m68000;
845
      break;
846
    case 68010:
847
      arch = bfd_arch_m68k;
848
      number = bfd_mach_m68010;
849
      break;
850
    case 68020:
851
      arch = bfd_arch_m68k;
852
      number = bfd_mach_m68020;
853
      break;
854
    case 68030:
855
      arch = bfd_arch_m68k;
856
      number = bfd_mach_m68030;
857
      break;
858
    case 68040:
859
      arch = bfd_arch_m68k;
860
      number = bfd_mach_m68040;
861
      break;
862
    case 68060:
863
      arch = bfd_arch_m68k;
864
      number = bfd_mach_m68060;
865
      break;
866
    case 68332:
867
      arch = bfd_arch_m68k;
868
      number = bfd_mach_cpu32;
869
      break;
870
    case 5200:
871
      arch = bfd_arch_m68k;
872
      number = bfd_mach_mcf5200;
873
      break;
874
    case 5206:
875
      arch = bfd_arch_m68k;
876
      number = bfd_mach_mcf5206e;
877
      break;
878
    case 5307:
879
      arch = bfd_arch_m68k;
880
      number = bfd_mach_mcf5307;
881
      break;
882
    case 5407:
883
      arch = bfd_arch_m68k;
884
      number = bfd_mach_mcf5407;
885
      break;
886
 
887
    case 32000:
888
      arch = bfd_arch_we32k;
889
      break;
890
 
891
    case 3000:
892
      arch = bfd_arch_mips;
893
      number = bfd_mach_mips3000;
894
      break;
895
 
896
    case 4000:
897
      arch = bfd_arch_mips;
898
      number = bfd_mach_mips4000;
899
      break;
900
 
901
    case 6000:
902
      arch = bfd_arch_rs6000;
903
      break;
904
 
905
    case 7410:
906
      arch = bfd_arch_sh;
907
      number = bfd_mach_sh_dsp;
908
      break;
909
 
910
    case 7708:
911
      arch = bfd_arch_sh;
912
      number = bfd_mach_sh3;
913
      break;
914
 
915
    case 7729:
916
      arch = bfd_arch_sh;
917
      number = bfd_mach_sh3_dsp;
918
      break;
919
 
920
    case 7750:
921
      arch = bfd_arch_sh;
922
      number = bfd_mach_sh4;
923
      break;
924
 
925
    default:
926
      return false;
927
    }
928
 
929
  if (arch != info->arch)
930
    return false;
931
 
932
  if (number != info->mach)
933
    return false;
934
 
935
  return true;
936
}
937
 
938
/*
939
FUNCTION
940
        bfd_get_arch_info
941
 
942
SYNOPSIS
943
        const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
944
 
945
DESCRIPTION
946
        Return the architecture info struct in @var{abfd}.
947
*/
948
 
949
const bfd_arch_info_type *
950
bfd_get_arch_info (abfd)
951
     bfd *abfd;
952
{
953
  return abfd->arch_info;
954
}
955
 
956
/*
957
FUNCTION
958
        bfd_lookup_arch
959
 
960
SYNOPSIS
961
        const bfd_arch_info_type *bfd_lookup_arch
962
                (enum bfd_architecture
963
                arch,
964
                unsigned long machine);
965
 
966
DESCRIPTION
967
        Look for the architecure info structure which matches the
968
        arguments @var{arch} and @var{machine}. A machine of 0 matches the
969
        machine/architecture structure which marks itself as the
970
        default.
971
*/
972
 
973
const bfd_arch_info_type *
974
bfd_lookup_arch (arch, machine)
975
     enum bfd_architecture arch;
976
     unsigned long machine;
977
{
978
  const bfd_arch_info_type * const *app, *ap;
979
 
980
  for (app = bfd_archures_list; *app != NULL; app++)
981
    {
982
      for (ap = *app; ap != NULL; ap = ap->next)
983
        {
984
          if (ap->arch == arch
985
              && (ap->mach == machine
986
                  || (machine == 0 && ap->the_default)))
987
            return ap;
988
        }
989
    }
990
 
991
  return NULL;
992
}
993
 
994
/*
995
FUNCTION
996
        bfd_printable_arch_mach
997
 
998
SYNOPSIS
999
        const char *bfd_printable_arch_mach
1000
                (enum bfd_architecture arch, unsigned long machine);
1001
 
1002
DESCRIPTION
1003
        Return a printable string representing the architecture and
1004
        machine type.
1005
 
1006
        This routine is depreciated.
1007
*/
1008
 
1009
const char *
1010
bfd_printable_arch_mach (arch, machine)
1011
     enum bfd_architecture arch;
1012
     unsigned long machine;
1013
{
1014
  const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
1015
 
1016
  if (ap)
1017
    return ap->printable_name;
1018
  return "UNKNOWN!";
1019
}
1020
 
1021
/*
1022
FUNCTION
1023
        bfd_octets_per_byte
1024
 
1025
SYNOPSIS
1026
        unsigned int bfd_octets_per_byte(bfd *abfd);
1027
 
1028
DESCRIPTION
1029
        Return the number of octets (8-bit quantities) per target byte
1030
        (minimum addressable unit).  In most cases, this will be one, but some
1031
        DSP targets have 16, 32, or even 48 bits per byte.
1032
*/
1033
 
1034
unsigned int
1035
bfd_octets_per_byte (abfd)
1036
     bfd *abfd;
1037
{
1038
  return bfd_arch_mach_octets_per_byte (bfd_get_arch (abfd),
1039
                                        bfd_get_mach (abfd));
1040
}
1041
 
1042
/*
1043
FUNCTION
1044
        bfd_arch_mach_octets_per_byte
1045
 
1046
SYNOPSIS
1047
        unsigned int bfd_arch_mach_octets_per_byte(enum bfd_architecture arch,
1048
                                                   unsigned long machine);
1049
 
1050
DESCRIPTION
1051
        See bfd_octets_per_byte.
1052
 
1053
        This routine is provided for those cases where a bfd * is not
1054
        available
1055
*/
1056
 
1057
unsigned int
1058
bfd_arch_mach_octets_per_byte (arch, mach)
1059
     enum bfd_architecture arch;
1060
     unsigned long mach;
1061
{
1062
  const bfd_arch_info_type *ap = bfd_lookup_arch (arch, mach);
1063
 
1064
  if (ap)
1065
    return ap->bits_per_byte / 8;
1066
  return 1;
1067
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.