diff --git a/src/base/emu-i386/cpu.c b/src/base/emu-i386/cpu.c index 8375004d37..795c094be9 100644 --- a/src/base/emu-i386/cpu.c +++ b/src/base/emu-i386/cpu.c @@ -238,29 +238,58 @@ static void fpu_init(void) } #endif -static void fpu_reset(void) +void get_fpu_state(emu_fpstate *fpstate) { - emu_fpstate vm86_fpu_state; - int cpu_vm; - - memset(&vm86_fpu_state, 0, sizeof vm86_fpu_state); - vm86_fpu_state.cwd = 0x0040; //bochs - vm86_fpu_state.ftw = 0xff; //all valid (-> 0x5555 in fsave tag) - cpu_vm = in_dpmi_pm() ? config.cpu_vm_dpmi : config.cpu_vm; + int cpu_vm = in_dpmi_pm() ? config.cpu_vm_dpmi : config.cpu_vm; switch(cpu_vm) { case CPUVM_KVM: - kvm_update_fpu(&vm86_fpu_state); + kvm_get_fpu_state(fpstate); + break; + case CPUVM_NATIVE: + native_dpmi_get_fpu_state(fpstate); + break; case CPUVM_EMU: - e_update_fpu(&vm86_fpu_state); + e_get_fpu_state(fpstate); + break; +#ifdef __i386__ + case CPUVM_VM86: + true_vm86_get_fpu_state(fpstate); + break; +#endif + } +} + +void set_fpu_state(const emu_fpstate *fpstate) +{ + int cpu_vm = in_dpmi_pm() ? config.cpu_vm_dpmi : config.cpu_vm; + switch(cpu_vm) { + case CPUVM_KVM: + kvm_set_fpu_state(fpstate); + break; case CPUVM_NATIVE: - native_dpmi_update_fpu(&vm86_fpu_state); + native_dpmi_set_fpu_state(fpstate); + break; + case CPUVM_EMU: + e_set_fpu_state(fpstate); + break; #ifdef __i386__ case CPUVM_VM86: - true_vm86_update_fpu(&vm86_fpu_state); + true_vm86_set_fpu_state(fpstate); + break; #endif } } +static void fpu_reset(void) +{ + emu_fpstate vm86_fpu_state; + + memset(&vm86_fpu_state, 0, sizeof vm86_fpu_state); + vm86_fpu_state.cwd = 0x0040; //bochs + vm86_fpu_state.ftw = 0xff; //all valid (-> 0x5555 in fsave tag) + set_fpu_state(&vm86_fpu_state); +} + static Bit8u fpu_io_read(ioport_t port) { return 0xff; diff --git a/src/base/emu-i386/do_vm86.c b/src/base/emu-i386/do_vm86.c index 26db1e916d..30d7346e35 100644 --- a/src/base/emu-i386/do_vm86.c +++ b/src/base/emu-i386/do_vm86.c @@ -485,7 +485,7 @@ static int true_vm86(union vm86_union *x) return ret; } -void true_vm86_update_fpu(const emu_fpstate *fpstate) +void true_vm86_set_fpu_state(const emu_fpstate *fpstate) { if (config.cpufxsr) true_vm86_fxsave = *fpstate; @@ -493,12 +493,7 @@ void true_vm86_update_fpu(const emu_fpstate *fpstate) fxsave_to_fsave(fpstate, &true_vm86_fsave); } -void true_vm86_enter(const emu_fpstate *fpstate) -{ - true_vm86_update_fpu(fpstate); -} - -void true_vm86_leave(emu_fpstate *fpstate) +void true_vm86_get_fpu_state(emu_fpstate *fpstate) { if (config.cpufxsr) *fpstate = true_vm86_fxsave; diff --git a/src/base/emu-i386/kvm.c b/src/base/emu-i386/kvm.c index f0d9216500..080c3bf048 100644 --- a/src/base/emu-i386/kvm.c +++ b/src/base/emu-i386/kvm.c @@ -783,7 +783,7 @@ static void set_ldt_seg(struct kvm_segment *seg, unsigned selector) seg->unusable = !desc->present; } -void kvm_update_fpu(const emu_fpstate *fpstate) +void kvm_set_fpu_state(const emu_fpstate *fpstate) { struct kvm_xsave fpu = {}; int ret; @@ -796,12 +796,7 @@ void kvm_update_fpu(const emu_fpstate *fpstate) } } -void kvm_enter(int pm, const emu_fpstate *fpstate) -{ - kvm_update_fpu(fpstate); -} - -void kvm_leave(int pm, emu_fpstate *fpstate) +void kvm_get_fpu_state(emu_fpstate *fpstate) { struct kvm_xsave fpu; int ret = ioctl(vcpufd, KVM_GET_XSAVE, &fpu); diff --git a/src/base/emu-i386/simx86/cpu-emu.c b/src/base/emu-i386/simx86/cpu-emu.c index cdfde521e8..54e2270195 100644 --- a/src/base/emu-i386/simx86/cpu-emu.c +++ b/src/base/emu-i386/simx86/cpu-emu.c @@ -581,7 +581,7 @@ void Cpu2Reg (void) REG(eflags),get_FLAGS(TheCPU.eflags),TheCPU.eflags); } -void e_update_fpu(const emu_fpstate *fpstate) +void e_set_fpu_state(const emu_fpstate *fpstate) { if (CONFIG_CPUSIM) fp87_load_fpstate(fpstate); @@ -593,12 +593,7 @@ void e_update_fpu(const emu_fpstate *fpstate) } } -void e_enter(const emu_fpstate *fpstate) -{ - e_update_fpu(fpstate); -} - -void e_leave(emu_fpstate *fpstate) +void e_get_fpu_state(emu_fpstate *fpstate) { if (CONFIG_CPUSIM) fp87_save_fpstate(fpstate); diff --git a/src/dosext/dpmi/dnative/dnative.c b/src/dosext/dpmi/dnative/dnative.c index af4dec4210..b8f04c62a3 100644 --- a/src/dosext/dpmi/dnative/dnative.c +++ b/src/dosext/dpmi/dnative/dnative.c @@ -109,7 +109,7 @@ static void copy_to_dpmi(sigcontext_t *scp, cpuctx_t *s) scp_fpregs = NULL; } -void native_dpmi_update_fpu(const emu_fpstate *fpstate) +void native_dpmi_set_fpu_state(const emu_fpstate *fpstate) { if (scp_fpregs) { void *fpregs = scp_fpregs; @@ -127,11 +127,6 @@ void native_dpmi_update_fpu(const emu_fpstate *fpstate) } } -void native_dpmi_enter_from_vm86(const emu_fpstate *fpstate) -{ - native_dpmi_update_fpu(fpstate); -} - static void copy_to_emu(cpuctx_t *d, sigcontext_t *scp) { #define _D(x) get_##x(d) = _scp_##x @@ -157,7 +152,7 @@ static void copy_to_emu(cpuctx_t *d, sigcontext_t *scp) scp_fpregs = scp->fpregs; } -void native_dpmi_leave_to_vm86(emu_fpstate *fpstate) +void native_dpmi_get_fpu_state(emu_fpstate *fpstate) { if (scp_fpregs) { void *fpregs = scp_fpregs; diff --git a/src/dosext/dpmi/dnative/dnative.h b/src/dosext/dpmi/dnative/dnative.h index 626340f982..26125a8d22 100644 --- a/src/dosext/dpmi/dnative/dnative.h +++ b/src/dosext/dpmi/dnative/dnative.h @@ -9,9 +9,8 @@ int native_dpmi_control(cpuctx_t *scp); int native_dpmi_exit(cpuctx_t *scp); void native_dpmi_enter(void); void native_dpmi_leave(void); -void native_dpmi_enter_from_vm86(const emu_fpstate *fpstate); -void native_dpmi_leave_to_vm86(emu_fpstate *fpstate); -void native_dpmi_update_fpu(const emu_fpstate *fpstate); +void native_dpmi_get_fpu_state(emu_fpstate *fpstate); +void native_dpmi_set_fpu_state(const emu_fpstate *fpstate); void dpmi_return(sigcontext_t *scp, int retcode); #else @@ -44,15 +43,11 @@ static inline void native_dpmi_leave(void) { } -static inline void native_dpmi_enter_from_vm86(const emu_fpstate *fpstate) +static inline void native_dpmi_set_fpu_state(const emu_fpstate *fpstate) { } -static inline void native_dpmi_leave_to_vm86(emu_fpstate *fpstate) -{ -} - -static inline void native_dpmi_update_fpu(const emu_fpstate *fpstate) +static inline void native_dpmi_get_fpu_state(emu_fpstate *fpstate) { } diff --git a/src/dosext/dpmi/dpmi.c b/src/dosext/dpmi/dpmi.c index 3d036399ba..e0acf3673d 100644 --- a/src/dosext/dpmi/dpmi.c +++ b/src/dosext/dpmi/dpmi.c @@ -418,60 +418,22 @@ static void print_ldt(void) _print_dt(buffer, MAX_SELECTORS, 1); } -static void leave_backend(int be, int pm, emu_fpstate *fpstate) -{ - switch(be) { - case CPUVM_KVM: - kvm_leave(pm, fpstate); - break; - case CPUVM_NATIVE: - native_dpmi_leave_to_vm86(fpstate); - break; - case CPUVM_EMU: - e_leave(fpstate); - break; -#ifdef __i386__ - case CPUVM_VM86: - true_vm86_leave(fpstate); - break; -#endif - } -} - -static void enter_backend(int be, int pm, const emu_fpstate *fpstate) -{ - switch(be) { - case CPUVM_KVM: - kvm_enter(pm, fpstate); - break; - case CPUVM_NATIVE: - native_dpmi_enter_from_vm86(fpstate); - break; - case CPUVM_EMU: - e_enter(fpstate); - break; -#ifdef __i386__ - case CPUVM_VM86: - true_vm86_enter(fpstate); - break; -#endif - } -} - static void dpmi_set_pm(int pm) { + static emu_fpstate fpstate; assert(pm <= 1); if (pm == dpmi_pm) { if (!pm) dosemu_error("DPMI: switch from real to real mode?\n"); return; } - dpmi_pm = pm; if (config.cpu_vm != config.cpu_vm_dpmi) { - static emu_fpstate fpstate; - leave_backend(pm ? config.cpu_vm : config.cpu_vm_dpmi, !pm, &fpstate); - enter_backend(!pm ? config.cpu_vm : config.cpu_vm_dpmi, pm, &fpstate); + get_fpu_state(&fpstate); + dpmi_pm = pm; + set_fpu_state(&fpstate); } + else + dpmi_pm = pm; } static dpmi_pm_block *lookup_pm_blocks_by_addr(dosaddr_t addr) diff --git a/src/include/cpu-emu.h b/src/include/cpu-emu.h index 79c9d1eecb..a01e0aded8 100644 --- a/src/include/cpu-emu.h +++ b/src/include/cpu-emu.h @@ -97,9 +97,8 @@ void reset_emu_cpu (void); int e_dpmi(cpuctx_t *scp); void e_dpmi_b0x(int op,cpuctx_t *scp); extern int in_dpmi_emu; -void e_enter(const emu_fpstate *fpstate); -void e_leave(emu_fpstate *fpstate); -void e_update_fpu(const emu_fpstate *fpstate); +void e_get_fpu_state(emu_fpstate *fpstate); +void e_set_fpu_state(const emu_fpstate *fpstate); /* called from emu-ldt.c */ void InvalidateSegs(void); diff --git a/src/include/cpu.h b/src/include/cpu.h index 1c9c0a9a9e..457394fa90 100644 --- a/src/include/cpu.h +++ b/src/include/cpu.h @@ -108,6 +108,9 @@ void fsave_to_fxsave(const struct emu_fsave *fptr, typedef struct emu_fpxstate emu_fpstate; typedef emu_fpstate *emu_fpregset_t; +void get_fpu_state(emu_fpstate *); +void set_fpu_state(const emu_fpstate *); + union g_reg { greg_t reg; #ifdef __x86_64__ diff --git a/src/include/emu.h b/src/include/emu.h index abf7077d98..5461dc61ab 100644 --- a/src/include/emu.h +++ b/src/include/emu.h @@ -104,9 +104,8 @@ extern FILE *real_stderr; void dos_ctrl_alt_del(void); /* disabled */ extern void vm86_helper(void); -extern void true_vm86_enter(const emu_fpstate *fpstate); -extern void true_vm86_leave(emu_fpstate *fpstate); -extern void true_vm86_update_fpu(const emu_fpstate *fpstate); +extern void true_vm86_get_fpu_state(emu_fpstate *fpstate); +extern void true_vm86_set_fpu_state(const emu_fpstate *fpstate); extern void run_vm86(void); extern void loopstep_run_vm86(void); extern int do_call_back(Bit16u cs, Bit16u ip); diff --git a/src/include/kvm.h b/src/include/kvm.h index 13338dcf37..b7d57f0a9b 100644 --- a/src/include/kvm.h +++ b/src/include/kvm.h @@ -33,9 +33,8 @@ void set_kvm_memory_regions(void); void kvm_set_idt_default(int i); void kvm_set_idt(int i, uint16_t sel, uint32_t offs, int is_32, int tg); -void kvm_enter(int pm, const emu_fpstate *fpstate); -void kvm_leave(int pm, emu_fpstate *fpstate); -void kvm_update_fpu(const emu_fpstate *fpstate); +void kvm_get_fpu_state(emu_fpstate *fpstate); +void kvm_set_fpu_state(const emu_fpstate *fpstate); void kvm_done(void);