Changed Haxm global function interface from CPUArchState to CPUState.
Removed Haxm code from kvm.h and cpu.h.
Removed CONFIG_HAX_BACKEND.
Additional modification:
Fixed Compilation error on linux.
Removed warnings.
Using "hax-stub.c" if CONFIG_HAX is not defined.
Change-Id: I52ab99f1650bdd81b6c0efa61e4f9f3c4d766512
Signed-off-by: Yucheng Yu <yu-cheng.yu@intel.com>
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
# HAX support
ifdef CONFIG_WIN32
obj-$(CONFIG_HAX) += target-i386/hax-all.o target-i386/hax-windows.o
-obj-$(CONFIG_NO_HAX) += hax-stub.o
endif
ifdef CONFIG_DARWIN
obj-$(CONFIG_HAX) += target-i386/hax-all.o target-i386/hax-darwin.o
-obj-$(CONFIG_NO_HAX) += hax-stub.o
endif
+obj-$(call lnot,$(CONFIG_HAX)) += hax-stub.o
# Hardware support
ifeq ($(TARGET_NAME), sparc64)
if test "$trace_default" = "yes"; then
echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak
fi
-if test "$hax" = "yes" ; then
- if test "$mingw32" = "yes" ; then
- echo "CONFIG_HAX_BACKEND=y" >> $config_host_mak
- elif test "$darwin" = "yes" ; then
- echo "CONFIG_HAX_BACKEND=y" >> $config_host_mak
- else
- hax="no"
- fi
-fi
if test "$rdma" = "yes" ; then
echo "CONFIG_RDMA=y" >> $config_host_mak
static int need_handle_intr_request(CPUState *cpu)
{
#ifdef CONFIG_HAX
- CPUArchState *env = cpu->env_ptr;
- if (!hax_enabled() || hax_vcpu_emulation_mode(env))
+ if (!hax_enabled() || hax_vcpu_emulation_mode(cpu))
return cpu->interrupt_request;
return 0;
#else
}
#ifdef CONFIG_HAX
- if (hax_enabled() && !hax_vcpu_exec(env))
+ if (hax_enabled() && !hax_vcpu_exec(cpu))
longjmp(cpu->jmp_env, 1);
#endif
}
cpu->current_tb = NULL;
#ifdef CONFIG_HAX
- if (hax_enabled() && hax_stop_emulation(env))
+ if (hax_enabled() && hax_stop_emulation(cpu))
cpu_loop_exit(cpu);
#endif
/* reset soft MMU for next block (it can currently
CPU_FOREACH(cpu) {
cpu_synchronize_post_reset(cpu);
+#ifdef CONFIG_HAX
+ if (hax_enabled())
+ hax_cpu_synchronize_post_reset(cpu);
+#endif
}
}
CPU_FOREACH(cpu) {
cpu_synchronize_post_init(cpu);
+#ifdef CONFIG_HAX
+ if (hax_enabled())
+ hax_cpu_synchronize_post_init(cpu);
+#endif
}
}
}
}
+#ifdef CONFIG_HAX
static void qemu_hax_wait_io_event(CPUState *cpu)
{
while (cpu_thread_is_idle(cpu)) {
qemu_wait_io_event_common(cpu);
}
+#endif
static void qemu_kvm_wait_io_event(CPUState *cpu)
{
return NULL;
}
+#ifdef CONFIG_HAX
static void *qemu_hax_cpu_thread_fn(void *arg)
{
CPUState *cpu = arg;
cpu->created = true;
current_cpu = cpu;
- hax_init_vcpu(cpu->env_ptr);
+ hax_init_vcpu(cpu);
qemu_cond_signal(&qemu_cpu_cond);
while (1) {
if (cpu_can_run(cpu)) {
- r = hax_smp_cpu_exec(cpu->env_ptr);
+ r = hax_smp_cpu_exec(cpu);
if (r == EXCP_DEBUG) {
cpu_handle_guest_debug(cpu);
}
}
return NULL;
}
+#endif
static void qemu_cpu_kick_thread(CPUState *cpu)
{
static void qemu_tcg_init_vcpu(CPUState *cpu)
{
#ifdef CONFIG_HAX
- if (hax_enabled())
- hax_init_vcpu(cpu->env_ptr);
+ if (hax_enabled())
+ hax_init_vcpu(cpu);
#endif
char thread_name[VCPU_THREAD_NAME_SIZE];
}
}
+#ifdef CONFIG_HAX
static void qemu_hax_start_vcpu(CPUState *cpu)
{
char thread_name[VCPU_THREAD_NAME_SIZE];
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
}
}
+#endif
static void qemu_kvm_start_vcpu(CPUState *cpu)
{
cpu->stopped = true;
if (kvm_enabled()) {
qemu_kvm_start_vcpu(cpu);
+#ifdef CONFIG_HAX
} else if (hax_enabled()) {
qemu_hax_start_vcpu(cpu);
+#endif
} else if (tcg_enabled()) {
qemu_tcg_init_vcpu(cpu);
} else {
*/
if (hax_enabled()) {
int ret;
- ret = hax_populate_ram((uint64_t)new_block->host, size);
+ ret = hax_populate_ram((uint64_t)(uintptr_t)new_block->host, size);
if (ret < 0) {
fprintf(stderr, "Hax failed to populate ram\n");
exit(-1);
#include "sysemu/sysemu.h"
#include "hw/acpi/acpi.h"
#include "sysemu/kvm.h"
+#include "sysemu/hax.h"
#include "exec/address-spaces.h"
#include "hw/i386/ich9.h"
VMSTATE_END_OF_LIST()
}
};
-extern int hax_enabled(void);
+
static void pm_reset(void *opaque)
{
ICH9LPCPMRegs *pm = opaque;
#include "hw/pci/pci.h"
#include "hw/acpi/acpi.h"
#include "sysemu/sysemu.h"
+#include "sysemu/hax.h"
#include "qemu/range.h"
#include "exec/ioport.h"
#include "hw/nvram/fw_cfg.h"
VMSTATE_END_OF_LIST()
}
};
-extern int hax_enabled(void);
+
static void piix4_reset(void *opaque)
{
PIIX4PMState *s = opaque;
#include "config-host.h"
#include "qemu-common.h"
-#define dprint printf
-#ifdef CONFIG_HAX_BACKEND
+
+// This needs to be fixed for vl.c, ich9.c, piix4.c.
+// Those files do not include config.h and will not have CONFIG_HAX defined.
+
int hax_enabled(void);
void hax_disable(int disable);
int hax_pre_init(uint64_t ram_size);
int hax_sync_vcpus(void);
#ifdef CONFIG_HAX
-//#include "cpu.h"
-//#include "kvm.h"
+
+#define dprint printf
+
#include "hw/hw.h"
#include "qemu/bitops.h"
#include "exec/memory.h"
-
-int hax_init_vcpu(CPUArchState *env);
-int hax_vcpu_exec(CPUArchState *env);
-int hax_smp_cpu_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_init_vcpu(CPUState *cpu);
+int hax_vcpu_exec(CPUState *cpu);
+int hax_smp_cpu_exec(CPUState *cpu);
+void hax_cpu_synchronize_post_reset(CPUState *cpu);
+void hax_cpu_synchronize_post_init(CPUState *cpu);
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);
+int hax_vcpu_emulation_mode(CPUState *cpu);
+int hax_stop_emulation(CPUState *cpu);
+int hax_stop_translate(CPUState *cpu);
+int hax_vcpu_destroy(CPUState *cpu);
+void hax_raise_event(CPUState *cpu);
void hax_reset_vcpu_state(void *opaque);
#include "target-i386/hax-interface.h"
#include "target-i386/hax-i386.h"
-int hax_handle_fastmmio(CPUArchState *env, struct hax_fastmmio *hft);
-#endif
-
-#else
-
-#define hax_enabled() (0)
-#define hax_sync_vcpus()
-#define hax_accel_init() (0)
-#define hax_pre_init(x)
#endif
-#endif
+#endif // _HAX_H
void kvm_cpu_synchronize_state(CPUState *cpu);
void kvm_cpu_synchronize_post_reset(CPUState *cpu);
void kvm_cpu_synchronize_post_init(CPUState *cpu);
-#ifdef CONFIG_HAX
-void hax_cpu_synchronize_post_reset(CPUArchState *env);
-void hax_cpu_synchronize_post_init(CPUArchState *env);
-#endif
/* generic hooks - to be moved/refactored once there are more users */
if (kvm_enabled()) {
kvm_cpu_synchronize_post_reset(cpu);
}
-#ifdef CONFIG_HAX
- CPUArchState *env = cpu->env_ptr;
- hax_cpu_synchronize_post_reset(env);
-#endif
}
static inline void cpu_synchronize_post_init(CPUState *cpu)
if (kvm_enabled()) {
kvm_cpu_synchronize_post_init(cpu);
}
-#ifdef CONFIG_HAX
- CPUArchState *env = cpu->env_ptr;
- hax_cpu_synchronize_post_init(env);
-#endif
}
int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
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;
}
-#ifdef CONFIG_HAX
- qemu_notify_hax_event();
-#endif
aio_notify(qemu_aio_context);
}
#define HAX_EMULATE_STATE_NONE 0x3
#define HAX_EMULATE_STATE_INITIAL 0x4
+static void hax_vcpu_sync_state(CPUArchState *env, int modified);
+static int hax_arch_get_registers(CPUArchState *env);
+static int hax_handle_io(CPUArchState *env, uint32_t df, uint16_t port, int dir, int size, int cnt, void *buf);
+static int hax_handle_fastmmio(CPUArchState *env, struct hax_fastmmio *hft);
+
struct hax_state hax_global;
int ret_hax_init = 0;
static int hax_disabled = 1;
}
/* Currently non-PG modes are emulated by QEMU */
-int hax_vcpu_emulation_mode(CPUArchState *env)
+int hax_vcpu_emulation_mode(CPUState *cpu)
{
// Tcg is single-thread, so we need haxm to run smp.
// If the host has no UG, we always run tcg.
break;
case HAX_EMULATE_STATE_INITIAL:
case HAX_EMULATE_STATE_REAL:
- if (!hax_vcpu_emulation_mode(env))
+ if (!hax_vcpu_emulation_mode(cpu))
return 1;
break;
default:
return 0;
}
-int hax_stop_emulation(CPUArchState *env)
+int hax_stop_emulation(CPUState *cpu)
{
- CPUState *cpu = ENV_GET_CPU(env);
+ CPUArchState *env = (CPUArchState *)(cpu->env_ptr);
+
if (hax_stop_tbloop(env))
{
cpu->hax_vcpu->emulation_state = HAX_EMULATE_STATE_NONE;
return 0;
}
-int hax_stop_translate(CPUArchState *env)
+int hax_stop_translate(CPUState *cpu)
{
- struct hax_vcpu_state *vstate;
+ struct hax_vcpu_state *vstate = cpu->hax_vcpu;
- vstate = ENV_GET_CPU(env)->hax_vcpu;
assert(vstate->emulation_state);
if (vstate->emulation_state == HAX_EMULATE_STATE_MMIO )
return 1;
return -1;
}
-int hax_vcpu_destroy(CPUArchState *env)
+int hax_vcpu_destroy(CPUState *cpu)
{
- struct hax_vcpu_state *vcpu = ENV_GET_CPU(env)->hax_vcpu;
+ struct hax_vcpu_state *vcpu = cpu->hax_vcpu;
if (!hax_global.vm)
{
return 0;
}
-int hax_init_vcpu(CPUArchState *env)
+int hax_init_vcpu(CPUState *cpu)
{
int ret;
- CPUState *cpu = ENV_GET_CPU(env);
ret = hax_vcpu_create(cpu->cpu_index);
if (ret < 0)
cpu->hax_vcpu = hax_global.vm->vcpus[cpu->cpu_index];
cpu->hax_vcpu->emulation_state = HAX_EMULATE_STATE_INITIAL;
cpu->hax_vcpu_dirty = 1;
- qemu_register_reset(hax_reset_vcpu_state, env);
+ qemu_register_reset(hax_reset_vcpu_state, (CPUArchState *)(cpu->env_ptr));
return ret;
}
}
}
-int hax_handle_fastmmio(CPUArchState *env, struct hax_fastmmio *hft)
+static int hax_handle_fastmmio(CPUArchState *env, struct hax_fastmmio *hft)
{
uint64_t buf = 0;
/*
return 0;
}
-int hax_handle_io(CPUArchState *env, uint32_t df, uint16_t port, int direction,
+static int hax_handle_io(CPUArchState *env, uint32_t df, uint16_t port, int direction,
int size, int count, void *buffer)
{
uint8_t *ptr;
return 0;
}
-void hax_raise_event(CPUArchState *env)
+void hax_raise_event(CPUState *cpu)
{
- struct hax_vcpu_state *vcpu = ENV_GET_CPU(env)->hax_vcpu;
+ struct hax_vcpu_state *vcpu = cpu->hax_vcpu;
if (!vcpu)
return;
struct hax_vcpu_state *vcpu = cpu->hax_vcpu;
struct hax_tunnel *ht = vcpu->tunnel;
- if (hax_vcpu_emulation_mode(env))
+ if (hax_vcpu_emulation_mode(cpu))
{
dprint("Trying to vcpu execute at eip:%lx\n", env->eip);
return HAX_EMUL_EXITLOOP;
hax_vcpu_sync_state(env, 1);
}
- //hax_cpu_synchronize_state(env);
+ //hax_cpu_synchronize_state(cpu);
do {
int hax_ret;
}
#if 0
- if (env->hax_vcpu_dirty) {
+ if (cpu->hax_vcpu_dirty) {
hax_vcpu_sync_state(env, 1);
- env->hax_vcpu_dirty = 0;
+ cpu->hax_vcpu_dirty = 0;
}
#endif
}
}
-void hax_cpu_synchronize_state(CPUState *cpu)
+static void hax_cpu_synchronize_state(CPUState *cpu)
{
if (!cpu->hax_vcpu_dirty) {
run_on_cpu(cpu, do_hax_cpu_synchronize_state, cpu);
}
#endif
-void hax_cpu_synchronize_post_reset(CPUArchState *env)
+void hax_cpu_synchronize_post_reset(CPUState *cpu)
{
+ CPUArchState *env = (CPUArchState *)(cpu->env_ptr);
hax_vcpu_sync_state(env, 1);
- ENV_GET_CPU(env)->hax_vcpu_dirty = 0;
+ cpu->hax_vcpu_dirty = 0;
}
-void hax_cpu_synchronize_post_init(CPUArchState *env)
+void hax_cpu_synchronize_post_init(CPUState *cpu)
{
+ CPUArchState *env = (CPUArchState *)(cpu->env_ptr);
hax_vcpu_sync_state(env, 1);
- ENV_GET_CPU(env)->hax_vcpu_dirty = 0;
+ cpu->hax_vcpu_dirty = 0;
}
/*
* return 1 when need emulate, 0 when need exit loop
*/
-int hax_vcpu_exec(CPUArchState *env)
+int hax_vcpu_exec(CPUState *cpu)
{
int next = 0, ret = 0;
struct hax_vcpu_state *vcpu;
- CPUState *cpu = ENV_GET_CPU(env);
+ CPUArchState *env = (CPUArchState *)(cpu->env_ptr);
if (cpu->hax_vcpu->emulation_state != HAX_EMULATE_STATE_NONE)
return 1;
return ret;
}
-int hax_smp_cpu_exec(CPUArchState *env)
+int hax_smp_cpu_exec(CPUState *cpu)
{
- CPUState *cpu = ENV_GET_CPU(env);
+ CPUArchState *env = (CPUArchState *)(cpu->env_ptr);
int why;
int ret;
return hax_sync_fpu(env, &fpu, 1);
}
-int hax_arch_get_registers(CPUArchState *env)
+static int hax_arch_get_registers(CPUArchState *env)
{
int ret;
return 0;
}
-void hax_vcpu_sync_state(CPUArchState *env, int modified)
+static void hax_vcpu_sync_state(CPUArchState *env, int modified)
{
if (hax_enabled()) {
if (modified)
info.pa_start = start_addr;
info.size = size;
- info.va = (uint64_t)(memory_region_get_ram_ptr(mr) + section->offset_within_region);
+ info.va = (uint64_t)(intptr_t)(memory_region_get_ram_ptr(mr) + section->offset_within_region);
info.flags = memory_region_is_rom(mr) ? 1 : 0;
ret = ioctl(hax_global.vm->fd, HAX_VM_IOCTL_SET_RAM, pinfo);
return ret;
}
- vcpu->tunnel = (struct hax_tunnel *)(info.va);
- vcpu->iobuf = (unsigned char *)(info.io_va);
+ vcpu->tunnel = (struct hax_tunnel *)(intptr_t)(info.va);
+ vcpu->iobuf = (unsigned char *)(intptr_t)(info.io_va);
return 0;
}
info.pa_start = start_addr;
info.size = size;
- info.va = (uint64_t)(memory_region_get_ram_ptr(mr) +
+ info.va = (uint64_t)(intptr_t)(memory_region_get_ram_ptr(mr) +
section->offset_within_region);
info.flags = memory_region_is_rom(mr) ? 1 : 0;
ret = -EINVAL;
return ret;
}
- vcpu->tunnel = (struct hax_tunnel *)(info.va);
- vcpu->iobuf = (unsigned char *)(info.io_va);
+ vcpu->tunnel = (struct hax_tunnel *)(intptr_t)(info.va);
+ vcpu->iobuf = (unsigned char *)(intptr_t)(info.io_va);
return 0;
}
pc_ptr = disas_insn(env, dc, pc_ptr);
num_insns++;
#ifdef CONFIG_HAX
- if (hax_enabled() && hax_stop_translate(env))
+ if (hax_enabled() && hax_stop_translate(cs))
{
gen_jmp_im(pc_ptr - dc->cs_base);
gen_eob(dc);
}
break;
case QEMU_OPTION_enable_hax:
-#ifdef CONFIG_HAX_BACKEND
olist = qemu_find_opts("machine");
//qemu_opts_reset(olist);
hax_disable(0);
//qemu_opts_parse(olist, "accel=hax", 0);
-#else
- fprintf(stderr,
- "HAX support is disabled, ignoring -enable-hax\n");
-#endif
break;
case QEMU_OPTION_add_fd:
#ifndef _WIN32