|
|
1.1 root 1:
2: /* Console Processor Interface */
3: /* Tahoe version, Nov. 1982 */
4:
5: /****************************************/
6: /* */
7: /* Reduced DCB layout for byte */
8: /* communication. */
9: /* */
10: /****************************************/
11:
12: asm(".set CPMDCB,21");
13: asm(".set DC_OFF,2");
14: asm(".set DC_ON,1");
15: asm(".set MME,9");
16: asm(".set DCR,27");
17: asm(".set PDCS,28");
18: asm(".set CTL_SW,0x41b"); /* Addr of switches to turn on Cache, MME, Fault */
19: long tmp_lw;
20:
21:
22: #define CPBUFLEN 200 /* Output buffer length */
23: struct cphdr
24: {
25: char cp_unit; /* Done bit & unit # */
26: char cp_comm; /* Command */
27: short cp_count; /* Counter (when relevant) */
28: };
29:
30: struct cpdcb_o /* Output structure */
31: {
32: struct cphdr cp_hdr;
33: char cp_buf[CPBUFLEN]; /* Buffer for output or 'stty' */
34: };
35:
36: struct cpdcb_i /* Structure for input */
37: {
38: struct cphdr cp_hdr;
39: char cpi_buf[4]; /* Buffer for input */
40: };
41:
42: #define CPDONE 0x80 /* 'Done' bit in cp_unit */
43: #define CPTAKE 0x40 /* CP 'ack' to this cpdcb */
44:
45: /* Values for 'unit' */
46: #define CPUNIT 0 /* The CP itself */
47: #define CPCONS 1 /* Console line */
48: #define CPREMOT 2 /* Remote line */
49:
50: /* Values for 'command' */
51: #define CPRESET 0
52: #define CPWRITE 1
53: #define CPREAD 2
54: #define CPSTTY 3
55: #define CPBOOT 4
56:
57:
58: /* Put a char to CPU2 console */
59:
60: #define NCHAR 1
61:
62: long cpbuf_sz = 1; /* Buffer size */
63: long charcnt = 0;
64: struct cpdcb_o cpout; /* DCB for output */
65: struct cpdcb_i cpin; /* DCB for input */
66:
67: asm(".set HISR,0x410");
68:
69: putstr(str)
70: char *str;
71: { long c_cnt;
72:
73: cpout.cp_hdr.cp_unit = CPCONS; /* Reset done bit */
74: cpout.cp_hdr.cp_comm = CPWRITE; /* Set command */
75: for(c_cnt=0;;c_cnt++) {
76: cpout.cp_buf[c_cnt] = *str++;
77: if (cpout.cp_buf[c_cnt]=='\n') {
78: c_cnt++;
79: cpout.cp_buf[c_cnt]='\r';
80: }
81: if (cpout.cp_buf[c_cnt]=='\0') break;
82: }
83: if (c_cnt) {
84: cpout.cp_hdr.cp_count = c_cnt;
85: cp_poll('\0'); }
86: }
87:
88: putchar(c)
89: {
90: cpout.cp_hdr.cp_unit = CPCONS; /* Reset done bit */
91: cpout.cp_hdr.cp_comm = CPWRITE; /* Set command */
92: cpout.cp_buf[charcnt] = c;
93: cpout.cp_hdr.cp_count = 1;
94: cp_poll(c);
95: }
96:
97:
98: char rdchar()
99: {
100: register long r12;
101: cpin.cp_hdr.cp_unit = CPCONS; /* Reset done bit */
102: cpin.cp_hdr.cp_comm = CPREAD; /* Set command */
103: cpin.cp_hdr.cp_count = 1;
104: cp_pollr();
105: r12 = (long)(&cpin.cpi_buf[0]);
106: asm("mtpr r12,$0x1c"); /* mtpr r11,$PDCS */
107: return(cpin.cpi_buf[0] & 0x7f);
108: }
109:
110:
111: /* Poll CP on read
112: */
113: cp_pollr()
114: { register long r12, r11, time;
115:
116: r12 = ((long)&cpin) & 0xffffff;
117: asm("mtpr r12,$CPMDCB");
118:
119: r11 = (long)(&cpin.cp_hdr.cp_unit);
120: while (!(cpin.cp_hdr.cp_unit & CPDONE)) {
121: asm("mtpr r11,$0x1c"); /* mtpr r11,$PDCS */
122: }
123: if (!(cpin.cp_hdr.cp_unit & CPDONE)) cp_hlt(); /* Time out */
124: }
125:
126:
127: /* Poll CP on write
128: */
129: cp_poll(c)
130: char c;
131: { register long r12, r11, time;
132:
133: time = 200000;
134: r12 = ((long)&cpout) & 0xffffff;
135: asm("mtpr r12,$CPMDCB");
136: asm("mtpr r12,$CPMDCB");
137:
138: r11 = (long)(&cpout.cp_hdr.cp_unit);
139: while (time-- && !(cpout.cp_hdr.cp_unit & CPDONE)) {
140: asm("mtpr r11,$0x1c"); /* mtpr r11,$PDCS */
141: }
142: if (!(cpout.cp_hdr.cp_unit & CPDONE)) cp_hlt(); /* Time out */
143: if (c== '\n') putchar('\r');
144: }
145:
146: cp_hlt()
147: {
148: asm("movl $0xeeeeeeee,r0");
149: asm("movl $0xeeeeeeee,r1");
150: asm("movl $0xeeeeeeee,r2");
151: asm("halt");
152: }
153:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.