xref: /onnv-gate/usr/src/uts/common/io/kb8042/at_keyprocess.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/stream.h>
31*0Sstevel@tonic-gate #include <sys/kbd.h>
32*0Sstevel@tonic-gate #include <sys/kbtrans.h>
33*0Sstevel@tonic-gate #include <sys/sunddi.h>
34*0Sstevel@tonic-gate #include <sys/consdev.h>
35*0Sstevel@tonic-gate #include <sys/promif.h>
36*0Sstevel@tonic-gate #include "kb8042.h"
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate  * A note on the SCAN_SET_2 #ifdef's:  This module was originally
40*0Sstevel@tonic-gate  * intended for handling Set 2 keyboard scan codes.  Now it has been
41*0Sstevel@tonic-gate  * switched to handle Set 1 keyboard scan codes.  The Set 2 tables
42*0Sstevel@tonic-gate  * and some other Set 2 specific elements have been preserved with
43*0Sstevel@tonic-gate  * these #ifdef's.  Also, the "break_prefix_received" variable and
44*0Sstevel@tonic-gate  * its surrounding structure were removed from the kb8042 struct,
45*0Sstevel@tonic-gate  * since Set 1 scan codes don't use this approach.
46*0Sstevel@tonic-gate  */
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate /*
49*0Sstevel@tonic-gate  * Debugging for this module is enabled by the kb8042_debug flag
50*0Sstevel@tonic-gate  * defined in kb8042.c.  See that module for details.  This flag is
51*0Sstevel@tonic-gate  * hotkey enabled by F10 if the kb8042_enable_debug_hotkey flag is set.
52*0Sstevel@tonic-gate  */
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate #if	defined(DEBUG) || defined(lint)
55*0Sstevel@tonic-gate #define	KD_DEBUG
56*0Sstevel@tonic-gate #endif
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate /*
59*0Sstevel@tonic-gate  * A note on the use of prom_printf here:  Most of these routines can be
60*0Sstevel@tonic-gate  * called from "polled mode", where we're servicing I/O requests from kmdb.
61*0Sstevel@tonic-gate  * Normal system services are not available from polled mode; cmn_err will
62*0Sstevel@tonic-gate  * not work.  prom_printf is the only safe output mechanism.
63*0Sstevel@tonic-gate  */
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate #if	defined(KD_DEBUG)
66*0Sstevel@tonic-gate extern boolean_t kb8042_debug;
67*0Sstevel@tonic-gate #define	DEBUG_KD(f)	{ if (kb8042_debug) prom_printf f; }
68*0Sstevel@tonic-gate #else
69*0Sstevel@tonic-gate #define	DEBUG_KD(f)	/* nothing */
70*0Sstevel@tonic-gate #endif
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate #define	KEYBAD		0xff		/* should generate an error */
73*0Sstevel@tonic-gate #define	KEYIGN		0xfe		/* ignore this sequence */
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate #define	KEY(code)	(code)
76*0Sstevel@tonic-gate #define	INVALID		KEYBAD
77*0Sstevel@tonic-gate #define	IGNORE		KEYIGN
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate /*
80*0Sstevel@tonic-gate  * These are the states of our parsing machine:
81*0Sstevel@tonic-gate  */
82*0Sstevel@tonic-gate #define	STATE_IDLE	0x10000000	/* Awaiting the start of a sequence */
83*0Sstevel@tonic-gate #define	STATE_E0	0x100000e0	/* Rec'd an E0 */
84*0Sstevel@tonic-gate #define	STATE_E1	0x100000e1	/* Rec'd an E1 (Pause key only) */
85*0Sstevel@tonic-gate #define	STATE_E1_1D	0x1000e11d	/* Rec'd an E1 1D (Pause key only) */
86*0Sstevel@tonic-gate #ifdef SCAN_SET_2
87*0Sstevel@tonic-gate #define	STATE_E1_14	0x1000e114	/* Rec'd an E1 14 (Pause key only) */
88*0Sstevel@tonic-gate #endif
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate #define	NELEM(a)	(sizeof (a) / sizeof (a)[0])
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate static const unsigned char	keytab_base[] = {
93*0Sstevel@tonic-gate /* scan		key number	keycap */
94*0Sstevel@tonic-gate /* 00 */	INVALID,
95*0Sstevel@tonic-gate /* 01 */	KEY(110),	/* Esc */
96*0Sstevel@tonic-gate /* 02 */	KEY(2),		/* 1 */
97*0Sstevel@tonic-gate /* 03 */	KEY(3),		/* 2 */
98*0Sstevel@tonic-gate /* 04 */	KEY(4),		/* 3 */
99*0Sstevel@tonic-gate /* 05 */	KEY(5),		/* 4 */
100*0Sstevel@tonic-gate /* 06 */	KEY(6),		/* 5 */
101*0Sstevel@tonic-gate /* 07 */	KEY(7),		/* 6 */
102*0Sstevel@tonic-gate /* 08 */	KEY(8),		/* 7 */
103*0Sstevel@tonic-gate /* 09 */	KEY(9),		/* 8 */
104*0Sstevel@tonic-gate /* 0a */	KEY(10),	/* 9 */
105*0Sstevel@tonic-gate /* 0b */	KEY(11),	/* 0 */
106*0Sstevel@tonic-gate /* 0c */	KEY(12),	/* - */
107*0Sstevel@tonic-gate /* 0d */	KEY(13),	/* = */
108*0Sstevel@tonic-gate /* 0e */	KEY(15),	/* backspace */
109*0Sstevel@tonic-gate /* 0f */	KEY(16),	/* tab */
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /* 10 */	KEY(17),	/* Q */
112*0Sstevel@tonic-gate /* 11 */	KEY(18),	/* W */
113*0Sstevel@tonic-gate /* 12 */	KEY(19),	/* E */
114*0Sstevel@tonic-gate /* 13 */	KEY(20),	/* R */
115*0Sstevel@tonic-gate /* 14 */	KEY(21),	/* T */
116*0Sstevel@tonic-gate /* 15 */	KEY(22),	/* Y */
117*0Sstevel@tonic-gate /* 16 */	KEY(23),	/* U */
118*0Sstevel@tonic-gate /* 17 */	KEY(24),	/* I */
119*0Sstevel@tonic-gate /* 18 */	KEY(25),	/* O */
120*0Sstevel@tonic-gate /* 19 */	KEY(26),	/* P */
121*0Sstevel@tonic-gate /* 1a */	KEY(27),	/* [ */
122*0Sstevel@tonic-gate /* 1b */	KEY(28),	/* ] */
123*0Sstevel@tonic-gate /* 1c */	KEY(43),	/* Enter (main) */
124*0Sstevel@tonic-gate /* 1d */	KEY(58),	/* L Ctrl */
125*0Sstevel@tonic-gate /* 1e */	KEY(31),	/* A */
126*0Sstevel@tonic-gate /* 1f */	KEY(32),	/* S */
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate /* 20 */	KEY(33),	/* D */
129*0Sstevel@tonic-gate /* 21 */	KEY(34),	/* F */
130*0Sstevel@tonic-gate /* 22 */	KEY(35),	/* G */
131*0Sstevel@tonic-gate /* 23 */	KEY(36),	/* H */
132*0Sstevel@tonic-gate /* 24 */	KEY(37),	/* J */
133*0Sstevel@tonic-gate /* 25 */	KEY(38),	/* K */
134*0Sstevel@tonic-gate /* 26 */	KEY(39),	/* L */
135*0Sstevel@tonic-gate /* 27 */	KEY(40),	/* ; */
136*0Sstevel@tonic-gate /* 28 */	KEY(41),	/* ' */
137*0Sstevel@tonic-gate /* 29 */	KEY(1),		/* ` */
138*0Sstevel@tonic-gate /* 2a */	KEY(44),	/* L Shift */
139*0Sstevel@tonic-gate /* 2b */	KEY(29),	/* \ */
140*0Sstevel@tonic-gate /* 2c */	KEY(46),	/* Z */
141*0Sstevel@tonic-gate /* 2d */	KEY(47),	/* X */
142*0Sstevel@tonic-gate /* 2e */	KEY(48),	/* C */
143*0Sstevel@tonic-gate /* 2f */	KEY(49),	/* V */
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate /* 30 */	KEY(50),	/* B */
146*0Sstevel@tonic-gate /* 31 */	KEY(51),	/* N */
147*0Sstevel@tonic-gate /* 32 */	KEY(52),	/* M */
148*0Sstevel@tonic-gate /* 33 */	KEY(53),	/* , */
149*0Sstevel@tonic-gate /* 34 */	KEY(54),	/* . */
150*0Sstevel@tonic-gate /* 35 */	KEY(55),	/* / */
151*0Sstevel@tonic-gate /* 36 */	KEY(57),	/* R Shift */
152*0Sstevel@tonic-gate /* 37 */	KEY(100),	/* * (num) */
153*0Sstevel@tonic-gate /* 38 */	KEY(60),	/* L Alt */
154*0Sstevel@tonic-gate /* 39 */	KEY(61),	/* Space */
155*0Sstevel@tonic-gate /* 3a */	KEY(30),	/* CapsLock */
156*0Sstevel@tonic-gate /* 3b */	KEY(112),	/* F1 */
157*0Sstevel@tonic-gate /* 3c */	KEY(113),	/* F2 */
158*0Sstevel@tonic-gate /* 3d */	KEY(114),	/* F3 */
159*0Sstevel@tonic-gate /* 3e */	KEY(115),	/* F4 */
160*0Sstevel@tonic-gate /* 3f */	KEY(116),	/* F5 */
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate /* 40 */	KEY(117),	/* F6 */
163*0Sstevel@tonic-gate /* 41 */	KEY(118),	/* F7 */
164*0Sstevel@tonic-gate /* 42 */	KEY(119),	/* F8 */
165*0Sstevel@tonic-gate /* 43 */	KEY(120),	/* F9 */
166*0Sstevel@tonic-gate /* 44 */	KEY(121),	/* F10 */
167*0Sstevel@tonic-gate /* 45 */	KEY(90),	/* NumLock */
168*0Sstevel@tonic-gate /* 46 */	KEY(125),	/* Scroll Lock */
169*0Sstevel@tonic-gate /* 47 */	KEY(91),	/* 7 (num) */
170*0Sstevel@tonic-gate /* 48 */	KEY(96),	/* 8 (num) */
171*0Sstevel@tonic-gate /* 49 */	KEY(101),	/* 9 (num) */
172*0Sstevel@tonic-gate /* 4a */	KEY(105),	/* - (num) */
173*0Sstevel@tonic-gate /* 4b */	KEY(92),	/* 4 (num) */
174*0Sstevel@tonic-gate /* 4c */	KEY(97),	/* 5 (num) */
175*0Sstevel@tonic-gate /* 4d */	KEY(102),	/* 6 (num) */
176*0Sstevel@tonic-gate /* 4e */	KEY(106),	/* + (num) */
177*0Sstevel@tonic-gate /* 4f */	KEY(93),	/* 1 (num) */
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate /* 50 */	KEY(98),	/* 2 (num) */
180*0Sstevel@tonic-gate /* 51 */	KEY(103),	/* 3 (num) */
181*0Sstevel@tonic-gate /* 52 */	KEY(99),	/* 0 (num) */
182*0Sstevel@tonic-gate /* 53 */	KEY(104),	/* . (num) */
183*0Sstevel@tonic-gate /* 54 */	KEY(124),	/* PrintScreen (with Alt) */
184*0Sstevel@tonic-gate /* 55 */	INVALID,
185*0Sstevel@tonic-gate /* 56 */	KEY(45),	/* not labled (102-key only) */
186*0Sstevel@tonic-gate /* 57 */	KEY(122),	/* F11 */
187*0Sstevel@tonic-gate /* 58 */	KEY(123),	/* F12 */
188*0Sstevel@tonic-gate /* 59 */	INVALID,
189*0Sstevel@tonic-gate /* 5a */	INVALID,
190*0Sstevel@tonic-gate /* 5b */	INVALID,
191*0Sstevel@tonic-gate /* 5c */	INVALID,
192*0Sstevel@tonic-gate /* 5d */	INVALID,
193*0Sstevel@tonic-gate /* 5e */	INVALID,
194*0Sstevel@tonic-gate /* 5f */	INVALID,
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate /* 60 */	INVALID,
197*0Sstevel@tonic-gate /* 61 */	INVALID,
198*0Sstevel@tonic-gate /* 62 */	INVALID,
199*0Sstevel@tonic-gate /* 63 */	INVALID,
200*0Sstevel@tonic-gate /* 64 */	INVALID,
201*0Sstevel@tonic-gate /* 65 */	INVALID,
202*0Sstevel@tonic-gate /* 66 */	INVALID,
203*0Sstevel@tonic-gate /* 67 */	INVALID,
204*0Sstevel@tonic-gate /* 68 */	INVALID,
205*0Sstevel@tonic-gate /* 69 */	INVALID,
206*0Sstevel@tonic-gate /* 6a */	INVALID,
207*0Sstevel@tonic-gate /* 6b */	INVALID,
208*0Sstevel@tonic-gate /* 6c */	INVALID,
209*0Sstevel@tonic-gate /* 6d */	INVALID,
210*0Sstevel@tonic-gate /* 6e */	INVALID,
211*0Sstevel@tonic-gate /* 6f */	INVALID,
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate /* 70 */	KEY(133),	/* Japanese 106-key keyboard */
214*0Sstevel@tonic-gate /* 71 */	INVALID,
215*0Sstevel@tonic-gate /* 72 */	INVALID,
216*0Sstevel@tonic-gate /* 73 */	KEY(56),	/* Japanese 106-key keyboard */
217*0Sstevel@tonic-gate /* 74 */	INVALID,
218*0Sstevel@tonic-gate /* 75 */	INVALID,
219*0Sstevel@tonic-gate /* 76 */	INVALID,
220*0Sstevel@tonic-gate /* 77 */	INVALID,
221*0Sstevel@tonic-gate /* 78 */	INVALID,
222*0Sstevel@tonic-gate /* 79 */	KEY(132),	/* Japanese 106-key keyboard */
223*0Sstevel@tonic-gate /* 7a */	INVALID,
224*0Sstevel@tonic-gate /* 7b */	KEY(131),	/* Japanese 106-key keyboard */
225*0Sstevel@tonic-gate /* 7c */	INVALID,
226*0Sstevel@tonic-gate /* 7d */	KEY(14),	/* Japanese 106-key keyboard */
227*0Sstevel@tonic-gate /* 7e */	INVALID,
228*0Sstevel@tonic-gate /* 7f */	INVALID,
229*0Sstevel@tonic-gate };
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate /*
232*0Sstevel@tonic-gate  * Parse table after receiving an E0 prefix code.
233*0Sstevel@tonic-gate  *
234*0Sstevel@tonic-gate  * Generally speaking, keys that were added on the 101-key keyboard are
235*0Sstevel@tonic-gate  * represented as an E0 followed by the code for an 84-key key.  Software
236*0Sstevel@tonic-gate  * ignorant of the 101-key keyboard ignores the E0 and so is handled
237*0Sstevel@tonic-gate  * compatibly.  Many of these variants involve "fake" shift presses
238*0Sstevel@tonic-gate  * and releases for compatibility; these are also prefixed with E0.
239*0Sstevel@tonic-gate  * We ignore these fake shifts.
240*0Sstevel@tonic-gate  */
241*0Sstevel@tonic-gate static const unsigned char	keytab_e0[] = {
242*0Sstevel@tonic-gate /* 00 */	INVALID,
243*0Sstevel@tonic-gate /* 01 */	INVALID,
244*0Sstevel@tonic-gate /* 02 */	INVALID,
245*0Sstevel@tonic-gate /* 03 */	INVALID,
246*0Sstevel@tonic-gate /* 04 */	INVALID,
247*0Sstevel@tonic-gate /* 05 */	INVALID,
248*0Sstevel@tonic-gate /* 06 */	INVALID,
249*0Sstevel@tonic-gate /* 07 */	INVALID,
250*0Sstevel@tonic-gate /* 08 */	INVALID,
251*0Sstevel@tonic-gate /* 09 */	INVALID,
252*0Sstevel@tonic-gate /* 0a */	INVALID,
253*0Sstevel@tonic-gate /* 0b */	INVALID,
254*0Sstevel@tonic-gate /* 0c */	INVALID,
255*0Sstevel@tonic-gate /* 0d */	INVALID,
256*0Sstevel@tonic-gate /* 0e */	INVALID,
257*0Sstevel@tonic-gate /* 0f */	INVALID,
258*0Sstevel@tonic-gate 
259*0Sstevel@tonic-gate /* 10 */	INVALID,
260*0Sstevel@tonic-gate /* 11 */	INVALID,
261*0Sstevel@tonic-gate /* 12 */	INVALID,
262*0Sstevel@tonic-gate /* 13 */	INVALID,
263*0Sstevel@tonic-gate /* 14 */	INVALID,
264*0Sstevel@tonic-gate /* 15 */	INVALID,
265*0Sstevel@tonic-gate /* 16 */	INVALID,
266*0Sstevel@tonic-gate /* 17 */	INVALID,
267*0Sstevel@tonic-gate /* 18 */	INVALID,
268*0Sstevel@tonic-gate /* 19 */	INVALID,
269*0Sstevel@tonic-gate /* 1a */	INVALID,
270*0Sstevel@tonic-gate /* 1b */	INVALID,
271*0Sstevel@tonic-gate /* 1c */	KEY(108),	/* Enter (num) */
272*0Sstevel@tonic-gate /* 1d */	KEY(64),	/* R Ctrl */
273*0Sstevel@tonic-gate /* 1e */	INVALID,
274*0Sstevel@tonic-gate /* 1f */	INVALID,
275*0Sstevel@tonic-gate 
276*0Sstevel@tonic-gate /* 20 */	INVALID,
277*0Sstevel@tonic-gate /* 21 */	INVALID,
278*0Sstevel@tonic-gate /* 22 */	INVALID,
279*0Sstevel@tonic-gate /* 23 */	INVALID,
280*0Sstevel@tonic-gate /* 24 */	INVALID,
281*0Sstevel@tonic-gate /* 25 */	INVALID,
282*0Sstevel@tonic-gate /* 26 */	INVALID,
283*0Sstevel@tonic-gate /* 27 */	INVALID,
284*0Sstevel@tonic-gate /* 28 */	INVALID,
285*0Sstevel@tonic-gate /* 29 */	INVALID,
286*0Sstevel@tonic-gate /* 2a */	INVALID,
287*0Sstevel@tonic-gate /* 2b */	INVALID,
288*0Sstevel@tonic-gate /* 2c */	INVALID,
289*0Sstevel@tonic-gate /* 2d */	INVALID,
290*0Sstevel@tonic-gate /* 2e */	INVALID,
291*0Sstevel@tonic-gate /* 2f */	INVALID,
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate /* 30 */	INVALID,
294*0Sstevel@tonic-gate /* 31 */	INVALID,
295*0Sstevel@tonic-gate /* 32 */	INVALID,
296*0Sstevel@tonic-gate /* 33 */	INVALID,
297*0Sstevel@tonic-gate /* 34 */	INVALID,
298*0Sstevel@tonic-gate /* 35 */	KEY(95),	/* / (num) */
299*0Sstevel@tonic-gate /* 36 */	INVALID,
300*0Sstevel@tonic-gate /* 37 */	KEY(124),	/* PrintScreen (no Alt) */
301*0Sstevel@tonic-gate /* 38 */	KEY(62),	/* R Alt */
302*0Sstevel@tonic-gate /* 39 */	INVALID,
303*0Sstevel@tonic-gate /* 3a */	INVALID,
304*0Sstevel@tonic-gate /* 3b */	INVALID,
305*0Sstevel@tonic-gate /* 3c */	INVALID,
306*0Sstevel@tonic-gate /* 3d */	INVALID,
307*0Sstevel@tonic-gate /* 3e */	INVALID,
308*0Sstevel@tonic-gate /* 3f */	INVALID,
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate /* 40 */	INVALID,
311*0Sstevel@tonic-gate /* 41 */	INVALID,
312*0Sstevel@tonic-gate /* 42 */	INVALID,
313*0Sstevel@tonic-gate /* 43 */	INVALID,
314*0Sstevel@tonic-gate /* 44 */	INVALID,
315*0Sstevel@tonic-gate /* 45 */	INVALID,
316*0Sstevel@tonic-gate /* 46 */	KEY(126),	/* Pause (with Cntl) */
317*0Sstevel@tonic-gate /* 47 */	KEY(80),	/* Home (arrow) */
318*0Sstevel@tonic-gate /* 48 */	KEY(83),	/* Up (arrow) */
319*0Sstevel@tonic-gate /* 49 */	KEY(85),	/* PgUp (arrow) */
320*0Sstevel@tonic-gate /* 4a */	INVALID,
321*0Sstevel@tonic-gate /* 4b */	KEY(79),	/* Left (arrow) */
322*0Sstevel@tonic-gate /* 4c */	INVALID,
323*0Sstevel@tonic-gate /* 4d */	KEY(89),	/* Right (arrow) */
324*0Sstevel@tonic-gate /* 4e */	INVALID,
325*0Sstevel@tonic-gate /* 4f */	KEY(81),	/* End (arrow) */
326*0Sstevel@tonic-gate 
327*0Sstevel@tonic-gate /* 50 */	KEY(84),	/* Down (arrow) */
328*0Sstevel@tonic-gate /* 51 */	KEY(86),	/* PgDn (arrow) */
329*0Sstevel@tonic-gate /* 52 */	KEY(75),	/* Insert (arrow) */
330*0Sstevel@tonic-gate /* 53 */	KEY(76),	/* Delete (arrow) */
331*0Sstevel@tonic-gate /* 54 */	INVALID,
332*0Sstevel@tonic-gate /* 55 */	INVALID,
333*0Sstevel@tonic-gate /* 56 */	INVALID,
334*0Sstevel@tonic-gate /* 57 */	INVALID,
335*0Sstevel@tonic-gate /* 58 */	INVALID,
336*0Sstevel@tonic-gate /* 59 */	INVALID,
337*0Sstevel@tonic-gate /* 5a */	INVALID,
338*0Sstevel@tonic-gate /* 5b */	KEY(59),	/* L Window (104-key) */
339*0Sstevel@tonic-gate /* 5c */	KEY(63),	/* R Window (104-key) */
340*0Sstevel@tonic-gate /* 5d */	KEY(65),	/* Menu (104-key) */
341*0Sstevel@tonic-gate /* 5e */	INVALID,
342*0Sstevel@tonic-gate /* 5f */	INVALID,
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate /* 60 */	INVALID,
345*0Sstevel@tonic-gate /* 61 */	INVALID,
346*0Sstevel@tonic-gate /* 62 */	INVALID,
347*0Sstevel@tonic-gate /* 63 */	INVALID,
348*0Sstevel@tonic-gate /* 64 */	INVALID,
349*0Sstevel@tonic-gate /* 65 */	INVALID,
350*0Sstevel@tonic-gate /* 66 */	INVALID,
351*0Sstevel@tonic-gate /* 67 */	INVALID,
352*0Sstevel@tonic-gate /* 68 */	INVALID,
353*0Sstevel@tonic-gate /* 69 */	INVALID,
354*0Sstevel@tonic-gate /* 6a */	INVALID,
355*0Sstevel@tonic-gate /* 6b */	INVALID,
356*0Sstevel@tonic-gate /* 6c */	INVALID,
357*0Sstevel@tonic-gate /* 6d */	INVALID,
358*0Sstevel@tonic-gate /* 6e */	INVALID,
359*0Sstevel@tonic-gate /* 6f */	INVALID,
360*0Sstevel@tonic-gate 
361*0Sstevel@tonic-gate /* 70 */	INVALID,
362*0Sstevel@tonic-gate /* 71 */	INVALID,
363*0Sstevel@tonic-gate /* 72 */	INVALID,
364*0Sstevel@tonic-gate /* 73 */	INVALID,
365*0Sstevel@tonic-gate /* 74 */	INVALID,
366*0Sstevel@tonic-gate /* 75 */	INVALID,
367*0Sstevel@tonic-gate /* 76 */	INVALID,
368*0Sstevel@tonic-gate /* 77 */	INVALID,
369*0Sstevel@tonic-gate /* 78 */	INVALID,
370*0Sstevel@tonic-gate /* 79 */	INVALID,
371*0Sstevel@tonic-gate /* 7a */	INVALID,
372*0Sstevel@tonic-gate /* 7b */	INVALID,
373*0Sstevel@tonic-gate /* 7c */	INVALID,
374*0Sstevel@tonic-gate /* 7d */	INVALID,
375*0Sstevel@tonic-gate /* 7e */	INVALID,
376*0Sstevel@tonic-gate };
377*0Sstevel@tonic-gate 
378*0Sstevel@tonic-gate 
379*0Sstevel@tonic-gate #ifdef SCAN_SET_2
380*0Sstevel@tonic-gate /*
381*0Sstevel@tonic-gate  *	Parse table for the base keyboard state.  The index is the start of
382*0Sstevel@tonic-gate  *	a new sequence.
383*0Sstevel@tonic-gate  *
384*0Sstevel@tonic-gate  * Questionable or unusual cases:
385*0Sstevel@tonic-gate  * 02		Old kd code says F7. Manual says no.
386*0Sstevel@tonic-gate  * 7f		Old kd code says this is an 84-key SysReq.  Manual says no.
387*0Sstevel@tonic-gate  * 87		Old kd code says 1 (num).  Manual says no.
388*0Sstevel@tonic-gate  * 8c		Old kd code says / (num).  Manual says no.
389*0Sstevel@tonic-gate  * aa		POST OK.  Handled by code.
390*0Sstevel@tonic-gate  * e0		Extend prefix.  Handled by code. (switches to E0 table)
391*0Sstevel@tonic-gate  * e1		Extend prefix.  Handled by code.  (Pause key only)
392*0Sstevel@tonic-gate  * f0		Break prefix.  Handled by code.
393*0Sstevel@tonic-gate  * f1		Korean Hangul/Hanja key.  Handled by code.
394*0Sstevel@tonic-gate  * f2		Korean Hangul key.  Handled by code.
395*0Sstevel@tonic-gate  * ff		Keyboard internal buffer overrun.  Handled by code.
396*0Sstevel@tonic-gate  *
397*0Sstevel@tonic-gate  * Other values past the end of the table are treated as INVALID.
398*0Sstevel@tonic-gate  */
399*0Sstevel@tonic-gate 
400*0Sstevel@tonic-gate static const unsigned char	keytab_base[] = {
401*0Sstevel@tonic-gate /* scan		state		keycap */
402*0Sstevel@tonic-gate /* 00 */	INVALID,
403*0Sstevel@tonic-gate /* 01 */	KEY(120),	/* F9 */
404*0Sstevel@tonic-gate /* 02 */	INVALID,	/* F7?  Old code says so but manual doesn't */
405*0Sstevel@tonic-gate /* 03 */	KEY(116),	/* F5 */
406*0Sstevel@tonic-gate /* 04 */	KEY(114),	/* F3 */
407*0Sstevel@tonic-gate /* 05 */	KEY(112),	/* F1 */
408*0Sstevel@tonic-gate /* 06 */	KEY(113),	/* F2 */
409*0Sstevel@tonic-gate /* 07 */	KEY(123),	/* F12 */
410*0Sstevel@tonic-gate /* 08 */	INVALID,
411*0Sstevel@tonic-gate /* 09 */	KEY(121),	/* F10 */
412*0Sstevel@tonic-gate /* 0a */	KEY(119),	/* F8 */
413*0Sstevel@tonic-gate /* 0b */	KEY(117),	/* F6 */
414*0Sstevel@tonic-gate /* 0c */	KEY(115),	/* F4 */
415*0Sstevel@tonic-gate /* 0d */	KEY(16),	/* tab */
416*0Sstevel@tonic-gate /* 0e */	KEY(1),		/* ` */
417*0Sstevel@tonic-gate /* 0f */	INVALID,
418*0Sstevel@tonic-gate /* 10 */	INVALID,
419*0Sstevel@tonic-gate /* 11 */	KEY(60),	/* L Alt */
420*0Sstevel@tonic-gate /* 12 */	KEY(44),	/* L Shift */
421*0Sstevel@tonic-gate /* 13 */	KEY(133),	/* Japanese 106-key */
422*0Sstevel@tonic-gate /* 14 */	KEY(58),	/* L Ctrl */
423*0Sstevel@tonic-gate /* 15 */	KEY(17),	/* Q */
424*0Sstevel@tonic-gate /* 16 */	KEY(2),		/* 1 */
425*0Sstevel@tonic-gate /* 17 */	INVALID,
426*0Sstevel@tonic-gate /* 18 */	INVALID,
427*0Sstevel@tonic-gate /* 19 */	INVALID,
428*0Sstevel@tonic-gate /* 1a */	KEY(46),	/* Z */
429*0Sstevel@tonic-gate /* 1b */	KEY(32),	/* S */
430*0Sstevel@tonic-gate /* 1c */	KEY(31),	/* A */
431*0Sstevel@tonic-gate /* 1d */	KEY(18),	/* W */
432*0Sstevel@tonic-gate /* 1e */	KEY(3),		/* 2 */
433*0Sstevel@tonic-gate /* 1f */	INVALID,
434*0Sstevel@tonic-gate /* 20 */	INVALID,
435*0Sstevel@tonic-gate /* 21 */	KEY(48),	/* C */
436*0Sstevel@tonic-gate /* 22 */	KEY(47),	/* X */
437*0Sstevel@tonic-gate /* 23 */	KEY(33),	/* D */
438*0Sstevel@tonic-gate /* 24 */	KEY(19),	/* E */
439*0Sstevel@tonic-gate /* 25 */	KEY(5),		/* 4 */
440*0Sstevel@tonic-gate /* 26 */	KEY(4),		/* 3 */
441*0Sstevel@tonic-gate /* 27 */	INVALID,
442*0Sstevel@tonic-gate /* 28 */	INVALID,
443*0Sstevel@tonic-gate /* 29 */	KEY(61),	/* Space */
444*0Sstevel@tonic-gate /* 2a */	KEY(49),	/* V */
445*0Sstevel@tonic-gate /* 2b */	KEY(34),	/* F */
446*0Sstevel@tonic-gate /* 2c */	KEY(21),	/* T */
447*0Sstevel@tonic-gate /* 2d */	KEY(20),	/* R */
448*0Sstevel@tonic-gate /* 2e */	KEY(6),		/* 5 */
449*0Sstevel@tonic-gate /* 2f */	INVALID,
450*0Sstevel@tonic-gate /* 30 */	INVALID,
451*0Sstevel@tonic-gate /* 31 */	KEY(51),	/* N */
452*0Sstevel@tonic-gate /* 32 */	KEY(50),	/* B */
453*0Sstevel@tonic-gate /* 33 */	KEY(36),	/* H */
454*0Sstevel@tonic-gate /* 34 */	KEY(35),	/* G */
455*0Sstevel@tonic-gate /* 35 */	KEY(22),	/* Y */
456*0Sstevel@tonic-gate /* 36 */	KEY(7),		/* 6 */
457*0Sstevel@tonic-gate /* 37 */	INVALID,
458*0Sstevel@tonic-gate /* 38 */	INVALID,
459*0Sstevel@tonic-gate /* 39 */	INVALID,
460*0Sstevel@tonic-gate /* 3a */	KEY(52),	/* M */
461*0Sstevel@tonic-gate /* 3b */	KEY(37),	/* J */
462*0Sstevel@tonic-gate /* 3c */	KEY(23),	/* U */
463*0Sstevel@tonic-gate /* 3d */	KEY(8),		/* 7 */
464*0Sstevel@tonic-gate /* 3e */	KEY(9),		/* 8 */
465*0Sstevel@tonic-gate /* 3f */	INVALID,
466*0Sstevel@tonic-gate /* 40 */	INVALID,
467*0Sstevel@tonic-gate /* 41 */	KEY(53),	/* , */
468*0Sstevel@tonic-gate /* 42 */	KEY(38),	/* K */
469*0Sstevel@tonic-gate /* 43 */	KEY(24),	/* I */
470*0Sstevel@tonic-gate /* 44 */	KEY(25),	/* O */
471*0Sstevel@tonic-gate /* 45 */	KEY(11),	/* 0 */
472*0Sstevel@tonic-gate /* 46 */	KEY(10),	/* 9 */
473*0Sstevel@tonic-gate /* 47 */	INVALID,
474*0Sstevel@tonic-gate /* 48 */	INVALID,
475*0Sstevel@tonic-gate /* 49 */	KEY(54),	/* . */
476*0Sstevel@tonic-gate /* 4a */	KEY(55),	/* / */
477*0Sstevel@tonic-gate /* 4b */	KEY(39),	/* L */
478*0Sstevel@tonic-gate /* 4c */	KEY(40),	/* ; */
479*0Sstevel@tonic-gate /* 4d */	KEY(26),	/* P */
480*0Sstevel@tonic-gate /* 4e */	KEY(12),	/* - */
481*0Sstevel@tonic-gate /* 4f */	INVALID,
482*0Sstevel@tonic-gate /* 50 */	INVALID,
483*0Sstevel@tonic-gate /* 51 */	KEY(56),	/* Japanese 106-key */
484*0Sstevel@tonic-gate /* 52 */	KEY(41),	/* ' */
485*0Sstevel@tonic-gate /* 53 */	INVALID,
486*0Sstevel@tonic-gate /* 54 */	KEY(27),	/* [ */
487*0Sstevel@tonic-gate /* 55 */	KEY(13),	/* = */
488*0Sstevel@tonic-gate /* 56 */	INVALID,
489*0Sstevel@tonic-gate /* 57 */	INVALID,
490*0Sstevel@tonic-gate /* 58 */	KEY(30),	/* CapsLock */
491*0Sstevel@tonic-gate /* 59 */	KEY(57),	/* R Shift */
492*0Sstevel@tonic-gate /* 5a */	KEY(43),	/* Enter (main) */
493*0Sstevel@tonic-gate /* 5b */	KEY(28),	/* ] */
494*0Sstevel@tonic-gate /* 5c */	INVALID,
495*0Sstevel@tonic-gate /* 5d */	KEY(29),	/* \, key 42 for 102-key */
496*0Sstevel@tonic-gate /* 5e */	INVALID,
497*0Sstevel@tonic-gate /* 5f */	INVALID,
498*0Sstevel@tonic-gate /* 60 */	INVALID,
499*0Sstevel@tonic-gate /* 61 */	KEY(45),	/* 102-key only, typically </> */
500*0Sstevel@tonic-gate /* 62 */	INVALID,
501*0Sstevel@tonic-gate /* 63 */	INVALID,
502*0Sstevel@tonic-gate /* 64 */	KEY(132),	/* Japanese 106-key */
503*0Sstevel@tonic-gate /* 65 */	INVALID,
504*0Sstevel@tonic-gate /* 66 */	KEY(15),	/* backspace */
505*0Sstevel@tonic-gate /* 67 */	KEY(131),	/* Japanese 106-key */
506*0Sstevel@tonic-gate /* 68 */	INVALID,
507*0Sstevel@tonic-gate /* 69 */	KEY(93),	/* 1 (num) */
508*0Sstevel@tonic-gate /* 6a */	KEY(14),	/* Japanese 106-key */
509*0Sstevel@tonic-gate /* 6b */	KEY(92),	/* 4 (num) */
510*0Sstevel@tonic-gate /* 6c */	KEY(91),	/* 7 (num) */
511*0Sstevel@tonic-gate /* 6d */	INVALID,
512*0Sstevel@tonic-gate /* 6e */	INVALID,
513*0Sstevel@tonic-gate /* 6f */	INVALID,
514*0Sstevel@tonic-gate /* 70 */	KEY(99),	/* 0 (num) */
515*0Sstevel@tonic-gate /* 71 */	KEY(104),	/* . (num) */
516*0Sstevel@tonic-gate /* 72 */	KEY(98),	/* 2 (num) */
517*0Sstevel@tonic-gate /* 73 */	KEY(97),	/* 5 (num) */
518*0Sstevel@tonic-gate /* 74 */	KEY(102),	/* 6 (num) */
519*0Sstevel@tonic-gate /* 75 */	KEY(96),	/* 8 (num) */
520*0Sstevel@tonic-gate /* 76 */	KEY(110),	/* Esc */
521*0Sstevel@tonic-gate /* 77 */	KEY(90),	/* NumLock */
522*0Sstevel@tonic-gate /* 78 */	KEY(122),	/* F11 */
523*0Sstevel@tonic-gate /* 79 */	KEY(106),	/* + (num) */
524*0Sstevel@tonic-gate /* 7a */	KEY(103),	/* 3 (num) */
525*0Sstevel@tonic-gate /* 7b */	KEY(105),	/* - (num) */
526*0Sstevel@tonic-gate /* 7c */	KEY(100),	/* * (num) */
527*0Sstevel@tonic-gate /* 7d */	KEY(101),	/* 9 (num) */
528*0Sstevel@tonic-gate /* 7e */	KEY(125),	/* Scroll Lock */
529*0Sstevel@tonic-gate /* 7f */	INVALID,	/* 84-key SysReq?  Manual says no. */
530*0Sstevel@tonic-gate /* 80 */	INVALID,
531*0Sstevel@tonic-gate /* 81 */	INVALID,
532*0Sstevel@tonic-gate /* 82 */	INVALID,
533*0Sstevel@tonic-gate /* 83 */	KEY(118),	/* F7 */
534*0Sstevel@tonic-gate /* 84 */	KEY(124),	/* PrintScreen (w/ Alt = SysRq) */
535*0Sstevel@tonic-gate };
536*0Sstevel@tonic-gate 
537*0Sstevel@tonic-gate /*
538*0Sstevel@tonic-gate  * Parse table after receiving an E0 prefix code.
539*0Sstevel@tonic-gate  *
540*0Sstevel@tonic-gate  * Generally speaking, keys that were added on the 101-key keyboard are
541*0Sstevel@tonic-gate  * represented as an E0 followed by the code for an 84-key key.  Software
542*0Sstevel@tonic-gate  * ignorant of the 101-key keyboard ignores the E0 and so is handled
543*0Sstevel@tonic-gate  * compatibly.  Many of these variants involve "fake" shift presses
544*0Sstevel@tonic-gate  * and releases for compatibility; these are also prefixed with E0.
545*0Sstevel@tonic-gate  * We ignore these fake shifts.
546*0Sstevel@tonic-gate  */
547*0Sstevel@tonic-gate static const unsigned char	keytab_e0[] = {
548*0Sstevel@tonic-gate /* 00 */	INVALID,
549*0Sstevel@tonic-gate /* 01 */	INVALID,
550*0Sstevel@tonic-gate /* 02 */	INVALID,
551*0Sstevel@tonic-gate /* 03 */	INVALID,
552*0Sstevel@tonic-gate /* 04 */	INVALID,
553*0Sstevel@tonic-gate /* 05 */	INVALID,
554*0Sstevel@tonic-gate /* 06 */	INVALID,
555*0Sstevel@tonic-gate /* 07 */	INVALID,
556*0Sstevel@tonic-gate /* 08 */	INVALID,
557*0Sstevel@tonic-gate /* 09 */	INVALID,
558*0Sstevel@tonic-gate /* 0a */	INVALID,
559*0Sstevel@tonic-gate /* 0b */	INVALID,
560*0Sstevel@tonic-gate /* 0c */	INVALID,
561*0Sstevel@tonic-gate /* 0d */	INVALID,
562*0Sstevel@tonic-gate /* 0e */	INVALID,
563*0Sstevel@tonic-gate /* 0f */	INVALID,
564*0Sstevel@tonic-gate /* 10 */	INVALID,
565*0Sstevel@tonic-gate /* 11 */	KEY(62),	/* R Alt */
566*0Sstevel@tonic-gate /* 12 */	IGNORE,		/* Fake L Shift */
567*0Sstevel@tonic-gate /* 13 */	INVALID,
568*0Sstevel@tonic-gate /* 14 */	KEY(64),	/* R Ctrl */
569*0Sstevel@tonic-gate /* 15 */	INVALID,
570*0Sstevel@tonic-gate /* 16 */	INVALID,
571*0Sstevel@tonic-gate /* 17 */	INVALID,
572*0Sstevel@tonic-gate /* 18 */	INVALID,
573*0Sstevel@tonic-gate /* 19 */	INVALID,
574*0Sstevel@tonic-gate /* 1a */	INVALID,
575*0Sstevel@tonic-gate /* 1b */	INVALID,
576*0Sstevel@tonic-gate /* 1c */	INVALID,
577*0Sstevel@tonic-gate /* 1d */	INVALID,
578*0Sstevel@tonic-gate /* 1e */	INVALID,
579*0Sstevel@tonic-gate /* 1f */	KEY(59),	/* L Window (104-key) */
580*0Sstevel@tonic-gate /* 20 */	INVALID,
581*0Sstevel@tonic-gate /* 21 */	INVALID,
582*0Sstevel@tonic-gate /* 22 */	INVALID,
583*0Sstevel@tonic-gate /* 23 */	INVALID,
584*0Sstevel@tonic-gate /* 24 */	INVALID,
585*0Sstevel@tonic-gate /* 25 */	INVALID,
586*0Sstevel@tonic-gate /* 26 */	INVALID,
587*0Sstevel@tonic-gate /* 27 */	KEY(63),	/* R Window (104-key) */
588*0Sstevel@tonic-gate /* 28 */	INVALID,
589*0Sstevel@tonic-gate /* 29 */	INVALID,
590*0Sstevel@tonic-gate /* 2a */	INVALID,
591*0Sstevel@tonic-gate /* 2b */	INVALID,
592*0Sstevel@tonic-gate /* 2c */	INVALID,
593*0Sstevel@tonic-gate /* 2d */	INVALID,
594*0Sstevel@tonic-gate /* 2e */	INVALID,
595*0Sstevel@tonic-gate /* 2f */	KEY(65),	/* Menu (104-key) */
596*0Sstevel@tonic-gate /* 30 */	INVALID,
597*0Sstevel@tonic-gate /* 31 */	INVALID,
598*0Sstevel@tonic-gate /* 32 */	INVALID,
599*0Sstevel@tonic-gate /* 33 */	INVALID,
600*0Sstevel@tonic-gate /* 34 */	INVALID,
601*0Sstevel@tonic-gate /* 35 */	INVALID,
602*0Sstevel@tonic-gate /* 36 */	INVALID,
603*0Sstevel@tonic-gate /* 37 */	INVALID,
604*0Sstevel@tonic-gate /* 38 */	INVALID,
605*0Sstevel@tonic-gate /* 39 */	INVALID,
606*0Sstevel@tonic-gate /* 3a */	INVALID,
607*0Sstevel@tonic-gate /* 3b */	INVALID,
608*0Sstevel@tonic-gate /* 3c */	INVALID,
609*0Sstevel@tonic-gate /* 3d */	INVALID,
610*0Sstevel@tonic-gate /* 3e */	INVALID,
611*0Sstevel@tonic-gate /* 3f */	INVALID,
612*0Sstevel@tonic-gate /* 40 */	INVALID,
613*0Sstevel@tonic-gate /* 41 */	INVALID,
614*0Sstevel@tonic-gate /* 42 */	INVALID,
615*0Sstevel@tonic-gate /* 43 */	INVALID,
616*0Sstevel@tonic-gate /* 44 */	INVALID,
617*0Sstevel@tonic-gate /* 45 */	INVALID,
618*0Sstevel@tonic-gate /* 46 */	INVALID,
619*0Sstevel@tonic-gate /* 47 */	INVALID,
620*0Sstevel@tonic-gate /* 48 */	INVALID,
621*0Sstevel@tonic-gate /* 49 */	INVALID,
622*0Sstevel@tonic-gate /* 4a */	KEY(95),	/* / (num) */
623*0Sstevel@tonic-gate /* 4b */	INVALID,
624*0Sstevel@tonic-gate /* 4c */	INVALID,
625*0Sstevel@tonic-gate /* 4d */	INVALID,
626*0Sstevel@tonic-gate /* 4e */	INVALID,
627*0Sstevel@tonic-gate /* 4f */	INVALID,
628*0Sstevel@tonic-gate /* 50 */	INVALID,
629*0Sstevel@tonic-gate /* 51 */	INVALID,
630*0Sstevel@tonic-gate /* 52 */	INVALID,
631*0Sstevel@tonic-gate /* 53 */	INVALID,
632*0Sstevel@tonic-gate /* 54 */	INVALID,
633*0Sstevel@tonic-gate /* 55 */	INVALID,
634*0Sstevel@tonic-gate /* 56 */	INVALID,
635*0Sstevel@tonic-gate /* 57 */	INVALID,
636*0Sstevel@tonic-gate /* 58 */	INVALID,
637*0Sstevel@tonic-gate /* 59 */	IGNORE,		/* Fake R Shift */
638*0Sstevel@tonic-gate /* 5a */	KEY(108),	/* Enter (num) */
639*0Sstevel@tonic-gate /* 5b */	INVALID,
640*0Sstevel@tonic-gate /* 5c */	INVALID,
641*0Sstevel@tonic-gate /* 5d */	INVALID,
642*0Sstevel@tonic-gate /* 5e */	INVALID,
643*0Sstevel@tonic-gate /* 5f */	INVALID,
644*0Sstevel@tonic-gate /* 60 */	INVALID,
645*0Sstevel@tonic-gate /* 61 */	INVALID,
646*0Sstevel@tonic-gate /* 62 */	INVALID,
647*0Sstevel@tonic-gate /* 63 */	INVALID,
648*0Sstevel@tonic-gate /* 64 */	INVALID,
649*0Sstevel@tonic-gate /* 65 */	INVALID,
650*0Sstevel@tonic-gate /* 66 */	INVALID,
651*0Sstevel@tonic-gate /* 67 */	INVALID,
652*0Sstevel@tonic-gate /* 68 */	INVALID,
653*0Sstevel@tonic-gate /* 69 */	KEY(81),	/* End (arrow) */
654*0Sstevel@tonic-gate /* 6a */	INVALID,
655*0Sstevel@tonic-gate /* 6b */	KEY(79),	/* Left (arrow) */
656*0Sstevel@tonic-gate /* 6c */	KEY(80),	/* Home (arrow) */
657*0Sstevel@tonic-gate /* 6d */	INVALID,
658*0Sstevel@tonic-gate /* 6e */	INVALID,
659*0Sstevel@tonic-gate /* 6f */	INVALID,
660*0Sstevel@tonic-gate /* 70 */	KEY(75),	/* Insert (arrow) */
661*0Sstevel@tonic-gate /* 71 */	KEY(76),	/* Delete (arrow) */
662*0Sstevel@tonic-gate /* 72 */	KEY(84),	/* Down (arrow) */
663*0Sstevel@tonic-gate /* 73 */	INVALID,
664*0Sstevel@tonic-gate /* 74 */	KEY(89),	/* Right (arrow) */
665*0Sstevel@tonic-gate /* 75 */	KEY(83),	/* Up (arrow) */
666*0Sstevel@tonic-gate /* 76 */	INVALID,
667*0Sstevel@tonic-gate /* 77 */	INVALID,
668*0Sstevel@tonic-gate /* 78 */	INVALID,
669*0Sstevel@tonic-gate /* 79 */	INVALID,
670*0Sstevel@tonic-gate /* 7a */	KEY(86),	/* PgDn (arrow) */
671*0Sstevel@tonic-gate /* 7b */	INVALID,
672*0Sstevel@tonic-gate /* 7c */	KEY(124),	/* PrintScreen (no Alt) */
673*0Sstevel@tonic-gate /* 7d */	KEY(85),	/* PgUp (arrow) */
674*0Sstevel@tonic-gate /* 7e */	KEY(126),	/* Pause (w/Ctrl = Break) */
675*0Sstevel@tonic-gate };
676*0Sstevel@tonic-gate 
677*0Sstevel@tonic-gate #endif /* SCAN_SET_2 */
678*0Sstevel@tonic-gate 
679*0Sstevel@tonic-gate /*
680*0Sstevel@tonic-gate  * Initialize the translation state machine.
681*0Sstevel@tonic-gate  */
682*0Sstevel@tonic-gate void
683*0Sstevel@tonic-gate KeyboardConvertScan_init(struct kb8042 *kb8042)
684*0Sstevel@tonic-gate {
685*0Sstevel@tonic-gate 	kb8042->parse_scan_state = STATE_IDLE;
686*0Sstevel@tonic-gate }
687*0Sstevel@tonic-gate 
688*0Sstevel@tonic-gate /*
689*0Sstevel@tonic-gate  *	KeyboardConvertScan(*kb8042, scan, *keynum, *state
690*0Sstevel@tonic-gate  *		*synthetic_release_needed)
691*0Sstevel@tonic-gate  *
692*0Sstevel@tonic-gate  *	State machine that takes scan codes from the keyboard and resolves
693*0Sstevel@tonic-gate  *	them to key numbers using the above tables.  Returns B_TRUE if this
694*0Sstevel@tonic-gate  *	scan code completes a scan code sequence, in which case "keynum",
695*0Sstevel@tonic-gate  *	"state", and "synthetic_release_needed" will be filled in correctly.
696*0Sstevel@tonic-gate  *
697*0Sstevel@tonic-gate  *	"synthetic_release_needed" is a hack to handle the additional two
698*0Sstevel@tonic-gate  *	keys on a Korean keyboard.  They report press only, so we tell the
699*0Sstevel@tonic-gate  *	upper layer to synthesize the release.
700*0Sstevel@tonic-gate  */
701*0Sstevel@tonic-gate boolean_t
702*0Sstevel@tonic-gate KeyboardConvertScan(
703*0Sstevel@tonic-gate     struct kb8042	*kb8042,
704*0Sstevel@tonic-gate     unsigned char	scan,
705*0Sstevel@tonic-gate     int			*keynum,
706*0Sstevel@tonic-gate     enum keystate	*state,
707*0Sstevel@tonic-gate     boolean_t		*synthetic_release_needed)
708*0Sstevel@tonic-gate {
709*0Sstevel@tonic-gate 	DEBUG_KD(("KeyboardConvertScan: 0x%02x ", scan));
710*0Sstevel@tonic-gate 
711*0Sstevel@tonic-gate 	*synthetic_release_needed = B_FALSE;
712*0Sstevel@tonic-gate 	*state = KEY_PRESSED;
713*0Sstevel@tonic-gate 
714*0Sstevel@tonic-gate 	switch (scan) {
715*0Sstevel@tonic-gate 	/*
716*0Sstevel@tonic-gate 	 * First, handle special cases.
717*0Sstevel@tonic-gate 	 * ACK has already been handled by our caller.
718*0Sstevel@tonic-gate 	 */
719*0Sstevel@tonic-gate 
720*0Sstevel@tonic-gate #ifdef SCAN_SET_2
721*0Sstevel@tonic-gate 	/*
722*0Sstevel@tonic-gate 	 * KAT_BREAK is 0xF0 and is not used for Set 1.   It is
723*0Sstevel@tonic-gate 	 * also the same as the break code for Japanese key 133.
724*0Sstevel@tonic-gate 	 * Therefore we don't treat it specially here.
725*0Sstevel@tonic-gate 	 */
726*0Sstevel@tonic-gate 	case KAT_BREAK:
727*0Sstevel@tonic-gate 		DEBUG_KD(("-> break prefix\n"));
728*0Sstevel@tonic-gate 		return (B_FALSE);	/* not a final keycode */
729*0Sstevel@tonic-gate #endif
730*0Sstevel@tonic-gate 	case KB_ERROR:
731*0Sstevel@tonic-gate 		/*
732*0Sstevel@tonic-gate 		 * Perhaps we should reset state here,
733*0Sstevel@tonic-gate 		 * since we no longer know what's going on.
734*0Sstevel@tonic-gate 		 */
735*0Sstevel@tonic-gate 		DEBUG_KD(("-> overrun\n"));
736*0Sstevel@tonic-gate 		return (B_FALSE);
737*0Sstevel@tonic-gate #ifdef SCAN_SET_2
738*0Sstevel@tonic-gate 	/*
739*0Sstevel@tonic-gate 	 * The KB_POST_OK code is 0xAA, which is the same as the Set 1
740*0Sstevel@tonic-gate 	 * break code for L-Shift.  Therefore, we don't treat it specially.
741*0Sstevel@tonic-gate 	 */
742*0Sstevel@tonic-gate 	case KB_POST_OK:
743*0Sstevel@tonic-gate #endif
744*0Sstevel@tonic-gate 	case KB_POST_FAIL:
745*0Sstevel@tonic-gate 		/*
746*0Sstevel@tonic-gate 		 * Perhaps we should reset the LEDs now.
747*0Sstevel@tonic-gate 		 * If so, this check should probably be in the main line.
748*0Sstevel@tonic-gate 		 * Perhaps we should tell the higher layers that the
749*0Sstevel@tonic-gate 		 * keyboard has been reset.
750*0Sstevel@tonic-gate 		 */
751*0Sstevel@tonic-gate 		/*
752*0Sstevel@tonic-gate 		 * Reset to idle
753*0Sstevel@tonic-gate 		 */
754*0Sstevel@tonic-gate 		kb8042->parse_scan_state = STATE_IDLE;
755*0Sstevel@tonic-gate 		DEBUG_KD(("-> POST %s\n", scan == KB_POST_OK ? "OK" : "FAIL"));
756*0Sstevel@tonic-gate 		return (B_FALSE);
757*0Sstevel@tonic-gate 
758*0Sstevel@tonic-gate 	case KXT_EXTEND:
759*0Sstevel@tonic-gate 	case KXT_EXTEND2:
760*0Sstevel@tonic-gate 	case KXT_HANGUL_HANJA:
761*0Sstevel@tonic-gate 	case KXT_HANGUL:
762*0Sstevel@tonic-gate 		/*
763*0Sstevel@tonic-gate 		 * Exclude these keys from the "default" test below.
764*0Sstevel@tonic-gate 		 */
765*0Sstevel@tonic-gate 		break;
766*0Sstevel@tonic-gate 
767*0Sstevel@tonic-gate 	default:
768*0Sstevel@tonic-gate 		/*
769*0Sstevel@tonic-gate 		 * See if it was a key release.
770*0Sstevel@tonic-gate 		 */
771*0Sstevel@tonic-gate 		if (scan > 0x80) {
772*0Sstevel@tonic-gate 			*state = KEY_RELEASED;
773*0Sstevel@tonic-gate 			scan -= 0x80;
774*0Sstevel@tonic-gate 		}
775*0Sstevel@tonic-gate 		break;
776*0Sstevel@tonic-gate 	}
777*0Sstevel@tonic-gate 
778*0Sstevel@tonic-gate 	switch (kb8042->parse_scan_state) {
779*0Sstevel@tonic-gate 	case STATE_IDLE:
780*0Sstevel@tonic-gate 		switch (scan) {
781*0Sstevel@tonic-gate 		case KXT_EXTEND:
782*0Sstevel@tonic-gate 			kb8042->parse_scan_state = STATE_E0;
783*0Sstevel@tonic-gate 			DEBUG_KD(("-> state E0\n"));
784*0Sstevel@tonic-gate 			return (B_FALSE);
785*0Sstevel@tonic-gate 
786*0Sstevel@tonic-gate 		case KXT_EXTEND2:
787*0Sstevel@tonic-gate 			kb8042->parse_scan_state = STATE_E1;
788*0Sstevel@tonic-gate 			DEBUG_KD(("-> state E1\n"));
789*0Sstevel@tonic-gate 			return (B_FALSE);
790*0Sstevel@tonic-gate 
791*0Sstevel@tonic-gate 		/*
792*0Sstevel@tonic-gate 		 * We could do the next two in the table, but it would
793*0Sstevel@tonic-gate 		 * require nearly doubling the size of the table.
794*0Sstevel@tonic-gate 		 *
795*0Sstevel@tonic-gate 		 * Also, for some stupid reason these two report presses
796*0Sstevel@tonic-gate 		 * only.  We tell the upper layer to synthesize a release.
797*0Sstevel@tonic-gate 		 */
798*0Sstevel@tonic-gate 		case KXT_HANGUL_HANJA:
799*0Sstevel@tonic-gate 			*keynum = KEY(150);
800*0Sstevel@tonic-gate 			*synthetic_release_needed = B_TRUE;
801*0Sstevel@tonic-gate 			break;
802*0Sstevel@tonic-gate 
803*0Sstevel@tonic-gate 		case KXT_HANGUL:
804*0Sstevel@tonic-gate 			*keynum = KEY(151);
805*0Sstevel@tonic-gate 			*synthetic_release_needed = B_TRUE;
806*0Sstevel@tonic-gate 			break;
807*0Sstevel@tonic-gate 
808*0Sstevel@tonic-gate 		default:
809*0Sstevel@tonic-gate 			/*
810*0Sstevel@tonic-gate 			 * Regular scan code
811*0Sstevel@tonic-gate 			 */
812*0Sstevel@tonic-gate 			if (scan < NELEM(keytab_base))
813*0Sstevel@tonic-gate 				*keynum = keytab_base[scan];
814*0Sstevel@tonic-gate 			else
815*0Sstevel@tonic-gate 				*keynum = INVALID;
816*0Sstevel@tonic-gate 			break;
817*0Sstevel@tonic-gate 		}
818*0Sstevel@tonic-gate 		break;
819*0Sstevel@tonic-gate 
820*0Sstevel@tonic-gate 	case STATE_E0:		/* Mostly 101-key additions */
821*0Sstevel@tonic-gate 		if (scan < NELEM(keytab_e0))
822*0Sstevel@tonic-gate 			*keynum = keytab_e0[scan];
823*0Sstevel@tonic-gate 		else
824*0Sstevel@tonic-gate 			*keynum = INVALID;
825*0Sstevel@tonic-gate 		break;
826*0Sstevel@tonic-gate 
827*0Sstevel@tonic-gate 	case STATE_E1:		/* Pause key only */
828*0Sstevel@tonic-gate 		switch (scan) {
829*0Sstevel@tonic-gate 		case 0x1d:
830*0Sstevel@tonic-gate 			kb8042->parse_scan_state = STATE_E1_1D;
831*0Sstevel@tonic-gate 			DEBUG_KD(("-> state E1 1D\n"));
832*0Sstevel@tonic-gate 			return (B_FALSE);
833*0Sstevel@tonic-gate #ifdef SCAN_SET_2
834*0Sstevel@tonic-gate 		case 0x14:
835*0Sstevel@tonic-gate 			kb8042->parse_scan_state = STATE_E1_14;
836*0Sstevel@tonic-gate 			DEBUG_KD(("-> state E1 14\n"));
837*0Sstevel@tonic-gate 			return (B_FALSE);
838*0Sstevel@tonic-gate #endif
839*0Sstevel@tonic-gate 		default:
840*0Sstevel@tonic-gate 			*keynum = INVALID;
841*0Sstevel@tonic-gate 			break;
842*0Sstevel@tonic-gate 		}
843*0Sstevel@tonic-gate 		break;
844*0Sstevel@tonic-gate 
845*0Sstevel@tonic-gate 	case STATE_E1_1D:	/* Pause key only */
846*0Sstevel@tonic-gate 		switch (scan) {
847*0Sstevel@tonic-gate 		case 0x45:
848*0Sstevel@tonic-gate 			*keynum = KEY(126);	/* Pause */
849*0Sstevel@tonic-gate 			break;
850*0Sstevel@tonic-gate 		default:
851*0Sstevel@tonic-gate 			*keynum = INVALID;
852*0Sstevel@tonic-gate 			break;
853*0Sstevel@tonic-gate 		}
854*0Sstevel@tonic-gate 		break;
855*0Sstevel@tonic-gate #ifdef SCAN_SET_2
856*0Sstevel@tonic-gate 	case STATE_E1_14:	/* Pause key only */
857*0Sstevel@tonic-gate 		switch (scan) {
858*0Sstevel@tonic-gate 		case 0x77:
859*0Sstevel@tonic-gate 			*keynum = KEY(126);	/* Pause */
860*0Sstevel@tonic-gate 			break;
861*0Sstevel@tonic-gate 		default:
862*0Sstevel@tonic-gate 			*keynum = INVALID;
863*0Sstevel@tonic-gate 			break;
864*0Sstevel@tonic-gate 		}
865*0Sstevel@tonic-gate 		break;
866*0Sstevel@tonic-gate #endif
867*0Sstevel@tonic-gate 	}
868*0Sstevel@tonic-gate 
869*0Sstevel@tonic-gate 	/*
870*0Sstevel@tonic-gate 	 * The results (*keynum, *state, and *synthetic_release_needed)
871*0Sstevel@tonic-gate 	 * have been filled in, but they are valid only if we return
872*0Sstevel@tonic-gate 	 * B_TRUE which is only done below.  If we make it to here, we
873*0Sstevel@tonic-gate 	 * have completed a scan code sequence, so reset parse_scan_state.
874*0Sstevel@tonic-gate 	 */
875*0Sstevel@tonic-gate 
876*0Sstevel@tonic-gate 	kb8042->parse_scan_state = STATE_IDLE;
877*0Sstevel@tonic-gate 
878*0Sstevel@tonic-gate 	switch (*keynum) {
879*0Sstevel@tonic-gate 	case KEYIGN:				/* not a key, nor an error */
880*0Sstevel@tonic-gate 		DEBUG_KD(("-> hole -> ignored\n"));
881*0Sstevel@tonic-gate 		return (B_FALSE);		/* also not a final keycode */
882*0Sstevel@tonic-gate 
883*0Sstevel@tonic-gate 	case KEYBAD:		/* not part of a legit sequence? */
884*0Sstevel@tonic-gate 		DEBUG_KD(("-> bad -> ignored\n"));
885*0Sstevel@tonic-gate 		return (B_FALSE);	/* and return not a final keycode */
886*0Sstevel@tonic-gate 
887*0Sstevel@tonic-gate 	default:
888*0Sstevel@tonic-gate 		/*
889*0Sstevel@tonic-gate 		 * If we're here, it's a valid keycode.  We've already
890*0Sstevel@tonic-gate 		 * filled in the return values; return success.
891*0Sstevel@tonic-gate 		 */
892*0Sstevel@tonic-gate 
893*0Sstevel@tonic-gate 		DEBUG_KD(("-> %s keypos %d\n",
894*0Sstevel@tonic-gate 			*state == KEY_RELEASED ? "released" : "pressed",
895*0Sstevel@tonic-gate 			*keynum));
896*0Sstevel@tonic-gate 
897*0Sstevel@tonic-gate 		return (B_TRUE);		/* resolved to a key */
898*0Sstevel@tonic-gate 	}
899*0Sstevel@tonic-gate }
900