Minor changes to accomodate merging of three include file directories.
[deliverable/binutils-gdb.git] / bfd / ieee.c
1 /*
2
3 bfd backend for ieee objects.
4
5
6
7 IEEE 695 format is a stream of records, which we parse using a simple one
8 token (which is one byte in this lexicon) lookahead recursive decent
9 parser.
10
11
12 */
13
14
15 #include "sysdep.h"
16 #include "bfd.h"
17 #include "libbfd.h"
18 #include "obstack.h"
19 #include "ieee.h"
20 #include "libieee.h"
21
22
23 #define obstack_chunk_alloc malloc
24 #define obstack_chunk_free free
25 #define ieee_malloc(abfd,size) \
26 obstack_alloc(&( ieee_data(abfd)->ieee_obstack), (size))
27
28 typedef void generic_symbol_type;
29
30
31 /***************************************************************************
32 Functions for writing to ieee files in the strange way that the
33 standard requires:
34 */
35
36
37 static void
38 DEFUN(ieee_write_byte,(abfd, byte),
39 bfd *abfd AND
40 bfd_byte byte)
41 {
42 bfd_write(&byte, 1, 1, abfd);
43 }
44
45
46 static void
47 DEFUN(ieee_write_2bytes,(abfd, bytes),
48 bfd *abfd AND
49 int bytes)
50 {
51 bfd_byte buffer[2];
52 buffer[0] = bytes >> 8;
53 buffer[1] = bytes & 0xff;
54
55 bfd_write(buffer, 1, 2, abfd);
56 }
57
58 static void
59 DEFUN(ieee_write_int,(abfd, value),
60 bfd *abfd AND
61 bfd_vma value)
62 {
63 if (value >= 0 && value <= 127) {
64 ieee_write_byte(abfd, value);
65 }
66 else {
67 unsigned int length;
68 /* How many significant bytes ? */
69 /* FIXME FOR LONGER INTS */
70 if (value & 0xff000000) {
71 length = 4;
72 }
73 else if (value & 0x00ff0000) {
74 length = 3;
75 }
76 else if (value & 0x0000ff00) {
77 length = 2;
78 }
79 else length = 1;
80
81 ieee_write_byte(abfd, ieee_number_repeat_start_enum + length);
82 switch (length) {
83 case 4:
84 ieee_write_byte(abfd, value >> 24);
85 case 3:
86 ieee_write_byte(abfd, value >> 16);
87 case 2:
88 ieee_write_byte(abfd, value >> 8);
89 case 1:
90 ieee_write_byte(abfd, value);
91 }
92 }
93 }
94
95 static void
96 DEFUN(ieee_write_id,(abfd, id),
97 bfd *abfd AND
98 CONST char *id)
99 {
100 size_t length = strlen(id);
101 if (length >= 0 && length <= 127) {
102 ieee_write_byte(abfd, length);
103 }
104 else if (length < 255) {
105 ieee_write_byte(abfd, ieee_extension_length_1_enum);
106 ieee_write_byte(abfd, length);
107 }
108 else if (length < 65535) {
109 ieee_write_byte(abfd, ieee_extension_length_2_enum);
110 ieee_write_byte(abfd, length >> 8);
111 ieee_write_byte(abfd, length & 0xff);
112 }
113 else {
114 BFD_FAIL();
115 }
116 bfd_write((bfd_byte *)id, 1, length, abfd);
117 }
118 /***************************************************************************
119 Functions for reading from ieee files in the strange way that the
120 standard requires:
121 */
122
123 #define this_byte(abfd) *(ptr(abfd))
124 #define next_byte(abfd) (ptr(abfd)++)
125 #define this_byte_and_next(abfd) *(ptr(abfd)++)
126
127
128 static unsigned short
129 DEFUN(read_2bytes,(abfd),
130 bfd *abfd)
131 {
132 unsigned char c1 = this_byte_and_next(abfd);
133 unsigned char c2 = this_byte_and_next(abfd);
134 return (c1<<8 ) | c2;
135
136 }
137
138 static void
139 DEFUN(bfd_get_string,(abfd, string, length),
140 bfd *abfd AND
141 char *string AND
142 size_t length)
143 {
144 size_t i;
145 for (i= 0; i < length; i++) {
146 string[i] = this_byte_and_next(abfd);
147 }
148 }
149
150 static char *
151 DEFUN(read_id,(abfd),
152 bfd *abfd)
153 {
154 size_t length;
155 char *string;
156 length = this_byte_and_next(abfd);
157 if (length >= 0x00 && length <= 0x7f) {
158 /* Simple string of length 0 to 127 */
159 }
160 else if (length == 0xde) {
161 /* Length is next byte, allowing 0..255 */
162 length = this_byte_and_next(abfd);
163 }
164 else if (length == 0xdf) {
165 /* Length is next two bytes, allowing 0..65535 */
166 length = this_byte_and_next(abfd) ;
167 length = (length * 256) + this_byte_and_next(abfd);
168 }
169 /* Buy memory and read string */
170 string = ieee_malloc(abfd, length+1);
171 bfd_get_string(abfd, string, length);
172 string[length] = 0;
173 return string;
174 }
175
176 static void
177 DEFUN(ieee_write_expression,(abfd, value, section, symbol),
178 bfd*abfd AND
179 bfd_vma value AND
180 asection *section AND
181 asymbol *symbol)
182 {
183 unsigned int plus_count = 0;
184 ieee_write_int(abfd, value);
185 if (section != (asection *)NULL) {
186 plus_count++;
187 ieee_write_byte(abfd, ieee_variable_L_enum);
188 ieee_write_byte(abfd, section->index +IEEE_SECTION_NUMBER_BASE);
189 }
190
191 if (symbol != (asymbol *)NULL) {
192 plus_count++;
193 if ((symbol->flags & BSF_UNDEFINED ) ||
194 (symbol->flags & BSF_FORT_COMM)) {
195 ieee_write_byte(abfd, ieee_variable_X_enum);
196 ieee_write_int(abfd, symbol->value);
197 }
198 else if (symbol->flags & BSF_GLOBAL) {
199 ieee_write_byte(abfd, ieee_variable_I_enum);
200 ieee_write_int(abfd, symbol->value);
201 }
202 else if (symbol->flags & BSF_LOCAL) {
203 /* This is a reference to a defined local symbol,
204 We can easily do a local as a section+offset */
205 if (symbol->section != (asection *)NULL) {
206 /* If this symbol is not absolute, add the base of it */
207 ieee_write_byte(abfd, ieee_variable_L_enum);
208 ieee_write_byte(abfd, symbol->section->index +
209 IEEE_SECTION_NUMBER_BASE);
210 plus_count++;
211 }
212
213 ieee_write_int(abfd, symbol->value);
214 }
215 else {
216
217 BFD_FAIL();
218 }
219 }
220
221 while (plus_count != 0) {
222 ieee_write_byte(abfd, ieee_function_plus_enum);
223 plus_count--;
224 }
225
226 }
227
228
229
230
231
232
233
234
235
236 /*****************************************************************************/
237
238 /*
239 writes any integer into the buffer supplied and always takes 5 bytes
240 */
241 static void
242 DEFUN(ieee_write_int5,(buffer, value),
243 bfd_byte*buffer AND
244 bfd_vma value )
245 {
246 buffer[0] = ieee_number_repeat_4_enum;
247 buffer[1] = (value >> 24 ) & 0xff;
248 buffer[2] = (value >> 16 ) & 0xff;
249 buffer[3] = (value >> 8 ) & 0xff;
250 buffer[4] = (value >> 0 ) & 0xff;
251 }
252 static void
253 DEFUN(ieee_write_int5_out, (abfd, value),
254 bfd *abfd AND
255 bfd_vma value)
256 {
257 char b[5];
258 ieee_write_int5(b, value);
259 bfd_write(b,1,5,abfd);
260 }
261
262
263 static boolean
264 DEFUN(parse_int,(abfd, value_ptr),
265 bfd *abfd AND
266 bfd_vma *value_ptr)
267 {
268 int value = this_byte(abfd);
269 int result;
270 if (value >= 0 && value <= 127) {
271 *value_ptr = value;
272 next_byte(abfd);
273 return true;
274 }
275 else if (value >= 0x80 && value <= 0x88) {
276 unsigned int count = value & 0xf;
277 result = 0;
278 next_byte(abfd);
279 while (count) {
280 result =(result << 8) | this_byte_and_next(abfd);
281 count--;
282 }
283 *value_ptr = result;
284 return true;
285 }
286 return false;
287 }
288 static int
289 DEFUN(parse_i,(abfd, ok),
290 bfd *abfd AND
291 boolean *ok)
292 {
293 bfd_vma x;
294 *ok = parse_int(abfd, &x);
295 return x;
296 }
297
298 static bfd_vma
299 DEFUN(must_parse_int,(abfd),
300 bfd *abfd)
301 {
302 bfd_vma result;
303 BFD_ASSERT(parse_int(abfd, &result) == true);
304 return result;
305 }
306
307 typedef struct
308 {
309 bfd_vma value;
310 asection *section;
311 ieee_symbol_index_type symbol;
312 } ieee_value_type;
313
314
315 static
316 reloc_howto_type abs32_howto
317 = HOWTO(1,0,2,32,0,0,0,true,0,"abs32",false,0xffffffff, 0xffffffff,false);
318 static
319 reloc_howto_type abs16_howto
320 = HOWTO(1,0,1,16,0,0,0,true,0,"abs16",false,0x0000ffff, 0x0000ffff,false);
321
322 static ieee_symbol_index_type NOSYMBOL = { 0, 0};
323
324
325 static void
326 DEFUN(parse_expression,(abfd, value, section, symbol, pcrel, extra),
327 bfd *abfd AND
328 bfd_vma *value AND
329 asection **section AND
330 ieee_symbol_index_type *symbol AND
331 boolean *pcrel AND
332 unsigned int *extra)
333 {
334 #define POS sp[1]
335 #define TOS sp[0]
336 #define NOS sp[-1]
337 #define INC sp++;
338 #define DEC sp--;
339
340 boolean loop = true;
341 ieee_value_type stack[10];
342
343 /* The stack pointer always points to the next unused location */
344 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
345 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
346 ieee_value_type *sp = stack;
347
348 while (loop) {
349 switch (this_byte(abfd))
350 {
351 case ieee_variable_P_enum:
352 /* P variable, current program counter for section n */
353 {
354 int section_n ;
355 next_byte(abfd);
356 section_n = must_parse_int(abfd);
357 PUSH(NOSYMBOL, 0,
358 TOS.value = ieee_data(abfd)->section_table[section_n]->vma +
359 ieee_per_section(ieee_data(abfd)->section_table[section_n])->pc);
360 break;
361 }
362 case ieee_variable_L_enum:
363 /* L variable address of section N */
364 next_byte(abfd);
365 PUSH(NOSYMBOL,ieee_data(abfd)->section_table[must_parse_int(abfd)],0);
366 break;
367 case ieee_variable_R_enum:
368 /* R variable, logical address of section module */
369 /* FIXME, this should be different to L */
370 next_byte(abfd);
371 PUSH(NOSYMBOL,ieee_data(abfd)->section_table[must_parse_int(abfd)],0);
372 break;
373 case ieee_variable_S_enum:
374 /* S variable, size in MAUS of section module */
375 next_byte(abfd);
376 PUSH(NOSYMBOL,
377 0,
378 ieee_data(abfd)->section_table[must_parse_int(abfd)]->size);
379 break;
380
381 case ieee_variable_X_enum:
382 /* Push the address of external variable n */
383 {
384 ieee_symbol_index_type sy;
385 next_byte(abfd);
386 sy.index = (int)(must_parse_int(abfd)) ;
387 sy.letter = 'X';
388
389 PUSH(sy, 0, 0);
390 }
391 break;
392 case ieee_function_minus_enum:
393 {
394 bfd_vma value1, value2;
395 asection *section;
396 ieee_symbol_index_type sy;
397 next_byte(abfd);
398
399 POP(sy, section, value1);
400 POP(sy, section, value2);
401 PUSH(NOSYMBOL, 0, value1-value2);
402 }
403 break;
404 case ieee_function_plus_enum:
405 {
406 bfd_vma value1, value2;
407 asection *section1;
408 asection *section2;
409 ieee_symbol_index_type sy1;
410 ieee_symbol_index_type sy2;
411 next_byte(abfd);
412
413 POP(sy1, section1, value1);
414 POP(sy2, section2, value2);
415 PUSH(sy1.letter ? sy1 : sy2, section1 ? section1: section2, value1+value2);
416 }
417 break;
418 default:
419 {
420 bfd_vma va;
421 BFD_ASSERT(this_byte(abfd) < ieee_variable_A_enum
422 || this_byte(abfd) > ieee_variable_Z_enum);
423 if (parse_int(abfd, &va))
424 {
425 PUSH(NOSYMBOL,0, va);
426 }
427 else {
428 /*
429 Thats all that we can understand. As far as I can see
430 there is a bug in the Microtec IEEE output which I'm
431 using to scan, whereby the comma operator is ommited
432 sometimes in an expression, giving expressions with too
433 many terms. We can tell if that's the case by ensuring
434 that sp == stack here. If not, then we've pushed
435 something too far. -
436 */
437
438 POP(*symbol, *section, *value);
439 if (sp != stack) {
440 BFD_ASSERT(*section == 0);
441 *extra = *value;
442 /* Get what should be returned */
443 POP(*symbol, *section, *value);
444 }
445 else {
446 *extra = 0;
447 }
448 loop = false;
449 }
450 }
451
452 }
453 }
454 }
455
456
457
458 #define ieee_seek(abfd, offset) \
459 ieee_data(abfd)->input_p = ieee_data(abfd)->first_byte + offset
460
461 static void
462 DEFUN(ieee_slurp_external_symbols,(abfd),
463 bfd *abfd)
464 {
465 ieee_data_type *ieee = ieee_data(abfd);
466 file_ptr offset = ieee->w.r.external_part;
467
468 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
469 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
470 ieee_symbol_type *symbol;
471 unsigned int symbol_count = 0;
472 boolean loop = true;
473
474 ieee->symbol_table_full = true;
475
476 ieee_seek(abfd, offset );
477
478 while (loop) {
479 switch (this_byte(abfd)) {
480 case ieee_external_symbol_enum:
481 next_byte(abfd);
482 symbol = (ieee_symbol_type *)ieee_malloc(abfd, sizeof(ieee_symbol_type));
483
484 *prev_symbols_ptr = symbol;
485 prev_symbols_ptr= &symbol->next;
486 symbol->index = must_parse_int(abfd);
487 if (symbol->index > ieee->external_symbol_max_index) {
488 ieee->external_symbol_max_index = symbol->index;
489 }
490 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
491 symbol_count++;
492 symbol->symbol.the_bfd = abfd;
493 symbol->symbol.name = read_id(abfd);
494 symbol->symbol.udata = (void *)NULL;
495 symbol->symbol.flags = BSF_NO_FLAGS;
496 break;
497 case ieee_attribute_record_enum >> 8:
498 {
499 unsigned int symbol_name_index;
500 unsigned int symbol_type_index;
501 unsigned int symbol_attribute_def;
502 bfd_vma value;
503 next_byte(abfd); /* Skip prefix */
504 next_byte(abfd);
505 symbol_name_index = must_parse_int(abfd);
506 symbol_type_index = must_parse_int(abfd);
507 symbol_attribute_def = must_parse_int(abfd);
508
509 parse_int(abfd,&value);
510
511 }
512 break;
513 case ieee_value_record_enum >> 8:
514 {
515 unsigned int symbol_name_index;
516 ieee_symbol_index_type symbol_ignore;
517 boolean pcrel_ignore;
518 unsigned int extra_ignore;
519 next_byte(abfd);
520 next_byte(abfd);
521
522 symbol_name_index = must_parse_int(abfd);
523 parse_expression(abfd,
524 &symbol->symbol.value,
525 &symbol->symbol.section,
526 &symbol_ignore,
527 &pcrel_ignore,
528 &extra_ignore);
529 if (symbol->symbol.section != (asection *)NULL) {
530 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
531 }
532 else {
533 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT | BSF_ABSOLUTE;
534 }
535 }
536 break;
537 case ieee_weak_external_reference_enum:
538 { bfd_vma size;
539 bfd_vma value ;
540 next_byte(abfd);
541 /* Throw away the external reference index */
542 (void)must_parse_int(abfd);
543 /* Fetch the default size if not resolved */
544 size = must_parse_int(abfd);
545 /* Fetch the defautlt value if available */
546 if ( parse_int(abfd, &value) == false) {
547 value = 0;
548 }
549 /* This turns into a common */
550 symbol->symbol.flags = BSF_FORT_COMM;
551 symbol->symbol.value = size;
552 }
553 break;
554
555 case ieee_external_reference_enum:
556 next_byte(abfd);
557 symbol = (ieee_symbol_type *)ieee_malloc(abfd, sizeof(ieee_symbol_type));
558 symbol_count++;
559 *prev_reference_ptr = symbol;
560 prev_reference_ptr = &symbol->next;
561 symbol->index = must_parse_int(abfd);
562 symbol->symbol.the_bfd = abfd;
563 symbol->symbol.name = read_id(abfd);
564 symbol->symbol.udata = (void *)NULL;
565 symbol->symbol.section = (asection *)NULL;
566 symbol->symbol.value = (bfd_vma)0;
567 symbol->symbol.flags = BSF_UNDEFINED;
568 if (symbol->index > ieee->external_reference_max_index) {
569 ieee->external_reference_max_index = symbol->index;
570 }
571 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
572 break;
573
574 default:
575 loop = false;
576 }
577 }
578
579 if (ieee->external_symbol_max_index != 0) {
580 ieee->external_symbol_count =
581 ieee->external_symbol_max_index -
582 ieee->external_symbol_min_index + 1 ;
583 }
584 else {
585 ieee->external_symbol_count = 0;
586 }
587
588
589 if(ieee->external_reference_max_index != 0) {
590 ieee->external_reference_count =
591 ieee->external_reference_max_index -
592 ieee->external_reference_min_index + 1;
593 }
594 else {
595 ieee->external_reference_count = 0;
596 }
597
598 abfd->symcount =
599 ieee->external_reference_count + ieee->external_symbol_count;
600
601 if (symbol_count != abfd->symcount) {
602 /* There are gaps in the table -- */
603 ieee->symbol_table_full = false;
604 }
605 *prev_symbols_ptr = (ieee_symbol_type *)NULL;
606 *prev_reference_ptr = (ieee_symbol_type *)NULL;
607 }
608
609 static void
610 DEFUN(ieee_slurp_symbol_table,(abfd),
611 bfd *abfd)
612 {
613 if (ieee_data(abfd)->read_symbols == false) {
614 ieee_slurp_external_symbols(abfd);
615 ieee_data(abfd)->read_symbols= true;
616 }
617 }
618
619 size_t
620 DEFUN(ieee_get_symtab_upper_bound,(abfd),
621 bfd *abfd)
622 {
623 ieee_slurp_symbol_table (abfd);
624
625 return (abfd->symcount != 0) ?
626 (abfd->symcount+1) * (sizeof (ieee_symbol_type *)) : 0;
627 }
628
629 /*
630 Move from our internal lists to the canon table, and insert in
631 symbol index order
632 */
633
634 extern bfd_target ieee_vec;
635
636 unsigned int
637 DEFUN(ieee_get_symtab,(abfd, location),
638 bfd *abfd AND
639 asymbol **location)
640 {
641 ieee_symbol_type *symp;
642 static bfd dummy_bfd;
643 static asymbol empty_symbol =
644 { &dummy_bfd," ieee empty",(symvalue)0,BSF_DEBUGGING | BSF_FAKE};
645
646 ieee_data_type *ieee = ieee_data(abfd);
647 dummy_bfd.xvec= &ieee_vec;
648 ieee_slurp_symbol_table(abfd);
649
650 if (ieee->symbol_table_full == false) {
651 /* Arrgh - there are gaps in the table, run through and fill them */
652 /* up with pointers to a null place */
653 unsigned int i;
654 for (i= 0; i < abfd->symcount; i++) {
655 location[i] = &empty_symbol;
656 }
657 }
658
659
660 ieee->external_symbol_base_offset= - ieee->external_symbol_min_index;
661 for (symp = ieee_data(abfd)->external_symbols;
662 symp != (ieee_symbol_type *)NULL;
663 symp = symp->next) {
664 /* Place into table at correct index locations */
665 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
666
667 }
668
669 /* The external refs are indexed in a bit */
670 ieee->external_reference_base_offset =
671 - ieee->external_reference_min_index +ieee->external_symbol_count ;
672
673 for (symp = ieee_data(abfd)->external_reference;
674 symp != (ieee_symbol_type *)NULL;
675 symp = symp->next) {
676 location[symp->index + ieee->external_reference_base_offset] =
677 &symp->symbol;
678
679 }
680
681
682
683 location[abfd->symcount] = (asymbol *)NULL;
684
685 return abfd->symcount;
686 }
687
688
689 static void
690 DEFUN(ieee_slurp_sections,(abfd),
691 bfd *abfd)
692 {
693 ieee_data_type *ieee = ieee_data(abfd);
694 file_ptr offset = ieee->w.r.section_part;
695
696 asection *section = (asection *)NULL;
697
698 if (offset != 0) {
699 bfd_byte section_type[3];
700 ieee_seek(abfd, offset);
701 while (true) {
702 switch (this_byte(abfd)) {
703 case ieee_section_type_enum:
704 {
705 unsigned int section_index ;
706 next_byte(abfd);
707 section_index = must_parse_int(abfd);
708 /* Fixme to be nice about a silly number of sections */
709 BFD_ASSERT(section_index < NSECTIONS);
710
711 section = bfd_make_section(abfd, " tempname");
712 ieee->section_table[section_index] = section;
713 section->flags = SEC_NO_FLAGS;
714 section->target_index = section_index;
715 section_type[0] = this_byte_and_next(abfd);
716 switch (section_type[0]) {
717 case 0xC3:
718 section_type[1] = this_byte(abfd);
719 section->flags = SEC_LOAD;
720 switch (section_type[1]) {
721 case 0xD0:
722 /* Normal code */
723 next_byte(abfd);
724 section->flags |= SEC_LOAD | SEC_CODE;
725 break;
726 case 0xC4:
727 next_byte(abfd);
728 section->flags |= SEC_LOAD | SEC_DATA;
729 /* Normal data */
730 break;
731 case 0xD2:
732 next_byte(abfd);
733 /* Normal rom data */
734 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
735 break;
736 default:
737 break;
738 }
739 }
740 section->name = read_id(abfd);
741 { bfd_vma parent, brother, context;
742 parse_int(abfd, &parent);
743 parse_int(abfd, &brother);
744 parse_int(abfd, &context);
745 }
746
747
748 }
749 break;
750 case ieee_section_alignment_enum:
751 {
752 unsigned int section_index;
753 bfd_vma value;
754 next_byte(abfd);
755 section_index = must_parse_int(abfd);
756 if (section_index > ieee->section_count) {
757 ieee->section_count = section_index;
758 }
759 ieee->section_table[section_index]->alignment_power =
760 bfd_log2(must_parse_int(abfd));
761 (void)parse_int(abfd, & value);
762 }
763 break;
764 case ieee_e2_first_byte_enum:
765 {
766 ieee_record_enum_type t = read_2bytes(abfd);
767 switch (t) {
768 case ieee_section_size_enum:
769 section = ieee->section_table[must_parse_int(abfd)];
770 section->size = must_parse_int(abfd);
771 break;
772 case ieee_physical_region_size_enum:
773 section = ieee->section_table[must_parse_int(abfd)];
774 section->size = must_parse_int(abfd);
775 break;
776 case ieee_region_base_address_enum:
777 section = ieee->section_table[must_parse_int(abfd)];
778 section->vma = must_parse_int(abfd);
779 break;
780 case ieee_mau_size_enum:
781 must_parse_int(abfd);
782 must_parse_int(abfd);
783 break;
784 case ieee_m_value_enum:
785 must_parse_int(abfd);
786 must_parse_int(abfd);
787 break;
788 case ieee_section_base_address_enum:
789 section = ieee->section_table[must_parse_int(abfd)];
790 section->vma = must_parse_int(abfd);
791 break;
792 case ieee_section_offset_enum:
793 (void) must_parse_int(abfd);
794 (void) must_parse_int(abfd);
795 break;
796 default:
797 return;
798 }
799 }
800 break;
801 default:
802 return;
803 }
804 }
805 }
806 }
807
808 /***********************************************************************
809 * archive stuff
810 */
811 bfd_target *
812 DEFUN(ieee_archive_p,(abfd),
813 bfd *abfd)
814 {
815 char *library;
816 boolean loop;
817 ieee_ar_data_type *ar;
818 unsigned int i;
819 return 0; /* FIXME */
820 ieee_seek(abfd, (file_ptr) 0);
821 if (this_byte(abfd) != Module_Beginning) return (bfd_target*)NULL;
822 next_byte(abfd);
823 library= read_id(abfd);
824 if (strcmp(library , "LIBRARY") != 0) {
825 free(library);
826 return (bfd_target *)NULL;
827 }
828 /* Throw away the filename */
829 free( read_id(abfd));
830 /* This must be an IEEE archive, so we'll buy some space to do
831 things */
832 ar = (ieee_ar_data_type *) malloc(sizeof(ieee_ar_data_type));
833 ieee_ar_data(abfd) = ar;
834 ar->element_count = 0;
835 ar->element_index = 0;
836 obstack_init(&ar->element_obstack);
837
838 next_byte(abfd); /* Drop the ad part */
839 must_parse_int(abfd); /* And the two dummy numbers */
840 must_parse_int(abfd);
841
842 loop = true;
843 /* Read the index of the BB table */
844 while (loop) {
845 ieee_ar_obstack_type t;
846 int rec =read_2bytes(abfd);
847 if (rec ==ieee_assign_value_to_variable_enum) {
848 int record_number = must_parse_int(abfd);
849 t.file_offset = must_parse_int(abfd);
850 t.abfd = (bfd *)NULL;
851 ar->element_count++;
852 obstack_grow(&ar->element_obstack, (PTR)&t, sizeof(t));
853 }
854 else loop = false;
855 }
856 ar->elements = (ieee_ar_obstack_type *)obstack_base(&ar->element_obstack);
857
858 /* Now scan the area again, and replace BB offsets with file */
859 /* offsets */
860
861
862 for (i = 2; i < ar->element_count; i++) {
863 ieee_seek(abfd, ar->elements[i].file_offset);
864 next_byte(abfd); /* Drop F8 */
865 next_byte(abfd); /* Drop 14 */
866 must_parse_int(abfd); /* Drop size of block */
867 if (must_parse_int(abfd) != 0) {
868 /* This object has been deleted */
869 ar->elements[i].file_offset = 0;
870 }
871 else {
872 ar->elements[i].file_offset = must_parse_int(abfd);
873 }
874 }
875
876 obstack_finish(&ar->element_obstack);
877 return abfd->xvec;
878 }
879
880 static boolean
881 DEFUN(ieee_mkobject,(abfd),
882 bfd *abfd)
883 {
884 struct obstack tmp_obstack;
885 ieee_data_type *ieee;
886 obstack_init(&tmp_obstack);
887 BFD_ASSERT(ieee_data(abfd) == 0);
888 ieee_data(abfd) =
889 (ieee_data_type*)obstack_alloc(&tmp_obstack,sizeof(ieee_data_type));
890 ieee = ieee_data(abfd);
891 ieee->ieee_obstack = tmp_obstack;
892 return true;
893 }
894
895 bfd_target *
896 DEFUN(ieee_object_p,(abfd),
897 bfd *abfd)
898 {
899 char *processor;
900 unsigned int part;
901 ieee_data_type *ieee;
902 char buffer[300];
903
904 ieee_data(abfd) = 0;
905 ieee_mkobject(abfd);
906 ieee = ieee_data(abfd);
907
908 /* Read the first few bytes in to see if it makes sense */
909 bfd_read(buffer, 1, sizeof(buffer), abfd);
910
911 ptr(abfd)= buffer;
912 if (*(ptr(abfd)++) != Module_Beginning) goto fail;
913
914 ieee->read_symbols= false;
915 ieee->read_data= false;
916 ieee->section_count = 0;
917 ieee->external_symbol_max_index = 0;
918 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
919 ieee->external_reference_min_index =IEEE_REFERENCE_BASE;
920 ieee->external_reference_max_index = 0;
921 memset((PTR)ieee->section_table, 0, sizeof(ieee->section_table));
922
923 processor = ieee->mb.processor = read_id(abfd);
924 if (strcmp(processor,"LIBRARY") == 0) goto fail;
925 ieee->mb.module_name = read_id(abfd);
926 if (abfd->filename == (char *)NULL) {
927 abfd->filename = ieee->mb.module_name;
928 }
929 /* Determine the architecture and machine type of the object file. */
930 bfd_scan_arch_mach(processor, &abfd->obj_arch, &abfd->obj_machine);
931
932 if (this_byte(abfd) != ieee_address_descriptor_enum) {
933 goto fail;
934 }
935 next_byte(abfd);
936
937 if (parse_int(abfd, &ieee->ad.number_of_bits_mau) == false) {
938 goto fail;
939 }
940 if(parse_int(abfd, &ieee->ad.number_of_maus_in_address) == false) {
941 goto fail;
942 }
943
944 /* If there is a byte order info, take it */
945 if (this_byte(abfd) == ieee_variable_L_enum ||
946 this_byte(abfd) == ieee_variable_M_enum)
947 next_byte(abfd);
948
949
950 for (part = 0; part < N_W_VARIABLES; part++) {
951 boolean ok;
952 if (read_2bytes(abfd) != ieee_assign_value_to_variable_enum) {
953 goto fail;
954 }
955 if (this_byte_and_next(abfd) != part) {
956 goto fail;
957 }
958
959 ieee->w.offset[part] = parse_i(abfd, &ok);
960 if (ok==false) {
961 goto fail;
962 }
963
964 }
965 abfd->flags = HAS_SYMS;
966
967 /* By now we know that this is a real IEEE file, we're going to read
968 the whole thing into memory so that we can run up and down it
969 quickly. We can work out how big the file is from the trailer
970 record */
971
972 ieee_data(abfd)->first_byte = ieee_malloc(abfd, ieee->w.r.me_record
973 + 50);
974 bfd_seek(abfd, 0, 0);
975 bfd_read(ieee_data(abfd)->first_byte, 1, ieee->w.r.me_record+50, abfd);
976
977 ieee_slurp_sections(abfd);
978 return abfd->xvec;
979 fail:
980 obstack_finish(&ieee->ieee_obstack);
981 return (bfd_target *)NULL;
982 }
983
984
985 void
986 DEFUN(ieee_print_symbol,(ignore_abfd, file, symbol, how),
987 bfd *ignore_abfd AND
988 FILE *file AND
989 asymbol *symbol AND
990 bfd_print_symbol_enum_type how)
991 {
992 switch (how) {
993 case bfd_print_symbol_name_enum:
994 fprintf(file,"%s", symbol->name);
995 break;
996 case bfd_print_symbol_type_enum:
997 #if 0
998 fprintf(file,"%4x %2x",aout_symbol(symbol)->desc & 0xffff,
999 aout_symbol(symbol)->other & 0xff);
1000 #endif
1001 BFD_FAIL();
1002 break;
1003 case bfd_print_symbol_all_enum:
1004 {
1005 CONST char *section_name = symbol->section == (asection *)NULL ?
1006 "*abs" : symbol->section->name;
1007
1008 bfd_print_symbol_vandf((void *)file,symbol);
1009
1010 fprintf(file," %-5s %04x %02x %s",
1011 section_name,
1012 (unsigned) ieee_symbol(symbol)->index,
1013 (unsigned) 0, /*
1014 aout_symbol(symbol)->desc & 0xffff,
1015 aout_symbol(symbol)->other & 0xff,*/
1016 symbol->name);
1017 }
1018 break;
1019 }
1020 }
1021
1022
1023
1024 /* Read in all the section data and relocation stuff too */
1025 static boolean
1026 DEFUN(ieee_slurp_section_data,(abfd),
1027 bfd *abfd)
1028 {
1029 bfd_byte *location_ptr ;
1030 ieee_data_type *ieee = ieee_data(abfd);
1031 unsigned int section_number ;
1032
1033 ieee_per_section_type *current_map;
1034 asection *s;
1035 /* Seek to the start of the data area */
1036 if (ieee->read_data== true) return true;
1037 ieee->read_data = true;
1038 ieee_seek(abfd, ieee->w.r.data_part);
1039
1040 /* Allocate enough space for all the section contents */
1041
1042
1043 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
1044 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1045 per->data = (bfd_byte *) ieee_malloc(abfd, s->size);
1046 /*SUPPRESS 68*/
1047 per->reloc_tail_ptr =
1048 (ieee_reloc_type **)&(s->relocation);
1049 }
1050
1051
1052
1053 while (true) {
1054 switch (this_byte(abfd))
1055 {
1056 /* IF we see anything strange then quit */
1057 default:
1058 return true;
1059
1060 case ieee_set_current_section_enum:
1061 next_byte(abfd);
1062 section_number = must_parse_int(abfd);
1063 s = ieee->section_table[section_number];
1064 current_map = (ieee_per_section_type *) s->used_by_bfd;
1065 location_ptr = current_map->data - s->vma;
1066 /* The document I have says that Microtec's compilers reset */
1067 /* this after a sec section, even though the standard says not */
1068 /* to. SO .. */
1069 current_map->pc =s->vma;
1070 break;
1071
1072 case ieee_load_constant_bytes_enum:
1073 {
1074 unsigned int number_of_maus;
1075 unsigned int i;
1076 next_byte(abfd);
1077 number_of_maus = must_parse_int(abfd);
1078
1079 for (i = 0; i < number_of_maus; i++) {
1080 location_ptr[current_map->pc++]= this_byte(abfd);
1081 next_byte(abfd);
1082 }
1083 }
1084 break;
1085
1086 case ieee_e2_first_byte_enum:
1087 next_byte(abfd);
1088 switch (this_byte(abfd))
1089 {
1090 case ieee_set_current_pc_enum & 0xff:
1091 {
1092 bfd_vma value;
1093 asection *dsection;
1094 ieee_symbol_index_type symbol;
1095 unsigned int extra;
1096 boolean pcrel;
1097 next_byte(abfd);
1098 must_parse_int(abfd); /* Thow away section #*/
1099 parse_expression(abfd, &value, &dsection, &symbol, &pcrel, &extra);
1100 current_map->pc = value;
1101 BFD_ASSERT((unsigned)(value - s->vma) <= s->size);
1102 }
1103 break;
1104
1105 case ieee_value_starting_address_enum & 0xff:
1106 /* We've got to the end of the data now - */
1107 return true;
1108 break;
1109 default:
1110 BFD_FAIL();
1111 return true;
1112 }
1113 break;
1114 case ieee_load_with_relocation_enum:
1115 {
1116 boolean loop = true;
1117 next_byte(abfd);
1118 while (loop)
1119 {
1120 switch (this_byte(abfd))
1121 {
1122 case ieee_variable_R_enum:
1123
1124 case ieee_function_signed_open_b_enum:
1125 case ieee_function_unsigned_open_b_enum:
1126 case ieee_function_either_open_b_enum:
1127 {
1128 unsigned int extra;
1129 boolean pcrel;
1130
1131 ieee_reloc_type *r =
1132 (ieee_reloc_type *) ieee_malloc(abfd,
1133 sizeof(ieee_reloc_type));
1134
1135 *(current_map->reloc_tail_ptr) = r;
1136 current_map->reloc_tail_ptr= &r->next;
1137 r->next = (ieee_reloc_type *)NULL;
1138 next_byte(abfd);
1139 parse_expression(abfd,
1140 &r->relent.addend,
1141 &r->relent.section,
1142 &r->symbol,
1143 &pcrel,
1144 &extra);
1145 r->relent.address = current_map->pc;
1146 s->reloc_count++;
1147 switch (this_byte(abfd)) {
1148 case ieee_function_signed_close_b_enum:
1149 next_byte(abfd);
1150 break;
1151 case ieee_function_unsigned_close_b_enum:
1152 next_byte(abfd);
1153 break;
1154 case ieee_function_either_close_b_enum:
1155 next_byte(abfd);
1156 break;
1157 default:
1158 break;
1159 }
1160 /* Build a relocation entry for this type */
1161 if (this_byte(abfd) == ieee_comma) {
1162
1163 next_byte(abfd);
1164 /* Fetch number of bytes to pad */
1165 extra = must_parse_int(abfd);
1166 BFD_FAIL();
1167 }
1168 switch (extra) {
1169 case 0:
1170 case 4:
1171 location_ptr[current_map->pc++] = 0;
1172 location_ptr[current_map->pc++] = 0;
1173 location_ptr[current_map->pc++] = 0;
1174 location_ptr[current_map->pc++] = 0;
1175 r->relent.howto = &abs32_howto;
1176 break;
1177 case 2:
1178 location_ptr[current_map->pc++] = 0;
1179 location_ptr[current_map->pc++] = 0;
1180 r->relent.howto = &abs16_howto;
1181 break;
1182
1183 default:
1184 BFD_FAIL();
1185 break;
1186 }
1187 }
1188 break;
1189 default:
1190 {
1191 bfd_vma this_size ;
1192 if (parse_int(abfd, &this_size) == true) {
1193 unsigned int i;
1194 for (i = 0; i < this_size; i++) {
1195 location_ptr[current_map->pc ++] = this_byte(abfd);
1196 next_byte(abfd);
1197 }
1198 }
1199 else {
1200 loop = false;
1201 }
1202 }
1203 }
1204 }
1205 }
1206 }
1207 }
1208 }
1209
1210
1211
1212 boolean
1213 DEFUN(ieee_new_section_hook,(abfd, newsect),
1214 bfd *abfd AND
1215 asection *newsect)
1216 {
1217 newsect->used_by_bfd = (PTR)
1218 ieee_malloc(abfd, sizeof(ieee_per_section_type));
1219 ieee_per_section( newsect)->data = (bfd_byte *)NULL;
1220 ieee_per_section(newsect)->section = newsect;
1221 return true;
1222 }
1223
1224
1225 unsigned int
1226 DEFUN(ieee_get_reloc_upper_bound,(abfd, asect),
1227 bfd *abfd AND
1228 sec_ptr asect)
1229 {
1230 ieee_slurp_section_data(abfd);
1231 return (asect->reloc_count+1) * sizeof(arelent *);
1232 }
1233
1234 static boolean
1235 DEFUN(ieee_get_section_contents,(abfd, section, location, offset, count),
1236 bfd *abfd AND
1237 sec_ptr section AND
1238 void *location AND
1239 file_ptr offset AND
1240 unsigned int count)
1241 {
1242 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1243 ieee_slurp_section_data(abfd);
1244 (void) memcpy(location, p->data + offset, count);
1245 return true;
1246 }
1247
1248
1249 unsigned int
1250 DEFUN(ieee_canonicalize_reloc,(abfd, section, relptr, symbols),
1251 bfd *abfd AND
1252 sec_ptr section AND
1253 arelent **relptr AND
1254 asymbol **symbols)
1255 {
1256 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1257 ieee_reloc_type *src = (ieee_reloc_type *)(section->relocation);
1258 ieee_data_type *ieee = ieee_data(abfd);
1259
1260 while (src != (ieee_reloc_type *)NULL) {
1261 /* Work out which symbol to attatch it this reloc to */
1262 switch (src->symbol.letter) {
1263 case 'X':
1264 src->relent.sym_ptr_ptr =
1265 symbols + src->symbol.index + ieee->external_reference_base_offset;
1266 break;
1267 case 0:
1268 src->relent.sym_ptr_ptr = (asymbol **)NULL;
1269 break;
1270 default:
1271
1272 BFD_FAIL();
1273 }
1274 *relptr++ = &src->relent;
1275 src = src->next;
1276 }
1277 *relptr = (arelent *)NULL;
1278 return section->reloc_count;
1279 }
1280
1281 boolean
1282 DEFUN(ieee_set_arch_mach,(abfd, arch, machine),
1283 bfd *abfd AND
1284 enum bfd_architecture arch AND
1285 unsigned long machine)
1286 {
1287 abfd->obj_arch = arch;
1288 abfd->obj_machine = machine;
1289 return true;
1290 }
1291
1292
1293 static int
1294 DEFUN(comp,(ap, bp),
1295 CONST PTR ap AND
1296 CONST PTR bp)
1297 {
1298 arelent *a = *((arelent **)ap);
1299 arelent *b = *((arelent **)bp);
1300 return a->address - b->address;
1301 }
1302
1303 /*
1304 Write the section headers
1305 */
1306
1307 static void
1308 DEFUN(ieee_write_section_part,(abfd),
1309 bfd *abfd)
1310 {
1311 ieee_data_type *ieee = ieee_data(abfd);
1312 asection *s;
1313 ieee->w.r.section_part = bfd_tell(abfd);
1314 for (s = abfd->sections; s != (asection *)NULL; s=s->next) {
1315 ieee_write_byte(abfd, ieee_section_type_enum);
1316 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1317
1318 switch (s->flags & (SEC_LOAD | SEC_CODE | SEC_DATA | SEC_ROM)) {
1319 case SEC_LOAD | SEC_CODE:
1320 /* Normal named section, code */
1321 ieee_write_byte(abfd, ieee_variable_C_enum);
1322 ieee_write_byte(abfd, ieee_variable_P_enum);
1323 break;
1324 case SEC_LOAD | SEC_DATA:
1325 /* Normal named section, data */
1326 ieee_write_byte(abfd, ieee_variable_C_enum);
1327 ieee_write_byte(abfd, ieee_variable_D_enum);
1328 break;
1329 case SEC_LOAD | SEC_DATA | SEC_ROM:
1330 /* Normal named section, data rom */
1331 ieee_write_byte(abfd, ieee_variable_C_enum);
1332 ieee_write_byte(abfd, ieee_variable_R_enum);
1333 break;
1334 default:
1335 ieee_write_byte(abfd, ieee_variable_C_enum);
1336 break;
1337 }
1338
1339 ieee_write_id(abfd, s->name);
1340 ieee_write_int(abfd, 0); /* Parent */
1341 ieee_write_int(abfd, 0); /* Brother */
1342 ieee_write_int(abfd, 0); /* Context */
1343
1344 /* Alignment */
1345 ieee_write_byte(abfd, ieee_section_alignment_enum);
1346 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1347 ieee_write_int(abfd, 1 << s->alignment_power);
1348
1349 /* Size */
1350 ieee_write_2bytes(abfd, ieee_section_size_enum);
1351 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1352 ieee_write_int(abfd, s->size);
1353
1354 /* Vma */
1355 ieee_write_2bytes(abfd, ieee_region_base_address_enum);
1356 ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE);
1357 ieee_write_int(abfd, s->vma);
1358
1359 }
1360 }
1361
1362
1363
1364 /* write the data in an ieee way */
1365 static void
1366 DEFUN(ieee_write_data_part,(abfd),
1367 bfd *abfd)
1368 {
1369 asection *s;
1370 ieee_data_type *ieee = ieee_data(abfd);
1371 ieee->w.r.data_part = bfd_tell(abfd);
1372 for (s = abfd->sections; s != (asection *)NULL; s = s->next)
1373 {
1374 bfd_byte header[11];
1375 bfd_byte *stream = ieee_per_section(s)->data;
1376 arelent **p = s->orelocation;
1377 unsigned int relocs_to_go = s->reloc_count;
1378 size_t current_byte_index = 0;
1379
1380
1381 /* Sort the reloc records so we can insert them in the correct
1382 places */
1383 if (s->reloc_count != 0) {
1384 qsort(s->orelocation,
1385 s->reloc_count,
1386 sizeof(arelent **),
1387 comp);
1388 }
1389
1390
1391 /* Output the section preheader */
1392 header[0] =ieee_set_current_section_enum;
1393 header[1] = s->index + IEEE_SECTION_NUMBER_BASE;
1394
1395 header[2] = ieee_set_current_pc_enum >> 8;
1396 header[3]= ieee_set_current_pc_enum & 0xff;
1397 header[4] = s->index + IEEE_SECTION_NUMBER_BASE;
1398 ieee_write_int5(header+5, s->vma );
1399 header[10] = ieee_load_with_relocation_enum;
1400 bfd_write(header, 1, sizeof(header), abfd);
1401
1402 /* Output the data stream as the longest sequence of bytes
1403 possible, allowing for the a reasonable packet size and
1404 relocation stuffs */
1405
1406 if (stream == (void *)NULL) {
1407 /* Outputting a section without data, fill it up */
1408 stream = ieee_malloc(abfd, s->size);
1409 memset(stream, 0, s->size);
1410 }
1411 while (current_byte_index < s->size) {
1412 size_t run;
1413 unsigned int MAXRUN = 32;
1414 if (p && *p) {
1415 run = (*p)->address - current_byte_index;
1416 }
1417 else {
1418 run = MAXRUN;
1419 }
1420 if (run > s->size - current_byte_index) {
1421 run = s->size - current_byte_index;
1422 }
1423
1424 if (run != 0) {
1425 /* Output a stream of bytes */
1426 ieee_write_int(abfd, run);
1427 bfd_write(stream + current_byte_index,
1428 1,
1429 run,
1430 abfd);
1431 current_byte_index += run;
1432 }
1433 /* Output any relocations here */
1434 if (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
1435 while (relocs_to_go && (*p) && (*p)->address == current_byte_index) {
1436
1437 arelent *r = *p;
1438 ieee_write_byte(abfd, ieee_function_either_open_b_enum);
1439 if (r->sym_ptr_ptr != (asymbol **)NULL) {
1440 ieee_write_expression(abfd, r->addend,
1441 r->section,
1442 *(r->sym_ptr_ptr));
1443 }
1444 else {
1445 ieee_write_expression(abfd, r->addend,
1446 r->section,
1447 (asymbol *)NULL);
1448 }
1449 ieee_write_byte(abfd,
1450 ieee_function_either_close_b_enum);
1451 relocs_to_go --;
1452 p++;
1453 }
1454 /* FIXME !! Are all relocations 4 bytes ? */
1455 current_byte_index += 4;
1456 }
1457 }
1458 }
1459
1460 }
1461
1462
1463
1464 static void
1465 DEFUN(init_for_output,(abfd),
1466 bfd *abfd)
1467 {
1468 asection *s;
1469 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
1470 if (s->size != 0) {
1471 ieee_per_section(s)->data = (bfd_byte *)(ieee_malloc(abfd, s->size));
1472 }
1473 }
1474 }
1475
1476 /** exec and core file sections */
1477
1478 /* set section contents is complicated with IEEE since the format is
1479 * not a byte image, but a record stream.
1480 */
1481 boolean
1482 DEFUN(ieee_set_section_contents,(abfd, section, location, offset, count),
1483 bfd *abfd AND
1484 sec_ptr section AND
1485 unsigned char *location AND
1486 file_ptr offset AND
1487 int count)
1488 {
1489 if (ieee_per_section(section)->data == (bfd_byte *)NULL) {
1490 init_for_output(abfd);
1491 }
1492 (void) memcpy(ieee_per_section(section)->data + offset, location, count);
1493 return true;
1494 }
1495
1496 /*
1497 write the external symbols of a file, IEEE considers two sorts of
1498 external symbols, public, and referenced. It uses to internal forms
1499 to index them as well. When we write them out we turn their symbol
1500 values into indexes from the right base.
1501 */
1502 static void
1503 DEFUN(ieee_write_external_part,(abfd),
1504 bfd *abfd)
1505 {
1506 asymbol **q;
1507 ieee_data_type *ieee = ieee_data(abfd);
1508
1509 unsigned int reference_index = IEEE_REFERENCE_BASE;
1510 unsigned int public_index = IEEE_PUBLIC_BASE;
1511 ieee->w.r.external_part = bfd_tell(abfd);
1512 if (abfd->outsymbols != (asymbol **)NULL) {
1513 for (q = abfd->outsymbols; *q != (asymbol *)NULL; q++) {
1514 asymbol *p = *q;
1515 if (p->flags & BSF_UNDEFINED) {
1516 /* This must be a symbol reference .. */
1517 ieee_write_byte(abfd, ieee_external_reference_enum);
1518 ieee_write_int(abfd, reference_index);
1519 ieee_write_id(abfd, p->name);
1520 p->value = reference_index;
1521 reference_index++;
1522 }
1523 else if(p->flags & BSF_FORT_COMM) {
1524 /* This is a weak reference */
1525 ieee_write_byte(abfd, ieee_external_reference_enum);
1526 ieee_write_int(abfd, reference_index);
1527 ieee_write_id(abfd, p->name);
1528 ieee_write_byte(abfd, ieee_weak_external_reference_enum);
1529 ieee_write_int(abfd, reference_index);
1530 ieee_write_int(abfd, p->value);
1531 ieee_write_int(abfd, BFD_FORT_COMM_DEFAULT_VALUE);
1532 p->value = reference_index;
1533 reference_index++;
1534 }
1535 else if(p->flags & BSF_GLOBAL) {
1536 /* This must be a symbol definition */
1537
1538 ieee_write_byte(abfd, ieee_external_symbol_enum);
1539 ieee_write_int(abfd, public_index );
1540 ieee_write_id(abfd, p->name);
1541
1542 /* Write out the value */
1543 ieee_write_2bytes(abfd, ieee_value_record_enum);
1544 ieee_write_int(abfd, public_index);
1545 if (p->section != (asection *)NULL)
1546 {
1547 ieee_write_expression(abfd,
1548 p->value + p->section->output_offset,
1549 p->section->output_section,
1550 (asymbol *)NULL);
1551 }
1552 else
1553 {
1554 ieee_write_expression(abfd,
1555 p->value,
1556 (asection *)NULL,
1557 (asymbol *)NULL);
1558 }
1559 p->value = public_index;
1560 public_index++;
1561 }
1562 else {
1563 /* This can happen - when there are gaps in the symbols read */
1564 /* from an input ieee file */
1565 }
1566 }
1567 }
1568
1569 }
1570
1571 static
1572 void
1573 DEFUN(ieee_write_me_part,(abfd),
1574 bfd *abfd)
1575 {
1576 ieee_data_type *ieee= ieee_data(abfd);
1577 ieee->w.r.me_record = bfd_tell(abfd);
1578
1579 ieee_write_2bytes(abfd, ieee_value_starting_address_enum);
1580 ieee_write_int(abfd, abfd->start_address);
1581 ieee_write_byte(abfd, ieee_module_end_enum);
1582
1583 }
1584 boolean
1585 DEFUN(ieee_write_object_contents,(abfd),
1586 bfd *abfd)
1587 {
1588 ieee_data_type *ieee = ieee_data(abfd);
1589 unsigned int i;
1590 file_ptr old;
1591 /* Fast forward over the header area */
1592 bfd_seek(abfd, 0, 0);
1593 ieee_write_byte(abfd, ieee_module_beginning_enum);
1594
1595 ieee_write_id(abfd, bfd_printable_arch_mach(abfd->obj_arch,
1596 abfd->obj_machine));
1597 ieee_write_id(abfd, abfd->filename);
1598 ieee_write_byte(abfd, ieee_address_descriptor_enum);
1599 ieee_write_byte(abfd, 8); /* Bits per MAU */
1600 ieee_write_byte(abfd, 4); /* MAU's per address */
1601
1602 /* Fast forward over the variable bits */
1603 old = bfd_tell(abfd);
1604 bfd_seek(abfd, 8 * N_W_VARIABLES, 1);
1605
1606 /*
1607 First write the symbols, this changes their values into table
1608 indeces so we cant use it after this point
1609 */
1610 ieee_write_external_part(abfd);
1611 ieee_write_byte(abfd, ieee_record_seperator_enum);
1612
1613 ieee_write_section_part(abfd);
1614 ieee_write_byte(abfd, ieee_record_seperator_enum);
1615 /*
1616 Can only write the data once the symbols have been written since
1617 the data contains relocation information which points to the
1618 symbols
1619 */
1620 ieee_write_data_part(abfd);
1621 ieee_write_byte(abfd, ieee_record_seperator_enum);
1622
1623 /*
1624 At the end we put the end !
1625 */
1626 ieee_write_me_part(abfd);
1627
1628
1629 /* Generate the header */
1630 bfd_seek(abfd, old, false);
1631
1632 for (i= 0; i < N_W_VARIABLES; i++) {
1633 ieee_write_2bytes(abfd,ieee_assign_value_to_variable_enum);
1634 ieee_write_byte(abfd, i);
1635 ieee_write_int5_out(abfd, ieee->w.offset[i]);
1636 }
1637 return true;
1638 }
1639
1640
1641
1642 \f
1643 /* Native-level interface to symbols. */
1644
1645 /* We read the symbols into a buffer, which is discarded when this
1646 function exits. We read the strings into a buffer large enough to
1647 hold them all plus all the cached symbol entries. */
1648
1649 asymbol *
1650 DEFUN(ieee_make_empty_symbol,(abfd),
1651 bfd *abfd)
1652 {
1653
1654 ieee_symbol_type *new =
1655 (ieee_symbol_type *)zalloc (sizeof (ieee_symbol_type));
1656 new->symbol.the_bfd = abfd;
1657 return &new->symbol;
1658
1659 }
1660
1661 void
1662 DEFUN(ieee_reclaim_symbol_table, (abfd),
1663 bfd *abfd)
1664 {
1665 #if 0
1666 asection *section;
1667
1668 if (!bfd_get_symcount (abfd)) return;
1669
1670 for (section = abfd->sections; section != NULL; section = section->next)
1671 if (section->relocation) {
1672 free ((void *)section->relocation);
1673 section->relocation = NULL;
1674 section->reloc_count = 0;
1675 }
1676
1677 bfd_get_symcount (abfd) = 0;
1678 free ((void *)obj_aout_symbols (abfd));
1679 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
1680 #endif
1681 }
1682 \f
1683
1684
1685 \f
1686 /* Obsolete procedural interface; better to look at the cache directly */
1687
1688 /* User should have checked the file flags; perhaps we should return
1689 BFD_NO_MORE_SYMBOLS if there are none? */
1690
1691 int
1692 DEFUN(ieee_get_symcount_upper_bound,(abfd),
1693 bfd *abfd)
1694 {
1695 #if 0
1696 /* In case we're doing an output file or something...? */
1697 if (bfd_get_symcount (abfd)) return bfd_get_symcount (abfd);
1698
1699 return (exec_hdr (abfd)->a_syms) / (sizeof (struct nlist));
1700 #endif
1701 return 0;
1702 }
1703
1704 symindex
1705 DEFUN(ieee_get_first_symbol,(ignore_abfd),
1706 bfd * ignore_abfd)
1707 {
1708 return 0;
1709 }
1710
1711 symindex
1712 DEFUN(ieee_get_next_symbol,(abfd, oidx),
1713 bfd *abfd AND
1714 symindex oidx)
1715 {
1716 #if 0
1717 if (oidx == BFD_NO_MORE_SYMBOLS) return BFD_NO_MORE_SYMBOLS;
1718 return ++oidx >= bfd_get_symcount (abfd) ? BFD_NO_MORE_SYMBOLS :
1719 oidx;
1720 #endif
1721 return 0;
1722 }
1723
1724 char *
1725 ieee_symbol_name (abfd, idx)
1726 bfd *abfd;
1727 symindex idx;
1728 {
1729 #if 0
1730 return (obj_aout_symbols (abfd) + idx)->symbol.name;
1731 #endif
1732 return 0;
1733 }
1734
1735 long
1736 ieee_symbol_value (abfd, idx)
1737 bfd *abfd;
1738 symindex idx;
1739 {
1740 #if 0
1741 return (obj_aout_symbols (abfd) + idx)->symbol.value;
1742 #endif
1743 return 0;
1744 }
1745
1746 symclass
1747 ieee_classify_symbol (abfd, idx)
1748 bfd *abfd;
1749 symindex idx;
1750 {
1751 #if 0
1752 aout_symbol_type *sym = obj_aout_symbols (abfd) + idx;
1753
1754 if ((sym->symbol.flags & BSF_FORT_COMM) != 0) return bfd_symclass_fcommon;
1755 if ((sym->symbol.flags & BSF_GLOBAL) != 0) return bfd_symclass_global;
1756 if ((sym->symbol.flags & BSF_DEBUGGING) != 0) return bfd_symclass_debugger;
1757 if ((sym->symbol.flags & BSF_UNDEFINED) != 0) return bfd_symclass_undefined;
1758 #endif
1759 return bfd_symclass_unknown;
1760 }
1761
1762 boolean
1763 ieee_symbol_hasclass (abfd, idx, class)
1764 bfd *abfd;
1765 symindex idx;
1766 symclass class;
1767 {
1768 #if 0
1769 aout_symbol_type *sym = obj_aout_symbols (abfd) + idx;
1770 switch (class) {
1771 case bfd_symclass_fcommon:
1772 return (sym->symbol.flags & BSF_FORT_COMM) ? true :false;
1773 case bfd_symclass_global:
1774 return (sym->symbol.flags & BSF_GLOBAL) ? true:false;
1775 case bfd_symclass_debugger:
1776 return (sym->symbol.flags & BSF_DEBUGGING) ? true:false;;
1777 case bfd_symclass_undefined:
1778 return (sym->symbol.flags & BSF_UNDEFINED) ? true:false;;
1779 default: return false;
1780 }
1781 #endif
1782 return 0;
1783 }
1784
1785
1786 void
1787 ieee_reclaim_reloc (ignore_abfd, section)
1788 bfd *ignore_abfd;
1789 sec_ptr section;
1790 {
1791 #if 0
1792 if (section->relocation) {
1793 free (section->relocation);
1794 section->relocation = NULL;
1795 section->reloc_count = 0;
1796 }
1797 #endif
1798 }
1799
1800 boolean
1801 ieee_close_and_cleanup (abfd)
1802 bfd *abfd;
1803 {
1804 if (bfd_read_p (abfd) == false)
1805 switch (abfd->format) {
1806 case bfd_archive:
1807 if (!_bfd_write_archive_contents (abfd)) {
1808 return false;
1809 }
1810 break;
1811 case bfd_object:
1812 if (!ieee_write_object_contents (abfd)) {
1813 return false;
1814 }
1815 break;
1816 default:
1817 bfd_error = invalid_operation;
1818 return false;
1819 }
1820
1821
1822 if (ieee_data(abfd) != (ieee_data_type *)NULL) {
1823 /* FIXME MORE LEAKS */
1824
1825 }
1826
1827 return true;
1828 }
1829
1830 static bfd *
1831 ieee_openr_next_archived_file(arch, prev)
1832 bfd *arch;
1833 bfd *prev;
1834 {
1835 ieee_ar_data_type *ar = ieee_ar_data(arch);
1836 /* take the next one from the arch state, or reset */
1837 if (prev == (bfd *)NULL) {
1838 /* Reset the index - the first two entries are bogus*/
1839 ar->element_index = 2;
1840 }
1841 while (true) {
1842 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
1843 ar->element_index++;
1844 if (ar->element_index <= ar->element_count) {
1845 if (p->file_offset != (file_ptr)0) {
1846 if (p->abfd == (bfd *)NULL) {
1847 p->abfd = _bfd_create_empty_archive_element_shell(arch);
1848 p->abfd->origin = p->file_offset;
1849 }
1850 return p->abfd;
1851 }
1852 }
1853 else {
1854 return (bfd *)NULL;
1855 }
1856
1857 }
1858 }
1859
1860 static boolean
1861 ieee_find_nearest_line(abfd,
1862 section,
1863 symbols,
1864 offset,
1865 filename_ptr,
1866 functionname_ptr,
1867 line_ptr)
1868 bfd *abfd;
1869 asection *section;
1870 asymbol **symbols;
1871 bfd_vma offset;
1872 char **filename_ptr;
1873 char **functionname_ptr;
1874 unsigned int *line_ptr;
1875 {
1876 return false;
1877
1878 }
1879
1880
1881 static int
1882 ieee_generic_stat_arch_elt(abfd, buf)
1883 bfd *abfd;
1884 struct stat *buf;
1885 {
1886 ieee_ar_data_type *ar = ieee_ar_data(abfd);
1887 if (ar == (ieee_ar_data_type *)NULL) {
1888 bfd_error = invalid_operation;
1889 return -1;
1890 }
1891 else {
1892 buf->st_size = 0x1;
1893 buf->st_mode = 0666;
1894 return 0;
1895 }
1896 }
1897 static int
1898 DEFUN(ieee_sizeof_headers,(abfd),
1899 bfd *abfd)
1900 {
1901 return 0;
1902 }
1903
1904 #define ieee_core_file_failing_command bfd_false
1905 #define ieee_core_file_failing_signal bfd_false
1906 #define ieee_core_file_matches_executable_p bfd_false
1907 #define ieee_slurp_armap bfd_true
1908 #define ieee_slurp_extended_name_table bfd_true
1909 #define ieee_truncate_arname bfd_false
1910 #define ieee_write_armap bfd_false
1911 #define ieee_get_lineno bfd_false
1912
1913
1914 /*SUPPRESS 460 */
1915 bfd_target ieee_vec =
1916 {
1917 "ieee", /* name */
1918 bfd_target_ieee_flavour_enum,
1919 true, /* target byte order */
1920 true, /* target headers byte order */
1921 (HAS_RELOC | EXEC_P | /* object flags */
1922 HAS_LINENO | HAS_DEBUG |
1923 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
1924 (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
1925 |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1926 ' ', /* ar_pad_char */
1927 16, /* ar_max_namelen */
1928
1929 _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* data */
1930 _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* hdrs */
1931
1932 {_bfd_dummy_target,
1933 ieee_object_p, /* bfd_check_format */
1934 ieee_archive_p,
1935 bfd_false
1936 },
1937 {
1938 bfd_false,
1939 ieee_mkobject,
1940 _bfd_generic_mkarchive,
1941 bfd_false
1942 },
1943 JUMP_TABLE(ieee)
1944 };
This page took 0.090515 seconds and 5 git commands to generate.