1 /* $NetBSD: pcio.c,v 1.30 2011/06/08 16:04:40 joerg Exp $ */
4 * Copyright (c) 1996, 1997
5 * Matthias Drochner. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * needs lowlevel routines from conio.S and comio.S
34 #include <lib/libsa/stand.h>
35 #include <lib/libkern/libkern.h>
36 #include <sys/bootblock.h>
41 extern struct x86_boot_params boot_params
;
43 struct btinfo_console btinfo_console
;
49 #include "comio_direct.h"
51 #define cominit_x() btinfo_console.speed = \
52 cominit_d(btinfo_console.addr, btinfo_console.speed)
53 #define computc_x(ch) computc_d(ch, btinfo_console.addr)
54 #define comgetc_x() comgetc_d(btinfo_console.addr)
55 #define comstatus_x() comstatus_d(btinfo_console.addr)
58 #define cominit_x() cominit(iodev - CONSDEV_COM0)
59 #define computc_x(ch) computc(ch, iodev - CONSDEV_COM0)
60 #define comgetc_x() comgetc(iodev - CONSDEV_COM0)
61 #define comstatus_x() comstatus(iodev - CONSDEV_COM0)
63 #endif /* DIRECT_SERIAL */
65 static int getcomaddr(int);
66 #endif /* SUPPORT_SERIAL */
73 int prev
= biosgetsystime();
74 int tgt
= prev
+ (20 * us
) / 1000000;
77 while ((new = biosgetsystime()) < tgt
) {
78 if (new < prev
) /* XXX timer wrapped */
93 /* read in BIOS data area */
94 pvbcopy((void *)(0x400 + 2 * idx
), &addr
, 2);
100 clear_pc_screen(void)
102 #ifdef SUPPORT_SERIAL
103 /* Clear the screen if we are on a glass tty. */
104 if (iodev
== CONSDEV_PC
)
112 #ifdef SUPPORT_SERIAL
115 #if defined(DIRECT_SERIAL) && defined(CONSPEED)
116 btinfo_console
.speed
= CONSPEED
;
118 btinfo_console
.speed
= 9600;
123 for (i
= 0; i
< 3; i
++) {
124 iodev
= CONSDEV_COM0
+ i
;
125 btinfo_console
.addr
= getcomaddr(i
);
126 if (!btinfo_console
.addr
)
128 conputc('0' + i
); /* to tell user what happens */
132 * 1. successful output
133 * 2. optionally, keypress within 7s
135 if ( computc_x(':') &&
138 #ifdef COMCONS_KEYPRESS
143 #else /* ! DIRECT_SERIAL */
145 * serial console must have hardware handshake!
147 * 1. character output without error
148 * 2. status bits for modem ready set
149 * (status seems only useful after character output)
150 * 3. optionally, keypress within 7s
152 if (!(computc_x('@') & 0x80)
153 && (comstatus_x() & 0x00b0)
154 #ifdef COMCONS_KEYPRESS
159 #endif /* DIRECT_SERIAL */
169 btinfo_console
.addr
= getcomaddr(iodev
- CONSDEV_COM0
);
170 if (!btinfo_console
.addr
)
174 case CONSDEV_COM0KBD
:
175 case CONSDEV_COM1KBD
:
176 case CONSDEV_COM2KBD
:
177 case CONSDEV_COM3KBD
:
178 iodev
= dev
- CONSDEV_COM0KBD
+ CONSDEV_COM0
;
179 i
= iodev
- CONSDEV_COM0
;
180 btinfo_console
.addr
= getcomaddr(i
);
181 if (!btinfo_console
.addr
)
183 conputc('0' + i
); /* to tell user what happens */
187 * 1. successful output
188 * 2. optionally, keypress within 7s
190 if ( computc_x(':') &&
193 #ifdef COMCONS_KEYPRESS
198 #else /* ! DIRECT_SERIAL */
200 * serial console must have hardware handshake!
202 * 1. character output without error
203 * 2. status bits for modem ready set
204 * (status seems only useful after character output)
205 * 3. optionally, keypress within 7s
207 if (!(computc_x('@') & 0x80)
208 && (comstatus_x() & 0x00b0)
209 #ifdef COMCONS_KEYPRESS
214 #endif /* DIRECT_SERIAL */
222 strncpy(btinfo_console
.devname
, iodev
== CONSDEV_PC
? "pc" : "com", 16);
224 #else /* !SUPPORT_SERIAL */
225 btinfo_console
.devname
[0] = 'p';
226 btinfo_console
.devname
[1] = 'c';
227 btinfo_console
.devname
[2] = 0;
228 #endif /* SUPPORT_SERIAL */
231 static inline void internal_putchar(int);
234 internal_putchar(int c
)
236 #ifdef SUPPORT_SERIAL
241 #ifdef SUPPORT_SERIAL
257 internal_putchar('\r');
265 #ifdef SUPPORT_SERIAL
267 default: /* to make gcc -Wall happy... */
273 #ifdef CONSOLE_KEYMAP
275 char *cp
= strchr(CONSOLE_KEYMAP
, c
& 0xff);
276 if (cp
!= 0 && cp
[1] != 0)
277 c
= cp
[1] | (c
& 0xff00);
281 #ifdef SUPPORT_SERIAL
291 } while ((c
>> 8) == 0xe0); /* catch timeout */
294 printf("com input %x, status %x\n",
299 #endif /* DIRECT_SERIAL */
302 #endif /* SUPPORT_SERIAL */
308 return getchar_ex() & 0xff;
314 #ifdef SUPPORT_SERIAL
316 default: /* to make gcc -Wall happy... */
319 return (intr
&& conisshift()) || coniskey();
320 #ifdef SUPPORT_SERIAL
326 return !!comstatus_x();
328 return !!(comstatus_x() & 0x0100);
331 #endif /* SUPPORT_SERIAL */
335 awaitkey(int timeout
, int tell
)
340 i
= timeout
* POLL_FREQ
;
343 if (tell
&& (i
% POLL_FREQ
) == 0) {
347 len
= snprintf(numbuf
, sizeof(numbuf
), "%d seconds. ",
349 if (len
> 0 && len
< sizeof(numbuf
)) {
352 printf("%s", numbuf
);
355 printf("%s", numbuf
);
359 /* flush input buffer */
367 wait(1000000 / POLL_FREQ
);
374 printf("0 seconds. \n");