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