Subversion Repositories HelenOS-historic

Rev

Rev 534 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 534 Rev 552
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
 
41
 
42
/**
42
/**
43
 * i8042 processor driver.
43
 * i8042 processor driver.
44
 * It takes care of low-level keyboard functions.
44
 * It takes care of low-level keyboard functions.
45
 */
45
 */
46
 
46
 
47
#define i8042_DATA      0x60
47
#define i8042_DATA      0x60
48
#define i8042_STATUS        0x64
48
#define i8042_STATUS        0x64
49
 
49
 
50
/** Keyboard commands. */
50
/** Keyboard commands. */
51
#define KBD_ENABLE  0xf4
51
#define KBD_ENABLE  0xf4
52
#define KBD_DISABLE 0xf5
52
#define KBD_DISABLE 0xf5
53
#define KBD_ACK     0xfa
53
#define KBD_ACK     0xfa
54
 
54
 
55
#define SPECIAL     '?'
55
#define SPECIAL     '?'
56
#define KEY_RELEASE 0x80
56
#define KEY_RELEASE 0x80
57
 
57
 
58
static void key_released(__u8 sc);
58
static void key_released(__u8 sc);
59
static void key_pressed(__u8 sc);
59
static void key_pressed(__u8 sc);
60
 
60
 
61
#define PRESSED_SHIFT       (1<<0)
61
#define PRESSED_SHIFT       (1<<0)
62
#define PRESSED_CAPSLOCK    (1<<1)
62
#define PRESSED_CAPSLOCK    (1<<1)
63
#define LOCKED_CAPSLOCK     (1<<0)
63
#define LOCKED_CAPSLOCK     (1<<0)
64
 
64
 
65
static spinlock_t keylock;      /**< keylock protects keyflags and lockflags. */
65
static spinlock_t keylock;      /**< keylock protects keyflags and lockflags. */
66
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
66
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
67
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
67
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
68
 
68
 
69
static void i8042_suspend(void);
69
static void i8042_suspend(void);
70
static void i8042_resume(void);
70
static void i8042_resume(void);
71
 
71
 
72
static chardev_t kbrd;
72
static chardev_t kbrd;
73
static chardev_operations_t ops = {
73
static chardev_operations_t ops = {
74
    .suspend = i8042_suspend,
74
    .suspend = i8042_suspend,
75
    .resume = i8042_resume
75
    .resume = i8042_resume
76
};
76
};
77
 
77
 
