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