xref: /freebsd/sys/i386/include/exec.h (revision 26f9a767)
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 
3626f9a767SRodney W. Grimes #ifndef	_EXEC_H_
3726f9a767SRodney W. Grimes #define	_EXEC_H_
3826f9a767SRodney 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) \
4326f9a767SRodney W. Grimes 	(N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \
4426f9a767SRodney W. Grimes 	 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \
4526f9a767SRodney W. Grimes 	 N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \
4626f9a767SRodney W. Grimes 	 N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC)
4726f9a767SRodney W. Grimes 
4826f9a767SRodney W. Grimes #define N_ALIGN(ex,x) \
4926f9a767SRodney W. Grimes 	(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \
5026f9a767SRodney W. Grimes 	 N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \
5126f9a767SRodney W. Grimes 	 ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
526cda32c0SRodney W. Grimes 
536cda32c0SRodney W. Grimes /* Address of the bottom of the text segment. */
5426f9a767SRodney W. Grimes #define N_TXTADDR(ex) \
5526f9a767SRodney W. Grimes 	((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \
5626f9a767SRodney 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) \
6026f9a767SRodney W. Grimes 	N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text)
6126f9a767SRodney W. Grimes 
6226f9a767SRodney W. Grimes #define N_GETMAGIC(ex) \
6326f9a767SRodney W. Grimes 	( (ex).a_midmag & 0xffff )
6426f9a767SRodney W. Grimes #define N_GETMID(ex) \
6526f9a767SRodney W. Grimes 	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \
6626f9a767SRodney W. Grimes 	((ex).a_midmag >> 16) & 0x03ff )
6726f9a767SRodney W. Grimes #define N_GETFLAG(ex) \
6826f9a767SRodney W. Grimes 	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \
6926f9a767SRodney W. Grimes 	((ex).a_midmag >> 26) & 0x3f )
7026f9a767SRodney W. Grimes #define N_SETMAGIC(ex,mag,mid,flag) \
7126f9a767SRodney W. Grimes 	( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \
7226f9a767SRodney W. Grimes 	((mag) & 0xffff) )
7326f9a767SRodney W. Grimes 
7426f9a767SRodney W. Grimes #define N_GETMAGIC_NET(ex) \
7526f9a767SRodney W. Grimes 	(ntohl((ex).a_midmag) & 0xffff)
7626f9a767SRodney W. Grimes #define N_GETMID_NET(ex) \
7726f9a767SRodney W. Grimes 	((ntohl((ex).a_midmag) >> 16) & 0x03ff)
7826f9a767SRodney W. Grimes #define N_GETFLAG_NET(ex) \
7926f9a767SRodney W. Grimes 	((ntohl((ex).a_midmag) >> 26) & 0x3f)
8026f9a767SRodney W. Grimes #define N_SETMAGIC_NET(ex,mag,mid,flag) \
8126f9a767SRodney W. Grimes 	( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
8226f9a767SRodney W. Grimes 	(((mag)&0xffff)) ) )
836cda32c0SRodney W. Grimes 
846cda32c0SRodney W. Grimes /* Text segment offset. */
856cda32c0SRodney W. Grimes #define	N_TXTOFF(ex) \
8626f9a767SRodney W. Grimes 	(N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \
8726f9a767SRodney 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) \
9126f9a767SRodney W. Grimes 	N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
9226f9a767SRodney W. Grimes 
9326f9a767SRodney W. Grimes /* Relocation table offset. */
9426f9a767SRodney W. Grimes #define N_RELOFF(ex) \
9526f9a767SRodney 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) \
9926f9a767SRodney 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 
10426f9a767SRodney W. Grimes /*
10526f9a767SRodney W. Grimes  * Header prepended to each a.out file.
10626f9a767SRodney W. Grimes  * only manipulate the a_midmag field via the
10726f9a767SRodney W. Grimes  * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h
10826f9a767SRodney W. Grimes  */
10926f9a767SRodney W. Grimes 
1106cda32c0SRodney W. Grimes struct exec {
11126f9a767SRodney W. Grimes unsigned long  a_midmag;   /* htonl(flags<<26 | mid<<16 | magic) */
11226f9a767SRodney W. Grimes unsigned long	a_text;		/* text segment size */
11326f9a767SRodney W. Grimes unsigned long	a_data;		/* initialized data size */
11426f9a767SRodney W. Grimes unsigned long	a_bss;		/* uninitialized data size */
11526f9a767SRodney W. Grimes unsigned long	a_syms;		/* symbol table size */
11626f9a767SRodney W. Grimes unsigned long	a_entry;	/* entry point */
11726f9a767SRodney W. Grimes unsigned long	a_trsize;	/* text relocation size */
11826f9a767SRodney W. Grimes unsigned long	a_drsize;	/* data relocation size */
11926f9a767SRodney W. Grimes };
12026f9a767SRodney W. Grimes #define a_magic a_midmag /* XXX Hack to work with current kern_execve.c */
12126f9a767SRodney W. Grimes 
12226f9a767SRodney 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 */
12626f9a767SRodney W. Grimes #define QMAGIC          0314    /* "compact" demand load format */
1276cda32c0SRodney W. Grimes 
12826f9a767SRodney W. Grimes #endif /* !_EXEC_H_ */
129