|
|
1.1 root 1: #include <libc.h>
2: #include <fio.h>
3: #include "crossbar.h"
4: #include "switch.h"
5:
6: extern int verbose;
7:
8: Switch::Switch(char *nam, int n)
9: {
10: int i;
11:
12: name = nam;
13: nwires = n;
14: maxlines = 0;
15: for(i = 0; i < MAXLABEL; i++)
16: lines[i][0] = lines[i][1] = 0;
17: }
18:
19: void
20: Switch::add(int inout, char label, char *n1, char *n2, Crossbar *c, int l)
21: {
22: int n = labeltoint(label);
23:
24: if(n > maxlines)
25: maxlines = n;
26: if(lines[n][inout])
27: fprint(2, "warning: redefining label %s.%c\n", name, label);
28: lines[n][inout] = new Line(label, n1, n2, c, l);
29: }
30:
31: void
32: Switch::reinit()
33: {
34: }
35:
36: void
37: Switch::describe()
38: {
39: int imax, omax, n, i;
40: char bi[256], bo[256];
41:
42: if(verbose)
43: Fprint(1, "%s video switch:\n", name);
44: imax = 6, omax = 7; /* inputs/outputs */
45: for(i = 0; i <= maxlines; i++){
46: n = lines[i][0]->pr(i, bi, 0);
47: if(n > imax) imax = n;
48: n = lines[i][1]->pr(i, bi, 0);
49: if(n > omax) omax = n;
50: }
51: blank(1, n = (imax-6)/2);
52: Fprint(1, "inputs");
53: blank(1, imax+3+(omax-7)/2-n-6);
54: Fprint(1, "outputs\n");
55: for(i = 0; i <= maxlines; i++){
56: lines[i][0]->pr(i, bi, imax+3);
57: lines[i][1]->pr(i, bo, 0);
58: Fprint(1, "%s%s\n", bi, bo);
59: }
60: }
61:
62: void
63: Switch::pr(char opt)
64: {
65: int i, j, l[50], k;
66: Crossbar *c[50];
67: Line *lp, *ll;
68: char buf[256];
69: int didit;
70:
71: if(!verbose)
72: Fprint(1, "-%c", opt);
73: for(i = 0; i <= maxlines; i++)
74: if(ll = lines[i][0]){
75: if(k = ll->c->map(ll->line, c, l)){
76: didit = 0;
77: for(j = 0; c[j]; j++)
78: if((k = lineofcl(1, c[j], l[j])) >= 0){
79: if(didit == 0){
80: if(verbose)
81: Fprint(1, "%s[i%c] ==>", ll->name[0], ll->label);
82: didit = 1;
83: }
84: lp = lines[k][1];
85: if(verbose)
86: Fprint(1, " %s[o%c]", lp->name[0], lp->label);
87: else
88: Fprint(1, " %c%c", lines[i][1]->label, lp->label);
89: }
90: if(didit && verbose)
91: Fprint(1, "\n");
92: }
93: }
94: if(!verbose)
95: Fprint(1, "\n");
96: }
97:
98: void
99: Switch::connect(char input, char output)
100: {
101: int i, o;
102: Line *lp;
103:
104: i = labeltoint(input);
105: o = labeltoint(output);
106: lp = lines[i][0];
107: lp->c->connect(lp->line, lines[o][1]->c, lines[o][1]->line, nwires);
108: }
109:
110: int
111: Switch::lineofcl(int output, Crossbar *c, int l)
112: {
113: int i;
114: register Line *lp;
115:
116: for(i = 0; i <= maxlines; i++){
117: lp = lines[i][output];
118: if((lp->c == c) && (lp->line == l))
119: return(i);
120: }
121: return(-1);
122: }
123:
124: int
125: labeltoint(char label)
126: {
127: if((label >= '0') && (label <= '9'))
128: return(label-'0');
129: if((label >= 'a') && (label <= 'z'))
130: return((label-'a')+10);
131: fprint(2, "bad arg to labeltoint '%c'\n", label);
132: abort();
133: return(0);
134: }
135:
136: char
137: inttolabel(int i)
138: {
139: if((i >= 0) && (i < MAXLABEL))
140: return("0123456789abcdefghijklmnopqrstuvwxyz"[i]);
141: fprint(2, "bad arg to inttolabel %d\n", i);
142: abort();
143: return(0);
144: }
145:
146: void
147: blank(int fd, int n)
148: {
149: while(n-- > 0)
150: Fputc(fd, ' ');
151: }
152:
153: #include <sys/filio.h>
154: #include <sys/ttyio.h>
155: #include <sysent.h>
156: #include <ipc.h>
157:
158: int
159: opendk(char *name)
160: {
161: int rfs;
162: char buf[256];
163: struct sgttyb vvec;
164: extern int tty_ld, buf_ld;
165:
166: sprint(buf, "/cs/dk!%s", name);
167: rfs = ipcopen(buf, "light");
168: if(rfs < 0){
169: perror(buf);
170: exit(1);
171: }
172: ioctl(rfs, FIOPUSHLD, &buf_ld);
173: if(ioctl(rfs, FIOLOOKLD, 0) != tty_ld){
174: if(ioctl(rfs, FIOPUSHLD, &tty_ld) < 0){
175: perror("tty_ld");
176: exit(1);
177: }
178: }
179: vvec.sg_flags = RAW;
180: vvec.sg_erase = 0;
181: vvec.sg_kill = 0;
182: if(ioctl(rfs, TIOCSETP, &vvec) < 0){
183: perror("ioctl");
184: exit(1);
185: }
186: return(rfs);
187: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.