]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - bfd/ecoffswap.h
* ecoff.c (ecoff_swap_tir_in): Change input argument to const.
[thirdparty/binutils-gdb.git] / bfd / ecoffswap.h
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 /* ECOFF auxiliary information swapping routines. These are the same
55 for all ECOFF targets, so they are defined in ecoff.c. */
56 extern void ecoff_swap_tir_in PARAMS ((int, const struct tir_ext *, TIR *));
57 extern void ecoff_swap_tir_out PARAMS ((int, const TIR *, struct tir_ext *));
58 extern void ecoff_swap_rndx_in PARAMS ((int, const struct rndx_ext *,
59 RNDXR *));
60 extern void ecoff_swap_rndx_out PARAMS ((int, const RNDXR *,
61 struct rndx_ext *));
62
63 /* Swap in the symbolic header. */
64
65 static void
66 ecoff_swap_hdr_in (abfd, ext_copy, intern)
67 bfd *abfd;
68 PTR ext_copy;
69 HDRR *intern;
70 {
71 struct hdr_ext ext[1];
72
73 *ext = *(struct hdr_ext *) ext_copy;
74
75 intern->magic = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_magic);
76 intern->vstamp = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_vstamp);
77 intern->ilineMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ilineMax);
78 intern->cbLine = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLine);
79 intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLineOffset);
80 intern->idnMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_idnMax);
81 intern->cbDnOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbDnOffset);
82 intern->ipdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ipdMax);
83 intern->cbPdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbPdOffset);
84 intern->isymMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_isymMax);
85 intern->cbSymOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSymOffset);
86 intern->ioptMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ioptMax);
87 intern->cbOptOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbOptOffset);
88 intern->iauxMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iauxMax);
89 intern->cbAuxOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbAuxOffset);
90 intern->issMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issMax);
91 intern->cbSsOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsOffset);
92 intern->issExtMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issExtMax);
93 intern->cbSsExtOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsExtOffset);
94 intern->ifdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ifdMax);
95 intern->cbFdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbFdOffset);
96 intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_crfd);
97 intern->cbRfdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbRfdOffset);
98 intern->iextMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iextMax);
99 intern->cbExtOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbExtOffset);
100
101 #ifdef TEST
102 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
103 abort();
104 #endif
105 }
106
107 /* Swap out the symbolic header. */
108
109 static void
110 ecoff_swap_hdr_out (abfd, intern_copy, ext_ptr)
111 bfd *abfd;
112 const HDRR *intern_copy;
113 PTR ext_ptr;
114 {
115 struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
116 HDRR intern[1];
117
118 *intern = *intern_copy;
119
120 bfd_h_put_signed_16 (abfd, intern->magic, (bfd_byte *)ext->h_magic);
121 bfd_h_put_signed_16 (abfd, intern->vstamp, (bfd_byte *)ext->h_vstamp);
122 bfd_h_put_32 (abfd, intern->ilineMax, (bfd_byte *)ext->h_ilineMax);
123 ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->h_cbLine);
124 ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->h_cbLineOffset);
125 bfd_h_put_32 (abfd, intern->idnMax, (bfd_byte *)ext->h_idnMax);
126 ecoff_put_off (abfd, intern->cbDnOffset, (bfd_byte *)ext->h_cbDnOffset);
127 bfd_h_put_32 (abfd, intern->ipdMax, (bfd_byte *)ext->h_ipdMax);
128 ecoff_put_off (abfd, intern->cbPdOffset, (bfd_byte *)ext->h_cbPdOffset);
129 bfd_h_put_32 (abfd, intern->isymMax, (bfd_byte *)ext->h_isymMax);
130 ecoff_put_off (abfd, intern->cbSymOffset, (bfd_byte *)ext->h_cbSymOffset);
131 bfd_h_put_32 (abfd, intern->ioptMax, (bfd_byte *)ext->h_ioptMax);
132 ecoff_put_off (abfd, intern->cbOptOffset, (bfd_byte *)ext->h_cbOptOffset);
133 bfd_h_put_32 (abfd, intern->iauxMax, (bfd_byte *)ext->h_iauxMax);
134 ecoff_put_off (abfd, intern->cbAuxOffset, (bfd_byte *)ext->h_cbAuxOffset);
135 bfd_h_put_32 (abfd, intern->issMax, (bfd_byte *)ext->h_issMax);
136 ecoff_put_off (abfd, intern->cbSsOffset, (bfd_byte *)ext->h_cbSsOffset);
137 bfd_h_put_32 (abfd, intern->issExtMax, (bfd_byte *)ext->h_issExtMax);
138 ecoff_put_off (abfd, intern->cbSsExtOffset, (bfd_byte *)ext->h_cbSsExtOffset);
139 bfd_h_put_32 (abfd, intern->ifdMax, (bfd_byte *)ext->h_ifdMax);
140 ecoff_put_off (abfd, intern->cbFdOffset, (bfd_byte *)ext->h_cbFdOffset);
141 bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->h_crfd);
142 ecoff_put_off (abfd, intern->cbRfdOffset, (bfd_byte *)ext->h_cbRfdOffset);
143 bfd_h_put_32 (abfd, intern->iextMax, (bfd_byte *)ext->h_iextMax);
144 ecoff_put_off (abfd, intern->cbExtOffset, (bfd_byte *)ext->h_cbExtOffset);
145
146 #ifdef TEST
147 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
148 abort();
149 #endif
150 }
151
152 /* Swap in the file descriptor record. */
153
154 static void
155 ecoff_swap_fdr_in (abfd, ext_copy, intern)
156 bfd *abfd;
157 PTR ext_copy;
158 FDR *intern;
159 {
160 struct fdr_ext ext[1];
161
162 *ext = *(struct fdr_ext *) ext_copy;
163
164 intern->adr = ecoff_get_off (abfd, (bfd_byte *)ext->f_adr);
165 intern->rss = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
166 intern->issBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_issBase);
167 intern->cbSs = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbSs);
168 intern->isymBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_isymBase);
169 intern->csym = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_csym);
170 intern->ilineBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ilineBase);
171 intern->cline = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
172 intern->ioptBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
173 intern->copt = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
174 #ifdef ECOFF_32
175 intern->ipdFirst = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
176 intern->cpd = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
177 #endif
178 #ifdef ECOFF_64
179 intern->ipdFirst = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ipdFirst);
180 intern->cpd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cpd);
181 #endif
182 intern->iauxBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_iauxBase);
183 intern->caux = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_caux);
184 intern->rfdBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rfdBase);
185 intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_crfd);
186
187 /* now the fun stuff... */
188 if (abfd->xvec->header_byteorder_big_p != false) {
189 intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
190 >> FDR_BITS1_LANG_SH_BIG;
191 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
192 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
193 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
194 intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
195 >> FDR_BITS2_GLEVEL_SH_BIG;
196 } else {
197 intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
198 >> FDR_BITS1_LANG_SH_LITTLE;
199 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
200 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
201 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
202 intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
203 >> FDR_BITS2_GLEVEL_SH_LITTLE;
204 }
205 intern->reserved = 0;
206
207 intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLineOffset);
208 intern->cbLine = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLine);
209
210 #ifdef TEST
211 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
212 abort();
213 #endif
214 }
215
216 /* Swap out the file descriptor record. */
217
218 static void
219 ecoff_swap_fdr_out (abfd, intern_copy, ext_ptr)
220 bfd *abfd;
221 const FDR *intern_copy;
222 PTR ext_ptr;
223 {
224 struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
225 FDR intern[1];
226
227 *intern = *intern_copy; /* Make it reasonable to do in-place. */
228
229 ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->f_adr);
230 bfd_h_put_32 (abfd, intern->rss, (bfd_byte *)ext->f_rss);
231 bfd_h_put_32 (abfd, intern->issBase, (bfd_byte *)ext->f_issBase);
232 ecoff_put_off (abfd, intern->cbSs, (bfd_byte *)ext->f_cbSs);
233 bfd_h_put_32 (abfd, intern->isymBase, (bfd_byte *)ext->f_isymBase);
234 bfd_h_put_32 (abfd, intern->csym, (bfd_byte *)ext->f_csym);
235 bfd_h_put_32 (abfd, intern->ilineBase, (bfd_byte *)ext->f_ilineBase);
236 bfd_h_put_32 (abfd, intern->cline, (bfd_byte *)ext->f_cline);
237 bfd_h_put_32 (abfd, intern->ioptBase, (bfd_byte *)ext->f_ioptBase);
238 bfd_h_put_32 (abfd, intern->copt, (bfd_byte *)ext->f_copt);
239 #ifdef ECOFF_32
240 bfd_h_put_16 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
241 bfd_h_put_16 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
242 #endif
243 #ifdef ECOFF_64
244 bfd_h_put_32 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
245 bfd_h_put_32 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
246 #endif
247 bfd_h_put_32 (abfd, intern->iauxBase, (bfd_byte *)ext->f_iauxBase);
248 bfd_h_put_32 (abfd, intern->caux, (bfd_byte *)ext->f_caux);
249 bfd_h_put_32 (abfd, intern->rfdBase, (bfd_byte *)ext->f_rfdBase);
250 bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->f_crfd);
251
252 /* now the fun stuff... */
253 if (abfd->xvec->header_byteorder_big_p != false) {
254 ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
255 & FDR_BITS1_LANG_BIG)
256 | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
257 | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
258 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
259 ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
260 & FDR_BITS2_GLEVEL_BIG);
261 ext->f_bits2[1] = 0;
262 ext->f_bits2[2] = 0;
263 } else {
264 ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
265 & FDR_BITS1_LANG_LITTLE)
266 | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
267 | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
268 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
269 ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
270 & FDR_BITS2_GLEVEL_LITTLE);
271 ext->f_bits2[1] = 0;
272 ext->f_bits2[2] = 0;
273 }
274
275 ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->f_cbLineOffset);
276 ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->f_cbLine);
277
278 #ifdef TEST
279 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
280 abort();
281 #endif
282 }
283
284 /* Swap in the procedure descriptor record. */
285
286 static void
287 ecoff_swap_pdr_in (abfd, ext_copy, intern)
288 bfd *abfd;
289 PTR ext_copy;
290 PDR *intern;
291 {
292 struct pdr_ext ext[1];
293
294 *ext = *(struct pdr_ext *) ext_copy;
295
296 intern->adr = ecoff_get_off (abfd, (bfd_byte *)ext->p_adr);
297 intern->isym = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
298 intern->iline = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
299 intern->regmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
300 intern->regoffset = bfd_h_get_signed_32 (abfd,
301 (bfd_byte *)ext->p_regoffset);
302 intern->iopt = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->p_iopt);
303 intern->fregmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
304 intern->fregoffset = bfd_h_get_signed_32 (abfd,
305 (bfd_byte *)ext->p_fregoffset);
306 intern->frameoffset = bfd_h_get_signed_32 (abfd,
307 (bfd_byte *)ext->p_frameoffset);
308 intern->framereg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
309 intern->pcreg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
310 intern->lnLow = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
311 intern->lnHigh = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
312 intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
313
314 #ifdef ECOFF_64
315 intern->gp_prologue = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_gp_prologue);
316 if (abfd->xvec->header_byteorder_big_p != false)
317 {
318 intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
319 intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
320 intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
321 << PDR_BITS1_RESERVED_SH_LEFT_BIG)
322 | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
323 >> PDR_BITS2_RESERVED_SH_BIG));
324 }
325 else
326 {
327 intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
328 intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
329 intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
330 >> PDR_BITS1_RESERVED_SH_LITTLE)
331 | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
332 << PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
333 }
334 intern->localoff = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_localoff);
335 #endif
336
337 #ifdef TEST
338 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
339 abort();
340 #endif
341 }
342
343 /* Swap out the procedure descriptor record. */
344
345 static void
346 ecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
347 bfd *abfd;
348 const PDR *intern_copy;
349 PTR ext_ptr;
350 {
351 struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
352 PDR intern[1];
353
354 *intern = *intern_copy; /* Make it reasonable to do in-place. */
355
356 ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->p_adr);
357 bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym);
358 bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline);
359 bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask);
360 bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset);
361 bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt);
362 bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask);
363 bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset);
364 bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset);
365 bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg);
366 bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg);
367 bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow);
368 bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
369 ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
370
371 #ifdef ECOFF_64
372 bfd_h_put_8 (abfd, intern->gp_prologue, (bfd_byte *) ext->p_gp_prologue);
373 if (abfd->xvec->header_byteorder_big_p != false)
374 {
375 ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
376 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
377 | ((intern->reserved
378 >> PDR_BITS1_RESERVED_SH_LEFT_BIG)
379 & PDR_BITS1_RESERVED_BIG));
380 ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
381 & PDR_BITS2_RESERVED_BIG);
382 }
383 else
384 {
385 ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
386 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
387 | ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
388 & PDR_BITS1_RESERVED_LITTLE));
389 ext->p_bits2[0] = ((intern->reserved >>
390 PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
391 & PDR_BITS2_RESERVED_LITTLE);
392 }
393 bfd_h_put_8 (abfd, intern->localoff, (bfd_byte *) ext->p_localoff);
394 #endif
395
396 #ifdef TEST
397 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
398 abort();
399 #endif
400 }
401
402 /* Swap in a symbol record. */
403
404 static void
405 ecoff_swap_sym_in (abfd, ext_copy, intern)
406 bfd *abfd;
407 PTR ext_copy;
408 SYMR *intern;
409 {
410 struct sym_ext ext[1];
411
412 *ext = *(struct sym_ext *) ext_copy;
413
414 intern->iss = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_iss);
415 intern->value = ecoff_get_off (abfd, (bfd_byte *)ext->s_value);
416
417 /* now the fun stuff... */
418 if (abfd->xvec->header_byteorder_big_p != false) {
419 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
420 >> SYM_BITS1_ST_SH_BIG;
421 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
422 << SYM_BITS1_SC_SH_LEFT_BIG)
423 | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
424 >> SYM_BITS2_SC_SH_BIG);
425 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
426 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
427 << SYM_BITS2_INDEX_SH_LEFT_BIG)
428 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
429 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
430 } else {
431 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
432 >> SYM_BITS1_ST_SH_LITTLE;
433 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
434 >> SYM_BITS1_SC_SH_LITTLE)
435 | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
436 << SYM_BITS2_SC_SH_LEFT_LITTLE);
437 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
438 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
439 >> SYM_BITS2_INDEX_SH_LITTLE)
440 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
441 | ((unsigned int) ext->s_bits4[0]
442 << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
443 }
444
445 #ifdef TEST
446 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
447 abort();
448 #endif
449 }
450
451 /* Swap out a symbol record. */
452
453 static void
454 ecoff_swap_sym_out (abfd, intern_copy, ext_ptr)
455 bfd *abfd;
456 const SYMR *intern_copy;
457 PTR ext_ptr;
458 {
459 struct sym_ext *ext = (struct sym_ext *) ext_ptr;
460 SYMR intern[1];
461
462 *intern = *intern_copy; /* Make it reasonable to do in-place. */
463
464 bfd_h_put_32 (abfd, intern->iss, (bfd_byte *)ext->s_iss);
465 ecoff_put_off (abfd, intern->value, (bfd_byte *)ext->s_value);
466
467 /* now the fun stuff... */
468 if (abfd->xvec->header_byteorder_big_p != false) {
469 ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
470 & SYM_BITS1_ST_BIG)
471 | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
472 & SYM_BITS1_SC_BIG));
473 ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
474 & SYM_BITS2_SC_BIG)
475 | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
476 | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
477 & SYM_BITS2_INDEX_BIG));
478 ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
479 ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
480 } else {
481 ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
482 & SYM_BITS1_ST_LITTLE)
483 | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
484 & SYM_BITS1_SC_LITTLE));
485 ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
486 & SYM_BITS2_SC_LITTLE)
487 | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
488 | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
489 & SYM_BITS2_INDEX_LITTLE));
490 ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
491 ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
492 }
493
494 #ifdef TEST
495 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
496 abort();
497 #endif
498 }
499
500 /* Swap in an external symbol record. */
501
502 static void
503 ecoff_swap_ext_in (abfd, ext_copy, intern)
504 bfd *abfd;
505 PTR ext_copy;
506 EXTR *intern;
507 {
508 struct ext_ext ext[1];
509
510 *ext = *(struct ext_ext *) ext_copy;
511
512 /* now the fun stuff... */
513 if (abfd->xvec->header_byteorder_big_p != false) {
514 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
515 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
516 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
517 } else {
518 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
519 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
520 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
521 }
522 intern->reserved = 0;
523
524 #ifdef ECOFF_32
525 intern->ifd = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->es_ifd);
526 #endif
527 #ifdef ECOFF_64
528 intern->ifd = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->es_ifd);
529 #endif
530
531 ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
532
533 #ifdef TEST
534 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
535 abort();
536 #endif
537 }
538
539 /* Swap out an external symbol record. */
540
541 static void
542 ecoff_swap_ext_out (abfd, intern_copy, ext_ptr)
543 bfd *abfd;
544 const EXTR *intern_copy;
545 PTR ext_ptr;
546 {
547 struct ext_ext *ext = (struct ext_ext *) ext_ptr;
548 EXTR intern[1];
549
550 *intern = *intern_copy; /* Make it reasonable to do in-place. */
551
552 /* now the fun stuff... */
553 if (abfd->xvec->header_byteorder_big_p != false) {
554 ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
555 | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
556 | (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
557 ext->es_bits2[0] = 0;
558 } else {
559 ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
560 | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
561 | (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
562 ext->es_bits2[0] = 0;
563 }
564
565 #ifdef ECOFF_32
566 bfd_h_put_signed_16 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
567 #endif
568 #ifdef ECOFF_64
569 bfd_h_put_signed_32 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
570 #endif
571
572 ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
573
574 #ifdef TEST
575 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
576 abort();
577 #endif
578 }
579
580 /* Swap in a relative file descriptor. */
581
582 static void
583 ecoff_swap_rfd_in (abfd, ext_ptr, intern)
584 bfd *abfd;
585 PTR ext_ptr;
586 RFDT *intern;
587 {
588 struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
589
590 *intern = bfd_h_get_32 (abfd, (bfd_byte *)ext->rfd);
591
592 #ifdef TEST
593 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
594 abort();
595 #endif
596 }
597
598 /* Swap out a relative file descriptor. */
599
600 static void
601 ecoff_swap_rfd_out (abfd, intern, ext_ptr)
602 bfd *abfd;
603 const RFDT *intern;
604 PTR ext_ptr;
605 {
606 struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
607
608 bfd_h_put_32 (abfd, *intern, (bfd_byte *)ext->rfd);
609
610 #ifdef TEST
611 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
612 abort();
613 #endif
614 }
615
616 /* Swap in an optimization symbol. */
617
618 static void
619 ecoff_swap_opt_in (abfd, ext_copy, intern)
620 bfd *abfd;
621 PTR ext_copy;
622 OPTR *intern;
623 {
624 struct opt_ext ext[1];
625
626 *ext = *(struct opt_ext *) ext_copy;
627
628 if (abfd->xvec->header_byteorder_big_p != false)
629 {
630 intern->ot = ext->o_bits1[0];
631 intern->value = (((unsigned int) ext->o_bits2[0]
632 << OPT_BITS2_VALUE_SH_LEFT_BIG)
633 | ((unsigned int) ext->o_bits3[0]
634 << OPT_BITS2_VALUE_SH_LEFT_BIG)
635 | ((unsigned int) ext->o_bits4[0]
636 << OPT_BITS2_VALUE_SH_LEFT_BIG));
637 }
638 else
639 {
640 intern->ot = ext->o_bits1[0];
641 intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
642 | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
643 | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
644 }
645
646 ecoff_swap_rndx_in (abfd->xvec->header_byteorder_big_p != false,
647 &ext->o_rndx, &intern->rndx);
648
649 intern->offset = bfd_h_get_32 (abfd, (bfd_byte *) ext->o_offset);
650
651 #ifdef TEST
652 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
653 abort();
654 #endif
655 }
656
657 /* Swap out an optimization symbol. */
658
659 static void
660 ecoff_swap_opt_out (abfd, intern_copy, ext_ptr)
661 bfd *abfd;
662 const OPTR *intern_copy;
663 PTR ext_ptr;
664 {
665 struct opt_ext *ext = (struct opt_ext *) ext_ptr;
666 OPTR intern[1];
667
668 *intern = *intern_copy; /* Make it reasonable to do in-place. */
669
670 if (abfd->xvec->header_byteorder_big_p != false)
671 {
672 ext->o_bits1[0] = intern->ot;
673 ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
674 ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
675 ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
676 }
677 else
678 {
679 ext->o_bits1[0] = intern->ot;
680 ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
681 ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
682 ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
683 }
684
685 ecoff_swap_rndx_out (abfd->xvec->header_byteorder_big_p != false,
686 &intern->rndx, &ext->o_rndx);
687
688 bfd_h_put_32 (abfd, intern->value, (bfd_byte *) ext->o_offset);
689
690 #ifdef TEST
691 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
692 abort();
693 #endif
694 }
695
696 /* Swap in a dense number. */
697
698 static void
699 ecoff_swap_dnr_in (abfd, ext_copy, intern)
700 bfd *abfd;
701 PTR ext_copy;
702 DNR *intern;
703 {
704 struct dnr_ext ext[1];
705
706 *ext = *(struct dnr_ext *) ext_copy;
707
708 intern->rfd = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_rfd);
709 intern->index = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_index);
710
711 #ifdef TEST
712 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
713 abort();
714 #endif
715 }
716
717 /* Swap out a dense number. */
718
719 static void
720 ecoff_swap_dnr_out (abfd, intern_copy, ext_ptr)
721 bfd *abfd;
722 const DNR *intern_copy;
723 PTR ext_ptr;
724 {
725 struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
726 DNR intern[1];
727
728 *intern = *intern_copy; /* Make it reasonable to do in-place. */
729
730 bfd_h_put_32 (abfd, intern->rfd, (bfd_byte *) ext->d_rfd);
731 bfd_h_put_32 (abfd, intern->index, (bfd_byte *) ext->d_index);
732
733 #ifdef TEST
734 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
735 abort();
736 #endif
737 }