Save/Restore FPU TOP-OF-STACK in FXSAVE/FXRSTOR instructions

This commit is contained in:
Stanislav Shwartsman 2003-01-23 18:33:35 +00:00
parent e1b8e5b9f9
commit 5222261080
5 changed files with 18 additions and 24 deletions

View File

@ -44,7 +44,7 @@ struct BxFpuRegisters {
s32 fos;
u32 fill0; /* to make sure the following aligns on an 8byte boundary */
u64 st_space[16]; /* 8*16 bytes per FP-reg (aligned) = 128 bytes */
unsigned char ftop;
unsigned char tos;
unsigned char no_update;
unsigned char rm;
unsigned char alimit;
@ -193,6 +193,7 @@ typedef union FpuMmxRegisters
#define FPU_TWD (BX_CPU_THIS_PTR the_i387.soft.twd)
#define FPU_SWD (BX_CPU_THIS_PTR the_i387.soft.swd)
#define FPU_TOS (BX_CPU_THIS_PTR the_i387.soft.tos)
#define BX_READ_MMX_REG(index) \
(BX_CPU_THIS_PTR the_i387.mmx.mmx[index].packed_mmx_register)
@ -203,8 +204,6 @@ typedef union FpuMmxRegisters
BX_CPU_THIS_PTR the_i387.mmx.mmx[index].exp = 0xffff; \
}
#define FPU_TOS (BX_CPU_THIS_PTR the_i387.soft.ftop)
#endif
#endif

View File

@ -86,10 +86,14 @@ void BX_CPU_C::FXSAVE(bxInstruction_c *i)
#if BX_SUPPORT_SSE >= 1
BxPackedXmmRegister xmm;
Bit16u twd = BX_CPU_THIS_PTR the_i387.soft.twd, tag_byte = 0;
Bit16u status_w = BX_CPU_THIS_PTR the_i387.soft.swd;
Bit16u tos = BX_CPU_THIS_PTR the_i387.soft.tos;
unsigned index;
xmm.xmm16u(0) = BX_CPU_THIS_PTR the_i387.soft.cwd;
xmm.xmm16u(1) = BX_CPU_THIS_PTR the_i387.soft.swd;
#define SW_TOP (0x3800)
xmm.xmm16u(0) = (BX_CPU_THIS_PTR the_i387.soft.cwd);
xmm.xmm16u(1) = (status_w & ~SW_TOP & 0xffff) | ((tos << 11) & SW_TOP);
if(twd & 0x0003 != 0x0003) tag_byte |= 0x0100;
if(twd & 0x000c != 0x000c) tag_byte |= 0x0200;
@ -168,8 +172,8 @@ void BX_CPU_C::FXRSTOR(bxInstruction_c *i)
BX_CPU_THIS_PTR the_i387.soft.cwd = xmm.xmm16u(0);
BX_CPU_THIS_PTR the_i387.soft.swd = xmm.xmm16u(1);
BX_CPU_THIS_PTR the_i387.soft.tos = (xmm.xmm16u(1) >> 11) & 0x07;
/* TOS restore still not implemented */
/* FOO/FPU IP restore still not implemented */
tag_byte = xmm.xmm16u(2);

View File

@ -3,11 +3,6 @@
/* XMM REGISTER */
#if 0 // does not seem to be used
typedef Bit32u Float32;
typedef Bit64u Float64;
#endif
typedef union bx_xmm_reg_t {
Bit8s _sbyte[16];
Bit16s _s16[8];
@ -45,10 +40,6 @@ typedef union bx_xmm_reg_t {
#define xmm64u(i) _u64[(i)]
#endif
/* floating point representation: single and double precission */
#define xmm32f(i) xmm32u(i)
#define xmm64f(i) xmm64u(i)
#define BX_READ_XMM_REG(index) (BX_CPU_THIS_PTR xmm[index])
#define BX_WRITE_XMM_REG(index, reg) { BX_CPU_THIS_PTR xmm[index] = reg; }

View File

@ -1,6 +1,6 @@
/*---------------------------------------------------------------------------+
| fpu_entry.c |
| $Id: fpu_entry.c,v 1.4 2001-10-06 03:53:46 bdenney Exp $
| $Id: fpu_entry.c,v 1.5 2003-01-23 18:33:35 sshwarts Exp $
| |
| The entry functions for wm-FPU-emu |
| |
@ -678,7 +678,7 @@ void math_abort(struct info * info, unsigned int signal)
#define S387 ((struct i387_soft_struct *)s387)
#define sstatus_word() \
((S387->swd & ~SW_Top & 0xffff) | ((S387->ftop << SW_Top_Shift) & SW_Top))
((S387->swd & ~SW_Top & 0xffff) | ((S387->tos << SW_Top_Shift) & SW_Top))
int restore_i387_soft(void *s387, struct _fpstate *buf)
{
@ -693,8 +693,8 @@ int restore_i387_soft(void *s387, struct _fpstate *buf)
d += 7*4;
S387->ftop = (S387->swd >> SW_Top_Shift) & 7;
offset = (S387->ftop & 7) * 10;
S387->tos = (S387->swd >> SW_Top_Shift) & 7;
offset = (S387->tos & 7) * 10;
other = 80 - offset;
RE_ENTRANT_CHECK_OFF;
@ -708,7 +708,7 @@ int restore_i387_soft(void *s387, struct _fpstate *buf)
/* The tags may need to be corrected now. */
tags = S387->twd;
newtop = S387->ftop;
newtop = S387->tos;
for ( i = 0; i < 8; i++ )
{
regnr = (i+newtop) & 7;
@ -729,7 +729,7 @@ int restore_i387_soft(void *s387, struct _fpstate *buf)
int save_i387_soft(void *s387, struct _fpstate * buf)
{
u_char *d = (u_char *)buf;
int offset = (S387->ftop & 7) * 10, other = 80 - offset;
int offset = (S387->tos & 7) * 10, other = 80 - offset;
RE_ENTRANT_CHECK_OFF;
FPU_verify_area(VERIFY_WRITE, d, 7*4 + 8*10);

View File

@ -1,6 +1,6 @@
/*---------------------------------------------------------------------------+
| fpu_system.h |
| $Id: fpu_system.h,v 1.4 2002-09-09 16:11:25 bdenney Exp $
| $Id: fpu_system.h,v 1.5 2003-01-23 18:33:35 sshwarts Exp $
| |
| Copyright (C) 1992,1994,1997 |
| W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
@ -64,7 +64,7 @@
#define control_word (I387.soft.cwd)
#define fpu_tag_word (I387.soft.twd)
#define registers (I387.soft.st_space)
#define top (I387.soft.ftop)
#define top (I387.soft.tos)
#define instruction_address (*(struct address *)&I387.soft.fip)
#define operand_address (*(struct address *)&I387.soft.foo)
@ -157,7 +157,7 @@ extern i387_t *current_i387;
#define control_word (I387.soft.cwd)
#define fpu_tag_word (I387.soft.twd)
#define registers (I387.soft.st_space)
#define top (I387.soft.ftop)
#define top (I387.soft.tos)
#define instruction_address (*(struct address *)&I387.soft.fip)
#define operand_address (*(struct address *)&I387.soft.foo)