1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#define _GNU_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include "debug.h"
#include "box64stack.h"
#include "x64emu.h"
#include "x64emu_private.h"
#include "x64run_private.h"
#include "x64primop.h"
#include "x64trace.h"
#include "x87emu_private.h"
#include "box64context.h"
#include "bridge.h"
#include "modrm.h"
#ifdef TEST_INTERPRETER
uintptr_t TestDF(x64test_t *test, rex_t rex, uintptr_t addr)
#else
uintptr_t RunDF(x64emu_t *emu, rex_t rex, uintptr_t addr)
#endif
{
uint8_t nextop;
int16_t tmp16s;
int64_t tmp64s;
reg64_t *oped;
#ifdef TEST_INTERPRETER
x64emu_t*emu = test->emu;
#endif
nextop = F8;
if(MODREG)
switch(nextop) {
case 0xC0: /* FFREEP STx */
case 0xC1:
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
fpu_do_free(emu, nextop-0xC0);
fpu_do_pop(emu);
break;
case 0xD0: /* FSTP STx, ST0 */
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
ST(nextop&7).q = ST0.q;
fpu_do_pop(emu);
break;
case 0xE0: /* FNSTSW AX */
emu->sw.f.F87_TOP = emu->top&7;
R_AX = emu->sw.x16;
break;
case 0xE8: /* FUCOMIP ST0, STx */
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
fpu_fcomi(emu, ST(nextop&7).d); // bad, should handle QNaN and IA interrupt
fpu_do_pop(emu);
break;
case 0xF0: /* FCOMIP ST0, STx */
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4:
case 0xF5:
case 0xF6:
case 0xF7:
fpu_fcomi(emu, ST(nextop&7).d);
fpu_do_pop(emu);
break;
default:
return 0;
} else
switch((nextop>>3)&7) {
case 0: /* FILD ST0, Gw */
GETEW(0);
tmp16s = EW->sword[0];
fpu_do_push(emu);
ST0.d = tmp16s;
break;
case 1: /* FISTTP Ew, ST0 */
GETEW(0);
tmp16s = ST0.d;
if(isgreater(ST0.d, (double)(int32_t)0x7fff) || isless(ST0.d, -(double)(int32_t)0x8000) || !isfinite(ST0.d))
EW->sword[0] = 0x8000;
else
EW->sword[0] = tmp16s;
fpu_do_pop(emu);
break;
case 2: /* FIST Ew, ST0 */
GETEW(0);
if(isgreater(ST0.d, (double)(int32_t)0x7fff) || isless(ST0.d, -(double)(int32_t)0x8000) || !isfinite(ST0.d))
EW->sword[0] = 0x8000;
else
EW->sword[0] = fpu_round(emu, ST0.d);
break;
case 3: /* FISTP Ew, ST0 */
GETEW(0);
if(isgreater(ST0.d, (double)(int32_t)0x7fff) || isless(ST0.d, -(double)(int32_t)0x8000) || !isfinite(ST0.d))
EW->sword[0] = 0x8000;
else
EW->sword[0] = fpu_round(emu, ST0.d);
fpu_do_pop(emu);
break;
case 4: /* FBLD ST0, tbytes */
GETET(0);
fpu_do_push(emu);
fpu_fbld(emu, (uint8_t*)ED);
break;
case 5: /* FILD ST0, Gq */
GETE8(0);
tmp64s = ED->sq[0];
fpu_do_push(emu);
ST0.d = tmp64s;
STll(0).sq = tmp64s;
STll(0).sref = ST0.sq;
break;
case 6: /* FBSTP tbytes, ST0 */
GETET(0);
fpu_fbst(emu, (uint8_t*)ED);
fpu_do_pop(emu);
break;
case 7: /* FISTP i64 */
GETE8(0);
if(STll(0).sref==ST(0).sq)
ED->sq[0] = STll(0).sq;
else {
if(isgreater(ST0.d, (double)0x7fffffffffffffffLL) || isless(ST0.d, -(double)0x8000000000000000LL) || !isfinite(ST0.d))
ED->sq[0] = 0x8000000000000000LL;
else
ED->sq[0] = fpu_round(emu, ST0.d);
}
fpu_do_pop(emu);
break;
default:
return 0;
}
return addr;
}
|