coff_sym.h revision 13981:577196ddd040
1/*
2 * Copyright (c) 2003, 2005-2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Steve Reinhardt
29 */
30
31/*
32 * Taken from binutils-2.14.90.0.5 include/coff/sym.h
33 */
34
35/* Declarations of internal format of MIPS ECOFF symbols.
36   Originally contributed by MIPS Computer Systems and Third Eye Software.
37   Changes contributed by Cygnus Support are in the public domain.
38
39   This file is just aggregated with the files that make up the GNU
40   release; it is not considered part of GAS, GDB, or other GNU
41   programs.  */
42
43/*
44 * |-----------------------------------------------------------|
45 * | Copyright (c) 1992, 1991, 1990 MIPS Computer Systems, Inc.|
46 * | MIPS Computer Systems, Inc. grants reproduction and use   |
47 * | rights to all parties, PROVIDED that this comment is      |
48 * | maintained in the copy.                                   |
49 * |-----------------------------------------------------------|
50 */
51#ifndef _SYM_H
52#define _SYM_H
53
54/* (C) Copyright 1984 by Third Eye Software, Inc.
55 *
56 * Third Eye Software, Inc. grants reproduction and use rights to
57 * all parties, PROVIDED that this comment is maintained in the copy.
58 *
59 * Third Eye makes no claims about the applicability of this
60 * symbol table to a particular use.
61 */
62
63/*
64 * This file contains the definition of the Third Eye Symbol Table.
65 *
66 * Symbols are assumed to be in 'encounter order' - i.e. the order that
67 * the things they represent were encountered by the compiler/assembler/loader.
68 * EXCEPT for globals!  These are assumed to be bunched together,
69 * probably right after the last 'normal' symbol.  Globals ARE sorted
70 * in ascending order.
71 *
72 * -----------------------------------------------------------------------
73 * A brief word about Third Eye naming/use conventions:
74 *
75 * All arrays and index's are 0 based.
76 * All "ifooMax" values are the highest legal value PLUS ONE. This makes
77 * them good for allocating arrays, etc. All checks are "ifoo < ifooMax".
78 *
79 * "isym"       Index into the SYMbol table.
80 * "ipd"        Index into the Procedure Descriptor array.
81 * "ifd"        Index into the File Descriptor array.
82 * "iss"        Index into String Space.
83 * "cb"         Count of Bytes.
84 * "rgPd"       array whose domain is "0..ipdMax-1" and RanGe is PDR.
85 * "rgFd"       array whose domain is "0..ifdMax-1" and RanGe is FDR.
86 */
87
88
89/*
90 * Symbolic Header (HDR) structure.
91 * As long as all the pointers are set correctly,
92 * we don't care WHAT order the various sections come out in!
93 *
94 * A file produced solely for the use of CDB will probably NOT have
95 * any instructions or data areas in it, as these are available
96 * in the original.
97 */
98
99typedef struct ecoff_symhdr {
100    coff_short  magic;          /* to verify validity of the table */
101    coff_short  vstamp;         /* version stamp */
102    coff_int    ilineMax;       /* number of line number entries */
103    coff_int    idnMax;         /* max index into dense number table */
104    coff_int    ipdMax;         /* number of procedures */
105    coff_int    isymMax;        /* number of local symbols */
106    coff_int    ioptMax;        /* max index into optimization symbol entries */
107    coff_int    iauxMax;        /* number of auxillary symbol entries */
108    coff_int    issMax;         /* max index into local strings */
109    coff_int    issExtMax;      /* max index into external strings */
110    coff_int    ifdMax;         /* number of file descriptor entries */
111    coff_int    crfd;           /* number of relative file descriptor entries */
112    coff_int    iextMax;        /* max index into external symbols */
113    coff_addr   cbLine;         /* number of bytes for line number entries */
114    coff_addr   cbLineOffset;   /* offset to start of line number entries*/
115    coff_addr   cbDnOffset;     /* offset to start dense number table */
116    coff_addr   cbPdOffset;     /* offset to procedure descriptor table */
117    coff_addr   cbSymOffset;    /* offset to start of local symbols*/
118    coff_addr   cbOptOffset;    /* offset to optimization symbol entries */
119    coff_addr   cbAuxOffset;    /* offset to start of auxillary symbol entries*/
120    coff_addr   cbSsOffset;     /* offset to start of local strings */
121    coff_addr   cbSsExtOffset;  /* offset to start of external strings */
122    coff_addr   cbFdOffset;     /* offset to file descriptor table */
123    coff_addr   cbRfdOffset;    /* offset to relative file descriptor table */
124    coff_addr   cbExtOffset;    /* offset to start of external symbol entries*/
125    /* If you add machine dependent fields, add them here */
126} HDRR, *pHDRR;
127#define cbHDRR sizeof(HDRR)
128#define hdrNil ((pHDRR)0)
129
130/*
131 * The FDR and PDR structures speed mapping of address <-> name.
132 * They are sorted in ascending memory order and are kept in
133 * memory by CDB at runtime.
134 */
135
136/*
137 * File Descriptor
138 *
139 * There is one of these for EVERY FILE, whether compiled with
140 * full debugging symbols or not.  The name of a file should be
141 * the path name given to the compiler.  This allows the user
142 * to simply specify the names of the directories where the COMPILES
143 * were done, and we will be able to find their files.
144 * A field whose comment starts with "R - " indicates that it will be
145 * setup at runtime.
146 */
147typedef struct ecoff_fdr {
148    coff_addr   adr;            /* memory address of beginning of file */
149    coff_addr   cbLineOffset;   /* byte offset from header for this file ln's */
150    coff_addr   cbLine;         /* size of lines for this file */
151    coff_addr   cbSs;           /* number of bytes in the ss */
152    coff_int    rss;            /* file name (of source, if known) */
153    coff_int    issBase;        /* file's string space */
154    coff_int    isymBase;       /* beginning of symbols */
155    coff_int    csym;           /* count file's of symbols */
156    coff_int    ilineBase;      /* file's line symbols */
157    coff_int    cline;          /* count of file's line symbols */
158    coff_int    ioptBase;       /* file's optimization entries */
159    coff_int    copt;           /* count of file's optimization entries */
160    coff_int    ipdFirst;       /* start of procedures for this file */
161    coff_int    cpd;            /* count of procedures for this file */
162    coff_int    iauxBase;       /* file's auxiliary entries */
163    coff_int    caux;           /* count of file's auxiliary entries */
164    coff_int    rfdBase;        /* index into the file indirect table */
165    coff_int    crfd;           /* count file indirect entries */
166    unsigned lang: 5;   /* language for this file */
167    unsigned fMerge : 1;        /* whether this file can be merged */
168    unsigned fReadin : 1;       /* true if it was read in (not just created) */
169    unsigned fBigendian : 1;/* if set, was compiled on big endian machine */
170    /*  aux's will be in compile host's sex */
171    unsigned glevel : 2;        /* level this file was compiled with */
172    unsigned reserved : 22;  /* reserved for future use */
173    coff_uint   reserved2;
174} FDR, *pFDR;
175#define cbFDR sizeof(FDR)
176#define fdNil ((pFDR)0)
177#define ifdNil -1
178#define ifdTemp 0
179#define ilnNil -1
180
181
182/*
183 * Procedure Descriptor
184 *
185 * There is one of these for EVERY TEXT LABEL.
186 * If a procedure is in a file with full symbols, then isym
187 * will point to the PROC symbols, else it will point to the
188 * global symbol for the label.
189 */
190
191typedef struct pdr {
192    coff_addr   adr;            /* memory address of start of procedure */
193    coff_addr   cbLineOffset;   /* byte offset for this procedure from the fd base */
194    coff_int    isym;           /* start of local symbol entries */
195    coff_int    iline;          /* start of line number entries*/
196    coff_uint   regmask;        /* save register mask */
197    coff_int    regoffset;      /* save register offset */
198    coff_int    iopt;           /* start of optimization symbol entries*/
199    coff_uint   fregmask;       /* save floating point register mask */
200    coff_int    fregoffset;     /* save floating point register offset */
201    coff_int    frameoffset;    /* frame size */
202    coff_int    lnLow;          /* lowest line in the procedure */
203    coff_int    lnHigh;         /* highest line in the procedure */
204    /* These fields are new for 64 bit ECOFF.  */
205    unsigned gp_prologue : 8; /* byte size of GP prologue */
206    unsigned gp_used : 1;       /* true if the procedure uses GP */
207    unsigned reg_frame : 1;     /* true if register frame procedure */
208    unsigned prof : 1;  /* true if compiled with -pg */
209    unsigned reserved : 13;     /* reserved: must be zero */
210    unsigned localoff : 8;      /* offset of local variables from vfp */
211    coff_short  framereg;       /* frame pointer register */
212    coff_short  pcreg;          /* offset or reg of return pc */
213} PDR, *pPDR;
214#define cbPDR sizeof(PDR)
215#define pdNil ((pPDR) 0)
216#define ipdNil  -1
217
218/*
219 * Line Numbers
220 *
221 * Line Numbers are segregated from the normal symbols because they
222 * are [1] smaller , [2] are of no interest to your
223 * average loader, and [3] are never needed in the middle of normal
224 * scanning and therefore slow things down.
225 *
226 * By definition, the first LINER for any given procedure will have
227 * the first line of a procedure and represent the first address.
228 */
229
230typedef coff_int LINER, *pLINER;
231#define lineNil ((pLINER)0)
232#define cbLINER sizeof(LINER)
233#define ilineNil        -1
234
235
236
237/*
238 * The Symbol Structure         (GFW, to those who Know!)
239 */
240
241typedef struct ecoff_sym {
242    coff_long   value;          /* value of symbol */
243    coff_int    iss;            /* index into String Space of name */
244    unsigned st : 6;    /* symbol type */
245    unsigned sc  : 5;   /* storage class - text, data, etc */
246    unsigned reserved : 1;      /* reserved */
247    unsigned index : 20;        /* index into sym/aux table */
248} SYMR, *pSYMR;
249#define symNil ((pSYMR)0)
250#define cbSYMR sizeof(SYMR)
251#define isymNil -1
252#define indexNil 0xfffff
253#define issNil -1
254#define issNull 0
255
256
257/* The following converts a memory resident string to an iss.
258 * This hack is recognized in SbFIss, in sym.c of the debugger.
259 */
260#define IssFSb(sb) (0x80000000 | ((coff_ulong)(sb)))
261
262/* E X T E R N A L   S Y M B O L  R E C O R D
263 *
264 *      Same as the SYMR except it contains file context to determine where
265 *      the index is.
266 */
267typedef struct ecoff_extsym {
268    SYMR        asym;           /* symbol for the external */
269    unsigned jmptbl:1;  /* symbol is a jump table entry for shlibs */
270    unsigned cobol_main:1;      /* symbol is a cobol main procedure */
271    unsigned weakext:1; /* symbol is weak external */
272    unsigned reserved:29;       /* reserved for future use */
273    coff_int ifd;               /* where the iss and index fields point into */
274} EXTR, *pEXTR;
275#define extNil ((pEXTR)0)
276#define cbEXTR sizeof(EXTR)
277
278
279/* A U X I L L A R Y   T Y P E   I N F O R M A T I O N */
280
281/*
282 * Type Information Record
283 */
284typedef struct {
285    unsigned fBitfield : 1; /* set if bit width is specified */
286    unsigned continued : 1; /* indicates additional TQ info in next AUX */
287    unsigned bt  : 6;   /* basic type */
288    unsigned tq4 : 4;
289    unsigned tq5 : 4;
290    /* ---- 16 bit boundary ---- */
291    unsigned tq0 : 4;
292    unsigned tq1 : 4;   /* 6 type qualifiers - tqPtr, etc. */
293    unsigned tq2 : 4;
294    unsigned tq3 : 4;
295} TIR, *pTIR;
296#define cbTIR sizeof(TIR)
297#define tiNil ((pTIR)0)
298#define itqMax 6
299
300/*
301 * Relative symbol record
302 *
303 * If the rfd field is 4095, the index field indexes into the global symbol
304 *      table.
305 */
306
307typedef struct {
308    unsigned    rfd : 12;    /* index into the file indirect table */
309    unsigned    index : 20; /* index int sym/aux/iss tables */
310} RNDXR, *pRNDXR;
311#define cbRNDXR sizeof(RNDXR)
312#define rndxNil ((pRNDXR)0)
313
314/* dense numbers or sometimes called block numbers are stored in this type,
315 *      a rfd of 0xffffffff is an index into the global table.
316 */
317typedef struct {
318    coff_uint   rfd;    /* index into the file table */
319    coff_uint   index;  /* index int sym/aux/iss tables */
320} DNR, *pDNR;
321#define cbDNR sizeof(DNR)
322#define dnNil ((pDNR)0)
323
324
325
326/*
327 * Auxillary information occurs only if needed.
328 * It ALWAYS occurs in this order when present.
329
330            isymMac             used by stProc only
331            TIR                 type info
332            TIR                 additional TQ info (if first TIR was not enough)
333            rndx                if (bt == btStruct,btUnion,btEnum,btSet,btRange,
334                                    btTypedef):
335                                    rsym.index == iaux for btSet or btRange
336                                    else rsym.index == isym
337            dimLow              btRange, btSet
338            dimMac              btRange, btSet
339            rndx0               As many as there are tq arrays
340            dimLow0
341            dimHigh0
342            ...
343            rndxMax-1
344            dimLowMax-1
345            dimHighMax-1
346            width in bits       if (bit field), width in bits.
347 */
348#define cAuxMax (6 + (idimMax*3))
349
350/* a union of all possible info in the AUX universe */
351typedef union {
352    TIR ti;             /* type information record */
353    RNDXR       rndx;           /* relative index into symbol table */
354    coff_int    dnLow;          /* low dimension */
355    coff_int    dnHigh;         /* high dimension */
356    coff_int    isym;           /* symbol table index (end of proc) */
357    coff_int    iss;            /* index into string space (not used) */
358    coff_int    width;          /* width for non-default sized struc fields */
359    coff_int    count;          /* count of ranges for variant arm */
360} AUXU, *pAUXU;
361#define cbAUXU sizeof(AUXU)
362#define auxNil ((pAUXU)0)
363#define iauxNil -1
364
365
366/*
367 * Optimization symbols
368 *
369 * Optimization symbols contain some overlap information with the normal
370 * symbol table. In particular, the proc information
371 * is somewhat redundant but necessary to easily find the other information
372 * present.
373 *
374 * All of the offsets are relative to the beginning of the last otProc
375 */
376
377typedef struct {
378    unsigned ot: 8;             /* optimization type */
379    unsigned value: 24; /* address where we are moving it to */
380    RNDXR       rndx;           /* points to a symbol or opt entry */
381    coff_ulong  offset; /* relative offset this occured */
382} OPTR, *pOPTR;
383#define optNil  ((pOPTR) 0)
384#define cbOPTR sizeof(OPTR)
385#define ioptNil -1
386
387/*
388 * File Indirect
389 *
390 * When a symbol is referenced across files the following procedure is used:
391 *      1) use the file index to get the File indirect entry.
392 *      2) use the file indirect entry to get the File descriptor.
393 *      3) add the sym index to the base of that file's sym table
394 *
395 */
396
397typedef coff_long RFDT, *pRFDT;
398#define cbRFDT sizeof(RFDT)
399#define rfdNil  -1
400
401/*
402 * The file indirect table in the mips loader is known as an array of FITs.
403 * This is done to keep the code in the loader readable in the area where
404 * these tables are merged.  Note this is only a name change.
405 */
406typedef coff_int FIT, *pFIT;
407#define cbFIT   sizeof(FIT)
408#define ifiNil  -1
409#define fiNil   ((pFIT) 0)
410
411#ifdef _LANGUAGE_PASCAL
412#define ifdNil -1
413#define ilnNil -1
414#define ipdNil -1
415#define ilineNil -1
416#define isymNil -1
417#define indexNil 16#fffff
418#define issNil -1
419#define issNull 0
420#define itqMax 6
421#define iauxNil -1
422#define ioptNil -1
423#define rfdNil -1
424#define ifiNil -1
425#endif  /* _LANGUAGE_PASCAL */
426
427
428/* Dense numbers
429 *
430 * Rather than use file index, symbol index pairs to represent symbols
431 *      and globals, we use dense number so that they can be easily embeded
432 *      in intermediate code and the programs that process them can
433 *      use direct access tabls instead of hash table (which would be
434 *      necesary otherwise because of the sparse name space caused by
435 *      file index, symbol index pairs. Dense number are represented
436 *      by RNDXRs.
437 */
438
439/*
440 * The following table defines the meaning of each SYM field as
441 * a function of the "st". (scD/B == scData OR scBss)
442 *
443 * Note: the value "isymMac" is used by symbols that have the concept
444 * of enclosing a block of related information.  This value is the
445 * isym of the first symbol AFTER the end associated with the primary
446 * symbol. For example if a procedure was at isym==90 and had an
447 * isymMac==155, the associated end would be at isym==154, and the
448 * symbol at 155 would probably (although not necessarily) be the
449 * symbol for the next procedure.  This allows rapid skipping over
450 * internal information of various sorts. "stEnd"s ALWAYS have the
451 * isym of the primary symbol that started the block.
452 *
453
454ST              SC      VALUE           INDEX
455--------        ------  --------        ------
456stFile          scText  address         isymMac
457stLabel         scText  address         ---
458stGlobal        scD/B   address         iaux
459stStatic        scD/B   address         iaux
460stParam         scAbs   offset          iaux
461stLocal         scAbs   offset          iaux
462stProc          scText  address         iaux    (isymMac is first AUX)
463stStaticProc    scText  address         iaux    (isymMac is first AUX)
464
465stMember        scNil   ordinal         ---     (if member of enum)
466        (mipsread thinks the case below has a bit, not byte, offset.)
467stMember        scNil   byte offset     iaux    (if member of struct/union)
468stMember        scBits  bit offset      iaux    (bit field spec)
469
470stBlock         scText  address         isymMac (text block)
471        (the code seems to think that rather than scNil, we see scInfo for
472         the two cases below.)
473stBlock         scNil   cb              isymMac (struct/union member define)
474stBlock         scNil   cMembers        isymMac (enum member define)
475
476        (New types added by SGI to simplify things:)
477stStruct        scInfo  cb              isymMac (struct type define)
478stUnion         scInfo  cb              isymMac (union  type define)
479stEnum          scInfo  cMembers        isymMac (enum   type define)
480
481stEnd           scText  address         isymStart
482stEnd           scNil   -------         isymStart (struct/union/enum)
483
484stTypedef       scNil   -------         iaux
485stRegReloc      sc???   value           old register number
486stForward       sc???   new address     isym to original symbol
487
488stConstant      scInfo  value           --- (scalar)
489stConstant      scInfo  iss             --- (complex, e.g. string)
490
491 *
492 */
493#endif
494