1 /* BFD back-end for ieee-695 objects.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
6 Written by Steve Chamberlain of Cygnus Support.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #define KEEPMINUSPCININST 0
26 /* IEEE 695 format is a stream of records, which we parse using a simple one-
27 token (which is one byte in this lexicon) lookahead recursive decent
38 static boolean ieee_write_byte
PARAMS ((bfd
*, int));
39 static boolean ieee_write_2bytes
PARAMS ((bfd
*, int));
40 static boolean ieee_write_int
PARAMS ((bfd
*, bfd_vma
));
41 static boolean ieee_write_id
PARAMS ((bfd
*, const char *));
42 static boolean ieee_write_expression
43 PARAMS ((bfd
*, bfd_vma
, asymbol
*, boolean
, unsigned int));
44 static void ieee_write_int5
PARAMS ((bfd_byte
*, bfd_vma
));
45 static boolean ieee_write_int5_out
PARAMS ((bfd
*, bfd_vma
));
46 static boolean ieee_write_section_part
PARAMS ((bfd
*));
47 static boolean do_with_relocs
PARAMS ((bfd
*, asection
*));
48 static boolean do_as_repeat
PARAMS ((bfd
*, asection
*));
49 static boolean do_without_relocs
PARAMS ((bfd
*, asection
*));
50 static boolean ieee_write_external_part
PARAMS ((bfd
*));
51 static boolean ieee_write_data_part
PARAMS ((bfd
*));
52 static boolean ieee_write_debug_part
PARAMS ((bfd
*));
53 static boolean ieee_write_me_part
PARAMS ((bfd
*));
54 static boolean ieee_write_processor
PARAMS ((bfd
*));
56 static boolean ieee_slurp_debug
PARAMS ((bfd
*));
57 static boolean ieee_slurp_section_data
PARAMS ((bfd
*));
59 /* Functions for writing to ieee files in the strange way that the
63 ieee_write_byte (abfd
, barg
)
70 if (bfd_write ((PTR
) &byte
, 1, 1, abfd
) != 1)
76 ieee_write_2bytes (abfd
, bytes
)
82 buffer
[0] = bytes
>> 8;
83 buffer
[1] = bytes
& 0xff;
84 if (bfd_write ((PTR
) buffer
, 1, 2, abfd
) != 2)
90 ieee_write_int (abfd
, value
)
96 if (! ieee_write_byte (abfd
, (bfd_byte
) value
))
103 /* How many significant bytes ? */
104 /* FIXME FOR LONGER INTS */
105 if (value
& 0xff000000)
107 else if (value
& 0x00ff0000)
109 else if (value
& 0x0000ff00)
114 if (! ieee_write_byte (abfd
,
115 (bfd_byte
) ((int) ieee_number_repeat_start_enum
121 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 24)))
125 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 16)))
129 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 8)))
133 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
)))
142 ieee_write_id (abfd
, id
)
146 size_t length
= strlen (id
);
150 if (! ieee_write_byte (abfd
, (bfd_byte
) length
))
153 else if (length
< 255)
155 if (! ieee_write_byte (abfd
, ieee_extension_length_1_enum
)
156 || ! ieee_write_byte (abfd
, (bfd_byte
) length
))
159 else if (length
< 65535)
161 if (! ieee_write_byte (abfd
, ieee_extension_length_2_enum
)
162 || ! ieee_write_2bytes (abfd
, (int) length
))
167 (*_bfd_error_handler
)
168 (_("%s: string too long (%d chars, max 65535)"),
169 bfd_get_filename (abfd
), length
);
170 bfd_set_error (bfd_error_invalid_operation
);
174 if (bfd_write ((PTR
) id
, 1, length
, abfd
) != length
)
179 /***************************************************************************
180 Functions for reading from ieee files in the strange way that the
184 #define this_byte(ieee) *((ieee)->input_p)
185 #define next_byte(ieee) ((ieee)->input_p++)
186 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
188 static unsigned short
190 common_header_type
*ieee
;
192 unsigned char c1
= this_byte_and_next (ieee
);
193 unsigned char c2
= this_byte_and_next (ieee
);
194 return (c1
<< 8) | c2
;
198 bfd_get_string (ieee
, string
, length
)
199 common_header_type
*ieee
;
204 for (i
= 0; i
< length
; i
++)
206 string
[i
] = this_byte_and_next (ieee
);
212 common_header_type
*ieee
;
216 length
= this_byte_and_next (ieee
);
219 /* Simple string of length 0 to 127 */
221 else if (length
== 0xde)
223 /* Length is next byte, allowing 0..255 */
224 length
= this_byte_and_next (ieee
);
226 else if (length
== 0xdf)
228 /* Length is next two bytes, allowing 0..65535 */
229 length
= this_byte_and_next (ieee
);
230 length
= (length
* 256) + this_byte_and_next (ieee
);
232 /* Buy memory and read string */
233 string
= bfd_alloc (ieee
->abfd
, length
+ 1);
236 bfd_get_string (ieee
, string
, length
);
242 ieee_write_expression (abfd
, value
, symbol
, pcrel
, index
)
249 unsigned int term_count
= 0;
253 if (! ieee_write_int (abfd
, value
))
258 if (bfd_is_com_section (symbol
->section
)
259 || bfd_is_und_section (symbol
->section
))
261 /* Def of a common symbol */
262 if (! ieee_write_byte (abfd
, ieee_variable_X_enum
)
263 || ! ieee_write_int (abfd
, symbol
->value
))
267 else if (! bfd_is_abs_section (symbol
->section
))
269 /* Ref to defined symbol - */
271 if (symbol
->flags
& BSF_GLOBAL
)
273 if (! ieee_write_byte (abfd
, ieee_variable_I_enum
)
274 || ! ieee_write_int (abfd
, symbol
->value
))
278 else if (symbol
->flags
& (BSF_LOCAL
| BSF_SECTION_SYM
))
280 /* This is a reference to a defined local symbol. We can
281 easily do a local as a section+offset. */
282 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
)
283 || ! ieee_write_byte (abfd
,
284 (bfd_byte
) (symbol
->section
->index
285 + IEEE_SECTION_NUMBER_BASE
)))
288 if (symbol
->value
!= 0)
290 if (! ieee_write_int (abfd
, symbol
->value
))
297 (*_bfd_error_handler
)
298 (_("%s: unrecognized symbol `%s' flags 0x%x"),
299 bfd_get_filename (abfd
), bfd_asymbol_name (symbol
),
301 bfd_set_error (bfd_error_invalid_operation
);
308 /* subtract the pc from here by asking for PC of this section*/
309 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
)
310 || ! ieee_write_byte (abfd
,
311 (bfd_byte
) (index
+ IEEE_SECTION_NUMBER_BASE
))
312 || ! ieee_write_byte (abfd
, ieee_function_minus_enum
))
316 /* Handle the degenerate case of a 0 address. */
319 if (! ieee_write_int (abfd
, 0))
323 while (term_count
> 1)
325 if (! ieee_write_byte (abfd
, ieee_function_plus_enum
))
333 /*****************************************************************************/
336 writes any integer into the buffer supplied and always takes 5 bytes
339 ieee_write_int5 (buffer
, value
)
343 buffer
[0] = (bfd_byte
) ieee_number_repeat_4_enum
;
344 buffer
[1] = (value
>> 24) & 0xff;
345 buffer
[2] = (value
>> 16) & 0xff;
346 buffer
[3] = (value
>> 8) & 0xff;
347 buffer
[4] = (value
>> 0) & 0xff;
351 ieee_write_int5_out (abfd
, value
)
357 ieee_write_int5 (b
, value
);
358 if (bfd_write ((PTR
) b
, 1, 5, abfd
) != 5)
364 parse_int (ieee
, value_ptr
)
365 common_header_type
*ieee
;
368 int value
= this_byte (ieee
);
370 if (value
>= 0 && value
<= 127)
376 else if (value
>= 0x80 && value
<= 0x88)
378 unsigned int count
= value
& 0xf;
383 result
= (result
<< 8) | this_byte_and_next (ieee
);
394 common_header_type
*ieee
;
398 *ok
= parse_int (ieee
, &x
);
403 must_parse_int (ieee
)
404 common_header_type
*ieee
;
407 BFD_ASSERT (parse_int (ieee
, &result
) == true);
415 ieee_symbol_index_type symbol
;
419 #if KEEPMINUSPCININST
421 #define SRC_MASK(arg) arg
422 #define PCREL_OFFSET false
426 #define SRC_MASK(arg) 0
427 #define PCREL_OFFSET true
431 static reloc_howto_type abs32_howto
=
438 complain_overflow_bitfield
,
446 static reloc_howto_type abs16_howto
=
453 complain_overflow_bitfield
,
461 static reloc_howto_type abs8_howto
=
468 complain_overflow_bitfield
,
476 static reloc_howto_type rel32_howto
=
483 complain_overflow_signed
,
487 SRC_MASK (0xffffffff),
491 static reloc_howto_type rel16_howto
=
498 complain_overflow_signed
,
502 SRC_MASK (0x0000ffff),
506 static reloc_howto_type rel8_howto
=
513 complain_overflow_signed
,
517 SRC_MASK (0x000000ff),
521 static ieee_symbol_index_type NOSYMBOL
= {0, 0};
524 parse_expression (ieee
, value
, symbol
, pcrel
, extra
, section
)
525 ieee_data_type
*ieee
;
527 ieee_symbol_index_type
*symbol
;
540 ieee_value_type stack
[10];
542 /* The stack pointer always points to the next unused location */
543 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
544 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
545 ieee_value_type
*sp
= stack
;
549 switch (this_byte (&(ieee
->h
)))
551 case ieee_variable_P_enum
:
552 /* P variable, current program counter for section n */
555 next_byte (&(ieee
->h
));
557 section_n
= must_parse_int (&(ieee
->h
));
558 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, 0);
561 case ieee_variable_L_enum
:
562 /* L variable address of section N */
563 next_byte (&(ieee
->h
));
564 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
566 case ieee_variable_R_enum
:
567 /* R variable, logical address of section module */
568 /* FIXME, this should be different to L */
569 next_byte (&(ieee
->h
));
570 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
572 case ieee_variable_S_enum
:
573 /* S variable, size in MAUS of section module */
574 next_byte (&(ieee
->h
));
577 ieee
->section_table
[must_parse_int (&(ieee
->h
))]->_raw_size
);
579 case ieee_variable_I_enum
:
580 /* Push the address of variable n */
582 ieee_symbol_index_type sy
;
583 next_byte (&(ieee
->h
));
584 sy
.index
= (int) must_parse_int (&(ieee
->h
));
587 PUSH (sy
, bfd_abs_section_ptr
, 0);
590 case ieee_variable_X_enum
:
591 /* Push the address of external variable n */
593 ieee_symbol_index_type sy
;
594 next_byte (&(ieee
->h
));
595 sy
.index
= (int) (must_parse_int (&(ieee
->h
)));
598 PUSH (sy
, bfd_und_section_ptr
, 0);
601 case ieee_function_minus_enum
:
603 bfd_vma value1
, value2
;
604 asection
*section1
, *section_dummy
;
605 ieee_symbol_index_type sy
;
606 next_byte (&(ieee
->h
));
608 POP (sy
, section1
, value1
);
609 POP (sy
, section_dummy
, value2
);
610 PUSH (sy
, section1
? section1
: section_dummy
, value2
- value1
);
613 case ieee_function_plus_enum
:
615 bfd_vma value1
, value2
;
618 ieee_symbol_index_type sy1
;
619 ieee_symbol_index_type sy2
;
620 next_byte (&(ieee
->h
));
622 POP (sy1
, section1
, value1
);
623 POP (sy2
, section2
, value2
);
624 PUSH (sy1
.letter
? sy1
: sy2
,
625 bfd_is_abs_section (section1
) ? section2
: section1
,
632 BFD_ASSERT (this_byte (&(ieee
->h
)) < (int) ieee_variable_A_enum
633 || this_byte (&(ieee
->h
)) > (int) ieee_variable_Z_enum
);
634 if (parse_int (&(ieee
->h
), &va
))
636 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, va
);
641 Thats all that we can understand. As far as I can see
642 there is a bug in the Microtec IEEE output which I'm
643 using to scan, whereby the comma operator is omitted
644 sometimes in an expression, giving expressions with too
645 many terms. We can tell if that's the case by ensuring
646 that sp == stack here. If not, then we've pushed
647 something too far, so we keep adding. */
649 while (sp
!= stack
+ 1)
652 ieee_symbol_index_type sy1
;
653 POP (sy1
, section1
, *extra
);
658 POP (*symbol
, dummy
, *value
);
671 #define ieee_seek(abfd, offset) \
672 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
674 #define ieee_pos(abfd) \
675 (IEEE_DATA(abfd)->h.input_p - IEEE_DATA(abfd)->h.first_byte)
677 static unsigned int last_index
;
678 static char last_type
; /* is the index for an X or a D */
680 static ieee_symbol_type
*
689 bfd
*abfd ATTRIBUTE_UNUSED
;
690 ieee_data_type
*ieee
;
691 ieee_symbol_type
*last_symbol
;
692 unsigned int *symbol_count
;
693 ieee_symbol_type
***pptr
;
694 unsigned int *max_index
;
698 /* Need a new symbol */
699 unsigned int new_index
= must_parse_int (&(ieee
->h
));
700 if (new_index
!= last_index
|| this_type
!= last_type
)
702 ieee_symbol_type
*new_symbol
= (ieee_symbol_type
*) bfd_alloc (ieee
->h
.abfd
,
703 sizeof (ieee_symbol_type
));
707 new_symbol
->index
= new_index
;
708 last_index
= new_index
;
711 *pptr
= &new_symbol
->next
;
712 if (new_index
> *max_index
)
714 *max_index
= new_index
;
716 last_type
= this_type
;
717 new_symbol
->symbol
.section
= bfd_abs_section_ptr
;
724 ieee_slurp_external_symbols (abfd
)
727 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
728 file_ptr offset
= ieee
->w
.r
.external_part
;
730 ieee_symbol_type
**prev_symbols_ptr
= &ieee
->external_symbols
;
731 ieee_symbol_type
**prev_reference_ptr
= &ieee
->external_reference
;
732 ieee_symbol_type
*symbol
= (ieee_symbol_type
*) NULL
;
733 unsigned int symbol_count
= 0;
735 last_index
= 0xffffff;
736 ieee
->symbol_table_full
= true;
738 ieee_seek (abfd
, offset
);
742 switch (this_byte (&(ieee
->h
)))
745 next_byte (&(ieee
->h
));
747 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
749 &ieee
->external_symbol_max_index
, 'I');
753 symbol
->symbol
.the_bfd
= abfd
;
754 symbol
->symbol
.name
= read_id (&(ieee
->h
));
755 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
756 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
758 case ieee_external_symbol_enum
:
759 next_byte (&(ieee
->h
));
761 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
763 &ieee
->external_symbol_max_index
, 'D');
767 BFD_ASSERT (symbol
->index
>= ieee
->external_symbol_min_index
);
769 symbol
->symbol
.the_bfd
= abfd
;
770 symbol
->symbol
.name
= read_id (&(ieee
->h
));
771 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
772 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
774 case ieee_attribute_record_enum
>> 8:
776 unsigned int symbol_name_index
;
777 unsigned int symbol_type_index
;
778 unsigned int symbol_attribute_def
;
780 switch (read_2bytes (ieee
))
782 case ieee_attribute_record_enum
:
783 symbol_name_index
= must_parse_int (&(ieee
->h
));
784 symbol_type_index
= must_parse_int (&(ieee
->h
));
785 symbol_attribute_def
= must_parse_int (&(ieee
->h
));
786 switch (symbol_attribute_def
)
790 parse_int (&ieee
->h
, &value
);
793 (*_bfd_error_handler
)
794 (_("%s: unimplemented ATI record %u for symbol %u"),
795 bfd_get_filename (abfd
), symbol_attribute_def
,
797 bfd_set_error (bfd_error_bad_value
);
802 case ieee_external_reference_info_record_enum
:
803 /* Skip over ATX record. */
804 parse_int (&(ieee
->h
), &value
);
805 parse_int (&(ieee
->h
), &value
);
806 parse_int (&(ieee
->h
), &value
);
807 parse_int (&(ieee
->h
), &value
);
809 case ieee_atn_record_enum
:
810 /* We may get call optimization information here,
811 which we just ignore. The format is
812 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs} */
813 parse_int (&ieee
->h
, &value
);
814 parse_int (&ieee
->h
, &value
);
815 parse_int (&ieee
->h
, &value
);
818 (*_bfd_error_handler
)
819 (_("%s: unexpected ATN type %d in external part"),
820 bfd_get_filename (abfd
), (int) value
);
821 bfd_set_error (bfd_error_bad_value
);
824 parse_int (&ieee
->h
, &value
);
825 parse_int (&ieee
->h
, &value
);
832 switch (read_2bytes (ieee
))
834 case ieee_asn_record_enum
:
835 parse_int (&ieee
->h
, &val1
);
836 parse_int (&ieee
->h
, &val1
);
840 (*_bfd_error_handler
)
841 (_("%s: unexpected type after ATN"),
842 bfd_get_filename (abfd
));
843 bfd_set_error (bfd_error_bad_value
);
850 case ieee_value_record_enum
>> 8:
852 unsigned int symbol_name_index
;
853 ieee_symbol_index_type symbol_ignore
;
854 boolean pcrel_ignore
;
856 next_byte (&(ieee
->h
));
857 next_byte (&(ieee
->h
));
859 symbol_name_index
= must_parse_int (&(ieee
->h
));
860 parse_expression (ieee
,
861 &symbol
->symbol
.value
,
865 &symbol
->symbol
.section
);
867 /* Fully linked IEEE-695 files tend to give every symbol
868 an absolute value. Try to convert that back into a
869 section relative value. FIXME: This won't always to
871 if (bfd_is_abs_section (symbol
->symbol
.section
)
872 && (abfd
->flags
& HAS_RELOC
) == 0)
877 val
= symbol
->symbol
.value
;
878 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
880 if (val
>= s
->vma
&& val
< s
->vma
+ s
->_raw_size
)
882 symbol
->symbol
.section
= s
;
883 symbol
->symbol
.value
-= s
->vma
;
889 symbol
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
;
893 case ieee_weak_external_reference_enum
:
897 next_byte (&(ieee
->h
));
898 /* Throw away the external reference index */
899 (void) must_parse_int (&(ieee
->h
));
900 /* Fetch the default size if not resolved */
901 size
= must_parse_int (&(ieee
->h
));
902 /* Fetch the defautlt value if available */
903 if (parse_int (&(ieee
->h
), &value
) == false)
907 /* This turns into a common */
908 symbol
->symbol
.section
= bfd_com_section_ptr
;
909 symbol
->symbol
.value
= size
;
913 case ieee_external_reference_enum
:
914 next_byte (&(ieee
->h
));
916 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
918 &ieee
->external_reference_max_index
, 'X');
922 symbol
->symbol
.the_bfd
= abfd
;
923 symbol
->symbol
.name
= read_id (&(ieee
->h
));
924 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
925 symbol
->symbol
.section
= bfd_und_section_ptr
;
926 symbol
->symbol
.value
= (bfd_vma
) 0;
927 symbol
->symbol
.flags
= 0;
929 BFD_ASSERT (symbol
->index
>= ieee
->external_reference_min_index
);
937 if (ieee
->external_symbol_max_index
!= 0)
939 ieee
->external_symbol_count
=
940 ieee
->external_symbol_max_index
-
941 ieee
->external_symbol_min_index
+ 1;
945 ieee
->external_symbol_count
= 0;
948 if (ieee
->external_reference_max_index
!= 0)
950 ieee
->external_reference_count
=
951 ieee
->external_reference_max_index
-
952 ieee
->external_reference_min_index
+ 1;
956 ieee
->external_reference_count
= 0;
960 ieee
->external_reference_count
+ ieee
->external_symbol_count
;
962 if (symbol_count
!= abfd
->symcount
)
964 /* There are gaps in the table -- */
965 ieee
->symbol_table_full
= false;
968 *prev_symbols_ptr
= (ieee_symbol_type
*) NULL
;
969 *prev_reference_ptr
= (ieee_symbol_type
*) NULL
;
975 ieee_slurp_symbol_table (abfd
)
978 if (IEEE_DATA (abfd
)->read_symbols
== false)
980 if (! ieee_slurp_external_symbols (abfd
))
982 IEEE_DATA (abfd
)->read_symbols
= true;
988 ieee_get_symtab_upper_bound (abfd
)
991 if (! ieee_slurp_symbol_table (abfd
))
994 return (abfd
->symcount
!= 0) ?
995 (abfd
->symcount
+ 1) * (sizeof (ieee_symbol_type
*)) : 0;
999 Move from our internal lists to the canon table, and insert in
1003 extern const bfd_target ieee_vec
;
1006 ieee_get_symtab (abfd
, location
)
1010 ieee_symbol_type
*symp
;
1011 static bfd dummy_bfd
;
1012 static asymbol empty_symbol
=
1020 /* K&R compilers can't initialise unions. */
1027 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1028 dummy_bfd
.xvec
= &ieee_vec
;
1029 if (! ieee_slurp_symbol_table (abfd
))
1032 if (ieee
->symbol_table_full
== false)
1034 /* Arrgh - there are gaps in the table, run through and fill them */
1035 /* up with pointers to a null place */
1037 for (i
= 0; i
< abfd
->symcount
; i
++)
1039 location
[i
] = &empty_symbol
;
1043 ieee
->external_symbol_base_offset
= -ieee
->external_symbol_min_index
;
1044 for (symp
= IEEE_DATA (abfd
)->external_symbols
;
1045 symp
!= (ieee_symbol_type
*) NULL
;
1048 /* Place into table at correct index locations */
1049 location
[symp
->index
+ ieee
->external_symbol_base_offset
] = &symp
->symbol
;
1052 /* The external refs are indexed in a bit */
1053 ieee
->external_reference_base_offset
=
1054 -ieee
->external_reference_min_index
+ ieee
->external_symbol_count
;
1056 for (symp
= IEEE_DATA (abfd
)->external_reference
;
1057 symp
!= (ieee_symbol_type
*) NULL
;
1060 location
[symp
->index
+ ieee
->external_reference_base_offset
] =
1067 location
[abfd
->symcount
] = (asymbol
*) NULL
;
1069 return abfd
->symcount
;
1073 get_section_entry (abfd
, ieee
, index
)
1075 ieee_data_type
*ieee
;
1078 if (index
>= ieee
->section_table_size
)
1083 c
= ieee
->section_table_size
;
1090 bfd_realloc (ieee
->section_table
, c
* sizeof (asection
*)));
1094 for (i
= ieee
->section_table_size
; i
< c
; i
++)
1097 ieee
->section_table
= n
;
1098 ieee
->section_table_size
= c
;
1101 if (ieee
->section_table
[index
] == (asection
*) NULL
)
1103 char *tmp
= bfd_alloc (abfd
, 11);
1108 sprintf (tmp
, " fsec%4d", index
);
1109 section
= bfd_make_section (abfd
, tmp
);
1110 ieee
->section_table
[index
] = section
;
1111 section
->flags
= SEC_NO_FLAGS
;
1112 section
->target_index
= index
;
1113 ieee
->section_table
[index
] = section
;
1115 return ieee
->section_table
[index
];
1119 ieee_slurp_sections (abfd
)
1122 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1123 file_ptr offset
= ieee
->w
.r
.section_part
;
1124 asection
*section
= (asection
*) NULL
;
1129 bfd_byte section_type
[3];
1130 ieee_seek (abfd
, offset
);
1133 switch (this_byte (&(ieee
->h
)))
1135 case ieee_section_type_enum
:
1137 unsigned int section_index
;
1138 next_byte (&(ieee
->h
));
1139 section_index
= must_parse_int (&(ieee
->h
));
1141 section
= get_section_entry (abfd
, ieee
, section_index
);
1143 section_type
[0] = this_byte_and_next (&(ieee
->h
));
1145 /* Set minimal section attributes. Attributes are
1146 extended later, based on section contents. */
1148 switch (section_type
[0])
1151 /* Normal attributes for absolute sections */
1152 section_type
[1] = this_byte (&(ieee
->h
));
1153 section
->flags
= SEC_ALLOC
;
1154 switch (section_type
[1])
1156 case 0xD3: /* AS Absolute section attributes */
1157 next_byte (&(ieee
->h
));
1158 section_type
[2] = this_byte (&(ieee
->h
));
1159 switch (section_type
[2])
1163 next_byte (&(ieee
->h
));
1164 section
->flags
|= SEC_CODE
;
1168 next_byte (&(ieee
->h
));
1169 section
->flags
|= SEC_DATA
;
1172 next_byte (&(ieee
->h
));
1173 /* Normal rom data */
1174 section
->flags
|= SEC_ROM
| SEC_DATA
;
1181 case 0xC3: /* Named relocatable sections (type C) */
1182 section_type
[1] = this_byte (&(ieee
->h
));
1183 section
->flags
= SEC_ALLOC
;
1184 switch (section_type
[1])
1186 case 0xD0: /* Normal code (CP) */
1187 next_byte (&(ieee
->h
));
1188 section
->flags
|= SEC_CODE
;
1190 case 0xC4: /* Normal data (CD) */
1191 next_byte (&(ieee
->h
));
1192 section
->flags
|= SEC_DATA
;
1194 case 0xD2: /* Normal rom data (CR) */
1195 next_byte (&(ieee
->h
));
1196 section
->flags
|= SEC_ROM
| SEC_DATA
;
1203 /* Read section name, use it if non empty. */
1204 name
= read_id (&ieee
->h
);
1206 section
->name
= name
;
1208 /* Skip these fields, which we don't care about */
1210 bfd_vma parent
, brother
, context
;
1211 parse_int (&(ieee
->h
), &parent
);
1212 parse_int (&(ieee
->h
), &brother
);
1213 parse_int (&(ieee
->h
), &context
);
1217 case ieee_section_alignment_enum
:
1219 unsigned int section_index
;
1222 next_byte (&(ieee
->h
));
1223 section_index
= must_parse_int (&ieee
->h
);
1224 section
= get_section_entry (abfd
, ieee
, section_index
);
1225 if (section_index
> ieee
->section_count
)
1227 ieee
->section_count
= section_index
;
1229 section
->alignment_power
=
1230 bfd_log2 (must_parse_int (&ieee
->h
));
1231 (void) parse_int (&(ieee
->h
), &value
);
1234 case ieee_e2_first_byte_enum
:
1236 ieee_record_enum_type t
= (ieee_record_enum_type
) (read_2bytes (&(ieee
->h
)));
1240 case ieee_section_size_enum
:
1241 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1242 section
->_raw_size
= must_parse_int (&(ieee
->h
));
1244 case ieee_physical_region_size_enum
:
1245 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1246 section
->_raw_size
= must_parse_int (&(ieee
->h
));
1248 case ieee_region_base_address_enum
:
1249 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1250 section
->vma
= must_parse_int (&(ieee
->h
));
1251 section
->lma
= section
->vma
;
1253 case ieee_mau_size_enum
:
1254 must_parse_int (&(ieee
->h
));
1255 must_parse_int (&(ieee
->h
));
1257 case ieee_m_value_enum
:
1258 must_parse_int (&(ieee
->h
));
1259 must_parse_int (&(ieee
->h
));
1261 case ieee_section_base_address_enum
:
1262 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1263 section
->vma
= must_parse_int (&(ieee
->h
));
1264 section
->lma
= section
->vma
;
1266 case ieee_section_offset_enum
:
1267 (void) must_parse_int (&(ieee
->h
));
1268 (void) must_parse_int (&(ieee
->h
));
1282 /* Make a section for the debugging information, if any. We don't try
1283 to interpret the debugging information; we just point the section
1284 at the area in the file so that program which understand can dig it
1288 ieee_slurp_debug (abfd
)
1291 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1295 if (ieee
->w
.r
.debug_information_part
== 0)
1298 sec
= bfd_make_section (abfd
, ".debug");
1301 sec
->flags
|= SEC_DEBUGGING
| SEC_HAS_CONTENTS
;
1302 sec
->filepos
= ieee
->w
.r
.debug_information_part
;
1304 debug_end
= ieee
->w
.r
.data_part
;
1306 debug_end
= ieee
->w
.r
.trailer_part
;
1308 debug_end
= ieee
->w
.r
.me_record
;
1309 sec
->_raw_size
= debug_end
- ieee
->w
.r
.debug_information_part
;
1314 /***********************************************************************
1319 ieee_archive_p (abfd
)
1324 unsigned char buffer
[512];
1325 file_ptr buffer_offset
= 0;
1326 ieee_ar_data_type
*save
= abfd
->tdata
.ieee_ar_data
;
1327 ieee_ar_data_type
*ieee
;
1328 unsigned int alc_elts
;
1329 ieee_ar_obstack_type
*elts
= NULL
;
1331 abfd
->tdata
.ieee_ar_data
=
1332 (ieee_ar_data_type
*) bfd_alloc (abfd
, sizeof (ieee_ar_data_type
));
1333 if (!abfd
->tdata
.ieee_ar_data
)
1335 ieee
= IEEE_AR_DATA (abfd
);
1337 /* FIXME: Check return value. I'm not sure whether it needs to read
1338 the entire buffer or not. */
1339 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1341 ieee
->h
.first_byte
= buffer
;
1342 ieee
->h
.input_p
= buffer
;
1344 ieee
->h
.abfd
= abfd
;
1346 if (this_byte (&(ieee
->h
)) != Module_Beginning
)
1347 goto got_wrong_format_error
;
1349 next_byte (&(ieee
->h
));
1350 library
= read_id (&(ieee
->h
));
1351 if (strcmp (library
, "LIBRARY") != 0)
1352 goto got_wrong_format_error
;
1354 /* Throw away the filename. */
1355 read_id (&(ieee
->h
));
1357 ieee
->element_count
= 0;
1358 ieee
->element_index
= 0;
1360 next_byte (&(ieee
->h
)); /* Drop the ad part. */
1361 must_parse_int (&(ieee
->h
)); /* And the two dummy numbers. */
1362 must_parse_int (&(ieee
->h
));
1365 elts
= (ieee_ar_obstack_type
*) bfd_malloc (alc_elts
* sizeof *elts
);
1369 /* Read the index of the BB table. */
1373 ieee_ar_obstack_type
*t
;
1375 rec
= read_2bytes (&(ieee
->h
));
1376 if (rec
!= (int) ieee_assign_value_to_variable_enum
)
1379 if (ieee
->element_count
>= alc_elts
)
1381 ieee_ar_obstack_type
*n
;
1384 n
= ((ieee_ar_obstack_type
*)
1385 bfd_realloc (elts
, alc_elts
* sizeof *elts
));
1391 t
= &elts
[ieee
->element_count
];
1392 ieee
->element_count
++;
1394 must_parse_int (&(ieee
->h
));
1395 t
->file_offset
= must_parse_int (&(ieee
->h
));
1396 t
->abfd
= (bfd
*) NULL
;
1398 /* Make sure that we don't go over the end of the buffer. */
1399 if ((size_t) ieee_pos (abfd
) > sizeof (buffer
) / 2)
1401 /* Past half way, reseek and reprime. */
1402 buffer_offset
+= ieee_pos (abfd
);
1403 if (bfd_seek (abfd
, buffer_offset
, SEEK_SET
) != 0)
1406 /* FIXME: Check return value. I'm not sure whether it needs
1407 to read the entire buffer or not. */
1408 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1409 ieee
->h
.first_byte
= buffer
;
1410 ieee
->h
.input_p
= buffer
;
1414 ieee
->elements
= ((ieee_ar_obstack_type
*)
1416 ieee
->element_count
* sizeof *ieee
->elements
));
1417 if (ieee
->elements
== NULL
)
1420 memcpy (ieee
->elements
, elts
,
1421 ieee
->element_count
* sizeof *ieee
->elements
);
1425 /* Now scan the area again, and replace BB offsets with file offsets. */
1426 for (i
= 2; i
< ieee
->element_count
; i
++)
1428 if (bfd_seek (abfd
, ieee
->elements
[i
].file_offset
, SEEK_SET
) != 0)
1431 /* FIXME: Check return value. I'm not sure whether it needs to
1432 read the entire buffer or not. */
1433 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1434 ieee
->h
.first_byte
= buffer
;
1435 ieee
->h
.input_p
= buffer
;
1437 next_byte (&(ieee
->h
)); /* Drop F8. */
1438 next_byte (&(ieee
->h
)); /* Drop 14. */
1439 must_parse_int (&(ieee
->h
)); /* Drop size of block. */
1441 if (must_parse_int (&(ieee
->h
)) != 0)
1442 /* This object has been deleted. */
1443 ieee
->elements
[i
].file_offset
= 0;
1445 ieee
->elements
[i
].file_offset
= must_parse_int (&(ieee
->h
));
1448 /* abfd->has_armap = ;*/
1452 got_wrong_format_error
:
1453 bfd_release (abfd
, ieee
);
1454 abfd
->tdata
.ieee_ar_data
= save
;
1455 bfd_set_error (bfd_error_wrong_format
);
1465 ieee_mkobject (abfd
)
1468 abfd
->tdata
.ieee_data
= (ieee_data_type
*) bfd_zalloc (abfd
, sizeof (ieee_data_type
));
1469 return abfd
->tdata
.ieee_data
? true : false;
1473 ieee_object_p (abfd
)
1478 ieee_data_type
*ieee
;
1479 unsigned char buffer
[300];
1480 ieee_data_type
*save
= IEEE_DATA (abfd
);
1482 abfd
->tdata
.ieee_data
= 0;
1483 ieee_mkobject (abfd
);
1485 ieee
= IEEE_DATA (abfd
);
1486 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1488 /* Read the first few bytes in to see if it makes sense */
1489 /* FIXME: Check return value. I'm not sure whether it needs to read
1490 the entire buffer or not. */
1491 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1493 ieee
->h
.input_p
= buffer
;
1494 if (this_byte_and_next (&(ieee
->h
)) != Module_Beginning
)
1495 goto got_wrong_format
;
1497 ieee
->read_symbols
= false;
1498 ieee
->read_data
= false;
1499 ieee
->section_count
= 0;
1500 ieee
->external_symbol_max_index
= 0;
1501 ieee
->external_symbol_min_index
= IEEE_PUBLIC_BASE
;
1502 ieee
->external_reference_min_index
= IEEE_REFERENCE_BASE
;
1503 ieee
->external_reference_max_index
= 0;
1504 ieee
->h
.abfd
= abfd
;
1505 ieee
->section_table
= NULL
;
1506 ieee
->section_table_size
= 0;
1508 processor
= ieee
->mb
.processor
= read_id (&(ieee
->h
));
1509 if (strcmp (processor
, "LIBRARY") == 0)
1510 goto got_wrong_format
;
1511 ieee
->mb
.module_name
= read_id (&(ieee
->h
));
1512 if (abfd
->filename
== (CONST
char *) NULL
)
1514 abfd
->filename
= ieee
->mb
.module_name
;
1516 /* Determine the architecture and machine type of the object file.
1519 const bfd_arch_info_type
*arch
;
1522 /* IEEE does not specify the format of the processor identificaton
1523 string, so the compiler is free to put in it whatever it wants.
1524 We try here to recognize different processors belonging to the
1525 m68k family. Code for other processors can be added here. */
1526 if ((processor
[0] == '6') && (processor
[1] == '8'))
1528 if (processor
[2] == '3') /* 683xx integrated processors */
1530 switch (processor
[3])
1532 case '0': /* 68302, 68306, 68307 */
1533 case '2': /* 68322, 68328 */
1534 case '5': /* 68356 */
1535 strcpy (family
, "68000"); /* MC68000-based controllers */
1538 case '3': /* 68330, 68331, 68332, 68333,
1539 68334, 68335, 68336, 68338 */
1540 case '6': /* 68360 */
1541 case '7': /* 68376 */
1542 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1546 if (processor
[4] == '9') /* 68349 */
1547 strcpy (family
, "68030"); /* CPU030 */
1548 else /* 68340, 68341 */
1549 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1552 default: /* Does not exist yet */
1553 strcpy (family
, "68332"); /* Guess it will be CPU32 */
1556 else if (toupper (processor
[3]) == 'F') /* 68F333 */
1557 strcpy (family
, "68332"); /* CPU32 */
1558 else if ((toupper (processor
[3]) == 'C') /* Embedded controllers */
1559 && ((toupper (processor
[2]) == 'E')
1560 || (toupper (processor
[2]) == 'H')
1561 || (toupper (processor
[2]) == 'L')))
1563 strcpy (family
, "68");
1564 strncat (family
, processor
+ 4, 7);
1567 else /* "Regular" processors */
1569 strncpy (family
, processor
, 9);
1573 else if ((strncmp (processor
, "cpu32", 5) == 0) /* CPU32 and CPU32+ */
1574 || (strncmp (processor
, "CPU32", 5) == 0))
1575 strcpy (family
, "68332");
1578 strncpy (family
, processor
, 9);
1582 arch
= bfd_scan_arch (family
);
1584 goto got_wrong_format
;
1585 abfd
->arch_info
= arch
;
1588 if (this_byte (&(ieee
->h
)) != (int) ieee_address_descriptor_enum
)
1592 next_byte (&(ieee
->h
));
1594 if (parse_int (&(ieee
->h
), &ieee
->ad
.number_of_bits_mau
) == false)
1598 if (parse_int (&(ieee
->h
), &ieee
->ad
.number_of_maus_in_address
) == false)
1603 /* If there is a byte order info, take it */
1604 if (this_byte (&(ieee
->h
)) == (int) ieee_variable_L_enum
||
1605 this_byte (&(ieee
->h
)) == (int) ieee_variable_M_enum
)
1606 next_byte (&(ieee
->h
));
1608 for (part
= 0; part
< N_W_VARIABLES
; part
++)
1611 if (read_2bytes (&(ieee
->h
)) != (int) ieee_assign_value_to_variable_enum
)
1615 if (this_byte_and_next (&(ieee
->h
)) != part
)
1620 ieee
->w
.offset
[part
] = parse_i (&(ieee
->h
), &ok
);
1628 if (ieee
->w
.r
.external_part
!= 0)
1629 abfd
->flags
= HAS_SYMS
;
1631 /* By now we know that this is a real IEEE file, we're going to read
1632 the whole thing into memory so that we can run up and down it
1633 quickly. We can work out how big the file is from the trailer
1636 IEEE_DATA (abfd
)->h
.first_byte
=
1637 (unsigned char *) bfd_alloc (ieee
->h
.abfd
, ieee
->w
.r
.me_record
+ 1);
1638 if (!IEEE_DATA (abfd
)->h
.first_byte
)
1640 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1642 /* FIXME: Check return value. I'm not sure whether it needs to read
1643 the entire buffer or not. */
1644 bfd_read ((PTR
) (IEEE_DATA (abfd
)->h
.first_byte
), 1,
1645 ieee
->w
.r
.me_record
+ 1, abfd
);
1647 ieee_slurp_sections (abfd
);
1649 if (! ieee_slurp_debug (abfd
))
1652 /* Parse section data to activate file and section flags implied by
1653 section contents. */
1655 if (! ieee_slurp_section_data (abfd
))
1660 bfd_set_error (bfd_error_wrong_format
);
1662 (void) bfd_release (abfd
, ieee
);
1663 abfd
->tdata
.ieee_data
= save
;
1664 return (const bfd_target
*) NULL
;
1668 ieee_get_symbol_info (ignore_abfd
, symbol
, ret
)
1669 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
1673 bfd_symbol_info (symbol
, ret
);
1674 if (symbol
->name
[0] == ' ')
1675 ret
->name
= "* empty table entry ";
1676 if (!symbol
->section
)
1677 ret
->type
= (symbol
->flags
& BSF_LOCAL
) ? 'a' : 'A';
1681 ieee_print_symbol (ignore_abfd
, afile
, symbol
, how
)
1682 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
1685 bfd_print_symbol_type how
;
1687 FILE *file
= (FILE *) afile
;
1691 case bfd_print_symbol_name
:
1692 fprintf (file
, "%s", symbol
->name
);
1694 case bfd_print_symbol_more
:
1696 fprintf (file
, "%4x %2x", aout_symbol (symbol
)->desc
& 0xffff,
1697 aout_symbol (symbol
)->other
& 0xff);
1701 case bfd_print_symbol_all
:
1703 const char *section_name
=
1704 (symbol
->section
== (asection
*) NULL
1706 : symbol
->section
->name
);
1707 if (symbol
->name
[0] == ' ')
1709 fprintf (file
, "* empty table entry ");
1713 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
1715 fprintf (file
, " %-5s %04x %02x %s",
1717 (unsigned) ieee_symbol (symbol
)->index
,
1727 do_one (ieee
, current_map
, location_ptr
, s
, iterations
)
1728 ieee_data_type
*ieee
;
1729 ieee_per_section_type
*current_map
;
1730 unsigned char *location_ptr
;
1734 switch (this_byte (&(ieee
->h
)))
1736 case ieee_load_constant_bytes_enum
:
1738 unsigned int number_of_maus
;
1740 next_byte (&(ieee
->h
));
1741 number_of_maus
= must_parse_int (&(ieee
->h
));
1743 for (i
= 0; i
< number_of_maus
; i
++)
1745 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1746 next_byte (&(ieee
->h
));
1751 case ieee_load_with_relocation_enum
:
1753 boolean loop
= true;
1754 next_byte (&(ieee
->h
));
1757 switch (this_byte (&(ieee
->h
)))
1759 case ieee_variable_R_enum
:
1761 case ieee_function_signed_open_b_enum
:
1762 case ieee_function_unsigned_open_b_enum
:
1763 case ieee_function_either_open_b_enum
:
1765 unsigned int extra
= 4;
1766 boolean pcrel
= false;
1768 ieee_reloc_type
*r
=
1769 (ieee_reloc_type
*) bfd_alloc (ieee
->h
.abfd
,
1770 sizeof (ieee_reloc_type
));
1774 *(current_map
->reloc_tail_ptr
) = r
;
1775 current_map
->reloc_tail_ptr
= &r
->next
;
1776 r
->next
= (ieee_reloc_type
*) NULL
;
1777 next_byte (&(ieee
->h
));
1779 r
->relent
.sym_ptr_ptr
= 0;
1780 parse_expression (ieee
,
1783 &pcrel
, &extra
, §ion
);
1784 r
->relent
.address
= current_map
->pc
;
1785 s
->flags
|= SEC_RELOC
;
1786 s
->owner
->flags
|= HAS_RELOC
;
1788 if (r
->relent
.sym_ptr_ptr
== NULL
&& section
!= NULL
)
1789 r
->relent
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
1791 if (this_byte (&(ieee
->h
)) == (int) ieee_comma
)
1793 next_byte (&(ieee
->h
));
1794 /* Fetch number of bytes to pad */
1795 extra
= must_parse_int (&(ieee
->h
));
1798 switch (this_byte (&(ieee
->h
)))
1800 case ieee_function_signed_close_b_enum
:
1801 next_byte (&(ieee
->h
));
1803 case ieee_function_unsigned_close_b_enum
:
1804 next_byte (&(ieee
->h
));
1806 case ieee_function_either_close_b_enum
:
1807 next_byte (&(ieee
->h
));
1812 /* Build a relocation entry for this type */
1813 /* If pc rel then stick -ve pc into instruction
1814 and take out of reloc ..
1816 I've changed this. It's all too complicated. I
1817 keep 0 in the instruction now. */
1826 #if KEEPMINUSPCININST
1827 bfd_put_32 (ieee
->h
.abfd
, -current_map
->pc
, location_ptr
+
1829 r
->relent
.howto
= &rel32_howto
;
1833 bfd_put_32 (ieee
->h
.abfd
, 0, location_ptr
+
1835 r
->relent
.howto
= &rel32_howto
;
1840 bfd_put_32 (ieee
->h
.abfd
, 0, location_ptr
+
1842 r
->relent
.howto
= &abs32_howto
;
1844 current_map
->pc
+= 4;
1849 #if KEEPMINUSPCININST
1850 bfd_put_16 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1851 r
->relent
.addend
-= current_map
->pc
;
1852 r
->relent
.howto
= &rel16_howto
;
1855 bfd_put_16 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1856 r
->relent
.howto
= &rel16_howto
;
1862 bfd_put_16 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1863 r
->relent
.howto
= &abs16_howto
;
1865 current_map
->pc
+= 2;
1870 #if KEEPMINUSPCININST
1871 bfd_put_8 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1872 r
->relent
.addend
-= current_map
->pc
;
1873 r
->relent
.howto
= &rel8_howto
;
1875 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1876 r
->relent
.howto
= &rel8_howto
;
1881 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1882 r
->relent
.howto
= &abs8_howto
;
1884 current_map
->pc
+= 1;
1896 if (parse_int (&(ieee
->h
), &this_size
) == true)
1899 for (i
= 0; i
< this_size
; i
++)
1901 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1902 next_byte (&(ieee
->h
));
1912 /* Prevent more than the first load-item of an LR record
1913 from being repeated (MRI convention). */
1914 if (iterations
!= 1)
1922 /* Read in all the section data and relocation stuff too */
1924 ieee_slurp_section_data (abfd
)
1927 bfd_byte
*location_ptr
= (bfd_byte
*) NULL
;
1928 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1929 unsigned int section_number
;
1931 ieee_per_section_type
*current_map
= (ieee_per_section_type
*) NULL
;
1933 /* Seek to the start of the data area */
1934 if (ieee
->read_data
== true)
1936 ieee
->read_data
= true;
1937 ieee_seek (abfd
, ieee
->w
.r
.data_part
);
1939 /* Allocate enough space for all the section contents */
1941 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1943 ieee_per_section_type
*per
= (ieee_per_section_type
*) s
->used_by_bfd
;
1944 if ((s
->flags
& SEC_DEBUGGING
) != 0)
1946 per
->data
= (bfd_byte
*) bfd_alloc (ieee
->h
.abfd
, s
->_raw_size
);
1950 per
->reloc_tail_ptr
=
1951 (ieee_reloc_type
**) & (s
->relocation
);
1956 switch (this_byte (&(ieee
->h
)))
1958 /* IF we see anything strange then quit */
1962 case ieee_set_current_section_enum
:
1963 next_byte (&(ieee
->h
));
1964 section_number
= must_parse_int (&(ieee
->h
));
1965 s
= ieee
->section_table
[section_number
];
1966 s
->flags
|= SEC_LOAD
| SEC_HAS_CONTENTS
;
1967 current_map
= (ieee_per_section_type
*) s
->used_by_bfd
;
1968 location_ptr
= current_map
->data
- s
->vma
;
1969 /* The document I have says that Microtec's compilers reset */
1970 /* this after a sec section, even though the standard says not */
1972 current_map
->pc
= s
->vma
;
1975 case ieee_e2_first_byte_enum
:
1976 next_byte (&(ieee
->h
));
1977 switch (this_byte (&(ieee
->h
)))
1979 case ieee_set_current_pc_enum
& 0xff:
1982 ieee_symbol_index_type symbol
;
1985 next_byte (&(ieee
->h
));
1986 must_parse_int (&(ieee
->h
)); /* Thow away section #*/
1987 parse_expression (ieee
, &value
,
1991 current_map
->pc
= value
;
1992 BFD_ASSERT ((unsigned) (value
- s
->vma
) <= s
->_raw_size
);
1996 case ieee_value_starting_address_enum
& 0xff:
1997 next_byte (&(ieee
->h
));
1998 if (this_byte (&(ieee
->h
)) == ieee_function_either_open_b_enum
)
1999 next_byte (&(ieee
->h
));
2000 abfd
->start_address
= must_parse_int (&(ieee
->h
));
2001 /* We've got to the end of the data now - */
2008 case ieee_repeat_data_enum
:
2010 /* Repeat the following LD or LR n times - we do this by
2011 remembering the stream pointer before running it and
2012 resetting it and running it n times. We special case
2013 the repetition of a repeat_data/load_constant
2016 unsigned int iterations
;
2017 unsigned char *start
;
2018 next_byte (&(ieee
->h
));
2019 iterations
= must_parse_int (&(ieee
->h
));
2020 start
= ieee
->h
.input_p
;
2021 if (start
[0] == (int) ieee_load_constant_bytes_enum
&&
2024 while (iterations
!= 0)
2026 location_ptr
[current_map
->pc
++] = start
[2];
2029 next_byte (&(ieee
->h
));
2030 next_byte (&(ieee
->h
));
2031 next_byte (&(ieee
->h
));
2035 while (iterations
!= 0)
2037 ieee
->h
.input_p
= start
;
2038 if (!do_one (ieee
, current_map
, location_ptr
, s
,
2046 case ieee_load_constant_bytes_enum
:
2047 case ieee_load_with_relocation_enum
:
2049 if (!do_one (ieee
, current_map
, location_ptr
, s
, 1))
2057 ieee_new_section_hook (abfd
, newsect
)
2061 newsect
->used_by_bfd
= (PTR
)
2062 bfd_alloc (abfd
, sizeof (ieee_per_section_type
));
2063 if (!newsect
->used_by_bfd
)
2065 ieee_per_section (newsect
)->data
= (bfd_byte
*) NULL
;
2066 ieee_per_section (newsect
)->section
= newsect
;
2071 ieee_get_reloc_upper_bound (abfd
, asect
)
2075 if ((asect
->flags
& SEC_DEBUGGING
) != 0)
2077 if (! ieee_slurp_section_data (abfd
))
2079 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
2083 ieee_get_section_contents (abfd
, section
, location
, offset
, count
)
2088 bfd_size_type count
;
2090 ieee_per_section_type
*p
= (ieee_per_section_type
*) section
->used_by_bfd
;
2091 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2092 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2094 ieee_slurp_section_data (abfd
);
2095 (void) memcpy ((PTR
) location
, (PTR
) (p
->data
+ offset
), (unsigned) count
);
2100 ieee_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
2106 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
2107 ieee_reloc_type
*src
= (ieee_reloc_type
*) (section
->relocation
);
2108 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2110 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2113 while (src
!= (ieee_reloc_type
*) NULL
)
2115 /* Work out which symbol to attach it this reloc to */
2116 switch (src
->symbol
.letter
)
2119 src
->relent
.sym_ptr_ptr
=
2120 symbols
+ src
->symbol
.index
+ ieee
->external_symbol_base_offset
;
2123 src
->relent
.sym_ptr_ptr
=
2124 symbols
+ src
->symbol
.index
+ ieee
->external_reference_base_offset
;
2127 if (src
->relent
.sym_ptr_ptr
!= NULL
)
2128 src
->relent
.sym_ptr_ptr
=
2129 src
->relent
.sym_ptr_ptr
[0]->section
->symbol_ptr_ptr
;
2135 *relptr
++ = &src
->relent
;
2138 *relptr
= (arelent
*) NULL
;
2139 return section
->reloc_count
;
2147 arelent
*a
= *((arelent
**) ap
);
2148 arelent
*b
= *((arelent
**) bp
);
2149 return a
->address
- b
->address
;
2152 /* Write the section headers. */
2155 ieee_write_section_part (abfd
)
2158 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2160 ieee
->w
.r
.section_part
= bfd_tell (abfd
);
2161 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
2163 if (! bfd_is_abs_section (s
)
2164 && (s
->flags
& SEC_DEBUGGING
) == 0)
2166 if (! ieee_write_byte (abfd
, ieee_section_type_enum
)
2167 || ! ieee_write_byte (abfd
,
2168 (bfd_byte
) (s
->index
2169 + IEEE_SECTION_NUMBER_BASE
)))
2172 if (abfd
->flags
& EXEC_P
)
2174 /* This image is executable, so output absolute sections */
2175 if (! ieee_write_byte (abfd
, ieee_variable_A_enum
)
2176 || ! ieee_write_byte (abfd
, ieee_variable_S_enum
))
2181 if (! ieee_write_byte (abfd
, ieee_variable_C_enum
))
2185 switch (s
->flags
& (SEC_CODE
| SEC_DATA
| SEC_ROM
))
2187 case SEC_CODE
| SEC_LOAD
:
2189 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
))
2194 if (! ieee_write_byte (abfd
, ieee_variable_D_enum
))
2198 case SEC_ROM
| SEC_DATA
:
2199 case SEC_ROM
| SEC_LOAD
:
2200 case SEC_ROM
| SEC_DATA
| SEC_LOAD
:
2201 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
))
2206 if (! ieee_write_id (abfd
, s
->name
))
2209 ieee_write_int (abfd
, 0); /* Parent */
2210 ieee_write_int (abfd
, 0); /* Brother */
2211 ieee_write_int (abfd
, 0); /* Context */
2214 if (! ieee_write_byte (abfd
, ieee_section_alignment_enum
)
2215 || ! ieee_write_byte (abfd
,
2216 (bfd_byte
) (s
->index
2217 + IEEE_SECTION_NUMBER_BASE
))
2218 || ! ieee_write_int (abfd
, 1 << s
->alignment_power
))
2222 if (! ieee_write_2bytes (abfd
, ieee_section_size_enum
)
2223 || ! ieee_write_byte (abfd
,
2224 (bfd_byte
) (s
->index
2225 + IEEE_SECTION_NUMBER_BASE
))
2226 || ! ieee_write_int (abfd
, s
->_raw_size
))
2228 if (abfd
->flags
& EXEC_P
)
2230 /* Relocateable sections don't have asl records */
2232 if (! ieee_write_2bytes (abfd
, ieee_section_base_address_enum
)
2233 || ! ieee_write_byte (abfd
,
2236 + IEEE_SECTION_NUMBER_BASE
)))
2237 || ! ieee_write_int (abfd
, s
->lma
))
2248 do_with_relocs (abfd
, s
)
2252 unsigned int number_of_maus_in_address
=
2253 bfd_arch_bits_per_address (abfd
) / bfd_arch_bits_per_byte (abfd
);
2254 unsigned int relocs_to_go
= s
->reloc_count
;
2255 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2256 arelent
**p
= s
->orelocation
;
2257 bfd_size_type current_byte_index
= 0;
2259 qsort (s
->orelocation
,
2261 sizeof (arelent
**),
2264 /* Output the section preheader */
2265 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2266 || ! ieee_write_byte (abfd
,
2267 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
))
2268 || ! ieee_write_2bytes (abfd
, ieee_set_current_pc_enum
)
2269 || ! ieee_write_byte (abfd
,
2270 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
)))
2272 if ((abfd
->flags
& EXEC_P
) != 0 && relocs_to_go
== 0)
2274 if (! ieee_write_int (abfd
, s
->lma
))
2279 if (! ieee_write_expression (abfd
, 0, s
->symbol
, 0, 0))
2283 if (relocs_to_go
== 0)
2285 /* If there aren't any relocations then output the load constant
2286 byte opcode rather than the load with relocation opcode */
2288 while (current_byte_index
< s
->_raw_size
)
2291 unsigned int MAXRUN
= 127;
2293 if (run
> s
->_raw_size
- current_byte_index
)
2295 run
= s
->_raw_size
- current_byte_index
;
2300 if (! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
))
2302 /* Output a stream of bytes */
2303 if (! ieee_write_int (abfd
, run
))
2305 if (bfd_write ((PTR
) (stream
+ current_byte_index
),
2311 current_byte_index
+= run
;
2317 if (! ieee_write_byte (abfd
, ieee_load_with_relocation_enum
))
2320 /* Output the data stream as the longest sequence of bytes
2321 possible, allowing for the a reasonable packet size and
2322 relocation stuffs. */
2324 if ((PTR
) stream
== (PTR
) NULL
)
2326 /* Outputting a section without data, fill it up */
2327 stream
= (unsigned char *) (bfd_alloc (abfd
, s
->_raw_size
));
2330 memset ((PTR
) stream
, 0, (size_t) s
->_raw_size
);
2332 while (current_byte_index
< s
->_raw_size
)
2335 unsigned int MAXRUN
= 127;
2338 run
= (*p
)->address
- current_byte_index
;
2346 if (run
> s
->_raw_size
- current_byte_index
)
2348 run
= s
->_raw_size
- current_byte_index
;
2353 /* Output a stream of bytes */
2354 if (! ieee_write_int (abfd
, run
))
2356 if (bfd_write ((PTR
) (stream
+ current_byte_index
),
2362 current_byte_index
+= run
;
2364 /* Output any relocations here */
2365 if (relocs_to_go
&& (*p
) && (*p
)->address
== current_byte_index
)
2368 && (*p
) && (*p
)->address
== current_byte_index
)
2374 if (r
->howto
->pc_relative
)
2376 r
->addend
+= current_byte_index
;
2380 switch (r
->howto
->size
)
2384 ov
= bfd_get_signed_32 (abfd
,
2385 stream
+ current_byte_index
);
2386 current_byte_index
+= 4;
2389 ov
= bfd_get_signed_16 (abfd
,
2390 stream
+ current_byte_index
);
2391 current_byte_index
+= 2;
2394 ov
= bfd_get_signed_8 (abfd
,
2395 stream
+ current_byte_index
);
2396 current_byte_index
++;
2404 ov
&= r
->howto
->src_mask
;
2406 if (r
->howto
->pc_relative
2407 && ! r
->howto
->pcrel_offset
)
2410 if (! ieee_write_byte (abfd
,
2411 ieee_function_either_open_b_enum
))
2416 if (r
->sym_ptr_ptr
!= (asymbol
**) NULL
)
2418 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2420 r
->howto
->pc_relative
,
2426 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2428 r
->howto
->pc_relative
,
2433 if (number_of_maus_in_address
2434 != bfd_get_reloc_size (r
->howto
))
2436 if (! ieee_write_int (abfd
,
2437 bfd_get_reloc_size (r
->howto
)))
2440 if (! ieee_write_byte (abfd
,
2441 ieee_function_either_close_b_enum
))
2455 /* If there are no relocations in the output section then we can be
2456 clever about how we write. We block items up into a max of 127
2460 do_as_repeat (abfd
, s
)
2466 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2467 || ! ieee_write_byte (abfd
,
2468 (bfd_byte
) (s
->index
2469 + IEEE_SECTION_NUMBER_BASE
))
2470 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
>> 8)
2471 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
& 0xff)
2472 || ! ieee_write_byte (abfd
,
2473 (bfd_byte
) (s
->index
2474 + IEEE_SECTION_NUMBER_BASE
))
2475 || ! ieee_write_int (abfd
, s
->lma
)
2476 || ! ieee_write_byte (abfd
, ieee_repeat_data_enum
)
2477 || ! ieee_write_int (abfd
, s
->_raw_size
)
2478 || ! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
)
2479 || ! ieee_write_byte (abfd
, 1)
2480 || ! ieee_write_byte (abfd
, 0))
2488 do_without_relocs (abfd
, s
)
2492 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2494 if (stream
== 0 || ((s
->flags
& SEC_LOAD
) == 0))
2496 if (! do_as_repeat (abfd
, s
))
2502 for (i
= 0; i
< s
->_raw_size
; i
++)
2506 if (! do_with_relocs (abfd
, s
))
2511 if (! do_as_repeat (abfd
, s
))
2519 static unsigned char *output_ptr_start
;
2520 static unsigned char *output_ptr
;
2521 static unsigned char *output_ptr_end
;
2522 static unsigned char *input_ptr_start
;
2523 static unsigned char *input_ptr
;
2524 static unsigned char *input_ptr_end
;
2525 static bfd
*input_bfd
;
2526 static bfd
*output_bfd
;
2527 static int output_buffer
;
2532 /* FIXME: Check return value. I'm not sure whether it needs to read
2533 the entire buffer or not. */
2534 bfd_read ((PTR
) input_ptr_start
, 1, input_ptr_end
- input_ptr_start
, input_bfd
);
2535 input_ptr
= input_ptr_start
;
2540 if (bfd_write ((PTR
) (output_ptr_start
), 1, output_ptr
- output_ptr_start
,
2542 != (bfd_size_type
) (output_ptr
- output_ptr_start
))
2544 output_ptr
= output_ptr_start
;
2548 #define THIS() ( *input_ptr )
2549 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2550 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2556 if (value
>= 0 && value
<= 127)
2562 unsigned int length
;
2563 /* How many significant bytes ? */
2564 /* FIXME FOR LONGER INTS */
2565 if (value
& 0xff000000)
2569 else if (value
& 0x00ff0000)
2573 else if (value
& 0x0000ff00)
2580 OUT ((int) ieee_number_repeat_start_enum
+ length
);
2599 int length
= THIS ();
2611 #define VAR(x) ((x | 0x80))
2626 value
= (value
<< 8) | THIS ();
2628 value
= (value
<< 8) | THIS ();
2630 value
= (value
<< 8) | THIS ();
2638 value
= (value
<< 8) | THIS ();
2640 value
= (value
<< 8) | THIS ();
2648 value
= (value
<< 8) | THIS ();
2665 /* Not a number, just bug out with the answer */
2666 write_int (*(--tos
));
2676 int value
= *(--tos
);
2685 ieee_data_type
*ieee
;
2688 section_number
= THIS ();
2691 ieee
= IEEE_DATA (input_bfd
);
2692 s
= ieee
->section_table
[section_number
];
2693 if (s
->output_section
)
2695 value
= s
->output_section
->lma
;
2701 value
+= s
->output_offset
;
2709 write_int (*(--tos
));
2719 /* Drop the int in the buffer, and copy a null into the gap, which we
2720 will overwrite later */
2722 struct output_buffer_struct
2724 unsigned char *ptrp
;
2730 struct output_buffer_struct
*buf
;
2732 if (buf
->buffer
== output_buffer
)
2734 /* Still a chance to output the size */
2735 int value
= output_ptr
- buf
->ptrp
+ 3;
2736 buf
->ptrp
[0] = value
>> 24;
2737 buf
->ptrp
[1] = value
>> 16;
2738 buf
->ptrp
[2] = value
>> 8;
2739 buf
->ptrp
[3] = value
>> 0;
2745 struct output_buffer_struct
*buf
;
2771 buf
->ptrp
= output_ptr
;
2772 buf
->buffer
= output_buffer
;
2812 #define ID copy_id()
2813 #define INT copy_int()
2814 #define EXP copy_expression()
2815 static void copy_till_end ();
2816 #define INTn(q) copy_int()
2817 #define EXPn(q) copy_expression()
2856 EXPn (instruction address
);
2890 EXPn (external function
);
2900 INTn (locked
register);
2923 /* Attribute record */
2981 static void block ();
2993 /* Unique typedefs for module */
2994 /* GLobal typedefs */
2995 /* High level module scope beginning */
2997 struct output_buffer_struct ob
;
3012 /* Global function */
3014 struct output_buffer_struct ob
;
3028 EXPn (size of block
);
3034 /* File name for source line numbers */
3036 struct output_buffer_struct ob
;
3056 /* Local function */
3058 struct output_buffer_struct ob
;
3076 /* Assembler module scope beginning -*/
3078 struct output_buffer_struct ob
;
3104 struct output_buffer_struct ob
;
3111 INTn (section index
);
3119 EXPn (Size in Maus
);
3174 moves all the debug information from the source bfd to the output
3175 bfd, and relocates any expressions it finds
3179 relocate_debug (output
, input
)
3180 bfd
*output ATTRIBUTE_UNUSED
;
3185 unsigned char input_buffer
[IBS
];
3187 input_ptr_start
= input_ptr
= input_buffer
;
3188 input_ptr_end
= input_buffer
+ IBS
;
3190 /* FIXME: Check return value. I'm not sure whether it needs to read
3191 the entire buffer or not. */
3192 bfd_read ((PTR
) input_ptr_start
, 1, IBS
, input
);
3196 /* Gather together all the debug information from each input BFD into
3197 one place, relocating it and emitting it as we go. */
3200 ieee_write_debug_part (abfd
)
3203 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3204 bfd_chain_type
*chain
= ieee
->chain_root
;
3205 unsigned char output_buffer
[OBS
];
3206 boolean some_debug
= false;
3207 file_ptr here
= bfd_tell (abfd
);
3209 output_ptr_start
= output_ptr
= output_buffer
;
3210 output_ptr_end
= output_buffer
+ OBS
;
3211 output_ptr
= output_buffer
;
3214 if (chain
== (bfd_chain_type
*) NULL
)
3218 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3219 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3223 ieee
->w
.r
.debug_information_part
= 0;
3227 ieee
->w
.r
.debug_information_part
= here
;
3228 if (bfd_write (s
->contents
, 1, s
->_raw_size
, abfd
) != s
->_raw_size
)
3233 while (chain
!= (bfd_chain_type
*) NULL
)
3235 bfd
*entry
= chain
->this;
3236 ieee_data_type
*entry_ieee
= IEEE_DATA (entry
);
3237 if (entry_ieee
->w
.r
.debug_information_part
)
3239 if (bfd_seek (entry
, entry_ieee
->w
.r
.debug_information_part
,
3243 relocate_debug (abfd
, entry
);
3246 chain
= chain
->next
;
3250 ieee
->w
.r
.debug_information_part
= here
;
3254 ieee
->w
.r
.debug_information_part
= 0;
3263 /* Write the data in an ieee way. */
3266 ieee_write_data_part (abfd
)
3270 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3271 ieee
->w
.r
.data_part
= bfd_tell (abfd
);
3272 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3274 /* Skip sections that have no loadable contents (.bss,
3276 if ((s
->flags
& SEC_LOAD
) == 0)
3279 /* Sort the reloc records so we can insert them in the correct
3281 if (s
->reloc_count
!= 0)
3283 if (! do_with_relocs (abfd
, s
))
3288 if (! do_without_relocs (abfd
, s
))
3298 init_for_output (abfd
)
3302 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3304 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3306 if (s
->_raw_size
!= 0)
3308 ieee_per_section (s
)->data
= (bfd_byte
*) (bfd_alloc (abfd
, s
->_raw_size
));
3309 if (!ieee_per_section (s
)->data
)
3316 /** exec and core file sections */
3318 /* set section contents is complicated with IEEE since the format is
3319 * not a byte image, but a record stream.
3322 ieee_set_section_contents (abfd
, section
, location
, offset
, count
)
3327 bfd_size_type count
;
3329 if ((section
->flags
& SEC_DEBUGGING
) != 0)
3331 if (section
->contents
== NULL
)
3333 section
->contents
= ((unsigned char *)
3334 bfd_alloc (abfd
, section
->_raw_size
));
3335 if (section
->contents
== NULL
)
3338 /* bfd_set_section_contents has already checked that everything
3340 memcpy (section
->contents
+ offset
, location
, count
);
3344 if (ieee_per_section (section
)->data
== (bfd_byte
*) NULL
)
3346 if (!init_for_output (abfd
))
3349 memcpy ((PTR
) (ieee_per_section (section
)->data
+ offset
),
3351 (unsigned int) count
);
3355 /* Write the external symbols of a file. IEEE considers two sorts of
3356 external symbols, public, and referenced. It uses to internal
3357 forms to index them as well. When we write them out we turn their
3358 symbol values into indexes from the right base. */
3361 ieee_write_external_part (abfd
)
3365 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3367 unsigned int reference_index
= IEEE_REFERENCE_BASE
;
3368 unsigned int public_index
= IEEE_PUBLIC_BASE
+ 2;
3369 file_ptr here
= bfd_tell (abfd
);
3370 boolean hadone
= false;
3371 if (abfd
->outsymbols
!= (asymbol
**) NULL
)
3374 for (q
= abfd
->outsymbols
; *q
!= (asymbol
*) NULL
; q
++)
3377 if (bfd_is_und_section (p
->section
))
3379 /* This must be a symbol reference .. */
3380 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3381 || ! ieee_write_int (abfd
, reference_index
)
3382 || ! ieee_write_id (abfd
, p
->name
))
3384 p
->value
= reference_index
;
3388 else if (bfd_is_com_section (p
->section
))
3390 /* This is a weak reference */
3391 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3392 || ! ieee_write_int (abfd
, reference_index
)
3393 || ! ieee_write_id (abfd
, p
->name
)
3394 || ! ieee_write_byte (abfd
,
3395 ieee_weak_external_reference_enum
)
3396 || ! ieee_write_int (abfd
, reference_index
)
3397 || ! ieee_write_int (abfd
, p
->value
))
3399 p
->value
= reference_index
;
3403 else if (p
->flags
& BSF_GLOBAL
)
3405 /* This must be a symbol definition */
3407 if (! ieee_write_byte (abfd
, ieee_external_symbol_enum
)
3408 || ! ieee_write_int (abfd
, public_index
)
3409 || ! ieee_write_id (abfd
, p
->name
)
3410 || ! ieee_write_2bytes (abfd
, ieee_attribute_record_enum
)
3411 || ! ieee_write_int (abfd
, public_index
)
3412 || ! ieee_write_byte (abfd
, 15) /* instruction address */
3413 || ! ieee_write_byte (abfd
, 19) /* static symbol */
3414 || ! ieee_write_byte (abfd
, 1)) /* one of them */
3417 /* Write out the value */
3418 if (! ieee_write_2bytes (abfd
, ieee_value_record_enum
)
3419 || ! ieee_write_int (abfd
, public_index
))
3421 if (! bfd_is_abs_section (p
->section
))
3423 if (abfd
->flags
& EXEC_P
)
3425 /* If fully linked, then output all symbols
3427 if (! (ieee_write_int
3430 + p
->section
->output_offset
3431 + p
->section
->output_section
->vma
))))
3436 if (! (ieee_write_expression
3438 p
->value
+ p
->section
->output_offset
,
3439 p
->section
->output_section
->symbol
,
3446 if (! ieee_write_expression (abfd
,
3448 bfd_abs_section_ptr
->symbol
,
3452 p
->value
= public_index
;
3458 /* This can happen - when there are gaps in the symbols read */
3459 /* from an input ieee file */
3464 ieee
->w
.r
.external_part
= here
;
3470 static CONST
unsigned char exten
[] =
3473 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3474 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3475 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3478 static CONST
unsigned char envi
[] =
3482 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3485 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3487 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3488 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3492 ieee_write_me_part (abfd
)
3495 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3496 ieee
->w
.r
.trailer_part
= bfd_tell (abfd
);
3497 if (abfd
->start_address
)
3499 if (! ieee_write_2bytes (abfd
, ieee_value_starting_address_enum
)
3500 || ! ieee_write_byte (abfd
, ieee_function_either_open_b_enum
)
3501 || ! ieee_write_int (abfd
, abfd
->start_address
)
3502 || ! ieee_write_byte (abfd
, ieee_function_either_close_b_enum
))
3505 ieee
->w
.r
.me_record
= bfd_tell (abfd
);
3506 if (! ieee_write_byte (abfd
, ieee_module_end_enum
))
3511 /* Write out the IEEE processor ID. */
3514 ieee_write_processor (abfd
)
3517 const bfd_arch_info_type
*arch
;
3519 arch
= bfd_get_arch_info (abfd
);
3523 if (! ieee_write_id (abfd
, bfd_printable_name (abfd
)))
3528 if (! ieee_write_id (abfd
, "29000"))
3532 case bfd_arch_h8300
:
3533 if (! ieee_write_id (abfd
, "H8/300"))
3537 case bfd_arch_h8500
:
3538 if (! ieee_write_id (abfd
, "H8/500"))
3546 case bfd_mach_i960_core
:
3547 case bfd_mach_i960_ka_sa
:
3548 if (! ieee_write_id (abfd
, "80960KA"))
3552 case bfd_mach_i960_kb_sb
:
3553 if (! ieee_write_id (abfd
, "80960KB"))
3557 case bfd_mach_i960_ca
:
3558 if (! ieee_write_id (abfd
, "80960CA"))
3562 case bfd_mach_i960_mc
:
3563 case bfd_mach_i960_xa
:
3564 if (! ieee_write_id (abfd
, "80960MC"))
3576 default: id
= "68020"; break;
3577 case bfd_mach_m68000
: id
= "68000"; break;
3578 case bfd_mach_m68008
: id
= "68008"; break;
3579 case bfd_mach_m68010
: id
= "68010"; break;
3580 case bfd_mach_m68020
: id
= "68020"; break;
3581 case bfd_mach_m68030
: id
= "68030"; break;
3582 case bfd_mach_m68040
: id
= "68040"; break;
3583 case bfd_mach_m68060
: id
= "68060"; break;
3584 case bfd_mach_cpu32
: id
= "cpu32"; break;
3585 case bfd_mach_mcf5200
:id
= "5200"; break;
3586 case bfd_mach_mcf5206e
:id
= "5206e"; break;
3587 case bfd_mach_mcf5307
:id
= "5307"; break;
3588 case bfd_mach_mcf5407
:id
= "5407"; break;
3591 if (! ieee_write_id (abfd
, id
))
3601 ieee_write_object_contents (abfd
)
3604 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3608 /* Fast forward over the header area */
3609 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3612 if (! ieee_write_byte (abfd
, ieee_module_beginning_enum
)
3613 || ! ieee_write_processor (abfd
)
3614 || ! ieee_write_id (abfd
, abfd
->filename
))
3617 /* Fast forward over the variable bits */
3618 if (! ieee_write_byte (abfd
, ieee_address_descriptor_enum
))
3622 if (! ieee_write_byte (abfd
, (bfd_byte
) (bfd_arch_bits_per_byte (abfd
))))
3624 /* MAU's per address */
3625 if (! ieee_write_byte (abfd
,
3626 (bfd_byte
) (bfd_arch_bits_per_address (abfd
)
3627 / bfd_arch_bits_per_byte (abfd
))))
3630 old
= bfd_tell (abfd
);
3631 if (bfd_seek (abfd
, (file_ptr
) (8 * N_W_VARIABLES
), SEEK_CUR
) != 0)
3634 ieee
->w
.r
.extension_record
= bfd_tell (abfd
);
3635 if (bfd_write ((char *) exten
, 1, sizeof (exten
), abfd
) != sizeof (exten
))
3637 if (abfd
->flags
& EXEC_P
)
3639 if (! ieee_write_byte (abfd
, 0x1)) /* Absolute */
3644 if (! ieee_write_byte (abfd
, 0x2)) /* Relocateable */
3648 ieee
->w
.r
.environmental_record
= bfd_tell (abfd
);
3649 if (bfd_write ((char *) envi
, 1, sizeof (envi
), abfd
) != sizeof (envi
))
3652 /* The HP emulator database requires a timestamp in the file. */
3658 t
= (struct tm
*) localtime (&now
);
3659 if (! ieee_write_2bytes (abfd
, (int) ieee_atn_record_enum
)
3660 || ! ieee_write_byte (abfd
, 0x21)
3661 || ! ieee_write_byte (abfd
, 0)
3662 || ! ieee_write_byte (abfd
, 50)
3663 || ! ieee_write_int (abfd
, t
->tm_year
+ 1900)
3664 || ! ieee_write_int (abfd
, t
->tm_mon
+ 1)
3665 || ! ieee_write_int (abfd
, t
->tm_mday
)
3666 || ! ieee_write_int (abfd
, t
->tm_hour
)
3667 || ! ieee_write_int (abfd
, t
->tm_min
)
3668 || ! ieee_write_int (abfd
, t
->tm_sec
))
3676 if (! ieee_write_section_part (abfd
))
3678 /* First write the symbols. This changes their values into table
3679 indeces so we cant use it after this point. */
3680 if (! ieee_write_external_part (abfd
))
3683 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3685 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3688 /* Write any debugs we have been told about. */
3689 if (! ieee_write_debug_part (abfd
))
3692 /* Can only write the data once the symbols have been written, since
3693 the data contains relocation information which points to the
3695 if (! ieee_write_data_part (abfd
))
3698 /* At the end we put the end! */
3699 if (! ieee_write_me_part (abfd
))
3702 /* Generate the header */
3703 if (bfd_seek (abfd
, old
, SEEK_SET
) != 0)
3706 for (i
= 0; i
< N_W_VARIABLES
; i
++)
3708 if (! ieee_write_2bytes (abfd
, ieee_assign_value_to_variable_enum
)
3709 || ! ieee_write_byte (abfd
, (bfd_byte
) i
)
3710 || ! ieee_write_int5_out (abfd
, ieee
->w
.offset
[i
]))
3717 /* Native-level interface to symbols. */
3719 /* We read the symbols into a buffer, which is discarded when this
3720 function exits. We read the strings into a buffer large enough to
3721 hold them all plus all the cached symbol entries. */
3724 ieee_make_empty_symbol (abfd
)
3727 ieee_symbol_type
*new =
3728 (ieee_symbol_type
*) bfd_zalloc (abfd
, sizeof (ieee_symbol_type
));
3731 new->symbol
.the_bfd
= abfd
;
3732 return &new->symbol
;
3736 ieee_openr_next_archived_file (arch
, prev
)
3740 ieee_ar_data_type
*ar
= IEEE_AR_DATA (arch
);
3741 /* take the next one from the arch state, or reset */
3742 if (prev
== (bfd
*) NULL
)
3744 /* Reset the index - the first two entries are bogus*/
3745 ar
->element_index
= 2;
3749 ieee_ar_obstack_type
*p
= ar
->elements
+ ar
->element_index
;
3750 ar
->element_index
++;
3751 if (ar
->element_index
<= ar
->element_count
)
3753 if (p
->file_offset
!= (file_ptr
) 0)
3755 if (p
->abfd
== (bfd
*) NULL
)
3757 p
->abfd
= _bfd_create_empty_archive_element_shell (arch
);
3758 p
->abfd
->origin
= p
->file_offset
;
3765 bfd_set_error (bfd_error_no_more_archived_files
);
3766 return (bfd
*) NULL
;
3773 ieee_find_nearest_line (abfd
,
3780 bfd
*abfd ATTRIBUTE_UNUSED
;
3781 asection
*section ATTRIBUTE_UNUSED
;
3782 asymbol
**symbols ATTRIBUTE_UNUSED
;
3783 bfd_vma offset ATTRIBUTE_UNUSED
;
3784 const char **filename_ptr ATTRIBUTE_UNUSED
;
3785 const char **functionname_ptr ATTRIBUTE_UNUSED
;
3786 unsigned int *line_ptr ATTRIBUTE_UNUSED
;
3792 ieee_generic_stat_arch_elt (abfd
, buf
)
3796 ieee_ar_data_type
*ar
= (ieee_ar_data_type
*) NULL
;
3797 ieee_data_type
*ieee
;
3799 if (abfd
->my_archive
!= NULL
)
3800 ar
= abfd
->my_archive
->tdata
.ieee_ar_data
;
3801 if (ar
== (ieee_ar_data_type
*) NULL
)
3803 bfd_set_error (bfd_error_invalid_operation
);
3807 if (IEEE_DATA (abfd
) == NULL
)
3809 if (ieee_object_p (abfd
) == NULL
)
3811 bfd_set_error (bfd_error_wrong_format
);
3816 ieee
= IEEE_DATA (abfd
);
3818 buf
->st_size
= ieee
->w
.r
.me_record
+ 1;
3819 buf
->st_mode
= 0644;
3824 ieee_sizeof_headers (abfd
, x
)
3825 bfd
*abfd ATTRIBUTE_UNUSED
;
3826 boolean x ATTRIBUTE_UNUSED
;
3832 /* The debug info routines are never used. */
3836 ieee_bfd_debug_info_start (abfd
)
3843 ieee_bfd_debug_info_end (abfd
)
3850 /* Add this section to the list of sections we have debug info for, to
3851 be ready to output it at close time
3854 ieee_bfd_debug_info_accumulate (abfd
, section
)
3858 ieee_data_type
*ieee
= IEEE_DATA (section
->owner
);
3859 ieee_data_type
*output_ieee
= IEEE_DATA (abfd
);
3860 /* can only accumulate data from other ieee bfds */
3861 if (section
->owner
->xvec
!= abfd
->xvec
)
3863 /* Only bother once per bfd */
3864 if (ieee
->done_debug
== true)
3866 ieee
->done_debug
= true;
3868 /* Don't bother if there is no debug info */
3869 if (ieee
->w
.r
.debug_information_part
== 0)
3875 bfd_chain_type
*n
= (bfd_chain_type
*) bfd_alloc (abfd
, sizeof (bfd_chain_type
));
3877 abort (); /* FIXME */
3878 n
->this = section
->owner
;
3879 n
->next
= (bfd_chain_type
*) NULL
;
3881 if (output_ieee
->chain_head
)
3883 output_ieee
->chain_head
->next
= n
;
3887 output_ieee
->chain_root
= n
;
3890 output_ieee
->chain_head
= n
;
3896 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3897 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3899 #define ieee_slurp_armap bfd_true
3900 #define ieee_slurp_extended_name_table bfd_true
3901 #define ieee_construct_extended_name_table \
3902 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
3904 #define ieee_truncate_arname bfd_dont_truncate_arname
3905 #define ieee_write_armap \
3907 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3909 #define ieee_read_ar_hdr bfd_nullvoidptr
3910 #define ieee_update_armap_timestamp bfd_true
3911 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3913 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3914 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3915 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3916 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3917 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3919 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3921 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3923 #define ieee_get_section_contents_in_window \
3924 _bfd_generic_get_section_contents_in_window
3925 #define ieee_bfd_get_relocated_section_contents \
3926 bfd_generic_get_relocated_section_contents
3927 #define ieee_bfd_relax_section bfd_generic_relax_section
3928 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3929 #define ieee_bfd_merge_sections bfd_generic_merge_sections
3930 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3931 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3932 #define ieee_bfd_final_link _bfd_generic_final_link
3933 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3936 const bfd_target ieee_vec
=
3939 bfd_target_ieee_flavour
,
3940 BFD_ENDIAN_UNKNOWN
, /* target byte order */
3941 BFD_ENDIAN_UNKNOWN
, /* target headers byte order */
3942 (HAS_RELOC
| EXEC_P
| /* object flags */
3943 HAS_LINENO
| HAS_DEBUG
|
3944 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
3945 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
3946 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3947 '_', /* leading underscore */
3948 ' ', /* ar_pad_char */
3949 16, /* ar_max_namelen */
3950 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3951 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3952 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
3953 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3954 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3955 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
3958 ieee_object_p
, /* bfd_check_format */
3965 _bfd_generic_mkarchive
,
3970 ieee_write_object_contents
,
3971 _bfd_write_archive_contents
,
3975 BFD_JUMP_TABLE_GENERIC (ieee
),
3976 BFD_JUMP_TABLE_COPY (_bfd_generic
),
3977 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3978 BFD_JUMP_TABLE_ARCHIVE (ieee
),
3979 BFD_JUMP_TABLE_SYMBOLS (ieee
),
3980 BFD_JUMP_TABLE_RELOCS (ieee
),
3981 BFD_JUMP_TABLE_WRITE (ieee
),
3982 BFD_JUMP_TABLE_LINK (ieee
),
3983 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),