]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for ieee-695 objects. |
219d1afa | 2 | Copyright (C) 1990-2018 Free Software Foundation, Inc. |
252b5132 RH |
3 | |
4 | Written by Steve Chamberlain of Cygnus Support. | |
5 | ||
ca09e32b | 6 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 7 | |
ca09e32b NC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 10 | the Free Software Foundation; either version 3 of the License, or |
ca09e32b | 11 | (at your option) any later version. |
252b5132 | 12 | |
ca09e32b NC |
13 | This program is distributed in the hope that it will be useful, |
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. | |
252b5132 | 17 | |
ca09e32b NC |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
cd123cb7 NC |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | MA 02110-1301, USA. */ | |
22 | ||
252b5132 RH |
23 | |
24 | #define KEEPMINUSPCININST 0 | |
25 | ||
26 | /* IEEE 695 format is a stream of records, which we parse using a simple one- | |
27 | token (which is one byte in this lexicon) lookahead recursive decent | |
28 | parser. */ | |
29 | ||
252b5132 | 30 | #include "sysdep.h" |
3db64b00 | 31 | #include "bfd.h" |
252b5132 RH |
32 | #include "libbfd.h" |
33 | #include "ieee.h" | |
34 | #include "libieee.h" | |
3882b010 | 35 | #include "safe-ctype.h" |
1be5090b | 36 | #include "libiberty.h" |
252b5132 | 37 | |
47fda0d3 AM |
38 | struct output_buffer_struct |
39 | { | |
40 | unsigned char *ptrp; | |
41 | int buffer; | |
42 | }; | |
43 | ||
46e94266 NC |
44 | static unsigned char *output_ptr_start; |
45 | static unsigned char *output_ptr; | |
46 | static unsigned char *output_ptr_end; | |
47 | static unsigned char *input_ptr_start; | |
48 | static unsigned char *input_ptr; | |
49 | static unsigned char *input_ptr_end; | |
50 | static bfd *input_bfd; | |
51 | static bfd *output_bfd; | |
52 | static int output_buffer; | |
53 | ||
54 | ||
55 | static void block (void); | |
56 | ||
252b5132 | 57 | /* Functions for writing to ieee files in the strange way that the |
c8e7bf0d | 58 | standard requires. */ |
252b5132 | 59 | |
b34976b6 | 60 | static bfd_boolean |
c8e7bf0d | 61 | ieee_write_byte (bfd *abfd, int barg) |
252b5132 RH |
62 | { |
63 | bfd_byte byte; | |
64 | ||
65 | byte = barg; | |
c8e7bf0d | 66 | if (bfd_bwrite ((void *) &byte, (bfd_size_type) 1, abfd) != 1) |
b34976b6 AM |
67 | return FALSE; |
68 | return TRUE; | |
252b5132 RH |
69 | } |
70 | ||
b34976b6 | 71 | static bfd_boolean |
c8e7bf0d | 72 | ieee_write_2bytes (bfd *abfd, int bytes) |
252b5132 RH |
73 | { |
74 | bfd_byte buffer[2]; | |
75 | ||
76 | buffer[0] = bytes >> 8; | |
77 | buffer[1] = bytes & 0xff; | |
c8e7bf0d | 78 | if (bfd_bwrite ((void *) buffer, (bfd_size_type) 2, abfd) != 2) |
b34976b6 AM |
79 | return FALSE; |
80 | return TRUE; | |
252b5132 RH |
81 | } |
82 | ||
b34976b6 | 83 | static bfd_boolean |
c8e7bf0d | 84 | ieee_write_int (bfd *abfd, bfd_vma value) |
252b5132 RH |
85 | { |
86 | if (value <= 127) | |
87 | { | |
88 | if (! ieee_write_byte (abfd, (bfd_byte) value)) | |
b34976b6 | 89 | return FALSE; |
252b5132 RH |
90 | } |
91 | else | |
92 | { | |
93 | unsigned int length; | |
94 | ||
49ae03bf NC |
95 | /* How many significant bytes ? */ |
96 | /* FIXME FOR LONGER INTS. */ | |
252b5132 RH |
97 | if (value & 0xff000000) |
98 | length = 4; | |
99 | else if (value & 0x00ff0000) | |
100 | length = 3; | |
101 | else if (value & 0x0000ff00) | |
102 | length = 2; | |
103 | else | |
104 | length = 1; | |
105 | ||
106 | if (! ieee_write_byte (abfd, | |
107 | (bfd_byte) ((int) ieee_number_repeat_start_enum | |
108 | + length))) | |
b34976b6 | 109 | return FALSE; |
252b5132 RH |
110 | switch (length) |
111 | { | |
112 | case 4: | |
113 | if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24))) | |
b34976b6 | 114 | return FALSE; |
252b5132 RH |
115 | /* Fall through. */ |
116 | case 3: | |
117 | if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16))) | |
b34976b6 | 118 | return FALSE; |
252b5132 RH |
119 | /* Fall through. */ |
120 | case 2: | |
121 | if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8))) | |
b34976b6 | 122 | return FALSE; |
252b5132 RH |
123 | /* Fall through. */ |
124 | case 1: | |
125 | if (! ieee_write_byte (abfd, (bfd_byte) (value))) | |
b34976b6 | 126 | return FALSE; |
252b5132 RH |
127 | } |
128 | } | |
129 | ||
b34976b6 | 130 | return TRUE; |
252b5132 RH |
131 | } |
132 | ||
b34976b6 | 133 | static bfd_boolean |
c8e7bf0d | 134 | ieee_write_id (bfd *abfd, const char *id) |
252b5132 RH |
135 | { |
136 | size_t length = strlen (id); | |
137 | ||
138 | if (length <= 127) | |
139 | { | |
140 | if (! ieee_write_byte (abfd, (bfd_byte) length)) | |
b34976b6 | 141 | return FALSE; |
252b5132 RH |
142 | } |
143 | else if (length < 255) | |
144 | { | |
145 | if (! ieee_write_byte (abfd, ieee_extension_length_1_enum) | |
146 | || ! ieee_write_byte (abfd, (bfd_byte) length)) | |
b34976b6 | 147 | return FALSE; |
252b5132 RH |
148 | } |
149 | else if (length < 65535) | |
150 | { | |
151 | if (! ieee_write_byte (abfd, ieee_extension_length_2_enum) | |
152 | || ! ieee_write_2bytes (abfd, (int) length)) | |
b34976b6 | 153 | return FALSE; |
252b5132 RH |
154 | } |
155 | else | |
156 | { | |
4eca0228 | 157 | _bfd_error_handler |
695344c0 | 158 | /* xgettext:c-format */ |
871b3ab2 | 159 | (_("%pB: string too long (%ld chars, max 65535)"), abfd, (long) length); |
252b5132 | 160 | bfd_set_error (bfd_error_invalid_operation); |
b34976b6 | 161 | return FALSE; |
252b5132 RH |
162 | } |
163 | ||
c8e7bf0d | 164 | if (bfd_bwrite ((void *) id, (bfd_size_type) length, abfd) != length) |
b34976b6 AM |
165 | return FALSE; |
166 | return TRUE; | |
252b5132 RH |
167 | } |
168 | \f | |
49ae03bf NC |
169 | /* Functions for reading from ieee files in the strange way that the |
170 | standard requires. */ | |
252b5132 | 171 | |
07d6d2b8 | 172 | #define this_byte(ieee) *((ieee)->input_p) |
acb56a83 | 173 | #define this_byte_and_next(ieee) ((ieee)->input_p < (ieee)->end_p ? *((ieee)->input_p++) : 0) |
252b5132 | 174 | |
0a9d414a NC |
175 | static bfd_boolean |
176 | next_byte (common_header_type * ieee) | |
177 | { | |
178 | ieee->input_p++; | |
179 | ||
180 | return ieee->input_p < ieee->last_byte; | |
181 | } | |
182 | ||
252b5132 | 183 | static unsigned short |
c8e7bf0d | 184 | read_2bytes (common_header_type *ieee) |
252b5132 RH |
185 | { |
186 | unsigned char c1 = this_byte_and_next (ieee); | |
187 | unsigned char c2 = this_byte_and_next (ieee); | |
49ae03bf | 188 | |
252b5132 RH |
189 | return (c1 << 8) | c2; |
190 | } | |
191 | ||
192 | static void | |
c8e7bf0d | 193 | bfd_get_string (common_header_type *ieee, char *string, size_t length) |
252b5132 RH |
194 | { |
195 | size_t i; | |
49ae03bf | 196 | |
252b5132 | 197 | for (i = 0; i < length; i++) |
49ae03bf | 198 | string[i] = this_byte_and_next (ieee); |
252b5132 RH |
199 | } |
200 | ||
201 | static char * | |
c8e7bf0d | 202 | read_id (common_header_type *ieee) |
252b5132 RH |
203 | { |
204 | size_t length; | |
205 | char *string; | |
49ae03bf | 206 | |
252b5132 RH |
207 | length = this_byte_and_next (ieee); |
208 | if (length <= 0x7f) | |
c8e7bf0d NC |
209 | /* Simple string of length 0 to 127. */ |
210 | ; | |
211 | ||
252b5132 | 212 | else if (length == 0xde) |
c8e7bf0d NC |
213 | /* Length is next byte, allowing 0..255. */ |
214 | length = this_byte_and_next (ieee); | |
215 | ||
252b5132 RH |
216 | else if (length == 0xdf) |
217 | { | |
49ae03bf | 218 | /* Length is next two bytes, allowing 0..65535. */ |
252b5132 RH |
219 | length = this_byte_and_next (ieee); |
220 | length = (length * 256) + this_byte_and_next (ieee); | |
221 | } | |
49ae03bf | 222 | |
acb56a83 NC |
223 | /* PR 21612: Check for an invalid length. */ |
224 | if (ieee->input_p + length >= ieee->end_p) | |
225 | { | |
226 | _bfd_error_handler (_("IEEE parser: string length: %#lx longer than buffer: %#lx"), | |
d42c267e | 227 | (long) length, (long) (ieee->end_p - ieee->input_p)); |
acb56a83 NC |
228 | bfd_set_error (bfd_error_invalid_operation); |
229 | return NULL; | |
230 | } | |
231 | ||
49ae03bf | 232 | /* Buy memory and read string. */ |
dc810e39 | 233 | string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1); |
252b5132 RH |
234 | if (!string) |
235 | return NULL; | |
236 | bfd_get_string (ieee, string, length); | |
237 | string[length] = 0; | |
238 | return string; | |
239 | } | |
240 | ||
b34976b6 | 241 | static bfd_boolean |
c8e7bf0d NC |
242 | ieee_write_expression (bfd *abfd, |
243 | bfd_vma value, | |
244 | asymbol *symbol, | |
245 | bfd_boolean pcrel, | |
91d6fa6a | 246 | unsigned int sindex) |
252b5132 RH |
247 | { |
248 | unsigned int term_count = 0; | |
249 | ||
250 | if (value != 0) | |
251 | { | |
252 | if (! ieee_write_int (abfd, value)) | |
b34976b6 | 253 | return FALSE; |
252b5132 RH |
254 | term_count++; |
255 | } | |
256 | ||
49ae03bf NC |
257 | /* Badly formatted binaries can have a missing symbol, |
258 | so test here to prevent a seg fault. */ | |
259 | if (symbol != NULL) | |
252b5132 | 260 | { |
49ae03bf NC |
261 | if (bfd_is_com_section (symbol->section) |
262 | || bfd_is_und_section (symbol->section)) | |
252b5132 | 263 | { |
49ae03bf NC |
264 | /* Def of a common symbol. */ |
265 | if (! ieee_write_byte (abfd, ieee_variable_X_enum) | |
252b5132 | 266 | || ! ieee_write_int (abfd, symbol->value)) |
b34976b6 | 267 | return FALSE; |
49ae03bf | 268 | term_count ++; |
252b5132 | 269 | } |
49ae03bf | 270 | else if (! bfd_is_abs_section (symbol->section)) |
252b5132 | 271 | { |
49ae03bf | 272 | /* Ref to defined symbol - */ |
49ae03bf | 273 | if (symbol->flags & BSF_GLOBAL) |
252b5132 | 274 | { |
49ae03bf NC |
275 | if (! ieee_write_byte (abfd, ieee_variable_I_enum) |
276 | || ! ieee_write_int (abfd, symbol->value)) | |
b34976b6 | 277 | return FALSE; |
252b5132 RH |
278 | term_count++; |
279 | } | |
49ae03bf NC |
280 | else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM)) |
281 | { | |
282 | /* This is a reference to a defined local symbol. We can | |
283 | easily do a local as a section+offset. */ | |
284 | if (! ieee_write_byte (abfd, ieee_variable_R_enum) | |
285 | || ! ieee_write_byte (abfd, | |
286 | (bfd_byte) (symbol->section->index | |
287 | + IEEE_SECTION_NUMBER_BASE))) | |
288 | return FALSE; | |
289 | ||
290 | term_count++; | |
291 | if (symbol->value != 0) | |
292 | { | |
293 | if (! ieee_write_int (abfd, symbol->value)) | |
294 | return FALSE; | |
295 | term_count++; | |
296 | } | |
297 | } | |
298 | else | |
299 | { | |
4eca0228 | 300 | _bfd_error_handler |
695344c0 | 301 | /* xgettext:c-format */ |
871b3ab2 | 302 | (_("%pB: unrecognized symbol `%s' flags 0x%x"), |
dae82561 | 303 | abfd, bfd_asymbol_name (symbol), symbol->flags); |
49ae03bf NC |
304 | bfd_set_error (bfd_error_invalid_operation); |
305 | return FALSE; | |
306 | } | |
252b5132 RH |
307 | } |
308 | } | |
309 | ||
310 | if (pcrel) | |
311 | { | |
49ae03bf | 312 | /* Subtract the pc from here by asking for PC of this section. */ |
252b5132 RH |
313 | if (! ieee_write_byte (abfd, ieee_variable_P_enum) |
314 | || ! ieee_write_byte (abfd, | |
91d6fa6a | 315 | (bfd_byte) (sindex + IEEE_SECTION_NUMBER_BASE)) |
252b5132 | 316 | || ! ieee_write_byte (abfd, ieee_function_minus_enum)) |
b34976b6 | 317 | return FALSE; |
252b5132 RH |
318 | } |
319 | ||
320 | /* Handle the degenerate case of a 0 address. */ | |
321 | if (term_count == 0) | |
49ae03bf NC |
322 | if (! ieee_write_int (abfd, (bfd_vma) 0)) |
323 | return FALSE; | |
252b5132 RH |
324 | |
325 | while (term_count > 1) | |
326 | { | |
327 | if (! ieee_write_byte (abfd, ieee_function_plus_enum)) | |
b34976b6 | 328 | return FALSE; |
252b5132 RH |
329 | term_count--; |
330 | } | |
331 | ||
b34976b6 | 332 | return TRUE; |
252b5132 RH |
333 | } |
334 | \f | |
49ae03bf | 335 | /* Writes any integer into the buffer supplied and always takes 5 bytes. */ |
252b5132 | 336 | |
252b5132 | 337 | static void |
c8e7bf0d | 338 | ieee_write_int5 (bfd_byte *buffer, bfd_vma value) |
252b5132 RH |
339 | { |
340 | buffer[0] = (bfd_byte) ieee_number_repeat_4_enum; | |
341 | buffer[1] = (value >> 24) & 0xff; | |
342 | buffer[2] = (value >> 16) & 0xff; | |
343 | buffer[3] = (value >> 8) & 0xff; | |
344 | buffer[4] = (value >> 0) & 0xff; | |
345 | } | |
346 | ||
b34976b6 | 347 | static bfd_boolean |
c8e7bf0d | 348 | ieee_write_int5_out (bfd *abfd, bfd_vma value) |
252b5132 RH |
349 | { |
350 | bfd_byte b[5]; | |
351 | ||
352 | ieee_write_int5 (b, value); | |
c8e7bf0d | 353 | if (bfd_bwrite ((void *) b, (bfd_size_type) 5, abfd) != 5) |
b34976b6 AM |
354 | return FALSE; |
355 | return TRUE; | |
252b5132 RH |
356 | } |
357 | ||
b34976b6 | 358 | static bfd_boolean |
c8e7bf0d | 359 | parse_int (common_header_type *ieee, bfd_vma *value_ptr) |
252b5132 RH |
360 | { |
361 | int value = this_byte (ieee); | |
362 | int result; | |
49ae03bf | 363 | |
252b5132 RH |
364 | if (value >= 0 && value <= 127) |
365 | { | |
366 | *value_ptr = value; | |
0a9d414a | 367 | return next_byte (ieee); |
252b5132 RH |
368 | } |
369 | else if (value >= 0x80 && value <= 0x88) | |
370 | { | |
371 | unsigned int count = value & 0xf; | |
49ae03bf | 372 | |
252b5132 | 373 | result = 0; |
0a9d414a NC |
374 | if (! next_byte (ieee)) |
375 | return FALSE; | |
252b5132 RH |
376 | while (count) |
377 | { | |
378 | result = (result << 8) | this_byte_and_next (ieee); | |
379 | count--; | |
380 | } | |
381 | *value_ptr = result; | |
b34976b6 | 382 | return TRUE; |
252b5132 | 383 | } |
b34976b6 | 384 | return FALSE; |
252b5132 RH |
385 | } |
386 | ||
387 | static int | |
c8e7bf0d | 388 | parse_i (common_header_type *ieee, bfd_boolean *ok) |
252b5132 | 389 | { |
1b0b5b1b | 390 | bfd_vma x = 0; |
252b5132 RH |
391 | *ok = parse_int (ieee, &x); |
392 | return x; | |
393 | } | |
394 | ||
395 | static bfd_vma | |
46e94266 | 396 | must_parse_int (common_header_type *ieee) |
252b5132 | 397 | { |
1b0b5b1b | 398 | bfd_vma result = 0; |
82e51918 | 399 | BFD_ASSERT (parse_int (ieee, &result)); |
252b5132 RH |
400 | return result; |
401 | } | |
402 | ||
403 | typedef struct | |
404 | { | |
405 | bfd_vma value; | |
406 | asection *section; | |
407 | ieee_symbol_index_type symbol; | |
408 | } ieee_value_type; | |
409 | ||
410 | ||
411 | #if KEEPMINUSPCININST | |
412 | ||
413 | #define SRC_MASK(arg) arg | |
b34976b6 | 414 | #define PCREL_OFFSET FALSE |
252b5132 RH |
415 | |
416 | #else | |
417 | ||
418 | #define SRC_MASK(arg) 0 | |
b34976b6 | 419 | #define PCREL_OFFSET TRUE |
252b5132 RH |
420 | |
421 | #endif | |
422 | ||
423 | static reloc_howto_type abs32_howto = | |
424 | HOWTO (1, | |
425 | 0, | |
426 | 2, | |
427 | 32, | |
b34976b6 | 428 | FALSE, |
252b5132 RH |
429 | 0, |
430 | complain_overflow_bitfield, | |
431 | 0, | |
432 | "abs32", | |
b34976b6 | 433 | TRUE, |
252b5132 RH |
434 | 0xffffffff, |
435 | 0xffffffff, | |
b34976b6 | 436 | FALSE); |
252b5132 RH |
437 | |
438 | static reloc_howto_type abs16_howto = | |
439 | HOWTO (1, | |
440 | 0, | |
441 | 1, | |
442 | 16, | |
b34976b6 | 443 | FALSE, |
252b5132 RH |
444 | 0, |
445 | complain_overflow_bitfield, | |
446 | 0, | |
447 | "abs16", | |
b34976b6 | 448 | TRUE, |
252b5132 RH |
449 | 0x0000ffff, |
450 | 0x0000ffff, | |
b34976b6 | 451 | FALSE); |
252b5132 RH |
452 | |
453 | static reloc_howto_type abs8_howto = | |
454 | HOWTO (1, | |
455 | 0, | |
456 | 0, | |
457 | 8, | |
b34976b6 | 458 | FALSE, |
252b5132 RH |
459 | 0, |
460 | complain_overflow_bitfield, | |
461 | 0, | |
462 | "abs8", | |
b34976b6 | 463 | TRUE, |
252b5132 RH |
464 | 0x000000ff, |
465 | 0x000000ff, | |
b34976b6 | 466 | FALSE); |
252b5132 RH |
467 | |
468 | static reloc_howto_type rel32_howto = | |
469 | HOWTO (1, | |
470 | 0, | |
471 | 2, | |
472 | 32, | |
b34976b6 | 473 | TRUE, |
252b5132 RH |
474 | 0, |
475 | complain_overflow_signed, | |
476 | 0, | |
477 | "rel32", | |
b34976b6 | 478 | TRUE, |
252b5132 RH |
479 | SRC_MASK (0xffffffff), |
480 | 0xffffffff, | |
481 | PCREL_OFFSET); | |
482 | ||
483 | static reloc_howto_type rel16_howto = | |
484 | HOWTO (1, | |
485 | 0, | |
486 | 1, | |
487 | 16, | |
b34976b6 | 488 | TRUE, |
252b5132 RH |
489 | 0, |
490 | complain_overflow_signed, | |
491 | 0, | |
492 | "rel16", | |
b34976b6 | 493 | TRUE, |
252b5132 RH |
494 | SRC_MASK (0x0000ffff), |
495 | 0x0000ffff, | |
496 | PCREL_OFFSET); | |
497 | ||
498 | static reloc_howto_type rel8_howto = | |
499 | HOWTO (1, | |
500 | 0, | |
501 | 0, | |
502 | 8, | |
b34976b6 | 503 | TRUE, |
252b5132 RH |
504 | 0, |
505 | complain_overflow_signed, | |
506 | 0, | |
507 | "rel8", | |
b34976b6 | 508 | TRUE, |
252b5132 RH |
509 | SRC_MASK (0x000000ff), |
510 | 0x000000ff, | |
511 | PCREL_OFFSET); | |
512 | ||
513 | static ieee_symbol_index_type NOSYMBOL = {0, 0}; | |
514 | ||
0a9d414a | 515 | static bfd_boolean |
c8e7bf0d NC |
516 | parse_expression (ieee_data_type *ieee, |
517 | bfd_vma *value, | |
518 | ieee_symbol_index_type *symbol, | |
519 | bfd_boolean *pcrel, | |
520 | unsigned int *extra, | |
521 | asection **section) | |
252b5132 RH |
522 | |
523 | { | |
c8e7bf0d NC |
524 | bfd_boolean loop = TRUE; |
525 | ieee_value_type stack[10]; | |
526 | ieee_value_type *sp = stack; | |
527 | asection *dummy; | |
528 | ||
252b5132 RH |
529 | #define POS sp[1] |
530 | #define TOS sp[0] | |
531 | #define NOS sp[-1] | |
532 | #define INC sp++; | |
533 | #define DEC sp--; | |
534 | ||
49ae03bf | 535 | /* The stack pointer always points to the next unused location. */ |
c8e7bf0d NC |
536 | #define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC; |
537 | #define POP(x,y,z) DEC; x = TOS.symbol; y = TOS.section; z = TOS.value; | |
252b5132 | 538 | |
47fda0d3 | 539 | while (loop && ieee->h.input_p < ieee->h.last_byte) |
252b5132 RH |
540 | { |
541 | switch (this_byte (&(ieee->h))) | |
542 | { | |
543 | case ieee_variable_P_enum: | |
49ae03bf | 544 | /* P variable, current program counter for section n. */ |
252b5132 RH |
545 | { |
546 | int section_n; | |
49ae03bf | 547 | |
0a9d414a NC |
548 | if (! next_byte (&(ieee->h))) |
549 | return FALSE; | |
b34976b6 | 550 | *pcrel = TRUE; |
252b5132 | 551 | section_n = must_parse_int (&(ieee->h)); |
c7e2358a | 552 | (void) section_n; |
252b5132 RH |
553 | PUSH (NOSYMBOL, bfd_abs_section_ptr, 0); |
554 | break; | |
555 | } | |
0a9d414a | 556 | |
252b5132 | 557 | case ieee_variable_L_enum: |
49ae03bf | 558 | /* L variable address of section N. */ |
0a9d414a NC |
559 | if (! next_byte (&(ieee->h))) |
560 | return FALSE; | |
252b5132 RH |
561 | PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0); |
562 | break; | |
0a9d414a | 563 | |
252b5132 | 564 | case ieee_variable_R_enum: |
49ae03bf NC |
565 | /* R variable, logical address of section module. */ |
566 | /* FIXME, this should be different to L. */ | |
0a9d414a NC |
567 | if (! next_byte (&(ieee->h))) |
568 | return FALSE; | |
252b5132 RH |
569 | PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0); |
570 | break; | |
0a9d414a | 571 | |
252b5132 | 572 | case ieee_variable_S_enum: |
49ae03bf | 573 | /* S variable, size in MAUS of section module. */ |
0a9d414a NC |
574 | if (! next_byte (&(ieee->h))) |
575 | return FALSE; | |
252b5132 RH |
576 | PUSH (NOSYMBOL, |
577 | 0, | |
eea6121a | 578 | ieee->section_table[must_parse_int (&(ieee->h))]->size); |
252b5132 | 579 | break; |
0a9d414a | 580 | |
252b5132 | 581 | case ieee_variable_I_enum: |
49ae03bf | 582 | /* Push the address of variable n. */ |
252b5132 RH |
583 | { |
584 | ieee_symbol_index_type sy; | |
c8e7bf0d | 585 | |
0a9d414a NC |
586 | if (! next_byte (&(ieee->h))) |
587 | return FALSE; | |
252b5132 RH |
588 | sy.index = (int) must_parse_int (&(ieee->h)); |
589 | sy.letter = 'I'; | |
590 | ||
591 | PUSH (sy, bfd_abs_section_ptr, 0); | |
592 | } | |
593 | break; | |
0a9d414a | 594 | |
252b5132 | 595 | case ieee_variable_X_enum: |
49ae03bf | 596 | /* Push the address of external variable n. */ |
252b5132 RH |
597 | { |
598 | ieee_symbol_index_type sy; | |
c8e7bf0d | 599 | |
0a9d414a NC |
600 | if (! next_byte (&(ieee->h))) |
601 | return FALSE; | |
602 | ||
252b5132 RH |
603 | sy.index = (int) (must_parse_int (&(ieee->h))); |
604 | sy.letter = 'X'; | |
605 | ||
606 | PUSH (sy, bfd_und_section_ptr, 0); | |
607 | } | |
608 | break; | |
0a9d414a | 609 | |
252b5132 RH |
610 | case ieee_function_minus_enum: |
611 | { | |
612 | bfd_vma value1, value2; | |
613 | asection *section1, *section_dummy; | |
614 | ieee_symbol_index_type sy; | |
c8e7bf0d | 615 | |
0a9d414a NC |
616 | if (! next_byte (&(ieee->h))) |
617 | return FALSE; | |
252b5132 RH |
618 | |
619 | POP (sy, section1, value1); | |
620 | POP (sy, section_dummy, value2); | |
621 | PUSH (sy, section1 ? section1 : section_dummy, value2 - value1); | |
622 | } | |
623 | break; | |
0a9d414a | 624 | |
252b5132 RH |
625 | case ieee_function_plus_enum: |
626 | { | |
627 | bfd_vma value1, value2; | |
628 | asection *section1; | |
629 | asection *section2; | |
630 | ieee_symbol_index_type sy1; | |
631 | ieee_symbol_index_type sy2; | |
c8e7bf0d | 632 | |
0a9d414a NC |
633 | if (! next_byte (&(ieee->h))) |
634 | return FALSE; | |
252b5132 RH |
635 | |
636 | POP (sy1, section1, value1); | |
637 | POP (sy2, section2, value2); | |
638 | PUSH (sy1.letter ? sy1 : sy2, | |
639 | bfd_is_abs_section (section1) ? section2 : section1, | |
640 | value1 + value2); | |
641 | } | |
642 | break; | |
0a9d414a | 643 | |
252b5132 RH |
644 | default: |
645 | { | |
646 | bfd_vma va; | |
c8e7bf0d | 647 | |
252b5132 RH |
648 | BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum |
649 | || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum); | |
650 | if (parse_int (&(ieee->h), &va)) | |
651 | { | |
652 | PUSH (NOSYMBOL, bfd_abs_section_ptr, va); | |
653 | } | |
654 | else | |
c8e7bf0d NC |
655 | /* Thats all that we can understand. */ |
656 | loop = FALSE; | |
252b5132 RH |
657 | } |
658 | } | |
659 | } | |
47fda0d3 AM |
660 | |
661 | /* As far as I can see there is a bug in the Microtec IEEE output | |
662 | which I'm using to scan, whereby the comma operator is omitted | |
663 | sometimes in an expression, giving expressions with too many | |
664 | terms. We can tell if that's the case by ensuring that | |
665 | sp == stack here. If not, then we've pushed something too far, | |
666 | so we keep adding. */ | |
47fda0d3 AM |
667 | while (sp != stack + 1) |
668 | { | |
669 | asection *section1; | |
670 | ieee_symbol_index_type sy1; | |
c8e7bf0d | 671 | |
47fda0d3 | 672 | POP (sy1, section1, *extra); |
c7e2358a AM |
673 | (void) section1; |
674 | (void) sy1; | |
47fda0d3 AM |
675 | } |
676 | ||
677 | POP (*symbol, dummy, *value); | |
678 | if (section) | |
679 | *section = dummy; | |
252b5132 | 680 | |
0a9d414a NC |
681 | return TRUE; |
682 | } | |
47fda0d3 AM |
683 | |
684 | #define ieee_pos(ieee) \ | |
685 | (ieee->h.input_p - ieee->h.first_byte) | |
252b5132 | 686 | |
47fda0d3 AM |
687 | /* Find the first part of the ieee file after HERE. */ |
688 | ||
689 | static file_ptr | |
c8e7bf0d | 690 | ieee_part_after (ieee_data_type *ieee, file_ptr here) |
47fda0d3 AM |
691 | { |
692 | int part; | |
693 | file_ptr after = ieee->w.r.me_record; | |
694 | ||
695 | /* File parts can come in any order, except that module end is | |
696 | guaranteed to be last (and the header first). */ | |
697 | for (part = 0; part < N_W_VARIABLES; part++) | |
698 | if (ieee->w.offset[part] > here && after > ieee->w.offset[part]) | |
699 | after = ieee->w.offset[part]; | |
700 | ||
701 | return after; | |
702 | } | |
252b5132 | 703 | |
0a9d414a NC |
704 | static bfd_boolean |
705 | ieee_seek (ieee_data_type * ieee, file_ptr offset) | |
706 | { | |
707 | /* PR 17512: file: 017-1157-0.004. */ | |
708 | if (offset < 0 || (bfd_size_type) offset >= ieee->h.total_amt) | |
709 | { | |
710 | ieee->h.input_p = ieee->h.first_byte + ieee->h.total_amt; | |
acb56a83 | 711 | ieee->h.end_p = ieee->h.last_byte = ieee->h.input_p; |
0a9d414a NC |
712 | return FALSE; |
713 | } | |
714 | ||
715 | ieee->h.input_p = ieee->h.first_byte + offset; | |
acb56a83 | 716 | ieee->h.end_p = ieee->h.last_byte = (ieee->h.first_byte + ieee_part_after (ieee, offset)); |
0a9d414a NC |
717 | return TRUE; |
718 | } | |
719 | ||
252b5132 | 720 | static unsigned int last_index; |
49ae03bf | 721 | static char last_type; /* Is the index for an X or a D. */ |
252b5132 RH |
722 | |
723 | static ieee_symbol_type * | |
c8e7bf0d NC |
724 | get_symbol (bfd *abfd ATTRIBUTE_UNUSED, |
725 | ieee_data_type *ieee, | |
726 | ieee_symbol_type *last_symbol, | |
727 | unsigned int *symbol_count, | |
728 | ieee_symbol_type ***pptr, | |
729 | unsigned int *max_index, | |
730 | int this_type) | |
252b5132 | 731 | { |
49ae03bf | 732 | /* Need a new symbol. */ |
252b5132 | 733 | unsigned int new_index = must_parse_int (&(ieee->h)); |
49ae03bf | 734 | |
252b5132 RH |
735 | if (new_index != last_index || this_type != last_type) |
736 | { | |
dc810e39 AM |
737 | ieee_symbol_type *new_symbol; |
738 | bfd_size_type amt = sizeof (ieee_symbol_type); | |
739 | ||
c8e7bf0d | 740 | new_symbol = bfd_alloc (ieee->h.abfd, amt); |
252b5132 RH |
741 | if (!new_symbol) |
742 | return NULL; | |
743 | ||
744 | new_symbol->index = new_index; | |
745 | last_index = new_index; | |
746 | (*symbol_count)++; | |
747 | **pptr = new_symbol; | |
748 | *pptr = &new_symbol->next; | |
749 | if (new_index > *max_index) | |
49ae03bf NC |
750 | *max_index = new_index; |
751 | ||
252b5132 RH |
752 | last_type = this_type; |
753 | new_symbol->symbol.section = bfd_abs_section_ptr; | |
754 | return new_symbol; | |
755 | } | |
756 | return last_symbol; | |
757 | } | |
758 | ||
b34976b6 | 759 | static bfd_boolean |
c8e7bf0d | 760 | ieee_slurp_external_symbols (bfd *abfd) |
252b5132 RH |
761 | { |
762 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
763 | file_ptr offset = ieee->w.r.external_part; | |
764 | ||
765 | ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols; | |
766 | ieee_symbol_type **prev_reference_ptr = &ieee->external_reference; | |
c8e7bf0d | 767 | ieee_symbol_type *symbol = NULL; |
252b5132 | 768 | unsigned int symbol_count = 0; |
b34976b6 | 769 | bfd_boolean loop = TRUE; |
c8e7bf0d | 770 | |
252b5132 | 771 | last_index = 0xffffff; |
b34976b6 | 772 | ieee->symbol_table_full = TRUE; |
252b5132 | 773 | |
0a9d414a NC |
774 | if (! ieee_seek (ieee, offset)) |
775 | return FALSE; | |
252b5132 RH |
776 | |
777 | while (loop) | |
778 | { | |
779 | switch (this_byte (&(ieee->h))) | |
780 | { | |
781 | case ieee_nn_record: | |
0a9d414a NC |
782 | if (! next_byte (&(ieee->h))) |
783 | return FALSE; | |
252b5132 RH |
784 | |
785 | symbol = get_symbol (abfd, ieee, symbol, &symbol_count, | |
c8e7bf0d NC |
786 | & prev_symbols_ptr, |
787 | & ieee->external_symbol_max_index, 'I'); | |
252b5132 | 788 | if (symbol == NULL) |
b34976b6 | 789 | return FALSE; |
252b5132 RH |
790 | |
791 | symbol->symbol.the_bfd = abfd; | |
792 | symbol->symbol.name = read_id (&(ieee->h)); | |
c8e7bf0d | 793 | symbol->symbol.udata.p = NULL; |
252b5132 RH |
794 | symbol->symbol.flags = BSF_NO_FLAGS; |
795 | break; | |
0a9d414a | 796 | |
252b5132 | 797 | case ieee_external_symbol_enum: |
0a9d414a NC |
798 | if (! next_byte (&(ieee->h))) |
799 | return FALSE; | |
252b5132 RH |
800 | |
801 | symbol = get_symbol (abfd, ieee, symbol, &symbol_count, | |
802 | &prev_symbols_ptr, | |
803 | &ieee->external_symbol_max_index, 'D'); | |
804 | if (symbol == NULL) | |
b34976b6 | 805 | return FALSE; |
252b5132 RH |
806 | |
807 | BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index); | |
808 | ||
809 | symbol->symbol.the_bfd = abfd; | |
810 | symbol->symbol.name = read_id (&(ieee->h)); | |
c8e7bf0d | 811 | symbol->symbol.udata.p = NULL; |
252b5132 RH |
812 | symbol->symbol.flags = BSF_NO_FLAGS; |
813 | break; | |
814 | case ieee_attribute_record_enum >> 8: | |
815 | { | |
816 | unsigned int symbol_name_index; | |
817 | unsigned int symbol_type_index; | |
818 | unsigned int symbol_attribute_def; | |
1b0b5b1b | 819 | bfd_vma value = 0; |
c8e7bf0d | 820 | |
47fda0d3 | 821 | switch (read_2bytes (&ieee->h)) |
252b5132 RH |
822 | { |
823 | case ieee_attribute_record_enum: | |
824 | symbol_name_index = must_parse_int (&(ieee->h)); | |
825 | symbol_type_index = must_parse_int (&(ieee->h)); | |
c7e2358a | 826 | (void) symbol_type_index; |
252b5132 RH |
827 | symbol_attribute_def = must_parse_int (&(ieee->h)); |
828 | switch (symbol_attribute_def) | |
829 | { | |
830 | case 8: | |
831 | case 19: | |
832 | parse_int (&ieee->h, &value); | |
833 | break; | |
834 | default: | |
4eca0228 | 835 | _bfd_error_handler |
695344c0 | 836 | /* xgettext:c-format */ |
871b3ab2 | 837 | (_("%pB: unimplemented ATI record %u for symbol %u"), |
d003868e | 838 | abfd, symbol_attribute_def, symbol_name_index); |
252b5132 | 839 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 840 | return FALSE; |
252b5132 RH |
841 | break; |
842 | } | |
843 | break; | |
844 | case ieee_external_reference_info_record_enum: | |
49ae03bf | 845 | /* Skip over ATX record. */ |
252b5132 RH |
846 | parse_int (&(ieee->h), &value); |
847 | parse_int (&(ieee->h), &value); | |
848 | parse_int (&(ieee->h), &value); | |
849 | parse_int (&(ieee->h), &value); | |
850 | break; | |
851 | case ieee_atn_record_enum: | |
852 | /* We may get call optimization information here, | |
853 | which we just ignore. The format is | |
49ae03bf | 854 | {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */ |
252b5132 RH |
855 | parse_int (&ieee->h, &value); |
856 | parse_int (&ieee->h, &value); | |
857 | parse_int (&ieee->h, &value); | |
858 | if (value != 0x3f) | |
859 | { | |
4eca0228 | 860 | _bfd_error_handler |
695344c0 | 861 | /* xgettext:c-format */ |
2dcf00ce AM |
862 | (_("%pB: unexpected ATN type %" PRId64 " in external part"), |
863 | abfd, (int64_t) value); | |
252b5132 | 864 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 865 | return FALSE; |
252b5132 RH |
866 | } |
867 | parse_int (&ieee->h, &value); | |
868 | parse_int (&ieee->h, &value); | |
869 | while (value > 0) | |
870 | { | |
871 | bfd_vma val1; | |
872 | ||
873 | --value; | |
874 | ||
47fda0d3 | 875 | switch (read_2bytes (&ieee->h)) |
252b5132 RH |
876 | { |
877 | case ieee_asn_record_enum: | |
878 | parse_int (&ieee->h, &val1); | |
879 | parse_int (&ieee->h, &val1); | |
880 | break; | |
881 | ||
882 | default: | |
4eca0228 | 883 | _bfd_error_handler |
871b3ab2 | 884 | (_("%pB: unexpected type after ATN"), abfd); |
252b5132 | 885 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 886 | return FALSE; |
252b5132 RH |
887 | } |
888 | } | |
889 | } | |
890 | } | |
891 | break; | |
0a9d414a | 892 | |
252b5132 RH |
893 | case ieee_value_record_enum >> 8: |
894 | { | |
895 | unsigned int symbol_name_index; | |
896 | ieee_symbol_index_type symbol_ignore; | |
b34976b6 | 897 | bfd_boolean pcrel_ignore; |
252b5132 | 898 | unsigned int extra; |
c8e7bf0d | 899 | |
0a9d414a NC |
900 | if (! next_byte (&(ieee->h))) |
901 | return FALSE; | |
902 | if (! next_byte (&(ieee->h))) | |
903 | return FALSE; | |
252b5132 RH |
904 | |
905 | symbol_name_index = must_parse_int (&(ieee->h)); | |
c7e2358a | 906 | (void) symbol_name_index; |
0a9d414a NC |
907 | if (! parse_expression (ieee, |
908 | &symbol->symbol.value, | |
909 | &symbol_ignore, | |
910 | &pcrel_ignore, | |
911 | &extra, | |
912 | &symbol->symbol.section)) | |
913 | return FALSE; | |
252b5132 RH |
914 | |
915 | /* Fully linked IEEE-695 files tend to give every symbol | |
07d6d2b8 AM |
916 | an absolute value. Try to convert that back into a |
917 | section relative value. FIXME: This won't always to | |
918 | the right thing. */ | |
252b5132 RH |
919 | if (bfd_is_abs_section (symbol->symbol.section) |
920 | && (abfd->flags & HAS_RELOC) == 0) | |
921 | { | |
922 | bfd_vma val; | |
923 | asection *s; | |
924 | ||
925 | val = symbol->symbol.value; | |
926 | for (s = abfd->sections; s != NULL; s = s->next) | |
927 | { | |
eea6121a | 928 | if (val >= s->vma && val < s->vma + s->size) |
252b5132 RH |
929 | { |
930 | symbol->symbol.section = s; | |
931 | symbol->symbol.value -= s->vma; | |
932 | break; | |
933 | } | |
934 | } | |
935 | } | |
936 | ||
937 | symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT; | |
938 | ||
939 | } | |
940 | break; | |
941 | case ieee_weak_external_reference_enum: | |
942 | { | |
943 | bfd_vma size; | |
944 | bfd_vma value; | |
c8e7bf0d | 945 | |
0a9d414a NC |
946 | if (! next_byte (&(ieee->h))) |
947 | return FALSE; | |
948 | ||
49ae03bf | 949 | /* Throw away the external reference index. */ |
252b5132 | 950 | (void) must_parse_int (&(ieee->h)); |
49ae03bf | 951 | /* Fetch the default size if not resolved. */ |
252b5132 | 952 | size = must_parse_int (&(ieee->h)); |
7dee875e | 953 | /* Fetch the default value if available. */ |
82e51918 | 954 | if (! parse_int (&(ieee->h), &value)) |
c8e7bf0d | 955 | value = 0; |
49ae03bf | 956 | /* This turns into a common. */ |
252b5132 RH |
957 | symbol->symbol.section = bfd_com_section_ptr; |
958 | symbol->symbol.value = size; | |
959 | } | |
960 | break; | |
961 | ||
962 | case ieee_external_reference_enum: | |
0a9d414a NC |
963 | if (! next_byte (&(ieee->h))) |
964 | return FALSE; | |
252b5132 RH |
965 | |
966 | symbol = get_symbol (abfd, ieee, symbol, &symbol_count, | |
967 | &prev_reference_ptr, | |
968 | &ieee->external_reference_max_index, 'X'); | |
969 | if (symbol == NULL) | |
b34976b6 | 970 | return FALSE; |
252b5132 RH |
971 | |
972 | symbol->symbol.the_bfd = abfd; | |
973 | symbol->symbol.name = read_id (&(ieee->h)); | |
c8e7bf0d | 974 | symbol->symbol.udata.p = NULL; |
252b5132 RH |
975 | symbol->symbol.section = bfd_und_section_ptr; |
976 | symbol->symbol.value = (bfd_vma) 0; | |
977 | symbol->symbol.flags = 0; | |
978 | ||
979 | BFD_ASSERT (symbol->index >= ieee->external_reference_min_index); | |
980 | break; | |
981 | ||
982 | default: | |
b34976b6 | 983 | loop = FALSE; |
252b5132 RH |
984 | } |
985 | } | |
986 | ||
987 | if (ieee->external_symbol_max_index != 0) | |
988 | { | |
989 | ieee->external_symbol_count = | |
990 | ieee->external_symbol_max_index - | |
991 | ieee->external_symbol_min_index + 1; | |
992 | } | |
993 | else | |
c8e7bf0d | 994 | ieee->external_symbol_count = 0; |
252b5132 RH |
995 | |
996 | if (ieee->external_reference_max_index != 0) | |
997 | { | |
998 | ieee->external_reference_count = | |
999 | ieee->external_reference_max_index - | |
1000 | ieee->external_reference_min_index + 1; | |
1001 | } | |
1002 | else | |
c8e7bf0d | 1003 | ieee->external_reference_count = 0; |
252b5132 RH |
1004 | |
1005 | abfd->symcount = | |
1006 | ieee->external_reference_count + ieee->external_symbol_count; | |
1007 | ||
1008 | if (symbol_count != abfd->symcount) | |
c8e7bf0d NC |
1009 | /* There are gaps in the table -- */ |
1010 | ieee->symbol_table_full = FALSE; | |
252b5132 | 1011 | |
c8e7bf0d NC |
1012 | *prev_symbols_ptr = NULL; |
1013 | *prev_reference_ptr = NULL; | |
252b5132 | 1014 | |
b34976b6 | 1015 | return TRUE; |
252b5132 RH |
1016 | } |
1017 | ||
b34976b6 | 1018 | static bfd_boolean |
c8e7bf0d | 1019 | ieee_slurp_symbol_table (bfd *abfd) |
252b5132 | 1020 | { |
82e51918 | 1021 | if (! IEEE_DATA (abfd)->read_symbols) |
252b5132 RH |
1022 | { |
1023 | if (! ieee_slurp_external_symbols (abfd)) | |
b34976b6 AM |
1024 | return FALSE; |
1025 | IEEE_DATA (abfd)->read_symbols = TRUE; | |
252b5132 | 1026 | } |
b34976b6 | 1027 | return TRUE; |
252b5132 RH |
1028 | } |
1029 | ||
47fda0d3 | 1030 | static long |
46e94266 | 1031 | ieee_get_symtab_upper_bound (bfd *abfd) |
252b5132 RH |
1032 | { |
1033 | if (! ieee_slurp_symbol_table (abfd)) | |
1034 | return -1; | |
1035 | ||
1036 | return (abfd->symcount != 0) ? | |
1037 | (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0; | |
1038 | } | |
1039 | ||
49ae03bf NC |
1040 | /* Move from our internal lists to the canon table, and insert in |
1041 | symbol index order. */ | |
252b5132 RH |
1042 | |
1043 | extern const bfd_target ieee_vec; | |
1044 | ||
47fda0d3 | 1045 | static long |
c8e7bf0d | 1046 | ieee_canonicalize_symtab (bfd *abfd, asymbol **location) |
252b5132 RH |
1047 | { |
1048 | ieee_symbol_type *symp; | |
1049 | static bfd dummy_bfd; | |
1050 | static asymbol empty_symbol = | |
dcdea4f4 AM |
1051 | { |
1052 | &dummy_bfd, | |
1053 | " ieee empty", | |
1054 | (symvalue) 0, | |
1055 | BSF_DEBUGGING, | |
1056 | bfd_abs_section_ptr | |
1057 | #ifdef __STDC__ | |
1058 | /* K&R compilers can't initialise unions. */ | |
1059 | , { 0 } | |
1060 | #endif | |
1061 | }; | |
252b5132 RH |
1062 | |
1063 | if (abfd->symcount) | |
1064 | { | |
1065 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
c8e7bf0d | 1066 | |
252b5132 RH |
1067 | dummy_bfd.xvec = &ieee_vec; |
1068 | if (! ieee_slurp_symbol_table (abfd)) | |
1069 | return -1; | |
1070 | ||
82e51918 | 1071 | if (! ieee->symbol_table_full) |
252b5132 | 1072 | { |
49ae03bf NC |
1073 | /* Arrgh - there are gaps in the table, run through and fill them |
1074 | up with pointers to a null place. */ | |
252b5132 | 1075 | unsigned int i; |
49ae03bf | 1076 | |
252b5132 | 1077 | for (i = 0; i < abfd->symcount; i++) |
49ae03bf | 1078 | location[i] = &empty_symbol; |
252b5132 RH |
1079 | } |
1080 | ||
1081 | ieee->external_symbol_base_offset = -ieee->external_symbol_min_index; | |
1082 | for (symp = IEEE_DATA (abfd)->external_symbols; | |
1083 | symp != (ieee_symbol_type *) NULL; | |
1084 | symp = symp->next) | |
49ae03bf NC |
1085 | /* Place into table at correct index locations. */ |
1086 | location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol; | |
252b5132 | 1087 | |
49ae03bf | 1088 | /* The external refs are indexed in a bit. */ |
252b5132 RH |
1089 | ieee->external_reference_base_offset = |
1090 | -ieee->external_reference_min_index + ieee->external_symbol_count; | |
1091 | ||
1092 | for (symp = IEEE_DATA (abfd)->external_reference; | |
1093 | symp != (ieee_symbol_type *) NULL; | |
1094 | symp = symp->next) | |
49ae03bf NC |
1095 | location[symp->index + ieee->external_reference_base_offset] = |
1096 | &symp->symbol; | |
252b5132 | 1097 | } |
49ae03bf | 1098 | |
252b5132 | 1099 | if (abfd->symcount) |
49ae03bf NC |
1100 | location[abfd->symcount] = (asymbol *) NULL; |
1101 | ||
252b5132 RH |
1102 | return abfd->symcount; |
1103 | } | |
1104 | ||
1105 | static asection * | |
91d6fa6a | 1106 | get_section_entry (bfd *abfd, ieee_data_type *ieee, unsigned int sindex) |
252b5132 | 1107 | { |
91d6fa6a | 1108 | if (sindex >= ieee->section_table_size) |
252b5132 RH |
1109 | { |
1110 | unsigned int c, i; | |
1111 | asection **n; | |
dc810e39 | 1112 | bfd_size_type amt; |
252b5132 RH |
1113 | |
1114 | c = ieee->section_table_size; | |
1115 | if (c == 0) | |
1116 | c = 20; | |
91d6fa6a | 1117 | while (c <= sindex) |
252b5132 RH |
1118 | c *= 2; |
1119 | ||
dc810e39 AM |
1120 | amt = c; |
1121 | amt *= sizeof (asection *); | |
c8e7bf0d | 1122 | n = bfd_realloc (ieee->section_table, amt); |
252b5132 RH |
1123 | if (n == NULL) |
1124 | return NULL; | |
1125 | ||
1126 | for (i = ieee->section_table_size; i < c; i++) | |
1127 | n[i] = NULL; | |
1128 | ||
1129 | ieee->section_table = n; | |
1130 | ieee->section_table_size = c; | |
1131 | } | |
1132 | ||
91d6fa6a | 1133 | if (ieee->section_table[sindex] == (asection *) NULL) |
252b5132 | 1134 | { |
dc810e39 | 1135 | char *tmp = bfd_alloc (abfd, (bfd_size_type) 11); |
252b5132 RH |
1136 | asection *section; |
1137 | ||
1138 | if (!tmp) | |
1139 | return NULL; | |
91d6fa6a | 1140 | sprintf (tmp, " fsec%4d", sindex); |
252b5132 | 1141 | section = bfd_make_section (abfd, tmp); |
91d6fa6a NC |
1142 | ieee->section_table[sindex] = section; |
1143 | section->target_index = sindex; | |
1144 | ieee->section_table[sindex] = section; | |
252b5132 | 1145 | } |
91d6fa6a | 1146 | return ieee->section_table[sindex]; |
252b5132 RH |
1147 | } |
1148 | ||
0a9d414a | 1149 | static bfd_boolean |
c8e7bf0d | 1150 | ieee_slurp_sections (bfd *abfd) |
252b5132 RH |
1151 | { |
1152 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
1153 | file_ptr offset = ieee->w.r.section_part; | |
252b5132 RH |
1154 | char *name; |
1155 | ||
1156 | if (offset != 0) | |
1157 | { | |
1158 | bfd_byte section_type[3]; | |
c8e7bf0d | 1159 | |
0a9d414a NC |
1160 | if (! ieee_seek (ieee, offset)) |
1161 | return FALSE; | |
1162 | ||
b34976b6 | 1163 | while (TRUE) |
252b5132 RH |
1164 | { |
1165 | switch (this_byte (&(ieee->h))) | |
1166 | { | |
1167 | case ieee_section_type_enum: | |
1168 | { | |
dc810e39 | 1169 | asection *section; |
252b5132 | 1170 | unsigned int section_index; |
c8e7bf0d | 1171 | |
0a9d414a NC |
1172 | if (! next_byte (&(ieee->h))) |
1173 | return FALSE; | |
252b5132 RH |
1174 | section_index = must_parse_int (&(ieee->h)); |
1175 | ||
1176 | section = get_section_entry (abfd, ieee, section_index); | |
1177 | ||
1178 | section_type[0] = this_byte_and_next (&(ieee->h)); | |
1179 | ||
1180 | /* Set minimal section attributes. Attributes are | |
49ae03bf | 1181 | extended later, based on section contents. */ |
252b5132 RH |
1182 | switch (section_type[0]) |
1183 | { | |
1184 | case 0xC1: | |
49ae03bf | 1185 | /* Normal attributes for absolute sections. */ |
252b5132 RH |
1186 | section_type[1] = this_byte (&(ieee->h)); |
1187 | section->flags = SEC_ALLOC; | |
1188 | switch (section_type[1]) | |
1189 | { | |
c8e7bf0d NC |
1190 | /* AS Absolute section attributes. */ |
1191 | case 0xD3: | |
0a9d414a NC |
1192 | if (! next_byte (&(ieee->h))) |
1193 | return FALSE; | |
252b5132 RH |
1194 | section_type[2] = this_byte (&(ieee->h)); |
1195 | switch (section_type[2]) | |
1196 | { | |
1197 | case 0xD0: | |
49ae03bf | 1198 | /* Normal code. */ |
0a9d414a NC |
1199 | if (! next_byte (&(ieee->h))) |
1200 | return FALSE; | |
252b5132 RH |
1201 | section->flags |= SEC_CODE; |
1202 | break; | |
1203 | case 0xC4: | |
49ae03bf | 1204 | /* Normal data. */ |
0a9d414a NC |
1205 | if (! next_byte (&(ieee->h))) |
1206 | return FALSE; | |
252b5132 RH |
1207 | section->flags |= SEC_DATA; |
1208 | break; | |
1209 | case 0xD2: | |
0a9d414a NC |
1210 | if (! next_byte (&(ieee->h))) |
1211 | return FALSE; | |
49ae03bf | 1212 | /* Normal rom data. */ |
252b5132 RH |
1213 | section->flags |= SEC_ROM | SEC_DATA; |
1214 | break; | |
1215 | default: | |
1216 | break; | |
1217 | } | |
1218 | } | |
1219 | break; | |
c8e7bf0d NC |
1220 | |
1221 | /* Named relocatable sections (type C). */ | |
1222 | case 0xC3: | |
252b5132 RH |
1223 | section_type[1] = this_byte (&(ieee->h)); |
1224 | section->flags = SEC_ALLOC; | |
1225 | switch (section_type[1]) | |
1226 | { | |
49ae03bf | 1227 | case 0xD0: /* Normal code (CP). */ |
0a9d414a NC |
1228 | if (! next_byte (&(ieee->h))) |
1229 | return FALSE; | |
252b5132 RH |
1230 | section->flags |= SEC_CODE; |
1231 | break; | |
49ae03bf | 1232 | case 0xC4: /* Normal data (CD). */ |
0a9d414a NC |
1233 | if (! next_byte (&(ieee->h))) |
1234 | return FALSE; | |
252b5132 RH |
1235 | section->flags |= SEC_DATA; |
1236 | break; | |
49ae03bf | 1237 | case 0xD2: /* Normal rom data (CR). */ |
0a9d414a NC |
1238 | if (! next_byte (&(ieee->h))) |
1239 | return FALSE; | |
252b5132 RH |
1240 | section->flags |= SEC_ROM | SEC_DATA; |
1241 | break; | |
1242 | default: | |
1243 | break; | |
1244 | } | |
1245 | } | |
1246 | ||
49ae03bf | 1247 | /* Read section name, use it if non empty. */ |
252b5132 | 1248 | name = read_id (&ieee->h); |
c458d007 NC |
1249 | if (name == NULL) |
1250 | return FALSE; | |
252b5132 RH |
1251 | if (name[0]) |
1252 | section->name = name; | |
1253 | ||
49ae03bf | 1254 | /* Skip these fields, which we don't care about. */ |
252b5132 RH |
1255 | { |
1256 | bfd_vma parent, brother, context; | |
c8e7bf0d | 1257 | |
252b5132 RH |
1258 | parse_int (&(ieee->h), &parent); |
1259 | parse_int (&(ieee->h), &brother); | |
1260 | parse_int (&(ieee->h), &context); | |
1261 | } | |
1262 | } | |
1263 | break; | |
1264 | case ieee_section_alignment_enum: | |
1265 | { | |
1266 | unsigned int section_index; | |
1267 | bfd_vma value; | |
1268 | asection *section; | |
c8e7bf0d | 1269 | |
0a9d414a NC |
1270 | if (! next_byte (&(ieee->h))) |
1271 | return FALSE; | |
252b5132 RH |
1272 | section_index = must_parse_int (&ieee->h); |
1273 | section = get_section_entry (abfd, ieee, section_index); | |
1274 | if (section_index > ieee->section_count) | |
c8e7bf0d NC |
1275 | ieee->section_count = section_index; |
1276 | ||
252b5132 RH |
1277 | section->alignment_power = |
1278 | bfd_log2 (must_parse_int (&ieee->h)); | |
1279 | (void) parse_int (&(ieee->h), &value); | |
1280 | } | |
1281 | break; | |
1282 | case ieee_e2_first_byte_enum: | |
1283 | { | |
dc810e39 AM |
1284 | asection *section; |
1285 | ieee_record_enum_type t; | |
252b5132 | 1286 | |
dc810e39 | 1287 | t = (ieee_record_enum_type) (read_2bytes (&(ieee->h))); |
252b5132 RH |
1288 | switch (t) |
1289 | { | |
1290 | case ieee_section_size_enum: | |
1291 | section = ieee->section_table[must_parse_int (&(ieee->h))]; | |
eea6121a | 1292 | section->size = must_parse_int (&(ieee->h)); |
252b5132 RH |
1293 | break; |
1294 | case ieee_physical_region_size_enum: | |
1295 | section = ieee->section_table[must_parse_int (&(ieee->h))]; | |
eea6121a | 1296 | section->size = must_parse_int (&(ieee->h)); |
252b5132 RH |
1297 | break; |
1298 | case ieee_region_base_address_enum: | |
1299 | section = ieee->section_table[must_parse_int (&(ieee->h))]; | |
1300 | section->vma = must_parse_int (&(ieee->h)); | |
1301 | section->lma = section->vma; | |
1302 | break; | |
1303 | case ieee_mau_size_enum: | |
1304 | must_parse_int (&(ieee->h)); | |
1305 | must_parse_int (&(ieee->h)); | |
1306 | break; | |
1307 | case ieee_m_value_enum: | |
1308 | must_parse_int (&(ieee->h)); | |
1309 | must_parse_int (&(ieee->h)); | |
1310 | break; | |
1311 | case ieee_section_base_address_enum: | |
1312 | section = ieee->section_table[must_parse_int (&(ieee->h))]; | |
1313 | section->vma = must_parse_int (&(ieee->h)); | |
1314 | section->lma = section->vma; | |
1315 | break; | |
1316 | case ieee_section_offset_enum: | |
1317 | (void) must_parse_int (&(ieee->h)); | |
1318 | (void) must_parse_int (&(ieee->h)); | |
1319 | break; | |
1320 | default: | |
0a9d414a | 1321 | return TRUE; |
252b5132 RH |
1322 | } |
1323 | } | |
1324 | break; | |
1325 | default: | |
0a9d414a | 1326 | return TRUE; |
252b5132 RH |
1327 | } |
1328 | } | |
1329 | } | |
0a9d414a NC |
1330 | |
1331 | return TRUE; | |
252b5132 RH |
1332 | } |
1333 | ||
1334 | /* Make a section for the debugging information, if any. We don't try | |
1335 | to interpret the debugging information; we just point the section | |
1336 | at the area in the file so that program which understand can dig it | |
1337 | out. */ | |
1338 | ||
b34976b6 | 1339 | static bfd_boolean |
c8e7bf0d | 1340 | ieee_slurp_debug (bfd *abfd) |
252b5132 RH |
1341 | { |
1342 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
1343 | asection *sec; | |
a8c5faf7 | 1344 | file_ptr debug_end; |
117ed4f8 | 1345 | flagword flags; |
252b5132 RH |
1346 | |
1347 | if (ieee->w.r.debug_information_part == 0) | |
b34976b6 | 1348 | return TRUE; |
252b5132 | 1349 | |
117ed4f8 AM |
1350 | flags = SEC_DEBUGGING | SEC_HAS_CONTENTS; |
1351 | sec = bfd_make_section_with_flags (abfd, ".debug", flags); | |
252b5132 | 1352 | if (sec == NULL) |
b34976b6 | 1353 | return FALSE; |
252b5132 | 1354 | sec->filepos = ieee->w.r.debug_information_part; |
a8c5faf7 | 1355 | |
47fda0d3 | 1356 | debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part); |
eea6121a | 1357 | sec->size = debug_end - ieee->w.r.debug_information_part; |
252b5132 | 1358 | |
b34976b6 | 1359 | return TRUE; |
252b5132 RH |
1360 | } |
1361 | \f | |
49ae03bf | 1362 | /* Archive stuff. */ |
252b5132 | 1363 | |
46e94266 | 1364 | static const bfd_target * |
c8e7bf0d | 1365 | ieee_archive_p (bfd *abfd) |
252b5132 RH |
1366 | { |
1367 | char *library; | |
1368 | unsigned int i; | |
62b76e4b | 1369 | static unsigned char buffer[512]; |
252b5132 RH |
1370 | file_ptr buffer_offset = 0; |
1371 | ieee_ar_data_type *save = abfd->tdata.ieee_ar_data; | |
1372 | ieee_ar_data_type *ieee; | |
dc810e39 | 1373 | bfd_size_type alc_elts; |
252b5132 | 1374 | ieee_ar_obstack_type *elts = NULL; |
dc810e39 | 1375 | bfd_size_type amt = sizeof (ieee_ar_data_type); |
252b5132 | 1376 | |
c8e7bf0d | 1377 | abfd->tdata.ieee_ar_data = bfd_alloc (abfd, amt); |
252b5132 | 1378 | if (!abfd->tdata.ieee_ar_data) |
487e54f2 | 1379 | goto error_ret_restore; |
252b5132 RH |
1380 | ieee = IEEE_AR_DATA (abfd); |
1381 | ||
47fda0d3 AM |
1382 | /* Ignore the return value here. It doesn't matter if we don't read |
1383 | the entire buffer. We might have a very small ieee file. */ | |
041830e0 NC |
1384 | if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0) |
1385 | goto got_wrong_format_error; | |
252b5132 RH |
1386 | |
1387 | ieee->h.first_byte = buffer; | |
1388 | ieee->h.input_p = buffer; | |
acb56a83 NC |
1389 | ieee->h.total_amt = sizeof (buffer); |
1390 | ieee->h.end_p = buffer + sizeof (buffer); | |
252b5132 RH |
1391 | |
1392 | ieee->h.abfd = abfd; | |
1393 | ||
1394 | if (this_byte (&(ieee->h)) != Module_Beginning) | |
c4920b97 | 1395 | goto got_wrong_format_error; |
252b5132 | 1396 | |
0a9d414a NC |
1397 | (void) next_byte (&(ieee->h)); |
1398 | ||
252b5132 | 1399 | library = read_id (&(ieee->h)); |
c458d007 | 1400 | if (library == NULL) |
07d6d2b8 | 1401 | goto got_wrong_format_error; |
252b5132 | 1402 | if (strcmp (library, "LIBRARY") != 0) |
c4920b97 NC |
1403 | goto got_wrong_format_error; |
1404 | ||
1405 | /* Throw away the filename. */ | |
252b5132 RH |
1406 | read_id (&(ieee->h)); |
1407 | ||
1408 | ieee->element_count = 0; | |
1409 | ieee->element_index = 0; | |
1410 | ||
0a9d414a | 1411 | (void) next_byte (&(ieee->h)); /* Drop the ad part. */ |
c4920b97 | 1412 | must_parse_int (&(ieee->h)); /* And the two dummy numbers. */ |
252b5132 RH |
1413 | must_parse_int (&(ieee->h)); |
1414 | ||
1415 | alc_elts = 10; | |
c8e7bf0d | 1416 | elts = bfd_malloc (alc_elts * sizeof *elts); |
252b5132 RH |
1417 | if (elts == NULL) |
1418 | goto error_return; | |
1419 | ||
c4920b97 | 1420 | /* Read the index of the BB table. */ |
252b5132 RH |
1421 | while (1) |
1422 | { | |
1423 | int rec; | |
1424 | ieee_ar_obstack_type *t; | |
1425 | ||
1426 | rec = read_2bytes (&(ieee->h)); | |
1427 | if (rec != (int) ieee_assign_value_to_variable_enum) | |
1428 | break; | |
1429 | ||
1430 | if (ieee->element_count >= alc_elts) | |
1431 | { | |
1432 | ieee_ar_obstack_type *n; | |
1433 | ||
1434 | alc_elts *= 2; | |
c8e7bf0d | 1435 | n = bfd_realloc (elts, alc_elts * sizeof (* elts)); |
252b5132 RH |
1436 | if (n == NULL) |
1437 | goto error_return; | |
1438 | elts = n; | |
1439 | } | |
1440 | ||
1441 | t = &elts[ieee->element_count]; | |
1442 | ieee->element_count++; | |
1443 | ||
1444 | must_parse_int (&(ieee->h)); | |
1445 | t->file_offset = must_parse_int (&(ieee->h)); | |
1446 | t->abfd = (bfd *) NULL; | |
1447 | ||
c4920b97 | 1448 | /* Make sure that we don't go over the end of the buffer. */ |
47fda0d3 | 1449 | if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2) |
252b5132 | 1450 | { |
c4920b97 | 1451 | /* Past half way, reseek and reprime. */ |
47fda0d3 | 1452 | buffer_offset += ieee_pos (IEEE_DATA (abfd)); |
252b5132 RH |
1453 | if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0) |
1454 | goto error_return; | |
c4920b97 | 1455 | |
dc810e39 | 1456 | /* Again ignore return value of bfd_bread. */ |
c8e7bf0d | 1457 | bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd); |
252b5132 RH |
1458 | ieee->h.first_byte = buffer; |
1459 | ieee->h.input_p = buffer; | |
acb56a83 NC |
1460 | ieee->h.total_amt = sizeof (buffer); |
1461 | ieee->h.end_p = buffer + sizeof (buffer); | |
252b5132 RH |
1462 | } |
1463 | } | |
1464 | ||
dc810e39 AM |
1465 | amt = ieee->element_count; |
1466 | amt *= sizeof *ieee->elements; | |
c8e7bf0d | 1467 | ieee->elements = bfd_alloc (abfd, amt); |
252b5132 RH |
1468 | if (ieee->elements == NULL) |
1469 | goto error_return; | |
c4920b97 | 1470 | |
dc810e39 | 1471 | memcpy (ieee->elements, elts, (size_t) amt); |
252b5132 RH |
1472 | free (elts); |
1473 | elts = NULL; | |
1474 | ||
c4920b97 | 1475 | /* Now scan the area again, and replace BB offsets with file offsets. */ |
252b5132 RH |
1476 | for (i = 2; i < ieee->element_count; i++) |
1477 | { | |
1478 | if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0) | |
1479 | goto error_return; | |
c4920b97 | 1480 | |
dc810e39 | 1481 | /* Again ignore return value of bfd_bread. */ |
c8e7bf0d | 1482 | bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd); |
252b5132 RH |
1483 | ieee->h.first_byte = buffer; |
1484 | ieee->h.input_p = buffer; | |
acb56a83 NC |
1485 | ieee->h.total_amt = sizeof (buffer); |
1486 | ieee->h.end_p = buffer + sizeof (buffer); | |
252b5132 | 1487 | |
0a9d414a NC |
1488 | (void) next_byte (&(ieee->h)); /* Drop F8. */ |
1489 | if (! next_byte (&(ieee->h))) /* Drop 14. */ | |
1490 | goto error_return; | |
c4920b97 | 1491 | must_parse_int (&(ieee->h)); /* Drop size of block. */ |
dc810e39 | 1492 | |
252b5132 | 1493 | if (must_parse_int (&(ieee->h)) != 0) |
c4920b97 NC |
1494 | /* This object has been deleted. */ |
1495 | ieee->elements[i].file_offset = 0; | |
252b5132 | 1496 | else |
c4920b97 | 1497 | ieee->elements[i].file_offset = must_parse_int (&(ieee->h)); |
252b5132 RH |
1498 | } |
1499 | ||
1500 | /* abfd->has_armap = ;*/ | |
1501 | ||
1502 | return abfd->xvec; | |
1503 | ||
911c6dae AM |
1504 | got_wrong_format_error: |
1505 | bfd_set_error (bfd_error_wrong_format); | |
252b5132 RH |
1506 | error_return: |
1507 | if (elts != NULL) | |
1508 | free (elts); | |
487e54f2 AM |
1509 | bfd_release (abfd, ieee); |
1510 | error_ret_restore: | |
1511 | abfd->tdata.ieee_ar_data = save; | |
c4920b97 | 1512 | |
252b5132 RH |
1513 | return NULL; |
1514 | } | |
1515 | ||
46e94266 NC |
1516 | static bfd_boolean |
1517 | ieee_mkobject (bfd *abfd) | |
252b5132 | 1518 | { |
dc810e39 | 1519 | bfd_size_type amt; |
252b5132 | 1520 | |
46e94266 NC |
1521 | output_ptr_start = NULL; |
1522 | output_ptr = NULL; | |
1523 | output_ptr_end = NULL; | |
1524 | input_ptr_start = NULL; | |
1525 | input_ptr = NULL; | |
1526 | input_ptr_end = NULL; | |
1527 | input_bfd = NULL; | |
1528 | output_bfd = NULL; | |
1529 | output_buffer = 0; | |
1530 | amt = sizeof (ieee_data_type); | |
1531 | abfd->tdata.ieee_data = bfd_zalloc (abfd, amt); | |
1532 | return abfd->tdata.ieee_data != NULL; | |
252b5132 RH |
1533 | } |
1534 | ||
b34976b6 | 1535 | static bfd_boolean |
c8e7bf0d NC |
1536 | do_one (ieee_data_type *ieee, |
1537 | ieee_per_section_type *current_map, | |
1538 | unsigned char *location_ptr, | |
1539 | asection *s, | |
1540 | int iterations) | |
252b5132 RH |
1541 | { |
1542 | switch (this_byte (&(ieee->h))) | |
1543 | { | |
1544 | case ieee_load_constant_bytes_enum: | |
1545 | { | |
1546 | unsigned int number_of_maus; | |
1547 | unsigned int i; | |
49ae03bf | 1548 | |
0a9d414a NC |
1549 | if (! next_byte (&(ieee->h))) |
1550 | return FALSE; | |
252b5132 RH |
1551 | number_of_maus = must_parse_int (&(ieee->h)); |
1552 | ||
1553 | for (i = 0; i < number_of_maus; i++) | |
1554 | { | |
1555 | location_ptr[current_map->pc++] = this_byte (&(ieee->h)); | |
1556 | next_byte (&(ieee->h)); | |
1557 | } | |
1558 | } | |
1559 | break; | |
1560 | ||
1561 | case ieee_load_with_relocation_enum: | |
1562 | { | |
b34976b6 | 1563 | bfd_boolean loop = TRUE; |
49ae03bf | 1564 | |
0a9d414a NC |
1565 | if (! next_byte (&(ieee->h))) |
1566 | return FALSE; | |
252b5132 RH |
1567 | while (loop) |
1568 | { | |
1569 | switch (this_byte (&(ieee->h))) | |
1570 | { | |
1571 | case ieee_variable_R_enum: | |
1572 | ||
1573 | case ieee_function_signed_open_b_enum: | |
1574 | case ieee_function_unsigned_open_b_enum: | |
1575 | case ieee_function_either_open_b_enum: | |
1576 | { | |
1577 | unsigned int extra = 4; | |
b34976b6 | 1578 | bfd_boolean pcrel = FALSE; |
252b5132 | 1579 | asection *section; |
dc810e39 | 1580 | ieee_reloc_type *r; |
dc810e39 | 1581 | |
116c20d2 | 1582 | r = bfd_alloc (ieee->h.abfd, sizeof (* r)); |
252b5132 | 1583 | if (!r) |
b34976b6 | 1584 | return FALSE; |
252b5132 RH |
1585 | |
1586 | *(current_map->reloc_tail_ptr) = r; | |
1587 | current_map->reloc_tail_ptr = &r->next; | |
1588 | r->next = (ieee_reloc_type *) NULL; | |
0a9d414a NC |
1589 | if (! next_byte (&(ieee->h))) |
1590 | return FALSE; | |
1591 | ||
252b5132 | 1592 | r->relent.sym_ptr_ptr = 0; |
0a9d414a NC |
1593 | if (! parse_expression (ieee, |
1594 | &r->relent.addend, | |
1595 | &r->symbol, | |
1596 | &pcrel, &extra, §ion)) | |
1597 | return FALSE; | |
1598 | ||
252b5132 RH |
1599 | r->relent.address = current_map->pc; |
1600 | s->flags |= SEC_RELOC; | |
1601 | s->owner->flags |= HAS_RELOC; | |
1602 | s->reloc_count++; | |
1603 | if (r->relent.sym_ptr_ptr == NULL && section != NULL) | |
1604 | r->relent.sym_ptr_ptr = section->symbol_ptr_ptr; | |
1605 | ||
1606 | if (this_byte (&(ieee->h)) == (int) ieee_comma) | |
1607 | { | |
0a9d414a NC |
1608 | if (! next_byte (&(ieee->h))) |
1609 | return FALSE; | |
49ae03bf | 1610 | /* Fetch number of bytes to pad. */ |
252b5132 RH |
1611 | extra = must_parse_int (&(ieee->h)); |
1612 | }; | |
1613 | ||
1614 | switch (this_byte (&(ieee->h))) | |
1615 | { | |
1616 | case ieee_function_signed_close_b_enum: | |
0a9d414a NC |
1617 | if (! next_byte (&(ieee->h))) |
1618 | return FALSE; | |
252b5132 RH |
1619 | break; |
1620 | case ieee_function_unsigned_close_b_enum: | |
0a9d414a NC |
1621 | if (! next_byte (&(ieee->h))) |
1622 | return FALSE; | |
252b5132 RH |
1623 | break; |
1624 | case ieee_function_either_close_b_enum: | |
0a9d414a NC |
1625 | if (! next_byte (&(ieee->h))) |
1626 | return FALSE; | |
252b5132 RH |
1627 | break; |
1628 | default: | |
1629 | break; | |
1630 | } | |
49ae03bf | 1631 | /* Build a relocation entry for this type. */ |
252b5132 RH |
1632 | /* If pc rel then stick -ve pc into instruction |
1633 | and take out of reloc .. | |
1634 | ||
1635 | I've changed this. It's all too complicated. I | |
1636 | keep 0 in the instruction now. */ | |
1637 | ||
1638 | switch (extra) | |
1639 | { | |
1640 | case 0: | |
1641 | case 4: | |
1642 | ||
82e51918 | 1643 | if (pcrel) |
252b5132 RH |
1644 | { |
1645 | #if KEEPMINUSPCININST | |
dc810e39 AM |
1646 | bfd_put_32 (ieee->h.abfd, -current_map->pc, |
1647 | location_ptr + current_map->pc); | |
252b5132 | 1648 | r->relent.howto = &rel32_howto; |
dc810e39 | 1649 | r->relent.addend -= current_map->pc; |
252b5132 | 1650 | #else |
dc810e39 | 1651 | bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr + |
252b5132 RH |
1652 | current_map->pc); |
1653 | r->relent.howto = &rel32_howto; | |
1654 | #endif | |
1655 | } | |
1656 | else | |
1657 | { | |
dc810e39 AM |
1658 | bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, |
1659 | location_ptr + current_map->pc); | |
252b5132 RH |
1660 | r->relent.howto = &abs32_howto; |
1661 | } | |
1662 | current_map->pc += 4; | |
1663 | break; | |
1664 | case 2: | |
82e51918 | 1665 | if (pcrel) |
252b5132 RH |
1666 | { |
1667 | #if KEEPMINUSPCININST | |
dc810e39 AM |
1668 | bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc, |
1669 | location_ptr + current_map->pc); | |
252b5132 RH |
1670 | r->relent.addend -= current_map->pc; |
1671 | r->relent.howto = &rel16_howto; | |
1672 | #else | |
1673 | ||
dc810e39 AM |
1674 | bfd_put_16 (ieee->h.abfd, (bfd_vma) 0, |
1675 | location_ptr + current_map->pc); | |
252b5132 RH |
1676 | r->relent.howto = &rel16_howto; |
1677 | #endif | |
1678 | } | |
1679 | ||
1680 | else | |
1681 | { | |
dc810e39 AM |
1682 | bfd_put_16 (ieee->h.abfd, (bfd_vma) 0, |
1683 | location_ptr + current_map->pc); | |
252b5132 RH |
1684 | r->relent.howto = &abs16_howto; |
1685 | } | |
1686 | current_map->pc += 2; | |
1687 | break; | |
1688 | case 1: | |
82e51918 | 1689 | if (pcrel) |
252b5132 RH |
1690 | { |
1691 | #if KEEPMINUSPCININST | |
1692 | bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc); | |
1693 | r->relent.addend -= current_map->pc; | |
1694 | r->relent.howto = &rel8_howto; | |
1695 | #else | |
1696 | bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc); | |
1697 | r->relent.howto = &rel8_howto; | |
1698 | #endif | |
1699 | } | |
1700 | else | |
1701 | { | |
1702 | bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc); | |
1703 | r->relent.howto = &abs8_howto; | |
1704 | } | |
1705 | current_map->pc += 1; | |
1706 | break; | |
1707 | ||
1708 | default: | |
1709 | BFD_FAIL (); | |
b34976b6 | 1710 | return FALSE; |
252b5132 RH |
1711 | } |
1712 | } | |
1713 | break; | |
1714 | default: | |
1715 | { | |
1716 | bfd_vma this_size; | |
c8e7bf0d | 1717 | |
82e51918 | 1718 | if (parse_int (&(ieee->h), &this_size)) |
252b5132 RH |
1719 | { |
1720 | unsigned int i; | |
c8e7bf0d | 1721 | |
252b5132 RH |
1722 | for (i = 0; i < this_size; i++) |
1723 | { | |
1724 | location_ptr[current_map->pc++] = this_byte (&(ieee->h)); | |
0a9d414a NC |
1725 | if (! next_byte (&(ieee->h))) |
1726 | return FALSE; | |
252b5132 RH |
1727 | } |
1728 | } | |
1729 | else | |
c8e7bf0d | 1730 | loop = FALSE; |
252b5132 RH |
1731 | } |
1732 | } | |
1733 | ||
1734 | /* Prevent more than the first load-item of an LR record | |
c8e7bf0d | 1735 | from being repeated (MRI convention). */ |
252b5132 | 1736 | if (iterations != 1) |
b34976b6 | 1737 | loop = FALSE; |
252b5132 RH |
1738 | } |
1739 | } | |
1740 | } | |
b34976b6 | 1741 | return TRUE; |
252b5132 RH |
1742 | } |
1743 | ||
49ae03bf NC |
1744 | /* Read in all the section data and relocation stuff too. */ |
1745 | ||
b34976b6 | 1746 | static bfd_boolean |
c8e7bf0d | 1747 | ieee_slurp_section_data (bfd *abfd) |
252b5132 RH |
1748 | { |
1749 | bfd_byte *location_ptr = (bfd_byte *) NULL; | |
1750 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
1751 | unsigned int section_number; | |
c8e7bf0d | 1752 | ieee_per_section_type *current_map = NULL; |
252b5132 | 1753 | asection *s; |
68ffbac6 | 1754 | |
49ae03bf | 1755 | /* Seek to the start of the data area. */ |
82e51918 | 1756 | if (ieee->read_data) |
b34976b6 AM |
1757 | return TRUE; |
1758 | ieee->read_data = TRUE; | |
0a9d414a NC |
1759 | |
1760 | if (! ieee_seek (ieee, ieee->w.r.data_part)) | |
1761 | return FALSE; | |
252b5132 | 1762 | |
49ae03bf | 1763 | /* Allocate enough space for all the section contents. */ |
252b5132 RH |
1764 | for (s = abfd->sections; s != (asection *) NULL; s = s->next) |
1765 | { | |
68bfbfcc | 1766 | ieee_per_section_type *per = ieee_per_section (s); |
6edfbbad | 1767 | arelent **relpp; |
c8e7bf0d | 1768 | |
252b5132 RH |
1769 | if ((s->flags & SEC_DEBUGGING) != 0) |
1770 | continue; | |
c8e7bf0d | 1771 | per->data = bfd_alloc (ieee->h.abfd, s->size); |
252b5132 | 1772 | if (!per->data) |
b34976b6 | 1773 | return FALSE; |
6edfbbad DJ |
1774 | relpp = &s->relocation; |
1775 | per->reloc_tail_ptr = (ieee_reloc_type **) relpp; | |
252b5132 RH |
1776 | } |
1777 | ||
b34976b6 | 1778 | while (TRUE) |
252b5132 RH |
1779 | { |
1780 | switch (this_byte (&(ieee->h))) | |
1781 | { | |
49ae03bf | 1782 | /* IF we see anything strange then quit. */ |
252b5132 | 1783 | default: |
b34976b6 | 1784 | return TRUE; |
252b5132 RH |
1785 | |
1786 | case ieee_set_current_section_enum: | |
0a9d414a NC |
1787 | if (! next_byte (&(ieee->h))) |
1788 | return FALSE; | |
252b5132 RH |
1789 | section_number = must_parse_int (&(ieee->h)); |
1790 | s = ieee->section_table[section_number]; | |
1791 | s->flags |= SEC_LOAD | SEC_HAS_CONTENTS; | |
68bfbfcc | 1792 | current_map = ieee_per_section (s); |
252b5132 | 1793 | location_ptr = current_map->data - s->vma; |
49ae03bf NC |
1794 | /* The document I have says that Microtec's compilers reset |
1795 | this after a sec section, even though the standard says not | |
1796 | to, SO... */ | |
252b5132 RH |
1797 | current_map->pc = s->vma; |
1798 | break; | |
1799 | ||
1800 | case ieee_e2_first_byte_enum: | |
0a9d414a NC |
1801 | if (! next_byte (&(ieee->h))) |
1802 | return FALSE; | |
252b5132 RH |
1803 | switch (this_byte (&(ieee->h))) |
1804 | { | |
1805 | case ieee_set_current_pc_enum & 0xff: | |
1806 | { | |
1807 | bfd_vma value; | |
1808 | ieee_symbol_index_type symbol; | |
1809 | unsigned int extra; | |
b34976b6 | 1810 | bfd_boolean pcrel; |
49ae03bf | 1811 | |
0a9d414a NC |
1812 | if (! next_byte (&(ieee->h))) |
1813 | return FALSE; | |
49ae03bf | 1814 | must_parse_int (&(ieee->h)); /* Throw away section #. */ |
0a9d414a NC |
1815 | if (! parse_expression (ieee, &value, |
1816 | &symbol, | |
1817 | &pcrel, &extra, | |
1818 | 0)) | |
1819 | return FALSE; | |
1820 | ||
252b5132 | 1821 | current_map->pc = value; |
eea6121a | 1822 | BFD_ASSERT ((unsigned) (value - s->vma) <= s->size); |
252b5132 RH |
1823 | } |
1824 | break; | |
1825 | ||
1826 | case ieee_value_starting_address_enum & 0xff: | |
0a9d414a NC |
1827 | if (! next_byte (&(ieee->h))) |
1828 | return FALSE; | |
252b5132 | 1829 | if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum) |
0a9d414a NC |
1830 | { |
1831 | if (! next_byte (&(ieee->h))) | |
1832 | return FALSE; | |
1833 | } | |
252b5132 | 1834 | abfd->start_address = must_parse_int (&(ieee->h)); |
49ae03bf | 1835 | /* We've got to the end of the data now - */ |
b34976b6 | 1836 | return TRUE; |
252b5132 RH |
1837 | default: |
1838 | BFD_FAIL (); | |
b34976b6 | 1839 | return FALSE; |
252b5132 RH |
1840 | } |
1841 | break; | |
1842 | case ieee_repeat_data_enum: | |
1843 | { | |
1844 | /* Repeat the following LD or LR n times - we do this by | |
49ae03bf NC |
1845 | remembering the stream pointer before running it and |
1846 | resetting it and running it n times. We special case | |
1847 | the repetition of a repeat_data/load_constant. */ | |
252b5132 RH |
1848 | unsigned int iterations; |
1849 | unsigned char *start; | |
49ae03bf | 1850 | |
0a9d414a NC |
1851 | if (! next_byte (&(ieee->h))) |
1852 | return FALSE; | |
252b5132 RH |
1853 | iterations = must_parse_int (&(ieee->h)); |
1854 | start = ieee->h.input_p; | |
49ae03bf NC |
1855 | if (start[0] == (int) ieee_load_constant_bytes_enum |
1856 | && start[1] == 1) | |
252b5132 RH |
1857 | { |
1858 | while (iterations != 0) | |
1859 | { | |
1860 | location_ptr[current_map->pc++] = start[2]; | |
1861 | iterations--; | |
1862 | } | |
0a9d414a NC |
1863 | (void) next_byte (&(ieee->h)); |
1864 | (void) next_byte (&(ieee->h)); | |
1865 | if (! next_byte (&(ieee->h))) | |
1866 | return FALSE; | |
252b5132 RH |
1867 | } |
1868 | else | |
1869 | { | |
1870 | while (iterations != 0) | |
1871 | { | |
1872 | ieee->h.input_p = start; | |
1873 | if (!do_one (ieee, current_map, location_ptr, s, | |
dc810e39 | 1874 | (int) iterations)) |
b34976b6 | 1875 | return FALSE; |
252b5132 RH |
1876 | iterations--; |
1877 | } | |
1878 | } | |
1879 | } | |
1880 | break; | |
1881 | case ieee_load_constant_bytes_enum: | |
1882 | case ieee_load_with_relocation_enum: | |
49ae03bf NC |
1883 | if (!do_one (ieee, current_map, location_ptr, s, 1)) |
1884 | return FALSE; | |
252b5132 RH |
1885 | } |
1886 | } | |
1887 | } | |
1888 | ||
46e94266 NC |
1889 | static const bfd_target * |
1890 | ieee_object_p (bfd *abfd) | |
1891 | { | |
1892 | char *processor; | |
1893 | unsigned int part; | |
1894 | ieee_data_type *ieee; | |
63634bb4 | 1895 | static unsigned char buffer[300]; |
46e94266 NC |
1896 | ieee_data_type *save = IEEE_DATA (abfd); |
1897 | bfd_size_type amt; | |
1898 | ||
1899 | abfd->tdata.ieee_data = 0; | |
1900 | ieee_mkobject (abfd); | |
1901 | ||
1902 | ieee = IEEE_DATA (abfd); | |
1903 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) | |
1904 | goto fail; | |
1905 | /* Read the first few bytes in to see if it makes sense. Ignore | |
1906 | bfd_bread return value; The file might be very small. */ | |
041830e0 NC |
1907 | if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0) |
1908 | goto got_wrong_format; | |
46e94266 NC |
1909 | |
1910 | ieee->h.input_p = buffer; | |
0a9d414a | 1911 | ieee->h.total_amt = sizeof (buffer); |
acb56a83 NC |
1912 | ieee->h.end_p = buffer + sizeof (buffer); |
1913 | ||
46e94266 NC |
1914 | if (this_byte_and_next (&(ieee->h)) != Module_Beginning) |
1915 | goto got_wrong_format; | |
1916 | ||
1917 | ieee->read_symbols = FALSE; | |
1918 | ieee->read_data = FALSE; | |
1919 | ieee->section_count = 0; | |
1920 | ieee->external_symbol_max_index = 0; | |
1921 | ieee->external_symbol_min_index = IEEE_PUBLIC_BASE; | |
1922 | ieee->external_reference_min_index = IEEE_REFERENCE_BASE; | |
1923 | ieee->external_reference_max_index = 0; | |
1924 | ieee->h.abfd = abfd; | |
1925 | ieee->section_table = NULL; | |
1926 | ieee->section_table_size = 0; | |
1927 | ||
1928 | processor = ieee->mb.processor = read_id (&(ieee->h)); | |
c458d007 | 1929 | if (processor == NULL) |
07d6d2b8 | 1930 | goto got_wrong_format; |
46e94266 NC |
1931 | if (strcmp (processor, "LIBRARY") == 0) |
1932 | goto got_wrong_format; | |
1933 | ieee->mb.module_name = read_id (&(ieee->h)); | |
c458d007 NC |
1934 | if (ieee->mb.module_name == NULL) |
1935 | goto got_wrong_format; | |
46e94266 | 1936 | if (abfd->filename == (const char *) NULL) |
1be5090b | 1937 | abfd->filename = xstrdup (ieee->mb.module_name); |
46e94266 NC |
1938 | |
1939 | /* Determine the architecture and machine type of the object file. */ | |
1940 | { | |
1941 | const bfd_arch_info_type *arch; | |
1942 | char family[10]; | |
1943 | ||
1944 | /* IEEE does not specify the format of the processor identification | |
1945 | string, so the compiler is free to put in it whatever it wants. | |
1946 | We try here to recognize different processors belonging to the | |
1947 | m68k family. Code for other processors can be added here. */ | |
1948 | if ((processor[0] == '6') && (processor[1] == '8')) | |
1949 | { | |
1950 | if (processor[2] == '3') /* 683xx integrated processors. */ | |
1951 | { | |
1952 | switch (processor[3]) | |
1953 | { | |
1954 | case '0': /* 68302, 68306, 68307 */ | |
1955 | case '2': /* 68322, 68328 */ | |
1956 | case '5': /* 68356 */ | |
1957 | strcpy (family, "68000"); /* MC68000-based controllers. */ | |
1958 | break; | |
1959 | ||
1960 | case '3': /* 68330, 68331, 68332, 68333, | |
1961 | 68334, 68335, 68336, 68338 */ | |
1962 | case '6': /* 68360 */ | |
1963 | case '7': /* 68376 */ | |
1964 | strcpy (family, "68332"); /* CPU32 and CPU32+ */ | |
1965 | break; | |
1966 | ||
1967 | case '4': | |
1968 | if (processor[4] == '9') /* 68349 */ | |
1969 | strcpy (family, "68030"); /* CPU030 */ | |
07d6d2b8 | 1970 | else /* 68340, 68341 */ |
46e94266 NC |
1971 | strcpy (family, "68332"); /* CPU32 and CPU32+ */ |
1972 | break; | |
1973 | ||
1974 | default: /* Does not exist yet. */ | |
1975 | strcpy (family, "68332"); /* Guess it will be CPU32 */ | |
1976 | } | |
1977 | } | |
1978 | else if (TOUPPER (processor[3]) == 'F') /* 68F333 */ | |
07d6d2b8 | 1979 | strcpy (family, "68332"); /* CPU32 */ |
46e94266 NC |
1980 | else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers. */ |
1981 | && ((TOUPPER (processor[2]) == 'E') | |
1982 | || (TOUPPER (processor[2]) == 'H') | |
1983 | || (TOUPPER (processor[2]) == 'L'))) | |
1984 | { | |
1985 | strcpy (family, "68"); | |
1986 | strncat (family, processor + 4, 7); | |
1987 | family[9] = '\0'; | |
1988 | } | |
1989 | else /* "Regular" processors. */ | |
1990 | { | |
1991 | strncpy (family, processor, 9); | |
1992 | family[9] = '\0'; | |
1993 | } | |
1994 | } | |
0112cd26 NC |
1995 | else if ((CONST_STRNEQ (processor, "cpu32")) /* CPU32 and CPU32+ */ |
1996 | || (CONST_STRNEQ (processor, "CPU32"))) | |
46e94266 NC |
1997 | strcpy (family, "68332"); |
1998 | else | |
1999 | { | |
2000 | strncpy (family, processor, 9); | |
2001 | family[9] = '\0'; | |
2002 | } | |
2003 | ||
2004 | arch = bfd_scan_arch (family); | |
2005 | if (arch == 0) | |
2006 | goto got_wrong_format; | |
2007 | abfd->arch_info = arch; | |
2008 | } | |
2009 | ||
2010 | if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum) | |
2011 | goto fail; | |
2012 | ||
0a9d414a NC |
2013 | if (! next_byte (&(ieee->h))) |
2014 | goto fail; | |
46e94266 NC |
2015 | |
2016 | if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau)) | |
2017 | goto fail; | |
2018 | ||
2019 | if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address)) | |
2020 | goto fail; | |
2021 | ||
2022 | /* If there is a byte order info, take it. */ | |
2023 | if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum | |
2024 | || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum) | |
0a9d414a NC |
2025 | { |
2026 | if (! next_byte (&(ieee->h))) | |
2027 | goto fail; | |
2028 | } | |
46e94266 NC |
2029 | |
2030 | for (part = 0; part < N_W_VARIABLES; part++) | |
2031 | { | |
2032 | bfd_boolean ok; | |
2033 | ||
2034 | if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum) | |
2035 | goto fail; | |
2036 | ||
2037 | if (this_byte_and_next (&(ieee->h)) != part) | |
2038 | goto fail; | |
2039 | ||
2040 | ieee->w.offset[part] = parse_i (&(ieee->h), &ok); | |
2041 | if (! ok) | |
2042 | goto fail; | |
2043 | } | |
2044 | ||
2045 | if (ieee->w.r.external_part != 0) | |
2046 | abfd->flags = HAS_SYMS; | |
2047 | ||
2048 | /* By now we know that this is a real IEEE file, we're going to read | |
2049 | the whole thing into memory so that we can run up and down it | |
2050 | quickly. We can work out how big the file is from the trailer | |
2051 | record. */ | |
2052 | ||
2053 | amt = ieee->w.r.me_record + 1; | |
2054 | IEEE_DATA (abfd)->h.first_byte = bfd_alloc (ieee->h.abfd, amt); | |
2055 | if (!IEEE_DATA (abfd)->h.first_byte) | |
2056 | goto fail; | |
2057 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) | |
2058 | goto fail; | |
0a9d414a | 2059 | |
46e94266 NC |
2060 | /* FIXME: Check return value. I'm not sure whether it needs to read |
2061 | the entire buffer or not. */ | |
0a9d414a NC |
2062 | amt = bfd_bread ((void *) (IEEE_DATA (abfd)->h.first_byte), |
2063 | (bfd_size_type) ieee->w.r.me_record + 1, abfd); | |
2064 | if (amt <= 0) | |
2065 | goto fail; | |
46e94266 | 2066 | |
0a9d414a NC |
2067 | IEEE_DATA (abfd)->h.total_amt = amt; |
2068 | if (ieee_slurp_sections (abfd)) | |
2069 | goto fail; | |
46e94266 NC |
2070 | |
2071 | if (! ieee_slurp_debug (abfd)) | |
2072 | goto fail; | |
2073 | ||
2074 | /* Parse section data to activate file and section flags implied by | |
2075 | section contents. */ | |
2076 | if (! ieee_slurp_section_data (abfd)) | |
2077 | goto fail; | |
2078 | ||
2079 | return abfd->xvec; | |
2080 | got_wrong_format: | |
2081 | bfd_set_error (bfd_error_wrong_format); | |
2082 | fail: | |
2083 | bfd_release (abfd, ieee); | |
2084 | abfd->tdata.ieee_data = save; | |
2085 | return (const bfd_target *) NULL; | |
2086 | } | |
2087 | ||
2088 | static void | |
2089 | ieee_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED, | |
2090 | asymbol *symbol, | |
2091 | symbol_info *ret) | |
2092 | { | |
2093 | bfd_symbol_info (symbol, ret); | |
2094 | if (symbol->name[0] == ' ') | |
2095 | ret->name = "* empty table entry "; | |
2096 | if (!symbol->section) | |
2097 | ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A'; | |
2098 | } | |
2099 | ||
2100 | static void | |
2101 | ieee_print_symbol (bfd *abfd, | |
2102 | void * afile, | |
2103 | asymbol *symbol, | |
2104 | bfd_print_symbol_type how) | |
2105 | { | |
2106 | FILE *file = (FILE *) afile; | |
2107 | ||
2108 | switch (how) | |
2109 | { | |
2110 | case bfd_print_symbol_name: | |
2111 | fprintf (file, "%s", symbol->name); | |
2112 | break; | |
2113 | case bfd_print_symbol_more: | |
2114 | BFD_FAIL (); | |
2115 | break; | |
2116 | case bfd_print_symbol_all: | |
2117 | { | |
2118 | const char *section_name = | |
2119 | (symbol->section == (asection *) NULL | |
2120 | ? "*abs" | |
2121 | : symbol->section->name); | |
2122 | ||
2123 | if (symbol->name[0] == ' ') | |
2124 | fprintf (file, "* empty table entry "); | |
2125 | else | |
2126 | { | |
2127 | bfd_print_symbol_vandf (abfd, (void *) file, symbol); | |
2128 | ||
2129 | fprintf (file, " %-5s %04x %02x %s", | |
2130 | section_name, | |
2131 | (unsigned) ieee_symbol (symbol)->index, | |
2132 | (unsigned) 0, | |
2133 | symbol->name); | |
2134 | } | |
2135 | } | |
2136 | break; | |
2137 | } | |
2138 | } | |
2139 | ||
2140 | static bfd_boolean | |
2141 | ieee_new_section_hook (bfd *abfd, asection *newsect) | |
252b5132 | 2142 | { |
252b5132 | 2143 | if (!newsect->used_by_bfd) |
f592407e AM |
2144 | { |
2145 | newsect->used_by_bfd = bfd_alloc (abfd, sizeof (ieee_per_section_type)); | |
2146 | if (!newsect->used_by_bfd) | |
2147 | return FALSE; | |
2148 | } | |
c8e7bf0d | 2149 | ieee_per_section (newsect)->data = NULL; |
252b5132 | 2150 | ieee_per_section (newsect)->section = newsect; |
f592407e | 2151 | return _bfd_generic_new_section_hook (abfd, newsect); |
252b5132 RH |
2152 | } |
2153 | ||
47fda0d3 | 2154 | static long |
c8e7bf0d | 2155 | ieee_get_reloc_upper_bound (bfd *abfd, sec_ptr asect) |
252b5132 RH |
2156 | { |
2157 | if ((asect->flags & SEC_DEBUGGING) != 0) | |
2158 | return 0; | |
2159 | if (! ieee_slurp_section_data (abfd)) | |
2160 | return -1; | |
2161 | return (asect->reloc_count + 1) * sizeof (arelent *); | |
2162 | } | |
2163 | ||
b34976b6 | 2164 | static bfd_boolean |
c8e7bf0d NC |
2165 | ieee_get_section_contents (bfd *abfd, |
2166 | sec_ptr section, | |
2167 | void * location, | |
2168 | file_ptr offset, | |
2169 | bfd_size_type count) | |
252b5132 | 2170 | { |
68bfbfcc | 2171 | ieee_per_section_type *p = ieee_per_section (section); |
252b5132 RH |
2172 | if ((section->flags & SEC_DEBUGGING) != 0) |
2173 | return _bfd_generic_get_section_contents (abfd, section, location, | |
2174 | offset, count); | |
2175 | ieee_slurp_section_data (abfd); | |
c8e7bf0d | 2176 | (void) memcpy ((void *) location, (void *) (p->data + offset), (unsigned) count); |
b34976b6 | 2177 | return TRUE; |
252b5132 RH |
2178 | } |
2179 | ||
47fda0d3 | 2180 | static long |
c8e7bf0d NC |
2181 | ieee_canonicalize_reloc (bfd *abfd, |
2182 | sec_ptr section, | |
2183 | arelent **relptr, | |
2184 | asymbol **symbols) | |
252b5132 | 2185 | { |
252b5132 RH |
2186 | ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation); |
2187 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
2188 | ||
2189 | if ((section->flags & SEC_DEBUGGING) != 0) | |
2190 | return 0; | |
2191 | ||
2192 | while (src != (ieee_reloc_type *) NULL) | |
2193 | { | |
49ae03bf | 2194 | /* Work out which symbol to attach it this reloc to. */ |
252b5132 RH |
2195 | switch (src->symbol.letter) |
2196 | { | |
2197 | case 'I': | |
2198 | src->relent.sym_ptr_ptr = | |
2199 | symbols + src->symbol.index + ieee->external_symbol_base_offset; | |
2200 | break; | |
2201 | case 'X': | |
2202 | src->relent.sym_ptr_ptr = | |
2203 | symbols + src->symbol.index + ieee->external_reference_base_offset; | |
2204 | break; | |
2205 | case 0: | |
2206 | if (src->relent.sym_ptr_ptr != NULL) | |
2207 | src->relent.sym_ptr_ptr = | |
2208 | src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr; | |
2209 | break; | |
2210 | default: | |
2211 | ||
2212 | BFD_FAIL (); | |
2213 | } | |
2214 | *relptr++ = &src->relent; | |
2215 | src = src->next; | |
2216 | } | |
c8e7bf0d | 2217 | *relptr = NULL; |
252b5132 RH |
2218 | return section->reloc_count; |
2219 | } | |
2220 | ||
2221 | static int | |
c8e7bf0d | 2222 | comp (const void * ap, const void * bp) |
252b5132 RH |
2223 | { |
2224 | arelent *a = *((arelent **) ap); | |
2225 | arelent *b = *((arelent **) bp); | |
2226 | return a->address - b->address; | |
2227 | } | |
2228 | ||
2229 | /* Write the section headers. */ | |
2230 | ||
b34976b6 | 2231 | static bfd_boolean |
c8e7bf0d | 2232 | ieee_write_section_part (bfd *abfd) |
252b5132 RH |
2233 | { |
2234 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
2235 | asection *s; | |
c8e7bf0d | 2236 | |
252b5132 RH |
2237 | ieee->w.r.section_part = bfd_tell (abfd); |
2238 | for (s = abfd->sections; s != (asection *) NULL; s = s->next) | |
2239 | { | |
2240 | if (! bfd_is_abs_section (s) | |
2241 | && (s->flags & SEC_DEBUGGING) == 0) | |
2242 | { | |
2243 | if (! ieee_write_byte (abfd, ieee_section_type_enum) | |
2244 | || ! ieee_write_byte (abfd, | |
2245 | (bfd_byte) (s->index | |
2246 | + IEEE_SECTION_NUMBER_BASE))) | |
b34976b6 | 2247 | return FALSE; |
252b5132 RH |
2248 | |
2249 | if (abfd->flags & EXEC_P) | |
2250 | { | |
49ae03bf | 2251 | /* This image is executable, so output absolute sections. */ |
252b5132 RH |
2252 | if (! ieee_write_byte (abfd, ieee_variable_A_enum) |
2253 | || ! ieee_write_byte (abfd, ieee_variable_S_enum)) | |
b34976b6 | 2254 | return FALSE; |
252b5132 RH |
2255 | } |
2256 | else | |
2257 | { | |
2258 | if (! ieee_write_byte (abfd, ieee_variable_C_enum)) | |
b34976b6 | 2259 | return FALSE; |
252b5132 RH |
2260 | } |
2261 | ||
2262 | switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM)) | |
2263 | { | |
2264 | case SEC_CODE | SEC_LOAD: | |
2265 | case SEC_CODE: | |
2266 | if (! ieee_write_byte (abfd, ieee_variable_P_enum)) | |
b34976b6 | 2267 | return FALSE; |
252b5132 RH |
2268 | break; |
2269 | case SEC_DATA: | |
2270 | default: | |
2271 | if (! ieee_write_byte (abfd, ieee_variable_D_enum)) | |
b34976b6 | 2272 | return FALSE; |
252b5132 RH |
2273 | break; |
2274 | case SEC_ROM: | |
2275 | case SEC_ROM | SEC_DATA: | |
2276 | case SEC_ROM | SEC_LOAD: | |
2277 | case SEC_ROM | SEC_DATA | SEC_LOAD: | |
2278 | if (! ieee_write_byte (abfd, ieee_variable_R_enum)) | |
b34976b6 | 2279 | return FALSE; |
252b5132 RH |
2280 | } |
2281 | ||
2282 | ||
2283 | if (! ieee_write_id (abfd, s->name)) | |
b34976b6 | 2284 | return FALSE; |
49ae03bf | 2285 | /* Alignment. */ |
252b5132 RH |
2286 | if (! ieee_write_byte (abfd, ieee_section_alignment_enum) |
2287 | || ! ieee_write_byte (abfd, | |
2288 | (bfd_byte) (s->index | |
2289 | + IEEE_SECTION_NUMBER_BASE)) | |
dc810e39 | 2290 | || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power)) |
b34976b6 | 2291 | return FALSE; |
252b5132 | 2292 | |
49ae03bf | 2293 | /* Size. */ |
252b5132 RH |
2294 | if (! ieee_write_2bytes (abfd, ieee_section_size_enum) |
2295 | || ! ieee_write_byte (abfd, | |
2296 | (bfd_byte) (s->index | |
2297 | + IEEE_SECTION_NUMBER_BASE)) | |
eea6121a | 2298 | || ! ieee_write_int (abfd, s->size)) |
b34976b6 | 2299 | return FALSE; |
252b5132 RH |
2300 | if (abfd->flags & EXEC_P) |
2301 | { | |
49ae03bf NC |
2302 | /* Relocateable sections don't have asl records. */ |
2303 | /* Vma. */ | |
252b5132 RH |
2304 | if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum) |
2305 | || ! ieee_write_byte (abfd, | |
2306 | ((bfd_byte) | |
2307 | (s->index | |
2308 | + IEEE_SECTION_NUMBER_BASE))) | |
2309 | || ! ieee_write_int (abfd, s->lma)) | |
b34976b6 | 2310 | return FALSE; |
252b5132 RH |
2311 | } |
2312 | } | |
2313 | } | |
2314 | ||
b34976b6 | 2315 | return TRUE; |
252b5132 RH |
2316 | } |
2317 | ||
b34976b6 | 2318 | static bfd_boolean |
c8e7bf0d | 2319 | do_with_relocs (bfd *abfd, asection *s) |
252b5132 RH |
2320 | { |
2321 | unsigned int number_of_maus_in_address = | |
2322 | bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd); | |
2323 | unsigned int relocs_to_go = s->reloc_count; | |
2324 | bfd_byte *stream = ieee_per_section (s)->data; | |
2325 | arelent **p = s->orelocation; | |
2326 | bfd_size_type current_byte_index = 0; | |
2327 | ||
2328 | qsort (s->orelocation, | |
2329 | relocs_to_go, | |
2330 | sizeof (arelent **), | |
2331 | comp); | |
2332 | ||
49ae03bf | 2333 | /* Output the section preheader. */ |
252b5132 RH |
2334 | if (! ieee_write_byte (abfd, ieee_set_current_section_enum) |
2335 | || ! ieee_write_byte (abfd, | |
2336 | (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)) | |
2337 | || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum) | |
2338 | || ! ieee_write_byte (abfd, | |
2339 | (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))) | |
b34976b6 | 2340 | return FALSE; |
47fda0d3 | 2341 | |
252b5132 RH |
2342 | if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0) |
2343 | { | |
2344 | if (! ieee_write_int (abfd, s->lma)) | |
b34976b6 | 2345 | return FALSE; |
252b5132 RH |
2346 | } |
2347 | else | |
2348 | { | |
dc810e39 | 2349 | if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0)) |
b34976b6 | 2350 | return FALSE; |
252b5132 RH |
2351 | } |
2352 | ||
2353 | if (relocs_to_go == 0) | |
2354 | { | |
2355 | /* If there aren't any relocations then output the load constant | |
49ae03bf | 2356 | byte opcode rather than the load with relocation opcode. */ |
eea6121a | 2357 | while (current_byte_index < s->size) |
252b5132 RH |
2358 | { |
2359 | bfd_size_type run; | |
2360 | unsigned int MAXRUN = 127; | |
49ae03bf | 2361 | |
252b5132 | 2362 | run = MAXRUN; |
eea6121a AM |
2363 | if (run > s->size - current_byte_index) |
2364 | run = s->size - current_byte_index; | |
252b5132 RH |
2365 | |
2366 | if (run != 0) | |
2367 | { | |
2368 | if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)) | |
b34976b6 | 2369 | return FALSE; |
49ae03bf | 2370 | /* Output a stream of bytes. */ |
252b5132 | 2371 | if (! ieee_write_int (abfd, run)) |
b34976b6 | 2372 | return FALSE; |
c8e7bf0d | 2373 | if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd) |
252b5132 | 2374 | != run) |
b34976b6 | 2375 | return FALSE; |
252b5132 RH |
2376 | current_byte_index += run; |
2377 | } | |
2378 | } | |
2379 | } | |
2380 | else | |
2381 | { | |
2382 | if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum)) | |
b34976b6 | 2383 | return FALSE; |
252b5132 RH |
2384 | |
2385 | /* Output the data stream as the longest sequence of bytes | |
2386 | possible, allowing for the a reasonable packet size and | |
2387 | relocation stuffs. */ | |
c8e7bf0d | 2388 | if (stream == NULL) |
252b5132 | 2389 | { |
49ae03bf | 2390 | /* Outputting a section without data, fill it up. */ |
c8e7bf0d | 2391 | stream = bfd_zalloc (abfd, s->size); |
252b5132 | 2392 | if (!stream) |
b34976b6 | 2393 | return FALSE; |
252b5132 | 2394 | } |
eea6121a | 2395 | while (current_byte_index < s->size) |
252b5132 RH |
2396 | { |
2397 | bfd_size_type run; | |
2398 | unsigned int MAXRUN = 127; | |
49ae03bf | 2399 | |
252b5132 RH |
2400 | if (relocs_to_go) |
2401 | { | |
2402 | run = (*p)->address - current_byte_index; | |
2403 | if (run > MAXRUN) | |
2404 | run = MAXRUN; | |
2405 | } | |
2406 | else | |
49ae03bf NC |
2407 | run = MAXRUN; |
2408 | ||
eea6121a AM |
2409 | if (run > s->size - current_byte_index) |
2410 | run = s->size - current_byte_index; | |
252b5132 RH |
2411 | |
2412 | if (run != 0) | |
2413 | { | |
49ae03bf | 2414 | /* Output a stream of bytes. */ |
252b5132 | 2415 | if (! ieee_write_int (abfd, run)) |
b34976b6 | 2416 | return FALSE; |
c8e7bf0d | 2417 | if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd) |
252b5132 | 2418 | != run) |
b34976b6 | 2419 | return FALSE; |
252b5132 RH |
2420 | current_byte_index += run; |
2421 | } | |
49ae03bf NC |
2422 | |
2423 | /* Output any relocations here. */ | |
252b5132 RH |
2424 | if (relocs_to_go && (*p) && (*p)->address == current_byte_index) |
2425 | { | |
2426 | while (relocs_to_go | |
2427 | && (*p) && (*p)->address == current_byte_index) | |
2428 | { | |
2429 | arelent *r = *p; | |
2430 | bfd_signed_vma ov; | |
252b5132 RH |
2431 | switch (r->howto->size) |
2432 | { | |
2433 | case 2: | |
252b5132 RH |
2434 | ov = bfd_get_signed_32 (abfd, |
2435 | stream + current_byte_index); | |
2436 | current_byte_index += 4; | |
2437 | break; | |
2438 | case 1: | |
2439 | ov = bfd_get_signed_16 (abfd, | |
2440 | stream + current_byte_index); | |
2441 | current_byte_index += 2; | |
2442 | break; | |
2443 | case 0: | |
2444 | ov = bfd_get_signed_8 (abfd, | |
2445 | stream + current_byte_index); | |
2446 | current_byte_index++; | |
2447 | break; | |
2448 | default: | |
2449 | ov = 0; | |
2450 | BFD_FAIL (); | |
b34976b6 | 2451 | return FALSE; |
252b5132 RH |
2452 | } |
2453 | ||
2454 | ov &= r->howto->src_mask; | |
2455 | ||
2456 | if (r->howto->pc_relative | |
2457 | && ! r->howto->pcrel_offset) | |
2458 | ov += r->address; | |
2459 | ||
2460 | if (! ieee_write_byte (abfd, | |
2461 | ieee_function_either_open_b_enum)) | |
b34976b6 | 2462 | return FALSE; |
252b5132 | 2463 | |
252b5132 RH |
2464 | if (r->sym_ptr_ptr != (asymbol **) NULL) |
2465 | { | |
2466 | if (! ieee_write_expression (abfd, r->addend + ov, | |
2467 | *(r->sym_ptr_ptr), | |
2468 | r->howto->pc_relative, | |
dc810e39 | 2469 | (unsigned) s->index)) |
b34976b6 | 2470 | return FALSE; |
252b5132 RH |
2471 | } |
2472 | else | |
2473 | { | |
2474 | if (! ieee_write_expression (abfd, r->addend + ov, | |
2475 | (asymbol *) NULL, | |
2476 | r->howto->pc_relative, | |
dc810e39 | 2477 | (unsigned) s->index)) |
b34976b6 | 2478 | return FALSE; |
252b5132 RH |
2479 | } |
2480 | ||
2481 | if (number_of_maus_in_address | |
2482 | != bfd_get_reloc_size (r->howto)) | |
2483 | { | |
dc810e39 AM |
2484 | bfd_vma rsize = bfd_get_reloc_size (r->howto); |
2485 | if (! ieee_write_int (abfd, rsize)) | |
b34976b6 | 2486 | return FALSE; |
252b5132 RH |
2487 | } |
2488 | if (! ieee_write_byte (abfd, | |
2489 | ieee_function_either_close_b_enum)) | |
b34976b6 | 2490 | return FALSE; |
252b5132 RH |
2491 | |
2492 | relocs_to_go--; | |
2493 | p++; | |
2494 | } | |
2495 | ||
2496 | } | |
2497 | } | |
2498 | } | |
2499 | ||
b34976b6 | 2500 | return TRUE; |
252b5132 RH |
2501 | } |
2502 | ||
2503 | /* If there are no relocations in the output section then we can be | |
2504 | clever about how we write. We block items up into a max of 127 | |
2505 | bytes. */ | |
2506 | ||
b34976b6 | 2507 | static bfd_boolean |
c8e7bf0d | 2508 | do_as_repeat (bfd *abfd, asection *s) |
252b5132 | 2509 | { |
eea6121a | 2510 | if (s->size) |
252b5132 RH |
2511 | { |
2512 | if (! ieee_write_byte (abfd, ieee_set_current_section_enum) | |
2513 | || ! ieee_write_byte (abfd, | |
2514 | (bfd_byte) (s->index | |
2515 | + IEEE_SECTION_NUMBER_BASE)) | |
2516 | || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8) | |
2517 | || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff) | |
2518 | || ! ieee_write_byte (abfd, | |
2519 | (bfd_byte) (s->index | |
47fda0d3 | 2520 | + IEEE_SECTION_NUMBER_BASE))) |
b34976b6 | 2521 | return FALSE; |
47fda0d3 AM |
2522 | |
2523 | if ((abfd->flags & EXEC_P) != 0) | |
2524 | { | |
2525 | if (! ieee_write_int (abfd, s->lma)) | |
b34976b6 | 2526 | return FALSE; |
47fda0d3 AM |
2527 | } |
2528 | else | |
2529 | { | |
dc810e39 | 2530 | if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0)) |
b34976b6 | 2531 | return FALSE; |
47fda0d3 AM |
2532 | } |
2533 | ||
2534 | if (! ieee_write_byte (abfd, ieee_repeat_data_enum) | |
eea6121a | 2535 | || ! ieee_write_int (abfd, s->size) |
252b5132 RH |
2536 | || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum) |
2537 | || ! ieee_write_byte (abfd, 1) | |
2538 | || ! ieee_write_byte (abfd, 0)) | |
b34976b6 | 2539 | return FALSE; |
252b5132 RH |
2540 | } |
2541 | ||
b34976b6 | 2542 | return TRUE; |
252b5132 RH |
2543 | } |
2544 | ||
b34976b6 | 2545 | static bfd_boolean |
c8e7bf0d | 2546 | do_without_relocs (bfd *abfd, asection *s) |
252b5132 RH |
2547 | { |
2548 | bfd_byte *stream = ieee_per_section (s)->data; | |
2549 | ||
2550 | if (stream == 0 || ((s->flags & SEC_LOAD) == 0)) | |
2551 | { | |
2552 | if (! do_as_repeat (abfd, s)) | |
b34976b6 | 2553 | return FALSE; |
252b5132 RH |
2554 | } |
2555 | else | |
2556 | { | |
2557 | unsigned int i; | |
49ae03bf | 2558 | |
eea6121a | 2559 | for (i = 0; i < s->size; i++) |
252b5132 RH |
2560 | { |
2561 | if (stream[i] != 0) | |
2562 | { | |
2563 | if (! do_with_relocs (abfd, s)) | |
b34976b6 AM |
2564 | return FALSE; |
2565 | return TRUE; | |
252b5132 RH |
2566 | } |
2567 | } | |
2568 | if (! do_as_repeat (abfd, s)) | |
b34976b6 | 2569 | return FALSE; |
252b5132 RH |
2570 | } |
2571 | ||
b34976b6 | 2572 | return TRUE; |
252b5132 RH |
2573 | } |
2574 | ||
252b5132 | 2575 | static void |
c8e7bf0d | 2576 | fill (void) |
252b5132 | 2577 | { |
dc810e39 | 2578 | bfd_size_type amt = input_ptr_end - input_ptr_start; |
252b5132 RH |
2579 | /* FIXME: Check return value. I'm not sure whether it needs to read |
2580 | the entire buffer or not. */ | |
c8e7bf0d | 2581 | bfd_bread ((void *) input_ptr_start, amt, input_bfd); |
252b5132 RH |
2582 | input_ptr = input_ptr_start; |
2583 | } | |
47fda0d3 | 2584 | |
252b5132 | 2585 | static void |
c8e7bf0d | 2586 | flush (void) |
252b5132 | 2587 | { |
dc810e39 | 2588 | bfd_size_type amt = output_ptr - output_ptr_start; |
49ae03bf | 2589 | |
c8e7bf0d | 2590 | if (bfd_bwrite ((void *) (output_ptr_start), amt, output_bfd) != amt) |
252b5132 RH |
2591 | abort (); |
2592 | output_ptr = output_ptr_start; | |
2593 | output_buffer++; | |
2594 | } | |
2595 | ||
2596 | #define THIS() ( *input_ptr ) | |
c8e7bf0d NC |
2597 | #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); } |
2598 | #define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end) flush (); } | |
252b5132 RH |
2599 | |
2600 | static void | |
c8e7bf0d | 2601 | write_int (int value) |
252b5132 RH |
2602 | { |
2603 | if (value >= 0 && value <= 127) | |
2604 | { | |
2605 | OUT (value); | |
2606 | } | |
2607 | else | |
2608 | { | |
2609 | unsigned int length; | |
c8e7bf0d | 2610 | |
49ae03bf NC |
2611 | /* How many significant bytes ? */ |
2612 | /* FIXME FOR LONGER INTS. */ | |
252b5132 | 2613 | if (value & 0xff000000) |
49ae03bf | 2614 | length = 4; |
252b5132 | 2615 | else if (value & 0x00ff0000) |
49ae03bf | 2616 | length = 3; |
252b5132 | 2617 | else if (value & 0x0000ff00) |
49ae03bf | 2618 | length = 2; |
252b5132 RH |
2619 | else |
2620 | length = 1; | |
2621 | ||
2622 | OUT ((int) ieee_number_repeat_start_enum + length); | |
2623 | switch (length) | |
2624 | { | |
2625 | case 4: | |
2626 | OUT (value >> 24); | |
1a0670f3 | 2627 | /* Fall through. */ |
252b5132 RH |
2628 | case 3: |
2629 | OUT (value >> 16); | |
1a0670f3 | 2630 | /* Fall through. */ |
252b5132 RH |
2631 | case 2: |
2632 | OUT (value >> 8); | |
1a0670f3 | 2633 | /* Fall through. */ |
252b5132 RH |
2634 | case 1: |
2635 | OUT (value); | |
2636 | } | |
252b5132 RH |
2637 | } |
2638 | } | |
2639 | ||
2640 | static void | |
46e94266 | 2641 | copy_id (void) |
252b5132 RH |
2642 | { |
2643 | int length = THIS (); | |
2644 | char ch; | |
49ae03bf | 2645 | |
252b5132 RH |
2646 | OUT (length); |
2647 | NEXT (); | |
2648 | while (length--) | |
2649 | { | |
2650 | ch = THIS (); | |
2651 | OUT (ch); | |
2652 | NEXT (); | |
2653 | } | |
2654 | } | |
2655 | ||
2656 | #define VAR(x) ((x | 0x80)) | |
2657 | static void | |
46e94266 | 2658 | copy_expression (void) |
252b5132 RH |
2659 | { |
2660 | int stack[10]; | |
2661 | int *tos = stack; | |
dc810e39 | 2662 | int value; |
49ae03bf | 2663 | |
252b5132 RH |
2664 | while (1) |
2665 | { | |
2666 | switch (THIS ()) | |
2667 | { | |
2668 | case 0x84: | |
2669 | NEXT (); | |
2670 | value = THIS (); | |
2671 | NEXT (); | |
2672 | value = (value << 8) | THIS (); | |
2673 | NEXT (); | |
2674 | value = (value << 8) | THIS (); | |
2675 | NEXT (); | |
2676 | value = (value << 8) | THIS (); | |
2677 | NEXT (); | |
2678 | *tos++ = value; | |
2679 | break; | |
2680 | case 0x83: | |
2681 | NEXT (); | |
2682 | value = THIS (); | |
2683 | NEXT (); | |
2684 | value = (value << 8) | THIS (); | |
2685 | NEXT (); | |
2686 | value = (value << 8) | THIS (); | |
2687 | NEXT (); | |
2688 | *tos++ = value; | |
2689 | break; | |
2690 | case 0x82: | |
2691 | NEXT (); | |
2692 | value = THIS (); | |
2693 | NEXT (); | |
2694 | value = (value << 8) | THIS (); | |
2695 | NEXT (); | |
2696 | *tos++ = value; | |
2697 | break; | |
2698 | case 0x81: | |
2699 | NEXT (); | |
2700 | value = THIS (); | |
2701 | NEXT (); | |
2702 | *tos++ = value; | |
2703 | break; | |
2704 | case 0x80: | |
2705 | NEXT (); | |
2706 | *tos++ = 0; | |
2707 | break; | |
2708 | default: | |
2709 | if (THIS () > 0x84) | |
2710 | { | |
49ae03bf | 2711 | /* Not a number, just bug out with the answer. */ |
252b5132 RH |
2712 | write_int (*(--tos)); |
2713 | return; | |
2714 | } | |
2715 | *tos++ = THIS (); | |
2716 | NEXT (); | |
252b5132 RH |
2717 | break; |
2718 | case 0xa5: | |
49ae03bf | 2719 | /* PLUS anything. */ |
dc810e39 AM |
2720 | value = *(--tos); |
2721 | value += *(--tos); | |
2722 | *tos++ = value; | |
2723 | NEXT (); | |
252b5132 RH |
2724 | break; |
2725 | case VAR ('R'): | |
2726 | { | |
2727 | int section_number; | |
2728 | ieee_data_type *ieee; | |
2729 | asection *s; | |
49ae03bf | 2730 | |
252b5132 RH |
2731 | NEXT (); |
2732 | section_number = THIS (); | |
2733 | ||
2734 | NEXT (); | |
2735 | ieee = IEEE_DATA (input_bfd); | |
2736 | s = ieee->section_table[section_number]; | |
dc810e39 | 2737 | value = 0; |
252b5132 | 2738 | if (s->output_section) |
dc810e39 | 2739 | value = s->output_section->lma; |
252b5132 RH |
2740 | value += s->output_offset; |
2741 | *tos++ = value; | |
252b5132 RH |
2742 | } |
2743 | break; | |
2744 | case 0x90: | |
2745 | { | |
2746 | NEXT (); | |
2747 | write_int (*(--tos)); | |
2748 | OUT (0x90); | |
2749 | return; | |
252b5132 RH |
2750 | } |
2751 | } | |
2752 | } | |
252b5132 RH |
2753 | } |
2754 | ||
2755 | /* Drop the int in the buffer, and copy a null into the gap, which we | |
c8e7bf0d | 2756 | will overwrite later. */ |
252b5132 | 2757 | |
252b5132 | 2758 | static void |
46e94266 | 2759 | fill_int (struct output_buffer_struct *buf) |
252b5132 RH |
2760 | { |
2761 | if (buf->buffer == output_buffer) | |
2762 | { | |
49ae03bf | 2763 | /* Still a chance to output the size. */ |
252b5132 RH |
2764 | int value = output_ptr - buf->ptrp + 3; |
2765 | buf->ptrp[0] = value >> 24; | |
2766 | buf->ptrp[1] = value >> 16; | |
2767 | buf->ptrp[2] = value >> 8; | |
2768 | buf->ptrp[3] = value >> 0; | |
2769 | } | |
2770 | } | |
2771 | ||
2772 | static void | |
46e94266 | 2773 | drop_int (struct output_buffer_struct *buf) |
252b5132 RH |
2774 | { |
2775 | int type = THIS (); | |
2776 | int ch; | |
49ae03bf | 2777 | |
252b5132 RH |
2778 | if (type <= 0x84) |
2779 | { | |
2780 | NEXT (); | |
2781 | switch (type) | |
2782 | { | |
2783 | case 0x84: | |
2784 | ch = THIS (); | |
2785 | NEXT (); | |
1a0670f3 | 2786 | /* Fall through. */ |
252b5132 RH |
2787 | case 0x83: |
2788 | ch = THIS (); | |
2789 | NEXT (); | |
1a0670f3 | 2790 | /* Fall through. */ |
252b5132 RH |
2791 | case 0x82: |
2792 | ch = THIS (); | |
2793 | NEXT (); | |
1a0670f3 | 2794 | /* Fall through. */ |
252b5132 RH |
2795 | case 0x81: |
2796 | ch = THIS (); | |
2797 | NEXT (); | |
1a0670f3 | 2798 | /* Fall through. */ |
252b5132 RH |
2799 | case 0x80: |
2800 | break; | |
2801 | } | |
2802 | } | |
c7e2358a | 2803 | (void) ch; |
252b5132 RH |
2804 | OUT (0x84); |
2805 | buf->ptrp = output_ptr; | |
2806 | buf->buffer = output_buffer; | |
2807 | OUT (0); | |
2808 | OUT (0); | |
2809 | OUT (0); | |
2810 | OUT (0); | |
2811 | } | |
2812 | ||
2813 | static void | |
46e94266 | 2814 | copy_int (void) |
252b5132 RH |
2815 | { |
2816 | int type = THIS (); | |
2817 | int ch; | |
2818 | if (type <= 0x84) | |
2819 | { | |
2820 | OUT (type); | |
2821 | NEXT (); | |
2822 | switch (type) | |
2823 | { | |
2824 | case 0x84: | |
2825 | ch = THIS (); | |
2826 | NEXT (); | |
2827 | OUT (ch); | |
1a0670f3 | 2828 | /* Fall through. */ |
252b5132 RH |
2829 | case 0x83: |
2830 | ch = THIS (); | |
2831 | NEXT (); | |
2832 | OUT (ch); | |
1a0670f3 | 2833 | /* Fall through. */ |
252b5132 RH |
2834 | case 0x82: |
2835 | ch = THIS (); | |
2836 | NEXT (); | |
2837 | OUT (ch); | |
1a0670f3 | 2838 | /* Fall through. */ |
252b5132 RH |
2839 | case 0x81: |
2840 | ch = THIS (); | |
2841 | NEXT (); | |
2842 | OUT (ch); | |
1a0670f3 | 2843 | /* Fall through. */ |
252b5132 RH |
2844 | case 0x80: |
2845 | break; | |
2846 | } | |
2847 | } | |
2848 | } | |
2849 | ||
46e94266 NC |
2850 | #define ID copy_id () |
2851 | #define INT copy_int () | |
2852 | #define EXP copy_expression () | |
2853 | #define INTn(q) copy_int () | |
2854 | #define EXPn(q) copy_expression () | |
252b5132 RH |
2855 | |
2856 | static void | |
46e94266 NC |
2857 | copy_till_end (void) |
2858 | { | |
2859 | int ch = THIS (); | |
2860 | ||
2861 | while (1) | |
2862 | { | |
2863 | while (ch <= 0x80) | |
2864 | { | |
2865 | OUT (ch); | |
2866 | NEXT (); | |
2867 | ch = THIS (); | |
2868 | } | |
2869 | switch (ch) | |
2870 | { | |
2871 | case 0x84: | |
2872 | OUT (THIS ()); | |
2873 | NEXT (); | |
1a0670f3 | 2874 | /* Fall through. */ |
46e94266 NC |
2875 | case 0x83: |
2876 | OUT (THIS ()); | |
2877 | NEXT (); | |
1a0670f3 | 2878 | /* Fall through. */ |
46e94266 NC |
2879 | case 0x82: |
2880 | OUT (THIS ()); | |
2881 | NEXT (); | |
1a0670f3 | 2882 | /* Fall through. */ |
46e94266 NC |
2883 | case 0x81: |
2884 | OUT (THIS ()); | |
2885 | NEXT (); | |
2886 | OUT (THIS ()); | |
2887 | NEXT (); | |
2888 | ||
2889 | ch = THIS (); | |
2890 | break; | |
2891 | default: | |
2892 | return; | |
2893 | } | |
2894 | } | |
2895 | ||
2896 | } | |
2897 | ||
2898 | static void | |
2899 | f1_record (void) | |
252b5132 RH |
2900 | { |
2901 | int ch; | |
49ae03bf NC |
2902 | |
2903 | /* ATN record. */ | |
252b5132 RH |
2904 | NEXT (); |
2905 | ch = THIS (); | |
2906 | switch (ch) | |
2907 | { | |
2908 | default: | |
2909 | OUT (0xf1); | |
2910 | OUT (ch); | |
2911 | break; | |
2912 | case 0xc9: | |
2913 | NEXT (); | |
2914 | OUT (0xf1); | |
2915 | OUT (0xc9); | |
2916 | INT; | |
2917 | INT; | |
2918 | ch = THIS (); | |
2919 | switch (ch) | |
2920 | { | |
2921 | case 0x16: | |
2922 | NEXT (); | |
2923 | break; | |
2924 | case 0x01: | |
2925 | NEXT (); | |
2926 | break; | |
2927 | case 0x00: | |
2928 | NEXT (); | |
2929 | INT; | |
2930 | break; | |
2931 | case 0x03: | |
2932 | NEXT (); | |
2933 | INT; | |
2934 | break; | |
2935 | case 0x13: | |
2936 | EXPn (instruction address); | |
2937 | break; | |
2938 | default: | |
2939 | break; | |
2940 | } | |
2941 | break; | |
2942 | case 0xd8: | |
49ae03bf | 2943 | /* EXternal ref. */ |
252b5132 RH |
2944 | NEXT (); |
2945 | OUT (0xf1); | |
2946 | OUT (0xd8); | |
2947 | EXP; | |
2948 | EXP; | |
2949 | EXP; | |
2950 | EXP; | |
2951 | break; | |
2952 | case 0xce: | |
2953 | NEXT (); | |
2954 | OUT (0xf1); | |
2955 | OUT (0xce); | |
2956 | INT; | |
2957 | INT; | |
2958 | ch = THIS (); | |
2959 | INT; | |
2960 | switch (ch) | |
2961 | { | |
2962 | case 0x01: | |
2963 | INT; | |
2964 | INT; | |
2965 | break; | |
2966 | case 0x02: | |
2967 | INT; | |
2968 | break; | |
2969 | case 0x04: | |
2970 | EXPn (external function); | |
2971 | break; | |
2972 | case 0x05: | |
2973 | break; | |
2974 | case 0x07: | |
2975 | INTn (line number); | |
2976 | INT; | |
2977 | case 0x08: | |
2978 | break; | |
2979 | case 0x0a: | |
2980 | INTn (locked register); | |
2981 | INT; | |
2982 | break; | |
2983 | case 0x3f: | |
2984 | copy_till_end (); | |
2985 | break; | |
2986 | case 0x3e: | |
2987 | copy_till_end (); | |
2988 | break; | |
2989 | case 0x40: | |
2990 | copy_till_end (); | |
2991 | break; | |
2992 | case 0x41: | |
2993 | ID; | |
2994 | break; | |
2995 | } | |
2996 | } | |
252b5132 RH |
2997 | } |
2998 | ||
2999 | static void | |
46e94266 | 3000 | f0_record (void) |
252b5132 | 3001 | { |
49ae03bf | 3002 | /* Attribute record. */ |
252b5132 RH |
3003 | NEXT (); |
3004 | OUT (0xf0); | |
3005 | INTn (Symbol name); | |
3006 | ID; | |
3007 | } | |
3008 | ||
3009 | static void | |
46e94266 | 3010 | f2_record (void) |
252b5132 RH |
3011 | { |
3012 | NEXT (); | |
3013 | OUT (0xf2); | |
3014 | INT; | |
3015 | NEXT (); | |
3016 | OUT (0xce); | |
3017 | INT; | |
3018 | copy_till_end (); | |
3019 | } | |
3020 | ||
252b5132 | 3021 | static void |
46e94266 | 3022 | f8_record (void) |
252b5132 RH |
3023 | { |
3024 | int ch; | |
3025 | NEXT (); | |
3026 | ch = THIS (); | |
3027 | switch (ch) | |
3028 | { | |
3029 | case 0x01: | |
3030 | case 0x02: | |
3031 | case 0x03: | |
49ae03bf NC |
3032 | /* Unique typedefs for module. */ |
3033 | /* GLobal typedefs. */ | |
3034 | /* High level module scope beginning. */ | |
252b5132 RH |
3035 | { |
3036 | struct output_buffer_struct ob; | |
49ae03bf | 3037 | |
252b5132 RH |
3038 | NEXT (); |
3039 | OUT (0xf8); | |
3040 | OUT (ch); | |
3041 | drop_int (&ob); | |
3042 | ID; | |
3043 | ||
3044 | block (); | |
3045 | ||
3046 | NEXT (); | |
3047 | fill_int (&ob); | |
3048 | OUT (0xf9); | |
3049 | } | |
3050 | break; | |
3051 | case 0x04: | |
49ae03bf | 3052 | /* Global function. */ |
252b5132 RH |
3053 | { |
3054 | struct output_buffer_struct ob; | |
49ae03bf | 3055 | |
252b5132 RH |
3056 | NEXT (); |
3057 | OUT (0xf8); | |
3058 | OUT (0x04); | |
3059 | drop_int (&ob); | |
3060 | ID; | |
3061 | INTn (stack size); | |
3062 | INTn (ret val); | |
3063 | EXPn (offset); | |
3064 | ||
3065 | block (); | |
3066 | ||
3067 | NEXT (); | |
3068 | OUT (0xf9); | |
3069 | EXPn (size of block); | |
3070 | fill_int (&ob); | |
3071 | } | |
3072 | break; | |
3073 | ||
3074 | case 0x05: | |
49ae03bf | 3075 | /* File name for source line numbers. */ |
252b5132 RH |
3076 | { |
3077 | struct output_buffer_struct ob; | |
49ae03bf | 3078 | |
252b5132 RH |
3079 | NEXT (); |
3080 | OUT (0xf8); | |
3081 | OUT (0x05); | |
3082 | drop_int (&ob); | |
3083 | ID; | |
3084 | INTn (year); | |
3085 | INTn (month); | |
3086 | INTn (day); | |
3087 | INTn (hour); | |
3088 | INTn (monute); | |
3089 | INTn (second); | |
3090 | block (); | |
3091 | NEXT (); | |
3092 | OUT (0xf9); | |
3093 | fill_int (&ob); | |
3094 | } | |
3095 | break; | |
3096 | ||
3097 | case 0x06: | |
49ae03bf | 3098 | /* Local function. */ |
252b5132 RH |
3099 | { |
3100 | struct output_buffer_struct ob; | |
49ae03bf | 3101 | |
252b5132 RH |
3102 | NEXT (); |
3103 | OUT (0xf8); | |
3104 | OUT (0x06); | |
3105 | drop_int (&ob); | |
3106 | ID; | |
3107 | INTn (stack size); | |
3108 | INTn (type return); | |
3109 | EXPn (offset); | |
3110 | block (); | |
3111 | NEXT (); | |
3112 | OUT (0xf9); | |
3113 | EXPn (size); | |
3114 | fill_int (&ob); | |
3115 | } | |
3116 | break; | |
3117 | ||
3118 | case 0x0a: | |
49ae03bf | 3119 | /* Assembler module scope beginning - */ |
252b5132 RH |
3120 | { |
3121 | struct output_buffer_struct ob; | |
3122 | ||
3123 | NEXT (); | |
3124 | OUT (0xf8); | |
3125 | OUT (0x0a); | |
3126 | drop_int (&ob); | |
3127 | ID; | |
3128 | ID; | |
3129 | INT; | |
3130 | ID; | |
3131 | INT; | |
3132 | INT; | |
3133 | INT; | |
3134 | INT; | |
3135 | INT; | |
3136 | INT; | |
3137 | ||
3138 | block (); | |
3139 | ||
3140 | NEXT (); | |
3141 | OUT (0xf9); | |
3142 | fill_int (&ob); | |
3143 | } | |
3144 | break; | |
3145 | case 0x0b: | |
3146 | { | |
3147 | struct output_buffer_struct ob; | |
49ae03bf | 3148 | |
252b5132 RH |
3149 | NEXT (); |
3150 | OUT (0xf8); | |
3151 | OUT (0x0b); | |
3152 | drop_int (&ob); | |
3153 | ID; | |
3154 | INT; | |
3155 | INTn (section index); | |
3156 | EXPn (offset); | |
3157 | INTn (stuff); | |
3158 | ||
3159 | block (); | |
3160 | ||
3161 | OUT (0xf9); | |
3162 | NEXT (); | |
3163 | EXPn (Size in Maus); | |
3164 | fill_int (&ob); | |
3165 | } | |
3166 | break; | |
3167 | } | |
3168 | } | |
3169 | ||
3170 | static void | |
46e94266 | 3171 | e2_record (void) |
252b5132 RH |
3172 | { |
3173 | OUT (0xe2); | |
3174 | NEXT (); | |
3175 | OUT (0xce); | |
3176 | NEXT (); | |
3177 | INT; | |
3178 | EXP; | |
3179 | } | |
3180 | ||
3181 | static void | |
46e94266 | 3182 | block (void) |
252b5132 RH |
3183 | { |
3184 | int ch; | |
49ae03bf | 3185 | |
252b5132 RH |
3186 | while (1) |
3187 | { | |
3188 | ch = THIS (); | |
3189 | switch (ch) | |
3190 | { | |
3191 | case 0xe1: | |
3192 | case 0xe5: | |
3193 | return; | |
3194 | case 0xf9: | |
3195 | return; | |
3196 | case 0xf0: | |
3197 | f0_record (); | |
3198 | break; | |
3199 | case 0xf1: | |
3200 | f1_record (); | |
3201 | break; | |
3202 | case 0xf2: | |
3203 | f2_record (); | |
3204 | break; | |
3205 | case 0xf8: | |
3206 | f8_record (); | |
3207 | break; | |
3208 | case 0xe2: | |
3209 | e2_record (); | |
3210 | break; | |
3211 | ||
3212 | } | |
3213 | } | |
3214 | } | |
3215 | ||
49ae03bf NC |
3216 | /* Moves all the debug information from the source bfd to the output |
3217 | bfd, and relocates any expressions it finds. */ | |
252b5132 RH |
3218 | |
3219 | static void | |
46e94266 NC |
3220 | relocate_debug (bfd *output ATTRIBUTE_UNUSED, |
3221 | bfd *input) | |
252b5132 RH |
3222 | { |
3223 | #define IBS 400 | |
3224 | #define OBS 400 | |
3225 | unsigned char input_buffer[IBS]; | |
3226 | ||
3227 | input_ptr_start = input_ptr = input_buffer; | |
3228 | input_ptr_end = input_buffer + IBS; | |
3229 | input_bfd = input; | |
3230 | /* FIXME: Check return value. I'm not sure whether it needs to read | |
3231 | the entire buffer or not. */ | |
c8e7bf0d | 3232 | bfd_bread ((void *) input_ptr_start, (bfd_size_type) IBS, input); |
252b5132 RH |
3233 | block (); |
3234 | } | |
3235 | ||
dce61835 KH |
3236 | /* Gather together all the debug information from each input BFD into |
3237 | one place, relocating it and emitting it as we go. */ | |
252b5132 | 3238 | |
b34976b6 | 3239 | static bfd_boolean |
46e94266 | 3240 | ieee_write_debug_part (bfd *abfd) |
252b5132 RH |
3241 | { |
3242 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
3243 | bfd_chain_type *chain = ieee->chain_root; | |
dc810e39 | 3244 | unsigned char obuff[OBS]; |
b34976b6 | 3245 | bfd_boolean some_debug = FALSE; |
252b5132 RH |
3246 | file_ptr here = bfd_tell (abfd); |
3247 | ||
dc810e39 AM |
3248 | output_ptr_start = output_ptr = obuff; |
3249 | output_ptr_end = obuff + OBS; | |
3250 | output_ptr = obuff; | |
252b5132 RH |
3251 | output_bfd = abfd; |
3252 | ||
3253 | if (chain == (bfd_chain_type *) NULL) | |
3254 | { | |
3255 | asection *s; | |
3256 | ||
3257 | for (s = abfd->sections; s != NULL; s = s->next) | |
3258 | if ((s->flags & SEC_DEBUGGING) != 0) | |
3259 | break; | |
3260 | if (s == NULL) | |
3261 | { | |
3262 | ieee->w.r.debug_information_part = 0; | |
b34976b6 | 3263 | return TRUE; |
252b5132 RH |
3264 | } |
3265 | ||
3266 | ieee->w.r.debug_information_part = here; | |
eea6121a | 3267 | if (bfd_bwrite (s->contents, s->size, abfd) != s->size) |
b34976b6 | 3268 | return FALSE; |
252b5132 RH |
3269 | } |
3270 | else | |
3271 | { | |
3272 | while (chain != (bfd_chain_type *) NULL) | |
3273 | { | |
3274 | bfd *entry = chain->this; | |
3275 | ieee_data_type *entry_ieee = IEEE_DATA (entry); | |
49ae03bf | 3276 | |
252b5132 RH |
3277 | if (entry_ieee->w.r.debug_information_part) |
3278 | { | |
3279 | if (bfd_seek (entry, entry_ieee->w.r.debug_information_part, | |
dc810e39 | 3280 | SEEK_SET) != 0) |
b34976b6 | 3281 | return FALSE; |
252b5132 RH |
3282 | relocate_debug (abfd, entry); |
3283 | } | |
3284 | ||
3285 | chain = chain->next; | |
3286 | } | |
49ae03bf | 3287 | |
252b5132 | 3288 | if (some_debug) |
49ae03bf | 3289 | ieee->w.r.debug_information_part = here; |
252b5132 | 3290 | else |
49ae03bf | 3291 | ieee->w.r.debug_information_part = 0; |
252b5132 RH |
3292 | |
3293 | flush (); | |
3294 | } | |
3295 | ||
b34976b6 | 3296 | return TRUE; |
252b5132 RH |
3297 | } |
3298 | ||
3299 | /* Write the data in an ieee way. */ | |
3300 | ||
b34976b6 | 3301 | static bfd_boolean |
46e94266 | 3302 | ieee_write_data_part (bfd *abfd) |
252b5132 RH |
3303 | { |
3304 | asection *s; | |
49ae03bf | 3305 | |
252b5132 RH |
3306 | ieee_data_type *ieee = IEEE_DATA (abfd); |
3307 | ieee->w.r.data_part = bfd_tell (abfd); | |
49ae03bf | 3308 | |
252b5132 RH |
3309 | for (s = abfd->sections; s != (asection *) NULL; s = s->next) |
3310 | { | |
3311 | /* Skip sections that have no loadable contents (.bss, | |
07d6d2b8 | 3312 | debugging, etc.) */ |
252b5132 RH |
3313 | if ((s->flags & SEC_LOAD) == 0) |
3314 | continue; | |
3315 | ||
3316 | /* Sort the reloc records so we can insert them in the correct | |
c8e7bf0d | 3317 | places. */ |
252b5132 RH |
3318 | if (s->reloc_count != 0) |
3319 | { | |
3320 | if (! do_with_relocs (abfd, s)) | |
b34976b6 | 3321 | return FALSE; |
252b5132 RH |
3322 | } |
3323 | else | |
3324 | { | |
3325 | if (! do_without_relocs (abfd, s)) | |
b34976b6 | 3326 | return FALSE; |
252b5132 RH |
3327 | } |
3328 | } | |
3329 | ||
b34976b6 | 3330 | return TRUE; |
252b5132 RH |
3331 | } |
3332 | ||
b34976b6 | 3333 | static bfd_boolean |
46e94266 | 3334 | init_for_output (bfd *abfd) |
252b5132 RH |
3335 | { |
3336 | asection *s; | |
49ae03bf | 3337 | |
252b5132 RH |
3338 | for (s = abfd->sections; s != (asection *) NULL; s = s->next) |
3339 | { | |
3340 | if ((s->flags & SEC_DEBUGGING) != 0) | |
3341 | continue; | |
eea6121a | 3342 | if (s->size != 0) |
252b5132 | 3343 | { |
eea6121a | 3344 | bfd_size_type size = s->size; |
c8e7bf0d | 3345 | ieee_per_section (s)->data = bfd_alloc (abfd, size); |
252b5132 | 3346 | if (!ieee_per_section (s)->data) |
b34976b6 | 3347 | return FALSE; |
252b5132 RH |
3348 | } |
3349 | } | |
b34976b6 | 3350 | return TRUE; |
252b5132 RH |
3351 | } |
3352 | \f | |
49ae03bf NC |
3353 | /* Exec and core file sections. */ |
3354 | ||
3355 | /* Set section contents is complicated with IEEE since the format is | |
3356 | not a byte image, but a record stream. */ | |
252b5132 | 3357 | |
b34976b6 | 3358 | static bfd_boolean |
46e94266 NC |
3359 | ieee_set_section_contents (bfd *abfd, |
3360 | sec_ptr section, | |
3361 | const void * location, | |
3362 | file_ptr offset, | |
3363 | bfd_size_type count) | |
252b5132 RH |
3364 | { |
3365 | if ((section->flags & SEC_DEBUGGING) != 0) | |
3366 | { | |
3367 | if (section->contents == NULL) | |
3368 | { | |
eea6121a | 3369 | bfd_size_type size = section->size; |
c8e7bf0d | 3370 | section->contents = bfd_alloc (abfd, size); |
252b5132 | 3371 | if (section->contents == NULL) |
b34976b6 | 3372 | return FALSE; |
252b5132 RH |
3373 | } |
3374 | /* bfd_set_section_contents has already checked that everything | |
07d6d2b8 | 3375 | is within range. */ |
dc810e39 | 3376 | memcpy (section->contents + offset, location, (size_t) count); |
b34976b6 | 3377 | return TRUE; |
252b5132 RH |
3378 | } |
3379 | ||
3380 | if (ieee_per_section (section)->data == (bfd_byte *) NULL) | |
3381 | { | |
3382 | if (!init_for_output (abfd)) | |
b34976b6 | 3383 | return FALSE; |
252b5132 | 3384 | } |
c8e7bf0d NC |
3385 | memcpy ((void *) (ieee_per_section (section)->data + offset), |
3386 | (void *) location, | |
252b5132 | 3387 | (unsigned int) count); |
b34976b6 | 3388 | return TRUE; |
252b5132 RH |
3389 | } |
3390 | ||
3391 | /* Write the external symbols of a file. IEEE considers two sorts of | |
3392 | external symbols, public, and referenced. It uses to internal | |
3393 | forms to index them as well. When we write them out we turn their | |
3394 | symbol values into indexes from the right base. */ | |
3395 | ||
b34976b6 | 3396 | static bfd_boolean |
46e94266 | 3397 | ieee_write_external_part (bfd *abfd) |
252b5132 RH |
3398 | { |
3399 | asymbol **q; | |
3400 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
252b5132 RH |
3401 | unsigned int reference_index = IEEE_REFERENCE_BASE; |
3402 | unsigned int public_index = IEEE_PUBLIC_BASE + 2; | |
3403 | file_ptr here = bfd_tell (abfd); | |
b34976b6 | 3404 | bfd_boolean hadone = FALSE; |
49ae03bf | 3405 | |
252b5132 RH |
3406 | if (abfd->outsymbols != (asymbol **) NULL) |
3407 | { | |
3408 | ||
3409 | for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++) | |
3410 | { | |
3411 | asymbol *p = *q; | |
49ae03bf | 3412 | |
252b5132 RH |
3413 | if (bfd_is_und_section (p->section)) |
3414 | { | |
49ae03bf | 3415 | /* This must be a symbol reference. */ |
252b5132 | 3416 | if (! ieee_write_byte (abfd, ieee_external_reference_enum) |
dc810e39 | 3417 | || ! ieee_write_int (abfd, (bfd_vma) reference_index) |
252b5132 | 3418 | || ! ieee_write_id (abfd, p->name)) |
b34976b6 | 3419 | return FALSE; |
252b5132 RH |
3420 | p->value = reference_index; |
3421 | reference_index++; | |
b34976b6 | 3422 | hadone = TRUE; |
252b5132 RH |
3423 | } |
3424 | else if (bfd_is_com_section (p->section)) | |
3425 | { | |
49ae03bf | 3426 | /* This is a weak reference. */ |
252b5132 | 3427 | if (! ieee_write_byte (abfd, ieee_external_reference_enum) |
dc810e39 | 3428 | || ! ieee_write_int (abfd, (bfd_vma) reference_index) |
252b5132 RH |
3429 | || ! ieee_write_id (abfd, p->name) |
3430 | || ! ieee_write_byte (abfd, | |
3431 | ieee_weak_external_reference_enum) | |
dc810e39 | 3432 | || ! ieee_write_int (abfd, (bfd_vma) reference_index) |
252b5132 | 3433 | || ! ieee_write_int (abfd, p->value)) |
b34976b6 | 3434 | return FALSE; |
252b5132 RH |
3435 | p->value = reference_index; |
3436 | reference_index++; | |
b34976b6 | 3437 | hadone = TRUE; |
252b5132 RH |
3438 | } |
3439 | else if (p->flags & BSF_GLOBAL) | |
3440 | { | |
49ae03bf | 3441 | /* This must be a symbol definition. */ |
252b5132 | 3442 | if (! ieee_write_byte (abfd, ieee_external_symbol_enum) |
dc810e39 | 3443 | || ! ieee_write_int (abfd, (bfd_vma) public_index) |
252b5132 RH |
3444 | || ! ieee_write_id (abfd, p->name) |
3445 | || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum) | |
dc810e39 | 3446 | || ! ieee_write_int (abfd, (bfd_vma) public_index) |
c8e7bf0d NC |
3447 | || ! ieee_write_byte (abfd, 15) /* Instruction address. */ |
3448 | || ! ieee_write_byte (abfd, 19) /* Static symbol. */ | |
3449 | || ! ieee_write_byte (abfd, 1)) /* One of them. */ | |
b34976b6 | 3450 | return FALSE; |
252b5132 | 3451 | |
49ae03bf | 3452 | /* Write out the value. */ |
252b5132 | 3453 | if (! ieee_write_2bytes (abfd, ieee_value_record_enum) |
dc810e39 | 3454 | || ! ieee_write_int (abfd, (bfd_vma) public_index)) |
b34976b6 | 3455 | return FALSE; |
252b5132 RH |
3456 | if (! bfd_is_abs_section (p->section)) |
3457 | { | |
3458 | if (abfd->flags & EXEC_P) | |
3459 | { | |
3460 | /* If fully linked, then output all symbols | |
49ae03bf | 3461 | relocated. */ |
252b5132 RH |
3462 | if (! (ieee_write_int |
3463 | (abfd, | |
3464 | (p->value | |
3465 | + p->section->output_offset | |
3466 | + p->section->output_section->vma)))) | |
b34976b6 | 3467 | return FALSE; |
252b5132 RH |
3468 | } |
3469 | else | |
3470 | { | |
3471 | if (! (ieee_write_expression | |
3472 | (abfd, | |
3473 | p->value + p->section->output_offset, | |
3474 | p->section->output_section->symbol, | |
b34976b6 AM |
3475 | FALSE, 0))) |
3476 | return FALSE; | |
252b5132 RH |
3477 | } |
3478 | } | |
3479 | else | |
3480 | { | |
3481 | if (! ieee_write_expression (abfd, | |
3482 | p->value, | |
3483 | bfd_abs_section_ptr->symbol, | |
b34976b6 AM |
3484 | FALSE, 0)) |
3485 | return FALSE; | |
252b5132 RH |
3486 | } |
3487 | p->value = public_index; | |
3488 | public_index++; | |
b34976b6 | 3489 | hadone = TRUE; |
252b5132 RH |
3490 | } |
3491 | else | |
3492 | { | |
49ae03bf | 3493 | /* This can happen - when there are gaps in the symbols read |
07d6d2b8 | 3494 | from an input ieee file. */ |
252b5132 RH |
3495 | } |
3496 | } | |
3497 | } | |
3498 | if (hadone) | |
3499 | ieee->w.r.external_part = here; | |
3500 | ||
b34976b6 | 3501 | return TRUE; |
252b5132 RH |
3502 | } |
3503 | ||
3504 | ||
47fda0d3 | 3505 | static const unsigned char exten[] = |
252b5132 RH |
3506 | { |
3507 | 0xf0, 0x20, 0x00, | |
49ae03bf NC |
3508 | 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */ |
3509 | 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */ | |
1049f94e | 3510 | 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */ |
252b5132 RH |
3511 | }; |
3512 | ||
47fda0d3 | 3513 | static const unsigned char envi[] = |
252b5132 RH |
3514 | { |
3515 | 0xf0, 0x21, 0x00, | |
3516 | ||
3517 | /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11, | |
3518 | 0x19, 0x2c, | |
3519 | */ | |
c8e7bf0d | 3520 | 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */ |
252b5132 | 3521 | |
c8e7bf0d | 3522 | 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */ |
252b5132 RH |
3523 | /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */ |
3524 | }; | |
3525 | ||
b34976b6 | 3526 | static bfd_boolean |
46e94266 | 3527 | ieee_write_me_part (bfd *abfd) |
252b5132 RH |
3528 | { |
3529 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
3530 | ieee->w.r.trailer_part = bfd_tell (abfd); | |
3531 | if (abfd->start_address) | |
3532 | { | |
3533 | if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum) | |
3534 | || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum) | |
3535 | || ! ieee_write_int (abfd, abfd->start_address) | |
3536 | || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum)) | |
b34976b6 | 3537 | return FALSE; |
252b5132 RH |
3538 | } |
3539 | ieee->w.r.me_record = bfd_tell (abfd); | |
3540 | if (! ieee_write_byte (abfd, ieee_module_end_enum)) | |
b34976b6 AM |
3541 | return FALSE; |
3542 | return TRUE; | |
252b5132 RH |
3543 | } |
3544 | ||
3545 | /* Write out the IEEE processor ID. */ | |
3546 | ||
b34976b6 | 3547 | static bfd_boolean |
46e94266 | 3548 | ieee_write_processor (bfd *abfd) |
252b5132 RH |
3549 | { |
3550 | const bfd_arch_info_type *arch; | |
3551 | ||
3552 | arch = bfd_get_arch_info (abfd); | |
3553 | switch (arch->arch) | |
3554 | { | |
3555 | default: | |
3556 | if (! ieee_write_id (abfd, bfd_printable_name (abfd))) | |
b34976b6 | 3557 | return FALSE; |
252b5132 RH |
3558 | break; |
3559 | ||
252b5132 RH |
3560 | case bfd_arch_h8300: |
3561 | if (! ieee_write_id (abfd, "H8/300")) | |
b34976b6 | 3562 | return FALSE; |
252b5132 RH |
3563 | break; |
3564 | ||
3565 | case bfd_arch_h8500: | |
3566 | if (! ieee_write_id (abfd, "H8/500")) | |
b34976b6 | 3567 | return FALSE; |
252b5132 RH |
3568 | break; |
3569 | ||
252b5132 RH |
3570 | case bfd_arch_m68k: |
3571 | { | |
3572 | const char *id; | |
3573 | ||
3574 | switch (arch->mach) | |
3575 | { | |
3576 | default: id = "68020"; break; | |
3577 | case bfd_mach_m68000: id = "68000"; break; | |
3578 | case bfd_mach_m68008: id = "68008"; break; | |
3579 | case bfd_mach_m68010: id = "68010"; break; | |
3580 | case bfd_mach_m68020: id = "68020"; break; | |
3581 | case bfd_mach_m68030: id = "68030"; break; | |
3582 | case bfd_mach_m68040: id = "68040"; break; | |
3583 | case bfd_mach_m68060: id = "68060"; break; | |
3584 | case bfd_mach_cpu32: id = "cpu32"; break; | |
0b2e31dc | 3585 | case bfd_mach_mcf_isa_a_nodiv: id = "isa-a:nodiv"; break; |
266abb8f | 3586 | case bfd_mach_mcf_isa_a: id = "isa-a"; break; |
0b2e31dc NS |
3587 | case bfd_mach_mcf_isa_a_mac: id = "isa-a:mac"; break; |
3588 | case bfd_mach_mcf_isa_a_emac: id = "isa-a:emac"; break; | |
3589 | case bfd_mach_mcf_isa_aplus: id = "isa-aplus"; break; | |
3590 | case bfd_mach_mcf_isa_aplus_mac: id = "isa-aplus:mac"; break; | |
3591 | case bfd_mach_mcf_isa_aplus_emac: id = "isa-aplus:mac"; break; | |
3592 | case bfd_mach_mcf_isa_b_nousp: id = "isa-b:nousp"; break; | |
3593 | case bfd_mach_mcf_isa_b_nousp_mac: id = "isa-b:nousp:mac"; break; | |
3594 | case bfd_mach_mcf_isa_b_nousp_emac: id = "isa-b:nousp:emac"; break; | |
266abb8f NS |
3595 | case bfd_mach_mcf_isa_b: id = "isa-b"; break; |
3596 | case bfd_mach_mcf_isa_b_mac: id = "isa-b:mac"; break; | |
3597 | case bfd_mach_mcf_isa_b_emac: id = "isa-b:emac"; break; | |
0b2e31dc NS |
3598 | case bfd_mach_mcf_isa_b_float: id = "isa-b:float"; break; |
3599 | case bfd_mach_mcf_isa_b_float_mac: id = "isa-b:float:mac"; break; | |
3600 | case bfd_mach_mcf_isa_b_float_emac: id = "isa-b:float:emac"; break; | |
8d100c32 KH |
3601 | case bfd_mach_mcf_isa_c: id = "isa-c"; break; |
3602 | case bfd_mach_mcf_isa_c_mac: id = "isa-c:mac"; break; | |
3603 | case bfd_mach_mcf_isa_c_emac: id = "isa-c:emac"; break; | |
3604 | case bfd_mach_mcf_isa_c_nodiv: id = "isa-c:nodiv"; break; | |
3605 | case bfd_mach_mcf_isa_c_nodiv_mac: id = "isa-c:nodiv:mac"; break; | |
3606 | case bfd_mach_mcf_isa_c_nodiv_emac: id = "isa-c:nodiv:emac"; break; | |
252b5132 RH |
3607 | } |
3608 | ||
3609 | if (! ieee_write_id (abfd, id)) | |
b34976b6 | 3610 | return FALSE; |
252b5132 RH |
3611 | } |
3612 | break; | |
3613 | } | |
3614 | ||
b34976b6 | 3615 | return TRUE; |
252b5132 RH |
3616 | } |
3617 | ||
b34976b6 | 3618 | static bfd_boolean |
46e94266 | 3619 | ieee_write_object_contents (bfd *abfd) |
252b5132 RH |
3620 | { |
3621 | ieee_data_type *ieee = IEEE_DATA (abfd); | |
3622 | unsigned int i; | |
3623 | file_ptr old; | |
3624 | ||
49ae03bf | 3625 | /* Fast forward over the header area. */ |
252b5132 | 3626 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) |
b34976b6 | 3627 | return FALSE; |
252b5132 RH |
3628 | |
3629 | if (! ieee_write_byte (abfd, ieee_module_beginning_enum) | |
3630 | || ! ieee_write_processor (abfd) | |
3631 | || ! ieee_write_id (abfd, abfd->filename)) | |
b34976b6 | 3632 | return FALSE; |
252b5132 | 3633 | |
49ae03bf | 3634 | /* Fast forward over the variable bits. */ |
252b5132 | 3635 | if (! ieee_write_byte (abfd, ieee_address_descriptor_enum)) |
b34976b6 | 3636 | return FALSE; |
252b5132 | 3637 | |
49ae03bf | 3638 | /* Bits per MAU. */ |
252b5132 | 3639 | if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd)))) |
b34976b6 | 3640 | return FALSE; |
49ae03bf | 3641 | /* MAU's per address. */ |
252b5132 RH |
3642 | if (! ieee_write_byte (abfd, |
3643 | (bfd_byte) (bfd_arch_bits_per_address (abfd) | |
3644 | / bfd_arch_bits_per_byte (abfd)))) | |
b34976b6 | 3645 | return FALSE; |
252b5132 RH |
3646 | |
3647 | old = bfd_tell (abfd); | |
3648 | if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0) | |
b34976b6 | 3649 | return FALSE; |
252b5132 RH |
3650 | |
3651 | ieee->w.r.extension_record = bfd_tell (abfd); | |
dc810e39 AM |
3652 | if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd) |
3653 | != sizeof (exten)) | |
b34976b6 | 3654 | return FALSE; |
252b5132 RH |
3655 | if (abfd->flags & EXEC_P) |
3656 | { | |
c8e7bf0d | 3657 | if (! ieee_write_byte (abfd, 0x1)) /* Absolute. */ |
b34976b6 | 3658 | return FALSE; |
252b5132 RH |
3659 | } |
3660 | else | |
3661 | { | |
c8e7bf0d | 3662 | if (! ieee_write_byte (abfd, 0x2)) /* Relocateable. */ |
b34976b6 | 3663 | return FALSE; |
252b5132 RH |
3664 | } |
3665 | ||
3666 | ieee->w.r.environmental_record = bfd_tell (abfd); | |
dc810e39 AM |
3667 | if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd) |
3668 | != sizeof (envi)) | |
b34976b6 | 3669 | return FALSE; |
252b5132 RH |
3670 | |
3671 | /* The HP emulator database requires a timestamp in the file. */ | |
3672 | { | |
3673 | time_t now; | |
3674 | const struct tm *t; | |
3675 | ||
3676 | time (&now); | |
3677 | t = (struct tm *) localtime (&now); | |
3678 | if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum) | |
3679 | || ! ieee_write_byte (abfd, 0x21) | |
3680 | || ! ieee_write_byte (abfd, 0) | |
3681 | || ! ieee_write_byte (abfd, 50) | |
dc810e39 AM |
3682 | || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900)) |
3683 | || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1)) | |
3684 | || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday) | |
3685 | || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour) | |
3686 | || ! ieee_write_int (abfd, (bfd_vma) t->tm_min) | |
3687 | || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec)) | |
b34976b6 | 3688 | return FALSE; |
252b5132 RH |
3689 | } |
3690 | ||
3691 | output_bfd = abfd; | |
3692 | ||
3693 | flush (); | |
3694 | ||
3695 | if (! ieee_write_section_part (abfd)) | |
b34976b6 | 3696 | return FALSE; |
252b5132 RH |
3697 | /* First write the symbols. This changes their values into table |
3698 | indeces so we cant use it after this point. */ | |
3699 | if (! ieee_write_external_part (abfd)) | |
b34976b6 | 3700 | return FALSE; |
252b5132 | 3701 | |
252b5132 RH |
3702 | /* Write any debugs we have been told about. */ |
3703 | if (! ieee_write_debug_part (abfd)) | |
b34976b6 | 3704 | return FALSE; |
252b5132 RH |
3705 | |
3706 | /* Can only write the data once the symbols have been written, since | |
3707 | the data contains relocation information which points to the | |
3708 | symbols. */ | |
3709 | if (! ieee_write_data_part (abfd)) | |
b34976b6 | 3710 | return FALSE; |
252b5132 RH |
3711 | |
3712 | /* At the end we put the end! */ | |
3713 | if (! ieee_write_me_part (abfd)) | |
b34976b6 | 3714 | return FALSE; |
252b5132 | 3715 | |
49ae03bf | 3716 | /* Generate the header. */ |
252b5132 | 3717 | if (bfd_seek (abfd, old, SEEK_SET) != 0) |
b34976b6 | 3718 | return FALSE; |
252b5132 RH |
3719 | |
3720 | for (i = 0; i < N_W_VARIABLES; i++) | |
3721 | { | |
3722 | if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum) | |
3723 | || ! ieee_write_byte (abfd, (bfd_byte) i) | |
dc810e39 | 3724 | || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i])) |
b34976b6 | 3725 | return FALSE; |
252b5132 RH |
3726 | } |
3727 | ||
b34976b6 | 3728 | return TRUE; |
252b5132 RH |
3729 | } |
3730 | \f | |
c8e7bf0d | 3731 | /* Native-level interface to symbols. */ |
252b5132 RH |
3732 | |
3733 | /* We read the symbols into a buffer, which is discarded when this | |
3734 | function exits. We read the strings into a buffer large enough to | |
49ae03bf | 3735 | hold them all plus all the cached symbol entries. */ |
252b5132 | 3736 | |
47fda0d3 | 3737 | static asymbol * |
46e94266 | 3738 | ieee_make_empty_symbol (bfd *abfd) |
252b5132 | 3739 | { |
dc810e39 | 3740 | bfd_size_type amt = sizeof (ieee_symbol_type); |
d3ce72d0 | 3741 | ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_zalloc (abfd, amt); |
49ae03bf | 3742 | |
d3ce72d0 | 3743 | if (!new_symbol) |
252b5132 | 3744 | return NULL; |
d3ce72d0 NC |
3745 | new_symbol->symbol.the_bfd = abfd; |
3746 | return &new_symbol->symbol; | |
252b5132 RH |
3747 | } |
3748 | ||
3749 | static bfd * | |
46e94266 | 3750 | ieee_openr_next_archived_file (bfd *arch, bfd *prev) |
252b5132 RH |
3751 | { |
3752 | ieee_ar_data_type *ar = IEEE_AR_DATA (arch); | |
49ae03bf NC |
3753 | |
3754 | /* Take the next one from the arch state, or reset. */ | |
252b5132 | 3755 | if (prev == (bfd *) NULL) |
49ae03bf NC |
3756 | /* Reset the index - the first two entries are bogus. */ |
3757 | ar->element_index = 2; | |
3758 | ||
b34976b6 | 3759 | while (TRUE) |
252b5132 RH |
3760 | { |
3761 | ieee_ar_obstack_type *p = ar->elements + ar->element_index; | |
49ae03bf | 3762 | |
252b5132 RH |
3763 | ar->element_index++; |
3764 | if (ar->element_index <= ar->element_count) | |
3765 | { | |
3766 | if (p->file_offset != (file_ptr) 0) | |
3767 | { | |
3768 | if (p->abfd == (bfd *) NULL) | |
3769 | { | |
3770 | p->abfd = _bfd_create_empty_archive_element_shell (arch); | |
3771 | p->abfd->origin = p->file_offset; | |
3772 | } | |
3773 | return p->abfd; | |
3774 | } | |
3775 | } | |
3776 | else | |
3777 | { | |
3778 | bfd_set_error (bfd_error_no_more_archived_files); | |
46e94266 | 3779 | return NULL; |
252b5132 | 3780 | } |
252b5132 RH |
3781 | } |
3782 | } | |
3783 | ||
9c461f7d | 3784 | #define ieee_find_nearest_line _bfd_nosymbols_find_nearest_line |
07d6d2b8 | 3785 | #define ieee_find_line _bfd_nosymbols_find_line |
9c461f7d | 3786 | #define ieee_find_inliner_info _bfd_nosymbols_find_inliner_info |
4ab527b0 | 3787 | |
252b5132 | 3788 | static int |
46e94266 | 3789 | ieee_generic_stat_arch_elt (bfd *abfd, struct stat *buf) |
252b5132 RH |
3790 | { |
3791 | ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL; | |
3792 | ieee_data_type *ieee; | |
3793 | ||
3794 | if (abfd->my_archive != NULL) | |
3795 | ar = abfd->my_archive->tdata.ieee_ar_data; | |
3796 | if (ar == (ieee_ar_data_type *) NULL) | |
3797 | { | |
3798 | bfd_set_error (bfd_error_invalid_operation); | |
3799 | return -1; | |
3800 | } | |
3801 | ||
3802 | if (IEEE_DATA (abfd) == NULL) | |
3803 | { | |
3804 | if (ieee_object_p (abfd) == NULL) | |
3805 | { | |
3806 | bfd_set_error (bfd_error_wrong_format); | |
3807 | return -1; | |
3808 | } | |
3809 | } | |
3810 | ||
3811 | ieee = IEEE_DATA (abfd); | |
3812 | ||
3813 | buf->st_size = ieee->w.r.me_record + 1; | |
3814 | buf->st_mode = 0644; | |
3815 | return 0; | |
3816 | } | |
3817 | ||
3818 | static int | |
46e94266 | 3819 | ieee_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED, |
a6b96beb | 3820 | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
252b5132 RH |
3821 | { |
3822 | return 0; | |
3823 | } | |
3824 | ||
252b5132 RH |
3825 | #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup |
3826 | #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info | |
3827 | ||
d00dd7dc AM |
3828 | #define ieee_slurp_armap _bfd_bool_bfd_true |
3829 | #define ieee_slurp_extended_name_table _bfd_bool_bfd_true | |
252b5132 | 3830 | #define ieee_construct_extended_name_table \ |
d00dd7dc | 3831 | _bfd_noarchive_construct_extended_name_table |
252b5132 | 3832 | #define ieee_truncate_arname bfd_dont_truncate_arname |
d00dd7dc AM |
3833 | #define ieee_write_armap _bfd_noarchive_write_armap |
3834 | #define ieee_read_ar_hdr _bfd_ptr_bfd_null_error | |
3835 | #define ieee_write_ar_hdr _bfd_noarchive_write_ar_hdr | |
3836 | #define ieee_update_armap_timestamp _bfd_bool_bfd_true | |
252b5132 RH |
3837 | #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index |
3838 | ||
60bb06bc L |
3839 | #define ieee_get_symbol_version_string \ |
3840 | _bfd_nosymbols_get_symbol_version_string | |
d00dd7dc | 3841 | #define ieee_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false |
252b5132 RH |
3842 | #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name |
3843 | #define ieee_get_lineno _bfd_nosymbols_get_lineno | |
3844 | #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol | |
3845 | #define ieee_read_minisymbols _bfd_generic_read_minisymbols | |
3846 | #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol | |
3847 | ||
3848 | #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup | |
157090f7 | 3849 | #define ieee_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup |
252b5132 RH |
3850 | |
3851 | #define ieee_set_arch_mach _bfd_generic_set_arch_mach | |
3852 | ||
3853 | #define ieee_get_section_contents_in_window \ | |
3854 | _bfd_generic_get_section_contents_in_window | |
3855 | #define ieee_bfd_get_relocated_section_contents \ | |
3856 | bfd_generic_get_relocated_section_contents | |
3857 | #define ieee_bfd_relax_section bfd_generic_relax_section | |
3858 | #define ieee_bfd_gc_sections bfd_generic_gc_sections | |
ae17ab41 | 3859 | #define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags |
8550eb6e | 3860 | #define ieee_bfd_merge_sections bfd_generic_merge_sections |
72adc230 | 3861 | #define ieee_bfd_is_group_section bfd_generic_is_group_section |
e61463e1 | 3862 | #define ieee_bfd_discard_group bfd_generic_discard_group |
082b7297 L |
3863 | #define ieee_section_already_linked \ |
3864 | _bfd_generic_section_already_linked | |
3023e3f6 | 3865 | #define ieee_bfd_define_common_symbol bfd_generic_define_common_symbol |
7dba9362 | 3866 | #define ieee_bfd_define_start_stop bfd_generic_define_start_stop |
252b5132 RH |
3867 | #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create |
3868 | #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols | |
2d653fc7 | 3869 | #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms |
1338dd10 PB |
3870 | #define ieee_bfd_copy_link_hash_symbol_type \ |
3871 | _bfd_generic_copy_link_hash_symbol_type | |
252b5132 RH |
3872 | #define ieee_bfd_final_link _bfd_generic_final_link |
3873 | #define ieee_bfd_link_split_section _bfd_generic_link_split_section | |
4f3b23b3 | 3874 | #define ieee_bfd_link_check_relocs _bfd_generic_link_check_relocs |
23186865 | 3875 | #define ieee_set_reloc _bfd_generic_set_reloc |
252b5132 | 3876 | |
252b5132 RH |
3877 | const bfd_target ieee_vec = |
3878 | { | |
116c20d2 | 3879 | "ieee", /* Name. */ |
252b5132 | 3880 | bfd_target_ieee_flavour, |
116c20d2 NC |
3881 | BFD_ENDIAN_UNKNOWN, /* Target byte order. */ |
3882 | BFD_ENDIAN_UNKNOWN, /* Target headers byte order. */ | |
3883 | (HAS_RELOC | EXEC_P | /* Object flags. */ | |
252b5132 RH |
3884 | HAS_LINENO | HAS_DEBUG | |
3885 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
3886 | (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS | |
116c20d2 NC |
3887 | | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */ |
3888 | '_', /* Leading underscore. */ | |
3889 | ' ', /* AR_pad_char. */ | |
3890 | 16, /* AR_max_namelen. */ | |
0aabe54e | 3891 | 0, /* match priority. */ |
252b5132 RH |
3892 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, |
3893 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
116c20d2 | 3894 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ |
252b5132 RH |
3895 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, |
3896 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
116c20d2 | 3897 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */ |
252b5132 RH |
3898 | |
3899 | {_bfd_dummy_target, | |
116c20d2 | 3900 | ieee_object_p, /* bfd_check_format. */ |
252b5132 RH |
3901 | ieee_archive_p, |
3902 | _bfd_dummy_target, | |
3903 | }, | |
3904 | { | |
d00dd7dc | 3905 | _bfd_bool_bfd_false_error, |
252b5132 RH |
3906 | ieee_mkobject, |
3907 | _bfd_generic_mkarchive, | |
d00dd7dc | 3908 | _bfd_bool_bfd_false_error |
252b5132 RH |
3909 | }, |
3910 | { | |
d00dd7dc | 3911 | _bfd_bool_bfd_false_error, |
252b5132 RH |
3912 | ieee_write_object_contents, |
3913 | _bfd_write_archive_contents, | |
d00dd7dc | 3914 | _bfd_bool_bfd_false_error, |
252b5132 RH |
3915 | }, |
3916 | ||
47fda0d3 | 3917 | /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook, |
c8e7bf0d | 3918 | ieee_get_section_contents, ieee_get_section_contents_in_window. */ |
252b5132 | 3919 | BFD_JUMP_TABLE_GENERIC (ieee), |
47fda0d3 | 3920 | |
252b5132 RH |
3921 | BFD_JUMP_TABLE_COPY (_bfd_generic), |
3922 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
47fda0d3 AM |
3923 | |
3924 | /* ieee_slurp_armap, ieee_slurp_extended_name_table, | |
3925 | ieee_construct_extended_name_table, ieee_truncate_arname, | |
3926 | ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file, | |
3927 | ieee_get_elt_at_index, ieee_generic_stat_arch_elt, | |
c8e7bf0d | 3928 | ieee_update_armap_timestamp. */ |
252b5132 | 3929 | BFD_JUMP_TABLE_ARCHIVE (ieee), |
47fda0d3 | 3930 | |
6cee3f79 AC |
3931 | /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab, |
3932 | ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info, | |
3933 | ieee_bfd_is_local_label_name, ieee_get_lineno, | |
3934 | ieee_find_nearest_line, ieee_bfd_make_debug_symbol, | |
c8e7bf0d | 3935 | ieee_read_minisymbols, ieee_minisymbol_to_symbol. */ |
252b5132 | 3936 | BFD_JUMP_TABLE_SYMBOLS (ieee), |
47fda0d3 AM |
3937 | |
3938 | /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc, | |
c8e7bf0d | 3939 | ieee_bfd_reloc_type_lookup. */ |
252b5132 | 3940 | BFD_JUMP_TABLE_RELOCS (ieee), |
47fda0d3 | 3941 | |
c8e7bf0d | 3942 | /* ieee_set_arch_mach, ieee_set_section_contents. */ |
252b5132 | 3943 | BFD_JUMP_TABLE_WRITE (ieee), |
47fda0d3 AM |
3944 | |
3945 | /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents, | |
3946 | ieee_bfd_relax_section, ieee_bfd_link_hash_table_create, | |
3947 | ieee_bfd_link_add_symbols, ieee_bfd_final_link, | |
3948 | ieee_bfd_link_split_section, ieee_bfd_gc_sections, | |
c8e7bf0d | 3949 | ieee_bfd_merge_sections. */ |
252b5132 | 3950 | BFD_JUMP_TABLE_LINK (ieee), |
47fda0d3 | 3951 | |
252b5132 RH |
3952 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
3953 | ||
c3c89269 | 3954 | NULL, |
dc810e39 | 3955 | |
116c20d2 | 3956 | NULL |
252b5132 | 3957 | }; |