Annotation of sys/arch/vax/boot/boot/consio.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: consio.c,v 1.7 2006/08/30 20:02:13 miod Exp $ */
2: /* $NetBSD: consio.c,v 1.13 2002/05/24 21:40:59 ragge Exp $ */
3: /*
4: * Copyright (c) 1994, 1998 Ludd, University of Lule}, Sweden.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed at Ludd, University of Lule}.
18: * 4. The name of the author may not be used to endorse or promote products
19: * derived from this software without specific prior written permission
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31: */
32:
33: /* All bugs are subject to removal without further notice */
34:
35:
36:
37: #include "sys/param.h"
38:
39: #include "../vax/gencons.h"
40:
41: #include "mtpr.h"
42: #include "sid.h"
43: #include "rpb.h"
44: #include "ka630.h"
45:
46: #include "data.h"
47:
48: void setup(void);
49:
50: static void (*put_fp)(int) = NULL;
51: static int (*get_fp)(void) = NULL;
52: static int (*test_fp)(void) = NULL;
53:
54: void pr_putchar(int c); /* putchar() using mtpr/mfpr */
55: int pr_getchar(void);
56: int pr_testchar(void);
57:
58: void rom_putchar(int c); /* putchar() using ROM routines */
59: int rom_getchar(void);
60: int rom_testchar(void);
61:
62: int rom_putc; /* ROM-address of put-routine */
63: int rom_getc; /* ROM-address of get-routine */
64:
65: /* Pointer to KA630 console page, initialized by ka630_consinit */
66: unsigned char *ka630_conspage;
67:
68: /* Function that initializes things for KA630 ROM console I/O */
69: void ka630_consinit(void);
70:
71: /* Functions that use KA630 ROM for console I/O */
72: void ka630_rom_putchar(int c);
73: int ka630_rom_getchar(void);
74: int ka630_rom_testchar(void);
75:
76: /* Also added such a thing for KA53 - MK-991208 */
77: unsigned char *ka53_conspage;
78: void ka53_consinit(void);
79:
80: void ka53_rom_putchar(int c);
81: int ka53_rom_getchar(void);
82: int ka53_rom_testchar(void);
83:
84: void vxt_putchar(int c);
85: int vxt_getchar(void);
86: int vxt_testchar(void);
87:
88: void putchar(int);
89: int getchar(void);
90: int testkey(void);
91: void consinit(void);
92: void _rtt(void);
93:
94: void
95: putchar(int c)
96: {
97: (*put_fp)(c);
98: if (c == 10)
99: (*put_fp)(13); /* CR/LF */
100: }
101:
102: int
103: getchar(void)
104: {
105: int c;
106:
107: do
108: c = (*get_fp)() & 0177;
109: while (c == 17 || c == 19); /* ignore XON/XOFF */
110: if (c < 96 && c > 64)
111: c += 32;
112: return c;
113: }
114:
115: int
116: testkey(void)
117: {
118: return (*test_fp)();
119: }
120:
121: /*
122: * setup() is called out of the startup files (start.s, srt0.s) and
123: * initializes data which are globally used and is called before main().
124: */
125: void
126: consinit(void)
127: {
128: put_fp = pr_putchar; /* Default */
129: get_fp = pr_getchar;
130: test_fp = pr_testchar;
131:
132: /*
133: * According to the vax_boardtype (vax_cputype is not specific
134: * enough to do that) we decide which method/routines to use
135: * for console I/O.
136: * mtpr/mfpr are restricted to serial consoles, ROM-based routines
137: * support both serial and graphical consoles.
138: * We default to mtpr routines; so that we don't crash if
139: * it isn't a supported system.
140: */
141: switch (vax_boardtype) {
142:
143: case VAX_BTYP_43:
144: case VAX_BTYP_410:
145: case VAX_BTYP_420:
146: put_fp = rom_putchar;
147: get_fp = rom_getchar;
148: test_fp = rom_testchar;
149: rom_putc = 0x20040058; /* 537133144 */
150: rom_getc = 0x20040044; /* 537133124 */
151: break;
152:
153: case VAX_BTYP_VXT:
154: put_fp = rom_putchar;
155: get_fp = vxt_getchar;
156: test_fp = vxt_testchar;
157: rom_putc = 0x20040058; /* 537133144 */
158: rom_getc = 0x20040044; /* 537133124 */
159: break;
160:
161: case VAX_BTYP_630:
162: ka630_consinit();
163: break;
164:
165: case VAX_BTYP_46:
166: case VAX_BTYP_48:
167: case VAX_BTYP_49:
168: put_fp = rom_putchar;
169: get_fp = rom_getchar;
170: test_fp = rom_testchar;
171: rom_putc = 0x20040068;
172: rom_getc = 0x20040054;
173: break;
174:
175: case VAX_BTYP_1303:
176: ka53_consinit();
177: break;
178:
179: #ifdef notdef
180: case VAX_BTYP_630:
181: case VAX_BTYP_650:
182: case VAX_BTYP_9CC:
183: case VAX_BTYP_60:
184: put_fp = pr_putchar;
185: get_fp = pr_getchar;
186: break
187: #endif
188: }
189: return;
190: }
191:
192: /*
193: * putchar() using MTPR
194: */
195: void
196: pr_putchar(int c)
197: {
198: int timeout = 1<<15; /* don't hang the machine! */
199:
200: /*
201: * On KA88 we may get C-S/C-Q from the console.
202: * Must obey it.
203: */
204: while (mfpr(PR_RXCS) & GC_DON) {
205: if ((mfpr(PR_RXDB) & 0x7f) == 19) {
206: while (1) {
207: while ((mfpr(PR_RXCS) & GC_DON) == 0)
208: ;
209: if ((mfpr(PR_RXDB) & 0x7f) == 17)
210: break;
211: }
212: }
213: }
214:
215: while ((mfpr(PR_TXCS) & GC_RDY) == 0) /* Wait until xmit ready */
216: if (--timeout < 0)
217: break;
218: mtpr(c, PR_TXDB); /* xmit character */
219: }
220:
221: /*
222: * getchar() using MFPR
223: */
224: int
225: pr_getchar(void)
226: {
227: while ((mfpr(PR_RXCS) & GC_DON) == 0)
228: ; /* wait for char */
229: return (mfpr(PR_RXDB)); /* now get it */
230: }
231:
232: int
233: pr_testchar(void)
234: {
235: if (mfpr(PR_RXCS) & GC_DON)
236: return mfpr(PR_RXDB);
237: else
238: return 0;
239: }
240:
241: /*
242: * void ka630_rom_getchar (void) ==> initialize KA630 ROM console I/O
243: */
244: void ka630_consinit(void)
245: {
246: short *NVR;
247: int i;
248:
249: /* Find the console page */
250: NVR = (short *) KA630_NVR_ADRS;
251:
252: i = *NVR++ & 0xFF;
253: i |= (*NVR++ & 0xFF) << 8;
254: i |= (*NVR++ & 0xFF) << 16;
255: i |= (*NVR++ & 0xFF) << 24;
256:
257: ka630_conspage = (char *) i;
258:
259: /* Go to last row to minimize confusion */
260: ka630_conspage[KA630_ROW] = ka630_conspage[KA630_MAXROW];
261: ka630_conspage[KA630_COL] = ka630_conspage[KA630_MINCOL];
262:
263: /* Use KA630 ROM console I/O routines */
264: put_fp = ka630_rom_putchar;
265: get_fp = ka630_rom_getchar;
266: test_fp = ka630_rom_testchar;
267: }
268:
269:
270: /*
271: * void ka53_consinit (void) ==> initialize KA53 ROM console I/O
272: */
273: void ka53_consinit(void)
274: {
275: ka53_conspage = (char *) 0x2014044b;
276:
277: put_fp = ka53_rom_putchar;
278: get_fp = ka53_rom_getchar;
279: test_fp = ka53_rom_testchar;
280: }
281:
282: /*
283: * VXT2000 console routines.
284: *
285: * While we can use the rom putchar routine, the rom getchar routine
286: * will happily return the last key pressed, even if it is not pressed
287: * anymore.
288: *
289: * To guard against this, we monitor the keyboard serial port and will
290: * only invoke the rom function (which will do the keyboard layout
291: * translation for us) if there is indeed a new keyboard event (we still
292: * need to guard against dead keys, hence the while() condition in
293: * vxt_getchar). This still unfortunately causes phantom characters to
294: * appear when playing with the shift keys, but nothing backspace can't
295: * erase, so this will be a minor annoyance.
296: *
297: * If console is on the serial port, we do not use the prom routines at
298: * all.
299: */
300: static volatile int *vxtregs = (int *)0x200A0000;
301:
302: #define CH_SRA 0x01
303: #define CH_CRA 0x02
304: #define CH_DATA 0x03
305: #define CH_SRC 0x11
306: #define CH_CRC 0x12
307: #define CH_DATC 0x13
308:
309: #define CR_RX_ENA 0x01
310: #define CR_TX_ENA 0x04
311: #define SR_RX_RDY 0x01
312: #define SR_TX_RDY 0x04
313:
314: int
315: vxt_getchar(void)
316: {
317: if (vax_confdata & 2) {
318: vxtregs[CH_CRC] = CR_RX_ENA;
319: while ((vxtregs[CH_SRC] & SR_RX_RDY) == 0 ||
320: rom_testchar() == 0)
321: ;
322: return rom_getchar();
323: } else {
324: vxtregs[CH_CRA] = CR_RX_ENA;
325: while ((vxtregs[CH_SRA] & SR_RX_RDY) == 0)
326: ;
327: return vxtregs[CH_DATA];
328: }
329: }
330:
331: int
332: vxt_testchar(void)
333: {
334: if (vax_confdata & 2) {
335: vxtregs[CH_CRC] = CR_RX_ENA;
336: if ((vxtregs[CH_SRC] & SR_RX_RDY) == 0)
337: return 0;
338: return rom_testchar();
339: } else {
340: vxtregs[CH_CRA] = CR_RX_ENA;
341: if ((vxtregs[CH_SRA] & SR_RX_RDY) == 0)
342: return 0;
343: return vxtregs[CH_DATA];
344: }
345: }
CVSweb