1 /* $OpenBSD: ibcs2_exec.h,v 1.3 2002/03/14 01:26:50 millert Exp $ */
2 /* $NetBSD: ibcs2_exec.h,v 1.4 1995/03/14 15:12:24 scottb Exp $ */
3
4 /*
5 * Copyright (c) 1994, 1995 Scott Bartram
6 * All rights reserved.
7 *
8 * adapted from sys/sys/exec_ecoff.h
9 * based on Intel iBCS2
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. 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 _IBCS2_EXEC_H_
35 #define _IBCS2_EXEC_H_
36
37 /*
38 * COFF file header
39 */
40
41 struct coff_filehdr {
42 u_short f_magic; /* magic number */
43 u_short f_nscns; /* # of sections */
44 long f_timdat; /* timestamp */
45 long f_symptr; /* file offset of symbol table */
46 long f_nsyms; /* # of symbol table entries */
47 u_short f_opthdr; /* size of optional header */
48 u_short f_flags; /* flags */
49 };
50
51 /* f_magic flags */
52 #define COFF_MAGIC_I386 0x14c
53
54 /* f_flags */
55 #define COFF_F_RELFLG 0x1
56 #define COFF_F_EXEC 0x2
57 #define COFF_F_LNNO 0x4
58 #define COFF_F_LSYMS 0x8
59 #define COFF_F_SWABD 0x40
60 #define COFF_F_AR16WR 0x80
61 #define COFF_F_AR32WR 0x100
62
63 /*
64 * COFF system header
65 */
66
67 struct coff_aouthdr {
68 short a_magic;
69 short a_vstamp;
70 long a_tsize;
71 long a_dsize;
72 long a_bsize;
73 long a_entry;
74 long a_tstart;
75 long a_dstart;
76 };
77
78 /* magic */
79 #define COFF_OMAGIC 0407 /* text not write-protected; data seg
80 is contiguous with text */
81 #define COFF_NMAGIC 0410 /* text is write-protected; data starts
82 at next seg following text */
83 #define COFF_ZMAGIC 0413 /* text and data segs are aligned for
84 direct paging */
85 #define COFF_SMAGIC 0443 /* shared lib */
86
87 /*
88 * COFF section header
89 */
90
91 struct coff_scnhdr {
92 char s_name[8];
93 long s_paddr;
94 long s_vaddr;
95 long s_size;
96 long s_scnptr;
97 long s_relptr;
98 long s_lnnoptr;
99 u_short s_nreloc;
100 u_short s_nlnno;
101 long s_flags;
102 };
103
104 /* s_flags */
105 #define COFF_STYP_REG 0x00
106 #define COFF_STYP_DSECT 0x01
107 #define COFF_STYP_NOLOAD 0x02
108 #define COFF_STYP_GROUP 0x04
109 #define COFF_STYP_PAD 0x08
110 #define COFF_STYP_COPY 0x10
111 #define COFF_STYP_TEXT 0x20
112 #define COFF_STYP_DATA 0x40
113 #define COFF_STYP_BSS 0x80
114 #define COFF_STYP_INFO 0x200
115 #define COFF_STYP_OVER 0x400
116 #define COFF_STYP_SHLIB 0x800
117
118 /*
119 * COFF shared library header
120 */
121
122 struct coff_slhdr {
123 long entry_len; /* in words */
124 long path_index; /* in words */
125 char sl_name[1];
126 };
127
128 #define COFF_ROUND(val, by) (((val) + by - 1) & ~(by - 1))
129
130 #define COFF_ALIGN(a) ((a) & ~(COFF_LDPGSZ - 1))
131
132 #define COFF_HDR_SIZE \
133 (sizeof(struct coff_filehdr) + sizeof(struct coff_aouthdr))
134
135 #define COFF_BLOCK_ALIGN(ap, value) \
136 (ap->a_magic == COFF_ZMAGIC ? COFF_ROUND(value, COFF_LDPGSZ) : \
137 value)
138
139 #define COFF_TXTOFF(fp, ap) \
140 (ap->a_magic == COFF_ZMAGIC ? 0 : \
141 COFF_ROUND(COFF_HDR_SIZE + fp->f_nscns * \
142 sizeof(struct coff_scnhdr), COFF_SEGMENT_ALIGNMENT(ap)))
143
144 #define COFF_DATOFF(fp, ap) \
145 (COFF_BLOCK_ALIGN(ap, COFF_TXTOFF(fp, ap) + ap->a_tsize))
146
147 #define COFF_SEGMENT_ALIGN(ap, value) \
148 (COFF_ROUND(value, (ap->a_magic == COFF_ZMAGIC ? COFF_LDPGSZ : \
149 COFF_SEGMENT_ALIGNMENT(ap))))
150
151 #define COFF_LDPGSZ 4096
152
153 #define COFF_SEGMENT_ALIGNMENT(ap) 4
154
155 #define COFF_BADMAG(ex) (ex->f_magic != COFF_MAGIC_I386)
156
157 #define IBCS2_HIGH_SYSCALL(n) (((n) & 0x7f) == 0x28)
158 #define IBCS2_CVT_HIGH_SYSCALL(n) (((n) >> 8) + 128)
159
160 struct exec_package;
161 int exec_ibcs2_coff_makecmds(struct proc *, struct exec_package *);
162
163 /*
164 * x.out (XENIX)
165 */
166
167 struct xexec {
168 u_short x_magic; /* magic number */
169 u_short x_ext; /* size of extended header */
170 long x_text; /* ignored */
171 long x_data; /* ignored */
172 long x_bss; /* ignored */
173 long x_syms; /* ignored */
174 long x_reloc; /* ignored */
175 long x_entry; /* executable entry point */
176 char x_cpu; /* processor type */
177 char x_relsym; /* ignored */
178 u_short x_renv; /* flags */
179 };
180
181 /* x_magic flags */
182 #define XOUT_MAGIC 0x0206
183
184 /* x_cpu flags */
185 #define XC_386 0x004a /* 386, word-swapped */
186
187 /* x_renv flags */
188 #define XE_V5 0xc000
189 #define XE_SEG 0x0800
190 #define XE_ABS 0x0400
191 #define XE_ITER 0x0200
192 #define XE_VMOD 0x0100
193 #define XE_FPH 0x0080
194 #define XE_LTEXT 0x0040
195 #define XE_LDATA 0x0020
196 #define XE_OVER 0x0010
197 #define XE_FS 0x0008
198 #define XE_PURE 0x0004
199 #define XE_SEP 0x0002
200 #define XE_EXEC 0x0001
201
202 /*
203 * x.out extended header
204 */
205
206 struct xext {
207 long xe_trsize; /* ignored */
208 long xe_drsize; /* ignored */
209 long xe_tbase; /* ignored */
210 long xe_dbase; /* ignored */
211 long xe_stksize; /* stack size if XE_FS set in x_renv */
212 long xe_segpos; /* offset of segment table */
213 long xe_segsize; /* segment table size */
214 long xe_mdtpos; /* ignored */
215 long xe_mdtsize; /* ignored */
216 char xe_mdttype; /* ignored */
217 char xe_pagesize; /* ignored */
218 char xe_ostype; /* ignored */
219 char xe_osvers; /* ignored */
220 u_short xe_eseg; /* ignored */
221 u_short xe_sres; /* ignored */
222 };
223
224 /*
225 * x.out segment table
226 */
227
228 struct xseg {
229 u_short xs_type; /* segment type */
230 u_short xs_attr; /* attribute flags */
231 u_short xs_seg; /* segment selector number */
232 char xs_align; /* ignored */
233 char xs_cres; /* ignored */
234 long xs_filpos; /* offset of this segment */
235 long xs_psize; /* physical segment size */
236 long xs_vsize; /* virtual segment size */
237 long xs_rbase; /* relocation base address */
238 u_short xs_noff; /* ignored */
239 u_short xs_sres; /* ignored */
240 long xs_lres; /* ignored */
241 };
242
243 /* xs_type flags */
244 #define XS_TNULL 0 /* unused */
245 #define XS_TTEXT 1 /* text (read-only) */
246 #define XS_TDATA 2 /* data (read-write) */
247 #define XS_TSYMS 3 /* symbol table (noload) */
248 #define XS_TREL 4 /* relocation segment (noload) */
249 #define XS_TSESTR 5 /* string table (noload) */
250 #define XS_TGRPS 6 /* group segment (noload) */
251
252 #define XS_TIDATA 64
253 #define XS_TTSS 65
254 #define XS_TLFIX 66
255 #define XS_TDNAME 67
256 #define XS_TDTEXT 68
257 #define XS_TDFIX 69
258 #define XS_TOVTAB 70
259 #define XS_T71 71
260 #define XS_TSYSTR 72
261
262 /* xs_attr flags */
263 #define XS_AMEM 0x8000 /* memory image */
264 #define XS_AITER 0x0001 /* iteration records */
265 #define XS_AHUGE 0x0002 /* unused */
266 #define XS_ABSS 0x0004 /* uninitialized data */
267 #define XS_APURE 0x0008 /* read-only (sharable) segment */
268 #define XS_AEDOWN 0x0010 /* expand down memory segment */
269 #define XS_APRIV 0x0020 /* unused */
270 #define XS_A32BIT 0x0040 /* 32-bit text/data */
271
272 /*
273 * x.out iteration record
274 */
275
276 struct xiter {
277 long xi_size; /* text/data size */
278 long xi_rep; /* number of replications */
279 long xi_offset; /* offset within segment to replicated data */
280 };
281
282 #define XOUT_HDR_SIZE (sizeof(struct xexec) + sizeof(struct xext))
283
284 int exec_ibcs2_xout_makecmds(struct proc *, struct exec_package *);
285
286 #endif /* !_IBCS2_EXEC_H_ */