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 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_set_error (bfd_error_no_memory);
208 bfd_get_string (ieee, string, length);
214 ieee_write_expression (abfd, value, symbol, pcrel, index)
221 unsigned int term_count = 0;
225 ieee_write_int (abfd, value);
229 if (bfd_is_com_section (symbol->section)
230 || symbol->section == &bfd_und_section)
232 /* Def of a common symbol */
233 ieee_write_byte (abfd, ieee_variable_X_enum);
234 ieee_write_int (abfd, symbol->value);
237 else if (symbol->section != &bfd_abs_section)
239 /* Ref to defined symbol - */
241 ieee_write_byte (abfd, ieee_variable_R_enum);
242 ieee_write_byte (abfd,
243 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
245 if (symbol->flags & BSF_GLOBAL)
247 ieee_write_byte (abfd, ieee_variable_I_enum);
248 ieee_write_int (abfd, symbol->value);
251 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
253 /* This is a reference to a defined local symbol,
254 We can easily do a local as a section+offset */
255 ieee_write_byte (abfd, ieee_variable_R_enum); /* or L */
256 ieee_write_byte (abfd,
257 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
258 ieee_write_int (abfd, symbol->value);
269 /* subtract the pc from here by asking for PC of this section*/
270 ieee_write_byte (abfd, ieee_variable_P_enum);
271 ieee_write_byte (abfd, (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE));
272 ieee_write_byte (abfd, ieee_function_minus_enum);
277 ieee_write_byte (abfd, 0);
281 while (term_count > 1)
283 ieee_write_byte (abfd, ieee_function_plus_enum);
290 /*****************************************************************************/
293 writes any integer into the buffer supplied and always takes 5 bytes
296 ieee_write_int5 (buffer, value)
300 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
301 buffer[1] = (value >> 24) & 0xff;
302 buffer[2] = (value >> 16) & 0xff;
303 buffer[3] = (value >> 8) & 0xff;
304 buffer[4] = (value >> 0) & 0xff;
308 ieee_write_int5_out (abfd, value)
313 ieee_write_int5 (b, value);
314 if (bfd_write ((PTR) b, 1, 5, abfd) != 5)
319 parse_int (ieee, value_ptr)
320 common_header_type *ieee;
323 int value = this_byte (ieee);
325 if (value >= 0 && value <= 127)
331 else if (value >= 0x80 && value <= 0x88)
333 unsigned int count = value & 0xf;
338 result = (result << 8) | this_byte_and_next (ieee);
349 common_header_type *ieee;
353 *ok = parse_int (ieee, &x);
358 must_parse_int (ieee)
359 common_header_type *ieee;
362 BFD_ASSERT (parse_int (ieee, &result) == true);
370 ieee_symbol_index_type symbol;
375 reloc_howto_type abs32_howto
376 = HOWTO (1, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false);
378 reloc_howto_type abs16_howto
379 = HOWTO (1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false);
382 reloc_howto_type abs8_howto
383 = HOWTO (1, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false);
386 reloc_howto_type rel32_howto
387 = HOWTO (1, 0, 2, 32, true, 0, complain_overflow_signed, 0, "rel32", true, 0xffffffff,
391 reloc_howto_type rel16_howto
392 = HOWTO (1, 0, 1, 16, true, 0, complain_overflow_signed, 0, "rel16", true, 0x0000ffff, 0x0000ffff, false);
395 reloc_howto_type rel8_howto
396 = HOWTO (1, 0, 0, 8, true, 0, complain_overflow_signed, 0, "rel8", true, 0x000000ff, 0x000000ff, false);
399 static ieee_symbol_index_type NOSYMBOL =
404 parse_expression (ieee, value, symbol, pcrel, extra, section)
405 ieee_data_type *ieee;
407 ieee_symbol_index_type *symbol;
420 ieee_value_type stack[10];
422 /* The stack pointer always points to the next unused location */
423 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
424 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
425 ieee_value_type *sp = stack;
429 switch (this_byte (&(ieee->h)))
431 case ieee_variable_P_enum:
432 /* P variable, current program counter for section n */
435 next_byte (&(ieee->h));
437 section_n = must_parse_int (&(ieee->h));
438 PUSH (NOSYMBOL, &bfd_abs_section,
439 TOS.value = ieee->section_table[section_n]->vma +
440 ieee_per_section (ieee->section_table[section_n])->pc);
443 case ieee_variable_L_enum:
444 /* L variable address of section N */
445 next_byte (&(ieee->h));
446 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
448 case ieee_variable_R_enum:
449 /* R variable, logical address of section module */
450 /* FIXME, this should be different to L */
451 next_byte (&(ieee->h));
452 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
454 case ieee_variable_S_enum:
455 /* S variable, size in MAUS of section module */
456 next_byte (&(ieee->h));
459 ieee->section_table[must_parse_int (&(ieee->h))]->_raw_size);
461 case ieee_variable_I_enum:
462 case ieee_variable_X_enum:
463 /* Push the address of external variable n */
465 ieee_symbol_index_type sy;
466 next_byte (&(ieee->h));
467 sy.index = (int) (must_parse_int (&(ieee->h)));
470 PUSH (sy, &bfd_und_section, 0);
473 case ieee_function_minus_enum:
475 bfd_vma value1, value2;
476 asection *section1, *section_dummy;
477 ieee_symbol_index_type sy;
478 next_byte (&(ieee->h));
480 POP (sy, section1, value1);
481 POP (sy, section_dummy, value2);
482 PUSH (sy, section1 ? section1 : section_dummy, value1 - value2);
485 case ieee_function_plus_enum:
487 bfd_vma value1, value2;
490 ieee_symbol_index_type sy1;
491 ieee_symbol_index_type sy2;
492 next_byte (&(ieee->h));
494 POP (sy1, section1, value1);
495 POP (sy2, section2, value2);
496 PUSH (sy1.letter ? sy1 : sy2, section1 != &bfd_abs_section ? section1 : section2, value1 + value2);
502 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
503 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
504 if (parse_int (&(ieee->h), &va))
506 PUSH (NOSYMBOL, &bfd_abs_section, va);
511 Thats all that we can understand. As far as I can see
512 there is a bug in the Microtec IEEE output which I'm
513 using to scan, whereby the comma operator is omitted
514 sometimes in an expression, giving expressions with too
515 many terms. We can tell if that's the case by ensuring
516 that sp == stack here. If not, then we've pushed
517 something too far, so we keep adding. */
519 while (sp != stack + 1)
522 ieee_symbol_index_type sy1;
523 POP (sy1, section1, *extra);
528 POP (*symbol, dummy, *value);
541 #define ieee_seek(abfd, offset) \
542 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
544 #define ieee_pos(abfd) 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));
575 bfd_set_error (bfd_error_no_memory);
579 new_symbol->index = new_index;
580 last_index = new_index;
583 *pptr = &new_symbol->next;
584 if (new_index > *max_index)
586 *max_index = new_index;
588 last_type = this_type;
595 ieee_slurp_external_symbols (abfd)
598 ieee_data_type *ieee = IEEE_DATA (abfd);
599 file_ptr offset = ieee->w.r.external_part;
601 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
602 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
603 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
604 unsigned int symbol_count = 0;
606 last_index = 0xffffff;
607 ieee->symbol_table_full = true;
609 ieee_seek (abfd, offset);
613 switch (this_byte (&(ieee->h)))
616 next_byte (&(ieee->h));
618 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
620 &ieee->external_symbol_max_index, 'D');
624 symbol->symbol.the_bfd = abfd;
625 symbol->symbol.name = read_id (&(ieee->h));
626 symbol->symbol.udata = (PTR) NULL;
627 symbol->symbol.flags = BSF_NO_FLAGS;
629 case ieee_external_symbol_enum:
630 next_byte (&(ieee->h));
632 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
634 &ieee->external_symbol_max_index, 'D');
638 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
640 symbol->symbol.the_bfd = abfd;
641 symbol->symbol.name = read_id (&(ieee->h));
642 symbol->symbol.udata = (PTR) NULL;
643 symbol->symbol.flags = BSF_NO_FLAGS;
645 case ieee_attribute_record_enum >> 8:
647 unsigned int symbol_name_index;
648 unsigned int symbol_type_index;
649 unsigned int symbol_attribute_def;
651 next_byte (&(ieee->h)); /* Skip prefix */
652 next_byte (&(ieee->h));
653 symbol_name_index = must_parse_int (&(ieee->h));
654 symbol_type_index = must_parse_int (&(ieee->h));
655 symbol_attribute_def = must_parse_int (&(ieee->h));
656 switch (symbol_attribute_def)
659 /* Module misc; followed by two fields which describe the
660 current module block. The first fired is the type id
661 number, the second is the number of asn records
662 associated with the directive */
663 parse_int (&(ieee->h), &value);
664 parse_int (&(ieee->h), &value);
668 parse_int (&(ieee->h), &value);
673 case ieee_value_record_enum >> 8:
675 unsigned int symbol_name_index;
676 ieee_symbol_index_type symbol_ignore;
677 boolean pcrel_ignore;
679 next_byte (&(ieee->h));
680 next_byte (&(ieee->h));
682 symbol_name_index = must_parse_int (&(ieee->h));
683 parse_expression (ieee,
684 &symbol->symbol.value,
688 &symbol->symbol.section);
690 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
694 case ieee_weak_external_reference_enum:
698 next_byte (&(ieee->h));
699 /* Throw away the external reference index */
700 (void) must_parse_int (&(ieee->h));
701 /* Fetch the default size if not resolved */
702 size = must_parse_int (&(ieee->h));
703 /* Fetch the defautlt value if available */
704 if (parse_int (&(ieee->h), &value) == false)
708 /* This turns into a common */
709 symbol->symbol.section = &bfd_com_section;
710 symbol->symbol.value = size;
714 case ieee_external_reference_enum:
715 next_byte (&(ieee->h));
717 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
719 &ieee->external_reference_max_index, 'X');
723 symbol->symbol.the_bfd = abfd;
724 symbol->symbol.name = read_id (&(ieee->h));
725 symbol->symbol.udata = (PTR) NULL;
726 symbol->symbol.section = &bfd_und_section;
727 symbol->symbol.value = (bfd_vma) 0;
728 symbol->symbol.flags = 0;
730 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
738 if (ieee->external_symbol_max_index != 0)
740 ieee->external_symbol_count =
741 ieee->external_symbol_max_index -
742 ieee->external_symbol_min_index + 1;
746 ieee->external_symbol_count = 0;
749 if (ieee->external_reference_max_index != 0)
751 ieee->external_reference_count =
752 ieee->external_reference_max_index -
753 ieee->external_reference_min_index + 1;
757 ieee->external_reference_count = 0;
761 ieee->external_reference_count + ieee->external_symbol_count;
763 if (symbol_count != abfd->symcount)
765 /* There are gaps in the table -- */
766 ieee->symbol_table_full = false;
769 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
770 *prev_reference_ptr = (ieee_symbol_type *) NULL;
776 ieee_slurp_symbol_table (abfd)
779 if (IEEE_DATA (abfd)->read_symbols == false)
781 if (! ieee_slurp_external_symbols (abfd))
783 IEEE_DATA (abfd)->read_symbols = true;
789 ieee_get_symtab_upper_bound (abfd)
792 if (! ieee_slurp_symbol_table (abfd))
795 return (abfd->symcount != 0) ?
796 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
800 Move from our internal lists to the canon table, and insert in
804 extern const bfd_target ieee_vec;
807 ieee_get_symtab (abfd, location)
811 ieee_symbol_type *symp;
812 static bfd dummy_bfd;
813 static asymbol empty_symbol =
814 /* the_bfd, name, value, attr, section */
815 {&dummy_bfd, " ieee empty", (symvalue) 0, BSF_DEBUGGING, &bfd_abs_section};
819 ieee_data_type *ieee = IEEE_DATA (abfd);
820 dummy_bfd.xvec = &ieee_vec;
821 if (! ieee_slurp_symbol_table (abfd))
824 if (ieee->symbol_table_full == false)
826 /* Arrgh - there are gaps in the table, run through and fill them */
827 /* up with pointers to a null place */
829 for (i = 0; i < abfd->symcount; i++)
831 location[i] = &empty_symbol;
835 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
836 for (symp = IEEE_DATA (abfd)->external_symbols;
837 symp != (ieee_symbol_type *) NULL;
840 /* Place into table at correct index locations */
841 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
844 /* The external refs are indexed in a bit */
845 ieee->external_reference_base_offset =
846 -ieee->external_reference_min_index + ieee->external_symbol_count;
848 for (symp = IEEE_DATA (abfd)->external_reference;
849 symp != (ieee_symbol_type *) NULL;
852 location[symp->index + ieee->external_reference_base_offset] =
859 location[abfd->symcount] = (asymbol *) NULL;
861 return abfd->symcount;
865 get_section_entry (abfd, ieee, index)
867 ieee_data_type *ieee;
870 if (ieee->section_table[index] == (asection *) NULL)
872 char *tmp = bfd_alloc (abfd, 11);
877 bfd_set_error (bfd_error_no_memory);
880 sprintf (tmp, " fsec%4d", index);
881 section = bfd_make_section (abfd, tmp);
882 ieee->section_table[index] = section;
883 section->flags = SEC_NO_FLAGS;
884 section->target_index = index;
885 ieee->section_table[index] = section;
887 return ieee->section_table[index];
891 ieee_slurp_sections (abfd)
894 ieee_data_type *ieee = IEEE_DATA (abfd);
895 file_ptr offset = ieee->w.r.section_part;
896 asection *section = (asection *) NULL;
901 bfd_byte section_type[3];
902 ieee_seek (abfd, offset);
905 switch (this_byte (&(ieee->h)))
907 case ieee_section_type_enum:
909 unsigned int section_index;
910 next_byte (&(ieee->h));
911 section_index = must_parse_int (&(ieee->h));
912 /* Fixme to be nice about a silly number of sections */
913 BFD_ASSERT (section_index < NSECTIONS);
915 section = get_section_entry (abfd, ieee, section_index);
917 section_type[0] = this_byte_and_next (&(ieee->h));
918 switch (section_type[0])
921 /* Normal attributes for absolute sections */
922 section_type[1] = this_byte (&(ieee->h));
923 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
924 switch (section_type[1])
926 case 0xD3: /* AS Absolute section attributes */
927 next_byte (&(ieee->h));
928 section_type[2] = this_byte (&(ieee->h));
929 switch (section_type[2])
933 next_byte (&(ieee->h));
934 section->flags |= SEC_LOAD | SEC_CODE;
937 next_byte (&(ieee->h));
938 section->flags |= SEC_LOAD | SEC_DATA;
942 next_byte (&(ieee->h));
943 /* Normal rom data */
944 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
951 case 0xC3: /* Named relocatable sections (type C) */
952 section_type[1] = this_byte (&(ieee->h));
953 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
954 switch (section_type[1])
956 case 0xD0: /* Normal code (CP) */
957 next_byte (&(ieee->h));
958 section->flags |= SEC_LOAD | SEC_CODE;
960 case 0xC4: /* Normal data (CD) */
961 next_byte (&(ieee->h));
962 section->flags |= SEC_LOAD | SEC_DATA;
964 case 0xD2: /* Normal rom data (CR) */
965 next_byte (&(ieee->h));
966 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
973 /* Read section name, use it if non empty. */
974 name = read_id (&ieee->h);
976 section->name = name;
978 /* Skip these fields, which we don't care about */
980 bfd_vma parent, brother, context;
981 parse_int (&(ieee->h), &parent);
982 parse_int (&(ieee->h), &brother);
983 parse_int (&(ieee->h), &context);
987 case ieee_section_alignment_enum:
989 unsigned int section_index;
992 next_byte (&(ieee->h));
993 section_index = must_parse_int (&ieee->h);
994 section = get_section_entry (abfd, ieee, section_index);
995 if (section_index > ieee->section_count)
997 ieee->section_count = section_index;
999 section->alignment_power =
1000 bfd_log2 (must_parse_int (&ieee->h));
1001 (void) parse_int (&(ieee->h), &value);
1004 case ieee_e2_first_byte_enum:
1006 ieee_record_enum_type t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1010 case ieee_section_size_enum:
1011 section = ieee->section_table[must_parse_int (&(ieee->h))];
1012 section->_raw_size = must_parse_int (&(ieee->h));
1014 case ieee_physical_region_size_enum:
1015 section = ieee->section_table[must_parse_int (&(ieee->h))];
1016 section->_raw_size = must_parse_int (&(ieee->h));
1018 case ieee_region_base_address_enum:
1019 section = ieee->section_table[must_parse_int (&(ieee->h))];
1020 section->vma = must_parse_int (&(ieee->h));
1022 case ieee_mau_size_enum:
1023 must_parse_int (&(ieee->h));
1024 must_parse_int (&(ieee->h));
1026 case ieee_m_value_enum:
1027 must_parse_int (&(ieee->h));
1028 must_parse_int (&(ieee->h));
1030 case ieee_section_base_address_enum:
1031 section = ieee->section_table[must_parse_int (&(ieee->h))];
1032 section->vma = must_parse_int (&(ieee->h));
1034 case ieee_section_offset_enum:
1035 (void) must_parse_int (&(ieee->h));
1036 (void) must_parse_int (&(ieee->h));
1051 /***********************************************************************
1056 ieee_archive_p (abfd)
1063 unsigned char buffer[512];
1065 file_ptr buffer_offset = 0;
1066 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1067 ieee_ar_data_type *ieee;
1068 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, sizeof (ieee_ar_data_type));
1069 if (!abfd->tdata.ieee_ar_data)
1071 bfd_set_error (bfd_error_no_memory);
1074 ieee = IEEE_AR_DATA (abfd);
1076 /* FIXME: Check return value. I'm not sure whether it needs to read
1077 the entire buffer or not. */
1078 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1080 ieee->h.first_byte = buffer;
1081 ieee->h.input_p = buffer;
1083 ieee->h.abfd = abfd;
1085 if (this_byte (&(ieee->h)) != Module_Beginning)
1087 abfd->tdata.ieee_ar_data = save;
1088 return (const bfd_target *) NULL;
1091 next_byte (&(ieee->h));
1092 library = read_id (&(ieee->h));
1093 if (strcmp (library, "LIBRARY") != 0)
1095 bfd_release (abfd, ieee);
1096 abfd->tdata.ieee_ar_data = save;
1097 return (const bfd_target *) NULL;
1099 /* Throw away the filename */
1100 read_id (&(ieee->h));
1101 /* This must be an IEEE archive, so we'll buy some space to do
1104 if (!obstack_begin (&ob, 128))
1106 bfd_set_error (bfd_error_no_memory);
1107 return (const bfd_target *) NULL;
1110 ieee->element_count = 0;
1111 ieee->element_index = 0;
1113 next_byte (&(ieee->h)); /* Drop the ad part */
1114 must_parse_int (&(ieee->h)); /* And the two dummy numbers */
1115 must_parse_int (&(ieee->h));
1118 /* Read the index of the BB table */
1121 ieee_ar_obstack_type t;
1122 int rec = read_2bytes (&(ieee->h));
1123 if (rec == (int) ieee_assign_value_to_variable_enum)
1125 must_parse_int (&(ieee->h));
1126 t.file_offset = must_parse_int (&(ieee->h));
1127 t.abfd = (bfd *) NULL;
1128 ieee->element_count++;
1130 obstack_grow (&ob, (PTR) & t, sizeof (t));
1132 /* Make sure that we don't go over the end of the buffer */
1134 if (ieee_pos (abfd) > sizeof (buffer) / 2)
1136 /* Past half way, reseek and reprime */
1137 buffer_offset += ieee_pos (abfd);
1138 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1140 /* FIXME: Check return value. I'm not sure whether it
1141 needs to read the entire buffer or not. */
1142 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1143 ieee->h.first_byte = buffer;
1144 ieee->h.input_p = buffer;
1151 ieee->elements = (ieee_ar_obstack_type *) obstack_finish (&ob);
1152 if (!ieee->elements)
1154 bfd_set_error (bfd_error_no_memory);
1155 return (const bfd_target *) NULL;
1158 /* Now scan the area again, and replace BB offsets with file */
1161 for (i = 2; i < ieee->element_count; i++)
1163 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1165 /* FIXME: Check return value. I'm not sure whether it needs to
1166 read the entire buffer or not. */
1167 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1168 ieee->h.first_byte = buffer;
1169 ieee->h.input_p = buffer;
1171 next_byte (&(ieee->h)); /* Drop F8 */
1172 next_byte (&(ieee->h)); /* Drop 14 */
1173 must_parse_int (&(ieee->h)); /* Drop size of block */
1174 if (must_parse_int (&(ieee->h)) != 0)
1176 /* This object has been deleted */
1177 ieee->elements[i].file_offset = 0;
1181 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1185 /* abfd->has_armap = ;*/
1190 ieee_mkobject (abfd)
1193 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, sizeof (ieee_data_type));
1194 return abfd->tdata.ieee_data ? true : false;
1198 ieee_object_p (abfd)
1203 ieee_data_type *ieee;
1204 unsigned char buffer[300];
1205 ieee_data_type *save = IEEE_DATA (abfd);
1207 abfd->tdata.ieee_data = 0;
1208 ieee_mkobject (abfd);
1210 ieee = IEEE_DATA (abfd);
1211 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1213 /* Read the first few bytes in to see if it makes sense */
1214 /* FIXME: Check return value. I'm not sure whether it needs to read
1215 the entire buffer or not. */
1216 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1218 ieee->h.input_p = buffer;
1219 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1220 goto got_wrong_format;
1222 ieee->read_symbols = false;
1223 ieee->read_data = false;
1224 ieee->section_count = 0;
1225 ieee->external_symbol_max_index = 0;
1226 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1227 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1228 ieee->external_reference_max_index = 0;
1229 ieee->h.abfd = abfd;
1230 memset ((PTR) ieee->section_table, 0, sizeof (ieee->section_table));
1232 processor = ieee->mb.processor = read_id (&(ieee->h));
1233 if (strcmp (processor, "LIBRARY") == 0)
1234 goto got_wrong_format;
1235 ieee->mb.module_name = read_id (&(ieee->h));
1236 if (abfd->filename == (CONST char *) NULL)
1238 abfd->filename = ieee->mb.module_name;
1240 /* Determine the architecture and machine type of the object file.
1243 bfd_arch_info_type *arch = bfd_scan_arch (processor);
1245 goto got_wrong_format;
1246 abfd->arch_info = arch;
1249 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1253 next_byte (&(ieee->h));
1255 if (parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau) == false)
1259 if (parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address) == false)
1264 /* If there is a byte order info, take it */
1265 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum ||
1266 this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
1267 next_byte (&(ieee->h));
1269 for (part = 0; part < N_W_VARIABLES; part++)
1272 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
1276 if (this_byte_and_next (&(ieee->h)) != part)
1281 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
1288 abfd->flags = HAS_SYMS;
1289 /* By now we know that this is a real IEEE file, we're going to read
1290 the whole thing into memory so that we can run up and down it
1291 quickly. We can work out how big the file is from the trailer
1294 IEEE_DATA (abfd)->h.first_byte = (unsigned char *) bfd_alloc (ieee->h.abfd, ieee->w.r.me_record
1296 if (!IEEE_DATA (abfd)->h.first_byte)
1298 bfd_set_error (bfd_error_no_memory);
1301 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1303 /* FIXME: Check return value. I'm not sure whether it needs to read
1304 the entire buffer or not. */
1305 bfd_read ((PTR) (IEEE_DATA (abfd)->h.first_byte), 1, ieee->w.r.me_record + 50, abfd);
1307 ieee_slurp_sections (abfd);
1310 bfd_set_error (bfd_error_wrong_format);
1312 (void) bfd_release (abfd, ieee);
1313 abfd->tdata.ieee_data = save;
1314 return (const bfd_target *) NULL;
1318 ieee_get_symbol_info (ignore_abfd, symbol, ret)
1323 bfd_symbol_info (symbol, ret);
1324 if (symbol->name[0] == ' ')
1325 ret->name = "* empty table entry ";
1326 if (!symbol->section)
1327 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
1331 ieee_print_symbol (ignore_abfd, afile, symbol, how)
1335 bfd_print_symbol_type how;
1337 FILE *file = (FILE *) afile;
1341 case bfd_print_symbol_name:
1342 fprintf (file, "%s", symbol->name);
1344 case bfd_print_symbol_more:
1346 fprintf (file, "%4x %2x", aout_symbol (symbol)->desc & 0xffff,
1347 aout_symbol (symbol)->other & 0xff);
1351 case bfd_print_symbol_all:
1353 CONST char *section_name = symbol->section == (asection *) NULL ?
1354 (CONST char *) "*abs" : symbol->section->name;
1355 if (symbol->name[0] == ' ')
1357 fprintf (file, "* empty table entry ");
1361 bfd_print_symbol_vandf ((PTR) file, symbol);
1363 fprintf (file, " %-5s %04x %02x %s",
1365 (unsigned) ieee_symbol (symbol)->index,
1367 aout_symbol(symbol)->desc & 0xffff,
1368 aout_symbol(symbol)->other & 0xff,*/
1377 do_one (ieee, current_map, location_ptr, s)
1378 ieee_data_type *ieee;
1379 ieee_per_section_type *current_map;
1380 unsigned char *location_ptr;
1383 switch (this_byte (&(ieee->h)))
1385 case ieee_load_constant_bytes_enum:
1387 unsigned int number_of_maus;
1389 next_byte (&(ieee->h));
1390 number_of_maus = must_parse_int (&(ieee->h));
1392 for (i = 0; i < number_of_maus; i++)
1394 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1395 next_byte (&(ieee->h));
1400 case ieee_load_with_relocation_enum:
1402 boolean loop = true;
1403 next_byte (&(ieee->h));
1406 switch (this_byte (&(ieee->h)))
1408 case ieee_variable_R_enum:
1410 case ieee_function_signed_open_b_enum:
1411 case ieee_function_unsigned_open_b_enum:
1412 case ieee_function_either_open_b_enum:
1414 unsigned int extra = 4;
1415 boolean pcrel = false;
1417 ieee_reloc_type *r =
1418 (ieee_reloc_type *) bfd_alloc (ieee->h.abfd,
1419 sizeof (ieee_reloc_type));
1422 bfd_set_error (bfd_error_no_memory);
1426 *(current_map->reloc_tail_ptr) = r;
1427 current_map->reloc_tail_ptr = &r->next;
1428 r->next = (ieee_reloc_type *) NULL;
1429 next_byte (&(ieee->h));
1431 r->relent.sym_ptr_ptr = 0;
1432 parse_expression (ieee,
1435 &pcrel, &extra, §ion);
1436 r->relent.address = current_map->pc;
1438 if (r->relent.sym_ptr_ptr == 0)
1440 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1443 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1445 next_byte (&(ieee->h));
1446 /* Fetch number of bytes to pad */
1447 extra = must_parse_int (&(ieee->h));
1450 switch (this_byte (&(ieee->h)))
1452 case ieee_function_signed_close_b_enum:
1453 next_byte (&(ieee->h));
1455 case ieee_function_unsigned_close_b_enum:
1456 next_byte (&(ieee->h));
1458 case ieee_function_either_close_b_enum:
1459 next_byte (&(ieee->h));
1464 /* Build a relocation entry for this type */
1465 /* If pc rel then stick -ve pc into instruction
1466 and take out of reloc ..
1468 I've changed this. It's all too
1469 complicated. I keep 0 in the
1480 #if KEEPMINUSPCININST
1481 bfd_put_32 (ieee->h.abfd, -current_map->pc, location_ptr +
1483 r->relent.howto = &rel32_howto;
1487 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1489 r->relent.howto = &rel32_howto;
1494 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1496 r->relent.howto = &abs32_howto;
1498 current_map->pc += 4;
1503 #if KEEPMINUSPCININST
1504 bfd_put_16 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1505 r->relent.addend -= current_map->pc;
1506 r->relent.howto = &rel16_howto;
1509 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1510 r->relent.howto = &rel16_howto;
1516 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1517 r->relent.howto = &abs16_howto;
1519 current_map->pc += 2;
1524 #if KEEPMINUSPCININST
1525 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1526 r->relent.addend -= current_map->pc;
1527 r->relent.howto = &rel8_howto;
1529 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1530 r->relent.howto = &rel8_howto;
1535 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1536 r->relent.howto = &abs8_howto;
1538 current_map->pc += 1;
1550 if (parse_int (&(ieee->h), &this_size) == true)
1553 for (i = 0; i < this_size; i++)
1555 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1556 next_byte (&(ieee->h));
1571 /* Read in all the section data and relocation stuff too */
1573 ieee_slurp_section_data (abfd)
1576 bfd_byte *location_ptr = (bfd_byte *) NULL;
1577 ieee_data_type *ieee = IEEE_DATA (abfd);
1578 unsigned int section_number;
1580 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
1582 /* Seek to the start of the data area */
1583 if (ieee->read_data == true)
1585 ieee->read_data = true;
1586 ieee_seek (abfd, ieee->w.r.data_part);
1588 /* Allocate enough space for all the section contents */
1590 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1592 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1593 per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->_raw_size);
1596 bfd_set_error (bfd_error_no_memory);
1600 per->reloc_tail_ptr =
1601 (ieee_reloc_type **) & (s->relocation);
1606 switch (this_byte (&(ieee->h)))
1608 /* IF we see anything strange then quit */
1612 case ieee_set_current_section_enum:
1613 next_byte (&(ieee->h));
1614 section_number = must_parse_int (&(ieee->h));
1615 s = ieee->section_table[section_number];
1616 current_map = (ieee_per_section_type *) s->used_by_bfd;
1617 location_ptr = current_map->data - s->vma;
1618 /* The document I have says that Microtec's compilers reset */
1619 /* this after a sec section, even though the standard says not */
1621 current_map->pc = s->vma;
1624 case ieee_e2_first_byte_enum:
1625 next_byte (&(ieee->h));
1626 switch (this_byte (&(ieee->h)))
1628 case ieee_set_current_pc_enum & 0xff:
1631 ieee_symbol_index_type symbol;
1634 next_byte (&(ieee->h));
1635 must_parse_int (&(ieee->h)); /* Thow away section #*/
1636 parse_expression (ieee, &value,
1640 current_map->pc = value;
1641 BFD_ASSERT ((unsigned) (value - s->vma) <= s->_raw_size);
1645 case ieee_value_starting_address_enum & 0xff:
1646 /* We've got to the end of the data now - */
1653 case ieee_repeat_data_enum:
1655 /* Repeat the following LD or LR n times - we do this by
1656 remembering the stream pointer before running it and
1657 resetting it and running it n times. We special case
1658 the repetition of a repeat_data/load_constant
1661 unsigned int iterations;
1662 unsigned char *start;
1663 next_byte (&(ieee->h));
1664 iterations = must_parse_int (&(ieee->h));
1665 start = ieee->h.input_p;
1666 if (start[0] == (int) ieee_load_constant_bytes_enum &&
1669 while (iterations != 0)
1671 location_ptr[current_map->pc++] = start[2];
1674 next_byte (&(ieee->h));
1675 next_byte (&(ieee->h));
1676 next_byte (&(ieee->h));
1680 while (iterations != 0)
1682 ieee->h.input_p = start;
1683 if (!do_one (ieee, current_map, location_ptr, s))
1690 case ieee_load_constant_bytes_enum:
1691 case ieee_load_with_relocation_enum:
1693 if (!do_one (ieee, current_map, location_ptr, s))
1701 ieee_new_section_hook (abfd, newsect)
1705 newsect->used_by_bfd = (PTR)
1706 bfd_alloc (abfd, sizeof (ieee_per_section_type));
1707 if (!newsect->used_by_bfd)
1709 bfd_set_error (bfd_error_no_memory);
1712 ieee_per_section (newsect)->data = (bfd_byte *) NULL;
1713 ieee_per_section (newsect)->section = newsect;
1718 ieee_get_reloc_upper_bound (abfd, asect)
1722 if (! ieee_slurp_section_data (abfd))
1724 return (asect->reloc_count + 1) * sizeof (arelent *);
1728 ieee_get_section_contents (abfd, section, location, offset, count)
1733 bfd_size_type count;
1735 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1736 ieee_slurp_section_data (abfd);
1737 (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
1742 ieee_canonicalize_reloc (abfd, section, relptr, symbols)
1748 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1749 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
1750 ieee_data_type *ieee = IEEE_DATA (abfd);
1752 while (src != (ieee_reloc_type *) NULL)
1754 /* Work out which symbol to attach it this reloc to */
1755 switch (src->symbol.letter)
1758 src->relent.sym_ptr_ptr =
1759 symbols + src->symbol.index + ieee->external_reference_base_offset;
1762 src->relent.sym_ptr_ptr =
1763 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
1769 *relptr++ = &src->relent;
1772 *relptr = (arelent *) NULL;
1773 return section->reloc_count;
1781 arelent *a = *((arelent **) ap);
1782 arelent *b = *((arelent **) bp);
1783 return a->address - b->address;
1787 Write the section headers
1791 ieee_write_section_part (abfd)
1794 ieee_data_type *ieee = IEEE_DATA (abfd);
1796 ieee->w.r.section_part = bfd_tell (abfd);
1797 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1799 if (s != &bfd_abs_section)
1801 ieee_write_byte (abfd, ieee_section_type_enum);
1802 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1804 if (abfd->flags & EXEC_P)
1806 /* This image is executable, so output absolute sections */
1807 ieee_write_byte (abfd, ieee_variable_A_enum);
1808 ieee_write_byte (abfd, ieee_variable_S_enum);
1812 ieee_write_byte (abfd, ieee_variable_C_enum);
1815 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
1817 case SEC_CODE | SEC_LOAD:
1819 ieee_write_byte (abfd, ieee_variable_P_enum);
1823 ieee_write_byte (abfd, ieee_variable_D_enum);
1826 case SEC_ROM | SEC_DATA:
1827 case SEC_ROM | SEC_LOAD:
1828 case SEC_ROM | SEC_DATA | SEC_LOAD:
1830 ieee_write_byte (abfd, ieee_variable_R_enum);
1834 ieee_write_id (abfd, s->name);
1836 ieee_write_int (abfd, 0); /* Parent */
1837 ieee_write_int (abfd, 0); /* Brother */
1838 ieee_write_int (abfd, 0); /* Context */
1841 ieee_write_byte (abfd, ieee_section_alignment_enum);
1842 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1843 ieee_write_int (abfd, 1 << s->alignment_power);
1846 ieee_write_2bytes (abfd, ieee_section_size_enum);
1847 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1848 ieee_write_int (abfd, s->_raw_size);
1849 if (abfd->flags & EXEC_P)
1851 /* Relocateable sections don't have asl records */
1853 ieee_write_2bytes (abfd, ieee_section_base_address_enum);
1854 ieee_write_byte (abfd,
1855 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1856 ieee_write_int (abfd, s->vma);
1865 do_with_relocs (abfd, s)
1869 unsigned int relocs_to_go = s->reloc_count;
1871 bfd_byte *stream = ieee_per_section (s)->data;
1872 arelent **p = s->orelocation;
1874 bfd_size_type current_byte_index = 0;
1876 qsort (s->orelocation,
1878 sizeof (arelent **),
1881 /* Output the section preheader */
1882 ieee_write_byte (abfd, ieee_set_current_section_enum);
1883 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1885 ieee_write_twobyte (abfd, ieee_set_current_pc_enum);
1886 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1887 ieee_write_expression (abfd, 0, s->symbol, 0, 0);
1889 if (relocs_to_go == 0)
1891 /* If there arn't any relocations then output the load constant byte
1892 opcode rather than the load with relocation opcode */
1894 while (current_byte_index < s->_raw_size)
1897 unsigned int MAXRUN = 32;
1899 if (run > s->_raw_size - current_byte_index)
1901 run = s->_raw_size - current_byte_index;
1906 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
1907 /* Output a stream of bytes */
1908 ieee_write_int (abfd, run);
1909 if (bfd_write ((PTR) (stream + current_byte_index),
1915 current_byte_index += run;
1921 ieee_write_byte (abfd, ieee_load_with_relocation_enum);
1924 /* Output the data stream as the longest sequence of bytes
1925 possible, allowing for the a reasonable packet size and
1926 relocation stuffs */
1928 if ((PTR) stream == (PTR) NULL)
1930 /* Outputting a section without data, fill it up */
1931 stream = (unsigned char *) (bfd_alloc (abfd, s->_raw_size));
1934 bfd_set_error (bfd_error_no_memory);
1937 memset ((PTR) stream, 0, s->_raw_size);
1939 while (current_byte_index < s->_raw_size)
1942 unsigned int MAXRUN = 32;
1945 run = (*p)->address - current_byte_index;
1951 if (run > s->_raw_size - current_byte_index)
1953 run = s->_raw_size - current_byte_index;
1958 /* Output a stream of bytes */
1959 ieee_write_int (abfd, run);
1960 if (bfd_write ((PTR) (stream + current_byte_index),
1966 current_byte_index += run;
1968 /* Output any relocations here */
1969 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1971 while (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1978 if (r->howto->pc_relative)
1980 r->addend += current_byte_index;
1984 switch (r->howto->size)
1988 ov = bfd_get_32 (abfd,
1989 stream + current_byte_index);
1990 current_byte_index += 4;
1993 ov = bfd_get_16 (abfd,
1994 stream + current_byte_index);
1995 current_byte_index += 2;
1998 ov = bfd_get_8 (abfd,
1999 stream + current_byte_index);
2000 current_byte_index++;
2006 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
2009 if (r->sym_ptr_ptr != (asymbol **) NULL)
2011 ieee_write_expression (abfd, r->addend + ov,
2013 r->howto->pc_relative, s->index);
2017 ieee_write_expression (abfd, r->addend + ov,
2019 r->howto->pc_relative, s->index);
2022 if (1 || r->howto->size != 2)
2024 ieee_write_byte (abfd, ieee_comma);
2025 ieee_write_int (abfd, 1 << r->howto->size);
2027 ieee_write_byte (abfd,
2028 ieee_function_either_close_b_enum);
2040 /* If there are no relocations in the output section then we can
2041 be clever about how we write. We block items up into a max of 127
2045 do_as_repeat (abfd, s)
2051 ieee_write_byte (abfd, ieee_set_current_section_enum);
2052 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2053 ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8);
2054 ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff);
2055 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2056 ieee_write_int (abfd, s->vma);
2058 ieee_write_byte (abfd, ieee_repeat_data_enum);
2059 ieee_write_int (abfd, s->_raw_size);
2060 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
2061 ieee_write_byte (abfd, 1);
2062 ieee_write_byte (abfd, 0);
2067 do_without_relocs (abfd, s)
2071 bfd_byte *stream = ieee_per_section (s)->data;
2073 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2075 do_as_repeat (abfd, s);
2080 for (i = 0; i < s->_raw_size; i++)
2084 do_with_relocs (abfd, s);
2088 do_as_repeat (abfd, s);
2094 static unsigned char *output_ptr_start;
2095 static unsigned char *output_ptr;
2096 static unsigned char *output_ptr_end;
2097 static unsigned char *input_ptr_start;
2098 static unsigned char *input_ptr;
2099 static unsigned char *input_ptr_end;
2100 static bfd *input_bfd;
2101 static bfd *output_bfd;
2102 static int output_buffer;
2107 /* FIXME: Check return value. I'm not sure whether it needs to read
2108 the entire buffer or not. */
2109 bfd_read ((PTR) input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
2110 input_ptr = input_ptr_start;
2115 if (bfd_write ((PTR) (output_ptr_start), 1, output_ptr - output_ptr_start,
2117 != output_ptr - output_ptr_start)
2119 output_ptr = output_ptr_start;
2123 #define THIS() ( *input_ptr )
2124 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2125 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2131 if (value >= 0 && value <= 127)
2137 unsigned int length;
2138 /* How many significant bytes ? */
2139 /* FIXME FOR LONGER INTS */
2140 if (value & 0xff000000)
2144 else if (value & 0x00ff0000)
2148 else if (value & 0x0000ff00)
2155 OUT ((int) ieee_number_repeat_start_enum + length);
2174 int length = THIS ();
2186 #define VAR(x) ((x | 0x80))
2201 value = (value << 8) | THIS ();
2203 value = (value << 8) | THIS ();
2205 value = (value << 8) | THIS ();
2213 value = (value << 8) | THIS ();
2215 value = (value << 8) | THIS ();
2223 value = (value << 8) | THIS ();
2240 /* Not a number, just bug out with the answer */
2241 write_int (*(--tos));
2251 int value = *(--tos);
2260 ieee_data_type *ieee;
2263 section_number = THIS ();
2266 ieee = IEEE_DATA (input_bfd);
2267 s = ieee->section_table[section_number];
2268 if (s->output_section)
2270 value = s->output_section->vma;
2276 value += s->output_offset;
2284 write_int (*(--tos));
2294 /* Drop the int in the buffer, and copy a null into the gap, which we
2295 will overwrite later */
2297 struct output_buffer_struct
2299 unsigned char *ptrp;
2305 struct output_buffer_struct *buf;
2307 if (buf->buffer == output_buffer)
2309 /* Still a chance to output the size */
2310 int value = output_ptr - buf->ptrp + 3;
2311 buf->ptrp[0] = value >> 24;
2312 buf->ptrp[1] = value >> 16;
2313 buf->ptrp[2] = value >> 8;
2314 buf->ptrp[3] = value >> 0;
2320 struct output_buffer_struct *buf;
2346 buf->ptrp = output_ptr;
2347 buf->buffer = output_buffer;
2387 #define ID copy_id()
2388 #define INT copy_int()
2389 #define EXP copy_expression()
2390 static void copy_till_end ();
2391 #define INTn(q) copy_int()
2392 #define EXPn(q) copy_expression()
2431 EXPn (instruction address);
2465 EXPn (external function);
2475 INTn (locked register);
2498 /* Attribute record */
2556 static void block ();
2568 /* Unique typedefs for module */
2569 /* GLobal typedefs */
2570 /* High level module scope beginning */
2572 struct output_buffer_struct ob;
2587 /* Global function */
2589 struct output_buffer_struct ob;
2603 EXPn (size of block);
2609 /* File name for source line numbers */
2611 struct output_buffer_struct ob;
2631 /* Local function */
2633 struct output_buffer_struct ob;
2651 /* Assembler module scope beginning -*/
2653 struct output_buffer_struct ob;
2679 struct output_buffer_struct ob;
2686 INTn (section index);
2694 EXPn (Size in Maus);
2749 moves all the debug information from the source bfd to the output
2750 bfd, and relocates any expressions it finds
2754 relocate_debug (output, input)
2760 unsigned char input_buffer[IBS];
2762 input_ptr_start = input_ptr = input_buffer;
2763 input_ptr_end = input_buffer + IBS;
2765 /* FIXME: Check return value. I'm not sure whether it needs to read
2766 the entire buffer or not. */
2767 bfd_read ((PTR) input_ptr_start, 1, IBS, input);
2772 During linking, we we told about the bfds which made up our
2773 contents, we have a list of them. They will still be open, so go to
2774 the debug info in each, and copy it out, relocating it as we go.
2778 ieee_write_debug_part (abfd)
2781 ieee_data_type *ieee = IEEE_DATA (abfd);
2782 bfd_chain_type *chain = ieee->chain_root;
2783 unsigned char output_buffer[OBS];
2784 boolean some_debug = false;
2785 file_ptr here = bfd_tell (abfd);
2787 output_ptr_start = output_ptr = output_buffer;
2788 output_ptr_end = output_buffer + OBS;
2789 output_ptr = output_buffer;
2792 if (chain == (bfd_chain_type *) NULL)
2795 /* There is no debug info, so we'll fake some up */
2796 CONST static char fake[] =
2798 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
2799 '1', '.', '1', 0x82, 1991 >> 8, 1991 & 0xff, 9, 20, 11, 07, 50};
2800 ieee->w.r.debug_information_part = 0;
2806 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2807 /* Now write a header for each section */
2810 asection *s = abfd->sections;
2813 if (s != abfd->abs_section)
2816 ieee_write_byte (abfd, 0xf8);
2817 ieee_write_byte (abfd, 0x0b);
2818 ieee_write_byte (abfd, 0);
2819 ieee_write_byte (abfd, 0);
2820 ieee_write_byte (abfd, 1);
2821 ieee_write_byte (abfd, i + IEEE_SECTION_NUMBER_BASE);
2822 ieee_write_expression (abfd, 0, s->symbol, 0, 0, 0);
2823 ieee_write_byte (abfd, 0);
2824 ieee_write_byte (abfd, 0xf9);
2825 ieee_write_expression (abfd, s->size,
2826 bfd_abs_section.symbol, 0, 0, 0);
2833 /* Close the scope */
2834 ieee_write_byte (abfd, 0xf9);
2840 while (chain != (bfd_chain_type *) NULL)
2842 bfd *entry = chain->this;
2843 ieee_data_type *entry_ieee = IEEE_DATA (entry);
2844 if (entry_ieee->w.r.debug_information_part)
2846 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
2850 relocate_debug (abfd, entry);
2853 chain = chain->next;
2857 ieee->w.r.debug_information_part = here;
2861 ieee->w.r.debug_information_part = 0;
2868 /* write the data in an ieee way */
2870 ieee_write_data_part (abfd)
2874 ieee_data_type *ieee = IEEE_DATA (abfd);
2875 ieee->w.r.data_part = bfd_tell (abfd);
2876 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2878 /* Sort the reloc records so we can insert them in the correct
2880 if (s->reloc_count != 0)
2882 do_with_relocs (abfd, s);
2886 do_without_relocs (abfd, s);
2893 init_for_output (abfd)
2897 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2899 if (s->_raw_size != 0)
2901 ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, s->_raw_size));
2902 if (!ieee_per_section (s)->data)
2904 bfd_set_error (bfd_error_no_memory);
2912 /** exec and core file sections */
2914 /* set section contents is complicated with IEEE since the format is
2915 * not a byte image, but a record stream.
2918 ieee_set_section_contents (abfd, section, location, offset, count)
2923 bfd_size_type count;
2925 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
2927 if (!init_for_output (abfd))
2930 memcpy ((PTR) (ieee_per_section (section)->data + offset),
2932 (unsigned int) count);
2937 write the external symbols of a file, IEEE considers two sorts of
2938 external symbols, public, and referenced. It uses to internal forms
2939 to index them as well. When we write them out we turn their symbol
2940 values into indexes from the right base.
2943 ieee_write_external_part (abfd)
2947 ieee_data_type *ieee = IEEE_DATA (abfd);
2949 unsigned int reference_index = IEEE_REFERENCE_BASE;
2950 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
2951 file_ptr here = bfd_tell (abfd);
2952 boolean hadone = false;
2953 if (abfd->outsymbols != (asymbol **) NULL)
2956 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
2960 if (p->section == &bfd_und_section)
2962 /* This must be a symbol reference .. */
2963 ieee_write_byte (abfd, ieee_external_reference_enum);
2964 ieee_write_int (abfd, reference_index);
2965 ieee_write_id (abfd, p->name);
2966 p->value = reference_index;
2969 else if (bfd_is_com_section (p->section))
2971 /* This is a weak reference */
2972 ieee_write_byte (abfd, ieee_external_reference_enum);
2973 ieee_write_int (abfd, reference_index);
2974 ieee_write_id (abfd, p->name);
2975 ieee_write_byte (abfd, ieee_weak_external_reference_enum);
2976 ieee_write_int (abfd, reference_index);
2977 ieee_write_int (abfd, p->value);
2978 ieee_write_int (abfd, BFD_FORT_COMM_DEFAULT_VALUE);
2979 p->value = reference_index;
2982 else if (p->flags & BSF_GLOBAL)
2984 /* This must be a symbol definition */
2987 ieee_write_byte (abfd, ieee_external_symbol_enum);
2988 ieee_write_int (abfd, public_index);
2989 ieee_write_id (abfd, p->name);
2991 ieee_write_twobyte (abfd, ieee_attribute_record_enum);
2992 ieee_write_int (abfd, public_index);
2993 ieee_write_byte (abfd, 15); /* instruction address */
2994 ieee_write_byte (abfd, 19); /* static symbol */
2995 ieee_write_byte (abfd, 1); /* one of them */
2998 /* Write out the value */
2999 ieee_write_2bytes (abfd, ieee_value_record_enum);
3000 ieee_write_int (abfd, public_index);
3001 if (p->section != &bfd_abs_section)
3003 if (abfd->flags & EXEC_P)
3005 /* If fully linked, then output all symbols
3007 ieee_write_int (abfd,
3008 p->value + p->section->output_offset + p->section->output_section->vma);
3013 ieee_write_expression (abfd,
3014 p->value + p->section->output_offset,
3015 p->section->output_section->symbol
3021 ieee_write_expression (abfd,
3023 bfd_abs_section.symbol,
3026 p->value = public_index;
3031 /* This can happen - when there are gaps in the symbols read */
3032 /* from an input ieee file */
3037 ieee->w.r.external_part = here;
3042 static CONST unsigned char exten[] =
3045 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3046 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3047 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3050 static CONST unsigned char envi[] =
3054 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3057 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3059 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3060 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3065 ieee_write_me_part (abfd)
3068 ieee_data_type *ieee = IEEE_DATA (abfd);
3069 ieee->w.r.trailer_part = bfd_tell (abfd);
3070 if (abfd->start_address)
3072 ieee->w.r.me_record = bfd_tell (abfd);
3073 ieee_write_2bytes (abfd, ieee_value_starting_address_enum);
3074 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
3075 ieee_write_int (abfd, abfd->start_address);
3076 ieee_write_byte (abfd, ieee_function_either_close_b_enum);
3080 ieee->w.r.me_record = bfd_tell (abfd);
3082 ieee_write_byte (abfd, ieee_module_end_enum);
3087 ieee_write_object_contents (abfd)
3090 ieee_data_type *ieee = IEEE_DATA (abfd);
3093 /* Fast forward over the header area */
3094 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3096 ieee_write_byte (abfd, ieee_module_beginning_enum);
3098 ieee_write_id (abfd, bfd_printable_name (abfd));
3099 ieee_write_id (abfd, abfd->filename);
3101 /* Fast forward over the variable bits */
3102 ieee_write_byte (abfd, ieee_address_descriptor_enum);
3105 ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd)));
3106 /* MAU's per address */
3107 ieee_write_byte (abfd,
3108 (bfd_byte) (bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd)));
3110 old = bfd_tell (abfd);
3111 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3114 ieee->w.r.extension_record = bfd_tell (abfd);
3115 if (bfd_write ((char *) exten, 1, sizeof (exten), abfd) != sizeof (exten))
3117 if (abfd->flags & EXEC_P)
3118 ieee_write_byte (abfd, 0x1);/* Absolute */
3120 ieee_write_byte (abfd, 0x2);/* Relocateable */
3122 ieee->w.r.environmental_record = bfd_tell (abfd);
3123 if (bfd_write ((char *) envi, 1, sizeof (envi), abfd) != sizeof (envi))
3128 ieee_write_section_part (abfd);
3130 First write the symbols, this changes their values into table
3131 indeces so we cant use it after this point
3133 ieee_write_external_part (abfd);
3134 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3137 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3141 Write any debugs we have been told about
3143 ieee_write_debug_part (abfd);
3146 Can only write the data once the symbols have been written since
3147 the data contains relocation information which points to the
3150 ieee_write_data_part (abfd);
3154 At the end we put the end !
3156 ieee_write_me_part (abfd);
3159 /* Generate the header */
3160 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3163 for (i = 0; i < N_W_VARIABLES; i++)
3165 ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum);
3166 ieee_write_byte (abfd, (bfd_byte) i);
3167 ieee_write_int5_out (abfd, ieee->w.offset[i]);
3174 /* Native-level interface to symbols. */
3176 /* We read the symbols into a buffer, which is discarded when this
3177 function exits. We read the strings into a buffer large enough to
3178 hold them all plus all the cached symbol entries. */
3181 ieee_make_empty_symbol (abfd)
3185 ieee_symbol_type *new =
3186 (ieee_symbol_type *) bfd_zmalloc (sizeof (ieee_symbol_type));
3189 bfd_set_error (bfd_error_no_error);
3192 new->symbol.the_bfd = abfd;
3193 return &new->symbol;
3197 ieee_openr_next_archived_file (arch, prev)
3201 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3202 /* take the next one from the arch state, or reset */
3203 if (prev == (bfd *) NULL)
3205 /* Reset the index - the first two entries are bogus*/
3206 ar->element_index = 2;
3210 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3211 ar->element_index++;
3212 if (ar->element_index <= ar->element_count)
3214 if (p->file_offset != (file_ptr) 0)
3216 if (p->abfd == (bfd *) NULL)
3218 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3219 p->abfd->origin = p->file_offset;
3226 bfd_set_error (bfd_error_no_more_archived_files);
3227 return (bfd *) NULL;
3234 ieee_find_nearest_line (abfd,
3245 char **filename_ptr;
3246 char **functionname_ptr;
3253 ieee_generic_stat_arch_elt (abfd, buf)
3257 ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
3258 if (ar == (ieee_ar_data_type *) NULL)
3260 bfd_set_error (bfd_error_invalid_operation);
3266 buf->st_mode = 0666;
3267 return !ieee_object_p (abfd);
3272 ieee_sizeof_headers (abfd, x)
3280 /* The debug info routines are never used. */
3284 ieee_bfd_debug_info_start (abfd)
3291 ieee_bfd_debug_info_end (abfd)
3298 /* Add this section to the list of sections we have debug info for, to
3299 be ready to output it at close time
3302 ieee_bfd_debug_info_accumulate (abfd, section)
3306 ieee_data_type *ieee = IEEE_DATA (section->owner);
3307 ieee_data_type *output_ieee = IEEE_DATA (abfd);
3308 /* can only accumulate data from other ieee bfds */
3309 if (section->owner->xvec != abfd->xvec)
3311 /* Only bother once per bfd */
3312 if (ieee->done_debug == true)
3314 ieee->done_debug = true;
3316 /* Don't bother if there is no debug info */
3317 if (ieee->w.r.debug_information_part == 0)
3323 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc (abfd, sizeof (bfd_chain_type));
3326 bfd_set_error (bfd_error_no_memory);
3327 abort (); /* FIXME */
3329 n->this = section->owner;
3330 n->next = (bfd_chain_type *) NULL;
3332 if (output_ieee->chain_head)
3334 output_ieee->chain_head->next = n;
3338 output_ieee->chain_root = n;
3341 output_ieee->chain_head = n;
3347 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3348 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3350 #define ieee_slurp_armap bfd_true
3351 #define ieee_slurp_extended_name_table bfd_true
3352 #define ieee_truncate_arname bfd_dont_truncate_arname
3353 #define ieee_write_armap \
3355 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3358 #define ieee_bfd_is_local_label bfd_generic_is_local_label
3359 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3360 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3362 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3364 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3366 #define ieee_bfd_get_relocated_section_contents \
3367 bfd_generic_get_relocated_section_contents
3368 #define ieee_bfd_relax_section bfd_generic_relax_section
3369 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3370 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3371 #define ieee_bfd_final_link _bfd_generic_final_link
3374 const bfd_target ieee_vec =
3377 bfd_target_ieee_flavour,
3378 true, /* target byte order */
3379 true, /* target headers byte order */
3380 (HAS_RELOC | EXEC_P | /* object flags */
3381 HAS_LINENO | HAS_DEBUG |
3382 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3383 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3384 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3385 0, /* leading underscore */
3386 ' ', /* ar_pad_char */
3387 16, /* ar_max_namelen */
3388 1, /* minimum alignment */
3389 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3390 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3391 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3392 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3393 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3394 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3397 ieee_object_p, /* bfd_check_format */
3404 _bfd_generic_mkarchive,
3409 ieee_write_object_contents,
3410 _bfd_write_archive_contents,
3414 BFD_JUMP_TABLE_GENERIC (ieee),
3415 BFD_JUMP_TABLE_COPY (_bfd_generic),
3416 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3417 BFD_JUMP_TABLE_ARCHIVE (ieee),
3418 BFD_JUMP_TABLE_SYMBOLS (ieee),
3419 BFD_JUMP_TABLE_RELOCS (ieee),
3420 BFD_JUMP_TABLE_WRITE (ieee),
3421 BFD_JUMP_TABLE_LINK (ieee),
3422 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),