Refactor some hax related codes.
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 12 Jul 2013 06:36:03 +0000 (15:36 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 12 Jul 2013 06:36:03 +0000 (15:36 +0900)
Change-Id: I84842e268491dd3e090d9d1c111643c7f10923d0
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
12 files changed:
cpu-exec.c
cpus.c
exec.c
hax-stub.c
include/qemu/main-loop.h
include/sysemu/hax.h [moved from hax.h with 94% similarity]
main-loop.c
target-i386/hax-all.c
target-i386/hax-i386.h
target-i386/hax-windows.c
target-i386/translate.c
vl.c

index 7d36d96..0871c5c 100644 (file)
@@ -20,9 +20,9 @@
 #include "cpu.h"
 #include "disas/disas.h"
 #include "tcg.h"
-#include "hax.h"
 #include "qemu/atomic.h"
 #include "sysemu/qtest.h"
+#include "sysemu/hax.h"
 
 bool qemu_cpu_has_work(CPUState *cpu)
 {
diff --git a/cpus.c b/cpus.c
index 3592ba2..c08a21b 100644 (file)
--- a/cpus.c
+++ b/cpus.c
@@ -30,7 +30,7 @@
 #include "exec/gdbstub.h"
 #include "sysemu/dma.h"
 #include "sysemu/kvm.h"
-#include "hax.h"
+#include "sysemu/hax.h"
 #include "qmp-commands.h"
 
 #include "qemu/thread.h"
@@ -1357,16 +1357,3 @@ void qmp_inject_nmi(Error **errp)
     error_set(errp, QERR_UNSUPPORTED);
 #endif
 }
-
-#ifdef CONFIG_HAX
-void qemu_notify_hax_event(void)
-{
-   CPUArchState *env = NULL;
-
-   if (hax_enabled()) {
-       for (env = first_cpu; env != NULL; env = env->next_cpu) {
-           hax_raise_event(env);
-       }
-   }
-}
-#endif
diff --git a/exec.c b/exec.c
index fb4b7b7..82c40d6 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -31,7 +31,7 @@
 #include "hw/qdev.h"
 #include "qemu/osdep.h"
 #include "sysemu/kvm.h"
-#include "hax.h"
+#include "sysemu/hax.h"
 #include "hw/xen/xen.h"
 #include "qemu/timer.h"
 #include "qemu/config-file.h"
index c939f45..456caa8 100644 (file)
@@ -18,7 +18,7 @@
  *
  */
 
-#include "hax.h"
+#include "sysemu/hax.h"
 
 int hax_sync_vcpus(void)
 {
@@ -44,8 +44,3 @@ int hax_enabled(void)
 {
    return 0;
 }
-
-void qemu_notify_hax_event(void)
-{
-   return;
-}
index 6014714..6f0200a 100644 (file)
@@ -101,16 +101,6 @@ AioContext *qemu_get_aio_context(void);
  */
 void qemu_notify_event(void);
 
-// TODO: Mark HAX related code...
-#ifdef CONFIG_HAX_BACKEND
-void qemu_notify_hax_event(void);
-#else
-static inline void qemu_notify_hax_event(void)
-{
-}
-#endif
-//
-
 #ifdef _WIN32
 /* return TRUE if no sleep should be done afterwards */
 typedef int PollingFunc(void *opaque);
similarity index 94%
rename from hax.h
rename to include/sysemu/hax.h
index 911898c..2def89a 100644 (file)
--- a/hax.h
@@ -33,10 +33,10 @@ int hax_sync_vcpus(void);
 
 #ifdef CONFIG_HAX
 //#include "cpu.h"
-#include "kvm.h"
+//#include "kvm.h"
 #include "hw/hw.h"
-#include "bitops.h"
-#include "memory.h"
+#include "qemu/bitops.h"
+#include "exec/memory.h"
 
 int hax_init_vcpu(CPUArchState *env);
 int hax_vcpu_exec(CPUArchState *env);
@@ -52,7 +52,7 @@ int hax_stop_translate(CPUArchState *env);
 int hax_arch_get_registers(CPUArchState *env);
 int hax_vcpu_destroy(CPUArchState *env);
 void hax_raise_event(CPUArchState *env);
-int need_handle_intr_request(CPUArchState *env);
+//int need_handle_intr_request(CPUState *env);
 int hax_handle_io(CPUArchState *env, uint32_t df, uint16_t port, int direction,
                 int size, int count, void *buffer);
 void hax_reset_vcpu_state(void *opaque);
index 7f81ac3..b2db5dc 100644 (file)
@@ -28,6 +28,8 @@
 #include "qemu/main-loop.h"
 #include "block/aio.h"
 
+#include "sysemu/hax.h"
+
 #ifndef _WIN32
 
 #include "qemu/compatfd.h"
@@ -114,14 +116,27 @@ AioContext *qemu_get_aio_context(void)
     return qemu_aio_context;
 }
 
+#ifdef CONFIG_HAX
+static void qemu_notify_hax_event(void)
+{
+   CPUArchState *env = NULL;
+
+   if (hax_enabled()) {
+       for (env = first_cpu; env != NULL; env = env->next_cpu) {
+           hax_raise_event(env);
+       }
+   }
+}
+#endif
+
 void qemu_notify_event(void)
 {
     if (!qemu_aio_context) {
         return;
     }
-    // TODO: Mark HAX related code...
+#ifdef CONFIG_HAX
     qemu_notify_hax_event();
-    //
+#endif
     aio_notify(qemu_aio_context);
 }
 
index a939f1d..7ef9063 100644 (file)
@@ -279,15 +279,16 @@ int hax_vcpu_destroy(CPUArchState *env)
 int hax_init_vcpu(CPUArchState *env)
 {
     int ret;
+    CPUState *cpu = ENV_GET_CPU(env);
 
-    ret = hax_vcpu_create(env->cpu_index);
+    ret = hax_vcpu_create(cpu->cpu_index);
     if (ret < 0)
     {
         dprint("Failed to create HAX vcpu\n");
         exit(-1);
     }
 
-    env->hax_vcpu = hax_global.vm->vcpus[env->cpu_index];
+    env->hax_vcpu = hax_global.vm->vcpus[cpu->cpu_index];
     env->hax_vcpu->emulation_state = HAX_EMULATE_STATE_INITIAL;
     env->hax_vcpu_dirty = 1;
     qemu_register_reset(hax_reset_vcpu_state, env);
@@ -431,7 +432,8 @@ static MemoryListener hax_memory_listener = {
 
 static void hax_handle_interrupt(CPUArchState *env, int mask)
 {
-    env->interrupt_request |= mask;
+    CPUState *cpu = ENV_GET_CPU(env);
+    cpu->interrupt_request |= mask;
 
     if (!qemu_cpu_is_self(env)) {
         qemu_cpu_kick(env);
@@ -578,17 +580,18 @@ static int hax_vcpu_interrupt(CPUArchState *env)
 {
     struct hax_vcpu_state *vcpu = env->hax_vcpu;
     struct hax_tunnel *ht = vcpu->tunnel;
+    CPUState *cpu = ENV_GET_CPU(env);
 
     /*
      * Try to inject an interrupt if the guest can accept it
      * Unlike KVM, HAX kernel check for the eflags, instead of qemu
      */
     if (ht->ready_for_interrupt_injection &&
-      (env->interrupt_request & CPU_INTERRUPT_HARD))
+      (cpu->interrupt_request & CPU_INTERRUPT_HARD))
     {
         int irq;
 
-        env->interrupt_request &= ~CPU_INTERRUPT_HARD;
+        cpu->interrupt_request &= ~CPU_INTERRUPT_HARD;
         irq = cpu_get_pic_interrupt(env);
         if (irq >= 0) {
             hax_inject_interrupt(env, irq);
@@ -599,7 +602,7 @@ static int hax_vcpu_interrupt(CPUArchState *env)
      * interrupt, request an interrupt window exit.  This will
      * cause a return to userspace as soon as the guest is ready to
      * receive interrupts. */
-    if ((env->interrupt_request & CPU_INTERRUPT_HARD))
+    if ((cpu->interrupt_request & CPU_INTERRUPT_HARD))
         ht->request_interrupt_window = 1;
     else
         ht->request_interrupt_window = 0;
@@ -630,6 +633,7 @@ static int hax_vcpu_hax_exec(CPUArchState *env)
     int ret = 0;
     struct hax_vcpu_state *vcpu = env->hax_vcpu;
     struct hax_tunnel *ht = vcpu->tunnel;
+    CPUState *cpu = ENV_GET_CPU(env);
 
     if (hax_vcpu_emulation_mode(env))
     {
@@ -644,7 +648,7 @@ static int hax_vcpu_hax_exec(CPUArchState *env)
         int hax_ret;
 
        
-        if (env->exit_request) {
+        if (cpu->exit_request) {
             ret = HAX_EMUL_EXITLOOP ;
             break;
         }
@@ -702,11 +706,11 @@ static int hax_vcpu_hax_exec(CPUArchState *env)
                 ret = HAX_EMUL_EXITLOOP;
                 break;
             case HAX_EXIT_HLT:
-                if (!(env->interrupt_request & CPU_INTERRUPT_HARD) &&
-                  !(env->interrupt_request & CPU_INTERRUPT_NMI)) {
+                if (!(cpu->interrupt_request & CPU_INTERRUPT_HARD) &&
+                  !(cpu->interrupt_request & CPU_INTERRUPT_NMI)) {
                     /* hlt instruction with interrupt disabled is shutdown */
                     env->eflags |= IF_MASK;
-                    env->halted = 1;
+                    cpu->halted = 1;
                     env->exception_index = EXCP_HLT;
                     ret = HAX_EMUL_HLT;
                 }
@@ -725,8 +729,8 @@ static int hax_vcpu_hax_exec(CPUArchState *env)
         }
     }while (!ret);
 
-    if (env->exit_request) {
-        env->exit_request = 0;
+    if (cpu->exit_request) {
+        cpu->exit_request = 0;
         env->exception_index = EXCP_INTERRUPT;
     }
     return ret;
index ac69e95..655e8bd 100644 (file)
@@ -13,7 +13,7 @@
 #define _HAX_I386_H
 
 //#include "android/utils/debug.h"
-#include "hax.h"
+#include "sysemu/hax.h"
 
 #ifdef CONFIG_DARWIN
 typedef int hax_fd;
index 0c8e261..8312cd2 100644 (file)
@@ -101,7 +101,7 @@ int hax_set_phys_mem(MemoryRegionSection *section)
 {
     struct hax_set_ram_info info, *pinfo = &info;
     MemoryRegion *mr = section->mr;
-    target_phys_addr_t start_addr = section->offset_within_address_space;
+    hwaddr start_addr = section->offset_within_address_space;
     ram_addr_t size = section->size;
     HANDLE hDeviceVM;
     DWORD dSize = 0;
index f165937..2215a46 100644 (file)
@@ -31,7 +31,7 @@
 #include "helper.h"
 #define GEN_HELPER 1
 #include "helper.h"
-#include "hax.h"
+#include "sysemu/hax.h"
 
 #define PREFIX_REPZ   0x01
 #define PREFIX_REPNZ  0x02
diff --git a/vl.c b/vl.c
index 0adbdd1..2f39c0d 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -154,7 +154,7 @@ int qemu_main(int argc, char **argv, char **envp);
 #include "audio/audio.h"
 #include "migration/migration.h"
 #include "sysemu/kvm.h"
-#include "hax.h"
+#include "sysemu/hax.h"
 #include "qapi/qmp/qjson.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"