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