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