1 /* $OpenBSD: a.out.h,v 1.4 2024/10/16 18:47:48 miod Exp $ */ 2 /* $NetBSD: a.out.h,v 1.15 1994/10/26 00:55:42 cgd Exp $ */ 3 4 /*- 5 * Copyright (c) 1993 Theo de Raadt 6 * Copyright (c) 1991 The Regents of the University of California. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)a.out.h 5.6 (Berkeley) 4/30/91 34 */ 35 36 #ifndef _AOUT_H_ 37 #define _AOUT_H_ 38 39 /* 40 * Legacy a.out structures and defines. 41 */ 42 43 /* 44 * Header prepended to each a.out file. 45 * only manipulate the a_midmag field via the 46 * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below. 47 */ 48 struct exec { 49 u_int32_t a_midmag; /* htonl(flags<<26|mid<<16|magic) */ 50 u_int32_t a_text; /* text segment size */ 51 u_int32_t a_data; /* initialized data size */ 52 u_int32_t a_bss; /* uninitialized data size */ 53 u_int32_t a_syms; /* symbol table size */ 54 u_int32_t a_entry; /* entry point */ 55 u_int32_t a_trsize; /* text relocation size */ 56 u_int32_t a_drsize; /* data relocation size */ 57 }; 58 59 /* a_magic */ 60 #define OMAGIC 0407 /* old impure format */ 61 #define NMAGIC 0410 /* read-only text */ 62 #define ZMAGIC 0413 /* demand load format */ 63 #define QMAGIC 0314 /* "compact" demand load format; deprecated */ 64 65 /* 66 * a_flags 67 */ 68 #define EX_DYNAMIC 0x20 69 #define EX_PIC 0x10 70 #define EX_DPMASK 0x30 71 /* 72 * Interpretation of the (a_flags & EX_DPMASK) bits: 73 * 74 * 00 traditional executable or object file 75 * 01 object file contains PIC code (set by `as -k') 76 * 10 dynamic executable 77 * 11 position independent executable image 78 * (eg. a shared library) 79 * 80 */ 81 82 /* 83 * The a.out structure's a_midmag field is a network-byteorder encoding 84 * of this int 85 * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM 86 * Where `F' is 6 bits of flag like EX_DYNAMIC, 87 * `m' is 10 bits of machine-id like MID_I386, and 88 * `M' is 16 bits worth of magic number, ie. ZMAGIC. 89 * The macros below will set/get the needed fields. 90 */ 91 #define N_GETMAGIC(ex) \ 92 ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : ((ex).a_midmag)) 93 #define N_GETMAGIC2(ex) \ 94 ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : \ 95 (((ex).a_midmag) | 0x10000) ) 96 #define N_GETMID(ex) \ 97 ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>16)&0x03ff) : MID_ZERO ) 98 #define N_GETFLAG(ex) \ 99 ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>26)&0x3f) : 0 ) 100 #define N_SETMAGIC(ex,mag,mid,flag) \ 101 ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \ 102 (((mag)&0xffff)) ) ) 103 104 #define N_ALIGN(ex,x) \ 105 (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \ 106 ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x)) 107 108 /* Valid magic number check. */ 109 #define N_BADMAG(ex) \ 110 (N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \ 111 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC) 112 113 /* Address of the bottom of the text segment. */ 114 #define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ) 115 116 /* Address of the bottom of the data segment. */ 117 #define N_DATADDR(ex) \ 118 (N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \ 119 (N_TXTADDR(ex) + (ex).a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1)) 120 121 /* Address of the bottom of the bss segment. */ 122 #define N_BSSADDR(ex) \ 123 (N_DATADDR(ex) + (ex).a_data) 124 125 /* Text segment offset. */ 126 #define N_TXTOFF(ex) \ 127 ( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \ 128 0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \ 129 sizeof(struct exec)) ) 130 131 /* Data segment offset. */ 132 #define N_DATOFF(ex) \ 133 N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text) 134 135 /* Text relocation table offset. */ 136 #define N_TRELOFF(ex) \ 137 (N_DATOFF(ex) + (ex).a_data) 138 139 /* Data relocation table offset. */ 140 #define N_DRELOFF(ex) \ 141 (N_TRELOFF(ex) + (ex).a_trsize) 142 143 /* Symbol table offset. */ 144 #define N_SYMOFF(ex) \ 145 (N_DRELOFF(ex) + (ex).a_drsize) 146 147 /* String table offset. */ 148 #define N_STROFF(ex) \ 149 (N_SYMOFF(ex) + (ex).a_syms) 150 151 #include <sys/exec.h> 152 153 #define _AOUT_INCLUDE_ 154 #include <nlist.h> 155 156 #endif /* !_AOUT_H_ */ 157