1: 
   2: /*
   3:  * Hyperchannel Log Printer
   4:  *
   5:  * Copyright (c) 1983, Tektronix Inc.
   6:  * All Rights Reserved
   7:  *
   8:  */
   9: 
  10: 
  11: char _rcsid[] = "$Header: hylog.c,v 2.5 84/10/10 04:42:56 steveg Exp $$Locker:  $";
  12: 
  13: #define ok(x) (((int)(x)) & 0x7fffffff)
  14: #define HYLOG
  15: 
  16: #include <stdio.h>
  17: #include <nlist.h>
  18: #include <sys/types.h>
  19: #include <sys/socket.h>
  20: #include <sys/ioctl.h>
  21: #include <netinet/in.h>
  22: #include <net/if.h>
  23: #include <vaxif/if_hyreg.h>
  24: #include <vaxif/if_hy.h>
  25: 
  26: struct nlist nl[2] = {
  27:     { "_hy_log" },
  28:     { 0 }
  29: };
  30: 
  31: struct hy_log hy_log;
  32: 
  33: char *kernel = "/vmunix";
  34: char *kmem = "/dev/kmem";
  35: 
  36: main(argc, argv)
  37: int argc;
  38: char *argv[];
  39: {
  40:     register unsigned char *p, *ep;
  41:     register unsigned len;
  42:     int mem;
  43: 
  44:     if (argc > 1)
  45:         kernel = argv[1];
  46:     if (argc > 2)
  47:         kmem = argv[2];
  48:     nlist(kernel, nl);
  49:     if (nl[0].n_type == 0)
  50:         done("No namelist\n");
  51:     if ((mem = open(kmem, 0)) < 0)
  52:         done("Can't open \"/dev/kmem\" file\n");
  53:     lseek(mem, (long)nl[0].n_value, 0);
  54:     read(mem, &hy_log, sizeof(hy_log));
  55:     if (ok(hy_log.hyl_self) != ok(nl[0].n_value))
  56:         done("hy_log.hyl_self not self referencing (namelist mismatch?)\n");
  57:     ep = &hy_log.hyl_buf[ok(hy_log.hyl_ptr) -
  58:         ok(& ( (struct hy_log *) (nl[0].n_value) )->hyl_buf[0])];
  59:     p = &hy_log.hyl_buf[0];
  60: 
  61:     printf("%d bytes in log buffer\n", ep - p);
  62: 
  63: #define plong(name) \
  64:     printf(" %s %08lx", name, *(unsigned long *)p); \
  65:     p += sizeof(unsigned long);
  66: 
  67: #define pnlong(name) \
  68:     printf(" %s %02x%02x%02x%02x", name, p[0], p[1], p[2], p[3]); \
  69:     p += sizeof(unsigned long);
  70: 
  71: #define pnshort(name) \
  72:     printf(" %s %02x%02x", name, p[0], p[1]); \
  73:     p += sizeof(unsigned short);
  74: 
  75: #define pshort(name) \
  76:     printf(" %s %04x", name, *(unsigned short *)p); \
  77:     p += sizeof(unsigned short);
  78: 
  79: #define pbyte(name) printf(" %s %02x", name, *p++);
  80: 
  81: #define phdr() \
  82:     pnshort("crtl"); \
  83:     pnshort("access"); \
  84:     putchar('\n'); \
  85:     putchar('\t'); \
  86:     pnshort("to"); \
  87:     pnshort("from"); \
  88:     pnshort("param"); \
  89:     pbyte("type"); \
  90:     pbyte("off");
  91: 
  92:     while (p < ep) {
  93:         switch(*p++) {
  94:         case HYL_NOP:
  95:             printf("nop -\n");
  96:             goto out;
  97: 
  98:         case HYL_UP:            /* no data */
  99:             printf("up -");
 100:             goto printdata;
 101: 
 102:         case HYL_STATUS:
 103:             printf("status -");
 104:             goto printdata;
 105: 
 106:         case HYL_STATISTICS:
 107:             printf("statistics -");
 108:             if (*p != sizeof(struct hy_stat))
 109:                 goto printdata;
 110:             p++;
 111:             pnlong("msgcnt"); pnlong("dbcnt");
 112:             pnlong("tbusy");  pnlong("hwret");
 113:             putchar('\n');
 114:             putchar('\t');
 115:             pnlong("crcbad"); pnlong("mcret"); pnlong("tdabort");
 116:             pbyte("atype");
 117:             pbyte("");
 118:             pbyte("rev");
 119:             pbyte("address");
 120:             break;
 121: 
 122:         case HYL_XMIT:
 123:             printf("xmt -");
 124:             if (*p != (sizeof(struct hy_hdr) + sizeof(short)))
 125:                 goto printdata;
 126:             p++;
 127:             pshort("mplen");
 128:             phdr();
 129:             break;
 130: 
 131:         case HYL_RECV:
 132:             printf("rcv -");
 133:             if (*p != (sizeof(struct hy_hdr) + sizeof(short)))
 134:                 goto printdata;
 135:             p++;
 136:             pshort("length");
 137:             phdr();
 138:             break;
 139: 
 140:         case HYL_CMD:
 141:             printf("cmd -");
 142:             if (*p != 4)
 143:                 goto printdata;
 144:             p++;
 145:             pbyte("cmd");
 146:             pbyte("state");
 147:             pshort("count");
 148:             break;
 149: 
 150:         case HYL_INT:
 151:             printf("int -");
 152:             if (*p == 4) {
 153:                 p++;
 154:                 pshort("csr");
 155:                 pshort("wcr");
 156:             } else if (*p == 6) {
 157:                 p++;
 158:                 pbyte("state");
 159:                 pbyte("flags");
 160:                 pshort("csr");
 161:                 pshort("wcr");
 162:             } else
 163:                 goto printdata;
 164:             break;
 165: 
 166:         default:
 167:             printf("unknown %d -", *p);
 168:         printdata:
 169:             len = *p++;
 170:             while (len > 0) {
 171:                 printf(" %02x", *p++);
 172:                 len--;
 173:             }
 174:             break;
 175:         }
 176:         putchar('\n');
 177:     }
 178: 
 179: out:
 180:     printf("end of log\n");
 181: }
 182: 
 183: done(s, p)
 184:     char *s;
 185:     int p;
 186: {
 187:     fprintf(stderr, s, &p);
 188:     exit(1);
 189: }

Defined functions

done defined in line 183; used 3 times
main defined in line 36; never used

Defined variables

_rcsid defined in line 11; never used
hy_log defined in line 31; used 6 times
kernel defined in line 33; used 2 times
kmem defined in line 34; used 2 times
nl defined in line 26; used 5 times

Defined macros

HYLOG defined in line 14; never used
ok defined in line 13; used 4 times
pbyte defined in line 79; used 10 times
phdr defined in line 81; used 2 times
plong defined in line 63; never used
pnlong defined in line 67; used 7 times
pnshort defined in line 71; used 5 times
pshort defined in line 75; used 7 times
Last modified: 1984-10-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1124
Valid CSS Valid XHTML 1.0 Strict