bfd/
[deliverable/binutils-gdb.git] / bfd / coff-tic30.c
CommitLineData
252b5132 1/* BFD back-end for TMS320C30 coff binaries.
157090f7
AM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2007
3 Free Software Foundation, Inc.
252b5132
RH
4 Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
5
6 This file is part of BFD, the Binary File Descriptor library.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
3e110533 20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
53e09e0a 21 02110-1301, USA. */
252b5132 22
252b5132 23#include "sysdep.h"
3db64b00 24#include "bfd.h"
252b5132
RH
25#include "libbfd.h"
26#include "bfdlink.h"
27#include "coff/tic30.h"
28#include "coff/internal.h"
29#include "libcoff.h"
30
f4ffd778
NC
31static int coff_tic30_select_reloc PARAMS ((reloc_howto_type *));
32static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
33static void reloc_processing PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
34
35reloc_howto_type * tic30_coff_reloc_type_lookup PARAMS ((bfd *, bfd_reloc_code_real_type));
36
252b5132
RH
37#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
38
39reloc_howto_type tic30_coff_howto_table[] =
f4ffd778 40 {
b34976b6
AM
41 HOWTO (R_TIC30_ABS16, 2, 1, 16, FALSE, 0, 0, NULL,
42 "16", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
43 HOWTO (R_TIC30_ABS24, 2, 2, 24, FALSE, 8, complain_overflow_bitfield, NULL,
44 "24", FALSE, 0xFFFFFF00, 0xFFFFFF00, FALSE),
45 HOWTO (R_TIC30_LDP, 18, 0, 24, FALSE, 0, complain_overflow_bitfield, NULL,
46 "LDP", FALSE, 0x00FF0000, 0x000000FF, FALSE),
47 HOWTO (R_TIC30_ABS32, 2, 2, 32, FALSE, 0, complain_overflow_bitfield, NULL,
48 "32", FALSE, 0xFFFFFFFF, 0xFFFFFFFF, FALSE),
49 HOWTO (R_TIC30_PC16, 2, 1, 16, TRUE, 0, complain_overflow_signed, NULL,
50 "PCREL", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
f4ffd778
NC
51 EMPTY_HOWTO (-1)
52 };
252b5132
RH
53
54#ifndef coff_bfd_reloc_type_lookup
55#define coff_bfd_reloc_type_lookup tic30_coff_reloc_type_lookup
157090f7 56#define coff_bfd_reloc_name_lookup tic30_coff_reloc_name_lookup
252b5132
RH
57
58/* For the case statement use the code values used in tc_gen_reloc to
59 map to the howto table entries that match those in both the aout
cbfe05c4 60 and coff implementations. */
f4ffd778 61
252b5132
RH
62reloc_howto_type *
63tic30_coff_reloc_type_lookup (abfd, code)
5f771d47 64 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
65 bfd_reloc_code_real_type code;
66{
67 switch (code)
68 {
69 case BFD_RELOC_8:
70 case BFD_RELOC_TIC30_LDP:
71 return &tic30_coff_howto_table[2];
72 case BFD_RELOC_16:
73 return &tic30_coff_howto_table[0];
74 case BFD_RELOC_24:
75 return &tic30_coff_howto_table[1];
76 case BFD_RELOC_16_PCREL:
77 return &tic30_coff_howto_table[4];
78 case BFD_RELOC_32:
79 return &tic30_coff_howto_table[3];
80 default:
81 return (reloc_howto_type *) NULL;
82 }
83}
84
157090f7
AM
85static reloc_howto_type *
86tic30_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
87 const char *r_name)
88{
89 unsigned int i;
90
91 for (i = 0;
92 i < (sizeof (tic30_coff_howto_table)
93 / sizeof (tic30_coff_howto_table[0]));
94 i++)
95 if (tic30_coff_howto_table[i].name != NULL
96 && strcasecmp (tic30_coff_howto_table[i].name, r_name) == 0)
97 return &tic30_coff_howto_table[i];
98
99 return NULL;
100}
101
252b5132
RH
102#endif
103
f4ffd778 104/* Turn a howto into a reloc number. */
252b5132
RH
105
106static int
107coff_tic30_select_reloc (howto)
108 reloc_howto_type *howto;
109{
110 return howto->type;
111}
112
113#define SELECT_RELOC(x,howto) x.r_type = coff_tic30_select_reloc(howto)
114
252b5132
RH
115#define BADMAG(x) TIC30BADMAG(x)
116#define TIC30 1 /* Customize coffcode.h */
117#define __A_MAGIC_SET__
118
119/* Code to swap in the reloc */
dc810e39
AM
120#define SWAP_IN_RELOC_OFFSET H_GET_32
121#define SWAP_OUT_RELOC_OFFSET H_PUT_32
252b5132
RH
122#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) dst->r_stuff[0] = 'S'; \
123dst->r_stuff[1] = 'C';
124
cbfe05c4 125/* Code to turn a r_type into a howto ptr, uses the above howto table. */
252b5132
RH
126
127static void
128rtype2howto (internal, dst)
129 arelent *internal;
130 struct internal_reloc *dst;
131{
132 switch (dst->r_type)
133 {
134 case R_TIC30_ABS16:
135 internal->howto = &tic30_coff_howto_table[0];
136 break;
137 case R_TIC30_ABS24:
138 internal->howto = &tic30_coff_howto_table[1];
139 break;
140 case R_TIC30_ABS32:
141 internal->howto = &tic30_coff_howto_table[3];
142 break;
143 case R_TIC30_LDP:
144 internal->howto = &tic30_coff_howto_table[2];
145 break;
146 case R_TIC30_PC16:
147 internal->howto = &tic30_coff_howto_table[4];
148 break;
149 default:
150 abort ();
151 break;
152 }
153}
154
f4ffd778 155#define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry)
252b5132
RH
156
157/* Perform any necessary magic to the addend in a reloc entry */
158
159#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
160 cache_ptr->addend = ext_reloc.r_offset;
161
252b5132
RH
162#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
163 reloc_processing(relent, reloc, symbols, abfd, section)
164
165static void
166reloc_processing (relent, reloc, symbols, abfd, section)
167 arelent *relent;
168 struct internal_reloc *reloc;
169 asymbol **symbols;
170 bfd *abfd;
171 asection *section;
172{
173 relent->address = reloc->r_vaddr;
174 rtype2howto (relent, reloc);
175
176 if (reloc->r_symndx > 0)
f4ffd778 177 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
252b5132 178 else
f4ffd778
NC
179 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
180
252b5132
RH
181 relent->addend = reloc->r_offset;
182 relent->address -= section->vma;
183}
184
185#include "coffcode.h"
186
187const bfd_target tic30_coff_vec =
188{
189 "coff-tic30", /* name */
190 bfd_target_coff_flavour,
191 BFD_ENDIAN_BIG, /* data byte order is big */
192 BFD_ENDIAN_LITTLE, /* header byte order is little */
193
194 (HAS_RELOC | EXEC_P | /* object flags */
195 HAS_LINENO | HAS_DEBUG |
196 HAS_SYMS | HAS_LOCALS | WP_TEXT),
197
198 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
199 '_', /* leading symbol underscore */
200 '/', /* ar_pad_char */
201 15, /* ar_max_namelen */
202 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
203 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
204 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
205 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
206 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
207 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
208
209 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
210 bfd_generic_archive_p, _bfd_dummy_target},
211 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
212 bfd_false},
213 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
214 _bfd_write_archive_contents, bfd_false},
215
216 BFD_JUMP_TABLE_GENERIC (coff),
217 BFD_JUMP_TABLE_COPY (coff),
218 BFD_JUMP_TABLE_CORE (_bfd_nocore),
219 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
220 BFD_JUMP_TABLE_SYMBOLS (coff),
221 BFD_JUMP_TABLE_RELOCS (coff),
222 BFD_JUMP_TABLE_WRITE (coff),
223 BFD_JUMP_TABLE_LINK (coff),
224 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
225
c3c89269 226 NULL,
cbfe05c4 227
252b5132
RH
228 COFF_SWAP_TABLE
229};
This page took 0.365158 seconds and 4 git commands to generate.