root / lab4 / .minix-src / include / sys / exec_aout.h @ 14
History | View | Annotate | Download (6.13 KB)
1 |
/* $NetBSD: exec_aout.h,v 1.40 2012/03/17 21:54:12 martin 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) (AOUT_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 |
#include <sys/aout_mids.h> |
63 |
|
64 |
/*
|
65 |
* a_flags
|
66 |
*/
|
67 |
#define EX_DYNAMIC 0x20 |
68 |
#define EX_PIC 0x10 |
69 |
#define EX_DPMASK 0x30 |
70 |
/*
|
71 |
* Interpretation of the (a_flags & EX_DPMASK) bits:
|
72 |
*
|
73 |
* 00 traditional executable or object file
|
74 |
* 01 object file contains PIC code (set by `as -k')
|
75 |
* 10 dynamic executable
|
76 |
* 11 position independent executable image
|
77 |
* (eg. a shared library)
|
78 |
*
|
79 |
*/
|
80 |
|
81 |
/*
|
82 |
* The a.out structure's a_midmag field is a network-byteorder encoding
|
83 |
* of this int
|
84 |
* FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
|
85 |
* Where `F' is 6 bits of flag like EX_DYNAMIC,
|
86 |
* `m' is 10 bits of machine-id like MID_I386, and
|
87 |
* `M' is 16 bits worth of magic number, ie. ZMAGIC.
|
88 |
* The macros below will set/get the needed fields.
|
89 |
*/
|
90 |
#define N_GETMAGIC(ex) \
|
91 |
((((uint32_t)(ex).a_midmag)&0xffff0000) ? \
|
92 |
(be32toh((uint32_t)((ex).a_midmag))&0xffff) : ((ex).a_midmag))
|
93 |
#define N_GETMAGIC2(ex) \
|
94 |
((((uint32_t)(ex).a_midmag)&0xffff0000) ? \
|
95 |
(be32toh((uint32_t)((ex).a_midmag))&0xffff) : (((ex).a_midmag) | 0x10000)) |
96 |
#define N_GETMID(ex) \
|
97 |
((((uint32_t)(ex).a_midmag)&0xffff0000) ? \
|
98 |
((be32toh((uint32_t)((ex).a_midmag))>>16)&0x03ff) : MID_ZERO) |
99 |
#define N_GETFLAG(ex) \
|
100 |
((((uint32_t)(ex).a_midmag)&0xffff0000) ? \
|
101 |
((be32toh((uint32_t)((ex).a_midmag))>>26)&0x3f) : 0) |
102 |
#define N_SETMAGIC(ex,mag,mid,flag) \
|
103 |
((ex).a_midmag = htobe32((uint32_t) \ |
104 |
((((flag)&0x3f)<<26)|(((mid)&0x03ff)<<16)|(((mag)&0xffff))))) |
105 |
|
106 |
#define N_ALIGN(ex,x) \
|
107 |
(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \ |
108 |
((x) + AOUT_LDPGSZ - 1) & ~(AOUT_LDPGSZ - 1) : (x)) |
109 |
|
110 |
/* Valid magic number check. */
|
111 |
#define N_BADMAG(ex) \
|
112 |
(N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \ |
113 |
N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC) |
114 |
|
115 |
/* Address of the bottom of the text segment. */
|
116 |
#define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : AOUT_LDPGSZ) |
117 |
|
118 |
/* Address of the bottom of the data segment. */
|
119 |
#define N_DATADDR(ex) \
|
120 |
(N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \ |
121 |
(N_TXTADDR(ex) + (ex).a_text + AOUT_LDPGSZ - 1) & ~(AOUT_LDPGSZ - 1)) |
122 |
|
123 |
/* Address of the bottom of the bss segment. */
|
124 |
#define N_BSSADDR(ex) \
|
125 |
(N_DATADDR(ex) + (ex).a_data) |
126 |
|
127 |
/* Text segment offset. */
|
128 |
#define N_TXTOFF(ex) \
|
129 |
( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
|
130 |
0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? AOUT_LDPGSZ : \ |
131 |
sizeof(struct exec)) ) |
132 |
|
133 |
/* Data segment offset. */
|
134 |
#define N_DATOFF(ex) \
|
135 |
N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text) |
136 |
|
137 |
/* Text relocation table offset. */
|
138 |
#define N_TRELOFF(ex) \
|
139 |
(N_DATOFF(ex) + (ex).a_data) |
140 |
|
141 |
/* Data relocation table offset. */
|
142 |
#define N_DRELOFF(ex) \
|
143 |
(N_TRELOFF(ex) + (ex).a_trsize) |
144 |
|
145 |
/* Symbol table offset. */
|
146 |
#define N_SYMOFF(ex) \
|
147 |
(N_DRELOFF(ex) + (ex).a_drsize) |
148 |
|
149 |
/* String table offset. */
|
150 |
#define N_STROFF(ex) \
|
151 |
(N_SYMOFF(ex) + (ex).a_syms) |
152 |
|
153 |
#include <machine/aout_machdep.h> |
154 |
|
155 |
#ifdef _KERNEL
|
156 |
|
157 |
/* the "a.out" format's entry in the exec switch */
|
158 |
int exec_aout_makecmds(struct lwp *, struct exec_package *); |
159 |
|
160 |
/* functions which prepare various a.out executable types */
|
161 |
/*
|
162 |
* MI portion
|
163 |
*/
|
164 |
int exec_aout_prep_zmagic(struct lwp *, struct exec_package *); |
165 |
int exec_aout_prep_nmagic(struct lwp *, struct exec_package *); |
166 |
int exec_aout_prep_omagic(struct lwp *, struct exec_package *); |
167 |
|
168 |
/* For compatibility modules */
|
169 |
int exec_aout_prep_oldzmagic(struct lwp *, struct exec_package *); |
170 |
int exec_aout_prep_oldnmagic(struct lwp *, struct exec_package *); |
171 |
int exec_aout_prep_oldomagic(struct lwp *, struct exec_package *); |
172 |
|
173 |
/*
|
174 |
* MD portion
|
175 |
*/
|
176 |
#ifndef cpu_exec_aout_makecmds
|
177 |
int cpu_exec_aout_makecmds(struct lwp *, struct exec_package *); |
178 |
#endif
|
179 |
|
180 |
#endif /* _KERNEL */ |
181 |
|
182 |
#endif /* !_SYS_EXEC_AOUT_H_ */ |