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