Home | History | Annotate | Line # | Download | only in common
      1  1.9  christos /*	$NetBSD: dl.c,v 1.9 2016/06/08 01:11:49 christos Exp $	*/
      2  1.2   thorpej 
      3  1.1       cjs /*
      4  1.1       cjs  * Copyright (c) 1993-95 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  *
     15  1.1       cjs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.1       cjs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  1.1       cjs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  1.1       cjs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  1.1       cjs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  1.1       cjs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  1.1       cjs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  1.1       cjs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  1.1       cjs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  1.1       cjs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  1.1       cjs  */
     26  1.1       cjs 
     27  1.9  christos #include "port.h"
     28  1.3     lukem #ifndef lint
     29  1.9  christos __RCSID("$NetBSD: dl.c,v 1.9 2016/06/08 01:11:49 christos Exp $");
     30  1.1       cjs #endif
     31  1.1       cjs 
     32  1.1       cjs #include "os.h"
     33  1.3     lukem #include "dl.h"
     34  1.3     lukem #include "get.h"
     35  1.3     lukem #include "mopdef.h"
     36  1.3     lukem #include "print.h"
     37  1.1       cjs 
     38  1.1       cjs void
     39  1.7  drochner mopDumpDL(FILE *fd, const u_char *pkt, int trans)
     40  1.1       cjs {
     41  1.5     lukem 	int	i,idx = 0;
     42  1.3     lukem 	u_int32_t tmpl;
     43  1.7  drochner 	u_char	tmpc,c,program[257],code;
     44  1.7  drochner 	const u_char *ucp;
     45  1.1       cjs 	u_short	len,tmps,moplen;
     46  1.1       cjs 
     47  1.1       cjs 	len = mopGetLength(pkt, trans);
     48  1.1       cjs 
     49  1.1       cjs 	switch (trans) {
     50  1.1       cjs 	case TRANS_8023:
     51  1.5     lukem 		idx = 22;
     52  1.1       cjs 		moplen = len - 8;
     53  1.1       cjs 		break;
     54  1.1       cjs 	default:
     55  1.5     lukem 		idx = 16;
     56  1.1       cjs 		moplen = len;
     57  1.1       cjs 	}
     58  1.5     lukem 	code = mopGetChar(pkt,&idx);
     59  1.1       cjs 
     60  1.1       cjs 	switch (code) {
     61  1.1       cjs 	case MOP_K_CODE_MLT:
     62  1.1       cjs 
     63  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Load Number */
     64  1.1       cjs 		(void)fprintf(fd,"Load Number  :   %02x\n",tmpc);
     65  1.1       cjs 
     66  1.1       cjs 		if (moplen > 6) {
     67  1.5     lukem 			tmpl = mopGetLong(pkt,&idx);/* Load Address */
     68  1.3     lukem 			(void)fprintf(fd,"Load Address : %08x\n", tmpl);
     69  1.1       cjs 		}
     70  1.1       cjs 
     71  1.1       cjs 		if (moplen > 10) {
     72  1.1       cjs #ifndef SHORT_PRINT
     73  1.1       cjs 			for (i = 0; i < (moplen - 10); i++) {
     74  1.1       cjs 				if ((i % 16) == 0) {
     75  1.1       cjs 					if ((i / 16) == 0) {
     76  1.1       cjs 					 	(void)fprintf(fd,
     77  1.1       cjs 						       "Image Data   : %04x ",
     78  1.1       cjs 							      moplen-10);
     79  1.1       cjs 					} else {
     80  1.1       cjs 						(void)fprintf(fd,
     81  1.1       cjs 						       "                    ");
     82  1.1       cjs 				        }
     83  1.1       cjs 				}
     84  1.1       cjs 
     85  1.1       cjs 				(void)fprintf(fd, "%02x ",
     86  1.5     lukem 					      mopGetChar(pkt,&idx));
     87  1.1       cjs 				if ((i % 16) == 15)
     88  1.1       cjs 					(void)fprintf(fd,"\n");
     89  1.1       cjs 			}
     90  1.1       cjs 
     91  1.1       cjs 			if ((i % 16) != 15)
     92  1.1       cjs 				(void)fprintf(fd,"\n");
     93  1.1       cjs #else
     94  1.5     lukem 			idx = idx + moplen - 10;
     95  1.1       cjs #endif
     96  1.1       cjs 		}
     97  1.1       cjs 
     98  1.5     lukem 		tmpl = mopGetLong(pkt,&idx);	/* Load Address */
     99  1.3     lukem 		(void)fprintf(fd,"Xfer Address : %08x\n", tmpl);
    100  1.1       cjs 
    101  1.1       cjs 		break;
    102  1.1       cjs 	case MOP_K_CODE_DCM:
    103  1.1       cjs 
    104  1.1       cjs 		/* Empty Message */
    105  1.1       cjs 
    106  1.1       cjs 		break;
    107  1.1       cjs 	case MOP_K_CODE_MLD:
    108  1.1       cjs 
    109  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Load Number */
    110  1.1       cjs 		(void)fprintf(fd,"Load Number  :   %02x\n",tmpc);
    111  1.1       cjs 
    112  1.5     lukem 		tmpl = mopGetLong(pkt,&idx);	/* Load Address */
    113  1.3     lukem 		(void)fprintf(fd,"Load Address : %08x\n", tmpl);
    114  1.1       cjs 
    115  1.1       cjs 		if (moplen > 6) {
    116  1.1       cjs #ifndef SHORT_PRINT
    117  1.1       cjs 			for (i = 0; i < (moplen - 6); i++) {
    118  1.1       cjs 				if ((i % 16) == 0) {
    119  1.1       cjs 					if ((i / 16) == 0) {
    120  1.1       cjs 						(void)fprintf(fd,
    121  1.1       cjs 						       "Image Data   : %04x ",
    122  1.1       cjs 							      moplen-6);
    123  1.1       cjs 					} else {
    124  1.1       cjs 						(void)fprintf(fd,
    125  1.1       cjs 						       "                    ");
    126  1.1       cjs 					}
    127  1.1       cjs 				}
    128  1.1       cjs 				(void)fprintf(fd,"%02x ",
    129  1.5     lukem 					      mopGetChar(pkt,&idx));
    130  1.1       cjs 				if ((i % 16) == 15)
    131  1.1       cjs 					(void)fprintf(fd,"\n");
    132  1.1       cjs 			}
    133  1.1       cjs 
    134  1.1       cjs 			if ((i % 16) != 15)
    135  1.1       cjs 				(void)fprintf(fd,"\n");
    136  1.1       cjs #else
    137  1.5     lukem 			idx = idx + moplen - 6;
    138  1.1       cjs #endif
    139  1.1       cjs 		}
    140  1.1       cjs 
    141  1.1       cjs 		break;
    142  1.1       cjs 	case MOP_K_CODE_ASV:
    143  1.1       cjs 
    144  1.1       cjs 		/* Empty Message */
    145  1.1       cjs 
    146  1.1       cjs 		break;
    147  1.1       cjs 	case MOP_K_CODE_RMD:
    148  1.1       cjs 
    149  1.5     lukem 		tmpl = mopGetLong(pkt,&idx);	/* Memory Address */
    150  1.3     lukem 		(void)fprintf(fd,"Mem Address  : %08x\n", tmpl);
    151  1.1       cjs 
    152  1.5     lukem 		tmps = mopGetShort(pkt,&idx);	/* Count */
    153  1.1       cjs 		(void)fprintf(fd,"Count        : %04x (%d)\n",tmps,tmps);
    154  1.1       cjs 
    155  1.1       cjs 		break;
    156  1.1       cjs 	case MOP_K_CODE_RPR:
    157  1.1       cjs 
    158  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Device Type */
    159  1.1       cjs 		(void)fprintf(fd, "Device Type  :   %02x ",tmpc);
    160  1.1       cjs 		mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n");
    161  1.1       cjs 
    162  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Format Version */
    163  1.1       cjs 		(void)fprintf(fd,"Format       :   %02x\n",tmpc);
    164  1.1       cjs 
    165  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Program Type */
    166  1.1       cjs 		(void)fprintf(fd,"Program Type :   %02x ",tmpc);
    167  1.1       cjs 		mopPrintPGTY(fd, tmpc); (void)fprintf(fd, "\n");
    168  1.1       cjs 
    169  1.1       cjs 		program[0] = 0;
    170  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Software ID Len */
    171  1.1       cjs 		for (i = 0; i < tmpc; i++) {
    172  1.5     lukem 			program[i] = mopGetChar(pkt,&idx);
    173  1.1       cjs 			program[i+1] = '\0';
    174  1.1       cjs 		}
    175  1.1       cjs 
    176  1.1       cjs 		(void)fprintf(fd,"Software     :   %02x '%s'\n",tmpc,program);
    177  1.1       cjs 
    178  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Processor */
    179  1.1       cjs 		(void)fprintf(fd,"Processor    :   %02x ",tmpc);
    180  1.1       cjs 		mopPrintBPTY(fd, tmpc); (void)fprintf(fd, "\n");
    181  1.1       cjs 
    182  1.5     lukem 		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
    183  1.1       cjs 
    184  1.1       cjs 		break;
    185  1.1       cjs 	case MOP_K_CODE_RML:
    186  1.1       cjs 
    187  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Load Number */
    188  1.1       cjs 		(void)fprintf(fd,"Load Number  :   %02x\n",tmpc);
    189  1.1       cjs 
    190  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Error */
    191  1.1       cjs 		(void)fprintf(fd,"Error        :   %02x (",tmpc);
    192  1.8     joerg 		if (tmpc == 0) {
    193  1.1       cjs 			(void)fprintf(fd,"no error)\n");
    194  1.1       cjs 		} else {
    195  1.1       cjs 		  	(void)fprintf(fd,"error)\n");
    196  1.1       cjs 		}
    197  1.1       cjs 
    198  1.1       cjs 		break;
    199  1.1       cjs 	case MOP_K_CODE_RDS:
    200  1.1       cjs 
    201  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Device Type */
    202  1.1       cjs 		(void)fprintf(fd, "Device Type  :   %02x ",tmpc);
    203  1.1       cjs 		mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n");
    204  1.1       cjs 
    205  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Format Version */
    206  1.1       cjs 		(void)fprintf(fd,"Format       :   %02x\n",tmpc);
    207  1.1       cjs 
    208  1.5     lukem 		tmpl = mopGetLong(pkt,&idx);	/* Memory Size */
    209  1.3     lukem 		(void)fprintf(fd,"Memory Size  : %08x\n", tmpl);
    210  1.1       cjs 
    211  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Bits */
    212  1.1       cjs 		(void)fprintf(fd,"Bits         :   %02x\n",tmpc);
    213  1.1       cjs 
    214  1.5     lukem 		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
    215  1.1       cjs 
    216  1.1       cjs 		break;
    217  1.1       cjs 	case MOP_K_CODE_MDD:
    218  1.1       cjs 
    219  1.5     lukem 		tmpl = mopGetLong(pkt,&idx);	/* Memory Address */
    220  1.3     lukem 		(void)fprintf(fd,"Mem Address  : %08x\n", tmpl);
    221  1.1       cjs 
    222  1.1       cjs 		if (moplen > 5) {
    223  1.1       cjs #ifndef SHORT_PRINT
    224  1.1       cjs 			for (i = 0; i < (moplen - 5); i++) {
    225  1.1       cjs 				if ((i % 16) == 0) {
    226  1.1       cjs 					if ((i / 16) == 0) {
    227  1.1       cjs 						(void)fprintf(fd,
    228  1.1       cjs 						       "Image Data   : %04x ",
    229  1.1       cjs 							      moplen-5);
    230  1.1       cjs 					} else {
    231  1.1       cjs 						(void)fprintf(fd,
    232  1.1       cjs 						       "                    ");
    233  1.1       cjs 				        }
    234  1.1       cjs 				}
    235  1.1       cjs 				(void)fprintf(fd,"%02x ",
    236  1.5     lukem 					      mopGetChar(pkt,&idx));
    237  1.1       cjs 				if ((i % 16) == 15)
    238  1.1       cjs 					(void)fprintf(fd,"\n");
    239  1.1       cjs 			}
    240  1.1       cjs 			if ((i % 16) != 15)
    241  1.1       cjs 				(void)fprintf(fd,"\n");
    242  1.1       cjs #else
    243  1.5     lukem 			idx = idx + moplen - 5;
    244  1.1       cjs #endif
    245  1.1       cjs 		}
    246  1.1       cjs 
    247  1.1       cjs 		break;
    248  1.1       cjs 	case MOP_K_CODE_PLT:
    249  1.1       cjs 
    250  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Load Number */
    251  1.1       cjs 		(void)fprintf(fd,"Load Number  :   %02x\n",tmpc);
    252  1.1       cjs 
    253  1.5     lukem 		tmpc = mopGetChar(pkt,&idx);	/* Parameter Type */
    254  1.1       cjs 		while (tmpc != MOP_K_PLTP_END) {
    255  1.5     lukem 			c = mopGetChar(pkt,&idx);	/* Parameter Length */
    256  1.1       cjs 			switch(tmpc) {
    257  1.1       cjs 			case MOP_K_PLTP_TSN:		/* Target Name */
    258  1.1       cjs 				(void)fprintf(fd,"Target Name  :   %02x '",
    259  1.1       cjs 					      tmpc);
    260  1.1       cjs 				for (i = 0; i < ((int) c); i++) {
    261  1.1       cjs 					(void)fprintf(fd,"%c",
    262  1.5     lukem 						    mopGetChar(pkt,&idx));
    263  1.1       cjs 				}
    264  1.1       cjs 				(void)fprintf(fd,"'\n");
    265  1.1       cjs 				break;
    266  1.1       cjs 			case MOP_K_PLTP_TSA:		/* Target Address */
    267  1.1       cjs 				(void)fprintf(fd,"Target Addr  :   %02x ",c);
    268  1.1       cjs 				for (i = 0; i < ((int) c); i++) {
    269  1.1       cjs 					(void)fprintf(fd,"%02x ",
    270  1.5     lukem 						    mopGetChar(pkt,&idx));
    271  1.1       cjs 				}
    272  1.1       cjs 				(void)fprintf(fd,"\n");
    273  1.1       cjs 				break;
    274  1.1       cjs 			case MOP_K_PLTP_HSN:		/* Host Name */
    275  1.1       cjs 				(void)fprintf(fd,"Host Name    :   %02x '",
    276  1.1       cjs 					      tmpc);
    277  1.1       cjs 				for (i = 0; i < ((int) c); i++) {
    278  1.1       cjs 					(void)fprintf(fd,"%c",
    279  1.5     lukem 						    mopGetChar(pkt,&idx));
    280  1.1       cjs 				}
    281  1.1       cjs 				(void)fprintf(fd,"'\n");
    282  1.1       cjs 				break;
    283  1.1       cjs 			case MOP_K_PLTP_HSA:		/* Host Address */
    284  1.1       cjs 				(void)fprintf(fd,"Host Addr    :   %02x ",c);
    285  1.1       cjs 				for (i = 0; i < ((int) c); i++) {
    286  1.1       cjs 					(void)fprintf(fd,"%02x ",
    287  1.5     lukem 						    mopGetChar(pkt,&idx));
    288  1.1       cjs 				}
    289  1.1       cjs 				(void)fprintf(fd,"\n");
    290  1.1       cjs 				break;
    291  1.1       cjs 			case MOP_K_PLTP_HST:		/* Host Time */
    292  1.5     lukem 				ucp = pkt + idx; idx = idx + 10;
    293  1.1       cjs 				(void)fprintf(fd,"Host Time    : ");
    294  1.1       cjs 				mopPrintTime(fd, ucp);
    295  1.1       cjs 				(void)fprintf(fd,"\n");
    296  1.1       cjs 				break;
    297  1.1       cjs 			default:
    298  1.1       cjs 				break;
    299  1.1       cjs 			}
    300  1.5     lukem 			tmpc = mopGetChar(pkt,&idx);/* Parameter Type */
    301  1.1       cjs 		}
    302  1.1       cjs 
    303  1.5     lukem 		tmpl = mopGetLong(pkt,&idx);	/* Transfer Address */
    304  1.3     lukem 		(void)fprintf(fd,"Transfer Addr: %08x\n", tmpl);
    305  1.1       cjs 
    306  1.1       cjs 		break;
    307  1.1       cjs 	default:
    308  1.1       cjs 		break;
    309  1.1       cjs 	}
    310  1.1       cjs }
    311  1.1       cjs 
    312  1.1       cjs 
    313