78
/** Primary meaning of scancodes. */
78
/** Primary meaning of scancodes. */
79
static char sc_primary_map[] = {
79
static char sc_primary_map[] = {
80
    SPECIAL, /* 0x00 */
80
    SPECIAL, /* 0x00 */
81
    SPECIAL, /* 0x01 - Esc */
81
    SPECIAL, /* 0x01 - Esc */
82
    '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
82
    '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
83
    SPECIAL, /* 0x0e - Backspace */
83
    SPECIAL, /* 0x0e - Backspace */
84
    '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
84
    '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
85
    SPECIAL, /* 0x1d - LCtrl */
85
    SPECIAL, /* 0x1d - LCtrl */
86
    'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'',
86
    'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'',
87
    '`',
87
    '`',
88
    SPECIAL, /* 0x2a - LShift */
88
    SPECIAL, /* 0x2a - LShift */
89
    '\\',
89
    '\\',
90
    'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
90
    'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
91
    SPECIAL, /* 0x36 - RShift */
91
    SPECIAL, /* 0x36 - RShift */
92
    '*',
92
    '*',
93
    SPECIAL, /* 0x38 - LAlt */
93
    SPECIAL, /* 0x38 - LAlt */
94
    ' ',
94
    ' ',
95
    SPECIAL, /* 0x3a - CapsLock */
95
    SPECIAL, /* 0x3a - CapsLock */
96
    SPECIAL, /* 0x3b - F1 */
96
    SPECIAL, /* 0x3b - F1 */
97
    SPECIAL, /* 0x3c - F2 */
97
    SPECIAL, /* 0x3c - F2 */
98
    SPECIAL, /* 0x3d - F3 */
98
    SPECIAL, /* 0x3d - F3 */
99
    SPECIAL, /* 0x3e - F4 */
99
    SPECIAL, /* 0x3e - F4 */
100
    SPECIAL, /* 0x3f - F5 */
100
    SPECIAL, /* 0x3f - F5 */
101
    SPECIAL, /* 0x40 - F6 */
101
    SPECIAL, /* 0x40 - F6 */
102
    SPECIAL, /* 0x41 - F7 */
102
    SPECIAL, /* 0x41 - F7 */
103
    SPECIAL, /* 0x42 - F8 */
103
    SPECIAL, /* 0x42 - F8 */
104
    SPECIAL, /* 0x43 - F9 */
104
    SPECIAL, /* 0x43 - F9 */
105
    SPECIAL, /* 0x44 - F10 */
105
    SPECIAL, /* 0x44 - F10 */
106
    SPECIAL, /* 0x45 - NumLock */
106
    SPECIAL, /* 0x45 - NumLock */
107
    SPECIAL, /* 0x46 - ScrollLock */
107
    SPECIAL, /* 0x46 - ScrollLock */
108
    '7', '8', '9', '-',
108
    '7', '8', '9', '-',
109
    '4', '5', '6', '+',
109
    '4', '5', '6', '+',
110
    '1', '2', '3',
110
    '1', '2', '3',
111
    '0', '.',
111
    '0', '.',
112
    SPECIAL, /* 0x54 - Alt-SysRq */
112
    SPECIAL, /* 0x54 - Alt-SysRq */
113
    SPECIAL, /* 0x55 - F11/F12/PF1/FN */
113
    SPECIAL, /* 0x55 - F11/F12/PF1/FN */
114
    SPECIAL, /* 0x56 - unlabelled key next to LAlt */
114
    SPECIAL, /* 0x56 - unlabelled key next to LAlt */
115
    SPECIAL, /* 0x57 - F11 */
115
    SPECIAL, /* 0x57 - F11 */
116
    SPECIAL, /* 0x58 - F12 */
116
    SPECIAL, /* 0x58 - F12 */
117
    SPECIAL, /* 0x59 */
117
    SPECIAL, /* 0x59 */
118
    SPECIAL, /* 0x5a */
118
    SPECIAL, /* 0x5a */
119
    SPECIAL, /* 0x5b */
119
    SPECIAL, /* 0x5b */
120
    SPECIAL, /* 0x5c */
120
    SPECIAL, /* 0x5c */
121
    SPECIAL, /* 0x5d */
121
    SPECIAL, /* 0x5d */
122
    SPECIAL, /* 0x5e */
122
    SPECIAL, /* 0x5e */
123
    SPECIAL, /* 0x5f */
123
    SPECIAL, /* 0x5f */
124
    SPECIAL, /* 0x60 */
124
    SPECIAL, /* 0x60 */
125
    SPECIAL, /* 0x61 */
125
    SPECIAL, /* 0x61 */
126
    SPECIAL, /* 0x62 */
126
    SPECIAL, /* 0x62 */
127
    SPECIAL, /* 0x63 */
127
    SPECIAL, /* 0x63 */
128
    SPECIAL, /* 0x64 */
128
    SPECIAL, /* 0x64 */
129
    SPECIAL, /* 0x65 */
129
    SPECIAL, /* 0x65 */
130
    SPECIAL, /* 0x66 */
130
    SPECIAL, /* 0x66 */
131
    SPECIAL, /* 0x67 */
131
    SPECIAL, /* 0x67 */
132
    SPECIAL, /* 0x68 */
132
    SPECIAL, /* 0x68 */
133
    SPECIAL, /* 0x69 */
133
    SPECIAL, /* 0x69 */
134
    SPECIAL, /* 0x6a */
134
    SPECIAL, /* 0x6a */
135
    SPECIAL, /* 0x6b */
135
    SPECIAL, /* 0x6b */
136
    SPECIAL, /* 0x6c */
136
    SPECIAL, /* 0x6c */
137
    SPECIAL, /* 0x6d */
137
    SPECIAL, /* 0x6d */
138
    SPECIAL, /* 0x6e */
138
    SPECIAL, /* 0x6e */
139
    SPECIAL, /* 0x6f */
139
    SPECIAL, /* 0x6f */
140
    SPECIAL, /* 0x70 */
140
    SPECIAL, /* 0x70 */
141
    SPECIAL, /* 0x71 */
141
    SPECIAL, /* 0x71 */
142
    SPECIAL, /* 0x72 */
142
    SPECIAL, /* 0x72 */
143
    SPECIAL, /* 0x73 */
143
    SPECIAL, /* 0x73 */
144
    SPECIAL, /* 0x74 */
144
    SPECIAL, /* 0x74 */
145
    SPECIAL, /* 0x75 */
145
    SPECIAL, /* 0x75 */
146
    SPECIAL, /* 0x76 */
146
    SPECIAL, /* 0x76 */
147
    SPECIAL, /* 0x77 */
147
    SPECIAL, /* 0x77 */
148
    SPECIAL, /* 0x78 */
148
    SPECIAL, /* 0x78 */
149
    SPECIAL, /* 0x79 */
149
    SPECIAL, /* 0x79 */
150
    SPECIAL, /* 0x7a */
150
    SPECIAL, /* 0x7a */
151
    SPECIAL, /* 0x7b */
151
    SPECIAL, /* 0x7b */
152
    SPECIAL, /* 0x7c */
152
    SPECIAL, /* 0x7c */
153
    SPECIAL, /* 0x7d */
153
    SPECIAL, /* 0x7d */
154
    SPECIAL, /* 0x7e */
154
    SPECIAL, /* 0x7e */
155
    SPECIAL, /* 0x7f */
155
    SPECIAL, /* 0x7f */
156
};
156
};
157
 
