From e51f8c9f6fc4f8c369a30e5ccd3b801c3c083b76 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Wed, 14 Feb 2018 14:59:56 -0500 Subject: [PATCH] cpu-exec: Purge all uses of ENV_GET_CPU() Remove un-needed usages of ENV_GET_CPU() by converting the APIs to use CPUState pointers and retrieving the env_ptr as minimally needed. Scripted conversion for target-* change: for I in target-*/cpu.h; do sed -i \ 's/\(^int cpu_[^_]*_exec(\)[^ ][^ ]* \*s);$/\1CPUState *cpu);/' \ $I; done Backports commit ea3e9847408131abc840240bd61e892d28459452 from qemu --- qemu/cpu-exec.c | 37 +++++++++++++++++++------------------ qemu/cpus.c | 3 +-- qemu/target-arm/cpu.h | 2 +- qemu/target-i386/cpu.h | 2 +- qemu/target-m68k/cpu.h | 2 +- qemu/target-mips/cpu.h | 2 +- qemu/target-sparc/cpu.h | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/qemu/cpu-exec.c b/qemu/cpu-exec.c index 81e21f4c..ea9c953a 100644 --- a/qemu/cpu-exec.c +++ b/qemu/cpu-exec.c @@ -28,10 +28,10 @@ #include "uc_priv.h" static tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr); -static TranslationBlock *tb_find_slow(CPUArchState *env, target_ulong pc, - target_ulong cs_base, uint64_t flags); -static TranslationBlock *tb_find_fast(CPUArchState *env); -static void cpu_handle_debug_exception(CPUArchState *env); +static TranslationBlock *tb_find_slow(CPUState *cpu, target_ulong pc, + target_ulong cs_base, uint64_t flags); +static TranslationBlock *tb_find_fast(CPUState *cpu); +static void cpu_handle_debug_exception(CPUState *cpu); void cpu_loop_exit(CPUState *cpu) { @@ -55,9 +55,9 @@ void cpu_resume_from_signal(CPUState *cpu, void *puc) /* main execution loop */ -int cpu_exec(struct uc_struct *uc, CPUArchState *env) // qq +int cpu_exec(struct uc_struct *uc, CPUState *cpu) { - CPUState *cpu = ENV_GET_CPU(env); + CPUArchState *env = cpu->env_ptr; TCGContext *tcg_ctx = env->uc->tcg_ctx; CPUClass *cc = CPU_GET_CLASS(uc, cpu); #ifdef TARGET_I386 @@ -116,7 +116,7 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env) // qq /* exit request from the cpu execution loop */ ret = cpu->exception_index; if (ret == EXCP_DEBUG) { - cpu_handle_debug_exception(env); + cpu_handle_debug_exception(cpu); } break; } else { @@ -211,7 +211,7 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env) // qq cpu->exception_index = EXCP_INTERRUPT; cpu_loop_exit(cpu); } - tb = tb_find_fast(env); // qq + tb = tb_find_fast(cpu); // UNICORN if (!tb) { // invalid TB due to invalid code? uc->invalid_error = UC_ERR_FETCH_UNMAPPED; ret = EXCP_HLT; @@ -243,7 +243,7 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env) // qq if (likely(!cpu->exit_request)) { tc_ptr = tb->tc_ptr; /* execute the generated code */ - next_tb = cpu_tb_exec(cpu, tc_ptr); // qq + next_tb = cpu_tb_exec(cpu, tc_ptr); // UNICORN switch (next_tb & TB_EXIT_MASK) { case TB_EXIT_REQUESTED: @@ -335,10 +335,12 @@ static tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr) return next_tb; } -static TranslationBlock *tb_find_slow(CPUArchState *env, target_ulong pc, - target_ulong cs_base, uint64_t flags) // qq +static TranslationBlock *tb_find_slow(CPUState *cpu, + target_ulong pc, + target_ulong cs_base, + uint64_t flags) { - CPUState *cpu = ENV_GET_CPU(env); + CPUArchState *env = (CPUArchState *)cpu->env_ptr; TCGContext *tcg_ctx = env->uc->tcg_ctx; TranslationBlock *tb, **ptb1; unsigned int h; @@ -394,9 +396,9 @@ found: return tb; } -static TranslationBlock *tb_find_fast(CPUArchState *env) // qq +static TranslationBlock *tb_find_fast(CPUState *cpu) { - CPUState *cpu = ENV_GET_CPU(env); + CPUArchState *env = (CPUArchState *)cpu->env_ptr; TranslationBlock *tb; target_ulong cs_base, pc; int flags; @@ -408,15 +410,14 @@ static TranslationBlock *tb_find_fast(CPUArchState *env) // qq tb = cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)]; if (unlikely(!tb || tb->pc != pc || tb->cs_base != cs_base || tb->flags != flags)) { - tb = tb_find_slow(env, pc, cs_base, flags); // qq + tb = tb_find_slow(cpu, pc, cs_base, flags); // qq } return tb; } -static void cpu_handle_debug_exception(CPUArchState *env) +static void cpu_handle_debug_exception(CPUState *cpu) { - CPUState *cpu = ENV_GET_CPU(env); - CPUClass *cc = CPU_GET_CLASS(env->uc, cpu); + CPUClass *cc = CPU_GET_CLASS(cpu->uc, cpu); CPUWatchpoint *wp; if (!cpu->watchpoint_hit) { diff --git a/qemu/cpus.c b/qemu/cpus.c index 784a8575..69aa2d83 100644 --- a/qemu/cpus.c +++ b/qemu/cpus.c @@ -117,8 +117,7 @@ static int qemu_tcg_init_vcpu(CPUState *cpu) static int tcg_cpu_exec(struct uc_struct *uc, CPUState *cpu) { - CPUArchState *env = cpu->env_ptr; - return cpu_exec(uc, env); + return cpu_exec(uc, cpu); } static bool tcg_exec_all(struct uc_struct* uc) diff --git a/qemu/target-arm/cpu.h b/qemu/target-arm/cpu.h index 873b56fd..5d70701f 100644 --- a/qemu/target-arm/cpu.h +++ b/qemu/target-arm/cpu.h @@ -507,7 +507,7 @@ typedef struct CPUARMState { #include "cpu-qom.h" ARMCPU *cpu_arm_init(struct uc_struct *uc, const char *cpu_model); -int cpu_arm_exec(struct uc_struct *uc, CPUARMState *s); +int cpu_arm_exec(struct uc_struct *uc, CPUState *cpu); uint32_t do_arm_semihosting(CPUARMState *env); void aarch64_sync_32_to_64(CPUARMState *env); void aarch64_sync_64_to_32(CPUARMState *env); diff --git a/qemu/target-i386/cpu.h b/qemu/target-i386/cpu.h index c45912f3..c8d5e87d 100644 --- a/qemu/target-i386/cpu.h +++ b/qemu/target-i386/cpu.h @@ -980,7 +980,7 @@ typedef struct CPUX86State { #include "cpu-qom.h" X86CPU *cpu_x86_create(struct uc_struct *uc, const char *cpu_model, Error **errp); -int cpu_x86_exec(struct uc_struct *uc, CPUX86State *s); +int cpu_x86_exec(struct uc_struct *uc, CPUState *cpu); void x86_cpudef_setup(void); int cpu_x86_support_mca_broadcast(CPUX86State *env); diff --git a/qemu/target-m68k/cpu.h b/qemu/target-m68k/cpu.h index 40f66b4c..67eee893 100644 --- a/qemu/target-m68k/cpu.h +++ b/qemu/target-m68k/cpu.h @@ -121,7 +121,7 @@ typedef struct CPUM68KState { void m68k_tcg_init(struct uc_struct *uc); M68kCPU *cpu_m68k_init(struct uc_struct *uc, const char *cpu_model); -int cpu_m68k_exec(struct uc_struct *uc, CPUM68KState *s); +int cpu_m68k_exec(struct uc_struct *uc, CPUState *cpu); /* you can call this signal handler from your SIGBUS and SIGSEGV signal handlers to inform the virtual CPU of exceptions. non zero is returned if the signal was handled by the virtual CPU. */ diff --git a/qemu/target-mips/cpu.h b/qemu/target-mips/cpu.h index d18cadf4..a8f69fc9 100644 --- a/qemu/target-mips/cpu.h +++ b/qemu/target-mips/cpu.h @@ -752,7 +752,7 @@ enum { */ #define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0 -int cpu_mips_exec(struct uc_struct *uc, CPUMIPSState *s); +int cpu_mips_exec(struct uc_struct *uc, CPUState *cpu); void mips_tcg_init(struct uc_struct *uc); MIPSCPU *cpu_mips_init(struct uc_struct *uc, const char *cpu_model); int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc); diff --git a/qemu/target-sparc/cpu.h b/qemu/target-sparc/cpu.h index 2f8ed15f..05827c1b 100644 --- a/qemu/target-sparc/cpu.h +++ b/qemu/target-sparc/cpu.h @@ -542,7 +542,7 @@ int sparc_cpu_memory_rw_debug(CPUState *cpu, vaddr addr, void gen_intermediate_code_init(CPUSPARCState *env); /* cpu-exec.c */ -int cpu_sparc_exec(struct uc_struct *uc, CPUSPARCState *s); +int cpu_sparc_exec(struct uc_struct *uc, CPUState *cpu); /* win_helper.c */ target_ulong cpu_get_psr(CPUSPARCState *env1);