Subversion Repositories HelenOS-historic

Rev

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

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