xref: /linux/include/uapi/linux/a.out.h (revision cdc7daa9e3e102fc650321c8c0d2d8cf0ced3910)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _UAPI__A_OUT_GNU_H__
3607ca46eSDavid Howells #define _UAPI__A_OUT_GNU_H__
4607ca46eSDavid Howells 
5607ca46eSDavid Howells #define __GNU_EXEC_MACROS__
6607ca46eSDavid Howells 
7607ca46eSDavid Howells #ifndef __STRUCT_EXEC_OVERRIDE__
8607ca46eSDavid Howells 
9607ca46eSDavid Howells #include <asm/a.out.h>
10607ca46eSDavid Howells 
11607ca46eSDavid Howells #endif /* __STRUCT_EXEC_OVERRIDE__ */
12607ca46eSDavid Howells 
13607ca46eSDavid Howells #ifndef __ASSEMBLY__
14607ca46eSDavid Howells 
15607ca46eSDavid Howells /* these go in the N_MACHTYPE field */
16607ca46eSDavid Howells enum machine_type {
17607ca46eSDavid Howells #if defined (M_OLDSUN2)
18607ca46eSDavid Howells   M__OLDSUN2 = M_OLDSUN2,
19607ca46eSDavid Howells #else
20607ca46eSDavid Howells   M_OLDSUN2 = 0,
21607ca46eSDavid Howells #endif
22607ca46eSDavid Howells #if defined (M_68010)
23607ca46eSDavid Howells   M__68010 = M_68010,
24607ca46eSDavid Howells #else
25607ca46eSDavid Howells   M_68010 = 1,
26607ca46eSDavid Howells #endif
27607ca46eSDavid Howells #if defined (M_68020)
28607ca46eSDavid Howells   M__68020 = M_68020,
29607ca46eSDavid Howells #else
30607ca46eSDavid Howells   M_68020 = 2,
31607ca46eSDavid Howells #endif
32607ca46eSDavid Howells #if defined (M_SPARC)
33607ca46eSDavid Howells   M__SPARC = M_SPARC,
34607ca46eSDavid Howells #else
35607ca46eSDavid Howells   M_SPARC = 3,
36607ca46eSDavid Howells #endif
37607ca46eSDavid Howells   /* skip a bunch so we don't run into any of sun's numbers */
38607ca46eSDavid Howells   M_386 = 100,
39607ca46eSDavid Howells   M_MIPS1 = 151,	/* MIPS R3000/R3000 binary */
40607ca46eSDavid Howells   M_MIPS2 = 152		/* MIPS R6000/R4000 binary */
41607ca46eSDavid Howells };
42607ca46eSDavid Howells 
43607ca46eSDavid Howells #if !defined (N_MAGIC)
44607ca46eSDavid Howells #define N_MAGIC(exec) ((exec).a_info & 0xffff)
45607ca46eSDavid Howells #endif
46607ca46eSDavid Howells #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
47607ca46eSDavid Howells #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
48607ca46eSDavid Howells #define N_SET_INFO(exec, magic, type, flags) \
49607ca46eSDavid Howells 	((exec).a_info = ((magic) & 0xffff) \
50607ca46eSDavid Howells 	 | (((int)(type) & 0xff) << 16) \
51607ca46eSDavid Howells 	 | (((flags) & 0xff) << 24))
52607ca46eSDavid Howells #define N_SET_MAGIC(exec, magic) \
53607ca46eSDavid Howells 	((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
54607ca46eSDavid Howells 
55607ca46eSDavid Howells #define N_SET_MACHTYPE(exec, machtype) \
56607ca46eSDavid Howells 	((exec).a_info = \
57607ca46eSDavid Howells 	 ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
58607ca46eSDavid Howells 
59607ca46eSDavid Howells #define N_SET_FLAGS(exec, flags) \
60607ca46eSDavid Howells 	((exec).a_info = \
61607ca46eSDavid Howells 	 ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
62607ca46eSDavid Howells 
63607ca46eSDavid Howells /* Code indicating object file or impure executable.  */
64607ca46eSDavid Howells #define OMAGIC 0407
65607ca46eSDavid Howells /* Code indicating pure executable.  */
66607ca46eSDavid Howells #define NMAGIC 0410
67607ca46eSDavid Howells /* Code indicating demand-paged executable.  */
68607ca46eSDavid Howells #define ZMAGIC 0413
69607ca46eSDavid Howells /* This indicates a demand-paged executable with the header in the text.
70607ca46eSDavid Howells    The first page is unmapped to help trap NULL pointer references */
71607ca46eSDavid Howells #define QMAGIC 0314
72607ca46eSDavid Howells 
73*cdc7daa9Sнаб /* Code indicating core file.  */
74*cdc7daa9Sнаб #define CMAGIC 0421
75*cdc7daa9Sнаб 
76607ca46eSDavid Howells #if !defined (N_BADMAG)
77607ca46eSDavid Howells #define N_BADMAG(x)	  (N_MAGIC(x) != OMAGIC		\
78607ca46eSDavid Howells 			&& N_MAGIC(x) != NMAGIC		\
79607ca46eSDavid Howells   			&& N_MAGIC(x) != ZMAGIC \
80607ca46eSDavid Howells 		        && N_MAGIC(x) != QMAGIC)
81607ca46eSDavid Howells #endif
82607ca46eSDavid Howells 
83607ca46eSDavid Howells #define _N_HDROFF(x) (1024 - sizeof (struct exec))
84607ca46eSDavid Howells 
85607ca46eSDavid Howells #if !defined (N_TXTOFF)
86607ca46eSDavid Howells #define N_TXTOFF(x) \
87607ca46eSDavid Howells  (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \
88607ca46eSDavid Howells   (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
89607ca46eSDavid Howells #endif
90607ca46eSDavid Howells 
91607ca46eSDavid Howells #if !defined (N_DATOFF)
92607ca46eSDavid Howells #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
93607ca46eSDavid Howells #endif
94607ca46eSDavid Howells 
95607ca46eSDavid Howells #if !defined (N_TRELOFF)
96607ca46eSDavid Howells #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
97607ca46eSDavid Howells #endif
98607ca46eSDavid Howells 
99607ca46eSDavid Howells #if !defined (N_DRELOFF)
100607ca46eSDavid Howells #define N_DRELOFF(x) (N_TRELOFF(x) + N_TRSIZE(x))
101607ca46eSDavid Howells #endif
102607ca46eSDavid Howells 
103607ca46eSDavid Howells #if !defined (N_SYMOFF)
104607ca46eSDavid Howells #define N_SYMOFF(x) (N_DRELOFF(x) + N_DRSIZE(x))
105607ca46eSDavid Howells #endif
106607ca46eSDavid Howells 
107607ca46eSDavid Howells #if !defined (N_STROFF)
108607ca46eSDavid Howells #define N_STROFF(x) (N_SYMOFF(x) + N_SYMSIZE(x))
109607ca46eSDavid Howells #endif
110607ca46eSDavid Howells 
111607ca46eSDavid Howells /* Address of text segment in memory after it is loaded.  */
112607ca46eSDavid Howells #if !defined (N_TXTADDR)
113607ca46eSDavid Howells #define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? PAGE_SIZE : 0)
114607ca46eSDavid Howells #endif
115607ca46eSDavid Howells 
116fbd57629SZack Weinberg /* Address of data segment in memory after it is loaded. */
117607ca46eSDavid Howells #ifndef __KERNEL__
118607ca46eSDavid Howells #include <unistd.h>
119607ca46eSDavid Howells #endif
120607ca46eSDavid Howells #if defined(__i386__) || defined(__mc68000__)
121607ca46eSDavid Howells #define SEGMENT_SIZE	1024
122607ca46eSDavid Howells #else
123607ca46eSDavid Howells #ifndef SEGMENT_SIZE
124607ca46eSDavid Howells #ifndef __KERNEL__
125607ca46eSDavid Howells #define SEGMENT_SIZE   getpagesize()
126607ca46eSDavid Howells #endif
127607ca46eSDavid Howells #endif
128607ca46eSDavid Howells #endif
129607ca46eSDavid Howells 
130607ca46eSDavid Howells #define _N_SEGMENT_ROUND(x) ALIGN(x, SEGMENT_SIZE)
131607ca46eSDavid Howells 
132607ca46eSDavid Howells #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
133607ca46eSDavid Howells 
134607ca46eSDavid Howells #ifndef N_DATADDR
135607ca46eSDavid Howells #define N_DATADDR(x) \
136607ca46eSDavid Howells     (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
137607ca46eSDavid Howells      : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
138607ca46eSDavid Howells #endif
139607ca46eSDavid Howells 
140607ca46eSDavid Howells /* Address of bss segment in memory after it is loaded.  */
141607ca46eSDavid Howells #if !defined (N_BSSADDR)
142607ca46eSDavid Howells #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
143607ca46eSDavid Howells #endif
144607ca46eSDavid Howells 
145607ca46eSDavid Howells #if !defined (N_NLIST_DECLARED)
146607ca46eSDavid Howells struct nlist {
147607ca46eSDavid Howells   union {
148607ca46eSDavid Howells     char *n_name;
149607ca46eSDavid Howells     struct nlist *n_next;
150607ca46eSDavid Howells     long n_strx;
151607ca46eSDavid Howells   } n_un;
152607ca46eSDavid Howells   unsigned char n_type;
153607ca46eSDavid Howells   char n_other;
154607ca46eSDavid Howells   short n_desc;
155607ca46eSDavid Howells   unsigned long n_value;
156607ca46eSDavid Howells };
157607ca46eSDavid Howells #endif /* no N_NLIST_DECLARED.  */
158607ca46eSDavid Howells 
159607ca46eSDavid Howells #if !defined (N_UNDF)
160607ca46eSDavid Howells #define N_UNDF 0
161607ca46eSDavid Howells #endif
162607ca46eSDavid Howells #if !defined (N_ABS)
163607ca46eSDavid Howells #define N_ABS 2
164607ca46eSDavid Howells #endif
165607ca46eSDavid Howells #if !defined (N_TEXT)
166607ca46eSDavid Howells #define N_TEXT 4
167607ca46eSDavid Howells #endif
168607ca46eSDavid Howells #if !defined (N_DATA)
169607ca46eSDavid Howells #define N_DATA 6
170607ca46eSDavid Howells #endif
171607ca46eSDavid Howells #if !defined (N_BSS)
172607ca46eSDavid Howells #define N_BSS 8
173607ca46eSDavid Howells #endif
174607ca46eSDavid Howells #if !defined (N_FN)
175607ca46eSDavid Howells #define N_FN 15
176607ca46eSDavid Howells #endif
177607ca46eSDavid Howells 
178607ca46eSDavid Howells #if !defined (N_EXT)
179607ca46eSDavid Howells #define N_EXT 1
180607ca46eSDavid Howells #endif
181607ca46eSDavid Howells #if !defined (N_TYPE)
182607ca46eSDavid Howells #define N_TYPE 036
183607ca46eSDavid Howells #endif
184607ca46eSDavid Howells #if !defined (N_STAB)
185607ca46eSDavid Howells #define N_STAB 0340
186607ca46eSDavid Howells #endif
187607ca46eSDavid Howells 
188607ca46eSDavid Howells /* The following type indicates the definition of a symbol as being
189607ca46eSDavid Howells    an indirect reference to another symbol.  The other symbol
190607ca46eSDavid Howells    appears as an undefined reference, immediately following this symbol.
191607ca46eSDavid Howells 
192607ca46eSDavid Howells    Indirection is asymmetrical.  The other symbol's value will be used
193607ca46eSDavid Howells    to satisfy requests for the indirect symbol, but not vice versa.
194607ca46eSDavid Howells    If the other symbol does not have a definition, libraries will
195607ca46eSDavid Howells    be searched to find a definition.  */
196607ca46eSDavid Howells #define N_INDR 0xa
197607ca46eSDavid Howells 
198607ca46eSDavid Howells /* The following symbols refer to set elements.
199607ca46eSDavid Howells    All the N_SET[ATDB] symbols with the same name form one set.
200607ca46eSDavid Howells    Space is allocated for the set in the text section, and each set
201607ca46eSDavid Howells    element's value is stored into one word of the space.
202607ca46eSDavid Howells    The first word of the space is the length of the set (number of elements).
203607ca46eSDavid Howells 
204607ca46eSDavid Howells    The address of the set is made into an N_SETV symbol
205607ca46eSDavid Howells    whose name is the same as the name of the set.
206607ca46eSDavid Howells    This symbol acts like a N_DATA global symbol
207607ca46eSDavid Howells    in that it can satisfy undefined external references.  */
208607ca46eSDavid Howells 
209607ca46eSDavid Howells /* These appear as input to LD, in a .o file.  */
210607ca46eSDavid Howells #define	N_SETA	0x14		/* Absolute set element symbol */
211607ca46eSDavid Howells #define	N_SETT	0x16		/* Text set element symbol */
212607ca46eSDavid Howells #define	N_SETD	0x18		/* Data set element symbol */
213607ca46eSDavid Howells #define	N_SETB	0x1A		/* Bss set element symbol */
214607ca46eSDavid Howells 
215607ca46eSDavid Howells /* This is output from LD.  */
216607ca46eSDavid Howells #define N_SETV	0x1C		/* Pointer to set vector in data area.  */
217607ca46eSDavid Howells 
218607ca46eSDavid Howells #if !defined (N_RELOCATION_INFO_DECLARED)
219607ca46eSDavid Howells /* This structure describes a single relocation to be performed.
220607ca46eSDavid Howells    The text-relocation section of the file is a vector of these structures,
221607ca46eSDavid Howells    all of which apply to the text section.
222607ca46eSDavid Howells    Likewise, the data-relocation section applies to the data section.  */
223607ca46eSDavid Howells 
224607ca46eSDavid Howells struct relocation_info
225607ca46eSDavid Howells {
226607ca46eSDavid Howells   /* Address (within segment) to be relocated.  */
227607ca46eSDavid Howells   int r_address;
228607ca46eSDavid Howells   /* The meaning of r_symbolnum depends on r_extern.  */
229607ca46eSDavid Howells   unsigned int r_symbolnum:24;
230607ca46eSDavid Howells   /* Nonzero means value is a pc-relative offset
231607ca46eSDavid Howells      and it should be relocated for changes in its own address
232607ca46eSDavid Howells      as well as for changes in the symbol or section specified.  */
233607ca46eSDavid Howells   unsigned int r_pcrel:1;
234607ca46eSDavid Howells   /* Length (as exponent of 2) of the field to be relocated.
235607ca46eSDavid Howells      Thus, a value of 2 indicates 1<<2 bytes.  */
236607ca46eSDavid Howells   unsigned int r_length:2;
237607ca46eSDavid Howells   /* 1 => relocate with value of symbol.
238607ca46eSDavid Howells           r_symbolnum is the index of the symbol
239607ca46eSDavid Howells 	  in file's the symbol table.
240607ca46eSDavid Howells      0 => relocate with the address of a segment.
241607ca46eSDavid Howells           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
242607ca46eSDavid Howells 	  (the N_EXT bit may be set also, but signifies nothing).  */
243607ca46eSDavid Howells   unsigned int r_extern:1;
244607ca46eSDavid Howells   /* Four bits that aren't used, but when writing an object file
245607ca46eSDavid Howells      it is desirable to clear them.  */
246607ca46eSDavid Howells   unsigned int r_pad:4;
247607ca46eSDavid Howells };
248607ca46eSDavid Howells #endif /* no N_RELOCATION_INFO_DECLARED.  */
249607ca46eSDavid Howells 
250607ca46eSDavid Howells #endif /*__ASSEMBLY__ */
251607ca46eSDavid Howells #endif /* _UAPI__A_OUT_GNU_H__ */
252