1 /* BFD back-end for Zilog Z800n COFF binaries.
2 Copyright 1992, 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
5 Written by Steve Chamberlain, <sac@cygnus.com>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "coff/internal.h"
31 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
33 static reloc_howto_type r_imm32
=
34 HOWTO (R_IMM32
, 0, 2, 32, FALSE
, 0,
35 complain_overflow_bitfield
, 0, "r_imm32", TRUE
, 0xffffffff,
38 static reloc_howto_type r_imm4l
=
39 HOWTO (R_IMM4L
, 0, 0, 4, FALSE
, 0,
40 complain_overflow_bitfield
, 0, "r_imm4l", TRUE
, 0xf, 0xf, FALSE
);
42 static reloc_howto_type r_da
=
43 HOWTO (R_IMM16
, 0, 1, 16, FALSE
, 0,
44 complain_overflow_bitfield
, 0, "r_da", TRUE
, 0x0000ffff, 0x0000ffff,
47 static reloc_howto_type r_imm8
=
48 HOWTO (R_IMM8
, 0, 0, 8, FALSE
, 0,
49 complain_overflow_bitfield
, 0, "r_imm8", TRUE
, 0x000000ff, 0x000000ff,
52 static reloc_howto_type r_rel16
=
53 HOWTO (R_REL16
, 0, 1, 16, FALSE
, 0,
54 complain_overflow_bitfield
, 0, "r_rel16", TRUE
, 0x0000ffff, 0x0000ffff,
57 static reloc_howto_type r_jr
=
58 HOWTO (R_JR
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, 0,
59 "r_jr", TRUE
, 0, 0, TRUE
);
61 static reloc_howto_type r_disp7
=
62 HOWTO (R_DISP7
, 0, 0, 7, TRUE
, 0, complain_overflow_bitfield
, 0,
63 "r_disp7", TRUE
, 0, 0, TRUE
);
65 static reloc_howto_type r_callr
=
66 HOWTO (R_CALLR
, 0, 1, 12, TRUE
, 0, complain_overflow_signed
, 0,
67 "r_callr", TRUE
, 0xfff, 0xfff, TRUE
);
69 /* Turn a howto into a reloc number */
72 coff_z8k_select_reloc (reloc_howto_type
*howto
)
77 #define SELECT_RELOC(x,howto) x.r_type = coff_z8k_select_reloc(howto)
79 #define BADMAG(x) Z8KBADMAG(x)
80 #define Z8K 1 /* Customize coffcode.h */
81 #define __A_MAGIC_SET__
83 /* Code to swap in the reloc. */
84 #define SWAP_IN_RELOC_OFFSET H_GET_32
85 #define SWAP_OUT_RELOC_OFFSET H_PUT_32
86 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
87 dst->r_stuff[0] = 'S'; \
88 dst->r_stuff[1] = 'C';
90 /* Code to turn a r_type into a howto ptr, uses the above howto table. */
93 rtype2howto (arelent
*internal
, struct internal_reloc
*dst
)
101 internal
->howto
= &r_imm8
;
104 internal
->howto
= &r_da
;
107 internal
->howto
= &r_jr
;
110 internal
->howto
= &r_disp7
;
113 internal
->howto
= &r_callr
;
116 internal
->howto
= &r_rel16
;
119 internal
->howto
= &r_imm32
;
122 internal
->howto
= &r_imm4l
;
127 #define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry)
129 /* Perform any necessary magic to the addend in a reloc entry. */
131 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
132 cache_ptr->addend = ext_reloc.r_offset;
134 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
135 reloc_processing(relent, reloc, symbols, abfd, section)
138 reloc_processing (arelent
*relent
,
139 struct internal_reloc
*reloc
,
144 relent
->address
= reloc
->r_vaddr
;
145 rtype2howto (relent
, reloc
);
147 if (reloc
->r_symndx
> 0)
148 relent
->sym_ptr_ptr
= symbols
+ obj_convert (abfd
)[reloc
->r_symndx
];
150 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
152 relent
->addend
= reloc
->r_offset
;
153 relent
->address
-= section
->vma
;
157 extra_case (bfd
*in_abfd
,
158 struct bfd_link_info
*link_info
,
159 struct bfd_link_order
*link_order
,
162 unsigned int *src_ptr
,
163 unsigned int *dst_ptr
)
165 asection
* input_section
= link_order
->u
.indirect
.section
;
167 switch (reloc
->howto
->type
)
171 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
178 /* If no flags are set, assume immediate value. */
179 if (! (*reloc
->sym_ptr_ptr
)->section
->flags
)
182 bfd_coff_reloc16_get_value (reloc
, link_info
,
188 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
190 /* Addresses are 23 bit, and the layout of those in a 32-bit
192 1AAAAAAA xxxxxxxx AAAAAAAA AAAAAAAA
193 (A - address bits, x - ignore). */
194 dst
= (dst
& 0xffff) | ((dst
& 0xff0000) << 8) | 0x80000000;
195 bfd_put_32 (in_abfd
, dst
, data
+ *dst_ptr
);
203 ((bfd_get_8 (in_abfd
, data
+ *dst_ptr
) & 0xf0)
205 & bfd_coff_reloc16_get_value (reloc
, link_info
,
214 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
222 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
224 bfd_vma dot
= (link_order
->offset
226 + input_section
->output_section
->vma
);
227 int gap
= dst
- dot
- 1; /* -1, since we're in the odd byte of the
228 word and the pc's been incremented. */
233 if (gap
> 128 || gap
< -128)
235 if (! ((*link_info
->callbacks
->reloc_overflow
)
236 (link_info
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
237 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
238 input_section
, reloc
->address
)))
241 bfd_put_8 (in_abfd
, gap
, data
+ *dst_ptr
);
249 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
251 bfd_vma dot
= (link_order
->offset
253 + input_section
->output_section
->vma
);
254 int gap
= dst
- dot
- 1; /* -1, since we're in the odd byte of the
255 word and the pc's been incremented. */
261 if (gap
> 0 || gap
< -127)
263 if (! ((*link_info
->callbacks
->reloc_overflow
)
264 (link_info
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
265 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
266 input_section
, reloc
->address
)))
270 (bfd_get_8 ( in_abfd
, data
+ *dst_ptr
) & 0x80) + (-gap
& 0x7f),
279 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
281 bfd_vma dot
= (link_order
->offset
283 + input_section
->output_section
->vma
);
284 int gap
= dst
- dot
- 2;
288 if (gap
> 4096 || gap
< -4095)
290 if (! ((*link_info
->callbacks
->reloc_overflow
)
291 (link_info
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
292 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
293 input_section
, reloc
->address
)))
298 (bfd_get_16 ( in_abfd
, data
+ *dst_ptr
) & 0xf000) | (-gap
& 0x0fff),
307 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
309 bfd_vma dot
= (link_order
->offset
311 + input_section
->output_section
->vma
);
312 int gap
= dst
- dot
- 2;
314 if (gap
> 32767 || gap
< -32768)
316 if (! ((*link_info
->callbacks
->reloc_overflow
)
317 (link_info
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
318 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
319 input_section
, reloc
->address
)))
322 bfd_put_16 (in_abfd
, (bfd_vma
) gap
, data
+ *dst_ptr
);
333 #define coff_reloc16_extra_cases extra_case
335 #include "coffcode.h"
337 #undef coff_bfd_get_relocated_section_contents
338 #undef coff_bfd_relax_section
339 #define coff_bfd_get_relocated_section_contents \
340 bfd_coff_reloc16_get_relocated_section_contents
341 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
343 CREATE_BIG_COFF_TARGET_VEC (z8kcoff_vec
, "coff-z8k", 0, 0, '_', NULL
, COFF_SWAP_TABLE
)