xref: /netbsd/sys/sys/exec_aout.h (revision bf9ec67e)
1 /*	$NetBSD: exec_aout.h,v 1.27 2001/08/16 05:06:35 matt Exp $	*/
2 
3 /*
4  * Copyright (c) 1993, 1994 Christopher G. Demetriou
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Christopher G. Demetriou.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _SYS_EXEC_AOUT_H_
34 #define _SYS_EXEC_AOUT_H_
35 
36 #ifndef N_PAGSIZ
37 #define	N_PAGSIZ(ex)	(__LDPGSZ)
38 #endif
39 
40 /*
41  * Header prepended to each a.out file.
42  * only manipulate the a_midmag field via the
43  * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below.
44  */
45 struct exec {
46 	u_long	a_midmag;	/* htonl(flags<<26 | mid<<16 | magic) */
47 	u_long	a_text;		/* text segment size */
48 	u_long	a_data;		/* initialized data size */
49 	u_long	a_bss;		/* uninitialized data size */
50 	u_long	a_syms;		/* symbol table size */
51 	u_long	a_entry;	/* entry point */
52 	u_long	a_trsize;	/* text relocation size */
53 	u_long	a_drsize;	/* data relocation size */
54 };
55 
56 /* a_magic */
57 #define	OMAGIC		0407	/* old impure format */
58 #define	NMAGIC		0410	/* read-only text */
59 #define	ZMAGIC		0413	/* demand load format */
60 #define	QMAGIC		0314	/* "compact" demand load format; deprecated */
61 
62 /*
63  * a_mid - keep sorted in numerical order for sanity's sake
64  * ensure that: 0 < mid < 0x3ff
65  */
66 #define	MID_ZERO	0	/* unknown - implementation dependent */
67 #define	MID_SUN010	1	/* sun 68010/68020 binary */
68 #define	MID_SUN020	2	/* sun 68020-only binary */
69 #define	MID_PC386	100	/* 386 PC binary. (so quoth BFD) */
70 #define	MID_HP200	200	/* hp200 (68010) BSD binary */
71 #define	MID_I386	134	/* i386 BSD binary */
72 #define	MID_M68K	135	/* m68k BSD binary with 8K page sizes */
73 #define	MID_M68K4K	136	/* m68k BSD binary with 4K page sizes */
74 #define	MID_NS32532	137	/* ns32532 */
75 #define	MID_SPARC	138	/* sparc */
76 #define	MID_PMAX	139	/* pmax */
77 #define	MID_VAX1K	140	/* vax 1K page size binaries */
78 #define	MID_ALPHA	141	/* Alpha BSD binary */
79 #define	MID_MIPS	142	/* big-endian MIPS */
80 #define	MID_ARM6	143	/* ARM6 */
81 #define	MID_M680002K	144	/* m68000 with 2K page sizes */
82 #define	MID_SH3		145	/* SH3 */
83 #define	MID_POWERPC	149	/* big-endian PowerPC */
84 #define	MID_VAX		150	/* vax */
85 #define	MID_SPARC64	151	/* LP64 sparc */
86 #define	MID_X86_64	152	/* AMD x86-64 */
87 #define	MID_M88K	153	/* m88k BSD core dumps */
88 #define	MID_HP300	300	/* hp300 (68020+68881) BSD binary */
89 #define	MID_HPUX	0x20C	/* hp200/300 HP-UX binary */
90 #define	MID_HPUX800     0x20B   /* hp800 HP-UX binary */
91 
92 /*
93  * a_flags
94  */
95 #define	EX_DYNAMIC	0x20
96 #define	EX_PIC		0x10
97 #define	EX_DPMASK	0x30
98 /*
99  * Interpretation of the (a_flags & EX_DPMASK) bits:
100  *
101  *	00		traditional executable or object file
102  *	01		object file contains PIC code (set by `as -k')
103  *	10		dynamic executable
104  *	11		position independent executable image
105  * 			(eg. a shared library)
106  *
107  */
108 
109 /*
110  * The a.out structure's a_midmag field is a network-byteorder encoding
111  * of this int
112  *	FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
113  * Where `F' is 6 bits of flag like EX_DYNAMIC,
114  *       `m' is 10 bits of machine-id like MID_I386, and
115  *       `M' is 16 bits worth of magic number, ie. ZMAGIC.
116  * The macros below will set/get the needed fields.
117  */
118 #define	N_GETMAGIC(ex) \
119     ((((ex).a_midmag)&0xffff0000) ? \
120     (ntohl((u_int32_t)((ex).a_midmag))&0xffff) : ((ex).a_midmag))
121 #define	N_GETMAGIC2(ex) \
122     ((((ex).a_midmag)&0xffff0000) ? \
123     (ntohl((u_int32_t)((ex).a_midmag))&0xffff) : (((ex).a_midmag) | 0x10000))
124 #define	N_GETMID(ex) \
125     ((((ex).a_midmag)&0xffff0000) ? \
126     ((ntohl((u_int32_t)((ex).a_midmag))>>16)&0x03ff) : MID_ZERO)
127 #define	N_GETFLAG(ex) \
128     ((((ex).a_midmag)&0xffff0000) ? \
129     ((ntohl((u_int32_t)((ex).a_midmag))>>26)&0x3f) : 0)
130 #define	N_SETMAGIC(ex,mag,mid,flag) \
131     ((ex).a_midmag = htonl((u_int32_t) \
132     ((((flag)&0x3f)<<26)|(((mid)&0x03ff)<<16)|(((mag)&0xffff)))))
133 
134 #define	N_ALIGN(ex,x) \
135 	(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \
136 	((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
137 
138 /* Valid magic number check. */
139 #define	N_BADMAG(ex) \
140 	(N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
141 	N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC)
142 
143 /* Address of the bottom of the text segment. */
144 #define	N_TXTADDR(ex)	(N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ)
145 
146 /* Address of the bottom of the data segment. */
147 #define	N_DATADDR(ex) \
148 	(N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \
149 	(N_TXTADDR(ex) + (ex).a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1))
150 
151 /* Address of the bottom of the bss segment. */
152 #define	N_BSSADDR(ex) \
153 	(N_DATADDR(ex) + (ex).a_data)
154 
155 /* Text segment offset. */
156 #define	N_TXTOFF(ex) \
157 	( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
158 	0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \
159 	sizeof(struct exec)) )
160 
161 /* Data segment offset. */
162 #define	N_DATOFF(ex) \
163 	N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
164 
165 /* Text relocation table offset. */
166 #define	N_TRELOFF(ex) \
167 	(N_DATOFF(ex) + (ex).a_data)
168 
169 /* Data relocation table offset. */
170 #define	N_DRELOFF(ex) \
171 	(N_TRELOFF(ex) + (ex).a_trsize)
172 
173 /* Symbol table offset. */
174 #define	N_SYMOFF(ex) \
175 	(N_DRELOFF(ex) + (ex).a_drsize)
176 
177 /* String table offset. */
178 #define	N_STROFF(ex) \
179 	(N_SYMOFF(ex) + (ex).a_syms)
180 
181 #include <machine/aout_machdep.h>
182 
183 #ifdef _KERNEL
184 
185 /* the "a.out" format's entry in the exec switch */
186 int	exec_aout_makecmds __P((struct proc *, struct exec_package *));
187 
188 /* functions which prepare various a.out executable types */
189 /*
190  * MI portion
191  */
192 int	exec_aout_prep_zmagic __P((struct proc *, struct exec_package *));
193 int	exec_aout_prep_nmagic __P((struct proc *, struct exec_package *));
194 int	exec_aout_prep_omagic __P((struct proc *, struct exec_package *));
195 int	exec_aout_setup_stack __P((struct proc *, struct exec_package *));
196 
197 /* For compatibility modules */
198 int	exec_aout_prep_oldzmagic __P((struct proc *, struct exec_package *));
199 int	exec_aout_prep_oldnmagic __P((struct proc *, struct exec_package *));
200 int	exec_aout_prep_oldomagic __P((struct proc *, struct exec_package *));
201 
202 /*
203  * MD portion
204  */
205 int	cpu_exec_aout_makecmds __P((struct proc *, struct exec_package *));
206 
207 #endif /* _KERNEL */
208 
209 #endif /* !_SYS_EXEC_AOUT_H_ */
210