1 /* BFD back-end for ieee-695 objects.
2 Copyright 1990, 1991, 1992, 1993 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
35 #define obstack_chunk_alloc bfd_xmalloc
36 #define obstack_chunk_free free
38 /* Functions for writing to ieee files in the strange way that the
42 DEFUN(ieee_write_byte,(abfd, byte),
46 bfd_write((PTR)&byte, 1, 1, abfd);
51 DEFUN(ieee_write_twobyte,(abfd, twobyte),
56 b[1] = twobyte & 0xff;
58 bfd_write((PTR)&b[0], 1, 2, abfd);
64 DEFUN(ieee_write_2bytes,(abfd, bytes),
69 buffer[0] = bytes >> 8;
70 buffer[1] = bytes & 0xff;
72 bfd_write((PTR)buffer, 1, 2, abfd);
76 DEFUN(ieee_write_int,(abfd, value),
80 if (((unsigned)value) <= 127) {
81 ieee_write_byte(abfd, (bfd_byte)value);
85 /* How many significant bytes ? */
86 /* FIXME FOR LONGER INTS */
87 if (value & 0xff000000) {
90 else if (value & 0x00ff0000) {
93 else if (value & 0x0000ff00) {
99 (bfd_byte)((int)ieee_number_repeat_start_enum + length));
102 ieee_write_byte(abfd, (bfd_byte)(value >> 24));
104 ieee_write_byte(abfd, (bfd_byte)(value >> 16));
106 ieee_write_byte(abfd, (bfd_byte)(value >> 8));
108 ieee_write_byte(abfd, (bfd_byte)(value));
114 DEFUN(ieee_write_id,(abfd, id),
118 size_t length = strlen(id);
119 if (length >= 0 && length <= 127) {
120 ieee_write_byte(abfd, (bfd_byte)length);
122 else if (length < 255) {
123 ieee_write_byte(abfd, ieee_extension_length_1_enum);
124 ieee_write_byte(abfd, (bfd_byte)length);
126 else if (length < 65535) {
127 ieee_write_byte(abfd, ieee_extension_length_2_enum);
128 ieee_write_byte(abfd, (bfd_byte)(length >> 8));
129 ieee_write_byte(abfd, (bfd_byte)(length & 0xff));
134 bfd_write((PTR)id, 1, length, abfd);
136 /***************************************************************************
137 Functions for reading from ieee files in the strange way that the
142 #define this_byte(ieee) *((ieee)->input_p)
143 #define next_byte(ieee) ((ieee)->input_p++)
144 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
147 static unsigned short
148 DEFUN(read_2bytes,(ieee),
149 common_header_type *ieee)
151 unsigned char c1 = this_byte_and_next(ieee);
152 unsigned char c2 = this_byte_and_next(ieee);
153 return (c1<<8 ) | c2;
158 DEFUN(bfd_get_string,(ieee, string, length),
159 common_header_type *ieee AND
164 for (i= 0; i < length; i++) {
165 string[i] = this_byte_and_next(ieee);
170 DEFUN(read_id,(ieee),
171 common_header_type *ieee)
175 length = this_byte_and_next(ieee);
176 if (length >= 0x00 && length <= 0x7f) {
177 /* Simple string of length 0 to 127 */
179 else if (length == 0xde) {
180 /* Length is next byte, allowing 0..255 */
181 length = this_byte_and_next(ieee);
183 else if (length == 0xdf) {
184 /* Length is next two bytes, allowing 0..65535 */
185 length = this_byte_and_next(ieee) ;
186 length = (length * 256) + this_byte_and_next(ieee);
188 /* Buy memory and read string */
189 string = bfd_alloc(ieee->abfd, length+1);
190 bfd_get_string(ieee, string, length);
196 DEFUN(ieee_write_expression,(abfd, value, symbol, pcrel, index),
203 unsigned int term_count = 0;
207 ieee_write_int(abfd, value);
213 if (bfd_is_com_section (symbol->section)
214 || symbol->section == &bfd_und_section)
216 /* Def of a common symbol */
217 ieee_write_byte(abfd, ieee_variable_X_enum);
218 ieee_write_int(abfd, symbol->value);
221 else if (symbol->section != &bfd_abs_section)
223 /* Ref to defined symbol - */
225 ieee_write_byte(abfd, ieee_variable_R_enum);
226 ieee_write_byte(abfd,
227 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
229 if (symbol->flags & BSF_GLOBAL)
231 ieee_write_byte(abfd, ieee_variable_I_enum);
232 ieee_write_int(abfd, symbol->value);
235 else if (symbol->flags & ( BSF_LOCAL | BSF_SECTION_SYM))
237 /* This is a reference to a defined local symbol,
238 We can easily do a local as a section+offset */
239 ieee_write_byte(abfd, ieee_variable_R_enum); /* or L */
240 ieee_write_byte(abfd,
241 (bfd_byte)(symbol->section->index + IEEE_SECTION_NUMBER_BASE));
242 ieee_write_int(abfd, symbol->value);
255 /* subtract the pc from here by asking for PC of this section*/
256 ieee_write_byte(abfd, ieee_variable_P_enum);
257 ieee_write_byte(abfd, (bfd_byte)(index+IEEE_SECTION_NUMBER_BASE));
258 ieee_write_byte(abfd, ieee_function_minus_enum);
263 ieee_write_byte(abfd,0);
266 while (term_count > 1) {
267 ieee_write_byte(abfd, ieee_function_plus_enum);
282 /*****************************************************************************/
285 writes any integer into the buffer supplied and always takes 5 bytes
288 DEFUN(ieee_write_int5,(buffer, value),
292 buffer[0] = (bfd_byte)ieee_number_repeat_4_enum;
293 buffer[1] = (value >> 24 ) & 0xff;
294 buffer[2] = (value >> 16 ) & 0xff;
295 buffer[3] = (value >> 8 ) & 0xff;
296 buffer[4] = (value >> 0 ) & 0xff;
299 DEFUN(ieee_write_int5_out, (abfd, value),
304 ieee_write_int5(b, value);
305 bfd_write((PTR)b,1,5,abfd);
310 DEFUN(parse_int,(ieee, value_ptr),
311 common_header_type *ieee AND
314 int value = this_byte(ieee);
316 if (value >= 0 && value <= 127) {
321 else if (value >= 0x80 && value <= 0x88) {
322 unsigned int count = value & 0xf;
326 result =(result << 8) | this_byte_and_next(ieee);
335 DEFUN(parse_i,(ieee, ok),
336 common_header_type *ieee AND
340 *ok = parse_int(ieee, &x);
345 DEFUN(must_parse_int,(ieee),
346 common_header_type *ieee)
349 BFD_ASSERT(parse_int(ieee, &result) == true);
357 ieee_symbol_index_type symbol;
362 reloc_howto_type abs32_howto
363 = HOWTO(1,0,2,32,false,0,false,true,0,"abs32",true,0xffffffff, 0xffffffff,false);
365 reloc_howto_type abs16_howto
366 = HOWTO(1,0,1,16,false,0,false,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false);
369 reloc_howto_type abs8_howto
370 = HOWTO(1,0,0,8,false,0,false,true,0,"abs8",true,0x000000ff, 0x000000ff,false);
373 reloc_howto_type rel32_howto
374 = HOWTO(1,0,2,32,true,0,false,true,0,"rel32",true,0xffffffff,
378 reloc_howto_type rel16_howto
379 = HOWTO(1,0,1,16,true,0,false,true,0,"rel16",true,0x0000ffff, 0x0000ffff,false);
382 reloc_howto_type rel8_howto
383 = HOWTO(1,0,0,8,true,0,false,true,0,"rel8",true,0x000000ff, 0x000000ff,false);
386 static ieee_symbol_index_type NOSYMBOL = { 0, 0};
390 DEFUN(parse_expression,(ieee, value, symbol, pcrel, extra, section),
391 ieee_data_type *ieee AND
393 ieee_symbol_index_type *symbol AND
395 unsigned int *extra AND
407 ieee_value_type stack[10];
409 /* The stack pointer always points to the next unused location */
410 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
411 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
412 ieee_value_type *sp = stack;
415 switch (this_byte(&(ieee->h)))
417 case ieee_variable_P_enum:
418 /* P variable, current program counter for section n */
421 next_byte(&(ieee->h));
423 section_n = must_parse_int(&(ieee->h));
424 PUSH(NOSYMBOL, &bfd_abs_section,
425 TOS.value = ieee->section_table[section_n]->vma +
426 ieee_per_section(ieee->section_table[section_n])->pc);
429 case ieee_variable_L_enum:
430 /* L variable address of section N */
431 next_byte(&(ieee->h));
432 PUSH(NOSYMBOL,ieee->section_table[must_parse_int(&(ieee->h))],0);
434 case ieee_variable_R_enum:
435 /* R variable, logical address of section module */
436 /* FIXME, this should be different to L */
437 next_byte(&(ieee->h));
438 PUSH(NOSYMBOL,ieee->section_table[must_parse_int(&(ieee->h))],0);
440 case ieee_variable_S_enum:
441 /* S variable, size in MAUS of section module */
442 next_byte(&(ieee->h));
445 ieee->section_table[must_parse_int(&(ieee->h))]->_raw_size);
447 case ieee_variable_I_enum:
448 case ieee_variable_X_enum:
449 /* Push the address of external variable n */
451 ieee_symbol_index_type sy;
452 next_byte(&(ieee->h));
453 sy.index = (int)(must_parse_int(&(ieee->h))) ;
456 PUSH(sy, &bfd_und_section, 0);
459 case ieee_function_minus_enum:
461 bfd_vma value1, value2;
462 asection *section1, *section_dummy;
463 ieee_symbol_index_type sy;
464 next_byte(&(ieee->h));
466 POP(sy, section1, value1);
467 POP(sy, section_dummy, value2);
468 PUSH(sy, section1 ? section1 : section_dummy, value1-value2);
471 case ieee_function_plus_enum:
473 bfd_vma value1, value2;
476 ieee_symbol_index_type sy1;
477 ieee_symbol_index_type sy2;
478 next_byte(&(ieee->h));
480 POP(sy1, section1, value1);
481 POP(sy2, section2, value2);
482 PUSH(sy1.letter ? sy1 : sy2, section1!=&bfd_abs_section ? section1: section2, value1+value2);
488 BFD_ASSERT(this_byte(&(ieee->h)) < (int)ieee_variable_A_enum
489 || this_byte(&(ieee->h)) > (int)ieee_variable_Z_enum);
490 if (parse_int(&(ieee->h), &va))
492 PUSH(NOSYMBOL, &bfd_abs_section, va);
496 Thats all that we can understand. As far as I can see
497 there is a bug in the Microtec IEEE output which I'm
498 using to scan, whereby the comma operator is ommited
499 sometimes in an expression, giving expressions with too
500 many terms. We can tell if that's the case by ensuring
501 that sp == stack here. If not, then we've pushed
502 something too far, so we keep adding
505 while (sp != stack+1) {
507 ieee_symbol_index_type sy1;
508 POP(sy1, section1, *extra);
513 POP(*symbol, dummy, *value);
514 if (section) *section = dummy;
527 #define ieee_seek(abfd, offset) \
528 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
530 #define ieee_pos(abfd) IEEE_DATA(abfd)->h.input_p -IEEE_DATA(abfd)->h.first_byte
532 static unsigned int last_index;
533 static char last_type; /* is the index for an X or a D */
534 static ieee_symbol_type *
535 DEFUN(get_symbol,(abfd,
544 ieee_data_type *ieee AND
545 ieee_symbol_type *last_symbol AND
546 unsigned int *symbol_count AND
547 ieee_symbol_type *** pptr AND
548 unsigned int *max_index AND
552 /* Need a new symbol */
553 unsigned int new_index = must_parse_int(&(ieee->h));
554 if (new_index != last_index || this_type != last_type) {
555 ieee_symbol_type * new_symbol = (ieee_symbol_type *)bfd_alloc(ieee->h.abfd,
556 sizeof(ieee_symbol_type));
558 new_symbol->index = new_index;
559 last_index = new_index;
562 *pptr = &new_symbol->next;
563 if (new_index > *max_index) {
564 *max_index = new_index;
566 last_type = this_type;
572 DEFUN(ieee_slurp_external_symbols,(abfd),
575 ieee_data_type *ieee = IEEE_DATA(abfd);
576 file_ptr offset = ieee->w.r.external_part;
579 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
580 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
581 ieee_symbol_type *symbol = (ieee_symbol_type *)NULL;
582 unsigned int symbol_count = 0;
584 last_index = 0xffffff;
585 ieee->symbol_table_full = true;
587 ieee_seek(abfd, offset );
590 switch (this_byte(&(ieee->h))) {
592 next_byte(&(ieee->h));
594 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
596 &ieee->external_symbol_max_index,'D');
599 symbol->symbol.the_bfd = abfd;
600 symbol->symbol.name = read_id(&(ieee->h));
601 symbol->symbol.udata = (PTR)NULL;
602 symbol->symbol.flags = BSF_NO_FLAGS;
606 case ieee_external_symbol_enum:
607 next_byte(&(ieee->h));
609 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
611 &ieee->external_symbol_max_index,'D');
614 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
616 symbol->symbol.the_bfd = abfd;
617 symbol->symbol.name = read_id(&(ieee->h));
618 symbol->symbol.udata = (PTR)NULL;
619 symbol->symbol.flags = BSF_NO_FLAGS;
621 case ieee_attribute_record_enum >> 8:
623 unsigned int symbol_name_index;
624 unsigned int symbol_type_index;
625 unsigned int symbol_attribute_def;
627 next_byte(&(ieee->h)); /* Skip prefix */
628 next_byte(&(ieee->h));
629 symbol_name_index = must_parse_int(&(ieee->h));
630 symbol_type_index = must_parse_int(&(ieee->h));
631 symbol_attribute_def = must_parse_int(&(ieee->h));
632 switch (symbol_attribute_def) {
634 /* Module misc; followed by two fields which describe the
635 current module block. The first fired is the type id
636 number, the second is the number of asn records
637 associated with the directive */
638 parse_int(&(ieee->h),&value);
639 parse_int(&(ieee->h),&value);
643 parse_int(&(ieee->h),&value);
648 case ieee_value_record_enum >> 8:
650 unsigned int symbol_name_index;
651 ieee_symbol_index_type symbol_ignore;
652 boolean pcrel_ignore;
654 next_byte(&(ieee->h));
655 next_byte(&(ieee->h));
657 symbol_name_index = must_parse_int(&(ieee->h));
658 parse_expression(ieee,
659 &symbol->symbol.value,
663 &symbol->symbol.section);
665 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
669 case ieee_weak_external_reference_enum:
672 next_byte(&(ieee->h));
673 /* Throw away the external reference index */
674 (void)must_parse_int(&(ieee->h));
675 /* Fetch the default size if not resolved */
676 size = must_parse_int(&(ieee->h));
677 /* Fetch the defautlt value if available */
678 if ( parse_int(&(ieee->h), &value) == false) {
681 /* This turns into a common */
682 symbol->symbol.section = &bfd_com_section;
683 symbol->symbol.value = size;
687 case ieee_external_reference_enum:
688 next_byte(&(ieee->h));
690 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
692 &ieee->external_reference_max_index,'X');
695 symbol->symbol.the_bfd = abfd;
696 symbol->symbol.name = read_id(&(ieee->h));
697 symbol->symbol.udata = (PTR)NULL;
698 symbol->symbol.section = &bfd_und_section;
699 symbol->symbol.value = (bfd_vma)0;
700 symbol->symbol.flags = 0;
702 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
710 if (ieee->external_symbol_max_index != 0) {
711 ieee->external_symbol_count =
712 ieee->external_symbol_max_index -
713 ieee->external_symbol_min_index + 1 ;
716 ieee->external_symbol_count = 0;
720 if(ieee->external_reference_max_index != 0) {
721 ieee->external_reference_count =
722 ieee->external_reference_max_index -
723 ieee->external_reference_min_index + 1;
726 ieee->external_reference_count = 0;
730 ieee->external_reference_count + ieee->external_symbol_count;
732 if (symbol_count != abfd->symcount) {
733 /* There are gaps in the table -- */
734 ieee->symbol_table_full = false;
738 *prev_symbols_ptr = (ieee_symbol_type *)NULL;
739 *prev_reference_ptr = (ieee_symbol_type *)NULL;
743 DEFUN(ieee_slurp_symbol_table,(abfd),
746 if (IEEE_DATA(abfd)->read_symbols == false) {
747 ieee_slurp_external_symbols(abfd);
748 IEEE_DATA(abfd)->read_symbols= true;
753 DEFUN(ieee_get_symtab_upper_bound,(abfd),
756 ieee_slurp_symbol_table (abfd);
758 return (abfd->symcount != 0) ?
759 (abfd->symcount+1) * (sizeof (ieee_symbol_type *)) : 0;
763 Move from our internal lists to the canon table, and insert in
767 extern bfd_target ieee_vec;
769 DEFUN(ieee_get_symtab,(abfd, location),
773 ieee_symbol_type *symp;
774 static bfd dummy_bfd;
775 static asymbol empty_symbol =
776 /* the_bfd, name, value, attr, section */
777 { &dummy_bfd, " ieee empty", (symvalue)0, BSF_DEBUGGING, &bfd_abs_section};
781 ieee_data_type *ieee = IEEE_DATA(abfd);
782 dummy_bfd.xvec= &ieee_vec;
783 ieee_slurp_symbol_table(abfd);
785 if (ieee->symbol_table_full == false) {
786 /* Arrgh - there are gaps in the table, run through and fill them */
787 /* up with pointers to a null place */
789 for (i= 0; i < abfd->symcount; i++) {
790 location[i] = &empty_symbol;
795 ieee->external_symbol_base_offset= - ieee->external_symbol_min_index;
796 for (symp = IEEE_DATA(abfd)->external_symbols;
797 symp != (ieee_symbol_type *)NULL;
799 /* Place into table at correct index locations */
800 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
804 /* The external refs are indexed in a bit */
805 ieee->external_reference_base_offset =
806 - ieee->external_reference_min_index +ieee->external_symbol_count ;
808 for (symp = IEEE_DATA(abfd)->external_reference;
809 symp != (ieee_symbol_type *)NULL;
811 location[symp->index + ieee->external_reference_base_offset] =
820 if (abfd->symcount) {
821 location[abfd->symcount] = (asymbol *)NULL;
823 return abfd->symcount;
826 DEFUN(get_section_entry,(abfd, ieee,index),
828 ieee_data_type *ieee AND
831 if (ieee->section_table[index] == (asection *)NULL) {
832 char *tmp = bfd_alloc(abfd,11);
834 sprintf(tmp," fsec%4d", index);
835 section = bfd_make_section(abfd, tmp);
836 ieee->section_table[index] = section;
837 section->flags = SEC_NO_FLAGS;
838 section->target_index = index;
839 ieee->section_table[index] = section;
841 return ieee->section_table[index];
845 DEFUN(ieee_slurp_sections,(abfd),
848 ieee_data_type *ieee = IEEE_DATA(abfd);
849 file_ptr offset = ieee->w.r.section_part;
850 asection *section = (asection *)NULL;
854 bfd_byte section_type[3];
855 ieee_seek(abfd, offset);
857 switch (this_byte(&(ieee->h))) {
858 case ieee_section_type_enum:
860 unsigned int section_index ;
861 next_byte(&(ieee->h));
862 section_index = must_parse_int(&(ieee->h));
863 /* Fixme to be nice about a silly number of sections */
864 BFD_ASSERT(section_index < NSECTIONS);
866 section =get_section_entry(abfd, ieee, section_index);
868 section_type[0] = this_byte_and_next(&(ieee->h));
869 switch (section_type[0]) {
871 /* Normal attributes for absolute sections */
872 section_type[1] = this_byte(&(ieee->h));
873 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
874 switch(section_type[1]) {
875 case 0xD3: /* AS Absolute section attributes */
876 next_byte(&(ieee->h));
877 section_type[2] = this_byte(&(ieee->h));
878 switch (section_type[2])
882 next_byte(&(ieee->h));
883 section->flags |= SEC_LOAD | SEC_CODE;
886 next_byte(&(ieee->h));
887 section->flags |= SEC_LOAD | SEC_DATA;
891 next_byte(&(ieee->h));
892 /* Normal rom data */
893 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
900 case 0xC3: /* Named relocatable sections (type C) */
901 section_type[1] = this_byte(&(ieee->h));
902 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
903 switch (section_type[1]) {
904 case 0xD0: /* Normal code (CP) */
905 next_byte(&(ieee->h));
906 section->flags |= SEC_LOAD | SEC_CODE;
908 case 0xC4: /* Normal data (CD) */
909 next_byte(&(ieee->h));
910 section->flags |= SEC_LOAD | SEC_DATA;
912 case 0xD2: /* Normal rom data (CR) */
913 next_byte(&(ieee->h));
914 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
921 /* Read section name, use it if non empty. */
922 name = read_id (&ieee->h);
924 section->name = name;
926 /* Skip these fields, which we don't care about */
928 bfd_vma parent, brother, context;
929 parse_int(&(ieee->h), &parent);
930 parse_int(&(ieee->h), &brother);
931 parse_int(&(ieee->h), &context);
935 case ieee_section_alignment_enum:
937 unsigned int section_index;
940 next_byte(&(ieee->h));
941 section_index = must_parse_int(&ieee->h);
942 section = get_section_entry(abfd, ieee, section_index);
943 if (section_index > ieee->section_count) {
944 ieee->section_count = section_index;
946 section->alignment_power =
947 bfd_log2(must_parse_int(&ieee->h));
948 (void)parse_int(&(ieee->h), & value);
951 case ieee_e2_first_byte_enum:
953 ieee_record_enum_type t = (ieee_record_enum_type)(read_2bytes(&(ieee->h)));
956 case ieee_section_size_enum:
957 section = ieee->section_table[must_parse_int(&(ieee->h))];
958 section->_raw_size = must_parse_int(&(ieee->h));
960 case ieee_physical_region_size_enum:
961 section = ieee->section_table[must_parse_int(&(ieee->h))];
962 section->_raw_size = must_parse_int(&(ieee->h));
964 case ieee_region_base_address_enum:
965 section = ieee->section_table[must_parse_int(&(ieee->h))];
966 section->vma = must_parse_int(&(ieee->h));
968 case ieee_mau_size_enum:
969 must_parse_int(&(ieee->h));
970 must_parse_int(&(ieee->h));
972 case ieee_m_value_enum:
973 must_parse_int(&(ieee->h));
974 must_parse_int(&(ieee->h));
976 case ieee_section_base_address_enum:
977 section = ieee->section_table[must_parse_int(&(ieee->h))];
978 section->vma = must_parse_int(&(ieee->h));
980 case ieee_section_offset_enum:
981 (void) must_parse_int(&(ieee->h));
982 (void) must_parse_int(&(ieee->h));
996 /***********************************************************************
1000 DEFUN(ieee_archive_p,(abfd),
1007 uint8e_type buffer[512];
1009 file_ptr buffer_offset = 0;
1010 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1011 ieee_ar_data_type *ieee ;
1012 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *)bfd_alloc(abfd, sizeof(ieee_ar_data_type));
1013 ieee= IEEE_AR_DATA(abfd);
1017 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1019 ieee->h.first_byte = buffer;
1020 ieee->h.input_p = buffer;
1022 ieee->h.abfd = abfd;
1024 if (this_byte(&(ieee->h)) != Module_Beginning) {
1025 abfd->tdata.ieee_ar_data = save;
1026 return (bfd_target*)NULL;
1030 next_byte(&(ieee->h));
1031 library= read_id(&(ieee->h));
1032 if (strcmp(library , "LIBRARY") != 0) {
1033 bfd_release(abfd, ieee);
1034 abfd->tdata.ieee_ar_data = save;
1035 return (bfd_target *)NULL;
1037 /* Throw away the filename */
1038 read_id(&(ieee->h));
1039 /* This must be an IEEE archive, so we'll buy some space to do
1042 obstack_begin(&ob, 128);
1045 ieee->element_count = 0;
1046 ieee->element_index = 0;
1048 next_byte(&(ieee->h)); /* Drop the ad part */
1049 must_parse_int(&(ieee->h)); /* And the two dummy numbers */
1050 must_parse_int(&(ieee->h));
1053 /* Read the index of the BB table */
1055 ieee_ar_obstack_type t;
1056 int rec =read_2bytes(&(ieee->h));
1057 if (rec ==(int)ieee_assign_value_to_variable_enum) {
1058 int record_number = must_parse_int(&(ieee->h));
1059 t.file_offset = must_parse_int(&(ieee->h));
1060 t.abfd = (bfd *)NULL;
1061 ieee->element_count++;
1063 obstack_grow(&ob, (PTR)&t, sizeof(t));
1065 /* Make sure that we don't go over the end of the buffer */
1067 if (ieee_pos(abfd) > sizeof(buffer)/2) {
1068 /* Past half way, reseek and reprime */
1069 buffer_offset += ieee_pos(abfd);
1070 bfd_seek(abfd, buffer_offset, SEEK_SET);
1071 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1072 ieee->h.first_byte = buffer;
1073 ieee->h.input_p = buffer;
1079 ieee->elements = (ieee_ar_obstack_type *)obstack_finish(&ob);
1081 /* Now scan the area again, and replace BB offsets with file */
1085 for (i = 2; i < ieee->element_count; i++) {
1086 bfd_seek(abfd, ieee->elements[i].file_offset, SEEK_SET);
1087 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1088 ieee->h.first_byte = buffer;
1089 ieee->h.input_p = buffer;
1091 next_byte(&(ieee->h)); /* Drop F8 */
1092 next_byte(&(ieee->h)); /* Drop 14 */
1093 must_parse_int(&(ieee->h)); /* Drop size of block */
1094 if (must_parse_int(&(ieee->h)) != 0) {
1095 /* This object has been deleted */
1096 ieee->elements[i].file_offset = 0;
1099 ieee->elements[i].file_offset = must_parse_int(&(ieee->h));
1103 /* abfd->has_armap = ;*/
1109 DEFUN(ieee_mkobject,(abfd),
1112 abfd->tdata.ieee_data = (ieee_data_type *)bfd_zalloc(abfd,sizeof(ieee_data_type));
1119 DEFUN(ieee_object_p,(abfd),
1124 ieee_data_type *ieee;
1125 uint8e_type buffer[300];
1126 ieee_data_type *save = IEEE_DATA(abfd);
1127 abfd->tdata.ieee_data = 0;
1128 ieee_mkobject(abfd);
1130 ieee = IEEE_DATA(abfd);
1131 bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
1132 /* Read the first few bytes in to see if it makes sense */
1133 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1135 ieee->h.input_p = buffer;
1136 if (this_byte_and_next(&(ieee->h)) != Module_Beginning) goto fail;
1138 ieee->read_symbols= false;
1139 ieee->read_data= false;
1140 ieee->section_count = 0;
1141 ieee->external_symbol_max_index = 0;
1142 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1143 ieee->external_reference_min_index =IEEE_REFERENCE_BASE;
1144 ieee->external_reference_max_index = 0;
1145 ieee->h.abfd = abfd;
1146 memset((PTR)ieee->section_table, 0, sizeof(ieee->section_table));
1148 processor = ieee->mb.processor = read_id(&(ieee->h));
1149 if (strcmp(processor,"LIBRARY") == 0) goto fail;
1150 ieee->mb.module_name = read_id(&(ieee->h));
1151 if (abfd->filename == (CONST char *)NULL) {
1152 abfd->filename = ieee->mb.module_name;
1154 /* Determine the architecture and machine type of the object file.
1157 bfd_arch_info_type *arch = bfd_scan_arch(processor);
1158 if (arch == 0) goto fail;
1159 abfd->arch_info = arch;
1162 if (this_byte(&(ieee->h)) != (int)ieee_address_descriptor_enum) {
1165 next_byte(&(ieee->h));
1167 if (parse_int(&(ieee->h), &ieee->ad.number_of_bits_mau) == false) {
1170 if(parse_int(&(ieee->h), &ieee->ad.number_of_maus_in_address) == false) {
1174 /* If there is a byte order info, take it */
1175 if (this_byte(&(ieee->h)) == (int)ieee_variable_L_enum ||
1176 this_byte(&(ieee->h)) == (int)ieee_variable_M_enum)
1177 next_byte(&(ieee->h));
1180 for (part = 0; part < N_W_VARIABLES; part++) {
1182 if (read_2bytes(&(ieee->h)) != (int) ieee_assign_value_to_variable_enum) {
1185 if (this_byte_and_next(&(ieee->h)) != part) {
1189 ieee->w.offset[part] = parse_i(&(ieee->h), &ok);
1195 abfd->flags = HAS_SYMS;
1196 /* By now we know that this is a real IEEE file, we're going to read
1197 the whole thing into memory so that we can run up and down it
1198 quickly. We can work out how big the file is from the trailer
1201 IEEE_DATA(abfd)->h.first_byte = (uint8e_type *) bfd_alloc(ieee->h.abfd, ieee->w.r.me_record
1203 bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
1204 bfd_read((PTR)(IEEE_DATA(abfd)->h.first_byte), 1, ieee->w.r.me_record+50, abfd);
1206 ieee_slurp_sections(abfd);
1209 (void) bfd_release(abfd, ieee);
1210 abfd->tdata.ieee_data = save;
1211 return (bfd_target *)NULL;
1216 DEFUN(ieee_print_symbol,(ignore_abfd, afile, symbol, how),
1217 bfd *ignore_abfd AND
1220 bfd_print_symbol_type how)
1222 FILE *file = (FILE *)afile;
1225 case bfd_print_symbol_name:
1226 fprintf(file,"%s", symbol->name);
1228 case bfd_print_symbol_more:
1230 fprintf(file,"%4x %2x",aout_symbol(symbol)->desc & 0xffff,
1231 aout_symbol(symbol)->other & 0xff);
1235 case bfd_print_symbol_nm:
1236 case bfd_print_symbol_all:
1238 CONST char *section_name = symbol->section == (asection *)NULL ?
1239 (CONST char *)"*abs" : symbol->section->name;
1240 if (symbol->name[0] == ' ') {
1241 fprintf(file,"* empty table entry ");
1244 bfd_print_symbol_vandf((PTR)file,symbol);
1246 fprintf(file," %-5s %04x %02x %s",
1248 (unsigned) ieee_symbol(symbol)->index,
1250 aout_symbol(symbol)->desc & 0xffff,
1251 aout_symbol(symbol)->other & 0xff,*/
1261 DEFUN(do_one,(ieee, current_map, location_ptr,s),
1262 ieee_data_type *ieee AND
1263 ieee_per_section_type *current_map AND
1264 uint8e_type *location_ptr AND
1267 switch (this_byte(&(ieee->h)))
1269 case ieee_load_constant_bytes_enum:
1271 unsigned int number_of_maus;
1273 next_byte(&(ieee->h));
1274 number_of_maus = must_parse_int(&(ieee->h));
1276 for (i = 0; i < number_of_maus; i++) {
1277 location_ptr[current_map->pc++]= this_byte(&(ieee->h));
1278 next_byte(&(ieee->h));
1283 case ieee_load_with_relocation_enum:
1285 boolean loop = true;
1286 next_byte(&(ieee->h));
1289 switch (this_byte(&(ieee->h)))
1291 case ieee_variable_R_enum:
1293 case ieee_function_signed_open_b_enum:
1294 case ieee_function_unsigned_open_b_enum:
1295 case ieee_function_either_open_b_enum:
1297 unsigned int extra = 4;
1298 boolean pcrel = false;
1300 ieee_reloc_type *r =
1301 (ieee_reloc_type *) bfd_alloc(ieee->h.abfd,
1302 sizeof(ieee_reloc_type));
1304 *(current_map->reloc_tail_ptr) = r;
1305 current_map->reloc_tail_ptr= &r->next;
1306 r->next = (ieee_reloc_type *)NULL;
1307 next_byte(&(ieee->h));
1309 r->relent.sym_ptr_ptr = 0;
1310 parse_expression(ieee,
1313 &pcrel, &extra, §ion);
1314 r->relent.address = current_map->pc;
1316 if (r->relent.sym_ptr_ptr == 0) {
1317 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1320 if (this_byte(&(ieee->h)) == (int)ieee_comma) {
1321 next_byte(&(ieee->h));
1322 /* Fetch number of bytes to pad */
1323 extra = must_parse_int(&(ieee->h));
1326 switch (this_byte(&(ieee->h))) {
1327 case ieee_function_signed_close_b_enum:
1328 next_byte(&(ieee->h));
1330 case ieee_function_unsigned_close_b_enum:
1331 next_byte(&(ieee->h));
1333 case ieee_function_either_close_b_enum:
1334 next_byte(&(ieee->h));
1339 /* Build a relocation entry for this type */
1340 /* If pc rel then stick -ve pc into instruction
1341 and take out of reloc ..
1343 I've changed this. It's all too
1344 complicated. I keep 0 in the
1355 #if KEEPMINUSPCININST
1356 bfd_put_32(ieee->h.abfd, -current_map->pc, location_ptr +
1358 r->relent.howto = &rel32_howto;
1362 bfd_put_32(ieee->h.abfd,0, location_ptr +
1364 r->relent.howto = &rel32_howto;
1369 bfd_put_32(ieee->h.abfd, 0, location_ptr +
1371 r->relent.howto = &abs32_howto;
1373 current_map->pc +=4;
1376 if (pcrel == true) {
1377 #if KEEPMINUSPCININST
1378 bfd_put_16(ieee->h.abfd, (int)(-current_map->pc), location_ptr +current_map->pc);
1379 r->relent.addend -= current_map->pc;
1380 r->relent.howto = &rel16_howto;
1383 bfd_put_16(ieee->h.abfd, 0, location_ptr +current_map->pc);
1384 r->relent.howto = &rel16_howto;
1389 bfd_put_16(ieee->h.abfd, 0, location_ptr +current_map->pc);
1390 r->relent.howto = &abs16_howto;
1392 current_map->pc +=2;
1395 if (pcrel == true) {
1396 #if KEEPMINUSPCININST
1397 bfd_put_8(ieee->h.abfd, (int)(-current_map->pc), location_ptr +current_map->pc);
1398 r->relent.addend -= current_map->pc;
1399 r->relent.howto = &rel8_howto;
1401 bfd_put_8(ieee->h.abfd,0, location_ptr +current_map->pc);
1402 r->relent.howto = &rel8_howto;
1406 bfd_put_8(ieee->h.abfd, 0, location_ptr +current_map->pc);
1407 r->relent.howto = &abs8_howto;
1409 current_map->pc +=1;
1421 if (parse_int(&(ieee->h), &this_size) == true) {
1423 for (i = 0; i < this_size; i++) {
1424 location_ptr[current_map->pc ++] = this_byte(&(ieee->h));
1425 next_byte(&(ieee->h));
1438 /* Read in all the section data and relocation stuff too */
1440 DEFUN(ieee_slurp_section_data,(abfd),
1443 bfd_byte *location_ptr = (bfd_byte *)NULL;
1444 ieee_data_type *ieee = IEEE_DATA(abfd);
1445 unsigned int section_number ;
1447 ieee_per_section_type *current_map = (ieee_per_section_type *)NULL;
1449 /* Seek to the start of the data area */
1450 if (ieee->read_data== true) return true;
1451 ieee->read_data = true;
1452 ieee_seek(abfd, ieee->w.r.data_part);
1454 /* Allocate enough space for all the section contents */
1457 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
1458 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1459 per->data = (bfd_byte *) bfd_alloc(ieee->h.abfd, s->_raw_size);
1461 per->reloc_tail_ptr =
1462 (ieee_reloc_type **)&(s->relocation);
1468 switch (this_byte(&(ieee->h)))
1470 /* IF we see anything strange then quit */
1474 case ieee_set_current_section_enum:
1475 next_byte(&(ieee->h));
1476 section_number = must_parse_int(&(ieee->h));
1477 s = ieee->section_table[section_number];
1478 current_map = (ieee_per_section_type *) s->used_by_bfd;
1479 location_ptr = current_map->data - s->vma;
1480 /* The document I have says that Microtec's compilers reset */
1481 /* this after a sec section, even though the standard says not */
1483 current_map->pc =s->vma;
1487 case ieee_e2_first_byte_enum:
1488 next_byte(&(ieee->h));
1489 switch (this_byte(&(ieee->h)))
1491 case ieee_set_current_pc_enum & 0xff:
1494 ieee_symbol_index_type symbol;
1497 next_byte(&(ieee->h));
1498 must_parse_int(&(ieee->h)); /* Thow away section #*/
1499 parse_expression(ieee, &value,
1503 current_map->pc = value;
1504 BFD_ASSERT((unsigned)(value - s->vma) <= s->_raw_size);
1508 case ieee_value_starting_address_enum & 0xff:
1509 /* We've got to the end of the data now - */
1516 case ieee_repeat_data_enum:
1518 /* Repeat the following LD or LR n times - we do this by
1519 remembering the stream pointer before running it and
1520 resetting it and running it n times. We special case
1521 the repetition of a repeat_data/load_constant
1524 unsigned int iterations ;
1525 uint8e_type *start ;
1526 next_byte(&(ieee->h));
1527 iterations = must_parse_int(&(ieee->h));
1528 start = ieee->h.input_p;
1529 if (start[0] == (int)ieee_load_constant_bytes_enum &&
1531 while (iterations != 0) {
1532 location_ptr[current_map->pc++] = start[2];
1535 next_byte(&(ieee->h));
1536 next_byte(&(ieee->h));
1537 next_byte(&(ieee->h));
1540 while (iterations != 0) {
1541 ieee->h.input_p = start;
1542 do_one(ieee, current_map, location_ptr,s);
1548 case ieee_load_constant_bytes_enum:
1549 case ieee_load_with_relocation_enum:
1551 do_one(ieee, current_map, location_ptr,s);
1562 DEFUN(ieee_new_section_hook,(abfd, newsect),
1566 newsect->used_by_bfd = (PTR)
1567 bfd_alloc(abfd, sizeof(ieee_per_section_type));
1568 ieee_per_section( newsect)->data = (bfd_byte *)NULL;
1569 ieee_per_section(newsect)->section = newsect;
1575 DEFUN(ieee_get_reloc_upper_bound,(abfd, asect),
1579 ieee_slurp_section_data(abfd);
1580 return (asect->reloc_count+1) * sizeof(arelent *);
1584 DEFUN(ieee_get_section_contents,(abfd, section, location, offset, count),
1589 bfd_size_type count)
1591 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1592 ieee_slurp_section_data(abfd);
1593 (void) memcpy((PTR)location, (PTR)(p->data + offset), (unsigned)count);
1599 DEFUN(ieee_canonicalize_reloc,(abfd, section, relptr, symbols),
1602 arelent **relptr AND
1605 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1606 ieee_reloc_type *src = (ieee_reloc_type *)(section->relocation);
1607 ieee_data_type *ieee = IEEE_DATA(abfd);
1609 while (src != (ieee_reloc_type *)NULL) {
1610 /* Work out which symbol to attach it this reloc to */
1611 switch (src->symbol.letter) {
1613 src->relent.sym_ptr_ptr =
1614 symbols + src->symbol.index + ieee->external_reference_base_offset;
1617 src->relent.sym_ptr_ptr =
1618 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
1624 *relptr++ = &src->relent;
1627 *relptr = (arelent *)NULL;
1628 return section->reloc_count;
1634 DEFUN(comp,(ap, bp),
1638 arelent *a = *((arelent **)ap);
1639 arelent *b = *((arelent **)bp);
1640 return a->address - b->address;
1644 Write the section headers
1648 DEFUN(ieee_write_section_part,(abfd),
1651 ieee_data_type *ieee = IEEE_DATA(abfd);
1653 ieee->w.r.section_part = bfd_tell(abfd);
1654 for (s = abfd->sections; s != (asection *)NULL; s=s->next) {
1655 if (s != &bfd_abs_section)
1658 ieee_write_byte(abfd, ieee_section_type_enum);
1659 ieee_write_byte(abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1661 if (abfd->flags & EXEC_P)
1663 /* This image is executable, so output absolute sections */
1664 ieee_write_byte(abfd, ieee_variable_A_enum);
1665 ieee_write_byte(abfd, ieee_variable_S_enum);
1669 ieee_write_byte(abfd, ieee_variable_C_enum);
1672 switch (s->flags &(SEC_CODE | SEC_DATA | SEC_ROM))
1674 case SEC_CODE | SEC_LOAD:
1676 ieee_write_byte(abfd, ieee_variable_P_enum);
1680 ieee_write_byte(abfd, ieee_variable_D_enum);
1683 case SEC_ROM | SEC_DATA:
1684 case SEC_ROM | SEC_LOAD:
1685 case SEC_ROM | SEC_DATA | SEC_LOAD:
1687 ieee_write_byte(abfd, ieee_variable_R_enum);
1691 ieee_write_id(abfd, s->name);
1693 ieee_write_int(abfd, 0); /* Parent */
1694 ieee_write_int(abfd, 0); /* Brother */
1695 ieee_write_int(abfd, 0); /* Context */
1698 ieee_write_byte(abfd, ieee_section_alignment_enum);
1699 ieee_write_byte(abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1700 ieee_write_int(abfd, 1 << s->alignment_power);
1703 ieee_write_2bytes(abfd, ieee_section_size_enum);
1704 ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
1705 ieee_write_int(abfd, s->_raw_size);
1706 if (abfd->flags & EXEC_P) {
1707 /* Relocateable sections don't have asl records */
1709 ieee_write_2bytes(abfd, ieee_section_base_address_enum);
1710 ieee_write_byte(abfd,
1711 (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
1712 ieee_write_int(abfd, s->vma);
1722 DEFUN(do_with_relocs,(abfd, s),
1726 unsigned int relocs_to_go = s->reloc_count;
1729 bfd_byte *stream = ieee_per_section(s)->data;
1730 arelent **p = s->orelocation;
1732 bfd_size_type current_byte_index = 0;
1734 qsort(s->orelocation,
1739 /* Output the section preheader */
1740 ieee_write_byte(abfd, ieee_set_current_section_enum);
1741 ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
1743 ieee_write_twobyte(abfd, ieee_set_current_pc_enum);
1744 ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
1745 ieee_write_expression(abfd, 0, s->symbol, 0, 0);
1747 if (relocs_to_go == 0)
1749 /* If there arn't any relocations then output the load constant byte
1750 opcode rather than the load with relocation opcode */
1752 while (current_byte_index < s->_raw_size) {
1754 unsigned int MAXRUN = 32;
1756 if (run > s->_raw_size - current_byte_index) {
1757 run = s->_raw_size - current_byte_index;
1761 ieee_write_byte(abfd, ieee_load_constant_bytes_enum);
1762 /* Output a stream of bytes */
1763 ieee_write_int(abfd, run);
1764 bfd_write((PTR)(stream + current_byte_index),
1768 current_byte_index += run;
1774 ieee_write_byte(abfd, ieee_load_with_relocation_enum);
1777 /* Output the data stream as the longest sequence of bytes
1778 possible, allowing for the a reasonable packet size and
1779 relocation stuffs */
1781 if ((PTR)stream == (PTR)NULL) {
1782 /* Outputting a section without data, fill it up */
1783 stream = (uint8e_type *)(bfd_alloc(abfd, s->_raw_size));
1784 memset((PTR)stream, 0, s->_raw_size);
1786 while (current_byte_index < s->_raw_size) {
1788 unsigned int MAXRUN = 32;
1790 run = (*p)->address - current_byte_index;
1795 if (run > s->_raw_size - current_byte_index) {
1796 run = s->_raw_size - current_byte_index;
1800 /* Output a stream of bytes */
1801 ieee_write_int(abfd, run);
1802 bfd_write((PTR)(stream + current_byte_index),
1806 current_byte_index += run;
1808 /* Output any relocations here */
1809 if (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
1810 while (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
1816 if (r->howto->pc_relative) {
1817 r->addend += current_byte_index ;
1821 switch (r->howto->size) {
1824 ov = bfd_get_32(abfd,
1825 stream+current_byte_index);
1826 current_byte_index +=4;
1829 ov = bfd_get_16(abfd,
1830 stream+current_byte_index);
1831 current_byte_index +=2;
1834 ov = bfd_get_8(abfd,
1835 stream+current_byte_index);
1836 current_byte_index ++;
1842 ieee_write_byte(abfd, ieee_function_either_open_b_enum);
1845 if (r->sym_ptr_ptr != (asymbol **)NULL) {
1846 ieee_write_expression(abfd, r->addend + ov,
1848 r->howto->pc_relative, s->index);
1851 ieee_write_expression(abfd, r->addend + ov,
1853 r->howto->pc_relative, s->index);
1856 if (1 || r->howto->size != 2) {
1857 ieee_write_byte(abfd, ieee_comma);
1858 ieee_write_int(abfd, 1<< r->howto->size);
1860 ieee_write_byte(abfd,
1861 ieee_function_either_close_b_enum);
1872 /* If there are no relocations in the output section then we can
1873 be clever about how we write. We block items up into a max of 127
1877 DEFUN(do_as_repeat, (abfd, s),
1882 ieee_write_byte(abfd, ieee_set_current_section_enum);
1883 ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
1884 ieee_write_byte(abfd, ieee_set_current_pc_enum >> 8);
1885 ieee_write_byte(abfd, ieee_set_current_pc_enum & 0xff);
1886 ieee_write_byte(abfd, (bfd_byte)(s->index + IEEE_SECTION_NUMBER_BASE));
1887 ieee_write_int(abfd, s->vma );
1889 ieee_write_byte(abfd,ieee_repeat_data_enum);
1890 ieee_write_int(abfd, s->_raw_size);
1891 ieee_write_byte(abfd, ieee_load_constant_bytes_enum);
1892 ieee_write_byte(abfd, 1);
1893 ieee_write_byte(abfd, 0);
1898 DEFUN(do_without_relocs, (abfd, s),
1902 bfd_byte *stream = ieee_per_section(s)->data;
1904 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
1906 do_as_repeat(abfd, s);
1911 for (i = 0; i < s->_raw_size; i++) {
1912 if (stream[i] != 0) {
1913 do_with_relocs(abfd, s);
1917 do_as_repeat(abfd, s);
1923 static unsigned char *output_ptr_start;
1924 static unsigned char *output_ptr;
1925 static unsigned char *output_ptr_end;
1926 static unsigned char *input_ptr_start;
1927 static unsigned char *input_ptr;
1928 static unsigned char *input_ptr_end;
1929 static bfd *input_bfd;
1930 static bfd *output_bfd;
1931 static int output_buffer;
1935 bfd_read((PTR)input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
1936 input_ptr = input_ptr_start;
1940 bfd_write((PTR)(output_ptr_start),1,output_ptr - output_ptr_start, output_bfd);
1941 output_ptr = output_ptr_start;
1945 #define THIS() ( *input_ptr )
1946 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
1947 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
1949 static void write_int(value)
1952 if (value >= 0 && value <= 127) {
1956 unsigned int length;
1957 /* How many significant bytes ? */
1958 /* FIXME FOR LONGER INTS */
1959 if (value & 0xff000000) {
1962 else if (value & 0x00ff0000) {
1965 else if (value & 0x0000ff00) {
1970 OUT((int)ieee_number_repeat_start_enum + length);
1984 static void copy_id()
1986 int length = THIS();
1996 #define VAR(x) ((x | 0x80))
1997 static void copy_expression()
2006 value = THIS(); NEXT();
2007 value = (value << 8) | THIS(); NEXT();
2008 value = (value << 8) | THIS(); NEXT();
2009 value = (value << 8) | THIS(); NEXT();
2014 value = THIS(); NEXT();
2015 value = (value << 8) | THIS(); NEXT();
2016 value = (value << 8) | THIS(); NEXT();
2021 value = THIS(); NEXT();
2022 value = (value << 8) | THIS(); NEXT();
2027 value = THIS(); NEXT();
2036 /* Not a number, just bug out with the answer */
2037 write_int(*(--tos));
2047 int value = *(--tos);
2055 int section_number ;
2056 ieee_data_type *ieee;
2059 section_number = THIS();
2062 ieee= IEEE_DATA(input_bfd);
2063 s = ieee->section_table[section_number];
2064 if (s->output_section) {
2065 value = s->output_section->vma ;
2066 } else { value = 0; }
2067 value += s->output_offset;
2075 write_int(*(--tos));
2085 /* Drop the int in the buffer, and copy a null into the gap, which we
2086 will overwrite later */
2088 struct output_buffer_struct {
2089 unsigned char *ptrp;
2094 DEFUN(fill_int,(buf),
2095 struct output_buffer_struct *buf)
2097 if (buf->buffer == output_buffer) {
2098 /* Still a chance to output the size */
2099 int value = output_ptr - buf->ptrp + 3;
2100 buf->ptrp[0] = value >> 24;
2101 buf->ptrp[1] = value >> 16;
2102 buf->ptrp[2] = value >> 8;
2103 buf->ptrp[3] = value >> 0;
2108 DEFUN(drop_int,(buf),
2109 struct output_buffer_struct *buf)
2116 case 0x84: ch = THIS(); NEXT();
2117 case 0x83: ch = THIS(); NEXT();
2118 case 0x82: ch = THIS(); NEXT();
2119 case 0x81: ch = THIS(); NEXT();
2124 buf->ptrp = output_ptr;
2125 buf->buffer = output_buffer;
2126 OUT(0);OUT(0);OUT(0);OUT(0);
2129 static void copy_int()
2137 case 0x84: ch = THIS(); NEXT(); OUT(ch);
2138 case 0x83: ch = THIS(); NEXT(); OUT(ch);
2139 case 0x82: ch = THIS(); NEXT(); OUT(ch);
2140 case 0x81: ch = THIS(); NEXT(); OUT(ch);
2146 #define ID copy_id()
2147 #define INT copy_int()
2148 #define EXP copy_expression()
2149 static void copy_till_end();
2150 #define INTn(q) copy_int()
2151 #define EXPn(q) copy_expression()
2152 static void f1_record()
2165 OUT(0xf1); OUT(0xc9);
2166 INT; INT; ch = THIS();
2169 case 0x16: NEXT();break;
2170 case 0x01: NEXT();break;
2171 case 0x00: NEXT(); INT; break;
2172 case 0x03: NEXT(); INT; break;
2173 case 0x13: EXPn(instruction address); break;
2181 OUT(0xf1); OUT(0xd8);
2182 EXP ; EXP; EXP; EXP;
2186 OUT(0xf1);OUT(0xce); INT; INT; ch = THIS(); INT;
2193 EXPn(external function); break;
2196 case 0x07: INTn(line number); INT;
2198 case 0x0a: INTn(locked register); INT; break;
2199 case 0x3f: copy_till_end(); break;
2200 case 0x3e: copy_till_end(); break;
2201 case 0x40: copy_till_end(); break;
2202 case 0x41: ID; break;
2207 static void f0_record()
2209 /* Attribute record */
2215 static void copy_till_end()
2250 static void f2_record()
2262 static void block();
2263 static void f8_record()
2273 /* Unique typedefs for module */
2274 /* GLobal typedefs */
2275 /* High level module scope beginning */
2277 struct output_buffer_struct ob;
2290 /* Global function */
2292 struct output_buffer_struct ob;
2294 OUT(0xf8); OUT(0x04);
2295 drop_int(&ob); ID ; INTn(stack size); INTn(ret val);
2302 EXPn(size of block);
2308 /* File name for source line numbers */
2310 struct output_buffer_struct ob;
2312 OUT(0xf8); OUT(0x05);
2314 ID; INTn(year); INTn(month); INTn(day);
2315 INTn(hour); INTn(monute); INTn(second);
2324 /* Local function */
2325 { struct output_buffer_struct ob;
2326 NEXT(); OUT(0xf8); OUT(0x06);
2328 ID; INTn(stack size); INTn(type return);
2339 /* Assembler module scope beginning -*/
2340 { struct output_buffer_struct ob;
2343 OUT(0xf8); OUT(0x0a);
2345 ID; ID; INT; ID; INT; INT; INT; INT; INT; INT;
2356 struct output_buffer_struct ob;
2358 OUT(0xf8); OUT(0x0b);
2359 drop_int(&ob); ID ; INT; INTn(section index); EXPn(offset); INTn(stuff);
2372 static void e2_record()
2382 static void DEFUN_VOID(block)
2416 moves all the debug information from the source bfd to the output
2417 bfd, and relocates any expressions it finds
2421 DEFUN(relocate_debug,(output, input),
2427 unsigned char input_buffer[IBS];
2429 input_ptr_start = input_ptr = input_buffer;
2430 input_ptr_end = input_buffer + IBS;
2432 bfd_read((PTR)input_ptr_start, 1, IBS, input);
2436 During linking, we we told about the bfds which made up our
2437 contents, we have a list of them. They will still be open, so go to
2438 the debug info in each, and copy it out, relocating it as we go.
2442 DEFUN(ieee_write_debug_part, (abfd),
2445 ieee_data_type *ieee = IEEE_DATA(abfd);
2446 bfd_chain_type *chain = ieee->chain_root;
2447 unsigned char output_buffer[OBS];
2448 boolean some_debug = false;
2449 file_ptr here = bfd_tell(abfd);
2451 output_ptr_start = output_ptr = output_buffer ;
2452 output_ptr_end = output_buffer + OBS;
2453 output_ptr = output_buffer;
2456 if (chain == (bfd_chain_type *)NULL) {
2458 /* There is no debug info, so we'll fake some up */
2459 CONST static char fake[] = {
2460 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
2461 '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 };
2462 ieee->w.r.debug_information_part = 0;
2468 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2469 /* Now write a header for each section */
2472 asection *s = abfd->sections;
2474 if (s != abfd->abs_section)
2477 ieee_write_byte(abfd, 0xf8);
2478 ieee_write_byte(abfd, 0x0b);
2479 ieee_write_byte(abfd, 0);
2480 ieee_write_byte(abfd, 0);
2481 ieee_write_byte(abfd, 1);
2482 ieee_write_byte(abfd, i + IEEE_SECTION_NUMBER_BASE);
2483 ieee_write_expression(abfd, 0, s->symbol, 0, 0, 0);
2484 ieee_write_byte(abfd,0);
2485 ieee_write_byte(abfd, 0xf9);
2486 ieee_write_expression(abfd, s->size,
2487 bfd_abs_section.symbol, 0, 0, 0);
2494 /* Close the scope */
2495 ieee_write_byte(abfd, 0xf9);
2500 while (chain != (bfd_chain_type *)NULL) {
2501 bfd *entry = chain->this;
2502 ieee_data_type *entry_ieee = IEEE_DATA(entry);
2503 if (entry_ieee->w.r.debug_information_part) {
2504 bfd_seek(entry, entry_ieee->w.r.debug_information_part, SEEK_SET);
2505 relocate_debug(abfd, entry);
2508 chain = chain->next;
2511 ieee->w.r.debug_information_part = here;
2514 ieee->w.r.debug_information_part = 0;
2520 /* write the data in an ieee way */
2522 DEFUN(ieee_write_data_part,(abfd),
2526 ieee_data_type *ieee = IEEE_DATA(abfd);
2527 ieee->w.r.data_part = bfd_tell(abfd);
2528 for (s = abfd->sections; s != (asection *)NULL; s = s->next)
2530 /* Sort the reloc records so we can insert them in the correct
2532 if (s->reloc_count != 0)
2534 do_with_relocs(abfd, s);
2538 do_without_relocs(abfd, s);
2546 DEFUN(init_for_output,(abfd),
2550 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
2551 if (s->_raw_size != 0) {
2552 ieee_per_section(s)->data = (bfd_byte *)(bfd_alloc(abfd, s->_raw_size));
2557 /** exec and core file sections */
2559 /* set section contents is complicated with IEEE since the format is
2560 * not a byte image, but a record stream.
2563 DEFUN(ieee_set_section_contents,(abfd, section, location, offset, count),
2568 bfd_size_type count)
2570 if (ieee_per_section(section)->data == (bfd_byte *)NULL) {
2571 init_for_output(abfd);
2573 (void) memcpy((PTR)(ieee_per_section(section)->data + offset),
2575 (unsigned int)count);
2580 write the external symbols of a file, IEEE considers two sorts of
2581 external symbols, public, and referenced. It uses to internal forms
2582 to index them as well. When we write them out we turn their symbol
2583 values into indexes from the right base.
2586 DEFUN(ieee_write_external_part,(abfd),
2590 ieee_data_type *ieee = IEEE_DATA(abfd);
2592 unsigned int reference_index = IEEE_REFERENCE_BASE;
2593 unsigned int public_index = IEEE_PUBLIC_BASE+2;
2594 file_ptr here = bfd_tell(abfd);
2595 boolean hadone = false;
2596 if (abfd->outsymbols != (asymbol **)NULL) {
2598 for (q = abfd->outsymbols; *q != (asymbol *)NULL; q++) {
2601 if (p->section == &bfd_und_section) {
2602 /* This must be a symbol reference .. */
2603 ieee_write_byte(abfd, ieee_external_reference_enum);
2604 ieee_write_int(abfd, reference_index);
2605 ieee_write_id(abfd, p->name);
2606 p->value = reference_index;
2609 else if (bfd_is_com_section (p->section)) {
2610 /* This is a weak reference */
2611 ieee_write_byte(abfd, ieee_external_reference_enum);
2612 ieee_write_int(abfd, reference_index);
2613 ieee_write_id(abfd, p->name);
2614 ieee_write_byte(abfd, ieee_weak_external_reference_enum);
2615 ieee_write_int(abfd, reference_index);
2616 ieee_write_int(abfd, p->value);
2617 ieee_write_int(abfd, BFD_FORT_COMM_DEFAULT_VALUE);
2618 p->value = reference_index;
2621 else if(p->flags & BSF_GLOBAL) {
2622 /* This must be a symbol definition */
2625 ieee_write_byte(abfd, ieee_external_symbol_enum);
2626 ieee_write_int(abfd, public_index );
2627 ieee_write_id(abfd, p->name);
2629 ieee_write_twobyte(abfd, ieee_attribute_record_enum);
2630 ieee_write_int(abfd, public_index );
2631 ieee_write_byte(abfd, 15); /* instruction address */
2632 ieee_write_byte(abfd, 19); /* static symbol */
2633 ieee_write_byte(abfd, 1); /* one of them */
2636 /* Write out the value */
2637 ieee_write_2bytes(abfd, ieee_value_record_enum);
2638 ieee_write_int(abfd, public_index);
2639 if (p->section != &bfd_abs_section)
2641 if (abfd->flags & EXEC_P)
2643 /* If fully linked, then output all symbols
2645 ieee_write_int(abfd,
2646 p->value + p->section->output_offset+ p->section->output_section->vma);
2650 ieee_write_expression(abfd,
2651 p->value + p->section->output_offset,
2652 p->section->output_section->symbol
2658 ieee_write_expression(abfd,
2660 bfd_abs_section.symbol,
2663 p->value = public_index;
2667 /* This can happen - when there are gaps in the symbols read */
2668 /* from an input ieee file */
2673 ieee->w.r.external_part = here;
2678 static CONST unsigned char exten[] =
2681 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
2682 0xf1, 0xce, 0x20, 0x00, 39, 2, /* keep symbol in original case */
2683 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
2686 static CONST unsigned char envi[] =
2690 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
2693 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
2695 0xf1, 0xce, 0x21, 0, 53, 0x03, /* host unix */
2696 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
2701 DEFUN(ieee_write_me_part,(abfd),
2704 ieee_data_type *ieee= IEEE_DATA(abfd);
2705 ieee->w.r.trailer_part = bfd_tell(abfd);
2706 if (abfd->start_address) {
2707 ieee->w.r.me_record = bfd_tell(abfd);
2708 ieee_write_2bytes(abfd, ieee_value_starting_address_enum);
2709 ieee_write_byte(abfd, ieee_function_either_open_b_enum);
2710 ieee_write_int(abfd, abfd->start_address);
2711 ieee_write_byte(abfd, ieee_function_either_close_b_enum);
2714 ieee->w.r.me_record = bfd_tell(abfd);
2716 ieee_write_byte(abfd, ieee_module_end_enum);
2720 DEFUN(ieee_write_object_contents,(abfd),
2723 ieee_data_type *ieee = IEEE_DATA(abfd);
2726 /* Fast forward over the header area */
2727 bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
2728 ieee_write_byte(abfd, ieee_module_beginning_enum);
2730 ieee_write_id(abfd, bfd_printable_name(abfd));
2731 ieee_write_id(abfd, abfd->filename);
2733 /* Fast forward over the variable bits */
2734 ieee_write_byte(abfd, ieee_address_descriptor_enum);
2737 ieee_write_byte(abfd, (bfd_byte) (bfd_arch_bits_per_byte(abfd)));
2738 /* MAU's per address */
2739 ieee_write_byte(abfd,
2740 (bfd_byte) (bfd_arch_bits_per_address(abfd) / bfd_arch_bits_per_byte(abfd)));
2742 old = bfd_tell(abfd);
2743 bfd_seek(abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR);
2745 ieee->w.r.extension_record = bfd_tell(abfd);
2746 bfd_write((char *)exten, 1, sizeof(exten), abfd);
2747 if (abfd->flags & EXEC_P)
2748 ieee_write_byte(abfd, 0x1); /* Absolute */
2750 ieee_write_byte(abfd, 0x2); /* Relocateable */
2752 ieee->w.r.environmental_record = bfd_tell(abfd);
2753 bfd_write((char *)envi, 1, sizeof(envi), abfd);
2757 ieee_write_section_part(abfd);
2759 First write the symbols, this changes their values into table
2760 indeces so we cant use it after this point
2762 ieee_write_external_part(abfd);
2763 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
2766 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
2770 Write any debugs we have been told about
2772 ieee_write_debug_part(abfd);
2775 Can only write the data once the symbols have been written since
2776 the data contains relocation information which points to the
2779 ieee_write_data_part(abfd);
2783 At the end we put the end !
2785 ieee_write_me_part(abfd);
2788 /* Generate the header */
2789 bfd_seek(abfd, old, SEEK_SET);
2791 for (i= 0; i < N_W_VARIABLES; i++) {
2792 ieee_write_2bytes(abfd,ieee_assign_value_to_variable_enum);
2793 ieee_write_byte(abfd, (bfd_byte) i);
2794 ieee_write_int5_out(abfd, ieee->w.offset[i]);
2802 /* Native-level interface to symbols. */
2804 /* We read the symbols into a buffer, which is discarded when this
2805 function exits. We read the strings into a buffer large enough to
2806 hold them all plus all the cached symbol entries. */
2809 DEFUN(ieee_make_empty_symbol,(abfd),
2813 ieee_symbol_type *new =
2814 (ieee_symbol_type *)zalloc (sizeof (ieee_symbol_type));
2815 new->symbol.the_bfd = abfd;
2816 return &new->symbol;
2821 DEFUN(ieee_openr_next_archived_file,(arch, prev),
2825 ieee_ar_data_type *ar = IEEE_AR_DATA(arch);
2826 /* take the next one from the arch state, or reset */
2827 if (prev == (bfd *)NULL) {
2828 /* Reset the index - the first two entries are bogus*/
2829 ar->element_index = 2;
2832 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
2833 ar->element_index++;
2834 if (ar->element_index <= ar->element_count) {
2835 if (p->file_offset != (file_ptr)0) {
2836 if (p->abfd == (bfd *)NULL) {
2837 p->abfd = _bfd_create_empty_archive_element_shell(arch);
2838 p->abfd->origin = p->file_offset;
2844 bfd_error = no_more_archived_files;
2852 ieee_find_nearest_line(abfd,
2863 char **filename_ptr;
2864 char **functionname_ptr;
2872 ieee_generic_stat_arch_elt(abfd, buf)
2876 ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
2877 if (ar == (ieee_ar_data_type *)NULL) {
2878 bfd_error = invalid_operation;
2883 buf->st_mode = 0666;
2884 return ! ieee_object_p(abfd);
2888 DEFUN(ieee_sizeof_headers,(abfd, x),
2898 DEFUN(ieee_bfd_debug_info_start,(abfd),
2905 DEFUN(ieee_bfd_debug_info_end,(abfd),
2912 /* Add this section to the list of sections we have debug info for, to
2913 be ready to output it at close time
2916 DEFUN(ieee_bfd_debug_info_accumulate,(abfd, section),
2920 ieee_data_type *ieee = IEEE_DATA(section->owner);
2921 ieee_data_type *output_ieee = IEEE_DATA(abfd);
2922 /* can only accumulate data from other ieee bfds */
2923 if (section->owner->xvec != abfd->xvec)
2925 /* Only bother once per bfd */
2926 if (ieee->done_debug == true)
2928 ieee->done_debug = true;
2930 /* Don't bother if there is no debug info */
2931 if (ieee->w.r.debug_information_part == 0)
2937 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc(abfd, sizeof(bfd_chain_type));
2938 n->this = section->owner;
2939 n->next = (bfd_chain_type *)NULL;
2941 if (output_ieee->chain_head) {
2942 output_ieee->chain_head->next = n;
2945 output_ieee->chain_root = n;
2948 output_ieee->chain_head = n;
2958 #define ieee_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
2959 #define ieee_core_file_failing_signal (int (*)())bfd_0
2960 #define ieee_core_file_matches_executable_p ( FOO(boolean, (*),(bfd *, bfd *)))bfd_false
2961 #define ieee_slurp_armap bfd_true
2962 #define ieee_slurp_extended_name_table bfd_true
2963 #define ieee_truncate_arname (void (*)())bfd_nullvoidptr
2964 #define ieee_write_armap (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, unsigned int, int))) bfd_nullvoidptr
2965 #define ieee_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
2966 #define ieee_close_and_cleanup bfd_generic_close_and_cleanup
2967 #define ieee_set_arch_mach bfd_default_set_arch_mach
2968 #define ieee_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
2969 #define ieee_bfd_relax_section bfd_generic_relax_section
2970 #define ieee_bfd_seclet_link bfd_generic_seclet_link
2971 #define ieee_bfd_reloc_type_lookup \
2972 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
2973 #define ieee_bfd_make_debug_symbol \
2974 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
2977 bfd_target ieee_vec =
2980 bfd_target_ieee_flavour,
2981 true, /* target byte order */
2982 true, /* target headers byte order */
2983 (HAS_RELOC | EXEC_P | /* object flags */
2984 HAS_LINENO | HAS_DEBUG |
2985 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2986 ( SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
2987 |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2988 0, /* leading underscore */
2989 ' ', /* ar_pad_char */
2990 16, /* ar_max_namelen */
2991 1, /* minimum alignment */
2992 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
2993 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
2995 { _bfd_dummy_target,
2996 ieee_object_p, /* bfd_check_format */
3003 _bfd_generic_mkarchive,
3008 ieee_write_object_contents,
3009 _bfd_write_archive_contents,