Keep m68klynx.c
[deliverable/binutils-gdb.git] / bfd / coff-z8k.c
CommitLineData
075caafd
ILT
1/* BFD back-end for Zilog Z800n COFF binaries.
2 Copyright 1992 Free Software Foundation, Inc.
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
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
8ad2a31d
SC
22#include "bfd.h"
23#include "sysdep.h"
24#include "libbfd.h"
25#include "obstack.h"
26#include "coff/z8k.h"
27#include "coff/internal.h"
28#include "libcoff.h"
29#include "seclet.h"
294eaca4 30
8ad2a31d 31extern bfd_error_vector_type bfd_error_vector;
294eaca4
SC
32
33/* Dummy for now */
34static bfd_reloc_status_type
075caafd
ILT
35DEFUN (func_da, (abfd, reloc_entry, symbol, data, input_section, output_bfd),
36 bfd * abfd AND
37 arelent * reloc_entry AND
38 struct symbol_cache_entry *symbol AND
39 PTR data AND
40 asection * input_section AND
41 bfd * output_bfd)
294eaca4
SC
42{
43}
44
45/* Dummy for now */
46static bfd_reloc_status_type
075caafd
ILT
47DEFUN (func_imm8, (abfd, reloc_entry, symbol, data, input_section, output_bfd),
48 bfd * abfd AND
49 arelent * reloc_entry AND
50 struct symbol_cache_entry *symbol AND
51 PTR data AND
52 asection * input_section AND
53 bfd * output_bfd)
294eaca4
SC
54{
55}
8ad2a31d 56
075caafd
ILT
57/* Dummy for now */
58static bfd_reloc_status_type
59DEFUN (func_jr, (abfd, reloc_entry, symbol, data, input_section, output_bfd),
60 bfd * abfd AND
61 arelent * reloc_entry AND
62 struct symbol_cache_entry *symbol AND
63 PTR data AND
64 asection * input_section AND
65 bfd * output_bfd)
66{
67}
8ad2a31d 68
8ad2a31d 69
075caafd
ILT
70static reloc_howto_type r_imm32 =
71HOWTO (R_IMM32, 0, 1, 32, false, 0, true,
72 true, func_jr, "r_imm32", true, 0xffffffff, 0xffffffff, false);
8ad2a31d 73
075caafd
ILT
74static reloc_howto_type r_imm4l =
75HOWTO (R_IMM4L, 0, 1, 4, false, 0, true,
76 true, func_jr, "r_imm4l", true, 0xf, 0xf, false);
8ad2a31d 77
075caafd
ILT
78static reloc_howto_type r_da =
79HOWTO (R_DA, 0, 1, 16, false, 0, true,
80 true, func_da, "r_da", true, 0x0000ffff, 0x0000ffff, false);
81
82static reloc_howto_type r_imm8 =
83HOWTO (R_IMM8, 0, 1, 8, false, 0, true,
84 true, func_imm8, "r_imm8", true, 0x000000ff, 0x000000ff, false);
8ad2a31d 85
075caafd
ILT
86static reloc_howto_type r_jr =
87HOWTO (R_JR, 0, 1, 8, true, 0, true, true, func_jr, "r_jr", true, 0, 0, true);
8ad2a31d
SC
88
89/* Turn a howto into a reloc number */
90
075caafd
ILT
91static int
92coff_z8k_select_reloc (howto)
93 reloc_howto_type *howto;
8ad2a31d 94{
075caafd 95 return howto->type;
8ad2a31d 96}
075caafd 97
8ad2a31d
SC
98#define SELECT_RELOC(x,howto) x= coff_z8k_select_reloc(howto)
99
100
101#define BADMAG(x) Z8KBADMAG(x)
075caafd 102#define Z8K 1 /* Customize coffcode.h */
8ad2a31d
SC
103#define __A_MAGIC_SET__
104
105
106
107/* Code to swap in the reloc */
108#define SWAP_IN_RELOC_OFFSET bfd_h_get_32
109#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
110#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
111 dst->r_stuff[0] = 'S'; \
075caafd 112 dst->r_stuff[1] = 'C';
8ad2a31d
SC
113
114/* Code to turn a r_type into a howto ptr, uses the above howto table
115 */
116
075caafd
ILT
117static void
118DEFUN (rtype2howto, (internal, dst),
119 arelent * internal AND
120 struct internal_reloc *dst)
8ad2a31d 121{
075caafd
ILT
122 switch (dst->r_type)
123 {
124 default:
125 printf ("BAD %x\n", dst->r_type);
126 case R_IMM8:
127 internal->howto = &r_imm8;
128 break;
129 case R_DA:
130 internal->howto = &r_da;
131 break;
132 case R_JR:
133 internal->howto = &r_jr;
134 break;
135 case R_IMM32:
136 internal->howto = &r_imm32;
137 break;
138 case R_IMM4L:
139 internal->howto = &r_imm4l;
140 break;
8ad2a31d
SC
141 }
142}
143
144#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
145
146
147/* Perform any necessaru magic to the addend in a reloc entry */
148
149
150#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
151 cache_ptr->addend = ext_reloc.r_offset;
152
075caafd 153
8ad2a31d
SC
154#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
155 reloc_processing(relent, reloc, symbols, abfd, section)
156
075caafd
ILT
157static void
158DEFUN (reloc_processing, (relent, reloc, symbols, abfd, section),
159 arelent * relent AND
160 struct internal_reloc *reloc AND
161 asymbol ** symbols AND
162 bfd * abfd AND
163 asection * section)
8ad2a31d 164{
075caafd
ILT
165 relent->address = reloc->r_vaddr;
166 rtype2howto (relent, reloc);
167
168 if (reloc->r_symndx > 0)
169 {
170 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
171 }
172 else
173 {
174 relent->sym_ptr_ptr = &(bfd_abs_symbol);
175 }
176
177
8ad2a31d 178 relent->addend = reloc->r_offset;
075caafd 179 relent->address -= section->vma;
8ad2a31d
SC
180}
181
5f9ca960 182static void
075caafd 183extra_case (in_abfd, seclet, reloc, data, src_ptr, dst_ptr)
5f9ca960
JG
184 bfd *in_abfd;
185 bfd_seclet_type *seclet;
186 arelent *reloc;
187 bfd_byte *data;
188 unsigned int *src_ptr;
189 unsigned int *dst_ptr;
8ad2a31d 190{
075caafd
ILT
191 switch (reloc->howto->type)
192 {
193 case R_IMM8:
194 bfd_put_8 (in_abfd, bfd_coff_reloc16_get_value (reloc, seclet),
195 data + *dst_ptr);
196 (*dst_ptr) += 1;
197 (*src_ptr) += 1;
198 break;
199
200 case R_IMM32:
201 bfd_put_32 (in_abfd, bfd_coff_reloc16_get_value (reloc, seclet),
202 data + *dst_ptr);
203 (*dst_ptr) += 4;
204 (*src_ptr) += 4;
205 break;
206
207 case R_IMM4L:
208 bfd_put_8 (in_abfd,
209 (bfd_get_8 (in_abfd, data + *dst_ptr) & 0xf0)
210 | (0x0f & bfd_coff_reloc16_get_value (reloc, seclet)),
211 data + *dst_ptr);
212 (*dst_ptr) += 1;
213 (*src_ptr) += 1;
214 break;
215
216 case R_DA:
217 bfd_put_16 (in_abfd, bfd_coff_reloc16_get_value (reloc, seclet),
218 data + *dst_ptr);
219 (*dst_ptr) += 2;
220 (*src_ptr) += 2;
221 break;
222
223 case R_JR:
224 {
225 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, seclet);
226 bfd_vma dot = seclet->offset
227 + *dst_ptr
228 + seclet->u.indirect.section->output_section->vma;
229 int gap = dst - dot - 1;/* -1 since were in the odd byte of the
230 word and the pc's been incremented */
231
232 if (gap & 1)
233 abort ();
234 gap /= 2;
235 if (gap > 128 || gap < -128)
236 {
237 bfd_error_vector.reloc_value_truncated (reloc, seclet);
238 }
239 bfd_put_8 (in_abfd, gap, data + *dst_ptr);
240 (*dst_ptr)++;
241 (*src_ptr)++;
242 break;
243 }
244 default:
245 abort ();
246 }
8ad2a31d 247}
8ad2a31d 248
075caafd 249#define coff_reloc16_extra_cases extra_case
8ad2a31d
SC
250
251#include "coffcode.h"
252
253
075caafd 254#undef coff_bfd_get_relocated_section_contents
8ad2a31d 255#undef coff_bfd_relax_section
075caafd
ILT
256#define coff_bfd_get_relocated_section_contents bfd_coff_reloc16_get_relocated_section_contents
257#define coff_bfd_relax_section bfd_coff_reloc16_relax_section
8ad2a31d
SC
258
259bfd_target z8kcoff_vec =
260{
294eaca4 261 "coff-z8k", /* name */
8ad2a31d
SC
262 bfd_target_coff_flavour,
263 true, /* data byte order is big */
264 true, /* header byte order is big */
265
266 (HAS_RELOC | EXEC_P | /* object flags */
267 HAS_LINENO | HAS_DEBUG |
268 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
269
075caafd 270 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
294eaca4 271 '_', /* leading symbol underscore */
8ad2a31d
SC
272 '/', /* ar_pad_char */
273 15, /* ar_max_namelen */
274 1, /* minimum section alignment */
075caafd
ILT
275 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
276 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
294eaca4 277
075caafd 278 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
294eaca4 279 bfd_generic_archive_p, _bfd_dummy_target},
075caafd 280 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
294eaca4 281 bfd_false},
075caafd 282 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
294eaca4
SC
283 _bfd_write_archive_contents, bfd_false},
284
075caafd
ILT
285 JUMP_TABLE (coff),
286 0, 0,
287 COFF_SWAP_TABLE,
288};
This page took 0.063794 seconds and 4 git commands to generate.