N_INDR movement
[external/binutils.git] / include / aout64.h
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 #define N_INDR 0x0a
178
179 /* The following symbols refer to set elements.
180    All the N_SET[ATDB] symbols with the same name form one set.
181    Space is allocated for the set in the text section, and each set
182    elements value is stored into one word of the space.
183    The first word of the space is the length of the set (number of elements).
184
185    The address of the set is made into an N_SETV symbol
186    whose name is the same as the name of the set.
187    This symbol acts like a N_DATA global symbol
188    in that it can satisfy undefined external references.  */
189
190 /* These appear as input to LD, in a .o file.  */
191 #define N_SETA  0x14            /* Absolute set element symbol */
192 #define N_SETT  0x16            /* Text set element symbol */
193 #define N_SETD  0x18            /* Data set element symbol */
194 #define N_SETB  0x1A            /* Bss set element symbol */
195
196 /* This is output from LD.  */
197 #define N_SETV  0x1C            /* Pointer to set vector in data area.  */
198
199
200 /* Relocations 
201
202   There are two types of relocation flavours for a.out systems,
203   standard and extended. The standard form is used on systems where
204   the instruction has room for all the bits of an offset to the operand, whilst the
205   extended form is used when an address operand has to be split over n
206   instructions. Eg, on the 68k, each move instruction can reference
207   the target with a displacement of 16 or 32 bits. On the sparc, move
208   instructions use an offset of 14 bits, so the offset is stored in
209   the reloc field, and the data in the section is ignored.
210 */
211
212 /* This structure describes a single relocation to be performed.
213    The text-relocation section of the file is a vector of these structures,
214    all of which apply to the text section.
215    Likewise, the data-relocation section applies to the data section.  */
216
217 struct reloc_std_external {
218   bfd_byte      r_address[BYTES_IN_WORD];       /* offset of of data to relocate        */
219   bfd_byte r_index[3];  /* symbol table index of symbol         */
220   bfd_byte r_type[1];   /* relocation type                      */
221 };
222
223 #define RELOC_STD_BITS_PCREL_BIG        0x80
224 #define RELOC_STD_BITS_PCREL_LITTLE     0x01
225
226 #define RELOC_STD_BITS_LENGTH_BIG       0x60
227 #define RELOC_STD_BITS_LENGTH_SH_BIG    5       /* To shift to units place */
228 #define RELOC_STD_BITS_LENGTH_LITTLE    0x06
229 #define RELOC_STD_BITS_LENGTH_SH_LITTLE 1
230
231 #define RELOC_STD_BITS_EXTERN_BIG       0x10
232 #define RELOC_STD_BITS_EXTERN_LITTLE    0x08
233
234 #define RELOC_STD_BITS_BASEREL_BIG      0x08
235 #define RELOC_STD_BITS_BASEREL_LITTLE   0x08
236
237 #define RELOC_STD_BITS_JMPTABLE_BIG     0x04
238 #define RELOC_STD_BITS_JMPTABLE_LITTLE  0x04
239
240 #define RELOC_STD_BITS_RELATIVE_BIG     0x02
241 #define RELOC_STD_BITS_RELATIVE_LITTLE  0x02
242
243 #define RELOC_STD_SIZE  (BYTES_IN_WORD + 3 + 1)         /* Bytes per relocation entry */
244
245 struct reloc_std_internal
246 {
247   bfd_vma r_address;            /* Address (within segment) to be relocated.  */
248   /* The meaning of r_symbolnum depends on r_extern.  */
249   unsigned int r_symbolnum:24;
250   /* Nonzero means value is a pc-relative offset
251      and it should be relocated for changes in its own address
252      as well as for changes in the symbol or section specified.  */
253   unsigned int r_pcrel:1;
254   /* Length (as exponent of 2) of the field to be relocated.
255      Thus, a value of 2 indicates 1<<2 bytes.  */
256   unsigned int r_length:2;
257   /* 1 => relocate with value of symbol.
258      r_symbolnum is the index of the symbol
259      in files the symbol table.
260      0 => relocate with the address of a segment.
261      r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
262      (the N_EXT bit may be set also, but signifies nothing).  */
263   unsigned int r_extern:1;
264   /* The next three bits are for SunOS shared libraries, and seem to
265      be undocumented.  */
266   unsigned int r_baserel:1;     /* Linkage table relative */
267   unsigned int r_jmptable:1;    /* pc-relative to jump table */
268   unsigned int r_relative:1;    /* "relative relocation" */
269   /* unused */
270   unsigned int r_pad:1;         /* Padding -- set to zero */
271 };
272
273
274 /* EXTENDED RELOCS  */
275
276 struct reloc_ext_external {
277   bfd_byte r_address[BYTES_IN_WORD];    /* offset of of data to relocate        */
278   bfd_byte r_index[3];  /* symbol table index of symbol         */
279   bfd_byte r_type[1];   /* relocation type                      */
280   bfd_byte r_addend[BYTES_IN_WORD];     /* datum addend                         */
281 };
282
283 #define RELOC_EXT_BITS_EXTERN_BIG       0x80
284 #define RELOC_EXT_BITS_EXTERN_LITTLE    0x01
285
286 #define RELOC_EXT_BITS_TYPE_BIG         0x1F
287 #define RELOC_EXT_BITS_TYPE_SH_BIG      0
288 #define RELOC_EXT_BITS_TYPE_LITTLE      0xF8
289 #define RELOC_EXT_BITS_TYPE_SH_LITTLE   3
290
291 #define RELOC_EXT_SIZE  (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD) /* Bytes per relocation entry */
292
293 enum reloc_type
294 {
295
296
297
298
299
300   /* simple relocations */
301   RELOC_8,                      /* data[0:7] = addend + sv              */
302   RELOC_16,                     /* data[0:15] = addend + sv             */
303   RELOC_32,                     /* data[0:31] = addend + sv             */
304   /* pc-rel displacement */
305   RELOC_DISP8,                  /* data[0:7] = addend - pc + sv         */
306   RELOC_DISP16,                 /* data[0:15] = addend - pc + sv        */
307   RELOC_DISP32,                 /* data[0:31] = addend - pc + sv        */
308   /* Special */
309   RELOC_WDISP30,                /* data[0:29] = (addend + sv - pc)>>2   */
310   RELOC_WDISP22,                /* data[0:21] = (addend + sv - pc)>>2   */
311   RELOC_HI22,                   /* data[0:21] = (addend + sv)>>10       */
312   RELOC_22,                     /* data[0:21] = (addend + sv)           */
313   RELOC_13,                     /* data[0:12] = (addend + sv)           */
314   RELOC_LO10,                   /* data[0:9] = (addend + sv)            */
315   RELOC_SFA_BASE,               
316   RELOC_SFA_OFF13,
317   /* P.I.C. (base-relative) */
318   RELOC_BASE10,                 /* Not sure - maybe we can do this the */
319   RELOC_BASE13,                 /* right way now */
320   RELOC_BASE22,
321   /* for some sort of pc-rel P.I.C. (?) */
322   RELOC_PC10,
323   RELOC_PC22,
324   /* P.I.C. jump table */
325   RELOC_JMP_TBL,
326   /* reputedly for shared libraries somehow */
327   RELOC_SEGOFF16,
328   RELOC_GLOB_DAT,
329   RELOC_JMP_SLOT,
330   RELOC_RELATIVE,
331
332   RELOC_11,     
333   RELOC_WDISP2_14,
334   RELOC_WDISP19,
335   RELOC_HHI22,                  /* data[0:21] = (addend + sv) >> 42     */
336   RELOC_HLO10,                  /* data[0:9] = (addend + sv) >> 32      */
337   
338   /* 29K relocation types */
339   RELOC_JUMPTARG,
340   RELOC_CONST,
341   RELOC_CONSTH,
342   
343   /* All the new ones I can think of *//*v9*/
344
345   RELOC_64,                     /* data[0:63] = addend + sv             *//*v9*/
346   RELOC_DISP64,                 /* data[0:63] = addend - pc + sv        *//*v9*/
347   RELOC_WDISP21,                /* data[0:20] = (addend + sv - pc)>>2   *//*v9*/
348   RELOC_DISP21,                 /* data[0:20] = addend - pc + sv        *//*v9*/
349   RELOC_DISP14,                 /* data[0:13] = addend - pc + sv        *//*v9*/
350   /* Q .
351      What are the other ones,
352      Since this is a clean slate, can we throw away the ones we dont
353      understand ? Should we sort the values ? What about using a
354      microcode format like the 68k ?
355      */
356   NO_RELOC
357   };
358
359
360 struct reloc_internal {
361   bfd_vma r_address;            /* offset of of data to relocate        */
362   long  r_index;                /* symbol table index of symbol         */
363   enum reloc_type r_type;       /* relocation type                      */
364   bfd_vma r_addend;             /* datum addend                         */
365 };
366
367 /* Q.
368    Should the length of the string table be 4 bytes or 8 bytes ?
369
370    Q.
371    What about archive indexes ?
372
373  */
374
375 #endif                          /* __A_OUT_GNU_H__ */