cpu_loop_exit: avoid using AREG0

Make cpu_loop_exit() take a parameter for CPUState instead of relying
on global env.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Blue Swirl 2011-05-14 12:52:35 +00:00
parent 4d2c2b77f3
commit 1162c041c1
16 changed files with 57 additions and 56 deletions

View File

@ -37,10 +37,10 @@ int qemu_cpu_has_work(CPUState *env)
return cpu_has_work(env); return cpu_has_work(env);
} }
void cpu_loop_exit(void) void cpu_loop_exit(CPUState *env1)
{ {
env->current_tb = NULL; env1->current_tb = NULL;
longjmp(env->jmp_env, 1); longjmp(env1->jmp_env, 1);
} }
/* exit the current TB from a signal handler. The host registers are /* exit the current TB from a signal handler. The host registers are
@ -327,7 +327,7 @@ int cpu_exec(CPUState *env1)
if (interrupt_request & CPU_INTERRUPT_DEBUG) { if (interrupt_request & CPU_INTERRUPT_DEBUG) {
env->interrupt_request &= ~CPU_INTERRUPT_DEBUG; env->interrupt_request &= ~CPU_INTERRUPT_DEBUG;
env->exception_index = EXCP_DEBUG; env->exception_index = EXCP_DEBUG;
cpu_loop_exit(); cpu_loop_exit(env);
} }
#if defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_MIPS) || \ #if defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_MIPS) || \
defined(TARGET_PPC) || defined(TARGET_ALPHA) || defined(TARGET_CRIS) || \ defined(TARGET_PPC) || defined(TARGET_ALPHA) || defined(TARGET_CRIS) || \
@ -336,7 +336,7 @@ int cpu_exec(CPUState *env1)
env->interrupt_request &= ~CPU_INTERRUPT_HALT; env->interrupt_request &= ~CPU_INTERRUPT_HALT;
env->halted = 1; env->halted = 1;
env->exception_index = EXCP_HLT; env->exception_index = EXCP_HLT;
cpu_loop_exit(); cpu_loop_exit(env);
} }
#endif #endif
#if defined(TARGET_I386) #if defined(TARGET_I386)
@ -344,7 +344,7 @@ int cpu_exec(CPUState *env1)
svm_check_intercept(SVM_EXIT_INIT); svm_check_intercept(SVM_EXIT_INIT);
do_cpu_init(env); do_cpu_init(env);
env->exception_index = EXCP_HALTED; env->exception_index = EXCP_HALTED;
cpu_loop_exit(); cpu_loop_exit(env);
} else if (interrupt_request & CPU_INTERRUPT_SIPI) { } else if (interrupt_request & CPU_INTERRUPT_SIPI) {
do_cpu_sipi(env); do_cpu_sipi(env);
} else if (env->hflags2 & HF2_GIF_MASK) { } else if (env->hflags2 & HF2_GIF_MASK) {
@ -564,7 +564,7 @@ int cpu_exec(CPUState *env1)
if (unlikely(env->exit_request)) { if (unlikely(env->exit_request)) {
env->exit_request = 0; env->exit_request = 0;
env->exception_index = EXCP_INTERRUPT; env->exception_index = EXCP_INTERRUPT;
cpu_loop_exit(); cpu_loop_exit(env);
} }
#if defined(DEBUG_DISAS) || defined(CONFIG_DEBUG_EXEC) #if defined(DEBUG_DISAS) || defined(CONFIG_DEBUG_EXEC)
if (qemu_loglevel_mask(CPU_LOG_TB_CPU)) { if (qemu_loglevel_mask(CPU_LOG_TB_CPU)) {
@ -647,7 +647,7 @@ int cpu_exec(CPUState *env1)
} }
env->exception_index = EXCP_INTERRUPT; env->exception_index = EXCP_INTERRUPT;
next_tb = 0; next_tb = 0;
cpu_loop_exit(); cpu_loop_exit(env);
} }
} }
} }

View File

@ -95,7 +95,7 @@ TranslationBlock *tb_gen_code(CPUState *env,
target_ulong pc, target_ulong cs_base, int flags, target_ulong pc, target_ulong cs_base, int flags,
int cflags); int cflags);
void cpu_exec_init(CPUState *env); void cpu_exec_init(CPUState *env);
void QEMU_NORETURN cpu_loop_exit(void); void QEMU_NORETURN cpu_loop_exit(CPUState *env1);
int page_unprotect(target_ulong address, unsigned long pc, void *puc); int page_unprotect(target_ulong address, unsigned long pc, void *puc);
void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end, void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
int is_cpu_write_access); int is_cpu_write_access);

View File

@ -32,7 +32,7 @@ void QEMU_NORETURN helper_excp(int excp, int error)
{ {
env->exception_index = excp; env->exception_index = excp;
env->error_code = error; env->error_code = error;
cpu_loop_exit(); cpu_loop_exit(env);
} }
static void do_restore_state(void *retaddr) static void do_restore_state(void *retaddr)
@ -53,7 +53,7 @@ static void QEMU_NORETURN dynamic_excp(int excp, int error)
env->exception_index = excp; env->exception_index = excp;
env->error_code = error; env->error_code = error;
do_restore_state(GETPC()); do_restore_state(GETPC());
cpu_loop_exit(); cpu_loop_exit(env);
} }
static void QEMU_NORETURN arith_excp(int exc, uint64_t mask) static void QEMU_NORETURN arith_excp(int exc, uint64_t mask)
@ -1341,7 +1341,7 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
if (unlikely(ret != 0)) { if (unlikely(ret != 0)) {
do_restore_state(retaddr); do_restore_state(retaddr);
/* Exception index and error code are already set */ /* Exception index and error code are already set */
cpu_loop_exit(); cpu_loop_exit(env);
} }
env = saved_env; env = saved_env;
} }

