Skip to content

Commit

Permalink
exec: refactor cpu_restore_state
Browse files Browse the repository at this point in the history
Refactor common code around calls to cpu_restore_state().

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

Signed-off-by: Blue Swirl <[email protected]>
  • Loading branch information
blueswirl committed Dec 16, 2012
1 parent 5b6dd86 commit a8a826a
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 172 deletions.
6 changes: 2 additions & 4 deletions exec-all.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions hw/kvmvapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
14 changes: 3 additions & 11 deletions target-alpha/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down
8 changes: 6 additions & 2 deletions target-alpha/mem_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 1 addition & 7 deletions target-arm/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 1 addition & 7 deletions target-cris/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
void tlb_fill(CPUCRISState *env, target_ulong addr, int is_write, int mmu_idx,
uintptr_t retaddr)
{
TranslationBlock *tb;
int ret;

D_LOG("%s pc=%x tpc=%x ra=%p\n", __func__,
Expand All @@ -66,12 +65,7 @@ void tlb_fill(CPUCRISState *env, target_ulong addr, int is_write, int 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);

if (cpu_restore_state(env, retaddr)) {
/* Evaluate flags after retranslation. */
helper_top_evaluate_flags(env);
}
Expand Down
5 changes: 1 addition & 4 deletions target-i386/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1196,15 +1196,12 @@ void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,

void cpu_report_tpr_access(CPUX86State *env, TPRAccess access)
{
TranslationBlock *tb;

if (kvm_enabled()) {
env->tpr_access_type = access;

cpu_interrupt(env, CPU_INTERRUPT_TPR);
} else {
tb = tb_find_pc(env->mem_io_pc);
cpu_restore_state(tb, env, env->mem_io_pc);
cpu_restore_state(env, env->mem_io_pc);

apic_handle_tpr_access_report(env->apic_state, env->eip, access);
}
Expand Down
8 changes: 1 addition & 7 deletions target-i386/mem_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,13 @@ void helper_boundl(CPUX86State *env, target_ulong a0, int v)
void tlb_fill(CPUX86State *env, target_ulong addr, int is_write, int mmu_idx,
uintptr_t retaddr)
{
TranslationBlock *tb;
int ret;

ret = cpu_x86_handle_mmu_fault(env, addr, is_write, mmu_idx);
if (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_err(env, env->exception_index, env->error_code);
}
Expand Down
8 changes: 1 addition & 7 deletions target-lm32/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,13 @@ uint32_t helper_rcsr_jrx(CPULM32State *env)
void tlb_fill(CPULM32State *env, target_ulong addr, int is_write, int mmu_idx,
uintptr_t retaddr)
{
TranslationBlock *tb;
int ret;

ret = cpu_lm32_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);
}
cpu_loop_exit(env);
}
Expand Down
8 changes: 1 addition & 7 deletions target-m68k/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,13 @@ extern int semihosting_enabled;
void tlb_fill(CPUM68KState *env, target_ulong addr, int is_write, int mmu_idx,
uintptr_t retaddr)
{
TranslationBlock *tb;
int ret;

ret = cpu_m68k_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);
}
cpu_loop_exit(env);
}
Expand Down
8 changes: 1 addition & 7 deletions target-microblaze/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,13 @@
void tlb_fill(CPUMBState *env, target_ulong addr, int is_write, int mmu_idx,
uintptr_t retaddr)
{
TranslationBlock *tb;
int ret;

ret = cpu_mb_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);
}
cpu_loop_exit(env);
}
Expand Down
8 changes: 1 addition & 7 deletions target-mips/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ static inline void QEMU_NORETURN do_raise_exception_err(CPUMIPSState *env,
int error_code,
uintptr_t pc)
{
TranslationBlock *tb;
#if 1
if (exception < 0x100)
qemu_log("%s: %d %d\n", __func__, exception, error_code);
Expand All @@ -48,12 +47,7 @@ static inline void QEMU_NORETURN do_raise_exception_err(CPUMIPSState *env,

if (pc) {
/* now we have a real cpu fault */
tb = tb_find_pc(pc);
if (tb) {
/* the PC is inside the translated code. It means that we have
a virtual CPU fault */
cpu_restore_state(tb, env, pc);
}
cpu_restore_state(env, pc);
}

cpu_loop_exit(env);
Expand Down
10 changes: 1 addition & 9 deletions target-openrisc/mmu_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,14 @@
void tlb_fill(CPUOpenRISCState *env, target_ulong addr, int is_write,
int mmu_idx, uintptr_t retaddr)
{
TranslationBlock *tb;
unsigned long pc;
int ret;

ret = cpu_openrisc_handle_mmu_fault(env, addr, is_write, mmu_idx);

if (ret) {
if (retaddr) {
/* now we have a real cpu fault. */
pc = (unsigned long)retaddr;
tb = tb_find_pc(pc);
if (tb) {
/* the PC is inside the translated code. It means that we
have a virtual CPU fault. */
cpu_restore_state(tb, env, pc);
}
cpu_restore_state(env, retaddr);
}
/* Raise Exception. */
cpu_loop_exit(env);
Expand Down
8 changes: 1 addition & 7 deletions target-ppc/mem_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,13 @@ STVE(stvewx, cpu_stl_data, bswap32, u32)
void tlb_fill(CPUPPCState *env, target_ulong addr, int is_write, int mmu_idx,
uintptr_t retaddr)
{
TranslationBlock *tb;
int ret;

ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, mmu_idx);
if (unlikely(ret != 0)) {
if (likely(retaddr)) {
/* now we have a real cpu fault */
tb = tb_find_pc(retaddr);
if (likely(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);
}
helper_raise_exception_err(env, env->exception_index, env->error_code);
}
Expand Down
8 changes: 1 addition & 7 deletions target-s390x/mem_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,13 @@
void tlb_fill(CPUS390XState *env, target_ulong addr, int is_write, int mmu_idx,
uintptr_t retaddr)
{
TranslationBlock *tb;
int ret;

ret = cpu_s390x_handle_mmu_fault(env, addr, is_write, mmu_idx);
if (unlikely(ret != 0)) {
if (likely(retaddr)) {
/* now we have a real cpu fault */
tb = tb_find_pc(retaddr);
if (likely(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);
}
cpu_loop_exit(env);
}
Expand Down
23 changes: 6 additions & 17 deletions target-sh4/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@
#include "cpu.h"
#include "helper.h"

static inline void cpu_restore_state_from_retaddr(CPUSH4State *env,
uintptr_t retaddr)
{
TranslationBlock *tb;

if (retaddr) {
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);
}
}
}

#ifndef CONFIG_USER_ONLY
#include "softmmu_exec.h"

Expand All @@ -61,7 +46,9 @@ void tlb_fill(CPUSH4State *env, target_ulong addr, int is_write, int mmu_idx,
ret = cpu_sh4_handle_mmu_fault(env, addr, is_write, mmu_idx);
if (ret) {
/* now we have a real cpu fault */
cpu_restore_state_from_retaddr(env, retaddr);
if (retaddr) {
cpu_restore_state(env, retaddr);
}
cpu_loop_exit(env);
}
}
Expand All @@ -82,7 +69,9 @@ static inline void QEMU_NORETURN raise_exception(CPUSH4State *env, int index,
uintptr_t retaddr)
{
env->exception_index = index;
cpu_restore_state_from_retaddr(env, retaddr);
if (retaddr) {
cpu_restore_state(env, retaddr);
}
cpu_loop_exit(env);
}

Expand Down
1 change: 0 additions & 1 deletion target-sparc/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ uint64_t cpu_tick_get_count(CPUTimer *timer);
void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit);
trap_state* cpu_tsptr(CPUSPARCState* env);
#endif
void cpu_restore_state2(CPUSPARCState *env, uintptr_t retaddr);

#define TB_FLAG_FPU_ENABLED (1 << 4)
#define TB_FLAG_AM_ENABLED (1 << 5)
Expand Down
Loading

0 comments on commit a8a826a

Please sign in to comment.