1 /* $NetBSD: exec_aout.h,v 1.33 2004/02/11 01:03:35 matt Exp $ */
4 * Copyright (c) 1993, 1994 Christopher G. Demetriou
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
33 #ifndef _SYS_EXEC_AOUT_H_
34 #define _SYS_EXEC_AOUT_H_
37 #define N_PAGSIZ(ex) (AOUT_LDPGSZ)
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.
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 */
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 */
63 * a_mid - keep sorted in numerical order for sanity's sake
64 * ensure that: 0 < mid < 0x3ff
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 */
87 #define MID_M88K 153 /* m88k BSD */
88 #define MID_HPPA 154 /* HP PARISC */
89 #define MID_SH5_64 155 /* LP64 SH5 */
90 #define MID_SPARC64 156 /* LP64 sparc */
91 #define MID_X86_64 157 /* AMD x86-64 */
92 #define MID_SH5_32 158 /* ILP32 SH5 */
93 #define MID_HP200 200 /* hp200 (68010) BSD binary */
94 #define MID_HP300 300 /* hp300 (68020+68881) BSD binary */
95 #define MID_HPUX 0x20C /* hp200/300 HP-UX binary */
96 #define MID_HPUX800 0x20B /* hp800 HP-UX binary */
101 #define EX_DYNAMIC 0x20
103 #define EX_DPMASK 0x30
105 * Interpretation of the (a_flags & EX_DPMASK) bits:
107 * 00 traditional executable or object file
108 * 01 object file contains PIC code (set by `as -k')
109 * 10 dynamic executable
110 * 11 position independent executable image
111 * (eg. a shared library)
116 * The a.out structure's a_midmag field is a network-byteorder encoding
118 * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
119 * Where `F' is 6 bits of flag like EX_DYNAMIC,
120 * `m' is 10 bits of machine-id like MID_I386, and
121 * `M' is 16 bits worth of magic number, ie. ZMAGIC.
122 * The macros below will set/get the needed fields.
124 #define N_GETMAGIC(ex) \
125 ((((ex).a_midmag)&0xffff0000) ? \
126 (ntohl((u_int32_t)((ex).a_midmag))&0xffff) : ((ex).a_midmag))
127 #define N_GETMAGIC2(ex) \
128 ((((ex).a_midmag)&0xffff0000) ? \
129 (ntohl((u_int32_t)((ex).a_midmag))&0xffff) : (((ex).a_midmag) | 0x10000))
130 #define N_GETMID(ex) \
131 ((((ex).a_midmag)&0xffff0000) ? \
132 ((ntohl((u_int32_t)((ex).a_midmag))>>16)&0x03ff) : MID_ZERO)
133 #define N_GETFLAG(ex) \
134 ((((ex).a_midmag)&0xffff0000) ? \
135 ((ntohl((u_int32_t)((ex).a_midmag))>>26)&0x3f) : 0)
136 #define N_SETMAGIC(ex,mag,mid,flag) \
137 ((ex).a_midmag = htonl((u_int32_t) \
138 ((((flag)&0x3f)<<26)|(((mid)&0x03ff)<<16)|(((mag)&0xffff)))))
140 #define N_ALIGN(ex,x) \
141 (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \
142 ((x) + AOUT_LDPGSZ - 1) & ~(AOUT_LDPGSZ - 1) : (x))
144 /* Valid magic number check. */
145 #define N_BADMAG(ex) \
146 (N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
147 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC)
149 /* Address of the bottom of the text segment. */
150 #define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : AOUT_LDPGSZ)
152 /* Address of the bottom of the data segment. */
153 #define N_DATADDR(ex) \
154 (N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \
155 (N_TXTADDR(ex) + (ex).a_text + AOUT_LDPGSZ - 1) & ~(AOUT_LDPGSZ - 1))
157 /* Address of the bottom of the bss segment. */
158 #define N_BSSADDR(ex) \
159 (N_DATADDR(ex) + (ex).a_data)
161 /* Text segment offset. */
162 #define N_TXTOFF(ex) \
163 ( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
164 0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? AOUT_LDPGSZ : \
165 sizeof(struct exec)) )
167 /* Data segment offset. */
168 #define N_DATOFF(ex) \
169 N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
171 /* Text relocation table offset. */
172 #define N_TRELOFF(ex) \
173 (N_DATOFF(ex) + (ex).a_data)
175 /* Data relocation table offset. */
176 #define N_DRELOFF(ex) \
177 (N_TRELOFF(ex) + (ex).a_trsize)
179 /* Symbol table offset. */
180 #define N_SYMOFF(ex) \
181 (N_DRELOFF(ex) + (ex).a_drsize)
183 /* String table offset. */
184 #define N_STROFF(ex) \
185 (N_SYMOFF(ex) + (ex).a_syms)
187 #include <machine/aout_machdep.h>
191 /* the "a.out" format's entry in the exec switch */
192 int exec_aout_makecmds
__P((struct proc
*, struct exec_package
*));
194 /* functions which prepare various a.out executable types */
198 int exec_aout_prep_zmagic
__P((struct proc
*, struct exec_package
*));
199 int exec_aout_prep_nmagic
__P((struct proc
*, struct exec_package
*));
200 int exec_aout_prep_omagic
__P((struct proc
*, struct exec_package
*));
202 /* For compatibility modules */
203 int exec_aout_prep_oldzmagic
__P((struct proc
*, struct exec_package
*));
204 int exec_aout_prep_oldnmagic
__P((struct proc
*, struct exec_package
*));
205 int exec_aout_prep_oldomagic
__P((struct proc
*, struct exec_package
*));
210 int cpu_exec_aout_makecmds
__P((struct proc
*, struct exec_package
*));
214 #endif /* !_SYS_EXEC_AOUT_H_ */