daily update
[binutils.git] / bfd / ecoffswap.h
blob24627d021fc181314a392ff41528bea5624a4157
1 /* Generic ECOFF swapping routines, for BFD.
2 Copyright 1992, 1993, 1994, 1995, 1996, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* NOTE: This is a header file, but it contains executable routines.
23 This is done this way because these routines are substantially
24 similar, but are not identical, for all ECOFF targets.
26 These are routines to swap the ECOFF symbolic information in and
27 out. The routines are defined statically. You can set breakpoints
28 on them in gdb by naming the including source file; e.g.,
29 'coff-mips.c':ecoff_swap_hdr_in.
31 Before including this header file, one of ECOFF_32, ECOFF_64,
32 ECOFF_SIGNED_32 or ECOFF_SIGNED_64 must be defined. These are
33 checked when swapping information that depends upon the target
34 size. This code works for 32 bit and 64 bit ECOFF, but may need to
35 be generalized in the future.
37 Some header file which defines the external forms of these
38 structures must also be included before including this header file.
39 Currently this is either coff/mips.h or coff/alpha.h.
41 If the symbol TEST is defined when this file is compiled, a
42 comparison is made to ensure that, in fact, the output is
43 bit-for-bit the same as the input. Of course, this symbol should
44 only be defined when deliberately testing the code on a machine
45 with the proper byte sex and such. */
47 #ifdef ECOFF_32
48 #define ECOFF_GET_OFF H_GET_32
49 #define ECOFF_PUT_OFF H_PUT_32
50 #endif
51 #ifdef ECOFF_64
52 #define ECOFF_GET_OFF H_GET_64
53 #define ECOFF_PUT_OFF H_PUT_64
54 #endif
55 #ifdef ECOFF_SIGNED_32
56 #define ECOFF_GET_OFF H_GET_S32
57 #define ECOFF_PUT_OFF H_PUT_S32
58 #endif
59 #ifdef ECOFF_SIGNED_64
60 #define ECOFF_GET_OFF H_GET_S64
61 #define ECOFF_PUT_OFF H_PUT_S64
62 #endif
64 /* ECOFF auxiliary information swapping routines. These are the same
65 for all ECOFF targets, so they are defined in ecofflink.c. */
67 extern void _bfd_ecoff_swap_tir_in
68 PARAMS ((int, const struct tir_ext *, TIR *));
69 extern void _bfd_ecoff_swap_tir_out
70 PARAMS ((int, const TIR *, struct tir_ext *));
71 extern void _bfd_ecoff_swap_rndx_in
72 PARAMS ((int, const struct rndx_ext *, RNDXR *));
73 extern void _bfd_ecoff_swap_rndx_out
74 PARAMS ((int, const RNDXR *, struct rndx_ext *));
76 /* Prototypes for functions defined in this file. */
78 static void ecoff_swap_hdr_in PARAMS ((bfd *, PTR, HDRR *));
79 static void ecoff_swap_hdr_out PARAMS ((bfd *, const HDRR *, PTR));
80 static void ecoff_swap_fdr_in PARAMS ((bfd *, PTR, FDR *));
81 static void ecoff_swap_fdr_out PARAMS ((bfd *, const FDR *, PTR));
82 static void ecoff_swap_pdr_in PARAMS ((bfd *, PTR, PDR *));
83 static void ecoff_swap_pdr_out PARAMS ((bfd *, const PDR *, PTR));
84 static void ecoff_swap_sym_in PARAMS ((bfd *, PTR, SYMR *));
85 static void ecoff_swap_sym_out PARAMS ((bfd *, const SYMR *, PTR));
86 static void ecoff_swap_ext_in PARAMS ((bfd *, PTR, EXTR *));
87 static void ecoff_swap_ext_out PARAMS ((bfd *, const EXTR *, PTR));
88 static void ecoff_swap_rfd_in PARAMS ((bfd *, PTR, RFDT *));
89 static void ecoff_swap_rfd_out PARAMS ((bfd *, const RFDT *, PTR));
90 static void ecoff_swap_opt_in PARAMS ((bfd *, PTR, OPTR *));
91 static void ecoff_swap_opt_out PARAMS ((bfd *, const OPTR *, PTR));
92 static void ecoff_swap_dnr_in PARAMS ((bfd *, PTR, DNR *));
93 static void ecoff_swap_dnr_out PARAMS ((bfd *, const DNR *, PTR));
95 /* Swap in the symbolic header. */
97 static void
98 ecoff_swap_hdr_in (abfd, ext_copy, intern)
99 bfd *abfd;
100 PTR ext_copy;
101 HDRR *intern;
103 struct hdr_ext ext[1];
105 *ext = *(struct hdr_ext *) ext_copy;
107 intern->magic = H_GET_S16 (abfd, ext->h_magic);
108 intern->vstamp = H_GET_S16 (abfd, ext->h_vstamp);
109 intern->ilineMax = H_GET_32 (abfd, ext->h_ilineMax);
110 intern->cbLine = ECOFF_GET_OFF (abfd, ext->h_cbLine);
111 intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->h_cbLineOffset);
112 intern->idnMax = H_GET_32 (abfd, ext->h_idnMax);
113 intern->cbDnOffset = ECOFF_GET_OFF (abfd, ext->h_cbDnOffset);
114 intern->ipdMax = H_GET_32 (abfd, ext->h_ipdMax);
115 intern->cbPdOffset = ECOFF_GET_OFF (abfd, ext->h_cbPdOffset);
116 intern->isymMax = H_GET_32 (abfd, ext->h_isymMax);
117 intern->cbSymOffset = ECOFF_GET_OFF (abfd, ext->h_cbSymOffset);
118 intern->ioptMax = H_GET_32 (abfd, ext->h_ioptMax);
119 intern->cbOptOffset = ECOFF_GET_OFF (abfd, ext->h_cbOptOffset);
120 intern->iauxMax = H_GET_32 (abfd, ext->h_iauxMax);
121 intern->cbAuxOffset = ECOFF_GET_OFF (abfd, ext->h_cbAuxOffset);
122 intern->issMax = H_GET_32 (abfd, ext->h_issMax);
123 intern->cbSsOffset = ECOFF_GET_OFF (abfd, ext->h_cbSsOffset);
124 intern->issExtMax = H_GET_32 (abfd, ext->h_issExtMax);
125 intern->cbSsExtOffset = ECOFF_GET_OFF (abfd, ext->h_cbSsExtOffset);
126 intern->ifdMax = H_GET_32 (abfd, ext->h_ifdMax);
127 intern->cbFdOffset = ECOFF_GET_OFF (abfd, ext->h_cbFdOffset);
128 intern->crfd = H_GET_32 (abfd, ext->h_crfd);
129 intern->cbRfdOffset = ECOFF_GET_OFF (abfd, ext->h_cbRfdOffset);
130 intern->iextMax = H_GET_32 (abfd, ext->h_iextMax);
131 intern->cbExtOffset = ECOFF_GET_OFF (abfd, ext->h_cbExtOffset);
133 #ifdef TEST
134 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
135 abort ();
136 #endif
139 /* Swap out the symbolic header. */
141 static void
142 ecoff_swap_hdr_out (abfd, intern_copy, ext_ptr)
143 bfd *abfd;
144 const HDRR *intern_copy;
145 PTR ext_ptr;
147 struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
148 HDRR intern[1];
150 *intern = *intern_copy;
152 H_PUT_S16 (abfd, intern->magic, ext->h_magic);
153 H_PUT_S16 (abfd, intern->vstamp, ext->h_vstamp);
154 H_PUT_32 (abfd, intern->ilineMax, ext->h_ilineMax);
155 ECOFF_PUT_OFF (abfd, intern->cbLine, ext->h_cbLine);
156 ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->h_cbLineOffset);
157 H_PUT_32 (abfd, intern->idnMax, ext->h_idnMax);
158 ECOFF_PUT_OFF (abfd, intern->cbDnOffset, ext->h_cbDnOffset);
159 H_PUT_32 (abfd, intern->ipdMax, ext->h_ipdMax);
160 ECOFF_PUT_OFF (abfd, intern->cbPdOffset, ext->h_cbPdOffset);
161 H_PUT_32 (abfd, intern->isymMax, ext->h_isymMax);
162 ECOFF_PUT_OFF (abfd, intern->cbSymOffset, ext->h_cbSymOffset);
163 H_PUT_32 (abfd, intern->ioptMax, ext->h_ioptMax);
164 ECOFF_PUT_OFF (abfd, intern->cbOptOffset, ext->h_cbOptOffset);
165 H_PUT_32 (abfd, intern->iauxMax, ext->h_iauxMax);
166 ECOFF_PUT_OFF (abfd, intern->cbAuxOffset, ext->h_cbAuxOffset);
167 H_PUT_32 (abfd, intern->issMax, ext->h_issMax);
168 ECOFF_PUT_OFF (abfd, intern->cbSsOffset, ext->h_cbSsOffset);
169 H_PUT_32 (abfd, intern->issExtMax, ext->h_issExtMax);
170 ECOFF_PUT_OFF (abfd, intern->cbSsExtOffset, ext->h_cbSsExtOffset);
171 H_PUT_32 (abfd, intern->ifdMax, ext->h_ifdMax);
172 ECOFF_PUT_OFF (abfd, intern->cbFdOffset, ext->h_cbFdOffset);
173 H_PUT_32 (abfd, intern->crfd, ext->h_crfd);
174 ECOFF_PUT_OFF (abfd, intern->cbRfdOffset, ext->h_cbRfdOffset);
175 H_PUT_32 (abfd, intern->iextMax, ext->h_iextMax);
176 ECOFF_PUT_OFF (abfd, intern->cbExtOffset, ext->h_cbExtOffset);
178 #ifdef TEST
179 if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
180 abort ();
181 #endif
184 /* Swap in the file descriptor record. */
186 static void
187 ecoff_swap_fdr_in (abfd, ext_copy, intern)
188 bfd *abfd;
189 PTR ext_copy;
190 FDR *intern;
192 struct fdr_ext ext[1];
194 *ext = *(struct fdr_ext *) ext_copy;
196 intern->adr = ECOFF_GET_OFF (abfd, ext->f_adr);
197 intern->rss = H_GET_32 (abfd, ext->f_rss);
198 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
199 if (intern->rss == (signed long) 0xffffffff)
200 intern->rss = -1;
201 #endif
202 intern->issBase = H_GET_32 (abfd, ext->f_issBase);
203 intern->cbSs = ECOFF_GET_OFF (abfd, ext->f_cbSs);
204 intern->isymBase = H_GET_32 (abfd, ext->f_isymBase);
205 intern->csym = H_GET_32 (abfd, ext->f_csym);
206 intern->ilineBase = H_GET_32 (abfd, ext->f_ilineBase);
207 intern->cline = H_GET_32 (abfd, ext->f_cline);
208 intern->ioptBase = H_GET_32 (abfd, ext->f_ioptBase);
209 intern->copt = H_GET_32 (abfd, ext->f_copt);
210 #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
211 intern->ipdFirst = H_GET_16 (abfd, ext->f_ipdFirst);
212 intern->cpd = H_GET_16 (abfd, ext->f_cpd);
213 #endif
214 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
215 intern->ipdFirst = H_GET_32 (abfd, ext->f_ipdFirst);
216 intern->cpd = H_GET_32 (abfd, ext->f_cpd);
217 #endif
218 intern->iauxBase = H_GET_32 (abfd, ext->f_iauxBase);
219 intern->caux = H_GET_32 (abfd, ext->f_caux);
220 intern->rfdBase = H_GET_32 (abfd, ext->f_rfdBase);
221 intern->crfd = H_GET_32 (abfd, ext->f_crfd);
223 /* now the fun stuff... */
224 if (bfd_header_big_endian (abfd))
226 intern->lang = ((ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
227 >> FDR_BITS1_LANG_SH_BIG);
228 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
229 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
230 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
231 intern->glevel = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
232 >> FDR_BITS2_GLEVEL_SH_BIG);
234 else
236 intern->lang = ((ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
237 >> FDR_BITS1_LANG_SH_LITTLE);
238 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
239 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
240 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
241 intern->glevel = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
242 >> FDR_BITS2_GLEVEL_SH_LITTLE);
244 intern->reserved = 0;
246 intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->f_cbLineOffset);
247 intern->cbLine = ECOFF_GET_OFF (abfd, ext->f_cbLine);
249 #ifdef TEST
250 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
251 abort ();
252 #endif
255 /* Swap out the file descriptor record. */
257 static void
258 ecoff_swap_fdr_out (abfd, intern_copy, ext_ptr)
259 bfd *abfd;
260 const FDR *intern_copy;
261 PTR ext_ptr;
263 struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
264 FDR intern[1];
266 *intern = *intern_copy; /* Make it reasonable to do in-place. */
268 ECOFF_PUT_OFF (abfd, intern->adr, ext->f_adr);
269 H_PUT_32 (abfd, intern->rss, ext->f_rss);
270 H_PUT_32 (abfd, intern->issBase, ext->f_issBase);
271 ECOFF_PUT_OFF (abfd, intern->cbSs, ext->f_cbSs);
272 H_PUT_32 (abfd, intern->isymBase, ext->f_isymBase);
273 H_PUT_32 (abfd, intern->csym, ext->f_csym);
274 H_PUT_32 (abfd, intern->ilineBase, ext->f_ilineBase);
275 H_PUT_32 (abfd, intern->cline, ext->f_cline);
276 H_PUT_32 (abfd, intern->ioptBase, ext->f_ioptBase);
277 H_PUT_32 (abfd, intern->copt, ext->f_copt);
278 #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
279 H_PUT_16 (abfd, intern->ipdFirst, ext->f_ipdFirst);
280 H_PUT_16 (abfd, intern->cpd, ext->f_cpd);
281 #endif
282 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
283 H_PUT_32 (abfd, intern->ipdFirst, ext->f_ipdFirst);
284 H_PUT_32 (abfd, intern->cpd, ext->f_cpd);
285 #endif
286 H_PUT_32 (abfd, intern->iauxBase, ext->f_iauxBase);
287 H_PUT_32 (abfd, intern->caux, ext->f_caux);
288 H_PUT_32 (abfd, intern->rfdBase, ext->f_rfdBase);
289 H_PUT_32 (abfd, intern->crfd, ext->f_crfd);
291 /* now the fun stuff... */
292 if (bfd_header_big_endian (abfd))
294 ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
295 & FDR_BITS1_LANG_BIG)
296 | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
297 | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
298 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
299 ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
300 & FDR_BITS2_GLEVEL_BIG);
301 ext->f_bits2[1] = 0;
302 ext->f_bits2[2] = 0;
304 else
306 ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
307 & FDR_BITS1_LANG_LITTLE)
308 | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
309 | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
310 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
311 ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
312 & FDR_BITS2_GLEVEL_LITTLE);
313 ext->f_bits2[1] = 0;
314 ext->f_bits2[2] = 0;
317 ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->f_cbLineOffset);
318 ECOFF_PUT_OFF (abfd, intern->cbLine, ext->f_cbLine);
320 #ifdef TEST
321 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
322 abort ();
323 #endif
326 #ifndef MPW_C
328 /* Swap in the procedure descriptor record. */
330 static void
331 ecoff_swap_pdr_in (abfd, ext_copy, intern)
332 bfd *abfd;
333 PTR ext_copy;
334 PDR *intern;
336 struct pdr_ext ext[1];
338 *ext = *(struct pdr_ext *) ext_copy;
340 memset ((PTR) intern, 0, sizeof (*intern));
342 intern->adr = ECOFF_GET_OFF (abfd, ext->p_adr);
343 intern->isym = H_GET_32 (abfd, ext->p_isym);
344 intern->iline = H_GET_32 (abfd, ext->p_iline);
345 intern->regmask = H_GET_32 (abfd, ext->p_regmask);
346 intern->regoffset = H_GET_S32 (abfd, ext->p_regoffset);
347 intern->iopt = H_GET_S32 (abfd, ext->p_iopt);
348 intern->fregmask = H_GET_32 (abfd, ext->p_fregmask);
349 intern->fregoffset = H_GET_S32 (abfd, ext->p_fregoffset);
350 intern->frameoffset = H_GET_S32 (abfd, ext->p_frameoffset);
351 intern->framereg = H_GET_16 (abfd, ext->p_framereg);
352 intern->pcreg = H_GET_16 (abfd, ext->p_pcreg);
353 intern->lnLow = H_GET_32 (abfd, ext->p_lnLow);
354 intern->lnHigh = H_GET_32 (abfd, ext->p_lnHigh);
355 intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->p_cbLineOffset);
357 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
358 intern->gp_prologue = H_GET_8 (abfd, ext->p_gp_prologue);
359 if (bfd_header_big_endian (abfd))
361 intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
362 intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
363 intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_BIG);
364 intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
365 << PDR_BITS1_RESERVED_SH_LEFT_BIG)
366 | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
367 >> PDR_BITS2_RESERVED_SH_BIG));
369 else
371 intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
372 intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
373 intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_LITTLE);
374 intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
375 >> PDR_BITS1_RESERVED_SH_LITTLE)
376 | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
377 << PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
379 intern->localoff = H_GET_8 (abfd, ext->p_localoff);
380 #endif
382 #ifdef TEST
383 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
384 abort ();
385 #endif
388 /* Swap out the procedure descriptor record. */
390 static void
391 ecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
392 bfd *abfd;
393 const PDR *intern_copy;
394 PTR ext_ptr;
396 struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
397 PDR intern[1];
399 *intern = *intern_copy; /* Make it reasonable to do in-place. */
401 ECOFF_PUT_OFF (abfd, intern->adr, ext->p_adr);
402 H_PUT_32 (abfd, intern->isym, ext->p_isym);
403 H_PUT_32 (abfd, intern->iline, ext->p_iline);
404 H_PUT_32 (abfd, intern->regmask, ext->p_regmask);
405 H_PUT_32 (abfd, intern->regoffset, ext->p_regoffset);
406 H_PUT_32 (abfd, intern->iopt, ext->p_iopt);
407 H_PUT_32 (abfd, intern->fregmask, ext->p_fregmask);
408 H_PUT_32 (abfd, intern->fregoffset, ext->p_fregoffset);
409 H_PUT_32 (abfd, intern->frameoffset, ext->p_frameoffset);
410 H_PUT_16 (abfd, intern->framereg, ext->p_framereg);
411 H_PUT_16 (abfd, intern->pcreg, ext->p_pcreg);
412 H_PUT_32 (abfd, intern->lnLow, ext->p_lnLow);
413 H_PUT_32 (abfd, intern->lnHigh, ext->p_lnHigh);
414 ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->p_cbLineOffset);
416 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
417 H_PUT_8 (abfd, intern->gp_prologue, ext->p_gp_prologue);
419 if (bfd_header_big_endian (abfd))
421 ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
422 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
423 | (intern->prof ? PDR_BITS1_PROF_BIG : 0)
424 | ((intern->reserved
425 >> PDR_BITS1_RESERVED_SH_LEFT_BIG)
426 & PDR_BITS1_RESERVED_BIG));
427 ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
428 & PDR_BITS2_RESERVED_BIG);
430 else
432 ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
433 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
434 | (intern->prof ? PDR_BITS1_PROF_LITTLE : 0)
435 | ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
436 & PDR_BITS1_RESERVED_LITTLE));
437 ext->p_bits2[0] = ((intern->reserved >>
438 PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
439 & PDR_BITS2_RESERVED_LITTLE);
441 H_PUT_8 (abfd, intern->localoff, ext->p_localoff);
442 #endif
444 #ifdef TEST
445 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
446 abort ();
447 #endif
450 #else /* MPW_C */
451 /* Same routines, but with ECOFF_64 code removed, so ^&%$#&! MPW C doesn't
452 corrupt itself and then freak out. */
453 /* Swap in the procedure descriptor record. */
455 static void
456 ecoff_swap_pdr_in (abfd, ext_copy, intern)
457 bfd *abfd;
458 PTR ext_copy;
459 PDR *intern;
461 struct pdr_ext ext[1];
463 *ext = *(struct pdr_ext *) ext_copy;
465 intern->adr = ECOFF_GET_OFF (abfd, ext->p_adr);
466 intern->isym = H_GET_32 (abfd, ext->p_isym);
467 intern->iline = H_GET_32 (abfd, ext->p_iline);
468 intern->regmask = H_GET_32 (abfd, ext->p_regmask);
469 intern->regoffset = H_GET_S32 (abfd, ext->p_regoffset);
470 intern->iopt = H_GET_S32 (abfd, ext->p_iopt);
471 intern->fregmask = H_GET_32 (abfd, ext->p_fregmask);
472 intern->fregoffset = H_GET_S32 (abfd, ext->p_fregoffset);
473 intern->frameoffset = H_GET_S32 (abfd, ext->p_frameoffset);
474 intern->framereg = H_GET_16 (abfd, ext->p_framereg);
475 intern->pcreg = H_GET_16 (abfd, ext->p_pcreg);
476 intern->lnLow = H_GET_32 (abfd, ext->p_lnLow);
477 intern->lnHigh = H_GET_32 (abfd, ext->p_lnHigh);
478 intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->p_cbLineOffset);
480 #ifdef TEST
481 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
482 abort ();
483 #endif
486 /* Swap out the procedure descriptor record. */
488 static void
489 ecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
490 bfd *abfd;
491 const PDR *intern_copy;
492 PTR ext_ptr;
494 struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
495 PDR intern[1];
497 *intern = *intern_copy; /* Make it reasonable to do in-place. */
499 ECOFF_PUT_OFF (abfd, intern->adr, ext->p_adr);
500 H_PUT_32 (abfd, intern->isym, ext->p_isym);
501 H_PUT_32 (abfd, intern->iline, ext->p_iline);
502 H_PUT_32 (abfd, intern->regmask, ext->p_regmask);
503 H_PUT_32 (abfd, intern->regoffset, ext->p_regoffset);
504 H_PUT_32 (abfd, intern->iopt, ext->p_iopt);
505 H_PUT_32 (abfd, intern->fregmask, ext->p_fregmask);
506 H_PUT_32 (abfd, intern->fregoffset, ext->p_fregoffset);
507 H_PUT_32 (abfd, intern->frameoffset, ext->p_frameoffset);
508 H_PUT_16 (abfd, intern->framereg, ext->p_framereg);
509 H_PUT_16 (abfd, intern->pcreg, ext->p_pcreg);
510 H_PUT_32 (abfd, intern->lnLow, ext->p_lnLow);
511 H_PUT_32 (abfd, intern->lnHigh, ext->p_lnHigh);
512 ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->p_cbLineOffset);
514 #ifdef TEST
515 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
516 abort ();
517 #endif
519 #endif /* MPW_C */
521 /* Swap in a symbol record. */
523 static void
524 ecoff_swap_sym_in (abfd, ext_copy, intern)
525 bfd *abfd;
526 PTR ext_copy;
527 SYMR *intern;
529 struct sym_ext ext[1];
531 *ext = *(struct sym_ext *) ext_copy;
533 intern->iss = H_GET_32 (abfd, ext->s_iss);
534 intern->value = ECOFF_GET_OFF (abfd, ext->s_value);
536 /* now the fun stuff... */
537 if (bfd_header_big_endian (abfd)) {
538 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
539 >> SYM_BITS1_ST_SH_BIG;
540 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
541 << SYM_BITS1_SC_SH_LEFT_BIG)
542 | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
543 >> SYM_BITS2_SC_SH_BIG);
544 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
545 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
546 << SYM_BITS2_INDEX_SH_LEFT_BIG)
547 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
548 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
549 } else {
550 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
551 >> SYM_BITS1_ST_SH_LITTLE;
552 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
553 >> SYM_BITS1_SC_SH_LITTLE)
554 | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
555 << SYM_BITS2_SC_SH_LEFT_LITTLE);
556 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
557 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
558 >> SYM_BITS2_INDEX_SH_LITTLE)
559 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
560 | ((unsigned int) ext->s_bits4[0]
561 << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
564 #ifdef TEST
565 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
566 abort ();
567 #endif
570 /* Swap out a symbol record. */
572 static void
573 ecoff_swap_sym_out (abfd, intern_copy, ext_ptr)
574 bfd *abfd;
575 const SYMR *intern_copy;
576 PTR ext_ptr;
578 struct sym_ext *ext = (struct sym_ext *) ext_ptr;
579 SYMR intern[1];
581 *intern = *intern_copy; /* Make it reasonable to do in-place. */
583 H_PUT_32 (abfd, intern->iss, ext->s_iss);
584 ECOFF_PUT_OFF (abfd, intern->value, ext->s_value);
586 /* now the fun stuff... */
587 if (bfd_header_big_endian (abfd)) {
588 ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
589 & SYM_BITS1_ST_BIG)
590 | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
591 & SYM_BITS1_SC_BIG));
592 ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
593 & SYM_BITS2_SC_BIG)
594 | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
595 | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
596 & SYM_BITS2_INDEX_BIG));
597 ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
598 ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
599 } else {
600 ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
601 & SYM_BITS1_ST_LITTLE)
602 | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
603 & SYM_BITS1_SC_LITTLE));
604 ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
605 & SYM_BITS2_SC_LITTLE)
606 | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
607 | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
608 & SYM_BITS2_INDEX_LITTLE));
609 ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
610 ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
613 #ifdef TEST
614 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
615 abort ();
616 #endif
619 /* Swap in an external symbol record. */
621 static void
622 ecoff_swap_ext_in (abfd, ext_copy, intern)
623 bfd *abfd;
624 PTR ext_copy;
625 EXTR *intern;
627 struct ext_ext ext[1];
629 *ext = *(struct ext_ext *) ext_copy;
631 /* now the fun stuff... */
632 if (bfd_header_big_endian (abfd)) {
633 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
634 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
635 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
636 } else {
637 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
638 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
639 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
641 intern->reserved = 0;
643 #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
644 intern->ifd = H_GET_S16 (abfd, ext->es_ifd);
645 #endif
646 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
647 intern->ifd = H_GET_S32 (abfd, ext->es_ifd);
648 #endif
650 ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
652 #ifdef TEST
653 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
654 abort ();
655 #endif
658 /* Swap out an external symbol record. */
660 static void
661 ecoff_swap_ext_out (abfd, intern_copy, ext_ptr)
662 bfd *abfd;
663 const EXTR *intern_copy;
664 PTR ext_ptr;
666 struct ext_ext *ext = (struct ext_ext *) ext_ptr;
667 EXTR intern[1];
669 *intern = *intern_copy; /* Make it reasonable to do in-place. */
671 /* now the fun stuff... */
672 if (bfd_header_big_endian (abfd)) {
673 ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
674 | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
675 | (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
676 ext->es_bits2[0] = 0;
677 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
678 ext->es_bits2[1] = 0;
679 ext->es_bits2[2] = 0;
680 #endif
681 } else {
682 ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
683 | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
684 | (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
685 ext->es_bits2[0] = 0;
686 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
687 ext->es_bits2[1] = 0;
688 ext->es_bits2[2] = 0;
689 #endif
692 #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
693 H_PUT_S16 (abfd, intern->ifd, ext->es_ifd);
694 #endif
695 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
696 H_PUT_S32 (abfd, intern->ifd, ext->es_ifd);
697 #endif
699 ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
701 #ifdef TEST
702 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
703 abort ();
704 #endif
707 /* Swap in a relative file descriptor. */
709 static void
710 ecoff_swap_rfd_in (abfd, ext_ptr, intern)
711 bfd *abfd;
712 PTR ext_ptr;
713 RFDT *intern;
715 struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
717 *intern = H_GET_32 (abfd, ext->rfd);
719 #ifdef TEST
720 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
721 abort ();
722 #endif
725 /* Swap out a relative file descriptor. */
727 static void
728 ecoff_swap_rfd_out (abfd, intern, ext_ptr)
729 bfd *abfd;
730 const RFDT *intern;
731 PTR ext_ptr;
733 struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
735 H_PUT_32 (abfd, *intern, ext->rfd);
737 #ifdef TEST
738 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
739 abort ();
740 #endif
743 /* Swap in an optimization symbol. */
745 static void
746 ecoff_swap_opt_in (abfd, ext_copy, intern)
747 bfd *abfd;
748 PTR ext_copy;
749 OPTR *intern;
751 struct opt_ext ext[1];
753 *ext = *(struct opt_ext *) ext_copy;
755 if (bfd_header_big_endian (abfd))
757 intern->ot = ext->o_bits1[0];
758 intern->value = (((unsigned int) ext->o_bits2[0]
759 << OPT_BITS2_VALUE_SH_LEFT_BIG)
760 | ((unsigned int) ext->o_bits3[0]
761 << OPT_BITS2_VALUE_SH_LEFT_BIG)
762 | ((unsigned int) ext->o_bits4[0]
763 << OPT_BITS2_VALUE_SH_LEFT_BIG));
765 else
767 intern->ot = ext->o_bits1[0];
768 intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
769 | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
770 | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
773 _bfd_ecoff_swap_rndx_in (bfd_header_big_endian (abfd),
774 &ext->o_rndx, &intern->rndx);
776 intern->offset = H_GET_32 (abfd, ext->o_offset);
778 #ifdef TEST
779 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
780 abort ();
781 #endif
784 /* Swap out an optimization symbol. */
786 static void
787 ecoff_swap_opt_out (abfd, intern_copy, ext_ptr)
788 bfd *abfd;
789 const OPTR *intern_copy;
790 PTR ext_ptr;
792 struct opt_ext *ext = (struct opt_ext *) ext_ptr;
793 OPTR intern[1];
795 *intern = *intern_copy; /* Make it reasonable to do in-place. */
797 if (bfd_header_big_endian (abfd))
799 ext->o_bits1[0] = intern->ot;
800 ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
801 ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
802 ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
804 else
806 ext->o_bits1[0] = intern->ot;
807 ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
808 ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
809 ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
812 _bfd_ecoff_swap_rndx_out (bfd_header_big_endian (abfd),
813 &intern->rndx, &ext->o_rndx);
815 H_PUT_32 (abfd, intern->value, ext->o_offset);
817 #ifdef TEST
818 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
819 abort ();
820 #endif
823 /* Swap in a dense number. */
825 static void
826 ecoff_swap_dnr_in (abfd, ext_copy, intern)
827 bfd *abfd;
828 PTR ext_copy;
829 DNR *intern;
831 struct dnr_ext ext[1];
833 *ext = *(struct dnr_ext *) ext_copy;
835 intern->rfd = H_GET_32 (abfd, ext->d_rfd);
836 intern->index = H_GET_32 (abfd, ext->d_index);
838 #ifdef TEST
839 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
840 abort ();
841 #endif
844 /* Swap out a dense number. */
846 static void
847 ecoff_swap_dnr_out (abfd, intern_copy, ext_ptr)
848 bfd *abfd;
849 const DNR *intern_copy;
850 PTR ext_ptr;
852 struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
853 DNR intern[1];
855 *intern = *intern_copy; /* Make it reasonable to do in-place. */
857 H_PUT_32 (abfd, intern->rfd, ext->d_rfd);
858 H_PUT_32 (abfd, intern->index, ext->d_index);
860 #ifdef TEST
861 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
862 abort ();
863 #endif