1 /* BFD back-end for Zilog Z800n COFF binaries.
2 Copyright 1992, 1993, 1994 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #include "coff/internal.h"
31 static reloc_howto_type r_imm32
=
32 HOWTO (R_IMM32
, 0, 1, 32, false, 0,
33 complain_overflow_bitfield
, 0, "r_imm32", true, 0xffffffff,
36 static reloc_howto_type r_imm4l
=
37 HOWTO (R_IMM4L
, 0, 1, 4, false, 0,
38 complain_overflow_bitfield
, 0, "r_imm4l", true, 0xf, 0xf, false);
40 static reloc_howto_type r_da
=
41 HOWTO (R_IMM16
, 0, 1, 16, false, 0,
42 complain_overflow_bitfield
, 0, "r_da", true, 0x0000ffff, 0x0000ffff,
45 static reloc_howto_type r_imm8
=
46 HOWTO (R_IMM8
, 0, 1, 8, false, 0,
47 complain_overflow_bitfield
, 0, "r_imm8", true, 0x000000ff, 0x000000ff,
50 static reloc_howto_type r_jr
=
51 HOWTO (R_JR
, 0, 1, 8, true, 0, complain_overflow_signed
, 0,
52 "r_jr", true, 0, 0, true);
54 /* Turn a howto into a reloc number */
57 coff_z8k_select_reloc (howto
)
58 reloc_howto_type
*howto
;
63 #define SELECT_RELOC(x,howto) x.r_type = coff_z8k_select_reloc(howto)
66 #define BADMAG(x) Z8KBADMAG(x)
67 #define Z8K 1 /* Customize coffcode.h */
68 #define __A_MAGIC_SET__
72 /* Code to swap in the reloc */
73 #define SWAP_IN_RELOC_OFFSET bfd_h_get_32
74 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
75 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
76 dst->r_stuff[0] = 'S'; \
77 dst->r_stuff[1] = 'C';
79 /* Code to turn a r_type into a howto ptr, uses the above howto table
83 rtype2howto (internal
, dst
)
85 struct internal_reloc
*dst
;
90 fprintf (stderr
, "BAD 0x%x\n", dst
->r_type
);
92 internal
->howto
= &r_imm8
;
95 internal
->howto
= &r_da
;
98 internal
->howto
= &r_jr
;
101 internal
->howto
= &r_imm32
;
104 internal
->howto
= &r_imm4l
;
109 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
112 /* Perform any necessaru magic to the addend in a reloc entry */
115 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
116 cache_ptr->addend = ext_reloc.r_offset;
119 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
120 reloc_processing(relent, reloc, symbols, abfd, section)
123 reloc_processing (relent
, reloc
, symbols
, abfd
, section
)
125 struct internal_reloc
*reloc
;
130 relent
->address
= reloc
->r_vaddr
;
131 rtype2howto (relent
, reloc
);
133 if (reloc
->r_symndx
> 0)
135 relent
->sym_ptr_ptr
= symbols
+ obj_convert (abfd
)[reloc
->r_symndx
];
139 relent
->sym_ptr_ptr
= &(bfd_abs_symbol
);
143 relent
->addend
= reloc
->r_offset
;
144 relent
->address
-= section
->vma
;
148 extra_case (in_abfd
, link_info
, link_order
, reloc
, data
, src_ptr
, dst_ptr
)
150 struct bfd_link_info
*link_info
;
151 struct bfd_link_order
*link_order
;
154 unsigned int *src_ptr
;
155 unsigned int *dst_ptr
;
157 asection
*input_section
= link_order
->u
.indirect
.section
;
159 switch (reloc
->howto
->type
)
163 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
171 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
179 ((bfd_get_8 (in_abfd
, data
+ *dst_ptr
) & 0xf0)
181 & bfd_coff_reloc16_get_value (reloc
, link_info
,
190 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
198 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
200 bfd_vma dot
= (link_order
->offset
202 + input_section
->output_section
->vma
);
203 int gap
= dst
- dot
- 1;/* -1 since were in the odd byte of the
204 word and the pc's been incremented */
209 if (gap
> 128 || gap
< -128)
211 if (! ((*link_info
->callbacks
->reloc_overflow
)
212 (link_info
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
213 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
214 input_section
, reloc
->address
)))
217 bfd_put_8 (in_abfd
, gap
, data
+ *dst_ptr
);
227 #define coff_reloc16_extra_cases extra_case
229 #include "coffcode.h"
232 #undef coff_bfd_get_relocated_section_contents
233 #undef coff_bfd_relax_section
234 #define coff_bfd_get_relocated_section_contents \
235 bfd_coff_reloc16_get_relocated_section_contents
236 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
238 const bfd_target z8kcoff_vec
=
240 "coff-z8k", /* name */
241 bfd_target_coff_flavour
,
242 true, /* data byte order is big */
243 true, /* header byte order is big */
245 (HAS_RELOC
| EXEC_P
| /* object flags */
246 HAS_LINENO
| HAS_DEBUG
|
247 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
249 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
250 '_', /* leading symbol underscore */
251 '/', /* ar_pad_char */
252 15, /* ar_max_namelen */
253 1, /* minimum section alignment */
254 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
255 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
256 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
257 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
258 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
259 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
261 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
262 bfd_generic_archive_p
, _bfd_dummy_target
},
263 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
265 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
266 _bfd_write_archive_contents
, bfd_false
},
268 BFD_JUMP_TABLE_GENERIC (coff
),
269 BFD_JUMP_TABLE_COPY (coff
),
270 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
271 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
272 BFD_JUMP_TABLE_SYMBOLS (coff
),
273 BFD_JUMP_TABLE_RELOCS (coff
),
274 BFD_JUMP_TABLE_WRITE (coff
),
275 BFD_JUMP_TABLE_LINK (coff
),
276 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),