2003-05-15 20:41:17 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (c) 2002 Stanislav Shwartsman
|
|
|
|
// Written by Stanislav Shwartsman <gate@fidonet.org.il>
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-09-09 20:11:25 +04:00
|
|
|
#ifndef BX_I387_RELATED_EXTENSIONS_H
|
|
|
|
#define BX_I387_RELATED_EXTENSIONS_H
|
|
|
|
|
2003-04-13 01:02:08 +04:00
|
|
|
#if BX_SUPPORT_FPU
|
|
|
|
|
|
|
|
//
|
|
|
|
// Minimal i387 structure
|
|
|
|
//
|
2003-10-04 15:04:10 +04:00
|
|
|
struct i387_t
|
|
|
|
{
|
2003-12-30 00:47:36 +03:00
|
|
|
Bit32u cwd; // control word
|
|
|
|
Bit32u swd; // status word
|
|
|
|
Bit32u twd; // tag word
|
|
|
|
Bit32u fip;
|
|
|
|
Bit32u fcs;
|
|
|
|
Bit32u foo;
|
|
|
|
Bit32u fos;
|
2003-10-04 15:04:10 +04:00
|
|
|
|
2003-04-13 01:02:08 +04:00
|
|
|
unsigned char tos;
|
|
|
|
unsigned char no_update;
|
|
|
|
unsigned char rm;
|
2004-02-01 23:19:52 +03:00
|
|
|
unsigned char align8;
|
2003-10-04 15:04:10 +04:00
|
|
|
|
|
|
|
Bit64u st_space[16]; // 8*16 bytes per FP-reg (aligned) = 128 bytes
|
2003-04-13 01:02:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Endian Host byte order Guest (x86) byte order
|
|
|
|
// ======================================================
|
|
|
|
// Little FFFFFFFFEEAAAAAA FFFFFFFFEEAAAAAA
|
|
|
|
// Big AAAAAAEEFFFFFFFF FFFFFFFFEEAAAAAA
|
|
|
|
//
|
|
|
|
// Legend: F - fraction/mmx
|
|
|
|
// E - exponent
|
2003-04-16 22:38:53 +04:00
|
|
|
// A - alignment
|
2002-09-09 20:11:25 +04:00
|
|
|
|
2003-01-23 20:53:11 +03:00
|
|
|
#ifdef BX_BIG_ENDIAN
|
2003-08-01 13:32:33 +04:00
|
|
|
struct bx_fpu_reg_t {
|
2003-04-16 22:38:53 +04:00
|
|
|
Bit16u alignment1, alignment2, alignment3;
|
2003-04-13 01:02:08 +04:00
|
|
|
Bit16s exp; /* Signed quantity used in internal arithmetic. */
|
|
|
|
Bit32u sigh;
|
|
|
|
Bit32u sigl;
|
2003-01-23 20:53:11 +03:00
|
|
|
} GCC_ATTRIBUTE((aligned(16), packed));
|
|
|
|
#else
|
2003-08-01 13:32:33 +04:00
|
|
|
struct bx_fpu_reg_t {
|
2003-04-13 01:02:08 +04:00
|
|
|
Bit32u sigl;
|
|
|
|
Bit32u sigh;
|
|
|
|
Bit16s exp; /* Signed quantity used in internal arithmetic. */
|
2003-04-16 22:38:53 +04:00
|
|
|
Bit16u alignment1, alignment2, alignment3;
|
2003-01-23 20:53:11 +03:00
|
|
|
} GCC_ATTRIBUTE((aligned(16), packed));
|
|
|
|
#endif
|
|
|
|
|
2003-10-25 14:32:54 +04:00
|
|
|
typedef struct bx_fpu_reg_t FPU_REG;
|
|
|
|
|
2003-01-23 20:53:11 +03:00
|
|
|
#define BX_FPU_REG(index) \
|
2003-04-13 01:02:08 +04:00
|
|
|
(BX_CPU_THIS_PTR the_i387.st_space[index*2])
|
|
|
|
|
|
|
|
#define FPU_PARTIAL_STATUS (BX_CPU_THIS_PTR the_i387.swd)
|
2004-02-06 15:45:43 +03:00
|
|
|
#define FPU_CONTROL_WORD (BX_CPU_THIS_PTR the_i387.cwd)
|
2003-08-01 13:32:33 +04:00
|
|
|
#define FPU_TAG_WORD (BX_CPU_THIS_PTR the_i387.twd)
|
2003-04-13 01:02:08 +04:00
|
|
|
#define FPU_TOS (BX_CPU_THIS_PTR the_i387.tos)
|
|
|
|
|
2003-08-01 13:32:33 +04:00
|
|
|
#define FPU_SW_SUMMARY (0x0080) /* exception summary */
|
|
|
|
|
2003-10-25 14:32:54 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
int FPU_tagof(FPU_REG *reg) BX_CPP_AttrRegparmN(1);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2003-01-23 20:53:11 +03:00
|
|
|
|
2002-09-09 20:11:25 +04:00
|
|
|
#if BX_SUPPORT_MMX
|
2003-04-13 01:02:08 +04:00
|
|
|
|
2002-09-09 20:11:25 +04:00
|
|
|
typedef union {
|
|
|
|
Bit8u u8;
|
|
|
|
Bit8s s8;
|
|
|
|
} MMX_BYTE;
|
|
|
|
|
|
|
|
typedef union {
|
|
|
|
Bit16u u16;
|
|
|
|
Bit16s s16;
|
|
|
|
struct {
|
|
|
|
#ifdef BX_BIG_ENDIAN
|
|
|
|
MMX_BYTE hi;
|
|
|
|
MMX_BYTE lo;
|
|
|
|
#else
|
|
|
|
MMX_BYTE lo;
|
|
|
|
MMX_BYTE hi;
|
|
|
|
#endif
|
|
|
|
} bytes;
|
|
|
|
} MMX_WORD;
|
|
|
|
|
|
|
|
typedef union {
|
|
|
|
Bit32u u32;
|
|
|
|
Bit32s s32;
|
|
|
|
struct {
|
|
|
|
#ifdef BX_BIG_ENDIAN
|
|
|
|
MMX_WORD hi;
|
|
|
|
MMX_WORD lo;
|
|
|
|
#else
|
|
|
|
MMX_WORD lo;
|
|
|
|
MMX_WORD hi;
|
|
|
|
#endif
|
|
|
|
} words;
|
|
|
|
} MMX_DWORD;
|
|
|
|
|
|
|
|
typedef union {
|
|
|
|
Bit64u u64;
|
|
|
|
Bit64s s64;
|
|
|
|
struct {
|
|
|
|
#ifdef BX_BIG_ENDIAN
|
|
|
|
MMX_DWORD hi;
|
|
|
|
MMX_DWORD lo;
|
|
|
|
#else
|
|
|
|
MMX_DWORD lo;
|
|
|
|
MMX_DWORD hi;
|
|
|
|
#endif
|
|
|
|
} dwords;
|
|
|
|
} MMX_QWORD, BxPackedMmxRegister;
|
|
|
|
|
|
|
|
#define MMXSB0(reg) (reg.dwords.lo.words.lo.bytes.lo.s8)
|
|
|
|
#define MMXSB1(reg) (reg.dwords.lo.words.lo.bytes.hi.s8)
|
|
|
|
#define MMXSB2(reg) (reg.dwords.lo.words.hi.bytes.lo.s8)
|
|
|
|
#define MMXSB3(reg) (reg.dwords.lo.words.hi.bytes.hi.s8)
|
|
|
|
#define MMXSB4(reg) (reg.dwords.hi.words.lo.bytes.lo.s8)
|
|
|
|
#define MMXSB5(reg) (reg.dwords.hi.words.lo.bytes.hi.s8)
|
|
|
|
#define MMXSB6(reg) (reg.dwords.hi.words.hi.bytes.lo.s8)
|
|
|
|
#define MMXSB7(reg) (reg.dwords.hi.words.hi.bytes.hi.s8)
|
|
|
|
|
|
|
|
#define MMXUB0(reg) (reg.dwords.lo.words.lo.bytes.lo.u8)
|
|
|
|
#define MMXUB1(reg) (reg.dwords.lo.words.lo.bytes.hi.u8)
|
|
|
|
#define MMXUB2(reg) (reg.dwords.lo.words.hi.bytes.lo.u8)
|
|
|
|
#define MMXUB3(reg) (reg.dwords.lo.words.hi.bytes.hi.u8)
|
|
|
|
#define MMXUB4(reg) (reg.dwords.hi.words.lo.bytes.lo.u8)
|
|
|
|
#define MMXUB5(reg) (reg.dwords.hi.words.lo.bytes.hi.u8)
|
|
|
|
#define MMXUB6(reg) (reg.dwords.hi.words.hi.bytes.lo.u8)
|
|
|
|
#define MMXUB7(reg) (reg.dwords.hi.words.hi.bytes.hi.u8)
|
|
|
|
|
|
|
|
#define MMXSW0(reg) (reg.dwords.lo.words.lo.s16)
|
|
|
|
#define MMXSW1(reg) (reg.dwords.lo.words.hi.s16)
|
|
|
|
#define MMXSW2(reg) (reg.dwords.hi.words.lo.s16)
|
|
|
|
#define MMXSW3(reg) (reg.dwords.hi.words.hi.s16)
|
|
|
|
|
|
|
|
#define MMXUW0(reg) (reg.dwords.lo.words.lo.u16)
|
|
|
|
#define MMXUW1(reg) (reg.dwords.lo.words.hi.u16)
|
|
|
|
#define MMXUW2(reg) (reg.dwords.hi.words.lo.u16)
|
|
|
|
#define MMXUW3(reg) (reg.dwords.hi.words.hi.u16)
|
|
|
|
|
|
|
|
#define MMXSD0(reg) (reg.dwords.lo.s32)
|
|
|
|
#define MMXSD1(reg) (reg.dwords.hi.s32)
|
|
|
|
|
|
|
|
#define MMXUD0(reg) (reg.dwords.lo.u32)
|
|
|
|
#define MMXUD1(reg) (reg.dwords.hi.u32)
|
|
|
|
|
|
|
|
#define MMXSQ(reg) (reg.s64)
|
|
|
|
#define MMXUQ(reg) (reg.u64)
|
|
|
|
|
2002-11-30 20:15:59 +03:00
|
|
|
// Endian Host byte order Guest (x86) byte order
|
|
|
|
// ======================================================
|
|
|
|
// Little FFFFFFFFEEAAAAAA FFFFFFFFEEAAAAAA
|
|
|
|
// Big AAAAAAEEFFFFFFFF FFFFFFFFEEAAAAAA
|
|
|
|
//
|
|
|
|
// Legend: F - fraction/mmx
|
|
|
|
// E - exponent
|
2003-04-16 22:38:53 +04:00
|
|
|
// A - alignment
|
2002-11-30 20:15:59 +03:00
|
|
|
|
|
|
|
#ifdef BX_BIG_ENDIAN
|
2003-04-13 01:02:08 +04:00
|
|
|
struct bx_mmx_reg_t {
|
2003-04-16 22:38:53 +04:00
|
|
|
Bit16u alignment1, alignment2, alignment3;
|
2003-04-13 01:02:08 +04:00
|
|
|
Bit16u exp; /* 2 byte FP-reg exponent */
|
2002-09-09 20:11:25 +04:00
|
|
|
BxPackedMmxRegister packed_mmx_register;
|
2003-04-13 01:02:08 +04:00
|
|
|
} GCC_ATTRIBUTE((aligned(16), packed));
|
2002-11-30 20:15:59 +03:00
|
|
|
#else
|
2003-04-13 01:02:08 +04:00
|
|
|
struct bx_mmx_reg_t {
|
2002-11-30 20:15:59 +03:00
|
|
|
BxPackedMmxRegister packed_mmx_register;
|
2003-04-13 01:02:08 +04:00
|
|
|
Bit16u exp; /* 2 byte FP reg exponent */
|
2003-04-16 22:38:53 +04:00
|
|
|
Bit16u alignment1, alignment2, alignment3;
|
2003-04-13 01:02:08 +04:00
|
|
|
} GCC_ATTRIBUTE((aligned(16), packed));
|
2002-11-30 20:15:59 +03:00
|
|
|
#endif
|
2002-09-09 20:11:25 +04:00
|
|
|
|
2003-04-13 01:02:08 +04:00
|
|
|
#define BX_MMX_REG(index) \
|
|
|
|
(((bx_mmx_reg_t*)(BX_CPU_THIS_PTR the_i387.st_space))[index])
|
2002-11-30 17:42:41 +03:00
|
|
|
|
2003-04-13 01:02:08 +04:00
|
|
|
#define BX_READ_MMX_REG(index) \
|
|
|
|
((BX_MMX_REG(index)).packed_mmx_register)
|
2002-11-30 17:42:41 +03:00
|
|
|
|
2003-04-13 01:02:08 +04:00
|
|
|
#define BX_WRITE_MMX_REG(index, value) \
|
|
|
|
{ \
|
|
|
|
(BX_MMX_REG(index)).packed_mmx_register = value; \
|
|
|
|
(BX_MMX_REG(index)).exp = 0xffff; \
|
2002-11-30 17:42:41 +03:00
|
|
|
}
|
|
|
|
|
2003-04-13 01:02:08 +04:00
|
|
|
#endif /* BX_SUPPORT_MMX */
|
|
|
|
|
|
|
|
#endif /* BX_SUPPORT_FPU */
|
2002-11-30 17:42:41 +03:00
|
|
|
|
2002-09-09 20:11:25 +04:00
|
|
|
#endif
|