3 bfd backend for ieee objects.
5 IEEE format is a stream of records, which we parse using a simple one
6 token (which is one byte in this lexicon) lookahead recursive decent
9 On output, this module creates files with the parts in this order:
28 #define obstack_chunk_alloc malloc
29 #define obstack_chunk_free free
31 typedef void generic_symbol_type;
32 static bfd_byte current_c;
34 /***************************************************************************
35 Functions for writing to ieee files in the strange way that the
41 ieee_write_byte(abfd, byte)
45 bfd_write(&byte, 1, 1, abfd);
50 ieee_write_2bytes(abfd, bytes)
55 buffer[0] = bytes >> 8;
56 buffer[1] = bytes & 0xff;
58 bfd_write(buffer, 1, 2, abfd);
62 ieee_write_int(abfd, value)
66 if (value >= 0 && value <= 127) {
67 ieee_write_byte(abfd, value);
71 /* How many significant bytes ? */
72 /* FIXME FOR LONGER INTS */
73 if (value & 0xff000000) {
76 else if (value & 0x00ff0000) {
79 else if (value & 0x0000ff00) {
84 ieee_write_byte(abfd, ieee_number_repeat_start_enum + length);
87 ieee_write_byte(abfd, value >> 24);
89 ieee_write_byte(abfd, value >> 16);
91 ieee_write_byte(abfd, value >> 8);
93 ieee_write_byte(abfd, value);
99 ieee_write_id(abfd, id)
103 size_t length = strlen(id);
104 if (length >= 0 && length <= 127) {
105 ieee_write_byte(abfd, length);
107 else if (length < 255) {
108 ieee_write_byte(abfd, ieee_extension_length_1_enum);
109 ieee_write_byte(abfd, length);
111 else if (length < 65535) {
112 ieee_write_byte(abfd, ieee_extension_length_2_enum);
113 ieee_write_byte(abfd, length >> 8);
114 ieee_write_byte(abfd, length & 0xff);
119 bfd_write((bfd_byte *)id, 1, length, abfd);
121 /***************************************************************************
122 Functions for reading from ieee files in the strange way that the
136 if ( bfd_read(¤t_c, 1, 1, abfd) != 1) {
143 static bfd_byte this_byte_and_next(abfd)
146 bfd_byte r = this_byte(abfd);
153 static unsigned short read_2bytes(abfd)
156 unsigned char c1 = this_byte_and_next(abfd);
157 unsigned char c2 = this_byte_and_next(abfd);
158 return (c1<<8 ) | c2;
163 bfd_get_string(abfd, string, length)
169 for (i= 0; i < length; i++) {
170 string[i] = this_byte_and_next(abfd);
174 static char *read_id(abfd)
179 length = this_byte_and_next(abfd);
180 if (length >= 0x00 && length <= 0x7f) {
181 /* Simple string of length 0 to 127 */
183 else if (length == 0xde) {
184 /* Length is next byte, allowing 0..255 */
185 length = this_byte_and_next(abfd);
187 else if (length == 0xdf) {
188 /* Length is next two bytes, allowing 0..65535 */
189 length = this_byte_and_next(abfd) ;
190 length = (length * 256) + this_byte_and_next(abfd);
192 /* Buy memory and read string */
193 string = malloc(length+1);
194 bfd_get_string(abfd, string, length);
200 ieee_write_expression(abfd, value, section, symbol)
206 unsigned int plus_count = 0;
207 ieee_write_int(abfd, value);
208 if (section != (asection *)NULL) {
210 ieee_write_byte(abfd, ieee_variable_L_enum);
211 ieee_write_byte(abfd, section->index +IEEE_SECTION_NUMBER_BASE);
214 if (symbol != (asymbol *)NULL) {
216 if ((symbol->flags & BSF_UNDEFINED ) ||
217 (symbol->flags & BSF_FORT_COMM)) {
218 ieee_write_byte(abfd, ieee_variable_X_enum);
219 ieee_write_int(abfd, symbol->value);
221 else if (symbol->flags & BSF_GLOBAL) {
222 ieee_write_byte(abfd, ieee_variable_I_enum);
223 ieee_write_int(abfd, symbol->value);
230 while (plus_count != 0) {
231 ieee_write_byte(abfd, ieee_function_plus_enum);
245 /*****************************************************************************/
248 writes any integer into the buffer supplied and always takes 5 bytes
251 ieee_write_int5(buffer, value)
255 buffer[0] = ieee_number_repeat_4_enum;
256 buffer[1] = (value >> 24 ) & 0xff;
257 buffer[2] = (value >> 16 ) & 0xff;
258 buffer[3] = (value >> 8 ) & 0xff;
259 buffer[4] = (value >> 4 ) & 0xff;
265 parse_int(abfd, value_ptr)
269 int value = this_byte(abfd);
271 if (value >= 0 && value <= 127) {
276 else if (value >= 0x80 && value <= 0x88) {
277 unsigned int count = value & 0xf;
281 result =(result << 8) | this_byte_and_next(abfd);
289 static int parse_i(abfd, ok)
294 *ok = parse_int(abfd, &x);
298 static bfd_vma must_parse_int(abfd)
302 BFD_ASSERT(parse_int(abfd, &result) == true);
310 ieee_symbol_index_type symbol;
315 reloc_howto_type abs32_howto
316 = {1,0,2,32,0,0,0,true,0,"abs32",false,0xffffffff};
318 reloc_howto_type abs16_howto
319 = {1,0,1,16,0,0,0,true,0,"abs16",false,0x0000ffff};
321 static ieee_symbol_index_type NOSYMBOL = { 0, 0};
325 frob(abfd, value, section, symbol, pcrel, extra)
329 ieee_symbol_index_type *symbol;
340 ieee_value_type stack[10];
342 /* The stack pointer always points to the next unused location */
343 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
344 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
345 ieee_value_type *sp = stack;
348 switch (this_byte(abfd))
350 case ieee_variable_P_enum:
351 /* P variable, current program counter for section n */
355 section_n = must_parse_int(abfd);
357 TOS.value = ieee_data(abfd)->section_table[section_n]->vma +
358 ieee_per_section(ieee_data(abfd)->section_table[section_n])->pc);
361 case ieee_variable_L_enum:
362 /* L variable address of section N */
364 PUSH(NOSYMBOL,ieee_data(abfd)->section_table[must_parse_int(abfd)],0);
366 case ieee_variable_R_enum:
367 /* R variable, logical address of section module */
368 /* FIXME, this should be different to L */
370 PUSH(NOSYMBOL,ieee_data(abfd)->section_table[must_parse_int(abfd)],0);
372 case ieee_variable_S_enum:
373 /* S variable, size in MAUS of section module */
377 ieee_data(abfd)->section_table[must_parse_int(abfd)]->size);
380 case ieee_variable_X_enum:
381 /* Push the address of external variable n */
383 ieee_symbol_index_type sy;
385 sy.index = (int)(must_parse_int(abfd)) ;
391 case ieee_function_minus_enum:
393 bfd_vma value1, value2;
395 ieee_symbol_index_type sy;
398 POP(sy, section, value1);
399 POP(sy, section, value2);
400 PUSH(NOSYMBOL, 0, value1-value2);
403 case ieee_function_plus_enum:
405 bfd_vma value1, value2;
408 ieee_symbol_index_type sy;
411 POP(sy, section1, value1);
412 POP(sy, section2, value2);
413 PUSH(NOSYMBOL, section1 ? section1: section2, value1+value2);
419 BFD_ASSERT(this_byte(abfd) < ieee_variable_A_enum
420 || this_byte(abfd) > ieee_variable_Z_enum);
421 if (parse_int(abfd, &va))
423 PUSH(NOSYMBOL,0, va);
427 Thats all that we can understand. As far as I can see
428 there is a bug in the Microtec IEEE output which I'm
429 using to scan, whereby the comma operator is ommited
430 sometimes in an expression, giving expressions with too
431 many terms. We can tell if that's the case by ensuring
432 that sp == stack here. If not, then we've pushed
436 POP(*symbol, *section, *value);
438 BFD_ASSERT(*section == 0);
440 /* Get what should be returned */
441 POP(*symbol, *section, *value);
455 ieee_seek(abfd, offset, rel)
460 (void) bfd_seek(abfd, offset, rel);
461 /* Prime look ahead token */
466 ieee_slurp_external_symbols(abfd)
469 ieee_data_type *ieee = ieee_data(abfd);
470 file_ptr offset = ieee->w.r.external_part;
472 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
473 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
474 ieee_symbol_type *symbol;
475 unsigned int symbol_count = 0;
478 ieee->symbol_table_full = true;
480 ieee_seek(abfd, offset ,false);
483 switch (this_byte(abfd)) {
484 case ieee_external_symbol_enum:
486 symbol = (ieee_symbol_type *)malloc(sizeof(ieee_symbol_type));
488 *prev_symbols_ptr = symbol;
489 prev_symbols_ptr= &symbol->next;
490 symbol->index = must_parse_int(abfd);
491 if (symbol->index > ieee->external_symbol_max_index) {
492 ieee->external_symbol_max_index = symbol->index;
494 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
496 symbol->symbol.the_bfd = abfd;
497 symbol->symbol.name = read_id(abfd);
498 symbol->symbol.udata = (void *)NULL;
499 symbol->symbol.flags = BSF_NO_FLAGS;
501 case ieee_attribute_record_enum >> 8:
503 unsigned int symbol_name_index;
504 unsigned int symbol_type_index;
505 unsigned int symbol_attribute_def;
507 next_byte(abfd); /* Skip prefix */
509 symbol_name_index = must_parse_int(abfd);
510 symbol_type_index = must_parse_int(abfd);
511 symbol_attribute_def = must_parse_int(abfd);
513 parse_int(abfd,&value);
517 case ieee_value_record_enum >> 8:
519 unsigned int symbol_name_index;
520 ieee_symbol_index_type symbol_ignore;
521 boolean *pcrel_ignore;
522 unsigned int extra_ignore;
526 symbol_name_index = must_parse_int(abfd);
528 &symbol->symbol.value,
529 &symbol->symbol.section,
533 if (symbol->symbol.section != (asection *)NULL) {
534 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
537 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT | BSF_ABSOLUTE;
541 case ieee_weak_external_reference_enum:
545 /* Throw away the external reference index */
546 (void)must_parse_int(abfd);
547 /* Fetch the default size if not resolved */
548 size = must_parse_int(abfd);
549 /* Fetch the defautlt value if available */
550 if ( parse_int(abfd, &value) == false) {
553 /* This turns into a common */
554 symbol->symbol.flags = BSF_FORT_COMM;
555 symbol->symbol.value = size;
559 case ieee_external_reference_enum:
561 symbol = (ieee_symbol_type *)malloc(sizeof(ieee_symbol_type));
563 *prev_reference_ptr = symbol;
564 prev_reference_ptr = &symbol->next;
565 symbol->index = must_parse_int(abfd);
566 symbol->symbol.the_bfd = abfd;
567 symbol->symbol.name = read_id(abfd);
568 symbol->symbol.udata = (void *)NULL;
569 symbol->symbol.section = (asection *)NULL;
570 symbol->symbol.value = (bfd_vma)0;
571 symbol->symbol.flags = BSF_UNDEFINED;
572 if (symbol->index > ieee->external_reference_max_index) {
573 ieee->external_reference_max_index = symbol->index;
575 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
583 if (ieee->external_symbol_max_index != 0) {
584 ieee->external_symbol_count =
585 ieee->external_symbol_max_index -
586 ieee->external_symbol_min_index + 1 ;
589 ieee->external_symbol_count = 0;
593 if(ieee->external_reference_max_index != 0) {
594 ieee->external_reference_count =
595 ieee->external_reference_max_index -
596 ieee->external_reference_min_index + 1;
599 ieee->external_reference_count = 0;
603 ieee->external_reference_count + ieee->external_symbol_count;
605 if (symbol_count != abfd->symcount) {
606 /* There are gaps in the table -- */
607 ieee->symbol_table_full = false;
609 *prev_symbols_ptr = (ieee_symbol_type *)NULL;
610 *prev_reference_ptr = (ieee_symbol_type *)NULL;
614 ieee_slurp_symbol_table(abfd)
617 if (ieee_data(abfd)->read_symbols == false) {
618 ieee_slurp_external_symbols(abfd);
619 ieee_data(abfd)->read_symbols= true;
624 ieee_get_symtab_upper_bound (abfd)
627 ieee_slurp_symbol_table (abfd);
629 return (abfd->symcount != 0) ?
630 (abfd->symcount+1) * (sizeof (ieee_symbol_type *)) : 0;
634 Move from our internal lists to the canon table, and insert in
638 extern bfd_target ieee_vec;
640 ieee_get_symtab (abfd, location)
644 ieee_symbol_type *symp;
645 static bfd dummy_bfd;
646 static asymbol empty_symbol =
647 { &dummy_bfd," ieee empty",(symvalue)0,BSF_DEBUGGING | BSF_FAKE};
649 ieee_data_type *ieee = ieee_data(abfd);
650 dummy_bfd.xvec= &ieee_vec;
651 ieee_slurp_symbol_table(abfd);
653 if (ieee->symbol_table_full == false) {
654 /* Arrgh - there are gaps in the table, run through and fill them */
655 /* up with pointers to a null place */
657 for (i= 0; i < abfd->symcount; i++) {
658 location[i] = &empty_symbol;
663 ieee->external_symbol_base_offset= - ieee->external_symbol_min_index;
664 for (symp = ieee_data(abfd)->external_symbols;
665 symp != (ieee_symbol_type *)NULL;
667 /* Place into table at correct index locations */
668 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
672 /* The external refs are indexed in a bit */
673 ieee->external_reference_base_offset =
674 - ieee->external_reference_min_index +ieee->external_symbol_count ;
676 for (symp = ieee_data(abfd)->external_reference;
677 symp != (ieee_symbol_type *)NULL;
679 location[symp->index + ieee->external_reference_base_offset] =
686 location[abfd->symcount] = (asymbol *)NULL;
688 return abfd->symcount;
693 ieee_slurp_sections(abfd)
696 ieee_data_type *ieee = ieee_data(abfd);
697 file_ptr offset = ieee->w.r.section_part;
699 asection *section = (asection *)NULL;
702 bfd_byte section_type[3];
703 ieee_seek(abfd, offset, false);
705 switch (this_byte(abfd)) {
706 case ieee_section_type_enum:
708 unsigned int section_index ;
710 section_index = must_parse_int(abfd);
711 /* Fixme to be nice about a silly number of sections */
712 BFD_ASSERT(section_index < NSECTIONS);
714 section = bfd_make_section(abfd, " tempname");
715 ieee->section_table[section_index] = section;
716 section->flags = SEC_NO_FLAGS;
717 section->target_index = section_index;
718 section_type[0] = this_byte_and_next(abfd);
719 switch (section_type[0]) {
721 section_type[1] = this_byte(abfd);
722 section->flags = SEC_LOAD;
723 switch (section_type[1]) {
727 section->flags |= SEC_LOAD | SEC_CODE;
731 section->flags |= SEC_LOAD | SEC_DATA;
736 /* Normal rom data */
737 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
743 section->name = read_id(abfd);
744 { bfd_vma parent, brother, context;
745 parse_int(abfd, &parent);
746 parse_int(abfd, &brother);
747 parse_int(abfd, &context);
753 case ieee_section_alignment_enum:
755 unsigned int section_index;
758 section_index = must_parse_int(abfd);
759 if (section_index > ieee->section_count) {
760 ieee->section_count = section_index;
762 ieee->section_table[section_index]->alignment_power =
763 bfd_log2(must_parse_int(abfd));
764 (void)parse_int(abfd, & value);
767 case ieee_e2_first_byte_enum:
769 ieee_record_enum_type t = read_2bytes(abfd);
771 case ieee_section_size_enum:
772 section = ieee->section_table[must_parse_int(abfd)];
773 section->size = must_parse_int(abfd);
775 case ieee_physical_region_size_enum:
776 section = ieee->section_table[must_parse_int(abfd)];
777 section->size = must_parse_int(abfd);
779 case ieee_region_base_address_enum:
780 section = ieee->section_table[must_parse_int(abfd)];
781 section->vma = must_parse_int(abfd);
783 case ieee_mau_size_enum:
784 must_parse_int(abfd);
785 must_parse_int(abfd);
787 case ieee_m_value_enum:
788 must_parse_int(abfd);
789 must_parse_int(abfd);
791 case ieee_section_base_address_enum:
792 section = ieee->section_table[must_parse_int(abfd)];
793 section->vma = must_parse_int(abfd);
795 case ieee_section_offset_enum:
796 (void) must_parse_int(abfd);
797 (void) must_parse_int(abfd);
811 /***********************************************************************
820 ieee_ar_data_type *ar;
822 ieee_seek(abfd, (file_ptr) 0, false);
823 if (this_byte(abfd) != Module_Beginning) return (bfd_target*)NULL;
825 library= read_id(abfd);
826 if (strcmp(library , "LIBRARY") != 0) {
828 return (bfd_target *)NULL;
830 /* Throw away the filename */
831 free( read_id(abfd));
832 /* This must be an IEEE archive, so we'll buy some space to do
834 ar = (ieee_ar_data_type *) malloc(sizeof(ieee_ar_data_type));
835 ieee_ar_data(abfd) = ar;
836 ar->element_count = 0;
837 ar->element_index = 0;
838 obstack_init(&ar->element_obstack);
840 next_byte(abfd); /* Drop the ad part */
841 must_parse_int(abfd); /* And the two dummy numbers */
842 must_parse_int(abfd);
845 /* Read the index of the BB table */
847 ieee_ar_obstack_type t;
848 int rec =read_2bytes(abfd);
849 if (rec ==ieee_assign_value_to_variable_enum) {
850 int record_number = must_parse_int(abfd);
851 t.file_offset = must_parse_int(abfd);
852 t.abfd = (bfd *)NULL;
854 obstack_grow(&ar->element_obstack, &t, sizeof(t));
858 ar->elements = (ieee_ar_obstack_type *)obstack_base(&ar->element_obstack);
860 /* Now scan the area again, and replace BB offsets with file */
864 for (i = 2; i < ar->element_count; i++) {
865 ieee_seek(abfd, ar->elements[i].file_offset, false);
866 next_byte(abfd); /* Drop F8 */
867 next_byte(abfd); /* Drop 14 */
868 must_parse_int(abfd); /* Drop size of block */
869 if (must_parse_int(abfd) != 0) {
870 /* This object has been deleted */
871 ar->elements[i].file_offset = 0;
874 ar->elements[i].file_offset = must_parse_int(abfd);
878 obstack_finish(&ar->element_obstack);
889 ieee_seek(abfd, (file_ptr)0, false);
892 if (this_byte(abfd) != Module_Beginning) return (bfd_target*)NULL;
896 ieee.read_symbols= false;
897 ieee.read_data= false;
898 ieee.section_count = 0;
899 ieee.external_symbol_max_index = 0;
900 ieee.external_symbol_min_index = IEEE_PUBLIC_BASE;
901 ieee.external_reference_min_index =IEEE_REFERENCE_BASE;
902 ieee.external_reference_max_index = 0;
903 memset((PTR)ieee.section_table, 0, sizeof(ieee.section_table));
905 processor = ieee.mb.processor = read_id(abfd);
906 if (strcmp(processor,"LIBRARY") == 0) return (bfd_target *)NULL;
907 ieee.mb.module_name = read_id(abfd);
908 if (abfd->filename == (char *)NULL) {
909 abfd->filename = ieee.mb.module_name;
911 /* Determine the architecture and machine type of the object file. */
912 bfd_scan_arch_mach(processor, &abfd->obj_arch, &abfd->obj_machine);
914 if (this_byte(abfd) != ieee_address_descriptor_enum) {
915 return (bfd_target *)NULL;
919 if (parse_int(abfd, &ieee.ad.number_of_bits_mau) == false) {
920 return (bfd_target *)NULL;
922 if(parse_int(abfd, &ieee.ad.number_of_maus_in_address) == false) {
923 return (bfd_target *)NULL;
926 /* If there is a byte order info, take it */
927 if (this_byte(abfd) == ieee_variable_L_enum ||
928 this_byte(abfd) == ieee_variable_M_enum)
932 for (part = 0; part < N_W_VARIABLES; part++) {
934 if (read_2bytes(abfd) != ieee_assign_value_to_variable_enum) {
935 return (bfd_target *)NULL;
937 if (this_byte_and_next(abfd) != part) {
938 return (bfd_target *)NULL;
942 ieee.w.offset[part] = parse_i(abfd, &ok);
944 return (bfd_target *)NULL;
948 abfd->flags = HAS_SYMS;
950 /* Read in the section info */
951 ieee_data(abfd) = (ieee_data_type *)(malloc(sizeof(ieee_data_type)));
952 memcpy(ieee_data(abfd), &ieee, sizeof(ieee));
953 ieee_slurp_sections(abfd);
959 ieee_print_symbol(ignore_abfd, file, symbol, how)
963 bfd_print_symbol_enum_type how;
967 case bfd_print_symbol_name_enum:
968 fprintf(file,"%s", symbol->name);
970 case bfd_print_symbol_type_enum:
972 fprintf(file,"%4x %2x",aout_symbol(symbol)->desc & 0xffff,
973 aout_symbol(symbol)->other & 0xff);
977 case bfd_print_symbol_all_enum:
979 char *section_name = symbol->section == (asection *)NULL ?
980 "*abs" : symbol->section->name;
982 bfd_print_symbol_vandf((void *)file,symbol);
984 fprintf(file," %-5s %04x %02x %s",
986 (unsigned) ieee_symbol(symbol)->index,
988 aout_symbol(symbol)->desc & 0xffff,
989 aout_symbol(symbol)->other & 0xff,*/
998 /* Read in all the section data and relocation stuff too */
999 static boolean ieee_slurp_section_data(abfd)
1002 bfd_byte *location_ptr ;
1003 ieee_data_type *ieee = ieee_data(abfd);
1004 unsigned int section_number ;
1006 ieee_per_section_type *current_map;
1008 /* Seek to the start of the data area */
1009 if (ieee->read_data== true) return true;
1010 ieee->read_data = true;
1011 ieee_seek(abfd, ieee->w.r.data_part, false);
1013 /* Allocate enough space for all the section contents */
1016 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
1017 ieee_per_section_type *per = s->used_by_bfd;
1018 per->data = (bfd_byte *) malloc(s->size);
1020 obstack_init( &per->reloc_obstack);
1021 per->reloc_tail_ptr =
1022 (ieee_reloc_type **)&(s->relocation);
1028 switch (this_byte(abfd))
1030 /* IF we see anything strange then quit */
1034 case ieee_set_current_section_enum:
1036 section_number = must_parse_int(abfd);
1037 s = ieee->section_table[section_number];
1038 current_map = s->used_by_bfd;
1039 location_ptr = current_map->data - s->vma;
1040 /* The document I have says that Microtec's compilers reset */
1041 /* this after a sec section, even though the standard says not */
1043 current_map->pc =s->vma;
1046 case ieee_load_constant_bytes_enum:
1048 unsigned int number_of_maus;
1051 number_of_maus = must_parse_int(abfd);
1053 for (i = 0; i < number_of_maus; i++) {
1054 location_ptr[current_map->pc++]= this_byte(abfd);
1060 case ieee_e2_first_byte_enum:
1062 switch (this_byte(abfd))
1064 case ieee_set_current_pc_enum & 0xff:
1068 ieee_symbol_index_type symbol;
1072 must_parse_int(abfd); /* Thow away section #*/
1073 frob(abfd, &value, &dsection, &symbol, &pcrel, &extra);
1074 current_map->pc = value;
1075 BFD_ASSERT((unsigned)(value - s->vma) < s->size);
1079 case ieee_value_starting_address_enum & 0xff:
1080 /* We've got to the end of the data now - */
1088 case ieee_load_with_relocation_enum:
1090 boolean loop = true;
1094 switch (this_byte(abfd))
1096 case ieee_variable_R_enum:
1098 case ieee_function_signed_open_b_enum:
1099 case ieee_function_unsigned_open_b_enum:
1100 case ieee_function_either_open_b_enum:
1105 ieee_reloc_type *r =
1107 obstack_alloc( ¤t_map->reloc_obstack,
1108 sizeof(ieee_reloc_type));
1110 *(current_map->reloc_tail_ptr) = r;
1111 current_map->reloc_tail_ptr= &r->next;
1112 r->next = (ieee_reloc_type *)NULL;
1120 r->relent.address = current_map->pc;
1122 switch (this_byte(abfd)) {
1123 case ieee_function_signed_close_b_enum:
1126 case ieee_function_unsigned_close_b_enum:
1129 case ieee_function_either_close_b_enum:
1135 /* Build a relocation entry for this type */
1136 if (this_byte(abfd) == ieee_comma) {
1139 /* Fetch number of bytes to pad */
1140 extra = must_parse_int(abfd);
1146 location_ptr[current_map->pc++] = 0;
1147 location_ptr[current_map->pc++] = 0;
1148 location_ptr[current_map->pc++] = 0;
1149 location_ptr[current_map->pc++] = 0;
1150 r->relent.howto = &abs32_howto;
1153 location_ptr[current_map->pc++] = 0;
1154 location_ptr[current_map->pc++] = 0;
1155 r->relent.howto = &abs16_howto;
1167 if (parse_int(abfd, &this_size) == true) {
1169 for (i = 0; i < this_size; i++) {
1170 location_ptr[current_map->pc ++] = this_byte(abfd);
1188 ieee_new_section_hook (abfd, newsect)
1192 newsect->used_by_bfd = (ieee_per_section_type *)
1193 malloc(sizeof(ieee_per_section_type));
1194 ieee_per_section( newsect)->data = (bfd_byte *)NULL;
1195 ieee_per_section(newsect)->section = newsect;
1201 ieee_get_reloc_upper_bound (abfd, asect)
1205 ieee_slurp_section_data(abfd);
1206 return (asect->reloc_count+1) * sizeof(arelent *);
1210 ieee_get_section_contents (abfd, section, location, offset, count)
1217 ieee_per_section_type *p = section->used_by_bfd;
1218 ieee_slurp_section_data(abfd);
1219 (void) memcpy(location, p->data + offset, count);
1225 ieee_canonicalize_reloc (abfd, section, relptr, symbols)
1231 ieee_per_section_type *p = section->used_by_bfd;
1232 ieee_reloc_type *src = (ieee_reloc_type *)(section->relocation);
1233 ieee_data_type *ieee = ieee_data(abfd);
1235 while (src != (ieee_reloc_type *)NULL) {
1236 /* Work out which symbol to attatch it this reloc to */
1237 switch (src->symbol.letter) {
1239 src->relent.sym_ptr_ptr =
1240 symbols + src->symbol.index + ieee->external_reference_base_offset;
1243 src->relent.sym_ptr_ptr = (asymbol **)NULL;
1249 *relptr++ = &src->relent;
1252 *relptr = (arelent *)NULL;
1253 return section->reloc_count;
1257 ieee_set_arch_mach (abfd, arch, machine)
1259 enum bfd_architecture arch;
1260 unsigned long machine;
1262 abfd->obj_arch = arch;
1263 abfd->obj_machine = machine;
1271 ieee_data_type *ieee = (ieee_data_type *) malloc(sizeof(ieee_data_type));
1272 ieee_data(abfd) = ieee;
1273 if (ieee == (ieee_data_type *)NULL) {
1274 bfd_error = no_memory;
1282 static int comp(ap, bp)
1288 return a->address - b->address;
1291 Write the section headers
1295 ieee_write_section_part(abfd)
1298 ieee_data_type *ieee = ieee_data(abfd);
1300 ieee->w.r.section_part = bfd_tell(abfd);
1301 for (s = abfd->sections; s != (asection *)NULL; s=s->next) {
1302 ieee_write_byte(abfd, ieee_section_type_enum);
1303 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1305 switch (s->flags & (SEC_LOAD | SEC_CODE | SEC_DATA | SEC_ROM)) {
1306 case SEC_LOAD | SEC_CODE:
1307 /* Normal named section, code */
1308 ieee_write_byte(abfd, ieee_variable_C_enum);
1309 ieee_write_byte(abfd, ieee_variable_P_enum);
1311 case SEC_LOAD | SEC_DATA:
1312 /* Normal named section, data */
1313 ieee_write_byte(abfd, ieee_variable_C_enum);
1314 ieee_write_byte(abfd, ieee_variable_D_enum);
1316 case SEC_LOAD | SEC_DATA | SEC_ROM:
1317 /* Normal named section, data rom */
1318 ieee_write_byte(abfd, ieee_variable_C_enum);
1319 ieee_write_byte(abfd, ieee_variable_R_enum);
1322 ieee_write_byte(abfd, ieee_variable_C_enum);
1326 ieee_write_id(abfd, s->name);
1327 ieee_write_int(abfd, 0); /* Parent */
1328 ieee_write_int(abfd, 0); /* Brother */
1329 ieee_write_int(abfd, 0); /* Context */
1332 ieee_write_byte(abfd, ieee_section_alignment_enum);
1333 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1334 ieee_write_int(abfd, 1 << s->alignment_power);
1337 ieee_write_2bytes(abfd, ieee_section_size_enum);
1338 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1339 ieee_write_int(abfd, s->size);
1342 ieee_write_2bytes(abfd, ieee_region_base_address_enum);
1343 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1344 ieee_write_int(abfd, s->vma);
1351 /* write the data in an ieee way */
1353 ieee_write_data_part(abfd)
1357 ieee_data_type *ieee = ieee_data(abfd);
1358 ieee->w.r.data_part = bfd_tell(abfd);
1359 for (s = abfd->sections; s != (asection *)NULL; s = s->next)
1361 bfd_byte header[11];
1362 bfd_byte *stream = ieee_per_section(s)->data;
1363 arelent **p = s->orelocation;
1364 size_t current_byte_index = 0;
1365 /* Sort the reloc records so we can insert them in the correct places */
1366 if (s->reloc_count != 0) {
1367 qsort(s->orelocation,
1374 /* Output the section preheader */
1375 header[0] =ieee_set_current_section_enum;
1376 header[1] = s->index + IEEE_SECTION_NUMBER_BASE;
1378 header[2] = ieee_set_current_pc_enum >> 8;
1379 header[3]= ieee_set_current_pc_enum & 0xff;
1380 header[4] = s->index + IEEE_SECTION_NUMBER_BASE;
1381 ieee_write_int5(header+5, s->vma );
1382 header[10] = ieee_load_with_relocation_enum;
1383 bfd_write(header, 1, sizeof(header), abfd);
1385 /* Output the data stream as the longest sequence of bytes possible, */
1386 /* allowing for the a reasonable packet size and relocation stuffs */
1387 if (stream == (void *)NULL) {
1388 stream = (bfd_byte *)"UNINITIALIZED AREA! ";
1389 s->size = strlen(stream);
1391 while (current_byte_index < s->size) {
1393 unsigned int MAXRUN = 32;
1395 run = (*p)->address - current_byte_index;
1400 if (run > s->size - current_byte_index) {
1401 run = s->size - current_byte_index;
1405 /* Output a stream of bytes */
1406 bfd_byte header[1] ;
1408 bfd_write(header, 1, sizeof(header), abfd);
1409 bfd_write(stream + current_byte_index,
1413 current_byte_index += run;
1415 /* Output any relocations here */
1416 if (p && (*p) && (*p)->address == current_byte_index) {
1417 while ((*p) && (*p)->address == current_byte_index) {
1420 ieee_write_byte(abfd, ieee_function_either_open_b_enum);
1421 if (r->sym_ptr_ptr != (asymbol **)NULL) {
1422 ieee_write_expression(abfd, r->addend,
1427 ieee_write_expression(abfd, r->addend,
1431 ieee_write_byte(abfd, ieee_function_either_close_b_enum);
1434 /* FIXME !! Are all relocations 4 bytes ? */
1435 current_byte_index += 4;
1447 init_for_output(abfd)
1451 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
1453 ieee_per_section(s)->data = (bfd_byte *)(malloc(s->size));
1458 /** exec and core file sections */
1460 /* set section contents is complicated with IEEE since the format is
1461 * not a byte image, but a record stream.
1464 ieee_set_section_contents (abfd, section, location, offset, count)
1467 unsigned char *location;
1471 if (ieee_per_section(section)->data == (bfd_byte *)NULL) {
1472 init_for_output(abfd);
1474 (void) memcpy(ieee_per_section(section)->data + offset, location, count);
1479 write the external symbols of a file, IEEE considers two sorts of
1480 external symbols, public, and referenced. It uses to internal forms
1481 to index them as well. When we write them out we turn their symbol
1482 values into indexes from the right base.
1485 ieee_write_external_part(abfd)
1489 ieee_data_type *ieee = ieee_data(abfd);
1491 unsigned int reference_index = IEEE_REFERENCE_BASE;
1492 unsigned int public_index = IEEE_PUBLIC_BASE;
1493 ieee->w.r.external_part = bfd_tell(abfd);
1494 if (abfd->outsymbols != (asymbol **)NULL) {
1495 for (q = abfd->outsymbols; *q != (asymbol *)NULL; q++) {
1497 if (p->flags & BSF_UNDEFINED) {
1498 /* This must be a symbol reference .. */
1499 ieee_write_byte(abfd, ieee_external_reference_enum);
1500 ieee_write_int(abfd, reference_index);
1501 ieee_write_id(abfd, p->name);
1502 p->value = reference_index;
1505 else if(p->flags & BSF_FORT_COMM) {
1506 /* This is a weak reference */
1507 ieee_write_byte(abfd, ieee_external_reference_enum);
1508 ieee_write_int(abfd, reference_index);
1509 ieee_write_id(abfd, p->name);
1510 ieee_write_byte(abfd, ieee_weak_external_reference_enum);
1511 ieee_write_int(abfd, reference_index);
1512 ieee_write_int(abfd, p->value);
1513 ieee_write_int(abfd, BFD_FORT_COMM_DEFAULT_VALUE);
1514 p->value = reference_index;
1517 else if(p->flags & BSF_GLOBAL) {
1518 /* This must be a symbol definition */
1520 ieee_write_byte(abfd, ieee_external_symbol_enum);
1521 ieee_write_int(abfd, public_index );
1522 ieee_write_id(abfd, p->name);
1524 /* Write out the value */
1525 ieee_write_2bytes(abfd, ieee_value_record_enum);
1526 ieee_write_int(abfd, public_index);
1527 if (p->section != (asection *)NULL)
1529 ieee_write_expression(abfd,
1530 p->value + p->section->output_offset,
1531 p->section->output_section,
1536 ieee_write_expression(abfd,
1541 p->value = public_index;
1545 /* This can happen - when there are gaps in the symbols read */
1546 /* from an input ieee file */
1554 void ieee_write_me_part(abfd)
1557 ieee_data_type *ieee= ieee_data(abfd);
1558 ieee->w.r.me_record = bfd_tell(abfd);
1560 ieee_write_2bytes(abfd, ieee_value_starting_address_enum);
1561 ieee_write_int(abfd, abfd->start_address);
1562 ieee_write_byte(abfd, ieee_module_end_enum);
1566 ieee_write_object_contents (abfd)
1569 ieee_data_type *ieee = ieee_data(abfd);
1572 /* Make a guess about the size of the header */
1573 bfd_seek(abfd, 100, false);
1575 First write the symbols, this changes their values into table
1576 indeces so we cant use it after this point
1578 ieee_write_external_part(abfd);
1579 ieee_write_byte(abfd, ieee_record_seperator_enum);
1581 ieee_write_section_part(abfd);
1582 ieee_write_byte(abfd, ieee_record_seperator_enum);
1584 Can only write the data once the symbols have been written since
1585 the data contains relocation information which points to the
1588 ieee_write_data_part(abfd);
1589 ieee_write_byte(abfd, ieee_record_seperator_enum);
1592 At the end we put the end !
1594 ieee_write_me_part(abfd);
1595 /* Now write the header */
1596 /* Generate the header */
1597 bfd_seek(abfd, (file_ptr)0, false);
1600 ieee_write_byte(abfd, ieee_module_beginning_enum);
1602 ieee_write_id(abfd, bfd_printable_arch_mach(abfd->obj_arch,
1603 abfd->obj_machine));
1604 ieee_write_id(abfd, abfd->filename);
1605 ieee_write_byte(abfd, ieee_address_descriptor_enum);
1606 ieee_write_byte(abfd, 8); /* Bits per MAU */
1607 ieee_write_byte(abfd, 4); /* MAU's per address */
1610 for (i= 0; i < N_W_VARIABLES; i++) {
1611 ieee_write_2bytes(abfd,ieee_assign_value_to_variable_enum);
1612 ieee_write_byte(abfd, i);
1613 ieee_write_int(abfd, ieee->w.offset[i]);
1621 /* Native-level interface to symbols. */
1623 /* We read the symbols into a buffer, which is discarded when this
1624 function exits. We read the strings into a buffer large enough to
1625 hold them all plus all the cached symbol entries. */
1628 ieee_make_empty_symbol (abfd)
1632 ieee_symbol_type *new =
1633 (ieee_symbol_type *)zalloc (sizeof (ieee_symbol_type));
1634 new->symbol.the_bfd = abfd;
1635 return &new->symbol;
1640 ieee_reclaim_symbol_table (abfd)
1646 if (!bfd_get_symcount (abfd)) return;
1648 for (section = abfd->sections; section != NULL; section = section->next)
1649 if (section->relocation) {
1650 free ((void *)section->relocation);
1651 section->relocation = NULL;
1652 section->reloc_count = 0;
1655 bfd_get_symcount (abfd) = 0;
1656 free ((void *)obj_aout_symbols (abfd));
1657 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
1664 /* Obsolete procedural interface; better to look at the cache directly */
1666 /* User should have checked the file flags; perhaps we should return
1667 BFD_NO_MORE_SYMBOLS if there are none? */
1670 ieee_get_symcount_upper_bound (abfd)
1674 /* In case we're doing an output file or something...? */
1675 if (bfd_get_symcount (abfd)) return bfd_get_symcount (abfd);
1677 return (exec_hdr (abfd)->a_syms) / (sizeof (struct nlist));
1683 ieee_get_first_symbol (ignore_abfd)
1690 ieee_get_next_symbol (abfd, oidx)
1695 if (oidx == BFD_NO_MORE_SYMBOLS) return BFD_NO_MORE_SYMBOLS;
1696 return ++oidx >= bfd_get_symcount (abfd) ? BFD_NO_MORE_SYMBOLS :
1703 ieee_symbol_name (abfd, idx)
1708 return (obj_aout_symbols (abfd) + idx)->symbol.name;
1714 ieee_symbol_value (abfd, idx)
1719 return (obj_aout_symbols (abfd) + idx)->symbol.value;
1725 ieee_classify_symbol (abfd, idx)
1730 aout_symbol_type *sym = obj_aout_symbols (abfd) + idx;
1732 if ((sym->symbol.flags & BSF_FORT_COMM) != 0) return bfd_symclass_fcommon;
1733 if ((sym->symbol.flags & BSF_GLOBAL) != 0) return bfd_symclass_global;
1734 if ((sym->symbol.flags & BSF_DEBUGGING) != 0) return bfd_symclass_debugger;
1735 if ((sym->symbol.flags & BSF_UNDEFINED) != 0) return bfd_symclass_undefined;
1737 return bfd_symclass_unknown;
1741 ieee_symbol_hasclass (abfd, idx, class)
1747 aout_symbol_type *sym = obj_aout_symbols (abfd) + idx;
1749 case bfd_symclass_fcommon:
1750 return (sym->symbol.flags & BSF_FORT_COMM) ? true :false;
1751 case bfd_symclass_global:
1752 return (sym->symbol.flags & BSF_GLOBAL) ? true:false;
1753 case bfd_symclass_debugger:
1754 return (sym->symbol.flags & BSF_DEBUGGING) ? true:false;;
1755 case bfd_symclass_undefined:
1756 return (sym->symbol.flags & BSF_UNDEFINED) ? true:false;;
1757 default: return false;
1765 ieee_reclaim_reloc (ignore_abfd, section)
1770 if (section->relocation) {
1771 free (section->relocation);
1772 section->relocation = NULL;
1773 section->reloc_count = 0;
1779 ieee_close_and_cleanup (abfd)
1782 if (bfd_read_p (abfd) == false)
1783 switch (abfd->format) {
1785 if (!_bfd_write_archive_contents (abfd)) {
1790 if (!ieee_write_object_contents (abfd)) {
1795 bfd_error = invalid_operation;
1800 if (ieee_data(abfd) != (ieee_data_type *)NULL) {
1801 /* FIXME MORE LEAKS */
1809 ieee_openr_next_archived_file(arch, prev)
1813 ieee_ar_data_type *ar = ieee_ar_data(arch);
1814 /* take the next one from the arch state, or reset */
1815 if (prev == (bfd *)NULL) {
1816 /* Reset the index - the first two entries are bogus*/
1817 ar->element_index = 2;
1820 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
1821 ar->element_index++;
1822 if (ar->element_index <= ar->element_count) {
1823 if (p->file_offset != (file_ptr)0) {
1824 if (p->abfd == (bfd *)NULL) {
1825 p->abfd = _bfd_create_empty_archive_element_shell(arch);
1826 p->abfd->origin = p->file_offset;
1839 ieee_find_nearest_line(abfd,
1850 char **filename_ptr;
1851 char **functionname_ptr;
1852 unsigned int *line_ptr;
1858 bfd_target ieee_vec =
1861 bfd_target_ieee_flavour_enum,
1862 true, /* target byte order */
1863 true, /* target headers byte order */
1864 (HAS_RELOC | EXEC_P | /* object flags */
1865 HAS_LINENO | HAS_DEBUG |
1866 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
1867 (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
1868 |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1869 0, /* valid reloc types */
1870 ' ', /* ar_pad_char */
1871 16, /* ar_max_namelen */
1872 ieee_close_and_cleanup, /* _close_and_cleanup */
1873 ieee_set_section_contents, /* bfd_set_section_contents */
1874 ieee_get_section_contents,
1875 ieee_new_section_hook, /* new_section_hook */
1876 0, /* _core_file_failing_command */
1877 0, /* _core_file_failing_signal */
1878 0, /* _core_file_matches_ex...p */
1880 0, /* bfd_slurp_bsd_armap, bfd_slurp_armap */
1881 bfd_true, /* bfd_slurp_extended_name_table */
1882 bfd_bsd_truncate_arname, /* bfd_truncate_arname */
1884 ieee_get_symtab_upper_bound, /* get_symtab_upper_bound */
1885 ieee_get_symtab, /* canonicalize_symtab */
1886 0, /* ieee_reclaim_symbol_table, bfd_reclaim_symbol_table */
1887 ieee_get_reloc_upper_bound, /* get_reloc_upper_bound */
1888 ieee_canonicalize_reloc, /* bfd_canonicalize_reloc */
1889 0, /* ieee_reclaim_reloc, bfd_reclaim_reloc */
1890 0, /* ieee_get_symcount_upper_bound, bfd_get_symcount_upper_bound */
1891 0, /* ieee_get_first_symbol, bfd_get_first_symbol */
1892 0, /* ieee_get_next_symbol, bfd_get_next_symbol */
1893 0, /* ieee_classify_symbol, bfd_classify_symbol */
1894 0, /* ieee_symbol_hasclass, bfd_symbol_hasclass */
1895 0, /* ieee_symbol_name, bfd_symbol_name */
1896 0, /* ieee_symbol_value, bfd_symbol_value */
1898 _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* data */
1899 _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* hdrs */
1902 ieee_object_p, /* bfd_check_format */
1909 _bfd_generic_mkarchive,
1912 ieee_make_empty_symbol,
1914 bfd_false, /* ieee_get_lineno,*/
1915 ieee_set_arch_mach, /* bfd_set_arch_mach,*/
1917 ieee_openr_next_archived_file,
1918 ieee_find_nearest_line, /* bfd_find_nearest_line */