* libbfd-in.h: Move declarations of bfd_read, bfd_write, bfd_seek,
[deliverable/binutils-gdb.git] / bfd / coff-i960.c
CommitLineData
6812b607 1/* BFD back-end for Intel 960 COFF files.
22aabad5 2 Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3b4f1a5d 3 Written by Cygnus Support.
fc723380 4
3b4f1a5d 5This file is part of BFD, the Binary File Descriptor library.
4a81b561 6
3b4f1a5d 7This program is free software; you can redistribute it and/or modify
4a81b561 8it under the terms of the GNU General Public License as published by
3b4f1a5d
SC
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
4a81b561 11
3b4f1a5d 12This program is distributed in the hope that it will be useful,
4a81b561
DHW
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
3b4f1a5d
SC
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
4a81b561 20
4a81b561 21#define I960 1
fc723380
JG
22#define BADMAG(x) I960BADMAG(x)
23
4a81b561 24#include "bfd.h"
3b4f1a5d 25#include "sysdep.h"
4a81b561 26#include "libbfd.h"
9872a49c 27#include "obstack.h"
8070f29d
KR
28#include "coff/i960.h"
29#include "coff/internal.h"
4a81b561 30#include "libcoff.h" /* to allow easier abstraction-breaking */
6812b607
ILT
31
32static bfd_reloc_status_type optcall_callback
33 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
34
294eaca4 35#define COFF_LONG_FILENAMES
4a81b561 36
4a81b561
DHW
37#define CALLS 0x66003800 /* Template for 'calls' instruction */
38#define BAL 0x0b000000 /* Template for 'bal' instruction */
39#define BAL_MASK 0x00ffffff
40
3b4f1a5d 41static bfd_reloc_status_type
6812b607
ILT
42optcall_callback (abfd, reloc_entry, symbol_in, data,
43 ignore_input_section, ignore_bfd, error_message)
44 bfd *abfd;
45 arelent *reloc_entry;
46 asymbol *symbol_in;
47 PTR data;
48 asection *ignore_input_section;
49 bfd *ignore_bfd;
50 char **error_message;
4a81b561
DHW
51{
52 /* This item has already been relocated correctly, but we may be
53 * able to patch in yet better code - done by digging out the
54 * correct info on this symbol */
3b4f1a5d 55 bfd_reloc_status_type result;
4a81b561
DHW
56 coff_symbol_type *cs = coffsymbol(symbol_in);
57
fc723380
JG
58 /* So the target symbol has to be of coff type, and the symbol
59 has to have the correct native information within it */
6812b607
ILT
60 if ((bfd_asymbol_flavour(&cs->symbol) != bfd_target_coff_flavour)
61 || (cs->native == (combined_entry_type *)NULL))
62 {
63 /* This is interesting, consider the case where we're outputting coff
64 from a mix n match input, linking from coff to a symbol defined in a
65 bout file will cause this match to be true. Should I complain? This
66 will only work if the bout symbol is non leaf. */
67 *error_message =
68 (char *) "uncertain calling convention for non-COFF symbol";
69 result = bfd_reloc_dangerous;
70 }
71 else
72 {
3b4f1a5d 73 switch (cs->native->u.syment.n_sclass)
4a81b561
DHW
74 {
75 case C_LEAFSTAT:
76 case C_LEAFEXT:
77 /* This is a call to a leaf procedure, replace instruction with a bal
6812b607 78 to the correct location. */
4a81b561 79 {
3b4f1a5d 80 union internal_auxent *aux = &((cs->native+2)->u.auxent);
8070f29d 81 int word = bfd_get_32(abfd, (bfd_byte *)data + reloc_entry->address);
3b4f1a5d
SC
82 int olf = (aux->x_bal.x_balntry - cs->native->u.syment.n_value);
83 BFD_ASSERT(cs->native->u.syment.n_numaux==2);
8e3c8f47 84
6812b607
ILT
85 /* We replace the original call instruction with a bal to
86 the bal entry point - the offset of which is described in
87 the 2nd auxent of the original symbol. We keep the native
88 sym and auxents untouched, so the delta between the two
89 is the offset of the bal entry point. */
8e3c8f47 90 word = ((word + olf) & BAL_MASK) | BAL;
8070f29d 91 bfd_put_32(abfd, word, (bfd_byte *) data + reloc_entry->address);
4a81b561
DHW
92 }
93 result = bfd_reloc_ok;
94 break;
95 case C_SCALL:
3b4f1a5d
SC
96 /* This is a call to a system call, replace with a calls to # */
97 BFD_ASSERT(0);
98 result = bfd_reloc_ok;
4a81b561
DHW
99 break;
100 default:
101 result = bfd_reloc_ok;
102 break;
103 }
104 }
105 return result;
106}
107
8070f29d 108static reloc_howto_type howto_rellong =
ffeef0bb
KR
109 HOWTO ((unsigned int) R_RELLONG, 0, 2, 32,false, 0,
110 complain_overflow_bitfield, 0,"rellong", true, 0xffffffff,
111 0xffffffff, 0);
8070f29d 112static reloc_howto_type howto_iprmed =
ffeef0bb
KR
113 HOWTO (R_IPRMED, 0, 2, 24,true,0, complain_overflow_signed,0,
114 "iprmed ", true, 0x00ffffff, 0x00ffffff, 0);
8070f29d 115static reloc_howto_type howto_optcall =
ffeef0bb
KR
116 HOWTO (R_OPTCALL, 0,2,24,true,0, complain_overflow_signed,
117 optcall_callback, "optcall", true, 0x00ffffff, 0x00ffffff, 0);
4a81b561 118
6812b607
ILT
119static const reloc_howto_type *
120coff_i960_reloc_type_lookup (abfd, code)
121 bfd *abfd;
122 bfd_reloc_code_real_type code;
8070f29d
KR
123{
124 switch (code)
125 {
126 default:
127 return 0;
128 case BFD_RELOC_I960_CALLJ:
129 return &howto_optcall;
130 case BFD_RELOC_32:
22aabad5 131 case BFD_RELOC_CTOR:
8070f29d
KR
132 return &howto_rellong;
133 case BFD_RELOC_24_PCREL:
134 return &howto_iprmed;
135 }
136}
4a81b561 137
924bbb38 138/* The real code is in coffcode.h */
4a81b561 139
3b4f1a5d 140#define RTYPE2HOWTO(cache_ptr, dst) \
8070f29d
KR
141{ \
142 reloc_howto_type *howto_ptr; \
143 switch ((dst)->r_type) { \
144 case 17: howto_ptr = &howto_rellong; break; \
145 case 25: howto_ptr = &howto_iprmed; break; \
146 case 27: howto_ptr = &howto_optcall; break; \
147 default: howto_ptr = 0; break; \
148 } \
149 cache_ptr->howto = howto_ptr; \
150 }
3b4f1a5d 151
7ed4093a 152#include "coffcode.h"
4a81b561 153
6812b607
ILT
154#undef coff_bfd_reloc_type_lookup
155#define coff_bfd_reloc_type_lookup coff_i960_reloc_type_lookup
156
ffeef0bb 157const bfd_target icoff_little_vec =
4a81b561 158{
9872a49c 159 "coff-Intel-little", /* name */
3b4f1a5d 160 bfd_target_coff_flavour,
4a81b561 161 false, /* data byte order is little */
9872a49c 162 false, /* header byte order is little */
4a81b561
DHW
163
164 (HAS_RELOC | EXEC_P | /* object flags */
165 HAS_LINENO | HAS_DEBUG |
6812b607 166 HAS_SYMS | HAS_LOCALS | WP_TEXT),
4a81b561
DHW
167
168 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
22aabad5 169 '_', /* leading underscore */
4a81b561
DHW
170 '/', /* ar_pad_char */
171 15, /* ar_max_namelen */
4a81b561 172
294eaca4 173 3, /* minimum alignment power */
6812b607
ILT
174 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
175 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
176 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
177 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
178 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
179 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
4a81b561 180
294eaca4
SC
181 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
182 bfd_generic_archive_p, _bfd_dummy_target},
183 {bfd_false, coff_mkobject, /* bfd_set_format */
184 _bfd_generic_mkarchive, bfd_false},
185 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
186 _bfd_write_archive_contents, bfd_false},
6812b607
ILT
187
188 BFD_JUMP_TABLE_GENERIC (coff),
189 BFD_JUMP_TABLE_COPY (coff),
190 BFD_JUMP_TABLE_CORE (_bfd_nocore),
191 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
192 BFD_JUMP_TABLE_SYMBOLS (coff),
193 BFD_JUMP_TABLE_RELOCS (coff),
194 BFD_JUMP_TABLE_WRITE (coff),
195 BFD_JUMP_TABLE_LINK (coff),
22aabad5 196 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
6812b607 197
8070f29d 198 COFF_SWAP_TABLE,
8070f29d 199};
4a81b561
DHW
200
201
ffeef0bb 202const bfd_target icoff_big_vec =
4a81b561 203{
9872a49c 204 "coff-Intel-big", /* name */
3b4f1a5d 205 bfd_target_coff_flavour,
4a81b561 206 false, /* data byte order is little */
9872a49c 207 true, /* header byte order is big */
4a81b561
DHW
208
209 (HAS_RELOC | EXEC_P | /* object flags */
210 HAS_LINENO | HAS_DEBUG |
6812b607 211 HAS_SYMS | HAS_LOCALS | WP_TEXT),
4a81b561
DHW
212
213 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
22aabad5 214 '_', /* leading underscore */
4a81b561
DHW
215 '/', /* ar_pad_char */
216 15, /* ar_max_namelen */
4a81b561 217
3b4f1a5d 218 3, /* minimum alignment power */
6812b607
ILT
219bfd_getl64, bfd_getl_signed_64, bfd_putl64,
220 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
221 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
222bfd_getb64, bfd_getb_signed_64, bfd_putb64,
223 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
224 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
4a81b561 225
2b1d8a50
JG
226 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
227 bfd_generic_archive_p, _bfd_dummy_target},
228 {bfd_false, coff_mkobject, /* bfd_set_format */
229 _bfd_generic_mkarchive, bfd_false},
230 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
231 _bfd_write_archive_contents, bfd_false},
6812b607
ILT
232
233 BFD_JUMP_TABLE_GENERIC (coff),
234 BFD_JUMP_TABLE_COPY (coff),
235 BFD_JUMP_TABLE_CORE (_bfd_nocore),
236 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
237 BFD_JUMP_TABLE_SYMBOLS (coff),
238 BFD_JUMP_TABLE_RELOCS (coff),
239 BFD_JUMP_TABLE_WRITE (coff),
240 BFD_JUMP_TABLE_LINK (coff),
22aabad5 241 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
6812b607 242
8070f29d 243 COFF_SWAP_TABLE,
fc723380 244};
This page took 0.12222 seconds and 4 git commands to generate.