View | Details | Raw Unified | Return to bug 213835
Collapse All | Expand All

(-)b/usr.sbin/bhyve/ps2kbd.c (-228 / +131 lines)
Lines 74-79 struct ps2kbd_softc { Link Here
74
	uint8_t			curcmd;	/* current command for next byte */
74
	uint8_t			curcmd;	/* current command for next byte */
75
};
75
};
76
76
77
#define SCANCODE_E0_PREFIX 1
78
struct extended_translation {
79
	uint32_t keysym;
80
	uint8_t scancode;
81
	int flags;
82
};
83
84
/*
85
 * FIXME: Pause/break and Print Screen/SysRq require special handling.
86
 */
87
static const struct extended_translation extended_translations[] = {
88
		{0xff08, 0x66},		/* Back space */
89
		{0xff09, 0x0d},		/* Tab */
90
		{0xff0d, 0x5a},		/* Return */
91
		{0xff1b, 0x76},		/* Escape */
92
		{0xff50, 0x6c, SCANCODE_E0_PREFIX}, 	/* Home */
93
		{0xff51, 0x6b, SCANCODE_E0_PREFIX}, 	/* Left arrow */
94
		{0xff52, 0x75, SCANCODE_E0_PREFIX}, 	/* Up arrow */
95
		{0xff53, 0x74, SCANCODE_E0_PREFIX}, 	/* Right arrow */
96
		{0xff54, 0x72, SCANCODE_E0_PREFIX}, 	/* Down arrow */
97
		{0xff55, 0x7d, SCANCODE_E0_PREFIX}, 	/* PgUp */
98
		{0xff56, 0x7a, SCANCODE_E0_PREFIX}, 	/* PgDown */
99
		{0xff57, 0x69, SCANCODE_E0_PREFIX}, 	/* End */
100
		{0xff63, 0x70, SCANCODE_E0_PREFIX}, 	/* Ins */
101
		{0xff8d, 0x5a, SCANCODE_E0_PREFIX}, 	/* Keypad Enter */
102
		{0xffe1, 0x12},		/* Left shift */
103
		{0xffe2, 0x59},		/* Right shift */
104
		{0xffe3, 0x14},		/* Left control */
105
		{0xffe4, 0x14, SCANCODE_E0_PREFIX}, 	/* Right control */
106
		/* {0xffe7, XXX}, Left meta */
107
		/* {0xffe8, XXX}, Right meta */
108
		{0xffe9, 0x11},		/* Left alt */
109
		{0xfe03, 0x11, SCANCODE_E0_PREFIX}, 	/* AltGr */
110
		{0xffea, 0x11, SCANCODE_E0_PREFIX}, 	/* Right alt */
111
		{0xffeb, 0x1f, SCANCODE_E0_PREFIX}, 	/* Left Windows */
112
		{0xffec, 0x27, SCANCODE_E0_PREFIX}, 	/* Right Windows */
113
		{0xffbe, 0x05},		/* F1 */
114
		{0xffbf, 0x06},		/* F2 */
115
		{0xffc0, 0x04},		/* F3 */
116
		{0xffc1, 0x0c},		/* F4 */
117
		{0xffc2, 0x03},		/* F5 */
118
		{0xffc3, 0x0b},		/* F6 */
119
		{0xffc4, 0x83},		/* F7 */
120
		{0xffc5, 0x0a},		/* F8 */
121
		{0xffc6, 0x01},		/* F9 */
122
		{0xffc7, 0x09},		/* F10 */
123
		{0xffc8, 0x78},		/* F11 */
124
		{0xffc9, 0x07},		/* F12 */
125
		{0xffff, 0x71, SCANCODE_E0_PREFIX},		/* Del */
126
		{0xff14, 0x7e},		/* ScrollLock */
127
		/* NumLock and company */
128
		{0xff7f, 0x77}, 	/* NumLock */
129
		{0xffaf, 0x4a, SCANCODE_E0_PREFIX}, 	/* Keypad slash */
130
		{0xffaa, 0x7c}, 	/* Keypad asterisk */
131
		{0xffad, 0x7b}, 	/* Keypad minus */
132
		{0xffab, 0x79}, 	/* Keypad plus */
133
		{0xffb7, 0x6c}, 	/* Keypad 7 */
134
		{0xff95, 0x6c}, 	/* Keypad home */
135
		{0xffb8, 0x75}, 	/* Keypad 8 */
136
		{0xff97, 0x75}, 	/* Keypad up arrow */
137
		{0xffb9, 0x7d}, 	/* Keypad 9 */
138
		{0xff9a, 0x7d}, 	/* Keypad PgUp */
139
		{0xffb4, 0x6b}, 	/* Keypad 4 */
140
		{0xff96, 0x6b}, 	/* Keypad left arrow */
141
		{0xffb5, 0x73}, 	/* Keypad 5 */
142
		{0xff9d, 0x73}, 	/* Keypad empty */
143
		{0xffb6, 0x74}, 	/* Keypad 6 */
144
		{0xff98, 0x74}, 	/* Keypad right arrow */
145
		{0xffb1, 0x69}, 	/* Keypad 1 */
146
		{0xff9c, 0x69}, 	/* Keypad end */
147
		{0xffb2, 0x72}, 	/* Keypad 2 */
148
		{0xff99, 0x72}, 	/* Keypad down arrow */
149
		{0xffb3, 0x7a}, 	/* Keypad 3 */
150
		{0xff9b, 0x7a}, 	/* Keypad PgDown */
151
		{0xffb0, 0x70}, 	/* Keypad 0 */
152
		{0xff9e, 0x70}, 	/* Keypad ins */
153
		{0xffae, 0x71}, 	/* Keypad . */
154
		{0xff9f, 0x71}, 	/* Keypad del */
155
		{0, 0, 0} 	/* Terminator */
156
};
157
158
/* ASCII to type 2 scancode lookup table */
159
static const uint8_t ascii_translations[128] = {
160
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164
		0x29, 0x16, 0x52, 0x26, 0x25, 0x2e, 0x3d, 0x52,
165
		0x46, 0x45, 0x3e, 0x55, 0x41, 0x4e, 0x49, 0x4a,
166
		0x45, 0x16, 0x1e, 0x26, 0x25, 0x2e, 0x36, 0x3d,
167
		0x3e, 0x46, 0x4c, 0x4c, 0x41, 0x55, 0x49, 0x4a,
168
		0x1e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
169
		0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
170
		0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
171
		0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x36, 0x4e,
172
		0x0e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
173
		0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
174
		0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
175
		0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00,
176
};
177
77
static void
178
static void
78
fifo_init(struct ps2kbd_softc *sc)
179
fifo_init(struct ps2kbd_softc *sc)
79
{
180
{
Lines 208-445 ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val) Link Here
208
 */
309
 */
209
static void
310
static void
210
ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
311
ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
211
    int down, uint32_t keysym)
