2007-08-26 17:48:12 +00:00
|
|
|
/*
|
|
|
|
* QEMU VMPort emulation
|
|
|
|
*
|
2011-12-02 09:30:41 +00:00
|
|
|
* Copyright (C) 2007 Hervé Poussineau
|
2007-08-26 17:48:12 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/isa.h"
|
|
|
|
#include "hw/pc.h"
|
2012-12-17 17:20:04 +00:00
|
|
|
#include "sysemu/kvm.h"
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/qdev.h"
|
2007-08-26 17:48:12 +00:00
|
|
|
|
2008-08-19 19:13:06 +00:00
|
|
|
//#define VMPORT_DEBUG
|
|
|
|
|
2007-08-26 17:48:12 +00:00
|
|
|
#define VMPORT_CMD_GETVERSION 0x0a
|
|
|
|
#define VMPORT_CMD_GETRAMSIZE 0x14
|
|
|
|
|
|
|
|
#define VMPORT_ENTRIES 0x2c
|
|
|
|
#define VMPORT_MAGIC 0x564D5868
|
|
|
|
|
|
|
|
typedef struct _VMPortState
|
|
|
|
{
|
2011-02-05 14:34:41 +00:00
|
|
|
ISADevice dev;
|
2011-08-16 15:38:14 +00:00
|
|
|
MemoryRegion io;
|
2007-08-26 17:48:12 +00:00
|
|
|
IOPortReadFunc *func[VMPORT_ENTRIES];
|
|
|
|
void *opaque[VMPORT_ENTRIES];
|
|
|
|
} VMPortState;
|
|
|
|
|
2011-02-17 03:27:19 +00:00
|
|
|
static VMPortState *port_state;
|
2007-08-26 17:48:12 +00:00
|
|
|
|
|
|
|
void vmport_register(unsigned char command, IOPortReadFunc *func, void *opaque)
|
|
|
|
{
|
|
|
|
if (command >= VMPORT_ENTRIES)
|
|
|
|
return;
|
|
|
|
|
2011-02-17 03:27:19 +00:00
|
|
|
port_state->func[command] = func;
|
|
|
|
port_state->opaque[command] = opaque;
|
2007-08-26 17:48:12 +00:00
|
|
|
}
|
|
|
|
|
2012-10-08 11:44:24 +00:00
|
|
|
static uint64_t vmport_ioport_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2007-08-26 17:48:12 +00:00
|
|
|
{
|
|
|
|
VMPortState *s = opaque;
|
2012-03-14 00:38:23 +00:00
|
|
|
CPUX86State *env = cpu_single_env;
|
2007-08-26 17:48:12 +00:00
|
|
|
unsigned char command;
|
2007-10-09 03:19:01 +00:00
|
|
|
uint32_t eax;
|
2007-08-26 17:48:12 +00:00
|
|
|
|
2010-02-03 20:16:41 +00:00
|
|
|
cpu_synchronize_state(env);
|
|
|
|
|
2008-04-07 19:47:25 +00:00
|
|
|
eax = env->regs[R_EAX];
|
2007-08-26 17:48:12 +00:00
|
|
|
if (eax != VMPORT_MAGIC)
|
|
|
|
return eax;
|
|
|
|
|
2008-04-07 19:47:25 +00:00
|
|
|
command = env->regs[R_ECX];
|
2007-08-26 17:48:12 +00:00
|
|
|
if (command >= VMPORT_ENTRIES)
|
|
|
|
return eax;
|
|
|
|
if (!s->func[command])
|
|
|
|
{
|
2008-08-19 19:13:06 +00:00
|
|
|
#ifdef VMPORT_DEBUG
|
|
|
|
fprintf(stderr, "vmport: unknown command %x\n", command);
|
|
|
|
#endif
|
2007-08-26 17:48:12 +00:00
|
|
|
return eax;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s->func[command](s->opaque[command], addr);
|
|
|
|
}
|
|
|
|
|
2012-10-08 11:44:24 +00:00
|
|
|
static void vmport_ioport_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2008-07-28 18:58:02 +00:00
|
|
|
{
|
2012-03-14 00:38:23 +00:00
|
|
|
CPUX86State *env = cpu_single_env;
|
2008-07-28 18:58:02 +00:00
|
|
|
|
2012-10-08 11:44:24 +00:00
|
|
|
env->regs[R_EAX] = vmport_ioport_read(opaque, addr, 4);
|
2008-07-28 18:58:02 +00:00
|
|
|
}
|
|
|
|
|
2007-08-26 17:48:12 +00:00
|
|
|
static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
|
|
|
|
{
|
2012-03-14 00:38:23 +00:00
|
|
|
CPUX86State *env = cpu_single_env;
|
2007-08-26 17:48:12 +00:00
|
|
|
env->regs[R_EBX] = VMPORT_MAGIC;
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr)
|
|
|
|
{
|
2012-03-14 00:38:23 +00:00
|
|
|
CPUX86State *env = cpu_single_env;
|
2007-08-26 17:48:12 +00:00
|
|
|
env->regs[R_EBX] = 0x1177;
|
|
|
|
return ram_size;
|
|
|
|
}
|
|
|
|
|
2011-02-05 14:34:52 +00:00
|
|
|
/* vmmouse helpers */
|
|
|
|
void vmmouse_get_data(uint32_t *data)
|
|
|
|
{
|
2012-03-14 00:38:23 +00:00
|
|
|
CPUX86State *env = cpu_single_env;
|
2011-02-05 14:34:52 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-03-14 00:38:23 +00:00
|
|
|
CPUX86State *env = cpu_single_env;
|
2011-02-05 14:34:52 +00:00
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2011-08-16 15:38:14 +00:00
|
|
|
static const MemoryRegionOps vmport_ops = {
|
2012-10-08 11:44:24 +00:00
|
|
|
.read = vmport_ioport_read,
|
|
|
|
.write = vmport_ioport_write,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 4,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-16 15:38:14 +00:00
|
|
|
};
|
|
|
|
|
2011-02-05 14:34:41 +00:00
|
|
|
static int vmport_initfn(ISADevice *dev)
|
2007-08-26 17:48:12 +00:00
|
|
|
{
|
2011-02-05 14:34:41 +00:00
|
|
|
VMPortState *s = DO_UPCAST(VMPortState, dev, dev);
|
2007-08-26 17:48:12 +00:00
|
|
|
|
2011-08-16 15:38:14 +00:00
|
|
|
memory_region_init_io(&s->io, &vmport_ops, s, "vmport", 1);
|
|
|
|
isa_register_ioport(dev, &s->io, 0x5658);
|
|
|
|
|
2011-02-17 03:27:19 +00:00
|
|
|
port_state = s;
|
2007-08-26 17:48:12 +00:00
|
|
|
/* Register some generic port commands */
|
2008-04-07 19:47:25 +00:00
|
|
|
vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
|
|
|
|
vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
|
2011-02-05 14:34:41 +00:00
|
|
|
return 0;
|
2007-08-26 17:48:12 +00:00
|
|
|
}
|
2011-02-05 14:34:41 +00:00
|
|
|
|
2011-12-04 17:52:49 +00:00
|
|
|
static void vmport_class_initfn(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 17:52:49 +00:00
|
|
|
ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
|
|
|
|
ic->init = vmport_initfn;
|
2011-12-08 03:34:16 +00:00
|
|
|
dc->no_user = 1;
|
2011-12-04 17:52:49 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 15:19:07 +00:00
|
|
|
static const TypeInfo vmport_info = {
|
2011-12-08 03:34:16 +00:00
|
|
|
.name = "vmport",
|
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(VMPortState),
|
|
|
|
.class_init = vmport_class_initfn,
|
2011-02-05 14:34:41 +00:00
|
|
|
};
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
static void vmport_register_types(void)
|
2011-02-05 14:34:41 +00:00
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
type_register_static(&vmport_info);
|
2011-02-05 14:34:41 +00:00
|
|
|
}
|
2012-02-09 14:20:55 +00:00
|
|
|
|
|
|
|
type_init(vmport_register_types)
|