1 #ifndef _BSD_A_OUT_H 2 #define _BSD_A_OUT_H 3 4 struct exec { /* a.out header */ 5 unsigned char a_magic[2]; /* magic number */ 6 unsigned char a_flags; /* flags, see below */ 7 unsigned char a_cpu; /* cpu id */ 8 unsigned char a_hdrlen; /* length of header */ 9 unsigned char a_unused; /* reserved for future use */ 10 unsigned short a_version; /* version stamp (not used at present) */ 11 long a_text; /* size of text segement in bytes */ 12 long a_data; /* size of data segment in bytes */ 13 long a_bss; /* size of bss segment in bytes */ 14 long a_entry; /* entry point */ 15 long a_total; /* total memory allocated */ 16 long a_syms; /* size of symbol table */ 17 /* SHORT FORM ENDS HERE */ 18 19 long a_trsize; /* text relocation size */ 20 long a_drsize; /* data relocation size */ 21 long a_tbase; /* text relocation base */ 22 long a_dbase; /* data relocation base */ 23 }; 24 25 #define A_MAGIC0 ((unsigned char) 0x01) 26 #define A_MAGIC1 ((unsigned char) 0x03) 27 #define BADMAG(X) ((X).a_magic[0] != A_MAGIC0 || (X).a_magic[1] != A_MAGIC1) 28 29 /* CPU Id of TARGET machine (byte order coded in low order two bits) */ 30 #define A_NONE 0x00 /* unknown */ 31 #define A_I8086 0x04 /* intel i8086/8088 */ 32 #define A_M68K 0x0B /* motorola m68000 */ 33 #define A_NS16K 0x0C /* national semiconductor 16032 */ 34 #define A_I80386 0x10 /* intel i80386 */ 35 #define A_SPARC 0x17 /* Sun SPARC */ 36 37 #define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */ 38 #define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */ 39 40 /* Flags. */ 41 #define A_UZP 0x01 /* unmapped zero page (pages) */ 42 #define A_EXEC 0x10 /* executable */ 43 #define A_SEP 0x20 /* separate I/D */ 44 #define A_PURE 0x40 /* pure text */ /* not used */ 45 #define A_TOVLY 0x80 /* text overlay */ /* not used */ 46 47 /* Tell a.out.gnu.h not to define `struct exec'. */ 48 #define __STRUCT_EXEC_OVERRIDE__ 49 50 /* Hide M_386 from enum declaration in a.out.h. */ 51 #define M_386 HIDE_M_386 52 53 #ifndef __A_OUT_GNU_H__ 54 #define __A_OUT_GNU_H__ 55 56 #if defined(sequent) && defined(i386) 57 #define a_magic a_info 58 #include <a.out.h> 59 #undef a_magic 60 #define __STRUCT_EXEC_OVERRIDE__ 61 #define N_NLIST_DECLARED 62 #define N_RELOCATION_INFO_DECLARED 63 #endif 64 65 #define __GNU_EXEC_MACROS__ 66 67 #ifndef __STRUCT_EXEC_OVERRIDE__ 68 69 struct exec 70 { 71 unsigned long a_info; /* Use macros N_MAGIC, etc for access */ 72 unsigned long a_text; /* length of text, in bytes */ 73 unsigned long a_data; /* length of data, in bytes */ 74 unsigned long a_bss; /* length of uninitialized data area for file, in bytes */ 75 unsigned long a_syms; /* length of symbol table data in file, in bytes */ 76 unsigned long a_entry; /* start address */ 77 unsigned long a_trsize; /* length of relocation info for text, in bytes */ 78 unsigned long a_drsize; /* length of relocation info for data, in bytes */ 79 }; 80 81 #endif /* __STRUCT_EXEC_OVERRIDE__ */ 82 83 /* these go in the N_MACHTYPE field */ 84 enum machine_type { 85 #if defined (M_OLDSUN2) 86 M__OLDSUN2 = M_OLDSUN2, 87 #else 88 M_OLDSUN2 = 0, 89 #endif 90 #if defined (M_68010) 91 M__68010 = M_68010, 92 #else 93 M_68010 = 1, 94 #endif 95 #if defined (M_68020) 96 M__68020 = M_68020, 97 #else 98 M_68020 = 2, 99 #endif 100 #if defined (M_SPARC) 101 M__SPARC = M_SPARC, 102 #else 103 M_SPARC = 3, 104 #endif 105 /* skip a bunch so we don't run into any of sun's numbers */ 106 M_386 = 100, 107 }; 108 109 #if !defined (N_MAGIC) 110 #define N_MAGIC(exec) ((exec).a_info & 0xffff) 111 #endif 112 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff)) 113 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff) 114 #define N_SET_INFO(exec, magic, type, flags) \ 115 ((exec).a_info = ((magic) & 0xffff) \ 116 | (((int)(type) & 0xff) << 16) \ 117 | (((flags) & 0xff) << 24)) 118 #define N_SET_MAGIC(exec, magic) \ 119 ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff))) 120 121 #define N_SET_MACHTYPE(exec, machtype) \ 122 ((exec).a_info = \ 123 ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16)) 124 125 #define N_SET_FLAGS(exec, flags) \ 126 ((exec).a_info = \ 127 ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24)) 128 129 #ifndef OMAGIC 130 /* Code indicating object file or impure executable. */ 131 #define OMAGIC 0407 132 /* Code indicating pure executable. */ 133 #define NMAGIC 0410 134 /* Code indicating demand-paged executable. */ 135 #define ZMAGIC 0413 136 #endif /* not OMAGIC */ 137 138 #if !defined (N_BADMAG) 139 #define N_BADMAG(x) \ 140 (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \ 141 && N_MAGIC(x) != ZMAGIC) 142 #endif 143 144 #define _N_BADMAG(x) \ 145 (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \ 146 && N_MAGIC(x) != ZMAGIC) 147 148 #define _N_HDROFF(x) (SEGMENT_SIZE - sizeof (struct exec)) 149 150 #if !defined (N_TXTOFF) 151 #define N_TXTOFF(x) \ 152 (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec)) 153 #endif 154 155 #if !defined (N_DATOFF) 156 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text) 157 #endif 158 159 #if !defined (N_TRELOFF) 160 #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data) 161 #endif 162 163 #if !defined (N_DRELOFF) 164 #define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize) 165 #endif 166 167 #if !defined (N_SYMOFF) 168 #define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize) 169 #endif 170 171 #if !defined (N_STROFF) 172 #define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms) 173 #endif 174 175 /* Address of text segment in memory after it is loaded. */ 176 #if !defined (N_TXTADDR) 177 #define N_TXTADDR(x) 0 178 #endif 179 180 /* Address of data segment in memory after it is loaded. 181 Note that it is up to you to define SEGMENT_SIZE 182 on machines not listed here. */ 183 #if defined(vax) || defined(hp300) || defined(pyr) 184 #define SEGMENT_SIZE PAGE_SIZE 185 #endif 186 #ifdef hp300 187 #define PAGE_SIZE 4096 188 #endif 189 #ifdef sony 190 #define SEGMENT_SIZE 0x2000 191 #endif /* Sony. */ 192 #ifdef is68k 193 #define SEGMENT_SIZE 0x20000 194 #endif 195 #if defined(m68k) && defined(PORTAR) 196 #define PAGE_SIZE 0x400 197 #define SEGMENT_SIZE PAGE_SIZE 198 #endif 199 200 #define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1)) 201 202 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text) 203 204 #ifndef N_DATADDR 205 #define N_DATADDR(x) \ 206 (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \ 207 : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x)))) 208 #endif 209 210 /* Address of bss segment in memory after it is loaded. */ 211 #if !defined (N_BSSADDR) 212 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data) 213 #endif 214 215 #if !defined (N_NLIST_DECLARED) 216 struct nlist { 217 union { 218 char *n_name; 219 struct nlist *n_next; 220 long n_strx; 221 } n_un; 222 unsigned char n_type; 223 char n_other; 224 short n_desc; 225 unsigned long n_value; 226 }; 227 #endif /* no N_NLIST_DECLARED. */ 228 229 #if !defined (N_UNDF) 230 #define N_UNDF 0 231 #endif 232 #if !defined (N_ABS) 233 #define N_ABS 2 234 #endif 235 #if !defined (N_TEXT) 236 #define N_TEXT 4 237 #endif 238 #if !defined (N_DATA) 239 #define N_DATA 6 240 #endif 241 #if !defined (N_BSS) 242 #define N_BSS 8 243 #endif 244 #if !defined (N_COMM) 245 #define N_COMM 18 246 #endif 247 #if !defined (N_FN) 248 #define N_FN 15 249 #endif 250 251 #if !defined (N_EXT) 252 #define N_EXT 1 253 #endif 254 #if !defined (N_TYPE) 255 #define N_TYPE 036 256 #endif 257 #if !defined (N_STAB) 258 #define N_STAB 0340 259 #endif 260 261 /* The following type indicates the definition of a symbol as being 262 an indirect reference to another symbol. The other symbol 263 appears as an undefined reference, immediately following this symbol. 264 265 Indirection is asymmetrical. The other symbol's value will be used 266 to satisfy requests for the indirect symbol, but not vice versa. 267 If the other symbol does not have a definition, libraries will 268 be searched to find a definition. */ 269 #define N_INDR 0xa 270 271 /* The following symbols refer to set elements. 272 All the N_SET[ATDB] symbols with the same name form one set. 273 Space is allocated for the set in the text section, and each set 274 element's value is stored into one word of the space. 275 The first word of the space is the length of the set (number of elements). 276 277 The address of the set is made into an N_SETV symbol 278 whose name is the same as the name of the set. 279 This symbol acts like a N_DATA global symbol 280 in that it can satisfy undefined external references. */ 281 282 /* These appear as input to LD, in a .o file. */ 283 #define N_SETA 0x14 /* Absolute set element symbol */ 284 #define N_SETT 0x16 /* Text set element symbol */ 285 #define N_SETD 0x18 /* Data set element symbol */ 286 #define N_SETB 0x1A /* Bss set element symbol */ 287 288 /* This is output from LD. */ 289 #define N_SETV 0x1C /* Pointer to set vector in data area. */ 290 291 #if !defined (N_RELOCATION_INFO_DECLARED) 292 /* This structure describes a single relocation to be performed. 293 The text-relocation section of the file is a vector of these structures, 294 all of which apply to the text section. 295 Likewise, the data-relocation section applies to the data section. */ 296 297 struct relocation_info 298 { 299 /* Address (within segment) to be relocated. */ 300 unsigned long r_address; 301 #if 0 302 /* The meaning of r_symbolnum depends on r_extern. */ 303 unsigned int r_symbolnum:24; 304 /* Nonzero means value is a pc-relative offset 305 and it should be relocated for changes in its own address 306 as well as for changes in the symbol or section specified. */ 307 unsigned int r_pcrel:1; 308 /* Length (as exponent of 2) of the field to be relocated. 309 Thus, a value of 2 indicates 1<<2 bytes. */ 310 unsigned int r_length:2; 311 /* 1 => relocate with value of symbol. 312 r_symbolnum is the index of the symbol 313 in file's the symbol table. 314 0 => relocate with the address of a segment. 315 r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS 316 (the N_EXT bit may be set also, but signifies nothing). */ 317 unsigned int r_extern:1; 318 /* Four bits that aren't used, but when writing an object file 319 it is desirable to clear them. */ 320 unsigned int r_pad:4; 321 #else 322 unsigned long foo; 323 #endif 324 }; 325 #endif /* no N_RELOCATION_INFO_DECLARED. */ 326 327 328 #endif /* __A_OUT_GNU_H__ */ 329 330 #undef M_386 331 #define M_386 A_I80386 332 333 #undef N_MAGIC 334 #define N_MAGIC3(magic0, magic1, type) \ 335 ((magic0) | ((magic1) << 8) | ((type) << 16)) 336 #define N_MAGIC(exec) \ 337 N_MAGIC3((exec).a_magic[0], (exec).a_magic[1], (exec).a_flags) 338 339 #undef N_MACHTYPE 340 #define N_MACHTYPE(exec) ((enum machine_type)((exec).a_cpu)) 341 342 #undef N_FLAGS 343 #define N_FLAGS(exec) 0 344 345 #undef N_SET_INFO 346 #define N_SET_INFO(exec, magic, type, flags) \ 347 ((exec).a_magic[0] = (magic) & 0xff, \ 348 (exec).a_magic[1] = ((magic) >> 8) & 0xff, \ 349 (exec).a_flags = ((magic) >> 16) & 0xff, \ 350 (exec).a_cpu = (type) & 0xff) 351 352 #undef N_SET_MAGIC 353 #define N_SET_MAGIC(exec, magic) \ 354 ((exec).a_magic[0] = (magic) & 0xff, \ 355 (exec).a_magic[1] = ((magic) >> 8) & 0xff, \ 356 (exec).a_flags = ((magic) >> 16) & 0xff) 357 358 #undef N_SET_MACHTYPE 359 #define N_SET_MACHTYPE(exec, machtype) \ 360 ((exec).a_cpu = (machtype) & 0xff, \ 361 (exec).a_hdrlen = sizeof (exec)) 362 363 #undef N_SET_FLAGS 364 #define N_SET_FLAGS(exec, flags) /* nothing */ 365 366 #undef OMAGIC 367 #define OMAGIC N_MAGIC3(A_MAGIC0, A_MAGIC1, 0) 368 369 #undef NMAGIC 370 #define NMAGIC N_MAGIC3(A_MAGIC0, A_MAGIC1, A_EXEC) 371 372 #undef ZMAGIC 373 #define ZMAGIC N_MAGIC3(A_MAGIC0, A_MAGIC1, A_EXEC) 374 375 #undef _N_HDROFF 376 #define _N_HDROFF(x) 0 377 378 #undef PAGE_SIZE 379 #define PAGE_SIZE 16 380 #define SEGMENT_SIZE PAGE_SIZE 381 #define getpagesize() PAGE_SIZE 382 383 #endif /* _BSD_A_OUT_H */ 384