1 /* bfd back-end for ieee-695 objects.
2 Copyright (C) 1990-1991 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 /* IEEE 695 format is a stream of records, which we parse using a simple one-
22 token (which is one byte in this lexicon) lookahead recursive decent
31 /* Functions for writing to ieee files in the strange way that the
35 DEFUN(ieee_write_byte,(abfd, byte),
39 bfd_write((PTR)&byte, 1, 1, abfd);
44 DEFUN(ieee_write_twobyte,(abfd, twobyte),
49 b[1] = twobyte & 0xff;
51 bfd_write((PTR)&b[0], 1, 2, abfd);
57 DEFUN(ieee_write_2bytes,(abfd, bytes),
62 buffer[0] = bytes >> 8;
63 buffer[1] = bytes & 0xff;
65 bfd_write((PTR)buffer, 1, 2, abfd);
69 DEFUN(ieee_write_int,(abfd, value),
73 if (((unsigned)value) <= 127) {
74 ieee_write_byte(abfd, value);
78 /* How many significant bytes ? */
79 /* FIXME FOR LONGER INTS */
80 if (value & 0xff000000) {
83 else if (value & 0x00ff0000) {
86 else if (value & 0x0000ff00) {
91 ieee_write_byte(abfd, (int)ieee_number_repeat_start_enum + length);
94 ieee_write_byte(abfd, value >> 24);
96 ieee_write_byte(abfd, value >> 16);
98 ieee_write_byte(abfd, value >> 8);
100 ieee_write_byte(abfd, value);
106 DEFUN(ieee_write_id,(abfd, id),
110 size_t length = strlen(id);
111 if (length >= 0 && length <= 127) {
112 ieee_write_byte(abfd, length);
114 else if (length < 255) {
115 ieee_write_byte(abfd, ieee_extension_length_1_enum);
116 ieee_write_byte(abfd, length);
118 else if (length < 65535) {
119 ieee_write_byte(abfd, ieee_extension_length_2_enum);
120 ieee_write_byte(abfd, length >> 8);
121 ieee_write_byte(abfd, length & 0xff);
126 bfd_write((PTR)id, 1, length, abfd);
128 /***************************************************************************
129 Functions for reading from ieee files in the strange way that the
134 #define this_byte(ieee) *((ieee)->input_p)
135 #define next_byte(ieee) ((ieee)->input_p++)
136 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
139 static unsigned short
140 DEFUN(read_2bytes,(ieee),
141 common_header_type *ieee)
143 unsigned char c1 = this_byte_and_next(ieee);
144 unsigned char c2 = this_byte_and_next(ieee);
145 return (c1<<8 ) | c2;
150 DEFUN(bfd_get_string,(ieee, string, length),
151 common_header_type *ieee AND
156 for (i= 0; i < length; i++) {
157 string[i] = this_byte_and_next(ieee);
162 DEFUN(read_id,(ieee),
163 common_header_type *ieee)
167 length = this_byte_and_next(ieee);
168 if (length >= 0x00 && length <= 0x7f) {
169 /* Simple string of length 0 to 127 */
171 else if (length == 0xde) {
172 /* Length is next byte, allowing 0..255 */
173 length = this_byte_and_next(ieee);
175 else if (length == 0xdf) {
176 /* Length is next two bytes, allowing 0..65535 */
177 length = this_byte_and_next(ieee) ;
178 length = (length * 256) + this_byte_and_next(ieee);
180 /* Buy memory and read string */
181 string = bfd_alloc(ieee->abfd, length+1);
182 bfd_get_string(ieee, string, length);
188 DEFUN(ieee_write_expression,(abfd, value, symbol, pcrel, index),
195 unsigned int term_count = 0;
199 ieee_write_int(abfd, value);
205 if (symbol->section == &bfd_com_section
206 || symbol->section == &bfd_und_section)
208 /* Def of a common symbol */
209 ieee_write_byte(abfd, ieee_variable_X_enum);
210 ieee_write_int(abfd, symbol->value);
213 else if (symbol->section != &bfd_abs_section)
215 /* Ref to defined symbol - */
217 ieee_write_byte(abfd, ieee_variable_R_enum);
218 ieee_write_byte(abfd, symbol->section->index + IEEE_SECTION_NUMBER_BASE);
220 if (symbol->flags & BSF_GLOBAL)
222 ieee_write_byte(abfd, ieee_variable_I_enum);
223 ieee_write_int(abfd, symbol->value);
226 else if (symbol->flags & ( BSF_LOCAL | BSF_SECTION_SYM))
228 /* This is a reference to a defined local symbol,
229 We can easily do a local as a section+offset */
230 ieee_write_byte(abfd, ieee_variable_R_enum); /* or L */
231 ieee_write_byte(abfd, symbol->section->index +
232 IEEE_SECTION_NUMBER_BASE);
233 ieee_write_int(abfd, symbol->value);
246 /* subtract the pc from here by asking for PC of this section*/
247 ieee_write_byte(abfd, ieee_variable_P_enum);
248 ieee_write_byte(abfd, index +IEEE_SECTION_NUMBER_BASE);
249 ieee_write_byte(abfd, ieee_function_minus_enum);
254 ieee_write_byte(abfd,0);
257 while (term_count > 1) {
258 ieee_write_byte(abfd, ieee_function_plus_enum);
273 /*****************************************************************************/
276 writes any integer into the buffer supplied and always takes 5 bytes
279 DEFUN(ieee_write_int5,(buffer, value),
283 buffer[0] = (bfd_byte)ieee_number_repeat_4_enum;
284 buffer[1] = (value >> 24 ) & 0xff;
285 buffer[2] = (value >> 16 ) & 0xff;
286 buffer[3] = (value >> 8 ) & 0xff;
287 buffer[4] = (value >> 0 ) & 0xff;
290 DEFUN(ieee_write_int5_out, (abfd, value),
295 ieee_write_int5(b, value);
296 bfd_write((PTR)b,1,5,abfd);
301 DEFUN(parse_int,(ieee, value_ptr),
302 common_header_type *ieee AND
305 int value = this_byte(ieee);
307 if (value >= 0 && value <= 127) {
312 else if (value >= 0x80 && value <= 0x88) {
313 unsigned int count = value & 0xf;
317 result =(result << 8) | this_byte_and_next(ieee);
326 DEFUN(parse_i,(ieee, ok),
327 common_header_type *ieee AND
331 *ok = parse_int(ieee, &x);
336 DEFUN(must_parse_int,(ieee),
337 common_header_type *ieee)
340 BFD_ASSERT(parse_int(ieee, &result) == true);
348 ieee_symbol_index_type symbol;
353 reloc_howto_type abs32_howto
354 = HOWTO(1,0,2,32,false,0,false,true,0,"abs32",true,0xffffffff, 0xffffffff,false);
356 reloc_howto_type abs16_howto
357 = HOWTO(1,0,1,16,false,0,false,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false);
360 reloc_howto_type abs8_howto
361 = HOWTO(1,0,0,8,false,0,false,true,0,"abs8",true,0x000000ff, 0x000000ff,false);
364 reloc_howto_type rel32_howto
365 = HOWTO(1,0,2,32,true,0,false,true,0,"rel32",true,0xffffffff, 0xffffffff,true);
367 reloc_howto_type rel16_howto
368 = HOWTO(1,0,1,16,true,0,false,true,0,"rel16",true,0x0000ffff, 0x0000ffff,true);
371 reloc_howto_type rel8_howto
372 = HOWTO(1,0,0,8,true,0,false,true,0,"rel8",true,0x000000ff, 0x000000ff,true);
375 static ieee_symbol_index_type NOSYMBOL = { 0, 0};
379 DEFUN(parse_expression,(ieee, value, symbol, pcrel, extra),
380 ieee_data_type *ieee AND
382 ieee_symbol_index_type *symbol AND
395 ieee_value_type stack[10];
397 /* The stack pointer always points to the next unused location */
398 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
399 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
400 ieee_value_type *sp = stack;
403 switch (this_byte(&(ieee->h)))
405 case ieee_variable_P_enum:
406 /* P variable, current program counter for section n */
409 next_byte(&(ieee->h));
411 section_n = must_parse_int(&(ieee->h));
412 PUSH(NOSYMBOL, &bfd_abs_section,
413 TOS.value = ieee->section_table[section_n]->vma +
414 ieee_per_section(ieee->section_table[section_n])->pc);
417 case ieee_variable_L_enum:
418 /* L variable address of section N */
419 next_byte(&(ieee->h));
420 PUSH(NOSYMBOL,ieee->section_table[must_parse_int(&(ieee->h))],0);
422 case ieee_variable_R_enum:
423 /* R variable, logical address of section module */
424 /* FIXME, this should be different to L */
425 next_byte(&(ieee->h));
426 PUSH(NOSYMBOL,ieee->section_table[must_parse_int(&(ieee->h))],0);
428 case ieee_variable_S_enum:
429 /* S variable, size in MAUS of section module */
430 next_byte(&(ieee->h));
433 ieee->section_table[must_parse_int(&(ieee->h))]->_raw_size);
435 case ieee_variable_I_enum:
436 case ieee_variable_X_enum:
437 /* Push the address of external variable n */
439 ieee_symbol_index_type sy;
440 next_byte(&(ieee->h));
441 sy.index = (int)(must_parse_int(&(ieee->h))) ;
444 PUSH(sy, &bfd_und_section, 0);
447 case ieee_function_minus_enum:
449 bfd_vma value1, value2;
450 asection *section1, *section_dummy;
451 ieee_symbol_index_type sy;
452 next_byte(&(ieee->h));
454 POP(sy, section1, value1);
455 POP(sy, section_dummy, value2);
456 PUSH(sy, section1 ? section1 : section_dummy, value1-value2);
459 case ieee_function_plus_enum:
461 bfd_vma value1, value2;
464 ieee_symbol_index_type sy1;
465 ieee_symbol_index_type sy2;
466 next_byte(&(ieee->h));
468 POP(sy1, section1, value1);
469 POP(sy2, section2, value2);
470 PUSH(sy1.letter ? sy1 : sy2, section1 ? section1: section2, value1+value2);
476 BFD_ASSERT(this_byte(&(ieee->h)) < (int)ieee_variable_A_enum
477 || this_byte(&(ieee->h)) > (int)ieee_variable_Z_enum);
478 if (parse_int(&(ieee->h), &va))
480 PUSH(NOSYMBOL, &bfd_abs_section, va);
484 Thats all that we can understand. As far as I can see
485 there is a bug in the Microtec IEEE output which I'm
486 using to scan, whereby the comma operator is ommited
487 sometimes in an expression, giving expressions with too
488 many terms. We can tell if that's the case by ensuring
489 that sp == stack here. If not, then we've pushed
490 something too far, so we keep adding
493 while (sp != stack+1) {
495 ieee_symbol_index_type sy1;
496 POP(sy1, section1, *extra);
501 POP(*symbol, dummy, *value);
514 #define ieee_seek(abfd, offset) \
515 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
517 #define ieee_pos(abfd) IEEE_DATA(abfd)->h.input_p -IEEE_DATA(abfd)->h.first_byte
519 static unsigned int last_index;
521 static ieee_symbol_type *
522 DEFUN(get_symbol,(abfd,
530 ieee_data_type *ieee AND
531 ieee_symbol_type *last_symbol AND
532 unsigned int *symbol_count AND
533 ieee_symbol_type *** pptr AND
534 unsigned int *max_index
537 /* Need a new symbol */
538 unsigned int new_index = must_parse_int(&(ieee->h));
539 if (new_index != last_index) {
540 ieee_symbol_type * new_symbol = (ieee_symbol_type *)bfd_alloc(ieee->h.abfd,
541 sizeof(ieee_symbol_type));
543 new_symbol->index = new_index;
544 last_index = new_index;
547 *pptr = &new_symbol->next;
548 if (new_index > *max_index) {
549 *max_index = new_index;
556 DEFUN(ieee_slurp_external_symbols,(abfd),
559 ieee_data_type *ieee = IEEE_DATA(abfd);
560 file_ptr offset = ieee->w.r.external_part;
563 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
564 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
565 ieee_symbol_type *symbol = (ieee_symbol_type *)NULL;
566 unsigned int symbol_count = 0;
568 last_index = 0xffffff;
569 ieee->symbol_table_full = true;
571 ieee_seek(abfd, offset );
574 switch (this_byte(&(ieee->h))) {
576 next_byte(&(ieee->h));
577 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
579 &ieee->external_symbol_max_index);
581 symbol->symbol.the_bfd = abfd;
582 symbol->symbol.name = read_id(&(ieee->h));
583 symbol->symbol.udata = (PTR)NULL;
584 symbol->symbol.flags = BSF_NO_FLAGS;
588 case ieee_external_symbol_enum:
589 next_byte(&(ieee->h));
591 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
593 &ieee->external_symbol_max_index);
596 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
598 symbol->symbol.the_bfd = abfd;
599 symbol->symbol.name = read_id(&(ieee->h));
600 symbol->symbol.udata = (PTR)NULL;
601 symbol->symbol.flags = BSF_NO_FLAGS;
603 case ieee_attribute_record_enum >> 8:
605 unsigned int symbol_name_index;
606 unsigned int symbol_type_index;
607 unsigned int symbol_attribute_def;
609 next_byte(&(ieee->h)); /* Skip prefix */
610 next_byte(&(ieee->h));
611 symbol_name_index = must_parse_int(&(ieee->h));
612 symbol_type_index = must_parse_int(&(ieee->h));
613 symbol_attribute_def = must_parse_int(&(ieee->h));
614 switch (symbol_attribute_def) {
616 /* Module misc; followed by two fields which describe the
617 current module block. The first fired is the type id
618 number, the second is the number of asn records
619 associated with the directive */
620 parse_int(&(ieee->h),&value);
621 parse_int(&(ieee->h),&value);
625 parse_int(&(ieee->h),&value);
630 case ieee_value_record_enum >> 8:
632 unsigned int symbol_name_index;
633 ieee_symbol_index_type symbol_ignore;
634 boolean pcrel_ignore;
636 next_byte(&(ieee->h));
637 next_byte(&(ieee->h));
639 symbol_name_index = must_parse_int(&(ieee->h));
640 parse_expression(ieee,
641 &symbol->symbol.value,
642 &symbol->symbol.section,
647 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
651 case ieee_weak_external_reference_enum:
654 next_byte(&(ieee->h));
655 /* Throw away the external reference index */
656 (void)must_parse_int(&(ieee->h));
657 /* Fetch the default size if not resolved */
658 size = must_parse_int(&(ieee->h));
659 /* Fetch the defautlt value if available */
660 if ( parse_int(&(ieee->h), &value) == false) {
663 /* This turns into a common */
664 symbol->symbol.section = &bfd_com_section;
665 symbol->symbol.value = size;
669 case ieee_external_reference_enum:
670 next_byte(&(ieee->h));
672 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
674 &ieee->external_reference_max_index);
677 symbol->symbol.the_bfd = abfd;
678 symbol->symbol.name = read_id(&(ieee->h));
679 symbol->symbol.udata = (PTR)NULL;
680 symbol->symbol.section = &bfd_und_section;
681 symbol->symbol.value = (bfd_vma)0;
682 symbol->symbol.flags = 0;
684 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
692 if (ieee->external_symbol_max_index != 0) {
693 ieee->external_symbol_count =
694 ieee->external_symbol_max_index -
695 ieee->external_symbol_min_index + 1 ;
698 ieee->external_symbol_count = 0;
702 if(ieee->external_reference_max_index != 0) {
703 ieee->external_reference_count =
704 ieee->external_reference_max_index -
705 ieee->external_reference_min_index + 1;
708 ieee->external_reference_count = 0;
712 ieee->external_reference_count + ieee->external_symbol_count;
714 if (symbol_count != abfd->symcount) {
715 /* There are gaps in the table -- */
716 ieee->symbol_table_full = false;
720 *prev_symbols_ptr = (ieee_symbol_type *)NULL;
721 *prev_reference_ptr = (ieee_symbol_type *)NULL;
725 DEFUN(ieee_slurp_symbol_table,(abfd),
728 if (IEEE_DATA(abfd)->read_symbols == false) {
729 ieee_slurp_external_symbols(abfd);
730 IEEE_DATA(abfd)->read_symbols= true;
735 DEFUN(ieee_get_symtab_upper_bound,(abfd),
738 ieee_slurp_symbol_table (abfd);
740 return (abfd->symcount != 0) ?
741 (abfd->symcount+1) * (sizeof (ieee_symbol_type *)) : 0;
745 Move from our internal lists to the canon table, and insert in
749 extern bfd_target ieee_vec;
751 DEFUN(ieee_get_symtab,(abfd, location),
755 ieee_symbol_type *symp;
756 static bfd dummy_bfd;
757 static asymbol empty_symbol =
758 { &dummy_bfd," ieee empty",(symvalue)0,BSF_DEBUGGING , &bfd_abs_section};
760 if (abfd->symcount) {
765 ieee_data_type *ieee = IEEE_DATA(abfd);
766 dummy_bfd.xvec= &ieee_vec;
767 ieee_slurp_symbol_table(abfd);
769 if (ieee->symbol_table_full == false) {
770 /* Arrgh - there are gaps in the table, run through and fill them */
771 /* up with pointers to a null place */
773 for (i= 0; i < abfd->symcount; i++) {
774 location[i] = &empty_symbol;
779 ieee->external_symbol_base_offset= - ieee->external_symbol_min_index;
780 for (symp = IEEE_DATA(abfd)->external_symbols;
781 symp != (ieee_symbol_type *)NULL;
783 /* Place into table at correct index locations */
784 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
788 /* The external refs are indexed in a bit */
789 ieee->external_reference_base_offset =
790 - ieee->external_reference_min_index +ieee->external_symbol_count ;
792 for (symp = IEEE_DATA(abfd)->external_reference;
793 symp != (ieee_symbol_type *)NULL;
795 location[symp->index + ieee->external_reference_base_offset] =
802 location[abfd->symcount] = (asymbol *)NULL;
804 return abfd->symcount;
807 DEFUN(get_section_entry,(abfd, ieee,index),
809 ieee_data_type *ieee AND
812 if (ieee->section_table[index] == (asection *)NULL) {
813 asection *section = bfd_make_section(abfd, " tempname");
814 ieee->section_table[index] = section;
815 section->flags = SEC_NO_FLAGS;
816 section->target_index = index;
817 ieee->section_table[index] = section;
819 return ieee->section_table[index];
823 DEFUN(ieee_slurp_sections,(abfd),
826 ieee_data_type *ieee = IEEE_DATA(abfd);
827 file_ptr offset = ieee->w.r.section_part;
829 asection *section = (asection *)NULL;
832 bfd_byte section_type[3];
833 ieee_seek(abfd, offset);
835 switch (this_byte(&(ieee->h))) {
836 case ieee_section_type_enum:
838 unsigned int section_index ;
839 next_byte(&(ieee->h));
840 section_index = must_parse_int(&(ieee->h));
841 /* Fixme to be nice about a silly number of sections */
842 BFD_ASSERT(section_index < NSECTIONS);
844 section =get_section_entry(abfd, ieee, section_index);
846 section_type[0] = this_byte_and_next(&(ieee->h));
847 switch (section_type[0]) {
849 /* Normal attributes for absolute sections */
850 section_type[1] = this_byte(&(ieee->h));
851 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
852 switch(section_type[1]) {
854 next_byte(&(ieee->h));
855 section_type[2] = this_byte(&(ieee->h));
856 switch (section_type[2])
860 next_byte(&(ieee->h));
861 section->flags |= SEC_LOAD | SEC_CODE;
864 next_byte(&(ieee->h));
865 section->flags |= SEC_LOAD | SEC_DATA;
869 next_byte(&(ieee->h));
870 /* Normal rom data */
871 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
879 section_type[1] = this_byte(&(ieee->h));
880 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
881 switch (section_type[1]) {
884 next_byte(&(ieee->h));
885 section->flags |= SEC_LOAD | SEC_CODE;
888 next_byte(&(ieee->h));
889 section->flags |= SEC_LOAD | SEC_DATA;
893 next_byte(&(ieee->h));
894 /* Normal rom data */
895 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
901 section->name = read_id(&(ieee->h));
902 { bfd_vma parent, brother, context;
903 parse_int(&(ieee->h), &parent);
904 parse_int(&(ieee->h), &brother);
905 parse_int(&(ieee->h), &context);
911 case ieee_section_alignment_enum:
913 unsigned int section_index;
916 next_byte(&(ieee->h));
917 section_index = must_parse_int(&ieee->h);
918 section = get_section_entry(abfd, ieee, section_index);
919 if (section_index > ieee->section_count) {
920 ieee->section_count = section_index;
922 section->alignment_power =
923 bfd_log2(must_parse_int(&ieee->h));
924 (void)parse_int(&(ieee->h), & value);
927 case ieee_e2_first_byte_enum:
929 ieee_record_enum_type t = (ieee_record_enum_type)(read_2bytes(&(ieee->h)));
932 case ieee_section_size_enum:
933 section = ieee->section_table[must_parse_int(&(ieee->h))];
934 section->_raw_size = must_parse_int(&(ieee->h));
936 case ieee_physical_region_size_enum:
937 section = ieee->section_table[must_parse_int(&(ieee->h))];
938 section->_raw_size = must_parse_int(&(ieee->h));
940 case ieee_region_base_address_enum:
941 section = ieee->section_table[must_parse_int(&(ieee->h))];
942 section->vma = must_parse_int(&(ieee->h));
944 case ieee_mau_size_enum:
945 must_parse_int(&(ieee->h));
946 must_parse_int(&(ieee->h));
948 case ieee_m_value_enum:
949 must_parse_int(&(ieee->h));
950 must_parse_int(&(ieee->h));
952 case ieee_section_base_address_enum:
953 section = ieee->section_table[must_parse_int(&(ieee->h))];
954 section->vma = must_parse_int(&(ieee->h));
956 case ieee_section_offset_enum:
957 (void) must_parse_int(&(ieee->h));
958 (void) must_parse_int(&(ieee->h));
972 /***********************************************************************
976 DEFUN(ieee_archive_p,(abfd),
983 uint8e_type buffer[512];
985 int buffer_offset = 0;
986 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
987 ieee_ar_data_type *ieee ;
988 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *)bfd_alloc(abfd, sizeof(ieee_ar_data_type));
989 ieee= IEEE_AR_DATA(abfd);
992 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
994 ieee->h.first_byte = buffer;
995 ieee->h.input_p = buffer;
999 if (this_byte(&(ieee->h)) != Module_Beginning) {
1000 abfd->tdata.ieee_ar_data = save;
1001 return (bfd_target*)NULL;
1005 next_byte(&(ieee->h));
1006 library= read_id(&(ieee->h));
1007 if (strcmp(library , "LIBRARY") != 0) {
1008 bfd_release(abfd, ieee);
1009 abfd->tdata.ieee_ar_data = save;
1010 return (bfd_target *)NULL;
1012 /* Throw away the filename */
1013 free( read_id(&(ieee->h)));
1014 /* This must be an IEEE archive, so we'll buy some space to do
1016 ieee->element_count = 0;
1017 ieee->element_index = 0;
1019 next_byte(&(ieee->h)); /* Drop the ad part */
1020 must_parse_int(&(ieee->h)); /* And the two dummy numbers */
1021 must_parse_int(&(ieee->h));
1024 /* Read the index of the BB table */
1026 ieee_ar_obstack_type t;
1027 int rec =read_2bytes(&(ieee->h));
1028 if (rec ==(int)ieee_assign_value_to_variable_enum) {
1029 int record_number = must_parse_int(&(ieee->h));
1030 t.file_offset = must_parse_int(&(ieee->h));
1031 t.abfd = (bfd *)NULL;
1032 ieee->element_count++;
1033 bfd_alloc_grow(abfd, (PTR)&t, sizeof(t));
1035 /* Make sure that we don't go over the end of the buffer */
1037 if (ieee_pos(abfd) > sizeof(buffer)/2) {
1038 /* Past half way, reseek and reprime */
1039 buffer_offset += ieee_pos(abfd);
1040 bfd_seek(abfd, buffer_offset, SEEK_SET);
1041 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1042 ieee->h.first_byte = buffer;
1043 ieee->h.input_p = buffer;
1049 ieee->elements = (ieee_ar_obstack_type *)bfd_alloc_finish(abfd);
1051 /* Now scan the area again, and replace BB offsets with file */
1055 for (i = 2; i < ieee->element_count; i++) {
1056 bfd_seek(abfd, ieee->elements[i].file_offset, SEEK_SET);
1057 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1058 ieee->h.first_byte = buffer;
1059 ieee->h.input_p = buffer;
1061 next_byte(&(ieee->h)); /* Drop F8 */
1062 next_byte(&(ieee->h)); /* Drop 14 */
1063 must_parse_int(&(ieee->h)); /* Drop size of block */
1064 if (must_parse_int(&(ieee->h)) != 0) {
1065 /* This object has been deleted */
1066 ieee->elements[i].file_offset = 0;
1069 ieee->elements[i].file_offset = must_parse_int(&(ieee->h));
1078 DEFUN(ieee_mkobject,(abfd),
1081 abfd->tdata.ieee_data = (ieee_data_type *)bfd_zalloc(abfd,sizeof(ieee_data_type));
1088 DEFUN(ieee_object_p,(abfd),
1093 ieee_data_type *ieee;
1094 uint8e_type buffer[300];
1095 ieee_data_type *save = IEEE_DATA(abfd);
1096 abfd->tdata.ieee_data = 0;
1097 ieee_mkobject(abfd);
1098 ieee = IEEE_DATA(abfd);
1100 /* Read the first few bytes in to see if it makes sense */
1101 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1103 ieee->h.input_p = buffer;
1104 if (this_byte_and_next(&(ieee->h)) != Module_Beginning) goto fail;
1106 ieee->read_symbols= false;
1107 ieee->read_data= false;
1108 ieee->section_count = 0;
1109 ieee->external_symbol_max_index = 0;
1110 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1111 ieee->external_reference_min_index =IEEE_REFERENCE_BASE;
1112 ieee->external_reference_max_index = 0;
1113 ieee->h.abfd = abfd;
1114 memset((PTR)ieee->section_table, 0, sizeof(ieee->section_table));
1116 processor = ieee->mb.processor = read_id(&(ieee->h));
1117 if (strcmp(processor,"LIBRARY") == 0) goto fail;
1118 ieee->mb.module_name = read_id(&(ieee->h));
1119 if (abfd->filename == (CONST char *)NULL) {
1120 abfd->filename = ieee->mb.module_name;
1122 /* Determine the architecture and machine type of the object file.
1125 bfd_arch_info_type *arch = bfd_scan_arch(processor);
1126 if (arch == 0) goto fail;
1127 abfd->arch_info = arch;
1130 if (this_byte(&(ieee->h)) != (int)ieee_address_descriptor_enum) {
1133 next_byte(&(ieee->h));
1135 if (parse_int(&(ieee->h), &ieee->ad.number_of_bits_mau) == false) {
1138 if(parse_int(&(ieee->h), &ieee->ad.number_of_maus_in_address) == false) {
1142 /* If there is a byte order info, take it */
1143 if (this_byte(&(ieee->h)) == (int)ieee_variable_L_enum ||
1144 this_byte(&(ieee->h)) == (int)ieee_variable_M_enum)
1145 next_byte(&(ieee->h));
1148 for (part = 0; part < N_W_VARIABLES; part++) {
1150 if (read_2bytes(&(ieee->h)) != (int) ieee_assign_value_to_variable_enum) {
1153 if (this_byte_and_next(&(ieee->h)) != part) {
1157 ieee->w.offset[part] = parse_i(&(ieee->h), &ok);
1163 abfd->flags = HAS_SYMS;
1165 /* By now we know that this is a real IEEE file, we're going to read
1166 the whole thing into memory so that we can run up and down it
1167 quickly. We can work out how big the file is from the trailer
1170 IEEE_DATA(abfd)->h.first_byte = (uint8e_type *) bfd_alloc(ieee->h.abfd, ieee->w.r.me_record
1172 bfd_seek(abfd, 0, 0);
1173 bfd_read((PTR)(IEEE_DATA(abfd)->h.first_byte), 1, ieee->w.r.me_record+50, abfd);
1175 ieee_slurp_sections(abfd);
1178 (void) bfd_release(abfd, ieee);
1179 abfd->tdata.ieee_data = save;
1180 return (bfd_target *)NULL;
1185 DEFUN(ieee_print_symbol,(ignore_abfd, afile, symbol, how),
1186 bfd *ignore_abfd AND
1189 bfd_print_symbol_type how)
1191 FILE *file = (FILE *)afile;
1194 case bfd_print_symbol_name:
1195 fprintf(file,"%s", symbol->name);
1197 case bfd_print_symbol_more:
1199 fprintf(file,"%4x %2x",aout_symbol(symbol)->desc & 0xffff,
1200 aout_symbol(symbol)->other & 0xff);
1204 case bfd_print_symbol_nm:
1205 case bfd_print_symbol_all:
1207 CONST char *section_name = symbol->section == (asection *)NULL ?
1208 (CONST char *)"*abs" : symbol->section->name;
1209 if (symbol->name[0] == ' ') {
1210 fprintf(file,"* empty table entry ");
1213 bfd_print_symbol_vandf((PTR)file,symbol);
1215 fprintf(file," %-5s %04x %02x %s",
1217 (unsigned) ieee_symbol(symbol)->index,
1219 aout_symbol(symbol)->desc & 0xffff,
1220 aout_symbol(symbol)->other & 0xff,*/
1230 DEFUN(do_one,(ieee, current_map, location_ptr,s),
1231 ieee_data_type *ieee AND
1232 ieee_per_section_type *current_map AND
1233 uint8e_type *location_ptr AND
1236 switch (this_byte(&(ieee->h)))
1238 case ieee_load_constant_bytes_enum:
1240 unsigned int number_of_maus;
1242 next_byte(&(ieee->h));
1243 number_of_maus = must_parse_int(&(ieee->h));
1245 for (i = 0; i < number_of_maus; i++) {
1246 location_ptr[current_map->pc++]= this_byte(&(ieee->h));
1247 next_byte(&(ieee->h));
1252 case ieee_load_with_relocation_enum:
1254 boolean loop = true;
1255 next_byte(&(ieee->h));
1258 switch (this_byte(&(ieee->h)))
1260 case ieee_variable_R_enum:
1262 case ieee_function_signed_open_b_enum:
1263 case ieee_function_unsigned_open_b_enum:
1264 case ieee_function_either_open_b_enum:
1266 unsigned int extra = 4;
1267 boolean pcrel = false;
1269 ieee_reloc_type *r =
1270 (ieee_reloc_type *) bfd_alloc(ieee->h.abfd,
1271 sizeof(ieee_reloc_type));
1273 *(current_map->reloc_tail_ptr) = r;
1274 current_map->reloc_tail_ptr= &r->next;
1275 r->next = (ieee_reloc_type *)NULL;
1276 next_byte(&(ieee->h));
1279 parse_expression(ieee,
1284 r->relent.address = current_map->pc;
1286 if (r->relent.sym_ptr_ptr == 0) {
1287 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1290 if (this_byte(&(ieee->h)) == (int)ieee_comma) {
1291 next_byte(&(ieee->h));
1292 /* Fetch number of bytes to pad */
1293 extra = must_parse_int(&(ieee->h));
1296 switch (this_byte(&(ieee->h))) {
1297 case ieee_function_signed_close_b_enum:
1298 next_byte(&(ieee->h));
1300 case ieee_function_unsigned_close_b_enum:
1301 next_byte(&(ieee->h));
1303 case ieee_function_either_close_b_enum:
1304 next_byte(&(ieee->h));
1309 /* Build a relocation entry for this type */
1310 /* If pc rel then stick -ve pc into instruction
1311 and take out of reloc ..
1313 I've changed this. It's all too
1314 complicated. I keep 0 in the
1325 #if KEEPMINUSPCININST
1326 bfd_put_32(ieee->h.abfd, -current_map->pc, location_ptr +
1328 r->relent.howto = &rel32_howto;
1332 bfd_put_32(ieee->h.abfd,0, location_ptr +
1334 r->relent.howto = &rel32_howto;
1339 bfd_put_32(ieee->h.abfd, 0, location_ptr +
1341 r->relent.howto = &abs32_howto;
1343 current_map->pc +=4;
1346 if (pcrel == true) {
1347 #if KEEPMINUSPCININST
1348 bfd_put_16(ieee->h.abfd, (int)(-current_map->pc), location_ptr +current_map->pc);
1349 r->relent.addend -= current_map->pc;
1350 r->relent.howto = &rel16_howto;
1353 bfd_put_16(ieee->h.abfd, 0, location_ptr +current_map->pc);
1354 r->relent.howto = &rel16_howto;
1359 bfd_put_16(ieee->h.abfd, 0, location_ptr +current_map->pc);
1360 r->relent.howto = &abs16_howto;
1362 current_map->pc +=2;
1365 if (pcrel == true) {
1366 #if KEEPMINUSPCININST
1367 bfd_put_8(ieee->h.abfd, (int)(-current_map->pc), location_ptr +current_map->pc);
1368 r->relent.addend -= current_map->pc;
1369 r->relent.howto = &rel8_howto;
1371 bfd_put_8(ieee->h.abfd,0, location_ptr +current_map->pc);
1372 r->relent.howto = &rel8_howto;
1376 bfd_put_8(ieee->h.abfd, 0, location_ptr +current_map->pc);
1377 r->relent.howto = &abs8_howto;
1379 current_map->pc +=1;
1391 if (parse_int(&(ieee->h), &this_size) == true) {
1393 for (i = 0; i < this_size; i++) {
1394 location_ptr[current_map->pc ++] = this_byte(&(ieee->h));
1395 next_byte(&(ieee->h));
1408 /* Read in all the section data and relocation stuff too */
1410 DEFUN(ieee_slurp_section_data,(abfd),
1413 bfd_byte *location_ptr = (bfd_byte *)NULL;
1414 ieee_data_type *ieee = IEEE_DATA(abfd);
1415 unsigned int section_number ;
1417 ieee_per_section_type *current_map = (ieee_per_section_type *)NULL;
1419 /* Seek to the start of the data area */
1420 if (ieee->read_data== true) return true;
1421 ieee->read_data = true;
1422 ieee_seek(abfd, ieee->w.r.data_part);
1424 /* Allocate enough space for all the section contents */
1427 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
1428 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1429 per->data = (bfd_byte *) bfd_alloc(ieee->h.abfd, s->_raw_size);
1431 per->reloc_tail_ptr =
1432 (ieee_reloc_type **)&(s->relocation);
1438 switch (this_byte(&(ieee->h)))
1440 /* IF we see anything strange then quit */
1444 case ieee_set_current_section_enum:
1445 next_byte(&(ieee->h));
1446 section_number = must_parse_int(&(ieee->h));
1447 s = ieee->section_table[section_number];
1448 current_map = (ieee_per_section_type *) s->used_by_bfd;
1449 location_ptr = current_map->data - s->vma;
1450 /* The document I have says that Microtec's compilers reset */
1451 /* this after a sec section, even though the standard says not */
1453 current_map->pc =s->vma;
1457 case ieee_e2_first_byte_enum:
1458 next_byte(&(ieee->h));
1459 switch (this_byte(&(ieee->h)))
1461 case ieee_set_current_pc_enum & 0xff:
1465 ieee_symbol_index_type symbol;
1468 next_byte(&(ieee->h));
1469 must_parse_int(&(ieee->h)); /* Thow away section #*/
1470 parse_expression(ieee, &value,
1474 current_map->pc = value;
1475 BFD_ASSERT((unsigned)(value - s->vma) <= s->_raw_size);
1479 case ieee_value_starting_address_enum & 0xff:
1480 /* We've got to the end of the data now - */
1487 case ieee_repeat_data_enum:
1489 /* Repeat the following LD or LR n times - we do this by
1490 remembering the stream pointer before running it and
1491 resetting it and running it n times. We special case
1492 the repetition of a repeat_data/load_constant
1495 unsigned int iterations ;
1496 uint8e_type *start ;
1497 next_byte(&(ieee->h));
1498 iterations = must_parse_int(&(ieee->h));
1499 start = ieee->h.input_p;
1500 if (start[0] == (int)ieee_load_constant_bytes_enum &&
1502 while (iterations != 0) {
1503 location_ptr[current_map->pc++] = start[2];
1506 next_byte(&(ieee->h));
1507 next_byte(&(ieee->h));
1508 next_byte(&(ieee->h));
1511 while (iterations != 0) {
1512 ieee->h.input_p = start;
1513 do_one(ieee, current_map, location_ptr,s);
1519 case ieee_load_constant_bytes_enum:
1520 case ieee_load_with_relocation_enum:
1522 do_one(ieee, current_map, location_ptr,s);
1533 DEFUN(ieee_new_section_hook,(abfd, newsect),
1537 newsect->used_by_bfd = (PTR)
1538 bfd_alloc(abfd, sizeof(ieee_per_section_type));
1539 ieee_per_section( newsect)->data = (bfd_byte *)NULL;
1540 ieee_per_section(newsect)->section = newsect;
1546 DEFUN(ieee_get_reloc_upper_bound,(abfd, asect),
1550 ieee_slurp_section_data(abfd);
1551 return (asect->reloc_count+1) * sizeof(arelent *);
1555 DEFUN(ieee_get_section_contents,(abfd, section, location, offset, count),
1560 bfd_size_type count)
1562 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1563 ieee_slurp_section_data(abfd);
1564 (void) memcpy((PTR)location, (PTR)(p->data + offset), (unsigned)count);
1570 DEFUN(ieee_canonicalize_reloc,(abfd, section, relptr, symbols),
1573 arelent **relptr AND
1576 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1577 ieee_reloc_type *src = (ieee_reloc_type *)(section->relocation);
1578 ieee_data_type *ieee = IEEE_DATA(abfd);
1580 while (src != (ieee_reloc_type *)NULL) {
1581 /* Work out which symbol to attach it this reloc to */
1582 switch (src->symbol.letter) {
1584 src->relent.sym_ptr_ptr =
1585 symbols + src->symbol.index + ieee->external_reference_base_offset;
1588 src->relent.sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
1594 *relptr++ = &src->relent;
1597 *relptr = (arelent *)NULL;
1598 return section->reloc_count;
1604 DEFUN(comp,(ap, bp),
1608 arelent *a = *((arelent **)ap);
1609 arelent *b = *((arelent **)bp);
1610 return a->address - b->address;
1614 Write the section headers
1618 DEFUN(ieee_write_section_part,(abfd),
1621 ieee_data_type *ieee = IEEE_DATA(abfd);
1623 ieee->w.r.section_part = bfd_tell(abfd);
1624 for (s = abfd->sections; s != (asection *)NULL; s=s->next) {
1625 if (s != &bfd_abs_section)
1628 ieee_write_byte(abfd, ieee_section_type_enum);
1629 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1631 if (abfd->flags & EXEC_P)
1633 /* This image is executable, so output absolute sections */
1634 ieee_write_byte(abfd, ieee_variable_A_enum);
1635 ieee_write_byte(abfd, ieee_variable_S_enum);
1639 ieee_write_byte(abfd, ieee_variable_C_enum);
1642 switch (s->flags &(SEC_CODE | SEC_DATA | SEC_ROM))
1644 case SEC_CODE | SEC_LOAD:
1646 ieee_write_byte(abfd, ieee_variable_P_enum);
1650 ieee_write_byte(abfd, ieee_variable_D_enum);
1653 case SEC_ROM | SEC_DATA:
1654 case SEC_ROM | SEC_LOAD:
1655 case SEC_ROM | SEC_DATA | SEC_LOAD:
1657 ieee_write_byte(abfd, ieee_variable_R_enum);
1661 ieee_write_id(abfd, s->name);
1663 ieee_write_int(abfd, 0); /* Parent */
1664 ieee_write_int(abfd, 0); /* Brother */
1665 ieee_write_int(abfd, 0); /* Context */
1668 ieee_write_byte(abfd, ieee_section_alignment_enum);
1669 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1670 ieee_write_int(abfd, 1 << s->alignment_power);
1673 ieee_write_2bytes(abfd, ieee_section_size_enum);
1674 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1675 ieee_write_int(abfd, s->_raw_size);
1676 if (abfd->flags & EXEC_P) {
1677 /* Relocateable sections don't have asl records */
1679 ieee_write_2bytes(abfd, ieee_section_base_address_enum);
1680 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1681 ieee_write_int(abfd, s->vma);
1691 DEFUN(do_with_relocs,(abfd, s),
1695 unsigned int relocs_to_go = s->reloc_count;
1698 bfd_byte *stream = ieee_per_section(s)->data;
1699 arelent **p = s->orelocation;
1701 bfd_size_type current_byte_index = 0;
1703 qsort(s->orelocation,
1708 /* Output the section preheader */
1709 ieee_write_byte(abfd, ieee_set_current_section_enum);
1710 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1712 ieee_write_twobyte(abfd, ieee_set_current_pc_enum);
1713 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1714 ieee_write_expression(abfd, 0, s->symbol, 0, 0);
1716 if (relocs_to_go == 0)
1718 /* If there arn't any relocations then output the load constant byte
1719 opcode rather than the load with relocation opcode */
1721 while (current_byte_index < s->_raw_size) {
1723 unsigned int MAXRUN = 32;
1725 if (run > s->_raw_size - current_byte_index) {
1726 run = s->_raw_size - current_byte_index;
1730 ieee_write_byte(abfd, ieee_load_constant_bytes_enum);
1731 /* Output a stream of bytes */
1732 ieee_write_int(abfd, run);
1733 bfd_write((PTR)(stream + current_byte_index),
1737 current_byte_index += run;
1743 ieee_write_byte(abfd, ieee_load_with_relocation_enum);
1746 /* Output the data stream as the longest sequence of bytes
1747 possible, allowing for the a reasonable packet size and
1748 relocation stuffs */
1750 if ((PTR)stream == (PTR)NULL) {
1751 /* Outputting a section without data, fill it up */
1752 stream = (uint8e_type *)(bfd_alloc(abfd, s->_raw_size));
1753 memset((PTR)stream, 0, s->_raw_size);
1755 while (current_byte_index < s->_raw_size) {
1757 unsigned int MAXRUN = 32;
1759 run = (*p)->address - current_byte_index;
1764 if (run > s->_raw_size - current_byte_index) {
1765 run = s->_raw_size - current_byte_index;
1769 /* Output a stream of bytes */
1770 ieee_write_int(abfd, run);
1771 bfd_write((PTR)(stream + current_byte_index),
1775 current_byte_index += run;
1777 /* Output any relocations here */
1778 if (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
1779 while (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
1785 if (r->howto->pc_relative) {
1786 r->addend += current_byte_index ;
1790 switch (r->howto->size) {
1793 ov = bfd_get_32(abfd,
1794 stream+current_byte_index);
1795 current_byte_index +=4;
1798 ov = bfd_get_16(abfd,
1799 stream+current_byte_index);
1800 current_byte_index +=2;
1803 ov = bfd_get_8(abfd,
1804 stream+current_byte_index);
1805 current_byte_index ++;
1811 ieee_write_byte(abfd, ieee_function_either_open_b_enum);
1814 if (r->sym_ptr_ptr != (asymbol **)NULL) {
1815 ieee_write_expression(abfd, r->addend + ov,
1817 r->howto->pc_relative, s->index);
1820 ieee_write_expression(abfd, r->addend + ov,
1822 r->howto->pc_relative, s->index);
1825 if (1 || r->howto->size != 2) {
1826 ieee_write_byte(abfd, ieee_comma);
1827 ieee_write_int(abfd, 1<< r->howto->size);
1829 ieee_write_byte(abfd,
1830 ieee_function_either_close_b_enum);
1841 /* If there are no relocations in the output section then we can
1842 be clever about how we write. We block items up into a max of 127
1846 DEFUN(do_as_repeat, (abfd, s),
1850 ieee_write_byte(abfd, ieee_set_current_section_enum);
1851 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1852 ieee_write_byte(abfd, ieee_set_current_pc_enum >> 8);
1853 ieee_write_byte(abfd, ieee_set_current_pc_enum & 0xff);
1854 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1855 ieee_write_int(abfd, s->vma );
1857 ieee_write_byte(abfd,ieee_repeat_data_enum);
1858 ieee_write_int(abfd, s->_raw_size);
1859 ieee_write_byte(abfd, ieee_load_constant_bytes_enum);
1860 ieee_write_byte(abfd, 1);
1861 ieee_write_byte(abfd, 0);
1865 DEFUN(do_without_relocs, (abfd, s),
1869 bfd_byte *stream = ieee_per_section(s)->data;
1871 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
1873 do_as_repeat(abfd, s);
1878 for (i = 0; i < s->_raw_size; i++) {
1879 if (stream[i] != 0) {
1880 do_with_relocs(abfd, s);
1884 do_as_repeat(abfd, s);
1890 static unsigned char *output_ptr_start;
1891 static unsigned char *output_ptr;
1892 static unsigned char *output_ptr_end;
1893 static unsigned char *input_ptr_start;
1894 static unsigned char *input_ptr;
1895 static unsigned char *input_ptr_end;
1896 static bfd *input_bfd;
1897 static bfd *output_bfd;
1898 static int output_buffer;
1902 bfd_read((PTR)input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
1903 input_ptr = input_ptr_start;
1907 bfd_write((PTR)(output_ptr_start),1,output_ptr - output_ptr_start, output_bfd);
1908 output_ptr = output_ptr_start;
1912 #define THIS() ( *input_ptr )
1913 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
1914 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
1916 static void write_int(value)
1919 if (value >= 0 && value <= 127) {
1923 unsigned int length;
1924 /* How many significant bytes ? */
1925 /* FIXME FOR LONGER INTS */
1926 if (value & 0xff000000) {
1929 else if (value & 0x00ff0000) {
1932 else if (value & 0x0000ff00) {
1937 OUT((int)ieee_number_repeat_start_enum + length);
1951 static void copy_id()
1953 int length = THIS();
1963 #define VAR(x) ((x | 0x80))
1964 static void copy_expression()
1973 value = THIS(); NEXT();
1974 value = (value << 8) | THIS(); NEXT();
1975 value = (value << 8) | THIS(); NEXT();
1976 value = (value << 8) | THIS(); NEXT();
1981 value = THIS(); NEXT();
1982 value = (value << 8) | THIS(); NEXT();
1983 value = (value << 8) | THIS(); NEXT();
1988 value = THIS(); NEXT();
1989 value = (value << 8) | THIS(); NEXT();
1994 value = THIS(); NEXT();
2003 /* Not a number, just bug out with the answer */
2004 write_int(*(--tos));
2014 int value = *(--tos);
2022 int section_number ;
2023 ieee_data_type *ieee;
2026 section_number = THIS();
2029 ieee= IEEE_DATA(input_bfd);
2030 s = ieee->section_table[section_number];
2031 if (s->output_section) {
2032 value = s->output_section->vma ;
2033 } else { value = 0; }
2034 value += s->output_offset;
2042 write_int(*(--tos));
2052 /* Drop the int in the buffer, and copy a null into the gap, which we
2053 will overwrite later */
2055 struct output_buffer_struct {
2056 unsigned char *ptrp;
2061 DEFUN(fill_int,(buf),
2062 struct output_buffer_struct *buf)
2064 if (buf->buffer == output_buffer) {
2065 /* Still a chance to output the size */
2066 int value = output_ptr - buf->ptrp + 3;
2067 buf->ptrp[0] = value >> 24;
2068 buf->ptrp[1] = value >> 16;
2069 buf->ptrp[2] = value >> 8;
2070 buf->ptrp[3] = value >> 0;
2075 DEFUN(drop_int,(buf),
2076 struct output_buffer_struct *buf)
2083 case 0x84: ch = THIS(); NEXT();
2084 case 0x83: ch = THIS(); NEXT();
2085 case 0x82: ch = THIS(); NEXT();
2086 case 0x81: ch = THIS(); NEXT();
2091 buf->ptrp = output_ptr;
2092 buf->buffer = output_buffer;
2093 OUT(0);OUT(0);OUT(0);OUT(0);
2096 static void copy_int()
2104 case 0x84: ch = THIS(); NEXT(); OUT(ch);
2105 case 0x83: ch = THIS(); NEXT(); OUT(ch);
2106 case 0x82: ch = THIS(); NEXT(); OUT(ch);
2107 case 0x81: ch = THIS(); NEXT(); OUT(ch);
2113 #define ID copy_id()
2114 #define INT copy_int()
2115 #define EXP copy_expression()
2116 static void copy_till_end();
2117 #define INTn(q) copy_int()
2118 #define EXPn(q) copy_expression()
2119 static void f1_record()
2132 OUT(0xf1); OUT(0xc9);
2133 INT; INT; ch = THIS();
2136 case 0x16: NEXT();break;
2137 case 0x01: NEXT();break;
2138 case 0x00: NEXT(); INT; break;
2139 case 0x03: NEXT(); INT; break;
2140 case 0x13: EXPn(instruction address); break;
2148 OUT(0xf1); OUT(0xd8);
2149 EXP ; EXP; EXP; EXP;
2153 OUT(0xf1);OUT(0xce); INT; INT; ch = THIS(); INT;
2160 EXPn(external function); break;
2163 case 0x07: INTn(line number); INT;
2165 case 0x0a: INTn(locked register); INT; break;
2166 case 0x3f: copy_till_end(); break;
2167 case 0x3e: copy_till_end(); break;
2168 case 0x40: copy_till_end(); break;
2169 case 0x41: ID; break;
2174 static void f0_record()
2176 /* Attribute record */
2182 static void copy_till_end()
2217 static void f2_record()
2229 static void block();
2230 static void f8_record()
2240 /* Unique typedefs for module */
2241 /* GLobal typedefs */
2242 /* High level module scope beginning */
2244 struct output_buffer_struct ob;
2257 /* Global function */
2259 struct output_buffer_struct ob;
2261 OUT(0xf8); OUT(0x04);
2262 drop_int(&ob); ID ; INTn(stack size); INTn(ret val);
2269 EXPn(size of block);
2275 /* File name for source line numbers */
2277 struct output_buffer_struct ob;
2279 OUT(0xf8); OUT(0x05);
2281 ID; INTn(year); INTn(month); INTn(day);
2282 INTn(hour); INTn(monute); INTn(second);
2291 /* Local function */
2292 { struct output_buffer_struct ob;
2293 NEXT(); OUT(0xf8); OUT(0x06);
2295 ID; INTn(stack size); INTn(type return);
2306 /* Assembler module scope beginning -*/
2307 { struct output_buffer_struct ob;
2310 OUT(0xf8); OUT(0x0a);
2312 ID; ID; INT; ID; INT; INT; INT; INT; INT; INT;
2323 struct output_buffer_struct ob;
2325 OUT(0xf8); OUT(0x0b);
2326 drop_int(&ob); ID ; INT; INTn(section index); EXPn(offset); INTn(stuff);
2339 static void e2_record()
2349 static void DEFUN_VOID(block)
2383 moves all the debug information from the source bfd to the output
2384 bfd, and relocates any expressions it finds
2388 DEFUN(relocate_debug,(output, input),
2394 unsigned char input_buffer[IBS];
2396 input_ptr_start = input_ptr = input_buffer;
2397 input_ptr_end = input_buffer + IBS;
2399 bfd_read((PTR)input_ptr_start, 1, IBS, input);
2403 During linking, we we told about the bfds which made up our
2404 contents, we have a list of them. They will still be open, so go to
2405 the debug info in each, and copy it out, relocating it as we go.
2409 DEFUN(ieee_write_debug_part, (abfd),
2412 ieee_data_type *ieee = IEEE_DATA(abfd);
2413 bfd_chain_type *chain = ieee->chain_root;
2414 unsigned char output_buffer[OBS];
2415 boolean some_debug = false;
2416 file_ptr here = bfd_tell(abfd);
2418 output_ptr_start = output_ptr = output_buffer ;
2419 output_ptr_end = output_buffer + OBS;
2420 output_ptr = output_buffer;
2423 if (chain == (bfd_chain_type *)NULL) {
2425 /* There is no debug info, so we'll fake some up */
2426 CONST static char fake[] = {
2427 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
2428 '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 };
2429 ieee->w.r.debug_information_part = 0;
2435 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2436 /* Now write a header for each section */
2439 asection *s = abfd->sections;
2441 if (s != abfd->abs_section)
2444 ieee_write_byte(abfd, 0xf8);
2445 ieee_write_byte(abfd, 0x0b);
2446 ieee_write_byte(abfd, 0);
2447 ieee_write_byte(abfd, 0);
2448 ieee_write_byte(abfd, 1);
2449 ieee_write_byte(abfd, i + IEEE_SECTION_NUMBER_BASE);
2450 ieee_write_expression(abfd, 0, s->symbol, 0, 0, 0);
2451 ieee_write_byte(abfd,0);
2452 ieee_write_byte(abfd, 0xf9);
2453 ieee_write_expression(abfd, s->size,
2454 bfd_abs_section.symbol, 0, 0, 0);
2461 /* Close the scope */
2462 ieee_write_byte(abfd, 0xf9);
2467 while (chain != (bfd_chain_type *)NULL) {
2468 bfd *entry = chain->this;
2469 ieee_data_type *entry_ieee = IEEE_DATA(entry);
2470 if (entry_ieee->w.r.debug_information_part) {
2471 bfd_seek(entry, entry_ieee->w.r.debug_information_part, SEEK_SET);
2472 relocate_debug(abfd, entry);
2475 chain = chain->next;
2478 ieee->w.r.debug_information_part = here;
2481 ieee->w.r.debug_information_part = 0;
2487 /* write the data in an ieee way */
2489 DEFUN(ieee_write_data_part,(abfd),
2493 ieee_data_type *ieee = IEEE_DATA(abfd);
2494 ieee->w.r.data_part = bfd_tell(abfd);
2495 for (s = abfd->sections; s != (asection *)NULL; s = s->next)
2497 /* Sort the reloc records so we can insert them in the correct
2499 if (s->reloc_count != 0)
2501 do_with_relocs(abfd, s);
2505 do_without_relocs(abfd, s);
2513 DEFUN(init_for_output,(abfd),
2517 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
2518 if (s->_raw_size != 0) {
2519 ieee_per_section(s)->data = (bfd_byte *)(bfd_alloc(abfd, s->_raw_size));
2524 /** exec and core file sections */
2526 /* set section contents is complicated with IEEE since the format is
2527 * not a byte image, but a record stream.
2530 DEFUN(ieee_set_section_contents,(abfd, section, location, offset, count),
2535 bfd_size_type count)
2537 if (ieee_per_section(section)->data == (bfd_byte *)NULL) {
2538 init_for_output(abfd);
2540 (void) memcpy((PTR)(ieee_per_section(section)->data + offset),
2542 (unsigned int)count);
2547 write the external symbols of a file, IEEE considers two sorts of
2548 external symbols, public, and referenced. It uses to internal forms
2549 to index them as well. When we write them out we turn their symbol
2550 values into indexes from the right base.
2553 DEFUN(ieee_write_external_part,(abfd),
2557 ieee_data_type *ieee = IEEE_DATA(abfd);
2559 unsigned int reference_index = IEEE_REFERENCE_BASE;
2560 unsigned int public_index = IEEE_PUBLIC_BASE+2;
2561 file_ptr here = bfd_tell(abfd);
2562 boolean hadone = false;
2563 if (abfd->outsymbols != (asymbol **)NULL) {
2565 for (q = abfd->outsymbols; *q != (asymbol *)NULL; q++) {
2568 if (p->section == &bfd_und_section) {
2569 /* This must be a symbol reference .. */
2570 ieee_write_byte(abfd, ieee_external_reference_enum);
2571 ieee_write_int(abfd, reference_index);
2572 ieee_write_id(abfd, p->name);
2573 p->value = reference_index;
2576 else if(p->section == &bfd_com_section) {
2577 /* This is a weak reference */
2578 ieee_write_byte(abfd, ieee_external_reference_enum);
2579 ieee_write_int(abfd, reference_index);
2580 ieee_write_id(abfd, p->name);
2581 ieee_write_byte(abfd, ieee_weak_external_reference_enum);
2582 ieee_write_int(abfd, reference_index);
2583 ieee_write_int(abfd, p->value);
2584 ieee_write_int(abfd, BFD_FORT_COMM_DEFAULT_VALUE);
2585 p->value = reference_index;
2588 else if(p->flags & BSF_GLOBAL) {
2589 /* This must be a symbol definition */
2592 ieee_write_byte(abfd, ieee_external_symbol_enum);
2593 ieee_write_int(abfd, public_index );
2594 ieee_write_id(abfd, p->name);
2596 ieee_write_twobyte(abfd, ieee_attribute_record_enum);
2597 ieee_write_int(abfd, public_index );
2598 ieee_write_byte(abfd, 15); /* instruction address */
2599 ieee_write_byte(abfd, 19); /* static symbol */
2600 ieee_write_byte(abfd, 1); /* one of them */
2603 /* Write out the value */
2604 ieee_write_2bytes(abfd, ieee_value_record_enum);
2605 ieee_write_int(abfd, public_index);
2606 if (p->section != &bfd_abs_section)
2608 if (abfd->flags & EXEC_P)
2610 /* If fully linked, then output all symbols
2612 ieee_write_int(abfd,
2613 p->value + p->section->output_offset+ p->section->output_section->vma);
2617 ieee_write_expression(abfd,
2618 p->value + p->section->output_offset,
2619 p->section->output_section->symbol
2625 ieee_write_expression(abfd,
2627 bfd_abs_section.symbol,
2630 p->value = public_index;
2634 /* This can happen - when there are gaps in the symbols read */
2635 /* from an input ieee file */
2640 ieee->w.r.external_part = here;
2645 CONST static unsigned char exten[] =
2648 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
2649 0xf1, 0xce, 0x20, 0x00, 39, 2, /* keep symbol in original case */
2650 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
2653 CONST static unsigned char envi[] =
2657 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
2660 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
2662 0xf1, 0xce, 0x21, 0, 53, 0x03, /* host unix */
2663 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
2668 DEFUN(ieee_write_me_part,(abfd),
2671 ieee_data_type *ieee= IEEE_DATA(abfd);
2672 ieee->w.r.trailer_part = bfd_tell(abfd);
2673 if (abfd->start_address) {
2674 ieee->w.r.me_record = bfd_tell(abfd);
2675 ieee_write_2bytes(abfd, ieee_value_starting_address_enum);
2676 ieee_write_byte(abfd, ieee_function_either_open_b_enum);
2677 ieee_write_int(abfd, abfd->start_address);
2678 ieee_write_byte(abfd, ieee_function_either_close_b_enum);
2681 ieee->w.r.me_record = bfd_tell(abfd);
2683 ieee_write_byte(abfd, ieee_module_end_enum);
2687 DEFUN(ieee_write_object_contents,(abfd),
2690 ieee_data_type *ieee = IEEE_DATA(abfd);
2693 /* Fast forward over the header area */
2694 bfd_seek(abfd, 0, 0);
2695 ieee_write_byte(abfd, ieee_module_beginning_enum);
2697 ieee_write_id(abfd, bfd_printable_name(abfd));
2698 ieee_write_id(abfd, abfd->filename);
2703 /* Fast forward over the variable bits */
2707 ieee_write_byte(abfd, ieee_address_descriptor_enum);
2710 ieee_write_byte(abfd, bfd_arch_bits_per_byte(abfd));
2711 /* MAU's per address */
2712 ieee_write_byte(abfd, bfd_arch_bits_per_address(abfd) /
2713 bfd_arch_bits_per_byte(abfd));
2716 old = bfd_tell(abfd);
2717 bfd_seek(abfd, 8 * N_W_VARIABLES, 1);
2720 ieee->w.r.extension_record = bfd_tell(abfd);
2721 bfd_write((char *)exten, 1, sizeof(exten), abfd);
2722 if (abfd->flags & EXEC_P)
2723 ieee_write_byte(abfd, 0x1); /* Absolute */
2725 ieee_write_byte(abfd, 0x2); /* Relocateable */
2727 ieee->w.r.environmental_record = bfd_tell(abfd);
2728 bfd_write((char *)envi, 1, sizeof(envi), abfd);
2732 ieee_write_section_part(abfd);
2734 First write the symbols, this changes their values into table
2735 indeces so we cant use it after this point
2737 ieee_write_external_part(abfd);
2738 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
2741 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
2745 Write any debugs we have been told about
2747 ieee_write_debug_part(abfd);
2750 Can only write the data once the symbols have been written since
2751 the data contains relocation information which points to the
2754 ieee_write_data_part(abfd);
2758 At the end we put the end !
2760 ieee_write_me_part(abfd);
2763 /* Generate the header */
2764 bfd_seek(abfd, old, false);
2766 for (i= 0; i < N_W_VARIABLES; i++) {
2767 ieee_write_2bytes(abfd,ieee_assign_value_to_variable_enum);
2768 ieee_write_byte(abfd, i);
2769 ieee_write_int5_out(abfd, ieee->w.offset[i]);
2777 /* Native-level interface to symbols. */
2779 /* We read the symbols into a buffer, which is discarded when this
2780 function exits. We read the strings into a buffer large enough to
2781 hold them all plus all the cached symbol entries. */
2784 DEFUN(ieee_make_empty_symbol,(abfd),
2788 ieee_symbol_type *new =
2789 (ieee_symbol_type *)zalloc (sizeof (ieee_symbol_type));
2790 new->symbol.the_bfd = abfd;
2791 return &new->symbol;
2796 DEFUN(ieee_openr_next_archived_file,(arch, prev),
2800 ieee_ar_data_type *ar = IEEE_AR_DATA(arch);
2801 /* take the next one from the arch state, or reset */
2802 if (prev == (bfd *)NULL) {
2803 /* Reset the index - the first two entries are bogus*/
2804 ar->element_index = 2;
2807 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
2808 ar->element_index++;
2809 if (ar->element_index <= ar->element_count) {
2810 if (p->file_offset != (file_ptr)0) {
2811 if (p->abfd == (bfd *)NULL) {
2812 p->abfd = _bfd_create_empty_archive_element_shell(arch);
2813 p->abfd->origin = p->file_offset;
2819 bfd_error = no_more_archived_files;
2827 ieee_find_nearest_line(abfd,
2838 char **filename_ptr;
2839 char **functionname_ptr;
2847 ieee_generic_stat_arch_elt(abfd, buf)
2851 ieee_ar_data_type *ar = IEEE_AR_DATA(abfd);
2852 if (ar == (ieee_ar_data_type *)NULL) {
2853 bfd_error = invalid_operation;
2858 buf->st_mode = 0666;
2863 DEFUN(ieee_sizeof_headers,(abfd, x),
2873 DEFUN(ieee_bfd_debug_info_start,(abfd),
2880 DEFUN(ieee_bfd_debug_info_end,(abfd),
2887 /* Add this section to the list of sections we have debug info for, to
2888 be ready to output it at close time
2891 DEFUN(ieee_bfd_debug_info_accumulate,(abfd, section),
2895 ieee_data_type *ieee = IEEE_DATA(section->owner);
2896 ieee_data_type *output_ieee = IEEE_DATA(abfd);
2897 /* can only accumulate data from other ieee bfds */
2898 if (section->owner->xvec != abfd->xvec)
2900 /* Only bother once per bfd */
2901 if (ieee->done_debug == true)
2903 ieee->done_debug = true;
2905 /* Don't bother if there is no debug info */
2906 if (ieee->w.r.debug_information_part == 0)
2912 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc(abfd, sizeof(bfd_chain_type));
2913 n->this = section->owner;
2914 n->next = (bfd_chain_type *)NULL;
2916 if (output_ieee->chain_head) {
2917 output_ieee->chain_head->next = n;
2920 output_ieee->chain_root = n;
2923 output_ieee->chain_head = n;
2933 #define ieee_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
2934 #define ieee_core_file_failing_signal (int (*)())bfd_0
2935 #define ieee_core_file_matches_executable_p ( FOO(boolean, (*),(bfd *, bfd *)))bfd_false
2936 #define ieee_slurp_armap bfd_true
2937 #define ieee_slurp_extended_name_table bfd_true
2938 #define ieee_truncate_arname (void (*)())bfd_nullvoidptr
2939 #define ieee_write_armap (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, unsigned int, int))) bfd_nullvoidptr
2940 #define ieee_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
2941 #define ieee_close_and_cleanup bfd_generic_close_and_cleanup
2942 #define ieee_set_arch_mach bfd_default_set_arch_mach
2943 #define ieee_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
2944 #define ieee_bfd_relax_section bfd_generic_relax_section
2946 bfd_target ieee_vec =
2949 bfd_target_ieee_flavour,
2950 true, /* target byte order */
2951 true, /* target headers byte order */
2952 (HAS_RELOC | EXEC_P | /* object flags */
2953 HAS_LINENO | HAS_DEBUG |
2954 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2955 ( SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
2956 |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2957 ' ', /* ar_pad_char */
2958 16, /* ar_max_namelen */
2959 1, /* minimum alignment */
2960 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
2961 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
2963 { _bfd_dummy_target,
2964 ieee_object_p, /* bfd_check_format */
2971 _bfd_generic_mkarchive,
2976 ieee_write_object_contents,
2977 _bfd_write_archive_contents,