1 /* $NetBSD: kbd.c,v 1.6 2009/03/14 15:36:04 dsl Exp $ */
4 * Copyright (C) 1995-1997 Gary Thomas (gdt@linuxppc.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.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Gary Thomas.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #if defined(CONS_BE) || defined(CONS_VGA)
34 #include <lib/libsa/stand.h>
40 #define L 0x0001 /* locking function */
41 #define SHF 0x0002 /* keyboard shift */
42 #define ALT 0x0004 /* alternate shift -- alternate chars */
43 #define NUM 0x0008 /* numeric shift cursors vs. numeric */
44 #define CTL 0x0010 /* control shift -- allows ctl function */
45 #define CPS 0x0020 /* caps shift -- swaps case of letter */
46 #define ASCII 0x0040 /* ascii code for this key */
47 #define STP 0x0080 /* stop output */
48 #define FUNC 0x0100 /* function key */
49 #define SCROLL 0x0200 /* scroll lock key */
51 #include "pcconstab.US"
53 u_char shfts
, ctls
, alts
, caps
, num
, stp
;
55 #define KBDATAP 0x60 /* kbd data port */
56 #define KBSTATUSPORT 0x61 /* kbd status */
57 #define KBSTATP 0x64 /* kbd status port */
61 #define _x__ 0x00 /* Unknown / unmapped */
63 const u_char keycode
[] = {
64 _x__
, 0x43, 0x41, 0x3F, 0x3D, 0x3B, 0x3C, _x__
, /* 0x00-0x07 */
65 _x__
, 0x44, 0x42, 0x40, 0x3E, 0x0F, 0x29, _x__
, /* 0x08-0x0F */
66 _x__
, 0x38, 0x2A, _x__
, 0x1D, 0x10, 0x02, _x__
, /* 0x10-0x17 */
67 _x__
, _x__
, 0x2C, 0x1F, 0x1E, 0x11, 0x03, _x__
, /* 0x18-0x1F */
68 _x__
, 0x2E, 0x2D, 0x20, 0x12, 0x05, 0x04, _x__
, /* 0x20-0x27 */
69 _x__
, 0x39, 0x2F, 0x21, 0x14, 0x13, 0x06, _x__
, /* 0x28-0x2F */
70 _x__
, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, _x__
, /* 0x30-0x37 */
71 _x__
, _x__
, 0x32, 0x24, 0x16, 0x08, 0x09, _x__
, /* 0x38-0x3F */
72 _x__
, 0x33, 0x25, 0x17, 0x18, 0x0B, 0x0A, _x__
, /* 0x40-0x47 */
73 _x__
, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0C, _x__
, /* 0x48-0x4F */
74 _x__
, _x__
, 0x28, _x__
, 0x1A, 0x0D, _x__
, _x__
, /* 0x50-0x57 */
75 0x3A, 0x36, 0x1C, 0x1B, _x__
, 0x2B, _x__
, _x__
, /* 0x58-0x5F */
76 _x__
, _x__
, _x__
, _x__
, _x__
, _x__
, 0x0E, _x__
, /* 0x60-0x67 */
77 _x__
, 0x4F, _x__
, 0x4B, 0x47, _x__
, _x__
, _x__
, /* 0x68-0x6F */
78 0x52, 0x53, 0x50, 0x4C, 0x4D, 0x48, 0x01, 0x45, /* 0x70-0x77 */
79 _x__
, 0x4E, 0x51, 0x4A, _x__
, 0x49, 0x46, 0x54, /* 0x78-0x7F */
90 if ((inb(KBSTATP
) & KBINRDY
) == 0)
92 } else while ((inb(KBSTATP
) & KBINRDY
) == 0)
97 brk
= dt
& 0x80; /* brk == 1 on key release */
98 dt
= dt
& 0x7f; /* keycode */
134 if ((act
& ASCII
) && !brk
) {
147 if (caps
&& (chr
>= 'a' && chr
<= 'z'))
149 #define CTRL(s) (s & 0x1F)
150 if ((chr
== '\r') || (chr
== '\n') ||
151 (chr
== CTRL('A')) || (chr
== CTRL('S'))) {
153 /* Wait for key up */
156 while ((inb(KBSTATP
) & KBINRDY
) == 0)
159 if (dt
& 0x80) /* key up */ break;
166 return (0); /* Ignore initial 'key up' codes */
177 while (inb(KBSTATP
) & KBOUTRDY
)
180 while ((inb(KBSTATP
) & KBINRDY
) == 0) /* wait input ready */
182 if ((c
= inb(KBDATAP
)) != 0x55) {
183 printf("Keyboard self test failed - result: %x\n", c
);
185 /* Enable interrupts and keyboard controller */
186 while (inb(KBSTATP
) & KBOUTRDY
)
189 while (inb(KBSTATP
) & KBOUTRDY
)
192 for (i
= 0; i
< 10000; i
++)
194 while (inb(KBSTATP
) & KBOUTRDY
)
203 while ((c
= kbd(0)) == 0)
211 return ((inb(KBSTATP
) & KBINRDY
) != 0);
213 #endif /* CONS_BE || CONS_VGA*/