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