Add OpenRISC support
[deliverable/binutils-gdb.git] / bfd / coff-z8k.c
CommitLineData
252b5132 1/* BFD back-end for Zilog Z800n COFF binaries.
7898deda
NC
2 Copyright 1992, 1993, 1994, 1995, 1997, 1999, 2000
3 Free Software Foundation, Inc.
252b5132
RH
4 Contributed by Cygnus Support.
5 Written by Steve Chamberlain, <sac@cygnus.com>.
6
7This file is part of BFD, the Binary File Descriptor library.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23#include "bfd.h"
24#include "sysdep.h"
25#include "libbfd.h"
26#include "bfdlink.h"
27#include "coff/z8k.h"
28#include "coff/internal.h"
29#include "libcoff.h"
30
31#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
32
33static reloc_howto_type r_imm32 =
34HOWTO (R_IMM32, 0, 1, 32, false, 0,
35 complain_overflow_bitfield, 0, "r_imm32", true, 0xffffffff,
36 0xffffffff, false);
37
38static reloc_howto_type r_imm4l =
39HOWTO (R_IMM4L, 0, 1, 4, false, 0,
40 complain_overflow_bitfield, 0, "r_imm4l", true, 0xf, 0xf, false);
41
42static reloc_howto_type r_da =
43HOWTO (R_IMM16, 0, 1, 16, false, 0,
44 complain_overflow_bitfield, 0, "r_da", true, 0x0000ffff, 0x0000ffff,
45 false);
46
47static reloc_howto_type r_imm8 =
48HOWTO (R_IMM8, 0, 1, 8, false, 0,
49 complain_overflow_bitfield, 0, "r_imm8", true, 0x000000ff, 0x000000ff,
50 false);
51
52static reloc_howto_type r_jr =
53HOWTO (R_JR, 0, 1, 8, true, 0, complain_overflow_signed, 0,
54 "r_jr", true, 0, 0, true);
55
56/* Turn a howto into a reloc number */
57
cbfe05c4 58static int
252b5132
RH
59coff_z8k_select_reloc (howto)
60 reloc_howto_type *howto;
61{
62 return howto->type;
63}
64
65#define SELECT_RELOC(x,howto) x.r_type = coff_z8k_select_reloc(howto)
66
252b5132
RH
67#define BADMAG(x) Z8KBADMAG(x)
68#define Z8K 1 /* Customize coffcode.h */
69#define __A_MAGIC_SET__
70
252b5132
RH
71/* Code to swap in the reloc */
72#define SWAP_IN_RELOC_OFFSET bfd_h_get_32
73#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
74#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
75 dst->r_stuff[0] = 'S'; \
76 dst->r_stuff[1] = 'C';
77
78/* Code to turn a r_type into a howto ptr, uses the above howto table
79 */
80
81static void
82rtype2howto (internal, dst)
83 arelent * internal;
84 struct internal_reloc *dst;
85{
86 switch (dst->r_type)
87 {
88 default:
89 abort ();
90 break;
91 case R_IMM8:
92 internal->howto = &r_imm8;
93 break;
94 case R_IMM16:
95 internal->howto = &r_da;
96 break;
97 case R_JR:
98 internal->howto = &r_jr;
99 break;
100 case R_IMM32:
101 internal->howto = &r_imm32;
102 break;
103 case R_IMM4L:
104 internal->howto = &r_imm4l;
105 break;
106 }
107}
108
109#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
110
252b5132
RH
111/* Perform any necessary magic to the addend in a reloc entry */
112
252b5132
RH
113#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
114 cache_ptr->addend = ext_reloc.r_offset;
115
252b5132
RH
116#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
117 reloc_processing(relent, reloc, symbols, abfd, section)
118
cbfe05c4 119static void
252b5132
RH
120reloc_processing (relent, reloc, symbols, abfd, section)
121 arelent * relent;
122 struct internal_reloc *reloc;
123 asymbol ** symbols;
124 bfd * abfd;
125 asection * section;
126{
127 relent->address = reloc->r_vaddr;
128 rtype2howto (relent, reloc);
129
130 if (reloc->r_symndx > 0)
131 {
132 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
133 }
134 else
135 {
136 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
137 }
138
252b5132
RH
139 relent->addend = reloc->r_offset;
140 relent->address -= section->vma;
141}
142
143static void
144extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
145 bfd *in_abfd;
146 struct bfd_link_info *link_info;
147 struct bfd_link_order *link_order;
148 arelent *reloc;
149 bfd_byte *data;
150 unsigned int *src_ptr;
151 unsigned int *dst_ptr;
152{
153 asection *input_section = link_order->u.indirect.section;
154
155 switch (reloc->howto->type)
156 {
157 case R_IMM8:
158 bfd_put_8 (in_abfd,
159 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
160 data + *dst_ptr);
161 (*dst_ptr) += 1;
162 (*src_ptr) += 1;
163 break;
164
165 case R_IMM32:
166 bfd_put_32 (in_abfd,
167 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
168 data + *dst_ptr);
169 (*dst_ptr) += 4;
170 (*src_ptr) += 4;
171 break;
172
173 case R_IMM4L:
174 bfd_put_8 (in_abfd,
cbfe05c4 175 ((bfd_get_8 (in_abfd, data + *dst_ptr) & 0xf0)
252b5132
RH
176 | (0x0f
177 & bfd_coff_reloc16_get_value (reloc, link_info,
178 input_section))),
179 data + *dst_ptr);
180 (*dst_ptr) += 1;
181 (*src_ptr) += 1;
182 break;
183
184 case R_IMM16:
185 bfd_put_16 (in_abfd,
186 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
187 data + *dst_ptr);
188 (*dst_ptr) += 2;
189 (*src_ptr) += 2;
190 break;
191
192 case R_JR:
193 {
194 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
195 input_section);
196 bfd_vma dot = (link_order->offset
197 + *dst_ptr
198 + input_section->output_section->vma);
199 int gap = dst - dot - 1;/* -1 since were in the odd byte of the
200 word and the pc's been incremented */
201
202 if (gap & 1)
203 abort ();
204 gap /= 2;
205 if (gap > 128 || gap < -128)
206 {
207 if (! ((*link_info->callbacks->reloc_overflow)
208 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
209 reloc->howto->name, reloc->addend, input_section->owner,
210 input_section, reloc->address)))
211 abort ();
212 }
213 bfd_put_8 (in_abfd, gap, data + *dst_ptr);
214 (*dst_ptr)++;
215 (*src_ptr)++;
216 break;
217 }
218 default:
219 abort ();
220 }
221}
222
223#define coff_reloc16_extra_cases extra_case
224
225#include "coffcode.h"
226
252b5132
RH
227#undef coff_bfd_get_relocated_section_contents
228#undef coff_bfd_relax_section
229#define coff_bfd_get_relocated_section_contents \
230 bfd_coff_reloc16_get_relocated_section_contents
231#define coff_bfd_relax_section bfd_coff_reloc16_relax_section
232
c3c89269 233CREATE_BIG_COFF_TARGET_VEC (z8kcoff_vec, "coff-z8k", 0, 0, '_', NULL)
This page took 0.078568 seconds and 4 git commands to generate.