Commit 6e4255f6a65091fbe7d17bfda546e2aa1b72f9a6

Authored by bellard
1 parent 74ffc772

windows support for kqemu (Filip Navara)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1366 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 74 additions and 12 deletions
... ... @@ -20,9 +20,11 @@
20 20 #include "config.h"
21 21 #ifdef _WIN32
22 22 #include <windows.h>
  23 +#include <winioctl.h>
23 24 #else
24 25 #include <sys/types.h>
25 26 #include <sys/mman.h>
  27 +#include <sys/ioctl.h>
26 28 #endif
27 29 #include <stdlib.h>
28 30 #include <stdio.h>
... ... @@ -41,13 +43,25 @@
41 43  
42 44 #include <unistd.h>
43 45 #include <fcntl.h>
44   -#include <sys/ioctl.h>
45 46 #include "kqemu/kqemu.h"
46 47  
  48 +#ifdef _WIN32
  49 +#define KQEMU_DEVICE "\\\\.\\kqemu"
  50 +#else
47 51 #define KQEMU_DEVICE "/dev/kqemu"
  52 +#endif
  53 +
  54 +#ifdef _WIN32
  55 +#define KQEMU_INVALID_FD INVALID_HANDLE_VALUE
  56 +HANDLE kqemu_fd = KQEMU_INVALID_FD;
  57 +#define kqemu_closefd(x) CloseHandle(x)
  58 +#else
  59 +#define KQEMU_INVALID_FD -1
  60 +int kqemu_fd = KQEMU_INVALID_FD;
  61 +#define kqemu_closefd(x) close(x)
  62 +#endif
48 63  
49 64 int kqemu_allowed = 1;
50   -int kqemu_fd = -1;
51 65 unsigned long *pages_to_flush;
52 66 unsigned int nb_pages_to_flush;
53 67 extern uint32_t **l1_phys_map;
... ... @@ -104,17 +118,32 @@ int kqemu_init(CPUState *env)
104 118 {
105 119 struct kqemu_init init;
106 120 int ret, version;
  121 +#ifdef _WIN32
  122 + DWORD temp;
  123 +#endif
107 124  
108 125 if (!kqemu_allowed)
109 126 return -1;
110 127  
  128 +#ifdef _WIN32
  129 + kqemu_fd = CreateFile(KQEMU_DEVICE, GENERIC_WRITE | GENERIC_READ,
  130 + FILE_SHARE_READ | FILE_SHARE_WRITE,
  131 + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
  132 + NULL);
  133 +#else
111 134 kqemu_fd = open(KQEMU_DEVICE, O_RDWR);
112   - if (kqemu_fd < 0) {
  135 +#endif
  136 + if (kqemu_fd == KQEMU_INVALID_FD) {
113 137 fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated\n", KQEMU_DEVICE);
114 138 return -1;
115 139 }
116 140 version = 0;
  141 +#ifdef _WIN32
  142 + DeviceIoControl(kqemu_fd, KQEMU_GET_VERSION, NULL, 0,
  143 + &version, sizeof(version), &temp, NULL);
  144 +#else
117 145 ioctl(kqemu_fd, KQEMU_GET_VERSION, &version);
  146 +#endif
118 147 if (version != KQEMU_VERSION) {
119 148 fprintf(stderr, "Version mismatch between kqemu module and qemu (%08x %08x) - disabling kqemu use\n",
120 149 version, KQEMU_VERSION);
... ... @@ -131,12 +160,17 @@ int kqemu_init(CPUState *env)
131 160 init.ram_dirty = phys_ram_dirty;
132 161 init.phys_to_ram_map = l1_phys_map;
133 162 init.pages_to_flush = pages_to_flush;
  163 +#ifdef _WIN32
  164 + ret = DeviceIoControl(kqemu_fd, KQEMU_INIT, &init, sizeof(init),
  165 + NULL, 0, &temp, NULL) == TRUE ? 0 : -1;
  166 +#else
134 167 ret = ioctl(kqemu_fd, KQEMU_INIT, &init);
  168 +#endif
135 169 if (ret < 0) {
136 170 fprintf(stderr, "Error %d while initializing QEMU acceleration layer - disabling it for now\n", ret);
137 171 fail:
138   - close(kqemu_fd);
139   - kqemu_fd = -1;
  172 + kqemu_closefd(kqemu_fd);
  173 + kqemu_fd = KQEMU_INVALID_FD;
140 174 return -1;
141 175 }
142 176 kqemu_update_cpuid(env);
... ... @@ -313,6 +347,9 @@ int kqemu_cpu_exec(CPUState *env)
313 347 {
314 348 struct kqemu_cpu_state kcpu_state, *kenv = &kcpu_state;
315 349 int ret;
  350 +#ifdef _WIN32
  351 + DWORD temp;
  352 +#endif
316 353  
317 354 #ifdef DEBUG
318 355 if (loglevel & CPU_LOG_INT) {
... ... @@ -354,8 +391,20 @@ int kqemu_cpu_exec(CPUState *env)
354 391 restore_native_fp_frstor(env);
355 392 }
356 393  
  394 +#ifdef _WIN32
  395 + DeviceIoControl(kqemu_fd, KQEMU_EXEC,
  396 + kenv, sizeof(struct kqemu_cpu_state),
  397 + kenv, sizeof(struct kqemu_cpu_state),
  398 + &temp, NULL);
  399 + ret = kenv->retval;
  400 +#else
  401 +#if KQEMU_VERSION >= 0x010100
  402 + ioctl(kqemu_fd, KQEMU_EXEC, kenv);
  403 + ret = kenv->retval;
  404 +#else
357 405 ret = ioctl(kqemu_fd, KQEMU_EXEC, kenv);
358   -
  406 +#endif
  407 +#endif
359 408 if (!(kenv->cr0 & CR0_TS_MASK)) {
360 409 if (env->cpuid_features & CPUID_FXSR)
361 410 save_native_fp_fxsave(env);
... ...
... ... @@ -273,15 +273,13 @@ void *get_mmap_addr(unsigned long size)
273 273  
274 274 #else
275 275  
276   -#ifdef _BSD
  276 +#ifdef _WIN32
  277 +#include <windows.h>
  278 +#elif defined(_BSD)
277 279 #include <stdlib.h>
278 280 #else
279 281 #include <malloc.h>
280 282 #endif
281   -#ifdef _WIN32
282   -/* XXX: find a solution to have page aligned data */
283   -#define memalign(align, size) malloc(size)
284   -#endif
285 283  
286 284 int qemu_write(int fd, const void *buf, size_t n)
287 285 {
... ... @@ -308,7 +306,22 @@ void *qemu_malloc(size_t size)
308 306 return malloc(size);
309 307 }
310 308  
311   -#if defined(USE_KQEMU)
  309 +#if defined(_WIN32)
  310 +
  311 +void *qemu_vmalloc(size_t size)
  312 +{
  313 + /* FIXME: this is not exactly optimal solution since VirtualAlloc
  314 + has 64Kb granularity, but at least it guarantees us that the
  315 + memory is page aligned. */
  316 + return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
  317 +}
  318 +
  319 +void qemu_vfree(void *ptr)
  320 +{
  321 + VirtualFree(ptr, 0, MEM_RELEASE);
  322 +}
  323 +
  324 +#elif defined(USE_KQEMU)
312 325  
313 326 #include <sys/mman.h>
314 327 #include <fcntl.h>
... ...