1 #ifndef __A_OUT_GNU_H__
2 #define __A_OUT_GNU_H__
4 #include "target.h" /* Figure out which target and host systems */
6 #define __GNU_EXEC_MACROS__
8 #ifndef __STRUCT_EXEC_OVERRIDE__
12 unsigned long a_info; /* Use macros N_MAGIC, etc for access */
13 unsigned a_text; /* length of text, in bytes */
14 unsigned a_data; /* length of data, in bytes */
15 unsigned a_bss; /* length of uninitialized data area for file, in bytes */
16 unsigned a_syms; /* length of symbol table data in file, in bytes */
17 unsigned a_entry; /* start address */
18 unsigned a_trsize; /* length of relocation info for text, in bytes */
19 unsigned a_drsize; /* length of relocation info for data, in bytes */
22 #endif /* __STRUCT_EXEC_OVERRIDE__ */
24 /* these go in the N_MACHTYPE field */
25 /* These symbols could be defined by code from Suns...punt 'em */
35 /* skip a bunch so we don't run into any of sun's numbers */
40 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
41 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
42 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
43 #define N_SET_INFO(exec, magic, type, flags) \
44 ((exec).a_info = ((magic) & 0xffff) \
45 | (((int)(type) & 0xff) << 16) \
46 | (((flags) & 0xff) << 24))
47 #define N_SET_MAGIC(exec, magic) \
48 ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
50 #define N_SET_MACHTYPE(exec, machtype) \
52 ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
54 #define N_SET_FLAGS(exec, flags) \
56 ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
58 /* Code indicating object file or impure executable. */
60 /* Code indicating pure executable. */
62 /* Code indicating demand-paged executable. */
66 (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
67 && N_MAGIC(x) != ZMAGIC)
69 #define _N_BADMAG(x) \
70 (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
71 && N_MAGIC(x) != ZMAGIC)
73 #define _N_HDROFF(x) (1024 - sizeof (struct exec))
76 (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec))
78 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
80 #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
82 #define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
84 #define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
86 #define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
88 /* Address of text segment in memory after it is loaded. */
89 /* Don't load things at zero, it encourages zero-pointer bugs */
90 #ifndef TEXT_START_ADDR
91 #define TEXT_START_ADDR 0x10000
93 #define N_TXTADDR(x) TEXT_START_ADDR
95 /* Address of data segment in memory after it is loaded.
96 Note that it is up to you to define SEGMENT_SIZE
97 on machines not listed here. */
99 #if defined(vax) || defined(hp300) || defined(pyr)
100 #define SEGMENT_SIZE page_size
103 #define SEGMENT_SIZE 0x2000
106 #define SEGMENT_SIZE 0x20000
108 #if defined(m68k) && defined(PORTAR)
109 #define PAGE_SIZE 0x400
110 #define SEGMENT_SIZE PAGE_SIZE
114 #define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
116 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
119 #define N_DATADDR(x) \
120 (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
121 : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
124 /* Address of bss segment in memory after it is loaded. */
125 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
130 struct nlist *n_next;
133 unsigned char n_type;
136 unsigned long n_value;
150 /* The following type indicates the definition of a symbol as being
151 an indirect reference to another symbol. The other symbol
152 appears as an undefined reference, immediately following this symbol.
154 Indirection is asymmetrical. The other symbol's value will be used
155 to satisfy requests for the indirect symbol, but not vice versa.
156 If the other symbol does not have a definition, libraries will
157 be searched to find a definition. */
160 /* The following symbols refer to set elements.
161 All the N_SET[ATDB] symbols with the same name form one set.
162 Space is allocated for the set in the text section, and each set
163 element's value is stored into one word of the space.
164 The first word of the space is the length of the set (number of elements).
166 The address of the set is made into an N_SETV symbol
167 whose name is the same as the name of the set.
168 This symbol acts like a N_DATA global symbol
169 in that it can satisfy undefined external references. */
171 /* These appear as input to LD, in a .o file. */
172 #define N_SETA 0x14 /* Absolute set element symbol */
173 #define N_SETT 0x16 /* Text set element symbol */
174 #define N_SETD 0x18 /* Data set element symbol */
175 #define N_SETB 0x1A /* Bss set element symbol */
177 /* This is output from LD. */
178 #define N_SETV 0x1C /* Pointer to set vector in data area. */
180 /* This structure describes a single relocation to be performed.
181 The text-relocation section of the file is a vector of these structures,
182 all of which apply to the text section.
183 Likewise, the data-relocation section applies to the data section. */
185 #if TARGET == TARGET_SPARC || TARGET == TARGET_AM29K
187 * The following enum and struct were borrowed from
188 * sunOS /usr/include/sun4/a.out.h and extended to handle
194 RELOC_8, RELOC_16, RELOC_32, RELOC_DISP8,
195 RELOC_DISP16, RELOC_DISP32, RELOC_WDISP30, RELOC_WDISP22,
196 RELOC_HI22, RELOC_22, RELOC_13, RELOC_LO10,
197 RELOC_SFA_BASE, RELOC_SFA_OFF13, RELOC_BASE10, RELOC_BASE13,
198 RELOC_BASE22, RELOC_PC10, RELOC_PC22, RELOC_JMP_TBL,
199 RELOC_SEGOFF16, RELOC_GLOB_DAT, RELOC_JMP_SLOT, RELOC_RELATIVE,
201 /* 29K relocation types */
202 RELOC_JUMPTARG, RELOC_CONST, RELOC_CONSTH,
207 #define RELOC_TYPE_NAMES \
208 "8", "16", "32", "DISP8", \
209 "DISP16", "DISP32", "WDISP30", "WDISP22", \
210 "HI22", "22", "13", "LO10", \
211 "SFA_BASE", "SFAOFF13", "BASE10", "BASE13", \
212 "BASE22", "PC10", "PC22", "JMP_TBL", \
213 "SEGOFF16", "GLOB_DAT", "JMP_SLOT", "RELATIVE", \
214 "JUMPTARG", "CONST", "CONSTH", \
216 "XXX_28", "XXX_29", "XXX_30", "XXX_31"
218 struct reloc_info_extended
220 unsigned long r_address;
221 unsigned int r_index:24;
222 # define r_symbolnum r_index
225 enum reloc_type r_type:5;
229 /* Let programs know what they're dealing with */
230 #define RELOC_EXTENDED 1
232 #undef relocation_info
233 #define relocation_info reloc_info_extended
234 #define RELOC_ADDRESS(r) ((r)->r_address)
235 #define RELOC_EXTERN_P(r) ((r)->r_extern)
236 #define RELOC_TYPE(r) ((r)->r_index)
237 #define RELOC_EXTENDED_TYPE(r) ((r)->r_type)
238 #define RELOC_SYMBOL(r) ((r)->r_index)
239 #define RELOC_MEMORY_SUB_P(r) 0
240 #define RELOC_MEMORY_ADD_P(r) 0
241 #define RELOC_ADD_EXTRA(r) ((r)->r_addend)
242 #define RELOC_PCREL_P(r) \
243 ( ((r)->r_type >= RELOC_DISP8 && (r)->r_type <= RELOC_WDISP22) \
244 || (r)->r_type == RELOC_JUMPTARG )
245 #define RELOC_VALUE_RIGHTSHIFT(r) (reloc_target_rightshift[(r)->r_type])
246 #define RELOC_TARGET_SIZE(r) (reloc_target_size[(r)->r_type])
247 #define RELOC_TARGET_BITPOS(r) 0
248 #define RELOC_TARGET_BITSIZE(r) (reloc_target_bitsize[(r)->r_type])
250 /* Note that these are very dependent on the order of the enums in
251 enum reloc_type (in a.out.h); if they change the following must be
253 /* Also note that some of these may be incorrect; I have no information */
257 static const int reloc_target_rightshift[] = {
264 2, 0,16, /* 29K jumptarg, const, consth */
267 #define RELOC_SIZE_SPLIT16 13
268 static const int reloc_target_size[] = {
275 RELOC_SIZE_SPLIT16, RELOC_SIZE_SPLIT16, RELOC_SIZE_SPLIT16,
278 static const int reloc_target_bitsize[] = {
283 0, 0, 0, 0, /* dunno */
285 16, 16, 16, /* 29K jumptarg, const, consth */
289 #define MAX_ALIGNMENT (sizeof (double))
291 #else /* Not SPARC or AM29K */
293 struct relocation_info
295 /* Address (within segment) to be relocated. */
297 /* The meaning of r_symbolnum depends on r_extern. */
298 unsigned int r_symbolnum:24;
299 /* Nonzero means value is a pc-relative offset
300 and it should be relocated for changes in its own address
301 as well as for changes in the symbol or section specified. */
302 unsigned int r_pcrel:1;
303 /* Length (as exponent of 2) of the field to be relocated.
304 Thus, a value of 2 indicates 1<<2 bytes. */
305 unsigned int r_length:2;
306 /* 1 => relocate with value of symbol.
307 r_symbolnum is the index of the symbol
308 in file's the symbol table.
309 0 => relocate with the address of a segment.
310 r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
311 (the N_EXT bit may be set also, but signifies nothing). */
312 unsigned int r_extern:1;
313 /* Four bits that aren't used, but when writing an object file
314 it is desirable to clear them. */
315 unsigned int r_pad:4;
320 * Ok. Following are the relocation information macros. If your
321 * system should not be able to use the default set (below), you must
322 * define the following:
324 * relocation_info: This must be typedef'd (or #define'd) to the type
325 * of structure that is stored in the relocation info section of your
326 * a.out files. Often this is defined in the a.out.h for your system.
328 * RELOC_ADDRESS (rval): Offset into the current section of the
329 * <whatever> to be relocated. *Must be an lvalue*.
331 * RELOC_EXTERN_P (rval): Is this relocation entry based on an
332 * external symbol (1), or was it fully resolved upon entering the
333 * loader (0) in which case some combination of the value in memory
334 * (if RELOC_MEMORY_ADD_P) and the extra (if RELOC_ADD_EXTRA) contains
335 * what the value of the relocation actually was. *Must be an lvalue*.
337 * RELOC_TYPE (rval): If this entry was fully resolved upon
338 * entering the loader, what type should it be relocated as?
340 * RELOC_EXTENDED_TYPE (rval): If this entry is for a machine using
341 * extended relocatino, what type of field is it? (For example, on RISC
342 * machines, odd-sized displacements or split displacements occur.)
344 * RELOC_SYMBOL (rval): If this entry was not fully resolved upon
345 * entering the loader, what is the index of it's symbol in the symbol
346 * table? *Must be a lvalue*.
348 * RELOC_MEMORY_ADD_P (rval): This should return true if the final
349 * relocation value output here should be added to memory, or if the
350 * section of memory described should simply be set to the relocation
353 * RELOC_ADD_EXTRA (rval): (Optional) This macro, if defined, gives
354 * an extra value to be added to the relocation value based on the
355 * individual relocation entry. *Must be an lvalue if defined*.
357 * RELOC_PCREL_P (rval): True if the relocation value described is
360 * RELOC_VALUE_RIGHTSHIFT (rval): Number of bits right to shift the
361 * final relocation value before putting it where it belongs.
363 * RELOC_TARGET_SIZE (rval): log to the base 2 of the number of
364 * bytes of size this relocation entry describes; 1 byte == 0; 2 bytes
365 * == 1; 4 bytes == 2, and etc. This is somewhat redundant (we could
366 * do everything in terms of the bit operators below), but having this
367 * macro could end up producing better code on machines without fancy
368 * bit twiddling. Also, it's easier to understand/code big/little
369 * endian distinctions with this macro.
371 * RELOC_TARGET_BITPOS (rval): The starting bit position within the
372 * object described in RELOC_TARGET_SIZE in which the relocation value
375 * RELOC_TARGET_BITSIZE (rval): How many bits are to be replaced
376 * with the bits of the relocation value. It may be assumed by the
377 * code that the relocation value will fit into this many bits. This
378 * may be larger than RELOC_TARGET_SIZE if such be useful.
381 * Things I haven't implemented
382 * ----------------------------
384 * Values for RELOC_TARGET_SIZE other than 0, 1, or 2.
386 * Pc relative relocation for External references.
388 #if TARGET == TARGET_SEQUENT
389 #define RELOC_ADDRESS(r) ((r)->r_address)
390 #define RELOC_EXTERN_P(r) ((r)->r_extern)
391 #define RELOC_TYPE(r) ((r)->r_symbolnum)
392 #define RELOC_SYMBOL(r) ((r)->r_symbolnum)
393 #define RELOC_MEMORY_SUB_P(r) ((r)->r_bsr)
394 #define RELOC_MEMORY_ADD_P(r) 1
395 #undef RELOC_ADD_EXTRA
396 #define RELOC_PCREL_P(r) ((r)->r_pcrel || (r)->r_bsr)
397 #define RELOC_VALUE_RIGHTSHIFT(r) 0
398 #define RELOC_TARGET_SIZE(r) ((r)->r_length)
399 #define RELOC_TARGET_BITPOS(r) 0
400 #define RELOC_TARGET_BITSIZE(r) 32
404 #ifndef RELOC_ADDRESS
405 #define RELOC_ADDRESS(r) ((r)->r_address)
406 #define RELOC_EXTERN_P(r) ((r)->r_extern)
407 #define RELOC_TYPE(r) ((r)->r_symbolnum)
408 #define RELOC_SYMBOL(r) ((r)->r_symbolnum)
409 #define RELOC_MEMORY_SUB_P(r) 0
410 #define RELOC_MEMORY_ADD_P(r) 1
411 #undef RELOC_ADD_EXTRA
412 #define RELOC_PCREL_P(r) ((r)->r_pcrel)
413 #define RELOC_VALUE_RIGHTSHIFT(r) 0
414 #define RELOC_TARGET_SIZE(r) ((r)->r_length)
415 #define RELOC_TARGET_BITPOS(r) 0
416 #define RELOC_TARGET_BITSIZE(r) 32
419 /* Maximum alignment required of a common'd variable. If a var of this
420 size or larger is allocated in BSS when nobody defines it, it gets
423 #ifndef MAX_ALIGNMENT
424 #define MAX_ALIGNMENT (sizeof (int))
428 /* Definitions for routines that read and write GNU a.out files */
437 enum objfile_kind read_aout_header(); /* (desc, &header) read&swap header */
439 /* Read an a.out header from DESC and call rel_fn(DESC, header)
440 if it is an object file, lib_fn(DESC) if it is a library, else
441 call err_fn("msg") */
442 void handle_aout_header(); /* (desc, rel_fn, lib_fn, err_fn) */
444 /* Byte-swapping definitions */
446 void swap_aoutheader(); /* BSD a.out header */
447 short swap_getshort ();
448 void swap_putshort();
449 long swap_getlong ();
451 void swap_reloc_info_in(); /* BSD relocation information */
452 void swap_reloc_info_out(); /* BSD relocation information */
453 void swap_nlists(); /* BSD symbol name lists */
454 void swap_root_updates(); /* GDB Symseg */
456 /* Bring on the encapsulation, if configured in! */
457 #ifdef COFF_ENCAPSULATE
458 #include "a.out.encap.h"
461 #endif /* __A_OUT_GNU_H__ */