From 6e4255f6a65091fbe7d17bfda546e2aa1b72f9a6 Mon Sep 17 00:00:00 2001 From: bellard Date: Sun, 17 Apr 2005 18:33:47 +0000 Subject: windows support for kqemu (Filip Navara) git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1366 c046a42c-6fe2-441c-8c8c-71466251a162 --- kqemu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-) (limited to 'kqemu.c') diff --git a/kqemu.c b/kqemu.c index 20aaf6376b..1e0e86b51b 100644 --- a/kqemu.c +++ b/kqemu.c @@ -20,9 +20,11 @@ #include "config.h" #ifdef _WIN32 #include +#include #else #include #include +#include #endif #include #include @@ -41,13 +43,25 @@ #include #include -#include #include "kqemu/kqemu.h" +#ifdef _WIN32 +#define KQEMU_DEVICE "\\\\.\\kqemu" +#else #define KQEMU_DEVICE "/dev/kqemu" +#endif + +#ifdef _WIN32 +#define KQEMU_INVALID_FD INVALID_HANDLE_VALUE +HANDLE kqemu_fd = KQEMU_INVALID_FD; +#define kqemu_closefd(x) CloseHandle(x) +#else +#define KQEMU_INVALID_FD -1 +int kqemu_fd = KQEMU_INVALID_FD; +#define kqemu_closefd(x) close(x) +#endif int kqemu_allowed = 1; -int kqemu_fd = -1; unsigned long *pages_to_flush; unsigned int nb_pages_to_flush; extern uint32_t **l1_phys_map; @@ -104,17 +118,32 @@ int kqemu_init(CPUState *env) { struct kqemu_init init; int ret, version; +#ifdef _WIN32 + DWORD temp; +#endif if (!kqemu_allowed) return -1; +#ifdef _WIN32 + kqemu_fd = CreateFile(KQEMU_DEVICE, GENERIC_WRITE | GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, + NULL); +#else kqemu_fd = open(KQEMU_DEVICE, O_RDWR); - if (kqemu_fd < 0) { +#endif + if (kqemu_fd == KQEMU_INVALID_FD) { fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated\n", KQEMU_DEVICE); return -1; } version = 0; +#ifdef _WIN32 + DeviceIoControl(kqemu_fd, KQEMU_GET_VERSION, NULL, 0, + &version, sizeof(version), &temp, NULL); +#else ioctl(kqemu_fd, KQEMU_GET_VERSION, &version); +#endif if (version != KQEMU_VERSION) { fprintf(stderr, "Version mismatch between kqemu module and qemu (%08x %08x) - disabling kqemu use\n", version, KQEMU_VERSION); @@ -131,12 +160,17 @@ int kqemu_init(CPUState *env) init.ram_dirty = phys_ram_dirty; init.phys_to_ram_map = l1_phys_map; init.pages_to_flush = pages_to_flush; +#ifdef _WIN32 + ret = DeviceIoControl(kqemu_fd, KQEMU_INIT, &init, sizeof(init), + NULL, 0, &temp, NULL) == TRUE ? 0 : -1; +#else ret = ioctl(kqemu_fd, KQEMU_INIT, &init); +#endif if (ret < 0) { fprintf(stderr, "Error %d while initializing QEMU acceleration layer - disabling it for now\n", ret); fail: - close(kqemu_fd); - kqemu_fd = -1; + kqemu_closefd(kqemu_fd); + kqemu_fd = KQEMU_INVALID_FD; return -1; } kqemu_update_cpuid(env); @@ -313,6 +347,9 @@ int kqemu_cpu_exec(CPUState *env) { struct kqemu_cpu_state kcpu_state, *kenv = &kcpu_state; int ret; +#ifdef _WIN32 + DWORD temp; +#endif #ifdef DEBUG if (loglevel & CPU_LOG_INT) { @@ -354,8 +391,20 @@ int kqemu_cpu_exec(CPUState *env) restore_native_fp_frstor(env); } +#ifdef _WIN32 + DeviceIoControl(kqemu_fd, KQEMU_EXEC, + kenv, sizeof(struct kqemu_cpu_state), + kenv, sizeof(struct kqemu_cpu_state), + &temp, NULL); + ret = kenv->retval; +#else +#if KQEMU_VERSION >= 0x010100 + ioctl(kqemu_fd, KQEMU_EXEC, kenv); + ret = kenv->retval; +#else ret = ioctl(kqemu_fd, KQEMU_EXEC, kenv); - +#endif +#endif if (!(kenv->cr0 & CR0_TS_MASK)) { if (env->cpuid_features & CPUID_FXSR) save_native_fp_fxsave(env); -- cgit v1.2.3