4 * Copyright (c) 2009 NONAKA Kimihiro <nonaka@netbsd.org>
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.
32 #include "compat_linux.h"
35 struct btinfo_console bi_cons
;
37 static int iodev
= CONSDEV_GLASS
;
41 static const char *comdevname
[] = {
45 static void common_putc(int fd
, int c
);
46 static int common_getc(int fd
, int timo
);
49 consinit(int dev
, int speed
)
51 struct linux_termios termios
;
62 iodev
= CONSDEV_GLASS
;
66 if (infd
>= 0 && infd
== outfd
) {
72 if (iodev
== CONSDEV_GLASS
) {
76 strlcpy(bi_cons
.devname
, "glass", sizeof(bi_cons
.devname
));
80 fd
= uopen(comdevname
[iodev
- CONSDEV_COM0
], LINUX_O_RDWR
);
86 linux_tcgetattr(fd
, &termios
);
87 if (linux_cfsetspeed(&termios
, speed
) < 0) {
89 if (linux_cfsetspeed(&termios
, speed
) < 0)
92 if (linux_tcsetattr(fd
, LINUX_TCSETS
, &termios
) < 0)
95 snprintf(bi_cons
.devname
, sizeof(bi_cons
.devname
), "com%d",
96 iodev
- CONSDEV_COM0
);
98 bi_cons
.speed
= speed
;
100 BI_ADD(&bi_cons
, BTINFO_CONSDEV
, sizeof(bi_cons
));
107 common_putc(outfd
, c
);
114 return common_getc(infd
, 1);
118 common_putc(int fd
, int c
)
121 (void)uwrite(fd
, &c
, 1);
125 common_getc(int fd
, int timo
)
127 struct linux_timeval tv
;
132 for (; timo
< 0 || timo
> 0; --timo
) {
140 n
= uselect(nfds
, &fdset
, NULL
, NULL
, &tv
);
146 for (fd
= 0; fd
< nfds
; fd
++) {
147 if (FD_ISSET(fd
, &fdset
)) {
148 return (uread(fd
, &c
, 1) < 1 ? -1 : c
);
156 awaitkey(int timeout
, int tell
)
158 struct linux_termios orig_termios
, raw_termios
;
163 linux_tcgetattr(infd
, &orig_termios
);
164 raw_termios
= orig_termios
;
165 linux_cfmakeraw(&raw_termios
);
166 linux_tcsetattr(infd
, LINUX_TCSETS
, &raw_termios
);
168 for (i
= timeout
; i
> 0; i
--) {
173 sprintf(numbuf
, "%d ", i
);
174 len
= strlen(numbuf
);
175 for (j
= 0; j
< len
; j
++)
176 numbuf
[len
+ j
] = '\b';
177 numbuf
[len
+ j
] = '\0';
180 c
= common_getc(infd
, 1);
189 /* set original mode */
190 linux_tcsetattr(infd
, LINUX_TCSETS
, &orig_termios
);
198 void dummycall2(void);
203 (void)linux_termio_to_bsd_termios
;
204 (void)bsd_termios_to_linux_termio
;
205 (void)linux_termios_to_bsd_termios
;
206 (void)bsd_termios_to_linux_termios
;