1 /* Generic COFF swapping routines, for BFD.
2 Copyright 1990, 1991, 1992, 1993 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., 675 Mass Ave, Cambridge, MA 02139, 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. */
29 #define PUTWORD bfd_h_put_32
30 #define PUTHALF bfd_h_put_16
31 #define PUTBYTE bfd_h_put_8
33 #ifndef GET_FCN_LNNOPTR
34 #define GET_FCN_LNNOPTR(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
37 #ifndef GET_FCN_ENDNDX
38 #define GET_FCN_ENDNDX(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
41 #ifndef PUT_FCN_LNNOPTR
42 #define PUT_FCN_LNNOPTR(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
44 #ifndef PUT_FCN_ENDNDX
45 #define PUT_FCN_ENDNDX(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
48 #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
51 #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
54 #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
57 #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
59 #ifndef GET_SCN_SCNLEN
60 #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
62 #ifndef GET_SCN_NRELOC
63 #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
65 #ifndef GET_SCN_NLINNO
66 #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
68 #ifndef PUT_SCN_SCNLEN
69 #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
71 #ifndef PUT_SCN_NRELOC
72 #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
74 #ifndef PUT_SCN_NLINNO
75 #define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
77 #ifndef GET_LINENO_LNNO
78 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
80 #ifndef PUT_LINENO_LNNO
81 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
84 /* The f_symptr field in the filehdr is sometimes 64 bits. */
85 #ifndef GET_FILEHDR_SYMPTR
86 #define GET_FILEHDR_SYMPTR bfd_h_get_32
88 #ifndef PUT_FILEHDR_SYMPTR
89 #define PUT_FILEHDR_SYMPTR bfd_h_put_32
92 /* Some fields in the aouthdr are sometimes 64 bits. */
93 #ifndef GET_AOUTHDR_TSIZE
94 #define GET_AOUTHDR_TSIZE bfd_h_get_32
96 #ifndef PUT_AOUTHDR_TSIZE
97 #define PUT_AOUTHDR_TSIZE bfd_h_put_32
99 #ifndef GET_AOUTHDR_DSIZE
100 #define GET_AOUTHDR_DSIZE bfd_h_get_32
102 #ifndef PUT_AOUTHDR_DSIZE
103 #define PUT_AOUTHDR_DSIZE bfd_h_put_32
105 #ifndef GET_AOUTHDR_BSIZE
106 #define GET_AOUTHDR_BSIZE bfd_h_get_32
108 #ifndef PUT_AOUTHDR_BSIZE
109 #define PUT_AOUTHDR_BSIZE bfd_h_put_32
111 #ifndef GET_AOUTHDR_ENTRY
112 #define GET_AOUTHDR_ENTRY bfd_h_get_32
114 #ifndef PUT_AOUTHDR_ENTRY
115 #define PUT_AOUTHDR_ENTRY bfd_h_put_32
117 #ifndef GET_AOUTHDR_TEXT_START
118 #define GET_AOUTHDR_TEXT_START bfd_h_get_32
120 #ifndef PUT_AOUTHDR_TEXT_START
121 #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
123 #ifndef GET_AOUTHDR_DATA_START
124 #define GET_AOUTHDR_DATA_START bfd_h_get_32
126 #ifndef PUT_AOUTHDR_DATA_START
127 #define PUT_AOUTHDR_DATA_START bfd_h_put_32
130 /* Some fields in the scnhdr are sometimes 64 bits. */
131 #ifndef GET_SCNHDR_PADDR
132 #define GET_SCNHDR_PADDR bfd_h_get_32
134 #ifndef PUT_SCNHDR_PADDR
135 #define PUT_SCNHDR_PADDR bfd_h_put_32
137 #ifndef GET_SCNHDR_VADDR
138 #define GET_SCNHDR_VADDR bfd_h_get_32
140 #ifndef PUT_SCNHDR_VADDR
141 #define PUT_SCNHDR_VADDR bfd_h_put_32
143 #ifndef GET_SCNHDR_SIZE
144 #define GET_SCNHDR_SIZE bfd_h_get_32
146 #ifndef PUT_SCNHDR_SIZE
147 #define PUT_SCNHDR_SIZE bfd_h_put_32
149 #ifndef GET_SCNHDR_SCNPTR
150 #define GET_SCNHDR_SCNPTR bfd_h_get_32
152 #ifndef PUT_SCNHDR_SCNPTR
153 #define PUT_SCNHDR_SCNPTR bfd_h_put_32
155 #ifndef GET_SCNHDR_RELPTR
156 #define GET_SCNHDR_RELPTR bfd_h_get_32
158 #ifndef PUT_SCNHDR_RELPTR
159 #define PUT_SCNHDR_RELPTR bfd_h_put_32
161 #ifndef GET_SCNHDR_LNNOPTR
162 #define GET_SCNHDR_LNNOPTR bfd_h_get_32
164 #ifndef PUT_SCNHDR_LNNOPTR
165 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
168 #ifndef NO_COFF_RELOCS
171 DEFUN(bfd_swap_reloc_in,(abfd, reloc_src, reloc_dst),
174 struct internal_reloc *reloc_dst)
176 reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
177 reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
180 reloc_dst->r_type = bfd_h_get_8(abfd, reloc_src->r_type);
181 reloc_dst->r_size = bfd_h_get_8(abfd, reloc_src->r_size);
183 reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
186 #ifdef SWAP_IN_RELOC_OFFSET
187 reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
188 (bfd_byte *) reloc_src->r_offset);
194 DEFUN(coff_swap_reloc_out,(abfd, src, dst),
199 struct internal_reloc *reloc_src = (struct internal_reloc *)src;
200 struct external_reloc *reloc_dst = (struct external_reloc *)dst;
201 bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
202 bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
203 bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
206 #ifdef SWAP_OUT_RELOC_OFFSET
207 SWAP_OUT_RELOC_OFFSET(abfd,
209 (bfd_byte *) reloc_dst->r_offset);
211 #ifdef SWAP_OUT_RELOC_EXTRA
212 SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
215 return sizeof(struct external_reloc);
218 #endif /* NO_COFF_RELOCS */
221 DEFUN(coff_swap_filehdr_in,(abfd, src, dst),
226 FILHDR *filehdr_src = (FILHDR *) src;
227 struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
228 filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
229 filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
230 filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
231 filehdr_dst->f_symptr =
232 GET_FILEHDR_SYMPTR (abfd, (bfd_byte *) filehdr_src->f_symptr);
233 filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
234 filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
235 filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
239 DEFUN(coff_swap_filehdr_out,(abfd, in, out),
244 struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
245 FILHDR *filehdr_out = (FILHDR *)out;
246 bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
247 bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
248 bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
249 PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
250 (bfd_byte *) filehdr_out->f_symptr);
251 bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
252 bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
253 bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
254 return sizeof(FILHDR);
258 #ifndef NO_COFF_SYMBOLS
261 DEFUN(coff_swap_sym_in,(abfd, ext1, in1),
266 SYMENT *ext = (SYMENT *)ext1;
267 struct internal_syment *in = (struct internal_syment *)in1;
269 if( ext->e.e_name[0] == 0) {
270 in->_n._n_n._n_zeroes = 0;
271 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
274 #if SYMNMLEN != E_SYMNMLEN
275 -> Error, we need to cope with truncating or extending SYMNMLEN!;
277 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
280 in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
281 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
282 if (sizeof(ext->e_type) == 2){
283 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
286 in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
288 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
289 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
293 DEFUN(coff_swap_sym_out,(abfd, inp, extp),
298 struct internal_syment *in = (struct internal_syment *)inp;
299 SYMENT *ext =(SYMENT *)extp;
300 if(in->_n._n_name[0] == 0) {
301 bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
302 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e.e.e_offset);
305 #if SYMNMLEN != E_SYMNMLEN
306 -> Error, we need to cope with truncating or extending SYMNMLEN!;
308 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
311 bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
312 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
313 if (sizeof(ext->e_type) == 2)
315 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
319 bfd_h_put_32(abfd, in->n_type , (bfd_byte *) ext->e_type);
321 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
322 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
323 return sizeof(SYMENT);
327 DEFUN(coff_swap_aux_in,(abfd, ext1, type, class, indx, numaux, in1),
336 AUXENT *ext = (AUXENT *)ext1;
337 union internal_auxent *in = (union internal_auxent *)in1;
341 if (ext->x_file.x_fname[0] == 0) {
342 in->x_file.x_n.x_zeroes = 0;
343 in->x_file.x_n.x_offset =
344 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
346 #if FILNMLEN != E_FILNMLEN
347 -> Error, we need to cope with truncating or extending FILNMLEN!;
349 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
354 /* RS/6000 "csect" auxents */
358 if (indx + 1 == numaux)
360 in->x_csect.x_scnlen = bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
361 in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
362 ext->x_csect.x_parmhash);
363 in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
364 /* We don't have to hack bitfields in x_smtyp because it's
365 defined by shifts-and-ands, which are equivalent on all
367 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
368 in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
369 in->x_csect.x_stab = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
370 in->x_csect.x_snstab = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
381 if (type == T_NULL) {
382 in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
383 in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
384 in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
390 in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
392 in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
396 #if DIMNUM != E_DIMNUM
397 -> Error, we need to cope with truncating or extending DIMNUM!;
399 in->x_sym.x_fcnary.x_ary.x_dimen[0] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
400 in->x_sym.x_fcnary.x_ary.x_dimen[1] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
401 in->x_sym.x_fcnary.x_ary.x_dimen[2] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
402 in->x_sym.x_fcnary.x_ary.x_dimen[3] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
405 if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
406 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR(abfd, ext);
407 in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX(abfd, ext);
411 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
414 in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
415 in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
420 DEFUN(coff_swap_aux_out,(abfd, inp, type, class, indx, numaux, extp),
429 union internal_auxent *in = (union internal_auxent *)inp;
430 AUXENT *ext = (AUXENT *)extp;
432 memset((PTR)ext, 0, AUXESZ);
435 if (in->x_file.x_fname[0] == 0) {
436 PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
438 in->x_file.x_n.x_offset,
439 (bfd_byte *) ext->x_file.x_n.x_offset);
442 #if FILNMLEN != E_FILNMLEN
443 -> Error, we need to cope with truncating or extending FILNMLEN!;
445 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
448 return sizeof (AUXENT);
451 /* RS/6000 "csect" auxents */
454 if (indx + 1 == numaux)
456 PUTWORD (abfd, in->x_csect.x_scnlen, ext->x_csect.x_scnlen);
457 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
458 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
459 /* We don't have to hack bitfields in x_smtyp because it's
460 defined by shifts-and-ands, which are equivalent on all
462 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
463 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
464 PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
465 PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
466 return sizeof (AUXENT);
476 if (type == T_NULL) {
477 PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
478 PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
479 PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
480 return sizeof (AUXENT);
485 PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
487 bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
490 if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
491 PUT_FCN_LNNOPTR(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
492 PUT_FCN_ENDNDX(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
496 PUTWORD(abfd, in->x_sym.x_misc.x_fsize, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
500 #if DIMNUM != E_DIMNUM
501 -> Error, we need to cope with truncating or extending DIMNUM!;
503 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
504 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
505 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
506 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
509 PUT_LNSZ_LNNO(abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
510 PUT_LNSZ_SIZE(abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
512 return sizeof(AUXENT);
515 #endif /* NO_COFF_SYMBOLS */
517 #ifndef NO_COFF_LINENOS
520 DEFUN(coff_swap_lineno_in,(abfd, ext1, in1),
525 LINENO *ext = (LINENO *)ext1;
526 struct internal_lineno *in = (struct internal_lineno *)in1;
528 in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
529 in->l_lnno = GET_LINENO_LNNO(abfd, ext);
533 DEFUN(coff_swap_lineno_out,(abfd, inp, outp),
538 struct internal_lineno *in = (struct internal_lineno *)inp;
539 struct external_lineno *ext = (struct external_lineno *)outp;
540 PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
541 ext->l_addr.l_symndx);
543 PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
544 return sizeof(struct external_lineno);
547 #endif /* NO_COFF_LINENOS */
551 DEFUN(coff_swap_aouthdr_in,(abfd, aouthdr_ext1, aouthdr_int1),
556 AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
557 struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
559 aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
560 aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
562 GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
564 GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
566 GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
568 GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
569 aouthdr_int->text_start =
570 GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
571 aouthdr_int->data_start =
572 GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
575 aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
579 bfd_h_put_32(abfd, aouthdr_int->o_inlib, (bfd_byte *) aouthdr_ext->o_inlib);
580 bfd_h_put_32(abfd, aouthdr_int->o_sri, (bfd_byte *) aouthdr_ext->o_sri);
581 bfd_h_put_32(abfd, aouthdr_int->vid[0], (bfd_byte *) aouthdr_ext->vid);
582 bfd_h_put_32(abfd, aouthdr_int->vid[1], (bfd_byte *) aouthdr_ext->vid + 4);
587 aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
588 aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
589 aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
590 aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
591 aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
592 aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
593 aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
594 aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
595 aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
596 aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
597 aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
601 aouthdr_int->bss_start = bfd_h_get_32(abfd, aouthdr_ext->bss_start);
602 aouthdr_int->gp_value = bfd_h_get_32(abfd, aouthdr_ext->gp_value);
603 aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
604 aouthdr_int->cprmask[0] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[0]);
605 aouthdr_int->cprmask[1] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[1]);
606 aouthdr_int->cprmask[2] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[2]);
607 aouthdr_int->cprmask[3] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[3]);
611 aouthdr_int->bss_start = bfd_h_get_64(abfd, aouthdr_ext->bss_start);
612 aouthdr_int->gp_value = bfd_h_get_64(abfd, aouthdr_ext->gp_value);
613 aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
614 aouthdr_int->fprmask = bfd_h_get_32(abfd, aouthdr_ext->fprmask);
619 DEFUN(coff_swap_aouthdr_out,(abfd, in, out),
624 struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
625 AOUTHDR *aouthdr_out = (AOUTHDR *)out;
627 bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
628 bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
629 PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
630 PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
631 PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
632 PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
633 PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
634 (bfd_byte *) aouthdr_out->text_start);
635 PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
636 (bfd_byte *) aouthdr_out->data_start);
638 bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
642 bfd_h_put_32(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
643 bfd_h_put_32(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
644 bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
645 bfd_h_put_32(abfd, aouthdr_in->cprmask[0], (bfd_byte *) aouthdr_out->cprmask[0]);
646 bfd_h_put_32(abfd, aouthdr_in->cprmask[1], (bfd_byte *) aouthdr_out->cprmask[1]);
647 bfd_h_put_32(abfd, aouthdr_in->cprmask[2], (bfd_byte *) aouthdr_out->cprmask[2]);
648 bfd_h_put_32(abfd, aouthdr_in->cprmask[3], (bfd_byte *) aouthdr_out->cprmask[3]);
652 /* FIXME: What does bldrev mean? */
653 bfd_h_put_16(abfd, (bfd_vma) 2, (bfd_byte *) aouthdr_out->bldrev);
654 bfd_h_put_16(abfd, (bfd_vma) 0, (bfd_byte *) aouthdr_out->padding);
655 bfd_h_put_64(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
656 bfd_h_put_64(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
657 bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
658 bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
661 return sizeof(AOUTHDR);
665 DEFUN(coff_swap_scnhdr_in,(abfd, ext, in),
670 SCNHDR *scnhdr_ext = (SCNHDR *) ext;
671 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
673 memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
674 scnhdr_int->s_vaddr =
675 GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
676 scnhdr_int->s_paddr =
677 GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
679 GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
681 scnhdr_int->s_scnptr =
682 GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
683 scnhdr_int->s_relptr =
684 GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
685 scnhdr_int->s_lnnoptr =
686 GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
687 scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
689 scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
690 scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
692 scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
693 scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
696 scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
699 /* start-sanitize-mpw */
701 /* end-sanitize-mpw */
704 DEFUN(coff_swap_scnhdr_out,(abfd, in, out),
709 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
710 SCNHDR *scnhdr_ext = (SCNHDR *)out;
712 memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
713 PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
714 (bfd_byte *) scnhdr_ext->s_vaddr);
715 PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr,
716 (bfd_byte *) scnhdr_ext->s_paddr);
717 PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
718 (bfd_byte *) scnhdr_ext->s_size);
719 PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
720 (bfd_byte *) scnhdr_ext->s_scnptr);
721 PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
722 (bfd_byte *) scnhdr_ext->s_relptr);
723 PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
724 (bfd_byte *) scnhdr_ext->s_lnnoptr);
725 PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
727 PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
728 PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
730 PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
731 PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
735 PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
737 return sizeof(SCNHDR);
739 /* start-sanitize-mpw */
741 /* Same routine, but with some pre-expanded macros, so ^&%$#&! MPW C doesn't
742 corrupt itself and then freak out. */
745 DEFUN(coff_swap_scnhdr_out,(abfd, in, out),
750 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
751 SCNHDR *scnhdr_ext = (SCNHDR *)out;
753 memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
754 bfd_h_put_32 (abfd, scnhdr_int->s_vaddr,
755 (bfd_byte *) scnhdr_ext->s_vaddr);
756 bfd_h_put_32 (abfd, scnhdr_int->s_paddr,
757 (bfd_byte *) scnhdr_ext->s_paddr);
758 bfd_h_put_32 (abfd, scnhdr_int->s_size,
759 (bfd_byte *) scnhdr_ext->s_size);
760 PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
761 (bfd_byte *) scnhdr_ext->s_scnptr);
762 PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
763 (bfd_byte *) scnhdr_ext->s_relptr);
764 PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
765 (bfd_byte *) scnhdr_ext->s_lnnoptr);
766 PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
768 PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
769 PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
771 PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
772 PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
776 PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
778 return sizeof(SCNHDR);
782 /* end-sanitize-mpw */