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