157
 
158
/** Secondary meaning of scancodes. */
158
/** Secondary meaning of scancodes. */
159
static char sc_secondary_map[] = {
159
static char sc_secondary_map[] = {
160
    SPECIAL, /* 0x00 */
160
    SPECIAL, /* 0x00 */
161
    SPECIAL, /* 0x01 - Esc */
161
    SPECIAL, /* 0x01 - Esc */
162
    '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
162
    '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
163
    SPECIAL, /* 0x0e - Backspace */
163
    SPECIAL, /* 0x0e - Backspace */
164
    '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n',
164
    '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n',
165
    SPECIAL, /* 0x1d - LCtrl */
165
    SPECIAL, /* 0x1d - LCtrl */
166
    'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"',
166
    'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"',
167
    '~',
167
    '~',
168
    SPECIAL, /* 0x2a - LShift */
168
    SPECIAL, /* 0x2a - LShift */
169
    '|',
169
    '|',
170
    'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
170
    'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
171
    SPECIAL, /* 0x36 - RShift */
171
    SPECIAL, /* 0x36 - RShift */
172
    '*',
172
    '*',
173
    SPECIAL, /* 0x38 - LAlt */
173
    SPECIAL, /* 0x38 - LAlt */
174
    ' ',
174
    ' ',
175
    SPECIAL, /* 0x3a - CapsLock */
175
    SPECIAL, /* 0x3a - CapsLock */
176
    SPECIAL, /* 0x3b - F1 */
176
    SPECIAL, /* 0x3b - F1 */
177
    SPECIAL, /* 0x3c - F2 */
177
    SPECIAL, /* 0x3c - F2 */
178
    SPECIAL, /* 0x3d - F3 */
178
    SPECIAL, /* 0x3d - F3 */
179
    SPECIAL, /* 0x3e - F4 */
179
    SPECIAL, /* 0x3e - F4 */
180
    SPECIAL, /* 0x3f - F5 */
180
    SPECIAL, /* 0x3f - F5 */
181
    SPECIAL, /* 0x40 - F6 */
181
    SPECIAL, /* 0x40 - F6 */
182
    SPECIAL, /* 0x41 - F7 */
182
    SPECIAL, /* 0x41 - F7 */
183
    SPECIAL, /* 0x42 - F8 */
183
    SPECIAL, /* 0x42 - F8 */
184
    SPECIAL, /* 0x43 - F9 */
184
    SPECIAL, /* 0x43 - F9 */
185
    SPECIAL, /* 0x44 - F10 */
185
    SPECIAL, /* 0x44 - F10 */
186
    SPECIAL, /* 0x45 - NumLock */
186
    SPECIAL, /* 0x45 - NumLock */
187
    SPECIAL, /* 0x46 - ScrollLock */
187
    SPECIAL, /* 0x46 - ScrollLock */
188
    '7', '8', '9', '-',
188
    '7', '8', '9', '-',
189
    '4', '5', '6', '+',
189
    '4', '5', '6', '+',
190
    '1', '2', '3',
190
    '1', '2', '3',
191
    '0', '.',
191
    '0', '.',
192
    SPECIAL, /* 0x54 - Alt-SysRq */
192
    SPECIAL, /* 0x54 - Alt-SysRq */
193
    SPECIAL, /* 0x55 - F11/F12/PF1/FN */
193
    SPECIAL, /* 0x55 - F11/F12/PF1/FN */
194
    SPECIAL, /* 0x56 - unlabelled key next to LAlt */
194
    SPECIAL, /* 0x56 - unlabelled key next to LAlt */
195
    SPECIAL, /* 0x57 - F11 */
195
    SPECIAL, /* 0x57 - F11 */
196
    SPECIAL, /* 0x58 - F12 */
196
    SPECIAL, /* 0x58 - F12 */
197
    SPECIAL, /* 0x59 */
197
    SPECIAL, /* 0x59 */
198
    SPECIAL, /* 0x5a */
198
    SPECIAL, /* 0x5a */
199
    SPECIAL, /* 0x5b */
199
    SPECIAL, /* 0x5b */
200
    SPECIAL, /* 0x5c */
200
    SPECIAL, /* 0x5c */
201
    SPECIAL, /* 0x5d */
201
    SPECIAL, /* 0x5d */
202
    SPECIAL, /* 0x5e */
202
    SPECIAL, /* 0x5e */
203
    SPECIAL, /* 0x5f */
203
    SPECIAL, /* 0x5f */
204
    SPECIAL, /* 0x60 */
204
    SPECIAL, /* 0x60 */
205
    SPECIAL, /* 0x61 */
205
    SPECIAL, /* 0x61 */
206
    SPECIAL, /* 0x62 */
206
    SPECIAL, /* 0x62 */
207
    SPECIAL, /* 0x63 */
207
    SPECIAL, /* 0x63 */
208
    SPECIAL, /* 0x64 */
208
    SPECIAL, /* 0x64 */
209
    SPECIAL, /* 0x65 */
209
    SPECIAL, /* 0x65 */
210
    SPECIAL, /* 0x66 */
210
    SPECIAL, /* 0x66 */
211
    SPECIAL, /* 0x67 */
211
    SPECIAL, /* 0x67 */
212
    SPECIAL, /* 0x68 */
212
    SPECIAL, /* 0x68 */
213
    SPECIAL, /* 0x69 */
213
    SPECIAL, /* 0x69 */
214
    SPECIAL, /* 0x6a */
214
    SPECIAL, /* 0x6a */
215
    SPECIAL, /* 0x6b */
215
    SPECIAL, /* 0x6b */
216
    SPECIAL, /* 0x6c */
216
    SPECIAL, /* 0x6c */
217
    SPECIAL, /* 0x6d */
217
    SPECIAL, /* 0x6d */
218
    SPECIAL, /* 0x6e */
218
    SPECIAL, /* 0x6e */
219
    SPECIAL, /* 0x6f */
219
    SPECIAL, /* 0x6f */
220
    SPECIAL, /* 0x70 */
220
    SPECIAL, /* 0x70 */
221
    SPECIAL, /* 0x71 */
221
    SPECIAL, /* 0x71 */
222
    SPECIAL, /* 0x72 */
222
    SPECIAL, /* 0x72 */
223
    SPECIAL, /* 0x73 */
223
    SPECIAL, /* 0x73 */
224
    SPECIAL, /* 0x74 */
224
    SPECIAL, /* 0x74 */
225
    SPECIAL, /* 0x75 */
225
    SPECIAL, /* 0x75 */
226
    SPECIAL, /* 0x76 */
226
    SPECIAL, /* 0x76 */
227
    SPECIAL, /* 0x77 */
227
    SPECIAL, /* 0x77 */
228
    SPECIAL, /* 0x78 */
228
    SPECIAL, /* 0x78 */
229
    SPECIAL, /* 0x79 */
229
    SPECIAL, /* 0x79 */
230
    SPECIAL, /* 0x7a */
230
    SPECIAL, /* 0x7a */
231
    SPECIAL, /* 0x7b */
231
    SPECIAL, /* 0x7b */
232
    SPECIAL, /* 0x7c */
232
    SPECIAL, /* 0x7c */
233
    SPECIAL, /* 0x7d */
233
    SPECIAL, /* 0x7d */
234
    SPECIAL, /* 0x7e */
234
    SPECIAL, /* 0x7e */
235
    SPECIAL, /* 0x7f */
235
    SPECIAL, /* 0x7f */
236
};
236
};
237
 
