Use struct bfd_seclet * rather than bfd_seclet_type in prototypes to
[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 /* These routines are not yet called from BFD. They are called from
21 the MIPS symbol reading code in GDB. However, they are in the BFD
22 library because they will eventually be useful if and when BFD
23 supports reading or writing of MIPS symbol tables.
24
25 The routines in this file convert the external representation of
26 ECOFF symbol tables to the internal (usual struct) representation.
27 On a machine with the same byte-order and the same basic type
28 sizes and alignments as a MIPS machine, this is a no-op.
29 If the symbol TEST is defined when this file is compiled, a comparison
30 is made to ensure that, in fact, the output is bit-for-bit the same as
31 the input. Of course, this symbol should only be defined when
32 deliberately testing the code on a machine with the proper byte sex
33 and such. */
34
35 #include "bfd.h"
36 #include "coff/sym.h" /* MIPS symbols */
37 #include "coff/symconst.h" /* MIPS symbols */
38 #include "coff/ecoff-ext.h" /* ECOFF external struct defns */
39
40 void
41 DEFUN (ecoff_swap_hdr_in, (abfd, ext_copy, intern),
42 bfd *abfd AND
43 struct hdr_ext *ext_copy AND
44 HDRR *intern)
45 {
46 struct hdr_ext ext[1];
47
48 *ext = *ext_copy;
49
50 intern->magic = bfd_h_get_16 (abfd, (bfd_byte *)ext->h_magic);
51 intern->vstamp = bfd_h_get_16 (abfd, (bfd_byte *)ext->h_vstamp);
52 intern->ilineMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ilineMax);
53 intern->cbLine = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbLine);
54 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbLineOffset);
55 intern->idnMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_idnMax);
56 intern->cbDnOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbDnOffset);
57 intern->ipdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ipdMax);
58 intern->cbPdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbPdOffset);
59 intern->isymMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_isymMax);
60 intern->cbSymOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSymOffset);
61 intern->ioptMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ioptMax);
62 intern->cbOptOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbOptOffset);
63 intern->iauxMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iauxMax);
64 intern->cbAuxOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbAuxOffset);
65 intern->issMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issMax);
66 intern->cbSsOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSsOffset);
67 intern->issExtMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issExtMax);
68 intern->cbSsExtOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSsExtOffset);
69 intern->ifdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ifdMax);
70 intern->cbFdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbFdOffset);
71 intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_crfd);
72 intern->cbRfdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbRfdOffset);
73 intern->iextMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iextMax);
74 intern->cbExtOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbExtOffset);
75
76 #ifdef TEST
77 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
78 abort();
79 #endif
80 }
81
82 /* Swap in the file descriptor record. */
83
84 void
85 DEFUN (ecoff_swap_fdr_in, (abfd, ext_copy, intern),
86 bfd *abfd AND
87 struct fdr_ext *ext_copy AND
88 FDR *intern)
89 {
90 struct fdr_ext ext[1];
91
92 *ext = *ext_copy; /* Make it reasonable to do in-place. */
93
94 intern->adr = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_adr);
95 intern->rss = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
96 intern->issBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_issBase);
97 intern->cbSs = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbSs);
98 intern->isymBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_isymBase);
99 intern->csym = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_csym);
100 intern->ilineBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ilineBase);
101 intern->cline = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
102 intern->ioptBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
103 intern->copt = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
104 intern->ipdFirst = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
105 intern->cpd = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
106 intern->iauxBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_iauxBase);
107 intern->caux = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_caux);
108 intern->rfdBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rfdBase);
109 intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_crfd);
110
111 /* now the fun stuff... */
112 if (abfd->xvec->header_byteorder_big_p != false) {
113 intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
114 >> FDR_BITS1_LANG_SH_BIG;
115 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
116 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
117 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
118 intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
119 >> FDR_BITS2_GLEVEL_SH_BIG;
120 /* intern->reserved we ignore. */
121 } else {
122 intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
123 >> FDR_BITS1_LANG_SH_LITTLE;
124 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
125 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
126 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
127 intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
128 >> FDR_BITS2_GLEVEL_SH_LITTLE;
129 /* intern->reserved we ignore. */
130 }
131
132 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbLineOffset);
133 intern->cbLine = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbLine);
134
135 #ifdef TEST
136 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
137 abort();
138 #endif
139 }
140
141
142
143 /* Swap in the procedure descriptor record. */
144
145 void
146 DEFUN (ecoff_swap_pdr_in, (abfd, ext_copy, intern),
147 bfd *abfd AND
148 struct pdr_ext *ext_copy AND
149 PDR *intern)
150 {
151 struct pdr_ext ext[1];
152
153 *ext = *ext_copy; /* Make it reasonable to do in-place. */
154
155 intern->adr = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_adr);
156 intern->isym = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
157 intern->iline = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
158 intern->regmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
159 intern->regoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regoffset);
160 intern->iopt = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iopt);
161 intern->fregmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
162 intern->fregoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregoffset);
163 intern->frameoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_frameoffset);
164 intern->framereg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
165 intern->pcreg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
166 intern->lnLow = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
167 intern->lnHigh = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
168 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_cbLineOffset);
169
170 #ifdef TEST
171 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
172 abort();
173 #endif
174 }
175
176
177 /* Swap in a symbol record. */
178
179 void
180 DEFUN (ecoff_swap_sym_in, (abfd, ext_copy, intern),
181 bfd *abfd AND
182 struct sym_ext *ext_copy AND
183 SYMR *intern)
184 {
185 struct sym_ext ext[1];
186
187 *ext = *ext_copy; /* Make it reasonable to do in-place. */
188
189 intern->iss = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_iss);
190 intern->value = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_value);
191
192 /* now the fun stuff... */
193 if (abfd->xvec->header_byteorder_big_p != false) {
194 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
195 >> SYM_BITS1_ST_SH_BIG;
196 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
197 << SYM_BITS1_SC_SH_LEFT_BIG)
198 | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
199 >> SYM_BITS2_SC_SH_BIG);
200 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
201 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
202 << SYM_BITS2_INDEX_SH_LEFT_BIG)
203 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
204 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
205 } else {
206 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
207 >> SYM_BITS1_ST_SH_LITTLE;
208 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
209 >> SYM_BITS1_SC_SH_LITTLE)
210 | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
211 << SYM_BITS2_SC_SH_LEFT_LITTLE);
212 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
213 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
214 >> SYM_BITS2_INDEX_SH_LITTLE)
215 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
216 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
217 }
218
219 #ifdef TEST
220 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
221 abort();
222 #endif
223 }
224
225
226 /* Swap in an external symbol record. */
227
228 void
229 DEFUN (ecoff_swap_ext_in, (abfd, ext_copy, intern),
230 bfd *abfd AND
231 struct ext_ext *ext_copy AND
232 EXTR *intern)
233 {
234 struct ext_ext ext[1];
235
236 *ext = *ext_copy; /* Make it reasonable to do in-place. */
237
238 /* now the fun stuff... */
239 if (abfd->xvec->header_byteorder_big_p != false) {
240 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
241 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
242 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
243 } else {
244 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
245 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
246 intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
247 }
248
249 intern->ifd = bfd_h_get_16 (abfd, (bfd_byte *)ext->es_ifd);
250 ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
251
252 #ifdef TEST
253 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
254 abort();
255 #endif
256 }
257
258 /* Swap in a type information record.
259 BIGEND says whether AUX symbols are big-endian or little-endian; this
260 info comes from the file header record (fh-fBigendian). */
261
262 void
263 DEFUN (ecoff_swap_tir_in, (bigend, ext_copy, intern),
264 int bigend AND
265 struct tir_ext *ext_copy AND
266 TIR *intern)
267 {
268 struct tir_ext ext[1];
269
270 *ext = *ext_copy; /* Make it reasonable to do in-place. */
271
272 /* now the fun stuff... */
273 if (bigend) {
274 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
275 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
276 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_BIG)
277 >> TIR_BITS1_BT_SH_BIG;
278 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_BIG)
279 >> TIR_BITS_TQ4_SH_BIG;
280 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_BIG)
281 >> TIR_BITS_TQ5_SH_BIG;
282 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_BIG)
283 >> TIR_BITS_TQ0_SH_BIG;
284 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_BIG)
285 >> TIR_BITS_TQ1_SH_BIG;
286 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_BIG)
287 >> TIR_BITS_TQ2_SH_BIG;
288 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_BIG)
289 >> TIR_BITS_TQ3_SH_BIG;
290 } else {
291 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_LITTLE);
292 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_LITTLE);
293 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_LITTLE)
294 >> TIR_BITS1_BT_SH_LITTLE;
295 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_LITTLE)
296 >> TIR_BITS_TQ4_SH_LITTLE;
297 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_LITTLE)
298 >> TIR_BITS_TQ5_SH_LITTLE;
299 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_LITTLE)
300 >> TIR_BITS_TQ0_SH_LITTLE;
301 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_LITTLE)
302 >> TIR_BITS_TQ1_SH_LITTLE;
303 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_LITTLE)
304 >> TIR_BITS_TQ2_SH_LITTLE;
305 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_LITTLE)
306 >> TIR_BITS_TQ3_SH_LITTLE;
307 }
308
309 #ifdef TEST
310 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
311 abort();
312 #endif
313 }
314
315 /* Swap in a relative symbol record. BIGEND says whether it is in
316 big-endian or little-endian format.*/
317
318 void
319 DEFUN (ecoff_swap_rndx_in, (bigend, ext_copy, intern),
320 int bigend AND
321 struct rndx_ext *ext_copy AND
322 RNDXR *intern)
323 {
324 struct rndx_ext ext[1];
325
326 *ext = *ext_copy; /* Make it reasonable to do in-place. */
327
328 /* now the fun stuff... */
329 if (bigend) {
330 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
331 | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
332 >> RNDX_BITS1_RFD_SH_BIG);
333 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_BIG)
334 << RNDX_BITS1_INDEX_SH_LEFT_BIG)
335 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG)
336 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG);
337 } else {
338 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE)
339 | ((ext->r_bits[1] & RNDX_BITS1_RFD_LITTLE)
340 << RNDX_BITS1_RFD_SH_LEFT_LITTLE);
341 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_LITTLE)
342 >> RNDX_BITS1_INDEX_SH_LITTLE)
343 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE)
344 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE);
345 }
346
347 #ifdef TEST
348 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
349 abort();
350 #endif
351 }
352
353 /* Swap in a relative file descriptor. */
354
355 void
356 DEFUN (ecoff_swap_rfd_in, (abfd, ext, intern),
357 bfd *abfd AND
358 struct rfd_ext *ext AND
359 RFDT *intern)
360 {
361
362 *intern = bfd_h_get_32 (abfd, (bfd_byte *)ext->rfd);
363
364 #ifdef TEST
365 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
366 abort();
367 #endif
368 }
This page took 0.043156 seconds and 4 git commands to generate.