From: SeokYeon Hwang Date: Fri, 12 Jul 2013 06:36:03 +0000 (+0900) Subject: Refactor some hax related codes. X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~900^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4cda23268f785945fd3405c55d11e7812da65648;p=sdk%2Femulator%2Fqemu.git Refactor some hax related codes. Change-Id: I84842e268491dd3e090d9d1c111643c7f10923d0 Signed-off-by: SeokYeon Hwang --- diff --git a/cpu-exec.c b/cpu-exec.c index 7d36d963a4..0871c5c04c 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -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 3592ba2063..c08a21ba31 100644 --- 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 fb4b7b725a..82c40d6ff6 100644 --- 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" diff --git a/hax-stub.c b/hax-stub.c index c939f452fe..456caa8ef7 100644 --- a/hax-stub.c +++ b/hax-stub.c @@ -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; -} diff --git a/hax.h b/hax.h deleted file mode 100644 index 911898cb62..0000000000 --- a/hax.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * QEMU HAXM support - * - * Copyright IBM, Corp. 2008 - * - * Authors: - * Anthony Liguori - * - * Copyright (c) 2011 Intel Corporation - * Written by: - * Jiang Yunhong - * Xin Xiaohui - * Zhang Xiantao - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * - */ - -/* header to be included in non-HAX-specific code */ -#ifndef _HAX_H -#define _HAX_H - -#include "config-host.h" -#include "qemu-common.h" - -#define dprint printf -#ifdef CONFIG_HAX_BACKEND -int hax_enabled(void); -void hax_disable(int disable); -int hax_pre_init(uint64_t ram_size); -int hax_accel_init(void); -int hax_sync_vcpus(void); - -#ifdef CONFIG_HAX -//#include "cpu.h" -#include "kvm.h" -#include "hw/hw.h" -#include "bitops.h" -#include "memory.h" - -int hax_init_vcpu(CPUArchState *env); -int hax_vcpu_exec(CPUArchState *env); -void hax_vcpu_sync_state(CPUArchState *env, int modified); -//extern void hax_cpu_synchronize_state(CPUArchState *env); -//extern void hax_cpu_synchronize_post_reset(CPUArchState *env); -//extern void hax_cpu_synchronize_post_init(CPUArchState *env); -int hax_populate_ram(uint64_t va, uint32_t size); -int hax_set_phys_mem(MemoryRegionSection *section); -int hax_vcpu_emulation_mode(CPUArchState *env); -int hax_stop_emulation(CPUArchState *env); -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 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); -#include "target-i386/hax-interface.h" -#include "target-i386/hax-i386.h" -#endif - -#else - -#define hax_enabled() (0) -#define hax_sync_vcpus() -#define hax_accel_init() (0) -#define hax_pre_init(x) - -#endif - -#endif diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index 6014714856..6f0200a7ac 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -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); diff --git a/include/sysemu/hax.h b/include/sysemu/hax.h new file mode 100644 index 0000000000..2def89a5e5 --- /dev/null +++ b/include/sysemu/hax.h @@ -0,0 +1,72 @@ +/* + * QEMU HAXM support + * + * Copyright IBM, Corp. 2008 + * + * Authors: + * Anthony Liguori + * + * Copyright (c) 2011 Intel Corporation + * Written by: + * Jiang Yunhong + * Xin Xiaohui + * Zhang Xiantao + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * + */ + +/* header to be included in non-HAX-specific code */ +#ifndef _HAX_H +#define _HAX_H + +#include "config-host.h" +#include "qemu-common.h" + +#define dprint printf +#ifdef CONFIG_HAX_BACKEND +int hax_enabled(void); +void hax_disable(int disable); +int hax_pre_init(uint64_t ram_size); +int hax_accel_init(void); +int hax_sync_vcpus(void); + +#ifdef CONFIG_HAX +//#include "cpu.h" +//#include "kvm.h" +#include "hw/hw.h" +#include "qemu/bitops.h" +#include "exec/memory.h" + +int hax_init_vcpu(CPUArchState *env); +int hax_vcpu_exec(CPUArchState *env); +void hax_vcpu_sync_state(CPUArchState *env, int modified); +//extern void hax_cpu_synchronize_state(CPUArchState *env); +//extern void hax_cpu_synchronize_post_reset(CPUArchState *env); +//extern void hax_cpu_synchronize_post_init(CPUArchState *env); +int hax_populate_ram(uint64_t va, uint32_t size); +int hax_set_phys_mem(MemoryRegionSection *section); +int hax_vcpu_emulation_mode(CPUArchState *env); +int hax_stop_emulation(CPUArchState *env); +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(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); +#include "target-i386/hax-interface.h" +#include "target-i386/hax-i386.h" +#endif + +#else + +#define hax_enabled() (0) +#define hax_sync_vcpus() +#define hax_accel_init() (0) +#define hax_pre_init(x) + +#endif + +#endif diff --git a/main-loop.c b/main-loop.c index 7f81ac3580..b2db5dc865 100644 --- a/main-loop.c +++ b/main-loop.c @@ -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); } diff --git a/target-i386/hax-all.c b/target-i386/hax-all.c index a939f1d66f..7ef9063c99 100644 --- a/target-i386/hax-all.c +++ b/target-i386/hax-all.c @@ -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; diff --git a/target-i386/hax-i386.h b/target-i386/hax-i386.h index ac69e956b9..655e8bd47a 100644 --- a/target-i386/hax-i386.h +++ b/target-i386/hax-i386.h @@ -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; diff --git a/target-i386/hax-windows.c b/target-i386/hax-windows.c index 0c8e261253..8312cd2a96 100644 --- a/target-i386/hax-windows.c +++ b/target-i386/hax-windows.c @@ -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; diff --git a/target-i386/translate.c b/target-i386/translate.c index f165937a37..2215a460ed 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -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 0adbdd1022..2f39c0d2c8 100644 --- 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"