]>
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 | ||
c188b0be DM |
27 | BFD keeps one atom in a BFD describing the |
28 | architecture of the data attached to the BFD: a pointer to a | |
9fda1a39 SC |
29 | <<bfd_arch_info_type>>. |
30 | ||
c188b0be | 31 | Pointers to structures can be requested independently of a BFD |
9fda1a39 | 32 | so that an architecture's information can be interrogated |
c188b0be | 33 | without access to an open BFD. |
9fda1a39 | 34 | |
c188b0be DM |
35 | The architecture information is provided by each architecture package. |
36 | The set of default architectures is selected by the macro | |
9fda1a39 | 37 | <<SELECT_ARCHITECTURES>>. This is normally set up in the |
2e235c93 | 38 | <<config/target.mt>> file of your choice. If the name is not |
9fda1a39 SC |
39 | defined, then all the architectures supported are included. |
40 | ||
41 | When BFD starts up, all the architectures are called with an | |
42 | initialize method. It is up to the architecture back end to | |
71c0bae0 | 43 | insert as many items into the list of architectures as it wants to; |
9fda1a39 SC |
44 | generally this would be one for each machine and one for the |
45 | default case (an item with a machine field of 0). | |
c188b0be DM |
46 | |
47 | BFD's idea of an architecture is implemented in <<archures.c>>. | |
c618de01 SC |
48 | */ |
49 | ||
9fda1a39 SC |
50 | /* |
51 | ||
52 | SUBSECTION | |
53 | bfd_architecture | |
54 | ||
55 | DESCRIPTION | |
56 | This enum gives the object file's CPU architecture, in a | |
c188b0be DM |
57 | global sense---i.e., what processor family does it belong to? |
58 | Another field indicates which processor within | |
9fda1a39 | 59 | the family is in use. The machine gives a number which |
c188b0be DM |
60 | distinguishes different versions of the architecture, |
61 | containing, for example, 2 and 3 for Intel i960 KA and i960 KB, | |
9fda1a39 SC |
62 | and 68020 and 68030 for Motorola 68020 and 68030. |
63 | ||
64 | .enum bfd_architecture | |
65 | .{ | |
66 | . bfd_arch_unknown, {* File arch not known *} | |
67 | . bfd_arch_obscure, {* Arch known, not one of these *} | |
68 | . bfd_arch_m68k, {* Motorola 68xxx *} | |
69 | . bfd_arch_vax, {* DEC Vax *} | |
70 | . bfd_arch_i960, {* Intel 960 *} | |
71 | . {* The order of the following is important. | |
72 | . lower number indicates a machine type that | |
73 | . only accepts a subset of the instructions | |
74 | . available to machines with higher numbers. | |
75 | . The exception is the "ca", which is | |
76 | . incompatible with all other machines except | |
77 | . "core". *} | |
78 | . | |
79 | .#define bfd_mach_i960_core 1 | |
80 | .#define bfd_mach_i960_ka_sa 2 | |
81 | .#define bfd_mach_i960_kb_sb 3 | |
82 | .#define bfd_mach_i960_mc 4 | |
83 | .#define bfd_mach_i960_xa 5 | |
84 | .#define bfd_mach_i960_ca 6 | |
85 | . | |
86 | . bfd_arch_a29k, {* AMD 29000 *} | |
87 | . bfd_arch_sparc, {* SPARC *} | |
88 | . bfd_arch_mips, {* MIPS Rxxxx *} | |
89 | . bfd_arch_i386, {* Intel 386 *} | |
71c0bae0 | 90 | . bfd_arch_we32k, {* AT&T WE32xxx *} |
9fda1a39 SC |
91 | . bfd_arch_tahoe, {* CCI/Harris Tahoe *} |
92 | . bfd_arch_i860, {* Intel 860 *} | |
93 | . bfd_arch_romp, {* IBM ROMP PC/RT *} | |
94 | . bfd_arch_alliant, {* Alliant *} | |
95 | . bfd_arch_convex, {* Convex *} | |
96 | . bfd_arch_m88k, {* Motorola 88xxx *} | |
97 | . bfd_arch_pyramid, {* Pyramid Technology *} | |
98 | . bfd_arch_h8300, {* Hitachi H8/300 *} | |
2e235c93 ILT |
99 | .#define bfd_mach_h8300 1 |
100 | .#define bfd_mach_h8300h 2 | |
9fda1a39 | 101 | . bfd_arch_rs6000, {* IBM RS/6000 *} |
e3c01e92 | 102 | . bfd_arch_hppa, {* HP PA RISC *} |
71c0bae0 KR |
103 | . bfd_arch_z8k, {* Zilog Z8000 *} |
104 | .#define bfd_mach_z8001 1 | |
105 | .#define bfd_mach_z8002 2 | |
2e235c93 ILT |
106 | . bfd_arch_h8500, {* Hitachi H8/500 *} |
107 | . bfd_arch_sh, {* Hitachi SH *} | |
108 | . bfd_arch_alpha, {* Dec Alpha *} | |
9fda1a39 SC |
109 | . bfd_arch_last |
110 | . }; | |
c618de01 | 111 | |
c618de01 SC |
112 | |
113 | */ | |
114 | ||
4a81b561 | 115 | #include "bfd.h" |
cbdc7909 | 116 | #include "sysdep.h" |
4e6f9223 SC |
117 | #include "libbfd.h" |
118 | ||
9fda1a39 SC |
119 | /* |
120 | ||
121 | SUBSECTION | |
122 | bfd_arch_info | |
123 | ||
124 | DESCRIPTION | |
125 | This structure contains information on architectures for use | |
126 | within BFD. | |
127 | ||
9fda1a39 SC |
128 | . |
129 | .typedef struct bfd_arch_info | |
130 | .{ | |
131 | . int bits_per_word; | |
132 | . int bits_per_address; | |
133 | . int bits_per_byte; | |
134 | . enum bfd_architecture arch; | |
135 | . long mach; | |
136 | . char *arch_name; | |
137 | . CONST char *printable_name; | |
ce07dd7c KR |
138 | . unsigned int section_align_power; |
139 | . {* true if this is the default machine for the architecture *} | |
9fda1a39 | 140 | . boolean the_default; |
71c0bae0 KR |
141 | . CONST struct bfd_arch_info * (*compatible) |
142 | . PARAMS ((CONST struct bfd_arch_info *a, | |
143 | . CONST struct bfd_arch_info *b)); | |
9fda1a39 | 144 | . |
71c0bae0 KR |
145 | . boolean (*scan) PARAMS ((CONST struct bfd_arch_info *, CONST char *)); |
146 | . {* How to disassemble an instruction, producing a printable | |
147 | . representation on a specified stdio stream. This isn't | |
148 | . defined for most processors at present, because of the size | |
149 | . of the additional tables it would drag in, and because gdb | |
150 | . wants to use a different interface. *} | |
151 | . unsigned int (*disassemble) PARAMS ((bfd_vma addr, CONST char *data, | |
152 | . PTR stream)); | |
9fda1a39 | 153 | . |
ce07dd7c | 154 | . struct bfd_arch_info *next; |
9fda1a39 | 155 | .} bfd_arch_info_type; |
4e6f9223 SC |
156 | */ |
157 | ||
cbdc7909 | 158 | bfd_arch_info_type *bfd_arch_info_list; |
4a81b561 | 159 | |
4a81b561 | 160 | |
9fda1a39 | 161 | /* |
9fda1a39 SC |
162 | FUNCTION |
163 | bfd_printable_name | |
4e6f9223 | 164 | |
ce07dd7c KR |
165 | SYNOPSIS |
166 | CONST char *bfd_printable_name(bfd *abfd); | |
167 | ||
9fda1a39 SC |
168 | DESCRIPTION |
169 | Return a printable string representing the architecture and machine | |
c188b0be | 170 | from the pointer to the architecture info structure. |
4e6f9223 | 171 | |
4e6f9223 SC |
172 | */ |
173 | ||
174 | CONST char * | |
175 | DEFUN(bfd_printable_name, (abfd), | |
176 | bfd *abfd) | |
177 | { | |
178 | return abfd->arch_info->printable_name; | |
4a81b561 DHW |
179 | } |
180 | ||
4e6f9223 SC |
181 | |
182 | ||
9fda1a39 SC |
183 | /* |
184 | FUNCTION | |
185 | bfd_scan_arch | |
4e6f9223 | 186 | |
ce07dd7c | 187 | SYNOPSIS |
c188b0be | 188 | bfd_arch_info_type *bfd_scan_arch(CONST char *string); |
ce07dd7c | 189 | |
9fda1a39 | 190 | DESCRIPTION |
c188b0be DM |
191 | Figure out if BFD supports any cpu which could be described with |
192 | the name @var{string}. Return a pointer to an <<arch_info>> | |
9fda1a39 SC |
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 |
c188b0be DM |
226 | Determine whether two BFDs' |
227 | architectures and machine types are compatible. Calculates | |
9fda1a39 SC |
228 | the lowest common denominator between the two architectures |
229 | and machine types implied by the BFDs and returns a pointer to | |
c188b0be | 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 | 270 | SYNOPSIS |
c188b0be | 271 | void bfd_set_arch_info(bfd *abfd, bfd_arch_info_type *arg); |
4e6f9223 | 272 | |
c188b0be DM |
273 | DESCRIPTION |
274 | Set the architecture info of @var{abfd} to @var{arg}. | |
4e6f9223 SC |
275 | */ |
276 | ||
277 | void DEFUN(bfd_set_arch_info,(abfd, arg), | |
278 | bfd *abfd AND | |
cbdc7909 | 279 | bfd_arch_info_type *arg) |
4a81b561 | 280 | { |
4e6f9223 SC |
281 | abfd->arch_info = arg; |
282 | } | |
283 | ||
9fda1a39 | 284 | /* |
ce07dd7c | 285 | INTERNAL_FUNCTION |
9fda1a39 SC |
286 | bfd_default_set_arch_mach |
287 | ||
9fda1a39 SC |
288 | SYNOPSIS |
289 | boolean bfd_default_set_arch_mach(bfd *abfd, | |
290 | enum bfd_architecture arch, | |
291 | unsigned long mach); | |
4e6f9223 | 292 | |
ce07dd7c | 293 | DESCRIPTION |
c188b0be DM |
294 | Set the architecture and machine type in BFD @var{abfd} |
295 | to @var{arch} and @var{mach}. Find the correct | |
296 | pointer to a structure and insert it into the <<arch_info>> | |
ce07dd7c | 297 | pointer. |
4e6f9223 SC |
298 | */ |
299 | ||
300 | boolean DEFUN(bfd_default_set_arch_mach,(abfd, arch, mach), | |
301 | bfd *abfd AND | |
302 | enum bfd_architecture arch AND | |
303 | unsigned long mach) | |
304 | { | |
cbdc7909 | 305 | static struct bfd_arch_info *old_ptr = &bfd_default_arch_struct; |
4e6f9223 SC |
306 | boolean found = false; |
307 | /* run through the table to find the one we want, we keep a little | |
308 | cache to speed things up */ | |
309 | if (old_ptr == 0 || arch != old_ptr->arch || mach != old_ptr->mach) { | |
cbdc7909 JG |
310 | bfd_arch_info_type *ptr; |
311 | old_ptr = (bfd_arch_info_type *)NULL; | |
4e6f9223 | 312 | for (ptr = bfd_arch_info_list; |
cbdc7909 | 313 | ptr != (bfd_arch_info_type *)NULL; |
4e6f9223 SC |
314 | ptr= ptr->next) { |
315 | if (ptr->arch == arch && | |
316 | ((ptr->mach == mach) || (ptr->the_default && mach == 0))) { | |
317 | old_ptr = ptr; | |
318 | found = true; | |
319 | break; | |
320 | } | |
4a81b561 | 321 | } |
4e6f9223 SC |
322 | if (found==false) { |
323 | /*looked for it and it wasn't there, so put in the default */ | |
324 | old_ptr = &bfd_default_arch_struct; | |
2e235c93 | 325 | bfd_error = bad_value; |
4e6f9223 SC |
326 | } |
327 | } | |
328 | else { | |
329 | /* it was in the cache */ | |
330 | found = true; | |
4a81b561 DHW |
331 | } |
332 | ||
4e6f9223 SC |
333 | abfd->arch_info = old_ptr; |
334 | ||
335 | return found; | |
4a81b561 | 336 | } |
4a81b561 | 337 | |
4e6f9223 | 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 | 346 | DESCRIPTION |
c188b0be DM |
347 | Return the enumerated type which describes the BFD @var{abfd}'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 | 364 | DESCRIPTION |
c188b0be DM |
365 | Return the long type which describes the BFD @var{abfd}'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 | 382 | DESCRIPTION |
c188b0be DM |
383 | Return the number of bits in one of the BFD @var{abfd}'s |
384 | architecture's bytes. | |
4e6f9223 | 385 | |
4e6f9223 SC |
386 | */ |
387 | ||
388 | unsigned int DEFUN(bfd_arch_bits_per_byte, (abfd), bfd *abfd) | |
c188b0be DM |
389 | { |
390 | return abfd->arch_info->bits_per_byte; | |
391 | } | |
4e6f9223 | 392 | |
9fda1a39 SC |
393 | /* |
394 | FUNCTION | |
395 | bfd_arch_bits_per_address | |
4e6f9223 | 396 | |
9fda1a39 SC |
397 | SYNOPSIS |
398 | unsigned int bfd_arch_bits_per_address(bfd *abfd); | |
ce07dd7c KR |
399 | |
400 | DESCRIPTION | |
c188b0be DM |
401 | Return the number of bits in one of the BFD @var{abfd}'s |
402 | architecture's addresses. | |
4e6f9223 SC |
403 | */ |
404 | ||
405 | unsigned int DEFUN(bfd_arch_bits_per_address, (abfd), bfd *abfd) | |
c188b0be DM |
406 | { |
407 | return abfd->arch_info->bits_per_address; | |
408 | } | |
4e6f9223 SC |
409 | |
410 | ||
c188b0be DM |
411 | extern void bfd_a29k_arch PARAMS ((void)); |
412 | extern void bfd_alpha_arch PARAMS ((void)); | |
71c0bae0 | 413 | extern void bfd_h8300_arch PARAMS ((void)); |
2e235c93 | 414 | extern void bfd_h8500_arch PARAMS ((void)); |
c188b0be DM |
415 | extern void bfd_hppa_arch PARAMS ((void)); |
416 | extern void bfd_i386_arch PARAMS ((void)); | |
71c0bae0 | 417 | extern void bfd_i960_arch PARAMS ((void)); |
71c0bae0 | 418 | extern void bfd_m68k_arch PARAMS ((void)); |
c188b0be | 419 | extern void bfd_m88k_arch PARAMS ((void)); |
71c0bae0 | 420 | extern void bfd_mips_arch PARAMS ((void)); |
71c0bae0 | 421 | extern void bfd_rs6000_arch PARAMS ((void)); |
c188b0be DM |
422 | extern void bfd_sh_arch PARAMS ((void)); |
423 | extern void bfd_sparc_arch PARAMS ((void)); | |
424 | extern void bfd_vax_arch PARAMS ((void)); | |
71c0bae0 | 425 | extern void bfd_we32k_arch PARAMS ((void)); |
c188b0be | 426 | extern void bfd_z8k_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 | 459 | SYNOPSIS |
c188b0be | 460 | void bfd_arch_init(void); |
ce07dd7c | 461 | |
9fda1a39 | 462 | DESCRIPTION |
c188b0be | 463 | Initialize the architecture dispatch table by |
9fda1a39 SC |
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 | 485 | SYNOPSIS |
c188b0be | 486 | void bfd_arch_linkin(bfd_arch_info_type *ptr); |
4e6f9223 | 487 | |
ce07dd7c | 488 | DESCRIPTION |
c188b0be | 489 | Link the architecture info structure @var{ptr} 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 | 534 | SYNOPSIS |
c188b0be | 535 | boolean bfd_default_scan(CONST struct bfd_arch_info *info, CONST char *string); |
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 | ||
9fda1a39 SC |
652 | /* |
653 | FUNCTION | |
654 | bfd_get_arch_info | |
c618de01 | 655 | |
9fda1a39 | 656 | SYNOPSIS |
c188b0be | 657 | bfd_arch_info_type * bfd_get_arch_info(bfd *abfd); |
c618de01 | 658 | |
c188b0be DM |
659 | DESCRIPTION |
660 | Return the architecture info struct in @var{abfd}. | |
4e6f9223 | 661 | */ |
c618de01 | 662 | |
cbdc7909 | 663 | bfd_arch_info_type * |
4e6f9223 SC |
664 | DEFUN(bfd_get_arch_info,(abfd), |
665 | bfd *abfd) | |
666 | { | |
667 | return abfd->arch_info; | |
668 | } | |
cbdc7909 JG |
669 | |
670 | ||
9fda1a39 SC |
671 | /* |
672 | FUNCTION | |
673 | bfd_lookup_arch | |
674 | ||
9fda1a39 SC |
675 | SYNOPSIS |
676 | bfd_arch_info_type *bfd_lookup_arch | |
677 | (enum bfd_architecture | |
678 | arch, | |
679 | long machine); | |
cbdc7909 | 680 | |
ce07dd7c | 681 | DESCRIPTION |
c188b0be DM |
682 | Look for the architecure info structure which matches the |
683 | arguments @var{arch} and @var{machine}. A machine of 0 matches the | |
ce07dd7c KR |
684 | machine/architecture structure which marks itself as the |
685 | default. | |
cbdc7909 JG |
686 | */ |
687 | ||
688 | bfd_arch_info_type * | |
689 | DEFUN(bfd_lookup_arch,(arch, machine), | |
690 | enum bfd_architecture arch AND | |
691 | long machine) | |
692 | { | |
9fda1a39 SC |
693 | bfd_arch_info_type *ap; |
694 | bfd_check_init(); | |
695 | for (ap = bfd_arch_info_list; | |
696 | ap != (bfd_arch_info_type *)NULL; | |
697 | ap = ap->next) { | |
698 | if (ap->arch == arch && | |
699 | ((ap->mach == machine) | |
700 | || (ap->the_default && machine == 0))) { | |
701 | return ap; | |
702 | } | |
703 | } | |
704 | return (bfd_arch_info_type *)NULL; | |
cbdc7909 JG |
705 | } |
706 | ||
707 | ||
9fda1a39 SC |
708 | /* |
709 | FUNCTION | |
710 | bfd_printable_arch_mach | |
711 | ||
ce07dd7c | 712 | SYNOPSIS |
c188b0be | 713 | CONST char *bfd_printable_arch_mach |
ce07dd7c KR |
714 | (enum bfd_architecture arch, unsigned long machine); |
715 | ||
9fda1a39 SC |
716 | DESCRIPTION |
717 | Return a printable string representing the architecture and | |
718 | machine type. | |
cbdc7909 | 719 | |
c188b0be | 720 | This routine is depreciated. |
cbdc7909 JG |
721 | */ |
722 | ||
723 | CONST char * | |
724 | DEFUN(bfd_printable_arch_mach,(arch, machine), | |
725 | enum bfd_architecture arch AND | |
726 | unsigned long machine) | |
727 | { | |
9fda1a39 SC |
728 | bfd_arch_info_type *ap = bfd_lookup_arch(arch, machine); |
729 | if(ap) return ap->printable_name; | |
730 | return "UNKNOWN!"; | |
cbdc7909 | 731 | } |