#include "hw.h"
#include "isa.h"
#include "pc.h"
-#include "sysemu.h"
+#include "kvm.h"
+#include "qdev.h"
+
+//#define VMPORT_DEBUG
#define VMPORT_CMD_GETVERSION 0x0a
#define VMPORT_CMD_GETRAMSIZE 0x14
typedef struct _VMPortState
{
+ ISADevice dev;
+ MemoryRegion io;
IOPortReadFunc *func[VMPORT_ENTRIES];
void *opaque[VMPORT_ENTRIES];
} VMPortState;
-static VMPortState port_state;
+static VMPortState *port_state;
void vmport_register(unsigned char command, IOPortReadFunc *func, void *opaque)
{
if (command >= VMPORT_ENTRIES)
return;
- port_state.func[command] = func;
- port_state.opaque[command] = opaque;
+ port_state->func[command] = func;
+ port_state->opaque[command] = opaque;
}
static uint32_t vmport_ioport_read(void *opaque, uint32_t addr)
unsigned char command;
uint32_t eax;
+ cpu_synchronize_state(env);
+
eax = env->regs[R_EAX];
if (eax != VMPORT_MAGIC)
return eax;
return eax;
if (!s->func[command])
{
- printf("vmport: unknown command %x\n", command);
+#ifdef VMPORT_DEBUG
+ fprintf(stderr, "vmport: unknown command %x\n", command);
+#endif
return eax;
}
return ram_size;
}
-void vmport_init(void)
+/* vmmouse helpers */
+void vmmouse_get_data(uint32_t *data)
+{
+ CPUState *env = cpu_single_env;
+
+ data[0] = env->regs[R_EAX]; data[1] = env->regs[R_EBX];
+ data[2] = env->regs[R_ECX]; data[3] = env->regs[R_EDX];
+ data[4] = env->regs[R_ESI]; data[5] = env->regs[R_EDI];
+}
+
+void vmmouse_set_data(const uint32_t *data)
{
- register_ioport_read(0x5658, 1, 4, vmport_ioport_read, &port_state);
- register_ioport_write(0x5658, 1, 4, vmport_ioport_write, &port_state);
+ CPUState *env = cpu_single_env;
+
+ env->regs[R_EAX] = data[0]; env->regs[R_EBX] = data[1];
+ env->regs[R_ECX] = data[2]; env->regs[R_EDX] = data[3];
+ env->regs[R_ESI] = data[4]; env->regs[R_EDI] = data[5];
+}
+static const MemoryRegionPortio vmport_portio[] = {
+ {0, 1, 4, .read = vmport_ioport_read, .write = vmport_ioport_write },
+ PORTIO_END_OF_LIST(),
+};
+
+static const MemoryRegionOps vmport_ops = {
+ .old_portio = vmport_portio
+};
+
+static int vmport_initfn(ISADevice *dev)
+{
+ VMPortState *s = DO_UPCAST(VMPortState, dev, dev);
+
+ memory_region_init_io(&s->io, &vmport_ops, s, "vmport", 1);
+ isa_register_ioport(dev, &s->io, 0x5658);
+
+ port_state = s;
/* Register some generic port commands */
vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
+ return 0;
+}
+
+static ISADeviceInfo vmport_info = {
+ .qdev.name = "vmport",
+ .qdev.size = sizeof(VMPortState),
+ .qdev.no_user = 1,
+ .init = vmport_initfn,
+};
+
+static void vmport_dev_register(void)
+{
+ isa_qdev_register(&vmport_info);
}
+device_init(vmport_dev_register)