xref: /freebsd-12.1/sys/amd64/include/exec.h (revision 52cd4384)
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
34*52cd4384SJordan K. Hubbard  * $Id: exec.h,v 1.3 1994/08/02 07:38:45 davidg Exp $
356cda32c0SRodney W. Grimes  */
366cda32c0SRodney W. Grimes 
3726f9a767SRodney W. Grimes #ifndef	_EXEC_H_
3826f9a767SRodney W. Grimes #define	_EXEC_H_
3926f9a767SRodney W. Grimes 
40*52cd4384SJordan K. Hubbard #if defined(hp300) || defined(i386)
416cda32c0SRodney W. Grimes #define	__LDPGSZ	4096
42*52cd4384SJordan K. Hubbard #endif
43*52cd4384SJordan K. Hubbard #if defined(tahoe) || defined(vax)
44*52cd4384SJordan K. Hubbard #define	__LDPGSZ	1024
45*52cd4384SJordan K. Hubbard #endif
4626f9a767SRodney W. Grimes 
4726f9a767SRodney W. Grimes #define N_GETMAGIC(ex) \
4826f9a767SRodney W. Grimes 	( (ex).a_midmag & 0xffff )
4926f9a767SRodney W. Grimes #define N_GETMID(ex) \
5026f9a767SRodney W. Grimes 	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \
5126f9a767SRodney W. Grimes 	((ex).a_midmag >> 16) & 0x03ff )
5226f9a767SRodney W. Grimes #define N_GETFLAG(ex) \
5326f9a767SRodney W. Grimes 	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \
5426f9a767SRodney W. Grimes 	((ex).a_midmag >> 26) & 0x3f )
5526f9a767SRodney W. Grimes #define N_SETMAGIC(ex,mag,mid,flag) \
5626f9a767SRodney W. Grimes 	( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \
5726f9a767SRodney W. Grimes 	((mag) & 0xffff) )
5826f9a767SRodney W. Grimes 
5926f9a767SRodney W. Grimes #define N_GETMAGIC_NET(ex) \
6026f9a767SRodney W. Grimes 	(ntohl((ex).a_midmag) & 0xffff)
6126f9a767SRodney W. Grimes #define N_GETMID_NET(ex) \
6226f9a767SRodney W. Grimes 	((ntohl((ex).a_midmag) >> 16) & 0x03ff)
6326f9a767SRodney W. Grimes #define N_GETFLAG_NET(ex) \
6426f9a767SRodney W. Grimes 	((ntohl((ex).a_midmag) >> 26) & 0x3f)
6526f9a767SRodney W. Grimes #define N_SETMAGIC_NET(ex,mag,mid,flag) \
6626f9a767SRodney W. Grimes 	( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
6726f9a767SRodney W. Grimes 	(((mag)&0xffff)) ) )
686cda32c0SRodney W. Grimes 
69*52cd4384SJordan K. Hubbard #define N_ALIGN(ex,x) \
70*52cd4384SJordan K. Hubbard 	(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \
71*52cd4384SJordan K. Hubbard 	 N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \
72*52cd4384SJordan K. Hubbard 	 ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
73*52cd4384SJordan K. Hubbard 
74*52cd4384SJordan K. Hubbard /* Valid magic number check. */
75*52cd4384SJordan K. Hubbard #define	N_BADMAG(ex) \
76*52cd4384SJordan K. Hubbard 	(N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \
77*52cd4384SJordan K. Hubbard 	 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \
78*52cd4384SJordan K. Hubbard 	 N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \
79*52cd4384SJordan K. Hubbard 	 N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC)
80*52cd4384SJordan K. Hubbard 
81*52cd4384SJordan K. Hubbard 
82*52cd4384SJordan K. Hubbard /* Address of the bottom of the text segment. */
83*52cd4384SJordan K. Hubbard #define N_TXTADDR(ex) \
84*52cd4384SJordan K. Hubbard 	((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \
85*52cd4384SJordan K. Hubbard 	N_GETMAGIC(ex) == ZMAGIC) ? 0 : __LDPGSZ)
86*52cd4384SJordan K. Hubbard 
87*52cd4384SJordan K. Hubbard /* Address of the bottom of the data segment. */
88*52cd4384SJordan K. Hubbard #define N_DATADDR(ex) \
89*52cd4384SJordan K. Hubbard 	N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text)
90*52cd4384SJordan K. Hubbard 
916cda32c0SRodney W. Grimes /* Text segment offset. */
926cda32c0SRodney W. Grimes #define	N_TXTOFF(ex) \
9326f9a767SRodney W. Grimes 	(N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \
9426f9a767SRodney W. Grimes 	N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec))
956cda32c0SRodney W. Grimes 
966cda32c0SRodney W. Grimes /* Data segment offset. */
976cda32c0SRodney W. Grimes #define	N_DATOFF(ex) \
9826f9a767SRodney W. Grimes 	N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
9926f9a767SRodney W. Grimes 
10026f9a767SRodney W. Grimes /* Relocation table offset. */
10126f9a767SRodney W. Grimes #define N_RELOFF(ex) \
10226f9a767SRodney W. Grimes 	N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data)
1036cda32c0SRodney W. Grimes 
1046cda32c0SRodney W. Grimes /* Symbol table offset. */
1056cda32c0SRodney W. Grimes #define N_SYMOFF(ex) \
10626f9a767SRodney W. Grimes 	(N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize)
1076cda32c0SRodney W. Grimes 
1086cda32c0SRodney W. Grimes /* String table offset. */
1096cda32c0SRodney W. Grimes #define	N_STROFF(ex) 	(N_SYMOFF(ex) + (ex).a_syms)
1106cda32c0SRodney W. Grimes 
11126f9a767SRodney W. Grimes /*
11226f9a767SRodney W. Grimes  * Header prepended to each a.out file.
11326f9a767SRodney W. Grimes  * only manipulate the a_midmag field via the
11426f9a767SRodney W. Grimes  * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h
11526f9a767SRodney W. Grimes  */
11626f9a767SRodney W. Grimes 
1176cda32c0SRodney W. Grimes struct exec {
11826f9a767SRodney W. Grimes      unsigned long  a_midmag;   /* htonl(flags<<26 | mid<<16 | magic) */
11926f9a767SRodney W. Grimes      unsigned long	a_text;		/* text segment size */
12026f9a767SRodney W. Grimes      unsigned long	a_data;		/* initialized data size */
12126f9a767SRodney W. Grimes      unsigned long	a_bss;		/* uninitialized data size */
12226f9a767SRodney W. Grimes      unsigned long	a_syms;		/* symbol table size */
12326f9a767SRodney W. Grimes      unsigned long	a_entry;	/* entry point */
12426f9a767SRodney W. Grimes      unsigned long	a_trsize;	/* text relocation size */
12526f9a767SRodney W. Grimes      unsigned long	a_drsize;	/* data relocation size */
12626f9a767SRodney W. Grimes };
12726f9a767SRodney W. Grimes #define a_magic a_midmag /* XXX Hack to work with current kern_execve.c */
12826f9a767SRodney W. Grimes 
12926f9a767SRodney W. Grimes /* a_magic */
1306cda32c0SRodney W. Grimes #define	OMAGIC		0407	/* old impure format */
1316cda32c0SRodney W. Grimes #define	NMAGIC		0410	/* read-only text */
1326cda32c0SRodney W. Grimes #define	ZMAGIC		0413	/* demand load format */
13326f9a767SRodney W. Grimes #define QMAGIC          0314    /* "compact" demand load format */
1346cda32c0SRodney W. Grimes 
135*52cd4384SJordan K. Hubbard /* a_mid */
136*52cd4384SJordan K. Hubbard #define	MID_ZERO	0	/* unknown - implementation dependent */
137*52cd4384SJordan K. Hubbard #define	MID_SUN010	1	/* sun 68010/68020 binary */
138*52cd4384SJordan K. Hubbard #define	MID_SUN020	2	/* sun 68020-only binary */
139*52cd4384SJordan K. Hubbard #define MID_I386	134	/* i386 BSD binary */
140*52cd4384SJordan K. Hubbard #define	MID_HP200	200	/* hp200 (68010) BSD binary */
141*52cd4384SJordan K. Hubbard #define	MID_HP300	300	/* hp300 (68020+68881) BSD binary */
142*52cd4384SJordan K. Hubbard #define	MID_HPUX	0x20C	/* hp200/300 HP-UX binary */
143*52cd4384SJordan K. Hubbard #define	MID_HPUX800     0x20B   /* hp800 HP-UX binary */
144*52cd4384SJordan K. Hubbard 
145*52cd4384SJordan K. Hubbard /*
146*52cd4384SJordan K. Hubbard  * a_flags
147*52cd4384SJordan K. Hubbard  */
148*52cd4384SJordan K. Hubbard #define EX_DYNAMIC   0x20  /* a.out contains run-time link-edit info */
149*52cd4384SJordan K. Hubbard 
15026f9a767SRodney W. Grimes #endif /* !_EXEC_H_ */
151