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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [bfd/] [archures.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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