This source file includes following definitions.
- kdb_get_kbd_char
- kdb_kbd_cleanup_state
1
2
3
4
5
6
7
8
9
10
11 #include <linux/kdb.h>
12 #include <linux/keyboard.h>
13 #include <linux/ctype.h>
14 #include <linux/module.h>
15 #include <linux/io.h>
16
17
18
19 #define KBD_STATUS_REG 0x64
20 #define KBD_DATA_REG 0x60
21
22
23
24 #define KBD_STAT_OBF 0x01
25 #define KBD_STAT_MOUSE_OBF 0x20
26
27 static int kbd_exists;
28 static int kbd_last_ret;
29
30
31
32
33
34
35 int kdb_get_kbd_char(void)
36 {
37 int scancode, scanstatus;
38 static int shift_lock;
39 static int shift_key;
40 static int ctrl_key;
41 u_short keychar;
42
43 if (KDB_FLAG(NO_I8042) || KDB_FLAG(NO_VT_CONSOLE) ||
44 (inb(KBD_STATUS_REG) == 0xff && inb(KBD_DATA_REG) == 0xff)) {
45 kbd_exists = 0;
46 return -1;
47 }
48 kbd_exists = 1;
49
50 if ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0)
51 return -1;
52
53
54
55
56 scancode = inb(KBD_DATA_REG);
57 scanstatus = inb(KBD_STATUS_REG);
58
59
60
61
62 if (scanstatus & KBD_STAT_MOUSE_OBF)
63 return -1;
64
65
66
67
68
69
70
71
72 if (((scancode&0x7f) == 0x2a) || ((scancode&0x7f) == 0x36)) {
73
74
75
76 if ((scancode & 0x80) == 0)
77 shift_key = 1;
78 else
79 shift_key = 0;
80 return -1;
81 }
82
83 if ((scancode&0x7f) == 0x1d) {
84
85
86
87 if ((scancode & 0x80) == 0)
88 ctrl_key = 1;
89 else
90 ctrl_key = 0;
91 return -1;
92 }
93
94 if ((scancode & 0x80) != 0) {
95 if (scancode == 0x9c)
96 kbd_last_ret = 0;
97 return -1;
98 }
99
100 scancode &= 0x7f;
101
102
103
104
105
106 if (scancode == 0x3a) {
107
108
109
110 shift_lock ^= 1;
111
112 #ifdef KDB_BLINK_LED
113 kdb_toggleled(0x4);
114 #endif
115 return -1;
116 }
117
118 if (scancode == 0x0e) {
119
120
121
122 return 8;
123 }
124
125
126 switch (scancode) {
127 case 0xF:
128 return 9;
129 case 0x53:
130 return 4;
131 case 0x47:
132 return 1;
133 case 0x4F:
134 return 5;
135 case 0x4B:
136 return 2;
137 case 0x48:
138 return 16;
139 case 0x50:
140 return 14;
141 case 0x4D:
142 return 6;
143 }
144
145 if (scancode == 0xe0)
146 return -1;
147
148
149
150
151
152
153 if (scancode == 0x73)
154 scancode = 0x59;
155 else if (scancode == 0x7d)
156 scancode = 0x7c;
157
158 if (!shift_lock && !shift_key && !ctrl_key) {
159 keychar = plain_map[scancode];
160 } else if ((shift_lock || shift_key) && key_maps[1]) {
161 keychar = key_maps[1][scancode];
162 } else if (ctrl_key && key_maps[4]) {
163 keychar = key_maps[4][scancode];
164 } else {
165 keychar = 0x0020;
166 kdb_printf("Unknown state/scancode (%d)\n", scancode);
167 }
168 keychar &= 0x0fff;
169 if (keychar == '\t')
170 keychar = ' ';
171 switch (KTYP(keychar)) {
172 case KT_LETTER:
173 case KT_LATIN:
174 if (isprint(keychar))
175 break;
176
177 case KT_SPEC:
178 if (keychar == K_ENTER)
179 break;
180
181 default:
182 return -1;
183 }
184
185 if (scancode == 0x1c) {
186 kbd_last_ret = 1;
187 return 13;
188 }
189
190 return keychar & 0xff;
191 }
192 EXPORT_SYMBOL_GPL(kdb_get_kbd_char);
193
194
195
196
197
198
199 void kdb_kbd_cleanup_state(void)
200 {
201 int scancode, scanstatus;
202
203
204
205
206
207
208 if (!kbd_last_ret)
209 return;
210
211 kbd_last_ret = 0;
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 while (1) {
227 while ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0)
228 cpu_relax();
229
230
231
232
233 scancode = inb(KBD_DATA_REG);
234 scanstatus = inb(KBD_STATUS_REG);
235
236
237
238
239 if (scanstatus & KBD_STAT_MOUSE_OBF)
240 continue;
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258 if (scancode != 0x9c)
259 continue;
260
261 return;
262 }
263 }