Convert i960 COFF to use COFF backend linker.
[deliverable/binutils-gdb.git] / bfd / ieee.c
CommitLineData
aff6e0b4 1/* BFD back-end for ieee-695 objects.
9783e04a 2 Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
b2c91bd9 3 Written by Steve Chamberlain of Cygnus Support.
d0ec7a8e 4
b2c91bd9 5This file is part of BFD, the Binary File Descriptor library.
87f86b4e 6
b2c91bd9 7This program is free software; you can redistribute it and/or modify
9b4641a6 8it under the terms of the GNU General Public License as published by
b2c91bd9
SC
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
87f86b4e 11
b2c91bd9 12This program is distributed in the hope that it will be useful,
9b4641a6
JG
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
87f86b4e 16
9b4641a6 17You should have received a copy of the GNU General Public License
b2c91bd9 18along with this program; if not, write to the Free Software
c3246d9b 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
87f86b4e 20
aff6e0b4 21#define KEEPMINUSPCININST 0
9465d03e 22
b2c91bd9
SC
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. */
d0ec7a8e 26
87f86b4e 27#include "bfd.h"
01dd1b2b 28#include "sysdep.h"
87f86b4e 29#include "libbfd.h"
87f86b4e
DHW
30#include "ieee.h"
31#include "libieee.h"
9465d03e 32#include "obstack.h"
9783e04a 33#define obstack_chunk_alloc malloc
9465d03e
SC
34#define obstack_chunk_free free
35
ce3f6d51
JG
36/* Functions for writing to ieee files in the strange way that the
37 standard requires. */
87f86b4e
DHW
38
39static void
57a1867e
DM
40ieee_write_byte (abfd, byte)
41 bfd *abfd;
42 bfd_byte byte;
87f86b4e 43{
4002f18a
ILT
44 if (bfd_write ((PTR) & byte, 1, 1, abfd) != 1)
45 abort ();
87f86b4e
DHW
46}
47
b2c91bd9 48static void
57a1867e
DM
49ieee_write_twobyte (abfd, twobyte)
50 bfd *abfd;
51 int twobyte;
b2c91bd9
SC
52{
53 bfd_byte b[2];
54 b[1] = twobyte & 0xff;
55 b[0] = twobyte >> 8;
4002f18a
ILT
56 if (bfd_write ((PTR) & b[0], 1, 2, abfd) != 2)
57 abort ();
b2c91bd9
SC
58}
59
87f86b4e 60static void
57a1867e
DM
61ieee_write_2bytes (abfd, bytes)
62 bfd *abfd;
63 int bytes;
87f86b4e
DHW
64{
65 bfd_byte buffer[2];
66 buffer[0] = bytes >> 8;
67 buffer[1] = bytes & 0xff;
68
4002f18a
ILT
69 if (bfd_write ((PTR) buffer, 1, 2, abfd) != 2)
70 abort ();
87f86b4e
DHW
71}
72
73static void
57a1867e
DM
74ieee_write_int (abfd, value)
75 bfd *abfd;
76 bfd_vma value;
87f86b4e 77{
9783e04a
DM
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 }
87f86b4e 115 }
87f86b4e
DHW
116}
117
118static void
57a1867e
DM
119ieee_write_id (abfd, id)
120 bfd *abfd;
121 CONST char *id;
87f86b4e 122{
9783e04a
DM
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 }
4002f18a
ILT
143 if (bfd_write ((PTR) id, 1, length, abfd) != length)
144 abort ();
87f86b4e 145}
9783e04a
DM
146\f
147
87f86b4e
DHW
148/***************************************************************************
149Functions for reading from ieee files in the strange way that the
150standard requires:
151*/
87f86b4e 152
6f715d66
SC
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++))
87f86b4e 156
9783e04a 157static unsigned short
57a1867e
DM
158read_2bytes (ieee)
159 common_header_type *ieee;
87f86b4e 160{
9783e04a
DM
161 unsigned char c1 = this_byte_and_next (ieee);
162 unsigned char c2 = this_byte_and_next (ieee);
163 return (c1 << 8) | c2;
87f86b4e
DHW
164}
165
166static void
57a1867e
DM
167bfd_get_string (ieee, string, length)
168 common_header_type *ieee;
169 char *string;
170 size_t length;
87f86b4e
DHW
171{
172 size_t i;
9783e04a
DM
173 for (i = 0; i < length; i++)
174 {
175 string[i] = this_byte_and_next (ieee);
176 }
87f86b4e
DHW
177}
178
301dfc71 179static char *
57a1867e
DM
180read_id (ieee)
181 common_header_type *ieee;
87f86b4e
DHW
182{
183 size_t length;
184 char *string;
9783e04a
DM
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 }
87f86b4e 201 /* Buy memory and read string */
9783e04a
DM
202 string = bfd_alloc (ieee->abfd, length + 1);
203 if (!string)
204 {
57a1867e 205 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
206 return NULL;
207 }
208 bfd_get_string (ieee, string, length);
87f86b4e
DHW
209 string[length] = 0;
210 return string;
211}
212
213static void
57a1867e
DM
214ieee_write_expression (abfd, value, symbol, pcrel, index)
215 bfd *abfd;
216 bfd_vma value;
217 asymbol *symbol;
218 boolean pcrel;
219 unsigned int index;
87f86b4e 220{
69e0d34d 221 unsigned int term_count = 0;
b2c91bd9 222
9783e04a
DM
223 if (value != 0)
224 {
225 ieee_write_int (abfd, value);
226 term_count++;
227 }
87f86b4e 228
8feff717 229 if (bfd_is_com_section (symbol->section)
c3246d9b 230 || bfd_is_und_section (symbol->section))
9783e04a
DM
231 {
232 /* Def of a common symbol */
233 ieee_write_byte (abfd, ieee_variable_X_enum);
234 ieee_write_int (abfd, symbol->value);
69e0d34d 235 term_count++;
87f86b4e 236 }
c3246d9b 237 else if (! bfd_is_abs_section (symbol->section))
69e0d34d 238 {
9783e04a 239 /* Ref to defined symbol - */
301dfc71 240
9783e04a
DM
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 }
87f86b4e 265 }
87f86b4e 266
9783e04a
DM
267 if (pcrel)
268 {
69e0d34d 269 /* subtract the pc from here by asking for PC of this section*/
9783e04a
DM
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);
69e0d34d
SC
273 }
274
9783e04a
DM
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);
69e0d34d
SC
284 term_count--;
285 }
b2c91bd9 286 }
87f86b4e 287}
9783e04a 288\f
87f86b4e 289
87f86b4e
DHW
290/*****************************************************************************/
291
292/*
293writes any integer into the buffer supplied and always takes 5 bytes
294*/
295static void
57a1867e
DM
296ieee_write_int5 (buffer, value)
297 bfd_byte *buffer;
298 bfd_vma value;
87f86b4e 299{
9783e04a
DM
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;
301dfc71 305}
9783e04a 306
301dfc71 307static void
57a1867e
DM
308ieee_write_int5_out (abfd, value)
309 bfd *abfd;
310 bfd_vma value;
301dfc71 311{
d0ec7a8e 312 bfd_byte b[5];
9783e04a 313 ieee_write_int5 (b, value);
4002f18a
ILT
314 if (bfd_write ((PTR) b, 1, 5, abfd) != 5)
315 abort ();
87f86b4e 316}
87f86b4e 317
9783e04a 318static boolean
57a1867e
DM
319parse_int (ieee, value_ptr)
320 common_header_type *ieee;
321 bfd_vma *value_ptr;
87f86b4e 322{
9783e04a 323 int value = this_byte (ieee);
87f86b4e 324 int result;
9783e04a
DM
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 }
87f86b4e
DHW
344 return false;
345}
9783e04a 346
301dfc71 347static int
57a1867e
DM
348parse_i (ieee, ok)
349 common_header_type *ieee;
350 boolean *ok;
87f86b4e
DHW
351{
352 bfd_vma x;
9783e04a 353 *ok = parse_int (ieee, &x);
87f86b4e
DHW
354 return x;
355}
356
9783e04a 357static bfd_vma
57a1867e
DM
358must_parse_int (ieee)
359 common_header_type *ieee;
87f86b4e
DHW
360{
361 bfd_vma result;
9783e04a 362 BFD_ASSERT (parse_int (ieee, &result) == true);
87f86b4e
DHW
363 return result;
364}
365
9783e04a 366typedef struct
87f86b4e
DHW
367{
368 bfd_vma value;
369 asection *section;
370 ieee_symbol_index_type symbol;
371} ieee_value_type;
372
373
87f86b4e 374static
9783e04a
DM
375reloc_howto_type abs32_howto
376= HOWTO (1, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false);
377static
378reloc_howto_type abs16_howto
379= HOWTO (1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false);
b2c91bd9
SC
380
381static
9783e04a
DM
382reloc_howto_type abs8_howto
383= HOWTO (1, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false);
d0ec7a8e 384
9783e04a
DM
385static
386reloc_howto_type rel32_howto
387= HOWTO (1, 0, 2, 32, true, 0, complain_overflow_signed, 0, "rel32", true, 0xffffffff,
388 0xffffffff, false);
9465d03e 389
d0ec7a8e 390static
9783e04a
DM
391reloc_howto_type rel16_howto
392= HOWTO (1, 0, 1, 16, true, 0, complain_overflow_signed, 0, "rel16", true, 0x0000ffff, 0x0000ffff, false);
b2c91bd9
SC
393
394static
9783e04a
DM
395reloc_howto_type rel8_howto
396= HOWTO (1, 0, 0, 8, true, 0, complain_overflow_signed, 0, "rel8", true, 0x000000ff, 0x000000ff, false);
b2c91bd9 397
87f86b4e 398
9783e04a
DM
399static ieee_symbol_index_type NOSYMBOL =
400{0, 0};
87f86b4e
DHW
401
402
301dfc71 403static void
57a1867e
DM
404parse_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;
d0ec7a8e 411
87f86b4e
DHW
412{
413#define POS sp[1]
414#define TOS sp[0]
415#define NOS sp[-1]
416#define INC sp++;
417#define DEC sp--;
69e0d34d 418
87f86b4e
DHW
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
9783e04a
DM
427 while (loop)
428 {
429 switch (this_byte (&(ieee->h)))
87f86b4e 430 {
d0ec7a8e
SC
431 case ieee_variable_P_enum:
432 /* P variable, current program counter for section n */
9783e04a
DM
433 {
434 int section_n;
435 next_byte (&(ieee->h));
436 *pcrel = true;
437 section_n = must_parse_int (&(ieee->h));
c3246d9b 438 PUSH (NOSYMBOL, bfd_abs_section_ptr,
9783e04a
DM
439 TOS.value = ieee->section_table[section_n]->vma +
440 ieee_per_section (ieee->section_table[section_n])->pc);
441 break;
442 }
d0ec7a8e
SC
443 case ieee_variable_L_enum:
444 /* L variable address of section N */
9783e04a
DM
445 next_byte (&(ieee->h));
446 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
d0ec7a8e
SC
447 break;
448 case ieee_variable_R_enum:
449 /* R variable, logical address of section module */
450 /* FIXME, this should be different to L */
9783e04a
DM
451 next_byte (&(ieee->h));
452 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
d0ec7a8e
SC
453 break;
454 case ieee_variable_S_enum:
455 /* S variable, size in MAUS of section module */
9783e04a
DM
456 next_byte (&(ieee->h));
457 PUSH (NOSYMBOL,
458 0,
459 ieee->section_table[must_parse_int (&(ieee->h))]->_raw_size);
87f86b4e 460 break;
9783e04a 461 case ieee_variable_I_enum:
d0ec7a8e
SC
462 case ieee_variable_X_enum:
463 /* Push the address of external variable n */
9783e04a
DM
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';
87f86b4e 469
c3246d9b 470 PUSH (sy, bfd_und_section_ptr, 0);
9783e04a 471 }
d0ec7a8e
SC
472 break;
473 case ieee_function_minus_enum:
9783e04a
DM
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 }
d0ec7a8e
SC
484 break;
485 case ieee_function_plus_enum:
9783e04a
DM
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);
c3246d9b
ILT
496 PUSH (sy1.letter ? sy1 : sy2,
497 bfd_is_abs_section (section1) ? section2 : section1,
498 value1 + value2);
9783e04a 499 }
d0ec7a8e 500 break;
9783e04a
DM
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 {
c3246d9b 508 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
9783e04a
DM
509 }
510 else
511 {
512 /*
d0ec7a8e
SC
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
9783e04a 515 using to scan, whereby the comma operator is omitted
d0ec7a8e
SC
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
9783e04a
DM
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;
d0ec7a8e 529
9783e04a
DM
530 POP (*symbol, dummy, *value);
531 if (section)
532 *section = dummy;
d0ec7a8e 533 }
9465d03e 534
d0ec7a8e
SC
535 loop = false;
536 }
9783e04a 537 }
d0ec7a8e 538 }
9783e04a 539 }
87f86b4e
DHW
540}
541
301dfc71 542
301dfc71 543#define ieee_seek(abfd, offset) \
e98e6ec1 544 IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset
6f715d66 545
ae115e51
ILT
546#define ieee_pos(abfd) \
547 (IEEE_DATA(abfd)->h.input_p - IEEE_DATA(abfd)->h.first_byte)
87f86b4e 548
b2c91bd9 549static unsigned int last_index;
9783e04a
DM
550static char last_type; /* is the index for an X or a D */
551
b2c91bd9 552static ieee_symbol_type *
57a1867e
DM
553get_symbol (abfd,
554 ieee,
555 last_symbol,
556 symbol_count,
557 pptr,
558 max_index,
559 this_type
9783e04a 560)
57a1867e
DM
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 ;
b2c91bd9
SC
569{
570 /* Need a new symbol */
9783e04a
DM
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 {
57a1867e 578 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
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 }
b2c91bd9
SC
594 return last_symbol;
595}
9783e04a 596
326e32d7 597static boolean
57a1867e
DM
598ieee_slurp_external_symbols (abfd)
599 bfd *abfd;
87f86b4e 600{
9783e04a 601 ieee_data_type *ieee = IEEE_DATA (abfd);
87f86b4e
DHW
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;
9783e04a 606 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
87f86b4e
DHW
607 unsigned int symbol_count = 0;
608 boolean loop = true;
b2c91bd9 609 last_index = 0xffffff;
87f86b4e
DHW
610 ieee->symbol_table_full = true;
611
9783e04a 612 ieee_seek (abfd, offset);
87f86b4e 613
9783e04a
DM
614 while (loop)
615 {
616 switch (this_byte (&(ieee->h)))
617 {
618 case ieee_nn_record:
619 next_byte (&(ieee->h));
aff6e0b4 620
9783e04a
DM
621 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
622 &prev_symbols_ptr,
623 &ieee->external_symbol_max_index, 'D');
326e32d7
ILT
624 if (symbol == NULL)
625 return false;
b2c91bd9 626
9783e04a
DM
627 symbol->symbol.the_bfd = abfd;
628 symbol->symbol.name = read_id (&(ieee->h));
c3246d9b 629 symbol->symbol.udata.p = (PTR) NULL;
9783e04a
DM
630 symbol->symbol.flags = BSF_NO_FLAGS;
631 break;
632 case ieee_external_symbol_enum:
633 next_byte (&(ieee->h));
b2c91bd9 634
9783e04a
DM
635 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
636 &prev_symbols_ptr,
637 &ieee->external_symbol_max_index, 'D');
326e32d7
ILT
638 if (symbol == NULL)
639 return false;
87f86b4e 640
9783e04a 641 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
b2c91bd9 642
9783e04a
DM
643 symbol->symbol.the_bfd = abfd;
644 symbol->symbol.name = read_id (&(ieee->h));
c3246d9b 645 symbol->symbol.udata.p = (PTR) NULL;
9783e04a
DM
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
b2c91bd9
SC
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 */
9783e04a
DM
666 parse_int (&(ieee->h), &value);
667 parse_int (&(ieee->h), &value);
668 break;
87f86b4e 669
9783e04a
DM
670 default:
671 parse_int (&(ieee->h), &value);
672 break;
673 }
b2c91bd9 674 }
9783e04a
DM
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;
e98e6ec1 694
b2c91bd9 695 }
9783e04a
DM
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 */
c3246d9b 712 symbol->symbol.section = bfd_com_section_ptr;
9783e04a
DM
713 symbol->symbol.value = size;
714 }
715 break;
87f86b4e 716
9783e04a
DM
717 case ieee_external_reference_enum:
718 next_byte (&(ieee->h));
b2c91bd9 719
9783e04a
DM
720 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
721 &prev_reference_ptr,
722 &ieee->external_reference_max_index, 'X');
326e32d7
ILT
723 if (symbol == NULL)
724 return false;
b2c91bd9 725
9783e04a
DM
726 symbol->symbol.the_bfd = abfd;
727 symbol->symbol.name = read_id (&(ieee->h));
c3246d9b
ILT
728 symbol->symbol.udata.p = (PTR) NULL;
729 symbol->symbol.section = bfd_und_section_ptr;
9783e04a
DM
730 symbol->symbol.value = (bfd_vma) 0;
731 symbol->symbol.flags = 0;
b2c91bd9 732
9783e04a
DM
733 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
734 break;
87f86b4e 735
9783e04a
DM
736 default:
737 loop = false;
738 }
87f86b4e 739 }
87f86b4e 740
9783e04a
DM
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 }
87f86b4e 751
9783e04a
DM
752 if (ieee->external_reference_max_index != 0)
753 {
754 ieee->external_reference_count =
755 ieee->external_reference_max_index -
87f86b4e 756 ieee->external_reference_min_index + 1;
9783e04a
DM
757 }
758 else
759 {
760 ieee->external_reference_count = 0;
761 }
87f86b4e
DHW
762
763 abfd->symcount =
9783e04a 764 ieee->external_reference_count + ieee->external_symbol_count;
b2c91bd9 765
9783e04a
DM
766 if (symbol_count != abfd->symcount)
767 {
768 /* There are gaps in the table -- */
769 ieee->symbol_table_full = false;
770 }
b2c91bd9 771
9783e04a
DM
772 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
773 *prev_reference_ptr = (ieee_symbol_type *) NULL;
326e32d7
ILT
774
775 return true;
87f86b4e
DHW
776}
777
326e32d7 778static boolean
57a1867e
DM
779ieee_slurp_symbol_table (abfd)
780 bfd *abfd;
87f86b4e 781{
9783e04a
DM
782 if (IEEE_DATA (abfd)->read_symbols == false)
783 {
326e32d7
ILT
784 if (! ieee_slurp_external_symbols (abfd))
785 return false;
9783e04a
DM
786 IEEE_DATA (abfd)->read_symbols = true;
787 }
326e32d7 788 return true;
87f86b4e
DHW
789}
790
326e32d7 791long
57a1867e
DM
792ieee_get_symtab_upper_bound (abfd)
793 bfd *abfd;
87f86b4e 794{
326e32d7
ILT
795 if (! ieee_slurp_symbol_table (abfd))
796 return -1;
87f86b4e 797
9783e04a
DM
798 return (abfd->symcount != 0) ?
799 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
87f86b4e
DHW
800}
801
9783e04a 802/*
87f86b4e
DHW
803Move from our internal lists to the canon table, and insert in
804symbol index order
805*/
806
2f3508ad 807extern const bfd_target ieee_vec;
9783e04a 808
326e32d7 809long
57a1867e
DM
810ieee_get_symtab (abfd, location)
811 bfd *abfd;
812 asymbol **location;
87f86b4e
DHW
813{
814 ieee_symbol_type *symp;
815 static bfd dummy_bfd;
816 static asymbol empty_symbol =
9783e04a 817 /* the_bfd, name, value, attr, section */
c3246d9b 818 {&dummy_bfd, " ieee empty", (symvalue) 0, BSF_DEBUGGING, bfd_abs_section_ptr};
b2c91bd9 819
9783e04a
DM
820 if (abfd->symcount)
821 {
822 ieee_data_type *ieee = IEEE_DATA (abfd);
823 dummy_bfd.xvec = &ieee_vec;
326e32d7
ILT
824 if (! ieee_slurp_symbol_table (abfd))
825 return -1;
b2c91bd9 826
9783e04a
DM
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 }
87f86b4e 837
9783e04a
DM
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 }
87f86b4e 846
9783e04a
DM
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;
87f86b4e 850
9783e04a
DM
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;
87f86b4e 857
9783e04a
DM
858 }
859 }
860 if (abfd->symcount)
861 {
862 location[abfd->symcount] = (asymbol *) NULL;
294eaca4 863 }
87f86b4e
DHW
864 return abfd->symcount;
865}
9783e04a 866
b2c91bd9 867static asection *
57a1867e
DM
868get_section_entry (abfd, ieee, index)
869 bfd *abfd;
870 ieee_data_type *ieee;
871 unsigned int index;
9783e04a
DM
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 {
57a1867e 880 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
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 }
b2c91bd9
SC
890 return ieee->section_table[index];
891}
87f86b4e
DHW
892
893static void
57a1867e
DM
894ieee_slurp_sections (abfd)
895 bfd *abfd;
87f86b4e 896{
9783e04a 897 ieee_data_type *ieee = IEEE_DATA (abfd);
87f86b4e 898 file_ptr offset = ieee->w.r.section_part;
9783e04a 899 asection *section = (asection *) NULL;
b07d03ba 900 char *name;
87f86b4e 901
9783e04a
DM
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)))
71858486 909 {
9783e04a
DM
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);
b2c91bd9 917
9783e04a
DM
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 }
b2c91bd9 989 break;
9783e04a
DM
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 }
b2c91bd9 1006 break;
9783e04a
DM
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 }
b2c91bd9
SC
1045 break;
1046 default:
1047 return;
1048 }
9783e04a 1049 }
87f86b4e 1050 }
87f86b4e 1051}
9783e04a 1052\f
87f86b4e
DHW
1053
1054/***********************************************************************
9783e04a 1055* archive stuff
87f86b4e 1056*/
9783e04a 1057
2f3508ad 1058const bfd_target *
57a1867e
DM
1059ieee_archive_p (abfd)
1060 bfd *abfd;
87f86b4e
DHW
1061{
1062 char *library;
1063 boolean loop;
6f715d66 1064
87f86b4e 1065 unsigned int i;
70e00914 1066 unsigned char buffer[512];
9465d03e 1067 struct obstack ob;
f8e01940 1068 file_ptr buffer_offset = 0;
69e0d34d 1069 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
9783e04a
DM
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 {
57a1867e 1074 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
1075 return NULL;
1076 }
1077 ieee = IEEE_AR_DATA (abfd);
9465d03e 1078
4002f18a
ILT
1079 /* FIXME: Check return value. I'm not sure whether it needs to read
1080 the entire buffer or not. */
9783e04a 1081 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
d0ec7a8e 1082
6f715d66
SC
1083 ieee->h.first_byte = buffer;
1084 ieee->h.input_p = buffer;
d0ec7a8e 1085
6f715d66
SC
1086 ieee->h.abfd = abfd;
1087
9783e04a
DM
1088 if (this_byte (&(ieee->h)) != Module_Beginning)
1089 {
1090 abfd->tdata.ieee_ar_data = save;
2f3508ad 1091 return (const bfd_target *) NULL;
69e0d34d 1092 }
6f715d66 1093
9783e04a
DM
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;
2f3508ad 1100 return (const bfd_target *) NULL;
9783e04a 1101 }
87f86b4e 1102 /* Throw away the filename */
9783e04a 1103 read_id (&(ieee->h));
87f86b4e
DHW
1104 /* This must be an IEEE archive, so we'll buy some space to do
1105 things */
9465d03e 1106
9783e04a
DM
1107 if (!obstack_begin (&ob, 128))
1108 {
57a1867e 1109 bfd_set_error (bfd_error_no_memory);
2f3508ad 1110 return (const bfd_target *) NULL;
9783e04a 1111 }
9465d03e 1112
6f715d66
SC
1113 ieee->element_count = 0;
1114 ieee->element_index = 0;
87f86b4e 1115
9783e04a
DM
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));
87f86b4e
DHW
1119
1120 loop = true;
1121 /* Read the index of the BB table */
9783e04a
DM
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
ae115e51 1137 if ((size_t) ieee_pos (abfd) > sizeof (buffer) / 2)
9783e04a
DM
1138 {
1139 /* Past half way, reseek and reprime */
1140 buffer_offset += ieee_pos (abfd);
4002f18a
ILT
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. */
9783e04a
DM
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;
87f86b4e 1152 }
6f715d66 1153
9783e04a
DM
1154 ieee->elements = (ieee_ar_obstack_type *) obstack_finish (&ob);
1155 if (!ieee->elements)
1156 {
57a1867e 1157 bfd_set_error (bfd_error_no_memory);
2f3508ad 1158 return (const bfd_target *) NULL;
9783e04a 1159 }
87f86b4e
DHW
1160
1161 /* Now scan the area again, and replace BB offsets with file */
1162 /* offsets */
1163
9783e04a
DM
1164 for (i = 2; i < ieee->element_count; i++)
1165 {
4002f18a
ILT
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. */
9783e04a
DM
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 }
87f86b4e 1186 }
87f86b4e 1187
aff6e0b4 1188/* abfd->has_armap = ;*/
87f86b4e
DHW
1189 return abfd->xvec;
1190}
1191
301dfc71 1192static boolean
57a1867e
DM
1193ieee_mkobject (abfd)
1194 bfd *abfd;
9783e04a
DM
1195{
1196 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, sizeof (ieee_data_type));
1197 return abfd->tdata.ieee_data ? true : false;
301dfc71
SC
1198}
1199
2f3508ad 1200const bfd_target *
57a1867e
DM
1201ieee_object_p (abfd)
1202 bfd *abfd;
87f86b4e
DHW
1203{
1204 char *processor;
1205 unsigned int part;
301dfc71 1206 ieee_data_type *ieee;
70e00914 1207 unsigned char buffer[300];
9783e04a 1208 ieee_data_type *save = IEEE_DATA (abfd);
70e00914 1209
e98e6ec1 1210 abfd->tdata.ieee_data = 0;
9783e04a
DM
1211 ieee_mkobject (abfd);
1212
1213 ieee = IEEE_DATA (abfd);
4002f18a
ILT
1214 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1215 goto fail;
301dfc71 1216 /* Read the first few bytes in to see if it makes sense */
4002f18a
ILT
1217 /* FIXME: Check return value. I'm not sure whether it needs to read
1218 the entire buffer or not. */
9783e04a 1219 bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
301dfc71 1220
6f715d66 1221 ieee->h.input_p = buffer;
9783e04a 1222 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
2f3508ad 1223 goto got_wrong_format;
301dfc71 1224
9783e04a
DM
1225 ieee->read_symbols = false;
1226 ieee->read_data = false;
301dfc71
SC
1227 ieee->section_count = 0;
1228 ieee->external_symbol_max_index = 0;
1229 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
9783e04a 1230 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
301dfc71 1231 ieee->external_reference_max_index = 0;
6f715d66 1232 ieee->h.abfd = abfd;
9783e04a 1233 memset ((PTR) ieee->section_table, 0, sizeof (ieee->section_table));
301dfc71 1234
9783e04a
DM
1235 processor = ieee->mb.processor = read_id (&(ieee->h));
1236 if (strcmp (processor, "LIBRARY") == 0)
2f3508ad 1237 goto got_wrong_format;
9783e04a
DM
1238 ieee->mb.module_name = read_id (&(ieee->h));
1239 if (abfd->filename == (CONST char *) NULL)
b2c91bd9 1240 {
9783e04a 1241 abfd->filename = ieee->mb.module_name;
b2c91bd9 1242 }
9783e04a
DM
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)
2f3508ad 1248 goto got_wrong_format;
9783e04a 1249 abfd->arch_info = arch;
87f86b4e
DHW
1250 }
1251
9783e04a
DM
1252 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1253 {
301dfc71 1254 goto fail;
87f86b4e 1255 }
9783e04a
DM
1256 next_byte (&(ieee->h));
1257
1258 if (parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau) == false)
1259 {
301dfc71 1260 goto fail;
87f86b4e 1261 }
9783e04a
DM
1262 if (parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address) == false)
1263 {
301dfc71 1264 goto fail;
87f86b4e
DHW
1265 }
1266
9783e04a
DM
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 }
87f86b4e 1291 abfd->flags = HAS_SYMS;
301dfc71
SC
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
9783e04a
DM
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 {
57a1867e 1301 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
1302 goto fail;
1303 }
4002f18a
ILT
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. */
9783e04a 1308 bfd_read ((PTR) (IEEE_DATA (abfd)->h.first_byte), 1, ieee->w.r.me_record + 50, abfd);
301dfc71 1309
9783e04a 1310 ieee_slurp_sections (abfd);
87f86b4e 1311 return abfd->xvec;
2f3508ad
ILT
1312got_wrong_format:
1313 bfd_set_error (bfd_error_wrong_format);
9783e04a
DM
1314fail:
1315 (void) bfd_release (abfd, ieee);
1316 abfd->tdata.ieee_data = save;
2f3508ad 1317 return (const bfd_target *) NULL;
87f86b4e
DHW
1318}
1319
9783e04a 1320void
57a1867e
DM
1321ieee_get_symbol_info (ignore_abfd, symbol, ret)
1322 bfd *ignore_abfd;
1323 asymbol *symbol;
1324 symbol_info *ret;
70e00914
KR
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}
87f86b4e 1332
9783e04a 1333void
57a1867e
DM
1334ieee_print_symbol (ignore_abfd, afile, symbol, how)
1335 bfd *ignore_abfd;
1336 PTR afile;
1337 asymbol *symbol;
1338 bfd_print_symbol_type how;
87f86b4e 1339{
9783e04a 1340 FILE *file = (FILE *) afile;
2b1d8a50 1341
9783e04a
DM
1342 switch (how)
1343 {
1344 case bfd_print_symbol_name:
1345 fprintf (file, "%s", symbol->name);
1346 break;
1347 case bfd_print_symbol_more:
87f86b4e 1348#if 0
9783e04a
DM
1349 fprintf (file, "%4x %2x", aout_symbol (symbol)->desc & 0xffff,
1350 aout_symbol (symbol)->other & 0xff);
87f86b4e 1351#endif
9783e04a
DM
1352 BFD_FAIL ();
1353 break;
1354 case bfd_print_symbol_all:
301dfc71 1355 {
9783e04a
DM
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);
301dfc71 1365
9783e04a
DM
1366 fprintf (file, " %-5s %04x %02x %s",
1367 section_name,
1368 (unsigned) ieee_symbol (symbol)->index,
1369 (unsigned) 0, /*
301dfc71
SC
1370 aout_symbol(symbol)->desc & 0xffff,
1371 aout_symbol(symbol)->other & 0xff,*/
9783e04a
DM
1372 symbol->name);
1373 }
301dfc71 1374 }
9783e04a
DM
1375 break;
1376 }
87f86b4e
DHW
1377}
1378
9783e04a 1379static boolean
57a1867e
DM
1380do_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;
7564d3d7 1385{
9783e04a
DM
1386 switch (this_byte (&(ieee->h)))
1387 {
1388 case ieee_load_constant_bytes_enum:
7564d3d7 1389 {
9783e04a
DM
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++)
7564d3d7 1396 {
9783e04a
DM
1397 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1398 next_byte (&(ieee->h));
7564d3d7 1399 }
9783e04a
DM
1400 }
1401 break;
7564d3d7 1402
9783e04a
DM
1403 case ieee_load_with_relocation_enum:
1404 {
1405 boolean loop = true;
1406 next_byte (&(ieee->h));
1407 while (loop)
7564d3d7 1408 {
9783e04a
DM
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:
7564d3d7 1416 {
9783e04a
DM
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 {
57a1867e 1425 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
1426 return false;
1427 }
7564d3d7 1428
9783e04a
DM
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));
69e0d34d 1433/* abort();*/
9783e04a
DM
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
b2c91bd9
SC
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 */
9783e04a
DM
1475
1476 switch (extra)
1477 {
1478 case 0:
1479 case 4:
1480
1481 if (pcrel == true)
1482 {
b2c91bd9 1483#if KEEPMINUSPCININST
9783e04a
DM
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;
b2c91bd9 1489#else
9783e04a
DM
1490 bfd_put_32 (ieee->h.abfd, 0, location_ptr +
1491 current_map->pc);
1492 r->relent.howto = &rel32_howto;
b2c91bd9 1493#endif
9783e04a
DM
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 {
b2c91bd9 1506#if KEEPMINUSPCININST
9783e04a
DM
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;
b2c91bd9
SC
1510#else
1511
9783e04a
DM
1512 bfd_put_16 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1513 r->relent.howto = &rel16_howto;
b2c91bd9 1514#endif
9783e04a
DM
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 {
b2c91bd9 1527#if KEEPMINUSPCININST
9783e04a
DM
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;
b2c91bd9 1531#else
9783e04a
DM
1532 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1533 r->relent.howto = &rel8_howto;
b2c91bd9 1534#endif
9783e04a
DM
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 }
7564d3d7 1566 }
9783e04a 1567 }
7564d3d7
SC
1568 }
1569 }
9783e04a
DM
1570 }
1571 return true;
7564d3d7 1572}
87f86b4e 1573
6f715d66 1574/* Read in all the section data and relocation stuff too */
9783e04a 1575static boolean
57a1867e
DM
1576ieee_slurp_section_data (abfd)
1577 bfd *abfd;
87f86b4e 1578{
9783e04a
DM
1579 bfd_byte *location_ptr = (bfd_byte *) NULL;
1580 ieee_data_type *ieee = IEEE_DATA (abfd);
1581 unsigned int section_number;
87f86b4e 1582
9783e04a 1583 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
87f86b4e
DHW
1584 asection *s;
1585 /* Seek to the start of the data area */
9783e04a
DM
1586 if (ieee->read_data == true)
1587 return true;
87f86b4e 1588 ieee->read_data = true;
9783e04a 1589 ieee_seek (abfd, ieee->w.r.data_part);
87f86b4e
DHW
1590
1591 /* Allocate enough space for all the section contents */
1592
9783e04a
DM
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 {
57a1867e 1599 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
1600 return false;
1601 }
1602 /*SUPPRESS 68*/
1603 per->reloc_tail_ptr =
1604 (ieee_reloc_type **) & (s->relocation);
1605 }
87f86b4e 1606
9783e04a
DM
1607 while (true)
1608 {
1609 switch (this_byte (&(ieee->h)))
87f86b4e 1610 {
7564d3d7
SC
1611 /* IF we see anything strange then quit */
1612 default:
1613 return true;
87f86b4e 1614
7564d3d7 1615 case ieee_set_current_section_enum:
9783e04a
DM
1616 next_byte (&(ieee->h));
1617 section_number = must_parse_int (&(ieee->h));
7564d3d7
SC
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 .. */
9783e04a 1624 current_map->pc = s->vma;
7564d3d7 1625 break;
87f86b4e 1626
7564d3d7 1627 case ieee_e2_first_byte_enum:
9783e04a
DM
1628 next_byte (&(ieee->h));
1629 switch (this_byte (&(ieee->h)))
1630 {
1631 case ieee_set_current_pc_enum & 0xff:
7564d3d7 1632 {
9783e04a
DM
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);
7564d3d7 1645 }
9783e04a
DM
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 }
7564d3d7
SC
1655 break;
1656 case ieee_repeat_data_enum:
9783e04a
DM
1657 {
1658 /* Repeat the following LD or LR n times - we do this by
7564d3d7 1659 remembering the stream pointer before running it and
6f715d66
SC
1660 resetting it and running it n times. We special case
1661 the repetition of a repeat_data/load_constant
7564d3d7
SC
1662 */
1663
9783e04a
DM
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));
6f715d66 1680 }
9783e04a
DM
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 }
7564d3d7 1690 }
9783e04a 1691 }
7564d3d7
SC
1692 break;
1693 case ieee_load_constant_bytes_enum:
1694 case ieee_load_with_relocation_enum:
9783e04a
DM
1695 {
1696 if (!do_one (ieee, current_map, location_ptr, s))
1697 return false;
1698 }
87f86b4e 1699 }
9783e04a 1700 }
87f86b4e
DHW
1701}
1702
87f86b4e 1703boolean
57a1867e
DM
1704ieee_new_section_hook (abfd, newsect)
1705 bfd *abfd;
1706 asection *newsect;
87f86b4e 1707{
a6dab071 1708 newsect->used_by_bfd = (PTR)
9783e04a
DM
1709 bfd_alloc (abfd, sizeof (ieee_per_section_type));
1710 if (!newsect->used_by_bfd)
1711 {
57a1867e 1712 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
1713 return false;
1714 }
1715 ieee_per_section (newsect)->data = (bfd_byte *) NULL;
1716 ieee_per_section (newsect)->section = newsect;
87f86b4e
DHW
1717 return true;
1718}
1719
326e32d7 1720long
57a1867e
DM
1721ieee_get_reloc_upper_bound (abfd, asect)
1722 bfd *abfd;
1723 sec_ptr asect;
87f86b4e 1724{
326e32d7
ILT
1725 if (! ieee_slurp_section_data (abfd))
1726 return -1;
9783e04a 1727 return (asect->reloc_count + 1) * sizeof (arelent *);
87f86b4e
DHW
1728}
1729
1730static boolean
57a1867e
DM
1731ieee_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;
87f86b4e 1737{
a6dab071 1738 ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;
9783e04a
DM
1739 ieee_slurp_section_data (abfd);
1740 (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
87f86b4e
DHW
1741 return true;
1742}
1743
326e32d7 1744long
57a1867e
DM
1745ieee_canonicalize_reloc (abfd, section, relptr, symbols)
1746 bfd *abfd;
1747 sec_ptr section;
1748 arelent **relptr;
1749 asymbol **symbols;
87f86b4e 1750{
d0ec7a8e 1751/* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
9783e04a
DM
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:
87f86b4e 1769
9783e04a
DM
1770 BFD_FAIL ();
1771 }
1772 *relptr++ = &src->relent;
1773 src = src->next;
87f86b4e 1774 }
9783e04a 1775 *relptr = (arelent *) NULL;
87f86b4e
DHW
1776 return section->reloc_count;
1777}
1778
9783e04a 1779static int
57a1867e
DM
1780comp (ap, bp)
1781 CONST PTR ap;
1782 CONST PTR bp;
87f86b4e 1783{
9783e04a
DM
1784 arelent *a = *((arelent **) ap);
1785 arelent *b = *((arelent **) bp);
87f86b4e
DHW
1786 return a->address - b->address;
1787}
9872a49c 1788
87f86b4e
DHW
1789/*
1790Write the section headers
1791*/
1792
1793static void
57a1867e
DM
1794ieee_write_section_part (abfd)
1795 bfd *abfd;
87f86b4e 1796{
9783e04a 1797 ieee_data_type *ieee = IEEE_DATA (abfd);
87f86b4e 1798 asection *s;
9783e04a
DM
1799 ieee->w.r.section_part = bfd_tell (abfd);
1800 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1801 {
c3246d9b 1802 if (! bfd_is_abs_section (s))
6f715d66 1803 {
9783e04a
DM
1804 ieee_write_byte (abfd, ieee_section_type_enum);
1805 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
6f715d66 1806
9783e04a
DM
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 }
6f715d66 1817
9783e04a
DM
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:
6f715d66 1832
9783e04a
DM
1833 ieee_write_byte (abfd, ieee_variable_R_enum);
1834 }
87f86b4e 1835
9783e04a
DM
1836
1837 ieee_write_id (abfd, s->name);
6f715d66 1838#if 0
9783e04a
DM
1839 ieee_write_int (abfd, 0); /* Parent */
1840 ieee_write_int (abfd, 0); /* Brother */
1841 ieee_write_int (abfd, 0); /* Context */
6f715d66 1842#endif
9783e04a
DM
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
b2c91bd9 1863 }
87f86b4e
DHW
1864}
1865
1866
9783e04a 1867static boolean
57a1867e
DM
1868do_with_relocs (abfd, s)
1869 bfd *abfd;
1870 asection *s;
87f86b4e 1871{
6f715d66 1872 unsigned int relocs_to_go = s->reloc_count;
b2c91bd9 1873
9783e04a 1874 bfd_byte *stream = ieee_per_section (s)->data;
6f715d66
SC
1875 arelent **p = s->orelocation;
1876
1877 bfd_size_type current_byte_index = 0;
1878
9783e04a
DM
1879 qsort (s->orelocation,
1880 relocs_to_go,
1881 sizeof (arelent **),
1882 comp);
6f715d66 1883
b2c91bd9 1884 /* Output the section preheader */
9783e04a
DM
1885 ieee_write_byte (abfd, ieee_set_current_section_enum);
1886 ieee_write_byte (abfd, (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE));
6f715d66 1887
9783e04a
DM
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);
6f715d66 1891
9783e04a
DM
1892 if (relocs_to_go == 0)
1893 {
1894 /* If there arn't any relocations then output the load constant byte
b2c91bd9
SC
1895 opcode rather than the load with relocation opcode */
1896
9783e04a
DM
1897 while (current_byte_index < s->_raw_size)
1898 {
b2c91bd9 1899 bfd_size_type run;
9783e04a 1900 unsigned int MAXRUN = 32;
b2c91bd9 1901 run = MAXRUN;
9783e04a
DM
1902 if (run > s->_raw_size - current_byte_index)
1903 {
1904 run = s->_raw_size - current_byte_index;
1905 }
6f715d66 1906
9783e04a
DM
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);
4002f18a
ILT
1912 if (bfd_write ((PTR) (stream + current_byte_index),
1913 1,
1914 run,
1915 abfd)
1916 != run)
1917 return false;
9783e04a
DM
1918 current_byte_index += run;
1919 }
6f715d66 1920 }
9783e04a
DM
1921 }
1922 else
1923 {
1924 ieee_write_byte (abfd, ieee_load_with_relocation_enum);
6f715d66 1925
6f715d66 1926
9783e04a 1927 /* Output the data stream as the longest sequence of bytes
b2c91bd9
SC
1928 possible, allowing for the a reasonable packet size and
1929 relocation stuffs */
6f715d66 1930
9783e04a
DM
1931 if ((PTR) stream == (PTR) NULL)
1932 {
b2c91bd9 1933 /* Outputting a section without data, fill it up */
9783e04a
DM
1934 stream = (unsigned char *) (bfd_alloc (abfd, s->_raw_size));
1935 if (!stream)
1936 {
57a1867e 1937 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
1938 return false;
1939 }
ae115e51 1940 memset ((PTR) stream, 0, (size_t) s->_raw_size);
6f715d66 1941 }
9783e04a
DM
1942 while (current_byte_index < s->_raw_size)
1943 {
b2c91bd9
SC
1944 bfd_size_type run;
1945 unsigned int MAXRUN = 32;
9783e04a
DM
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 }
6f715d66 1958
9783e04a
DM
1959 if (run != 0)
1960 {
1961 /* Output a stream of bytes */
1962 ieee_write_int (abfd, run);
4002f18a
ILT
1963 if (bfd_write ((PTR) (stream + current_byte_index),
1964 1,
1965 run,
1966 abfd)
1967 != run)
1968 return false;
9783e04a
DM
1969 current_byte_index += run;
1970 }
b2c91bd9 1971 /* Output any relocations here */
9783e04a
DM
1972 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1973 {
1974 while (relocs_to_go && (*p) && (*p)->address == current_byte_index)
1975 {
6f715d66 1976
9783e04a
DM
1977 arelent *r = *p;
1978 bfd_vma ov;
b2c91bd9
SC
1979
1980#if 0
9783e04a
DM
1981 if (r->howto->pc_relative)
1982 {
1983 r->addend += current_byte_index;
1984 }
b2c91bd9
SC
1985#endif
1986
9783e04a
DM
1987 switch (r->howto->size)
1988 {
1989 case 2:
b2c91bd9 1990
9783e04a
DM
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);
aff6e0b4 2010/* abort();*/
b2c91bd9 2011
9783e04a
DM
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 }
b2c91bd9 2024
9783e04a
DM
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);
b2c91bd9 2032
9783e04a
DM
2033 relocs_to_go--;
2034 p++;
2035 }
2036
2037 }
b2c91bd9 2038 }
9783e04a
DM
2039 }
2040 return true;
6f715d66
SC
2041}
2042
2043/* If there are no relocations in the output section then we can
2044be clever about how we write. We block items up into a max of 127
2045bytes */
2046
9783e04a 2047static void
57a1867e
DM
2048do_as_repeat (abfd, s)
2049 bfd *abfd;
2050 asection *s;
9783e04a
DM
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 }
6f715d66
SC
2067}
2068
9783e04a 2069static void
57a1867e
DM
2070do_without_relocs (abfd, s)
2071 bfd *abfd;
2072 asection *s;
6f715d66 2073{
9783e04a 2074 bfd_byte *stream = ieee_per_section (s)->data;
6f715d66 2075
9783e04a
DM
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 }
6f715d66 2090 }
9783e04a
DM
2091 do_as_repeat (abfd, s);
2092 }
2093
6f715d66 2094}
301dfc71 2095
6f715d66
SC
2096
2097static unsigned char *output_ptr_start;
2098static unsigned char *output_ptr;
2099static unsigned char *output_ptr_end;
2100static unsigned char *input_ptr_start;
2101static unsigned char *input_ptr;
2102static unsigned char *input_ptr_end;
2103static bfd *input_bfd;
2104static bfd *output_bfd;
2105static int output_buffer;
2106
57a1867e 2107static void
9783e04a 2108fill ()
6f715d66 2109{
4002f18a
ILT
2110 /* FIXME: Check return value. I'm not sure whether it needs to read
2111 the entire buffer or not. */
9783e04a 2112 bfd_read ((PTR) input_ptr_start, 1, input_ptr_end - input_ptr_start, input_bfd);
6f715d66
SC
2113 input_ptr = input_ptr_start;
2114}
57a1867e 2115static void
9783e04a 2116flush ()
6f715d66 2117{
4002f18a
ILT
2118 if (bfd_write ((PTR) (output_ptr_start), 1, output_ptr - output_ptr_start,
2119 output_bfd)
ae115e51 2120 != (bfd_size_type) (output_ptr - output_ptr_start))
4002f18a 2121 abort ();
6f715d66
SC
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
57a1867e 2130static void
9783e04a
DM
2131write_int (value)
2132 int value;
6f715d66 2133{
9783e04a
DM
2134 if (value >= 0 && value <= 127)
2135 {
2136 OUT (value);
6f715d66 2137 }
9783e04a
DM
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;
6f715d66 2157
9783e04a
DM
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 }
6f715d66 2170
9783e04a 2171 }
6f715d66 2172}
9783e04a 2173
57a1867e 2174static void
9783e04a 2175copy_id ()
6f715d66 2176{
9783e04a 2177 int length = THIS ();
6f715d66 2178 char ch;
9783e04a
DM
2179 OUT (length);
2180 NEXT ();
2181 while (length--)
2182 {
2183 ch = THIS ();
2184 OUT (ch);
2185 NEXT ();
2186 }
6f715d66 2187}
9783e04a 2188
6f715d66 2189#define VAR(x) ((x | 0x80))
57a1867e 2190static void
9783e04a 2191copy_expression ()
6f715d66
SC
2192{
2193 int stack[10];
2194 int *tos = stack;
2195 int value = 0;
9783e04a
DM
2196 while (1)
2197 {
2198 switch (THIS ())
6f715d66 2199 {
9783e04a
DM
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 ();
6f715d66 2210 *tos++ = value;
9783e04a
DM
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 ();
6f715d66 2234 *tos++ = value;
9783e04a
DM
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 ();
6f715d66 2249 value = 0;
9783e04a
DM
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;
87f86b4e 2290
9783e04a 2291 }
6f715d66
SC
2292 }
2293 }
6f715d66
SC
2294
2295}
87f86b4e 2296
6f715d66
SC
2297/* Drop the int in the buffer, and copy a null into the gap, which we
2298 will overwrite later */
87f86b4e 2299
9783e04a
DM
2300struct output_buffer_struct
2301{
2302 unsigned char *ptrp;
6f715d66 2303 int buffer;
9783e04a 2304};
87f86b4e 2305
6f715d66 2306static void
57a1867e
DM
2307fill_int (buf)
2308 struct output_buffer_struct *buf;
9783e04a
DM
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 }
6f715d66 2319}
9783e04a 2320
6f715d66 2321static void
57a1867e
DM
2322drop_int (buf)
2323 struct output_buffer_struct *buf;
6f715d66 2324{
9783e04a 2325 int type = THIS ();
6f715d66 2326 int ch;
9783e04a
DM
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 }
6f715d66 2347 }
9783e04a 2348 OUT (0x84);
6f715d66 2349 buf->ptrp = output_ptr;
9783e04a
DM
2350 buf->buffer = output_buffer;
2351 OUT (0);
2352 OUT (0);
2353 OUT (0);
2354 OUT (0);
6f715d66
SC
2355}
2356
57a1867e 2357static void
9783e04a 2358copy_int ()
6f715d66 2359{
9783e04a 2360 int type = THIS ();
6f715d66 2361 int ch;
9783e04a
DM
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 }
6f715d66 2387 }
6f715d66
SC
2388}
2389
2390#define ID copy_id()
2391#define INT copy_int()
2392#define EXP copy_expression()
9783e04a 2393static void copy_till_end ();
6f715d66
SC
2394#define INTn(q) copy_int()
2395#define EXPn(q) copy_expression()
9783e04a 2396
57a1867e 2397static void
9783e04a 2398f1_record ()
6f715d66
SC
2399{
2400 int ch;
2401 /* ATN record */
9783e04a
DM
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 {
6f715d66 2460 case 0x01:
9783e04a
DM
2461 INT;
2462 INT;
2463 break;
6f715d66 2464 case 0x02:
9783e04a
DM
2465 INT;
2466 break;
6f715d66 2467 case 0x04:
9783e04a
DM
2468 EXPn (external function);
2469 break;
6f715d66
SC
2470 case 0x05:
2471 break;
9783e04a
DM
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;
87f86b4e 2493 }
9783e04a 2494 }
6f715d66
SC
2495
2496}
9783e04a 2497
57a1867e 2498static void
9783e04a 2499f0_record ()
6f715d66
SC
2500{
2501 /* Attribute record */
9783e04a
DM
2502 NEXT ();
2503 OUT (0xf0);
2504 INTn (Symbol name);
6f715d66
SC
2505 ID;
2506}
9783e04a 2507
57a1867e 2508static void
9783e04a 2509copy_till_end ()
6f715d66 2510{
9783e04a
DM
2511 int ch = THIS ();
2512 while (1)
2513 {
2514 while (ch <= 0x80)
6f715d66 2515 {
9783e04a
DM
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;
6f715d66 2541 }
6f715d66 2542 }
6f715d66
SC
2543
2544}
2545
57a1867e 2546static void
9783e04a 2547f2_record ()
6f715d66 2548{
9783e04a
DM
2549 NEXT ();
2550 OUT (0xf2);
2551 INT;
2552 NEXT ();
2553 OUT (0xce);
2554 INT;
2555 copy_till_end ();
6f715d66
SC
2556}
2557
2558
9783e04a 2559static void block ();
57a1867e 2560static void
9783e04a 2561f8_record ()
6f715d66
SC
2562{
2563 int ch;
9783e04a
DM
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 */
6f715d66 2574 {
9783e04a
DM
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;
301dfc71 2610
9783e04a
DM
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;
d0ec7a8e 2632
9783e04a
DM
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;
d0ec7a8e 2652
9783e04a
DM
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);
87f86b4e 2699 }
9783e04a
DM
2700 break;
2701 }
6f715d66 2702}
87f86b4e 2703
57a1867e 2704static void
9783e04a 2705e2_record ()
6f715d66 2706{
9783e04a
DM
2707 OUT (0xe2);
2708 NEXT ();
2709 OUT (0xce);
2710 NEXT ();
6f715d66
SC
2711 INT;
2712 EXP;
2713}
2714
57a1867e
DM
2715static void
2716block ()
6f715d66 2717{
9783e04a
DM
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;
6f715d66 2744
9783e04a
DM
2745 }
2746 }
6f715d66 2747}
6f715d66
SC
2748
2749
9783e04a
DM
2750
2751/* relocate_debug,
6f715d66
SC
2752 moves all the debug information from the source bfd to the output
2753 bfd, and relocates any expressions it finds
2754*/
2755
2756static void
57a1867e
DM
2757relocate_debug (output, input)
2758 bfd *output;
2759 bfd *input;
6f715d66
SC
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;
4002f18a
ILT
2768 /* FIXME: Check return value. I'm not sure whether it needs to read
2769 the entire buffer or not. */
9783e04a
DM
2770 bfd_read ((PTR) input_ptr_start, 1, IBS, input);
2771 block ();
6f715d66 2772}
9783e04a
DM
2773
2774/*
6f715d66
SC
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
9783e04a 2780static void
57a1867e
DM
2781ieee_write_debug_part (abfd)
2782 bfd *abfd;
6f715d66 2783{
9783e04a 2784 ieee_data_type *ieee = IEEE_DATA (abfd);
6f715d66
SC
2785 bfd_chain_type *chain = ieee->chain_root;
2786 unsigned char output_buffer[OBS];
b2c91bd9 2787 boolean some_debug = false;
9783e04a 2788 file_ptr here = bfd_tell (abfd);
b2c91bd9 2789
9783e04a 2790 output_ptr_start = output_ptr = output_buffer;
6f715d66
SC
2791 output_ptr_end = output_buffer + OBS;
2792 output_ptr = output_buffer;
2793 output_bfd = abfd;
6f715d66 2794
9783e04a
DM
2795 if (chain == (bfd_chain_type *) NULL)
2796 {
b645b632 2797#if 0
e98e6ec1 2798 /* There is no debug info, so we'll fake some up */
9783e04a
DM
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};
e98e6ec1 2803 ieee->w.r.debug_information_part = 0;
b2c91bd9 2804
b645b632 2805
e98e6ec1 2806 here;
b2c91bd9
SC
2807
2808
e98e6ec1
SC
2809 /* bfd_write(fake, 1, sizeof(fake), abfd);*/
2810 /* Now write a header for each section */
9783e04a
DM
2811 {
2812 int i = 0;
2813 asection *s = abfd->sections;
2814 while (s)
e98e6ec1 2815 {
9783e04a
DM
2816 if (s != abfd->abs_section)
2817 {
e98e6ec1 2818
9783e04a
DM
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,
c3246d9b 2829 bfd_abs_section_ptr->symbol, 0, 0, 0);
9783e04a
DM
2830 i++;
2831 }
2832
2833 s = s->next;
2834
2835 }
2836 /* Close the scope */
2837 ieee_write_byte (abfd, 0xf9);
2838 }
b2c91bd9 2839#endif
e98e6ec1 2840 }
9783e04a
DM
2841 else
2842 {
2843 while (chain != (bfd_chain_type *) NULL)
2844 {
e98e6ec1 2845 bfd *entry = chain->this;
9783e04a
DM
2846 ieee_data_type *entry_ieee = IEEE_DATA (entry);
2847 if (entry_ieee->w.r.debug_information_part)
2848 {
4002f18a
ILT
2849 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
2850 SEEK_SET)
2851 != 0)
2852 abort ();
9783e04a 2853 relocate_debug (abfd, entry);
e98e6ec1 2854 }
6f715d66 2855
e98e6ec1
SC
2856 chain = chain->next;
2857 }
9783e04a
DM
2858 if (some_debug)
2859 {
e98e6ec1
SC
2860 ieee->w.r.debug_information_part = here;
2861 }
9783e04a
DM
2862 else
2863 {
e98e6ec1
SC
2864 ieee->w.r.debug_information_part = 0;
2865 }
b2c91bd9 2866 }
9783e04a
DM
2867 flush ();
2868
2869}
6f715d66 2870
6f715d66
SC
2871/* write the data in an ieee way */
2872static void
57a1867e
DM
2873ieee_write_data_part (abfd)
2874 bfd *abfd;
6f715d66
SC
2875{
2876 asection *s;
9783e04a
DM
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
6f715d66 2882 places */
9783e04a
DM
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 }
301dfc71 2892}
87f86b4e
DHW
2893
2894
9783e04a 2895static boolean
57a1867e
DM
2896init_for_output (abfd)
2897 bfd *abfd;
87f86b4e 2898{
9783e04a
DM
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 {
57a1867e 2907 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
2908 return false;
2909 }
2910 }
87f86b4e 2911 }
9783e04a 2912 return true;
87f86b4e 2913}
9783e04a 2914\f
87f86b4e
DHW
2915/** exec and core file sections */
2916
9783e04a 2917/* set section contents is complicated with IEEE since the format is
87f86b4e
DHW
2918* not a byte image, but a record stream.
2919*/
2920boolean
57a1867e
DM
2921ieee_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;
9783e04a
DM
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);
87f86b4e
DHW
2936 return true;
2937}
2938
2939/*
2940write the external symbols of a file, IEEE considers two sorts of
2941external symbols, public, and referenced. It uses to internal forms
2942to index them as well. When we write them out we turn their symbol
2943values into indexes from the right base.
2944*/
2945static void
57a1867e
DM
2946ieee_write_external_part (abfd)
2947 bfd *abfd;
87f86b4e
DHW
2948{
2949 asymbol **q;
9783e04a 2950 ieee_data_type *ieee = IEEE_DATA (abfd);
87f86b4e
DHW
2951
2952 unsigned int reference_index = IEEE_REFERENCE_BASE;
9783e04a
DM
2953 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
2954 file_ptr here = bfd_tell (abfd);
b2c91bd9 2955 boolean hadone = false;
9783e04a
DM
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;
c3246d9b 2963 if (bfd_is_und_section (p->section))
9783e04a
DM
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 */
87f86b4e 2988
b2c91bd9 2989
9783e04a
DM
2990 ieee_write_byte (abfd, ieee_external_symbol_enum);
2991 ieee_write_int (abfd, public_index);
2992 ieee_write_id (abfd, p->name);
87f86b4e 2993
9783e04a
DM
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 */
b2c91bd9
SC
2999
3000
9783e04a
DM
3001 /* Write out the value */
3002 ieee_write_2bytes (abfd, ieee_value_record_enum);
3003 ieee_write_int (abfd, public_index);
c3246d9b 3004 if (! bfd_is_abs_section (p->section))
9783e04a
DM
3005 {
3006 if (abfd->flags & EXEC_P)
3007 {
3008 /* If fully linked, then output all symbols
e98e6ec1 3009 relocated */
9783e04a
DM
3010 ieee_write_int (abfd,
3011 p->value + p->section->output_offset + p->section->output_section->vma);
6f715d66 3012
9783e04a
DM
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,
c3246d9b 3026 bfd_abs_section_ptr->symbol,
9783e04a 3027 false, 0);
e98e6ec1 3028 }
9783e04a
DM
3029 p->value = public_index;
3030 public_index++;
b2c91bd9 3031 }
9783e04a 3032 else
b2c91bd9 3033 {
9783e04a
DM
3034 /* This can happen - when there are gaps in the symbols read */
3035 /* from an input ieee file */
6f715d66 3036 }
9783e04a 3037 }
87f86b4e 3038 }
b2c91bd9
SC
3039 if (hadone)
3040 ieee->w.r.external_part = here;
87f86b4e
DHW
3041
3042}
3043
b2c91bd9 3044
9783e04a
DM
3045static 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};
b2c91bd9 3052
71858486 3053static CONST unsigned char envi[] =
9783e04a
DM
3054{
3055 0xf0, 0x21, 0x00,
b2c91bd9
SC
3056
3057/* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
9783e04a 3058 0x19, 0x2c,
b2c91bd9 3059*/
9783e04a 3060 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
b2c91bd9 3061
9783e04a 3062 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
b2c91bd9 3063/* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
9783e04a 3064};
b2c91bd9 3065
87f86b4e 3066static
9783e04a 3067void
57a1867e
DM
3068ieee_write_me_part (abfd)
3069 bfd *abfd;
9783e04a
DM
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);
87f86b4e
DHW
3086
3087}
9783e04a 3088
87f86b4e 3089boolean
57a1867e
DM
3090ieee_write_object_contents (abfd)
3091 bfd *abfd;
87f86b4e 3092{
9783e04a 3093 ieee_data_type *ieee = IEEE_DATA (abfd);
87f86b4e 3094 unsigned int i;
9783e04a 3095 file_ptr old;
301dfc71 3096 /* Fast forward over the header area */
4002f18a
ILT
3097 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3098 return false;
9783e04a 3099 ieee_write_byte (abfd, ieee_module_beginning_enum);
301dfc71 3100
9783e04a
DM
3101 ieee_write_id (abfd, bfd_printable_name (abfd));
3102 ieee_write_id (abfd, abfd->filename);
6f715d66 3103
9783e04a
DM
3104 /* Fast forward over the variable bits */
3105 ieee_write_byte (abfd, ieee_address_descriptor_enum);
b2c91bd9
SC
3106
3107 /* Bits per MAU */
9783e04a 3108 ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd)));
b2c91bd9 3109 /* MAU's per address */
9783e04a
DM
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);
4002f18a
ILT
3114 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3115 return false;
9783e04a
DM
3116
3117 ieee->w.r.extension_record = bfd_tell (abfd);
4002f18a
ILT
3118 if (bfd_write ((char *) exten, 1, sizeof (exten), abfd) != sizeof (exten))
3119 return false;
9783e04a
DM
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);
4002f18a
ILT
3126 if (bfd_write ((char *) envi, 1, sizeof (envi), abfd) != sizeof (envi))
3127 return false;
b2c91bd9 3128 output_bfd = abfd;
9783e04a 3129 flush ();
6f715d66 3130
9783e04a 3131 ieee_write_section_part (abfd);
87f86b4e 3132 /*
9783e04a 3133 First write the symbols, this changes their values into table
301dfc71
SC
3134 indeces so we cant use it after this point
3135 */
9783e04a 3136 ieee_write_external_part (abfd);
b2c91bd9 3137 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
87f86b4e 3138
b2c91bd9
SC
3139
3140 /* ieee_write_byte(abfd, ieee_record_seperator_enum);*/
6f715d66
SC
3141
3142
3143 /*
9783e04a 3144 Write any debugs we have been told about
6f715d66 3145 */
9783e04a 3146 ieee_write_debug_part (abfd);
6f715d66 3147
9783e04a 3148 /*
301dfc71
SC
3149 Can only write the data once the symbols have been written since
3150 the data contains relocation information which points to the
9783e04a 3151 symbols
301dfc71 3152 */
9783e04a 3153 ieee_write_data_part (abfd);
b2c91bd9 3154
87f86b4e
DHW
3155
3156 /*
301dfc71
SC
3157 At the end we put the end !
3158 */
9783e04a 3159 ieee_write_me_part (abfd);
87f86b4e 3160
87f86b4e 3161
301dfc71 3162 /* Generate the header */
4002f18a
ILT
3163 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3164 return false;
87f86b4e 3165
9783e04a
DM
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 }
87f86b4e
DHW
3172 return true;
3173}
9783e04a 3174\f
87f86b4e
DHW
3175
3176
87f86b4e
DHW
3177/* Native-level interface to symbols. */
3178
3179/* We read the symbols into a buffer, which is discarded when this
3180function exits. We read the strings into a buffer large enough to
3181hold them all plus all the cached symbol entries. */
3182
3183asymbol *
57a1867e
DM
3184ieee_make_empty_symbol (abfd)
3185 bfd *abfd;
87f86b4e
DHW
3186{
3187
9783e04a
DM
3188 ieee_symbol_type *new =
3189 (ieee_symbol_type *) bfd_zmalloc (sizeof (ieee_symbol_type));
3190 if (!new)
3191 {
57a1867e 3192 bfd_set_error (bfd_error_no_error);
9783e04a
DM
3193 return NULL;
3194 }
87f86b4e
DHW
3195 new->symbol.the_bfd = abfd;
3196 return &new->symbol;
87f86b4e
DHW
3197}
3198
87f86b4e 3199static bfd *
57a1867e
DM
3200ieee_openr_next_archived_file (arch, prev)
3201 bfd *arch;
3202 bfd *prev;
87f86b4e 3203{
9783e04a 3204 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
87f86b4e 3205 /* take the next one from the arch state, or reset */
9783e04a
DM
3206 if (prev == (bfd *) NULL)
3207 {
3208 /* Reset the index - the first two entries are bogus*/
3209 ar->element_index = 2;
87f86b4e 3210 }
9783e04a
DM
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 {
57a1867e 3229 bfd_set_error (bfd_error_no_more_archived_files);
9783e04a
DM
3230 return (bfd *) NULL;
3231 }
87f86b4e 3232
9783e04a 3233 }
87f86b4e
DHW
3234}
3235
3236static boolean
9783e04a
DM
3237ieee_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;
87f86b4e
DHW
3251{
3252 return false;
87f86b4e 3253}
301dfc71 3254
301dfc71 3255static int
9783e04a
DM
3256ieee_generic_stat_arch_elt (abfd, buf)
3257 bfd *abfd;
3258 struct stat *buf;
301dfc71 3259{
9465d03e 3260 ieee_ar_data_type *ar = abfd->my_archive->tdata.ieee_ar_data;
9783e04a
DM
3261 if (ar == (ieee_ar_data_type *) NULL)
3262 {
57a1867e 3263 bfd_set_error (bfd_error_invalid_operation);
9783e04a
DM
3264 return -1;
3265 }
3266 else
3267 {
3268 buf->st_size = 0x1;
3269 buf->st_mode = 0666;
3270 return !ieee_object_p (abfd);
3271 }
301dfc71 3272}
9783e04a
DM
3273
3274static int
57a1867e
DM
3275ieee_sizeof_headers (abfd, x)
3276 bfd *abfd;
3277 boolean x;
39a2ce33 3278{
d0ec7a8e 3279 return 0;
39a2ce33
SC
3280}
3281
6f715d66 3282
6812b607
ILT
3283/* The debug info routines are never used. */
3284#if 0
3285
9783e04a 3286static void
57a1867e
DM
3287ieee_bfd_debug_info_start (abfd)
3288 bfd *abfd;
9783e04a 3289{
6f715d66 3290
9783e04a 3291}
6f715d66 3292
9783e04a 3293static void
57a1867e
DM
3294ieee_bfd_debug_info_end (abfd)
3295 bfd *abfd;
9783e04a 3296{
6f715d66 3297
9783e04a 3298}
6f715d66
SC
3299
3300
3301/* Add this section to the list of sections we have debug info for, to
9783e04a 3302 be ready to output it at close time
6f715d66 3303 */
9783e04a 3304static void
57a1867e
DM
3305ieee_bfd_debug_info_accumulate (abfd, section)
3306 bfd *abfd;
3307 asection *section;
6f715d66 3308{
9783e04a
DM
3309 ieee_data_type *ieee = IEEE_DATA (section->owner);
3310 ieee_data_type *output_ieee = IEEE_DATA (abfd);
6f715d66
SC
3311 /* can only accumulate data from other ieee bfds */
3312 if (section->owner->xvec != abfd->xvec)
3313 return;
3314 /* Only bother once per bfd */
9783e04a 3315 if (ieee->done_debug == true)
6f715d66
SC
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 */
9783e04a
DM
3325 {
3326 bfd_chain_type *n = (bfd_chain_type *) bfd_alloc (abfd, sizeof (bfd_chain_type));
3327 if (!n)
3328 {
57a1867e
DM
3329 bfd_set_error (bfd_error_no_memory);
3330 abort (); /* FIXME */
9783e04a
DM
3331 }
3332 n->this = section->owner;
3333 n->next = (bfd_chain_type *) NULL;
3334
3335 if (output_ieee->chain_head)
3336 {
6f715d66
SC
3337 output_ieee->chain_head->next = n;
3338 }
9783e04a
DM
3339 else
3340 {
6f715d66
SC
3341 output_ieee->chain_root = n;
3342
3343 }
9783e04a
DM
3344 output_ieee->chain_head = n;
3345 }
6f715d66
SC
3346}
3347
6812b607
ILT
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
6f715d66 3352
9872a49c
SC
3353#define ieee_slurp_armap bfd_true
3354#define ieee_slurp_extended_name_table bfd_true
c3246d9b
ILT
3355#define ieee_construct_extended_name_table \
3356 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
3357 bfd_true)
6812b607
ILT
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)
c3246d9b 3363#define ieee_update_armap_timestamp bfd_true
6812b607
ILT
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
c3246d9b
ILT
3368#define ieee_read_minisymbols _bfd_generic_read_minisymbols
3369#define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
6812b607
ILT
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
69e0d34d 3377#define ieee_bfd_relax_section bfd_generic_relax_section
f4bd7a8f
DM
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
c3246d9b 3381#define ieee_bfd_link_split_section _bfd_generic_link_split_section
8feff717 3382
87f86b4e 3383/*SUPPRESS 460 */
2f3508ad 3384const bfd_target ieee_vec =
87f86b4e
DHW
3385{
3386 "ieee", /* name */
01dd1b2b 3387 bfd_target_ieee_flavour,
87f86b4e
DHW
3388 true, /* target byte order */
3389 true, /* target headers byte order */
3390 (HAS_RELOC | EXEC_P | /* object flags */
3391 HAS_LINENO | HAS_DEBUG |
f4bd7a8f 3392 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
9783e04a
DM
3393 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3394 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3395 0, /* leading underscore */
87f86b4e
DHW
3396 ' ', /* ar_pad_char */
3397 16, /* ar_max_namelen */
9783e04a
DM
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 },
87f86b4e
DHW
3411 {
3412 bfd_false,
9783e04a 3413 ieee_mkobject,
87f86b4e
DHW
3414 _bfd_generic_mkarchive,
3415 bfd_false
9783e04a 3416 },
2b1d8a50
JG
3417 {
3418 bfd_false,
3419 ieee_write_object_contents,
3420 _bfd_write_archive_contents,
3421 bfd_false,
3422 },
6812b607
ILT
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),
dfc1c006 3432 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
6812b607 3433
8feff717 3434 (PTR) 0
87f86b4e 3435};
This page took 0.372032 seconds and 4 git commands to generate.