00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #define KEEPMINUSPCININST 0
00029
00030
00031
00032
00033
00034 #include "bfd.h"
00035 #include "sysdep.h"
00036 #include "libbfd.h"
00037 #include "ieee.h"
00038 #include "libieee.h"
00039 #include "safe-ctype.h"
00040
00041 struct output_buffer_struct
00042 {
00043 unsigned char *ptrp;
00044 int buffer;
00045 };
00046
00047 static bfd_boolean ieee_write_byte
00048 PARAMS ((bfd *, int));
00049 static bfd_boolean ieee_write_2bytes
00050 PARAMS ((bfd *, int));
00051 static bfd_boolean ieee_write_int
00052 PARAMS ((bfd *, bfd_vma));
00053 static bfd_boolean ieee_write_id
00054 PARAMS ((bfd *, const char *));
00055 static unsigned short read_2bytes
00056 PARAMS ((common_header_type *));
00057 static void bfd_get_string
00058 PARAMS ((common_header_type *, char *, size_t));
00059 static char *read_id
00060 PARAMS ((common_header_type *));
00061 static bfd_boolean ieee_write_expression
00062 PARAMS ((bfd *, bfd_vma, asymbol *, bfd_boolean, unsigned int));
00063 static void ieee_write_int5
00064 PARAMS ((bfd_byte *, bfd_vma));
00065 static bfd_boolean ieee_write_int5_out
00066 PARAMS ((bfd *, bfd_vma));
00067 static bfd_boolean parse_int
00068 PARAMS ((common_header_type *, bfd_vma *));
00069 static int parse_i
00070 PARAMS ((common_header_type *, bfd_boolean *));
00071 static bfd_vma must_parse_int
00072 PARAMS ((common_header_type *));
00073 static void parse_expression
00074 PARAMS ((ieee_data_type *, bfd_vma *, ieee_symbol_index_type *,
00075 bfd_boolean *, unsigned int *, asection **));
00076 static file_ptr ieee_part_after
00077 PARAMS ((ieee_data_type *, file_ptr));
00078 static ieee_symbol_type *get_symbol
00079 PARAMS ((bfd *, ieee_data_type *, ieee_symbol_type *, unsigned int *,
00080 ieee_symbol_type ***, unsigned int *, int));
00081 static bfd_boolean ieee_slurp_external_symbols
00082 PARAMS ((bfd *));
00083 static bfd_boolean ieee_slurp_symbol_table
00084 PARAMS ((bfd *));
00085 static long ieee_get_symtab_upper_bound
00086 PARAMS ((bfd *));
00087 static long ieee_canonicalize_symtab
00088 PARAMS ((bfd *, asymbol **));
00089 static asection *get_section_entry
00090 PARAMS ((bfd *, ieee_data_type *i, unsigned int));
00091 static void ieee_slurp_sections
00092 PARAMS ((bfd *));
00093 static bfd_boolean ieee_slurp_debug
00094 PARAMS ((bfd *));
00095 const bfd_target *ieee_archive_p
00096 PARAMS ((bfd *));
00097 const bfd_target *ieee_object_p
00098 PARAMS ((bfd *));
00099 static void ieee_get_symbol_info
00100 PARAMS ((bfd *, asymbol *, symbol_info *));
00101 static void ieee_print_symbol
00102 PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
00103 static bfd_boolean do_one
00104 PARAMS ((ieee_data_type *, ieee_per_section_type *, unsigned char *,
00105 asection *, int));
00106 static bfd_boolean ieee_slurp_section_data
00107 PARAMS ((bfd *));
00108 static bfd_boolean ieee_new_section_hook
00109 PARAMS ((bfd *, asection *));
00110 static long ieee_get_reloc_upper_bound
00111 PARAMS ((bfd *, sec_ptr));
00112 static bfd_boolean ieee_get_section_contents
00113 PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
00114 static long ieee_canonicalize_reloc
00115 PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
00116 static int comp
00117 PARAMS ((const PTR, const PTR));
00118 static bfd_boolean ieee_write_section_part
00119 PARAMS ((bfd *));
00120 static bfd_boolean do_with_relocs
00121 PARAMS ((bfd *, asection *));
00122 static bfd_boolean do_as_repeat
00123 PARAMS ((bfd *, asection *));
00124 static bfd_boolean do_without_relocs
00125 PARAMS ((bfd *, asection *));
00126 static bfd_boolean ieee_mkobject
00127 PARAMS ((bfd *));
00128 static void fill
00129 PARAMS ((void));
00130 static void flush
00131 PARAMS ((void));
00132 static void write_int
00133 PARAMS ((int));
00134 static void copy_id
00135 PARAMS ((void));
00136 static void copy_expression
00137 PARAMS ((void));
00138 static void fill_int
00139 PARAMS ((struct output_buffer_struct *));
00140 static void drop_int
00141 PARAMS ((struct output_buffer_struct *));
00142 static void copy_int
00143 PARAMS ((void));
00144 static void f1_record
00145 PARAMS ((void));
00146 static void f0_record
00147 PARAMS ((void));
00148 static void copy_till_end
00149 PARAMS ((void));
00150 static void f2_record
00151 PARAMS ((void));
00152 static void f8_record
00153 PARAMS ((void));
00154 static void e2_record
00155 PARAMS ((void));
00156 static void block
00157 PARAMS ((void));
00158 static void relocate_debug
00159 PARAMS ((bfd *, bfd *));
00160 static bfd_boolean ieee_write_debug_part
00161 PARAMS ((bfd *));
00162 static bfd_boolean ieee_write_data_part
00163 PARAMS ((bfd *));
00164 static bfd_boolean init_for_output
00165 PARAMS ((bfd *));
00166 static bfd_boolean ieee_set_section_contents
00167 PARAMS ((bfd *, sec_ptr, const PTR, file_ptr, bfd_size_type));
00168 static bfd_boolean ieee_write_external_part
00169 PARAMS ((bfd *));
00170 static bfd_boolean ieee_write_me_part
00171 PARAMS ((bfd *));
00172 static bfd_boolean ieee_write_processor
00173 PARAMS ((bfd *));
00174 static bfd_boolean ieee_write_object_contents
00175 PARAMS ((bfd *));
00176 static asymbol *ieee_make_empty_symbol
00177 PARAMS ((bfd *));
00178 static bfd *ieee_openr_next_archived_file
00179 PARAMS ((bfd *, bfd *));
00180 static bfd_boolean ieee_find_nearest_line
00181 PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
00182 const char **, unsigned int *));
00183 static int ieee_generic_stat_arch_elt
00184 PARAMS ((bfd *, struct stat *));
00185 static int ieee_sizeof_headers
00186 PARAMS ((bfd *, bfd_boolean));
00187
00188
00189
00190
00191 static bfd_boolean
00192 ieee_write_byte (abfd, barg)
00193 bfd *abfd;
00194 int barg;
00195 {
00196 bfd_byte byte;
00197
00198 byte = barg;
00199 if (bfd_bwrite ((PTR) &byte, (bfd_size_type) 1, abfd) != 1)
00200 return FALSE;
00201 return TRUE;
00202 }
00203
00204 static bfd_boolean
00205 ieee_write_2bytes (abfd, bytes)
00206 bfd *abfd;
00207 int bytes;
00208 {
00209 bfd_byte buffer[2];
00210
00211 buffer[0] = bytes >> 8;
00212 buffer[1] = bytes & 0xff;
00213 if (bfd_bwrite ((PTR) buffer, (bfd_size_type) 2, abfd) != 2)
00214 return FALSE;
00215 return TRUE;
00216 }
00217
00218 static bfd_boolean
00219 ieee_write_int (abfd, value)
00220 bfd *abfd;
00221 bfd_vma value;
00222 {
00223 if (value <= 127)
00224 {
00225 if (! ieee_write_byte (abfd, (bfd_byte) value))
00226 return FALSE;
00227 }
00228 else
00229 {
00230 unsigned int length;
00231
00232
00233
00234 if (value & 0xff000000)
00235 length = 4;
00236 else if (value & 0x00ff0000)
00237 length = 3;
00238 else if (value & 0x0000ff00)
00239 length = 2;
00240 else
00241 length = 1;
00242
00243 if (! ieee_write_byte (abfd,
00244 (bfd_byte) ((int) ieee_number_repeat_start_enum
00245 + length)))
00246 return FALSE;
00247 switch (length)
00248 {
00249 case 4:
00250 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))
00251 return FALSE;
00252
00253 case 3:
00254 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))
00255 return FALSE;
00256
00257 case 2:
00258 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))
00259 return FALSE;
00260
00261 case 1:
00262 if (! ieee_write_byte (abfd, (bfd_byte) (value)))
00263 return FALSE;
00264 }
00265 }
00266
00267 return TRUE;
00268 }
00269
00270 static bfd_boolean
00271 ieee_write_id (abfd, id)
00272 bfd *abfd;
00273 const char *id;
00274 {
00275 size_t length = strlen (id);
00276
00277 if (length <= 127)
00278 {
00279 if (! ieee_write_byte (abfd, (bfd_byte) length))
00280 return FALSE;
00281 }
00282 else if (length < 255)
00283 {
00284 if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)
00285 || ! ieee_write_byte (abfd, (bfd_byte) length))
00286 return FALSE;
00287 }
00288 else if (length < 65535)
00289 {
00290 if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)
00291 || ! ieee_write_2bytes (abfd, (int) length))
00292 return FALSE;
00293 }
00294 else
00295 {
00296 (*_bfd_error_handler)
00297 (_("%s: string too long (%d chars, max 65535)"),
00298 bfd_get_filename (abfd), length);
00299 bfd_set_error (bfd_error_invalid_operation);
00300 return FALSE;
00301 }
00302
00303 if (bfd_bwrite ((PTR) id, (bfd_size_type) length, abfd) != length)
00304 return FALSE;
00305 return TRUE;
00306 }
00307
00308
00309
00310
00311 #define this_byte(ieee) *((ieee)->input_p)
00312 #define next_byte(ieee) ((ieee)->input_p++)
00313 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
00314
00315 static unsigned short
00316 read_2bytes (ieee)
00317 common_header_type *ieee;
00318 {
00319 unsigned char c1 = this_byte_and_next (ieee);
00320 unsigned char c2 = this_byte_and_next (ieee);
00321
00322 return (c1 << 8) | c2;
00323 }
00324
00325 static void
00326 bfd_get_string (ieee, string, length)
00327 common_header_type *ieee;
00328 char *string;
00329 size_t length;
00330 {
00331 size_t i;
00332
00333 for (i = 0; i < length; i++)
00334 string[i] = this_byte_and_next (ieee);
00335 }
00336
00337 static char *
00338 read_id (ieee)
00339 common_header_type *ieee;
00340 {
00341 size_t length;
00342 char *string;
00343
00344 length = this_byte_and_next (ieee);
00345 if (length <= 0x7f)
00346 {
00347
00348 }
00349 else if (length == 0xde)
00350 {
00351
00352 length = this_byte_and_next (ieee);
00353 }
00354 else if (length == 0xdf)
00355 {
00356
00357 length = this_byte_and_next (ieee);
00358 length = (length * 256) + this_byte_and_next (ieee);
00359 }
00360
00361
00362 string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
00363 if (!string)
00364 return NULL;
00365 bfd_get_string (ieee, string, length);
00366 string[length] = 0;
00367 return string;
00368 }
00369
00370 static bfd_boolean
00371 ieee_write_expression (abfd, value, symbol, pcrel, index)
00372 bfd *abfd;
00373 bfd_vma value;
00374 asymbol *symbol;
00375 bfd_boolean pcrel;
00376 unsigned int index;
00377 {
00378 unsigned int term_count = 0;
00379
00380 if (value != 0)
00381 {
00382 if (! ieee_write_int (abfd, value))
00383 return FALSE;
00384 term_count++;
00385 }
00386
00387
00388
00389 if (symbol != NULL)
00390 {
00391 if (bfd_is_com_section (symbol->section)
00392 || bfd_is_und_section (symbol->section))
00393 {
00394
00395 if (! ieee_write_byte (abfd, ieee_variable_X_enum)
00396 || ! ieee_write_int (abfd, symbol->value))
00397 return FALSE;
00398 term_count ++;
00399 }
00400 else if (! bfd_is_abs_section (symbol->section))
00401 {
00402
00403
00404 if (symbol->flags & BSF_GLOBAL)
00405 {
00406 if (! ieee_write_byte (abfd, ieee_variable_I_enum)
00407 || ! ieee_write_int (abfd, symbol->value))
00408 return FALSE;
00409 term_count++;
00410 }
00411 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
00412 {
00413
00414
00415 if (! ieee_write_byte (abfd, ieee_variable_R_enum)
00416 || ! ieee_write_byte (abfd,
00417 (bfd_byte) (symbol->section->index
00418 + IEEE_SECTION_NUMBER_BASE)))
00419 return FALSE;
00420
00421 term_count++;
00422 if (symbol->value != 0)
00423 {
00424 if (! ieee_write_int (abfd, symbol->value))
00425 return FALSE;
00426 term_count++;
00427 }
00428 }
00429 else
00430 {
00431 (*_bfd_error_handler)
00432 (_("%s: unrecognized symbol `%s' flags 0x%x"),
00433 bfd_get_filename (abfd), bfd_asymbol_name (symbol),
00434 symbol->flags);
00435 bfd_set_error (bfd_error_invalid_operation);
00436 return FALSE;
00437 }
00438 }
00439 }
00440
00441 if (pcrel)
00442 {
00443
00444 if (! ieee_write_byte (abfd, ieee_variable_P_enum)
00445 || ! ieee_write_byte (abfd,
00446 (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE))
00447 || ! ieee_write_byte (abfd, ieee_function_minus_enum))
00448 return FALSE;
00449 }
00450
00451
00452 if (term_count == 0)
00453 if (! ieee_write_int (abfd, (bfd_vma) 0))
00454 return FALSE;
00455
00456 while (term_count > 1)
00457 {
00458 if (! ieee_write_byte (abfd, ieee_function_plus_enum))
00459 return FALSE;
00460 term_count--;
00461 }
00462
00463 return TRUE;
00464 }
00465
00466
00467
00468 static void
00469 ieee_write_int5 (buffer, value)
00470 bfd_byte *buffer;
00471 bfd_vma value;
00472 {
00473 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
00474 buffer[1] = (value >> 24) & 0xff;
00475 buffer[2] = (value >> 16) & 0xff;
00476 buffer[3] = (value >> 8) & 0xff;
00477 buffer[4] = (value >> 0) & 0xff;
00478 }
00479
00480 static bfd_boolean
00481 ieee_write_int5_out (abfd, value)
00482 bfd *abfd;
00483 bfd_vma value;
00484 {
00485 bfd_byte b[5];
00486
00487 ieee_write_int5 (b, value);
00488 if (bfd_bwrite ((PTR) b, (bfd_size_type) 5, abfd) != 5)
00489 return FALSE;
00490 return TRUE;
00491 }
00492
00493 static bfd_boolean
00494 parse_int (ieee, value_ptr)
00495 common_header_type *ieee;
00496 bfd_vma *value_ptr;
00497 {
00498 int value = this_byte (ieee);
00499 int result;
00500
00501 if (value >= 0 && value <= 127)
00502 {
00503 *value_ptr = value;
00504 next_byte (ieee);
00505 return TRUE;
00506 }
00507 else if (value >= 0x80 && value <= 0x88)
00508 {
00509 unsigned int count = value & 0xf;
00510
00511 result = 0;
00512 next_byte (ieee);
00513 while (count)
00514 {
00515 result = (result << 8) | this_byte_and_next (ieee);
00516 count--;
00517 }
00518 *value_ptr = result;
00519 return TRUE;
00520 }
00521 return FALSE;
00522 }
00523
00524 static int
00525 parse_i (ieee, ok)
00526 common_header_type *ieee;
00527 bfd_boolean *ok;
00528 {
00529 bfd_vma x;
00530 *ok = parse_int (ieee, &x);
00531 return x;
00532 }
00533
00534 static bfd_vma
00535 must_parse_int (ieee)
00536 common_header_type *ieee;
00537 {
00538 bfd_vma result;
00539 BFD_ASSERT (parse_int (ieee, &result));
00540 return result;
00541 }
00542
00543 typedef struct
00544 {
00545 bfd_vma value;
00546 asection *section;
00547 ieee_symbol_index_type symbol;
00548 } ieee_value_type;
00549
00550
00551 #if KEEPMINUSPCININST
00552
00553 #define SRC_MASK(arg) arg
00554 #define PCREL_OFFSET FALSE
00555
00556 #else
00557
00558 #define SRC_MASK(arg) 0
00559 #define PCREL_OFFSET TRUE
00560
00561 #endif
00562
00563 static reloc_howto_type abs32_howto =
00564 HOWTO (1,
00565 0,
00566 2,
00567 32,
00568 FALSE,
00569 0,
00570 complain_overflow_bitfield,
00571 0,
00572 "abs32",
00573 TRUE,
00574 0xffffffff,
00575 0xffffffff,
00576 FALSE);
00577
00578 static reloc_howto_type abs16_howto =
00579 HOWTO (1,
00580 0,
00581 1,
00582 16,
00583 FALSE,
00584 0,
00585 complain_overflow_bitfield,
00586 0,
00587 "abs16",
00588 TRUE,
00589 0x0000ffff,
00590 0x0000ffff,
00591 FALSE);
00592
00593 static reloc_howto_type abs8_howto =
00594 HOWTO (1,
00595 0,
00596 0,
00597 8,
00598 FALSE,
00599 0,
00600 complain_overflow_bitfield,
00601 0,
00602 "abs8",
00603 TRUE,
00604 0x000000ff,
00605 0x000000ff,
00606 FALSE);
00607
00608 static reloc_howto_type rel32_howto =
00609 HOWTO (1,
00610 0,
00611 2,
00612 32,
00613 TRUE,
00614 0,
00615 complain_overflow_signed,
00616 0,
00617 "rel32",
00618 TRUE,
00619 SRC_MASK (0xffffffff),
00620 0xffffffff,
00621 PCREL_OFFSET);
00622
00623 static reloc_howto_type rel16_howto =
00624 HOWTO (1,
00625 0,
00626 1,
00627 16,
00628 TRUE,
00629 0,
00630 complain_overflow_signed,
00631 0,
00632 "rel16",
00633 TRUE,
00634 SRC_MASK (0x0000ffff),
00635 0x0000ffff,
00636 PCREL_OFFSET);
00637
00638 static reloc_howto_type rel8_howto =
00639 HOWTO (1,
00640 0,
00641 0,
00642 8,
00643 TRUE,
00644 0,
00645 complain_overflow_signed,
00646 0,
00647 "rel8",
00648 TRUE,
00649 SRC_MASK (0x000000ff),
00650 0x000000ff,
00651 PCREL_OFFSET);
00652
00653 static ieee_symbol_index_type NOSYMBOL = {0, 0};
00654
00655 static void
00656 parse_expression (ieee, value, symbol, pcrel, extra, section)
00657 ieee_data_type *ieee;
00658 bfd_vma *value;
00659 ieee_symbol_index_type *symbol;
00660 bfd_boolean *pcrel;
00661 unsigned int *extra;
00662 asection **section;
00663
00664 {
00665 #define POS sp[1]
00666 #define TOS sp[0]
00667 #define NOS sp[-1]
00668 #define INC sp++;
00669 #define DEC sp--;
00670
00671 bfd_boolean loop = TRUE;
00672 ieee_value_type stack[10];
00673
00674
00675 #define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
00676 #define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
00677 ieee_value_type *sp = stack;
00678 asection *dummy;
00679
00680 while (loop && ieee->h.input_p < ieee->h.last_byte)
00681 {
00682 switch (this_byte (&(ieee->h)))
00683 {
00684 case ieee_variable_P_enum:
00685
00686 {
00687 int section_n;
00688
00689 next_byte (&(ieee->h));
00690 *pcrel = TRUE;
00691 section_n = must_parse_int (&(ieee->h));
00692 PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
00693 break;
00694 }
00695 case ieee_variable_L_enum:
00696
00697 next_byte (&(ieee->h));
00698 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
00699 break;
00700 case ieee_variable_R_enum:
00701
00702
00703 next_byte (&(ieee->h));
00704 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
00705 break;
00706 case ieee_variable_S_enum:
00707
00708 next_byte (&(ieee->h));
00709 PUSH (NOSYMBOL,
00710 0,
00711 ieee->section_table[must_parse_int (&(ieee->h))]->size);
00712 break;
00713 case ieee_variable_I_enum:
00714
00715 {
00716 ieee_symbol_index_type sy;
00717 next_byte (&(ieee->h));
00718 sy.index = (int) must_parse_int (&(ieee->h));
00719 sy.letter = 'I';
00720
00721 PUSH (sy, bfd_abs_section_ptr, 0);
00722 }
00723 break;
00724 case ieee_variable_X_enum:
00725
00726 {
00727 ieee_symbol_index_type sy;
00728 next_byte (&(ieee->h));
00729 sy.index = (int) (must_parse_int (&(ieee->h)));
00730 sy.letter = 'X';
00731
00732 PUSH (sy, bfd_und_section_ptr, 0);
00733 }
00734 break;
00735 case ieee_function_minus_enum:
00736 {
00737 bfd_vma value1, value2;
00738 asection *section1, *section_dummy;
00739 ieee_symbol_index_type sy;
00740 next_byte (&(ieee->h));
00741
00742 POP (sy, section1, value1);
00743 POP (sy, section_dummy, value2);
00744 PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
00745 }
00746 break;
00747 case ieee_function_plus_enum:
00748 {
00749 bfd_vma value1, value2;
00750 asection *section1;
00751 asection *section2;
00752 ieee_symbol_index_type sy1;
00753 ieee_symbol_index_type sy2;
00754 next_byte (&(ieee->h));
00755
00756 POP (sy1, section1, value1);
00757 POP (sy2, section2, value2);
00758 PUSH (sy1.letter ? sy1 : sy2,
00759 bfd_is_abs_section (section1) ? section2 : section1,
00760 value1 + value2);
00761 }
00762 break;
00763 default:
00764 {
00765 bfd_vma va;
00766 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
00767 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
00768 if (parse_int (&(ieee->h), &va))
00769 {
00770 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
00771 }
00772 else
00773 {
00774
00775 loop = FALSE;
00776 }
00777 }
00778 }
00779 }
00780
00781
00782
00783
00784
00785
00786
00787 while (sp != stack + 1)
00788 {
00789 asection *section1;
00790 ieee_symbol_index_type sy1;
00791 POP (sy1, section1, *extra);
00792 }
00793
00794 POP (*symbol, dummy, *value);
00795 if (section)
00796 *section = dummy;
00797 }
00798
00799
00800 #define ieee_seek(ieee, offset) \
00801 do \
00802 { \
00803 ieee->h.input_p = ieee->h.first_byte + offset; \
00804 ieee->h.last_byte = (ieee->h.first_byte \
00805 + ieee_part_after (ieee, offset)); \
00806 } \
00807 while (0)
00808
00809 #define ieee_pos(ieee) \
00810 (ieee->h.input_p - ieee->h.first_byte)
00811
00812
00813
00814 static file_ptr
00815 ieee_part_after (ieee, here)
00816 ieee_data_type *ieee;
00817 file_ptr here;
00818 {
00819 int part;
00820 file_ptr after = ieee->w.r.me_record;
00821
00822
00823
00824 for (part = 0; part < N_W_VARIABLES; part++)
00825 if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
00826 after = ieee->w.offset[part];
00827
00828 return after;
00829 }
00830
00831 static unsigned int last_index;
00832 static char last_type;
00833
00834 static ieee_symbol_type *
00835 get_symbol (abfd, ieee, last_symbol, symbol_count, pptr, max_index, this_type)
00836 bfd *abfd ATTRIBUTE_UNUSED;
00837 ieee_data_type *ieee;
00838 ieee_symbol_type *last_symbol;
00839 unsigned int *symbol_count;
00840 ieee_symbol_type ***pptr;
00841 unsigned int *max_index;
00842 int this_type;
00843 {
00844
00845 unsigned int new_index = must_parse_int (&(ieee->h));
00846
00847 if (new_index != last_index || this_type != last_type)
00848 {
00849 ieee_symbol_type *new_symbol;
00850 bfd_size_type amt = sizeof (ieee_symbol_type);
00851
00852 new_symbol = (ieee_symbol_type *) bfd_alloc (ieee->h.abfd, amt);
00853 if (!new_symbol)
00854 return NULL;
00855
00856 new_symbol->index = new_index;
00857 last_index = new_index;
00858 (*symbol_count)++;
00859 **pptr = new_symbol;
00860 *pptr = &new_symbol->next;
00861 if (new_index > *max_index)
00862 *max_index = new_index;
00863
00864 last_type = this_type;
00865 new_symbol->symbol.section = bfd_abs_section_ptr;
00866 return new_symbol;
00867 }
00868 return last_symbol;
00869 }
00870
00871 static bfd_boolean
00872 ieee_slurp_external_symbols (abfd)
00873 bfd *abfd;
00874 {
00875 ieee_data_type *ieee = IEEE_DATA (abfd);
00876 file_ptr offset = ieee->w.r.external_part;
00877
00878 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
00879 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
00880 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
00881 unsigned int symbol_count = 0;
00882 bfd_boolean loop = TRUE;
00883 last_index = 0xffffff;
00884 ieee->symbol_table_full = TRUE;
00885
00886 ieee_seek (ieee, offset);
00887
00888 while (loop)
00889 {
00890 switch (this_byte (&(ieee->h)))
00891 {
00892 case ieee_nn_record:
00893 next_byte (&(ieee->h));
00894
00895 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
00896 &prev_symbols_ptr,
00897 &ieee->external_symbol_max_index, 'I');
00898 if (symbol == NULL)
00899 return FALSE;
00900
00901 symbol->symbol.the_bfd = abfd;
00902 symbol->symbol.name = read_id (&(ieee->h));
00903 symbol->symbol.udata.p = (PTR) NULL;
00904 symbol->symbol.flags = BSF_NO_FLAGS;
00905 break;
00906 case ieee_external_symbol_enum:
00907 next_byte (&(ieee->h));
00908
00909 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
00910 &prev_symbols_ptr,
00911 &ieee->external_symbol_max_index, 'D');
00912 if (symbol == NULL)
00913 return FALSE;
00914
00915 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
00916
00917 symbol->symbol.the_bfd = abfd;
00918 symbol->symbol.name = read_id (&(ieee->h));
00919 symbol->symbol.udata.p = (PTR) NULL;
00920 symbol->symbol.flags = BSF_NO_FLAGS;
00921 break;
00922 case ieee_attribute_record_enum >> 8:
00923 {
00924 unsigned int symbol_name_index;
00925 unsigned int symbol_type_index;
00926 unsigned int symbol_attribute_def;
00927 bfd_vma value;
00928 switch (read_2bytes (&ieee->h))
00929 {
00930 case ieee_attribute_record_enum:
00931 symbol_name_index = must_parse_int (&(ieee->h));
00932 symbol_type_index = must_parse_int (&(ieee->h));
00933 symbol_attribute_def = must_parse_int (&(ieee->h));
00934 switch (symbol_attribute_def)
00935 {
00936 case 8:
00937 case 19:
00938 parse_int (&ieee->h, &value);
00939 break;
00940 default:
00941 (*_bfd_error_handler)
00942 (_("%B: unimplemented ATI record %u for symbol %u"),
00943 abfd, symbol_attribute_def, symbol_name_index);
00944 bfd_set_error (bfd_error_bad_value);
00945 return FALSE;
00946 break;
00947 }
00948 break;
00949 case ieee_external_reference_info_record_enum:
00950
00951 parse_int (&(ieee->h), &value);
00952 parse_int (&(ieee->h), &value);
00953 parse_int (&(ieee->h), &value);
00954 parse_int (&(ieee->h), &value);
00955 break;
00956 case ieee_atn_record_enum:
00957
00958
00959
00960 parse_int (&ieee->h, &value);
00961 parse_int (&ieee->h, &value);
00962 parse_int (&ieee->h, &value);
00963 if (value != 0x3f)
00964 {
00965 (*_bfd_error_handler)
00966 (_("%B: unexpected ATN type %d in external part"),
00967 abfd, (int) value);
00968 bfd_set_error (bfd_error_bad_value);
00969 return FALSE;
00970 }
00971 parse_int (&ieee->h, &value);
00972 parse_int (&ieee->h, &value);
00973 while (value > 0)
00974 {
00975 bfd_vma val1;
00976
00977 --value;
00978
00979 switch (read_2bytes (&ieee->h))
00980 {
00981 case ieee_asn_record_enum:
00982 parse_int (&ieee->h, &val1);
00983 parse_int (&ieee->h, &val1);
00984 break;
00985
00986 default:
00987 (*_bfd_error_handler)
00988 (_("%B: unexpected type after ATN"), abfd);
00989 bfd_set_error (bfd_error_bad_value);
00990 return FALSE;
00991 }
00992 }
00993 }
00994 }
00995 break;
00996 case ieee_value_record_enum >> 8:
00997 {
00998 unsigned int symbol_name_index;
00999 ieee_symbol_index_type symbol_ignore;
01000 bfd_boolean pcrel_ignore;
01001 unsigned int extra;
01002 next_byte (&(ieee->h));
01003 next_byte (&(ieee->h));
01004
01005 symbol_name_index = must_parse_int (&(ieee->h));
01006 parse_expression (ieee,
01007 &symbol->symbol.value,
01008 &symbol_ignore,
01009 &pcrel_ignore,
01010 &extra,
01011 &symbol->symbol.section);
01012
01013
01014
01015
01016
01017 if (bfd_is_abs_section (symbol->symbol.section)
01018 && (abfd->flags & HAS_RELOC) == 0)
01019 {
01020 bfd_vma val;
01021 asection *s;
01022
01023 val = symbol->symbol.value;
01024 for (s = abfd->sections; s != NULL; s = s->next)
01025 {
01026 if (val >= s->vma && val < s->vma + s->size)
01027 {
01028 symbol->symbol.section = s;
01029 symbol->symbol.value -= s->vma;
01030 break;
01031 }
01032 }
01033 }
01034
01035 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
01036
01037 }
01038 break;
01039 case ieee_weak_external_reference_enum:
01040 {
01041 bfd_vma size;
01042 bfd_vma value;
01043 next_byte (&(ieee->h));
01044
01045 (void) must_parse_int (&(ieee->h));
01046
01047 size = must_parse_int (&(ieee->h));
01048
01049 if (! parse_int (&(ieee->h), &value))
01050 {
01051 value = 0;
01052 }
01053
01054 symbol->symbol.section = bfd_com_section_ptr;
01055 symbol->symbol.value = size;
01056 }
01057 break;
01058
01059 case ieee_external_reference_enum:
01060 next_byte (&(ieee->h));
01061
01062 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
01063 &prev_reference_ptr,
01064 &ieee->external_reference_max_index, 'X');
01065 if (symbol == NULL)
01066 return FALSE;
01067
01068 symbol->symbol.the_bfd = abfd;
01069 symbol->symbol.name = read_id (&(ieee->h));
01070 symbol->symbol.udata.p = (PTR) NULL;
01071 symbol->symbol.section = bfd_und_section_ptr;
01072 symbol->symbol.value = (bfd_vma) 0;
01073 symbol->symbol.flags = 0;
01074
01075 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
01076 break;
01077
01078 default:
01079 loop = FALSE;
01080 }
01081 }
01082
01083 if (ieee->external_symbol_max_index != 0)
01084 {
01085 ieee->external_symbol_count =
01086 ieee->external_symbol_max_index -
01087 ieee->external_symbol_min_index + 1;
01088 }
01089 else
01090 {
01091 ieee->external_symbol_count = 0;
01092 }
01093
01094 if (ieee->external_reference_max_index != 0)
01095 {
01096 ieee->external_reference_count =
01097 ieee->external_reference_max_index -
01098 ieee->external_reference_min_index + 1;
01099 }
01100 else
01101 {
01102 ieee->external_reference_count = 0;
01103 }
01104
01105 abfd->symcount =
01106 ieee->external_reference_count + ieee->external_symbol_count;
01107
01108 if (symbol_count != abfd->symcount)
01109 {
01110
01111 ieee->symbol_table_full = FALSE;
01112 }
01113
01114 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
01115 *prev_reference_ptr = (ieee_symbol_type *) NULL;
01116
01117 return TRUE;
01118 }
01119
01120 static bfd_boolean
01121 ieee_slurp_symbol_table (abfd)
01122 bfd *abfd;
01123 {
01124 if (! IEEE_DATA (abfd)->read_symbols)
01125 {
01126 if (! ieee_slurp_external_symbols (abfd))
01127 return FALSE;
01128 IEEE_DATA (abfd)->read_symbols = TRUE;
01129 }
01130 return TRUE;
01131 }
01132
01133 static long
01134 ieee_get_symtab_upper_bound (abfd)
01135 bfd *abfd;
01136 {
01137 if (! ieee_slurp_symbol_table (abfd))
01138 return -1;
01139
01140 return (abfd->symcount != 0) ?
01141 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
01142 }
01143
01144
01145
01146
01147 extern const bfd_target ieee_vec;
01148
01149 static long
01150 ieee_canonicalize_symtab (abfd, location)
01151 bfd *abfd;
01152 asymbol **location;
01153 {
01154 ieee_symbol_type *symp;
01155 static bfd dummy_bfd;
01156 static asymbol empty_symbol =
01157 {
01158 &dummy_bfd,
01159 " ieee empty",
01160 (symvalue) 0,
01161 BSF_DEBUGGING,
01162 bfd_abs_section_ptr
01163 #ifdef __STDC__
01164
01165 , { 0 }
01166 #endif
01167 };
01168
01169 if (abfd->symcount)
01170 {
01171 ieee_data_type *ieee = IEEE_DATA (abfd);
01172 dummy_bfd.xvec = &ieee_vec;
01173 if (! ieee_slurp_symbol_table (abfd))
01174 return -1;
01175
01176 if (! ieee->symbol_table_full)
01177 {
01178
01179
01180 unsigned int i;
01181
01182 for (i = 0; i < abfd->symcount; i++)
01183 location[i] = &empty_symbol;
01184 }
01185
01186 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
01187 for (symp = IEEE_DATA (abfd)->external_symbols;
01188 symp != (ieee_symbol_type *) NULL;
01189 symp = symp->next)
01190
01191 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
01192
01193
01194 ieee->external_reference_base_offset =
01195 -ieee->external_reference_min_index + ieee->external_symbol_count;
01196
01197 for (symp = IEEE_DATA (abfd)->external_reference;
01198 symp != (ieee_symbol_type *) NULL;
01199 symp = symp->next)
01200 location[symp->index + ieee->external_reference_base_offset] =
01201 &symp->symbol;
01202 }
01203
01204 if (abfd->symcount)
01205 location[abfd->symcount] = (asymbol *) NULL;
01206
01207 return abfd->symcount;
01208 }
01209
01210 static asection *
01211 get_section_entry (abfd, ieee, index)
01212 bfd *abfd;
01213 ieee_data_type *ieee;
01214 unsigned int index;
01215 {
01216 if (index >= ieee->section_table_size)
01217 {
01218 unsigned int c, i;
01219 asection **n;
01220 bfd_size_type amt;
01221
01222 c = ieee->section_table_size;
01223 if (c == 0)
01224 c = 20;
01225 while (c <= index)
01226 c *= 2;
01227
01228 amt = c;
01229 amt *= sizeof (asection *);
01230 n = (asection **) bfd_realloc (ieee->section_table, amt);
01231 if (n == NULL)
01232 return NULL;
01233
01234 for (i = ieee->section_table_size; i < c; i++)
01235 n[i] = NULL;
01236
01237 ieee->section_table = n;
01238 ieee->section_table_size = c;
01239 }
01240
01241 if (ieee->section_table[index] == (asection *) NULL)
01242 {
01243 char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
01244 asection *section;
01245
01246 if (!tmp)
01247 return NULL;
01248 sprintf (tmp, " fsec%4d", index);
01249 section = bfd_make_section (abfd, tmp);
01250 ieee->section_table[index] = section;
01251 section->flags = SEC_NO_FLAGS;
01252 section->target_index = index;
01253 ieee->section_table[index] = section;
01254 }
01255 return ieee->section_table[index];
01256 }
01257
01258 static void
01259 ieee_slurp_sections (abfd)
01260 bfd *abfd;
01261 {
01262 ieee_data_type *ieee = IEEE_DATA (abfd);
01263 file_ptr offset = ieee->w.r.section_part;
01264 char *name;
01265
01266 if (offset != 0)
01267 {
01268 bfd_byte section_type[3];
01269 ieee_seek (ieee, offset);
01270 while (TRUE)
01271 {
01272 switch (this_byte (&(ieee->h)))
01273 {
01274 case ieee_section_type_enum:
01275 {
01276 asection *section;
01277 unsigned int section_index;
01278 next_byte (&(ieee->h));
01279 section_index = must_parse_int (&(ieee->h));
01280
01281 section = get_section_entry (abfd, ieee, section_index);
01282
01283 section_type[0] = this_byte_and_next (&(ieee->h));
01284
01285
01286
01287 switch (section_type[0])
01288 {
01289 case 0xC1:
01290
01291 section_type[1] = this_byte (&(ieee->h));
01292 section->flags = SEC_ALLOC;
01293 switch (section_type[1])
01294 {
01295 case 0xD3:
01296 next_byte (&(ieee->h));
01297 section_type[2] = this_byte (&(ieee->h));
01298 switch (section_type[2])
01299 {
01300 case 0xD0:
01301
01302 next_byte (&(ieee->h));
01303 section->flags |= SEC_CODE;
01304 break;
01305 case 0xC4:
01306
01307 next_byte (&(ieee->h));
01308 section->flags |= SEC_DATA;
01309 break;
01310 case 0xD2:
01311 next_byte (&(ieee->h));
01312
01313 section->flags |= SEC_ROM | SEC_DATA;
01314 break;
01315 default:
01316 break;
01317 }
01318 }
01319 break;
01320 case 0xC3:
01321 section_type[1] = this_byte (&(ieee->h));
01322 section->flags = SEC_ALLOC;
01323 switch (section_type[1])
01324 {
01325 case 0xD0:
01326 next_byte (&(ieee->h));
01327 section->flags |= SEC_CODE;
01328 break;
01329 case 0xC4:
01330 next_byte (&(ieee->h));
01331 section->flags |= SEC_DATA;
01332 break;
01333 case 0xD2:
01334 next_byte (&(ieee->h));
01335 section->flags |= SEC_ROM | SEC_DATA;
01336 break;
01337 default:
01338 break;
01339 }
01340 }
01341
01342
01343 name = read_id (&ieee->h);
01344 if (name[0])
01345 section->name = name;
01346
01347
01348 {
01349 bfd_vma parent, brother, context;
01350 parse_int (&(ieee->h), &parent);
01351 parse_int (&(ieee->h), &brother);
01352 parse_int (&(ieee->h), &context);
01353 }
01354 }
01355 break;
01356 case ieee_section_alignment_enum:
01357 {
01358 unsigned int section_index;
01359 bfd_vma value;
01360 asection *section;
01361 next_byte (&(ieee->h));
01362 section_index = must_parse_int (&ieee->h);
01363 section = get_section_entry (abfd, ieee, section_index);
01364 if (section_index > ieee->section_count)
01365 {
01366 ieee->section_count = section_index;
01367 }
01368 section->alignment_power =
01369 bfd_log2 (must_parse_int (&ieee->h));
01370 (void) parse_int (&(ieee->h), &value);
01371 }
01372 break;
01373 case ieee_e2_first_byte_enum:
01374 {
01375 asection *section;
01376 ieee_record_enum_type t;
01377
01378 t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
01379 switch (t)
01380 {
01381 case ieee_section_size_enum:
01382 section = ieee->section_table[must_parse_int (&(ieee->h))];
01383 section->size = must_parse_int (&(ieee->h));
01384 break;
01385 case ieee_physical_region_size_enum:
01386 section = ieee->section_table[must_parse_int (&(ieee->h))];
01387 section->size = must_parse_int (&(ieee->h));
01388 break;
01389 case ieee_region_base_address_enum:
01390 section = ieee->section_table[must_parse_int (&(ieee->h))];
01391 section->vma = must_parse_int (&(ieee->h));
01392 section->lma = section->vma;
01393 break;
01394 case ieee_mau_size_enum:
01395 must_parse_int (&(ieee->h));
01396 must_parse_int (&(ieee->h));
01397 break;
01398 case ieee_m_value_enum:
01399 must_parse_int (&(ieee->h));
01400 must_parse_int (&(ieee->h));
01401 break;
01402 case ieee_section_base_address_enum:
01403 section = ieee->section_table[must_parse_int (&(ieee->h))];
01404 section->vma = must_parse_int (&(ieee->h));
01405 section->lma = section->vma;
01406 break;
01407 case ieee_section_offset_enum:
01408 (void) must_parse_int (&(ieee->h));
01409 (void) must_parse_int (&(ieee->h));
01410 break;
01411 default:
01412 return;
01413 }
01414 }
01415 break;
01416 default:
01417 return;
01418 }
01419 }
01420 }
01421 }
01422
01423
01424
01425
01426
01427
01428 static bfd_boolean
01429 ieee_slurp_debug (abfd)
01430 bfd *abfd;
01431 {
01432 ieee_data_type *ieee = IEEE_DATA (abfd);
01433 asection *sec;
01434 file_ptr debug_end;
01435
01436 if (ieee->w.r.debug_information_part == 0)
01437 return TRUE;
01438
01439 sec = bfd_make_section (abfd, ".debug");
01440 if (sec == NULL)
01441 return FALSE;
01442 sec->flags |= SEC_DEBUGGING | SEC_HAS_CONTENTS;
01443 sec->filepos = ieee->w.r.debug_information_part;
01444
01445 debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
01446 sec->size = debug_end - ieee->w.r.debug_information_part;
01447
01448 return TRUE;
01449 }
01450
01451
01452
01453 const bfd_target *
01454 ieee_archive_p (abfd)
01455 bfd *abfd;
01456 {
01457 char *library;
01458 unsigned int i;
01459 unsigned char buffer[512];
01460 file_ptr buffer_offset = 0;
01461 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
01462 ieee_ar_data_type *ieee;
01463 bfd_size_type alc_elts;
01464 ieee_ar_obstack_type *elts = NULL;
01465 bfd_size_type amt = sizeof (ieee_ar_data_type);
01466
01467 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, amt);
01468 if (!abfd->tdata.ieee_ar_data)
01469 goto error_ret_restore;
01470 ieee = IEEE_AR_DATA (abfd);
01471
01472
01473
01474 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
01475
01476 ieee->h.first_byte = buffer;
01477 ieee->h.input_p = buffer;
01478
01479 ieee->h.abfd = abfd;
01480
01481 if (this_byte (&(ieee->h)) != Module_Beginning)
01482 goto got_wrong_format_error;
01483
01484 next_byte (&(ieee->h));
01485 library = read_id (&(ieee->h));
01486 if (strcmp (library, "LIBRARY") != 0)
01487 goto got_wrong_format_error;
01488
01489
01490 read_id (&(ieee->h));
01491
01492 ieee->element_count = 0;
01493 ieee->element_index = 0;
01494
01495 next_byte (&(ieee->h));
01496 must_parse_int (&(ieee->h));
01497 must_parse_int (&(ieee->h));
01498
01499 alc_elts = 10;
01500 elts = (ieee_ar_obstack_type *) bfd_malloc (alc_elts * sizeof *elts);
01501 if (elts == NULL)
01502 goto error_return;
01503
01504
01505 while (1)
01506 {
01507 int rec;
01508 ieee_ar_obstack_type *t;
01509
01510 rec = read_2bytes (&(ieee->h));
01511 if (rec != (int) ieee_assign_value_to_variable_enum)
01512 break;
01513
01514 if (ieee->element_count >= alc_elts)
01515 {
01516 ieee_ar_obstack_type *n;
01517
01518 alc_elts *= 2;
01519 n = ((ieee_ar_obstack_type *)
01520 bfd_realloc (elts, alc_elts * sizeof *elts));
01521 if (n == NULL)
01522 goto error_return;
01523 elts = n;
01524 }
01525
01526 t = &elts[ieee->element_count];
01527 ieee->element_count++;
01528
01529 must_parse_int (&(ieee->h));
01530 t->file_offset = must_parse_int (&(ieee->h));
01531 t->abfd = (bfd *) NULL;
01532
01533
01534 if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
01535 {
01536
01537 buffer_offset += ieee_pos (IEEE_DATA (abfd));
01538 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
01539 goto error_return;
01540
01541
01542 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
01543 ieee->h.first_byte = buffer;
01544 ieee->h.input_p = buffer;
01545 }
01546 }
01547
01548 amt = ieee->element_count;
01549 amt *= sizeof *ieee->elements;
01550 ieee->elements = (ieee_ar_obstack_type *) bfd_alloc (abfd, amt);
01551 if (ieee->elements == NULL)
01552 goto error_return;
01553
01554 memcpy (ieee->elements, elts, (size_t) amt);
01555 free (elts);
01556 elts = NULL;
01557
01558
01559 for (i = 2; i < ieee->element_count; i++)
01560 {
01561 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
01562 goto error_return;
01563
01564
01565 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
01566 ieee->h.first_byte = buffer;
01567 ieee->h.input_p = buffer;
01568
01569 next_byte (&(ieee->h));
01570 next_byte (&(ieee->h));
01571 must_parse_int (&(ieee->h));
01572
01573 if (must_parse_int (&(ieee->h)) != 0)
01574
01575 ieee->elements[i].file_offset = 0;
01576 else
01577 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
01578 }
01579
01580
01581
01582 return abfd->xvec;
01583
01584 got_wrong_format_error:
01585 bfd_set_error (bfd_error_wrong_format);
01586 error_return:
01587 if (elts != NULL)
01588 free (elts);
01589 bfd_release (abfd, ieee);
01590 error_ret_restore:
01591 abfd->tdata.ieee_ar_data = save;
01592
01593 return NULL;
01594 }
01595
01596 const bfd_target *
01597 ieee_object_p (abfd)
01598 bfd *abfd;
01599 {
01600 char *processor;
01601 unsigned int part;
01602 ieee_data_type *ieee;
01603 unsigned char buffer[300];
01604 ieee_data_type *save = IEEE_DATA (abfd);
01605 bfd_size_type amt;
01606
01607 abfd->tdata.ieee_data = 0;
01608 ieee_mkobject (abfd);
01609
01610 ieee = IEEE_DATA (abfd);
01611 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
01612 goto fail;
01613
01614
01615 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
01616
01617 ieee->h.input_p = buffer;
01618 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
01619 goto got_wrong_format;
01620
01621 ieee->read_symbols = FALSE;
01622 ieee->read_data = FALSE;
01623 ieee->section_count = 0;
01624 ieee->external_symbol_max_index = 0;
01625 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
01626 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
01627 ieee->external_reference_max_index = 0;
01628 ieee->h.abfd = abfd;
01629 ieee->section_table = NULL;
01630 ieee->section_table_size = 0;
01631
01632 processor = ieee->mb.processor = read_id (&(ieee->h));
01633 if (strcmp (processor, "LIBRARY") == 0)
01634 goto got_wrong_format;
01635 ieee->mb.module_name = read_id (&(ieee->h));
01636 if (abfd->filename == (const char *) NULL)
01637 abfd->filename = ieee->mb.module_name;
01638
01639
01640 {
01641 const bfd_arch_info_type *arch;
01642 char family[10];
01643
01644
01645
01646
01647
01648 if ((processor[0] == '6') && (processor[1] == '8'))
01649 {
01650 if (processor[2] == '3')
01651 {
01652 switch (processor[3])
01653 {
01654 case '0':
01655 case '2':
01656 case '5':
01657 strcpy (family, "68000");
01658 break;
01659
01660 case '3':
01661
01662 case '6':
01663 case '7':
01664 strcpy (family, "68332");
01665 break;
01666
01667 case '4':
01668 if (processor[4] == '9')
01669 strcpy (family, "68030");
01670 else
01671 strcpy (family, "68332");
01672 break;
01673
01674 default:
01675 strcpy (family, "68332");
01676 }
01677 }
01678 else if (TOUPPER (processor[3]) == 'F')
01679 strcpy (family, "68332");
01680 else if ((TOUPPER (processor[3]) == 'C')
01681 && ((TOUPPER (processor[2]) == 'E')
01682 || (TOUPPER (processor[2]) == 'H')
01683 || (TOUPPER (processor[2]) == 'L')))
01684 {
01685 strcpy (family, "68");
01686 strncat (family, processor + 4, 7);
01687 family[9] = '\0';
01688 }
01689 else
01690 {
01691 strncpy (family, processor, 9);
01692 family[9] = '\0';
01693 }
01694 }
01695 else if ((strncmp (processor, "cpu32", 5) == 0)
01696 || (strncmp (processor, "CPU32", 5) == 0))
01697 strcpy (family, "68332");
01698 else
01699 {
01700 strncpy (family, processor, 9);
01701 family[9] = '\0';
01702 }
01703
01704 arch = bfd_scan_arch (family);
01705 if (arch == 0)
01706 goto got_wrong_format;
01707 abfd->arch_info = arch;
01708 }
01709
01710 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
01711 goto fail;
01712
01713 next_byte (&(ieee->h));
01714
01715 if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
01716 goto fail;
01717
01718 if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
01719 goto fail;
01720
01721
01722 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum
01723 || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
01724 next_byte (&(ieee->h));
01725
01726 for (part = 0; part < N_W_VARIABLES; part++)
01727 {
01728 bfd_boolean ok;
01729
01730 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
01731 goto fail;
01732
01733 if (this_byte_and_next (&(ieee->h)) != part)
01734 goto fail;
01735
01736 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
01737 if (! ok)
01738 goto fail;
01739 }
01740
01741 if (ieee->w.r.external_part != 0)
01742 abfd->flags = HAS_SYMS;
01743
01744
01745
01746
01747
01748
01749 amt = ieee->w.r.me_record + 1;
01750 IEEE_DATA (abfd)->h.first_byte =
01751 (unsigned char *) bfd_alloc (ieee->h.abfd, amt);
01752 if (!IEEE_DATA (abfd)->h.first_byte)
01753 goto fail;
01754 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
01755 goto fail;
01756
01757
01758 bfd_bread ((PTR) (IEEE_DATA (abfd)->h.first_byte),
01759 (bfd_size_type) ieee->w.r.me_record + 1, abfd);
01760
01761 ieee_slurp_sections (abfd);
01762
01763 if (! ieee_slurp_debug (abfd))
01764 goto fail;
01765
01766
01767
01768 if (! ieee_slurp_section_data (abfd))
01769 goto fail;
01770
01771 return abfd->xvec;
01772 got_wrong_format:
01773 bfd_set_error (bfd_error_wrong_format);
01774 fail:
01775 bfd_release (abfd, ieee);
01776 abfd->tdata.ieee_data = save;
01777 return (const bfd_target *) NULL;
01778 }
01779
01780 static void
01781 ieee_get_symbol_info (ignore_abfd, symbol, ret)
01782 bfd *ignore_abfd ATTRIBUTE_UNUSED;
01783 asymbol *symbol;
01784 symbol_info *ret;
01785 {
01786 bfd_symbol_info (symbol, ret);
01787 if (symbol->name[0] == ' ')
01788 ret->name = "* empty table entry ";
01789 if (!symbol->section)
01790 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
01791 }
01792
01793 static void
01794 ieee_print_symbol (abfd, afile, symbol, how)
01795 bfd *abfd;
01796 PTR afile;
01797 asymbol *symbol;
01798 bfd_print_symbol_type how;
01799 {
01800 FILE *file = (FILE *) afile;
01801
01802 switch (how)
01803 {
01804 case bfd_print_symbol_name:
01805 fprintf (file, "%s", symbol->name);
01806 break;
01807 case bfd_print_symbol_more:
01808 BFD_FAIL ();
01809 break;
01810 case bfd_print_symbol_all:
01811 {
01812 const char *section_name =
01813 (symbol->section == (asection *) NULL
01814 ? "*abs"
01815 : symbol->section->name);
01816
01817 if (symbol->name[0] == ' ')
01818 {
01819 fprintf (file, "* empty table entry ");
01820 }
01821 else
01822 {
01823 bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
01824
01825 fprintf (file, " %-5s %04x %02x %s",
01826 section_name,
01827 (unsigned) ieee_symbol (symbol)->index,
01828 (unsigned) 0,
01829 symbol->name);
01830 }
01831 }
01832 break;
01833 }
01834 }
01835
01836 static bfd_boolean
01837 do_one (ieee, current_map, location_ptr, s, iterations)
01838 ieee_data_type *ieee;
01839 ieee_per_section_type *current_map;
01840 unsigned char *location_ptr;
01841 asection *s;
01842 int iterations;
01843 {
01844 switch (this_byte (&(ieee->h)))
01845 {
01846 case ieee_load_constant_bytes_enum:
01847 {
01848 unsigned int number_of_maus;
01849 unsigned int i;
01850
01851 next_byte (&(ieee->h));
01852 number_of_maus = must_parse_int (&(ieee->h));
01853
01854 for (i = 0; i < number_of_maus; i++)
01855 {
01856 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
01857 next_byte (&(ieee->h));
01858 }
01859 }
01860 break;
01861
01862 case ieee_load_with_relocation_enum:
01863 {
01864 bfd_boolean loop = TRUE;
01865
01866 next_byte (&(ieee->h));
01867 while (loop)
01868 {
01869 switch (this_byte (&(ieee->h)))
01870 {
01871 case ieee_variable_R_enum:
01872
01873 case ieee_function_signed_open_b_enum:
01874 case ieee_function_unsigned_open_b_enum:
01875 case ieee_function_either_open_b_enum:
01876 {
01877 unsigned int extra = 4;
01878 bfd_boolean pcrel = FALSE;
01879 asection *section;
01880 ieee_reloc_type *r;
01881 bfd_size_type amt = sizeof (ieee_reloc_type);
01882
01883 r = (ieee_reloc_type *) bfd_alloc (ieee->h.abfd, amt);
01884 if (!r)
01885 return FALSE;
01886
01887 *(current_map->reloc_tail_ptr) = r;
01888 current_map->reloc_tail_ptr = &r->next;
01889 r->next = (ieee_reloc_type *) NULL;
01890 next_byte (&(ieee->h));
01891
01892 r->relent.sym_ptr_ptr = 0;
01893 parse_expression (ieee,
01894 &r->relent.addend,
01895 &r->symbol,
01896 &pcrel, &extra, §ion);
01897 r->relent.address = current_map->pc;
01898 s->flags |= SEC_RELOC;
01899 s->owner->flags |= HAS_RELOC;
01900 s->reloc_count++;
01901 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
01902 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
01903
01904 if (this_byte (&(ieee->h)) == (int) ieee_comma)
01905 {
01906 next_byte (&(ieee->h));
01907
01908 extra = must_parse_int (&(ieee->h));
01909 };
01910
01911 switch (this_byte (&(ieee->h)))
01912 {
01913 case ieee_function_signed_close_b_enum:
01914 next_byte (&(ieee->h));
01915 break;
01916 case ieee_function_unsigned_close_b_enum:
01917 next_byte (&(ieee->h));
01918 break;
01919 case ieee_function_either_close_b_enum:
01920 next_byte (&(ieee->h));
01921 break;
01922 default:
01923 break;
01924 }
01925
01926
01927
01928
01929
01930
01931
01932 switch (extra)
01933 {
01934 case 0:
01935 case 4:
01936
01937 if (pcrel)
01938 {
01939 #if KEEPMINUSPCININST
01940 bfd_put_32 (ieee->h.abfd, -current_map->pc,
01941 location_ptr + current_map->pc);
01942 r->relent.howto = &rel32_howto;
01943 r->relent.addend -= current_map->pc;
01944 #else
01945 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
01946 current_map->pc);
01947 r->relent.howto = &rel32_howto;
01948 #endif
01949 }
01950 else
01951 {
01952 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
01953 location_ptr + current_map->pc);
01954 r->relent.howto = &abs32_howto;
01955 }
01956 current_map->pc += 4;
01957 break;
01958 case 2:
01959 if (pcrel)
01960 {
01961 #if KEEPMINUSPCININST
01962 bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
01963 location_ptr + current_map->pc);
01964 r->relent.addend -= current_map->pc;
01965 r->relent.howto = &rel16_howto;
01966 #else
01967
01968 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
01969 location_ptr + current_map->pc);
01970 r->relent.howto = &rel16_howto;
01971 #endif
01972 }
01973
01974 else
01975 {
01976 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
01977 location_ptr + current_map->pc);
01978 r->relent.howto = &abs16_howto;
01979 }
01980 current_map->pc += 2;
01981 break;
01982 case 1:
01983 if (pcrel)
01984 {
01985 #if KEEPMINUSPCININST
01986 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
01987 r->relent.addend -= current_map->pc;
01988 r->relent.howto = &rel8_howto;
01989 #else
01990 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
01991 r->relent.howto = &rel8_howto;
01992 #endif
01993 }
01994 else
01995 {
01996 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
01997 r->relent.howto = &abs8_howto;
01998 }
01999 current_map->pc += 1;
02000 break;
02001
02002 default:
02003 BFD_FAIL ();
02004 return FALSE;
02005 }
02006 }
02007 break;
02008 default:
02009 {
02010 bfd_vma this_size;
02011 if (parse_int (&(ieee->h), &this_size))
02012 {
02013 unsigned int i;
02014 for (i = 0; i < this_size; i++)
02015 {
02016 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
02017 next_byte (&(ieee->h));
02018 }
02019 }
02020 else
02021 {
02022 loop = FALSE;
02023 }
02024 }
02025 }
02026
02027
02028
02029 if (iterations != 1)
02030 loop = FALSE;
02031 }
02032 }
02033 }
02034 return TRUE;
02035 }
02036
02037
02038
02039 static bfd_boolean
02040 ieee_slurp_section_data (abfd)
02041 bfd *abfd;
02042 {
02043 bfd_byte *location_ptr = (bfd_byte *) NULL;
02044 ieee_data_type *ieee = IEEE_DATA (abfd);
02045 unsigned int section_number;
02046
02047 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
02048 asection *s;
02049
02050 if (ieee->read_data)
02051 return TRUE;
02052 ieee->read_data = TRUE;
02053 ieee_seek (ieee, ieee->w.r.data_part);
02054
02055
02056 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
02057 {
02058 ieee_per_section_type *per = ieee_per_section (s);
02059 if ((s->flags & SEC_DEBUGGING) != 0)
02060 continue;
02061 per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->size);
02062 if (!per->data)
02063 return FALSE;
02064 per->reloc_tail_ptr =
02065 (ieee_reloc_type **) & (s->relocation);
02066 }
02067
02068 while (TRUE)
02069 {
02070 switch (this_byte (&(ieee->h)))
02071 {
02072
02073 default:
02074 return TRUE;
02075
02076 case ieee_set_current_section_enum:
02077 next_byte (&(ieee->h));
02078 section_number = must_parse_int (&(ieee->h));
02079 s = ieee->section_table[section_number];
02080 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
02081 current_map = ieee_per_section (s);
02082 location_ptr = current_map->data - s->vma;
02083
02084
02085
02086 current_map->pc = s->vma;
02087 break;
02088
02089 case ieee_e2_first_byte_enum:
02090 next_byte (&(ieee->h));
02091 switch (this_byte (&(ieee->h)))
02092 {
02093 case ieee_set_current_pc_enum & 0xff:
02094 {
02095 bfd_vma value;
02096 ieee_symbol_index_type symbol;
02097 unsigned int extra;
02098 bfd_boolean pcrel;
02099
02100 next_byte (&(ieee->h));
02101 must_parse_int (&(ieee->h));
02102 parse_expression (ieee, &value,
02103 &symbol,
02104 &pcrel, &extra,
02105 0);
02106 current_map->pc = value;
02107 BFD_ASSERT ((unsigned) (value - s->vma) <= s->size);
02108 }
02109 break;
02110
02111 case ieee_value_starting_address_enum & 0xff:
02112 next_byte (&(ieee->h));
02113 if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
02114 next_byte (&(ieee->h));
02115 abfd->start_address = must_parse_int (&(ieee->h));
02116
02117 return TRUE;
02118 default:
02119 BFD_FAIL ();
02120 return FALSE;
02121 }
02122 break;
02123 case ieee_repeat_data_enum:
02124 {
02125
02126
02127
02128
02129 unsigned int iterations;
02130 unsigned char *start;
02131
02132 next_byte (&(ieee->h));
02133 iterations = must_parse_int (&(ieee->h));
02134 start = ieee->h.input_p;
02135 if (start[0] == (int) ieee_load_constant_bytes_enum
02136 && start[1] == 1)
02137 {
02138 while (iterations != 0)
02139 {
02140 location_ptr[current_map->pc++] = start[2];
02141 iterations--;
02142 }
02143 next_byte (&(ieee->h));
02144 next_byte (&(ieee->h));
02145 next_byte (&(ieee->h));
02146 }
02147 else
02148 {
02149 while (iterations != 0)
02150 {
02151 ieee->h.input_p = start;
02152 if (!do_one (ieee, current_map, location_ptr, s,
02153 (int) iterations))
02154 return FALSE;
02155 iterations--;
02156 }
02157 }
02158 }
02159 break;
02160 case ieee_load_constant_bytes_enum:
02161 case ieee_load_with_relocation_enum:
02162 if (!do_one (ieee, current_map, location_ptr, s, 1))
02163 return FALSE;
02164 }
02165 }
02166 }
02167
02168 static bfd_boolean
02169 ieee_new_section_hook (abfd, newsect)
02170 bfd *abfd;
02171 asection *newsect;
02172 {
02173 newsect->used_by_bfd
02174 = (PTR) bfd_alloc (abfd, (bfd_size_type) sizeof (ieee_per_section_type));
02175 if (!newsect->used_by_bfd)
02176 return FALSE;
02177 ieee_per_section (newsect)->data = (bfd_byte *) NULL;
02178 ieee_per_section (newsect)->section = newsect;
02179 return TRUE;
02180 }
02181
02182 static long
02183 ieee_get_reloc_upper_bound (abfd, asect)
02184 bfd *abfd;
02185 sec_ptr asect;
02186 {
02187 if ((asect->flags & SEC_DEBUGGING) != 0)
02188 return 0;
02189 if (! ieee_slurp_section_data (abfd))
02190 return -1;
02191 return (asect->reloc_count + 1) * sizeof (arelent *);
02192 }
02193
02194 static bfd_boolean
02195 ieee_get_section_contents (abfd, section, location, offset, count)
02196 bfd *abfd;
02197 sec_ptr section;
02198 PTR location;
02199 file_ptr offset;
02200 bfd_size_type count;
02201 {
02202 ieee_per_section_type *p = ieee_per_section (section);
02203 if ((section->flags & SEC_DEBUGGING) != 0)
02204 return _bfd_generic_get_section_contents (abfd, section, location,
02205 offset, count);
02206 ieee_slurp_section_data (abfd);
02207 (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
02208 return TRUE;
02209 }
02210
02211 static long
02212 ieee_canonicalize_reloc (abfd, section, relptr, symbols)
02213 bfd *abfd;
02214 sec_ptr section;
02215 arelent **relptr;
02216 asymbol **symbols;
02217 {
02218 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
02219 ieee_data_type *ieee = IEEE_DATA (abfd);
02220
02221 if ((section->flags & SEC_DEBUGGING) != 0)
02222 return 0;
02223
02224 while (src != (ieee_reloc_type *) NULL)
02225 {
02226
02227 switch (src->symbol.letter)
02228 {
02229 case 'I':
02230 src->relent.sym_ptr_ptr =
02231 symbols + src->symbol.index + ieee->external_symbol_base_offset;
02232 break;
02233 case 'X':
02234 src->relent.sym_ptr_ptr =
02235 symbols + src->symbol.index + ieee->external_reference_base_offset;
02236 break;
02237 case 0:
02238 if (src->relent.sym_ptr_ptr != NULL)
02239 src->relent.sym_ptr_ptr =
02240 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
02241 break;
02242 default:
02243
02244 BFD_FAIL ();
02245 }
02246 *relptr++ = &src->relent;
02247 src = src->next;
02248 }
02249 *relptr = (arelent *) NULL;
02250 return section->reloc_count;
02251 }
02252
02253 static int
02254 comp (ap, bp)
02255 const PTR ap;
02256 const PTR bp;
02257 {
02258 arelent *a = *((arelent **) ap);
02259 arelent *b = *((arelent **) bp);
02260 return a->address - b->address;
02261 }
02262
02263
02264
02265 static bfd_boolean
02266 ieee_write_section_part (abfd)
02267 bfd *abfd;
02268 {
02269 ieee_data_type *ieee = IEEE_DATA (abfd);
02270 asection *s;
02271 ieee->w.r.section_part = bfd_tell (abfd);
02272 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
02273 {
02274 if (! bfd_is_abs_section (s)
02275 && (s->flags & SEC_DEBUGGING) == 0)
02276 {
02277 if (! ieee_write_byte (abfd, ieee_section_type_enum)
02278 || ! ieee_write_byte (abfd,
02279 (bfd_byte) (s->index
02280 + IEEE_SECTION_NUMBER_BASE)))
02281 return FALSE;
02282
02283 if (abfd->flags & EXEC_P)
02284 {
02285
02286 if (! ieee_write_byte (abfd, ieee_variable_A_enum)
02287 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
02288 return FALSE;
02289 }
02290 else
02291 {
02292 if (! ieee_write_byte (abfd, ieee_variable_C_enum))
02293 return FALSE;
02294 }
02295
02296 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
02297 {
02298 case SEC_CODE | SEC_LOAD:
02299 case SEC_CODE:
02300 if (! ieee_write_byte (abfd, ieee_variable_P_enum))
02301 return FALSE;
02302 break;
02303 case SEC_DATA:
02304 default:
02305 if (! ieee_write_byte (abfd, ieee_variable_D_enum))
02306 return FALSE;
02307 break;
02308 case SEC_ROM:
02309 case SEC_ROM | SEC_DATA:
02310 case SEC_ROM | SEC_LOAD:
02311 case SEC_ROM | SEC_DATA | SEC_LOAD:
02312 if (! ieee_write_byte (abfd, ieee_variable_R_enum))
02313 return FALSE;
02314 }
02315
02316
02317 if (! ieee_write_id (abfd, s->name))
02318 return FALSE;
02319
02320 if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
02321 || ! ieee_write_byte (abfd,
02322 (bfd_byte) (s->index
02323 + IEEE_SECTION_NUMBER_BASE))
02324 || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
02325 return FALSE;
02326
02327
02328 if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
02329 || ! ieee_write_byte (abfd,
02330 (bfd_byte) (s->index
02331 + IEEE_SECTION_NUMBER_BASE))
02332 || ! ieee_write_int (abfd, s->size))
02333 return FALSE;
02334 if (abfd->flags & EXEC_P)
02335 {
02336
02337
02338 if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
02339 || ! ieee_write_byte (abfd,
02340 ((bfd_byte)
02341 (s->index
02342 + IEEE_SECTION_NUMBER_BASE)))
02343 || ! ieee_write_int (abfd, s->lma))
02344 return FALSE;
02345 }
02346 }
02347 }
02348
02349 return TRUE;
02350 }
02351
02352
02353 static bfd_boolean
02354 do_with_relocs (abfd, s)
02355 bfd *abfd;
02356 asection *s;
02357 {
02358 unsigned int number_of_maus_in_address =
02359 bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
02360 unsigned int relocs_to_go = s->reloc_count;
02361 bfd_byte *stream = ieee_per_section (s)->data;
02362 arelent **p = s->orelocation;
02363 bfd_size_type current_byte_index = 0;
02364
02365 qsort (s->orelocation,
02366 relocs_to_go,
02367 sizeof (arelent **),
02368 comp);
02369
02370
02371 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
02372 || ! ieee_write_byte (abfd,
02373 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
02374 || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
02375 || ! ieee_write_byte (abfd,
02376 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
02377 return FALSE;
02378
02379 if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
02380 {
02381 if (! ieee_write_int (abfd, s->lma))
02382 return FALSE;
02383 }
02384 else
02385 {
02386 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
02387 return FALSE;
02388 }
02389
02390 if (relocs_to_go == 0)
02391 {
02392
02393
02394 while (current_byte_index < s->size)
02395 {
02396 bfd_size_type run;
02397 unsigned int MAXRUN = 127;
02398
02399 run = MAXRUN;
02400 if (run > s->size - current_byte_index)
02401 run = s->size - current_byte_index;
02402
02403 if (run != 0)
02404 {
02405 if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
02406 return FALSE;
02407
02408 if (! ieee_write_int (abfd, run))
02409 return FALSE;
02410 if (bfd_bwrite ((PTR) (stream + current_byte_index), run, abfd)
02411 != run)
02412 return FALSE;
02413 current_byte_index += run;
02414 }
02415 }
02416 }
02417 else
02418 {
02419 if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
02420 return FALSE;
02421
02422
02423
02424
02425
02426 if ((PTR) stream == (PTR) NULL)
02427 {
02428
02429 stream = (unsigned char *) bfd_zalloc (abfd, s->size);
02430 if (!stream)
02431 return FALSE;
02432 }
02433 while (current_byte_index < s->size)
02434 {
02435 bfd_size_type run;
02436 unsigned int MAXRUN = 127;
02437
02438 if (relocs_to_go)
02439 {
02440 run = (*p)->address - current_byte_index;
02441 if (run > MAXRUN)
02442 run = MAXRUN;
02443 }
02444 else
02445 run = MAXRUN;
02446
02447 if (run > s->size - current_byte_index)
02448 run = s->size - current_byte_index;
02449
02450 if (run != 0)
02451 {
02452
02453 if (! ieee_write_int (abfd, run))
02454 return FALSE;
02455 if (bfd_bwrite ((PTR) (stream + current_byte_index), run, abfd)
02456 != run)
02457 return FALSE;
02458 current_byte_index += run;
02459 }
02460
02461
02462 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
02463 {
02464 while (relocs_to_go
02465 && (*p) && (*p)->address == current_byte_index)
02466 {
02467 arelent *r = *p;
02468 bfd_signed_vma ov;
02469 switch (r->howto->size)
02470 {
02471 case 2:
02472
02473 ov = bfd_get_signed_32 (abfd,
02474 stream + current_byte_index);
02475 current_byte_index += 4;
02476 break;
02477 case 1:
02478 ov = bfd_get_signed_16 (abfd,
02479 stream + current_byte_index);
02480 current_byte_index += 2;
02481 break;
02482 case 0:
02483 ov = bfd_get_signed_8 (abfd,
02484 stream + current_byte_index);
02485 current_byte_index++;
02486 break;
02487 default:
02488 ov = 0;
02489 BFD_FAIL ();
02490 return FALSE;
02491 }
02492
02493 ov &= r->howto->src_mask;
02494
02495 if (r->howto->pc_relative
02496 && ! r->howto->pcrel_offset)
02497 ov += r->address;
02498
02499 if (! ieee_write_byte (abfd,
02500 ieee_function_either_open_b_enum))
02501 return FALSE;
02502
02503
02504
02505 if (r->sym_ptr_ptr != (asymbol **) NULL)
02506 {
02507 if (! ieee_write_expression (abfd, r->addend + ov,
02508 *(r->sym_ptr_ptr),
02509 r->howto->pc_relative,
02510 (unsigned) s->index))
02511 return FALSE;
02512 }
02513 else
02514 {
02515 if (! ieee_write_expression (abfd, r->addend + ov,
02516 (asymbol *) NULL,
02517 r->howto->pc_relative,
02518 (unsigned) s->index))
02519 return FALSE;
02520 }
02521
02522 if (number_of_maus_in_address
02523 != bfd_get_reloc_size (r->howto))
02524 {
02525 bfd_vma rsize = bfd_get_reloc_size (r->howto);
02526 if (! ieee_write_int (abfd, rsize))
02527 return FALSE;
02528 }
02529 if (! ieee_write_byte (abfd,
02530 ieee_function_either_close_b_enum))
02531 return FALSE;
02532
02533 relocs_to_go--;
02534 p++;
02535 }
02536
02537 }
02538 }
02539 }
02540
02541 return TRUE;
02542 }
02543
02544
02545
02546
02547
02548 static bfd_boolean
02549 do_as_repeat (abfd, s)
02550 bfd *abfd;
02551 asection *s;
02552 {
02553 if (s->size)
02554 {
02555 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
02556 || ! ieee_write_byte (abfd,
02557 (bfd_byte) (s->index
02558 + IEEE_SECTION_NUMBER_BASE))
02559 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
02560 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
02561 || ! ieee_write_byte (abfd,
02562 (bfd_byte) (s->index
02563 + IEEE_SECTION_NUMBER_BASE)))
02564 return FALSE;
02565
02566 if ((abfd->flags & EXEC_P) != 0)
02567 {
02568 if (! ieee_write_int (abfd, s->lma))
02569 return FALSE;
02570 }
02571 else
02572 {
02573 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
02574 return FALSE;
02575 }
02576
02577 if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
02578 || ! ieee_write_int (abfd, s->size)
02579 || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
02580 || ! ieee_write_byte (abfd, 1)
02581 || ! ieee_write_byte (abfd, 0))
02582 return FALSE;
02583 }
02584
02585 return TRUE;
02586 }
02587
02588 static bfd_boolean
02589 do_without_relocs (abfd, s)
02590 bfd *abfd;
02591 asection *s;
02592 {
02593 bfd_byte *stream = ieee_per_section (s)->data;
02594
02595 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
02596 {
02597 if (! do_as_repeat (abfd, s))
02598 return FALSE;
02599 }
02600 else
02601 {
02602 unsigned int i;
02603
02604 for (i = 0; i < s->size; i++)
02605 {
02606 if (stream[i] != 0)
02607 {
02608 if (! do_with_relocs (abfd, s))
02609 return FALSE;
02610 return TRUE;
02611 }
02612 }
02613 if (! do_as_repeat (abfd, s))
02614 return FALSE;
02615 }
02616
02617 return TRUE;
02618 }
02619
02620
02621 static unsigned char *output_ptr_start;
02622 static unsigned char *output_ptr;
02623 static unsigned char *output_ptr_end;
02624 static unsigned char *input_ptr_start;
02625 static unsigned char *input_ptr;
02626 static unsigned char *input_ptr_end;
02627 static bfd *input_bfd;
02628 static bfd *output_bfd;
02629 static int output_buffer;
02630
02631 static bfd_boolean
02632 ieee_mkobject (abfd)
02633 bfd *abfd;
02634 {
02635 bfd_size_type amt;
02636
02637 output_ptr_start = NULL;
02638 output_ptr = NULL;
02639 output_ptr_end = NULL;
02640 input_ptr_start = NULL;
02641 input_ptr = NULL;
02642 input_ptr_end = NULL;
02643 input_bfd = NULL;
02644 output_bfd = NULL;
02645 output_buffer = 0;
02646 amt = sizeof (ieee_data_type);
02647 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, amt);
02648 return abfd->tdata.ieee_data != NULL;
02649 }
02650
02651 static void
02652 fill ()
02653 {
02654 bfd_size_type amt = input_ptr_end - input_ptr_start;
02655
02656
02657 bfd_bread ((PTR) input_ptr_start, amt, input_bfd);
02658 input_ptr = input_ptr_start;
02659 }
02660
02661 static void
02662 flush ()
02663 {
02664 bfd_size_type amt = output_ptr - output_ptr_start;
02665
02666 if (bfd_bwrite ((PTR) (output_ptr_start), amt, output_bfd) != amt)
02667 abort ();
02668 output_ptr = output_ptr_start;
02669 output_buffer++;
02670 }
02671
02672 #define THIS() ( *input_ptr )
02673 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
02674 #define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
02675
02676 static void
02677 write_int (value)
02678 int value;
02679 {
02680 if (value >= 0 && value <= 127)
02681 {
02682 OUT (value);
02683 }
02684 else
02685 {
02686 unsigned int length;
02687
02688
02689 if (value & 0xff000000)
02690 length = 4;
02691 else if (value & 0x00ff0000)
02692 length = 3;
02693 else if (value & 0x0000ff00)
02694 length = 2;
02695 else
02696 length = 1;
02697
02698 OUT ((int) ieee_number_repeat_start_enum + length);
02699 switch (length)
02700 {
02701 case 4:
02702 OUT (value >> 24);
02703 case 3:
02704 OUT (value >> 16);
02705 case 2:
02706 OUT (value >> 8);
02707 case 1:
02708 OUT (value);
02709 }
02710 }
02711 }
02712
02713 static void
02714 copy_id ()
02715 {
02716 int length = THIS ();
02717 char ch;
02718
02719 OUT (length);
02720 NEXT ();
02721 while (length--)
02722 {
02723 ch = THIS ();
02724 OUT (ch);
02725 NEXT ();
02726 }
02727 }
02728
02729 #define VAR(x) ((x | 0x80))
02730 static void
02731 copy_expression ()
02732 {
02733 int stack[10];
02734 int *tos = stack;
02735 int value;
02736
02737 while (1)
02738 {
02739 switch (THIS ())
02740 {
02741 case 0x84:
02742 NEXT ();
02743 value = THIS ();
02744 NEXT ();
02745 value = (value << 8) | THIS ();
02746 NEXT ();
02747 value = (value << 8) | THIS ();
02748 NEXT ();
02749 value = (value << 8) | THIS ();
02750 NEXT ();
02751 *tos++ = value;
02752 break;
02753 case 0x83:
02754 NEXT ();
02755 value = THIS ();
02756 NEXT ();
02757 value = (value << 8) | THIS ();
02758 NEXT ();
02759 value = (value << 8) | THIS ();
02760 NEXT ();
02761 *tos++ = value;
02762 break;
02763 case 0x82:
02764 NEXT ();
02765 value = THIS ();
02766 NEXT ();
02767 value = (value << 8) | THIS ();
02768 NEXT ();
02769 *tos++ = value;
02770 break;
02771 case 0x81:
02772 NEXT ();
02773 value = THIS ();
02774 NEXT ();
02775 *tos++ = value;
02776 break;
02777 case 0x80:
02778 NEXT ();
02779 *tos++ = 0;
02780 break;
02781 default:
02782 if (THIS () > 0x84)
02783 {
02784
02785 write_int (*(--tos));
02786 return;
02787 }
02788 *tos++ = THIS ();
02789 NEXT ();
02790 break;
02791 case 0xa5:
02792
02793 value = *(--tos);
02794 value += *(--tos);
02795 *tos++ = value;
02796 NEXT ();
02797 break;
02798 case VAR ('R'):
02799 {
02800 int section_number;
02801 ieee_data_type *ieee;
02802 asection *s;
02803
02804 NEXT ();
02805 section_number = THIS ();
02806
02807 NEXT ();
02808 ieee = IEEE_DATA (input_bfd);
02809 s = ieee->section_table[section_number];
02810 value = 0;
02811 if (s->output_section)
02812 value = s->output_section->lma;
02813 value += s->output_offset;
02814 *tos++ = value;
02815 }
02816 break;
02817 case 0x90:
02818 {
02819 NEXT ();
02820 write_int (*(--tos));
02821 OUT (0x90);
02822 return;
02823 }
02824 }
02825 }
02826 }
02827
02828
02829
02830
02831 static void
02832 fill_int (buf)
02833 struct output_buffer_struct *buf;
02834 {
02835 if (buf->buffer == output_buffer)
02836 {
02837
02838 int value = output_ptr - buf->ptrp + 3;
02839 buf->ptrp[0] = value >> 24;
02840 buf->ptrp[1] = value >> 16;
02841 buf->ptrp[2] = value >> 8;
02842 buf->ptrp[3] = value >> 0;
02843 }
02844 }
02845
02846 static void
02847 drop_int (buf)
02848 struct output_buffer_struct *buf;
02849 {
02850 int type = THIS ();
02851 int ch;
02852
02853 if (type <= 0x84)
02854 {
02855 NEXT ();
02856 switch (type)
02857 {
02858 case 0x84:
02859 ch = THIS ();
02860 NEXT ();
02861 case 0x83:
02862 ch = THIS ();
02863 NEXT ();
02864 case 0x82:
02865 ch = THIS ();
02866 NEXT ();
02867 case 0x81:
02868 ch = THIS ();
02869 NEXT ();
02870 case 0x80:
02871 break;
02872 }
02873 }
02874 OUT (0x84);
02875 buf->ptrp = output_ptr;
02876 buf->buffer = output_buffer;
02877 OUT (0);
02878 OUT (0);
02879 OUT (0);
02880 OUT (0);
02881 }
02882
02883 static void
02884 copy_int ()
02885 {
02886 int type = THIS ();
02887 int ch;
02888 if (type <= 0x84)
02889 {
02890 OUT (type);
02891 NEXT ();
02892 switch (type)
02893 {
02894 case 0x84:
02895 ch = THIS ();
02896 NEXT ();
02897 OUT (ch);
02898 case 0x83:
02899 ch = THIS ();
02900 NEXT ();
02901 OUT (ch);
02902 case 0x82:
02903 ch = THIS ();
02904 NEXT ();
02905 OUT (ch);
02906 case 0x81:
02907 ch = THIS ();
02908 NEXT ();
02909 OUT (ch);
02910 case 0x80:
02911 break;
02912 }
02913 }
02914 }
02915
02916 #define ID copy_id()
02917 #define INT copy_int()
02918 #define EXP copy_expression()
02919 #define INTn(q) copy_int()
02920 #define EXPn(q) copy_expression()
02921
02922 static void
02923 f1_record ()
02924 {
02925 int ch;
02926
02927
02928 NEXT ();
02929 ch = THIS ();
02930 switch (ch)
02931 {
02932 default:
02933 OUT (0xf1);
02934 OUT (ch);
02935 break;
02936 case 0xc9:
02937 NEXT ();
02938 OUT (0xf1);
02939 OUT (0xc9);
02940 INT;
02941 INT;
02942 ch = THIS ();
02943 switch (ch)
02944 {
02945 case 0x16:
02946 NEXT ();
02947 break;
02948 case 0x01:
02949 NEXT ();
02950 break;
02951 case 0x00:
02952 NEXT ();
02953 INT;
02954 break;
02955 case 0x03:
02956 NEXT ();
02957 INT;
02958 break;
02959 case 0x13:
02960 EXPn (instruction address);
02961 break;
02962 default:
02963 break;
02964 }
02965 break;
02966 case 0xd8:
02967
02968 NEXT ();
02969 OUT (0xf1);
02970 OUT (0xd8);
02971 EXP;
02972 EXP;
02973 EXP;
02974 EXP;
02975 break;
02976 case 0xce:
02977 NEXT ();
02978 OUT (0xf1);
02979 OUT (0xce);
02980 INT;
02981 INT;
02982 ch = THIS ();
02983 INT;
02984 switch (ch)
02985 {
02986 case 0x01:
02987 INT;
02988 INT;
02989 break;
02990 case 0x02:
02991 INT;
02992 break;
02993 case 0x04:
02994 EXPn (external function);
02995 break;
02996 case 0x05:
02997 break;
02998 case 0x07:
02999 INTn (line number);
03000 INT;
03001 case 0x08:
03002 break;
03003 case 0x0a:
03004 INTn (locked register);
03005 INT;
03006 break;
03007 case 0x3f:
03008 copy_till_end ();
03009 break;
03010 case 0x3e:
03011 copy_till_end ();
03012 break;
03013 case 0x40:
03014 copy_till_end ();
03015 break;
03016 case 0x41:
03017 ID;
03018 break;
03019 }
03020 }
03021 }
03022
03023 static void
03024 f0_record ()
03025 {
03026
03027 NEXT ();
03028 OUT (0xf0);
03029 INTn (Symbol name);
03030 ID;
03031 }
03032
03033 static void
03034 copy_till_end ()
03035 {
03036 int ch = THIS ();
03037
03038 while (1)
03039 {
03040 while (ch <= 0x80)
03041 {
03042 OUT (ch);
03043 NEXT ();
03044 ch = THIS ();
03045 }
03046 switch (ch)
03047 {
03048 case 0x84:
03049 OUT (THIS ());
03050 NEXT ();
03051 case 0x83:
03052 OUT (THIS ());
03053 NEXT ();
03054 case 0x82:
03055 OUT (THIS ());
03056 NEXT ();
03057 case 0x81:
03058 OUT (THIS ());
03059 NEXT ();
03060 OUT (THIS ());
03061 NEXT ();
03062
03063 ch = THIS ();
03064 break;
03065 default:
03066 return;
03067 }
03068 }
03069
03070 }
03071
03072 static void
03073 f2_record ()
03074 {
03075 NEXT ();
03076 OUT (0xf2);
03077 INT;
03078 NEXT ();
03079 OUT (0xce);
03080 INT;
03081 copy_till_end ();
03082 }
03083
03084
03085 static void
03086 f8_record ()
03087 {
03088 int ch;
03089 NEXT ();
03090 ch = THIS ();
03091 switch (ch)
03092 {
03093 case 0x01:
03094 case 0x02:
03095 case 0x03:
03096
03097
03098
03099 {
03100 struct output_buffer_struct ob;
03101
03102 NEXT ();
03103 OUT (0xf8);
03104 OUT (ch);
03105 drop_int (&ob);
03106 ID;
03107
03108 block ();
03109
03110 NEXT ();
03111 fill_int (&ob);
03112 OUT (0xf9);
03113 }
03114 break;
03115 case 0x04:
03116
03117 {
03118 struct output_buffer_struct ob;
03119
03120 NEXT ();
03121 OUT (0xf8);
03122 OUT (0x04);
03123 drop_int (&ob);
03124 ID;
03125 INTn (stack size);
03126 INTn (ret val);
03127 EXPn (offset);
03128
03129 block ();
03130
03131 NEXT ();
03132 OUT (0xf9);
03133 EXPn (size of block);
03134 fill_int (&ob);
03135 }
03136 break;
03137
03138 case 0x05:
03139
03140 {
03141 struct output_buffer_struct ob;
03142
03143 NEXT ();
03144 OUT (0xf8);
03145 OUT (0x05);
03146 drop_int (&ob);
03147 ID;
03148 INTn (year);
03149 INTn (month);
03150 INTn (day);
03151 INTn (hour);
03152 INTn (monute);
03153 INTn (second);
03154 block ();
03155 NEXT ();
03156 OUT (0xf9);
03157 fill_int (&ob);
03158 }
03159 break;
03160
03161 case 0x06:
03162
03163 {
03164 struct output_buffer_struct ob;
03165
03166 NEXT ();
03167 OUT (0xf8);
03168 OUT (0x06);
03169 drop_int (&ob);
03170 ID;
03171 INTn (stack size);
03172 INTn (type return);
03173 EXPn (offset);
03174 block ();
03175 NEXT ();
03176 OUT (0xf9);
03177 EXPn (size);
03178 fill_int (&ob);
03179 }
03180 break;
03181
03182 case 0x0a:
03183
03184 {
03185 struct output_buffer_struct ob;
03186
03187 NEXT ();
03188 OUT (0xf8);
03189 OUT (0x0a);
03190 drop_int (&ob);
03191 ID;
03192 ID;
03193 INT;
03194 ID;
03195 INT;
03196 INT;
03197 INT;
03198 INT;
03199 INT;
03200 INT;
03201
03202 block ();
03203
03204 NEXT ();
03205 OUT (0xf9);
03206 fill_int (&ob);
03207 }
03208 break;
03209 case 0x0b:
03210 {
03211 struct output_buffer_struct ob;
03212
03213 NEXT ();
03214 OUT (0xf8);
03215 OUT (0x0b);
03216 drop_int (&ob);
03217 ID;
03218 INT;
03219 INTn (section index);
03220 EXPn (offset);
03221 INTn (stuff);
03222
03223 block ();
03224
03225 OUT (0xf9);
03226 NEXT ();
03227 EXPn (Size in Maus);
03228 fill_int (&ob);
03229 }
03230 break;
03231 }
03232 }
03233
03234 static void
03235 e2_record ()
03236 {
03237 OUT (0xe2);
03238 NEXT ();
03239 OUT (0xce);
03240 NEXT ();
03241 INT;
03242 EXP;
03243 }
03244
03245 static void
03246 block ()
03247 {
03248 int ch;
03249
03250 while (1)
03251 {
03252 ch = THIS ();
03253 switch (ch)
03254 {
03255 case 0xe1:
03256 case 0xe5:
03257 return;
03258 case 0xf9:
03259 return;
03260 case 0xf0:
03261 f0_record ();
03262 break;
03263 case 0xf1:
03264 f1_record ();
03265 break;
03266 case 0xf2:
03267 f2_record ();
03268 break;
03269 case 0xf8:
03270 f8_record ();
03271 break;
03272 case 0xe2:
03273 e2_record ();
03274 break;
03275
03276 }
03277 }
03278 }
03279
03280
03281
03282
03283
03284 static void
03285 relocate_debug (output, input)
03286 bfd *output ATTRIBUTE_UNUSED;
03287 bfd *input;
03288 {
03289 #define IBS 400
03290 #define OBS 400
03291 unsigned char input_buffer[IBS];
03292
03293 input_ptr_start = input_ptr = input_buffer;
03294 input_ptr_end = input_buffer + IBS;
03295 input_bfd = input;
03296
03297
03298 bfd_bread ((PTR) input_ptr_start, (bfd_size_type) IBS, input);
03299 block ();
03300 }
03301
03302
03303
03304
03305 static bfd_boolean
03306 ieee_write_debug_part (abfd)
03307 bfd *abfd;
03308 {
03309 ieee_data_type *ieee = IEEE_DATA (abfd);
03310 bfd_chain_type *chain = ieee->chain_root;
03311 unsigned char obuff[OBS];
03312 bfd_boolean some_debug = FALSE;
03313 file_ptr here = bfd_tell (abfd);
03314
03315 output_ptr_start = output_ptr = obuff;
03316 output_ptr_end = obuff + OBS;
03317 output_ptr = obuff;
03318 output_bfd = abfd;
03319
03320 if (chain == (bfd_chain_type *) NULL)
03321 {
03322 asection *s;
03323
03324 for (s = abfd->sections; s != NULL; s = s->next)
03325 if ((s->flags & SEC_DEBUGGING) != 0)
03326 break;
03327 if (s == NULL)
03328 {
03329 ieee->w.r.debug_information_part = 0;
03330 return TRUE;
03331 }
03332
03333 ieee->w.r.debug_information_part = here;
03334 if (bfd_bwrite (s->contents, s->size, abfd) != s->size)
03335 return FALSE;
03336 }
03337 else
03338 {
03339 while (chain != (bfd_chain_type *) NULL)
03340 {
03341 bfd *entry = chain->this;
03342 ieee_data_type *entry_ieee = IEEE_DATA (entry);
03343
03344 if (entry_ieee->w.r.debug_information_part)
03345 {
03346 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
03347 SEEK_SET) != 0)
03348 return FALSE;
03349 relocate_debug (abfd, entry);
03350 }
03351
03352 chain = chain->next;
03353 }
03354
03355 if (some_debug)
03356 ieee->w.r.debug_information_part = here;
03357 else
03358 ieee->w.r.debug_information_part = 0;
03359
03360 flush ();
03361 }
03362
03363 return TRUE;
03364 }
03365
03366
03367
03368 static bfd_boolean
03369 ieee_write_data_part (abfd)
03370 bfd *abfd;
03371 {
03372 asection *s;
03373
03374 ieee_data_type *ieee = IEEE_DATA (abfd);
03375 ieee->w.r.data_part = bfd_tell (abfd);
03376
03377 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
03378 {
03379
03380
03381 if ((s->flags & SEC_LOAD) == 0)
03382 continue;
03383
03384
03385
03386 if (s->reloc_count != 0)
03387 {
03388 if (! do_with_relocs (abfd, s))
03389 return FALSE;
03390 }
03391 else
03392 {
03393 if (! do_without_relocs (abfd, s))
03394 return FALSE;
03395 }
03396 }
03397
03398 return TRUE;
03399 }
03400
03401
03402 static bfd_boolean
03403 init_for_output (abfd)
03404 bfd *abfd;
03405 {
03406 asection *s;
03407
03408 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
03409 {
03410 if ((s->flags & SEC_DEBUGGING) != 0)
03411 continue;
03412 if (s->size != 0)
03413 {
03414 bfd_size_type size = s->size;
03415 ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, size));
03416 if (!ieee_per_section (s)->data)
03417 return FALSE;
03418 }
03419 }
03420 return TRUE;
03421 }
03422
03423
03424
03425
03426
03427
03428 static bfd_boolean
03429 ieee_set_section_contents (abfd, section, location, offset, count)
03430 bfd *abfd;
03431 sec_ptr section;
03432 const PTR location;
03433 file_ptr offset;
03434 bfd_size_type count;
03435 {
03436 if ((section->flags & SEC_DEBUGGING) != 0)
03437 {
03438 if (section->contents == NULL)
03439 {
03440 bfd_size_type size = section->size;
03441 section->contents = (unsigned char *) bfd_alloc (abfd, size);
03442 if (section->contents == NULL)
03443 return FALSE;
03444 }
03445
03446
03447 memcpy (section->contents + offset, location, (size_t) count);
03448 return TRUE;
03449 }
03450
03451 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
03452 {
03453 if (!init_for_output (abfd))
03454 return FALSE;
03455 }
03456 memcpy ((PTR) (ieee_per_section (section)->data + offset),
03457 (PTR) location,
03458 (unsigned int) count);
03459 return TRUE;
03460 }
03461
03462
03463
03464
03465
03466
03467 static bfd_boolean
03468 ieee_write_external_part (abfd)
03469 bfd *abfd;
03470 {
03471 asymbol **q;
03472 ieee_data_type *ieee = IEEE_DATA (abfd);
03473 unsigned int reference_index = IEEE_REFERENCE_BASE;
03474 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
03475 file_ptr here = bfd_tell (abfd);
03476 bfd_boolean hadone = FALSE;
03477
03478 if (abfd->outsymbols != (asymbol **) NULL)
03479 {
03480
03481 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
03482 {
03483 asymbol *p = *q;
03484
03485 if (bfd_is_und_section (p->section))
03486 {
03487
03488 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
03489 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
03490 || ! ieee_write_id (abfd, p->name))
03491 return FALSE;
03492 p->value = reference_index;
03493 reference_index++;
03494 hadone = TRUE;
03495 }
03496 else if (bfd_is_com_section (p->section))
03497 {
03498
03499 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
03500 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
03501 || ! ieee_write_id (abfd, p->name)
03502 || ! ieee_write_byte (abfd,
03503 ieee_weak_external_reference_enum)
03504 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
03505 || ! ieee_write_int (abfd, p->value))
03506 return FALSE;
03507 p->value = reference_index;
03508 reference_index++;
03509 hadone = TRUE;
03510 }
03511 else if (p->flags & BSF_GLOBAL)
03512 {
03513
03514 if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
03515 || ! ieee_write_int (abfd, (bfd_vma) public_index)
03516 || ! ieee_write_id (abfd, p->name)
03517 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
03518 || ! ieee_write_int (abfd, (bfd_vma) public_index)
03519 || ! ieee_write_byte (abfd, 15)
03520 || ! ieee_write_byte (abfd, 19)
03521 || ! ieee_write_byte (abfd, 1))
03522 return FALSE;
03523
03524
03525 if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
03526 || ! ieee_write_int (abfd, (bfd_vma) public_index))
03527 return FALSE;
03528 if (! bfd_is_abs_section (p->section))
03529 {
03530 if (abfd->flags & EXEC_P)
03531 {
03532
03533
03534 if (! (ieee_write_int
03535 (abfd,
03536 (p->value
03537 + p->section->output_offset
03538 + p->section->output_section->vma))))
03539 return FALSE;
03540 }
03541 else
03542 {
03543 if (! (ieee_write_expression
03544 (abfd,
03545 p->value + p->section->output_offset,
03546 p->section->output_section->symbol,
03547 FALSE, 0)))
03548 return FALSE;
03549 }
03550 }
03551 else
03552 {
03553 if (! ieee_write_expression (abfd,
03554 p->value,
03555 bfd_abs_section_ptr->symbol,
03556 FALSE, 0))
03557 return FALSE;
03558 }
03559 p->value = public_index;
03560 public_index++;
03561 hadone = TRUE;
03562 }
03563 else
03564 {
03565
03566
03567 }
03568 }
03569 }
03570 if (hadone)
03571 ieee->w.r.external_part = here;
03572
03573 return TRUE;
03574 }
03575
03576
03577 static const unsigned char exten[] =
03578 {
03579 0xf0, 0x20, 0x00,
03580 0xf1, 0xce, 0x20, 0x00, 37, 3, 3,
03581 0xf1, 0xce, 0x20, 0x00, 39, 2,
03582 0xf1, 0xce, 0x20, 0x00, 38
03583 };
03584
03585 static const unsigned char envi[] =
03586 {
03587 0xf0, 0x21, 0x00,
03588
03589
03590
03591
03592 0xf1, 0xce, 0x21, 00, 52, 0x00,
03593
03594 0xf1, 0xce, 0x21, 0, 53, 0x03,
03595
03596 };
03597
03598 static bfd_boolean
03599 ieee_write_me_part (abfd)
03600 bfd *abfd;
03601 {
03602 ieee_data_type *ieee = IEEE_DATA (abfd);
03603 ieee->w.r.trailer_part = bfd_tell (abfd);
03604 if (abfd->start_address)
03605 {
03606 if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
03607 || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
03608 || ! ieee_write_int (abfd, abfd->start_address)
03609 || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
03610 return FALSE;
03611 }
03612 ieee->w.r.me_record = bfd_tell (abfd);
03613 if (! ieee_write_byte (abfd, ieee_module_end_enum))
03614 return FALSE;
03615 return TRUE;
03616 }
03617
03618
03619
03620 static bfd_boolean
03621 ieee_write_processor (abfd)
03622 bfd *abfd;
03623 {
03624 const bfd_arch_info_type *arch;
03625
03626 arch = bfd_get_arch_info (abfd);
03627 switch (arch->arch)
03628 {
03629 default:
03630 if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
03631 return FALSE;
03632 break;
03633
03634 case bfd_arch_a29k:
03635 if (! ieee_write_id (abfd, "29000"))
03636 return FALSE;
03637 break;
03638
03639 case bfd_arch_h8300:
03640 if (! ieee_write_id (abfd, "H8/300"))
03641 return FALSE;
03642 break;
03643
03644 case bfd_arch_h8500:
03645 if (! ieee_write_id (abfd, "H8/500"))
03646 return FALSE;
03647 break;
03648
03649 case bfd_arch_i960:
03650 switch (arch->mach)
03651 {
03652 default:
03653 case bfd_mach_i960_core:
03654 case bfd_mach_i960_ka_sa:
03655 if (! ieee_write_id (abfd, "80960KA"))
03656 return FALSE;
03657 break;
03658
03659 case bfd_mach_i960_kb_sb:
03660 if (! ieee_write_id (abfd, "80960KB"))
03661 return FALSE;
03662 break;
03663
03664 case bfd_mach_i960_ca:
03665 if (! ieee_write_id (abfd, "80960CA"))
03666 return FALSE;
03667 break;
03668
03669 case bfd_mach_i960_mc:
03670 case bfd_mach_i960_xa:
03671 if (! ieee_write_id (abfd, "80960MC"))
03672 return FALSE;
03673 break;
03674 }
03675 break;
03676
03677 case bfd_arch_m68k:
03678 {
03679 const char *id;
03680
03681 switch (arch->mach)
03682 {
03683 default: id = "68020"; break;
03684 case bfd_mach_m68000: id = "68000"; break;
03685 case bfd_mach_m68008: id = "68008"; break;
03686 case bfd_mach_m68010: id = "68010"; break;
03687 case bfd_mach_m68020: id = "68020"; break;
03688 case bfd_mach_m68030: id = "68030"; break;
03689 case bfd_mach_m68040: id = "68040"; break;
03690 case bfd_mach_m68060: id = "68060"; break;
03691 case bfd_mach_cpu32: id = "cpu32"; break;
03692 case bfd_mach_mcf5200:id = "5200"; break;
03693 case bfd_mach_mcf5206e:id = "5206e"; break;
03694 case bfd_mach_mcf5307:id = "5307"; break;
03695 case bfd_mach_mcf5407:id = "5407"; break;
03696 case bfd_mach_mcf528x:id = "5282"; break;
03697 }
03698
03699 if (! ieee_write_id (abfd, id))
03700 return FALSE;
03701 }
03702 break;
03703 }
03704
03705 return TRUE;
03706 }
03707
03708 static bfd_boolean
03709 ieee_write_object_contents (abfd)
03710 bfd *abfd;
03711 {
03712 ieee_data_type *ieee = IEEE_DATA (abfd);
03713 unsigned int i;
03714 file_ptr old;
03715
03716
03717 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
03718 return FALSE;
03719
03720 if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
03721 || ! ieee_write_processor (abfd)
03722 || ! ieee_write_id (abfd, abfd->filename))
03723 return FALSE;
03724
03725
03726 if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
03727 return FALSE;
03728
03729
03730 if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
03731 return FALSE;
03732
03733 if (! ieee_write_byte (abfd,
03734 (bfd_byte) (bfd_arch_bits_per_address (abfd)
03735 / bfd_arch_bits_per_byte (abfd))))
03736 return FALSE;
03737
03738 old = bfd_tell (abfd);
03739 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
03740 return FALSE;
03741
03742 ieee->w.r.extension_record = bfd_tell (abfd);
03743 if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
03744 != sizeof (exten))
03745 return FALSE;
03746 if (abfd->flags & EXEC_P)
03747 {
03748 if (! ieee_write_byte (abfd, 0x1))
03749 return FALSE;
03750 }
03751 else
03752 {
03753 if (! ieee_write_byte (abfd, 0x2))
03754 return FALSE;
03755 }
03756
03757 ieee->w.r.environmental_record = bfd_tell (abfd);
03758 if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
03759 != sizeof (envi))
03760 return FALSE;
03761
03762
03763 {
03764 time_t now;
03765 const struct tm *t;
03766
03767 time (&now);
03768 t = (struct tm *) localtime (&now);
03769 if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
03770 || ! ieee_write_byte (abfd, 0x21)
03771 || ! ieee_write_byte (abfd, 0)
03772 || ! ieee_write_byte (abfd, 50)
03773 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
03774 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
03775 || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
03776 || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
03777 || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
03778 || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
03779 return FALSE;
03780 }
03781
03782 output_bfd = abfd;
03783
03784 flush ();
03785
03786 if (! ieee_write_section_part (abfd))
03787 return FALSE;
03788
03789
03790 if (! ieee_write_external_part (abfd))
03791 return FALSE;
03792
03793
03794 if (! ieee_write_debug_part (abfd))
03795 return FALSE;
03796
03797
03798
03799
03800 if (! ieee_write_data_part (abfd))
03801 return FALSE;
03802
03803
03804 if (! ieee_write_me_part (abfd))
03805 return FALSE;
03806
03807
03808 if (bfd_seek (abfd, old, SEEK_SET) != 0)
03809 return FALSE;
03810
03811 for (i = 0; i < N_W_VARIABLES; i++)
03812 {
03813 if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
03814 || ! ieee_write_byte (abfd, (bfd_byte) i)
03815 || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
03816 return FALSE;
03817 }
03818
03819 return TRUE;
03820 }
03821
03822
03823
03824
03825
03826
03827
03828 static asymbol *
03829 ieee_make_empty_symbol (abfd)
03830 bfd *abfd;
03831 {
03832 bfd_size_type amt = sizeof (ieee_symbol_type);
03833 ieee_symbol_type *new = (ieee_symbol_type *) bfd_zalloc (abfd, amt);
03834
03835 if (!new)
03836 return NULL;
03837 new->symbol.the_bfd = abfd;
03838 return &new->symbol;
03839 }
03840
03841 static bfd *
03842 ieee_openr_next_archived_file (arch, prev)
03843 bfd *arch;
03844 bfd *prev;
03845 {
03846 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
03847
03848
03849 if (prev == (bfd *) NULL)
03850
03851 ar->element_index = 2;
03852
03853 while (TRUE)
03854 {
03855 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
03856
03857 ar->element_index++;
03858 if (ar->element_index <= ar->element_count)
03859 {
03860 if (p->file_offset != (file_ptr) 0)
03861 {
03862 if (p->abfd == (bfd *) NULL)
03863 {
03864 p->abfd = _bfd_create_empty_archive_element_shell (arch);
03865 p->abfd->origin = p->file_offset;
03866 }
03867 return p->abfd;
03868 }
03869 }
03870 else
03871 {
03872 bfd_set_error (bfd_error_no_more_archived_files);
03873 return (bfd *) NULL;
03874 }
03875 }
03876 }
03877
03878 static bfd_boolean
03879 ieee_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
03880 functionname_ptr, line_ptr)
03881 bfd *abfd ATTRIBUTE_UNUSED;
03882 asection *section ATTRIBUTE_UNUSED;
03883 asymbol **symbols ATTRIBUTE_UNUSED;
03884 bfd_vma offset ATTRIBUTE_UNUSED;
03885 const char **filename_ptr ATTRIBUTE_UNUSED;
03886 const char **functionname_ptr ATTRIBUTE_UNUSED;
03887 unsigned int *line_ptr ATTRIBUTE_UNUSED;
03888 {
03889 return FALSE;
03890 }
03891
03892 static int
03893 ieee_generic_stat_arch_elt (abfd, buf)
03894 bfd *abfd;
03895 struct stat *buf;
03896 {
03897 ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
03898 ieee_data_type *ieee;
03899
03900 if (abfd->my_archive != NULL)
03901 ar = abfd->my_archive->tdata.ieee_ar_data;
03902 if (ar == (ieee_ar_data_type *) NULL)
03903 {
03904 bfd_set_error (bfd_error_invalid_operation);
03905 return -1;
03906 }
03907
03908 if (IEEE_DATA (abfd) == NULL)
03909 {
03910 if (ieee_object_p (abfd) == NULL)
03911 {
03912 bfd_set_error (bfd_error_wrong_format);
03913 return -1;
03914 }
03915 }
03916
03917 ieee = IEEE_DATA (abfd);
03918
03919 buf->st_size = ieee->w.r.me_record + 1;
03920 buf->st_mode = 0644;
03921 return 0;
03922 }
03923
03924 static int
03925 ieee_sizeof_headers (abfd, x)
03926 bfd *abfd ATTRIBUTE_UNUSED;
03927 bfd_boolean x ATTRIBUTE_UNUSED;
03928 {
03929 return 0;
03930 }
03931
03932 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
03933 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
03934
03935 #define ieee_slurp_armap bfd_true
03936 #define ieee_slurp_extended_name_table bfd_true
03937 #define ieee_construct_extended_name_table \
03938 ((bfd_boolean (*) \
03939 PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
03940 bfd_true)
03941 #define ieee_truncate_arname bfd_dont_truncate_arname
03942 #define ieee_write_armap \
03943 ((bfd_boolean (*) \
03944 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
03945 bfd_true)
03946 #define ieee_read_ar_hdr bfd_nullvoidptr
03947 #define ieee_update_armap_timestamp bfd_true
03948 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
03949
03950 #define ieee_bfd_is_target_special_symbol \
03951 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
03952 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
03953 #define ieee_get_lineno _bfd_nosymbols_get_lineno
03954 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
03955 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
03956 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
03957
03958 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
03959
03960 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
03961
03962 #define ieee_get_section_contents_in_window \
03963 _bfd_generic_get_section_contents_in_window
03964 #define ieee_bfd_get_relocated_section_contents \
03965 bfd_generic_get_relocated_section_contents
03966 #define ieee_bfd_relax_section bfd_generic_relax_section
03967 #define ieee_bfd_gc_sections bfd_generic_gc_sections
03968 #define ieee_bfd_merge_sections bfd_generic_merge_sections
03969 #define ieee_bfd_is_group_section bfd_generic_is_group_section
03970 #define ieee_bfd_discard_group bfd_generic_discard_group
03971 #define ieee_section_already_linked \
03972 _bfd_generic_section_already_linked
03973 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
03974 #define ieee_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
03975 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
03976 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
03977 #define ieee_bfd_final_link _bfd_generic_final_link
03978 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
03979
03980 const bfd_target ieee_vec =
03981 {
03982 "ieee",
03983 bfd_target_ieee_flavour,
03984 BFD_ENDIAN_UNKNOWN,
03985 BFD_ENDIAN_UNKNOWN,
03986 (HAS_RELOC | EXEC_P |
03987 HAS_LINENO | HAS_DEBUG |
03988 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
03989 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
03990 | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
03991 '_',
03992 ' ',
03993 16,
03994 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
03995 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
03996 bfd_getb16, bfd_getb_signed_16, bfd_putb16,
03997 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
03998 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
03999 bfd_getb16, bfd_getb_signed_16, bfd_putb16,
04000
04001 {_bfd_dummy_target,
04002 ieee_object_p,
04003 ieee_archive_p,
04004 _bfd_dummy_target,
04005 },
04006 {
04007 bfd_false,
04008 ieee_mkobject,
04009 _bfd_generic_mkarchive,
04010 bfd_false
04011 },
04012 {
04013 bfd_false,
04014 ieee_write_object_contents,
04015 _bfd_write_archive_contents,
04016 bfd_false,
04017 },
04018
04019
04020
04021 BFD_JUMP_TABLE_GENERIC (ieee),
04022
04023 BFD_JUMP_TABLE_COPY (_bfd_generic),
04024 BFD_JUMP_TABLE_CORE (_bfd_nocore),
04025
04026
04027
04028
04029
04030
04031 BFD_JUMP_TABLE_ARCHIVE (ieee),
04032
04033
04034
04035
04036
04037
04038 BFD_JUMP_TABLE_SYMBOLS (ieee),
04039
04040
04041
04042 BFD_JUMP_TABLE_RELOCS (ieee),
04043
04044
04045 BFD_JUMP_TABLE_WRITE (ieee),
04046
04047
04048
04049
04050
04051
04052
04053 BFD_JUMP_TABLE_LINK (ieee),
04054
04055 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
04056
04057 NULL,
04058
04059 (PTR) 0
04060 };