file.c revision 1.3 1 1.3 lukem /* $NetBSD: file.c,v 1.3 1997/10/16 07:36:31 lukem Exp $ */
2 1.2 thorpej
3 1.1 cjs /*
4 1.1 cjs * Copyright (c) 1995-96 Mats O Jansson. All rights reserved.
5 1.1 cjs *
6 1.1 cjs * Redistribution and use in source and binary forms, with or without
7 1.1 cjs * modification, are permitted provided that the following conditions
8 1.1 cjs * are met:
9 1.1 cjs * 1. Redistributions of source code must retain the above copyright
10 1.1 cjs * notice, this list of conditions and the following disclaimer.
11 1.1 cjs * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 cjs * notice, this list of conditions and the following disclaimer in the
13 1.1 cjs * documentation and/or other materials provided with the distribution.
14 1.1 cjs * 3. All advertising materials mentioning features or use of this software
15 1.1 cjs * must display the following acknowledgement:
16 1.1 cjs * This product includes software developed by Mats O Jansson.
17 1.1 cjs * 4. The name of the author may not be used to endorse or promote products
18 1.1 cjs * derived from this software without specific prior written permission.
19 1.1 cjs *
20 1.1 cjs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 cjs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 cjs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 cjs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 cjs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 cjs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 cjs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 cjs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 cjs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 cjs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 cjs */
31 1.1 cjs
32 1.1 cjs #ifndef LINT
33 1.3 lukem static char rcsid[] = "$NetBSD: file.c,v 1.3 1997/10/16 07:36:31 lukem Exp $";
34 1.1 cjs #endif
35 1.1 cjs
36 1.1 cjs #include "os.h"
37 1.1 cjs #include "common/common.h"
38 1.1 cjs #include "common/mopdef.h"
39 1.1 cjs
40 1.1 cjs #ifndef NOAOUT
41 1.1 cjs #if defined(__NetBSD__) || defined(__OpenBSD__)
42 1.1 cjs #include <sys/exec_aout.h>
43 1.1 cjs #endif
44 1.1 cjs #if defined(__bsdi__)
45 1.1 cjs #define NOAOUT
46 1.1 cjs #endif
47 1.1 cjs #if defined(__FreeBSD__)
48 1.1 cjs #include <sys/imgact_aout.h>
49 1.1 cjs #endif
50 1.1 cjs #if !defined(MID_VAX)
51 1.1 cjs #define MID_VAX 140
52 1.1 cjs #endif
53 1.1 cjs #endif
54 1.1 cjs
55 1.1 cjs void
56 1.1 cjs mopFilePutLX(buf, index, value, cnt)
57 1.1 cjs u_char *buf;
58 1.1 cjs int index, cnt;
59 1.1 cjs u_long value;
60 1.1 cjs {
61 1.1 cjs int i;
62 1.1 cjs for (i = 0; i < cnt; i++) {
63 1.1 cjs buf[index+i] = value % 256;
64 1.1 cjs value = value / 256;
65 1.1 cjs }
66 1.1 cjs }
67 1.1 cjs
68 1.1 cjs void
69 1.1 cjs mopFilePutBX(buf, index, value, cnt)
70 1.1 cjs u_char *buf;
71 1.1 cjs int index, cnt;
72 1.1 cjs u_long value;
73 1.1 cjs {
74 1.1 cjs int i;
75 1.1 cjs for (i = 0; i < cnt; i++) {
76 1.1 cjs buf[index+cnt-1-i] = value % 256;
77 1.1 cjs value = value / 256;
78 1.1 cjs }
79 1.1 cjs }
80 1.1 cjs
81 1.1 cjs u_long
82 1.1 cjs mopFileGetLX(buf, index, cnt)
83 1.1 cjs u_char *buf;
84 1.1 cjs int index, cnt;
85 1.1 cjs {
86 1.1 cjs u_long ret = 0;
87 1.1 cjs int i;
88 1.1 cjs
89 1.1 cjs for (i = 0; i < cnt; i++) {
90 1.1 cjs ret = ret*256 + buf[index+cnt-1-i];
91 1.1 cjs }
92 1.1 cjs
93 1.1 cjs return(ret);
94 1.1 cjs }
95 1.1 cjs
96 1.1 cjs u_long
97 1.1 cjs mopFileGetBX(buf, index, cnt)
98 1.1 cjs u_char *buf;
99 1.1 cjs int index, cnt;
100 1.1 cjs {
101 1.1 cjs u_long ret = 0;
102 1.1 cjs int i;
103 1.1 cjs
104 1.1 cjs for (i = 0; i < cnt; i++) {
105 1.1 cjs ret = ret*256 + buf[index+i];
106 1.1 cjs }
107 1.1 cjs
108 1.1 cjs return(ret);
109 1.1 cjs }
110 1.1 cjs
111 1.1 cjs void
112 1.1 cjs mopFileSwapX(buf, index, cnt)
113 1.1 cjs u_char *buf;
114 1.1 cjs int index, cnt;
115 1.1 cjs {
116 1.1 cjs int i;
117 1.1 cjs u_char c;
118 1.1 cjs
119 1.1 cjs for (i = 0; i < (cnt / 2); i++) {
120 1.1 cjs c = buf[index+i];
121 1.1 cjs buf[index+i] = buf[index+cnt-1-i];
122 1.1 cjs buf[index+cnt-1-i] = c;
123 1.1 cjs }
124 1.1 cjs
125 1.1 cjs }
126 1.1 cjs
127 1.1 cjs int
128 1.1 cjs CheckMopFile(fd)
129 1.1 cjs int fd;
130 1.1 cjs {
131 1.1 cjs u_char header[512];
132 1.1 cjs short image_type;
133 1.1 cjs
134 1.1 cjs if (read(fd, header, 512) != 512)
135 1.1 cjs return(-1);
136 1.1 cjs
137 1.1 cjs (void)lseek(fd, (off_t) 0, SEEK_SET);
138 1.1 cjs
139 1.1 cjs image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
140 1.1 cjs header[IHD_W_ALIAS]);
141 1.1 cjs
142 1.1 cjs switch(image_type) {
143 1.1 cjs case IHD_C_NATIVE: /* Native mode image (VAX) */
144 1.1 cjs case IHD_C_RSX: /* RSX image produced by TKB */
145 1.1 cjs case IHD_C_BPA: /* BASIC plus analog */
146 1.1 cjs case IHD_C_ALIAS: /* Alias */
147 1.1 cjs case IHD_C_CLI: /* Image is CLI */
148 1.1 cjs case IHD_C_PMAX: /* PMAX system image */
149 1.1 cjs case IHD_C_ALPHA: /* ALPHA system image */
150 1.1 cjs break;
151 1.1 cjs default:
152 1.1 cjs return(-1);
153 1.1 cjs }
154 1.1 cjs
155 1.1 cjs return(0);
156 1.1 cjs }
157 1.1 cjs
158 1.1 cjs int
159 1.1 cjs GetMopFileInfo(fd, load, xfr)
160 1.1 cjs int fd;
161 1.1 cjs u_long *load, *xfr;
162 1.1 cjs {
163 1.1 cjs u_char header[512];
164 1.1 cjs short image_type;
165 1.1 cjs u_long load_addr, xfr_addr, isd, iha, hbcnt, isize;
166 1.1 cjs
167 1.1 cjs if (read(fd, header, 512) != 512)
168 1.1 cjs return(-1);
169 1.1 cjs
170 1.1 cjs image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
171 1.1 cjs header[IHD_W_ALIAS]);
172 1.1 cjs
173 1.1 cjs switch(image_type) {
174 1.1 cjs case IHD_C_NATIVE: /* Native mode image (VAX) */
175 1.1 cjs isd = (header[IHD_W_SIZE+1]*256 +
176 1.1 cjs header[IHD_W_SIZE]);
177 1.1 cjs iha = (header[IHD_W_ACTIVOFF+1]*256 +
178 1.1 cjs header[IHD_W_ACTIVOFF]);
179 1.1 cjs hbcnt = (header[IHD_B_HDRBLKCNT]);
180 1.1 cjs isize = (header[isd+ISD_W_PAGCNT+1]*256 +
181 1.1 cjs header[isd+ISD_W_PAGCNT]) * 512;
182 1.1 cjs load_addr = ((header[isd+ISD_V_VPN+1]*256 +
183 1.1 cjs header[isd+ISD_V_VPN]) & ISD_M_VPN)
184 1.1 cjs * 512;
185 1.1 cjs xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
186 1.1 cjs header[iha+IHA_L_TFRADR1+2]*0x10000 +
187 1.1 cjs header[iha+IHA_L_TFRADR1+1]*0x100 +
188 1.1 cjs header[iha+IHA_L_TFRADR1]) & 0x7fffffff;
189 1.1 cjs printf("Native Image (VAX)\n");
190 1.1 cjs printf("Header Block Count: %d\n",hbcnt);
191 1.1 cjs printf("Image Size: %08x\n",isize);
192 1.1 cjs printf("Load Address: %08x\n",load_addr);
193 1.1 cjs printf("Transfer Address: %08x\n",xfr_addr);
194 1.1 cjs break;
195 1.1 cjs case IHD_C_RSX: /* RSX image produced by TKB */
196 1.1 cjs hbcnt = header[L_BBLK+1]*256 + header[L_BBLK];
197 1.1 cjs isize = (header[L_BLDZ+1]*256 + header[L_BLDZ]) * 64;
198 1.1 cjs load_addr = header[L_BSA+1]*256 + header[L_BSA];
199 1.1 cjs xfr_addr = header[L_BXFR+1]*256 + header[L_BXFR];
200 1.1 cjs printf("RSX Image\n");
201 1.1 cjs printf("Header Block Count: %d\n",hbcnt);
202 1.1 cjs printf("Image Size: %08x\n",isize);
203 1.1 cjs printf("Load Address: %08x\n",load_addr);
204 1.1 cjs printf("Transfer Address: %08x\n",xfr_addr);
205 1.1 cjs break;
206 1.1 cjs case IHD_C_BPA: /* BASIC plus analog */
207 1.1 cjs printf("BASIC-Plus Image, not supported\n");
208 1.1 cjs return(-1);
209 1.1 cjs break;
210 1.1 cjs case IHD_C_ALIAS: /* Alias */
211 1.1 cjs printf("Alias, not supported\n");
212 1.1 cjs return(-1);
213 1.1 cjs break;
214 1.1 cjs case IHD_C_CLI: /* Image is CLI */
215 1.1 cjs printf("CLI, not supported\n");
216 1.1 cjs return(-1);
217 1.1 cjs break;
218 1.1 cjs case IHD_C_PMAX: /* PMAX system image */
219 1.1 cjs isd = (header[IHD_W_SIZE+1]*256 +
220 1.1 cjs header[IHD_W_SIZE]);
221 1.1 cjs iha = (header[IHD_W_ACTIVOFF+1]*256 +
222 1.1 cjs header[IHD_W_ACTIVOFF]);
223 1.1 cjs hbcnt = (header[IHD_B_HDRBLKCNT]);
224 1.1 cjs isize = (header[isd+ISD_W_PAGCNT+1]*256 +
225 1.1 cjs header[isd+ISD_W_PAGCNT]) * 512;
226 1.1 cjs load_addr = (header[isd+ISD_V_VPN+1]*256 +
227 1.1 cjs header[isd+ISD_V_VPN]) * 512;
228 1.1 cjs xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
229 1.1 cjs header[iha+IHA_L_TFRADR1+2]*0x10000 +
230 1.1 cjs header[iha+IHA_L_TFRADR1+1]*0x100 +
231 1.1 cjs header[iha+IHA_L_TFRADR1]);
232 1.1 cjs printf("PMAX Image \n");
233 1.1 cjs printf("Header Block Count: %d\n",hbcnt);
234 1.1 cjs printf("Image Size: %08x\n",isize);
235 1.1 cjs printf("Load Address: %08x\n",load_addr);
236 1.1 cjs printf("Transfer Address: %08x\n",xfr_addr);
237 1.1 cjs break;
238 1.1 cjs case IHD_C_ALPHA: /* ALPHA system image */
239 1.1 cjs isd = (header[EIHD_L_ISDOFF+3]*0x1000000 +
240 1.1 cjs header[EIHD_L_ISDOFF+2]*0x10000 +
241 1.1 cjs header[EIHD_L_ISDOFF+1]*0x100 +
242 1.1 cjs header[EIHD_L_ISDOFF]);
243 1.1 cjs hbcnt = (header[EIHD_L_HDRBLKCNT+3]*0x1000000 +
244 1.1 cjs header[EIHD_L_HDRBLKCNT+2]*0x10000 +
245 1.1 cjs header[EIHD_L_HDRBLKCNT+1]*0x100 +
246 1.1 cjs header[EIHD_L_HDRBLKCNT]);
247 1.1 cjs isize = (header[isd+EISD_L_SECSIZE+3]*0x1000000 +
248 1.1 cjs header[isd+EISD_L_SECSIZE+2]*0x10000 +
249 1.1 cjs header[isd+EISD_L_SECSIZE+1]*0x100 +
250 1.1 cjs header[isd+EISD_L_SECSIZE]);
251 1.1 cjs load_addr = 0;
252 1.1 cjs xfr_addr = 0;
253 1.1 cjs printf("Alpha Image \n");
254 1.1 cjs printf("Header Block Count: %d\n",hbcnt);
255 1.1 cjs printf("Image Size: %08x\n",isize);
256 1.1 cjs printf("Load Address: %08x\n",load_addr);
257 1.1 cjs printf("Transfer Address: %08x\n",xfr_addr);
258 1.1 cjs break;
259 1.1 cjs default:
260 1.1 cjs printf("Unknown Image (%d)\n",image_type);
261 1.1 cjs return(-1);
262 1.1 cjs }
263 1.1 cjs
264 1.1 cjs if (load != NULL) {
265 1.1 cjs *load = load_addr;
266 1.1 cjs }
267 1.1 cjs
268 1.1 cjs if (xfr != NULL) {
269 1.1 cjs *xfr = xfr_addr;
270 1.1 cjs }
271 1.1 cjs
272 1.1 cjs return(0);
273 1.1 cjs }
274 1.1 cjs
275 1.1 cjs #ifndef NOAOUT
276 1.1 cjs int
277 1.1 cjs getMID(old_mid,new_mid)
278 1.1 cjs int old_mid, new_mid;
279 1.1 cjs {
280 1.1 cjs int mid;
281 1.1 cjs
282 1.1 cjs mid = old_mid;
283 1.1 cjs
284 1.1 cjs switch (new_mid) {
285 1.1 cjs case MID_I386:
286 1.1 cjs mid = MID_I386;
287 1.1 cjs break;
288 1.1 cjs #ifdef MID_M68K
289 1.1 cjs case MID_M68K:
290 1.1 cjs mid = MID_M68K;
291 1.1 cjs break;
292 1.1 cjs #endif
293 1.1 cjs #ifdef MID_M68K4K
294 1.1 cjs case MID_M68K4K:
295 1.1 cjs mid = MID_M68K4K;
296 1.1 cjs break;
297 1.1 cjs #endif
298 1.1 cjs #ifdef MID_NS32532
299 1.1 cjs case MID_NS32532:
300 1.1 cjs mid = MID_NS32532;
301 1.1 cjs break;
302 1.1 cjs #endif
303 1.1 cjs /*###323 [cc] for each function it appears in.)%%%*/
304 1.1 cjs /*###323 [cc] (Each undeclared identifier is reported only once%%%*/
305 1.1 cjs /*###323 [cc] `MID_SPARC' undeclared (first use this function)%%%*/
306 1.1 cjs case MID_SPARC:
307 1.1 cjs mid = MID_SPARC;
308 1.1 cjs break;
309 1.1 cjs #ifdef MID_PMAX
310 1.1 cjs case MID_PMAX:
311 1.1 cjs mid = MID_PMAX;
312 1.1 cjs break;
313 1.1 cjs #endif
314 1.1 cjs #ifdef MID_VAX
315 1.1 cjs case MID_VAX:
316 1.1 cjs mid = MID_VAX;
317 1.1 cjs break;
318 1.1 cjs #endif
319 1.1 cjs #ifdef MID_ALPHA
320 1.1 cjs case MID_ALPHA:
321 1.1 cjs mid = MID_ALPHA;
322 1.1 cjs break;
323 1.1 cjs #endif
324 1.1 cjs #ifdef MID_MIPS
325 1.1 cjs case MID_MIPS:
326 1.1 cjs mid = MID_MIPS;
327 1.1 cjs break;
328 1.1 cjs #endif
329 1.1 cjs #ifdef MID_ARM6
330 1.1 cjs case MID_ARM6:
331 1.1 cjs mid = MID_ARM6;
332 1.1 cjs break;
333 1.1 cjs #endif
334 1.1 cjs default:
335 1.1 cjs /*###352 [cc] syntax error before `}'%%%*/
336 1.1 cjs }
337 1.1 cjs
338 1.1 cjs return(mid);
339 1.1 cjs }
340 1.1 cjs
341 1.1 cjs int
342 1.1 cjs getCLBYTES(mid)
343 1.1 cjs int mid;
344 1.1 cjs {
345 1.1 cjs int clbytes;
346 1.1 cjs
347 1.1 cjs switch (mid) {
348 1.1 cjs #ifdef MID_VAX
349 1.1 cjs case MID_VAX:
350 1.1 cjs clbytes = 1024;
351 1.1 cjs break;
352 1.1 cjs #endif
353 1.1 cjs case MID_I386:
354 1.1 cjs #ifdef MID_M68K4K
355 1.1 cjs case MID_M68K4K:
356 1.1 cjs #endif
357 1.1 cjs #ifdef MID_NS32532
358 1.1 cjs case MID_NS32532:
359 1.1 cjs #endif
360 1.1 cjs case MID_SPARC: /* It might be 8192 */
361 1.1 cjs #ifdef MID_PMAX
362 1.1 cjs case MID_PMAX:
363 1.1 cjs #endif
364 1.1 cjs #ifdef MID_MIPS
365 1.1 cjs case MID_MIPS:
366 1.1 cjs #endif
367 1.1 cjs #ifdef MID_ARM6
368 1.1 cjs case MID_ARM6:
369 1.1 cjs #endif
370 1.1 cjs clbytes = 4096;
371 1.1 cjs break;
372 1.1 cjs #ifdef MID_M68K
373 1.1 cjs case MID_M68K:
374 1.1 cjs #endif
375 1.1 cjs #ifdef MID_ALPHA
376 1.1 cjs case MID_ALPHA:
377 1.1 cjs #endif
378 1.1 cjs #if defined(MID_M68K) || defined(MID_ALPHA)
379 1.1 cjs clbytes = 8192;
380 1.1 cjs break;
381 1.1 cjs #endif
382 1.1 cjs default:
383 1.1 cjs clbytes = 0;
384 1.1 cjs }
385 1.1 cjs
386 1.1 cjs return(clbytes);
387 1.1 cjs }
388 1.1 cjs #endif
389 1.1 cjs
390 1.1 cjs /*###406 [cc] syntax error before `int'%%%*/
391 1.1 cjs int
392 1.1 cjs CheckAOutFile(fd)
393 1.1 cjs int fd;
394 1.1 cjs {
395 1.1 cjs #ifdef NOAOUT
396 1.1 cjs return(-1);
397 1.1 cjs #else
398 1.1 cjs struct exec ex, ex_swap;
399 1.1 cjs int mid = -1;
400 1.1 cjs
401 1.1 cjs /*###416 [cc] `fd' undeclared (first use this function)%%%*/
402 1.1 cjs if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
403 1.1 cjs return(-1);
404 1.1 cjs
405 1.1 cjs (void)lseek(fd, (off_t) 0, SEEK_SET);
406 1.1 cjs
407 1.1 cjs if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
408 1.1 cjs return(-1);
409 1.1 cjs
410 1.1 cjs (void)lseek(fd, (off_t) 0, SEEK_SET);
411 1.1 cjs
412 1.1 cjs mid = getMID(mid, N_GETMID (ex));
413 1.1 cjs
414 1.1 cjs if (mid == -1) {
415 1.1 cjs mid = getMID(mid, N_GETMID (ex_swap));
416 1.1 cjs }
417 1.1 cjs
418 1.1 cjs if (mid != -1) {
419 1.1 cjs return(0);
420 1.1 cjs } else {
421 1.1 cjs return(-1);
422 1.1 cjs }
423 1.1 cjs #endif NOAOUT
424 1.1 cjs }
425 1.1 cjs
426 1.1 cjs /*###440 [cc] syntax error before `int'%%%*/
427 1.1 cjs int
428 1.1 cjs GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
429 1.1 cjs a_data, a_data_fill, a_bss, a_bss_fill, aout)
430 1.1 cjs int fd, *aout;
431 1.1 cjs u_long *load, *xfr, *a_text, *a_text_fill;
432 1.1 cjs u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
433 1.1 cjs {
434 1.1 cjs #ifdef NOAOUT
435 1.1 cjs return(-1);
436 1.1 cjs #else
437 1.1 cjs struct exec ex, ex_swap;
438 1.1 cjs int mid = -1;
439 1.1 cjs u_long magic, clbytes, clofset;
440 1.1 cjs
441 1.1 cjs if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
442 1.1 cjs return(-1);
443 1.1 cjs
444 1.1 cjs (void)lseek(fd, (off_t) 0, SEEK_SET);
445 1.1 cjs
446 1.1 cjs if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
447 1.1 cjs return(-1);
448 1.1 cjs
449 1.1 cjs mopFileSwapX((u_char *)&ex_swap, 0, 4);
450 1.1 cjs
451 1.1 cjs mid = getMID(mid, N_GETMID (ex));
452 1.1 cjs
453 1.1 cjs if (mid == -1) {
454 1.1 cjs mid = getMID(mid, N_GETMID (ex_swap));
455 1.1 cjs if (mid != -1) {
456 1.1 cjs mopFileSwapX((u_char *)&ex, 0, 4);
457 1.1 cjs }
458 1.1 cjs }
459 1.1 cjs
460 1.1 cjs if (mid == -1) {
461 1.1 cjs return(-1);
462 1.1 cjs }
463 1.1 cjs
464 1.1 cjs if (N_BADMAG (ex)) {
465 1.1 cjs return(-1);
466 1.1 cjs }
467 1.1 cjs
468 1.1 cjs switch (mid) {
469 1.1 cjs case MID_I386:
470 1.1 cjs #ifdef MID_NS32532
471 1.1 cjs case MID_NS32532:
472 1.1 cjs #endif
473 1.1 cjs #ifdef MID_PMAX
474 1.1 cjs case MID_PMAX:
475 1.1 cjs #endif
476 1.1 cjs #ifdef MID_VAX
477 1.1 cjs case MID_VAX:
478 1.1 cjs #endif
479 1.1 cjs #ifdef MID_ALPHA
480 1.1 cjs case MID_ALPHA:
481 1.1 cjs #endif
482 1.1 cjs #ifdef MID_ARM6
483 1.1 cjs case MID_ARM6:
484 1.1 cjs #endif
485 1.1 cjs ex.a_text = mopFileGetLX((u_char *)&ex_swap, 4, 4);
486 1.1 cjs ex.a_data = mopFileGetLX((u_char *)&ex_swap, 8, 4);
487 1.1 cjs ex.a_bss = mopFileGetLX((u_char *)&ex_swap, 12, 4);
488 1.1 cjs ex.a_syms = mopFileGetLX((u_char *)&ex_swap, 16, 4);
489 1.1 cjs ex.a_entry = mopFileGetLX((u_char *)&ex_swap, 20, 4);
490 1.1 cjs ex.a_trsize= mopFileGetLX((u_char *)&ex_swap, 24, 4);
491 1.1 cjs ex.a_drsize= mopFileGetLX((u_char *)&ex_swap, 28, 4);
492 1.1 cjs break;
493 1.1 cjs #ifdef MID_M68K
494 1.1 cjs case MID_M68K:
495 1.1 cjs #endif
496 1.1 cjs #ifdef MID_M68K4K
497 1.1 cjs case MID_M68K4K:
498 1.1 cjs #endif
499 1.1 cjs case MID_SPARC:
500 1.1 cjs #ifdef MID_MIPS
501 1.1 cjs case MID_MIPS:
502 1.1 cjs #endif
503 1.1 cjs ex.a_text = mopFileGetBX((u_char *)&ex_swap, 4, 4);
504 1.1 cjs ex.a_data = mopFileGetBX((u_char *)&ex_swap, 8, 4);
505 1.1 cjs ex.a_bss = mopFileGetBX((u_char *)&ex_swap, 12, 4);
506 1.1 cjs ex.a_syms = mopFileGetBX((u_char *)&ex_swap, 16, 4);
507 1.1 cjs ex.a_entry = mopFileGetBX((u_char *)&ex_swap, 20, 4);
508 1.1 cjs ex.a_trsize= mopFileGetBX((u_char *)&ex_swap, 24, 4);
509 1.1 cjs ex.a_drsize= mopFileGetBX((u_char *)&ex_swap, 28, 4);
510 1.1 cjs break;
511 1.1 cjs default:
512 1.1 cjs /*###525 [cc] syntax error before `}'%%%*/
513 1.1 cjs }
514 1.1 cjs
515 1.1 cjs printf("a.out image (");
516 1.1 cjs switch (N_GETMID (ex)) {
517 1.1 cjs case MID_I386:
518 1.1 cjs printf("i386");
519 1.1 cjs break;
520 1.1 cjs #ifdef MID_M68K
521 1.1 cjs case MID_M68K:
522 1.1 cjs printf("m68k");
523 1.1 cjs break;
524 1.1 cjs #endif
525 1.1 cjs #ifdef MID_M68K4K
526 1.1 cjs case MID_M68K4K:
527 1.1 cjs printf("m68k 4k");
528 1.1 cjs break;
529 1.1 cjs #endif
530 1.1 cjs #ifdef MID_NS32532
531 1.1 cjs case MID_NS32532:
532 1.1 cjs printf("pc532");
533 1.1 cjs break;
534 1.1 cjs #endif
535 1.1 cjs case MID_SPARC:
536 1.1 cjs printf("sparc");
537 1.1 cjs break;
538 1.1 cjs #ifdef MID_PMAX
539 1.1 cjs case MID_PMAX:
540 1.1 cjs printf("pmax");
541 1.1 cjs break;
542 1.1 cjs #endif
543 1.1 cjs #ifdef MID_VAX
544 1.1 cjs case MID_VAX:
545 1.1 cjs printf("vax");
546 1.1 cjs break;
547 1.1 cjs #endif
548 1.1 cjs #ifdef MID_ALPHA
549 1.1 cjs case MID_ALPHA:
550 1.1 cjs printf("alpha");
551 1.1 cjs break;
552 1.1 cjs #endif
553 1.1 cjs #ifdef MID_MIPS
554 1.1 cjs case MID_MIPS:
555 1.1 cjs printf("mips");
556 1.1 cjs break;
557 1.1 cjs #endif
558 1.1 cjs #ifdef MID_ARM6
559 1.1 cjs case MID_ARM6:
560 1.1 cjs printf("arm32");
561 1.1 cjs break;
562 1.1 cjs #endif
563 1.1 cjs default:
564 1.1 cjs }
565 1.1 cjs printf(") Magic: ");
566 1.1 cjs switch (N_GETMAGIC (ex)) {
567 1.1 cjs case OMAGIC:
568 1.1 cjs printf("OMAGIC");
569 1.1 cjs break;
570 1.1 cjs case NMAGIC:
571 1.1 cjs printf("NMAGIC");
572 1.1 cjs break;
573 1.1 cjs case ZMAGIC:
574 1.1 cjs printf("ZMAGIC");
575 1.1 cjs break;
576 1.1 cjs case QMAGIC:
577 1.1 cjs printf("QMAGIC");
578 1.1 cjs break;
579 1.1 cjs default:
580 1.1 cjs printf("Unknown %d",N_GETMAGIC (ex));
581 1.1 cjs }
582 1.1 cjs printf("\n");
583 1.1 cjs printf("Size of text: %08x\n",ex.a_text);
584 1.1 cjs printf("Size of data: %08x\n",ex.a_data);
585 1.1 cjs printf("Size of bss: %08x\n",ex.a_bss);
586 1.1 cjs printf("Size of symbol tab: %08x\n",ex.a_syms);
587 1.1 cjs printf("Transfer Address: %08x\n",ex.a_entry);
588 1.1 cjs printf("Size of reloc text: %08x\n",ex.a_trsize);
589 1.1 cjs printf("Size of reloc data: %08x\n",ex.a_drsize);
590 1.3 lukem
591 1.1 cjs magic = N_GETMAGIC (ex);
592 1.1 cjs clbytes = getCLBYTES(mid);
593 1.1 cjs clofset = clbytes - 1;
594 1.1 cjs
595 1.1 cjs /*###608 [cc] `load' undeclared (first use this function)%%%*/
596 1.1 cjs if (load != NULL) {
597 1.1 cjs *load = 0;
598 1.1 cjs }
599 1.1 cjs
600 1.1 cjs /*###612 [cc] `xfr' undeclared (first use this function)%%%*/
601 1.1 cjs if (xfr != NULL) {
602 1.1 cjs *xfr = ex.a_entry;
603 1.1 cjs }
604 1.1 cjs
605 1.1 cjs /*###616 [cc] `a_text' undeclared (first use this function)%%%*/
606 1.1 cjs if (a_text != NULL) {
607 1.1 cjs *a_text = ex.a_text;
608 1.1 cjs }
609 1.1 cjs
610 1.1 cjs /*###620 [cc] `a_text_fill' undeclared (first use this function)%%%*/
611 1.1 cjs if (a_text_fill != NULL) {
612 1.1 cjs if (magic == ZMAGIC || magic == NMAGIC) {
613 1.1 cjs *a_text_fill = clbytes - (ex.a_text & clofset);
614 1.1 cjs if (*a_text_fill == clbytes) {
615 1.1 cjs *a_text_fill = 0;
616 1.1 cjs }
617 1.1 cjs } else {
618 1.1 cjs *a_text_fill = 0;
619 1.1 cjs }
620 1.1 cjs }
621 1.1 cjs
622 1.1 cjs /*###631 [cc] `a_data' undeclared (first use this function)%%%*/
623 1.1 cjs if (a_data != NULL) {
624 1.1 cjs *a_data = ex.a_data;
625 1.1 cjs }
626 1.1 cjs
627 1.1 cjs /*###635 [cc] `a_data_fill' undeclared (first use this function)%%%*/
628 1.1 cjs if (a_data_fill != NULL) {
629 1.1 cjs if (magic == ZMAGIC || magic == NMAGIC) {
630 1.1 cjs *a_data_fill = clbytes - (ex.a_data & clofset);
631 1.1 cjs if (*a_data_fill == clbytes) {
632 1.1 cjs *a_data_fill = 0;
633 1.1 cjs }
634 1.1 cjs } else {
635 1.1 cjs *a_data_fill = 0;
636 1.1 cjs }
637 1.1 cjs }
638 1.1 cjs
639 1.1 cjs /*###646 [cc] `a_bss' undeclared (first use this function)%%%*/
640 1.1 cjs if (a_bss != NULL) {
641 1.1 cjs *a_bss = ex.a_bss;
642 1.1 cjs }
643 1.1 cjs
644 1.1 cjs /*###650 [cc] `a_bss_fill' undeclared (first use this function)%%%*/
645 1.1 cjs if (a_bss_fill != NULL) {
646 1.1 cjs if (magic == ZMAGIC || magic == NMAGIC) {
647 1.1 cjs *a_bss_fill = clbytes - (ex.a_bss & clofset);
648 1.1 cjs if (*a_bss_fill == clbytes) {
649 1.1 cjs *a_bss_fill = 0;
650 1.1 cjs }
651 1.1 cjs } else {
652 1.1 cjs *a_bss_fill = clbytes -
653 1.1 cjs ((ex.a_text+ex.a_data+ex.a_bss) & clofset);
654 1.1 cjs if (*a_text_fill == clbytes) {
655 1.1 cjs *a_text_fill = 0;
656 1.1 cjs }
657 1.1 cjs }
658 1.1 cjs }
659 1.1 cjs
660 1.1 cjs /*###665 [cc] `aout' undeclared (first use this function)%%%*/
661 1.1 cjs if (aout != NULL) {
662 1.1 cjs *aout = mid;
663 1.1 cjs }
664 1.1 cjs
665 1.1 cjs return(0);
666 1.1 cjs #endif NOAOUT
667 1.1 cjs }
668 1.1 cjs
669 1.1 cjs /*###673 [cc] syntax error before `int'%%%*/
670 1.1 cjs int
671 1.1 cjs GetFileInfo(fd, load, xfr, aout,
672 1.1 cjs a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill)
673 1.1 cjs int fd, *aout;
674 1.1 cjs u_long *load, *xfr, *a_text, *a_text_fill;
675 1.1 cjs u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
676 1.1 cjs {
677 1.1 cjs int err;
678 1.1 cjs
679 1.1 cjs err = CheckAOutFile(fd);
680 1.1 cjs
681 1.1 cjs if (err == 0) {
682 1.1 cjs err = GetAOutFileInfo(fd, load, xfr,
683 1.1 cjs a_text, a_text_fill,
684 1.1 cjs a_data, a_data_fill,
685 1.1 cjs a_bss, a_bss_fill,
686 1.1 cjs aout);
687 1.1 cjs if (err != 0) {
688 1.1 cjs return(-1);
689 1.1 cjs }
690 1.1 cjs } else {
691 1.1 cjs err = CheckMopFile(fd);
692 1.1 cjs
693 1.1 cjs if (err == 0) {
694 1.1 cjs err = GetMopFileInfo(fd, load, xfr);
695 1.1 cjs if (err != 0) {
696 1.1 cjs return(-1);
697 1.1 cjs }
698 1.1 cjs *aout = -1;
699 1.1 cjs } else {
700 1.1 cjs return(-1);
701 1.1 cjs }
702 1.1 cjs }
703 1.1 cjs
704 1.1 cjs return(0);
705 1.1 cjs }
706 1.1 cjs
707 1.1 cjs ssize_t
708 1.1 cjs /*###711 [cc] syntax error before `mopFileRead'%%%*/
709 1.1 cjs mopFileRead(dlslot, buf)
710 1.1 cjs struct dllist *dlslot;
711 1.1 cjs u_char *buf;
712 1.1 cjs {
713 1.1 cjs ssize_t len, outlen;
714 1.1 cjs int bsz;
715 1.1 cjs long pos, notdone, total;
716 1.1 cjs
717 1.1 cjs /*###719 [cc] `dlslot' undeclared (first use this function)%%%*/
718 1.1 cjs if (dlslot->aout == -1) {
719 1.1 cjs /*###720 [cc] `buf' undeclared (first use this function)%%%*/
720 1.1 cjs len = read(dlslot->ldfd,buf,dlslot->dl_bsz);
721 1.1 cjs } else {
722 1.1 cjs bsz = dlslot->dl_bsz;
723 1.1 cjs pos = dlslot->a_lseek;
724 1.1 cjs len = 0;
725 1.1 cjs
726 1.1 cjs total = dlslot->a_text;
727 1.1 cjs
728 1.1 cjs if (pos < total) {
729 1.1 cjs notdone = total - pos;
730 1.1 cjs if (notdone <= bsz) {
731 1.1 cjs /*###731 [cc] subscripted value is neither array nor pointer%%%*/
732 1.1 cjs outlen = read(dlslot->ldfd,&buf[len],notdone);
733 1.1 cjs } else {
734 1.1 cjs /*###733 [cc] subscripted value is neither array nor pointer%%%*/
735 1.1 cjs outlen = read(dlslot->ldfd,&buf[len],bsz);
736 1.1 cjs }
737 1.1 cjs len = len + outlen;
738 1.1 cjs pos = pos + outlen;
739 1.1 cjs bsz = bsz - outlen;
740 1.1 cjs }
741 1.1 cjs
742 1.1 cjs total = total + dlslot->a_text_fill;
743 1.1 cjs
744 1.1 cjs if ((bsz > 0) && (pos < total)) {
745 1.1 cjs notdone = total - pos;
746 1.1 cjs if (notdone <= bsz) {
747 1.1 cjs outlen = notdone;
748 1.1 cjs } else {
749 1.1 cjs outlen = bsz;
750 1.1 cjs }
751 1.1 cjs /*###749 [cc] subscripted value is neither array nor pointer%%%*/
752 1.1 cjs bzero(&buf[len],outlen);
753 1.1 cjs len = len + outlen;
754 1.1 cjs pos = pos + outlen;
755 1.1 cjs bsz = bsz - outlen;
756 1.1 cjs }
757 1.1 cjs
758 1.1 cjs total = total + dlslot->a_data;
759 1.1 cjs
760 1.1 cjs if ((bsz > 0) && (pos < total)) {
761 1.1 cjs notdone = total - pos;
762 1.1 cjs if (notdone <= bsz) {
763 1.1 cjs /*###760 [cc] subscripted value is neither array nor pointer%%%*/
764 1.1 cjs outlen = read(dlslot->ldfd,&buf[len],notdone);
765 1.1 cjs } else {
766 1.1 cjs /*###762 [cc] subscripted value is neither array nor pointer%%%*/
767 1.1 cjs outlen = read(dlslot->ldfd,&buf[len],bsz);
768 1.1 cjs }
769 1.1 cjs len = len + outlen;
770 1.1 cjs pos = pos + outlen;
771 1.1 cjs bsz = bsz - outlen;
772 1.1 cjs }
773 1.1 cjs
774 1.1 cjs total = total + dlslot->a_data_fill;
775 1.1 cjs
776 1.1 cjs if ((bsz > 0) && (pos < total)) {
777 1.1 cjs notdone = total - pos;
778 1.1 cjs if (notdone <= bsz) {
779 1.1 cjs outlen = notdone;
780 1.1 cjs } else {
781 1.1 cjs outlen = bsz;
782 1.1 cjs }
783 1.1 cjs /*###778 [cc] subscripted value is neither array nor pointer%%%*/
784 1.1 cjs bzero(&buf[len],outlen);
785 1.1 cjs len = len + outlen;
786 1.1 cjs pos = pos + outlen;
787 1.1 cjs bsz = bsz - outlen;
788 1.1 cjs }
789 1.1 cjs
790 1.1 cjs total = total + dlslot->a_bss;
791 1.1 cjs
792 1.1 cjs if ((bsz > 0) && (pos < total)) {
793 1.1 cjs notdone = total - pos;
794 1.1 cjs if (notdone <= bsz) {
795 1.1 cjs outlen = notdone;
796 1.1 cjs } else {
797 1.1 cjs outlen = bsz;
798 1.1 cjs }
799 1.1 cjs /*###793 [cc] subscripted value is neither array nor pointer%%%*/
800 1.1 cjs bzero(&buf[len],outlen);
801 1.1 cjs len = len + outlen;
802 1.1 cjs pos = pos + outlen;
803 1.1 cjs bsz = bsz - outlen;
804 1.1 cjs }
805 1.1 cjs
806 1.1 cjs total = total + dlslot->a_bss_fill;
807 1.1 cjs
808 1.1 cjs if ((bsz > 0) && (pos < total)) {
809 1.1 cjs notdone = total - pos;
810 1.1 cjs if (notdone <= bsz) {
811 1.1 cjs outlen = notdone;
812 1.1 cjs } else {
813 1.1 cjs outlen = bsz;
814 1.1 cjs }
815 1.1 cjs /*###808 [cc] subscripted value is neither array nor pointer%%%*/
816 1.1 cjs bzero(&buf[len],outlen);
817 1.1 cjs len = len + outlen;
818 1.1 cjs pos = pos + outlen;
819 1.1 cjs bsz = bsz - outlen;
820 1.1 cjs }
821 1.1 cjs
822 1.1 cjs dlslot->a_lseek = pos;
823 1.1 cjs
824 1.1 cjs }
825 1.1 cjs
826 1.1 cjs return(len);
827 1.1 cjs }
828 1.1 cjs /*###820 [cc] syntax error at end of input%%%*/
829