View File

@ -25,7 +25,7 @@
void raise_exception(int tt) void raise_exception(int tt)
{ {
env->exception_index = tt; env->exception_index = tt;
cpu_loop_exit(); cpu_loop_exit(env);
} }
uint32_t HELPER(neon_tbl)(uint32_t ireg, uint32_t def, uint32_t HELPER(neon_tbl)(uint32_t ireg, uint32_t def,
@ -234,13 +234,13 @@ void HELPER(wfi)(void)
{ {
env->exception_index = EXCP_HLT; env->exception_index = EXCP_HLT;
env->halted = 1; env->halted = 1;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void HELPER(exception)(uint32_t excp) void HELPER(exception)(uint32_t excp)
{ {
env->exception_index = excp; env->exception_index = excp;
cpu_loop_exit(); cpu_loop_exit(env);
} }
uint32_t HELPER(cpsr_read)(void) uint32_t HELPER(cpsr_read)(void)

View File

@ -83,7 +83,7 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
helper_top_evaluate_flags(); helper_top_evaluate_flags();
} }
} }
cpu_loop_exit(); cpu_loop_exit(env);
} }
env = saved_env; env = saved_env;
} }
@ -93,7 +93,7 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
void helper_raise_exception(uint32_t index) void helper_raise_exception(uint32_t index)
{ {
env->exception_index = index; env->exception_index = index;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_tlb_flush_pid(uint32_t pid) void helper_tlb_flush_pid(uint32_t pid)

View File

@ -1000,7 +1000,7 @@ void helper_syscall(int next_eip_addend)
{ {
env->exception_index = EXCP_SYSCALL; env->exception_index = EXCP_SYSCALL;
env->exception_next_eip = env->eip + next_eip_addend; env->exception_next_eip = env->eip + next_eip_addend;
cpu_loop_exit(); cpu_loop_exit(env);
} }
#else #else
void helper_syscall(int next_eip_addend) void helper_syscall(int next_eip_addend)
@ -1335,7 +1335,7 @@ static void QEMU_NORETURN raise_interrupt(int intno, int is_int, int error_code,
env->error_code = error_code; env->error_code = error_code;
env->exception_is_int = is_int; env->exception_is_int = is_int;
env->exception_next_eip = env->eip + next_eip_addend; env->exception_next_eip = env->eip + next_eip_addend;
cpu_loop_exit(); cpu_loop_exit(env);
} }
/* shortcuts to generate exceptions */ /* shortcuts to generate exceptions */
@ -4658,7 +4658,7 @@ static void do_hlt(void)
env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */ env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */
env->halted = 1; env->halted = 1;
env->exception_index = EXCP_HLT; env->exception_index = EXCP_HLT;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_hlt(int next_eip_addend) void helper_hlt(int next_eip_addend)
@ -4696,7 +4696,7 @@ void helper_mwait(int next_eip_addend)
void helper_debug(void) void helper_debug(void)
{ {
env->exception_index = EXCP_DEBUG; env->exception_index = EXCP_DEBUG;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_reset_rf(void) void helper_reset_rf(void)
@ -5048,7 +5048,7 @@ void helper_vmrun(int aflag, int next_eip_addend)
env->exception_is_int = 0; env->exception_is_int = 0;
env->exception_next_eip = EIP; env->exception_next_eip = EIP;
qemu_log_mask(CPU_LOG_TB_IN_ASM, "NMI"); qemu_log_mask(CPU_LOG_TB_IN_ASM, "NMI");
cpu_loop_exit(); cpu_loop_exit(env);
break; break;
case SVM_EVTINJ_TYPE_EXEPT: case SVM_EVTINJ_TYPE_EXEPT:
env->exception_index = vector; env->exception_index = vector;
@ -5056,7 +5056,7 @@ void helper_vmrun(int aflag, int next_eip_addend)
env->exception_is_int = 0; env->exception_is_int = 0;
env->exception_next_eip = -1; env->exception_next_eip = -1;
qemu_log_mask(CPU_LOG_TB_IN_ASM, "EXEPT"); qemu_log_mask(CPU_LOG_TB_IN_ASM, "EXEPT");
cpu_loop_exit(); cpu_loop_exit(env);
break; break;
case SVM_EVTINJ_TYPE_SOFT: case SVM_EVTINJ_TYPE_SOFT:
env->exception_index = vector; env->exception_index = vector;
@ -5064,7 +5064,7 @@ void helper_vmrun(int aflag, int next_eip_addend)
env->exception_is_int = 1; env->exception_is_int = 1;
env->exception_next_eip = EIP; env->exception_next_eip = EIP;
qemu_log_mask(CPU_LOG_TB_IN_ASM, "SOFT"); qemu_log_mask(CPU_LOG_TB_IN_ASM, "SOFT");
cpu_loop_exit(); cpu_loop_exit(env);
break; break;
} }
qemu_log_mask(CPU_LOG_TB_IN_ASM, " %#x %#x\n", env->exception_index, env->error_code); qemu_log_mask(CPU_LOG_TB_IN_ASM, " %#x %#x\n", env->exception_index, env->error_code);
@ -5400,7 +5400,7 @@ void helper_vmexit(uint32_t exit_code, uint64_t exit_info_1)
env->error_code = 0; env->error_code = 0;
env->old_exception = -1; env->old_exception = -1;
cpu_loop_exit(); cpu_loop_exit(env);
} }
#endif #endif

