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