Commit | Line | Data |
---|---|---|
61a153e5 RP |
1 | #ifndef __A_OUT_GNU_H__ |
2 | #define __A_OUT_GNU_H__ | |
3 | ||
bad3df67 | 4 | #include "reloc.h" |
61a153e5 RP |
5 | |
6 | #define __GNU_EXEC_MACROS__ | |
7 | ||
8 | #ifndef __STRUCT_EXEC_OVERRIDE__ | |
9 | ||
bad3df67 JG |
10 | /* This is the layout on disk of a Unix V7, Berkeley, SunOS, Vax Ultrix |
11 | "struct exec". Don't assume that on this machine, the "struct exec" | |
12 | will lay out the same sizes or alignments. */ | |
13 | ||
14 | struct exec_bytes { | |
15 | unsigned char a_info[4]; | |
16 | unsigned char a_text[4]; | |
17 | unsigned char a_data[4]; | |
18 | unsigned char a_bss[4]; | |
19 | unsigned char a_syms[4]; | |
20 | unsigned char a_entry[4]; | |
21 | unsigned char a_trsize[4]; | |
22 | unsigned char a_drsize[4]; | |
23 | }; | |
24 | ||
25 | /* How big the "struct exec" is on disk */ | |
26 | #define EXEC_BYTES_SIZE (8 * 4) | |
27 | ||
28 | /* This is the layout in memory of a "struct exec" while we process it. */ | |
29 | ||
61a153e5 RP |
30 | struct exec |
31 | { | |
32 | unsigned long a_info; /* Use macros N_MAGIC, etc for access */ | |
33 | unsigned a_text; /* length of text, in bytes */ | |
34 | unsigned a_data; /* length of data, in bytes */ | |
35 | unsigned a_bss; /* length of uninitialized data area for file, in bytes */ | |
36 | unsigned a_syms; /* length of symbol table data in file, in bytes */ | |
37 | unsigned a_entry; /* start address */ | |
38 | unsigned a_trsize; /* length of relocation info for text, in bytes */ | |
39 | unsigned a_drsize; /* length of relocation info for data, in bytes */ | |
40 | }; | |
41 | ||
42 | #endif /* __STRUCT_EXEC_OVERRIDE__ */ | |
43 | ||
44 | /* these go in the N_MACHTYPE field */ | |
45 | /* These symbols could be defined by code from Suns...punt 'em */ | |
bad3df67 | 46 | #undef M_UNKNOWN |
61a153e5 RP |
47 | #undef M_68010 |
48 | #undef M_68020 | |
49 | #undef M_SPARC | |
50 | enum machine_type { | |
bad3df67 | 51 | M_UNKNOWN = 0, |
61a153e5 RP |
52 | M_68010 = 1, |
53 | M_68020 = 2, | |
54 | M_SPARC = 3, | |
55 | /* skip a bunch so we don't run into any of sun's numbers */ | |
56 | M_386 = 100, | |
57 | M_29K = 101, | |
58 | }; | |
59 | ||
60 | #define N_MAGIC(exec) ((exec).a_info & 0xffff) | |
61 | #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff)) | |
62 | #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff) | |
63 | #define N_SET_INFO(exec, magic, type, flags) \ | |
64 | ((exec).a_info = ((magic) & 0xffff) \ | |
65 | | (((int)(type) & 0xff) << 16) \ | |
66 | | (((flags) & 0xff) << 24)) | |
67 | #define N_SET_MAGIC(exec, magic) \ | |
68 | ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff))) | |
69 | ||
70 | #define N_SET_MACHTYPE(exec, machtype) \ | |
71 | ((exec).a_info = \ | |
72 | ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16)) | |
73 | ||
74 | #define N_SET_FLAGS(exec, flags) \ | |
75 | ((exec).a_info = \ | |
76 | ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24)) | |
77 | ||
78 | /* Code indicating object file or impure executable. */ | |
79 | #define OMAGIC 0407 | |
80 | /* Code indicating pure executable. */ | |
81 | #define NMAGIC 0410 | |
82 | /* Code indicating demand-paged executable. */ | |
83 | #define ZMAGIC 0413 | |
84 | ||
bad3df67 JG |
85 | /* Virtual Address of text segment from the a.out file. For OMAGIC, |
86 | (almost always "unlinked .o's" these days), should be zero. | |
bad3df67 JG |
87 | For linked files, should reflect reality if we know it. */ |
88 | ||
89 | #ifndef N_TXTADDR | |
66d4e1bb JG |
90 | #define N_TXTADDR(x) (N_MAGIC(x)==OMAGIC? 0 : TEXT_START_ADDR) |
91 | #endif | |
92 | ||
93 | #ifndef N_BADMAG | |
94 | #define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \ | |
95 | && N_MAGIC(x) != NMAGIC \ | |
96 | && N_MAGIC(x) != ZMAGIC) | |
97 | #endif | |
98 | ||
99 | /* This complexity is for encapsulated COFF support */ | |
100 | #ifndef _N_HDROFF | |
101 | #define _N_HDROFF(x) (SEGMENT_SIZE - sizeof (struct exec)) | |
102 | #endif | |
103 | ||
104 | #ifndef N_TXTOFF | |
105 | #define N_TXTOFF(x) (N_MAGIC(x) == ZMAGIC ? \ | |
106 | _N_HDROFF((x)) + sizeof (struct exec) : \ | |
107 | sizeof (struct exec)) | |
108 | #endif | |
109 | ||
110 | ||
111 | #ifndef N_DATOFF | |
112 | #define N_DATOFF(x) ( N_TXTOFF(x) + (x).a_text ) | |
113 | #endif | |
114 | ||
115 | #ifndef N_TRELOFF | |
116 | #define N_TRELOFF(x) ( N_DATOFF(x) + (x).a_data ) | |
117 | #endif | |
118 | ||
119 | #ifndef N_DRELOFF | |
120 | #define N_DRELOFF(x) ( N_TRELOFF(x) + (x).a_trsize ) | |
bad3df67 | 121 | #endif |
61a153e5 | 122 | |
66d4e1bb JG |
123 | #ifndef N_SYMOFF |
124 | #define N_SYMOFF(x) ( N_DRELOFF(x) + (x).a_drsize ) | |
61a153e5 | 125 | #endif |
66d4e1bb JG |
126 | |
127 | #ifndef N_STROFF | |
128 | #define N_STROFF(x) ( N_SYMOFF(x) + (x).a_syms ) | |
61a153e5 | 129 | #endif |
66d4e1bb JG |
130 | |
131 | /* Address of text segment in memory after it is loaded. */ | |
132 | #ifndef N_TXTADDR | |
133 | #define N_TXTADDR(x) 0 | |
61a153e5 | 134 | #endif |
61a153e5 RP |
135 | |
136 | #ifndef N_DATADDR | |
137 | #define N_DATADDR(x) \ | |
bad3df67 JG |
138 | (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+(x).a_text) \ |
139 | : (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1)))) | |
61a153e5 RP |
140 | #endif |
141 | ||
142 | /* Address of bss segment in memory after it is loaded. */ | |
143 | #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data) | |
144 | \f | |
145 | struct nlist { | |
146 | union { | |
147 | char *n_name; | |
148 | struct nlist *n_next; | |
149 | long n_strx; | |
150 | } n_un; | |
151 | unsigned char n_type; | |
152 | char n_other; | |
153 | short n_desc; | |
154 | unsigned long n_value; | |
155 | }; | |
156 | ||
157 | #define N_UNDF 0 | |
158 | #define N_ABS 2 | |
159 | #define N_TEXT 4 | |
160 | #define N_DATA 6 | |
161 | #define N_BSS 8 | |
162 | #define N_FN 15 | |
163 | ||
164 | #define N_EXT 1 | |
165 | #define N_TYPE 036 | |
166 | #define N_STAB 0340 | |
167 | ||
168 | /* The following type indicates the definition of a symbol as being | |
169 | an indirect reference to another symbol. The other symbol | |
170 | appears as an undefined reference, immediately following this symbol. | |
171 | ||
172 | Indirection is asymmetrical. The other symbol's value will be used | |
173 | to satisfy requests for the indirect symbol, but not vice versa. | |
174 | If the other symbol does not have a definition, libraries will | |
175 | be searched to find a definition. */ | |
176 | #define N_INDR 0xa | |
177 | ||
178 | /* The following symbols refer to set elements. | |
179 | All the N_SET[ATDB] symbols with the same name form one set. | |
180 | Space is allocated for the set in the text section, and each set | |
181 | element's value is stored into one word of the space. | |
182 | The first word of the space is the length of the set (number of elements). | |
183 | ||
184 | The address of the set is made into an N_SETV symbol | |
185 | whose name is the same as the name of the set. | |
186 | This symbol acts like a N_DATA global symbol | |
187 | in that it can satisfy undefined external references. */ | |
188 | ||
189 | /* These appear as input to LD, in a .o file. */ | |
190 | #define N_SETA 0x14 /* Absolute set element symbol */ | |
191 | #define N_SETT 0x16 /* Text set element symbol */ | |
192 | #define N_SETD 0x18 /* Data set element symbol */ | |
193 | #define N_SETB 0x1A /* Bss set element symbol */ | |
194 | ||
195 | /* This is output from LD. */ | |
196 | #define N_SETV 0x1C /* Pointer to set vector in data area. */ | |
197 | \f | |
198 | /* This structure describes a single relocation to be performed. | |
199 | The text-relocation section of the file is a vector of these structures, | |
200 | all of which apply to the text section. | |
201 | Likewise, the data-relocation section applies to the data section. */ | |
202 | ||
bad3df67 JG |
203 | /* The following enum and struct were borrowed from SunOS's |
204 | /usr/include/sun4/a.out.h and extended to handle | |
205 | other machines. It is currently used on SPARC and AMD 29000. | |
61a153e5 | 206 | |
bad3df67 JG |
207 | reloc_ext_bytes is how it looks on disk. reloc_info_extended is |
208 | how we might process it on a native host. */ | |
61a153e5 | 209 | |
bad3df67 JG |
210 | struct reloc_ext_bytes { |
211 | unsigned char r_address[4]; | |
212 | unsigned char r_index[3]; | |
213 | unsigned char r_bits[1]; | |
214 | unsigned char r_addend[4]; | |
61a153e5 RP |
215 | }; |
216 | ||
bad3df67 JG |
217 | #define RELOC_EXT_BITS_EXTERN_BIG 0x80 |
218 | #define RELOC_EXT_BITS_EXTERN_LITTLE 0x01 | |
219 | ||
220 | #define RELOC_EXT_BITS_TYPE_BIG 0x1F | |
221 | #define RELOC_EXT_BITS_TYPE_SH_BIG 0 | |
222 | #define RELOC_EXT_BITS_TYPE_LITTLE 0xF8 | |
223 | #define RELOC_EXT_BITS_TYPE_SH_LITTLE 3 | |
224 | ||
225 | #define RELOC_EXT_SIZE 12 /* Bytes per relocation entry */ | |
61a153e5 RP |
226 | |
227 | struct reloc_info_extended | |
228 | { | |
229 | unsigned long r_address; | |
230 | unsigned int r_index:24; | |
231 | # define r_symbolnum r_index | |
232 | unsigned r_extern:1; | |
233 | unsigned :2; | |
234 | enum reloc_type r_type:5; | |
235 | long int r_addend; | |
236 | }; | |
237 | ||
bad3df67 JG |
238 | /* The standard, old-fashioned, Berkeley compatible relocation struct */ |
239 | ||
240 | struct reloc_std_bytes { | |
241 | unsigned char r_address[4]; | |
242 | unsigned char r_index[3]; | |
243 | unsigned char r_bits[1]; | |
61a153e5 RP |
244 | }; |
245 | ||
bad3df67 JG |
246 | #define RELOC_STD_BITS_PCREL_BIG 0x80 |
247 | #define RELOC_STD_BITS_PCREL_LITTLE 0x01 | |
248 | ||
249 | #define RELOC_STD_BITS_LENGTH_BIG 0x60 | |
250 | #define RELOC_STD_BITS_LENGTH_SH_BIG 5 /* To shift to units place */ | |
251 | #define RELOC_STD_BITS_LENGTH_LITTLE 0x06 | |
252 | #define RELOC_STD_BITS_LENGTH_SH_LITTLE 1 | |
253 | ||
254 | #define RELOC_STD_BITS_EXTERN_BIG 0x10 | |
255 | #define RELOC_STD_BITS_EXTERN_LITTLE 0x08 | |
256 | ||
257 | #define RELOC_STD_BITS_BASEREL_BIG 0x08 | |
258 | #define RELOC_STD_BITS_BASEREL_LITTLE 0x08 | |
259 | ||
260 | #define RELOC_STD_BITS_JMPTABLE_BIG 0x04 | |
261 | #define RELOC_STD_BITS_JMPTABLE_LITTLE 0x04 | |
262 | ||
263 | #define RELOC_STD_BITS_RELATIVE_BIG 0x02 | |
264 | #define RELOC_STD_BITS_RELATIVE_LITTLE 0x02 | |
61a153e5 | 265 | |
bad3df67 | 266 | #define RELOC_STD_SIZE 8 /* Bytes per relocation entry */ |
61a153e5 RP |
267 | |
268 | struct relocation_info | |
269 | { | |
270 | /* Address (within segment) to be relocated. */ | |
271 | int r_address; | |
272 | /* The meaning of r_symbolnum depends on r_extern. */ | |
273 | unsigned int r_symbolnum:24; | |
274 | /* Nonzero means value is a pc-relative offset | |
275 | and it should be relocated for changes in its own address | |
276 | as well as for changes in the symbol or section specified. */ | |
277 | unsigned int r_pcrel:1; | |
278 | /* Length (as exponent of 2) of the field to be relocated. | |
279 | Thus, a value of 2 indicates 1<<2 bytes. */ | |
280 | unsigned int r_length:2; | |
281 | /* 1 => relocate with value of symbol. | |
282 | r_symbolnum is the index of the symbol | |
283 | in file's the symbol table. | |
284 | 0 => relocate with the address of a segment. | |
285 | r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS | |
286 | (the N_EXT bit may be set also, but signifies nothing). */ | |
287 | unsigned int r_extern:1; | |
bad3df67 JG |
288 | /* The next three bits are for SunOS shared libraries, and seem to |
289 | be undocumented. */ | |
290 | unsigned int r_baserel:1; /* Linkage table relative */ | |
291 | unsigned int r_jmptable:1; /* pc-relative to jump table */ | |
f827120d RP |
292 | |
293 | #ifdef TC_NS32K | |
294 | #define r_bsr r_baserel | |
295 | #define r_disp r_jmptable | |
296 | #endif /* TC_NS32K */ | |
297 | ||
bad3df67 JG |
298 | unsigned int r_relative:1; /* "relative relocation" */ |
299 | /* unused */ | |
300 | unsigned int r_pad:1; /* Padding -- set to zero */ | |
61a153e5 RP |
301 | }; |
302 | ||
61a153e5 | 303 | #endif /* __A_OUT_GNU_H__ */ |