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