312
	int down, uint32_t keysym)
212
{
313
{
213
	/* ASCII to type 2 scancode lookup table */
214
	const uint8_t translation[128] = {
215
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219
		0x29, 0x16, 0x52, 0x26, 0x25, 0x2e, 0x3d, 0x52,
220
		0x46, 0x45, 0x3e, 0x55, 0x41, 0x4e, 0x49, 0x4a,
221
		0x45, 0x16, 0x1e, 0x26, 0x25, 0x2e, 0x36, 0x3d,
222
		0x3e, 0x46, 0x4c, 0x4c, 0x41, 0x55, 0x49, 0x4a,
223
		0x1e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
224
		0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
225
		0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
226
		0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x36, 0x4e,
227
		0x0e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
228
		0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
229
		0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
230
		0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00,
231
	};
232
233
	assert(pthread_mutex_isowned_np(&sc->mtx));
314
	assert(pthread_mutex_isowned_np(&sc->mtx));
315
	int e0_prefix, found;
316
	uint8_t code;
317
	const struct extended_translation *trans;
318
319
	found = 0;
320
	if (keysym < 0x80) {
321
		code = ascii_translations[keysym];
322
		e0_prefix = 0;
323
		found = 1;
324
	}
325
	else {
326
		for (trans = &(extended_translations[0]); trans->keysym != 0; trans++) {
327
			if (keysym == trans->keysym) {
328
				code = trans->scancode;
329
				e0_prefix = trans->flags & SCANCODE_E0_PREFIX;
330
				found = 1;
331
				break;
332
			}
333
		}
334
	}
234
335
235
	switch (keysym) {
336
	if (!found) {
236
	case 0x0 ... 0x7f:
337
		fprintf(stderr, "Unhandled ps2 keyboard keysym 0x%x\n", keysym);
237
		if (!down)
338
		return;
238
			fifo_put(sc, 0xf0);
239
		fifo_put(sc, translation[keysym]);
240
		break;
241
	case 0xff08:	/* Back space */
242
		if (!down)
243
			fifo_put(sc, 0xf0);
244
		fifo_put(sc, 0x66);
245
		break;
246
	case 0xff09:	/* Tab */
247
		if (!down)
248
			fifo_put(sc, 0xf0);
249
		fifo_put(sc, 0x0d);
250
		break;
251
	case 0xff0d:	/* Return  */
252
		if (!down)
253
			fifo_put(sc, 0xf0);
254
		fifo_put(sc, 0x5a);
255
		break;
256
	case 0xff1b:	/* Escape */
257
		if (!down)
258
			fifo_put(sc, 0xf0);
259
		fifo_put(sc, 0x76);
260
		break;
261
	case 0xff50:	/* Home */
262
		fifo_put(sc, 0xe0);
263
		if (!down)
264
			fifo_put(sc, 0xf0);
265
		fifo_put(sc, 0x6c);
266
		break;
267
	case 0xff51:	/* Left arrow */
268
		fifo_put(sc, 0xe0);
269
		if (!down)
270
			fifo_put(sc, 0xf0);
271
		fifo_put(sc, 0x6b);
272
		break;
273
	case 0xff52:	/* Up arrow */
274
		fifo_put(sc, 0xe0);
275
		if (!down)
276
			fifo_put(sc, 0xf0);
277
		fifo_put(sc, 0x75);
278
		break;
279
	case 0xff53:	/* Right arrow */
280
		fifo_put(sc, 0xe0);
281
		if (!down)
282
			fifo_put(sc, 0xf0);
283
		fifo_put(sc, 0x74);
284
		break;
285
	case 0xff54:	/* Down arrow */
286
		fifo_put(sc, 0xe0);
287
		if (!down)
288
			fifo_put(sc, 0xf0);
289
		fifo_put(sc, 0x72);
290
		break;
291
	case 0xff55:	/* PgUp */
292
		fifo_put(sc, 0xe0);
293
		if (!down)
294
			fifo_put(sc, 0xf0);	
295
		fifo_put(sc, 0x7d);
296
		break;
297
	case 0xff56:	/* PgDwn */
298
		fifo_put(sc, 0xe0);
299
		if (!down)
300
			fifo_put(sc, 0xf0);	
301
		fifo_put(sc, 0x7a);
302
		break;
303
	case 0xff57:	/* End */
304
		fifo_put(sc, 0xe0);
305
		if (!down)
306
			fifo_put(sc, 0xf0);	
307
		fifo_put(sc, 0x69);
308
		break;
309
	case 0xff63:	/* Ins */
310
		fifo_put(sc, 0xe0);
311
		if (!down)
312
			fifo_put(sc, 0xf0);	
313
		fifo_put(sc, 0x70);
314
		break;
315
	case 0xff8d:	/* Keypad Enter */
316
		fifo_put(sc, 0xe0);
317
		if (!down)
318
			fifo_put(sc, 0xf0);
319
		fifo_put(sc, 0x5a);
320
		break;
321
	case 0xffe1:	/* Left shift */
322
		if (!down)
323
			fifo_put(sc, 0xf0);
324
		fifo_put(sc, 0x12);
325
		break;
326
	case 0xffe2:	/* Right shift */
327
		if (!down)
328
			fifo_put(sc, 0xf0);
329
		fifo_put(sc, 0x59);
330
		break;
331
	case 0xffe3:	/* Left control */
332
		if (!down)
333
			fifo_put(sc, 0xf0);
334
		fifo_put(sc, 0x14);
335
		break;
336
	case 0xffe4:	/* Right control */
337
		fifo_put(sc, 0xe0);
338
		if (!down)
339
			fifo_put(sc, 0xf0);
340
		fifo_put(sc, 0x14);
341
		break;
342
	case 0xffe7:	/* Left meta */
343
		/* XXX */
344
		break;
345
	case 0xffe8:	/* Right meta */
346
		/* XXX */
347
		break;
348
	case 0xffe9:	/* Left alt */
349
		if (!down)
350
			fifo_put(sc, 0xf0);
351
		fifo_put(sc, 0x11);
352
		break;
353
	case 0xfe03:	/* AltGr */
354
	case 0xffea:	/* Right alt */
355
		fifo_put(sc, 0xe0);
356
		if (!down)
357
			fifo_put(sc, 0xf0);
358
		fifo_put(sc, 0x11);
359
		break;
360
	case 0xffeb:	/* Left Windows */
361
		fifo_put(sc, 0xe0);
362
		if (!down)
363
			fifo_put(sc, 0xf0);
364
		fifo_put(sc, 0x1f);
365
		break;
366
	case 0xffec:	/* Right Windows */
367
		fifo_put(sc, 0xe0);
368
		if (!down)
369
			fifo_put(sc, 0xf0);
370
		fifo_put(sc, 0x27);
371
		break;
372
	case 0xffbe:    /* F1 */
373
		if (!down)
374
			fifo_put(sc, 0xf0);
375
		fifo_put(sc, 0x05);
376
		break;
377
	case 0xffbf:    /* F2 */
378
		if (!down)
379
			fifo_put(sc, 0xf0);
380
		fifo_put(sc, 0x06);
381
		break;
382
	case 0xffc0:    /* F3 */
383
		if (!down)
384
			fifo_put(sc, 0xf0);
385
		fifo_put(sc, 0x04);
386
		break;
387
	case 0xffc1:    /* F4 */
388
		if (!down)
389
			fifo_put(sc, 0xf0);
390
		fifo_put(sc, 0x0C);
391
		break;
392
	case 0xffc2:    /* F5 */
393
		if (!down)
394
			fifo_put(sc, 0xf0);
395
		fifo_put(sc, 0x03);
396
		break;
397
	case 0xffc3:    /* F6 */
398
		if (!down)
399
			fifo_put(sc, 0xf0);
400
		fifo_put(sc, 0x0B);
401
		break;
402
	case 0xffc4:    /* F7 */
403
		if (!down)
404
			fifo_put(sc, 0xf0);
405
		fifo_put(sc, 0x83);
406
		break;
407
	case 0xffc5:    /* F8 */
408
		if (!down)
409
			fifo_put(sc, 0xf0);
410
		fifo_put(sc, 0x0A);
411
		break;
412
	case 0xffc6:    /* F9 */
413
		if (!down)
414
			fifo_put(sc, 0xf0);
415
		fifo_put(sc, 0x01);
416
		break;
417
	case 0xffc7:    /* F10 */
418
		if (!down)
419
			fifo_put(sc, 0xf0);
420
		fifo_put(sc, 0x09);
421
		break;
422
	case 0xffc8:    /* F11 */
423
		if (!down)
424
			fifo_put(sc, 0xf0);
425
		fifo_put(sc, 0x78);
426
		break;
427
	case 0xffc9:    /* F12 */
428
		if (!down)
429
			fifo_put(sc, 0xf0);
430
		fifo_put(sc, 0x07);
431
		break;
432
	case 0xffff:    /* Del */
433
		fifo_put(sc, 0xe0);
434
		if (!down)
435
			fifo_put(sc, 0xf0);
436
		fifo_put(sc, 0x71);
437
		break;
438
	default:
439
		fprintf(stderr, "Unhandled ps2 keyboard keysym 0x%x\n",
440
		     keysym);
441
		break;
442
	}
339
	}
340
341
	if (e0_prefix)
342
		fifo_put(sc, 0xe0);
343
	if (!down)
344
		fifo_put(sc, 0xf0);
345
	fifo_put(sc, code);
443
}
346
}
444
347
445
static void
348
static void

Return to bug 213835