]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - include/coff/ecoff.h
2005-07-14 Kelley Cook <kcook@gcc.gnu.org>
[thirdparty/binutils-gdb.git] / include / coff / ecoff.h
CommitLineData
252b5132
RH
1/* Generic ECOFF support.
2 This does not include symbol information, found in sym.h and
4f1d9bd8
NC
3 symconst.h.
4
c3aa17e9 5 Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4f1d9bd8
NC
6
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.
b34976b6 11
4f1d9bd8
NC
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.
b34976b6 16
4f1d9bd8
NC
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
e172dbf8 19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
b34976b6 20
4f1d9bd8
NC
21#ifndef ECOFF_H
22#define ECOFF_H
252b5132
RH
23
24/* Mips magic numbers used in filehdr. MIPS_MAGIC_LITTLE is used on
25 little endian machines. MIPS_MAGIC_BIG is used on big endian
26 machines. Where is MIPS_MAGIC_1 from? */
27#define MIPS_MAGIC_1 0x0180
28#define MIPS_MAGIC_LITTLE 0x0162
29#define MIPS_MAGIC_BIG 0x0160
30
31/* These are the magic numbers used for MIPS code compiled at ISA
32 level 2. */
33#define MIPS_MAGIC_LITTLE2 0x0166
34#define MIPS_MAGIC_BIG2 0x0163
35
36/* These are the magic numbers used for MIPS code compiled at ISA
37 level 3. */
38#define MIPS_MAGIC_LITTLE3 0x142
39#define MIPS_MAGIC_BIG3 0x140
40
41/* Alpha magic numbers used in filehdr. */
42#define ALPHA_MAGIC 0x183
43#define ALPHA_MAGIC_BSD 0x185
44
45/* Magic numbers used in a.out header. */
46#define ECOFF_AOUT_OMAGIC 0407 /* not demand paged (ld -N). */
47#define ECOFF_AOUT_ZMAGIC 0413 /* demand load format, eg normal ld output */
48
49/* Names of special sections. */
50#define _TEXT ".text"
51#define _DATA ".data"
52#define _BSS ".bss"
53#define _RDATA ".rdata"
54#define _SDATA ".sdata"
55#define _SBSS ".sbss"
56#define _LITA ".lita"
57#define _LIT4 ".lit4"
58#define _LIT8 ".lit8"
59#define _LIB ".lib"
60#define _INIT ".init"
61#define _FINI ".fini"
62#define _PDATA ".pdata"
63#define _XDATA ".xdata"
64#define _GOT ".got"
65#define _HASH ".hash"
66#define _DYNSYM ".dynsym"
67#define _DYNSTR ".dynstr"
68#define _RELDYN ".rel.dyn"
69#define _CONFLIC ".conflic"
70#define _COMMENT ".comment"
71#define _LIBLIST ".liblist"
72#define _DYNAMIC ".dynamic"
73#define _RCONST ".rconst"
74
75/* ECOFF uses some additional section flags. */
76#define STYP_RDATA 0x100
77#define STYP_SDATA 0x200
78#define STYP_SBSS 0x400
79#define STYP_GOT 0x1000
80#define STYP_DYNAMIC 0x2000
81#define STYP_DYNSYM 0x4000
82#define STYP_RELDYN 0x8000
83#define STYP_DYNSTR 0x10000
84#define STYP_HASH 0x20000
85#define STYP_LIBLIST 0x40000
86#define STYP_CONFLIC 0x100000
87#define STYP_ECOFF_FINI 0x1000000
88#define STYP_EXTENDESC 0x2000000 /* 0x02FFF000 bits => scn type, rest clr */
89#define STYP_LITA 0x4000000
90#define STYP_LIT8 0x8000000
91#define STYP_LIT4 0x10000000
92#define STYP_ECOFF_LIB 0x40000000
93#define STYP_ECOFF_INIT 0x80000000
94#define STYP_OTHER_LOAD (STYP_ECOFF_INIT | STYP_ECOFF_FINI)
95
96/* extended section types */
97#define STYP_COMMENT 0x2100000
98#define STYP_RCONST 0x2200000
99#define STYP_XDATA 0x2400000
100#define STYP_PDATA 0x2800000
101
102/* The linker needs a section to hold small common variables while
103 linking. There is no convenient way to create it when the linker
104 needs it, so we always create one for each BFD. We then avoid
105 writing it out. */
106#define SCOMMON ".scommon"
107
108/* If the extern bit in a reloc is 1, then r_symndx is an index into
109 the external symbol table. If the extern bit is 0, then r_symndx
110 indicates a section, and is one of the following values. */
111#define RELOC_SECTION_NONE 0
112#define RELOC_SECTION_TEXT 1
113#define RELOC_SECTION_RDATA 2
114#define RELOC_SECTION_DATA 3
115#define RELOC_SECTION_SDATA 4
116#define RELOC_SECTION_SBSS 5
117#define RELOC_SECTION_BSS 6
118#define RELOC_SECTION_INIT 7
119#define RELOC_SECTION_LIT8 8
120#define RELOC_SECTION_LIT4 9
121#define RELOC_SECTION_XDATA 10
122#define RELOC_SECTION_PDATA 11
123#define RELOC_SECTION_FINI 12
124#define RELOC_SECTION_LITA 13
125#define RELOC_SECTION_ABS 14
126#define RELOC_SECTION_RCONST 15
127
128#define NUM_RELOC_SECTIONS 16
129
130/********************** STABS **********************/
131
132/* gcc uses mips-tfile to output type information in special stabs
133 entries. These must match the corresponding definition in
134 gcc/config/mips.h. At some point, these should probably go into a
135 shared include file, but currently gcc and gdb do not share any
136 directories. */
137#define CODE_MASK 0x8F300
138#define ECOFF_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
139#define ECOFF_MARK_STAB(code) ((code)+CODE_MASK)
140#define ECOFF_UNMARK_STAB(code) ((code)-CODE_MASK)
141#define STABS_SYMBOL "@stabs"
142
143/********************** COFF **********************/
144
145/* gcc also uses mips-tfile to output COFF debugging information.
146 These are the values it uses when outputting the .type directive.
147 These should also be in a shared include file. */
148#define N_BTMASK (017)
149#define N_TMASK (060)
150#define N_BTSHFT (4)
151#define N_TSHIFT (2)
152
153/********************** AUX **********************/
154
155/* The auxiliary type information is the same on all known ECOFF
156 targets. I can't see any reason that it would ever change, so I am
157 going to gamble and define the external structures here, in the
158 target independent ECOFF header file. The internal forms are
159 defined in coff/sym.h, which was originally donated by MIPS
160 Computer Systems. */
161
162/* Type information external record */
163
164struct tir_ext {
165 unsigned char t_bits1[1];
166 unsigned char t_tq45[1];
167 unsigned char t_tq01[1];
168 unsigned char t_tq23[1];
169};
170
171#define TIR_BITS1_FBITFIELD_BIG ((unsigned int) 0x80)
172#define TIR_BITS1_FBITFIELD_LITTLE ((unsigned int) 0x01)
173
174#define TIR_BITS1_CONTINUED_BIG ((unsigned int) 0x40)
175#define TIR_BITS1_CONTINUED_LITTLE ((unsigned int) 0x02)
176
177#define TIR_BITS1_BT_BIG ((unsigned int) 0x3F)
178#define TIR_BITS1_BT_SH_BIG 0
179#define TIR_BITS1_BT_LITTLE ((unsigned int) 0xFC)
180#define TIR_BITS1_BT_SH_LITTLE 2
181
182#define TIR_BITS_TQ4_BIG ((unsigned int) 0xF0)
183#define TIR_BITS_TQ4_SH_BIG 4
184#define TIR_BITS_TQ5_BIG ((unsigned int) 0x0F)
185#define TIR_BITS_TQ5_SH_BIG 0
186#define TIR_BITS_TQ4_LITTLE ((unsigned int) 0x0F)
187#define TIR_BITS_TQ4_SH_LITTLE 0
188#define TIR_BITS_TQ5_LITTLE ((unsigned int) 0xF0)
189#define TIR_BITS_TQ5_SH_LITTLE 4
190
191#define TIR_BITS_TQ0_BIG ((unsigned int) 0xF0)
192#define TIR_BITS_TQ0_SH_BIG 4
193#define TIR_BITS_TQ1_BIG ((unsigned int) 0x0F)
194#define TIR_BITS_TQ1_SH_BIG 0
195#define TIR_BITS_TQ0_LITTLE ((unsigned int) 0x0F)
196#define TIR_BITS_TQ0_SH_LITTLE 0
197#define TIR_BITS_TQ1_LITTLE ((unsigned int) 0xF0)
198#define TIR_BITS_TQ1_SH_LITTLE 4
199
200#define TIR_BITS_TQ2_BIG ((unsigned int) 0xF0)
201#define TIR_BITS_TQ2_SH_BIG 4
202#define TIR_BITS_TQ3_BIG ((unsigned int) 0x0F)
203#define TIR_BITS_TQ3_SH_BIG 0
204#define TIR_BITS_TQ2_LITTLE ((unsigned int) 0x0F)
205#define TIR_BITS_TQ2_SH_LITTLE 0
206#define TIR_BITS_TQ3_LITTLE ((unsigned int) 0xF0)
207#define TIR_BITS_TQ3_SH_LITTLE 4
208
209/* Relative symbol external record */
210
211struct rndx_ext {
212 unsigned char r_bits[4];
213};
214
215#define RNDX_BITS0_RFD_SH_LEFT_BIG 4
216#define RNDX_BITS1_RFD_BIG ((unsigned int) 0xF0)
217#define RNDX_BITS1_RFD_SH_BIG 4
218
219#define RNDX_BITS0_RFD_SH_LEFT_LITTLE 0
220#define RNDX_BITS1_RFD_LITTLE ((unsigned int) 0x0F)
221#define RNDX_BITS1_RFD_SH_LEFT_LITTLE 8
222
223#define RNDX_BITS1_INDEX_BIG ((unsigned int) 0x0F)
224#define RNDX_BITS1_INDEX_SH_LEFT_BIG 16
225#define RNDX_BITS2_INDEX_SH_LEFT_BIG 8
226#define RNDX_BITS3_INDEX_SH_LEFT_BIG 0
227
228#define RNDX_BITS1_INDEX_LITTLE ((unsigned int) 0xF0)
229#define RNDX_BITS1_INDEX_SH_LITTLE 4
230#define RNDX_BITS2_INDEX_SH_LEFT_LITTLE 4
231#define RNDX_BITS3_INDEX_SH_LEFT_LITTLE 12
232
233/* Auxiliary symbol information external record */
234
235union aux_ext {
236 struct tir_ext a_ti;
237 struct rndx_ext a_rndx;
238 unsigned char a_dnLow[4];
239 unsigned char a_dnHigh[4];
240 unsigned char a_isym[4];
241 unsigned char a_iss[4];
242 unsigned char a_width[4];
243 unsigned char a_count[4];
244};
245
246#define AUX_GET_ANY(bigend, ax, field) \
247 ((bigend) ? bfd_getb32 ((ax)->field) : bfd_getl32 ((ax)->field))
248
249#define AUX_GET_DNLOW(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_dnLow)
250#define AUX_GET_DNHIGH(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_dnHigh)
251#define AUX_GET_ISYM(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_isym)
252#define AUX_GET_ISS(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_iss)
253#define AUX_GET_WIDTH(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_width)
254#define AUX_GET_COUNT(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_count)
255
256#define AUX_PUT_ANY(bigend, val, ax, field) \
257 ((bigend) \
258 ? (bfd_putb32 ((bfd_vma) (val), (ax)->field), 0) \
259 : (bfd_putl32 ((bfd_vma) (val), (ax)->field), 0))
260
261#define AUX_PUT_DNLOW(bigend, val, ax) \
262 AUX_PUT_ANY ((bigend), (val), (ax), a_dnLow)
263#define AUX_PUT_DNHIGH(bigend, val, ax) \
264 AUX_PUT_ANY ((bigend), (val), (ax), a_dnHigh)
265#define AUX_PUT_ISYM(bigend, val, ax) \
266 AUX_PUT_ANY ((bigend), (val), (ax), a_isym)
267#define AUX_PUT_ISS(bigend, val, ax) \
268 AUX_PUT_ANY ((bigend), (val), (ax), a_iss)
269#define AUX_PUT_WIDTH(bigend, val, ax) \
270 AUX_PUT_ANY ((bigend), (val), (ax), a_width)
271#define AUX_PUT_COUNT(bigend, val, ax) \
272 AUX_PUT_ANY ((bigend), (val), (ax), a_count)
273
274/********************** SYMBOLS **********************/
275
276/* For efficiency, gdb deals directly with the unswapped symbolic
277 information (that way it only takes the time to swap information
278 that it really needs to read). gdb originally retrieved the
279 information directly from the BFD backend information, but that
280 strategy, besides being sort of ugly, does not work for MIPS ELF,
281 which also uses ECOFF debugging information. This structure holds
282 pointers to the (mostly) unswapped symbolic information. */
283
284struct ecoff_debug_info
285{
286 /* The swapped ECOFF symbolic header. */
287 HDRR symbolic_header;
288
289 /* Pointers to the unswapped symbolic information. Note that the
290 pointers to external structures point to different sorts of
291 information on different ECOFF targets. The ecoff_debug_swap
292 structure provides the sizes of the structures and the functions
293 needed to swap the information in and out. These pointers are
294 all pointers to arrays, not single structures. They will be NULL
295 if there are no instances of the relevant structure. These
296 fields are also used by the assembler to output ECOFF debugging
297 information. */
298 unsigned char *line;
a6f5b2c3
AJ
299 void *external_dnr; /* struct dnr_ext */
300 void *external_pdr; /* struct pdr_ext */
301 void *external_sym; /* struct sym_ext */
302 void *external_opt; /* struct opt_ext */
252b5132
RH
303 union aux_ext *external_aux;
304 char *ss;
305 char *ssext;
a6f5b2c3
AJ
306 void *external_fdr; /* struct fdr_ext */
307 void *external_rfd; /* struct rfd_ext */
308 void *external_ext; /* struct ext_ext */
252b5132
RH
309
310 /* These fields are used when linking. They may disappear at some
311 point. */
312 char *ssext_end;
a6f5b2c3 313 void *external_ext_end;
252b5132
RH
314
315 /* When linking, this field holds a mapping from the input FDR
316 numbers to the output numbers, and is used when writing out the
317 external symbols. It is NULL if no mapping is required. */
318 RFDT *ifdmap;
319
320 /* The swapped FDR information. Currently this is never NULL, but
321 code using this structure should probably double-check in case
322 this changes in the future. This is a pointer to an array, not a
323 single structure. */
324 FDR *fdr;
252b5132
RH
325};
326
327/* These structures are used by the ECOFF find_nearest_line function. */
328
329struct ecoff_fdrtab_entry
330{
331 /* Base address in .text of this FDR. */
332 bfd_vma base_addr;
333 FDR *fdr;
334};
335
336struct ecoff_find_line
337{
338 /* Allocated memory to hold function and file names. */
339 char *find_buffer;
340
341 /* FDR table, sorted by address: */
342 long fdrtab_len;
343 struct ecoff_fdrtab_entry *fdrtab;
344
345 /* Cache entry for most recently found line information. The sect
346 field is NULL if this cache does not contain valid information. */
347 struct
348 {
349 asection *sect;
350 bfd_vma start;
351 bfd_vma stop;
352 const char *filename;
353 const char *functionname;
354 unsigned int line_num;
355 } cache;
356};
357
358/********************** SWAPPING **********************/
359
360/* The generic ECOFF code needs to be able to swap debugging
361 information in and out in the specific format used by a particular
362 ECOFF implementation. This structure provides the information
363 needed to do this. */
364
365struct ecoff_debug_swap
366{
367 /* Symbol table magic number. */
368 int sym_magic;
369 /* Alignment of debugging information. E.g., 4. */
370 bfd_size_type debug_align;
371 /* Sizes of external symbolic information. */
372 bfd_size_type external_hdr_size;
373 bfd_size_type external_dnr_size;
374 bfd_size_type external_pdr_size;
375 bfd_size_type external_sym_size;
376 bfd_size_type external_opt_size;
377 bfd_size_type external_fdr_size;
378 bfd_size_type external_rfd_size;
379 bfd_size_type external_ext_size;
380 /* Functions to swap in external symbolic data. */
a6f5b2c3
AJ
381 void (*swap_hdr_in) (bfd *, void *, HDRR *);
382 void (*swap_dnr_in) (bfd *, void *, DNR *);
383 void (*swap_pdr_in) (bfd *, void *, PDR *);
384 void (*swap_sym_in) (bfd *, void *, SYMR *);
385 void (*swap_opt_in) (bfd *, void *, OPTR *);
386 void (*swap_fdr_in) (bfd *, void *, FDR *);
387 void (*swap_rfd_in) (bfd *, void *, RFDT *);
388 void (*swap_ext_in) (bfd *, void *, EXTR *);
389 void (*swap_tir_in) (int, const struct tir_ext *, TIR *);
390 void (*swap_rndx_in) (int, const struct rndx_ext *, RNDXR *);
252b5132 391 /* Functions to swap out external symbolic data. */
a6f5b2c3
AJ
392 void (*swap_hdr_out) (bfd *, const HDRR *, void *);
393 void (*swap_dnr_out) (bfd *, const DNR *, void *);
394 void (*swap_pdr_out) (bfd *, const PDR *, void *);
395 void (*swap_sym_out) (bfd *, const SYMR *, void *);
396 void (*swap_opt_out) (bfd *, const OPTR *, void *);
397 void (*swap_fdr_out) (bfd *, const FDR *, void *);
398 void (*swap_rfd_out) (bfd *, const RFDT *, void *);
399 void (*swap_ext_out) (bfd *, const EXTR *, void *);
400 void (*swap_tir_out) (int, const TIR *, struct tir_ext *);
401 void (*swap_rndx_out) (int, const RNDXR *, struct rndx_ext *);
252b5132
RH
402 /* Function to read symbol data and set up pointers in
403 ecoff_debug_info structure. The section argument is used for
404 ELF, not straight ECOFF. */
a6f5b2c3 405 bfd_boolean (*read_debug_info) (bfd *, asection *, struct ecoff_debug_info *);
252b5132
RH
406};
407
408#endif /* ! defined (ECOFF_H) */