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