1 /* BFD back-end for ieee-695 objects.
2 Copyright (C) 1990-2016 Free Software Foundation, Inc.
4 Written by Steve Chamberlain of Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
24 #define KEEPMINUSPCININST 0
26 /* IEEE 695 format is a stream of records, which we parse using a simple one-
27 token (which is one byte in this lexicon) lookahead recursive decent
35 #include "safe-ctype.h"
36 #include "libiberty.h"
38 struct output_buffer_struct
44 static unsigned char *output_ptr_start;
45 static unsigned char *output_ptr;
46 static unsigned char *output_ptr_end;
47 static unsigned char *input_ptr_start;
48 static unsigned char *input_ptr;
49 static unsigned char *input_ptr_end;
50 static bfd *input_bfd;
51 static bfd *output_bfd;
52 static int output_buffer;
55 static void block (void);
57 /* Functions for writing to ieee files in the strange way that the
61 ieee_write_byte (bfd *abfd, int barg)
66 if (bfd_bwrite ((void *) &byte, (bfd_size_type) 1, abfd) != 1)
72 ieee_write_2bytes (bfd *abfd, int bytes)
76 buffer[0] = bytes >> 8;
77 buffer[1] = bytes & 0xff;
78 if (bfd_bwrite ((void *) buffer, (bfd_size_type) 2, abfd) != 2)
84 ieee_write_int (bfd *abfd, bfd_vma value)
88 if (! ieee_write_byte (abfd, (bfd_byte) value))
95 /* How many significant bytes ? */
96 /* FIXME FOR LONGER INTS. */
97 if (value & 0xff000000)
99 else if (value & 0x00ff0000)
101 else if (value & 0x0000ff00)
106 if (! ieee_write_byte (abfd,
107 (bfd_byte) ((int) ieee_number_repeat_start_enum
113 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))
117 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))
121 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))
125 if (! ieee_write_byte (abfd, (bfd_byte) (value)))
134 ieee_write_id (bfd *abfd, const char *id)
136 size_t length = strlen (id);
140 if (! ieee_write_byte (abfd, (bfd_byte) length))
143 else if (length < 255)
145 if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)
146 || ! ieee_write_byte (abfd, (bfd_byte) length))
149 else if (length < 65535)
151 if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)
152 || ! ieee_write_2bytes (abfd, (int) length))
158 /* xgettext:c-format */
159 (_("%s: string too long (%d chars, max 65535)"),
160 bfd_get_filename (abfd), length);
161 bfd_set_error (bfd_error_invalid_operation);
165 if (bfd_bwrite ((void *) id, (bfd_size_type) length, abfd) != length)
170 /* Functions for reading from ieee files in the strange way that the
171 standard requires. */
173 #define this_byte(ieee) *((ieee)->input_p)
174 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
177 next_byte (common_header_type * ieee)
181 return ieee->input_p < ieee->last_byte;
184 static unsigned short
185 read_2bytes (common_header_type *ieee)
187 unsigned char c1 = this_byte_and_next (ieee);
188 unsigned char c2 = this_byte_and_next (ieee);
190 return (c1 << 8) | c2;
194 bfd_get_string (common_header_type *ieee, char *string, size_t length)
198 for (i = 0; i < length; i++)
199 string[i] = this_byte_and_next (ieee);
203 read_id (common_header_type *ieee)
208 length = this_byte_and_next (ieee);
210 /* Simple string of length 0 to 127. */
213 else if (length == 0xde)
214 /* Length is next byte, allowing 0..255. */
215 length = this_byte_and_next (ieee);
217 else if (length == 0xdf)
219 /* Length is next two bytes, allowing 0..65535. */
220 length = this_byte_and_next (ieee);
221 length = (length * 256) + this_byte_and_next (ieee);
224 /* Buy memory and read string. */
225 string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
228 bfd_get_string (ieee, string, length);
234 ieee_write_expression (bfd *abfd,
240 unsigned int term_count = 0;
244 if (! ieee_write_int (abfd, value))
249 /* Badly formatted binaries can have a missing symbol,
250 so test here to prevent a seg fault. */
253 if (bfd_is_com_section (symbol->section)
254 || bfd_is_und_section (symbol->section))
256 /* Def of a common symbol. */
257 if (! ieee_write_byte (abfd, ieee_variable_X_enum)
258 || ! ieee_write_int (abfd, symbol->value))
262 else if (! bfd_is_abs_section (symbol->section))
264 /* Ref to defined symbol - */
265 if (symbol->flags & BSF_GLOBAL)
267 if (! ieee_write_byte (abfd, ieee_variable_I_enum)
268 || ! ieee_write_int (abfd, symbol->value))
272 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
274 /* This is a reference to a defined local symbol. We can
275 easily do a local as a section+offset. */
276 if (! ieee_write_byte (abfd, ieee_variable_R_enum)
277 || ! ieee_write_byte (abfd,
278 (bfd_byte) (symbol->section->index
279 + IEEE_SECTION_NUMBER_BASE)))
283 if (symbol->value != 0)
285 if (! ieee_write_int (abfd, symbol->value))
293 /* xgettext:c-format */
294 (_("%s: unrecognized symbol `%s' flags 0x%x"),
295 bfd_get_filename (abfd), bfd_asymbol_name (symbol),
297 bfd_set_error (bfd_error_invalid_operation);
305 /* Subtract the pc from here by asking for PC of this section. */
306 if (! ieee_write_byte (abfd, ieee_variable_P_enum)
307 || ! ieee_write_byte (abfd,
308 (bfd_byte) (sindex + IEEE_SECTION_NUMBER_BASE))
309 || ! ieee_write_byte (abfd, ieee_function_minus_enum))
313 /* Handle the degenerate case of a 0 address. */
315 if (! ieee_write_int (abfd, (bfd_vma) 0))
318 while (term_count > 1)
320 if (! ieee_write_byte (abfd, ieee_function_plus_enum))
328 /* Writes any integer into the buffer supplied and always takes 5 bytes. */
331 ieee_write_int5 (bfd_byte *buffer, bfd_vma value)
333 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
334 buffer[1] = (value >> 24) & 0xff;
335 buffer[2] = (value >> 16) & 0xff;
336 buffer[3] = (value >> 8) & 0xff;
337 buffer[4] = (value >> 0) & 0xff;
341 ieee_write_int5_out (bfd *abfd, bfd_vma value)
345 ieee_write_int5 (b, value);
346 if (bfd_bwrite ((void *) b, (bfd_size_type) 5, abfd) != 5)
352 parse_int (common_header_type *ieee, bfd_vma *value_ptr)
354 int value = this_byte (ieee);
357 if (value >= 0 && value <= 127)
360 return next_byte (ieee);
362 else if (value >= 0x80 && value <= 0x88)
364 unsigned int count = value & 0xf;
367 if (! next_byte (ieee))
371 result = (result << 8) | this_byte_and_next (ieee);
381 parse_i (common_header_type *ieee, bfd_boolean *ok)
384 *ok = parse_int (ieee, &x);
389 must_parse_int (common_header_type *ieee)
392 BFD_ASSERT (parse_int (ieee, &result));
400 ieee_symbol_index_type symbol;
404 #if KEEPMINUSPCININST
406 #define SRC_MASK(arg) arg
407 #define PCREL_OFFSET FALSE
411 #define SRC_MASK(arg) 0
412 #define PCREL_OFFSET TRUE
416 static reloc_howto_type abs32_howto =
423 complain_overflow_bitfield,
431 static reloc_howto_type abs16_howto =
438 complain_overflow_bitfield,
446 static reloc_howto_type abs8_howto =
453 complain_overflow_bitfield,
461 static reloc_howto_type rel32_howto =
468 complain_overflow_signed,
472 SRC_MASK (0xffffffff),
476 static reloc_howto_type rel16_howto =
483 complain_overflow_signed,
487 SRC_MASK (0x0000ffff),
491 static reloc_howto_type rel8_howto =
498 complain_overflow_signed,
502 SRC_MASK (0x000000ff),
506 static ieee_symbol_index_type NOSYMBOL = {0, 0};
509 parse_expression (ieee_data_type *ieee,
511 ieee_symbol_index_type *symbol,
517 bfd_boolean loop = TRUE;
518 ieee_value_type stack[10];
519 ieee_value_type *sp = stack;
528 /* The stack pointer always points to the next unused location. */
529 #define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC;
530 #define POP(x,y,z) DEC; x = TOS.symbol; y = TOS.section; z = TOS.value;
532 while (loop && ieee->h.input_p < ieee->h.last_byte)
534 switch (this_byte (&(ieee->h)))
536 case ieee_variable_P_enum:
537 /* P variable, current program counter for section n. */
541 if (! next_byte (&(ieee->h)))
544 section_n = must_parse_int (&(ieee->h));
546 PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
550 case ieee_variable_L_enum:
551 /* L variable address of section N. */
552 if (! next_byte (&(ieee->h)))
554 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
557 case ieee_variable_R_enum:
558 /* R variable, logical address of section module. */
559 /* FIXME, this should be different to L. */
560 if (! next_byte (&(ieee->h)))
562 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
565 case ieee_variable_S_enum:
566 /* S variable, size in MAUS of section module. */
567 if (! next_byte (&(ieee->h)))
571 ieee->section_table[must_parse_int (&(ieee->h))]->size);
574 case ieee_variable_I_enum:
575 /* Push the address of variable n. */
577 ieee_symbol_index_type sy;
579 if (! next_byte (&(ieee->h)))
581 sy.index = (int) must_parse_int (&(ieee->h));
584 PUSH (sy, bfd_abs_section_ptr, 0);
588 case ieee_variable_X_enum:
589 /* Push the address of external variable n. */
591 ieee_symbol_index_type sy;
593 if (! next_byte (&(ieee->h)))
596 sy.index = (int) (must_parse_int (&(ieee->h)));
599 PUSH (sy, bfd_und_section_ptr, 0);
603 case ieee_function_minus_enum:
605 bfd_vma value1, value2;
606 asection *section1, *section_dummy;
607 ieee_symbol_index_type sy;
609 if (! next_byte (&(ieee->h)))
612 POP (sy, section1, value1);
613 POP (sy, section_dummy, value2);
614 PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
618 case ieee_function_plus_enum:
620 bfd_vma value1, value2;
623 ieee_symbol_index_type sy1;
624 ieee_symbol_index_type sy2;
626 if (! next_byte (&(ieee->h)))
629 POP (sy1, section1, value1);
630 POP (sy2, section2, value2);
631 PUSH (sy1.letter ? sy1 : sy2,
632 bfd_is_abs_section (section1) ? section2 : section1,
641 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
642 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
643 if (parse_int (&(ieee->h), &va))
645 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
648 /* Thats all that we can understand. */
654 /* As far as I can see there is a bug in the Microtec IEEE output
655 which I'm using to scan, whereby the comma operator is omitted
656 sometimes in an expression, giving expressions with too many
657 terms. We can tell if that's the case by ensuring that
658 sp == stack here. If not, then we've pushed something too far,
659 so we keep adding. */
660 while (sp != stack + 1)
663 ieee_symbol_index_type sy1;
665 POP (sy1, section1, *extra);
670 POP (*symbol, dummy, *value);
677 #define ieee_pos(ieee) \
678 (ieee->h.input_p - ieee->h.first_byte)
680 /* Find the first part of the ieee file after HERE. */
683 ieee_part_after (ieee_data_type *ieee, file_ptr here)
686 file_ptr after = ieee->w.r.me_record;
688 /* File parts can come in any order, except that module end is
689 guaranteed to be last (and the header first). */
690 for (part = 0; part < N_W_VARIABLES; part++)
691 if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
692 after = ieee->w.offset[part];
698 ieee_seek (ieee_data_type * ieee, file_ptr offset)
700 /* PR 17512: file: 017-1157-0.004. */
701 if (offset < 0 || (bfd_size_type) offset >= ieee->h.total_amt)
703 ieee->h.input_p = ieee->h.first_byte + ieee->h.total_amt;
704 ieee->h.last_byte = ieee->h.input_p;
708 ieee->h.input_p = ieee->h.first_byte + offset;
709 ieee->h.last_byte = (ieee->h.first_byte + ieee_part_after (ieee, offset));
713 static unsigned int last_index;
714 static char last_type; /* Is the index for an X or a D. */
716 static ieee_symbol_type *
717 get_symbol (bfd *abfd ATTRIBUTE_UNUSED,
718 ieee_data_type *ieee,
719 ieee_symbol_type *last_symbol,
720 unsigned int *symbol_count,
721 ieee_symbol_type ***pptr,
722 unsigned int *max_index,
725 /* Need a new symbol. */
726 unsigned int new_index = must_parse_int (&(ieee->h));
728 if (new_index != last_index || this_type != last_type)
730 ieee_symbol_type *new_symbol;
731 bfd_size_type amt = sizeof (ieee_symbol_type);
733 new_symbol = bfd_alloc (ieee->h.abfd, amt);
737 new_symbol->index = new_index;
738 last_index = new_index;
741 *pptr = &new_symbol->next;
742 if (new_index > *max_index)
743 *max_index = new_index;
745 last_type = this_type;
746 new_symbol->symbol.section = bfd_abs_section_ptr;
753 ieee_slurp_external_symbols (bfd *abfd)
755 ieee_data_type *ieee = IEEE_DATA (abfd);
756 file_ptr offset = ieee->w.r.external_part;
758 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
759 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
760 ieee_symbol_type *symbol = NULL;
761 unsigned int symbol_count = 0;
762 bfd_boolean loop = TRUE;
764 last_index = 0xffffff;
765 ieee->symbol_table_full = TRUE;
767 if (! ieee_seek (ieee, offset))
772 switch (this_byte (&(ieee->h)))
775 if (! next_byte (&(ieee->h)))
778 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
780 & ieee->external_symbol_max_index, 'I');
784 symbol->symbol.the_bfd = abfd;
785 symbol->symbol.name = read_id (&(ieee->h));
786 symbol->symbol.udata.p = NULL;
787 symbol->symbol.flags = BSF_NO_FLAGS;
790 case ieee_external_symbol_enum:
791 if (! next_byte (&(ieee->h)))
794 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
796 &ieee->external_symbol_max_index, 'D');
800 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
802 symbol->symbol.the_bfd = abfd;
803 symbol->symbol.name = read_id (&(ieee->h));
804 symbol->symbol.udata.p = NULL;
805 symbol->symbol.flags = BSF_NO_FLAGS;
807 case ieee_attribute_record_enum >> 8:
809 unsigned int symbol_name_index;
810 unsigned int symbol_type_index;
811 unsigned int symbol_attribute_def;
814 switch (read_2bytes (&ieee->h))
816 case ieee_attribute_record_enum:
817 symbol_name_index = must_parse_int (&(ieee->h));
818 symbol_type_index = must_parse_int (&(ieee->h));
819 (void) symbol_type_index;
820 symbol_attribute_def = must_parse_int (&(ieee->h));
821 switch (symbol_attribute_def)
825 parse_int (&ieee->h, &value);
829 /* xgettext:c-format */
830 (_("%B: unimplemented ATI record %u for symbol %u"),
831 abfd, symbol_attribute_def, symbol_name_index);
832 bfd_set_error (bfd_error_bad_value);
837 case ieee_external_reference_info_record_enum:
838 /* Skip over ATX record. */
839 parse_int (&(ieee->h), &value);
840 parse_int (&(ieee->h), &value);
841 parse_int (&(ieee->h), &value);
842 parse_int (&(ieee->h), &value);
844 case ieee_atn_record_enum:
845 /* We may get call optimization information here,
846 which we just ignore. The format is
847 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */
848 parse_int (&ieee->h, &value);
849 parse_int (&ieee->h, &value);
850 parse_int (&ieee->h, &value);
854 /* xgettext:c-format */
855 (_("%B: unexpected ATN type %d in external part"),
857 bfd_set_error (bfd_error_bad_value);
860 parse_int (&ieee->h, &value);
861 parse_int (&ieee->h, &value);
868 switch (read_2bytes (&ieee->h))
870 case ieee_asn_record_enum:
871 parse_int (&ieee->h, &val1);
872 parse_int (&ieee->h, &val1);
877 (_("%B: unexpected type after ATN"), abfd);
878 bfd_set_error (bfd_error_bad_value);
886 case ieee_value_record_enum >> 8:
888 unsigned int symbol_name_index;
889 ieee_symbol_index_type symbol_ignore;
890 bfd_boolean pcrel_ignore;
893 if (! next_byte (&(ieee->h)))
895 if (! next_byte (&(ieee->h)))
898 symbol_name_index = must_parse_int (&(ieee->h));
899 (void) symbol_name_index;
900 if (! parse_expression (ieee,
901 &symbol->symbol.value,
905 &symbol->symbol.section))
908 /* Fully linked IEEE-695 files tend to give every symbol
909 an absolute value. Try to convert that back into a
910 section relative value. FIXME: This won't always to
912 if (bfd_is_abs_section (symbol->symbol.section)
913 && (abfd->flags & HAS_RELOC) == 0)
918 val = symbol->symbol.value;
919 for (s = abfd->sections; s != NULL; s = s->next)
921 if (val >= s->vma && val < s->vma + s->size)
923 symbol->symbol.section = s;
924 symbol->symbol.value -= s->vma;
930 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
934 case ieee_weak_external_reference_enum:
939 if (! next_byte (&(ieee->h)))
942 /* Throw away the external reference index. */
943 (void) must_parse_int (&(ieee->h));
944 /* Fetch the default size if not resolved. */
945 size = must_parse_int (&(ieee->h));
946 /* Fetch the default value if available. */
947 if (! parse_int (&(ieee->h), &value))
949 /* This turns into a common. */
950 symbol->symbol.section = bfd_com_section_ptr;
951 symbol->symbol.value = size;
955 case ieee_external_reference_enum:
956 if (! next_byte (&(ieee->h)))
959 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
961 &ieee->external_reference_max_index, 'X');
965 symbol->symbol.the_bfd = abfd;
966 symbol->symbol.name = read_id (&(ieee->h));
967 symbol->symbol.udata.p = NULL;
968 symbol->symbol.section = bfd_und_section_ptr;
969 symbol->symbol.value = (bfd_vma) 0;
970 symbol->symbol.flags = 0;
972 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
980 if (ieee->external_symbol_max_index != 0)
982 ieee->external_symbol_count =
983 ieee->external_symbol_max_index -
984 ieee->external_symbol_min_index + 1;
987 ieee->external_symbol_count = 0;
989 if (ieee->external_reference_max_index != 0)
991 ieee->external_reference_count =
992 ieee->external_reference_max_index -
993 ieee->external_reference_min_index + 1;
996 ieee->external_reference_count = 0;
999 ieee->external_reference_count + ieee->external_symbol_count;
1001 if (symbol_count != abfd->symcount)
1002 /* There are gaps in the table -- */
1003 ieee->symbol_table_full = FALSE;
1005 *prev_symbols_ptr = NULL;
1006 *prev_reference_ptr = NULL;
1012 ieee_slurp_symbol_table (bfd *abfd)
1014 if (! IEEE_DATA (abfd)->read_symbols)
1016 if (! ieee_slurp_external_symbols (abfd))
1018 IEEE_DATA (abfd)->read_symbols = TRUE;
1024 ieee_get_symtab_upper_bound (bfd *abfd)
1026 if (! ieee_slurp_symbol_table (abfd))
1029 return (abfd->symcount != 0) ?
1030 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
1033 /* Move from our internal lists to the canon table, and insert in
1034 symbol index order. */
1036 extern const bfd_target ieee_vec;
1039 ieee_canonicalize_symtab (bfd *abfd, asymbol **location)
1041 ieee_symbol_type *symp;
1042 static bfd dummy_bfd;
1043 static asymbol empty_symbol =
1051 /* K&R compilers can't initialise unions. */
1058 ieee_data_type *ieee = IEEE_DATA (abfd);
1060 dummy_bfd.xvec = &ieee_vec;
1061 if (! ieee_slurp_symbol_table (abfd))
1064 if (! ieee->symbol_table_full)
1066 /* Arrgh - there are gaps in the table, run through and fill them
1067 up with pointers to a null place. */
1070 for (i = 0; i < abfd->symcount; i++)
1071 location[i] = &empty_symbol;
1074 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
1075 for (symp = IEEE_DATA (abfd)->external_symbols;
1076 symp != (ieee_symbol_type *) NULL;
1078 /* Place into table at correct index locations. */
1079 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
1081 /* The external refs are indexed in a bit. */
1082 ieee->external_reference_base_offset =
1083 -ieee->external_reference_min_index + ieee->external_symbol_count;
1085 for (symp = IEEE_DATA (abfd)->external_reference;
1086 symp != (ieee_symbol_type *) NULL;
1088 location[symp->index + ieee->external_reference_base_offset] =
1093 location[abfd->symcount] = (asymbol *) NULL;
1095 return abfd->symcount;
1099 get_section_entry (bfd *abfd, ieee_data_type *ieee, unsigned int sindex)
1101 if (sindex >= ieee->section_table_size)
1107 c = ieee->section_table_size;
1114 amt *= sizeof (asection *);
1115 n = bfd_realloc (ieee->section_table, amt);
1119 for (i = ieee->section_table_size; i < c; i++)
1122 ieee->section_table = n;
1123 ieee->section_table_size = c;
1126 if (ieee->section_table[sindex] == (asection *) NULL)
1128 char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
1133 sprintf (tmp, " fsec%4d", sindex);
1134 section = bfd_make_section (abfd, tmp);
1135 ieee->section_table[sindex] = section;
1136 section->target_index = sindex;
1137 ieee->section_table[sindex] = section;
1139 return ieee->section_table[sindex];
1143 ieee_slurp_sections (bfd *abfd)
1145 ieee_data_type *ieee = IEEE_DATA (abfd);
1146 file_ptr offset = ieee->w.r.section_part;
1151 bfd_byte section_type[3];
1153 if (! ieee_seek (ieee, offset))
1158 switch (this_byte (&(ieee->h)))
1160 case ieee_section_type_enum:
1163 unsigned int section_index;
1165 if (! next_byte (&(ieee->h)))
1167 section_index = must_parse_int (&(ieee->h));
1169 section = get_section_entry (abfd, ieee, section_index);
1171 section_type[0] = this_byte_and_next (&(ieee->h));
1173 /* Set minimal section attributes. Attributes are
1174 extended later, based on section contents. */
1175 switch (section_type[0])
1178 /* Normal attributes for absolute sections. */
1179 section_type[1] = this_byte (&(ieee->h));
1180 section->flags = SEC_ALLOC;
1181 switch (section_type[1])
1183 /* AS Absolute section attributes. */
1185 if (! next_byte (&(ieee->h)))
1187 section_type[2] = this_byte (&(ieee->h));
1188 switch (section_type[2])
1192 if (! next_byte (&(ieee->h)))
1194 section->flags |= SEC_CODE;
1198 if (! next_byte (&(ieee->h)))
1200 section->flags |= SEC_DATA;
1203 if (! next_byte (&(ieee->h)))
1205 /* Normal rom data. */
1206 section->flags |= SEC_ROM | SEC_DATA;
1214 /* Named relocatable sections (type C). */
1216 section_type[1] = this_byte (&(ieee->h));
1217 section->flags = SEC_ALLOC;
1218 switch (section_type[1])
1220 case 0xD0: /* Normal code (CP). */
1221 if (! next_byte (&(ieee->h)))
1223 section->flags |= SEC_CODE;
1225 case 0xC4: /* Normal data (CD). */
1226 if (! next_byte (&(ieee->h)))
1228 section->flags |= SEC_DATA;
1230 case 0xD2: /* Normal rom data (CR). */
1231 if (! next_byte (&(ieee->h)))
1233 section->flags |= SEC_ROM | SEC_DATA;
1240 /* Read section name, use it if non empty. */
1241 name = read_id (&ieee->h);
1243 section->name = name;
1245 /* Skip these fields, which we don't care about. */
1247 bfd_vma parent, brother, context;
1249 parse_int (&(ieee->h), &parent);
1250 parse_int (&(ieee->h), &brother);
1251 parse_int (&(ieee->h), &context);
1255 case ieee_section_alignment_enum:
1257 unsigned int section_index;
1261 if (! next_byte (&(ieee->h)))
1263 section_index = must_parse_int (&ieee->h);
1264 section = get_section_entry (abfd, ieee, section_index);
1265 if (section_index > ieee->section_count)
1266 ieee->section_count = section_index;
1268 section->alignment_power =
1269 bfd_log2 (must_parse_int (&ieee->h));
1270 (void) parse_int (&(ieee->h), &value);
1273 case ieee_e2_first_byte_enum:
1276 ieee_record_enum_type t;
1278 t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1281 case ieee_section_size_enum:
1282 section = ieee->section_table[must_parse_int (&(ieee->h))];
1283 section->size = must_parse_int (&(ieee->h));
1285 case ieee_physical_region_size_enum:
1286 section = ieee->section_table[must_parse_int (&(ieee->h))];
1287 section->size = must_parse_int (&(ieee->h));
1289 case ieee_region_base_address_enum:
1290 section = ieee->section_table[must_parse_int (&(ieee->h))];
1291 section->vma = must_parse_int (&(ieee->h));
1292 section->lma = section->vma;
1294 case ieee_mau_size_enum:
1295 must_parse_int (&(ieee->h));
1296 must_parse_int (&(ieee->h));
1298 case ieee_m_value_enum:
1299 must_parse_int (&(ieee->h));
1300 must_parse_int (&(ieee->h));
1302 case ieee_section_base_address_enum:
1303 section = ieee->section_table[must_parse_int (&(ieee->h))];
1304 section->vma = must_parse_int (&(ieee->h));
1305 section->lma = section->vma;
1307 case ieee_section_offset_enum:
1308 (void) must_parse_int (&(ieee->h));
1309 (void) must_parse_int (&(ieee->h));
1325 /* Make a section for the debugging information, if any. We don't try
1326 to interpret the debugging information; we just point the section
1327 at the area in the file so that program which understand can dig it
1331 ieee_slurp_debug (bfd *abfd)
1333 ieee_data_type *ieee = IEEE_DATA (abfd);
1338 if (ieee->w.r.debug_information_part == 0)
1341 flags = SEC_DEBUGGING | SEC_HAS_CONTENTS;
1342 sec = bfd_make_section_with_flags (abfd, ".debug", flags);
1345 sec->filepos = ieee->w.r.debug_information_part;
1347 debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
1348 sec->size = debug_end - ieee->w.r.debug_information_part;
1353 /* Archive stuff. */
1355 static const bfd_target *
1356 ieee_archive_p (bfd *abfd)
1360 unsigned char buffer[512];
1361 file_ptr buffer_offset = 0;
1362 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1363 ieee_ar_data_type *ieee;
1364 bfd_size_type alc_elts;
1365 ieee_ar_obstack_type *elts = NULL;
1366 bfd_size_type amt = sizeof (ieee_ar_data_type);
1368 abfd->tdata.ieee_ar_data = bfd_alloc (abfd, amt);
1369 if (!abfd->tdata.ieee_ar_data)
1370 goto error_ret_restore;
1371 ieee = IEEE_AR_DATA (abfd);
1373 /* Ignore the return value here. It doesn't matter if we don't read
1374 the entire buffer. We might have a very small ieee file. */
1375 if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0)
1376 goto got_wrong_format_error;
1378 ieee->h.first_byte = buffer;
1379 ieee->h.input_p = buffer;
1381 ieee->h.abfd = abfd;
1383 if (this_byte (&(ieee->h)) != Module_Beginning)
1384 goto got_wrong_format_error;
1386 (void) next_byte (&(ieee->h));
1388 library = read_id (&(ieee->h));
1389 if (strcmp (library, "LIBRARY") != 0)
1390 goto got_wrong_format_error;
1392 /* Throw away the filename. */
1393 read_id (&(ieee->h));
1395 ieee->element_count = 0;
1396 ieee->element_index = 0;
1398 (void) next_byte (&(ieee->h)); /* Drop the ad part. */
1399 must_parse_int (&(ieee->h)); /* And the two dummy numbers. */
1400 must_parse_int (&(ieee->h));
1403 elts = bfd_malloc (alc_elts * sizeof *elts);
1407 /* Read the index of the BB table. */
1411 ieee_ar_obstack_type *t;
1413 rec = read_2bytes (&(ieee->h));
1414 if (rec != (int) ieee_assign_value_to_variable_enum)
1417 if (ieee->element_count >= alc_elts)
1419 ieee_ar_obstack_type *n;
1422 n = bfd_realloc (elts, alc_elts * sizeof (* elts));
1428 t = &elts[ieee->element_count];
1429 ieee->element_count++;
1431 must_parse_int (&(ieee->h));
1432 t->file_offset = must_parse_int (&(ieee->h));
1433 t->abfd = (bfd *) NULL;
1435 /* Make sure that we don't go over the end of the buffer. */
1436 if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
1438 /* Past half way, reseek and reprime. */
1439 buffer_offset += ieee_pos (IEEE_DATA (abfd));
1440 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1443 /* Again ignore return value of bfd_bread. */
1444 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1445 ieee->h.first_byte = buffer;
1446 ieee->h.input_p = buffer;
1450 amt = ieee->element_count;
1451 amt *= sizeof *ieee->elements;
1452 ieee->elements = bfd_alloc (abfd, amt);
1453 if (ieee->elements == NULL)
1456 memcpy (ieee->elements, elts, (size_t) amt);
1460 /* Now scan the area again, and replace BB offsets with file offsets. */
1461 for (i = 2; i < ieee->element_count; i++)
1463 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1466 /* Again ignore return value of bfd_bread. */
1467 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1468 ieee->h.first_byte = buffer;
1469 ieee->h.input_p = buffer;
1471 (void) next_byte (&(ieee->h)); /* Drop F8. */
1472 if (! next_byte (&(ieee->h))) /* Drop 14. */
1474 must_parse_int (&(ieee->h)); /* Drop size of block. */
1476 if (must_parse_int (&(ieee->h)) != 0)
1477 /* This object has been deleted. */
1478 ieee->elements[i].file_offset = 0;
1480 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1483 /* abfd->has_armap = ;*/
1487 got_wrong_format_error:
1488 bfd_set_error (bfd_error_wrong_format);
1492 bfd_release (abfd, ieee);
1494 abfd->tdata.ieee_ar_data = save;
1500 ieee_mkobject (bfd *abfd)
1504 output_ptr_start = NULL;
1506 output_ptr_end = NULL;
1507 input_ptr_start = NULL;
1509 input_ptr_end = NULL;
1513 amt = sizeof (ieee_data_type);
1514 abfd->tdata.ieee_data = bfd_zalloc (abfd, amt);
1515 return abfd->tdata.ieee_data != NULL;
1519 do_one (ieee_data_type *ieee,
1520 ieee_per_section_type *current_map,
1521 unsigned char *location_ptr,
1525 switch (this_byte (&(ieee->h)))
1527 case ieee_load_constant_bytes_enum:
1529 unsigned int number_of_maus;
1532 if (! next_byte (&(ieee->h)))
1534 number_of_maus = must_parse_int (&(ieee->h));
1536 for (i = 0; i < number_of_maus; i++)
1538 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1539 next_byte (&(ieee->h));
1544 case ieee_load_with_relocation_enum:
1546 bfd_boolean loop = TRUE;
1548 if (! next_byte (&(ieee->h)))
1552 switch (this_byte (&(ieee->h)))
1554 case ieee_variable_R_enum:
1556 case ieee_function_signed_open_b_enum:
1557 case ieee_function_unsigned_open_b_enum:
1558 case ieee_function_either_open_b_enum:
1560 unsigned int extra = 4;
1561 bfd_boolean pcrel = FALSE;
1565 r = bfd_alloc (ieee->h.abfd, sizeof (* r));
1569 *(current_map->reloc_tail_ptr) = r;
1570 current_map->reloc_tail_ptr = &r->next;
1571 r->next = (ieee_reloc_type *) NULL;
1572 if (! next_byte (&(ieee->h)))
1575 r->relent.sym_ptr_ptr = 0;
1576 if (! parse_expression (ieee,
1579 &pcrel, &extra, §ion))
1582 r->relent.address = current_map->pc;
1583 s->flags |= SEC_RELOC;
1584 s->owner->flags |= HAS_RELOC;
1586 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
1587 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1589 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1591 if (! next_byte (&(ieee->h)))
1593 /* Fetch number of bytes to pad. */
1594 extra = must_parse_int (&(ieee->h));
1597 switch (this_byte (&(ieee->h)))
1599 case ieee_function_signed_close_b_enum:
1600 if (! next_byte (&(ieee->h)))
1603 case ieee_function_unsigned_close_b_enum:
1604 if (! next_byte (&(ieee->h)))
1607 case ieee_function_either_close_b_enum:
1608 if (! next_byte (&(ieee->h)))
1614 /* Build a relocation entry for this type. */
1615 /* If pc rel then stick -ve pc into instruction
1616 and take out of reloc ..
1618 I've changed this. It's all too complicated. I
1619 keep 0 in the instruction now. */
1628 #if KEEPMINUSPCININST
1629 bfd_put_32 (ieee->h.abfd, -current_map->pc,
1630 location_ptr + current_map->pc);
1631 r->relent.howto = &rel32_howto;
1632 r->relent.addend -= current_map->pc;
1634 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
1636 r->relent.howto = &rel32_howto;
1641 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
1642 location_ptr + current_map->pc);
1643 r->relent.howto = &abs32_howto;
1645 current_map->pc += 4;
1650 #if KEEPMINUSPCININST
1651 bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
1652 location_ptr + current_map->pc);
1653 r->relent.addend -= current_map->pc;
1654 r->relent.howto = &rel16_howto;
1657 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1658 location_ptr + current_map->pc);
1659 r->relent.howto = &rel16_howto;
1665 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1666 location_ptr + current_map->pc);
1667 r->relent.howto = &abs16_howto;
1669 current_map->pc += 2;
1674 #if KEEPMINUSPCININST
1675 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1676 r->relent.addend -= current_map->pc;
1677 r->relent.howto = &rel8_howto;
1679 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1680 r->relent.howto = &rel8_howto;
1685 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1686 r->relent.howto = &abs8_howto;
1688 current_map->pc += 1;
1701 if (parse_int (&(ieee->h), &this_size))
1705 for (i = 0; i < this_size; i++)
1707 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1708 if (! next_byte (&(ieee->h)))
1717 /* Prevent more than the first load-item of an LR record
1718 from being repeated (MRI convention). */
1719 if (iterations != 1)
1727 /* Read in all the section data and relocation stuff too. */
1730 ieee_slurp_section_data (bfd *abfd)
1732 bfd_byte *location_ptr = (bfd_byte *) NULL;
1733 ieee_data_type *ieee = IEEE_DATA (abfd);
1734 unsigned int section_number;
1735 ieee_per_section_type *current_map = NULL;
1738 /* Seek to the start of the data area. */
1739 if (ieee->read_data)
1741 ieee->read_data = TRUE;
1743 if (! ieee_seek (ieee, ieee->w.r.data_part))
1746 /* Allocate enough space for all the section contents. */
1747 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1749 ieee_per_section_type *per = ieee_per_section (s);
1752 if ((s->flags & SEC_DEBUGGING) != 0)
1754 per->data = bfd_alloc (ieee->h.abfd, s->size);
1757 relpp = &s->relocation;
1758 per->reloc_tail_ptr = (ieee_reloc_type **) relpp;
1763 switch (this_byte (&(ieee->h)))
1765 /* IF we see anything strange then quit. */
1769 case ieee_set_current_section_enum:
1770 if (! next_byte (&(ieee->h)))
1772 section_number = must_parse_int (&(ieee->h));
1773 s = ieee->section_table[section_number];
1774 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
1775 current_map = ieee_per_section (s);
1776 location_ptr = current_map->data - s->vma;
1777 /* The document I have says that Microtec's compilers reset
1778 this after a sec section, even though the standard says not
1780 current_map->pc = s->vma;
1783 case ieee_e2_first_byte_enum:
1784 if (! next_byte (&(ieee->h)))
1786 switch (this_byte (&(ieee->h)))
1788 case ieee_set_current_pc_enum & 0xff:
1791 ieee_symbol_index_type symbol;
1795 if (! next_byte (&(ieee->h)))
1797 must_parse_int (&(ieee->h)); /* Throw away section #. */
1798 if (! parse_expression (ieee, &value,
1804 current_map->pc = value;
1805 BFD_ASSERT ((unsigned) (value - s->vma) <= s->size);
1809 case ieee_value_starting_address_enum & 0xff:
1810 if (! next_byte (&(ieee->h)))
1812 if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
1814 if (! next_byte (&(ieee->h)))
1817 abfd->start_address = must_parse_int (&(ieee->h));
1818 /* We've got to the end of the data now - */
1825 case ieee_repeat_data_enum:
1827 /* Repeat the following LD or LR n times - we do this by
1828 remembering the stream pointer before running it and
1829 resetting it and running it n times. We special case
1830 the repetition of a repeat_data/load_constant. */
1831 unsigned int iterations;
1832 unsigned char *start;
1834 if (! next_byte (&(ieee->h)))
1836 iterations = must_parse_int (&(ieee->h));
1837 start = ieee->h.input_p;
1838 if (start[0] == (int) ieee_load_constant_bytes_enum
1841 while (iterations != 0)
1843 location_ptr[current_map->pc++] = start[2];
1846 (void) next_byte (&(ieee->h));
1847 (void) next_byte (&(ieee->h));
1848 if (! next_byte (&(ieee->h)))
1853 while (iterations != 0)
1855 ieee->h.input_p = start;
1856 if (!do_one (ieee, current_map, location_ptr, s,
1864 case ieee_load_constant_bytes_enum:
1865 case ieee_load_with_relocation_enum:
1866 if (!do_one (ieee, current_map, location_ptr, s, 1))
1872 static const bfd_target *
1873 ieee_object_p (bfd *abfd)
1877 ieee_data_type *ieee;
1878 unsigned char buffer[300];
1879 ieee_data_type *save = IEEE_DATA (abfd);
1882 abfd->tdata.ieee_data = 0;
1883 ieee_mkobject (abfd);
1885 ieee = IEEE_DATA (abfd);
1886 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1888 /* Read the first few bytes in to see if it makes sense. Ignore
1889 bfd_bread return value; The file might be very small. */
1890 if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0)
1891 goto got_wrong_format;
1893 ieee->h.input_p = buffer;
1894 ieee->h.total_amt = sizeof (buffer);
1895 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1896 goto got_wrong_format;
1898 ieee->read_symbols = FALSE;
1899 ieee->read_data = FALSE;
1900 ieee->section_count = 0;
1901 ieee->external_symbol_max_index = 0;
1902 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1903 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1904 ieee->external_reference_max_index = 0;
1905 ieee->h.abfd = abfd;
1906 ieee->section_table = NULL;
1907 ieee->section_table_size = 0;
1909 processor = ieee->mb.processor = read_id (&(ieee->h));
1910 if (strcmp (processor, "LIBRARY") == 0)
1911 goto got_wrong_format;
1912 ieee->mb.module_name = read_id (&(ieee->h));
1913 if (abfd->filename == (const char *) NULL)
1914 abfd->filename = xstrdup (ieee->mb.module_name);
1916 /* Determine the architecture and machine type of the object file. */
1918 const bfd_arch_info_type *arch;
1921 /* IEEE does not specify the format of the processor identification
1922 string, so the compiler is free to put in it whatever it wants.
1923 We try here to recognize different processors belonging to the
1924 m68k family. Code for other processors can be added here. */
1925 if ((processor[0] == '6') && (processor[1] == '8'))
1927 if (processor[2] == '3') /* 683xx integrated processors. */
1929 switch (processor[3])
1931 case '0': /* 68302, 68306, 68307 */
1932 case '2': /* 68322, 68328 */
1933 case '5': /* 68356 */
1934 strcpy (family, "68000"); /* MC68000-based controllers. */
1937 case '3': /* 68330, 68331, 68332, 68333,
1938 68334, 68335, 68336, 68338 */
1939 case '6': /* 68360 */
1940 case '7': /* 68376 */
1941 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1945 if (processor[4] == '9') /* 68349 */
1946 strcpy (family, "68030"); /* CPU030 */
1947 else /* 68340, 68341 */
1948 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1951 default: /* Does not exist yet. */
1952 strcpy (family, "68332"); /* Guess it will be CPU32 */
1955 else if (TOUPPER (processor[3]) == 'F') /* 68F333 */
1956 strcpy (family, "68332"); /* CPU32 */
1957 else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers. */
1958 && ((TOUPPER (processor[2]) == 'E')
1959 || (TOUPPER (processor[2]) == 'H')
1960 || (TOUPPER (processor[2]) == 'L')))
1962 strcpy (family, "68");
1963 strncat (family, processor + 4, 7);
1966 else /* "Regular" processors. */
1968 strncpy (family, processor, 9);
1972 else if ((CONST_STRNEQ (processor, "cpu32")) /* CPU32 and CPU32+ */
1973 || (CONST_STRNEQ (processor, "CPU32")))
1974 strcpy (family, "68332");
1977 strncpy (family, processor, 9);
1981 arch = bfd_scan_arch (family);
1983 goto got_wrong_format;
1984 abfd->arch_info = arch;
1987 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1990 if (! next_byte (&(ieee->h)))
1993 if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
1996 if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
1999 /* If there is a byte order info, take it. */
2000 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum
2001 || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
2003 if (! next_byte (&(ieee->h)))
2007 for (part = 0; part < N_W_VARIABLES; part++)
2011 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
2014 if (this_byte_and_next (&(ieee->h)) != part)
2017 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
2022 if (ieee->w.r.external_part != 0)
2023 abfd->flags = HAS_SYMS;
2025 /* By now we know that this is a real IEEE file, we're going to read
2026 the whole thing into memory so that we can run up and down it
2027 quickly. We can work out how big the file is from the trailer
2030 amt = ieee->w.r.me_record + 1;
2031 IEEE_DATA (abfd)->h.first_byte = bfd_alloc (ieee->h.abfd, amt);
2032 if (!IEEE_DATA (abfd)->h.first_byte)
2034 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
2037 /* FIXME: Check return value. I'm not sure whether it needs to read
2038 the entire buffer or not. */
2039 amt = bfd_bread ((void *) (IEEE_DATA (abfd)->h.first_byte),
2040 (bfd_size_type) ieee->w.r.me_record + 1, abfd);
2044 IEEE_DATA (abfd)->h.total_amt = amt;
2045 if (ieee_slurp_sections (abfd))
2048 if (! ieee_slurp_debug (abfd))
2051 /* Parse section data to activate file and section flags implied by
2052 section contents. */
2053 if (! ieee_slurp_section_data (abfd))
2058 bfd_set_error (bfd_error_wrong_format);
2060 bfd_release (abfd, ieee);
2061 abfd->tdata.ieee_data = save;
2062 return (const bfd_target *) NULL;
2066 ieee_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED,
2070 bfd_symbol_info (symbol, ret);
2071 if (symbol->name[0] == ' ')
2072 ret->name = "* empty table entry ";
2073 if (!symbol->section)
2074 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
2078 ieee_print_symbol (bfd *abfd,
2081 bfd_print_symbol_type how)
2083 FILE *file = (FILE *) afile;
2087 case bfd_print_symbol_name:
2088 fprintf (file, "%s", symbol->name);
2090 case bfd_print_symbol_more:
2093 case bfd_print_symbol_all:
2095 const char *section_name =
2096 (symbol->section == (asection *) NULL
2098 : symbol->section->name);
2100 if (symbol->name[0] == ' ')
2101 fprintf (file, "* empty table entry ");
2104 bfd_print_symbol_vandf (abfd, (void *) file, symbol);
2106 fprintf (file, " %-5s %04x %02x %s",
2108 (unsigned) ieee_symbol (symbol)->index,
2118 ieee_new_section_hook (bfd *abfd, asection *newsect)
2120 if (!newsect->used_by_bfd)
2122 newsect->used_by_bfd = bfd_alloc (abfd, sizeof (ieee_per_section_type));
2123 if (!newsect->used_by_bfd)
2126 ieee_per_section (newsect)->data = NULL;
2127 ieee_per_section (newsect)->section = newsect;
2128 return _bfd_generic_new_section_hook (abfd, newsect);
2132 ieee_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
2134 if ((asect->flags & SEC_DEBUGGING) != 0)
2136 if (! ieee_slurp_section_data (abfd))
2138 return (asect->reloc_count + 1) * sizeof (arelent *);
2142 ieee_get_section_contents (bfd *abfd,
2146 bfd_size_type count)
2148 ieee_per_section_type *p = ieee_per_section (section);
2149 if ((section->flags & SEC_DEBUGGING) != 0)
2150 return _bfd_generic_get_section_contents (abfd, section, location,
2152 ieee_slurp_section_data (abfd);
2153 (void) memcpy ((void *) location, (void *) (p->data + offset), (unsigned) count);
2158 ieee_canonicalize_reloc (bfd *abfd,
2163 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
2164 ieee_data_type *ieee = IEEE_DATA (abfd);
2166 if ((section->flags & SEC_DEBUGGING) != 0)
2169 while (src != (ieee_reloc_type *) NULL)
2171 /* Work out which symbol to attach it this reloc to. */
2172 switch (src->symbol.letter)
2175 src->relent.sym_ptr_ptr =
2176 symbols + src->symbol.index + ieee->external_symbol_base_offset;
2179 src->relent.sym_ptr_ptr =
2180 symbols + src->symbol.index + ieee->external_reference_base_offset;
2183 if (src->relent.sym_ptr_ptr != NULL)
2184 src->relent.sym_ptr_ptr =
2185 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
2191 *relptr++ = &src->relent;
2195 return section->reloc_count;
2199 comp (const void * ap, const void * bp)
2201 arelent *a = *((arelent **) ap);
2202 arelent *b = *((arelent **) bp);
2203 return a->address - b->address;
2206 /* Write the section headers. */
2209 ieee_write_section_part (bfd *abfd)
2211 ieee_data_type *ieee = IEEE_DATA (abfd);
2214 ieee->w.r.section_part = bfd_tell (abfd);
2215 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2217 if (! bfd_is_abs_section (s)
2218 && (s->flags & SEC_DEBUGGING) == 0)
2220 if (! ieee_write_byte (abfd, ieee_section_type_enum)
2221 || ! ieee_write_byte (abfd,
2222 (bfd_byte) (s->index
2223 + IEEE_SECTION_NUMBER_BASE)))
2226 if (abfd->flags & EXEC_P)
2228 /* This image is executable, so output absolute sections. */
2229 if (! ieee_write_byte (abfd, ieee_variable_A_enum)
2230 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
2235 if (! ieee_write_byte (abfd, ieee_variable_C_enum))
2239 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
2241 case SEC_CODE | SEC_LOAD:
2243 if (! ieee_write_byte (abfd, ieee_variable_P_enum))
2248 if (! ieee_write_byte (abfd, ieee_variable_D_enum))
2252 case SEC_ROM | SEC_DATA:
2253 case SEC_ROM | SEC_LOAD:
2254 case SEC_ROM | SEC_DATA | SEC_LOAD:
2255 if (! ieee_write_byte (abfd, ieee_variable_R_enum))
2260 if (! ieee_write_id (abfd, s->name))
2263 if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
2264 || ! ieee_write_byte (abfd,
2265 (bfd_byte) (s->index
2266 + IEEE_SECTION_NUMBER_BASE))
2267 || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
2271 if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
2272 || ! ieee_write_byte (abfd,
2273 (bfd_byte) (s->index
2274 + IEEE_SECTION_NUMBER_BASE))
2275 || ! ieee_write_int (abfd, s->size))
2277 if (abfd->flags & EXEC_P)
2279 /* Relocateable sections don't have asl records. */
2281 if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
2282 || ! ieee_write_byte (abfd,
2285 + IEEE_SECTION_NUMBER_BASE)))
2286 || ! ieee_write_int (abfd, s->lma))
2296 do_with_relocs (bfd *abfd, asection *s)
2298 unsigned int number_of_maus_in_address =
2299 bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
2300 unsigned int relocs_to_go = s->reloc_count;
2301 bfd_byte *stream = ieee_per_section (s)->data;
2302 arelent **p = s->orelocation;
2303 bfd_size_type current_byte_index = 0;
2305 qsort (s->orelocation,
2307 sizeof (arelent **),
2310 /* Output the section preheader. */
2311 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2312 || ! ieee_write_byte (abfd,
2313 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
2314 || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
2315 || ! ieee_write_byte (abfd,
2316 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
2319 if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
2321 if (! ieee_write_int (abfd, s->lma))
2326 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2330 if (relocs_to_go == 0)
2332 /* If there aren't any relocations then output the load constant
2333 byte opcode rather than the load with relocation opcode. */
2334 while (current_byte_index < s->size)
2337 unsigned int MAXRUN = 127;
2340 if (run > s->size - current_byte_index)
2341 run = s->size - current_byte_index;
2345 if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
2347 /* Output a stream of bytes. */
2348 if (! ieee_write_int (abfd, run))
2350 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
2353 current_byte_index += run;
2359 if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
2362 /* Output the data stream as the longest sequence of bytes
2363 possible, allowing for the a reasonable packet size and
2364 relocation stuffs. */
2367 /* Outputting a section without data, fill it up. */
2368 stream = bfd_zalloc (abfd, s->size);
2372 while (current_byte_index < s->size)
2375 unsigned int MAXRUN = 127;
2379 run = (*p)->address - current_byte_index;
2386 if (run > s->size - current_byte_index)
2387 run = s->size - current_byte_index;
2391 /* Output a stream of bytes. */
2392 if (! ieee_write_int (abfd, run))
2394 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
2397 current_byte_index += run;
2400 /* Output any relocations here. */
2401 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
2404 && (*p) && (*p)->address == current_byte_index)
2408 switch (r->howto->size)
2411 ov = bfd_get_signed_32 (abfd,
2412 stream + current_byte_index);
2413 current_byte_index += 4;
2416 ov = bfd_get_signed_16 (abfd,
2417 stream + current_byte_index);
2418 current_byte_index += 2;
2421 ov = bfd_get_signed_8 (abfd,
2422 stream + current_byte_index);
2423 current_byte_index++;
2431 ov &= r->howto->src_mask;
2433 if (r->howto->pc_relative
2434 && ! r->howto->pcrel_offset)
2437 if (! ieee_write_byte (abfd,
2438 ieee_function_either_open_b_enum))
2441 if (r->sym_ptr_ptr != (asymbol **) NULL)
2443 if (! ieee_write_expression (abfd, r->addend + ov,
2445 r->howto->pc_relative,
2446 (unsigned) s->index))
2451 if (! ieee_write_expression (abfd, r->addend + ov,
2453 r->howto->pc_relative,
2454 (unsigned) s->index))
2458 if (number_of_maus_in_address
2459 != bfd_get_reloc_size (r->howto))
2461 bfd_vma rsize = bfd_get_reloc_size (r->howto);
2462 if (! ieee_write_int (abfd, rsize))
2465 if (! ieee_write_byte (abfd,
2466 ieee_function_either_close_b_enum))
2480 /* If there are no relocations in the output section then we can be
2481 clever about how we write. We block items up into a max of 127
2485 do_as_repeat (bfd *abfd, asection *s)
2489 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2490 || ! ieee_write_byte (abfd,
2491 (bfd_byte) (s->index
2492 + IEEE_SECTION_NUMBER_BASE))
2493 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
2494 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
2495 || ! ieee_write_byte (abfd,
2496 (bfd_byte) (s->index
2497 + IEEE_SECTION_NUMBER_BASE)))
2500 if ((abfd->flags & EXEC_P) != 0)
2502 if (! ieee_write_int (abfd, s->lma))
2507 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2511 if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
2512 || ! ieee_write_int (abfd, s->size)
2513 || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
2514 || ! ieee_write_byte (abfd, 1)
2515 || ! ieee_write_byte (abfd, 0))
2523 do_without_relocs (bfd *abfd, asection *s)
2525 bfd_byte *stream = ieee_per_section (s)->data;
2527 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2529 if (! do_as_repeat (abfd, s))
2536 for (i = 0; i < s->size; i++)
2540 if (! do_with_relocs (abfd, s))
2545 if (! do_as_repeat (abfd, s))
2555 bfd_size_type amt = input_ptr_end - input_ptr_start;
2556 /* FIXME: Check return value. I'm not sure whether it needs to read
2557 the entire buffer or not. */
2558 bfd_bread ((void *) input_ptr_start, amt, input_bfd);
2559 input_ptr = input_ptr_start;
2565 bfd_size_type amt = output_ptr - output_ptr_start;
2567 if (bfd_bwrite ((void *) (output_ptr_start), amt, output_bfd) != amt)
2569 output_ptr = output_ptr_start;
2573 #define THIS() ( *input_ptr )
2574 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); }
2575 #define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end) flush (); }
2578 write_int (int value)
2580 if (value >= 0 && value <= 127)
2586 unsigned int length;
2588 /* How many significant bytes ? */
2589 /* FIXME FOR LONGER INTS. */
2590 if (value & 0xff000000)
2592 else if (value & 0x00ff0000)
2594 else if (value & 0x0000ff00)
2599 OUT ((int) ieee_number_repeat_start_enum + length);
2620 int length = THIS ();
2633 #define VAR(x) ((x | 0x80))
2635 copy_expression (void)
2649 value = (value << 8) | THIS ();
2651 value = (value << 8) | THIS ();
2653 value = (value << 8) | THIS ();
2661 value = (value << 8) | THIS ();
2663 value = (value << 8) | THIS ();
2671 value = (value << 8) | THIS ();
2688 /* Not a number, just bug out with the answer. */
2689 write_int (*(--tos));
2696 /* PLUS anything. */
2705 ieee_data_type *ieee;
2709 section_number = THIS ();
2712 ieee = IEEE_DATA (input_bfd);
2713 s = ieee->section_table[section_number];
2715 if (s->output_section)
2716 value = s->output_section->lma;
2717 value += s->output_offset;
2724 write_int (*(--tos));
2732 /* Drop the int in the buffer, and copy a null into the gap, which we
2733 will overwrite later. */
2736 fill_int (struct output_buffer_struct *buf)
2738 if (buf->buffer == output_buffer)
2740 /* Still a chance to output the size. */
2741 int value = output_ptr - buf->ptrp + 3;
2742 buf->ptrp[0] = value >> 24;
2743 buf->ptrp[1] = value >> 16;
2744 buf->ptrp[2] = value >> 8;
2745 buf->ptrp[3] = value >> 0;
2750 drop_int (struct output_buffer_struct *buf)
2782 buf->ptrp = output_ptr;
2783 buf->buffer = output_buffer;
2827 #define ID copy_id ()
2828 #define INT copy_int ()
2829 #define EXP copy_expression ()
2830 #define INTn(q) copy_int ()
2831 #define EXPn(q) copy_expression ()
2834 copy_till_end (void)
2913 EXPn (instruction address);
2947 EXPn (external function);
2957 INTn (locked register);
2979 /* Attribute record. */
3009 /* Unique typedefs for module. */
3010 /* GLobal typedefs. */
3011 /* High level module scope beginning. */
3013 struct output_buffer_struct ob;
3029 /* Global function. */
3031 struct output_buffer_struct ob;
3046 EXPn (size of block);
3052 /* File name for source line numbers. */
3054 struct output_buffer_struct ob;
3075 /* Local function. */
3077 struct output_buffer_struct ob;
3096 /* Assembler module scope beginning - */
3098 struct output_buffer_struct ob;
3124 struct output_buffer_struct ob;
3132 INTn (section index);
3140 EXPn (Size in Maus);
3193 /* Moves all the debug information from the source bfd to the output
3194 bfd, and relocates any expressions it finds. */
3197 relocate_debug (bfd *output ATTRIBUTE_UNUSED,
3202 unsigned char input_buffer[IBS];
3204 input_ptr_start = input_ptr = input_buffer;
3205 input_ptr_end = input_buffer + IBS;
3207 /* FIXME: Check return value. I'm not sure whether it needs to read
3208 the entire buffer or not. */
3209 bfd_bread ((void *) input_ptr_start, (bfd_size_type) IBS, input);
3213 /* Gather together all the debug information from each input BFD into
3214 one place, relocating it and emitting it as we go. */
3217 ieee_write_debug_part (bfd *abfd)
3219 ieee_data_type *ieee = IEEE_DATA (abfd);
3220 bfd_chain_type *chain = ieee->chain_root;
3221 unsigned char obuff[OBS];
3222 bfd_boolean some_debug = FALSE;
3223 file_ptr here = bfd_tell (abfd);
3225 output_ptr_start = output_ptr = obuff;
3226 output_ptr_end = obuff + OBS;
3230 if (chain == (bfd_chain_type *) NULL)
3234 for (s = abfd->sections; s != NULL; s = s->next)
3235 if ((s->flags & SEC_DEBUGGING) != 0)
3239 ieee->w.r.debug_information_part = 0;
3243 ieee->w.r.debug_information_part = here;
3244 if (bfd_bwrite (s->contents, s->size, abfd) != s->size)
3249 while (chain != (bfd_chain_type *) NULL)
3251 bfd *entry = chain->this;
3252 ieee_data_type *entry_ieee = IEEE_DATA (entry);
3254 if (entry_ieee->w.r.debug_information_part)
3256 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
3259 relocate_debug (abfd, entry);
3262 chain = chain->next;
3266 ieee->w.r.debug_information_part = here;
3268 ieee->w.r.debug_information_part = 0;
3276 /* Write the data in an ieee way. */
3279 ieee_write_data_part (bfd *abfd)
3283 ieee_data_type *ieee = IEEE_DATA (abfd);
3284 ieee->w.r.data_part = bfd_tell (abfd);
3286 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3288 /* Skip sections that have no loadable contents (.bss,
3290 if ((s->flags & SEC_LOAD) == 0)
3293 /* Sort the reloc records so we can insert them in the correct
3295 if (s->reloc_count != 0)
3297 if (! do_with_relocs (abfd, s))
3302 if (! do_without_relocs (abfd, s))
3311 init_for_output (bfd *abfd)
3315 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3317 if ((s->flags & SEC_DEBUGGING) != 0)
3321 bfd_size_type size = s->size;
3322 ieee_per_section (s)->data = bfd_alloc (abfd, size);
3323 if (!ieee_per_section (s)->data)
3330 /* Exec and core file sections. */
3332 /* Set section contents is complicated with IEEE since the format is
3333 not a byte image, but a record stream. */
3336 ieee_set_section_contents (bfd *abfd,
3338 const void * location,
3340 bfd_size_type count)
3342 if ((section->flags & SEC_DEBUGGING) != 0)
3344 if (section->contents == NULL)
3346 bfd_size_type size = section->size;
3347 section->contents = bfd_alloc (abfd, size);
3348 if (section->contents == NULL)
3351 /* bfd_set_section_contents has already checked that everything
3353 memcpy (section->contents + offset, location, (size_t) count);
3357 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
3359 if (!init_for_output (abfd))
3362 memcpy ((void *) (ieee_per_section (section)->data + offset),
3364 (unsigned int) count);
3368 /* Write the external symbols of a file. IEEE considers two sorts of
3369 external symbols, public, and referenced. It uses to internal
3370 forms to index them as well. When we write them out we turn their
3371 symbol values into indexes from the right base. */
3374 ieee_write_external_part (bfd *abfd)
3377 ieee_data_type *ieee = IEEE_DATA (abfd);
3378 unsigned int reference_index = IEEE_REFERENCE_BASE;
3379 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
3380 file_ptr here = bfd_tell (abfd);
3381 bfd_boolean hadone = FALSE;
3383 if (abfd->outsymbols != (asymbol **) NULL)
3386 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
3390 if (bfd_is_und_section (p->section))
3392 /* This must be a symbol reference. */
3393 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3394 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3395 || ! ieee_write_id (abfd, p->name))
3397 p->value = reference_index;
3401 else if (bfd_is_com_section (p->section))
3403 /* This is a weak reference. */
3404 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3405 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3406 || ! ieee_write_id (abfd, p->name)
3407 || ! ieee_write_byte (abfd,
3408 ieee_weak_external_reference_enum)
3409 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3410 || ! ieee_write_int (abfd, p->value))
3412 p->value = reference_index;
3416 else if (p->flags & BSF_GLOBAL)
3418 /* This must be a symbol definition. */
3419 if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
3420 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3421 || ! ieee_write_id (abfd, p->name)
3422 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
3423 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3424 || ! ieee_write_byte (abfd, 15) /* Instruction address. */
3425 || ! ieee_write_byte (abfd, 19) /* Static symbol. */
3426 || ! ieee_write_byte (abfd, 1)) /* One of them. */
3429 /* Write out the value. */
3430 if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
3431 || ! ieee_write_int (abfd, (bfd_vma) public_index))
3433 if (! bfd_is_abs_section (p->section))
3435 if (abfd->flags & EXEC_P)
3437 /* If fully linked, then output all symbols
3439 if (! (ieee_write_int
3442 + p->section->output_offset
3443 + p->section->output_section->vma))))
3448 if (! (ieee_write_expression
3450 p->value + p->section->output_offset,
3451 p->section->output_section->symbol,
3458 if (! ieee_write_expression (abfd,
3460 bfd_abs_section_ptr->symbol,
3464 p->value = public_index;
3470 /* This can happen - when there are gaps in the symbols read
3471 from an input ieee file. */
3476 ieee->w.r.external_part = here;
3482 static const unsigned char exten[] =
3485 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3486 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
3487 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
3490 static const unsigned char envi[] =
3494 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3497 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */
3499 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */
3500 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3504 ieee_write_me_part (bfd *abfd)
3506 ieee_data_type *ieee = IEEE_DATA (abfd);
3507 ieee->w.r.trailer_part = bfd_tell (abfd);
3508 if (abfd->start_address)
3510 if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
3511 || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
3512 || ! ieee_write_int (abfd, abfd->start_address)
3513 || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
3516 ieee->w.r.me_record = bfd_tell (abfd);
3517 if (! ieee_write_byte (abfd, ieee_module_end_enum))
3522 /* Write out the IEEE processor ID. */
3525 ieee_write_processor (bfd *abfd)
3527 const bfd_arch_info_type *arch;
3529 arch = bfd_get_arch_info (abfd);
3533 if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
3537 case bfd_arch_h8300:
3538 if (! ieee_write_id (abfd, "H8/300"))
3542 case bfd_arch_h8500:
3543 if (! ieee_write_id (abfd, "H8/500"))
3551 case bfd_mach_i960_core:
3552 case bfd_mach_i960_ka_sa:
3553 if (! ieee_write_id (abfd, "80960KA"))
3557 case bfd_mach_i960_kb_sb:
3558 if (! ieee_write_id (abfd, "80960KB"))
3562 case bfd_mach_i960_ca:
3563 if (! ieee_write_id (abfd, "80960CA"))
3567 case bfd_mach_i960_mc:
3568 case bfd_mach_i960_xa:
3569 if (! ieee_write_id (abfd, "80960MC"))
3581 default: id = "68020"; break;
3582 case bfd_mach_m68000: id = "68000"; break;
3583 case bfd_mach_m68008: id = "68008"; break;
3584 case bfd_mach_m68010: id = "68010"; break;
3585 case bfd_mach_m68020: id = "68020"; break;
3586 case bfd_mach_m68030: id = "68030"; break;
3587 case bfd_mach_m68040: id = "68040"; break;
3588 case bfd_mach_m68060: id = "68060"; break;
3589 case bfd_mach_cpu32: id = "cpu32"; break;
3590 case bfd_mach_mcf_isa_a_nodiv: id = "isa-a:nodiv"; break;
3591 case bfd_mach_mcf_isa_a: id = "isa-a"; break;
3592 case bfd_mach_mcf_isa_a_mac: id = "isa-a:mac"; break;
3593 case bfd_mach_mcf_isa_a_emac: id = "isa-a:emac"; break;
3594 case bfd_mach_mcf_isa_aplus: id = "isa-aplus"; break;
3595 case bfd_mach_mcf_isa_aplus_mac: id = "isa-aplus:mac"; break;
3596 case bfd_mach_mcf_isa_aplus_emac: id = "isa-aplus:mac"; break;
3597 case bfd_mach_mcf_isa_b_nousp: id = "isa-b:nousp"; break;
3598 case bfd_mach_mcf_isa_b_nousp_mac: id = "isa-b:nousp:mac"; break;
3599 case bfd_mach_mcf_isa_b_nousp_emac: id = "isa-b:nousp:emac"; break;
3600 case bfd_mach_mcf_isa_b: id = "isa-b"; break;
3601 case bfd_mach_mcf_isa_b_mac: id = "isa-b:mac"; break;
3602 case bfd_mach_mcf_isa_b_emac: id = "isa-b:emac"; break;
3603 case bfd_mach_mcf_isa_b_float: id = "isa-b:float"; break;
3604 case bfd_mach_mcf_isa_b_float_mac: id = "isa-b:float:mac"; break;
3605 case bfd_mach_mcf_isa_b_float_emac: id = "isa-b:float:emac"; break;
3606 case bfd_mach_mcf_isa_c: id = "isa-c"; break;
3607 case bfd_mach_mcf_isa_c_mac: id = "isa-c:mac"; break;
3608 case bfd_mach_mcf_isa_c_emac: id = "isa-c:emac"; break;
3609 case bfd_mach_mcf_isa_c_nodiv: id = "isa-c:nodiv"; break;
3610 case bfd_mach_mcf_isa_c_nodiv_mac: id = "isa-c:nodiv:mac"; break;
3611 case bfd_mach_mcf_isa_c_nodiv_emac: id = "isa-c:nodiv:emac"; break;
3614 if (! ieee_write_id (abfd, id))
3624 ieee_write_object_contents (bfd *abfd)
3626 ieee_data_type *ieee = IEEE_DATA (abfd);
3630 /* Fast forward over the header area. */
3631 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3634 if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
3635 || ! ieee_write_processor (abfd)
3636 || ! ieee_write_id (abfd, abfd->filename))
3639 /* Fast forward over the variable bits. */
3640 if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
3644 if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
3646 /* MAU's per address. */
3647 if (! ieee_write_byte (abfd,
3648 (bfd_byte) (bfd_arch_bits_per_address (abfd)
3649 / bfd_arch_bits_per_byte (abfd))))
3652 old = bfd_tell (abfd);
3653 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3656 ieee->w.r.extension_record = bfd_tell (abfd);
3657 if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
3660 if (abfd->flags & EXEC_P)
3662 if (! ieee_write_byte (abfd, 0x1)) /* Absolute. */
3667 if (! ieee_write_byte (abfd, 0x2)) /* Relocateable. */
3671 ieee->w.r.environmental_record = bfd_tell (abfd);
3672 if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
3676 /* The HP emulator database requires a timestamp in the file. */
3682 t = (struct tm *) localtime (&now);
3683 if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
3684 || ! ieee_write_byte (abfd, 0x21)
3685 || ! ieee_write_byte (abfd, 0)
3686 || ! ieee_write_byte (abfd, 50)
3687 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
3688 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
3689 || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
3690 || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
3691 || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
3692 || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
3700 if (! ieee_write_section_part (abfd))
3702 /* First write the symbols. This changes their values into table
3703 indeces so we cant use it after this point. */
3704 if (! ieee_write_external_part (abfd))
3707 /* Write any debugs we have been told about. */
3708 if (! ieee_write_debug_part (abfd))
3711 /* Can only write the data once the symbols have been written, since
3712 the data contains relocation information which points to the
3714 if (! ieee_write_data_part (abfd))
3717 /* At the end we put the end! */
3718 if (! ieee_write_me_part (abfd))
3721 /* Generate the header. */
3722 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3725 for (i = 0; i < N_W_VARIABLES; i++)
3727 if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
3728 || ! ieee_write_byte (abfd, (bfd_byte) i)
3729 || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
3736 /* Native-level interface to symbols. */
3738 /* We read the symbols into a buffer, which is discarded when this
3739 function exits. We read the strings into a buffer large enough to
3740 hold them all plus all the cached symbol entries. */
3743 ieee_make_empty_symbol (bfd *abfd)
3745 bfd_size_type amt = sizeof (ieee_symbol_type);
3746 ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_zalloc (abfd, amt);
3750 new_symbol->symbol.the_bfd = abfd;
3751 return &new_symbol->symbol;
3755 ieee_openr_next_archived_file (bfd *arch, bfd *prev)
3757 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3759 /* Take the next one from the arch state, or reset. */
3760 if (prev == (bfd *) NULL)
3761 /* Reset the index - the first two entries are bogus. */
3762 ar->element_index = 2;
3766 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3768 ar->element_index++;
3769 if (ar->element_index <= ar->element_count)
3771 if (p->file_offset != (file_ptr) 0)
3773 if (p->abfd == (bfd *) NULL)
3775 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3776 p->abfd->origin = p->file_offset;
3783 bfd_set_error (bfd_error_no_more_archived_files);
3789 #define ieee_find_nearest_line _bfd_nosymbols_find_nearest_line
3790 #define ieee_find_line _bfd_nosymbols_find_line
3791 #define ieee_find_inliner_info _bfd_nosymbols_find_inliner_info
3794 ieee_generic_stat_arch_elt (bfd *abfd, struct stat *buf)
3796 ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
3797 ieee_data_type *ieee;
3799 if (abfd->my_archive != NULL)
3800 ar = abfd->my_archive->tdata.ieee_ar_data;
3801 if (ar == (ieee_ar_data_type *) NULL)
3803 bfd_set_error (bfd_error_invalid_operation);
3807 if (IEEE_DATA (abfd) == NULL)
3809 if (ieee_object_p (abfd) == NULL)
3811 bfd_set_error (bfd_error_wrong_format);
3816 ieee = IEEE_DATA (abfd);
3818 buf->st_size = ieee->w.r.me_record + 1;
3819 buf->st_mode = 0644;
3824 ieee_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
3825 struct bfd_link_info *info ATTRIBUTE_UNUSED)
3830 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3831 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3833 #define ieee_slurp_armap bfd_true
3834 #define ieee_slurp_extended_name_table bfd_true
3835 #define ieee_construct_extended_name_table \
3837 (bfd *, char **, bfd_size_type *, const char **)) \
3839 #define ieee_truncate_arname bfd_dont_truncate_arname
3840 #define ieee_write_armap \
3842 (bfd *, unsigned int, struct orl *, unsigned int, int)) \
3844 #define ieee_read_ar_hdr bfd_nullvoidptr
3845 #define ieee_write_ar_hdr ((bfd_boolean (*) (bfd *, bfd *)) bfd_false)
3846 #define ieee_update_armap_timestamp bfd_true
3847 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3849 #define ieee_get_symbol_version_string \
3850 _bfd_nosymbols_get_symbol_version_string
3851 #define ieee_bfd_is_target_special_symbol \
3852 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
3853 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3854 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3855 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3856 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3857 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3859 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3860 #define ieee_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
3862 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3864 #define ieee_get_section_contents_in_window \
3865 _bfd_generic_get_section_contents_in_window
3866 #define ieee_bfd_get_relocated_section_contents \
3867 bfd_generic_get_relocated_section_contents
3868 #define ieee_bfd_relax_section bfd_generic_relax_section
3869 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3870 #define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
3871 #define ieee_bfd_merge_sections bfd_generic_merge_sections
3872 #define ieee_bfd_is_group_section bfd_generic_is_group_section
3873 #define ieee_bfd_discard_group bfd_generic_discard_group
3874 #define ieee_section_already_linked \
3875 _bfd_generic_section_already_linked
3876 #define ieee_bfd_define_common_symbol bfd_generic_define_common_symbol
3877 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3878 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3879 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
3880 #define ieee_bfd_copy_link_hash_symbol_type \
3881 _bfd_generic_copy_link_hash_symbol_type
3882 #define ieee_bfd_final_link _bfd_generic_final_link
3883 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3884 #define ieee_bfd_link_check_relocs _bfd_generic_link_check_relocs
3886 const bfd_target ieee_vec =
3889 bfd_target_ieee_flavour,
3890 BFD_ENDIAN_UNKNOWN, /* Target byte order. */
3891 BFD_ENDIAN_UNKNOWN, /* Target headers byte order. */
3892 (HAS_RELOC | EXEC_P | /* Object flags. */
3893 HAS_LINENO | HAS_DEBUG |
3894 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3895 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3896 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
3897 '_', /* Leading underscore. */
3898 ' ', /* AR_pad_char. */
3899 16, /* AR_max_namelen. */
3900 0, /* match priority. */
3901 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3902 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3903 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
3904 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3905 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3906 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
3909 ieee_object_p, /* bfd_check_format. */
3916 _bfd_generic_mkarchive,
3921 ieee_write_object_contents,
3922 _bfd_write_archive_contents,
3926 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
3927 ieee_get_section_contents, ieee_get_section_contents_in_window. */
3928 BFD_JUMP_TABLE_GENERIC (ieee),
3930 BFD_JUMP_TABLE_COPY (_bfd_generic),
3931 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3933 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
3934 ieee_construct_extended_name_table, ieee_truncate_arname,
3935 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
3936 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
3937 ieee_update_armap_timestamp. */
3938 BFD_JUMP_TABLE_ARCHIVE (ieee),
3940 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
3941 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
3942 ieee_bfd_is_local_label_name, ieee_get_lineno,
3943 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
3944 ieee_read_minisymbols, ieee_minisymbol_to_symbol. */
3945 BFD_JUMP_TABLE_SYMBOLS (ieee),
3947 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
3948 ieee_bfd_reloc_type_lookup. */
3949 BFD_JUMP_TABLE_RELOCS (ieee),
3951 /* ieee_set_arch_mach, ieee_set_section_contents. */
3952 BFD_JUMP_TABLE_WRITE (ieee),
3954 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
3955 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
3956 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
3957 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
3958 ieee_bfd_merge_sections. */
3959 BFD_JUMP_TABLE_LINK (ieee),
3961 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),