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