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