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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #define KEEPMINUSPCININST 0
23 /* IEEE 695 format is a stream of records, which we parse using a simple one-
24 token (which is one byte in this lexicon) lookahead recursive decent
33 #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 if (bfd_write ((PTR) & byte, 1, 1, abfd) != 1)
49 ieee_write_twobyte (abfd, twobyte)
54 b[1] = twobyte & 0xff;
56 if (bfd_write ((PTR) & b[0], 1, 2, abfd) != 2)
61 ieee_write_2bytes (abfd, bytes)
66 buffer[0] = bytes >> 8;
67 buffer[1] = bytes & 0xff;
69 if (bfd_write ((PTR) buffer, 1, 2, abfd) != 2)
74 ieee_write_int (abfd, value)
78 if (((unsigned) value) <= 127)
80 ieee_write_byte (abfd, (bfd_byte) value);
85 /* How many significant bytes ? */
86 /* FIXME FOR LONGER INTS */
87 if (value & 0xff000000)
91 else if (value & 0x00ff0000)
95 else if (value & 0x0000ff00)
102 ieee_write_byte (abfd,
103 (bfd_byte) ((int) ieee_number_repeat_start_enum + length));
107 ieee_write_byte (abfd, (bfd_byte) (value >> 24));
109 ieee_write_byte (abfd, (bfd_byte) (value >> 16));
111 ieee_write_byte (abfd, (bfd_byte) (value >> 8));
113 ieee_write_byte (abfd, (bfd_byte) (value));
119 ieee_write_id (abfd, id)
123 size_t length = strlen (id);
126 ieee_write_byte (abfd, (bfd_byte) length);
128 else if (length < 255)
130 ieee_write_byte (abfd, ieee_extension_length_1_enum);
131 ieee_write_byte (abfd, (bfd_byte) length);
133 else if (length < 65535)
135 ieee_write_byte (abfd, ieee_extension_length_2_enum);
136 ieee_write_byte (abfd, (bfd_byte) (length >> 8));
137 ieee_write_byte (abfd, (bfd_byte) (length & 0xff));
143 if (bfd_write ((PTR) id, 1, length, abfd) != length)
148 /***************************************************************************
149 Functions for reading from ieee files in the strange way that the
153 #define this_byte(ieee) *((ieee)->input_p)
154 #define next_byte(ieee) ((ieee)->input_p++)
155 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
157 static unsigned short
159 common_header_type *ieee;
161 unsigned char c1 = this_byte_and_next (ieee);
162 unsigned char c2 = this_byte_and_next (ieee);
163 return (c1 << 8) | c2;
167 bfd_get_string (ieee, string, length)
168 common_header_type *ieee;
173 for (i = 0; i < length; i++)
175 string[i] = this_byte_and_next (ieee);
181 common_header_type *ieee;
185 length = this_byte_and_next (ieee);
188 /* Simple string of length 0 to 127 */
190 else if (length == 0xde)
192 /* Length is next byte, allowing 0..255 */
193 length = this_byte_and_next (ieee);
195 else if (length == 0xdf)
197 /* Length is next two bytes, allowing 0..65535 */
198 length = this_byte_and_next (ieee);
199 length = (length * 256) + this_byte_and_next (ieee);
201 /* Buy memory and read string */
202 string = bfd_alloc (ieee->abfd, length + 1);
205 bfd_get_string (ieee, string, length);
211 ieee_write_expression (abfd, value, symbol, pcrel, index)
218 unsigned int term_count = 0;
222 ieee_write_int (abfd, value);
226 if (bfd_is_com_section (symbol->section)
227 || bfd_is_und_section (symbol->section))
229 /* Def of a common symbol */
230 ieee_write_byte (abfd, ieee_variable_X_enum);
231 ieee_write_int (abfd, symbol->value);
234 else if (! bfd_is_abs_section (symbol->section))
236 /* Ref to defined symbol - */
238 ieee_write_byte (abfd, ieee_variable_R_enum);
239 ieee_write_byte (abfd,
240 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
242 if (symbol->flags & BSF_GLOBAL)
244 ieee_write_byte (abfd, ieee_variable_I_enum);
245 ieee_write_int (abfd, symbol->value);
248 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
250 /* This is a reference to a defined local symbol,
251 We can easily do a local as a section+offset */
252 ieee_write_byte (abfd, ieee_variable_R_enum); /* or L */
253 ieee_write_byte (abfd,
254 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
255 ieee_write_int (abfd, symbol->value);
266 /* subtract the pc from here by asking for PC of this section*/
267 ieee_write_byte (abfd, ieee_variable_P_enum);
268 ieee_write_byte (abfd, (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE));
269 ieee_write_byte (abfd, ieee_function_minus_enum);
274 ieee_write_byte (abfd, 0);
278 while (term_count > 1)
280 ieee_write_byte (abfd, ieee_function_plus_enum);
287 /*****************************************************************************/
290 writes any integer into the buffer supplied and always takes 5 bytes
293 ieee_write_int5 (buffer, value)
297 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
298 buffer[1] = (value >> 24) & 0xff;
299 buffer[2] = (value >> 16) & 0xff;
300 buffer[3] = (value >> 8) & 0xff;
301 buffer[4] = (value >> 0) & 0xff;
305 ieee_write_int5_out (abfd, value)
310 ieee_write_int5 (b, value);
311 if (bfd_write ((PTR) b, 1, 5, abfd) != 5)
316 parse_int (ieee, value_ptr)
317 common_header_type *ieee;
320 int value = this_byte (ieee);
322 if (value >= 0 && value <= 127)
328 else if (value >= 0x80 && value <= 0x88)
330 unsigned int count = value & 0xf;
335 result = (result << 8) | this_byte_and_next (ieee);
346 common_header_type *ieee;
350 *ok = parse_int (ieee, &x);
355 must_parse_int (ieee)
356 common_header_type *ieee;
359 BFD_ASSERT (parse_int (ieee, &result) == true);
367 ieee_symbol_index_type symbol;
372 reloc_howto_type abs32_howto
373 = HOWTO (1, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false);
375 reloc_howto_type abs16_howto
376 = HOWTO (1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false);
379 reloc_howto_type abs8_howto
380 = HOWTO (1, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false);
383 reloc_howto_type rel32_howto
384 = HOWTO (1, 0, 2, 32, true, 0, complain_overflow_signed, 0, "rel32", true, 0xffffffff,
388 reloc_howto_type rel16_howto
389 = HOWTO (1, 0, 1, 16, true, 0, complain_overflow_signed, 0, "rel16", true, 0x0000ffff, 0x0000ffff, false);
392 reloc_howto_type rel8_howto
393 = HOWTO (1, 0, 0, 8, true, 0, complain_overflow_signed, 0, "rel8", true, 0x000000ff, 0x000000ff, false);
396 static ieee_symbol_index_type NOSYMBOL =
401 parse_expression (ieee, value, symbol, pcrel, extra, section)
402 ieee_data_type *ieee;
404 ieee_symbol_index_type *symbol;
417 ieee_value_type stack[10];
419 /* The stack pointer always points to the next unused location */
420 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
421 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
422 ieee_value_type *sp = stack;
426 switch (this_byte (&(ieee->h)))
428 case ieee_variable_P_enum:
429 /* P variable, current program counter for section n */
432 next_byte (&(ieee->h));
434 section_n = must_parse_int (&(ieee->h));
435 PUSH (NOSYMBOL, bfd_abs_section_ptr,
436 TOS.value = ieee->section_table[section_n]->vma +
437 ieee_per_section (ieee->section_table[section_n])->pc);
440 case ieee_variable_L_enum:
441 /* L variable address of section N */
442 next_byte (&(ieee->h));
443 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
445 case ieee_variable_R_enum:
446 /* R variable, logical address of section module */
447 /* FIXME, this should be different to L */
448 next_byte (&(ieee->h));
449 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
451 case ieee_variable_S_enum:
452 /* S variable, size in MAUS of section module */
453 next_byte (&(ieee->h));
456 ieee->section_table[must_parse_int (&(ieee->h))]->_raw_size);
458 case ieee_variable_I_enum:
459 case ieee_variable_X_enum:
460 /* Push the address of external variable n */
462 ieee_symbol_index_type sy;
463 next_byte (&(ieee->h));
464 sy.index = (int) (must_parse_int (&(ieee->h)));
467 PUSH (sy, bfd_und_section_ptr, 0);
470 case ieee_function_minus_enum:
472 bfd_vma value1, value2;
473 asection *section1, *section_dummy;
474 ieee_symbol_index_type sy;
475 next_byte (&(ieee->h));
477 POP (sy, section1, value1);
478 POP (sy, section_dummy, value2);
479 PUSH (sy, section1 ? section1 : section_dummy, value1 - value2);
482 case ieee_function_plus_enum:
484 bfd_vma value1, value2;
487 ieee_symbol_index_type sy1;
488 ieee_symbol_index_type sy2;
489 next_byte (&(ieee->h));
491 POP (sy1, section1, value1);
492 POP (sy2, section2, value2);
493 PUSH (sy1.letter ? sy1 : sy2,
494 bfd_is_abs_section (section1) ? section2 : section1,
501 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
502 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
503 if (parse_int (&(ieee->h), &va))
505 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
510 Thats all that we can understand. As far as I can see
511 there is a bug in the Microtec IEEE output which I'm
512 using to scan, whereby the comma operator is omitted
513 sometimes in an expression, giving expressions with too
514 many terms. We can tell if that's the case by ensuring
515 that sp == stack here. If not, then we've pushed
516 something too far, so we keep adding. */
518 while (sp != stack + 1)
521 ieee_symbol_index_type sy1;
522 POP (sy1, section1, *extra);
527 POP (*symbol, dummy, *value);
540 #define ieee_seek(abfd, offset) \
541 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
543 #define ieee_pos(abfd) \
544 (IEEE_DATA(abfd)->h.input_p - IEEE_DATA(abfd)->h.first_byte)
546 static unsigned int last_index;
547 static char last_type; /* is the index for an X or a D */
549 static ieee_symbol_type *
559 ieee_data_type *ieee;
560 ieee_symbol_type *last_symbol;
561 unsigned int *symbol_count;
562 ieee_symbol_type ***pptr;
563 unsigned int *max_index;
567 /* Need a new symbol */
568 unsigned int new_index = must_parse_int (&(ieee->h));
569 if (new_index != last_index || this_type != last_type)
571 ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_alloc (ieee->h.abfd,
572 sizeof (ieee_symbol_type));
576 new_symbol->index = new_index;
577 last_index = new_index;
580 *pptr = &new_symbol->next;
581 if (new_index > *max_index)
583 *max_index = new_index;
585 last_type = this_type;
592 ieee_slurp_external_symbols (abfd)
595 ieee_data_type *ieee = IEEE_DATA (abfd);
596 file_ptr offset = ieee->w.r.external_part;
598 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
599 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
600 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
601 unsigned int symbol_count = 0;
603 last_index = 0xffffff;
604 ieee->symbol_table_full = true;
606 ieee_seek (abfd, offset);
610 switch (this_byte (&(ieee->h)))
613 next_byte (&(ieee->h));
615 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
617 &ieee->external_symbol_max_index, 'D');
621 symbol->symbol.the_bfd = abfd;
622 symbol->symbol.name = read_id (&(ieee->h));
623 symbol->symbol.udata.p = (PTR) NULL;
624 symbol->symbol.flags = BSF_NO_FLAGS;
626 case ieee_external_symbol_enum:
627 next_byte (&(ieee->h));
629 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
631 &ieee->external_symbol_max_index, 'D');
635 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
637 symbol->symbol.the_bfd = abfd;
638 symbol->symbol.name = read_id (&(ieee->h));
639 symbol->symbol.udata.p = (PTR) NULL;
640 symbol->symbol.flags = BSF_NO_FLAGS;
642 case ieee_attribute_record_enum >> 8:
644 unsigned int symbol_name_index;
645 unsigned int symbol_type_index;
646 unsigned int symbol_attribute_def;
648 next_byte (&(ieee->h)); /* Skip prefix */
649 next_byte (&(ieee->h));
650 symbol_name_index = must_parse_int (&(ieee->h));
651 symbol_type_index = must_parse_int (&(ieee->h));
652 symbol_attribute_def = must_parse_int (&(ieee->h));
653 switch (symbol_attribute_def)
656 /* Module misc; followed by two fields which describe the
657 current module block. The first fired is the type id
658 number, the second is the number of asn records
659 associated with the directive */
660 parse_int (&(ieee->h), &value);
661 parse_int (&(ieee->h), &value);
665 parse_int (&(ieee->h), &value);
670 case ieee_value_record_enum >> 8:
672 unsigned int symbol_name_index;
673 ieee_symbol_index_type symbol_ignore;
674 boolean pcrel_ignore;
676 next_byte (&(ieee->h));
677 next_byte (&(ieee->h));
679 symbol_name_index = must_parse_int (&(ieee->h));
680 parse_expression (ieee,
681 &symbol->symbol.value,
685 &symbol->symbol.section);
687 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
691 case ieee_weak_external_reference_enum:
695 next_byte (&(ieee->h));
696 /* Throw away the external reference index */
697 (void) must_parse_int (&(ieee->h));
698 /* Fetch the default size if not resolved */
699 size = must_parse_int (&(ieee->h));
700 /* Fetch the defautlt value if available */
701 if (parse_int (&(ieee->h), &value) == false)
705 /* This turns into a common */
706 symbol->symbol.section = bfd_com_section_ptr;
707 symbol->symbol.value = size;
711 case ieee_external_reference_enum:
712 next_byte (&(ieee->h));
714 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
716 &ieee->external_reference_max_index, 'X');
720 symbol->symbol.the_bfd = abfd;
721 symbol->symbol.name = read_id (&(ieee->h));
722 symbol->symbol.udata.p = (PTR) NULL;
723 symbol->symbol.section = bfd_und_section_ptr;
724 symbol->symbol.value = (bfd_vma) 0;
725 symbol->symbol.flags = 0;
727 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
735 if (ieee->external_symbol_max_index != 0)
737 ieee->external_symbol_count =
738 ieee->external_symbol_max_index -
739 ieee->external_symbol_min_index + 1;
743 ieee->external_symbol_count = 0;
746 if (ieee->external_reference_max_index != 0)
748 ieee->external_reference_count =
749 ieee->external_reference_max_index -
750 ieee->external_reference_min_index + 1;
754 ieee->external_reference_count = 0;
758 ieee->external_reference_count + ieee->external_symbol_count;
760 if (symbol_count != abfd->symcount)
762 /* There are gaps in the table -- */
763 ieee->symbol_table_full = false;
766 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
767 *prev_reference_ptr = (ieee_symbol_type *) NULL;
773 ieee_slurp_symbol_table (abfd)
776 if (IEEE_DATA (abfd)->read_symbols == false)
778 if (! ieee_slurp_external_symbols (abfd))
780 IEEE_DATA (abfd)->read_symbols = true;
786 ieee_get_symtab_upper_bound (abfd)
789 if (! ieee_slurp_symbol_table (abfd))
792 return (abfd->symcount != 0) ?
793 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
797 Move from our internal lists to the canon table, and insert in
801 extern const bfd_target ieee_vec;
804 ieee_get_symtab (abfd, location)
808 ieee_symbol_type *symp;
809 static bfd dummy_bfd;
810 static asymbol empty_symbol =
811 /* the_bfd, name, value, attr, section */
812 {&dummy_bfd, " ieee empty", (symvalue) 0, BSF_DEBUGGING, bfd_abs_section_ptr};
816 ieee_data_type *ieee = IEEE_DATA (abfd);
817 dummy_bfd.xvec = &ieee_vec;
818 if (! ieee_slurp_symbol_table (abfd))
821 if (ieee->symbol_table_full == false)
823 /* Arrgh - there are gaps in the table, run through and fill them */
824 /* up with pointers to a null place */
826 for (i = 0; i < abfd->symcount; i++)
828 location[i] = &empty_symbol;
832 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
833 for (symp = IEEE_DATA (abfd)->external_symbols;
834 symp != (ieee_symbol_type *) NULL;
837 /* Place into table at correct index locations */
838 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
841 /* The external refs are indexed in a bit */
842 ieee->external_reference_base_offset =
843 -ieee->external_reference_min_index + ieee->external_symbol_count;
845 for (symp = IEEE_DATA (abfd)->external_reference;
846 symp != (ieee_symbol_type *) NULL;
849 location[symp->index + ieee->external_reference_base_offset] =
856 location[abfd->symcount] = (asymbol *) NULL;
858 return abfd->symcount;
862 get_section_entry (abfd, ieee, index)
864 ieee_data_type *ieee;
867 if (ieee->section_table[index] == (asection *) NULL)
869 char *tmp = bfd_alloc (abfd, 11);
874 sprintf (tmp, " fsec%4d", index);
875 section = bfd_make_section (abfd, tmp);
876 ieee->section_table[index] = section;
877 section->flags = SEC_NO_FLAGS;
878 section->target_index = index;
879 ieee->section_table[index] = section;
881 return ieee->section_table[index];
885 ieee_slurp_sections (abfd)
888 ieee_data_type *ieee = IEEE_DATA (abfd);
889 file_ptr offset = ieee->w.r.section_part;
890 asection *section = (asection *) NULL;
895 bfd_byte section_type[3];
896 ieee_seek (abfd, offset);
899 switch (this_byte (&(ieee->h)))
901 case ieee_section_type_enum:
903 unsigned int section_index;
904 next_byte (&(ieee->h));
905 section_index = must_parse_int (&(ieee->h));
906 /* Fixme to be nice about a silly number of sections */
907 BFD_ASSERT (section_index < NSECTIONS);
909 section = get_section_entry (abfd, ieee, section_index);
911 section_type[0] = this_byte_and_next (&(ieee->h));
912 switch (section_type[0])
915 /* Normal attributes for absolute sections */
916 section_type[1] = this_byte (&(ieee->h));
917 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
918 switch (section_type[1])
920 case 0xD3: /* AS Absolute section attributes */
921 next_byte (&(ieee->h));
922 section_type[2] = this_byte (&(ieee->h));
923 switch (section_type[2])
927 next_byte (&(ieee->h));
928 section->flags |= SEC_LOAD | SEC_CODE;
931 next_byte (&(ieee->h));
932 section->flags |= SEC_LOAD | SEC_DATA;
936 next_byte (&(ieee->h));
937 /* Normal rom data */
938 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
945 case 0xC3: /* Named relocatable sections (type C) */
946 section_type[1] = this_byte (&(ieee->h));
947 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
948 switch (section_type[1])
950 case 0xD0: /* Normal code (CP) */
951 next_byte (&(ieee->h));
952 section->flags |= SEC_LOAD | SEC_CODE;
954 case 0xC4: /* Normal data (CD) */
955 next_byte (&(ieee->h));
956 section->flags |= SEC_LOAD | SEC_DATA;
958 case 0xD2: /* Normal rom data (CR) */
959 next_byte (&(ieee->h));
960 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
967 /* Read section name, use it if non empty. */
968 name = read_id (&ieee->h);
970 section->name = name;
972 /* Skip these fields, which we don't care about */
974 bfd_vma parent, brother, context;
975 parse_int (&(ieee->h), &parent);
976 parse_int (&(ieee->h), &brother);
977 parse_int (&(ieee->h), &context);
981 case ieee_section_alignment_enum:
983 unsigned int section_index;
986 next_byte (&(ieee->h));
987 section_index = must_parse_int (&ieee->h);
988 section = get_section_entry (abfd, ieee, section_index);
989 if (section_index > ieee->section_count)
991 ieee->section_count = section_index;
993 section->alignment_power =
994 bfd_log2 (must_parse_int (&ieee->h));
995 (void) parse_int (&(ieee->h), &value);
998 case ieee_e2_first_byte_enum:
1000 ieee_record_enum_type t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1004 case ieee_section_size_enum:
1005 section = ieee->section_table[must_parse_int (&(ieee->h))];
1006 section->_raw_size = must_parse_int (&(ieee->h));
1008 case ieee_physical_region_size_enum:
1009 section = ieee->section_table[must_parse_int (&(ieee->h))];
1010 section->_raw_size = must_parse_int (&(ieee->h));
1012 case ieee_region_base_address_enum:
1013 section = ieee->section_table[must_parse_int (&(ieee->h))];
1014 section->vma = must_parse_int (&(ieee->h));
1016 case ieee_mau_size_enum:
1017 must_parse_int (&(ieee->h));
1018 must_parse_int (&(ieee->h));
1020 case ieee_m_value_enum:
1021 must_parse_int (&(ieee->h));
1022 must_parse_int (&(ieee->h));
1024 case ieee_section_base_address_enum:
1025 section = ieee->section_table[must_parse_int (&(ieee->h))];
1026 section->vma = must_parse_int (&(ieee->h));
1028 case ieee_section_offset_enum:
1029 (void) must_parse_int (&(ieee->h));
1030 (void) must_parse_int (&(ieee->h));
1045 /***********************************************************************
1050 ieee_archive_p (abfd)
1057 unsigned char buffer[512];
1059 file_ptr buffer_offset = 0;
1060 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1061 ieee_ar_data_type *ieee;
1062 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, sizeof (ieee_ar_data_type));
1063 if (!abfd->tdata.ieee_ar_data)
1065 ieee = IEEE_AR_DATA (abfd);
1067 /* FIXME: Check return value. I'm not sure whether it needs to read
1068 the entire buffer or not. */
1069 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1071 ieee->h.first_byte = buffer;
1072 ieee->h.input_p = buffer;
1074 ieee->h.abfd = abfd;
1076 if (this_byte (&(ieee->h)) != Module_Beginning)
1078 abfd->tdata.ieee_ar_data = save;
1079 return (const bfd_target *) NULL;
1082 next_byte (&(ieee->h));
1083 library = read_id (&(ieee->h));
1084 if (strcmp (library, "LIBRARY") != 0)
1086 bfd_release (abfd, ieee);
1087 abfd->tdata.ieee_ar_data = save;
1088 return (const bfd_target *) NULL;
1090 /* Throw away the filename */
1091 read_id (&(ieee->h));
1092 /* This must be an IEEE archive, so we'll buy some space to do
1095 if (!obstack_begin (&ob, 128))
1097 bfd_set_error (bfd_error_no_memory);
1098 return (const bfd_target *) NULL;
1101 ieee->element_count = 0;
1102 ieee->element_index = 0;
1104 next_byte (&(ieee->h)); /* Drop the ad part */
1105 must_parse_int (&(ieee->h)); /* And the two dummy numbers */
1106 must_parse_int (&(ieee->h));
1109 /* Read the index of the BB table */
1112 ieee_ar_obstack_type t;
1113 int rec = read_2bytes (&(ieee->h));
1114 if (rec == (int) ieee_assign_value_to_variable_enum)
1116 must_parse_int (&(ieee->h));
1117 t.file_offset = must_parse_int (&(ieee->h));
1118 t.abfd = (bfd *) NULL;
1119 ieee->element_count++;
1121 obstack_grow (&ob, (PTR) & t, sizeof (t));
1123 /* Make sure that we don't go over the end of the buffer */
1125 if ((size_t) ieee_pos (abfd) > sizeof (buffer) / 2)
1127 /* Past half way, reseek and reprime */
1128 buffer_offset += ieee_pos (abfd);
1129 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1131 /* FIXME: Check return value. I'm not sure whether it
1132 needs to read the entire buffer or not. */
1133 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1134 ieee->h.first_byte = buffer;
1135 ieee->h.input_p = buffer;
1142 ieee->elements = (ieee_ar_obstack_type *) obstack_finish (&ob);
1143 if (!ieee->elements)
1145 bfd_set_error (bfd_error_no_memory);
1146 return (const bfd_target *) NULL;
1149 /* Now scan the area again, and replace BB offsets with file */
1152 for (i = 2; i < ieee->element_count; i++)
1154 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1156 /* FIXME: Check return value. I'm not sure whether it needs to
1157 read the entire buffer or not. */
1158 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1159 ieee->h.first_byte = buffer;
1160 ieee->h.input_p = buffer;
1162 next_byte (&(ieee->h)); /* Drop F8 */
1163 next_byte (&(ieee->h)); /* Drop 14 */
1164 must_parse_int (&(ieee->h)); /* Drop size of block */
1165 if (must_parse_int (&(ieee->h)) != 0)
1167 /* This object has been deleted */
1168 ieee->elements[i].file_offset = 0;
1172 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1176 /* abfd->has_armap = ;*/
1181 ieee_mkobject (abfd)
1184 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, sizeof (ieee_data_type));
1185 return abfd->tdata.ieee_data ? true : false;
1189 ieee_object_p (abfd)
1194 ieee_data_type *ieee;
1195 unsigned char buffer[300];
1196 ieee_data_type *save = IEEE_DATA (abfd);
1198 abfd->tdata.ieee_data = 0;
1199 ieee_mkobject (abfd);
1201 ieee = IEEE_DATA (abfd);
1202 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1204 /* Read the first few bytes in to see if it makes sense */
1205 /* FIXME: Check return value. I'm not sure whether it needs to read
1206 the entire buffer or not. */
1207 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1209 ieee->h.input_p = buffer;
1210 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1211 goto got_wrong_format;
1213 ieee->read_symbols = false;
1214 ieee->read_data = false;
1215 ieee->section_count = 0;
1216 ieee->external_symbol_max_index = 0;
1217 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1218 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1219 ieee->external_reference_max_index = 0;
1220 ieee->h.abfd = abfd;
1221 memset ((PTR) ieee->section_table, 0, sizeof (ieee->section_table));
1223 processor = ieee->mb.processor = read_id (&(ieee->h));
1224 if (strcmp (processor, "LIBRARY") == 0)
1225 goto got_wrong_format;
1226 ieee->mb.module_name = read_id (&(ieee->h));
1227 if (abfd->filename == (CONST char *) NULL)
1229 abfd->filename = ieee->mb.module_name;
1231 /* Determine the architecture and machine type of the object file.
1234 const bfd_arch_info_type *arch = bfd_scan_arch (processor);
1236 goto got_wrong_format;
1237 abfd->arch_info = arch;
1240 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1244 next_byte (&(ieee->h));
1246 if (parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau) == false)
1250 if (parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address) == false)
1255 /* If there is a byte order info, take it */
1256 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum ||
1257 this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
1258 next_byte (&(ieee->h));
1260 for (part = 0; part < N_W_VARIABLES; part++)
1263 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
1267 if (this_byte_and_next (&(ieee->h)) != part)
1272 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
1279 abfd->flags = HAS_SYMS;
1280 /* By now we know that this is a real IEEE file, we're going to read
1281 the whole thing into memory so that we can run up and down it
1282 quickly. We can work out how big the file is from the trailer
1285 IEEE_DATA (abfd)->h.first_byte = (unsigned char *) bfd_alloc (ieee->h.abfd, ieee->w.r.me_record
1287 if (!IEEE_DATA (abfd)->h.first_byte)
1289 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1291 /* FIXME: Check return value. I'm not sure whether it needs to read
1292 the entire buffer or not. */
1293 bfd_read ((PTR) (IEEE_DATA (abfd)->h.first_byte), 1, ieee->w.r.me_record + 50, abfd);
1295 ieee_slurp_sections (abfd);
1298 bfd_set_error (bfd_error_wrong_format);
1300 (void) bfd_release (abfd, ieee);
1301 abfd->tdata.ieee_data = save;
1302 return (const bfd_target *) NULL;
1306 ieee_get_symbol_info (ignore_abfd, symbol, ret)
1311 bfd_symbol_info (symbol, ret);
1312 if (symbol->name[0] == ' ')
1313 ret->name = "* empty table entry ";
1314 if (!symbol->section)
1315 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
1319 ieee_print_symbol (ignore_abfd, afile, symbol, how)
1323 bfd_print_symbol_type how;
1325 FILE *file = (FILE *) afile;
1329 case bfd_print_symbol_name:
1330 fprintf (file, "%s", symbol->name);
1332 case bfd_print_symbol_more:
1334 fprintf (file, "%4x %2x", aout_symbol (symbol)->desc & 0xffff,
1335 aout_symbol (symbol)->other & 0xff);
1339 case bfd_print_symbol_all:
1341 CONST char *section_name = symbol->section == (asection *) NULL ?
1342 (CONST char *) "*abs" : symbol->section->name;
1343 if (symbol->name[0] == ' ')
1345 fprintf (file, "* empty table entry ");
1349 bfd_print_symbol_vandf ((PTR) file, symbol);
1351 fprintf (file, " %-5s %04x %02x %s",
1353 (unsigned) ieee_symbol (symbol)->index,
1355 aout_symbol(symbol)->desc & 0xffff,
1356 aout_symbol(symbol)->other & 0xff,*/
1365 do_one (ieee, current_map, location_ptr, s)
1366 ieee_data_type *ieee;
1367 ieee_per_section_type *current_map;
1368 unsigned char *location_ptr;
1371 switch (this_byte (&(ieee->h)))
1373 case ieee_load_constant_bytes_enum:
1375 unsigned int number_of_maus;
1377 next_byte (&(ieee->h));
1378 number_of_maus = must_parse_int (&(ieee->h));
1380 for (i = 0; i < number_of_maus; i++)
1382 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1383 next_byte (&(ieee->h));
1388 case ieee_load_with_relocation_enum:
1390 boolean loop = true;
1391 next_byte (&(ieee->h));
1394 switch (this_byte (&(ieee->h)))
1396 case ieee_variable_R_enum:
1398 case ieee_function_signed_open_b_enum:
1399 case ieee_function_unsigned_open_b_enum:
1400 case ieee_function_either_open_b_enum:
1402 unsigned int extra = 4;
1403 boolean pcrel = false;
1405 ieee_reloc_type *r =
1406 (ieee_reloc_type *) bfd_alloc (ieee->h.abfd,
1407 sizeof (ieee_reloc_type));
1411 *(current_map->reloc_tail_ptr) = r;
1412 current_map->reloc_tail_ptr = &r->next;
1413 r->next = (ieee_reloc_type *) NULL;
1414 next_byte (&(ieee->h));
1416 r->relent.sym_ptr_ptr = 0;
1417 parse_expression (ieee,
1420 &pcrel, &extra, §ion);
1421 r->relent.address = current_map->pc;
1423 if (r->relent.sym_ptr_ptr == 0)
1425 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1428 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1430 next_byte (&(ieee->h));
1431 /* Fetch number of bytes to pad */
1432 extra = must_parse_int (&(ieee->h));
1435 switch (this_byte (&(ieee->h)))
1437 case ieee_function_signed_close_b_enum:
1438 next_byte (&(ieee->h));
1440 case ieee_function_unsigned_close_b_enum:
1441 next_byte (&(ieee->h));
1443 case ieee_function_either_close_b_enum:
1444 next_byte (&(ieee->h));
1449 /* Build a relocation entry for this type */
1450 /* If pc rel then stick -ve pc into instruction
1451 and take out of reloc ..
1453 I've changed this. It's all too
1454 complicated. I keep 0 in the
1465 #if KEEPMINUSPCININST
1466 bfd_put_32 (ieee->h.abfd, -current_map->pc, location_ptr +
1468 r->relent.howto = &rel32_howto;
1472 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1474 r->relent.howto = &rel32_howto;
1479 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1481 r->relent.howto = &abs32_howto;
1483 current_map->pc += 4;
1488 #if KEEPMINUSPCININST
1489 bfd_put_16 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1490 r->relent.addend -= current_map->pc;
1491 r->relent.howto = &rel16_howto;
1494 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1495 r->relent.howto = &rel16_howto;
1501 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1502 r->relent.howto = &abs16_howto;
1504 current_map->pc += 2;
1509 #if KEEPMINUSPCININST
1510 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1511 r->relent.addend -= current_map->pc;
1512 r->relent.howto = &rel8_howto;
1514 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1515 r->relent.howto = &rel8_howto;
1520 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1521 r->relent.howto = &abs8_howto;
1523 current_map->pc += 1;
1535 if (parse_int (&(ieee->h), &this_size) == true)
1538 for (i = 0; i < this_size; i++)
1540 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1541 next_byte (&(ieee->h));
1556 /* Read in all the section data and relocation stuff too */
1558 ieee_slurp_section_data (abfd)
1561 bfd_byte *location_ptr = (bfd_byte *) NULL;
1562 ieee_data_type *ieee = IEEE_DATA (abfd);
1563 unsigned int section_number;
1565 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
1567 /* Seek to the start of the data area */
1568 if (ieee->read_data == true)
1570 ieee->read_data = true;
1571 ieee_seek (abfd, ieee->w.r.data_part);
1573 /* Allocate enough space for all the section contents */
1575 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1577 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1578 per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->_raw_size);
1582 per->reloc_tail_ptr =
1583 (ieee_reloc_type **) & (s->relocation);
1588 switch (this_byte (&(ieee->h)))
1590 /* IF we see anything strange then quit */
1594 case ieee_set_current_section_enum:
1595 next_byte (&(ieee->h));
1596 section_number = must_parse_int (&(ieee->h));
1597 s = ieee->section_table[section_number];
1598 current_map = (ieee_per_section_type *) s->used_by_bfd;
1599 location_ptr = current_map->data - s->vma;
1600 /* The document I have says that Microtec's compilers reset */
1601 /* this after a sec section, even though the standard says not */
1603 current_map->pc = s->vma;
1606 case ieee_e2_first_byte_enum:
1607 next_byte (&(ieee->h));
1608 switch (this_byte (&(ieee->h)))
1610 case ieee_set_current_pc_enum & 0xff:
1613 ieee_symbol_index_type symbol;
1616 next_byte (&(ieee->h));
1617 must_parse_int (&(ieee->h)); /* Thow away section #*/
1618 parse_expression (ieee, &value,
1622 current_map->pc = value;
1623 BFD_ASSERT ((unsigned) (value - s->vma) <= s->_raw_size);
1627 case ieee_value_starting_address_enum & 0xff:
1628 /* We've got to the end of the data now - */
1635 case ieee_repeat_data_enum:
1637 /* Repeat the following LD or LR n times - we do this by
1638 remembering the stream pointer before running it and
1639 resetting it and running it n times. We special case
1640 the repetition of a repeat_data/load_constant
1643 unsigned int iterations;
1644 unsigned char *start;
1645 next_byte (&(ieee->h));
1646 iterations = must_parse_int (&(ieee->h));
1647 start = ieee->h.input_p;
1648 if (start[0] == (int) ieee_load_constant_bytes_enum &&
1651 while (iterations != 0)
1653 location_ptr[current_map->pc++] = start[2];
1656 next_byte (&(ieee->h));
1657 next_byte (&(ieee->h));
1658 next_byte (&(ieee->h));
1662 while (iterations != 0)
1664 ieee->h.input_p = start;
1665 if (!do_one (ieee, current_map, location_ptr, s))
1672 case ieee_load_constant_bytes_enum:
1673 case ieee_load_with_relocation_enum:
1675 if (!do_one (ieee, current_map, location_ptr, s))
1683 ieee_new_section_hook (abfd, newsect)
1687 newsect->used_by_bfd = (PTR)
1688 bfd_alloc (abfd, sizeof (ieee_per_section_type));
1689 if (!newsect->used_by_bfd)
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 (! bfd_is_abs_section (s))
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 if (bfd_write ((PTR) (stream + current_byte_index),
1894 current_byte_index += run;
1900 ieee_write_byte (abfd, ieee_load_with_relocation_enum);
1903 /* Output the data stream as the longest sequence of bytes
1904 possible, allowing for the a reasonable packet size and
1905 relocation stuffs */
1907 if ((PTR) stream == (PTR) NULL)
1909 /* Outputting a section without data, fill it up */
1910 stream = (unsigned char *) (bfd_alloc (abfd, s->_raw_size));
1913 memset ((PTR) stream, 0, (size_t) s->_raw_size);
1915 while (current_byte_index < s->_raw_size)
1918 unsigned int MAXRUN = 32;
1921 run = (*p)->address - current_byte_index;
1927 if (run > s->_raw_size - current_byte_index)
1929 run = s->_raw_size - current_byte_index;
1934 /* Output a stream of bytes */
1935 ieee_write_int (abfd, run);
1936 if (bfd_write ((PTR) (stream + current_byte_index),
1942 current_byte_index += run;
1944 /* Output any relocations here */
1945 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1947 while (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1954 if (r->howto->pc_relative)
1956 r->addend += current_byte_index;
1960 switch (r->howto->size)
1964 ov = bfd_get_32 (abfd,
1965 stream + current_byte_index);
1966 current_byte_index += 4;
1969 ov = bfd_get_16 (abfd,
1970 stream + current_byte_index);
1971 current_byte_index += 2;
1974 ov = bfd_get_8 (abfd,
1975 stream + current_byte_index);
1976 current_byte_index++;
1982 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
1985 if (r->sym_ptr_ptr != (asymbol **) NULL)
1987 ieee_write_expression (abfd, r->addend + ov,
1989 r->howto->pc_relative, s->index);
1993 ieee_write_expression (abfd, r->addend + ov,
1995 r->howto->pc_relative, s->index);
1998 if (1 || r->howto->size != 2)
2000 ieee_write_byte (abfd, ieee_comma);
2001 ieee_write_int (abfd, 1 << r->howto->size);
2003 ieee_write_byte (abfd,
2004 ieee_function_either_close_b_enum);
2016 /* If there are no relocations in the output section then we can
2017 be clever about how we write. We block items up into a max of 127
2021 do_as_repeat (abfd, s)
2027 ieee_write_byte (abfd, ieee_set_current_section_enum);
2028 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2029 ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8);
2030 ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff);
2031 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2032 ieee_write_int (abfd, s->vma);
2034 ieee_write_byte (abfd, ieee_repeat_data_enum);
2035 ieee_write_int (abfd, s->_raw_size);
2036 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
2037 ieee_write_byte (abfd, 1);
2038 ieee_write_byte (abfd, 0);
2043 do_without_relocs (abfd, s)
2047 bfd_byte *stream = ieee_per_section (s)->data;
2049 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2051 do_as_repeat (abfd, s);
2056 for (i = 0; i < s->_raw_size; i++)
2060 do_with_relocs (abfd, s);
2064 do_as_repeat (abfd, s);
2070 static unsigned char *output_ptr_start;
2071 static unsigned char *output_ptr;
2072 static unsigned char *output_ptr_end;
2073 static unsigned char *input_ptr_start;
2074 static unsigned char *input_ptr;
2075 static unsigned char *input_ptr_end;
2076 static bfd *input_bfd;
2077 static bfd *output_bfd;
2078 static int output_buffer;
2083 /* FIXME: Check return value. I'm not sure whether it needs to read
2084 the entire buffer or not. */
2085 bfd_read ((PTR) input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
2086 input_ptr = input_ptr_start;
2091 if (bfd_write ((PTR) (output_ptr_start), 1, output_ptr - output_ptr_start,
2093 != (bfd_size_type) (output_ptr - output_ptr_start))
2095 output_ptr = output_ptr_start;
2099 #define THIS() ( *input_ptr )
2100 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2101 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2107 if (value >= 0 && value <= 127)
2113 unsigned int length;
2114 /* How many significant bytes ? */
2115 /* FIXME FOR LONGER INTS */
2116 if (value & 0xff000000)
2120 else if (value & 0x00ff0000)
2124 else if (value & 0x0000ff00)
2131 OUT ((int) ieee_number_repeat_start_enum + length);
2150 int length = THIS ();
2162 #define VAR(x) ((x | 0x80))
2177 value = (value << 8) | THIS ();
2179 value = (value << 8) | THIS ();
2181 value = (value << 8) | THIS ();
2189 value = (value << 8) | THIS ();
2191 value = (value << 8) | THIS ();
2199 value = (value << 8) | THIS ();
2216 /* Not a number, just bug out with the answer */
2217 write_int (*(--tos));
2227 int value = *(--tos);
2236 ieee_data_type *ieee;
2239 section_number = THIS ();
2242 ieee = IEEE_DATA (input_bfd);
2243 s = ieee->section_table[section_number];
2244 if (s->output_section)
2246 value = s->output_section->vma;
2252 value += s->output_offset;
2260 write_int (*(--tos));
2270 /* Drop the int in the buffer, and copy a null into the gap, which we
2271 will overwrite later */
2273 struct output_buffer_struct
2275 unsigned char *ptrp;
2281 struct output_buffer_struct *buf;
2283 if (buf->buffer == output_buffer)
2285 /* Still a chance to output the size */
2286 int value = output_ptr - buf->ptrp + 3;
2287 buf->ptrp[0] = value >> 24;
2288 buf->ptrp[1] = value >> 16;
2289 buf->ptrp[2] = value >> 8;
2290 buf->ptrp[3] = value >> 0;
2296 struct output_buffer_struct *buf;
2322 buf->ptrp = output_ptr;
2323 buf->buffer = output_buffer;
2363 #define ID copy_id()
2364 #define INT copy_int()
2365 #define EXP copy_expression()
2366 static void copy_till_end ();
2367 #define INTn(q) copy_int()
2368 #define EXPn(q) copy_expression()
2407 EXPn (instruction address);
2441 EXPn (external function);
2451 INTn (locked register);
2474 /* Attribute record */
2532 static void block ();
2544 /* Unique typedefs for module */
2545 /* GLobal typedefs */
2546 /* High level module scope beginning */
2548 struct output_buffer_struct ob;
2563 /* Global function */
2565 struct output_buffer_struct ob;
2579 EXPn (size of block);
2585 /* File name for source line numbers */
2587 struct output_buffer_struct ob;
2607 /* Local function */
2609 struct output_buffer_struct ob;
2627 /* Assembler module scope beginning -*/
2629 struct output_buffer_struct ob;
2655 struct output_buffer_struct ob;
2662 INTn (section index);
2670 EXPn (Size in Maus);
2725 moves all the debug information from the source bfd to the output
2726 bfd, and relocates any expressions it finds
2730 relocate_debug (output, input)
2736 unsigned char input_buffer[IBS];
2738 input_ptr_start = input_ptr = input_buffer;
2739 input_ptr_end = input_buffer + IBS;
2741 /* FIXME: Check return value. I'm not sure whether it needs to read
2742 the entire buffer or not. */
2743 bfd_read ((PTR) input_ptr_start, 1, IBS, input);
2748 During linking, we we told about the bfds which made up our
2749 contents, we have a list of them. They will still be open, so go to
2750 the debug info in each, and copy it out, relocating it as we go.
2754 ieee_write_debug_part (abfd)
2757 ieee_data_type *ieee = IEEE_DATA (abfd);
2758 bfd_chain_type *chain = ieee->chain_root;
2759 unsigned char output_buffer[OBS];
2760 boolean some_debug = false;
2761 file_ptr here = bfd_tell (abfd);
2763 output_ptr_start = output_ptr = output_buffer;
2764 output_ptr_end = output_buffer + OBS;
2765 output_ptr = output_buffer;
2768 if (chain == (bfd_chain_type *) NULL)
2771 /* There is no debug info, so we'll fake some up */
2772 CONST static char fake[] =
2774 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
2775 '1', '.', '1', 0x82, 1991 >> 8, 1991 & 0xff, 9, 20, 11, 07, 50};
2776 ieee->w.r.debug_information_part = 0;
2782 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2783 /* Now write a header for each section */
2786 asection *s = abfd->sections;
2789 if (s != abfd->abs_section)
2792 ieee_write_byte (abfd, 0xf8);
2793 ieee_write_byte (abfd, 0x0b);
2794 ieee_write_byte (abfd, 0);
2795 ieee_write_byte (abfd, 0);
2796 ieee_write_byte (abfd, 1);
2797 ieee_write_byte (abfd, i + IEEE_SECTION_NUMBER_BASE);
2798 ieee_write_expression (abfd, 0, s->symbol, 0, 0, 0);
2799 ieee_write_byte (abfd, 0);
2800 ieee_write_byte (abfd, 0xf9);
2801 ieee_write_expression (abfd, s->size,
2802 bfd_abs_section_ptr->symbol, 0, 0, 0);
2809 /* Close the scope */
2810 ieee_write_byte (abfd, 0xf9);
2816 while (chain != (bfd_chain_type *) NULL)
2818 bfd *entry = chain->this;
2819 ieee_data_type *entry_ieee = IEEE_DATA (entry);
2820 if (entry_ieee->w.r.debug_information_part)
2822 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
2826 relocate_debug (abfd, entry);
2829 chain = chain->next;
2833 ieee->w.r.debug_information_part = here;
2837 ieee->w.r.debug_information_part = 0;
2844 /* write the data in an ieee way */
2846 ieee_write_data_part (abfd)
2850 ieee_data_type *ieee = IEEE_DATA (abfd);
2851 ieee->w.r.data_part = bfd_tell (abfd);
2852 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2854 /* Sort the reloc records so we can insert them in the correct
2856 if (s->reloc_count != 0)
2858 do_with_relocs (abfd, s);
2862 do_without_relocs (abfd, s);
2869 init_for_output (abfd)
2873 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2875 if (s->_raw_size != 0)
2877 ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, s->_raw_size));
2878 if (!ieee_per_section (s)->data)
2885 /** exec and core file sections */
2887 /* set section contents is complicated with IEEE since the format is
2888 * not a byte image, but a record stream.
2891 ieee_set_section_contents (abfd, section, location, offset, count)
2896 bfd_size_type count;
2898 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
2900 if (!init_for_output (abfd))
2903 memcpy ((PTR) (ieee_per_section (section)->data + offset),
2905 (unsigned int) count);
2910 write the external symbols of a file, IEEE considers two sorts of
2911 external symbols, public, and referenced. It uses to internal forms
2912 to index them as well. When we write them out we turn their symbol
2913 values into indexes from the right base.
2916 ieee_write_external_part (abfd)
2920 ieee_data_type *ieee = IEEE_DATA (abfd);
2922 unsigned int reference_index = IEEE_REFERENCE_BASE;
2923 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
2924 file_ptr here = bfd_tell (abfd);
2925 boolean hadone = false;
2926 if (abfd->outsymbols != (asymbol **) NULL)
2929 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
2933 if (bfd_is_und_section (p->section))
2935 /* This must be a symbol reference .. */
2936 ieee_write_byte (abfd, ieee_external_reference_enum);
2937 ieee_write_int (abfd, reference_index);
2938 ieee_write_id (abfd, p->name);
2939 p->value = reference_index;
2942 else if (bfd_is_com_section (p->section))
2944 /* This is a weak reference */
2945 ieee_write_byte (abfd, ieee_external_reference_enum);
2946 ieee_write_int (abfd, reference_index);
2947 ieee_write_id (abfd, p->name);
2948 ieee_write_byte (abfd, ieee_weak_external_reference_enum);
2949 ieee_write_int (abfd, reference_index);
2950 ieee_write_int (abfd, p->value);
2951 ieee_write_int (abfd, BFD_FORT_COMM_DEFAULT_VALUE);
2952 p->value = reference_index;
2955 else if (p->flags & BSF_GLOBAL)
2957 /* This must be a symbol definition */
2960 ieee_write_byte (abfd, ieee_external_symbol_enum);
2961 ieee_write_int (abfd, public_index);
2962 ieee_write_id (abfd, p->name);
2964 ieee_write_twobyte (abfd, ieee_attribute_record_enum);
2965 ieee_write_int (abfd, public_index);
2966 ieee_write_byte (abfd, 15); /* instruction address */
2967 ieee_write_byte (abfd, 19); /* static symbol */
2968 ieee_write_byte (abfd, 1); /* one of them */
2971 /* Write out the value */
2972 ieee_write_2bytes (abfd, ieee_value_record_enum);
2973 ieee_write_int (abfd, public_index);
2974 if (! bfd_is_abs_section (p->section))
2976 if (abfd->flags & EXEC_P)
2978 /* If fully linked, then output all symbols
2980 ieee_write_int (abfd,
2981 p->value + p->section->output_offset + p->section->output_section->vma);
2986 ieee_write_expression (abfd,
2987 p->value + p->section->output_offset,
2988 p->section->output_section->symbol
2994 ieee_write_expression (abfd,
2996 bfd_abs_section_ptr->symbol,
2999 p->value = public_index;
3004 /* This can happen - when there are gaps in the symbols read */
3005 /* from an input ieee file */
3010 ieee->w.r.external_part = here;
3015 static CONST unsigned char exten[] =
3018 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3019 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3020 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3023 static CONST unsigned char envi[] =
3027 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3030 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3032 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3033 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3038 ieee_write_me_part (abfd)
3041 ieee_data_type *ieee = IEEE_DATA (abfd);
3042 ieee->w.r.trailer_part = bfd_tell (abfd);
3043 if (abfd->start_address)
3045 ieee->w.r.me_record = bfd_tell (abfd);
3046 ieee_write_2bytes (abfd, ieee_value_starting_address_enum);
3047 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
3048 ieee_write_int (abfd, abfd->start_address);
3049 ieee_write_byte (abfd, ieee_function_either_close_b_enum);
3053 ieee->w.r.me_record = bfd_tell (abfd);
3055 ieee_write_byte (abfd, ieee_module_end_enum);
3060 ieee_write_object_contents (abfd)
3063 ieee_data_type *ieee = IEEE_DATA (abfd);
3066 /* Fast forward over the header area */
3067 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3069 ieee_write_byte (abfd, ieee_module_beginning_enum);
3071 ieee_write_id (abfd, bfd_printable_name (abfd));
3072 ieee_write_id (abfd, abfd->filename);
3074 /* Fast forward over the variable bits */
3075 ieee_write_byte (abfd, ieee_address_descriptor_enum);
3078 ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd)));
3079 /* MAU's per address */
3080 ieee_write_byte (abfd,
3081 (bfd_byte) (bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd)));
3083 old = bfd_tell (abfd);
3084 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3087 ieee->w.r.extension_record = bfd_tell (abfd);
3088 if (bfd_write ((char *) exten, 1, sizeof (exten), abfd) != sizeof (exten))
3090 if (abfd->flags & EXEC_P)
3091 ieee_write_byte (abfd, 0x1);/* Absolute */
3093 ieee_write_byte (abfd, 0x2);/* Relocateable */
3095 ieee->w.r.environmental_record = bfd_tell (abfd);
3096 if (bfd_write ((char *) envi, 1, sizeof (envi), abfd) != sizeof (envi))
3101 ieee_write_section_part (abfd);
3103 First write the symbols, this changes their values into table
3104 indeces so we cant use it after this point
3106 ieee_write_external_part (abfd);
3107 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3110 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3114 Write any debugs we have been told about
3116 ieee_write_debug_part (abfd);
3119 Can only write the data once the symbols have been written since
3120 the data contains relocation information which points to the
3123 ieee_write_data_part (abfd);
3127 At the end we put the end !
3129 ieee_write_me_part (abfd);
3132 /* Generate the header */
3133 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3136 for (i = 0; i < N_W_VARIABLES; i++)
3138 ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum);
3139 ieee_write_byte (abfd, (bfd_byte) i);
3140 ieee_write_int5_out (abfd, ieee->w.offset[i]);
3147 /* Native-level interface to symbols. */
3149 /* We read the symbols into a buffer, which is discarded when this
3150 function exits. We read the strings into a buffer large enough to
3151 hold them all plus all the cached symbol entries. */
3154 ieee_make_empty_symbol (abfd)
3158 ieee_symbol_type *new =
3159 (ieee_symbol_type *) bfd_zmalloc (sizeof (ieee_symbol_type));
3162 bfd_set_error (bfd_error_no_error);
3165 new->symbol.the_bfd = abfd;
3166 return &new->symbol;
3170 ieee_openr_next_archived_file (arch, prev)
3174 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3175 /* take the next one from the arch state, or reset */
3176 if (prev == (bfd *) NULL)
3178 /* Reset the index - the first two entries are bogus*/
3179 ar->element_index = 2;
3183 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3184 ar->element_index++;
3185 if (ar->element_index <= ar->element_count)
3187 if (p->file_offset != (file_ptr) 0)
3189 if (p->abfd == (bfd *) NULL)
3191 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3192 p->abfd->origin = p->file_offset;
3199 bfd_set_error (bfd_error_no_more_archived_files);
3200 return (bfd *) NULL;
3207 ieee_find_nearest_line (abfd,
3218 char **filename_ptr;
3219 char **functionname_ptr;
3226 ieee_generic_stat_arch_elt (abfd, buf)
3230 ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
3231 if (ar == (ieee_ar_data_type *) NULL)
3233 bfd_set_error (bfd_error_invalid_operation);
3239 buf->st_mode = 0666;
3240 return !ieee_object_p (abfd);
3245 ieee_sizeof_headers (abfd, x)
3253 /* The debug info routines are never used. */
3257 ieee_bfd_debug_info_start (abfd)
3264 ieee_bfd_debug_info_end (abfd)
3271 /* Add this section to the list of sections we have debug info for, to
3272 be ready to output it at close time
3275 ieee_bfd_debug_info_accumulate (abfd, section)
3279 ieee_data_type *ieee = IEEE_DATA (section->owner);
3280 ieee_data_type *output_ieee = IEEE_DATA (abfd);
3281 /* can only accumulate data from other ieee bfds */
3282 if (section->owner->xvec != abfd->xvec)
3284 /* Only bother once per bfd */
3285 if (ieee->done_debug == true)
3287 ieee->done_debug = true;
3289 /* Don't bother if there is no debug info */
3290 if (ieee->w.r.debug_information_part == 0)
3296 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc (abfd, sizeof (bfd_chain_type));
3298 abort (); /* FIXME */
3299 n->this = section->owner;
3300 n->next = (bfd_chain_type *) NULL;
3302 if (output_ieee->chain_head)
3304 output_ieee->chain_head->next = n;
3308 output_ieee->chain_root = n;
3311 output_ieee->chain_head = n;
3317 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3318 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3320 #define ieee_slurp_armap bfd_true
3321 #define ieee_slurp_extended_name_table bfd_true
3322 #define ieee_construct_extended_name_table \
3323 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
3325 #define ieee_truncate_arname bfd_dont_truncate_arname
3326 #define ieee_write_armap \
3328 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3330 #define ieee_read_ar_hdr bfd_nullvoidptr
3331 #define ieee_update_armap_timestamp bfd_true
3333 #define ieee_bfd_is_local_label bfd_generic_is_local_label
3334 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3335 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3336 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3337 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3339 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3341 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3343 #define ieee_get_section_contents_in_window \
3344 _bfd_generic_get_section_contents_in_window
3345 #define ieee_bfd_get_relocated_section_contents \
3346 bfd_generic_get_relocated_section_contents
3347 #define ieee_bfd_relax_section bfd_generic_relax_section
3348 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3349 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3350 #define ieee_bfd_final_link _bfd_generic_final_link
3351 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3354 const bfd_target ieee_vec =
3357 bfd_target_ieee_flavour,
3358 true, /* target byte order */
3359 true, /* target headers byte order */
3360 (HAS_RELOC | EXEC_P | /* object flags */
3361 HAS_LINENO | HAS_DEBUG |
3362 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3363 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3364 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3365 0, /* leading underscore */
3366 ' ', /* ar_pad_char */
3367 16, /* ar_max_namelen */
3368 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3369 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3370 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3371 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3372 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3373 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3376 ieee_object_p, /* bfd_check_format */
3383 _bfd_generic_mkarchive,
3388 ieee_write_object_contents,
3389 _bfd_write_archive_contents,
3393 BFD_JUMP_TABLE_GENERIC (ieee),
3394 BFD_JUMP_TABLE_COPY (_bfd_generic),
3395 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3396 BFD_JUMP_TABLE_ARCHIVE (ieee),
3397 BFD_JUMP_TABLE_SYMBOLS (ieee),
3398 BFD_JUMP_TABLE_RELOCS (ieee),
3399 BFD_JUMP_TABLE_WRITE (ieee),
3400 BFD_JUMP_TABLE_LINK (ieee),
3401 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),