Commit ea3e9847 authored by Peter Crosthwaite's avatar Peter Crosthwaite Committed by Andreas Färber
Browse files

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

Signed-off-by: default avatarPeter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: default avatarAndreas Färber <afaerber@suse.de>
parent 4bad9e39
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -166,6 +166,8 @@ static void set_idt(int n, unsigned int dpl)

void cpu_loop(CPUX86State *env)
{
    X86CPU *cpu = x86_env_get_cpu(env);
    CPUState *cs = CPU(cpu);
    int trapnr;
    abi_ulong pc;
    //target_siginfo_t info;
@@ -512,7 +514,7 @@ void cpu_loop(CPUSPARCState *env)
    //target_siginfo_t info;

    while (1) {
        trapnr = cpu_sparc_exec (env);
        trapnr = cpu_sparc_exec(cs);

        switch (trapnr) {
#ifndef TARGET_SPARC64
+13 −15
Original line number Diff line number Diff line
@@ -227,10 +227,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr)

/* Execute the code without caching the generated code. An interpreter
   could be used if available. */
static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
                             TranslationBlock *orig_tb)
{
    CPUState *cpu = ENV_GET_CPU(env);
    TranslationBlock *tb;
    target_ulong pc = orig_tb->pc;
    target_ulong cs_base = orig_tb->cs_base;
@@ -254,12 +253,12 @@ static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
    tb_free(tb);
}

static TranslationBlock *tb_find_slow(CPUArchState *env,
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;
    TranslationBlock *tb, **ptb1;
    unsigned int h;
    tb_page_addr_t phys_pc, phys_page1;
@@ -311,9 +310,9 @@ static TranslationBlock *tb_find_slow(CPUArchState *env,
    return tb;
}

static inline TranslationBlock *tb_find_fast(CPUArchState *env)
static inline 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;
@@ -325,14 +324,13 @@ static inline TranslationBlock *tb_find_fast(CPUArchState *env)
    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);
        tb = tb_find_slow(cpu, pc, cs_base, flags);
    }
    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(cpu);
    CPUWatchpoint *wp;

@@ -349,12 +347,12 @@ static void cpu_handle_debug_exception(CPUArchState *env)

volatile sig_atomic_t exit_request;