237
 
238
/** Initialize i8042. */
238
/** Initialize i8042. */
239
void i8042_init(void)
239
void i8042_init(void)
240
{
240
{
241
    trap_register(VECTOR_KBD, i8042_interrupt);
241
    trap_register(VECTOR_KBD, i8042_interrupt);
242
    trap_virtual_enable_irqs(1<<IRQ_KBD);
242
    trap_virtual_enable_irqs(1<<IRQ_KBD);
243
    spinlock_initialize(&keylock);
243
    spinlock_initialize(&keylock, "i8042_lock");
244
    chardev_initialize(&kbrd, &ops);
244
    chardev_initialize(&kbrd, &ops);
245
    stdin = &kbrd;
245
    stdin = &kbrd;
246
}
246
}
247
 
247
 
248
/** Process i8042 interrupt.
248
/** Process i8042 interrupt.
249
 *
249
 *
250
 * @param n Interrupt vector.
250
 * @param n Interrupt vector.
251
 * @param stack Interrupted stack.
251
 * @param stack Interrupted stack.
252
 */
252
 */
253
void i8042_interrupt(__u8 n, __native stack[])
253
void i8042_interrupt(__u8 n, __native stack[])
254
{
254
{
255
    __u8 x;
255
    __u8 x;
256
 
256
 
257
    trap_virtual_eoi();
257
    trap_virtual_eoi();
258
    x = inb(i8042_DATA);
258
    x = inb(i8042_DATA);
259
    if (x & KEY_RELEASE)
259
    if (x & KEY_RELEASE)
260
        key_released(x ^ KEY_RELEASE);
260
        key_released(x ^ KEY_RELEASE);
261
    else
261
    else
262
        key_pressed(x);
262
        key_pressed(x);
263
}
263
}
264
 
