Changes to existing files to add HAX support

HAX (Hardware-based Accelerated eXecution) employes hardware virtualization
technology to boost performance of the Android emulator on Mac OS X or Windows
hosts.
This changeset includes the changes required to the existing files. To pass
the compilation, hax.h is added, but CONFIG_HAX is disabled so that no
real changes added.

Change-Id: Ifa5777e8788e6698747c1ec4cd91315161c2ca0b
Signed-off-by: Zhang, Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Xin, Xiaohui <xiaohui.xin@intel.com>
Signed-off-by: Jiang Yunhong <yunhong.jiang@intel.com>
Signed-off-by: Nakajima, Jun <jun.nakajima@intel.com>
diff --git a/cpus.c b/cpus.c
index 470eb32..585a6b3 100644
--- a/cpus.c
+++ b/cpus.c
@@ -28,6 +28,7 @@
 #include "gdbstub.h"
 #include "dma.h"
 #include "kvm.h"
+#include "hax.h"
 
 #include "cpus.h"
 
@@ -191,6 +192,10 @@
 
     if (kvm_enabled())
         kvm_init_vcpu(env);
+#ifdef CONFIG_HAX
+    if (hax_enabled())
+        hax_init_vcpu(env);
+#endif
     return;
 }
 
@@ -222,7 +227,27 @@
         if (env->kqemu_enabled)
             kqemu_cpu_interrupt(env);
 #endif
+    /*
+     * This is mainly for the Windows host, where the timer may be in
+     * a different thread with vcpu. Thus the timer function needs to
+     * notify the vcpu thread of more than simply cpu_exit.  If env is
+     * not NULL, it means that the vcpu is in execute state, we need
+     * only to set the flags.  If the guest is in execute state, the
+     * HAX kernel module will exit to qemu.  If env is NULL, vcpu is
+     * in main_loop_wait, and we need a event to notify it.
+     */
+#ifdef CONFIG_HAX
+        if (hax_enabled())
+            hax_raise_event(env);
+     } else {
+#ifdef _WIN32
+         if(hax_enabled())
+             SetEvent(qemu_event_handle);
+#endif
      }
+#else
+     }
+#endif
 }
 
 void qemu_mutex_lock_iothread(void)
@@ -361,7 +386,7 @@
 {
     CPUState *env = _env;
     qemu_cond_broadcast(env->halt_cond);
-    if (kvm_enabled())
+    if (kvm_enabled() || hax_enabled())
         qemu_thread_signal(env->thread, SIGUSR1);
 }
 
@@ -425,7 +450,7 @@
 
 void qemu_mutex_lock_iothread(void)
 {
-    if (kvm_enabled()) {
+    if (kvm_enabled() || hax_enabled()) {
         qemu_mutex_lock(&qemu_fair_mutex);
         qemu_mutex_lock(&qemu_global_mutex);
         qemu_mutex_unlock(&qemu_fair_mutex);