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