Commit a8a826a3 authored by Blue Swirl's avatar Blue Swirl
Browse files

exec: refactor cpu_restore_state



Refactor common code around calls to cpu_restore_state().

tb_find_pc() has now no external users, make it static.

Signed-off-by: default avatarBlue Swirl <blauwirbel@gmail.com>
parent 5b6dd868
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -80,8 +80,8 @@ void restore_state_to_opc(CPUArchState *env, struct TranslationBlock *tb,
void cpu_gen_init(void);
int cpu_gen_code(CPUArchState *env, struct TranslationBlock *tb,
                 int *gen_code_size_ptr);
int cpu_restore_state(struct TranslationBlock *tb,
                      CPUArchState *env, uintptr_t searched_pc);
bool cpu_restore_state(CPUArchState *env, uintptr_t searched_pc);

void QEMU_NORETURN cpu_resume_from_signal(CPUArchState *env1, void *puc);
void QEMU_NORETURN cpu_io_recompile(CPUArchState *env, uintptr_t retaddr);
TranslationBlock *tb_gen_code(CPUArchState *env, 
@@ -275,8 +275,6 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
    }
}

TranslationBlock *tb_find_pc(uintptr_t pc_ptr);

#include "qemu-lock.h"

extern spinlock_t tb_lock;
+1 −3
Original line number Diff line number Diff line
@@ -387,7 +387,6 @@ static void patch_instruction(VAPICROMState *s, CPUX86State *env, target_ulong i
    VAPICHandlers *handlers;
    uint8_t opcode[2];
    uint32_t imm32;
    TranslationBlock *current_tb;
    target_ulong current_pc = 0;
    target_ulong current_cs_base = 0;
    int current_flags = 0;
@@ -399,8 +398,7 @@ static void patch_instruction(VAPICROMState *s, CPUX86State *env, target_ulong i
    }

    if (!kvm_enabled()) {
        current_tb = tb_find_pc(env->mem_io_pc);
        cpu_restore_state(current_tb, env, env->mem_io_pc);
        cpu_restore_state(env, env->mem_io_pc);
        cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
                             &current_flags);
    }
+3 −11
Original line number Diff line number Diff line
@@ -494,16 +494,6 @@ void cpu_dump_state (CPUAlphaState *env, FILE *f, fprintf_function cpu_fprintf,
    cpu_fprintf(f, "\n");
}

void do_restore_state(CPUAlphaState *env, uintptr_t retaddr)
{
    if (retaddr) {
        TranslationBlock *tb = tb_find_pc(retaddr);
        if (tb) {
            cpu_restore_state(tb, env, retaddr);
        }
    }
}

/* This should only be called from translate, via gen_excp.
   We expect that ENV->PC has already been updated.  */
void QEMU_NORETURN helper_excp(CPUAlphaState *env, int excp, int error)
@@ -519,7 +509,9 @@ void QEMU_NORETURN dynamic_excp(CPUAlphaState *env, uintptr_t retaddr,
{
    env->exception_index = excp;
    env->error_code = error;
    do_restore_state(env, retaddr);
    if (retaddr) {
        cpu_restore_state(env, retaddr);
    }
    cpu_loop_exit(env);
}

+6 −2
Original line number Diff line number Diff line
@@ -94,7 +94,9 @@ static void do_unaligned_access(CPUAlphaState *env, target_ulong addr,
    uint64_t pc;
    uint32_t insn;

    do_restore_state(env, retaddr);
    if (retaddr) {
        cpu_restore_state(env, retaddr);
    }

    pc = env->pc;
    insn = cpu_ldl_code(env, pc);
@@ -143,7 +145,9 @@ void tlb_fill(CPUAlphaState *env, target_ulong addr, int is_write,

    ret = cpu_alpha_handle_mmu_fault(env, addr, is_write, mmu_idx);
    if (unlikely(ret != 0)) {
        do_restore_state(env, retaddr);
        if (retaddr) {
            cpu_restore_state(env, retaddr);
        }
        /* Exception index and error code are already set */
        cpu_loop_exit(env);
    }
+1 −7
Original line number Diff line number Diff line
@@ -74,19 +74,13 @@ uint32_t HELPER(neon_tbl)(CPUARMState *env, uint32_t ireg, uint32_t def,
void tlb_fill(CPUARMState *env, target_ulong addr, int is_write, int mmu_idx,
              uintptr_t retaddr)
{
    TranslationBlock *tb;
    int ret;

    ret = cpu_arm_handle_mmu_fault(env, addr, is_write, mmu_idx);
    if (unlikely(ret)) {
        if (retaddr) {
            /* now we have a real cpu fault */
            tb = tb_find_pc(retaddr);
            if (tb) {
                /* the PC is inside the translated code. It means that we have
                   a virtual CPU fault */
                cpu_restore_state(tb, env, retaddr);
            }
            cpu_restore_state(env, retaddr);
        }
        raise_exception(env, env->exception_index);
    }
Loading