]> Git Repo - binutils.git/blame - bfd/ieee.c
Remove spurious whitespace introduced by previous delta.
[binutils.git] / bfd / ieee.c
CommitLineData
252b5132 1/* BFD back-end for ieee-695 objects.
6f2750fe 2 Copyright (C) 1990-2016 Free Software Foundation, Inc.
252b5132
RH
3
4 Written by Steve Chamberlain of Cygnus Support.
5
ca09e32b 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
ca09e32b
NC
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
cd123cb7 10 the Free Software Foundation; either version 3 of the License, or
ca09e32b 11 (at your option) any later version.
252b5132 12
ca09e32b
NC
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
252b5132 17
ca09e32b
NC
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
cd123cb7
NC
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
22
252b5132
RH
23
24#define KEEPMINUSPCININST 0
25
26/* IEEE 695 format is a stream of records, which we parse using a simple one-
27 token (which is one byte in this lexicon) lookahead recursive decent
28 parser. */
29
252b5132 30#include "sysdep.h"
3db64b00 31#include "bfd.h"
252b5132
RH
32#include "libbfd.h"
33#include "ieee.h"
34#include "libieee.h"
3882b010 35#include "safe-ctype.h"
1be5090b 36#include "libiberty.h"
252b5132 37
47fda0d3
AM
38struct output_buffer_struct
39{
40 unsigned char *ptrp;
41 int buffer;
42};
43
46e94266
NC
44static unsigned char *output_ptr_start;
45static unsigned char *output_ptr;
46static unsigned char *output_ptr_end;
47static unsigned char *input_ptr_start;
48static unsigned char *input_ptr;
49static unsigned char *input_ptr_end;
50static bfd *input_bfd;
51static bfd *output_bfd;
52static int output_buffer;
53
54
55static void block (void);
56
252b5132 57/* Functions for writing to ieee files in the strange way that the
c8e7bf0d 58 standard requires. */
252b5132 59
b34976b6 60static bfd_boolean
c8e7bf0d 61ieee_write_byte (bfd *abfd, int barg)
252b5132
RH
62{
63 bfd_byte byte;
64
65 byte = barg;
c8e7bf0d 66 if (bfd_bwrite ((void *) &byte, (bfd_size_type) 1, abfd) != 1)
b34976b6
AM
67 return FALSE;
68 return TRUE;
252b5132
RH
69}
70
b34976b6 71static bfd_boolean
c8e7bf0d 72ieee_write_2bytes (bfd *abfd, int bytes)
252b5132
RH
73{
74 bfd_byte buffer[2];
75
76 buffer[0] = bytes >> 8;
77 buffer[1] = bytes & 0xff;
c8e7bf0d 78 if (bfd_bwrite ((void *) buffer, (bfd_size_type) 2, abfd) != 2)
b34976b6
AM
79 return FALSE;
80 return TRUE;
252b5132
RH
81}
82
b34976b6 83static bfd_boolean
c8e7bf0d 84ieee_write_int (bfd *abfd, bfd_vma value)
252b5132
RH
85{
86 if (value <= 127)
87 {
88 if (! ieee_write_byte (abfd, (bfd_byte) value))
b34976b6 89 return FALSE;
252b5132
RH
90 }
91 else
92 {
93 unsigned int length;
94
49ae03bf
NC
95 /* How many significant bytes ? */
96 /* FIXME FOR LONGER INTS. */
252b5132
RH
97 if (value & 0xff000000)
98 length = 4;
99 else if (value & 0x00ff0000)
100 length = 3;
101 else if (value & 0x0000ff00)
102 length = 2;
103 else
104 length = 1;
105
106 if (! ieee_write_byte (abfd,
107 (bfd_byte) ((int) ieee_number_repeat_start_enum
108 + length)))
b34976b6 109 return FALSE;
252b5132
RH
110 switch (length)
111 {
112 case 4:
113 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))
b34976b6 114 return FALSE;
252b5132
RH
115 /* Fall through. */
116 case 3:
117 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))
b34976b6 118 return FALSE;
252b5132
RH
119 /* Fall through. */
120 case 2:
121 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))
b34976b6 122 return FALSE;
252b5132
RH
123 /* Fall through. */
124 case 1:
125 if (! ieee_write_byte (abfd, (bfd_byte) (value)))
b34976b6 126 return FALSE;
252b5132
RH
127 }
128 }
129
b34976b6 130 return TRUE;
252b5132
RH
131}
132
b34976b6 133static bfd_boolean
c8e7bf0d 134ieee_write_id (bfd *abfd, const char *id)
252b5132
RH
135{
136 size_t length = strlen (id);
137
138 if (length <= 127)
139 {
140 if (! ieee_write_byte (abfd, (bfd_byte) length))
b34976b6 141 return FALSE;
252b5132
RH
142 }
143 else if (length < 255)
144 {
145 if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)
146 || ! ieee_write_byte (abfd, (bfd_byte) length))
b34976b6 147 return FALSE;
252b5132
RH
148 }
149 else if (length < 65535)
150 {
151 if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)
152 || ! ieee_write_2bytes (abfd, (int) length))
b34976b6 153 return FALSE;
252b5132
RH
154 }
155 else
156 {
4eca0228 157 _bfd_error_handler
252b5132
RH
158 (_("%s: string too long (%d chars, max 65535)"),
159 bfd_get_filename (abfd), length);
160 bfd_set_error (bfd_error_invalid_operation);
b34976b6 161 return FALSE;
252b5132
RH
162 }
163
c8e7bf0d 164 if (bfd_bwrite ((void *) id, (bfd_size_type) length, abfd) != length)
b34976b6
AM
165 return FALSE;
166 return TRUE;
252b5132
RH
167}
168\f
49ae03bf
NC
169/* Functions for reading from ieee files in the strange way that the
170 standard requires. */
252b5132 171
c8e7bf0d 172#define this_byte(ieee) *((ieee)->input_p)
252b5132
RH
173#define this_byte_and_next(ieee) (*((ieee)->input_p++))
174
0a9d414a
NC
175static bfd_boolean
176next_byte (common_header_type * ieee)
177{
178 ieee->input_p++;
179
180 return ieee->input_p < ieee->last_byte;
181}
182
252b5132 183static unsigned short
c8e7bf0d 184read_2bytes (common_header_type *ieee)
252b5132
RH
185{
186 unsigned char c1 = this_byte_and_next (ieee);
187 unsigned char c2 = this_byte_and_next (ieee);
49ae03bf 188
252b5132
RH
189 return (c1 << 8) | c2;
190}
191
192static void
c8e7bf0d 193bfd_get_string (common_header_type *ieee, char *string, size_t length)
252b5132
RH
194{
195 size_t i;
49ae03bf 196
252b5132 197 for (i = 0; i < length; i++)
49ae03bf 198 string[i] = this_byte_and_next (ieee);
252b5132
RH
199}
200
201static char *
c8e7bf0d 202read_id (common_header_type *ieee)
252b5132
RH
203{
204 size_t length;
205 char *string;
49ae03bf 206
252b5132
RH
207 length = this_byte_and_next (ieee);
208 if (length <= 0x7f)
c8e7bf0d
NC
209 /* Simple string of length 0 to 127. */
210 ;
211
252b5132 212 else if (length == 0xde)
c8e7bf0d
NC
213 /* Length is next byte, allowing 0..255. */
214 length = this_byte_and_next (ieee);
215
252b5132
RH
216 else if (length == 0xdf)
217 {
49ae03bf 218 /* Length is next two bytes, allowing 0..65535. */
252b5132
RH
219 length = this_byte_and_next (ieee);
220 length = (length * 256) + this_byte_and_next (ieee);
221 }
49ae03bf
NC
222
223 /* Buy memory and read string. */
dc810e39 224 string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
252b5132
RH
225 if (!string)
226 return NULL;
227 bfd_get_string (ieee, string, length);
228 string[length] = 0;
229 return string;
230}
231
b34976b6 232static bfd_boolean
c8e7bf0d
NC
233ieee_write_expression (bfd *abfd,
234 bfd_vma value,
235 asymbol *symbol,
236 bfd_boolean pcrel,
91d6fa6a 237 unsigned int sindex)
252b5132
RH
238{
239 unsigned int term_count = 0;
240
241 if (value != 0)
242 {
243 if (! ieee_write_int (abfd, value))
b34976b6 244 return FALSE;
252b5132
RH
245 term_count++;
246 }
247
49ae03bf
NC
248 /* Badly formatted binaries can have a missing symbol,
249 so test here to prevent a seg fault. */
250 if (symbol != NULL)
252b5132 251 {
49ae03bf
NC
252 if (bfd_is_com_section (symbol->section)
253 || bfd_is_und_section (symbol->section))
252b5132 254 {
49ae03bf
NC
255 /* Def of a common symbol. */
256 if (! ieee_write_byte (abfd, ieee_variable_X_enum)
252b5132 257 || ! ieee_write_int (abfd, symbol->value))
b34976b6 258 return FALSE;
49ae03bf 259 term_count ++;
252b5132 260 }
49ae03bf 261 else if (! bfd_is_abs_section (symbol->section))
252b5132 262 {
49ae03bf 263 /* Ref to defined symbol - */
49ae03bf 264 if (symbol->flags & BSF_GLOBAL)
252b5132 265 {
49ae03bf
NC
266 if (! ieee_write_byte (abfd, ieee_variable_I_enum)
267 || ! ieee_write_int (abfd, symbol->value))
b34976b6 268 return FALSE;
252b5132
RH
269 term_count++;
270 }
49ae03bf
NC
271 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
272 {
273 /* This is a reference to a defined local symbol. We can
274 easily do a local as a section+offset. */
275 if (! ieee_write_byte (abfd, ieee_variable_R_enum)
276 || ! ieee_write_byte (abfd,
277 (bfd_byte) (symbol->section->index
278 + IEEE_SECTION_NUMBER_BASE)))
279 return FALSE;
280
281 term_count++;
282 if (symbol->value != 0)
283 {
284 if (! ieee_write_int (abfd, symbol->value))
285 return FALSE;
286 term_count++;
287 }
288 }
289 else
290 {
4eca0228 291 _bfd_error_handler
49ae03bf
NC
292 (_("%s: unrecognized symbol `%s' flags 0x%x"),
293 bfd_get_filename (abfd), bfd_asymbol_name (symbol),
294 symbol->flags);
295 bfd_set_error (bfd_error_invalid_operation);
296 return FALSE;
297 }
252b5132
RH
298 }
299 }
300
301 if (pcrel)
302 {
49ae03bf 303 /* Subtract the pc from here by asking for PC of this section. */
252b5132
RH
304 if (! ieee_write_byte (abfd, ieee_variable_P_enum)
305 || ! ieee_write_byte (abfd,
91d6fa6a 306 (bfd_byte) (sindex + IEEE_SECTION_NUMBER_BASE))
252b5132 307 || ! ieee_write_byte (abfd, ieee_function_minus_enum))
b34976b6 308 return FALSE;
252b5132
RH
309 }
310
311 /* Handle the degenerate case of a 0 address. */
312 if (term_count == 0)
49ae03bf
NC
313 if (! ieee_write_int (abfd, (bfd_vma) 0))
314 return FALSE;
252b5132
RH
315
316 while (term_count > 1)
317 {
318 if (! ieee_write_byte (abfd, ieee_function_plus_enum))
b34976b6 319 return FALSE;
252b5132
RH
320 term_count--;
321 }
322
b34976b6 323 return TRUE;
252b5132
RH
324}
325\f
49ae03bf 326/* Writes any integer into the buffer supplied and always takes 5 bytes. */
252b5132 327
252b5132 328static void
c8e7bf0d 329ieee_write_int5 (bfd_byte *buffer, bfd_vma value)
252b5132
RH
330{
331 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
332 buffer[1] = (value >> 24) & 0xff;
333 buffer[2] = (value >> 16) & 0xff;
334 buffer[3] = (value >> 8) & 0xff;
335 buffer[4] = (value >> 0) & 0xff;
336}
337
b34976b6 338static bfd_boolean
c8e7bf0d 339ieee_write_int5_out (bfd *abfd, bfd_vma value)
252b5132
RH
340{
341 bfd_byte b[5];
342
343 ieee_write_int5 (b, value);
c8e7bf0d 344 if (bfd_bwrite ((void *) b, (bfd_size_type) 5, abfd) != 5)
b34976b6
AM
345 return FALSE;
346 return TRUE;
252b5132
RH
347}
348
b34976b6 349static bfd_boolean
c8e7bf0d 350parse_int (common_header_type *ieee, bfd_vma *value_ptr)
252b5132
RH
351{
352 int value = this_byte (ieee);
353 int result;
49ae03bf 354
252b5132
RH
355 if (value >= 0 && value <= 127)
356 {
357 *value_ptr = value;
0a9d414a 358 return next_byte (ieee);
252b5132
RH
359 }
360 else if (value >= 0x80 && value <= 0x88)
361 {
362 unsigned int count = value & 0xf;
49ae03bf 363
252b5132 364 result = 0;
0a9d414a
NC
365 if (! next_byte (ieee))
366 return FALSE;
252b5132
RH
367 while (count)
368 {
369 result = (result << 8) | this_byte_and_next (ieee);
370 count--;
371 }
372 *value_ptr = result;
b34976b6 373 return TRUE;
252b5132 374 }
b34976b6 375 return FALSE;
252b5132
RH
376}
377
378static int
c8e7bf0d 379parse_i (common_header_type *ieee, bfd_boolean *ok)
252b5132 380{
1b0b5b1b 381 bfd_vma x = 0;
252b5132
RH
382 *ok = parse_int (ieee, &x);
383 return x;
384}
385
386static bfd_vma
46e94266 387must_parse_int (common_header_type *ieee)
252b5132 388{
1b0b5b1b 389 bfd_vma result = 0;
82e51918 390 BFD_ASSERT (parse_int (ieee, &result));
252b5132
RH
391 return result;
392}
393
394typedef struct
395{
396 bfd_vma value;
397 asection *section;
398 ieee_symbol_index_type symbol;
399} ieee_value_type;
400
401
402#if KEEPMINUSPCININST
403
404#define SRC_MASK(arg) arg
b34976b6 405#define PCREL_OFFSET FALSE
252b5132
RH
406
407#else
408
409#define SRC_MASK(arg) 0
b34976b6 410#define PCREL_OFFSET TRUE
252b5132
RH
411
412#endif
413
414static reloc_howto_type abs32_howto =
415 HOWTO (1,
416 0,
417 2,
418 32,
b34976b6 419 FALSE,
252b5132
RH
420 0,
421 complain_overflow_bitfield,
422 0,
423 "abs32",
b34976b6 424 TRUE,
252b5132
RH
425 0xffffffff,
426 0xffffffff,
b34976b6 427 FALSE);
252b5132
RH
428
429static reloc_howto_type abs16_howto =
430 HOWTO (1,
431 0,
432 1,
433 16,
b34976b6 434 FALSE,
252b5132
RH
435 0,
436 complain_overflow_bitfield,
437 0,
438 "abs16",
b34976b6 439 TRUE,
252b5132
RH
440 0x0000ffff,
441 0x0000ffff,
b34976b6 442 FALSE);
252b5132
RH
443
444static reloc_howto_type abs8_howto =
445 HOWTO (1,
446 0,
447 0,
448 8,
b34976b6 449 FALSE,
252b5132
RH
450 0,
451 complain_overflow_bitfield,
452 0,
453 "abs8",
b34976b6 454 TRUE,
252b5132
RH
455 0x000000ff,
456 0x000000ff,
b34976b6 457 FALSE);
252b5132
RH
458
459static reloc_howto_type rel32_howto =
460 HOWTO (1,
461 0,
462 2,
463 32,
b34976b6 464 TRUE,
252b5132
RH
465 0,
466 complain_overflow_signed,
467 0,
468 "rel32",
b34976b6 469 TRUE,
252b5132
RH
470 SRC_MASK (0xffffffff),
471 0xffffffff,
472 PCREL_OFFSET);
473
474static reloc_howto_type rel16_howto =
475 HOWTO (1,
476 0,
477 1,
478 16,
b34976b6 479 TRUE,
252b5132
RH
480 0,
481 complain_overflow_signed,
482 0,
483 "rel16",
b34976b6 484 TRUE,
252b5132
RH
485 SRC_MASK (0x0000ffff),
486 0x0000ffff,
487 PCREL_OFFSET);
488
489static reloc_howto_type rel8_howto =
490 HOWTO (1,
491 0,
492 0,
493 8,
b34976b6 494 TRUE,
252b5132
RH
495 0,
496 complain_overflow_signed,
497 0,
498 "rel8",
b34976b6 499 TRUE,
252b5132
RH
500 SRC_MASK (0x000000ff),
501 0x000000ff,
502 PCREL_OFFSET);
503
504static ieee_symbol_index_type NOSYMBOL = {0, 0};
505
0a9d414a 506static bfd_boolean
c8e7bf0d
NC
507parse_expression (ieee_data_type *ieee,
508 bfd_vma *value,
509 ieee_symbol_index_type *symbol,
510 bfd_boolean *pcrel,
511 unsigned int *extra,
512 asection **section)
252b5132
RH
513
514{
c8e7bf0d
NC
515 bfd_boolean loop = TRUE;
516 ieee_value_type stack[10];
517 ieee_value_type *sp = stack;
518 asection *dummy;
519
252b5132
RH
520#define POS sp[1]
521#define TOS sp[0]
522#define NOS sp[-1]
523#define INC sp++;
524#define DEC sp--;
525
49ae03bf 526 /* The stack pointer always points to the next unused location. */
c8e7bf0d
NC
527#define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC;
528#define POP(x,y,z) DEC; x = TOS.symbol; y = TOS.section; z = TOS.value;
252b5132 529
47fda0d3 530 while (loop && ieee->h.input_p < ieee->h.last_byte)
252b5132
RH
531 {
532 switch (this_byte (&(ieee->h)))
533 {
534 case ieee_variable_P_enum:
49ae03bf 535 /* P variable, current program counter for section n. */
252b5132
RH
536 {
537 int section_n;
49ae03bf 538
0a9d414a
NC
539 if (! next_byte (&(ieee->h)))
540 return FALSE;
b34976b6 541 *pcrel = TRUE;
252b5132 542 section_n = must_parse_int (&(ieee->h));
c7e2358a 543 (void) section_n;
252b5132
RH
544 PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
545 break;
546 }
0a9d414a 547
252b5132 548 case ieee_variable_L_enum:
49ae03bf 549 /* L variable address of section N. */
0a9d414a
NC
550 if (! next_byte (&(ieee->h)))
551 return FALSE;
252b5132
RH
552 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
553 break;
0a9d414a 554
252b5132 555 case ieee_variable_R_enum:
49ae03bf
NC
556 /* R variable, logical address of section module. */
557 /* FIXME, this should be different to L. */
0a9d414a
NC
558 if (! next_byte (&(ieee->h)))
559 return FALSE;
252b5132
RH
560 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
561 break;
0a9d414a 562
252b5132 563 case ieee_variable_S_enum:
49ae03bf 564 /* S variable, size in MAUS of section module. */
0a9d414a
NC
565 if (! next_byte (&(ieee->h)))
566 return FALSE;
252b5132
RH
567 PUSH (NOSYMBOL,
568 0,
eea6121a 569 ieee->section_table[must_parse_int (&(ieee->h))]->size);
252b5132 570 break;
0a9d414a 571
252b5132 572 case ieee_variable_I_enum:
49ae03bf 573 /* Push the address of variable n. */
252b5132
RH
574 {
575 ieee_symbol_index_type sy;
c8e7bf0d 576
0a9d414a
NC
577 if (! next_byte (&(ieee->h)))
578 return FALSE;
252b5132
RH
579 sy.index = (int) must_parse_int (&(ieee->h));
580 sy.letter = 'I';
581
582 PUSH (sy, bfd_abs_section_ptr, 0);
583 }
584 break;
0a9d414a 585
252b5132 586 case ieee_variable_X_enum:
49ae03bf 587 /* Push the address of external variable n. */
252b5132
RH
588 {
589 ieee_symbol_index_type sy;
c8e7bf0d 590
0a9d414a
NC
591 if (! next_byte (&(ieee->h)))
592 return FALSE;
593
252b5132
RH
594 sy.index = (int) (must_parse_int (&(ieee->h)));
595 sy.letter = 'X';
596
597 PUSH (sy, bfd_und_section_ptr, 0);
598 }
599 break;
0a9d414a 600
252b5132
RH
601 case ieee_function_minus_enum:
602 {
603 bfd_vma value1, value2;
604 asection *section1, *section_dummy;
605 ieee_symbol_index_type sy;
c8e7bf0d 606
0a9d414a
NC
607 if (! next_byte (&(ieee->h)))
608 return FALSE;
252b5132
RH
609
610 POP (sy, section1, value1);
611 POP (sy, section_dummy, value2);
612 PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
613 }
614 break;
0a9d414a 615
252b5132
RH
616 case ieee_function_plus_enum:
617 {
618 bfd_vma value1, value2;
619 asection *section1;
620 asection *section2;
621 ieee_symbol_index_type sy1;
622 ieee_symbol_index_type sy2;
c8e7bf0d 623
0a9d414a
NC
624 if (! next_byte (&(ieee->h)))
625 return FALSE;
252b5132
RH
626
627 POP (sy1, section1, value1);
628 POP (sy2, section2, value2);
629 PUSH (sy1.letter ? sy1 : sy2,
630 bfd_is_abs_section (section1) ? section2 : section1,
631 value1 + value2);
632 }
633 break;
0a9d414a 634
252b5132
RH
635 default:
636 {
637 bfd_vma va;
c8e7bf0d 638
252b5132
RH
639 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
640 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
641 if (parse_int (&(ieee->h), &va))
642 {
643 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
644 }
645 else
c8e7bf0d
NC
646 /* Thats all that we can understand. */
647 loop = FALSE;
252b5132
RH
648 }
649 }
650 }
47fda0d3
AM
651
652 /* As far as I can see there is a bug in the Microtec IEEE output
653 which I'm using to scan, whereby the comma operator is omitted
654 sometimes in an expression, giving expressions with too many
655 terms. We can tell if that's the case by ensuring that
656 sp == stack here. If not, then we've pushed something too far,
657 so we keep adding. */
47fda0d3
AM
658 while (sp != stack + 1)
659 {
660 asection *section1;
661 ieee_symbol_index_type sy1;
c8e7bf0d 662
47fda0d3 663 POP (sy1, section1, *extra);
c7e2358a
AM
664 (void) section1;
665 (void) sy1;
47fda0d3
AM
666 }
667
668 POP (*symbol, dummy, *value);
669 if (section)
670 *section = dummy;
252b5132 671
0a9d414a
NC
672 return TRUE;
673}
47fda0d3
AM
674
675#define ieee_pos(ieee) \
676 (ieee->h.input_p - ieee->h.first_byte)
252b5132 677
47fda0d3
AM
678/* Find the first part of the ieee file after HERE. */
679
680static file_ptr
c8e7bf0d 681ieee_part_after (ieee_data_type *ieee, file_ptr here)
47fda0d3
AM
682{
683 int part;
684 file_ptr after = ieee->w.r.me_record;
685
686 /* File parts can come in any order, except that module end is
687 guaranteed to be last (and the header first). */
688 for (part = 0; part < N_W_VARIABLES; part++)
689 if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
690 after = ieee->w.offset[part];
691
692 return after;
693}
252b5132 694
0a9d414a
NC
695static bfd_boolean
696ieee_seek (ieee_data_type * ieee, file_ptr offset)
697{
698 /* PR 17512: file: 017-1157-0.004. */
699 if (offset < 0 || (bfd_size_type) offset >= ieee->h.total_amt)
700 {
701 ieee->h.input_p = ieee->h.first_byte + ieee->h.total_amt;
702 ieee->h.last_byte = ieee->h.input_p;
703 return FALSE;
704 }
705
706 ieee->h.input_p = ieee->h.first_byte + offset;
707 ieee->h.last_byte = (ieee->h.first_byte + ieee_part_after (ieee, offset));
708 return TRUE;
709}
710
252b5132 711static unsigned int last_index;
49ae03bf 712static char last_type; /* Is the index for an X or a D. */
252b5132
RH
713
714static ieee_symbol_type *
c8e7bf0d
NC
715get_symbol (bfd *abfd ATTRIBUTE_UNUSED,
716 ieee_data_type *ieee,
717 ieee_symbol_type *last_symbol,
718 unsigned int *symbol_count,
719 ieee_symbol_type ***pptr,
720 unsigned int *max_index,
721 int this_type)
252b5132 722{
49ae03bf 723 /* Need a new symbol. */
252b5132 724 unsigned int new_index = must_parse_int (&(ieee->h));
49ae03bf 725
252b5132
RH
726 if (new_index != last_index || this_type != last_type)
727 {
dc810e39
AM
728 ieee_symbol_type *new_symbol;
729 bfd_size_type amt = sizeof (ieee_symbol_type);
730
c8e7bf0d 731 new_symbol = bfd_alloc (ieee->h.abfd, amt);
252b5132
RH
732 if (!new_symbol)
733 return NULL;
734
735 new_symbol->index = new_index;
736 last_index = new_index;
737 (*symbol_count)++;
738 **pptr = new_symbol;
739 *pptr = &new_symbol->next;
740 if (new_index > *max_index)
49ae03bf
NC
741 *max_index = new_index;
742
252b5132
RH
743 last_type = this_type;
744 new_symbol->symbol.section = bfd_abs_section_ptr;
745 return new_symbol;
746 }
747 return last_symbol;
748}
749
b34976b6 750static bfd_boolean
c8e7bf0d 751ieee_slurp_external_symbols (bfd *abfd)
252b5132
RH
752{
753 ieee_data_type *ieee = IEEE_DATA (abfd);
754 file_ptr offset = ieee->w.r.external_part;
755
756 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
757 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
c8e7bf0d 758 ieee_symbol_type *symbol = NULL;
252b5132 759 unsigned int symbol_count = 0;
b34976b6 760 bfd_boolean loop = TRUE;
c8e7bf0d 761
252b5132 762 last_index = 0xffffff;
b34976b6 763 ieee->symbol_table_full = TRUE;
252b5132 764
0a9d414a
NC
765 if (! ieee_seek (ieee, offset))
766 return FALSE;
252b5132
RH
767
768 while (loop)
769 {
770 switch (this_byte (&(ieee->h)))
771 {
772 case ieee_nn_record:
0a9d414a
NC
773 if (! next_byte (&(ieee->h)))
774 return FALSE;
252b5132
RH
775
776 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
c8e7bf0d
NC
777 & prev_symbols_ptr,
778 & ieee->external_symbol_max_index, 'I');
252b5132 779 if (symbol == NULL)
b34976b6 780 return FALSE;
252b5132
RH
781
782 symbol->symbol.the_bfd = abfd;
783 symbol->symbol.name = read_id (&(ieee->h));
c8e7bf0d 784 symbol->symbol.udata.p = NULL;
252b5132
RH
785 symbol->symbol.flags = BSF_NO_FLAGS;
786 break;
0a9d414a 787
252b5132 788 case ieee_external_symbol_enum:
0a9d414a
NC
789 if (! next_byte (&(ieee->h)))
790 return FALSE;
252b5132
RH
791
792 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
793 &prev_symbols_ptr,
794 &ieee->external_symbol_max_index, 'D');
795 if (symbol == NULL)
b34976b6 796 return FALSE;
252b5132
RH
797
798 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
799
800 symbol->symbol.the_bfd = abfd;
801 symbol->symbol.name = read_id (&(ieee->h));
c8e7bf0d 802 symbol->symbol.udata.p = NULL;
252b5132
RH
803 symbol->symbol.flags = BSF_NO_FLAGS;
804 break;
805 case ieee_attribute_record_enum >> 8:
806 {
807 unsigned int symbol_name_index;
808 unsigned int symbol_type_index;
809 unsigned int symbol_attribute_def;
1b0b5b1b 810 bfd_vma value = 0;
c8e7bf0d 811
47fda0d3 812 switch (read_2bytes (&ieee->h))
252b5132
RH
813 {
814 case ieee_attribute_record_enum:
815 symbol_name_index = must_parse_int (&(ieee->h));
816 symbol_type_index = must_parse_int (&(ieee->h));
c7e2358a 817 (void) symbol_type_index;
252b5132
RH
818 symbol_attribute_def = must_parse_int (&(ieee->h));
819 switch (symbol_attribute_def)
820 {
821 case 8:
822 case 19:
823 parse_int (&ieee->h, &value);
824 break;
825 default:
4eca0228 826 _bfd_error_handler
d003868e
AM
827 (_("%B: unimplemented ATI record %u for symbol %u"),
828 abfd, symbol_attribute_def, symbol_name_index);
252b5132 829 bfd_set_error (bfd_error_bad_value);
b34976b6 830 return FALSE;
252b5132
RH
831 break;
832 }
833 break;
834 case ieee_external_reference_info_record_enum:
49ae03bf 835 /* Skip over ATX record. */
252b5132
RH
836 parse_int (&(ieee->h), &value);
837 parse_int (&(ieee->h), &value);
838 parse_int (&(ieee->h), &value);
839 parse_int (&(ieee->h), &value);
840 break;
841 case ieee_atn_record_enum:
842 /* We may get call optimization information here,
843 which we just ignore. The format is
49ae03bf 844 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */
252b5132
RH
845 parse_int (&ieee->h, &value);
846 parse_int (&ieee->h, &value);
847 parse_int (&ieee->h, &value);
848 if (value != 0x3f)
849 {
4eca0228 850 _bfd_error_handler
d003868e
AM
851 (_("%B: unexpected ATN type %d in external part"),
852 abfd, (int) value);
252b5132 853 bfd_set_error (bfd_error_bad_value);
b34976b6 854 return FALSE;
252b5132
RH
855 }
856 parse_int (&ieee->h, &value);
857 parse_int (&ieee->h, &value);
858 while (value > 0)
859 {
860 bfd_vma val1;
861
862 --value;
863
47fda0d3 864 switch (read_2bytes (&ieee->h))
252b5132
RH
865 {
866 case ieee_asn_record_enum:
867 parse_int (&ieee->h, &val1);
868 parse_int (&ieee->h, &val1);
869 break;
870
871 default:
4eca0228 872 _bfd_error_handler
d003868e 873 (_("%B: unexpected type after ATN"), abfd);
252b5132 874 bfd_set_error (bfd_error_bad_value);
b34976b6 875 return FALSE;
252b5132
RH
876 }
877 }
878 }
879 }
880 break;
0a9d414a 881
252b5132
RH
882 case ieee_value_record_enum >> 8:
883 {
884 unsigned int symbol_name_index;
885 ieee_symbol_index_type symbol_ignore;
b34976b6 886 bfd_boolean pcrel_ignore;
252b5132 887 unsigned int extra;
c8e7bf0d 888
0a9d414a
NC
889 if (! next_byte (&(ieee->h)))
890 return FALSE;
891 if (! next_byte (&(ieee->h)))
892 return FALSE;
252b5132
RH
893
894 symbol_name_index = must_parse_int (&(ieee->h));
c7e2358a 895 (void) symbol_name_index;
0a9d414a
NC
896 if (! parse_expression (ieee,
897 &symbol->symbol.value,
898 &symbol_ignore,
899 &pcrel_ignore,
900 &extra,
901 &symbol->symbol.section))
902 return FALSE;
252b5132
RH
903
904 /* Fully linked IEEE-695 files tend to give every symbol
905 an absolute value. Try to convert that back into a
906 section relative value. FIXME: This won't always to
907 the right thing. */
908 if (bfd_is_abs_section (symbol->symbol.section)
909 && (abfd->flags & HAS_RELOC) == 0)
910 {
911 bfd_vma val;
912 asection *s;
913
914 val = symbol->symbol.value;
915 for (s = abfd->sections; s != NULL; s = s->next)
916 {
eea6121a 917 if (val >= s->vma && val < s->vma + s->size)
252b5132
RH
918 {
919 symbol->symbol.section = s;
920 symbol->symbol.value -= s->vma;
921 break;
922 }
923 }
924 }
925
926 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
927
928 }
929 break;
930 case ieee_weak_external_reference_enum:
931 {
932 bfd_vma size;
933 bfd_vma value;
c8e7bf0d 934
0a9d414a
NC
935 if (! next_byte (&(ieee->h)))
936 return FALSE;
937
49ae03bf 938 /* Throw away the external reference index. */
252b5132 939 (void) must_parse_int (&(ieee->h));
49ae03bf 940 /* Fetch the default size if not resolved. */
252b5132 941 size = must_parse_int (&(ieee->h));
7dee875e 942 /* Fetch the default value if available. */
82e51918 943 if (! parse_int (&(ieee->h), &value))
c8e7bf0d 944 value = 0;
49ae03bf 945 /* This turns into a common. */
252b5132
RH
946 symbol->symbol.section = bfd_com_section_ptr;
947 symbol->symbol.value = size;
948 }
949 break;
950
951 case ieee_external_reference_enum:
0a9d414a
NC
952 if (! next_byte (&(ieee->h)))
953 return FALSE;
252b5132
RH
954
955 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
956 &prev_reference_ptr,
957 &ieee->external_reference_max_index, 'X');
958 if (symbol == NULL)
b34976b6 959 return FALSE;
252b5132
RH
960
961 symbol->symbol.the_bfd = abfd;
962 symbol->symbol.name = read_id (&(ieee->h));
c8e7bf0d 963 symbol->symbol.udata.p = NULL;
252b5132
RH
964 symbol->symbol.section = bfd_und_section_ptr;
965 symbol->symbol.value = (bfd_vma) 0;
966 symbol->symbol.flags = 0;
967
968 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
969 break;
970
971 default:
b34976b6 972 loop = FALSE;
252b5132
RH
973 }
974 }
975
976 if (ieee->external_symbol_max_index != 0)
977 {
978 ieee->external_symbol_count =
979 ieee->external_symbol_max_index -
980 ieee->external_symbol_min_index + 1;
981 }
982 else
c8e7bf0d 983 ieee->external_symbol_count = 0;
252b5132
RH
984
985 if (ieee->external_reference_max_index != 0)
986 {
987 ieee->external_reference_count =
988 ieee->external_reference_max_index -
989 ieee->external_reference_min_index + 1;
990 }
991 else
c8e7bf0d 992 ieee->external_reference_count = 0;
252b5132
RH
993
994 abfd->symcount =
995 ieee->external_reference_count + ieee->external_symbol_count;
996
997 if (symbol_count != abfd->symcount)
c8e7bf0d
NC
998 /* There are gaps in the table -- */
999 ieee->symbol_table_full = FALSE;
252b5132 1000
c8e7bf0d
NC
1001 *prev_symbols_ptr = NULL;
1002 *prev_reference_ptr = NULL;
252b5132 1003
b34976b6 1004 return TRUE;
252b5132
RH
1005}
1006
b34976b6 1007static bfd_boolean
c8e7bf0d 1008ieee_slurp_symbol_table (bfd *abfd)
252b5132 1009{
82e51918 1010 if (! IEEE_DATA (abfd)->read_symbols)
252b5132
RH
1011 {
1012 if (! ieee_slurp_external_symbols (abfd))
b34976b6
AM
1013 return FALSE;
1014 IEEE_DATA (abfd)->read_symbols = TRUE;
252b5132 1015 }
b34976b6 1016 return TRUE;
252b5132
RH
1017}
1018
47fda0d3 1019static long
46e94266 1020ieee_get_symtab_upper_bound (bfd *abfd)
252b5132
RH
1021{
1022 if (! ieee_slurp_symbol_table (abfd))
1023 return -1;
1024
1025 return (abfd->symcount != 0) ?
1026 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
1027}
1028
49ae03bf
NC
1029/* Move from our internal lists to the canon table, and insert in
1030 symbol index order. */
252b5132
RH
1031
1032extern const bfd_target ieee_vec;
1033
47fda0d3 1034static long
c8e7bf0d 1035ieee_canonicalize_symtab (bfd *abfd, asymbol **location)
252b5132
RH
1036{
1037 ieee_symbol_type *symp;
1038 static bfd dummy_bfd;
1039 static asymbol empty_symbol =
dcdea4f4
AM
1040 {
1041 &dummy_bfd,
1042 " ieee empty",
1043 (symvalue) 0,
1044 BSF_DEBUGGING,
1045 bfd_abs_section_ptr
1046#ifdef __STDC__
1047 /* K&R compilers can't initialise unions. */
1048 , { 0 }
1049#endif
1050 };
252b5132
RH
1051
1052 if (abfd->symcount)
1053 {
1054 ieee_data_type *ieee = IEEE_DATA (abfd);
c8e7bf0d 1055
252b5132
RH
1056 dummy_bfd.xvec = &ieee_vec;
1057 if (! ieee_slurp_symbol_table (abfd))
1058 return -1;
1059
82e51918 1060 if (! ieee->symbol_table_full)
252b5132 1061 {
49ae03bf
NC
1062 /* Arrgh - there are gaps in the table, run through and fill them
1063 up with pointers to a null place. */
252b5132 1064 unsigned int i;
49ae03bf 1065
252b5132 1066 for (i = 0; i < abfd->symcount; i++)
49ae03bf 1067 location[i] = &empty_symbol;
252b5132
RH
1068 }
1069
1070 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
1071 for (symp = IEEE_DATA (abfd)->external_symbols;
1072 symp != (ieee_symbol_type *) NULL;
1073 symp = symp->next)
49ae03bf
NC
1074 /* Place into table at correct index locations. */
1075 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
252b5132 1076
49ae03bf 1077 /* The external refs are indexed in a bit. */
252b5132
RH
1078 ieee->external_reference_base_offset =
1079 -ieee->external_reference_min_index + ieee->external_symbol_count;
1080
1081 for (symp = IEEE_DATA (abfd)->external_reference;
1082 symp != (ieee_symbol_type *) NULL;
1083 symp = symp->next)
49ae03bf
NC
1084 location[symp->index + ieee->external_reference_base_offset] =
1085 &symp->symbol;
252b5132 1086 }
49ae03bf 1087
252b5132 1088 if (abfd->symcount)
49ae03bf
NC
1089 location[abfd->symcount] = (asymbol *) NULL;
1090
252b5132
RH
1091 return abfd->symcount;
1092}
1093
1094static asection *
91d6fa6a 1095get_section_entry (bfd *abfd, ieee_data_type *ieee, unsigned int sindex)
252b5132 1096{
91d6fa6a 1097 if (sindex >= ieee->section_table_size)
252b5132
RH
1098 {
1099 unsigned int c, i;
1100 asection **n;
dc810e39 1101 bfd_size_type amt;
252b5132
RH
1102
1103 c = ieee->section_table_size;
1104 if (c == 0)
1105 c = 20;
91d6fa6a 1106 while (c <= sindex)
252b5132
RH
1107 c *= 2;
1108
dc810e39
AM
1109 amt = c;
1110 amt *= sizeof (asection *);
c8e7bf0d 1111 n = bfd_realloc (ieee->section_table, amt);
252b5132
RH
1112 if (n == NULL)
1113 return NULL;
1114
1115 for (i = ieee->section_table_size; i < c; i++)
1116 n[i] = NULL;
1117
1118 ieee->section_table = n;
1119 ieee->section_table_size = c;
1120 }
1121
91d6fa6a 1122 if (ieee->section_table[sindex] == (asection *) NULL)
252b5132 1123 {
dc810e39 1124 char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
252b5132
RH
1125 asection *section;
1126
1127 if (!tmp)
1128 return NULL;
91d6fa6a 1129 sprintf (tmp, " fsec%4d", sindex);
252b5132 1130 section = bfd_make_section (abfd, tmp);
91d6fa6a
NC
1131 ieee->section_table[sindex] = section;
1132 section->target_index = sindex;
1133 ieee->section_table[sindex] = section;
252b5132 1134 }
91d6fa6a 1135 return ieee->section_table[sindex];
252b5132
RH
1136}
1137
0a9d414a 1138static bfd_boolean
c8e7bf0d 1139ieee_slurp_sections (bfd *abfd)
252b5132
RH
1140{
1141 ieee_data_type *ieee = IEEE_DATA (abfd);
1142 file_ptr offset = ieee->w.r.section_part;
252b5132
RH
1143 char *name;
1144
1145 if (offset != 0)
1146 {
1147 bfd_byte section_type[3];
c8e7bf0d 1148
0a9d414a
NC
1149 if (! ieee_seek (ieee, offset))
1150 return FALSE;
1151
b34976b6 1152 while (TRUE)
252b5132
RH
1153 {
1154 switch (this_byte (&(ieee->h)))
1155 {
1156 case ieee_section_type_enum:
1157 {
dc810e39 1158 asection *section;
252b5132 1159 unsigned int section_index;
c8e7bf0d 1160
0a9d414a
NC
1161 if (! next_byte (&(ieee->h)))
1162 return FALSE;
252b5132
RH
1163 section_index = must_parse_int (&(ieee->h));
1164
1165 section = get_section_entry (abfd, ieee, section_index);
1166
1167 section_type[0] = this_byte_and_next (&(ieee->h));
1168
1169 /* Set minimal section attributes. Attributes are
49ae03bf 1170 extended later, based on section contents. */
252b5132
RH
1171 switch (section_type[0])
1172 {
1173 case 0xC1:
49ae03bf 1174 /* Normal attributes for absolute sections. */
252b5132
RH
1175 section_type[1] = this_byte (&(ieee->h));
1176 section->flags = SEC_ALLOC;
1177 switch (section_type[1])
1178 {
c8e7bf0d
NC
1179 /* AS Absolute section attributes. */
1180 case 0xD3:
0a9d414a
NC
1181 if (! next_byte (&(ieee->h)))
1182 return FALSE;
252b5132
RH
1183 section_type[2] = this_byte (&(ieee->h));
1184 switch (section_type[2])
1185 {
1186 case 0xD0:
49ae03bf 1187 /* Normal code. */
0a9d414a
NC
1188 if (! next_byte (&(ieee->h)))
1189 return FALSE;
252b5132
RH
1190 section->flags |= SEC_CODE;
1191 break;
1192 case 0xC4:
49ae03bf 1193 /* Normal data. */
0a9d414a
NC
1194 if (! next_byte (&(ieee->h)))
1195 return FALSE;
252b5132
RH
1196 section->flags |= SEC_DATA;
1197 break;
1198 case 0xD2:
0a9d414a
NC
1199 if (! next_byte (&(ieee->h)))
1200 return FALSE;
49ae03bf 1201 /* Normal rom data. */
252b5132
RH
1202 section->flags |= SEC_ROM | SEC_DATA;
1203 break;
1204 default:
1205 break;
1206 }
1207 }
1208 break;
c8e7bf0d
NC
1209
1210 /* Named relocatable sections (type C). */
1211 case 0xC3:
252b5132
RH
1212 section_type[1] = this_byte (&(ieee->h));
1213 section->flags = SEC_ALLOC;
1214 switch (section_type[1])
1215 {
49ae03bf 1216 case 0xD0: /* Normal code (CP). */
0a9d414a
NC
1217 if (! next_byte (&(ieee->h)))
1218 return FALSE;
252b5132
RH
1219 section->flags |= SEC_CODE;
1220 break;
49ae03bf 1221 case 0xC4: /* Normal data (CD). */
0a9d414a
NC
1222 if (! next_byte (&(ieee->h)))
1223 return FALSE;
252b5132
RH
1224 section->flags |= SEC_DATA;
1225 break;
49ae03bf 1226 case 0xD2: /* Normal rom data (CR). */
0a9d414a
NC
1227 if (! next_byte (&(ieee->h)))
1228 return FALSE;
252b5132
RH
1229 section->flags |= SEC_ROM | SEC_DATA;
1230 break;
1231 default:
1232 break;
1233 }
1234 }
1235
49ae03bf 1236 /* Read section name, use it if non empty. */
252b5132
RH
1237 name = read_id (&ieee->h);
1238 if (name[0])
1239 section->name = name;
1240
49ae03bf 1241 /* Skip these fields, which we don't care about. */
252b5132
RH
1242 {
1243 bfd_vma parent, brother, context;
c8e7bf0d 1244
252b5132
RH
1245 parse_int (&(ieee->h), &parent);
1246 parse_int (&(ieee->h), &brother);
1247 parse_int (&(ieee->h), &context);
1248 }
1249 }
1250 break;
1251 case ieee_section_alignment_enum:
1252 {
1253 unsigned int section_index;
1254 bfd_vma value;
1255 asection *section;
c8e7bf0d 1256
0a9d414a
NC
1257 if (! next_byte (&(ieee->h)))
1258 return FALSE;
252b5132
RH
1259 section_index = must_parse_int (&ieee->h);
1260 section = get_section_entry (abfd, ieee, section_index);
1261 if (section_index > ieee->section_count)
c8e7bf0d
NC
1262 ieee->section_count = section_index;
1263
252b5132
RH
1264 section->alignment_power =
1265 bfd_log2 (must_parse_int (&ieee->h));
1266 (void) parse_int (&(ieee->h), &value);
1267 }
1268 break;
1269 case ieee_e2_first_byte_enum:
1270 {
dc810e39
AM
1271 asection *section;
1272 ieee_record_enum_type t;
252b5132 1273
dc810e39 1274 t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
252b5132
RH
1275 switch (t)
1276 {
1277 case ieee_section_size_enum:
1278 section = ieee->section_table[must_parse_int (&(ieee->h))];
eea6121a 1279 section->size = must_parse_int (&(ieee->h));
252b5132
RH
1280 break;
1281 case ieee_physical_region_size_enum:
1282 section = ieee->section_table[must_parse_int (&(ieee->h))];
eea6121a 1283 section->size = must_parse_int (&(ieee->h));
252b5132
RH
1284 break;
1285 case ieee_region_base_address_enum:
1286 section = ieee->section_table[must_parse_int (&(ieee->h))];
1287 section->vma = must_parse_int (&(ieee->h));
1288 section->lma = section->vma;
1289 break;
1290 case ieee_mau_size_enum:
1291 must_parse_int (&(ieee->h));
1292 must_parse_int (&(ieee->h));
1293 break;
1294 case ieee_m_value_enum:
1295 must_parse_int (&(ieee->h));
1296 must_parse_int (&(ieee->h));
1297 break;
1298 case ieee_section_base_address_enum:
1299 section = ieee->section_table[must_parse_int (&(ieee->h))];
1300 section->vma = must_parse_int (&(ieee->h));
1301 section->lma = section->vma;
1302 break;
1303 case ieee_section_offset_enum:
1304 (void) must_parse_int (&(ieee->h));
1305 (void) must_parse_int (&(ieee->h));
1306 break;
1307 default:
0a9d414a 1308 return TRUE;
252b5132
RH
1309 }
1310 }
1311 break;
1312 default:
0a9d414a 1313 return TRUE;
252b5132
RH
1314 }
1315 }
1316 }
0a9d414a
NC
1317
1318 return TRUE;
252b5132
RH
1319}
1320
1321/* Make a section for the debugging information, if any. We don't try
1322 to interpret the debugging information; we just point the section
1323 at the area in the file so that program which understand can dig it
1324 out. */
1325
b34976b6 1326static bfd_boolean
c8e7bf0d 1327ieee_slurp_debug (bfd *abfd)
252b5132
RH
1328{
1329 ieee_data_type *ieee = IEEE_DATA (abfd);
1330 asection *sec;
a8c5faf7 1331 file_ptr debug_end;
117ed4f8 1332 flagword flags;
252b5132
RH
1333
1334 if (ieee->w.r.debug_information_part == 0)
b34976b6 1335 return TRUE;
252b5132 1336
117ed4f8
AM
1337 flags = SEC_DEBUGGING | SEC_HAS_CONTENTS;
1338 sec = bfd_make_section_with_flags (abfd, ".debug", flags);
252b5132 1339 if (sec == NULL)
b34976b6 1340 return FALSE;
252b5132 1341 sec->filepos = ieee->w.r.debug_information_part;
a8c5faf7 1342
47fda0d3 1343 debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
eea6121a 1344 sec->size = debug_end - ieee->w.r.debug_information_part;
252b5132 1345
b34976b6 1346 return TRUE;
252b5132
RH
1347}
1348\f
49ae03bf 1349/* Archive stuff. */
252b5132 1350
46e94266 1351static const bfd_target *
c8e7bf0d 1352ieee_archive_p (bfd *abfd)
252b5132
RH
1353{
1354 char *library;
1355 unsigned int i;
1356 unsigned char buffer[512];
1357 file_ptr buffer_offset = 0;
1358 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1359 ieee_ar_data_type *ieee;
dc810e39 1360 bfd_size_type alc_elts;
252b5132 1361 ieee_ar_obstack_type *elts = NULL;
dc810e39 1362 bfd_size_type amt = sizeof (ieee_ar_data_type);
252b5132 1363
c8e7bf0d 1364 abfd->tdata.ieee_ar_data = bfd_alloc (abfd, amt);
252b5132 1365 if (!abfd->tdata.ieee_ar_data)
487e54f2 1366 goto error_ret_restore;
252b5132
RH
1367 ieee = IEEE_AR_DATA (abfd);
1368
47fda0d3
AM
1369 /* Ignore the return value here. It doesn't matter if we don't read
1370 the entire buffer. We might have a very small ieee file. */
041830e0
NC
1371 if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0)
1372 goto got_wrong_format_error;
252b5132
RH
1373
1374 ieee->h.first_byte = buffer;
1375 ieee->h.input_p = buffer;
1376
1377 ieee->h.abfd = abfd;
1378
1379 if (this_byte (&(ieee->h)) != Module_Beginning)
c4920b97 1380 goto got_wrong_format_error;
252b5132 1381
0a9d414a
NC
1382 (void) next_byte (&(ieee->h));
1383
252b5132
RH
1384 library = read_id (&(ieee->h));
1385 if (strcmp (library, "LIBRARY") != 0)
c4920b97
NC
1386 goto got_wrong_format_error;
1387
1388 /* Throw away the filename. */
252b5132
RH
1389 read_id (&(ieee->h));
1390
1391 ieee->element_count = 0;
1392 ieee->element_index = 0;
1393
0a9d414a 1394 (void) next_byte (&(ieee->h)); /* Drop the ad part. */
c4920b97 1395 must_parse_int (&(ieee->h)); /* And the two dummy numbers. */
252b5132
RH
1396 must_parse_int (&(ieee->h));
1397
1398 alc_elts = 10;
c8e7bf0d 1399 elts = bfd_malloc (alc_elts * sizeof *elts);
252b5132
RH
1400 if (elts == NULL)
1401 goto error_return;
1402
c4920b97 1403 /* Read the index of the BB table. */
252b5132
RH
1404 while (1)
1405 {
1406 int rec;
1407 ieee_ar_obstack_type *t;
1408
1409 rec = read_2bytes (&(ieee->h));
1410 if (rec != (int) ieee_assign_value_to_variable_enum)
1411 break;
1412
1413 if (ieee->element_count >= alc_elts)
1414 {
1415 ieee_ar_obstack_type *n;
1416
1417 alc_elts *= 2;
c8e7bf0d 1418 n = bfd_realloc (elts, alc_elts * sizeof (* elts));
252b5132
RH
1419 if (n == NULL)
1420 goto error_return;
1421 elts = n;
1422 }
1423
1424 t = &elts[ieee->element_count];
1425 ieee->element_count++;
1426
1427 must_parse_int (&(ieee->h));
1428 t->file_offset = must_parse_int (&(ieee->h));
1429 t->abfd = (bfd *) NULL;
1430
c4920b97 1431 /* Make sure that we don't go over the end of the buffer. */
47fda0d3 1432 if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
252b5132 1433 {
c4920b97 1434 /* Past half way, reseek and reprime. */
47fda0d3 1435 buffer_offset += ieee_pos (IEEE_DATA (abfd));
252b5132
RH
1436 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1437 goto error_return;
c4920b97 1438
dc810e39 1439 /* Again ignore return value of bfd_bread. */
c8e7bf0d 1440 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
252b5132
RH
1441 ieee->h.first_byte = buffer;
1442 ieee->h.input_p = buffer;
1443 }
1444 }
1445
dc810e39
AM
1446 amt = ieee->element_count;
1447 amt *= sizeof *ieee->elements;
c8e7bf0d 1448 ieee->elements = bfd_alloc (abfd, amt);
252b5132
RH
1449 if (ieee->elements == NULL)
1450 goto error_return;
c4920b97 1451
dc810e39 1452 memcpy (ieee->elements, elts, (size_t) amt);
252b5132
RH
1453 free (elts);
1454 elts = NULL;
1455
c4920b97 1456 /* Now scan the area again, and replace BB offsets with file offsets. */
252b5132
RH
1457 for (i = 2; i < ieee->element_count; i++)
1458 {
1459 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1460 goto error_return;
c4920b97 1461
dc810e39 1462 /* Again ignore return value of bfd_bread. */
c8e7bf0d 1463 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
252b5132
RH
1464 ieee->h.first_byte = buffer;
1465 ieee->h.input_p = buffer;
1466
0a9d414a
NC
1467 (void) next_byte (&(ieee->h)); /* Drop F8. */
1468 if (! next_byte (&(ieee->h))) /* Drop 14. */
1469 goto error_return;
c4920b97 1470 must_parse_int (&(ieee->h)); /* Drop size of block. */
dc810e39 1471
252b5132 1472 if (must_parse_int (&(ieee->h)) != 0)
c4920b97
NC
1473 /* This object has been deleted. */
1474 ieee->elements[i].file_offset = 0;
252b5132 1475 else
c4920b97 1476 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
252b5132
RH
1477 }
1478
1479 /* abfd->has_armap = ;*/
1480
1481 return abfd->xvec;
1482
911c6dae
AM
1483 got_wrong_format_error:
1484 bfd_set_error (bfd_error_wrong_format);
252b5132
RH
1485 error_return:
1486 if (elts != NULL)
1487 free (elts);
487e54f2
AM
1488 bfd_release (abfd, ieee);
1489 error_ret_restore:
1490 abfd->tdata.ieee_ar_data = save;
c4920b97 1491
252b5132
RH
1492 return NULL;
1493}
1494
46e94266
NC
1495static bfd_boolean
1496ieee_mkobject (bfd *abfd)
252b5132 1497{
dc810e39 1498 bfd_size_type amt;
252b5132 1499
46e94266
NC
1500 output_ptr_start = NULL;
1501 output_ptr = NULL;
1502 output_ptr_end = NULL;
1503 input_ptr_start = NULL;
1504 input_ptr = NULL;
1505 input_ptr_end = NULL;
1506 input_bfd = NULL;
1507 output_bfd = NULL;
1508 output_buffer = 0;
1509 amt = sizeof (ieee_data_type);
1510 abfd->tdata.ieee_data = bfd_zalloc (abfd, amt);
1511 return abfd->tdata.ieee_data != NULL;
252b5132
RH
1512}
1513
b34976b6 1514static bfd_boolean
c8e7bf0d
NC
1515do_one (ieee_data_type *ieee,
1516 ieee_per_section_type *current_map,
1517 unsigned char *location_ptr,
1518 asection *s,
1519 int iterations)
252b5132
RH
1520{
1521 switch (this_byte (&(ieee->h)))
1522 {
1523 case ieee_load_constant_bytes_enum:
1524 {
1525 unsigned int number_of_maus;
1526 unsigned int i;
49ae03bf 1527
0a9d414a
NC
1528 if (! next_byte (&(ieee->h)))
1529 return FALSE;
252b5132
RH
1530 number_of_maus = must_parse_int (&(ieee->h));
1531
1532 for (i = 0; i < number_of_maus; i++)
1533 {
1534 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1535 next_byte (&(ieee->h));
1536 }
1537 }
1538 break;
1539
1540 case ieee_load_with_relocation_enum:
1541 {
b34976b6 1542 bfd_boolean loop = TRUE;
49ae03bf 1543
0a9d414a
NC
1544 if (! next_byte (&(ieee->h)))
1545 return FALSE;
252b5132
RH
1546 while (loop)
1547 {
1548 switch (this_byte (&(ieee->h)))
1549 {
1550 case ieee_variable_R_enum:
1551
1552 case ieee_function_signed_open_b_enum:
1553 case ieee_function_unsigned_open_b_enum:
1554 case ieee_function_either_open_b_enum:
1555 {
1556 unsigned int extra = 4;
b34976b6 1557 bfd_boolean pcrel = FALSE;
252b5132 1558 asection *section;
dc810e39 1559 ieee_reloc_type *r;
dc810e39 1560
116c20d2 1561 r = bfd_alloc (ieee->h.abfd, sizeof (* r));
252b5132 1562 if (!r)
b34976b6 1563 return FALSE;
252b5132
RH
1564
1565 *(current_map->reloc_tail_ptr) = r;
1566 current_map->reloc_tail_ptr = &r->next;
1567 r->next = (ieee_reloc_type *) NULL;
0a9d414a
NC
1568 if (! next_byte (&(ieee->h)))
1569 return FALSE;
1570
252b5132 1571 r->relent.sym_ptr_ptr = 0;
0a9d414a
NC
1572 if (! parse_expression (ieee,
1573 &r->relent.addend,
1574 &r->symbol,
1575 &pcrel, &extra, &section))
1576 return FALSE;
1577
252b5132
RH
1578 r->relent.address = current_map->pc;
1579 s->flags |= SEC_RELOC;
1580 s->owner->flags |= HAS_RELOC;
1581 s->reloc_count++;
1582 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
1583 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1584
1585 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1586 {
0a9d414a
NC
1587 if (! next_byte (&(ieee->h)))
1588 return FALSE;
49ae03bf 1589 /* Fetch number of bytes to pad. */
252b5132
RH
1590 extra = must_parse_int (&(ieee->h));
1591 };
1592
1593 switch (this_byte (&(ieee->h)))
1594 {
1595 case ieee_function_signed_close_b_enum:
0a9d414a
NC
1596 if (! next_byte (&(ieee->h)))
1597 return FALSE;
252b5132
RH
1598 break;
1599 case ieee_function_unsigned_close_b_enum:
0a9d414a
NC
1600 if (! next_byte (&(ieee->h)))
1601 return FALSE;
252b5132
RH
1602 break;
1603 case ieee_function_either_close_b_enum:
0a9d414a
NC
1604 if (! next_byte (&(ieee->h)))
1605 return FALSE;
252b5132
RH
1606 break;
1607 default:
1608 break;
1609 }
49ae03bf 1610 /* Build a relocation entry for this type. */
252b5132
RH
1611 /* If pc rel then stick -ve pc into instruction
1612 and take out of reloc ..
1613
1614 I've changed this. It's all too complicated. I
1615 keep 0 in the instruction now. */
1616
1617 switch (extra)
1618 {
1619 case 0:
1620 case 4:
1621
82e51918 1622 if (pcrel)
252b5132
RH
1623 {
1624#if KEEPMINUSPCININST
dc810e39
AM
1625 bfd_put_32 (ieee->h.abfd, -current_map->pc,
1626 location_ptr + current_map->pc);
252b5132 1627 r->relent.howto = &rel32_howto;
dc810e39 1628 r->relent.addend -= current_map->pc;
252b5132 1629#else
dc810e39 1630 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
252b5132
RH
1631 current_map->pc);
1632 r->relent.howto = &rel32_howto;
1633#endif
1634 }
1635 else
1636 {
dc810e39
AM
1637 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
1638 location_ptr + current_map->pc);
252b5132
RH
1639 r->relent.howto = &abs32_howto;
1640 }
1641 current_map->pc += 4;
1642 break;
1643 case 2:
82e51918 1644 if (pcrel)
252b5132
RH
1645 {
1646#if KEEPMINUSPCININST
dc810e39
AM
1647 bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
1648 location_ptr + current_map->pc);
252b5132
RH
1649 r->relent.addend -= current_map->pc;
1650 r->relent.howto = &rel16_howto;
1651#else
1652
dc810e39
AM
1653 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1654 location_ptr + current_map->pc);
252b5132
RH
1655 r->relent.howto = &rel16_howto;
1656#endif
1657 }
1658
1659 else
1660 {
dc810e39
AM
1661 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1662 location_ptr + current_map->pc);
252b5132
RH
1663 r->relent.howto = &abs16_howto;
1664 }
1665 current_map->pc += 2;
1666 break;
1667 case 1:
82e51918 1668 if (pcrel)
252b5132
RH
1669 {
1670#if KEEPMINUSPCININST
1671 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1672 r->relent.addend -= current_map->pc;
1673 r->relent.howto = &rel8_howto;
1674#else
1675 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1676 r->relent.howto = &rel8_howto;
1677#endif
1678 }
1679 else
1680 {
1681 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1682 r->relent.howto = &abs8_howto;
1683 }
1684 current_map->pc += 1;
1685 break;
1686
1687 default:
1688 BFD_FAIL ();
b34976b6 1689 return FALSE;
252b5132
RH
1690 }
1691 }
1692 break;
1693 default:
1694 {
1695 bfd_vma this_size;
c8e7bf0d 1696
82e51918 1697 if (parse_int (&(ieee->h), &this_size))
252b5132
RH
1698 {
1699 unsigned int i;
c8e7bf0d 1700
252b5132
RH
1701 for (i = 0; i < this_size; i++)
1702 {
1703 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
0a9d414a
NC
1704 if (! next_byte (&(ieee->h)))
1705 return FALSE;
252b5132
RH
1706 }
1707 }
1708 else
c8e7bf0d 1709 loop = FALSE;
252b5132
RH
1710 }
1711 }
1712
1713 /* Prevent more than the first load-item of an LR record
c8e7bf0d 1714 from being repeated (MRI convention). */
252b5132 1715 if (iterations != 1)
b34976b6 1716 loop = FALSE;
252b5132
RH
1717 }
1718 }
1719 }
b34976b6 1720 return TRUE;
252b5132
RH
1721}
1722
49ae03bf
NC
1723/* Read in all the section data and relocation stuff too. */
1724
b34976b6 1725static bfd_boolean
c8e7bf0d 1726ieee_slurp_section_data (bfd *abfd)
252b5132
RH
1727{
1728 bfd_byte *location_ptr = (bfd_byte *) NULL;
1729 ieee_data_type *ieee = IEEE_DATA (abfd);
1730 unsigned int section_number;
c8e7bf0d 1731 ieee_per_section_type *current_map = NULL;
252b5132 1732 asection *s;
68ffbac6 1733
49ae03bf 1734 /* Seek to the start of the data area. */
82e51918 1735 if (ieee->read_data)
b34976b6
AM
1736 return TRUE;
1737 ieee->read_data = TRUE;
0a9d414a
NC
1738
1739 if (! ieee_seek (ieee, ieee->w.r.data_part))
1740 return FALSE;
252b5132 1741
49ae03bf 1742 /* Allocate enough space for all the section contents. */
252b5132
RH
1743 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1744 {
68bfbfcc 1745 ieee_per_section_type *per = ieee_per_section (s);
6edfbbad 1746 arelent **relpp;
c8e7bf0d 1747
252b5132
RH
1748 if ((s->flags & SEC_DEBUGGING) != 0)
1749 continue;
c8e7bf0d 1750 per->data = bfd_alloc (ieee->h.abfd, s->size);
252b5132 1751 if (!per->data)
b34976b6 1752 return FALSE;
6edfbbad
DJ
1753 relpp = &s->relocation;
1754 per->reloc_tail_ptr = (ieee_reloc_type **) relpp;
252b5132
RH
1755 }
1756
b34976b6 1757 while (TRUE)
252b5132
RH
1758 {
1759 switch (this_byte (&(ieee->h)))
1760 {
49ae03bf 1761 /* IF we see anything strange then quit. */
252b5132 1762 default:
b34976b6 1763 return TRUE;
252b5132
RH
1764
1765 case ieee_set_current_section_enum:
0a9d414a
NC
1766 if (! next_byte (&(ieee->h)))
1767 return FALSE;
252b5132
RH
1768 section_number = must_parse_int (&(ieee->h));
1769 s = ieee->section_table[section_number];
1770 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
68bfbfcc 1771 current_map = ieee_per_section (s);
252b5132 1772 location_ptr = current_map->data - s->vma;
49ae03bf
NC
1773 /* The document I have says that Microtec's compilers reset
1774 this after a sec section, even though the standard says not
1775 to, SO... */
252b5132
RH
1776 current_map->pc = s->vma;
1777 break;
1778
1779 case ieee_e2_first_byte_enum:
0a9d414a
NC
1780 if (! next_byte (&(ieee->h)))
1781 return FALSE;
252b5132
RH
1782 switch (this_byte (&(ieee->h)))
1783 {
1784 case ieee_set_current_pc_enum & 0xff:
1785 {
1786 bfd_vma value;
1787 ieee_symbol_index_type symbol;
1788 unsigned int extra;
b34976b6 1789 bfd_boolean pcrel;
49ae03bf 1790
0a9d414a
NC
1791 if (! next_byte (&(ieee->h)))
1792 return FALSE;
49ae03bf 1793 must_parse_int (&(ieee->h)); /* Throw away section #. */
0a9d414a
NC
1794 if (! parse_expression (ieee, &value,
1795 &symbol,
1796 &pcrel, &extra,
1797 0))
1798 return FALSE;
1799
252b5132 1800 current_map->pc = value;
eea6121a 1801 BFD_ASSERT ((unsigned) (value - s->vma) <= s->size);
252b5132
RH
1802 }
1803 break;
1804
1805 case ieee_value_starting_address_enum & 0xff:
0a9d414a
NC
1806 if (! next_byte (&(ieee->h)))
1807 return FALSE;
252b5132 1808 if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
0a9d414a
NC
1809 {
1810 if (! next_byte (&(ieee->h)))
1811 return FALSE;
1812 }
252b5132 1813 abfd->start_address = must_parse_int (&(ieee->h));
49ae03bf 1814 /* We've got to the end of the data now - */
b34976b6 1815 return TRUE;
252b5132
RH
1816 default:
1817 BFD_FAIL ();
b34976b6 1818 return FALSE;
252b5132
RH
1819 }
1820 break;
1821 case ieee_repeat_data_enum:
1822 {
1823 /* Repeat the following LD or LR n times - we do this by
49ae03bf
NC
1824 remembering the stream pointer before running it and
1825 resetting it and running it n times. We special case
1826 the repetition of a repeat_data/load_constant. */
252b5132
RH
1827 unsigned int iterations;
1828 unsigned char *start;
49ae03bf 1829
0a9d414a
NC
1830 if (! next_byte (&(ieee->h)))
1831 return FALSE;
252b5132
RH
1832 iterations = must_parse_int (&(ieee->h));
1833 start = ieee->h.input_p;
49ae03bf
NC
1834 if (start[0] == (int) ieee_load_constant_bytes_enum
1835 && start[1] == 1)
252b5132
RH
1836 {
1837 while (iterations != 0)
1838 {
1839 location_ptr[current_map->pc++] = start[2];
1840 iterations--;
1841 }
0a9d414a
NC
1842 (void) next_byte (&(ieee->h));
1843 (void) next_byte (&(ieee->h));
1844 if (! next_byte (&(ieee->h)))
1845 return FALSE;
252b5132
RH
1846 }
1847 else
1848 {
1849 while (iterations != 0)
1850 {
1851 ieee->h.input_p = start;
1852 if (!do_one (ieee, current_map, location_ptr, s,
dc810e39 1853 (int) iterations))
b34976b6 1854 return FALSE;
252b5132
RH
1855 iterations--;
1856 }
1857 }
1858 }
1859 break;
1860 case ieee_load_constant_bytes_enum:
1861 case ieee_load_with_relocation_enum:
49ae03bf
NC
1862 if (!do_one (ieee, current_map, location_ptr, s, 1))
1863 return FALSE;
252b5132
RH
1864 }
1865 }
1866}
1867
46e94266
NC
1868static const bfd_target *
1869ieee_object_p (bfd *abfd)
1870{
1871 char *processor;
1872 unsigned int part;
1873 ieee_data_type *ieee;
1874 unsigned char buffer[300];
1875 ieee_data_type *save = IEEE_DATA (abfd);
1876 bfd_size_type amt;
1877
1878 abfd->tdata.ieee_data = 0;
1879 ieee_mkobject (abfd);
1880
1881 ieee = IEEE_DATA (abfd);
1882 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1883 goto fail;
1884 /* Read the first few bytes in to see if it makes sense. Ignore
1885 bfd_bread return value; The file might be very small. */
041830e0
NC
1886 if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0)
1887 goto got_wrong_format;
46e94266
NC
1888
1889 ieee->h.input_p = buffer;
0a9d414a 1890 ieee->h.total_amt = sizeof (buffer);
46e94266
NC
1891 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1892 goto got_wrong_format;
1893
1894 ieee->read_symbols = FALSE;
1895 ieee->read_data = FALSE;
1896 ieee->section_count = 0;
1897 ieee->external_symbol_max_index = 0;
1898 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1899 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1900 ieee->external_reference_max_index = 0;
1901 ieee->h.abfd = abfd;
1902 ieee->section_table = NULL;
1903 ieee->section_table_size = 0;
1904
1905 processor = ieee->mb.processor = read_id (&(ieee->h));
1906 if (strcmp (processor, "LIBRARY") == 0)
1907 goto got_wrong_format;
1908 ieee->mb.module_name = read_id (&(ieee->h));
1909 if (abfd->filename == (const char *) NULL)
1be5090b 1910 abfd->filename = xstrdup (ieee->mb.module_name);
46e94266
NC
1911
1912 /* Determine the architecture and machine type of the object file. */
1913 {
1914 const bfd_arch_info_type *arch;
1915 char family[10];
1916
1917 /* IEEE does not specify the format of the processor identification
1918 string, so the compiler is free to put in it whatever it wants.
1919 We try here to recognize different processors belonging to the
1920 m68k family. Code for other processors can be added here. */
1921 if ((processor[0] == '6') && (processor[1] == '8'))
1922 {
1923 if (processor[2] == '3') /* 683xx integrated processors. */
1924 {
1925 switch (processor[3])
1926 {
1927 case '0': /* 68302, 68306, 68307 */
1928 case '2': /* 68322, 68328 */
1929 case '5': /* 68356 */
1930 strcpy (family, "68000"); /* MC68000-based controllers. */
1931 break;
1932
1933 case '3': /* 68330, 68331, 68332, 68333,
1934 68334, 68335, 68336, 68338 */
1935 case '6': /* 68360 */
1936 case '7': /* 68376 */
1937 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1938 break;
1939
1940 case '4':
1941 if (processor[4] == '9') /* 68349 */
1942 strcpy (family, "68030"); /* CPU030 */
1943 else /* 68340, 68341 */
1944 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1945 break;
1946
1947 default: /* Does not exist yet. */
1948 strcpy (family, "68332"); /* Guess it will be CPU32 */
1949 }
1950 }
1951 else if (TOUPPER (processor[3]) == 'F') /* 68F333 */
1952 strcpy (family, "68332"); /* CPU32 */
1953 else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers. */
1954 && ((TOUPPER (processor[2]) == 'E')
1955 || (TOUPPER (processor[2]) == 'H')
1956 || (TOUPPER (processor[2]) == 'L')))
1957 {
1958 strcpy (family, "68");
1959 strncat (family, processor + 4, 7);
1960 family[9] = '\0';
1961 }
1962 else /* "Regular" processors. */
1963 {
1964 strncpy (family, processor, 9);
1965 family[9] = '\0';
1966 }
1967 }
0112cd26
NC
1968 else if ((CONST_STRNEQ (processor, "cpu32")) /* CPU32 and CPU32+ */
1969 || (CONST_STRNEQ (processor, "CPU32")))
46e94266
NC
1970 strcpy (family, "68332");
1971 else
1972 {
1973 strncpy (family, processor, 9);
1974 family[9] = '\0';
1975 }
1976
1977 arch = bfd_scan_arch (family);
1978 if (arch == 0)
1979 goto got_wrong_format;
1980 abfd->arch_info = arch;
1981 }
1982
1983 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
1984 goto fail;
1985
0a9d414a
NC
1986 if (! next_byte (&(ieee->h)))
1987 goto fail;
46e94266
NC
1988
1989 if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
1990 goto fail;
1991
1992 if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
1993 goto fail;
1994
1995 /* If there is a byte order info, take it. */
1996 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum
1997 || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
0a9d414a
NC
1998 {
1999 if (! next_byte (&(ieee->h)))
2000 goto fail;
2001 }
46e94266
NC
2002
2003 for (part = 0; part < N_W_VARIABLES; part++)
2004 {
2005 bfd_boolean ok;
2006
2007 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
2008 goto fail;
2009
2010 if (this_byte_and_next (&(ieee->h)) != part)
2011 goto fail;
2012
2013 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
2014 if (! ok)
2015 goto fail;
2016 }
2017
2018 if (ieee->w.r.external_part != 0)
2019 abfd->flags = HAS_SYMS;
2020
2021 /* By now we know that this is a real IEEE file, we're going to read
2022 the whole thing into memory so that we can run up and down it
2023 quickly. We can work out how big the file is from the trailer
2024 record. */
2025
2026 amt = ieee->w.r.me_record + 1;
2027 IEEE_DATA (abfd)->h.first_byte = bfd_alloc (ieee->h.abfd, amt);
2028 if (!IEEE_DATA (abfd)->h.first_byte)
2029 goto fail;
2030 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
2031 goto fail;
0a9d414a 2032
46e94266
NC
2033 /* FIXME: Check return value. I'm not sure whether it needs to read
2034 the entire buffer or not. */
0a9d414a
NC
2035 amt = bfd_bread ((void *) (IEEE_DATA (abfd)->h.first_byte),
2036 (bfd_size_type) ieee->w.r.me_record + 1, abfd);
2037 if (amt <= 0)
2038 goto fail;
46e94266 2039
0a9d414a
NC
2040 IEEE_DATA (abfd)->h.total_amt = amt;
2041 if (ieee_slurp_sections (abfd))
2042 goto fail;
46e94266
NC
2043
2044 if (! ieee_slurp_debug (abfd))
2045 goto fail;
2046
2047 /* Parse section data to activate file and section flags implied by
2048 section contents. */
2049 if (! ieee_slurp_section_data (abfd))
2050 goto fail;
2051
2052 return abfd->xvec;
2053got_wrong_format:
2054 bfd_set_error (bfd_error_wrong_format);
2055fail:
2056 bfd_release (abfd, ieee);
2057 abfd->tdata.ieee_data = save;
2058 return (const bfd_target *) NULL;
2059}
2060
2061static void
2062ieee_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED,
2063 asymbol *symbol,
2064 symbol_info *ret)
2065{
2066 bfd_symbol_info (symbol, ret);
2067 if (symbol->name[0] == ' ')
2068 ret->name = "* empty table entry ";
2069 if (!symbol->section)
2070 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
2071}
2072
2073static void
2074ieee_print_symbol (bfd *abfd,
2075 void * afile,
2076 asymbol *symbol,
2077 bfd_print_symbol_type how)
2078{
2079 FILE *file = (FILE *) afile;
2080
2081 switch (how)
2082 {
2083 case bfd_print_symbol_name:
2084 fprintf (file, "%s", symbol->name);
2085 break;
2086 case bfd_print_symbol_more:
2087 BFD_FAIL ();
2088 break;
2089 case bfd_print_symbol_all:
2090 {
2091 const char *section_name =
2092 (symbol->section == (asection *) NULL
2093 ? "*abs"
2094 : symbol->section->name);
2095
2096 if (symbol->name[0] == ' ')
2097 fprintf (file, "* empty table entry ");
2098 else
2099 {
2100 bfd_print_symbol_vandf (abfd, (void *) file, symbol);
2101
2102 fprintf (file, " %-5s %04x %02x %s",
2103 section_name,
2104 (unsigned) ieee_symbol (symbol)->index,
2105 (unsigned) 0,
2106 symbol->name);
2107 }
2108 }
2109 break;
2110 }
2111}
2112
2113static bfd_boolean
2114ieee_new_section_hook (bfd *abfd, asection *newsect)
252b5132 2115{
252b5132 2116 if (!newsect->used_by_bfd)
f592407e
AM
2117 {
2118 newsect->used_by_bfd = bfd_alloc (abfd, sizeof (ieee_per_section_type));
2119 if (!newsect->used_by_bfd)
2120 return FALSE;
2121 }
c8e7bf0d 2122 ieee_per_section (newsect)->data = NULL;
252b5132 2123 ieee_per_section (newsect)->section = newsect;
f592407e 2124 return _bfd_generic_new_section_hook (abfd, newsect);
252b5132
RH
2125}
2126
47fda0d3 2127static long
c8e7bf0d 2128ieee_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
252b5132
RH
2129{
2130 if ((asect->flags & SEC_DEBUGGING) != 0)
2131 return 0;
2132 if (! ieee_slurp_section_data (abfd))
2133 return -1;
2134 return (asect->reloc_count + 1) * sizeof (arelent *);
2135}
2136
b34976b6 2137static bfd_boolean
c8e7bf0d
NC
2138ieee_get_section_contents (bfd *abfd,
2139 sec_ptr section,
2140 void * location,
2141 file_ptr offset,
2142 bfd_size_type count)
252b5132 2143{
68bfbfcc 2144 ieee_per_section_type *p = ieee_per_section (section);
252b5132
RH
2145 if ((section->flags & SEC_DEBUGGING) != 0)
2146 return _bfd_generic_get_section_contents (abfd, section, location,
2147 offset, count);
2148 ieee_slurp_section_data (abfd);
c8e7bf0d 2149 (void) memcpy ((void *) location, (void *) (p->data + offset), (unsigned) count);
b34976b6 2150 return TRUE;
252b5132
RH
2151}
2152
47fda0d3 2153static long
c8e7bf0d
NC
2154ieee_canonicalize_reloc (bfd *abfd,
2155 sec_ptr section,
2156 arelent **relptr,
2157 asymbol **symbols)
252b5132 2158{
252b5132
RH
2159 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
2160 ieee_data_type *ieee = IEEE_DATA (abfd);
2161
2162 if ((section->flags & SEC_DEBUGGING) != 0)
2163 return 0;
2164
2165 while (src != (ieee_reloc_type *) NULL)
2166 {
49ae03bf 2167 /* Work out which symbol to attach it this reloc to. */
252b5132
RH
2168 switch (src->symbol.letter)
2169 {
2170 case 'I':
2171 src->relent.sym_ptr_ptr =
2172 symbols + src->symbol.index + ieee->external_symbol_base_offset;
2173 break;
2174 case 'X':
2175 src->relent.sym_ptr_ptr =
2176 symbols + src->symbol.index + ieee->external_reference_base_offset;
2177 break;
2178 case 0:
2179 if (src->relent.sym_ptr_ptr != NULL)
2180 src->relent.sym_ptr_ptr =
2181 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
2182 break;
2183 default:
2184
2185 BFD_FAIL ();
2186 }
2187 *relptr++ = &src->relent;
2188 src = src->next;
2189 }
c8e7bf0d 2190 *relptr = NULL;
252b5132
RH
2191 return section->reloc_count;
2192}
2193
2194static int
c8e7bf0d 2195comp (const void * ap, const void * bp)
252b5132
RH
2196{
2197 arelent *a = *((arelent **) ap);
2198 arelent *b = *((arelent **) bp);
2199 return a->address - b->address;
2200}
2201
2202/* Write the section headers. */
2203
b34976b6 2204static bfd_boolean
c8e7bf0d 2205ieee_write_section_part (bfd *abfd)
252b5132
RH
2206{
2207 ieee_data_type *ieee = IEEE_DATA (abfd);
2208 asection *s;
c8e7bf0d 2209
252b5132
RH
2210 ieee->w.r.section_part = bfd_tell (abfd);
2211 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2212 {
2213 if (! bfd_is_abs_section (s)
2214 && (s->flags & SEC_DEBUGGING) == 0)
2215 {
2216 if (! ieee_write_byte (abfd, ieee_section_type_enum)
2217 || ! ieee_write_byte (abfd,
2218 (bfd_byte) (s->index
2219 + IEEE_SECTION_NUMBER_BASE)))
b34976b6 2220 return FALSE;
252b5132
RH
2221
2222 if (abfd->flags & EXEC_P)
2223 {
49ae03bf 2224 /* This image is executable, so output absolute sections. */
252b5132
RH
2225 if (! ieee_write_byte (abfd, ieee_variable_A_enum)
2226 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
b34976b6 2227 return FALSE;
252b5132
RH
2228 }
2229 else
2230 {
2231 if (! ieee_write_byte (abfd, ieee_variable_C_enum))
b34976b6 2232 return FALSE;
252b5132
RH
2233 }
2234
2235 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
2236 {
2237 case SEC_CODE | SEC_LOAD:
2238 case SEC_CODE:
2239 if (! ieee_write_byte (abfd, ieee_variable_P_enum))
b34976b6 2240 return FALSE;
252b5132
RH
2241 break;
2242 case SEC_DATA:
2243 default:
2244 if (! ieee_write_byte (abfd, ieee_variable_D_enum))
b34976b6 2245 return FALSE;
252b5132
RH
2246 break;
2247 case SEC_ROM:
2248 case SEC_ROM | SEC_DATA:
2249 case SEC_ROM | SEC_LOAD:
2250 case SEC_ROM | SEC_DATA | SEC_LOAD:
2251 if (! ieee_write_byte (abfd, ieee_variable_R_enum))
b34976b6 2252 return FALSE;
252b5132
RH
2253 }
2254
2255
2256 if (! ieee_write_id (abfd, s->name))
b34976b6 2257 return FALSE;
49ae03bf 2258 /* Alignment. */
252b5132
RH
2259 if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
2260 || ! ieee_write_byte (abfd,
2261 (bfd_byte) (s->index
2262 + IEEE_SECTION_NUMBER_BASE))
dc810e39 2263 || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
b34976b6 2264 return FALSE;
252b5132 2265
49ae03bf 2266 /* Size. */
252b5132
RH
2267 if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
2268 || ! ieee_write_byte (abfd,
2269 (bfd_byte) (s->index
2270 + IEEE_SECTION_NUMBER_BASE))
eea6121a 2271 || ! ieee_write_int (abfd, s->size))
b34976b6 2272 return FALSE;
252b5132
RH
2273 if (abfd->flags & EXEC_P)
2274 {
49ae03bf
NC
2275 /* Relocateable sections don't have asl records. */
2276 /* Vma. */
252b5132
RH
2277 if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
2278 || ! ieee_write_byte (abfd,
2279 ((bfd_byte)
2280 (s->index
2281 + IEEE_SECTION_NUMBER_BASE)))
2282 || ! ieee_write_int (abfd, s->lma))
b34976b6 2283 return FALSE;
252b5132
RH
2284 }
2285 }
2286 }
2287
b34976b6 2288 return TRUE;
252b5132
RH
2289}
2290
b34976b6 2291static bfd_boolean
c8e7bf0d 2292do_with_relocs (bfd *abfd, asection *s)
252b5132
RH
2293{
2294 unsigned int number_of_maus_in_address =
2295 bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
2296 unsigned int relocs_to_go = s->reloc_count;
2297 bfd_byte *stream = ieee_per_section (s)->data;
2298 arelent **p = s->orelocation;
2299 bfd_size_type current_byte_index = 0;
2300
2301 qsort (s->orelocation,
2302 relocs_to_go,
2303 sizeof (arelent **),
2304 comp);
2305
49ae03bf 2306 /* Output the section preheader. */
252b5132
RH
2307 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2308 || ! ieee_write_byte (abfd,
2309 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
2310 || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
2311 || ! ieee_write_byte (abfd,
2312 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
b34976b6 2313 return FALSE;
47fda0d3 2314
252b5132
RH
2315 if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
2316 {
2317 if (! ieee_write_int (abfd, s->lma))
b34976b6 2318 return FALSE;
252b5132
RH
2319 }
2320 else
2321 {
dc810e39 2322 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
b34976b6 2323 return FALSE;
252b5132
RH
2324 }
2325
2326 if (relocs_to_go == 0)
2327 {
2328 /* If there aren't any relocations then output the load constant
49ae03bf 2329 byte opcode rather than the load with relocation opcode. */
eea6121a 2330 while (current_byte_index < s->size)
252b5132
RH
2331 {
2332 bfd_size_type run;
2333 unsigned int MAXRUN = 127;
49ae03bf 2334
252b5132 2335 run = MAXRUN;
eea6121a
AM
2336 if (run > s->size - current_byte_index)
2337 run = s->size - current_byte_index;
252b5132
RH
2338
2339 if (run != 0)
2340 {
2341 if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
b34976b6 2342 return FALSE;
49ae03bf 2343 /* Output a stream of bytes. */
252b5132 2344 if (! ieee_write_int (abfd, run))
b34976b6 2345 return FALSE;
c8e7bf0d 2346 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
252b5132 2347 != run)
b34976b6 2348 return FALSE;
252b5132
RH
2349 current_byte_index += run;
2350 }
2351 }
2352 }
2353 else
2354 {
2355 if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
b34976b6 2356 return FALSE;
252b5132
RH
2357
2358 /* Output the data stream as the longest sequence of bytes
2359 possible, allowing for the a reasonable packet size and
2360 relocation stuffs. */
c8e7bf0d 2361 if (stream == NULL)
252b5132 2362 {
49ae03bf 2363 /* Outputting a section without data, fill it up. */
c8e7bf0d 2364 stream = bfd_zalloc (abfd, s->size);
252b5132 2365 if (!stream)
b34976b6 2366 return FALSE;
252b5132 2367 }
eea6121a 2368 while (current_byte_index < s->size)
252b5132
RH
2369 {
2370 bfd_size_type run;
2371 unsigned int MAXRUN = 127;
49ae03bf 2372
252b5132
RH
2373 if (relocs_to_go)
2374 {
2375 run = (*p)->address - current_byte_index;
2376 if (run > MAXRUN)
2377 run = MAXRUN;
2378 }
2379 else
49ae03bf
NC
2380 run = MAXRUN;
2381
eea6121a
AM
2382 if (run > s->size - current_byte_index)
2383 run = s->size - current_byte_index;
252b5132
RH
2384
2385 if (run != 0)
2386 {
49ae03bf 2387 /* Output a stream of bytes. */
252b5132 2388 if (! ieee_write_int (abfd, run))
b34976b6 2389 return FALSE;
c8e7bf0d 2390 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
252b5132 2391 != run)
b34976b6 2392 return FALSE;
252b5132
RH
2393 current_byte_index += run;
2394 }
49ae03bf
NC
2395
2396 /* Output any relocations here. */
252b5132
RH
2397 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
2398 {
2399 while (relocs_to_go
2400 && (*p) && (*p)->address == current_byte_index)
2401 {
2402 arelent *r = *p;
2403 bfd_signed_vma ov;
252b5132
RH
2404 switch (r->howto->size)
2405 {
2406 case 2:
252b5132
RH
2407 ov = bfd_get_signed_32 (abfd,
2408 stream + current_byte_index);
2409 current_byte_index += 4;
2410 break;
2411 case 1:
2412 ov = bfd_get_signed_16 (abfd,
2413 stream + current_byte_index);
2414 current_byte_index += 2;
2415 break;
2416 case 0:
2417 ov = bfd_get_signed_8 (abfd,
2418 stream + current_byte_index);
2419 current_byte_index++;
2420 break;
2421 default:
2422 ov = 0;
2423 BFD_FAIL ();
b34976b6 2424 return FALSE;
252b5132
RH
2425 }
2426
2427 ov &= r->howto->src_mask;
2428
2429 if (r->howto->pc_relative
2430 && ! r->howto->pcrel_offset)
2431 ov += r->address;
2432
2433 if (! ieee_write_byte (abfd,
2434 ieee_function_either_open_b_enum))
b34976b6 2435 return FALSE;
252b5132 2436
252b5132
RH
2437 if (r->sym_ptr_ptr != (asymbol **) NULL)
2438 {
2439 if (! ieee_write_expression (abfd, r->addend + ov,
2440 *(r->sym_ptr_ptr),
2441 r->howto->pc_relative,
dc810e39 2442 (unsigned) s->index))
b34976b6 2443 return FALSE;
252b5132
RH
2444 }
2445 else
2446 {
2447 if (! ieee_write_expression (abfd, r->addend + ov,
2448 (asymbol *) NULL,
2449 r->howto->pc_relative,
dc810e39 2450 (unsigned) s->index))
b34976b6 2451 return FALSE;
252b5132
RH
2452 }
2453
2454 if (number_of_maus_in_address
2455 != bfd_get_reloc_size (r->howto))
2456 {
dc810e39
AM
2457 bfd_vma rsize = bfd_get_reloc_size (r->howto);
2458 if (! ieee_write_int (abfd, rsize))
b34976b6 2459 return FALSE;
252b5132
RH
2460 }
2461 if (! ieee_write_byte (abfd,
2462 ieee_function_either_close_b_enum))
b34976b6 2463 return FALSE;
252b5132
RH
2464
2465 relocs_to_go--;
2466 p++;
2467 }
2468
2469 }
2470 }
2471 }
2472
b34976b6 2473 return TRUE;
252b5132
RH
2474}
2475
2476/* If there are no relocations in the output section then we can be
2477 clever about how we write. We block items up into a max of 127
2478 bytes. */
2479
b34976b6 2480static bfd_boolean
c8e7bf0d 2481do_as_repeat (bfd *abfd, asection *s)
252b5132 2482{
eea6121a 2483 if (s->size)
252b5132
RH
2484 {
2485 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2486 || ! ieee_write_byte (abfd,
2487 (bfd_byte) (s->index
2488 + IEEE_SECTION_NUMBER_BASE))
2489 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
2490 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
2491 || ! ieee_write_byte (abfd,
2492 (bfd_byte) (s->index
47fda0d3 2493 + IEEE_SECTION_NUMBER_BASE)))
b34976b6 2494 return FALSE;
47fda0d3
AM
2495
2496 if ((abfd->flags & EXEC_P) != 0)
2497 {
2498 if (! ieee_write_int (abfd, s->lma))
b34976b6 2499 return FALSE;
47fda0d3
AM
2500 }
2501 else
2502 {
dc810e39 2503 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
b34976b6 2504 return FALSE;
47fda0d3
AM
2505 }
2506
2507 if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
eea6121a 2508 || ! ieee_write_int (abfd, s->size)
252b5132
RH
2509 || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
2510 || ! ieee_write_byte (abfd, 1)
2511 || ! ieee_write_byte (abfd, 0))
b34976b6 2512 return FALSE;
252b5132
RH
2513 }
2514
b34976b6 2515 return TRUE;
252b5132
RH
2516}
2517
b34976b6 2518static bfd_boolean
c8e7bf0d 2519do_without_relocs (bfd *abfd, asection *s)
252b5132
RH
2520{
2521 bfd_byte *stream = ieee_per_section (s)->data;
2522
2523 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2524 {
2525 if (! do_as_repeat (abfd, s))
b34976b6 2526 return FALSE;
252b5132
RH
2527 }
2528 else
2529 {
2530 unsigned int i;
49ae03bf 2531
eea6121a 2532 for (i = 0; i < s->size; i++)
252b5132
RH
2533 {
2534 if (stream[i] != 0)
2535 {
2536 if (! do_with_relocs (abfd, s))
b34976b6
AM
2537 return FALSE;
2538 return TRUE;
252b5132
RH
2539 }
2540 }
2541 if (! do_as_repeat (abfd, s))
b34976b6 2542 return FALSE;
252b5132
RH
2543 }
2544
b34976b6 2545 return TRUE;
252b5132
RH
2546}
2547
252b5132 2548static void
c8e7bf0d 2549fill (void)
252b5132 2550{
dc810e39 2551 bfd_size_type amt = input_ptr_end - input_ptr_start;
252b5132
RH
2552 /* FIXME: Check return value. I'm not sure whether it needs to read
2553 the entire buffer or not. */
c8e7bf0d 2554 bfd_bread ((void *) input_ptr_start, amt, input_bfd);
252b5132
RH
2555 input_ptr = input_ptr_start;
2556}
47fda0d3 2557
252b5132 2558static void
c8e7bf0d 2559flush (void)
252b5132 2560{
dc810e39 2561 bfd_size_type amt = output_ptr - output_ptr_start;
49ae03bf 2562
c8e7bf0d 2563 if (bfd_bwrite ((void *) (output_ptr_start), amt, output_bfd) != amt)
252b5132
RH
2564 abort ();
2565 output_ptr = output_ptr_start;
2566 output_buffer++;
2567}
2568
2569#define THIS() ( *input_ptr )
c8e7bf0d
NC
2570#define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); }
2571#define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end) flush (); }
252b5132
RH
2572
2573static void
c8e7bf0d 2574write_int (int value)
252b5132
RH
2575{
2576 if (value >= 0 && value <= 127)
2577 {
2578 OUT (value);
2579 }
2580 else
2581 {
2582 unsigned int length;
c8e7bf0d 2583
49ae03bf
NC
2584 /* How many significant bytes ? */
2585 /* FIXME FOR LONGER INTS. */
252b5132 2586 if (value & 0xff000000)
49ae03bf 2587 length = 4;
252b5132 2588 else if (value & 0x00ff0000)
49ae03bf 2589 length = 3;
252b5132 2590 else if (value & 0x0000ff00)
49ae03bf 2591 length = 2;
252b5132
RH
2592 else
2593 length = 1;
2594
2595 OUT ((int) ieee_number_repeat_start_enum + length);
2596 switch (length)
2597 {
2598 case 4:
2599 OUT (value >> 24);
1a0670f3 2600 /* Fall through. */
252b5132
RH
2601 case 3:
2602 OUT (value >> 16);
1a0670f3 2603 /* Fall through. */
252b5132
RH
2604 case 2:
2605 OUT (value >> 8);
1a0670f3 2606 /* Fall through. */
252b5132
RH
2607 case 1:
2608 OUT (value);
2609 }
252b5132
RH
2610 }
2611}
2612
2613static void
46e94266 2614copy_id (void)
252b5132
RH
2615{
2616 int length = THIS ();
2617 char ch;
49ae03bf 2618
252b5132
RH
2619 OUT (length);
2620 NEXT ();
2621 while (length--)
2622 {
2623 ch = THIS ();
2624 OUT (ch);
2625 NEXT ();
2626 }
2627}
2628
2629#define VAR(x) ((x | 0x80))
2630static void
46e94266 2631copy_expression (void)
252b5132
RH
2632{
2633 int stack[10];
2634 int *tos = stack;
dc810e39 2635 int value;
49ae03bf 2636
252b5132
RH
2637 while (1)
2638 {
2639 switch (THIS ())
2640 {
2641 case 0x84:
2642 NEXT ();
2643 value = THIS ();
2644 NEXT ();
2645 value = (value << 8) | THIS ();
2646 NEXT ();
2647 value = (value << 8) | THIS ();
2648 NEXT ();
2649 value = (value << 8) | THIS ();
2650 NEXT ();
2651 *tos++ = value;
2652 break;
2653 case 0x83:
2654 NEXT ();
2655 value = THIS ();
2656 NEXT ();
2657 value = (value << 8) | THIS ();
2658 NEXT ();
2659 value = (value << 8) | THIS ();
2660 NEXT ();
2661 *tos++ = value;
2662 break;
2663 case 0x82:
2664 NEXT ();
2665 value = THIS ();
2666 NEXT ();
2667 value = (value << 8) | THIS ();
2668 NEXT ();
2669 *tos++ = value;
2670 break;
2671 case 0x81:
2672 NEXT ();
2673 value = THIS ();
2674 NEXT ();
2675 *tos++ = value;
2676 break;
2677 case 0x80:
2678 NEXT ();
2679 *tos++ = 0;
2680 break;
2681 default:
2682 if (THIS () > 0x84)
2683 {
49ae03bf 2684 /* Not a number, just bug out with the answer. */
252b5132
RH
2685 write_int (*(--tos));
2686 return;
2687 }
2688 *tos++ = THIS ();
2689 NEXT ();
252b5132
RH
2690 break;
2691 case 0xa5:
49ae03bf 2692 /* PLUS anything. */
dc810e39
AM
2693 value = *(--tos);
2694 value += *(--tos);
2695 *tos++ = value;
2696 NEXT ();
252b5132
RH
2697 break;
2698 case VAR ('R'):
2699 {
2700 int section_number;
2701 ieee_data_type *ieee;
2702 asection *s;
49ae03bf 2703
252b5132
RH
2704 NEXT ();
2705 section_number = THIS ();
2706
2707 NEXT ();
2708 ieee = IEEE_DATA (input_bfd);
2709 s = ieee->section_table[section_number];
dc810e39 2710 value = 0;
252b5132 2711 if (s->output_section)
dc810e39 2712 value = s->output_section->lma;
252b5132
RH
2713 value += s->output_offset;
2714 *tos++ = value;
252b5132
RH
2715 }
2716 break;
2717 case 0x90:
2718 {
2719 NEXT ();
2720 write_int (*(--tos));
2721 OUT (0x90);
2722 return;
252b5132
RH
2723 }
2724 }
2725 }
252b5132
RH
2726}
2727
2728/* Drop the int in the buffer, and copy a null into the gap, which we
c8e7bf0d 2729 will overwrite later. */
252b5132 2730
252b5132 2731static void
46e94266 2732fill_int (struct output_buffer_struct *buf)
252b5132
RH
2733{
2734 if (buf->buffer == output_buffer)
2735 {
49ae03bf 2736 /* Still a chance to output the size. */
252b5132
RH
2737 int value = output_ptr - buf->ptrp + 3;
2738 buf->ptrp[0] = value >> 24;
2739 buf->ptrp[1] = value >> 16;
2740 buf->ptrp[2] = value >> 8;
2741 buf->ptrp[3] = value >> 0;
2742 }
2743}
2744
2745static void
46e94266 2746drop_int (struct output_buffer_struct *buf)
252b5132
RH
2747{
2748 int type = THIS ();
2749 int ch;
49ae03bf 2750
252b5132
RH
2751 if (type <= 0x84)
2752 {
2753 NEXT ();
2754 switch (type)
2755 {
2756 case 0x84:
2757 ch = THIS ();
2758 NEXT ();
1a0670f3 2759 /* Fall through. */
252b5132
RH
2760 case 0x83:
2761 ch = THIS ();
2762 NEXT ();
1a0670f3 2763 /* Fall through. */
252b5132
RH
2764 case 0x82:
2765 ch = THIS ();
2766 NEXT ();
1a0670f3 2767 /* Fall through. */
252b5132
RH
2768 case 0x81:
2769 ch = THIS ();
2770 NEXT ();
1a0670f3 2771 /* Fall through. */
252b5132
RH
2772 case 0x80:
2773 break;
2774 }
2775 }
c7e2358a 2776 (void) ch;
252b5132
RH
2777 OUT (0x84);
2778 buf->ptrp = output_ptr;
2779 buf->buffer = output_buffer;
2780 OUT (0);
2781 OUT (0);
2782 OUT (0);
2783 OUT (0);
2784}
2785
2786static void
46e94266 2787copy_int (void)
252b5132
RH
2788{
2789 int type = THIS ();
2790 int ch;
2791 if (type <= 0x84)
2792 {
2793 OUT (type);
2794 NEXT ();
2795 switch (type)
2796 {
2797 case 0x84:
2798 ch = THIS ();
2799 NEXT ();
2800 OUT (ch);
1a0670f3 2801 /* Fall through. */
252b5132
RH
2802 case 0x83:
2803 ch = THIS ();
2804 NEXT ();
2805 OUT (ch);
1a0670f3 2806 /* Fall through. */
252b5132
RH
2807 case 0x82:
2808 ch = THIS ();
2809 NEXT ();
2810 OUT (ch);
1a0670f3 2811 /* Fall through. */
252b5132
RH
2812 case 0x81:
2813 ch = THIS ();
2814 NEXT ();
2815 OUT (ch);
1a0670f3 2816 /* Fall through. */
252b5132
RH
2817 case 0x80:
2818 break;
2819 }
2820 }
2821}
2822
46e94266
NC
2823#define ID copy_id ()
2824#define INT copy_int ()
2825#define EXP copy_expression ()
2826#define INTn(q) copy_int ()
2827#define EXPn(q) copy_expression ()
252b5132
RH
2828
2829static void
46e94266
NC
2830copy_till_end (void)
2831{
2832 int ch = THIS ();
2833
2834 while (1)
2835 {
2836 while (ch <= 0x80)
2837 {
2838 OUT (ch);
2839 NEXT ();
2840 ch = THIS ();
2841 }
2842 switch (ch)
2843 {
2844 case 0x84:
2845 OUT (THIS ());
2846 NEXT ();
1a0670f3 2847 /* Fall through. */
46e94266
NC
2848 case 0x83:
2849 OUT (THIS ());
2850 NEXT ();
1a0670f3 2851 /* Fall through. */
46e94266
NC
2852 case 0x82:
2853 OUT (THIS ());
2854 NEXT ();
1a0670f3 2855 /* Fall through. */
46e94266
NC
2856 case 0x81:
2857 OUT (THIS ());
2858 NEXT ();
2859 OUT (THIS ());
2860 NEXT ();
2861
2862 ch = THIS ();
2863 break;
2864 default:
2865 return;
2866 }
2867 }
2868
2869}
2870
2871static void
2872f1_record (void)
252b5132
RH
2873{
2874 int ch;
49ae03bf
NC
2875
2876 /* ATN record. */
252b5132
RH
2877 NEXT ();
2878 ch = THIS ();
2879 switch (ch)
2880 {
2881 default:
2882 OUT (0xf1);
2883 OUT (ch);
2884 break;
2885 case 0xc9:
2886 NEXT ();
2887 OUT (0xf1);
2888 OUT (0xc9);
2889 INT;
2890 INT;
2891 ch = THIS ();
2892 switch (ch)
2893 {
2894 case 0x16:
2895 NEXT ();
2896 break;
2897 case 0x01:
2898 NEXT ();
2899 break;
2900 case 0x00:
2901 NEXT ();
2902 INT;
2903 break;
2904 case 0x03:
2905 NEXT ();
2906 INT;
2907 break;
2908 case 0x13:
2909 EXPn (instruction address);
2910 break;
2911 default:
2912 break;
2913 }
2914 break;
2915 case 0xd8:
49ae03bf 2916 /* EXternal ref. */
252b5132
RH
2917 NEXT ();
2918 OUT (0xf1);
2919 OUT (0xd8);
2920 EXP;
2921 EXP;
2922 EXP;
2923 EXP;
2924 break;
2925 case 0xce:
2926 NEXT ();
2927 OUT (0xf1);
2928 OUT (0xce);
2929 INT;
2930 INT;
2931 ch = THIS ();
2932 INT;
2933 switch (ch)
2934 {
2935 case 0x01:
2936 INT;
2937 INT;
2938 break;
2939 case 0x02:
2940 INT;
2941 break;
2942 case 0x04:
2943 EXPn (external function);
2944 break;
2945 case 0x05:
2946 break;
2947 case 0x07:
2948 INTn (line number);
2949 INT;
2950 case 0x08:
2951 break;
2952 case 0x0a:
2953 INTn (locked register);
2954 INT;
2955 break;
2956 case 0x3f:
2957 copy_till_end ();
2958 break;
2959 case 0x3e:
2960 copy_till_end ();
2961 break;
2962 case 0x40:
2963 copy_till_end ();
2964 break;
2965 case 0x41:
2966 ID;
2967 break;
2968 }
2969 }
252b5132
RH
2970}
2971
2972static void
46e94266 2973f0_record (void)
252b5132 2974{
49ae03bf 2975 /* Attribute record. */
252b5132
RH
2976 NEXT ();
2977 OUT (0xf0);
2978 INTn (Symbol name);
2979 ID;
2980}
2981
2982static void
46e94266 2983f2_record (void)
252b5132
RH
2984{
2985 NEXT ();
2986 OUT (0xf2);
2987 INT;
2988 NEXT ();
2989 OUT (0xce);
2990 INT;
2991 copy_till_end ();
2992}
2993
252b5132 2994static void
46e94266 2995f8_record (void)
252b5132
RH
2996{
2997 int ch;
2998 NEXT ();
2999 ch = THIS ();
3000 switch (ch)
3001 {
3002 case 0x01:
3003 case 0x02:
3004 case 0x03:
49ae03bf
NC
3005 /* Unique typedefs for module. */
3006 /* GLobal typedefs. */
3007 /* High level module scope beginning. */
252b5132
RH
3008 {
3009 struct output_buffer_struct ob;
49ae03bf 3010
252b5132
RH
3011 NEXT ();
3012 OUT (0xf8);
3013 OUT (ch);
3014 drop_int (&ob);
3015 ID;
3016
3017 block ();
3018
3019 NEXT ();
3020 fill_int (&ob);
3021 OUT (0xf9);
3022 }
3023 break;
3024 case 0x04:
49ae03bf 3025 /* Global function. */
252b5132
RH
3026 {
3027 struct output_buffer_struct ob;
49ae03bf 3028
252b5132
RH
3029 NEXT ();
3030 OUT (0xf8);
3031 OUT (0x04);
3032 drop_int (&ob);
3033 ID;
3034 INTn (stack size);
3035 INTn (ret val);
3036 EXPn (offset);
3037
3038 block ();
3039
3040 NEXT ();
3041 OUT (0xf9);
3042 EXPn (size of block);
3043 fill_int (&ob);
3044 }
3045 break;
3046
3047 case 0x05:
49ae03bf 3048 /* File name for source line numbers. */
252b5132
RH
3049 {
3050 struct output_buffer_struct ob;
49ae03bf 3051
252b5132
RH
3052 NEXT ();
3053 OUT (0xf8);
3054 OUT (0x05);
3055 drop_int (&ob);
3056 ID;
3057 INTn (year);
3058 INTn (month);
3059 INTn (day);
3060 INTn (hour);
3061 INTn (monute);
3062 INTn (second);
3063 block ();
3064 NEXT ();
3065 OUT (0xf9);
3066 fill_int (&ob);
3067 }
3068 break;
3069
3070 case 0x06:
49ae03bf 3071 /* Local function. */
252b5132
RH
3072 {
3073 struct output_buffer_struct ob;
49ae03bf 3074
252b5132
RH
3075 NEXT ();
3076 OUT (0xf8);
3077 OUT (0x06);
3078 drop_int (&ob);
3079 ID;
3080 INTn (stack size);
3081 INTn (type return);
3082 EXPn (offset);
3083 block ();
3084 NEXT ();
3085 OUT (0xf9);
3086 EXPn (size);
3087 fill_int (&ob);
3088 }
3089 break;
3090
3091 case 0x0a:
49ae03bf 3092 /* Assembler module scope beginning - */
252b5132
RH
3093 {
3094 struct output_buffer_struct ob;
3095
3096 NEXT ();
3097 OUT (0xf8);
3098 OUT (0x0a);
3099 drop_int (&ob);
3100 ID;
3101 ID;
3102 INT;
3103 ID;
3104 INT;
3105 INT;
3106 INT;
3107 INT;
3108 INT;
3109 INT;
3110
3111 block ();
3112
3113 NEXT ();
3114 OUT (0xf9);
3115 fill_int (&ob);
3116 }
3117 break;
3118 case 0x0b:
3119 {
3120 struct output_buffer_struct ob;
49ae03bf 3121
252b5132
RH
3122 NEXT ();
3123 OUT (0xf8);
3124 OUT (0x0b);
3125 drop_int (&ob);
3126 ID;
3127 INT;
3128 INTn (section index);
3129 EXPn (offset);
3130 INTn (stuff);
3131
3132 block ();
3133
3134 OUT (0xf9);
3135 NEXT ();
3136 EXPn (Size in Maus);
3137 fill_int (&ob);
3138 }
3139 break;
3140 }
3141}
3142
3143static void
46e94266 3144e2_record (void)
252b5132
RH
3145{
3146 OUT (0xe2);
3147 NEXT ();
3148 OUT (0xce);
3149 NEXT ();
3150 INT;
3151 EXP;
3152}
3153
3154static void
46e94266 3155block (void)
252b5132
RH
3156{
3157 int ch;
49ae03bf 3158
252b5132
RH
3159 while (1)
3160 {
3161 ch = THIS ();
3162 switch (ch)
3163 {
3164 case 0xe1:
3165 case 0xe5:
3166 return;
3167 case 0xf9:
3168 return;
3169 case 0xf0:
3170 f0_record ();
3171 break;
3172 case 0xf1:
3173 f1_record ();
3174 break;
3175 case 0xf2:
3176 f2_record ();
3177 break;
3178 case 0xf8:
3179 f8_record ();
3180 break;
3181 case 0xe2:
3182 e2_record ();
3183 break;
3184
3185 }
3186 }
3187}
3188
49ae03bf
NC
3189/* Moves all the debug information from the source bfd to the output
3190 bfd, and relocates any expressions it finds. */
252b5132
RH
3191
3192static void
46e94266
NC
3193relocate_debug (bfd *output ATTRIBUTE_UNUSED,
3194 bfd *input)
252b5132
RH
3195{
3196#define IBS 400
3197#define OBS 400
3198 unsigned char input_buffer[IBS];
3199
3200 input_ptr_start = input_ptr = input_buffer;
3201 input_ptr_end = input_buffer + IBS;
3202 input_bfd = input;
3203 /* FIXME: Check return value. I'm not sure whether it needs to read
3204 the entire buffer or not. */
c8e7bf0d 3205 bfd_bread ((void *) input_ptr_start, (bfd_size_type) IBS, input);
252b5132
RH
3206 block ();
3207}
3208
dce61835
KH
3209/* Gather together all the debug information from each input BFD into
3210 one place, relocating it and emitting it as we go. */
252b5132 3211
b34976b6 3212static bfd_boolean
46e94266 3213ieee_write_debug_part (bfd *abfd)
252b5132
RH
3214{
3215 ieee_data_type *ieee = IEEE_DATA (abfd);
3216 bfd_chain_type *chain = ieee->chain_root;
dc810e39 3217 unsigned char obuff[OBS];
b34976b6 3218 bfd_boolean some_debug = FALSE;
252b5132
RH
3219 file_ptr here = bfd_tell (abfd);
3220
dc810e39
AM
3221 output_ptr_start = output_ptr = obuff;
3222 output_ptr_end = obuff + OBS;
3223 output_ptr = obuff;
252b5132
RH
3224 output_bfd = abfd;
3225
3226 if (chain == (bfd_chain_type *) NULL)
3227 {
3228 asection *s;
3229
3230 for (s = abfd->sections; s != NULL; s = s->next)
3231 if ((s->flags & SEC_DEBUGGING) != 0)
3232 break;
3233 if (s == NULL)
3234 {
3235 ieee->w.r.debug_information_part = 0;
b34976b6 3236 return TRUE;
252b5132
RH
3237 }
3238
3239 ieee->w.r.debug_information_part = here;
eea6121a 3240 if (bfd_bwrite (s->contents, s->size, abfd) != s->size)
b34976b6 3241 return FALSE;
252b5132
RH
3242 }
3243 else
3244 {
3245 while (chain != (bfd_chain_type *) NULL)
3246 {
3247 bfd *entry = chain->this;
3248 ieee_data_type *entry_ieee = IEEE_DATA (entry);
49ae03bf 3249
252b5132
RH
3250 if (entry_ieee->w.r.debug_information_part)
3251 {
3252 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
dc810e39 3253 SEEK_SET) != 0)
b34976b6 3254 return FALSE;
252b5132
RH
3255 relocate_debug (abfd, entry);
3256 }
3257
3258 chain = chain->next;
3259 }
49ae03bf 3260
252b5132 3261 if (some_debug)
49ae03bf 3262 ieee->w.r.debug_information_part = here;
252b5132 3263 else
49ae03bf 3264 ieee->w.r.debug_information_part = 0;
252b5132
RH
3265
3266 flush ();
3267 }
3268
b34976b6 3269 return TRUE;
252b5132
RH
3270}
3271
3272/* Write the data in an ieee way. */
3273
b34976b6 3274static bfd_boolean
46e94266 3275ieee_write_data_part (bfd *abfd)
252b5132
RH
3276{
3277 asection *s;
49ae03bf 3278
252b5132
RH
3279 ieee_data_type *ieee = IEEE_DATA (abfd);
3280 ieee->w.r.data_part = bfd_tell (abfd);
49ae03bf 3281
252b5132
RH
3282 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3283 {
3284 /* Skip sections that have no loadable contents (.bss,
3285 debugging, etc.) */
3286 if ((s->flags & SEC_LOAD) == 0)
3287 continue;
3288
3289 /* Sort the reloc records so we can insert them in the correct
c8e7bf0d 3290 places. */
252b5132
RH
3291 if (s->reloc_count != 0)
3292 {
3293 if (! do_with_relocs (abfd, s))
b34976b6 3294 return FALSE;
252b5132
RH
3295 }
3296 else
3297 {
3298 if (! do_without_relocs (abfd, s))
b34976b6 3299 return FALSE;
252b5132
RH
3300 }
3301 }
3302
b34976b6 3303 return TRUE;
252b5132
RH
3304}
3305
b34976b6 3306static bfd_boolean
46e94266 3307init_for_output (bfd *abfd)
252b5132
RH
3308{
3309 asection *s;
49ae03bf 3310
252b5132
RH
3311 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3312 {
3313 if ((s->flags & SEC_DEBUGGING) != 0)
3314 continue;
eea6121a 3315 if (s->size != 0)
252b5132 3316 {
eea6121a 3317 bfd_size_type size = s->size;
c8e7bf0d 3318 ieee_per_section (s)->data = bfd_alloc (abfd, size);
252b5132 3319 if (!ieee_per_section (s)->data)
b34976b6 3320 return FALSE;
252b5132
RH
3321 }
3322 }
b34976b6 3323 return TRUE;
252b5132
RH
3324}
3325\f
49ae03bf
NC
3326/* Exec and core file sections. */
3327
3328/* Set section contents is complicated with IEEE since the format is
3329 not a byte image, but a record stream. */
252b5132 3330
b34976b6 3331static bfd_boolean
46e94266
NC
3332ieee_set_section_contents (bfd *abfd,
3333 sec_ptr section,
3334 const void * location,
3335 file_ptr offset,
3336 bfd_size_type count)
252b5132
RH
3337{
3338 if ((section->flags & SEC_DEBUGGING) != 0)
3339 {
3340 if (section->contents == NULL)
3341 {
eea6121a 3342 bfd_size_type size = section->size;
c8e7bf0d 3343 section->contents = bfd_alloc (abfd, size);
252b5132 3344 if (section->contents == NULL)
b34976b6 3345 return FALSE;
252b5132
RH
3346 }
3347 /* bfd_set_section_contents has already checked that everything
3348 is within range. */
dc810e39 3349 memcpy (section->contents + offset, location, (size_t) count);
b34976b6 3350 return TRUE;
252b5132
RH
3351 }
3352
3353 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
3354 {
3355 if (!init_for_output (abfd))
b34976b6 3356 return FALSE;
252b5132 3357 }
c8e7bf0d
NC
3358 memcpy ((void *) (ieee_per_section (section)->data + offset),
3359 (void *) location,
252b5132 3360 (unsigned int) count);
b34976b6 3361 return TRUE;
252b5132
RH
3362}
3363
3364/* Write the external symbols of a file. IEEE considers two sorts of
3365 external symbols, public, and referenced. It uses to internal
3366 forms to index them as well. When we write them out we turn their
3367 symbol values into indexes from the right base. */
3368
b34976b6 3369static bfd_boolean
46e94266 3370ieee_write_external_part (bfd *abfd)
252b5132
RH
3371{
3372 asymbol **q;
3373 ieee_data_type *ieee = IEEE_DATA (abfd);
252b5132
RH
3374 unsigned int reference_index = IEEE_REFERENCE_BASE;
3375 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
3376 file_ptr here = bfd_tell (abfd);
b34976b6 3377 bfd_boolean hadone = FALSE;
49ae03bf 3378
252b5132
RH
3379 if (abfd->outsymbols != (asymbol **) NULL)
3380 {
3381
3382 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
3383 {
3384 asymbol *p = *q;
49ae03bf 3385
252b5132
RH
3386 if (bfd_is_und_section (p->section))
3387 {
49ae03bf 3388 /* This must be a symbol reference. */
252b5132 3389 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
dc810e39 3390 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
252b5132 3391 || ! ieee_write_id (abfd, p->name))
b34976b6 3392 return FALSE;
252b5132
RH
3393 p->value = reference_index;
3394 reference_index++;
b34976b6 3395 hadone = TRUE;
252b5132
RH
3396 }
3397 else if (bfd_is_com_section (p->section))
3398 {
49ae03bf 3399 /* This is a weak reference. */
252b5132 3400 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
dc810e39 3401 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
252b5132
RH
3402 || ! ieee_write_id (abfd, p->name)
3403 || ! ieee_write_byte (abfd,
3404 ieee_weak_external_reference_enum)
dc810e39 3405 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
252b5132 3406 || ! ieee_write_int (abfd, p->value))
b34976b6 3407 return FALSE;
252b5132
RH
3408 p->value = reference_index;
3409 reference_index++;
b34976b6 3410 hadone = TRUE;
252b5132
RH
3411 }
3412 else if (p->flags & BSF_GLOBAL)
3413 {
49ae03bf 3414 /* This must be a symbol definition. */
252b5132 3415 if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
dc810e39 3416 || ! ieee_write_int (abfd, (bfd_vma) public_index)
252b5132
RH
3417 || ! ieee_write_id (abfd, p->name)
3418 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
dc810e39 3419 || ! ieee_write_int (abfd, (bfd_vma) public_index)
c8e7bf0d
NC
3420 || ! ieee_write_byte (abfd, 15) /* Instruction address. */
3421 || ! ieee_write_byte (abfd, 19) /* Static symbol. */
3422 || ! ieee_write_byte (abfd, 1)) /* One of them. */
b34976b6 3423 return FALSE;
252b5132 3424
49ae03bf 3425 /* Write out the value. */
252b5132 3426 if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
dc810e39 3427 || ! ieee_write_int (abfd, (bfd_vma) public_index))
b34976b6 3428 return FALSE;
252b5132
RH
3429 if (! bfd_is_abs_section (p->section))
3430 {
3431 if (abfd->flags & EXEC_P)
3432 {
3433 /* If fully linked, then output all symbols
49ae03bf 3434 relocated. */
252b5132
RH
3435 if (! (ieee_write_int
3436 (abfd,
3437 (p->value
3438 + p->section->output_offset
3439 + p->section->output_section->vma))))
b34976b6 3440 return FALSE;
252b5132
RH
3441 }
3442 else
3443 {
3444 if (! (ieee_write_expression
3445 (abfd,
3446 p->value + p->section->output_offset,
3447 p->section->output_section->symbol,
b34976b6
AM
3448 FALSE, 0)))
3449 return FALSE;
252b5132
RH
3450 }
3451 }
3452 else
3453 {
3454 if (! ieee_write_expression (abfd,
3455 p->value,
3456 bfd_abs_section_ptr->symbol,
b34976b6
AM
3457 FALSE, 0))
3458 return FALSE;
252b5132
RH
3459 }
3460 p->value = public_index;
3461 public_index++;
b34976b6 3462 hadone = TRUE;
252b5132
RH
3463 }
3464 else
3465 {
49ae03bf
NC
3466 /* This can happen - when there are gaps in the symbols read
3467 from an input ieee file. */
252b5132
RH
3468 }
3469 }
3470 }
3471 if (hadone)
3472 ieee->w.r.external_part = here;
3473
b34976b6 3474 return TRUE;
252b5132
RH
3475}
3476
3477
47fda0d3 3478static const unsigned char exten[] =
252b5132
RH
3479{
3480 0xf0, 0x20, 0x00,
49ae03bf
NC
3481 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3482 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
1049f94e 3483 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
252b5132
RH
3484};
3485
47fda0d3 3486static const unsigned char envi[] =
252b5132
RH
3487{
3488 0xf0, 0x21, 0x00,
3489
3490/* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3491 0x19, 0x2c,
3492*/
c8e7bf0d 3493 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */
252b5132 3494
c8e7bf0d 3495 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */
252b5132
RH
3496/* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3497};
3498
b34976b6 3499static bfd_boolean
46e94266 3500ieee_write_me_part (bfd *abfd)
252b5132
RH
3501{
3502 ieee_data_type *ieee = IEEE_DATA (abfd);
3503 ieee->w.r.trailer_part = bfd_tell (abfd);
3504 if (abfd->start_address)
3505 {
3506 if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
3507 || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
3508 || ! ieee_write_int (abfd, abfd->start_address)
3509 || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
b34976b6 3510 return FALSE;
252b5132
RH
3511 }
3512 ieee->w.r.me_record = bfd_tell (abfd);
3513 if (! ieee_write_byte (abfd, ieee_module_end_enum))
b34976b6
AM
3514 return FALSE;
3515 return TRUE;
252b5132
RH
3516}
3517
3518/* Write out the IEEE processor ID. */
3519
b34976b6 3520static bfd_boolean
46e94266 3521ieee_write_processor (bfd *abfd)
252b5132
RH
3522{
3523 const bfd_arch_info_type *arch;
3524
3525 arch = bfd_get_arch_info (abfd);
3526 switch (arch->arch)
3527 {
3528 default:
3529 if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
b34976b6 3530 return FALSE;
252b5132
RH
3531 break;
3532
252b5132
RH
3533 case bfd_arch_h8300:
3534 if (! ieee_write_id (abfd, "H8/300"))
b34976b6 3535 return FALSE;
252b5132
RH
3536 break;
3537
3538 case bfd_arch_h8500:
3539 if (! ieee_write_id (abfd, "H8/500"))
b34976b6 3540 return FALSE;
252b5132
RH
3541 break;
3542
3543 case bfd_arch_i960:
3544 switch (arch->mach)
3545 {
3546 default:
3547 case bfd_mach_i960_core:
3548 case bfd_mach_i960_ka_sa:
3549 if (! ieee_write_id (abfd, "80960KA"))
b34976b6 3550 return FALSE;
252b5132
RH
3551 break;
3552
3553 case bfd_mach_i960_kb_sb:
3554 if (! ieee_write_id (abfd, "80960KB"))
b34976b6 3555 return FALSE;
252b5132
RH
3556 break;
3557
3558 case bfd_mach_i960_ca:
3559 if (! ieee_write_id (abfd, "80960CA"))
b34976b6 3560 return FALSE;
252b5132
RH
3561 break;
3562
3563 case bfd_mach_i960_mc:
3564 case bfd_mach_i960_xa:
3565 if (! ieee_write_id (abfd, "80960MC"))
b34976b6 3566 return FALSE;
252b5132
RH
3567 break;
3568 }
3569 break;
3570
3571 case bfd_arch_m68k:
3572 {
3573 const char *id;
3574
3575 switch (arch->mach)
3576 {
3577 default: id = "68020"; break;
3578 case bfd_mach_m68000: id = "68000"; break;
3579 case bfd_mach_m68008: id = "68008"; break;
3580 case bfd_mach_m68010: id = "68010"; break;
3581 case bfd_mach_m68020: id = "68020"; break;
3582 case bfd_mach_m68030: id = "68030"; break;
3583 case bfd_mach_m68040: id = "68040"; break;
3584 case bfd_mach_m68060: id = "68060"; break;
3585 case bfd_mach_cpu32: id = "cpu32"; break;
0b2e31dc 3586 case bfd_mach_mcf_isa_a_nodiv: id = "isa-a:nodiv"; break;
266abb8f 3587 case bfd_mach_mcf_isa_a: id = "isa-a"; break;
0b2e31dc
NS
3588 case bfd_mach_mcf_isa_a_mac: id = "isa-a:mac"; break;
3589 case bfd_mach_mcf_isa_a_emac: id = "isa-a:emac"; break;
3590 case bfd_mach_mcf_isa_aplus: id = "isa-aplus"; break;
3591 case bfd_mach_mcf_isa_aplus_mac: id = "isa-aplus:mac"; break;
3592 case bfd_mach_mcf_isa_aplus_emac: id = "isa-aplus:mac"; break;
3593 case bfd_mach_mcf_isa_b_nousp: id = "isa-b:nousp"; break;
3594 case bfd_mach_mcf_isa_b_nousp_mac: id = "isa-b:nousp:mac"; break;
3595 case bfd_mach_mcf_isa_b_nousp_emac: id = "isa-b:nousp:emac"; break;
266abb8f
NS
3596 case bfd_mach_mcf_isa_b: id = "isa-b"; break;
3597 case bfd_mach_mcf_isa_b_mac: id = "isa-b:mac"; break;
3598 case bfd_mach_mcf_isa_b_emac: id = "isa-b:emac"; break;
0b2e31dc
NS
3599 case bfd_mach_mcf_isa_b_float: id = "isa-b:float"; break;
3600 case bfd_mach_mcf_isa_b_float_mac: id = "isa-b:float:mac"; break;
3601 case bfd_mach_mcf_isa_b_float_emac: id = "isa-b:float:emac"; break;
8d100c32
KH
3602 case bfd_mach_mcf_isa_c: id = "isa-c"; break;
3603 case bfd_mach_mcf_isa_c_mac: id = "isa-c:mac"; break;
3604 case bfd_mach_mcf_isa_c_emac: id = "isa-c:emac"; break;
3605 case bfd_mach_mcf_isa_c_nodiv: id = "isa-c:nodiv"; break;
3606 case bfd_mach_mcf_isa_c_nodiv_mac: id = "isa-c:nodiv:mac"; break;
3607 case bfd_mach_mcf_isa_c_nodiv_emac: id = "isa-c:nodiv:emac"; break;
252b5132
RH
3608 }
3609
3610 if (! ieee_write_id (abfd, id))
b34976b6 3611 return FALSE;
252b5132
RH
3612 }
3613 break;
3614 }
3615
b34976b6 3616 return TRUE;
252b5132
RH
3617}
3618
b34976b6 3619static bfd_boolean
46e94266 3620ieee_write_object_contents (bfd *abfd)
252b5132
RH
3621{
3622 ieee_data_type *ieee = IEEE_DATA (abfd);
3623 unsigned int i;
3624 file_ptr old;
3625
49ae03bf 3626 /* Fast forward over the header area. */
252b5132 3627 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
b34976b6 3628 return FALSE;
252b5132
RH
3629
3630 if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
3631 || ! ieee_write_processor (abfd)
3632 || ! ieee_write_id (abfd, abfd->filename))
b34976b6 3633 return FALSE;
252b5132 3634
49ae03bf 3635 /* Fast forward over the variable bits. */
252b5132 3636 if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
b34976b6 3637 return FALSE;
252b5132 3638
49ae03bf 3639 /* Bits per MAU. */
252b5132 3640 if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
b34976b6 3641 return FALSE;
49ae03bf 3642 /* MAU's per address. */
252b5132
RH
3643 if (! ieee_write_byte (abfd,
3644 (bfd_byte) (bfd_arch_bits_per_address (abfd)
3645 / bfd_arch_bits_per_byte (abfd))))
b34976b6 3646 return FALSE;
252b5132
RH
3647
3648 old = bfd_tell (abfd);
3649 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
b34976b6 3650 return FALSE;
252b5132
RH
3651
3652 ieee->w.r.extension_record = bfd_tell (abfd);
dc810e39
AM
3653 if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
3654 != sizeof (exten))
b34976b6 3655 return FALSE;
252b5132
RH
3656 if (abfd->flags & EXEC_P)
3657 {
c8e7bf0d 3658 if (! ieee_write_byte (abfd, 0x1)) /* Absolute. */
b34976b6 3659 return FALSE;
252b5132
RH
3660 }
3661 else
3662 {
c8e7bf0d 3663 if (! ieee_write_byte (abfd, 0x2)) /* Relocateable. */
b34976b6 3664 return FALSE;
252b5132
RH
3665 }
3666
3667 ieee->w.r.environmental_record = bfd_tell (abfd);
dc810e39
AM
3668 if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
3669 != sizeof (envi))
b34976b6 3670 return FALSE;
252b5132
RH
3671
3672 /* The HP emulator database requires a timestamp in the file. */
3673 {
3674 time_t now;
3675 const struct tm *t;
3676
3677 time (&now);
3678 t = (struct tm *) localtime (&now);
3679 if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
3680 || ! ieee_write_byte (abfd, 0x21)
3681 || ! ieee_write_byte (abfd, 0)
3682 || ! ieee_write_byte (abfd, 50)
dc810e39
AM
3683 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
3684 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
3685 || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
3686 || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
3687 || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
3688 || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
b34976b6 3689 return FALSE;
252b5132
RH
3690 }
3691
3692 output_bfd = abfd;
3693
3694 flush ();
3695
3696 if (! ieee_write_section_part (abfd))
b34976b6 3697 return FALSE;
252b5132
RH
3698 /* First write the symbols. This changes their values into table
3699 indeces so we cant use it after this point. */
3700 if (! ieee_write_external_part (abfd))
b34976b6 3701 return FALSE;
252b5132 3702
252b5132
RH
3703 /* Write any debugs we have been told about. */
3704 if (! ieee_write_debug_part (abfd))
b34976b6 3705 return FALSE;
252b5132
RH
3706
3707 /* Can only write the data once the symbols have been written, since
3708 the data contains relocation information which points to the
3709 symbols. */
3710 if (! ieee_write_data_part (abfd))
b34976b6 3711 return FALSE;
252b5132
RH
3712
3713 /* At the end we put the end! */
3714 if (! ieee_write_me_part (abfd))
b34976b6 3715 return FALSE;
252b5132 3716
49ae03bf 3717 /* Generate the header. */
252b5132 3718 if (bfd_seek (abfd, old, SEEK_SET) != 0)
b34976b6 3719 return FALSE;
252b5132
RH
3720
3721 for (i = 0; i < N_W_VARIABLES; i++)
3722 {
3723 if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
3724 || ! ieee_write_byte (abfd, (bfd_byte) i)
dc810e39 3725 || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
b34976b6 3726 return FALSE;
252b5132
RH
3727 }
3728
b34976b6 3729 return TRUE;
252b5132
RH
3730}
3731\f
c8e7bf0d 3732/* Native-level interface to symbols. */
252b5132
RH
3733
3734/* We read the symbols into a buffer, which is discarded when this
3735 function exits. We read the strings into a buffer large enough to
49ae03bf 3736 hold them all plus all the cached symbol entries. */
252b5132 3737
47fda0d3 3738static asymbol *
46e94266 3739ieee_make_empty_symbol (bfd *abfd)
252b5132 3740{
dc810e39 3741 bfd_size_type amt = sizeof (ieee_symbol_type);
d3ce72d0 3742 ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_zalloc (abfd, amt);
49ae03bf 3743
d3ce72d0 3744 if (!new_symbol)
252b5132 3745 return NULL;
d3ce72d0
NC
3746 new_symbol->symbol.the_bfd = abfd;
3747 return &new_symbol->symbol;
252b5132
RH
3748}
3749
3750static bfd *
46e94266 3751ieee_openr_next_archived_file (bfd *arch, bfd *prev)
252b5132
RH
3752{
3753 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
49ae03bf
NC
3754
3755 /* Take the next one from the arch state, or reset. */
252b5132 3756 if (prev == (bfd *) NULL)
49ae03bf
NC
3757 /* Reset the index - the first two entries are bogus. */
3758 ar->element_index = 2;
3759
b34976b6 3760 while (TRUE)
252b5132
RH
3761 {
3762 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
49ae03bf 3763
252b5132
RH
3764 ar->element_index++;
3765 if (ar->element_index <= ar->element_count)
3766 {
3767 if (p->file_offset != (file_ptr) 0)
3768 {
3769 if (p->abfd == (bfd *) NULL)
3770 {
3771 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3772 p->abfd->origin = p->file_offset;
3773 }
3774 return p->abfd;
3775 }
3776 }
3777 else
3778 {
3779 bfd_set_error (bfd_error_no_more_archived_files);
46e94266 3780 return NULL;
252b5132 3781 }
252b5132
RH
3782 }
3783}
3784
9c461f7d
AM
3785#define ieee_find_nearest_line _bfd_nosymbols_find_nearest_line
3786#define ieee_find_line _bfd_nosymbols_find_line
3787#define ieee_find_inliner_info _bfd_nosymbols_find_inliner_info
4ab527b0 3788
252b5132 3789static int
46e94266 3790ieee_generic_stat_arch_elt (bfd *abfd, struct stat *buf)
252b5132
RH
3791{
3792 ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
3793 ieee_data_type *ieee;
3794
3795 if (abfd->my_archive != NULL)
3796 ar = abfd->my_archive->tdata.ieee_ar_data;
3797 if (ar == (ieee_ar_data_type *) NULL)
3798 {
3799 bfd_set_error (bfd_error_invalid_operation);
3800 return -1;
3801 }
3802
3803 if (IEEE_DATA (abfd) == NULL)
3804 {
3805 if (ieee_object_p (abfd) == NULL)
3806 {
3807 bfd_set_error (bfd_error_wrong_format);
3808 return -1;
3809 }
3810 }
3811
3812 ieee = IEEE_DATA (abfd);
3813
3814 buf->st_size = ieee->w.r.me_record + 1;
3815 buf->st_mode = 0644;
3816 return 0;
3817}
3818
3819static int
46e94266 3820ieee_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
a6b96beb 3821 struct bfd_link_info *info ATTRIBUTE_UNUSED)
252b5132
RH
3822{
3823 return 0;
3824}
3825
252b5132
RH
3826#define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3827#define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3828
3829#define ieee_slurp_armap bfd_true
3830#define ieee_slurp_extended_name_table bfd_true
3831#define ieee_construct_extended_name_table \
b34976b6 3832 ((bfd_boolean (*) \
116c20d2 3833 (bfd *, char **, bfd_size_type *, const char **)) \
252b5132
RH
3834 bfd_true)
3835#define ieee_truncate_arname bfd_dont_truncate_arname
3836#define ieee_write_armap \
b34976b6 3837 ((bfd_boolean (*) \
116c20d2 3838 (bfd *, unsigned int, struct orl *, unsigned int, int)) \
252b5132
RH
3839 bfd_true)
3840#define ieee_read_ar_hdr bfd_nullvoidptr
8f95b6e4 3841#define ieee_write_ar_hdr ((bfd_boolean (*) (bfd *, bfd *)) bfd_false)
252b5132
RH
3842#define ieee_update_armap_timestamp bfd_true
3843#define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3844
60bb06bc
L
3845#define ieee_get_symbol_version_string \
3846 _bfd_nosymbols_get_symbol_version_string
3c9458e9
NC
3847#define ieee_bfd_is_target_special_symbol \
3848 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
252b5132
RH
3849#define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3850#define ieee_get_lineno _bfd_nosymbols_get_lineno
3851#define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3852#define ieee_read_minisymbols _bfd_generic_read_minisymbols
3853#define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3854
3855#define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
157090f7 3856#define ieee_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
252b5132
RH
3857
3858#define ieee_set_arch_mach _bfd_generic_set_arch_mach
3859
3860#define ieee_get_section_contents_in_window \
3861 _bfd_generic_get_section_contents_in_window
3862#define ieee_bfd_get_relocated_section_contents \
3863 bfd_generic_get_relocated_section_contents
3864#define ieee_bfd_relax_section bfd_generic_relax_section
3865#define ieee_bfd_gc_sections bfd_generic_gc_sections
ae17ab41 3866#define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
8550eb6e 3867#define ieee_bfd_merge_sections bfd_generic_merge_sections
72adc230 3868#define ieee_bfd_is_group_section bfd_generic_is_group_section
e61463e1 3869#define ieee_bfd_discard_group bfd_generic_discard_group
082b7297
L
3870#define ieee_section_already_linked \
3871 _bfd_generic_section_already_linked
3023e3f6 3872#define ieee_bfd_define_common_symbol bfd_generic_define_common_symbol
252b5132
RH
3873#define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3874#define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
2d653fc7 3875#define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
1338dd10
PB
3876#define ieee_bfd_copy_link_hash_symbol_type \
3877 _bfd_generic_copy_link_hash_symbol_type
252b5132
RH
3878#define ieee_bfd_final_link _bfd_generic_final_link
3879#define ieee_bfd_link_split_section _bfd_generic_link_split_section
4f3b23b3 3880#define ieee_bfd_link_check_relocs _bfd_generic_link_check_relocs
252b5132 3881
252b5132
RH
3882const bfd_target ieee_vec =
3883{
116c20d2 3884 "ieee", /* Name. */
252b5132 3885 bfd_target_ieee_flavour,
116c20d2
NC
3886 BFD_ENDIAN_UNKNOWN, /* Target byte order. */
3887 BFD_ENDIAN_UNKNOWN, /* Target headers byte order. */
3888 (HAS_RELOC | EXEC_P | /* Object flags. */
252b5132
RH
3889 HAS_LINENO | HAS_DEBUG |
3890 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3891 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
116c20d2
NC
3892 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
3893 '_', /* Leading underscore. */
3894 ' ', /* AR_pad_char. */
3895 16, /* AR_max_namelen. */
0aabe54e 3896 0, /* match priority. */
252b5132
RH
3897 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3898 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
116c20d2 3899 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
252b5132
RH
3900 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3901 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
116c20d2 3902 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
252b5132
RH
3903
3904 {_bfd_dummy_target,
116c20d2 3905 ieee_object_p, /* bfd_check_format. */
252b5132
RH
3906 ieee_archive_p,
3907 _bfd_dummy_target,
3908 },
3909 {
3910 bfd_false,
3911 ieee_mkobject,
3912 _bfd_generic_mkarchive,
3913 bfd_false
3914 },
3915 {
3916 bfd_false,
3917 ieee_write_object_contents,
3918 _bfd_write_archive_contents,
3919 bfd_false,
3920 },
3921
47fda0d3 3922 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
c8e7bf0d 3923 ieee_get_section_contents, ieee_get_section_contents_in_window. */
252b5132 3924 BFD_JUMP_TABLE_GENERIC (ieee),
47fda0d3 3925
252b5132
RH
3926 BFD_JUMP_TABLE_COPY (_bfd_generic),
3927 BFD_JUMP_TABLE_CORE (_bfd_nocore),
47fda0d3
AM
3928
3929 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
3930 ieee_construct_extended_name_table, ieee_truncate_arname,
3931 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
3932 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
c8e7bf0d 3933 ieee_update_armap_timestamp. */
252b5132 3934 BFD_JUMP_TABLE_ARCHIVE (ieee),
47fda0d3 3935
6cee3f79
AC
3936 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
3937 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
3938 ieee_bfd_is_local_label_name, ieee_get_lineno,
3939 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
c8e7bf0d 3940 ieee_read_minisymbols, ieee_minisymbol_to_symbol. */
252b5132 3941 BFD_JUMP_TABLE_SYMBOLS (ieee),
47fda0d3
AM
3942
3943 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
c8e7bf0d 3944 ieee_bfd_reloc_type_lookup. */
252b5132 3945 BFD_JUMP_TABLE_RELOCS (ieee),
47fda0d3 3946
c8e7bf0d 3947 /* ieee_set_arch_mach, ieee_set_section_contents. */
252b5132 3948 BFD_JUMP_TABLE_WRITE (ieee),
47fda0d3
AM
3949
3950 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
3951 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
3952 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
3953 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
c8e7bf0d 3954 ieee_bfd_merge_sections. */
252b5132 3955 BFD_JUMP_TABLE_LINK (ieee),
47fda0d3 3956
252b5132
RH
3957 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
3958
c3c89269 3959 NULL,
dc810e39 3960
116c20d2 3961 NULL
252b5132 3962};
This page took 2.321145 seconds and 4 git commands to generate.