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