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