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, 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) {
98 ieee_write_byte(abfd, (int)ieee_number_repeat_start_enum + length);
101 ieee_write_byte(abfd, value >> 24);
103 ieee_write_byte(abfd, value >> 16);
105 ieee_write_byte(abfd, value >> 8);
107 ieee_write_byte(abfd, value);
113 DEFUN(ieee_write_id,(abfd, id),
117 size_t length = strlen(id);
118 if (length >= 0 && length <= 127) {
119 ieee_write_byte(abfd, length);
121 else if (length < 255) {
122 ieee_write_byte(abfd, ieee_extension_length_1_enum);
123 ieee_write_byte(abfd, length);
125 else if (length < 65535) {
126 ieee_write_byte(abfd, ieee_extension_length_2_enum);
127 ieee_write_byte(abfd, length >> 8);
128 ieee_write_byte(abfd, length & 0xff);
133 bfd_write((PTR)id, 1, length, abfd);
135 /***************************************************************************
136 Functions for reading from ieee files in the strange way that the
141 #define this_byte(ieee) *((ieee)->input_p)
142 #define next_byte(ieee) ((ieee)->input_p++)
143 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
146 static unsigned short
147 DEFUN(read_2bytes,(ieee),
148 common_header_type *ieee)
150 unsigned char c1 = this_byte_and_next(ieee);
151 unsigned char c2 = this_byte_and_next(ieee);
152 return (c1<<8 ) | c2;
157 DEFUN(bfd_get_string,(ieee, string, length),
158 common_header_type *ieee AND
163 for (i= 0; i < length; i++) {
164 string[i] = this_byte_and_next(ieee);
169 DEFUN(read_id,(ieee),
170 common_header_type *ieee)
174 length = this_byte_and_next(ieee);
175 if (length >= 0x00 && length <= 0x7f) {
176 /* Simple string of length 0 to 127 */
178 else if (length == 0xde) {
179 /* Length is next byte, allowing 0..255 */
180 length = this_byte_and_next(ieee);
182 else if (length == 0xdf) {
183 /* Length is next two bytes, allowing 0..65535 */
184 length = this_byte_and_next(ieee) ;
185 length = (length * 256) + this_byte_and_next(ieee);
187 /* Buy memory and read string */
188 string = bfd_alloc(ieee->abfd, length+1);
189 bfd_get_string(ieee, string, length);
195 DEFUN(ieee_write_expression,(abfd, value, symbol, pcrel, index),
202 unsigned int term_count = 0;
206 ieee_write_int(abfd, value);
212 if (bfd_is_com_section (symbol->section)
213 || symbol->section == &bfd_und_section)
215 /* Def of a common symbol */
216 ieee_write_byte(abfd, ieee_variable_X_enum);
217 ieee_write_int(abfd, symbol->value);
220 else if (symbol->section != &bfd_abs_section)
222 /* Ref to defined symbol - */
224 ieee_write_byte(abfd, ieee_variable_R_enum);
225 ieee_write_byte(abfd, symbol->section->index + IEEE_SECTION_NUMBER_BASE);
227 if (symbol->flags & BSF_GLOBAL)
229 ieee_write_byte(abfd, ieee_variable_I_enum);
230 ieee_write_int(abfd, symbol->value);
233 else if (symbol->flags & ( BSF_LOCAL | BSF_SECTION_SYM))
235 /* This is a reference to a defined local symbol,
236 We can easily do a local as a section+offset */
237 ieee_write_byte(abfd, ieee_variable_R_enum); /* or L */
238 ieee_write_byte(abfd, symbol->section->index +
239 IEEE_SECTION_NUMBER_BASE);
240 ieee_write_int(abfd, symbol->value);
253 /* subtract the pc from here by asking for PC of this section*/
254 ieee_write_byte(abfd, ieee_variable_P_enum);
255 ieee_write_byte(abfd, index +IEEE_SECTION_NUMBER_BASE);
256 ieee_write_byte(abfd, ieee_function_minus_enum);
261 ieee_write_byte(abfd,0);
264 while (term_count > 1) {
265 ieee_write_byte(abfd, ieee_function_plus_enum);
280 /*****************************************************************************/
283 writes any integer into the buffer supplied and always takes 5 bytes
286 DEFUN(ieee_write_int5,(buffer, value),
290 buffer[0] = (bfd_byte)ieee_number_repeat_4_enum;
291 buffer[1] = (value >> 24 ) & 0xff;
292 buffer[2] = (value >> 16 ) & 0xff;
293 buffer[3] = (value >> 8 ) & 0xff;
294 buffer[4] = (value >> 0 ) & 0xff;
297 DEFUN(ieee_write_int5_out, (abfd, value),
302 ieee_write_int5(b, value);
303 bfd_write((PTR)b,1,5,abfd);
308 DEFUN(parse_int,(ieee, value_ptr),
309 common_header_type *ieee AND
312 int value = this_byte(ieee);
314 if (value >= 0 && value <= 127) {
319 else if (value >= 0x80 && value <= 0x88) {
320 unsigned int count = value & 0xf;
324 result =(result << 8) | this_byte_and_next(ieee);
333 DEFUN(parse_i,(ieee, ok),
334 common_header_type *ieee AND
338 *ok = parse_int(ieee, &x);
343 DEFUN(must_parse_int,(ieee),
344 common_header_type *ieee)
347 BFD_ASSERT(parse_int(ieee, &result) == true);
355 ieee_symbol_index_type symbol;
360 reloc_howto_type abs32_howto
361 = HOWTO(1,0,2,32,false,0,false,true,0,"abs32",true,0xffffffff, 0xffffffff,false);
363 reloc_howto_type abs16_howto
364 = HOWTO(1,0,1,16,false,0,false,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false);
367 reloc_howto_type abs8_howto
368 = HOWTO(1,0,0,8,false,0,false,true,0,"abs8",true,0x000000ff, 0x000000ff,false);
371 reloc_howto_type rel32_howto
372 = HOWTO(1,0,2,32,true,0,false,true,0,"rel32",true,0xffffffff,
376 reloc_howto_type rel16_howto
377 = HOWTO(1,0,1,16,true,0,false,true,0,"rel16",true,0x0000ffff, 0x0000ffff,false);
380 reloc_howto_type rel8_howto
381 = HOWTO(1,0,0,8,true,0,false,true,0,"rel8",true,0x000000ff, 0x000000ff,false);
384 static ieee_symbol_index_type NOSYMBOL = { 0, 0};
388 DEFUN(parse_expression,(ieee, value, symbol, pcrel, extra, section),
389 ieee_data_type *ieee AND
391 ieee_symbol_index_type *symbol AND
393 unsigned int *extra AND
405 ieee_value_type stack[10];
407 /* The stack pointer always points to the next unused location */
408 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
409 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
410 ieee_value_type *sp = stack;
413 switch (this_byte(&(ieee->h)))
415 case ieee_variable_P_enum:
416 /* P variable, current program counter for section n */
419 next_byte(&(ieee->h));
421 section_n = must_parse_int(&(ieee->h));
422 PUSH(NOSYMBOL, &bfd_abs_section,
423 TOS.value = ieee->section_table[section_n]->vma +
424 ieee_per_section(ieee->section_table[section_n])->pc);
427 case ieee_variable_L_enum:
428 /* L variable address of section N */
429 next_byte(&(ieee->h));
430 PUSH(NOSYMBOL,ieee->section_table[must_parse_int(&(ieee->h))],0);
432 case ieee_variable_R_enum:
433 /* R variable, logical address of section module */
434 /* FIXME, this should be different to L */
435 next_byte(&(ieee->h));
436 PUSH(NOSYMBOL,ieee->section_table[must_parse_int(&(ieee->h))],0);
438 case ieee_variable_S_enum:
439 /* S variable, size in MAUS of section module */
440 next_byte(&(ieee->h));
443 ieee->section_table[must_parse_int(&(ieee->h))]->_raw_size);
445 case ieee_variable_I_enum:
446 case ieee_variable_X_enum:
447 /* Push the address of external variable n */
449 ieee_symbol_index_type sy;
450 next_byte(&(ieee->h));
451 sy.index = (int)(must_parse_int(&(ieee->h))) ;
454 PUSH(sy, &bfd_und_section, 0);
457 case ieee_function_minus_enum:
459 bfd_vma value1, value2;
460 asection *section1, *section_dummy;
461 ieee_symbol_index_type sy;
462 next_byte(&(ieee->h));
464 POP(sy, section1, value1);
465 POP(sy, section_dummy, value2);
466 PUSH(sy, section1 ? section1 : section_dummy, value1-value2);
469 case ieee_function_plus_enum:
471 bfd_vma value1, value2;
474 ieee_symbol_index_type sy1;
475 ieee_symbol_index_type sy2;
476 next_byte(&(ieee->h));
478 POP(sy1, section1, value1);
479 POP(sy2, section2, value2);
480 PUSH(sy1.letter ? sy1 : sy2, section1!=&bfd_abs_section ? section1: section2, value1+value2);
486 BFD_ASSERT(this_byte(&(ieee->h)) < (int)ieee_variable_A_enum
487 || this_byte(&(ieee->h)) > (int)ieee_variable_Z_enum);
488 if (parse_int(&(ieee->h), &va))
490 PUSH(NOSYMBOL, &bfd_abs_section, va);
494 Thats all that we can understand. As far as I can see
495 there is a bug in the Microtec IEEE output which I'm
496 using to scan, whereby the comma operator is ommited
497 sometimes in an expression, giving expressions with too
498 many terms. We can tell if that's the case by ensuring
499 that sp == stack here. If not, then we've pushed
500 something too far, so we keep adding
503 while (sp != stack+1) {
505 ieee_symbol_index_type sy1;
506 POP(sy1, section1, *extra);
511 POP(*symbol, dummy, *value);
512 if (section) *section = dummy;
525 #define ieee_seek(abfd, offset) \
526 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
528 #define ieee_pos(abfd) IEEE_DATA(abfd)->h.input_p -IEEE_DATA(abfd)->h.first_byte
530 static unsigned int last_index;
531 static char last_type; /* is the index for an X or a D */
532 static ieee_symbol_type *
533 DEFUN(get_symbol,(abfd,
542 ieee_data_type *ieee AND
543 ieee_symbol_type *last_symbol AND
544 unsigned int *symbol_count AND
545 ieee_symbol_type *** pptr AND
546 unsigned int *max_index AND
550 /* Need a new symbol */
551 unsigned int new_index = must_parse_int(&(ieee->h));
552 if (new_index != last_index || this_type != last_type) {
553 ieee_symbol_type * new_symbol = (ieee_symbol_type *)bfd_alloc(ieee->h.abfd,
554 sizeof(ieee_symbol_type));
556 new_symbol->index = new_index;
557 last_index = new_index;
560 *pptr = &new_symbol->next;
561 if (new_index > *max_index) {
562 *max_index = new_index;
564 last_type = this_type;
570 DEFUN(ieee_slurp_external_symbols,(abfd),
573 ieee_data_type *ieee = IEEE_DATA(abfd);
574 file_ptr offset = ieee->w.r.external_part;
577 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
578 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
579 ieee_symbol_type *symbol = (ieee_symbol_type *)NULL;
580 unsigned int symbol_count = 0;
582 last_index = 0xffffff;
583 ieee->symbol_table_full = true;
585 ieee_seek(abfd, offset );
588 switch (this_byte(&(ieee->h))) {
590 next_byte(&(ieee->h));
592 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
594 &ieee->external_symbol_max_index,'D');
597 symbol->symbol.the_bfd = abfd;
598 symbol->symbol.name = read_id(&(ieee->h));
599 symbol->symbol.udata = (PTR)NULL;
600 symbol->symbol.flags = BSF_NO_FLAGS;
604 case ieee_external_symbol_enum:
605 next_byte(&(ieee->h));
607 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
609 &ieee->external_symbol_max_index,'D');
612 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
614 symbol->symbol.the_bfd = abfd;
615 symbol->symbol.name = read_id(&(ieee->h));
616 symbol->symbol.udata = (PTR)NULL;
617 symbol->symbol.flags = BSF_NO_FLAGS;
619 case ieee_attribute_record_enum >> 8:
621 unsigned int symbol_name_index;
622 unsigned int symbol_type_index;
623 unsigned int symbol_attribute_def;
625 next_byte(&(ieee->h)); /* Skip prefix */
626 next_byte(&(ieee->h));
627 symbol_name_index = must_parse_int(&(ieee->h));
628 symbol_type_index = must_parse_int(&(ieee->h));
629 symbol_attribute_def = must_parse_int(&(ieee->h));
630 switch (symbol_attribute_def) {
632 /* Module misc; followed by two fields which describe the
633 current module block. The first fired is the type id
634 number, the second is the number of asn records
635 associated with the directive */
636 parse_int(&(ieee->h),&value);
637 parse_int(&(ieee->h),&value);
641 parse_int(&(ieee->h),&value);
646 case ieee_value_record_enum >> 8:
648 unsigned int symbol_name_index;
649 ieee_symbol_index_type symbol_ignore;
650 boolean pcrel_ignore;
652 next_byte(&(ieee->h));
653 next_byte(&(ieee->h));
655 symbol_name_index = must_parse_int(&(ieee->h));
656 parse_expression(ieee,
657 &symbol->symbol.value,
661 &symbol->symbol.section);
663 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
667 case ieee_weak_external_reference_enum:
670 next_byte(&(ieee->h));
671 /* Throw away the external reference index */
672 (void)must_parse_int(&(ieee->h));
673 /* Fetch the default size if not resolved */
674 size = must_parse_int(&(ieee->h));
675 /* Fetch the defautlt value if available */
676 if ( parse_int(&(ieee->h), &value) == false) {
679 /* This turns into a common */
680 symbol->symbol.section = &bfd_com_section;
681 symbol->symbol.value = size;
685 case ieee_external_reference_enum:
686 next_byte(&(ieee->h));
688 symbol = get_symbol(abfd, ieee, symbol, &symbol_count,
690 &ieee->external_reference_max_index,'X');
693 symbol->symbol.the_bfd = abfd;
694 symbol->symbol.name = read_id(&(ieee->h));
695 symbol->symbol.udata = (PTR)NULL;
696 symbol->symbol.section = &bfd_und_section;
697 symbol->symbol.value = (bfd_vma)0;
698 symbol->symbol.flags = 0;
700 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
708 if (ieee->external_symbol_max_index != 0) {
709 ieee->external_symbol_count =
710 ieee->external_symbol_max_index -
711 ieee->external_symbol_min_index + 1 ;
714 ieee->external_symbol_count = 0;
718 if(ieee->external_reference_max_index != 0) {
719 ieee->external_reference_count =
720 ieee->external_reference_max_index -
721 ieee->external_reference_min_index + 1;
724 ieee->external_reference_count = 0;
728 ieee->external_reference_count + ieee->external_symbol_count;
730 if (symbol_count != abfd->symcount) {
731 /* There are gaps in the table -- */
732 ieee->symbol_table_full = false;
736 *prev_symbols_ptr = (ieee_symbol_type *)NULL;
737 *prev_reference_ptr = (ieee_symbol_type *)NULL;
741 DEFUN(ieee_slurp_symbol_table,(abfd),
744 if (IEEE_DATA(abfd)->read_symbols == false) {
745 ieee_slurp_external_symbols(abfd);
746 IEEE_DATA(abfd)->read_symbols= true;
751 DEFUN(ieee_get_symtab_upper_bound,(abfd),
754 ieee_slurp_symbol_table (abfd);
756 return (abfd->symcount != 0) ?
757 (abfd->symcount+1) * (sizeof (ieee_symbol_type *)) : 0;
761 Move from our internal lists to the canon table, and insert in
765 extern bfd_target ieee_vec;
767 DEFUN(ieee_get_symtab,(abfd, location),
771 ieee_symbol_type *symp;
772 static bfd dummy_bfd;
773 static asymbol empty_symbol =
774 /* the_bfd, name, value, attr, section */
775 { &dummy_bfd, " ieee empty", (symvalue)0, BSF_DEBUGGING, &bfd_abs_section};
779 ieee_data_type *ieee = IEEE_DATA(abfd);
780 dummy_bfd.xvec= &ieee_vec;
781 ieee_slurp_symbol_table(abfd);
783 if (ieee->symbol_table_full == false) {
784 /* Arrgh - there are gaps in the table, run through and fill them */
785 /* up with pointers to a null place */
787 for (i= 0; i < abfd->symcount; i++) {
788 location[i] = &empty_symbol;
793 ieee->external_symbol_base_offset= - ieee->external_symbol_min_index;
794 for (symp = IEEE_DATA(abfd)->external_symbols;
795 symp != (ieee_symbol_type *)NULL;
797 /* Place into table at correct index locations */
798 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
802 /* The external refs are indexed in a bit */
803 ieee->external_reference_base_offset =
804 - ieee->external_reference_min_index +ieee->external_symbol_count ;
806 for (symp = IEEE_DATA(abfd)->external_reference;
807 symp != (ieee_symbol_type *)NULL;
809 location[symp->index + ieee->external_reference_base_offset] =
818 if (abfd->symcount) {
819 location[abfd->symcount] = (asymbol *)NULL;
821 return abfd->symcount;
824 DEFUN(get_section_entry,(abfd, ieee,index),
826 ieee_data_type *ieee AND
829 if (ieee->section_table[index] == (asection *)NULL) {
830 char *tmp = bfd_alloc(abfd,11);
832 sprintf(tmp," fsec%4d", index);
833 section = bfd_make_section(abfd, tmp);
834 ieee->section_table[index] = section;
835 section->flags = SEC_NO_FLAGS;
836 section->target_index = index;
837 ieee->section_table[index] = section;
839 return ieee->section_table[index];
843 DEFUN(ieee_slurp_sections,(abfd),
846 ieee_data_type *ieee = IEEE_DATA(abfd);
847 file_ptr offset = ieee->w.r.section_part;
849 asection *section = (asection *)NULL;
852 bfd_byte section_type[3];
853 ieee_seek(abfd, offset);
855 switch (this_byte(&(ieee->h))) {
856 case ieee_section_type_enum:
858 unsigned int section_index ;
859 next_byte(&(ieee->h));
860 section_index = must_parse_int(&(ieee->h));
861 /* Fixme to be nice about a silly number of sections */
862 BFD_ASSERT(section_index < NSECTIONS);
864 section =get_section_entry(abfd, ieee, section_index);
866 section_type[0] = this_byte_and_next(&(ieee->h));
867 switch (section_type[0]) {
869 /* Normal attributes for absolute sections */
870 section_type[1] = this_byte(&(ieee->h));
871 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
872 switch(section_type[1]) {
874 next_byte(&(ieee->h));
875 section_type[2] = this_byte(&(ieee->h));
876 switch (section_type[2])
880 next_byte(&(ieee->h));
881 section->flags |= SEC_LOAD | SEC_CODE;
884 next_byte(&(ieee->h));
885 section->flags |= SEC_LOAD | SEC_DATA;
889 next_byte(&(ieee->h));
890 /* Normal rom data */
891 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
899 section_type[1] = this_byte(&(ieee->h));
900 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
901 switch (section_type[1]) {
904 next_byte(&(ieee->h));
905 section->flags |= SEC_LOAD | SEC_CODE;
908 next_byte(&(ieee->h));
909 section->flags |= SEC_LOAD | SEC_DATA;
913 next_byte(&(ieee->h));
914 /* Normal rom data */
915 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
921 memcpy((char*)section->name, read_id(&(ieee->h)),8);
922 /* Truncate sections to 8 chars */
923 if (strlen(section->name) > 8)
925 char *copy = bfd_alloc(abfd, 9);
926 memcpy(copy, section->name, 8);
928 section->name = copy;
932 bfd_vma parent, brother, context;
933 parse_int(&(ieee->h), &parent);
934 parse_int(&(ieee->h), &brother);
935 parse_int(&(ieee->h), &context);
941 case ieee_section_alignment_enum:
943 unsigned int section_index;
946 next_byte(&(ieee->h));
947 section_index = must_parse_int(&ieee->h);
948 section = get_section_entry(abfd, ieee, section_index);
949 if (section_index > ieee->section_count) {
950 ieee->section_count = section_index;
952 section->alignment_power =
953 bfd_log2(must_parse_int(&ieee->h));
954 (void)parse_int(&(ieee->h), & value);
957 case ieee_e2_first_byte_enum:
959 ieee_record_enum_type t = (ieee_record_enum_type)(read_2bytes(&(ieee->h)));
962 case ieee_section_size_enum:
963 section = ieee->section_table[must_parse_int(&(ieee->h))];
964 section->_raw_size = must_parse_int(&(ieee->h));
966 case ieee_physical_region_size_enum:
967 section = ieee->section_table[must_parse_int(&(ieee->h))];
968 section->_raw_size = must_parse_int(&(ieee->h));
970 case ieee_region_base_address_enum:
971 section = ieee->section_table[must_parse_int(&(ieee->h))];
972 section->vma = must_parse_int(&(ieee->h));
974 case ieee_mau_size_enum:
975 must_parse_int(&(ieee->h));
976 must_parse_int(&(ieee->h));
978 case ieee_m_value_enum:
979 must_parse_int(&(ieee->h));
980 must_parse_int(&(ieee->h));
982 case ieee_section_base_address_enum:
983 section = ieee->section_table[must_parse_int(&(ieee->h))];
984 section->vma = must_parse_int(&(ieee->h));
986 case ieee_section_offset_enum:
987 (void) must_parse_int(&(ieee->h));
988 (void) must_parse_int(&(ieee->h));
1002 /***********************************************************************
1006 DEFUN(ieee_archive_p,(abfd),
1013 uint8e_type buffer[512];
1015 file_ptr buffer_offset = 0;
1016 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1017 ieee_ar_data_type *ieee ;
1018 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *)bfd_alloc(abfd, sizeof(ieee_ar_data_type));
1019 ieee= IEEE_AR_DATA(abfd);
1023 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1025 ieee->h.first_byte = buffer;
1026 ieee->h.input_p = buffer;
1028 ieee->h.abfd = abfd;
1030 if (this_byte(&(ieee->h)) != Module_Beginning) {
1031 abfd->tdata.ieee_ar_data = save;
1032 return (bfd_target*)NULL;
1036 next_byte(&(ieee->h));
1037 library= read_id(&(ieee->h));
1038 if (strcmp(library , "LIBRARY") != 0) {
1039 bfd_release(abfd, ieee);
1040 abfd->tdata.ieee_ar_data = save;
1041 return (bfd_target *)NULL;
1043 /* Throw away the filename */
1044 read_id(&(ieee->h));
1045 /* This must be an IEEE archive, so we'll buy some space to do
1048 obstack_begin(&ob, 128);
1051 ieee->element_count = 0;
1052 ieee->element_index = 0;
1054 next_byte(&(ieee->h)); /* Drop the ad part */
1055 must_parse_int(&(ieee->h)); /* And the two dummy numbers */
1056 must_parse_int(&(ieee->h));
1059 /* Read the index of the BB table */
1061 ieee_ar_obstack_type t;
1062 int rec =read_2bytes(&(ieee->h));
1063 if (rec ==(int)ieee_assign_value_to_variable_enum) {
1064 int record_number = must_parse_int(&(ieee->h));
1065 t.file_offset = must_parse_int(&(ieee->h));
1066 t.abfd = (bfd *)NULL;
1067 ieee->element_count++;
1069 obstack_grow(&ob, (PTR)&t, sizeof(t));
1071 /* Make sure that we don't go over the end of the buffer */
1073 if (ieee_pos(abfd) > sizeof(buffer)/2) {
1074 /* Past half way, reseek and reprime */
1075 buffer_offset += ieee_pos(abfd);
1076 bfd_seek(abfd, buffer_offset, SEEK_SET);
1077 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1078 ieee->h.first_byte = buffer;
1079 ieee->h.input_p = buffer;
1085 ieee->elements = (ieee_ar_obstack_type *)obstack_finish(&ob);
1087 /* Now scan the area again, and replace BB offsets with file */
1091 for (i = 2; i < ieee->element_count; i++) {
1092 bfd_seek(abfd, ieee->elements[i].file_offset, SEEK_SET);
1093 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1094 ieee->h.first_byte = buffer;
1095 ieee->h.input_p = buffer;
1097 next_byte(&(ieee->h)); /* Drop F8 */
1098 next_byte(&(ieee->h)); /* Drop 14 */
1099 must_parse_int(&(ieee->h)); /* Drop size of block */
1100 if (must_parse_int(&(ieee->h)) != 0) {
1101 /* This object has been deleted */
1102 ieee->elements[i].file_offset = 0;
1105 ieee->elements[i].file_offset = must_parse_int(&(ieee->h));
1109 /* abfd->has_armap = ;*/
1115 DEFUN(ieee_mkobject,(abfd),
1118 abfd->tdata.ieee_data = (ieee_data_type *)bfd_zalloc(abfd,sizeof(ieee_data_type));
1125 DEFUN(ieee_object_p,(abfd),
1130 ieee_data_type *ieee;
1131 uint8e_type buffer[300];
1132 ieee_data_type *save = IEEE_DATA(abfd);
1133 abfd->tdata.ieee_data = 0;
1134 ieee_mkobject(abfd);
1136 ieee = IEEE_DATA(abfd);
1137 bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
1138 /* Read the first few bytes in to see if it makes sense */
1139 bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);
1141 ieee->h.input_p = buffer;
1142 if (this_byte_and_next(&(ieee->h)) != Module_Beginning) goto fail;
1144 ieee->read_symbols= false;
1145 ieee->read_data= false;
1146 ieee->section_count = 0;
1147 ieee->external_symbol_max_index = 0;
1148 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1149 ieee->external_reference_min_index =IEEE_REFERENCE_BASE;
1150 ieee->external_reference_max_index = 0;
1151 ieee->h.abfd = abfd;
1152 memset((PTR)ieee->section_table, 0, sizeof(ieee->section_table));
1154 processor = ieee->mb.processor = read_id(&(ieee->h));
1155 if (strcmp(processor,"LIBRARY") == 0) goto fail;
1156 ieee->mb.module_name = read_id(&(ieee->h));
1157 if (abfd->filename == (CONST char *)NULL) {
1158 abfd->filename = ieee->mb.module_name;
1160 /* Determine the architecture and machine type of the object file.
1163 bfd_arch_info_type *arch = bfd_scan_arch(processor);
1164 if (arch == 0) goto fail;
1165 abfd->arch_info = arch;
1168 if (this_byte(&(ieee->h)) != (int)ieee_address_descriptor_enum) {
1171 next_byte(&(ieee->h));
1173 if (parse_int(&(ieee->h), &ieee->ad.number_of_bits_mau) == false) {
1176 if(parse_int(&(ieee->h), &ieee->ad.number_of_maus_in_address) == false) {
1180 /* If there is a byte order info, take it */
1181 if (this_byte(&(ieee->h)) == (int)ieee_variable_L_enum ||
1182 this_byte(&(ieee->h)) == (int)ieee_variable_M_enum)
1183 next_byte(&(ieee->h));
1186 for (part = 0; part < N_W_VARIABLES; part++) {
1188 if (read_2bytes(&(ieee->h)) != (int) ieee_assign_value_to_variable_enum) {
1191 if (this_byte_and_next(&(ieee->h)) != part) {
1195 ieee->w.offset[part] = parse_i(&(ieee->h), &ok);
1201 abfd->flags = HAS_SYMS;
1202 /* By now we know that this is a real IEEE file, we're going to read
1203 the whole thing into memory so that we can run up and down it
1204 quickly. We can work out how big the file is from the trailer
1207 IEEE_DATA(abfd)->h.first_byte = (uint8e_type *) bfd_alloc(ieee->h.abfd, ieee->w.r.me_record
1209 bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
1210 bfd_read((PTR)(IEEE_DATA(abfd)->h.first_byte), 1, ieee->w.r.me_record+50, abfd);
1212 ieee_slurp_sections(abfd);
1215 (void) bfd_release(abfd, ieee);
1216 abfd->tdata.ieee_data = save;
1217 return (bfd_target *)NULL;
1222 DEFUN(ieee_print_symbol,(ignore_abfd, afile, symbol, how),
1223 bfd *ignore_abfd AND
1226 bfd_print_symbol_type how)
1228 FILE *file = (FILE *)afile;
1231 case bfd_print_symbol_name:
1232 fprintf(file,"%s", symbol->name);
1234 case bfd_print_symbol_more:
1236 fprintf(file,"%4x %2x",aout_symbol(symbol)->desc & 0xffff,
1237 aout_symbol(symbol)->other & 0xff);
1241 case bfd_print_symbol_nm:
1242 case bfd_print_symbol_all:
1244 CONST char *section_name = symbol->section == (asection *)NULL ?
1245 (CONST char *)"*abs" : symbol->section->name;
1246 if (symbol->name[0] == ' ') {
1247 fprintf(file,"* empty table entry ");
1250 bfd_print_symbol_vandf((PTR)file,symbol);
1252 fprintf(file," %-5s %04x %02x %s",
1254 (unsigned) ieee_symbol(symbol)->index,
1256 aout_symbol(symbol)->desc & 0xffff,
1257 aout_symbol(symbol)->other & 0xff,*/
1267 DEFUN(do_one,(ieee, current_map, location_ptr,s),
1268 ieee_data_type *ieee AND
1269 ieee_per_section_type *current_map AND
1270 uint8e_type *location_ptr AND
1273 switch (this_byte(&(ieee->h)))
1275 case ieee_load_constant_bytes_enum:
1277 unsigned int number_of_maus;
1279 next_byte(&(ieee->h));
1280 number_of_maus = must_parse_int(&(ieee->h));
1282 for (i = 0; i < number_of_maus; i++) {
1283 location_ptr[current_map->pc++]= this_byte(&(ieee->h));
1284 next_byte(&(ieee->h));
1289 case ieee_load_with_relocation_enum:
1291 boolean loop = true;
1292 next_byte(&(ieee->h));
1295 switch (this_byte(&(ieee->h)))
1297 case ieee_variable_R_enum:
1299 case ieee_function_signed_open_b_enum:
1300 case ieee_function_unsigned_open_b_enum:
1301 case ieee_function_either_open_b_enum:
1303 unsigned int extra = 4;
1304 boolean pcrel = false;
1306 ieee_reloc_type *r =
1307 (ieee_reloc_type *) bfd_alloc(ieee->h.abfd,
1308 sizeof(ieee_reloc_type));
1310 *(current_map->reloc_tail_ptr) = r;
1311 current_map->reloc_tail_ptr= &r->next;
1312 r->next = (ieee_reloc_type *)NULL;
1313 next_byte(&(ieee->h));
1315 r->relent.sym_ptr_ptr = 0;
1316 parse_expression(ieee,
1319 &pcrel, &extra, §ion);
1320 r->relent.address = current_map->pc;
1322 if (r->relent.sym_ptr_ptr == 0) {
1323 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1326 if (this_byte(&(ieee->h)) == (int)ieee_comma) {
1327 next_byte(&(ieee->h));
1328 /* Fetch number of bytes to pad */
1329 extra = must_parse_int(&(ieee->h));
1332 switch (this_byte(&(ieee->h))) {
1333 case ieee_function_signed_close_b_enum:
1334 next_byte(&(ieee->h));
1336 case ieee_function_unsigned_close_b_enum:
1337 next_byte(&(ieee->h));
1339 case ieee_function_either_close_b_enum:
1340 next_byte(&(ieee->h));
1345 /* Build a relocation entry for this type */
1346 /* If pc rel then stick -ve pc into instruction
1347 and take out of reloc ..
1349 I've changed this. It's all too
1350 complicated. I keep 0 in the
1361 #if KEEPMINUSPCININST
1362 bfd_put_32(ieee->h.abfd, -current_map->pc, location_ptr +
1364 r->relent.howto = &rel32_howto;
1368 bfd_put_32(ieee->h.abfd,0, location_ptr +
1370 r->relent.howto = &rel32_howto;
1375 bfd_put_32(ieee->h.abfd, 0, location_ptr +
1377 r->relent.howto = &abs32_howto;
1379 current_map->pc +=4;
1382 if (pcrel == true) {
1383 #if KEEPMINUSPCININST
1384 bfd_put_16(ieee->h.abfd, (int)(-current_map->pc), location_ptr +current_map->pc);
1385 r->relent.addend -= current_map->pc;
1386 r->relent.howto = &rel16_howto;
1389 bfd_put_16(ieee->h.abfd, 0, location_ptr +current_map->pc);
1390 r->relent.howto = &rel16_howto;
1395 bfd_put_16(ieee->h.abfd, 0, location_ptr +current_map->pc);
1396 r->relent.howto = &abs16_howto;
1398 current_map->pc +=2;
1401 if (pcrel == true) {
1402 #if KEEPMINUSPCININST
1403 bfd_put_8(ieee->h.abfd, (int)(-current_map->pc), location_ptr +current_map->pc);
1404 r->relent.addend -= current_map->pc;
1405 r->relent.howto = &rel8_howto;
1407 bfd_put_8(ieee->h.abfd,0, location_ptr +current_map->pc);
1408 r->relent.howto = &rel8_howto;
1412 bfd_put_8(ieee->h.abfd, 0, location_ptr +current_map->pc);
1413 r->relent.howto = &abs8_howto;
1415 current_map->pc +=1;
1427 if (parse_int(&(ieee->h), &this_size) == true) {
1429 for (i = 0; i < this_size; i++) {
1430 location_ptr[current_map->pc ++] = this_byte(&(ieee->h));
1431 next_byte(&(ieee->h));
1444 /* Read in all the section data and relocation stuff too */
1446 DEFUN(ieee_slurp_section_data,(abfd),
1449 bfd_byte *location_ptr = (bfd_byte *)NULL;
1450 ieee_data_type *ieee = IEEE_DATA(abfd);
1451 unsigned int section_number ;
1453 ieee_per_section_type *current_map = (ieee_per_section_type *)NULL;
1455 /* Seek to the start of the data area */
1456 if (ieee->read_data== true) return true;
1457 ieee->read_data = true;
1458 ieee_seek(abfd, ieee->w.r.data_part);
1460 /* Allocate enough space for all the section contents */
1463 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
1464 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1465 per->data = (bfd_byte *) bfd_alloc(ieee->h.abfd, s->_raw_size);
1467 per->reloc_tail_ptr =
1468 (ieee_reloc_type **)&(s->relocation);
1474 switch (this_byte(&(ieee->h)))
1476 /* IF we see anything strange then quit */
1480 case ieee_set_current_section_enum:
1481 next_byte(&(ieee->h));
1482 section_number = must_parse_int(&(ieee->h));
1483 s = ieee->section_table[section_number];
1484 current_map = (ieee_per_section_type *) s->used_by_bfd;
1485 location_ptr = current_map->data - s->vma;
1486 /* The document I have says that Microtec's compilers reset */
1487 /* this after a sec section, even though the standard says not */
1489 current_map->pc =s->vma;
1493 case ieee_e2_first_byte_enum:
1494 next_byte(&(ieee->h));
1495 switch (this_byte(&(ieee->h)))
1497 case ieee_set_current_pc_enum & 0xff:
1501 ieee_symbol_index_type symbol;
1504 next_byte(&(ieee->h));
1505 must_parse_int(&(ieee->h)); /* Thow away section #*/
1506 parse_expression(ieee, &value,
1510 current_map->pc = value;
1511 BFD_ASSERT((unsigned)(value - s->vma) <= s->_raw_size);
1515 case ieee_value_starting_address_enum & 0xff:
1516 /* We've got to the end of the data now - */
1523 case ieee_repeat_data_enum:
1525 /* Repeat the following LD or LR n times - we do this by
1526 remembering the stream pointer before running it and
1527 resetting it and running it n times. We special case
1528 the repetition of a repeat_data/load_constant
1531 unsigned int iterations ;
1532 uint8e_type *start ;
1533 next_byte(&(ieee->h));
1534 iterations = must_parse_int(&(ieee->h));
1535 start = ieee->h.input_p;
1536 if (start[0] == (int)ieee_load_constant_bytes_enum &&
1538 while (iterations != 0) {
1539 location_ptr[current_map->pc++] = start[2];
1542 next_byte(&(ieee->h));
1543 next_byte(&(ieee->h));
1544 next_byte(&(ieee->h));
1547 while (iterations != 0) {
1548 ieee->h.input_p = start;
1549 do_one(ieee, current_map, location_ptr,s);
1555 case ieee_load_constant_bytes_enum:
1556 case ieee_load_with_relocation_enum:
1558 do_one(ieee, current_map, location_ptr,s);
1569 DEFUN(ieee_new_section_hook,(abfd, newsect),
1573 newsect->used_by_bfd = (PTR)
1574 bfd_alloc(abfd, sizeof(ieee_per_section_type));
1575 ieee_per_section( newsect)->data = (bfd_byte *)NULL;
1576 ieee_per_section(newsect)->section = newsect;
1582 DEFUN(ieee_get_reloc_upper_bound,(abfd, asect),
1586 ieee_slurp_section_data(abfd);
1587 return (asect->reloc_count+1) * sizeof(arelent *);
1591 DEFUN(ieee_get_section_contents,(abfd, section, location, offset, count),
1596 bfd_size_type count)
1598 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1599 ieee_slurp_section_data(abfd);
1600 (void) memcpy((PTR)location, (PTR)(p->data + offset), (unsigned)count);
1606 DEFUN(ieee_canonicalize_reloc,(abfd, section, relptr, symbols),
1609 arelent **relptr AND
1612 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1613 ieee_reloc_type *src = (ieee_reloc_type *)(section->relocation);
1614 ieee_data_type *ieee = IEEE_DATA(abfd);
1616 while (src != (ieee_reloc_type *)NULL) {
1617 /* Work out which symbol to attach it this reloc to */
1618 switch (src->symbol.letter) {
1620 src->relent.sym_ptr_ptr =
1621 symbols + src->symbol.index + ieee->external_reference_base_offset;
1624 src->relent.sym_ptr_ptr =
1625 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
1631 *relptr++ = &src->relent;
1634 *relptr = (arelent *)NULL;
1635 return section->reloc_count;
1641 DEFUN(comp,(ap, bp),
1645 arelent *a = *((arelent **)ap);
1646 arelent *b = *((arelent **)bp);
1647 return a->address - b->address;
1651 Write the section headers
1655 DEFUN(ieee_write_section_part,(abfd),
1658 ieee_data_type *ieee = IEEE_DATA(abfd);
1660 ieee->w.r.section_part = bfd_tell(abfd);
1661 for (s = abfd->sections; s != (asection *)NULL; s=s->next) {
1662 if (s != &bfd_abs_section)
1665 ieee_write_byte(abfd, ieee_section_type_enum);
1666 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1668 if (abfd->flags & EXEC_P)
1670 /* This image is executable, so output absolute sections */
1671 ieee_write_byte(abfd, ieee_variable_A_enum);
1672 ieee_write_byte(abfd, ieee_variable_S_enum);
1676 ieee_write_byte(abfd, ieee_variable_C_enum);
1679 switch (s->flags &(SEC_CODE | SEC_DATA | SEC_ROM))
1681 case SEC_CODE | SEC_LOAD:
1683 ieee_write_byte(abfd, ieee_variable_P_enum);
1687 ieee_write_byte(abfd, ieee_variable_D_enum);
1690 case SEC_ROM | SEC_DATA:
1691 case SEC_ROM | SEC_LOAD:
1692 case SEC_ROM | SEC_DATA | SEC_LOAD:
1694 ieee_write_byte(abfd, ieee_variable_R_enum);
1698 ieee_write_id(abfd, s->name);
1700 ieee_write_int(abfd, 0); /* Parent */
1701 ieee_write_int(abfd, 0); /* Brother */
1702 ieee_write_int(abfd, 0); /* Context */
1705 ieee_write_byte(abfd, ieee_section_alignment_enum);
1706 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1707 ieee_write_int(abfd, 1 << s->alignment_power);
1710 ieee_write_2bytes(abfd, ieee_section_size_enum);
1711 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1712 ieee_write_int(abfd, s->_raw_size);
1713 if (abfd->flags & EXEC_P) {
1714 /* Relocateable sections don't have asl records */
1716 ieee_write_2bytes(abfd, ieee_section_base_address_enum);
1717 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1718 ieee_write_int(abfd, s->vma);
1728 DEFUN(do_with_relocs,(abfd, s),
1732 unsigned int relocs_to_go = s->reloc_count;
1735 bfd_byte *stream = ieee_per_section(s)->data;
1736 arelent **p = s->orelocation;
1738 bfd_size_type current_byte_index = 0;
1740 qsort(s->orelocation,
1745 /* Output the section preheader */
1746 ieee_write_byte(abfd, ieee_set_current_section_enum);
1747 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1749 ieee_write_twobyte(abfd, ieee_set_current_pc_enum);
1750 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1751 ieee_write_expression(abfd, 0, s->symbol, 0, 0);
1753 if (relocs_to_go == 0)
1755 /* If there arn't any relocations then output the load constant byte
1756 opcode rather than the load with relocation opcode */
1758 while (current_byte_index < s->_raw_size) {
1760 unsigned int MAXRUN = 32;
1762 if (run > s->_raw_size - current_byte_index) {
1763 run = s->_raw_size - current_byte_index;
1767 ieee_write_byte(abfd, ieee_load_constant_bytes_enum);
1768 /* Output a stream of bytes */
1769 ieee_write_int(abfd, run);
1770 bfd_write((PTR)(stream + current_byte_index),
1774 current_byte_index += run;
1780 ieee_write_byte(abfd, ieee_load_with_relocation_enum);
1783 /* Output the data stream as the longest sequence of bytes
1784 possible, allowing for the a reasonable packet size and
1785 relocation stuffs */
1787 if ((PTR)stream == (PTR)NULL) {
1788 /* Outputting a section without data, fill it up */
1789 stream = (uint8e_type *)(bfd_alloc(abfd, s->_raw_size));
1790 memset((PTR)stream, 0, s->_raw_size);
1792 while (current_byte_index < s->_raw_size) {
1794 unsigned int MAXRUN = 32;
1796 run = (*p)->address - current_byte_index;
1801 if (run > s->_raw_size - current_byte_index) {
1802 run = s->_raw_size - current_byte_index;
1806 /* Output a stream of bytes */
1807 ieee_write_int(abfd, run);
1808 bfd_write((PTR)(stream + current_byte_index),
1812 current_byte_index += run;
1814 /* Output any relocations here */
1815 if (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
1816 while (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
1822 if (r->howto->pc_relative) {
1823 r->addend += current_byte_index ;
1827 switch (r->howto->size) {
1830 ov = bfd_get_32(abfd,
1831 stream+current_byte_index);
1832 current_byte_index +=4;
1835 ov = bfd_get_16(abfd,
1836 stream+current_byte_index);
1837 current_byte_index +=2;
1840 ov = bfd_get_8(abfd,
1841 stream+current_byte_index);
1842 current_byte_index ++;
1848 ieee_write_byte(abfd, ieee_function_either_open_b_enum);
1851 if (r->sym_ptr_ptr != (asymbol **)NULL) {
1852 ieee_write_expression(abfd, r->addend + ov,
1854 r->howto->pc_relative, s->index);
1857 ieee_write_expression(abfd, r->addend + ov,
1859 r->howto->pc_relative, s->index);
1862 if (1 || r->howto->size != 2) {
1863 ieee_write_byte(abfd, ieee_comma);
1864 ieee_write_int(abfd, 1<< r->howto->size);
1866 ieee_write_byte(abfd,
1867 ieee_function_either_close_b_enum);
1878 /* If there are no relocations in the output section then we can
1879 be clever about how we write. We block items up into a max of 127
1883 DEFUN(do_as_repeat, (abfd, s),
1888 ieee_write_byte(abfd, ieee_set_current_section_enum);
1889 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1890 ieee_write_byte(abfd, ieee_set_current_pc_enum >> 8);
1891 ieee_write_byte(abfd, ieee_set_current_pc_enum & 0xff);
1892 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1893 ieee_write_int(abfd, s->vma );
1895 ieee_write_byte(abfd,ieee_repeat_data_enum);
1896 ieee_write_int(abfd, s->_raw_size);
1897 ieee_write_byte(abfd, ieee_load_constant_bytes_enum);
1898 ieee_write_byte(abfd, 1);
1899 ieee_write_byte(abfd, 0);
1904 DEFUN(do_without_relocs, (abfd, s),
1908 bfd_byte *stream = ieee_per_section(s)->data;
1910 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
1912 do_as_repeat(abfd, s);
1917 for (i = 0; i < s->_raw_size; i++) {
1918 if (stream[i] != 0) {
1919 do_with_relocs(abfd, s);
1923 do_as_repeat(abfd, s);
1929 static unsigned char *output_ptr_start;
1930 static unsigned char *output_ptr;
1931 static unsigned char *output_ptr_end;
1932 static unsigned char *input_ptr_start;
1933 static unsigned char *input_ptr;
1934 static unsigned char *input_ptr_end;
1935 static bfd *input_bfd;
1936 static bfd *output_bfd;
1937 static int output_buffer;
1941 bfd_read((PTR)input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
1942 input_ptr = input_ptr_start;
1946 bfd_write((PTR)(output_ptr_start),1,output_ptr - output_ptr_start, output_bfd);
1947 output_ptr = output_ptr_start;
1951 #define THIS() ( *input_ptr )
1952 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
1953 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
1955 static void write_int(value)
1958 if (value >= 0 && value <= 127) {
1962 unsigned int length;
1963 /* How many significant bytes ? */
1964 /* FIXME FOR LONGER INTS */
1965 if (value & 0xff000000) {
1968 else if (value & 0x00ff0000) {
1971 else if (value & 0x0000ff00) {
1976 OUT((int)ieee_number_repeat_start_enum + length);
1990 static void copy_id()
1992 int length = THIS();
2002 #define VAR(x) ((x | 0x80))
2003 static void copy_expression()
2012 value = THIS(); NEXT();
2013 value = (value << 8) | THIS(); NEXT();
2014 value = (value << 8) | THIS(); NEXT();
2015 value = (value << 8) | THIS(); NEXT();
2020 value = THIS(); NEXT();
2021 value = (value << 8) | THIS(); NEXT();
2022 value = (value << 8) | THIS(); NEXT();
2027 value = THIS(); NEXT();
2028 value = (value << 8) | THIS(); NEXT();
2033 value = THIS(); NEXT();
2042 /* Not a number, just bug out with the answer */
2043 write_int(*(--tos));
2053 int value = *(--tos);
2061 int section_number ;
2062 ieee_data_type *ieee;
2065 section_number = THIS();
2068 ieee= IEEE_DATA(input_bfd);
2069 s = ieee->section_table[section_number];
2070 if (s->output_section) {
2071 value = s->output_section->vma ;
2072 } else { value = 0; }
2073 value += s->output_offset;
2081 write_int(*(--tos));
2091 /* Drop the int in the buffer, and copy a null into the gap, which we
2092 will overwrite later */
2094 struct output_buffer_struct {
2095 unsigned char *ptrp;
2100 DEFUN(fill_int,(buf),
2101 struct output_buffer_struct *buf)
2103 if (buf->buffer == output_buffer) {
2104 /* Still a chance to output the size */
2105 int value = output_ptr - buf->ptrp + 3;
2106 buf->ptrp[0] = value >> 24;
2107 buf->ptrp[1] = value >> 16;
2108 buf->ptrp[2] = value >> 8;
2109 buf->ptrp[3] = value >> 0;
2114 DEFUN(drop_int,(buf),
2115 struct output_buffer_struct *buf)
2122 case 0x84: ch = THIS(); NEXT();
2123 case 0x83: ch = THIS(); NEXT();
2124 case 0x82: ch = THIS(); NEXT();
2125 case 0x81: ch = THIS(); NEXT();
2130 buf->ptrp = output_ptr;
2131 buf->buffer = output_buffer;
2132 OUT(0);OUT(0);OUT(0);OUT(0);
2135 static void copy_int()
2143 case 0x84: ch = THIS(); NEXT(); OUT(ch);
2144 case 0x83: ch = THIS(); NEXT(); OUT(ch);
2145 case 0x82: ch = THIS(); NEXT(); OUT(ch);
2146 case 0x81: ch = THIS(); NEXT(); OUT(ch);
2152 #define ID copy_id()
2153 #define INT copy_int()
2154 #define EXP copy_expression()
2155 static void copy_till_end();
2156 #define INTn(q) copy_int()
2157 #define EXPn(q) copy_expression()
2158 static void f1_record()
2171 OUT(0xf1); OUT(0xc9);
2172 INT; INT; ch = THIS();
2175 case 0x16: NEXT();break;
2176 case 0x01: NEXT();break;
2177 case 0x00: NEXT(); INT; break;
2178 case 0x03: NEXT(); INT; break;
2179 case 0x13: EXPn(instruction address); break;
2187 OUT(0xf1); OUT(0xd8);
2188 EXP ; EXP; EXP; EXP;
2192 OUT(0xf1);OUT(0xce); INT; INT; ch = THIS(); INT;
2199 EXPn(external function); break;
2202 case 0x07: INTn(line number); INT;
2204 case 0x0a: INTn(locked register); INT; break;
2205 case 0x3f: copy_till_end(); break;
2206 case 0x3e: copy_till_end(); break;
2207 case 0x40: copy_till_end(); break;
2208 case 0x41: ID; break;
2213 static void f0_record()
2215 /* Attribute record */
2221 static void copy_till_end()
2256 static void f2_record()
2268 static void block();
2269 static void f8_record()
2279 /* Unique typedefs for module */
2280 /* GLobal typedefs */
2281 /* High level module scope beginning */
2283 struct output_buffer_struct ob;
2296 /* Global function */
2298 struct output_buffer_struct ob;
2300 OUT(0xf8); OUT(0x04);
2301 drop_int(&ob); ID ; INTn(stack size); INTn(ret val);
2308 EXPn(size of block);
2314 /* File name for source line numbers */
2316 struct output_buffer_struct ob;
2318 OUT(0xf8); OUT(0x05);
2320 ID; INTn(year); INTn(month); INTn(day);
2321 INTn(hour); INTn(monute); INTn(second);
2330 /* Local function */
2331 { struct output_buffer_struct ob;
2332 NEXT(); OUT(0xf8); OUT(0x06);
2334 ID; INTn(stack size); INTn(type return);
2345 /* Assembler module scope beginning -*/
2346 { struct output_buffer_struct ob;
2349 OUT(0xf8); OUT(0x0a);
2351 ID; ID; INT; ID; INT; INT; INT; INT; INT; INT;
2362 struct output_buffer_struct ob;
2364 OUT(0xf8); OUT(0x0b);
2365 drop_int(&ob); ID ; INT; INTn(section index); EXPn(offset); INTn(stuff);
2378 static void e2_record()
2388 static void DEFUN_VOID(block)
2422 moves all the debug information from the source bfd to the output
2423 bfd, and relocates any expressions it finds
2427 DEFUN(relocate_debug,(output, input),
2433 unsigned char input_buffer[IBS];
2435 input_ptr_start = input_ptr = input_buffer;
2436 input_ptr_end = input_buffer + IBS;
2438 bfd_read((PTR)input_ptr_start, 1, IBS, input);
2442 During linking, we we told about the bfds which made up our
2443 contents, we have a list of them. They will still be open, so go to
2444 the debug info in each, and copy it out, relocating it as we go.
2448 DEFUN(ieee_write_debug_part, (abfd),
2451 ieee_data_type *ieee = IEEE_DATA(abfd);
2452 bfd_chain_type *chain = ieee->chain_root;
2453 unsigned char output_buffer[OBS];
2454 boolean some_debug = false;
2455 file_ptr here = bfd_tell(abfd);
2457 output_ptr_start = output_ptr = output_buffer ;
2458 output_ptr_end = output_buffer + OBS;
2459 output_ptr = output_buffer;
2462 if (chain == (bfd_chain_type *)NULL) {
2464 /* There is no debug info, so we'll fake some up */
2465 CONST static char fake[] = {
2466 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
2467 '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 };
2468 ieee->w.r.debug_information_part = 0;
2474 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2475 /* Now write a header for each section */
2478 asection *s = abfd->sections;
2480 if (s != abfd->abs_section)
2483 ieee_write_byte(abfd, 0xf8);
2484 ieee_write_byte(abfd, 0x0b);
2485 ieee_write_byte(abfd, 0);
2486 ieee_write_byte(abfd, 0);
2487 ieee_write_byte(abfd, 1);
2488 ieee_write_byte(abfd, i + IEEE_SECTION_NUMBER_BASE);
2489 ieee_write_expression(abfd, 0, s->symbol, 0, 0, 0);
2490 ieee_write_byte(abfd,0);
2491 ieee_write_byte(abfd, 0xf9);
2492 ieee_write_expression(abfd, s->size,
2493 bfd_abs_section.symbol, 0, 0, 0);
2500 /* Close the scope */
2501 ieee_write_byte(abfd, 0xf9);
2506 while (chain != (bfd_chain_type *)NULL) {
2507 bfd *entry = chain->this;
2508 ieee_data_type *entry_ieee = IEEE_DATA(entry);
2509 if (entry_ieee->w.r.debug_information_part) {
2510 bfd_seek(entry, entry_ieee->w.r.debug_information_part, SEEK_SET);
2511 relocate_debug(abfd, entry);
2514 chain = chain->next;
2517 ieee->w.r.debug_information_part = here;
2520 ieee->w.r.debug_information_part = 0;
2526 /* write the data in an ieee way */
2528 DEFUN(ieee_write_data_part,(abfd),
2532 ieee_data_type *ieee = IEEE_DATA(abfd);
2533 ieee->w.r.data_part = bfd_tell(abfd);
2534 for (s = abfd->sections; s != (asection *)NULL; s = s->next)
2536 /* Sort the reloc records so we can insert them in the correct
2538 if (s->reloc_count != 0)
2540 do_with_relocs(abfd, s);
2544 do_without_relocs(abfd, s);
2552 DEFUN(init_for_output,(abfd),
2556 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
2557 if (s->_raw_size != 0) {
2558 ieee_per_section(s)->data = (bfd_byte *)(bfd_alloc(abfd, s->_raw_size));
2563 /** exec and core file sections */
2565 /* set section contents is complicated with IEEE since the format is
2566 * not a byte image, but a record stream.
2569 DEFUN(ieee_set_section_contents,(abfd, section, location, offset, count),
2574 bfd_size_type count)
2576 if (ieee_per_section(section)->data == (bfd_byte *)NULL) {
2577 init_for_output(abfd);
2579 (void) memcpy((PTR)(ieee_per_section(section)->data + offset),
2581 (unsigned int)count);
2586 write the external symbols of a file, IEEE considers two sorts of
2587 external symbols, public, and referenced. It uses to internal forms
2588 to index them as well. When we write them out we turn their symbol
2589 values into indexes from the right base.
2592 DEFUN(ieee_write_external_part,(abfd),
2596 ieee_data_type *ieee = IEEE_DATA(abfd);
2598 unsigned int reference_index = IEEE_REFERENCE_BASE;
2599 unsigned int public_index = IEEE_PUBLIC_BASE+2;
2600 file_ptr here = bfd_tell(abfd);
2601 boolean hadone = false;
2602 if (abfd->outsymbols != (asymbol **)NULL) {
2604 for (q = abfd->outsymbols; *q != (asymbol *)NULL; q++) {
2607 if (p->section == &bfd_und_section) {
2608 /* This must be a symbol reference .. */
2609 ieee_write_byte(abfd, ieee_external_reference_enum);
2610 ieee_write_int(abfd, reference_index);
2611 ieee_write_id(abfd, p->name);
2612 p->value = reference_index;
2615 else if (bfd_is_com_section (p->section)) {
2616 /* This is a weak reference */
2617 ieee_write_byte(abfd, ieee_external_reference_enum);
2618 ieee_write_int(abfd, reference_index);
2619 ieee_write_id(abfd, p->name);
2620 ieee_write_byte(abfd, ieee_weak_external_reference_enum);
2621 ieee_write_int(abfd, reference_index);
2622 ieee_write_int(abfd, p->value);
2623 ieee_write_int(abfd, BFD_FORT_COMM_DEFAULT_VALUE);
2624 p->value = reference_index;
2627 else if(p->flags & BSF_GLOBAL) {
2628 /* This must be a symbol definition */
2631 ieee_write_byte(abfd, ieee_external_symbol_enum);
2632 ieee_write_int(abfd, public_index );
2633 ieee_write_id(abfd, p->name);
2635 ieee_write_twobyte(abfd, ieee_attribute_record_enum);
2636 ieee_write_int(abfd, public_index );
2637 ieee_write_byte(abfd, 15); /* instruction address */
2638 ieee_write_byte(abfd, 19); /* static symbol */
2639 ieee_write_byte(abfd, 1); /* one of them */
2642 /* Write out the value */
2643 ieee_write_2bytes(abfd, ieee_value_record_enum);
2644 ieee_write_int(abfd, public_index);
2645 if (p->section != &bfd_abs_section)
2647 if (abfd->flags & EXEC_P)
2649 /* If fully linked, then output all symbols
2651 ieee_write_int(abfd,
2652 p->value + p->section->output_offset+ p->section->output_section->vma);
2656 ieee_write_expression(abfd,
2657 p->value + p->section->output_offset,
2658 p->section->output_section->symbol
2664 ieee_write_expression(abfd,
2666 bfd_abs_section.symbol,
2669 p->value = public_index;
2673 /* This can happen - when there are gaps in the symbols read */
2674 /* from an input ieee file */
2679 ieee->w.r.external_part = here;
2684 CONST static unsigned char exten[] =
2687 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
2688 0xf1, 0xce, 0x20, 0x00, 39, 2, /* keep symbol in original case */
2689 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
2692 CONST static unsigned char envi[] =
2696 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
2699 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
2701 0xf1, 0xce, 0x21, 0, 53, 0x03, /* host unix */
2702 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
2707 DEFUN(ieee_write_me_part,(abfd),
2710 ieee_data_type *ieee= IEEE_DATA(abfd);
2711 ieee->w.r.trailer_part = bfd_tell(abfd);
2712 if (abfd->start_address) {
2713 ieee->w.r.me_record = bfd_tell(abfd);
2714 ieee_write_2bytes(abfd, ieee_value_starting_address_enum);
2715 ieee_write_byte(abfd, ieee_function_either_open_b_enum);
2716 ieee_write_int(abfd, abfd->start_address);
2717 ieee_write_byte(abfd, ieee_function_either_close_b_enum);
2720 ieee->w.r.me_record = bfd_tell(abfd);
2722 ieee_write_byte(abfd, ieee_module_end_enum);
2726 DEFUN(ieee_write_object_contents,(abfd),
2729 ieee_data_type *ieee = IEEE_DATA(abfd);
2732 /* Fast forward over the header area */
2733 bfd_seek(abfd, (file_ptr) 0, SEEK_SET);
2734 ieee_write_byte(abfd, ieee_module_beginning_enum);
2736 ieee_write_id(abfd, bfd_printable_name(abfd));
2737 ieee_write_id(abfd, abfd->filename);
2739 /* Fast forward over the variable bits */
2740 ieee_write_byte(abfd, ieee_address_descriptor_enum);
2743 ieee_write_byte(abfd, bfd_arch_bits_per_byte(abfd));
2744 /* MAU's per address */
2745 ieee_write_byte(abfd, bfd_arch_bits_per_address(abfd) /
2746 bfd_arch_bits_per_byte(abfd));
2748 old = bfd_tell(abfd);
2749 bfd_seek(abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR);
2751 ieee->w.r.extension_record = bfd_tell(abfd);
2752 bfd_write((char *)exten, 1, sizeof(exten), abfd);
2753 if (abfd->flags & EXEC_P)
2754 ieee_write_byte(abfd, 0x1); /* Absolute */
2756 ieee_write_byte(abfd, 0x2); /* Relocateable */
2758 ieee->w.r.environmental_record = bfd_tell(abfd);
2759 bfd_write((char *)envi, 1, sizeof(envi), abfd);
2763 ieee_write_section_part(abfd);
2765 First write the symbols, this changes their values into table
2766 indeces so we cant use it after this point
2768 ieee_write_external_part(abfd);
2769 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
2772 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
2776 Write any debugs we have been told about
2778 ieee_write_debug_part(abfd);
2781 Can only write the data once the symbols have been written since
2782 the data contains relocation information which points to the
2785 ieee_write_data_part(abfd);
2789 At the end we put the end !
2791 ieee_write_me_part(abfd);
2794 /* Generate the header */
2795 bfd_seek(abfd, old, SEEK_SET);
2797 for (i= 0; i < N_W_VARIABLES; i++) {
2798 ieee_write_2bytes(abfd,ieee_assign_value_to_variable_enum);
2799 ieee_write_byte(abfd, i);
2800 ieee_write_int5_out(abfd, ieee->w.offset[i]);
2808 /* Native-level interface to symbols. */
2810 /* We read the symbols into a buffer, which is discarded when this
2811 function exits. We read the strings into a buffer large enough to
2812 hold them all plus all the cached symbol entries. */
2815 DEFUN(ieee_make_empty_symbol,(abfd),
2819 ieee_symbol_type *new =
2820 (ieee_symbol_type *)zalloc (sizeof (ieee_symbol_type));
2821 new->symbol.the_bfd = abfd;
2822 return &new->symbol;
2827 DEFUN(ieee_openr_next_archived_file,(arch, prev),
2831 ieee_ar_data_type *ar = IEEE_AR_DATA(arch);
2832 /* take the next one from the arch state, or reset */
2833 if (prev == (bfd *)NULL) {
2834 /* Reset the index - the first two entries are bogus*/
2835 ar->element_index = 2;
2838 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
2839 ar->element_index++;
2840 if (ar->element_index <= ar->element_count) {
2841 if (p->file_offset != (file_ptr)0) {
2842 if (p->abfd == (bfd *)NULL) {
2843 p->abfd = _bfd_create_empty_archive_element_shell(arch);
2844 p->abfd->origin = p->file_offset;
2850 bfd_error = no_more_archived_files;
2858 ieee_find_nearest_line(abfd,
2869 char **filename_ptr;
2870 char **functionname_ptr;
2878 ieee_generic_stat_arch_elt(abfd, buf)
2882 ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
2883 if (ar == (ieee_ar_data_type *)NULL) {
2884 bfd_error = invalid_operation;
2889 buf->st_mode = 0666;
2890 return ! ieee_object_p(abfd);
2894 DEFUN(ieee_sizeof_headers,(abfd, x),
2904 DEFUN(ieee_bfd_debug_info_start,(abfd),
2911 DEFUN(ieee_bfd_debug_info_end,(abfd),
2918 /* Add this section to the list of sections we have debug info for, to
2919 be ready to output it at close time
2922 DEFUN(ieee_bfd_debug_info_accumulate,(abfd, section),
2926 ieee_data_type *ieee = IEEE_DATA(section->owner);
2927 ieee_data_type *output_ieee = IEEE_DATA(abfd);
2928 /* can only accumulate data from other ieee bfds */
2929 if (section->owner->xvec != abfd->xvec)
2931 /* Only bother once per bfd */
2932 if (ieee->done_debug == true)
2934 ieee->done_debug = true;
2936 /* Don't bother if there is no debug info */
2937 if (ieee->w.r.debug_information_part == 0)
2943 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc(abfd, sizeof(bfd_chain_type));
2944 n->this = section->owner;
2945 n->next = (bfd_chain_type *)NULL;
2947 if (output_ieee->chain_head) {
2948 output_ieee->chain_head->next = n;
2951 output_ieee->chain_root = n;
2954 output_ieee->chain_head = n;
2964 #define ieee_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
2965 #define ieee_core_file_failing_signal (int (*)())bfd_0
2966 #define ieee_core_file_matches_executable_p ( FOO(boolean, (*),(bfd *, bfd *)))bfd_false
2967 #define ieee_slurp_armap bfd_true
2968 #define ieee_slurp_extended_name_table bfd_true
2969 #define ieee_truncate_arname (void (*)())bfd_nullvoidptr
2970 #define ieee_write_armap (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, unsigned int, int))) bfd_nullvoidptr
2971 #define ieee_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
2972 #define ieee_close_and_cleanup bfd_generic_close_and_cleanup
2973 #define ieee_set_arch_mach bfd_default_set_arch_mach
2974 #define ieee_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
2975 #define ieee_bfd_relax_section bfd_generic_relax_section
2976 #define ieee_bfd_seclet_link bfd_generic_seclet_link
2977 #define ieee_bfd_reloc_type_lookup \
2978 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
2979 #define ieee_bfd_make_debug_symbol \
2980 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
2983 bfd_target ieee_vec =
2986 bfd_target_ieee_flavour,
2987 true, /* target byte order */
2988 true, /* target headers byte order */
2989 (HAS_RELOC | EXEC_P | /* object flags */
2990 HAS_LINENO | HAS_DEBUG |
2991 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2992 ( SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
2993 |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2994 0, /* leading underscore */
2995 ' ', /* ar_pad_char */
2996 16, /* ar_max_namelen */
2997 1, /* minimum alignment */
2998 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
2999 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
3001 { _bfd_dummy_target,
3002 ieee_object_p, /* bfd_check_format */
3009 _bfd_generic_mkarchive,
3014 ieee_write_object_contents,
3015 _bfd_write_archive_contents,