1 /* BFD back-end for Zilog Z800n COFF binaries.
2 Copyright 1992, 1993, 1994, 1995, 1997, 1999, 2000
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, 1, 32, false, 0,
35 complain_overflow_bitfield
, 0, "r_imm32", true, 0xffffffff,
38 static reloc_howto_type r_imm4l
=
39 HOWTO (R_IMM4L
, 0, 1, 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, 1, 8, false, 0,
49 complain_overflow_bitfield
, 0, "r_imm8", true, 0x000000ff, 0x000000ff,
52 static reloc_howto_type r_jr
=
53 HOWTO (R_JR
, 0, 1, 8, true, 0, complain_overflow_signed
, 0,
54 "r_jr", true, 0, 0, true);
56 /* Turn a howto into a reloc number */
59 coff_z8k_select_reloc (howto
)
60 reloc_howto_type
*howto
;
65 #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__
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';
78 /* Code to turn a r_type into a howto ptr, uses the above howto table
82 rtype2howto (internal
, dst
)
84 struct internal_reloc
*dst
;
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)
111 /* Perform any necessary magic to the addend in a reloc entry */
113 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
114 cache_ptr->addend = ext_reloc.r_offset;
116 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
117 reloc_processing(relent, reloc, symbols, abfd, section)
120 reloc_processing (relent
, reloc
, symbols
, abfd
, section
)
122 struct internal_reloc
*reloc
;
127 relent
->address
= reloc
->r_vaddr
;
128 rtype2howto (relent
, reloc
);
130 if (reloc
->r_symndx
> 0)
132 relent
->sym_ptr_ptr
= symbols
+ obj_convert (abfd
)[reloc
->r_symndx
];
136 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
139 relent
->addend
= reloc
->r_offset
;
140 relent
->address
-= section
->vma
;
144 extra_case (in_abfd
, link_info
, link_order
, reloc
, data
, src_ptr
, dst_ptr
)
146 struct bfd_link_info
*link_info
;
147 struct bfd_link_order
*link_order
;
150 unsigned int *src_ptr
;
151 unsigned int *dst_ptr
;
153 asection
*input_section
= link_order
->u
.indirect
.section
;
155 switch (reloc
->howto
->type
)
159 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
167 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
175 ((bfd_get_8 (in_abfd
, data
+ *dst_ptr
) & 0xf0)
177 & bfd_coff_reloc16_get_value (reloc
, link_info
,
186 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
194 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
196 bfd_vma dot
= (link_order
->offset
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 */
205 if (gap
> 128 || gap
< -128)
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
)))
213 bfd_put_8 (in_abfd
, gap
, data
+ *dst_ptr
);
223 #define coff_reloc16_extra_cases extra_case
225 #include "coffcode.h"
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
233 CREATE_BIG_COFF_TARGET_VEC (z8kcoff_vec
, "coff-z8k", 0, 0, '_', NULL
)