1 /* bfd back-end for ieee-695 objects.
3 IEEE 695 format is a stream of records, which we parse using a simple one-
4 token (which is one byte in this lexicon) lookahead recursive decent
7 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
9 This file is part of BFD, the Binary File Diddler.
11 BFD is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 1, or (at your option)
16 BFD is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with BFD; see the file COPYING. If not, write to
23 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
32 /* Functions for writing to ieee files in the strange way that the
36 DEFUN(ieee_write_byte
,(abfd
, byte
),
40 bfd_write((PTR
)&byte
, 1, 1, abfd
);
45 DEFUN(ieee_write_2bytes
,(abfd
, bytes
),
50 buffer
[0] = bytes
>> 8;
51 buffer
[1] = bytes
& 0xff;
53 bfd_write((PTR
)buffer
, 1, 2, abfd
);
57 DEFUN(ieee_write_int
,(abfd
, value
),
61 if (value
>= 0 && value
<= 127) {
62 ieee_write_byte(abfd
, value
);
66 /* How many significant bytes ? */
67 /* FIXME FOR LONGER INTS */
68 if (value
& 0xff000000) {
71 else if (value
& 0x00ff0000) {
74 else if (value
& 0x0000ff00) {
79 ieee_write_byte(abfd
, (int)ieee_number_repeat_start_enum
+ length
);
82 ieee_write_byte(abfd
, value
>> 24);
84 ieee_write_byte(abfd
, value
>> 16);
86 ieee_write_byte(abfd
, value
>> 8);
88 ieee_write_byte(abfd
, value
);
94 DEFUN(ieee_write_id
,(abfd
, id
),
98 size_t length
= strlen(id
);
99 if (length
>= 0 && length
<= 127) {
100 ieee_write_byte(abfd
, length
);
102 else if (length
< 255) {
103 ieee_write_byte(abfd
, ieee_extension_length_1_enum
);
104 ieee_write_byte(abfd
, length
);
106 else if (length
< 65535) {
107 ieee_write_byte(abfd
, ieee_extension_length_2_enum
);
108 ieee_write_byte(abfd
, length
>> 8);
109 ieee_write_byte(abfd
, length
& 0xff);
114 bfd_write((PTR
)id
, 1, length
, abfd
);
116 /***************************************************************************
117 Functions for reading from ieee files in the strange way that the
122 #define this_byte(ieee) *((ieee)->input_p)
123 #define next_byte(ieee) ((ieee)->input_p++)
124 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
127 static unsigned short
128 DEFUN(read_2bytes
,(ieee
),
129 common_header_type
*ieee
)
131 unsigned char c1
= this_byte_and_next(ieee
);
132 unsigned char c2
= this_byte_and_next(ieee
);
133 return (c1
<<8 ) | c2
;
138 DEFUN(bfd_get_string
,(ieee
, string
, length
),
139 common_header_type
*ieee AND
144 for (i
= 0; i
< length
; i
++) {
145 string
[i
] = this_byte_and_next(ieee
);
150 DEFUN(read_id
,(ieee
),
151 common_header_type
*ieee
)
155 length
= this_byte_and_next(ieee
);
156 if (length
>= 0x00 && length
<= 0x7f) {
157 /* Simple string of length 0 to 127 */
159 else if (length
== 0xde) {
160 /* Length is next byte, allowing 0..255 */
161 length
= this_byte_and_next(ieee
);
163 else if (length
== 0xdf) {
164 /* Length is next two bytes, allowing 0..65535 */
165 length
= this_byte_and_next(ieee
) ;
166 length
= (length
* 256) + this_byte_and_next(ieee
);
168 /* Buy memory and read string */
169 string
= bfd_alloc(ieee
->abfd
, length
+1);
170 bfd_get_string(ieee
, string
, length
);
176 DEFUN(ieee_write_expression
,(abfd
, value
, section
, symbol
, pcrel
, index
),
179 asection
*section AND
184 unsigned int plus_count
= 0;
185 ieee_write_int(abfd
, value
);
186 if (section
!= (asection
*)NULL
) {
188 ieee_write_byte(abfd
, ieee_variable_L_enum
);
189 ieee_write_byte(abfd
, section
->index
+IEEE_SECTION_NUMBER_BASE
);
194 if (symbol
!= (asymbol
*)NULL
) {
196 if ((symbol
->flags
& BSF_UNDEFINED
) ||
197 (symbol
->flags
& BSF_FORT_COMM
)) {
198 ieee_write_byte(abfd
, ieee_variable_X_enum
);
199 ieee_write_int(abfd
, symbol
->value
);
201 else if (symbol
->flags
& BSF_GLOBAL
) {
202 ieee_write_byte(abfd
, ieee_variable_I_enum
);
203 ieee_write_int(abfd
, symbol
->value
);
205 else if (symbol
->flags
& BSF_LOCAL
) {
206 /* This is a reference to a defined local symbol,
207 We can easily do a local as a section+offset */
208 if (symbol
->section
!= (asection
*)NULL
) {
209 /* If this symbol is not absolute, add the base of it */
210 ieee_write_byte(abfd
, ieee_variable_L_enum
);
211 ieee_write_byte(abfd
, symbol
->section
->index
+
212 IEEE_SECTION_NUMBER_BASE
);
216 ieee_write_int(abfd
, symbol
->value
);
225 /* subtract the pc from here by asking for PC of this section*/
226 ieee_write_byte(abfd
, ieee_variable_P_enum
);
227 ieee_write_byte(abfd
, index
+IEEE_SECTION_NUMBER_BASE
);
228 ieee_write_byte(abfd
, ieee_function_minus_enum
);
231 while (plus_count
> 0) {
232 ieee_write_byte(abfd
, ieee_function_plus_enum
);
246 /*****************************************************************************/
249 writes any integer into the buffer supplied and always takes 5 bytes
252 DEFUN(ieee_write_int5
,(buffer
, value
),
256 buffer
[0] = ieee_number_repeat_4_enum
;
257 buffer
[1] = (value
>> 24 ) & 0xff;
258 buffer
[2] = (value
>> 16 ) & 0xff;
259 buffer
[3] = (value
>> 8 ) & 0xff;
260 buffer
[4] = (value
>> 0 ) & 0xff;
263 DEFUN(ieee_write_int5_out
, (abfd
, value
),
268 ieee_write_int5(b
, value
);
269 bfd_write((PTR
)b
,1,5,abfd
);
274 DEFUN(parse_int
,(ieee
, value_ptr
),
275 common_header_type
*ieee AND
278 int value
= this_byte(ieee
);
280 if (value
>= 0 && value
<= 127) {
285 else if (value
>= 0x80 && value
<= 0x88) {
286 unsigned int count
= value
& 0xf;
290 result
=(result
<< 8) | this_byte_and_next(ieee
);
299 DEFUN(parse_i
,(ieee
, ok
),
300 common_header_type
*ieee AND
304 *ok
= parse_int(ieee
, &x
);
309 DEFUN(must_parse_int
,(ieee
),
310 common_header_type
*ieee
)
313 BFD_ASSERT(parse_int(ieee
, &result
) == true);
321 ieee_symbol_index_type symbol
;
326 reloc_howto_type abs32_howto
327 = HOWTO(1,0,2,32,0,0,0,true,0,"abs32",true,0xffffffff, 0xffffffff,false);
329 reloc_howto_type abs16_howto
330 = HOWTO(1,0,1,16,0,0,0,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false);
333 reloc_howto_type rel32_howto
334 = HOWTO(1,0,2,32,1,0,0,true,0,"rel32",true,0xffffffff, 0xffffffff,false);
336 reloc_howto_type rel16_howto
337 = HOWTO(1,0,1,16,1,0,0,true,0,"rel16",true,0x0000ffff, 0x0000ffff,false);
339 static ieee_symbol_index_type NOSYMBOL
= { 0, 0};
343 DEFUN(parse_expression
,(ieee
, value
, section
, symbol
, pcrel
, extra
),
344 ieee_data_type
*ieee AND
346 asection
**section AND
347 ieee_symbol_index_type
*symbol AND
359 ieee_value_type stack
[10];
361 /* The stack pointer always points to the next unused location */
362 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
363 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
364 ieee_value_type
*sp
= stack
;
367 switch (this_byte(&(ieee
->h
)))
369 case ieee_variable_P_enum
:
370 /* P variable, current program counter for section n */
373 next_byte(&(ieee
->h
));
375 section_n
= must_parse_int(&(ieee
->h
));
377 TOS
.value
= ieee
->section_table
[section_n
]->vma
+
378 ieee_per_section(ieee
->section_table
[section_n
])->pc
);
381 case ieee_variable_L_enum
:
382 /* L variable address of section N */
383 next_byte(&(ieee
->h
));
384 PUSH(NOSYMBOL
,ieee
->section_table
[must_parse_int(&(ieee
->h
))],0);
386 case ieee_variable_R_enum
:
387 /* R variable, logical address of section module */
388 /* FIXME, this should be different to L */
389 next_byte(&(ieee
->h
));
390 PUSH(NOSYMBOL
,ieee
->section_table
[must_parse_int(&(ieee
->h
))],0);
392 case ieee_variable_S_enum
:
393 /* S variable, size in MAUS of section module */
394 next_byte(&(ieee
->h
));
397 ieee
->section_table
[must_parse_int(&(ieee
->h
))]->size
);
400 case ieee_variable_X_enum
:
401 /* Push the address of external variable n */
403 ieee_symbol_index_type sy
;
404 next_byte(&(ieee
->h
));
405 sy
.index
= (int)(must_parse_int(&(ieee
->h
))) ;
411 case ieee_function_minus_enum
:
413 bfd_vma value1
, value2
;
414 asection
*section1
, *section_dummy
;
415 ieee_symbol_index_type sy
;
416 next_byte(&(ieee
->h
));
418 POP(sy
, section1
, value1
);
419 POP(sy
, section_dummy
, value2
);
420 PUSH(sy
, section1
, value1
-value2
);
423 case ieee_function_plus_enum
:
425 bfd_vma value1
, value2
;
428 ieee_symbol_index_type sy1
;
429 ieee_symbol_index_type sy2
;
430 next_byte(&(ieee
->h
));
432 POP(sy1
, section1
, value1
);
433 POP(sy2
, section2
, value2
);
434 PUSH(sy1
.letter
? sy1
: sy2
, section1
? section1
: section2
, value1
+value2
);
440 BFD_ASSERT(this_byte(&(ieee
->h
)) < (int)ieee_variable_A_enum
441 || this_byte(&(ieee
->h
)) > (int)ieee_variable_Z_enum
);
442 if (parse_int(&(ieee
->h
), &va
))
444 PUSH(NOSYMBOL
,0, va
);
448 Thats all that we can understand. As far as I can see
449 there is a bug in the Microtec IEEE output which I'm
450 using to scan, whereby the comma operator is ommited
451 sometimes in an expression, giving expressions with too
452 many terms. We can tell if that's the case by ensuring
453 that sp == stack here. If not, then we've pushed
454 something too far, so we keep adding
457 while (sp
!= stack
+1) {
459 ieee_symbol_index_type sy1
;
460 POP(sy1
, section1
, *extra
);
463 POP(*symbol
, *section
, *value
);
474 #define ieee_seek(abfd, offset) \
475 ieee_data(abfd)->h.input_p = ieee_data(abfd)->h.first_byte + offset
477 #define ieee_pos(abfd) ieee_data(abfd)->h.input_p -ieee_data(abfd)->h.first_byte
480 DEFUN(ieee_slurp_external_symbols
,(abfd
),
483 ieee_data_type
*ieee
= ieee_data(abfd
);
484 file_ptr offset
= ieee
->w
.r
.external_part
;
486 ieee_symbol_type
**prev_symbols_ptr
= &ieee
->external_symbols
;
487 ieee_symbol_type
**prev_reference_ptr
= &ieee
->external_reference
;
488 ieee_symbol_type
*symbol
;
489 unsigned int symbol_count
= 0;
492 ieee
->symbol_table_full
= true;
494 ieee_seek(abfd
, offset
);
497 switch (this_byte(&(ieee
->h
))) {
498 case ieee_external_symbol_enum
:
499 next_byte(&(ieee
->h
));
500 symbol
= (ieee_symbol_type
*)bfd_alloc(ieee
->h
.abfd
, sizeof(ieee_symbol_type
));
502 *prev_symbols_ptr
= symbol
;
503 prev_symbols_ptr
= &symbol
->next
;
504 symbol
->index
= must_parse_int(&(ieee
->h
));
505 if (symbol
->index
> ieee
->external_symbol_max_index
) {
506 ieee
->external_symbol_max_index
= symbol
->index
;
508 BFD_ASSERT (symbol
->index
>= ieee
->external_symbol_min_index
);
510 symbol
->symbol
.the_bfd
= abfd
;
511 symbol
->symbol
.name
= read_id(&(ieee
->h
));
512 symbol
->symbol
.udata
= (PTR
)NULL
;
513 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
515 case ieee_attribute_record_enum
>> 8:
517 unsigned int symbol_name_index
;
518 unsigned int symbol_type_index
;
519 unsigned int symbol_attribute_def
;
521 next_byte(&(ieee
->h
)); /* Skip prefix */
522 next_byte(&(ieee
->h
));
523 symbol_name_index
= must_parse_int(&(ieee
->h
));
524 symbol_type_index
= must_parse_int(&(ieee
->h
));
525 symbol_attribute_def
= must_parse_int(&(ieee
->h
));
527 parse_int(&(ieee
->h
),&value
);
531 case ieee_value_record_enum
>> 8:
533 unsigned int symbol_name_index
;
534 ieee_symbol_index_type symbol_ignore
;
535 boolean pcrel_ignore
;
537 next_byte(&(ieee
->h
));
538 next_byte(&(ieee
->h
));
540 symbol_name_index
= must_parse_int(&(ieee
->h
));
541 parse_expression(ieee
,
542 &symbol
->symbol
.value
,
543 &symbol
->symbol
.section
,
547 if (symbol
->symbol
.section
!= (asection
*)NULL
) {
548 symbol
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
;
551 symbol
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
| BSF_ABSOLUTE
;
555 case ieee_weak_external_reference_enum
:
558 next_byte(&(ieee
->h
));
559 /* Throw away the external reference index */
560 (void)must_parse_int(&(ieee
->h
));
561 /* Fetch the default size if not resolved */
562 size
= must_parse_int(&(ieee
->h
));
563 /* Fetch the defautlt value if available */
564 if ( parse_int(&(ieee
->h
), &value
) == false) {
567 /* This turns into a common */
568 symbol
->symbol
.flags
= BSF_FORT_COMM
;
569 symbol
->symbol
.value
= size
;
573 case ieee_external_reference_enum
:
574 next_byte(&(ieee
->h
));
575 symbol
= (ieee_symbol_type
*)bfd_alloc(ieee
->h
.abfd
, sizeof(ieee_symbol_type
));
577 *prev_reference_ptr
= symbol
;
578 prev_reference_ptr
= &symbol
->next
;
579 symbol
->index
= must_parse_int(&(ieee
->h
));
580 symbol
->symbol
.the_bfd
= abfd
;
581 symbol
->symbol
.name
= read_id(&(ieee
->h
));
582 symbol
->symbol
.udata
= (PTR
)NULL
;
583 symbol
->symbol
.section
= (asection
*)NULL
;
584 symbol
->symbol
.value
= (bfd_vma
)0;
585 symbol
->symbol
.flags
= BSF_UNDEFINED
;
586 if (symbol
->index
> ieee
->external_reference_max_index
) {
587 ieee
->external_reference_max_index
= symbol
->index
;
589 BFD_ASSERT (symbol
->index
>= ieee
->external_reference_min_index
);
597 if (ieee
->external_symbol_max_index
!= 0) {
598 ieee
->external_symbol_count
=
599 ieee
->external_symbol_max_index
-
600 ieee
->external_symbol_min_index
+ 1 ;
603 ieee
->external_symbol_count
= 0;
607 if(ieee
->external_reference_max_index
!= 0) {
608 ieee
->external_reference_count
=
609 ieee
->external_reference_max_index
-
610 ieee
->external_reference_min_index
+ 1;
613 ieee
->external_reference_count
= 0;
617 ieee
->external_reference_count
+ ieee
->external_symbol_count
;
619 if (symbol_count
!= abfd
->symcount
) {
620 /* There are gaps in the table -- */
621 ieee
->symbol_table_full
= false;
623 *prev_symbols_ptr
= (ieee_symbol_type
*)NULL
;
624 *prev_reference_ptr
= (ieee_symbol_type
*)NULL
;
628 DEFUN(ieee_slurp_symbol_table
,(abfd
),
631 if (ieee_data(abfd
)->read_symbols
== false) {
632 ieee_slurp_external_symbols(abfd
);
633 ieee_data(abfd
)->read_symbols
= true;
638 DEFUN(ieee_get_symtab_upper_bound
,(abfd
),
641 ieee_slurp_symbol_table (abfd
);
643 return (abfd
->symcount
!= 0) ?
644 (abfd
->symcount
+1) * (sizeof (ieee_symbol_type
*)) : 0;
648 Move from our internal lists to the canon table, and insert in
652 extern bfd_target ieee_vec
;
654 DEFUN(ieee_get_symtab
,(abfd
, location
),
658 ieee_symbol_type
*symp
;
659 static bfd dummy_bfd
;
660 static asymbol empty_symbol
=
661 { &dummy_bfd
," ieee empty",(symvalue
)0,BSF_DEBUGGING
| BSF_ABSOLUTE
};
664 ieee_data_type
*ieee
= ieee_data(abfd
);
665 dummy_bfd
.xvec
= &ieee_vec
;
666 ieee_slurp_symbol_table(abfd
);
668 if (ieee
->symbol_table_full
== false) {
669 /* Arrgh - there are gaps in the table, run through and fill them */
670 /* up with pointers to a null place */
672 for (i
= 0; i
< abfd
->symcount
; i
++) {
673 location
[i
] = &empty_symbol
;
678 ieee
->external_symbol_base_offset
= - ieee
->external_symbol_min_index
;
679 for (symp
= ieee_data(abfd
)->external_symbols
;
680 symp
!= (ieee_symbol_type
*)NULL
;
682 /* Place into table at correct index locations */
683 location
[symp
->index
+ ieee
->external_symbol_base_offset
] = &symp
->symbol
;
687 /* The external refs are indexed in a bit */
688 ieee
->external_reference_base_offset
=
689 - ieee
->external_reference_min_index
+ieee
->external_symbol_count
;
691 for (symp
= ieee_data(abfd
)->external_reference
;
692 symp
!= (ieee_symbol_type
*)NULL
;
694 location
[symp
->index
+ ieee
->external_reference_base_offset
] =
701 location
[abfd
->symcount
] = (asymbol
*)NULL
;
703 return abfd
->symcount
;
708 DEFUN(ieee_slurp_sections
,(abfd
),
711 ieee_data_type
*ieee
= ieee_data(abfd
);
712 file_ptr offset
= ieee
->w
.r
.section_part
;
714 asection
*section
= (asection
*)NULL
;
717 bfd_byte section_type
[3];
718 ieee_seek(abfd
, offset
);
720 switch (this_byte(&(ieee
->h
))) {
721 case ieee_section_type_enum
:
723 unsigned int section_index
;
724 next_byte(&(ieee
->h
));
725 section_index
= must_parse_int(&(ieee
->h
));
726 /* Fixme to be nice about a silly number of sections */
727 BFD_ASSERT(section_index
< NSECTIONS
);
729 section
= bfd_make_section(abfd
, " tempname");
730 ieee
->section_table
[section_index
] = section
;
731 section
->flags
= SEC_NO_FLAGS
;
732 section
->target_index
= section_index
;
733 section_type
[0] = this_byte_and_next(&(ieee
->h
));
734 switch (section_type
[0]) {
736 section_type
[1] = this_byte(&(ieee
->h
));
737 section
->flags
= SEC_LOAD
| SEC_ALLOC
| SEC_HAS_CONTENTS
;
738 switch (section_type
[1]) {
741 next_byte(&(ieee
->h
));
742 section
->flags
|= SEC_LOAD
| SEC_CODE
;
745 next_byte(&(ieee
->h
));
746 section
->flags
|= SEC_LOAD
| SEC_DATA
;
750 next_byte(&(ieee
->h
));
751 /* Normal rom data */
752 section
->flags
|= SEC_LOAD
| SEC_ROM
| SEC_DATA
;
758 section
->name
= read_id(&(ieee
->h
));
759 { bfd_vma parent
, brother
, context
;
760 parse_int(&(ieee
->h
), &parent
);
761 parse_int(&(ieee
->h
), &brother
);
762 parse_int(&(ieee
->h
), &context
);
768 case ieee_section_alignment_enum
:
770 unsigned int section_index
;
772 next_byte(&(ieee
->h
));
773 section_index
= must_parse_int(&ieee
->h
);
774 if (section_index
> ieee
->section_count
) {
775 ieee
->section_count
= section_index
;
777 ieee
->section_table
[section_index
]->alignment_power
=
778 bfd_log2(must_parse_int(&ieee
->h
));
779 (void)parse_int(&(ieee
->h
), & value
);
782 case ieee_e2_first_byte_enum
:
784 ieee_record_enum_type t
= read_2bytes(&(ieee
->h
));
786 case ieee_section_size_enum
:
787 section
= ieee
->section_table
[must_parse_int(&(ieee
->h
))];
788 section
->size
= must_parse_int(&(ieee
->h
));
790 case ieee_physical_region_size_enum
:
791 section
= ieee
->section_table
[must_parse_int(&(ieee
->h
))];
792 section
->size
= must_parse_int(&(ieee
->h
));
794 case ieee_region_base_address_enum
:
795 section
= ieee
->section_table
[must_parse_int(&(ieee
->h
))];
796 section
->vma
= must_parse_int(&(ieee
->h
));
798 case ieee_mau_size_enum
:
799 must_parse_int(&(ieee
->h
));
800 must_parse_int(&(ieee
->h
));
802 case ieee_m_value_enum
:
803 must_parse_int(&(ieee
->h
));
804 must_parse_int(&(ieee
->h
));
806 case ieee_section_base_address_enum
:
807 section
= ieee
->section_table
[must_parse_int(&(ieee
->h
))];
808 section
->vma
= must_parse_int(&(ieee
->h
));
810 case ieee_section_offset_enum
:
811 (void) must_parse_int(&(ieee
->h
));
812 (void) must_parse_int(&(ieee
->h
));
826 /***********************************************************************
830 DEFUN(ieee_archive_p
,(abfd
),
837 uint8e_type buffer
[512];
839 int buffer_offset
= 0;
840 ieee_ar_data_type
*save
= ieee_ar_data(abfd
);
841 ieee_ar_data_type
*ieee
;
842 set_tdata(abfd
, bfd_alloc(abfd
, sizeof(ieee_ar_data_type
)));
843 ieee
= ieee_ar_data(abfd
);
846 bfd_read((PTR
)buffer
, 1, sizeof(buffer
), abfd
);
848 ieee
->h
.first_byte
= buffer
;
849 ieee
->h
.input_p
= buffer
;
853 if (this_byte(&(ieee
->h
)) != Module_Beginning
) return (bfd_target
*)NULL
;
855 next_byte(&(ieee
->h
));
856 library
= read_id(&(ieee
->h
));
857 if (strcmp(library
, "LIBRARY") != 0) {
858 bfd_release(abfd
, ieee
);
859 set_tdata (abfd
, save
);
860 return (bfd_target
*)NULL
;
862 /* Throw away the filename */
863 free( read_id(&(ieee
->h
)));
864 /* This must be an IEEE archive, so we'll buy some space to do
866 ieee
->element_count
= 0;
867 ieee
->element_index
= 0;
869 next_byte(&(ieee
->h
)); /* Drop the ad part */
870 must_parse_int(&(ieee
->h
)); /* And the two dummy numbers */
871 must_parse_int(&(ieee
->h
));
874 /* Read the index of the BB table */
876 ieee_ar_obstack_type t
;
877 int rec
=read_2bytes(&(ieee
->h
));
878 if (rec
==ieee_assign_value_to_variable_enum
) {
879 int record_number
= must_parse_int(&(ieee
->h
));
880 t
.file_offset
= must_parse_int(&(ieee
->h
));
881 t
.abfd
= (bfd
*)NULL
;
882 ieee
->element_count
++;
883 bfd_alloc_grow(abfd
, (PTR
)&t
, sizeof(t
));
885 /* Make sure that we don't go over the end of the buffer */
887 if (ieee_pos(abfd
) > sizeof(buffer
)/2) {
888 /* Past half way, reseek and reprime */
889 buffer_offset
+= ieee_pos(abfd
);
890 bfd_seek(abfd
, buffer_offset
, SEEK_SET
);
891 bfd_read(buffer
, 1, sizeof(buffer
), abfd
);
892 ieee
->h
.first_byte
= buffer
;
893 ieee
->h
.input_p
= buffer
;
899 ieee
->elements
= (ieee_ar_obstack_type
*)bfd_alloc_finish(abfd
);
901 /* Now scan the area again, and replace BB offsets with file */
905 for (i
= 2; i
< ieee
->element_count
; i
++) {
906 bfd_seek(abfd
, ieee
->elements
[i
].file_offset
, SEEK_SET
);
907 bfd_read(buffer
, 1, sizeof(buffer
), abfd
);
908 ieee
->h
.first_byte
= buffer
;
909 ieee
->h
.input_p
= buffer
;
911 next_byte(&(ieee
->h
)); /* Drop F8 */
912 next_byte(&(ieee
->h
)); /* Drop 14 */
913 must_parse_int(&(ieee
->h
)); /* Drop size of block */
914 if (must_parse_int(&(ieee
->h
)) != 0) {
915 /* This object has been deleted */
916 ieee
->elements
[i
].file_offset
= 0;
919 ieee
->elements
[i
].file_offset
= must_parse_int(&(ieee
->h
));
928 DEFUN(ieee_mkobject
,(abfd
),
931 set_tdata (abfd
, bfd_zalloc(abfd
,sizeof(ieee_data_type
)));
938 DEFUN(ieee_object_p
,(abfd
),
943 ieee_data_type
*ieee
;
944 uint8e_type buffer
[300];
945 ieee_data_type
*save
= ieee_data(abfd
);
948 ieee
= ieee_data(abfd
);
950 /* Read the first few bytes in to see if it makes sense */
951 bfd_read((PTR
)buffer
, 1, sizeof(buffer
), abfd
);
953 ieee
->h
.input_p
= buffer
;
954 if (this_byte_and_next(&(ieee
->h
)) != Module_Beginning
) goto fail
;
956 ieee
->read_symbols
= false;
957 ieee
->read_data
= false;
958 ieee
->section_count
= 0;
959 ieee
->external_symbol_max_index
= 0;
960 ieee
->external_symbol_min_index
= IEEE_PUBLIC_BASE
;
961 ieee
->external_reference_min_index
=IEEE_REFERENCE_BASE
;
962 ieee
->external_reference_max_index
= 0;
964 memset((PTR
)ieee
->section_table
, 0, sizeof(ieee
->section_table
));
966 processor
= ieee
->mb
.processor
= read_id(&(ieee
->h
));
967 if (strcmp(processor
,"LIBRARY") == 0) goto fail
;
968 ieee
->mb
.module_name
= read_id(&(ieee
->h
));
969 if (abfd
->filename
== (char *)NULL
) {
970 abfd
->filename
= ieee
->mb
.module_name
;
972 /* Determine the architecture and machine type of the object file. */
973 bfd_scan_arch_mach(processor
, &abfd
->obj_arch
, &abfd
->obj_machine
);
975 if (this_byte(&(ieee
->h
)) != ieee_address_descriptor_enum
) {
978 next_byte(&(ieee
->h
));
980 if (parse_int(&(ieee
->h
), &ieee
->ad
.number_of_bits_mau
) == false) {
983 if(parse_int(&(ieee
->h
), &ieee
->ad
.number_of_maus_in_address
) == false) {
987 /* If there is a byte order info, take it */
988 if (this_byte(&(ieee
->h
)) == ieee_variable_L_enum
||
989 this_byte(&(ieee
->h
)) == ieee_variable_M_enum
)
990 next_byte(&(ieee
->h
));
993 for (part
= 0; part
< N_W_VARIABLES
; part
++) {
995 if (read_2bytes(&(ieee
->h
)) != ieee_assign_value_to_variable_enum
) {
998 if (this_byte_and_next(&(ieee
->h
)) != part
) {
1002 ieee
->w
.offset
[part
] = parse_i(&(ieee
->h
), &ok
);
1008 abfd
->flags
= HAS_SYMS
;
1010 /* By now we know that this is a real IEEE file, we're going to read
1011 the whole thing into memory so that we can run up and down it
1012 quickly. We can work out how big the file is from the trailer
1015 ieee_data(abfd
)->h
.first_byte
= (uint8e_type
*) bfd_alloc(ieee
->h
.abfd
, ieee
->w
.r
.me_record
1017 bfd_seek(abfd
, 0, 0);
1018 bfd_read((PTR
)(ieee_data(abfd
)->h
.first_byte
), 1, ieee
->w
.r
.me_record
+50, abfd
);
1020 ieee_slurp_sections(abfd
);
1023 (void) bfd_release(abfd
, ieee
);
1024 set_tdata (abfd
, save
);
1025 return (bfd_target
*)NULL
;
1030 DEFUN(ieee_print_symbol
,(ignore_abfd
, afile
, symbol
, how
),
1031 bfd
*ignore_abfd AND
1034 bfd_print_symbol_enum_type how
)
1036 FILE *file
= (FILE *)afile
;
1039 case bfd_print_symbol_name_enum
:
1040 fprintf(file
,"%s", symbol
->name
);
1042 case bfd_print_symbol_type_enum
:
1044 fprintf(file
,"%4x %2x",aout_symbol(symbol
)->desc
& 0xffff,
1045 aout_symbol(symbol
)->other
& 0xff);
1049 case bfd_print_symbol_all_enum
:
1051 CONST
char *section_name
= symbol
->section
== (asection
*)NULL
?
1052 "*abs" : symbol
->section
->name
;
1053 if (symbol
->name
[0] == ' ') {
1054 fprintf(file
,"* empty table entry ");
1057 bfd_print_symbol_vandf((PTR
)file
,symbol
);
1059 fprintf(file
," %-5s %04x %02x %s",
1061 (unsigned) ieee_symbol(symbol
)->index
,
1063 aout_symbol(symbol)->desc & 0xffff,
1064 aout_symbol(symbol)->other & 0xff,*/
1074 DEFUN(do_one
,(ieee
, current_map
, location_ptr
,s
),
1075 ieee_data_type
*ieee AND
1076 ieee_per_section_type
*current_map AND
1077 uint8e_type
*location_ptr AND
1080 switch (this_byte(&(ieee
->h
)))
1082 case ieee_load_constant_bytes_enum
:
1084 unsigned int number_of_maus
;
1086 next_byte(&(ieee
->h
));
1087 number_of_maus
= must_parse_int(&(ieee
->h
));
1089 for (i
= 0; i
< number_of_maus
; i
++) {
1090 location_ptr
[current_map
->pc
++]= this_byte(&(ieee
->h
));
1091 next_byte(&(ieee
->h
));
1096 case ieee_load_with_relocation_enum
:
1098 boolean loop
= true;
1099 next_byte(&(ieee
->h
));
1102 switch (this_byte(&(ieee
->h
)))
1104 case ieee_variable_R_enum
:
1106 case ieee_function_signed_open_b_enum
:
1107 case ieee_function_unsigned_open_b_enum
:
1108 case ieee_function_either_open_b_enum
:
1110 unsigned int extra
= 4;
1111 boolean pcrel
= false;
1113 ieee_reloc_type
*r
=
1114 (ieee_reloc_type
*) bfd_alloc(ieee
->h
.abfd
,
1115 sizeof(ieee_reloc_type
));
1117 *(current_map
->reloc_tail_ptr
) = r
;
1118 current_map
->reloc_tail_ptr
= &r
->next
;
1119 r
->next
= (ieee_reloc_type
*)NULL
;
1120 next_byte(&(ieee
->h
));
1121 parse_expression(ieee
,
1126 r
->relent
.address
= current_map
->pc
;
1128 switch (this_byte(&(ieee
->h
))) {
1129 case ieee_function_signed_close_b_enum
:
1130 next_byte(&(ieee
->h
));
1132 case ieee_function_unsigned_close_b_enum
:
1133 next_byte(&(ieee
->h
));
1135 case ieee_function_either_close_b_enum
:
1136 next_byte(&(ieee
->h
));
1141 /* Build a relocation entry for this type */
1142 if (this_byte(&(ieee
->h
)) == ieee_comma
) {
1143 next_byte(&(ieee
->h
));
1144 /* Fetch number of bytes to pad */
1145 extra
= must_parse_int(&(ieee
->h
));
1148 /* If pc rel then stick -ve pc into instruction
1149 and take out of reloc*/
1157 bfd_put_32(ieee
->h
.abfd
, -current_map
->pc
, location_ptr
+
1159 r
->relent
.howto
= &rel32_howto
;
1160 r
->relent
.addend
-= current_map
->pc
;
1164 bfd_put_32(ieee
->h
.abfd
, 0, location_ptr
+
1166 r
->relent
.howto
= &abs32_howto
;
1168 current_map
->pc
+=4;
1171 if (pcrel
== true) {
1172 bfd_put_16(ieee
->h
.abfd
, (int)(-current_map
->pc
), location_ptr
+current_map
->pc
);
1173 r
->relent
.addend
-= current_map
->pc
;
1174 r
->relent
.howto
= &rel16_howto
;
1177 bfd_put_16(ieee
->h
.abfd
, 0, location_ptr
+current_map
->pc
);
1178 r
->relent
.howto
= &abs16_howto
;
1180 current_map
->pc
+=2;
1192 if (parse_int(&(ieee
->h
), &this_size
) == true) {
1194 for (i
= 0; i
< this_size
; i
++) {
1195 location_ptr
[current_map
->pc
++] = this_byte(&(ieee
->h
));
1196 next_byte(&(ieee
->h
));
1209 /* Read in all the section data and relocation stuff too */
1211 DEFUN(ieee_slurp_section_data
,(abfd
),
1214 bfd_byte
*location_ptr
;
1215 ieee_data_type
*ieee
= ieee_data(abfd
);
1216 unsigned int section_number
;
1218 ieee_per_section_type
*current_map
;
1220 /* Seek to the start of the data area */
1221 if (ieee
->read_data
== true) return true;
1222 ieee
->read_data
= true;
1223 ieee_seek(abfd
, ieee
->w
.r
.data_part
);
1225 /* Allocate enough space for all the section contents */
1228 for (s
= abfd
->sections
; s
!= (asection
*)NULL
; s
= s
->next
) {
1229 ieee_per_section_type
*per
= (ieee_per_section_type
*) s
->used_by_bfd
;
1230 per
->data
= (bfd_byte
*) bfd_alloc(ieee
->h
.abfd
, s
->size
);
1232 per
->reloc_tail_ptr
=
1233 (ieee_reloc_type
**)&(s
->relocation
);
1239 switch (this_byte(&(ieee
->h
)))
1241 /* IF we see anything strange then quit */
1245 case ieee_set_current_section_enum
:
1246 next_byte(&(ieee
->h
));
1247 section_number
= must_parse_int(&(ieee
->h
));
1248 s
= ieee
->section_table
[section_number
];
1249 current_map
= (ieee_per_section_type
*) s
->used_by_bfd
;
1250 location_ptr
= current_map
->data
- s
->vma
;
1251 /* The document I have says that Microtec's compilers reset */
1252 /* this after a sec section, even though the standard says not */
1254 current_map
->pc
=s
->vma
;
1258 case ieee_e2_first_byte_enum
:
1259 next_byte(&(ieee
->h
));
1260 switch (this_byte(&(ieee
->h
)))
1262 case ieee_set_current_pc_enum
& 0xff:
1266 ieee_symbol_index_type symbol
;
1269 next_byte(&(ieee
->h
));
1270 must_parse_int(&(ieee
->h
)); /* Thow away section #*/
1271 parse_expression(ieee
, &value
, &dsection
, &symbol
,
1273 current_map
->pc
= value
;
1274 BFD_ASSERT((unsigned)(value
- s
->vma
) <= s
->size
);
1278 case ieee_value_starting_address_enum
& 0xff:
1279 /* We've got to the end of the data now - */
1286 case ieee_repeat_data_enum
:
1288 /* Repeat the following LD or LR n times - we do this by
1289 remembering the stream pointer before running it and
1290 resetting it and running it n times. We special case
1291 the repetition of a repeat_data/load_constant
1294 unsigned int iterations
;
1295 uint8e_type
*start
;
1296 next_byte(&(ieee
->h
));
1297 iterations
= must_parse_int(&(ieee
->h
));
1298 start
= ieee
->h
.input_p
;
1299 if (start
[0] == ieee_load_constant_bytes_enum
&&
1301 while (iterations
!= 0) {
1302 location_ptr
[current_map
->pc
++] = start
[2];
1305 next_byte(&(ieee
->h
));
1306 next_byte(&(ieee
->h
));
1307 next_byte(&(ieee
->h
));
1310 while (iterations
!= 0) {
1311 ieee
->h
.input_p
= start
;
1312 do_one(ieee
, current_map
, location_ptr
,s
);
1318 case ieee_load_constant_bytes_enum
:
1319 case ieee_load_with_relocation_enum
:
1321 do_one(ieee
, current_map
, location_ptr
,s
);
1332 DEFUN(ieee_new_section_hook
,(abfd
, newsect
),
1336 newsect
->used_by_bfd
= (PTR
)
1337 bfd_alloc(abfd
, sizeof(ieee_per_section_type
));
1338 ieee_per_section( newsect
)->data
= (bfd_byte
*)NULL
;
1339 ieee_per_section(newsect
)->section
= newsect
;
1345 DEFUN(ieee_get_reloc_upper_bound
,(abfd
, asect
),
1349 ieee_slurp_section_data(abfd
);
1350 return (asect
->reloc_count
+1) * sizeof(arelent
*);
1354 DEFUN(ieee_get_section_contents
,(abfd
, section
, location
, offset
, count
),
1359 bfd_size_type count
)
1361 ieee_per_section_type
*p
= (ieee_per_section_type
*) section
->used_by_bfd
;
1362 ieee_slurp_section_data(abfd
);
1363 (void) memcpy(location
, p
->data
+ offset
, (unsigned)count
);
1369 DEFUN(ieee_canonicalize_reloc
,(abfd
, section
, relptr
, symbols
),
1372 arelent
**relptr AND
1375 /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/
1376 ieee_reloc_type
*src
= (ieee_reloc_type
*)(section
->relocation
);
1377 ieee_data_type
*ieee
= ieee_data(abfd
);
1379 while (src
!= (ieee_reloc_type
*)NULL
) {
1380 /* Work out which symbol to attatch it this reloc to */
1381 switch (src
->symbol
.letter
) {
1383 src
->relent
.sym_ptr_ptr
=
1384 symbols
+ src
->symbol
.index
+ ieee
->external_reference_base_offset
;
1387 src
->relent
.sym_ptr_ptr
= (asymbol
**)NULL
;
1393 *relptr
++ = &src
->relent
;
1396 *relptr
= (arelent
*)NULL
;
1397 return section
->reloc_count
;
1401 DEFUN(ieee_set_arch_mach
,(abfd
, arch
, machine
),
1403 enum bfd_architecture arch AND
1404 unsigned long machine
)
1406 abfd
->obj_arch
= arch
;
1407 abfd
->obj_machine
= machine
;
1413 DEFUN(comp
,(ap
, bp
),
1417 arelent
*a
= *((arelent
**)ap
);
1418 arelent
*b
= *((arelent
**)bp
);
1419 return a
->address
- b
->address
;
1423 Write the section headers
1427 DEFUN(ieee_write_section_part
,(abfd
),
1430 ieee_data_type
*ieee
= ieee_data(abfd
);
1432 ieee
->w
.r
.section_part
= bfd_tell(abfd
);
1433 for (s
= abfd
->sections
; s
!= (asection
*)NULL
; s
=s
->next
) {
1434 ieee_write_byte(abfd
, ieee_section_type_enum
);
1435 ieee_write_byte(abfd
, s
->index
+ IEEE_SECTION_NUMBER_BASE
);
1437 if (abfd
->flags
& EXEC_P
)
1439 /* This image is executable, so output absolute sections */
1440 ieee_write_byte(abfd
, ieee_variable_A_enum
);
1441 ieee_write_byte(abfd
, ieee_variable_S_enum
);
1445 ieee_write_byte(abfd
, ieee_variable_C_enum
);
1448 switch (s
->flags
&(SEC_CODE
| SEC_DATA
| SEC_ROM
))
1450 case SEC_CODE
| SEC_LOAD
:
1452 ieee_write_byte(abfd
, ieee_variable_P_enum
);
1456 ieee_write_byte(abfd
, ieee_variable_D_enum
);
1459 case SEC_ROM
| SEC_DATA
:
1460 case SEC_ROM
| SEC_LOAD
:
1461 case SEC_ROM
| SEC_DATA
| SEC_LOAD
:
1463 ieee_write_byte(abfd
, ieee_variable_R_enum
);
1467 ieee_write_id(abfd
, s
->name
);
1469 ieee_write_int(abfd
, 0); /* Parent */
1470 ieee_write_int(abfd
, 0); /* Brother */
1471 ieee_write_int(abfd
, 0); /* Context */
1474 ieee_write_byte(abfd
, ieee_section_alignment_enum
);
1475 ieee_write_byte(abfd
, s
->index
+ IEEE_SECTION_NUMBER_BASE
);
1476 ieee_write_int(abfd
, 1 << s
->alignment_power
);
1479 ieee_write_2bytes(abfd
, ieee_section_size_enum
);
1480 ieee_write_byte(abfd
, s
->index
+ IEEE_SECTION_NUMBER_BASE
);
1481 ieee_write_int(abfd
, s
->size
);
1484 ieee_write_2bytes(abfd
, ieee_section_base_address_enum
);
1485 ieee_write_byte(abfd
, s
->index
+ IEEE_SECTION_NUMBER_BASE
);
1486 ieee_write_int(abfd
, s
->vma
);
1494 DEFUN(do_with_relocs
,(abfd
, s
),
1498 unsigned int relocs_to_go
= s
->reloc_count
;
1499 bfd_byte header
[11];
1501 bfd_byte
*stream
= ieee_per_section(s
)->data
;
1502 arelent
**p
= s
->orelocation
;
1504 bfd_size_type current_byte_index
= 0;
1506 qsort(s
->orelocation
,
1513 /* Output the section preheader */
1514 header
[0] =ieee_set_current_section_enum
;
1515 header
[1] = s
->index
+ IEEE_SECTION_NUMBER_BASE
;
1517 header
[2] = ieee_set_current_pc_enum
>> 8;
1518 header
[3]= ieee_set_current_pc_enum
& 0xff;
1519 header
[4] = s
->index
+ IEEE_SECTION_NUMBER_BASE
;
1520 ieee_write_int5(header
+5, s
->vma
);
1521 header
[10] = ieee_load_with_relocation_enum
;
1522 bfd_write((PTR
)header
, 1, sizeof(header
), abfd
);
1524 /* Output the data stream as the longest sequence of bytes
1525 possible, allowing for the a reasonable packet size and
1526 relocation stuffs */
1528 if ((PTR
)stream
== (PTR
)NULL
) {
1529 /* Outputting a section without data, fill it up */
1530 stream
= (uint8e_type
*)(bfd_alloc(abfd
, s
->size
));
1531 memset((PTR
)stream
, 0, s
->size
);
1533 while (current_byte_index
< s
->size
) {
1535 unsigned int MAXRUN
= 32;
1537 run
= (*p
)->address
- current_byte_index
;
1542 if (run
> s
->size
- current_byte_index
) {
1543 run
= s
->size
- current_byte_index
;
1547 /* Output a stream of bytes */
1548 ieee_write_int(abfd
, run
);
1549 bfd_write((PTR
)(stream
+ current_byte_index
),
1553 current_byte_index
+= run
;
1555 /* Output any relocations here */
1556 if (relocs_to_go
&& (*p
) && (*p
)->address
== current_byte_index
) {
1557 while (relocs_to_go
&& (*p
) && (*p
)->address
== current_byte_index
) {
1561 if (r
->howto
->pc_relative
) {
1562 r
->addend
+= current_byte_index
;
1565 switch (r
->howto
->size
) {
1568 ov
= bfd_get_32(abfd
,
1569 stream
+current_byte_index
);
1570 current_byte_index
+=4;
1573 ov
= bfd_get_16(abfd
,
1574 stream
+current_byte_index
);
1575 current_byte_index
+=2;
1580 ieee_write_byte(abfd
, ieee_function_either_open_b_enum
);
1582 if (r
->sym_ptr_ptr
!= (asymbol
**)NULL
) {
1583 ieee_write_expression(abfd
, r
->addend
+ ov
,
1586 r
->howto
->pc_relative
, s
->target_index
);
1589 ieee_write_expression(abfd
, r
->addend
+ ov
,
1592 r
->howto
->pc_relative
, s
->target_index
);
1594 ieee_write_byte(abfd
,
1595 ieee_function_either_close_b_enum
);
1596 if (r
->howto
->size
!= 2) {
1597 ieee_write_byte(abfd
, ieee_comma
);
1598 ieee_write_int(abfd
, 1<< r
->howto
->size
);
1609 /* If there are no relocations in the output section then we can
1610 be clever about how we write. We block items up into a max of 127
1614 DEFUN(do_as_repeat
, (abfd
, s
),
1618 ieee_write_byte(abfd
, ieee_set_current_section_enum
);
1619 ieee_write_byte(abfd
, s
->index
+ IEEE_SECTION_NUMBER_BASE
);
1620 ieee_write_byte(abfd
, ieee_set_current_pc_enum
>> 8);
1621 ieee_write_byte(abfd
, ieee_set_current_pc_enum
& 0xff);
1622 ieee_write_byte(abfd
, s
->index
+ IEEE_SECTION_NUMBER_BASE
);
1623 ieee_write_int(abfd
, s
->vma
);
1625 ieee_write_byte(abfd
,ieee_repeat_data_enum
);
1626 ieee_write_int(abfd
, s
->size
);
1627 ieee_write_byte(abfd
, ieee_load_constant_bytes_enum
);
1628 ieee_write_byte(abfd
, 1);
1629 ieee_write_byte(abfd
, 0);
1633 DEFUN(do_without_relocs
, (abfd
, s
),
1637 bfd_byte
*stream
= ieee_per_section(s
)->data
;
1639 if (stream
== 0 || ((s
->flags
& SEC_LOAD
) == 0))
1641 do_as_repeat(abfd
, s
);
1646 for (i
= 0; i
< s
->size
; i
++) {
1647 if (stream
[i
] != 0) {
1648 do_with_relocs(abfd
, s
);
1652 do_as_repeat(abfd
, s
);
1658 static unsigned char *output_ptr_start
;
1659 static unsigned char *output_ptr
;
1660 static unsigned char *output_ptr_end
;
1661 static unsigned char *input_ptr_start
;
1662 static unsigned char *input_ptr
;
1663 static unsigned char *input_ptr_end
;
1664 static bfd
*input_bfd
;
1665 static bfd
*output_bfd
;
1666 static int output_buffer
;
1670 bfd_read(input_ptr_start
, 1, input_ptr_end
- input_ptr_start
, input_bfd
);
1671 input_ptr
= input_ptr_start
;
1675 bfd_write(output_ptr_start
,1,output_ptr
- output_ptr_start
, output_bfd
);
1676 output_ptr
= output_ptr_start
;
1680 #define THIS() ( *input_ptr )
1681 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
1682 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
1684 static void write_int(value
)
1687 if (value
>= 0 && value
<= 127) {
1691 unsigned int length
;
1692 /* How many significant bytes ? */
1693 /* FIXME FOR LONGER INTS */
1694 if (value
& 0xff000000) {
1697 else if (value
& 0x00ff0000) {
1700 else if (value
& 0x0000ff00) {
1705 OUT((int)ieee_number_repeat_start_enum
+ length
);
1719 static void copy_id()
1721 int length
= THIS();
1731 #define VAR(x) ((x | 0x80))
1732 static void copy_expression()
1741 value
= THIS(); NEXT();
1742 value
= (value
<< 8) | THIS(); NEXT();
1743 value
= (value
<< 8) | THIS(); NEXT();
1744 value
= (value
<< 8) | THIS(); NEXT();
1749 value
= THIS(); NEXT();
1750 value
= (value
<< 8) | THIS(); NEXT();
1751 value
= (value
<< 8) | THIS(); NEXT();
1756 value
= THIS(); NEXT();
1757 value
= (value
<< 8) | THIS(); NEXT();
1762 value
= THIS(); NEXT();
1771 /* Not a number, just bug out with the answer */
1772 write_int(*(--tos
));
1782 int value
= *(--tos
);
1790 int section_number
;
1791 ieee_data_type
*ieee
;
1794 section_number
= THIS();
1797 ieee
= ieee_data(input_bfd
);
1798 s
= ieee
->section_table
[section_number
];
1799 if (s
->output_section
) {
1800 value
= s
->output_section
->vma
;
1801 } else { value
= 0; }
1802 value
+= s
->output_offset
;
1810 write_int(*(--tos
));
1820 /* Drop the int in the buffer, and copy a null into the gap, which we
1821 will overwrite later */
1823 struct output_buffer_struct
{
1824 unsigned char *ptrp
;
1829 DEFUN(fill_int
,(buf
),
1830 struct output_buffer_struct
*buf
)
1832 if (buf
->buffer
== output_buffer
) {
1833 /* Still a chance to output the size */
1834 int value
= output_ptr
- buf
->ptrp
+ 3;
1835 buf
->ptrp
[0] = value
>> 24;
1836 buf
->ptrp
[1] = value
>> 16;
1837 buf
->ptrp
[2] = value
>> 8;
1838 buf
->ptrp
[3] = value
>> 0;
1843 DEFUN(drop_int
,(buf
),
1844 struct output_buffer_struct
*buf
)
1851 case 0x84: ch
= THIS(); NEXT();
1852 case 0x83: ch
= THIS(); NEXT();
1853 case 0x82: ch
= THIS(); NEXT();
1854 case 0x81: ch
= THIS(); NEXT();
1859 buf
->ptrp
= output_ptr
;
1860 buf
->buffer
= output_buffer
;
1861 OUT(0);OUT(0);OUT(0);OUT(0);
1864 static void copy_int()
1872 case 0x84: ch
= THIS(); NEXT(); OUT(ch
);
1873 case 0x83: ch
= THIS(); NEXT(); OUT(ch
);
1874 case 0x82: ch
= THIS(); NEXT(); OUT(ch
);
1875 case 0x81: ch
= THIS(); NEXT(); OUT(ch
);
1881 #define ID copy_id()
1882 #define INT copy_int()
1883 #define EXP copy_expression()
1884 static void copy_till_end();
1885 #define INTn(q) copy_int()
1886 #define EXPn(q) copy_expression()
1887 static void f1_record()
1900 OUT(0xf1); OUT(0xc9);
1901 INT
; INT
; ch
= THIS();
1904 case 0x16: NEXT();break;
1905 case 0x01: NEXT();break;
1906 case 0x00: NEXT(); INT
; break;
1907 case 0x03: NEXT(); INT
; break;
1908 case 0x13: EXPn(instruction address
); break;
1916 OUT(0xf1); OUT(0xd8);
1917 EXP
; EXP
; EXP
; EXP
;
1921 OUT(0xf1);OUT(0xce); INT
; INT
; ch
= THIS(); INT
;
1928 EXPn(external function
); break;
1931 case 0x07: INTn(line number
); INT
;
1933 case 0x0a: INTn(locked
register); INT
; break;
1934 case 0x3f: copy_till_end(); break;
1935 case 0x3e: copy_till_end(); break;
1936 case 0x40: copy_till_end(); break;
1937 case 0x41: ID
; break;
1942 static void f0_record()
1944 /* Attribute record */
1950 static void copy_till_end()
1985 static void f2_record()
1998 static void block();
1999 static void f8_record()
2009 /* Unique typedefs for module */
2010 /* GLobal typedefs */
2011 /* High level module scope beginning */
2013 struct output_buffer_struct ob
;
2026 /* Global function */
2028 struct output_buffer_struct ob
;
2030 OUT(0xf8); OUT(0x04);
2031 drop_int(&ob
); ID
; INTn(stack size
); INTn(ret val
);
2038 EXPn(size of block
);
2044 /* File name for source line numbers */
2046 struct output_buffer_struct ob
;
2048 OUT(0xf8); OUT(0x05);
2050 ID
; INTn(year
); INTn(month
); INTn(day
);
2051 INTn(hour
); INTn(monute
); INTn(second
);
2060 /* Local function */
2061 { struct output_buffer_struct ob
;
2062 NEXT(); OUT(0xf8); OUT(0x06);
2064 ID
; INTn(stack size
); INTn(type
return);
2075 /* Assembler module scope beginning -*/
2076 { struct output_buffer_struct ob
;
2079 OUT(0xf8); OUT(0x0a);
2081 ID
; ID
; INT
; ID
; INT
; INT
; INT
; INT
; INT
; INT
;
2092 struct output_buffer_struct ob
;
2094 OUT(0xf8); OUT(0x0b);
2095 drop_int(&ob
); ID
; INT
; INTn(section index
); EXPn(offset
); INTn(stuff
);
2108 static void e2_record()
2118 static void DEFUN_VOID(block
)
2152 moves all the debug information from the source bfd to the output
2153 bfd, and relocates any expressions it finds
2157 DEFUN(relocate_debug
,(output
, input
),
2163 unsigned char input_buffer
[IBS
];
2165 input_ptr_start
= input_ptr
= input_buffer
;
2166 input_ptr_end
= input_buffer
+ IBS
;
2168 bfd_read(input_ptr_start
, 1, IBS
, input
);
2172 During linking, we we told about the bfds which made up our
2173 contents, we have a list of them. They will still be open, so go to
2174 the debug info in each, and copy it out, relocating it as we go.
2178 DEFUN(ieee_write_debug_part
, (abfd
),
2181 ieee_data_type
*ieee
= ieee_data(abfd
);
2182 bfd_chain_type
*chain
= ieee
->chain_root
;
2183 unsigned char output_buffer
[OBS
];
2184 output_ptr_start
= output_ptr
= output_buffer
;
2185 output_ptr_end
= output_buffer
+ OBS
;
2186 output_ptr
= output_buffer
;
2188 ieee
->w
.r
.debug_information_part
= bfd_tell(abfd
);
2189 while (chain
!= (bfd_chain_type
*)NULL
) {
2190 bfd
*entry
= chain
->this;
2191 ieee_data_type
*entry_ieee
= ieee_data(entry
);
2192 if (entry_ieee
->w
.r
.debug_information_part
) {
2193 bfd_seek(entry
, entry_ieee
->w
.r
.debug_information_part
, SEEK_SET
);
2194 relocate_debug(abfd
, entry
);
2197 chain
= chain
->next
;
2203 /* write the data in an ieee way */
2205 DEFUN(ieee_write_data_part
,(abfd
),
2209 ieee_data_type
*ieee
= ieee_data(abfd
);
2210 ieee
->w
.r
.data_part
= bfd_tell(abfd
);
2211 for (s
= abfd
->sections
; s
!= (asection
*)NULL
; s
= s
->next
)
2213 /* Sort the reloc records so we can insert them in the correct
2215 if (s
->reloc_count
!= 0)
2217 do_with_relocs(abfd
, s
);
2221 do_without_relocs(abfd
, s
);
2229 DEFUN(init_for_output
,(abfd
),
2233 for (s
= abfd
->sections
; s
!= (asection
*)NULL
; s
= s
->next
) {
2235 ieee_per_section(s
)->data
= (bfd_byte
*)(bfd_alloc(abfd
, s
->size
));
2240 /** exec and core file sections */
2242 /* set section contents is complicated with IEEE since the format is
2243 * not a byte image, but a record stream.
2246 DEFUN(ieee_set_section_contents
,(abfd
, section
, location
, offset
, count
),
2251 bfd_size_type count
)
2253 if (ieee_per_section(section
)->data
== (bfd_byte
*)NULL
) {
2254 init_for_output(abfd
);
2256 (void) memcpy(ieee_per_section(section
)->data
+ offset
,
2258 (unsigned int)count
);
2263 write the external symbols of a file, IEEE considers two sorts of
2264 external symbols, public, and referenced. It uses to internal forms
2265 to index them as well. When we write them out we turn their symbol
2266 values into indexes from the right base.
2269 DEFUN(ieee_write_external_part
,(abfd
),
2273 ieee_data_type
*ieee
= ieee_data(abfd
);
2275 unsigned int reference_index
= IEEE_REFERENCE_BASE
;
2276 unsigned int public_index
= IEEE_PUBLIC_BASE
;
2277 ieee
->w
.r
.external_part
= bfd_tell(abfd
);
2278 if (abfd
->outsymbols
!= (asymbol
**)NULL
) {
2279 for (q
= abfd
->outsymbols
; *q
!= (asymbol
*)NULL
; q
++) {
2281 if (p
->flags
& BSF_UNDEFINED
) {
2282 /* This must be a symbol reference .. */
2283 ieee_write_byte(abfd
, ieee_external_reference_enum
);
2284 ieee_write_int(abfd
, reference_index
);
2285 ieee_write_id(abfd
, p
->name
);
2286 p
->value
= reference_index
;
2289 else if(p
->flags
& BSF_FORT_COMM
) {
2290 /* This is a weak reference */
2291 ieee_write_byte(abfd
, ieee_external_reference_enum
);
2292 ieee_write_int(abfd
, reference_index
);
2293 ieee_write_id(abfd
, p
->name
);
2294 ieee_write_byte(abfd
, ieee_weak_external_reference_enum
);
2295 ieee_write_int(abfd
, reference_index
);
2296 ieee_write_int(abfd
, p
->value
);
2297 ieee_write_int(abfd
, BFD_FORT_COMM_DEFAULT_VALUE
);
2298 p
->value
= reference_index
;
2301 else if(p
->flags
& BSF_GLOBAL
) {
2302 /* This must be a symbol definition */
2304 ieee_write_byte(abfd
, ieee_external_symbol_enum
);
2305 ieee_write_int(abfd
, public_index
);
2306 ieee_write_id(abfd
, p
->name
);
2308 /* Write out the value */
2309 ieee_write_2bytes(abfd
, ieee_value_record_enum
);
2310 ieee_write_int(abfd
, public_index
);
2311 if (p
->section
!= (asection
*)NULL
)
2313 if (abfd
->flags
& EXEC_P
)
2315 /* If fully linked, then output all symbols
2317 ieee_write_int(abfd
,
2318 p
->value
+ p
->section
->output_offset
+ p
->section
->output_section
->vma
);
2322 ieee_write_expression(abfd
,
2323 p
->value
+ p
->section
->output_offset
,
2324 p
->section
->output_section
,
2325 (asymbol
*)NULL
, false, 0);
2330 ieee_write_expression(abfd
,
2333 (asymbol
*)NULL
, false, 0);
2335 p
->value
= public_index
;
2339 /* This can happen - when there are gaps in the symbols read */
2340 /* from an input ieee file */
2349 DEFUN(ieee_write_me_part
,(abfd
),
2352 ieee_data_type
*ieee
= ieee_data(abfd
);
2353 ieee
->w
.r
.me_record
= bfd_tell(abfd
);
2355 ieee_write_2bytes(abfd
, ieee_value_starting_address_enum
);
2356 ieee_write_int(abfd
, abfd
->start_address
);
2357 ieee_write_byte(abfd
, ieee_module_end_enum
);
2361 DEFUN(ieee_write_object_contents
,(abfd
),
2364 ieee_data_type
*ieee
= ieee_data(abfd
);
2367 /* Fast forward over the header area */
2368 bfd_seek(abfd
, 0, 0);
2369 ieee_write_byte(abfd
, ieee_module_beginning_enum
);
2371 ieee_write_id(abfd
, bfd_printable_arch_mach(abfd
->obj_arch
,
2372 abfd
->obj_machine
));
2373 ieee_write_id(abfd
, abfd
->filename
);
2378 /* Fast forward over the variable bits */
2382 ieee_write_byte(abfd
, ieee_address_descriptor_enum
);
2383 ieee_write_byte(abfd
, 8); /* Bits per MAU */
2384 ieee_write_byte(abfd
, 4); /* MAU's per address */
2386 old
= bfd_tell(abfd
);
2387 bfd_seek(abfd
, 8 * N_W_VARIABLES
, 1);
2390 ieee
->w
.r
.extension_record
= bfd_tell(abfd
);
2391 ieee
->w
.r
.environmental_record
= bfd_tell(abfd
);
2392 ieee_write_byte(abfd
, 0xf0);
2393 ieee_write_byte(abfd
, 0x20);
2394 ieee_write_byte(abfd
, 0x00);
2395 ieee_write_byte(abfd
, 0xf1);
2396 ieee_write_byte(abfd
, 0xce);
2397 ieee_write_byte(abfd
, 0x20);
2398 ieee_write_byte(abfd
, 0x00);
2399 ieee_write_byte(abfd
, 0x55);
2400 ieee_write_id(abfd
,"built using BFD");
2405 First write the symbols, this changes their values into table
2406 indeces so we cant use it after this point
2408 ieee_write_external_part(abfd
);
2409 ieee_write_byte(abfd
, ieee_record_seperator_enum
);
2411 ieee_write_section_part(abfd
);
2412 ieee_write_byte(abfd
, ieee_record_seperator_enum
);
2416 Write any debugs we have been told about
2418 ieee_write_debug_part(abfd
);
2421 Can only write the data once the symbols have been written since
2422 the data contains relocation information which points to the
2425 ieee_write_data_part(abfd
);
2426 ieee_write_byte(abfd
, ieee_record_seperator_enum
);
2429 At the end we put the end !
2431 ieee_write_me_part(abfd
);
2434 /* Generate the header */
2435 bfd_seek(abfd
, old
, false);
2437 for (i
= 0; i
< N_W_VARIABLES
; i
++) {
2438 ieee_write_2bytes(abfd
,ieee_assign_value_to_variable_enum
);
2439 ieee_write_byte(abfd
, i
);
2440 ieee_write_int5_out(abfd
, ieee
->w
.offset
[i
]);
2448 /* Native-level interface to symbols. */
2450 /* We read the symbols into a buffer, which is discarded when this
2451 function exits. We read the strings into a buffer large enough to
2452 hold them all plus all the cached symbol entries. */
2455 DEFUN(ieee_make_empty_symbol
,(abfd
),
2459 ieee_symbol_type
*new =
2460 (ieee_symbol_type
*)zalloc (sizeof (ieee_symbol_type
));
2461 new->symbol
.the_bfd
= abfd
;
2462 return &new->symbol
;
2467 DEFUN(ieee_openr_next_archived_file
,(arch
, prev
),
2471 ieee_ar_data_type
*ar
= ieee_ar_data(arch
);
2472 /* take the next one from the arch state, or reset */
2473 if (prev
== (bfd
*)NULL
) {
2474 /* Reset the index - the first two entries are bogus*/
2475 ar
->element_index
= 2;
2478 ieee_ar_obstack_type
*p
= ar
->elements
+ ar
->element_index
;
2479 ar
->element_index
++;
2480 if (ar
->element_index
<= ar
->element_count
) {
2481 if (p
->file_offset
!= (file_ptr
)0) {
2482 if (p
->abfd
== (bfd
*)NULL
) {
2483 p
->abfd
= _bfd_create_empty_archive_element_shell(arch
);
2484 p
->abfd
->origin
= p
->file_offset
;
2490 bfd_error
= no_more_archived_files
;
2498 ieee_find_nearest_line(abfd
,
2509 char **filename_ptr
;
2510 char **functionname_ptr
;
2518 ieee_generic_stat_arch_elt(abfd
, buf
)
2522 ieee_ar_data_type
*ar
= ieee_ar_data(abfd
);
2523 if (ar
== (ieee_ar_data_type
*)NULL
) {
2524 bfd_error
= invalid_operation
;
2529 buf
->st_mode
= 0666;
2534 DEFUN(ieee_sizeof_headers
,(abfd
, x
),
2544 DEFUN(ieee_bfd_debug_info_start
,(abfd
),
2551 DEFUN(ieee_bfd_debug_info_end
,(abfd
),
2558 /* Add this section to the list of sections we have debug info for, to
2559 be ready to output it at close time
2562 DEFUN(ieee_bfd_debug_info_accumulate
,(abfd
, section
),
2566 ieee_data_type
*ieee
= ieee_data(section
->owner
);
2567 ieee_data_type
*output_ieee
= ieee_data(abfd
);
2568 /* can only accumulate data from other ieee bfds */
2569 if (section
->owner
->xvec
!= abfd
->xvec
)
2571 /* Only bother once per bfd */
2572 if (ieee
->done_debug
== true)
2574 ieee
->done_debug
= true;
2576 /* Don't bother if there is no debug info */
2577 if (ieee
->w
.r
.debug_information_part
== 0)
2583 bfd_chain_type
*n
= (bfd_chain_type
*) bfd_alloc(abfd
, sizeof(bfd_chain_type
));
2584 n
->this = section
->owner
;
2585 n
->next
= (bfd_chain_type
*)NULL
;
2587 if (output_ieee
->chain_head
) {
2588 output_ieee
->chain_head
->next
= n
;
2591 output_ieee
->chain_root
= n
;
2594 output_ieee
->chain_head
= n
;
2604 #define ieee_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
2605 #define ieee_core_file_failing_signal (int (*)())bfd_0
2606 #define ieee_core_file_matches_executable_p ( FOO(boolean, (*),(bfd *, bfd *)))bfd_false
2607 #define ieee_slurp_armap bfd_true
2608 #define ieee_slurp_extended_name_table bfd_true
2609 #define ieee_truncate_arname (void (*)())bfd_nullvoidptr
2610 #define ieee_write_armap (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, int, int))) bfd_nullvoidptr
2611 #define ieee_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
2612 #define ieee_close_and_cleanup bfd_generic_close_and_cleanup
2616 bfd_target ieee_vec
=
2619 bfd_target_ieee_flavour_enum
,
2620 true, /* target byte order */
2621 true, /* target headers byte order */
2622 (HAS_RELOC
| EXEC_P
| /* object flags */
2623 HAS_LINENO
| HAS_DEBUG
|
2624 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
2625 (SEC_CODE
|SEC_DATA
|SEC_ROM
|SEC_HAS_CONTENTS
2626 |SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
2627 ' ', /* ar_pad_char */
2628 16, /* ar_max_namelen */
2629 1, /* minimum alignment */
2630 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
, /* data */
2631 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
, /* hdrs */
2633 { _bfd_dummy_target
,
2634 ieee_object_p
, /* bfd_check_format */
2641 _bfd_generic_mkarchive
,
2646 ieee_write_object_contents
,
2647 _bfd_write_archive_contents
,