1 /* BFD back-end for ieee-695 objects.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
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 static bfd_boolean ieee_write_byte
44 PARAMS ((bfd *, int));
45 static bfd_boolean ieee_write_2bytes
46 PARAMS ((bfd *, int));
47 static bfd_boolean ieee_write_int
48 PARAMS ((bfd *, bfd_vma));
49 static bfd_boolean ieee_write_id
50 PARAMS ((bfd *, const char *));
51 static unsigned short read_2bytes
52 PARAMS ((common_header_type *));
53 static void bfd_get_string
54 PARAMS ((common_header_type *, char *, size_t));
56 PARAMS ((common_header_type *));
57 static bfd_boolean ieee_write_expression
58 PARAMS ((bfd *, bfd_vma, asymbol *, bfd_boolean, unsigned int));
59 static void ieee_write_int5
60 PARAMS ((bfd_byte *, bfd_vma));
61 static bfd_boolean ieee_write_int5_out
62 PARAMS ((bfd *, bfd_vma));
63 static bfd_boolean parse_int
64 PARAMS ((common_header_type *, bfd_vma *));
66 PARAMS ((common_header_type *, bfd_boolean *));
67 static bfd_vma must_parse_int
68 PARAMS ((common_header_type *));
69 static void parse_expression
70 PARAMS ((ieee_data_type *, bfd_vma *, ieee_symbol_index_type *,
71 bfd_boolean *, unsigned int *, asection **));
72 static file_ptr ieee_part_after
73 PARAMS ((ieee_data_type *, file_ptr));
74 static ieee_symbol_type *get_symbol
75 PARAMS ((bfd *, ieee_data_type *, ieee_symbol_type *, unsigned int *,
76 ieee_symbol_type ***, unsigned int *, int));
77 static bfd_boolean ieee_slurp_external_symbols
79 static bfd_boolean ieee_slurp_symbol_table
81 static long ieee_get_symtab_upper_bound
83 static long ieee_get_symtab
84 PARAMS ((bfd *, asymbol **));
85 static asection *get_section_entry
86 PARAMS ((bfd *, ieee_data_type *i, unsigned int));
87 static void ieee_slurp_sections
89 static bfd_boolean ieee_slurp_debug
91 const bfd_target *ieee_archive_p
93 const bfd_target *ieee_object_p
95 static void ieee_get_symbol_info
96 PARAMS ((bfd *, asymbol *, symbol_info *));
97 static void ieee_print_symbol
98 PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
99 static bfd_boolean do_one
100 PARAMS ((ieee_data_type *, ieee_per_section_type *, unsigned char *,
102 static bfd_boolean ieee_slurp_section_data
104 static bfd_boolean ieee_new_section_hook
105 PARAMS ((bfd *, asection *));
106 static long ieee_get_reloc_upper_bound
107 PARAMS ((bfd *, sec_ptr));
108 static bfd_boolean ieee_get_section_contents
109 PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
110 static long ieee_canonicalize_reloc
111 PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
113 PARAMS ((const PTR, const PTR));
114 static bfd_boolean ieee_write_section_part
116 static bfd_boolean do_with_relocs
117 PARAMS ((bfd *, asection *));
118 static bfd_boolean do_as_repeat
119 PARAMS ((bfd *, asection *));
120 static bfd_boolean do_without_relocs
121 PARAMS ((bfd *, asection *));
122 static bfd_boolean ieee_mkobject
128 static void write_int
132 static void copy_expression
135 PARAMS ((struct output_buffer_struct *));
137 PARAMS ((struct output_buffer_struct *));
140 static void f1_record
142 static void f0_record
144 static void copy_till_end
146 static void f2_record
148 static void f8_record
150 static void e2_record
154 static void relocate_debug
155 PARAMS ((bfd *, bfd *));
156 static bfd_boolean ieee_write_debug_part
158 static bfd_boolean ieee_write_data_part
160 static bfd_boolean init_for_output
162 static bfd_boolean ieee_set_section_contents
163 PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
164 static bfd_boolean ieee_write_external_part
166 static bfd_boolean ieee_write_me_part
168 static bfd_boolean ieee_write_processor
170 static bfd_boolean ieee_write_object_contents
172 static asymbol *ieee_make_empty_symbol
174 static bfd *ieee_openr_next_archived_file
175 PARAMS ((bfd *, bfd *));
176 static bfd_boolean ieee_find_nearest_line
177 PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
178 const char **, unsigned int *));
179 static int ieee_generic_stat_arch_elt
180 PARAMS ((bfd *, struct stat *));
181 static int ieee_sizeof_headers
182 PARAMS ((bfd *, bfd_boolean));
184 /* Functions for writing to ieee files in the strange way that the
185 standard requires. */
188 ieee_write_byte (abfd, barg)
195 if (bfd_bwrite ((PTR) &byte, (bfd_size_type) 1, abfd) != 1)
201 ieee_write_2bytes (abfd, bytes)
207 buffer[0] = bytes >> 8;
208 buffer[1] = bytes & 0xff;
209 if (bfd_bwrite ((PTR) buffer, (bfd_size_type) 2, abfd) != 2)
215 ieee_write_int (abfd, value)
221 if (! ieee_write_byte (abfd, (bfd_byte) value))
228 /* How many significant bytes ? */
229 /* FIXME FOR LONGER INTS */
230 if (value & 0xff000000)
232 else if (value & 0x00ff0000)
234 else if (value & 0x0000ff00)
239 if (! ieee_write_byte (abfd,
240 (bfd_byte) ((int) ieee_number_repeat_start_enum
246 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))
250 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))
254 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))
258 if (! ieee_write_byte (abfd, (bfd_byte) (value)))
267 ieee_write_id (abfd, id)
271 size_t length = strlen (id);
275 if (! ieee_write_byte (abfd, (bfd_byte) length))
278 else if (length < 255)
280 if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)
281 || ! ieee_write_byte (abfd, (bfd_byte) length))
284 else if (length < 65535)
286 if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)
287 || ! ieee_write_2bytes (abfd, (int) length))
292 (*_bfd_error_handler)
293 (_("%s: string too long (%d chars, max 65535)"),
294 bfd_get_filename (abfd), length);
295 bfd_set_error (bfd_error_invalid_operation);
299 if (bfd_bwrite ((PTR) id, (bfd_size_type) length, abfd) != length)
304 /***************************************************************************
305 Functions for reading from ieee files in the strange way that the
309 #define this_byte(ieee) *((ieee)->input_p)
310 #define next_byte(ieee) ((ieee)->input_p++)
311 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
313 static unsigned short
315 common_header_type *ieee;
317 unsigned char c1 = this_byte_and_next (ieee);
318 unsigned char c2 = this_byte_and_next (ieee);
319 return (c1 << 8) | c2;
323 bfd_get_string (ieee, string, length)
324 common_header_type *ieee;
329 for (i = 0; i < length; i++)
331 string[i] = this_byte_and_next (ieee);
337 common_header_type *ieee;
341 length = this_byte_and_next (ieee);
344 /* Simple string of length 0 to 127 */
346 else if (length == 0xde)
348 /* Length is next byte, allowing 0..255 */
349 length = this_byte_and_next (ieee);
351 else if (length == 0xdf)
353 /* Length is next two bytes, allowing 0..65535 */
354 length = this_byte_and_next (ieee);
355 length = (length * 256) + this_byte_and_next (ieee);
357 /* Buy memory and read string */
358 string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
361 bfd_get_string (ieee, string, length);
367 ieee_write_expression (abfd, value, symbol, pcrel, index)
374 unsigned int term_count = 0;
378 if (! ieee_write_int (abfd, value))
383 if (bfd_is_com_section (symbol->section)
384 || bfd_is_und_section (symbol->section))
386 /* Def of a common symbol */
387 if (! ieee_write_byte (abfd, ieee_variable_X_enum)
388 || ! ieee_write_int (abfd, symbol->value))
392 else if (! bfd_is_abs_section (symbol->section))
394 /* Ref to defined symbol - */
396 if (symbol->flags & BSF_GLOBAL)
398 if (! ieee_write_byte (abfd, ieee_variable_I_enum)
399 || ! ieee_write_int (abfd, symbol->value))
403 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
405 /* This is a reference to a defined local symbol. We can
406 easily do a local as a section+offset. */
407 if (! ieee_write_byte (abfd, ieee_variable_R_enum)
408 || ! ieee_write_byte (abfd,
409 (bfd_byte) (symbol->section->index
410 + IEEE_SECTION_NUMBER_BASE)))
413 if (symbol->value != 0)
415 if (! ieee_write_int (abfd, symbol->value))
422 (*_bfd_error_handler)
423 (_("%s: unrecognized symbol `%s' flags 0x%x"),
424 bfd_get_filename (abfd), bfd_asymbol_name (symbol),
426 bfd_set_error (bfd_error_invalid_operation);
433 /* subtract the pc from here by asking for PC of this section*/
434 if (! ieee_write_byte (abfd, ieee_variable_P_enum)
435 || ! ieee_write_byte (abfd,
436 (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE))
437 || ! ieee_write_byte (abfd, ieee_function_minus_enum))
441 /* Handle the degenerate case of a 0 address. */
444 if (! ieee_write_int (abfd, (bfd_vma) 0))
448 while (term_count > 1)
450 if (! ieee_write_byte (abfd, ieee_function_plus_enum))
458 /*****************************************************************************/
461 writes any integer into the buffer supplied and always takes 5 bytes
464 ieee_write_int5 (buffer, value)
468 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
469 buffer[1] = (value >> 24) & 0xff;
470 buffer[2] = (value >> 16) & 0xff;
471 buffer[3] = (value >> 8) & 0xff;
472 buffer[4] = (value >> 0) & 0xff;
476 ieee_write_int5_out (abfd, value)
482 ieee_write_int5 (b, value);
483 if (bfd_bwrite ((PTR) b, (bfd_size_type) 5, abfd) != 5)
489 parse_int (ieee, value_ptr)
490 common_header_type *ieee;
493 int value = this_byte (ieee);
495 if (value >= 0 && value <= 127)
501 else if (value >= 0x80 && value <= 0x88)
503 unsigned int count = value & 0xf;
508 result = (result << 8) | this_byte_and_next (ieee);
519 common_header_type *ieee;
523 *ok = parse_int (ieee, &x);
528 must_parse_int (ieee)
529 common_header_type *ieee;
532 BFD_ASSERT (parse_int (ieee, &result));
540 ieee_symbol_index_type symbol;
544 #if KEEPMINUSPCININST
546 #define SRC_MASK(arg) arg
547 #define PCREL_OFFSET FALSE
551 #define SRC_MASK(arg) 0
552 #define PCREL_OFFSET TRUE
556 static reloc_howto_type abs32_howto =
563 complain_overflow_bitfield,
571 static reloc_howto_type abs16_howto =
578 complain_overflow_bitfield,
586 static reloc_howto_type abs8_howto =
593 complain_overflow_bitfield,
601 static reloc_howto_type rel32_howto =
608 complain_overflow_signed,
612 SRC_MASK (0xffffffff),
616 static reloc_howto_type rel16_howto =
623 complain_overflow_signed,
627 SRC_MASK (0x0000ffff),
631 static reloc_howto_type rel8_howto =
638 complain_overflow_signed,
642 SRC_MASK (0x000000ff),
646 static ieee_symbol_index_type NOSYMBOL = {0, 0};
649 parse_expression (ieee, value, symbol, pcrel, extra, section)
650 ieee_data_type *ieee;
652 ieee_symbol_index_type *symbol;
664 bfd_boolean loop = TRUE;
665 ieee_value_type stack[10];
667 /* The stack pointer always points to the next unused location */
668 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
669 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
670 ieee_value_type *sp = stack;
673 while (loop && ieee->h.input_p < ieee->h.last_byte)
675 switch (this_byte (&(ieee->h)))
677 case ieee_variable_P_enum:
678 /* P variable, current program counter for section n */
681 next_byte (&(ieee->h));
683 section_n = must_parse_int (&(ieee->h));
684 PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
687 case ieee_variable_L_enum:
688 /* L variable address of section N */
689 next_byte (&(ieee->h));
690 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
692 case ieee_variable_R_enum:
693 /* R variable, logical address of section module */
694 /* FIXME, this should be different to L */
695 next_byte (&(ieee->h));
696 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
698 case ieee_variable_S_enum:
699 /* S variable, size in MAUS of section module */
700 next_byte (&(ieee->h));
703 ieee->section_table[must_parse_int (&(ieee->h))]->_raw_size);
705 case ieee_variable_I_enum:
706 /* Push the address of variable n */
708 ieee_symbol_index_type sy;
709 next_byte (&(ieee->h));
710 sy.index = (int) must_parse_int (&(ieee->h));
713 PUSH (sy, bfd_abs_section_ptr, 0);
716 case ieee_variable_X_enum:
717 /* Push the address of external variable n */
719 ieee_symbol_index_type sy;
720 next_byte (&(ieee->h));
721 sy.index = (int) (must_parse_int (&(ieee->h)));
724 PUSH (sy, bfd_und_section_ptr, 0);
727 case ieee_function_minus_enum:
729 bfd_vma value1, value2;
730 asection *section1, *section_dummy;
731 ieee_symbol_index_type sy;
732 next_byte (&(ieee->h));
734 POP (sy, section1, value1);
735 POP (sy, section_dummy, value2);
736 PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
739 case ieee_function_plus_enum:
741 bfd_vma value1, value2;
744 ieee_symbol_index_type sy1;
745 ieee_symbol_index_type sy2;
746 next_byte (&(ieee->h));
748 POP (sy1, section1, value1);
749 POP (sy2, section2, value2);
750 PUSH (sy1.letter ? sy1 : sy2,
751 bfd_is_abs_section (section1) ? section2 : section1,
758 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
759 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
760 if (parse_int (&(ieee->h), &va))
762 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
766 /* Thats all that we can understand. */
773 /* As far as I can see there is a bug in the Microtec IEEE output
774 which I'm using to scan, whereby the comma operator is omitted
775 sometimes in an expression, giving expressions with too many
776 terms. We can tell if that's the case by ensuring that
777 sp == stack here. If not, then we've pushed something too far,
778 so we keep adding. */
780 while (sp != stack + 1)
783 ieee_symbol_index_type sy1;
784 POP (sy1, section1, *extra);
787 POP (*symbol, dummy, *value);
793 #define ieee_seek(ieee, offset) \
796 ieee->h.input_p = ieee->h.first_byte + offset; \
797 ieee->h.last_byte = (ieee->h.first_byte \
798 + ieee_part_after (ieee, offset)); \
802 #define ieee_pos(ieee) \
803 (ieee->h.input_p - ieee->h.first_byte)
805 /* Find the first part of the ieee file after HERE. */
808 ieee_part_after (ieee, here)
809 ieee_data_type *ieee;
813 file_ptr after = ieee->w.r.me_record;
815 /* File parts can come in any order, except that module end is
816 guaranteed to be last (and the header first). */
817 for (part = 0; part < N_W_VARIABLES; part++)
818 if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
819 after = ieee->w.offset[part];
824 static unsigned int last_index;
825 static char last_type; /* is the index for an X or a D */
827 static ieee_symbol_type *
828 get_symbol (abfd, ieee, last_symbol, symbol_count, pptr, max_index, this_type)
829 bfd *abfd ATTRIBUTE_UNUSED;
830 ieee_data_type *ieee;
831 ieee_symbol_type *last_symbol;
832 unsigned int *symbol_count;
833 ieee_symbol_type ***pptr;
834 unsigned int *max_index;
837 /* Need a new symbol */
838 unsigned int new_index = must_parse_int (&(ieee->h));
839 if (new_index != last_index || this_type != last_type)
841 ieee_symbol_type *new_symbol;
842 bfd_size_type amt = sizeof (ieee_symbol_type);
844 new_symbol = (ieee_symbol_type *) bfd_alloc (ieee->h.abfd, amt);
848 new_symbol->index = new_index;
849 last_index = new_index;
852 *pptr = &new_symbol->next;
853 if (new_index > *max_index)
855 *max_index = new_index;
857 last_type = this_type;
858 new_symbol->symbol.section = bfd_abs_section_ptr;
865 ieee_slurp_external_symbols (abfd)
868 ieee_data_type *ieee = IEEE_DATA (abfd);
869 file_ptr offset = ieee->w.r.external_part;
871 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
872 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
873 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
874 unsigned int symbol_count = 0;
875 bfd_boolean loop = TRUE;
876 last_index = 0xffffff;
877 ieee->symbol_table_full = TRUE;
879 ieee_seek (ieee, offset);
883 switch (this_byte (&(ieee->h)))
886 next_byte (&(ieee->h));
888 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
890 &ieee->external_symbol_max_index, 'I');
894 symbol->symbol.the_bfd = abfd;
895 symbol->symbol.name = read_id (&(ieee->h));
896 symbol->symbol.udata.p = (PTR) NULL;
897 symbol->symbol.flags = BSF_NO_FLAGS;
899 case ieee_external_symbol_enum:
900 next_byte (&(ieee->h));
902 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
904 &ieee->external_symbol_max_index, 'D');
908 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
910 symbol->symbol.the_bfd = abfd;
911 symbol->symbol.name = read_id (&(ieee->h));
912 symbol->symbol.udata.p = (PTR) NULL;
913 symbol->symbol.flags = BSF_NO_FLAGS;
915 case ieee_attribute_record_enum >> 8:
917 unsigned int symbol_name_index;
918 unsigned int symbol_type_index;
919 unsigned int symbol_attribute_def;
921 switch (read_2bytes (&ieee->h))
923 case ieee_attribute_record_enum:
924 symbol_name_index = must_parse_int (&(ieee->h));
925 symbol_type_index = must_parse_int (&(ieee->h));
926 symbol_attribute_def = must_parse_int (&(ieee->h));
927 switch (symbol_attribute_def)
931 parse_int (&ieee->h, &value);
934 (*_bfd_error_handler)
935 (_("%s: unimplemented ATI record %u for symbol %u"),
936 bfd_archive_filename (abfd), symbol_attribute_def,
938 bfd_set_error (bfd_error_bad_value);
943 case ieee_external_reference_info_record_enum:
944 /* Skip over ATX record. */
945 parse_int (&(ieee->h), &value);
946 parse_int (&(ieee->h), &value);
947 parse_int (&(ieee->h), &value);
948 parse_int (&(ieee->h), &value);
950 case ieee_atn_record_enum:
951 /* We may get call optimization information here,
952 which we just ignore. The format is
953 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs} */
954 parse_int (&ieee->h, &value);
955 parse_int (&ieee->h, &value);
956 parse_int (&ieee->h, &value);
959 (*_bfd_error_handler)
960 (_("%s: unexpected ATN type %d in external part"),
961 bfd_archive_filename (abfd), (int) value);
962 bfd_set_error (bfd_error_bad_value);
965 parse_int (&ieee->h, &value);
966 parse_int (&ieee->h, &value);
973 switch (read_2bytes (&ieee->h))
975 case ieee_asn_record_enum:
976 parse_int (&ieee->h, &val1);
977 parse_int (&ieee->h, &val1);
981 (*_bfd_error_handler)
982 (_("%s: unexpected type after ATN"),
983 bfd_archive_filename (abfd));
984 bfd_set_error (bfd_error_bad_value);
991 case ieee_value_record_enum >> 8:
993 unsigned int symbol_name_index;
994 ieee_symbol_index_type symbol_ignore;
995 bfd_boolean pcrel_ignore;
997 next_byte (&(ieee->h));
998 next_byte (&(ieee->h));
1000 symbol_name_index = must_parse_int (&(ieee->h));
1001 parse_expression (ieee,
1002 &symbol->symbol.value,
1006 &symbol->symbol.section);
1008 /* Fully linked IEEE-695 files tend to give every symbol
1009 an absolute value. Try to convert that back into a
1010 section relative value. FIXME: This won't always to
1012 if (bfd_is_abs_section (symbol->symbol.section)
1013 && (abfd->flags & HAS_RELOC) == 0)
1018 val = symbol->symbol.value;
1019 for (s = abfd->sections; s != NULL; s = s->next)
1021 if (val >= s->vma && val < s->vma + s->_raw_size)
1023 symbol->symbol.section = s;
1024 symbol->symbol.value -= s->vma;
1030 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
1034 case ieee_weak_external_reference_enum:
1038 next_byte (&(ieee->h));
1039 /* Throw away the external reference index */
1040 (void) must_parse_int (&(ieee->h));
1041 /* Fetch the default size if not resolved */
1042 size = must_parse_int (&(ieee->h));
1043 /* Fetch the defautlt value if available */
1044 if (! parse_int (&(ieee->h), &value))
1048 /* This turns into a common */
1049 symbol->symbol.section = bfd_com_section_ptr;
1050 symbol->symbol.value = size;
1054 case ieee_external_reference_enum:
1055 next_byte (&(ieee->h));
1057 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
1058 &prev_reference_ptr,
1059 &ieee->external_reference_max_index, 'X');
1063 symbol->symbol.the_bfd = abfd;
1064 symbol->symbol.name = read_id (&(ieee->h));
1065 symbol->symbol.udata.p = (PTR) NULL;
1066 symbol->symbol.section = bfd_und_section_ptr;
1067 symbol->symbol.value = (bfd_vma) 0;
1068 symbol->symbol.flags = 0;
1070 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
1078 if (ieee->external_symbol_max_index != 0)
1080 ieee->external_symbol_count =
1081 ieee->external_symbol_max_index -
1082 ieee->external_symbol_min_index + 1;
1086 ieee->external_symbol_count = 0;
1089 if (ieee->external_reference_max_index != 0)
1091 ieee->external_reference_count =
1092 ieee->external_reference_max_index -
1093 ieee->external_reference_min_index + 1;
1097 ieee->external_reference_count = 0;
1101 ieee->external_reference_count + ieee->external_symbol_count;
1103 if (symbol_count != abfd->symcount)
1105 /* There are gaps in the table -- */
1106 ieee->symbol_table_full = FALSE;
1109 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
1110 *prev_reference_ptr = (ieee_symbol_type *) NULL;
1116 ieee_slurp_symbol_table (abfd)
1119 if (! IEEE_DATA (abfd)->read_symbols)
1121 if (! ieee_slurp_external_symbols (abfd))
1123 IEEE_DATA (abfd)->read_symbols = TRUE;
1129 ieee_get_symtab_upper_bound (abfd)
1132 if (! ieee_slurp_symbol_table (abfd))
1135 return (abfd->symcount != 0) ?
1136 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
1140 Move from our internal lists to the canon table, and insert in
1144 extern const bfd_target ieee_vec;
1147 ieee_get_symtab (abfd, location)
1151 ieee_symbol_type *symp;
1152 static bfd dummy_bfd;
1153 static asymbol empty_symbol =
1161 /* K&R compilers can't initialise unions. */
1168 ieee_data_type *ieee = IEEE_DATA (abfd);
1169 dummy_bfd.xvec = &ieee_vec;
1170 if (! ieee_slurp_symbol_table (abfd))
1173 if (! ieee->symbol_table_full)
1175 /* Arrgh - there are gaps in the table, run through and fill them */
1176 /* up with pointers to a null place */
1178 for (i = 0; i < abfd->symcount; i++)
1180 location[i] = &empty_symbol;
1184 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
1185 for (symp = IEEE_DATA (abfd)->external_symbols;
1186 symp != (ieee_symbol_type *) NULL;
1189 /* Place into table at correct index locations */
1190 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
1193 /* The external refs are indexed in a bit */
1194 ieee->external_reference_base_offset =
1195 -ieee->external_reference_min_index + ieee->external_symbol_count;
1197 for (symp = IEEE_DATA (abfd)->external_reference;
1198 symp != (ieee_symbol_type *) NULL;
1201 location[symp->index + ieee->external_reference_base_offset] =
1208 location[abfd->symcount] = (asymbol *) NULL;
1210 return abfd->symcount;
1214 get_section_entry (abfd, ieee, index)
1216 ieee_data_type *ieee;
1219 if (index >= ieee->section_table_size)
1225 c = ieee->section_table_size;
1232 amt *= sizeof (asection *);
1233 n = (asection **) bfd_realloc (ieee->section_table, amt);
1237 for (i = ieee->section_table_size; i < c; i++)
1240 ieee->section_table = n;
1241 ieee->section_table_size = c;
1244 if (ieee->section_table[index] == (asection *) NULL)
1246 char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
1251 sprintf (tmp, " fsec%4d", index);
1252 section = bfd_make_section (abfd, tmp);
1253 ieee->section_table[index] = section;
1254 section->flags = SEC_NO_FLAGS;
1255 section->target_index = index;
1256 ieee->section_table[index] = section;
1258 return ieee->section_table[index];
1262 ieee_slurp_sections (abfd)
1265 ieee_data_type *ieee = IEEE_DATA (abfd);
1266 file_ptr offset = ieee->w.r.section_part;
1271 bfd_byte section_type[3];
1272 ieee_seek (ieee, offset);
1275 switch (this_byte (&(ieee->h)))
1277 case ieee_section_type_enum:
1280 unsigned int section_index;
1281 next_byte (&(ieee->h));
1282 section_index = must_parse_int (&(ieee->h));
1284 section = get_section_entry (abfd, ieee, section_index);
1286 section_type[0] = this_byte_and_next (&(ieee->h));
1288 /* Set minimal section attributes. Attributes are
1289 extended later, based on section contents. */
1291 switch (section_type[0])
1294 /* Normal attributes for absolute sections */
1295 section_type[1] = this_byte (&(ieee->h));
1296 section->flags = SEC_ALLOC;
1297 switch (section_type[1])
1299 case 0xD3: /* AS Absolute section attributes */
1300 next_byte (&(ieee->h));
1301 section_type[2] = this_byte (&(ieee->h));
1302 switch (section_type[2])
1306 next_byte (&(ieee->h));
1307 section->flags |= SEC_CODE;
1311 next_byte (&(ieee->h));
1312 section->flags |= SEC_DATA;
1315 next_byte (&(ieee->h));
1316 /* Normal rom data */
1317 section->flags |= SEC_ROM | SEC_DATA;
1324 case 0xC3: /* Named relocatable sections (type C) */
1325 section_type[1] = this_byte (&(ieee->h));
1326 section->flags = SEC_ALLOC;
1327 switch (section_type[1])
1329 case 0xD0: /* Normal code (CP) */
1330 next_byte (&(ieee->h));
1331 section->flags |= SEC_CODE;
1333 case 0xC4: /* Normal data (CD) */
1334 next_byte (&(ieee->h));
1335 section->flags |= SEC_DATA;
1337 case 0xD2: /* Normal rom data (CR) */
1338 next_byte (&(ieee->h));
1339 section->flags |= SEC_ROM | SEC_DATA;
1346 /* Read section name, use it if non empty. */
1347 name = read_id (&ieee->h);
1349 section->name = name;
1351 /* Skip these fields, which we don't care about */
1353 bfd_vma parent, brother, context;
1354 parse_int (&(ieee->h), &parent);
1355 parse_int (&(ieee->h), &brother);
1356 parse_int (&(ieee->h), &context);
1360 case ieee_section_alignment_enum:
1362 unsigned int section_index;
1365 next_byte (&(ieee->h));
1366 section_index = must_parse_int (&ieee->h);
1367 section = get_section_entry (abfd, ieee, section_index);
1368 if (section_index > ieee->section_count)
1370 ieee->section_count = section_index;
1372 section->alignment_power =
1373 bfd_log2 (must_parse_int (&ieee->h));
1374 (void) parse_int (&(ieee->h), &value);
1377 case ieee_e2_first_byte_enum:
1380 ieee_record_enum_type t;
1382 t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1385 case ieee_section_size_enum:
1386 section = ieee->section_table[must_parse_int (&(ieee->h))];
1387 section->_raw_size = must_parse_int (&(ieee->h));
1389 case ieee_physical_region_size_enum:
1390 section = ieee->section_table[must_parse_int (&(ieee->h))];
1391 section->_raw_size = must_parse_int (&(ieee->h));
1393 case ieee_region_base_address_enum:
1394 section = ieee->section_table[must_parse_int (&(ieee->h))];
1395 section->vma = must_parse_int (&(ieee->h));
1396 section->lma = section->vma;
1398 case ieee_mau_size_enum:
1399 must_parse_int (&(ieee->h));
1400 must_parse_int (&(ieee->h));
1402 case ieee_m_value_enum:
1403 must_parse_int (&(ieee->h));
1404 must_parse_int (&(ieee->h));
1406 case ieee_section_base_address_enum:
1407 section = ieee->section_table[must_parse_int (&(ieee->h))];
1408 section->vma = must_parse_int (&(ieee->h));
1409 section->lma = section->vma;
1411 case ieee_section_offset_enum:
1412 (void) must_parse_int (&(ieee->h));
1413 (void) must_parse_int (&(ieee->h));
1427 /* Make a section for the debugging information, if any. We don't try
1428 to interpret the debugging information; we just point the section
1429 at the area in the file so that program which understand can dig it
1433 ieee_slurp_debug (abfd)
1436 ieee_data_type *ieee = IEEE_DATA (abfd);
1440 if (ieee->w.r.debug_information_part == 0)
1443 sec = bfd_make_section (abfd, ".debug");
1446 sec->flags |= SEC_DEBUGGING | SEC_HAS_CONTENTS;
1447 sec->filepos = ieee->w.r.debug_information_part;
1449 debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
1450 sec->_raw_size = debug_end - ieee->w.r.debug_information_part;
1455 /***********************************************************************
1460 ieee_archive_p (abfd)
1465 unsigned char buffer[512];
1466 file_ptr buffer_offset = 0;
1467 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1468 ieee_ar_data_type *ieee;
1469 bfd_size_type alc_elts;
1470 ieee_ar_obstack_type *elts = NULL;
1471 bfd_size_type amt = sizeof (ieee_ar_data_type);
1473 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, amt);
1474 if (!abfd->tdata.ieee_ar_data)
1475 goto error_ret_restore;
1476 ieee = IEEE_AR_DATA (abfd);
1478 /* Ignore the return value here. It doesn't matter if we don't read
1479 the entire buffer. We might have a very small ieee file. */
1480 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
1482 ieee->h.first_byte = buffer;
1483 ieee->h.input_p = buffer;
1485 ieee->h.abfd = abfd;
1487 if (this_byte (&(ieee->h)) != Module_Beginning)
1488 goto got_wrong_format_error;
1490 next_byte (&(ieee->h));
1491 library = read_id (&(ieee->h));
1492 if (strcmp (library, "LIBRARY") != 0)
1493 goto got_wrong_format_error;
1495 /* Throw away the filename. */
1496 read_id (&(ieee->h));
1498 ieee->element_count = 0;
1499 ieee->element_index = 0;
1501 next_byte (&(ieee->h)); /* Drop the ad part. */
1502 must_parse_int (&(ieee->h)); /* And the two dummy numbers. */
1503 must_parse_int (&(ieee->h));
1506 elts = (ieee_ar_obstack_type *) bfd_malloc (alc_elts * sizeof *elts);
1510 /* Read the index of the BB table. */
1514 ieee_ar_obstack_type *t;
1516 rec = read_2bytes (&(ieee->h));
1517 if (rec != (int) ieee_assign_value_to_variable_enum)
1520 if (ieee->element_count >= alc_elts)
1522 ieee_ar_obstack_type *n;
1525 n = ((ieee_ar_obstack_type *)
1526 bfd_realloc (elts, alc_elts * sizeof *elts));
1532 t = &elts[ieee->element_count];
1533 ieee->element_count++;
1535 must_parse_int (&(ieee->h));
1536 t->file_offset = must_parse_int (&(ieee->h));
1537 t->abfd = (bfd *) NULL;
1539 /* Make sure that we don't go over the end of the buffer. */
1540 if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
1542 /* Past half way, reseek and reprime. */
1543 buffer_offset += ieee_pos (IEEE_DATA (abfd));
1544 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1547 /* Again ignore return value of bfd_bread. */
1548 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
1549 ieee->h.first_byte = buffer;
1550 ieee->h.input_p = buffer;
1554 amt = ieee->element_count;
1555 amt *= sizeof *ieee->elements;
1556 ieee->elements = (ieee_ar_obstack_type *) bfd_alloc (abfd, amt);
1557 if (ieee->elements == NULL)
1560 memcpy (ieee->elements, elts, (size_t) amt);
1564 /* Now scan the area again, and replace BB offsets with file offsets. */
1565 for (i = 2; i < ieee->element_count; i++)
1567 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1570 /* Again ignore return value of bfd_bread. */
1571 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
1572 ieee->h.first_byte = buffer;
1573 ieee->h.input_p = buffer;
1575 next_byte (&(ieee->h)); /* Drop F8. */
1576 next_byte (&(ieee->h)); /* Drop 14. */
1577 must_parse_int (&(ieee->h)); /* Drop size of block. */
1579 if (must_parse_int (&(ieee->h)) != 0)
1580 /* This object has been deleted. */
1581 ieee->elements[i].file_offset = 0;
1583 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1586 /* abfd->has_armap = ;*/
1590 got_wrong_format_error:
1591 bfd_set_error (bfd_error_wrong_format);
1595 bfd_release (abfd, ieee);
1597 abfd->tdata.ieee_ar_data = save;
1603 ieee_object_p (abfd)
1608 ieee_data_type *ieee;
1609 unsigned char buffer[300];
1610 ieee_data_type *save = IEEE_DATA (abfd);
1613 abfd->tdata.ieee_data = 0;
1614 ieee_mkobject (abfd);
1616 ieee = IEEE_DATA (abfd);
1617 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1619 /* Read the first few bytes in to see if it makes sense. Ignore
1620 bfd_bread return value; The file might be very small. */
1621 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
1623 ieee->h.input_p = buffer;
1624 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1625 goto got_wrong_format;
1627 ieee->read_symbols = FALSE;
1628 ieee->read_data = FALSE;
1629 ieee->section_count = 0;
1630 ieee->external_symbol_max_index = 0;
1631 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1632 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1633 ieee->external_reference_max_index = 0;
1634 ieee->h.abfd = abfd;
1635 ieee->section_table = NULL;
1636 ieee->section_table_size = 0;
1638 processor = ieee->mb.processor = read_id (&(ieee->h));
1639 if (strcmp (processor, "LIBRARY") == 0)
1640 goto got_wrong_format;
1641 ieee->mb.module_name = read_id (&(ieee->h));
1642 if (abfd->filename == (const char *) NULL)
1644 abfd->filename = ieee->mb.module_name;
1646 /* Determine the architecture and machine type of the object file.
1649 const bfd_arch_info_type *arch;
1652 /* IEEE does not specify the format of the processor identificaton
1653 string, so the compiler is free to put in it whatever it wants.
1654 We try here to recognize different processors belonging to the
1655 m68k family. Code for other processors can be added here. */
1656 if ((processor[0] == '6') && (processor[1] == '8'))
1658 if (processor[2] == '3') /* 683xx integrated processors */
1660 switch (processor[3])
1662 case '0': /* 68302, 68306, 68307 */
1663 case '2': /* 68322, 68328 */
1664 case '5': /* 68356 */
1665 strcpy (family, "68000"); /* MC68000-based controllers */
1668 case '3': /* 68330, 68331, 68332, 68333,
1669 68334, 68335, 68336, 68338 */
1670 case '6': /* 68360 */
1671 case '7': /* 68376 */
1672 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1676 if (processor[4] == '9') /* 68349 */
1677 strcpy (family, "68030"); /* CPU030 */
1678 else /* 68340, 68341 */
1679 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1682 default: /* Does not exist yet */
1683 strcpy (family, "68332"); /* Guess it will be CPU32 */
1686 else if (TOUPPER (processor[3]) == 'F') /* 68F333 */
1687 strcpy (family, "68332"); /* CPU32 */
1688 else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers */
1689 && ((TOUPPER (processor[2]) == 'E')
1690 || (TOUPPER (processor[2]) == 'H')
1691 || (TOUPPER (processor[2]) == 'L')))
1693 strcpy (family, "68");
1694 strncat (family, processor + 4, 7);
1697 else /* "Regular" processors */
1699 strncpy (family, processor, 9);
1703 else if ((strncmp (processor, "cpu32", 5) == 0) /* CPU32 and CPU32+ */
1704 || (strncmp (processor, "CPU32", 5) == 0))
1705 strcpy (family, "68332");
1708 strncpy (family, processor, 9);
1712 arch = bfd_scan_arch (family);
1714 goto got_wrong_format;
1715 abfd->arch_info = arch;
1718 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1722 next_byte (&(ieee->h));
1724 if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
1728 if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
1733 /* If there is a byte order info, take it */
1734 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum ||
1735 this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
1736 next_byte (&(ieee->h));
1738 for (part = 0; part < N_W_VARIABLES; part++)
1741 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
1745 if (this_byte_and_next (&(ieee->h)) != part)
1750 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
1758 if (ieee->w.r.external_part != 0)
1759 abfd->flags = HAS_SYMS;
1761 /* By now we know that this is a real IEEE file, we're going to read
1762 the whole thing into memory so that we can run up and down it
1763 quickly. We can work out how big the file is from the trailer
1766 amt = ieee->w.r.me_record + 1;
1767 IEEE_DATA (abfd)->h.first_byte =
1768 (unsigned char *) bfd_alloc (ieee->h.abfd, amt);
1769 if (!IEEE_DATA (abfd)->h.first_byte)
1771 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1773 /* FIXME: Check return value. I'm not sure whether it needs to read
1774 the entire buffer or not. */
1775 bfd_bread ((PTR) (IEEE_DATA (abfd)->h.first_byte),
1776 (bfd_size_type) ieee->w.r.me_record + 1, abfd);
1778 ieee_slurp_sections (abfd);
1780 if (! ieee_slurp_debug (abfd))
1783 /* Parse section data to activate file and section flags implied by
1784 section contents. */
1786 if (! ieee_slurp_section_data (abfd))
1791 bfd_set_error (bfd_error_wrong_format);
1793 bfd_release (abfd, ieee);
1794 abfd->tdata.ieee_data = save;
1795 return (const bfd_target *) NULL;
1799 ieee_get_symbol_info (ignore_abfd, symbol, ret)
1800 bfd *ignore_abfd ATTRIBUTE_UNUSED;
1804 bfd_symbol_info (symbol, ret);
1805 if (symbol->name[0] == ' ')
1806 ret->name = "* empty table entry ";
1807 if (!symbol->section)
1808 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
1812 ieee_print_symbol (abfd, afile, symbol, how)
1816 bfd_print_symbol_type how;
1818 FILE *file = (FILE *) afile;
1822 case bfd_print_symbol_name:
1823 fprintf (file, "%s", symbol->name);
1825 case bfd_print_symbol_more:
1827 fprintf (file, "%4x %2x", aout_symbol (symbol)->desc & 0xffff,
1828 aout_symbol (symbol)->other & 0xff);
1832 case bfd_print_symbol_all:
1834 const char *section_name =
1835 (symbol->section == (asection *) NULL
1837 : symbol->section->name);
1838 if (symbol->name[0] == ' ')
1840 fprintf (file, "* empty table entry ");
1844 bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
1846 fprintf (file, " %-5s %04x %02x %s",
1848 (unsigned) ieee_symbol (symbol)->index,
1858 do_one (ieee, current_map, location_ptr, s, iterations)
1859 ieee_data_type *ieee;
1860 ieee_per_section_type *current_map;
1861 unsigned char *location_ptr;
1865 switch (this_byte (&(ieee->h)))
1867 case ieee_load_constant_bytes_enum:
1869 unsigned int number_of_maus;
1871 next_byte (&(ieee->h));
1872 number_of_maus = must_parse_int (&(ieee->h));
1874 for (i = 0; i < number_of_maus; i++)
1876 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1877 next_byte (&(ieee->h));
1882 case ieee_load_with_relocation_enum:
1884 bfd_boolean loop = TRUE;
1885 next_byte (&(ieee->h));
1888 switch (this_byte (&(ieee->h)))
1890 case ieee_variable_R_enum:
1892 case ieee_function_signed_open_b_enum:
1893 case ieee_function_unsigned_open_b_enum:
1894 case ieee_function_either_open_b_enum:
1896 unsigned int extra = 4;
1897 bfd_boolean pcrel = FALSE;
1900 bfd_size_type amt = sizeof (ieee_reloc_type);
1902 r = (ieee_reloc_type *) bfd_alloc (ieee->h.abfd, amt);
1906 *(current_map->reloc_tail_ptr) = r;
1907 current_map->reloc_tail_ptr = &r->next;
1908 r->next = (ieee_reloc_type *) NULL;
1909 next_byte (&(ieee->h));
1911 r->relent.sym_ptr_ptr = 0;
1912 parse_expression (ieee,
1915 &pcrel, &extra, §ion);
1916 r->relent.address = current_map->pc;
1917 s->flags |= SEC_RELOC;
1918 s->owner->flags |= HAS_RELOC;
1920 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
1921 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1923 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1925 next_byte (&(ieee->h));
1926 /* Fetch number of bytes to pad */
1927 extra = must_parse_int (&(ieee->h));
1930 switch (this_byte (&(ieee->h)))
1932 case ieee_function_signed_close_b_enum:
1933 next_byte (&(ieee->h));
1935 case ieee_function_unsigned_close_b_enum:
1936 next_byte (&(ieee->h));
1938 case ieee_function_either_close_b_enum:
1939 next_byte (&(ieee->h));
1944 /* Build a relocation entry for this type */
1945 /* If pc rel then stick -ve pc into instruction
1946 and take out of reloc ..
1948 I've changed this. It's all too complicated. I
1949 keep 0 in the instruction now. */
1958 #if KEEPMINUSPCININST
1959 bfd_put_32 (ieee->h.abfd, -current_map->pc,
1960 location_ptr + current_map->pc);
1961 r->relent.howto = &rel32_howto;
1962 r->relent.addend -= current_map->pc;
1964 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
1966 r->relent.howto = &rel32_howto;
1971 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
1972 location_ptr + current_map->pc);
1973 r->relent.howto = &abs32_howto;
1975 current_map->pc += 4;
1980 #if KEEPMINUSPCININST
1981 bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
1982 location_ptr + current_map->pc);
1983 r->relent.addend -= current_map->pc;
1984 r->relent.howto = &rel16_howto;
1987 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1988 location_ptr + current_map->pc);
1989 r->relent.howto = &rel16_howto;
1995 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1996 location_ptr + current_map->pc);
1997 r->relent.howto = &abs16_howto;
1999 current_map->pc += 2;
2004 #if KEEPMINUSPCININST
2005 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
2006 r->relent.addend -= current_map->pc;
2007 r->relent.howto = &rel8_howto;
2009 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
2010 r->relent.howto = &rel8_howto;
2015 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
2016 r->relent.howto = &abs8_howto;
2018 current_map->pc += 1;
2030 if (parse_int (&(ieee->h), &this_size))
2033 for (i = 0; i < this_size; i++)
2035 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
2036 next_byte (&(ieee->h));
2046 /* Prevent more than the first load-item of an LR record
2047 from being repeated (MRI convention). */
2048 if (iterations != 1)
2056 /* Read in all the section data and relocation stuff too */
2058 ieee_slurp_section_data (abfd)
2061 bfd_byte *location_ptr = (bfd_byte *) NULL;
2062 ieee_data_type *ieee = IEEE_DATA (abfd);
2063 unsigned int section_number;
2065 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
2067 /* Seek to the start of the data area */
2068 if (ieee->read_data)
2070 ieee->read_data = TRUE;
2071 ieee_seek (ieee, ieee->w.r.data_part);
2073 /* Allocate enough space for all the section contents */
2075 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2077 ieee_per_section_type *per = ieee_per_section (s);
2078 if ((s->flags & SEC_DEBUGGING) != 0)
2080 per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->_raw_size);
2084 per->reloc_tail_ptr =
2085 (ieee_reloc_type **) & (s->relocation);
2090 switch (this_byte (&(ieee->h)))
2092 /* IF we see anything strange then quit */
2096 case ieee_set_current_section_enum:
2097 next_byte (&(ieee->h));
2098 section_number = must_parse_int (&(ieee->h));
2099 s = ieee->section_table[section_number];
2100 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
2101 current_map = ieee_per_section (s);
2102 location_ptr = current_map->data - s->vma;
2103 /* The document I have says that Microtec's compilers reset */
2104 /* this after a sec section, even though the standard says not */
2106 current_map->pc = s->vma;
2109 case ieee_e2_first_byte_enum:
2110 next_byte (&(ieee->h));
2111 switch (this_byte (&(ieee->h)))
2113 case ieee_set_current_pc_enum & 0xff:
2116 ieee_symbol_index_type symbol;
2119 next_byte (&(ieee->h));
2120 must_parse_int (&(ieee->h)); /* Throw away section #*/
2121 parse_expression (ieee, &value,
2125 current_map->pc = value;
2126 BFD_ASSERT ((unsigned) (value - s->vma) <= s->_raw_size);
2130 case ieee_value_starting_address_enum & 0xff:
2131 next_byte (&(ieee->h));
2132 if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
2133 next_byte (&(ieee->h));
2134 abfd->start_address = must_parse_int (&(ieee->h));
2135 /* We've got to the end of the data now - */
2142 case ieee_repeat_data_enum:
2144 /* Repeat the following LD or LR n times - we do this by
2145 remembering the stream pointer before running it and
2146 resetting it and running it n times. We special case
2147 the repetition of a repeat_data/load_constant
2150 unsigned int iterations;
2151 unsigned char *start;
2152 next_byte (&(ieee->h));
2153 iterations = must_parse_int (&(ieee->h));
2154 start = ieee->h.input_p;
2155 if (start[0] == (int) ieee_load_constant_bytes_enum &&
2158 while (iterations != 0)
2160 location_ptr[current_map->pc++] = start[2];
2163 next_byte (&(ieee->h));
2164 next_byte (&(ieee->h));
2165 next_byte (&(ieee->h));
2169 while (iterations != 0)
2171 ieee->h.input_p = start;
2172 if (!do_one (ieee, current_map, location_ptr, s,
2180 case ieee_load_constant_bytes_enum:
2181 case ieee_load_with_relocation_enum:
2183 if (!do_one (ieee, current_map, location_ptr, s, 1))
2191 ieee_new_section_hook (abfd, newsect)
2195 newsect->used_by_bfd
2196 = (PTR) bfd_alloc (abfd, (bfd_size_type) sizeof (ieee_per_section_type));
2197 if (!newsect->used_by_bfd)
2199 ieee_per_section (newsect)->data = (bfd_byte *) NULL;
2200 ieee_per_section (newsect)->section = newsect;
2205 ieee_get_reloc_upper_bound (abfd, asect)
2209 if ((asect->flags & SEC_DEBUGGING) != 0)
2211 if (! ieee_slurp_section_data (abfd))
2213 return (asect->reloc_count + 1) * sizeof (arelent *);
2217 ieee_get_section_contents (abfd, section, location, offset, count)
2222 bfd_size_type count;
2224 ieee_per_section_type *p = ieee_per_section (section);
2225 if ((section->flags & SEC_DEBUGGING) != 0)
2226 return _bfd_generic_get_section_contents (abfd, section, location,
2228 ieee_slurp_section_data (abfd);
2229 (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
2234 ieee_canonicalize_reloc (abfd, section, relptr, symbols)
2240 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
2241 ieee_data_type *ieee = IEEE_DATA (abfd);
2243 if ((section->flags & SEC_DEBUGGING) != 0)
2246 while (src != (ieee_reloc_type *) NULL)
2248 /* Work out which symbol to attach it this reloc to */
2249 switch (src->symbol.letter)
2252 src->relent.sym_ptr_ptr =
2253 symbols + src->symbol.index + ieee->external_symbol_base_offset;
2256 src->relent.sym_ptr_ptr =
2257 symbols + src->symbol.index + ieee->external_reference_base_offset;
2260 if (src->relent.sym_ptr_ptr != NULL)
2261 src->relent.sym_ptr_ptr =
2262 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
2268 *relptr++ = &src->relent;
2271 *relptr = (arelent *) NULL;
2272 return section->reloc_count;
2280 arelent *a = *((arelent **) ap);
2281 arelent *b = *((arelent **) bp);
2282 return a->address - b->address;
2285 /* Write the section headers. */
2288 ieee_write_section_part (abfd)
2291 ieee_data_type *ieee = IEEE_DATA (abfd);
2293 ieee->w.r.section_part = bfd_tell (abfd);
2294 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2296 if (! bfd_is_abs_section (s)
2297 && (s->flags & SEC_DEBUGGING) == 0)
2299 if (! ieee_write_byte (abfd, ieee_section_type_enum)
2300 || ! ieee_write_byte (abfd,
2301 (bfd_byte) (s->index
2302 + IEEE_SECTION_NUMBER_BASE)))
2305 if (abfd->flags & EXEC_P)
2307 /* This image is executable, so output absolute sections */
2308 if (! ieee_write_byte (abfd, ieee_variable_A_enum)
2309 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
2314 if (! ieee_write_byte (abfd, ieee_variable_C_enum))
2318 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
2320 case SEC_CODE | SEC_LOAD:
2322 if (! ieee_write_byte (abfd, ieee_variable_P_enum))
2327 if (! ieee_write_byte (abfd, ieee_variable_D_enum))
2331 case SEC_ROM | SEC_DATA:
2332 case SEC_ROM | SEC_LOAD:
2333 case SEC_ROM | SEC_DATA | SEC_LOAD:
2334 if (! ieee_write_byte (abfd, ieee_variable_R_enum))
2339 if (! ieee_write_id (abfd, s->name))
2342 ieee_write_int (abfd, 0); /* Parent */
2343 ieee_write_int (abfd, 0); /* Brother */
2344 ieee_write_int (abfd, 0); /* Context */
2347 if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
2348 || ! ieee_write_byte (abfd,
2349 (bfd_byte) (s->index
2350 + IEEE_SECTION_NUMBER_BASE))
2351 || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
2355 if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
2356 || ! ieee_write_byte (abfd,
2357 (bfd_byte) (s->index
2358 + IEEE_SECTION_NUMBER_BASE))
2359 || ! ieee_write_int (abfd, s->_raw_size))
2361 if (abfd->flags & EXEC_P)
2363 /* Relocateable sections don't have asl records */
2365 if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
2366 || ! ieee_write_byte (abfd,
2369 + IEEE_SECTION_NUMBER_BASE)))
2370 || ! ieee_write_int (abfd, s->lma))
2381 do_with_relocs (abfd, s)
2385 unsigned int number_of_maus_in_address =
2386 bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
2387 unsigned int relocs_to_go = s->reloc_count;
2388 bfd_byte *stream = ieee_per_section (s)->data;
2389 arelent **p = s->orelocation;
2390 bfd_size_type current_byte_index = 0;
2392 qsort (s->orelocation,
2394 sizeof (arelent **),
2397 /* Output the section preheader */
2398 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2399 || ! ieee_write_byte (abfd,
2400 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
2401 || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
2402 || ! ieee_write_byte (abfd,
2403 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
2406 if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
2408 if (! ieee_write_int (abfd, s->lma))
2413 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2417 if (relocs_to_go == 0)
2419 /* If there aren't any relocations then output the load constant
2420 byte opcode rather than the load with relocation opcode */
2422 while (current_byte_index < s->_raw_size)
2425 unsigned int MAXRUN = 127;
2427 if (run > s->_raw_size - current_byte_index)
2429 run = s->_raw_size - current_byte_index;
2434 if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
2436 /* Output a stream of bytes */
2437 if (! ieee_write_int (abfd, run))
2439 if (bfd_bwrite ((PTR) (stream + current_byte_index), run, abfd)
2442 current_byte_index += run;
2448 if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
2451 /* Output the data stream as the longest sequence of bytes
2452 possible, allowing for the a reasonable packet size and
2453 relocation stuffs. */
2455 if ((PTR) stream == (PTR) NULL)
2457 /* Outputting a section without data, fill it up */
2458 stream = (unsigned char *) bfd_zalloc (abfd, s->_raw_size);
2462 while (current_byte_index < s->_raw_size)
2465 unsigned int MAXRUN = 127;
2468 run = (*p)->address - current_byte_index;
2476 if (run > s->_raw_size - current_byte_index)
2478 run = s->_raw_size - current_byte_index;
2483 /* Output a stream of bytes */
2484 if (! ieee_write_int (abfd, run))
2486 if (bfd_bwrite ((PTR) (stream + current_byte_index), run, abfd)
2489 current_byte_index += run;
2491 /* Output any relocations here */
2492 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
2495 && (*p) && (*p)->address == current_byte_index)
2501 if (r->howto->pc_relative)
2503 r->addend += current_byte_index;
2507 switch (r->howto->size)
2511 ov = bfd_get_signed_32 (abfd,
2512 stream + current_byte_index);
2513 current_byte_index += 4;
2516 ov = bfd_get_signed_16 (abfd,
2517 stream + current_byte_index);
2518 current_byte_index += 2;
2521 ov = bfd_get_signed_8 (abfd,
2522 stream + current_byte_index);
2523 current_byte_index++;
2531 ov &= r->howto->src_mask;
2533 if (r->howto->pc_relative
2534 && ! r->howto->pcrel_offset)
2537 if (! ieee_write_byte (abfd,
2538 ieee_function_either_open_b_enum))
2543 if (r->sym_ptr_ptr != (asymbol **) NULL)
2545 if (! ieee_write_expression (abfd, r->addend + ov,
2547 r->howto->pc_relative,
2548 (unsigned) s->index))
2553 if (! ieee_write_expression (abfd, r->addend + ov,
2555 r->howto->pc_relative,
2556 (unsigned) s->index))
2560 if (number_of_maus_in_address
2561 != bfd_get_reloc_size (r->howto))
2563 bfd_vma rsize = bfd_get_reloc_size (r->howto);
2564 if (! ieee_write_int (abfd, rsize))
2567 if (! ieee_write_byte (abfd,
2568 ieee_function_either_close_b_enum))
2582 /* If there are no relocations in the output section then we can be
2583 clever about how we write. We block items up into a max of 127
2587 do_as_repeat (abfd, s)
2593 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2594 || ! ieee_write_byte (abfd,
2595 (bfd_byte) (s->index
2596 + IEEE_SECTION_NUMBER_BASE))
2597 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
2598 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
2599 || ! ieee_write_byte (abfd,
2600 (bfd_byte) (s->index
2601 + IEEE_SECTION_NUMBER_BASE)))
2604 if ((abfd->flags & EXEC_P) != 0)
2606 if (! ieee_write_int (abfd, s->lma))
2611 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2615 if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
2616 || ! ieee_write_int (abfd, s->_raw_size)
2617 || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
2618 || ! ieee_write_byte (abfd, 1)
2619 || ! ieee_write_byte (abfd, 0))
2627 do_without_relocs (abfd, s)
2631 bfd_byte *stream = ieee_per_section (s)->data;
2633 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2635 if (! do_as_repeat (abfd, s))
2641 for (i = 0; i < s->_raw_size; i++)
2645 if (! do_with_relocs (abfd, s))
2650 if (! do_as_repeat (abfd, s))
2658 static unsigned char *output_ptr_start;
2659 static unsigned char *output_ptr;
2660 static unsigned char *output_ptr_end;
2661 static unsigned char *input_ptr_start;
2662 static unsigned char *input_ptr;
2663 static unsigned char *input_ptr_end;
2664 static bfd *input_bfd;
2665 static bfd *output_bfd;
2666 static int output_buffer;
2669 ieee_mkobject (abfd)
2674 output_ptr_start = NULL;
2676 output_ptr_end = NULL;
2677 input_ptr_start = NULL;
2679 input_ptr_end = NULL;
2683 amt = sizeof (ieee_data_type);
2684 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, amt);
2685 return abfd->tdata.ieee_data != NULL;
2691 bfd_size_type amt = input_ptr_end - input_ptr_start;
2692 /* FIXME: Check return value. I'm not sure whether it needs to read
2693 the entire buffer or not. */
2694 bfd_bread ((PTR) input_ptr_start, amt, input_bfd);
2695 input_ptr = input_ptr_start;
2701 bfd_size_type amt = output_ptr - output_ptr_start;
2702 if (bfd_bwrite ((PTR) (output_ptr_start), amt, output_bfd) != amt)
2704 output_ptr = output_ptr_start;
2708 #define THIS() ( *input_ptr )
2709 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2710 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2716 if (value >= 0 && value <= 127)
2722 unsigned int length;
2723 /* How many significant bytes ? */
2724 /* FIXME FOR LONGER INTS */
2725 if (value & 0xff000000)
2729 else if (value & 0x00ff0000)
2733 else if (value & 0x0000ff00)
2740 OUT ((int) ieee_number_repeat_start_enum + length);
2759 int length = THIS ();
2771 #define VAR(x) ((x | 0x80))
2786 value = (value << 8) | THIS ();
2788 value = (value << 8) | THIS ();
2790 value = (value << 8) | THIS ();
2798 value = (value << 8) | THIS ();
2800 value = (value << 8) | THIS ();
2808 value = (value << 8) | THIS ();
2825 /* Not a number, just bug out with the answer */
2826 write_int (*(--tos));
2842 ieee_data_type *ieee;
2845 section_number = THIS ();
2848 ieee = IEEE_DATA (input_bfd);
2849 s = ieee->section_table[section_number];
2851 if (s->output_section)
2852 value = s->output_section->lma;
2853 value += s->output_offset;
2860 write_int (*(--tos));
2868 /* Drop the int in the buffer, and copy a null into the gap, which we
2869 will overwrite later */
2873 struct output_buffer_struct *buf;
2875 if (buf->buffer == output_buffer)
2877 /* Still a chance to output the size */
2878 int value = output_ptr - buf->ptrp + 3;
2879 buf->ptrp[0] = value >> 24;
2880 buf->ptrp[1] = value >> 16;
2881 buf->ptrp[2] = value >> 8;
2882 buf->ptrp[3] = value >> 0;
2888 struct output_buffer_struct *buf;
2914 buf->ptrp = output_ptr;
2915 buf->buffer = output_buffer;
2955 #define ID copy_id()
2956 #define INT copy_int()
2957 #define EXP copy_expression()
2958 #define INTn(q) copy_int()
2959 #define EXPn(q) copy_expression()
2998 EXPn (instruction address);
3032 EXPn (external function);
3042 INTn (locked register);
3065 /* Attribute record */
3134 /* Unique typedefs for module */
3135 /* GLobal typedefs */
3136 /* High level module scope beginning */
3138 struct output_buffer_struct ob;
3153 /* Global function */
3155 struct output_buffer_struct ob;
3169 EXPn (size of block);
3175 /* File name for source line numbers */
3177 struct output_buffer_struct ob;
3197 /* Local function */
3199 struct output_buffer_struct ob;
3217 /* Assembler module scope beginning -*/
3219 struct output_buffer_struct ob;
3245 struct output_buffer_struct ob;
3252 INTn (section index);
3260 EXPn (Size in Maus);
3315 moves all the debug information from the source bfd to the output
3316 bfd, and relocates any expressions it finds
3320 relocate_debug (output, input)
3321 bfd *output ATTRIBUTE_UNUSED;
3326 unsigned char input_buffer[IBS];
3328 input_ptr_start = input_ptr = input_buffer;
3329 input_ptr_end = input_buffer + IBS;
3331 /* FIXME: Check return value. I'm not sure whether it needs to read
3332 the entire buffer or not. */
3333 bfd_bread ((PTR) input_ptr_start, (bfd_size_type) IBS, input);
3337 /* Gather together all the debug information from each input BFD into
3338 one place, relocating it and emitting it as we go. */
3341 ieee_write_debug_part (abfd)
3344 ieee_data_type *ieee = IEEE_DATA (abfd);
3345 bfd_chain_type *chain = ieee->chain_root;
3346 unsigned char obuff[OBS];
3347 bfd_boolean some_debug = FALSE;
3348 file_ptr here = bfd_tell (abfd);
3350 output_ptr_start = output_ptr = obuff;
3351 output_ptr_end = obuff + OBS;
3355 if (chain == (bfd_chain_type *) NULL)
3359 for (s = abfd->sections; s != NULL; s = s->next)
3360 if ((s->flags & SEC_DEBUGGING) != 0)
3364 ieee->w.r.debug_information_part = 0;
3368 ieee->w.r.debug_information_part = here;
3369 if (bfd_bwrite (s->contents, s->_raw_size, abfd) != s->_raw_size)
3374 while (chain != (bfd_chain_type *) NULL)
3376 bfd *entry = chain->this;
3377 ieee_data_type *entry_ieee = IEEE_DATA (entry);
3378 if (entry_ieee->w.r.debug_information_part)
3380 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
3383 relocate_debug (abfd, entry);
3386 chain = chain->next;
3390 ieee->w.r.debug_information_part = here;
3394 ieee->w.r.debug_information_part = 0;
3403 /* Write the data in an ieee way. */
3406 ieee_write_data_part (abfd)
3410 ieee_data_type *ieee = IEEE_DATA (abfd);
3411 ieee->w.r.data_part = bfd_tell (abfd);
3412 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3414 /* Skip sections that have no loadable contents (.bss,
3416 if ((s->flags & SEC_LOAD) == 0)
3419 /* Sort the reloc records so we can insert them in the correct
3421 if (s->reloc_count != 0)
3423 if (! do_with_relocs (abfd, s))
3428 if (! do_without_relocs (abfd, s))
3438 init_for_output (abfd)
3442 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3444 if ((s->flags & SEC_DEBUGGING) != 0)
3446 if (s->_raw_size != 0)
3448 bfd_size_type size = s->_raw_size;
3449 ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, size));
3450 if (!ieee_per_section (s)->data)
3457 /** exec and core file sections */
3459 /* set section contents is complicated with IEEE since the format is
3460 * not a byte image, but a record stream.
3463 ieee_set_section_contents (abfd, section, location, offset, count)
3468 bfd_size_type count;
3470 if ((section->flags & SEC_DEBUGGING) != 0)
3472 if (section->contents == NULL)
3474 bfd_size_type size = section->_raw_size;
3475 section->contents = (unsigned char *) bfd_alloc (abfd, size);
3476 if (section->contents == NULL)
3479 /* bfd_set_section_contents has already checked that everything
3481 memcpy (section->contents + offset, location, (size_t) count);
3485 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
3487 if (!init_for_output (abfd))
3490 memcpy ((PTR) (ieee_per_section (section)->data + offset),
3492 (unsigned int) count);
3496 /* Write the external symbols of a file. IEEE considers two sorts of
3497 external symbols, public, and referenced. It uses to internal
3498 forms to index them as well. When we write them out we turn their
3499 symbol values into indexes from the right base. */
3502 ieee_write_external_part (abfd)
3506 ieee_data_type *ieee = IEEE_DATA (abfd);
3508 unsigned int reference_index = IEEE_REFERENCE_BASE;
3509 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
3510 file_ptr here = bfd_tell (abfd);
3511 bfd_boolean hadone = FALSE;
3512 if (abfd->outsymbols != (asymbol **) NULL)
3515 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
3518 if (bfd_is_und_section (p->section))
3520 /* This must be a symbol reference .. */
3521 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3522 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3523 || ! ieee_write_id (abfd, p->name))
3525 p->value = reference_index;
3529 else if (bfd_is_com_section (p->section))
3531 /* This is a weak reference */
3532 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3533 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3534 || ! ieee_write_id (abfd, p->name)
3535 || ! ieee_write_byte (abfd,
3536 ieee_weak_external_reference_enum)
3537 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3538 || ! ieee_write_int (abfd, p->value))
3540 p->value = reference_index;
3544 else if (p->flags & BSF_GLOBAL)
3546 /* This must be a symbol definition */
3548 if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
3549 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3550 || ! ieee_write_id (abfd, p->name)
3551 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
3552 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3553 || ! ieee_write_byte (abfd, 15) /* instruction address */
3554 || ! ieee_write_byte (abfd, 19) /* static symbol */
3555 || ! ieee_write_byte (abfd, 1)) /* one of them */
3558 /* Write out the value */
3559 if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
3560 || ! ieee_write_int (abfd, (bfd_vma) public_index))
3562 if (! bfd_is_abs_section (p->section))
3564 if (abfd->flags & EXEC_P)
3566 /* If fully linked, then output all symbols
3568 if (! (ieee_write_int
3571 + p->section->output_offset
3572 + p->section->output_section->vma))))
3577 if (! (ieee_write_expression
3579 p->value + p->section->output_offset,
3580 p->section->output_section->symbol,
3587 if (! ieee_write_expression (abfd,
3589 bfd_abs_section_ptr->symbol,
3593 p->value = public_index;
3599 /* This can happen - when there are gaps in the symbols read */
3600 /* from an input ieee file */
3605 ieee->w.r.external_part = here;
3611 static const unsigned char exten[] =
3614 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3615 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3616 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3619 static const unsigned char envi[] =
3623 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3626 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3628 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3629 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3633 ieee_write_me_part (abfd)
3636 ieee_data_type *ieee = IEEE_DATA (abfd);
3637 ieee->w.r.trailer_part = bfd_tell (abfd);
3638 if (abfd->start_address)
3640 if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
3641 || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
3642 || ! ieee_write_int (abfd, abfd->start_address)
3643 || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
3646 ieee->w.r.me_record = bfd_tell (abfd);
3647 if (! ieee_write_byte (abfd, ieee_module_end_enum))
3652 /* Write out the IEEE processor ID. */
3655 ieee_write_processor (abfd)
3658 const bfd_arch_info_type *arch;
3660 arch = bfd_get_arch_info (abfd);
3664 if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
3669 if (! ieee_write_id (abfd, "29000"))
3673 case bfd_arch_h8300:
3674 if (! ieee_write_id (abfd, "H8/300"))
3678 case bfd_arch_h8500:
3679 if (! ieee_write_id (abfd, "H8/500"))
3687 case bfd_mach_i960_core:
3688 case bfd_mach_i960_ka_sa:
3689 if (! ieee_write_id (abfd, "80960KA"))
3693 case bfd_mach_i960_kb_sb:
3694 if (! ieee_write_id (abfd, "80960KB"))
3698 case bfd_mach_i960_ca:
3699 if (! ieee_write_id (abfd, "80960CA"))
3703 case bfd_mach_i960_mc:
3704 case bfd_mach_i960_xa:
3705 if (! ieee_write_id (abfd, "80960MC"))
3717 default: id = "68020"; break;
3718 case bfd_mach_m68000: id = "68000"; break;
3719 case bfd_mach_m68008: id = "68008"; break;
3720 case bfd_mach_m68010: id = "68010"; break;
3721 case bfd_mach_m68020: id = "68020"; break;
3722 case bfd_mach_m68030: id = "68030"; break;
3723 case bfd_mach_m68040: id = "68040"; break;
3724 case bfd_mach_m68060: id = "68060"; break;
3725 case bfd_mach_cpu32: id = "cpu32"; break;
3726 case bfd_mach_mcf5200:id = "5200"; break;
3727 case bfd_mach_mcf5206e:id = "5206e"; break;
3728 case bfd_mach_mcf5307:id = "5307"; break;
3729 case bfd_mach_mcf5407:id = "5407"; break;
3732 if (! ieee_write_id (abfd, id))
3742 ieee_write_object_contents (abfd)
3745 ieee_data_type *ieee = IEEE_DATA (abfd);
3749 /* Fast forward over the header area */
3750 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3753 if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
3754 || ! ieee_write_processor (abfd)
3755 || ! ieee_write_id (abfd, abfd->filename))
3758 /* Fast forward over the variable bits */
3759 if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
3763 if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
3765 /* MAU's per address */
3766 if (! ieee_write_byte (abfd,
3767 (bfd_byte) (bfd_arch_bits_per_address (abfd)
3768 / bfd_arch_bits_per_byte (abfd))))
3771 old = bfd_tell (abfd);
3772 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3775 ieee->w.r.extension_record = bfd_tell (abfd);
3776 if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
3779 if (abfd->flags & EXEC_P)
3781 if (! ieee_write_byte (abfd, 0x1)) /* Absolute */
3786 if (! ieee_write_byte (abfd, 0x2)) /* Relocateable */
3790 ieee->w.r.environmental_record = bfd_tell (abfd);
3791 if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
3795 /* The HP emulator database requires a timestamp in the file. */
3801 t = (struct tm *) localtime (&now);
3802 if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
3803 || ! ieee_write_byte (abfd, 0x21)
3804 || ! ieee_write_byte (abfd, 0)
3805 || ! ieee_write_byte (abfd, 50)
3806 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
3807 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
3808 || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
3809 || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
3810 || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
3811 || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
3819 if (! ieee_write_section_part (abfd))
3821 /* First write the symbols. This changes their values into table
3822 indeces so we cant use it after this point. */
3823 if (! ieee_write_external_part (abfd))
3826 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3828 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3831 /* Write any debugs we have been told about. */
3832 if (! ieee_write_debug_part (abfd))
3835 /* Can only write the data once the symbols have been written, since
3836 the data contains relocation information which points to the
3838 if (! ieee_write_data_part (abfd))
3841 /* At the end we put the end! */
3842 if (! ieee_write_me_part (abfd))
3845 /* Generate the header */
3846 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3849 for (i = 0; i < N_W_VARIABLES; i++)
3851 if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
3852 || ! ieee_write_byte (abfd, (bfd_byte) i)
3853 || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
3860 /* Native-level interface to symbols. */
3862 /* We read the symbols into a buffer, which is discarded when this
3863 function exits. We read the strings into a buffer large enough to
3864 hold them all plus all the cached symbol entries. */
3867 ieee_make_empty_symbol (abfd)
3870 bfd_size_type amt = sizeof (ieee_symbol_type);
3871 ieee_symbol_type *new = (ieee_symbol_type *) bfd_zalloc (abfd, amt);
3874 new->symbol.the_bfd = abfd;
3875 return &new->symbol;
3879 ieee_openr_next_archived_file (arch, prev)
3883 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3884 /* take the next one from the arch state, or reset */
3885 if (prev == (bfd *) NULL)
3887 /* Reset the index - the first two entries are bogus*/
3888 ar->element_index = 2;
3892 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3893 ar->element_index++;
3894 if (ar->element_index <= ar->element_count)
3896 if (p->file_offset != (file_ptr) 0)
3898 if (p->abfd == (bfd *) NULL)
3900 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3901 p->abfd->origin = p->file_offset;
3908 bfd_set_error (bfd_error_no_more_archived_files);
3909 return (bfd *) NULL;
3916 ieee_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
3917 functionname_ptr, line_ptr)
3918 bfd *abfd ATTRIBUTE_UNUSED;
3919 asection *section ATTRIBUTE_UNUSED;
3920 asymbol **symbols ATTRIBUTE_UNUSED;
3921 bfd_vma offset ATTRIBUTE_UNUSED;
3922 const char **filename_ptr ATTRIBUTE_UNUSED;
3923 const char **functionname_ptr ATTRIBUTE_UNUSED;
3924 unsigned int *line_ptr ATTRIBUTE_UNUSED;
3930 ieee_generic_stat_arch_elt (abfd, buf)
3934 ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
3935 ieee_data_type *ieee;
3937 if (abfd->my_archive != NULL)
3938 ar = abfd->my_archive->tdata.ieee_ar_data;
3939 if (ar == (ieee_ar_data_type *) NULL)
3941 bfd_set_error (bfd_error_invalid_operation);
3945 if (IEEE_DATA (abfd) == NULL)
3947 if (ieee_object_p (abfd) == NULL)
3949 bfd_set_error (bfd_error_wrong_format);
3954 ieee = IEEE_DATA (abfd);
3956 buf->st_size = ieee->w.r.me_record + 1;
3957 buf->st_mode = 0644;
3962 ieee_sizeof_headers (abfd, x)
3963 bfd *abfd ATTRIBUTE_UNUSED;
3964 bfd_boolean x ATTRIBUTE_UNUSED;
3970 /* The debug info routines are never used. */
3974 ieee_bfd_debug_info_start (abfd)
3981 ieee_bfd_debug_info_end (abfd)
3988 /* Add this section to the list of sections we have debug info for, to
3989 be ready to output it at close time
3992 ieee_bfd_debug_info_accumulate (abfd, section)
3996 ieee_data_type *ieee = IEEE_DATA (section->owner);
3997 ieee_data_type *output_ieee = IEEE_DATA (abfd);
3998 /* can only accumulate data from other ieee bfds */
3999 if (section->owner->xvec != abfd->xvec)
4001 /* Only bother once per bfd */
4002 if (ieee->done_debug)
4004 ieee->done_debug = TRUE;
4006 /* Don't bother if there is no debug info */
4007 if (ieee->w.r.debug_information_part == 0)
4013 bfd_size_type amt = sizeof (bfd_chain_type);
4014 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc (abfd, amt);
4016 abort (); /* FIXME */
4017 n->this = section->owner;
4018 n->next = (bfd_chain_type *) NULL;
4020 if (output_ieee->chain_head)
4022 output_ieee->chain_head->next = n;
4026 output_ieee->chain_root = n;
4029 output_ieee->chain_head = n;
4035 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
4036 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
4038 #define ieee_slurp_armap bfd_true
4039 #define ieee_slurp_extended_name_table bfd_true
4040 #define ieee_construct_extended_name_table \
4042 PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
4044 #define ieee_truncate_arname bfd_dont_truncate_arname
4045 #define ieee_write_armap \
4047 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
4049 #define ieee_read_ar_hdr bfd_nullvoidptr
4050 #define ieee_update_armap_timestamp bfd_true
4051 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
4053 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
4054 #define ieee_get_lineno _bfd_nosymbols_get_lineno
4055 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
4056 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
4057 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
4059 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
4061 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
4063 #define ieee_get_section_contents_in_window \
4064 _bfd_generic_get_section_contents_in_window
4065 #define ieee_bfd_get_relocated_section_contents \
4066 bfd_generic_get_relocated_section_contents
4067 #define ieee_bfd_relax_section bfd_generic_relax_section
4068 #define ieee_bfd_gc_sections bfd_generic_gc_sections
4069 #define ieee_bfd_merge_sections bfd_generic_merge_sections
4070 #define ieee_bfd_discard_group bfd_generic_discard_group
4071 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
4072 #define ieee_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
4073 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
4074 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
4075 #define ieee_bfd_final_link _bfd_generic_final_link
4076 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
4079 const bfd_target ieee_vec =
4082 bfd_target_ieee_flavour,
4083 BFD_ENDIAN_UNKNOWN, /* target byte order */
4084 BFD_ENDIAN_UNKNOWN, /* target headers byte order */
4085 (HAS_RELOC | EXEC_P | /* object flags */
4086 HAS_LINENO | HAS_DEBUG |
4087 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
4088 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
4089 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
4090 '_', /* leading underscore */
4091 ' ', /* ar_pad_char */
4092 16, /* ar_max_namelen */
4093 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
4094 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
4095 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
4096 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
4097 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
4098 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
4101 ieee_object_p, /* bfd_check_format */
4108 _bfd_generic_mkarchive,
4113 ieee_write_object_contents,
4114 _bfd_write_archive_contents,
4118 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
4119 ieee_get_section_contents, ieee_get_section_contents_in_window */
4120 BFD_JUMP_TABLE_GENERIC (ieee),
4122 BFD_JUMP_TABLE_COPY (_bfd_generic),
4123 BFD_JUMP_TABLE_CORE (_bfd_nocore),
4125 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
4126 ieee_construct_extended_name_table, ieee_truncate_arname,
4127 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
4128 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
4129 ieee_update_armap_timestamp */
4130 BFD_JUMP_TABLE_ARCHIVE (ieee),
4132 /* ieee_get_symtab_upper_bound, ieee_get_symtab, ieee_make_empty_symbol,
4133 ieee_print_symbol, ieee_get_symbol_info, ieee_bfd_is_local_label_name,
4134 ieee_get_lineno, ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
4135 ieee_read_minisymbols, ieee_minisymbol_to_symbol */
4136 BFD_JUMP_TABLE_SYMBOLS (ieee),
4138 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
4139 ieee_bfd_reloc_type_lookup */
4140 BFD_JUMP_TABLE_RELOCS (ieee),
4142 /* ieee_set_arch_mach, ieee_set_section_contents */
4143 BFD_JUMP_TABLE_WRITE (ieee),
4145 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
4146 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
4147 _bfd_generic_link_hash_table_free,
4148 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
4149 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
4150 ieee_bfd_merge_sections */
4151 BFD_JUMP_TABLE_LINK (ieee),
4153 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),