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