Home | History | Annotate | Line # | Download | only in common
file.c revision 1.2
      1  1.2  thorpej /*	$NetBSD: file.c,v 1.2 1997/03/25 03:07:12 thorpej 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.2  thorpej static char rcsid[] = "$NetBSD: file.c,v 1.2 1997/03/25 03:07:12 thorpej 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 #ifdef INFO
    190  1.1      cjs 			printf("Native Image (VAX)\n");
    191  1.1      cjs 			printf("Header Block Count: %d\n",hbcnt);
    192  1.1      cjs 			printf("Image Size:         %08x\n",isize);
    193  1.1      cjs 			printf("Load Address:       %08x\n",load_addr);
    194  1.1      cjs 			printf("Transfer Address:   %08x\n",xfr_addr);
    195  1.1      cjs #endif
    196  1.1      cjs 			break;
    197  1.1      cjs 		case IHD_C_RSX:			/* RSX image produced by TKB */
    198  1.1      cjs 			hbcnt = header[L_BBLK+1]*256 + header[L_BBLK];
    199  1.1      cjs 			isize = (header[L_BLDZ+1]*256 + header[L_BLDZ]) * 64;
    200  1.1      cjs 			load_addr = header[L_BSA+1]*256 + header[L_BSA];
    201  1.1      cjs 			xfr_addr  = header[L_BXFR+1]*256 + header[L_BXFR];
    202  1.1      cjs #ifdef INFO
    203  1.1      cjs 			printf("RSX Image\n");
    204  1.1      cjs 			printf("Header Block Count: %d\n",hbcnt);
    205  1.1      cjs 			printf("Image Size:         %08x\n",isize);
    206  1.1      cjs 			printf("Load Address:       %08x\n",load_addr);
    207  1.1      cjs 			printf("Transfer Address:   %08x\n",xfr_addr);
    208  1.1      cjs #endif
    209  1.1      cjs 			break;
    210  1.1      cjs 		case IHD_C_BPA:			/* BASIC plus analog         */
    211  1.1      cjs #ifdef INFO
    212  1.1      cjs 			printf("BASIC-Plus Image, not supported\n");
    213  1.1      cjs #endif
    214  1.1      cjs 			return(-1);
    215  1.1      cjs 			break;
    216  1.1      cjs 		case IHD_C_ALIAS:		/* Alias		     */
    217  1.1      cjs #ifdef INFO
    218  1.1      cjs 			printf("Alias, not supported\n");
    219  1.1      cjs #endif
    220  1.1      cjs 			return(-1);
    221  1.1      cjs 			break;
    222  1.1      cjs 		case IHD_C_CLI:			/* Image is CLI		     */
    223  1.1      cjs #ifdef INFO
    224  1.1      cjs 			printf("CLI, not supported\n");
    225  1.1      cjs #endif
    226  1.1      cjs 			return(-1);
    227  1.1      cjs 			break;
    228  1.1      cjs 		case IHD_C_PMAX:		/* PMAX system image	     */
    229  1.1      cjs 			isd = (header[IHD_W_SIZE+1]*256 +
    230  1.1      cjs 			       header[IHD_W_SIZE]);
    231  1.1      cjs 			iha = (header[IHD_W_ACTIVOFF+1]*256 +
    232  1.1      cjs 			       header[IHD_W_ACTIVOFF]);
    233  1.1      cjs 			hbcnt = (header[IHD_B_HDRBLKCNT]);
    234  1.1      cjs 			isize = (header[isd+ISD_W_PAGCNT+1]*256 +
    235  1.1      cjs 				 header[isd+ISD_W_PAGCNT]) * 512;
    236  1.1      cjs 			load_addr = (header[isd+ISD_V_VPN+1]*256 +
    237  1.1      cjs 				     header[isd+ISD_V_VPN]) * 512;
    238  1.1      cjs 			xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
    239  1.1      cjs 				    header[iha+IHA_L_TFRADR1+2]*0x10000 +
    240  1.1      cjs 				    header[iha+IHA_L_TFRADR1+1]*0x100 +
    241  1.1      cjs 				    header[iha+IHA_L_TFRADR1]);
    242  1.1      cjs #ifdef INFO
    243  1.1      cjs 			printf("PMAX Image \n");
    244  1.1      cjs 			printf("Header Block Count: %d\n",hbcnt);
    245  1.1      cjs 			printf("Image Size:         %08x\n",isize);
    246  1.1      cjs 			printf("Load Address:       %08x\n",load_addr);
    247  1.1      cjs 			printf("Transfer Address:   %08x\n",xfr_addr);
    248  1.1      cjs #endif
    249  1.1      cjs 			break;
    250  1.1      cjs 		case IHD_C_ALPHA:		/* ALPHA system image	     */
    251  1.1      cjs 			isd = (header[EIHD_L_ISDOFF+3]*0x1000000 +
    252  1.1      cjs 			       header[EIHD_L_ISDOFF+2]*0x10000 +
    253  1.1      cjs 			       header[EIHD_L_ISDOFF+1]*0x100 +
    254  1.1      cjs 			       header[EIHD_L_ISDOFF]);
    255  1.1      cjs 			hbcnt = (header[EIHD_L_HDRBLKCNT+3]*0x1000000 +
    256  1.1      cjs 				 header[EIHD_L_HDRBLKCNT+2]*0x10000 +
    257  1.1      cjs 				 header[EIHD_L_HDRBLKCNT+1]*0x100 +
    258  1.1      cjs 				 header[EIHD_L_HDRBLKCNT]);
    259  1.1      cjs 			isize = (header[isd+EISD_L_SECSIZE+3]*0x1000000 +
    260  1.1      cjs 				 header[isd+EISD_L_SECSIZE+2]*0x10000 +
    261  1.1      cjs 				 header[isd+EISD_L_SECSIZE+1]*0x100 +
    262  1.1      cjs 				 header[isd+EISD_L_SECSIZE]);
    263  1.1      cjs 			load_addr = 0;
    264  1.1      cjs 			xfr_addr = 0;
    265  1.1      cjs #ifdef INFO
    266  1.1      cjs 			printf("Alpha Image \n");
    267  1.1      cjs 			printf("Header Block Count: %d\n",hbcnt);
    268  1.1      cjs 			printf("Image Size:         %08x\n",isize);
    269  1.1      cjs 			printf("Load Address:       %08x\n",load_addr);
    270  1.1      cjs 			printf("Transfer Address:   %08x\n",xfr_addr);
    271  1.1      cjs #endif
    272  1.1      cjs 			break;
    273  1.1      cjs 		default:
    274  1.1      cjs #ifdef INFO
    275  1.1      cjs 			printf("Unknown Image (%d)\n",image_type);
    276  1.1      cjs #endif
    277  1.1      cjs 			return(-1);
    278  1.1      cjs 	}
    279  1.1      cjs 
    280  1.1      cjs 	if (load != NULL) {
    281  1.1      cjs 		*load = load_addr;
    282  1.1      cjs 	}
    283  1.1      cjs 
    284  1.1      cjs 	if (xfr != NULL) {
    285  1.1      cjs 		*xfr  = xfr_addr;
    286  1.1      cjs 	}
    287  1.1      cjs 
    288  1.1      cjs 	return(0);
    289  1.1      cjs }
    290  1.1      cjs 
    291  1.1      cjs #ifndef NOAOUT
    292  1.1      cjs int
    293  1.1      cjs getMID(old_mid,new_mid)
    294  1.1      cjs 	int	old_mid, new_mid;
    295  1.1      cjs {
    296  1.1      cjs 	int	mid;
    297  1.1      cjs 
    298  1.1      cjs 	mid = old_mid;
    299  1.1      cjs 
    300  1.1      cjs 	switch (new_mid) {
    301  1.1      cjs 	case MID_I386:
    302  1.1      cjs 		mid = MID_I386;
    303  1.1      cjs 		break;
    304  1.1      cjs #ifdef MID_M68K
    305  1.1      cjs 	case MID_M68K:
    306  1.1      cjs 		mid = MID_M68K;
    307  1.1      cjs 		break;
    308  1.1      cjs #endif
    309  1.1      cjs #ifdef MID_M68K4K
    310  1.1      cjs 	case MID_M68K4K:
    311  1.1      cjs 		mid = MID_M68K4K;
    312  1.1      cjs 		break;
    313  1.1      cjs #endif
    314  1.1      cjs #ifdef MID_NS32532
    315  1.1      cjs 	case MID_NS32532:
    316  1.1      cjs 		mid = MID_NS32532;
    317  1.1      cjs 		break;
    318  1.1      cjs #endif
    319  1.1      cjs /*###323 [cc] for each function it appears in.)%%%*/
    320  1.1      cjs /*###323 [cc] (Each undeclared identifier is reported only once%%%*/
    321  1.1      cjs /*###323 [cc] `MID_SPARC' undeclared (first use this function)%%%*/
    322  1.1      cjs 	case MID_SPARC:
    323  1.1      cjs 		mid = MID_SPARC;
    324  1.1      cjs 		break;
    325  1.1      cjs #ifdef MID_PMAX
    326  1.1      cjs 	case MID_PMAX:
    327  1.1      cjs 		mid = MID_PMAX;
    328  1.1      cjs 		break;
    329  1.1      cjs #endif
    330  1.1      cjs #ifdef MID_VAX
    331  1.1      cjs 	case MID_VAX:
    332  1.1      cjs 		mid = MID_VAX;
    333  1.1      cjs 		break;
    334  1.1      cjs #endif
    335  1.1      cjs #ifdef MID_ALPHA
    336  1.1      cjs 	case MID_ALPHA:
    337  1.1      cjs 		mid = MID_ALPHA;
    338  1.1      cjs 		break;
    339  1.1      cjs #endif
    340  1.1      cjs #ifdef MID_MIPS
    341  1.1      cjs 	case MID_MIPS:
    342  1.1      cjs 		mid = MID_MIPS;
    343  1.1      cjs 		break;
    344  1.1      cjs #endif
    345  1.1      cjs #ifdef MID_ARM6
    346  1.1      cjs 	case MID_ARM6:
    347  1.1      cjs 		mid = MID_ARM6;
    348  1.1      cjs 		break;
    349  1.1      cjs #endif
    350  1.1      cjs 	default:
    351  1.1      cjs /*###352 [cc] syntax error before `}'%%%*/
    352  1.1      cjs 	}
    353  1.1      cjs 
    354  1.1      cjs 	return(mid);
    355  1.1      cjs }
    356  1.1      cjs 
    357  1.1      cjs int
    358  1.1      cjs getCLBYTES(mid)
    359  1.1      cjs 	int	mid;
    360  1.1      cjs {
    361  1.1      cjs 	int	clbytes;
    362  1.1      cjs 
    363  1.1      cjs 	switch (mid) {
    364  1.1      cjs #ifdef MID_VAX
    365  1.1      cjs 	case MID_VAX:
    366  1.1      cjs 		clbytes = 1024;
    367  1.1      cjs 		break;
    368  1.1      cjs #endif
    369  1.1      cjs 	case MID_I386:
    370  1.1      cjs #ifdef MID_M68K4K
    371  1.1      cjs 	case MID_M68K4K:
    372  1.1      cjs #endif
    373  1.1      cjs #ifdef MID_NS32532
    374  1.1      cjs 	case MID_NS32532:
    375  1.1      cjs #endif
    376  1.1      cjs 	case MID_SPARC:				/* It might be 8192 */
    377  1.1      cjs #ifdef MID_PMAX
    378  1.1      cjs 	case MID_PMAX:
    379  1.1      cjs #endif
    380  1.1      cjs #ifdef MID_MIPS
    381  1.1      cjs 	case MID_MIPS:
    382  1.1      cjs #endif
    383  1.1      cjs #ifdef MID_ARM6
    384  1.1      cjs 	case MID_ARM6:
    385  1.1      cjs #endif
    386  1.1      cjs 		clbytes = 4096;
    387  1.1      cjs 		break;
    388  1.1      cjs #ifdef MID_M68K
    389  1.1      cjs 	case MID_M68K:
    390  1.1      cjs #endif
    391  1.1      cjs #ifdef MID_ALPHA
    392  1.1      cjs 	case MID_ALPHA:
    393  1.1      cjs #endif
    394  1.1      cjs #if defined(MID_M68K) || defined(MID_ALPHA)
    395  1.1      cjs 		clbytes = 8192;
    396  1.1      cjs 		break;
    397  1.1      cjs #endif
    398  1.1      cjs 	default:
    399  1.1      cjs 		clbytes = 0;
    400  1.1      cjs 	}
    401  1.1      cjs 
    402  1.1      cjs 	return(clbytes);
    403  1.1      cjs }
    404  1.1      cjs #endif
    405  1.1      cjs 
    406  1.1      cjs /*###406 [cc] syntax error before `int'%%%*/
    407  1.1      cjs int
    408  1.1      cjs CheckAOutFile(fd)
    409  1.1      cjs 	int	fd;
    410  1.1      cjs {
    411  1.1      cjs #ifdef NOAOUT
    412  1.1      cjs 	return(-1);
    413  1.1      cjs #else
    414  1.1      cjs 	struct exec ex, ex_swap;
    415  1.1      cjs 	int	mid = -1;
    416  1.1      cjs 
    417  1.1      cjs /*###416 [cc] `fd' undeclared (first use this function)%%%*/
    418  1.1      cjs 	if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
    419  1.1      cjs 		return(-1);
    420  1.1      cjs 
    421  1.1      cjs 	(void)lseek(fd, (off_t) 0, SEEK_SET);
    422  1.1      cjs 
    423  1.1      cjs 	if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
    424  1.1      cjs 		return(-1);
    425  1.1      cjs 
    426  1.1      cjs 	(void)lseek(fd, (off_t) 0, SEEK_SET);
    427  1.1      cjs 
    428  1.1      cjs 	mid = getMID(mid, N_GETMID (ex));
    429  1.1      cjs 
    430  1.1      cjs 	if (mid == -1) {
    431  1.1      cjs 		mid = getMID(mid, N_GETMID (ex_swap));
    432  1.1      cjs 	}
    433  1.1      cjs 
    434  1.1      cjs 	if (mid != -1) {
    435  1.1      cjs 		return(0);
    436  1.1      cjs 	} else {
    437  1.1      cjs 		return(-1);
    438  1.1      cjs 	}
    439  1.1      cjs #endif NOAOUT
    440  1.1      cjs }
    441  1.1      cjs 
    442  1.1      cjs /*###440 [cc] syntax error before `int'%%%*/
    443  1.1      cjs int
    444  1.1      cjs GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
    445  1.1      cjs 		a_data, a_data_fill, a_bss, a_bss_fill, aout)
    446  1.1      cjs 	int	fd, *aout;
    447  1.1      cjs 	u_long	*load, *xfr, *a_text, *a_text_fill;
    448  1.1      cjs 	u_long	*a_data, *a_data_fill, *a_bss, *a_bss_fill;
    449  1.1      cjs {
    450  1.1      cjs #ifdef NOAOUT
    451  1.1      cjs 	return(-1);
    452  1.1      cjs #else
    453  1.1      cjs 	struct exec ex, ex_swap;
    454  1.1      cjs 	int	mid = -1;
    455  1.1      cjs 	u_long	magic, clbytes, clofset;
    456  1.1      cjs 
    457  1.1      cjs 	if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
    458  1.1      cjs 		return(-1);
    459  1.1      cjs 
    460  1.1      cjs 	(void)lseek(fd, (off_t) 0, SEEK_SET);
    461  1.1      cjs 
    462  1.1      cjs 	if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
    463  1.1      cjs 		return(-1);
    464  1.1      cjs 
    465  1.1      cjs 	mopFileSwapX((u_char *)&ex_swap, 0, 4);
    466  1.1      cjs 
    467  1.1      cjs 	mid = getMID(mid, N_GETMID (ex));
    468  1.1      cjs 
    469  1.1      cjs 	if (mid == -1) {
    470  1.1      cjs 		mid = getMID(mid, N_GETMID (ex_swap));
    471  1.1      cjs 		if (mid != -1) {
    472  1.1      cjs 			mopFileSwapX((u_char *)&ex, 0, 4);
    473  1.1      cjs 		}
    474  1.1      cjs 	}
    475  1.1      cjs 
    476  1.1      cjs 	if (mid == -1) {
    477  1.1      cjs 		return(-1);
    478  1.1      cjs 	}
    479  1.1      cjs 
    480  1.1      cjs 	if (N_BADMAG (ex)) {
    481  1.1      cjs 		return(-1);
    482  1.1      cjs 	}
    483  1.1      cjs 
    484  1.1      cjs 	switch (mid) {
    485  1.1      cjs 	case MID_I386:
    486  1.1      cjs #ifdef MID_NS32532
    487  1.1      cjs 	case MID_NS32532:
    488  1.1      cjs #endif
    489  1.1      cjs #ifdef MID_PMAX
    490  1.1      cjs 	case MID_PMAX:
    491  1.1      cjs #endif
    492  1.1      cjs #ifdef MID_VAX
    493  1.1      cjs 	case MID_VAX:
    494  1.1      cjs #endif
    495  1.1      cjs #ifdef MID_ALPHA
    496  1.1      cjs 	case MID_ALPHA:
    497  1.1      cjs #endif
    498  1.1      cjs #ifdef MID_ARM6
    499  1.1      cjs 	case MID_ARM6:
    500  1.1      cjs #endif
    501  1.1      cjs 		ex.a_text  = mopFileGetLX((u_char *)&ex_swap,  4, 4);
    502  1.1      cjs 		ex.a_data  = mopFileGetLX((u_char *)&ex_swap,  8, 4);
    503  1.1      cjs 		ex.a_bss   = mopFileGetLX((u_char *)&ex_swap, 12, 4);
    504  1.1      cjs 		ex.a_syms  = mopFileGetLX((u_char *)&ex_swap, 16, 4);
    505  1.1      cjs 		ex.a_entry = mopFileGetLX((u_char *)&ex_swap, 20, 4);
    506  1.1      cjs 		ex.a_trsize= mopFileGetLX((u_char *)&ex_swap, 24, 4);
    507  1.1      cjs 		ex.a_drsize= mopFileGetLX((u_char *)&ex_swap, 28, 4);
    508  1.1      cjs 		break;
    509  1.1      cjs #ifdef MID_M68K
    510  1.1      cjs 	case MID_M68K:
    511  1.1      cjs #endif
    512  1.1      cjs #ifdef MID_M68K4K
    513  1.1      cjs 	case MID_M68K4K:
    514  1.1      cjs #endif
    515  1.1      cjs 	case MID_SPARC:
    516  1.1      cjs #ifdef MID_MIPS
    517  1.1      cjs 	case MID_MIPS:
    518  1.1      cjs #endif
    519  1.1      cjs 		ex.a_text  = mopFileGetBX((u_char *)&ex_swap,  4, 4);
    520  1.1      cjs 		ex.a_data  = mopFileGetBX((u_char *)&ex_swap,  8, 4);
    521  1.1      cjs 		ex.a_bss   = mopFileGetBX((u_char *)&ex_swap, 12, 4);
    522  1.1      cjs 		ex.a_syms  = mopFileGetBX((u_char *)&ex_swap, 16, 4);
    523  1.1      cjs 		ex.a_entry = mopFileGetBX((u_char *)&ex_swap, 20, 4);
    524  1.1      cjs 		ex.a_trsize= mopFileGetBX((u_char *)&ex_swap, 24, 4);
    525  1.1      cjs 		ex.a_drsize= mopFileGetBX((u_char *)&ex_swap, 28, 4);
    526  1.1      cjs 		break;
    527  1.1      cjs 	default:
    528  1.1      cjs /*###525 [cc] syntax error before `}'%%%*/
    529  1.1      cjs 	}
    530  1.1      cjs 
    531  1.1      cjs #ifdef INFO
    532  1.1      cjs 	printf("a.out image (");
    533  1.1      cjs 	switch (N_GETMID (ex)) {
    534  1.1      cjs 	case MID_I386:
    535  1.1      cjs 		printf("i386");
    536  1.1      cjs 		break;
    537  1.1      cjs #ifdef MID_M68K
    538  1.1      cjs 	case MID_M68K:
    539  1.1      cjs 		printf("m68k");
    540  1.1      cjs 		break;
    541  1.1      cjs #endif
    542  1.1      cjs #ifdef MID_M68K4K
    543  1.1      cjs 	case MID_M68K4K:
    544  1.1      cjs 		printf("m68k 4k");
    545  1.1      cjs 		break;
    546  1.1      cjs #endif
    547  1.1      cjs #ifdef MID_NS32532
    548  1.1      cjs 	case MID_NS32532:
    549  1.1      cjs 		printf("pc532");
    550  1.1      cjs 		break;
    551  1.1      cjs #endif
    552  1.1      cjs 	case MID_SPARC:
    553  1.1      cjs 		printf("sparc");
    554  1.1      cjs 		break;
    555  1.1      cjs #ifdef MID_PMAX
    556  1.1      cjs 	case MID_PMAX:
    557  1.1      cjs 		printf("pmax");
    558  1.1      cjs 		break;
    559  1.1      cjs #endif
    560  1.1      cjs #ifdef MID_VAX
    561  1.1      cjs 	case MID_VAX:
    562  1.1      cjs 		printf("vax");
    563  1.1      cjs 		break;
    564  1.1      cjs #endif
    565  1.1      cjs #ifdef MID_ALPHA
    566  1.1      cjs 	case MID_ALPHA:
    567  1.1      cjs 		printf("alpha");
    568  1.1      cjs 		break;
    569  1.1      cjs #endif
    570  1.1      cjs #ifdef MID_MIPS
    571  1.1      cjs 	case MID_MIPS:
    572  1.1      cjs 		printf("mips");
    573  1.1      cjs 		break;
    574  1.1      cjs #endif
    575  1.1      cjs #ifdef MID_ARM6
    576  1.1      cjs 	case MID_ARM6:
    577  1.1      cjs 		printf("arm32");
    578  1.1      cjs 		break;
    579  1.1      cjs #endif
    580  1.1      cjs 	default:
    581  1.1      cjs 	}
    582  1.1      cjs 	printf(") Magic: ");
    583  1.1      cjs 	switch (N_GETMAGIC (ex)) {
    584  1.1      cjs 	case OMAGIC:
    585  1.1      cjs 		printf("OMAGIC");
    586  1.1      cjs 		break;
    587  1.1      cjs 	case NMAGIC:
    588  1.1      cjs 		printf("NMAGIC");
    589  1.1      cjs 		break;
    590  1.1      cjs 	case ZMAGIC:
    591  1.1      cjs 		printf("ZMAGIC");
    592  1.1      cjs 		break;
    593  1.1      cjs 	case QMAGIC:
    594  1.1      cjs 		printf("QMAGIC");
    595  1.1      cjs 		break;
    596  1.1      cjs 	default:
    597  1.1      cjs 		printf("Unknown %d",N_GETMAGIC (ex));
    598  1.1      cjs 	}
    599  1.1      cjs 	printf("\n");
    600  1.1      cjs 	printf("Size of text:       %08x\n",ex.a_text);
    601  1.1      cjs 	printf("Size of data:       %08x\n",ex.a_data);
    602  1.1      cjs 	printf("Size of bss:        %08x\n",ex.a_bss);
    603  1.1      cjs 	printf("Size of symbol tab: %08x\n",ex.a_syms);
    604  1.1      cjs 	printf("Transfer Address:   %08x\n",ex.a_entry);
    605  1.1      cjs 	printf("Size of reloc text: %08x\n",ex.a_trsize);
    606  1.1      cjs 	printf("Size of reloc data: %08x\n",ex.a_drsize);
    607  1.1      cjs #endif
    608  1.1      cjs 	magic = N_GETMAGIC (ex);
    609  1.1      cjs 	clbytes = getCLBYTES(mid);
    610  1.1      cjs 	clofset = clbytes - 1;
    611  1.1      cjs 
    612  1.1      cjs /*###608 [cc] `load' undeclared (first use this function)%%%*/
    613  1.1      cjs 	if (load != NULL) {
    614  1.1      cjs 		*load   = 0;
    615  1.1      cjs 	}
    616  1.1      cjs 
    617  1.1      cjs /*###612 [cc] `xfr' undeclared (first use this function)%%%*/
    618  1.1      cjs 	if (xfr != NULL) {
    619  1.1      cjs 		*xfr    = ex.a_entry;
    620  1.1      cjs 	}
    621  1.1      cjs 
    622  1.1      cjs /*###616 [cc] `a_text' undeclared (first use this function)%%%*/
    623  1.1      cjs 	if (a_text != NULL) {
    624  1.1      cjs 		*a_text = ex.a_text;
    625  1.1      cjs 	}
    626  1.1      cjs 
    627  1.1      cjs /*###620 [cc] `a_text_fill' undeclared (first use this function)%%%*/
    628  1.1      cjs 	if (a_text_fill != NULL) {
    629  1.1      cjs 		if (magic == ZMAGIC || magic == NMAGIC) {
    630  1.1      cjs 			*a_text_fill = clbytes - (ex.a_text & clofset);
    631  1.1      cjs 			if (*a_text_fill == clbytes) {
    632  1.1      cjs 				*a_text_fill = 0;
    633  1.1      cjs 			}
    634  1.1      cjs 		} else {
    635  1.1      cjs 			*a_text_fill = 0;
    636  1.1      cjs 	        }
    637  1.1      cjs 	}
    638  1.1      cjs 
    639  1.1      cjs /*###631 [cc] `a_data' undeclared (first use this function)%%%*/
    640  1.1      cjs 	if (a_data != NULL) {
    641  1.1      cjs 		*a_data = ex.a_data;
    642  1.1      cjs 	}
    643  1.1      cjs 
    644  1.1      cjs /*###635 [cc] `a_data_fill' undeclared (first use this function)%%%*/
    645  1.1      cjs 	if (a_data_fill != NULL) {
    646  1.1      cjs 		if (magic == ZMAGIC || magic == NMAGIC) {
    647  1.1      cjs 			*a_data_fill = clbytes - (ex.a_data & clofset);
    648  1.1      cjs 			if (*a_data_fill == clbytes) {
    649  1.1      cjs 				*a_data_fill = 0;
    650  1.1      cjs 			}
    651  1.1      cjs 		} else {
    652  1.1      cjs 			*a_data_fill = 0;
    653  1.1      cjs 	        }
    654  1.1      cjs 	}
    655  1.1      cjs 
    656  1.1      cjs /*###646 [cc] `a_bss' undeclared (first use this function)%%%*/
    657  1.1      cjs 	if (a_bss != NULL) {
    658  1.1      cjs 		*a_bss  = ex.a_bss;
    659  1.1      cjs 	}
    660  1.1      cjs 
    661  1.1      cjs /*###650 [cc] `a_bss_fill' undeclared (first use this function)%%%*/
    662  1.1      cjs 	if (a_bss_fill != NULL) {
    663  1.1      cjs 		if (magic == ZMAGIC || magic == NMAGIC) {
    664  1.1      cjs 			*a_bss_fill = clbytes - (ex.a_bss & clofset);
    665  1.1      cjs 			if (*a_bss_fill == clbytes) {
    666  1.1      cjs 				*a_bss_fill = 0;
    667  1.1      cjs 			}
    668  1.1      cjs 		} else {
    669  1.1      cjs 			*a_bss_fill = clbytes -
    670  1.1      cjs 				((ex.a_text+ex.a_data+ex.a_bss) & clofset);
    671  1.1      cjs 			if (*a_text_fill == clbytes) {
    672  1.1      cjs 				*a_text_fill = 0;
    673  1.1      cjs 			}
    674  1.1      cjs 	        }
    675  1.1      cjs 	}
    676  1.1      cjs 
    677  1.1      cjs /*###665 [cc] `aout' undeclared (first use this function)%%%*/
    678  1.1      cjs 	if (aout != NULL) {
    679  1.1      cjs 		*aout = mid;
    680  1.1      cjs 	}
    681  1.1      cjs 
    682  1.1      cjs 	return(0);
    683  1.1      cjs #endif NOAOUT
    684  1.1      cjs }
    685  1.1      cjs 
    686  1.1      cjs /*###673 [cc] syntax error before `int'%%%*/
    687  1.1      cjs int
    688  1.1      cjs GetFileInfo(fd, load, xfr, aout,
    689  1.1      cjs 	    a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill)
    690  1.1      cjs 	int	fd, *aout;
    691  1.1      cjs 	u_long	*load, *xfr, *a_text, *a_text_fill;
    692  1.1      cjs 	u_long	*a_data, *a_data_fill, *a_bss, *a_bss_fill;
    693  1.1      cjs {
    694  1.1      cjs 	int	err;
    695  1.1      cjs 
    696  1.1      cjs 	err = CheckAOutFile(fd);
    697  1.1      cjs 
    698  1.1      cjs 	if (err == 0) {
    699  1.1      cjs 		err = GetAOutFileInfo(fd, load, xfr,
    700  1.1      cjs 				      a_text, a_text_fill,
    701  1.1      cjs 				      a_data, a_data_fill,
    702  1.1      cjs 				      a_bss, a_bss_fill,
    703  1.1      cjs 				      aout);
    704  1.1      cjs 		if (err != 0) {
    705  1.1      cjs 			return(-1);
    706  1.1      cjs 		}
    707  1.1      cjs 	} else {
    708  1.1      cjs 		err = CheckMopFile(fd);
    709  1.1      cjs 
    710  1.1      cjs 		if (err == 0) {
    711  1.1      cjs 			err = GetMopFileInfo(fd, load, xfr);
    712  1.1      cjs 			if (err != 0) {
    713  1.1      cjs 				return(-1);
    714  1.1      cjs 			}
    715  1.1      cjs 			*aout = -1;
    716  1.1      cjs 		} else {
    717  1.1      cjs 			return(-1);
    718  1.1      cjs 		}
    719  1.1      cjs 	}
    720  1.1      cjs 
    721  1.1      cjs 	return(0);
    722  1.1      cjs }
    723  1.1      cjs 
    724  1.1      cjs ssize_t
    725  1.1      cjs /*###711 [cc] syntax error before `mopFileRead'%%%*/
    726  1.1      cjs mopFileRead(dlslot, buf)
    727  1.1      cjs 	struct dllist *dlslot;
    728  1.1      cjs 	u_char	*buf;
    729  1.1      cjs {
    730  1.1      cjs 	ssize_t len, outlen;
    731  1.1      cjs 	int	bsz;
    732  1.1      cjs 	long	pos, notdone, total;
    733  1.1      cjs 
    734  1.1      cjs /*###719 [cc] `dlslot' undeclared (first use this function)%%%*/
    735  1.1      cjs 	if (dlslot->aout == -1) {
    736  1.1      cjs /*###720 [cc] `buf' undeclared (first use this function)%%%*/
    737  1.1      cjs 		len = read(dlslot->ldfd,buf,dlslot->dl_bsz);
    738  1.1      cjs 	} else {
    739  1.1      cjs 		bsz = dlslot->dl_bsz;
    740  1.1      cjs 		pos = dlslot->a_lseek;
    741  1.1      cjs 		len = 0;
    742  1.1      cjs 
    743  1.1      cjs 		total = dlslot->a_text;
    744  1.1      cjs 
    745  1.1      cjs 		if (pos < total) {
    746  1.1      cjs 			notdone = total - pos;
    747  1.1      cjs 			if (notdone <= bsz) {
    748  1.1      cjs /*###731 [cc] subscripted value is neither array nor pointer%%%*/
    749  1.1      cjs 				outlen = read(dlslot->ldfd,&buf[len],notdone);
    750  1.1      cjs 			} else {
    751  1.1      cjs /*###733 [cc] subscripted value is neither array nor pointer%%%*/
    752  1.1      cjs 				outlen = read(dlslot->ldfd,&buf[len],bsz);
    753  1.1      cjs 			}
    754  1.1      cjs 			len = len + outlen;
    755  1.1      cjs 			pos = pos + outlen;
    756  1.1      cjs 			bsz = bsz - outlen;
    757  1.1      cjs 		}
    758  1.1      cjs 
    759  1.1      cjs 		total = total + dlslot->a_text_fill;
    760  1.1      cjs 
    761  1.1      cjs 		if ((bsz > 0) && (pos < total)) {
    762  1.1      cjs 			notdone = total - pos;
    763  1.1      cjs 			if (notdone <= bsz) {
    764  1.1      cjs 				outlen = notdone;
    765  1.1      cjs 			} else {
    766  1.1      cjs 				outlen = bsz;
    767  1.1      cjs 			}
    768  1.1      cjs /*###749 [cc] subscripted value is neither array nor pointer%%%*/
    769  1.1      cjs 			bzero(&buf[len],outlen);
    770  1.1      cjs 			len = len + outlen;
    771  1.1      cjs 			pos = pos + outlen;
    772  1.1      cjs 			bsz = bsz - outlen;
    773  1.1      cjs 		}
    774  1.1      cjs 
    775  1.1      cjs 		total = total + dlslot->a_data;
    776  1.1      cjs 
    777  1.1      cjs 		if ((bsz > 0) && (pos < total)) {
    778  1.1      cjs 			notdone = total - pos;
    779  1.1      cjs 			if (notdone <= bsz) {
    780  1.1      cjs /*###760 [cc] subscripted value is neither array nor pointer%%%*/
    781  1.1      cjs 				outlen = read(dlslot->ldfd,&buf[len],notdone);
    782  1.1      cjs 			} else {
    783  1.1      cjs /*###762 [cc] subscripted value is neither array nor pointer%%%*/
    784  1.1      cjs 				outlen = read(dlslot->ldfd,&buf[len],bsz);
    785  1.1      cjs 			}
    786  1.1      cjs 			len = len + outlen;
    787  1.1      cjs 			pos = pos + outlen;
    788  1.1      cjs 			bsz = bsz - outlen;
    789  1.1      cjs 		}
    790  1.1      cjs 
    791  1.1      cjs 		total = total + dlslot->a_data_fill;
    792  1.1      cjs 
    793  1.1      cjs 		if ((bsz > 0) && (pos < total)) {
    794  1.1      cjs 			notdone = total - pos;
    795  1.1      cjs 			if (notdone <= bsz) {
    796  1.1      cjs 				outlen = notdone;
    797  1.1      cjs 			} else {
    798  1.1      cjs 				outlen = bsz;
    799  1.1      cjs 			}
    800  1.1      cjs /*###778 [cc] subscripted value is neither array nor pointer%%%*/
    801  1.1      cjs 			bzero(&buf[len],outlen);
    802  1.1      cjs 			len = len + outlen;
    803  1.1      cjs 			pos = pos + outlen;
    804  1.1      cjs 			bsz = bsz - outlen;
    805  1.1      cjs 		}
    806  1.1      cjs 
    807  1.1      cjs 		total = total + dlslot->a_bss;
    808  1.1      cjs 
    809  1.1      cjs 		if ((bsz > 0) && (pos < total)) {
    810  1.1      cjs 			notdone = total - pos;
    811  1.1      cjs 			if (notdone <= bsz) {
    812  1.1      cjs 				outlen = notdone;
    813  1.1      cjs 			} else {
    814  1.1      cjs 				outlen = bsz;
    815  1.1      cjs 			}
    816  1.1      cjs /*###793 [cc] subscripted value is neither array nor pointer%%%*/
    817  1.1      cjs 			bzero(&buf[len],outlen);
    818  1.1      cjs 			len = len + outlen;
    819  1.1      cjs 			pos = pos + outlen;
    820  1.1      cjs 			bsz = bsz - outlen;
    821  1.1      cjs 		}
    822  1.1      cjs 
    823  1.1      cjs 		total = total + dlslot->a_bss_fill;
    824  1.1      cjs 
    825  1.1      cjs 		if ((bsz > 0) && (pos < total)) {
    826  1.1      cjs 			notdone = total - pos;
    827  1.1      cjs 			if (notdone <= bsz) {
    828  1.1      cjs 				outlen = notdone;
    829  1.1      cjs 			} else {
    830  1.1      cjs 				outlen = bsz;
    831  1.1      cjs 			}
    832  1.1      cjs /*###808 [cc] subscripted value is neither array nor pointer%%%*/
    833  1.1      cjs 			bzero(&buf[len],outlen);
    834  1.1      cjs 			len = len + outlen;
    835  1.1      cjs 			pos = pos + outlen;
    836  1.1      cjs 			bsz = bsz - outlen;
    837  1.1      cjs 		}
    838  1.1      cjs 
    839  1.1      cjs 		dlslot->a_lseek = pos;
    840  1.1      cjs 
    841  1.1      cjs 	}
    842  1.1      cjs 
    843  1.1      cjs 	return(len);
    844  1.1      cjs }
    845  1.1      cjs /*###820 [cc] syntax error at end of input%%%*/
    846