hax: CPUOldState -> CPUState
Change-Id: I4352da69e3a4e064a9fbaebee1dcb717cbb329b7
diff --git a/cpu-exec.c b/cpu-exec.c
index d963f8f..9bc29d3 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -224,7 +224,7 @@
{
CPUState *cpu = ENV_GET_CPU(env);
#ifdef CONFIG_HAX
- if (!hax_enabled() || hax_vcpu_emulation_mode(env))
+ if (!hax_enabled() || hax_vcpu_emulation_mode(cpu))
return cpu->interrupt_request;
return 0;
#else
@@ -314,12 +314,12 @@
}
#ifdef CONFIG_HAX
- if (hax_enabled() && !hax_vcpu_exec(env))
+ if (hax_enabled() && !hax_vcpu_exec(cpu))
longjmp(env->jmp_env, 1);
#endif
if (kvm_enabled()) {
- kvm_cpu_exec(ENV_GET_CPU(env));
+ kvm_cpu_exec(cpu);
longjmp(env->jmp_env, 1);
}
@@ -624,7 +624,7 @@
}
env->current_tb = NULL;
#ifdef CONFIG_HAX
- if (hax_enabled() && hax_stop_emulation(env))
+ if (hax_enabled() && hax_stop_emulation(cpu))
cpu_loop_exit(env);
#endif
/* reset soft MMU for next block (it can currently
diff --git a/cpus.c b/cpus.c
index 97a19ed..984bd43 100644
--- a/cpus.c
+++ b/cpus.c
@@ -150,7 +150,7 @@
*/
#ifdef CONFIG_HAX
if (hax_enabled())
- hax_raise_event(env);
+ hax_raise_event(cpu);
} else {
#ifdef _WIN32
if(hax_enabled())
diff --git a/include/exec/hax.h b/include/exec/hax.h
index c8cd9a2..8db22ee 100644
--- a/include/exec/hax.h
+++ b/include/exec/hax.h
@@ -13,21 +13,21 @@
int hax_enabled(void);
int hax_set_ramsize(uint64_t ramsize);
int hax_init(int smp_cpus);
-int hax_init_vcpu(CPUOldState *env);
+int hax_init_vcpu(CPUState *cpu);
/* Execute vcpu in non-root mode */
-int hax_vcpu_exec(CPUOldState *env);
+int hax_vcpu_exec(CPUState *cpu);
/* Sync vcpu state with HAX driver */
int hax_sync_vcpus(void);
-void hax_vcpu_sync_state(CPUOldState *env, int modified);
+void hax_vcpu_sync_state(CPUState *cpu, int modified);
int hax_populate_ram(uint64_t va, uint32_t size);
int hax_set_phys_mem(hwaddr start_addr,
ram_addr_t size, ram_addr_t phys_offset);
/* Check if QEMU need emulate guest execution */
-int hax_vcpu_emulation_mode(CPUOldState *env);
-int hax_stop_emulation(CPUOldState *env);
-int hax_stop_translate(CPUOldState *env);
-int hax_arch_get_registers(CPUOldState *env);
-void hax_raise_event(CPUOldState *env);
+int hax_vcpu_emulation_mode(CPUState *cpu);
+int hax_stop_emulation(CPUState *cpu);
+int hax_stop_translate(CPUState *cpu);
+int hax_arch_get_registers(CPUState *cpu);
+void hax_raise_event(CPUState *cpu);
void hax_reset_vcpu_state(void *opaque);
#include "target-i386/hax-interface.h"
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index fb7421b..f86026a 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -138,7 +138,7 @@
/* generic hooks - to be moved/refactored once there are more users */
#ifdef CONFIG_HAX
-void hax_vcpu_sync_state(CPUOldState *env, int modified);
+void hax_vcpu_sync_state(CPUState *cpu, int modified);
#endif
static inline void cpu_synchronize_state(CPUState *cpu, int modified)
{
@@ -149,7 +149,7 @@
kvm_arch_get_registers(cpu);
}
#ifdef CONFIG_HAX
- hax_vcpu_sync_state(cpu->env_ptr, modified);
+ hax_vcpu_sync_state(cpu, modified);
#endif
}
diff --git a/target-i386/hax-all.c b/target-i386/hax-all.c
index dd26d07..c8bb7c4 100644
--- a/target-i386/hax-all.c
+++ b/target-i386/hax-all.c
@@ -40,8 +40,9 @@
}
/* Currently non-PG modes are emulated by QEMU */
-int hax_vcpu_emulation_mode(CPUX86State *env)
+int hax_vcpu_emulation_mode(CPUState *cpu)
{
+ CPUX86State *env = cpu->env_ptr;
return !(env->cr[0] & CR0_PG_MASK);
}
@@ -51,7 +52,7 @@
tlb_flush(env, 1);
tb_flush(env);
/* Sync the vcpu state from hax kernel module */
- hax_vcpu_sync_state(env, 0);
+ hax_vcpu_sync_state(ENV_GET_CPU(env), 0);
return 0;
}
@@ -59,49 +60,47 @@
* Check whether to break the translation block loop
* Break tbloop after one MMIO emulation, or after finish emulation mode
*/
-static int hax_stop_tbloop(CPUX86State *env)
+static int hax_stop_tbloop(CPUState *cpu)
{
- CPUState *cpu = ENV_GET_CPU(env);
-
switch (cpu->hax_vcpu->emulation_state)
{
case HAX_EMULATE_STATE_MMIO:
return 1;
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:
dprint("Invalid emulation state in hax_sto_tbloop state %x\n",
- cpu->hax_vcpu->emulation_state);
+ cpu->hax_vcpu->emulation_state);
break;
}
return 0;
}
-int hax_stop_emulation(CPUX86State *env)
+int hax_stop_emulation(CPUState *cpu)
{
- if (hax_stop_tbloop(env))
+ if (hax_stop_tbloop(cpu))
{
- ENV_GET_CPU(env)->hax_vcpu->emulation_state = HAX_EMULATE_STATE_NONE;
+ cpu->hax_vcpu->emulation_state = HAX_EMULATE_STATE_NONE;
/*
* QEMU emulation changes vcpu state,
* Sync the vcpu state to HAX kernel module
*/
- hax_vcpu_sync_state(env, 1);
+ hax_vcpu_sync_state(cpu, 1);
return 1;
}
return 0;
}
-int hax_stop_translate(CPUX86State *env)
+int hax_stop_translate(CPUState *cpu)
{
struct hax_vcpu_state *vstate;
- vstate = ENV_GET_CPU(env)->hax_vcpu;
+ vstate = cpu->hax_vcpu;
assert(vstate->emulation_state);
if (vstate->emulation_state == HAX_EMULATE_STATE_MMIO )
return 1;
@@ -114,9 +113,9 @@
return size >= sizeof(struct hax_tunnel);
}
-hax_fd hax_vcpu_get_fd(CPUX86State *env)
+hax_fd hax_vcpu_get_fd(CPUState *cpu)
{
- struct hax_vcpu_state *vcpu = ENV_GET_CPU(env)->hax_vcpu;
+ struct hax_vcpu_state *vcpu = cpu->hax_vcpu;
if (!vcpu)
return HAX_INVALID_FD;
return vcpu->fd;
@@ -236,9 +235,9 @@
return -1;
}
-int hax_vcpu_destroy(CPUX86State *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)
{
@@ -259,10 +258,9 @@
return 0;
}
-int hax_init_vcpu(CPUX86State *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)
@@ -470,11 +468,11 @@
return 0;
}
-static int hax_vcpu_interrupt(CPUX86State *env)
+static int hax_vcpu_interrupt(CPUState *cpu)
{
- CPUState *cpu = ENV_GET_CPU(env);
struct hax_vcpu_state *vcpu = cpu->hax_vcpu;
struct hax_tunnel *ht = vcpu->tunnel;
+ CPUX86State *env = cpu->env_ptr;
/*
* Try to inject an interrupt if the guest can accept it
@@ -488,7 +486,7 @@
cpu->interrupt_request &= ~CPU_INTERRUPT_HARD;
irq = cpu_get_pic_interrupt(env);
if (irq >= 0) {
- hax_inject_interrupt(env, irq);
+ hax_inject_interrupt(cpu, irq);
}
}
@@ -505,9 +503,9 @@
return 0;
}
-void hax_raise_event(CPUX86State *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;
@@ -525,14 +523,14 @@
* 5. An unknown VMX-exit happens
*/
extern void qemu_system_reset_request(void);
-static int hax_vcpu_hax_exec(CPUX86State *env)
+static int hax_vcpu_hax_exec(CPUState *cpu)
{
int ret = 0;
- CPUState *cpu = ENV_GET_CPU(env);
+ CPUX86State *env = cpu->env_ptr;
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;
@@ -546,7 +544,7 @@
break;
}
- hax_vcpu_interrupt(env);
+ hax_vcpu_interrupt(cpu);
hax_ret = hax_vcpu_run(vcpu);
@@ -585,14 +583,14 @@
dprint("VCPU shutdown request\n");
qemu_system_reset_request();
hax_prepare_emulation(env);
- cpu_dump_state(env, stderr, fprintf, 0);
+ cpu_dump_state(cpu, stderr, fprintf, 0);
ret = HAX_EMUL_EXITLOOP;
break;
case HAX_EXIT_UNKNOWN_VMEXIT:
dprint("Unknown VMX exit %x from guest\n", ht->_exit_reason);
qemu_system_reset_request();
hax_prepare_emulation(env);
- cpu_dump_state(env, stderr, fprintf, 0);
+ cpu_dump_state(cpu, stderr, fprintf, 0);
ret = HAX_EMUL_EXITLOOP;
break;
case HAX_EXIT_HLT:
@@ -613,7 +611,7 @@
dprint("Unknow exit %x from hax\n", ht->_exit_status);
qemu_system_reset_request();
hax_prepare_emulation(env);
- cpu_dump_state(env, stderr, fprintf, 0);
+ cpu_dump_state(cpu, stderr, fprintf, 0);
ret = HAX_EMUL_EXITLOOP;
break;
}
@@ -629,17 +627,17 @@
/*
* return 1 when need to emulate, 0 when need to exit loop
*/
-int hax_vcpu_exec(CPUX86State *env)
+int hax_vcpu_exec(CPUState *cpu)
{
int next = 0, ret = 0;
struct hax_vcpu_state *vcpu;
- CPUState *cpu = ENV_GET_CPU(env);
+ CPUX86State *env = cpu->env_ptr;
if (cpu->hax_vcpu->emulation_state != HAX_EMULATE_STATE_NONE)
return 1;
vcpu = cpu->hax_vcpu;
- next = hax_vcpu_hax_exec(env);
+ next = hax_vcpu_hax_exec(cpu);
switch (next)
{
case HAX_EMUL_ONE:
@@ -830,13 +828,14 @@
static int hax_sync_vcpu_register(CPUX86State *env, int set)
{
+ CPUState *cpu = ENV_GET_CPU(env);
struct vcpu_state_t regs;
int ret;
memset(®s, 0, sizeof(struct vcpu_state_t));
if (!set)
{
- ret = hax_sync_vcpu_state(env, ®s, 0);
+ ret = hax_sync_vcpu_state(cpu, ®s, 0);
if (ret < 0)
return -1;
}
@@ -874,7 +873,7 @@
if (set)
{
- ret = hax_sync_vcpu_state(env, ®s, 1);
+ ret = hax_sync_vcpu_state(cpu, ®s, 1);
if (ret < 0)
return -1;
}
@@ -902,7 +901,7 @@
msrs[n++].entry = MSR_IA32_SYSENTER_EIP;
msrs[n++].entry = MSR_IA32_TSC;
md.nr_msr = n;
- ret = hax_sync_msr(env, &md, 0);
+ ret = hax_sync_msr(ENV_GET_CPU(env), &md, 0);
if (ret < 0)
return ret;
@@ -941,7 +940,7 @@
md.nr_msr = n;
md.done = 0;
- return hax_sync_msr(env, &md, 1);
+ return hax_sync_msr(ENV_GET_CPU(env), &md, 1);
}
@@ -950,7 +949,7 @@
struct fx_layout fpu;
int i, ret;
- ret = hax_sync_fpu(env, &fpu, 0);
+ ret = hax_sync_fpu(ENV_GET_CPU(env), &fpu, 0);
if (ret < 0)
return ret;
@@ -987,11 +986,12 @@
fpu.mxcsr = env->mxcsr;
- return hax_sync_fpu(env, &fpu, 1);
+ return hax_sync_fpu(ENV_GET_CPU(env), &fpu, 1);
}
-int hax_arch_get_registers(CPUX86State *env)
+int hax_arch_get_registers(CPUState *cpu)
{
+ CPUX86State *env = cpu->env_ptr;
int ret;
ret = hax_sync_vcpu_register(env, 0);
@@ -1009,9 +1009,10 @@
return 0;
}
-static int hax_arch_set_registers(CPUX86State *env)
+static int hax_arch_set_registers(CPUState *cpu)
{
int ret;
+ CPUX86State *env = cpu->env_ptr;
ret = hax_sync_vcpu_register(env, 1);
if (ret < 0)
@@ -1035,13 +1036,13 @@
return 0;
}
-void hax_vcpu_sync_state(CPUX86State *env, int modified)
+void hax_vcpu_sync_state(CPUState *cpu, int modified)
{
if (hax_enabled()) {
if (modified)
- hax_arch_set_registers(env);
+ hax_arch_set_registers(cpu);
else
- hax_arch_get_registers(env);
+ hax_arch_get_registers(cpu);
}
}
@@ -1055,7 +1056,7 @@
CPUState *cpu;
CPU_FOREACH(cpu) {
- int ret = hax_arch_set_registers(cpu->env_ptr);
+ int ret = hax_arch_set_registers(cpu);
if (ret < 0) {
dprint("Failed to sync HAX vcpu context\n");
exit(1);
diff --git a/target-i386/hax-darwin.c b/target-i386/hax-darwin.c
index c5fd741..3e85f1f 100644
--- a/target-i386/hax-darwin.c
+++ b/target-i386/hax-darwin.c
@@ -73,7 +73,7 @@
info.pa_start = start_addr;
info.size = size;
- info.va = (uint64_t)qemu_get_ram_ptr(phys_offset);
+ info.va = (uint64_t)(uintptr_t)qemu_get_ram_ptr(phys_offset);
info.flags = (flags & IO_MEM_ROM) ? 1 : 0;
ret = ioctl(hax_global.vm->fd, HAX_VM_IOCTL_SET_RAM, pinfo);
@@ -252,8 +252,8 @@
return ret;
}
- vcpu->tunnel = (struct hax_tunnel *)(info.va);
- vcpu->iobuf = (unsigned char *)(info.io_va);
+ vcpu->tunnel = (struct hax_tunnel *)(uintptr_t)(info.va);
+ vcpu->iobuf = (unsigned char *)(uintptr_t)(info.io_va);
return 0;
}
@@ -265,11 +265,11 @@
return ret;
}
-int hax_sync_fpu(CPUX86State *env, struct fx_layout *fl, int set)
+int hax_sync_fpu(CPUState *cpu, struct fx_layout *fl, int set)
{
int ret, fd;
- fd = hax_vcpu_get_fd(env);
+ fd = hax_vcpu_get_fd(cpu);
if (fd <= 0)
return -1;
@@ -280,11 +280,11 @@
return ret;
}
-int hax_sync_msr(CPUX86State *env, struct hax_msr_data *msrs, int set)
+int hax_sync_msr(CPUState *cpu, struct hax_msr_data *msrs, int set)
{
int ret, fd;
- fd = hax_vcpu_get_fd(env);
+ fd = hax_vcpu_get_fd(cpu);
if (fd <= 0)
return -1;
if (set)
@@ -294,11 +294,11 @@
return ret;
}
-int hax_sync_vcpu_state(CPUX86State *env, struct vcpu_state_t *state, int set)
+int hax_sync_vcpu_state(CPUState *cpu, struct vcpu_state_t *state, int set)
{
int ret, fd;
- fd = hax_vcpu_get_fd(env);
+ fd = hax_vcpu_get_fd(cpu);
if (fd <= 0)
return -1;
@@ -309,11 +309,11 @@
return ret;
}
-int hax_inject_interrupt(CPUX86State *env, int vector)
+int hax_inject_interrupt(CPUState *cpu, int vector)
{
int ret, fd;
- fd = hax_vcpu_get_fd(env);
+ fd = hax_vcpu_get_fd(cpu);
if (fd <= 0)
return -1;
diff --git a/target-i386/hax-i386.h b/target-i386/hax-i386.h
index 3dd91a0..6feafd8 100644
--- a/target-i386/hax-i386.h
+++ b/target-i386/hax-i386.h
@@ -55,18 +55,18 @@
};
/* Functions exported to host specific mode */
-hax_fd hax_vcpu_get_fd(CPUX86State *env);
+hax_fd hax_vcpu_get_fd(CPUState *cpu);
int valid_hax_tunnel_size(uint16_t size);
/* Host specific functions */
int hax_mod_version(struct hax_state *hax, struct hax_module_version *version);
-int hax_inject_interrupt(CPUX86State *env, int vector);
+int hax_inject_interrupt(CPUState *cpu, int vector);
struct hax_vm *hax_vm_create(struct hax_state *hax);
int hax_vcpu_run(struct hax_vcpu_state *vcpu);
int hax_vcpu_create(int id);
-int hax_sync_vcpu_state(CPUX86State *env, struct vcpu_state_t *state, int set);
-int hax_sync_msr(CPUX86State *env, struct hax_msr_data *msrs, int set);
-int hax_sync_fpu(CPUX86State *env, struct fx_layout *fl, int set);
+int hax_sync_vcpu_state(CPUState *cpu, struct vcpu_state_t *state, int set);
+int hax_sync_msr(CPUState *cpu, struct hax_msr_data *msrs, int set);
+int hax_sync_fpu(CPUState *cpu, struct fx_layout *fl, int set);
int hax_vm_destroy(struct hax_vm *vm);
int hax_capability(struct hax_state *hax, struct hax_capabilityinfo *cap);
int hax_notify_qemu_version(hax_fd vm_fd, struct hax_qemu_version *qversion);
diff --git a/target-i386/hax-windows.c b/target-i386/hax-windows.c
index ca38aa9..5db687b 100644
--- a/target-i386/hax-windows.c
+++ b/target-i386/hax-windows.c
@@ -399,14 +399,14 @@
return 0;
}
-int hax_sync_fpu(CPUX86State *env, struct fx_layout *fl, int set)
+int hax_sync_fpu(CPUState *cpu, struct fx_layout *fl, int set)
{
int ret;
hax_fd fd;
HANDLE hDeviceVCPU;
DWORD dSize = 0;
- fd = hax_vcpu_get_fd(env);
+ fd = hax_vcpu_get_fd(cpu);
if (hax_invalid_fd(fd))
return -1;
@@ -432,14 +432,14 @@
return 0;
}
-int hax_sync_msr(CPUX86State *env, struct hax_msr_data *msrs, int set)
+int hax_sync_msr(CPUState *cpu, struct hax_msr_data *msrs, int set)
{
int ret;
hax_fd fd;
HANDLE hDeviceVCPU;
DWORD dSize = 0;
- fd = hax_vcpu_get_fd(env);
+ fd = hax_vcpu_get_fd(cpu);
if (hax_invalid_fd(fd))
return -1;
hDeviceVCPU = fd;
@@ -464,14 +464,14 @@
return 0;
}
-int hax_sync_vcpu_state(CPUX86State *env, struct vcpu_state_t *state, int set)
+int hax_sync_vcpu_state(CPUState *cpu, struct vcpu_state_t *state, int set)
{
int ret;
hax_fd fd;
HANDLE hDeviceVCPU;
DWORD dSize;
- fd = hax_vcpu_get_fd(env);
+ fd = hax_vcpu_get_fd(cpu);
if (hax_invalid_fd(fd))
return -1;
@@ -497,14 +497,14 @@
return 0;
}
-int hax_inject_interrupt(CPUX86State *env, int vector)
+int hax_inject_interrupt(CPUState *cpu, int vector)
{
int ret;
hax_fd fd;
HANDLE hDeviceVCPU;
DWORD dSize;
- fd = hax_vcpu_get_fd(env);
+ fd = hax_vcpu_get_fd(cpu);
if (hax_invalid_fd(fd))
return -1;
diff --git a/target-i386/helper.c b/target-i386/helper.c
index f47b849..3e25e3a 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -666,7 +666,7 @@
#ifdef CONFIG_HAX
if (hax_enabled())
- hax_arch_get_registers(env);
+ hax_arch_get_registers(cpu);
#endif
eflags = env->eflags;
diff --git a/target-i386/translate.c b/target-i386/translate.c
index 3f8e040..3e9fe47 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -7893,7 +7893,7 @@
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(ENV_GET_CPU(env)))
{
gen_jmp_im(pc_ptr - dc->cs_base);
gen_eob(dc);