1 /* BFD back-end for ieee-695 objects.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Written by Steve Chamberlain of Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #define KEEPMINUSPCININST 0
23 /* IEEE 695 format is a stream of records, which we parse using a simple one-
24 token (which is one byte in this lexicon) lookahead recursive decent
33 static boolean ieee_write_byte
PARAMS ((bfd
*, int));
34 static boolean ieee_write_2bytes
PARAMS ((bfd
*, int));
35 static boolean ieee_write_int
PARAMS ((bfd
*, bfd_vma
));
36 static boolean ieee_write_id
PARAMS ((bfd
*, const char *));
37 static boolean ieee_write_expression
38 PARAMS ((bfd
*, bfd_vma
, asymbol
*, boolean
, unsigned int));
39 static void ieee_write_int5
PARAMS ((bfd_byte
*, bfd_vma
));
40 static boolean ieee_write_int5_out
PARAMS ((bfd
*, bfd_vma
));
41 static boolean ieee_write_section_part
PARAMS ((bfd
*));
42 static boolean do_with_relocs
PARAMS ((bfd
*, asection
*));
43 static boolean do_as_repeat
PARAMS ((bfd
*, asection
*));
44 static boolean do_without_relocs
PARAMS ((bfd
*, asection
*));
45 static boolean ieee_write_external_part
PARAMS ((bfd
*));
46 static boolean ieee_write_data_part
PARAMS ((bfd
*));
47 static boolean ieee_write_debug_part
PARAMS ((bfd
*));
48 static boolean ieee_write_me_part
PARAMS ((bfd
*));
49 static boolean ieee_write_processor
PARAMS ((bfd
*));
51 static boolean ieee_slurp_debug
PARAMS ((bfd
*));
52 static boolean ieee_slurp_section_data
PARAMS ((bfd
*));
54 /* Functions for writing to ieee files in the strange way that the
58 ieee_write_byte (abfd
, barg
)
65 if (bfd_write ((PTR
) &byte
, 1, 1, abfd
) != 1)
71 ieee_write_2bytes (abfd
, bytes
)
77 buffer
[0] = bytes
>> 8;
78 buffer
[1] = bytes
& 0xff;
79 if (bfd_write ((PTR
) buffer
, 1, 2, abfd
) != 2)
85 ieee_write_int (abfd
, value
)
91 if (! ieee_write_byte (abfd
, (bfd_byte
) value
))
98 /* How many significant bytes ? */
99 /* FIXME FOR LONGER INTS */
100 if (value
& 0xff000000)
102 else if (value
& 0x00ff0000)
104 else if (value
& 0x0000ff00)
109 if (! ieee_write_byte (abfd
,
110 (bfd_byte
) ((int) ieee_number_repeat_start_enum
116 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 24)))
120 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 16)))
124 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 8)))
128 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
)))
137 ieee_write_id (abfd
, id
)
141 size_t length
= strlen (id
);
145 if (! ieee_write_byte (abfd
, (bfd_byte
) length
))
148 else if (length
< 255)
150 if (! ieee_write_byte (abfd
, ieee_extension_length_1_enum
)
151 || ! ieee_write_byte (abfd
, (bfd_byte
) length
))
154 else if (length
< 65535)
156 if (! ieee_write_byte (abfd
, ieee_extension_length_2_enum
)
157 || ! ieee_write_2bytes (abfd
, (int) length
))
162 (*_bfd_error_handler
)
163 ("%s: string too long (%d chars, max 65535)",
164 bfd_get_filename (abfd
), length
);
165 bfd_set_error (bfd_error_invalid_operation
);
169 if (bfd_write ((PTR
) id
, 1, length
, abfd
) != length
)
174 /***************************************************************************
175 Functions for reading from ieee files in the strange way that the
179 #define this_byte(ieee) *((ieee)->input_p)
180 #define next_byte(ieee) ((ieee)->input_p++)
181 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
183 static unsigned short
185 common_header_type
*ieee
;
187 unsigned char c1
= this_byte_and_next (ieee
);
188 unsigned char c2
= this_byte_and_next (ieee
);
189 return (c1
<< 8) | c2
;
193 bfd_get_string (ieee
, string
, length
)
194 common_header_type
*ieee
;
199 for (i
= 0; i
< length
; i
++)
201 string
[i
] = this_byte_and_next (ieee
);
207 common_header_type
*ieee
;
211 length
= this_byte_and_next (ieee
);
214 /* Simple string of length 0 to 127 */
216 else if (length
== 0xde)
218 /* Length is next byte, allowing 0..255 */
219 length
= this_byte_and_next (ieee
);
221 else if (length
== 0xdf)
223 /* Length is next two bytes, allowing 0..65535 */
224 length
= this_byte_and_next (ieee
);
225 length
= (length
* 256) + this_byte_and_next (ieee
);
227 /* Buy memory and read string */
228 string
= bfd_alloc (ieee
->abfd
, length
+ 1);
231 bfd_get_string (ieee
, string
, length
);
237 ieee_write_expression (abfd
, value
, symbol
, pcrel
, index
)
244 unsigned int term_count
= 0;
248 if (! ieee_write_int (abfd
, value
))
253 if (bfd_is_com_section (symbol
->section
)
254 || bfd_is_und_section (symbol
->section
))
256 /* Def of a common symbol */
257 if (! ieee_write_byte (abfd
, ieee_variable_X_enum
)
258 || ! ieee_write_int (abfd
, symbol
->value
))
262 else if (! bfd_is_abs_section (symbol
->section
))
264 /* Ref to defined symbol - */
266 if (symbol
->flags
& BSF_GLOBAL
)
268 if (! ieee_write_byte (abfd
, ieee_variable_I_enum
)
269 || ! ieee_write_int (abfd
, symbol
->value
))
273 else if (symbol
->flags
& (BSF_LOCAL
| BSF_SECTION_SYM
))
275 /* This is a reference to a defined local symbol. We can
276 easily do a local as a section+offset. */
277 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
)
278 || ! ieee_write_byte (abfd
,
279 (bfd_byte
) (symbol
->section
->index
280 + IEEE_SECTION_NUMBER_BASE
)))
283 if (symbol
->value
!= 0)
285 if (! ieee_write_int (abfd
, symbol
->value
))
292 (*_bfd_error_handler
)
293 ("%s: unrecognized symbol `%s' flags 0x%x",
294 bfd_get_filename (abfd
), bfd_asymbol_name (symbol
),
296 bfd_set_error (bfd_error_invalid_operation
);
303 /* subtract the pc from here by asking for PC of this section*/
304 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
)
305 || ! ieee_write_byte (abfd
,
306 (bfd_byte
) (index
+ IEEE_SECTION_NUMBER_BASE
))
307 || ! ieee_write_byte (abfd
, ieee_function_minus_enum
))
311 /* Handle the degenerate case of a 0 address. */
314 if (! ieee_write_int (abfd
, 0))
318 while (term_count
> 1)
320 if (! ieee_write_byte (abfd
, ieee_function_plus_enum
))
328 /*****************************************************************************/
331 writes any integer into the buffer supplied and always takes 5 bytes
334 ieee_write_int5 (buffer
, value
)
338 buffer
[0] = (bfd_byte
) ieee_number_repeat_4_enum
;
339 buffer
[1] = (value
>> 24) & 0xff;
340 buffer
[2] = (value
>> 16) & 0xff;
341 buffer
[3] = (value
>> 8) & 0xff;
342 buffer
[4] = (value
>> 0) & 0xff;
346 ieee_write_int5_out (abfd
, value
)
352 ieee_write_int5 (b
, value
);
353 if (bfd_write ((PTR
) b
, 1, 5, abfd
) != 5)
359 parse_int (ieee
, value_ptr
)
360 common_header_type
*ieee
;
363 int value
= this_byte (ieee
);
365 if (value
>= 0 && value
<= 127)
371 else if (value
>= 0x80 && value
<= 0x88)
373 unsigned int count
= value
& 0xf;
378 result
= (result
<< 8) | this_byte_and_next (ieee
);
389 common_header_type
*ieee
;
393 *ok
= parse_int (ieee
, &x
);
398 must_parse_int (ieee
)
399 common_header_type
*ieee
;
402 BFD_ASSERT (parse_int (ieee
, &result
) == true);
410 ieee_symbol_index_type symbol
;
414 #if KEEPMINUSPCININST
416 #define SRC_MASK(arg) arg
417 #define PCREL_OFFSET false
421 #define SRC_MASK(arg) 0
422 #define PCREL_OFFSET true
426 static reloc_howto_type abs32_howto
=
433 complain_overflow_bitfield
,
441 static reloc_howto_type abs16_howto
=
448 complain_overflow_bitfield
,
456 static reloc_howto_type abs8_howto
=
463 complain_overflow_bitfield
,
471 static reloc_howto_type rel32_howto
=
478 complain_overflow_signed
,
482 SRC_MASK (0xffffffff),
486 static reloc_howto_type rel16_howto
=
493 complain_overflow_signed
,
497 SRC_MASK (0x0000ffff),
501 static reloc_howto_type rel8_howto
=
508 complain_overflow_signed
,
512 SRC_MASK (0x000000ff),
516 static ieee_symbol_index_type NOSYMBOL
= {0, 0};
519 parse_expression (ieee
, value
, symbol
, pcrel
, extra
, section
)
520 ieee_data_type
*ieee
;
522 ieee_symbol_index_type
*symbol
;
535 ieee_value_type stack
[10];
537 /* The stack pointer always points to the next unused location */
538 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
539 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
540 ieee_value_type
*sp
= stack
;
544 switch (this_byte (&(ieee
->h
)))
546 case ieee_variable_P_enum
:
547 /* P variable, current program counter for section n */
550 next_byte (&(ieee
->h
));
552 section_n
= must_parse_int (&(ieee
->h
));
553 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, 0);
556 case ieee_variable_L_enum
:
557 /* L variable address of section N */
558 next_byte (&(ieee
->h
));
559 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
561 case ieee_variable_R_enum
:
562 /* R variable, logical address of section module */
563 /* FIXME, this should be different to L */
564 next_byte (&(ieee
->h
));
565 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
567 case ieee_variable_S_enum
:
568 /* S variable, size in MAUS of section module */
569 next_byte (&(ieee
->h
));
572 ieee
->section_table
[must_parse_int (&(ieee
->h
))]->_raw_size
);
574 case ieee_variable_I_enum
:
575 /* Push the address of variable n */
577 ieee_symbol_index_type sy
;
578 next_byte (&(ieee
->h
));
579 sy
.index
= (int) must_parse_int (&(ieee
->h
));
582 PUSH (sy
, bfd_abs_section_ptr
, 0);
585 case ieee_variable_X_enum
:
586 /* Push the address of external variable n */
588 ieee_symbol_index_type sy
;
589 next_byte (&(ieee
->h
));
590 sy
.index
= (int) (must_parse_int (&(ieee
->h
)));
593 PUSH (sy
, bfd_und_section_ptr
, 0);
596 case ieee_function_minus_enum
:
598 bfd_vma value1
, value2
;
599 asection
*section1
, *section_dummy
;
600 ieee_symbol_index_type sy
;
601 next_byte (&(ieee
->h
));
603 POP (sy
, section1
, value1
);
604 POP (sy
, section_dummy
, value2
);
605 PUSH (sy
, section1
? section1
: section_dummy
, value2
- value1
);
608 case ieee_function_plus_enum
:
610 bfd_vma value1
, value2
;
613 ieee_symbol_index_type sy1
;
614 ieee_symbol_index_type sy2
;
615 next_byte (&(ieee
->h
));
617 POP (sy1
, section1
, value1
);
618 POP (sy2
, section2
, value2
);
619 PUSH (sy1
.letter
? sy1
: sy2
,
620 bfd_is_abs_section (section1
) ? section2
: section1
,
627 BFD_ASSERT (this_byte (&(ieee
->h
)) < (int) ieee_variable_A_enum
628 || this_byte (&(ieee
->h
)) > (int) ieee_variable_Z_enum
);
629 if (parse_int (&(ieee
->h
), &va
))
631 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, va
);
636 Thats all that we can understand. As far as I can see
637 there is a bug in the Microtec IEEE output which I'm
638 using to scan, whereby the comma operator is omitted
639 sometimes in an expression, giving expressions with too
640 many terms. We can tell if that's the case by ensuring
641 that sp == stack here. If not, then we've pushed
642 something too far, so we keep adding. */
644 while (sp
!= stack
+ 1)
647 ieee_symbol_index_type sy1
;
648 POP (sy1
, section1
, *extra
);
653 POP (*symbol
, dummy
, *value
);
666 #define ieee_seek(abfd, offset) \
667 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
669 #define ieee_pos(abfd) \
670 (IEEE_DATA(abfd)->h.input_p - IEEE_DATA(abfd)->h.first_byte)
672 static unsigned int last_index
;
673 static char last_type
; /* is the index for an X or a D */
675 static ieee_symbol_type
*
685 ieee_data_type
*ieee
;
686 ieee_symbol_type
*last_symbol
;
687 unsigned int *symbol_count
;
688 ieee_symbol_type
***pptr
;
689 unsigned int *max_index
;
693 /* Need a new symbol */
694 unsigned int new_index
= must_parse_int (&(ieee
->h
));
695 if (new_index
!= last_index
|| this_type
!= last_type
)
697 ieee_symbol_type
*new_symbol
= (ieee_symbol_type
*) bfd_alloc (ieee
->h
.abfd
,
698 sizeof (ieee_symbol_type
));
702 new_symbol
->index
= new_index
;
703 last_index
= new_index
;
706 *pptr
= &new_symbol
->next
;
707 if (new_index
> *max_index
)
709 *max_index
= new_index
;
711 last_type
= this_type
;
712 new_symbol
->symbol
.section
= bfd_abs_section_ptr
;
719 ieee_slurp_external_symbols (abfd
)
722 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
723 file_ptr offset
= ieee
->w
.r
.external_part
;
725 ieee_symbol_type
**prev_symbols_ptr
= &ieee
->external_symbols
;
726 ieee_symbol_type
**prev_reference_ptr
= &ieee
->external_reference
;
727 ieee_symbol_type
*symbol
= (ieee_symbol_type
*) NULL
;
728 unsigned int symbol_count
= 0;
730 last_index
= 0xffffff;
731 ieee
->symbol_table_full
= true;
733 ieee_seek (abfd
, offset
);
737 switch (this_byte (&(ieee
->h
)))
740 next_byte (&(ieee
->h
));
742 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
744 &ieee
->external_symbol_max_index
, 'I');
748 symbol
->symbol
.the_bfd
= abfd
;
749 symbol
->symbol
.name
= read_id (&(ieee
->h
));
750 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
751 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
753 case ieee_external_symbol_enum
:
754 next_byte (&(ieee
->h
));
756 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
758 &ieee
->external_symbol_max_index
, 'D');
762 BFD_ASSERT (symbol
->index
>= ieee
->external_symbol_min_index
);
764 symbol
->symbol
.the_bfd
= abfd
;
765 symbol
->symbol
.name
= read_id (&(ieee
->h
));
766 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
767 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
769 case ieee_attribute_record_enum
>> 8:
771 unsigned int symbol_name_index
;
772 unsigned int symbol_type_index
;
773 unsigned int symbol_attribute_def
;
775 switch (read_2bytes (ieee
))
777 case ieee_attribute_record_enum
:
778 symbol_name_index
= must_parse_int (&(ieee
->h
));
779 symbol_type_index
= must_parse_int (&(ieee
->h
));
780 symbol_attribute_def
= must_parse_int (&(ieee
->h
));
781 switch (symbol_attribute_def
)
785 parse_int (&ieee
->h
, &value
);
788 (*_bfd_error_handler
)
789 ("%s: unimplemented ATI record %u for symbol %u",
790 bfd_get_filename (abfd
), symbol_attribute_def
,
792 bfd_set_error (bfd_error_bad_value
);
797 case ieee_external_reference_info_record_enum
:
798 /* Skip over ATX record. */
799 parse_int (&(ieee
->h
), &value
);
800 parse_int (&(ieee
->h
), &value
);
801 parse_int (&(ieee
->h
), &value
);
802 parse_int (&(ieee
->h
), &value
);
807 case ieee_value_record_enum
>> 8:
809 unsigned int symbol_name_index
;
810 ieee_symbol_index_type symbol_ignore
;
811 boolean pcrel_ignore
;
813 next_byte (&(ieee
->h
));
814 next_byte (&(ieee
->h
));
816 symbol_name_index
= must_parse_int (&(ieee
->h
));
817 parse_expression (ieee
,
818 &symbol
->symbol
.value
,
822 &symbol
->symbol
.section
);
824 symbol
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
;
828 case ieee_weak_external_reference_enum
:
832 next_byte (&(ieee
->h
));
833 /* Throw away the external reference index */
834 (void) must_parse_int (&(ieee
->h
));
835 /* Fetch the default size if not resolved */
836 size
= must_parse_int (&(ieee
->h
));
837 /* Fetch the defautlt value if available */
838 if (parse_int (&(ieee
->h
), &value
) == false)
842 /* This turns into a common */
843 symbol
->symbol
.section
= bfd_com_section_ptr
;
844 symbol
->symbol
.value
= size
;
848 case ieee_external_reference_enum
:
849 next_byte (&(ieee
->h
));
851 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
853 &ieee
->external_reference_max_index
, 'X');
857 symbol
->symbol
.the_bfd
= abfd
;
858 symbol
->symbol
.name
= read_id (&(ieee
->h
));
859 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
860 symbol
->symbol
.section
= bfd_und_section_ptr
;
861 symbol
->symbol
.value
= (bfd_vma
) 0;
862 symbol
->symbol
.flags
= 0;
864 BFD_ASSERT (symbol
->index
>= ieee
->external_reference_min_index
);
872 if (ieee
->external_symbol_max_index
!= 0)
874 ieee
->external_symbol_count
=
875 ieee
->external_symbol_max_index
-
876 ieee
->external_symbol_min_index
+ 1;
880 ieee
->external_symbol_count
= 0;
883 if (ieee
->external_reference_max_index
!= 0)
885 ieee
->external_reference_count
=
886 ieee
->external_reference_max_index
-
887 ieee
->external_reference_min_index
+ 1;
891 ieee
->external_reference_count
= 0;
895 ieee
->external_reference_count
+ ieee
->external_symbol_count
;
897 if (symbol_count
!= abfd
->symcount
)
899 /* There are gaps in the table -- */
900 ieee
->symbol_table_full
= false;
903 *prev_symbols_ptr
= (ieee_symbol_type
*) NULL
;
904 *prev_reference_ptr
= (ieee_symbol_type
*) NULL
;
910 ieee_slurp_symbol_table (abfd
)
913 if (IEEE_DATA (abfd
)->read_symbols
== false)
915 if (! ieee_slurp_external_symbols (abfd
))
917 IEEE_DATA (abfd
)->read_symbols
= true;
923 ieee_get_symtab_upper_bound (abfd
)
926 if (! ieee_slurp_symbol_table (abfd
))
929 return (abfd
->symcount
!= 0) ?
930 (abfd
->symcount
+ 1) * (sizeof (ieee_symbol_type
*)) : 0;
934 Move from our internal lists to the canon table, and insert in
938 extern const bfd_target ieee_vec
;
941 ieee_get_symtab (abfd
, location
)
945 ieee_symbol_type
*symp
;
946 static bfd dummy_bfd
;
947 static asymbol empty_symbol
=
948 /* the_bfd, name, value, attr, section */
949 {&dummy_bfd
, " ieee empty", (symvalue
) 0, BSF_DEBUGGING
, bfd_abs_section_ptr
};
953 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
954 dummy_bfd
.xvec
= &ieee_vec
;
955 if (! ieee_slurp_symbol_table (abfd
))
958 if (ieee
->symbol_table_full
== false)
960 /* Arrgh - there are gaps in the table, run through and fill them */
961 /* up with pointers to a null place */
963 for (i
= 0; i
< abfd
->symcount
; i
++)
965 location
[i
] = &empty_symbol
;
969 ieee
->external_symbol_base_offset
= -ieee
->external_symbol_min_index
;
970 for (symp
= IEEE_DATA (abfd
)->external_symbols
;
971 symp
!= (ieee_symbol_type
*) NULL
;
974 /* Place into table at correct index locations */
975 location
[symp
->index
+ ieee
->external_symbol_base_offset
] = &symp
->symbol
;
978 /* The external refs are indexed in a bit */
979 ieee
->external_reference_base_offset
=
980 -ieee
->external_reference_min_index
+ ieee
->external_symbol_count
;
982 for (symp
= IEEE_DATA (abfd
)->external_reference
;
983 symp
!= (ieee_symbol_type
*) NULL
;
986 location
[symp
->index
+ ieee
->external_reference_base_offset
] =
993 location
[abfd
->symcount
] = (asymbol
*) NULL
;
995 return abfd
->symcount
;
999 get_section_entry (abfd
, ieee
, index
)
1001 ieee_data_type
*ieee
;
1004 if (index
>= ieee
->section_table_size
)
1009 c
= ieee
->section_table_size
;
1016 bfd_realloc (ieee
->section_table
, c
* sizeof (asection
*)));
1020 for (i
= ieee
->section_table_size
; i
< c
; i
++)
1023 ieee
->section_table
= n
;
1024 ieee
->section_table_size
= c
;
1027 if (ieee
->section_table
[index
] == (asection
*) NULL
)
1029 char *tmp
= bfd_alloc (abfd
, 11);
1034 sprintf (tmp
, " fsec%4d", index
);
1035 section
= bfd_make_section (abfd
, tmp
);
1036 ieee
->section_table
[index
] = section
;
1037 section
->flags
= SEC_NO_FLAGS
;
1038 section
->target_index
= index
;
1039 ieee
->section_table
[index
] = section
;
1041 return ieee
->section_table
[index
];
1045 ieee_slurp_sections (abfd
)
1048 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1049 file_ptr offset
= ieee
->w
.r
.section_part
;
1050 asection
*section
= (asection
*) NULL
;
1055 bfd_byte section_type
[3];
1056 ieee_seek (abfd
, offset
);
1059 switch (this_byte (&(ieee
->h
)))
1061 case ieee_section_type_enum
:
1063 unsigned int section_index
;
1064 next_byte (&(ieee
->h
));
1065 section_index
= must_parse_int (&(ieee
->h
));
1067 section
= get_section_entry (abfd
, ieee
, section_index
);
1069 section_type
[0] = this_byte_and_next (&(ieee
->h
));
1071 /* Set minimal section attributes. Attributes are
1072 extended later, based on section contents. */
1074 switch (section_type
[0])
1077 /* Normal attributes for absolute sections */
1078 section_type
[1] = this_byte (&(ieee
->h
));
1079 section
->flags
= SEC_ALLOC
;
1080 switch (section_type
[1])
1082 case 0xD3: /* AS Absolute section attributes */
1083 next_byte (&(ieee
->h
));
1084 section_type
[2] = this_byte (&(ieee
->h
));
1085 switch (section_type
[2])
1089 next_byte (&(ieee
->h
));
1090 section
->flags
|= SEC_CODE
;
1094 next_byte (&(ieee
->h
));
1095 section
->flags
|= SEC_DATA
;
1098 next_byte (&(ieee
->h
));
1099 /* Normal rom data */
1100 section
->flags
|= SEC_ROM
| SEC_DATA
;
1107 case 0xC3: /* Named relocatable sections (type C) */
1108 section_type
[1] = this_byte (&(ieee
->h
));
1109 section
->flags
= SEC_ALLOC
;
1110 switch (section_type
[1])
1112 case 0xD0: /* Normal code (CP) */
1113 next_byte (&(ieee
->h
));
1114 section
->flags
|= SEC_CODE
;
1116 case 0xC4: /* Normal data (CD) */
1117 next_byte (&(ieee
->h
));
1118 section
->flags
|= SEC_DATA
;
1120 case 0xD2: /* Normal rom data (CR) */
1121 next_byte (&(ieee
->h
));
1122 section
->flags
|= SEC_ROM
| SEC_DATA
;
1129 /* Read section name, use it if non empty. */
1130 name
= read_id (&ieee
->h
);
1132 section
->name
= name
;
1134 /* Skip these fields, which we don't care about */
1136 bfd_vma parent
, brother
, context
;
1137 parse_int (&(ieee
->h
), &parent
);
1138 parse_int (&(ieee
->h
), &brother
);
1139 parse_int (&(ieee
->h
), &context
);
1143 case ieee_section_alignment_enum
:
1145 unsigned int section_index
;
1148 next_byte (&(ieee
->h
));
1149 section_index
= must_parse_int (&ieee
->h
);
1150 section
= get_section_entry (abfd
, ieee
, section_index
);
1151 if (section_index
> ieee
->section_count
)
1153 ieee
->section_count
= section_index
;
1155 section
->alignment_power
=
1156 bfd_log2 (must_parse_int (&ieee
->h
));
1157 (void) parse_int (&(ieee
->h
), &value
);
1160 case ieee_e2_first_byte_enum
:
1162 ieee_record_enum_type t
= (ieee_record_enum_type
) (read_2bytes (&(ieee
->h
)));
1166 case ieee_section_size_enum
:
1167 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1168 section
->_raw_size
= must_parse_int (&(ieee
->h
));
1170 case ieee_physical_region_size_enum
:
1171 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1172 section
->_raw_size
= must_parse_int (&(ieee
->h
));
1174 case ieee_region_base_address_enum
:
1175 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1176 section
->vma
= must_parse_int (&(ieee
->h
));
1177 section
->lma
= section
->vma
;
1179 case ieee_mau_size_enum
:
1180 must_parse_int (&(ieee
->h
));
1181 must_parse_int (&(ieee
->h
));
1183 case ieee_m_value_enum
:
1184 must_parse_int (&(ieee
->h
));
1185 must_parse_int (&(ieee
->h
));
1187 case ieee_section_base_address_enum
:
1188 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1189 section
->vma
= must_parse_int (&(ieee
->h
));
1190 section
->lma
= section
->vma
;
1192 case ieee_section_offset_enum
:
1193 (void) must_parse_int (&(ieee
->h
));
1194 (void) must_parse_int (&(ieee
->h
));
1208 /* Make a section for the debugging information, if any. We don't try
1209 to interpret the debugging information; we just point the section
1210 at the area in the file so that program which understand can dig it
1214 ieee_slurp_debug (abfd
)
1217 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1220 if (ieee
->w
.r
.debug_information_part
== 0)
1223 sec
= bfd_make_section (abfd
, ".debug");
1226 sec
->flags
|= SEC_DEBUGGING
| SEC_HAS_CONTENTS
;
1227 sec
->filepos
= ieee
->w
.r
.debug_information_part
;
1228 sec
->_raw_size
= ieee
->w
.r
.data_part
- ieee
->w
.r
.debug_information_part
;
1233 /***********************************************************************
1238 ieee_archive_p (abfd
)
1244 unsigned char buffer
[512];
1245 file_ptr buffer_offset
= 0;
1246 ieee_ar_data_type
*save
= abfd
->tdata
.ieee_ar_data
;
1247 ieee_ar_data_type
*ieee
;
1248 abfd
->tdata
.ieee_ar_data
= (ieee_ar_data_type
*) bfd_alloc (abfd
, sizeof (ieee_ar_data_type
));
1249 if (!abfd
->tdata
.ieee_ar_data
)
1251 ieee
= IEEE_AR_DATA (abfd
);
1253 /* FIXME: Check return value. I'm not sure whether it needs to read
1254 the entire buffer or not. */
1255 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1257 ieee
->h
.first_byte
= buffer
;
1258 ieee
->h
.input_p
= buffer
;
1260 ieee
->h
.abfd
= abfd
;
1262 if (this_byte (&(ieee
->h
)) != Module_Beginning
)
1264 abfd
->tdata
.ieee_ar_data
= save
;
1265 return (const bfd_target
*) NULL
;
1268 next_byte (&(ieee
->h
));
1269 library
= read_id (&(ieee
->h
));
1270 if (strcmp (library
, "LIBRARY") != 0)
1272 bfd_release (abfd
, ieee
);
1273 abfd
->tdata
.ieee_ar_data
= save
;
1274 return (const bfd_target
*) NULL
;
1276 /* Throw away the filename */
1277 read_id (&(ieee
->h
));
1279 ieee
->element_count
= 0;
1280 ieee
->element_index
= 0;
1282 next_byte (&(ieee
->h
)); /* Drop the ad part */
1283 must_parse_int (&(ieee
->h
)); /* And the two dummy numbers */
1284 must_parse_int (&(ieee
->h
));
1287 /* Read the index of the BB table */
1290 ieee_ar_obstack_type t
;
1291 int rec
= read_2bytes (&(ieee
->h
));
1292 if (rec
== (int) ieee_assign_value_to_variable_enum
)
1294 must_parse_int (&(ieee
->h
));
1295 t
.file_offset
= must_parse_int (&(ieee
->h
));
1296 t
.abfd
= (bfd
*) NULL
;
1297 ieee
->element_count
++;
1299 bfd_alloc_grow (abfd
, (PTR
) &t
, sizeof t
);
1301 /* Make sure that we don't go over the end of the buffer */
1303 if ((size_t) ieee_pos (abfd
) > sizeof (buffer
) / 2)
1305 /* Past half way, reseek and reprime */
1306 buffer_offset
+= ieee_pos (abfd
);
1307 if (bfd_seek (abfd
, buffer_offset
, SEEK_SET
) != 0)
1309 /* FIXME: Check return value. I'm not sure whether it
1310 needs to read the entire buffer or not. */
1311 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1312 ieee
->h
.first_byte
= buffer
;
1313 ieee
->h
.input_p
= buffer
;
1320 ieee
->elements
= (ieee_ar_obstack_type
*) bfd_alloc_finish (abfd
);
1321 if (!ieee
->elements
)
1322 return (const bfd_target
*) NULL
;
1324 /* Now scan the area again, and replace BB offsets with file */
1327 for (i
= 2; i
< ieee
->element_count
; i
++)
1329 if (bfd_seek (abfd
, ieee
->elements
[i
].file_offset
, SEEK_SET
) != 0)
1331 /* FIXME: Check return value. I'm not sure whether it needs to
1332 read the entire buffer or not. */
1333 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1334 ieee
->h
.first_byte
= buffer
;
1335 ieee
->h
.input_p
= buffer
;
1337 next_byte (&(ieee
->h
)); /* Drop F8 */
1338 next_byte (&(ieee
->h
)); /* Drop 14 */
1339 must_parse_int (&(ieee
->h
)); /* Drop size of block */
1340 if (must_parse_int (&(ieee
->h
)) != 0)
1342 /* This object has been deleted */
1343 ieee
->elements
[i
].file_offset
= 0;
1347 ieee
->elements
[i
].file_offset
= must_parse_int (&(ieee
->h
));
1351 /* abfd->has_armap = ;*/
1356 ieee_mkobject (abfd
)
1359 abfd
->tdata
.ieee_data
= (ieee_data_type
*) bfd_zalloc (abfd
, sizeof (ieee_data_type
));
1360 return abfd
->tdata
.ieee_data
? true : false;
1364 ieee_object_p (abfd
)
1369 ieee_data_type
*ieee
;
1370 unsigned char buffer
[300];
1371 ieee_data_type
*save
= IEEE_DATA (abfd
);
1373 abfd
->tdata
.ieee_data
= 0;
1374 ieee_mkobject (abfd
);
1376 ieee
= IEEE_DATA (abfd
);
1377 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1379 /* Read the first few bytes in to see if it makes sense */
1380 /* FIXME: Check return value. I'm not sure whether it needs to read
1381 the entire buffer or not. */
1382 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1384 ieee
->h
.input_p
= buffer
;
1385 if (this_byte_and_next (&(ieee
->h
)) != Module_Beginning
)
1386 goto got_wrong_format
;
1388 ieee
->read_symbols
= false;
1389 ieee
->read_data
= false;
1390 ieee
->section_count
= 0;
1391 ieee
->external_symbol_max_index
= 0;
1392 ieee
->external_symbol_min_index
= IEEE_PUBLIC_BASE
;
1393 ieee
->external_reference_min_index
= IEEE_REFERENCE_BASE
;
1394 ieee
->external_reference_max_index
= 0;
1395 ieee
->h
.abfd
= abfd
;
1396 ieee
->section_table
= NULL
;
1397 ieee
->section_table_size
= 0;
1399 processor
= ieee
->mb
.processor
= read_id (&(ieee
->h
));
1400 if (strcmp (processor
, "LIBRARY") == 0)
1401 goto got_wrong_format
;
1402 ieee
->mb
.module_name
= read_id (&(ieee
->h
));
1403 if (abfd
->filename
== (CONST
char *) NULL
)
1405 abfd
->filename
= ieee
->mb
.module_name
;
1407 /* Determine the architecture and machine type of the object file.
1410 const bfd_arch_info_type
*arch
= bfd_scan_arch (processor
);
1412 goto got_wrong_format
;
1413 abfd
->arch_info
= arch
;
1416 if (this_byte (&(ieee
->h
)) != (int) ieee_address_descriptor_enum
)
1420 next_byte (&(ieee
->h
));
1422 if (parse_int (&(ieee
->h
), &ieee
->ad
.number_of_bits_mau
) == false)
1426 if (parse_int (&(ieee
->h
), &ieee
->ad
.number_of_maus_in_address
) == false)
1431 /* If there is a byte order info, take it */
1432 if (this_byte (&(ieee
->h
)) == (int) ieee_variable_L_enum
||
1433 this_byte (&(ieee
->h
)) == (int) ieee_variable_M_enum
)
1434 next_byte (&(ieee
->h
));
1436 for (part
= 0; part
< N_W_VARIABLES
; part
++)
1439 if (read_2bytes (&(ieee
->h
)) != (int) ieee_assign_value_to_variable_enum
)
1443 if (this_byte_and_next (&(ieee
->h
)) != part
)
1448 ieee
->w
.offset
[part
] = parse_i (&(ieee
->h
), &ok
);
1456 if (ieee
->w
.r
.external_part
!= 0)
1457 abfd
->flags
= HAS_SYMS
;
1459 /* By now we know that this is a real IEEE file, we're going to read
1460 the whole thing into memory so that we can run up and down it
1461 quickly. We can work out how big the file is from the trailer
1464 IEEE_DATA (abfd
)->h
.first_byte
=
1465 (unsigned char *) bfd_alloc (ieee
->h
.abfd
, ieee
->w
.r
.me_record
+ 1);
1466 if (!IEEE_DATA (abfd
)->h
.first_byte
)
1468 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1470 /* FIXME: Check return value. I'm not sure whether it needs to read
1471 the entire buffer or not. */
1472 bfd_read ((PTR
) (IEEE_DATA (abfd
)->h
.first_byte
), 1,
1473 ieee
->w
.r
.me_record
+ 1, abfd
);
1475 ieee_slurp_sections (abfd
);
1477 if (! ieee_slurp_debug (abfd
))
1480 /* Parse section data to activate file and section flags implied by
1481 section contents. */
1483 if (! ieee_slurp_section_data (abfd
))
1488 bfd_set_error (bfd_error_wrong_format
);
1490 (void) bfd_release (abfd
, ieee
);
1491 abfd
->tdata
.ieee_data
= save
;
1492 return (const bfd_target
*) NULL
;
1496 ieee_get_symbol_info (ignore_abfd
, symbol
, ret
)
1501 bfd_symbol_info (symbol
, ret
);
1502 if (symbol
->name
[0] == ' ')
1503 ret
->name
= "* empty table entry ";
1504 if (!symbol
->section
)
1505 ret
->type
= (symbol
->flags
& BSF_LOCAL
) ? 'a' : 'A';
1509 ieee_print_symbol (ignore_abfd
, afile
, symbol
, how
)
1513 bfd_print_symbol_type how
;
1515 FILE *file
= (FILE *) afile
;
1519 case bfd_print_symbol_name
:
1520 fprintf (file
, "%s", symbol
->name
);
1522 case bfd_print_symbol_more
:
1524 fprintf (file
, "%4x %2x", aout_symbol (symbol
)->desc
& 0xffff,
1525 aout_symbol (symbol
)->other
& 0xff);
1529 case bfd_print_symbol_all
:
1531 const char *section_name
=
1532 (symbol
->section
== (asection
*) NULL
1534 : symbol
->section
->name
);
1535 if (symbol
->name
[0] == ' ')
1537 fprintf (file
, "* empty table entry ");
1541 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
1543 fprintf (file
, " %-5s %04x %02x %s",
1545 (unsigned) ieee_symbol (symbol
)->index
,
1555 do_one (ieee
, current_map
, location_ptr
, s
, iterations
)
1556 ieee_data_type
*ieee
;
1557 ieee_per_section_type
*current_map
;
1558 unsigned char *location_ptr
;
1562 switch (this_byte (&(ieee
->h
)))
1564 case ieee_load_constant_bytes_enum
:
1566 unsigned int number_of_maus
;
1568 next_byte (&(ieee
->h
));
1569 number_of_maus
= must_parse_int (&(ieee
->h
));
1571 for (i
= 0; i
< number_of_maus
; i
++)
1573 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1574 next_byte (&(ieee
->h
));
1579 case ieee_load_with_relocation_enum
:
1581 boolean loop
= true;
1582 next_byte (&(ieee
->h
));
1585 switch (this_byte (&(ieee
->h
)))
1587 case ieee_variable_R_enum
:
1589 case ieee_function_signed_open_b_enum
:
1590 case ieee_function_unsigned_open_b_enum
:
1591 case ieee_function_either_open_b_enum
:
1593 unsigned int extra
= 4;
1594 boolean pcrel
= false;
1596 ieee_reloc_type
*r
=
1597 (ieee_reloc_type
*) bfd_alloc (ieee
->h
.abfd
,
1598 sizeof (ieee_reloc_type
));
1602 *(current_map
->reloc_tail_ptr
) = r
;
1603 current_map
->reloc_tail_ptr
= &r
->next
;
1604 r
->next
= (ieee_reloc_type
*) NULL
;
1605 next_byte (&(ieee
->h
));
1607 r
->relent
.sym_ptr_ptr
= 0;
1608 parse_expression (ieee
,
1611 &pcrel
, &extra
, §ion
);
1612 r
->relent
.address
= current_map
->pc
;
1613 s
->flags
|= SEC_RELOC
;
1614 s
->owner
->flags
|= HAS_RELOC
;
1616 if (r
->relent
.sym_ptr_ptr
== 0)
1618 r
->relent
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
1621 if (this_byte (&(ieee
->h
)) == (int) ieee_comma
)
1623 next_byte (&(ieee
->h
));
1624 /* Fetch number of bytes to pad */
1625 extra
= must_parse_int (&(ieee
->h
));
1628 switch (this_byte (&(ieee
->h
)))
1630 case ieee_function_signed_close_b_enum
:
1631 next_byte (&(ieee
->h
));
1633 case ieee_function_unsigned_close_b_enum
:
1634 next_byte (&(ieee
->h
));
1636 case ieee_function_either_close_b_enum
:
1637 next_byte (&(ieee
->h
));
1642 /* Build a relocation entry for this type */
1643 /* If pc rel then stick -ve pc into instruction
1644 and take out of reloc ..
1646 I've changed this. It's all too complicated. I
1647 keep 0 in the instruction now. */
1656 #if KEEPMINUSPCININST
1657 bfd_put_32 (ieee
->h
.abfd
, -current_map
->pc
, location_ptr
+
1659 r
->relent
.howto
= &rel32_howto
;
1663 bfd_put_32 (ieee
->h
.abfd
, 0, location_ptr
+
1665 r
->relent
.howto
= &rel32_howto
;
1670 bfd_put_32 (ieee
->h
.abfd
, 0, location_ptr
+
1672 r
->relent
.howto
= &abs32_howto
;
1674 current_map
->pc
+= 4;
1679 #if KEEPMINUSPCININST
1680 bfd_put_16 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1681 r
->relent
.addend
-= current_map
->pc
;
1682 r
->relent
.howto
= &rel16_howto
;
1685 bfd_put_16 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1686 r
->relent
.howto
= &rel16_howto
;
1692 bfd_put_16 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1693 r
->relent
.howto
= &abs16_howto
;
1695 current_map
->pc
+= 2;
1700 #if KEEPMINUSPCININST
1701 bfd_put_8 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1702 r
->relent
.addend
-= current_map
->pc
;
1703 r
->relent
.howto
= &rel8_howto
;
1705 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1706 r
->relent
.howto
= &rel8_howto
;
1711 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1712 r
->relent
.howto
= &abs8_howto
;
1714 current_map
->pc
+= 1;
1726 if (parse_int (&(ieee
->h
), &this_size
) == true)
1729 for (i
= 0; i
< this_size
; i
++)
1731 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1732 next_byte (&(ieee
->h
));
1742 /* Prevent more than the first load-item of an LR record
1743 from being repeated (MRI convention). */
1744 if (iterations
!= 1)
1752 /* Read in all the section data and relocation stuff too */
1754 ieee_slurp_section_data (abfd
)
1757 bfd_byte
*location_ptr
= (bfd_byte
*) NULL
;
1758 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1759 unsigned int section_number
;
1761 ieee_per_section_type
*current_map
= (ieee_per_section_type
*) NULL
;
1763 /* Seek to the start of the data area */
1764 if (ieee
->read_data
== true)
1766 ieee
->read_data
= true;
1767 ieee_seek (abfd
, ieee
->w
.r
.data_part
);
1769 /* Allocate enough space for all the section contents */
1771 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1773 ieee_per_section_type
*per
= (ieee_per_section_type
*) s
->used_by_bfd
;
1774 if ((s
->flags
& SEC_DEBUGGING
) != 0)
1776 per
->data
= (bfd_byte
*) bfd_alloc (ieee
->h
.abfd
, s
->_raw_size
);
1780 per
->reloc_tail_ptr
=
1781 (ieee_reloc_type
**) & (s
->relocation
);
1786 switch (this_byte (&(ieee
->h
)))
1788 /* IF we see anything strange then quit */
1792 case ieee_set_current_section_enum
:
1793 next_byte (&(ieee
->h
));
1794 section_number
= must_parse_int (&(ieee
->h
));
1795 s
= ieee
->section_table
[section_number
];
1796 s
->flags
|= SEC_LOAD
| SEC_HAS_CONTENTS
;
1797 current_map
= (ieee_per_section_type
*) s
->used_by_bfd
;
1798 location_ptr
= current_map
->data
- s
->vma
;
1799 /* The document I have says that Microtec's compilers reset */
1800 /* this after a sec section, even though the standard says not */
1802 current_map
->pc
= s
->vma
;
1805 case ieee_e2_first_byte_enum
:
1806 next_byte (&(ieee
->h
));
1807 switch (this_byte (&(ieee
->h
)))
1809 case ieee_set_current_pc_enum
& 0xff:
1812 ieee_symbol_index_type symbol
;
1815 next_byte (&(ieee
->h
));
1816 must_parse_int (&(ieee
->h
)); /* Thow away section #*/
1817 parse_expression (ieee
, &value
,
1821 current_map
->pc
= value
;
1822 BFD_ASSERT ((unsigned) (value
- s
->vma
) <= s
->_raw_size
);
1826 case ieee_value_starting_address_enum
& 0xff:
1827 next_byte (&(ieee
->h
));
1828 if (this_byte (&(ieee
->h
)) == ieee_function_either_open_b_enum
)
1829 next_byte (&(ieee
->h
));
1830 abfd
->start_address
= must_parse_int (&(ieee
->h
));
1831 /* We've got to the end of the data now - */
1838 case ieee_repeat_data_enum
:
1840 /* Repeat the following LD or LR n times - we do this by
1841 remembering the stream pointer before running it and
1842 resetting it and running it n times. We special case
1843 the repetition of a repeat_data/load_constant
1846 unsigned int iterations
;
1847 unsigned char *start
;
1848 next_byte (&(ieee
->h
));
1849 iterations
= must_parse_int (&(ieee
->h
));
1850 start
= ieee
->h
.input_p
;
1851 if (start
[0] == (int) ieee_load_constant_bytes_enum
&&
1854 while (iterations
!= 0)
1856 location_ptr
[current_map
->pc
++] = start
[2];
1859 next_byte (&(ieee
->h
));
1860 next_byte (&(ieee
->h
));
1861 next_byte (&(ieee
->h
));
1865 while (iterations
!= 0)
1867 ieee
->h
.input_p
= start
;
1868 if (!do_one (ieee
, current_map
, location_ptr
, s
,
1876 case ieee_load_constant_bytes_enum
:
1877 case ieee_load_with_relocation_enum
:
1879 if (!do_one (ieee
, current_map
, location_ptr
, s
, 1))
1887 ieee_new_section_hook (abfd
, newsect
)
1891 newsect
->used_by_bfd
= (PTR
)
1892 bfd_alloc (abfd
, sizeof (ieee_per_section_type
));
1893 if (!newsect
->used_by_bfd
)
1895 ieee_per_section (newsect
)->data
= (bfd_byte
*) NULL
;
1896 ieee_per_section (newsect
)->section
= newsect
;
1901 ieee_get_reloc_upper_bound (abfd
, asect
)
1905 if ((asect
->flags
& SEC_DEBUGGING
) != 0)
1907 if (! ieee_slurp_section_data (abfd
))
1909 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
1913 ieee_get_section_contents (abfd
, section
, location
, offset
, count
)
1918 bfd_size_type count
;
1920 ieee_per_section_type
*p
= (ieee_per_section_type
*) section
->used_by_bfd
;
1921 if ((section
->flags
& SEC_DEBUGGING
) != 0)
1922 return _bfd_generic_get_section_contents (abfd
, section
, location
,
1924 ieee_slurp_section_data (abfd
);
1925 (void) memcpy ((PTR
) location
, (PTR
) (p
->data
+ offset
), (unsigned) count
);
1930 ieee_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1936 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1937 ieee_reloc_type
*src
= (ieee_reloc_type
*) (section
->relocation
);
1938 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1940 if ((section
->flags
& SEC_DEBUGGING
) != 0)
1943 while (src
!= (ieee_reloc_type
*) NULL
)
1945 /* Work out which symbol to attach it this reloc to */
1946 switch (src
->symbol
.letter
)
1949 src
->relent
.sym_ptr_ptr
=
1950 symbols
+ src
->symbol
.index
+ ieee
->external_symbol_base_offset
;
1953 src
->relent
.sym_ptr_ptr
=
1954 symbols
+ src
->symbol
.index
+ ieee
->external_reference_base_offset
;
1957 src
->relent
.sym_ptr_ptr
=
1958 src
->relent
.sym_ptr_ptr
[0]->section
->symbol_ptr_ptr
;
1964 *relptr
++ = &src
->relent
;
1967 *relptr
= (arelent
*) NULL
;
1968 return section
->reloc_count
;
1976 arelent
*a
= *((arelent
**) ap
);
1977 arelent
*b
= *((arelent
**) bp
);
1978 return a
->address
- b
->address
;
1981 /* Write the section headers. */
1984 ieee_write_section_part (abfd
)
1987 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1989 ieee
->w
.r
.section_part
= bfd_tell (abfd
);
1990 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1992 if (! bfd_is_abs_section (s
)
1993 && (s
->flags
& SEC_DEBUGGING
) == 0)
1995 if (! ieee_write_byte (abfd
, ieee_section_type_enum
)
1996 || ! ieee_write_byte (abfd
,
1997 (bfd_byte
) (s
->index
1998 + IEEE_SECTION_NUMBER_BASE
)))
2001 if (abfd
->flags
& EXEC_P
)
2003 /* This image is executable, so output absolute sections */
2004 if (! ieee_write_byte (abfd
, ieee_variable_A_enum
)
2005 || ! ieee_write_byte (abfd
, ieee_variable_S_enum
))
2010 if (! ieee_write_byte (abfd
, ieee_variable_C_enum
))
2014 switch (s
->flags
& (SEC_CODE
| SEC_DATA
| SEC_ROM
))
2016 case SEC_CODE
| SEC_LOAD
:
2018 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
))
2023 if (! ieee_write_byte (abfd
, ieee_variable_D_enum
))
2027 case SEC_ROM
| SEC_DATA
:
2028 case SEC_ROM
| SEC_LOAD
:
2029 case SEC_ROM
| SEC_DATA
| SEC_LOAD
:
2030 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
))
2035 if (! ieee_write_id (abfd
, s
->name
))
2038 ieee_write_int (abfd
, 0); /* Parent */
2039 ieee_write_int (abfd
, 0); /* Brother */
2040 ieee_write_int (abfd
, 0); /* Context */
2043 if (! ieee_write_byte (abfd
, ieee_section_alignment_enum
)
2044 || ! ieee_write_byte (abfd
,
2045 (bfd_byte
) (s
->index
2046 + IEEE_SECTION_NUMBER_BASE
))
2047 || ! ieee_write_int (abfd
, 1 << s
->alignment_power
))
2051 if (! ieee_write_2bytes (abfd
, ieee_section_size_enum
)
2052 || ! ieee_write_byte (abfd
,
2053 (bfd_byte
) (s
->index
2054 + IEEE_SECTION_NUMBER_BASE
))
2055 || ! ieee_write_int (abfd
, s
->_raw_size
))
2057 if (abfd
->flags
& EXEC_P
)
2059 /* Relocateable sections don't have asl records */
2061 if (! ieee_write_2bytes (abfd
, ieee_section_base_address_enum
)
2062 || ! ieee_write_byte (abfd
,
2065 + IEEE_SECTION_NUMBER_BASE
)))
2066 || ! ieee_write_int (abfd
, s
->lma
))
2077 do_with_relocs (abfd
, s
)
2081 unsigned int number_of_maus_in_address
=
2082 bfd_arch_bits_per_address (abfd
) / bfd_arch_bits_per_byte (abfd
);
2083 unsigned int relocs_to_go
= s
->reloc_count
;
2084 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2085 arelent
**p
= s
->orelocation
;
2086 bfd_size_type current_byte_index
= 0;
2088 qsort (s
->orelocation
,
2090 sizeof (arelent
**),
2093 /* Output the section preheader */
2094 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2095 || ! ieee_write_byte (abfd
,
2096 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
))
2097 || ! ieee_write_2bytes (abfd
, ieee_set_current_pc_enum
)
2098 || ! ieee_write_byte (abfd
,
2099 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
)))
2101 if ((abfd
->flags
& EXEC_P
) != 0 && relocs_to_go
== 0)
2103 if (! ieee_write_int (abfd
, s
->lma
))
2108 if (! ieee_write_expression (abfd
, 0, s
->symbol
, 0, 0))
2112 if (relocs_to_go
== 0)
2114 /* If there aren't any relocations then output the load constant
2115 byte opcode rather than the load with relocation opcode */
2117 while (current_byte_index
< s
->_raw_size
)
2120 unsigned int MAXRUN
= 127;
2122 if (run
> s
->_raw_size
- current_byte_index
)
2124 run
= s
->_raw_size
- current_byte_index
;
2129 if (! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
))
2131 /* Output a stream of bytes */
2132 if (! ieee_write_int (abfd
, run
))
2134 if (bfd_write ((PTR
) (stream
+ current_byte_index
),
2140 current_byte_index
+= run
;
2146 if (! ieee_write_byte (abfd
, ieee_load_with_relocation_enum
))
2149 /* Output the data stream as the longest sequence of bytes
2150 possible, allowing for the a reasonable packet size and
2151 relocation stuffs. */
2153 if ((PTR
) stream
== (PTR
) NULL
)
2155 /* Outputting a section without data, fill it up */
2156 stream
= (unsigned char *) (bfd_alloc (abfd
, s
->_raw_size
));
2159 memset ((PTR
) stream
, 0, (size_t) s
->_raw_size
);
2161 while (current_byte_index
< s
->_raw_size
)
2164 unsigned int MAXRUN
= 127;
2167 run
= (*p
)->address
- current_byte_index
;
2175 if (run
> s
->_raw_size
- current_byte_index
)
2177 run
= s
->_raw_size
- current_byte_index
;
2182 /* Output a stream of bytes */
2183 if (! ieee_write_int (abfd
, run
))
2185 if (bfd_write ((PTR
) (stream
+ current_byte_index
),
2191 current_byte_index
+= run
;
2193 /* Output any relocations here */
2194 if (relocs_to_go
&& (*p
) && (*p
)->address
== current_byte_index
)
2197 && (*p
) && (*p
)->address
== current_byte_index
)
2203 if (r
->howto
->pc_relative
)
2205 r
->addend
+= current_byte_index
;
2209 switch (r
->howto
->size
)
2213 ov
= bfd_get_signed_32 (abfd
,
2214 stream
+ current_byte_index
);
2215 current_byte_index
+= 4;
2218 ov
= bfd_get_signed_16 (abfd
,
2219 stream
+ current_byte_index
);
2220 current_byte_index
+= 2;
2223 ov
= bfd_get_signed_8 (abfd
,
2224 stream
+ current_byte_index
);
2225 current_byte_index
++;
2233 ov
&= r
->howto
->src_mask
;
2235 if (r
->howto
->pc_relative
2236 && ! r
->howto
->pcrel_offset
)
2239 if (! ieee_write_byte (abfd
,
2240 ieee_function_either_open_b_enum
))
2245 if (r
->sym_ptr_ptr
!= (asymbol
**) NULL
)
2247 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2249 r
->howto
->pc_relative
,
2255 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2257 r
->howto
->pc_relative
,
2262 if (number_of_maus_in_address
2263 != bfd_get_reloc_size (r
->howto
))
2265 if (! ieee_write_int (abfd
,
2266 bfd_get_reloc_size (r
->howto
)))
2269 if (! ieee_write_byte (abfd
,
2270 ieee_function_either_close_b_enum
))
2284 /* If there are no relocations in the output section then we can be
2285 clever about how we write. We block items up into a max of 127
2289 do_as_repeat (abfd
, s
)
2295 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2296 || ! ieee_write_byte (abfd
,
2297 (bfd_byte
) (s
->index
2298 + IEEE_SECTION_NUMBER_BASE
))
2299 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
>> 8)
2300 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
& 0xff)
2301 || ! ieee_write_byte (abfd
,
2302 (bfd_byte
) (s
->index
2303 + IEEE_SECTION_NUMBER_BASE
))
2304 || ! ieee_write_int (abfd
, s
->lma
)
2305 || ! ieee_write_byte (abfd
, ieee_repeat_data_enum
)
2306 || ! ieee_write_int (abfd
, s
->_raw_size
)
2307 || ! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
)
2308 || ! ieee_write_byte (abfd
, 1)
2309 || ! ieee_write_byte (abfd
, 0))
2317 do_without_relocs (abfd
, s
)
2321 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2323 if (stream
== 0 || ((s
->flags
& SEC_LOAD
) == 0))
2325 if (! do_as_repeat (abfd
, s
))
2331 for (i
= 0; i
< s
->_raw_size
; i
++)
2335 if (! do_with_relocs (abfd
, s
))
2340 if (! do_as_repeat (abfd
, s
))
2348 static unsigned char *output_ptr_start
;
2349 static unsigned char *output_ptr
;
2350 static unsigned char *output_ptr_end
;
2351 static unsigned char *input_ptr_start
;
2352 static unsigned char *input_ptr
;
2353 static unsigned char *input_ptr_end
;
2354 static bfd
*input_bfd
;
2355 static bfd
*output_bfd
;
2356 static int output_buffer
;
2361 /* FIXME: Check return value. I'm not sure whether it needs to read
2362 the entire buffer or not. */
2363 bfd_read ((PTR
) input_ptr_start
, 1, input_ptr_end
- input_ptr_start
, input_bfd
);
2364 input_ptr
= input_ptr_start
;
2369 if (bfd_write ((PTR
) (output_ptr_start
), 1, output_ptr
- output_ptr_start
,
2371 != (bfd_size_type
) (output_ptr
- output_ptr_start
))
2373 output_ptr
= output_ptr_start
;
2377 #define THIS() ( *input_ptr )
2378 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2379 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2385 if (value
>= 0 && value
<= 127)
2391 unsigned int length
;
2392 /* How many significant bytes ? */
2393 /* FIXME FOR LONGER INTS */
2394 if (value
& 0xff000000)
2398 else if (value
& 0x00ff0000)
2402 else if (value
& 0x0000ff00)
2409 OUT ((int) ieee_number_repeat_start_enum
+ length
);
2428 int length
= THIS ();
2440 #define VAR(x) ((x | 0x80))
2455 value
= (value
<< 8) | THIS ();
2457 value
= (value
<< 8) | THIS ();
2459 value
= (value
<< 8) | THIS ();
2467 value
= (value
<< 8) | THIS ();
2469 value
= (value
<< 8) | THIS ();
2477 value
= (value
<< 8) | THIS ();
2494 /* Not a number, just bug out with the answer */
2495 write_int (*(--tos
));
2505 int value
= *(--tos
);
2514 ieee_data_type
*ieee
;
2517 section_number
= THIS ();
2520 ieee
= IEEE_DATA (input_bfd
);
2521 s
= ieee
->section_table
[section_number
];
2522 if (s
->output_section
)
2524 value
= s
->output_section
->lma
;
2530 value
+= s
->output_offset
;
2538 write_int (*(--tos
));
2548 /* Drop the int in the buffer, and copy a null into the gap, which we
2549 will overwrite later */
2551 struct output_buffer_struct
2553 unsigned char *ptrp
;
2559 struct output_buffer_struct
*buf
;
2561 if (buf
->buffer
== output_buffer
)
2563 /* Still a chance to output the size */
2564 int value
= output_ptr
- buf
->ptrp
+ 3;
2565 buf
->ptrp
[0] = value
>> 24;
2566 buf
->ptrp
[1] = value
>> 16;
2567 buf
->ptrp
[2] = value
>> 8;
2568 buf
->ptrp
[3] = value
>> 0;
2574 struct output_buffer_struct
*buf
;
2600 buf
->ptrp
= output_ptr
;
2601 buf
->buffer
= output_buffer
;
2641 #define ID copy_id()
2642 #define INT copy_int()
2643 #define EXP copy_expression()
2644 static void copy_till_end ();
2645 #define INTn(q) copy_int()
2646 #define EXPn(q) copy_expression()
2685 EXPn (instruction address
);
2719 EXPn (external function
);
2729 INTn (locked
register);
2752 /* Attribute record */
2810 static void block ();
2822 /* Unique typedefs for module */
2823 /* GLobal typedefs */
2824 /* High level module scope beginning */
2826 struct output_buffer_struct ob
;
2841 /* Global function */
2843 struct output_buffer_struct ob
;
2857 EXPn (size of block
);
2863 /* File name for source line numbers */
2865 struct output_buffer_struct ob
;
2885 /* Local function */
2887 struct output_buffer_struct ob
;
2905 /* Assembler module scope beginning -*/
2907 struct output_buffer_struct ob
;
2933 struct output_buffer_struct ob
;
2940 INTn (section index
);
2948 EXPn (Size in Maus
);
3003 moves all the debug information from the source bfd to the output
3004 bfd, and relocates any expressions it finds
3008 relocate_debug (output
, input
)
3014 unsigned char input_buffer
[IBS
];
3016 input_ptr_start
= input_ptr
= input_buffer
;
3017 input_ptr_end
= input_buffer
+ IBS
;
3019 /* FIXME: Check return value. I'm not sure whether it needs to read
3020 the entire buffer or not. */
3021 bfd_read ((PTR
) input_ptr_start
, 1, IBS
, input
);
3026 During linking, we we told about the bfds which made up our
3027 contents, we have a list of them. They will still be open, so go to
3028 the debug info in each, and copy it out, relocating it as we go.
3032 ieee_write_debug_part (abfd
)
3035 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3036 bfd_chain_type
*chain
= ieee
->chain_root
;
3037 unsigned char output_buffer
[OBS
];
3038 boolean some_debug
= false;
3039 file_ptr here
= bfd_tell (abfd
);
3041 output_ptr_start
= output_ptr
= output_buffer
;
3042 output_ptr_end
= output_buffer
+ OBS
;
3043 output_ptr
= output_buffer
;
3046 if (chain
== (bfd_chain_type
*) NULL
)
3050 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3051 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3055 ieee
->w
.r
.debug_information_part
= 0;
3059 ieee
->w
.r
.debug_information_part
= here
;
3060 if (bfd_write (s
->contents
, 1, s
->_raw_size
, abfd
) != s
->_raw_size
)
3065 while (chain
!= (bfd_chain_type
*) NULL
)
3067 bfd
*entry
= chain
->this;
3068 ieee_data_type
*entry_ieee
= IEEE_DATA (entry
);
3069 if (entry_ieee
->w
.r
.debug_information_part
)
3071 if (bfd_seek (entry
, entry_ieee
->w
.r
.debug_information_part
,
3075 relocate_debug (abfd
, entry
);
3078 chain
= chain
->next
;
3082 ieee
->w
.r
.debug_information_part
= here
;
3086 ieee
->w
.r
.debug_information_part
= 0;
3095 /* Write the data in an ieee way. */
3098 ieee_write_data_part (abfd
)
3102 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3103 ieee
->w
.r
.data_part
= bfd_tell (abfd
);
3104 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3106 /* Skip sections that have no loadable contents (.bss,
3108 if ((s
->flags
& SEC_LOAD
) == 0)
3111 /* Sort the reloc records so we can insert them in the correct
3113 if (s
->reloc_count
!= 0)
3115 if (! do_with_relocs (abfd
, s
))
3120 if (! do_without_relocs (abfd
, s
))
3130 init_for_output (abfd
)
3134 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3136 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3138 if (s
->_raw_size
!= 0)
3140 ieee_per_section (s
)->data
= (bfd_byte
*) (bfd_alloc (abfd
, s
->_raw_size
));
3141 if (!ieee_per_section (s
)->data
)
3148 /** exec and core file sections */
3150 /* set section contents is complicated with IEEE since the format is
3151 * not a byte image, but a record stream.
3154 ieee_set_section_contents (abfd
, section
, location
, offset
, count
)
3159 bfd_size_type count
;
3161 if ((section
->flags
& SEC_DEBUGGING
) != 0)
3163 if (section
->contents
== NULL
)
3165 section
->contents
= ((unsigned char *)
3166 bfd_alloc (abfd
, section
->_raw_size
));
3167 if (section
->contents
== NULL
)
3170 /* bfd_set_section_contents has already checked that everything
3172 memcpy (section
->contents
+ offset
, location
, count
);
3176 if (ieee_per_section (section
)->data
== (bfd_byte
*) NULL
)
3178 if (!init_for_output (abfd
))
3181 memcpy ((PTR
) (ieee_per_section (section
)->data
+ offset
),
3183 (unsigned int) count
);
3187 /* Write the external symbols of a file. IEEE considers two sorts of
3188 external symbols, public, and referenced. It uses to internal
3189 forms to index them as well. When we write them out we turn their
3190 symbol values into indexes from the right base. */
3193 ieee_write_external_part (abfd
)
3197 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3199 unsigned int reference_index
= IEEE_REFERENCE_BASE
;
3200 unsigned int public_index
= IEEE_PUBLIC_BASE
+ 2;
3201 file_ptr here
= bfd_tell (abfd
);
3202 boolean hadone
= false;
3203 if (abfd
->outsymbols
!= (asymbol
**) NULL
)
3206 for (q
= abfd
->outsymbols
; *q
!= (asymbol
*) NULL
; q
++)
3209 if (bfd_is_und_section (p
->section
))
3211 /* This must be a symbol reference .. */
3212 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3213 || ! ieee_write_int (abfd
, reference_index
)
3214 || ! ieee_write_id (abfd
, p
->name
))
3216 p
->value
= reference_index
;
3220 else if (bfd_is_com_section (p
->section
))
3222 /* This is a weak reference */
3223 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3224 || ! ieee_write_int (abfd
, reference_index
)
3225 || ! ieee_write_id (abfd
, p
->name
)
3226 || ! ieee_write_byte (abfd
,
3227 ieee_weak_external_reference_enum
)
3228 || ! ieee_write_int (abfd
, reference_index
)
3229 || ! ieee_write_int (abfd
, p
->value
))
3231 p
->value
= reference_index
;
3235 else if (p
->flags
& BSF_GLOBAL
)
3237 /* This must be a symbol definition */
3239 if (! ieee_write_byte (abfd
, ieee_external_symbol_enum
)
3240 || ! ieee_write_int (abfd
, public_index
)
3241 || ! ieee_write_id (abfd
, p
->name
)
3242 || ! ieee_write_2bytes (abfd
, ieee_attribute_record_enum
)
3243 || ! ieee_write_int (abfd
, public_index
)
3244 || ! ieee_write_byte (abfd
, 15) /* instruction address */
3245 || ! ieee_write_byte (abfd
, 19) /* static symbol */
3246 || ! ieee_write_byte (abfd
, 1)) /* one of them */
3249 /* Write out the value */
3250 if (! ieee_write_2bytes (abfd
, ieee_value_record_enum
)
3251 || ! ieee_write_int (abfd
, public_index
))
3253 if (! bfd_is_abs_section (p
->section
))
3255 if (abfd
->flags
& EXEC_P
)
3257 /* If fully linked, then output all symbols
3259 if (! (ieee_write_int
3262 + p
->section
->output_offset
3263 + p
->section
->output_section
->vma
))))
3268 if (! (ieee_write_expression
3270 p
->value
+ p
->section
->output_offset
,
3271 p
->section
->output_section
->symbol
,
3278 if (! ieee_write_expression (abfd
,
3280 bfd_abs_section_ptr
->symbol
,
3284 p
->value
= public_index
;
3290 /* This can happen - when there are gaps in the symbols read */
3291 /* from an input ieee file */
3296 ieee
->w
.r
.external_part
= here
;
3302 static CONST
unsigned char exten
[] =
3305 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3306 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3307 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3310 static CONST
unsigned char envi
[] =
3314 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3317 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3319 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3320 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3324 ieee_write_me_part (abfd
)
3327 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3328 ieee
->w
.r
.trailer_part
= bfd_tell (abfd
);
3329 if (abfd
->start_address
)
3331 if (! ieee_write_2bytes (abfd
, ieee_value_starting_address_enum
)
3332 || ! ieee_write_byte (abfd
, ieee_function_either_open_b_enum
)
3333 || ! ieee_write_int (abfd
, abfd
->start_address
)
3334 || ! ieee_write_byte (abfd
, ieee_function_either_close_b_enum
))
3337 ieee
->w
.r
.me_record
= bfd_tell (abfd
);
3338 if (! ieee_write_byte (abfd
, ieee_module_end_enum
))
3343 /* Write out the IEEE processor ID. */
3346 ieee_write_processor (abfd
)
3349 const bfd_arch_info_type
*arch
;
3351 arch
= bfd_get_arch_info (abfd
);
3355 if (! ieee_write_id (abfd
, bfd_printable_name (abfd
)))
3360 if (! ieee_write_id (abfd
, "29000"))
3364 case bfd_arch_h8300
:
3365 if (! ieee_write_id (abfd
, "H8/300"))
3369 case bfd_arch_h8500
:
3370 if (! ieee_write_id (abfd
, "H8/500"))
3378 case bfd_mach_i960_core
:
3379 case bfd_mach_i960_ka_sa
:
3380 if (! ieee_write_id (abfd
, "80960KA"))
3384 case bfd_mach_i960_kb_sb
:
3385 if (! ieee_write_id (abfd
, "80960KB"))
3389 case bfd_mach_i960_ca
:
3390 if (! ieee_write_id (abfd
, "80960CA"))
3394 case bfd_mach_i960_mc
:
3395 case bfd_mach_i960_xa
:
3396 if (! ieee_write_id (abfd
, "80960MC"))
3406 sprintf (ab
, "%lu", arch
->mach
);
3407 if (! ieee_write_id (abfd
, ab
))
3417 ieee_write_object_contents (abfd
)
3420 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3424 /* Fast forward over the header area */
3425 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3428 if (! ieee_write_byte (abfd
, ieee_module_beginning_enum
)
3429 || ! ieee_write_processor (abfd
)
3430 || ! ieee_write_id (abfd
, abfd
->filename
))
3433 /* Fast forward over the variable bits */
3434 if (! ieee_write_byte (abfd
, ieee_address_descriptor_enum
))
3438 if (! ieee_write_byte (abfd
, (bfd_byte
) (bfd_arch_bits_per_byte (abfd
))))
3440 /* MAU's per address */
3441 if (! ieee_write_byte (abfd
,
3442 (bfd_byte
) (bfd_arch_bits_per_address (abfd
)
3443 / bfd_arch_bits_per_byte (abfd
))))
3446 old
= bfd_tell (abfd
);
3447 if (bfd_seek (abfd
, (file_ptr
) (8 * N_W_VARIABLES
), SEEK_CUR
) != 0)
3450 ieee
->w
.r
.extension_record
= bfd_tell (abfd
);
3451 if (bfd_write ((char *) exten
, 1, sizeof (exten
), abfd
) != sizeof (exten
))
3453 if (abfd
->flags
& EXEC_P
)
3455 if (! ieee_write_byte (abfd
, 0x1)) /* Absolute */
3460 if (! ieee_write_byte (abfd
, 0x2)) /* Relocateable */
3464 ieee
->w
.r
.environmental_record
= bfd_tell (abfd
);
3465 if (bfd_write ((char *) envi
, 1, sizeof (envi
), abfd
) != sizeof (envi
))
3468 /* The HP emulator database requires a timestamp in the file. */
3474 t
= (struct tm
*) localtime (&now
);
3475 if (! ieee_write_2bytes (abfd
, (int) ieee_atn_record_enum
)
3476 || ! ieee_write_byte (abfd
, 0x21)
3477 || ! ieee_write_byte (abfd
, 0)
3478 || ! ieee_write_byte (abfd
, 50)
3479 || ! ieee_write_int (abfd
, t
->tm_year
+ 1900)
3480 || ! ieee_write_int (abfd
, t
->tm_mon
+ 1)
3481 || ! ieee_write_int (abfd
, t
->tm_mday
)
3482 || ! ieee_write_int (abfd
, t
->tm_hour
)
3483 || ! ieee_write_int (abfd
, t
->tm_min
)
3484 || ! ieee_write_int (abfd
, t
->tm_sec
))
3492 if (! ieee_write_section_part (abfd
))
3494 /* First write the symbols. This changes their values into table
3495 indeces so we cant use it after this point. */
3496 if (! ieee_write_external_part (abfd
))
3499 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3501 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3504 /* Write any debugs we have been told about. */
3505 if (! ieee_write_debug_part (abfd
))
3508 /* Can only write the data once the symbols have been written, since
3509 the data contains relocation information which points to the
3511 if (! ieee_write_data_part (abfd
))
3514 /* At the end we put the end! */
3515 if (! ieee_write_me_part (abfd
))
3518 /* Generate the header */
3519 if (bfd_seek (abfd
, old
, SEEK_SET
) != 0)
3522 for (i
= 0; i
< N_W_VARIABLES
; i
++)
3524 if (! ieee_write_2bytes (abfd
, ieee_assign_value_to_variable_enum
)
3525 || ! ieee_write_byte (abfd
, (bfd_byte
) i
)
3526 || ! ieee_write_int5_out (abfd
, ieee
->w
.offset
[i
]))
3533 /* Native-level interface to symbols. */
3535 /* We read the symbols into a buffer, which is discarded when this
3536 function exits. We read the strings into a buffer large enough to
3537 hold them all plus all the cached symbol entries. */
3540 ieee_make_empty_symbol (abfd
)
3543 ieee_symbol_type
*new =
3544 (ieee_symbol_type
*) bfd_zmalloc (sizeof (ieee_symbol_type
));
3547 new->symbol
.the_bfd
= abfd
;
3548 return &new->symbol
;
3552 ieee_openr_next_archived_file (arch
, prev
)
3556 ieee_ar_data_type
*ar
= IEEE_AR_DATA (arch
);
3557 /* take the next one from the arch state, or reset */
3558 if (prev
== (bfd
*) NULL
)
3560 /* Reset the index - the first two entries are bogus*/
3561 ar
->element_index
= 2;
3565 ieee_ar_obstack_type
*p
= ar
->elements
+ ar
->element_index
;
3566 ar
->element_index
++;
3567 if (ar
->element_index
<= ar
->element_count
)
3569 if (p
->file_offset
!= (file_ptr
) 0)
3571 if (p
->abfd
== (bfd
*) NULL
)
3573 p
->abfd
= _bfd_create_empty_archive_element_shell (arch
);
3574 p
->abfd
->origin
= p
->file_offset
;
3581 bfd_set_error (bfd_error_no_more_archived_files
);
3582 return (bfd
*) NULL
;
3589 ieee_find_nearest_line (abfd
,
3600 char **filename_ptr
;
3601 char **functionname_ptr
;
3608 ieee_generic_stat_arch_elt (abfd
, buf
)
3612 ieee_ar_data_type
*ar
= abfd
->my_archive
->tdata
.ieee_ar_data
;
3613 ieee_data_type
*ieee
;
3615 if (ar
== (ieee_ar_data_type
*) NULL
)
3617 bfd_set_error (bfd_error_invalid_operation
);
3621 if (IEEE_DATA (abfd
) == NULL
)
3623 if (ieee_object_p (abfd
) == NULL
)
3625 bfd_set_error (bfd_error_wrong_format
);
3630 ieee
= IEEE_DATA (abfd
);
3632 buf
->st_size
= ieee
->w
.r
.me_record
+ 1;
3633 buf
->st_mode
= 0644;
3638 ieee_sizeof_headers (abfd
, x
)
3646 /* The debug info routines are never used. */
3650 ieee_bfd_debug_info_start (abfd
)
3657 ieee_bfd_debug_info_end (abfd
)
3664 /* Add this section to the list of sections we have debug info for, to
3665 be ready to output it at close time
3668 ieee_bfd_debug_info_accumulate (abfd
, section
)
3672 ieee_data_type
*ieee
= IEEE_DATA (section
->owner
);
3673 ieee_data_type
*output_ieee
= IEEE_DATA (abfd
);
3674 /* can only accumulate data from other ieee bfds */
3675 if (section
->owner
->xvec
!= abfd
->xvec
)
3677 /* Only bother once per bfd */
3678 if (ieee
->done_debug
== true)
3680 ieee
->done_debug
= true;
3682 /* Don't bother if there is no debug info */
3683 if (ieee
->w
.r
.debug_information_part
== 0)
3689 bfd_chain_type
*n
= (bfd_chain_type
*) bfd_alloc (abfd
, sizeof (bfd_chain_type
));
3691 abort (); /* FIXME */
3692 n
->this = section
->owner
;
3693 n
->next
= (bfd_chain_type
*) NULL
;
3695 if (output_ieee
->chain_head
)
3697 output_ieee
->chain_head
->next
= n
;
3701 output_ieee
->chain_root
= n
;
3704 output_ieee
->chain_head
= n
;
3710 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3711 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3713 #define ieee_slurp_armap bfd_true
3714 #define ieee_slurp_extended_name_table bfd_true
3715 #define ieee_construct_extended_name_table \
3716 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
3718 #define ieee_truncate_arname bfd_dont_truncate_arname
3719 #define ieee_write_armap \
3721 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3723 #define ieee_read_ar_hdr bfd_nullvoidptr
3724 #define ieee_update_armap_timestamp bfd_true
3725 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3727 #define ieee_bfd_is_local_label bfd_generic_is_local_label
3728 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3729 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3730 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3731 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3733 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3735 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3737 #define ieee_get_section_contents_in_window \
3738 _bfd_generic_get_section_contents_in_window
3739 #define ieee_bfd_get_relocated_section_contents \
3740 bfd_generic_get_relocated_section_contents
3741 #define ieee_bfd_relax_section bfd_generic_relax_section
3742 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3743 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3744 #define ieee_bfd_final_link _bfd_generic_final_link
3745 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3748 const bfd_target ieee_vec
=
3751 bfd_target_ieee_flavour
,
3752 BFD_ENDIAN_UNKNOWN
, /* target byte order */
3753 BFD_ENDIAN_UNKNOWN
, /* target headers byte order */
3754 (HAS_RELOC
| EXEC_P
| /* object flags */
3755 HAS_LINENO
| HAS_DEBUG
|
3756 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
3757 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
3758 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3759 '_', /* leading underscore */
3760 ' ', /* ar_pad_char */
3761 16, /* ar_max_namelen */
3762 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3763 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3764 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
3765 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3766 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3767 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
3770 ieee_object_p
, /* bfd_check_format */
3777 _bfd_generic_mkarchive
,
3782 ieee_write_object_contents
,
3783 _bfd_write_archive_contents
,
3787 BFD_JUMP_TABLE_GENERIC (ieee
),
3788 BFD_JUMP_TABLE_COPY (_bfd_generic
),
3789 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3790 BFD_JUMP_TABLE_ARCHIVE (ieee
),
3791 BFD_JUMP_TABLE_SYMBOLS (ieee
),
3792 BFD_JUMP_TABLE_RELOCS (ieee
),
3793 BFD_JUMP_TABLE_WRITE (ieee
),
3794 BFD_JUMP_TABLE_LINK (ieee
),
3795 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),