1 /* BFD back-end for ieee-695 objects.
2 Copyright (C) 1990-2015 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))
157 (*_bfd_error_handler)
158 (_("%s: string too long (%d chars, max 65535)"),
159 bfd_get_filename (abfd), length);
160 bfd_set_error (bfd_error_invalid_operation);
164 if (bfd_bwrite ((void *) id, (bfd_size_type) length, abfd) != length)
169 /* Functions for reading from ieee files in the strange way that the
170 standard requires. */
172 #define this_byte(ieee) *((ieee)->input_p)
173 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
176 next_byte (common_header_type * ieee)
180 return ieee->input_p < ieee->last_byte;
183 static unsigned short
184 read_2bytes (common_header_type *ieee)
186 unsigned char c1 = this_byte_and_next (ieee);
187 unsigned char c2 = this_byte_and_next (ieee);
189 return (c1 << 8) | c2;
193 bfd_get_string (common_header_type *ieee, char *string, size_t length)
197 for (i = 0; i < length; i++)
198 string[i] = this_byte_and_next (ieee);
202 read_id (common_header_type *ieee)
207 length = this_byte_and_next (ieee);
209 /* Simple string of length 0 to 127. */
212 else if (length == 0xde)
213 /* Length is next byte, allowing 0..255. */
214 length = this_byte_and_next (ieee);
216 else if (length == 0xdf)
218 /* Length is next two bytes, allowing 0..65535. */
219 length = this_byte_and_next (ieee);
220 length = (length * 256) + this_byte_and_next (ieee);
223 /* Buy memory and read string. */
224 string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
227 bfd_get_string (ieee, string, length);
233 ieee_write_expression (bfd *abfd,
239 unsigned int term_count = 0;
243 if (! ieee_write_int (abfd, value))
248 /* Badly formatted binaries can have a missing symbol,
249 so test here to prevent a seg fault. */
252 if (bfd_is_com_section (symbol->section)
253 || bfd_is_und_section (symbol->section))
255 /* Def of a common symbol. */
256 if (! ieee_write_byte (abfd, ieee_variable_X_enum)
257 || ! ieee_write_int (abfd, symbol->value))
261 else if (! bfd_is_abs_section (symbol->section))
263 /* Ref to defined symbol - */
264 if (symbol->flags & BSF_GLOBAL)
266 if (! ieee_write_byte (abfd, ieee_variable_I_enum)
267 || ! ieee_write_int (abfd, symbol->value))
271 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
273 /* This is a reference to a defined local symbol. We can
274 easily do a local as a section+offset. */
275 if (! ieee_write_byte (abfd, ieee_variable_R_enum)
276 || ! ieee_write_byte (abfd,
277 (bfd_byte) (symbol->section->index
278 + IEEE_SECTION_NUMBER_BASE)))
282 if (symbol->value != 0)
284 if (! ieee_write_int (abfd, symbol->value))
291 (*_bfd_error_handler)
292 (_("%s: unrecognized symbol `%s' flags 0x%x"),
293 bfd_get_filename (abfd), bfd_asymbol_name (symbol),
295 bfd_set_error (bfd_error_invalid_operation);
303 /* Subtract the pc from here by asking for PC of this section. */
304 if (! ieee_write_byte (abfd, ieee_variable_P_enum)
305 || ! ieee_write_byte (abfd,
306 (bfd_byte) (sindex + IEEE_SECTION_NUMBER_BASE))
307 || ! ieee_write_byte (abfd, ieee_function_minus_enum))
311 /* Handle the degenerate case of a 0 address. */
313 if (! ieee_write_int (abfd, (bfd_vma) 0))
316 while (term_count > 1)
318 if (! ieee_write_byte (abfd, ieee_function_plus_enum))
326 /* Writes any integer into the buffer supplied and always takes 5 bytes. */
329 ieee_write_int5 (bfd_byte *buffer, bfd_vma value)
331 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
332 buffer[1] = (value >> 24) & 0xff;
333 buffer[2] = (value >> 16) & 0xff;
334 buffer[3] = (value >> 8) & 0xff;
335 buffer[4] = (value >> 0) & 0xff;
339 ieee_write_int5_out (bfd *abfd, bfd_vma value)
343 ieee_write_int5 (b, value);
344 if (bfd_bwrite ((void *) b, (bfd_size_type) 5, abfd) != 5)
350 parse_int (common_header_type *ieee, bfd_vma *value_ptr)
352 int value = this_byte (ieee);
355 if (value >= 0 && value <= 127)
358 return next_byte (ieee);
360 else if (value >= 0x80 && value <= 0x88)
362 unsigned int count = value & 0xf;
365 if (! next_byte (ieee))
369 result = (result << 8) | this_byte_and_next (ieee);
379 parse_i (common_header_type *ieee, bfd_boolean *ok)
382 *ok = parse_int (ieee, &x);
387 must_parse_int (common_header_type *ieee)
390 BFD_ASSERT (parse_int (ieee, &result));
398 ieee_symbol_index_type symbol;
402 #if KEEPMINUSPCININST
404 #define SRC_MASK(arg) arg
405 #define PCREL_OFFSET FALSE
409 #define SRC_MASK(arg) 0
410 #define PCREL_OFFSET TRUE
414 static reloc_howto_type abs32_howto =
421 complain_overflow_bitfield,
429 static reloc_howto_type abs16_howto =
436 complain_overflow_bitfield,
444 static reloc_howto_type abs8_howto =
451 complain_overflow_bitfield,
459 static reloc_howto_type rel32_howto =
466 complain_overflow_signed,
470 SRC_MASK (0xffffffff),
474 static reloc_howto_type rel16_howto =
481 complain_overflow_signed,
485 SRC_MASK (0x0000ffff),
489 static reloc_howto_type rel8_howto =
496 complain_overflow_signed,
500 SRC_MASK (0x000000ff),
504 static ieee_symbol_index_type NOSYMBOL = {0, 0};
507 parse_expression (ieee_data_type *ieee,
509 ieee_symbol_index_type *symbol,
515 bfd_boolean loop = TRUE;
516 ieee_value_type stack[10];
517 ieee_value_type *sp = stack;
526 /* The stack pointer always points to the next unused location. */
527 #define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC;
528 #define POP(x,y,z) DEC; x = TOS.symbol; y = TOS.section; z = TOS.value;
530 while (loop && ieee->h.input_p < ieee->h.last_byte)
532 switch (this_byte (&(ieee->h)))
534 case ieee_variable_P_enum:
535 /* P variable, current program counter for section n. */
539 if (! next_byte (&(ieee->h)))
542 section_n = must_parse_int (&(ieee->h));
544 PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
548 case ieee_variable_L_enum:
549 /* L variable address of section N. */
550 if (! next_byte (&(ieee->h)))
552 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
555 case ieee_variable_R_enum:
556 /* R variable, logical address of section module. */
557 /* FIXME, this should be different to L. */
558 if (! next_byte (&(ieee->h)))
560 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
563 case ieee_variable_S_enum:
564 /* S variable, size in MAUS of section module. */
565 if (! next_byte (&(ieee->h)))
569 ieee->section_table[must_parse_int (&(ieee->h))]->size);
572 case ieee_variable_I_enum:
573 /* Push the address of variable n. */
575 ieee_symbol_index_type sy;
577 if (! next_byte (&(ieee->h)))
579 sy.index = (int) must_parse_int (&(ieee->h));
582 PUSH (sy, bfd_abs_section_ptr, 0);
586 case ieee_variable_X_enum:
587 /* Push the address of external variable n. */
589 ieee_symbol_index_type sy;
591 if (! next_byte (&(ieee->h)))
594 sy.index = (int) (must_parse_int (&(ieee->h)));
597 PUSH (sy, bfd_und_section_ptr, 0);
601 case ieee_function_minus_enum:
603 bfd_vma value1, value2;
604 asection *section1, *section_dummy;
605 ieee_symbol_index_type sy;
607 if (! next_byte (&(ieee->h)))
610 POP (sy, section1, value1);
611 POP (sy, section_dummy, value2);
612 PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
616 case ieee_function_plus_enum:
618 bfd_vma value1, value2;
621 ieee_symbol_index_type sy1;
622 ieee_symbol_index_type sy2;
624 if (! next_byte (&(ieee->h)))
627 POP (sy1, section1, value1);
628 POP (sy2, section2, value2);
629 PUSH (sy1.letter ? sy1 : sy2,
630 bfd_is_abs_section (section1) ? section2 : section1,
639 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
640 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
641 if (parse_int (&(ieee->h), &va))
643 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
646 /* Thats all that we can understand. */
652 /* As far as I can see there is a bug in the Microtec IEEE output
653 which I'm using to scan, whereby the comma operator is omitted
654 sometimes in an expression, giving expressions with too many
655 terms. We can tell if that's the case by ensuring that
656 sp == stack here. If not, then we've pushed something too far,
657 so we keep adding. */
658 while (sp != stack + 1)
661 ieee_symbol_index_type sy1;
663 POP (sy1, section1, *extra);
668 POP (*symbol, dummy, *value);
675 #define ieee_pos(ieee) \
676 (ieee->h.input_p - ieee->h.first_byte)
678 /* Find the first part of the ieee file after HERE. */
681 ieee_part_after (ieee_data_type *ieee, file_ptr here)
684 file_ptr after = ieee->w.r.me_record;
686 /* File parts can come in any order, except that module end is
687 guaranteed to be last (and the header first). */
688 for (part = 0; part < N_W_VARIABLES; part++)
689 if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
690 after = ieee->w.offset[part];
696 ieee_seek (ieee_data_type * ieee, file_ptr offset)
698 /* PR 17512: file: 017-1157-0.004. */
699 if (offset < 0 || (bfd_size_type) offset >= ieee->h.total_amt)
701 ieee->h.input_p = ieee->h.first_byte + ieee->h.total_amt;
702 ieee->h.last_byte = ieee->h.input_p;
706 ieee->h.input_p = ieee->h.first_byte + offset;
707 ieee->h.last_byte = (ieee->h.first_byte + ieee_part_after (ieee, offset));
711 static unsigned int last_index;
712 static char last_type; /* Is the index for an X or a D. */
714 static ieee_symbol_type *
715 get_symbol (bfd *abfd ATTRIBUTE_UNUSED,
716 ieee_data_type *ieee,
717 ieee_symbol_type *last_symbol,
718 unsigned int *symbol_count,
719 ieee_symbol_type ***pptr,
720 unsigned int *max_index,
723 /* Need a new symbol. */
724 unsigned int new_index = must_parse_int (&(ieee->h));
726 if (new_index != last_index || this_type != last_type)
728 ieee_symbol_type *new_symbol;
729 bfd_size_type amt = sizeof (ieee_symbol_type);
731 new_symbol = bfd_alloc (ieee->h.abfd, amt);
735 new_symbol->index = new_index;
736 last_index = new_index;
739 *pptr = &new_symbol->next;
740 if (new_index > *max_index)
741 *max_index = new_index;
743 last_type = this_type;
744 new_symbol->symbol.section = bfd_abs_section_ptr;
751 ieee_slurp_external_symbols (bfd *abfd)
753 ieee_data_type *ieee = IEEE_DATA (abfd);
754 file_ptr offset = ieee->w.r.external_part;
756 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
757 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
758 ieee_symbol_type *symbol = NULL;
759 unsigned int symbol_count = 0;
760 bfd_boolean loop = TRUE;
762 last_index = 0xffffff;
763 ieee->symbol_table_full = TRUE;
765 if (! ieee_seek (ieee, offset))
770 switch (this_byte (&(ieee->h)))
773 if (! next_byte (&(ieee->h)))
776 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
778 & ieee->external_symbol_max_index, 'I');
782 symbol->symbol.the_bfd = abfd;
783 symbol->symbol.name = read_id (&(ieee->h));
784 symbol->symbol.udata.p = NULL;
785 symbol->symbol.flags = BSF_NO_FLAGS;
788 case ieee_external_symbol_enum:
789 if (! next_byte (&(ieee->h)))
792 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
794 &ieee->external_symbol_max_index, 'D');
798 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
800 symbol->symbol.the_bfd = abfd;
801 symbol->symbol.name = read_id (&(ieee->h));
802 symbol->symbol.udata.p = NULL;
803 symbol->symbol.flags = BSF_NO_FLAGS;
805 case ieee_attribute_record_enum >> 8:
807 unsigned int symbol_name_index;
808 unsigned int symbol_type_index;
809 unsigned int symbol_attribute_def;
812 switch (read_2bytes (&ieee->h))
814 case ieee_attribute_record_enum:
815 symbol_name_index = must_parse_int (&(ieee->h));
816 symbol_type_index = must_parse_int (&(ieee->h));
817 (void) symbol_type_index;
818 symbol_attribute_def = must_parse_int (&(ieee->h));
819 switch (symbol_attribute_def)
823 parse_int (&ieee->h, &value);
826 (*_bfd_error_handler)
827 (_("%B: unimplemented ATI record %u for symbol %u"),
828 abfd, symbol_attribute_def, symbol_name_index);
829 bfd_set_error (bfd_error_bad_value);
834 case ieee_external_reference_info_record_enum:
835 /* Skip over ATX record. */
836 parse_int (&(ieee->h), &value);
837 parse_int (&(ieee->h), &value);
838 parse_int (&(ieee->h), &value);
839 parse_int (&(ieee->h), &value);
841 case ieee_atn_record_enum:
842 /* We may get call optimization information here,
843 which we just ignore. The format is
844 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */
845 parse_int (&ieee->h, &value);
846 parse_int (&ieee->h, &value);
847 parse_int (&ieee->h, &value);
850 (*_bfd_error_handler)
851 (_("%B: unexpected ATN type %d in external part"),
853 bfd_set_error (bfd_error_bad_value);
856 parse_int (&ieee->h, &value);
857 parse_int (&ieee->h, &value);
864 switch (read_2bytes (&ieee->h))
866 case ieee_asn_record_enum:
867 parse_int (&ieee->h, &val1);
868 parse_int (&ieee->h, &val1);
872 (*_bfd_error_handler)
873 (_("%B: unexpected type after ATN"), abfd);
874 bfd_set_error (bfd_error_bad_value);
882 case ieee_value_record_enum >> 8:
884 unsigned int symbol_name_index;
885 ieee_symbol_index_type symbol_ignore;
886 bfd_boolean pcrel_ignore;
889 if (! next_byte (&(ieee->h)))
891 if (! next_byte (&(ieee->h)))
894 symbol_name_index = must_parse_int (&(ieee->h));
895 (void) symbol_name_index;
896 if (! parse_expression (ieee,
897 &symbol->symbol.value,
901 &symbol->symbol.section))
904 /* Fully linked IEEE-695 files tend to give every symbol
905 an absolute value. Try to convert that back into a
906 section relative value. FIXME: This won't always to
908 if (bfd_is_abs_section (symbol->symbol.section)
909 && (abfd->flags & HAS_RELOC) == 0)
914 val = symbol->symbol.value;
915 for (s = abfd->sections; s != NULL; s = s->next)
917 if (val >= s->vma && val < s->vma + s->size)
919 symbol->symbol.section = s;
920 symbol->symbol.value -= s->vma;
926 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
930 case ieee_weak_external_reference_enum:
935 if (! next_byte (&(ieee->h)))
938 /* Throw away the external reference index. */
939 (void) must_parse_int (&(ieee->h));
940 /* Fetch the default size if not resolved. */
941 size = must_parse_int (&(ieee->h));
942 /* Fetch the default value if available. */
943 if (! parse_int (&(ieee->h), &value))
945 /* This turns into a common. */
946 symbol->symbol.section = bfd_com_section_ptr;
947 symbol->symbol.value = size;
951 case ieee_external_reference_enum:
952 if (! next_byte (&(ieee->h)))
955 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
957 &ieee->external_reference_max_index, 'X');
961 symbol->symbol.the_bfd = abfd;
962 symbol->symbol.name = read_id (&(ieee->h));
963 symbol->symbol.udata.p = NULL;
964 symbol->symbol.section = bfd_und_section_ptr;
965 symbol->symbol.value = (bfd_vma) 0;
966 symbol->symbol.flags = 0;
968 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
976 if (ieee->external_symbol_max_index != 0)
978 ieee->external_symbol_count =
979 ieee->external_symbol_max_index -
980 ieee->external_symbol_min_index + 1;
983 ieee->external_symbol_count = 0;
985 if (ieee->external_reference_max_index != 0)
987 ieee->external_reference_count =
988 ieee->external_reference_max_index -
989 ieee->external_reference_min_index + 1;
992 ieee->external_reference_count = 0;
995 ieee->external_reference_count + ieee->external_symbol_count;
997 if (symbol_count != abfd->symcount)
998 /* There are gaps in the table -- */
999 ieee->symbol_table_full = FALSE;
1001 *prev_symbols_ptr = NULL;
1002 *prev_reference_ptr = NULL;
1008 ieee_slurp_symbol_table (bfd *abfd)
1010 if (! IEEE_DATA (abfd)->read_symbols)
1012 if (! ieee_slurp_external_symbols (abfd))
1014 IEEE_DATA (abfd)->read_symbols = TRUE;
1020 ieee_get_symtab_upper_bound (bfd *abfd)
1022 if (! ieee_slurp_symbol_table (abfd))
1025 return (abfd->symcount != 0) ?
1026 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
1029 /* Move from our internal lists to the canon table, and insert in
1030 symbol index order. */
1032 extern const bfd_target ieee_vec;
1035 ieee_canonicalize_symtab (bfd *abfd, asymbol **location)
1037 ieee_symbol_type *symp;
1038 static bfd dummy_bfd;
1039 static asymbol empty_symbol =
1047 /* K&R compilers can't initialise unions. */
1054 ieee_data_type *ieee = IEEE_DATA (abfd);
1056 dummy_bfd.xvec = &ieee_vec;
1057 if (! ieee_slurp_symbol_table (abfd))
1060 if (! ieee->symbol_table_full)
1062 /* Arrgh - there are gaps in the table, run through and fill them
1063 up with pointers to a null place. */
1066 for (i = 0; i < abfd->symcount; i++)
1067 location[i] = &empty_symbol;
1070 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
1071 for (symp = IEEE_DATA (abfd)->external_symbols;
1072 symp != (ieee_symbol_type *) NULL;
1074 /* Place into table at correct index locations. */
1075 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
1077 /* The external refs are indexed in a bit. */
1078 ieee->external_reference_base_offset =
1079 -ieee->external_reference_min_index + ieee->external_symbol_count;
1081 for (symp = IEEE_DATA (abfd)->external_reference;
1082 symp != (ieee_symbol_type *) NULL;
1084 location[symp->index + ieee->external_reference_base_offset] =
1089 location[abfd->symcount] = (asymbol *) NULL;
1091 return abfd->symcount;
1095 get_section_entry (bfd *abfd, ieee_data_type *ieee, unsigned int sindex)
1097 if (sindex >= ieee->section_table_size)
1103 c = ieee->section_table_size;
1110 amt *= sizeof (asection *);
1111 n = bfd_realloc (ieee->section_table, amt);
1115 for (i = ieee->section_table_size; i < c; i++)
1118 ieee->section_table = n;
1119 ieee->section_table_size = c;
1122 if (ieee->section_table[sindex] == (asection *) NULL)
1124 char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
1129 sprintf (tmp, " fsec%4d", sindex);
1130 section = bfd_make_section (abfd, tmp);
1131 ieee->section_table[sindex] = section;
1132 section->target_index = sindex;
1133 ieee->section_table[sindex] = section;
1135 return ieee->section_table[sindex];
1139 ieee_slurp_sections (bfd *abfd)
1141 ieee_data_type *ieee = IEEE_DATA (abfd);
1142 file_ptr offset = ieee->w.r.section_part;
1147 bfd_byte section_type[3];
1149 if (! ieee_seek (ieee, offset))
1154 switch (this_byte (&(ieee->h)))
1156 case ieee_section_type_enum:
1159 unsigned int section_index;
1161 if (! next_byte (&(ieee->h)))
1163 section_index = must_parse_int (&(ieee->h));
1165 section = get_section_entry (abfd, ieee, section_index);
1167 section_type[0] = this_byte_and_next (&(ieee->h));
1169 /* Set minimal section attributes. Attributes are
1170 extended later, based on section contents. */
1171 switch (section_type[0])
1174 /* Normal attributes for absolute sections. */
1175 section_type[1] = this_byte (&(ieee->h));
1176 section->flags = SEC_ALLOC;
1177 switch (section_type[1])
1179 /* AS Absolute section attributes. */
1181 if (! next_byte (&(ieee->h)))
1183 section_type[2] = this_byte (&(ieee->h));
1184 switch (section_type[2])
1188 if (! next_byte (&(ieee->h)))
1190 section->flags |= SEC_CODE;
1194 if (! next_byte (&(ieee->h)))
1196 section->flags |= SEC_DATA;
1199 if (! next_byte (&(ieee->h)))
1201 /* Normal rom data. */
1202 section->flags |= SEC_ROM | SEC_DATA;
1210 /* Named relocatable sections (type C). */
1212 section_type[1] = this_byte (&(ieee->h));
1213 section->flags = SEC_ALLOC;
1214 switch (section_type[1])
1216 case 0xD0: /* Normal code (CP). */
1217 if (! next_byte (&(ieee->h)))
1219 section->flags |= SEC_CODE;
1221 case 0xC4: /* Normal data (CD). */
1222 if (! next_byte (&(ieee->h)))
1224 section->flags |= SEC_DATA;
1226 case 0xD2: /* Normal rom data (CR). */
1227 if (! next_byte (&(ieee->h)))
1229 section->flags |= SEC_ROM | SEC_DATA;
1236 /* Read section name, use it if non empty. */
1237 name = read_id (&ieee->h);
1239 section->name = name;
1241 /* Skip these fields, which we don't care about. */
1243 bfd_vma parent, brother, context;
1245 parse_int (&(ieee->h), &parent);
1246 parse_int (&(ieee->h), &brother);
1247 parse_int (&(ieee->h), &context);
1251 case ieee_section_alignment_enum:
1253 unsigned int section_index;
1257 if (! next_byte (&(ieee->h)))
1259 section_index = must_parse_int (&ieee->h);
1260 section = get_section_entry (abfd, ieee, section_index);
1261 if (section_index > ieee->section_count)
1262 ieee->section_count = section_index;
1264 section->alignment_power =
1265 bfd_log2 (must_parse_int (&ieee->h));
1266 (void) parse_int (&(ieee->h), &value);
1269 case ieee_e2_first_byte_enum:
1272 ieee_record_enum_type t;
1274 t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1277 case ieee_section_size_enum:
1278 section = ieee->section_table[must_parse_int (&(ieee->h))];
1279 section->size = must_parse_int (&(ieee->h));
1281 case ieee_physical_region_size_enum:
1282 section = ieee->section_table[must_parse_int (&(ieee->h))];
1283 section->size = must_parse_int (&(ieee->h));
1285 case ieee_region_base_address_enum:
1286 section = ieee->section_table[must_parse_int (&(ieee->h))];
1287 section->vma = must_parse_int (&(ieee->h));
1288 section->lma = section->vma;
1290 case ieee_mau_size_enum:
1291 must_parse_int (&(ieee->h));
1292 must_parse_int (&(ieee->h));
1294 case ieee_m_value_enum:
1295 must_parse_int (&(ieee->h));
1296 must_parse_int (&(ieee->h));
1298 case ieee_section_base_address_enum:
1299 section = ieee->section_table[must_parse_int (&(ieee->h))];
1300 section->vma = must_parse_int (&(ieee->h));
1301 section->lma = section->vma;
1303 case ieee_section_offset_enum:
1304 (void) must_parse_int (&(ieee->h));
1305 (void) must_parse_int (&(ieee->h));
1321 /* Make a section for the debugging information, if any. We don't try
1322 to interpret the debugging information; we just point the section
1323 at the area in the file so that program which understand can dig it
1327 ieee_slurp_debug (bfd *abfd)
1329 ieee_data_type *ieee = IEEE_DATA (abfd);
1334 if (ieee->w.r.debug_information_part == 0)
1337 flags = SEC_DEBUGGING | SEC_HAS_CONTENTS;
1338 sec = bfd_make_section_with_flags (abfd, ".debug", flags);
1341 sec->filepos = ieee->w.r.debug_information_part;
1343 debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
1344 sec->size = debug_end - ieee->w.r.debug_information_part;
1349 /* Archive stuff. */
1351 static const bfd_target *
1352 ieee_archive_p (bfd *abfd)
1356 unsigned char buffer[512];
1357 file_ptr buffer_offset = 0;
1358 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1359 ieee_ar_data_type *ieee;
1360 bfd_size_type alc_elts;
1361 ieee_ar_obstack_type *elts = NULL;
1362 bfd_size_type amt = sizeof (ieee_ar_data_type);
1364 abfd->tdata.ieee_ar_data = bfd_alloc (abfd, amt);
1365 if (!abfd->tdata.ieee_ar_data)
1366 goto error_ret_restore;
1367 ieee = IEEE_AR_DATA (abfd);
1369 /* Ignore the return value here. It doesn't matter if we don't read
1370 the entire buffer. We might have a very small ieee file. */
1371 if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0)
1372 goto got_wrong_format_error;
1374 ieee->h.first_byte = buffer;
1375 ieee->h.input_p = buffer;
1377 ieee->h.abfd = abfd;
1379 if (this_byte (&(ieee->h)) != Module_Beginning)
1380 goto got_wrong_format_error;
1382 (void) next_byte (&(ieee->h));
1384 library = read_id (&(ieee->h));
1385 if (strcmp (library, "LIBRARY") != 0)
1386 goto got_wrong_format_error;
1388 /* Throw away the filename. */
1389 read_id (&(ieee->h));
1391 ieee->element_count = 0;
1392 ieee->element_index = 0;
1394 (void) next_byte (&(ieee->h)); /* Drop the ad part. */
1395 must_parse_int (&(ieee->h)); /* And the two dummy numbers. */
1396 must_parse_int (&(ieee->h));
1399 elts = bfd_malloc (alc_elts * sizeof *elts);
1403 /* Read the index of the BB table. */
1407 ieee_ar_obstack_type *t;
1409 rec = read_2bytes (&(ieee->h));
1410 if (rec != (int) ieee_assign_value_to_variable_enum)
1413 if (ieee->element_count >= alc_elts)
1415 ieee_ar_obstack_type *n;
1418 n = bfd_realloc (elts, alc_elts * sizeof (* elts));
1424 t = &elts[ieee->element_count];
1425 ieee->element_count++;
1427 must_parse_int (&(ieee->h));
1428 t->file_offset = must_parse_int (&(ieee->h));
1429 t->abfd = (bfd *) NULL;
1431 /* Make sure that we don't go over the end of the buffer. */
1432 if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
1434 /* Past half way, reseek and reprime. */
1435 buffer_offset += ieee_pos (IEEE_DATA (abfd));
1436 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1439 /* Again ignore return value of bfd_bread. */
1440 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1441 ieee->h.first_byte = buffer;
1442 ieee->h.input_p = buffer;
1446 amt = ieee->element_count;
1447 amt *= sizeof *ieee->elements;
1448 ieee->elements = bfd_alloc (abfd, amt);
1449 if (ieee->elements == NULL)
1452 memcpy (ieee->elements, elts, (size_t) amt);
1456 /* Now scan the area again, and replace BB offsets with file offsets. */
1457 for (i = 2; i < ieee->element_count; i++)
1459 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1462 /* Again ignore return value of bfd_bread. */
1463 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1464 ieee->h.first_byte = buffer;
1465 ieee->h.input_p = buffer;
1467 (void) next_byte (&(ieee->h)); /* Drop F8. */
1468 if (! next_byte (&(ieee->h))) /* Drop 14. */
1470 must_parse_int (&(ieee->h)); /* Drop size of block. */
1472 if (must_parse_int (&(ieee->h)) != 0)
1473 /* This object has been deleted. */
1474 ieee->elements[i].file_offset = 0;
1476 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1479 /* abfd->has_armap = ;*/
1483 got_wrong_format_error:
1484 bfd_set_error (bfd_error_wrong_format);
1488 bfd_release (abfd, ieee);
1490 abfd->tdata.ieee_ar_data = save;
1496 ieee_mkobject (bfd *abfd)
1500 output_ptr_start = NULL;
1502 output_ptr_end = NULL;
1503 input_ptr_start = NULL;
1505 input_ptr_end = NULL;
1509 amt = sizeof (ieee_data_type);
1510 abfd->tdata.ieee_data = bfd_zalloc (abfd, amt);
1511 return abfd->tdata.ieee_data != NULL;
1515 do_one (ieee_data_type *ieee,
1516 ieee_per_section_type *current_map,
1517 unsigned char *location_ptr,
1521 switch (this_byte (&(ieee->h)))
1523 case ieee_load_constant_bytes_enum:
1525 unsigned int number_of_maus;
1528 if (! next_byte (&(ieee->h)))
1530 number_of_maus = must_parse_int (&(ieee->h));
1532 for (i = 0; i < number_of_maus; i++)
1534 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1535 next_byte (&(ieee->h));
1540 case ieee_load_with_relocation_enum:
1542 bfd_boolean loop = TRUE;
1544 if (! next_byte (&(ieee->h)))
1548 switch (this_byte (&(ieee->h)))
1550 case ieee_variable_R_enum:
1552 case ieee_function_signed_open_b_enum:
1553 case ieee_function_unsigned_open_b_enum:
1554 case ieee_function_either_open_b_enum:
1556 unsigned int extra = 4;
1557 bfd_boolean pcrel = FALSE;
1561 r = bfd_alloc (ieee->h.abfd, sizeof (* r));
1565 *(current_map->reloc_tail_ptr) = r;
1566 current_map->reloc_tail_ptr = &r->next;
1567 r->next = (ieee_reloc_type *) NULL;
1568 if (! next_byte (&(ieee->h)))
1571 r->relent.sym_ptr_ptr = 0;
1572 if (! parse_expression (ieee,
1575 &pcrel, &extra, §ion))
1578 r->relent.address = current_map->pc;
1579 s->flags |= SEC_RELOC;
1580 s->owner->flags |= HAS_RELOC;
1582 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
1583 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1585 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1587 if (! next_byte (&(ieee->h)))
1589 /* Fetch number of bytes to pad. */
1590 extra = must_parse_int (&(ieee->h));
1593 switch (this_byte (&(ieee->h)))
1595 case ieee_function_signed_close_b_enum:
1596 if (! next_byte (&(ieee->h)))
1599 case ieee_function_unsigned_close_b_enum:
1600 if (! next_byte (&(ieee->h)))
1603 case ieee_function_either_close_b_enum:
1604 if (! next_byte (&(ieee->h)))
1610 /* Build a relocation entry for this type. */
1611 /* If pc rel then stick -ve pc into instruction
1612 and take out of reloc ..
1614 I've changed this. It's all too complicated. I
1615 keep 0 in the instruction now. */
1624 #if KEEPMINUSPCININST
1625 bfd_put_32 (ieee->h.abfd, -current_map->pc,
1626 location_ptr + current_map->pc);
1627 r->relent.howto = &rel32_howto;
1628 r->relent.addend -= current_map->pc;
1630 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
1632 r->relent.howto = &rel32_howto;
1637 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
1638 location_ptr + current_map->pc);
1639 r->relent.howto = &abs32_howto;
1641 current_map->pc += 4;
1646 #if KEEPMINUSPCININST
1647 bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
1648 location_ptr + current_map->pc);
1649 r->relent.addend -= current_map->pc;
1650 r->relent.howto = &rel16_howto;
1653 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1654 location_ptr + current_map->pc);
1655 r->relent.howto = &rel16_howto;
1661 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1662 location_ptr + current_map->pc);
1663 r->relent.howto = &abs16_howto;
1665 current_map->pc += 2;
1670 #if KEEPMINUSPCININST
1671 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1672 r->relent.addend -= current_map->pc;
1673 r->relent.howto = &rel8_howto;
1675 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1676 r->relent.howto = &rel8_howto;
1681 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1682 r->relent.howto = &abs8_howto;
1684 current_map->pc += 1;
1697 if (parse_int (&(ieee->h), &this_size))
1701 for (i = 0; i < this_size; i++)
1703 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1704 if (! next_byte (&(ieee->h)))
1713 /* Prevent more than the first load-item of an LR record
1714 from being repeated (MRI convention). */
1715 if (iterations != 1)
1723 /* Read in all the section data and relocation stuff too. */
1726 ieee_slurp_section_data (bfd *abfd)
1728 bfd_byte *location_ptr = (bfd_byte *) NULL;
1729 ieee_data_type *ieee = IEEE_DATA (abfd);
1730 unsigned int section_number;
1731 ieee_per_section_type *current_map = NULL;
1734 /* Seek to the start of the data area. */
1735 if (ieee->read_data)
1737 ieee->read_data = TRUE;
1739 if (! ieee_seek (ieee, ieee->w.r.data_part))
1742 /* Allocate enough space for all the section contents. */
1743 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1745 ieee_per_section_type *per = ieee_per_section (s);
1748 if ((s->flags & SEC_DEBUGGING) != 0)
1750 per->data = bfd_alloc (ieee->h.abfd, s->size);
1753 relpp = &s->relocation;
1754 per->reloc_tail_ptr = (ieee_reloc_type **) relpp;
1759 switch (this_byte (&(ieee->h)))
1761 /* IF we see anything strange then quit. */
1765 case ieee_set_current_section_enum:
1766 if (! next_byte (&(ieee->h)))
1768 section_number = must_parse_int (&(ieee->h));
1769 s = ieee->section_table[section_number];
1770 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
1771 current_map = ieee_per_section (s);
1772 location_ptr = current_map->data - s->vma;
1773 /* The document I have says that Microtec's compilers reset
1774 this after a sec section, even though the standard says not
1776 current_map->pc = s->vma;
1779 case ieee_e2_first_byte_enum:
1780 if (! next_byte (&(ieee->h)))
1782 switch (this_byte (&(ieee->h)))
1784 case ieee_set_current_pc_enum & 0xff:
1787 ieee_symbol_index_type symbol;
1791 if (! next_byte (&(ieee->h)))
1793 must_parse_int (&(ieee->h)); /* Throw away section #. */
1794 if (! parse_expression (ieee, &value,
1800 current_map->pc = value;
1801 BFD_ASSERT ((unsigned) (value - s->vma) <= s->size);
1805 case ieee_value_starting_address_enum & 0xff:
1806 if (! next_byte (&(ieee->h)))
1808 if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
1810 if (! next_byte (&(ieee->h)))
1813 abfd->start_address = must_parse_int (&(ieee->h));
1814 /* We've got to the end of the data now - */
1821 case ieee_repeat_data_enum:
1823 /* Repeat the following LD or LR n times - we do this by
1824 remembering the stream pointer before running it and
1825 resetting it and running it n times. We special case
1826 the repetition of a repeat_data/load_constant. */
1827 unsigned int iterations;
1828 unsigned char *start;
1830 if (! next_byte (&(ieee->h)))
1832 iterations = must_parse_int (&(ieee->h));
1833 start = ieee->h.input_p;
1834 if (start[0] == (int) ieee_load_constant_bytes_enum
1837 while (iterations != 0)
1839 location_ptr[current_map->pc++] = start[2];
1842 (void) next_byte (&(ieee->h));
1843 (void) next_byte (&(ieee->h));
1844 if (! next_byte (&(ieee->h)))
1849 while (iterations != 0)
1851 ieee->h.input_p = start;
1852 if (!do_one (ieee, current_map, location_ptr, s,
1860 case ieee_load_constant_bytes_enum:
1861 case ieee_load_with_relocation_enum:
1862 if (!do_one (ieee, current_map, location_ptr, s, 1))
1868 static const bfd_target *
1869 ieee_object_p (bfd *abfd)
1873 ieee_data_type *ieee;
1874 unsigned char buffer[300];
1875 ieee_data_type *save = IEEE_DATA (abfd);
1878 abfd->tdata.ieee_data = 0;
1879 ieee_mkobject (abfd);
1881 ieee = IEEE_DATA (abfd);
1882 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1884 /* Read the first few bytes in to see if it makes sense. Ignore
1885 bfd_bread return value; The file might be very small. */
1886 if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0)
1887 goto got_wrong_format;
1889 ieee->h.input_p = buffer;
1890 ieee->h.total_amt = sizeof (buffer);
1891 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1892 goto got_wrong_format;
1894 ieee->read_symbols = FALSE;
1895 ieee->read_data = FALSE;
1896 ieee->section_count = 0;
1897 ieee->external_symbol_max_index = 0;
1898 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1899 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1900 ieee->external_reference_max_index = 0;
1901 ieee->h.abfd = abfd;
1902 ieee->section_table = NULL;
1903 ieee->section_table_size = 0;
1905 processor = ieee->mb.processor = read_id (&(ieee->h));
1906 if (strcmp (processor, "LIBRARY") == 0)
1907 goto got_wrong_format;
1908 ieee->mb.module_name = read_id (&(ieee->h));
1909 if (abfd->filename == (const char *) NULL)
1910 abfd->filename = xstrdup (ieee->mb.module_name);
1912 /* Determine the architecture and machine type of the object file. */
1914 const bfd_arch_info_type *arch;
1917 /* IEEE does not specify the format of the processor identification
1918 string, so the compiler is free to put in it whatever it wants.
1919 We try here to recognize different processors belonging to the
1920 m68k family. Code for other processors can be added here. */
1921 if ((processor[0] == '6') && (processor[1] == '8'))
1923 if (processor[2] == '3') /* 683xx integrated processors. */
1925 switch (processor[3])
1927 case '0': /* 68302, 68306, 68307 */
1928 case '2': /* 68322, 68328 */
1929 case '5': /* 68356 */
1930 strcpy (family, "68000"); /* MC68000-based controllers. */
1933 case '3': /* 68330, 68331, 68332, 68333,
1934 68334, 68335, 68336, 68338 */
1935 case '6': /* 68360 */
1936 case '7': /* 68376 */
1937 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1941 if (processor[4] == '9') /* 68349 */
1942 strcpy (family, "68030"); /* CPU030 */
1943 else /* 68340, 68341 */
1944 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1947 default: /* Does not exist yet. */
1948 strcpy (family, "68332"); /* Guess it will be CPU32 */
1951 else if (TOUPPER (processor[3]) == 'F') /* 68F333 */
1952 strcpy (family, "68332"); /* CPU32 */
1953 else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers. */
1954 && ((TOUPPER (processor[2]) == 'E')
1955 || (TOUPPER (processor[2]) == 'H')
1956 || (TOUPPER (processor[2]) == 'L')))
1958 strcpy (family, "68");
1959 strncat (family, processor + 4, 7);
1962 else /* "Regular" processors. */
1964 strncpy (family, processor, 9);
1968 else if ((CONST_STRNEQ (processor, "cpu32")) /* CPU32 and CPU32+ */
1969 || (CONST_STRNEQ (processor, "CPU32")))
1970 strcpy (family, "68332");
1973 strncpy (family, processor, 9);
1977 arch = bfd_scan_arch (family);
1979 goto got_wrong_format;
1980 abfd->arch_info = arch;
1983 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1986 if (! next_byte (&(ieee->h)))
1989 if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
1992 if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
1995 /* If there is a byte order info, take it. */
1996 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum
1997 || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
1999 if (! next_byte (&(ieee->h)))
2003 for (part = 0; part < N_W_VARIABLES; part++)
2007 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
2010 if (this_byte_and_next (&(ieee->h)) != part)
2013 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
2018 if (ieee->w.r.external_part != 0)
2019 abfd->flags = HAS_SYMS;
2021 /* By now we know that this is a real IEEE file, we're going to read
2022 the whole thing into memory so that we can run up and down it
2023 quickly. We can work out how big the file is from the trailer
2026 amt = ieee->w.r.me_record + 1;
2027 IEEE_DATA (abfd)->h.first_byte = bfd_alloc (ieee->h.abfd, amt);
2028 if (!IEEE_DATA (abfd)->h.first_byte)
2030 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
2033 /* FIXME: Check return value. I'm not sure whether it needs to read
2034 the entire buffer or not. */
2035 amt = bfd_bread ((void *) (IEEE_DATA (abfd)->h.first_byte),
2036 (bfd_size_type) ieee->w.r.me_record + 1, abfd);
2040 IEEE_DATA (abfd)->h.total_amt = amt;
2041 if (ieee_slurp_sections (abfd))
2044 if (! ieee_slurp_debug (abfd))
2047 /* Parse section data to activate file and section flags implied by
2048 section contents. */
2049 if (! ieee_slurp_section_data (abfd))
2054 bfd_set_error (bfd_error_wrong_format);
2056 bfd_release (abfd, ieee);
2057 abfd->tdata.ieee_data = save;
2058 return (const bfd_target *) NULL;
2062 ieee_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED,
2066 bfd_symbol_info (symbol, ret);
2067 if (symbol->name[0] == ' ')
2068 ret->name = "* empty table entry ";
2069 if (!symbol->section)
2070 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
2074 ieee_print_symbol (bfd *abfd,
2077 bfd_print_symbol_type how)
2079 FILE *file = (FILE *) afile;
2083 case bfd_print_symbol_name:
2084 fprintf (file, "%s", symbol->name);
2086 case bfd_print_symbol_more:
2089 case bfd_print_symbol_all:
2091 const char *section_name =
2092 (symbol->section == (asection *) NULL
2094 : symbol->section->name);
2096 if (symbol->name[0] == ' ')
2097 fprintf (file, "* empty table entry ");
2100 bfd_print_symbol_vandf (abfd, (void *) file, symbol);
2102 fprintf (file, " %-5s %04x %02x %s",
2104 (unsigned) ieee_symbol (symbol)->index,
2114 ieee_new_section_hook (bfd *abfd, asection *newsect)
2116 if (!newsect->used_by_bfd)
2118 newsect->used_by_bfd = bfd_alloc (abfd, sizeof (ieee_per_section_type));
2119 if (!newsect->used_by_bfd)
2122 ieee_per_section (newsect)->data = NULL;
2123 ieee_per_section (newsect)->section = newsect;
2124 return _bfd_generic_new_section_hook (abfd, newsect);
2128 ieee_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
2130 if ((asect->flags & SEC_DEBUGGING) != 0)
2132 if (! ieee_slurp_section_data (abfd))
2134 return (asect->reloc_count + 1) * sizeof (arelent *);
2138 ieee_get_section_contents (bfd *abfd,
2142 bfd_size_type count)
2144 ieee_per_section_type *p = ieee_per_section (section);
2145 if ((section->flags & SEC_DEBUGGING) != 0)
2146 return _bfd_generic_get_section_contents (abfd, section, location,
2148 ieee_slurp_section_data (abfd);
2149 (void) memcpy ((void *) location, (void *) (p->data + offset), (unsigned) count);
2154 ieee_canonicalize_reloc (bfd *abfd,
2159 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
2160 ieee_data_type *ieee = IEEE_DATA (abfd);
2162 if ((section->flags & SEC_DEBUGGING) != 0)
2165 while (src != (ieee_reloc_type *) NULL)
2167 /* Work out which symbol to attach it this reloc to. */
2168 switch (src->symbol.letter)
2171 src->relent.sym_ptr_ptr =
2172 symbols + src->symbol.index + ieee->external_symbol_base_offset;
2175 src->relent.sym_ptr_ptr =
2176 symbols + src->symbol.index + ieee->external_reference_base_offset;
2179 if (src->relent.sym_ptr_ptr != NULL)
2180 src->relent.sym_ptr_ptr =
2181 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
2187 *relptr++ = &src->relent;
2191 return section->reloc_count;
2195 comp (const void * ap, const void * bp)
2197 arelent *a = *((arelent **) ap);
2198 arelent *b = *((arelent **) bp);
2199 return a->address - b->address;
2202 /* Write the section headers. */
2205 ieee_write_section_part (bfd *abfd)
2207 ieee_data_type *ieee = IEEE_DATA (abfd);
2210 ieee->w.r.section_part = bfd_tell (abfd);
2211 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2213 if (! bfd_is_abs_section (s)
2214 && (s->flags & SEC_DEBUGGING) == 0)
2216 if (! ieee_write_byte (abfd, ieee_section_type_enum)
2217 || ! ieee_write_byte (abfd,
2218 (bfd_byte) (s->index
2219 + IEEE_SECTION_NUMBER_BASE)))
2222 if (abfd->flags & EXEC_P)
2224 /* This image is executable, so output absolute sections. */
2225 if (! ieee_write_byte (abfd, ieee_variable_A_enum)
2226 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
2231 if (! ieee_write_byte (abfd, ieee_variable_C_enum))
2235 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
2237 case SEC_CODE | SEC_LOAD:
2239 if (! ieee_write_byte (abfd, ieee_variable_P_enum))
2244 if (! ieee_write_byte (abfd, ieee_variable_D_enum))
2248 case SEC_ROM | SEC_DATA:
2249 case SEC_ROM | SEC_LOAD:
2250 case SEC_ROM | SEC_DATA | SEC_LOAD:
2251 if (! ieee_write_byte (abfd, ieee_variable_R_enum))
2256 if (! ieee_write_id (abfd, s->name))
2259 if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
2260 || ! ieee_write_byte (abfd,
2261 (bfd_byte) (s->index
2262 + IEEE_SECTION_NUMBER_BASE))
2263 || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
2267 if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
2268 || ! ieee_write_byte (abfd,
2269 (bfd_byte) (s->index
2270 + IEEE_SECTION_NUMBER_BASE))
2271 || ! ieee_write_int (abfd, s->size))
2273 if (abfd->flags & EXEC_P)
2275 /* Relocateable sections don't have asl records. */
2277 if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
2278 || ! ieee_write_byte (abfd,
2281 + IEEE_SECTION_NUMBER_BASE)))
2282 || ! ieee_write_int (abfd, s->lma))
2292 do_with_relocs (bfd *abfd, asection *s)
2294 unsigned int number_of_maus_in_address =
2295 bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
2296 unsigned int relocs_to_go = s->reloc_count;
2297 bfd_byte *stream = ieee_per_section (s)->data;
2298 arelent **p = s->orelocation;
2299 bfd_size_type current_byte_index = 0;
2301 qsort (s->orelocation,
2303 sizeof (arelent **),
2306 /* Output the section preheader. */
2307 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2308 || ! ieee_write_byte (abfd,
2309 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
2310 || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
2311 || ! ieee_write_byte (abfd,
2312 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
2315 if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
2317 if (! ieee_write_int (abfd, s->lma))
2322 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2326 if (relocs_to_go == 0)
2328 /* If there aren't any relocations then output the load constant
2329 byte opcode rather than the load with relocation opcode. */
2330 while (current_byte_index < s->size)
2333 unsigned int MAXRUN = 127;
2336 if (run > s->size - current_byte_index)
2337 run = s->size - current_byte_index;
2341 if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
2343 /* Output a stream of bytes. */
2344 if (! ieee_write_int (abfd, run))
2346 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
2349 current_byte_index += run;
2355 if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
2358 /* Output the data stream as the longest sequence of bytes
2359 possible, allowing for the a reasonable packet size and
2360 relocation stuffs. */
2363 /* Outputting a section without data, fill it up. */
2364 stream = bfd_zalloc (abfd, s->size);
2368 while (current_byte_index < s->size)
2371 unsigned int MAXRUN = 127;
2375 run = (*p)->address - current_byte_index;
2382 if (run > s->size - current_byte_index)
2383 run = s->size - current_byte_index;
2387 /* Output a stream of bytes. */
2388 if (! ieee_write_int (abfd, run))
2390 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
2393 current_byte_index += run;
2396 /* Output any relocations here. */
2397 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
2400 && (*p) && (*p)->address == current_byte_index)
2404 switch (r->howto->size)
2407 ov = bfd_get_signed_32 (abfd,
2408 stream + current_byte_index);
2409 current_byte_index += 4;
2412 ov = bfd_get_signed_16 (abfd,
2413 stream + current_byte_index);
2414 current_byte_index += 2;
2417 ov = bfd_get_signed_8 (abfd,
2418 stream + current_byte_index);
2419 current_byte_index++;
2427 ov &= r->howto->src_mask;
2429 if (r->howto->pc_relative
2430 && ! r->howto->pcrel_offset)
2433 if (! ieee_write_byte (abfd,
2434 ieee_function_either_open_b_enum))
2437 if (r->sym_ptr_ptr != (asymbol **) NULL)
2439 if (! ieee_write_expression (abfd, r->addend + ov,
2441 r->howto->pc_relative,
2442 (unsigned) s->index))
2447 if (! ieee_write_expression (abfd, r->addend + ov,
2449 r->howto->pc_relative,
2450 (unsigned) s->index))
2454 if (number_of_maus_in_address
2455 != bfd_get_reloc_size (r->howto))
2457 bfd_vma rsize = bfd_get_reloc_size (r->howto);
2458 if (! ieee_write_int (abfd, rsize))
2461 if (! ieee_write_byte (abfd,
2462 ieee_function_either_close_b_enum))
2476 /* If there are no relocations in the output section then we can be
2477 clever about how we write. We block items up into a max of 127
2481 do_as_repeat (bfd *abfd, asection *s)
2485 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2486 || ! ieee_write_byte (abfd,
2487 (bfd_byte) (s->index
2488 + IEEE_SECTION_NUMBER_BASE))
2489 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
2490 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
2491 || ! ieee_write_byte (abfd,
2492 (bfd_byte) (s->index
2493 + IEEE_SECTION_NUMBER_BASE)))
2496 if ((abfd->flags & EXEC_P) != 0)
2498 if (! ieee_write_int (abfd, s->lma))
2503 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2507 if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
2508 || ! ieee_write_int (abfd, s->size)
2509 || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
2510 || ! ieee_write_byte (abfd, 1)
2511 || ! ieee_write_byte (abfd, 0))
2519 do_without_relocs (bfd *abfd, asection *s)
2521 bfd_byte *stream = ieee_per_section (s)->data;
2523 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2525 if (! do_as_repeat (abfd, s))
2532 for (i = 0; i < s->size; i++)
2536 if (! do_with_relocs (abfd, s))
2541 if (! do_as_repeat (abfd, s))
2551 bfd_size_type amt = input_ptr_end - input_ptr_start;
2552 /* FIXME: Check return value. I'm not sure whether it needs to read
2553 the entire buffer or not. */
2554 bfd_bread ((void *) input_ptr_start, amt, input_bfd);
2555 input_ptr = input_ptr_start;
2561 bfd_size_type amt = output_ptr - output_ptr_start;
2563 if (bfd_bwrite ((void *) (output_ptr_start), amt, output_bfd) != amt)
2565 output_ptr = output_ptr_start;
2569 #define THIS() ( *input_ptr )
2570 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); }
2571 #define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end) flush (); }
2574 write_int (int value)
2576 if (value >= 0 && value <= 127)
2582 unsigned int length;
2584 /* How many significant bytes ? */
2585 /* FIXME FOR LONGER INTS. */
2586 if (value & 0xff000000)
2588 else if (value & 0x00ff0000)
2590 else if (value & 0x0000ff00)
2595 OUT ((int) ieee_number_repeat_start_enum + length);
2613 int length = THIS ();
2626 #define VAR(x) ((x | 0x80))
2628 copy_expression (void)
2642 value = (value << 8) | THIS ();
2644 value = (value << 8) | THIS ();
2646 value = (value << 8) | THIS ();
2654 value = (value << 8) | THIS ();
2656 value = (value << 8) | THIS ();
2664 value = (value << 8) | THIS ();
2681 /* Not a number, just bug out with the answer. */
2682 write_int (*(--tos));
2689 /* PLUS anything. */
2698 ieee_data_type *ieee;
2702 section_number = THIS ();
2705 ieee = IEEE_DATA (input_bfd);
2706 s = ieee->section_table[section_number];
2708 if (s->output_section)
2709 value = s->output_section->lma;
2710 value += s->output_offset;
2717 write_int (*(--tos));
2725 /* Drop the int in the buffer, and copy a null into the gap, which we
2726 will overwrite later. */
2729 fill_int (struct output_buffer_struct *buf)
2731 if (buf->buffer == output_buffer)
2733 /* Still a chance to output the size. */
2734 int value = output_ptr - buf->ptrp + 3;
2735 buf->ptrp[0] = value >> 24;
2736 buf->ptrp[1] = value >> 16;
2737 buf->ptrp[2] = value >> 8;
2738 buf->ptrp[3] = value >> 0;
2743 drop_int (struct output_buffer_struct *buf)
2771 buf->ptrp = output_ptr;
2772 buf->buffer = output_buffer;
2812 #define ID copy_id ()
2813 #define INT copy_int ()
2814 #define EXP copy_expression ()
2815 #define INTn(q) copy_int ()
2816 #define EXPn(q) copy_expression ()
2819 copy_till_end (void)
2895 EXPn (instruction address);
2929 EXPn (external function);
2939 INTn (locked register);
2961 /* Attribute record. */
2991 /* Unique typedefs for module. */
2992 /* GLobal typedefs. */
2993 /* High level module scope beginning. */
2995 struct output_buffer_struct ob;
3011 /* Global function. */
3013 struct output_buffer_struct ob;
3028 EXPn (size of block);
3034 /* File name for source line numbers. */
3036 struct output_buffer_struct ob;
3057 /* Local function. */
3059 struct output_buffer_struct ob;
3078 /* Assembler module scope beginning - */
3080 struct output_buffer_struct ob;
3106 struct output_buffer_struct ob;
3114 INTn (section index);
3122 EXPn (Size in Maus);
3175 /* Moves all the debug information from the source bfd to the output
3176 bfd, and relocates any expressions it finds. */
3179 relocate_debug (bfd *output ATTRIBUTE_UNUSED,
3184 unsigned char input_buffer[IBS];
3186 input_ptr_start = input_ptr = input_buffer;
3187 input_ptr_end = input_buffer + IBS;
3189 /* FIXME: Check return value. I'm not sure whether it needs to read
3190 the entire buffer or not. */
3191 bfd_bread ((void *) input_ptr_start, (bfd_size_type) IBS, input);
3195 /* Gather together all the debug information from each input BFD into
3196 one place, relocating it and emitting it as we go. */
3199 ieee_write_debug_part (bfd *abfd)
3201 ieee_data_type *ieee = IEEE_DATA (abfd);
3202 bfd_chain_type *chain = ieee->chain_root;
3203 unsigned char obuff[OBS];
3204 bfd_boolean some_debug = FALSE;
3205 file_ptr here = bfd_tell (abfd);
3207 output_ptr_start = output_ptr = obuff;
3208 output_ptr_end = obuff + OBS;
3212 if (chain == (bfd_chain_type *) NULL)
3216 for (s = abfd->sections; s != NULL; s = s->next)
3217 if ((s->flags & SEC_DEBUGGING) != 0)
3221 ieee->w.r.debug_information_part = 0;
3225 ieee->w.r.debug_information_part = here;
3226 if (bfd_bwrite (s->contents, s->size, abfd) != s->size)
3231 while (chain != (bfd_chain_type *) NULL)
3233 bfd *entry = chain->this;
3234 ieee_data_type *entry_ieee = IEEE_DATA (entry);
3236 if (entry_ieee->w.r.debug_information_part)
3238 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
3241 relocate_debug (abfd, entry);
3244 chain = chain->next;
3248 ieee->w.r.debug_information_part = here;
3250 ieee->w.r.debug_information_part = 0;
3258 /* Write the data in an ieee way. */
3261 ieee_write_data_part (bfd *abfd)
3265 ieee_data_type *ieee = IEEE_DATA (abfd);
3266 ieee->w.r.data_part = bfd_tell (abfd);
3268 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3270 /* Skip sections that have no loadable contents (.bss,
3272 if ((s->flags & SEC_LOAD) == 0)
3275 /* Sort the reloc records so we can insert them in the correct
3277 if (s->reloc_count != 0)
3279 if (! do_with_relocs (abfd, s))
3284 if (! do_without_relocs (abfd, s))
3293 init_for_output (bfd *abfd)
3297 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3299 if ((s->flags & SEC_DEBUGGING) != 0)
3303 bfd_size_type size = s->size;
3304 ieee_per_section (s)->data = bfd_alloc (abfd, size);
3305 if (!ieee_per_section (s)->data)
3312 /* Exec and core file sections. */
3314 /* Set section contents is complicated with IEEE since the format is
3315 not a byte image, but a record stream. */
3318 ieee_set_section_contents (bfd *abfd,
3320 const void * location,
3322 bfd_size_type count)
3324 if ((section->flags & SEC_DEBUGGING) != 0)
3326 if (section->contents == NULL)
3328 bfd_size_type size = section->size;
3329 section->contents = bfd_alloc (abfd, size);
3330 if (section->contents == NULL)
3333 /* bfd_set_section_contents has already checked that everything
3335 memcpy (section->contents + offset, location, (size_t) count);
3339 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
3341 if (!init_for_output (abfd))
3344 memcpy ((void *) (ieee_per_section (section)->data + offset),
3346 (unsigned int) count);
3350 /* Write the external symbols of a file. IEEE considers two sorts of
3351 external symbols, public, and referenced. It uses to internal
3352 forms to index them as well. When we write them out we turn their
3353 symbol values into indexes from the right base. */
3356 ieee_write_external_part (bfd *abfd)
3359 ieee_data_type *ieee = IEEE_DATA (abfd);
3360 unsigned int reference_index = IEEE_REFERENCE_BASE;
3361 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
3362 file_ptr here = bfd_tell (abfd);
3363 bfd_boolean hadone = FALSE;
3365 if (abfd->outsymbols != (asymbol **) NULL)
3368 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
3372 if (bfd_is_und_section (p->section))
3374 /* This must be a symbol reference. */
3375 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3376 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3377 || ! ieee_write_id (abfd, p->name))
3379 p->value = reference_index;
3383 else if (bfd_is_com_section (p->section))
3385 /* This is a weak reference. */
3386 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3387 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3388 || ! ieee_write_id (abfd, p->name)
3389 || ! ieee_write_byte (abfd,
3390 ieee_weak_external_reference_enum)
3391 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3392 || ! ieee_write_int (abfd, p->value))
3394 p->value = reference_index;
3398 else if (p->flags & BSF_GLOBAL)
3400 /* This must be a symbol definition. */
3401 if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
3402 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3403 || ! ieee_write_id (abfd, p->name)
3404 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
3405 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3406 || ! ieee_write_byte (abfd, 15) /* Instruction address. */
3407 || ! ieee_write_byte (abfd, 19) /* Static symbol. */
3408 || ! ieee_write_byte (abfd, 1)) /* One of them. */
3411 /* Write out the value. */
3412 if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
3413 || ! ieee_write_int (abfd, (bfd_vma) public_index))
3415 if (! bfd_is_abs_section (p->section))
3417 if (abfd->flags & EXEC_P)
3419 /* If fully linked, then output all symbols
3421 if (! (ieee_write_int
3424 + p->section->output_offset
3425 + p->section->output_section->vma))))
3430 if (! (ieee_write_expression
3432 p->value + p->section->output_offset,
3433 p->section->output_section->symbol,
3440 if (! ieee_write_expression (abfd,
3442 bfd_abs_section_ptr->symbol,
3446 p->value = public_index;
3452 /* This can happen - when there are gaps in the symbols read
3453 from an input ieee file. */
3458 ieee->w.r.external_part = here;
3464 static const unsigned char exten[] =
3467 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3468 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
3469 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
3472 static const unsigned char envi[] =
3476 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3479 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */
3481 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */
3482 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3486 ieee_write_me_part (bfd *abfd)
3488 ieee_data_type *ieee = IEEE_DATA (abfd);
3489 ieee->w.r.trailer_part = bfd_tell (abfd);
3490 if (abfd->start_address)
3492 if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
3493 || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
3494 || ! ieee_write_int (abfd, abfd->start_address)
3495 || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
3498 ieee->w.r.me_record = bfd_tell (abfd);
3499 if (! ieee_write_byte (abfd, ieee_module_end_enum))
3504 /* Write out the IEEE processor ID. */
3507 ieee_write_processor (bfd *abfd)
3509 const bfd_arch_info_type *arch;
3511 arch = bfd_get_arch_info (abfd);
3515 if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
3519 case bfd_arch_h8300:
3520 if (! ieee_write_id (abfd, "H8/300"))
3524 case bfd_arch_h8500:
3525 if (! ieee_write_id (abfd, "H8/500"))
3533 case bfd_mach_i960_core:
3534 case bfd_mach_i960_ka_sa:
3535 if (! ieee_write_id (abfd, "80960KA"))
3539 case bfd_mach_i960_kb_sb:
3540 if (! ieee_write_id (abfd, "80960KB"))
3544 case bfd_mach_i960_ca:
3545 if (! ieee_write_id (abfd, "80960CA"))
3549 case bfd_mach_i960_mc:
3550 case bfd_mach_i960_xa:
3551 if (! ieee_write_id (abfd, "80960MC"))
3563 default: id = "68020"; break;
3564 case bfd_mach_m68000: id = "68000"; break;
3565 case bfd_mach_m68008: id = "68008"; break;
3566 case bfd_mach_m68010: id = "68010"; break;
3567 case bfd_mach_m68020: id = "68020"; break;
3568 case bfd_mach_m68030: id = "68030"; break;
3569 case bfd_mach_m68040: id = "68040"; break;
3570 case bfd_mach_m68060: id = "68060"; break;
3571 case bfd_mach_cpu32: id = "cpu32"; break;
3572 case bfd_mach_mcf_isa_a_nodiv: id = "isa-a:nodiv"; break;
3573 case bfd_mach_mcf_isa_a: id = "isa-a"; break;
3574 case bfd_mach_mcf_isa_a_mac: id = "isa-a:mac"; break;
3575 case bfd_mach_mcf_isa_a_emac: id = "isa-a:emac"; break;
3576 case bfd_mach_mcf_isa_aplus: id = "isa-aplus"; break;
3577 case bfd_mach_mcf_isa_aplus_mac: id = "isa-aplus:mac"; break;
3578 case bfd_mach_mcf_isa_aplus_emac: id = "isa-aplus:mac"; break;
3579 case bfd_mach_mcf_isa_b_nousp: id = "isa-b:nousp"; break;
3580 case bfd_mach_mcf_isa_b_nousp_mac: id = "isa-b:nousp:mac"; break;
3581 case bfd_mach_mcf_isa_b_nousp_emac: id = "isa-b:nousp:emac"; break;
3582 case bfd_mach_mcf_isa_b: id = "isa-b"; break;
3583 case bfd_mach_mcf_isa_b_mac: id = "isa-b:mac"; break;
3584 case bfd_mach_mcf_isa_b_emac: id = "isa-b:emac"; break;
3585 case bfd_mach_mcf_isa_b_float: id = "isa-b:float"; break;
3586 case bfd_mach_mcf_isa_b_float_mac: id = "isa-b:float:mac"; break;
3587 case bfd_mach_mcf_isa_b_float_emac: id = "isa-b:float:emac"; break;
3588 case bfd_mach_mcf_isa_c: id = "isa-c"; break;
3589 case bfd_mach_mcf_isa_c_mac: id = "isa-c:mac"; break;
3590 case bfd_mach_mcf_isa_c_emac: id = "isa-c:emac"; break;
3591 case bfd_mach_mcf_isa_c_nodiv: id = "isa-c:nodiv"; break;
3592 case bfd_mach_mcf_isa_c_nodiv_mac: id = "isa-c:nodiv:mac"; break;
3593 case bfd_mach_mcf_isa_c_nodiv_emac: id = "isa-c:nodiv:emac"; break;
3596 if (! ieee_write_id (abfd, id))
3606 ieee_write_object_contents (bfd *abfd)
3608 ieee_data_type *ieee = IEEE_DATA (abfd);
3612 /* Fast forward over the header area. */
3613 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3616 if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
3617 || ! ieee_write_processor (abfd)
3618 || ! ieee_write_id (abfd, abfd->filename))
3621 /* Fast forward over the variable bits. */
3622 if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
3626 if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
3628 /* MAU's per address. */
3629 if (! ieee_write_byte (abfd,
3630 (bfd_byte) (bfd_arch_bits_per_address (abfd)
3631 / bfd_arch_bits_per_byte (abfd))))
3634 old = bfd_tell (abfd);
3635 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3638 ieee->w.r.extension_record = bfd_tell (abfd);
3639 if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
3642 if (abfd->flags & EXEC_P)
3644 if (! ieee_write_byte (abfd, 0x1)) /* Absolute. */
3649 if (! ieee_write_byte (abfd, 0x2)) /* Relocateable. */
3653 ieee->w.r.environmental_record = bfd_tell (abfd);
3654 if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
3658 /* The HP emulator database requires a timestamp in the file. */
3664 t = (struct tm *) localtime (&now);
3665 if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
3666 || ! ieee_write_byte (abfd, 0x21)
3667 || ! ieee_write_byte (abfd, 0)
3668 || ! ieee_write_byte (abfd, 50)
3669 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
3670 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
3671 || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
3672 || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
3673 || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
3674 || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
3682 if (! ieee_write_section_part (abfd))
3684 /* First write the symbols. This changes their values into table
3685 indeces so we cant use it after this point. */
3686 if (! ieee_write_external_part (abfd))
3689 /* Write any debugs we have been told about. */
3690 if (! ieee_write_debug_part (abfd))
3693 /* Can only write the data once the symbols have been written, since
3694 the data contains relocation information which points to the
3696 if (! ieee_write_data_part (abfd))
3699 /* At the end we put the end! */
3700 if (! ieee_write_me_part (abfd))
3703 /* Generate the header. */
3704 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3707 for (i = 0; i < N_W_VARIABLES; i++)
3709 if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
3710 || ! ieee_write_byte (abfd, (bfd_byte) i)
3711 || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
3718 /* Native-level interface to symbols. */
3720 /* We read the symbols into a buffer, which is discarded when this
3721 function exits. We read the strings into a buffer large enough to
3722 hold them all plus all the cached symbol entries. */
3725 ieee_make_empty_symbol (bfd *abfd)
3727 bfd_size_type amt = sizeof (ieee_symbol_type);
3728 ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_zalloc (abfd, amt);
3732 new_symbol->symbol.the_bfd = abfd;
3733 return &new_symbol->symbol;
3737 ieee_openr_next_archived_file (bfd *arch, bfd *prev)
3739 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3741 /* Take the next one from the arch state, or reset. */
3742 if (prev == (bfd *) NULL)
3743 /* Reset the index - the first two entries are bogus. */
3744 ar->element_index = 2;
3748 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3750 ar->element_index++;
3751 if (ar->element_index <= ar->element_count)
3753 if (p->file_offset != (file_ptr) 0)
3755 if (p->abfd == (bfd *) NULL)
3757 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3758 p->abfd->origin = p->file_offset;
3765 bfd_set_error (bfd_error_no_more_archived_files);
3771 #define ieee_find_nearest_line _bfd_nosymbols_find_nearest_line
3772 #define ieee_find_line _bfd_nosymbols_find_line
3773 #define ieee_find_inliner_info _bfd_nosymbols_find_inliner_info
3776 ieee_generic_stat_arch_elt (bfd *abfd, struct stat *buf)
3778 ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
3779 ieee_data_type *ieee;
3781 if (abfd->my_archive != NULL)
3782 ar = abfd->my_archive->tdata.ieee_ar_data;
3783 if (ar == (ieee_ar_data_type *) NULL)
3785 bfd_set_error (bfd_error_invalid_operation);
3789 if (IEEE_DATA (abfd) == NULL)
3791 if (ieee_object_p (abfd) == NULL)
3793 bfd_set_error (bfd_error_wrong_format);
3798 ieee = IEEE_DATA (abfd);
3800 buf->st_size = ieee->w.r.me_record + 1;
3801 buf->st_mode = 0644;
3806 ieee_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
3807 struct bfd_link_info *info ATTRIBUTE_UNUSED)
3812 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3813 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3815 #define ieee_slurp_armap bfd_true
3816 #define ieee_slurp_extended_name_table bfd_true
3817 #define ieee_construct_extended_name_table \
3819 (bfd *, char **, bfd_size_type *, const char **)) \
3821 #define ieee_truncate_arname bfd_dont_truncate_arname
3822 #define ieee_write_armap \
3824 (bfd *, unsigned int, struct orl *, unsigned int, int)) \
3826 #define ieee_read_ar_hdr bfd_nullvoidptr
3827 #define ieee_write_ar_hdr ((bfd_boolean (*) (bfd *, bfd *)) bfd_false)
3828 #define ieee_update_armap_timestamp bfd_true
3829 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3831 #define ieee_get_symbol_version_string \
3832 _bfd_nosymbols_get_symbol_version_string
3833 #define ieee_bfd_is_target_special_symbol \
3834 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
3835 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3836 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3837 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3838 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3839 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3841 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3842 #define ieee_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
3844 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3846 #define ieee_get_section_contents_in_window \
3847 _bfd_generic_get_section_contents_in_window
3848 #define ieee_bfd_get_relocated_section_contents \
3849 bfd_generic_get_relocated_section_contents
3850 #define ieee_bfd_relax_section bfd_generic_relax_section
3851 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3852 #define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
3853 #define ieee_bfd_merge_sections bfd_generic_merge_sections
3854 #define ieee_bfd_is_group_section bfd_generic_is_group_section
3855 #define ieee_bfd_discard_group bfd_generic_discard_group
3856 #define ieee_section_already_linked \
3857 _bfd_generic_section_already_linked
3858 #define ieee_bfd_define_common_symbol bfd_generic_define_common_symbol
3859 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3860 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3861 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
3862 #define ieee_bfd_copy_link_hash_symbol_type \
3863 _bfd_generic_copy_link_hash_symbol_type
3864 #define ieee_bfd_final_link _bfd_generic_final_link
3865 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3867 const bfd_target ieee_vec =
3870 bfd_target_ieee_flavour,
3871 BFD_ENDIAN_UNKNOWN, /* Target byte order. */
3872 BFD_ENDIAN_UNKNOWN, /* Target headers byte order. */
3873 (HAS_RELOC | EXEC_P | /* Object flags. */
3874 HAS_LINENO | HAS_DEBUG |
3875 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3876 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3877 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
3878 '_', /* Leading underscore. */
3879 ' ', /* AR_pad_char. */
3880 16, /* AR_max_namelen. */
3881 0, /* match priority. */
3882 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3883 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3884 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
3885 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3886 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3887 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
3890 ieee_object_p, /* bfd_check_format. */
3897 _bfd_generic_mkarchive,
3902 ieee_write_object_contents,
3903 _bfd_write_archive_contents,
3907 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
3908 ieee_get_section_contents, ieee_get_section_contents_in_window. */
3909 BFD_JUMP_TABLE_GENERIC (ieee),
3911 BFD_JUMP_TABLE_COPY (_bfd_generic),
3912 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3914 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
3915 ieee_construct_extended_name_table, ieee_truncate_arname,
3916 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
3917 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
3918 ieee_update_armap_timestamp. */
3919 BFD_JUMP_TABLE_ARCHIVE (ieee),
3921 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
3922 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
3923 ieee_bfd_is_local_label_name, ieee_get_lineno,
3924 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
3925 ieee_read_minisymbols, ieee_minisymbol_to_symbol. */
3926 BFD_JUMP_TABLE_SYMBOLS (ieee),
3928 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
3929 ieee_bfd_reloc_type_lookup. */
3930 BFD_JUMP_TABLE_RELOCS (ieee),
3932 /* ieee_set_arch_mach, ieee_set_section_contents. */
3933 BFD_JUMP_TABLE_WRITE (ieee),
3935 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
3936 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
3937 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
3938 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
3939 ieee_bfd_merge_sections. */
3940 BFD_JUMP_TABLE_LINK (ieee),
3942 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),