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