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