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