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