View File

@ -20,14 +20,14 @@
void helper_raise_exception(uint32_t index) void helper_raise_exception(uint32_t index)
{ {
env->exception_index = index; env->exception_index = index;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_hlt(void) void helper_hlt(void)
{ {
env->halted = 1; env->halted = 1;
env->exception_index = EXCP_HLT; env->exception_index = EXCP_HLT;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_wcsr_im(uint32_t im) void helper_wcsr_im(uint32_t im)
@ -98,7 +98,7 @@ void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)
cpu_restore_state(tb, env, pc); cpu_restore_state(tb, env, pc);
} }
} }
cpu_loop_exit(); cpu_loop_exit(env);
} }
env = saved_env; env = saved_env;
} }

View File

@ -71,7 +71,7 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
cpu_restore_state(tb, env, pc); cpu_restore_state(tb, env, pc);
} }
} }
cpu_loop_exit(); cpu_loop_exit(env);
} }
env = saved_env; env = saved_env;
} }
@ -118,7 +118,7 @@ void do_interrupt(int is_hw)
} }
env->halted = 1; env->halted = 1;
env->exception_index = EXCP_HLT; env->exception_index = EXCP_HLT;
cpu_loop_exit(); cpu_loop_exit(env);
return; return;
} }
if (env->exception_index >= EXCP_TRAP0 if (env->exception_index >= EXCP_TRAP0
@ -160,7 +160,7 @@ void do_interrupt(int is_hw)
static void raise_exception(int tt) static void raise_exception(int tt)
{ {
env->exception_index = tt; env->exception_index = tt;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void HELPER(raise_exception)(uint32_t tt) void HELPER(raise_exception)(uint32_t tt)

View File

@ -63,7 +63,7 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
cpu_restore_state(tb, env, pc); cpu_restore_state(tb, env, pc);
} }
} }
cpu_loop_exit(); cpu_loop_exit(env);
} }
env = saved_env; env = saved_env;
} }
@ -107,7 +107,7 @@ uint32_t helper_get(uint32_t id, uint32_t ctrl)
void helper_raise_exception(uint32_t index) void helper_raise_exception(uint32_t index)
{ {
env->exception_index = index; env->exception_index = index;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_debug(void) void helper_debug(void)

View File

@ -38,7 +38,7 @@ void helper_raise_exception_err (uint32_t exception, int error_code)
#endif #endif
env->exception_index = exception; env->exception_index = exception;
env->error_code = error_code; env->error_code = error_code;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_raise_exception (uint32_t exception) void helper_raise_exception (uint32_t exception)
@ -277,7 +277,7 @@ static inline target_phys_addr_t do_translate_address(target_ulong address, int
lladdr = cpu_mips_translate_address(env, address, rw); lladdr = cpu_mips_translate_address(env, address, rw);
if (lladdr == -1LL) { if (lladdr == -1LL) {
cpu_loop_exit(); cpu_loop_exit(env);
} else { } else {
return lladdr; return lladdr;
} }

View File

@ -44,7 +44,7 @@ void helper_raise_exception_err (uint32_t exception, uint32_t error_code)
#endif #endif
env->exception_index = exception; env->exception_index = exception;
env->error_code = error_code; env->error_code = error_code;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_raise_exception (uint32_t exception) void helper_raise_exception (uint32_t exception)

View File

@ -73,7 +73,7 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
cpu_restore_state(tb, env, pc); cpu_restore_state(tb, env, pc);
} }
} }
cpu_loop_exit(); cpu_loop_exit(env);
} }
env = saved_env; env = saved_env;
} }
@ -92,7 +92,7 @@ void HELPER(exception)(uint32_t excp)
{ {
HELPER_LOG("%s: exception %d\n", __FUNCTION__, excp); HELPER_LOG("%s: exception %d\n", __FUNCTION__, excp);
env->exception_index = excp; env->exception_index = excp;
cpu_loop_exit(); cpu_loop_exit(env);
} }
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
@ -2326,7 +2326,7 @@ void HELPER(tr)(uint32_t len, uint64_t array, uint64_t trans)
void HELPER(load_psw)(uint64_t mask, uint64_t addr) void HELPER(load_psw)(uint64_t mask, uint64_t addr)
{ {
load_psw(env, mask, addr); load_psw(env, mask, addr);
cpu_loop_exit(); cpu_loop_exit(env);
} }
static void program_interrupt(CPUState *env, uint32_t code, int ilc) static void program_interrupt(CPUState *env, uint32_t code, int ilc)
@ -2341,7 +2341,7 @@ static void program_interrupt(CPUState *env, uint32_t code, int ilc)
env->int_pgm_code = code; env->int_pgm_code = code;
env->int_pgm_ilc = ilc; env->int_pgm_ilc = ilc;
env->exception_index = EXCP_PGM; env->exception_index = EXCP_PGM;
cpu_loop_exit(); cpu_loop_exit(env);
} }
} }
@ -2828,12 +2828,12 @@ static uint32_t mvc_asc(int64_t l, uint64_t a1, uint64_t mode1, uint64_t a2,
} }
if (mmu_translate(env, a1 & TARGET_PAGE_MASK, 1, mode1, &dest, &flags)) { if (mmu_translate(env, a1 & TARGET_PAGE_MASK, 1, mode1, &dest, &flags)) {
cpu_loop_exit(); cpu_loop_exit(env);
} }
dest |= a1 & ~TARGET_PAGE_MASK; dest |= a1 & ~TARGET_PAGE_MASK;
if (mmu_translate(env, a2 & TARGET_PAGE_MASK, 0, mode2, &src, &flags)) { if (mmu_translate(env, a2 & TARGET_PAGE_MASK, 0, mode2, &src, &flags)) {
cpu_loop_exit(); cpu_loop_exit(env);
} }
src |= a2 & ~TARGET_PAGE_MASK; src |= a2 & ~TARGET_PAGE_MASK;

