1 /* BFD back-end for ieee-695 objects.
2 Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
3 Written by Steve Chamberlain of Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define KEEPMINUSPCININST 0
23 /* IEEE 695 format is a stream of records, which we parse using a simple one-
24 token (which is one byte in this lexicon) lookahead recursive decent
33 #define obstack_chunk_alloc malloc
34 #define obstack_chunk_free free
36 /* Functions for writing to ieee files in the strange way that the
40 ieee_write_byte (abfd, byte)
44 bfd_write ((PTR) & byte, 1, 1, abfd);
48 ieee_write_twobyte (abfd, twobyte)
53 b[1] = twobyte & 0xff;
55 bfd_write ((PTR) & b[0], 1, 2, abfd);
59 ieee_write_2bytes (abfd, bytes)
64 buffer[0] = bytes >> 8;
65 buffer[1] = bytes & 0xff;
67 bfd_write ((PTR) buffer, 1, 2, abfd);
71 ieee_write_int (abfd, value)
75 if (((unsigned) value) <= 127)
77 ieee_write_byte (abfd, (bfd_byte) value);
82 /* How many significant bytes ? */
83 /* FIXME FOR LONGER INTS */
84 if (value & 0xff000000)
88 else if (value & 0x00ff0000)
92 else if (value & 0x0000ff00)
99 ieee_write_byte (abfd,
100 (bfd_byte) ((int) ieee_number_repeat_start_enum + length));
104 ieee_write_byte (abfd, (bfd_byte) (value >> 24));
106 ieee_write_byte (abfd, (bfd_byte) (value >> 16));
108 ieee_write_byte (abfd, (bfd_byte) (value >> 8));
110 ieee_write_byte (abfd, (bfd_byte) (value));
116 ieee_write_id (abfd, id)
120 size_t length = strlen (id);
123 ieee_write_byte (abfd, (bfd_byte) length);
125 else if (length < 255)
127 ieee_write_byte (abfd, ieee_extension_length_1_enum);
128 ieee_write_byte (abfd, (bfd_byte) length);
130 else if (length < 65535)
132 ieee_write_byte (abfd, ieee_extension_length_2_enum);
133 ieee_write_byte (abfd, (bfd_byte) (length >> 8));
134 ieee_write_byte (abfd, (bfd_byte) (length & 0xff));
140 bfd_write ((PTR) id, 1, length, abfd);
144 /***************************************************************************
145 Functions for reading from ieee files in the strange way that the
149 #define this_byte(ieee) *((ieee)->input_p)
150 #define next_byte(ieee) ((ieee)->input_p++)
151 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
153 static unsigned short
155 common_header_type *ieee;
157 unsigned char c1 = this_byte_and_next (ieee);
158 unsigned char c2 = this_byte_and_next (ieee);
159 return (c1 << 8) | c2;
163 bfd_get_string (ieee, string, length)
164 common_header_type *ieee;
169 for (i = 0; i < length; i++)
171 string[i] = this_byte_and_next (ieee);
177 common_header_type *ieee;
181 length = this_byte_and_next (ieee);
184 /* Simple string of length 0 to 127 */
186 else if (length == 0xde)
188 /* Length is next byte, allowing 0..255 */
189 length = this_byte_and_next (ieee);
191 else if (length == 0xdf)
193 /* Length is next two bytes, allowing 0..65535 */
194 length = this_byte_and_next (ieee);
195 length = (length * 256) + this_byte_and_next (ieee);
197 /* Buy memory and read string */
198 string = bfd_alloc (ieee->abfd, length + 1);
201 bfd_set_error (bfd_error_no_memory);
204 bfd_get_string (ieee, string, length);
210 ieee_write_expression (abfd, value, symbol, pcrel, index)
217 unsigned int term_count = 0;
221 ieee_write_int (abfd, value);
225 if (bfd_is_com_section (symbol->section)
226 || symbol->section == &bfd_und_section)
228 /* Def of a common symbol */
229 ieee_write_byte (abfd, ieee_variable_X_enum);
230 ieee_write_int (abfd, symbol->value);
233 else if (symbol->section != &bfd_abs_section)
235 /* Ref to defined symbol - */
237 ieee_write_byte (abfd, ieee_variable_R_enum);
238 ieee_write_byte (abfd,
239 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
241 if (symbol->flags & BSF_GLOBAL)
243 ieee_write_byte (abfd, ieee_variable_I_enum);
244 ieee_write_int (abfd, symbol->value);
247 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
249 /* This is a reference to a defined local symbol,
250 We can easily do a local as a section+offset */
251 ieee_write_byte (abfd, ieee_variable_R_enum); /* or L */
252 ieee_write_byte (abfd,
253 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
254 ieee_write_int (abfd, symbol->value);
265 /* subtract the pc from here by asking for PC of this section*/
266 ieee_write_byte (abfd, ieee_variable_P_enum);
267 ieee_write_byte (abfd, (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE));
268 ieee_write_byte (abfd, ieee_function_minus_enum);
273 ieee_write_byte (abfd, 0);
277 while (term_count > 1)
279 ieee_write_byte (abfd, ieee_function_plus_enum);
286 /*****************************************************************************/
289 writes any integer into the buffer supplied and always takes 5 bytes
292 ieee_write_int5 (buffer, value)
296 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
297 buffer[1] = (value >> 24) & 0xff;
298 buffer[2] = (value >> 16) & 0xff;
299 buffer[3] = (value >> 8) & 0xff;
300 buffer[4] = (value >> 0) & 0xff;
304 ieee_write_int5_out (abfd, value)
309 ieee_write_int5 (b, value);
310 bfd_write ((PTR) b, 1, 5, abfd);
314 parse_int (ieee, value_ptr)
315 common_header_type *ieee;
318 int value = this_byte (ieee);
320 if (value >= 0 && value <= 127)
326 else if (value >= 0x80 && value <= 0x88)
328 unsigned int count = value & 0xf;
333 result = (result << 8) | this_byte_and_next (ieee);
344 common_header_type *ieee;
348 *ok = parse_int (ieee, &x);
353 must_parse_int (ieee)
354 common_header_type *ieee;
357 BFD_ASSERT (parse_int (ieee, &result) == true);
365 ieee_symbol_index_type symbol;
370 reloc_howto_type abs32_howto
371 = HOWTO (1, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false);
373 reloc_howto_type abs16_howto
374 = HOWTO (1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false);
377 reloc_howto_type abs8_howto
378 = HOWTO (1, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false);
381 reloc_howto_type rel32_howto
382 = HOWTO (1, 0, 2, 32, true, 0, complain_overflow_signed, 0, "rel32", true, 0xffffffff,
386 reloc_howto_type rel16_howto
387 = HOWTO (1, 0, 1, 16, true, 0, complain_overflow_signed, 0, "rel16", true, 0x0000ffff, 0x0000ffff, false);
390 reloc_howto_type rel8_howto
391 = HOWTO (1, 0, 0, 8, true, 0, complain_overflow_signed, 0, "rel8", true, 0x000000ff, 0x000000ff, false);
394 static ieee_symbol_index_type NOSYMBOL =
399 parse_expression (ieee, value, symbol, pcrel, extra, section)
400 ieee_data_type *ieee;
402 ieee_symbol_index_type *symbol;
415 ieee_value_type stack[10];
417 /* The stack pointer always points to the next unused location */
418 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
419 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
420 ieee_value_type *sp = stack;
424 switch (this_byte (&(ieee->h)))
426 case ieee_variable_P_enum:
427 /* P variable, current program counter for section n */
430 next_byte (&(ieee->h));
432 section_n = must_parse_int (&(ieee->h));
433 PUSH (NOSYMBOL, &bfd_abs_section,
434 TOS.value = ieee->section_table[section_n]->vma +
435 ieee_per_section (ieee->section_table[section_n])->pc);
438 case ieee_variable_L_enum:
439 /* L variable address of section N */
440 next_byte (&(ieee->h));
441 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
443 case ieee_variable_R_enum:
444 /* R variable, logical address of section module */
445 /* FIXME, this should be different to L */
446 next_byte (&(ieee->h));
447 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
449 case ieee_variable_S_enum:
450 /* S variable, size in MAUS of section module */
451 next_byte (&(ieee->h));
454 ieee->section_table[must_parse_int (&(ieee->h))]->_raw_size);
456 case ieee_variable_I_enum:
457 case ieee_variable_X_enum:
458 /* Push the address of external variable n */
460 ieee_symbol_index_type sy;
461 next_byte (&(ieee->h));
462 sy.index = (int) (must_parse_int (&(ieee->h)));
465 PUSH (sy, &bfd_und_section, 0);
468 case ieee_function_minus_enum:
470 bfd_vma value1, value2;
471 asection *section1, *section_dummy;
472 ieee_symbol_index_type sy;
473 next_byte (&(ieee->h));
475 POP (sy, section1, value1);
476 POP (sy, section_dummy, value2);
477 PUSH (sy, section1 ? section1 : section_dummy, value1 - value2);
480 case ieee_function_plus_enum:
482 bfd_vma value1, value2;
485 ieee_symbol_index_type sy1;
486 ieee_symbol_index_type sy2;
487 next_byte (&(ieee->h));
489 POP (sy1, section1, value1);
490 POP (sy2, section2, value2);
491 PUSH (sy1.letter ? sy1 : sy2, section1 != &bfd_abs_section ? section1 : section2, value1 + value2);
497 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
498 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
499 if (parse_int (&(ieee->h), &va))
501 PUSH (NOSYMBOL, &bfd_abs_section, va);
506 Thats all that we can understand. As far as I can see
507 there is a bug in the Microtec IEEE output which I'm
508 using to scan, whereby the comma operator is omitted
509 sometimes in an expression, giving expressions with too
510 many terms. We can tell if that's the case by ensuring
511 that sp == stack here. If not, then we've pushed
512 something too far, so we keep adding. */
514 while (sp != stack + 1)
517 ieee_symbol_index_type sy1;
518 POP (sy1, section1, *extra);
523 POP (*symbol, dummy, *value);
536 #define ieee_seek(abfd, offset) \
537 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
539 #define ieee_pos(abfd) IEEE_DATA(abfd)->h.input_p -IEEE_DATA(abfd)->h.first_byte
541 static unsigned int last_index;
542 static char last_type; /* is the index for an X or a D */
544 static ieee_symbol_type *
554 ieee_data_type *ieee;
555 ieee_symbol_type *last_symbol;
556 unsigned int *symbol_count;
557 ieee_symbol_type ***pptr;
558 unsigned int *max_index;
562 /* Need a new symbol */
563 unsigned int new_index = must_parse_int (&(ieee->h));
564 if (new_index != last_index || this_type != last_type)
566 ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_alloc (ieee->h.abfd,
567 sizeof (ieee_symbol_type));
570 bfd_set_error (bfd_error_no_memory);
574 new_symbol->index = new_index;
575 last_index = new_index;
578 *pptr = &new_symbol->next;
579 if (new_index > *max_index)
581 *max_index = new_index;
583 last_type = this_type;
590 ieee_slurp_external_symbols (abfd)
593 ieee_data_type *ieee = IEEE_DATA (abfd);
594 file_ptr offset = ieee->w.r.external_part;
596 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
597 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
598 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
599 unsigned int symbol_count = 0;
601 last_index = 0xffffff;
602 ieee->symbol_table_full = true;
604 ieee_seek (abfd, offset);
608 switch (this_byte (&(ieee->h)))
611 next_byte (&(ieee->h));
613 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
615 &ieee->external_symbol_max_index, 'D');
619 symbol->symbol.the_bfd = abfd;
620 symbol->symbol.name = read_id (&(ieee->h));
621 symbol->symbol.udata = (PTR) NULL;
622 symbol->symbol.flags = BSF_NO_FLAGS;
624 case ieee_external_symbol_enum:
625 next_byte (&(ieee->h));
627 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
629 &ieee->external_symbol_max_index, 'D');
633 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
635 symbol->symbol.the_bfd = abfd;
636 symbol->symbol.name = read_id (&(ieee->h));
637 symbol->symbol.udata = (PTR) NULL;
638 symbol->symbol.flags = BSF_NO_FLAGS;
640 case ieee_attribute_record_enum >> 8:
642 unsigned int symbol_name_index;
643 unsigned int symbol_type_index;
644 unsigned int symbol_attribute_def;
646 next_byte (&(ieee->h)); /* Skip prefix */
647 next_byte (&(ieee->h));
648 symbol_name_index = must_parse_int (&(ieee->h));
649 symbol_type_index = must_parse_int (&(ieee->h));
650 symbol_attribute_def = must_parse_int (&(ieee->h));
651 switch (symbol_attribute_def)
654 /* Module misc; followed by two fields which describe the
655 current module block. The first fired is the type id
656 number, the second is the number of asn records
657 associated with the directive */
658 parse_int (&(ieee->h), &value);
659 parse_int (&(ieee->h), &value);
663 parse_int (&(ieee->h), &value);
668 case ieee_value_record_enum >> 8:
670 unsigned int symbol_name_index;
671 ieee_symbol_index_type symbol_ignore;
672 boolean pcrel_ignore;
674 next_byte (&(ieee->h));
675 next_byte (&(ieee->h));
677 symbol_name_index = must_parse_int (&(ieee->h));
678 parse_expression (ieee,
679 &symbol->symbol.value,
683 &symbol->symbol.section);
685 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
689 case ieee_weak_external_reference_enum:
693 next_byte (&(ieee->h));
694 /* Throw away the external reference index */
695 (void) must_parse_int (&(ieee->h));
696 /* Fetch the default size if not resolved */
697 size = must_parse_int (&(ieee->h));
698 /* Fetch the defautlt value if available */
699 if (parse_int (&(ieee->h), &value) == false)
703 /* This turns into a common */
704 symbol->symbol.section = &bfd_com_section;
705 symbol->symbol.value = size;
709 case ieee_external_reference_enum:
710 next_byte (&(ieee->h));
712 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
714 &ieee->external_reference_max_index, 'X');
718 symbol->symbol.the_bfd = abfd;
719 symbol->symbol.name = read_id (&(ieee->h));
720 symbol->symbol.udata = (PTR) NULL;
721 symbol->symbol.section = &bfd_und_section;
722 symbol->symbol.value = (bfd_vma) 0;
723 symbol->symbol.flags = 0;
725 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
733 if (ieee->external_symbol_max_index != 0)
735 ieee->external_symbol_count =
736 ieee->external_symbol_max_index -
737 ieee->external_symbol_min_index + 1;
741 ieee->external_symbol_count = 0;
744 if (ieee->external_reference_max_index != 0)
746 ieee->external_reference_count =
747 ieee->external_reference_max_index -
748 ieee->external_reference_min_index + 1;
752 ieee->external_reference_count = 0;
756 ieee->external_reference_count + ieee->external_symbol_count;
758 if (symbol_count != abfd->symcount)
760 /* There are gaps in the table -- */
761 ieee->symbol_table_full = false;
764 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
765 *prev_reference_ptr = (ieee_symbol_type *) NULL;
771 ieee_slurp_symbol_table (abfd)
774 if (IEEE_DATA (abfd)->read_symbols == false)
776 if (! ieee_slurp_external_symbols (abfd))
778 IEEE_DATA (abfd)->read_symbols = true;
784 ieee_get_symtab_upper_bound (abfd)
787 if (! ieee_slurp_symbol_table (abfd))
790 return (abfd->symcount != 0) ?
791 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
795 Move from our internal lists to the canon table, and insert in
799 extern bfd_target ieee_vec;
802 ieee_get_symtab (abfd, location)
806 ieee_symbol_type *symp;
807 static bfd dummy_bfd;
808 static asymbol empty_symbol =
809 /* the_bfd, name, value, attr, section */
810 {&dummy_bfd, " ieee empty", (symvalue) 0, BSF_DEBUGGING, &bfd_abs_section};
814 ieee_data_type *ieee = IEEE_DATA (abfd);
815 dummy_bfd.xvec = &ieee_vec;
816 if (! ieee_slurp_symbol_table (abfd))
819 if (ieee->symbol_table_full == false)
821 /* Arrgh - there are gaps in the table, run through and fill them */
822 /* up with pointers to a null place */
824 for (i = 0; i < abfd->symcount; i++)
826 location[i] = &empty_symbol;
830 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
831 for (symp = IEEE_DATA (abfd)->external_symbols;
832 symp != (ieee_symbol_type *) NULL;
835 /* Place into table at correct index locations */
836 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
839 /* The external refs are indexed in a bit */
840 ieee->external_reference_base_offset =
841 -ieee->external_reference_min_index + ieee->external_symbol_count;
843 for (symp = IEEE_DATA (abfd)->external_reference;
844 symp != (ieee_symbol_type *) NULL;
847 location[symp->index + ieee->external_reference_base_offset] =
854 location[abfd->symcount] = (asymbol *) NULL;
856 return abfd->symcount;
860 get_section_entry (abfd, ieee, index)
862 ieee_data_type *ieee;
865 if (ieee->section_table[index] == (asection *) NULL)
867 char *tmp = bfd_alloc (abfd, 11);
872 bfd_set_error (bfd_error_no_memory);
875 sprintf (tmp, " fsec%4d", index);
876 section = bfd_make_section (abfd, tmp);
877 ieee->section_table[index] = section;
878 section->flags = SEC_NO_FLAGS;
879 section->target_index = index;
880 ieee->section_table[index] = section;
882 return ieee->section_table[index];
886 ieee_slurp_sections (abfd)
889 ieee_data_type *ieee = IEEE_DATA (abfd);
890 file_ptr offset = ieee->w.r.section_part;
891 asection *section = (asection *) NULL;
896 bfd_byte section_type[3];
897 ieee_seek (abfd, offset);
900 switch (this_byte (&(ieee->h)))
902 case ieee_section_type_enum:
904 unsigned int section_index;
905 next_byte (&(ieee->h));
906 section_index = must_parse_int (&(ieee->h));
907 /* Fixme to be nice about a silly number of sections */
908 BFD_ASSERT (section_index < NSECTIONS);
910 section = get_section_entry (abfd, ieee, section_index);
912 section_type[0] = this_byte_and_next (&(ieee->h));
913 switch (section_type[0])
916 /* Normal attributes for absolute sections */
917 section_type[1] = this_byte (&(ieee->h));
918 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
919 switch (section_type[1])
921 case 0xD3: /* AS Absolute section attributes */
922 next_byte (&(ieee->h));
923 section_type[2] = this_byte (&(ieee->h));
924 switch (section_type[2])
928 next_byte (&(ieee->h));
929 section->flags |= SEC_LOAD | SEC_CODE;
932 next_byte (&(ieee->h));
933 section->flags |= SEC_LOAD | SEC_DATA;
937 next_byte (&(ieee->h));
938 /* Normal rom data */
939 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
946 case 0xC3: /* Named relocatable sections (type C) */
947 section_type[1] = this_byte (&(ieee->h));
948 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
949 switch (section_type[1])
951 case 0xD0: /* Normal code (CP) */
952 next_byte (&(ieee->h));
953 section->flags |= SEC_LOAD | SEC_CODE;
955 case 0xC4: /* Normal data (CD) */
956 next_byte (&(ieee->h));
957 section->flags |= SEC_LOAD | SEC_DATA;
959 case 0xD2: /* Normal rom data (CR) */
960 next_byte (&(ieee->h));
961 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
968 /* Read section name, use it if non empty. */
969 name = read_id (&ieee->h);
971 section->name = name;
973 /* Skip these fields, which we don't care about */
975 bfd_vma parent, brother, context;
976 parse_int (&(ieee->h), &parent);
977 parse_int (&(ieee->h), &brother);
978 parse_int (&(ieee->h), &context);
982 case ieee_section_alignment_enum:
984 unsigned int section_index;
987 next_byte (&(ieee->h));
988 section_index = must_parse_int (&ieee->h);
989 section = get_section_entry (abfd, ieee, section_index);
990 if (section_index > ieee->section_count)
992 ieee->section_count = section_index;
994 section->alignment_power =
995 bfd_log2 (must_parse_int (&ieee->h));
996 (void) parse_int (&(ieee->h), &value);
999 case ieee_e2_first_byte_enum:
1001 ieee_record_enum_type t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1005 case ieee_section_size_enum:
1006 section = ieee->section_table[must_parse_int (&(ieee->h))];
1007 section->_raw_size = must_parse_int (&(ieee->h));
1009 case ieee_physical_region_size_enum:
1010 section = ieee->section_table[must_parse_int (&(ieee->h))];
1011 section->_raw_size = must_parse_int (&(ieee->h));
1013 case ieee_region_base_address_enum:
1014 section = ieee->section_table[must_parse_int (&(ieee->h))];
1015 section->vma = must_parse_int (&(ieee->h));
1017 case ieee_mau_size_enum:
1018 must_parse_int (&(ieee->h));
1019 must_parse_int (&(ieee->h));
1021 case ieee_m_value_enum:
1022 must_parse_int (&(ieee->h));
1023 must_parse_int (&(ieee->h));
1025 case ieee_section_base_address_enum:
1026 section = ieee->section_table[must_parse_int (&(ieee->h))];
1027 section->vma = must_parse_int (&(ieee->h));
1029 case ieee_section_offset_enum:
1030 (void) must_parse_int (&(ieee->h));
1031 (void) must_parse_int (&(ieee->h));
1046 /***********************************************************************
1051 ieee_archive_p (abfd)
1058 unsigned char buffer[512];
1060 file_ptr buffer_offset = 0;
1061 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1062 ieee_ar_data_type *ieee;
1063 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, sizeof (ieee_ar_data_type));
1064 if (!abfd->tdata.ieee_ar_data)
1066 bfd_set_error (bfd_error_no_memory);
1069 ieee = IEEE_AR_DATA (abfd);
1071 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1073 ieee->h.first_byte = buffer;
1074 ieee->h.input_p = buffer;
1076 ieee->h.abfd = abfd;
1078 if (this_byte (&(ieee->h)) != Module_Beginning)
1080 abfd->tdata.ieee_ar_data = save;
1081 return (bfd_target *) NULL;
1084 next_byte (&(ieee->h));
1085 library = read_id (&(ieee->h));
1086 if (strcmp (library, "LIBRARY") != 0)
1088 bfd_release (abfd, ieee);
1089 abfd->tdata.ieee_ar_data = save;
1090 return (bfd_target *) NULL;
1092 /* Throw away the filename */
1093 read_id (&(ieee->h));
1094 /* This must be an IEEE archive, so we'll buy some space to do
1097 if (!obstack_begin (&ob, 128))
1099 bfd_set_error (bfd_error_no_memory);
1100 return (bfd_target *) NULL;
1103 ieee->element_count = 0;
1104 ieee->element_index = 0;
1106 next_byte (&(ieee->h)); /* Drop the ad part */
1107 must_parse_int (&(ieee->h)); /* And the two dummy numbers */
1108 must_parse_int (&(ieee->h));
1111 /* Read the index of the BB table */
1114 ieee_ar_obstack_type t;
1115 int rec = read_2bytes (&(ieee->h));
1116 if (rec == (int) ieee_assign_value_to_variable_enum)
1118 must_parse_int (&(ieee->h));
1119 t.file_offset = must_parse_int (&(ieee->h));
1120 t.abfd = (bfd *) NULL;
1121 ieee->element_count++;
1123 obstack_grow (&ob, (PTR) & t, sizeof (t));
1125 /* Make sure that we don't go over the end of the buffer */
1127 if (ieee_pos (abfd) > sizeof (buffer) / 2)
1129 /* Past half way, reseek and reprime */
1130 buffer_offset += ieee_pos (abfd);
1131 bfd_seek (abfd, buffer_offset, SEEK_SET);
1132 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1133 ieee->h.first_byte = buffer;
1134 ieee->h.input_p = buffer;
1141 ieee->elements = (ieee_ar_obstack_type *) obstack_finish (&ob);
1142 if (!ieee->elements)
1144 bfd_set_error (bfd_error_no_memory);
1145 return (bfd_target *) NULL;
1148 /* Now scan the area again, and replace BB offsets with file */
1151 for (i = 2; i < ieee->element_count; i++)
1153 bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET);
1154 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1155 ieee->h.first_byte = buffer;
1156 ieee->h.input_p = buffer;
1158 next_byte (&(ieee->h)); /* Drop F8 */
1159 next_byte (&(ieee->h)); /* Drop 14 */
1160 must_parse_int (&(ieee->h)); /* Drop size of block */
1161 if (must_parse_int (&(ieee->h)) != 0)
1163 /* This object has been deleted */
1164 ieee->elements[i].file_offset = 0;
1168 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1172 /* abfd->has_armap = ;*/
1177 ieee_mkobject (abfd)
1180 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, sizeof (ieee_data_type));
1181 return abfd->tdata.ieee_data ? true : false;
1185 ieee_object_p (abfd)
1190 ieee_data_type *ieee;
1191 unsigned char buffer[300];
1192 ieee_data_type *save = IEEE_DATA (abfd);
1194 abfd->tdata.ieee_data = 0;
1195 ieee_mkobject (abfd);
1197 ieee = IEEE_DATA (abfd);
1198 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
1199 /* Read the first few bytes in to see if it makes sense */
1200 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1202 ieee->h.input_p = buffer;
1203 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1206 ieee->read_symbols = false;
1207 ieee->read_data = false;
1208 ieee->section_count = 0;
1209 ieee->external_symbol_max_index = 0;
1210 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1211 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1212 ieee->external_reference_max_index = 0;
1213 ieee->h.abfd = abfd;
1214 memset ((PTR) ieee->section_table, 0, sizeof (ieee->section_table));
1216 processor = ieee->mb.processor = read_id (&(ieee->h));
1217 if (strcmp (processor, "LIBRARY") == 0)
1219 ieee->mb.module_name = read_id (&(ieee->h));
1220 if (abfd->filename == (CONST char *) NULL)
1222 abfd->filename = ieee->mb.module_name;
1224 /* Determine the architecture and machine type of the object file.
1227 bfd_arch_info_type *arch = bfd_scan_arch (processor);
1230 abfd->arch_info = arch;
1233 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1237 next_byte (&(ieee->h));
1239 if (parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau) == false)
1243 if (parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address) == false)
1248 /* If there is a byte order info, take it */
1249 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum ||
1250 this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
1251 next_byte (&(ieee->h));
1253 for (part = 0; part < N_W_VARIABLES; part++)
1256 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
1260 if (this_byte_and_next (&(ieee->h)) != part)
1265 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
1272 abfd->flags = HAS_SYMS;
1273 /* By now we know that this is a real IEEE file, we're going to read
1274 the whole thing into memory so that we can run up and down it
1275 quickly. We can work out how big the file is from the trailer
1278 IEEE_DATA (abfd)->h.first_byte = (unsigned char *) bfd_alloc (ieee->h.abfd, ieee->w.r.me_record
1280 if (!IEEE_DATA (abfd)->h.first_byte)
1282 bfd_set_error (bfd_error_no_memory);
1285 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
1286 bfd_read ((PTR) (IEEE_DATA (abfd)->h.first_byte), 1, ieee->w.r.me_record + 50, abfd);
1288 ieee_slurp_sections (abfd);
1291 (void) bfd_release (abfd, ieee);
1292 abfd->tdata.ieee_data = save;
1293 return (bfd_target *) NULL;
1297 ieee_get_symbol_info (ignore_abfd, symbol, ret)
1302 bfd_symbol_info (symbol, ret);
1303 if (symbol->name[0] == ' ')
1304 ret->name = "* empty table entry ";
1305 if (!symbol->section)
1306 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
1310 ieee_print_symbol (ignore_abfd, afile, symbol, how)
1314 bfd_print_symbol_type how;
1316 FILE *file = (FILE *) afile;
1320 case bfd_print_symbol_name:
1321 fprintf (file, "%s", symbol->name);
1323 case bfd_print_symbol_more:
1325 fprintf (file, "%4x %2x", aout_symbol (symbol)->desc & 0xffff,
1326 aout_symbol (symbol)->other & 0xff);
1330 case bfd_print_symbol_all:
1332 CONST char *section_name = symbol->section == (asection *) NULL ?
1333 (CONST char *) "*abs" : symbol->section->name;
1334 if (symbol->name[0] == ' ')
1336 fprintf (file, "* empty table entry ");
1340 bfd_print_symbol_vandf ((PTR) file, symbol);
1342 fprintf (file, " %-5s %04x %02x %s",
1344 (unsigned) ieee_symbol (symbol)->index,
1346 aout_symbol(symbol)->desc & 0xffff,
1347 aout_symbol(symbol)->other & 0xff,*/
1356 do_one (ieee, current_map, location_ptr, s)
1357 ieee_data_type *ieee;
1358 ieee_per_section_type *current_map;
1359 unsigned char *location_ptr;
1362 switch (this_byte (&(ieee->h)))
1364 case ieee_load_constant_bytes_enum:
1366 unsigned int number_of_maus;
1368 next_byte (&(ieee->h));
1369 number_of_maus = must_parse_int (&(ieee->h));
1371 for (i = 0; i < number_of_maus; i++)
1373 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1374 next_byte (&(ieee->h));
1379 case ieee_load_with_relocation_enum:
1381 boolean loop = true;
1382 next_byte (&(ieee->h));
1385 switch (this_byte (&(ieee->h)))
1387 case ieee_variable_R_enum:
1389 case ieee_function_signed_open_b_enum:
1390 case ieee_function_unsigned_open_b_enum:
1391 case ieee_function_either_open_b_enum:
1393 unsigned int extra = 4;
1394 boolean pcrel = false;
1396 ieee_reloc_type *r =
1397 (ieee_reloc_type *) bfd_alloc (ieee->h.abfd,
1398 sizeof (ieee_reloc_type));
1401 bfd_set_error (bfd_error_no_memory);
1405 *(current_map->reloc_tail_ptr) = r;
1406 current_map->reloc_tail_ptr = &r->next;
1407 r->next = (ieee_reloc_type *) NULL;
1408 next_byte (&(ieee->h));
1410 r->relent.sym_ptr_ptr = 0;
1411 parse_expression (ieee,
1414 &pcrel, &extra, §ion);
1415 r->relent.address = current_map->pc;
1417 if (r->relent.sym_ptr_ptr == 0)
1419 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1422 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1424 next_byte (&(ieee->h));
1425 /* Fetch number of bytes to pad */
1426 extra = must_parse_int (&(ieee->h));
1429 switch (this_byte (&(ieee->h)))
1431 case ieee_function_signed_close_b_enum:
1432 next_byte (&(ieee->h));
1434 case ieee_function_unsigned_close_b_enum:
1435 next_byte (&(ieee->h));
1437 case ieee_function_either_close_b_enum:
1438 next_byte (&(ieee->h));
1443 /* Build a relocation entry for this type */
1444 /* If pc rel then stick -ve pc into instruction
1445 and take out of reloc ..
1447 I've changed this. It's all too
1448 complicated. I keep 0 in the
1459 #if KEEPMINUSPCININST
1460 bfd_put_32 (ieee->h.abfd, -current_map->pc, location_ptr +
1462 r->relent.howto = &rel32_howto;
1466 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1468 r->relent.howto = &rel32_howto;
1473 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1475 r->relent.howto = &abs32_howto;
1477 current_map->pc += 4;
1482 #if KEEPMINUSPCININST
1483 bfd_put_16 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1484 r->relent.addend -= current_map->pc;
1485 r->relent.howto = &rel16_howto;
1488 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1489 r->relent.howto = &rel16_howto;
1495 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1496 r->relent.howto = &abs16_howto;
1498 current_map->pc += 2;
1503 #if KEEPMINUSPCININST
1504 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1505 r->relent.addend -= current_map->pc;
1506 r->relent.howto = &rel8_howto;
1508 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1509 r->relent.howto = &rel8_howto;
1514 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1515 r->relent.howto = &abs8_howto;
1517 current_map->pc += 1;
1529 if (parse_int (&(ieee->h), &this_size) == true)
1532 for (i = 0; i < this_size; i++)
1534 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1535 next_byte (&(ieee->h));
1550 /* Read in all the section data and relocation stuff too */
1552 ieee_slurp_section_data (abfd)
1555 bfd_byte *location_ptr = (bfd_byte *) NULL;
1556 ieee_data_type *ieee = IEEE_DATA (abfd);
1557 unsigned int section_number;
1559 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
1561 /* Seek to the start of the data area */
1562 if (ieee->read_data == true)
1564 ieee->read_data = true;
1565 ieee_seek (abfd, ieee->w.r.data_part);
1567 /* Allocate enough space for all the section contents */
1569 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1571 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1572 per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->_raw_size);
1575 bfd_set_error (bfd_error_no_memory);
1579 per->reloc_tail_ptr =
1580 (ieee_reloc_type **) & (s->relocation);
1585 switch (this_byte (&(ieee->h)))
1587 /* IF we see anything strange then quit */
1591 case ieee_set_current_section_enum:
1592 next_byte (&(ieee->h));
1593 section_number = must_parse_int (&(ieee->h));
1594 s = ieee->section_table[section_number];
1595 current_map = (ieee_per_section_type *) s->used_by_bfd;
1596 location_ptr = current_map->data - s->vma;
1597 /* The document I have says that Microtec's compilers reset */
1598 /* this after a sec section, even though the standard says not */
1600 current_map->pc = s->vma;
1603 case ieee_e2_first_byte_enum:
1604 next_byte (&(ieee->h));
1605 switch (this_byte (&(ieee->h)))
1607 case ieee_set_current_pc_enum & 0xff:
1610 ieee_symbol_index_type symbol;
1613 next_byte (&(ieee->h));
1614 must_parse_int (&(ieee->h)); /* Thow away section #*/
1615 parse_expression (ieee, &value,
1619 current_map->pc = value;
1620 BFD_ASSERT ((unsigned) (value - s->vma) <= s->_raw_size);
1624 case ieee_value_starting_address_enum & 0xff:
1625 /* We've got to the end of the data now - */
1632 case ieee_repeat_data_enum:
1634 /* Repeat the following LD or LR n times - we do this by
1635 remembering the stream pointer before running it and
1636 resetting it and running it n times. We special case
1637 the repetition of a repeat_data/load_constant
1640 unsigned int iterations;
1641 unsigned char *start;
1642 next_byte (&(ieee->h));
1643 iterations = must_parse_int (&(ieee->h));
1644 start = ieee->h.input_p;
1645 if (start[0] == (int) ieee_load_constant_bytes_enum &&
1648 while (iterations != 0)
1650 location_ptr[current_map->pc++] = start[2];
1653 next_byte (&(ieee->h));
1654 next_byte (&(ieee->h));
1655 next_byte (&(ieee->h));
1659 while (iterations != 0)
1661 ieee->h.input_p = start;
1662 if (!do_one (ieee, current_map, location_ptr, s))
1669 case ieee_load_constant_bytes_enum:
1670 case ieee_load_with_relocation_enum:
1672 if (!do_one (ieee, current_map, location_ptr, s))
1680 ieee_new_section_hook (abfd, newsect)
1684 newsect->used_by_bfd = (PTR)
1685 bfd_alloc (abfd, sizeof (ieee_per_section_type));
1686 if (!newsect->used_by_bfd)
1688 bfd_set_error (bfd_error_no_memory);
1691 ieee_per_section (newsect)->data = (bfd_byte *) NULL;
1692 ieee_per_section (newsect)->section = newsect;
1697 ieee_get_reloc_upper_bound (abfd, asect)
1701 if (! ieee_slurp_section_data (abfd))
1703 return (asect->reloc_count + 1) * sizeof (arelent *);
1707 ieee_get_section_contents (abfd, section, location, offset, count)
1712 bfd_size_type count;
1714 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1715 ieee_slurp_section_data (abfd);
1716 (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
1721 ieee_canonicalize_reloc (abfd, section, relptr, symbols)
1727 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1728 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
1729 ieee_data_type *ieee = IEEE_DATA (abfd);
1731 while (src != (ieee_reloc_type *) NULL)
1733 /* Work out which symbol to attach it this reloc to */
1734 switch (src->symbol.letter)
1737 src->relent.sym_ptr_ptr =
1738 symbols + src->symbol.index + ieee->external_reference_base_offset;
1741 src->relent.sym_ptr_ptr =
1742 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
1748 *relptr++ = &src->relent;
1751 *relptr = (arelent *) NULL;
1752 return section->reloc_count;
1760 arelent *a = *((arelent **) ap);
1761 arelent *b = *((arelent **) bp);
1762 return a->address - b->address;
1766 Write the section headers
1770 ieee_write_section_part (abfd)
1773 ieee_data_type *ieee = IEEE_DATA (abfd);
1775 ieee->w.r.section_part = bfd_tell (abfd);
1776 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1778 if (s != &bfd_abs_section)
1780 ieee_write_byte (abfd, ieee_section_type_enum);
1781 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1783 if (abfd->flags & EXEC_P)
1785 /* This image is executable, so output absolute sections */
1786 ieee_write_byte (abfd, ieee_variable_A_enum);
1787 ieee_write_byte (abfd, ieee_variable_S_enum);
1791 ieee_write_byte (abfd, ieee_variable_C_enum);
1794 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
1796 case SEC_CODE | SEC_LOAD:
1798 ieee_write_byte (abfd, ieee_variable_P_enum);
1802 ieee_write_byte (abfd, ieee_variable_D_enum);
1805 case SEC_ROM | SEC_DATA:
1806 case SEC_ROM | SEC_LOAD:
1807 case SEC_ROM | SEC_DATA | SEC_LOAD:
1809 ieee_write_byte (abfd, ieee_variable_R_enum);
1813 ieee_write_id (abfd, s->name);
1815 ieee_write_int (abfd, 0); /* Parent */
1816 ieee_write_int (abfd, 0); /* Brother */
1817 ieee_write_int (abfd, 0); /* Context */
1820 ieee_write_byte (abfd, ieee_section_alignment_enum);
1821 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1822 ieee_write_int (abfd, 1 << s->alignment_power);
1825 ieee_write_2bytes (abfd, ieee_section_size_enum);
1826 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1827 ieee_write_int (abfd, s->_raw_size);
1828 if (abfd->flags & EXEC_P)
1830 /* Relocateable sections don't have asl records */
1832 ieee_write_2bytes (abfd, ieee_section_base_address_enum);
1833 ieee_write_byte (abfd,
1834 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1835 ieee_write_int (abfd, s->vma);
1844 do_with_relocs (abfd, s)
1848 unsigned int relocs_to_go = s->reloc_count;
1850 bfd_byte *stream = ieee_per_section (s)->data;
1851 arelent **p = s->orelocation;
1853 bfd_size_type current_byte_index = 0;
1855 qsort (s->orelocation,
1857 sizeof (arelent **),
1860 /* Output the section preheader */
1861 ieee_write_byte (abfd, ieee_set_current_section_enum);
1862 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1864 ieee_write_twobyte (abfd, ieee_set_current_pc_enum);
1865 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1866 ieee_write_expression (abfd, 0, s->symbol, 0, 0);
1868 if (relocs_to_go == 0)
1870 /* If there arn't any relocations then output the load constant byte
1871 opcode rather than the load with relocation opcode */
1873 while (current_byte_index < s->_raw_size)
1876 unsigned int MAXRUN = 32;
1878 if (run > s->_raw_size - current_byte_index)
1880 run = s->_raw_size - current_byte_index;
1885 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
1886 /* Output a stream of bytes */
1887 ieee_write_int (abfd, run);
1888 bfd_write ((PTR) (stream + current_byte_index),
1892 current_byte_index += run;
1898 ieee_write_byte (abfd, ieee_load_with_relocation_enum);
1901 /* Output the data stream as the longest sequence of bytes
1902 possible, allowing for the a reasonable packet size and
1903 relocation stuffs */
1905 if ((PTR) stream == (PTR) NULL)
1907 /* Outputting a section without data, fill it up */
1908 stream = (unsigned char *) (bfd_alloc (abfd, s->_raw_size));
1911 bfd_set_error (bfd_error_no_memory);
1914 memset ((PTR) stream, 0, s->_raw_size);
1916 while (current_byte_index < s->_raw_size)
1919 unsigned int MAXRUN = 32;
1922 run = (*p)->address - current_byte_index;
1928 if (run > s->_raw_size - current_byte_index)
1930 run = s->_raw_size - current_byte_index;
1935 /* Output a stream of bytes */
1936 ieee_write_int (abfd, run);
1937 bfd_write ((PTR) (stream + current_byte_index),
1941 current_byte_index += run;
1943 /* Output any relocations here */
1944 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1946 while (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1953 if (r->howto->pc_relative)
1955 r->addend += current_byte_index;
1959 switch (r->howto->size)
1963 ov = bfd_get_32 (abfd,
1964 stream + current_byte_index);
1965 current_byte_index += 4;
1968 ov = bfd_get_16 (abfd,
1969 stream + current_byte_index);
1970 current_byte_index += 2;
1973 ov = bfd_get_8 (abfd,
1974 stream + current_byte_index);
1975 current_byte_index++;
1981 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
1984 if (r->sym_ptr_ptr != (asymbol **) NULL)
1986 ieee_write_expression (abfd, r->addend + ov,
1988 r->howto->pc_relative, s->index);
1992 ieee_write_expression (abfd, r->addend + ov,
1994 r->howto->pc_relative, s->index);
1997 if (1 || r->howto->size != 2)
1999 ieee_write_byte (abfd, ieee_comma);
2000 ieee_write_int (abfd, 1 << r->howto->size);
2002 ieee_write_byte (abfd,
2003 ieee_function_either_close_b_enum);
2015 /* If there are no relocations in the output section then we can
2016 be clever about how we write. We block items up into a max of 127
2020 do_as_repeat (abfd, s)
2026 ieee_write_byte (abfd, ieee_set_current_section_enum);
2027 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2028 ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8);
2029 ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff);
2030 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2031 ieee_write_int (abfd, s->vma);
2033 ieee_write_byte (abfd, ieee_repeat_data_enum);
2034 ieee_write_int (abfd, s->_raw_size);
2035 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
2036 ieee_write_byte (abfd, 1);
2037 ieee_write_byte (abfd, 0);
2042 do_without_relocs (abfd, s)
2046 bfd_byte *stream = ieee_per_section (s)->data;
2048 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2050 do_as_repeat (abfd, s);
2055 for (i = 0; i < s->_raw_size; i++)
2059 do_with_relocs (abfd, s);
2063 do_as_repeat (abfd, s);
2069 static unsigned char *output_ptr_start;
2070 static unsigned char *output_ptr;
2071 static unsigned char *output_ptr_end;
2072 static unsigned char *input_ptr_start;
2073 static unsigned char *input_ptr;
2074 static unsigned char *input_ptr_end;
2075 static bfd *input_bfd;
2076 static bfd *output_bfd;
2077 static int output_buffer;
2082 bfd_read ((PTR) input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
2083 input_ptr = input_ptr_start;
2088 bfd_write ((PTR) (output_ptr_start), 1, output_ptr - output_ptr_start, output_bfd);
2089 output_ptr = output_ptr_start;
2093 #define THIS() ( *input_ptr )
2094 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2095 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2101 if (value >= 0 && value <= 127)
2107 unsigned int length;
2108 /* How many significant bytes ? */
2109 /* FIXME FOR LONGER INTS */
2110 if (value & 0xff000000)
2114 else if (value & 0x00ff0000)
2118 else if (value & 0x0000ff00)
2125 OUT ((int) ieee_number_repeat_start_enum + length);
2144 int length = THIS ();
2156 #define VAR(x) ((x | 0x80))
2171 value = (value << 8) | THIS ();
2173 value = (value << 8) | THIS ();
2175 value = (value << 8) | THIS ();
2183 value = (value << 8) | THIS ();
2185 value = (value << 8) | THIS ();
2193 value = (value << 8) | THIS ();
2210 /* Not a number, just bug out with the answer */
2211 write_int (*(--tos));
2221 int value = *(--tos);
2230 ieee_data_type *ieee;
2233 section_number = THIS ();
2236 ieee = IEEE_DATA (input_bfd);
2237 s = ieee->section_table[section_number];
2238 if (s->output_section)
2240 value = s->output_section->vma;
2246 value += s->output_offset;
2254 write_int (*(--tos));
2264 /* Drop the int in the buffer, and copy a null into the gap, which we
2265 will overwrite later */
2267 struct output_buffer_struct
2269 unsigned char *ptrp;
2275 struct output_buffer_struct *buf;
2277 if (buf->buffer == output_buffer)
2279 /* Still a chance to output the size */
2280 int value = output_ptr - buf->ptrp + 3;
2281 buf->ptrp[0] = value >> 24;
2282 buf->ptrp[1] = value >> 16;
2283 buf->ptrp[2] = value >> 8;
2284 buf->ptrp[3] = value >> 0;
2290 struct output_buffer_struct *buf;
2316 buf->ptrp = output_ptr;
2317 buf->buffer = output_buffer;
2357 #define ID copy_id()
2358 #define INT copy_int()
2359 #define EXP copy_expression()
2360 static void copy_till_end ();
2361 #define INTn(q) copy_int()
2362 #define EXPn(q) copy_expression()
2401 EXPn (instruction address);
2435 EXPn (external function);
2445 INTn (locked register);
2468 /* Attribute record */
2526 static void block ();
2538 /* Unique typedefs for module */
2539 /* GLobal typedefs */
2540 /* High level module scope beginning */
2542 struct output_buffer_struct ob;
2557 /* Global function */
2559 struct output_buffer_struct ob;
2573 EXPn (size of block);
2579 /* File name for source line numbers */
2581 struct output_buffer_struct ob;
2601 /* Local function */
2603 struct output_buffer_struct ob;
2621 /* Assembler module scope beginning -*/
2623 struct output_buffer_struct ob;
2649 struct output_buffer_struct ob;
2656 INTn (section index);
2664 EXPn (Size in Maus);
2719 moves all the debug information from the source bfd to the output
2720 bfd, and relocates any expressions it finds
2724 relocate_debug (output, input)
2730 unsigned char input_buffer[IBS];
2732 input_ptr_start = input_ptr = input_buffer;
2733 input_ptr_end = input_buffer + IBS;
2735 bfd_read ((PTR) input_ptr_start, 1, IBS, input);
2740 During linking, we we told about the bfds which made up our
2741 contents, we have a list of them. They will still be open, so go to
2742 the debug info in each, and copy it out, relocating it as we go.
2746 ieee_write_debug_part (abfd)
2749 ieee_data_type *ieee = IEEE_DATA (abfd);
2750 bfd_chain_type *chain = ieee->chain_root;
2751 unsigned char output_buffer[OBS];
2752 boolean some_debug = false;
2753 file_ptr here = bfd_tell (abfd);
2755 output_ptr_start = output_ptr = output_buffer;
2756 output_ptr_end = output_buffer + OBS;
2757 output_ptr = output_buffer;
2760 if (chain == (bfd_chain_type *) NULL)
2763 /* There is no debug info, so we'll fake some up */
2764 CONST static char fake[] =
2766 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
2767 '1', '.', '1', 0x82, 1991 >> 8, 1991 & 0xff, 9, 20, 11, 07, 50};
2768 ieee->w.r.debug_information_part = 0;
2774 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2775 /* Now write a header for each section */
2778 asection *s = abfd->sections;
2781 if (s != abfd->abs_section)
2784 ieee_write_byte (abfd, 0xf8);
2785 ieee_write_byte (abfd, 0x0b);
2786 ieee_write_byte (abfd, 0);
2787 ieee_write_byte (abfd, 0);
2788 ieee_write_byte (abfd, 1);
2789 ieee_write_byte (abfd, i + IEEE_SECTION_NUMBER_BASE);
2790 ieee_write_expression (abfd, 0, s->symbol, 0, 0, 0);
2791 ieee_write_byte (abfd, 0);
2792 ieee_write_byte (abfd, 0xf9);
2793 ieee_write_expression (abfd, s->size,
2794 bfd_abs_section.symbol, 0, 0, 0);
2801 /* Close the scope */
2802 ieee_write_byte (abfd, 0xf9);
2808 while (chain != (bfd_chain_type *) NULL)
2810 bfd *entry = chain->this;
2811 ieee_data_type *entry_ieee = IEEE_DATA (entry);
2812 if (entry_ieee->w.r.debug_information_part)
2814 bfd_seek (entry, entry_ieee->w.r.debug_information_part, SEEK_SET);
2815 relocate_debug (abfd, entry);
2818 chain = chain->next;
2822 ieee->w.r.debug_information_part = here;
2826 ieee->w.r.debug_information_part = 0;
2833 /* write the data in an ieee way */
2835 ieee_write_data_part (abfd)
2839 ieee_data_type *ieee = IEEE_DATA (abfd);
2840 ieee->w.r.data_part = bfd_tell (abfd);
2841 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2843 /* Sort the reloc records so we can insert them in the correct
2845 if (s->reloc_count != 0)
2847 do_with_relocs (abfd, s);
2851 do_without_relocs (abfd, s);
2858 init_for_output (abfd)
2862 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2864 if (s->_raw_size != 0)
2866 ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, s->_raw_size));
2867 if (!ieee_per_section (s)->data)
2869 bfd_set_error (bfd_error_no_memory);
2877 /** exec and core file sections */
2879 /* set section contents is complicated with IEEE since the format is
2880 * not a byte image, but a record stream.
2883 ieee_set_section_contents (abfd, section, location, offset, count)
2888 bfd_size_type count;
2890 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
2892 if (!init_for_output (abfd))
2895 memcpy ((PTR) (ieee_per_section (section)->data + offset),
2897 (unsigned int) count);
2902 write the external symbols of a file, IEEE considers two sorts of
2903 external symbols, public, and referenced. It uses to internal forms
2904 to index them as well. When we write them out we turn their symbol
2905 values into indexes from the right base.
2908 ieee_write_external_part (abfd)
2912 ieee_data_type *ieee = IEEE_DATA (abfd);
2914 unsigned int reference_index = IEEE_REFERENCE_BASE;
2915 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
2916 file_ptr here = bfd_tell (abfd);
2917 boolean hadone = false;
2918 if (abfd->outsymbols != (asymbol **) NULL)
2921 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
2925 if (p->section == &bfd_und_section)
2927 /* This must be a symbol reference .. */
2928 ieee_write_byte (abfd, ieee_external_reference_enum);
2929 ieee_write_int (abfd, reference_index);
2930 ieee_write_id (abfd, p->name);
2931 p->value = reference_index;
2934 else if (bfd_is_com_section (p->section))
2936 /* This is a weak reference */
2937 ieee_write_byte (abfd, ieee_external_reference_enum);
2938 ieee_write_int (abfd, reference_index);
2939 ieee_write_id (abfd, p->name);
2940 ieee_write_byte (abfd, ieee_weak_external_reference_enum);
2941 ieee_write_int (abfd, reference_index);
2942 ieee_write_int (abfd, p->value);
2943 ieee_write_int (abfd, BFD_FORT_COMM_DEFAULT_VALUE);
2944 p->value = reference_index;
2947 else if (p->flags & BSF_GLOBAL)
2949 /* This must be a symbol definition */
2952 ieee_write_byte (abfd, ieee_external_symbol_enum);
2953 ieee_write_int (abfd, public_index);
2954 ieee_write_id (abfd, p->name);
2956 ieee_write_twobyte (abfd, ieee_attribute_record_enum);
2957 ieee_write_int (abfd, public_index);
2958 ieee_write_byte (abfd, 15); /* instruction address */
2959 ieee_write_byte (abfd, 19); /* static symbol */
2960 ieee_write_byte (abfd, 1); /* one of them */
2963 /* Write out the value */
2964 ieee_write_2bytes (abfd, ieee_value_record_enum);
2965 ieee_write_int (abfd, public_index);
2966 if (p->section != &bfd_abs_section)
2968 if (abfd->flags & EXEC_P)
2970 /* If fully linked, then output all symbols
2972 ieee_write_int (abfd,
2973 p->value + p->section->output_offset + p->section->output_section->vma);
2978 ieee_write_expression (abfd,
2979 p->value + p->section->output_offset,
2980 p->section->output_section->symbol
2986 ieee_write_expression (abfd,
2988 bfd_abs_section.symbol,
2991 p->value = public_index;
2996 /* This can happen - when there are gaps in the symbols read */
2997 /* from an input ieee file */
3002 ieee->w.r.external_part = here;
3007 static CONST unsigned char exten[] =
3010 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3011 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3012 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3015 static CONST unsigned char envi[] =
3019 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3022 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3024 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3025 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3030 ieee_write_me_part (abfd)
3033 ieee_data_type *ieee = IEEE_DATA (abfd);
3034 ieee->w.r.trailer_part = bfd_tell (abfd);
3035 if (abfd->start_address)
3037 ieee->w.r.me_record = bfd_tell (abfd);
3038 ieee_write_2bytes (abfd, ieee_value_starting_address_enum);
3039 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
3040 ieee_write_int (abfd, abfd->start_address);
3041 ieee_write_byte (abfd, ieee_function_either_close_b_enum);
3045 ieee->w.r.me_record = bfd_tell (abfd);
3047 ieee_write_byte (abfd, ieee_module_end_enum);
3052 ieee_write_object_contents (abfd)
3055 ieee_data_type *ieee = IEEE_DATA (abfd);
3058 /* Fast forward over the header area */
3059 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
3060 ieee_write_byte (abfd, ieee_module_beginning_enum);
3062 ieee_write_id (abfd, bfd_printable_name (abfd));
3063 ieee_write_id (abfd, abfd->filename);
3065 /* Fast forward over the variable bits */
3066 ieee_write_byte (abfd, ieee_address_descriptor_enum);
3069 ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd)));
3070 /* MAU's per address */
3071 ieee_write_byte (abfd,
3072 (bfd_byte) (bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd)));
3074 old = bfd_tell (abfd);
3075 bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR);
3077 ieee->w.r.extension_record = bfd_tell (abfd);
3078 bfd_write ((char *) exten, 1, sizeof (exten), abfd);
3079 if (abfd->flags & EXEC_P)
3080 ieee_write_byte (abfd, 0x1);/* Absolute */
3082 ieee_write_byte (abfd, 0x2);/* Relocateable */
3084 ieee->w.r.environmental_record = bfd_tell (abfd);
3085 bfd_write ((char *) envi, 1, sizeof (envi), abfd);
3089 ieee_write_section_part (abfd);
3091 First write the symbols, this changes their values into table
3092 indeces so we cant use it after this point
3094 ieee_write_external_part (abfd);
3095 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3098 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3102 Write any debugs we have been told about
3104 ieee_write_debug_part (abfd);
3107 Can only write the data once the symbols have been written since
3108 the data contains relocation information which points to the
3111 ieee_write_data_part (abfd);
3115 At the end we put the end !
3117 ieee_write_me_part (abfd);
3120 /* Generate the header */
3121 bfd_seek (abfd, old, SEEK_SET);
3123 for (i = 0; i < N_W_VARIABLES; i++)
3125 ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum);
3126 ieee_write_byte (abfd, (bfd_byte) i);
3127 ieee_write_int5_out (abfd, ieee->w.offset[i]);
3134 /* Native-level interface to symbols. */
3136 /* We read the symbols into a buffer, which is discarded when this
3137 function exits. We read the strings into a buffer large enough to
3138 hold them all plus all the cached symbol entries. */
3141 ieee_make_empty_symbol (abfd)
3145 ieee_symbol_type *new =
3146 (ieee_symbol_type *) bfd_zmalloc (sizeof (ieee_symbol_type));
3149 bfd_set_error (bfd_error_no_error);
3152 new->symbol.the_bfd = abfd;
3153 return &new->symbol;
3157 ieee_openr_next_archived_file (arch, prev)
3161 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3162 /* take the next one from the arch state, or reset */
3163 if (prev == (bfd *) NULL)
3165 /* Reset the index - the first two entries are bogus*/
3166 ar->element_index = 2;
3170 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3171 ar->element_index++;
3172 if (ar->element_index <= ar->element_count)
3174 if (p->file_offset != (file_ptr) 0)
3176 if (p->abfd == (bfd *) NULL)
3178 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3179 p->abfd->origin = p->file_offset;
3186 bfd_set_error (bfd_error_no_more_archived_files);
3187 return (bfd *) NULL;
3194 ieee_find_nearest_line (abfd,
3205 char **filename_ptr;
3206 char **functionname_ptr;
3213 ieee_generic_stat_arch_elt (abfd, buf)
3217 ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
3218 if (ar == (ieee_ar_data_type *) NULL)
3220 bfd_set_error (bfd_error_invalid_operation);
3226 buf->st_mode = 0666;
3227 return !ieee_object_p (abfd);
3232 ieee_sizeof_headers (abfd, x)
3241 ieee_bfd_debug_info_start (abfd)
3248 ieee_bfd_debug_info_end (abfd)
3255 /* Add this section to the list of sections we have debug info for, to
3256 be ready to output it at close time
3259 ieee_bfd_debug_info_accumulate (abfd, section)
3263 ieee_data_type *ieee = IEEE_DATA (section->owner);
3264 ieee_data_type *output_ieee = IEEE_DATA (abfd);
3265 /* can only accumulate data from other ieee bfds */
3266 if (section->owner->xvec != abfd->xvec)
3268 /* Only bother once per bfd */
3269 if (ieee->done_debug == true)
3271 ieee->done_debug = true;
3273 /* Don't bother if there is no debug info */
3274 if (ieee->w.r.debug_information_part == 0)
3280 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc (abfd, sizeof (bfd_chain_type));
3283 bfd_set_error (bfd_error_no_memory);
3284 abort (); /* FIXME */
3286 n->this = section->owner;
3287 n->next = (bfd_chain_type *) NULL;
3289 if (output_ieee->chain_head)
3291 output_ieee->chain_head->next = n;
3295 output_ieee->chain_root = n;
3298 output_ieee->chain_head = n;
3304 #define ieee_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
3305 #define ieee_core_file_failing_signal (int (*)())bfd_0
3306 #define ieee_core_file_matches_executable_p ( FOO(boolean, (*),(bfd *, bfd *)))bfd_false
3307 #define ieee_slurp_armap bfd_true
3308 #define ieee_slurp_extended_name_table bfd_true
3309 #define ieee_truncate_arname (void (*)())bfd_nullvoidptr
3310 #define ieee_write_armap (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, unsigned int, int))) bfd_nullvoidptr
3311 #define ieee_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
3312 #define ieee_close_and_cleanup bfd_generic_close_and_cleanup
3313 #define ieee_set_arch_mach bfd_default_set_arch_mach
3314 #define ieee_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
3315 #define ieee_bfd_relax_section bfd_generic_relax_section
3316 #define ieee_bfd_reloc_type_lookup \
3317 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
3318 #define ieee_bfd_make_debug_symbol \
3319 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
3320 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3321 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3322 #define ieee_bfd_final_link _bfd_generic_final_link
3323 #define ieee_bfd_copy_private_section_data \
3324 ((boolean (*) PARAMS ((bfd *, asection *, bfd *, asection *))) bfd_true)
3325 #define ieee_bfd_copy_private_bfd_data \
3326 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
3327 #define ieee_bfd_is_local_label bfd_generic_is_local_label
3328 #define ieee_bfd_free_cached_info bfd_true
3331 bfd_target ieee_vec =
3334 bfd_target_ieee_flavour,
3335 true, /* target byte order */
3336 true, /* target headers byte order */
3337 (HAS_RELOC | EXEC_P | /* object flags */
3338 HAS_LINENO | HAS_DEBUG |
3339 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3340 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3341 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3342 0, /* leading underscore */
3343 ' ', /* ar_pad_char */
3344 16, /* ar_max_namelen */
3345 1, /* minimum alignment */
3346 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3347 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3348 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3349 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3350 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3351 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3354 ieee_object_p, /* bfd_check_format */
3361 _bfd_generic_mkarchive,
3366 ieee_write_object_contents,
3367 _bfd_write_archive_contents,