264
 
265
/** Process release of key.
265
/** Process release of key.
266
 *
266
 *
267
 * @param sc Scancode of the key being released.
267
 * @param sc Scancode of the key being released.
268
 */
268
 */
269
void key_released(__u8 sc)
269
void key_released(__u8 sc)
270
{
270
{
271
    spinlock_lock(&keylock);
271
    spinlock_lock(&keylock);
272
    switch (sc) {
272
    switch (sc) {
273
        case SC_LSHIFT:
273
        case SC_LSHIFT:
274
        case SC_RSHIFT:
274
        case SC_RSHIFT:
275
        keyflags &= ~PRESSED_SHIFT;
275
        keyflags &= ~PRESSED_SHIFT;
276
        break;
276
        break;
277
        case SC_CAPSLOCK:
277
        case SC_CAPSLOCK:
278
        keyflags &= ~PRESSED_CAPSLOCK;
278
        keyflags &= ~PRESSED_CAPSLOCK;
279
        if (lockflags & LOCKED_CAPSLOCK)
279
        if (lockflags & LOCKED_CAPSLOCK)
280
            lockflags &= ~LOCKED_CAPSLOCK;
280
            lockflags &= ~LOCKED_CAPSLOCK;
281
        else
281
        else
282
            lockflags |= LOCKED_CAPSLOCK;
282
            lockflags |= LOCKED_CAPSLOCK;
283
        break;
283
        break;
284
        default:
284
        default:
285
        break;
285
        break;
286
    }
286
    }
287
    spinlock_unlock(&keylock);
287
    spinlock_unlock(&keylock);
288
}
288
}
289
 
