Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / landisk / stand / boot / cons.c
blob928668eb7298bd3091f7ef404438429084ac987d
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 2005 NONAKA Kimihiro
5 * All rights reserved.
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.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include <lib/libsa/stand.h>
30 #include <lib/libkern/libkern.h>
32 #include <sys/bootblock.h>
34 #include "boot.h"
35 #include "cons.h"
37 #ifndef CONSPEED
38 #define CONSPEED 9600
39 #endif
41 #define POLL_FREQ 10
43 extern struct landisk_boot_params boot_params;
45 static int consdev = CONSDEV_BIOSCONS;
47 /*ARGSUSED*/
48 int
49 cninit(int dev)
52 switch (dev) {
53 default:
54 case CONSDEV_BIOSCONS:
55 break;
57 case CONSDEV_SCIF:
58 switch (boot_params.bp_conspeed) {
59 default:
60 scif_init(CONSPEED);
61 break;
63 case 9600:
64 #if 0
65 case 19200:
66 case 38400:
67 case 57600:
68 case 115200:
69 #endif
70 scif_init(boot_params.bp_conspeed);
71 break;
73 break;
75 consdev = dev;
77 return (0);
80 int
81 getchar(void)
84 switch (consdev) {
85 default:
86 case CONSDEV_BIOSCONS:
87 return bioscons_getc();
89 case CONSDEV_SCIF:
90 return scif_getc();
94 void
95 putchar(int c)
98 switch (consdev) {
99 default:
100 case CONSDEV_BIOSCONS:
101 bioscons_putc(c);
102 break;
104 case CONSDEV_SCIF:
105 if (c == '\n')
106 scif_putc('\r');
107 scif_putc(c);
108 break;
112 /*ARGSUSED*/
114 iskey(int intr)
117 switch (consdev) {
118 default:
119 case CONSDEV_BIOSCONS:
120 return scif_status2();
122 case CONSDEV_SCIF:
123 return scif_status();
127 char
128 awaitkey(int timeout, int tell)
130 int i;
131 char c = 0;
133 i = timeout * POLL_FREQ;
135 for (;;) {
136 if (tell && (i % POLL_FREQ) == 0) {
137 char numbuf[20];
138 int len, j;
140 sprintf(numbuf, "%d ", i / POLL_FREQ);
141 len = strlen(numbuf);
142 for (j = 0; j < len; j++)
143 numbuf[len + j] = '\b';
144 numbuf[len + j] = '\0';
145 printf(numbuf);
147 if (iskey(1)) {
148 /* flush input buffer */
149 while (iskey(0))
150 c = getchar();
151 if (c == 0)
152 c = -1;
153 goto out;
155 if (i--) {
156 delay(1000 / POLL_FREQ);
157 } else {
158 break;
162 out:
163 if (tell)
164 printf("0 \n");
166 return (c);