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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 #define KEEPMINUSPCININST 0
26 /* IEEE 695 format is a stream of records, which we parse using a simple one-
27 token (which is one byte in this lexicon) lookahead recursive decent
35 #include "safe-ctype.h"
37 struct output_buffer_struct
43 static unsigned char *output_ptr_start
;
44 static unsigned char *output_ptr
;
45 static unsigned char *output_ptr_end
;
46 static unsigned char *input_ptr_start
;
47 static unsigned char *input_ptr
;
48 static unsigned char *input_ptr_end
;
49 static bfd
*input_bfd
;
50 static bfd
*output_bfd
;
51 static int output_buffer
;
54 static void block (void);
56 /* Functions for writing to ieee files in the strange way that the
60 ieee_write_byte (bfd
*abfd
, int barg
)
65 if (bfd_bwrite ((void *) &byte
, (bfd_size_type
) 1, abfd
) != 1)
71 ieee_write_2bytes (bfd
*abfd
, int bytes
)
75 buffer
[0] = bytes
>> 8;
76 buffer
[1] = bytes
& 0xff;
77 if (bfd_bwrite ((void *) buffer
, (bfd_size_type
) 2, abfd
) != 2)
83 ieee_write_int (bfd
*abfd
, bfd_vma value
)
87 if (! ieee_write_byte (abfd
, (bfd_byte
) value
))
94 /* How many significant bytes ? */
95 /* FIXME FOR LONGER INTS. */
96 if (value
& 0xff000000)
98 else if (value
& 0x00ff0000)
100 else if (value
& 0x0000ff00)
105 if (! ieee_write_byte (abfd
,
106 (bfd_byte
) ((int) ieee_number_repeat_start_enum
112 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 24)))
116 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 16)))
120 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 8)))
124 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
)))
133 ieee_write_id (bfd
*abfd
, const char *id
)
135 size_t length
= strlen (id
);
139 if (! ieee_write_byte (abfd
, (bfd_byte
) length
))
142 else if (length
< 255)
144 if (! ieee_write_byte (abfd
, ieee_extension_length_1_enum
)
145 || ! ieee_write_byte (abfd
, (bfd_byte
) length
))
148 else if (length
< 65535)
150 if (! ieee_write_byte (abfd
, ieee_extension_length_2_enum
)
151 || ! ieee_write_2bytes (abfd
, (int) length
))
156 (*_bfd_error_handler
)
157 (_("%s: string too long (%d chars, max 65535)"),
158 bfd_get_filename (abfd
), length
);
159 bfd_set_error (bfd_error_invalid_operation
);
163 if (bfd_bwrite ((void *) id
, (bfd_size_type
) length
, abfd
) != length
)
168 /* Functions for reading from ieee files in the strange way that the
169 standard requires. */
171 #define this_byte(ieee) *((ieee)->input_p)
172 #define next_byte(ieee) ((ieee)->input_p++)
173 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
175 static unsigned short
176 read_2bytes (common_header_type
*ieee
)
178 unsigned char c1
= this_byte_and_next (ieee
);
179 unsigned char c2
= this_byte_and_next (ieee
);
181 return (c1
<< 8) | c2
;
185 bfd_get_string (common_header_type
*ieee
, char *string
, size_t length
)
189 for (i
= 0; i
< length
; i
++)
190 string
[i
] = this_byte_and_next (ieee
);
194 read_id (common_header_type
*ieee
)
199 length
= this_byte_and_next (ieee
);
201 /* Simple string of length 0 to 127. */
204 else if (length
== 0xde)
205 /* Length is next byte, allowing 0..255. */
206 length
= this_byte_and_next (ieee
);
208 else if (length
== 0xdf)
210 /* Length is next two bytes, allowing 0..65535. */
211 length
= this_byte_and_next (ieee
);
212 length
= (length
* 256) + this_byte_and_next (ieee
);
215 /* Buy memory and read string. */
216 string
= bfd_alloc (ieee
->abfd
, (bfd_size_type
) length
+ 1);
219 bfd_get_string (ieee
, string
, length
);
225 ieee_write_expression (bfd
*abfd
,
231 unsigned int term_count
= 0;
235 if (! ieee_write_int (abfd
, value
))
240 /* Badly formatted binaries can have a missing symbol,
241 so test here to prevent a seg fault. */
244 if (bfd_is_com_section (symbol
->section
)
245 || bfd_is_und_section (symbol
->section
))
247 /* Def of a common symbol. */
248 if (! ieee_write_byte (abfd
, ieee_variable_X_enum
)
249 || ! ieee_write_int (abfd
, symbol
->value
))
253 else if (! bfd_is_abs_section (symbol
->section
))
255 /* Ref to defined symbol - */
256 if (symbol
->flags
& BSF_GLOBAL
)
258 if (! ieee_write_byte (abfd
, ieee_variable_I_enum
)
259 || ! ieee_write_int (abfd
, symbol
->value
))
263 else if (symbol
->flags
& (BSF_LOCAL
| BSF_SECTION_SYM
))
265 /* This is a reference to a defined local symbol. We can
266 easily do a local as a section+offset. */
267 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
)
268 || ! ieee_write_byte (abfd
,
269 (bfd_byte
) (symbol
->section
->index
270 + IEEE_SECTION_NUMBER_BASE
)))
274 if (symbol
->value
!= 0)
276 if (! ieee_write_int (abfd
, symbol
->value
))
283 (*_bfd_error_handler
)
284 (_("%s: unrecognized symbol `%s' flags 0x%x"),
285 bfd_get_filename (abfd
), bfd_asymbol_name (symbol
),
287 bfd_set_error (bfd_error_invalid_operation
);
295 /* Subtract the pc from here by asking for PC of this section. */
296 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
)
297 || ! ieee_write_byte (abfd
,
298 (bfd_byte
) (index
+ IEEE_SECTION_NUMBER_BASE
))
299 || ! ieee_write_byte (abfd
, ieee_function_minus_enum
))
303 /* Handle the degenerate case of a 0 address. */
305 if (! ieee_write_int (abfd
, (bfd_vma
) 0))
308 while (term_count
> 1)
310 if (! ieee_write_byte (abfd
, ieee_function_plus_enum
))
318 /* Writes any integer into the buffer supplied and always takes 5 bytes. */
321 ieee_write_int5 (bfd_byte
*buffer
, bfd_vma value
)
323 buffer
[0] = (bfd_byte
) ieee_number_repeat_4_enum
;
324 buffer
[1] = (value
>> 24) & 0xff;
325 buffer
[2] = (value
>> 16) & 0xff;
326 buffer
[3] = (value
>> 8) & 0xff;
327 buffer
[4] = (value
>> 0) & 0xff;
331 ieee_write_int5_out (bfd
*abfd
, bfd_vma value
)
335 ieee_write_int5 (b
, value
);
336 if (bfd_bwrite ((void *) b
, (bfd_size_type
) 5, abfd
) != 5)
342 parse_int (common_header_type
*ieee
, bfd_vma
*value_ptr
)
344 int value
= this_byte (ieee
);
347 if (value
>= 0 && value
<= 127)
353 else if (value
>= 0x80 && value
<= 0x88)
355 unsigned int count
= value
& 0xf;
361 result
= (result
<< 8) | this_byte_and_next (ieee
);
371 parse_i (common_header_type
*ieee
, bfd_boolean
*ok
)
374 *ok
= parse_int (ieee
, &x
);
379 must_parse_int (common_header_type
*ieee
)
382 BFD_ASSERT (parse_int (ieee
, &result
));
390 ieee_symbol_index_type symbol
;
394 #if KEEPMINUSPCININST
396 #define SRC_MASK(arg) arg
397 #define PCREL_OFFSET FALSE
401 #define SRC_MASK(arg) 0
402 #define PCREL_OFFSET TRUE
406 static reloc_howto_type abs32_howto
=
413 complain_overflow_bitfield
,
421 static reloc_howto_type abs16_howto
=
428 complain_overflow_bitfield
,
436 static reloc_howto_type abs8_howto
=
443 complain_overflow_bitfield
,
451 static reloc_howto_type rel32_howto
=
458 complain_overflow_signed
,
462 SRC_MASK (0xffffffff),
466 static reloc_howto_type rel16_howto
=
473 complain_overflow_signed
,
477 SRC_MASK (0x0000ffff),
481 static reloc_howto_type rel8_howto
=
488 complain_overflow_signed
,
492 SRC_MASK (0x000000ff),
496 static ieee_symbol_index_type NOSYMBOL
= {0, 0};
499 parse_expression (ieee_data_type
*ieee
,
501 ieee_symbol_index_type
*symbol
,
507 bfd_boolean loop
= TRUE
;
508 ieee_value_type stack
[10];
509 ieee_value_type
*sp
= stack
;
518 /* The stack pointer always points to the next unused location. */
519 #define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC;
520 #define POP(x,y,z) DEC; x = TOS.symbol; y = TOS.section; z = TOS.value;
522 while (loop
&& ieee
->h
.input_p
< ieee
->h
.last_byte
)
524 switch (this_byte (&(ieee
->h
)))
526 case ieee_variable_P_enum
:
527 /* P variable, current program counter for section n. */
531 next_byte (&(ieee
->h
));
533 section_n
= must_parse_int (&(ieee
->h
));
534 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, 0);
537 case ieee_variable_L_enum
:
538 /* L variable address of section N. */
539 next_byte (&(ieee
->h
));
540 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
542 case ieee_variable_R_enum
:
543 /* R variable, logical address of section module. */
544 /* FIXME, this should be different to L. */
545 next_byte (&(ieee
->h
));
546 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
548 case ieee_variable_S_enum
:
549 /* S variable, size in MAUS of section module. */
550 next_byte (&(ieee
->h
));
553 ieee
->section_table
[must_parse_int (&(ieee
->h
))]->size
);
555 case ieee_variable_I_enum
:
556 /* Push the address of variable n. */
558 ieee_symbol_index_type sy
;
560 next_byte (&(ieee
->h
));
561 sy
.index
= (int) must_parse_int (&(ieee
->h
));
564 PUSH (sy
, bfd_abs_section_ptr
, 0);
567 case ieee_variable_X_enum
:
568 /* Push the address of external variable n. */
570 ieee_symbol_index_type sy
;
572 next_byte (&(ieee
->h
));
573 sy
.index
= (int) (must_parse_int (&(ieee
->h
)));
576 PUSH (sy
, bfd_und_section_ptr
, 0);
579 case ieee_function_minus_enum
:
581 bfd_vma value1
, value2
;
582 asection
*section1
, *section_dummy
;
583 ieee_symbol_index_type sy
;
585 next_byte (&(ieee
->h
));
587 POP (sy
, section1
, value1
);
588 POP (sy
, section_dummy
, value2
);
589 PUSH (sy
, section1
? section1
: section_dummy
, value2
- value1
);
592 case ieee_function_plus_enum
:
594 bfd_vma value1
, value2
;
597 ieee_symbol_index_type sy1
;
598 ieee_symbol_index_type sy2
;
600 next_byte (&(ieee
->h
));
602 POP (sy1
, section1
, value1
);
603 POP (sy2
, section2
, value2
);
604 PUSH (sy1
.letter
? sy1
: sy2
,
605 bfd_is_abs_section (section1
) ? section2
: section1
,
613 BFD_ASSERT (this_byte (&(ieee
->h
)) < (int) ieee_variable_A_enum
614 || this_byte (&(ieee
->h
)) > (int) ieee_variable_Z_enum
);
615 if (parse_int (&(ieee
->h
), &va
))
617 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, va
);
620 /* Thats all that we can understand. */
626 /* As far as I can see there is a bug in the Microtec IEEE output
627 which I'm using to scan, whereby the comma operator is omitted
628 sometimes in an expression, giving expressions with too many
629 terms. We can tell if that's the case by ensuring that
630 sp == stack here. If not, then we've pushed something too far,
631 so we keep adding. */
632 while (sp
!= stack
+ 1)
635 ieee_symbol_index_type sy1
;
637 POP (sy1
, section1
, *extra
);
640 POP (*symbol
, dummy
, *value
);
646 #define ieee_seek(ieee, offset) \
649 ieee->h.input_p = ieee->h.first_byte + offset; \
650 ieee->h.last_byte = (ieee->h.first_byte \
651 + ieee_part_after (ieee, offset)); \
655 #define ieee_pos(ieee) \
656 (ieee->h.input_p - ieee->h.first_byte)
658 /* Find the first part of the ieee file after HERE. */
661 ieee_part_after (ieee_data_type
*ieee
, file_ptr here
)
664 file_ptr after
= ieee
->w
.r
.me_record
;
666 /* File parts can come in any order, except that module end is
667 guaranteed to be last (and the header first). */
668 for (part
= 0; part
< N_W_VARIABLES
; part
++)
669 if (ieee
->w
.offset
[part
] > here
&& after
> ieee
->w
.offset
[part
])
670 after
= ieee
->w
.offset
[part
];
675 static unsigned int last_index
;
676 static char last_type
; /* Is the index for an X or a D. */
678 static ieee_symbol_type
*
679 get_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
680 ieee_data_type
*ieee
,
681 ieee_symbol_type
*last_symbol
,
682 unsigned int *symbol_count
,
683 ieee_symbol_type
***pptr
,
684 unsigned int *max_index
,
687 /* Need a new symbol. */
688 unsigned int new_index
= must_parse_int (&(ieee
->h
));
690 if (new_index
!= last_index
|| this_type
!= last_type
)
692 ieee_symbol_type
*new_symbol
;
693 bfd_size_type amt
= sizeof (ieee_symbol_type
);
695 new_symbol
= bfd_alloc (ieee
->h
.abfd
, amt
);
699 new_symbol
->index
= new_index
;
700 last_index
= new_index
;
703 *pptr
= &new_symbol
->next
;
704 if (new_index
> *max_index
)
705 *max_index
= new_index
;
707 last_type
= this_type
;
708 new_symbol
->symbol
.section
= bfd_abs_section_ptr
;
715 ieee_slurp_external_symbols (bfd
*abfd
)
717 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
718 file_ptr offset
= ieee
->w
.r
.external_part
;
720 ieee_symbol_type
**prev_symbols_ptr
= &ieee
->external_symbols
;
721 ieee_symbol_type
**prev_reference_ptr
= &ieee
->external_reference
;
722 ieee_symbol_type
*symbol
= NULL
;
723 unsigned int symbol_count
= 0;
724 bfd_boolean loop
= TRUE
;
726 last_index
= 0xffffff;
727 ieee
->symbol_table_full
= TRUE
;
729 ieee_seek (ieee
, offset
);
733 switch (this_byte (&(ieee
->h
)))
736 next_byte (&(ieee
->h
));
738 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
740 & ieee
->external_symbol_max_index
, 'I');
744 symbol
->symbol
.the_bfd
= abfd
;
745 symbol
->symbol
.name
= read_id (&(ieee
->h
));
746 symbol
->symbol
.udata
.p
= NULL
;
747 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
749 case ieee_external_symbol_enum
:
750 next_byte (&(ieee
->h
));
752 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
754 &ieee
->external_symbol_max_index
, 'D');
758 BFD_ASSERT (symbol
->index
>= ieee
->external_symbol_min_index
);
760 symbol
->symbol
.the_bfd
= abfd
;
761 symbol
->symbol
.name
= read_id (&(ieee
->h
));
762 symbol
->symbol
.udata
.p
= NULL
;
763 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
765 case ieee_attribute_record_enum
>> 8:
767 unsigned int symbol_name_index
;
768 unsigned int symbol_type_index
;
769 unsigned int symbol_attribute_def
;
772 switch (read_2bytes (&ieee
->h
))
774 case ieee_attribute_record_enum
:
775 symbol_name_index
= must_parse_int (&(ieee
->h
));
776 symbol_type_index
= must_parse_int (&(ieee
->h
));
777 symbol_attribute_def
= must_parse_int (&(ieee
->h
));
778 switch (symbol_attribute_def
)
782 parse_int (&ieee
->h
, &value
);
785 (*_bfd_error_handler
)
786 (_("%B: unimplemented ATI record %u for symbol %u"),
787 abfd
, symbol_attribute_def
, symbol_name_index
);
788 bfd_set_error (bfd_error_bad_value
);
793 case ieee_external_reference_info_record_enum
:
794 /* Skip over ATX record. */
795 parse_int (&(ieee
->h
), &value
);
796 parse_int (&(ieee
->h
), &value
);
797 parse_int (&(ieee
->h
), &value
);
798 parse_int (&(ieee
->h
), &value
);
800 case ieee_atn_record_enum
:
801 /* We may get call optimization information here,
802 which we just ignore. The format is
803 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */
804 parse_int (&ieee
->h
, &value
);
805 parse_int (&ieee
->h
, &value
);
806 parse_int (&ieee
->h
, &value
);
809 (*_bfd_error_handler
)
810 (_("%B: unexpected ATN type %d in external part"),
812 bfd_set_error (bfd_error_bad_value
);
815 parse_int (&ieee
->h
, &value
);
816 parse_int (&ieee
->h
, &value
);
823 switch (read_2bytes (&ieee
->h
))
825 case ieee_asn_record_enum
:
826 parse_int (&ieee
->h
, &val1
);
827 parse_int (&ieee
->h
, &val1
);
831 (*_bfd_error_handler
)
832 (_("%B: unexpected type after ATN"), abfd
);
833 bfd_set_error (bfd_error_bad_value
);
840 case ieee_value_record_enum
>> 8:
842 unsigned int symbol_name_index
;
843 ieee_symbol_index_type symbol_ignore
;
844 bfd_boolean pcrel_ignore
;
847 next_byte (&(ieee
->h
));
848 next_byte (&(ieee
->h
));
850 symbol_name_index
= must_parse_int (&(ieee
->h
));
851 parse_expression (ieee
,
852 &symbol
->symbol
.value
,
856 &symbol
->symbol
.section
);
858 /* Fully linked IEEE-695 files tend to give every symbol
859 an absolute value. Try to convert that back into a
860 section relative value. FIXME: This won't always to
862 if (bfd_is_abs_section (symbol
->symbol
.section
)
863 && (abfd
->flags
& HAS_RELOC
) == 0)
868 val
= symbol
->symbol
.value
;
869 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
871 if (val
>= s
->vma
&& val
< s
->vma
+ s
->size
)
873 symbol
->symbol
.section
= s
;
874 symbol
->symbol
.value
-= s
->vma
;
880 symbol
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
;
884 case ieee_weak_external_reference_enum
:
889 next_byte (&(ieee
->h
));
890 /* Throw away the external reference index. */
891 (void) must_parse_int (&(ieee
->h
));
892 /* Fetch the default size if not resolved. */
893 size
= must_parse_int (&(ieee
->h
));
894 /* Fetch the default value if available. */
895 if (! parse_int (&(ieee
->h
), &value
))
897 /* This turns into a common. */
898 symbol
->symbol
.section
= bfd_com_section_ptr
;
899 symbol
->symbol
.value
= size
;
903 case ieee_external_reference_enum
:
904 next_byte (&(ieee
->h
));
906 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
908 &ieee
->external_reference_max_index
, 'X');
912 symbol
->symbol
.the_bfd
= abfd
;
913 symbol
->symbol
.name
= read_id (&(ieee
->h
));
914 symbol
->symbol
.udata
.p
= NULL
;
915 symbol
->symbol
.section
= bfd_und_section_ptr
;
916 symbol
->symbol
.value
= (bfd_vma
) 0;
917 symbol
->symbol
.flags
= 0;
919 BFD_ASSERT (symbol
->index
>= ieee
->external_reference_min_index
);
927 if (ieee
->external_symbol_max_index
!= 0)
929 ieee
->external_symbol_count
=
930 ieee
->external_symbol_max_index
-
931 ieee
->external_symbol_min_index
+ 1;
934 ieee
->external_symbol_count
= 0;
936 if (ieee
->external_reference_max_index
!= 0)
938 ieee
->external_reference_count
=
939 ieee
->external_reference_max_index
-
940 ieee
->external_reference_min_index
+ 1;
943 ieee
->external_reference_count
= 0;
946 ieee
->external_reference_count
+ ieee
->external_symbol_count
;
948 if (symbol_count
!= abfd
->symcount
)
949 /* There are gaps in the table -- */
950 ieee
->symbol_table_full
= FALSE
;
952 *prev_symbols_ptr
= NULL
;
953 *prev_reference_ptr
= NULL
;
959 ieee_slurp_symbol_table (bfd
*abfd
)
961 if (! IEEE_DATA (abfd
)->read_symbols
)
963 if (! ieee_slurp_external_symbols (abfd
))
965 IEEE_DATA (abfd
)->read_symbols
= TRUE
;
971 ieee_get_symtab_upper_bound (bfd
*abfd
)
973 if (! ieee_slurp_symbol_table (abfd
))
976 return (abfd
->symcount
!= 0) ?
977 (abfd
->symcount
+ 1) * (sizeof (ieee_symbol_type
*)) : 0;
980 /* Move from our internal lists to the canon table, and insert in
981 symbol index order. */
983 extern const bfd_target ieee_vec
;
986 ieee_canonicalize_symtab (bfd
*abfd
, asymbol
**location
)
988 ieee_symbol_type
*symp
;
989 static bfd dummy_bfd
;
990 static asymbol empty_symbol
=
998 /* K&R compilers can't initialise unions. */
1005 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1007 dummy_bfd
.xvec
= &ieee_vec
;
1008 if (! ieee_slurp_symbol_table (abfd
))
1011 if (! ieee
->symbol_table_full
)
1013 /* Arrgh - there are gaps in the table, run through and fill them
1014 up with pointers to a null place. */
1017 for (i
= 0; i
< abfd
->symcount
; i
++)
1018 location
[i
] = &empty_symbol
;
1021 ieee
->external_symbol_base_offset
= -ieee
->external_symbol_min_index
;
1022 for (symp
= IEEE_DATA (abfd
)->external_symbols
;
1023 symp
!= (ieee_symbol_type
*) NULL
;
1025 /* Place into table at correct index locations. */
1026 location
[symp
->index
+ ieee
->external_symbol_base_offset
] = &symp
->symbol
;
1028 /* The external refs are indexed in a bit. */
1029 ieee
->external_reference_base_offset
=
1030 -ieee
->external_reference_min_index
+ ieee
->external_symbol_count
;
1032 for (symp
= IEEE_DATA (abfd
)->external_reference
;
1033 symp
!= (ieee_symbol_type
*) NULL
;
1035 location
[symp
->index
+ ieee
->external_reference_base_offset
] =
1040 location
[abfd
->symcount
] = (asymbol
*) NULL
;
1042 return abfd
->symcount
;
1046 get_section_entry (bfd
*abfd
, ieee_data_type
*ieee
, unsigned int index
)
1048 if (index
>= ieee
->section_table_size
)
1054 c
= ieee
->section_table_size
;
1061 amt
*= sizeof (asection
*);
1062 n
= bfd_realloc (ieee
->section_table
, amt
);
1066 for (i
= ieee
->section_table_size
; i
< c
; i
++)
1069 ieee
->section_table
= n
;
1070 ieee
->section_table_size
= c
;
1073 if (ieee
->section_table
[index
] == (asection
*) NULL
)
1075 char *tmp
= bfd_alloc (abfd
, (bfd_size_type
) 11);
1080 sprintf (tmp
, " fsec%4d", index
);
1081 section
= bfd_make_section (abfd
, tmp
);
1082 ieee
->section_table
[index
] = section
;
1083 section
->flags
= SEC_NO_FLAGS
;
1084 section
->target_index
= index
;
1085 ieee
->section_table
[index
] = section
;
1087 return ieee
->section_table
[index
];
1091 ieee_slurp_sections (bfd
*abfd
)
1093 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1094 file_ptr offset
= ieee
->w
.r
.section_part
;
1099 bfd_byte section_type
[3];
1101 ieee_seek (ieee
, offset
);
1104 switch (this_byte (&(ieee
->h
)))
1106 case ieee_section_type_enum
:
1109 unsigned int section_index
;
1111 next_byte (&(ieee
->h
));
1112 section_index
= must_parse_int (&(ieee
->h
));
1114 section
= get_section_entry (abfd
, ieee
, section_index
);
1116 section_type
[0] = this_byte_and_next (&(ieee
->h
));
1118 /* Set minimal section attributes. Attributes are
1119 extended later, based on section contents. */
1120 switch (section_type
[0])
1123 /* Normal attributes for absolute sections. */
1124 section_type
[1] = this_byte (&(ieee
->h
));
1125 section
->flags
= SEC_ALLOC
;
1126 switch (section_type
[1])
1128 /* AS Absolute section attributes. */
1130 next_byte (&(ieee
->h
));
1131 section_type
[2] = this_byte (&(ieee
->h
));
1132 switch (section_type
[2])
1136 next_byte (&(ieee
->h
));
1137 section
->flags
|= SEC_CODE
;
1141 next_byte (&(ieee
->h
));
1142 section
->flags
|= SEC_DATA
;
1145 next_byte (&(ieee
->h
));
1146 /* Normal rom data. */
1147 section
->flags
|= SEC_ROM
| SEC_DATA
;
1155 /* Named relocatable sections (type C). */
1157 section_type
[1] = this_byte (&(ieee
->h
));
1158 section
->flags
= SEC_ALLOC
;
1159 switch (section_type
[1])
1161 case 0xD0: /* Normal code (CP). */
1162 next_byte (&(ieee
->h
));
1163 section
->flags
|= SEC_CODE
;
1165 case 0xC4: /* Normal data (CD). */
1166 next_byte (&(ieee
->h
));
1167 section
->flags
|= SEC_DATA
;
1169 case 0xD2: /* Normal rom data (CR). */
1170 next_byte (&(ieee
->h
));
1171 section
->flags
|= SEC_ROM
| SEC_DATA
;
1178 /* Read section name, use it if non empty. */
1179 name
= read_id (&ieee
->h
);
1181 section
->name
= name
;
1183 /* Skip these fields, which we don't care about. */
1185 bfd_vma parent
, brother
, context
;
1187 parse_int (&(ieee
->h
), &parent
);
1188 parse_int (&(ieee
->h
), &brother
);
1189 parse_int (&(ieee
->h
), &context
);
1193 case ieee_section_alignment_enum
:
1195 unsigned int section_index
;
1199 next_byte (&(ieee
->h
));
1200 section_index
= must_parse_int (&ieee
->h
);
1201 section
= get_section_entry (abfd
, ieee
, section_index
);
1202 if (section_index
> ieee
->section_count
)
1203 ieee
->section_count
= section_index
;
1205 section
->alignment_power
=
1206 bfd_log2 (must_parse_int (&ieee
->h
));
1207 (void) parse_int (&(ieee
->h
), &value
);
1210 case ieee_e2_first_byte_enum
:
1213 ieee_record_enum_type t
;
1215 t
= (ieee_record_enum_type
) (read_2bytes (&(ieee
->h
)));
1218 case ieee_section_size_enum
:
1219 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1220 section
->size
= must_parse_int (&(ieee
->h
));
1222 case ieee_physical_region_size_enum
:
1223 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1224 section
->size
= must_parse_int (&(ieee
->h
));
1226 case ieee_region_base_address_enum
:
1227 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1228 section
->vma
= must_parse_int (&(ieee
->h
));
1229 section
->lma
= section
->vma
;
1231 case ieee_mau_size_enum
:
1232 must_parse_int (&(ieee
->h
));
1233 must_parse_int (&(ieee
->h
));
1235 case ieee_m_value_enum
:
1236 must_parse_int (&(ieee
->h
));
1237 must_parse_int (&(ieee
->h
));
1239 case ieee_section_base_address_enum
:
1240 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1241 section
->vma
= must_parse_int (&(ieee
->h
));
1242 section
->lma
= section
->vma
;
1244 case ieee_section_offset_enum
:
1245 (void) must_parse_int (&(ieee
->h
));
1246 (void) must_parse_int (&(ieee
->h
));
1260 /* Make a section for the debugging information, if any. We don't try
1261 to interpret the debugging information; we just point the section
1262 at the area in the file so that program which understand can dig it
1266 ieee_slurp_debug (bfd
*abfd
)
1268 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1272 if (ieee
->w
.r
.debug_information_part
== 0)
1275 sec
= bfd_make_section (abfd
, ".debug");
1278 sec
->flags
|= SEC_DEBUGGING
| SEC_HAS_CONTENTS
;
1279 sec
->filepos
= ieee
->w
.r
.debug_information_part
;
1281 debug_end
= ieee_part_after (ieee
, ieee
->w
.r
.debug_information_part
);
1282 sec
->size
= debug_end
- ieee
->w
.r
.debug_information_part
;
1287 /* Archive stuff. */
1289 static const bfd_target
*
1290 ieee_archive_p (bfd
*abfd
)
1294 unsigned char buffer
[512];
1295 file_ptr buffer_offset
= 0;
1296 ieee_ar_data_type
*save
= abfd
->tdata
.ieee_ar_data
;
1297 ieee_ar_data_type
*ieee
;
1298 bfd_size_type alc_elts
;
1299 ieee_ar_obstack_type
*elts
= NULL
;
1300 bfd_size_type amt
= sizeof (ieee_ar_data_type
);
1302 abfd
->tdata
.ieee_ar_data
= bfd_alloc (abfd
, amt
);
1303 if (!abfd
->tdata
.ieee_ar_data
)
1304 goto error_ret_restore
;
1305 ieee
= IEEE_AR_DATA (abfd
);
1307 /* Ignore the return value here. It doesn't matter if we don't read
1308 the entire buffer. We might have a very small ieee file. */
1309 bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
);
1311 ieee
->h
.first_byte
= buffer
;
1312 ieee
->h
.input_p
= buffer
;
1314 ieee
->h
.abfd
= abfd
;
1316 if (this_byte (&(ieee
->h
)) != Module_Beginning
)
1317 goto got_wrong_format_error
;
1319 next_byte (&(ieee
->h
));
1320 library
= read_id (&(ieee
->h
));
1321 if (strcmp (library
, "LIBRARY") != 0)
1322 goto got_wrong_format_error
;
1324 /* Throw away the filename. */
1325 read_id (&(ieee
->h
));
1327 ieee
->element_count
= 0;
1328 ieee
->element_index
= 0;
1330 next_byte (&(ieee
->h
)); /* Drop the ad part. */
1331 must_parse_int (&(ieee
->h
)); /* And the two dummy numbers. */
1332 must_parse_int (&(ieee
->h
));
1335 elts
= bfd_malloc (alc_elts
* sizeof *elts
);
1339 /* Read the index of the BB table. */
1343 ieee_ar_obstack_type
*t
;
1345 rec
= read_2bytes (&(ieee
->h
));
1346 if (rec
!= (int) ieee_assign_value_to_variable_enum
)
1349 if (ieee
->element_count
>= alc_elts
)
1351 ieee_ar_obstack_type
*n
;
1354 n
= bfd_realloc (elts
, alc_elts
* sizeof (* elts
));
1360 t
= &elts
[ieee
->element_count
];
1361 ieee
->element_count
++;
1363 must_parse_int (&(ieee
->h
));
1364 t
->file_offset
= must_parse_int (&(ieee
->h
));
1365 t
->abfd
= (bfd
*) NULL
;
1367 /* Make sure that we don't go over the end of the buffer. */
1368 if ((size_t) ieee_pos (IEEE_DATA (abfd
)) > sizeof (buffer
) / 2)
1370 /* Past half way, reseek and reprime. */
1371 buffer_offset
+= ieee_pos (IEEE_DATA (abfd
));
1372 if (bfd_seek (abfd
, buffer_offset
, SEEK_SET
) != 0)
1375 /* Again ignore return value of bfd_bread. */
1376 bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
);
1377 ieee
->h
.first_byte
= buffer
;
1378 ieee
->h
.input_p
= buffer
;
1382 amt
= ieee
->element_count
;
1383 amt
*= sizeof *ieee
->elements
;
1384 ieee
->elements
= bfd_alloc (abfd
, amt
);
1385 if (ieee
->elements
== NULL
)
1388 memcpy (ieee
->elements
, elts
, (size_t) amt
);
1392 /* Now scan the area again, and replace BB offsets with file offsets. */
1393 for (i
= 2; i
< ieee
->element_count
; i
++)
1395 if (bfd_seek (abfd
, ieee
->elements
[i
].file_offset
, SEEK_SET
) != 0)
1398 /* Again ignore return value of bfd_bread. */
1399 bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
);
1400 ieee
->h
.first_byte
= buffer
;
1401 ieee
->h
.input_p
= buffer
;
1403 next_byte (&(ieee
->h
)); /* Drop F8. */
1404 next_byte (&(ieee
->h
)); /* Drop 14. */
1405 must_parse_int (&(ieee
->h
)); /* Drop size of block. */
1407 if (must_parse_int (&(ieee
->h
)) != 0)
1408 /* This object has been deleted. */
1409 ieee
->elements
[i
].file_offset
= 0;
1411 ieee
->elements
[i
].file_offset
= must_parse_int (&(ieee
->h
));
1414 /* abfd->has_armap = ;*/
1418 got_wrong_format_error
:
1419 bfd_set_error (bfd_error_wrong_format
);
1423 bfd_release (abfd
, ieee
);
1425 abfd
->tdata
.ieee_ar_data
= save
;
1431 ieee_mkobject (bfd
*abfd
)
1435 output_ptr_start
= NULL
;
1437 output_ptr_end
= NULL
;
1438 input_ptr_start
= NULL
;
1440 input_ptr_end
= NULL
;
1444 amt
= sizeof (ieee_data_type
);
1445 abfd
->tdata
.ieee_data
= bfd_zalloc (abfd
, amt
);
1446 return abfd
->tdata
.ieee_data
!= NULL
;
1450 do_one (ieee_data_type
*ieee
,
1451 ieee_per_section_type
*current_map
,
1452 unsigned char *location_ptr
,
1456 switch (this_byte (&(ieee
->h
)))
1458 case ieee_load_constant_bytes_enum
:
1460 unsigned int number_of_maus
;
1463 next_byte (&(ieee
->h
));
1464 number_of_maus
= must_parse_int (&(ieee
->h
));
1466 for (i
= 0; i
< number_of_maus
; i
++)
1468 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1469 next_byte (&(ieee
->h
));
1474 case ieee_load_with_relocation_enum
:
1476 bfd_boolean loop
= TRUE
;
1478 next_byte (&(ieee
->h
));
1481 switch (this_byte (&(ieee
->h
)))
1483 case ieee_variable_R_enum
:
1485 case ieee_function_signed_open_b_enum
:
1486 case ieee_function_unsigned_open_b_enum
:
1487 case ieee_function_either_open_b_enum
:
1489 unsigned int extra
= 4;
1490 bfd_boolean pcrel
= FALSE
;
1494 r
= bfd_alloc (ieee
->h
.abfd
, sizeof (* r
));
1498 *(current_map
->reloc_tail_ptr
) = r
;
1499 current_map
->reloc_tail_ptr
= &r
->next
;
1500 r
->next
= (ieee_reloc_type
*) NULL
;
1501 next_byte (&(ieee
->h
));
1503 r
->relent
.sym_ptr_ptr
= 0;
1504 parse_expression (ieee
,
1507 &pcrel
, &extra
, §ion
);
1508 r
->relent
.address
= current_map
->pc
;
1509 s
->flags
|= SEC_RELOC
;
1510 s
->owner
->flags
|= HAS_RELOC
;
1512 if (r
->relent
.sym_ptr_ptr
== NULL
&& section
!= NULL
)
1513 r
->relent
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
1515 if (this_byte (&(ieee
->h
)) == (int) ieee_comma
)
1517 next_byte (&(ieee
->h
));
1518 /* Fetch number of bytes to pad. */
1519 extra
= must_parse_int (&(ieee
->h
));
1522 switch (this_byte (&(ieee
->h
)))
1524 case ieee_function_signed_close_b_enum
:
1525 next_byte (&(ieee
->h
));
1527 case ieee_function_unsigned_close_b_enum
:
1528 next_byte (&(ieee
->h
));
1530 case ieee_function_either_close_b_enum
:
1531 next_byte (&(ieee
->h
));
1536 /* Build a relocation entry for this type. */
1537 /* If pc rel then stick -ve pc into instruction
1538 and take out of reloc ..
1540 I've changed this. It's all too complicated. I
1541 keep 0 in the instruction now. */
1550 #if KEEPMINUSPCININST
1551 bfd_put_32 (ieee
->h
.abfd
, -current_map
->pc
,
1552 location_ptr
+ current_map
->pc
);
1553 r
->relent
.howto
= &rel32_howto
;
1554 r
->relent
.addend
-= current_map
->pc
;
1556 bfd_put_32 (ieee
->h
.abfd
, (bfd_vma
) 0, location_ptr
+
1558 r
->relent
.howto
= &rel32_howto
;
1563 bfd_put_32 (ieee
->h
.abfd
, (bfd_vma
) 0,
1564 location_ptr
+ current_map
->pc
);
1565 r
->relent
.howto
= &abs32_howto
;
1567 current_map
->pc
+= 4;
1572 #if KEEPMINUSPCININST
1573 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) -current_map
->pc
,
1574 location_ptr
+ current_map
->pc
);
1575 r
->relent
.addend
-= current_map
->pc
;
1576 r
->relent
.howto
= &rel16_howto
;
1579 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) 0,
1580 location_ptr
+ current_map
->pc
);
1581 r
->relent
.howto
= &rel16_howto
;
1587 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) 0,
1588 location_ptr
+ current_map
->pc
);
1589 r
->relent
.howto
= &abs16_howto
;
1591 current_map
->pc
+= 2;
1596 #if KEEPMINUSPCININST
1597 bfd_put_8 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1598 r
->relent
.addend
-= current_map
->pc
;
1599 r
->relent
.howto
= &rel8_howto
;
1601 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1602 r
->relent
.howto
= &rel8_howto
;
1607 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1608 r
->relent
.howto
= &abs8_howto
;
1610 current_map
->pc
+= 1;
1623 if (parse_int (&(ieee
->h
), &this_size
))
1627 for (i
= 0; i
< this_size
; i
++)
1629 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1630 next_byte (&(ieee
->h
));
1638 /* Prevent more than the first load-item of an LR record
1639 from being repeated (MRI convention). */
1640 if (iterations
!= 1)
1648 /* Read in all the section data and relocation stuff too. */
1651 ieee_slurp_section_data (bfd
*abfd
)
1653 bfd_byte
*location_ptr
= (bfd_byte
*) NULL
;
1654 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1655 unsigned int section_number
;
1656 ieee_per_section_type
*current_map
= NULL
;
1659 /* Seek to the start of the data area. */
1660 if (ieee
->read_data
)
1662 ieee
->read_data
= TRUE
;
1663 ieee_seek (ieee
, ieee
->w
.r
.data_part
);
1665 /* Allocate enough space for all the section contents. */
1666 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1668 ieee_per_section_type
*per
= ieee_per_section (s
);
1670 if ((s
->flags
& SEC_DEBUGGING
) != 0)
1672 per
->data
= bfd_alloc (ieee
->h
.abfd
, s
->size
);
1675 per
->reloc_tail_ptr
=
1676 (ieee_reloc_type
**) & (s
->relocation
);
1681 switch (this_byte (&(ieee
->h
)))
1683 /* IF we see anything strange then quit. */
1687 case ieee_set_current_section_enum
:
1688 next_byte (&(ieee
->h
));
1689 section_number
= must_parse_int (&(ieee
->h
));
1690 s
= ieee
->section_table
[section_number
];
1691 s
->flags
|= SEC_LOAD
| SEC_HAS_CONTENTS
;
1692 current_map
= ieee_per_section (s
);
1693 location_ptr
= current_map
->data
- s
->vma
;
1694 /* The document I have says that Microtec's compilers reset
1695 this after a sec section, even though the standard says not
1697 current_map
->pc
= s
->vma
;
1700 case ieee_e2_first_byte_enum
:
1701 next_byte (&(ieee
->h
));
1702 switch (this_byte (&(ieee
->h
)))
1704 case ieee_set_current_pc_enum
& 0xff:
1707 ieee_symbol_index_type symbol
;
1711 next_byte (&(ieee
->h
));
1712 must_parse_int (&(ieee
->h
)); /* Throw away section #. */
1713 parse_expression (ieee
, &value
,
1717 current_map
->pc
= value
;
1718 BFD_ASSERT ((unsigned) (value
- s
->vma
) <= s
->size
);
1722 case ieee_value_starting_address_enum
& 0xff:
1723 next_byte (&(ieee
->h
));
1724 if (this_byte (&(ieee
->h
)) == ieee_function_either_open_b_enum
)
1725 next_byte (&(ieee
->h
));
1726 abfd
->start_address
= must_parse_int (&(ieee
->h
));
1727 /* We've got to the end of the data now - */
1734 case ieee_repeat_data_enum
:
1736 /* Repeat the following LD or LR n times - we do this by
1737 remembering the stream pointer before running it and
1738 resetting it and running it n times. We special case
1739 the repetition of a repeat_data/load_constant. */
1740 unsigned int iterations
;
1741 unsigned char *start
;
1743 next_byte (&(ieee
->h
));
1744 iterations
= must_parse_int (&(ieee
->h
));
1745 start
= ieee
->h
.input_p
;
1746 if (start
[0] == (int) ieee_load_constant_bytes_enum
1749 while (iterations
!= 0)
1751 location_ptr
[current_map
->pc
++] = start
[2];
1754 next_byte (&(ieee
->h
));
1755 next_byte (&(ieee
->h
));
1756 next_byte (&(ieee
->h
));
1760 while (iterations
!= 0)
1762 ieee
->h
.input_p
= start
;
1763 if (!do_one (ieee
, current_map
, location_ptr
, s
,
1771 case ieee_load_constant_bytes_enum
:
1772 case ieee_load_with_relocation_enum
:
1773 if (!do_one (ieee
, current_map
, location_ptr
, s
, 1))
1779 static const bfd_target
*
1780 ieee_object_p (bfd
*abfd
)
1784 ieee_data_type
*ieee
;
1785 unsigned char buffer
[300];
1786 ieee_data_type
*save
= IEEE_DATA (abfd
);
1789 abfd
->tdata
.ieee_data
= 0;
1790 ieee_mkobject (abfd
);
1792 ieee
= IEEE_DATA (abfd
);
1793 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1795 /* Read the first few bytes in to see if it makes sense. Ignore
1796 bfd_bread return value; The file might be very small. */
1797 bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
);
1799 ieee
->h
.input_p
= buffer
;
1800 if (this_byte_and_next (&(ieee
->h
)) != Module_Beginning
)
1801 goto got_wrong_format
;
1803 ieee
->read_symbols
= FALSE
;
1804 ieee
->read_data
= FALSE
;
1805 ieee
->section_count
= 0;
1806 ieee
->external_symbol_max_index
= 0;
1807 ieee
->external_symbol_min_index
= IEEE_PUBLIC_BASE
;
1808 ieee
->external_reference_min_index
= IEEE_REFERENCE_BASE
;
1809 ieee
->external_reference_max_index
= 0;
1810 ieee
->h
.abfd
= abfd
;
1811 ieee
->section_table
= NULL
;
1812 ieee
->section_table_size
= 0;
1814 processor
= ieee
->mb
.processor
= read_id (&(ieee
->h
));
1815 if (strcmp (processor
, "LIBRARY") == 0)
1816 goto got_wrong_format
;
1817 ieee
->mb
.module_name
= read_id (&(ieee
->h
));
1818 if (abfd
->filename
== (const char *) NULL
)
1819 abfd
->filename
= ieee
->mb
.module_name
;
1821 /* Determine the architecture and machine type of the object file. */
1823 const bfd_arch_info_type
*arch
;
1826 /* IEEE does not specify the format of the processor identification
1827 string, so the compiler is free to put in it whatever it wants.
1828 We try here to recognize different processors belonging to the
1829 m68k family. Code for other processors can be added here. */
1830 if ((processor
[0] == '6') && (processor
[1] == '8'))
1832 if (processor
[2] == '3') /* 683xx integrated processors. */
1834 switch (processor
[3])
1836 case '0': /* 68302, 68306, 68307 */
1837 case '2': /* 68322, 68328 */
1838 case '5': /* 68356 */
1839 strcpy (family
, "68000"); /* MC68000-based controllers. */
1842 case '3': /* 68330, 68331, 68332, 68333,
1843 68334, 68335, 68336, 68338 */
1844 case '6': /* 68360 */
1845 case '7': /* 68376 */
1846 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1850 if (processor
[4] == '9') /* 68349 */
1851 strcpy (family
, "68030"); /* CPU030 */
1852 else /* 68340, 68341 */
1853 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1856 default: /* Does not exist yet. */
1857 strcpy (family
, "68332"); /* Guess it will be CPU32 */
1860 else if (TOUPPER (processor
[3]) == 'F') /* 68F333 */
1861 strcpy (family
, "68332"); /* CPU32 */
1862 else if ((TOUPPER (processor
[3]) == 'C') /* Embedded controllers. */
1863 && ((TOUPPER (processor
[2]) == 'E')
1864 || (TOUPPER (processor
[2]) == 'H')
1865 || (TOUPPER (processor
[2]) == 'L')))
1867 strcpy (family
, "68");
1868 strncat (family
, processor
+ 4, 7);
1871 else /* "Regular" processors. */
1873 strncpy (family
, processor
, 9);
1877 else if ((strncmp (processor
, "cpu32", 5) == 0) /* CPU32 and CPU32+ */
1878 || (strncmp (processor
, "CPU32", 5) == 0))
1879 strcpy (family
, "68332");
1882 strncpy (family
, processor
, 9);
1886 arch
= bfd_scan_arch (family
);
1888 goto got_wrong_format
;
1889 abfd
->arch_info
= arch
;
1892 if (this_byte (&(ieee
->h
)) != (int) ieee_address_descriptor_enum
)
1895 next_byte (&(ieee
->h
));
1897 if (! parse_int (&(ieee
->h
), &ieee
->ad
.number_of_bits_mau
))
1900 if (! parse_int (&(ieee
->h
), &ieee
->ad
.number_of_maus_in_address
))
1903 /* If there is a byte order info, take it. */
1904 if (this_byte (&(ieee
->h
)) == (int) ieee_variable_L_enum
1905 || this_byte (&(ieee
->h
)) == (int) ieee_variable_M_enum
)
1906 next_byte (&(ieee
->h
));
1908 for (part
= 0; part
< N_W_VARIABLES
; part
++)
1912 if (read_2bytes (&(ieee
->h
)) != (int) ieee_assign_value_to_variable_enum
)
1915 if (this_byte_and_next (&(ieee
->h
)) != part
)
1918 ieee
->w
.offset
[part
] = parse_i (&(ieee
->h
), &ok
);
1923 if (ieee
->w
.r
.external_part
!= 0)
1924 abfd
->flags
= HAS_SYMS
;
1926 /* By now we know that this is a real IEEE file, we're going to read
1927 the whole thing into memory so that we can run up and down it
1928 quickly. We can work out how big the file is from the trailer
1931 amt
= ieee
->w
.r
.me_record
+ 1;
1932 IEEE_DATA (abfd
)->h
.first_byte
= bfd_alloc (ieee
->h
.abfd
, amt
);
1933 if (!IEEE_DATA (abfd
)->h
.first_byte
)
1935 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1937 /* FIXME: Check return value. I'm not sure whether it needs to read
1938 the entire buffer or not. */
1939 bfd_bread ((void *) (IEEE_DATA (abfd
)->h
.first_byte
),
1940 (bfd_size_type
) ieee
->w
.r
.me_record
+ 1, abfd
);
1942 ieee_slurp_sections (abfd
);
1944 if (! ieee_slurp_debug (abfd
))
1947 /* Parse section data to activate file and section flags implied by
1948 section contents. */
1949 if (! ieee_slurp_section_data (abfd
))
1954 bfd_set_error (bfd_error_wrong_format
);
1956 bfd_release (abfd
, ieee
);
1957 abfd
->tdata
.ieee_data
= save
;
1958 return (const bfd_target
*) NULL
;
1962 ieee_get_symbol_info (bfd
*ignore_abfd ATTRIBUTE_UNUSED
,
1966 bfd_symbol_info (symbol
, ret
);
1967 if (symbol
->name
[0] == ' ')
1968 ret
->name
= "* empty table entry ";
1969 if (!symbol
->section
)
1970 ret
->type
= (symbol
->flags
& BSF_LOCAL
) ? 'a' : 'A';
1974 ieee_print_symbol (bfd
*abfd
,
1977 bfd_print_symbol_type how
)
1979 FILE *file
= (FILE *) afile
;
1983 case bfd_print_symbol_name
:
1984 fprintf (file
, "%s", symbol
->name
);
1986 case bfd_print_symbol_more
:
1989 case bfd_print_symbol_all
:
1991 const char *section_name
=
1992 (symbol
->section
== (asection
*) NULL
1994 : symbol
->section
->name
);
1996 if (symbol
->name
[0] == ' ')
1997 fprintf (file
, "* empty table entry ");
2000 bfd_print_symbol_vandf (abfd
, (void *) file
, symbol
);
2002 fprintf (file
, " %-5s %04x %02x %s",
2004 (unsigned) ieee_symbol (symbol
)->index
,
2014 ieee_new_section_hook (bfd
*abfd
, asection
*newsect
)
2016 newsect
->used_by_bfd
= bfd_alloc (abfd
, (bfd_size_type
) sizeof (ieee_per_section_type
));
2017 if (!newsect
->used_by_bfd
)
2019 ieee_per_section (newsect
)->data
= NULL
;
2020 ieee_per_section (newsect
)->section
= newsect
;
2025 ieee_get_reloc_upper_bound (bfd
*abfd
, sec_ptr asect
)
2027 if ((asect
->flags
& SEC_DEBUGGING
) != 0)
2029 if (! ieee_slurp_section_data (abfd
))
2031 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
2035 ieee_get_section_contents (bfd
*abfd
,
2039 bfd_size_type count
)
2041 ieee_per_section_type
*p
= ieee_per_section (section
);
2042 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2043 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2045 ieee_slurp_section_data (abfd
);
2046 (void) memcpy ((void *) location
, (void *) (p
->data
+ offset
), (unsigned) count
);
2051 ieee_canonicalize_reloc (bfd
*abfd
,
2056 ieee_reloc_type
*src
= (ieee_reloc_type
*) (section
->relocation
);
2057 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2059 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2062 while (src
!= (ieee_reloc_type
*) NULL
)
2064 /* Work out which symbol to attach it this reloc to. */
2065 switch (src
->symbol
.letter
)
2068 src
->relent
.sym_ptr_ptr
=
2069 symbols
+ src
->symbol
.index
+ ieee
->external_symbol_base_offset
;
2072 src
->relent
.sym_ptr_ptr
=
2073 symbols
+ src
->symbol
.index
+ ieee
->external_reference_base_offset
;
2076 if (src
->relent
.sym_ptr_ptr
!= NULL
)
2077 src
->relent
.sym_ptr_ptr
=
2078 src
->relent
.sym_ptr_ptr
[0]->section
->symbol_ptr_ptr
;
2084 *relptr
++ = &src
->relent
;
2088 return section
->reloc_count
;
2092 comp (const void * ap
, const void * bp
)
2094 arelent
*a
= *((arelent
**) ap
);
2095 arelent
*b
= *((arelent
**) bp
);
2096 return a
->address
- b
->address
;
2099 /* Write the section headers. */
2102 ieee_write_section_part (bfd
*abfd
)
2104 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2107 ieee
->w
.r
.section_part
= bfd_tell (abfd
);
2108 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
2110 if (! bfd_is_abs_section (s
)
2111 && (s
->flags
& SEC_DEBUGGING
) == 0)
2113 if (! ieee_write_byte (abfd
, ieee_section_type_enum
)
2114 || ! ieee_write_byte (abfd
,
2115 (bfd_byte
) (s
->index
2116 + IEEE_SECTION_NUMBER_BASE
)))
2119 if (abfd
->flags
& EXEC_P
)
2121 /* This image is executable, so output absolute sections. */
2122 if (! ieee_write_byte (abfd
, ieee_variable_A_enum
)
2123 || ! ieee_write_byte (abfd
, ieee_variable_S_enum
))
2128 if (! ieee_write_byte (abfd
, ieee_variable_C_enum
))
2132 switch (s
->flags
& (SEC_CODE
| SEC_DATA
| SEC_ROM
))
2134 case SEC_CODE
| SEC_LOAD
:
2136 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
))
2141 if (! ieee_write_byte (abfd
, ieee_variable_D_enum
))
2145 case SEC_ROM
| SEC_DATA
:
2146 case SEC_ROM
| SEC_LOAD
:
2147 case SEC_ROM
| SEC_DATA
| SEC_LOAD
:
2148 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
))
2153 if (! ieee_write_id (abfd
, s
->name
))
2156 if (! ieee_write_byte (abfd
, ieee_section_alignment_enum
)
2157 || ! ieee_write_byte (abfd
,
2158 (bfd_byte
) (s
->index
2159 + IEEE_SECTION_NUMBER_BASE
))
2160 || ! ieee_write_int (abfd
, (bfd_vma
) 1 << s
->alignment_power
))
2164 if (! ieee_write_2bytes (abfd
, ieee_section_size_enum
)
2165 || ! ieee_write_byte (abfd
,
2166 (bfd_byte
) (s
->index
2167 + IEEE_SECTION_NUMBER_BASE
))
2168 || ! ieee_write_int (abfd
, s
->size
))
2170 if (abfd
->flags
& EXEC_P
)
2172 /* Relocateable sections don't have asl records. */
2174 if (! ieee_write_2bytes (abfd
, ieee_section_base_address_enum
)
2175 || ! ieee_write_byte (abfd
,
2178 + IEEE_SECTION_NUMBER_BASE
)))
2179 || ! ieee_write_int (abfd
, s
->lma
))
2189 do_with_relocs (bfd
*abfd
, asection
*s
)
2191 unsigned int number_of_maus_in_address
=
2192 bfd_arch_bits_per_address (abfd
) / bfd_arch_bits_per_byte (abfd
);
2193 unsigned int relocs_to_go
= s
->reloc_count
;
2194 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2195 arelent
**p
= s
->orelocation
;
2196 bfd_size_type current_byte_index
= 0;
2198 qsort (s
->orelocation
,
2200 sizeof (arelent
**),
2203 /* Output the section preheader. */
2204 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2205 || ! ieee_write_byte (abfd
,
2206 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
))
2207 || ! ieee_write_2bytes (abfd
, ieee_set_current_pc_enum
)
2208 || ! ieee_write_byte (abfd
,
2209 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
)))
2212 if ((abfd
->flags
& EXEC_P
) != 0 && relocs_to_go
== 0)
2214 if (! ieee_write_int (abfd
, s
->lma
))
2219 if (! ieee_write_expression (abfd
, (bfd_vma
) 0, s
->symbol
, 0, 0))
2223 if (relocs_to_go
== 0)
2225 /* If there aren't any relocations then output the load constant
2226 byte opcode rather than the load with relocation opcode. */
2227 while (current_byte_index
< s
->size
)
2230 unsigned int MAXRUN
= 127;
2233 if (run
> s
->size
- current_byte_index
)
2234 run
= s
->size
- current_byte_index
;
2238 if (! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
))
2240 /* Output a stream of bytes. */
2241 if (! ieee_write_int (abfd
, run
))
2243 if (bfd_bwrite ((void *) (stream
+ current_byte_index
), run
, abfd
)
2246 current_byte_index
+= run
;
2252 if (! ieee_write_byte (abfd
, ieee_load_with_relocation_enum
))
2255 /* Output the data stream as the longest sequence of bytes
2256 possible, allowing for the a reasonable packet size and
2257 relocation stuffs. */
2260 /* Outputting a section without data, fill it up. */
2261 stream
= bfd_zalloc (abfd
, s
->size
);
2265 while (current_byte_index
< s
->size
)
2268 unsigned int MAXRUN
= 127;
2272 run
= (*p
)->address
- current_byte_index
;
2279 if (run
> s
->size
- current_byte_index
)
2280 run
= s
->size
- current_byte_index
;
2284 /* Output a stream of bytes. */
2285 if (! ieee_write_int (abfd
, run
))
2287 if (bfd_bwrite ((void *) (stream
+ current_byte_index
), run
, abfd
)
2290 current_byte_index
+= run
;
2293 /* Output any relocations here. */
2294 if (relocs_to_go
&& (*p
) && (*p
)->address
== current_byte_index
)
2297 && (*p
) && (*p
)->address
== current_byte_index
)
2301 switch (r
->howto
->size
)
2304 ov
= bfd_get_signed_32 (abfd
,
2305 stream
+ current_byte_index
);
2306 current_byte_index
+= 4;
2309 ov
= bfd_get_signed_16 (abfd
,
2310 stream
+ current_byte_index
);
2311 current_byte_index
+= 2;
2314 ov
= bfd_get_signed_8 (abfd
,
2315 stream
+ current_byte_index
);
2316 current_byte_index
++;
2324 ov
&= r
->howto
->src_mask
;
2326 if (r
->howto
->pc_relative
2327 && ! r
->howto
->pcrel_offset
)
2330 if (! ieee_write_byte (abfd
,
2331 ieee_function_either_open_b_enum
))
2334 if (r
->sym_ptr_ptr
!= (asymbol
**) NULL
)
2336 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2338 r
->howto
->pc_relative
,
2339 (unsigned) s
->index
))
2344 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2346 r
->howto
->pc_relative
,
2347 (unsigned) s
->index
))
2351 if (number_of_maus_in_address
2352 != bfd_get_reloc_size (r
->howto
))
2354 bfd_vma rsize
= bfd_get_reloc_size (r
->howto
);
2355 if (! ieee_write_int (abfd
, rsize
))
2358 if (! ieee_write_byte (abfd
,
2359 ieee_function_either_close_b_enum
))
2373 /* If there are no relocations in the output section then we can be
2374 clever about how we write. We block items up into a max of 127
2378 do_as_repeat (bfd
*abfd
, asection
*s
)
2382 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2383 || ! ieee_write_byte (abfd
,
2384 (bfd_byte
) (s
->index
2385 + IEEE_SECTION_NUMBER_BASE
))
2386 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
>> 8)
2387 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
& 0xff)
2388 || ! ieee_write_byte (abfd
,
2389 (bfd_byte
) (s
->index
2390 + IEEE_SECTION_NUMBER_BASE
)))
2393 if ((abfd
->flags
& EXEC_P
) != 0)
2395 if (! ieee_write_int (abfd
, s
->lma
))
2400 if (! ieee_write_expression (abfd
, (bfd_vma
) 0, s
->symbol
, 0, 0))
2404 if (! ieee_write_byte (abfd
, ieee_repeat_data_enum
)
2405 || ! ieee_write_int (abfd
, s
->size
)
2406 || ! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
)
2407 || ! ieee_write_byte (abfd
, 1)
2408 || ! ieee_write_byte (abfd
, 0))
2416 do_without_relocs (bfd
*abfd
, asection
*s
)
2418 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2420 if (stream
== 0 || ((s
->flags
& SEC_LOAD
) == 0))
2422 if (! do_as_repeat (abfd
, s
))
2429 for (i
= 0; i
< s
->size
; i
++)
2433 if (! do_with_relocs (abfd
, s
))
2438 if (! do_as_repeat (abfd
, s
))
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))
2525 copy_expression (void)
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. */
2626 fill_int (struct output_buffer_struct
*buf
)
2628 if (buf
->buffer
== output_buffer
)
2630 /* Still a chance to output the size. */
2631 int value
= output_ptr
- buf
->ptrp
+ 3;
2632 buf
->ptrp
[0] = value
>> 24;
2633 buf
->ptrp
[1] = value
>> 16;
2634 buf
->ptrp
[2] = value
>> 8;
2635 buf
->ptrp
[3] = value
>> 0;
2640 drop_int (struct output_buffer_struct
*buf
)
2667 buf
->ptrp
= output_ptr
;
2668 buf
->buffer
= output_buffer
;
2708 #define ID copy_id ()
2709 #define INT copy_int ()
2710 #define EXP copy_expression ()
2711 #define INTn(q) copy_int ()
2712 #define EXPn(q) copy_expression ()
2715 copy_till_end (void)
2791 EXPn (instruction address
);
2825 EXPn (external function
);
2835 INTn (locked
register);
2857 /* Attribute record. */
2887 /* Unique typedefs for module. */
2888 /* GLobal typedefs. */
2889 /* High level module scope beginning. */
2891 struct output_buffer_struct ob
;
2907 /* Global function. */
2909 struct output_buffer_struct ob
;
2924 EXPn (size of block
);
2930 /* File name for source line numbers. */
2932 struct output_buffer_struct ob
;
2953 /* Local function. */
2955 struct output_buffer_struct ob
;
2974 /* Assembler module scope beginning - */
2976 struct output_buffer_struct ob
;
3002 struct output_buffer_struct ob
;
3010 INTn (section index
);
3018 EXPn (Size in Maus
);
3071 /* Moves all the debug information from the source bfd to the output
3072 bfd, and relocates any expressions it finds. */
3075 relocate_debug (bfd
*output ATTRIBUTE_UNUSED
,
3080 unsigned char input_buffer
[IBS
];
3082 input_ptr_start
= input_ptr
= input_buffer
;
3083 input_ptr_end
= input_buffer
+ IBS
;
3085 /* FIXME: Check return value. I'm not sure whether it needs to read
3086 the entire buffer or not. */
3087 bfd_bread ((void *) input_ptr_start
, (bfd_size_type
) IBS
, input
);
3091 /* Gather together all the debug information from each input BFD into
3092 one place, relocating it and emitting it as we go. */
3095 ieee_write_debug_part (bfd
*abfd
)
3097 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3098 bfd_chain_type
*chain
= ieee
->chain_root
;
3099 unsigned char obuff
[OBS
];
3100 bfd_boolean some_debug
= FALSE
;
3101 file_ptr here
= bfd_tell (abfd
);
3103 output_ptr_start
= output_ptr
= obuff
;
3104 output_ptr_end
= obuff
+ OBS
;
3108 if (chain
== (bfd_chain_type
*) NULL
)
3112 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3113 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3117 ieee
->w
.r
.debug_information_part
= 0;
3121 ieee
->w
.r
.debug_information_part
= here
;
3122 if (bfd_bwrite (s
->contents
, s
->size
, abfd
) != s
->size
)
3127 while (chain
!= (bfd_chain_type
*) NULL
)
3129 bfd
*entry
= chain
->this;
3130 ieee_data_type
*entry_ieee
= IEEE_DATA (entry
);
3132 if (entry_ieee
->w
.r
.debug_information_part
)
3134 if (bfd_seek (entry
, entry_ieee
->w
.r
.debug_information_part
,
3137 relocate_debug (abfd
, entry
);
3140 chain
= chain
->next
;
3144 ieee
->w
.r
.debug_information_part
= here
;
3146 ieee
->w
.r
.debug_information_part
= 0;
3154 /* Write the data in an ieee way. */
3157 ieee_write_data_part (bfd
*abfd
)
3161 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3162 ieee
->w
.r
.data_part
= bfd_tell (abfd
);
3164 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3166 /* Skip sections that have no loadable contents (.bss,
3168 if ((s
->flags
& SEC_LOAD
) == 0)
3171 /* Sort the reloc records so we can insert them in the correct
3173 if (s
->reloc_count
!= 0)
3175 if (! do_with_relocs (abfd
, s
))
3180 if (! do_without_relocs (abfd
, s
))
3189 init_for_output (bfd
*abfd
)
3193 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3195 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3199 bfd_size_type size
= s
->size
;
3200 ieee_per_section (s
)->data
= bfd_alloc (abfd
, size
);
3201 if (!ieee_per_section (s
)->data
)
3208 /* Exec and core file sections. */
3210 /* Set section contents is complicated with IEEE since the format is
3211 not a byte image, but a record stream. */
3214 ieee_set_section_contents (bfd
*abfd
,
3216 const void * location
,
3218 bfd_size_type count
)
3220 if ((section
->flags
& SEC_DEBUGGING
) != 0)
3222 if (section
->contents
== NULL
)
3224 bfd_size_type size
= section
->size
;
3225 section
->contents
= bfd_alloc (abfd
, size
);
3226 if (section
->contents
== NULL
)
3229 /* bfd_set_section_contents has already checked that everything
3231 memcpy (section
->contents
+ offset
, location
, (size_t) count
);
3235 if (ieee_per_section (section
)->data
== (bfd_byte
*) NULL
)
3237 if (!init_for_output (abfd
))
3240 memcpy ((void *) (ieee_per_section (section
)->data
+ offset
),
3242 (unsigned int) count
);
3246 /* Write the external symbols of a file. IEEE considers two sorts of
3247 external symbols, public, and referenced. It uses to internal
3248 forms to index them as well. When we write them out we turn their
3249 symbol values into indexes from the right base. */
3252 ieee_write_external_part (bfd
*abfd
)
3255 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3256 unsigned int reference_index
= IEEE_REFERENCE_BASE
;
3257 unsigned int public_index
= IEEE_PUBLIC_BASE
+ 2;
3258 file_ptr here
= bfd_tell (abfd
);
3259 bfd_boolean hadone
= FALSE
;
3261 if (abfd
->outsymbols
!= (asymbol
**) NULL
)
3264 for (q
= abfd
->outsymbols
; *q
!= (asymbol
*) NULL
; q
++)
3268 if (bfd_is_und_section (p
->section
))
3270 /* This must be a symbol reference. */
3271 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3272 || ! ieee_write_int (abfd
, (bfd_vma
) reference_index
)
3273 || ! ieee_write_id (abfd
, p
->name
))
3275 p
->value
= reference_index
;
3279 else if (bfd_is_com_section (p
->section
))
3281 /* This is a weak 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
)
3285 || ! ieee_write_byte (abfd
,
3286 ieee_weak_external_reference_enum
)
3287 || ! ieee_write_int (abfd
, (bfd_vma
) reference_index
)
3288 || ! ieee_write_int (abfd
, p
->value
))
3290 p
->value
= reference_index
;
3294 else if (p
->flags
& BSF_GLOBAL
)
3296 /* This must be a symbol definition. */
3297 if (! ieee_write_byte (abfd
, ieee_external_symbol_enum
)
3298 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
)
3299 || ! ieee_write_id (abfd
, p
->name
)
3300 || ! ieee_write_2bytes (abfd
, ieee_attribute_record_enum
)
3301 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
)
3302 || ! ieee_write_byte (abfd
, 15) /* Instruction address. */
3303 || ! ieee_write_byte (abfd
, 19) /* Static symbol. */
3304 || ! ieee_write_byte (abfd
, 1)) /* One of them. */
3307 /* Write out the value. */
3308 if (! ieee_write_2bytes (abfd
, ieee_value_record_enum
)
3309 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
))
3311 if (! bfd_is_abs_section (p
->section
))
3313 if (abfd
->flags
& EXEC_P
)
3315 /* If fully linked, then output all symbols
3317 if (! (ieee_write_int
3320 + p
->section
->output_offset
3321 + p
->section
->output_section
->vma
))))
3326 if (! (ieee_write_expression
3328 p
->value
+ p
->section
->output_offset
,
3329 p
->section
->output_section
->symbol
,
3336 if (! ieee_write_expression (abfd
,
3338 bfd_abs_section_ptr
->symbol
,
3342 p
->value
= public_index
;
3348 /* This can happen - when there are gaps in the symbols read
3349 from an input ieee file. */
3354 ieee
->w
.r
.external_part
= here
;
3360 static const unsigned char exten
[] =
3363 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3364 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
3365 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
3368 static const unsigned char envi
[] =
3372 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3375 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */
3377 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */
3378 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3382 ieee_write_me_part (bfd
*abfd
)
3384 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3385 ieee
->w
.r
.trailer_part
= bfd_tell (abfd
);
3386 if (abfd
->start_address
)
3388 if (! ieee_write_2bytes (abfd
, ieee_value_starting_address_enum
)
3389 || ! ieee_write_byte (abfd
, ieee_function_either_open_b_enum
)
3390 || ! ieee_write_int (abfd
, abfd
->start_address
)
3391 || ! ieee_write_byte (abfd
, ieee_function_either_close_b_enum
))
3394 ieee
->w
.r
.me_record
= bfd_tell (abfd
);
3395 if (! ieee_write_byte (abfd
, ieee_module_end_enum
))
3400 /* Write out the IEEE processor ID. */
3403 ieee_write_processor (bfd
*abfd
)
3405 const bfd_arch_info_type
*arch
;
3407 arch
= bfd_get_arch_info (abfd
);
3411 if (! ieee_write_id (abfd
, bfd_printable_name (abfd
)))
3416 if (! ieee_write_id (abfd
, "29000"))
3420 case bfd_arch_h8300
:
3421 if (! ieee_write_id (abfd
, "H8/300"))
3425 case bfd_arch_h8500
:
3426 if (! ieee_write_id (abfd
, "H8/500"))
3434 case bfd_mach_i960_core
:
3435 case bfd_mach_i960_ka_sa
:
3436 if (! ieee_write_id (abfd
, "80960KA"))
3440 case bfd_mach_i960_kb_sb
:
3441 if (! ieee_write_id (abfd
, "80960KB"))
3445 case bfd_mach_i960_ca
:
3446 if (! ieee_write_id (abfd
, "80960CA"))
3450 case bfd_mach_i960_mc
:
3451 case bfd_mach_i960_xa
:
3452 if (! ieee_write_id (abfd
, "80960MC"))
3464 default: id
= "68020"; break;
3465 case bfd_mach_m68000
: id
= "68000"; break;
3466 case bfd_mach_m68008
: id
= "68008"; break;
3467 case bfd_mach_m68010
: id
= "68010"; break;
3468 case bfd_mach_m68020
: id
= "68020"; break;
3469 case bfd_mach_m68030
: id
= "68030"; break;
3470 case bfd_mach_m68040
: id
= "68040"; break;
3471 case bfd_mach_m68060
: id
= "68060"; break;
3472 case bfd_mach_cpu32
: id
= "cpu32"; break;
3473 case bfd_mach_mcf5200
:id
= "5200"; break;
3474 case bfd_mach_mcf5206e
:id
= "5206e"; break;
3475 case bfd_mach_mcf5307
:id
= "5307"; break;
3476 case bfd_mach_mcf5407
:id
= "5407"; break;
3477 case bfd_mach_mcf528x
:id
= "5282"; break;
3480 if (! ieee_write_id (abfd
, id
))
3490 ieee_write_object_contents (bfd
*abfd
)
3492 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3496 /* Fast forward over the header area. */
3497 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3500 if (! ieee_write_byte (abfd
, ieee_module_beginning_enum
)
3501 || ! ieee_write_processor (abfd
)
3502 || ! ieee_write_id (abfd
, abfd
->filename
))
3505 /* Fast forward over the variable bits. */
3506 if (! ieee_write_byte (abfd
, ieee_address_descriptor_enum
))
3510 if (! ieee_write_byte (abfd
, (bfd_byte
) (bfd_arch_bits_per_byte (abfd
))))
3512 /* MAU's per address. */
3513 if (! ieee_write_byte (abfd
,
3514 (bfd_byte
) (bfd_arch_bits_per_address (abfd
)
3515 / bfd_arch_bits_per_byte (abfd
))))
3518 old
= bfd_tell (abfd
);
3519 if (bfd_seek (abfd
, (file_ptr
) (8 * N_W_VARIABLES
), SEEK_CUR
) != 0)
3522 ieee
->w
.r
.extension_record
= bfd_tell (abfd
);
3523 if (bfd_bwrite ((char *) exten
, (bfd_size_type
) sizeof (exten
), abfd
)
3526 if (abfd
->flags
& EXEC_P
)
3528 if (! ieee_write_byte (abfd
, 0x1)) /* Absolute. */
3533 if (! ieee_write_byte (abfd
, 0x2)) /* Relocateable. */
3537 ieee
->w
.r
.environmental_record
= bfd_tell (abfd
);
3538 if (bfd_bwrite ((char *) envi
, (bfd_size_type
) sizeof (envi
), abfd
)
3542 /* The HP emulator database requires a timestamp in the file. */
3548 t
= (struct tm
*) localtime (&now
);
3549 if (! ieee_write_2bytes (abfd
, (int) ieee_atn_record_enum
)
3550 || ! ieee_write_byte (abfd
, 0x21)
3551 || ! ieee_write_byte (abfd
, 0)
3552 || ! ieee_write_byte (abfd
, 50)
3553 || ! ieee_write_int (abfd
, (bfd_vma
) (t
->tm_year
+ 1900))
3554 || ! ieee_write_int (abfd
, (bfd_vma
) (t
->tm_mon
+ 1))
3555 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_mday
)
3556 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_hour
)
3557 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_min
)
3558 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_sec
))
3566 if (! ieee_write_section_part (abfd
))
3568 /* First write the symbols. This changes their values into table
3569 indeces so we cant use it after this point. */
3570 if (! ieee_write_external_part (abfd
))
3573 /* Write any debugs we have been told about. */
3574 if (! ieee_write_debug_part (abfd
))
3577 /* Can only write the data once the symbols have been written, since
3578 the data contains relocation information which points to the
3580 if (! ieee_write_data_part (abfd
))
3583 /* At the end we put the end! */
3584 if (! ieee_write_me_part (abfd
))
3587 /* Generate the header. */
3588 if (bfd_seek (abfd
, old
, SEEK_SET
) != 0)
3591 for (i
= 0; i
< N_W_VARIABLES
; i
++)
3593 if (! ieee_write_2bytes (abfd
, ieee_assign_value_to_variable_enum
)
3594 || ! ieee_write_byte (abfd
, (bfd_byte
) i
)
3595 || ! ieee_write_int5_out (abfd
, (bfd_vma
) ieee
->w
.offset
[i
]))
3602 /* Native-level interface to symbols. */
3604 /* We read the symbols into a buffer, which is discarded when this
3605 function exits. We read the strings into a buffer large enough to
3606 hold them all plus all the cached symbol entries. */
3609 ieee_make_empty_symbol (bfd
*abfd
)
3611 bfd_size_type amt
= sizeof (ieee_symbol_type
);
3612 ieee_symbol_type
*new = bfd_zalloc (abfd
, amt
);
3616 new->symbol
.the_bfd
= abfd
;
3617 return &new->symbol
;
3621 ieee_openr_next_archived_file (bfd
*arch
, bfd
*prev
)
3623 ieee_ar_data_type
*ar
= IEEE_AR_DATA (arch
);
3625 /* Take the next one from the arch state, or reset. */
3626 if (prev
== (bfd
*) NULL
)
3627 /* Reset the index - the first two entries are bogus. */
3628 ar
->element_index
= 2;
3632 ieee_ar_obstack_type
*p
= ar
->elements
+ ar
->element_index
;
3634 ar
->element_index
++;
3635 if (ar
->element_index
<= ar
->element_count
)
3637 if (p
->file_offset
!= (file_ptr
) 0)
3639 if (p
->abfd
== (bfd
*) NULL
)
3641 p
->abfd
= _bfd_create_empty_archive_element_shell (arch
);
3642 p
->abfd
->origin
= p
->file_offset
;
3649 bfd_set_error (bfd_error_no_more_archived_files
);
3656 ieee_find_nearest_line (bfd
*abfd ATTRIBUTE_UNUSED
,
3657 asection
*section ATTRIBUTE_UNUSED
,
3658 asymbol
**symbols ATTRIBUTE_UNUSED
,
3659 bfd_vma offset ATTRIBUTE_UNUSED
,
3660 const char **filename_ptr ATTRIBUTE_UNUSED
,
3661 const char **functionname_ptr ATTRIBUTE_UNUSED
,
3662 unsigned int *line_ptr ATTRIBUTE_UNUSED
)
3668 ieee_generic_stat_arch_elt (bfd
*abfd
, struct stat
*buf
)
3670 ieee_ar_data_type
*ar
= (ieee_ar_data_type
*) NULL
;
3671 ieee_data_type
*ieee
;
3673 if (abfd
->my_archive
!= NULL
)
3674 ar
= abfd
->my_archive
->tdata
.ieee_ar_data
;
3675 if (ar
== (ieee_ar_data_type
*) NULL
)
3677 bfd_set_error (bfd_error_invalid_operation
);
3681 if (IEEE_DATA (abfd
) == NULL
)
3683 if (ieee_object_p (abfd
) == NULL
)
3685 bfd_set_error (bfd_error_wrong_format
);
3690 ieee
= IEEE_DATA (abfd
);
3692 buf
->st_size
= ieee
->w
.r
.me_record
+ 1;
3693 buf
->st_mode
= 0644;
3698 ieee_sizeof_headers (bfd
*abfd ATTRIBUTE_UNUSED
,
3699 bfd_boolean x ATTRIBUTE_UNUSED
)
3704 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3705 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3707 #define ieee_slurp_armap bfd_true
3708 #define ieee_slurp_extended_name_table bfd_true
3709 #define ieee_construct_extended_name_table \
3711 (bfd *, char **, bfd_size_type *, const char **)) \
3713 #define ieee_truncate_arname bfd_dont_truncate_arname
3714 #define ieee_write_armap \
3716 (bfd *, unsigned int, struct orl *, unsigned int, int)) \
3718 #define ieee_read_ar_hdr bfd_nullvoidptr
3719 #define ieee_update_armap_timestamp bfd_true
3720 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3722 #define ieee_bfd_is_target_special_symbol \
3723 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
3724 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3725 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3726 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3727 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3728 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3730 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3732 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3734 #define ieee_get_section_contents_in_window \
3735 _bfd_generic_get_section_contents_in_window
3736 #define ieee_bfd_get_relocated_section_contents \
3737 bfd_generic_get_relocated_section_contents
3738 #define ieee_bfd_relax_section bfd_generic_relax_section
3739 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3740 #define ieee_bfd_merge_sections bfd_generic_merge_sections
3741 #define ieee_bfd_is_group_section bfd_generic_is_group_section
3742 #define ieee_bfd_discard_group bfd_generic_discard_group
3743 #define ieee_section_already_linked \
3744 _bfd_generic_section_already_linked
3745 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3746 #define ieee_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
3747 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3748 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
3749 #define ieee_bfd_final_link _bfd_generic_final_link
3750 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3752 const bfd_target ieee_vec
=
3755 bfd_target_ieee_flavour
,
3756 BFD_ENDIAN_UNKNOWN
, /* Target byte order. */
3757 BFD_ENDIAN_UNKNOWN
, /* Target headers byte order. */
3758 (HAS_RELOC
| EXEC_P
| /* Object flags. */
3759 HAS_LINENO
| HAS_DEBUG
|
3760 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
3761 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
3762 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* Section flags. */
3763 '_', /* Leading underscore. */
3764 ' ', /* AR_pad_char. */
3765 16, /* AR_max_namelen. */
3766 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3767 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3768 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* Data. */
3769 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3770 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3771 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* Headers. */
3774 ieee_object_p
, /* bfd_check_format. */
3781 _bfd_generic_mkarchive
,
3786 ieee_write_object_contents
,
3787 _bfd_write_archive_contents
,
3791 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
3792 ieee_get_section_contents, ieee_get_section_contents_in_window. */
3793 BFD_JUMP_TABLE_GENERIC (ieee
),
3795 BFD_JUMP_TABLE_COPY (_bfd_generic
),
3796 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3798 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
3799 ieee_construct_extended_name_table, ieee_truncate_arname,
3800 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
3801 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
3802 ieee_update_armap_timestamp. */
3803 BFD_JUMP_TABLE_ARCHIVE (ieee
),
3805 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
3806 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
3807 ieee_bfd_is_local_label_name, ieee_get_lineno,
3808 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
3809 ieee_read_minisymbols, ieee_minisymbol_to_symbol. */
3810 BFD_JUMP_TABLE_SYMBOLS (ieee
),
3812 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
3813 ieee_bfd_reloc_type_lookup. */
3814 BFD_JUMP_TABLE_RELOCS (ieee
),
3816 /* ieee_set_arch_mach, ieee_set_section_contents. */
3817 BFD_JUMP_TABLE_WRITE (ieee
),
3819 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
3820 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
3821 _bfd_generic_link_hash_table_free,
3822 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
3823 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
3824 ieee_bfd_merge_sections. */
3825 BFD_JUMP_TABLE_LINK (ieee
),
3827 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),