Tue Jan 19 09:06:14 1993 Ian Lance Taylor (ian@cygnus.com)
[deliverable/binutils-gdb.git] / bfd / coff-msym.c
1 /* BFD support to byte-swap a symbol table in MIPS (Third-Eye, `ecoff') format.
2 Copyright 1992 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* The routines in this file convert the external representation of
21 ECOFF symbol tables to the internal (usual struct) representation.
22 On a machine with the same byte-order and the same basic type
23 sizes and alignments as a MIPS machine, this is a no-op.
24 If the symbol TEST is defined when this file is compiled, a comparison
25 is made to ensure that, in fact, the output is bit-for-bit the same as
26 the input. Of course, this symbol should only be defined when
27 deliberately testing the code on a machine with the proper byte sex
28 and such. */
29
30 #include "bfd.h"
31 #include "coff/sym.h" /* MIPS symbols */
32 #include "coff/symconst.h" /* MIPS symbols */
33 #include "coff/ecoff-ext.h" /* ECOFF external struct defns */
34
35 /* Swap in the symbolic header. */
36
37 void
38 DEFUN (ecoff_swap_hdr_in, (abfd, ext_copy, intern),
39 bfd *abfd AND
40 struct hdr_ext *ext_copy AND
41 HDRR *intern)
42 {
43 struct hdr_ext ext[1];
44
45 *ext = *ext_copy;
46
47 intern->magic = bfd_h_get_16 (abfd, (bfd_byte *)ext->h_magic);
48 intern->vstamp = bfd_h_get_16 (abfd, (bfd_byte *)ext->h_vstamp);
49 intern->ilineMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ilineMax);
50 intern->cbLine = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbLine);
51 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbLineOffset);
52 intern->idnMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_idnMax);
53 intern->cbDnOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbDnOffset);
54 intern->ipdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ipdMax);
55 intern->cbPdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbPdOffset);
56 intern->isymMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_isymMax);
57 intern->cbSymOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSymOffset);
58 intern->ioptMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ioptMax);
59 intern->cbOptOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbOptOffset);
60 intern->iauxMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iauxMax);
61 intern->cbAuxOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbAuxOffset);
62 intern->issMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issMax);
63 intern->cbSsOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSsOffset);
64 intern->issExtMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issExtMax);
65 intern->cbSsExtOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSsExtOffset);
66 intern->ifdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ifdMax);
67 intern->cbFdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbFdOffset);
68 intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_crfd);
69 intern->cbRfdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbRfdOffset);
70 intern->iextMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iextMax);
71 intern->cbExtOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbExtOffset);
72
73 #ifdef TEST
74 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
75 abort();
76 #endif
77 }
78
79 /* Swap out the symbolic header. */
80
81 void
82 DEFUN (ecoff_swap_hdr_out, (abfd, intern_copy, ext),
83 bfd *abfd AND
84 HDRR *intern_copy AND
85 struct hdr_ext *ext)
86 {
87 HDRR intern[1];
88
89 *intern = *intern_copy;
90
91 bfd_h_put_16 (abfd, intern->magic, (bfd_byte *)ext->h_magic);
92 bfd_h_put_16 (abfd, intern->vstamp, (bfd_byte *)ext->h_vstamp);
93 bfd_h_put_32 (abfd, intern->ilineMax, (bfd_byte *)ext->h_ilineMax);
94 bfd_h_put_32 (abfd, intern->cbLine, (bfd_byte *)ext->h_cbLine);
95 bfd_h_put_32 (abfd, intern->cbLineOffset, (bfd_byte *)ext->h_cbLineOffset);
96 bfd_h_put_32 (abfd, intern->idnMax, (bfd_byte *)ext->h_idnMax);
97 bfd_h_put_32 (abfd, intern->cbDnOffset, (bfd_byte *)ext->h_cbDnOffset);
98 bfd_h_put_32 (abfd, intern->ipdMax, (bfd_byte *)ext->h_ipdMax);
99 bfd_h_put_32 (abfd, intern->cbPdOffset, (bfd_byte *)ext->h_cbPdOffset);
100 bfd_h_put_32 (abfd, intern->isymMax, (bfd_byte *)ext->h_isymMax);
101 bfd_h_put_32 (abfd, intern->cbSymOffset, (bfd_byte *)ext->h_cbSymOffset);
102 bfd_h_put_32 (abfd, intern->ioptMax, (bfd_byte *)ext->h_ioptMax);
103 bfd_h_put_32 (abfd, intern->cbOptOffset, (bfd_byte *)ext->h_cbOptOffset);
104 bfd_h_put_32 (abfd, intern->iauxMax, (bfd_byte *)ext->h_iauxMax);
105 bfd_h_put_32 (abfd, intern->cbAuxOffset, (bfd_byte *)ext->h_cbAuxOffset);
106 bfd_h_put_32 (abfd, intern->issMax, (bfd_byte *)ext->h_issMax);
107 bfd_h_put_32 (abfd, intern->cbSsOffset, (bfd_byte *)ext->h_cbSsOffset);
108 bfd_h_put_32 (abfd, intern->issExtMax, (bfd_byte *)ext->h_issExtMax);
109 bfd_h_put_32 (abfd, intern->cbSsExtOffset, (bfd_byte *)ext->h_cbSsExtOffset);
110 bfd_h_put_32 (abfd, intern->ifdMax, (bfd_byte *)ext->h_ifdMax);
111 bfd_h_put_32 (abfd, intern->cbFdOffset, (bfd_byte *)ext->h_cbFdOffset);
112 bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->h_crfd);
113 bfd_h_put_32 (abfd, intern->cbRfdOffset, (bfd_byte *)ext->h_cbRfdOffset);
114 bfd_h_put_32 (abfd, intern->iextMax, (bfd_byte *)ext->h_iextMax);
115 bfd_h_put_32 (abfd, intern->cbExtOffset, (bfd_byte *)ext->h_cbExtOffset);
116
117 #ifdef TEST
118 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
119 abort();
120 #endif
121 }
122
123 /* Swap in the file descriptor record. */
124
125 void
126 DEFUN (ecoff_swap_fdr_in, (abfd, ext_copy, intern),
127 bfd *abfd AND
128 struct fdr_ext *ext_copy AND
129 FDR *intern)
130 {
131 struct fdr_ext ext[1];
132
133 *ext = *ext_copy; /* Make it reasonable to do in-place. */
134
135 intern->adr = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_adr);
136 intern->rss = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
137 intern->issBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_issBase);
138 intern->cbSs = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbSs);
139 intern->isymBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_isymBase);
140 intern->csym = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_csym);
141 intern->ilineBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ilineBase);
142 intern->cline = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
143 intern->ioptBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
144 intern->copt = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
145 intern->ipdFirst = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
146 intern->cpd = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
147 intern->iauxBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_iauxBase);
148 intern->caux = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_caux);
149 intern->rfdBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rfdBase);
150 intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_crfd);
151
152 /* now the fun stuff... */
153 if (abfd->xvec->header_byteorder_big_p != false) {
154 intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
155 >> FDR_BITS1_LANG_SH_BIG;
156 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
157 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
158 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
159 intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
160 >> FDR_BITS2_GLEVEL_SH_BIG;
161 /* intern->reserved we ignore. */
162 } else {
163 intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
164 >> FDR_BITS1_LANG_SH_LITTLE;
165 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
166 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
167 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
168 intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
169 >> FDR_BITS2_GLEVEL_SH_LITTLE;
170 /* intern->reserved we ignore. */
171 }
172
173 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbLineOffset);
174 intern->cbLine = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbLine);
175
176 #ifdef TEST
177 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
178 abort();
179 #endif
180 }
181
182 /* Swap out the file descriptor record. */
183
184 void
185 DEFUN (ecoff_swap_fdr_out, (abfd, intern_copy, ext),
186 bfd *abfd AND
187 FDR *intern_copy AND
188 struct fdr_ext *ext)
189 {
190 FDR intern[1];
191
192 *intern = *intern_copy; /* Make it reasonable to do in-place. */
193
194 bfd_h_put_32 (abfd, intern->adr, (bfd_byte *)ext->f_adr);
195 bfd_h_put_32 (abfd, intern->rss, (bfd_byte *)ext->f_rss);
196 bfd_h_put_32 (abfd, intern->issBase, (bfd_byte *)ext->f_issBase);
197 bfd_h_put_32 (abfd, intern->cbSs, (bfd_byte *)ext->f_cbSs);
198 bfd_h_put_32 (abfd, intern->isymBase, (bfd_byte *)ext->f_isymBase);
199 bfd_h_put_32 (abfd, intern->csym, (bfd_byte *)ext->f_csym);
200 bfd_h_put_32 (abfd, intern->ilineBase, (bfd_byte *)ext->f_ilineBase);
201 bfd_h_put_32 (abfd, intern->cline, (bfd_byte *)ext->f_cline);
202 bfd_h_put_32 (abfd, intern->ioptBase, (bfd_byte *)ext->f_ioptBase);
203 bfd_h_put_32 (abfd, intern->copt, (bfd_byte *)ext->f_copt);
204 bfd_h_put_16 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
205 bfd_h_put_16 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
206 bfd_h_put_32 (abfd, intern->iauxBase, (bfd_byte *)ext->f_iauxBase);
207 bfd_h_put_32 (abfd, intern->caux, (bfd_byte *)ext->f_caux);
208 bfd_h_put_32 (abfd, intern->rfdBase, (bfd_byte *)ext->f_rfdBase);
209 bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->f_crfd);
210
211 /* now the fun stuff... */
212 if (abfd->xvec->header_byteorder_big_p != false) {
213 ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
214 & FDR_BITS1_LANG_BIG)
215 | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
216 | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
217 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
218 ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
219 & FDR_BITS2_GLEVEL_BIG);
220 ext->f_bits2[1] = 0;
221 ext->f_bits2[2] = 0;
222 } else {
223 ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
224 & FDR_BITS1_LANG_LITTLE)
225 | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
226 | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
227 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
228 ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
229 & FDR_BITS2_GLEVEL_LITTLE);
230 ext->f_bits2[1] = 0;
231 ext->f_bits2[2] = 0;
232 }
233
234 bfd_h_put_32 (abfd, intern->cbLineOffset, (bfd_byte *)ext->f_cbLineOffset);
235 bfd_h_put_32 (abfd, intern->cbLine, (bfd_byte *)ext->f_cbLine);
236
237 #ifdef TEST
238 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
239 abort();
240 #endif
241 }
242
243 /* Swap in the procedure descriptor record. */
244
245 void
246 DEFUN (ecoff_swap_pdr_in, (abfd, ext_copy, intern),
247 bfd *abfd AND
248 struct pdr_ext *ext_copy AND
249 PDR *intern)
250 {
251 struct pdr_ext ext[1];
252
253 *ext = *ext_copy; /* Make it reasonable to do in-place. */
254
255 intern->adr = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_adr);
256 intern->isym = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
257 intern->iline = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
258 intern->regmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
259 intern->regoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regoffset);
260 intern->iopt = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iopt);
261 intern->fregmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
262 intern->fregoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregoffset);
263 intern->frameoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_frameoffset);
264 intern->framereg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
265 intern->pcreg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
266 intern->lnLow = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
267 intern->lnHigh = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
268 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_cbLineOffset);
269
270 #ifdef TEST
271 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
272 abort();
273 #endif
274 }
275
276 /* Swap out the procedure descriptor record. */
277
278 void
279 DEFUN (ecoff_swap_pdr_out, (abfd, intern_copy, ext),
280 bfd *abfd AND
281 PDR *intern_copy AND
282 struct pdr_ext *ext)
283 {
284 PDR intern[1];
285
286 *intern = *intern_copy; /* Make it reasonable to do in-place. */
287
288 bfd_h_put_32 (abfd, intern->adr, (bfd_byte *)ext->p_adr);
289 bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym);
290 bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline);
291 bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask);
292 bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset);
293 bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt);
294 bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask);
295 bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset);
296 bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset);
297 bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg);
298 bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg);
299 bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow);
300 bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
301 bfd_h_put_32 (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
302
303 #ifdef TEST
304 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
305 abort();
306 #endif
307 }
308
309 /* Swap in a symbol record. */
310
311 void
312 DEFUN (ecoff_swap_sym_in, (abfd, ext_copy, intern),
313 bfd *abfd AND
314 struct sym_ext *ext_copy AND
315 SYMR *intern)
316 {
317 struct sym_ext ext[1];
318
319 *ext = *ext_copy; /* Make it reasonable to do in-place. */
320
321 intern->iss = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_iss);
322 intern->value = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_value);
323
324 /* now the fun stuff... */
325 if (abfd->xvec->header_byteorder_big_p != false) {
326 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
327 >> SYM_BITS1_ST_SH_BIG;
328 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
329 << SYM_BITS1_SC_SH_LEFT_BIG)
330 | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
331 >> SYM_BITS2_SC_SH_BIG);
332 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
333 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
334 << SYM_BITS2_INDEX_SH_LEFT_BIG)
335 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
336 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
337 } else {
338 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
339 >> SYM_BITS1_ST_SH_LITTLE;
340 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
341 >> SYM_BITS1_SC_SH_LITTLE)
342 | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
343 << SYM_BITS2_SC_SH_LEFT_LITTLE);
344 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
345 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
346 >> SYM_BITS2_INDEX_SH_LITTLE)
347 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
348 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
349 }
350
351 #ifdef TEST
352 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
353 abort();
354 #endif
355 }
356
357 /* Swap out a symbol record. */
358
359 void
360 DEFUN (ecoff_swap_sym_out, (abfd, intern_copy, ext),
361 bfd *abfd AND
362 SYMR *intern_copy AND
363 struct sym_ext *ext)
364 {
365 SYMR intern[1];
366
367 *intern = *intern_copy; /* Make it reasonable to do in-place. */
368
369 bfd_h_put_32 (abfd, intern->iss, (bfd_byte *)ext->s_iss);
370 bfd_h_put_32 (abfd, intern->value, (bfd_byte *)ext->s_value);
371
372 /* now the fun stuff... */
373 if (abfd->xvec->header_byteorder_big_p != false) {
374 ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
375 & SYM_BITS1_ST_BIG)
376 | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
377 & SYM_BITS1_SC_BIG));
378 ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
379 & SYM_BITS2_SC_BIG)
380 | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
381 | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
382 & SYM_BITS2_INDEX_BIG));
383 ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
384 ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
385 } else {
386 ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
387 & SYM_BITS1_ST_LITTLE)
388 | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
389 & SYM_BITS1_SC_LITTLE));
390 ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
391 & SYM_BITS2_SC_LITTLE)
392 | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
393 | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
394 & SYM_BITS2_INDEX_LITTLE));
395 ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
396 ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
397 }
398
399 #ifdef TEST
400 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
401 abort();
402 #endif
403 }
404
405 /* Swap in an external symbol record. */
406
407 void
408 DEFUN (ecoff_swap_ext_in, (abfd, ext_copy, intern),
409 bfd *abfd AND
410 struct ext_ext *ext_copy AND
411 EXTR *intern)
412 {
413 struct ext_ext ext[1];
414
415 *ext = *ext_copy; /* Make it reasonable to do in-place. */
416
417 /* now the fun stuff... */
418 if (abfd->xvec->header_byteorder_big_p != false) {
419 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
420 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
421 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
422 } else {
423 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
424 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
425 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
426 }
427
428 intern->ifd = bfd_h_get_16 (abfd, (bfd_byte *)ext->es_ifd);
429 ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
430
431 #ifdef TEST
432 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
433 abort();
434 #endif
435 }
436
437 /* Swap out an external symbol record. */
438
439 void
440 DEFUN (ecoff_swap_ext_out, (abfd, intern_copy, ext),
441 bfd *abfd AND
442 EXTR *intern_copy AND
443 struct ext_ext *ext)
444 {
445 EXTR intern[1];
446
447 *intern = *intern_copy; /* Make it reasonable to do in-place. */
448
449 /* now the fun stuff... */
450 if (abfd->xvec->header_byteorder_big_p != false) {
451 ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
452 | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
453 | (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
454 ext->es_bits2[0] = 0;
455 } else {
456 ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
457 | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
458 | (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
459 ext->es_bits2[0] = 0;
460 }
461
462 bfd_h_put_16 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
463 ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
464
465 #ifdef TEST
466 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
467 abort();
468 #endif
469 }
470
471 /* Swap in a type information record.
472 BIGEND says whether AUX symbols are big-endian or little-endian; this
473 info comes from the file header record (fh-fBigendian). */
474
475 void
476 DEFUN (ecoff_swap_tir_in, (bigend, ext_copy, intern),
477 int bigend AND
478 struct tir_ext *ext_copy AND
479 TIR *intern)
480 {
481 struct tir_ext ext[1];
482
483 *ext = *ext_copy; /* Make it reasonable to do in-place. */
484
485 /* now the fun stuff... */
486 if (bigend) {
487 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
488 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
489 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_BIG)
490 >> TIR_BITS1_BT_SH_BIG;
491 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_BIG)
492 >> TIR_BITS_TQ4_SH_BIG;
493 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_BIG)
494 >> TIR_BITS_TQ5_SH_BIG;
495 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_BIG)
496 >> TIR_BITS_TQ0_SH_BIG;
497 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_BIG)
498 >> TIR_BITS_TQ1_SH_BIG;
499 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_BIG)
500 >> TIR_BITS_TQ2_SH_BIG;
501 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_BIG)
502 >> TIR_BITS_TQ3_SH_BIG;
503 } else {
504 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_LITTLE);
505 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_LITTLE);
506 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_LITTLE)
507 >> TIR_BITS1_BT_SH_LITTLE;
508 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_LITTLE)
509 >> TIR_BITS_TQ4_SH_LITTLE;
510 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_LITTLE)
511 >> TIR_BITS_TQ5_SH_LITTLE;
512 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_LITTLE)
513 >> TIR_BITS_TQ0_SH_LITTLE;
514 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_LITTLE)
515 >> TIR_BITS_TQ1_SH_LITTLE;
516 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_LITTLE)
517 >> TIR_BITS_TQ2_SH_LITTLE;
518 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_LITTLE)
519 >> TIR_BITS_TQ3_SH_LITTLE;
520 }
521
522 #ifdef TEST
523 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
524 abort();
525 #endif
526 }
527
528 /* Swap in a relative symbol record. BIGEND says whether it is in
529 big-endian or little-endian format.*/
530
531 void
532 DEFUN (ecoff_swap_rndx_in, (bigend, ext_copy, intern),
533 int bigend AND
534 struct rndx_ext *ext_copy AND
535 RNDXR *intern)
536 {
537 struct rndx_ext ext[1];
538
539 *ext = *ext_copy; /* Make it reasonable to do in-place. */
540
541 /* now the fun stuff... */
542 if (bigend) {
543 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
544 | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
545 >> RNDX_BITS1_RFD_SH_BIG);
546 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_BIG)
547 << RNDX_BITS1_INDEX_SH_LEFT_BIG)
548 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG)
549 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG);
550 } else {
551 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE)
552 | ((ext->r_bits[1] & RNDX_BITS1_RFD_LITTLE)
553 << RNDX_BITS1_RFD_SH_LEFT_LITTLE);
554 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_LITTLE)
555 >> RNDX_BITS1_INDEX_SH_LITTLE)
556 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE)
557 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE);
558 }
559
560 #ifdef TEST
561 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
562 abort();
563 #endif
564 }
565
566 /* Swap out a relative symbol record. BIGEND says whether it is in
567 big-endian or little-endian format.*/
568
569 void
570 DEFUN (ecoff_swap_rndx_out, (bigend, intern_copy, ext),
571 int bigend AND
572 RNDXR *intern_copy AND
573 struct rndx_ext *ext)
574 {
575 RNDXR intern[1];
576
577 *intern = *intern_copy; /* Make it reasonable to do in-place. */
578
579 /* now the fun stuff... */
580 if (bigend) {
581 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_BIG;
582 ext->r_bits[1] = (((intern->rfd << RNDX_BITS1_RFD_SH_BIG)
583 & RNDX_BITS1_RFD_BIG)
584 | ((intern->index >> RNDX_BITS1_INDEX_SH_LEFT_BIG)
585 & RNDX_BITS1_INDEX_BIG));
586 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_BIG;
587 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_BIG;
588 } else {
589 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_LITTLE;
590 ext->r_bits[1] = (((intern->rfd >> RNDX_BITS1_RFD_SH_LEFT_LITTLE)
591 & RNDX_BITS1_RFD_LITTLE)
592 | ((intern->index << RNDX_BITS1_INDEX_SH_LITTLE)
593 & RNDX_BITS1_INDEX_LITTLE));
594 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_LITTLE;
595 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_LITTLE;
596 }
597
598 #ifdef TEST
599 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
600 abort();
601 #endif
602 }
603
604 /* Swap in a relative file descriptor. */
605
606 void
607 DEFUN (ecoff_swap_rfd_in, (abfd, ext, intern),
608 bfd *abfd AND
609 struct rfd_ext *ext AND
610 RFDT *intern)
611 {
612
613 *intern = bfd_h_get_32 (abfd, (bfd_byte *)ext->rfd);
614
615 #ifdef TEST
616 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
617 abort();
618 #endif
619 }
620
621 /* Swap out a relative file descriptor. */
622
623 void
624 DEFUN (ecoff_swap_rfd_out, (abfd, intern, ext),
625 bfd *abfd AND
626 RFDT *intern AND
627 struct rfd_ext *ext)
628 {
629 bfd_h_put_32 (abfd, *intern, (bfd_byte *)ext->rfd);
630
631 #ifdef TEST
632 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
633 abort();
634 #endif
635 }
636
637 /* Swap in an optimization symbol. */
638
639 void
640 DEFUN (ecoff_swap_opt_in, (abfd, ext_copy, intern),
641 bfd *abfd AND
642 struct opt_ext *ext_copy AND
643 OPTR *intern)
644 {
645 struct opt_ext ext[1];
646
647 *ext = *ext_copy; /* Make it reasonable to do in-place. */
648
649 if (abfd->xvec->header_byteorder_big_p != false)
650 {
651 intern->ot = ext->o_bits1[0];
652 intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_BIG)
653 | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_BIG)
654 | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_BIG));
655 }
656 else
657 {
658 intern->ot = ext->o_bits1[0];
659 intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
660 | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
661 | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
662 }
663
664 ecoff_swap_rndx_in (abfd->xvec->header_byteorder_big_p != false,
665 &ext->o_rndx, &intern->rndx);
666
667 intern->offset = bfd_h_get_32 (abfd, (bfd_byte *) ext->o_offset);
668
669 #ifdef TEST
670 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
671 abort();
672 #endif
673 }
674
675 /* Swap out an optimization symbol. */
676
677 void
678 DEFUN (ecoff_swap_opt_out, (abfd, intern_copy, ext),
679 bfd *abfd AND
680 OPTR *intern_copy AND
681 struct opt_ext *ext)
682 {
683 OPTR intern[1];
684
685 *intern = *intern_copy; /* Make it reasonable to do in-place. */
686
687 if (abfd->xvec->header_byteorder_big_p != false)
688 {
689 ext->o_bits1[0] = intern->ot;
690 ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
691 ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
692 ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
693 }
694 else
695 {
696 ext->o_bits1[0] = intern->ot;
697 ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
698 ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
699 ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
700 }
701
702 ecoff_swap_rndx_out (abfd->xvec->header_byteorder_big_p != false,
703 &intern->rndx, &ext->o_rndx);
704
705 bfd_h_put_32 (abfd, intern->value, (bfd_byte *) ext->o_offset);
706
707 #ifdef TEST
708 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
709 abort();
710 #endif
711 }
712
713 /* Swap in a dense number. */
714
715 void
716 DEFUN (ecoff_swap_dnr_in, (abfd, ext_copy, intern),
717 bfd *abfd AND
718 struct dnr_ext *ext_copy AND
719 DNR *intern)
720 {
721 struct dnr_ext ext[1];
722
723 *ext = *ext_copy; /* Make it reasonable to do in-place. */
724
725 intern->rfd = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_rfd);
726 intern->index = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_index);
727
728 #ifdef TEST
729 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
730 abort();
731 #endif
732 }
733
734 /* Swap out a dense number. */
735
736 void
737 DEFUN (ecoff_swap_dnr_out, (abfd, intern_copy, ext),
738 bfd *abfd AND
739 DNR *intern_copy AND
740 struct dnr_ext *ext)
741 {
742 DNR intern[1];
743
744 *intern = *intern_copy; /* Make it reasonable to do in-place. */
745
746 bfd_h_put_32 (abfd, intern->rfd, (bfd_byte *) ext->d_rfd);
747 bfd_h_put_32 (abfd, intern->index, (bfd_byte *) ext->d_index);
748
749 #ifdef TEST
750 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
751 abort();
752 #endif
753 }
This page took 0.046575 seconds and 4 git commands to generate.