* coff-tic80.c: Remove unnecessary #ifdefs.
[external/binutils.git] / bfd / coff-tic80.c
1 /* BFD back-end for Texas Instruments TMS320C80 Multimedia Video Processor (MVP).
2    Copyright 1996, 1997 Free Software Foundation, Inc.
3
4    Written by Fred Fish (fnf@cygnus.com)
5
6    There is nothing new under the sun. This file draws a lot on other
7    coff files.
8
9 This file is part of BFD, the Binary File Descriptor library.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
24
25 #include "bfd.h"
26 #include "sysdep.h"
27 #include "libbfd.h"
28 #include "coff/tic80.h"
29 #include "coff/internal.h"
30 #include "libcoff.h"
31
32 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
33
34 #define coff_relocate_section _bfd_coff_generic_relocate_section
35
36 static void rtype2howto PARAMS ((arelent *cache_ptr, struct internal_reloc *dst));
37
38 static reloc_howto_type tic80_howto_table[] =
39 {
40
41   HOWTO (R_RELLONG,                     /* type */
42          0,                             /* rightshift */
43          2,                             /* size (0 = byte, 1 = short, 2 = long) */
44          32,                            /* bitsize */
45          false,                         /* pc_relative */
46          0,                             /* bitpos */
47          complain_overflow_bitfield,    /* complain_on_overflow */
48          NULL,                          /* special_function */
49          "32",                          /* name */
50          true,                          /* partial_inplace */
51          0xffffffff,                    /* src_mask */
52          0xffffffff,                    /* dst_mask */
53          false),                        /* pcrel_offset */
54
55   HOWTO (R_MPPCR,                       /* type */
56          0,                             /* rightshift */
57          2,                             /* size (0 = byte, 1 = short, 2 = long) */
58          32,                            /* bitsize */
59          true,                          /* pc_relative */
60          0,                             /* bitpos */
61          complain_overflow_dont,        /* complain_on_overflow */
62          NULL,                          /* special_function */
63          "MPPCR",                       /* name */
64          true,                          /* partial_inplace */
65          0xffffffff,                    /* src_mask */
66          0xffffffff,                    /* dst_mask */
67          true),                         /* pcrel_offset */
68
69   HOWTO (R_ABS,                         /* type */
70          0,                             /* rightshift */
71          2,                             /* size (0 = byte, 1 = short, 2 = long) */
72          32,                            /* bitsize */
73          false,                         /* pc_relative */
74          0,                             /* bitpos */
75          complain_overflow_bitfield,    /* complain_on_overflow */
76          NULL,                          /* special_function */
77          "ABS",                         /* name */
78          true,                          /* partial_inplace */
79          0xffffffff,                    /* src_mask */
80          0xffffffff,                    /* dst_mask */
81          false),                                /* pcrel_offset */
82 };
83
84 /* Code to turn an external r_type into a pointer to an entry in the howto_table.
85    If passed an r_type we don't recognize the abort rather than silently failing
86    to generate an output file. */
87
88 static void
89 rtype2howto (cache_ptr, dst)
90      arelent *cache_ptr;
91      struct internal_reloc *dst;
92 {
93   switch (dst -> r_type)
94     {
95     default:            abort (); break;
96     case R_RELLONG:     cache_ptr -> howto = tic80_howto_table + 0; break;
97     case R_MPPCR:       cache_ptr -> howto = tic80_howto_table + 1; break;
98     case R_ABS:         cache_ptr -> howto = tic80_howto_table + 2; break;
99     }
100 }
101
102 #define RTYPE2HOWTO(cache_ptr, dst) rtype2howto (cache_ptr, dst)
103 #define coff_rtype_to_howto coff_tic80_rtype_to_howto
104
105 static reloc_howto_type *
106 coff_tic80_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
107      bfd *abfd;
108      asection *sec;
109      struct internal_reloc *rel;
110      struct coff_link_hash_entry *h;
111      struct internal_syment *sym;
112      bfd_vma *addendp;
113 {
114   arelent genrel;
115
116   if (rel -> r_symndx == -1 && addendp != NULL)
117     {
118       /* This is a TI "internal relocation", which means that the relocation
119          amount is the amount by which the current section is being relocated
120          in the output section. */
121       *addendp = (sec -> output_section -> vma + sec -> output_offset) - sec -> vma;
122     }
123   RTYPE2HOWTO (&genrel, rel);
124   return genrel.howto;
125 }
126
127 #ifndef BADMAG
128 #define BADMAG(x) TIC80BADMAG(x)
129 #endif
130
131 #define TIC80 1         /* Customize coffcode.h */
132 #include "coffcode.h"
133
134 const bfd_target 
135   tic80coff_vec =
136 {
137   "coff-tic80",                 /* name */
138   bfd_target_coff_flavour,
139   BFD_ENDIAN_LITTLE,            /* data byte order is little (arch supports both) */
140   BFD_ENDIAN_LITTLE,            /* header byte order is little */
141
142   (HAS_RELOC | EXEC_P |         /* object flags */
143    HAS_LINENO | HAS_DEBUG |
144    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
145
146   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
147   '_',                          /* leading underscore */
148   '/',                          /* ar_pad_char */
149   15,                           /* ar_max_namelen */
150   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
151      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
152      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
153   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
154      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
155      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
156
157  {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
158    bfd_generic_archive_p, _bfd_dummy_target},
159  {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
160    bfd_false},
161  {bfd_false, coff_write_object_contents, /* bfd_write_contents */
162    _bfd_write_archive_contents, bfd_false},
163
164      BFD_JUMP_TABLE_GENERIC (coff),
165      BFD_JUMP_TABLE_COPY (coff),
166      BFD_JUMP_TABLE_CORE (_bfd_nocore),
167      BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
168      BFD_JUMP_TABLE_SYMBOLS (coff),
169      BFD_JUMP_TABLE_RELOCS (coff),
170      BFD_JUMP_TABLE_WRITE (coff),
171      BFD_JUMP_TABLE_LINK (coff),
172      BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
173
174   COFF_SWAP_TABLE
175  };