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