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