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