289
 
290
/** Process keypress.
290
/** Process keypress.
291
 *
291
 *
292
 * @param sc Scancode of the key being pressed.
292
 * @param sc Scancode of the key being pressed.
293
 */
293
 */
294
void key_pressed(__u8 sc)
294
void key_pressed(__u8 sc)
295
{
295
{
296
    char *map = sc_primary_map;
296
    char *map = sc_primary_map;
297
    char ascii = sc_primary_map[sc];
297
    char ascii = sc_primary_map[sc];
298
    bool shift, capslock;
298
    bool shift, capslock;
299
    bool letter = false;
299
    bool letter = false;
300
 
300
 
301
    spinlock_lock(&keylock);
301
    spinlock_lock(&keylock);
302
    switch (sc) {
302
    switch (sc) {
303
        case SC_LSHIFT:
303
        case SC_LSHIFT:
304
        case SC_RSHIFT:
304
        case SC_RSHIFT:
305
            keyflags |= PRESSED_SHIFT;
305
            keyflags |= PRESSED_SHIFT;
306
        break;
306
        break;
307
        case SC_CAPSLOCK:
307
        case SC_CAPSLOCK:
308
        keyflags |= PRESSED_CAPSLOCK;
308
        keyflags |= PRESSED_CAPSLOCK;
309
        break;
309
        break;
310
        default:
310
        default:
311
            letter = is_lower(ascii);
311
            letter = is_lower(ascii);
312
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
312
        capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
313
        shift = keyflags & PRESSED_SHIFT;
313
        shift = keyflags & PRESSED_SHIFT;
314
        if (letter && capslock)
314
        if (letter && capslock)
315
            shift = !shift;
315
            shift = !shift;
316
        if (shift)
316
        if (shift)
317
            map = sc_secondary_map;
317
            map = sc_secondary_map;
318
        chardev_push_character(&kbrd, map[sc]);
318
        chardev_push_character(&kbrd, map[sc]);
319
        break;
319
        break;
320
    }
320
    }
321
    spinlock_unlock(&keylock);
321
    spinlock_unlock(&keylock);
322
}
322
}
323
 
323
 
324
/* Called from getc(). */
324
/* Called from getc(). */
325
void i8042_resume(void)
325
void i8042_resume(void)
326
{
326
{
327
}
327
}
328
 
328
 
329
/* Called from getc(). */
329
/* Called from getc(). */
330
void i8042_suspend(void)
330
void i8042_suspend(void)
331
{
331
{
332
}
332
}
333
 
333