PR 11042
[deliverable/binutils-gdb.git] / bfd / ecoffswap.h
CommitLineData
252b5132 1/* Generic ECOFF swapping routines, for BFD.
cd123cb7
NC
2 Copyright 1992, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2004, 2005,
3 2007 Free Software Foundation, Inc.
252b5132
RH
4 Written by Cygnus Support.
5
1c59ba3f 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
1c59ba3f
NC
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
cd123cb7 10 the Free Software Foundation; either version 3 of the License, or
1c59ba3f 11 (at your option) any later version.
252b5132 12
1c59ba3f
NC
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.
252b5132 17
1c59ba3f
NC
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
cd123cb7
NC
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
22
252b5132
RH
23
24/* NOTE: This is a header file, but it contains executable routines.
25 This is done this way because these routines are substantially
26 similar, but are not identical, for all ECOFF targets.
27
28 These are routines to swap the ECOFF symbolic information in and
29 out. The routines are defined statically. You can set breakpoints
30 on them in gdb by naming the including source file; e.g.,
31 'coff-mips.c':ecoff_swap_hdr_in.
32
23e2c83b
AC
33 Before including this header file, one of ECOFF_32, ECOFF_64,
34 ECOFF_SIGNED_32 or ECOFF_SIGNED_64 must be defined. These are
35 checked when swapping information that depends upon the target
36 size. This code works for 32 bit and 64 bit ECOFF, but may need to
37 be generalized in the future.
252b5132
RH
38
39 Some header file which defines the external forms of these
40 structures must also be included before including this header file.
41 Currently this is either coff/mips.h or coff/alpha.h.
42
43 If the symbol TEST is defined when this file is compiled, a
44 comparison is made to ensure that, in fact, the output is
45 bit-for-bit the same as the input. Of course, this symbol should
46 only be defined when deliberately testing the code on a machine
47 with the proper byte sex and such. */
48
49#ifdef ECOFF_32
dc810e39
AM
50#define ECOFF_GET_OFF H_GET_32
51#define ECOFF_PUT_OFF H_PUT_32
252b5132
RH
52#endif
53#ifdef ECOFF_64
dc810e39
AM
54#define ECOFF_GET_OFF H_GET_64
55#define ECOFF_PUT_OFF H_PUT_64
252b5132 56#endif
23e2c83b 57#ifdef ECOFF_SIGNED_32
dc810e39
AM
58#define ECOFF_GET_OFF H_GET_S32
59#define ECOFF_PUT_OFF H_PUT_S32
23e2c83b
AC
60#endif
61#ifdef ECOFF_SIGNED_64
dc810e39
AM
62#define ECOFF_GET_OFF H_GET_S64
63#define ECOFF_PUT_OFF H_PUT_S64
23e2c83b 64#endif
252b5132
RH
65
66/* ECOFF auxiliary information swapping routines. These are the same
67 for all ECOFF targets, so they are defined in ecofflink.c. */
68
69extern void _bfd_ecoff_swap_tir_in
116c20d2 70 (int, const struct tir_ext *, TIR *);
252b5132 71extern void _bfd_ecoff_swap_tir_out
116c20d2 72 (int, const TIR *, struct tir_ext *);
252b5132 73extern void _bfd_ecoff_swap_rndx_in
116c20d2 74 (int, const struct rndx_ext *, RNDXR *);
252b5132 75extern void _bfd_ecoff_swap_rndx_out
116c20d2 76 (int, const RNDXR *, struct rndx_ext *);
252b5132
RH
77
78/* Prototypes for functions defined in this file. */
79
116c20d2
NC
80static void ecoff_swap_hdr_in (bfd *, void *, HDRR *);
81static void ecoff_swap_hdr_out (bfd *, const HDRR *, void *);
82static void ecoff_swap_fdr_in (bfd *, void *, FDR *);
83static void ecoff_swap_fdr_out (bfd *, const FDR *, void *);
84static void ecoff_swap_pdr_in (bfd *, void *, PDR *);
85static void ecoff_swap_pdr_out (bfd *, const PDR *, void *);
86static void ecoff_swap_sym_in (bfd *, void *, SYMR *);
87static void ecoff_swap_sym_out (bfd *, const SYMR *, void *);
88static void ecoff_swap_ext_in (bfd *, void *, EXTR *);
89static void ecoff_swap_ext_out (bfd *, const EXTR *, void *);
90static void ecoff_swap_rfd_in (bfd *, void *, RFDT *);
91static void ecoff_swap_rfd_out (bfd *, const RFDT *, void *);
92static void ecoff_swap_opt_in (bfd *, void *, OPTR *);
93static void ecoff_swap_opt_out (bfd *, const OPTR *, void *);
94static void ecoff_swap_dnr_in (bfd *, void *, DNR *);
95static void ecoff_swap_dnr_out (bfd *, const DNR *, void *);
252b5132
RH
96
97/* Swap in the symbolic header. */
98
99static void
116c20d2 100ecoff_swap_hdr_in (bfd *abfd, void * ext_copy, HDRR *intern)
252b5132
RH
101{
102 struct hdr_ext ext[1];
103
104 *ext = *(struct hdr_ext *) ext_copy;
105
dc810e39
AM
106 intern->magic = H_GET_S16 (abfd, ext->h_magic);
107 intern->vstamp = H_GET_S16 (abfd, ext->h_vstamp);
108 intern->ilineMax = H_GET_32 (abfd, ext->h_ilineMax);
109 intern->cbLine = ECOFF_GET_OFF (abfd, ext->h_cbLine);
110 intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->h_cbLineOffset);
111 intern->idnMax = H_GET_32 (abfd, ext->h_idnMax);
112 intern->cbDnOffset = ECOFF_GET_OFF (abfd, ext->h_cbDnOffset);
113 intern->ipdMax = H_GET_32 (abfd, ext->h_ipdMax);
114 intern->cbPdOffset = ECOFF_GET_OFF (abfd, ext->h_cbPdOffset);
115 intern->isymMax = H_GET_32 (abfd, ext->h_isymMax);
116 intern->cbSymOffset = ECOFF_GET_OFF (abfd, ext->h_cbSymOffset);
117 intern->ioptMax = H_GET_32 (abfd, ext->h_ioptMax);
118 intern->cbOptOffset = ECOFF_GET_OFF (abfd, ext->h_cbOptOffset);
119 intern->iauxMax = H_GET_32 (abfd, ext->h_iauxMax);
120 intern->cbAuxOffset = ECOFF_GET_OFF (abfd, ext->h_cbAuxOffset);
121 intern->issMax = H_GET_32 (abfd, ext->h_issMax);
122 intern->cbSsOffset = ECOFF_GET_OFF (abfd, ext->h_cbSsOffset);
123 intern->issExtMax = H_GET_32 (abfd, ext->h_issExtMax);
124 intern->cbSsExtOffset = ECOFF_GET_OFF (abfd, ext->h_cbSsExtOffset);
125 intern->ifdMax = H_GET_32 (abfd, ext->h_ifdMax);
126 intern->cbFdOffset = ECOFF_GET_OFF (abfd, ext->h_cbFdOffset);
127 intern->crfd = H_GET_32 (abfd, ext->h_crfd);
128 intern->cbRfdOffset = ECOFF_GET_OFF (abfd, ext->h_cbRfdOffset);
129 intern->iextMax = H_GET_32 (abfd, ext->h_iextMax);
130 intern->cbExtOffset = ECOFF_GET_OFF (abfd, ext->h_cbExtOffset);
252b5132
RH
131
132#ifdef TEST
116c20d2 133 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 134 abort ();
252b5132
RH
135#endif
136}
137
138/* Swap out the symbolic header. */
139
140static void
116c20d2 141ecoff_swap_hdr_out (bfd *abfd, const HDRR *intern_copy, void * ext_ptr)
252b5132
RH
142{
143 struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
144 HDRR intern[1];
145
146 *intern = *intern_copy;
147
dc810e39
AM
148 H_PUT_S16 (abfd, intern->magic, ext->h_magic);
149 H_PUT_S16 (abfd, intern->vstamp, ext->h_vstamp);
150 H_PUT_32 (abfd, intern->ilineMax, ext->h_ilineMax);
151 ECOFF_PUT_OFF (abfd, intern->cbLine, ext->h_cbLine);
152 ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->h_cbLineOffset);
153 H_PUT_32 (abfd, intern->idnMax, ext->h_idnMax);
154 ECOFF_PUT_OFF (abfd, intern->cbDnOffset, ext->h_cbDnOffset);
155 H_PUT_32 (abfd, intern->ipdMax, ext->h_ipdMax);
156 ECOFF_PUT_OFF (abfd, intern->cbPdOffset, ext->h_cbPdOffset);
157 H_PUT_32 (abfd, intern->isymMax, ext->h_isymMax);
158 ECOFF_PUT_OFF (abfd, intern->cbSymOffset, ext->h_cbSymOffset);
159 H_PUT_32 (abfd, intern->ioptMax, ext->h_ioptMax);
160 ECOFF_PUT_OFF (abfd, intern->cbOptOffset, ext->h_cbOptOffset);
161 H_PUT_32 (abfd, intern->iauxMax, ext->h_iauxMax);
162 ECOFF_PUT_OFF (abfd, intern->cbAuxOffset, ext->h_cbAuxOffset);
163 H_PUT_32 (abfd, intern->issMax, ext->h_issMax);
164 ECOFF_PUT_OFF (abfd, intern->cbSsOffset, ext->h_cbSsOffset);
165 H_PUT_32 (abfd, intern->issExtMax, ext->h_issExtMax);
166 ECOFF_PUT_OFF (abfd, intern->cbSsExtOffset, ext->h_cbSsExtOffset);
167 H_PUT_32 (abfd, intern->ifdMax, ext->h_ifdMax);
168 ECOFF_PUT_OFF (abfd, intern->cbFdOffset, ext->h_cbFdOffset);
169 H_PUT_32 (abfd, intern->crfd, ext->h_crfd);
170 ECOFF_PUT_OFF (abfd, intern->cbRfdOffset, ext->h_cbRfdOffset);
171 H_PUT_32 (abfd, intern->iextMax, ext->h_iextMax);
172 ECOFF_PUT_OFF (abfd, intern->cbExtOffset, ext->h_cbExtOffset);
252b5132
RH
173
174#ifdef TEST
dc810e39 175 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 176 abort ();
252b5132
RH
177#endif
178}
179
180/* Swap in the file descriptor record. */
181
182static void
116c20d2 183ecoff_swap_fdr_in (bfd *abfd, void * ext_copy, FDR *intern)
252b5132
RH
184{
185 struct fdr_ext ext[1];
186
187 *ext = *(struct fdr_ext *) ext_copy;
3e932841 188
dc810e39
AM
189 intern->adr = ECOFF_GET_OFF (abfd, ext->f_adr);
190 intern->rss = H_GET_32 (abfd, ext->f_rss);
23e2c83b 191#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
062e2358 192 if (intern->rss == (signed long) 0xffffffff)
252b5132
RH
193 intern->rss = -1;
194#endif
dc810e39
AM
195 intern->issBase = H_GET_32 (abfd, ext->f_issBase);
196 intern->cbSs = ECOFF_GET_OFF (abfd, ext->f_cbSs);
197 intern->isymBase = H_GET_32 (abfd, ext->f_isymBase);
198 intern->csym = H_GET_32 (abfd, ext->f_csym);
199 intern->ilineBase = H_GET_32 (abfd, ext->f_ilineBase);
200 intern->cline = H_GET_32 (abfd, ext->f_cline);
201 intern->ioptBase = H_GET_32 (abfd, ext->f_ioptBase);
202 intern->copt = H_GET_32 (abfd, ext->f_copt);
23e2c83b 203#if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
dc810e39
AM
204 intern->ipdFirst = H_GET_16 (abfd, ext->f_ipdFirst);
205 intern->cpd = H_GET_16 (abfd, ext->f_cpd);
252b5132 206#endif
23e2c83b 207#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
dc810e39
AM
208 intern->ipdFirst = H_GET_32 (abfd, ext->f_ipdFirst);
209 intern->cpd = H_GET_32 (abfd, ext->f_cpd);
252b5132 210#endif
dc810e39
AM
211 intern->iauxBase = H_GET_32 (abfd, ext->f_iauxBase);
212 intern->caux = H_GET_32 (abfd, ext->f_caux);
213 intern->rfdBase = H_GET_32 (abfd, ext->f_rfdBase);
214 intern->crfd = H_GET_32 (abfd, ext->f_crfd);
252b5132 215
1c59ba3f 216 /* Now the fun stuff... */
dc810e39
AM
217 if (bfd_header_big_endian (abfd))
218 {
219 intern->lang = ((ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
220 >> FDR_BITS1_LANG_SH_BIG);
221 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
222 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
223 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
224 intern->glevel = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
225 >> FDR_BITS2_GLEVEL_SH_BIG);
226 }
227 else
228 {
229 intern->lang = ((ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
230 >> FDR_BITS1_LANG_SH_LITTLE);
231 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
232 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
233 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
234 intern->glevel = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
235 >> FDR_BITS2_GLEVEL_SH_LITTLE);
236 }
252b5132
RH
237 intern->reserved = 0;
238
dc810e39
AM
239 intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->f_cbLineOffset);
240 intern->cbLine = ECOFF_GET_OFF (abfd, ext->f_cbLine);
252b5132
RH
241
242#ifdef TEST
116c20d2 243 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 244 abort ();
252b5132
RH
245#endif
246}
247
248/* Swap out the file descriptor record. */
249
250static void
116c20d2 251ecoff_swap_fdr_out (bfd *abfd, const FDR *intern_copy, void * ext_ptr)
252b5132
RH
252{
253 struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
254 FDR intern[1];
255
1c59ba3f
NC
256 /* Make it reasonable to do in-place. */
257 *intern = *intern_copy;
3e932841 258
dc810e39
AM
259 ECOFF_PUT_OFF (abfd, intern->adr, ext->f_adr);
260 H_PUT_32 (abfd, intern->rss, ext->f_rss);
261 H_PUT_32 (abfd, intern->issBase, ext->f_issBase);
262 ECOFF_PUT_OFF (abfd, intern->cbSs, ext->f_cbSs);
263 H_PUT_32 (abfd, intern->isymBase, ext->f_isymBase);
264 H_PUT_32 (abfd, intern->csym, ext->f_csym);
265 H_PUT_32 (abfd, intern->ilineBase, ext->f_ilineBase);
266 H_PUT_32 (abfd, intern->cline, ext->f_cline);
267 H_PUT_32 (abfd, intern->ioptBase, ext->f_ioptBase);
268 H_PUT_32 (abfd, intern->copt, ext->f_copt);
23e2c83b 269#if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
dc810e39
AM
270 H_PUT_16 (abfd, intern->ipdFirst, ext->f_ipdFirst);
271 H_PUT_16 (abfd, intern->cpd, ext->f_cpd);
252b5132 272#endif
23e2c83b 273#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
dc810e39
AM
274 H_PUT_32 (abfd, intern->ipdFirst, ext->f_ipdFirst);
275 H_PUT_32 (abfd, intern->cpd, ext->f_cpd);
252b5132 276#endif
dc810e39
AM
277 H_PUT_32 (abfd, intern->iauxBase, ext->f_iauxBase);
278 H_PUT_32 (abfd, intern->caux, ext->f_caux);
279 H_PUT_32 (abfd, intern->rfdBase, ext->f_rfdBase);
280 H_PUT_32 (abfd, intern->crfd, ext->f_crfd);
252b5132 281
1c59ba3f 282 /* Now the fun stuff... */
dc810e39
AM
283 if (bfd_header_big_endian (abfd))
284 {
285 ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
286 & FDR_BITS1_LANG_BIG)
287 | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
288 | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
289 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
290 ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
291 & FDR_BITS2_GLEVEL_BIG);
292 ext->f_bits2[1] = 0;
293 ext->f_bits2[2] = 0;
294 }
295 else
296 {
297 ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
298 & FDR_BITS1_LANG_LITTLE)
299 | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
300 | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
301 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
302 ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
303 & FDR_BITS2_GLEVEL_LITTLE);
304 ext->f_bits2[1] = 0;
305 ext->f_bits2[2] = 0;
306 }
252b5132 307
dc810e39
AM
308 ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->f_cbLineOffset);
309 ECOFF_PUT_OFF (abfd, intern->cbLine, ext->f_cbLine);
252b5132
RH
310
311#ifdef TEST
116c20d2 312 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 313 abort ();
252b5132
RH
314#endif
315}
316
252b5132
RH
317/* Swap in the procedure descriptor record. */
318
319static void
116c20d2 320ecoff_swap_pdr_in (bfd *abfd, void * ext_copy, PDR *intern)
252b5132
RH
321{
322 struct pdr_ext ext[1];
323
324 *ext = *(struct pdr_ext *) ext_copy;
325
116c20d2 326 memset ((void *) intern, 0, sizeof (*intern));
252b5132 327
dc810e39
AM
328 intern->adr = ECOFF_GET_OFF (abfd, ext->p_adr);
329 intern->isym = H_GET_32 (abfd, ext->p_isym);
330 intern->iline = H_GET_32 (abfd, ext->p_iline);
331 intern->regmask = H_GET_32 (abfd, ext->p_regmask);
332 intern->regoffset = H_GET_S32 (abfd, ext->p_regoffset);
333 intern->iopt = H_GET_S32 (abfd, ext->p_iopt);
334 intern->fregmask = H_GET_32 (abfd, ext->p_fregmask);
335 intern->fregoffset = H_GET_S32 (abfd, ext->p_fregoffset);
336 intern->frameoffset = H_GET_S32 (abfd, ext->p_frameoffset);
337 intern->framereg = H_GET_16 (abfd, ext->p_framereg);
338 intern->pcreg = H_GET_16 (abfd, ext->p_pcreg);
339 intern->lnLow = H_GET_32 (abfd, ext->p_lnLow);
340 intern->lnHigh = H_GET_32 (abfd, ext->p_lnHigh);
341 intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->p_cbLineOffset);
252b5132 342
23e2c83b 343#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
1c59ba3f
NC
344 if (intern->isym == (signed long) 0xffffffff)
345 intern->isym = -1;
346 if (intern->iline == (signed long) 0xffffffff)
347 intern->iline = -1;
348
dc810e39 349 intern->gp_prologue = H_GET_8 (abfd, ext->p_gp_prologue);
252b5132
RH
350 if (bfd_header_big_endian (abfd))
351 {
352 intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
353 intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
354 intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_BIG);
355 intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
356 << PDR_BITS1_RESERVED_SH_LEFT_BIG)
357 | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
358 >> PDR_BITS2_RESERVED_SH_BIG));
359 }
360 else
361 {
362 intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
363 intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
364 intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_LITTLE);
365 intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
366 >> PDR_BITS1_RESERVED_SH_LITTLE)
367 | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
368 << PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
369 }
dc810e39 370 intern->localoff = H_GET_8 (abfd, ext->p_localoff);
3e932841 371#endif
252b5132
RH
372
373#ifdef TEST
116c20d2 374 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 375 abort ();
252b5132
RH
376#endif
377}
378
379/* Swap out the procedure descriptor record. */
380
381static void
116c20d2 382ecoff_swap_pdr_out (bfd *abfd, const PDR *intern_copy, void * ext_ptr)
252b5132
RH
383{
384 struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
385 PDR intern[1];
386
1c59ba3f
NC
387 /* Make it reasonable to do in-place. */
388 *intern = *intern_copy;
3e932841 389
dc810e39
AM
390 ECOFF_PUT_OFF (abfd, intern->adr, ext->p_adr);
391 H_PUT_32 (abfd, intern->isym, ext->p_isym);
392 H_PUT_32 (abfd, intern->iline, ext->p_iline);
393 H_PUT_32 (abfd, intern->regmask, ext->p_regmask);
394 H_PUT_32 (abfd, intern->regoffset, ext->p_regoffset);
395 H_PUT_32 (abfd, intern->iopt, ext->p_iopt);
396 H_PUT_32 (abfd, intern->fregmask, ext->p_fregmask);
397 H_PUT_32 (abfd, intern->fregoffset, ext->p_fregoffset);
398 H_PUT_32 (abfd, intern->frameoffset, ext->p_frameoffset);
399 H_PUT_16 (abfd, intern->framereg, ext->p_framereg);
400 H_PUT_16 (abfd, intern->pcreg, ext->p_pcreg);
401 H_PUT_32 (abfd, intern->lnLow, ext->p_lnLow);
402 H_PUT_32 (abfd, intern->lnHigh, ext->p_lnHigh);
403 ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->p_cbLineOffset);
252b5132 404
23e2c83b 405#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
dc810e39
AM
406 H_PUT_8 (abfd, intern->gp_prologue, ext->p_gp_prologue);
407
252b5132
RH
408 if (bfd_header_big_endian (abfd))
409 {
410 ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
411 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
412 | (intern->prof ? PDR_BITS1_PROF_BIG : 0)
413 | ((intern->reserved
414 >> PDR_BITS1_RESERVED_SH_LEFT_BIG)
415 & PDR_BITS1_RESERVED_BIG));
416 ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
417 & PDR_BITS2_RESERVED_BIG);
418 }
419 else
420 {
421 ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
422 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
423 | (intern->prof ? PDR_BITS1_PROF_LITTLE : 0)
424 | ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
425 & PDR_BITS1_RESERVED_LITTLE));
426 ext->p_bits2[0] = ((intern->reserved >>
427 PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
428 & PDR_BITS2_RESERVED_LITTLE);
429 }
dc810e39 430 H_PUT_8 (abfd, intern->localoff, ext->p_localoff);
3e932841 431#endif
252b5132
RH
432
433#ifdef TEST
116c20d2 434 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 435 abort ();
252b5132
RH
436#endif
437}
438
252b5132
RH
439/* Swap in a symbol record. */
440
441static void
116c20d2 442ecoff_swap_sym_in (bfd *abfd, void * ext_copy, SYMR *intern)
252b5132
RH
443{
444 struct sym_ext ext[1];
445
446 *ext = *(struct sym_ext *) ext_copy;
3e932841 447
dc810e39
AM
448 intern->iss = H_GET_32 (abfd, ext->s_iss);
449 intern->value = ECOFF_GET_OFF (abfd, ext->s_value);
252b5132 450
1c59ba3f
NC
451#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
452 if (intern->iss == (signed long) 0xffffffff)
453 intern->iss = -1;
454#endif
455
456 /* Now the fun stuff... */
457 if (bfd_header_big_endian (abfd))
458 {
459 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
460 >> SYM_BITS1_ST_SH_BIG;
461 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
462 << SYM_BITS1_SC_SH_LEFT_BIG)
463 | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
464 >> SYM_BITS2_SC_SH_BIG);
465 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
466 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
467 << SYM_BITS2_INDEX_SH_LEFT_BIG)
468 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
469 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
470 }
471 else
472 {
473 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
474 >> SYM_BITS1_ST_SH_LITTLE;
475 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
476 >> SYM_BITS1_SC_SH_LITTLE)
477 | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
478 << SYM_BITS2_SC_SH_LEFT_LITTLE);
479 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
480 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
481 >> SYM_BITS2_INDEX_SH_LITTLE)
482 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
483 | ((unsigned int) ext->s_bits4[0]
484 << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
485 }
252b5132
RH
486
487#ifdef TEST
116c20d2 488 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 489 abort ();
252b5132
RH
490#endif
491}
492
493/* Swap out a symbol record. */
494
495static void
116c20d2 496ecoff_swap_sym_out (bfd *abfd, const SYMR *intern_copy, void * ext_ptr)
252b5132
RH
497{
498 struct sym_ext *ext = (struct sym_ext *) ext_ptr;
499 SYMR intern[1];
500
1c59ba3f
NC
501 /* Make it reasonable to do in-place. */
502 *intern = *intern_copy;
3e932841 503
dc810e39
AM
504 H_PUT_32 (abfd, intern->iss, ext->s_iss);
505 ECOFF_PUT_OFF (abfd, intern->value, ext->s_value);
252b5132 506
1c59ba3f
NC
507 /* Now the fun stuff... */
508 if (bfd_header_big_endian (abfd))
509 {
510 ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
511 & SYM_BITS1_ST_BIG)
512 | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
513 & SYM_BITS1_SC_BIG));
514 ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
515 & SYM_BITS2_SC_BIG)
516 | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
517 | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
518 & SYM_BITS2_INDEX_BIG));
519 ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
520 ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
521 }
522 else
523 {
524 ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
525 & SYM_BITS1_ST_LITTLE)
526 | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
527 & SYM_BITS1_SC_LITTLE));
528 ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
529 & SYM_BITS2_SC_LITTLE)
530 | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
531 | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
532 & SYM_BITS2_INDEX_LITTLE));
533 ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
534 ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
535 }
252b5132
RH
536
537#ifdef TEST
116c20d2 538 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 539 abort ();
252b5132
RH
540#endif
541}
542
543/* Swap in an external symbol record. */
544
545static void
116c20d2 546ecoff_swap_ext_in (bfd *abfd, void * ext_copy, EXTR *intern)
252b5132
RH
547{
548 struct ext_ext ext[1];
549
550 *ext = *(struct ext_ext *) ext_copy;
3e932841 551
1c59ba3f
NC
552 /* Now the fun stuff... */
553 if (bfd_header_big_endian (abfd))
554 {
555 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
556 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
557 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
558 }
559 else
560 {
561 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
562 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
563 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
564 }
252b5132
RH
565 intern->reserved = 0;
566
23e2c83b 567#if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
1c59ba3f 568 intern->ifd = H_GET_S16 (abfd, ext->es_ifd);
252b5132 569#endif
23e2c83b 570#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
1c59ba3f 571 intern->ifd = H_GET_S32 (abfd, ext->es_ifd);
252b5132
RH
572#endif
573
574 ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
575
576#ifdef TEST
116c20d2 577 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 578 abort ();
252b5132
RH
579#endif
580}
581
582/* Swap out an external symbol record. */
583
584static void
116c20d2 585ecoff_swap_ext_out (bfd *abfd, const EXTR *intern_copy, void * ext_ptr)
252b5132
RH
586{
587 struct ext_ext *ext = (struct ext_ext *) ext_ptr;
588 EXTR intern[1];
589
1c59ba3f
NC
590 /* Make it reasonable to do in-place. */
591 *intern = *intern_copy;
3e932841 592
1c59ba3f
NC
593 /* Now the fun stuff... */
594 if (bfd_header_big_endian (abfd))
595 {
596 ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
597 | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
598 | (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
599 ext->es_bits2[0] = 0;
23e2c83b 600#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
1c59ba3f
NC
601 ext->es_bits2[1] = 0;
602 ext->es_bits2[2] = 0;
603#endif
604 }
605 else
606 {
607 ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
608 | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
609 | (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
610 ext->es_bits2[0] = 0;
23e2c83b 611#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
1c59ba3f
NC
612 ext->es_bits2[1] = 0;
613 ext->es_bits2[2] = 0;
252b5132 614#endif
1c59ba3f 615 }
252b5132 616
23e2c83b 617#if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
dc810e39 618 H_PUT_S16 (abfd, intern->ifd, ext->es_ifd);
252b5132 619#endif
23e2c83b 620#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
dc810e39 621 H_PUT_S32 (abfd, intern->ifd, ext->es_ifd);
252b5132
RH
622#endif
623
624 ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
625
626#ifdef TEST
116c20d2 627 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 628 abort ();
252b5132
RH
629#endif
630}
631
632/* Swap in a relative file descriptor. */
633
634static void
116c20d2 635ecoff_swap_rfd_in (bfd *abfd, void * ext_ptr, RFDT *intern)
252b5132
RH
636{
637 struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
638
dc810e39 639 *intern = H_GET_32 (abfd, ext->rfd);
252b5132
RH
640
641#ifdef TEST
116c20d2 642 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 643 abort ();
252b5132
RH
644#endif
645}
646
647/* Swap out a relative file descriptor. */
648
649static void
116c20d2 650ecoff_swap_rfd_out (bfd *abfd, const RFDT *intern, void * ext_ptr)
252b5132
RH
651{
652 struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
653
dc810e39 654 H_PUT_32 (abfd, *intern, ext->rfd);
252b5132
RH
655
656#ifdef TEST
116c20d2 657 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 658 abort ();
252b5132
RH
659#endif
660}
661
662/* Swap in an optimization symbol. */
663
664static void
116c20d2 665ecoff_swap_opt_in (bfd *abfd, void * ext_copy, OPTR * intern)
252b5132
RH
666{
667 struct opt_ext ext[1];
668
669 *ext = *(struct opt_ext *) ext_copy;
670
671 if (bfd_header_big_endian (abfd))
672 {
673 intern->ot = ext->o_bits1[0];
674 intern->value = (((unsigned int) ext->o_bits2[0]
675 << OPT_BITS2_VALUE_SH_LEFT_BIG)
676 | ((unsigned int) ext->o_bits3[0]
677 << OPT_BITS2_VALUE_SH_LEFT_BIG)
678 | ((unsigned int) ext->o_bits4[0]
679 << OPT_BITS2_VALUE_SH_LEFT_BIG));
680 }
681 else
682 {
683 intern->ot = ext->o_bits1[0];
684 intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
685 | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
686 | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
687 }
688
689 _bfd_ecoff_swap_rndx_in (bfd_header_big_endian (abfd),
690 &ext->o_rndx, &intern->rndx);
691
dc810e39 692 intern->offset = H_GET_32 (abfd, ext->o_offset);
252b5132
RH
693
694#ifdef TEST
116c20d2 695 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 696 abort ();
252b5132
RH
697#endif
698}
699
700/* Swap out an optimization symbol. */
701
702static void
116c20d2 703ecoff_swap_opt_out (bfd *abfd, const OPTR *intern_copy, void * ext_ptr)
252b5132
RH
704{
705 struct opt_ext *ext = (struct opt_ext *) ext_ptr;
706 OPTR intern[1];
707
1c59ba3f
NC
708 /* Make it reasonable to do in-place. */
709 *intern = *intern_copy;
252b5132
RH
710
711 if (bfd_header_big_endian (abfd))
712 {
713 ext->o_bits1[0] = intern->ot;
714 ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
715 ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
716 ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
717 }
718 else
719 {
720 ext->o_bits1[0] = intern->ot;
721 ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
722 ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
723 ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
724 }
725
726 _bfd_ecoff_swap_rndx_out (bfd_header_big_endian (abfd),
727 &intern->rndx, &ext->o_rndx);
728
dc810e39 729 H_PUT_32 (abfd, intern->value, ext->o_offset);
252b5132
RH
730
731#ifdef TEST
116c20d2 732 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 733 abort ();
252b5132
RH
734#endif
735}
736
737/* Swap in a dense number. */
738
739static void
116c20d2 740ecoff_swap_dnr_in (bfd *abfd, void * ext_copy, DNR *intern)
252b5132
RH
741{
742 struct dnr_ext ext[1];
743
744 *ext = *(struct dnr_ext *) ext_copy;
745
dc810e39
AM
746 intern->rfd = H_GET_32 (abfd, ext->d_rfd);
747 intern->index = H_GET_32 (abfd, ext->d_index);
252b5132
RH
748
749#ifdef TEST
116c20d2 750 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 751 abort ();
252b5132
RH
752#endif
753}
754
755/* Swap out a dense number. */
756
757static void
116c20d2 758ecoff_swap_dnr_out (bfd *abfd, const DNR *intern_copy, void * ext_ptr)
252b5132
RH
759{
760 struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
761 DNR intern[1];
762
1c59ba3f
NC
763 /* Make it reasonable to do in-place. */
764 *intern = *intern_copy;
252b5132 765
dc810e39
AM
766 H_PUT_32 (abfd, intern->rfd, ext->d_rfd);
767 H_PUT_32 (abfd, intern->index, ext->d_index);
252b5132
RH
768
769#ifdef TEST
116c20d2 770 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
3e932841 771 abort ();
252b5132
RH
772#endif
773}
This page took 0.507329 seconds and 4 git commands to generate.