OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [bfd/] [aout-tic30.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* BFD back-end for TMS320C30 a.out binaries.
2
   Copyright 1998, 1999, 2000 Free Software Foundation, Inc.
3
   Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
4
 
5
   This file is part of BFD, the Binary File Descriptor library.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20
   02111-1307, USA.  */
21
 
22
#define TARGET_IS_BIG_ENDIAN_P
23
#define N_HEADER_IN_TEXT(x) 1
24
#define BYTES_IN_WORD 4
25
#define TEXT_START_ADDR 1024
26
#define TARGET_PAGE_SIZE 128
27
#define SEGMENT_SIZE TARGET_PAGE_SIZE
28
#define DEFAULT_ARCH bfd_arch_tic30
29
#define ARCH_SIZE 32
30
 
31
#define MY(OP) CAT(tic30_aout_,OP)
32
#define TARGETNAME "a.out-tic30"
33
#define NAME(x,y) CAT3(tic30_aout,_32_,y)
34
 
35
#include "bfd.h"
36
#include "sysdep.h"
37
#include "libaout.h"
38
 
39
#include "aout/aout64.h"
40
#include "aout/stab_gnu.h"
41
#include "aout/ar.h"
42
 
43
static bfd_reloc_status_type tic30_aout_fix_16
44
  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
45
static bfd_reloc_status_type tic30_aout_fix_32
46
  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
47
static bfd_reloc_status_type tic30_aout_fix_pcrel_16
48
  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
49
static reloc_howto_type *tic30_aout_reloc_howto
50
  PARAMS ((bfd *, struct reloc_std_external *, int *, int *, int *));
51
static bfd_reloc_status_type tic30_aout_relocate_contents
52
  PARAMS ((reloc_howto_type *, bfd *, bfd_vma, bfd_byte *));
53
static bfd_reloc_status_type tic30_aout_final_link_relocate
54
  PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, bfd_vma,
55
           bfd_vma, bfd_vma));
56
static const bfd_target *tic30_aout_object_p PARAMS ((bfd *));
57
static boolean tic30_aout_write_object_contents PARAMS ((bfd *));
58
static boolean tic30_aout_set_sizes PARAMS ((bfd *));
59
 
60
#define MY_reloc_howto(BFD,REL,IN,EX,PC) tic30_aout_reloc_howto(BFD,REL,&IN,&EX,&PC)
61
#define MY_final_link_relocate tic30_aout_final_link_relocate
62
#define MY_object_p tic30_aout_object_p
63
#define MY_mkobject NAME(aout,mkobject)
64
#define MY_write_object_contents tic30_aout_write_object_contents
65
#define MY_set_sizes tic30_aout_set_sizes
66
 
67
#ifndef MY_exec_hdr_flags
68
#define MY_exec_hdr_flags 1
69
#endif
70
 
71
#ifndef MY_backend_data
72
 
73
#ifndef MY_zmagic_contiguous
74
#define MY_zmagic_contiguous 0
75
#endif
76
#ifndef MY_text_includes_header
77
#define MY_text_includes_header 0
78
#endif
79
#ifndef MY_entry_is_text_address
80
#define MY_entry_is_text_address 0
81
#endif
82
#ifndef MY_exec_header_not_counted
83
#define MY_exec_header_not_counted 1
84
#endif
85
#ifndef MY_add_dynamic_symbols
86
#define MY_add_dynamic_symbols 0
87
#endif
88
#ifndef MY_add_one_symbol
89
#define MY_add_one_symbol 0
90
#endif
91
#ifndef MY_link_dynamic_object
92
#define MY_link_dynamic_object 0
93
#endif
94
#ifndef MY_write_dynamic_symbol
95
#define MY_write_dynamic_symbol 0
96
#endif
97
#ifndef MY_check_dynamic_reloc
98
#define MY_check_dynamic_reloc 0
99
#endif
100
#ifndef MY_finish_dynamic_link
101
#define MY_finish_dynamic_link 0
102
#endif
103
 
104
static CONST struct aout_backend_data tic30_aout_backend_data =
105
{
106
  MY_zmagic_contiguous,
107
  MY_text_includes_header,
108
  MY_entry_is_text_address,
109
  MY_exec_hdr_flags,
110
  0,                             /* text vma? */
111
  MY_set_sizes,
112
  MY_exec_header_not_counted,
113
  MY_add_dynamic_symbols,
114
  MY_add_one_symbol,
115
  MY_link_dynamic_object,
116
  MY_write_dynamic_symbol,
117
  MY_check_dynamic_reloc,
118
  MY_finish_dynamic_link
119
};
120
#define MY_backend_data &tic30_aout_backend_data
121
#endif
122
 
123
/* FIXME: This is wrong.  aoutx.h should really only be included by
124
   aout32.c.  */
125
 
126
#include "aoutx.h"
127
 
128
/* This table lists the relocation types for the TMS320C30.  There are
129
   only a few relocations required, and all must be divided by 4 (>>
130
   2) to get the 32-bit addresses in the format the TMS320C30 likes
131
   it.  */
