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