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