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