View File

@ -66,7 +66,7 @@ void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)
if (ret) { if (ret) {
/* now we have a real cpu fault */ /* now we have a real cpu fault */
cpu_restore_state_from_retaddr(retaddr); cpu_restore_state_from_retaddr(retaddr);
cpu_loop_exit(); cpu_loop_exit(env);
} }
env = saved_env; env = saved_env;
} }
@ -87,7 +87,7 @@ static inline void raise_exception(int index, void *retaddr)
{ {
env->exception_index = index; env->exception_index = index;
cpu_restore_state_from_retaddr(retaddr); cpu_restore_state_from_retaddr(retaddr);
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_raise_illegal_instruction(void) void helper_raise_illegal_instruction(void)
@ -113,7 +113,7 @@ void helper_raise_slot_fpu_disable(void)
void helper_debug(void) void helper_debug(void)
{ {
env->exception_index = EXCP_DEBUG; env->exception_index = EXCP_DEBUG;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_sleep(uint32_t next_pc) void helper_sleep(uint32_t next_pc)
@ -122,7 +122,7 @@ void helper_sleep(uint32_t next_pc)
env->in_sleep = 1; env->in_sleep = 1;
env->exception_index = EXCP_HLT; env->exception_index = EXCP_HLT;
env->pc = next_pc; env->pc = next_pc;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void helper_trapa(uint32_t tra) void helper_trapa(uint32_t tra)
@ -482,7 +482,7 @@ static void update_fpscr(void *retaddr)
if (cause & enable) { if (cause & enable) {
cpu_restore_state_from_retaddr(retaddr); cpu_restore_state_from_retaddr(retaddr);
env->exception_index = 0x120; env->exception_index = 0x120;
cpu_loop_exit(); cpu_loop_exit(env);
} }
} }
} }

