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