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