View File

@ -316,7 +316,7 @@ static inline target_ulong asi_address_mask(CPUState *env1,
static void raise_exception(int tt) static void raise_exception(int tt)
{ {
env->exception_index = tt; env->exception_index = tt;
cpu_loop_exit(); cpu_loop_exit(env);
} }
void HELPER(raise_exception)(int tt) void HELPER(raise_exception)(int tt)
@ -3724,7 +3724,7 @@ void helper_ldxfsr(uint64_t new_fsr)
void helper_debug(void) void helper_debug(void)
{ {
env->exception_index = EXCP_DEBUG; env->exception_index = EXCP_DEBUG;
cpu_loop_exit(); cpu_loop_exit(env);
} }
#ifndef TARGET_SPARC64 #ifndef TARGET_SPARC64
@ -4424,7 +4424,7 @@ void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)
ret = cpu_sparc_handle_mmu_fault(env, addr, is_write, mmu_idx, 1); ret = cpu_sparc_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
if (ret) { if (ret) {
cpu_restore_state2(retaddr); cpu_restore_state2(retaddr);
cpu_loop_exit(); cpu_loop_exit(env);
} }
env = saved_env; env = saved_env;
} }

View File

@ -16,7 +16,7 @@
void HELPER(exception)(uint32_t excp) void HELPER(exception)(uint32_t excp)
{ {
env->exception_index = excp; env->exception_index = excp;
cpu_loop_exit(); cpu_loop_exit(env);
} }
static target_ulong asr_read(void) static target_ulong asr_read(void)

View File

@ -37,13 +37,14 @@
//#define DEBUG_SIGNAL //#define DEBUG_SIGNAL
static void exception_action(CPUState *env1)
{
#if defined(TARGET_I386) #if defined(TARGET_I386)
#define EXCEPTION_ACTION \ raise_exception_err(env1->exception_index, env1->error_code);
raise_exception_err(env->exception_index, env->error_code)
#else #else
#define EXCEPTION_ACTION \ cpu_loop_exit(env1);
cpu_loop_exit()
#endif #endif
}
/* exit the current TB from a signal handler. The host registers are /* exit the current TB from a signal handler. The host registers are
restored in a state compatible with the CPU emulator restored in a state compatible with the CPU emulator
@ -118,7 +119,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
/* we restore the process signal mask as the sigreturn should /* we restore the process signal mask as the sigreturn should
do it (XXX: use sigsetjmp) */ do it (XXX: use sigsetjmp) */
sigprocmask(SIG_SETMASK, old_set, NULL); sigprocmask(SIG_SETMASK, old_set, NULL);
EXCEPTION_ACTION; exception_action(env);
/* never comes here */ /* never comes here */
return 1; return 1;