1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. 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 * @(#)exec.h 8.1 (Berkeley) 6/11/93 34 * $Id: exec.h,v 1.3 1994/08/02 07:38:45 davidg Exp $ 35 */ 36 37 #ifndef _EXEC_H_ 38 #define _EXEC_H_ 39 40 #if defined(hp300) || defined(i386) 41 #define __LDPGSZ 4096 42 #endif 43 #if defined(tahoe) || defined(vax) 44 #define __LDPGSZ 1024 45 #endif 46 47 #define N_GETMAGIC(ex) \ 48 ( (ex).a_midmag & 0xffff ) 49 #define N_GETMID(ex) \ 50 ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \ 51 ((ex).a_midmag >> 16) & 0x03ff ) 52 #define N_GETFLAG(ex) \ 53 ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \ 54 ((ex).a_midmag >> 26) & 0x3f ) 55 #define N_SETMAGIC(ex,mag,mid,flag) \ 56 ( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \ 57 ((mag) & 0xffff) ) 58 59 #define N_GETMAGIC_NET(ex) \ 60 (ntohl((ex).a_midmag) & 0xffff) 61 #define N_GETMID_NET(ex) \ 62 ((ntohl((ex).a_midmag) >> 16) & 0x03ff) 63 #define N_GETFLAG_NET(ex) \ 64 ((ntohl((ex).a_midmag) >> 26) & 0x3f) 65 #define N_SETMAGIC_NET(ex,mag,mid,flag) \ 66 ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \ 67 (((mag)&0xffff)) ) ) 68 69 #define N_ALIGN(ex,x) \ 70 (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \ 71 N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \ 72 ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x)) 73 74 /* Valid magic number check. */ 75 #define N_BADMAG(ex) \ 76 (N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \ 77 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \ 78 N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \ 79 N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC) 80 81 82 /* Address of the bottom of the text segment. */ 83 #define N_TXTADDR(ex) \ 84 ((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \ 85 N_GETMAGIC(ex) == ZMAGIC) ? 0 : __LDPGSZ) 86 87 /* Address of the bottom of the data segment. */ 88 #define N_DATADDR(ex) \ 89 N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text) 90 91 /* Text segment offset. */ 92 #define N_TXTOFF(ex) \ 93 (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \ 94 N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec)) 95 96 /* Data segment offset. */ 97 #define N_DATOFF(ex) \ 98 N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text) 99 100 /* Relocation table offset. */ 101 #define N_RELOFF(ex) \ 102 N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data) 103 104 /* Symbol table offset. */ 105 #define N_SYMOFF(ex) \ 106 (N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize) 107 108 /* String table offset. */ 109 #define N_STROFF(ex) (N_SYMOFF(ex) + (ex).a_syms) 110 111 /* 112 * Header prepended to each a.out file. 113 * only manipulate the a_midmag field via the 114 * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h 115 */ 116 117 struct exec { 118 unsigned long a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */ 119 unsigned long a_text; /* text segment size */ 120 unsigned long a_data; /* initialized data size */ 121 unsigned long a_bss; /* uninitialized data size */ 122 unsigned long a_syms; /* symbol table size */ 123 unsigned long a_entry; /* entry point */ 124 unsigned long a_trsize; /* text relocation size */ 125 unsigned long a_drsize; /* data relocation size */ 126 }; 127 #define a_magic a_midmag /* XXX Hack to work with current kern_execve.c */ 128 129 /* a_magic */ 130 #define OMAGIC 0407 /* old impure format */ 131 #define NMAGIC 0410 /* read-only text */ 132 #define ZMAGIC 0413 /* demand load format */ 133 #define QMAGIC 0314 /* "compact" demand load format */ 134 135 /* a_mid */ 136 #define MID_ZERO 0 /* unknown - implementation dependent */ 137 #define MID_SUN010 1 /* sun 68010/68020 binary */ 138 #define MID_SUN020 2 /* sun 68020-only binary */ 139 #define MID_I386 134 /* i386 BSD binary */ 140 #define MID_HP200 200 /* hp200 (68010) BSD binary */ 141 #define MID_HP300 300 /* hp300 (68020+68881) BSD binary */ 142 #define MID_HPUX 0x20C /* hp200/300 HP-UX binary */ 143 #define MID_HPUX800 0x20B /* hp800 HP-UX binary */ 144 145 /* 146 * a_flags 147 */ 148 #define EX_DYNAMIC 0x20 /* a.out contains run-time link-edit info */ 149 150 #endif /* !_EXEC_H_ */ 151