// After the Keyboard SET_RATE is called
// we wait for the output byte on 64?
SET_RATE,
+ // after having a f0 sent to 60
+ // we wait for a new output byte on 60
+ GETSET_SCANCODES,
} state;
uint8_t wrap;
int mouse_enabled;
+ int scancode_set;
struct queue kbd_queue;
struct queue mouse_queue;
kbd->state = NORMAL;
break;
+ case GETSET_SCANCODES:
+ switch (data) {
+ case 0:
+ PrintDebug("Keyboard: scancode set being read\n");
+ push_to_output_queue(kbd, 0x45 - 2 * kbd->scancode_set, COMMAND, KEYBOARD);
+ break;
+ case 1:
+ PrintError("keyboard: unsupported scancode set %d selected\n", data);
+ return -1;
+ case 2:
+ PrintDebug("Keyboard: scancode set being set to %d\n", data);
+ kbd->scancode_set = data;
+ push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD);
+ break;
+ case 3:
+ /* OpenBSD wants scancode set 3, but falls back to 2 if a
+ * subsequent read reveals that the request was ignored
+ */
+ PrintError("keyboard: ignoring request for scancode set %d\n", data);
+ break;
+ default:
+ PrintError("keyboard: unknown scancode set %d selected\n", data);
+ return -1;
+
+ }
+ kbd->state = NORMAL;
+ break;
+
default:
case NORMAL: {
// command is being sent to keyboard controller
push_to_output_queue(kbd, 0xee, COMMAND, KEYBOARD);
break;
+ case 0xf0: // get/set scancode set
+ push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD);
+ kbd->state = GETSET_SCANCODES;
+ break;
+
case 0xfe: // resend
case 0xfd: // set key type make
case 0xfc: // set key typ make/break
-static int keyboard_free(struct vm_device * dev) {
+static int keyboard_free(struct keyboard_internal * kbd) {
+
+ // unhook host events
+
+ V3_Free(kbd);
return 0;
}
kbd->kbd_queue.count = 0;
kbd->mouse_enabled = 0;
+ kbd->scancode_set = 2;
kbd->state = NORMAL;
kbd->mouse_state = STREAM;
}
static struct v3_device_ops dev_ops = {
- .free = keyboard_free,
+ .free = (int (*)(void *))keyboard_free,
};
static int keyboard_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
struct keyboard_internal * kbd = NULL;
char * dev_id = v3_cfg_val(cfg, "ID");
+ int ret = 0;
PrintDebug("keyboard: init_device\n");
kbd->vm = vm;
- struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, kbd);
+ struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, kbd);
- if (v3_attach_device(vm, dev) == -1) {
+ if (dev == NULL) {
PrintError("Could not attach device %s\n", dev_id);
+ V3_Free(kbd);
return -1;
}
// hook ports
- v3_dev_hook_io(dev, KEYBOARD_64H, &keyboard_read_status, &keyboard_write_command);
- v3_dev_hook_io(dev, KEYBOARD_60H, &keyboard_read_input, &keyboard_write_output);
+ ret |= v3_dev_hook_io(dev, KEYBOARD_64H, &keyboard_read_status, &keyboard_write_command);
+ ret |= v3_dev_hook_io(dev, KEYBOARD_60H, &keyboard_read_input, &keyboard_write_output);
+
+ if (ret != 0) {
+ PrintError("Error hooking keyboard IO ports\n");
+ v3_remove_device(dev);
+ return -1;
+ }
v3_hook_host_event(vm, HOST_KEYBOARD_EVT, V3_HOST_EVENT_HANDLER(key_event_handler), kbd);
v3_hook_host_event(vm, HOST_MOUSE_EVT, V3_HOST_EVENT_HANDLER(mouse_event_handler), kbd);