1 /* BFD back-end for ieee-695 objects.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 Written by Steve Chamberlain of Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #define KEEPMINUSPCININST 0
25 /* IEEE 695 format is a stream of records, which we parse using a simple one-
26 token (which is one byte in this lexicon) lookahead recursive decent
37 static boolean ieee_write_byte
PARAMS ((bfd
*, int));
38 static boolean ieee_write_2bytes
PARAMS ((bfd
*, int));
39 static boolean ieee_write_int
PARAMS ((bfd
*, bfd_vma
));
40 static boolean ieee_write_id
PARAMS ((bfd
*, const char *));
41 static boolean ieee_write_expression
42 PARAMS ((bfd
*, bfd_vma
, asymbol
*, boolean
, unsigned int));
43 static void ieee_write_int5
PARAMS ((bfd_byte
*, bfd_vma
));
44 static boolean ieee_write_int5_out
PARAMS ((bfd
*, bfd_vma
));
45 static boolean ieee_write_section_part
PARAMS ((bfd
*));
46 static boolean do_with_relocs
PARAMS ((bfd
*, asection
*));
47 static boolean do_as_repeat
PARAMS ((bfd
*, asection
*));
48 static boolean do_without_relocs
PARAMS ((bfd
*, asection
*));
49 static boolean ieee_write_external_part
PARAMS ((bfd
*));
50 static boolean ieee_write_data_part
PARAMS ((bfd
*));
51 static boolean ieee_write_debug_part
PARAMS ((bfd
*));
52 static boolean ieee_write_me_part
PARAMS ((bfd
*));
53 static boolean ieee_write_processor
PARAMS ((bfd
*));
55 static boolean ieee_slurp_debug
PARAMS ((bfd
*));
56 static boolean ieee_slurp_section_data
PARAMS ((bfd
*));
58 /* Functions for writing to ieee files in the strange way that the
62 ieee_write_byte (abfd
, barg
)
69 if (bfd_write ((PTR
) &byte
, 1, 1, abfd
) != 1)
75 ieee_write_2bytes (abfd
, bytes
)
81 buffer
[0] = bytes
>> 8;
82 buffer
[1] = bytes
& 0xff;
83 if (bfd_write ((PTR
) buffer
, 1, 2, abfd
) != 2)
89 ieee_write_int (abfd
, value
)
95 if (! ieee_write_byte (abfd
, (bfd_byte
) value
))
102 /* How many significant bytes ? */
103 /* FIXME FOR LONGER INTS */
104 if (value
& 0xff000000)
106 else if (value
& 0x00ff0000)
108 else if (value
& 0x0000ff00)
113 if (! ieee_write_byte (abfd
,
114 (bfd_byte
) ((int) ieee_number_repeat_start_enum
120 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 24)))
124 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 16)))
128 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 8)))
132 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
)))
141 ieee_write_id (abfd
, id
)
145 size_t length
= strlen (id
);
149 if (! ieee_write_byte (abfd
, (bfd_byte
) length
))
152 else if (length
< 255)
154 if (! ieee_write_byte (abfd
, ieee_extension_length_1_enum
)
155 || ! ieee_write_byte (abfd
, (bfd_byte
) length
))
158 else if (length
< 65535)
160 if (! ieee_write_byte (abfd
, ieee_extension_length_2_enum
)
161 || ! ieee_write_2bytes (abfd
, (int) length
))
166 (*_bfd_error_handler
)
167 (_("%s: string too long (%d chars, max 65535)"),
168 bfd_get_filename (abfd
), length
);
169 bfd_set_error (bfd_error_invalid_operation
);
173 if (bfd_write ((PTR
) id
, 1, length
, abfd
) != length
)
178 /***************************************************************************
179 Functions for reading from ieee files in the strange way that the
183 #define this_byte(ieee) *((ieee)->input_p)
184 #define next_byte(ieee) ((ieee)->input_p++)
185 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
187 static unsigned short
189 common_header_type
*ieee
;
191 unsigned char c1
= this_byte_and_next (ieee
);
192 unsigned char c2
= this_byte_and_next (ieee
);
193 return (c1
<< 8) | c2
;
197 bfd_get_string (ieee
, string
, length
)
198 common_header_type
*ieee
;
203 for (i
= 0; i
< length
; i
++)
205 string
[i
] = this_byte_and_next (ieee
);
211 common_header_type
*ieee
;
215 length
= this_byte_and_next (ieee
);
218 /* Simple string of length 0 to 127 */
220 else if (length
== 0xde)
222 /* Length is next byte, allowing 0..255 */
223 length
= this_byte_and_next (ieee
);
225 else if (length
== 0xdf)
227 /* Length is next two bytes, allowing 0..65535 */
228 length
= this_byte_and_next (ieee
);
229 length
= (length
* 256) + this_byte_and_next (ieee
);
231 /* Buy memory and read string */
232 string
= bfd_alloc (ieee
->abfd
, length
+ 1);
235 bfd_get_string (ieee
, string
, length
);
241 ieee_write_expression (abfd
, value
, symbol
, pcrel
, index
)
248 unsigned int term_count
= 0;
252 if (! ieee_write_int (abfd
, value
))
257 if (bfd_is_com_section (symbol
->section
)
258 || bfd_is_und_section (symbol
->section
))
260 /* Def of a common symbol */
261 if (! ieee_write_byte (abfd
, ieee_variable_X_enum
)
262 || ! ieee_write_int (abfd
, symbol
->value
))
266 else if (! bfd_is_abs_section (symbol
->section
))
268 /* Ref to defined symbol - */
270 if (symbol
->flags
& BSF_GLOBAL
)
272 if (! ieee_write_byte (abfd
, ieee_variable_I_enum
)
273 || ! ieee_write_int (abfd
, symbol
->value
))
277 else if (symbol
->flags
& (BSF_LOCAL
| BSF_SECTION_SYM
))
279 /* This is a reference to a defined local symbol. We can
280 easily do a local as a section+offset. */
281 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
)
282 || ! ieee_write_byte (abfd
,
283 (bfd_byte
) (symbol
->section
->index
284 + IEEE_SECTION_NUMBER_BASE
)))
287 if (symbol
->value
!= 0)
289 if (! ieee_write_int (abfd
, symbol
->value
))
296 (*_bfd_error_handler
)
297 (_("%s: unrecognized symbol `%s' flags 0x%x"),
298 bfd_get_filename (abfd
), bfd_asymbol_name (symbol
),
300 bfd_set_error (bfd_error_invalid_operation
);
307 /* subtract the pc from here by asking for PC of this section*/
308 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
)
309 || ! ieee_write_byte (abfd
,
310 (bfd_byte
) (index
+ IEEE_SECTION_NUMBER_BASE
))
311 || ! ieee_write_byte (abfd
, ieee_function_minus_enum
))
315 /* Handle the degenerate case of a 0 address. */
318 if (! ieee_write_int (abfd
, 0))
322 while (term_count
> 1)
324 if (! ieee_write_byte (abfd
, ieee_function_plus_enum
))
332 /*****************************************************************************/
335 writes any integer into the buffer supplied and always takes 5 bytes
338 ieee_write_int5 (buffer
, value
)
342 buffer
[0] = (bfd_byte
) ieee_number_repeat_4_enum
;
343 buffer
[1] = (value
>> 24) & 0xff;
344 buffer
[2] = (value
>> 16) & 0xff;
345 buffer
[3] = (value
>> 8) & 0xff;
346 buffer
[4] = (value
>> 0) & 0xff;
350 ieee_write_int5_out (abfd
, value
)
356 ieee_write_int5 (b
, value
);
357 if (bfd_write ((PTR
) b
, 1, 5, abfd
) != 5)
363 parse_int (ieee
, value_ptr
)
364 common_header_type
*ieee
;
367 int value
= this_byte (ieee
);
369 if (value
>= 0 && value
<= 127)
375 else if (value
>= 0x80 && value
<= 0x88)
377 unsigned int count
= value
& 0xf;
382 result
= (result
<< 8) | this_byte_and_next (ieee
);
393 common_header_type
*ieee
;
397 *ok
= parse_int (ieee
, &x
);
402 must_parse_int (ieee
)
403 common_header_type
*ieee
;
406 BFD_ASSERT (parse_int (ieee
, &result
) == true);
414 ieee_symbol_index_type symbol
;
418 #if KEEPMINUSPCININST
420 #define SRC_MASK(arg) arg
421 #define PCREL_OFFSET false
425 #define SRC_MASK(arg) 0
426 #define PCREL_OFFSET true
430 static reloc_howto_type abs32_howto
=
437 complain_overflow_bitfield
,
445 static reloc_howto_type abs16_howto
=
452 complain_overflow_bitfield
,
460 static reloc_howto_type abs8_howto
=
467 complain_overflow_bitfield
,
475 static reloc_howto_type rel32_howto
=
482 complain_overflow_signed
,
486 SRC_MASK (0xffffffff),
490 static reloc_howto_type rel16_howto
=
497 complain_overflow_signed
,
501 SRC_MASK (0x0000ffff),
505 static reloc_howto_type rel8_howto
=
512 complain_overflow_signed
,
516 SRC_MASK (0x000000ff),
520 static ieee_symbol_index_type NOSYMBOL
= {0, 0};
523 parse_expression (ieee
, value
, symbol
, pcrel
, extra
, section
)
524 ieee_data_type
*ieee
;
526 ieee_symbol_index_type
*symbol
;
539 ieee_value_type stack
[10];
541 /* The stack pointer always points to the next unused location */
542 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
543 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
544 ieee_value_type
*sp
= stack
;
548 switch (this_byte (&(ieee
->h
)))
550 case ieee_variable_P_enum
:
551 /* P variable, current program counter for section n */
554 next_byte (&(ieee
->h
));
556 section_n
= must_parse_int (&(ieee
->h
));
557 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, 0);
560 case ieee_variable_L_enum
:
561 /* L variable address of section N */
562 next_byte (&(ieee
->h
));
563 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
565 case ieee_variable_R_enum
:
566 /* R variable, logical address of section module */
567 /* FIXME, this should be different to L */
568 next_byte (&(ieee
->h
));
569 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
571 case ieee_variable_S_enum
:
572 /* S variable, size in MAUS of section module */
573 next_byte (&(ieee
->h
));
576 ieee
->section_table
[must_parse_int (&(ieee
->h
))]->_raw_size
);
578 case ieee_variable_I_enum
:
579 /* Push the address of variable n */
581 ieee_symbol_index_type sy
;
582 next_byte (&(ieee
->h
));
583 sy
.index
= (int) must_parse_int (&(ieee
->h
));
586 PUSH (sy
, bfd_abs_section_ptr
, 0);
589 case ieee_variable_X_enum
:
590 /* Push the address of external variable n */
592 ieee_symbol_index_type sy
;
593 next_byte (&(ieee
->h
));
594 sy
.index
= (int) (must_parse_int (&(ieee
->h
)));
597 PUSH (sy
, bfd_und_section_ptr
, 0);
600 case ieee_function_minus_enum
:
602 bfd_vma value1
, value2
;
603 asection
*section1
, *section_dummy
;
604 ieee_symbol_index_type sy
;
605 next_byte (&(ieee
->h
));
607 POP (sy
, section1
, value1
);
608 POP (sy
, section_dummy
, value2
);
609 PUSH (sy
, section1
? section1
: section_dummy
, value2
- value1
);
612 case ieee_function_plus_enum
:
614 bfd_vma value1
, value2
;
617 ieee_symbol_index_type sy1
;
618 ieee_symbol_index_type sy2
;
619 next_byte (&(ieee
->h
));
621 POP (sy1
, section1
, value1
);
622 POP (sy2
, section2
, value2
);
623 PUSH (sy1
.letter
? sy1
: sy2
,
624 bfd_is_abs_section (section1
) ? section2
: section1
,
631 BFD_ASSERT (this_byte (&(ieee
->h
)) < (int) ieee_variable_A_enum
632 || this_byte (&(ieee
->h
)) > (int) ieee_variable_Z_enum
);
633 if (parse_int (&(ieee
->h
), &va
))
635 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, va
);
640 Thats all that we can understand. As far as I can see
641 there is a bug in the Microtec IEEE output which I'm
642 using to scan, whereby the comma operator is omitted
643 sometimes in an expression, giving expressions with too
644 many terms. We can tell if that's the case by ensuring
645 that sp == stack here. If not, then we've pushed
646 something too far, so we keep adding. */
648 while (sp
!= stack
+ 1)
651 ieee_symbol_index_type sy1
;
652 POP (sy1
, section1
, *extra
);
657 POP (*symbol
, dummy
, *value
);
670 #define ieee_seek(abfd, offset) \
671 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
673 #define ieee_pos(abfd) \
674 (IEEE_DATA(abfd)->h.input_p - IEEE_DATA(abfd)->h.first_byte)
676 static unsigned int last_index
;
677 static char last_type
; /* is the index for an X or a D */
679 static ieee_symbol_type
*
689 ieee_data_type
*ieee
;
690 ieee_symbol_type
*last_symbol
;
691 unsigned int *symbol_count
;
692 ieee_symbol_type
***pptr
;
693 unsigned int *max_index
;
697 /* Need a new symbol */
698 unsigned int new_index
= must_parse_int (&(ieee
->h
));
699 if (new_index
!= last_index
|| this_type
!= last_type
)
701 ieee_symbol_type
*new_symbol
= (ieee_symbol_type
*) bfd_alloc (ieee
->h
.abfd
,
702 sizeof (ieee_symbol_type
));
706 new_symbol
->index
= new_index
;
707 last_index
= new_index
;
710 *pptr
= &new_symbol
->next
;
711 if (new_index
> *max_index
)
713 *max_index
= new_index
;
715 last_type
= this_type
;
716 new_symbol
->symbol
.section
= bfd_abs_section_ptr
;
723 ieee_slurp_external_symbols (abfd
)
726 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
727 file_ptr offset
= ieee
->w
.r
.external_part
;
729 ieee_symbol_type
**prev_symbols_ptr
= &ieee
->external_symbols
;
730 ieee_symbol_type
**prev_reference_ptr
= &ieee
->external_reference
;
731 ieee_symbol_type
*symbol
= (ieee_symbol_type
*) NULL
;
732 unsigned int symbol_count
= 0;
734 last_index
= 0xffffff;
735 ieee
->symbol_table_full
= true;
737 ieee_seek (abfd
, offset
);
741 switch (this_byte (&(ieee
->h
)))
744 next_byte (&(ieee
->h
));
746 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
748 &ieee
->external_symbol_max_index
, 'I');
752 symbol
->symbol
.the_bfd
= abfd
;
753 symbol
->symbol
.name
= read_id (&(ieee
->h
));
754 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
755 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
757 case ieee_external_symbol_enum
:
758 next_byte (&(ieee
->h
));
760 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
762 &ieee
->external_symbol_max_index
, 'D');
766 BFD_ASSERT (symbol
->index
>= ieee
->external_symbol_min_index
);
768 symbol
->symbol
.the_bfd
= abfd
;
769 symbol
->symbol
.name
= read_id (&(ieee
->h
));
770 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
771 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
773 case ieee_attribute_record_enum
>> 8:
775 unsigned int symbol_name_index
;
776 unsigned int symbol_type_index
;
777 unsigned int symbol_attribute_def
;
779 switch (read_2bytes (ieee
))
781 case ieee_attribute_record_enum
:
782 symbol_name_index
= must_parse_int (&(ieee
->h
));
783 symbol_type_index
= must_parse_int (&(ieee
->h
));
784 symbol_attribute_def
= must_parse_int (&(ieee
->h
));
785 switch (symbol_attribute_def
)
789 parse_int (&ieee
->h
, &value
);
792 (*_bfd_error_handler
)
793 (_("%s: unimplemented ATI record %u for symbol %u"),
794 bfd_get_filename (abfd
), symbol_attribute_def
,
796 bfd_set_error (bfd_error_bad_value
);
801 case ieee_external_reference_info_record_enum
:
802 /* Skip over ATX record. */
803 parse_int (&(ieee
->h
), &value
);
804 parse_int (&(ieee
->h
), &value
);
805 parse_int (&(ieee
->h
), &value
);
806 parse_int (&(ieee
->h
), &value
);
811 case ieee_value_record_enum
>> 8:
813 unsigned int symbol_name_index
;
814 ieee_symbol_index_type symbol_ignore
;
815 boolean pcrel_ignore
;
817 next_byte (&(ieee
->h
));
818 next_byte (&(ieee
->h
));
820 symbol_name_index
= must_parse_int (&(ieee
->h
));
821 parse_expression (ieee
,
822 &symbol
->symbol
.value
,
826 &symbol
->symbol
.section
);
828 /* Fully linked IEEE-695 files tend to give every symbol
829 an absolute value. Try to convert that back into a
830 section relative value. FIXME: This won't always to
832 if (bfd_is_abs_section (symbol
->symbol
.section
)
833 && (abfd
->flags
& HAS_RELOC
) == 0)
838 val
= symbol
->symbol
.value
;
839 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
841 if (val
>= s
->vma
&& val
< s
->vma
+ s
->_raw_size
)
843 symbol
->symbol
.section
= s
;
844 symbol
->symbol
.value
-= s
->vma
;
850 symbol
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
;
854 case ieee_weak_external_reference_enum
:
858 next_byte (&(ieee
->h
));
859 /* Throw away the external reference index */
860 (void) must_parse_int (&(ieee
->h
));
861 /* Fetch the default size if not resolved */
862 size
= must_parse_int (&(ieee
->h
));
863 /* Fetch the defautlt value if available */
864 if (parse_int (&(ieee
->h
), &value
) == false)
868 /* This turns into a common */
869 symbol
->symbol
.section
= bfd_com_section_ptr
;
870 symbol
->symbol
.value
= size
;
874 case ieee_external_reference_enum
:
875 next_byte (&(ieee
->h
));
877 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
879 &ieee
->external_reference_max_index
, 'X');
883 symbol
->symbol
.the_bfd
= abfd
;
884 symbol
->symbol
.name
= read_id (&(ieee
->h
));
885 symbol
->symbol
.udata
.p
= (PTR
) NULL
;
886 symbol
->symbol
.section
= bfd_und_section_ptr
;
887 symbol
->symbol
.value
= (bfd_vma
) 0;
888 symbol
->symbol
.flags
= 0;
890 BFD_ASSERT (symbol
->index
>= ieee
->external_reference_min_index
);
898 if (ieee
->external_symbol_max_index
!= 0)
900 ieee
->external_symbol_count
=
901 ieee
->external_symbol_max_index
-
902 ieee
->external_symbol_min_index
+ 1;
906 ieee
->external_symbol_count
= 0;
909 if (ieee
->external_reference_max_index
!= 0)
911 ieee
->external_reference_count
=
912 ieee
->external_reference_max_index
-
913 ieee
->external_reference_min_index
+ 1;
917 ieee
->external_reference_count
= 0;
921 ieee
->external_reference_count
+ ieee
->external_symbol_count
;
923 if (symbol_count
!= abfd
->symcount
)
925 /* There are gaps in the table -- */
926 ieee
->symbol_table_full
= false;
929 *prev_symbols_ptr
= (ieee_symbol_type
*) NULL
;
930 *prev_reference_ptr
= (ieee_symbol_type
*) NULL
;
936 ieee_slurp_symbol_table (abfd
)
939 if (IEEE_DATA (abfd
)->read_symbols
== false)
941 if (! ieee_slurp_external_symbols (abfd
))
943 IEEE_DATA (abfd
)->read_symbols
= true;
949 ieee_get_symtab_upper_bound (abfd
)
952 if (! ieee_slurp_symbol_table (abfd
))
955 return (abfd
->symcount
!= 0) ?
956 (abfd
->symcount
+ 1) * (sizeof (ieee_symbol_type
*)) : 0;
960 Move from our internal lists to the canon table, and insert in
964 extern const bfd_target ieee_vec
;
967 ieee_get_symtab (abfd
, location
)
971 ieee_symbol_type
*symp
;
972 static bfd dummy_bfd
;
973 static asymbol empty_symbol
=
974 /* the_bfd, name, value, attr, section */
975 {&dummy_bfd
, " ieee empty", (symvalue
) 0, BSF_DEBUGGING
, bfd_abs_section_ptr
};
979 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
980 dummy_bfd
.xvec
= &ieee_vec
;
981 if (! ieee_slurp_symbol_table (abfd
))
984 if (ieee
->symbol_table_full
== false)
986 /* Arrgh - there are gaps in the table, run through and fill them */
987 /* up with pointers to a null place */
989 for (i
= 0; i
< abfd
->symcount
; i
++)
991 location
[i
] = &empty_symbol
;
995 ieee
->external_symbol_base_offset
= -ieee
->external_symbol_min_index
;
996 for (symp
= IEEE_DATA (abfd
)->external_symbols
;
997 symp
!= (ieee_symbol_type
*) NULL
;
1000 /* Place into table at correct index locations */
1001 location
[symp
->index
+ ieee
->external_symbol_base_offset
] = &symp
->symbol
;
1004 /* The external refs are indexed in a bit */
1005 ieee
->external_reference_base_offset
=
1006 -ieee
->external_reference_min_index
+ ieee
->external_symbol_count
;
1008 for (symp
= IEEE_DATA (abfd
)->external_reference
;
1009 symp
!= (ieee_symbol_type
*) NULL
;
1012 location
[symp
->index
+ ieee
->external_reference_base_offset
] =
1019 location
[abfd
->symcount
] = (asymbol
*) NULL
;
1021 return abfd
->symcount
;
1025 get_section_entry (abfd
, ieee
, index
)
1027 ieee_data_type
*ieee
;
1030 if (index
>= ieee
->section_table_size
)
1035 c
= ieee
->section_table_size
;
1042 bfd_realloc (ieee
->section_table
, c
* sizeof (asection
*)));
1046 for (i
= ieee
->section_table_size
; i
< c
; i
++)
1049 ieee
->section_table
= n
;
1050 ieee
->section_table_size
= c
;
1053 if (ieee
->section_table
[index
] == (asection
*) NULL
)
1055 char *tmp
= bfd_alloc (abfd
, 11);
1060 sprintf (tmp
, " fsec%4d", index
);
1061 section
= bfd_make_section (abfd
, tmp
);
1062 ieee
->section_table
[index
] = section
;
1063 section
->flags
= SEC_NO_FLAGS
;
1064 section
->target_index
= index
;
1065 ieee
->section_table
[index
] = section
;
1067 return ieee
->section_table
[index
];
1071 ieee_slurp_sections (abfd
)
1074 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1075 file_ptr offset
= ieee
->w
.r
.section_part
;
1076 asection
*section
= (asection
*) NULL
;
1081 bfd_byte section_type
[3];
1082 ieee_seek (abfd
, offset
);
1085 switch (this_byte (&(ieee
->h
)))
1087 case ieee_section_type_enum
:
1089 unsigned int section_index
;
1090 next_byte (&(ieee
->h
));
1091 section_index
= must_parse_int (&(ieee
->h
));
1093 section
= get_section_entry (abfd
, ieee
, section_index
);
1095 section_type
[0] = this_byte_and_next (&(ieee
->h
));
1097 /* Set minimal section attributes. Attributes are
1098 extended later, based on section contents. */
1100 switch (section_type
[0])
1103 /* Normal attributes for absolute sections */
1104 section_type
[1] = this_byte (&(ieee
->h
));
1105 section
->flags
= SEC_ALLOC
;
1106 switch (section_type
[1])
1108 case 0xD3: /* AS Absolute section attributes */
1109 next_byte (&(ieee
->h
));
1110 section_type
[2] = this_byte (&(ieee
->h
));
1111 switch (section_type
[2])
1115 next_byte (&(ieee
->h
));
1116 section
->flags
|= SEC_CODE
;
1120 next_byte (&(ieee
->h
));
1121 section
->flags
|= SEC_DATA
;
1124 next_byte (&(ieee
->h
));
1125 /* Normal rom data */
1126 section
->flags
|= SEC_ROM
| SEC_DATA
;
1133 case 0xC3: /* Named relocatable sections (type C) */
1134 section_type
[1] = this_byte (&(ieee
->h
));
1135 section
->flags
= SEC_ALLOC
;
1136 switch (section_type
[1])
1138 case 0xD0: /* Normal code (CP) */
1139 next_byte (&(ieee
->h
));
1140 section
->flags
|= SEC_CODE
;
1142 case 0xC4: /* Normal data (CD) */
1143 next_byte (&(ieee
->h
));
1144 section
->flags
|= SEC_DATA
;
1146 case 0xD2: /* Normal rom data (CR) */
1147 next_byte (&(ieee
->h
));
1148 section
->flags
|= SEC_ROM
| SEC_DATA
;
1155 /* Read section name, use it if non empty. */
1156 name
= read_id (&ieee
->h
);
1158 section
->name
= name
;
1160 /* Skip these fields, which we don't care about */
1162 bfd_vma parent
, brother
, context
;
1163 parse_int (&(ieee
->h
), &parent
);
1164 parse_int (&(ieee
->h
), &brother
);
1165 parse_int (&(ieee
->h
), &context
);
1169 case ieee_section_alignment_enum
:
1171 unsigned int section_index
;
1174 next_byte (&(ieee
->h
));
1175 section_index
= must_parse_int (&ieee
->h
);
1176 section
= get_section_entry (abfd
, ieee
, section_index
);
1177 if (section_index
> ieee
->section_count
)
1179 ieee
->section_count
= section_index
;
1181 section
->alignment_power
=
1182 bfd_log2 (must_parse_int (&ieee
->h
));
1183 (void) parse_int (&(ieee
->h
), &value
);
1186 case ieee_e2_first_byte_enum
:
1188 ieee_record_enum_type t
= (ieee_record_enum_type
) (read_2bytes (&(ieee
->h
)));
1192 case ieee_section_size_enum
:
1193 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1194 section
->_raw_size
= must_parse_int (&(ieee
->h
));
1196 case ieee_physical_region_size_enum
:
1197 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1198 section
->_raw_size
= must_parse_int (&(ieee
->h
));
1200 case ieee_region_base_address_enum
:
1201 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1202 section
->vma
= must_parse_int (&(ieee
->h
));
1203 section
->lma
= section
->vma
;
1205 case ieee_mau_size_enum
:
1206 must_parse_int (&(ieee
->h
));
1207 must_parse_int (&(ieee
->h
));
1209 case ieee_m_value_enum
:
1210 must_parse_int (&(ieee
->h
));
1211 must_parse_int (&(ieee
->h
));
1213 case ieee_section_base_address_enum
:
1214 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1215 section
->vma
= must_parse_int (&(ieee
->h
));
1216 section
->lma
= section
->vma
;
1218 case ieee_section_offset_enum
:
1219 (void) must_parse_int (&(ieee
->h
));
1220 (void) must_parse_int (&(ieee
->h
));
1234 /* Make a section for the debugging information, if any. We don't try
1235 to interpret the debugging information; we just point the section
1236 at the area in the file so that program which understand can dig it
1240 ieee_slurp_debug (abfd
)
1243 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1246 if (ieee
->w
.r
.debug_information_part
== 0)
1249 sec
= bfd_make_section (abfd
, ".debug");
1252 sec
->flags
|= SEC_DEBUGGING
| SEC_HAS_CONTENTS
;
1253 sec
->filepos
= ieee
->w
.r
.debug_information_part
;
1254 sec
->_raw_size
= ieee
->w
.r
.data_part
- ieee
->w
.r
.debug_information_part
;
1259 /***********************************************************************
1264 ieee_archive_p (abfd
)
1269 unsigned char buffer
[512];
1270 file_ptr buffer_offset
= 0;
1271 ieee_ar_data_type
*save
= abfd
->tdata
.ieee_ar_data
;
1272 ieee_ar_data_type
*ieee
;
1273 unsigned int alc_elts
;
1274 ieee_ar_obstack_type
*elts
= NULL
;
1276 abfd
->tdata
.ieee_ar_data
=
1277 (ieee_ar_data_type
*) bfd_alloc (abfd
, sizeof (ieee_ar_data_type
));
1278 if (!abfd
->tdata
.ieee_ar_data
)
1280 ieee
= IEEE_AR_DATA (abfd
);
1282 /* FIXME: Check return value. I'm not sure whether it needs to read
1283 the entire buffer or not. */
1284 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1286 ieee
->h
.first_byte
= buffer
;
1287 ieee
->h
.input_p
= buffer
;
1289 ieee
->h
.abfd
= abfd
;
1291 if (this_byte (&(ieee
->h
)) != Module_Beginning
)
1293 abfd
->tdata
.ieee_ar_data
= save
;
1297 next_byte (&(ieee
->h
));
1298 library
= read_id (&(ieee
->h
));
1299 if (strcmp (library
, "LIBRARY") != 0)
1301 bfd_release (abfd
, ieee
);
1302 abfd
->tdata
.ieee_ar_data
= save
;
1305 /* Throw away the filename */
1306 read_id (&(ieee
->h
));
1308 ieee
->element_count
= 0;
1309 ieee
->element_index
= 0;
1311 next_byte (&(ieee
->h
)); /* Drop the ad part */
1312 must_parse_int (&(ieee
->h
)); /* And the two dummy numbers */
1313 must_parse_int (&(ieee
->h
));
1316 elts
= (ieee_ar_obstack_type
*) bfd_malloc (alc_elts
* sizeof *elts
);
1320 /* Read the index of the BB table */
1324 ieee_ar_obstack_type
*t
;
1326 rec
= read_2bytes (&(ieee
->h
));
1327 if (rec
!= (int) ieee_assign_value_to_variable_enum
)
1330 if (ieee
->element_count
>= alc_elts
)
1332 ieee_ar_obstack_type
*n
;
1335 n
= ((ieee_ar_obstack_type
*)
1336 bfd_realloc (elts
, alc_elts
* sizeof *elts
));
1342 t
= &elts
[ieee
->element_count
];
1343 ieee
->element_count
++;
1345 must_parse_int (&(ieee
->h
));
1346 t
->file_offset
= must_parse_int (&(ieee
->h
));
1347 t
->abfd
= (bfd
*) NULL
;
1349 /* Make sure that we don't go over the end of the buffer */
1351 if ((size_t) ieee_pos (abfd
) > sizeof (buffer
) / 2)
1353 /* Past half way, reseek and reprime */
1354 buffer_offset
+= ieee_pos (abfd
);
1355 if (bfd_seek (abfd
, buffer_offset
, SEEK_SET
) != 0)
1357 /* FIXME: Check return value. I'm not sure whether it needs
1358 to read the entire buffer or not. */
1359 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1360 ieee
->h
.first_byte
= buffer
;
1361 ieee
->h
.input_p
= buffer
;
1365 ieee
->elements
= ((ieee_ar_obstack_type
*)
1367 ieee
->element_count
* sizeof *ieee
->elements
));
1368 if (ieee
->elements
== NULL
)
1370 memcpy (ieee
->elements
, elts
,
1371 ieee
->element_count
* sizeof *ieee
->elements
);
1375 /* Now scan the area again, and replace BB offsets with file */
1378 for (i
= 2; i
< ieee
->element_count
; i
++)
1380 if (bfd_seek (abfd
, ieee
->elements
[i
].file_offset
, SEEK_SET
) != 0)
1382 /* FIXME: Check return value. I'm not sure whether it needs to
1383 read the entire buffer or not. */
1384 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1385 ieee
->h
.first_byte
= buffer
;
1386 ieee
->h
.input_p
= buffer
;
1388 next_byte (&(ieee
->h
)); /* Drop F8 */
1389 next_byte (&(ieee
->h
)); /* Drop 14 */
1390 must_parse_int (&(ieee
->h
)); /* Drop size of block */
1391 if (must_parse_int (&(ieee
->h
)) != 0)
1393 /* This object has been deleted */
1394 ieee
->elements
[i
].file_offset
= 0;
1398 ieee
->elements
[i
].file_offset
= must_parse_int (&(ieee
->h
));
1402 /* abfd->has_armap = ;*/
1413 ieee_mkobject (abfd
)
1416 abfd
->tdata
.ieee_data
= (ieee_data_type
*) bfd_zalloc (abfd
, sizeof (ieee_data_type
));
1417 return abfd
->tdata
.ieee_data
? true : false;
1421 ieee_object_p (abfd
)
1426 ieee_data_type
*ieee
;
1427 unsigned char buffer
[300];
1428 ieee_data_type
*save
= IEEE_DATA (abfd
);
1430 abfd
->tdata
.ieee_data
= 0;
1431 ieee_mkobject (abfd
);
1433 ieee
= IEEE_DATA (abfd
);
1434 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1436 /* Read the first few bytes in to see if it makes sense */
1437 /* FIXME: Check return value. I'm not sure whether it needs to read
1438 the entire buffer or not. */
1439 bfd_read ((PTR
) buffer
, 1, sizeof (buffer
), abfd
);
1441 ieee
->h
.input_p
= buffer
;
1442 if (this_byte_and_next (&(ieee
->h
)) != Module_Beginning
)
1443 goto got_wrong_format
;
1445 ieee
->read_symbols
= false;
1446 ieee
->read_data
= false;
1447 ieee
->section_count
= 0;
1448 ieee
->external_symbol_max_index
= 0;
1449 ieee
->external_symbol_min_index
= IEEE_PUBLIC_BASE
;
1450 ieee
->external_reference_min_index
= IEEE_REFERENCE_BASE
;
1451 ieee
->external_reference_max_index
= 0;
1452 ieee
->h
.abfd
= abfd
;
1453 ieee
->section_table
= NULL
;
1454 ieee
->section_table_size
= 0;
1456 processor
= ieee
->mb
.processor
= read_id (&(ieee
->h
));
1457 if (strcmp (processor
, "LIBRARY") == 0)
1458 goto got_wrong_format
;
1459 ieee
->mb
.module_name
= read_id (&(ieee
->h
));
1460 if (abfd
->filename
== (CONST
char *) NULL
)
1462 abfd
->filename
= ieee
->mb
.module_name
;
1464 /* Determine the architecture and machine type of the object file.
1467 const bfd_arch_info_type
*arch
;
1470 /* IEEE does not specify the format of the processor identificaton
1471 string, so the compiler is free to put in it whatever it wants.
1472 We try here to recognize different processors belonging to the
1473 m68k family. Code for other processors can be added here. */
1474 if ((processor
[0] == '6') && (processor
[1] == '8'))
1476 if (processor
[2] == '3') /* 683xx integrated processors */
1478 switch (processor
[3])
1480 case '0': /* 68302, 68306, 68307 */
1481 case '2': /* 68322, 68328 */
1482 case '5': /* 68356 */
1483 strcpy (family
, "68000"); /* MC68000-based controllers */
1486 case '3': /* 68330, 68331, 68332, 68333,
1487 68334, 68335, 68336, 68338 */
1488 case '6': /* 68360 */
1489 case '7': /* 68376 */
1490 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1494 if (processor
[4] == '9') /* 68349 */
1495 strcpy (family
, "68030"); /* CPU030 */
1496 else /* 68340, 68341 */
1497 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1500 default: /* Does not exist yet */
1501 strcpy (family
, "68332"); /* Guess it will be CPU32 */
1504 else if (toupper (processor
[3]) == 'F') /* 68F333 */
1505 strcpy (family
, "68332"); /* CPU32 */
1506 else if ((toupper (processor
[3]) == 'C') /* Embedded controllers */
1507 && ((toupper (processor
[2]) == 'E')
1508 || (toupper (processor
[2]) == 'H')
1509 || (toupper (processor
[2]) == 'L')))
1511 strcpy (family
, "68");
1512 strncat (family
, processor
+ 4, 7);
1515 else /* "Regular" processors */
1517 strncpy (family
, processor
, 9);
1521 else if ((strncmp (processor
, "cpu32", 5) == 0) /* CPU32 and CPU32+ */
1522 || (strncmp (processor
, "CPU32", 5) == 0))
1523 strcpy (family
, "68332");
1526 strncpy (family
, processor
, 9);
1530 arch
= bfd_scan_arch (family
);
1532 goto got_wrong_format
;
1533 abfd
->arch_info
= arch
;
1536 if (this_byte (&(ieee
->h
)) != (int) ieee_address_descriptor_enum
)
1540 next_byte (&(ieee
->h
));
1542 if (parse_int (&(ieee
->h
), &ieee
->ad
.number_of_bits_mau
) == false)
1546 if (parse_int (&(ieee
->h
), &ieee
->ad
.number_of_maus_in_address
) == false)
1551 /* If there is a byte order info, take it */
1552 if (this_byte (&(ieee
->h
)) == (int) ieee_variable_L_enum
||
1553 this_byte (&(ieee
->h
)) == (int) ieee_variable_M_enum
)
1554 next_byte (&(ieee
->h
));
1556 for (part
= 0; part
< N_W_VARIABLES
; part
++)
1559 if (read_2bytes (&(ieee
->h
)) != (int) ieee_assign_value_to_variable_enum
)
1563 if (this_byte_and_next (&(ieee
->h
)) != part
)
1568 ieee
->w
.offset
[part
] = parse_i (&(ieee
->h
), &ok
);
1576 if (ieee
->w
.r
.external_part
!= 0)
1577 abfd
->flags
= HAS_SYMS
;
1579 /* By now we know that this is a real IEEE file, we're going to read
1580 the whole thing into memory so that we can run up and down it
1581 quickly. We can work out how big the file is from the trailer
1584 IEEE_DATA (abfd
)->h
.first_byte
=
1585 (unsigned char *) bfd_alloc (ieee
->h
.abfd
, ieee
->w
.r
.me_record
+ 1);
1586 if (!IEEE_DATA (abfd
)->h
.first_byte
)
1588 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1590 /* FIXME: Check return value. I'm not sure whether it needs to read
1591 the entire buffer or not. */
1592 bfd_read ((PTR
) (IEEE_DATA (abfd
)->h
.first_byte
), 1,
1593 ieee
->w
.r
.me_record
+ 1, abfd
);
1595 ieee_slurp_sections (abfd
);
1597 if (! ieee_slurp_debug (abfd
))
1600 /* Parse section data to activate file and section flags implied by
1601 section contents. */
1603 if (! ieee_slurp_section_data (abfd
))
1608 bfd_set_error (bfd_error_wrong_format
);
1610 (void) bfd_release (abfd
, ieee
);
1611 abfd
->tdata
.ieee_data
= save
;
1612 return (const bfd_target
*) NULL
;
1616 ieee_get_symbol_info (ignore_abfd
, symbol
, ret
)
1621 bfd_symbol_info (symbol
, ret
);
1622 if (symbol
->name
[0] == ' ')
1623 ret
->name
= "* empty table entry ";
1624 if (!symbol
->section
)
1625 ret
->type
= (symbol
->flags
& BSF_LOCAL
) ? 'a' : 'A';
1629 ieee_print_symbol (ignore_abfd
, afile
, symbol
, how
)
1633 bfd_print_symbol_type how
;
1635 FILE *file
= (FILE *) afile
;
1639 case bfd_print_symbol_name
:
1640 fprintf (file
, "%s", symbol
->name
);
1642 case bfd_print_symbol_more
:
1644 fprintf (file
, "%4x %2x", aout_symbol (symbol
)->desc
& 0xffff,
1645 aout_symbol (symbol
)->other
& 0xff);
1649 case bfd_print_symbol_all
:
1651 const char *section_name
=
1652 (symbol
->section
== (asection
*) NULL
1654 : symbol
->section
->name
);
1655 if (symbol
->name
[0] == ' ')
1657 fprintf (file
, "* empty table entry ");
1661 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
1663 fprintf (file
, " %-5s %04x %02x %s",
1665 (unsigned) ieee_symbol (symbol
)->index
,
1675 do_one (ieee
, current_map
, location_ptr
, s
, iterations
)
1676 ieee_data_type
*ieee
;
1677 ieee_per_section_type
*current_map
;
1678 unsigned char *location_ptr
;
1682 switch (this_byte (&(ieee
->h
)))
1684 case ieee_load_constant_bytes_enum
:
1686 unsigned int number_of_maus
;
1688 next_byte (&(ieee
->h
));
1689 number_of_maus
= must_parse_int (&(ieee
->h
));
1691 for (i
= 0; i
< number_of_maus
; i
++)
1693 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1694 next_byte (&(ieee
->h
));
1699 case ieee_load_with_relocation_enum
:
1701 boolean loop
= true;
1702 next_byte (&(ieee
->h
));
1705 switch (this_byte (&(ieee
->h
)))
1707 case ieee_variable_R_enum
:
1709 case ieee_function_signed_open_b_enum
:
1710 case ieee_function_unsigned_open_b_enum
:
1711 case ieee_function_either_open_b_enum
:
1713 unsigned int extra
= 4;
1714 boolean pcrel
= false;
1716 ieee_reloc_type
*r
=
1717 (ieee_reloc_type
*) bfd_alloc (ieee
->h
.abfd
,
1718 sizeof (ieee_reloc_type
));
1722 *(current_map
->reloc_tail_ptr
) = r
;
1723 current_map
->reloc_tail_ptr
= &r
->next
;
1724 r
->next
= (ieee_reloc_type
*) NULL
;
1725 next_byte (&(ieee
->h
));
1727 r
->relent
.sym_ptr_ptr
= 0;
1728 parse_expression (ieee
,
1731 &pcrel
, &extra
, §ion
);
1732 r
->relent
.address
= current_map
->pc
;
1733 s
->flags
|= SEC_RELOC
;
1734 s
->owner
->flags
|= HAS_RELOC
;
1736 if (r
->relent
.sym_ptr_ptr
== NULL
&& section
!= NULL
)
1737 r
->relent
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
1739 if (this_byte (&(ieee
->h
)) == (int) ieee_comma
)
1741 next_byte (&(ieee
->h
));
1742 /* Fetch number of bytes to pad */
1743 extra
= must_parse_int (&(ieee
->h
));
1746 switch (this_byte (&(ieee
->h
)))
1748 case ieee_function_signed_close_b_enum
:
1749 next_byte (&(ieee
->h
));
1751 case ieee_function_unsigned_close_b_enum
:
1752 next_byte (&(ieee
->h
));
1754 case ieee_function_either_close_b_enum
:
1755 next_byte (&(ieee
->h
));
1760 /* Build a relocation entry for this type */
1761 /* If pc rel then stick -ve pc into instruction
1762 and take out of reloc ..
1764 I've changed this. It's all too complicated. I
1765 keep 0 in the instruction now. */
1774 #if KEEPMINUSPCININST
1775 bfd_put_32 (ieee
->h
.abfd
, -current_map
->pc
, location_ptr
+
1777 r
->relent
.howto
= &rel32_howto
;
1781 bfd_put_32 (ieee
->h
.abfd
, 0, location_ptr
+
1783 r
->relent
.howto
= &rel32_howto
;
1788 bfd_put_32 (ieee
->h
.abfd
, 0, location_ptr
+
1790 r
->relent
.howto
= &abs32_howto
;
1792 current_map
->pc
+= 4;
1797 #if KEEPMINUSPCININST
1798 bfd_put_16 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1799 r
->relent
.addend
-= current_map
->pc
;
1800 r
->relent
.howto
= &rel16_howto
;
1803 bfd_put_16 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1804 r
->relent
.howto
= &rel16_howto
;
1810 bfd_put_16 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1811 r
->relent
.howto
= &abs16_howto
;
1813 current_map
->pc
+= 2;
1818 #if KEEPMINUSPCININST
1819 bfd_put_8 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1820 r
->relent
.addend
-= current_map
->pc
;
1821 r
->relent
.howto
= &rel8_howto
;
1823 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1824 r
->relent
.howto
= &rel8_howto
;
1829 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1830 r
->relent
.howto
= &abs8_howto
;
1832 current_map
->pc
+= 1;
1844 if (parse_int (&(ieee
->h
), &this_size
) == true)
1847 for (i
= 0; i
< this_size
; i
++)
1849 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1850 next_byte (&(ieee
->h
));
1860 /* Prevent more than the first load-item of an LR record
1861 from being repeated (MRI convention). */
1862 if (iterations
!= 1)
1870 /* Read in all the section data and relocation stuff too */
1872 ieee_slurp_section_data (abfd
)
1875 bfd_byte
*location_ptr
= (bfd_byte
*) NULL
;
1876 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1877 unsigned int section_number
;
1879 ieee_per_section_type
*current_map
= (ieee_per_section_type
*) NULL
;
1881 /* Seek to the start of the data area */
1882 if (ieee
->read_data
== true)
1884 ieee
->read_data
= true;
1885 ieee_seek (abfd
, ieee
->w
.r
.data_part
);
1887 /* Allocate enough space for all the section contents */
1889 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1891 ieee_per_section_type
*per
= (ieee_per_section_type
*) s
->used_by_bfd
;
1892 if ((s
->flags
& SEC_DEBUGGING
) != 0)
1894 per
->data
= (bfd_byte
*) bfd_alloc (ieee
->h
.abfd
, s
->_raw_size
);
1898 per
->reloc_tail_ptr
=
1899 (ieee_reloc_type
**) & (s
->relocation
);
1904 switch (this_byte (&(ieee
->h
)))
1906 /* IF we see anything strange then quit */
1910 case ieee_set_current_section_enum
:
1911 next_byte (&(ieee
->h
));
1912 section_number
= must_parse_int (&(ieee
->h
));
1913 s
= ieee
->section_table
[section_number
];
1914 s
->flags
|= SEC_LOAD
| SEC_HAS_CONTENTS
;
1915 current_map
= (ieee_per_section_type
*) s
->used_by_bfd
;
1916 location_ptr
= current_map
->data
- s
->vma
;
1917 /* The document I have says that Microtec's compilers reset */
1918 /* this after a sec section, even though the standard says not */
1920 current_map
->pc
= s
->vma
;
1923 case ieee_e2_first_byte_enum
:
1924 next_byte (&(ieee
->h
));
1925 switch (this_byte (&(ieee
->h
)))
1927 case ieee_set_current_pc_enum
& 0xff:
1930 ieee_symbol_index_type symbol
;
1933 next_byte (&(ieee
->h
));
1934 must_parse_int (&(ieee
->h
)); /* Thow away section #*/
1935 parse_expression (ieee
, &value
,
1939 current_map
->pc
= value
;
1940 BFD_ASSERT ((unsigned) (value
- s
->vma
) <= s
->_raw_size
);
1944 case ieee_value_starting_address_enum
& 0xff:
1945 next_byte (&(ieee
->h
));
1946 if (this_byte (&(ieee
->h
)) == ieee_function_either_open_b_enum
)
1947 next_byte (&(ieee
->h
));
1948 abfd
->start_address
= must_parse_int (&(ieee
->h
));
1949 /* We've got to the end of the data now - */
1956 case ieee_repeat_data_enum
:
1958 /* Repeat the following LD or LR n times - we do this by
1959 remembering the stream pointer before running it and
1960 resetting it and running it n times. We special case
1961 the repetition of a repeat_data/load_constant
1964 unsigned int iterations
;
1965 unsigned char *start
;
1966 next_byte (&(ieee
->h
));
1967 iterations
= must_parse_int (&(ieee
->h
));
1968 start
= ieee
->h
.input_p
;
1969 if (start
[0] == (int) ieee_load_constant_bytes_enum
&&
1972 while (iterations
!= 0)
1974 location_ptr
[current_map
->pc
++] = start
[2];
1977 next_byte (&(ieee
->h
));
1978 next_byte (&(ieee
->h
));
1979 next_byte (&(ieee
->h
));
1983 while (iterations
!= 0)
1985 ieee
->h
.input_p
= start
;
1986 if (!do_one (ieee
, current_map
, location_ptr
, s
,
1994 case ieee_load_constant_bytes_enum
:
1995 case ieee_load_with_relocation_enum
:
1997 if (!do_one (ieee
, current_map
, location_ptr
, s
, 1))
2005 ieee_new_section_hook (abfd
, newsect
)
2009 newsect
->used_by_bfd
= (PTR
)
2010 bfd_alloc (abfd
, sizeof (ieee_per_section_type
));
2011 if (!newsect
->used_by_bfd
)
2013 ieee_per_section (newsect
)->data
= (bfd_byte
*) NULL
;
2014 ieee_per_section (newsect
)->section
= newsect
;
2019 ieee_get_reloc_upper_bound (abfd
, asect
)
2023 if ((asect
->flags
& SEC_DEBUGGING
) != 0)
2025 if (! ieee_slurp_section_data (abfd
))
2027 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
2031 ieee_get_section_contents (abfd
, section
, location
, offset
, count
)
2036 bfd_size_type count
;
2038 ieee_per_section_type
*p
= (ieee_per_section_type
*) section
->used_by_bfd
;
2039 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2040 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2042 ieee_slurp_section_data (abfd
);
2043 (void) memcpy ((PTR
) location
, (PTR
) (p
->data
+ offset
), (unsigned) count
);
2048 ieee_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
2054 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
2055 ieee_reloc_type
*src
= (ieee_reloc_type
*) (section
->relocation
);
2056 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2058 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2061 while (src
!= (ieee_reloc_type
*) NULL
)
2063 /* Work out which symbol to attach it this reloc to */
2064 switch (src
->symbol
.letter
)
2067 src
->relent
.sym_ptr_ptr
=
2068 symbols
+ src
->symbol
.index
+ ieee
->external_symbol_base_offset
;
2071 src
->relent
.sym_ptr_ptr
=
2072 symbols
+ src
->symbol
.index
+ ieee
->external_reference_base_offset
;
2075 if (src
->relent
.sym_ptr_ptr
!= NULL
)
2076 src
->relent
.sym_ptr_ptr
=
2077 src
->relent
.sym_ptr_ptr
[0]->section
->symbol_ptr_ptr
;
2083 *relptr
++ = &src
->relent
;
2086 *relptr
= (arelent
*) NULL
;
2087 return section
->reloc_count
;
2095 arelent
*a
= *((arelent
**) ap
);
2096 arelent
*b
= *((arelent
**) bp
);
2097 return a
->address
- b
->address
;
2100 /* Write the section headers. */
2103 ieee_write_section_part (abfd
)
2106 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2108 ieee
->w
.r
.section_part
= bfd_tell (abfd
);
2109 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
2111 if (! bfd_is_abs_section (s
)
2112 && (s
->flags
& SEC_DEBUGGING
) == 0)
2114 if (! ieee_write_byte (abfd
, ieee_section_type_enum
)
2115 || ! ieee_write_byte (abfd
,
2116 (bfd_byte
) (s
->index
2117 + IEEE_SECTION_NUMBER_BASE
)))
2120 if (abfd
->flags
& EXEC_P
)
2122 /* This image is executable, so output absolute sections */
2123 if (! ieee_write_byte (abfd
, ieee_variable_A_enum
)
2124 || ! ieee_write_byte (abfd
, ieee_variable_S_enum
))
2129 if (! ieee_write_byte (abfd
, ieee_variable_C_enum
))
2133 switch (s
->flags
& (SEC_CODE
| SEC_DATA
| SEC_ROM
))
2135 case SEC_CODE
| SEC_LOAD
:
2137 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
))
2142 if (! ieee_write_byte (abfd
, ieee_variable_D_enum
))
2146 case SEC_ROM
| SEC_DATA
:
2147 case SEC_ROM
| SEC_LOAD
:
2148 case SEC_ROM
| SEC_DATA
| SEC_LOAD
:
2149 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
))
2154 if (! ieee_write_id (abfd
, s
->name
))
2157 ieee_write_int (abfd
, 0); /* Parent */
2158 ieee_write_int (abfd
, 0); /* Brother */
2159 ieee_write_int (abfd
, 0); /* Context */
2162 if (! ieee_write_byte (abfd
, ieee_section_alignment_enum
)
2163 || ! ieee_write_byte (abfd
,
2164 (bfd_byte
) (s
->index
2165 + IEEE_SECTION_NUMBER_BASE
))
2166 || ! ieee_write_int (abfd
, 1 << s
->alignment_power
))
2170 if (! ieee_write_2bytes (abfd
, ieee_section_size_enum
)
2171 || ! ieee_write_byte (abfd
,
2172 (bfd_byte
) (s
->index
2173 + IEEE_SECTION_NUMBER_BASE
))
2174 || ! ieee_write_int (abfd
, s
->_raw_size
))
2176 if (abfd
->flags
& EXEC_P
)
2178 /* Relocateable sections don't have asl records */
2180 if (! ieee_write_2bytes (abfd
, ieee_section_base_address_enum
)
2181 || ! ieee_write_byte (abfd
,
2184 + IEEE_SECTION_NUMBER_BASE
)))
2185 || ! ieee_write_int (abfd
, s
->lma
))
2196 do_with_relocs (abfd
, s
)
2200 unsigned int number_of_maus_in_address
=
2201 bfd_arch_bits_per_address (abfd
) / bfd_arch_bits_per_byte (abfd
);
2202 unsigned int relocs_to_go
= s
->reloc_count
;
2203 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2204 arelent
**p
= s
->orelocation
;
2205 bfd_size_type current_byte_index
= 0;
2207 qsort (s
->orelocation
,
2209 sizeof (arelent
**),
2212 /* Output the section preheader */
2213 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2214 || ! ieee_write_byte (abfd
,
2215 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
))
2216 || ! ieee_write_2bytes (abfd
, ieee_set_current_pc_enum
)
2217 || ! ieee_write_byte (abfd
,
2218 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
)))
2220 if ((abfd
->flags
& EXEC_P
) != 0 && relocs_to_go
== 0)
2222 if (! ieee_write_int (abfd
, s
->lma
))
2227 if (! ieee_write_expression (abfd
, 0, s
->symbol
, 0, 0))
2231 if (relocs_to_go
== 0)
2233 /* If there aren't any relocations then output the load constant
2234 byte opcode rather than the load with relocation opcode */
2236 while (current_byte_index
< s
->_raw_size
)
2239 unsigned int MAXRUN
= 127;
2241 if (run
> s
->_raw_size
- current_byte_index
)
2243 run
= s
->_raw_size
- current_byte_index
;
2248 if (! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
))
2250 /* Output a stream of bytes */
2251 if (! ieee_write_int (abfd
, run
))
2253 if (bfd_write ((PTR
) (stream
+ current_byte_index
),
2259 current_byte_index
+= run
;
2265 if (! ieee_write_byte (abfd
, ieee_load_with_relocation_enum
))
2268 /* Output the data stream as the longest sequence of bytes
2269 possible, allowing for the a reasonable packet size and
2270 relocation stuffs. */
2272 if ((PTR
) stream
== (PTR
) NULL
)
2274 /* Outputting a section without data, fill it up */
2275 stream
= (unsigned char *) (bfd_alloc (abfd
, s
->_raw_size
));
2278 memset ((PTR
) stream
, 0, (size_t) s
->_raw_size
);
2280 while (current_byte_index
< s
->_raw_size
)
2283 unsigned int MAXRUN
= 127;
2286 run
= (*p
)->address
- current_byte_index
;
2294 if (run
> s
->_raw_size
- current_byte_index
)
2296 run
= s
->_raw_size
- current_byte_index
;
2301 /* Output a stream of bytes */
2302 if (! ieee_write_int (abfd
, run
))
2304 if (bfd_write ((PTR
) (stream
+ current_byte_index
),
2310 current_byte_index
+= run
;
2312 /* Output any relocations here */
2313 if (relocs_to_go
&& (*p
) && (*p
)->address
== current_byte_index
)
2316 && (*p
) && (*p
)->address
== current_byte_index
)
2322 if (r
->howto
->pc_relative
)
2324 r
->addend
+= current_byte_index
;
2328 switch (r
->howto
->size
)
2332 ov
= bfd_get_signed_32 (abfd
,
2333 stream
+ current_byte_index
);
2334 current_byte_index
+= 4;
2337 ov
= bfd_get_signed_16 (abfd
,
2338 stream
+ current_byte_index
);
2339 current_byte_index
+= 2;
2342 ov
= bfd_get_signed_8 (abfd
,
2343 stream
+ current_byte_index
);
2344 current_byte_index
++;
2352 ov
&= r
->howto
->src_mask
;
2354 if (r
->howto
->pc_relative
2355 && ! r
->howto
->pcrel_offset
)
2358 if (! ieee_write_byte (abfd
,
2359 ieee_function_either_open_b_enum
))
2364 if (r
->sym_ptr_ptr
!= (asymbol
**) NULL
)
2366 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2368 r
->howto
->pc_relative
,
2374 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2376 r
->howto
->pc_relative
,
2381 if (number_of_maus_in_address
2382 != bfd_get_reloc_size (r
->howto
))
2384 if (! ieee_write_int (abfd
,
2385 bfd_get_reloc_size (r
->howto
)))
2388 if (! ieee_write_byte (abfd
,
2389 ieee_function_either_close_b_enum
))
2403 /* If there are no relocations in the output section then we can be
2404 clever about how we write. We block items up into a max of 127
2408 do_as_repeat (abfd
, s
)
2414 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2415 || ! ieee_write_byte (abfd
,
2416 (bfd_byte
) (s
->index
2417 + IEEE_SECTION_NUMBER_BASE
))
2418 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
>> 8)
2419 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
& 0xff)
2420 || ! ieee_write_byte (abfd
,
2421 (bfd_byte
) (s
->index
2422 + IEEE_SECTION_NUMBER_BASE
))
2423 || ! ieee_write_int (abfd
, s
->lma
)
2424 || ! ieee_write_byte (abfd
, ieee_repeat_data_enum
)
2425 || ! ieee_write_int (abfd
, s
->_raw_size
)
2426 || ! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
)
2427 || ! ieee_write_byte (abfd
, 1)
2428 || ! ieee_write_byte (abfd
, 0))
2436 do_without_relocs (abfd
, s
)
2440 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2442 if (stream
== 0 || ((s
->flags
& SEC_LOAD
) == 0))
2444 if (! do_as_repeat (abfd
, s
))
2450 for (i
= 0; i
< s
->_raw_size
; i
++)
2454 if (! do_with_relocs (abfd
, s
))
2459 if (! do_as_repeat (abfd
, s
))
2467 static unsigned char *output_ptr_start
;
2468 static unsigned char *output_ptr
;
2469 static unsigned char *output_ptr_end
;
2470 static unsigned char *input_ptr_start
;
2471 static unsigned char *input_ptr
;
2472 static unsigned char *input_ptr_end
;
2473 static bfd
*input_bfd
;
2474 static bfd
*output_bfd
;
2475 static int output_buffer
;
2480 /* FIXME: Check return value. I'm not sure whether it needs to read
2481 the entire buffer or not. */
2482 bfd_read ((PTR
) input_ptr_start
, 1, input_ptr_end
- input_ptr_start
, input_bfd
);
2483 input_ptr
= input_ptr_start
;
2488 if (bfd_write ((PTR
) (output_ptr_start
), 1, output_ptr
- output_ptr_start
,
2490 != (bfd_size_type
) (output_ptr
- output_ptr_start
))
2492 output_ptr
= output_ptr_start
;
2496 #define THIS() ( *input_ptr )
2497 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2498 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2504 if (value
>= 0 && value
<= 127)
2510 unsigned int length
;
2511 /* How many significant bytes ? */
2512 /* FIXME FOR LONGER INTS */
2513 if (value
& 0xff000000)
2517 else if (value
& 0x00ff0000)
2521 else if (value
& 0x0000ff00)
2528 OUT ((int) ieee_number_repeat_start_enum
+ length
);
2547 int length
= THIS ();
2559 #define VAR(x) ((x | 0x80))
2574 value
= (value
<< 8) | THIS ();
2576 value
= (value
<< 8) | THIS ();
2578 value
= (value
<< 8) | THIS ();
2586 value
= (value
<< 8) | THIS ();
2588 value
= (value
<< 8) | THIS ();
2596 value
= (value
<< 8) | THIS ();
2613 /* Not a number, just bug out with the answer */
2614 write_int (*(--tos
));
2624 int value
= *(--tos
);
2633 ieee_data_type
*ieee
;
2636 section_number
= THIS ();
2639 ieee
= IEEE_DATA (input_bfd
);
2640 s
= ieee
->section_table
[section_number
];
2641 if (s
->output_section
)
2643 value
= s
->output_section
->lma
;
2649 value
+= s
->output_offset
;
2657 write_int (*(--tos
));
2667 /* Drop the int in the buffer, and copy a null into the gap, which we
2668 will overwrite later */
2670 struct output_buffer_struct
2672 unsigned char *ptrp
;
2678 struct output_buffer_struct
*buf
;
2680 if (buf
->buffer
== output_buffer
)
2682 /* Still a chance to output the size */
2683 int value
= output_ptr
- buf
->ptrp
+ 3;
2684 buf
->ptrp
[0] = value
>> 24;
2685 buf
->ptrp
[1] = value
>> 16;
2686 buf
->ptrp
[2] = value
>> 8;
2687 buf
->ptrp
[3] = value
>> 0;
2693 struct output_buffer_struct
*buf
;
2719 buf
->ptrp
= output_ptr
;
2720 buf
->buffer
= output_buffer
;
2760 #define ID copy_id()
2761 #define INT copy_int()
2762 #define EXP copy_expression()
2763 static void copy_till_end ();
2764 #define INTn(q) copy_int()
2765 #define EXPn(q) copy_expression()
2804 EXPn (instruction address
);
2838 EXPn (external function
);
2848 INTn (locked
register);
2871 /* Attribute record */
2929 static void block ();
2941 /* Unique typedefs for module */
2942 /* GLobal typedefs */
2943 /* High level module scope beginning */
2945 struct output_buffer_struct ob
;
2960 /* Global function */
2962 struct output_buffer_struct ob
;
2976 EXPn (size of block
);
2982 /* File name for source line numbers */
2984 struct output_buffer_struct ob
;
3004 /* Local function */
3006 struct output_buffer_struct ob
;
3024 /* Assembler module scope beginning -*/
3026 struct output_buffer_struct ob
;
3052 struct output_buffer_struct ob
;
3059 INTn (section index
);
3067 EXPn (Size in Maus
);
3122 moves all the debug information from the source bfd to the output
3123 bfd, and relocates any expressions it finds
3127 relocate_debug (output
, input
)
3133 unsigned char input_buffer
[IBS
];
3135 input_ptr_start
= input_ptr
= input_buffer
;
3136 input_ptr_end
= input_buffer
+ IBS
;
3138 /* FIXME: Check return value. I'm not sure whether it needs to read
3139 the entire buffer or not. */
3140 bfd_read ((PTR
) input_ptr_start
, 1, IBS
, input
);
3145 During linking, we we told about the bfds which made up our
3146 contents, we have a list of them. They will still be open, so go to
3147 the debug info in each, and copy it out, relocating it as we go.
3151 ieee_write_debug_part (abfd
)
3154 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3155 bfd_chain_type
*chain
= ieee
->chain_root
;
3156 unsigned char output_buffer
[OBS
];
3157 boolean some_debug
= false;
3158 file_ptr here
= bfd_tell (abfd
);
3160 output_ptr_start
= output_ptr
= output_buffer
;
3161 output_ptr_end
= output_buffer
+ OBS
;
3162 output_ptr
= output_buffer
;
3165 if (chain
== (bfd_chain_type
*) NULL
)
3169 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3170 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3174 ieee
->w
.r
.debug_information_part
= 0;
3178 ieee
->w
.r
.debug_information_part
= here
;
3179 if (bfd_write (s
->contents
, 1, s
->_raw_size
, abfd
) != s
->_raw_size
)
3184 while (chain
!= (bfd_chain_type
*) NULL
)
3186 bfd
*entry
= chain
->this;
3187 ieee_data_type
*entry_ieee
= IEEE_DATA (entry
);
3188 if (entry_ieee
->w
.r
.debug_information_part
)
3190 if (bfd_seek (entry
, entry_ieee
->w
.r
.debug_information_part
,
3194 relocate_debug (abfd
, entry
);
3197 chain
= chain
->next
;
3201 ieee
->w
.r
.debug_information_part
= here
;
3205 ieee
->w
.r
.debug_information_part
= 0;
3214 /* Write the data in an ieee way. */
3217 ieee_write_data_part (abfd
)
3221 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3222 ieee
->w
.r
.data_part
= bfd_tell (abfd
);
3223 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3225 /* Skip sections that have no loadable contents (.bss,
3227 if ((s
->flags
& SEC_LOAD
) == 0)
3230 /* Sort the reloc records so we can insert them in the correct
3232 if (s
->reloc_count
!= 0)
3234 if (! do_with_relocs (abfd
, s
))
3239 if (! do_without_relocs (abfd
, s
))
3249 init_for_output (abfd
)
3253 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3255 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3257 if (s
->_raw_size
!= 0)
3259 ieee_per_section (s
)->data
= (bfd_byte
*) (bfd_alloc (abfd
, s
->_raw_size
));
3260 if (!ieee_per_section (s
)->data
)
3267 /** exec and core file sections */
3269 /* set section contents is complicated with IEEE since the format is
3270 * not a byte image, but a record stream.
3273 ieee_set_section_contents (abfd
, section
, location
, offset
, count
)
3278 bfd_size_type count
;
3280 if ((section
->flags
& SEC_DEBUGGING
) != 0)
3282 if (section
->contents
== NULL
)
3284 section
->contents
= ((unsigned char *)
3285 bfd_alloc (abfd
, section
->_raw_size
));
3286 if (section
->contents
== NULL
)
3289 /* bfd_set_section_contents has already checked that everything
3291 memcpy (section
->contents
+ offset
, location
, count
);
3295 if (ieee_per_section (section
)->data
== (bfd_byte
*) NULL
)
3297 if (!init_for_output (abfd
))
3300 memcpy ((PTR
) (ieee_per_section (section
)->data
+ offset
),
3302 (unsigned int) count
);
3306 /* Write the external symbols of a file. IEEE considers two sorts of
3307 external symbols, public, and referenced. It uses to internal
3308 forms to index them as well. When we write them out we turn their
3309 symbol values into indexes from the right base. */
3312 ieee_write_external_part (abfd
)
3316 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3318 unsigned int reference_index
= IEEE_REFERENCE_BASE
;
3319 unsigned int public_index
= IEEE_PUBLIC_BASE
+ 2;
3320 file_ptr here
= bfd_tell (abfd
);
3321 boolean hadone
= false;
3322 if (abfd
->outsymbols
!= (asymbol
**) NULL
)
3325 for (q
= abfd
->outsymbols
; *q
!= (asymbol
*) NULL
; q
++)
3328 if (bfd_is_und_section (p
->section
))
3330 /* This must be a symbol reference .. */
3331 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3332 || ! ieee_write_int (abfd
, reference_index
)
3333 || ! ieee_write_id (abfd
, p
->name
))
3335 p
->value
= reference_index
;
3339 else if (bfd_is_com_section (p
->section
))
3341 /* This is a weak reference */
3342 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3343 || ! ieee_write_int (abfd
, reference_index
)
3344 || ! ieee_write_id (abfd
, p
->name
)
3345 || ! ieee_write_byte (abfd
,
3346 ieee_weak_external_reference_enum
)
3347 || ! ieee_write_int (abfd
, reference_index
)
3348 || ! ieee_write_int (abfd
, p
->value
))
3350 p
->value
= reference_index
;
3354 else if (p
->flags
& BSF_GLOBAL
)
3356 /* This must be a symbol definition */
3358 if (! ieee_write_byte (abfd
, ieee_external_symbol_enum
)
3359 || ! ieee_write_int (abfd
, public_index
)
3360 || ! ieee_write_id (abfd
, p
->name
)
3361 || ! ieee_write_2bytes (abfd
, ieee_attribute_record_enum
)
3362 || ! ieee_write_int (abfd
, public_index
)
3363 || ! ieee_write_byte (abfd
, 15) /* instruction address */
3364 || ! ieee_write_byte (abfd
, 19) /* static symbol */
3365 || ! ieee_write_byte (abfd
, 1)) /* one of them */
3368 /* Write out the value */
3369 if (! ieee_write_2bytes (abfd
, ieee_value_record_enum
)
3370 || ! ieee_write_int (abfd
, public_index
))
3372 if (! bfd_is_abs_section (p
->section
))
3374 if (abfd
->flags
& EXEC_P
)
3376 /* If fully linked, then output all symbols
3378 if (! (ieee_write_int
3381 + p
->section
->output_offset
3382 + p
->section
->output_section
->vma
))))
3387 if (! (ieee_write_expression
3389 p
->value
+ p
->section
->output_offset
,
3390 p
->section
->output_section
->symbol
,
3397 if (! ieee_write_expression (abfd
,
3399 bfd_abs_section_ptr
->symbol
,
3403 p
->value
= public_index
;
3409 /* This can happen - when there are gaps in the symbols read */
3410 /* from an input ieee file */
3415 ieee
->w
.r
.external_part
= here
;
3421 static CONST
unsigned char exten
[] =
3424 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3425 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3426 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3429 static CONST
unsigned char envi
[] =
3433 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3436 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3438 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3439 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3443 ieee_write_me_part (abfd
)
3446 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3447 ieee
->w
.r
.trailer_part
= bfd_tell (abfd
);
3448 if (abfd
->start_address
)
3450 if (! ieee_write_2bytes (abfd
, ieee_value_starting_address_enum
)
3451 || ! ieee_write_byte (abfd
, ieee_function_either_open_b_enum
)
3452 || ! ieee_write_int (abfd
, abfd
->start_address
)
3453 || ! ieee_write_byte (abfd
, ieee_function_either_close_b_enum
))
3456 ieee
->w
.r
.me_record
= bfd_tell (abfd
);
3457 if (! ieee_write_byte (abfd
, ieee_module_end_enum
))
3462 /* Write out the IEEE processor ID. */
3465 ieee_write_processor (abfd
)
3468 const bfd_arch_info_type
*arch
;
3470 arch
= bfd_get_arch_info (abfd
);
3474 if (! ieee_write_id (abfd
, bfd_printable_name (abfd
)))
3479 if (! ieee_write_id (abfd
, "29000"))
3483 case bfd_arch_h8300
:
3484 if (! ieee_write_id (abfd
, "H8/300"))
3488 case bfd_arch_h8500
:
3489 if (! ieee_write_id (abfd
, "H8/500"))
3497 case bfd_mach_i960_core
:
3498 case bfd_mach_i960_ka_sa
:
3499 if (! ieee_write_id (abfd
, "80960KA"))
3503 case bfd_mach_i960_kb_sb
:
3504 if (! ieee_write_id (abfd
, "80960KB"))
3508 case bfd_mach_i960_ca
:
3509 if (! ieee_write_id (abfd
, "80960CA"))
3513 case bfd_mach_i960_mc
:
3514 case bfd_mach_i960_xa
:
3515 if (! ieee_write_id (abfd
, "80960MC"))
3525 sprintf (ab
, "%lu", arch
->mach
);
3526 if (! ieee_write_id (abfd
, ab
))
3536 ieee_write_object_contents (abfd
)
3539 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3543 /* Fast forward over the header area */
3544 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3547 if (! ieee_write_byte (abfd
, ieee_module_beginning_enum
)
3548 || ! ieee_write_processor (abfd
)
3549 || ! ieee_write_id (abfd
, abfd
->filename
))
3552 /* Fast forward over the variable bits */
3553 if (! ieee_write_byte (abfd
, ieee_address_descriptor_enum
))
3557 if (! ieee_write_byte (abfd
, (bfd_byte
) (bfd_arch_bits_per_byte (abfd
))))
3559 /* MAU's per address */
3560 if (! ieee_write_byte (abfd
,
3561 (bfd_byte
) (bfd_arch_bits_per_address (abfd
)
3562 / bfd_arch_bits_per_byte (abfd
))))
3565 old
= bfd_tell (abfd
);
3566 if (bfd_seek (abfd
, (file_ptr
) (8 * N_W_VARIABLES
), SEEK_CUR
) != 0)
3569 ieee
->w
.r
.extension_record
= bfd_tell (abfd
);
3570 if (bfd_write ((char *) exten
, 1, sizeof (exten
), abfd
) != sizeof (exten
))
3572 if (abfd
->flags
& EXEC_P
)
3574 if (! ieee_write_byte (abfd
, 0x1)) /* Absolute */
3579 if (! ieee_write_byte (abfd
, 0x2)) /* Relocateable */
3583 ieee
->w
.r
.environmental_record
= bfd_tell (abfd
);
3584 if (bfd_write ((char *) envi
, 1, sizeof (envi
), abfd
) != sizeof (envi
))
3587 /* The HP emulator database requires a timestamp in the file. */
3593 t
= (struct tm
*) localtime (&now
);
3594 if (! ieee_write_2bytes (abfd
, (int) ieee_atn_record_enum
)
3595 || ! ieee_write_byte (abfd
, 0x21)
3596 || ! ieee_write_byte (abfd
, 0)
3597 || ! ieee_write_byte (abfd
, 50)
3598 || ! ieee_write_int (abfd
, t
->tm_year
+ 1900)
3599 || ! ieee_write_int (abfd
, t
->tm_mon
+ 1)
3600 || ! ieee_write_int (abfd
, t
->tm_mday
)
3601 || ! ieee_write_int (abfd
, t
->tm_hour
)
3602 || ! ieee_write_int (abfd
, t
->tm_min
)
3603 || ! ieee_write_int (abfd
, t
->tm_sec
))
3611 if (! ieee_write_section_part (abfd
))
3613 /* First write the symbols. This changes their values into table
3614 indeces so we cant use it after this point. */
3615 if (! ieee_write_external_part (abfd
))
3618 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3620 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3623 /* Write any debugs we have been told about. */
3624 if (! ieee_write_debug_part (abfd
))
3627 /* Can only write the data once the symbols have been written, since
3628 the data contains relocation information which points to the
3630 if (! ieee_write_data_part (abfd
))
3633 /* At the end we put the end! */
3634 if (! ieee_write_me_part (abfd
))
3637 /* Generate the header */
3638 if (bfd_seek (abfd
, old
, SEEK_SET
) != 0)
3641 for (i
= 0; i
< N_W_VARIABLES
; i
++)
3643 if (! ieee_write_2bytes (abfd
, ieee_assign_value_to_variable_enum
)
3644 || ! ieee_write_byte (abfd
, (bfd_byte
) i
)
3645 || ! ieee_write_int5_out (abfd
, ieee
->w
.offset
[i
]))
3652 /* Native-level interface to symbols. */
3654 /* We read the symbols into a buffer, which is discarded when this
3655 function exits. We read the strings into a buffer large enough to
3656 hold them all plus all the cached symbol entries. */
3659 ieee_make_empty_symbol (abfd
)
3662 ieee_symbol_type
*new =
3663 (ieee_symbol_type
*) bfd_zmalloc (sizeof (ieee_symbol_type
));
3666 new->symbol
.the_bfd
= abfd
;
3667 return &new->symbol
;
3671 ieee_openr_next_archived_file (arch
, prev
)
3675 ieee_ar_data_type
*ar
= IEEE_AR_DATA (arch
);
3676 /* take the next one from the arch state, or reset */
3677 if (prev
== (bfd
*) NULL
)
3679 /* Reset the index - the first two entries are bogus*/
3680 ar
->element_index
= 2;
3684 ieee_ar_obstack_type
*p
= ar
->elements
+ ar
->element_index
;
3685 ar
->element_index
++;
3686 if (ar
->element_index
<= ar
->element_count
)
3688 if (p
->file_offset
!= (file_ptr
) 0)
3690 if (p
->abfd
== (bfd
*) NULL
)
3692 p
->abfd
= _bfd_create_empty_archive_element_shell (arch
);
3693 p
->abfd
->origin
= p
->file_offset
;
3700 bfd_set_error (bfd_error_no_more_archived_files
);
3701 return (bfd
*) NULL
;
3708 ieee_find_nearest_line (abfd
,
3719 char **filename_ptr
;
3720 char **functionname_ptr
;
3727 ieee_generic_stat_arch_elt (abfd
, buf
)
3731 ieee_ar_data_type
*ar
= (ieee_ar_data_type
*) NULL
;
3732 ieee_data_type
*ieee
;
3734 if (abfd
->my_archive
!= NULL
)
3735 ar
= abfd
->my_archive
->tdata
.ieee_ar_data
;
3736 if (ar
== (ieee_ar_data_type
*) NULL
)
3738 bfd_set_error (bfd_error_invalid_operation
);
3742 if (IEEE_DATA (abfd
) == NULL
)
3744 if (ieee_object_p (abfd
) == NULL
)
3746 bfd_set_error (bfd_error_wrong_format
);
3751 ieee
= IEEE_DATA (abfd
);
3753 buf
->st_size
= ieee
->w
.r
.me_record
+ 1;
3754 buf
->st_mode
= 0644;
3759 ieee_sizeof_headers (abfd
, x
)
3767 /* The debug info routines are never used. */
3771 ieee_bfd_debug_info_start (abfd
)
3778 ieee_bfd_debug_info_end (abfd
)
3785 /* Add this section to the list of sections we have debug info for, to
3786 be ready to output it at close time
3789 ieee_bfd_debug_info_accumulate (abfd
, section
)
3793 ieee_data_type
*ieee
= IEEE_DATA (section
->owner
);
3794 ieee_data_type
*output_ieee
= IEEE_DATA (abfd
);
3795 /* can only accumulate data from other ieee bfds */
3796 if (section
->owner
->xvec
!= abfd
->xvec
)
3798 /* Only bother once per bfd */
3799 if (ieee
->done_debug
== true)
3801 ieee
->done_debug
= true;
3803 /* Don't bother if there is no debug info */
3804 if (ieee
->w
.r
.debug_information_part
== 0)
3810 bfd_chain_type
*n
= (bfd_chain_type
*) bfd_alloc (abfd
, sizeof (bfd_chain_type
));
3812 abort (); /* FIXME */
3813 n
->this = section
->owner
;
3814 n
->next
= (bfd_chain_type
*) NULL
;
3816 if (output_ieee
->chain_head
)
3818 output_ieee
->chain_head
->next
= n
;
3822 output_ieee
->chain_root
= n
;
3825 output_ieee
->chain_head
= n
;
3831 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3832 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3834 #define ieee_slurp_armap bfd_true
3835 #define ieee_slurp_extended_name_table bfd_true
3836 #define ieee_construct_extended_name_table \
3837 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
3839 #define ieee_truncate_arname bfd_dont_truncate_arname
3840 #define ieee_write_armap \
3842 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3844 #define ieee_read_ar_hdr bfd_nullvoidptr
3845 #define ieee_update_armap_timestamp bfd_true
3846 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3848 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3849 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3850 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3851 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3852 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3854 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3856 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3858 #define ieee_get_section_contents_in_window \
3859 _bfd_generic_get_section_contents_in_window
3860 #define ieee_bfd_get_relocated_section_contents \
3861 bfd_generic_get_relocated_section_contents
3862 #define ieee_bfd_relax_section bfd_generic_relax_section
3863 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3864 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3865 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3866 #define ieee_bfd_final_link _bfd_generic_final_link
3867 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3870 const bfd_target ieee_vec
=
3873 bfd_target_ieee_flavour
,
3874 BFD_ENDIAN_UNKNOWN
, /* target byte order */
3875 BFD_ENDIAN_UNKNOWN
, /* target headers byte order */
3876 (HAS_RELOC
| EXEC_P
| /* object flags */
3877 HAS_LINENO
| HAS_DEBUG
|
3878 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
3879 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
3880 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3881 '_', /* leading underscore */
3882 ' ', /* ar_pad_char */
3883 16, /* ar_max_namelen */
3884 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3885 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3886 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
3887 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3888 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3889 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
3892 ieee_object_p
, /* bfd_check_format */
3899 _bfd_generic_mkarchive
,
3904 ieee_write_object_contents
,
3905 _bfd_write_archive_contents
,
3909 BFD_JUMP_TABLE_GENERIC (ieee
),
3910 BFD_JUMP_TABLE_COPY (_bfd_generic
),
3911 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3912 BFD_JUMP_TABLE_ARCHIVE (ieee
),
3913 BFD_JUMP_TABLE_SYMBOLS (ieee
),
3914 BFD_JUMP_TABLE_RELOCS (ieee
),
3915 BFD_JUMP_TABLE_WRITE (ieee
),
3916 BFD_JUMP_TABLE_LINK (ieee
),
3917 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),