16cda32c0SRodney W. Grimes /*- 26cda32c0SRodney W. Grimes * Copyright (c) 1992, 1993 36cda32c0SRodney W. Grimes * The Regents of the University of California. All rights reserved. 46cda32c0SRodney W. Grimes * 56cda32c0SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 66cda32c0SRodney W. Grimes * modification, are permitted provided that the following conditions 76cda32c0SRodney W. Grimes * are met: 86cda32c0SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 96cda32c0SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 106cda32c0SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 116cda32c0SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 126cda32c0SRodney W. Grimes * documentation and/or other materials provided with the distribution. 136cda32c0SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 146cda32c0SRodney W. Grimes * must display the following acknowledgement: 156cda32c0SRodney W. Grimes * This product includes software developed by the University of 166cda32c0SRodney W. Grimes * California, Berkeley and its contributors. 176cda32c0SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 186cda32c0SRodney W. Grimes * may be used to endorse or promote products derived from this software 196cda32c0SRodney W. Grimes * without specific prior written permission. 206cda32c0SRodney W. Grimes * 216cda32c0SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 226cda32c0SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 236cda32c0SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 246cda32c0SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 256cda32c0SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 266cda32c0SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 276cda32c0SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 286cda32c0SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 296cda32c0SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 306cda32c0SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 316cda32c0SRodney W. Grimes * SUCH DAMAGE. 326cda32c0SRodney W. Grimes * 336cda32c0SRodney W. Grimes * @(#)exec.h 8.1 (Berkeley) 6/11/93 346cda32c0SRodney W. Grimes */ 356cda32c0SRodney W. Grimes 36*26f9a767SRodney W. Grimes #ifndef _EXEC_H_ 37*26f9a767SRodney W. Grimes #define _EXEC_H_ 38*26f9a767SRodney W. Grimes 396cda32c0SRodney W. Grimes #define __LDPGSZ 4096 406cda32c0SRodney W. Grimes 416cda32c0SRodney W. Grimes /* Valid magic number check. */ 426cda32c0SRodney W. Grimes #define N_BADMAG(ex) \ 43*26f9a767SRodney W. Grimes (N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \ 44*26f9a767SRodney W. Grimes N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \ 45*26f9a767SRodney W. Grimes N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \ 46*26f9a767SRodney W. Grimes N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC) 47*26f9a767SRodney W. Grimes 48*26f9a767SRodney W. Grimes #define N_ALIGN(ex,x) \ 49*26f9a767SRodney W. Grimes (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \ 50*26f9a767SRodney W. Grimes N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \ 51*26f9a767SRodney W. Grimes ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x)) 526cda32c0SRodney W. Grimes 536cda32c0SRodney W. Grimes /* Address of the bottom of the text segment. */ 54*26f9a767SRodney W. Grimes #define N_TXTADDR(ex) \ 55*26f9a767SRodney W. Grimes ((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \ 56*26f9a767SRodney W. Grimes N_GETMAGIC(ex) == ZMAGIC) ? 0 : __LDPGSZ) 576cda32c0SRodney W. Grimes 586cda32c0SRodney W. Grimes /* Address of the bottom of the data segment. */ 596cda32c0SRodney W. Grimes #define N_DATADDR(ex) \ 60*26f9a767SRodney W. Grimes N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text) 61*26f9a767SRodney W. Grimes 62*26f9a767SRodney W. Grimes #define N_GETMAGIC(ex) \ 63*26f9a767SRodney W. Grimes ( (ex).a_midmag & 0xffff ) 64*26f9a767SRodney W. Grimes #define N_GETMID(ex) \ 65*26f9a767SRodney W. Grimes ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \ 66*26f9a767SRodney W. Grimes ((ex).a_midmag >> 16) & 0x03ff ) 67*26f9a767SRodney W. Grimes #define N_GETFLAG(ex) \ 68*26f9a767SRodney W. Grimes ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \ 69*26f9a767SRodney W. Grimes ((ex).a_midmag >> 26) & 0x3f ) 70*26f9a767SRodney W. Grimes #define N_SETMAGIC(ex,mag,mid,flag) \ 71*26f9a767SRodney W. Grimes ( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \ 72*26f9a767SRodney W. Grimes ((mag) & 0xffff) ) 73*26f9a767SRodney W. Grimes 74*26f9a767SRodney W. Grimes #define N_GETMAGIC_NET(ex) \ 75*26f9a767SRodney W. Grimes (ntohl((ex).a_midmag) & 0xffff) 76*26f9a767SRodney W. Grimes #define N_GETMID_NET(ex) \ 77*26f9a767SRodney W. Grimes ((ntohl((ex).a_midmag) >> 16) & 0x03ff) 78*26f9a767SRodney W. Grimes #define N_GETFLAG_NET(ex) \ 79*26f9a767SRodney W. Grimes ((ntohl((ex).a_midmag) >> 26) & 0x3f) 80*26f9a767SRodney W. Grimes #define N_SETMAGIC_NET(ex,mag,mid,flag) \ 81*26f9a767SRodney W. Grimes ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \ 82*26f9a767SRodney W. Grimes (((mag)&0xffff)) ) ) 836cda32c0SRodney W. Grimes 846cda32c0SRodney W. Grimes /* Text segment offset. */ 856cda32c0SRodney W. Grimes #define N_TXTOFF(ex) \ 86*26f9a767SRodney W. Grimes (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \ 87*26f9a767SRodney W. Grimes N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec)) 886cda32c0SRodney W. Grimes 896cda32c0SRodney W. Grimes /* Data segment offset. */ 906cda32c0SRodney W. Grimes #define N_DATOFF(ex) \ 91*26f9a767SRodney W. Grimes N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text) 92*26f9a767SRodney W. Grimes 93*26f9a767SRodney W. Grimes /* Relocation table offset. */ 94*26f9a767SRodney W. Grimes #define N_RELOFF(ex) \ 95*26f9a767SRodney W. Grimes N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data) 966cda32c0SRodney W. Grimes 976cda32c0SRodney W. Grimes /* Symbol table offset. */ 986cda32c0SRodney W. Grimes #define N_SYMOFF(ex) \ 99*26f9a767SRodney W. Grimes (N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize) 1006cda32c0SRodney W. Grimes 1016cda32c0SRodney W. Grimes /* String table offset. */ 1026cda32c0SRodney W. Grimes #define N_STROFF(ex) (N_SYMOFF(ex) + (ex).a_syms) 1036cda32c0SRodney W. Grimes 104*26f9a767SRodney W. Grimes /* 105*26f9a767SRodney W. Grimes * Header prepended to each a.out file. 106*26f9a767SRodney W. Grimes * only manipulate the a_midmag field via the 107*26f9a767SRodney W. Grimes * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h 108*26f9a767SRodney W. Grimes */ 109*26f9a767SRodney W. Grimes 1106cda32c0SRodney W. Grimes struct exec { 111*26f9a767SRodney W. Grimes unsigned long a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */ 112*26f9a767SRodney W. Grimes unsigned long a_text; /* text segment size */ 113*26f9a767SRodney W. Grimes unsigned long a_data; /* initialized data size */ 114*26f9a767SRodney W. Grimes unsigned long a_bss; /* uninitialized data size */ 115*26f9a767SRodney W. Grimes unsigned long a_syms; /* symbol table size */ 116*26f9a767SRodney W. Grimes unsigned long a_entry; /* entry point */ 117*26f9a767SRodney W. Grimes unsigned long a_trsize; /* text relocation size */ 118*26f9a767SRodney W. Grimes unsigned long a_drsize; /* data relocation size */ 119*26f9a767SRodney W. Grimes }; 120*26f9a767SRodney W. Grimes #define a_magic a_midmag /* XXX Hack to work with current kern_execve.c */ 121*26f9a767SRodney W. Grimes 122*26f9a767SRodney W. Grimes /* a_magic */ 1236cda32c0SRodney W. Grimes #define OMAGIC 0407 /* old impure format */ 1246cda32c0SRodney W. Grimes #define NMAGIC 0410 /* read-only text */ 1256cda32c0SRodney W. Grimes #define ZMAGIC 0413 /* demand load format */ 126*26f9a767SRodney W. Grimes #define QMAGIC 0314 /* "compact" demand load format */ 1276cda32c0SRodney W. Grimes 128*26f9a767SRodney W. Grimes #endif /* !_EXEC_H_ */ 129