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