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