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