Commit | Line | Data |
---|---|---|
a3bb31a0 SC |
1 | #ifndef __A_OUT_64_H__ |
2 | #define __A_OUT_64_H__ | |
3 | ||
4 | ||
5 | /* This is the layout on disk of the 64 bit exec header. */ | |
6 | ||
7 | struct external_exec | |
8 | { | |
9 | bfd_byte e_info[4]; /* magic number and stuff */ | |
10 | bfd_byte e_text[BYTES_IN_WORD]; /* length of text section in bytes */ | |
11 | bfd_byte e_data[BYTES_IN_WORD]; /* length of data section in bytes */ | |
12 | bfd_byte e_bss[BYTES_IN_WORD]; /* length of bss area in bytes */ | |
13 | bfd_byte e_syms[BYTES_IN_WORD]; /* length of symbol table in bytes */ | |
14 | bfd_byte e_entry[BYTES_IN_WORD]; /* start address */ | |
15 | bfd_byte e_trsize[BYTES_IN_WORD]; /* length of text relocation info */ | |
16 | bfd_byte e_drsize[BYTES_IN_WORD]; /* length of data relocation info */ | |
17 | }; | |
18 | ||
19 | ||
20 | #define EXEC_BYTES_SIZE (4 + BYTES_IN_WORD * 7) | |
21 | ||
22 | /* This is the layout in memory of a "struct exec" while we process it. */ | |
23 | struct internal_exec | |
24 | { | |
25 | long a_info; /* Magic number and flags packed */ | |
26 | bfd_vma a_text; /* length of text, in bytes */ | |
27 | bfd_vma a_data; /* length of data, in bytes */ | |
28 | bfd_vma a_bss; /* length of uninitialized data area for file */ | |
29 | bfd_vma a_syms; /* length of symbol table data in file */ | |
30 | bfd_vma a_entry; /* start address */ | |
31 | bfd_vma a_trsize; /* length of relocation info for text, in bytes */ | |
32 | bfd_vma a_drsize; /* length of relocation info for data, in bytes */ | |
33 | }; | |
34 | ||
35 | ||
36 | /* Magic number is written | |
37 | < MSB > | |
38 | 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 | |
39 | < FLAGS > < MACHINE TYPE > < MAGIC > | |
40 | */ | |
41 | enum machine_type { | |
42 | M_UNKNOWN = 0, | |
43 | M_68010 = 1, | |
44 | M_68020 = 2, | |
45 | M_SPARC = 3, | |
46 | /* skip a bunch so we dont run into any of suns numbers */ | |
47 | M_386 = 100, | |
48 | M_29K = 101, | |
49 | M_NEWONE = 200, | |
50 | M_NEWTWO = 201, | |
51 | ||
52 | }; | |
53 | ||
54 | #define N_DYNAMIC(exec) ((exec).a_info & 0x8000000) | |
55 | ||
56 | #define N_MAGIC(exec) ((exec).a_info & 0xffff) | |
57 | #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff)) | |
58 | #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff) | |
59 | #define N_SET_INFO(exec, magic, type, flags) \ | |
60 | ((exec).a_info = ((magic) & 0xffff) \ | |
61 | | (((int)(type) & 0xff) << 16) \ | |
62 | | (((flags) & 0xff) << 24)) | |
63 | ||
64 | #define N_SET_MAGIC(exec, magic) \ | |
65 | ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff))) | |
66 | ||
67 | #define N_SET_MACHTYPE(exec, machtype) \ | |
68 | ((exec).a_info = \ | |
69 | ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16)) | |
70 | ||
71 | #define N_SET_FLAGS(exec, flags) \ | |
72 | ((exec).a_info = \ | |
73 | ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24)) | |
74 | ||
d7f8f106 JG |
75 | /* By default, segment size is constant. But on some machines, it can |
76 | be a function of the a.out header (e.g. machine type). */ | |
77 | #ifndef N_SEGSIZE | |
78 | #define N_SEGSIZE(x) SEGMENT_SIZE | |
79 | #endif | |
80 | ||
81 | #define _N_HDROFF(x) (N_SEGSIZE(x) - EXEC_BYTES_SIZE) | |
a3bb31a0 SC |
82 | /* address in an a.out of the text section. When demand paged, it's |
83 | set up a bit to make nothing at 0, when an object file it's 0. | |
84 | There's a special hack case when the entry point is < TEXT_START_ADDR | |
85 | for executables, then the real start is 0 | |
86 | */ | |
87 | ||
88 | #define N_TXTADDR(x) \ | |
89 | (N_MAGIC(x)==OMAGIC? 0 \ | |
90 | : (N_MAGIC(x) == ZMAGIC && (x).a_entry < TEXT_START_ADDR)? 0 \ | |
91 | : TEXT_START_ADDR) | |
92 | ||
93 | /* offset in an a.out of the start of the text section. When demand | |
94 | paged, this is the start of the file | |
95 | */ | |
96 | ||
97 | #define N_TXTOFF(x) ( (N_MAGIC((x)) == ZMAGIC) ? 0 : EXEC_BYTES_SIZE) | |
98 | #if ARCH_SIZE==64 | |
99 | #define PAGE_SIZE 0x2000 | |
100 | #define OMAGIC 0x1001 /* Code indicating object file */ | |
101 | #define ZMAGIC 0x1002 /* Code indicating demand-paged executable. */ | |
102 | #define NMAGIC 0x1003 /* Code indicating pure executable. */ | |
103 | #else | |
104 | #ifndef PAGE_SIZE | |
105 | #define PAGE_SIZE 0x2000 | |
106 | #endif | |
107 | #define OMAGIC 0407 /* Code indicating object file or impure executable. */ | |
108 | #define NMAGIC 0410 /* Code indicating pure executable. */ | |
109 | #define ZMAGIC 0413 /* Code indicating demand-paged executable. */ | |
110 | #endif | |
111 | ||
112 | #define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \ | |
113 | && N_MAGIC(x) != NMAGIC \ | |
114 | && N_MAGIC(x) != ZMAGIC) | |
115 | ||
116 | ||
117 | ||
118 | #define N_DATADDR(x) \ | |
119 | (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+(x).a_text) \ | |
d7f8f106 | 120 | : (N_SEGSIZE(x) + ((N_TXTADDR(x)+(x).a_text-1) & ~(N_SEGSIZE(x)-1)))) |
a3bb31a0 SC |
121 | |
122 | #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data) | |
123 | ||
124 | ||
125 | #define N_DATOFF(x) ( N_TXTOFF(x) + (x).a_text ) | |
126 | #define N_TRELOFF(x) ( N_DATOFF(x) + (x).a_data ) | |
127 | #define N_DRELOFF(x) ( N_TRELOFF(x) + (x).a_trsize ) | |
128 | #define N_SYMOFF(x) ( N_DRELOFF(x) + (x).a_drsize ) | |
129 | #define N_STROFF(x) ( N_SYMOFF(x) + (x).a_syms ) | |
130 | ||
131 | ||
132 | /* Symbols */ | |
133 | struct external_nlist { | |
134 | bfd_byte e_strx[BYTES_IN_WORD]; /* index into string table of symbol name */ | |
135 | bfd_byte e_type[1]; /* type of symbol */ | |
136 | bfd_byte e_other[1]; /* misc info (usually empty) */ | |
137 | bfd_byte e_desc[2]; /* description field */ | |
138 | bfd_byte e_value[BYTES_IN_WORD];/* value of symbol */ | |
139 | }; | |
140 | ||
141 | #define EXTERNAL_LIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD) | |
142 | struct internal_nlist { | |
143 | char *strx; /* index into string table of symbol name */ | |
144 | uint8_type n_type; /* type of symbol */ | |
145 | uint8_type n_other; /* misc info (usually empty) */ | |
146 | uint16_type n_desc; /* description field */ | |
147 | bfd_vma n_value; /* value of symbol */ | |
148 | }; | |
149 | ||
150 | /* The n_type field is packed : | |
151 | ||
152 | 7 6 5 4 3 2 1 0 | |
153 | ^- if set the symbol is externaly visible | |
154 | 0 local | |
155 | 1 N_EXT external | |
156 | ^ ^ ^---- select which section the symbol belongs to | |
157 | 0 0 0 0 x N_UNDF, undefined | |
158 | 0 0 0 1 x N_ABS, no section, base at 0 | |
159 | 0 0 1 0 x N_TEXT, text section | |
160 | 0 0 1 1 x N_DATA, data section | |
161 | 0 1 0 0 x N_BSS, bss section | |
162 | ^---------- if set the symbol is a set element | |
163 | 1 0 1 0 x N_SETA absolute set element symbol | |
164 | 1 0 1 1 x N_SETT text set element symbol | |
165 | 1 1 0 0 x N_SETD data set element symbol | |
166 | 1 1 0 1 x N_SETB bss set element symbol | |
167 | 1 1 1 0 x N_SETV pointer to set vector in data area | |
168 | 1 1 1 1 0 N_TYPE mask for all of the above | |
169 | ||
170 | 1 1 1 0 0 0 0 0 N_STAB type is a stab | |
171 | */ | |
172 | ||
173 | #define N_UNDF 0 | |
174 | #define N_ABS 2 | |
175 | #define N_TEXT 4 | |
176 | #define N_DATA 6 | |
177 | #define N_BSS 8 | |
e557edcf | 178 | #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */ |
30c52cdf JG |
179 | #define N_FN 0x1f /* File name of .o file */ |
180 | /* Note: N_EXT can only usefully be OR-ed with N_UNDF, N_ABS, N_TEXT, | |
181 | N_DATA, or N_BSS. When the low-order bit of other types is set, | |
182 | (e.g. N_WARNING versus N_FN), they are two different types. */ | |
a3bb31a0 SC |
183 | #define N_EXT 1 |
184 | #define N_TYPE 0x1e | |
185 | #define N_STAB 0xe0 | |
186 | ||
9bbfd057 SC |
187 | #define N_INDR 0x0a |
188 | ||
a3bb31a0 SC |
189 | /* The following symbols refer to set elements. |
190 | All the N_SET[ATDB] symbols with the same name form one set. | |
191 | Space is allocated for the set in the text section, and each set | |
192 | elements value is stored into one word of the space. | |
193 | The first word of the space is the length of the set (number of elements). | |
194 | ||
195 | The address of the set is made into an N_SETV symbol | |
196 | whose name is the same as the name of the set. | |
197 | This symbol acts like a N_DATA global symbol | |
198 | in that it can satisfy undefined external references. */ | |
199 | ||
200 | /* These appear as input to LD, in a .o file. */ | |
201 | #define N_SETA 0x14 /* Absolute set element symbol */ | |
202 | #define N_SETT 0x16 /* Text set element symbol */ | |
203 | #define N_SETD 0x18 /* Data set element symbol */ | |
204 | #define N_SETB 0x1A /* Bss set element symbol */ | |
205 | ||
206 | /* This is output from LD. */ | |
207 | #define N_SETV 0x1C /* Pointer to set vector in data area. */ | |
208 | ||
e557edcf JG |
209 | /* Warning symbol. The text gives a warning message, the next symbol |
210 | in the table will be undefined. When the symbol is referenced, the | |
211 | message is printed. */ | |
212 | ||
213 | #define N_WARNING 0x1e | |
a3bb31a0 SC |
214 | |
215 | /* Relocations | |
216 | ||
217 | There are two types of relocation flavours for a.out systems, | |
218 | standard and extended. The standard form is used on systems where | |
219 | the instruction has room for all the bits of an offset to the operand, whilst the | |
220 | extended form is used when an address operand has to be split over n | |
221 | instructions. Eg, on the 68k, each move instruction can reference | |
222 | the target with a displacement of 16 or 32 bits. On the sparc, move | |
223 | instructions use an offset of 14 bits, so the offset is stored in | |
224 | the reloc field, and the data in the section is ignored. | |
225 | */ | |
226 | ||
227 | /* This structure describes a single relocation to be performed. | |
228 | The text-relocation section of the file is a vector of these structures, | |
229 | all of which apply to the text section. | |
230 | Likewise, the data-relocation section applies to the data section. */ | |
231 | ||
232 | struct reloc_std_external { | |
233 | bfd_byte r_address[BYTES_IN_WORD]; /* offset of of data to relocate */ | |
234 | bfd_byte r_index[3]; /* symbol table index of symbol */ | |
235 | bfd_byte r_type[1]; /* relocation type */ | |
236 | }; | |
237 | ||
238 | #define RELOC_STD_BITS_PCREL_BIG 0x80 | |
239 | #define RELOC_STD_BITS_PCREL_LITTLE 0x01 | |
240 | ||
241 | #define RELOC_STD_BITS_LENGTH_BIG 0x60 | |
242 | #define RELOC_STD_BITS_LENGTH_SH_BIG 5 /* To shift to units place */ | |
243 | #define RELOC_STD_BITS_LENGTH_LITTLE 0x06 | |
244 | #define RELOC_STD_BITS_LENGTH_SH_LITTLE 1 | |
245 | ||
246 | #define RELOC_STD_BITS_EXTERN_BIG 0x10 | |
247 | #define RELOC_STD_BITS_EXTERN_LITTLE 0x08 | |
248 | ||
249 | #define RELOC_STD_BITS_BASEREL_BIG 0x08 | |
250 | #define RELOC_STD_BITS_BASEREL_LITTLE 0x08 | |
251 | ||
252 | #define RELOC_STD_BITS_JMPTABLE_BIG 0x04 | |
253 | #define RELOC_STD_BITS_JMPTABLE_LITTLE 0x04 | |
254 | ||
255 | #define RELOC_STD_BITS_RELATIVE_BIG 0x02 | |
256 | #define RELOC_STD_BITS_RELATIVE_LITTLE 0x02 | |
257 | ||
258 | #define RELOC_STD_SIZE (BYTES_IN_WORD + 3 + 1) /* Bytes per relocation entry */ | |
259 | ||
260 | struct reloc_std_internal | |
261 | { | |
262 | bfd_vma r_address; /* Address (within segment) to be relocated. */ | |
263 | /* The meaning of r_symbolnum depends on r_extern. */ | |
264 | unsigned int r_symbolnum:24; | |
265 | /* Nonzero means value is a pc-relative offset | |
266 | and it should be relocated for changes in its own address | |
267 | as well as for changes in the symbol or section specified. */ | |
268 | unsigned int r_pcrel:1; | |
269 | /* Length (as exponent of 2) of the field to be relocated. | |
270 | Thus, a value of 2 indicates 1<<2 bytes. */ | |
271 | unsigned int r_length:2; | |
272 | /* 1 => relocate with value of symbol. | |
273 | r_symbolnum is the index of the symbol | |
274 | in files the symbol table. | |
275 | 0 => relocate with the address of a segment. | |
276 | r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS | |
277 | (the N_EXT bit may be set also, but signifies nothing). */ | |
278 | unsigned int r_extern:1; | |
279 | /* The next three bits are for SunOS shared libraries, and seem to | |
280 | be undocumented. */ | |
281 | unsigned int r_baserel:1; /* Linkage table relative */ | |
282 | unsigned int r_jmptable:1; /* pc-relative to jump table */ | |
283 | unsigned int r_relative:1; /* "relative relocation" */ | |
284 | /* unused */ | |
285 | unsigned int r_pad:1; /* Padding -- set to zero */ | |
286 | }; | |
287 | ||
288 | ||
289 | /* EXTENDED RELOCS */ | |
290 | ||
291 | struct reloc_ext_external { | |
292 | bfd_byte r_address[BYTES_IN_WORD]; /* offset of of data to relocate */ | |
293 | bfd_byte r_index[3]; /* symbol table index of symbol */ | |
294 | bfd_byte r_type[1]; /* relocation type */ | |
295 | bfd_byte r_addend[BYTES_IN_WORD]; /* datum addend */ | |
296 | }; | |
297 | ||
298 | #define RELOC_EXT_BITS_EXTERN_BIG 0x80 | |
299 | #define RELOC_EXT_BITS_EXTERN_LITTLE 0x01 | |
300 | ||
301 | #define RELOC_EXT_BITS_TYPE_BIG 0x1F | |
302 | #define RELOC_EXT_BITS_TYPE_SH_BIG 0 | |
303 | #define RELOC_EXT_BITS_TYPE_LITTLE 0xF8 | |
304 | #define RELOC_EXT_BITS_TYPE_SH_LITTLE 3 | |
305 | ||
306 | #define RELOC_EXT_SIZE (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD) /* Bytes per relocation entry */ | |
307 | ||
308 | enum reloc_type | |
309 | { | |
bdedf53f SC |
310 | |
311 | ||
312 | ||
313 | ||
314 | ||
a3bb31a0 SC |
315 | /* simple relocations */ |
316 | RELOC_8, /* data[0:7] = addend + sv */ | |
317 | RELOC_16, /* data[0:15] = addend + sv */ | |
318 | RELOC_32, /* data[0:31] = addend + sv */ | |
319 | /* pc-rel displacement */ | |
320 | RELOC_DISP8, /* data[0:7] = addend - pc + sv */ | |
321 | RELOC_DISP16, /* data[0:15] = addend - pc + sv */ | |
322 | RELOC_DISP32, /* data[0:31] = addend - pc + sv */ | |
323 | /* Special */ | |
324 | RELOC_WDISP30, /* data[0:29] = (addend + sv - pc)>>2 */ | |
325 | RELOC_WDISP22, /* data[0:21] = (addend + sv - pc)>>2 */ | |
326 | RELOC_HI22, /* data[0:21] = (addend + sv)>>10 */ | |
327 | RELOC_22, /* data[0:21] = (addend + sv) */ | |
328 | RELOC_13, /* data[0:12] = (addend + sv) */ | |
329 | RELOC_LO10, /* data[0:9] = (addend + sv) */ | |
330 | RELOC_SFA_BASE, | |
331 | RELOC_SFA_OFF13, | |
332 | /* P.I.C. (base-relative) */ | |
333 | RELOC_BASE10, /* Not sure - maybe we can do this the */ | |
334 | RELOC_BASE13, /* right way now */ | |
335 | RELOC_BASE22, | |
336 | /* for some sort of pc-rel P.I.C. (?) */ | |
337 | RELOC_PC10, | |
338 | RELOC_PC22, | |
339 | /* P.I.C. jump table */ | |
340 | RELOC_JMP_TBL, | |
341 | /* reputedly for shared libraries somehow */ | |
342 | RELOC_SEGOFF16, | |
343 | RELOC_GLOB_DAT, | |
344 | RELOC_JMP_SLOT, | |
345 | RELOC_RELATIVE, | |
fcc654cb SC |
346 | |
347 | RELOC_11, | |
348 | RELOC_WDISP2_14, | |
349 | RELOC_WDISP19, | |
350 | RELOC_HHI22, /* data[0:21] = (addend + sv) >> 42 */ | |
351 | RELOC_HLO10, /* data[0:9] = (addend + sv) >> 32 */ | |
352 | ||
a3bb31a0 SC |
353 | /* 29K relocation types */ |
354 | RELOC_JUMPTARG, | |
355 | RELOC_CONST, | |
356 | RELOC_CONSTH, | |
357 | ||
bdedf53f | 358 | /* All the new ones I can think of *//*v9*/ |
a3bb31a0 | 359 | |
bdedf53f SC |
360 | RELOC_64, /* data[0:63] = addend + sv *//*v9*/ |
361 | RELOC_DISP64, /* data[0:63] = addend - pc + sv *//*v9*/ | |
362 | RELOC_WDISP21, /* data[0:20] = (addend + sv - pc)>>2 *//*v9*/ | |
363 | RELOC_DISP21, /* data[0:20] = addend - pc + sv *//*v9*/ | |
364 | RELOC_DISP14, /* data[0:13] = addend - pc + sv *//*v9*/ | |
a3bb31a0 SC |
365 | /* Q . |
366 | What are the other ones, | |
367 | Since this is a clean slate, can we throw away the ones we dont | |
368 | understand ? Should we sort the values ? What about using a | |
369 | microcode format like the 68k ? | |
370 | */ | |
371 | NO_RELOC | |
372 | }; | |
373 | ||
374 | ||
375 | struct reloc_internal { | |
376 | bfd_vma r_address; /* offset of of data to relocate */ | |
377 | long r_index; /* symbol table index of symbol */ | |
378 | enum reloc_type r_type; /* relocation type */ | |
379 | bfd_vma r_addend; /* datum addend */ | |
380 | }; | |
381 | ||
382 | /* Q. | |
383 | Should the length of the string table be 4 bytes or 8 bytes ? | |
384 | ||
385 | Q. | |
386 | What about archive indexes ? | |
387 | ||
388 | */ | |
389 | ||
390 | #endif /* __A_OUT_GNU_H__ */ |