| 1 | /* BFD library support routines for architectures. |
| 2 | Copyright (C) 1990, 91, 92, 93, 94 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | /* |
| 22 | |
| 23 | SECTION |
| 24 | Architectures |
| 25 | |
| 26 | BFD keeps one atom in a BFD describing the |
| 27 | architecture of the data attached to the BFD: a pointer to a |
| 28 | <<bfd_arch_info_type>>. |
| 29 | |
| 30 | Pointers to structures can be requested independently of a BFD |
| 31 | so that an architecture's information can be interrogated |
| 32 | without access to an open BFD. |
| 33 | |
| 34 | The architecture information is provided by each architecture package. |
| 35 | The set of default architectures is selected by the macro |
| 36 | <<SELECT_ARCHITECTURES>>. This is normally set up in the |
| 37 | @file{config/@var{target}.mt} file of your choice. If the name is not |
| 38 | defined, then all the architectures supported are included. |
| 39 | |
| 40 | When BFD starts up, all the architectures are called with an |
| 41 | initialize method. It is up to the architecture back end to |
| 42 | insert as many items into the list of architectures as it wants to; |
| 43 | generally this would be one for each machine and one for the |
| 44 | default case (an item with a machine field of 0). |
| 45 | |
| 46 | BFD's idea of an architecture is implemented in @file{archures.c}. |
| 47 | */ |
| 48 | |
| 49 | /* |
| 50 | |
| 51 | SUBSECTION |
| 52 | bfd_architecture |
| 53 | |
| 54 | DESCRIPTION |
| 55 | This enum gives the object file's CPU architecture, in a |
| 56 | global sense---i.e., what processor family does it belong to? |
| 57 | Another field indicates which processor within |
| 58 | the family is in use. The machine gives a number which |
| 59 | distinguishes different versions of the architecture, |
| 60 | containing, for example, 2 and 3 for Intel i960 KA and i960 KB, |
| 61 | and 68020 and 68030 for Motorola 68020 and 68030. |
| 62 | |
| 63 | .enum bfd_architecture |
| 64 | .{ |
| 65 | . bfd_arch_unknown, {* File arch not known *} |
| 66 | . bfd_arch_obscure, {* Arch known, not one of these *} |
| 67 | . bfd_arch_m68k, {* Motorola 68xxx *} |
| 68 | . bfd_arch_vax, {* DEC Vax *} |
| 69 | . bfd_arch_i960, {* Intel 960 *} |
| 70 | . {* The order of the following is important. |
| 71 | . lower number indicates a machine type that |
| 72 | . only accepts a subset of the instructions |
| 73 | . available to machines with higher numbers. |
| 74 | . The exception is the "ca", which is |
| 75 | . incompatible with all other machines except |
| 76 | . "core". *} |
| 77 | . |
| 78 | .#define bfd_mach_i960_core 1 |
| 79 | .#define bfd_mach_i960_ka_sa 2 |
| 80 | .#define bfd_mach_i960_kb_sb 3 |
| 81 | .#define bfd_mach_i960_mc 4 |
| 82 | .#define bfd_mach_i960_xa 5 |
| 83 | .#define bfd_mach_i960_ca 6 |
| 84 | . {* start-sanitize-i960xl *} |
| 85 | .#define bfd_mach_i960_xl 7 |
| 86 | . {* end-sanitize-i960xl *} |
| 87 | . |
| 88 | . bfd_arch_a29k, {* AMD 29000 *} |
| 89 | . bfd_arch_sparc, {* SPARC *} |
| 90 | . bfd_arch_mips, {* MIPS Rxxxx *} |
| 91 | . bfd_arch_i386, {* Intel 386 *} |
| 92 | . bfd_arch_we32k, {* AT&T WE32xxx *} |
| 93 | . bfd_arch_tahoe, {* CCI/Harris Tahoe *} |
| 94 | . bfd_arch_i860, {* Intel 860 *} |
| 95 | . bfd_arch_romp, {* IBM ROMP PC/RT *} |
| 96 | . bfd_arch_alliant, {* Alliant *} |
| 97 | . bfd_arch_convex, {* Convex *} |
| 98 | . bfd_arch_m88k, {* Motorola 88xxx *} |
| 99 | . bfd_arch_pyramid, {* Pyramid Technology *} |
| 100 | . bfd_arch_h8300, {* Hitachi H8/300 *} |
| 101 | .#define bfd_mach_h8300 1 |
| 102 | .#define bfd_mach_h8300h 2 |
| 103 | . bfd_arch_powerpc, {* PowerPC *} |
| 104 | . bfd_arch_rs6000, {* IBM RS/6000 *} |
| 105 | . bfd_arch_hppa, {* HP PA RISC *} |
| 106 | . bfd_arch_z8k, {* Zilog Z8000 *} |
| 107 | .#define bfd_mach_z8001 1 |
| 108 | .#define bfd_mach_z8002 2 |
| 109 | . bfd_arch_h8500, {* Hitachi H8/500 *} |
| 110 | . bfd_arch_sh, {* Hitachi SH *} |
| 111 | . bfd_arch_alpha, {* Dec Alpha *} |
| 112 | . bfd_arch_arm, {* Advanced Risc Machines ARM *} |
| 113 | . bfd_arch_ns32k, {* National Semiconductors ns32000 *} |
| 114 | . {* start-sanitize-rce *} |
| 115 | . bfd_arch_rce, {* Motorola RCE *} |
| 116 | . {* end-sanitize-rce *} |
| 117 | . {* start-sanitize-arc *} |
| 118 | . bfd_arch_arc, {* Argonaut RISC Core *} |
| 119 | . {* end-sanitize-arc *} |
| 120 | . bfd_arch_last |
| 121 | . }; |
| 122 | |
| 123 | |
| 124 | */ |
| 125 | |
| 126 | #include "bfd.h" |
| 127 | #include "sysdep.h" |
| 128 | #include "libbfd.h" |
| 129 | |
| 130 | /* |
| 131 | |
| 132 | SUBSECTION |
| 133 | bfd_arch_info |
| 134 | |
| 135 | DESCRIPTION |
| 136 | This structure contains information on architectures for use |
| 137 | within BFD. |
| 138 | |
| 139 | . |
| 140 | .typedef struct bfd_arch_info |
| 141 | .{ |
| 142 | . int bits_per_word; |
| 143 | . int bits_per_address; |
| 144 | . int bits_per_byte; |
| 145 | . enum bfd_architecture arch; |
| 146 | . long mach; |
| 147 | . char *arch_name; |
| 148 | . CONST char *printable_name; |
| 149 | . unsigned int section_align_power; |
| 150 | . {* true if this is the default machine for the architecture *} |
| 151 | . boolean the_default; |
| 152 | . CONST struct bfd_arch_info * (*compatible) |
| 153 | . PARAMS ((CONST struct bfd_arch_info *a, |
| 154 | . CONST struct bfd_arch_info *b)); |
| 155 | . |
| 156 | . boolean (*scan) PARAMS ((CONST struct bfd_arch_info *, CONST char *)); |
| 157 | . {* How to disassemble an instruction, producing a printable |
| 158 | . representation on a specified stdio stream. This isn't |
| 159 | . defined for most processors at present, because of the size |
| 160 | . of the additional tables it would drag in, and because gdb |
| 161 | . wants to use a different interface. *} |
| 162 | . unsigned int (*disassemble) PARAMS ((bfd_vma addr, CONST char *data, |
| 163 | . PTR stream)); |
| 164 | . |
| 165 | . struct bfd_arch_info *next; |
| 166 | .} bfd_arch_info_type; |
| 167 | */ |
| 168 | |
| 169 | bfd_arch_info_type *bfd_arch_info_list; |
| 170 | |
| 171 | |
| 172 | /* |
| 173 | FUNCTION |
| 174 | bfd_printable_name |
| 175 | |
| 176 | SYNOPSIS |
| 177 | CONST char *bfd_printable_name(bfd *abfd); |
| 178 | |
| 179 | DESCRIPTION |
| 180 | Return a printable string representing the architecture and machine |
| 181 | from the pointer to the architecture info structure. |
| 182 | |
| 183 | */ |
| 184 | |
| 185 | CONST char * |
| 186 | bfd_printable_name (abfd) |
| 187 | bfd *abfd; |
| 188 | { |
| 189 | return abfd->arch_info->printable_name; |
| 190 | } |
| 191 | |
| 192 | |
| 193 | |
| 194 | /* |
| 195 | FUNCTION |
| 196 | bfd_scan_arch |
| 197 | |
| 198 | SYNOPSIS |
| 199 | bfd_arch_info_type *bfd_scan_arch(CONST char *string); |
| 200 | |
| 201 | DESCRIPTION |
| 202 | Figure out if BFD supports any cpu which could be described with |
| 203 | the name @var{string}. Return a pointer to an <<arch_info>> |
| 204 | structure if a machine is found, otherwise NULL. |
| 205 | |
| 206 | */ |
| 207 | |
| 208 | bfd_arch_info_type * |
| 209 | bfd_scan_arch (string) |
| 210 | CONST char *string; |
| 211 | { |
| 212 | struct bfd_arch_info *ap; |
| 213 | |
| 214 | /* Look through all the installed architectures */ |
| 215 | for (ap = bfd_arch_info_list; |
| 216 | ap != (bfd_arch_info_type *)NULL; |
| 217 | ap = ap->next) { |
| 218 | |
| 219 | if (ap->scan(ap, string)) |
| 220 | return ap; |
| 221 | } |
| 222 | return (bfd_arch_info_type *)NULL; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | |
| 227 | /* |
| 228 | FUNCTION |
| 229 | bfd_arch_get_compatible |
| 230 | |
| 231 | SYNOPSIS |
| 232 | CONST bfd_arch_info_type *bfd_arch_get_compatible( |
| 233 | CONST bfd *abfd, |
| 234 | CONST bfd *bbfd); |
| 235 | |
| 236 | DESCRIPTION |
| 237 | Determine whether two BFDs' |
| 238 | architectures and machine types are compatible. Calculates |
| 239 | the lowest common denominator between the two architectures |
| 240 | and machine types implied by the BFDs and returns a pointer to |
| 241 | an <<arch_info>> structure describing the compatible machine. |
| 242 | */ |
| 243 | |
| 244 | CONST bfd_arch_info_type * |
| 245 | bfd_arch_get_compatible (abfd, bbfd) |
| 246 | CONST bfd *abfd; |
| 247 | CONST bfd *bbfd; |
| 248 | { |
| 249 | return abfd->arch_info->compatible(abfd->arch_info,bbfd->arch_info); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | /* |
| 254 | INTERNAL_DEFINITION |
| 255 | bfd_default_arch_struct |
| 256 | |
| 257 | DESCRIPTION |
| 258 | The <<bfd_default_arch_struct>> is an item of |
| 259 | <<bfd_arch_info_type>> which has been initialized to a fairly |
| 260 | generic state. A BFD starts life by pointing to this |
| 261 | structure, until the correct back end has determined the real |
| 262 | architecture of the file. |
| 263 | |
| 264 | .extern bfd_arch_info_type bfd_default_arch_struct; |
| 265 | |
| 266 | */ |
| 267 | |
| 268 | bfd_arch_info_type bfd_default_arch_struct = |
| 269 | { |
| 270 | 32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true, |
| 271 | bfd_default_compatible, |
| 272 | bfd_default_scan, |
| 273 | 0, |
| 274 | }; |
| 275 | |
| 276 | /* |
| 277 | FUNCTION |
| 278 | bfd_set_arch_info |
| 279 | |
| 280 | SYNOPSIS |
| 281 | void bfd_set_arch_info(bfd *abfd, bfd_arch_info_type *arg); |
| 282 | |
| 283 | DESCRIPTION |
| 284 | Set the architecture info of @var{abfd} to @var{arg}. |
| 285 | */ |
| 286 | |
| 287 | void |
| 288 | bfd_set_arch_info (abfd, arg) |
| 289 | bfd *abfd; |
| 290 | bfd_arch_info_type *arg; |
| 291 | { |
| 292 | abfd->arch_info = arg; |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | INTERNAL_FUNCTION |
| 297 | bfd_default_set_arch_mach |
| 298 | |
| 299 | SYNOPSIS |
| 300 | boolean bfd_default_set_arch_mach(bfd *abfd, |
| 301 | enum bfd_architecture arch, |
| 302 | unsigned long mach); |
| 303 | |
| 304 | DESCRIPTION |
| 305 | Set the architecture and machine type in BFD @var{abfd} |
| 306 | to @var{arch} and @var{mach}. Find the correct |
| 307 | pointer to a structure and insert it into the <<arch_info>> |
| 308 | pointer. |
| 309 | */ |
| 310 | |
| 311 | boolean |
| 312 | bfd_default_set_arch_mach (abfd, arch, mach) |
| 313 | bfd *abfd; |
| 314 | enum bfd_architecture arch; |
| 315 | unsigned long mach; |
| 316 | { |
| 317 | static struct bfd_arch_info *old_ptr = &bfd_default_arch_struct; |
| 318 | boolean found = false; |
| 319 | /* run through the table to find the one we want, we keep a little |
| 320 | cache to speed things up */ |
| 321 | if (old_ptr == 0 || arch != old_ptr->arch || mach != old_ptr->mach) { |
| 322 | bfd_arch_info_type *ptr; |
| 323 | old_ptr = (bfd_arch_info_type *)NULL; |
| 324 | for (ptr = bfd_arch_info_list; |
| 325 | ptr != (bfd_arch_info_type *)NULL; |
| 326 | ptr= ptr->next) { |
| 327 | if (ptr->arch == arch && |
| 328 | ((ptr->mach == mach) || (ptr->the_default && mach == 0))) { |
| 329 | old_ptr = ptr; |
| 330 | found = true; |
| 331 | break; |
| 332 | } |
| 333 | } |
| 334 | if (found==false) { |
| 335 | /*looked for it and it wasn't there, so put in the default */ |
| 336 | old_ptr = &bfd_default_arch_struct; |
| 337 | bfd_set_error (bfd_error_bad_value); |
| 338 | } |
| 339 | } |
| 340 | else { |
| 341 | /* it was in the cache */ |
| 342 | found = true; |
| 343 | } |
| 344 | |
| 345 | abfd->arch_info = old_ptr; |
| 346 | |
| 347 | return found; |
| 348 | } |
| 349 | |
| 350 | |
| 351 | /* |
| 352 | FUNCTION |
| 353 | bfd_get_arch |
| 354 | |
| 355 | SYNOPSIS |
| 356 | enum bfd_architecture bfd_get_arch(bfd *abfd); |
| 357 | |
| 358 | DESCRIPTION |
| 359 | Return the enumerated type which describes the BFD @var{abfd}'s |
| 360 | architecture. |
| 361 | |
| 362 | */ |
| 363 | |
| 364 | enum bfd_architecture |
| 365 | bfd_get_arch (abfd) |
| 366 | bfd *abfd; |
| 367 | { |
| 368 | return abfd->arch_info->arch; |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | FUNCTION |
| 373 | bfd_get_mach |
| 374 | |
| 375 | SYNOPSIS |
| 376 | unsigned long bfd_get_mach(bfd *abfd); |
| 377 | |
| 378 | DESCRIPTION |
| 379 | Return the long type which describes the BFD @var{abfd}'s |
| 380 | machine. |
| 381 | */ |
| 382 | |
| 383 | unsigned long |
| 384 | bfd_get_mach (abfd) |
| 385 | bfd *abfd; |
| 386 | { |
| 387 | return abfd->arch_info->mach; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | FUNCTION |
| 392 | bfd_arch_bits_per_byte |
| 393 | |
| 394 | SYNOPSIS |
| 395 | unsigned int bfd_arch_bits_per_byte(bfd *abfd); |
| 396 | |
| 397 | DESCRIPTION |
| 398 | Return the number of bits in one of the BFD @var{abfd}'s |
| 399 | architecture's bytes. |
| 400 | |
| 401 | */ |
| 402 | |
| 403 | unsigned int |
| 404 | bfd_arch_bits_per_byte (abfd) |
| 405 | bfd *abfd; |
| 406 | { |
| 407 | return abfd->arch_info->bits_per_byte; |
| 408 | } |
| 409 | |
| 410 | /* |
| 411 | FUNCTION |
| 412 | bfd_arch_bits_per_address |
| 413 | |
| 414 | SYNOPSIS |
| 415 | unsigned int bfd_arch_bits_per_address(bfd *abfd); |
| 416 | |
| 417 | DESCRIPTION |
| 418 | Return the number of bits in one of the BFD @var{abfd}'s |
| 419 | architecture's addresses. |
| 420 | */ |
| 421 | |
| 422 | unsigned int |
| 423 | bfd_arch_bits_per_address (abfd) |
| 424 | bfd *abfd; |
| 425 | { |
| 426 | return abfd->arch_info->bits_per_address; |
| 427 | } |
| 428 | |
| 429 | |
| 430 | extern void bfd_a29k_arch PARAMS ((void)); |
| 431 | extern void bfd_alpha_arch PARAMS ((void)); |
| 432 | /* start-sanitize-arc */ |
| 433 | extern void bfd_arc_arch PARAMS ((void)); |
| 434 | /* end-sanitize-arc */ |
| 435 | extern void bfd_arm_arch PARAMS ((void)); |
| 436 | extern void bfd_h8300_arch PARAMS ((void)); |
| 437 | extern void bfd_h8500_arch PARAMS ((void)); |
| 438 | extern void bfd_hppa_arch PARAMS ((void)); |
| 439 | extern void bfd_i386_arch PARAMS ((void)); |
| 440 | extern void bfd_i960_arch PARAMS ((void)); |
| 441 | extern void bfd_m68k_arch PARAMS ((void)); |
| 442 | extern void bfd_m88k_arch PARAMS ((void)); |
| 443 | extern void bfd_mips_arch PARAMS ((void)); |
| 444 | extern void bfd_powerpc_arch PARAMS ((void)); |
| 445 | extern void bfd_rs6000_arch PARAMS ((void)); |
| 446 | extern void bfd_sh_arch PARAMS ((void)); |
| 447 | /* start-sanitize-rce */ |
| 448 | extern void bfd_rce_arch PARAMS ((void)); |
| 449 | /* end-sanitize-rce */ |
| 450 | extern void bfd_sparc_arch PARAMS ((void)); |
| 451 | extern void bfd_vax_arch PARAMS ((void)); |
| 452 | extern void bfd_we32k_arch PARAMS ((void)); |
| 453 | extern void bfd_z8k_arch PARAMS ((void)); |
| 454 | extern void bfd_ns32k_arch PARAMS ((void)); |
| 455 | |
| 456 | static void (*const archures_init_table[]) PARAMS ((void)) = |
| 457 | { |
| 458 | #ifdef SELECT_ARCHITECTURES |
| 459 | SELECT_ARCHITECTURES, |
| 460 | #else |
| 461 | bfd_a29k_arch, |
| 462 | bfd_alpha_arch, |
| 463 | /* start-sanitize-arc */ |
| 464 | bfd_arc_arch, |
| 465 | /* end-sanitize-arc */ |
| 466 | bfd_arm_arch, |
| 467 | bfd_h8300_arch, |
| 468 | bfd_h8500_arch, |
| 469 | bfd_hppa_arch, |
| 470 | bfd_i386_arch, |
| 471 | bfd_i960_arch, |
| 472 | bfd_m68k_arch, |
| 473 | bfd_m88k_arch, |
| 474 | bfd_mips_arch, |
| 475 | bfd_powerpc_arch, |
| 476 | bfd_rs6000_arch, |
| 477 | bfd_sh_arch, |
| 478 | /* start-sanitize-rce */ |
| 479 | bfd_rce_arch, |
| 480 | /* end-sanitize-rce */ |
| 481 | bfd_sparc_arch, |
| 482 | bfd_vax_arch, |
| 483 | bfd_we32k_arch, |
| 484 | bfd_z8k_arch, |
| 485 | bfd_ns32k_arch, |
| 486 | #endif |
| 487 | 0 |
| 488 | }; |
| 489 | |
| 490 | |
| 491 | |
| 492 | /* |
| 493 | INTERNAL_FUNCTION |
| 494 | bfd_arch_init |
| 495 | |
| 496 | SYNOPSIS |
| 497 | void bfd_arch_init(void); |
| 498 | |
| 499 | DESCRIPTION |
| 500 | Initialize the architecture dispatch table by |
| 501 | calling all installed architecture packages and getting them |
| 502 | to poke around. |
| 503 | */ |
| 504 | |
| 505 | void |
| 506 | bfd_arch_init () |
| 507 | { |
| 508 | void (*const *ptable) PARAMS ((void)); |
| 509 | for (ptable = archures_init_table; *ptable ; ptable++) |
| 510 | (*ptable)(); |
| 511 | } |
| 512 | |
| 513 | |
| 514 | /* |
| 515 | INTERNAL_FUNCTION |
| 516 | bfd_arch_linkin |
| 517 | |
| 518 | SYNOPSIS |
| 519 | void bfd_arch_linkin(bfd_arch_info_type *ptr); |
| 520 | |
| 521 | DESCRIPTION |
| 522 | Link the architecture info structure @var{ptr} into the list. |
| 523 | */ |
| 524 | |
| 525 | void |
| 526 | bfd_arch_linkin (ptr) |
| 527 | bfd_arch_info_type *ptr; |
| 528 | { |
| 529 | ptr->next = bfd_arch_info_list; |
| 530 | bfd_arch_info_list = ptr; |
| 531 | } |
| 532 | |
| 533 | |
| 534 | /* |
| 535 | INTERNAL_FUNCTION |
| 536 | bfd_default_compatible |
| 537 | |
| 538 | SYNOPSIS |
| 539 | CONST bfd_arch_info_type *bfd_default_compatible |
| 540 | (CONST bfd_arch_info_type *a, |
| 541 | CONST bfd_arch_info_type *b); |
| 542 | |
| 543 | DESCRIPTION |
| 544 | The default function for testing for compatibility. |
| 545 | */ |
| 546 | |
| 547 | CONST bfd_arch_info_type * |
| 548 | bfd_default_compatible (a,b) |
| 549 | CONST bfd_arch_info_type *a; |
| 550 | CONST bfd_arch_info_type *b; |
| 551 | { |
| 552 | if(a->arch != b->arch) return NULL; |
| 553 | |
| 554 | if (a->mach > b->mach) { |
| 555 | return a; |
| 556 | } |
| 557 | if (b->mach > a->mach) { |
| 558 | return b; |
| 559 | } |
| 560 | return a; |
| 561 | } |
| 562 | |
| 563 | |
| 564 | /* |
| 565 | INTERNAL_FUNCTION |
| 566 | bfd_default_scan |
| 567 | |
| 568 | SYNOPSIS |
| 569 | boolean bfd_default_scan(CONST struct bfd_arch_info *info, CONST char *string); |
| 570 | |
| 571 | DESCRIPTION |
| 572 | The default function for working out whether this is an |
| 573 | architecture hit and a machine hit. |
| 574 | */ |
| 575 | |
| 576 | boolean |
| 577 | bfd_default_scan (info, string) |
| 578 | CONST struct bfd_arch_info *info; |
| 579 | CONST char *string; |
| 580 | { |
| 581 | CONST char *ptr_src; |
| 582 | CONST char *ptr_tst; |
| 583 | unsigned long number; |
| 584 | enum bfd_architecture arch; |
| 585 | /* First test for an exact match */ |
| 586 | if (strcmp(string, info->printable_name) == 0) return true; |
| 587 | |
| 588 | /* See how much of the supplied string matches with the |
| 589 | architecture, eg the string m68k:68020 would match the 68k entry |
| 590 | up to the :, then we get left with the machine number */ |
| 591 | |
| 592 | for (ptr_src = string, |
| 593 | ptr_tst = info->arch_name; |
| 594 | *ptr_src && *ptr_tst; |
| 595 | ptr_src++, |
| 596 | ptr_tst++) |
| 597 | { |
| 598 | if (*ptr_src != *ptr_tst) break; |
| 599 | } |
| 600 | |
| 601 | /* Chewed up as much of the architecture as will match, skip any |
| 602 | colons */ |
| 603 | if (*ptr_src == ':') ptr_src++; |
| 604 | |
| 605 | if (*ptr_src == 0) { |
| 606 | /* nothing more, then only keep this one if it is the default |
| 607 | machine for this architecture */ |
| 608 | return info->the_default; |
| 609 | } |
| 610 | number = 0; |
| 611 | while (isdigit(*ptr_src)) { |
| 612 | number = number * 10 + *ptr_src - '0'; |
| 613 | ptr_src++; |
| 614 | } |
| 615 | |
| 616 | switch (number) |
| 617 | { |
| 618 | case 300: |
| 619 | arch = bfd_arch_h8300; |
| 620 | break; |
| 621 | |
| 622 | case 500: |
| 623 | arch = bfd_arch_h8500; |
| 624 | break; |
| 625 | |
| 626 | case 68010: |
| 627 | case 68020: |
| 628 | case 68030: |
| 629 | case 68040: |
| 630 | case 68332: |
| 631 | case 68050: |
| 632 | case 68000: |
| 633 | arch = bfd_arch_m68k; |
| 634 | break; |
| 635 | case 386: |
| 636 | case 80386: |
| 637 | case 486: |
| 638 | case 80486: |
| 639 | arch = bfd_arch_i386; |
| 640 | break; |
| 641 | case 29000: |
| 642 | arch = bfd_arch_a29k; |
| 643 | break; |
| 644 | |
| 645 | case 8000: |
| 646 | arch = bfd_arch_z8k; |
| 647 | break; |
| 648 | |
| 649 | case 32000: |
| 650 | arch = bfd_arch_we32k; |
| 651 | break; |
| 652 | |
| 653 | case 860: |
| 654 | case 80860: |
| 655 | arch = bfd_arch_i860; |
| 656 | break; |
| 657 | case 960: |
| 658 | case 80960: |
| 659 | arch = bfd_arch_i960; |
| 660 | break; |
| 661 | |
| 662 | case 2000: |
| 663 | case 3000: |
| 664 | case 4000: |
| 665 | case 4400: |
| 666 | arch = bfd_arch_mips; |
| 667 | break; |
| 668 | |
| 669 | case 6000: |
| 670 | arch = bfd_arch_rs6000; |
| 671 | break; |
| 672 | |
| 673 | default: |
| 674 | return false; |
| 675 | } |
| 676 | if (arch != info->arch) |
| 677 | return false; |
| 678 | |
| 679 | if (number != info->mach) |
| 680 | return false; |
| 681 | |
| 682 | return true; |
| 683 | } |
| 684 | |
| 685 | |
| 686 | /* |
| 687 | FUNCTION |
| 688 | bfd_get_arch_info |
| 689 | |
| 690 | SYNOPSIS |
| 691 | bfd_arch_info_type * bfd_get_arch_info(bfd *abfd); |
| 692 | |
| 693 | DESCRIPTION |
| 694 | Return the architecture info struct in @var{abfd}. |
| 695 | */ |
| 696 | |
| 697 | bfd_arch_info_type * |
| 698 | bfd_get_arch_info (abfd) |
| 699 | bfd *abfd; |
| 700 | { |
| 701 | return abfd->arch_info; |
| 702 | } |
| 703 | |
| 704 | |
| 705 | /* |
| 706 | FUNCTION |
| 707 | bfd_lookup_arch |
| 708 | |
| 709 | SYNOPSIS |
| 710 | bfd_arch_info_type *bfd_lookup_arch |
| 711 | (enum bfd_architecture |
| 712 | arch, |
| 713 | long machine); |
| 714 | |
| 715 | DESCRIPTION |
| 716 | Look for the architecure info structure which matches the |
| 717 | arguments @var{arch} and @var{machine}. A machine of 0 matches the |
| 718 | machine/architecture structure which marks itself as the |
| 719 | default. |
| 720 | */ |
| 721 | |
| 722 | bfd_arch_info_type * |
| 723 | bfd_lookup_arch (arch, machine) |
| 724 | enum bfd_architecture arch; |
| 725 | long machine; |
| 726 | { |
| 727 | bfd_arch_info_type *ap; |
| 728 | bfd_check_init(); |
| 729 | for (ap = bfd_arch_info_list; |
| 730 | ap != (bfd_arch_info_type *)NULL; |
| 731 | ap = ap->next) { |
| 732 | if (ap->arch == arch && |
| 733 | ((ap->mach == machine) |
| 734 | || (ap->the_default && machine == 0))) { |
| 735 | return ap; |
| 736 | } |
| 737 | } |
| 738 | return (bfd_arch_info_type *)NULL; |
| 739 | } |
| 740 | |
| 741 | |
| 742 | /* |
| 743 | FUNCTION |
| 744 | bfd_printable_arch_mach |
| 745 | |
| 746 | SYNOPSIS |
| 747 | CONST char *bfd_printable_arch_mach |
| 748 | (enum bfd_architecture arch, unsigned long machine); |
| 749 | |
| 750 | DESCRIPTION |
| 751 | Return a printable string representing the architecture and |
| 752 | machine type. |
| 753 | |
| 754 | This routine is depreciated. |
| 755 | */ |
| 756 | |
| 757 | CONST char * |
| 758 | bfd_printable_arch_mach (arch, machine) |
| 759 | enum bfd_architecture arch; |
| 760 | unsigned long machine; |
| 761 | { |
| 762 | bfd_arch_info_type *ap = bfd_lookup_arch(arch, machine); |
| 763 | if(ap) return ap->printable_name; |
| 764 | return "UNKNOWN!"; |
| 765 | } |