Commit | Line | Data |
---|---|---|
ce3f6d51 | 1 | /* bfd back-end for ieee-695 objects. |
d0ec7a8e | 2 | |
ce3f6d51 | 3 | IEEE 695 format is a stream of records, which we parse using a simple one- |
9b4641a6 JG |
4 | token (which is one byte in this lexicon) lookahead recursive decent |
5 | parser. */ | |
87f86b4e | 6 | |
9b4641a6 | 7 | /* Copyright (C) 1990, 1991 Free Software Foundation, Inc. |
87f86b4e | 8 | |
9b4641a6 | 9 | This file is part of BFD, the Binary File Diddler. |
87f86b4e | 10 | |
9b4641a6 JG |
11 | BFD is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 1, or (at your option) | |
14 | any later version. | |
87f86b4e | 15 | |
9b4641a6 JG |
16 | BFD is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
87f86b4e | 20 | |
9b4641a6 JG |
21 | You should have received a copy of the GNU General Public License |
22 | along with BFD; see the file COPYING. If not, write to | |
23 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
87f86b4e | 24 | |
d0ec7a8e | 25 | |
7ed4093a | 26 | #include <sysdep.h> |
87f86b4e DHW |
27 | #include "bfd.h" |
28 | #include "libbfd.h" | |
87f86b4e DHW |
29 | #include "ieee.h" |
30 | #include "libieee.h" | |
31 | ||
ce3f6d51 JG |
32 | /* Functions for writing to ieee files in the strange way that the |
33 | standard requires. */ | |
87f86b4e DHW |
34 | |
35 | static void | |
301dfc71 SC |
36 | DEFUN(ieee_write_byte,(abfd, byte), |
37 | bfd *abfd AND | |
38 | bfd_byte byte) | |
87f86b4e | 39 | { |
d0ec7a8e | 40 | bfd_write((PTR)&byte, 1, 1, abfd); |
87f86b4e DHW |
41 | } |
42 | ||
43 | ||
44 | static void | |
301dfc71 SC |
45 | DEFUN(ieee_write_2bytes,(abfd, bytes), |
46 | bfd *abfd AND | |
47 | int bytes) | |
87f86b4e DHW |
48 | { |
49 | bfd_byte buffer[2]; | |
50 | buffer[0] = bytes >> 8; | |
51 | buffer[1] = bytes & 0xff; | |
52 | ||
d0ec7a8e | 53 | bfd_write((PTR)buffer, 1, 2, abfd); |
87f86b4e DHW |
54 | } |
55 | ||
56 | static void | |
301dfc71 SC |
57 | DEFUN(ieee_write_int,(abfd, value), |
58 | bfd *abfd AND | |
59 | bfd_vma value) | |
87f86b4e DHW |
60 | { |
61 | if (value >= 0 && value <= 127) { | |
62 | ieee_write_byte(abfd, value); | |
63 | } | |
64 | else { | |
65 | unsigned int length; | |
66 | /* How many significant bytes ? */ | |
67 | /* FIXME FOR LONGER INTS */ | |
68 | if (value & 0xff000000) { | |
69 | length = 4; | |
70 | } | |
71 | else if (value & 0x00ff0000) { | |
72 | length = 3; | |
73 | } | |
74 | else if (value & 0x0000ff00) { | |
75 | length = 2; | |
76 | } | |
77 | else length = 1; | |
78 | ||
ce3f6d51 | 79 | ieee_write_byte(abfd, (int)ieee_number_repeat_start_enum + length); |
87f86b4e DHW |
80 | switch (length) { |
81 | case 4: | |
82 | ieee_write_byte(abfd, value >> 24); | |
83 | case 3: | |
84 | ieee_write_byte(abfd, value >> 16); | |
85 | case 2: | |
86 | ieee_write_byte(abfd, value >> 8); | |
87 | case 1: | |
88 | ieee_write_byte(abfd, value); | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | static void | |
301dfc71 SC |
94 | DEFUN(ieee_write_id,(abfd, id), |
95 | bfd *abfd AND | |
96 | CONST char *id) | |
87f86b4e DHW |
97 | { |
98 | size_t length = strlen(id); | |
99 | if (length >= 0 && length <= 127) { | |
100 | ieee_write_byte(abfd, length); | |
101 | } | |
102 | else if (length < 255) { | |
103 | ieee_write_byte(abfd, ieee_extension_length_1_enum); | |
104 | ieee_write_byte(abfd, length); | |
105 | } | |
106 | else if (length < 65535) { | |
107 | ieee_write_byte(abfd, ieee_extension_length_2_enum); | |
108 | ieee_write_byte(abfd, length >> 8); | |
109 | ieee_write_byte(abfd, length & 0xff); | |
110 | } | |
111 | else { | |
112 | BFD_FAIL(); | |
113 | } | |
d0ec7a8e | 114 | bfd_write((PTR)id, 1, length, abfd); |
87f86b4e DHW |
115 | } |
116 | /*************************************************************************** | |
117 | Functions for reading from ieee files in the strange way that the | |
118 | standard requires: | |
119 | */ | |
87f86b4e | 120 | |
d0ec7a8e SC |
121 | |
122 | #define this_byte(ieee) *(ieee->input_p) | |
123 | #define next_byte(ieee) (ieee->input_p++) | |
124 | #define this_byte_and_next(ieee) (*(ieee->input_p++)) | |
87f86b4e DHW |
125 | |
126 | ||
301dfc71 | 127 | static unsigned short |
d0ec7a8e SC |
128 | DEFUN(read_2bytes,(ieee), |
129 | ieee_data_type *ieee) | |
87f86b4e | 130 | { |
d0ec7a8e SC |
131 | unsigned char c1 = this_byte_and_next(ieee); |
132 | unsigned char c2 = this_byte_and_next(ieee); | |
87f86b4e DHW |
133 | return (c1<<8 ) | c2; |
134 | ||
135 | } | |
136 | ||
137 | static void | |
d0ec7a8e SC |
138 | DEFUN(bfd_get_string,(ieee, string, length), |
139 | ieee_data_type *ieee AND | |
301dfc71 SC |
140 | char *string AND |
141 | size_t length) | |
87f86b4e DHW |
142 | { |
143 | size_t i; | |
144 | for (i= 0; i < length; i++) { | |
d0ec7a8e | 145 | string[i] = this_byte_and_next(ieee); |
87f86b4e DHW |
146 | } |
147 | } | |
148 | ||
301dfc71 | 149 | static char * |
d0ec7a8e SC |
150 | DEFUN(read_id,(ieee), |
151 | ieee_data_type *ieee) | |
87f86b4e DHW |
152 | { |
153 | size_t length; | |
154 | char *string; | |
d0ec7a8e | 155 | length = this_byte_and_next(ieee); |
87f86b4e DHW |
156 | if (length >= 0x00 && length <= 0x7f) { |
157 | /* Simple string of length 0 to 127 */ | |
158 | } | |
159 | else if (length == 0xde) { | |
160 | /* Length is next byte, allowing 0..255 */ | |
d0ec7a8e | 161 | length = this_byte_and_next(ieee); |
87f86b4e DHW |
162 | } |
163 | else if (length == 0xdf) { | |
164 | /* Length is next two bytes, allowing 0..65535 */ | |
d0ec7a8e SC |
165 | length = this_byte_and_next(ieee) ; |
166 | length = (length * 256) + this_byte_and_next(ieee); | |
87f86b4e DHW |
167 | } |
168 | /* Buy memory and read string */ | |
d0ec7a8e SC |
169 | string = bfd_alloc(ieee->abfd, length+1); |
170 | bfd_get_string(ieee, string, length); | |
87f86b4e DHW |
171 | string[length] = 0; |
172 | return string; | |
173 | } | |
174 | ||
175 | static void | |
d0ec7a8e | 176 | DEFUN(ieee_write_expression,(abfd, value, section, symbol, pcrel, index), |
301dfc71 SC |
177 | bfd*abfd AND |
178 | bfd_vma value AND | |
179 | asection *section AND | |
d0ec7a8e SC |
180 | asymbol *symbol AND |
181 | boolean pcrel AND | |
182 | unsigned int index) | |
87f86b4e DHW |
183 | { |
184 | unsigned int plus_count = 0; | |
185 | ieee_write_int(abfd, value); | |
186 | if (section != (asection *)NULL) { | |
187 | plus_count++; | |
188 | ieee_write_byte(abfd, ieee_variable_L_enum); | |
189 | ieee_write_byte(abfd, section->index +IEEE_SECTION_NUMBER_BASE); | |
190 | } | |
191 | ||
d0ec7a8e SC |
192 | |
193 | ||
87f86b4e DHW |
194 | if (symbol != (asymbol *)NULL) { |
195 | plus_count++; | |
196 | if ((symbol->flags & BSF_UNDEFINED ) || | |
197 | (symbol->flags & BSF_FORT_COMM)) { | |
198 | ieee_write_byte(abfd, ieee_variable_X_enum); | |
199 | ieee_write_int(abfd, symbol->value); | |
200 | } | |
201 | else if (symbol->flags & BSF_GLOBAL) { | |
202 | ieee_write_byte(abfd, ieee_variable_I_enum); | |
203 | ieee_write_int(abfd, symbol->value); | |
204 | } | |
301dfc71 SC |
205 | else if (symbol->flags & BSF_LOCAL) { |
206 | /* This is a reference to a defined local symbol, | |
207 | We can easily do a local as a section+offset */ | |
208 | if (symbol->section != (asection *)NULL) { | |
209 | /* If this symbol is not absolute, add the base of it */ | |
210 | ieee_write_byte(abfd, ieee_variable_L_enum); | |
211 | ieee_write_byte(abfd, symbol->section->index + | |
212 | IEEE_SECTION_NUMBER_BASE); | |
213 | plus_count++; | |
214 | } | |
215 | ||
216 | ieee_write_int(abfd, symbol->value); | |
217 | } | |
87f86b4e | 218 | else { |
301dfc71 | 219 | |
87f86b4e DHW |
220 | BFD_FAIL(); |
221 | } | |
222 | } | |
223 | ||
d0ec7a8e SC |
224 | if(pcrel) { |
225 | /* subtract the pc from here by asking for PC of this section*/ | |
226 | ieee_write_byte(abfd, ieee_variable_P_enum); | |
227 | ieee_write_byte(abfd, index +IEEE_SECTION_NUMBER_BASE); | |
228 | ieee_write_byte(abfd, ieee_function_minus_enum); | |
229 | } | |
230 | ||
231 | while (plus_count > 0) { | |
87f86b4e DHW |
232 | ieee_write_byte(abfd, ieee_function_plus_enum); |
233 | plus_count--; | |
234 | } | |
235 | ||
236 | } | |
237 | ||
238 | ||
239 | ||
240 | ||
241 | ||
242 | ||
243 | ||
244 | ||
245 | ||
246 | /*****************************************************************************/ | |
247 | ||
248 | /* | |
249 | writes any integer into the buffer supplied and always takes 5 bytes | |
250 | */ | |
251 | static void | |
301dfc71 SC |
252 | DEFUN(ieee_write_int5,(buffer, value), |
253 | bfd_byte*buffer AND | |
254 | bfd_vma value ) | |
87f86b4e DHW |
255 | { |
256 | buffer[0] = ieee_number_repeat_4_enum; | |
257 | buffer[1] = (value >> 24 ) & 0xff; | |
258 | buffer[2] = (value >> 16 ) & 0xff; | |
259 | buffer[3] = (value >> 8 ) & 0xff; | |
301dfc71 SC |
260 | buffer[4] = (value >> 0 ) & 0xff; |
261 | } | |
262 | static void | |
263 | DEFUN(ieee_write_int5_out, (abfd, value), | |
264 | bfd *abfd AND | |
265 | bfd_vma value) | |
266 | { | |
d0ec7a8e | 267 | bfd_byte b[5]; |
301dfc71 | 268 | ieee_write_int5(b, value); |
d0ec7a8e | 269 | bfd_write((PTR)b,1,5,abfd); |
87f86b4e | 270 | } |
87f86b4e DHW |
271 | |
272 | ||
273 | static boolean | |
d0ec7a8e SC |
274 | DEFUN(parse_int,(ieee, value_ptr), |
275 | ieee_data_type *ieee AND | |
301dfc71 | 276 | bfd_vma *value_ptr) |
87f86b4e | 277 | { |
d0ec7a8e | 278 | int value = this_byte(ieee); |
87f86b4e DHW |
279 | int result; |
280 | if (value >= 0 && value <= 127) { | |
281 | *value_ptr = value; | |
d0ec7a8e | 282 | next_byte(ieee); |
87f86b4e DHW |
283 | return true; |
284 | } | |
285 | else if (value >= 0x80 && value <= 0x88) { | |
286 | unsigned int count = value & 0xf; | |
287 | result = 0; | |
d0ec7a8e | 288 | next_byte(ieee); |
87f86b4e | 289 | while (count) { |
d0ec7a8e | 290 | result =(result << 8) | this_byte_and_next(ieee); |
87f86b4e DHW |
291 | count--; |
292 | } | |
293 | *value_ptr = result; | |
294 | return true; | |
295 | } | |
296 | return false; | |
297 | } | |
301dfc71 | 298 | static int |
d0ec7a8e SC |
299 | DEFUN(parse_i,(ieee, ok), |
300 | ieee_data_type *ieee AND | |
301dfc71 | 301 | boolean *ok) |
87f86b4e DHW |
302 | { |
303 | bfd_vma x; | |
d0ec7a8e | 304 | *ok = parse_int(ieee, &x); |
87f86b4e DHW |
305 | return x; |
306 | } | |
307 | ||
301dfc71 | 308 | static bfd_vma |
d0ec7a8e SC |
309 | DEFUN(must_parse_int,(ieee), |
310 | ieee_data_type *ieee) | |
87f86b4e DHW |
311 | { |
312 | bfd_vma result; | |
d0ec7a8e | 313 | BFD_ASSERT(parse_int(ieee, &result) == true); |
87f86b4e DHW |
314 | return result; |
315 | } | |
316 | ||
317 | typedef struct | |
318 | { | |
319 | bfd_vma value; | |
320 | asection *section; | |
321 | ieee_symbol_index_type symbol; | |
322 | } ieee_value_type; | |
323 | ||
324 | ||
325 | static | |
326 | reloc_howto_type abs32_howto | |
d0ec7a8e | 327 | = HOWTO(1,0,2,32,0,0,0,true,0,"abs32",true,0xffffffff, 0xffffffff,false); |
87f86b4e DHW |
328 | static |
329 | reloc_howto_type abs16_howto | |
d0ec7a8e SC |
330 | = HOWTO(1,0,1,16,0,0,0,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false); |
331 | ||
332 | static | |
333 | reloc_howto_type rel32_howto | |
334 | = HOWTO(1,0,2,32,1,0,0,true,0,"rel32",true,0xffffffff, 0xffffffff,false); | |
335 | static | |
336 | reloc_howto_type rel16_howto | |
337 | = HOWTO(1,0,1,16,1,0,0,true,0,"rel16",true,0x0000ffff, 0x0000ffff,false); | |
87f86b4e DHW |
338 | |
339 | static ieee_symbol_index_type NOSYMBOL = { 0, 0}; | |
340 | ||
341 | ||
301dfc71 | 342 | static void |
d0ec7a8e SC |
343 | DEFUN(parse_expression,(ieee, value, section, symbol, pcrel, extra), |
344 | ieee_data_type *ieee AND | |
301dfc71 SC |
345 | bfd_vma *value AND |
346 | asection **section AND | |
347 | ieee_symbol_index_type *symbol AND | |
348 | boolean *pcrel AND | |
349 | unsigned int *extra) | |
d0ec7a8e | 350 | |
87f86b4e DHW |
351 | { |
352 | #define POS sp[1] | |
353 | #define TOS sp[0] | |
354 | #define NOS sp[-1] | |
355 | #define INC sp++; | |
356 | #define DEC sp--; | |
357 | ||
358 | boolean loop = true; | |
359 | ieee_value_type stack[10]; | |
360 | ||
361 | /* The stack pointer always points to the next unused location */ | |
362 | #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC; | |
363 | #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value; | |
364 | ieee_value_type *sp = stack; | |
365 | ||
366 | while (loop) { | |
d0ec7a8e | 367 | switch (this_byte(ieee)) |
87f86b4e | 368 | { |
d0ec7a8e SC |
369 | case ieee_variable_P_enum: |
370 | /* P variable, current program counter for section n */ | |
371 | { | |
372 | int section_n ; | |
373 | next_byte(ieee); | |
374 | *pcrel = true; | |
375 | section_n = must_parse_int(ieee); | |
376 | PUSH(NOSYMBOL, 0, | |
377 | TOS.value = ieee->section_table[section_n]->vma + | |
378 | ieee_per_section(ieee->section_table[section_n])->pc); | |
379 | break; | |
380 | } | |
381 | case ieee_variable_L_enum: | |
382 | /* L variable address of section N */ | |
383 | next_byte(ieee); | |
384 | PUSH(NOSYMBOL,ieee->section_table[must_parse_int(ieee)],0); | |
385 | break; | |
386 | case ieee_variable_R_enum: | |
387 | /* R variable, logical address of section module */ | |
388 | /* FIXME, this should be different to L */ | |
389 | next_byte(ieee); | |
390 | PUSH(NOSYMBOL,ieee->section_table[must_parse_int(ieee)],0); | |
391 | break; | |
392 | case ieee_variable_S_enum: | |
393 | /* S variable, size in MAUS of section module */ | |
394 | next_byte(ieee); | |
395 | PUSH(NOSYMBOL, | |
396 | 0, | |
397 | ieee->section_table[must_parse_int(ieee)]->size); | |
87f86b4e | 398 | break; |
87f86b4e | 399 | |
d0ec7a8e SC |
400 | case ieee_variable_X_enum: |
401 | /* Push the address of external variable n */ | |
402 | { | |
403 | ieee_symbol_index_type sy; | |
404 | next_byte(ieee); | |
405 | sy.index = (int)(must_parse_int(ieee)) ; | |
406 | sy.letter = 'X'; | |
87f86b4e | 407 | |
d0ec7a8e SC |
408 | PUSH(sy, 0, 0); |
409 | } | |
410 | break; | |
411 | case ieee_function_minus_enum: | |
87f86b4e | 412 | { |
d0ec7a8e SC |
413 | bfd_vma value1, value2; |
414 | asection *section1, *section_dummy; | |
415 | ieee_symbol_index_type sy; | |
416 | next_byte(ieee); | |
417 | ||
418 | POP(sy, section1, value1); | |
419 | POP(sy, section_dummy, value2); | |
420 | PUSH(sy, section1, value1-value2); | |
87f86b4e | 421 | } |
d0ec7a8e SC |
422 | break; |
423 | case ieee_function_plus_enum: | |
424 | { | |
425 | bfd_vma value1, value2; | |
426 | asection *section1; | |
427 | asection *section2; | |
428 | ieee_symbol_index_type sy1; | |
429 | ieee_symbol_index_type sy2; | |
430 | next_byte(ieee); | |
431 | ||
432 | POP(sy1, section1, value1); | |
433 | POP(sy2, section2, value2); | |
434 | PUSH(sy1.letter ? sy1 : sy2, section1 ? section1: section2, value1+value2); | |
87f86b4e | 435 | } |
d0ec7a8e SC |
436 | break; |
437 | default: | |
438 | { | |
439 | bfd_vma va; | |
ce3f6d51 JG |
440 | BFD_ASSERT(this_byte(ieee) < (int)ieee_variable_A_enum |
441 | || this_byte(ieee) > (int)ieee_variable_Z_enum); | |
d0ec7a8e SC |
442 | if (parse_int(ieee, &va)) |
443 | { | |
444 | PUSH(NOSYMBOL,0, va); | |
445 | } | |
446 | else { | |
447 | /* | |
448 | Thats all that we can understand. As far as I can see | |
449 | there is a bug in the Microtec IEEE output which I'm | |
450 | using to scan, whereby the comma operator is ommited | |
451 | sometimes in an expression, giving expressions with too | |
452 | many terms. We can tell if that's the case by ensuring | |
453 | that sp == stack here. If not, then we've pushed | |
454 | something too far, so we keep adding | |
455 | */ | |
456 | ||
457 | while (sp != stack+1) { | |
458 | asection *section1; | |
459 | ieee_symbol_index_type sy1; | |
460 | POP(sy1, section1, *extra); | |
461 | } | |
462 | ||
463 | POP(*symbol, *section, *value); | |
464 | loop = false; | |
465 | } | |
87f86b4e | 466 | } |
87f86b4e | 467 | |
d0ec7a8e | 468 | } |
87f86b4e DHW |
469 | } |
470 | } | |
471 | ||
301dfc71 SC |
472 | |
473 | ||
474 | #define ieee_seek(abfd, offset) \ | |
475 | ieee_data(abfd)->input_p = ieee_data(abfd)->first_byte + offset | |
87f86b4e DHW |
476 | |
477 | static void | |
301dfc71 SC |
478 | DEFUN(ieee_slurp_external_symbols,(abfd), |
479 | bfd *abfd) | |
87f86b4e DHW |
480 | { |
481 | ieee_data_type *ieee = ieee_data(abfd); | |
482 | file_ptr offset = ieee->w.r.external_part; | |
483 | ||
484 | ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols; | |
485 | ieee_symbol_type **prev_reference_ptr = &ieee->external_reference; | |
486 | ieee_symbol_type *symbol; | |
487 | unsigned int symbol_count = 0; | |
488 | boolean loop = true; | |
489 | ||
490 | ieee->symbol_table_full = true; | |
491 | ||
301dfc71 | 492 | ieee_seek(abfd, offset ); |
87f86b4e DHW |
493 | |
494 | while (loop) { | |
d0ec7a8e | 495 | switch (this_byte(ieee)) { |
87f86b4e | 496 | case ieee_external_symbol_enum: |
d0ec7a8e SC |
497 | next_byte(ieee); |
498 | symbol = (ieee_symbol_type *)bfd_alloc(ieee->abfd, sizeof(ieee_symbol_type)); | |
87f86b4e DHW |
499 | |
500 | *prev_symbols_ptr = symbol; | |
501 | prev_symbols_ptr= &symbol->next; | |
d0ec7a8e | 502 | symbol->index = must_parse_int(ieee); |
87f86b4e DHW |
503 | if (symbol->index > ieee->external_symbol_max_index) { |
504 | ieee->external_symbol_max_index = symbol->index; | |
505 | } | |
506 | BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index); | |
507 | symbol_count++; | |
508 | symbol->symbol.the_bfd = abfd; | |
d0ec7a8e SC |
509 | symbol->symbol.name = read_id(ieee); |
510 | symbol->symbol.udata = (PTR)NULL; | |
87f86b4e DHW |
511 | symbol->symbol.flags = BSF_NO_FLAGS; |
512 | break; | |
513 | case ieee_attribute_record_enum >> 8: | |
514 | { | |
515 | unsigned int symbol_name_index; | |
516 | unsigned int symbol_type_index; | |
517 | unsigned int symbol_attribute_def; | |
518 | bfd_vma value; | |
d0ec7a8e SC |
519 | next_byte(ieee); /* Skip prefix */ |
520 | next_byte(ieee); | |
521 | symbol_name_index = must_parse_int(ieee); | |
522 | symbol_type_index = must_parse_int(ieee); | |
523 | symbol_attribute_def = must_parse_int(ieee); | |
87f86b4e | 524 | |
d0ec7a8e | 525 | parse_int(ieee,&value); |
87f86b4e DHW |
526 | |
527 | } | |
528 | break; | |
529 | case ieee_value_record_enum >> 8: | |
530 | { | |
531 | unsigned int symbol_name_index; | |
532 | ieee_symbol_index_type symbol_ignore; | |
301dfc71 | 533 | boolean pcrel_ignore; |
d0ec7a8e SC |
534 | unsigned int extra; |
535 | next_byte(ieee); | |
536 | next_byte(ieee); | |
87f86b4e | 537 | |
d0ec7a8e SC |
538 | symbol_name_index = must_parse_int(ieee); |
539 | parse_expression(ieee, | |
87f86b4e DHW |
540 | &symbol->symbol.value, |
541 | &symbol->symbol.section, | |
542 | &symbol_ignore, | |
d0ec7a8e SC |
543 | &pcrel_ignore, |
544 | &extra); | |
87f86b4e DHW |
545 | if (symbol->symbol.section != (asection *)NULL) { |
546 | symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT; | |
547 | } | |
548 | else { | |
549 | symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT | BSF_ABSOLUTE; | |
550 | } | |
551 | } | |
552 | break; | |
553 | case ieee_weak_external_reference_enum: | |
554 | { bfd_vma size; | |
555 | bfd_vma value ; | |
d0ec7a8e | 556 | next_byte(ieee); |
87f86b4e | 557 | /* Throw away the external reference index */ |
d0ec7a8e | 558 | (void)must_parse_int(ieee); |
87f86b4e | 559 | /* Fetch the default size if not resolved */ |
d0ec7a8e | 560 | size = must_parse_int(ieee); |
87f86b4e | 561 | /* Fetch the defautlt value if available */ |
d0ec7a8e | 562 | if ( parse_int(ieee, &value) == false) { |
87f86b4e DHW |
563 | value = 0; |
564 | } | |
565 | /* This turns into a common */ | |
566 | symbol->symbol.flags = BSF_FORT_COMM; | |
567 | symbol->symbol.value = size; | |
568 | } | |
569 | break; | |
570 | ||
571 | case ieee_external_reference_enum: | |
d0ec7a8e SC |
572 | next_byte(ieee); |
573 | symbol = (ieee_symbol_type *)bfd_alloc(ieee->abfd, sizeof(ieee_symbol_type)); | |
87f86b4e DHW |
574 | symbol_count++; |
575 | *prev_reference_ptr = symbol; | |
576 | prev_reference_ptr = &symbol->next; | |
d0ec7a8e | 577 | symbol->index = must_parse_int(ieee); |
87f86b4e | 578 | symbol->symbol.the_bfd = abfd; |
d0ec7a8e SC |
579 | symbol->symbol.name = read_id(ieee); |
580 | symbol->symbol.udata = (PTR)NULL; | |
87f86b4e DHW |
581 | symbol->symbol.section = (asection *)NULL; |
582 | symbol->symbol.value = (bfd_vma)0; | |
583 | symbol->symbol.flags = BSF_UNDEFINED; | |
584 | if (symbol->index > ieee->external_reference_max_index) { | |
585 | ieee->external_reference_max_index = symbol->index; | |
586 | } | |
587 | BFD_ASSERT (symbol->index >= ieee->external_reference_min_index); | |
588 | break; | |
589 | ||
590 | default: | |
591 | loop = false; | |
592 | } | |
593 | } | |
594 | ||
595 | if (ieee->external_symbol_max_index != 0) { | |
596 | ieee->external_symbol_count = | |
597 | ieee->external_symbol_max_index - | |
598 | ieee->external_symbol_min_index + 1 ; | |
599 | } | |
600 | else { | |
601 | ieee->external_symbol_count = 0; | |
602 | } | |
603 | ||
604 | ||
605 | if(ieee->external_reference_max_index != 0) { | |
606 | ieee->external_reference_count = | |
607 | ieee->external_reference_max_index - | |
608 | ieee->external_reference_min_index + 1; | |
609 | } | |
610 | else { | |
611 | ieee->external_reference_count = 0; | |
612 | } | |
613 | ||
614 | abfd->symcount = | |
615 | ieee->external_reference_count + ieee->external_symbol_count; | |
616 | ||
617 | if (symbol_count != abfd->symcount) { | |
618 | /* There are gaps in the table -- */ | |
619 | ieee->symbol_table_full = false; | |
620 | } | |
621 | *prev_symbols_ptr = (ieee_symbol_type *)NULL; | |
622 | *prev_reference_ptr = (ieee_symbol_type *)NULL; | |
623 | } | |
624 | ||
625 | static void | |
301dfc71 SC |
626 | DEFUN(ieee_slurp_symbol_table,(abfd), |
627 | bfd *abfd) | |
87f86b4e DHW |
628 | { |
629 | if (ieee_data(abfd)->read_symbols == false) { | |
630 | ieee_slurp_external_symbols(abfd); | |
631 | ieee_data(abfd)->read_symbols= true; | |
632 | } | |
633 | } | |
634 | ||
d0ec7a8e | 635 | unsigned int |
301dfc71 SC |
636 | DEFUN(ieee_get_symtab_upper_bound,(abfd), |
637 | bfd *abfd) | |
87f86b4e DHW |
638 | { |
639 | ieee_slurp_symbol_table (abfd); | |
640 | ||
641 | return (abfd->symcount != 0) ? | |
642 | (abfd->symcount+1) * (sizeof (ieee_symbol_type *)) : 0; | |
643 | } | |
644 | ||
645 | /* | |
646 | Move from our internal lists to the canon table, and insert in | |
647 | symbol index order | |
648 | */ | |
649 | ||
650 | extern bfd_target ieee_vec; | |
651 | unsigned int | |
301dfc71 SC |
652 | DEFUN(ieee_get_symtab,(abfd, location), |
653 | bfd *abfd AND | |
654 | asymbol **location) | |
87f86b4e DHW |
655 | { |
656 | ieee_symbol_type *symp; | |
657 | static bfd dummy_bfd; | |
658 | static asymbol empty_symbol = | |
d0ec7a8e SC |
659 | { &dummy_bfd," ieee empty",(symvalue)0,BSF_DEBUGGING | BSF_ABSOLUTE}; |
660 | ||
87f86b4e DHW |
661 | |
662 | ieee_data_type *ieee = ieee_data(abfd); | |
663 | dummy_bfd.xvec= &ieee_vec; | |
664 | ieee_slurp_symbol_table(abfd); | |
665 | ||
666 | if (ieee->symbol_table_full == false) { | |
667 | /* Arrgh - there are gaps in the table, run through and fill them */ | |
668 | /* up with pointers to a null place */ | |
669 | unsigned int i; | |
670 | for (i= 0; i < abfd->symcount; i++) { | |
671 | location[i] = &empty_symbol; | |
672 | } | |
673 | } | |
674 | ||
675 | ||
676 | ieee->external_symbol_base_offset= - ieee->external_symbol_min_index; | |
677 | for (symp = ieee_data(abfd)->external_symbols; | |
678 | symp != (ieee_symbol_type *)NULL; | |
679 | symp = symp->next) { | |
680 | /* Place into table at correct index locations */ | |
681 | location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol; | |
682 | ||
683 | } | |
684 | ||
685 | /* The external refs are indexed in a bit */ | |
686 | ieee->external_reference_base_offset = | |
687 | - ieee->external_reference_min_index +ieee->external_symbol_count ; | |
688 | ||
689 | for (symp = ieee_data(abfd)->external_reference; | |
690 | symp != (ieee_symbol_type *)NULL; | |
691 | symp = symp->next) { | |
692 | location[symp->index + ieee->external_reference_base_offset] = | |
693 | &symp->symbol; | |
694 | ||
695 | } | |
696 | ||
697 | ||
698 | ||
699 | location[abfd->symcount] = (asymbol *)NULL; | |
700 | ||
701 | return abfd->symcount; | |
702 | } | |
703 | ||
704 | ||
705 | static void | |
301dfc71 SC |
706 | DEFUN(ieee_slurp_sections,(abfd), |
707 | bfd *abfd) | |
87f86b4e DHW |
708 | { |
709 | ieee_data_type *ieee = ieee_data(abfd); | |
710 | file_ptr offset = ieee->w.r.section_part; | |
711 | ||
712 | asection *section = (asection *)NULL; | |
713 | ||
714 | if (offset != 0) { | |
715 | bfd_byte section_type[3]; | |
301dfc71 | 716 | ieee_seek(abfd, offset); |
87f86b4e | 717 | while (true) { |
d0ec7a8e | 718 | switch (this_byte(ieee)) { |
87f86b4e DHW |
719 | case ieee_section_type_enum: |
720 | { | |
721 | unsigned int section_index ; | |
d0ec7a8e SC |
722 | next_byte(ieee); |
723 | section_index = must_parse_int(ieee); | |
87f86b4e DHW |
724 | /* Fixme to be nice about a silly number of sections */ |
725 | BFD_ASSERT(section_index < NSECTIONS); | |
726 | ||
727 | section = bfd_make_section(abfd, " tempname"); | |
728 | ieee->section_table[section_index] = section; | |
729 | section->flags = SEC_NO_FLAGS; | |
730 | section->target_index = section_index; | |
d0ec7a8e | 731 | section_type[0] = this_byte_and_next(ieee); |
87f86b4e DHW |
732 | switch (section_type[0]) { |
733 | case 0xC3: | |
d0ec7a8e | 734 | section_type[1] = this_byte(ieee); |
87f86b4e DHW |
735 | section->flags = SEC_LOAD; |
736 | switch (section_type[1]) { | |
737 | case 0xD0: | |
738 | /* Normal code */ | |
d0ec7a8e | 739 | next_byte(ieee); |
87f86b4e DHW |
740 | section->flags |= SEC_LOAD | SEC_CODE; |
741 | break; | |
742 | case 0xC4: | |
d0ec7a8e | 743 | next_byte(ieee); |
87f86b4e DHW |
744 | section->flags |= SEC_LOAD | SEC_DATA; |
745 | /* Normal data */ | |
746 | break; | |
747 | case 0xD2: | |
d0ec7a8e | 748 | next_byte(ieee); |
87f86b4e DHW |
749 | /* Normal rom data */ |
750 | section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA; | |
751 | break; | |
752 | default: | |
753 | break; | |
754 | } | |
755 | } | |
d0ec7a8e | 756 | section->name = read_id(ieee); |
87f86b4e | 757 | { bfd_vma parent, brother, context; |
d0ec7a8e SC |
758 | parse_int(ieee, &parent); |
759 | parse_int(ieee, &brother); | |
760 | parse_int(ieee, &context); | |
87f86b4e DHW |
761 | } |
762 | ||
763 | ||
764 | } | |
765 | break; | |
766 | case ieee_section_alignment_enum: | |
767 | { | |
768 | unsigned int section_index; | |
769 | bfd_vma value; | |
d0ec7a8e SC |
770 | next_byte(ieee); |
771 | section_index = must_parse_int(ieee); | |
87f86b4e DHW |
772 | if (section_index > ieee->section_count) { |
773 | ieee->section_count = section_index; | |
774 | } | |
775 | ieee->section_table[section_index]->alignment_power = | |
d0ec7a8e SC |
776 | bfd_log2(must_parse_int(ieee)); |
777 | (void)parse_int(ieee, & value); | |
87f86b4e DHW |
778 | } |
779 | break; | |
780 | case ieee_e2_first_byte_enum: | |
781 | { | |
d0ec7a8e | 782 | ieee_record_enum_type t = read_2bytes(ieee); |
87f86b4e DHW |
783 | switch (t) { |
784 | case ieee_section_size_enum: | |
d0ec7a8e SC |
785 | section = ieee->section_table[must_parse_int(ieee)]; |
786 | section->size = must_parse_int(ieee); | |
87f86b4e DHW |
787 | break; |
788 | case ieee_physical_region_size_enum: | |
d0ec7a8e SC |
789 | section = ieee->section_table[must_parse_int(ieee)]; |
790 | section->size = must_parse_int(ieee); | |
87f86b4e DHW |
791 | break; |
792 | case ieee_region_base_address_enum: | |
d0ec7a8e SC |
793 | section = ieee->section_table[must_parse_int(ieee)]; |
794 | section->vma = must_parse_int(ieee); | |
87f86b4e DHW |
795 | break; |
796 | case ieee_mau_size_enum: | |
d0ec7a8e SC |
797 | must_parse_int(ieee); |
798 | must_parse_int(ieee); | |
87f86b4e DHW |
799 | break; |
800 | case ieee_m_value_enum: | |
d0ec7a8e SC |
801 | must_parse_int(ieee); |
802 | must_parse_int(ieee); | |
87f86b4e DHW |
803 | break; |
804 | case ieee_section_base_address_enum: | |
d0ec7a8e SC |
805 | section = ieee->section_table[must_parse_int(ieee)]; |
806 | section->vma = must_parse_int(ieee); | |
87f86b4e DHW |
807 | break; |
808 | case ieee_section_offset_enum: | |
d0ec7a8e SC |
809 | (void) must_parse_int(ieee); |
810 | (void) must_parse_int(ieee); | |
87f86b4e DHW |
811 | break; |
812 | default: | |
813 | return; | |
814 | } | |
815 | } | |
816 | break; | |
817 | default: | |
818 | return; | |
819 | } | |
820 | } | |
821 | } | |
822 | } | |
823 | ||
824 | /*********************************************************************** | |
825 | * archive stuff | |
826 | */ | |
827 | bfd_target * | |
301dfc71 SC |
828 | DEFUN(ieee_archive_p,(abfd), |
829 | bfd *abfd) | |
87f86b4e | 830 | { |
d0ec7a8e SC |
831 | return 0; |
832 | #if 0 | |
87f86b4e DHW |
833 | char *library; |
834 | boolean loop; | |
835 | ieee_ar_data_type *ar; | |
836 | unsigned int i; | |
d0ec7a8e SC |
837 | |
838 | ||
839 | /* FIXME */ | |
301dfc71 | 840 | ieee_seek(abfd, (file_ptr) 0); |
87f86b4e | 841 | if (this_byte(abfd) != Module_Beginning) return (bfd_target*)NULL; |
d0ec7a8e SC |
842 | next_byte(ieee); |
843 | library= read_id(ieee); | |
87f86b4e DHW |
844 | if (strcmp(library , "LIBRARY") != 0) { |
845 | free(library); | |
846 | return (bfd_target *)NULL; | |
847 | } | |
848 | /* Throw away the filename */ | |
d0ec7a8e | 849 | free( read_id(ieee)); |
87f86b4e DHW |
850 | /* This must be an IEEE archive, so we'll buy some space to do |
851 | things */ | |
852 | ar = (ieee_ar_data_type *) malloc(sizeof(ieee_ar_data_type)); | |
9b4641a6 | 853 | set_tdata (abfd, ar); |
87f86b4e DHW |
854 | ar->element_count = 0; |
855 | ar->element_index = 0; | |
856 | obstack_init(&ar->element_obstack); | |
857 | ||
d0ec7a8e SC |
858 | next_byte(ieee); /* Drop the ad part */ |
859 | must_parse_int(ieee); /* And the two dummy numbers */ | |
860 | must_parse_int(ieee); | |
87f86b4e DHW |
861 | |
862 | loop = true; | |
863 | /* Read the index of the BB table */ | |
864 | while (loop) { | |
865 | ieee_ar_obstack_type t; | |
866 | int rec =read_2bytes(abfd); | |
867 | if (rec ==ieee_assign_value_to_variable_enum) { | |
d0ec7a8e SC |
868 | int record_number = must_parse_int(ieee); |
869 | t.file_offset = must_parse_int(ieee); | |
87f86b4e DHW |
870 | t.abfd = (bfd *)NULL; |
871 | ar->element_count++; | |
301dfc71 | 872 | obstack_grow(&ar->element_obstack, (PTR)&t, sizeof(t)); |
87f86b4e DHW |
873 | } |
874 | else loop = false; | |
875 | } | |
876 | ar->elements = (ieee_ar_obstack_type *)obstack_base(&ar->element_obstack); | |
877 | ||
878 | /* Now scan the area again, and replace BB offsets with file */ | |
879 | /* offsets */ | |
880 | ||
881 | ||
882 | for (i = 2; i < ar->element_count; i++) { | |
301dfc71 | 883 | ieee_seek(abfd, ar->elements[i].file_offset); |
d0ec7a8e SC |
884 | next_byte(ieee); /* Drop F8 */ |
885 | next_byte(ieee); /* Drop 14 */ | |
886 | must_parse_int(ieee); /* Drop size of block */ | |
887 | if (must_parse_int(ieee) != 0) { | |
87f86b4e DHW |
888 | /* This object has been deleted */ |
889 | ar->elements[i].file_offset = 0; | |
890 | } | |
891 | else { | |
d0ec7a8e | 892 | ar->elements[i].file_offset = must_parse_int(ieee); |
87f86b4e DHW |
893 | } |
894 | } | |
895 | ||
896 | obstack_finish(&ar->element_obstack); | |
897 | return abfd->xvec; | |
d0ec7a8e | 898 | #endif |
87f86b4e DHW |
899 | } |
900 | ||
301dfc71 SC |
901 | static boolean |
902 | DEFUN(ieee_mkobject,(abfd), | |
903 | bfd *abfd) | |
904 | { | |
d0ec7a8e | 905 | ieee_data(abfd) = (ieee_data_type *)bfd_alloc(abfd,sizeof(ieee_data_type)); |
301dfc71 SC |
906 | return true; |
907 | } | |
908 | ||
87f86b4e | 909 | bfd_target * |
301dfc71 SC |
910 | DEFUN(ieee_object_p,(abfd), |
911 | bfd *abfd) | |
87f86b4e DHW |
912 | { |
913 | char *processor; | |
914 | unsigned int part; | |
301dfc71 | 915 | ieee_data_type *ieee; |
d0ec7a8e SC |
916 | uint8e_type buffer[300]; |
917 | ieee_data_type *save = ieee_data(abfd); | |
9b4641a6 | 918 | set_tdata (abfd, 0); |
301dfc71 SC |
919 | ieee_mkobject(abfd); |
920 | ieee = ieee_data(abfd); | |
921 | ||
922 | /* Read the first few bytes in to see if it makes sense */ | |
d0ec7a8e | 923 | bfd_read((PTR)buffer, 1, sizeof(buffer), abfd); |
301dfc71 | 924 | |
d0ec7a8e SC |
925 | ieee->input_p = buffer; |
926 | if (this_byte_and_next(ieee) != Module_Beginning) goto fail; | |
301dfc71 SC |
927 | |
928 | ieee->read_symbols= false; | |
929 | ieee->read_data= false; | |
930 | ieee->section_count = 0; | |
931 | ieee->external_symbol_max_index = 0; | |
932 | ieee->external_symbol_min_index = IEEE_PUBLIC_BASE; | |
933 | ieee->external_reference_min_index =IEEE_REFERENCE_BASE; | |
934 | ieee->external_reference_max_index = 0; | |
d0ec7a8e | 935 | ieee->abfd = abfd; |
301dfc71 SC |
936 | memset((PTR)ieee->section_table, 0, sizeof(ieee->section_table)); |
937 | ||
d0ec7a8e | 938 | processor = ieee->mb.processor = read_id(ieee); |
301dfc71 | 939 | if (strcmp(processor,"LIBRARY") == 0) goto fail; |
d0ec7a8e | 940 | ieee->mb.module_name = read_id(ieee); |
87f86b4e | 941 | if (abfd->filename == (char *)NULL) { |
301dfc71 | 942 | abfd->filename = ieee->mb.module_name; |
87f86b4e DHW |
943 | } |
944 | /* Determine the architecture and machine type of the object file. */ | |
945 | bfd_scan_arch_mach(processor, &abfd->obj_arch, &abfd->obj_machine); | |
946 | ||
d0ec7a8e | 947 | if (this_byte(ieee) != ieee_address_descriptor_enum) { |
301dfc71 | 948 | goto fail; |
87f86b4e | 949 | } |
d0ec7a8e | 950 | next_byte(ieee); |
87f86b4e | 951 | |
d0ec7a8e | 952 | if (parse_int(ieee, &ieee->ad.number_of_bits_mau) == false) { |
301dfc71 | 953 | goto fail; |
87f86b4e | 954 | } |
d0ec7a8e | 955 | if(parse_int(ieee, &ieee->ad.number_of_maus_in_address) == false) { |
301dfc71 | 956 | goto fail; |
87f86b4e DHW |
957 | } |
958 | ||
959 | /* If there is a byte order info, take it */ | |
d0ec7a8e SC |
960 | if (this_byte(ieee) == ieee_variable_L_enum || |
961 | this_byte(ieee) == ieee_variable_M_enum) | |
962 | next_byte(ieee); | |
87f86b4e DHW |
963 | |
964 | ||
965 | for (part = 0; part < N_W_VARIABLES; part++) { | |
966 | boolean ok; | |
d0ec7a8e | 967 | if (read_2bytes(ieee) != ieee_assign_value_to_variable_enum) { |
301dfc71 | 968 | goto fail; |
87f86b4e | 969 | } |
d0ec7a8e | 970 | if (this_byte_and_next(ieee) != part) { |
301dfc71 | 971 | goto fail; |
87f86b4e DHW |
972 | } |
973 | ||
d0ec7a8e | 974 | ieee->w.offset[part] = parse_i(ieee, &ok); |
87f86b4e | 975 | if (ok==false) { |
301dfc71 | 976 | goto fail; |
87f86b4e DHW |
977 | } |
978 | ||
979 | } | |
980 | abfd->flags = HAS_SYMS; | |
981 | ||
301dfc71 SC |
982 | /* By now we know that this is a real IEEE file, we're going to read |
983 | the whole thing into memory so that we can run up and down it | |
984 | quickly. We can work out how big the file is from the trailer | |
985 | record */ | |
986 | ||
d0ec7a8e | 987 | ieee_data(abfd)->first_byte = (uint8e_type *) bfd_alloc(ieee->abfd, ieee->w.r.me_record |
301dfc71 SC |
988 | + 50); |
989 | bfd_seek(abfd, 0, 0); | |
d0ec7a8e | 990 | bfd_read((PTR)(ieee_data(abfd)->first_byte), 1, ieee->w.r.me_record+50, abfd); |
301dfc71 | 991 | |
87f86b4e DHW |
992 | ieee_slurp_sections(abfd); |
993 | return abfd->xvec; | |
301dfc71 | 994 | fail: |
d0ec7a8e SC |
995 | (void) bfd_release(abfd, ieee); |
996 | ieee_data(abfd) = save; | |
301dfc71 | 997 | return (bfd_target *)NULL; |
87f86b4e DHW |
998 | } |
999 | ||
1000 | ||
1001 | void | |
2b1d8a50 | 1002 | DEFUN(ieee_print_symbol,(ignore_abfd, afile, symbol, how), |
301dfc71 | 1003 | bfd *ignore_abfd AND |
2b1d8a50 | 1004 | PTR afile AND |
301dfc71 SC |
1005 | asymbol *symbol AND |
1006 | bfd_print_symbol_enum_type how) | |
87f86b4e | 1007 | { |
2b1d8a50 JG |
1008 | FILE *file = (FILE *)afile; |
1009 | ||
87f86b4e DHW |
1010 | switch (how) { |
1011 | case bfd_print_symbol_name_enum: | |
1012 | fprintf(file,"%s", symbol->name); | |
1013 | break; | |
1014 | case bfd_print_symbol_type_enum: | |
1015 | #if 0 | |
1016 | fprintf(file,"%4x %2x",aout_symbol(symbol)->desc & 0xffff, | |
1017 | aout_symbol(symbol)->other & 0xff); | |
1018 | #endif | |
1019 | BFD_FAIL(); | |
1020 | break; | |
1021 | case bfd_print_symbol_all_enum: | |
301dfc71 SC |
1022 | { |
1023 | CONST char *section_name = symbol->section == (asection *)NULL ? | |
1024 | "*abs" : symbol->section->name; | |
d0ec7a8e SC |
1025 | if (symbol->name[0] == ' ') { |
1026 | fprintf(file,"* empty table entry "); | |
1027 | } | |
1028 | else { | |
1029 | bfd_print_symbol_vandf((PTR)file,symbol); | |
301dfc71 | 1030 | |
d0ec7a8e SC |
1031 | fprintf(file," %-5s %04x %02x %s", |
1032 | section_name, | |
1033 | (unsigned) ieee_symbol(symbol)->index, | |
1034 | (unsigned) 0, /* | |
301dfc71 SC |
1035 | aout_symbol(symbol)->desc & 0xffff, |
1036 | aout_symbol(symbol)->other & 0xff,*/ | |
d0ec7a8e SC |
1037 | symbol->name); |
1038 | } | |
301dfc71 | 1039 | } |
87f86b4e DHW |
1040 | break; |
1041 | } | |
1042 | } | |
1043 | ||
1044 | ||
7ed4093a | 1045 | static void |
7564d3d7 SC |
1046 | DEFUN(do_one,(ieee, current_map, location_ptr,s), |
1047 | ieee_data_type *ieee AND | |
1048 | ieee_per_section_type *current_map AND | |
1049 | uint8e_type *location_ptr AND | |
1050 | asection *s) | |
1051 | { | |
1052 | switch (this_byte(ieee)) | |
1053 | { | |
1054 | case ieee_load_constant_bytes_enum: | |
1055 | { | |
1056 | unsigned int number_of_maus; | |
1057 | unsigned int i; | |
1058 | next_byte(ieee); | |
1059 | number_of_maus = must_parse_int(ieee); | |
1060 | ||
1061 | for (i = 0; i < number_of_maus; i++) { | |
1062 | location_ptr[current_map->pc++]= this_byte(ieee); | |
1063 | next_byte(ieee); | |
1064 | } | |
1065 | } | |
1066 | break; | |
1067 | ||
1068 | case ieee_load_with_relocation_enum: | |
1069 | { | |
1070 | boolean loop = true; | |
1071 | next_byte(ieee); | |
1072 | while (loop) | |
1073 | { | |
1074 | switch (this_byte(ieee)) | |
1075 | { | |
1076 | case ieee_variable_R_enum: | |
1077 | ||
1078 | case ieee_function_signed_open_b_enum: | |
1079 | case ieee_function_unsigned_open_b_enum: | |
1080 | case ieee_function_either_open_b_enum: | |
1081 | { | |
1082 | unsigned int extra = 4; | |
1083 | boolean pcrel = false; | |
1084 | ||
1085 | ieee_reloc_type *r = | |
1086 | (ieee_reloc_type *) bfd_alloc(ieee->abfd, | |
1087 | sizeof(ieee_reloc_type)); | |
1088 | ||
1089 | *(current_map->reloc_tail_ptr) = r; | |
1090 | current_map->reloc_tail_ptr= &r->next; | |
1091 | r->next = (ieee_reloc_type *)NULL; | |
1092 | next_byte(ieee); | |
1093 | parse_expression(ieee, | |
1094 | &r->relent.addend, | |
1095 | &r->relent.section, | |
1096 | &r->symbol, | |
1097 | &pcrel, &extra); | |
1098 | r->relent.address = current_map->pc; | |
1099 | s->reloc_count++; | |
1100 | switch (this_byte(ieee)) { | |
1101 | case ieee_function_signed_close_b_enum: | |
1102 | next_byte(ieee); | |
1103 | break; | |
1104 | case ieee_function_unsigned_close_b_enum: | |
1105 | next_byte(ieee); | |
1106 | break; | |
1107 | case ieee_function_either_close_b_enum: | |
1108 | next_byte(ieee); | |
1109 | break; | |
1110 | default: | |
1111 | break; | |
1112 | } | |
1113 | /* Build a relocation entry for this type */ | |
1114 | if (this_byte(ieee) == ieee_comma) { | |
1115 | next_byte(ieee); | |
1116 | /* Fetch number of bytes to pad */ | |
1117 | extra = must_parse_int(ieee); | |
1118 | }; | |
1119 | ||
1120 | /* If pc rel then stick -ve pc into instruction | |
1121 | and take out of reloc*/ | |
1122 | ||
1123 | switch (extra) | |
1124 | { | |
1125 | case 0: | |
1126 | case 4: | |
1127 | if (pcrel == true) | |
1128 | { | |
7ed4093a | 1129 | bfd_put_32(ieee->abfd, -current_map->pc, location_ptr + |
7564d3d7 SC |
1130 | current_map->pc); |
1131 | r->relent.howto = &rel32_howto; | |
1132 | r->relent.addend -= current_map->pc; | |
1133 | } | |
1134 | else | |
1135 | { | |
7ed4093a | 1136 | bfd_put_32(ieee->abfd, 0, location_ptr + |
7564d3d7 SC |
1137 | current_map->pc); |
1138 | r->relent.howto = &abs32_howto; | |
1139 | } | |
1140 | current_map->pc +=4; | |
1141 | break; | |
1142 | case 2: | |
1143 | if (pcrel == true) { | |
7ed4093a | 1144 | bfd_put_16(ieee->abfd, (int)(-current_map->pc), location_ptr +current_map->pc); |
7564d3d7 SC |
1145 | r->relent.addend -= current_map->pc; |
1146 | r->relent.howto = &rel16_howto; | |
1147 | } | |
1148 | else { | |
7ed4093a | 1149 | bfd_put_16(ieee->abfd, 0, location_ptr +current_map->pc); |
7564d3d7 SC |
1150 | r->relent.howto = &abs16_howto; |
1151 | } | |
1152 | current_map->pc +=2; | |
1153 | break; | |
1154 | ||
1155 | default: | |
1156 | BFD_FAIL(); | |
1157 | break; | |
1158 | } | |
1159 | } | |
1160 | break; | |
1161 | default: | |
1162 | { | |
1163 | bfd_vma this_size ; | |
1164 | if (parse_int(ieee, &this_size) == true) { | |
1165 | unsigned int i; | |
1166 | for (i = 0; i < this_size; i++) { | |
1167 | location_ptr[current_map->pc ++] = this_byte(ieee); | |
1168 | next_byte(ieee); | |
1169 | } | |
1170 | } | |
1171 | else { | |
1172 | loop = false; | |
1173 | } | |
1174 | } | |
1175 | } | |
1176 | } | |
1177 | } | |
1178 | } | |
1179 | } | |
87f86b4e | 1180 | |
7564d3d7 | 1181 | /* Read in all the section data and relocation stuff too */ |
301dfc71 SC |
1182 | static boolean |
1183 | DEFUN(ieee_slurp_section_data,(abfd), | |
1184 | bfd *abfd) | |
87f86b4e DHW |
1185 | { |
1186 | bfd_byte *location_ptr ; | |
1187 | ieee_data_type *ieee = ieee_data(abfd); | |
1188 | unsigned int section_number ; | |
1189 | ||
1190 | ieee_per_section_type *current_map; | |
1191 | asection *s; | |
1192 | /* Seek to the start of the data area */ | |
1193 | if (ieee->read_data== true) return true; | |
1194 | ieee->read_data = true; | |
301dfc71 | 1195 | ieee_seek(abfd, ieee->w.r.data_part); |
87f86b4e DHW |
1196 | |
1197 | /* Allocate enough space for all the section contents */ | |
1198 | ||
1199 | ||
1200 | for (s = abfd->sections; s != (asection *)NULL; s = s->next) { | |
a6dab071 | 1201 | ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd; |
d0ec7a8e | 1202 | per->data = (bfd_byte *) bfd_alloc(ieee->abfd, s->size); |
87f86b4e | 1203 | /*SUPPRESS 68*/ |
87f86b4e DHW |
1204 | per->reloc_tail_ptr = |
1205 | (ieee_reloc_type **)&(s->relocation); | |
1206 | } | |
1207 | ||
1208 | ||
1209 | ||
1210 | while (true) { | |
d0ec7a8e | 1211 | switch (this_byte(ieee)) |
87f86b4e | 1212 | { |
7564d3d7 SC |
1213 | /* IF we see anything strange then quit */ |
1214 | default: | |
1215 | return true; | |
87f86b4e | 1216 | |
7564d3d7 SC |
1217 | case ieee_set_current_section_enum: |
1218 | next_byte(ieee); | |
1219 | section_number = must_parse_int(ieee); | |
1220 | s = ieee->section_table[section_number]; | |
1221 | current_map = (ieee_per_section_type *) s->used_by_bfd; | |
1222 | location_ptr = current_map->data - s->vma; | |
1223 | /* The document I have says that Microtec's compilers reset */ | |
1224 | /* this after a sec section, even though the standard says not */ | |
1225 | /* to. SO .. */ | |
1226 | current_map->pc =s->vma; | |
1227 | break; | |
87f86b4e | 1228 | |
87f86b4e | 1229 | |
7564d3d7 | 1230 | case ieee_e2_first_byte_enum: |
d0ec7a8e | 1231 | next_byte(ieee); |
7564d3d7 SC |
1232 | switch (this_byte(ieee)) |
1233 | { | |
1234 | case ieee_set_current_pc_enum & 0xff: | |
87f86b4e | 1235 | { |
7564d3d7 SC |
1236 | bfd_vma value; |
1237 | asection *dsection; | |
1238 | ieee_symbol_index_type symbol; | |
1239 | unsigned int extra; | |
1240 | boolean pcrel; | |
d0ec7a8e | 1241 | next_byte(ieee); |
7564d3d7 SC |
1242 | must_parse_int(ieee); /* Thow away section #*/ |
1243 | parse_expression(ieee, &value, &dsection, &symbol, | |
d0ec7a8e | 1244 | &pcrel, &extra); |
7564d3d7 SC |
1245 | current_map->pc = value; |
1246 | BFD_ASSERT((unsigned)(value - s->vma) <= s->size); | |
87f86b4e | 1247 | } |
7564d3d7 SC |
1248 | break; |
1249 | ||
1250 | case ieee_value_starting_address_enum & 0xff: | |
1251 | /* We've got to the end of the data now - */ | |
1252 | return true; | |
1253 | default: | |
1254 | BFD_FAIL(); | |
1255 | return true; | |
1256 | } | |
1257 | break; | |
1258 | case ieee_repeat_data_enum: | |
1259 | { | |
1260 | /* Repeat the following LD or LR n times - we do this by | |
1261 | remembering the stream pointer before running it and | |
1262 | resetting it and running it n times | |
1263 | */ | |
1264 | ||
1265 | unsigned int iterations ; | |
1266 | uint8e_type *start ; | |
1267 | next_byte(ieee); | |
1268 | iterations = must_parse_int(ieee); | |
1269 | start = ieee->input_p; | |
1270 | while (iterations != 0) { | |
1271 | ieee->input_p = start; | |
1272 | do_one(ieee, current_map, location_ptr,s); | |
1273 | iterations --; | |
1274 | } | |
1275 | } | |
1276 | break; | |
1277 | case ieee_load_constant_bytes_enum: | |
1278 | case ieee_load_with_relocation_enum: | |
1279 | { | |
1280 | do_one(ieee, current_map, location_ptr,s); | |
87f86b4e DHW |
1281 | } |
1282 | } | |
87f86b4e DHW |
1283 | } |
1284 | } | |
1285 | ||
1286 | ||
1287 | ||
7564d3d7 SC |
1288 | |
1289 | ||
87f86b4e | 1290 | boolean |
301dfc71 SC |
1291 | DEFUN(ieee_new_section_hook,(abfd, newsect), |
1292 | bfd *abfd AND | |
1293 | asection *newsect) | |
87f86b4e | 1294 | { |
a6dab071 | 1295 | newsect->used_by_bfd = (PTR) |
d0ec7a8e | 1296 | bfd_alloc(abfd, sizeof(ieee_per_section_type)); |
87f86b4e DHW |
1297 | ieee_per_section( newsect)->data = (bfd_byte *)NULL; |
1298 | ieee_per_section(newsect)->section = newsect; | |
1299 | return true; | |
1300 | } | |
1301 | ||
1302 | ||
1303 | unsigned int | |
301dfc71 SC |
1304 | DEFUN(ieee_get_reloc_upper_bound,(abfd, asect), |
1305 | bfd *abfd AND | |
1306 | sec_ptr asect) | |
87f86b4e DHW |
1307 | { |
1308 | ieee_slurp_section_data(abfd); | |
1309 | return (asect->reloc_count+1) * sizeof(arelent *); | |
1310 | } | |
1311 | ||
1312 | static boolean | |
301dfc71 SC |
1313 | DEFUN(ieee_get_section_contents,(abfd, section, location, offset, count), |
1314 | bfd *abfd AND | |
1315 | sec_ptr section AND | |
d0ec7a8e | 1316 | PTR location AND |
301dfc71 | 1317 | file_ptr offset AND |
7ed4093a | 1318 | bfd_size_type count) |
87f86b4e | 1319 | { |
a6dab071 | 1320 | ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd; |
87f86b4e | 1321 | ieee_slurp_section_data(abfd); |
7ed4093a | 1322 | (void) memcpy(location, p->data + offset, (unsigned)count); |
87f86b4e DHW |
1323 | return true; |
1324 | } | |
1325 | ||
1326 | ||
1327 | unsigned int | |
301dfc71 SC |
1328 | DEFUN(ieee_canonicalize_reloc,(abfd, section, relptr, symbols), |
1329 | bfd *abfd AND | |
1330 | sec_ptr section AND | |
1331 | arelent **relptr AND | |
1332 | asymbol **symbols) | |
87f86b4e | 1333 | { |
d0ec7a8e | 1334 | /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/ |
87f86b4e DHW |
1335 | ieee_reloc_type *src = (ieee_reloc_type *)(section->relocation); |
1336 | ieee_data_type *ieee = ieee_data(abfd); | |
1337 | ||
1338 | while (src != (ieee_reloc_type *)NULL) { | |
1339 | /* Work out which symbol to attatch it this reloc to */ | |
1340 | switch (src->symbol.letter) { | |
1341 | case 'X': | |
1342 | src->relent.sym_ptr_ptr = | |
1343 | symbols + src->symbol.index + ieee->external_reference_base_offset; | |
1344 | break; | |
1345 | case 0: | |
1346 | src->relent.sym_ptr_ptr = (asymbol **)NULL; | |
1347 | break; | |
1348 | default: | |
1349 | ||
1350 | BFD_FAIL(); | |
1351 | } | |
1352 | *relptr++ = &src->relent; | |
1353 | src = src->next; | |
1354 | } | |
1355 | *relptr = (arelent *)NULL; | |
1356 | return section->reloc_count; | |
1357 | } | |
1358 | ||
1359 | boolean | |
301dfc71 SC |
1360 | DEFUN(ieee_set_arch_mach,(abfd, arch, machine), |
1361 | bfd *abfd AND | |
1362 | enum bfd_architecture arch AND | |
1363 | unsigned long machine) | |
87f86b4e DHW |
1364 | { |
1365 | abfd->obj_arch = arch; | |
1366 | abfd->obj_machine = machine; | |
1367 | return true; | |
1368 | } | |
1369 | ||
87f86b4e | 1370 | |
301dfc71 SC |
1371 | static int |
1372 | DEFUN(comp,(ap, bp), | |
39a2ce33 SC |
1373 | CONST PTR ap AND |
1374 | CONST PTR bp) | |
87f86b4e | 1375 | { |
9872a49c SC |
1376 | arelent *a = *((arelent **)ap); |
1377 | arelent *b = *((arelent **)bp); | |
87f86b4e DHW |
1378 | return a->address - b->address; |
1379 | } | |
9872a49c | 1380 | |
87f86b4e DHW |
1381 | /* |
1382 | Write the section headers | |
1383 | */ | |
1384 | ||
1385 | static void | |
301dfc71 SC |
1386 | DEFUN(ieee_write_section_part,(abfd), |
1387 | bfd *abfd) | |
87f86b4e DHW |
1388 | { |
1389 | ieee_data_type *ieee = ieee_data(abfd); | |
1390 | asection *s; | |
1391 | ieee->w.r.section_part = bfd_tell(abfd); | |
1392 | for (s = abfd->sections; s != (asection *)NULL; s=s->next) { | |
1393 | ieee_write_byte(abfd, ieee_section_type_enum); | |
1394 | ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); | |
1395 | ||
1396 | switch (s->flags & (SEC_LOAD | SEC_CODE | SEC_DATA | SEC_ROM)) { | |
1397 | case SEC_LOAD | SEC_CODE: | |
1398 | /* Normal named section, code */ | |
1399 | ieee_write_byte(abfd, ieee_variable_C_enum); | |
1400 | ieee_write_byte(abfd, ieee_variable_P_enum); | |
1401 | break; | |
1402 | case SEC_LOAD | SEC_DATA: | |
1403 | /* Normal named section, data */ | |
1404 | ieee_write_byte(abfd, ieee_variable_C_enum); | |
1405 | ieee_write_byte(abfd, ieee_variable_D_enum); | |
1406 | break; | |
1407 | case SEC_LOAD | SEC_DATA | SEC_ROM: | |
1408 | /* Normal named section, data rom */ | |
1409 | ieee_write_byte(abfd, ieee_variable_C_enum); | |
1410 | ieee_write_byte(abfd, ieee_variable_R_enum); | |
1411 | break; | |
1412 | default: | |
1413 | ieee_write_byte(abfd, ieee_variable_C_enum); | |
1414 | break; | |
1415 | } | |
1416 | ||
1417 | ieee_write_id(abfd, s->name); | |
1418 | ieee_write_int(abfd, 0); /* Parent */ | |
1419 | ieee_write_int(abfd, 0); /* Brother */ | |
1420 | ieee_write_int(abfd, 0); /* Context */ | |
1421 | ||
1422 | /* Alignment */ | |
1423 | ieee_write_byte(abfd, ieee_section_alignment_enum); | |
1424 | ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); | |
1425 | ieee_write_int(abfd, 1 << s->alignment_power); | |
1426 | ||
1427 | /* Size */ | |
1428 | ieee_write_2bytes(abfd, ieee_section_size_enum); | |
1429 | ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); | |
1430 | ieee_write_int(abfd, s->size); | |
1431 | ||
1432 | /* Vma */ | |
1433 | ieee_write_2bytes(abfd, ieee_region_base_address_enum); | |
1434 | ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); | |
1435 | ieee_write_int(abfd, s->vma); | |
1436 | ||
1437 | } | |
1438 | } | |
1439 | ||
1440 | ||
1441 | ||
1442 | /* write the data in an ieee way */ | |
1443 | static void | |
301dfc71 SC |
1444 | DEFUN(ieee_write_data_part,(abfd), |
1445 | bfd *abfd) | |
87f86b4e DHW |
1446 | { |
1447 | asection *s; | |
1448 | ieee_data_type *ieee = ieee_data(abfd); | |
1449 | ieee->w.r.data_part = bfd_tell(abfd); | |
1450 | for (s = abfd->sections; s != (asection *)NULL; s = s->next) | |
301dfc71 SC |
1451 | { |
1452 | bfd_byte header[11]; | |
1453 | bfd_byte *stream = ieee_per_section(s)->data; | |
1454 | arelent **p = s->orelocation; | |
1455 | unsigned int relocs_to_go = s->reloc_count; | |
7ed4093a | 1456 | bfd_size_type current_byte_index = 0; |
301dfc71 | 1457 | |
301dfc71 SC |
1458 | /* Sort the reloc records so we can insert them in the correct |
1459 | places */ | |
1460 | if (s->reloc_count != 0) { | |
1461 | qsort(s->orelocation, | |
d0ec7a8e | 1462 | relocs_to_go, |
301dfc71 SC |
1463 | sizeof(arelent **), |
1464 | comp); | |
1465 | } | |
87f86b4e DHW |
1466 | |
1467 | ||
301dfc71 SC |
1468 | /* Output the section preheader */ |
1469 | header[0] =ieee_set_current_section_enum; | |
1470 | header[1] = s->index + IEEE_SECTION_NUMBER_BASE; | |
87f86b4e | 1471 | |
301dfc71 SC |
1472 | header[2] = ieee_set_current_pc_enum >> 8; |
1473 | header[3]= ieee_set_current_pc_enum & 0xff; | |
1474 | header[4] = s->index + IEEE_SECTION_NUMBER_BASE; | |
1475 | ieee_write_int5(header+5, s->vma ); | |
1476 | header[10] = ieee_load_with_relocation_enum; | |
d0ec7a8e | 1477 | bfd_write((PTR)header, 1, sizeof(header), abfd); |
87f86b4e | 1478 | |
301dfc71 SC |
1479 | /* Output the data stream as the longest sequence of bytes |
1480 | possible, allowing for the a reasonable packet size and | |
1481 | relocation stuffs */ | |
87f86b4e | 1482 | |
d0ec7a8e | 1483 | if ((PTR)stream == (PTR)NULL) { |
301dfc71 | 1484 | /* Outputting a section without data, fill it up */ |
d0ec7a8e SC |
1485 | stream = (uint8e_type *)(bfd_alloc(abfd, s->size)); |
1486 | memset((PTR)stream, 0, s->size); | |
87f86b4e | 1487 | } |
301dfc71 | 1488 | while (current_byte_index < s->size) { |
7ed4093a | 1489 | bfd_size_type run; |
301dfc71 | 1490 | unsigned int MAXRUN = 32; |
d0ec7a8e | 1491 | if (relocs_to_go) { |
301dfc71 SC |
1492 | run = (*p)->address - current_byte_index; |
1493 | } | |
1494 | else { | |
1495 | run = MAXRUN; | |
1496 | } | |
1497 | if (run > s->size - current_byte_index) { | |
1498 | run = s->size - current_byte_index; | |
1499 | } | |
1500 | ||
1501 | if (run != 0) { | |
1502 | /* Output a stream of bytes */ | |
1503 | ieee_write_int(abfd, run); | |
d0ec7a8e | 1504 | bfd_write((PTR)(stream + current_byte_index), |
301dfc71 SC |
1505 | 1, |
1506 | run, | |
1507 | abfd); | |
1508 | current_byte_index += run; | |
1509 | } | |
1510 | /* Output any relocations here */ | |
1511 | if (relocs_to_go && (*p) && (*p)->address == current_byte_index) { | |
1512 | while (relocs_to_go && (*p) && (*p)->address == current_byte_index) { | |
1513 | ||
1514 | arelent *r = *p; | |
d0ec7a8e SC |
1515 | bfd_vma ov; |
1516 | if (r->howto->pc_relative) { | |
1517 | r->addend += current_byte_index; | |
1518 | } | |
1519 | ||
1520 | switch (r->howto->size) { | |
1521 | case 2: | |
1522 | ||
7ed4093a | 1523 | ov = bfd_get_32(abfd, |
d0ec7a8e SC |
1524 | stream+current_byte_index); |
1525 | current_byte_index +=4; | |
1526 | break; | |
1527 | case 1: | |
7ed4093a | 1528 | ov = bfd_get_16(abfd, |
d0ec7a8e SC |
1529 | stream+current_byte_index); |
1530 | current_byte_index +=2; | |
1531 | break; | |
1532 | default: | |
1533 | BFD_FAIL(); | |
1534 | } | |
301dfc71 | 1535 | ieee_write_byte(abfd, ieee_function_either_open_b_enum); |
d0ec7a8e | 1536 | |
301dfc71 | 1537 | if (r->sym_ptr_ptr != (asymbol **)NULL) { |
d0ec7a8e | 1538 | ieee_write_expression(abfd, r->addend + ov, |
301dfc71 | 1539 | r->section, |
d0ec7a8e SC |
1540 | *(r->sym_ptr_ptr), |
1541 | r->howto->pc_relative, s->target_index); | |
301dfc71 SC |
1542 | } |
1543 | else { | |
d0ec7a8e | 1544 | ieee_write_expression(abfd, r->addend + ov, |
301dfc71 | 1545 | r->section, |
d0ec7a8e SC |
1546 | (asymbol *)NULL, |
1547 | r->howto->pc_relative, s->target_index); | |
301dfc71 SC |
1548 | } |
1549 | ieee_write_byte(abfd, | |
1550 | ieee_function_either_close_b_enum); | |
d0ec7a8e SC |
1551 | if (r->howto->size != 2) { |
1552 | ieee_write_byte(abfd, ieee_comma); | |
1553 | ieee_write_int(abfd, 1<< r->howto->size); | |
1554 | } | |
1555 | ||
301dfc71 SC |
1556 | relocs_to_go --; |
1557 | p++; | |
87f86b4e | 1558 | } |
d0ec7a8e | 1559 | |
87f86b4e | 1560 | } |
87f86b4e DHW |
1561 | } |
1562 | } | |
87f86b4e | 1563 | |
301dfc71 | 1564 | } |
87f86b4e DHW |
1565 | |
1566 | ||
1567 | ||
1568 | static void | |
301dfc71 SC |
1569 | DEFUN(init_for_output,(abfd), |
1570 | bfd *abfd) | |
87f86b4e DHW |
1571 | { |
1572 | asection *s; | |
1573 | for (s = abfd->sections; s != (asection *)NULL; s = s->next) { | |
1574 | if (s->size != 0) { | |
d0ec7a8e | 1575 | ieee_per_section(s)->data = (bfd_byte *)(bfd_alloc(abfd, s->size)); |
87f86b4e DHW |
1576 | } |
1577 | } | |
1578 | } | |
1579 | ||
1580 | /** exec and core file sections */ | |
1581 | ||
1582 | /* set section contents is complicated with IEEE since the format is | |
1583 | * not a byte image, but a record stream. | |
1584 | */ | |
1585 | boolean | |
301dfc71 SC |
1586 | DEFUN(ieee_set_section_contents,(abfd, section, location, offset, count), |
1587 | bfd *abfd AND | |
1588 | sec_ptr section AND | |
d0ec7a8e | 1589 | PTR location AND |
301dfc71 | 1590 | file_ptr offset AND |
7ed4093a | 1591 | bfd_size_type count) |
87f86b4e DHW |
1592 | { |
1593 | if (ieee_per_section(section)->data == (bfd_byte *)NULL) { | |
1594 | init_for_output(abfd); | |
1595 | } | |
7ed4093a SC |
1596 | (void) memcpy(ieee_per_section(section)->data + offset, |
1597 | location, | |
1598 | (unsigned int)count); | |
87f86b4e DHW |
1599 | return true; |
1600 | } | |
1601 | ||
1602 | /* | |
1603 | write the external symbols of a file, IEEE considers two sorts of | |
1604 | external symbols, public, and referenced. It uses to internal forms | |
1605 | to index them as well. When we write them out we turn their symbol | |
1606 | values into indexes from the right base. | |
1607 | */ | |
1608 | static void | |
301dfc71 SC |
1609 | DEFUN(ieee_write_external_part,(abfd), |
1610 | bfd *abfd) | |
87f86b4e DHW |
1611 | { |
1612 | asymbol **q; | |
1613 | ieee_data_type *ieee = ieee_data(abfd); | |
1614 | ||
1615 | unsigned int reference_index = IEEE_REFERENCE_BASE; | |
1616 | unsigned int public_index = IEEE_PUBLIC_BASE; | |
1617 | ieee->w.r.external_part = bfd_tell(abfd); | |
1618 | if (abfd->outsymbols != (asymbol **)NULL) { | |
1619 | for (q = abfd->outsymbols; *q != (asymbol *)NULL; q++) { | |
1620 | asymbol *p = *q; | |
1621 | if (p->flags & BSF_UNDEFINED) { | |
1622 | /* This must be a symbol reference .. */ | |
1623 | ieee_write_byte(abfd, ieee_external_reference_enum); | |
1624 | ieee_write_int(abfd, reference_index); | |
1625 | ieee_write_id(abfd, p->name); | |
1626 | p->value = reference_index; | |
1627 | reference_index++; | |
1628 | } | |
1629 | else if(p->flags & BSF_FORT_COMM) { | |
1630 | /* This is a weak reference */ | |
1631 | ieee_write_byte(abfd, ieee_external_reference_enum); | |
1632 | ieee_write_int(abfd, reference_index); | |
1633 | ieee_write_id(abfd, p->name); | |
1634 | ieee_write_byte(abfd, ieee_weak_external_reference_enum); | |
1635 | ieee_write_int(abfd, reference_index); | |
1636 | ieee_write_int(abfd, p->value); | |
1637 | ieee_write_int(abfd, BFD_FORT_COMM_DEFAULT_VALUE); | |
1638 | p->value = reference_index; | |
1639 | reference_index++; | |
1640 | } | |
1641 | else if(p->flags & BSF_GLOBAL) { | |
1642 | /* This must be a symbol definition */ | |
1643 | ||
1644 | ieee_write_byte(abfd, ieee_external_symbol_enum); | |
1645 | ieee_write_int(abfd, public_index ); | |
1646 | ieee_write_id(abfd, p->name); | |
1647 | ||
1648 | /* Write out the value */ | |
1649 | ieee_write_2bytes(abfd, ieee_value_record_enum); | |
1650 | ieee_write_int(abfd, public_index); | |
1651 | if (p->section != (asection *)NULL) | |
1652 | { | |
1653 | ieee_write_expression(abfd, | |
1654 | p->value + p->section->output_offset, | |
1655 | p->section->output_section, | |
d0ec7a8e | 1656 | (asymbol *)NULL, false, 0); |
87f86b4e DHW |
1657 | } |
1658 | else | |
1659 | { | |
1660 | ieee_write_expression(abfd, | |
1661 | p->value, | |
1662 | (asection *)NULL, | |
d0ec7a8e | 1663 | (asymbol *)NULL, false, 0); |
87f86b4e DHW |
1664 | } |
1665 | p->value = public_index; | |
1666 | public_index++; | |
1667 | } | |
1668 | else { | |
1669 | /* This can happen - when there are gaps in the symbols read */ | |
1670 | /* from an input ieee file */ | |
1671 | } | |
1672 | } | |
1673 | } | |
1674 | ||
1675 | } | |
1676 | ||
1677 | static | |
301dfc71 SC |
1678 | void |
1679 | DEFUN(ieee_write_me_part,(abfd), | |
1680 | bfd *abfd) | |
87f86b4e DHW |
1681 | { |
1682 | ieee_data_type *ieee= ieee_data(abfd); | |
1683 | ieee->w.r.me_record = bfd_tell(abfd); | |
1684 | ||
1685 | ieee_write_2bytes(abfd, ieee_value_starting_address_enum); | |
1686 | ieee_write_int(abfd, abfd->start_address); | |
1687 | ieee_write_byte(abfd, ieee_module_end_enum); | |
1688 | ||
1689 | } | |
1690 | boolean | |
301dfc71 SC |
1691 | DEFUN(ieee_write_object_contents,(abfd), |
1692 | bfd *abfd) | |
87f86b4e DHW |
1693 | { |
1694 | ieee_data_type *ieee = ieee_data(abfd); | |
1695 | unsigned int i; | |
301dfc71 SC |
1696 | file_ptr old; |
1697 | /* Fast forward over the header area */ | |
1698 | bfd_seek(abfd, 0, 0); | |
1699 | ieee_write_byte(abfd, ieee_module_beginning_enum); | |
1700 | ||
1701 | ieee_write_id(abfd, bfd_printable_arch_mach(abfd->obj_arch, | |
1702 | abfd->obj_machine)); | |
1703 | ieee_write_id(abfd, abfd->filename); | |
1704 | ieee_write_byte(abfd, ieee_address_descriptor_enum); | |
1705 | ieee_write_byte(abfd, 8); /* Bits per MAU */ | |
1706 | ieee_write_byte(abfd, 4); /* MAU's per address */ | |
1707 | ||
1708 | /* Fast forward over the variable bits */ | |
1709 | old = bfd_tell(abfd); | |
1710 | bfd_seek(abfd, 8 * N_W_VARIABLES, 1); | |
87f86b4e | 1711 | |
87f86b4e | 1712 | /* |
301dfc71 SC |
1713 | First write the symbols, this changes their values into table |
1714 | indeces so we cant use it after this point | |
1715 | */ | |
87f86b4e DHW |
1716 | ieee_write_external_part(abfd); |
1717 | ieee_write_byte(abfd, ieee_record_seperator_enum); | |
1718 | ||
1719 | ieee_write_section_part(abfd); | |
1720 | ieee_write_byte(abfd, ieee_record_seperator_enum); | |
1721 | /* | |
301dfc71 SC |
1722 | Can only write the data once the symbols have been written since |
1723 | the data contains relocation information which points to the | |
1724 | symbols | |
1725 | */ | |
87f86b4e DHW |
1726 | ieee_write_data_part(abfd); |
1727 | ieee_write_byte(abfd, ieee_record_seperator_enum); | |
1728 | ||
1729 | /* | |
301dfc71 SC |
1730 | At the end we put the end ! |
1731 | */ | |
87f86b4e | 1732 | ieee_write_me_part(abfd); |
87f86b4e | 1733 | |
87f86b4e | 1734 | |
301dfc71 SC |
1735 | /* Generate the header */ |
1736 | bfd_seek(abfd, old, false); | |
87f86b4e DHW |
1737 | |
1738 | for (i= 0; i < N_W_VARIABLES; i++) { | |
1739 | ieee_write_2bytes(abfd,ieee_assign_value_to_variable_enum); | |
1740 | ieee_write_byte(abfd, i); | |
301dfc71 | 1741 | ieee_write_int5_out(abfd, ieee->w.offset[i]); |
87f86b4e DHW |
1742 | } |
1743 | return true; | |
1744 | } | |
1745 | ||
1746 | ||
1747 | ||
1748 | \f | |
1749 | /* Native-level interface to symbols. */ | |
1750 | ||
1751 | /* We read the symbols into a buffer, which is discarded when this | |
1752 | function exits. We read the strings into a buffer large enough to | |
1753 | hold them all plus all the cached symbol entries. */ | |
1754 | ||
1755 | asymbol * | |
301dfc71 SC |
1756 | DEFUN(ieee_make_empty_symbol,(abfd), |
1757 | bfd *abfd) | |
87f86b4e DHW |
1758 | { |
1759 | ||
1760 | ieee_symbol_type *new = | |
1761 | (ieee_symbol_type *)zalloc (sizeof (ieee_symbol_type)); | |
1762 | new->symbol.the_bfd = abfd; | |
1763 | return &new->symbol; | |
1764 | ||
1765 | } | |
1766 | ||
87f86b4e DHW |
1767 | static bfd * |
1768 | ieee_openr_next_archived_file(arch, prev) | |
1769 | bfd *arch; | |
1770 | bfd *prev; | |
1771 | { | |
1772 | ieee_ar_data_type *ar = ieee_ar_data(arch); | |
1773 | /* take the next one from the arch state, or reset */ | |
1774 | if (prev == (bfd *)NULL) { | |
1775 | /* Reset the index - the first two entries are bogus*/ | |
1776 | ar->element_index = 2; | |
1777 | } | |
1778 | while (true) { | |
1779 | ieee_ar_obstack_type *p = ar->elements + ar->element_index; | |
1780 | ar->element_index++; | |
1781 | if (ar->element_index <= ar->element_count) { | |
1782 | if (p->file_offset != (file_ptr)0) { | |
1783 | if (p->abfd == (bfd *)NULL) { | |
1784 | p->abfd = _bfd_create_empty_archive_element_shell(arch); | |
1785 | p->abfd->origin = p->file_offset; | |
1786 | } | |
1787 | return p->abfd; | |
1788 | } | |
1789 | } | |
1790 | else { | |
1791 | return (bfd *)NULL; | |
1792 | } | |
1793 | ||
1794 | } | |
1795 | } | |
1796 | ||
1797 | static boolean | |
1798 | ieee_find_nearest_line(abfd, | |
1799 | section, | |
1800 | symbols, | |
1801 | offset, | |
1802 | filename_ptr, | |
1803 | functionname_ptr, | |
1804 | line_ptr) | |
1805 | bfd *abfd; | |
1806 | asection *section; | |
1807 | asymbol **symbols; | |
1808 | bfd_vma offset; | |
1809 | char **filename_ptr; | |
1810 | char **functionname_ptr; | |
d0ec7a8e | 1811 | int *line_ptr; |
87f86b4e DHW |
1812 | { |
1813 | return false; | |
87f86b4e | 1814 | } |
301dfc71 SC |
1815 | |
1816 | ||
1817 | static int | |
9872a49c | 1818 | ieee_generic_stat_arch_elt(abfd, buf) |
301dfc71 SC |
1819 | bfd *abfd; |
1820 | struct stat *buf; | |
1821 | { | |
1822 | ieee_ar_data_type *ar = ieee_ar_data(abfd); | |
1823 | if (ar == (ieee_ar_data_type *)NULL) { | |
1824 | bfd_error = invalid_operation; | |
1825 | return -1; | |
1826 | } | |
1827 | else { | |
1828 | buf->st_size = 0x1; | |
1829 | buf->st_mode = 0666; | |
1830 | return 0; | |
1831 | } | |
1832 | } | |
39a2ce33 | 1833 | static int |
d0ec7a8e SC |
1834 | DEFUN(ieee_sizeof_headers,(abfd, x), |
1835 | bfd *abfd AND | |
1836 | boolean x) | |
39a2ce33 | 1837 | { |
d0ec7a8e | 1838 | return 0; |
39a2ce33 SC |
1839 | } |
1840 | ||
d0ec7a8e SC |
1841 | #define ieee_core_file_failing_command (char *(*)())(bfd_nullvoidptr) |
1842 | #define ieee_core_file_failing_signal (int (*)())bfd_0 | |
1843 | #define ieee_core_file_matches_executable_p ( PROTO(boolean, (*),(bfd *, bfd *)))bfd_false | |
9872a49c SC |
1844 | #define ieee_slurp_armap bfd_true |
1845 | #define ieee_slurp_extended_name_table bfd_true | |
d0ec7a8e SC |
1846 | #define ieee_truncate_arname (void (*)())bfd_nullvoidptr |
1847 | #define ieee_write_armap (PROTO( boolean, (*),(bfd *, unsigned int, struct orl *, int, int))) bfd_nullvoidptr | |
1848 | #define ieee_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr | |
2b1d8a50 | 1849 | #define ieee_close_and_cleanup bfd_generic_close_and_cleanup |
9872a49c | 1850 | |
301dfc71 | 1851 | |
87f86b4e DHW |
1852 | /*SUPPRESS 460 */ |
1853 | bfd_target ieee_vec = | |
1854 | { | |
1855 | "ieee", /* name */ | |
1856 | bfd_target_ieee_flavour_enum, | |
1857 | true, /* target byte order */ | |
1858 | true, /* target headers byte order */ | |
1859 | (HAS_RELOC | EXEC_P | /* object flags */ | |
1860 | HAS_LINENO | HAS_DEBUG | | |
1861 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), | |
f61d204a | 1862 | (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS |
87f86b4e | 1863 | |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
87f86b4e DHW |
1864 | ' ', /* ar_pad_char */ |
1865 | 16, /* ar_max_namelen */ | |
7ed4093a SC |
1866 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */ |
1867 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */ | |
87f86b4e | 1868 | |
d0ec7a8e | 1869 | { _bfd_dummy_target, |
87f86b4e DHW |
1870 | ieee_object_p, /* bfd_check_format */ |
1871 | ieee_archive_p, | |
d0ec7a8e | 1872 | _bfd_dummy_target, |
87f86b4e DHW |
1873 | }, |
1874 | { | |
1875 | bfd_false, | |
1876 | ieee_mkobject, | |
1877 | _bfd_generic_mkarchive, | |
1878 | bfd_false | |
1879 | }, | |
2b1d8a50 JG |
1880 | { |
1881 | bfd_false, | |
1882 | ieee_write_object_contents, | |
1883 | _bfd_write_archive_contents, | |
1884 | bfd_false, | |
1885 | }, | |
1886 | JUMP_TABLE(ieee) | |
87f86b4e | 1887 | }; |