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