ReactOS  0.4.14-dev-98-gb0d4763
fpu.h
Go to the documentation of this file.
1 /*
2  * Fast486 386/486 CPU Emulation Library
3  * fpu.h
4  *
5  * Copyright (C) 2015 Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef _FPU_H_
23 #define _FPU_H_
24 
25 #pragma once
26 
27 #include "opcodes.h"
28 
29 /* DEFINES ********************************************************************/
30 
31 #define FPU_CHECK() if (State->ControlRegisters[FAST486_REG_CR0] & (FAST486_CR0_EM | FAST486_CR0_TS)) \
32  { \
33  Fast486Exception(State, FAST486_EXCEPTION_NM); \
34  return; \
35  }
36 #define FPU_INDEX(i) ((State->FpuStatus.Top + (i)) % FAST486_NUM_FPU_REGS)
37 #define FPU_ST(i) State->FpuRegisters[FPU_INDEX(i)]
38 
39 #define FPU_GET_TAG(i) ((State->FpuTag >> (FPU_INDEX(i) * 2)) & 3)
40 #define FPU_SET_TAG(i, t) { \
41  State->FpuTag &= ~((1 << (FPU_INDEX(i) * 2)) | (1 << ((FPU_INDEX(i) * 2) + 1))); \
42  State->FpuTag |= ((t) & 3) << (FPU_INDEX(i) * 2); \
43  }
44 #define FPU_UPDATE_TAG(i) FPU_SET_TAG((i), Fast486FpuGetValueTag(&FPU_ST(i)))
45 #define FPU_SAVE_LAST_INST() { \
46  State->FpuLastInstPtr = State->SavedInstPtr; \
47  State->FpuLastCodeSel = State->SegmentRegs[FAST486_REG_CS].Selector; \
48  }
49 #define FPU_SAVE_LAST_OPERAND() { \
50  State->FpuLastOpPtr.Long = ModRegRm.MemoryAddress; \
51  State->FpuLastDataSel = (State->PrefixFlags & FAST486_PREFIX_SEG) \
52  ? State->SegmentOverride : FAST486_REG_DS; \
53  }
54 
55 #define FPU_REAL4_BIAS 0x7F
56 #define FPU_REAL8_BIAS 0x3FF
57 #define FPU_REAL10_BIAS 0x3FFF
58 #define FPU_MAX_EXPONENT 0x7FFE
59 #define FPU_MANTISSA_HIGH_BIT 0x8000000000000000ULL
60 #define FPU_INDEFINITE_MANTISSA 0xC000000000000000ULL
61 #define FPU_REAL4_INFINITY 0x7F800000
62 #define FPU_REAL4_INDEFINITE 0xFFC00000
63 #define FPU_REAL8_INFINITY 0x7FF0000000000000ULL
64 #define FPU_REAL8_INDEFINITE 0xFFF8000000000000ULL
65 
66 #define FPU_IS_NORMALIZED(x) (FPU_IS_ZERO(x) || (((x)->Mantissa & FPU_MANTISSA_HIGH_BIT) != 0ULL))
67 #define FPU_IS_ZERO(x) ((x)->Mantissa == 0ULL)
68 #define FPU_IS_NAN(x) ((x)->Exponent == (FPU_MAX_EXPONENT + 1))
69 #define FPU_IS_INFINITY(x) (FPU_IS_NAN(x) && ((x)->Mantissa == FPU_MANTISSA_HIGH_BIT))
70 #define FPU_IS_POS_INF(x) (FPU_IS_INFINITY(x) && !(x)->Sign)
71 #define FPU_IS_NEG_INF(x) (FPU_IS_INFINITY(x) && (x)->Sign)
72 #define FPU_IS_INDEFINITE(x) (FPU_IS_NAN(x) && !FPU_IS_INFINITY(x))
73 
74 #define INVERSE_NUMBERS_COUNT 50
75 
76 enum
77 {
81 };
82 
83 enum
84 {
89 };
90 
91 enum
92 {
97 };
98 
99 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD8);
100 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD9);
101 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDA);
102 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDB);
103 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDC);
104 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDD);
105 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDE);
106 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDF);
107 
108 #endif // _FPU_H_
109 
110 /* EOF */
FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD8)
Definition: fpu.c:1808