Fix typo; some progress in ppcbug support
[binutils-gdb.git] / bfd / ieee.c
1 /* BFD back-end for ieee-695 objects.
2 Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
3 Written by Steve Chamberlain of Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
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.
11
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.
16
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #define KEEPMINUSPCININST 0
22
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
25 parser. */
26
27 #include "bfd.h"
28 #include "sysdep.h"
29 #include "libbfd.h"
30 #include "ieee.h"
31 #include "libieee.h"
32 #include "obstack.h"
33 #define obstack_chunk_alloc malloc
34 #define obstack_chunk_free free
35
36 /* Functions for writing to ieee files in the strange way that the
37 standard requires. */
38
39 static void
40 ieee_write_byte (abfd, byte)
41 bfd *abfd;
42 bfd_byte byte;
43 {
44 if (bfd_write ((PTR) & byte, 1, 1, abfd) != 1)
45 abort ();
46 }
47
48 static void
49 ieee_write_twobyte (abfd, twobyte)
50 bfd *abfd;
51 int twobyte;
52 {
53 bfd_byte b[2];
54 b[1] = twobyte & 0xff;
55 b[0] = twobyte >> 8;
56 if (bfd_write ((PTR) & b[0], 1, 2, abfd) != 2)
57 abort ();
58 }
59
60 static void
61 ieee_write_2bytes (abfd, bytes)
62 bfd *abfd;
63 int bytes;
64 {
65 bfd_byte buffer[2];
66 buffer[0] = bytes >> 8;
67 buffer[1] = bytes & 0xff;
68
69 if (bfd_write ((PTR) buffer, 1, 2, abfd) != 2)
70 abort ();
71 }
72
73 static void
74 ieee_write_int (abfd, value)
75 bfd *abfd;
76 bfd_vma value;
77 {
78 if (((unsigned) value) <= 127)
79 {
80 ieee_write_byte (abfd, (bfd_byte) value);
81 }
82 else
83 {
84 unsigned int length;
85 /* How many significant bytes ? */
86 /* FIXME FOR LONGER INTS */
87 if (value & 0xff000000)
88 {
89 length = 4;
90 }
91 else if (value & 0x00ff0000)
92 {
93 length = 3;
94 }
95 else if (value & 0x0000ff00)
96 {
97 length = 2;
98 }
99 else
100 length = 1;
101
102 ieee_write_byte (abfd,
103 (bfd_byte) ((int) ieee_number_repeat_start_enum + length));
104 switch (length)
105 {
106 case 4:
107 ieee_write_byte (abfd, (bfd_byte) (value >> 24));
108 case 3:
109 ieee_write_byte (abfd, (bfd_byte) (value >> 16));
110 case 2:
111 ieee_write_byte (abfd, (bfd_byte) (value >> 8));
112 case 1:
113 ieee_write_byte (abfd, (bfd_byte) (value));
114 }
115 }
116 }
117
118 static void
119 ieee_write_id (abfd, id)
120 bfd *abfd;
121 CONST char *id;
122 {
123 size_t length = strlen (id);
124 if (length <= 127)
125 {
126 ieee_write_byte (abfd, (bfd_byte) length);
127 }
128 else if (length < 255)
129 {
130 ieee_write_byte (abfd, ieee_extension_length_1_enum);
131 ieee_write_byte (abfd, (bfd_byte) length);
132 }
133 else if (length < 65535)
134 {
135 ieee_write_byte (abfd, ieee_extension_length_2_enum);
136 ieee_write_byte (abfd, (bfd_byte) (length >> 8));
137 ieee_write_byte (abfd, (bfd_byte) (length & 0xff));
138 }
139 else
140 {
141 BFD_FAIL ();
142 }
143 if (bfd_write ((PTR) id, 1, length, abfd) != length)
144 abort ();
145 }
146 \f
147
148 /***************************************************************************
149 Functions for reading from ieee files in the strange way that the
150 standard requires:
151 */
152
153 #define this_byte(ieee) *((ieee)->input_p)
154 #define next_byte(ieee) ((ieee)->input_p++)
155 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
156
157 static unsigned short
158 read_2bytes (ieee)
159 common_header_type *ieee;
160 {
161 unsigned char c1 = this_byte_and_next (ieee);
162 unsigned char c2 = this_byte_and_next (ieee);
163 return (c1 << 8) | c2;
164 }
165
166 static void
167 bfd_get_string (ieee, string, length)
168 common_header_type *ieee;
169 char *string;
170 size_t length;
171 {
172 size_t i;
173 for (i = 0; i < length; i++)
174 {
175 string[i] = this_byte_and_next (ieee);
176 }
177 }
178
179 static char *
180 read_id (ieee)
181 common_header_type *ieee;
182 {
183 size_t length;
184 char *string;
185 length = this_byte_and_next (ieee);
186 if (length <= 0x7f)
187 {
188 /* Simple string of length 0 to 127 */
189 }
190 else if (length == 0xde)
191 {
192 /* Length is next byte, allowing 0..255 */
193 length = this_byte_and_next (ieee);
194 }
195 else if (length == 0xdf)
196 {
197 /* Length is next two bytes, allowing 0..65535 */
198 length = this_byte_and_next (ieee);
199 length = (length * 256) + this_byte_and_next (ieee);
200 }
201 /* Buy memory and read string */
202 string = bfd_alloc (ieee->abfd, length + 1);
203 if (!string)
204 return NULL;
205 bfd_get_string (ieee, string, length);
206 string[length] = 0;
207 return string;
208 }
209
210 static void
211 ieee_write_expression (abfd, value, symbol, pcrel, index)
212 bfd *abfd;
213 bfd_vma value;
214 asymbol *symbol;
215 boolean pcrel;
216 unsigned int index;
217 {
218 unsigned int term_count = 0;
219
220 if (value != 0)
221 {
222 ieee_write_int (abfd, value);
223 term_count++;
224 }
225
226 if (bfd_is_com_section (symbol->section)
227 || bfd_is_und_section (symbol->section))
228 {
229 /* Def of a common symbol */
230 ieee_write_byte (abfd, ieee_variable_X_enum);
231 ieee_write_int (abfd, symbol->value);
232 term_count++;
233 }
234 else if (! bfd_is_abs_section (symbol->section))
235 {
236 /* Ref to defined symbol - */
237
238 ieee_write_byte (abfd, ieee_variable_R_enum);
239 ieee_write_byte (abfd,
240 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
241 term_count++;
242 if (symbol->flags & BSF_GLOBAL)
243 {
244 ieee_write_byte (abfd, ieee_variable_I_enum);
245 ieee_write_int (abfd, symbol->value);
246 term_count++;
247 }
248 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
249 {
250 /* This is a reference to a defined local symbol,
251 We can easily do a local as a section+offset */
252 ieee_write_byte (abfd, ieee_variable_R_enum); /* or L */
253 ieee_write_byte (abfd,
254 (bfd_byte) (symbol->section->index + IEEE_SECTION_NUMBER_BASE));
255 ieee_write_int (abfd, symbol->value);
256 term_count++;
257 }
258 else
259 {
260 BFD_FAIL ();
261 }
262 }
263
264 if (pcrel)
265 {
266 /* subtract the pc from here by asking for PC of this section*/
267 ieee_write_byte (abfd, ieee_variable_P_enum);
268 ieee_write_byte (abfd, (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE));
269 ieee_write_byte (abfd, ieee_function_minus_enum);
270 }
271
272 if (term_count == 1)
273 {
274 ieee_write_byte (abfd, 0);
275 }
276 else
277 {
278 while (term_count > 1)
279 {
280 ieee_write_byte (abfd, ieee_function_plus_enum);
281 term_count--;
282 }
283 }
284 }
285 \f
286
287 /*****************************************************************************/
288
289 /*
290 writes any integer into the buffer supplied and always takes 5 bytes
291 */
292 static void
293 ieee_write_int5 (buffer, value)
294 bfd_byte *buffer;
295 bfd_vma value;
296 {
297 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
298 buffer[1] = (value >> 24) & 0xff;
299 buffer[2] = (value >> 16) & 0xff;
300 buffer[3] = (value >> 8) & 0xff;
301 buffer[4] = (value >> 0) & 0xff;
302 }
303
304 static void
305 ieee_write_int5_out (abfd, value)
306 bfd *abfd;
307 bfd_vma value;
308 {
309 bfd_byte b[5];
310 ieee_write_int5 (b, value);
311 if (bfd_write ((PTR) b, 1, 5, abfd) != 5)
312 abort ();
313 }
314
315 static boolean
316 parse_int (ieee, value_ptr)
317 common_header_type *ieee;
318 bfd_vma *value_ptr;
319 {
320 int value = this_byte (ieee);
321 int result;
322 if (value >= 0 && value <= 127)
323 {
324 *value_ptr = value;
325 next_byte (ieee);
326 return true;
327 }
328 else if (value >= 0x80 && value <= 0x88)
329 {
330 unsigned int count = value & 0xf;
331 result = 0;
332 next_byte (ieee);
333 while (count)
334 {
335 result = (result << 8) | this_byte_and_next (ieee);
336 count--;
337 }
338 *value_ptr = result;
339 return true;
340 }
341 return false;
342 }
343
344 static int
345 parse_i (ieee, ok)
346 common_header_type *ieee;
347 boolean *ok;
348 {
349 bfd_vma x;
350 *ok = parse_int (ieee, &x);
351 return x;
352 }
353
354 static bfd_vma
355 must_parse_int (ieee)
356 common_header_type *ieee;
357 {
358 bfd_vma result;
359 BFD_ASSERT (parse_int (ieee, &result) == true);
360 return result;
361 }
362
363 typedef struct
364 {
365 bfd_vma value;
366 asection *section;
367 ieee_symbol_index_type symbol;
368 } ieee_value_type;
369
370
371 static
372 reloc_howto_type abs32_howto
373 = HOWTO (1, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false);
374 static
375 reloc_howto_type abs16_howto
376 = HOWTO (1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false);
377
378 static
379 reloc_howto_type abs8_howto
380 = HOWTO (1, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false);
381
382 static
383 reloc_howto_type rel32_howto
384 = HOWTO (1, 0, 2, 32, true, 0, complain_overflow_signed, 0, "rel32", true, 0xffffffff,
385 0xffffffff, false);
386
387 static
388 reloc_howto_type rel16_howto
389 = HOWTO (1, 0, 1, 16, true, 0, complain_overflow_signed, 0, "rel16", true, 0x0000ffff, 0x0000ffff, false);
390
391 static
392 reloc_howto_type rel8_howto
393 = HOWTO (1, 0, 0, 8, true, 0, complain_overflow_signed, 0, "rel8", true, 0x000000ff, 0x000000ff, false);
394
395
396 static ieee_symbol_index_type NOSYMBOL =
397 {0, 0};
398
399
400 static void
401 parse_expression (ieee, value, symbol, pcrel, extra, section)
402 ieee_data_type *ieee;
403 bfd_vma *value;
404 ieee_symbol_index_type *symbol;
405 boolean *pcrel;
406 unsigned int *extra;
407 asection **section;
408
409 {
410 #define POS sp[1]
411 #define TOS sp[0]
412 #define NOS sp[-1]
413 #define INC sp++;
414 #define DEC sp--;
415
416 boolean loop = true;
417 ieee_value_type stack[10];
418
419 /* The stack pointer always points to the next unused location */
420 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
421 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
422 ieee_value_type *sp = stack;
423
424 while (loop)
425 {
426 switch (this_byte (&(ieee->h)))
427 {
428 case ieee_variable_P_enum:
429 /* P variable, current program counter for section n */
430 {
431 int section_n;
432 next_byte (&(ieee->h));
433 *pcrel = true;
434 section_n = must_parse_int (&(ieee->h));
435 PUSH (NOSYMBOL, bfd_abs_section_ptr,
436 TOS.value = ieee->section_table[section_n]->vma +
437 ieee_per_section (ieee->section_table[section_n])->pc);
438 break;
439 }
440 case ieee_variable_L_enum:
441 /* L variable address of section N */
442 next_byte (&(ieee->h));
443 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
444 break;
445 case ieee_variable_R_enum:
446 /* R variable, logical address of section module */
447 /* FIXME, this should be different to L */
448 next_byte (&(ieee->h));
449 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
450 break;
451 case ieee_variable_S_enum:
452 /* S variable, size in MAUS of section module */
453 next_byte (&(ieee->h));
454 PUSH (NOSYMBOL,
455 0,
456 ieee->section_table[must_parse_int (&(ieee->h))]->_raw_size);
457 break;
458 case ieee_variable_I_enum:
459 case ieee_variable_X_enum:
460 /* Push the address of external variable n */
461 {
462 ieee_symbol_index_type sy;
463 next_byte (&(ieee->h));
464 sy.index = (int) (must_parse_int (&(ieee->h)));
465 sy.letter = 'X';
466
467 PUSH (sy, bfd_und_section_ptr, 0);
468 }
469 break;
470 case ieee_function_minus_enum:
471 {
472 bfd_vma value1, value2;
473 asection *section1, *section_dummy;
474 ieee_symbol_index_type sy;
475 next_byte (&(ieee->h));
476
477 POP (sy, section1, value1);
478 POP (sy, section_dummy, value2);
479 PUSH (sy, section1 ? section1 : section_dummy, value1 - value2);
480 }
481 break;
482 case ieee_function_plus_enum:
483 {
484 bfd_vma value1, value2;
485 asection *section1;
486 asection *section2;
487 ieee_symbol_index_type sy1;
488 ieee_symbol_index_type sy2;
489 next_byte (&(ieee->h));
490
491 POP (sy1, section1, value1);
492 POP (sy2, section2, value2);
493 PUSH (sy1.letter ? sy1 : sy2,
494 bfd_is_abs_section (section1) ? section2 : section1,
495 value1 + value2);
496 }
497 break;
498 default:
499 {
500 bfd_vma va;
501 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
502 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
503 if (parse_int (&(ieee->h), &va))
504 {
505 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
506 }
507 else
508 {
509 /*
510 Thats all that we can understand. As far as I can see
511 there is a bug in the Microtec IEEE output which I'm
512 using to scan, whereby the comma operator is omitted
513 sometimes in an expression, giving expressions with too
514 many terms. We can tell if that's the case by ensuring
515 that sp == stack here. If not, then we've pushed
516 something too far, so we keep adding. */
517
518 while (sp != stack + 1)
519 {
520 asection *section1;
521 ieee_symbol_index_type sy1;
522 POP (sy1, section1, *extra);
523 }
524 {
525 asection *dummy;
526
527 POP (*symbol, dummy, *value);
528 if (section)
529 *section = dummy;
530 }
531
532 loop = false;
533 }
534 }
535 }
536 }
537 }
538
539
540 #define ieee_seek(abfd, offset) \
541 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
542
543 #define ieee_pos(abfd) \
544 (IEEE_DATA(abfd)->h.input_p - IEEE_DATA(abfd)->h.first_byte)
545
546 static unsigned int last_index;
547 static char last_type; /* is the index for an X or a D */
548
549 static ieee_symbol_type *
550 get_symbol (abfd,
551 ieee,
552 last_symbol,
553 symbol_count,
554 pptr,
555 max_index,
556 this_type
557 )
558 bfd *abfd;
559 ieee_data_type *ieee;
560 ieee_symbol_type *last_symbol;
561 unsigned int *symbol_count;
562 ieee_symbol_type ***pptr;
563 unsigned int *max_index;
564 char this_type
565 ;
566 {
567 /* Need a new symbol */
568 unsigned int new_index = must_parse_int (&(ieee->h));
569 if (new_index != last_index || this_type != last_type)
570 {
571 ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_alloc (ieee->h.abfd,
572 sizeof (ieee_symbol_type));
573 if (!new_symbol)
574 return NULL;
575
576 new_symbol->index = new_index;
577 last_index = new_index;
578 (*symbol_count)++;
579 **pptr = new_symbol;
580 *pptr = &new_symbol->next;
581 if (new_index > *max_index)
582 {
583 *max_index = new_index;
584 }
585 last_type = this_type;
586 return new_symbol;
587 }
588 return last_symbol;
589 }
590
591 static boolean
592 ieee_slurp_external_symbols (abfd)
593 bfd *abfd;
594 {
595 ieee_data_type *ieee = IEEE_DATA (abfd);
596 file_ptr offset = ieee->w.r.external_part;
597
598 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
599 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
600 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
601 unsigned int symbol_count = 0;
602 boolean loop = true;
603 last_index = 0xffffff;
604 ieee->symbol_table_full = true;
605
606 ieee_seek (abfd, offset);
607
608 while (loop)
609 {
610 switch (this_byte (&(ieee->h)))
611 {
612 case ieee_nn_record:
613 next_byte (&(ieee->h));
614
615 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
616 &prev_symbols_ptr,
617 &ieee->external_symbol_max_index, 'D');
618 if (symbol == NULL)
619 return false;
620
621 symbol->symbol.the_bfd = abfd;
622 symbol->symbol.name = read_id (&(ieee->h));
623 symbol->symbol.udata.p = (PTR) NULL;
624 symbol->symbol.flags = BSF_NO_FLAGS;
625 break;
626 case ieee_external_symbol_enum:
627 next_byte (&(ieee->h));
628
629 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
630 &prev_symbols_ptr,
631 &ieee->external_symbol_max_index, 'D');
632 if (symbol == NULL)
633 return false;
634
635 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
636
637 symbol->symbol.the_bfd = abfd;
638 symbol->symbol.name = read_id (&(ieee->h));
639 symbol->symbol.udata.p = (PTR) NULL;
640 symbol->symbol.flags = BSF_NO_FLAGS;
641 break;
642 case ieee_attribute_record_enum >> 8:
643 {
644 unsigned int symbol_name_index;
645 unsigned int symbol_type_index;
646 unsigned int symbol_attribute_def;
647 bfd_vma value;
648 next_byte (&(ieee->h)); /* Skip prefix */
649 next_byte (&(ieee->h));
650 symbol_name_index = must_parse_int (&(ieee->h));
651 symbol_type_index = must_parse_int (&(ieee->h));
652 symbol_attribute_def = must_parse_int (&(ieee->h));
653 switch (symbol_attribute_def)
654 {
655 case 63:
656 /* Module misc; followed by two fields which describe the
657 current module block. The first fired is the type id
658 number, the second is the number of asn records
659 associated with the directive */
660 parse_int (&(ieee->h), &value);
661 parse_int (&(ieee->h), &value);
662 break;
663
664 default:
665 parse_int (&(ieee->h), &value);
666 break;
667 }
668 }
669 break;
670 case ieee_value_record_enum >> 8:
671 {
672 unsigned int symbol_name_index;
673 ieee_symbol_index_type symbol_ignore;
674 boolean pcrel_ignore;
675 unsigned int extra;
676 next_byte (&(ieee->h));
677 next_byte (&(ieee->h));
678
679 symbol_name_index = must_parse_int (&(ieee->h));
680 parse_expression (ieee,
681 &symbol->symbol.value,
682 &symbol_ignore,
683 &pcrel_ignore,
684 &extra,
685 &symbol->symbol.section);
686
687 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
688
689 }
690 break;
691 case ieee_weak_external_reference_enum:
692 {
693 bfd_vma size;
694 bfd_vma value;
695 next_byte (&(ieee->h));
696 /* Throw away the external reference index */
697 (void) must_parse_int (&(ieee->h));
698 /* Fetch the default size if not resolved */
699 size = must_parse_int (&(ieee->h));
700 /* Fetch the defautlt value if available */
701 if (parse_int (&(ieee->h), &value) == false)
702 {
703 value = 0;
704 }
705 /* This turns into a common */
706 symbol->symbol.section = bfd_com_section_ptr;
707 symbol->symbol.value = size;
708 }
709 break;
710
711 case ieee_external_reference_enum:
712 next_byte (&(ieee->h));
713
714 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
715 &prev_reference_ptr,
716 &ieee->external_reference_max_index, 'X');
717 if (symbol == NULL)
718 return false;
719
720 symbol->symbol.the_bfd = abfd;
721 symbol->symbol.name = read_id (&(ieee->h));
722 symbol->symbol.udata.p = (PTR) NULL;
723 symbol->symbol.section = bfd_und_section_ptr;
724 symbol->symbol.value = (bfd_vma) 0;
725 symbol->symbol.flags = 0;
726
727 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
728 break;
729
730 default:
731 loop = false;
732 }
733 }
734
735 if (ieee->external_symbol_max_index != 0)
736 {
737 ieee->external_symbol_count =
738 ieee->external_symbol_max_index -
739 ieee->external_symbol_min_index + 1;
740 }
741 else
742 {
743 ieee->external_symbol_count = 0;
744 }
745
746 if (ieee->external_reference_max_index != 0)
747 {
748 ieee->external_reference_count =
749 ieee->external_reference_max_index -
750 ieee->external_reference_min_index + 1;
751 }
752 else
753 {
754 ieee->external_reference_count = 0;
755 }
756
757 abfd->symcount =
758 ieee->external_reference_count + ieee->external_symbol_count;
759
760 if (symbol_count != abfd->symcount)
761 {
762 /* There are gaps in the table -- */
763 ieee->symbol_table_full = false;
764 }
765
766 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
767 *prev_reference_ptr = (ieee_symbol_type *) NULL;
768
769 return true;
770 }
771
772 static boolean
773 ieee_slurp_symbol_table (abfd)
774 bfd *abfd;
775 {
776 if (IEEE_DATA (abfd)->read_symbols == false)
777 {
778 if (! ieee_slurp_external_symbols (abfd))
779 return false;
780 IEEE_DATA (abfd)->read_symbols = true;
781 }
782 return true;
783 }
784
785 long
786 ieee_get_symtab_upper_bound (abfd)
787 bfd *abfd;
788 {
789 if (! ieee_slurp_symbol_table (abfd))
790 return -1;
791
792 return (abfd->symcount != 0) ?
793 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
794 }
795
796 /*
797 Move from our internal lists to the canon table, and insert in
798 symbol index order
799 */
800
801 extern const bfd_target ieee_vec;
802
803 long
804 ieee_get_symtab (abfd, location)
805 bfd *abfd;
806 asymbol **location;
807 {
808 ieee_symbol_type *symp;
809 static bfd dummy_bfd;
810 static asymbol empty_symbol =
811 /* the_bfd, name, value, attr, section */
812 {&dummy_bfd, " ieee empty", (symvalue) 0, BSF_DEBUGGING, bfd_abs_section_ptr};
813
814 if (abfd->symcount)
815 {
816 ieee_data_type *ieee = IEEE_DATA (abfd);
817 dummy_bfd.xvec = &ieee_vec;
818 if (! ieee_slurp_symbol_table (abfd))
819 return -1;
820
821 if (ieee->symbol_table_full == false)
822 {
823 /* Arrgh - there are gaps in the table, run through and fill them */
824 /* up with pointers to a null place */
825 unsigned int i;
826 for (i = 0; i < abfd->symcount; i++)
827 {
828 location[i] = &empty_symbol;
829 }
830 }
831
832 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
833 for (symp = IEEE_DATA (abfd)->external_symbols;
834 symp != (ieee_symbol_type *) NULL;
835 symp = symp->next)
836 {
837 /* Place into table at correct index locations */
838 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
839 }
840
841 /* The external refs are indexed in a bit */
842 ieee->external_reference_base_offset =
843 -ieee->external_reference_min_index + ieee->external_symbol_count;
844
845 for (symp = IEEE_DATA (abfd)->external_reference;
846 symp != (ieee_symbol_type *) NULL;
847 symp = symp->next)
848 {
849 location[symp->index + ieee->external_reference_base_offset] =
850 &symp->symbol;
851
852 }
853 }
854 if (abfd->symcount)
855 {
856 location[abfd->symcount] = (asymbol *) NULL;
857 }
858 return abfd->symcount;
859 }
860
861 static asection *
862 get_section_entry (abfd, ieee, index)
863 bfd *abfd;
864 ieee_data_type *ieee;
865 unsigned int index;
866 {
867 if (ieee->section_table[index] == (asection *) NULL)
868 {
869 char *tmp = bfd_alloc (abfd, 11);
870 asection *section;
871
872 if (!tmp)
873 return NULL;
874 sprintf (tmp, " fsec%4d", index);
875 section = bfd_make_section (abfd, tmp);
876 ieee->section_table[index] = section;
877 section->flags = SEC_NO_FLAGS;
878 section->target_index = index;
879 ieee->section_table[index] = section;
880 }
881 return ieee->section_table[index];
882 }
883
884 static void
885 ieee_slurp_sections (abfd)
886 bfd *abfd;
887 {
888 ieee_data_type *ieee = IEEE_DATA (abfd);
889 file_ptr offset = ieee->w.r.section_part;
890 asection *section = (asection *) NULL;
891 char *name;
892
893 if (offset != 0)
894 {
895 bfd_byte section_type[3];
896 ieee_seek (abfd, offset);
897 while (true)
898 {
899 switch (this_byte (&(ieee->h)))
900 {
901 case ieee_section_type_enum:
902 {
903 unsigned int section_index;
904 next_byte (&(ieee->h));
905 section_index = must_parse_int (&(ieee->h));
906 /* Fixme to be nice about a silly number of sections */
907 BFD_ASSERT (section_index < NSECTIONS);
908
909 section = get_section_entry (abfd, ieee, section_index);
910
911 section_type[0] = this_byte_and_next (&(ieee->h));
912 switch (section_type[0])
913 {
914 case 0xC1:
915 /* Normal attributes for absolute sections */
916 section_type[1] = this_byte (&(ieee->h));
917 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
918 switch (section_type[1])
919 {
920 case 0xD3: /* AS Absolute section attributes */
921 next_byte (&(ieee->h));
922 section_type[2] = this_byte (&(ieee->h));
923 switch (section_type[2])
924 {
925 case 0xD0:
926 /* Normal code */
927 next_byte (&(ieee->h));
928 section->flags |= SEC_LOAD | SEC_CODE;
929 break;
930 case 0xC4:
931 next_byte (&(ieee->h));
932 section->flags |= SEC_LOAD | SEC_DATA;
933 /* Normal data */
934 break;
935 case 0xD2:
936 next_byte (&(ieee->h));
937 /* Normal rom data */
938 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
939 break;
940 default:
941 break;
942 }
943 }
944 break;
945 case 0xC3: /* Named relocatable sections (type C) */
946 section_type[1] = this_byte (&(ieee->h));
947 section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
948 switch (section_type[1])
949 {
950 case 0xD0: /* Normal code (CP) */
951 next_byte (&(ieee->h));
952 section->flags |= SEC_LOAD | SEC_CODE;
953 break;
954 case 0xC4: /* Normal data (CD) */
955 next_byte (&(ieee->h));
956 section->flags |= SEC_LOAD | SEC_DATA;
957 break;
958 case 0xD2: /* Normal rom data (CR) */
959 next_byte (&(ieee->h));
960 section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;
961 break;
962 default:
963 break;
964 }
965 }
966
967 /* Read section name, use it if non empty. */
968 name = read_id (&ieee->h);
969 if (name[0])
970 section->name = name;
971
972 /* Skip these fields, which we don't care about */
973 {
974 bfd_vma parent, brother, context;
975 parse_int (&(ieee->h), &parent);
976 parse_int (&(ieee->h), &brother);
977 parse_int (&(ieee->h), &context);
978 }
979 }
980 break;
981 case ieee_section_alignment_enum:
982 {
983 unsigned int section_index;
984 bfd_vma value;
985 asection *section;
986 next_byte (&(ieee->h));
987 section_index = must_parse_int (&ieee->h);
988 section = get_section_entry (abfd, ieee, section_index);
989 if (section_index > ieee->section_count)
990 {
991 ieee->section_count = section_index;
992 }
993 section->alignment_power =
994 bfd_log2 (must_parse_int (&ieee->h));
995 (void) parse_int (&(ieee->h), &value);
996 }
997 break;
998 case ieee_e2_first_byte_enum:
999 {
1000 ieee_record_enum_type t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1001
1002 switch (t)
1003 {
1004 case ieee_section_size_enum:
1005 section = ieee->section_table[must_parse_int (&(ieee->h))];
1006 section->_raw_size = must_parse_int (&(ieee->h));
1007 break;
1008 case ieee_physical_region_size_enum:
1009 section = ieee->section_table[must_parse_int (&(ieee->h))];
1010 section->_raw_size = must_parse_int (&(ieee->h));
1011 break;
1012 case ieee_region_base_address_enum:
1013 section = ieee->section_table[must_parse_int (&(ieee->h))];
1014 section->vma = must_parse_int (&(ieee->h));
1015 break;
1016 case ieee_mau_size_enum:
1017 must_parse_int (&(ieee->h));
1018 must_parse_int (&(ieee->h));
1019 break;
1020 case ieee_m_value_enum:
1021 must_parse_int (&(ieee->h));
1022 must_parse_int (&(ieee->h));
1023 break;
1024 case ieee_section_base_address_enum:
1025 section = ieee->section_table[must_parse_int (&(ieee->h))];
1026 section->vma = must_parse_int (&(ieee->h));
1027 break;
1028 case ieee_section_offset_enum:
1029 (void) must_parse_int (&(ieee->h));
1030 (void) must_parse_int (&(ieee->h));
1031 break;
1032 default:
1033 return;
1034 }
1035 }
1036 break;
1037 default:
1038 return;
1039 }
1040 }
1041 }
1042 }
1043 \f
1044
1045 /***********************************************************************
1046 * archive stuff
1047 */
1048
1049 const bfd_target *
1050 ieee_archive_p (abfd)
1051 bfd *abfd;
1052 {
1053 char *library;
1054 boolean loop;
1055
1056 unsigned int i;
1057 unsigned char buffer[512];
1058 struct obstack ob;
1059 file_ptr buffer_offset = 0;
1060 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1061 ieee_ar_data_type *ieee;
1062 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, sizeof (ieee_ar_data_type));
1063 if (!abfd->tdata.ieee_ar_data)
1064 return NULL;
1065 ieee = IEEE_AR_DATA (abfd);
1066
1067 /* FIXME: Check return value. I'm not sure whether it needs to read
1068 the entire buffer or not. */
1069 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1070
1071 ieee->h.first_byte = buffer;
1072 ieee->h.input_p = buffer;
1073
1074 ieee->h.abfd = abfd;
1075
1076 if (this_byte (&(ieee->h)) != Module_Beginning)
1077 {
1078 abfd->tdata.ieee_ar_data = save;
1079 return (const bfd_target *) NULL;
1080 }
1081
1082 next_byte (&(ieee->h));
1083 library = read_id (&(ieee->h));
1084 if (strcmp (library, "LIBRARY") != 0)
1085 {
1086 bfd_release (abfd, ieee);
1087 abfd->tdata.ieee_ar_data = save;
1088 return (const bfd_target *) NULL;
1089 }
1090 /* Throw away the filename */
1091 read_id (&(ieee->h));
1092 /* This must be an IEEE archive, so we'll buy some space to do
1093 things */
1094
1095 if (!obstack_begin (&ob, 128))
1096 {
1097 bfd_set_error (bfd_error_no_memory);
1098 return (const bfd_target *) NULL;
1099 }
1100
1101 ieee->element_count = 0;
1102 ieee->element_index = 0;
1103
1104 next_byte (&(ieee->h)); /* Drop the ad part */
1105 must_parse_int (&(ieee->h)); /* And the two dummy numbers */
1106 must_parse_int (&(ieee->h));
1107
1108 loop = true;
1109 /* Read the index of the BB table */
1110 while (loop)
1111 {
1112 ieee_ar_obstack_type t;
1113 int rec = read_2bytes (&(ieee->h));
1114 if (rec == (int) ieee_assign_value_to_variable_enum)
1115 {
1116 must_parse_int (&(ieee->h));
1117 t.file_offset = must_parse_int (&(ieee->h));
1118 t.abfd = (bfd *) NULL;
1119 ieee->element_count++;
1120
1121 obstack_grow (&ob, (PTR) & t, sizeof (t));
1122
1123 /* Make sure that we don't go over the end of the buffer */
1124
1125 if ((size_t) ieee_pos (abfd) > sizeof (buffer) / 2)
1126 {
1127 /* Past half way, reseek and reprime */
1128 buffer_offset += ieee_pos (abfd);
1129 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1130 return NULL;
1131 /* FIXME: Check return value. I'm not sure whether it
1132 needs to read the entire buffer or not. */
1133 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1134 ieee->h.first_byte = buffer;
1135 ieee->h.input_p = buffer;
1136 }
1137 }
1138 else
1139 loop = false;
1140 }
1141
1142 ieee->elements = (ieee_ar_obstack_type *) obstack_finish (&ob);
1143 if (!ieee->elements)
1144 {
1145 bfd_set_error (bfd_error_no_memory);
1146 return (const bfd_target *) NULL;
1147 }
1148
1149 /* Now scan the area again, and replace BB offsets with file */
1150 /* offsets */
1151
1152 for (i = 2; i < ieee->element_count; i++)
1153 {
1154 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1155 return NULL;
1156 /* FIXME: Check return value. I'm not sure whether it needs to
1157 read the entire buffer or not. */
1158 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1159 ieee->h.first_byte = buffer;
1160 ieee->h.input_p = buffer;
1161
1162 next_byte (&(ieee->h)); /* Drop F8 */
1163 next_byte (&(ieee->h)); /* Drop 14 */
1164 must_parse_int (&(ieee->h)); /* Drop size of block */
1165 if (must_parse_int (&(ieee->h)) != 0)
1166 {
1167 /* This object has been deleted */
1168 ieee->elements[i].file_offset = 0;
1169 }
1170 else
1171 {
1172 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1173 }
1174 }
1175
1176 /* abfd->has_armap = ;*/
1177 return abfd->xvec;
1178 }
1179
1180 static boolean
1181 ieee_mkobject (abfd)
1182 bfd *abfd;
1183 {
1184 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, sizeof (ieee_data_type));
1185 return abfd->tdata.ieee_data ? true : false;
1186 }
1187
1188 const bfd_target *
1189 ieee_object_p (abfd)
1190 bfd *abfd;
1191 {
1192 char *processor;
1193 unsigned int part;
1194 ieee_data_type *ieee;
1195 unsigned char buffer[300];
1196 ieee_data_type *save = IEEE_DATA (abfd);
1197
1198 abfd->tdata.ieee_data = 0;
1199 ieee_mkobject (abfd);
1200
1201 ieee = IEEE_DATA (abfd);
1202 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1203 goto fail;
1204 /* Read the first few bytes in to see if it makes sense */
1205 /* FIXME: Check return value. I'm not sure whether it needs to read
1206 the entire buffer or not. */
1207 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
1208
1209 ieee->h.input_p = buffer;
1210 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1211 goto got_wrong_format;
1212
1213 ieee->read_symbols = false;
1214 ieee->read_data = false;
1215 ieee->section_count = 0;
1216 ieee->external_symbol_max_index = 0;
1217 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1218 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1219 ieee->external_reference_max_index = 0;
1220 ieee->h.abfd = abfd;
1221 memset ((PTR) ieee->section_table, 0, sizeof (ieee->section_table));
1222
1223 processor = ieee->mb.processor = read_id (&(ieee->h));
1224 if (strcmp (processor, "LIBRARY") == 0)
1225 goto got_wrong_format;
1226 ieee->mb.module_name = read_id (&(ieee->h));
1227 if (abfd->filename == (CONST char *) NULL)
1228 {
1229 abfd->filename = ieee->mb.module_name;
1230 }
1231 /* Determine the architecture and machine type of the object file.
1232 */
1233 {
1234 const bfd_arch_info_type *arch = bfd_scan_arch (processor);
1235 if (arch == 0)
1236 goto got_wrong_format;
1237 abfd->arch_info = arch;
1238 }
1239
1240 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1241 {
1242 goto fail;
1243 }
1244 next_byte (&(ieee->h));
1245
1246 if (parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau) == false)
1247 {
1248 goto fail;
1249 }
1250 if (parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address) == false)
1251 {
1252 goto fail;
1253 }
1254
1255 /* If there is a byte order info, take it */
1256 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum ||
1257 this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
1258 next_byte (&(ieee->h));
1259
1260 for (part = 0; part < N_W_VARIABLES; part++)
1261 {
1262 boolean ok;
1263 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
1264 {
1265 goto fail;
1266 }
1267 if (this_byte_and_next (&(ieee->h)) != part)
1268 {
1269 goto fail;
1270 }
1271
1272 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
1273 if (ok == false)
1274 {
1275 goto fail;
1276 }
1277
1278 }
1279 abfd->flags = HAS_SYMS;
1280 /* By now we know that this is a real IEEE file, we're going to read
1281 the whole thing into memory so that we can run up and down it
1282 quickly. We can work out how big the file is from the trailer
1283 record */
1284
1285 IEEE_DATA (abfd)->h.first_byte = (unsigned char *) bfd_alloc (ieee->h.abfd, ieee->w.r.me_record
1286 + 50);
1287 if (!IEEE_DATA (abfd)->h.first_byte)
1288 goto fail;
1289 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1290 goto fail;
1291 /* FIXME: Check return value. I'm not sure whether it needs to read
1292 the entire buffer or not. */
1293 bfd_read ((PTR) (IEEE_DATA (abfd)->h.first_byte), 1, ieee->w.r.me_record + 50, abfd);
1294
1295 ieee_slurp_sections (abfd);
1296 return abfd->xvec;
1297 got_wrong_format:
1298 bfd_set_error (bfd_error_wrong_format);
1299 fail:
1300 (void) bfd_release (abfd, ieee);
1301 abfd->tdata.ieee_data = save;
1302 return (const bfd_target *) NULL;
1303 }
1304
1305 void
1306 ieee_get_symbol_info (ignore_abfd, symbol, ret)
1307 bfd *ignore_abfd;
1308 asymbol *symbol;
1309 symbol_info *ret;
1310 {
1311 bfd_symbol_info (symbol, ret);
1312 if (symbol->name[0] == ' ')
1313 ret->name = "* empty table entry ";
1314 if (!symbol->section)
1315 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
1316 }
1317
1318 void
1319 ieee_print_symbol (ignore_abfd, afile, symbol, how)
1320 bfd *ignore_abfd;
1321 PTR afile;
1322 asymbol *symbol;
1323 bfd_print_symbol_type how;
1324 {
1325 FILE *file = (FILE *) afile;
1326
1327 switch (how)
1328 {
1329 case bfd_print_symbol_name:
1330 fprintf (file, "%s", symbol->name);
1331 break;
1332 case bfd_print_symbol_more:
1333 #if 0
1334 fprintf (file, "%4x %2x", aout_symbol (symbol)->desc & 0xffff,
1335 aout_symbol (symbol)->other & 0xff);
1336 #endif
1337 BFD_FAIL ();
1338 break;
1339 case bfd_print_symbol_all:
1340 {
1341 CONST char *section_name = symbol->section == (asection *) NULL ?
1342 (CONST char *) "*abs" : symbol->section->name;
1343 if (symbol->name[0] == ' ')
1344 {
1345 fprintf (file, "* empty table entry ");
1346 }
1347 else
1348 {
1349 bfd_print_symbol_vandf ((PTR) file, symbol);
1350
1351 fprintf (file, " %-5s %04x %02x %s",
1352 section_name,
1353 (unsigned) ieee_symbol (symbol)->index,
1354 (unsigned) 0, /*
1355 aout_symbol(symbol)->desc & 0xffff,
1356 aout_symbol(symbol)->other & 0xff,*/
1357 symbol->name);
1358 }
1359 }
1360 break;
1361 }
1362 }
1363
1364 static boolean
1365 do_one (ieee, current_map, location_ptr, s)
1366 ieee_data_type *ieee;
1367 ieee_per_section_type *current_map;
1368 unsigned char *location_ptr;
1369 asection *s;
1370 {
1371 switch (this_byte (&(ieee->h)))
1372 {
1373 case ieee_load_constant_bytes_enum:
1374 {
1375 unsigned int number_of_maus;
1376 unsigned int i;
1377 next_byte (&(ieee->h));
1378 number_of_maus = must_parse_int (&(ieee->h));
1379
1380 for (i = 0; i < number_of_maus; i++)
1381 {
1382 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1383 next_byte (&(ieee->h));
1384 }
1385 }
1386 break;
1387
1388 case ieee_load_with_relocation_enum:
1389 {
1390 boolean loop = true;
1391 next_byte (&(ieee->h));
1392 while (loop)
1393 {
1394 switch (this_byte (&(ieee->h)))
1395 {
1396 case ieee_variable_R_enum:
1397
1398 case ieee_function_signed_open_b_enum:
1399 case ieee_function_unsigned_open_b_enum:
1400 case ieee_function_either_open_b_enum:
1401 {
1402 unsigned int extra = 4;
1403 boolean pcrel = false;
1404 asection *section;
1405 ieee_reloc_type *r =
1406 (ieee_reloc_type *) bfd_alloc (ieee->h.abfd,
1407 sizeof (ieee_reloc_type));
1408 if (!r)
1409 return false;
1410
1411 *(current_map->reloc_tail_ptr) = r;
1412 current_map->reloc_tail_ptr = &r->next;
1413 r->next = (ieee_reloc_type *) NULL;
1414 next_byte (&(ieee->h));
1415 /* abort();*/
1416 r->relent.sym_ptr_ptr = 0;
1417 parse_expression (ieee,
1418 &r->relent.addend,
1419 &r->symbol,
1420 &pcrel, &extra, &section);
1421 r->relent.address = current_map->pc;
1422 s->reloc_count++;
1423 if (r->relent.sym_ptr_ptr == 0)
1424 {
1425 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1426 }
1427
1428 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1429 {
1430 next_byte (&(ieee->h));
1431 /* Fetch number of bytes to pad */
1432 extra = must_parse_int (&(ieee->h));
1433 };
1434
1435 switch (this_byte (&(ieee->h)))
1436 {
1437 case ieee_function_signed_close_b_enum:
1438 next_byte (&(ieee->h));
1439 break;
1440 case ieee_function_unsigned_close_b_enum:
1441 next_byte (&(ieee->h));
1442 break;
1443 case ieee_function_either_close_b_enum:
1444 next_byte (&(ieee->h));
1445 break;
1446 default:
1447 break;
1448 }
1449 /* Build a relocation entry for this type */
1450 /* If pc rel then stick -ve pc into instruction
1451 and take out of reloc ..
1452
1453 I've changed this. It's all too
1454 complicated. I keep 0 in the
1455 instruction now.
1456 */
1457
1458 switch (extra)
1459 {
1460 case 0:
1461 case 4:
1462
1463 if (pcrel == true)
1464 {
1465 #if KEEPMINUSPCININST
1466 bfd_put_32 (ieee->h.abfd, -current_map->pc, location_ptr +
1467 current_map->pc);
1468 r->relent.howto = &rel32_howto;
1469 r->relent.addend -=
1470 current_map->pc;
1471 #else
1472 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1473 current_map->pc);
1474 r->relent.howto = &rel32_howto;
1475 #endif
1476 }
1477 else
1478 {
1479 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1480 current_map->pc);
1481 r->relent.howto = &abs32_howto;
1482 }
1483 current_map->pc += 4;
1484 break;
1485 case 2:
1486 if (pcrel == true)
1487 {
1488 #if KEEPMINUSPCININST
1489 bfd_put_16 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1490 r->relent.addend -= current_map->pc;
1491 r->relent.howto = &rel16_howto;
1492 #else
1493
1494 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1495 r->relent.howto = &rel16_howto;
1496 #endif
1497 }
1498
1499 else
1500 {
1501 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1502 r->relent.howto = &abs16_howto;
1503 }
1504 current_map->pc += 2;
1505 break;
1506 case 1:
1507 if (pcrel == true)
1508 {
1509 #if KEEPMINUSPCININST
1510 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1511 r->relent.addend -= current_map->pc;
1512 r->relent.howto = &rel8_howto;
1513 #else
1514 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1515 r->relent.howto = &rel8_howto;
1516 #endif
1517 }
1518 else
1519 {
1520 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1521 r->relent.howto = &abs8_howto;
1522 }
1523 current_map->pc += 1;
1524 break;
1525
1526 default:
1527 BFD_FAIL ();
1528 break;
1529 }
1530 }
1531 break;
1532 default:
1533 {
1534 bfd_vma this_size;
1535 if (parse_int (&(ieee->h), &this_size) == true)
1536 {
1537 unsigned int i;
1538 for (i = 0; i < this_size; i++)
1539 {
1540 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1541 next_byte (&(ieee->h));
1542 }
1543 }
1544 else
1545 {
1546 loop = false;
1547 }
1548 }
1549 }
1550 }
1551 }
1552 }
1553 return true;
1554 }
1555
1556 /* Read in all the section data and relocation stuff too */
1557 static boolean
1558 ieee_slurp_section_data (abfd)
1559 bfd *abfd;
1560 {
1561 bfd_byte *location_ptr = (bfd_byte *) NULL;
1562 ieee_data_type *ieee = IEEE_DATA (abfd);
1563 unsigned int section_number;
1564
1565 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
1566 asection *s;
1567 /* Seek to the start of the data area */
1568 if (ieee->read_data == true)
1569 return true;
1570 ieee->read_data = true;
1571 ieee_seek (abfd, ieee->w.r.data_part);
1572
1573 /* Allocate enough space for all the section contents */
1574
1575 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1576 {
1577 ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd;
1578 per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->_raw_size);
1579 if (!per->data)
1580 return false;
1581 /*SUPPRESS 68*/
1582 per->reloc_tail_ptr =
1583 (ieee_reloc_type **) & (s->relocation);
1584 }
1585
1586 while (true)
1587 {
1588 switch (this_byte (&(ieee->h)))
1589 {
1590 /* IF we see anything strange then quit */
1591 default:
1592 return true;
1593
1594 case ieee_set_current_section_enum:
1595 next_byte (&(ieee->h));
1596 section_number = must_parse_int (&(ieee->h));
1597 s = ieee->section_table[section_number];
1598 current_map = (ieee_per_section_type *) s->used_by_bfd;
1599 location_ptr = current_map->data - s->vma;
1600 /* The document I have says that Microtec's compilers reset */
1601 /* this after a sec section, even though the standard says not */
1602 /* to. SO .. */
1603 current_map->pc = s->vma;
1604 break;
1605
1606 case ieee_e2_first_byte_enum:
1607 next_byte (&(ieee->h));
1608 switch (this_byte (&(ieee->h)))
1609 {
1610 case ieee_set_current_pc_enum & 0xff:
1611 {
1612 bfd_vma value;
1613 ieee_symbol_index_type symbol;
1614 unsigned int extra;
1615 boolean pcrel;
1616 next_byte (&(ieee->h));
1617 must_parse_int (&(ieee->h)); /* Thow away section #*/
1618 parse_expression (ieee, &value,
1619 &symbol,
1620 &pcrel, &extra,
1621 0);
1622 current_map->pc = value;
1623 BFD_ASSERT ((unsigned) (value - s->vma) <= s->_raw_size);
1624 }
1625 break;
1626
1627 case ieee_value_starting_address_enum & 0xff:
1628 /* We've got to the end of the data now - */
1629 return true;
1630 default:
1631 BFD_FAIL ();
1632 return true;
1633 }
1634 break;
1635 case ieee_repeat_data_enum:
1636 {
1637 /* Repeat the following LD or LR n times - we do this by
1638 remembering the stream pointer before running it and
1639 resetting it and running it n times. We special case
1640 the repetition of a repeat_data/load_constant
1641 */
1642
1643 unsigned int iterations;
1644 unsigned char *start;
1645 next_byte (&(ieee->h));
1646 iterations = must_parse_int (&(ieee->h));
1647 start = ieee->h.input_p;
1648 if (start[0] == (int) ieee_load_constant_bytes_enum &&
1649 start[1] == 1)
1650 {
1651 while (iterations != 0)
1652 {
1653 location_ptr[current_map->pc++] = start[2];
1654 iterations--;
1655 }
1656 next_byte (&(ieee->h));
1657 next_byte (&(ieee->h));
1658 next_byte (&(ieee->h));
1659 }
1660 else
1661 {
1662 while (iterations != 0)
1663 {
1664 ieee->h.input_p = start;
1665 if (!do_one (ieee, current_map, location_ptr, s))
1666 return false;
1667 iterations--;
1668 }
1669 }
1670 }
1671 break;
1672 case ieee_load_constant_bytes_enum:
1673 case ieee_load_with_relocation_enum:
1674 {
1675 if (!do_one (ieee, current_map, location_ptr, s))
1676 return false;
1677 }
1678 }
1679 }
1680 }
1681
1682 boolean
1683 ieee_new_section_hook (abfd, newsect)
1684 bfd *abfd;
1685 asection *newsect;
1686 {
1687 newsect->used_by_bfd = (PTR)
1688 bfd_alloc (abfd, sizeof (ieee_per_section_type));
1689 if (!newsect->used_by_bfd)
1690 return false;
1691 ieee_per_section (newsect)->data = (bfd_byte *) NULL;
1692 ieee_per_section (newsect)->section = newsect;
1693 return true;
1694 }
1695
1696 long
1697 ieee_get_reloc_upper_bound (abfd, asect)
1698 bfd *abfd;
1699 sec_ptr asect;
1700 {
1701 if (! ieee_slurp_section_data (abfd))
1702 return -1;
1703 return (asect->reloc_count + 1) * sizeof (arelent *);
1704 }
1705
1706 static boolean
1707 ieee_get_section_contents (abfd, section, location, offset, count)
1708 bfd *abfd;
1709 sec_ptr section;
1710 PTR location;
1711 file_ptr offset;
1712 bfd_size_type count;
1713 {
1714 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
1715 ieee_slurp_section_data (abfd);
1716 (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
1717 return true;
1718 }
1719
1720 long
1721 ieee_canonicalize_reloc (abfd, section, relptr, symbols)
1722 bfd *abfd;
1723 sec_ptr section;
1724 arelent **relptr;
1725 asymbol **symbols;
1726 {
1727 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1728 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
1729 ieee_data_type *ieee = IEEE_DATA (abfd);
1730
1731 while (src != (ieee_reloc_type *) NULL)
1732 {
1733 /* Work out which symbol to attach it this reloc to */
1734 switch (src->symbol.letter)
1735 {
1736 case 'X':
1737 src->relent.sym_ptr_ptr =
1738 symbols + src->symbol.index + ieee->external_reference_base_offset;
1739 break;
1740 case 0:
1741 src->relent.sym_ptr_ptr =
1742 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
1743 break;
1744 default:
1745
1746 BFD_FAIL ();
1747 }
1748 *relptr++ = &src->relent;
1749 src = src->next;
1750 }
1751 *relptr = (arelent *) NULL;
1752 return section->reloc_count;
1753 }
1754
1755 static int
1756 comp (ap, bp)
1757 CONST PTR ap;
1758 CONST PTR bp;
1759 {
1760 arelent *a = *((arelent **) ap);
1761 arelent *b = *((arelent **) bp);
1762 return a->address - b->address;
1763 }
1764
1765 /*
1766 Write the section headers
1767 */
1768
1769 static void
1770 ieee_write_section_part (abfd)
1771 bfd *abfd;
1772 {
1773 ieee_data_type *ieee = IEEE_DATA (abfd);
1774 asection *s;
1775 ieee->w.r.section_part = bfd_tell (abfd);
1776 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1777 {
1778 if (! bfd_is_abs_section (s))
1779 {
1780 ieee_write_byte (abfd, ieee_section_type_enum);
1781 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1782
1783 if (abfd->flags & EXEC_P)
1784 {
1785 /* This image is executable, so output absolute sections */
1786 ieee_write_byte (abfd, ieee_variable_A_enum);
1787 ieee_write_byte (abfd, ieee_variable_S_enum);
1788 }
1789 else
1790 {
1791 ieee_write_byte (abfd, ieee_variable_C_enum);
1792 }
1793
1794 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
1795 {
1796 case SEC_CODE | SEC_LOAD:
1797 case SEC_CODE:
1798 ieee_write_byte (abfd, ieee_variable_P_enum);
1799 break;
1800 case SEC_DATA:
1801 default:
1802 ieee_write_byte (abfd, ieee_variable_D_enum);
1803 break;
1804 case SEC_ROM:
1805 case SEC_ROM | SEC_DATA:
1806 case SEC_ROM | SEC_LOAD:
1807 case SEC_ROM | SEC_DATA | SEC_LOAD:
1808
1809 ieee_write_byte (abfd, ieee_variable_R_enum);
1810 }
1811
1812
1813 ieee_write_id (abfd, s->name);
1814 #if 0
1815 ieee_write_int (abfd, 0); /* Parent */
1816 ieee_write_int (abfd, 0); /* Brother */
1817 ieee_write_int (abfd, 0); /* Context */
1818 #endif
1819 /* Alignment */
1820 ieee_write_byte (abfd, ieee_section_alignment_enum);
1821 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1822 ieee_write_int (abfd, 1 << s->alignment_power);
1823
1824 /* Size */
1825 ieee_write_2bytes (abfd, ieee_section_size_enum);
1826 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1827 ieee_write_int (abfd, s->_raw_size);
1828 if (abfd->flags & EXEC_P)
1829 {
1830 /* Relocateable sections don't have asl records */
1831 /* Vma */
1832 ieee_write_2bytes (abfd, ieee_section_base_address_enum);
1833 ieee_write_byte (abfd,
1834 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1835 ieee_write_int (abfd, s->vma);
1836 }
1837 }
1838
1839 }
1840 }
1841
1842
1843 static boolean
1844 do_with_relocs (abfd, s)
1845 bfd *abfd;
1846 asection *s;
1847 {
1848 unsigned int relocs_to_go = s->reloc_count;
1849
1850 bfd_byte *stream = ieee_per_section (s)->data;
1851 arelent **p = s->orelocation;
1852
1853 bfd_size_type current_byte_index = 0;
1854
1855 qsort (s->orelocation,
1856 relocs_to_go,
1857 sizeof (arelent **),
1858 comp);
1859
1860 /* Output the section preheader */
1861 ieee_write_byte (abfd, ieee_set_current_section_enum);
1862 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1863
1864 ieee_write_twobyte (abfd, ieee_set_current_pc_enum);
1865 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
1866 ieee_write_expression (abfd, 0, s->symbol, 0, 0);
1867
1868 if (relocs_to_go == 0)
1869 {
1870 /* If there arn't any relocations then output the load constant byte
1871 opcode rather than the load with relocation opcode */
1872
1873 while (current_byte_index < s->_raw_size)
1874 {
1875 bfd_size_type run;
1876 unsigned int MAXRUN = 32;
1877 run = MAXRUN;
1878 if (run > s->_raw_size - current_byte_index)
1879 {
1880 run = s->_raw_size - current_byte_index;
1881 }
1882
1883 if (run != 0)
1884 {
1885 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
1886 /* Output a stream of bytes */
1887 ieee_write_int (abfd, run);
1888 if (bfd_write ((PTR) (stream + current_byte_index),
1889 1,
1890 run,
1891 abfd)
1892 != run)
1893 return false;
1894 current_byte_index += run;
1895 }
1896 }
1897 }
1898 else
1899 {
1900 ieee_write_byte (abfd, ieee_load_with_relocation_enum);
1901
1902
1903 /* Output the data stream as the longest sequence of bytes
1904 possible, allowing for the a reasonable packet size and
1905 relocation stuffs */
1906
1907 if ((PTR) stream == (PTR) NULL)
1908 {
1909 /* Outputting a section without data, fill it up */
1910 stream = (unsigned char *) (bfd_alloc (abfd, s->_raw_size));
1911 if (!stream)
1912 return false;
1913 memset ((PTR) stream, 0, (size_t) s->_raw_size);
1914 }
1915 while (current_byte_index < s->_raw_size)
1916 {
1917 bfd_size_type run;
1918 unsigned int MAXRUN = 32;
1919 if (relocs_to_go)
1920 {
1921 run = (*p)->address - current_byte_index;
1922 }
1923 else
1924 {
1925 run = MAXRUN;
1926 }
1927 if (run > s->_raw_size - current_byte_index)
1928 {
1929 run = s->_raw_size - current_byte_index;
1930 }
1931
1932 if (run != 0)
1933 {
1934 /* Output a stream of bytes */
1935 ieee_write_int (abfd, run);
1936 if (bfd_write ((PTR) (stream + current_byte_index),
1937 1,
1938 run,
1939 abfd)
1940 != run)
1941 return false;
1942 current_byte_index += run;
1943 }
1944 /* Output any relocations here */
1945 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1946 {
1947 while (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1948 {
1949
1950 arelent *r = *p;
1951 bfd_vma ov;
1952
1953 #if 0
1954 if (r->howto->pc_relative)
1955 {
1956 r->addend += current_byte_index;
1957 }
1958 #endif
1959
1960 switch (r->howto->size)
1961 {
1962 case 2:
1963
1964 ov = bfd_get_32 (abfd,
1965 stream + current_byte_index);
1966 current_byte_index += 4;
1967 break;
1968 case 1:
1969 ov = bfd_get_16 (abfd,
1970 stream + current_byte_index);
1971 current_byte_index += 2;
1972 break;
1973 case 0:
1974 ov = bfd_get_8 (abfd,
1975 stream + current_byte_index);
1976 current_byte_index++;
1977 break;
1978 default:
1979 ov = 0;
1980 BFD_FAIL ();
1981 }
1982 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
1983 /* abort();*/
1984
1985 if (r->sym_ptr_ptr != (asymbol **) NULL)
1986 {
1987 ieee_write_expression (abfd, r->addend + ov,
1988 *(r->sym_ptr_ptr),
1989 r->howto->pc_relative, s->index);
1990 }
1991 else
1992 {
1993 ieee_write_expression (abfd, r->addend + ov,
1994 (asymbol *) NULL,
1995 r->howto->pc_relative, s->index);
1996 }
1997
1998 if (1 || r->howto->size != 2)
1999 {
2000 ieee_write_byte (abfd, ieee_comma);
2001 ieee_write_int (abfd, 1 << r->howto->size);
2002 }
2003 ieee_write_byte (abfd,
2004 ieee_function_either_close_b_enum);
2005
2006 relocs_to_go--;
2007 p++;
2008 }
2009
2010 }
2011 }
2012 }
2013 return true;
2014 }
2015
2016 /* If there are no relocations in the output section then we can
2017 be clever about how we write. We block items up into a max of 127
2018 bytes */
2019
2020 static void
2021 do_as_repeat (abfd, s)
2022 bfd *abfd;
2023 asection *s;
2024 {
2025 if (s->_raw_size)
2026 {
2027 ieee_write_byte (abfd, ieee_set_current_section_enum);
2028 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2029 ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8);
2030 ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff);
2031 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
2032 ieee_write_int (abfd, s->vma);
2033
2034 ieee_write_byte (abfd, ieee_repeat_data_enum);
2035 ieee_write_int (abfd, s->_raw_size);
2036 ieee_write_byte (abfd, ieee_load_constant_bytes_enum);
2037 ieee_write_byte (abfd, 1);
2038 ieee_write_byte (abfd, 0);
2039 }
2040 }
2041
2042 static void
2043 do_without_relocs (abfd, s)
2044 bfd *abfd;
2045 asection *s;
2046 {
2047 bfd_byte *stream = ieee_per_section (s)->data;
2048
2049 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2050 {
2051 do_as_repeat (abfd, s);
2052 }
2053 else
2054 {
2055 unsigned int i;
2056 for (i = 0; i < s->_raw_size; i++)
2057 {
2058 if (stream[i] != 0)
2059 {
2060 do_with_relocs (abfd, s);
2061 return;
2062 }
2063 }
2064 do_as_repeat (abfd, s);
2065 }
2066
2067 }
2068
2069
2070 static unsigned char *output_ptr_start;
2071 static unsigned char *output_ptr;
2072 static unsigned char *output_ptr_end;
2073 static unsigned char *input_ptr_start;
2074 static unsigned char *input_ptr;
2075 static unsigned char *input_ptr_end;
2076 static bfd *input_bfd;
2077 static bfd *output_bfd;
2078 static int output_buffer;
2079
2080 static void
2081 fill ()
2082 {
2083 /* FIXME: Check return value. I'm not sure whether it needs to read
2084 the entire buffer or not. */
2085 bfd_read ((PTR) input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
2086 input_ptr = input_ptr_start;
2087 }
2088 static void
2089 flush ()
2090 {
2091 if (bfd_write ((PTR) (output_ptr_start), 1, output_ptr - output_ptr_start,
2092 output_bfd)
2093 != (bfd_size_type) (output_ptr - output_ptr_start))
2094 abort ();
2095 output_ptr = output_ptr_start;
2096 output_buffer++;
2097 }
2098
2099 #define THIS() ( *input_ptr )
2100 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2101 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2102
2103 static void
2104 write_int (value)
2105 int value;
2106 {
2107 if (value >= 0 && value <= 127)
2108 {
2109 OUT (value);
2110 }
2111 else
2112 {
2113 unsigned int length;
2114 /* How many significant bytes ? */
2115 /* FIXME FOR LONGER INTS */
2116 if (value & 0xff000000)
2117 {
2118 length = 4;
2119 }
2120 else if (value & 0x00ff0000)
2121 {
2122 length = 3;
2123 }
2124 else if (value & 0x0000ff00)
2125 {
2126 length = 2;
2127 }
2128 else
2129 length = 1;
2130
2131 OUT ((int) ieee_number_repeat_start_enum + length);
2132 switch (length)
2133 {
2134 case 4:
2135 OUT (value >> 24);
2136 case 3:
2137 OUT (value >> 16);
2138 case 2:
2139 OUT (value >> 8);
2140 case 1:
2141 OUT (value);
2142 }
2143
2144 }
2145 }
2146
2147 static void
2148 copy_id ()
2149 {
2150 int length = THIS ();
2151 char ch;
2152 OUT (length);
2153 NEXT ();
2154 while (length--)
2155 {
2156 ch = THIS ();
2157 OUT (ch);
2158 NEXT ();
2159 }
2160 }
2161
2162 #define VAR(x) ((x | 0x80))
2163 static void
2164 copy_expression ()
2165 {
2166 int stack[10];
2167 int *tos = stack;
2168 int value = 0;
2169 while (1)
2170 {
2171 switch (THIS ())
2172 {
2173 case 0x84:
2174 NEXT ();
2175 value = THIS ();
2176 NEXT ();
2177 value = (value << 8) | THIS ();
2178 NEXT ();
2179 value = (value << 8) | THIS ();
2180 NEXT ();
2181 value = (value << 8) | THIS ();
2182 NEXT ();
2183 *tos++ = value;
2184 break;
2185 case 0x83:
2186 NEXT ();
2187 value = THIS ();
2188 NEXT ();
2189 value = (value << 8) | THIS ();
2190 NEXT ();
2191 value = (value << 8) | THIS ();
2192 NEXT ();
2193 *tos++ = value;
2194 break;
2195 case 0x82:
2196 NEXT ();
2197 value = THIS ();
2198 NEXT ();
2199 value = (value << 8) | THIS ();
2200 NEXT ();
2201 *tos++ = value;
2202 break;
2203 case 0x81:
2204 NEXT ();
2205 value = THIS ();
2206 NEXT ();
2207 *tos++ = value;
2208 break;
2209 case 0x80:
2210 NEXT ();
2211 *tos++ = 0;
2212 break;
2213 default:
2214 if (THIS () > 0x84)
2215 {
2216 /* Not a number, just bug out with the answer */
2217 write_int (*(--tos));
2218 return;
2219 }
2220 *tos++ = THIS ();
2221 NEXT ();
2222 value = 0;
2223 break;
2224 case 0xa5:
2225 /* PLUS anything */
2226 {
2227 int value = *(--tos);
2228 value += *(--tos);
2229 *tos++ = value;
2230 NEXT ();
2231 }
2232 break;
2233 case VAR ('R'):
2234 {
2235 int section_number;
2236 ieee_data_type *ieee;
2237 asection *s;
2238 NEXT ();
2239 section_number = THIS ();
2240
2241 NEXT ();
2242 ieee = IEEE_DATA (input_bfd);
2243 s = ieee->section_table[section_number];
2244 if (s->output_section)
2245 {
2246 value = s->output_section->vma;
2247 }
2248 else
2249 {
2250 value = 0;
2251 }
2252 value += s->output_offset;
2253 *tos++ = value;
2254 value = 0;
2255 }
2256 break;
2257 case 0x90:
2258 {
2259 NEXT ();
2260 write_int (*(--tos));
2261 OUT (0x90);
2262 return;
2263
2264 }
2265 }
2266 }
2267
2268 }
2269
2270 /* Drop the int in the buffer, and copy a null into the gap, which we
2271 will overwrite later */
2272
2273 struct output_buffer_struct
2274 {
2275 unsigned char *ptrp;
2276 int buffer;
2277 };
2278
2279 static void
2280 fill_int (buf)
2281 struct output_buffer_struct *buf;
2282 {
2283 if (buf->buffer == output_buffer)
2284 {
2285 /* Still a chance to output the size */
2286 int value = output_ptr - buf->ptrp + 3;
2287 buf->ptrp[0] = value >> 24;
2288 buf->ptrp[1] = value >> 16;
2289 buf->ptrp[2] = value >> 8;
2290 buf->ptrp[3] = value >> 0;
2291 }
2292 }
2293
2294 static void
2295 drop_int (buf)
2296 struct output_buffer_struct *buf;
2297 {
2298 int type = THIS ();
2299 int ch;
2300 if (type <= 0x84)
2301 {
2302 NEXT ();
2303 switch (type)
2304 {
2305 case 0x84:
2306 ch = THIS ();
2307 NEXT ();
2308 case 0x83:
2309 ch = THIS ();
2310 NEXT ();
2311 case 0x82:
2312 ch = THIS ();
2313 NEXT ();
2314 case 0x81:
2315 ch = THIS ();
2316 NEXT ();
2317 case 0x80:
2318 break;
2319 }
2320 }
2321 OUT (0x84);
2322 buf->ptrp = output_ptr;
2323 buf->buffer = output_buffer;
2324 OUT (0);
2325 OUT (0);
2326 OUT (0);
2327 OUT (0);
2328 }
2329
2330 static void
2331 copy_int ()
2332 {
2333 int type = THIS ();
2334 int ch;
2335 if (type <= 0x84)
2336 {
2337 OUT (type);
2338 NEXT ();
2339 switch (type)
2340 {
2341 case 0x84:
2342 ch = THIS ();
2343 NEXT ();
2344 OUT (ch);
2345 case 0x83:
2346 ch = THIS ();
2347 NEXT ();
2348 OUT (ch);
2349 case 0x82:
2350 ch = THIS ();
2351 NEXT ();
2352 OUT (ch);
2353 case 0x81:
2354 ch = THIS ();
2355 NEXT ();
2356 OUT (ch);
2357 case 0x80:
2358 break;
2359 }
2360 }
2361 }
2362
2363 #define ID copy_id()
2364 #define INT copy_int()
2365 #define EXP copy_expression()
2366 static void copy_till_end ();
2367 #define INTn(q) copy_int()
2368 #define EXPn(q) copy_expression()
2369
2370 static void
2371 f1_record ()
2372 {
2373 int ch;
2374 /* ATN record */
2375 NEXT ();
2376 ch = THIS ();
2377 switch (ch)
2378 {
2379 default:
2380 OUT (0xf1);
2381 OUT (ch);
2382 break;
2383 case 0xc9:
2384 NEXT ();
2385 OUT (0xf1);
2386 OUT (0xc9);
2387 INT;
2388 INT;
2389 ch = THIS ();
2390 switch (ch)
2391 {
2392 case 0x16:
2393 NEXT ();
2394 break;
2395 case 0x01:
2396 NEXT ();
2397 break;
2398 case 0x00:
2399 NEXT ();
2400 INT;
2401 break;
2402 case 0x03:
2403 NEXT ();
2404 INT;
2405 break;
2406 case 0x13:
2407 EXPn (instruction address);
2408 break;
2409 default:
2410 break;
2411 }
2412 break;
2413 case 0xd8:
2414 /* EXternal ref */
2415 NEXT ();
2416 OUT (0xf1);
2417 OUT (0xd8);
2418 EXP;
2419 EXP;
2420 EXP;
2421 EXP;
2422 break;
2423 case 0xce:
2424 NEXT ();
2425 OUT (0xf1);
2426 OUT (0xce);
2427 INT;
2428 INT;
2429 ch = THIS ();
2430 INT;
2431 switch (ch)
2432 {
2433 case 0x01:
2434 INT;
2435 INT;
2436 break;
2437 case 0x02:
2438 INT;
2439 break;
2440 case 0x04:
2441 EXPn (external function);
2442 break;
2443 case 0x05:
2444 break;
2445 case 0x07:
2446 INTn (line number);
2447 INT;
2448 case 0x08:
2449 break;
2450 case 0x0a:
2451 INTn (locked register);
2452 INT;
2453 break;
2454 case 0x3f:
2455 copy_till_end ();
2456 break;
2457 case 0x3e:
2458 copy_till_end ();
2459 break;
2460 case 0x40:
2461 copy_till_end ();
2462 break;
2463 case 0x41:
2464 ID;
2465 break;
2466 }
2467 }
2468
2469 }
2470
2471 static void
2472 f0_record ()
2473 {
2474 /* Attribute record */
2475 NEXT ();
2476 OUT (0xf0);
2477 INTn (Symbol name);
2478 ID;
2479 }
2480
2481 static void
2482 copy_till_end ()
2483 {
2484 int ch = THIS ();
2485 while (1)
2486 {
2487 while (ch <= 0x80)
2488 {
2489 OUT (ch);
2490 NEXT ();
2491 ch = THIS ();
2492 }
2493 switch (ch)
2494 {
2495 case 0x84:
2496 OUT (THIS ());
2497 NEXT ();
2498 case 0x83:
2499 OUT (THIS ());
2500 NEXT ();
2501 case 0x82:
2502 OUT (THIS ());
2503 NEXT ();
2504 case 0x81:
2505 OUT (THIS ());
2506 NEXT ();
2507 OUT (THIS ());
2508 NEXT ();
2509
2510 ch = THIS ();
2511 break;
2512 default:
2513 return;
2514 }
2515 }
2516
2517 }
2518
2519 static void
2520 f2_record ()
2521 {
2522 NEXT ();
2523 OUT (0xf2);
2524 INT;
2525 NEXT ();
2526 OUT (0xce);
2527 INT;
2528 copy_till_end ();
2529 }
2530
2531
2532 static void block ();
2533 static void
2534 f8_record ()
2535 {
2536 int ch;
2537 NEXT ();
2538 ch = THIS ();
2539 switch (ch)
2540 {
2541 case 0x01:
2542 case 0x02:
2543 case 0x03:
2544 /* Unique typedefs for module */
2545 /* GLobal typedefs */
2546 /* High level module scope beginning */
2547 {
2548 struct output_buffer_struct ob;
2549 NEXT ();
2550 OUT (0xf8);
2551 OUT (ch);
2552 drop_int (&ob);
2553 ID;
2554
2555 block ();
2556
2557 NEXT ();
2558 fill_int (&ob);
2559 OUT (0xf9);
2560 }
2561 break;
2562 case 0x04:
2563 /* Global function */
2564 {
2565 struct output_buffer_struct ob;
2566 NEXT ();
2567 OUT (0xf8);
2568 OUT (0x04);
2569 drop_int (&ob);
2570 ID;
2571 INTn (stack size);
2572 INTn (ret val);
2573 EXPn (offset);
2574
2575 block ();
2576
2577 NEXT ();
2578 OUT (0xf9);
2579 EXPn (size of block);
2580 fill_int (&ob);
2581 }
2582 break;
2583
2584 case 0x05:
2585 /* File name for source line numbers */
2586 {
2587 struct output_buffer_struct ob;
2588 NEXT ();
2589 OUT (0xf8);
2590 OUT (0x05);
2591 drop_int (&ob);
2592 ID;
2593 INTn (year);
2594 INTn (month);
2595 INTn (day);
2596 INTn (hour);
2597 INTn (monute);
2598 INTn (second);
2599 block ();
2600 NEXT ();
2601 OUT (0xf9);
2602 fill_int (&ob);
2603 }
2604 break;
2605
2606 case 0x06:
2607 /* Local function */
2608 {
2609 struct output_buffer_struct ob;
2610 NEXT ();
2611 OUT (0xf8);
2612 OUT (0x06);
2613 drop_int (&ob);
2614 ID;
2615 INTn (stack size);
2616 INTn (type return);
2617 EXPn (offset);
2618 block ();
2619 NEXT ();
2620 OUT (0xf9);
2621 EXPn (size);
2622 fill_int (&ob);
2623 }
2624 break;
2625
2626 case 0x0a:
2627 /* Assembler module scope beginning -*/
2628 {
2629 struct output_buffer_struct ob;
2630
2631 NEXT ();
2632 OUT (0xf8);
2633 OUT (0x0a);
2634 drop_int (&ob);
2635 ID;
2636 ID;
2637 INT;
2638 ID;
2639 INT;
2640 INT;
2641 INT;
2642 INT;
2643 INT;
2644 INT;
2645
2646 block ();
2647
2648 NEXT ();
2649 OUT (0xf9);
2650 fill_int (&ob);
2651 }
2652 break;
2653 case 0x0b:
2654 {
2655 struct output_buffer_struct ob;
2656 NEXT ();
2657 OUT (0xf8);
2658 OUT (0x0b);
2659 drop_int (&ob);
2660 ID;
2661 INT;
2662 INTn (section index);
2663 EXPn (offset);
2664 INTn (stuff);
2665
2666 block ();
2667
2668 OUT (0xf9);
2669 NEXT ();
2670 EXPn (Size in Maus);
2671 fill_int (&ob);
2672 }
2673 break;
2674 }
2675 }
2676
2677 static void
2678 e2_record ()
2679 {
2680 OUT (0xe2);
2681 NEXT ();
2682 OUT (0xce);
2683 NEXT ();
2684 INT;
2685 EXP;
2686 }
2687
2688 static void
2689 block ()
2690 {
2691 int ch;
2692 while (1)
2693 {
2694 ch = THIS ();
2695 switch (ch)
2696 {
2697 case 0xe1:
2698 case 0xe5:
2699 return;
2700 case 0xf9:
2701 return;
2702 case 0xf0:
2703 f0_record ();
2704 break;
2705 case 0xf1:
2706 f1_record ();
2707 break;
2708 case 0xf2:
2709 f2_record ();
2710 break;
2711 case 0xf8:
2712 f8_record ();
2713 break;
2714 case 0xe2:
2715 e2_record ();
2716 break;
2717
2718 }
2719 }
2720 }
2721
2722
2723
2724 /* relocate_debug,
2725 moves all the debug information from the source bfd to the output
2726 bfd, and relocates any expressions it finds
2727 */
2728
2729 static void
2730 relocate_debug (output, input)
2731 bfd *output;
2732 bfd *input;
2733 {
2734 #define IBS 400
2735 #define OBS 400
2736 unsigned char input_buffer[IBS];
2737
2738 input_ptr_start = input_ptr = input_buffer;
2739 input_ptr_end = input_buffer + IBS;
2740 input_bfd = input;
2741 /* FIXME: Check return value. I'm not sure whether it needs to read
2742 the entire buffer or not. */
2743 bfd_read ((PTR) input_ptr_start, 1, IBS, input);
2744 block ();
2745 }
2746
2747 /*
2748 During linking, we we told about the bfds which made up our
2749 contents, we have a list of them. They will still be open, so go to
2750 the debug info in each, and copy it out, relocating it as we go.
2751 */
2752
2753 static void
2754 ieee_write_debug_part (abfd)
2755 bfd *abfd;
2756 {
2757 ieee_data_type *ieee = IEEE_DATA (abfd);
2758 bfd_chain_type *chain = ieee->chain_root;
2759 unsigned char output_buffer[OBS];
2760 boolean some_debug = false;
2761 file_ptr here = bfd_tell (abfd);
2762
2763 output_ptr_start = output_ptr = output_buffer;
2764 output_ptr_end = output_buffer + OBS;
2765 output_ptr = output_buffer;
2766 output_bfd = abfd;
2767
2768 if (chain == (bfd_chain_type *) NULL)
2769 {
2770 #if 0
2771 /* There is no debug info, so we'll fake some up */
2772 CONST static char fake[] =
2773 {
2774 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
2775 '1', '.', '1', 0x82, 1991 >> 8, 1991 & 0xff, 9, 20, 11, 07, 50};
2776 ieee->w.r.debug_information_part = 0;
2777
2778
2779 here;
2780
2781
2782 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2783 /* Now write a header for each section */
2784 {
2785 int i = 0;
2786 asection *s = abfd->sections;
2787 while (s)
2788 {
2789 if (s != abfd->abs_section)
2790 {
2791
2792 ieee_write_byte (abfd, 0xf8);
2793 ieee_write_byte (abfd, 0x0b);
2794 ieee_write_byte (abfd, 0);
2795 ieee_write_byte (abfd, 0);
2796 ieee_write_byte (abfd, 1);
2797 ieee_write_byte (abfd, i + IEEE_SECTION_NUMBER_BASE);
2798 ieee_write_expression (abfd, 0, s->symbol, 0, 0, 0);
2799 ieee_write_byte (abfd, 0);
2800 ieee_write_byte (abfd, 0xf9);
2801 ieee_write_expression (abfd, s->size,
2802 bfd_abs_section_ptr->symbol, 0, 0, 0);
2803 i++;
2804 }
2805
2806 s = s->next;
2807
2808 }
2809 /* Close the scope */
2810 ieee_write_byte (abfd, 0xf9);
2811 }
2812 #endif
2813 }
2814 else
2815 {
2816 while (chain != (bfd_chain_type *) NULL)
2817 {
2818 bfd *entry = chain->this;
2819 ieee_data_type *entry_ieee = IEEE_DATA (entry);
2820 if (entry_ieee->w.r.debug_information_part)
2821 {
2822 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
2823 SEEK_SET)
2824 != 0)
2825 abort ();
2826 relocate_debug (abfd, entry);
2827 }
2828
2829 chain = chain->next;
2830 }
2831 if (some_debug)
2832 {
2833 ieee->w.r.debug_information_part = here;
2834 }
2835 else
2836 {
2837 ieee->w.r.debug_information_part = 0;
2838 }
2839 }
2840 flush ();
2841
2842 }
2843
2844 /* write the data in an ieee way */
2845 static void
2846 ieee_write_data_part (abfd)
2847 bfd *abfd;
2848 {
2849 asection *s;
2850 ieee_data_type *ieee = IEEE_DATA (abfd);
2851 ieee->w.r.data_part = bfd_tell (abfd);
2852 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2853 {
2854 /* Sort the reloc records so we can insert them in the correct
2855 places */
2856 if (s->reloc_count != 0)
2857 {
2858 do_with_relocs (abfd, s);
2859 }
2860 else
2861 {
2862 do_without_relocs (abfd, s);
2863 }
2864 }
2865 }
2866
2867
2868 static boolean
2869 init_for_output (abfd)
2870 bfd *abfd;
2871 {
2872 asection *s;
2873 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2874 {
2875 if (s->_raw_size != 0)
2876 {
2877 ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, s->_raw_size));
2878 if (!ieee_per_section (s)->data)
2879 return false;
2880 }
2881 }
2882 return true;
2883 }
2884 \f
2885 /** exec and core file sections */
2886
2887 /* set section contents is complicated with IEEE since the format is
2888 * not a byte image, but a record stream.
2889 */
2890 boolean
2891 ieee_set_section_contents (abfd, section, location, offset, count)
2892 bfd *abfd;
2893 sec_ptr section;
2894 PTR location;
2895 file_ptr offset;
2896 bfd_size_type count;
2897 {
2898 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
2899 {
2900 if (!init_for_output (abfd))
2901 return false;
2902 }
2903 memcpy ((PTR) (ieee_per_section (section)->data + offset),
2904 (PTR) location,
2905 (unsigned int) count);
2906 return true;
2907 }
2908
2909 /*
2910 write the external symbols of a file, IEEE considers two sorts of
2911 external symbols, public, and referenced. It uses to internal forms
2912 to index them as well. When we write them out we turn their symbol
2913 values into indexes from the right base.
2914 */
2915 static void
2916 ieee_write_external_part (abfd)
2917 bfd *abfd;
2918 {
2919 asymbol **q;
2920 ieee_data_type *ieee = IEEE_DATA (abfd);
2921
2922 unsigned int reference_index = IEEE_REFERENCE_BASE;
2923 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
2924 file_ptr here = bfd_tell (abfd);
2925 boolean hadone = false;
2926 if (abfd->outsymbols != (asymbol **) NULL)
2927 {
2928
2929 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
2930 {
2931 asymbol *p = *q;
2932 hadone = true;
2933 if (bfd_is_und_section (p->section))
2934 {
2935 /* This must be a symbol reference .. */
2936 ieee_write_byte (abfd, ieee_external_reference_enum);
2937 ieee_write_int (abfd, reference_index);
2938 ieee_write_id (abfd, p->name);
2939 p->value = reference_index;
2940 reference_index++;
2941 }
2942 else if (bfd_is_com_section (p->section))
2943 {
2944 /* This is a weak reference */
2945 ieee_write_byte (abfd, ieee_external_reference_enum);
2946 ieee_write_int (abfd, reference_index);
2947 ieee_write_id (abfd, p->name);
2948 ieee_write_byte (abfd, ieee_weak_external_reference_enum);
2949 ieee_write_int (abfd, reference_index);
2950 ieee_write_int (abfd, p->value);
2951 ieee_write_int (abfd, BFD_FORT_COMM_DEFAULT_VALUE);
2952 p->value = reference_index;
2953 reference_index++;
2954 }
2955 else if (p->flags & BSF_GLOBAL)
2956 {
2957 /* This must be a symbol definition */
2958
2959
2960 ieee_write_byte (abfd, ieee_external_symbol_enum);
2961 ieee_write_int (abfd, public_index);
2962 ieee_write_id (abfd, p->name);
2963
2964 ieee_write_twobyte (abfd, ieee_attribute_record_enum);
2965 ieee_write_int (abfd, public_index);
2966 ieee_write_byte (abfd, 15); /* instruction address */
2967 ieee_write_byte (abfd, 19); /* static symbol */
2968 ieee_write_byte (abfd, 1); /* one of them */
2969
2970
2971 /* Write out the value */
2972 ieee_write_2bytes (abfd, ieee_value_record_enum);
2973 ieee_write_int (abfd, public_index);
2974 if (! bfd_is_abs_section (p->section))
2975 {
2976 if (abfd->flags & EXEC_P)
2977 {
2978 /* If fully linked, then output all symbols
2979 relocated */
2980 ieee_write_int (abfd,
2981 p->value + p->section->output_offset + p->section->output_section->vma);
2982
2983 }
2984 else
2985 {
2986 ieee_write_expression (abfd,
2987 p->value + p->section->output_offset,
2988 p->section->output_section->symbol
2989 ,false, 0);
2990 }
2991 }
2992 else
2993 {
2994 ieee_write_expression (abfd,
2995 p->value,
2996 bfd_abs_section_ptr->symbol,
2997 false, 0);
2998 }
2999 p->value = public_index;
3000 public_index++;
3001 }
3002 else
3003 {
3004 /* This can happen - when there are gaps in the symbols read */
3005 /* from an input ieee file */
3006 }
3007 }
3008 }
3009 if (hadone)
3010 ieee->w.r.external_part = here;
3011
3012 }
3013
3014
3015 static CONST unsigned char exten[] =
3016 {
3017 0xf0, 0x20, 0x00,
3018 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3 */
3019 0xf1, 0xce, 0x20, 0x00, 39, 2,/* keep symbol in original case */
3020 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
3021 };
3022
3023 static CONST unsigned char envi[] =
3024 {
3025 0xf0, 0x21, 0x00,
3026
3027 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3028 0x19, 0x2c,
3029 */
3030 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3031
3032 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3033 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3034 };
3035
3036 static
3037 void
3038 ieee_write_me_part (abfd)
3039 bfd *abfd;
3040 {
3041 ieee_data_type *ieee = IEEE_DATA (abfd);
3042 ieee->w.r.trailer_part = bfd_tell (abfd);
3043 if (abfd->start_address)
3044 {
3045 ieee->w.r.me_record = bfd_tell (abfd);
3046 ieee_write_2bytes (abfd, ieee_value_starting_address_enum);
3047 ieee_write_byte (abfd, ieee_function_either_open_b_enum);
3048 ieee_write_int (abfd, abfd->start_address);
3049 ieee_write_byte (abfd, ieee_function_either_close_b_enum);
3050 }
3051 else
3052 {
3053 ieee->w.r.me_record = bfd_tell (abfd);
3054 }
3055 ieee_write_byte (abfd, ieee_module_end_enum);
3056
3057 }
3058
3059 boolean
3060 ieee_write_object_contents (abfd)
3061 bfd *abfd;
3062 {
3063 ieee_data_type *ieee = IEEE_DATA (abfd);
3064 unsigned int i;
3065 file_ptr old;
3066 /* Fast forward over the header area */
3067 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3068 return false;
3069 ieee_write_byte (abfd, ieee_module_beginning_enum);
3070
3071 ieee_write_id (abfd, bfd_printable_name (abfd));
3072 ieee_write_id (abfd, abfd->filename);
3073
3074 /* Fast forward over the variable bits */
3075 ieee_write_byte (abfd, ieee_address_descriptor_enum);
3076
3077 /* Bits per MAU */
3078 ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd)));
3079 /* MAU's per address */
3080 ieee_write_byte (abfd,
3081 (bfd_byte) (bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd)));
3082
3083 old = bfd_tell (abfd);
3084 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3085 return false;
3086
3087 ieee->w.r.extension_record = bfd_tell (abfd);
3088 if (bfd_write ((char *) exten, 1, sizeof (exten), abfd) != sizeof (exten))
3089 return false;
3090 if (abfd->flags & EXEC_P)
3091 ieee_write_byte (abfd, 0x1);/* Absolute */
3092 else
3093 ieee_write_byte (abfd, 0x2);/* Relocateable */
3094
3095 ieee->w.r.environmental_record = bfd_tell (abfd);
3096 if (bfd_write ((char *) envi, 1, sizeof (envi), abfd) != sizeof (envi))
3097 return false;
3098 output_bfd = abfd;
3099 flush ();
3100
3101 ieee_write_section_part (abfd);
3102 /*
3103 First write the symbols, this changes their values into table
3104 indeces so we cant use it after this point
3105 */
3106 ieee_write_external_part (abfd);
3107 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3108
3109
3110 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
3111
3112
3113 /*
3114 Write any debugs we have been told about
3115 */
3116 ieee_write_debug_part (abfd);
3117
3118 /*
3119 Can only write the data once the symbols have been written since
3120 the data contains relocation information which points to the
3121 symbols
3122 */
3123 ieee_write_data_part (abfd);
3124
3125
3126 /*
3127 At the end we put the end !
3128 */
3129 ieee_write_me_part (abfd);
3130
3131
3132 /* Generate the header */
3133 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3134 return false;
3135
3136 for (i = 0; i < N_W_VARIABLES; i++)
3137 {
3138 ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum);
3139 ieee_write_byte (abfd, (bfd_byte) i);
3140 ieee_write_int5_out (abfd, ieee->w.offset[i]);
3141 }
3142 return true;
3143 }
3144 \f
3145
3146
3147 /* Native-level interface to symbols. */
3148
3149 /* We read the symbols into a buffer, which is discarded when this
3150 function exits. We read the strings into a buffer large enough to
3151 hold them all plus all the cached symbol entries. */
3152
3153 asymbol *
3154 ieee_make_empty_symbol (abfd)
3155 bfd *abfd;
3156 {
3157
3158 ieee_symbol_type *new =
3159 (ieee_symbol_type *) bfd_zmalloc (sizeof (ieee_symbol_type));
3160 if (!new)
3161 return NULL;
3162 new->symbol.the_bfd = abfd;
3163 return &new->symbol;
3164 }
3165
3166 static bfd *
3167 ieee_openr_next_archived_file (arch, prev)
3168 bfd *arch;
3169 bfd *prev;
3170 {
3171 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3172 /* take the next one from the arch state, or reset */
3173 if (prev == (bfd *) NULL)
3174 {
3175 /* Reset the index - the first two entries are bogus*/
3176 ar->element_index = 2;
3177 }
3178 while (true)
3179 {
3180 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3181 ar->element_index++;
3182 if (ar->element_index <= ar->element_count)
3183 {
3184 if (p->file_offset != (file_ptr) 0)
3185 {
3186 if (p->abfd == (bfd *) NULL)
3187 {
3188 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3189 p->abfd->origin = p->file_offset;
3190 }
3191 return p->abfd;
3192 }
3193 }
3194 else
3195 {
3196 bfd_set_error (bfd_error_no_more_archived_files);
3197 return (bfd *) NULL;
3198 }
3199
3200 }
3201 }
3202
3203 static boolean
3204 ieee_find_nearest_line (abfd,
3205 section,
3206 symbols,
3207 offset,
3208 filename_ptr,
3209 functionname_ptr,
3210 line_ptr)
3211 bfd *abfd;
3212 asection *section;
3213 asymbol **symbols;
3214 bfd_vma offset;
3215 char **filename_ptr;
3216 char **functionname_ptr;
3217 int *line_ptr;
3218 {
3219 return false;
3220 }
3221
3222 static int
3223 ieee_generic_stat_arch_elt (abfd, buf)
3224 bfd *abfd;
3225 struct stat *buf;
3226 {
3227 ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
3228 if (ar == (ieee_ar_data_type *) NULL)
3229 {
3230 bfd_set_error (bfd_error_invalid_operation);
3231 return -1;
3232 }
3233 else
3234 {
3235 buf->st_size = 0x1;
3236 buf->st_mode = 0666;
3237 return !ieee_object_p (abfd);
3238 }
3239 }
3240
3241 static int
3242 ieee_sizeof_headers (abfd, x)
3243 bfd *abfd;
3244 boolean x;
3245 {
3246 return 0;
3247 }
3248
3249
3250 /* The debug info routines are never used. */
3251 #if 0
3252
3253 static void
3254 ieee_bfd_debug_info_start (abfd)
3255 bfd *abfd;
3256 {
3257
3258 }
3259
3260 static void
3261 ieee_bfd_debug_info_end (abfd)
3262 bfd *abfd;
3263 {
3264
3265 }
3266
3267
3268 /* Add this section to the list of sections we have debug info for, to
3269 be ready to output it at close time
3270 */
3271 static void
3272 ieee_bfd_debug_info_accumulate (abfd, section)
3273 bfd *abfd;
3274 asection *section;
3275 {
3276 ieee_data_type *ieee = IEEE_DATA (section->owner);
3277 ieee_data_type *output_ieee = IEEE_DATA (abfd);
3278 /* can only accumulate data from other ieee bfds */
3279 if (section->owner->xvec != abfd->xvec)
3280 return;
3281 /* Only bother once per bfd */
3282 if (ieee->done_debug == true)
3283 return;
3284 ieee->done_debug = true;
3285
3286 /* Don't bother if there is no debug info */
3287 if (ieee->w.r.debug_information_part == 0)
3288 return;
3289
3290
3291 /* Add to chain */
3292 {
3293 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc (abfd, sizeof (bfd_chain_type));
3294 if (!n)
3295 abort (); /* FIXME */
3296 n->this = section->owner;
3297 n->next = (bfd_chain_type *) NULL;
3298
3299 if (output_ieee->chain_head)
3300 {
3301 output_ieee->chain_head->next = n;
3302 }
3303 else
3304 {
3305 output_ieee->chain_root = n;
3306
3307 }
3308 output_ieee->chain_head = n;
3309 }
3310 }
3311
3312 #endif
3313
3314 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3315 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3316
3317 #define ieee_slurp_armap bfd_true
3318 #define ieee_slurp_extended_name_table bfd_true
3319 #define ieee_construct_extended_name_table \
3320 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
3321 bfd_true)
3322 #define ieee_truncate_arname bfd_dont_truncate_arname
3323 #define ieee_write_armap \
3324 ((boolean (*) \
3325 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3326 bfd_true)
3327 #define ieee_read_ar_hdr bfd_nullvoidptr
3328 #define ieee_update_armap_timestamp bfd_true
3329
3330 #define ieee_bfd_is_local_label bfd_generic_is_local_label
3331 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3332 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3333 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3334 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3335
3336 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3337
3338 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3339
3340 #define ieee_get_section_contents_in_window \
3341 _bfd_generic_get_section_contents_in_window
3342 #define ieee_bfd_get_relocated_section_contents \
3343 bfd_generic_get_relocated_section_contents
3344 #define ieee_bfd_relax_section bfd_generic_relax_section
3345 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3346 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3347 #define ieee_bfd_final_link _bfd_generic_final_link
3348 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3349
3350 /*SUPPRESS 460 */
3351 const bfd_target ieee_vec =
3352 {
3353 "ieee", /* name */
3354 bfd_target_ieee_flavour,
3355 true, /* target byte order */
3356 true, /* target headers byte order */
3357 (HAS_RELOC | EXEC_P | /* object flags */
3358 HAS_LINENO | HAS_DEBUG |
3359 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3360 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3361 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3362 0, /* leading underscore */
3363 ' ', /* ar_pad_char */
3364 16, /* ar_max_namelen */
3365 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3366 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3367 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3368 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3369 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3370 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3371
3372 {_bfd_dummy_target,
3373 ieee_object_p, /* bfd_check_format */
3374 ieee_archive_p,
3375 _bfd_dummy_target,
3376 },
3377 {
3378 bfd_false,
3379 ieee_mkobject,
3380 _bfd_generic_mkarchive,
3381 bfd_false
3382 },
3383 {
3384 bfd_false,
3385 ieee_write_object_contents,
3386 _bfd_write_archive_contents,
3387 bfd_false,
3388 },
3389
3390 BFD_JUMP_TABLE_GENERIC (ieee),
3391 BFD_JUMP_TABLE_COPY (_bfd_generic),
3392 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3393 BFD_JUMP_TABLE_ARCHIVE (ieee),
3394 BFD_JUMP_TABLE_SYMBOLS (ieee),
3395 BFD_JUMP_TABLE_RELOCS (ieee),
3396 BFD_JUMP_TABLE_WRITE (ieee),
3397 BFD_JUMP_TABLE_LINK (ieee),
3398 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
3399
3400 (PTR) 0
3401 };