Skip to content

Commit

Permalink
cpu: no longer need to allocate fpstate
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Dec 13, 2022
1 parent a85654d commit 5241bf5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/base/emu-i386/simx86/cpu-emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ static void Scp2Cpu (cpuctx_t *scp)
TheCPU.df_increments = (TheCPU.eflags&DF)?0xfcfeff:0x040201;

/* __fpstate is loaded later on demand for JIT, not used for simulator */
TheCPU.fpstate = __fpstate;
TheCPU.fpstate = &TheCPU._fpstate;
TheCPU._fpstate = *__fpstate;
}

/*
Expand Down Expand Up @@ -641,7 +642,10 @@ static void Cpu2Scp (cpuctx_t *scp, int trapno)
*/
if (!TheCPU.err) _err = 0; //???
if (TheCPU.fpstate == NULL) {
if (!CONFIG_CPUSIM) savefpstate(*__fpstate);
if (!CONFIG_CPUSIM) {
savefpstate(TheCPU._fpstate);
*get_fpstate(scp) = TheCPU._fpstate;
}
/* there is no real need to save and restore the FPU state of the
emulator itself: savefpstate (fnsave) also resets the current FPU
state using fninit; fesetenv then restores trapping of division by
Expand Down
1 change: 1 addition & 0 deletions src/base/emu-i386/simx86/syncpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ typedef struct {

/* should be moved to TSS once implemented */
struct revectored_struct int_revectored;
struct _libc_fpstate _fpstate __attribute__((aligned(16)));
} SynCPU;

union _SynCPU {
Expand Down
6 changes: 4 additions & 2 deletions src/dosext/dpmi/dnative.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ static void copy_to_dpmi(sigcontext_t *scp, cpuctx_t *s)
_C(trapno);
_C(err);
_C(cr2);
_scp_fpstate = (struct _fpstate *)get_fpstate(s);
if (scp->fpstate)
memcpy(scp->fpstate, get_fpstate(s), sizeof(struct _fpstate));
}

static void copy_to_emu(cpuctx_t *d, sigcontext_t *scp)
Expand All @@ -110,7 +111,8 @@ static void copy_to_emu(cpuctx_t *d, sigcontext_t *scp)
_D(trapno);
_D(err);
_D(cr2);
memcpy(get_fpstate(d), _scp_fpstate, sizeof(*get_fpstate(d)));
if (scp->fpstate)
memcpy(get_fpstate(d), _scp_fpstate, sizeof(*get_fpstate(d)));
}

#if WANT_SIGRETURN_WA
Expand Down
14 changes: 4 additions & 10 deletions src/dosext/dpmi/dpmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,17 +1162,12 @@ void GetFreeMemoryInformation(unsigned int *lp)

static void save_context_nofpu(cpuctx_t *d, cpuctx_t *s)
{
*d = *s;
assert(d->fpregs);
d->fpregs = NULL;
memcpy(d, s, REGS_SIZE);
}

static void restore_context_nofpu(cpuctx_t *d, cpuctx_t *s)
{
fpregset_t fptr = d->fpregs;
assert(fptr && !s->fpregs);
*d = *s;
d->fpregs = fptr;
memcpy(d, s, REGS_SIZE); // copy w/o fpstate
}

static void *enter_lpms(cpuctx_t *scp)
Expand Down Expand Up @@ -3247,9 +3242,8 @@ static void dpmi_cleanup(void)
DPMI_free(&host_pm_block_root, DPMI_CLIENT.pm_stack->handle);
hlt_unregister_handler_vm86(DPMI_CLIENT.rmcb_off);
if (!DPMI_CLIENT.RSP_installed) {
cpuctx_t *scp = &DPMI_CLIENT.stack_frame;
DPMIfreeAll();
free(__fpstate);
// free(__fpstate);
}

if (win3x_mode != INACTIVE) {
Expand Down Expand Up @@ -4005,7 +3999,7 @@ void dpmi_init(void)
_gs = 0;
#ifdef __linux__
/* fpu_state needs to be paragraph aligned for fxrstor/fxsave */
__fpstate = aligned_alloc(16, sizeof(*__fpstate));
// __fpstate = aligned_alloc(16, sizeof(*__fpstate));
*__fpstate = *vm86_fpu_state;
#endif
NOCARRY;
Expand Down
7 changes: 4 additions & 3 deletions src/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,10 @@ struct pm_regs {
unsigned trapno;
unsigned err;
unsigned long cr2;
struct _libc_fpstate *fpregs;
struct _libc_fpstate fpregs;
};
typedef struct pm_regs cpuctx_t;
#define REGS_SIZE offsetof(struct pm_regs, fpregs)

#define _es (scp->es)
#define _ds (scp->ds)
Expand All @@ -517,7 +518,7 @@ typedef struct pm_regs cpuctx_t;
#define get_trapno(s) ((s)->trapno)
#define get_err(s) ((s)->err)
#define get_cr2(s) ((s)->cr2)
#define get_fpstate(s) ((s)->fpregs)
#define get_fpstate(s) (&(s)->fpregs)
#define _edi get_edi(scp)
#define _esi get_esi(scp)
#define _ebp get_ebp(scp)
Expand Down Expand Up @@ -546,7 +547,7 @@ typedef struct pm_regs cpuctx_t;
#define _eflags_ (scp->eflags)
#define _cr2 (scp->cr2)
#define _trapno (scp->trapno)
#define __fpstate (scp->fpregs)
#define __fpstate (&scp->fpregs)
/* compatibility */
#define _rdi _edi
#define _rsi _esi
Expand Down

0 comments on commit 5241bf5

Please sign in to comment.