source: mainline/kbd/arch/ia32/src/kbd.c@ ce5bcb4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ce5bcb4 was ce5bcb4, checked in by Josef Cejka <malyzelenyhnus@…>, 19 years ago

Doxygen comments update.

  • Property mode set to 100644
File size: 9.5 KB
RevLine 
[51d6f80]1/*
2 * Copyright (C) 2001-2004 Jakub Jermar
3 * Copyright (C) 2006 Josef Cejka
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - 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 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[ce5bcb4]30/** @addtogroup kbdia32 ia32
31 * @brief HelenOS ia32 arch dependent parts of uspace keyboard handler.
32 * @ingroup kbd
33 * @{
34 */
35/** @file
36 */
37
[51d6f80]38#include <arch/kbd.h>
[38edb96]39#include <ipc/ipc.h>
[51d6f80]40
[1890e312]41#define SPECIAL 255
[51d6f80]42#define KEY_RELEASE 0x80
43
44/**
45 * These codes read from i8042 data register are silently ignored.
46 */
47#define IGNORE_CODE 0x7f
48
49#define PRESSED_SHIFT (1<<0)
50#define PRESSED_CAPSLOCK (1<<1)
51#define LOCKED_CAPSLOCK (1<<0)
52
53/** Scancodes. */
54#define SC_ESC 0x01
55#define SC_BACKSPACE 0x0e
56#define SC_LSHIFT 0x2a
57#define SC_RSHIFT 0x36
58#define SC_CAPSLOCK 0x3a
59#define SC_SPEC_ESCAPE 0xe0
60#define SC_LEFTARR 0x4b
61#define SC_RIGHTARR 0x4d
62#define SC_UPARR 0x48
63#define SC_DOWNARR 0x50
64#define SC_DELETE 0x53
65#define SC_HOME 0x47
66#define SC_END 0x4f
67
[dd641e3]68#define FUNCTION_KEYS 0x100
69
[51d6f80]70static volatile int keyflags; /**< Tracking of multiple keypresses. */
71static volatile int lockflags; /**< Tracking of multiple keys lockings. */
72
73/** Primary meaning of scancodes. */
[dd641e3]74static int sc_primary_map[] = {
[51d6f80]75 SPECIAL, /* 0x00 */
76 SPECIAL, /* 0x01 - Esc */
77 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
78 '\b', /* 0x0e - Backspace */
79 '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
80 SPECIAL, /* 0x1d - LCtrl */
81 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'',
82 '`',
83 SPECIAL, /* 0x2a - LShift */
84 '\\',
85 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
86 SPECIAL, /* 0x36 - RShift */
87 '*',
88 SPECIAL, /* 0x38 - LAlt */
89 ' ',
90 SPECIAL, /* 0x3a - CapsLock */
[dd641e3]91 (FUNCTION_KEYS | 1), /* 0x3b - F1 */
92 (FUNCTION_KEYS | 2), /* 0x3c - F2 */
93 (FUNCTION_KEYS | 3), /* 0x3d - F3 */
94 (FUNCTION_KEYS | 4), /* 0x3e - F4 */
95 (FUNCTION_KEYS | 5), /* 0x3f - F5 */
96 (FUNCTION_KEYS | 6), /* 0x40 - F6 */
97 (FUNCTION_KEYS | 7), /* 0x41 - F7 */
98 (FUNCTION_KEYS | 8), /* 0x42 - F8 */
99 (FUNCTION_KEYS | 9), /* 0x43 - F9 */
100 (FUNCTION_KEYS | 10), /* 0x44 - F10 */
[51d6f80]101 SPECIAL, /* 0x45 - NumLock */
102 SPECIAL, /* 0x46 - ScrollLock */
103 '7', '8', '9', '-',
104 '4', '5', '6', '+',
105 '1', '2', '3',
106 '0', '.',
107 SPECIAL, /* 0x54 - Alt-SysRq */
108 SPECIAL, /* 0x55 - F11/F12/PF1/FN */
109 SPECIAL, /* 0x56 - unlabelled key next to LAlt */
[3dd98c7a]110 (FUNCTION_KEYS | 11), /* 0x57 - F11 */
111 (FUNCTION_KEYS | 12), /* 0x58 - F12 */
[51d6f80]112 SPECIAL, /* 0x59 */
113 SPECIAL, /* 0x5a */
114 SPECIAL, /* 0x5b */
115 SPECIAL, /* 0x5c */
116 SPECIAL, /* 0x5d */
117 SPECIAL, /* 0x5e */
118 SPECIAL, /* 0x5f */
119 SPECIAL, /* 0x60 */
120 SPECIAL, /* 0x61 */
121 SPECIAL, /* 0x62 */
122 SPECIAL, /* 0x63 */
123 SPECIAL, /* 0x64 */
124 SPECIAL, /* 0x65 */
125 SPECIAL, /* 0x66 */
126 SPECIAL, /* 0x67 */
127 SPECIAL, /* 0x68 */
128 SPECIAL, /* 0x69 */
129 SPECIAL, /* 0x6a */
130 SPECIAL, /* 0x6b */
131 SPECIAL, /* 0x6c */
132 SPECIAL, /* 0x6d */
133 SPECIAL, /* 0x6e */
134 SPECIAL, /* 0x6f */
135 SPECIAL, /* 0x70 */
136 SPECIAL, /* 0x71 */
137 SPECIAL, /* 0x72 */
138 SPECIAL, /* 0x73 */
139 SPECIAL, /* 0x74 */
140 SPECIAL, /* 0x75 */
141 SPECIAL, /* 0x76 */
142 SPECIAL, /* 0x77 */
143 SPECIAL, /* 0x78 */
144 SPECIAL, /* 0x79 */
145 SPECIAL, /* 0x7a */
146 SPECIAL, /* 0x7b */
147 SPECIAL, /* 0x7c */
148 SPECIAL, /* 0x7d */
149 SPECIAL, /* 0x7e */
150 SPECIAL, /* 0x7f */
151};
152
153/** Secondary meaning of scancodes. */
[3dd98c7a]154static int sc_secondary_map[] = {
[51d6f80]155 SPECIAL, /* 0x00 */
[e8d77a4]156 0x1b, /* 0x01 - Esc */
[51d6f80]157 '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
158 SPECIAL, /* 0x0e - Backspace */
159 '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n',
160 SPECIAL, /* 0x1d - LCtrl */
161 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"',
162 '~',
163 SPECIAL, /* 0x2a - LShift */
164 '|',
165 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
166 SPECIAL, /* 0x36 - RShift */
167 '*',
168 SPECIAL, /* 0x38 - LAlt */
169 ' ',
170 SPECIAL, /* 0x3a - CapsLock */
[bd929cfb]171 SPECIAL, /* 0x3b - F1 */
172 SPECIAL, /* 0x3c - F2 */
173 SPECIAL, /* 0x3d - F3 */
174 SPECIAL, /* 0x3e - F4 */
175 SPECIAL, /* 0x3f - F5 */
176 SPECIAL, /* 0x40 - F6 */
177 SPECIAL, /* 0x41 - F7 */
178 SPECIAL, /* 0x42 - F8 */
179 SPECIAL, /* 0x43 - F9 */
180 SPECIAL, /* 0x44 - F10 */
[51d6f80]181 SPECIAL, /* 0x45 - NumLock */
182 SPECIAL, /* 0x46 - ScrollLock */
183 '7', '8', '9', '-',
184 '4', '5', '6', '+',
185 '1', '2', '3',
186 '0', '.',
187 SPECIAL, /* 0x54 - Alt-SysRq */
188 SPECIAL, /* 0x55 - F11/F12/PF1/FN */
189 SPECIAL, /* 0x56 - unlabelled key next to LAlt */
190 SPECIAL, /* 0x57 - F11 */
191 SPECIAL, /* 0x58 - F12 */
192 SPECIAL, /* 0x59 */
193 SPECIAL, /* 0x5a */
194 SPECIAL, /* 0x5b */
195 SPECIAL, /* 0x5c */
196 SPECIAL, /* 0x5d */
197 SPECIAL, /* 0x5e */
198 SPECIAL, /* 0x5f */
199 SPECIAL, /* 0x60 */
200 SPECIAL, /* 0x61 */
201 SPECIAL, /* 0x62 */
202 SPECIAL, /* 0x63 */
203 SPECIAL, /* 0x64 */
204 SPECIAL, /* 0x65 */
205 SPECIAL, /* 0x66 */
206 SPECIAL, /* 0x67 */
207 SPECIAL, /* 0x68 */
208 SPECIAL, /* 0x69 */
209 SPECIAL, /* 0x6a */
210 SPECIAL, /* 0x6b */
211 SPECIAL, /* 0x6c */
212 SPECIAL, /* 0x6d */
213 SPECIAL, /* 0x6e */
214 SPECIAL, /* 0x6f */
215 SPECIAL, /* 0x70 */
216 SPECIAL, /* 0x71 */
217 SPECIAL, /* 0x72 */
218 SPECIAL, /* 0x73 */
219 SPECIAL, /* 0x74 */
220 SPECIAL, /* 0x75 */
221 SPECIAL, /* 0x76 */
222 SPECIAL, /* 0x77 */
223 SPECIAL, /* 0x78 */
224 SPECIAL, /* 0x79 */
225 SPECIAL, /* 0x7a */
226 SPECIAL, /* 0x7b */
227 SPECIAL, /* 0x7c */
228 SPECIAL, /* 0x7d */
229 SPECIAL, /* 0x7e */
230 SPECIAL, /* 0x7f */
231};
232
233irq_cmd_t i8042_cmds[1] = {
234 { CMD_PORT_READ_1, (void *)0x60, 0 }
235};
236
237irq_code_t i8042_kbd = {
238 1,
239 i8042_cmds
240};
241
[79460ae]242static int key_released(keybuffer_t *keybuffer, unsigned char key)
[51d6f80]243{
244 switch (key) {
245 case SC_LSHIFT:
246 case SC_RSHIFT:
247 keyflags &= ~PRESSED_SHIFT;
248 break;
249 case SC_CAPSLOCK:
250 keyflags &= ~PRESSED_CAPSLOCK;
251 if (lockflags & LOCKED_CAPSLOCK)
252 lockflags &= ~LOCKED_CAPSLOCK;
253 else
254 lockflags |= LOCKED_CAPSLOCK;
255 break;
256 default:
257 break;
258 }
259}
260
[79460ae]261static int key_pressed(keybuffer_t *keybuffer, unsigned char key)
[51d6f80]262{
[dd641e3]263 int *map = sc_primary_map;
264 int ascii = sc_primary_map[key];
265 int shift, capslock;
266 int letter = 0;
[51d6f80]267
[e8d77a4]268 static int esc_count=0;
269
270
271 if ( key == SC_ESC ) {
272 esc_count++;
273 if ( esc_count == 3 ) {
274 __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
275 }
276 } else {
277 esc_count=0;
278 }
279
280
281
[51d6f80]282 switch (key) {
283 case SC_LSHIFT:
284 case SC_RSHIFT:
285 keyflags |= PRESSED_SHIFT;
286 break;
287 case SC_CAPSLOCK:
288 keyflags |= PRESSED_CAPSLOCK;
289 break;
290 case SC_SPEC_ESCAPE:
291 break;
[bd929cfb]292 /* case SC_LEFTARR:
[79460ae]293 if (keybuffer_available(keybuffer) >= 3) {
294 keybuffer_push(keybuffer, 0x1b);
295 keybuffer_push(keybuffer, 0x5b);
296 keybuffer_push(keybuffer, 0x44);
[51d6f80]297 }
298 break;
299 case SC_RIGHTARR:
[79460ae]300 if (keybuffer_available(keybuffer) >= 3) {
301 keybuffer_push(keybuffer, 0x1b);
302 keybuffer_push(keybuffer, 0x5b);
303 keybuffer_push(keybuffer, 0x43);
[51d6f80]304 }
305 break;
306 case SC_UPARR:
[79460ae]307 if (keybuffer_available(keybuffer) >= 3) {
308 keybuffer_push(keybuffer, 0x1b);
309 keybuffer_push(keybuffer, 0x5b);
310 keybuffer_push(keybuffer, 0x41);
[51d6f80]311 }
312 break;
313 case SC_DOWNARR:
[79460ae]314 if (keybuffer_available(keybuffer) >= 3) {
315 keybuffer_push(keybuffer, 0x1b);
316 keybuffer_push(keybuffer, 0x5b);
317 keybuffer_push(keybuffer, 0x42);
[51d6f80]318 }
319 break;
320 case SC_HOME:
[79460ae]321 if (keybuffer_available(keybuffer) >= 3) {
322 keybuffer_push(keybuffer, 0x1b);
323 keybuffer_push(keybuffer, 0x4f);
324 keybuffer_push(keybuffer, 0x48);
[51d6f80]325 }
326 break;
327 case SC_END:
[79460ae]328 if (keybuffer_available(keybuffer) >= 3) {
329 keybuffer_push(keybuffer, 0x1b);
330 keybuffer_push(keybuffer, 0x4f);
331 keybuffer_push(keybuffer, 0x46);
[51d6f80]332 }
333 break;
334 case SC_DELETE:
[79460ae]335 if (keybuffer_available(keybuffer) >= 4) {
336 keybuffer_push(keybuffer, 0x1b);
337 keybuffer_push(keybuffer, 0x5b);
338 keybuffer_push(keybuffer, 0x33);
339 keybuffer_push(keybuffer, 0x7e);
[51d6f80]340 }
341 break;
[bd929cfb]342 */ default:
[51d6f80]343 letter = ((ascii >= 'a') && (ascii <= 'z'));
344 capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
345 shift = keyflags & PRESSED_SHIFT;
346 if (letter && capslock)
347 shift = !shift;
348 if (shift)
349 map = sc_secondary_map;
[bd929cfb]350 if (map[key] != SPECIAL)
351 keybuffer_push(keybuffer, map[key]);
[51d6f80]352 break;
353 }
354}
355
356/** Register uspace irq handler
357 * @return
358 */
359int kbd_arch_init(void)
360{
361 return !(ipc_register_irq(1, &i8042_kbd));
362}
363
[79460ae]364int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
[51d6f80]365{
366 if (scan_code != IGNORE_CODE) {
367 if (scan_code & KEY_RELEASE)
[79460ae]368 key_released(keybuffer, scan_code ^ KEY_RELEASE);
[51d6f80]369 else
[79460ae]370 key_pressed(keybuffer, scan_code);
[51d6f80]371 }
372 return 1;
373}
[ce5bcb4]374
375/**
376 * @}
377 */
378
Note: See TracBrowser for help on using the repository browser.