Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / usr.bin / as / config / aout.h
1 /* This file is aout.h
2
3    Copyright (C) 1987-1992 Free Software Foundation, Inc.
4
5    This file is part of GAS, the GNU Assembler.
6
7    GAS 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, or (at your option)
10    any later version.
11
12    GAS 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.
16
17    You should have received a copy of the GNU General Public License
18    along with GAS; see the file COPYING.  If not, write to
19    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 #ifndef __A_OUT_GNU_H__
22 #define __A_OUT_GNU_H__
23
24 enum reloc_type {
25
26 #ifdef TC_M88K
27         RELOC_LO16, /* lo16(sym) */
28         RELOC_HI16, /* hi16(sym) */
29         RELOC_PC16, /* bb0, bb1, bcnd */
30         RELOC_PC26, /* br, bsr */
31         RELOC_32, /* jump tables, etc */
32         RELOC_IW16, /* global access through linker regs 28 */
33         NO_RELOC,
34 #else /* not TC_M88K */
35 #ifdef TC_I860
36
37 /* NOTE: three bits max, see struct reloc_info_i860.r_type */
38         NO_RELOC = 0, BRADDR, LOW0, LOW1, LOW2, LOW3, LOW4, SPLIT0, SPLIT1, SPLIT2, RELOC_32,
39
40 #else /* not TC_I860 */
41
42         RELOC_8,        RELOC_16,        RELOC_32, /* simple relocations */
43         RELOC_DISP8,    RELOC_DISP16,    RELOC_DISP32, /* pc-rel displacement */
44         RELOC_WDISP30,  RELOC_WDISP22,
45         RELOC_HI22,     RELOC_22,
46         RELOC_13,       RELOC_LO10,
47         RELOC_SFA_BASE, RELOC_SFA_OFF13,
48         RELOC_BASE10,   RELOC_BASE13,    RELOC_BASE22, /* P.I.C. (base-relative) */
49         RELOC_PC10,     RELOC_PC22,     /* for some sort of pc-rel P.I.C. (?) */
50         RELOC_JMP_TBL,          /* P.I.C. jump table */
51         RELOC_SEGOFF16,         /* reputedly for shared libraries somehow */
52         RELOC_GLOB_DAT,  RELOC_JMP_SLOT, RELOC_RELATIVE,
53 #ifndef TC_SPARC
54         RELOC_11,
55         RELOC_WDISP2_14,
56         RELOC_WDISP19,
57         RELOC_HHI22,
58         RELOC_HLO10,
59
60         /* 29K relocation types */
61         RELOC_JUMPTARG, RELOC_CONST,     RELOC_CONSTH,
62
63         RELOC_WDISP14, RELOC_WDISP21,
64 #endif /* not TC_SPARC */
65         NO_RELOC,
66
67 #ifdef TC_I386
68         /* Used internally by gas */
69         RELOC_GOT,
70         RELOC_GOTOFF,
71 #endif
72
73 #endif /* not TC_I860 */
74 #endif /* not TC_M88K */
75 };
76
77
78 #ifdef TC_I860
79  /* NOTE: two bits max, see reloc_info_i860.r_type */
80 enum highlow_type {
81         NO_SPEC = 0, PAIR, HIGH, HIGHADJ,
82 };
83 #endif /* TC_I860 */
84
85
86 #define __GNU_EXEC_MACROS__
87
88 #ifndef __STRUCT_EXEC_OVERRIDE__
89
90 /* This is the layout on disk of a Unix V7, Berkeley, SunOS, Vax Ultrix
91    "struct exec".  Don't assume that on this machine, the "struct exec"
92    will lay out the same sizes or alignments.  */
93
94 struct exec_bytes {
95         unsigned char a_info[4];
96         unsigned char a_text[4];
97         unsigned char a_data[4];
98         unsigned char a_bss[4];
99         unsigned char a_syms[4];
100         unsigned char a_entry[4];
101         unsigned char a_trsize[4];
102         unsigned char a_drsize[4];
103 };
104
105 /* How big the "struct exec" is on disk */
106 #define EXEC_BYTES_SIZE (8 * 4)
107
108 /* This is the layout in memory of a "struct exec" while we process it.  */
109
110 struct exec
111 {
112         unsigned long a_info;           /* Use macros N_MAGIC, etc for access */
113         unsigned a_text;                /* length of text, in bytes */
114         unsigned a_data;                /* length of data, in bytes */
115         unsigned a_bss;         /* length of uninitialized data area for file, in bytes */
116         unsigned a_syms;                /* length of symbol table data in file, in bytes */
117         unsigned a_entry;               /* start address */
118         unsigned a_trsize;              /* length of relocation info for text, in bytes */
119         unsigned a_drsize;              /* length of relocation info for data, in bytes */
120 };
121
122 #endif /* __STRUCT_EXEC_OVERRIDE__ */
123
124 /* these go in the N_MACHTYPE field */
125 /* These symbols could be defined by code from Suns...punt 'em */
126 #undef M_UNKNOWN
127 #undef M_68010
128 #undef M_68020
129 #undef M_SPARC
130 enum machine_type {
131         M_UNKNOWN = 0,
132         M_68010 = 1,
133         M_68020 = 2,
134         M_SPARC = 3,
135         /* skip a bunch so we don't run into any of sun's numbers */
136         M_386 = 100,
137         M_29K = 101,
138         M_RS6000 = 102, /* IBM RS/6000 */
139         /* HP/BSD formats */
140         M_HP200 = 200,  /* hp200 (68010) BSD binary */
141         M_HP300 = 300,  /* hp300 (68020+68881) BSD binary */
142         M_HPUX23 = 0x020C,      /* hp200/300 HPUX binary */
143 };
144
145 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
146 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
147 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
148 #define N_SET_INFO(exec, magic, type, flags) \
149     ((exec).a_info = ((magic) & 0xffff) \
150      | (((int)(type) & 0xff) << 16) \
151      | (((flags) & 0xff) << 24))
152 #define N_SET_MAGIC(exec, magic) \
153     ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
154
155 #define N_SET_MACHTYPE(exec, machtype) \
156     ((exec).a_info = \
157      ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
158
159 #define N_SET_FLAGS(exec, flags) \
160     ((exec).a_info = \
161      ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
162
163 /* Code indicating object file or impure executable.  */
164 #define OMAGIC 0407
165 /* Code indicating pure executable.  */
166 #define NMAGIC 0410
167 /* Code indicating demand-paged executable.  */
168 #define ZMAGIC 0413
169
170 /* Virtual Address of text segment from the a.out file.  For OMAGIC,
171    (almost always "unlinked .o's" these days), should be zero.
172    For linked files, should reflect reality if we know it.  */
173
174 #ifndef N_TXTADDR
175 #define N_TXTADDR(x)    (N_MAGIC(x) == OMAGIC? 0 : TEXT_START_ADDR)
176 #endif
177
178 #ifndef N_BADMAG
179 #define N_BADMAG(x)       (N_MAGIC(x) != OMAGIC         \
180                            && N_MAGIC(x) != NMAGIC              \
181                            && N_MAGIC(x) != ZMAGIC)
182 #endif
183
184 /* By default, segment size is constant.  But on some machines, it can
185    be a function of the a.out header (e.g. machine type).  */
186 #ifndef N_SEGSIZE
187 #define N_SEGSIZE(x)    SEGMENT_SIZE
188 #endif
189
190     /* This complexity is for encapsulated COFF support */
191 #ifndef _N_HDROFF
192 #define _N_HDROFF(x)    (N_SEGSIZE(x) - sizeof (struct exec))
193 #endif
194
195 #ifndef N_TXTOFF
196 #define N_TXTOFF(x)     (N_MAGIC(x) == ZMAGIC ? \
197                          _N_HDROFF((x)) + sizeof (struct exec) :        \
198                          sizeof (struct exec))
199 #endif
200
201
202 #ifndef N_DATOFF
203 #define N_DATOFF(x)     ( N_TXTOFF(x) + (x).a_text )
204 #endif
205
206 #ifndef N_TRELOFF
207 #define N_TRELOFF(x)    ( N_DATOFF(x) + (x).a_data )
208 #endif
209
210 #ifndef N_DRELOFF
211 #define N_DRELOFF(x)    ( N_TRELOFF(x) + (x).a_trsize )
212 #endif
213
214 #ifndef N_SYMOFF
215 #define N_SYMOFF(x)     ( N_DRELOFF(x) + (x).a_drsize )
216 #endif
217
218 #ifndef N_STROFF
219 #define N_STROFF(x)     ( N_SYMOFF(x) + (x).a_syms )
220 #endif
221
222 /* Address of text segment in memory after it is loaded.  */
223 #ifndef N_TXTADDR
224 #define N_TXTADDR(x)    0
225 #endif
226
227 #ifndef N_DATADDR
228 #define N_DATADDR(x) \
229     (N_MAGIC(x) == OMAGIC? (N_TXTADDR(x)+(x).a_text) \
230      :  (N_SEGSIZE(x) + ((N_TXTADDR(x)+(x).a_text-1) & ~(N_SEGSIZE(x)-1))))
231 #endif
232
233 /* Address of bss segment in memory after it is loaded.  */
234 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
235 \f
236 struct nlist {
237         union {
238                 char *n_name;
239                 struct nlist *n_next;
240                 long n_strx;
241         } n_un;
242         unsigned char n_type;
243         char n_other;
244         short n_desc;
245         unsigned long n_value;
246 };
247
248 #define N_UNDF 0
249 #define N_ABS 2
250 #define N_TEXT 4
251 #define N_DATA 6
252 #define N_BSS 8
253 #define N_COMM  0x12            /* common (visible in shared lib commons) */
254 #define N_FN 0x1F               /* File name of a .o file */
255
256 /* Note: N_EXT can only usefully be OR-ed with N_UNDF, N_ABS, N_TEXT,
257    N_DATA, or N_BSS.  When the low-order bit of other types is set,
258    (e.g. N_WARNING versus N_FN), they are two different types.  */
259 #define N_EXT 1
260 #define N_TYPE 036
261 #define N_STAB 0340
262
263 /* The following type indicates the definition of a symbol as being
264    an indirect reference to another symbol.  The other symbol
265    appears as an undefined reference, immediately following this symbol.
266
267    Indirection is asymmetrical.  The other symbol's value will be used
268    to satisfy requests for the indirect symbol, but not vice versa.
269    If the other symbol does not have a definition, libraries will
270    be searched to find a definition.  */
271
272 #define N_INDR 0xa
273
274 /* The following type indicates the size of the symbol it refers to */
275 #define N_SIZE 0xc
276
277 /* The following symbols refer to set elements.
278    All the N_SET[ATDB] symbols with the same name form one set.
279    Space is allocated for the set in the text section, and each set
280    element's value is stored into one word of the space.
281    The first word of the space is the length of the set (number of elements).
282
283    The address of the set is made into an N_SETV symbol
284    whose name is the same as the name of the set.
285    This symbol acts like a N_DATA global symbol
286    in that it can satisfy undefined external references.  */
287
288 /* These appear as input to LD, in a .o file.  */
289 #define N_SETA  0x14            /* Absolute set element symbol */
290 #define N_SETT  0x16            /* Text set element symbol */
291 #define N_SETD  0x18            /* Data set element symbol */
292 #define N_SETB  0x1A            /* Bss set element symbol */
293
294 /* This is output from LD.  */
295 #define N_SETV  0x1C            /* Pointer to set vector in data area.  */
296
297 /* Warning symbol. The text gives a warning message, the next symbol
298    in the table will be undefined. When the symbol is referenced, the
299    message is printed.  */
300
301 #define N_WARNING 0x1e
302 \f
303 /* This structure describes a single relocation to be performed.
304    The text-relocation section of the file is a vector of these structures,
305    all of which apply to the text section.
306    Likewise, the data-relocation section applies to the data section.  */
307
308 /* The following enum and struct were borrowed from SunOS's
309    /usr/include/sun4/a.out.h  and extended to handle
310    other machines.  It is currently used on SPARC and AMD 29000.
311
312    reloc_ext_bytes is how it looks on disk.  reloc_info_extended is
313    how we might process it on a native host.  */
314
315 struct reloc_ext_bytes {
316         unsigned char   r_address[4];
317         unsigned char r_index[3];
318         unsigned char r_bits[1];
319         unsigned char r_addend[4];
320 };
321
322 struct reloc_info_i860
323 {
324         unsigned long r_address;
325         /*
326          * Using bit fields here is a bad idea because the order is not portable. :-(
327          */
328         unsigned int r_symbolnum: 24;
329         unsigned int r_pcrel    : 1;
330         unsigned int r_extern   : 1;
331         /* combining the two field simplifies the argument passing in "new_fix()" */
332         /* and is compatible with the existing Sparc #ifdef's */
333         /* r_type:  highlow_type - bits 5,4; reloc_type - bits 3-0 */
334         unsigned int r_type     : 6;
335         long r_addend;
336 };
337
338
339 #define RELOC_EXT_BITS_EXTERN_BIG       0x80
340 #define RELOC_EXT_BITS_EXTERN_LITTLE    0x01
341
342 #define RELOC_EXT_BITS_TYPE_BIG         0x1F
343 #define RELOC_EXT_BITS_TYPE_SH_BIG      0
344 #define RELOC_EXT_BITS_TYPE_LITTLE      0xF8
345 #define RELOC_EXT_BITS_TYPE_SH_LITTLE   3
346
347 #define RELOC_EXT_SIZE  12              /* Bytes per relocation entry */
348
349 struct reloc_info_extended
350 {
351         unsigned long r_address;
352         unsigned int  r_index:24;
353 # define        r_symbolnum  r_index
354         unsigned        r_extern:1;
355         unsigned        :2;
356         /*  RS/6000 compiler does not support enum bitfield
357             enum reloc_type r_type:5; */
358         enum reloc_type r_type;
359         long int        r_addend;
360 };
361
362 /* The standard, old-fashioned, Berkeley compatible relocation struct */
363
364 struct reloc_std_bytes {
365         unsigned char   r_address[4];
366         unsigned char r_index[3];
367         unsigned char r_bits[1];
368 };
369
370 #define RELOC_STD_BITS_PCREL_BIG        0x80
371 #define RELOC_STD_BITS_PCREL_LITTLE     0x01
372
373 #define RELOC_STD_BITS_LENGTH_BIG       0x60
374 #define RELOC_STD_BITS_LENGTH_SH_BIG    5       /* To shift to units place */
375 #define RELOC_STD_BITS_LENGTH_LITTLE    0x06
376 #define RELOC_STD_BITS_LENGTH_SH_LITTLE 1
377
378 #define RELOC_STD_BITS_EXTERN_BIG       0x10
379 #define RELOC_STD_BITS_EXTERN_LITTLE    0x08
380
381 #define RELOC_STD_BITS_BASEREL_BIG      0x08
382 #define RELOC_STD_BITS_BASEREL_LITTLE   0x08
383
384 #define RELOC_STD_BITS_JMPTABLE_BIG     0x04
385 #define RELOC_STD_BITS_JMPTABLE_LITTLE  0x04
386
387 #define RELOC_STD_BITS_RELATIVE_BIG     0x02
388 #define RELOC_STD_BITS_RELATIVE_LITTLE  0x02
389
390 #define RELOC_STD_SIZE  8               /* Bytes per relocation entry */
391
392 #ifndef CUSTOM_RELOC_FORMAT
393 struct relocation_info {
394         /* Address (within segment) to be relocated.  */
395         int r_address;
396         /* The meaning of r_symbolnum depends on r_extern.  */
397 #if defined(TC_NS32K) && !defined(TE_SEQUENT)
398         unsigned int r_symbolnum:22;
399         unsigned int r_copy:1;
400         unsigned int r_relative:1;
401 #else
402         unsigned int r_symbolnum:24;
403 #endif
404         /* Nonzero means value is a pc-relative offset
405            and it should be relocated for changes in its own address
406            as well as for changes in the symbol or section specified.  */
407         unsigned int r_pcrel:1;
408         /* Length (as exponent of 2) of the field to be relocated.
409            Thus, a value of 2 indicates 1<<2 bytes.  */
410         unsigned int r_length:2;
411         /* 1 => relocate with value of symbol.
412            r_symbolnum is the index of the symbol
413            in file's the symbol table.
414            0 => relocate with the address of a segment.
415            r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
416            (the N_EXT bit may be set also, but signifies nothing).  */
417         unsigned int r_extern:1;
418 #ifdef TC_NS32K
419 #ifdef TE_SEQUENT
420         unsigned int r_bsr:1;
421 #else
422         unsigned int r_jmptable:1;
423 #endif
424         unsigned int r_disp:2;
425         unsigned int r_baserel:1;
426 #else
427         /* The next three bits are for SunOS shared libraries, and seem to
428            be undocumented.  */
429         unsigned int r_baserel:1;       /* Linkage table relative */
430         unsigned int r_jmptable:1;      /* pc-relative to jump table */
431         unsigned int r_relative:1;      /* "relative relocation" */
432         /* unused */
433         unsigned int r_pad:1;           /* Padding -- set to zero */
434 #endif
435 };
436 #endif /* CUSTOM_RELOC_FORMAT */
437
438 #endif /* __A_OUT_GNU_H__ */
439
440 /* end of aout.h */