linux-user/i386: Split out maybe_handle_vm86_trap

Reduce the number of ifdefs within cpu_loop().

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220107213243.212806-10-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Richard Henderson 2022-01-07 13:32:28 -08:00 committed by Laurent Vivier
parent 0edf34c93e
commit 1ade5b2fed

View File

@ -198,6 +198,17 @@ static void emulate_vsyscall(CPUX86State *env)
} }
#endif #endif
static bool maybe_handle_vm86_trap(CPUX86State *env, int trapnr)
{
#ifndef TARGET_X86_64
if (env->eflags & VM_MASK) {
handle_vm86_trap(env, trapnr);
return true;
}
#endif
return false;
}
void cpu_loop(CPUX86State *env) void cpu_loop(CPUX86State *env)
{ {
CPUState *cs = env_cpu(env); CPUState *cs = env_cpu(env);
@ -259,12 +270,9 @@ void cpu_loop(CPUX86State *env)
break; break;
case EXCP0D_GPF: case EXCP0D_GPF:
/* XXX: potential problem if ABI32 */ /* XXX: potential problem if ABI32 */
#ifndef TARGET_X86_64 if (maybe_handle_vm86_trap(env, trapnr)) {
if (env->eflags & VM_MASK) {
handle_vm86_fault(env);
break; break;
} }
#endif
gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
break; break;
case EXCP0E_PAGE: case EXCP0E_PAGE:
@ -274,22 +282,16 @@ void cpu_loop(CPUX86State *env)
env->cr[2]); env->cr[2]);
break; break;
case EXCP00_DIVZ: case EXCP00_DIVZ:
#ifndef TARGET_X86_64 if (maybe_handle_vm86_trap(env, trapnr)) {
if (env->eflags & VM_MASK) {
handle_vm86_trap(env, trapnr);
break; break;
} }
#endif
gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip); gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip);
break; break;
case EXCP01_DB: case EXCP01_DB:
case EXCP03_INT3: case EXCP03_INT3:
#ifndef TARGET_X86_64 if (maybe_handle_vm86_trap(env, trapnr)) {
if (env->eflags & VM_MASK) {
handle_vm86_trap(env, trapnr);
break; break;
} }
#endif
if (trapnr == EXCP01_DB) { if (trapnr == EXCP01_DB) {
gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip); gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip);
} else { } else {
@ -298,12 +300,9 @@ void cpu_loop(CPUX86State *env)
break; break;
case EXCP04_INTO: case EXCP04_INTO:
case EXCP05_BOUND: case EXCP05_BOUND:
#ifndef TARGET_X86_64 if (maybe_handle_vm86_trap(env, trapnr)) {
if (env->eflags & VM_MASK) {
handle_vm86_trap(env, trapnr);
break; break;
} }
#endif
gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
break; break;
case EXCP06_ILLOP: case EXCP06_ILLOP: