Initial revision
[external/binutils.git] / include / internalcoff.h
1 /********************** FILE HEADER **********************/
2 struct internal_filehdr 
3 {
4   unsigned short        f_magic; /* magic number                        */
5   unsigned short        f_nscns; /* number of sections          */
6   long          f_timdat;       /* time & date stamp            */
7   long          f_symptr;       /* file pointer to symtab       */
8   long          f_nsyms;        /* number of symtab entries     */
9   unsigned short        f_opthdr; /* sizeof(optional hdr)               */
10   unsigned short        f_flags; /* flags                       */
11 };
12
13 /* Bits for f_flags:
14  *      F_RELFLG        relocation info stripped from file
15  *      F_EXEC          file is executable (no unresolved external references)
16  *      F_LNNO          line numbers stripped from file
17  *      F_LSYMS         local symbols stripped from file
18  *      F_AR32WR        file has byte ordering of an AR32WR machine (e.g. vax)
19  */
20
21 #define F_RELFLG        (0x0001)
22 #define F_EXEC          (0x0002)
23 #define F_LNNO          (0x0004)
24 #define F_LSYMS         (0x0008)
25 #define F_AR32WR        (0x0010)
26 #define F_AR32W     0x200
27 /********************** AOUT "OPTIONAL HEADER" **********************/
28 struct internal_aouthdr {
29         short           magic;  /* type of file                         */
30         short           vstamp; /* version stamp                        */
31         unsigned long   tsize;  /* text size in bytes, padded to FW bdry*/
32         unsigned long   dsize;  /* initialized data "  "                */
33         unsigned long   bsize;  /* uninitialized data "   "             */
34         unsigned long   entry;  /* entry pt.                            */
35         unsigned long   text_start;     /* base of text used for this file */
36         unsigned long   data_start;     /* base of data used for this file */
37         unsigned long   tagentries;     /* number of tag entries to follow */
38 } ;
39
40 /********************** STORAGE CLASSES **********************/
41
42 #define C_EFCN          -1      /* physical end of function     */
43 #define C_NULL          0
44 #define C_AUTO          1       /* automatic variable           */
45 #define C_EXT           2       /* external symbol              */
46 #define C_STAT          3       /* static                       */
47 #define C_REG           4       /* register variable            */
48 #define C_EXTDEF        5       /* external definition          */
49 #define C_LABEL         6       /* label                        */
50 #define C_ULABEL        7       /* undefined label              */
51 #define C_MOS           8       /* member of structure          */
52 #define C_ARG           9       /* function argument            */
53 #define C_STRTAG        10      /* structure tag                */
54 #define C_MOU           11      /* member of union              */
55 #define C_UNTAG         12      /* union tag                    */
56 #define C_TPDEF         13      /* type definition              */
57 #define C_USTATIC       14      /* undefined static             */
58 #define C_ENTAG         15      /* enumeration tag              */
59 #define C_MOE           16      /* member of enumeration        */
60 #define C_REGPARM       17      /* register parameter           */
61 #define C_FIELD         18      /* bit field                    */
62 #define C_AUTOARG       19      /* auto argument                */
63 #define C_LASTENT       20      /* dummy entry (end of block)   */
64 #define C_BLOCK         100     /* ".bb" or ".eb"               */
65 #define C_FCN           101     /* ".bf" or ".ef"               */
66 #define C_EOS           102     /* end of structure             */
67 #define C_FILE          103     /* file name                    */
68 #define C_LINE          104     /* line # reformatted as symbol table entry */
69 #define C_ALIAS         105     /* duplicate tag                */
70 #define C_HIDDEN        106     /* ext symbol in dmert public lib */
71
72         /* New storage classes for 80960 */
73  
74 /* C_LEAFPROC is obsolete.  Use C_LEAFEXT or C_LEAFSTAT */
75 #define C_LEAFPROC      108     /* Leaf procedure, "call" via BAL */
76
77 #define C_SCALL         107     /* Procedure reachable via system call */
78 #define C_LEAFEXT       108     /* External leaf */
79 #define C_LEAFSTAT      113     /* Static leaf */
80 #define C_OPTVAR        109     /* Optimized variable           */
81 #define C_DEFINE        110     /* Preprocessor #define         */
82 #define C_PRAGMA        111     /* Advice to compiler or linker */
83 #define C_SEGMENT       112     /* 80960 segment name           */
84
85 /********************** SECTION HEADER **********************/
86 struct internal_scnhdr {
87         char            s_name[8];      /* section name                 */
88         long            s_paddr;        /* physical address, aliased s_nlib */
89         long            s_vaddr;        /* virtual address              */
90         long            s_size;         /* section size                 */
91         long            s_scnptr;       /* file ptr to raw data for section */
92         long            s_relptr;       /* file ptr to relocation       */
93         long            s_lnnoptr;      /* file ptr to line numbers     */
94         unsigned short  s_nreloc;       /* number of relocation entries */
95         unsigned short  s_nlnno;        /* number of line number entries*/
96         long            s_flags;        /* flags                        */
97 #ifdef I960
98         long            s_align;        
99 #endif
100 };
101
102
103 /*
104  * names of "special" sections
105  */
106 #define _TEXT   ".text"
107 #define _DATA   ".data"
108 #define _BSS    ".bss"
109
110 /*
111  * s_flags "type"
112  */
113 #define STYP_REG         (0x0000) /* "regular": allocated, relocated, loaded */
114 #define STYP_DSECT       (0x0001) /* "dummy":  relocated only*/
115 #define STYP_NOLOAD      (0x0002) /* "noload": allocated, relocated, not loaded */
116 #define STYP_GROUP       (0x0004) /* "grouped": formed of input sections */
117 #define STYP_PAD         (0x0008) /* "padding": not allocated, not relocated, loaded */
118 #define STYP_COPY        (0x0010) /* "copy": for decision function used by field update;  not allocated, not relocated,
119                                      loaded; reloc & lineno entries processed normally */
120 #define STYP_TEXT        (0x0020) /* section contains text only */
121 #define S_SHRSEG         (0x0020) /* In 3b Update files (output of ogen), sections which appear in SHARED segments of the Pfile
122                                      will have the S_SHRSEG flag set by ogen, to inform dufr that updating 1 copy of the proc. will
123                                      update all process invocations. */
124 #define STYP_DATA        (0x0040) /* section contains data only */
125 #define STYP_BSS         (0x0080) /* section contains bss only */
126 #define S_NEWFCN         (0x0100) /* In a minimal file or an update file, a new function (as compared with a replaced function) */
127 #define STYP_INFO        (0x0200) /* comment: not allocated not relocated, not loaded */
128 #define STYP_OVER        (0x0400) /* overlay: relocated not allocated or loaded */
129 #define STYP_LIB         (0x0800) /* for .lib: same as INFO */
130 #define STYP_MERGE       (0x2000) /* merge section -- combines with text, data or bss sections only */
131 #define STYP_REVERSE_PAD (0x4000) /* section will be padded with no-op instructions wherever padding is necessary and there is a
132                                      word of contiguous bytes beginning on a word boundary. */
133 /********************** LINE NUMBERS **********************/
134
135 /* 1 line number entry for every "breakpointable" source line in a section.
136  * Line numbers are grouped on a per function basis; first entry in a function
137  * grouping will have l_lnno = 0 and in place of physical address will be the
138  * symbol table index of the function name.
139  */
140
141 struct internal_lineno {
142         union {
143                 long l_symndx;  /* function name symbol index, iff l_lnno == 0*/
144                 long l_paddr;   /* (physical) address of line number    */
145         } l_addr;
146         unsigned short  l_lnno; /* line number          */
147 };
148
149 /********************** SYMBOLS **********************/
150 struct internal_syment {
151         union {
152                 char    _n_name[SYMNMLEN];      /* old COFF version     */
153                 struct {
154                         long    _n_zeroes;      /* new == 0             */
155                         long    _n_offset;      /* offset into string table */
156                 } _n_n;
157                 char    *_n_nptr[2];    /* allows for overlaying        */
158         } _n;
159         long            n_value;        /* value of symbol              */
160         short           n_scnum;        /* section number               */
161         unsigned short  n_flags;        /* copy of flags from filhdr    */
162         unsigned short  n_type;         /* type and derived type        */
163         char            n_sclass;       /* storage class                */
164         char            n_numaux;       /* number of aux. entries       */
165 };
166
167 /*
168  * Relocatable symbols have number of the section in which they are defined,
169  * or one of the following:
170  */
171 #define N_UNDEF ((short)0)  /* undefined symbol */
172 #define N_ABS   ((short)-1) /* value of symbol is absolute */
173 #define N_DEBUG ((short)-2) /* debugging symbol -- value is meaningless */
174 #define N_TV    ((short)-3) /* indicates symbol needs preload transfer vector */
175 #define P_TV    ((short)-4) /* indicates symbol needs postload transfer vector*/
176
177 /*
178  * Type of a symbol, in low N bits of the word
179  */
180 #define T_NULL          0
181 #define T_VOID          1       /* function argument (only used by compiler) */
182 #define T_CHAR          2       /* character            */
183 #define T_SHORT         3       /* short integer        */
184 #define T_INT           4       /* integer              */
185 #define T_LONG          5       /* long integer         */
186 #define T_FLOAT         6       /* floating point       */
187 #define T_DOUBLE        7       /* double word          */
188 #define T_STRUCT        8       /* structure            */
189 #define T_UNION         9       /* union                */
190 #define T_ENUM          10      /* enumeration          */
191 #define T_MOE           11      /* member of enumeration*/
192 #define T_UCHAR         12      /* unsigned character   */
193 #define T_USHORT        13      /* unsigned short       */
194 #define T_UINT          14      /* unsigned integer     */
195 #define T_ULONG         15      /* unsigned long        */
196 #define T_LNGDBL        16      /* long double          */
197
198 /*
199  * derived types, in n_type
200 */
201 #define DT_NON          (0)     /* no derived type */
202 #define DT_PTR          (1)     /* pointer */
203 #define DT_FCN          (2)     /* function */
204 #define DT_ARY          (3)     /* array */
205
206 #define BTYPE(x)        ((x) & N_BTMASK)
207
208 #define ISPTR(x)        (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
209 #define ISFCN(x)        (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
210 #define ISARY(x)        (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
211 #define ISTAG(x)        ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
212 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
213
214
215 union internal_auxent 
216 {
217   struct {
218     union {
219       long l;                   /* str, un, or enum tag indx */
220       struct coff_ptr_struct *p;
221     } x_tagndx;
222
223     union {
224       struct {
225         unsigned short x_lnno;  /* declaration line number */
226         unsigned short x_size;  /* str/union/array size */
227       } x_lnsz;
228       long x_fsize;             /* size of function */
229     } x_misc;
230     union {
231
232       struct {                  /* if ISFCN, tag, or .bb */
233         long x_lnnoptr;         /* ptr to fcn line # */
234         union {                 /* entry ndx past block end */
235           long  l;
236           struct coff_ptr_struct *p;
237
238         } x_endndx;
239
240
241       } x_fcn;
242       struct {                  /* if ISARY, up to 4 dimen. */
243         unsigned short x_dimen[DIMNUM];
244       } x_ary;
245     } x_fcnary;
246     unsigned short x_tvndx;     /* tv index */
247   } x_sym;
248
249   union {
250     char x_fname[FILNMLEN];
251     struct {
252       long x_zeroes;
253       long x_offset;
254     } x_n;
255   } x_file;
256
257   struct {
258     long x_scnlen;              /* section length */
259     unsigned short x_nreloc;    /* # relocation entries */
260     unsigned short x_nlinno;    /* # line numbers */
261   } x_scn;
262
263   struct {
264     long                x_tvfill; /* tv fill value */
265     unsigned short      x_tvlen; /* length of .tv */
266     unsigned short      x_tvran[2]; /* tv range */
267   } x_tv;                       /* info about .tv section (in auxent of symbol .tv)) */
268
269   /******************************************
270    *  I960-specific *2nd* aux. entry formats
271    ******************************************/
272   struct {
273     /* This is a very old typo that keeps getting propagated. */
274 #define x_stdindx x_stindx
275     long x_stindx;              /* sys. table entry */
276   } x_sc;                       /* system call entry */
277
278   struct {
279     unsigned long x_balntry;    /* BAL entry point */
280   } x_bal;                      /* BAL-callable function */
281
282   struct {
283     unsigned long       x_timestamp; /* time stamp */
284     char        x_idstring[20]; /* producer identity string */
285   } x_ident;                    /* Producer ident info */
286
287
288 };
289
290 /********************** RELOCATION DIRECTIVES **********************/
291
292 struct internal_reloc {
293         long r_vaddr;           /* Virtual address of reference */
294         long r_symndx;          /* Index into symbol table      */
295         unsigned short r_type;  /* Relocation type              */
296 #if M88
297         unsigned short r_offset;
298 #endif
299 };
300
301 #define R_RELBYTE       017
302 #define R_RELWORD       020
303 #define R_PCRBYTE       022
304 #define R_PCRWORD       023
305 #define R_PCRLONG       024
306
307 #define R_DIR32         06
308 #define R_PCLONG        020
309 #define R_RELBYTE       017
310 #define R_RELWORD       020
311
312 #define R_PCRBYTE       022
313 #define R_PCRWORD       023
314 #define R_PCRLONG       024
315
316 #define R_PCR16L 128
317 #define R_PCR26L 129
318 #define R_VRT16  130
319 #define R_HVRT16 131
320 #define R_LVRT16 132
321 #define R_VRT32  133
322 #define R_RELLONG       (0x11)  /* Direct 32-bit relocation */
323 #define R_IPRSHORT      (0x18)
324 #define R_IPRMED        (0x19)  /* 24-bit ip-relative relocation */
325 #define R_IPRLONG       (0x1a)
326 #define R_OPTCALL       (0x1b)  /* 32-bit optimizable call (leafproc/sysproc) */
327 #define R_OPTCALLX      (0x1c)  /* 64-bit optimizable call (leafproc/sysproc) */
328 #define R_GETSEG        (0x1d)
329 #define R_GETPA         (0x1e)
330 #define R_TAGWORD       (0x1f)