* Makefile.am (PROGS,bin_PROGRAMS): Add @BUILD_MISC@
[deliverable/binutils-gdb.git] / bfd / coff-z8k.c
CommitLineData
075caafd 1/* BFD back-end for Zilog Z800n COFF binaries.
6812b607 2 Copyright 1992, 1993, 1994 Free Software Foundation, Inc.
075caafd
ILT
3 Contributed by Cygnus Support.
4 Written by Steve Chamberlain, <sac@cygnus.com>.
8ad2a31d
SC
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
a5655244 20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
8ad2a31d 21
8ad2a31d
SC
22#include "bfd.h"
23#include "sysdep.h"
8ad2a31d 24#include "obstack.h"
4991ebb9
ILT
25#include "libbfd.h"
26#include "bfdlink.h"
8ad2a31d
SC
27#include "coff/z8k.h"
28#include "coff/internal.h"
29#include "libcoff.h"
8ad2a31d 30
a5655244
ILT
31#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
32
075caafd 33static reloc_howto_type r_imm32 =
4991ebb9
ILT
34HOWTO (R_IMM32, 0, 1, 32, false, 0,
35 complain_overflow_bitfield, 0, "r_imm32", true, 0xffffffff,
36 0xffffffff, false);
8ad2a31d 37
075caafd 38static reloc_howto_type r_imm4l =
4991ebb9
ILT
39HOWTO (R_IMM4L, 0, 1, 4, false, 0,
40 complain_overflow_bitfield, 0, "r_imm4l", true, 0xf, 0xf, false);
8ad2a31d 41
075caafd 42static reloc_howto_type r_da =
4991ebb9
ILT
43HOWTO (R_IMM16, 0, 1, 16, false, 0,
44 complain_overflow_bitfield, 0, "r_da", true, 0x0000ffff, 0x0000ffff,
45 false);
075caafd
ILT
46
47static reloc_howto_type r_imm8 =
4991ebb9
ILT
48HOWTO (R_IMM8, 0, 1, 8, false, 0,
49 complain_overflow_bitfield, 0, "r_imm8", true, 0x000000ff, 0x000000ff,
50 false);
8ad2a31d 51
075caafd 52static reloc_howto_type r_jr =
4991ebb9
ILT
53HOWTO (R_JR, 0, 1, 8, true, 0, complain_overflow_signed, 0,
54 "r_jr", true, 0, 0, true);
8ad2a31d
SC
55
56/* Turn a howto into a reloc number */
57
075caafd
ILT
58static int
59coff_z8k_select_reloc (howto)
60 reloc_howto_type *howto;
8ad2a31d 61{
075caafd 62 return howto->type;
8ad2a31d 63}
075caafd 64
6812b607 65#define SELECT_RELOC(x,howto) x.r_type = coff_z8k_select_reloc(howto)
8ad2a31d
SC
66
67
68#define BADMAG(x) Z8KBADMAG(x)
075caafd 69#define Z8K 1 /* Customize coffcode.h */
8ad2a31d
SC
70#define __A_MAGIC_SET__
71
72
73
74/* Code to swap in the reloc */
75#define SWAP_IN_RELOC_OFFSET bfd_h_get_32
76#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
77#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
78 dst->r_stuff[0] = 'S'; \
075caafd 79 dst->r_stuff[1] = 'C';
8ad2a31d
SC
80
81/* Code to turn a r_type into a howto ptr, uses the above howto table
82 */
83
075caafd 84static void
6812b607
ILT
85rtype2howto (internal, dst)
86 arelent * internal;
87 struct internal_reloc *dst;
8ad2a31d 88{
075caafd
ILT
89 switch (dst->r_type)
90 {
91 default:
4991ebb9 92 fprintf (stderr, "BAD 0x%x\n", dst->r_type);
075caafd
ILT
93 case R_IMM8:
94 internal->howto = &r_imm8;
95 break;
4991ebb9 96 case R_IMM16:
075caafd
ILT
97 internal->howto = &r_da;
98 break;
99 case R_JR:
100 internal->howto = &r_jr;
101 break;
102 case R_IMM32:
103 internal->howto = &r_imm32;
104 break;
105 case R_IMM4L:
106 internal->howto = &r_imm4l;
107 break;
8ad2a31d
SC
108 }
109}
110
111#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
112
113
114/* Perform any necessaru magic to the addend in a reloc entry */
115
116
117#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
118 cache_ptr->addend = ext_reloc.r_offset;
119
075caafd 120
8ad2a31d
SC
121#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
122 reloc_processing(relent, reloc, symbols, abfd, section)
123
075caafd 124static void
6812b607
ILT
125reloc_processing (relent, reloc, symbols, abfd, section)
126 arelent * relent;
127 struct internal_reloc *reloc;
128 asymbol ** symbols;
129 bfd * abfd;
130 asection * section;
8ad2a31d 131{
075caafd
ILT
132 relent->address = reloc->r_vaddr;
133 rtype2howto (relent, reloc);
134
135 if (reloc->r_symndx > 0)
136 {
137 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
138 }
139 else
140 {
a5655244 141 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
075caafd
ILT
142 }
143
144
8ad2a31d 145 relent->addend = reloc->r_offset;
075caafd 146 relent->address -= section->vma;
8ad2a31d
SC
147}
148
5f9ca960 149static void
4991ebb9 150extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
5f9ca960 151 bfd *in_abfd;
4991ebb9
ILT
152 struct bfd_link_info *link_info;
153 struct bfd_link_order *link_order;
5f9ca960
JG
154 arelent *reloc;
155 bfd_byte *data;
156 unsigned int *src_ptr;
157 unsigned int *dst_ptr;
8ad2a31d 158{
4991ebb9
ILT
159 asection *input_section = link_order->u.indirect.section;
160
075caafd
ILT
161 switch (reloc->howto->type)
162 {
163 case R_IMM8:
4991ebb9
ILT
164 bfd_put_8 (in_abfd,
165 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
075caafd
ILT
166 data + *dst_ptr);
167 (*dst_ptr) += 1;
168 (*src_ptr) += 1;
169 break;
170
171 case R_IMM32:
4991ebb9
ILT
172 bfd_put_32 (in_abfd,
173 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
075caafd
ILT
174 data + *dst_ptr);
175 (*dst_ptr) += 4;
176 (*src_ptr) += 4;
177 break;
178
179 case R_IMM4L:
180 bfd_put_8 (in_abfd,
4991ebb9
ILT
181 ((bfd_get_8 (in_abfd, data + *dst_ptr) & 0xf0)
182 | (0x0f
183 & bfd_coff_reloc16_get_value (reloc, link_info,
184 input_section))),
075caafd
ILT
185 data + *dst_ptr);
186 (*dst_ptr) += 1;
187 (*src_ptr) += 1;
188 break;
189
4991ebb9
ILT
190 case R_IMM16:
191 bfd_put_16 (in_abfd,
192 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
075caafd
ILT
193 data + *dst_ptr);
194 (*dst_ptr) += 2;
195 (*src_ptr) += 2;
196 break;
197
198 case R_JR:
199 {
4991ebb9
ILT
200 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
201 input_section);
202 bfd_vma dot = (link_order->offset
203 + *dst_ptr
204 + input_section->output_section->vma);
075caafd
ILT
205 int gap = dst - dot - 1;/* -1 since were in the odd byte of the
206 word and the pc's been incremented */
207
208 if (gap & 1)
209 abort ();
210 gap /= 2;
211 if (gap > 128 || gap < -128)
212 {
4991ebb9
ILT
213 if (! ((*link_info->callbacks->reloc_overflow)
214 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
215 reloc->howto->name, reloc->addend, input_section->owner,
216 input_section, reloc->address)))
217 abort ();
075caafd
ILT
218 }
219 bfd_put_8 (in_abfd, gap, data + *dst_ptr);
220 (*dst_ptr)++;
221 (*src_ptr)++;
222 break;
223 }
224 default:
225 abort ();
226 }
8ad2a31d 227}
8ad2a31d 228
075caafd 229#define coff_reloc16_extra_cases extra_case
8ad2a31d
SC
230
231#include "coffcode.h"
232
233
075caafd 234#undef coff_bfd_get_relocated_section_contents
8ad2a31d 235#undef coff_bfd_relax_section
4991ebb9
ILT
236#define coff_bfd_get_relocated_section_contents \
237 bfd_coff_reloc16_get_relocated_section_contents
075caafd 238#define coff_bfd_relax_section bfd_coff_reloc16_relax_section
8ad2a31d 239
2f3508ad 240const bfd_target z8kcoff_vec =
8ad2a31d 241{
294eaca4 242 "coff-z8k", /* name */
8ad2a31d
SC
243 bfd_target_coff_flavour,
244 true, /* data byte order is big */
245 true, /* header byte order is big */
246
247 (HAS_RELOC | EXEC_P | /* object flags */
248 HAS_LINENO | HAS_DEBUG |
4991ebb9 249 HAS_SYMS | HAS_LOCALS | WP_TEXT),
8ad2a31d 250
075caafd 251 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
294eaca4 252 '_', /* leading symbol underscore */
8ad2a31d
SC
253 '/', /* ar_pad_char */
254 15, /* ar_max_namelen */
4991ebb9
ILT
255 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
256 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
257 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
258 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
259 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
260 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
294eaca4 261
075caafd 262 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
294eaca4 263 bfd_generic_archive_p, _bfd_dummy_target},
075caafd 264 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
294eaca4 265 bfd_false},
075caafd 266 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
294eaca4
SC
267 _bfd_write_archive_contents, bfd_false},
268
6812b607
ILT
269 BFD_JUMP_TABLE_GENERIC (coff),
270 BFD_JUMP_TABLE_COPY (coff),
271 BFD_JUMP_TABLE_CORE (_bfd_nocore),
272 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
273 BFD_JUMP_TABLE_SYMBOLS (coff),
274 BFD_JUMP_TABLE_RELOCS (coff),
275 BFD_JUMP_TABLE_WRITE (coff),
276 BFD_JUMP_TABLE_LINK (coff),
2f3508ad 277 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
6812b607 278
075caafd
ILT
279 COFF_SWAP_TABLE,
280};
This page took 0.227279 seconds and 4 git commands to generate.