| @@ -1,382 +1,378 @@ | | | @@ -1,382 +1,378 @@ |
1 | /* $NetBSD: pcio.c,v 1.29 2011/02/14 23:47:11 jmcneill Exp $ */ | | 1 | /* $NetBSD: pcio.c,v 1.30 2011/06/08 16:04:40 joerg Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996, 1997 | | 4 | * Copyright (c) 1996, 1997 |
5 | * Matthias Drochner. All rights reserved. | | 5 | * Matthias Drochner. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * | | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 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 | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 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 | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 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 | | 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. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | | 26 | * |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | /* | | 29 | /* |
30 | * console I/O | | 30 | * console I/O |
31 | * needs lowlevel routines from conio.S and comio.S | | 31 | * needs lowlevel routines from conio.S and comio.S |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include <lib/libsa/stand.h> | | 34 | #include <lib/libsa/stand.h> |
35 | #include <lib/libkern/libkern.h> | | 35 | #include <lib/libkern/libkern.h> |
36 | #include <sys/bootblock.h> | | 36 | #include <sys/bootblock.h> |
37 | | | 37 | |
38 | #include "libi386.h" | | 38 | #include "libi386.h" |
39 | #include "bootinfo.h" | | 39 | #include "bootinfo.h" |
40 | | | 40 | |
41 | extern void conputc(int); | | | |
42 | extern int congetc(void); | | | |
43 | extern int conisshift(void); | | | |
44 | extern int coniskey(void); | | | |
45 | extern struct x86_boot_params boot_params; | | 41 | extern struct x86_boot_params boot_params; |
46 | | | 42 | |
47 | struct btinfo_console btinfo_console; | | 43 | struct btinfo_console btinfo_console; |
48 | | | 44 | |
49 | #ifdef SUPPORT_SERIAL | | 45 | #ifdef SUPPORT_SERIAL |
50 | static int iodev; | | 46 | static int iodev; |
51 | | | 47 | |
52 | #ifdef DIRECT_SERIAL | | 48 | #ifdef DIRECT_SERIAL |
53 | #include "comio_direct.h" | | 49 | #include "comio_direct.h" |
54 | | | 50 | |
55 | #define cominit_x() btinfo_console.speed = \ | | 51 | #define cominit_x() btinfo_console.speed = \ |
56 | cominit_d(btinfo_console.addr, btinfo_console.speed) | | 52 | cominit_d(btinfo_console.addr, btinfo_console.speed) |
57 | #define computc_x(ch) computc_d(ch, btinfo_console.addr) | | 53 | #define computc_x(ch) computc_d(ch, btinfo_console.addr) |
58 | #define comgetc_x() comgetc_d(btinfo_console.addr) | | 54 | #define comgetc_x() comgetc_d(btinfo_console.addr) |
59 | #define comstatus_x() comstatus_d(btinfo_console.addr) | | 55 | #define comstatus_x() comstatus_d(btinfo_console.addr) |
60 | | | 56 | |
61 | #else | | 57 | #else |
62 | #define cominit_x() cominit(iodev - CONSDEV_COM0) | | 58 | #define cominit_x() cominit(iodev - CONSDEV_COM0) |
63 | #define computc_x(ch) computc(ch, iodev - CONSDEV_COM0) | | 59 | #define computc_x(ch) computc(ch, iodev - CONSDEV_COM0) |
64 | #define comgetc_x() comgetc(iodev - CONSDEV_COM0) | | 60 | #define comgetc_x() comgetc(iodev - CONSDEV_COM0) |
65 | #define comstatus_x() comstatus(iodev - CONSDEV_COM0) | | 61 | #define comstatus_x() comstatus(iodev - CONSDEV_COM0) |
66 | | | 62 | |
67 | #endif /* DIRECT_SERIAL */ | | 63 | #endif /* DIRECT_SERIAL */ |
68 | | | 64 | |
69 | static int getcomaddr(int); | | 65 | static int getcomaddr(int); |
70 | #endif /* SUPPORT_SERIAL */ | | 66 | #endif /* SUPPORT_SERIAL */ |
71 | | | 67 | |
72 | #define POLL_FREQ 10 | | 68 | #define POLL_FREQ 10 |
73 | | | 69 | |
74 | static void | | 70 | static void |
75 | wait(int us) | | 71 | wait(int us) |
76 | { | | 72 | { |
77 | int prev = biosgetsystime(); | | 73 | int prev = biosgetsystime(); |
78 | int tgt = prev + (20 * us) / 1000000; | | 74 | int tgt = prev + (20 * us) / 1000000; |
79 | int new; | | 75 | int new; |
80 | | | 76 | |
81 | while ((new = biosgetsystime()) < tgt) { | | 77 | while ((new = biosgetsystime()) < tgt) { |
82 | if (new < prev) /* XXX timer wrapped */ | | 78 | if (new < prev) /* XXX timer wrapped */ |
83 | break; | | 79 | break; |
84 | prev = new; | | 80 | prev = new; |
85 | } | | 81 | } |
86 | } | | 82 | } |
87 | | | 83 | |
88 | #ifdef SUPPORT_SERIAL | | 84 | #ifdef SUPPORT_SERIAL |
89 | static int | | 85 | static int |
90 | getcomaddr(int idx) | | 86 | getcomaddr(int idx) |
91 | { | | 87 | { |
92 | short addr; | | 88 | short addr; |
93 | #ifdef CONSADDR | | 89 | #ifdef CONSADDR |
94 | if (CONSADDR != 0) | | 90 | if (CONSADDR != 0) |
95 | return CONSADDR; | | 91 | return CONSADDR; |
96 | #endif | | 92 | #endif |
97 | /* read in BIOS data area */ | | 93 | /* read in BIOS data area */ |
98 | pvbcopy((void *)(0x400 + 2 * idx), &addr, 2); | | 94 | pvbcopy((void *)(0x400 + 2 * idx), &addr, 2); |
99 | return addr; | | 95 | return addr; |
100 | } | | 96 | } |
101 | #endif | | 97 | #endif |
102 | | | 98 | |
103 | void | | 99 | void |
104 | clear_pc_screen(void) | | 100 | clear_pc_screen(void) |
105 | { | | 101 | { |
106 | #ifdef SUPPORT_SERIAL | | 102 | #ifdef SUPPORT_SERIAL |
107 | /* Clear the screen if we are on a glass tty. */ | | 103 | /* Clear the screen if we are on a glass tty. */ |
108 | if (iodev == CONSDEV_PC) | | 104 | if (iodev == CONSDEV_PC) |
109 | conclr(); | | 105 | conclr(); |
110 | #endif | | 106 | #endif |
111 | } | | 107 | } |
112 | | | 108 | |
113 | void | | 109 | void |
114 | initio(int dev) | | 110 | initio(int dev) |
115 | { | | 111 | { |
116 | #ifdef SUPPORT_SERIAL | | 112 | #ifdef SUPPORT_SERIAL |
117 | int i; | | 113 | int i; |
118 | | | 114 | |
119 | #if defined(DIRECT_SERIAL) && defined(CONSPEED) | | 115 | #if defined(DIRECT_SERIAL) && defined(CONSPEED) |
120 | btinfo_console.speed = CONSPEED; | | 116 | btinfo_console.speed = CONSPEED; |
121 | #else | | 117 | #else |
122 | btinfo_console.speed = 9600; | | 118 | btinfo_console.speed = 9600; |
123 | #endif | | 119 | #endif |
124 | | | 120 | |
125 | switch (dev) { | | 121 | switch (dev) { |
126 | case CONSDEV_AUTO: | | 122 | case CONSDEV_AUTO: |
127 | for (i = 0; i < 3; i++) { | | 123 | for (i = 0; i < 3; i++) { |
128 | iodev = CONSDEV_COM0 + i; | | 124 | iodev = CONSDEV_COM0 + i; |
129 | btinfo_console.addr = getcomaddr(i); | | 125 | btinfo_console.addr = getcomaddr(i); |
130 | if (!btinfo_console.addr) | | 126 | if (!btinfo_console.addr) |
131 | break; | | 127 | break; |
132 | conputc('0' + i); /* to tell user what happens */ | | 128 | conputc('0' + i); /* to tell user what happens */ |
133 | cominit_x(); | | 129 | cominit_x(); |
134 | #ifdef DIRECT_SERIAL | | 130 | #ifdef DIRECT_SERIAL |
135 | /* check for: | | 131 | /* check for: |
136 | * 1. successful output | | 132 | * 1. successful output |
137 | * 2. optionally, keypress within 7s | | 133 | * 2. optionally, keypress within 7s |
138 | */ | | 134 | */ |
139 | if ( computc_x(':') && | | 135 | if ( computc_x(':') && |
140 | computc_x('-') && | | 136 | computc_x('-') && |
141 | computc_x('(') | | 137 | computc_x('(') |
142 | #ifdef COMCONS_KEYPRESS | | 138 | #ifdef COMCONS_KEYPRESS |
143 | && awaitkey(7, 0) | | 139 | && awaitkey(7, 0) |
144 | #endif | | 140 | #endif |
145 | ) | | 141 | ) |
146 | goto ok; | | 142 | goto ok; |
147 | #else /* ! DIRECT_SERIAL */ | | 143 | #else /* ! DIRECT_SERIAL */ |
148 | /* | | 144 | /* |
149 | * serial console must have hardware handshake! | | 145 | * serial console must have hardware handshake! |
150 | * check: | | 146 | * check: |
151 | * 1. character output without error | | 147 | * 1. character output without error |
152 | * 2. status bits for modem ready set | | 148 | * 2. status bits for modem ready set |
153 | * (status seems only useful after character output) | | 149 | * (status seems only useful after character output) |
154 | * 3. optionally, keypress within 7s | | 150 | * 3. optionally, keypress within 7s |
155 | */ | | 151 | */ |
156 | if (!(computc_x('@') & 0x80) | | 152 | if (!(computc_x('@') & 0x80) |
157 | && (comstatus_x() & 0x00b0) | | 153 | && (comstatus_x() & 0x00b0) |
158 | #ifdef COMCONS_KEYPRESS | | 154 | #ifdef COMCONS_KEYPRESS |
159 | && awaitkey(7, 0) | | 155 | && awaitkey(7, 0) |
160 | #endif | | 156 | #endif |
161 | ) | | 157 | ) |
162 | goto ok; | | 158 | goto ok; |
163 | #endif /* DIRECT_SERIAL */ | | 159 | #endif /* DIRECT_SERIAL */ |
164 | } | | 160 | } |
165 | iodev = CONSDEV_PC; | | 161 | iodev = CONSDEV_PC; |
166 | ok: | | 162 | ok: |
167 | break; | | 163 | break; |
168 | case CONSDEV_COM0: | | 164 | case CONSDEV_COM0: |
169 | case CONSDEV_COM1: | | 165 | case CONSDEV_COM1: |
170 | case CONSDEV_COM2: | | 166 | case CONSDEV_COM2: |
171 | case CONSDEV_COM3: | | 167 | case CONSDEV_COM3: |
172 | iodev = dev; | | 168 | iodev = dev; |
173 | btinfo_console.addr = getcomaddr(iodev - CONSDEV_COM0); | | 169 | btinfo_console.addr = getcomaddr(iodev - CONSDEV_COM0); |
174 | if (!btinfo_console.addr) | | 170 | if (!btinfo_console.addr) |
175 | goto nocom; | | 171 | goto nocom; |
176 | cominit_x(); | | 172 | cominit_x(); |
177 | break; | | 173 | break; |
178 | case CONSDEV_COM0KBD: | | 174 | case CONSDEV_COM0KBD: |
179 | case CONSDEV_COM1KBD: | | 175 | case CONSDEV_COM1KBD: |
180 | case CONSDEV_COM2KBD: | | 176 | case CONSDEV_COM2KBD: |
181 | case CONSDEV_COM3KBD: | | 177 | case CONSDEV_COM3KBD: |
182 | iodev = dev - CONSDEV_COM0KBD + CONSDEV_COM0; | | 178 | iodev = dev - CONSDEV_COM0KBD + CONSDEV_COM0; |
183 | i = iodev - CONSDEV_COM0; | | 179 | i = iodev - CONSDEV_COM0; |
184 | btinfo_console.addr = getcomaddr(i); | | 180 | btinfo_console.addr = getcomaddr(i); |
185 | if (!btinfo_console.addr) | | 181 | if (!btinfo_console.addr) |
186 | goto nocom; | | 182 | goto nocom; |
187 | conputc('0' + i); /* to tell user what happens */ | | 183 | conputc('0' + i); /* to tell user what happens */ |
188 | cominit_x(); | | 184 | cominit_x(); |
189 | #ifdef DIRECT_SERIAL | | 185 | #ifdef DIRECT_SERIAL |
190 | /* check for: | | 186 | /* check for: |
191 | * 1. successful output | | 187 | * 1. successful output |
192 | * 2. optionally, keypress within 7s | | 188 | * 2. optionally, keypress within 7s |
193 | */ | | 189 | */ |
194 | if ( computc_x(':') && | | 190 | if ( computc_x(':') && |
195 | computc_x('-') && | | 191 | computc_x('-') && |
196 | computc_x('(') | | 192 | computc_x('(') |
197 | #ifdef COMCONS_KEYPRESS | | 193 | #ifdef COMCONS_KEYPRESS |
198 | && awaitkey(7, 0) | | 194 | && awaitkey(7, 0) |
199 | #endif | | 195 | #endif |
200 | ) | | 196 | ) |
201 | break; | | 197 | break; |
202 | #else /* ! DIRECT_SERIAL */ | | 198 | #else /* ! DIRECT_SERIAL */ |
203 | /* | | 199 | /* |
204 | * serial console must have hardware handshake! | | 200 | * serial console must have hardware handshake! |
205 | * check: | | 201 | * check: |
206 | * 1. character output without error | | 202 | * 1. character output without error |
207 | * 2. status bits for modem ready set | | 203 | * 2. status bits for modem ready set |
208 | * (status seems only useful after character output) | | 204 | * (status seems only useful after character output) |
209 | * 3. optionally, keypress within 7s | | 205 | * 3. optionally, keypress within 7s |
210 | */ | | 206 | */ |
211 | if (!(computc_x('@') & 0x80) | | 207 | if (!(computc_x('@') & 0x80) |
212 | && (comstatus_x() & 0x00b0) | | 208 | && (comstatus_x() & 0x00b0) |
213 | #ifdef COMCONS_KEYPRESS | | 209 | #ifdef COMCONS_KEYPRESS |
214 | && awaitkey(7, 0) | | 210 | && awaitkey(7, 0) |
215 | #endif | | 211 | #endif |
216 | ) | | 212 | ) |
217 | break; | | 213 | break; |
218 | #endif /* DIRECT_SERIAL */ | | 214 | #endif /* DIRECT_SERIAL */ |
219 | default: | | 215 | default: |
220 | nocom: | | 216 | nocom: |
221 | iodev = CONSDEV_PC; | | 217 | iodev = CONSDEV_PC; |
222 | break; | | 218 | break; |
223 | } | | 219 | } |
224 | conputc('\015'); | | 220 | conputc('\015'); |
225 | conputc('\n'); | | 221 | conputc('\n'); |
226 | strncpy(btinfo_console.devname, iodev == CONSDEV_PC ? "pc" : "com", 16); | | 222 | strncpy(btinfo_console.devname, iodev == CONSDEV_PC ? "pc" : "com", 16); |
227 | | | 223 | |
228 | #else /* !SUPPORT_SERIAL */ | | 224 | #else /* !SUPPORT_SERIAL */ |
229 | btinfo_console.devname[0] = 'p'; | | 225 | btinfo_console.devname[0] = 'p'; |
230 | btinfo_console.devname[1] = 'c'; | | 226 | btinfo_console.devname[1] = 'c'; |
231 | btinfo_console.devname[2] = 0; | | 227 | btinfo_console.devname[2] = 0; |
232 | #endif /* SUPPORT_SERIAL */ | | 228 | #endif /* SUPPORT_SERIAL */ |
233 | } | | 229 | } |
234 | | | 230 | |
235 | static inline void internal_putchar(int); | | 231 | static inline void internal_putchar(int); |
236 | | | 232 | |
237 | static inline void | | 233 | static inline void |
238 | internal_putchar(int c) | | 234 | internal_putchar(int c) |
239 | { | | 235 | { |
240 | #ifdef SUPPORT_SERIAL | | 236 | #ifdef SUPPORT_SERIAL |
241 | switch (iodev) { | | 237 | switch (iodev) { |
242 | case CONSDEV_PC: | | 238 | case CONSDEV_PC: |
243 | #endif | | 239 | #endif |
244 | conputc(c); | | 240 | conputc(c); |
245 | #ifdef SUPPORT_SERIAL | | 241 | #ifdef SUPPORT_SERIAL |
246 | break; | | 242 | break; |
247 | case CONSDEV_COM0: | | 243 | case CONSDEV_COM0: |
248 | case CONSDEV_COM1: | | 244 | case CONSDEV_COM1: |
249 | case CONSDEV_COM2: | | 245 | case CONSDEV_COM2: |
250 | case CONSDEV_COM3: | | 246 | case CONSDEV_COM3: |
251 | computc_x(c); | | 247 | computc_x(c); |
252 | break; | | 248 | break; |
253 | } | | 249 | } |
254 | #endif | | 250 | #endif |
255 | } | | 251 | } |
256 | | | 252 | |
257 | void | | 253 | void |
258 | putchar(int c) | | 254 | putchar(int c) |
259 | { | | 255 | { |
260 | if (c == '\n') | | 256 | if (c == '\n') |
261 | internal_putchar('\r'); | | 257 | internal_putchar('\r'); |
262 | internal_putchar(c); | | 258 | internal_putchar(c); |
263 | } | | 259 | } |
264 | | | 260 | |
265 | int | | 261 | int |
266 | getchar(void) | | 262 | getchar(void) |
267 | { | | 263 | { |
268 | int c; | | 264 | int c; |
269 | #ifdef SUPPORT_SERIAL | | 265 | #ifdef SUPPORT_SERIAL |
270 | switch (iodev) { | | 266 | switch (iodev) { |
271 | default: /* to make gcc -Wall happy... */ | | 267 | default: /* to make gcc -Wall happy... */ |
272 | case CONSDEV_PC: | | 268 | case CONSDEV_PC: |
273 | #endif | | 269 | #endif |
274 | while (!coniskey()) | | 270 | while (!coniskey()) |
275 | ; | | 271 | ; |
276 | c = congetc(); | | 272 | c = congetc(); |
277 | #ifdef CONSOLE_KEYMAP | | 273 | #ifdef CONSOLE_KEYMAP |
278 | { | | 274 | { |
279 | char *cp = strchr(CONSOLE_KEYMAP, c); | | 275 | char *cp = strchr(CONSOLE_KEYMAP, c); |
280 | if (cp != 0 && cp[1] != 0) | | 276 | if (cp != 0 && cp[1] != 0) |
281 | c = cp[1]; | | 277 | c = cp[1]; |
282 | } | | 278 | } |
283 | #endif | | 279 | #endif |
284 | return c; | | 280 | return c; |
285 | #ifdef SUPPORT_SERIAL | | 281 | #ifdef SUPPORT_SERIAL |
286 | case CONSDEV_COM0: | | 282 | case CONSDEV_COM0: |
287 | case CONSDEV_COM1: | | 283 | case CONSDEV_COM1: |
288 | case CONSDEV_COM2: | | 284 | case CONSDEV_COM2: |
289 | case CONSDEV_COM3: | | 285 | case CONSDEV_COM3: |
290 | #ifdef DIRECT_SERIAL | | 286 | #ifdef DIRECT_SERIAL |
291 | c = comgetc_x(); | | 287 | c = comgetc_x(); |
292 | #else | | 288 | #else |
293 | do { | | 289 | do { |
294 | c = comgetc_x(); | | 290 | c = comgetc_x(); |
295 | } while ((c >> 8) == 0xe0); /* catch timeout */ | | 291 | } while ((c >> 8) == 0xe0); /* catch timeout */ |
296 | #ifdef COMDEBUG | | 292 | #ifdef COMDEBUG |
297 | if (c & 0x8000) { | | 293 | if (c & 0x8000) { |
298 | printf("com input %x, status %x\n", | | 294 | printf("com input %x, status %x\n", |
299 | c, comstatus_x()); | | 295 | c, comstatus_x()); |
300 | } | | 296 | } |
301 | #endif | | 297 | #endif |
302 | c &= 0xff; | | 298 | c &= 0xff; |
303 | #endif /* DIRECT_SERIAL */ | | 299 | #endif /* DIRECT_SERIAL */ |
304 | return c; | | 300 | return c; |
305 | } | | 301 | } |
306 | #endif /* SUPPORT_SERIAL */ | | 302 | #endif /* SUPPORT_SERIAL */ |
307 | } | | 303 | } |
308 | | | 304 | |
309 | int | | 305 | int |
310 | iskey(int intr) | | 306 | iskey(int intr) |
311 | { | | 307 | { |
312 | #ifdef SUPPORT_SERIAL | | 308 | #ifdef SUPPORT_SERIAL |
313 | switch (iodev) { | | 309 | switch (iodev) { |
314 | default: /* to make gcc -Wall happy... */ | | 310 | default: /* to make gcc -Wall happy... */ |
315 | case CONSDEV_PC: | | 311 | case CONSDEV_PC: |
316 | #endif | | 312 | #endif |
317 | return (intr && conisshift()) || coniskey(); | | 313 | return (intr && conisshift()) || coniskey(); |
318 | #ifdef SUPPORT_SERIAL | | 314 | #ifdef SUPPORT_SERIAL |
319 | case CONSDEV_COM0: | | 315 | case CONSDEV_COM0: |
320 | case CONSDEV_COM1: | | 316 | case CONSDEV_COM1: |
321 | case CONSDEV_COM2: | | 317 | case CONSDEV_COM2: |
322 | case CONSDEV_COM3: | | 318 | case CONSDEV_COM3: |
323 | #ifdef DIRECT_SERIAL | | 319 | #ifdef DIRECT_SERIAL |
324 | return !!comstatus_x(); | | 320 | return !!comstatus_x(); |
325 | #else | | 321 | #else |
326 | return !!(comstatus_x() & 0x0100); | | 322 | return !!(comstatus_x() & 0x0100); |
327 | #endif | | 323 | #endif |
328 | } | | 324 | } |
329 | #endif /* SUPPORT_SERIAL */ | | 325 | #endif /* SUPPORT_SERIAL */ |
330 | } | | 326 | } |
331 | | | 327 | |
332 | char | | 328 | char |
333 | awaitkey(int timeout, int tell) | | 329 | awaitkey(int timeout, int tell) |
334 | { | | 330 | { |
335 | int i; | | 331 | int i; |
336 | char c = 0; | | 332 | char c = 0; |
337 | | | 333 | |
338 | i = timeout * POLL_FREQ; | | 334 | i = timeout * POLL_FREQ; |
339 | | | 335 | |
340 | for (;;) { | | 336 | for (;;) { |
341 | if (tell && (i % POLL_FREQ) == 0) { | | 337 | if (tell && (i % POLL_FREQ) == 0) { |
342 | char numbuf[32]; | | 338 | char numbuf[32]; |
343 | int len; | | 339 | int len; |
344 | | | 340 | |
345 | len = snprintf(numbuf, sizeof(numbuf), "%d seconds. ", | | 341 | len = snprintf(numbuf, sizeof(numbuf), "%d seconds. ", |
346 | i/POLL_FREQ); | | 342 | i/POLL_FREQ); |
347 | if (len > 0 && len < sizeof(numbuf)) { | | 343 | if (len > 0 && len < sizeof(numbuf)) { |
348 | char *p = numbuf; | | 344 | char *p = numbuf; |
349 | | | 345 | |
350 | printf("%s", numbuf); | | 346 | printf("%s", numbuf); |
351 | while (*p) | | 347 | while (*p) |
352 | *p++ = '\b'; | | 348 | *p++ = '\b'; |
353 | printf("%s", numbuf); | | 349 | printf("%s", numbuf); |
354 | } | | 350 | } |
355 | } | | 351 | } |
356 | if (iskey(1)) { | | 352 | if (iskey(1)) { |
357 | /* flush input buffer */ | | 353 | /* flush input buffer */ |
358 | while (iskey(0)) | | 354 | while (iskey(0)) |
359 | c = getchar(); | | 355 | c = getchar(); |
360 | if (c == 0) | | 356 | if (c == 0) |
361 | c = -1; | | 357 | c = -1; |
362 | goto out; | | 358 | goto out; |
363 | } | | 359 | } |
364 | if (i--) | | 360 | if (i--) |
365 | wait(1000000 / POLL_FREQ); | | 361 | wait(1000000 / POLL_FREQ); |
366 | else | | 362 | else |
367 | break; | | 363 | break; |
368 | } | | 364 | } |
369 | | | 365 | |
370 | out: | | 366 | out: |
371 | if (tell) | | 367 | if (tell) |
372 | printf("0 seconds. \n"); | | 368 | printf("0 seconds. \n"); |
373 | | | 369 | |
374 | return c; | | 370 | return c; |
375 | } | | 371 | } |
376 | | | 372 | |
377 | void | | 373 | void |
378 | wait_sec(int sec) | | 374 | wait_sec(int sec) |
379 | { | | 375 | { |
380 | | | 376 | |
381 | wait(sec * 1000000); | | 377 | wait(sec * 1000000); |
382 | } | | 378 | } |