1 /* BFD back-end for ieee-695 objects.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
6 Written by Steve Chamberlain of Cygnus Support.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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"
37 struct output_buffer_struct
43 /* Functions for writing to ieee files in the strange way that the
47 ieee_write_byte (bfd *abfd, int barg)
52 if (bfd_bwrite ((void *) &byte, (bfd_size_type) 1, abfd) != 1)
58 ieee_write_2bytes (bfd *abfd, int bytes)
62 buffer[0] = bytes >> 8;
63 buffer[1] = bytes & 0xff;
64 if (bfd_bwrite ((void *) buffer, (bfd_size_type) 2, abfd) != 2)
70 ieee_write_int (bfd *abfd, bfd_vma value)
74 if (! ieee_write_byte (abfd, (bfd_byte) value))
81 /* How many significant bytes ? */
82 /* FIXME FOR LONGER INTS. */
83 if (value & 0xff000000)
85 else if (value & 0x00ff0000)
87 else if (value & 0x0000ff00)
92 if (! ieee_write_byte (abfd,
93 (bfd_byte) ((int) ieee_number_repeat_start_enum
99 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))
103 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))
107 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))
111 if (! ieee_write_byte (abfd, (bfd_byte) (value)))
120 ieee_write_id (bfd *abfd, const char *id)
122 size_t length = strlen (id);
126 if (! ieee_write_byte (abfd, (bfd_byte) length))
129 else if (length < 255)
131 if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)
132 || ! ieee_write_byte (abfd, (bfd_byte) length))
135 else if (length < 65535)
137 if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)
138 || ! ieee_write_2bytes (abfd, (int) length))
143 (*_bfd_error_handler)
144 (_("%s: string too long (%d chars, max 65535)"),
145 bfd_get_filename (abfd), length);
146 bfd_set_error (bfd_error_invalid_operation);
150 if (bfd_bwrite ((void *) id, (bfd_size_type) length, abfd) != length)
155 /* Functions for reading from ieee files in the strange way that the
156 standard requires. */
158 #define this_byte(ieee) *((ieee)->input_p)
159 #define next_byte(ieee) ((ieee)->input_p++)
160 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
162 static unsigned short
163 read_2bytes (common_header_type *ieee)
165 unsigned char c1 = this_byte_and_next (ieee);
166 unsigned char c2 = this_byte_and_next (ieee);
168 return (c1 << 8) | c2;
172 bfd_get_string (common_header_type *ieee, char *string, size_t length)
176 for (i = 0; i < length; i++)
177 string[i] = this_byte_and_next (ieee);
181 read_id (common_header_type *ieee)
186 length = this_byte_and_next (ieee);
188 /* Simple string of length 0 to 127. */
191 else if (length == 0xde)
192 /* Length is next byte, allowing 0..255. */
193 length = this_byte_and_next (ieee);
195 else if (length == 0xdf)
197 /* Length is next two bytes, allowing 0..65535. */
198 length = this_byte_and_next (ieee);
199 length = (length * 256) + this_byte_and_next (ieee);
202 /* Buy memory and read string. */
203 string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
206 bfd_get_string (ieee, string, length);
212 ieee_write_expression (bfd *abfd,
218 unsigned int term_count = 0;
222 if (! ieee_write_int (abfd, value))
227 /* Badly formatted binaries can have a missing symbol,
228 so test here to prevent a seg fault. */
231 if (bfd_is_com_section (symbol->section)
232 || bfd_is_und_section (symbol->section))
234 /* Def of a common symbol. */
235 if (! ieee_write_byte (abfd, ieee_variable_X_enum)
236 || ! ieee_write_int (abfd, symbol->value))
240 else if (! bfd_is_abs_section (symbol->section))
242 /* Ref to defined symbol - */
243 if (symbol->flags & BSF_GLOBAL)
245 if (! ieee_write_byte (abfd, ieee_variable_I_enum)
246 || ! ieee_write_int (abfd, symbol->value))
250 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
252 /* This is a reference to a defined local symbol. We can
253 easily do a local as a section+offset. */
254 if (! ieee_write_byte (abfd, ieee_variable_R_enum)
255 || ! ieee_write_byte (abfd,
256 (bfd_byte) (symbol->section->index
257 + IEEE_SECTION_NUMBER_BASE)))
261 if (symbol->value != 0)
263 if (! ieee_write_int (abfd, symbol->value))
270 (*_bfd_error_handler)
271 (_("%s: unrecognized symbol `%s' flags 0x%x"),
272 bfd_get_filename (abfd), bfd_asymbol_name (symbol),
274 bfd_set_error (bfd_error_invalid_operation);
282 /* Subtract the pc from here by asking for PC of this section. */
283 if (! ieee_write_byte (abfd, ieee_variable_P_enum)
284 || ! ieee_write_byte (abfd,
285 (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE))
286 || ! ieee_write_byte (abfd, ieee_function_minus_enum))
290 /* Handle the degenerate case of a 0 address. */
292 if (! ieee_write_int (abfd, (bfd_vma) 0))
295 while (term_count > 1)
297 if (! ieee_write_byte (abfd, ieee_function_plus_enum))
305 /* Writes any integer into the buffer supplied and always takes 5 bytes. */
308 ieee_write_int5 (bfd_byte *buffer, bfd_vma value)
310 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
311 buffer[1] = (value >> 24) & 0xff;
312 buffer[2] = (value >> 16) & 0xff;
313 buffer[3] = (value >> 8) & 0xff;
314 buffer[4] = (value >> 0) & 0xff;
318 ieee_write_int5_out (bfd *abfd, bfd_vma value)
322 ieee_write_int5 (b, value);
323 if (bfd_bwrite ((void *) b, (bfd_size_type) 5, abfd) != 5)
329 parse_int (common_header_type *ieee, bfd_vma *value_ptr)
331 int value = this_byte (ieee);
334 if (value >= 0 && value <= 127)
340 else if (value >= 0x80 && value <= 0x88)
342 unsigned int count = value & 0xf;
348 result = (result << 8) | this_byte_and_next (ieee);
358 parse_i (common_header_type *ieee, bfd_boolean *ok)
361 *ok = parse_int (ieee, &x);
366 must_parse_int (common_header_type *ieee)a
369 BFD_ASSERT (parse_int (ieee, &result));
377 ieee_symbol_index_type symbol;
381 #if KEEPMINUSPCININST
383 #define SRC_MASK(arg) arg
384 #define PCREL_OFFSET FALSE
388 #define SRC_MASK(arg) 0
389 #define PCREL_OFFSET TRUE
393 static reloc_howto_type abs32_howto =
400 complain_overflow_bitfield,
408 static reloc_howto_type abs16_howto =
415 complain_overflow_bitfield,
423 static reloc_howto_type abs8_howto =
430 complain_overflow_bitfield,
438 static reloc_howto_type rel32_howto =
445 complain_overflow_signed,
449 SRC_MASK (0xffffffff),
453 static reloc_howto_type rel16_howto =
460 complain_overflow_signed,
464 SRC_MASK (0x0000ffff),
468 static reloc_howto_type rel8_howto =
475 complain_overflow_signed,
479 SRC_MASK (0x000000ff),
483 static ieee_symbol_index_type NOSYMBOL = {0, 0};
486 parse_expression (ieee_data_type *ieee,
488 ieee_symbol_index_type *symbol,
494 bfd_boolean loop = TRUE;
495 ieee_value_type stack[10];
496 ieee_value_type *sp = stack;
505 /* The stack pointer always points to the next unused location. */
506 #define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC;
507 #define POP(x,y,z) DEC; x = TOS.symbol; y = TOS.section; z = TOS.value;
509 while (loop && ieee->h.input_p < ieee->h.last_byte)
511 switch (this_byte (&(ieee->h)))
513 case ieee_variable_P_enum:
514 /* P variable, current program counter for section n. */
518 next_byte (&(ieee->h));
520 section_n = must_parse_int (&(ieee->h));
521 PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
524 case ieee_variable_L_enum:
525 /* L variable address of section N. */
526 next_byte (&(ieee->h));
527 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
529 case ieee_variable_R_enum:
530 /* R variable, logical address of section module. */
531 /* FIXME, this should be different to L. */
532 next_byte (&(ieee->h));
533 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
535 case ieee_variable_S_enum:
536 /* S variable, size in MAUS of section module. */
537 next_byte (&(ieee->h));
540 ieee->section_table[must_parse_int (&(ieee->h))]->size);
542 case ieee_variable_I_enum:
543 /* Push the address of variable n. */
545 ieee_symbol_index_type sy;
547 next_byte (&(ieee->h));
548 sy.index = (int) must_parse_int (&(ieee->h));
551 PUSH (sy, bfd_abs_section_ptr, 0);
554 case ieee_variable_X_enum:
555 /* Push the address of external variable n. */
557 ieee_symbol_index_type sy;
559 next_byte (&(ieee->h));
560 sy.index = (int) (must_parse_int (&(ieee->h)));
563 PUSH (sy, bfd_und_section_ptr, 0);
566 case ieee_function_minus_enum:
568 bfd_vma value1, value2;
569 asection *section1, *section_dummy;
570 ieee_symbol_index_type sy;
572 next_byte (&(ieee->h));
574 POP (sy, section1, value1);
575 POP (sy, section_dummy, value2);
576 PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
579 case ieee_function_plus_enum:
581 bfd_vma value1, value2;
584 ieee_symbol_index_type sy1;
585 ieee_symbol_index_type sy2;
587 next_byte (&(ieee->h));
589 POP (sy1, section1, value1);
590 POP (sy2, section2, value2);
591 PUSH (sy1.letter ? sy1 : sy2,
592 bfd_is_abs_section (section1) ? section2 : section1,
600 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
601 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
602 if (parse_int (&(ieee->h), &va))
604 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
607 /* Thats all that we can understand. */
613 /* As far as I can see there is a bug in the Microtec IEEE output
614 which I'm using to scan, whereby the comma operator is omitted
615 sometimes in an expression, giving expressions with too many
616 terms. We can tell if that's the case by ensuring that
617 sp == stack here. If not, then we've pushed something too far,
618 so we keep adding. */
619 while (sp != stack + 1)
622 ieee_symbol_index_type sy1;
624 POP (sy1, section1, *extra);
627 POP (*symbol, dummy, *value);
633 #define ieee_seek(ieee, offset) \
636 ieee->h.input_p = ieee->h.first_byte + offset; \
637 ieee->h.last_byte = (ieee->h.first_byte \
638 + ieee_part_after (ieee, offset)); \
642 #define ieee_pos(ieee) \
643 (ieee->h.input_p - ieee->h.first_byte)
645 /* Find the first part of the ieee file after HERE. */
648 ieee_part_after (ieee_data_type *ieee, file_ptr here)
651 file_ptr after = ieee->w.r.me_record;
653 /* File parts can come in any order, except that module end is
654 guaranteed to be last (and the header first). */
655 for (part = 0; part < N_W_VARIABLES; part++)
656 if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
657 after = ieee->w.offset[part];
662 static unsigned int last_index;
663 static char last_type; /* Is the index for an X or a D. */
665 static ieee_symbol_type *
666 get_symbol (bfd *abfd ATTRIBUTE_UNUSED,
667 ieee_data_type *ieee,
668 ieee_symbol_type *last_symbol,
669 unsigned int *symbol_count,
670 ieee_symbol_type ***pptr,
671 unsigned int *max_index,
674 /* Need a new symbol. */
675 unsigned int new_index = must_parse_int (&(ieee->h));
677 if (new_index != last_index || this_type != last_type)
679 ieee_symbol_type *new_symbol;
680 bfd_size_type amt = sizeof (ieee_symbol_type);
682 new_symbol = bfd_alloc (ieee->h.abfd, amt);
686 new_symbol->index = new_index;
687 last_index = new_index;
690 *pptr = &new_symbol->next;
691 if (new_index > *max_index)
692 *max_index = new_index;
694 last_type = this_type;
695 new_symbol->symbol.section = bfd_abs_section_ptr;
702 ieee_slurp_external_symbols (bfd *abfd)
704 ieee_data_type *ieee = IEEE_DATA (abfd);
705 file_ptr offset = ieee->w.r.external_part;
707 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
708 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
709 ieee_symbol_type *symbol = NULL;
710 unsigned int symbol_count = 0;
711 bfd_boolean loop = TRUE;
713 last_index = 0xffffff;
714 ieee->symbol_table_full = TRUE;
716 ieee_seek (ieee, offset);
720 switch (this_byte (&(ieee->h)))
723 next_byte (&(ieee->h));
725 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
727 & ieee->external_symbol_max_index, 'I');
731 symbol->symbol.the_bfd = abfd;
732 symbol->symbol.name = read_id (&(ieee->h));
733 symbol->symbol.udata.p = NULL;
734 symbol->symbol.flags = BSF_NO_FLAGS;
736 case ieee_external_symbol_enum:
737 next_byte (&(ieee->h));
739 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
741 &ieee->external_symbol_max_index, 'D');
745 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
747 symbol->symbol.the_bfd = abfd;
748 symbol->symbol.name = read_id (&(ieee->h));
749 symbol->symbol.udata.p = NULL;
750 symbol->symbol.flags = BSF_NO_FLAGS;
752 case ieee_attribute_record_enum >> 8:
754 unsigned int symbol_name_index;
755 unsigned int symbol_type_index;
756 unsigned int symbol_attribute_def;
759 switch (read_2bytes (&ieee->h))
761 case ieee_attribute_record_enum:
762 symbol_name_index = must_parse_int (&(ieee->h));
763 symbol_type_index = must_parse_int (&(ieee->h));
764 symbol_attribute_def = must_parse_int (&(ieee->h));
765 switch (symbol_attribute_def)
769 parse_int (&ieee->h, &value);
772 (*_bfd_error_handler)
773 (_("%B: unimplemented ATI record %u for symbol %u"),
774 abfd, symbol_attribute_def, symbol_name_index);
775 bfd_set_error (bfd_error_bad_value);
780 case ieee_external_reference_info_record_enum:
781 /* Skip over ATX record. */
782 parse_int (&(ieee->h), &value);
783 parse_int (&(ieee->h), &value);
784 parse_int (&(ieee->h), &value);
785 parse_int (&(ieee->h), &value);
787 case ieee_atn_record_enum:
788 /* We may get call optimization information here,
789 which we just ignore. The format is
790 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */
791 parse_int (&ieee->h, &value);
792 parse_int (&ieee->h, &value);
793 parse_int (&ieee->h, &value);
796 (*_bfd_error_handler)
797 (_("%B: unexpected ATN type %d in external part"),
799 bfd_set_error (bfd_error_bad_value);
802 parse_int (&ieee->h, &value);
803 parse_int (&ieee->h, &value);
810 switch (read_2bytes (&ieee->h))
812 case ieee_asn_record_enum:
813 parse_int (&ieee->h, &val1);
814 parse_int (&ieee->h, &val1);
818 (*_bfd_error_handler)
819 (_("%B: unexpected type after ATN"), abfd);
820 bfd_set_error (bfd_error_bad_value);
827 case ieee_value_record_enum >> 8:
829 unsigned int symbol_name_index;
830 ieee_symbol_index_type symbol_ignore;
831 bfd_boolean pcrel_ignore;
834 next_byte (&(ieee->h));
835 next_byte (&(ieee->h));
837 symbol_name_index = must_parse_int (&(ieee->h));
838 parse_expression (ieee,
839 &symbol->symbol.value,
843 &symbol->symbol.section);
845 /* Fully linked IEEE-695 files tend to give every symbol
846 an absolute value. Try to convert that back into a
847 section relative value. FIXME: This won't always to
849 if (bfd_is_abs_section (symbol->symbol.section)
850 && (abfd->flags & HAS_RELOC) == 0)
855 val = symbol->symbol.value;
856 for (s = abfd->sections; s != NULL; s = s->next)
858 if (val >= s->vma && val < s->vma + s->size)
860 symbol->symbol.section = s;
861 symbol->symbol.value -= s->vma;
867 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
871 case ieee_weak_external_reference_enum:
876 next_byte (&(ieee->h));
877 /* Throw away the external reference index. */
878 (void) must_parse_int (&(ieee->h));
879 /* Fetch the default size if not resolved. */
880 size = must_parse_int (&(ieee->h));
881 /* Fetch the default value if available. */
882 if (! parse_int (&(ieee->h), &value))
884 /* This turns into a common. */
885 symbol->symbol.section = bfd_com_section_ptr;
886 symbol->symbol.value = size;
890 case ieee_external_reference_enum:
891 next_byte (&(ieee->h));
893 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
895 &ieee->external_reference_max_index, 'X');
899 symbol->symbol.the_bfd = abfd;
900 symbol->symbol.name = read_id (&(ieee->h));
901 symbol->symbol.udata.p = NULL;
902 symbol->symbol.section = bfd_und_section_ptr;
903 symbol->symbol.value = (bfd_vma) 0;
904 symbol->symbol.flags = 0;
906 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
914 if (ieee->external_symbol_max_index != 0)
916 ieee->external_symbol_count =
917 ieee->external_symbol_max_index -
918 ieee->external_symbol_min_index + 1;
921 ieee->external_symbol_count = 0;
923 if (ieee->external_reference_max_index != 0)
925 ieee->external_reference_count =
926 ieee->external_reference_max_index -
927 ieee->external_reference_min_index + 1;
930 ieee->external_reference_count = 0;
933 ieee->external_reference_count + ieee->external_symbol_count;
935 if (symbol_count != abfd->symcount)
936 /* There are gaps in the table -- */
937 ieee->symbol_table_full = FALSE;
939 *prev_symbols_ptr = NULL;
940 *prev_reference_ptr = NULL;
946 ieee_slurp_symbol_table (bfd *abfd)
948 if (! IEEE_DATA (abfd)->read_symbols)
950 if (! ieee_slurp_external_symbols (abfd))
952 IEEE_DATA (abfd)->read_symbols = TRUE;
958 ieee_get_symtab_upper_bound (abfd)
961 if (! ieee_slurp_symbol_table (abfd))
964 return (abfd->symcount != 0) ?
965 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
968 /* Move from our internal lists to the canon table, and insert in
969 symbol index order. */
971 extern const bfd_target ieee_vec;
974 ieee_canonicalize_symtab (bfd *abfd, asymbol **location)
976 ieee_symbol_type *symp;
977 static bfd dummy_bfd;
978 static asymbol empty_symbol =
986 /* K&R compilers can't initialise unions. */
993 ieee_data_type *ieee = IEEE_DATA (abfd);
995 dummy_bfd.xvec = &ieee_vec;
996 if (! ieee_slurp_symbol_table (abfd))
999 if (! ieee->symbol_table_full)
1001 /* Arrgh - there are gaps in the table, run through and fill them
1002 up with pointers to a null place. */
1005 for (i = 0; i < abfd->symcount; i++)
1006 location[i] = &empty_symbol;
1009 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
1010 for (symp = IEEE_DATA (abfd)->external_symbols;
1011 symp != (ieee_symbol_type *) NULL;
1013 /* Place into table at correct index locations. */
1014 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
1016 /* The external refs are indexed in a bit. */
1017 ieee->external_reference_base_offset =
1018 -ieee->external_reference_min_index + ieee->external_symbol_count;
1020 for (symp = IEEE_DATA (abfd)->external_reference;
1021 symp != (ieee_symbol_type *) NULL;
1023 location[symp->index + ieee->external_reference_base_offset] =
1028 location[abfd->symcount] = (asymbol *) NULL;
1030 return abfd->symcount;
1034 get_section_entry (bfd *abfd, ieee_data_type *ieee, unsigned int index)
1036 if (index >= ieee->section_table_size)
1042 c = ieee->section_table_size;
1049 amt *= sizeof (asection *);
1050 n = bfd_realloc (ieee->section_table, amt);
1054 for (i = ieee->section_table_size; i < c; i++)
1057 ieee->section_table = n;
1058 ieee->section_table_size = c;
1061 if (ieee->section_table[index] == (asection *) NULL)
1063 char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
1068 sprintf (tmp, " fsec%4d", index);
1069 section = bfd_make_section (abfd, tmp);
1070 ieee->section_table[index] = section;
1071 section->flags = SEC_NO_FLAGS;
1072 section->target_index = index;
1073 ieee->section_table[index] = section;
1075 return ieee->section_table[index];
1079 ieee_slurp_sections (bfd *abfd)
1081 ieee_data_type *ieee = IEEE_DATA (abfd);
1082 file_ptr offset = ieee->w.r.section_part;
1087 bfd_byte section_type[3];
1089 ieee_seek (ieee, offset);
1092 switch (this_byte (&(ieee->h)))
1094 case ieee_section_type_enum:
1097 unsigned int section_index;
1099 next_byte (&(ieee->h));
1100 section_index = must_parse_int (&(ieee->h));
1102 section = get_section_entry (abfd, ieee, section_index);
1104 section_type[0] = this_byte_and_next (&(ieee->h));
1106 /* Set minimal section attributes. Attributes are
1107 extended later, based on section contents. */
1108 switch (section_type[0])
1111 /* Normal attributes for absolute sections. */
1112 section_type[1] = this_byte (&(ieee->h));
1113 section->flags = SEC_ALLOC;
1114 switch (section_type[1])
1116 /* AS Absolute section attributes. */
1118 next_byte (&(ieee->h));
1119 section_type[2] = this_byte (&(ieee->h));
1120 switch (section_type[2])
1124 next_byte (&(ieee->h));
1125 section->flags |= SEC_CODE;
1129 next_byte (&(ieee->h));
1130 section->flags |= SEC_DATA;
1133 next_byte (&(ieee->h));
1134 /* Normal rom data. */
1135 section->flags |= SEC_ROM | SEC_DATA;
1143 /* Named relocatable sections (type C). */
1145 section_type[1] = this_byte (&(ieee->h));
1146 section->flags = SEC_ALLOC;
1147 switch (section_type[1])
1149 case 0xD0: /* Normal code (CP). */
1150 next_byte (&(ieee->h));
1151 section->flags |= SEC_CODE;
1153 case 0xC4: /* Normal data (CD). */
1154 next_byte (&(ieee->h));
1155 section->flags |= SEC_DATA;
1157 case 0xD2: /* Normal rom data (CR). */
1158 next_byte (&(ieee->h));
1159 section->flags |= SEC_ROM | SEC_DATA;
1166 /* Read section name, use it if non empty. */
1167 name = read_id (&ieee->h);
1169 section->name = name;
1171 /* Skip these fields, which we don't care about. */
1173 bfd_vma parent, brother, context;
1175 parse_int (&(ieee->h), &parent);
1176 parse_int (&(ieee->h), &brother);
1177 parse_int (&(ieee->h), &context);
1181 case ieee_section_alignment_enum:
1183 unsigned int section_index;
1187 next_byte (&(ieee->h));
1188 section_index = must_parse_int (&ieee->h);
1189 section = get_section_entry (abfd, ieee, section_index);
1190 if (section_index > ieee->section_count)
1191 ieee->section_count = section_index;
1193 section->alignment_power =
1194 bfd_log2 (must_parse_int (&ieee->h));
1195 (void) parse_int (&(ieee->h), &value);
1198 case ieee_e2_first_byte_enum:
1201 ieee_record_enum_type t;
1203 t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1206 case ieee_section_size_enum:
1207 section = ieee->section_table[must_parse_int (&(ieee->h))];
1208 section->size = must_parse_int (&(ieee->h));
1210 case ieee_physical_region_size_enum:
1211 section = ieee->section_table[must_parse_int (&(ieee->h))];
1212 section->size = must_parse_int (&(ieee->h));
1214 case ieee_region_base_address_enum:
1215 section = ieee->section_table[must_parse_int (&(ieee->h))];
1216 section->vma = must_parse_int (&(ieee->h));
1217 section->lma = section->vma;
1219 case ieee_mau_size_enum:
1220 must_parse_int (&(ieee->h));
1221 must_parse_int (&(ieee->h));
1223 case ieee_m_value_enum:
1224 must_parse_int (&(ieee->h));
1225 must_parse_int (&(ieee->h));
1227 case ieee_section_base_address_enum:
1228 section = ieee->section_table[must_parse_int (&(ieee->h))];
1229 section->vma = must_parse_int (&(ieee->h));
1230 section->lma = section->vma;
1232 case ieee_section_offset_enum:
1233 (void) must_parse_int (&(ieee->h));
1234 (void) must_parse_int (&(ieee->h));
1248 /* Make a section for the debugging information, if any. We don't try
1249 to interpret the debugging information; we just point the section
1250 at the area in the file so that program which understand can dig it
1254 ieee_slurp_debug (bfd *abfd)
1256 ieee_data_type *ieee = IEEE_DATA (abfd);
1260 if (ieee->w.r.debug_information_part == 0)
1263 sec = bfd_make_section (abfd, ".debug");
1266 sec->flags |= SEC_DEBUGGING | SEC_HAS_CONTENTS;
1267 sec->filepos = ieee->w.r.debug_information_part;
1269 debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
1270 sec->size = debug_end - ieee->w.r.debug_information_part;
1275 /* Archive stuff. */
1278 ieee_archive_p (bfd *abfd)
1282 unsigned char buffer[512];
1283 file_ptr buffer_offset = 0;
1284 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1285 ieee_ar_data_type *ieee;
1286 bfd_size_type alc_elts;
1287 ieee_ar_obstack_type *elts = NULL;
1288 bfd_size_type amt = sizeof (ieee_ar_data_type);
1290 abfd->tdata.ieee_ar_data = bfd_alloc (abfd, amt);
1291 if (!abfd->tdata.ieee_ar_data)
1292 goto error_ret_restore;
1293 ieee = IEEE_AR_DATA (abfd);
1295 /* Ignore the return value here. It doesn't matter if we don't read
1296 the entire buffer. We might have a very small ieee file. */
1297 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1299 ieee->h.first_byte = buffer;
1300 ieee->h.input_p = buffer;
1302 ieee->h.abfd = abfd;
1304 if (this_byte (&(ieee->h)) != Module_Beginning)
1305 goto got_wrong_format_error;
1307 next_byte (&(ieee->h));
1308 library = read_id (&(ieee->h));
1309 if (strcmp (library, "LIBRARY") != 0)
1310 goto got_wrong_format_error;
1312 /* Throw away the filename. */
1313 read_id (&(ieee->h));
1315 ieee->element_count = 0;
1316 ieee->element_index = 0;
1318 next_byte (&(ieee->h)); /* Drop the ad part. */
1319 must_parse_int (&(ieee->h)); /* And the two dummy numbers. */
1320 must_parse_int (&(ieee->h));
1323 elts = bfd_malloc (alc_elts * sizeof *elts);
1327 /* Read the index of the BB table. */
1331 ieee_ar_obstack_type *t;
1333 rec = read_2bytes (&(ieee->h));
1334 if (rec != (int) ieee_assign_value_to_variable_enum)
1337 if (ieee->element_count >= alc_elts)
1339 ieee_ar_obstack_type *n;
1342 n = bfd_realloc (elts, alc_elts * sizeof (* elts));
1348 t = &elts[ieee->element_count];
1349 ieee->element_count++;
1351 must_parse_int (&(ieee->h));
1352 t->file_offset = must_parse_int (&(ieee->h));
1353 t->abfd = (bfd *) NULL;
1355 /* Make sure that we don't go over the end of the buffer. */
1356 if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
1358 /* Past half way, reseek and reprime. */
1359 buffer_offset += ieee_pos (IEEE_DATA (abfd));
1360 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1363 /* Again ignore return value of bfd_bread. */
1364 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1365 ieee->h.first_byte = buffer;
1366 ieee->h.input_p = buffer;
1370 amt = ieee->element_count;
1371 amt *= sizeof *ieee->elements;
1372 ieee->elements = bfd_alloc (abfd, amt);
1373 if (ieee->elements == NULL)
1376 memcpy (ieee->elements, elts, (size_t) amt);
1380 /* Now scan the area again, and replace BB offsets with file offsets. */
1381 for (i = 2; i < ieee->element_count; i++)
1383 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1386 /* Again ignore return value of bfd_bread. */
1387 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1388 ieee->h.first_byte = buffer;
1389 ieee->h.input_p = buffer;
1391 next_byte (&(ieee->h)); /* Drop F8. */
1392 next_byte (&(ieee->h)); /* Drop 14. */
1393 must_parse_int (&(ieee->h)); /* Drop size of block. */
1395 if (must_parse_int (&(ieee->h)) != 0)
1396 /* This object has been deleted. */
1397 ieee->elements[i].file_offset = 0;
1399 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1402 /* abfd->has_armap = ;*/
1406 got_wrong_format_error:
1407 bfd_set_error (bfd_error_wrong_format);
1411 bfd_release (abfd, ieee);
1413 abfd->tdata.ieee_ar_data = save;
1419 ieee_object_p (bfd *abfd)
1423 ieee_data_type *ieee;
1424 unsigned char buffer[300];
1425 ieee_data_type *save = IEEE_DATA (abfd);
1428 abfd->tdata.ieee_data = 0;
1429 ieee_mkobject (abfd);
1431 ieee = IEEE_DATA (abfd);
1432 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1434 /* Read the first few bytes in to see if it makes sense. Ignore
1435 bfd_bread return value; The file might be very small. */
1436 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1438 ieee->h.input_p = buffer;
1439 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1440 goto got_wrong_format;
1442 ieee->read_symbols = FALSE;
1443 ieee->read_data = FALSE;
1444 ieee->section_count = 0;
1445 ieee->external_symbol_max_index = 0;
1446 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1447 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1448 ieee->external_reference_max_index = 0;
1449 ieee->h.abfd = abfd;
1450 ieee->section_table = NULL;
1451 ieee->section_table_size = 0;
1453 processor = ieee->mb.processor = read_id (&(ieee->h));
1454 if (strcmp (processor, "LIBRARY") == 0)
1455 goto got_wrong_format;
1456 ieee->mb.module_name = read_id (&(ieee->h));
1457 if (abfd->filename == (const char *) NULL)
1458 abfd->filename = ieee->mb.module_name;
1460 /* Determine the architecture and machine type of the object file. */
1462 const bfd_arch_info_type *arch;
1465 /* IEEE does not specify the format of the processor identification
1466 string, so the compiler is free to put in it whatever it wants.
1467 We try here to recognize different processors belonging to the
1468 m68k family. Code for other processors can be added here. */
1469 if ((processor[0] == '6') && (processor[1] == '8'))
1471 if (processor[2] == '3') /* 683xx integrated processors. */
1473 switch (processor[3])
1475 case '0': /* 68302, 68306, 68307 */
1476 case '2': /* 68322, 68328 */
1477 case '5': /* 68356 */
1478 strcpy (family, "68000"); /* MC68000-based controllers. */
1481 case '3': /* 68330, 68331, 68332, 68333,
1482 68334, 68335, 68336, 68338 */
1483 case '6': /* 68360 */
1484 case '7': /* 68376 */
1485 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1489 if (processor[4] == '9') /* 68349 */
1490 strcpy (family, "68030"); /* CPU030 */
1491 else /* 68340, 68341 */
1492 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1495 default: /* Does not exist yet. */
1496 strcpy (family, "68332"); /* Guess it will be CPU32 */
1499 else if (TOUPPER (processor[3]) == 'F') /* 68F333 */
1500 strcpy (family, "68332"); /* CPU32 */
1501 else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers. */
1502 && ((TOUPPER (processor[2]) == 'E')
1503 || (TOUPPER (processor[2]) == 'H')
1504 || (TOUPPER (processor[2]) == 'L')))
1506 strcpy (family, "68");
1507 strncat (family, processor + 4, 7);
1510 else /* "Regular" processors. */
1512 strncpy (family, processor, 9);
1516 else if ((strncmp (processor, "cpu32", 5) == 0) /* CPU32 and CPU32+ */
1517 || (strncmp (processor, "CPU32", 5) == 0))
1518 strcpy (family, "68332");
1521 strncpy (family, processor, 9);
1525 arch = bfd_scan_arch (family);
1527 goto got_wrong_format;
1528 abfd->arch_info = arch;
1531 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1534 next_byte (&(ieee->h));
1536 if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
1539 if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
1542 /* If there is a byte order info, take it. */
1543 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum
1544 || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
1545 next_byte (&(ieee->h));
1547 for (part = 0; part < N_W_VARIABLES; part++)
1551 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
1554 if (this_byte_and_next (&(ieee->h)) != part)
1557 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
1562 if (ieee->w.r.external_part != 0)
1563 abfd->flags = HAS_SYMS;
1565 /* By now we know that this is a real IEEE file, we're going to read
1566 the whole thing into memory so that we can run up and down it
1567 quickly. We can work out how big the file is from the trailer
1570 amt = ieee->w.r.me_record + 1;
1571 IEEE_DATA (abfd)->h.first_byte = bfd_alloc (ieee->h.abfd, amt);
1572 if (!IEEE_DATA (abfd)->h.first_byte)
1574 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1576 /* FIXME: Check return value. I'm not sure whether it needs to read
1577 the entire buffer or not. */
1578 bfd_bread ((void *) (IEEE_DATA (abfd)->h.first_byte),
1579 (bfd_size_type) ieee->w.r.me_record + 1, abfd);
1581 ieee_slurp_sections (abfd);
1583 if (! ieee_slurp_debug (abfd))
1586 /* Parse section data to activate file and section flags implied by
1587 section contents. */
1588 if (! ieee_slurp_section_data (abfd))
1593 bfd_set_error (bfd_error_wrong_format);
1595 bfd_release (abfd, ieee);
1596 abfd->tdata.ieee_data = save;
1597 return (const bfd_target *) NULL;
1601 ieee_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED,
1605 bfd_symbol_info (symbol, ret);
1606 if (symbol->name[0] == ' ')
1607 ret->name = "* empty table entry ";
1608 if (!symbol->section)
1609 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
1613 ieee_print_symbol (bfd *abfd,
1616 bfd_print_symbol_type how)
1618 FILE *file = (FILE *) afile;
1622 case bfd_print_symbol_name:
1623 fprintf (file, "%s", symbol->name);
1625 case bfd_print_symbol_more:
1628 case bfd_print_symbol_all:
1630 const char *section_name =
1631 (symbol->section == (asection *) NULL
1633 : symbol->section->name);
1635 if (symbol->name[0] == ' ')
1636 fprintf (file, "* empty table entry ");
1639 bfd_print_symbol_vandf (abfd, (void *) file, symbol);
1641 fprintf (file, " %-5s %04x %02x %s",
1643 (unsigned) ieee_symbol (symbol)->index,
1653 do_one (ieee_data_type *ieee,
1654 ieee_per_section_type *current_map,
1655 unsigned char *location_ptr,
1659 switch (this_byte (&(ieee->h)))
1661 case ieee_load_constant_bytes_enum:
1663 unsigned int number_of_maus;
1666 next_byte (&(ieee->h));
1667 number_of_maus = must_parse_int (&(ieee->h));
1669 for (i = 0; i < number_of_maus; i++)
1671 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1672 next_byte (&(ieee->h));
1677 case ieee_load_with_relocation_enum:
1679 bfd_boolean loop = TRUE;
1681 next_byte (&(ieee->h));
1684 switch (this_byte (&(ieee->h)))
1686 case ieee_variable_R_enum:
1688 case ieee_function_signed_open_b_enum:
1689 case ieee_function_unsigned_open_b_enum:
1690 case ieee_function_either_open_b_enum:
1692 unsigned int extra = 4;
1693 bfd_boolean pcrel = FALSE;
1696 bfd_size_type amt = sizeof (ieee_reloc_type);
1698 r = bfd_alloc (ieee->h.abfd, amt);
1702 *(current_map->reloc_tail_ptr) = r;
1703 current_map->reloc_tail_ptr = &r->next;
1704 r->next = (ieee_reloc_type *) NULL;
1705 next_byte (&(ieee->h));
1707 r->relent.sym_ptr_ptr = 0;
1708 parse_expression (ieee,
1711 &pcrel, &extra, §ion);
1712 r->relent.address = current_map->pc;
1713 s->flags |= SEC_RELOC;
1714 s->owner->flags |= HAS_RELOC;
1716 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
1717 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1719 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1721 next_byte (&(ieee->h));
1722 /* Fetch number of bytes to pad. */
1723 extra = must_parse_int (&(ieee->h));
1726 switch (this_byte (&(ieee->h)))
1728 case ieee_function_signed_close_b_enum:
1729 next_byte (&(ieee->h));
1731 case ieee_function_unsigned_close_b_enum:
1732 next_byte (&(ieee->h));
1734 case ieee_function_either_close_b_enum:
1735 next_byte (&(ieee->h));
1740 /* Build a relocation entry for this type. */
1741 /* If pc rel then stick -ve pc into instruction
1742 and take out of reloc ..
1744 I've changed this. It's all too complicated. I
1745 keep 0 in the instruction now. */
1754 #if KEEPMINUSPCININST
1755 bfd_put_32 (ieee->h.abfd, -current_map->pc,
1756 location_ptr + current_map->pc);
1757 r->relent.howto = &rel32_howto;
1758 r->relent.addend -= current_map->pc;
1760 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
1762 r->relent.howto = &rel32_howto;
1767 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
1768 location_ptr + current_map->pc);
1769 r->relent.howto = &abs32_howto;
1771 current_map->pc += 4;
1776 #if KEEPMINUSPCININST
1777 bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
1778 location_ptr + current_map->pc);
1779 r->relent.addend -= current_map->pc;
1780 r->relent.howto = &rel16_howto;
1783 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1784 location_ptr + current_map->pc);
1785 r->relent.howto = &rel16_howto;
1791 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1792 location_ptr + current_map->pc);
1793 r->relent.howto = &abs16_howto;
1795 current_map->pc += 2;
1800 #if KEEPMINUSPCININST
1801 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1802 r->relent.addend -= current_map->pc;
1803 r->relent.howto = &rel8_howto;
1805 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1806 r->relent.howto = &rel8_howto;
1811 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1812 r->relent.howto = &abs8_howto;
1814 current_map->pc += 1;
1827 if (parse_int (&(ieee->h), &this_size))
1831 for (i = 0; i < this_size; i++)
1833 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1834 next_byte (&(ieee->h));
1842 /* Prevent more than the first load-item of an LR record
1843 from being repeated (MRI convention). */
1844 if (iterations != 1)
1852 /* Read in all the section data and relocation stuff too. */
1855 ieee_slurp_section_data (bfd *abfd)
1857 bfd_byte *location_ptr = (bfd_byte *) NULL;
1858 ieee_data_type *ieee = IEEE_DATA (abfd);
1859 unsigned int section_number;
1860 ieee_per_section_type *current_map = NULL;
1863 /* Seek to the start of the data area. */
1864 if (ieee->read_data)
1866 ieee->read_data = TRUE;
1867 ieee_seek (ieee, ieee->w.r.data_part);
1869 /* Allocate enough space for all the section contents. */
1870 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1872 ieee_per_section_type *per = ieee_per_section (s);
1874 if ((s->flags & SEC_DEBUGGING) != 0)
1876 per->data = bfd_alloc (ieee->h.abfd, s->size);
1879 per->reloc_tail_ptr =
1880 (ieee_reloc_type **) & (s->relocation);
1885 switch (this_byte (&(ieee->h)))
1887 /* IF we see anything strange then quit. */
1891 case ieee_set_current_section_enum:
1892 next_byte (&(ieee->h));
1893 section_number = must_parse_int (&(ieee->h));
1894 s = ieee->section_table[section_number];
1895 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
1896 current_map = ieee_per_section (s);
1897 location_ptr = current_map->data - s->vma;
1898 /* The document I have says that Microtec's compilers reset
1899 this after a sec section, even though the standard says not
1901 current_map->pc = s->vma;
1904 case ieee_e2_first_byte_enum:
1905 next_byte (&(ieee->h));
1906 switch (this_byte (&(ieee->h)))
1908 case ieee_set_current_pc_enum & 0xff:
1911 ieee_symbol_index_type symbol;
1915 next_byte (&(ieee->h));
1916 must_parse_int (&(ieee->h)); /* Throw away section #. */
1917 parse_expression (ieee, &value,
1921 current_map->pc = value;
1922 BFD_ASSERT ((unsigned) (value - s->vma) <= s->size);
1926 case ieee_value_starting_address_enum & 0xff:
1927 next_byte (&(ieee->h));
1928 if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
1929 next_byte (&(ieee->h));
1930 abfd->start_address = must_parse_int (&(ieee->h));
1931 /* We've got to the end of the data now - */
1938 case ieee_repeat_data_enum:
1940 /* Repeat the following LD or LR n times - we do this by
1941 remembering the stream pointer before running it and
1942 resetting it and running it n times. We special case
1943 the repetition of a repeat_data/load_constant. */
1944 unsigned int iterations;
1945 unsigned char *start;
1947 next_byte (&(ieee->h));
1948 iterations = must_parse_int (&(ieee->h));
1949 start = ieee->h.input_p;
1950 if (start[0] == (int) ieee_load_constant_bytes_enum
1953 while (iterations != 0)
1955 location_ptr[current_map->pc++] = start[2];
1958 next_byte (&(ieee->h));
1959 next_byte (&(ieee->h));
1960 next_byte (&(ieee->h));
1964 while (iterations != 0)
1966 ieee->h.input_p = start;
1967 if (!do_one (ieee, current_map, location_ptr, s,
1975 case ieee_load_constant_bytes_enum:
1976 case ieee_load_with_relocation_enum:
1977 if (!do_one (ieee, current_map, location_ptr, s, 1))
1984 ieee_new_section_hook (bfd *abfd, asection *newsect)
1986 newsect->used_by_bfd = bfd_alloc (abfd, (bfd_size_type) sizeof (ieee_per_section_type));
1987 if (!newsect->used_by_bfd)
1989 ieee_per_section (newsect)->data = NULL;
1990 ieee_per_section (newsect)->section = newsect;
1995 ieee_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
1997 if ((asect->flags & SEC_DEBUGGING) != 0)
1999 if (! ieee_slurp_section_data (abfd))
2001 return (asect->reloc_count + 1) * sizeof (arelent *);
2005 ieee_get_section_contents (bfd *abfd,
2009 bfd_size_type count)
2011 ieee_per_section_type *p = ieee_per_section (section);
2012 if ((section->flags & SEC_DEBUGGING) != 0)
2013 return _bfd_generic_get_section_contents (abfd, section, location,
2015 ieee_slurp_section_data (abfd);
2016 (void) memcpy ((void *) location, (void *) (p->data + offset), (unsigned) count);
2021 ieee_canonicalize_reloc (bfd *abfd,
2026 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
2027 ieee_data_type *ieee = IEEE_DATA (abfd);
2029 if ((section->flags & SEC_DEBUGGING) != 0)
2032 while (src != (ieee_reloc_type *) NULL)
2034 /* Work out which symbol to attach it this reloc to. */
2035 switch (src->symbol.letter)
2038 src->relent.sym_ptr_ptr =
2039 symbols + src->symbol.index + ieee->external_symbol_base_offset;
2042 src->relent.sym_ptr_ptr =
2043 symbols + src->symbol.index + ieee->external_reference_base_offset;
2046 if (src->relent.sym_ptr_ptr != NULL)
2047 src->relent.sym_ptr_ptr =
2048 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
2054 *relptr++ = &src->relent;
2058 return section->reloc_count;
2062 comp (const void * ap, const void * bp)
2064 arelent *a = *((arelent **) ap);
2065 arelent *b = *((arelent **) bp);
2066 return a->address - b->address;
2069 /* Write the section headers. */
2072 ieee_write_section_part (bfd *abfd)
2074 ieee_data_type *ieee = IEEE_DATA (abfd);
2077 ieee->w.r.section_part = bfd_tell (abfd);
2078 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2080 if (! bfd_is_abs_section (s)
2081 && (s->flags & SEC_DEBUGGING) == 0)
2083 if (! ieee_write_byte (abfd, ieee_section_type_enum)
2084 || ! ieee_write_byte (abfd,
2085 (bfd_byte) (s->index
2086 + IEEE_SECTION_NUMBER_BASE)))
2089 if (abfd->flags & EXEC_P)
2091 /* This image is executable, so output absolute sections. */
2092 if (! ieee_write_byte (abfd, ieee_variable_A_enum)
2093 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
2098 if (! ieee_write_byte (abfd, ieee_variable_C_enum))
2102 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
2104 case SEC_CODE | SEC_LOAD:
2106 if (! ieee_write_byte (abfd, ieee_variable_P_enum))
2111 if (! ieee_write_byte (abfd, ieee_variable_D_enum))
2115 case SEC_ROM | SEC_DATA:
2116 case SEC_ROM | SEC_LOAD:
2117 case SEC_ROM | SEC_DATA | SEC_LOAD:
2118 if (! ieee_write_byte (abfd, ieee_variable_R_enum))
2123 if (! ieee_write_id (abfd, s->name))
2126 if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
2127 || ! ieee_write_byte (abfd,
2128 (bfd_byte) (s->index
2129 + IEEE_SECTION_NUMBER_BASE))
2130 || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
2134 if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
2135 || ! ieee_write_byte (abfd,
2136 (bfd_byte) (s->index
2137 + IEEE_SECTION_NUMBER_BASE))
2138 || ! ieee_write_int (abfd, s->size))
2140 if (abfd->flags & EXEC_P)
2142 /* Relocateable sections don't have asl records. */
2144 if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
2145 || ! ieee_write_byte (abfd,
2148 + IEEE_SECTION_NUMBER_BASE)))
2149 || ! ieee_write_int (abfd, s->lma))
2159 do_with_relocs (bfd *abfd, asection *s)
2161 unsigned int number_of_maus_in_address =
2162 bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
2163 unsigned int relocs_to_go = s->reloc_count;
2164 bfd_byte *stream = ieee_per_section (s)->data;
2165 arelent **p = s->orelocation;
2166 bfd_size_type current_byte_index = 0;
2168 qsort (s->orelocation,
2170 sizeof (arelent **),
2173 /* Output the section preheader. */
2174 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2175 || ! ieee_write_byte (abfd,
2176 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
2177 || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
2178 || ! ieee_write_byte (abfd,
2179 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
2182 if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
2184 if (! ieee_write_int (abfd, s->lma))
2189 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2193 if (relocs_to_go == 0)
2195 /* If there aren't any relocations then output the load constant
2196 byte opcode rather than the load with relocation opcode. */
2197 while (current_byte_index < s->size)
2200 unsigned int MAXRUN = 127;
2203 if (run > s->size - current_byte_index)
2204 run = s->size - current_byte_index;
2208 if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
2210 /* Output a stream of bytes. */
2211 if (! ieee_write_int (abfd, run))
2213 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
2216 current_byte_index += run;
2222 if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
2225 /* Output the data stream as the longest sequence of bytes
2226 possible, allowing for the a reasonable packet size and
2227 relocation stuffs. */
2230 /* Outputting a section without data, fill it up. */
2231 stream = bfd_zalloc (abfd, s->size);
2235 while (current_byte_index < s->size)
2238 unsigned int MAXRUN = 127;
2242 run = (*p)->address - current_byte_index;
2249 if (run > s->size - current_byte_index)
2250 run = s->size - current_byte_index;
2254 /* Output a stream of bytes. */
2255 if (! ieee_write_int (abfd, run))
2257 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
2260 current_byte_index += run;
2263 /* Output any relocations here. */
2264 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
2267 && (*p) && (*p)->address == current_byte_index)
2271 switch (r->howto->size)
2274 ov = bfd_get_signed_32 (abfd,
2275 stream + current_byte_index);
2276 current_byte_index += 4;
2279 ov = bfd_get_signed_16 (abfd,
2280 stream + current_byte_index);
2281 current_byte_index += 2;
2284 ov = bfd_get_signed_8 (abfd,
2285 stream + current_byte_index);
2286 current_byte_index++;
2294 ov &= r->howto->src_mask;
2296 if (r->howto->pc_relative
2297 && ! r->howto->pcrel_offset)
2300 if (! ieee_write_byte (abfd,
2301 ieee_function_either_open_b_enum))
2304 if (r->sym_ptr_ptr != (asymbol **) NULL)
2306 if (! ieee_write_expression (abfd, r->addend + ov,
2308 r->howto->pc_relative,
2309 (unsigned) s->index))
2314 if (! ieee_write_expression (abfd, r->addend + ov,
2316 r->howto->pc_relative,
2317 (unsigned) s->index))
2321 if (number_of_maus_in_address
2322 != bfd_get_reloc_size (r->howto))
2324 bfd_vma rsize = bfd_get_reloc_size (r->howto);
2325 if (! ieee_write_int (abfd, rsize))
2328 if (! ieee_write_byte (abfd,
2329 ieee_function_either_close_b_enum))
2343 /* If there are no relocations in the output section then we can be
2344 clever about how we write. We block items up into a max of 127
2348 do_as_repeat (bfd *abfd, asection *s)
2352 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2353 || ! ieee_write_byte (abfd,
2354 (bfd_byte) (s->index
2355 + IEEE_SECTION_NUMBER_BASE))
2356 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
2357 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
2358 || ! ieee_write_byte (abfd,
2359 (bfd_byte) (s->index
2360 + IEEE_SECTION_NUMBER_BASE)))
2363 if ((abfd->flags & EXEC_P) != 0)
2365 if (! ieee_write_int (abfd, s->lma))
2370 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2374 if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
2375 || ! ieee_write_int (abfd, s->size)
2376 || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
2377 || ! ieee_write_byte (abfd, 1)
2378 || ! ieee_write_byte (abfd, 0))
2386 do_without_relocs (bfd *abfd, asection *s)
2388 bfd_byte *stream = ieee_per_section (s)->data;
2390 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2392 if (! do_as_repeat (abfd, s))
2399 for (i = 0; i < s->size; i++)
2403 if (! do_with_relocs (abfd, s))
2408 if (! do_as_repeat (abfd, s))
2416 static unsigned char *output_ptr_start;
2417 static unsigned char *output_ptr;
2418 static unsigned char *output_ptr_end;
2419 static unsigned char *input_ptr_start;
2420 static unsigned char *input_ptr;
2421 static unsigned char *input_ptr_end;
2422 static bfd *input_bfd;
2423 static bfd *output_bfd;
2424 static int output_buffer;
2427 ieee_mkobject (bfd *abfd)
2431 output_ptr_start = NULL;
2433 output_ptr_end = NULL;
2434 input_ptr_start = NULL;
2436 input_ptr_end = NULL;
2440 amt = sizeof (ieee_data_type);
2441 abfd->tdata.ieee_data = bfd_zalloc (abfd, amt);
2442 return abfd->tdata.ieee_data != NULL;
2448 bfd_size_type amt = input_ptr_end - input_ptr_start;
2449 /* FIXME: Check return value. I'm not sure whether it needs to read
2450 the entire buffer or not. */
2451 bfd_bread ((void *) input_ptr_start, amt, input_bfd);
2452 input_ptr = input_ptr_start;
2458 bfd_size_type amt = output_ptr - output_ptr_start;
2460 if (bfd_bwrite ((void *) (output_ptr_start), amt, output_bfd) != amt)
2462 output_ptr = output_ptr_start;
2466 #define THIS() ( *input_ptr )
2467 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); }
2468 #define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end) flush (); }
2471 write_int (int value)
2473 if (value >= 0 && value <= 127)
2479 unsigned int length;
2481 /* How many significant bytes ? */
2482 /* FIXME FOR LONGER INTS. */
2483 if (value & 0xff000000)
2485 else if (value & 0x00ff0000)
2487 else if (value & 0x0000ff00)
2492 OUT ((int) ieee_number_repeat_start_enum + length);
2510 int length = THIS ();
2523 #define VAR(x) ((x | 0x80))
2539 value = (value << 8) | THIS ();
2541 value = (value << 8) | THIS ();
2543 value = (value << 8) | THIS ();
2551 value = (value << 8) | THIS ();
2553 value = (value << 8) | THIS ();
2561 value = (value << 8) | THIS ();
2578 /* Not a number, just bug out with the answer. */
2579 write_int (*(--tos));
2586 /* PLUS anything. */
2595 ieee_data_type *ieee;
2599 section_number = THIS ();
2602 ieee = IEEE_DATA (input_bfd);
2603 s = ieee->section_table[section_number];
2605 if (s->output_section)
2606 value = s->output_section->lma;
2607 value += s->output_offset;
2614 write_int (*(--tos));
2622 /* Drop the int in the buffer, and copy a null into the gap, which we
2623 will overwrite later. */
2627 struct output_buffer_struct *buf;
2629 if (buf->buffer == output_buffer)
2631 /* Still a chance to output the size. */
2632 int value = output_ptr - buf->ptrp + 3;
2633 buf->ptrp[0] = value >> 24;
2634 buf->ptrp[1] = value >> 16;
2635 buf->ptrp[2] = value >> 8;
2636 buf->ptrp[3] = value >> 0;
2642 struct output_buffer_struct *buf;
2669 buf->ptrp = output_ptr;
2670 buf->buffer = output_buffer;
2710 #define ID copy_id()
2711 #define INT copy_int()
2712 #define EXP copy_expression()
2713 #define INTn(q) copy_int()
2714 #define EXPn(q) copy_expression()
2754 EXPn (instruction address);
2788 EXPn (external function);
2798 INTn (locked register);
2820 /* Attribute record. */
2890 /* Unique typedefs for module. */
2891 /* GLobal typedefs. */
2892 /* High level module scope beginning. */
2894 struct output_buffer_struct ob;
2910 /* Global function. */
2912 struct output_buffer_struct ob;
2927 EXPn (size of block);
2933 /* File name for source line numbers. */
2935 struct output_buffer_struct ob;
2956 /* Local function. */
2958 struct output_buffer_struct ob;
2977 /* Assembler module scope beginning - */
2979 struct output_buffer_struct ob;
3005 struct output_buffer_struct ob;
3013 INTn (section index);
3021 EXPn (Size in Maus);
3075 /* Moves all the debug information from the source bfd to the output
3076 bfd, and relocates any expressions it finds. */
3079 relocate_debug (output, input)
3080 bfd *output ATTRIBUTE_UNUSED;
3085 unsigned char input_buffer[IBS];
3087 input_ptr_start = input_ptr = input_buffer;
3088 input_ptr_end = input_buffer + IBS;
3090 /* FIXME: Check return value. I'm not sure whether it needs to read
3091 the entire buffer or not. */
3092 bfd_bread ((void *) input_ptr_start, (bfd_size_type) IBS, input);
3096 /* Gather together all the debug information from each input BFD into
3097 one place, relocating it and emitting it as we go. */
3100 ieee_write_debug_part (abfd)
3103 ieee_data_type *ieee = IEEE_DATA (abfd);
3104 bfd_chain_type *chain = ieee->chain_root;
3105 unsigned char obuff[OBS];
3106 bfd_boolean some_debug = FALSE;
3107 file_ptr here = bfd_tell (abfd);
3109 output_ptr_start = output_ptr = obuff;
3110 output_ptr_end = obuff + OBS;
3114 if (chain == (bfd_chain_type *) NULL)
3118 for (s = abfd->sections; s != NULL; s = s->next)
3119 if ((s->flags & SEC_DEBUGGING) != 0)
3123 ieee->w.r.debug_information_part = 0;
3127 ieee->w.r.debug_information_part = here;
3128 if (bfd_bwrite (s->contents, s->size, abfd) != s->size)
3133 while (chain != (bfd_chain_type *) NULL)
3135 bfd *entry = chain->this;
3136 ieee_data_type *entry_ieee = IEEE_DATA (entry);
3138 if (entry_ieee->w.r.debug_information_part)
3140 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
3143 relocate_debug (abfd, entry);
3146 chain = chain->next;
3150 ieee->w.r.debug_information_part = here;
3152 ieee->w.r.debug_information_part = 0;
3160 /* Write the data in an ieee way. */
3163 ieee_write_data_part (abfd)
3168 ieee_data_type *ieee = IEEE_DATA (abfd);
3169 ieee->w.r.data_part = bfd_tell (abfd);
3171 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3173 /* Skip sections that have no loadable contents (.bss,
3175 if ((s->flags & SEC_LOAD) == 0)
3178 /* Sort the reloc records so we can insert them in the correct
3180 if (s->reloc_count != 0)
3182 if (! do_with_relocs (abfd, s))
3187 if (! do_without_relocs (abfd, s))
3197 init_for_output (abfd)
3202 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3204 if ((s->flags & SEC_DEBUGGING) != 0)
3208 bfd_size_type size = s->size;
3209 ieee_per_section (s)->data = bfd_alloc (abfd, size);
3210 if (!ieee_per_section (s)->data)
3217 /* Exec and core file sections. */
3219 /* Set section contents is complicated with IEEE since the format is
3220 not a byte image, but a record stream. */
3223 ieee_set_section_contents (abfd, section, location, offset, count)
3226 const void * location;
3228 bfd_size_type count;
3230 if ((section->flags & SEC_DEBUGGING) != 0)
3232 if (section->contents == NULL)
3234 bfd_size_type size = section->size;
3235 section->contents = bfd_alloc (abfd, size);
3236 if (section->contents == NULL)
3239 /* bfd_set_section_contents has already checked that everything
3241 memcpy (section->contents + offset, location, (size_t) count);
3245 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
3247 if (!init_for_output (abfd))
3250 memcpy ((void *) (ieee_per_section (section)->data + offset),
3252 (unsigned int) count);
3256 /* Write the external symbols of a file. IEEE considers two sorts of
3257 external symbols, public, and referenced. It uses to internal
3258 forms to index them as well. When we write them out we turn their
3259 symbol values into indexes from the right base. */
3262 ieee_write_external_part (abfd)
3266 ieee_data_type *ieee = IEEE_DATA (abfd);
3267 unsigned int reference_index = IEEE_REFERENCE_BASE;
3268 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
3269 file_ptr here = bfd_tell (abfd);
3270 bfd_boolean hadone = FALSE;
3272 if (abfd->outsymbols != (asymbol **) NULL)
3275 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
3279 if (bfd_is_und_section (p->section))
3281 /* This must be a symbol reference. */
3282 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3283 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3284 || ! ieee_write_id (abfd, p->name))
3286 p->value = reference_index;
3290 else if (bfd_is_com_section (p->section))
3292 /* This is a weak reference. */
3293 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3294 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3295 || ! ieee_write_id (abfd, p->name)
3296 || ! ieee_write_byte (abfd,
3297 ieee_weak_external_reference_enum)
3298 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3299 || ! ieee_write_int (abfd, p->value))
3301 p->value = reference_index;
3305 else if (p->flags & BSF_GLOBAL)
3307 /* This must be a symbol definition. */
3308 if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
3309 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3310 || ! ieee_write_id (abfd, p->name)
3311 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
3312 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3313 || ! ieee_write_byte (abfd, 15) /* Instruction address. */
3314 || ! ieee_write_byte (abfd, 19) /* Static symbol. */
3315 || ! ieee_write_byte (abfd, 1)) /* One of them. */
3318 /* Write out the value. */
3319 if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
3320 || ! ieee_write_int (abfd, (bfd_vma) public_index))
3322 if (! bfd_is_abs_section (p->section))
3324 if (abfd->flags & EXEC_P)
3326 /* If fully linked, then output all symbols
3328 if (! (ieee_write_int
3331 + p->section->output_offset
3332 + p->section->output_section->vma))))
3337 if (! (ieee_write_expression
3339 p->value + p->section->output_offset,
3340 p->section->output_section->symbol,
3347 if (! ieee_write_expression (abfd,
3349 bfd_abs_section_ptr->symbol,
3353 p->value = public_index;
3359 /* This can happen - when there are gaps in the symbols read
3360 from an input ieee file. */
3365 ieee->w.r.external_part = here;
3371 static const unsigned char exten[] =
3374 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3375 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
3376 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
3379 static const unsigned char envi[] =
3383 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3386 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */
3388 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */
3389 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3393 ieee_write_me_part (abfd)
3396 ieee_data_type *ieee = IEEE_DATA (abfd);
3397 ieee->w.r.trailer_part = bfd_tell (abfd);
3398 if (abfd->start_address)
3400 if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
3401 || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
3402 || ! ieee_write_int (abfd, abfd->start_address)
3403 || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
3406 ieee->w.r.me_record = bfd_tell (abfd);
3407 if (! ieee_write_byte (abfd, ieee_module_end_enum))
3412 /* Write out the IEEE processor ID. */
3415 ieee_write_processor (abfd)
3418 const bfd_arch_info_type *arch;
3420 arch = bfd_get_arch_info (abfd);
3424 if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
3429 if (! ieee_write_id (abfd, "29000"))
3433 case bfd_arch_h8300:
3434 if (! ieee_write_id (abfd, "H8/300"))
3438 case bfd_arch_h8500:
3439 if (! ieee_write_id (abfd, "H8/500"))
3447 case bfd_mach_i960_core:
3448 case bfd_mach_i960_ka_sa:
3449 if (! ieee_write_id (abfd, "80960KA"))
3453 case bfd_mach_i960_kb_sb:
3454 if (! ieee_write_id (abfd, "80960KB"))
3458 case bfd_mach_i960_ca:
3459 if (! ieee_write_id (abfd, "80960CA"))
3463 case bfd_mach_i960_mc:
3464 case bfd_mach_i960_xa:
3465 if (! ieee_write_id (abfd, "80960MC"))
3477 default: id = "68020"; break;
3478 case bfd_mach_m68000: id = "68000"; break;
3479 case bfd_mach_m68008: id = "68008"; break;
3480 case bfd_mach_m68010: id = "68010"; break;
3481 case bfd_mach_m68020: id = "68020"; break;
3482 case bfd_mach_m68030: id = "68030"; break;
3483 case bfd_mach_m68040: id = "68040"; break;
3484 case bfd_mach_m68060: id = "68060"; break;
3485 case bfd_mach_cpu32: id = "cpu32"; break;
3486 case bfd_mach_mcf5200:id = "5200"; break;
3487 case bfd_mach_mcf5206e:id = "5206e"; break;
3488 case bfd_mach_mcf5307:id = "5307"; break;
3489 case bfd_mach_mcf5407:id = "5407"; break;
3490 case bfd_mach_mcf528x:id = "5282"; break;
3493 if (! ieee_write_id (abfd, id))
3503 ieee_write_object_contents (abfd)
3506 ieee_data_type *ieee = IEEE_DATA (abfd);
3510 /* Fast forward over the header area. */
3511 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3514 if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
3515 || ! ieee_write_processor (abfd)
3516 || ! ieee_write_id (abfd, abfd->filename))
3519 /* Fast forward over the variable bits. */
3520 if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
3524 if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
3526 /* MAU's per address. */
3527 if (! ieee_write_byte (abfd,
3528 (bfd_byte) (bfd_arch_bits_per_address (abfd)
3529 / bfd_arch_bits_per_byte (abfd))))
3532 old = bfd_tell (abfd);
3533 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3536 ieee->w.r.extension_record = bfd_tell (abfd);
3537 if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
3540 if (abfd->flags & EXEC_P)
3542 if (! ieee_write_byte (abfd, 0x1)) /* Absolute. */
3547 if (! ieee_write_byte (abfd, 0x2)) /* Relocateable. */
3551 ieee->w.r.environmental_record = bfd_tell (abfd);
3552 if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
3556 /* The HP emulator database requires a timestamp in the file. */
3562 t = (struct tm *) localtime (&now);
3563 if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
3564 || ! ieee_write_byte (abfd, 0x21)
3565 || ! ieee_write_byte (abfd, 0)
3566 || ! ieee_write_byte (abfd, 50)
3567 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
3568 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
3569 || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
3570 || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
3571 || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
3572 || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
3580 if (! ieee_write_section_part (abfd))
3582 /* First write the symbols. This changes their values into table
3583 indeces so we cant use it after this point. */
3584 if (! ieee_write_external_part (abfd))
3587 /* Write any debugs we have been told about. */
3588 if (! ieee_write_debug_part (abfd))
3591 /* Can only write the data once the symbols have been written, since
3592 the data contains relocation information which points to the
3594 if (! ieee_write_data_part (abfd))
3597 /* At the end we put the end! */
3598 if (! ieee_write_me_part (abfd))
3601 /* Generate the header. */
3602 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3605 for (i = 0; i < N_W_VARIABLES; i++)
3607 if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
3608 || ! ieee_write_byte (abfd, (bfd_byte) i)
3609 || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
3616 /* Native-level interface to symbols. */
3618 /* We read the symbols into a buffer, which is discarded when this
3619 function exits. We read the strings into a buffer large enough to
3620 hold them all plus all the cached symbol entries. */
3623 ieee_make_empty_symbol (abfd)
3626 bfd_size_type amt = sizeof (ieee_symbol_type);
3627 ieee_symbol_type *new = bfd_zalloc (abfd, amt);
3631 new->symbol.the_bfd = abfd;
3632 return &new->symbol;
3636 ieee_openr_next_archived_file (arch, prev)
3640 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3642 /* Take the next one from the arch state, or reset. */
3643 if (prev == (bfd *) NULL)
3644 /* Reset the index - the first two entries are bogus. */
3645 ar->element_index = 2;
3649 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3651 ar->element_index++;
3652 if (ar->element_index <= ar->element_count)
3654 if (p->file_offset != (file_ptr) 0)
3656 if (p->abfd == (bfd *) NULL)
3658 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3659 p->abfd->origin = p->file_offset;
3666 bfd_set_error (bfd_error_no_more_archived_files);
3667 return (bfd *) NULL;
3673 ieee_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
3674 functionname_ptr, line_ptr)
3675 bfd *abfd ATTRIBUTE_UNUSED;
3676 asection *section ATTRIBUTE_UNUSED;
3677 asymbol **symbols ATTRIBUTE_UNUSED;
3678 bfd_vma offset ATTRIBUTE_UNUSED;
3679 const char **filename_ptr ATTRIBUTE_UNUSED;
3680 const char **functionname_ptr ATTRIBUTE_UNUSED;
3681 unsigned int *line_ptr ATTRIBUTE_UNUSED;
3687 ieee_generic_stat_arch_elt (abfd, buf)
3691 ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
3692 ieee_data_type *ieee;
3694 if (abfd->my_archive != NULL)
3695 ar = abfd->my_archive->tdata.ieee_ar_data;
3696 if (ar == (ieee_ar_data_type *) NULL)
3698 bfd_set_error (bfd_error_invalid_operation);
3702 if (IEEE_DATA (abfd) == NULL)
3704 if (ieee_object_p (abfd) == NULL)
3706 bfd_set_error (bfd_error_wrong_format);
3711 ieee = IEEE_DATA (abfd);
3713 buf->st_size = ieee->w.r.me_record + 1;
3714 buf->st_mode = 0644;
3719 ieee_sizeof_headers (abfd, x)
3720 bfd *abfd ATTRIBUTE_UNUSED;
3721 bfd_boolean x ATTRIBUTE_UNUSED;
3726 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3727 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3729 #define ieee_slurp_armap bfd_true
3730 #define ieee_slurp_extended_name_table bfd_true
3731 #define ieee_construct_extended_name_table \
3733 PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
3735 #define ieee_truncate_arname bfd_dont_truncate_arname
3736 #define ieee_write_armap \
3738 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3740 #define ieee_read_ar_hdr bfd_nullvoidptr
3741 #define ieee_update_armap_timestamp bfd_true
3742 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3744 #define ieee_bfd_is_target_special_symbol \
3745 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
3746 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3747 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3748 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3749 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3750 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3752 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3754 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3756 #define ieee_get_section_contents_in_window \
3757 _bfd_generic_get_section_contents_in_window
3758 #define ieee_bfd_get_relocated_section_contents \
3759 bfd_generic_get_relocated_section_contents
3760 #define ieee_bfd_relax_section bfd_generic_relax_section
3761 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3762 #define ieee_bfd_merge_sections bfd_generic_merge_sections
3763 #define ieee_bfd_is_group_section bfd_generic_is_group_section
3764 #define ieee_bfd_discard_group bfd_generic_discard_group
3765 #define ieee_section_already_linked \
3766 _bfd_generic_section_already_linked
3767 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3768 #define ieee_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
3769 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3770 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
3771 #define ieee_bfd_final_link _bfd_generic_final_link
3772 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3774 const bfd_target ieee_vec =
3777 bfd_target_ieee_flavour,
3778 BFD_ENDIAN_UNKNOWN, /* target byte order */
3779 BFD_ENDIAN_UNKNOWN, /* target headers byte order */
3780 (HAS_RELOC | EXEC_P | /* object flags */
3781 HAS_LINENO | HAS_DEBUG |
3782 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3783 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3784 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3785 '_', /* leading underscore */
3786 ' ', /* ar_pad_char */
3787 16, /* ar_max_namelen */
3788 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3789 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3790 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3791 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3792 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3793 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3796 ieee_object_p, /* bfd_check_format */
3803 _bfd_generic_mkarchive,
3808 ieee_write_object_contents,
3809 _bfd_write_archive_contents,
3813 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
3814 ieee_get_section_contents, ieee_get_section_contents_in_window. */
3815 BFD_JUMP_TABLE_GENERIC (ieee),
3817 BFD_JUMP_TABLE_COPY (_bfd_generic),
3818 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3820 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
3821 ieee_construct_extended_name_table, ieee_truncate_arname,
3822 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
3823 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
3824 ieee_update_armap_timestamp. */
3825 BFD_JUMP_TABLE_ARCHIVE (ieee),
3827 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
3828 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
3829 ieee_bfd_is_local_label_name, ieee_get_lineno,
3830 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
3831 ieee_read_minisymbols, ieee_minisymbol_to_symbol. */
3832 BFD_JUMP_TABLE_SYMBOLS (ieee),
3834 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
3835 ieee_bfd_reloc_type_lookup. */
3836 BFD_JUMP_TABLE_RELOCS (ieee),
3838 /* ieee_set_arch_mach, ieee_set_section_contents. */
3839 BFD_JUMP_TABLE_WRITE (ieee),
3841 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
3842 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
3843 _bfd_generic_link_hash_table_free,
3844 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
3845 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
3846 ieee_bfd_merge_sections. */
3847 BFD_JUMP_TABLE_LINK (ieee),
3849 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),