]>
Commit | Line | Data |
---|---|---|
fbffaf55 ILT |
1 | /* Generic ECOFF swapping routines, for BFD. |
2 | Copyright 1992, 1993 Free Software Foundation, Inc. | |
3 | Written by Cygnus Support. | |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* NOTE: This is a header file, but it contains executable routines. | |
22 | This is done this way because these routines are substantially | |
23 | similar, but are not identical, for all ECOFF targets. | |
24 | ||
25 | These are routines to swap the ECOFF symbolic information in and | |
26 | out. The routines are defined statically. You can set breakpoints | |
27 | on them in gdb by naming the including source file; e.g., | |
28 | 'coff-mips.c':ecoff_swap_hdr_in. | |
29 | ||
30 | Before including this header file, one of ECOFF_32 or ECOFF_64 must | |
31 | be defined. These are checked when swapping information that | |
32 | depends upon the target size. This code works for 32 bit and 64 | |
33 | bit ECOFF, but may need to be generalized in the future. | |
34 | ||
35 | Some header file which defines the external forms of these | |
36 | structures must also be included before including this header file. | |
37 | Currently this is either coff/mips.h or coff/alpha.h. | |
38 | ||
39 | If the symbol TEST is defined when this file is compiled, a | |
40 | comparison is made to ensure that, in fact, the output is | |
41 | bit-for-bit the same as the input. Of course, this symbol should | |
42 | only be defined when deliberately testing the code on a machine | |
43 | with the proper byte sex and such. */ | |
44 | ||
45 | #ifdef ECOFF_32 | |
46 | #define ecoff_get_off bfd_h_get_32 | |
47 | #define ecoff_put_off bfd_h_put_32 | |
48 | #endif | |
49 | #ifdef ECOFF_64 | |
50 | #define ecoff_get_off bfd_h_get_64 | |
51 | #define ecoff_put_off bfd_h_put_64 | |
52 | #endif | |
53 | ||
54 | /* Swap in the symbolic header. */ | |
55 | ||
56 | static void | |
57 | ecoff_swap_hdr_in (abfd, ext_copy, intern) | |
58 | bfd *abfd; | |
59 | PTR ext_copy; | |
60 | HDRR *intern; | |
61 | { | |
62 | struct hdr_ext ext[1]; | |
63 | ||
64 | *ext = *(struct hdr_ext *) ext_copy; | |
65 | ||
66 | intern->magic = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_magic); | |
67 | intern->vstamp = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_vstamp); | |
68 | intern->ilineMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ilineMax); | |
69 | intern->cbLine = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLine); | |
70 | intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLineOffset); | |
71 | intern->idnMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_idnMax); | |
72 | intern->cbDnOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbDnOffset); | |
73 | intern->ipdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ipdMax); | |
74 | intern->cbPdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbPdOffset); | |
75 | intern->isymMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_isymMax); | |
76 | intern->cbSymOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSymOffset); | |
77 | intern->ioptMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ioptMax); | |
78 | intern->cbOptOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbOptOffset); | |
79 | intern->iauxMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iauxMax); | |
80 | intern->cbAuxOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbAuxOffset); | |
81 | intern->issMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issMax); | |
82 | intern->cbSsOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsOffset); | |
83 | intern->issExtMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issExtMax); | |
84 | intern->cbSsExtOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsExtOffset); | |
85 | intern->ifdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ifdMax); | |
86 | intern->cbFdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbFdOffset); | |
87 | intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_crfd); | |
88 | intern->cbRfdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbRfdOffset); | |
89 | intern->iextMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iextMax); | |
90 | intern->cbExtOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbExtOffset); | |
91 | ||
92 | #ifdef TEST | |
93 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
94 | abort(); | |
95 | #endif | |
96 | } | |
97 | ||
98 | /* Swap out the symbolic header. */ | |
99 | ||
100 | static void | |
101 | ecoff_swap_hdr_out (abfd, intern_copy, ext_ptr) | |
102 | bfd *abfd; | |
103 | const HDRR *intern_copy; | |
104 | PTR ext_ptr; | |
105 | { | |
106 | struct hdr_ext *ext = (struct hdr_ext *) ext_ptr; | |
107 | HDRR intern[1]; | |
108 | ||
109 | *intern = *intern_copy; | |
110 | ||
111 | bfd_h_put_signed_16 (abfd, intern->magic, (bfd_byte *)ext->h_magic); | |
112 | bfd_h_put_signed_16 (abfd, intern->vstamp, (bfd_byte *)ext->h_vstamp); | |
113 | bfd_h_put_32 (abfd, intern->ilineMax, (bfd_byte *)ext->h_ilineMax); | |
114 | ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->h_cbLine); | |
115 | ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->h_cbLineOffset); | |
116 | bfd_h_put_32 (abfd, intern->idnMax, (bfd_byte *)ext->h_idnMax); | |
117 | ecoff_put_off (abfd, intern->cbDnOffset, (bfd_byte *)ext->h_cbDnOffset); | |
118 | bfd_h_put_32 (abfd, intern->ipdMax, (bfd_byte *)ext->h_ipdMax); | |
119 | ecoff_put_off (abfd, intern->cbPdOffset, (bfd_byte *)ext->h_cbPdOffset); | |
120 | bfd_h_put_32 (abfd, intern->isymMax, (bfd_byte *)ext->h_isymMax); | |
121 | ecoff_put_off (abfd, intern->cbSymOffset, (bfd_byte *)ext->h_cbSymOffset); | |
122 | bfd_h_put_32 (abfd, intern->ioptMax, (bfd_byte *)ext->h_ioptMax); | |
123 | ecoff_put_off (abfd, intern->cbOptOffset, (bfd_byte *)ext->h_cbOptOffset); | |
124 | bfd_h_put_32 (abfd, intern->iauxMax, (bfd_byte *)ext->h_iauxMax); | |
125 | ecoff_put_off (abfd, intern->cbAuxOffset, (bfd_byte *)ext->h_cbAuxOffset); | |
126 | bfd_h_put_32 (abfd, intern->issMax, (bfd_byte *)ext->h_issMax); | |
127 | ecoff_put_off (abfd, intern->cbSsOffset, (bfd_byte *)ext->h_cbSsOffset); | |
128 | bfd_h_put_32 (abfd, intern->issExtMax, (bfd_byte *)ext->h_issExtMax); | |
129 | ecoff_put_off (abfd, intern->cbSsExtOffset, (bfd_byte *)ext->h_cbSsExtOffset); | |
130 | bfd_h_put_32 (abfd, intern->ifdMax, (bfd_byte *)ext->h_ifdMax); | |
131 | ecoff_put_off (abfd, intern->cbFdOffset, (bfd_byte *)ext->h_cbFdOffset); | |
132 | bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->h_crfd); | |
133 | ecoff_put_off (abfd, intern->cbRfdOffset, (bfd_byte *)ext->h_cbRfdOffset); | |
134 | bfd_h_put_32 (abfd, intern->iextMax, (bfd_byte *)ext->h_iextMax); | |
135 | ecoff_put_off (abfd, intern->cbExtOffset, (bfd_byte *)ext->h_cbExtOffset); | |
136 | ||
137 | #ifdef TEST | |
138 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
139 | abort(); | |
140 | #endif | |
141 | } | |
142 | ||
143 | /* Swap in the file descriptor record. */ | |
144 | ||
145 | static void | |
146 | ecoff_swap_fdr_in (abfd, ext_copy, intern) | |
147 | bfd *abfd; | |
148 | PTR ext_copy; | |
149 | FDR *intern; | |
150 | { | |
151 | struct fdr_ext ext[1]; | |
152 | ||
153 | *ext = *(struct fdr_ext *) ext_copy; | |
154 | ||
155 | intern->adr = ecoff_get_off (abfd, (bfd_byte *)ext->f_adr); | |
156 | intern->rss = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss); | |
157 | intern->issBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_issBase); | |
158 | intern->cbSs = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbSs); | |
159 | intern->isymBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_isymBase); | |
160 | intern->csym = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_csym); | |
161 | intern->ilineBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ilineBase); | |
162 | intern->cline = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline); | |
163 | intern->ioptBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase); | |
164 | intern->copt = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt); | |
165 | #ifdef ECOFF_32 | |
166 | intern->ipdFirst = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst); | |
167 | intern->cpd = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd); | |
168 | #endif | |
169 | #ifdef ECOFF_64 | |
170 | intern->ipdFirst = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ipdFirst); | |
171 | intern->cpd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cpd); | |
172 | #endif | |
173 | intern->iauxBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_iauxBase); | |
174 | intern->caux = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_caux); | |
175 | intern->rfdBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rfdBase); | |
176 | intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_crfd); | |
177 | ||
178 | /* now the fun stuff... */ | |
179 | if (abfd->xvec->header_byteorder_big_p != false) { | |
180 | intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_BIG) | |
181 | >> FDR_BITS1_LANG_SH_BIG; | |
182 | intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG); | |
183 | intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG); | |
184 | intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG); | |
185 | intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG) | |
186 | >> FDR_BITS2_GLEVEL_SH_BIG; | |
187 | } else { | |
188 | intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE) | |
189 | >> FDR_BITS1_LANG_SH_LITTLE; | |
190 | intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE); | |
191 | intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE); | |
192 | intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE); | |
193 | intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE) | |
194 | >> FDR_BITS2_GLEVEL_SH_LITTLE; | |
195 | } | |
196 | intern->reserved = 0; | |
197 | ||
198 | intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLineOffset); | |
199 | intern->cbLine = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLine); | |
200 | ||
201 | #ifdef TEST | |
202 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
203 | abort(); | |
204 | #endif | |
205 | } | |
206 | ||
207 | /* Swap out the file descriptor record. */ | |
208 | ||
209 | static void | |
210 | ecoff_swap_fdr_out (abfd, intern_copy, ext_ptr) | |
211 | bfd *abfd; | |
212 | FDR *intern_copy; | |
213 | PTR ext_ptr; | |
214 | { | |
215 | struct fdr_ext *ext = (struct fdr_ext *) ext_ptr; | |
216 | FDR intern[1]; | |
217 | ||
218 | *intern = *intern_copy; /* Make it reasonable to do in-place. */ | |
219 | ||
220 | ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->f_adr); | |
221 | bfd_h_put_32 (abfd, intern->rss, (bfd_byte *)ext->f_rss); | |
222 | bfd_h_put_32 (abfd, intern->issBase, (bfd_byte *)ext->f_issBase); | |
223 | ecoff_put_off (abfd, intern->cbSs, (bfd_byte *)ext->f_cbSs); | |
224 | bfd_h_put_32 (abfd, intern->isymBase, (bfd_byte *)ext->f_isymBase); | |
225 | bfd_h_put_32 (abfd, intern->csym, (bfd_byte *)ext->f_csym); | |
226 | bfd_h_put_32 (abfd, intern->ilineBase, (bfd_byte *)ext->f_ilineBase); | |
227 | bfd_h_put_32 (abfd, intern->cline, (bfd_byte *)ext->f_cline); | |
228 | bfd_h_put_32 (abfd, intern->ioptBase, (bfd_byte *)ext->f_ioptBase); | |
229 | bfd_h_put_32 (abfd, intern->copt, (bfd_byte *)ext->f_copt); | |
230 | #ifdef ECOFF_32 | |
231 | bfd_h_put_16 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst); | |
232 | bfd_h_put_16 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd); | |
233 | #endif | |
234 | #ifdef ECOFF_64 | |
235 | bfd_h_put_32 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst); | |
236 | bfd_h_put_32 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd); | |
237 | #endif | |
238 | bfd_h_put_32 (abfd, intern->iauxBase, (bfd_byte *)ext->f_iauxBase); | |
239 | bfd_h_put_32 (abfd, intern->caux, (bfd_byte *)ext->f_caux); | |
240 | bfd_h_put_32 (abfd, intern->rfdBase, (bfd_byte *)ext->f_rfdBase); | |
241 | bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->f_crfd); | |
242 | ||
243 | /* now the fun stuff... */ | |
244 | if (abfd->xvec->header_byteorder_big_p != false) { | |
245 | ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG) | |
246 | & FDR_BITS1_LANG_BIG) | |
247 | | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0) | |
248 | | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0) | |
249 | | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0)); | |
250 | ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG) | |
251 | & FDR_BITS2_GLEVEL_BIG); | |
252 | ext->f_bits2[1] = 0; | |
253 | ext->f_bits2[2] = 0; | |
254 | } else { | |
255 | ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE) | |
256 | & FDR_BITS1_LANG_LITTLE) | |
257 | | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0) | |
258 | | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0) | |
259 | | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0)); | |
260 | ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE) | |
261 | & FDR_BITS2_GLEVEL_LITTLE); | |
262 | ext->f_bits2[1] = 0; | |
263 | ext->f_bits2[2] = 0; | |
264 | } | |
265 | ||
266 | ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->f_cbLineOffset); | |
267 | ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->f_cbLine); | |
268 | ||
269 | #ifdef TEST | |
270 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
271 | abort(); | |
272 | #endif | |
273 | } | |
274 | ||
275 | /* Swap in the procedure descriptor record. */ | |
276 | ||
277 | static void | |
278 | ecoff_swap_pdr_in (abfd, ext_copy, intern) | |
279 | bfd *abfd; | |
280 | PTR ext_copy; | |
281 | PDR *intern; | |
282 | { | |
283 | struct pdr_ext ext[1]; | |
284 | ||
285 | *ext = *(struct pdr_ext *) ext_copy; | |
286 | ||
287 | intern->adr = ecoff_get_off (abfd, (bfd_byte *)ext->p_adr); | |
288 | intern->isym = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym); | |
289 | intern->iline = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline); | |
290 | intern->regmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask); | |
291 | intern->regoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regoffset); | |
292 | intern->iopt = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iopt); | |
293 | intern->fregmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask); | |
294 | intern->fregoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregoffset); | |
295 | intern->frameoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_frameoffset); | |
296 | intern->framereg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg); | |
297 | intern->pcreg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg); | |
298 | intern->lnLow = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow); | |
299 | intern->lnHigh = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh); | |
300 | intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset); | |
301 | ||
302 | #ifdef TEST | |
303 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
304 | abort(); | |
305 | #endif | |
306 | } | |
307 | ||
308 | /* Swap out the procedure descriptor record. */ | |
309 | ||
310 | static void | |
311 | ecoff_swap_pdr_out (abfd, intern_copy, ext_ptr) | |
312 | bfd *abfd; | |
313 | PDR *intern_copy; | |
314 | PTR ext_ptr; | |
315 | { | |
316 | struct pdr_ext *ext = (struct pdr_ext *) ext_ptr; | |
317 | PDR intern[1]; | |
318 | ||
319 | *intern = *intern_copy; /* Make it reasonable to do in-place. */ | |
320 | ||
321 | ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->p_adr); | |
322 | bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym); | |
323 | bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline); | |
324 | bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask); | |
325 | bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset); | |
326 | bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt); | |
327 | bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask); | |
328 | bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset); | |
329 | bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset); | |
330 | bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg); | |
331 | bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg); | |
332 | bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow); | |
333 | bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh); | |
334 | ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset); | |
335 | ||
336 | #ifdef TEST | |
337 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
338 | abort(); | |
339 | #endif | |
340 | } | |
341 | ||
342 | /* Swap in a symbol record. */ | |
343 | ||
344 | static void | |
345 | ecoff_swap_sym_in (abfd, ext_copy, intern) | |
346 | bfd *abfd; | |
347 | PTR ext_copy; | |
348 | SYMR *intern; | |
349 | { | |
350 | struct sym_ext ext[1]; | |
351 | ||
352 | *ext = *(struct sym_ext *) ext_copy; | |
353 | ||
354 | intern->iss = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_iss); | |
355 | intern->value = ecoff_get_off (abfd, (bfd_byte *)ext->s_value); | |
356 | ||
357 | /* now the fun stuff... */ | |
358 | if (abfd->xvec->header_byteorder_big_p != false) { | |
359 | intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG) | |
360 | >> SYM_BITS1_ST_SH_BIG; | |
361 | intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG) | |
362 | << SYM_BITS1_SC_SH_LEFT_BIG) | |
363 | | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG) | |
364 | >> SYM_BITS2_SC_SH_BIG); | |
365 | intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG); | |
366 | intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG) | |
367 | << SYM_BITS2_INDEX_SH_LEFT_BIG) | |
368 | | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG) | |
369 | | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG); | |
370 | } else { | |
371 | intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE) | |
372 | >> SYM_BITS1_ST_SH_LITTLE; | |
373 | intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE) | |
374 | >> SYM_BITS1_SC_SH_LITTLE) | |
375 | | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE) | |
376 | << SYM_BITS2_SC_SH_LEFT_LITTLE); | |
377 | intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE); | |
378 | intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE) | |
379 | >> SYM_BITS2_INDEX_SH_LITTLE) | |
380 | | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE) | |
381 | | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_LITTLE); | |
382 | } | |
383 | ||
384 | #ifdef TEST | |
385 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
386 | abort(); | |
387 | #endif | |
388 | } | |
389 | ||
390 | /* Swap out a symbol record. */ | |
391 | ||
392 | static void | |
393 | ecoff_swap_sym_out (abfd, intern_copy, ext_ptr) | |
394 | bfd *abfd; | |
395 | SYMR *intern_copy; | |
396 | PTR ext_ptr; | |
397 | { | |
398 | struct sym_ext *ext = (struct sym_ext *) ext_ptr; | |
399 | SYMR intern[1]; | |
400 | ||
401 | *intern = *intern_copy; /* Make it reasonable to do in-place. */ | |
402 | ||
403 | bfd_h_put_32 (abfd, intern->iss, (bfd_byte *)ext->s_iss); | |
404 | ecoff_put_off (abfd, intern->value, (bfd_byte *)ext->s_value); | |
405 | ||
406 | /* now the fun stuff... */ | |
407 | if (abfd->xvec->header_byteorder_big_p != false) { | |
408 | ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG) | |
409 | & SYM_BITS1_ST_BIG) | |
410 | | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG) | |
411 | & SYM_BITS1_SC_BIG)); | |
412 | ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG) | |
413 | & SYM_BITS2_SC_BIG) | |
414 | | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0) | |
415 | | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG) | |
416 | & SYM_BITS2_INDEX_BIG)); | |
417 | ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff; | |
418 | ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff; | |
419 | } else { | |
420 | ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE) | |
421 | & SYM_BITS1_ST_LITTLE) | |
422 | | ((intern->sc << SYM_BITS1_SC_SH_LITTLE) | |
423 | & SYM_BITS1_SC_LITTLE)); | |
424 | ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE) | |
425 | & SYM_BITS2_SC_LITTLE) | |
426 | | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0) | |
427 | | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE) | |
428 | & SYM_BITS2_INDEX_LITTLE)); | |
429 | ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff; | |
430 | ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff; | |
431 | } | |
432 | ||
433 | #ifdef TEST | |
434 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
435 | abort(); | |
436 | #endif | |
437 | } | |
438 | ||
439 | /* Swap in an external symbol record. */ | |
440 | ||
441 | static void | |
442 | ecoff_swap_ext_in (abfd, ext_copy, intern) | |
443 | bfd *abfd; | |
444 | PTR ext_copy; | |
445 | EXTR *intern; | |
446 | { | |
447 | struct ext_ext ext[1]; | |
448 | ||
449 | *ext = *(struct ext_ext *) ext_copy; | |
450 | ||
451 | /* now the fun stuff... */ | |
452 | if (abfd->xvec->header_byteorder_big_p != false) { | |
453 | intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG); | |
454 | intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG); | |
455 | intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG); | |
456 | } else { | |
457 | intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE); | |
458 | intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE); | |
459 | intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE); | |
460 | } | |
461 | intern->reserved = 0; | |
462 | ||
463 | #ifdef ECOFF_32 | |
464 | intern->ifd = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->es_ifd); | |
465 | #endif | |
466 | #ifdef ECOFF_64 | |
467 | intern->ifd = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->es_ifd); | |
468 | #endif | |
469 | ||
470 | ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym); | |
471 | ||
472 | #ifdef TEST | |
473 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
474 | abort(); | |
475 | #endif | |
476 | } | |
477 | ||
478 | /* Swap out an external symbol record. */ | |
479 | ||
480 | static void | |
481 | ecoff_swap_ext_out (abfd, intern_copy, ext_ptr) | |
482 | bfd *abfd; | |
483 | EXTR *intern_copy; | |
484 | PTR ext_ptr; | |
485 | { | |
486 | struct ext_ext *ext = (struct ext_ext *) ext_ptr; | |
487 | EXTR intern[1]; | |
488 | ||
489 | *intern = *intern_copy; /* Make it reasonable to do in-place. */ | |
490 | ||
491 | /* now the fun stuff... */ | |
492 | if (abfd->xvec->header_byteorder_big_p != false) { | |
493 | ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0) | |
494 | | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0) | |
495 | | (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0)); | |
496 | ext->es_bits2[0] = 0; | |
497 | } else { | |
498 | ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0) | |
499 | | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0) | |
500 | | (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0)); | |
501 | ext->es_bits2[0] = 0; | |
502 | } | |
503 | ||
504 | #ifdef ECOFF_32 | |
505 | bfd_h_put_signed_16 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd); | |
506 | #endif | |
507 | #ifdef ECOFF_64 | |
508 | bfd_h_put_signed_32 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd); | |
509 | #endif | |
510 | ||
511 | ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym); | |
512 | ||
513 | #ifdef TEST | |
514 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
515 | abort(); | |
516 | #endif | |
517 | } | |
518 | ||
519 | /* Swap in a relative file descriptor. */ | |
520 | ||
521 | static void | |
522 | ecoff_swap_rfd_in (abfd, ext_ptr, intern) | |
523 | bfd *abfd; | |
524 | PTR ext_ptr; | |
525 | RFDT *intern; | |
526 | { | |
527 | struct rfd_ext *ext = (struct rfd_ext *) ext_ptr; | |
528 | ||
529 | *intern = bfd_h_get_32 (abfd, (bfd_byte *)ext->rfd); | |
530 | ||
531 | #ifdef TEST | |
532 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
533 | abort(); | |
534 | #endif | |
535 | } | |
536 | ||
537 | /* Swap out a relative file descriptor. */ | |
538 | ||
539 | static void | |
540 | ecoff_swap_rfd_out (abfd, intern, ext_ptr) | |
541 | bfd *abfd; | |
542 | RFDT *intern; | |
543 | PTR ext_ptr; | |
544 | { | |
545 | struct rfd_ext *ext = (struct rfd_ext *) ext_ptr; | |
546 | ||
547 | bfd_h_put_32 (abfd, *intern, (bfd_byte *)ext->rfd); | |
548 | ||
549 | #ifdef TEST | |
550 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
551 | abort(); | |
552 | #endif | |
553 | } | |
554 | ||
555 | /* Swap in an optimization symbol. */ | |
556 | ||
557 | static void | |
558 | ecoff_swap_opt_in (abfd, ext_copy, intern) | |
559 | bfd *abfd; | |
560 | PTR ext_copy; | |
561 | OPTR *intern; | |
562 | { | |
563 | struct opt_ext ext[1]; | |
564 | ||
565 | *ext = *(struct opt_ext *) ext_copy; | |
566 | ||
567 | if (abfd->xvec->header_byteorder_big_p != false) | |
568 | { | |
569 | intern->ot = ext->o_bits1[0]; | |
570 | intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_BIG) | |
571 | | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_BIG) | |
572 | | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_BIG)); | |
573 | } | |
574 | else | |
575 | { | |
576 | intern->ot = ext->o_bits1[0]; | |
577 | intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE) | |
578 | | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE) | |
579 | | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)); | |
580 | } | |
581 | ||
582 | ecoff_swap_rndx_in (abfd->xvec->header_byteorder_big_p != false, | |
583 | &ext->o_rndx, &intern->rndx); | |
584 | ||
585 | intern->offset = bfd_h_get_32 (abfd, (bfd_byte *) ext->o_offset); | |
586 | ||
587 | #ifdef TEST | |
588 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
589 | abort(); | |
590 | #endif | |
591 | } | |
592 | ||
593 | /* Swap out an optimization symbol. */ | |
594 | ||
595 | static void | |
596 | ecoff_swap_opt_out (abfd, intern_copy, ext_ptr) | |
597 | bfd *abfd; | |
598 | OPTR *intern_copy; | |
599 | PTR ext_ptr; | |
600 | { | |
601 | struct opt_ext *ext = (struct opt_ext *) ext_ptr; | |
602 | OPTR intern[1]; | |
603 | ||
604 | *intern = *intern_copy; /* Make it reasonable to do in-place. */ | |
605 | ||
606 | if (abfd->xvec->header_byteorder_big_p != false) | |
607 | { | |
608 | ext->o_bits1[0] = intern->ot; | |
609 | ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG; | |
610 | ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG; | |
611 | ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG; | |
612 | } | |
613 | else | |
614 | { | |
615 | ext->o_bits1[0] = intern->ot; | |
616 | ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE; | |
617 | ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE; | |
618 | ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE; | |
619 | } | |
620 | ||
621 | ecoff_swap_rndx_out (abfd->xvec->header_byteorder_big_p != false, | |
622 | &intern->rndx, &ext->o_rndx); | |
623 | ||
624 | bfd_h_put_32 (abfd, intern->value, (bfd_byte *) ext->o_offset); | |
625 | ||
626 | #ifdef TEST | |
627 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
628 | abort(); | |
629 | #endif | |
630 | } | |
631 | ||
632 | /* Swap in a dense number. */ | |
633 | ||
634 | static void | |
635 | ecoff_swap_dnr_in (abfd, ext_copy, intern) | |
636 | bfd *abfd; | |
637 | PTR ext_copy; | |
638 | DNR *intern; | |
639 | { | |
640 | struct dnr_ext ext[1]; | |
641 | ||
642 | *ext = *(struct dnr_ext *) ext_copy; | |
643 | ||
644 | intern->rfd = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_rfd); | |
645 | intern->index = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_index); | |
646 | ||
647 | #ifdef TEST | |
648 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
649 | abort(); | |
650 | #endif | |
651 | } | |
652 | ||
653 | /* Swap out a dense number. */ | |
654 | ||
655 | static void | |
656 | ecoff_swap_dnr_out (abfd, intern_copy, ext_ptr) | |
657 | bfd *abfd; | |
658 | DNR *intern_copy; | |
659 | PTR ext_ptr; | |
660 | { | |
661 | struct dnr_ext *ext = (struct dnr_ext *) ext_ptr; | |
662 | DNR intern[1]; | |
663 | ||
664 | *intern = *intern_copy; /* Make it reasonable to do in-place. */ | |
665 | ||
666 | bfd_h_put_32 (abfd, intern->rfd, (bfd_byte *) ext->d_rfd); | |
667 | bfd_h_put_32 (abfd, intern->index, (bfd_byte *) ext->d_index); | |
668 | ||
669 | #ifdef TEST | |
670 | if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0) | |
671 | abort(); | |
672 | #endif | |
673 | } |