Rev 511 | Rev 517 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 511 | Rev 512 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <arch/i8042.h> |
29 | #include <arch/i8042.h> |
30 | #include <arch/i8259.h> |
30 | #include <arch/i8259.h> |
31 | #include <arch/interrupt.h> |
31 | #include <arch/interrupt.h> |
32 | #include <cpu.h> |
32 | #include <cpu.h> |
33 | #include <arch/asm.h> |
33 | #include <arch/asm.h> |
34 | #include <arch.h> |
34 | #include <arch.h> |
35 | #include <print.h> |
35 | #include <print.h> |
36 | #include <synch/spinlock.h> |
36 | #include <synch/spinlock.h> |
37 | #include <typedefs.h> |
37 | #include <typedefs.h> |
38 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
39 | #include <console/console.h> |
39 | #include <console/console.h> |
40 | 40 | ||
41 | /** |
41 | /** |
42 | * i8042 processor driver. |
42 | * i8042 processor driver. |
43 | * It takes care of low-level keyboard functions. |
43 | * It takes care of low-level keyboard functions. |
44 | */ |
44 | */ |
45 | 45 | ||
- | 46 | #define i8042_DATA 0x60 |
|
- | 47 | #define i8042_STATUS 0x64 |
|
- | 48 | ||
- | 49 | /** Keyboard commands. */ |
|
- | 50 | #define KBD_ENABLE 0xf4 |
|
- | 51 | #define KBD_DISABLE 0xf5 |
|
- | 52 | #define KBD_ACK 0xfa |
|
- | 53 | ||
46 | #define SPECIAL '?' |
54 | #define SPECIAL '?' |
47 | #define KEY_RELEASE 0x80 |
55 | #define KEY_RELEASE 0x80 |
48 | 56 | ||
49 | static void key_released(__u8 sc); |
57 | static void key_released(__u8 sc); |
50 | static void key_pressed(__u8 sc); |
58 | static void key_pressed(__u8 sc); |
51 | 59 | ||
52 | #define PRESSED_SHIFT (1<<0) |
60 | #define PRESSED_SHIFT (1<<0) |
53 | #define PRESSED_CAPSLOCK (1<<1) |
61 | #define PRESSED_CAPSLOCK (1<<1) |
54 | #define LOCKED_CAPSLOCK (1<<0) |
62 | #define LOCKED_CAPSLOCK (1<<0) |
55 | 63 | ||
56 | static spinlock_t keylock; /**< keylock protects keyflags and lockflags. */ |
64 | static spinlock_t keylock; /**< keylock protects keyflags and lockflags. */ |
57 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
65 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
58 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
66 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
59 | 67 | ||
60 | static void i8042_suspend(void); |
68 | static void i8042_suspend(void); |
61 | static void i8042_resume(void); |
69 | static void i8042_resume(void); |
62 | 70 | ||
63 | static chardev_t kbrd; |
71 | static chardev_t kbrd; |
64 | static chardev_operations_t ops = { |
72 | static chardev_operations_t ops = { |
65 | .suspend = i8042_suspend, |
73 | .suspend = i8042_suspend, |
66 | .resume = i8042_resume |
74 | .resume = i8042_resume |
67 | }; |
75 | }; |
68 | 76 | ||
69 | /** Primary meaning of scancodes. */ |
77 | /** Primary meaning of scancodes. */ |
70 | static char sc_primary_map[] = { |
78 | static char sc_primary_map[] = { |
71 | SPECIAL, /* 0x00 */ |
79 | SPECIAL, /* 0x00 */ |
72 | SPECIAL, /* 0x01 - Esc */ |
80 | SPECIAL, /* 0x01 - Esc */ |
73 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', |
81 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', |
74 | SPECIAL, /* 0x0e - Backspace */ |
82 | SPECIAL, /* 0x0e - Backspace */ |
75 | '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', |
83 | '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', |
76 | SPECIAL, /* 0x1d - LCtrl */ |
84 | SPECIAL, /* 0x1d - LCtrl */ |
77 | 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', |
85 | 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', |
78 | '`', |
86 | '`', |
79 | SPECIAL, /* 0x2a - LShift */ |
87 | SPECIAL, /* 0x2a - LShift */ |
80 | '\\', |
88 | '\\', |
81 | 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', |
89 | 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', |
82 | SPECIAL, /* 0x36 - RShift */ |
90 | SPECIAL, /* 0x36 - RShift */ |
83 | '*', |
91 | '*', |
84 | SPECIAL, /* 0x38 - LAlt */ |
92 | SPECIAL, /* 0x38 - LAlt */ |
85 | ' ', |
93 | ' ', |
86 | SPECIAL, /* 0x3a - CapsLock */ |
94 | SPECIAL, /* 0x3a - CapsLock */ |
87 | SPECIAL, /* 0x3b - F1 */ |
95 | SPECIAL, /* 0x3b - F1 */ |
88 | SPECIAL, /* 0x3c - F2 */ |
96 | SPECIAL, /* 0x3c - F2 */ |
89 | SPECIAL, /* 0x3d - F3 */ |
97 | SPECIAL, /* 0x3d - F3 */ |
90 | SPECIAL, /* 0x3e - F4 */ |
98 | SPECIAL, /* 0x3e - F4 */ |
91 | SPECIAL, /* 0x3f - F5 */ |
99 | SPECIAL, /* 0x3f - F5 */ |
92 | SPECIAL, /* 0x40 - F6 */ |
100 | SPECIAL, /* 0x40 - F6 */ |
93 | SPECIAL, /* 0x41 - F7 */ |
101 | SPECIAL, /* 0x41 - F7 */ |
94 | SPECIAL, /* 0x42 - F8 */ |
102 | SPECIAL, /* 0x42 - F8 */ |
95 | SPECIAL, /* 0x43 - F9 */ |
103 | SPECIAL, /* 0x43 - F9 */ |
96 | SPECIAL, /* 0x44 - F10 */ |
104 | SPECIAL, /* 0x44 - F10 */ |
97 | SPECIAL, /* 0x45 - NumLock */ |
105 | SPECIAL, /* 0x45 - NumLock */ |
98 | SPECIAL, /* 0x46 - ScrollLock */ |
106 | SPECIAL, /* 0x46 - ScrollLock */ |
99 | '7', '8', '9', '-', |
107 | '7', '8', '9', '-', |
100 | '4', '5', '6', '+', |
108 | '4', '5', '6', '+', |
101 | '1', '2', '3', |
109 | '1', '2', '3', |
102 | '0', '.', |
110 | '0', '.', |
103 | SPECIAL, /* 0x54 - Alt-SysRq */ |
111 | SPECIAL, /* 0x54 - Alt-SysRq */ |
104 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
112 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
105 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
113 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
106 | SPECIAL, /* 0x57 - F11 */ |
114 | SPECIAL, /* 0x57 - F11 */ |
107 | SPECIAL, /* 0x58 - F12 */ |
115 | SPECIAL, /* 0x58 - F12 */ |
108 | SPECIAL, /* 0x59 */ |
116 | SPECIAL, /* 0x59 */ |
109 | SPECIAL, /* 0x5a */ |
117 | SPECIAL, /* 0x5a */ |
110 | SPECIAL, /* 0x5b */ |
118 | SPECIAL, /* 0x5b */ |
111 | SPECIAL, /* 0x5c */ |
119 | SPECIAL, /* 0x5c */ |
112 | SPECIAL, /* 0x5d */ |
120 | SPECIAL, /* 0x5d */ |
113 | SPECIAL, /* 0x5e */ |
121 | SPECIAL, /* 0x5e */ |
114 | SPECIAL, /* 0x5f */ |
122 | SPECIAL, /* 0x5f */ |
115 | SPECIAL, /* 0x60 */ |
123 | SPECIAL, /* 0x60 */ |
116 | SPECIAL, /* 0x61 */ |
124 | SPECIAL, /* 0x61 */ |
117 | SPECIAL, /* 0x62 */ |
125 | SPECIAL, /* 0x62 */ |
118 | SPECIAL, /* 0x63 */ |
126 | SPECIAL, /* 0x63 */ |
119 | SPECIAL, /* 0x64 */ |
127 | SPECIAL, /* 0x64 */ |
120 | SPECIAL, /* 0x65 */ |
128 | SPECIAL, /* 0x65 */ |
121 | SPECIAL, /* 0x66 */ |
129 | SPECIAL, /* 0x66 */ |
122 | SPECIAL, /* 0x67 */ |
130 | SPECIAL, /* 0x67 */ |
123 | SPECIAL, /* 0x68 */ |
131 | SPECIAL, /* 0x68 */ |
124 | SPECIAL, /* 0x69 */ |
132 | SPECIAL, /* 0x69 */ |
125 | SPECIAL, /* 0x6a */ |
133 | SPECIAL, /* 0x6a */ |
126 | SPECIAL, /* 0x6b */ |
134 | SPECIAL, /* 0x6b */ |
127 | SPECIAL, /* 0x6c */ |
135 | SPECIAL, /* 0x6c */ |
128 | SPECIAL, /* 0x6d */ |
136 | SPECIAL, /* 0x6d */ |
129 | SPECIAL, /* 0x6e */ |
137 | SPECIAL, /* 0x6e */ |
130 | SPECIAL, /* 0x6f */ |
138 | SPECIAL, /* 0x6f */ |
131 | SPECIAL, /* 0x70 */ |
139 | SPECIAL, /* 0x70 */ |
132 | SPECIAL, /* 0x71 */ |
140 | SPECIAL, /* 0x71 */ |
133 | SPECIAL, /* 0x72 */ |
141 | SPECIAL, /* 0x72 */ |
134 | SPECIAL, /* 0x73 */ |
142 | SPECIAL, /* 0x73 */ |
135 | SPECIAL, /* 0x74 */ |
143 | SPECIAL, /* 0x74 */ |
136 | SPECIAL, /* 0x75 */ |
144 | SPECIAL, /* 0x75 */ |
137 | SPECIAL, /* 0x76 */ |
145 | SPECIAL, /* 0x76 */ |
138 | SPECIAL, /* 0x77 */ |
146 | SPECIAL, /* 0x77 */ |
139 | SPECIAL, /* 0x78 */ |
147 | SPECIAL, /* 0x78 */ |
140 | SPECIAL, /* 0x79 */ |
148 | SPECIAL, /* 0x79 */ |
141 | SPECIAL, /* 0x7a */ |
149 | SPECIAL, /* 0x7a */ |
142 | SPECIAL, /* 0x7b */ |
150 | SPECIAL, /* 0x7b */ |
143 | SPECIAL, /* 0x7c */ |
151 | SPECIAL, /* 0x7c */ |
144 | SPECIAL, /* 0x7d */ |
152 | SPECIAL, /* 0x7d */ |
145 | SPECIAL, /* 0x7e */ |
153 | SPECIAL, /* 0x7e */ |
146 | SPECIAL, /* 0x7f */ |
154 | SPECIAL, /* 0x7f */ |
147 | }; |
155 | }; |
148 | 156 | ||
149 | /** Secondary meaning of scancodes. */ |
157 | /** Secondary meaning of scancodes. */ |
150 | static char sc_secondary_map[] = { |
158 | static char sc_secondary_map[] = { |
151 | SPECIAL, /* 0x00 */ |
159 | SPECIAL, /* 0x00 */ |
152 | SPECIAL, /* 0x01 - Esc */ |
160 | SPECIAL, /* 0x01 - Esc */ |
153 | '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', |
161 | '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', |
154 | SPECIAL, /* 0x0e - Backspace */ |
162 | SPECIAL, /* 0x0e - Backspace */ |
155 | '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', |
163 | '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', |
156 | SPECIAL, /* 0x1d - LCtrl */ |
164 | SPECIAL, /* 0x1d - LCtrl */ |
157 | 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', |
165 | 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', |
158 | '~', |
166 | '~', |
159 | SPECIAL, /* 0x2a - LShift */ |
167 | SPECIAL, /* 0x2a - LShift */ |
160 | '|', |
168 | '|', |
161 | 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', |
169 | 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', |
162 | SPECIAL, /* 0x36 - RShift */ |
170 | SPECIAL, /* 0x36 - RShift */ |
163 | '*', |
171 | '*', |
164 | SPECIAL, /* 0x38 - LAlt */ |
172 | SPECIAL, /* 0x38 - LAlt */ |
165 | ' ', |
173 | ' ', |
166 | SPECIAL, /* 0x3a - CapsLock */ |
174 | SPECIAL, /* 0x3a - CapsLock */ |
167 | SPECIAL, /* 0x3b - F1 */ |
175 | SPECIAL, /* 0x3b - F1 */ |
168 | SPECIAL, /* 0x3c - F2 */ |
176 | SPECIAL, /* 0x3c - F2 */ |
169 | SPECIAL, /* 0x3d - F3 */ |
177 | SPECIAL, /* 0x3d - F3 */ |
170 | SPECIAL, /* 0x3e - F4 */ |
178 | SPECIAL, /* 0x3e - F4 */ |
171 | SPECIAL, /* 0x3f - F5 */ |
179 | SPECIAL, /* 0x3f - F5 */ |
172 | SPECIAL, /* 0x40 - F6 */ |
180 | SPECIAL, /* 0x40 - F6 */ |
173 | SPECIAL, /* 0x41 - F7 */ |
181 | SPECIAL, /* 0x41 - F7 */ |
174 | SPECIAL, /* 0x42 - F8 */ |
182 | SPECIAL, /* 0x42 - F8 */ |
175 | SPECIAL, /* 0x43 - F9 */ |
183 | SPECIAL, /* 0x43 - F9 */ |
176 | SPECIAL, /* 0x44 - F10 */ |
184 | SPECIAL, /* 0x44 - F10 */ |
177 | SPECIAL, /* 0x45 - NumLock */ |
185 | SPECIAL, /* 0x45 - NumLock */ |
178 | SPECIAL, /* 0x46 - ScrollLock */ |
186 | SPECIAL, /* 0x46 - ScrollLock */ |
179 | '7', '8', '9', '-', |
187 | '7', '8', '9', '-', |
180 | '4', '5', '6', '+', |
188 | '4', '5', '6', '+', |
181 | '1', '2', '3', |
189 | '1', '2', '3', |
182 | '0', '.', |
190 | '0', '.', |
183 | SPECIAL, /* 0x54 - Alt-SysRq */ |
191 | SPECIAL, /* 0x54 - Alt-SysRq */ |
184 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
192 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
185 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
193 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
186 | SPECIAL, /* 0x57 - F11 */ |
194 | SPECIAL, /* 0x57 - F11 */ |
187 | SPECIAL, /* 0x58 - F12 */ |
195 | SPECIAL, /* 0x58 - F12 */ |
188 | SPECIAL, /* 0x59 */ |
196 | SPECIAL, /* 0x59 */ |
189 | SPECIAL, /* 0x5a */ |
197 | SPECIAL, /* 0x5a */ |
190 | SPECIAL, /* 0x5b */ |
198 | SPECIAL, /* 0x5b */ |
191 | SPECIAL, /* 0x5c */ |
199 | SPECIAL, /* 0x5c */ |
192 | SPECIAL, /* 0x5d */ |
200 | SPECIAL, /* 0x5d */ |
193 | SPECIAL, /* 0x5e */ |
201 | SPECIAL, /* 0x5e */ |
194 | SPECIAL, /* 0x5f */ |
202 | SPECIAL, /* 0x5f */ |
195 | SPECIAL, /* 0x60 */ |
203 | SPECIAL, /* 0x60 */ |
196 | SPECIAL, /* 0x61 */ |
204 | SPECIAL, /* 0x61 */ |
197 | SPECIAL, /* 0x62 */ |
205 | SPECIAL, /* 0x62 */ |
198 | SPECIAL, /* 0x63 */ |
206 | SPECIAL, /* 0x63 */ |
199 | SPECIAL, /* 0x64 */ |
207 | SPECIAL, /* 0x64 */ |
200 | SPECIAL, /* 0x65 */ |
208 | SPECIAL, /* 0x65 */ |
201 | SPECIAL, /* 0x66 */ |
209 | SPECIAL, /* 0x66 */ |
202 | SPECIAL, /* 0x67 */ |
210 | SPECIAL, /* 0x67 */ |
203 | SPECIAL, /* 0x68 */ |
211 | SPECIAL, /* 0x68 */ |
204 | SPECIAL, /* 0x69 */ |
212 | SPECIAL, /* 0x69 */ |
205 | SPECIAL, /* 0x6a */ |
213 | SPECIAL, /* 0x6a */ |
206 | SPECIAL, /* 0x6b */ |
214 | SPECIAL, /* 0x6b */ |
207 | SPECIAL, /* 0x6c */ |
215 | SPECIAL, /* 0x6c */ |
208 | SPECIAL, /* 0x6d */ |
216 | SPECIAL, /* 0x6d */ |
209 | SPECIAL, /* 0x6e */ |
217 | SPECIAL, /* 0x6e */ |
210 | SPECIAL, /* 0x6f */ |
218 | SPECIAL, /* 0x6f */ |
211 | SPECIAL, /* 0x70 */ |
219 | SPECIAL, /* 0x70 */ |
212 | SPECIAL, /* 0x71 */ |
220 | SPECIAL, /* 0x71 */ |
213 | SPECIAL, /* 0x72 */ |
221 | SPECIAL, /* 0x72 */ |
214 | SPECIAL, /* 0x73 */ |
222 | SPECIAL, /* 0x73 */ |
215 | SPECIAL, /* 0x74 */ |
223 | SPECIAL, /* 0x74 */ |
216 | SPECIAL, /* 0x75 */ |
224 | SPECIAL, /* 0x75 */ |
217 | SPECIAL, /* 0x76 */ |
225 | SPECIAL, /* 0x76 */ |
218 | SPECIAL, /* 0x77 */ |
226 | SPECIAL, /* 0x77 */ |
219 | SPECIAL, /* 0x78 */ |
227 | SPECIAL, /* 0x78 */ |
220 | SPECIAL, /* 0x79 */ |
228 | SPECIAL, /* 0x79 */ |
221 | SPECIAL, /* 0x7a */ |
229 | SPECIAL, /* 0x7a */ |
222 | SPECIAL, /* 0x7b */ |
230 | SPECIAL, /* 0x7b */ |
223 | SPECIAL, /* 0x7c */ |
231 | SPECIAL, /* 0x7c */ |
224 | SPECIAL, /* 0x7d */ |
232 | SPECIAL, /* 0x7d */ |
225 | SPECIAL, /* 0x7e */ |
233 | SPECIAL, /* 0x7e */ |
226 | SPECIAL, /* 0x7f */ |
234 | SPECIAL, /* 0x7f */ |
227 | }; |
235 | }; |
228 | 236 | ||
229 | /** Initialize i8042. */ |
237 | /** Initialize i8042. */ |
230 | void i8042_init(void) |
238 | void i8042_init(void) |
231 | { |
239 | { |
232 | trap_register(VECTOR_KBD, i8042_interrupt); |
240 | trap_register(VECTOR_KBD, i8042_interrupt); |
- | 241 | trap_virtual_enable_irqs(1<<IRQ_KBD); |
|
233 | spinlock_initialize(&keylock); |
242 | spinlock_initialize(&keylock); |
234 | chardev_initialize(&kbrd, &ops); |
243 | chardev_initialize(&kbrd, &ops); |
235 | stdin = &kbrd; |
244 | stdin = &kbrd; |
236 | } |
245 | } |
237 | 246 | ||
238 | /** Process i8042 interrupt. |
247 | /** Process i8042 interrupt. |
239 | * |
248 | * |
240 | * @param n Interrupt vector. |
249 | * @param n Interrupt vector. |
241 | * @param stack Interrupted stack. |
250 | * @param stack Interrupted stack. |
242 | */ |
251 | */ |
243 | void i8042_interrupt(__u8 n, __native stack[]) |
252 | void i8042_interrupt(__u8 n, __native stack[]) |
244 | { |
253 | { |
245 | __u8 x; |
254 | __u8 x; |
246 | 255 | ||
247 | trap_virtual_eoi(); |
256 | trap_virtual_eoi(); |
248 | x = inb(0x60); |
257 | x = inb(i8042_DATA); |
249 | if (x & KEY_RELEASE) |
258 | if (x & KEY_RELEASE) |
250 | key_released(x ^ KEY_RELEASE); |
259 | key_released(x ^ KEY_RELEASE); |
251 | else |
260 | else |
252 | key_pressed(x); |
261 | key_pressed(x); |
253 | } |
262 | } |
254 | 263 | ||
255 | /** Process release of key. |
264 | /** Process release of key. |
256 | * |
265 | * |
257 | * @param sc Scancode of the key being released. |
266 | * @param sc Scancode of the key being released. |
258 | */ |
267 | */ |
259 | void key_released(__u8 sc) |
268 | void key_released(__u8 sc) |
260 | { |
269 | { |
261 | spinlock_lock(&keylock); |
270 | spinlock_lock(&keylock); |
262 | switch (sc) { |
271 | switch (sc) { |
263 | case SC_LSHIFT: |
272 | case SC_LSHIFT: |
264 | case SC_RSHIFT: |
273 | case SC_RSHIFT: |
265 | keyflags &= ~PRESSED_SHIFT; |
274 | keyflags &= ~PRESSED_SHIFT; |
266 | break; |
275 | break; |
267 | case SC_CAPSLOCK: |
276 | case SC_CAPSLOCK: |
268 | keyflags &= ~PRESSED_CAPSLOCK; |
277 | keyflags &= ~PRESSED_CAPSLOCK; |
269 | if (lockflags & LOCKED_CAPSLOCK) |
278 | if (lockflags & LOCKED_CAPSLOCK) |
270 | lockflags &= ~LOCKED_CAPSLOCK; |
279 | lockflags &= ~LOCKED_CAPSLOCK; |
271 | else |
280 | else |
272 | lockflags |= LOCKED_CAPSLOCK; |
281 | lockflags |= LOCKED_CAPSLOCK; |
273 | break; |
282 | break; |
274 | default: |
283 | default: |
275 | break; |
284 | break; |
276 | } |
285 | } |
277 | spinlock_unlock(&keylock); |
286 | spinlock_unlock(&keylock); |
278 | } |
287 | } |
279 | 288 | ||
280 | /** Process keypress. |
289 | /** Process keypress. |
281 | * |
290 | * |
282 | * @param sc Scancode of the key being pressed. |
291 | * @param sc Scancode of the key being pressed. |
283 | */ |
292 | */ |
284 | void key_pressed(__u8 sc) |
293 | void key_pressed(__u8 sc) |
285 | { |
294 | { |
286 | char *map = sc_primary_map; |
295 | char *map = sc_primary_map; |
287 | char ascii = sc_primary_map[sc]; |
296 | char ascii = sc_primary_map[sc]; |
288 | bool shift, capslock; |
297 | bool shift, capslock; |
289 | bool letter = false; |
298 | bool letter = false; |
290 | 299 | ||
291 | spinlock_lock(&keylock); |
300 | spinlock_lock(&keylock); |
292 | switch (sc) { |
301 | switch (sc) { |
293 | case SC_LSHIFT: |
302 | case SC_LSHIFT: |
294 | case SC_RSHIFT: |
303 | case SC_RSHIFT: |
295 | keyflags |= PRESSED_SHIFT; |
304 | keyflags |= PRESSED_SHIFT; |
296 | break; |
305 | break; |
297 | case SC_CAPSLOCK: |
306 | case SC_CAPSLOCK: |
298 | keyflags |= PRESSED_CAPSLOCK; |
307 | keyflags |= PRESSED_CAPSLOCK; |
299 | break; |
308 | break; |
300 | default: |
309 | default: |
301 | letter = (ascii >= 'a') && (ascii <= 'z'); |
310 | letter = (ascii >= 'a') && (ascii <= 'z'); |
302 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
311 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
303 | shift = keyflags & PRESSED_SHIFT; |
312 | shift = keyflags & PRESSED_SHIFT; |
304 | if (letter && capslock) |
313 | if (letter && capslock) |
305 | shift = !shift; |
314 | shift = !shift; |
306 | if (shift) |
315 | if (shift) |
307 | map = sc_secondary_map; |
316 | map = sc_secondary_map; |
308 | chardev_push_character(&kbrd, map[sc]); |
317 | chardev_push_character(&kbrd, map[sc]); |
309 | break; |
318 | break; |
310 | } |
319 | } |
311 | spinlock_unlock(&keylock); |
320 | spinlock_unlock(&keylock); |
312 | } |
321 | } |
313 | 322 | ||
314 | /* Called from getc(). */ |
323 | /* Called from getc(). */ |
315 | void i8042_resume(void) |
324 | void i8042_resume(void) |
316 | { |
325 | { |
317 | } |
326 | } |
318 | 327 | ||
319 | /* Called from getc(). */ |
328 | /* Called from getc(). */ |
320 | void i8042_suspend(void) |
329 | void i8042_suspend(void) |
321 | { |
330 | { |
322 | } |
331 | } |
323 | 332 |