132
reloc_howto_type tic30_aout_howto_table[] =
133
{
134
  EMPTY_HOWTO (-1),
135
  HOWTO (1, 2, 1, 16, false, 0, 0, tic30_aout_fix_16,
136
         "16", false, 0x0000FFFF, 0x0000FFFF, false),
137
  HOWTO (2, 2, 2, 24, false, 0, complain_overflow_bitfield, NULL,
138
         "24", false, 0x00FFFFFF, 0x00FFFFFF, false),
139
  HOWTO (3, 18, 3, 24, false, 0, complain_overflow_bitfield, NULL,
140
         "LDP", false, 0x00FF0000, 0x000000FF, false),
141
  HOWTO (4, 2, 4, 32, false, 0, complain_overflow_bitfield, tic30_aout_fix_32,
142
         "32", false, 0xFFFFFFFF, 0xFFFFFFFF, false),
143
  HOWTO (5, 2, 1, 16, true, 0, complain_overflow_signed,
144
         tic30_aout_fix_pcrel_16, "PCREL", true, 0x0000FFFF, 0x0000FFFF, true),
145
  EMPTY_HOWTO (-1),
146
  EMPTY_HOWTO (-1),
147
  EMPTY_HOWTO (-1),
148
  EMPTY_HOWTO (-1),
149
  EMPTY_HOWTO (-1)
150
};
151
 
152
extern reloc_howto_type *NAME (aout, reloc_type_lookup) ();
153
 
154
reloc_howto_type *
155
tic30_aout_reloc_type_lookup (abfd, code)
156
     bfd *abfd ATTRIBUTE_UNUSED;
157
     bfd_reloc_code_real_type code;
158
{
159
  switch (code)
160
    {
161
    case BFD_RELOC_8:
162
    case BFD_RELOC_TIC30_LDP:
163
      return &tic30_aout_howto_table[3];
164
    case BFD_RELOC_16:
165
      return &tic30_aout_howto_table[1];
166
    case BFD_RELOC_24:
167
      return &tic30_aout_howto_table[2];
168
    case BFD_RELOC_16_PCREL:
169
      return &tic30_aout_howto_table[5];
170
    case BFD_RELOC_32:
171
      return &tic30_aout_howto_table[4];
172
    default:
173
      return (reloc_howto_type *) NULL;
174
    }
175
}
176
 
177
static reloc_howto_type *
178
tic30_aout_reloc_howto (abfd, relocs, r_index, r_extern, r_pcrel)
179
     bfd *abfd;
180
     struct reloc_std_external *relocs;
181
     int *r_index;
182
     int *r_extern;
183
     int *r_pcrel;
