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