xref: /dragonfly/sys/sys/imgact_aout.h (revision 6a3cbbc2)
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. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	from: @(#)exec.h	8.1 (Berkeley) 6/11/93
30  * $FreeBSD: src/sys/sys/imgact_aout.h,v 1.13 1999/12/29 04:24:41 peter Exp $
31  * $DragonFly: src/sys/sys/imgact_aout.h,v 1.6 2007/02/03 09:56:04 y0netan1 Exp $
32  */
33 
34 #ifndef	_IMGACT_AOUT_H_
35 #define	_IMGACT_AOUT_H_
36 
37 #ifndef _SYS_TYPES_H_
38 #include <sys/types.h>
39 #endif
40 
41 #define N_GETMAGIC(ex) \
42 	( (ex).a_midmag & 0xffff )
43 #define N_GETMID(ex) \
44 	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \
45 	((ex).a_midmag >> 16) & 0x03ff )
46 #define N_GETFLAG(ex) \
47 	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \
48 	((ex).a_midmag >> 26) & 0x3f )
49 #define N_SETMAGIC(ex,mag,mid,flag) \
50 	( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \
51 	((mag) & 0xffff) )
52 
53 #define N_GETMAGIC_NET(ex) \
54 	(ntohl((ex).a_midmag) & 0xffff)
55 #define N_GETMID_NET(ex) \
56 	((ntohl((ex).a_midmag) >> 16) & 0x03ff)
57 #define N_GETFLAG_NET(ex) \
58 	((ntohl((ex).a_midmag) >> 26) & 0x3f)
59 #define N_SETMAGIC_NET(ex,mag,mid,flag) \
60 	( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
61 	(((mag)&0xffff)) ) )
62 
63 #define N_ALIGN(ex,x) \
64 	(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \
65 	 N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \
66 	 ((x) + __LDPGSZ - 1) & ~(unsigned long)(__LDPGSZ - 1) : (x))
67 
68 /* Valid magic number check. */
69 #define	N_BADMAG(ex) \
70 	(N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \
71 	 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \
72 	 N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \
73 	 N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC)
74 
75 
76 /* Address of the bottom of the text segment. */
77 /*
78  * This can not be done right.  Abuse a_entry in some cases to handle kernels.
79  */
80 #define N_TXTADDR(ex) \
81 	((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \
82 	N_GETMAGIC(ex) == ZMAGIC) ? \
83 	((ex).a_entry < (ex).a_text ? 0 : (ex).a_entry & ~__LDPGSZ) : __LDPGSZ)
84 
85 /* Address of the bottom of the data segment. */
86 #define N_DATADDR(ex) \
87 	N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text)
88 
89 /* Text segment offset. */
90 #define	N_TXTOFF(ex) \
91 	(N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \
92 	N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec))
93 
94 /* Data segment offset. */
95 #define	N_DATOFF(ex) \
96 	N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
97 
98 /* Relocation table offset. */
99 #define N_RELOFF(ex) \
100 	N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data)
101 
102 /* Symbol table offset. */
103 #define N_SYMOFF(ex) \
104 	(N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize)
105 
106 /* String table offset. */
107 #define	N_STROFF(ex) 	(N_SYMOFF(ex) + (ex).a_syms)
108 
109 /*
110  * Header prepended to each a.out file.
111  * only manipulate the a_midmag field via the
112  * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h
113  *
114  * AOUT_H_FORCE32 is used by btxld and sys/boot when compiling
115  * from a 64 bit environment to generate a 32 bit a.out.h header.
116  */
117 
118 #ifdef AOUT_H_FORCE32
119 typedef u_int32_t	aout_register_t;
120 #else
121 typedef unsigned long	aout_register_t;
122 #endif
123 
124 struct exec {
125      aout_register_t	a_midmag;	/* flags<<26 | mid<<16 | magic */
126      aout_register_t	a_text;		/* text segment size */
127      aout_register_t	a_data;		/* initialized data size */
128      aout_register_t	a_bss;		/* uninitialized data size */
129      aout_register_t	a_syms;		/* symbol table size */
130      aout_register_t	a_entry;	/* entry point */
131      aout_register_t	a_trsize;	/* text relocation size */
132      aout_register_t	a_drsize;	/* data relocation size */
133 };
134 #define a_magic a_midmag /* XXX Hack to work with current kern_execve.c */
135 
136 /* a_magic */
137 #define	OMAGIC		0407	/* old impure format */
138 #define	NMAGIC		0410	/* read-only text */
139 #define	ZMAGIC		0413	/* demand load format */
140 #define QMAGIC          0314    /* "compact" demand load format */
141 
142 /* a_mid */
143 #define	MID_ZERO	0	/* unknown - implementation dependent */
144 #define	MID_SUN010	1	/* sun 68010/68020 binary */
145 #define	MID_SUN020	2	/* sun 68020-only binary */
146 #define MID_I386	134	/* i386 BSD binary */
147 #define MID_SPARC	138	/* sparc */
148 #define	MID_HP200	200	/* hp200 (68010) BSD binary */
149 #define	MID_HP300	300	/* hp300 (68020+68881) BSD binary */
150 #define	MID_HPUX	0x20C	/* hp200/300 HP-UX binary */
151 #define	MID_HPUX800     0x20B   /* hp800 HP-UX binary */
152 
153 /*
154  * a_flags
155  */
156 #define EX_PIC		0x10	/* contains position independent code */
157 #define EX_DYNAMIC	0x20	/* contains run-time link-edit info */
158 #define EX_DPMASK	0x30	/* mask for the above */
159 
160 #ifdef _KERNEL
161 struct proc;
162 struct vnode;
163 #endif
164 
165 #endif /* !_IMGACT_AOUT_H_ */
166