184
{
185
  unsigned int r_length;
186
  unsigned int r_pcrel_done;
187
  int index;
188
 
189
  *r_pcrel = 0;
190
  if (bfd_header_big_endian (abfd))
191
    {
192
      *r_index = ((relocs->r_index[0] << 16) | (relocs->r_index[1] << 8) | relocs->r_index[2]);
193
      *r_extern = (0 != (relocs->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
194
      r_pcrel_done = (0 != (relocs->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
195
      r_length = ((relocs->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) >> RELOC_STD_BITS_LENGTH_SH_BIG);
196
    }
197
  else
198
    {
199
      *r_index = ((relocs->r_index[2] << 16) | (relocs->r_index[1] << 8) | relocs->r_index[0]);
200
      *r_extern = (0 != (relocs->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
201
      r_pcrel_done = (0 != (relocs->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
202
      r_length = ((relocs->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
203
    }
204
  index = r_length + 4 * r_pcrel_done;
205
  return tic30_aout_howto_table + index;
206
}
207
 
208
/* This function is used as a callback for 16-bit relocs.  This is
209
   required for relocations between segments.  A line in aoutx.h
210
   requires that any relocations for the data section should point to
211
   the end of the aligned text section, plus an offset.  By default,
212
   this does not happen, therefore this function takes care of
213
   that.  */
214
 
215
static bfd_reloc_status_type
216
tic30_aout_fix_16 (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message)
217
     bfd *abfd;
218
     arelent *reloc_entry;
219
     asymbol *symbol;
220
     PTR data;
221
     asection *input_section ATTRIBUTE_UNUSED;
222
     bfd *output_bfd;
223
     char **error_message ATTRIBUTE_UNUSED;
224
{
225
  bfd_vma relocation;
226
 
227
  /* Make sure that the symbol's section is defined.  */
228
  if (symbol->section == &bfd_und_section && (symbol->flags & BSF_WEAK) == 0)
229
    return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;
230
  /* Get the size of the input section and turn it into the TMS320C30
231
     32-bit address format.  */
232
  relocation = (symbol->section->vma >> 2);
233
  relocation += bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
234
  bfd_put_16 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
235
  return bfd_reloc_ok;
236
}
237
 
238
/* This function does the same thing as tic30_aout_fix_16 except for 32
239
   bit relocations.  */
240
 
241
static bfd_reloc_status_type
242
tic30_aout_fix_32 (abfd, reloc_entry, symbol, data, input_section,
243
                   output_bfd, error_message)
244
     bfd *abfd;
245
     arelent *reloc_entry;
246
     asymbol *symbol;
247
     PTR data;
248
     asection *input_section ATTRIBUTE_UNUSED;
249
     bfd *output_bfd;
250
     char **error_message ATTRIBUTE_UNUSED;
251
{
252
  bfd_vma relocation;
253
 
254
  /* Make sure that the symbol's section is defined.  */
255
  if (symbol->section == &bfd_und_section && (symbol->flags & BSF_WEAK) == 0)
256
    return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;
257
  /* Get the size of the input section and turn it into the TMS320C30
258
     32-bit address format.  */
259
  relocation = (symbol->section->vma >> 2);
260
  relocation += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
261
  bfd_put_32 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
262
  return bfd_reloc_ok;
263
}
264
 
265
/* This function is used to work out pc-relative offsets for the
266
   TMS320C30.  The data already placed by md_pcrel_from within gas is
267
   useless for a relocation, so we just get the offset value and place
268
   a version of this within the object code.
269
   tic30_aout_final_link_relocate will then calculate the required
270
   relocation to add on to the value in the object code.  */
271
 
272
static bfd_reloc_status_type
273
tic30_aout_fix_pcrel_16 (abfd, reloc_entry, symbol, data, input_section,
274
                         output_bfd, error_message)
275
     bfd *abfd;
276
     arelent *reloc_entry;
277
     asymbol *symbol ATTRIBUTE_UNUSED;
278
     PTR data;
279
     asection *input_section ATTRIBUTE_UNUSED;
280
     bfd *output_bfd ATTRIBUTE_UNUSED;
281
     char **error_message ATTRIBUTE_UNUSED;
282
{
283
  bfd_vma relocation = 1;
284
  bfd_byte offset_data = bfd_get_8 (abfd, (bfd_byte *) data + reloc_entry->address - 1);
285
 
286
  /* The byte before the location of the fix contains bits 23-16 of
287
     the pcrel instruction.  Bit 21 is set for a delayed instruction
288
     which requires on offset of 3 instead of 1.  */
289
  if (offset_data & 0x20)
290
    relocation -= 3;
291
  else
292
    relocation -= 1;
293
  bfd_put_16 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
294
  return bfd_reloc_ok;
295
}
296
 
297
/* These macros will get 24-bit values from the bfd definition.
298
   Big-endian only.  */
299
#define bfd_getb_24(BFD,ADDR)                   \
300
 (bfd_get_8 (BFD, ADDR    ) << 16) |            \
301
 (bfd_get_8 (BFD, ADDR + 1) <<  8) |            \
302
 (bfd_get_8 (BFD, ADDR + 2)      )
303
 
304
#define bfd_putb_24(BFD,DATA,ADDR)                              \
305
 bfd_put_8 (BFD, (bfd_byte) ((DATA >> 16) & 0xFF), ADDR    );   \
306
 bfd_put_8 (BFD, (bfd_byte) ((DATA >>  8) & 0xFF), ADDR + 1);   \
307
 bfd_put_8 (BFD, (bfd_byte) ( DATA        & 0xFF), ADDR + 2)
308
 
309
/* Set parameters about this a.out file that are machine-dependent.
310
   This routine is called from some_aout_object_p just before it returns.  */
311
 
312
static const bfd_target *
313
tic30_aout_callback (abfd)
314
     bfd *abfd;
315
{
316
  struct internal_exec *execp = exec_hdr (abfd);
317
  unsigned int arch_align_power;
318
  unsigned long arch_align;
319
 
320
  /* Calculate the file positions of the parts of a newly read aout header */
321
  obj_textsec (abfd)->_raw_size = N_TXTSIZE (*execp);
322
 
323
  /* The virtual memory addresses of the sections */
324
  obj_textsec (abfd)->vma = N_TXTADDR (*execp);
325
  obj_datasec (abfd)->vma = N_DATADDR (*execp);
326
  obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
327
 
328
  obj_textsec (abfd)->lma = obj_textsec (abfd)->vma;
329
  obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;
330
  obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;
331
 
332
  /* The file offsets of the sections */
333
  obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
334
  obj_datasec (abfd)->filepos = N_DATOFF (*execp);
335
 
336
  /* The file offsets of the relocation info */
337
  obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
338
  obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
339
 
340
  /* The file offsets of the string table and symbol table.  */
341
  obj_sym_filepos (abfd) = N_SYMOFF (*execp);
342
  obj_str_filepos (abfd) = N_STROFF (*execp);
343
 
344
  /* Determine the architecture and machine type of the object file.  */
345
#ifdef SET_ARCH_MACH
346
  SET_ARCH_MACH (abfd, *execp);
347
#else
348
  bfd_default_set_arch_mach (abfd, DEFAULT_ARCH, 0);
349
#endif
350
 
351
  /* Now that we know the architecture, set the alignments of the
352
     sections.  This is normally done by NAME(aout,new_section_hook),
353
     but when the initial sections were created the architecture had
354
     not yet been set.  However, for backward compatibility, we don't
355
     set the alignment power any higher than as required by the size
356
     of the section.  */
357
  arch_align_power = bfd_get_arch_info (abfd)->section_align_power;
358
  arch_align = 1 << arch_align_power;
359
  if ((BFD_ALIGN (obj_textsec (abfd)->_raw_size, arch_align)
360
       == obj_textsec (abfd)->_raw_size)
361
      && (BFD_ALIGN (obj_datasec (abfd)->_raw_size, arch_align)
362
          == obj_datasec (abfd)->_raw_size)
363
      && (BFD_ALIGN (obj_bsssec (abfd)->_raw_size, arch_align)
364
          == obj_bsssec (abfd)->_raw_size))
365
    {
366
      obj_textsec (abfd)->alignment_power = arch_align_power;
367
      obj_datasec (abfd)->alignment_power = arch_align_power;
368
      obj_bsssec (abfd)->alignment_power = arch_align_power;
369
    }
370
  return abfd->xvec;
371
}
372
 
373
static bfd_reloc_status_type
374
tic30_aout_final_link_relocate (howto, input_bfd, input_section, contents,
375
                                address, value, addend)
376
     reloc_howto_type *howto;
377
     bfd *input_bfd;
378
     asection *input_section;
379
     bfd_byte *contents;
380
     bfd_vma address;
381
     bfd_vma value;
382
     bfd_vma addend;
383
{
384
  bfd_vma relocation;
385
 
386
  if (address > input_section->_raw_size)
387
    return bfd_reloc_outofrange;
388
 
389
  relocation = value + addend;
390
  if (howto->pc_relative)
391
    {
392
      relocation -= (input_section->output_section->vma + input_section->output_offset);
393
      if (howto->pcrel_offset)
394
        relocation -= address;
395
    }
396
  return tic30_aout_relocate_contents (howto, input_bfd, relocation,
397
                                       contents + address);
398
}
399
 
400
bfd_reloc_status_type
401
tic30_aout_relocate_contents (howto, input_bfd, relocation, location)
402
     reloc_howto_type *howto;
403
     bfd *input_bfd;
404
     bfd_vma relocation;
405
     bfd_byte *location;
406
{
407
  bfd_vma x;
408
  boolean overflow;
409
 
410
  if (howto->size < 0)
411
    relocation = -relocation;
412
 
413
  switch (howto->size)
414
    {
415
    default:
416
    case 0:
417
      abort ();
418
      break;
419
    case 1:
420
      x = bfd_get_16 (input_bfd, location);
421
      break;
422
    case 2:
423
      x = bfd_getb_24 (input_bfd, location);
424
      break;
425
    case 3:
426
      x = bfd_get_8 (input_bfd, location);
427
      break;
428
    case 4:
429
      x = bfd_get_32 (input_bfd, location);
430
      break;
431
    }
432
  overflow = false;
433
  if (howto->complain_on_overflow != complain_overflow_dont)
434
    {
435
      bfd_vma check;
436
      bfd_signed_vma signed_check;
437
      bfd_vma add;
438
      bfd_signed_vma signed_add;
439
 
440
      if (howto->rightshift == 0)
441
        {
442
          check = relocation;
443
          signed_check = (bfd_signed_vma) relocation;
444
        }
445
      else
446
        {
447
          check = relocation >> howto->rightshift;
448
          if ((bfd_signed_vma) relocation >= 0)
449
            signed_check = check;
450
          else
451
            signed_check = (check | ((bfd_vma) - 1 & ~((bfd_vma) - 1 >> howto->rightshift)));
452
        }
453
      add = x & howto->src_mask;
454
      signed_add = add;
455
      if ((add & (((~howto->src_mask) >> 1) & howto->src_mask)) != 0)
456
        signed_add -= (((~howto->src_mask) >> 1) & howto->src_mask) << 1;
457
      if (howto->bitpos == 0)
458
        {
459
          check += add;
460
          signed_check += signed_add;
461
        }
462
      else
463
        {
464
          check += add >> howto->bitpos;
465
          if (signed_add >= 0)
466
            signed_check += add >> howto->bitpos;
467
          else
468
            signed_check += ((add >> howto->bitpos) | ((bfd_vma) - 1 & ~((bfd_vma) - 1 >> howto->bitpos)));
469
        }
470
      switch (howto->complain_on_overflow)
471
        {
472
        case complain_overflow_signed:
473
          {
474
            bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
475
            bfd_signed_vma reloc_signed_min = ~reloc_signed_max;
476
            if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
477
              overflow = true;
478
          }
479
          break;
480
        case complain_overflow_unsigned:
481
          {
482
            bfd_vma reloc_unsigned_max = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;
483
            if (check > reloc_unsigned_max)
484
              overflow = true;
485
          }
486
          break;
487
        case complain_overflow_bitfield:
488
          {
489
            bfd_vma reloc_bits = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;
490
            if ((check & ~reloc_bits) != 0 && (((bfd_vma) signed_check & ~reloc_bits) != (-1 & ~reloc_bits)))
491
              overflow = true;
492
          }
493
          break;
494
        default:
495
          abort ();
496
        }
497
    }
498
  relocation >>= (bfd_vma) howto->rightshift;
499
  relocation <<= (bfd_vma) howto->bitpos;
500
  x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask));
501
  switch (howto->size)
502
    {
503
    default:
504
    case 0:
505
      abort ();
506
      break;
507
    case 1:
508
      bfd_put_16 (input_bfd, x, location);
509
      break;
510
    case 2:
511
      bfd_putb_24 (input_bfd, x, location);
512
      break;
513
    case 3:
514
      bfd_put_8 (input_bfd, x, location);
515
      break;
516
    case 4:
517
      bfd_put_32 (input_bfd, x, location);
518
      break;
519
    }
520
  return overflow ? bfd_reloc_overflow : bfd_reloc_ok;
521
}
522
 
523
/* Finish up the reading of an a.out file header */
524
 
525
static const bfd_target *
526
tic30_aout_object_p (abfd)
527
     bfd *abfd;
528
{
529
  struct external_exec exec_bytes;      /* Raw exec header from file */
530
  struct internal_exec exec;    /* Cleaned-up exec header */
531
  const bfd_target *target;
532
 
533
  if (bfd_read ((PTR) & exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
534
      != EXEC_BYTES_SIZE)
535
    {
536
      if (bfd_get_error () != bfd_error_system_call)
537
        bfd_set_error (bfd_error_wrong_format);
538
      return 0;
539
    }
540
 
541
#ifdef SWAP_MAGIC
542
  exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
543
#else
544
  exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
545
#endif /* SWAP_MAGIC */
546
 
547
  if (N_BADMAG (exec))
548
    return 0;
549
#ifdef MACHTYPE_OK
550
  if (!(MACHTYPE_OK (N_MACHTYPE (exec))))
551
    return 0;
552
#endif
553
 
554
  NAME (aout, swap_exec_header_in) (abfd, &exec_bytes, &exec);
555
 
556
#ifdef SWAP_MAGIC
557
  /* swap_exec_header_in read in a_info with the wrong byte order */
558
  exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
559
#endif /* SWAP_MAGIC */
560
 
561
  target = NAME (aout, some_aout_object_p) (abfd, &exec, tic30_aout_callback);
562
 
563
#ifdef ENTRY_CAN_BE_ZERO
564
  /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
565
   * means that it isn't obvious if EXEC_P should be set.
566
   * All of the following must be true for an executable:
567
   * There must be no relocations, the bfd can be neither an
568
   * archive nor an archive element, and the file must be executable.  */
569
 
570
  if (exec.a_trsize + exec.a_drsize == 0
571
      && bfd_get_format (abfd) == bfd_object && abfd->my_archive == NULL)
572
    {
573
      struct stat buf;
574
#ifndef S_IXUSR
575
#define S_IXUSR 0100            /* Execute by owner.  */
576
#endif
577
      if (stat (abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
578
        abfd->flags |= EXEC_P;
579
    }
580
#endif /* ENTRY_CAN_BE_ZERO */
581
 
582
  return target;
583
}
584
 
585
/* Copy private section data.  This actually does nothing with the
586
   sections.  It copies the subformat field.  We copy it here, because
587
   we need to know whether this is a QMAGIC file before we set the
588
   section contents, and copy_private_bfd_data is not called until
589
   after the section contents have been set.  */
590
 
591
static boolean
592
MY_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
593
     bfd *ibfd;
594
     asection *isec ATTRIBUTE_UNUSED;
595
     bfd *obfd;
596
     asection *osec ATTRIBUTE_UNUSED;
597
{
598
  if (bfd_get_flavour (obfd) == bfd_target_aout_flavour)
599
    obj_aout_subformat (obfd) = obj_aout_subformat (ibfd);
600
  return true;
601
}
602
 
603
/* Write an object file.
604
   Section contents have already been written.  We write the
605
   file header, symbols, and relocation.  */
606
 
607
static boolean
608
tic30_aout_write_object_contents (abfd)
609
     bfd *abfd;
610
{
611
  struct external_exec exec_bytes;
612
  struct internal_exec *execp = exec_hdr (abfd);
613
 
614
  obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
615
 
616
  {
617
    bfd_size_type text_size;    /* dummy vars */
618
    file_ptr text_end;
619
    if (adata (abfd).magic == undecided_magic)
620
      NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end);
621
 
622
    execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE;
623
    execp->a_entry = bfd_get_start_address (abfd);
624
 
625
    execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * obj_reloc_entry_size (abfd));
626
    execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * obj_reloc_entry_size (abfd));
627
    NAME (aout, swap_exec_header_out) (abfd, execp, &exec_bytes);
628
 
629
    if (adata (abfd).exec_bytes_size > 0)
630
      {
631
        if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
632
          return false;
633
        if (bfd_write ((PTR) & exec_bytes, 1, adata (abfd).exec_bytes_size, abfd) != adata (abfd).exec_bytes_size)
634
          return false;
635
      }
636
    /* Now write out reloc info, followed by syms and strings */
637
 
638
    if (bfd_get_outsymbols (abfd) != (asymbol **) NULL
639
        && bfd_get_symcount (abfd) != 0)
640
      {
641
        if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*execp)), SEEK_SET) != 0)
642
          return false;
643
 
644
        if (!NAME (aout, write_syms) (abfd))
645
          return false;
646
      }
647
 
648
    if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*execp)), SEEK_SET) != 0)
649
      return false;
650
    if (!NAME (aout, squirt_out_relocs) (abfd, obj_textsec (abfd)))
651
      return false;
652
 
653
    if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*execp)), SEEK_SET) != 0)
