Rev 1657 | Rev 1707 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1657 | Rev 1694 | ||
---|---|---|---|
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 / amd64 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 | * @ingroup kbdamd64 |
37 | */ |
37 | */ |
38 | 38 | ||
39 | #include <arch/kbd.h> |
39 | #include <arch/kbd.h> |
40 | #include <ipc/ipc.h> |
40 | #include <ipc/ipc.h> |
- | 41 | #include <unistd.h> |
|
- | 42 | #include <kbd.h> |
|
- | 43 | #include <keys.h> |
|
- | 44 | ||
- | 45 | /* Interesting bits for status register */ |
|
- | 46 | #define i8042_OUTPUT_FULL 0x1 |
|
- | 47 | #define i8042_INPUT_FULL 0x2 |
|
- | 48 | #define i8042_MOUSE_DATA 0x20 |
|
- | 49 | ||
- | 50 | /* Command constants */ |
|
- | 51 | #define i8042_CMD_KBD 0x60 |
|
- | 52 | #define i8042_CMD_MOUSE 0xd4 |
|
- | 53 | ||
- | 54 | /* Keyboard cmd byte */ |
|
- | 55 | #define i8042_KBD_IE 0x1 |
|
- | 56 | #define i8042_MOUSE_IE 0x2 |
|
- | 57 | #define i8042_KBD_DISABLE 0x10 |
|
- | 58 | #define i8042_MOUSE_DISABLE 0x20 |
|
- | 59 | #define i8042_KBD_TRANSLATE 0x40 |
|
- | 60 | ||
- | 61 | /* Mouse constants */ |
|
- | 62 | #define MOUSE_OUT_INIT 0xf4 |
|
- | 63 | #define MOUSE_ACK 0xfa |
|
- | 64 | ||
41 | 65 | ||
42 | #define SPECIAL 255 |
66 | #define SPECIAL 255 |
43 | #define KEY_RELEASE 0x80 |
67 | #define KEY_RELEASE 0x80 |
44 | 68 | ||
45 | /** |
69 | /** |
46 | * These codes read from i8042 data register are silently ignored. |
70 | * These codes read from i8042 data register are silently ignored. |
47 | */ |
71 | */ |
48 | #define IGNORE_CODE 0x7f |
72 | #define IGNORE_CODE 0x7f |
49 | 73 | ||
50 | #define PRESSED_SHIFT (1<<0) |
74 | #define PRESSED_SHIFT (1<<0) |
51 | #define PRESSED_CAPSLOCK (1<<1) |
75 | #define PRESSED_CAPSLOCK (1<<1) |
52 | #define LOCKED_CAPSLOCK (1<<0) |
76 | #define LOCKED_CAPSLOCK (1<<0) |
53 | 77 | ||
54 | /** Scancodes. */ |
78 | /** Scancodes. */ |
55 | #define SC_ESC 0x01 |
79 | #define SC_ESC 0x01 |
56 | #define SC_BACKSPACE 0x0e |
80 | #define SC_BACKSPACE 0x0e |
57 | #define SC_LSHIFT 0x2a |
81 | #define SC_LSHIFT 0x2a |
58 | #define SC_RSHIFT 0x36 |
82 | #define SC_RSHIFT 0x36 |
59 | #define SC_CAPSLOCK 0x3a |
83 | #define SC_CAPSLOCK 0x3a |
60 | #define SC_SPEC_ESCAPE 0xe0 |
84 | #define SC_SPEC_ESCAPE 0xe0 |
61 | #define SC_LEFTARR 0x4b |
85 | #define SC_LEFTARR 0x4b |
62 | #define SC_RIGHTARR 0x4d |
86 | #define SC_RIGHTARR 0x4d |
63 | #define SC_UPARR 0x48 |
87 | #define SC_UPARR 0x48 |
64 | #define SC_DOWNARR 0x50 |
88 | #define SC_DOWNARR 0x50 |
65 | #define SC_DELETE 0x53 |
89 | #define SC_DELETE 0x53 |
66 | #define SC_HOME 0x47 |
90 | #define SC_HOME 0x47 |
67 | #define SC_END 0x4f |
91 | #define SC_END 0x4f |
68 | 92 | ||
69 | #define FUNCTION_KEYS 0x100 |
93 | #define FUNCTION_KEYS 0x100 |
70 | 94 | ||
71 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
95 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
72 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
96 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
73 | 97 | ||
74 | /** Primary meaning of scancodes. */ |
98 | /** Primary meaning of scancodes. */ |
75 | static int sc_primary_map[] = { |
99 | static int sc_primary_map[] = { |
76 | SPECIAL, /* 0x00 */ |
100 | SPECIAL, /* 0x00 */ |
77 | SPECIAL, /* 0x01 - Esc */ |
101 | SPECIAL, /* 0x01 - Esc */ |
78 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', |
102 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', |
79 | '\b', /* 0x0e - Backspace */ |
103 | '\b', /* 0x0e - Backspace */ |
80 | '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', |
104 | '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', |
81 | SPECIAL, /* 0x1d - LCtrl */ |
105 | SPECIAL, /* 0x1d - LCtrl */ |
82 | 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', |
106 | 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', |
83 | '`', |
107 | '`', |
84 | SPECIAL, /* 0x2a - LShift */ |
108 | SPECIAL, /* 0x2a - LShift */ |
85 | '\\', |
109 | '\\', |
86 | 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', |
110 | 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', |
87 | SPECIAL, /* 0x36 - RShift */ |
111 | SPECIAL, /* 0x36 - RShift */ |
88 | '*', |
112 | '*', |
89 | SPECIAL, /* 0x38 - LAlt */ |
113 | SPECIAL, /* 0x38 - LAlt */ |
90 | ' ', |
114 | ' ', |
91 | SPECIAL, /* 0x3a - CapsLock */ |
115 | SPECIAL, /* 0x3a - CapsLock */ |
92 | (FUNCTION_KEYS | 1), /* 0x3b - F1 */ |
116 | (FUNCTION_KEYS | 1), /* 0x3b - F1 */ |
93 | (FUNCTION_KEYS | 2), /* 0x3c - F2 */ |
117 | (FUNCTION_KEYS | 2), /* 0x3c - F2 */ |
94 | (FUNCTION_KEYS | 3), /* 0x3d - F3 */ |
118 | (FUNCTION_KEYS | 3), /* 0x3d - F3 */ |
95 | (FUNCTION_KEYS | 4), /* 0x3e - F4 */ |
119 | (FUNCTION_KEYS | 4), /* 0x3e - F4 */ |
96 | (FUNCTION_KEYS | 5), /* 0x3f - F5 */ |
120 | (FUNCTION_KEYS | 5), /* 0x3f - F5 */ |
97 | (FUNCTION_KEYS | 6), /* 0x40 - F6 */ |
121 | (FUNCTION_KEYS | 6), /* 0x40 - F6 */ |
98 | (FUNCTION_KEYS | 7), /* 0x41 - F7 */ |
122 | (FUNCTION_KEYS | 7), /* 0x41 - F7 */ |
99 | (FUNCTION_KEYS | 8), /* 0x42 - F8 */ |
123 | (FUNCTION_KEYS | 8), /* 0x42 - F8 */ |
100 | (FUNCTION_KEYS | 9), /* 0x43 - F9 */ |
124 | (FUNCTION_KEYS | 9), /* 0x43 - F9 */ |
101 | (FUNCTION_KEYS | 10), /* 0x44 - F10 */ |
125 | (FUNCTION_KEYS | 10), /* 0x44 - F10 */ |
102 | SPECIAL, /* 0x45 - NumLock */ |
126 | SPECIAL, /* 0x45 - NumLock */ |
103 | SPECIAL, /* 0x46 - ScrollLock */ |
127 | SPECIAL, /* 0x46 - ScrollLock */ |
104 | '7', '8', '9', '-', |
128 | '7', '8', '9', '-', |
105 | '4', '5', '6', '+', |
129 | '4', '5', '6', '+', |
106 | '1', '2', '3', |
130 | '1', '2', '3', |
107 | '0', '.', |
131 | '0', '.', |
108 | SPECIAL, /* 0x54 - Alt-SysRq */ |
132 | SPECIAL, /* 0x54 - Alt-SysRq */ |
109 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
133 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
110 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
134 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
111 | (FUNCTION_KEYS | 11), /* 0x57 - F11 */ |
135 | (FUNCTION_KEYS | 11), /* 0x57 - F11 */ |
112 | (FUNCTION_KEYS | 12), /* 0x58 - F12 */ |
136 | (FUNCTION_KEYS | 12), /* 0x58 - F12 */ |
113 | SPECIAL, /* 0x59 */ |
137 | SPECIAL, /* 0x59 */ |
114 | SPECIAL, /* 0x5a */ |
138 | SPECIAL, /* 0x5a */ |
115 | SPECIAL, /* 0x5b */ |
139 | SPECIAL, /* 0x5b */ |
116 | SPECIAL, /* 0x5c */ |
140 | SPECIAL, /* 0x5c */ |
117 | SPECIAL, /* 0x5d */ |
141 | SPECIAL, /* 0x5d */ |
118 | SPECIAL, /* 0x5e */ |
142 | SPECIAL, /* 0x5e */ |
119 | SPECIAL, /* 0x5f */ |
143 | SPECIAL, /* 0x5f */ |
120 | SPECIAL, /* 0x60 */ |
144 | SPECIAL, /* 0x60 */ |
121 | SPECIAL, /* 0x61 */ |
145 | SPECIAL, /* 0x61 */ |
122 | SPECIAL, /* 0x62 */ |
146 | SPECIAL, /* 0x62 */ |
123 | SPECIAL, /* 0x63 */ |
147 | SPECIAL, /* 0x63 */ |
124 | SPECIAL, /* 0x64 */ |
148 | SPECIAL, /* 0x64 */ |
125 | SPECIAL, /* 0x65 */ |
149 | SPECIAL, /* 0x65 */ |
126 | SPECIAL, /* 0x66 */ |
150 | SPECIAL, /* 0x66 */ |
127 | SPECIAL, /* 0x67 */ |
151 | SPECIAL, /* 0x67 */ |
128 | SPECIAL, /* 0x68 */ |
152 | SPECIAL, /* 0x68 */ |
129 | SPECIAL, /* 0x69 */ |
153 | SPECIAL, /* 0x69 */ |
130 | SPECIAL, /* 0x6a */ |
154 | SPECIAL, /* 0x6a */ |
131 | SPECIAL, /* 0x6b */ |
155 | SPECIAL, /* 0x6b */ |
132 | SPECIAL, /* 0x6c */ |
156 | SPECIAL, /* 0x6c */ |
133 | SPECIAL, /* 0x6d */ |
157 | SPECIAL, /* 0x6d */ |
134 | SPECIAL, /* 0x6e */ |
158 | SPECIAL, /* 0x6e */ |
135 | SPECIAL, /* 0x6f */ |
159 | SPECIAL, /* 0x6f */ |
136 | SPECIAL, /* 0x70 */ |
160 | SPECIAL, /* 0x70 */ |
137 | SPECIAL, /* 0x71 */ |
161 | SPECIAL, /* 0x71 */ |
138 | SPECIAL, /* 0x72 */ |
162 | SPECIAL, /* 0x72 */ |
139 | SPECIAL, /* 0x73 */ |
163 | SPECIAL, /* 0x73 */ |
140 | SPECIAL, /* 0x74 */ |
164 | SPECIAL, /* 0x74 */ |
141 | SPECIAL, /* 0x75 */ |
165 | SPECIAL, /* 0x75 */ |
142 | SPECIAL, /* 0x76 */ |
166 | SPECIAL, /* 0x76 */ |
143 | SPECIAL, /* 0x77 */ |
167 | SPECIAL, /* 0x77 */ |
144 | SPECIAL, /* 0x78 */ |
168 | SPECIAL, /* 0x78 */ |
145 | SPECIAL, /* 0x79 */ |
169 | SPECIAL, /* 0x79 */ |
146 | SPECIAL, /* 0x7a */ |
170 | SPECIAL, /* 0x7a */ |
147 | SPECIAL, /* 0x7b */ |
171 | SPECIAL, /* 0x7b */ |
148 | SPECIAL, /* 0x7c */ |
172 | SPECIAL, /* 0x7c */ |
149 | SPECIAL, /* 0x7d */ |
173 | SPECIAL, /* 0x7d */ |
150 | SPECIAL, /* 0x7e */ |
174 | SPECIAL, /* 0x7e */ |
151 | SPECIAL, /* 0x7f */ |
175 | SPECIAL, /* 0x7f */ |
152 | }; |
176 | }; |
153 | 177 | ||
154 | /** Secondary meaning of scancodes. */ |
178 | /** Secondary meaning of scancodes. */ |
155 | static int sc_secondary_map[] = { |
179 | static int sc_secondary_map[] = { |
156 | SPECIAL, /* 0x00 */ |
180 | SPECIAL, /* 0x00 */ |
157 | 0x1b, /* 0x01 - Esc */ |
181 | 0x1b, /* 0x01 - Esc */ |
158 | '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', |
182 | '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', |
159 | SPECIAL, /* 0x0e - Backspace */ |
183 | SPECIAL, /* 0x0e - Backspace */ |
160 | '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', |
184 | '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', |
161 | SPECIAL, /* 0x1d - LCtrl */ |
185 | SPECIAL, /* 0x1d - LCtrl */ |
162 | 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', |
186 | 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', |
163 | '~', |
187 | '~', |
164 | SPECIAL, /* 0x2a - LShift */ |
188 | SPECIAL, /* 0x2a - LShift */ |
165 | '|', |
189 | '|', |
166 | 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', |
190 | 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', |
167 | SPECIAL, /* 0x36 - RShift */ |
191 | SPECIAL, /* 0x36 - RShift */ |
168 | '*', |
192 | '*', |
169 | SPECIAL, /* 0x38 - LAlt */ |
193 | SPECIAL, /* 0x38 - LAlt */ |
170 | ' ', |
194 | ' ', |
171 | SPECIAL, /* 0x3a - CapsLock */ |
195 | SPECIAL, /* 0x3a - CapsLock */ |
172 | SPECIAL, /* 0x3b - F1 */ |
196 | SPECIAL, /* 0x3b - F1 */ |
173 | SPECIAL, /* 0x3c - F2 */ |
197 | SPECIAL, /* 0x3c - F2 */ |
174 | SPECIAL, /* 0x3d - F3 */ |
198 | SPECIAL, /* 0x3d - F3 */ |
175 | SPECIAL, /* 0x3e - F4 */ |
199 | SPECIAL, /* 0x3e - F4 */ |
176 | SPECIAL, /* 0x3f - F5 */ |
200 | SPECIAL, /* 0x3f - F5 */ |
177 | SPECIAL, /* 0x40 - F6 */ |
201 | SPECIAL, /* 0x40 - F6 */ |
178 | SPECIAL, /* 0x41 - F7 */ |
202 | SPECIAL, /* 0x41 - F7 */ |
179 | SPECIAL, /* 0x42 - F8 */ |
203 | SPECIAL, /* 0x42 - F8 */ |
180 | SPECIAL, /* 0x43 - F9 */ |
204 | SPECIAL, /* 0x43 - F9 */ |
181 | SPECIAL, /* 0x44 - F10 */ |
205 | SPECIAL, /* 0x44 - F10 */ |
182 | SPECIAL, /* 0x45 - NumLock */ |
206 | SPECIAL, /* 0x45 - NumLock */ |
183 | SPECIAL, /* 0x46 - ScrollLock */ |
207 | SPECIAL, /* 0x46 - ScrollLock */ |
184 | '7', '8', '9', '-', |
208 | '7', '8', '9', '-', |
185 | '4', '5', '6', '+', |
209 | '4', '5', '6', '+', |
186 | '1', '2', '3', |
210 | '1', '2', '3', |
187 | '0', '.', |
211 | '0', '.', |
188 | SPECIAL, /* 0x54 - Alt-SysRq */ |
212 | SPECIAL, /* 0x54 - Alt-SysRq */ |
189 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
213 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
190 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
214 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
191 | SPECIAL, /* 0x57 - F11 */ |
215 | SPECIAL, /* 0x57 - F11 */ |
192 | SPECIAL, /* 0x58 - F12 */ |
216 | SPECIAL, /* 0x58 - F12 */ |
193 | SPECIAL, /* 0x59 */ |
217 | SPECIAL, /* 0x59 */ |
194 | SPECIAL, /* 0x5a */ |
218 | SPECIAL, /* 0x5a */ |
195 | SPECIAL, /* 0x5b */ |
219 | SPECIAL, /* 0x5b */ |
196 | SPECIAL, /* 0x5c */ |
220 | SPECIAL, /* 0x5c */ |
197 | SPECIAL, /* 0x5d */ |
221 | SPECIAL, /* 0x5d */ |
198 | SPECIAL, /* 0x5e */ |
222 | SPECIAL, /* 0x5e */ |
199 | SPECIAL, /* 0x5f */ |
223 | SPECIAL, /* 0x5f */ |
200 | SPECIAL, /* 0x60 */ |
224 | SPECIAL, /* 0x60 */ |
201 | SPECIAL, /* 0x61 */ |
225 | SPECIAL, /* 0x61 */ |
202 | SPECIAL, /* 0x62 */ |
226 | SPECIAL, /* 0x62 */ |
203 | SPECIAL, /* 0x63 */ |
227 | SPECIAL, /* 0x63 */ |
204 | SPECIAL, /* 0x64 */ |
228 | SPECIAL, /* 0x64 */ |
205 | SPECIAL, /* 0x65 */ |
229 | SPECIAL, /* 0x65 */ |
206 | SPECIAL, /* 0x66 */ |
230 | SPECIAL, /* 0x66 */ |
207 | SPECIAL, /* 0x67 */ |
231 | SPECIAL, /* 0x67 */ |
208 | SPECIAL, /* 0x68 */ |
232 | SPECIAL, /* 0x68 */ |
209 | SPECIAL, /* 0x69 */ |
233 | SPECIAL, /* 0x69 */ |
210 | SPECIAL, /* 0x6a */ |
234 | SPECIAL, /* 0x6a */ |
211 | SPECIAL, /* 0x6b */ |
235 | SPECIAL, /* 0x6b */ |
212 | SPECIAL, /* 0x6c */ |
236 | SPECIAL, /* 0x6c */ |
213 | SPECIAL, /* 0x6d */ |
237 | SPECIAL, /* 0x6d */ |
214 | SPECIAL, /* 0x6e */ |
238 | SPECIAL, /* 0x6e */ |
215 | SPECIAL, /* 0x6f */ |
239 | SPECIAL, /* 0x6f */ |
216 | SPECIAL, /* 0x70 */ |
240 | SPECIAL, /* 0x70 */ |
217 | SPECIAL, /* 0x71 */ |
241 | SPECIAL, /* 0x71 */ |
218 | SPECIAL, /* 0x72 */ |
242 | SPECIAL, /* 0x72 */ |
219 | SPECIAL, /* 0x73 */ |
243 | SPECIAL, /* 0x73 */ |
220 | SPECIAL, /* 0x74 */ |
244 | SPECIAL, /* 0x74 */ |
221 | SPECIAL, /* 0x75 */ |
245 | SPECIAL, /* 0x75 */ |
222 | SPECIAL, /* 0x76 */ |
246 | SPECIAL, /* 0x76 */ |
223 | SPECIAL, /* 0x77 */ |
247 | SPECIAL, /* 0x77 */ |
224 | SPECIAL, /* 0x78 */ |
248 | SPECIAL, /* 0x78 */ |
225 | SPECIAL, /* 0x79 */ |
249 | SPECIAL, /* 0x79 */ |
226 | SPECIAL, /* 0x7a */ |
250 | SPECIAL, /* 0x7a */ |
227 | SPECIAL, /* 0x7b */ |
251 | SPECIAL, /* 0x7b */ |
228 | SPECIAL, /* 0x7c */ |
252 | SPECIAL, /* 0x7c */ |
229 | SPECIAL, /* 0x7d */ |
253 | SPECIAL, /* 0x7d */ |
230 | SPECIAL, /* 0x7e */ |
254 | SPECIAL, /* 0x7e */ |
231 | SPECIAL, /* 0x7f */ |
255 | SPECIAL, /* 0x7f */ |
232 | }; |
256 | }; |
233 | 257 | ||
234 | irq_cmd_t i8042_cmds[1] = { |
258 | irq_cmd_t i8042_cmds[2] = { |
- | 259 | { CMD_PORT_READ_1, (void *)0x64, 0, 1 }, |
|
235 | { CMD_PORT_READ_1, (void *)0x60, 0 } |
260 | { CMD_PORT_READ_1, (void *)0x60, 0, 2 } |
236 | }; |
261 | }; |
237 | 262 | ||
238 | irq_code_t i8042_kbd = { |
263 | irq_code_t i8042_kbd = { |
239 | 1, |
264 | 2, |
240 | i8042_cmds |
265 | i8042_cmds |
241 | }; |
266 | }; |
242 | 267 | ||
243 | static int key_released(keybuffer_t *keybuffer, unsigned char key) |
268 | static int key_released(keybuffer_t *keybuffer, unsigned char key) |
244 | { |
269 | { |
245 | switch (key) { |
270 | switch (key) { |
246 | case SC_LSHIFT: |
271 | case SC_LSHIFT: |
247 | case SC_RSHIFT: |
272 | case SC_RSHIFT: |
248 | keyflags &= ~PRESSED_SHIFT; |
273 | keyflags &= ~PRESSED_SHIFT; |
249 | break; |
274 | break; |
250 | case SC_CAPSLOCK: |
275 | case SC_CAPSLOCK: |
251 | keyflags &= ~PRESSED_CAPSLOCK; |
276 | keyflags &= ~PRESSED_CAPSLOCK; |
252 | if (lockflags & LOCKED_CAPSLOCK) |
277 | if (lockflags & LOCKED_CAPSLOCK) |
253 | lockflags &= ~LOCKED_CAPSLOCK; |
278 | lockflags &= ~LOCKED_CAPSLOCK; |
254 | else |
279 | else |
255 | lockflags |= LOCKED_CAPSLOCK; |
280 | lockflags |= LOCKED_CAPSLOCK; |
256 | break; |
281 | break; |
257 | default: |
282 | default: |
258 | break; |
283 | break; |
259 | } |
284 | } |
260 | } |
285 | } |
261 | 286 | ||
262 | static int key_pressed(keybuffer_t *keybuffer, unsigned char key) |
287 | static int key_pressed(keybuffer_t *keybuffer, unsigned char key) |
263 | { |
288 | { |
264 | int *map = sc_primary_map; |
289 | int *map = sc_primary_map; |
265 | int ascii = sc_primary_map[key]; |
290 | int ascii = sc_primary_map[key]; |
266 | int shift, capslock; |
291 | int shift, capslock; |
267 | int letter = 0; |
292 | int letter = 0; |
268 | 293 | ||
269 | static int esc_count=0; |
294 | static int esc_count=0; |
270 | 295 | ||
271 | 296 | ||
272 | if ( key == SC_ESC ) { |
297 | if ( key == SC_ESC ) { |
273 | esc_count++; |
298 | esc_count++; |
274 | if ( esc_count == 3 ) { |
299 | if ( esc_count == 3 ) { |
275 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
300 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
276 | } |
301 | } |
277 | } else { |
302 | } else { |
278 | esc_count=0; |
303 | esc_count=0; |
279 | } |
304 | } |
280 | 305 | ||
281 | 306 | ||
282 | 307 | ||
283 | switch (key) { |
308 | switch (key) { |
284 | case SC_LSHIFT: |
309 | case SC_LSHIFT: |
285 | case SC_RSHIFT: |
310 | case SC_RSHIFT: |
286 | keyflags |= PRESSED_SHIFT; |
311 | keyflags |= PRESSED_SHIFT; |
287 | break; |
312 | break; |
288 | case SC_CAPSLOCK: |
313 | case SC_CAPSLOCK: |
289 | keyflags |= PRESSED_CAPSLOCK; |
314 | keyflags |= PRESSED_CAPSLOCK; |
290 | break; |
315 | break; |
291 | case SC_SPEC_ESCAPE: |
316 | case SC_SPEC_ESCAPE: |
292 | break; |
317 | break; |
293 | /* case SC_LEFTARR: |
318 | /* case SC_LEFTARR: |
294 | if (keybuffer_available(keybuffer) >= 3) { |
319 | if (keybuffer_available(keybuffer) >= 3) { |
295 | keybuffer_push(keybuffer, 0x1b); |
320 | keybuffer_push(keybuffer, 0x1b); |
296 | keybuffer_push(keybuffer, 0x5b); |
321 | keybuffer_push(keybuffer, 0x5b); |
297 | keybuffer_push(keybuffer, 0x44); |
322 | keybuffer_push(keybuffer, 0x44); |
298 | } |
323 | } |
299 | break; |
324 | break; |
300 | case SC_RIGHTARR: |
325 | case SC_RIGHTARR: |
301 | if (keybuffer_available(keybuffer) >= 3) { |
326 | if (keybuffer_available(keybuffer) >= 3) { |
302 | keybuffer_push(keybuffer, 0x1b); |
327 | keybuffer_push(keybuffer, 0x1b); |
303 | keybuffer_push(keybuffer, 0x5b); |
328 | keybuffer_push(keybuffer, 0x5b); |
304 | keybuffer_push(keybuffer, 0x43); |
329 | keybuffer_push(keybuffer, 0x43); |
305 | } |
330 | } |
306 | break; |
331 | break; |
307 | case SC_UPARR: |
332 | case SC_UPARR: |
308 | if (keybuffer_available(keybuffer) >= 3) { |
333 | if (keybuffer_available(keybuffer) >= 3) { |
309 | keybuffer_push(keybuffer, 0x1b); |
334 | keybuffer_push(keybuffer, 0x1b); |
310 | keybuffer_push(keybuffer, 0x5b); |
335 | keybuffer_push(keybuffer, 0x5b); |
311 | keybuffer_push(keybuffer, 0x41); |
336 | keybuffer_push(keybuffer, 0x41); |
312 | } |
337 | } |
313 | break; |
338 | break; |
314 | case SC_DOWNARR: |
339 | case SC_DOWNARR: |
315 | if (keybuffer_available(keybuffer) >= 3) { |
340 | if (keybuffer_available(keybuffer) >= 3) { |
316 | keybuffer_push(keybuffer, 0x1b); |
341 | keybuffer_push(keybuffer, 0x1b); |
317 | keybuffer_push(keybuffer, 0x5b); |
342 | keybuffer_push(keybuffer, 0x5b); |
318 | keybuffer_push(keybuffer, 0x42); |
343 | keybuffer_push(keybuffer, 0x42); |
319 | } |
344 | } |
320 | break; |
345 | break; |
321 | case SC_HOME: |
346 | case SC_HOME: |
322 | if (keybuffer_available(keybuffer) >= 3) { |
347 | if (keybuffer_available(keybuffer) >= 3) { |
323 | keybuffer_push(keybuffer, 0x1b); |
348 | keybuffer_push(keybuffer, 0x1b); |
324 | keybuffer_push(keybuffer, 0x4f); |
349 | keybuffer_push(keybuffer, 0x4f); |
325 | keybuffer_push(keybuffer, 0x48); |
350 | keybuffer_push(keybuffer, 0x48); |
326 | } |
351 | } |
327 | break; |
352 | break; |
328 | case SC_END: |
353 | case SC_END: |
329 | if (keybuffer_available(keybuffer) >= 3) { |
354 | if (keybuffer_available(keybuffer) >= 3) { |
330 | keybuffer_push(keybuffer, 0x1b); |
355 | keybuffer_push(keybuffer, 0x1b); |
331 | keybuffer_push(keybuffer, 0x4f); |
356 | keybuffer_push(keybuffer, 0x4f); |
332 | keybuffer_push(keybuffer, 0x46); |
357 | keybuffer_push(keybuffer, 0x46); |
333 | } |
358 | } |
334 | break; |
359 | break; |
335 | case SC_DELETE: |
360 | case SC_DELETE: |
336 | if (keybuffer_available(keybuffer) >= 4) { |
361 | if (keybuffer_available(keybuffer) >= 4) { |
337 | keybuffer_push(keybuffer, 0x1b); |
362 | keybuffer_push(keybuffer, 0x1b); |
338 | keybuffer_push(keybuffer, 0x5b); |
363 | keybuffer_push(keybuffer, 0x5b); |
339 | keybuffer_push(keybuffer, 0x33); |
364 | keybuffer_push(keybuffer, 0x33); |
340 | keybuffer_push(keybuffer, 0x7e); |
365 | keybuffer_push(keybuffer, 0x7e); |
341 | } |
366 | } |
342 | break; |
367 | break; |
343 | */ default: |
368 | */ default: |
344 | letter = ((ascii >= 'a') && (ascii <= 'z')); |
369 | letter = ((ascii >= 'a') && (ascii <= 'z')); |
345 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
370 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
346 | shift = keyflags & PRESSED_SHIFT; |
371 | shift = keyflags & PRESSED_SHIFT; |
347 | if (letter && capslock) |
372 | if (letter && capslock) |
348 | shift = !shift; |
373 | shift = !shift; |
349 | if (shift) |
374 | if (shift) |
350 | map = sc_secondary_map; |
375 | map = sc_secondary_map; |
351 | if (map[key] != SPECIAL) |
376 | if (map[key] != SPECIAL) |
352 | keybuffer_push(keybuffer, map[key]); |
377 | keybuffer_push(keybuffer, map[key]); |
353 | break; |
378 | break; |
354 | } |
379 | } |
355 | } |
380 | } |
356 | 381 | ||
- | 382 | ||
- | 383 | static void wait_ready(void) { |
|
- | 384 | while (i8042_status_read() & i8042_INPUT_FULL) |
|
- | 385 | ; |
|
- | 386 | } |
|
- | 387 | ||
357 | /** Register uspace irq handler |
388 | /** Register uspace irq handler |
358 | * @return |
389 | * @return |
359 | */ |
390 | */ |
360 | int kbd_arch_init(void) |
391 | int kbd_arch_init(void) |
361 | { |
392 | { |
- | 393 | int rc1, i; |
|
- | 394 | int mouseenabled = 0; |
|
- | 395 | ||
- | 396 | iospace_enable(task_get_id(),(void *)i8042_DATA, 5); |
|
- | 397 | /* Disable kbd, enable mouse */ |
|
- | 398 | i8042_command_write(i8042_CMD_KBD); |
|
- | 399 | wait_ready(); |
|
- | 400 | i8042_command_write(i8042_CMD_KBD); |
|
- | 401 | wait_ready(); |
|
- | 402 | i8042_data_write(i8042_KBD_DISABLE); |
|
- | 403 | wait_ready(); |
|
- | 404 | ||
- | 405 | /* Flush all current IO */ |
|
362 | return !(ipc_register_irq(1, &i8042_kbd)); |
406 | while (i8042_status_read() & i8042_OUTPUT_FULL) |
- | 407 | i8042_data_read(); |
|
- | 408 | /* Initialize mouse */ |
|
- | 409 | i8042_command_write(i8042_CMD_MOUSE); |
|
- | 410 | wait_ready(); |
|
- | 411 | i8042_data_write(MOUSE_OUT_INIT); |
|
- | 412 | wait_ready(); |
|
- | 413 | ||
- | 414 | int mouseanswer = 0; |
|
- | 415 | for (i=0;i < 1000; i++) { |
|
- | 416 | int status = i8042_status_read(); |
|
- | 417 | if (status & i8042_OUTPUT_FULL) { |
|
- | 418 | int data = i8042_data_read(); |
|
- | 419 | if (status & i8042_MOUSE_DATA) { |
|
- | 420 | mouseanswer = data; |
|
- | 421 | break; |
|
- | 422 | } |
|
363 | } |
423 | } |
- | 424 | usleep(1000); |
|
- | 425 | } |
|
- | 426 | if (mouseanswer == MOUSE_ACK) { |
|
- | 427 | /* enable mouse */ |
|
- | 428 | mouseenabled = 1; |
|
- | 429 | ||
- | 430 | ipc_register_irq(MOUSE_IRQ, &i8042_kbd); |
|
- | 431 | } |
|
- | 432 | /* Enable kbd */ |
|
- | 433 | ipc_register_irq(KBD_IRQ, &i8042_kbd); |
|
- | 434 | ||
- | 435 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
|
- | 436 | if (mouseenabled) |
|
- | 437 | newcontrol |= i8042_MOUSE_IE; |
|
- | 438 | ||
- | 439 | i8042_command_write(i8042_CMD_KBD); |
|
- | 440 | wait_ready(); |
|
- | 441 | i8042_data_write(newcontrol); |
|
- | 442 | wait_ready(); |
|
364 | 443 | ||
- | 444 | return 0; |
|
- | 445 | } |
|
- | 446 | ||
- | 447 | /** Process keyboard & mouse events */ |
|
365 | int kbd_arch_process(keybuffer_t *keybuffer, int scan_code) |
448 | int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call) |
366 | { |
449 | { |
- | 450 | int status = IPC_GET_ARG1(*call); |
|
- | 451 | ||
- | 452 | if ((status & i8042_MOUSE_DATA)) { |
|
- | 453 | ; |
|
- | 454 | } else { |
|
- | 455 | int scan_code = IPC_GET_ARG2(*call); |
|
- | 456 | ||
367 | if (scan_code != IGNORE_CODE) { |
457 | if (scan_code != IGNORE_CODE) { |
368 | if (scan_code & KEY_RELEASE) |
458 | if (scan_code & KEY_RELEASE) |
369 | key_released(keybuffer, scan_code ^ KEY_RELEASE); |
459 | key_released(keybuffer, scan_code ^ KEY_RELEASE); |
370 | else |
460 | else |
371 | key_pressed(keybuffer, scan_code); |
461 | key_pressed(keybuffer, scan_code); |
372 | } |
462 | } |
- | 463 | } |
|
373 | return 1; |
464 | return 1; |
374 | } |
465 | } |
375 | 466 | ||
376 | /** |
467 | /** |
377 | * @} |
468 | * @} |
378 | */ |
469 | */ |
379 | 470 | ||
380 | 471 |