Rev 878 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 878 | Rev 893 | ||
---|---|---|---|
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 | #include <macros.h> |
40 | #include <macros.h> |
41 | #include <interrupt.h> |
41 | #include <interrupt.h> |
42 | 42 | ||
43 | /** |
43 | /** |
44 | * i8042 processor driver. |
44 | * i8042 processor driver. |
45 | * It takes care of low-level keyboard functions. |
45 | * It takes care of low-level keyboard functions. |
46 | */ |
46 | */ |
47 | 47 | ||
48 | #define i8042_DATA 0x60 |
48 | #define i8042_DATA 0x60 |
49 | #define i8042_STATUS 0x64 |
49 | #define i8042_STATUS 0x64 |
50 | #define i8042_BUFFER_FULL_MASK 0x01 |
50 | #define i8042_BUFFER_FULL_MASK 0x01 |
51 | 51 | ||
52 | - | ||
53 | /** Keyboard commands. */ |
52 | /** Keyboard commands. */ |
54 | #define KBD_ENABLE 0xf4 |
53 | #define KBD_ENABLE 0xf4 |
55 | #define KBD_DISABLE 0xf5 |
54 | #define KBD_DISABLE 0xf5 |
56 | #define KBD_ACK 0xfa |
55 | #define KBD_ACK 0xfa |
57 | 56 | ||
58 | /* |
57 | /* |
59 | 60 Write 8042 Command Byte: next data byte written to port 60h is |
58 | * 60 Write 8042 Command Byte: next data byte written to port 60h is |
60 | placed in 8042 command register.Format: |
59 | * placed in 8042 command register.Format: |
61 | 60 | * |
|
62 | |7|6|5|4|3|2|1|0|8042 Command Byte |
61 | * |7|6|5|4|3|2|1|0|8042 Command Byte |
63 | | | | | | | | `---- 1=enable output register full interrupt |
62 | * | | | | | | | `---- 1=enable output register full interrupt |
64 | | | | | | | `----- should be 0 |
63 | * | | | | | | `----- should be 0 |
65 | | | | | | `------ 1=set status register system, 0=clear |
64 | * | | | | | `------ 1=set status register system, 0=clear |
66 | | | | | `------- 1=override keyboard inhibit, 0=allow inhibit |
65 | * | | | | `------- 1=override keyboard inhibit, 0=allow inhibit |
67 | | | | `-------- disable keyboard I/O by driving clock line low |
66 | * | | | `-------- disable keyboard I/O by driving clock line low |
68 | | | `--------- disable auxiliary device, drives clock line low |
67 | * | | `--------- disable auxiliary device, drives clock line low |
69 | | `---------- IBM scancode translation 0=AT, 1=PC/XT |
68 | * | `---------- IBM scancode translation 0=AT, 1=PC/XT |
70 | `----------- reserved, should be 0 |
69 | * `----------- reserved, should be 0 |
71 | */ |
70 | */ |
72 | 71 | ||
73 | #define i8042_SET_COMMAND 0x60 |
72 | #define i8042_SET_COMMAND 0x60 |
74 | #define i8042_COMMAND 0x49 |
73 | #define i8042_COMMAND 0x49 |
75 | #define i8042_WAIT_MASK 0x02 |
74 | #define i8042_WAIT_MASK 0x02 |
76 | 75 | ||
77 | - | ||
78 | #define SPECIAL '?' |
76 | #define SPECIAL '?' |
79 | #define KEY_RELEASE 0x80 |
77 | #define KEY_RELEASE 0x80 |
80 | 78 | ||
81 | static void key_released(__u8 sc); |
79 | static void key_released(__u8 sc); |
82 | static void key_pressed(__u8 sc); |
80 | static void key_pressed(__u8 sc); |
83 | static char key_read(chardev_t *d); |
81 | static char key_read(chardev_t *d); |
84 | 82 | ||
85 | #define PRESSED_SHIFT (1<<0) |
83 | #define PRESSED_SHIFT (1<<0) |
86 | #define PRESSED_CAPSLOCK (1<<1) |
84 | #define PRESSED_CAPSLOCK (1<<1) |
87 | #define LOCKED_CAPSLOCK (1<<0) |
85 | #define LOCKED_CAPSLOCK (1<<0) |
88 | 86 | ||
89 | #define ACTIVE_READ_BUFF_SIZE 16 /*Must be power of 2*/ |
87 | #define ACTIVE_READ_BUFF_SIZE 16 /*Must be power of 2*/ |
90 | 88 | ||
91 | - | ||
92 | __u8 active_read_buff[ACTIVE_READ_BUFF_SIZE]={0}; |
89 | __u8 active_read_buff[ACTIVE_READ_BUFF_SIZE]={0}; |
93 | 90 | ||
94 | SPINLOCK_INITIALIZE(keylock); /**< keylock protects keyflags and lockflags. */ |
91 | SPINLOCK_INITIALIZE(keylock); /**< keylock protects keyflags and lockflags. */ |
95 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
92 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
96 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
93 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
97 | 94 | ||
98 | static void i8042_suspend(chardev_t *); |
95 | static void i8042_suspend(chardev_t *); |
99 | static void i8042_resume(chardev_t *); |
96 | static void i8042_resume(chardev_t *); |
100 | 97 | ||
101 | static chardev_t kbrd; |
98 | static chardev_t kbrd; |
102 | static chardev_operations_t ops = { |
99 | static chardev_operations_t ops = { |
103 | .suspend = i8042_suspend, |
100 | .suspend = i8042_suspend, |
104 | .resume = i8042_resume, |
101 | .resume = i8042_resume, |
105 | .read = key_read |
102 | .read = key_read |
106 | }; |
103 | }; |
107 | 104 | ||
108 | /** Primary meaning of scancodes. */ |
105 | /** Primary meaning of scancodes. */ |
109 | static char sc_primary_map[] = { |
106 | static char sc_primary_map[] = { |
110 | SPECIAL, /* 0x00 */ |
107 | SPECIAL, /* 0x00 */ |
111 | SPECIAL, /* 0x01 - Esc */ |
108 | SPECIAL, /* 0x01 - Esc */ |
112 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', |
109 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', |
113 | '\b', /* 0x0e - Backspace */ |
110 | '\b', /* 0x0e - Backspace */ |
114 | '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', |
111 | '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', |
115 | SPECIAL, /* 0x1d - LCtrl */ |
112 | SPECIAL, /* 0x1d - LCtrl */ |
116 | 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', |
113 | 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', |
117 | '`', |
114 | '`', |
118 | SPECIAL, /* 0x2a - LShift */ |
115 | SPECIAL, /* 0x2a - LShift */ |
119 | '\\', |
116 | '\\', |
120 | 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', |
117 | 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', |
121 | SPECIAL, /* 0x36 - RShift */ |
118 | SPECIAL, /* 0x36 - RShift */ |
122 | '*', |
119 | '*', |
123 | SPECIAL, /* 0x38 - LAlt */ |
120 | SPECIAL, /* 0x38 - LAlt */ |
124 | ' ', |
121 | ' ', |
125 | SPECIAL, /* 0x3a - CapsLock */ |
122 | SPECIAL, /* 0x3a - CapsLock */ |
126 | SPECIAL, /* 0x3b - F1 */ |
123 | SPECIAL, /* 0x3b - F1 */ |
127 | SPECIAL, /* 0x3c - F2 */ |
124 | SPECIAL, /* 0x3c - F2 */ |
128 | SPECIAL, /* 0x3d - F3 */ |
125 | SPECIAL, /* 0x3d - F3 */ |
129 | SPECIAL, /* 0x3e - F4 */ |
126 | SPECIAL, /* 0x3e - F4 */ |
130 | SPECIAL, /* 0x3f - F5 */ |
127 | SPECIAL, /* 0x3f - F5 */ |
131 | SPECIAL, /* 0x40 - F6 */ |
128 | SPECIAL, /* 0x40 - F6 */ |
132 | SPECIAL, /* 0x41 - F7 */ |
129 | SPECIAL, /* 0x41 - F7 */ |
133 | SPECIAL, /* 0x42 - F8 */ |
130 | SPECIAL, /* 0x42 - F8 */ |
134 | SPECIAL, /* 0x43 - F9 */ |
131 | SPECIAL, /* 0x43 - F9 */ |
135 | SPECIAL, /* 0x44 - F10 */ |
132 | SPECIAL, /* 0x44 - F10 */ |
136 | SPECIAL, /* 0x45 - NumLock */ |
133 | SPECIAL, /* 0x45 - NumLock */ |
137 | SPECIAL, /* 0x46 - ScrollLock */ |
134 | SPECIAL, /* 0x46 - ScrollLock */ |
138 | '7', '8', '9', '-', |
135 | '7', '8', '9', '-', |
139 | '4', '5', '6', '+', |
136 | '4', '5', '6', '+', |
140 | '1', '2', '3', |
137 | '1', '2', '3', |
141 | '0', '.', |
138 | '0', '.', |
142 | SPECIAL, /* 0x54 - Alt-SysRq */ |
139 | SPECIAL, /* 0x54 - Alt-SysRq */ |
143 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
140 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
144 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
141 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
145 | SPECIAL, /* 0x57 - F11 */ |
142 | SPECIAL, /* 0x57 - F11 */ |
146 | SPECIAL, /* 0x58 - F12 */ |
143 | SPECIAL, /* 0x58 - F12 */ |
147 | SPECIAL, /* 0x59 */ |
144 | SPECIAL, /* 0x59 */ |
148 | SPECIAL, /* 0x5a */ |
145 | SPECIAL, /* 0x5a */ |
149 | SPECIAL, /* 0x5b */ |
146 | SPECIAL, /* 0x5b */ |
150 | SPECIAL, /* 0x5c */ |
147 | SPECIAL, /* 0x5c */ |
151 | SPECIAL, /* 0x5d */ |
148 | SPECIAL, /* 0x5d */ |
152 | SPECIAL, /* 0x5e */ |
149 | SPECIAL, /* 0x5e */ |
153 | SPECIAL, /* 0x5f */ |
150 | SPECIAL, /* 0x5f */ |
154 | SPECIAL, /* 0x60 */ |
151 | SPECIAL, /* 0x60 */ |
155 | SPECIAL, /* 0x61 */ |
152 | SPECIAL, /* 0x61 */ |
156 | SPECIAL, /* 0x62 */ |
153 | SPECIAL, /* 0x62 */ |
157 | SPECIAL, /* 0x63 */ |
154 | SPECIAL, /* 0x63 */ |
158 | SPECIAL, /* 0x64 */ |
155 | SPECIAL, /* 0x64 */ |
159 | SPECIAL, /* 0x65 */ |
156 | SPECIAL, /* 0x65 */ |
160 | SPECIAL, /* 0x66 */ |
157 | SPECIAL, /* 0x66 */ |
161 | SPECIAL, /* 0x67 */ |
158 | SPECIAL, /* 0x67 */ |
162 | SPECIAL, /* 0x68 */ |
159 | SPECIAL, /* 0x68 */ |
163 | SPECIAL, /* 0x69 */ |
160 | SPECIAL, /* 0x69 */ |
164 | SPECIAL, /* 0x6a */ |
161 | SPECIAL, /* 0x6a */ |
165 | SPECIAL, /* 0x6b */ |
162 | SPECIAL, /* 0x6b */ |
166 | SPECIAL, /* 0x6c */ |
163 | SPECIAL, /* 0x6c */ |
167 | SPECIAL, /* 0x6d */ |
164 | SPECIAL, /* 0x6d */ |
168 | SPECIAL, /* 0x6e */ |
165 | SPECIAL, /* 0x6e */ |
169 | SPECIAL, /* 0x6f */ |
166 | SPECIAL, /* 0x6f */ |
170 | SPECIAL, /* 0x70 */ |
167 | SPECIAL, /* 0x70 */ |
171 | SPECIAL, /* 0x71 */ |
168 | SPECIAL, /* 0x71 */ |
172 | SPECIAL, /* 0x72 */ |
169 | SPECIAL, /* 0x72 */ |
173 | SPECIAL, /* 0x73 */ |
170 | SPECIAL, /* 0x73 */ |
174 | SPECIAL, /* 0x74 */ |
171 | SPECIAL, /* 0x74 */ |
175 | SPECIAL, /* 0x75 */ |
172 | SPECIAL, /* 0x75 */ |
176 | SPECIAL, /* 0x76 */ |
173 | SPECIAL, /* 0x76 */ |
177 | SPECIAL, /* 0x77 */ |
174 | SPECIAL, /* 0x77 */ |
178 | SPECIAL, /* 0x78 */ |
175 | SPECIAL, /* 0x78 */ |
179 | SPECIAL, /* 0x79 */ |
176 | SPECIAL, /* 0x79 */ |
180 | SPECIAL, /* 0x7a */ |
177 | SPECIAL, /* 0x7a */ |
181 | SPECIAL, /* 0x7b */ |
178 | SPECIAL, /* 0x7b */ |
182 | SPECIAL, /* 0x7c */ |
179 | SPECIAL, /* 0x7c */ |
183 | SPECIAL, /* 0x7d */ |
180 | SPECIAL, /* 0x7d */ |
184 | SPECIAL, /* 0x7e */ |
181 | SPECIAL, /* 0x7e */ |
185 | SPECIAL, /* 0x7f */ |
182 | SPECIAL, /* 0x7f */ |
186 | }; |
183 | }; |
187 | 184 | ||
188 | /** Secondary meaning of scancodes. */ |
185 | /** Secondary meaning of scancodes. */ |
189 | static char sc_secondary_map[] = { |
186 | static char sc_secondary_map[] = { |
190 | SPECIAL, /* 0x00 */ |
187 | SPECIAL, /* 0x00 */ |
191 | SPECIAL, /* 0x01 - Esc */ |
188 | SPECIAL, /* 0x01 - Esc */ |
192 | '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', |
189 | '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', |
193 | SPECIAL, /* 0x0e - Backspace */ |
190 | SPECIAL, /* 0x0e - Backspace */ |
194 | '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', |
191 | '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', |
195 | SPECIAL, /* 0x1d - LCtrl */ |
192 | SPECIAL, /* 0x1d - LCtrl */ |
196 | 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', |
193 | 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', |
197 | '~', |
194 | '~', |
198 | SPECIAL, /* 0x2a - LShift */ |
195 | SPECIAL, /* 0x2a - LShift */ |
199 | '|', |
196 | '|', |
200 | 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', |
197 | 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', |
201 | SPECIAL, /* 0x36 - RShift */ |
198 | SPECIAL, /* 0x36 - RShift */ |
202 | '*', |
199 | '*', |
203 | SPECIAL, /* 0x38 - LAlt */ |
200 | SPECIAL, /* 0x38 - LAlt */ |
204 | ' ', |
201 | ' ', |
205 | SPECIAL, /* 0x3a - CapsLock */ |
202 | SPECIAL, /* 0x3a - CapsLock */ |
206 | SPECIAL, /* 0x3b - F1 */ |
203 | SPECIAL, /* 0x3b - F1 */ |
207 | SPECIAL, /* 0x3c - F2 */ |
204 | SPECIAL, /* 0x3c - F2 */ |
208 | SPECIAL, /* 0x3d - F3 */ |
205 | SPECIAL, /* 0x3d - F3 */ |
209 | SPECIAL, /* 0x3e - F4 */ |
206 | SPECIAL, /* 0x3e - F4 */ |
210 | SPECIAL, /* 0x3f - F5 */ |
207 | SPECIAL, /* 0x3f - F5 */ |
211 | SPECIAL, /* 0x40 - F6 */ |
208 | SPECIAL, /* 0x40 - F6 */ |
212 | SPECIAL, /* 0x41 - F7 */ |
209 | SPECIAL, /* 0x41 - F7 */ |
213 | SPECIAL, /* 0x42 - F8 */ |
210 | SPECIAL, /* 0x42 - F8 */ |
214 | SPECIAL, /* 0x43 - F9 */ |
211 | SPECIAL, /* 0x43 - F9 */ |
215 | SPECIAL, /* 0x44 - F10 */ |
212 | SPECIAL, /* 0x44 - F10 */ |
216 | SPECIAL, /* 0x45 - NumLock */ |
213 | SPECIAL, /* 0x45 - NumLock */ |
217 | SPECIAL, /* 0x46 - ScrollLock */ |
214 | SPECIAL, /* 0x46 - ScrollLock */ |
218 | '7', '8', '9', '-', |
215 | '7', '8', '9', '-', |
219 | '4', '5', '6', '+', |
216 | '4', '5', '6', '+', |
220 | '1', '2', '3', |
217 | '1', '2', '3', |
221 | '0', '.', |
218 | '0', '.', |
222 | SPECIAL, /* 0x54 - Alt-SysRq */ |
219 | SPECIAL, /* 0x54 - Alt-SysRq */ |
223 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
220 | SPECIAL, /* 0x55 - F11/F12/PF1/FN */ |
224 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
221 | SPECIAL, /* 0x56 - unlabelled key next to LAlt */ |
225 | SPECIAL, /* 0x57 - F11 */ |
222 | SPECIAL, /* 0x57 - F11 */ |
226 | SPECIAL, /* 0x58 - F12 */ |
223 | SPECIAL, /* 0x58 - F12 */ |
227 | SPECIAL, /* 0x59 */ |
224 | SPECIAL, /* 0x59 */ |
228 | SPECIAL, /* 0x5a */ |
225 | SPECIAL, /* 0x5a */ |
229 | SPECIAL, /* 0x5b */ |
226 | SPECIAL, /* 0x5b */ |
230 | SPECIAL, /* 0x5c */ |
227 | SPECIAL, /* 0x5c */ |
231 | SPECIAL, /* 0x5d */ |
228 | SPECIAL, /* 0x5d */ |
232 | SPECIAL, /* 0x5e */ |
229 | SPECIAL, /* 0x5e */ |
233 | SPECIAL, /* 0x5f */ |
230 | SPECIAL, /* 0x5f */ |
234 | SPECIAL, /* 0x60 */ |
231 | SPECIAL, /* 0x60 */ |
235 | SPECIAL, /* 0x61 */ |
232 | SPECIAL, /* 0x61 */ |
236 | SPECIAL, /* 0x62 */ |
233 | SPECIAL, /* 0x62 */ |
237 | SPECIAL, /* 0x63 */ |
234 | SPECIAL, /* 0x63 */ |
238 | SPECIAL, /* 0x64 */ |
235 | SPECIAL, /* 0x64 */ |
239 | SPECIAL, /* 0x65 */ |
236 | SPECIAL, /* 0x65 */ |
240 | SPECIAL, /* 0x66 */ |
237 | SPECIAL, /* 0x66 */ |
241 | SPECIAL, /* 0x67 */ |
238 | SPECIAL, /* 0x67 */ |
242 | SPECIAL, /* 0x68 */ |
239 | SPECIAL, /* 0x68 */ |
243 | SPECIAL, /* 0x69 */ |
240 | SPECIAL, /* 0x69 */ |
244 | SPECIAL, /* 0x6a */ |
241 | SPECIAL, /* 0x6a */ |
245 | SPECIAL, /* 0x6b */ |
242 | SPECIAL, /* 0x6b */ |
246 | SPECIAL, /* 0x6c */ |
243 | SPECIAL, /* 0x6c */ |
247 | SPECIAL, /* 0x6d */ |
244 | SPECIAL, /* 0x6d */ |
248 | SPECIAL, /* 0x6e */ |
245 | SPECIAL, /* 0x6e */ |
249 | SPECIAL, /* 0x6f */ |
246 | SPECIAL, /* 0x6f */ |
250 | SPECIAL, /* 0x70 */ |
247 | SPECIAL, /* 0x70 */ |
251 | SPECIAL, /* 0x71 */ |
248 | SPECIAL, /* 0x71 */ |
252 | SPECIAL, /* 0x72 */ |
249 | SPECIAL, /* 0x72 */ |
253 | SPECIAL, /* 0x73 */ |
250 | SPECIAL, /* 0x73 */ |
254 | SPECIAL, /* 0x74 */ |
251 | SPECIAL, /* 0x74 */ |
255 | SPECIAL, /* 0x75 */ |
252 | SPECIAL, /* 0x75 */ |
256 | SPECIAL, /* 0x76 */ |
253 | SPECIAL, /* 0x76 */ |
257 | SPECIAL, /* 0x77 */ |
254 | SPECIAL, /* 0x77 */ |
258 | SPECIAL, /* 0x78 */ |
255 | SPECIAL, /* 0x78 */ |
259 | SPECIAL, /* 0x79 */ |
256 | SPECIAL, /* 0x79 */ |
260 | SPECIAL, /* 0x7a */ |
257 | SPECIAL, /* 0x7a */ |
261 | SPECIAL, /* 0x7b */ |
258 | SPECIAL, /* 0x7b */ |
262 | SPECIAL, /* 0x7c */ |
259 | SPECIAL, /* 0x7c */ |
263 | SPECIAL, /* 0x7d */ |
260 | SPECIAL, /* 0x7d */ |
264 | SPECIAL, /* 0x7e */ |
261 | SPECIAL, /* 0x7e */ |
265 | SPECIAL, /* 0x7f */ |
262 | SPECIAL, /* 0x7f */ |
266 | }; |
263 | }; |
267 | 264 | ||
268 | static void i8042_interrupt(int n, void *stack); |
265 | static void i8042_interrupt(int n, void *stack); |
269 | 266 | ||
270 | /** Initialize i8042. */ |
267 | /** Initialize i8042. */ |
271 | void i8042_init(void) |
268 | void i8042_init(void) |
272 | { |
269 | { |
273 | exc_register(VECTOR_KBD, "i8042_interrupt", i8042_interrupt); |
270 | exc_register(VECTOR_KBD, "i8042_interrupt", i8042_interrupt); |
274 | while (inb(i8042_STATUS)&i8042_WAIT_MASK); /*Wait*/ |
271 | while (inb(i8042_STATUS)&i8042_WAIT_MASK) { |
- | 272 | /* wait */ |
|
- | 273 | } |
|
275 | outb(i8042_STATUS,i8042_SET_COMMAND); |
274 | outb(i8042_STATUS,i8042_SET_COMMAND); |
276 | while (inb(i8042_STATUS)&i8042_WAIT_MASK); /*Wait*/ |
275 | while (inb(i8042_STATUS)&i8042_WAIT_MASK) { |
- | 276 | /* wait */ |
|
- | 277 | } |
|
277 | outb(i8042_DATA,i8042_COMMAND); |
278 | outb(i8042_DATA,i8042_COMMAND); |
278 | 279 | ||
279 | trap_virtual_enable_irqs(1<<IRQ_KBD); |
280 | trap_virtual_enable_irqs(1<<IRQ_KBD); |
280 | chardev_initialize("i8042_kbd", &kbrd, &ops); |
281 | chardev_initialize("i8042_kbd", &kbrd, &ops); |
281 | stdin = &kbrd; |
282 | stdin = &kbrd; |
282 | } |
283 | } |
283 | 284 | ||
284 | /** Process i8042 interrupt. |
285 | /** Process i8042 interrupt. |
285 | * |
286 | * |
286 | * @param n Interrupt vector. |
287 | * @param n Interrupt vector. |
287 | * @param stack Interrupted stack. |
288 | * @param stack Interrupted stack. |
288 | */ |
289 | */ |
289 | void i8042_interrupt(int n, void *stack) |
290 | void i8042_interrupt(int n, void *stack) |
290 | { |
291 | { |
291 | __u8 x; |
292 | __u8 x; |
292 | 293 | ||
293 | trap_virtual_eoi(); |
294 | trap_virtual_eoi(); |
294 | x = inb(i8042_DATA); |
295 | x = inb(i8042_DATA); |
295 | if (x & KEY_RELEASE) |
296 | if (x & KEY_RELEASE) |
296 | key_released(x ^ KEY_RELEASE); |
297 | key_released(x ^ KEY_RELEASE); |
297 | else |
298 | else |
298 | key_pressed(x); |
299 | key_pressed(x); |
299 | } |
300 | } |
300 | 301 | ||
301 | /** Process release of key. |
302 | /** Process release of key. |
302 | * |
303 | * |
303 | * @param sc Scancode of the key being released. |
304 | * @param sc Scancode of the key being released. |
304 | */ |
305 | */ |
305 | void key_released(__u8 sc) |
306 | void key_released(__u8 sc) |
306 | { |
307 | { |
307 | spinlock_lock(&keylock); |
308 | spinlock_lock(&keylock); |
308 | switch (sc) { |
309 | switch (sc) { |
309 | case SC_LSHIFT: |
310 | case SC_LSHIFT: |
310 | case SC_RSHIFT: |
311 | case SC_RSHIFT: |
311 | keyflags &= ~PRESSED_SHIFT; |
312 | keyflags &= ~PRESSED_SHIFT; |
312 | break; |
313 | break; |
313 | case SC_CAPSLOCK: |
314 | case SC_CAPSLOCK: |
314 | keyflags &= ~PRESSED_CAPSLOCK; |
315 | keyflags &= ~PRESSED_CAPSLOCK; |
315 | if (lockflags & LOCKED_CAPSLOCK) |
316 | if (lockflags & LOCKED_CAPSLOCK) |
316 | lockflags &= ~LOCKED_CAPSLOCK; |
317 | lockflags &= ~LOCKED_CAPSLOCK; |
317 | else |
318 | else |
318 | lockflags |= LOCKED_CAPSLOCK; |
319 | lockflags |= LOCKED_CAPSLOCK; |
319 | break; |
320 | break; |
320 | default: |
321 | default: |
321 | break; |
322 | break; |
322 | } |
323 | } |
323 | spinlock_unlock(&keylock); |
324 | spinlock_unlock(&keylock); |
324 | } |
325 | } |
325 | 326 | ||
326 | /** Process keypress. |
327 | /** Process keypress. |
327 | * |
328 | * |
328 | * @param sc Scancode of the key being pressed. |
329 | * @param sc Scancode of the key being pressed. |
329 | */ |
330 | */ |
330 | void key_pressed(__u8 sc) |
331 | void key_pressed(__u8 sc) |
331 | { |
332 | { |
332 | char *map = sc_primary_map; |
333 | char *map = sc_primary_map; |
333 | char ascii = sc_primary_map[sc]; |
334 | char ascii = sc_primary_map[sc]; |
334 | bool shift, capslock; |
335 | bool shift, capslock; |
335 | bool letter = false; |
336 | bool letter = false; |
336 | 337 | ||
337 | spinlock_lock(&keylock); |
338 | spinlock_lock(&keylock); |
338 | switch (sc) { |
339 | switch (sc) { |
339 | case SC_LSHIFT: |
340 | case SC_LSHIFT: |
340 | case SC_RSHIFT: |
341 | case SC_RSHIFT: |
341 | keyflags |= PRESSED_SHIFT; |
342 | keyflags |= PRESSED_SHIFT; |
342 | break; |
343 | break; |
343 | case SC_CAPSLOCK: |
344 | case SC_CAPSLOCK: |
344 | keyflags |= PRESSED_CAPSLOCK; |
345 | keyflags |= PRESSED_CAPSLOCK; |
345 | break; |
346 | break; |
346 | case SC_SPEC_ESCAPE: |
347 | case SC_SPEC_ESCAPE: |
347 | break; |
348 | break; |
348 | case SC_LEFTARR: |
349 | case SC_LEFTARR: |
349 | chardev_push_character(&kbrd, 0x1b); |
350 | chardev_push_character(&kbrd, 0x1b); |
350 | chardev_push_character(&kbrd, 0x5b); |
351 | chardev_push_character(&kbrd, 0x5b); |
351 | chardev_push_character(&kbrd, 0x44); |
352 | chardev_push_character(&kbrd, 0x44); |
352 | break; |
353 | break; |
353 | case SC_RIGHTARR: |
354 | case SC_RIGHTARR: |
354 | chardev_push_character(&kbrd, 0x1b); |
355 | chardev_push_character(&kbrd, 0x1b); |
355 | chardev_push_character(&kbrd, 0x5b); |
356 | chardev_push_character(&kbrd, 0x5b); |
356 | chardev_push_character(&kbrd, 0x43); |
357 | chardev_push_character(&kbrd, 0x43); |
357 | break; |
358 | break; |
358 | case SC_UPARR: |
359 | case SC_UPARR: |
359 | chardev_push_character(&kbrd, 0x1b); |
360 | chardev_push_character(&kbrd, 0x1b); |
360 | chardev_push_character(&kbrd, 0x5b); |
361 | chardev_push_character(&kbrd, 0x5b); |
361 | chardev_push_character(&kbrd, 0x41); |
362 | chardev_push_character(&kbrd, 0x41); |
362 | break; |
363 | break; |
363 | case SC_DOWNARR: |
364 | case SC_DOWNARR: |
364 | chardev_push_character(&kbrd, 0x1b); |
365 | chardev_push_character(&kbrd, 0x1b); |
365 | chardev_push_character(&kbrd, 0x5b); |
366 | chardev_push_character(&kbrd, 0x5b); |
366 | chardev_push_character(&kbrd, 0x42); |
367 | chardev_push_character(&kbrd, 0x42); |
367 | break; |
368 | break; |
368 | case SC_HOME: |
369 | case SC_HOME: |
369 | chardev_push_character(&kbrd, 0x1b); |
370 | chardev_push_character(&kbrd, 0x1b); |
370 | chardev_push_character(&kbrd, 0x4f); |
371 | chardev_push_character(&kbrd, 0x4f); |
371 | chardev_push_character(&kbrd, 0x48); |
372 | chardev_push_character(&kbrd, 0x48); |
372 | break; |
373 | break; |
373 | case SC_END: |
374 | case SC_END: |
374 | chardev_push_character(&kbrd, 0x1b); |
375 | chardev_push_character(&kbrd, 0x1b); |
375 | chardev_push_character(&kbrd, 0x4f); |
376 | chardev_push_character(&kbrd, 0x4f); |
376 | chardev_push_character(&kbrd, 0x46); |
377 | chardev_push_character(&kbrd, 0x46); |
377 | break; |
378 | break; |
378 | case SC_DELETE: |
379 | case SC_DELETE: |
379 | chardev_push_character(&kbrd, 0x1b); |
380 | chardev_push_character(&kbrd, 0x1b); |
380 | chardev_push_character(&kbrd, 0x5b); |
381 | chardev_push_character(&kbrd, 0x5b); |
381 | chardev_push_character(&kbrd, 0x33); |
382 | chardev_push_character(&kbrd, 0x33); |
382 | chardev_push_character(&kbrd, 0x7e); |
383 | chardev_push_character(&kbrd, 0x7e); |
383 | break; |
384 | break; |
384 | default: |
385 | default: |
385 | letter = is_lower(ascii); |
386 | letter = is_lower(ascii); |
386 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
387 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
387 | shift = keyflags & PRESSED_SHIFT; |
388 | shift = keyflags & PRESSED_SHIFT; |
388 | if (letter && capslock) |
389 | if (letter && capslock) |
389 | shift = !shift; |
390 | shift = !shift; |
390 | if (shift) |
391 | if (shift) |
391 | map = sc_secondary_map; |
392 | map = sc_secondary_map; |
392 | chardev_push_character(&kbrd, map[sc]); |
393 | chardev_push_character(&kbrd, map[sc]); |
393 | break; |
394 | break; |
394 | } |
395 | } |
395 | spinlock_unlock(&keylock); |
396 | spinlock_unlock(&keylock); |
396 | } |
397 | } |
397 | 398 | ||
398 | /* Called from getc(). */ |
399 | /* Called from getc(). */ |
399 | void i8042_resume(chardev_t *d) |
400 | void i8042_resume(chardev_t *d) |
400 | { |
401 | { |
401 | } |
402 | } |
402 | 403 | ||
403 | /* Called from getc(). */ |
404 | /* Called from getc(). */ |
404 | void i8042_suspend(chardev_t *d) |
405 | void i8042_suspend(chardev_t *d) |
405 | { |
406 | { |
406 | } |
407 | } |
407 | 408 | ||
408 | - | ||
409 | static __u8 active_read_buff_read(void) |
409 | static __u8 active_read_buff_read(void) |
410 | { |
410 | { |
411 | static int i=0; |
411 | static int i=0; |
412 | i&=(ACTIVE_READ_BUFF_SIZE-1); |
412 | i&=(ACTIVE_READ_BUFF_SIZE-1); |
413 | if(!active_read_buff[i]) |
413 | if(!active_read_buff[i]) |
414 | { |
414 | { |
415 | return 0; |
415 | return 0; |
416 | } |
416 | } |
417 | return active_read_buff[i++]; |
417 | return active_read_buff[i++]; |
418 | } |
418 | } |
419 | 419 | ||
420 | static void active_read_buff_write(__u8 ch) |
420 | static void active_read_buff_write(__u8 ch) |
421 | { |
421 | { |
422 | static int i=0; |
422 | static int i=0; |
423 | active_read_buff[i]=ch; |
423 | active_read_buff[i]=ch; |
424 | i++; |
424 | i++; |
425 | i&=(ACTIVE_READ_BUFF_SIZE-1); |
425 | i&=(ACTIVE_READ_BUFF_SIZE-1); |
426 | active_read_buff[i]=0; |
426 | active_read_buff[i]=0; |
427 | } |
427 | } |
428 | 428 | ||
429 | 429 | ||
430 | static void active_readed_key_pressed(__u8 sc) |
430 | static void active_read_key_pressed(__u8 sc) |
431 | { |
431 | { |
432 | char *map = sc_primary_map; |
432 | char *map = sc_primary_map; |
433 | char ascii = sc_primary_map[sc]; |
433 | char ascii = sc_primary_map[sc]; |
434 | bool shift, capslock; |
434 | bool shift, capslock; |
435 | bool letter = false; |
435 | bool letter = false; |
436 | 436 | ||
437 | /*spinlock_lock(&keylock);*/ |
437 | /*spinlock_lock(&keylock);*/ |
438 | switch (sc) { |
438 | switch (sc) { |
439 | case SC_LSHIFT: |
439 | case SC_LSHIFT: |
440 | case SC_RSHIFT: |
440 | case SC_RSHIFT: |
441 | keyflags |= PRESSED_SHIFT; |
441 | keyflags |= PRESSED_SHIFT; |
442 | break; |
442 | break; |
443 | case SC_CAPSLOCK: |
443 | case SC_CAPSLOCK: |
444 | keyflags |= PRESSED_CAPSLOCK; |
444 | keyflags |= PRESSED_CAPSLOCK; |
445 | break; |
445 | break; |
446 | case SC_SPEC_ESCAPE: |
446 | case SC_SPEC_ESCAPE: |
447 | break; |
447 | break; |
448 | case SC_LEFTARR: |
448 | case SC_LEFTARR: |
449 | active_read_buff_write(0x1b); |
449 | active_read_buff_write(0x1b); |
450 | active_read_buff_write(0x5b); |
450 | active_read_buff_write(0x5b); |
451 | active_read_buff_write(0x44); |
451 | active_read_buff_write(0x44); |
452 | break; |
452 | break; |
453 | case SC_RIGHTARR: |
453 | case SC_RIGHTARR: |
454 | active_read_buff_write(0x1b); |
454 | active_read_buff_write(0x1b); |
455 | active_read_buff_write(0x5b); |
455 | active_read_buff_write(0x5b); |
456 | active_read_buff_write(0x43); |
456 | active_read_buff_write(0x43); |
457 | break; |
457 | break; |
458 | case SC_UPARR: |
458 | case SC_UPARR: |
459 | active_read_buff_write(0x1b); |
459 | active_read_buff_write(0x1b); |
460 | active_read_buff_write(0x5b); |
460 | active_read_buff_write(0x5b); |
461 | active_read_buff_write(0x41); |
461 | active_read_buff_write(0x41); |
462 | break; |
462 | break; |
463 | case SC_DOWNARR: |
463 | case SC_DOWNARR: |
464 | active_read_buff_write(0x1b); |
464 | active_read_buff_write(0x1b); |
465 | active_read_buff_write(0x5b); |
465 | active_read_buff_write(0x5b); |
466 | active_read_buff_write(0x42); |
466 | active_read_buff_write(0x42); |
467 | break; |
467 | break; |
468 | case SC_HOME: |
468 | case SC_HOME: |
469 | active_read_buff_write(0x1b); |
469 | active_read_buff_write(0x1b); |
470 | active_read_buff_write(0x4f); |
470 | active_read_buff_write(0x4f); |
471 | active_read_buff_write(0x48); |
471 | active_read_buff_write(0x48); |
472 | break; |
472 | break; |
473 | case SC_END: |
473 | case SC_END: |
474 | active_read_buff_write(0x1b); |
474 | active_read_buff_write(0x1b); |
475 | active_read_buff_write(0x4f); |
475 | active_read_buff_write(0x4f); |
476 | active_read_buff_write(0x46); |
476 | active_read_buff_write(0x46); |
477 | break; |
477 | break; |
478 | case SC_DELETE: |
478 | case SC_DELETE: |
479 | active_read_buff_write(0x1b); |
479 | active_read_buff_write(0x1b); |
480 | active_read_buff_write(0x5b); |
480 | active_read_buff_write(0x5b); |
481 | active_read_buff_write(0x33); |
481 | active_read_buff_write(0x33); |
482 | active_read_buff_write(0x7e); |
482 | active_read_buff_write(0x7e); |
483 | break; |
483 | break; |
484 | default: |
484 | default: |
485 | letter = is_lower(ascii); |
485 | letter = is_lower(ascii); |
486 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
486 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
487 | shift = keyflags & PRESSED_SHIFT; |
487 | shift = keyflags & PRESSED_SHIFT; |
488 | if (letter && capslock) |
488 | if (letter && capslock) |
489 | shift = !shift; |
489 | shift = !shift; |
490 | if (shift) |
490 | if (shift) |
491 | map = sc_secondary_map; |
491 | map = sc_secondary_map; |
492 | active_read_buff_write(map[sc]); |
492 | active_read_buff_write(map[sc]); |
493 | break; |
493 | break; |
494 | } |
494 | } |
495 | /*spinlock_unlock(&keylock);*/ |
495 | /*spinlock_unlock(&keylock);*/ |
496 | 496 | ||
497 | } |
497 | } |
498 | 498 | ||
499 | - | ||
500 | static char key_read(chardev_t *d) |
499 | static char key_read(chardev_t *d) |
501 | { |
500 | { |
502 | char ch; |
501 | char ch; |
503 | 502 | ||
504 | - | ||
505 | while(!(ch=active_read_buff_read())) |
503 | while(!(ch=active_read_buff_read())) |
506 | { |
504 | { |
507 | __u8 x; |
505 | __u8 x; |
508 | while (!((x=inb(i8042_STATUS))&i8042_BUFFER_FULL_MASK)); |
506 | while (!((x=inb(i8042_STATUS))&i8042_BUFFER_FULL_MASK)); |
509 | x = inb(i8042_DATA); |
507 | x = inb(i8042_DATA); |
510 | if (x & KEY_RELEASE) |
508 | if (x & KEY_RELEASE) |
511 | key_released(x ^ KEY_RELEASE); |
509 | key_released(x ^ KEY_RELEASE); |
512 | else |
510 | else |
513 | active_readed_key_pressed(x); |
511 | active_read_key_pressed(x); |
514 | } |
512 | } |
515 | return ch; |
513 | return ch; |
516 | } |
514 | } |
517 | - | ||
518 | - | ||
519 | 515 |