mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-08-04 10:01:46 +00:00
cpu-exec: Move interrupt handling out of cpu_exec()
Simplify cpu_exec() by extracting interrupt handling code outside of cpu_exec() into a new static inline function cpu_handle_interrupt(). Backports commit c385e6e49763c6dd5dbbd90fadde95d986f8bd38 from qemu
This commit is contained in:
parent
c1b52a4387
commit
d4ef96abf2
|
@ -258,50 +258,11 @@ static inline bool cpu_handle_exception(struct uc_struct *uc, CPUState *cpu, int
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* main execution loop */
|
static inline void cpu_handle_interrupt(CPUState *cpu,
|
||||||
|
TranslationBlock **last_tb)
|
||||||
int cpu_exec(struct uc_struct *uc, CPUState *cpu)
|
|
||||||
{
|
{
|
||||||
CPUArchState *env = cpu->env_ptr;
|
CPUClass *cc = CPU_GET_CLASS(cpu->uc, cpu);
|
||||||
CPUClass *cc = CPU_GET_CLASS(uc, cpu);
|
int interrupt_request = cpu->interrupt_request;
|
||||||
#ifdef TARGET_I386
|
|
||||||
X86CPU *x86_cpu = X86_CPU(uc, cpu);
|
|
||||||
#endif
|
|
||||||
int ret, interrupt_request;
|
|
||||||
TranslationBlock *tb, *last_tb;
|
|
||||||
int tb_exit = 0;
|
|
||||||
|
|
||||||
if (cpu_handle_halt(cpu)) {
|
|
||||||
return EXCP_HALTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
uc->current_cpu = cpu;
|
|
||||||
atomic_mb_set(&uc->tcg_current_cpu, cpu);
|
|
||||||
|
|
||||||
if (unlikely(atomic_mb_read(&uc->exit_request))) {
|
|
||||||
cpu->exit_request = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cc->cpu_exec_enter(cpu);
|
|
||||||
cpu->exception_index = -1;
|
|
||||||
env->invalid_error = UC_ERR_OK;
|
|
||||||
|
|
||||||
for(;;) {
|
|
||||||
/* prepare setjmp context for exception handling */
|
|
||||||
if (sigsetjmp(cpu->jmp_env, 0) == 0) {
|
|
||||||
if (uc->stop_request || uc->invalid_error) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if an exception is pending, we execute it here */
|
|
||||||
if (cpu_handle_exception(uc, cpu, &ret)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_tb = NULL; /* forget the last executed TB after exception */
|
|
||||||
cpu->tb_flushed = false; /* reset before first TB lookup */
|
|
||||||
for(;;) {
|
|
||||||
interrupt_request = cpu->interrupt_request;
|
|
||||||
|
|
||||||
if (unlikely(interrupt_request)) {
|
if (unlikely(interrupt_request)) {
|
||||||
if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) {
|
if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) {
|
||||||
|
@ -336,7 +297,7 @@ int cpu_exec(struct uc_struct *uc, CPUState *cpu)
|
||||||
True when it is, and we should restart on a new TB,
|
True when it is, and we should restart on a new TB,
|
||||||
and via longjmp via cpu_loop_exit. */
|
and via longjmp via cpu_loop_exit. */
|
||||||
if (cc->cpu_exec_interrupt(cpu, interrupt_request)) {
|
if (cc->cpu_exec_interrupt(cpu, interrupt_request)) {
|
||||||
last_tb = NULL;
|
*last_tb = NULL;
|
||||||
}
|
}
|
||||||
/* Don't use the cached interrupt_request value,
|
/* Don't use the cached interrupt_request value,
|
||||||
do_interrupt may have updated the EXITTB flag. */
|
do_interrupt may have updated the EXITTB flag. */
|
||||||
|
@ -344,7 +305,7 @@ int cpu_exec(struct uc_struct *uc, CPUState *cpu)
|
||||||
cpu->interrupt_request &= ~CPU_INTERRUPT_EXITTB;
|
cpu->interrupt_request &= ~CPU_INTERRUPT_EXITTB;
|
||||||
/* ensure that no TB jump will be modified as
|
/* ensure that no TB jump will be modified as
|
||||||
the program flow was changed */
|
the program flow was changed */
|
||||||
last_tb = NULL;
|
*last_tb = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unlikely(cpu->exit_request)) {
|
if (unlikely(cpu->exit_request)) {
|
||||||
|
@ -352,6 +313,52 @@ int cpu_exec(struct uc_struct *uc, CPUState *cpu)
|
||||||
cpu->exception_index = EXCP_INTERRUPT;
|
cpu->exception_index = EXCP_INTERRUPT;
|
||||||
cpu_loop_exit(cpu);
|
cpu_loop_exit(cpu);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* main execution loop */
|
||||||
|
|
||||||
|
int cpu_exec(struct uc_struct *uc, CPUState *cpu)
|
||||||
|
{
|
||||||
|
CPUArchState *env = cpu->env_ptr;
|
||||||
|
CPUClass *cc = CPU_GET_CLASS(uc, cpu);
|
||||||
|
#ifdef TARGET_I386
|
||||||
|
X86CPU *x86_cpu = X86_CPU(uc, cpu);
|
||||||
|
#endif
|
||||||
|
int ret;
|
||||||
|
TranslationBlock *tb, *last_tb;
|
||||||
|
int tb_exit = 0;
|
||||||
|
|
||||||
|
if (cpu_handle_halt(cpu)) {
|
||||||
|
return EXCP_HALTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
uc->current_cpu = cpu;
|
||||||
|
atomic_mb_set(&uc->tcg_current_cpu, cpu);
|
||||||
|
|
||||||
|
if (unlikely(atomic_mb_read(&uc->exit_request))) {
|
||||||
|
cpu->exit_request = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cc->cpu_exec_enter(cpu);
|
||||||
|
cpu->exception_index = -1;
|
||||||
|
env->invalid_error = UC_ERR_OK;
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
/* prepare setjmp context for exception handling */
|
||||||
|
if (sigsetjmp(cpu->jmp_env, 0) == 0) {
|
||||||
|
if (uc->stop_request || uc->invalid_error) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if an exception is pending, we execute it here */
|
||||||
|
if (cpu_handle_exception(uc, cpu, &ret)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
last_tb = NULL; /* forget the last executed TB after exception */
|
||||||
|
cpu->tb_flushed = false; /* reset before first TB lookup */
|
||||||
|
for(;;) {
|
||||||
|
cpu_handle_interrupt(cpu, &last_tb);
|
||||||
tb = tb_find_fast(cpu, &last_tb, tb_exit);
|
tb = tb_find_fast(cpu, &last_tb, tb_exit);
|
||||||
if (!tb) { // invalid TB due to invalid code?
|
if (!tb) { // invalid TB due to invalid code?
|
||||||
uc->invalid_error = UC_ERR_FETCH_UNMAPPED;
|
uc->invalid_error = UC_ERR_FETCH_UNMAPPED;
|
||||||
|
|
Loading…
Reference in a new issue