1 /* BFD back-end for TMS320C30 coff binaries.
2 Copyright (C) 1998-2019 Free Software Foundation, Inc.
3 Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
5 This file is part of BFD, the Binary File Descriptor library.
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 3 of the License, or
10 (at your option) any later version.
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.
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., 51 Franklin Street - Fifth Floor, Boston, MA
26 #include "coff/tic30.h"
27 #include "coff/internal.h"
30 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
32 reloc_howto_type tic30_coff_howto_table[] =
34 HOWTO (R_TIC30_ABS16, 2, 1, 16, FALSE, 0, 0, NULL,
35 "16", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
36 HOWTO (R_TIC30_ABS24, 2, 2, 24, FALSE, 8, complain_overflow_bitfield, NULL,
37 "24", FALSE, 0xFFFFFF00, 0xFFFFFF00, FALSE),
38 HOWTO (R_TIC30_LDP, 18, 0, 24, FALSE, 0, complain_overflow_bitfield, NULL,
39 "LDP", FALSE, 0x00FF0000, 0x000000FF, FALSE),
40 HOWTO (R_TIC30_ABS32, 2, 2, 32, FALSE, 0, complain_overflow_bitfield, NULL,
41 "32", FALSE, 0xFFFFFFFF, 0xFFFFFFFF, FALSE),
42 HOWTO (R_TIC30_PC16, 2, 1, 16, TRUE, 0, complain_overflow_signed, NULL,
43 "PCREL", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
47 #ifndef coff_bfd_reloc_type_lookup
48 #define coff_bfd_reloc_type_lookup tic30_coff_reloc_type_lookup
49 #define coff_bfd_reloc_name_lookup tic30_coff_reloc_name_lookup
51 /* For the case statement use the code values used in tc_gen_reloc to
52 map to the howto table entries that match those in both the aout
53 and coff implementations. */
55 static reloc_howto_type *
56 tic30_coff_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
57 bfd_reloc_code_real_type code)
62 case BFD_RELOC_TIC30_LDP:
63 return &tic30_coff_howto_table[2];
65 return &tic30_coff_howto_table[0];
67 return &tic30_coff_howto_table[1];
68 case BFD_RELOC_16_PCREL:
69 return &tic30_coff_howto_table[4];
71 return &tic30_coff_howto_table[3];
73 return (reloc_howto_type *) NULL;
77 static reloc_howto_type *
78 tic30_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
84 i < (sizeof (tic30_coff_howto_table)
85 / sizeof (tic30_coff_howto_table[0]));
87 if (tic30_coff_howto_table[i].name != NULL
88 && strcasecmp (tic30_coff_howto_table[i].name, r_name) == 0)
89 return &tic30_coff_howto_table[i];
96 /* Turn a howto into a reloc number. */
99 coff_tic30_select_reloc (reloc_howto_type *howto)
104 #define SELECT_RELOC(x,howto) x.r_type = coff_tic30_select_reloc(howto)
106 #define BADMAG(x) TIC30BADMAG(x)
107 #define TIC30 1 /* Customize coffcode.h */
108 #define __A_MAGIC_SET__
110 /* Code to swap in the reloc */
111 #define SWAP_IN_RELOC_OFFSET H_GET_32
112 #define SWAP_OUT_RELOC_OFFSET H_PUT_32
113 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) dst->r_stuff[0] = 'S'; \
114 dst->r_stuff[1] = 'C';
116 /* Code to turn a r_type into a howto ptr, uses the above howto table. */
119 rtype2howto (arelent *internal, struct internal_reloc *dst)
124 internal->howto = &tic30_coff_howto_table[0];
127 internal->howto = &tic30_coff_howto_table[1];
130 internal->howto = &tic30_coff_howto_table[3];
133 internal->howto = &tic30_coff_howto_table[2];
136 internal->howto = &tic30_coff_howto_table[4];
139 internal->howto = NULL;
144 #define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry)
146 /* Perform any necessary magic to the addend in a reloc entry */
148 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
149 cache_ptr->addend = ext_reloc.r_offset;
151 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
152 reloc_processing(relent, reloc, symbols, abfd, section)
155 reloc_processing (arelent *relent,
156 struct internal_reloc *reloc,
161 relent->address = reloc->r_vaddr;
162 rtype2howto (relent, reloc);
164 if (reloc->r_symndx > 0)
165 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
167 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
169 relent->addend = reloc->r_offset;
170 relent->address -= section->vma;
173 #ifndef bfd_pe_print_pdata
174 #define bfd_pe_print_pdata NULL
177 #include "coffcode.h"
179 const bfd_target tic30_coff_vec =
181 "coff-tic30", /* name */
182 bfd_target_coff_flavour,
183 BFD_ENDIAN_BIG, /* data byte order is big */
184 BFD_ENDIAN_LITTLE, /* header byte order is little */
186 (HAS_RELOC | EXEC_P /* object flags */
187 | HAS_LINENO | HAS_DEBUG
188 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
190 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
191 '_', /* leading symbol underscore */
192 '/', /* ar_pad_char */
193 15, /* ar_max_namelen */
194 0, /* match priority. */
195 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
196 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
197 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
198 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
199 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
200 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
202 { /* bfd_check_format */
205 bfd_generic_archive_p,
208 { /* bfd_set_format */
209 _bfd_bool_bfd_false_error,
211 _bfd_generic_mkarchive,
212 _bfd_bool_bfd_false_error
214 { /* bfd_write_contents */
215 _bfd_bool_bfd_false_error,
216 coff_write_object_contents,
217 _bfd_write_archive_contents,
218 _bfd_bool_bfd_false_error
221 BFD_JUMP_TABLE_GENERIC (coff),
222 BFD_JUMP_TABLE_COPY (coff),
223 BFD_JUMP_TABLE_CORE (_bfd_nocore),
224 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
225 BFD_JUMP_TABLE_SYMBOLS (coff),
226 BFD_JUMP_TABLE_RELOCS (coff),
227 BFD_JUMP_TABLE_WRITE (coff),
228 BFD_JUMP_TABLE_LINK (coff),
229 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),