xref: /netbsd/sys/arch/mvme68k/stand/sboot/console.c (revision bf9ec67e)
1 /*	$NetBSD: console.c,v 1.5 2000/07/24 18:40:01 jdolecek Exp $	*/
2 
3 /*
4  *
5  * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Charles D. Cranor
19  *	and Seth Widoff.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 /*
35  * console i/o
36  */
37 
38 #include "sboot.h"
39 
40 /*
41  * hardware
42  */
43 
44 struct zs_hw {
45   volatile u_char ctl;
46   volatile u_char data;
47 };
48 
49 struct zs_hw *zs =  (struct zs_hw *)CONS_ZS_ADDR;
50 
51 /*
52  * consinit: init console
53  */
54 
55 void
56 consinit()
57 
58 {
59   int mark = time();
60   int rr1;
61   while (1) {
62     if (time() > mark + 5) break;
63     zs->ctl = 1; rr1 = zs->ctl;
64     zs->ctl = 0;
65     if ((rr1 & 0x1) == 1 && (zs->ctl & 0x4) == 4) break; /* zs_drain! */
66   }
67   zs->ctl =  9; zs->ctl = 0x00; /* clear interrupt */
68   zs->ctl =  4; zs->ctl = 0x44; /* 16x clk, 1 stop bit */
69   zs->ctl =  5; zs->ctl = 0xea; /* DTR on, 8 bit xmit, xmit on, RTS on */
70   zs->ctl =  3; zs->ctl = 0xc1; /* 8 bit recv, auto cd_cts, recv on */
71   zs->ctl =  1; zs->ctl = 0x00; /* no intrs */
72   zs->ctl =  2; zs->ctl = 0x00; /* no vector */
73   zs->ctl = 10; zs->ctl = 0x00; /* */
74   zs->ctl = 11; zs->ctl = 0x50; /* clocking options */
75   zs->ctl = 12; zs->ctl = 0x0e; /* 9600 baud, part 1 */
76   zs->ctl = 13; zs->ctl = 0x00; /* 9600 baud, part 2 */
77   zs->ctl = 14; zs->ctl = 0x03; /* more clocking options */
78   zs->ctl = 15; zs->ctl = 0x00; /* clear intrs */
79 }
80 
81 /*
82  * putchar: put char to console
83  */
84 
85 void putchar(int c)
86 {
87   if (c == '\n') putchar('\r');  /* avoid the need for \r\n in printf */
88   zs->ctl = 0;
89   while ((zs->ctl & 0x04) == 0) {
90     zs->ctl = 0;
91   }
92   zs->ctl = 8;
93   zs->ctl = (char) c;
94 }
95 
96 /*
97  * cngetc: get 1 char from console
98  */
99 
100 char cngetc ()
101 {
102   zs->ctl = 0;
103   while ((zs->ctl & 0x1) == 0) {
104     zs->ctl = 0;
105   }
106   zs->ctl = 8;
107   return zs->ctl;
108 }
109 
110 /*
111  * puts: put string to console
112  */
113 
114 void puts ( char * str )
115 {
116   while ( *str != '\0' ) {
117     putchar(*str);
118     str++;
119   }
120 }
121 
122 /*
123  * ngets: get string from console
124  */
125 
126 char *ngets ( char * str, int size )
127 {
128   int i = 0;
129   while ( (i < size - 1) && (str[i] = cngetc()) != '\r') {
130     if ( str[i] == '\b' || str[i] == 0x7F ) {
131       if ( i == 0) continue;
132       i--;
133       puts("\b \b");
134       continue;
135     }
136     putchar(str[i]);
137     i++;
138   }
139   puts("\n");
140   str[i] = '\0';
141   return(&str[i]);
142 }
143 
144