|
|
1.1 root 1: #include <libc.h>
2: #include <fio.h>
3: #include <ctype.h>
4: #include <sysent.h>
5: #include <string.h>
6: #include "crossbar.h"
7:
8: int rread(int fd, char *buf, int n);
9:
10: System10::System10(char *dkname, int n, int depth) : (dkname, n, depth)
11: {
12: }
13:
14: void
15: System10::startup()
16: {
17: int i, n;
18: char buf[256];
19: extern int opendk(char *);
20:
21: fd = opendk(dial);
22: for(i = 0; i < 3; i++){
23: write(fd, "@\r", 2);
24: read(fd, buf, 3);
25: if((n = read(fd, buf, sizeof buf)) != 3){
26: fprint(2, "read %d, wanted %d: %s: ", n, 3, buf);
27: perror("read");
28: exit(1);
29: }
30: if(strncmp(buf, "@\r", 2) == 0)
31: break;
32: }
33: }
34:
35: int
36: System10::connect(int input, Crossbar *c, int output, int nw)
37: {
38: char buf[256];
39: int n;
40:
41: if(fd < 0)
42: startup();
43: if(c != this){
44: if(nextc->connect(nextl, c, output, nw) == 0)
45: return(0);
46: output = froml;
47: }
48: nw /= nwires;
49: while(nw-- > 0){
50: fprint(fd, "%d%d\r", output, input);
51: n = read(fd, buf, 7);
52: if(n != 7){
53: fprint(2, "%s.con %d->%d failed; %d!=7\n", name(), input, output, n);
54: return(0);
55: }
56: input++, output++;
57: }
58: return(1);
59: }
60:
61: void
62: System10::config()
63: {
64: int i, n;
65: char buf[256], *s;
66:
67: imap = new int[nouts];
68: write(fd, "?\r", 2);
69: read(fd, buf, 3);
70: if((n = rread(fd, buf, 31)) < 0){
71: perror("read2");
72: exit(1);
73: }
74: if(n != 31){
75: fprint(2, "erk! read expected 31, got %d '%s'\n", n, buf);
76: exit(1);
77: }
78: for(i = 0, s = buf; i < 10; i++){
79: if(!isdigit(*s)){
80: fprint(2, "erk: output must be digit '%s'\n", s);
81: exit(1);
82: }
83: if(!isdigit(s[1])){
84: fprint(2, "erk: input must be digit '%s'\n", s+1);
85: exit(1);
86: }
87: imap[*s-'0'] = s[1]-'0';
88: if(0)Fprint(1, "%c<-%c ", s[0], s[1]);
89: s += 3;
90: }
91: if(0)Fprint(1, "\n"), Fflush(1);
92: }
93:
94: int
95: rread(int fd, char *buf, int n)
96: {
97: int k, m = 0;
98:
99: while(m != n){
100: buf[m]=0;fprint(2, "read %d of %d '%s'\n", m, n, buf);
101: k = read(fd, &buf[m], n-m);
102: if(k < 0)
103: return(k);
104: if(k == 0)
105: break;
106: m += k;
107: }
108: return(m);
109: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.