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.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #define KEEPMINUSPCININST 0
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
33 #define obstack_chunk_alloc malloc
34 #define obstack_chunk_free free
36 /* Functions for writing to ieee files in the strange way that the
40 ieee_write_byte (abfd, byte)
44 if (bfd_write ((PTR) & byte, 1, 1, abfd) != 1)
49 ieee_write_twobyte (abfd, twobyte)
54 b[1] = twobyte & 0xff;
56 if (bfd_write ((PTR) & b[0], 1, 2, abfd) != 2)
61 ieee_write_2bytes (abfd, bytes)
66 buffer[0] = bytes >> 8;
67 buffer[1] = bytes & 0xff;
69 if (bfd_write ((PTR) buffer, 1, 2, abfd) != 2)
74 ieee_write_int (abfd, value)
78 if (((unsigned) value) <= 127)
80 ieee_write_byte (abfd, (bfd_byte) value);
85 /* How many significant bytes ? */
86 /* FIXME FOR LONGER INTS */
87 if (value & 0xff000000)
91 else if (value & 0x00ff0000)
95 else if (value & 0x0000ff00)
102 ieee_write_byte (abfd,
103 (bfd_byte) ((int) ieee_number_repeat_start_enum + length));
107 ieee_write_byte (abfd, (bfd_byte) (value >> 24));
109 ieee_write_byte (abfd, (bfd_byte) (value >> 16));
111 ieee_write_byte (abfd, (bfd_byte) (value >> 8));
113 ieee_write_byte (abfd, (bfd_byte) (value));
119 ieee_write_id (abfd, id)
123 size_t length = strlen (id);
126 ieee_write_byte (abfd, (bfd_byte) length);
128 else if (length < 255)
130 ieee_write_byte (abfd, ieee_extension_length_1_enum);
131 ieee_write_byte (abfd, (bfd_byte) length);
133 else if (length < 65535)
135 ieee_write_byte (abfd, ieee_extension_length_2_enum);
136 ieee_write_byte (abfd, (bfd_byte) (length >> 8));
137 ieee_write_byte (abfd, (bfd_byte) (length & 0xff));
143 if (bfd_write ((PTR) id, 1, length, abfd) != length)
148 /***************************************************************************
149 Functions for reading from ieee files in the strange way that the
153 #define this_byte(ieee) *((ieee)->input_p)
154 #define next_byte(ieee) ((ieee)->input_p++)
155 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
157 static unsigned short
159 common_header_type *ieee;
161 unsigned char c1 = this_byte_and_next (ieee);
162 unsigned char c2 = this_byte_and_next (ieee);
163 return (c1 << 8) | c2;
167 bfd_get_string (ieee, string, length)
168 common_header_type *ieee;
173 for (i = 0; i < length; i++)
175 string[i] = this_byte_and_next (ieee);
181 common_header_type *ieee;
185 length = this_byte_and_next (ieee);
188 /* Simple string of length 0 to 127 */
190 else if (length == 0xde)
192 /* Length is next byte, allowing 0..255 */
193 length = this_byte_and_next (ieee);
195 else if (length == 0xdf)
197 /* Length is next two bytes, allowing 0..65535 */
198 length = this_byte_and_next (ieee);
199 length = (length * 256) + this_byte_and_next (ieee);
201 /* Buy memory and read string */
202 string = bfd_alloc (ieee->abfd, length + 1);
205 bfd_set_error (bfd_error_no_memory);
208 bfd_get_string (ieee, string, length);
214 ieee_write_expression (abfd, value, symbol, pcrel, index)
221 unsigned int term_count = 0;
225 ieee_write_int (abfd, value);
229 if (bfd_is_com_section (symbol->section)
230 || bfd_is_und_section (symbol->section))
232 /* Def of a common symbol */
233 ieee_write_byte (abfd, ieee_variable_X_enum);
234 ieee_write_int (abfd, symbol->value);
237 else if (! bfd_is_abs_section (symbol->section))
239 /* Ref to defined symbol - */
241 ieee_write_byte (abfd, ieee_variable_R_enum);
242 ieee_write_byte (abfd,
243 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
245 if (symbol->flags & BSF_GLOBAL)
247 ieee_write_byte (abfd, ieee_variable_I_enum);
248 ieee_write_int (abfd, symbol->value);
251 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
253 /* This is a reference to a defined local symbol,
254 We can easily do a local as a section+offset */
255 ieee_write_byte (abfd, ieee_variable_R_enum); /* or L */
256 ieee_write_byte (abfd,
257 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
258 ieee_write_int (abfd, symbol->value);
269 /* subtract the pc from here by asking for PC of this section*/
270 ieee_write_byte (abfd, ieee_variable_P_enum);
271 ieee_write_byte (abfd, (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE));
272 ieee_write_byte (abfd, ieee_function_minus_enum);
277 ieee_write_byte (abfd, 0);
281 while (term_count > 1)
283 ieee_write_byte (abfd, ieee_function_plus_enum);
290 /*****************************************************************************/
293 writes any integer into the buffer supplied and always takes 5 bytes
296 ieee_write_int5 (buffer, value)
300 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
301 buffer[1] = (value >> 24) & 0xff;
302 buffer[2] = (value >> 16) & 0xff;
303 buffer[3] = (value >> 8) & 0xff;
304 buffer[4] = (value >> 0) & 0xff;
308 ieee_write_int5_out (abfd, value)
313 ieee_write_int5 (b, value);
314 if (bfd_write ((PTR) b, 1, 5, abfd) != 5)
319 parse_int (ieee, value_ptr)
320 common_header_type *ieee;
323 int value = this_byte (ieee);
325 if (value >= 0 && value <= 127)
331 else if (value >= 0x80 && value <= 0x88)
333 unsigned int count = value & 0xf;
338 result = (result << 8) | this_byte_and_next (ieee);
349 common_header_type *ieee;
353 *ok = parse_int (ieee, &x);
358 must_parse_int (ieee)
359 common_header_type *ieee;
362 BFD_ASSERT (parse_int (ieee, &result) == true);
370 ieee_symbol_index_type symbol;
375 reloc_howto_type abs32_howto
376 = HOWTO (1, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false);
378 reloc_howto_type abs16_howto
379 = HOWTO (1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false);
382 reloc_howto_type abs8_howto
383 = HOWTO (1, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false);
386 reloc_howto_type rel32_howto
387 = HOWTO (1, 0, 2, 32, true, 0, complain_overflow_signed, 0, "rel32", true, 0xffffffff,
391 reloc_howto_type rel16_howto
392 = HOWTO (1, 0, 1, 16, true, 0, complain_overflow_signed, 0, "rel16", true, 0x0000ffff, 0x0000ffff, false);
395 reloc_howto_type rel8_howto
396 = HOWTO (1, 0, 0, 8, true, 0, complain_overflow_signed, 0, "rel8", true, 0x000000ff, 0x000000ff, false);
399 static ieee_symbol_index_type NOSYMBOL =
404 parse_expression (ieee, value, symbol, pcrel, extra, section)
405 ieee_data_type *ieee;
407 ieee_symbol_index_type *symbol;
420 ieee_value_type stack[10];
422 /* The stack pointer always points to the next unused location */
423 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
424 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
425 ieee_value_type *sp = stack;
429 switch (this_byte (&(ieee->h)))
431 case ieee_variable_P_enum:
432 /* P variable, current program counter for section n */
435 next_byte (&(ieee->h));
437 section_n = must_parse_int (&(ieee->h));
438 PUSH (NOSYMBOL, bfd_abs_section_ptr,
439 TOS.value = ieee->section_table[section_n]->vma +
440 ieee_per_section (ieee->section_table[section_n])->pc);
443 case ieee_variable_L_enum:
444 /* L variable address of section N */
445 next_byte (&(ieee->h));
446 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
448 case ieee_variable_R_enum:
449 /* R variable, logical address of section module */
450 /* FIXME, this should be different to L */
451 next_byte (&(ieee->h));
452 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
454 case ieee_variable_S_enum:
455 /* S variable, size in MAUS of section module */
456 next_byte (&(ieee->h));
459 ieee->section_table[must_parse_int (&(ieee->h))]->_raw_size);
461 case ieee_variable_I_enum:
462 case ieee_variable_X_enum:
463 /* Push the address of external variable n */
465 ieee_symbol_index_type sy;
466 next_byte (&(ieee->h));
467 sy.index = (int) (must_parse_int (&(ieee->h)));
470 PUSH (sy, bfd_und_section_ptr, 0);
473 case ieee_function_minus_enum:
475 bfd_vma value1, value2;
476 asection *section1, *section_dummy;
477 ieee_symbol_index_type sy;
478 next_byte (&(ieee->h));
480 POP (sy, section1, value1);
481 POP (sy, section_dummy, value2);
482 PUSH (sy, section1 ? section1 : section_dummy, value1 - value2);
485 case ieee_function_plus_enum:
487 bfd_vma value1, value2;
490 ieee_symbol_index_type sy1;
491 ieee_symbol_index_type sy2;
492 next_byte (&(ieee->h));
494 POP (sy1, section1, value1);
495 POP (sy2, section2, value2);
496 PUSH (sy1.letter ? sy1 : sy2,
497 bfd_is_abs_section (section1) ? section2 : section1,
504 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
505 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
506 if (parse_int (&(ieee->h), &va))
508 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
513 Thats all that we can understand. As far as I can see
514 there is a bug in the Microtec IEEE output which I'm
515 using to scan, whereby the comma operator is omitted
516 sometimes in an expression, giving expressions with too
517 many terms. We can tell if that's the case by ensuring
518 that sp == stack here. If not, then we've pushed
519 something too far, so we keep adding. */
521 while (sp != stack + 1)
524 ieee_symbol_index_type sy1;
525 POP (sy1, section1, *extra);
530 POP (*symbol, dummy, *value);
543 #define ieee_seek(abfd, offset) \
544 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
546 #define ieee_pos(abfd) \
547 (IEEE_DATA(abfd)->h.input_p - IEEE_DATA(abfd)->h.first_byte)
549 static unsigned int last_index;
550 static char last_type; /* is the index for an X or a D */
552 static ieee_symbol_type *
562 ieee_data_type *ieee;
563 ieee_symbol_type *last_symbol;
564 unsigned int *symbol_count;
565 ieee_symbol_type ***pptr;
566 unsigned int *max_index;
570 /* Need a new symbol */
571 unsigned int new_index = must_parse_int (&(ieee->h));
572 if (new_index != last_index || this_type != last_type)
574 ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_alloc (ieee->h.abfd,
575 sizeof (ieee_symbol_type));
578 bfd_set_error (bfd_error_no_memory);
582 new_symbol->index = new_index;
583 last_index = new_index;
586 *pptr = &new_symbol->next;
587 if (new_index > *max_index)
589 *max_index = new_index;
591 last_type = this_type;
598 ieee_slurp_external_symbols (abfd)
601 ieee_data_type *ieee = IEEE_DATA (abfd);
602 file_ptr offset = ieee->w.r.external_part;
604 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
605 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
606 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
607 unsigned int symbol_count = 0;
609 last_index = 0xffffff;
610 ieee->symbol_table_full = true;
612 ieee_seek (abfd, offset);
616 switch (this_byte (&(ieee->h)))
619 next_byte (&(ieee->h));
621 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
623 &ieee->external_symbol_max_index, 'D');
627 symbol->symbol.the_bfd = abfd;
628 symbol->symbol.name = read_id (&(ieee->h));
629 symbol->symbol.udata.p = (PTR) NULL;
630 symbol->symbol.flags = BSF_NO_FLAGS;
632 case ieee_external_symbol_enum:
633 next_byte (&(ieee->h));
635 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
637 &ieee->external_symbol_max_index, 'D');
641 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
643 symbol->symbol.the_bfd = abfd;
644 symbol->symbol.name = read_id (&(ieee->h));
645 symbol->symbol.udata.p = (PTR) NULL;
646 symbol->symbol.flags = BSF_NO_FLAGS;
648 case ieee_attribute_record_enum >> 8:
650 unsigned int symbol_name_index;
651 unsigned int symbol_type_index;
652 unsigned int symbol_attribute_def;
654 next_byte (&(ieee->h)); /* Skip prefix */
655 next_byte (&(ieee->h));
656 symbol_name_index = must_parse_int (&(ieee->h));
657 symbol_type_index = must_parse_int (&(ieee->h));
658 symbol_attribute_def = must_parse_int (&(ieee->h));
659 switch (symbol_attribute_def)
662 /* Module misc; followed by two fields which describe the
663 current module block. The first fired is the type id
664 number, the second is the number of asn records
665 associated with the directive */
666 parse_int (&(ieee->h), &value);
667 parse_int (&(ieee->h), &value);
671 parse_int (&(ieee->h), &value);
676 case ieee_value_record_enum >> 8:
678 unsigned int symbol_name_index;
679 ieee_symbol_index_type symbol_ignore;
680 boolean pcrel_ignore;
682 next_byte (&(ieee->h));
683 next_byte (&(ieee->h));
685 symbol_name_index = must_parse_int (&(ieee->h));
686 parse_expression (ieee,
687 &symbol->symbol.value,
691 &symbol->symbol.section);
693 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
697 case ieee_weak_external_reference_enum:
701 next_byte (&(ieee->h));
702 /* Throw away the external reference index */
703 (void) must_parse_int (&(ieee->h));
704 /* Fetch the default size if not resolved */
705 size = must_parse_int (&(ieee->h));
706 /* Fetch the defautlt value if available */
707 if (parse_int (&(ieee->h), &value) == false)
711 /* This turns into a common */
712 symbol->symbol.section = bfd_com_section_ptr;
713 symbol->symbol.value = size;
717 case ieee_external_reference_enum:
718 next_byte (&(ieee->h));
720 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
722 &ieee->external_reference_max_index, 'X');
726 symbol->symbol.the_bfd = abfd;
727 symbol->symbol.name = read_id (&(ieee->h));
728 symbol->symbol.udata.p = (PTR) NULL;
729 symbol->symbol.section = bfd_und_section_ptr;
730 symbol->symbol.value = (bfd_vma) 0;
731 symbol->symbol.flags = 0;
733 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
741 if (ieee->external_symbol_max_index != 0)
743 ieee->external_symbol_count =
744 ieee->external_symbol_max_index -
745 ieee->external_symbol_min_index + 1;
749 ieee->external_symbol_count = 0;
752 if (ieee->external_reference_max_index != 0)
754 ieee->external_reference_count =
755 ieee->external_reference_max_index -
756 ieee->external_reference_min_index + 1;
760 ieee->external_reference_count = 0;
764 ieee->external_reference_count + ieee->external_symbol_count;
766 if (symbol_count != abfd->symcount)
768 /* There are gaps in the table -- */
769 ieee->symbol_table_full = false;
772 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
773 *prev_reference_ptr = (ieee_symbol_type *) NULL;
779 ieee_slurp_symbol_table (abfd)
782 if (IEEE_DATA (abfd)->read_symbols == false)
784 if (! ieee_slurp_external_symbols (abfd))
786 IEEE_DATA (abfd)->read_symbols = true;
792 ieee_get_symtab_upper_bound (abfd)
795 if (! ieee_slurp_symbol_table (abfd))
798 return (abfd->symcount != 0) ?
799 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
803 Move from our internal lists to the canon table, and insert in
807 extern const bfd_target ieee_vec;
810 ieee_get_symtab (abfd, location)
814 ieee_symbol_type *symp;
815 static bfd dummy_bfd;
816 static asymbol empty_symbol =
817 /* the_bfd, name, value, attr, section */
818 {&dummy_bfd, " ieee empty", (symvalue) 0, BSF_DEBUGGING, bfd_abs_section_ptr};
822 ieee_data_type *ieee = IEEE_DATA (abfd);
823 dummy_bfd.xvec = &ieee_vec;
824 if (! ieee_slurp_symbol_table (abfd))
827 if (ieee->symbol_table_full == false)
829 /* Arrgh - there are gaps in the table, run through and fill them */
830 /* up with pointers to a null place */
832 for (i = 0; i < abfd->symcount; i++)
834 location[i] = &empty_symbol;
838 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
839 for (symp = IEEE_DATA (abfd)->external_symbols;
840 symp != (ieee_symbol_type *) NULL;
843 /* Place into table at correct index locations */
844 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
847 /* The external refs are indexed in a bit */
848 ieee->external_reference_base_offset =
849 -ieee->external_reference_min_index + ieee->external_symbol_count;
851 for (symp = IEEE_DATA (abfd)->external_reference;
852 symp != (ieee_symbol_type *) NULL;
855 location[symp->index + ieee->external_reference_base_offset] =
862 location[abfd->symcount] = (asymbol *) NULL;
864 return abfd->symcount;
868 get_section_entry (abfd, ieee, index)
870 ieee_data_type *ieee;
873 if (ieee->section_table[index] == (asection *) NULL)
875 char *tmp = bfd_alloc (abfd, 11);
880 bfd_set_error (bfd_error_no_memory);
883 sprintf (tmp, " fsec%4d", index);
884 section = bfd_make_section (abfd, tmp);
885 ieee->section_table[index] = section;
886 section->flags = SEC_NO_FLAGS;
887 section->target_index = index;
888 ieee->section_table[index] = section;
890 return ieee->section_table[index];
894 ieee_slurp_sections (abfd)
897 ieee_data_type *ieee = IEEE_DATA (abfd);
898 file_ptr offset = ieee->w.r.section_part;
899 asection *section = (asection *) NULL;
904 bfd_byte section_type[3];
905 ieee_seek (abfd, offset);
908 switch (this_byte (&(ieee->h)))
910 case ieee_section_type_enum:
912 unsigned int section_index;
913 next_byte (&(ieee->h));
914 section_index = must_parse_int (&(ieee->h));
915 /* Fixme to be nice about a silly number of sections */
916 BFD_ASSERT (section_index < NSECTIONS);
918 section = get_section_entry (abfd, ieee, section_index);
920 section_type[0] = this_byte_and_next (&(ieee->h));
921 switch (section_type[0])
924 /* Normal attributes for absolute sections */
925 section_type[1] = this_byte (&(ieee->h));
926 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
927 switch (section_type[1])
929 case 0xD3: /* AS Absolute section attributes */
930 next_byte (&(ieee->h));
931 section_type[2] = this_byte (&(ieee->h));
932 switch (section_type[2])
936 next_byte (&(ieee->h));
937 section->flags |= SEC_LOAD | SEC_CODE;
940 next_byte (&(ieee->h));
941 section->flags |= SEC_LOAD | SEC_DATA;
945 next_byte (&(ieee->h));
946 /* Normal rom data */
947 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
954 case 0xC3: /* Named relocatable sections (type C) */
955 section_type[1] = this_byte (&(ieee->h));
956 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
957 switch (section_type[1])
959 case 0xD0: /* Normal code (CP) */
960 next_byte (&(ieee->h));
961 section->flags |= SEC_LOAD | SEC_CODE;
963 case 0xC4: /* Normal data (CD) */
964 next_byte (&(ieee->h));
965 section->flags |= SEC_LOAD | SEC_DATA;
967 case 0xD2: /* Normal rom data (CR) */
968 next_byte (&(ieee->h));
969 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
976 /* Read section name, use it if non empty. */
977 name = read_id (&ieee->h);
979 section->name = name;
981 /* Skip these fields, which we don't care about */
983 bfd_vma parent, brother, context;
984 parse_int (&(ieee->h), &parent);
985 parse_int (&(ieee->h), &brother);
986 parse_int (&(ieee->h), &context);
990 case ieee_section_alignment_enum:
992 unsigned int section_index;
995 next_byte (&(ieee->h));
996 section_index = must_parse_int (&ieee->h);
997 section = get_section_entry (abfd, ieee, section_index);
998 if (section_index > ieee->section_count)
1000 ieee->section_count = section_index;
1002 section->alignment_power =
1003 bfd_log2 (must_parse_int (&ieee->h));
1004 (void) parse_int (&(ieee->h), &value);
1007 case ieee_e2_first_byte_enum:
1009 ieee_record_enum_type t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1013 case ieee_section_size_enum:
1014 section = ieee->section_table[must_parse_int (&(ieee->h))];
1015 section->_raw_size = must_parse_int (&(ieee->h));
1017 case ieee_physical_region_size_enum:
1018 section = ieee->section_table[must_parse_int (&(ieee->h))];
1019 section->_raw_size = must_parse_int (&(ieee->h));
1021 case ieee_region_base_address_enum:
1022 section = ieee->section_table[must_parse_int (&(ieee->h))];
1023 section->vma = must_parse_int (&(ieee->h));
1025 case ieee_mau_size_enum:
1026 must_parse_int (&(ieee->h));
1027 must_parse_int (&(ieee->h));
1029 case ieee_m_value_enum:
1030 must_parse_int (&(ieee->h));
1031 must_parse_int (&(ieee->h));
1033 case ieee_section_base_address_enum:
1034 section = ieee->section_table[must_parse_int (&(ieee->h))];
1035 section->vma = must_parse_int (&(ieee->h));
1037 case ieee_section_offset_enum:
1038 (void) must_parse_int (&(ieee->h));
1039 (void) must_parse_int (&(ieee->h));
1054 /***********************************************************************
1059 ieee_archive_p (abfd)
1066 unsigned char buffer[512];
1068 file_ptr buffer_offset = 0;
1069 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1070 ieee_ar_data_type *ieee;
1071 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, sizeof (ieee_ar_data_type));
1072 if (!abfd->tdata.ieee_ar_data)
1074 bfd_set_error (bfd_error_no_memory);
1077 ieee = IEEE_AR_DATA (abfd);
1079 /* FIXME: Check return value. I'm not sure whether it needs to read
1080 the entire buffer or not. */
1081 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1083 ieee->h.first_byte = buffer;
1084 ieee->h.input_p = buffer;
1086 ieee->h.abfd = abfd;
1088 if (this_byte (&(ieee->h)) != Module_Beginning)
1090 abfd->tdata.ieee_ar_data = save;
1091 return (const bfd_target *) NULL;
1094 next_byte (&(ieee->h));
1095 library = read_id (&(ieee->h));
1096 if (strcmp (library, "LIBRARY") != 0)
1098 bfd_release (abfd, ieee);
1099 abfd->tdata.ieee_ar_data = save;
1100 return (const bfd_target *) NULL;
1102 /* Throw away the filename */
1103 read_id (&(ieee->h));
1104 /* This must be an IEEE archive, so we'll buy some space to do
1107 if (!obstack_begin (&ob, 128))
1109 bfd_set_error (bfd_error_no_memory);
1110 return (const bfd_target *) NULL;
1113 ieee->element_count = 0;
1114 ieee->element_index = 0;
1116 next_byte (&(ieee->h)); /* Drop the ad part */
1117 must_parse_int (&(ieee->h)); /* And the two dummy numbers */
1118 must_parse_int (&(ieee->h));
1121 /* Read the index of the BB table */
1124 ieee_ar_obstack_type t;
1125 int rec = read_2bytes (&(ieee->h));
1126 if (rec == (int) ieee_assign_value_to_variable_enum)
1128 must_parse_int (&(ieee->h));
1129 t.file_offset = must_parse_int (&(ieee->h));
1130 t.abfd = (bfd *) NULL;
1131 ieee->element_count++;
1133 obstack_grow (&ob, (PTR) & t, sizeof (t));
1135 /* Make sure that we don't go over the end of the buffer */
1137 if ((size_t) ieee_pos (abfd) > sizeof (buffer) / 2)
1139 /* Past half way, reseek and reprime */
1140 buffer_offset += ieee_pos (abfd);
1141 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1143 /* FIXME: Check return value. I'm not sure whether it
1144 needs to read the entire buffer or not. */
1145 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1146 ieee->h.first_byte = buffer;
1147 ieee->h.input_p = buffer;
1154 ieee->elements = (ieee_ar_obstack_type *) obstack_finish (&ob);
1155 if (!ieee->elements)
1157 bfd_set_error (bfd_error_no_memory);
1158 return (const bfd_target *) NULL;
1161 /* Now scan the area again, and replace BB offsets with file */
1164 for (i = 2; i < ieee->element_count; i++)
1166 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1168 /* FIXME: Check return value. I'm not sure whether it needs to
1169 read the entire buffer or not. */
1170 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1171 ieee->h.first_byte = buffer;
1172 ieee->h.input_p = buffer;
1174 next_byte (&(ieee->h)); /* Drop F8 */
1175 next_byte (&(ieee->h)); /* Drop 14 */
1176 must_parse_int (&(ieee->h)); /* Drop size of block */
1177 if (must_parse_int (&(ieee->h)) != 0)
1179 /* This object has been deleted */
1180 ieee->elements[i].file_offset = 0;
1184 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1188 /* abfd->has_armap = ;*/
1193 ieee_mkobject (abfd)
1196 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, sizeof (ieee_data_type));
1197 return abfd->tdata.ieee_data ? true : false;
1201 ieee_object_p (abfd)
1206 ieee_data_type *ieee;
1207 unsigned char buffer[300];
1208 ieee_data_type *save = IEEE_DATA (abfd);
1210 abfd->tdata.ieee_data = 0;
1211 ieee_mkobject (abfd);
1213 ieee = IEEE_DATA (abfd);
1214 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1216 /* Read the first few bytes in to see if it makes sense */
1217 /* FIXME: Check return value. I'm not sure whether it needs to read
1218 the entire buffer or not. */
1219 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1221 ieee->h.input_p = buffer;
1222 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1223 goto got_wrong_format;
1225 ieee->read_symbols = false;
1226 ieee->read_data = false;
1227 ieee->section_count = 0;
1228 ieee->external_symbol_max_index = 0;
1229 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1230 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1231 ieee->external_reference_max_index = 0;
1232 ieee->h.abfd = abfd;
1233 memset ((PTR) ieee->section_table, 0, sizeof (ieee->section_table));
1235 processor = ieee->mb.processor = read_id (&(ieee->h));
1236 if (strcmp (processor, "LIBRARY") == 0)
1237 goto got_wrong_format;
1238 ieee->mb.module_name = read_id (&(ieee->h));
1239 if (abfd->filename == (CONST char *) NULL)
1241 abfd->filename = ieee->mb.module_name;
1243 /* Determine the architecture and machine type of the object file.
1246 bfd_arch_info_type *arch = bfd_scan_arch (processor);
1248 goto got_wrong_format;
1249 abfd->arch_info = arch;
1252 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1256 next_byte (&(ieee->h));
1258 if (parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau) == false)
1262 if (parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address) == false)
1267 /* If there is a byte order info, take it */
1268 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum ||
1269 this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
1270 next_byte (&(ieee->h));
1272 for (part = 0; part < N_W_VARIABLES; part++)
1275 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
1279 if (this_byte_and_next (&(ieee->h)) != part)
1284 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
1291 abfd->flags = HAS_SYMS;
1292 /* By now we know that this is a real IEEE file, we're going to read
1293 the whole thing into memory so that we can run up and down it
1294 quickly. We can work out how big the file is from the trailer
1297 IEEE_DATA (abfd)->h.first_byte = (unsigned char *) bfd_alloc (ieee->h.abfd, ieee->w.r.me_record
1299 if (!IEEE_DATA (abfd)->h.first_byte)
1301 bfd_set_error (bfd_error_no_memory);
1304 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1306 /* FIXME: Check return value. I'm not sure whether it needs to read
1307 the entire buffer or not. */
1308 bfd_read ((PTR) (IEEE_DATA (abfd)->h.first_byte), 1, ieee->w.r.me_record + 50, abfd);
1310 ieee_slurp_sections (abfd);
1313 bfd_set_error (bfd_error_wrong_format);
1315 (void) bfd_release (abfd, ieee);
1316 abfd->tdata.ieee_data = save;
1317 return (const bfd_target *) NULL;
1321 ieee_get_symbol_info (ignore_abfd, symbol, ret)
1326 bfd_symbol_info (symbol, ret);
1327 if (symbol->name[0] == ' ')
1328 ret->name = "* empty table entry ";
1329 if (!symbol->section)
1330 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
1334 ieee_print_symbol (ignore_abfd, afile, symbol, how)
1338 bfd_print_symbol_type how;
1340 FILE *file = (FILE *) afile;
1344 case bfd_print_symbol_name:
1345 fprintf (file, "%s", symbol->name);
1347 case bfd_print_symbol_more:
1349 fprintf (file, "%4x %2x", aout_symbol (symbol)->desc & 0xffff,
1350 aout_symbol (symbol)->other & 0xff);
1354 case bfd_print_symbol_all:
1356 CONST char *section_name = symbol->section == (asection *) NULL ?
1357 (CONST char *) "*abs" : symbol->section->name;
1358 if (symbol->name[0] == ' ')
1360 fprintf (file, "* empty table entry ");
1364 bfd_print_symbol_vandf ((PTR) file, symbol);
1366 fprintf (file, " %-5s %04x %02x %s",
1368 (unsigned) ieee_symbol (symbol)->index,
1370 aout_symbol(symbol)->desc & 0xffff,
1371 aout_symbol(symbol)->other & 0xff,*/
1380 do_one (ieee, current_map, location_ptr, s)
1381 ieee_data_type *ieee;
1382 ieee_per_section_type *current_map;
1383 unsigned char *location_ptr;
1386 switch (this_byte (&(ieee->h)))
1388 case ieee_load_constant_bytes_enum:
1390 unsigned int number_of_maus;
1392 next_byte (&(ieee->h));
1393 number_of_maus = must_parse_int (&(ieee->h));
1395 for (i = 0; i < number_of_maus; i++)
1397 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1398 next_byte (&(ieee->h));
1403 case ieee_load_with_relocation_enum:
1405 boolean loop = true;
1406 next_byte (&(ieee->h));
1409 switch (this_byte (&(ieee->h)))
1411 case ieee_variable_R_enum:
1413 case ieee_function_signed_open_b_enum:
1414 case ieee_function_unsigned_open_b_enum:
1415 case ieee_function_either_open_b_enum:
1417 unsigned int extra = 4;
1418 boolean pcrel = false;
1420 ieee_reloc_type *r =
1421 (ieee_reloc_type *) bfd_alloc (ieee->h.abfd,
1422 sizeof (ieee_reloc_type));
1425 bfd_set_error (bfd_error_no_memory);
1429 *(current_map->reloc_tail_ptr) = r;
1430 current_map->reloc_tail_ptr = &r->next;
1431 r->next = (ieee_reloc_type *) NULL;
1432 next_byte (&(ieee->h));
1434 r->relent.sym_ptr_ptr = 0;
1435 parse_expression (ieee,
1438 &pcrel, &extra, §ion);
1439 r->relent.address = current_map->pc;
1441 if (r->relent.sym_ptr_ptr == 0)
1443 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1446 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1448 next_byte (&(ieee->h));
1449 /* Fetch number of bytes to pad */
1450 extra = must_parse_int (&(ieee->h));
1453 switch (this_byte (&(ieee->h)))
1455 case ieee_function_signed_close_b_enum:
1456 next_byte (&(ieee->h));
1458 case ieee_function_unsigned_close_b_enum:
1459 next_byte (&(ieee->h));
1461 case ieee_function_either_close_b_enum:
1462 next_byte (&(ieee->h));
1467 /* Build a relocation entry for this type */
1468 /* If pc rel then stick -ve pc into instruction
1469 and take out of reloc ..
1471 I've changed this. It's all too
1472 complicated. I keep 0 in the
1483 #if KEEPMINUSPCININST
1484 bfd_put_32 (ieee->h.abfd, -current_map->pc, location_ptr +
1486 r->relent.howto = &rel32_howto;
1490 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1492 r->relent.howto = &rel32_howto;
1497 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1499 r->relent.howto = &abs32_howto;
1501 current_map->pc += 4;
1506 #if KEEPMINUSPCININST
1507 bfd_put_16 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1508 r->relent.addend -= current_map->pc;
1509 r->relent.howto = &rel16_howto;
1512 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1513 r->relent.howto = &rel16_howto;
1519 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1520 r->relent.howto = &abs16_howto;
1522 current_map->pc += 2;
1527 #if KEEPMINUSPCININST
1528 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1529 r->relent.addend -= current_map->pc;
1530 r->relent.howto = &rel8_howto;
1532 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1533 r->relent.howto = &rel8_howto;
1538 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1539 r->relent.howto = &abs8_howto;
1541 current_map->pc += 1;
1553 if (parse_int (&(ieee->h), &this_size) == true)
1556 for (i = 0; i < this_size; i++)
1558 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1559 next_byte (&(ieee->h));
1574 /* Read in all the section data and relocation stuff too */
1576 ieee_slurp_section_data (abfd)
1579 bfd_byte *location_ptr = (bfd_byte *) NULL;
1580 ieee_data_type *ieee = IEEE_DATA (abfd);
1581 unsigned int section_number;
1583 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
1585 /* Seek to the start of the data area */
1586 if (ieee->read_data == true)
1588 ieee->read_data = true;
1589 ieee_seek (abfd, ieee->w.r.data_part);
1591 /* Allocate enough space for all the section contents */
1593 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1595 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1596 per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->_raw_size);
1599 bfd_set_error (bfd_error_no_memory);
1603 per->reloc_tail_ptr =
1604 (ieee_reloc_type **) & (s->relocation);
1609 switch (this_byte (&(ieee->h)))
1611 /* IF we see anything strange then quit */
1615 case ieee_set_current_section_enum:
1616 next_byte (&(ieee->h));
1617 section_number = must_parse_int (&(ieee->h));
1618 s = ieee->section_table[section_number];
1619 current_map = (ieee_per_section_type *) s->used_by_bfd;
1620 location_ptr = current_map->data - s->vma;
1621 /* The document I have says that Microtec's compilers reset */
1622 /* this after a sec section, even though the standard says not */
1624 current_map->pc = s->vma;
1627 case ieee_e2_first_byte_enum:
1628 next_byte (&(ieee->h));
1629 switch (this_byte (&(ieee->h)))
1631 case ieee_set_current_pc_enum & 0xff:
1634 ieee_symbol_index_type symbol;
1637 next_byte (&(ieee->h));
1638 must_parse_int (&(ieee->h)); /* Thow away section #*/
1639 parse_expression (ieee, &value,
1643 current_map->pc = value;
1644 BFD_ASSERT ((unsigned) (value - s->vma) <= s->_raw_size);
1648 case ieee_value_starting_address_enum & 0xff:
1649 /* We've got to the end of the data now - */
1656 case ieee_repeat_data_enum:
1658 /* Repeat the following LD or LR n times - we do this by
1659 remembering the stream pointer before running it and
1660 resetting it and running it n times. We special case
1661 the repetition of a repeat_data/load_constant
1664 unsigned int iterations;
1665 unsigned char *start;
1666 next_byte (&(ieee->h));
1667 iterations = must_parse_int (&(ieee->h));
1668 start = ieee->h.input_p;
1669 if (start[0] == (int) ieee_load_constant_bytes_enum &&
1672 while (iterations != 0)
1674 location_ptr[current_map->pc++] = start[2];
1677 next_byte (&(ieee->h));
1678 next_byte (&(ieee->h));
1679 next_byte (&(ieee->h));
1683 while (iterations != 0)
1685 ieee->h.input_p = start;
1686 if (!do_one (ieee, current_map, location_ptr, s))
1693 case ieee_load_constant_bytes_enum:
1694 case ieee_load_with_relocation_enum:
1696 if (!do_one (ieee, current_map, location_ptr, s))
1704 ieee_new_section_hook (abfd, newsect)
1708 newsect->used_by_bfd = (PTR)
1709 bfd_alloc (abfd, sizeof (ieee_per_section_type));
1710 if (!newsect->used_by_bfd)
1712 bfd_set_error (bfd_error_no_memory);
1715 ieee_per_section (newsect)->data = (bfd_byte *) NULL;
1716 ieee_per_section (newsect)->section = newsect;
1721 ieee_get_reloc_upper_bound (abfd, asect)
1725 if (! ieee_slurp_section_data (abfd))
1727 return (asect->reloc_count + 1) * sizeof (arelent *);
1731 ieee_get_section_contents (abfd, section, location, offset, count)
1736 bfd_size_type count;
1738 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1739 ieee_slurp_section_data (abfd);
1740 (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
1745 ieee_canonicalize_reloc (abfd, section, relptr, symbols)
1751 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1752 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
1753 ieee_data_type *ieee = IEEE_DATA (abfd);
1755 while (src != (ieee_reloc_type *) NULL)
1757 /* Work out which symbol to attach it this reloc to */
1758 switch (src->symbol.letter)
1761 src->relent.sym_ptr_ptr =
1762 symbols + src->symbol.index + ieee->external_reference_base_offset;
1765 src->relent.sym_ptr_ptr =
1766 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
1772 *relptr++ = &src->relent;
1775 *relptr = (arelent *) NULL;
1776 return section->reloc_count;
1784 arelent *a = *((arelent **) ap);
1785 arelent *b = *((arelent **) bp);
1786 return a->address - b->address;
1790 Write the section headers
1794 ieee_write_section_part (abfd)
1797 ieee_data_type *ieee = IEEE_DATA (abfd);
1799 ieee->w.r.section_part = bfd_tell (abfd);
1800 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1802 if (! bfd_is_abs_section (s))
1804 ieee_write_byte (abfd, ieee_section_type_enum);
1805 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1807 if (abfd->flags & EXEC_P)
1809 /* This image is executable, so output absolute sections */
1810 ieee_write_byte (abfd, ieee_variable_A_enum);
1811 ieee_write_byte (abfd, ieee_variable_S_enum);
1815 ieee_write_byte (abfd, ieee_variable_C_enum);
1818 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
1820 case SEC_CODE | SEC_LOAD:
1822 ieee_write_byte (abfd, ieee_variable_P_enum);
1826 ieee_write_byte (abfd, ieee_variable_D_enum);
1829 case SEC_ROM | SEC_DATA:
1830 case SEC_ROM | SEC_LOAD:
1831 case SEC_ROM | SEC_DATA | SEC_LOAD:
1833 ieee_write_byte (abfd, ieee_variable_R_enum);
1837 ieee_write_id (abfd, s->name);
1839 ieee_write_int (abfd, 0); /* Parent */
1840 ieee_write_int (abfd, 0); /* Brother */
1841 ieee_write_int (abfd, 0); /* Context */
1844 ieee_write_byte (abfd, ieee_section_alignment_enum);
1845 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1846 ieee_write_int (abfd, 1 << s->alignment_power);
1849 ieee_write_2bytes (abfd, ieee_section_size_enum);
1850 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1851 ieee_write_int (abfd, s->_raw_size);
1852 if (abfd->flags & EXEC_P)
1854 /* Relocateable sections don't have asl records */
1856 ieee_write_2bytes (abfd, ieee_section_base_address_enum);
1857 ieee_write_byte (abfd,
1858 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1859 ieee_write_int (abfd, s->vma);
1868 do_with_relocs (abfd, s)
1872 unsigned int relocs_to_go = s->reloc_count;
1874 bfd_byte *stream = ieee_per_section (s)->data;
1875 arelent **p = s->orelocation;
1877 bfd_size_type current_byte_index = 0;
1879 qsort (s->orelocation,
1881 sizeof (arelent **),
1884 /* Output the section preheader */
1885 ieee_write_byte (abfd, ieee_set_current_section_enum);
1886 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1888 ieee_write_twobyte (abfd, ieee_set_current_pc_enum);
1889 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1890 ieee_write_expression (abfd, 0, s->symbol, 0, 0);
1892 if (relocs_to_go == 0)
1894 /* If there arn't any relocations then output the load constant byte
1895 opcode rather than the load with relocation opcode */
1897 while (current_byte_index < s->_raw_size)
1900 unsigned int MAXRUN = 32;
1902 if (run > s->_raw_size - current_byte_index)
1904 run = s->_raw_size - current_byte_index;
1909 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
1910 /* Output a stream of bytes */
1911 ieee_write_int (abfd, run);
1912 if (bfd_write ((PTR) (stream + current_byte_index),
1918 current_byte_index += run;
1924 ieee_write_byte (abfd, ieee_load_with_relocation_enum);
1927 /* Output the data stream as the longest sequence of bytes
1928 possible, allowing for the a reasonable packet size and
1929 relocation stuffs */
1931 if ((PTR) stream == (PTR) NULL)
1933 /* Outputting a section without data, fill it up */
1934 stream = (unsigned char *) (bfd_alloc (abfd, s->_raw_size));
1937 bfd_set_error (bfd_error_no_memory);
1940 memset ((PTR) stream, 0, (size_t) s->_raw_size);
1942 while (current_byte_index < s->_raw_size)
1945 unsigned int MAXRUN = 32;
1948 run = (*p)->address - current_byte_index;
1954 if (run > s->_raw_size - current_byte_index)
1956 run = s->_raw_size - current_byte_index;
1961 /* Output a stream of bytes */
1962 ieee_write_int (abfd, run);
1963 if (bfd_write ((PTR) (stream + current_byte_index),
1969 current_byte_index += run;
1971 /* Output any relocations here */
1972 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1974 while (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1981 if (r->howto->pc_relative)
1983 r->addend += current_byte_index;
1987 switch (r->howto->size)
1991 ov = bfd_get_32 (abfd,
1992 stream + current_byte_index);
1993 current_byte_index += 4;
1996 ov = bfd_get_16 (abfd,
1997 stream + current_byte_index);
1998 current_byte_index += 2;
2001 ov = bfd_get_8 (abfd,
2002 stream + current_byte_index);
2003 current_byte_index++;
2009 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
2012 if (r->sym_ptr_ptr != (asymbol **) NULL)
2014 ieee_write_expression (abfd, r->addend + ov,
2016 r->howto->pc_relative, s->index);
2020 ieee_write_expression (abfd, r->addend + ov,
2022 r->howto->pc_relative, s->index);
2025 if (1 || r->howto->size != 2)
2027 ieee_write_byte (abfd, ieee_comma);
2028 ieee_write_int (abfd, 1 << r->howto->size);
2030 ieee_write_byte (abfd,
2031 ieee_function_either_close_b_enum);
2043 /* If there are no relocations in the output section then we can
2044 be clever about how we write. We block items up into a max of 127
2048 do_as_repeat (abfd, s)
2054 ieee_write_byte (abfd, ieee_set_current_section_enum);
2055 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2056 ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8);
2057 ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff);
2058 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2059 ieee_write_int (abfd, s->vma);
2061 ieee_write_byte (abfd, ieee_repeat_data_enum);
2062 ieee_write_int (abfd, s->_raw_size);
2063 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
2064 ieee_write_byte (abfd, 1);
2065 ieee_write_byte (abfd, 0);
2070 do_without_relocs (abfd, s)
2074 bfd_byte *stream = ieee_per_section (s)->data;
2076 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2078 do_as_repeat (abfd, s);
2083 for (i = 0; i < s->_raw_size; i++)
2087 do_with_relocs (abfd, s);
2091 do_as_repeat (abfd, s);
2097 static unsigned char *output_ptr_start;
2098 static unsigned char *output_ptr;
2099 static unsigned char *output_ptr_end;
2100 static unsigned char *input_ptr_start;
2101 static unsigned char *input_ptr;
2102 static unsigned char *input_ptr_end;
2103 static bfd *input_bfd;
2104 static bfd *output_bfd;
2105 static int output_buffer;
2110 /* FIXME: Check return value. I'm not sure whether it needs to read
2111 the entire buffer or not. */
2112 bfd_read ((PTR) input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
2113 input_ptr = input_ptr_start;
2118 if (bfd_write ((PTR) (output_ptr_start), 1, output_ptr - output_ptr_start,
2120 != (bfd_size_type) (output_ptr - output_ptr_start))
2122 output_ptr = output_ptr_start;
2126 #define THIS() ( *input_ptr )
2127 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2128 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2134 if (value >= 0 && value <= 127)
2140 unsigned int length;
2141 /* How many significant bytes ? */
2142 /* FIXME FOR LONGER INTS */
2143 if (value & 0xff000000)
2147 else if (value & 0x00ff0000)
2151 else if (value & 0x0000ff00)
2158 OUT ((int) ieee_number_repeat_start_enum + length);
2177 int length = THIS ();
2189 #define VAR(x) ((x | 0x80))
2204 value = (value << 8) | THIS ();
2206 value = (value << 8) | THIS ();
2208 value = (value << 8) | THIS ();
2216 value = (value << 8) | THIS ();
2218 value = (value << 8) | THIS ();
2226 value = (value << 8) | THIS ();
2243 /* Not a number, just bug out with the answer */
2244 write_int (*(--tos));
2254 int value = *(--tos);
2263 ieee_data_type *ieee;
2266 section_number = THIS ();
2269 ieee = IEEE_DATA (input_bfd);
2270 s = ieee->section_table[section_number];
2271 if (s->output_section)
2273 value = s->output_section->vma;
2279 value += s->output_offset;
2287 write_int (*(--tos));
2297 /* Drop the int in the buffer, and copy a null into the gap, which we
2298 will overwrite later */
2300 struct output_buffer_struct
2302 unsigned char *ptrp;
2308 struct output_buffer_struct *buf;
2310 if (buf->buffer == output_buffer)
2312 /* Still a chance to output the size */
2313 int value = output_ptr - buf->ptrp + 3;
2314 buf->ptrp[0] = value >> 24;
2315 buf->ptrp[1] = value >> 16;
2316 buf->ptrp[2] = value >> 8;
2317 buf->ptrp[3] = value >> 0;
2323 struct output_buffer_struct *buf;
2349 buf->ptrp = output_ptr;
2350 buf->buffer = output_buffer;
2390 #define ID copy_id()
2391 #define INT copy_int()
2392 #define EXP copy_expression()
2393 static void copy_till_end ();
2394 #define INTn(q) copy_int()
2395 #define EXPn(q) copy_expression()
2434 EXPn (instruction address);
2468 EXPn (external function);
2478 INTn (locked register);
2501 /* Attribute record */
2559 static void block ();
2571 /* Unique typedefs for module */
2572 /* GLobal typedefs */
2573 /* High level module scope beginning */
2575 struct output_buffer_struct ob;
2590 /* Global function */
2592 struct output_buffer_struct ob;
2606 EXPn (size of block);
2612 /* File name for source line numbers */
2614 struct output_buffer_struct ob;
2634 /* Local function */
2636 struct output_buffer_struct ob;
2654 /* Assembler module scope beginning -*/
2656 struct output_buffer_struct ob;
2682 struct output_buffer_struct ob;
2689 INTn (section index);
2697 EXPn (Size in Maus);
2752 moves all the debug information from the source bfd to the output
2753 bfd, and relocates any expressions it finds
2757 relocate_debug (output, input)
2763 unsigned char input_buffer[IBS];
2765 input_ptr_start = input_ptr = input_buffer;
2766 input_ptr_end = input_buffer + IBS;
2768 /* FIXME: Check return value. I'm not sure whether it needs to read
2769 the entire buffer or not. */
2770 bfd_read ((PTR) input_ptr_start, 1, IBS, input);
2775 During linking, we we told about the bfds which made up our
2776 contents, we have a list of them. They will still be open, so go to
2777 the debug info in each, and copy it out, relocating it as we go.
2781 ieee_write_debug_part (abfd)
2784 ieee_data_type *ieee = IEEE_DATA (abfd);
2785 bfd_chain_type *chain = ieee->chain_root;
2786 unsigned char output_buffer[OBS];
2787 boolean some_debug = false;
2788 file_ptr here = bfd_tell (abfd);
2790 output_ptr_start = output_ptr = output_buffer;
2791 output_ptr_end = output_buffer + OBS;
2792 output_ptr = output_buffer;
2795 if (chain == (bfd_chain_type *) NULL)
2798 /* There is no debug info, so we'll fake some up */
2799 CONST static char fake[] =
2801 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
2802 '1', '.', '1', 0x82, 1991 >> 8, 1991 & 0xff, 9, 20, 11, 07, 50};
2803 ieee->w.r.debug_information_part = 0;
2809 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2810 /* Now write a header for each section */
2813 asection *s = abfd->sections;
2816 if (s != abfd->abs_section)
2819 ieee_write_byte (abfd, 0xf8);
2820 ieee_write_byte (abfd, 0x0b);
2821 ieee_write_byte (abfd, 0);
2822 ieee_write_byte (abfd, 0);
2823 ieee_write_byte (abfd, 1);
2824 ieee_write_byte (abfd, i + IEEE_SECTION_NUMBER_BASE);
2825 ieee_write_expression (abfd, 0, s->symbol, 0, 0, 0);
2826 ieee_write_byte (abfd, 0);
2827 ieee_write_byte (abfd, 0xf9);
2828 ieee_write_expression (abfd, s->size,
2829 bfd_abs_section_ptr->symbol, 0, 0, 0);
2836 /* Close the scope */
2837 ieee_write_byte (abfd, 0xf9);
2843 while (chain != (bfd_chain_type *) NULL)
2845 bfd *entry = chain->this;
2846 ieee_data_type *entry_ieee = IEEE_DATA (entry);
2847 if (entry_ieee->w.r.debug_information_part)
2849 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
2853 relocate_debug (abfd, entry);
2856 chain = chain->next;
2860 ieee->w.r.debug_information_part = here;
2864 ieee->w.r.debug_information_part = 0;
2871 /* write the data in an ieee way */
2873 ieee_write_data_part (abfd)
2877 ieee_data_type *ieee = IEEE_DATA (abfd);
2878 ieee->w.r.data_part = bfd_tell (abfd);
2879 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2881 /* Sort the reloc records so we can insert them in the correct
2883 if (s->reloc_count != 0)
2885 do_with_relocs (abfd, s);
2889 do_without_relocs (abfd, s);
2896 init_for_output (abfd)
2900 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2902 if (s->_raw_size != 0)
2904 ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, s->_raw_size));
2905 if (!ieee_per_section (s)->data)
2907 bfd_set_error (bfd_error_no_memory);
2915 /** exec and core file sections */
2917 /* set section contents is complicated with IEEE since the format is
2918 * not a byte image, but a record stream.
2921 ieee_set_section_contents (abfd, section, location, offset, count)
2926 bfd_size_type count;
2928 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
2930 if (!init_for_output (abfd))
2933 memcpy ((PTR) (ieee_per_section (section)->data + offset),
2935 (unsigned int) count);
2940 write the external symbols of a file, IEEE considers two sorts of
2941 external symbols, public, and referenced. It uses to internal forms
2942 to index them as well. When we write them out we turn their symbol
2943 values into indexes from the right base.
2946 ieee_write_external_part (abfd)
2950 ieee_data_type *ieee = IEEE_DATA (abfd);
2952 unsigned int reference_index = IEEE_REFERENCE_BASE;
2953 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
2954 file_ptr here = bfd_tell (abfd);
2955 boolean hadone = false;
2956 if (abfd->outsymbols != (asymbol **) NULL)
2959 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
2963 if (bfd_is_und_section (p->section))
2965 /* This must be a symbol reference .. */
2966 ieee_write_byte (abfd, ieee_external_reference_enum);
2967 ieee_write_int (abfd, reference_index);
2968 ieee_write_id (abfd, p->name);
2969 p->value = reference_index;
2972 else if (bfd_is_com_section (p->section))
2974 /* This is a weak reference */
2975 ieee_write_byte (abfd, ieee_external_reference_enum);
2976 ieee_write_int (abfd, reference_index);
2977 ieee_write_id (abfd, p->name);
2978 ieee_write_byte (abfd, ieee_weak_external_reference_enum);
2979 ieee_write_int (abfd, reference_index);
2980 ieee_write_int (abfd, p->value);
2981 ieee_write_int (abfd, BFD_FORT_COMM_DEFAULT_VALUE);
2982 p->value = reference_index;
2985 else if (p->flags & BSF_GLOBAL)
2987 /* This must be a symbol definition */
2990 ieee_write_byte (abfd, ieee_external_symbol_enum);
2991 ieee_write_int (abfd, public_index);
2992 ieee_write_id (abfd, p->name);
2994 ieee_write_twobyte (abfd, ieee_attribute_record_enum);
2995 ieee_write_int (abfd, public_index);
2996 ieee_write_byte (abfd, 15); /* instruction address */
2997 ieee_write_byte (abfd, 19); /* static symbol */
2998 ieee_write_byte (abfd, 1); /* one of them */
3001 /* Write out the value */
3002 ieee_write_2bytes (abfd, ieee_value_record_enum);
3003 ieee_write_int (abfd, public_index);
3004 if (! bfd_is_abs_section (p->section))
3006 if (abfd->flags & EXEC_P)
3008 /* If fully linked, then output all symbols
3010 ieee_write_int (abfd,
3011 p->value + p->section->output_offset + p->section->output_section->vma);
3016 ieee_write_expression (abfd,
3017 p->value + p->section->output_offset,
3018 p->section->output_section->symbol
3024 ieee_write_expression (abfd,
3026 bfd_abs_section_ptr->symbol,
3029 p->value = public_index;
3034 /* This can happen - when there are gaps in the symbols read */
3035 /* from an input ieee file */
3040 ieee->w.r.external_part = here;
3045 static CONST unsigned char exten[] =
3048 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3049 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3050 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3053 static CONST unsigned char envi[] =
3057 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3060 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3062 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3063 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3068 ieee_write_me_part (abfd)
3071 ieee_data_type *ieee = IEEE_DATA (abfd);
3072 ieee->w.r.trailer_part = bfd_tell (abfd);
3073 if (abfd->start_address)
3075 ieee->w.r.me_record = bfd_tell (abfd);
3076 ieee_write_2bytes (abfd, ieee_value_starting_address_enum);
3077 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
3078 ieee_write_int (abfd, abfd->start_address);
3079 ieee_write_byte (abfd, ieee_function_either_close_b_enum);
3083 ieee->w.r.me_record = bfd_tell (abfd);
3085 ieee_write_byte (abfd, ieee_module_end_enum);
3090 ieee_write_object_contents (abfd)
3093 ieee_data_type *ieee = IEEE_DATA (abfd);
3096 /* Fast forward over the header area */
3097 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3099 ieee_write_byte (abfd, ieee_module_beginning_enum);
3101 ieee_write_id (abfd, bfd_printable_name (abfd));
3102 ieee_write_id (abfd, abfd->filename);
3104 /* Fast forward over the variable bits */
3105 ieee_write_byte (abfd, ieee_address_descriptor_enum);
3108 ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd)));
3109 /* MAU's per address */
3110 ieee_write_byte (abfd,
3111 (bfd_byte) (bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd)));
3113 old = bfd_tell (abfd);
3114 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3117 ieee->w.r.extension_record = bfd_tell (abfd);
3118 if (bfd_write ((char *) exten, 1, sizeof (exten), abfd) != sizeof (exten))
3120 if (abfd->flags & EXEC_P)
3121 ieee_write_byte (abfd, 0x1);/* Absolute */
3123 ieee_write_byte (abfd, 0x2);/* Relocateable */
3125 ieee->w.r.environmental_record = bfd_tell (abfd);
3126 if (bfd_write ((char *) envi, 1, sizeof (envi), abfd) != sizeof (envi))
3131 ieee_write_section_part (abfd);
3133 First write the symbols, this changes their values into table
3134 indeces so we cant use it after this point
3136 ieee_write_external_part (abfd);
3137 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3140 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3144 Write any debugs we have been told about
3146 ieee_write_debug_part (abfd);
3149 Can only write the data once the symbols have been written since
3150 the data contains relocation information which points to the
3153 ieee_write_data_part (abfd);
3157 At the end we put the end !
3159 ieee_write_me_part (abfd);
3162 /* Generate the header */
3163 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3166 for (i = 0; i < N_W_VARIABLES; i++)
3168 ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum);
3169 ieee_write_byte (abfd, (bfd_byte) i);
3170 ieee_write_int5_out (abfd, ieee->w.offset[i]);
3177 /* Native-level interface to symbols. */
3179 /* We read the symbols into a buffer, which is discarded when this
3180 function exits. We read the strings into a buffer large enough to
3181 hold them all plus all the cached symbol entries. */
3184 ieee_make_empty_symbol (abfd)
3188 ieee_symbol_type *new =
3189 (ieee_symbol_type *) bfd_zmalloc (sizeof (ieee_symbol_type));
3192 bfd_set_error (bfd_error_no_error);
3195 new->symbol.the_bfd = abfd;
3196 return &new->symbol;
3200 ieee_openr_next_archived_file (arch, prev)
3204 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3205 /* take the next one from the arch state, or reset */
3206 if (prev == (bfd *) NULL)
3208 /* Reset the index - the first two entries are bogus*/
3209 ar->element_index = 2;
3213 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3214 ar->element_index++;
3215 if (ar->element_index <= ar->element_count)
3217 if (p->file_offset != (file_ptr) 0)
3219 if (p->abfd == (bfd *) NULL)
3221 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3222 p->abfd->origin = p->file_offset;
3229 bfd_set_error (bfd_error_no_more_archived_files);
3230 return (bfd *) NULL;
3237 ieee_find_nearest_line (abfd,
3248 char **filename_ptr;
3249 char **functionname_ptr;
3256 ieee_generic_stat_arch_elt (abfd, buf)
3260 ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
3261 if (ar == (ieee_ar_data_type *) NULL)
3263 bfd_set_error (bfd_error_invalid_operation);
3269 buf->st_mode = 0666;
3270 return !ieee_object_p (abfd);
3275 ieee_sizeof_headers (abfd, x)
3283 /* The debug info routines are never used. */
3287 ieee_bfd_debug_info_start (abfd)
3294 ieee_bfd_debug_info_end (abfd)
3301 /* Add this section to the list of sections we have debug info for, to
3302 be ready to output it at close time
3305 ieee_bfd_debug_info_accumulate (abfd, section)
3309 ieee_data_type *ieee = IEEE_DATA (section->owner);
3310 ieee_data_type *output_ieee = IEEE_DATA (abfd);
3311 /* can only accumulate data from other ieee bfds */
3312 if (section->owner->xvec != abfd->xvec)
3314 /* Only bother once per bfd */
3315 if (ieee->done_debug == true)
3317 ieee->done_debug = true;
3319 /* Don't bother if there is no debug info */
3320 if (ieee->w.r.debug_information_part == 0)
3326 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc (abfd, sizeof (bfd_chain_type));
3329 bfd_set_error (bfd_error_no_memory);
3330 abort (); /* FIXME */
3332 n->this = section->owner;
3333 n->next = (bfd_chain_type *) NULL;
3335 if (output_ieee->chain_head)
3337 output_ieee->chain_head->next = n;
3341 output_ieee->chain_root = n;
3344 output_ieee->chain_head = n;
3350 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3351 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3353 #define ieee_slurp_armap bfd_true
3354 #define ieee_slurp_extended_name_table bfd_true
3355 #define ieee_construct_extended_name_table \
3356 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
3358 #define ieee_truncate_arname bfd_dont_truncate_arname
3359 #define ieee_write_armap \
3361 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3363 #define ieee_update_armap_timestamp bfd_true
3365 #define ieee_bfd_is_local_label bfd_generic_is_local_label
3366 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3367 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3368 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3369 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3371 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3373 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3375 #define ieee_bfd_get_relocated_section_contents \
3376 bfd_generic_get_relocated_section_contents
3377 #define ieee_bfd_relax_section bfd_generic_relax_section
3378 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3379 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3380 #define ieee_bfd_final_link _bfd_generic_final_link
3381 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3384 const bfd_target ieee_vec =
3387 bfd_target_ieee_flavour,
3388 true, /* target byte order */
3389 true, /* target headers byte order */
3390 (HAS_RELOC | EXEC_P | /* object flags */
3391 HAS_LINENO | HAS_DEBUG |
3392 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3393 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3394 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3395 0, /* leading underscore */
3396 ' ', /* ar_pad_char */
3397 16, /* ar_max_namelen */
3398 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3399 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3400 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3401 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3402 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3403 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3406 ieee_object_p, /* bfd_check_format */
3413 _bfd_generic_mkarchive,
3418 ieee_write_object_contents,
3419 _bfd_write_archive_contents,
3423 BFD_JUMP_TABLE_GENERIC (ieee),
3424 BFD_JUMP_TABLE_COPY (_bfd_generic),
3425 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3426 BFD_JUMP_TABLE_ARCHIVE (ieee),
3427 BFD_JUMP_TABLE_SYMBOLS (ieee),
3428 BFD_JUMP_TABLE_RELOCS (ieee),
3429 BFD_JUMP_TABLE_WRITE (ieee),
3430 BFD_JUMP_TABLE_LINK (ieee),
3431 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),