1 /* Generic COFF swapping routines, for BFD.
2 Copyright 1990, 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file contains routines used to swap COFF data. It is a header
22 file because the details of swapping depend on the details of the
23 structures used by each COFF implementation. This is included by
24 coffcode.h, as well as by the ECOFF backend.
26 Any file which uses this must first include "coff/internal.h" and
27 "coff/CPU.h". The functions will then be correct for that CPU. */
33 #define PUTWORD bfd_h_put_32
34 #define PUTHALF bfd_h_put_16
35 #define PUTBYTE bfd_h_put_8
37 #ifndef GET_FCN_LNNOPTR
38 #define GET_FCN_LNNOPTR(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
41 #ifndef GET_FCN_ENDNDX
42 #define GET_FCN_ENDNDX(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
45 #ifndef PUT_FCN_LNNOPTR
46 #define PUT_FCN_LNNOPTR(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
48 #ifndef PUT_FCN_ENDNDX
49 #define PUT_FCN_ENDNDX(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
52 #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
55 #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
58 #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
61 #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
63 #ifndef GET_SCN_SCNLEN
64 #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
66 #ifndef GET_SCN_NRELOC
67 #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
69 #ifndef GET_SCN_NLINNO
70 #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
72 #ifndef PUT_SCN_SCNLEN
73 #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
75 #ifndef PUT_SCN_NRELOC
76 #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
78 #ifndef PUT_SCN_NLINNO
79 #define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
81 #ifndef GET_LINENO_LNNO
82 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
84 #ifndef PUT_LINENO_LNNO
85 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
88 /* The f_symptr field in the filehdr is sometimes 64 bits. */
89 #ifndef GET_FILEHDR_SYMPTR
90 #define GET_FILEHDR_SYMPTR bfd_h_get_32
92 #ifndef PUT_FILEHDR_SYMPTR
93 #define PUT_FILEHDR_SYMPTR bfd_h_put_32
96 /* Some fields in the aouthdr are sometimes 64 bits. */
97 #ifndef GET_AOUTHDR_TSIZE
98 #define GET_AOUTHDR_TSIZE bfd_h_get_32
100 #ifndef PUT_AOUTHDR_TSIZE
101 #define PUT_AOUTHDR_TSIZE bfd_h_put_32
103 #ifndef GET_AOUTHDR_DSIZE
104 #define GET_AOUTHDR_DSIZE bfd_h_get_32
106 #ifndef PUT_AOUTHDR_DSIZE
107 #define PUT_AOUTHDR_DSIZE bfd_h_put_32
109 #ifndef GET_AOUTHDR_BSIZE
110 #define GET_AOUTHDR_BSIZE bfd_h_get_32
112 #ifndef PUT_AOUTHDR_BSIZE
113 #define PUT_AOUTHDR_BSIZE bfd_h_put_32
115 #ifndef GET_AOUTHDR_ENTRY
116 #define GET_AOUTHDR_ENTRY bfd_h_get_32
118 #ifndef PUT_AOUTHDR_ENTRY
119 #define PUT_AOUTHDR_ENTRY bfd_h_put_32
121 #ifndef GET_AOUTHDR_TEXT_START
122 #define GET_AOUTHDR_TEXT_START bfd_h_get_32
124 #ifndef PUT_AOUTHDR_TEXT_START
125 #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
127 #ifndef GET_AOUTHDR_DATA_START
128 #define GET_AOUTHDR_DATA_START bfd_h_get_32
130 #ifndef PUT_AOUTHDR_DATA_START
131 #define PUT_AOUTHDR_DATA_START bfd_h_put_32
134 /* Some fields in the scnhdr are sometimes 64 bits. */
135 #ifndef GET_SCNHDR_PADDR
136 #define GET_SCNHDR_PADDR bfd_h_get_32
138 #ifndef PUT_SCNHDR_PADDR
139 #define PUT_SCNHDR_PADDR bfd_h_put_32
141 #ifndef GET_SCNHDR_VADDR
142 #define GET_SCNHDR_VADDR bfd_h_get_32
144 #ifndef PUT_SCNHDR_VADDR
145 #define PUT_SCNHDR_VADDR bfd_h_put_32
147 #ifndef GET_SCNHDR_SIZE
148 #define GET_SCNHDR_SIZE bfd_h_get_32
150 #ifndef PUT_SCNHDR_SIZE
151 #define PUT_SCNHDR_SIZE bfd_h_put_32
153 #ifndef GET_SCNHDR_SCNPTR
154 #define GET_SCNHDR_SCNPTR bfd_h_get_32
156 #ifndef PUT_SCNHDR_SCNPTR
157 #define PUT_SCNHDR_SCNPTR bfd_h_put_32
159 #ifndef GET_SCNHDR_RELPTR
160 #define GET_SCNHDR_RELPTR bfd_h_get_32
162 #ifndef PUT_SCNHDR_RELPTR
163 #define PUT_SCNHDR_RELPTR bfd_h_put_32
165 #ifndef GET_SCNHDR_LNNOPTR
166 #define GET_SCNHDR_LNNOPTR bfd_h_get_32
168 #ifndef PUT_SCNHDR_LNNOPTR
169 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
172 #ifndef NO_COFF_RELOCS
175 coff_swap_reloc_in (abfd, src, dst)
180 RELOC *reloc_src = (RELOC *) src;
181 struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
183 reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
184 reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
187 reloc_dst->r_type = bfd_h_get_8(abfd, reloc_src->r_type);
188 reloc_dst->r_size = bfd_h_get_8(abfd, reloc_src->r_size);
190 reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
193 #ifdef SWAP_IN_RELOC_OFFSET
194 reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
195 (bfd_byte *) reloc_src->r_offset);
201 coff_swap_reloc_out (abfd, src, dst)
206 struct internal_reloc *reloc_src = (struct internal_reloc *)src;
207 struct external_reloc *reloc_dst = (struct external_reloc *)dst;
208 bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
209 bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
212 bfd_h_put_8 (abfd, reloc_src->r_type, (bfd_byte *) reloc_dst->r_type);
213 bfd_h_put_8 (abfd, reloc_src->r_size, (bfd_byte *) reloc_dst->r_size);
215 bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
219 #ifdef SWAP_OUT_RELOC_OFFSET
220 SWAP_OUT_RELOC_OFFSET(abfd,
222 (bfd_byte *) reloc_dst->r_offset);
224 #ifdef SWAP_OUT_RELOC_EXTRA
225 SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
228 return sizeof(struct external_reloc);
231 #endif /* NO_COFF_RELOCS */
234 coff_swap_filehdr_in (abfd, src, dst)
239 FILHDR *filehdr_src = (FILHDR *) src;
240 struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
241 filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
242 filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
243 filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
244 filehdr_dst->f_symptr =
245 GET_FILEHDR_SYMPTR (abfd, (bfd_byte *) filehdr_src->f_symptr);
246 filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
247 filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
248 filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
252 coff_swap_filehdr_out (abfd, in, out)
257 struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
258 FILHDR *filehdr_out = (FILHDR *)out;
260 bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
261 bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
262 bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
263 PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
264 (bfd_byte *) filehdr_out->f_symptr);
265 bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
266 bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
267 bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
269 return sizeof(FILHDR);
273 #ifndef NO_COFF_SYMBOLS
276 coff_swap_sym_in (abfd, ext1, in1)
281 SYMENT *ext = (SYMENT *)ext1;
282 struct internal_syment *in = (struct internal_syment *)in1;
284 if( ext->e.e_name[0] == 0) {
285 in->_n._n_n._n_zeroes = 0;
286 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
289 #if SYMNMLEN != E_SYMNMLEN
290 -> Error, we need to cope with truncating or extending SYMNMLEN!;
292 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
295 in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
296 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
297 if (sizeof(ext->e_type) == 2){
298 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
301 in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
303 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
304 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
308 coff_swap_sym_out (abfd, inp, extp)
313 struct internal_syment *in = (struct internal_syment *)inp;
314 SYMENT *ext =(SYMENT *)extp;
315 if(in->_n._n_name[0] == 0) {
316 bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
317 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e.e.e_offset);
320 #if SYMNMLEN != E_SYMNMLEN
321 -> Error, we need to cope with truncating or extending SYMNMLEN!;
323 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
326 bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
327 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
328 if (sizeof(ext->e_type) == 2)
330 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
334 bfd_h_put_32(abfd, in->n_type , (bfd_byte *) ext->e_type);
336 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
337 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
338 return sizeof(SYMENT);
342 coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
351 AUXENT *ext = (AUXENT *)ext1;
352 union internal_auxent *in = (union internal_auxent *)in1;
356 if (ext->x_file.x_fname[0] == 0) {
357 in->x_file.x_n.x_zeroes = 0;
358 in->x_file.x_n.x_offset =
359 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
361 #if FILNMLEN != E_FILNMLEN
362 -> Error, we need to cope with truncating or extending FILNMLEN!;
364 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
369 /* RS/6000 "csect" auxents */
373 if (indx + 1 == numaux)
375 in->x_csect.x_scnlen.l = bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
376 in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
377 ext->x_csect.x_parmhash);
378 in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
379 /* We don't have to hack bitfields in x_smtyp because it's
380 defined by shifts-and-ands, which are equivalent on all
382 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
383 in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
384 in->x_csect.x_stab = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
385 in->x_csect.x_snstab = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
396 if (type == T_NULL) {
397 in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
398 in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
399 in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
405 in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
407 in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
410 if (class == C_BLOCK || ISFCN (type) || ISTAG (class))
412 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext);
413 in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext);
417 #if DIMNUM != E_DIMNUM
418 #error we need to cope with truncating or extending DIMNUM
420 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
421 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
422 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
423 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
424 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
425 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
426 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
427 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
431 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
434 in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
435 in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
440 coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
449 union internal_auxent *in = (union internal_auxent *)inp;
450 AUXENT *ext = (AUXENT *)extp;
452 memset((PTR)ext, 0, AUXESZ);
455 if (in->x_file.x_fname[0] == 0) {
456 PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
458 in->x_file.x_n.x_offset,
459 (bfd_byte *) ext->x_file.x_n.x_offset);
462 #if FILNMLEN != E_FILNMLEN
463 -> Error, we need to cope with truncating or extending FILNMLEN!;
465 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
468 return sizeof (AUXENT);
471 /* RS/6000 "csect" auxents */
474 if (indx + 1 == numaux)
476 PUTWORD (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
477 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
478 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
479 /* We don't have to hack bitfields in x_smtyp because it's
480 defined by shifts-and-ands, which are equivalent on all
482 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
483 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
484 PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
485 PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
486 return sizeof (AUXENT);
496 if (type == T_NULL) {
497 PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
498 PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
499 PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
500 return sizeof (AUXENT);
505 PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
507 bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
510 if (class == C_BLOCK || ISFCN (type) || ISTAG (class))
512 PUT_FCN_LNNOPTR(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
513 PUT_FCN_ENDNDX(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
517 #if DIMNUM != E_DIMNUM
518 #error we need to cope with truncating or extending DIMNUM
520 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
521 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
522 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
523 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
524 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
525 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
526 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
527 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
531 PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
532 (bfd_byte *) ext->x_sym.x_misc.x_fsize);
535 PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
536 PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
539 return sizeof(AUXENT);
542 #endif /* NO_COFF_SYMBOLS */
544 #ifndef NO_COFF_LINENOS
547 coff_swap_lineno_in (abfd, ext1, in1)
552 LINENO *ext = (LINENO *)ext1;
553 struct internal_lineno *in = (struct internal_lineno *)in1;
555 in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
556 in->l_lnno = GET_LINENO_LNNO(abfd, ext);
560 coff_swap_lineno_out (abfd, inp, outp)
565 struct internal_lineno *in = (struct internal_lineno *)inp;
566 struct external_lineno *ext = (struct external_lineno *)outp;
567 PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
568 ext->l_addr.l_symndx);
570 PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
571 return sizeof(struct external_lineno);
574 #endif /* NO_COFF_LINENOS */
578 coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
583 AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
584 struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
586 aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
587 aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
589 GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
591 GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
593 GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
595 GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
596 aouthdr_int->text_start =
597 GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
598 aouthdr_int->data_start =
599 GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
602 aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
606 bfd_h_put_32(abfd, aouthdr_int->o_inlib, (bfd_byte *) aouthdr_ext->o_inlib);
607 bfd_h_put_32(abfd, aouthdr_int->o_sri, (bfd_byte *) aouthdr_ext->o_sri);
608 bfd_h_put_32(abfd, aouthdr_int->vid[0], (bfd_byte *) aouthdr_ext->vid);
609 bfd_h_put_32(abfd, aouthdr_int->vid[1], (bfd_byte *) aouthdr_ext->vid + 4);
614 aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
615 aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
616 aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
617 aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
618 aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
619 aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
620 aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
621 aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
622 aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
623 aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
624 aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
625 aouthdr_int->o_maxdata = bfd_h_get_32(abfd, aouthdr_ext->o_maxdata);
629 aouthdr_int->bss_start = bfd_h_get_32(abfd, aouthdr_ext->bss_start);
630 aouthdr_int->gp_value = bfd_h_get_32(abfd, aouthdr_ext->gp_value);
631 aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
632 aouthdr_int->cprmask[0] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[0]);
633 aouthdr_int->cprmask[1] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[1]);
634 aouthdr_int->cprmask[2] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[2]);
635 aouthdr_int->cprmask[3] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[3]);
639 aouthdr_int->bss_start = bfd_h_get_64(abfd, aouthdr_ext->bss_start);
640 aouthdr_int->gp_value = bfd_h_get_64(abfd, aouthdr_ext->gp_value);
641 aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
642 aouthdr_int->fprmask = bfd_h_get_32(abfd, aouthdr_ext->fprmask);
647 coff_swap_aouthdr_out (abfd, in, out)
652 struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
653 AOUTHDR *aouthdr_out = (AOUTHDR *)out;
655 bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
656 bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
657 PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
658 PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
659 PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
660 PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
661 PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
662 (bfd_byte *) aouthdr_out->text_start);
663 PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
664 (bfd_byte *) aouthdr_out->data_start);
667 bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
671 bfd_h_put_32 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc);
672 bfd_h_put_16 (abfd, aouthdr_in->o_snentry, aouthdr_out->o_snentry);
673 bfd_h_put_16 (abfd, aouthdr_in->o_sntext, aouthdr_out->o_sntext);
674 bfd_h_put_16 (abfd, aouthdr_in->o_sndata, aouthdr_out->o_sndata);
675 bfd_h_put_16 (abfd, aouthdr_in->o_sntoc, aouthdr_out->o_sntoc);
676 bfd_h_put_16 (abfd, aouthdr_in->o_snloader, aouthdr_out->o_snloader);
677 bfd_h_put_16 (abfd, aouthdr_in->o_snbss, aouthdr_out->o_snbss);
678 bfd_h_put_16 (abfd, aouthdr_in->o_algntext, aouthdr_out->o_algntext);
679 bfd_h_put_16 (abfd, aouthdr_in->o_algndata, aouthdr_out->o_algndata);
680 bfd_h_put_16 (abfd, aouthdr_in->o_modtype, aouthdr_out->o_modtype);
681 bfd_h_put_32 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack);
682 bfd_h_put_32 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata);
683 memset (aouthdr_out->o_resv1, 0, sizeof aouthdr_out->o_resv1);
684 memset (aouthdr_out->o_resv2, 0, sizeof aouthdr_out->o_resv2);
688 bfd_h_put_32(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
689 bfd_h_put_32(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
690 bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
691 bfd_h_put_32(abfd, aouthdr_in->cprmask[0], (bfd_byte *) aouthdr_out->cprmask[0]);
692 bfd_h_put_32(abfd, aouthdr_in->cprmask[1], (bfd_byte *) aouthdr_out->cprmask[1]);
693 bfd_h_put_32(abfd, aouthdr_in->cprmask[2], (bfd_byte *) aouthdr_out->cprmask[2]);
694 bfd_h_put_32(abfd, aouthdr_in->cprmask[3], (bfd_byte *) aouthdr_out->cprmask[3]);
698 /* FIXME: What does bldrev mean? */
699 bfd_h_put_16(abfd, (bfd_vma) 2, (bfd_byte *) aouthdr_out->bldrev);
700 bfd_h_put_16(abfd, (bfd_vma) 0, (bfd_byte *) aouthdr_out->padding);
701 bfd_h_put_64(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
702 bfd_h_put_64(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
703 bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
704 bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
707 return sizeof(AOUTHDR);
711 coff_swap_scnhdr_in (abfd, ext, in)
716 SCNHDR *scnhdr_ext = (SCNHDR *) ext;
717 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
719 memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
720 scnhdr_int->s_vaddr =
721 GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
722 scnhdr_int->s_paddr =
723 GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
725 GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
727 scnhdr_int->s_scnptr =
728 GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
729 scnhdr_int->s_relptr =
730 GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
731 scnhdr_int->s_lnnoptr =
732 GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
733 scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
735 scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
736 scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
738 scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
739 scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
742 scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
747 coff_swap_scnhdr_out (abfd, in, out)
752 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
753 SCNHDR *scnhdr_ext = (SCNHDR *)out;
754 unsigned int ret = sizeof (SCNHDR);
756 memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
758 PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
759 (bfd_byte *) scnhdr_ext->s_vaddr);
762 PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr,
763 (bfd_byte *) scnhdr_ext->s_paddr);
764 PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
765 (bfd_byte *) scnhdr_ext->s_size);
767 PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
768 (bfd_byte *) scnhdr_ext->s_scnptr);
769 PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
770 (bfd_byte *) scnhdr_ext->s_relptr);
771 PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
772 (bfd_byte *) scnhdr_ext->s_lnnoptr);
773 PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
775 PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
776 PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
778 if (scnhdr_int->s_nlnno <= 0xffff)
779 PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
782 (*_bfd_error_handler) ("%s: line number overflow: 0x%lx > 0xffff",
783 bfd_get_filename (abfd),
784 scnhdr_int->s_nlnno);
785 bfd_set_error (bfd_error_file_truncated);
786 PUTHALF (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nlnno);
789 if (scnhdr_int->s_nreloc <= 0xffff)
790 PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
793 (*_bfd_error_handler) ("%s: reloc overflow: 0x%lx > 0xffff",
794 bfd_get_filename (abfd),
795 scnhdr_int->s_nreloc);
796 bfd_set_error (bfd_error_file_truncated);
797 PUTHALF (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nreloc);
803 PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);