1e6ef0ebd03d6e29e55961cde703fd2db83f83bc
[deliverable/binutils-gdb.git] / include / aout / aout64.h
1 /* `a.out' object-file definitions, including extensions to 64-bit fields */
2
3 #ifndef __A_OUT_64_H__
4 #define __A_OUT_64_H__
5
6 /* This is the layout on disk of the 32-bit or 64-bit exec header. */
7
8 #ifndef external_exec
9 struct external_exec
10 {
11 bfd_byte e_info[4]; /* magic number and stuff */
12 bfd_byte e_text[BYTES_IN_WORD]; /* length of text section in bytes */
13 bfd_byte e_data[BYTES_IN_WORD]; /* length of data section in bytes */
14 bfd_byte e_bss[BYTES_IN_WORD]; /* length of bss area in bytes */
15 bfd_byte e_syms[BYTES_IN_WORD]; /* length of symbol table in bytes */
16 bfd_byte e_entry[BYTES_IN_WORD]; /* start address */
17 bfd_byte e_trsize[BYTES_IN_WORD]; /* length of text relocation info */
18 bfd_byte e_drsize[BYTES_IN_WORD]; /* length of data relocation info */
19 };
20
21 #define EXEC_BYTES_SIZE (4 + BYTES_IN_WORD * 7)
22
23 /* Magic numbers for a.out files */
24
25 #if ARCH_SIZE==64
26 #define OMAGIC 0x1001 /* Code indicating object file */
27 #define ZMAGIC 0x1002 /* Code indicating demand-paged executable. */
28 #define NMAGIC 0x1003 /* Code indicating pure executable. */
29
30 /* There is no 64-bit QMAGIC as far as I know. */
31
32 #define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \
33 && N_MAGIC(x) != NMAGIC \
34 && N_MAGIC(x) != ZMAGIC)
35 #else
36 #define OMAGIC 0407 /* ...object file or impure executable. */
37 #define NMAGIC 0410 /* Code indicating pure executable. */
38 #define ZMAGIC 0413 /* Code indicating demand-paged executable. */
39
40 /* This indicates a demand-paged executable with the header in the text.
41 As far as I know it is only used by 386BSD and/or BSDI. */
42 #define QMAGIC 0314
43 #define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \
44 && N_MAGIC(x) != NMAGIC \
45 && N_MAGIC(x) != ZMAGIC \
46 && N_MAGIC(x) != QMAGIC)
47 #endif
48
49 #endif
50
51 #ifdef QMAGIC
52 #define N_IS_QMAGIC(x) (N_MAGIC (x) == QMAGIC)
53 #else
54 #define N_IS_QMAGIC(x) (0)
55 #endif
56
57 /* The difference between PAGE_SIZE and N_SEGSIZE is that PAGE_SIZE is
58 the the finest granularity at which you can page something, thus it
59 controls the padding (if any) before the text segment of a ZMAGIC
60 file. N_SEGSIZE is the resolution at which things can be marked as
61 read-only versus read/write, so it controls the padding between the
62 text segment and the data segment. These are the same for most
63 machines, but different for sun3. */
64
65 /* By default, segment size is constant. But some machines override this
66 to be a function of the a.out header (e.g. machine type). */
67
68 #ifndef N_SEGSIZE
69 #define N_SEGSIZE(x) SEGMENT_SIZE
70 #endif
71 \f
72 /* Virtual memory address of the text section.
73 This is getting very complicated. A good reason to discard a.out format
74 for something that specifies these fields explicitly. But til then...
75
76 * OMAGIC and NMAGIC files:
77 (object files: text for "relocatable addr 0" right after the header)
78 start at 0, offset is EXEC_BYTES_SIZE, size as stated.
79 * The text address, offset, and size of ZMAGIC files depend
80 on the entry point of the file:
81 * entry point below TEXT_START_ADDR:
82 (hack for SunOS shared libraries)
83 start at 0, offset is 0, size as stated.
84 * If N_HEADER_IN_TEXT(x) is true (which defaults to being the
85 case when the entry point is EXEC_BYTES_SIZE or further into a page):
86 no padding is needed; text can start after exec header. Sun
87 considers the text segment of such files to include the exec header;
88 for BFD's purposes, we don't, which makes more work for us.
89 start at TEXT_START_ADDR + EXEC_BYTES_SIZE, offset is EXEC_BYTES_SIZE,
90 size as stated minus EXEC_BYTES_SIZE.
91 * If N_HEADER_IN_TEXT(x) is false (which defaults to being the case when
92 the entry point is less than EXEC_BYTES_SIZE into a page (e.g. page
93 aligned)): (padding is needed so that text can start at a page boundary)
94 start at TEXT_START_ADDR, offset PAGE_SIZE, size as stated.
95
96 Specific configurations may want to hardwire N_HEADER_IN_TEXT,
97 for efficiency or to allow people to play games with the entry point.
98 In that case, you would #define N_HEADER_IN_TEXT(x) as 1 for sunos,
99 and as 0 for most other hosts (Sony News, Vax Ultrix, etc).
100 (Do this in the appropriate bfd target file.)
101 (The default is a heuristic that will break if people try changing
102 the entry point, perhaps with the ld -e flag.)
103
104 * QMAGIC is always like a ZMAGIC for which N_HEADER_IN_TEXT is true,
105 and for which the starting address is PAGE_SIZE (or should this be
106 SEGMENT_SIZE?) (TEXT_START_ADDR only applies to ZMAGIC, not to QMAGIC).
107 */
108
109 /* This macro is only relevant for ZMAGIC files; QMAGIC always has the header
110 in the text. */
111 #ifndef N_HEADER_IN_TEXT
112 #define N_HEADER_IN_TEXT(x) (((x).a_entry & (PAGE_SIZE-1)) >= EXEC_BYTES_SIZE)
113 #endif
114
115 /* Sun shared libraries, not linux. This macro is only relevant for ZMAGIC
116 files. */
117 #ifndef N_SHARED_LIB
118 #define N_SHARED_LIB(x) ((x).a_entry < TEXT_START_ADDR)
119 #endif
120
121 #ifndef N_TXTADDR
122 #define N_TXTADDR(x) \
123 (/* The address of a QMAGIC file is always one page in, */ \
124 /* with the header in the text. */ \
125 N_IS_QMAGIC (x) ? PAGE_SIZE + EXEC_BYTES_SIZE : \
126 N_MAGIC(x) != ZMAGIC ? 0 : /* object file or NMAGIC */\
127 N_SHARED_LIB(x) ? 0 : \
128 N_HEADER_IN_TEXT(x) ? \
129 TEXT_START_ADDR + EXEC_BYTES_SIZE : /* no padding */\
130 TEXT_START_ADDR /* a page of padding */\
131 )
132 #endif
133
134 /* Offset in an a.out of the start of the text section. */
135 #ifndef N_TXTOFF
136 #define N_TXTOFF(x) \
137 (/* For {O,N,Q}MAGIC, no padding. */ \
138 N_MAGIC(x) != ZMAGIC ? EXEC_BYTES_SIZE : \
139 N_SHARED_LIB(x) ? 0 : \
140 N_HEADER_IN_TEXT(x) ? \
141 EXEC_BYTES_SIZE : /* no padding */\
142 PAGE_SIZE /* a page of padding */\
143 )
144 #endif
145 /* Size of the text section. It's always as stated, except that we
146 offset it to `undo' the adjustment to N_TXTADDR and N_TXTOFF
147 for ZMAGIC files that nominally include the exec header
148 as part of the first page of text. (BFD doesn't consider the
149 exec header to be part of the text segment.) */
150 #ifndef N_TXTSIZE
151 #define N_TXTSIZE(x) \
152 (/* For QMAGIC, we don't consider the header part of the text section. */\
153 N_IS_QMAGIC (x) ? (x).a_text - EXEC_BYTES_SIZE : \
154 (N_MAGIC(x) != ZMAGIC || N_SHARED_LIB(x)) ? (x).a_text : \
155 N_HEADER_IN_TEXT(x) ? \
156 (x).a_text - EXEC_BYTES_SIZE: /* no padding */\
157 (x).a_text /* a page of padding */\
158 )
159 #endif
160 /* The address of the data segment in virtual memory.
161 It is the text segment address, plus text segment size, rounded
162 up to a N_SEGSIZE boundary for pure or pageable files. */
163 #ifndef N_DATADDR
164 #define N_DATADDR(x) \
165 (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+N_TXTSIZE(x)) \
166 : (N_SEGSIZE(x) + ((N_TXTADDR(x)+N_TXTSIZE(x)-1) & ~(N_SEGSIZE(x)-1))))
167 #endif
168 /* The address of the BSS segment -- immediately after the data segment. */
169
170 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
171
172 /* Offsets of the various portions of the file after the text segment. */
173
174 /* For {N,Q,Z}MAGIC, there is padding to make the data segment start
175 on a page boundary. Most of the time the a_text field (and thus
176 N_TXTSIZE) already contains this padding. But if it doesn't (I
177 think maybe this happens on BSDI and/or 386BSD), then add it. */
178
179 #ifndef N_DATOFF
180 #define N_DATOFF(x) \
181 (N_MAGIC(x) == OMAGIC ? N_TXTOFF(x) + N_TXTSIZE(x) : \
182 N_SEGSIZE(x) + ((N_TXTOFF(x) + N_TXTSIZE(x) - 1) & ~(N_SEGSIZE(x) - 1)))
183 #endif
184
185 #ifndef N_TRELOFF
186 #define N_TRELOFF(x) ( N_DATOFF(x) + (x).a_data )
187 #endif
188 #ifndef N_DRELOFF
189 #define N_DRELOFF(x) ( N_TRELOFF(x) + (x).a_trsize )
190 #endif
191 #ifndef N_SYMOFF
192 #define N_SYMOFF(x) ( N_DRELOFF(x) + (x).a_drsize )
193 #endif
194 #ifndef N_STROFF
195 #define N_STROFF(x) ( N_SYMOFF(x) + (x).a_syms )
196 #endif
197 \f
198 /* Symbols */
199 #ifndef external_nlist
200 struct external_nlist {
201 bfd_byte e_strx[BYTES_IN_WORD]; /* index into string table of name */
202 bfd_byte e_type[1]; /* type of symbol */
203 bfd_byte e_other[1]; /* misc info (usually empty) */
204 bfd_byte e_desc[2]; /* description field */
205 bfd_byte e_value[BYTES_IN_WORD]; /* value of symbol */
206 };
207 #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD)
208 #endif
209
210 struct internal_nlist {
211 unsigned long n_strx; /* index into string table of name */
212 unsigned char n_type; /* type of symbol */
213 unsigned char n_other; /* misc info (usually empty) */
214 unsigned short n_desc; /* description field */
215 bfd_vma n_value; /* value of symbol */
216 };
217
218 /* The n_type field is the symbol type, containing: */
219
220 #define N_UNDF 0 /* Undefined symbol */
221 #define N_ABS 2 /* Absolute symbol -- defined at particular addr */
222 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
223 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
224 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
225 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
226 #define N_FN 0x1f /* File name of .o file */
227 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
228 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
229 N_DATA, or N_BSS. When the low-order bit of other types is set,
230 (e.g. N_WARNING versus N_FN), they are two different types. */
231 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
232 #define N_TYPE 0x1e
233 #define N_STAB 0xe0 /* If any of these bits are on, it's a debug symbol */
234
235 #define N_INDR 0x0a
236
237 /* The following symbols refer to set elements.
238 All the N_SET[ATDB] symbols with the same name form one set.
239 Space is allocated for the set in the text section, and each set
240 elements value is stored into one word of the space.
241 The first word of the space is the length of the set (number of elements).
242
243 The address of the set is made into an N_SETV symbol
244 whose name is the same as the name of the set.
245 This symbol acts like a N_DATA global symbol
246 in that it can satisfy undefined external references. */
247
248 /* These appear as input to LD, in a .o file. */
249 #define N_SETA 0x14 /* Absolute set element symbol */
250 #define N_SETT 0x16 /* Text set element symbol */
251 #define N_SETD 0x18 /* Data set element symbol */
252 #define N_SETB 0x1A /* Bss set element symbol */
253
254 /* This is output from LD. */
255 #define N_SETV 0x1C /* Pointer to set vector in data area. */
256
257 /* Warning symbol. The text gives a warning message, the next symbol
258 in the table will be undefined. When the symbol is referenced, the
259 message is printed. */
260
261 #define N_WARNING 0x1e
262
263 /* Relocations
264
265 There are two types of relocation flavours for a.out systems,
266 standard and extended. The standard form is used on systems where the
267 instruction has room for all the bits of an offset to the operand, whilst
268 the extended form is used when an address operand has to be split over n
269 instructions. Eg, on the 68k, each move instruction can reference
270 the target with a displacement of 16 or 32 bits. On the sparc, move
271 instructions use an offset of 14 bits, so the offset is stored in
272 the reloc field, and the data in the section is ignored.
273 */
274
275 /* This structure describes a single relocation to be performed.
276 The text-relocation section of the file is a vector of these structures,
277 all of which apply to the text section.
278 Likewise, the data-relocation section applies to the data section. */
279
280 struct reloc_std_external {
281 bfd_byte r_address[BYTES_IN_WORD]; /* offset of of data to relocate */
282 bfd_byte r_index[3]; /* symbol table index of symbol */
283 bfd_byte r_type[1]; /* relocation type */
284 };
285
286 #define RELOC_STD_BITS_PCREL_BIG 0x80
287 #define RELOC_STD_BITS_PCREL_LITTLE 0x01
288
289 #define RELOC_STD_BITS_LENGTH_BIG 0x60
290 #define RELOC_STD_BITS_LENGTH_SH_BIG 5 /* To shift to units place */
291 #define RELOC_STD_BITS_LENGTH_LITTLE 0x06
292 #define RELOC_STD_BITS_LENGTH_SH_LITTLE 1
293
294 #define RELOC_STD_BITS_EXTERN_BIG 0x10
295 #define RELOC_STD_BITS_EXTERN_LITTLE 0x08
296
297 #define RELOC_STD_BITS_BASEREL_BIG 0x08
298 #define RELOC_STD_BITS_BASEREL_LITTLE 0x08
299
300 #define RELOC_STD_BITS_JMPTABLE_BIG 0x04
301 #define RELOC_STD_BITS_JMPTABLE_LITTLE 0x04
302
303 #define RELOC_STD_BITS_RELATIVE_BIG 0x02
304 #define RELOC_STD_BITS_RELATIVE_LITTLE 0x02
305
306 #define RELOC_STD_SIZE (BYTES_IN_WORD + 3 + 1) /* Bytes per relocation entry */
307
308 struct reloc_std_internal
309 {
310 bfd_vma r_address; /* Address (within segment) to be relocated. */
311 /* The meaning of r_symbolnum depends on r_extern. */
312 unsigned int r_symbolnum:24;
313 /* Nonzero means value is a pc-relative offset
314 and it should be relocated for changes in its own address
315 as well as for changes in the symbol or section specified. */
316 unsigned int r_pcrel:1;
317 /* Length (as exponent of 2) of the field to be relocated.
318 Thus, a value of 2 indicates 1<<2 bytes. */
319 unsigned int r_length:2;
320 /* 1 => relocate with value of symbol.
321 r_symbolnum is the index of the symbol
322 in files the symbol table.
323 0 => relocate with the address of a segment.
324 r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
325 (the N_EXT bit may be set also, but signifies nothing). */
326 unsigned int r_extern:1;
327 /* The next three bits are for SunOS shared libraries, and seem to
328 be undocumented. */
329 unsigned int r_baserel:1; /* Linkage table relative */
330 unsigned int r_jmptable:1; /* pc-relative to jump table */
331 unsigned int r_relative:1; /* "relative relocation" */
332 /* unused */
333 unsigned int r_pad:1; /* Padding -- set to zero */
334 };
335
336
337 /* EXTENDED RELOCS */
338
339 struct reloc_ext_external {
340 bfd_byte r_address[BYTES_IN_WORD]; /* offset of of data to relocate */
341 bfd_byte r_index[3]; /* symbol table index of symbol */
342 bfd_byte r_type[1]; /* relocation type */
343 bfd_byte r_addend[BYTES_IN_WORD]; /* datum addend */
344 };
345
346 #define RELOC_EXT_BITS_EXTERN_BIG 0x80
347 #define RELOC_EXT_BITS_EXTERN_LITTLE 0x01
348
349 #define RELOC_EXT_BITS_TYPE_BIG 0x1F
350 #define RELOC_EXT_BITS_TYPE_SH_BIG 0
351 #define RELOC_EXT_BITS_TYPE_LITTLE 0xF8
352 #define RELOC_EXT_BITS_TYPE_SH_LITTLE 3
353
354 /* Bytes per relocation entry */
355 #define RELOC_EXT_SIZE (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD)
356
357 enum reloc_type
358 {
359 /* simple relocations */
360 RELOC_8, /* data[0:7] = addend + sv */
361 RELOC_16, /* data[0:15] = addend + sv */
362 RELOC_32, /* data[0:31] = addend + sv */
363 /* pc-rel displacement */
364 RELOC_DISP8, /* data[0:7] = addend - pc + sv */
365 RELOC_DISP16, /* data[0:15] = addend - pc + sv */
366 RELOC_DISP32, /* data[0:31] = addend - pc + sv */
367 /* Special */
368 RELOC_WDISP30, /* data[0:29] = (addend + sv - pc)>>2 */
369 RELOC_WDISP22, /* data[0:21] = (addend + sv - pc)>>2 */
370 RELOC_HI22, /* data[0:21] = (addend + sv)>>10 */
371 RELOC_22, /* data[0:21] = (addend + sv) */
372 RELOC_13, /* data[0:12] = (addend + sv) */
373 RELOC_LO10, /* data[0:9] = (addend + sv) */
374 RELOC_SFA_BASE,
375 RELOC_SFA_OFF13,
376 /* P.I.C. (base-relative) */
377 RELOC_BASE10, /* Not sure - maybe we can do this the */
378 RELOC_BASE13, /* right way now */
379 RELOC_BASE22,
380 /* for some sort of pc-rel P.I.C. (?) */
381 RELOC_PC10,
382 RELOC_PC22,
383 /* P.I.C. jump table */
384 RELOC_JMP_TBL,
385 /* reputedly for shared libraries somehow */
386 RELOC_SEGOFF16,
387 RELOC_GLOB_DAT,
388 RELOC_JMP_SLOT,
389 RELOC_RELATIVE,
390
391 RELOC_11,
392 RELOC_WDISP2_14,
393 RELOC_WDISP19,
394 RELOC_HHI22, /* data[0:21] = (addend + sv) >> 42 */
395 RELOC_HLO10, /* data[0:9] = (addend + sv) >> 32 */
396
397 /* 29K relocation types */
398 RELOC_JUMPTARG,
399 RELOC_CONST,
400 RELOC_CONSTH,
401
402 /* All the new ones I can think of *//*v9*/
403
404 RELOC_64, /* data[0:63] = addend + sv *//*v9*/
405 RELOC_DISP64, /* data[0:63] = addend - pc + sv *//*v9*/
406 RELOC_WDISP21, /* data[0:20] = (addend + sv - pc)>>2 *//*v9*/
407 RELOC_DISP21, /* data[0:20] = addend - pc + sv *//*v9*/
408 RELOC_DISP14, /* data[0:13] = addend - pc + sv *//*v9*/
409 /* Q .
410 What are the other ones,
411 Since this is a clean slate, can we throw away the ones we dont
412 understand ? Should we sort the values ? What about using a
413 microcode format like the 68k ?
414 */
415 NO_RELOC
416 };
417
418
419 struct reloc_internal {
420 bfd_vma r_address; /* offset of of data to relocate */
421 long r_index; /* symbol table index of symbol */
422 enum reloc_type r_type; /* relocation type */
423 bfd_vma r_addend; /* datum addend */
424 };
425
426 /* Q.
427 Should the length of the string table be 4 bytes or 8 bytes ?
428
429 Q.
430 What about archive indexes ?
431
432 */
433
434 #endif /* __A_OUT_64_H__ */
This page took 0.036902 seconds and 4 git commands to generate.