1 /* Hello emacs, this should be edited in -*- Fundamental -*- mode */
4 * Copyright (c) 1994 Joerg Wunsch
8 * This program is free software.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Joerg Wunsch
21 * 4. The name of the developer may not be used to endorse or promote
22 * products derived from this software without specific prior written
25 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #ident "$FreeBSD: src/usr.sbin/pcvt/kbdio/kbdio.y,v 1.6 1999/09/06 07:39:30 peter Exp $"
41 * Revision 1.2 1994/09/18 19:49:22 j
42 * Refined expr handling; can now set/clear bits.
44 * Revision 1.1 1994/09/18 12:57:13 j
53 #include <sys/fcntl.h>
54 #include <machine/cpufunc.h>
55 #include <machine/pcvt_ioctl.h>
58 #include <machine/pio.h>
62 { u_char x = inb(0x84); } \
63 { u_char x = inb(0x84); } \
64 { u_char x = inb(0x84); } \
65 { u_char x = inb(0x84); } \
66 { u_char x = inb(0x84); } \
67 { u_char x = inb(0x84); }
71 void yyerror(const char *msg);
73 static void help(int), status(void), data(int), kbd(int), cmdbyte(int),
74 kbc(int), whatMCA(void);
75 static int kbget(void);
83 %token ALL CMD DATA DEFAULTS ECHOC ENABLE EXPR HELP ID LED
84 %token MAKE ONLY RELEASE RESEND RESET SCAN STATUS TYPEMATIC
98 line: statements NEWLINE
100 | error NEWLINE { fprintf(stderr, "bing!\n"); }
103 statements: statement
104 | statements ';' statement
107 statement: '?' { help(0); }
109 | HELP EXPR { help(1); }
110 | STATUS '?' { status(); }
111 | WHAT '?' { whatMCA(); }
112 | DATA '?' { data(kbget()); }
113 | LED '=' NUM { kbd(0xed); kbd($3); }
114 | ECHOC { kbd(0xee); kbget(); }
115 | SCAN '=' NUM { kbd(0xf0); kbd($3);
116 if($3 == 0) data(kbget()); }
117 | SCAN '?' { kbd(0xf0); kbd(0); data(kbget()); }
118 | ID '?' { kbd(0xf2); data(kbget());
120 | TYPEMATIC '=' NUM ',' NUM
122 if($3 > 1000) $3 = 1000;
127 (8.0 * log(30.0 / (double)$5)
129 | ((($3 / 250) - 1) * 32)
132 | ENABLE { kbd(0xf4); }
133 | DEFAULTS { kbd(0xf6); }
134 | ALL TYPEMATIC { kbd(0xf7); }
135 | ALL MAKE RELEASE { kbd(0xf8); }
136 | ALL MAKE ONLY { kbd(0xf9); }
137 | ALL TYPEMATIC MAKE RELEASE
139 | NUM TYPEMATIC { kbd(0xfb); kbd($1); }
140 | NUM MAKE RELEASE { kbd(0xfc); kbd($1); }
141 | NUM MAKE ONLY { kbd(0xfd); kbd($1); }
142 | RESEND { kbd(0xfe); }
143 | RESET { kbd(0xff); }
144 | CMD '?' { kbc(0x20); cmdbyte(kbget()); }
145 | CMD '=' expr { kbc(0x60); kbd($3); }
149 expr: opr { $$ = $1; }
150 | expr '+' opr { $$ = $1 | $3; }
151 | expr '-' opr { $$ = $1 & ~($3); }
154 opr: NUM { $$ = $1; }
155 | CMD { kbc(0x20); $$ = kbget(); }
165 "Input consists of lines, containing one or more semicolon-separated\n"
166 "statements. Numbers are implicitly hexadecimal, append a dot for\n"
167 "decimal numbers. Valid statements include:\n"
168 "help [expr]; give help [to expression syntax]\n"
169 "status ? interpret kbd ctrl status byte\n"
170 "what ? check for MCA type 1 or 2 motherboard controller\n"
171 "data ? get one byte of data\n"
172 "led = NUM set kbd LEDs\n"
173 "echo = NUM echo byte to kbd\n"
174 "scan = NUM; scan ? set scan code set; return current set\n"
175 "id ? get two id bytes\n"
176 "typematic=delay,rate set typematic delay(ms)&rate(1/s)\n"
177 "enable; defaults enable kbd; back to defaults\n"
178 "all typematic make all keys typematic\n"
179 "all make release make all keys sending make/release\n"
180 "all make only make all keys sending make only\n"
181 "all typematic make release make all keys typematic & make/release\n"
182 "NUM typematic make specific key typematic\n"
183 "NUM make release make specific key sending make/release\n"
184 "NUM make only make specific key sending make only\n"
185 "resend; reset resend last byte from kbd; reset kbd\n"
186 "cmd ? fetch kbd ctrl command byte\n"
187 "cmd = expr set kbd ctrl command byte\n"
193 "Expressions can either consist of a number, possibly followed\n"
194 "by a + or - sign and bit values in numeric or symbolic form.\n"
195 "Symbolic bit values are:\n"
196 "SCCONV IGNPAR CLKLOW OVRINH TEST IRQ\n"
205 if(c&0x80) printf("parity error | ");
206 if(c&0x40) printf("rx timeout | ");
207 if(c&0x20) printf("tx timeout | ");
208 if(c&0x10) printf("kbd released ");
209 else printf("kbd locked ");
210 if(c&0x08) printf("| cmd last sent ");
211 else printf("| data last sent ");
212 if(c&0x04) printf("| power-on ");
213 else printf("| test ok ");
214 if(c&0x02) printf("| ctrl write busy ");
215 else printf("| ctrl write ok ");
216 if(c&0x01) printf("| ctrl read ok\n");
217 else printf("| ctrl read empty\n");
220 /* see: Frank van Gilluwe, "The Undocumented PC", Addison Wesley 1994, pp 273 */
225 kbc(0x20); /* get command byte */
226 sav = kbget(); /* sav = command byte */
227 kbc(0x60); /* set command byte */
228 kbd(sav | 0x40); /* set keyboard xlate bit */
229 kbc(0x20); /* get keyboard command */
230 new = kbget(); /* new = command byte */
231 kbc(0x60); /* set command byte */
232 kbd(sav); /* restore command byte */
234 printf("Hmm - looks like MCA type 1 motherboard controller\n");
236 printf("Hmm - looks like MCA type 2 motherboard controller\n");
242 while(i && (inb(0x64) & 2)) i--;
243 if(i == 0) { printf("kbd write: timed out\n"); return; }
250 while(i && (inb(0x64) & 2)) i--;
251 if(i == 0) { printf("ctrl write: timed out\n"); return; }
260 while(i && (inb(0x64) & 1) == 0) i--;
261 if(i == 0) { printf("data read: timed out\n"); return -1; }
263 c = (unsigned char)inb(0x60);
266 printf("got kbd overrun\n"); break;
268 printf("got self-test OK\n"); break;
270 printf("got ECHO byte\n"); break;
272 printf("got ACK\n"); break;
274 printf("got self-test FAIL\n"); break;
276 printf("got internal failure\n"); break;
278 printf("got RESEND request\n"); break;
289 if(d&0x40) printf("scan conv ");
290 else printf("pass thru ");
291 if(d&0x20) printf("| ign parity ");
292 else printf("| check parity ");
293 if(d&0x10) printf("| kbd clk low ");
294 else printf("| enable kbd ");
295 if(d&0x08) printf("| override kbd inh ");
296 if(d&0x04) printf("| test ok ");
297 else printf("| power-on ");
298 if(d&0x01) printf("| irq 1 enable\n");
299 else printf("| no irq\n");
305 printf("data: 0x%02x\n", d);
308 void yyerror(const char *msg) {
309 fprintf(stderr, "yyerror: %s\n", msg);
312 int main(int argc, char **argv) {
315 if(argc > 1) yydebug = 1;
317 if((fd = open("/dev/console", O_RDONLY)) < 0)
320 if(ioctl(fd, KDENABIO, 0) < 0) {
321 perror("ioctl(KDENABIO)");
326 (void)ioctl(fd, KDDISABIO, 0);