int cpu_exec(CPUArchState *env)
int cpu_exec(CPUState *cpu)
{
    CPUState *cpu = ENV_GET_CPU(env);
    CPUClass *cc = CPU_GET_CLASS(cpu);
#ifdef TARGET_I386
    X86CPU *x86_cpu = X86_CPU(cpu);
    CPUArchState *env = &x86_cpu->env;
#endif
    int ret, interrupt_request;
    TranslationBlock *tb;
@@ -407,7 +405,7 @@ int cpu_exec(CPUArchState *env)
                    /* 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);
                    }
                    cpu->exception_index = -1;
                    break;
@@ -483,7 +481,7 @@ int cpu_exec(CPUArchState *env)
                }
                spin_lock(&tcg_ctx.tb_ctx.tb_lock);
                have_tb_lock = true;
                tb = tb_find_fast(env);
                tb = tb_find_fast(cpu);
                /* Note: we do it here to avoid a gcc bug on Mac OS X when
                   doing it in tb_find_slow */
                if (tcg_ctx.tb_ctx.tb_invalidated_flag) {
@@ -543,7 +541,7 @@ int cpu_exec(CPUArchState *env)
                            if (insns_left > 0) {
                                /* Execute remaining instructions.  */
                                tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK);
                                cpu_exec_nocache(env, insns_left, tb);
                                cpu_exec_nocache(cpu, insns_left, tb);
                                align_clocks(&sc, cpu);
                            }
                            cpu->exception_index = EXCP_INTERRUPT;
@@ -567,11 +565,11 @@ int cpu_exec(CPUArchState *env)
            /* Reload env after longjmp - the compiler may have smashed all
             * local variables as longjmp is marked 'noreturn'. */
            cpu = current_cpu;
            env = cpu->env_ptr;
            cc = CPU_GET_CLASS(cpu);
            cpu->can_do_io = 1;
#ifdef TARGET_I386
            x86_cpu = X86_CPU(cpu);
            env = &x86_cpu->env;
#endif
            if (have_tb_lock) {
                spin_unlock(&tcg_ctx.tb_ctx.tb_lock);
+1 −2
Original line number Diff line number Diff line
@@ -1359,7 +1359,6 @@ int vm_stop_force_state(RunState state)

static int tcg_cpu_exec(CPUState *cpu)
{
    CPUArchState *env = cpu->env_ptr;
    int ret;
#ifdef CONFIG_PROFILER
    int64_t ti;
@@ -1394,7 +1393,7 @@ static int tcg_cpu_exec(CPUState *cpu)
        cpu->icount_decr.u16.low = decr;
        cpu->icount_extra = count;
    }
    ret = cpu_exec(env);
    ret = cpu_exec(cpu);
#ifdef CONFIG_PROFILER
    tcg_time += profile_getclock() - ti;
#endif
+14 −14
Original line number Diff line number Diff line
@@ -280,7 +280,7 @@ void cpu_loop(CPUX86State *env)

    for(;;) {
        cpu_exec_start(cs);
        trapnr = cpu_x86_exec(env);
        trapnr = cpu_x86_exec(cs);
        cpu_exec_end(cs);
        switch(trapnr) {
        case 0x80:
@@ -674,7 +674,7 @@ void cpu_loop(CPUARMState *env)

    for(;;) {
        cpu_exec_start(cs);
        trapnr = cpu_arm_exec(env);
        trapnr = cpu_arm_exec(cs);
        cpu_exec_end(cs);
        switch(trapnr) {
        case EXCP_UDEF:
@@ -1005,7 +1005,7 @@ void cpu_loop(CPUARMState *env)

    for (;;) {
        cpu_exec_start(cs);
        trapnr = cpu_arm_exec(env);
        trapnr = cpu_arm_exec(cs);
        cpu_exec_end(cs);

        switch (trapnr) {
@@ -1084,7 +1084,7 @@ void cpu_loop(CPUUniCore32State *env)

    for (;;) {
        cpu_exec_start(cs);
        trapnr = uc32_cpu_exec(env);
        trapnr = uc32_cpu_exec(cs);
        cpu_exec_end(cs);
        switch (trapnr) {
        case UC32_EXCP_PRIV:
@@ -1285,7 +1285,7 @@ void cpu_loop (CPUSPARCState *env)

    while (1) {
        cpu_exec_start(cs);
        trapnr = cpu_sparc_exec (env);
        trapnr = cpu_sparc_exec(cs);
        cpu_exec_end(cs);

        /* Compute PSR before exposing state.  */
@@ -1565,7 +1565,7 @@ void cpu_loop(CPUPPCState *env)

    for(;;) {
        cpu_exec_start(cs);
        trapnr = cpu_ppc_exec(env);
        trapnr = cpu_ppc_exec(cs);
        cpu_exec_end(cs);
        switch(trapnr) {
        case POWERPC_EXCP_NONE:
@@ -2417,7 +2417,7 @@ void cpu_loop(CPUMIPSState *env)

    for(;;) {
        cpu_exec_start(cs);
        trapnr = cpu_mips_exec(env);
        trapnr = cpu_mips_exec(cs);
        cpu_exec_end(cs);
        switch(trapnr) {
        case EXCP_SYSCALL:
@@ -2654,7 +2654,7 @@ void cpu_loop(CPUOpenRISCState *env)

    for (;;) {
        cpu_exec_start(cs);
        trapnr = cpu_exec(env);
        trapnr = cpu_openrisc_exec(cs);
        cpu_exec_end(cs);
        gdbsig = 0;

@@ -2744,7 +2744,7 @@ void cpu_loop(CPUSH4State *env)

    while (1) {
        cpu_exec_start(cs);
        trapnr = cpu_sh4_exec (env);
        trapnr = cpu_sh4_exec(cs);
        cpu_exec_end(cs);

        switch (trapnr) {
@@ -2806,7 +2806,7 @@ void cpu_loop(CPUCRISState *env)
    
    while (1) {
        cpu_exec_start(cs);
        trapnr = cpu_cris_exec (env);
        trapnr = cpu_cris_exec(cs);
        cpu_exec_end(cs);
        switch (trapnr) {
        case 0xaa:
@@ -2867,7 +2867,7 @@ void cpu_loop(CPUMBState *env)
    
    while (1) {
        cpu_exec_start(cs);
        trapnr = cpu_mb_exec (env);
        trapnr = cpu_mb_exec(cs);
        cpu_exec_end(cs);
        switch (trapnr) {
        case 0xaa:
@@ -2972,7 +2972,7 @@ void cpu_loop(CPUM68KState *env)

    for(;;) {
        cpu_exec_start(cs);
        trapnr = cpu_m68k_exec(env);
        trapnr = cpu_m68k_exec(cs);
        cpu_exec_end(cs);
        switch(trapnr) {
        case EXCP_ILLEGAL:
@@ -3111,7 +3111,7 @@ void cpu_loop(CPUAlphaState *env)

    while (1) {
        cpu_exec_start(cs);
        trapnr = cpu_alpha_exec (env);
        trapnr = cpu_alpha_exec(cs);
        cpu_exec_end(cs);

        /* All of the traps imply a transition through PALcode, which
@@ -3299,7 +3299,7 @@ void cpu_loop(CPUS390XState *env)

    while (1) {
        cpu_exec_start(cs);
        trapnr = cpu_s390x_exec(env);
        trapnr = cpu_s390x_exec(cs);
        cpu_exec_end(cs);
        switch (trapnr) {
        case EXCP_INTERRUPT:
+1 −1
Original line number Diff line number Diff line
@@ -431,7 +431,7 @@ AlphaCPU *cpu_alpha_init(const char *cpu_model);
#define cpu_init(cpu_model) CPU(cpu_alpha_init(cpu_model))

void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);
int cpu_alpha_exec(CPUAlphaState *s);
int cpu_alpha_exec(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.  */
Loading