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