654
      return false;
655
    if (!NAME (aout, squirt_out_relocs) (abfd, obj_datasec (abfd)))
656
      return false;
657
  }
658
 
659
  return true;
660
}
661
 
662
static boolean
663
tic30_aout_set_sizes (abfd)
664
     bfd *abfd;
665
{
666
  adata (abfd).page_size = TARGET_PAGE_SIZE;
667
 
668
#ifdef SEGMENT_SIZE
669
  adata (abfd).segment_size = SEGMENT_SIZE;
670
#else
671
  adata (abfd).segment_size = TARGET_PAGE_SIZE;
672
#endif
673
 
674
#ifdef ZMAGIC_DISK_BLOCK_SIZE
675
  adata (abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE;
676
#else
677
  adata (abfd).zmagic_disk_block_size = TARGET_PAGE_SIZE;
678
#endif
679
 
680
  adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
681
 
682
  return true;
683
}
684
 
685
#ifndef MY_final_link_callback
686
 
687
/* Callback for the final_link routine to set the section offsets.  */
688
 
689
static void MY_final_link_callback
690
  PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
691
 
692
static void
693
MY_final_link_callback (abfd, ptreloff, pdreloff, psymoff)
694
     bfd *abfd;
695
     file_ptr *ptreloff;
696
     file_ptr *pdreloff;
697
     file_ptr *psymoff;
698
{
699
  struct internal_exec *execp = exec_hdr (abfd);
700
 
701
  *ptreloff = obj_datasec (abfd)->filepos + execp->a_data;
702
  *pdreloff = *ptreloff + execp->a_trsize;
703
  *psymoff = *pdreloff + execp->a_drsize;;
704
}
705
 
706
#endif
707
 
708
#ifndef MY_bfd_final_link
709
 
710
/* Final link routine.  We need to use a call back to get the correct
711
   offsets in the output file.  */
712
 
713
static boolean
714
MY_bfd_final_link (abfd, info)
715
     bfd *abfd;
716
     struct bfd_link_info *info;
717
{
718
  struct internal_exec *execp = exec_hdr (abfd);
719
  file_ptr pos;
720
  bfd_vma vma = 0;
721
  int pad;
722
 
723
  /* Set the executable header size to 0, as we don't want one for an
724
     output.  */
725
  adata (abfd).exec_bytes_size = 0;
726
  pos = adata (abfd).exec_bytes_size;
727
  /* Text.  */
728
  vma = info->create_object_symbols_section->vma;
729
  pos += vma;
730
  obj_textsec (abfd)->filepos = pos;
731
  obj_textsec (abfd)->vma = vma;
732
  obj_textsec (abfd)->user_set_vma = 1;
733
  pos += obj_textsec (abfd)->_raw_size;
734
  vma += obj_textsec (abfd)->_raw_size;
735
 
736
  /* Data.  */
737
  if (abfd->flags & D_PAGED)
738
    {
739
      if (info->create_object_symbols_section->next->vma > 0)
740
        obj_datasec (abfd)->vma = info->create_object_symbols_section->next->vma;
741
      else
742
        obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
743
    }
744
  else
745
    {
746
      obj_datasec (abfd)->vma = BFD_ALIGN (vma, 4);
747
    }
748
  if (obj_datasec (abfd)->vma < vma)
749
    {
750
      obj_datasec (abfd)->vma = BFD_ALIGN (vma, 4);
751
    }
752
  obj_datasec (abfd)->user_set_vma = 1;
753
  vma = obj_datasec (abfd)->vma;
754
  obj_datasec (abfd)->filepos = vma + adata (abfd).exec_bytes_size;
755
  execp->a_text = vma - obj_textsec (abfd)->vma;
756
  obj_textsec (abfd)->_raw_size = execp->a_text;
757
 
758
  /* Since BSS follows data immediately, see if it needs alignment.  */
759
  vma += obj_datasec (abfd)->_raw_size;
760
  pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
761
  obj_datasec (abfd)->_raw_size += pad;
762
  pos += obj_datasec (abfd)->_raw_size;
763
  execp->a_data = obj_datasec (abfd)->_raw_size;
764
 
765
  /* BSS.  */
766
  obj_bsssec (abfd)->vma = vma;
767
  obj_bsssec (abfd)->user_set_vma = 1;
768
 
769
  /* We are fully resized, so don't readjust in final_link.  */
770
  adata (abfd).magic = z_magic;
771
 
772
  return NAME (aout, final_link) (abfd, info, MY_final_link_callback);
773
}
774
 
775
#endif
776
 
777
enum machine_type
778
tic30_aout_machine_type (arch, machine, unknown)
779
     enum bfd_architecture arch;
780
     unsigned long machine ATTRIBUTE_UNUSED;
781
     boolean *unknown;
782
{
783
  enum machine_type arch_flags;
784
 
785
  arch_flags = M_UNKNOWN;
786
  *unknown = true;
787
 
788
  switch (arch)
789
    {
790
    case bfd_arch_tic30:
791
      *unknown = false;
792
      break;
793
    default:
794
      arch_flags = M_UNKNOWN;
795
    }
796
  if (arch_flags != M_UNKNOWN)
797
    *unknown = false;
798
  return arch_flags;
799
}
800
 
801
boolean
802
tic30_aout_set_arch_mach (abfd, arch, machine)
803
     bfd *abfd;
804
     enum bfd_architecture arch;
805
     unsigned long machine;
806
{
807
  if (!bfd_default_set_arch_mach (abfd, arch, machine))
808
    return false;
809
  if (arch != bfd_arch_unknown)
810
    {
811
      boolean unknown;
812
      tic30_aout_machine_type (arch, machine, &unknown);
813
      if (unknown)
814
        return false;
815
    }
816
  obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
817
  return (*aout_backend_info (abfd)->set_sizes) (abfd);
818
}
819
 
820
/* We assume BFD generic archive files.  */
821
#ifndef MY_openr_next_archived_file
822
#define MY_openr_next_archived_file     bfd_generic_openr_next_archived_file
823
#endif
824
#ifndef MY_get_elt_at_index
825
#define MY_get_elt_at_index             _bfd_generic_get_elt_at_index
826
#endif
827
#ifndef MY_generic_stat_arch_elt
828
#define MY_generic_stat_arch_elt        bfd_generic_stat_arch_elt
829
#endif
830
#ifndef MY_slurp_armap
831
#define MY_slurp_armap                  bfd_slurp_bsd_armap
832
#endif
833
#ifndef MY_slurp_extended_name_table
834
#define MY_slurp_extended_name_table    _bfd_slurp_extended_name_table
835
#endif
836
#ifndef MY_construct_extended_name_table
837
#define MY_construct_extended_name_table \
838
  _bfd_archive_bsd_construct_extended_name_table
839
#endif
840
#ifndef MY_write_armap
841
#define MY_write_armap          bsd_write_armap
842
#endif
843
#ifndef MY_read_ar_hdr
844
#define MY_read_ar_hdr          _bfd_generic_read_ar_hdr
845
#endif
846
#ifndef MY_truncate_arname
847
#define MY_truncate_arname              bfd_bsd_truncate_arname
848
#endif
849
#ifndef MY_update_armap_timestamp
850
#define MY_update_armap_timestamp _bfd_archive_bsd_update_armap_timestamp
851
#endif
852
 
853
/* No core file defined here -- configure in trad-core.c separately.  */
854
#ifndef MY_core_file_failing_command
855
#define MY_core_file_failing_command _bfd_nocore_core_file_failing_command
856
#endif
857
#ifndef MY_core_file_failing_signal
858
#define MY_core_file_failing_signal     _bfd_nocore_core_file_failing_signal
859
#endif
860
#ifndef MY_core_file_matches_executable_p
861
#define MY_core_file_matches_executable_p       \
862
                                _bfd_nocore_core_file_matches_executable_p
863
#endif
864
#ifndef MY_core_file_p
865
#define MY_core_file_p          _bfd_dummy_target
866
#endif
867
 
868
#ifndef MY_bfd_debug_info_start
869
#define MY_bfd_debug_info_start         bfd_void
870
#endif
871
#ifndef MY_bfd_debug_info_end
872
#define MY_bfd_debug_info_end           bfd_void
873
#endif
874
#ifndef MY_bfd_debug_info_accumulate
875
#define MY_bfd_debug_info_accumulate    \
876
                        (void (*) PARAMS ((bfd*, struct sec *))) bfd_void
877
#endif
878
 
879
#ifndef MY_core_file_failing_command
880
#define MY_core_file_failing_command NAME(aout,core_file_failing_command)
881
#endif
882
#ifndef MY_core_file_failing_signal
883
#define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
884
#endif
885
#ifndef MY_core_file_matches_executable_p
886
#define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
887
#endif
888
#ifndef MY_set_section_contents
889
#define MY_set_section_contents NAME(aout,set_section_contents)
890
#endif
891
#ifndef MY_get_section_contents
892
#define MY_get_section_contents aout_32_get_section_contents
893
#endif
894
#ifndef MY_get_section_contents_in_window
895
#define MY_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
896
#endif
897
#ifndef MY_new_section_hook
898
#define MY_new_section_hook NAME(aout,new_section_hook)
899
#endif
900
#ifndef MY_get_symtab_upper_bound
901
#define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
902
#endif
903
#ifndef MY_get_symtab
904
#define MY_get_symtab NAME(aout,get_symtab)
905
#endif
906
#ifndef MY_get_reloc_upper_bound
907
#define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
908
#endif
909
#ifndef MY_canonicalize_reloc
910
#define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
911
#endif
912
#ifndef MY_make_empty_symbol
913
#define MY_make_empty_symbol NAME(aout,make_empty_symbol)
914
#endif
915
#ifndef MY_print_symbol
916
#define MY_print_symbol NAME(aout,print_symbol)
917
#endif
918
#ifndef MY_get_symbol_info
919
#define MY_get_symbol_info NAME(aout,get_symbol_info)
920
#endif
921
#ifndef MY_get_lineno
922
#define MY_get_lineno NAME(aout,get_lineno)
923
#endif
924
#ifndef MY_set_arch_mach
925
#define MY_set_arch_mach tic30_aout_set_arch_mach
926
#endif
927
#ifndef MY_find_nearest_line
928
#define MY_find_nearest_line NAME(aout,find_nearest_line)
929
#endif
930
#ifndef MY_sizeof_headers
931
#define MY_sizeof_headers NAME(aout,sizeof_headers)
932
#endif
933
#ifndef MY_bfd_get_relocated_section_contents
934
#define MY_bfd_get_relocated_section_contents \
935
                        bfd_generic_get_relocated_section_contents
936
#endif
937
#ifndef MY_bfd_relax_section
938
#define MY_bfd_relax_section bfd_generic_relax_section
939
#endif
940
#ifndef MY_bfd_gc_sections
941
#define MY_bfd_gc_sections bfd_generic_gc_sections
942
#endif
943
#ifndef MY_bfd_merge_sections
944
#define MY_bfd_merge_sections bfd_generic_merge_sections
945
#endif
946
#ifndef MY_bfd_reloc_type_lookup
947
#define MY_bfd_reloc_type_lookup tic30_aout_reloc_type_lookup
948
#endif
949
#ifndef MY_bfd_make_debug_symbol
950
#define MY_bfd_make_debug_symbol 0
951
#endif
952
#ifndef MY_read_minisymbols
953
#define MY_read_minisymbols NAME(aout,read_minisymbols)
954
#endif
955
#ifndef MY_minisymbol_to_symbol
956
#define MY_minisymbol_to_symbol NAME(aout,minisymbol_to_symbol)
957
#endif
958
#ifndef MY_bfd_link_hash_table_create
959
#define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
960
#endif
961
#ifndef MY_bfd_link_add_symbols
962
#define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
963
#endif
964
#ifndef MY_bfd_link_split_section
965
#define MY_bfd_link_split_section  _bfd_generic_link_split_section
966
#endif
967
 
968
#ifndef MY_bfd_copy_private_bfd_data
969
#define MY_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
970
#endif
971
 
972
#ifndef MY_bfd_merge_private_bfd_data
973
#define MY_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
974
#endif
975
 
976
#ifndef MY_bfd_copy_private_symbol_data
977
#define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
978
#endif
979
 
980
#ifndef MY_bfd_print_private_bfd_data
981
#define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
982
#endif
983
 
984
#ifndef MY_bfd_set_private_flags
985
#define MY_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
986
#endif
987
 
988
#ifndef MY_bfd_is_local_label_name
989
#define MY_bfd_is_local_label_name bfd_generic_is_local_label_name
990
#endif
991
 
992
#ifndef MY_bfd_free_cached_info
993
#define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
994
#endif
995
 
996
#ifndef MY_close_and_cleanup
997
#define MY_close_and_cleanup MY_bfd_free_cached_info
998
#endif
999
 
1000
#ifndef MY_get_dynamic_symtab_upper_bound
1001
#define MY_get_dynamic_symtab_upper_bound \
1002
  _bfd_nodynamic_get_dynamic_symtab_upper_bound
1003
#endif
1004
#ifndef MY_canonicalize_dynamic_symtab
1005
#define MY_canonicalize_dynamic_symtab \
1006
  _bfd_nodynamic_canonicalize_dynamic_symtab
1007
#endif
1008
#ifndef MY_get_dynamic_reloc_upper_bound
1009
#define MY_get_dynamic_reloc_upper_bound \
1010
  _bfd_nodynamic_get_dynamic_reloc_upper_bound
1011
#endif
1012
#ifndef MY_canonicalize_dynamic_reloc
1013
#define MY_canonicalize_dynamic_reloc \
1014
  _bfd_nodynamic_canonicalize_dynamic_reloc
1015
#endif
1016
 
1017
/* Aout symbols normally have leading underscores */
1018
#ifndef MY_symbol_leading_char
1019
#define MY_symbol_leading_char '_'
1020
#endif
1021
 
1022
/* Aout archives normally use spaces for padding */
1023
#ifndef AR_PAD_CHAR
1024
#define AR_PAD_CHAR ' '
1025
#endif
1026
 
1027
#ifndef MY_BFD_TARGET
1028
const bfd_target tic30_aout_vec =
1029
{
1030
  TARGETNAME,                   /* name */
1031
  bfd_target_aout_flavour,
1032
  BFD_ENDIAN_BIG,               /* target byte order (big) */
1033
  BFD_ENDIAN_BIG,               /* target headers byte order (big) */
1034
  (HAS_RELOC |                  /* object flags */
1035
   HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1036
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),        /* section flags */
1037
  MY_symbol_leading_char,
1038
  AR_PAD_CHAR,                  /* ar_pad_char */
1039
  15,                           /* ar_max_namelen */
1040
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1041
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1042
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* data */
1043
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1044
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1045
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* hdrs */
1046
  {_bfd_dummy_target, MY_object_p,      /* bfd_check_format */
1047
   bfd_generic_archive_p, MY_core_file_p},
1048
  {bfd_false, MY_mkobject,      /* bfd_set_format */
1049
   _bfd_generic_mkarchive, bfd_false},
1050
  {bfd_false, MY_write_object_contents,         /* bfd_write_contents */
1051
   _bfd_write_archive_contents, bfd_false},
1052
 
1053
  BFD_JUMP_TABLE_GENERIC (MY),
1054
  BFD_JUMP_TABLE_COPY (MY),
1055
  BFD_JUMP_TABLE_CORE (MY),
1056
  BFD_JUMP_TABLE_ARCHIVE (MY),
1057
  BFD_JUMP_TABLE_SYMBOLS (MY),
1058
  BFD_JUMP_TABLE_RELOCS (MY),
1059
  BFD_JUMP_TABLE_WRITE (MY),
1060
  BFD_JUMP_TABLE_LINK (MY),
1061
  BFD_JUMP_TABLE_DYNAMIC (MY),
1062
 
1063
  NULL,
1064
 
1065
  (PTR) MY_backend_data
1066
};
1067
#endif /* MY_BFD_TARGET */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.