864b51e177de8326ce446838416e75c41f0bbc4a
[binutils-gdb.git] / bfd / coff-z8k.c
1 /* Zilog Z800n COFF back-end for BFD.
2 Copyright (C) 1992 Free Software Foundation, Inc.
3 Written by Steve Chamberlain
4 sac@cygnus.com
5
6 This file is part of BFD, the Binary File Descriptor library.
7
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.
12
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.
17
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. */
21
22
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libbfd.h"
26 #include "obstack.h"
27 #include "coff/z8k.h"
28 #include "coff/internal.h"
29 #include "libcoff.h"
30 #include "seclet.h"
31
32 extern bfd_error_vector_type bfd_error_vector;
33
34 /* Dummy for now */
35 static bfd_reloc_status_type
36 DEFUN(func_da, (abfd, reloc_entry, symbol, data, input_section, output_bfd),
37 bfd *abfd AND
38 arelent *reloc_entry AND
39 struct symbol_cache_entry *symbol AND
40 PTR data AND
41 asection *input_section AND
42 bfd *output_bfd)
43 {
44 }
45
46 /* Dummy for now */
47 static bfd_reloc_status_type
48 DEFUN(func_jr, (abfd, reloc_entry, symbol, data, input_section, output_bfd),
49 bfd *abfd AND
50 arelent *reloc_entry AND
51 struct symbol_cache_entry *symbol AND
52 PTR data AND
53 asection *input_section AND
54 bfd *output_bfd)
55 {
56 }
57
58 static reloc_howto_type r_da =
59 HOWTO(R_DA , 0, 1, 16, false, 0, true,
60 true,func_da,"r_da", true, 0x0000ffff,0x0000ffff, false);
61
62 static reloc_howto_type r_jr =
63 HOWTO(R_JR, 0,1,8,true,0,true,true,func_jr,"r_jr", true,0,0,true);
64
65
66
67
68
69 /* Turn a howto into a reloc number */
70
71 static int coff_z8k_select_reloc(howto)
72 reloc_howto_type *howto;
73 {
74 return howto->type;
75 }
76 #define SELECT_RELOC(x,howto) x= coff_z8k_select_reloc(howto)
77
78
79 #define BADMAG(x) Z8KBADMAG(x)
80 #define Z8K 1 /* Customize coffcode.h */
81 #define __A_MAGIC_SET__
82
83
84
85 /* Code to swap in the reloc */
86 #define SWAP_IN_RELOC_OFFSET bfd_h_get_32
87 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
88 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
89 dst->r_stuff[0] = 'S'; \
90 dst->r_stuff[1] = 'C';
91
92 /* Code to turn a r_type into a howto ptr, uses the above howto table
93 */
94
95 static void
96 DEFUN(rtype2howto,(internal, dst),
97 arelent *internal AND
98 struct internal_reloc *dst)
99 {
100 switch (dst->r_type) {
101 default:
102 printf("BAD %x\n", dst->r_type);
103 case R_DA:
104 internal->howto = &r_da;
105 break;
106 case R_JR:
107 internal->howto = &r_jr;
108 }
109 }
110
111 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
112
113
114 /* Perform any necessaru magic to the addend in a reloc entry */
115
116
117 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
118 cache_ptr->addend = ext_reloc.r_offset;
119
120
121 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
122 reloc_processing(relent, reloc, symbols, abfd, section)
123
124 static void DEFUN(reloc_processing,(relent,reloc, symbols, abfd, section) ,
125 arelent *relent AND
126 struct internal_reloc *reloc AND
127 asymbol **symbols AND
128 bfd *abfd AND
129 asection *section)
130 {
131 relent->address = reloc->r_vaddr;
132 rtype2howto(relent,reloc);
133
134 if (reloc->r_symndx > 0)
135 {
136
137 relent->sym_ptr_ptr = symbols + obj_convert(abfd)[reloc->r_symndx];
138
139 }
140 else
141 {
142 relent->sym_ptr_ptr = &(bfd_abs_symbol);
143 }
144
145
146
147 relent->addend = reloc->r_offset;
148
149 relent->address-= section->vma;
150 /* relent->section = 0;*/
151 }
152
153 static bfd_vma get_value();
154
155 static void
156 extra_case(in_abfd, seclet, reloc, data, src_ptr, dst_ptr)
157 bfd *in_abfd;
158 bfd_seclet_type *seclet;
159 arelent *reloc;
160 bfd_byte *data;
161 unsigned int *src_ptr;
162 unsigned int *dst_ptr;
163 {
164 switch (reloc->howto->type)
165 {
166 case R_DA:
167 bfd_put_16(in_abfd, get_value(reloc, seclet), data+*dst_ptr);
168 (*dst_ptr)+=2;
169 ( *src_ptr)+=2;
170 break;
171 case R_JR:
172 {
173 bfd_vma dst = get_value(reloc,seclet);
174 bfd_vma dot = seclet->offset
175 + *dst_ptr
176 + seclet->u.indirect.section->output_section->vma;
177 int gap = dst - dot - 1 ; /* -1 since were in the odd byte of the
178 word */
179 if (gap & 1)
180 abort();
181 gap/=2;
182 if (gap > 128 || gap< -128)
183 {
184 bfd_error_vector.reloc_value_truncated(reloc, seclet);
185 }
186 bfd_put_8(in_abfd, gap, data+*dst_ptr);
187 (*dst_ptr)++;
188 (*src_ptr)++;
189 break;
190 }
191 default:
192 abort();
193 }
194 }
195 #define EXTRA_CASES default: extra_case(in_abfd,seclet,reloc, data, &src_address, &dst_address);
196
197
198
199
200 #include "coffcode.h"
201
202
203 #undef coff_bfd_get_relocated_section_contents
204 #undef coff_bfd_relax_section
205 #define coff_bfd_get_relocated_section_contents bfd_coff_get_relocated_section_contents
206 #define coff_bfd_relax_section bfd_coff_relax_section
207
208 bfd_target z8kcoff_vec =
209 {
210 "coff-z8k", /* name */
211 bfd_target_coff_flavour,
212 true, /* data byte order is big */
213 true, /* header byte order is big */
214
215 (HAS_RELOC | EXEC_P | /* object flags */
216 HAS_LINENO | HAS_DEBUG |
217 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
218
219 ( SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
220 '_', /* leading symbol underscore */
221 '/', /* ar_pad_char */
222 15, /* ar_max_namelen */
223 1, /* minimum section alignment */
224 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
225 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
226
227 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
228 bfd_generic_archive_p, _bfd_dummy_target},
229 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
230 bfd_false},
231 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
232 _bfd_write_archive_contents, bfd_false},
233
234 JUMP_TABLE(coff),
235 COFF_SWAP_TABLE
236 };