Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / mvme68k / stand / sboot / console.c
blob304ff72ebf8cb8c933c7b6ac3067034aba763cdd
1 /* $NetBSD: console.c,v 1.5 2000/07/24 18:40:01 jdolecek Exp $ */
3 /*
5 * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
6 * All rights reserved.
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.
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.
35 * console i/o
38 #include "sboot.h"
41 * hardware
44 struct zs_hw {
45 volatile u_char ctl;
46 volatile u_char data;
49 struct zs_hw *zs = (struct zs_hw *)CONS_ZS_ADDR;
52 * consinit: init console
55 void
56 consinit(void)
58 int mark = time();
59 int rr1;
60 for (;;) {
61 if (time() > mark + 5) break;
62 zs->ctl = 1; rr1 = zs->ctl;
63 zs->ctl = 0;
64 if ((rr1 & 0x1) == 1 && (zs->ctl & 0x4) == 4)
65 break; /* zs_drain! */
67 zs->ctl = 9;
68 zs->ctl = 0x00; /* clear interrupt */
69 zs->ctl = 4;
70 zs->ctl = 0x44; /* 16x clk, 1 stop bit */
71 zs->ctl = 5;
72 zs->ctl = 0xea; /* DTR on, 8 bit xmit, xmit on, RTS on */
73 zs->ctl = 3;
74 zs->ctl = 0xc1; /* 8 bit recv, auto cd_cts, recv on */
75 zs->ctl = 1;
76 zs->ctl = 0x00; /* no intrs */
77 zs->ctl = 2;
78 zs->ctl = 0x00; /* no vector */
79 zs->ctl = 10;
80 zs->ctl = 0x00; /* */
81 zs->ctl = 11;
82 zs->ctl = 0x50; /* clocking options */
83 zs->ctl = 12;
84 zs->ctl = 0x0e; /* 9600 baud, part 1 */
85 zs->ctl = 13;
86 zs->ctl = 0x00; /* 9600 baud, part 2 */
87 zs->ctl = 14;
88 zs->ctl = 0x03; /* more clocking options */
89 zs->ctl = 15;
90 zs->ctl = 0x00; /* clear intrs */
94 * putchar: put char to console
97 void putchar(int c)
99 if (c == '\n')
100 putchar('\r'); /* avoid the need for \r\n in printf */
101 zs->ctl = 0;
102 while ((zs->ctl & 0x04) == 0) {
103 zs->ctl = 0;
105 zs->ctl = 8;
106 zs->ctl = (char)c;
110 * cngetc: get 1 char from console
113 char cngetc(void)
116 zs->ctl = 0;
117 while ((zs->ctl & 0x1) == 0) {
118 zs->ctl = 0;
120 zs->ctl = 8;
121 return zs->ctl;
125 * puts: put string to console
128 void
129 puts(char *str)
132 while (*str != '\0') {
133 putchar(*str);
134 str++;
139 * ngets: get string from console
142 char *
143 ngets(char *str, int size)
146 int i = 0;
147 while ((i < size - 1) && (str[i] = cngetc()) != '\r') {
148 if (str[i] == '\b' || str[i] == 0x7F) {
149 if (i == 0)
150 continue;
151 i--;
152 puts("\b \b");
153 continue;
155 putchar(str[i]);
156 i++;
158 puts("\n");
159 str[i] = '\0';
160 return &str[i];