* configure.ac: Don't add target-libmudflap to noconfigdirs for
[deliverable/binutils-gdb.git] / bfd / aout-ns32k.c
CommitLineData
252b5132 1/* BFD back-end for ns32k a.out-ish binaries.
9553c638 2 Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
157090f7 3 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
252b5132
RH
4 Contributed by Ian Dall (idall@eleceng.adelaide.edu.au).
5
4eb6b71c 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
4eb6b71c
NC
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.
252b5132 12
4eb6b71c
NC
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.
252b5132 17
4eb6b71c
NC
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 02110-1301, USA. */
252b5132 21
252b5132
RH
22#include "bfd.h"
23#include "aout/aout64.h"
24#include "ns32k.h"
25
e43d48cc
AM
26/* Do not "beautify" the CONCAT* macro args. Traditional C will not
27 remove whitespace added here, and thus will fail to concatenate
28 the tokens. */
29#define MYNS(OP) CONCAT2 (ns32kaout_,OP)
30
157090f7
AM
31reloc_howto_type * MYNS (bfd_reloc_type_lookup) (bfd *, bfd_reloc_code_real_type);
32reloc_howto_type * MYNS (bfd_reloc_name_lookup) (bfd *, const char *);
33bfd_boolean MYNS (write_object_contents) (bfd *);
252b5132 34
1725a96e
NC
35/* Avoid multiple definitions from aoutx if supporting
36 standard a.out format(s) as well as this one. */
e43d48cc 37#define NAME(x,y) CONCAT3 (ns32kaout,_32_,y)
252b5132 38
7920ce38 39void bfd_ns32k_arch (void);
252b5132
RH
40
41#include "libaout.h"
42
7920ce38 43#define MY(OP) MYNS (OP)
252b5132 44
7920ce38
NC
45#define MY_swap_std_reloc_in MY (swap_std_reloc_in)
46#define MY_swap_std_reloc_out MY (swap_std_reloc_out)
252b5132
RH
47
48/* The ns32k series is ah, unusual, when it comes to relocation.
1049f94e 49 There are three storage methods for relocatable objects. There
1725a96e
NC
50 are displacements, immediate operands and ordinary twos complement
51 data. Of these, only the last fits into the standard relocation
52 scheme. Immediate operands are stored huffman encoded and
53 immediate operands are stored big endian (where as the natural byte
5c4491d3 54 order is little endian for this architecture).
1725a96e
NC
55
56 Note that the ns32k displacement storage method is orthogonal to
57 whether the relocation is pc relative or not. The "displacement"
58 storage scheme is used for essentially all address constants. The
59 displacement can be relative to zero (absolute displacement),
60 relative to the pc (pc relative), the stack pointer, the frame
61 pointer, the static base register and general purpose register etc.
62
63 For example:
dc810e39 64
1725a96e
NC
65 sym1: .long . # pc relative 2's complement
66 sym1: .long foo # 2's complement not pc relative
dc810e39 67
1725a96e
NC
68 self: movd @self, r0 # pc relative displacement
69 movd foo, r0 # non pc relative displacement
70
71 self: movd self, r0 # pc relative immediate
72 movd foo, r0 # non pc relative immediate
dc810e39 73
1725a96e
NC
74 In addition, for historical reasons the encoding of the relocation types
75 in the a.out format relocation entries is such that even the relocation
4eb6b71c 76 methods which are standard are not encoded the standard way. */
252b5132 77
7920ce38
NC
78reloc_howto_type MY (howto_table)[] =
79{
80 /* ns32k immediate operands. */
81 HOWTO (BFD_RELOC_NS32K_IMM_8, 0, 0, 8, FALSE, 0, complain_overflow_signed,
82 _bfd_ns32k_reloc_imm, "NS32K_IMM_8",
83 TRUE, 0x000000ff,0x000000ff, FALSE),
84 HOWTO (BFD_RELOC_NS32K_IMM_16, 0, 1, 16, FALSE, 0, complain_overflow_signed,
85 _bfd_ns32k_reloc_imm, "NS32K_IMM_16",
86 TRUE, 0x0000ffff,0x0000ffff, FALSE),
87 HOWTO (BFD_RELOC_NS32K_IMM_32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
88 _bfd_ns32k_reloc_imm, "NS32K_IMM_32",
89 TRUE, 0xffffffff,0xffffffff, FALSE),
90 HOWTO (BFD_RELOC_NS32K_IMM_8_PCREL, 0, 0, 8, TRUE, 0, complain_overflow_signed,
91 _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_8",
92 TRUE, 0x000000ff, 0x000000ff, FALSE),
93 HOWTO (BFD_RELOC_NS32K_IMM_16_PCREL, 0, 1, 16, TRUE, 0, complain_overflow_signed,
94 _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_16",
95 TRUE, 0x0000ffff,0x0000ffff, FALSE),
96 HOWTO (BFD_RELOC_NS32K_IMM_32_PCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
97 _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_32",
98 TRUE, 0xffffffff,0xffffffff, FALSE),
99
100 /* ns32k displacements. */
101 HOWTO (BFD_RELOC_NS32K_DISP_8, 0, 0, 7, FALSE, 0, complain_overflow_signed,
102 _bfd_ns32k_reloc_disp, "NS32K_DISP_8",
103 TRUE, 0x000000ff,0x000000ff, FALSE),
104 HOWTO (BFD_RELOC_NS32K_DISP_16, 0, 1, 14, FALSE, 0, complain_overflow_signed,
105 _bfd_ns32k_reloc_disp, "NS32K_DISP_16",
106 TRUE, 0x0000ffff, 0x0000ffff, FALSE),
107 HOWTO (BFD_RELOC_NS32K_DISP_32, 0, 2, 30, FALSE, 0, complain_overflow_signed,
108 _bfd_ns32k_reloc_disp, "NS32K_DISP_32",
109 TRUE, 0xffffffff, 0xffffffff, FALSE),
110 HOWTO (BFD_RELOC_NS32K_DISP_8_PCREL, 0, 0, 7, TRUE, 0, complain_overflow_signed,
1725a96e 111 _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_8",
7920ce38
NC
112 TRUE, 0x000000ff,0x000000ff, FALSE),
113 HOWTO (BFD_RELOC_NS32K_DISP_16_PCREL, 0, 1, 14, TRUE, 0, complain_overflow_signed,
114 _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_16",
115 TRUE, 0x0000ffff,0x0000ffff, FALSE),
116 HOWTO (BFD_RELOC_NS32K_DISP_32_PCREL, 0, 2, 30, TRUE, 0, complain_overflow_signed,
117 _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_32",
118 TRUE, 0xffffffff,0xffffffff, FALSE),
119
120 /* Normal 2's complement. */
121 HOWTO (BFD_RELOC_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,0,
122 "8", TRUE, 0x000000ff,0x000000ff, FALSE),
123 HOWTO (BFD_RELOC_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,
124 "16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
125 HOWTO (BFD_RELOC_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,
126 "32", TRUE, 0xffffffff,0xffffffff, FALSE),
127 HOWTO (BFD_RELOC_8_PCREL, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0,
128 "PCREL_8", TRUE, 0x000000ff,0x000000ff, FALSE),
129 HOWTO (BFD_RELOC_16_PCREL, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0,
130 "PCREL_16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
131 HOWTO (BFD_RELOC_32_PCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0,
132 "PCREL_32", TRUE, 0xffffffff,0xffffffff, FALSE),
133};
134
135#define CTOR_TABLE_RELOC_HOWTO(BFD) (MY (howto_table) + 14)
136
137#define RELOC_STD_BITS_NS32K_TYPE_BIG 0x06
138#define RELOC_STD_BITS_NS32K_TYPE_LITTLE 0x60
139#define RELOC_STD_BITS_NS32K_TYPE_SH_BIG 1
140#define RELOC_STD_BITS_NS32K_TYPE_SH_LITTLE 5
141
142static reloc_howto_type *
143MY (reloc_howto) (bfd *abfd ATTRIBUTE_UNUSED,
144 struct reloc_std_external *rel,
145 int *r_index,
146 int *r_extern,
147 int *r_pcrel)
252b5132
RH
148{
149 unsigned int r_length;
150 int r_ns32k_type;
1725a96e 151
252b5132
RH
152 *r_index = ((rel->r_index[2] << 16)
153 | (rel->r_index[1] << 8)
154 | rel->r_index[0] );
155 *r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
156 *r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
157 r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
158 >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
159 r_ns32k_type = ((rel->r_type[0] & RELOC_STD_BITS_NS32K_TYPE_LITTLE)
160 >> RELOC_STD_BITS_NS32K_TYPE_SH_LITTLE);
7920ce38 161 return (MY (howto_table) + r_length + 3 * (*r_pcrel) + 6 * r_ns32k_type);
252b5132
RH
162}
163
dc810e39 164#define MY_reloc_howto(BFD, REL, IN, EX, PC) \
7920ce38
NC
165 MY (reloc_howto) (BFD, REL, &IN, &EX, &PC)
166
167static void
168MY (put_reloc) (bfd *abfd,
169 int r_extern,
170 int r_index,
171 bfd_vma value,
172 reloc_howto_type *howto,
173 struct reloc_std_external *reloc)
252b5132
RH
174{
175 unsigned int r_length;
176 int r_pcrel;
177 int r_ns32k_type;
1725a96e 178
252b5132 179 PUT_WORD (abfd, value, reloc->r_address);
1725a96e
NC
180 r_length = howto->size ; /* Size as a power of two. */
181 r_pcrel = (int) howto->pc_relative; /* Relative to PC? */
7920ce38 182 r_ns32k_type = (howto - MY (howto_table) )/6;
1725a96e 183
252b5132
RH
184 reloc->r_index[2] = r_index >> 16;
185 reloc->r_index[1] = r_index >> 8;
186 reloc->r_index[0] = r_index;
187 reloc->r_type[0] =
188 (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0)
189 | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0)
190 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE)
191 | (r_ns32k_type << RELOC_STD_BITS_NS32K_TYPE_SH_LITTLE);
192}
193
194#define MY_put_reloc(BFD, EXT, IDX, VAL, HOWTO, RELOC) \
7920ce38 195 MY (put_reloc) (BFD, EXT, IDX, VAL, HOWTO, RELOC)
252b5132
RH
196
197#define STAT_FOR_EXEC
198
199#define MY_final_link_relocate _bfd_ns32k_final_link_relocate
7920ce38
NC
200#define MY_relocate_contents _bfd_ns32k_relocate_contents
201
202static void MY_swap_std_reloc_in (bfd *, struct reloc_std_external *, arelent *, asymbol **, bfd_size_type);
203static void MY_swap_std_reloc_out (bfd *, arelent *, struct reloc_std_external *);
252b5132 204
dc810e39 205#include "aoutx.h"
252b5132
RH
206
207reloc_howto_type *
7920ce38 208MY (bfd_reloc_type_lookup) (bfd *abfd, bfd_reloc_code_real_type code)
252b5132 209{
7920ce38 210#define ENTRY(i,j) case i: return &MY (howto_table)[j]
252b5132
RH
211
212 int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE;
213
7920ce38 214 BFD_ASSERT (ext == 0);
252b5132
RH
215 if (code == BFD_RELOC_CTOR)
216 switch (bfd_get_arch_info (abfd)->bits_per_address)
217 {
218 case 32:
219 code = BFD_RELOC_32;
220 break;
1725a96e
NC
221 default:
222 break;
252b5132
RH
223 }
224 switch (code)
225 {
7920ce38
NC
226 ENTRY (BFD_RELOC_NS32K_IMM_8, 0);
227 ENTRY (BFD_RELOC_NS32K_IMM_16, 1);
228 ENTRY (BFD_RELOC_NS32K_IMM_32, 2);
229 ENTRY (BFD_RELOC_NS32K_IMM_8_PCREL, 3);
230 ENTRY (BFD_RELOC_NS32K_IMM_16_PCREL, 4);
231 ENTRY (BFD_RELOC_NS32K_IMM_32_PCREL, 5);
232 ENTRY (BFD_RELOC_NS32K_DISP_8, 6);
233 ENTRY (BFD_RELOC_NS32K_DISP_16, 7);
234 ENTRY (BFD_RELOC_NS32K_DISP_32, 8);
235 ENTRY (BFD_RELOC_NS32K_DISP_8_PCREL, 9);
236 ENTRY (BFD_RELOC_NS32K_DISP_16_PCREL, 10);
237 ENTRY (BFD_RELOC_NS32K_DISP_32_PCREL, 11);
238 ENTRY (BFD_RELOC_8, 12);
239 ENTRY (BFD_RELOC_16, 13);
240 ENTRY (BFD_RELOC_32, 14);
241 ENTRY (BFD_RELOC_8_PCREL, 15);
242 ENTRY (BFD_RELOC_16_PCREL, 16);
243 ENTRY (BFD_RELOC_32_PCREL, 17);
1725a96e 244 default:
7920ce38 245 return NULL;
252b5132
RH
246 }
247#undef ENTRY
248}
249
157090f7
AM
250reloc_howto_type *
251MY (bfd_reloc_name_lookup) (bfd *abfd ATTRIBUTE_UNUSED,
252 const char *r_name)
253{
254 unsigned int i;
255
256 for (i = 0;
257 i < sizeof (MY (howto_table)) / sizeof (MY (howto_table)[0]);
258 i++)
259 if (MY (howto_table)[i].name != NULL
260 && strcasecmp (MY (howto_table)[i].name, r_name) == 0)
261 return &MY (howto_table)[i];
262
263 return NULL;
264}
265
252b5132 266static void
7920ce38
NC
267MY_swap_std_reloc_in (bfd *abfd,
268 struct reloc_std_external *bytes,
269 arelent *cache_ptr,
270 asymbol **symbols,
271 bfd_size_type symcount ATTRIBUTE_UNUSED)
252b5132
RH
272{
273 int r_index;
274 int r_extern;
275 int r_pcrel;
276 struct aoutdata *su = &(abfd->tdata.aout_data->a);
277
dc810e39 278 cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
252b5132 279
1725a96e 280 /* Now the fun stuff. */
7920ce38 281 cache_ptr->howto = MY_reloc_howto (abfd, bytes, r_index, r_extern, r_pcrel);
252b5132 282
1725a96e 283 MOVE_ADDRESS (0);
252b5132
RH
284}
285
286static void
7920ce38
NC
287MY_swap_std_reloc_out (bfd *abfd,
288 arelent *g,
289 struct reloc_std_external *natptr)
252b5132
RH
290{
291 int r_index;
292 asymbol *sym = *(g->sym_ptr_ptr);
293 int r_extern;
252b5132
RH
294 asection *output_section = sym->section->output_section;
295
1725a96e 296 /* Name was clobbered by aout_write_syms to be symbol index. */
252b5132 297
c4dfa77f 298 /* If this relocation is relative to a symbol then set the
252b5132
RH
299 r_index to the symbols index, and the r_extern bit.
300
301 Absolute symbols can come in in two ways, either as an offset
302 from the abs section, or as a symbol which has an abs value.
303 Check for that here. */
252b5132
RH
304 if (bfd_is_com_section (output_section)
305 || output_section == &bfd_abs_section
c4dfa77f 306 || output_section == &bfd_und_section)
252b5132
RH
307 {
308 if (bfd_abs_section.symbol == sym)
309 {
310 /* Whoops, looked like an abs symbol, but is really an offset
1725a96e 311 from the abs section. */
252b5132
RH
312 r_index = 0;
313 r_extern = 0;
314 }
c4dfa77f 315 else
252b5132 316 {
1725a96e 317 /* Fill in symbol. */
252b5132
RH
318 r_extern = 1;
319#undef KEEPIT
320#define KEEPIT udata.i
321 r_index = (*(g->sym_ptr_ptr))->KEEPIT;
c4dfa77f 322#undef KEEPIT
252b5132
RH
323 }
324 }
c4dfa77f 325 else
252b5132 326 {
1725a96e 327 /* Just an ordinary section. */
252b5132 328 r_extern = 0;
c4dfa77f 329 r_index = output_section->target_index;
252b5132
RH
330 }
331
332 MY_put_reloc (abfd, r_extern, r_index, g->address, g->howto, natptr);
333}
334
335bfd_reloc_status_type
7920ce38
NC
336_bfd_ns32k_relocate_contents (reloc_howto_type *howto,
337 bfd *input_bfd,
338 bfd_vma relocation,
339 bfd_byte *location)
252b5132 340{
7920ce38
NC
341 int r_ns32k_type = (howto - MY (howto_table)) / 6;
342 bfd_vma (*get_data) (bfd_byte *, int);
343 void (*put_data) (bfd_vma, bfd_byte *, int);
252b5132
RH
344
345 switch (r_ns32k_type)
346 {
347 case 0:
348 get_data = _bfd_ns32k_get_immediate;
349 put_data = _bfd_ns32k_put_immediate;
350 break;
351 case 1:
352 get_data = _bfd_ns32k_get_displacement;
353 put_data = _bfd_ns32k_put_displacement;
354 break;
355 case 2:
356 return _bfd_relocate_contents (howto, input_bfd, relocation,
357 location);
252b5132
RH
358 default:
359 return bfd_reloc_notsupported;
360 }
361 return _bfd_do_ns32k_reloc_contents (howto, input_bfd, relocation,
362 location, get_data, put_data);
363}
This page took 0.333842 seconds and 4 git commands to generate.