1 /* BFD back-end for Zilog Z800n COFF binaries.
2 Copyright 1992, 93, 94, 95, 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4 Written by Steve Chamberlain, <sac@cygnus.com>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "coff/internal.h"
30 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
32 static reloc_howto_type r_imm32
=
33 HOWTO (R_IMM32
, 0, 1, 32, false, 0,
34 complain_overflow_bitfield
, 0, "r_imm32", true, 0xffffffff,
37 static reloc_howto_type r_imm4l
=
38 HOWTO (R_IMM4L
, 0, 1, 4, false, 0,
39 complain_overflow_bitfield
, 0, "r_imm4l", true, 0xf, 0xf, false);
41 static reloc_howto_type r_da
=
42 HOWTO (R_IMM16
, 0, 1, 16, false, 0,
43 complain_overflow_bitfield
, 0, "r_da", true, 0x0000ffff, 0x0000ffff,
46 static reloc_howto_type r_imm8
=
47 HOWTO (R_IMM8
, 0, 1, 8, false, 0,
48 complain_overflow_bitfield
, 0, "r_imm8", true, 0x000000ff, 0x000000ff,
51 static reloc_howto_type r_jr
=
52 HOWTO (R_JR
, 0, 1, 8, true, 0, complain_overflow_signed
, 0,
53 "r_jr", true, 0, 0, true);
55 /* Turn a howto into a reloc number */
58 coff_z8k_select_reloc (howto
)
59 reloc_howto_type
*howto
;
64 #define SELECT_RELOC(x,howto) x.r_type = coff_z8k_select_reloc(howto)
67 #define BADMAG(x) Z8KBADMAG(x)
68 #define Z8K 1 /* Customize coffcode.h */
69 #define __A_MAGIC_SET__
73 /* Code to swap in the reloc */
74 #define SWAP_IN_RELOC_OFFSET bfd_h_get_32
75 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
76 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
77 dst->r_stuff[0] = 'S'; \
78 dst->r_stuff[1] = 'C';
80 /* Code to turn a r_type into a howto ptr, uses the above howto table
84 rtype2howto (internal
, dst
)
86 struct internal_reloc
*dst
;
94 internal
->howto
= &r_imm8
;
97 internal
->howto
= &r_da
;
100 internal
->howto
= &r_jr
;
103 internal
->howto
= &r_imm32
;
106 internal
->howto
= &r_imm4l
;
111 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
114 /* Perform any necessary magic to the addend in a reloc entry */
117 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
118 cache_ptr->addend = ext_reloc.r_offset;
121 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
122 reloc_processing(relent, reloc, symbols, abfd, section)
125 reloc_processing (relent
, reloc
, symbols
, abfd
, section
)
127 struct internal_reloc
*reloc
;
132 relent
->address
= reloc
->r_vaddr
;
133 rtype2howto (relent
, reloc
);
135 if (reloc
->r_symndx
> 0)
137 relent
->sym_ptr_ptr
= symbols
+ obj_convert (abfd
)[reloc
->r_symndx
];
141 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
145 relent
->addend
= reloc
->r_offset
;
146 relent
->address
-= section
->vma
;
150 extra_case (in_abfd
, link_info
, link_order
, reloc
, data
, src_ptr
, dst_ptr
)
152 struct bfd_link_info
*link_info
;
153 struct bfd_link_order
*link_order
;
156 unsigned int *src_ptr
;
157 unsigned int *dst_ptr
;
159 asection
*input_section
= link_order
->u
.indirect
.section
;
161 switch (reloc
->howto
->type
)
165 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
173 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
181 ((bfd_get_8 (in_abfd
, data
+ *dst_ptr
) & 0xf0)
183 & bfd_coff_reloc16_get_value (reloc
, link_info
,
192 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
200 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
202 bfd_vma dot
= (link_order
->offset
204 + input_section
->output_section
->vma
);
205 int gap
= dst
- dot
- 1;/* -1 since were in the odd byte of the
206 word and the pc's been incremented */
211 if (gap
> 128 || gap
< -128)
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
)))
219 bfd_put_8 (in_abfd
, gap
, data
+ *dst_ptr
);
229 #define coff_reloc16_extra_cases extra_case
231 #include "coffcode.h"
234 #undef coff_bfd_get_relocated_section_contents
235 #undef coff_bfd_relax_section
236 #define coff_bfd_get_relocated_section_contents \
237 bfd_coff_reloc16_get_relocated_section_contents
238 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
240 const bfd_target z8kcoff_vec
=
242 "coff-z8k", /* name */
243 bfd_target_coff_flavour
,
244 BFD_ENDIAN_BIG
, /* data byte order is big */
245 BFD_ENDIAN_BIG
, /* header byte order is big */
247 (HAS_RELOC
| EXEC_P
| /* object flags */
248 HAS_LINENO
| HAS_DEBUG
|
249 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
251 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
252 '_', /* leading symbol underscore */
253 '/', /* ar_pad_char */
254 15, /* ar_max_namelen */
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 */
262 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
263 bfd_generic_archive_p
, _bfd_dummy_target
},
264 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
266 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
267 _bfd_write_archive_contents
, bfd_false
},
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
),
277 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),