1 | /*
|
---|
2 | * i386 micro operations
|
---|
3 | *
|
---|
4 | * Copyright (c) 2003 Fabrice Bellard
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | #define ASM_SOFTMMU
|
---|
22 | #include "exec.h"
|
---|
23 |
|
---|
24 | /* n must be a constant to be efficient */
|
---|
25 | static inline target_long lshift(target_long x, int n)
|
---|
26 | {
|
---|
27 | if (n >= 0)
|
---|
28 | return x << n;
|
---|
29 | else
|
---|
30 | return x >> (-n);
|
---|
31 | }
|
---|
32 |
|
---|
33 | /* we define the various pieces of code used by the JIT */
|
---|
34 |
|
---|
35 | #define REG EAX
|
---|
36 | #define REGNAME _EAX
|
---|
37 | #include "opreg_template.h"
|
---|
38 | #undef REG
|
---|
39 | #undef REGNAME
|
---|
40 |
|
---|
41 | #define REG ECX
|
---|
42 | #define REGNAME _ECX
|
---|
43 | #include "opreg_template.h"
|
---|
44 | #undef REG
|
---|
45 | #undef REGNAME
|
---|
46 |
|
---|
47 | #define REG EDX
|
---|
48 | #define REGNAME _EDX
|
---|
49 | #include "opreg_template.h"
|
---|
50 | #undef REG
|
---|
51 | #undef REGNAME
|
---|
52 |
|
---|
53 | #define REG EBX
|
---|
54 | #define REGNAME _EBX
|
---|
55 | #include "opreg_template.h"
|
---|
56 | #undef REG
|
---|
57 | #undef REGNAME
|
---|
58 |
|
---|
59 | #define REG ESP
|
---|
60 | #define REGNAME _ESP
|
---|
61 | #include "opreg_template.h"
|
---|
62 | #undef REG
|
---|
63 | #undef REGNAME
|
---|
64 |
|
---|
65 | #define REG EBP
|
---|
66 | #define REGNAME _EBP
|
---|
67 | #include "opreg_template.h"
|
---|
68 | #undef REG
|
---|
69 | #undef REGNAME
|
---|
70 |
|
---|
71 | #define REG ESI
|
---|
72 | #define REGNAME _ESI
|
---|
73 | #include "opreg_template.h"
|
---|
74 | #undef REG
|
---|
75 | #undef REGNAME
|
---|
76 |
|
---|
77 | #define REG EDI
|
---|
78 | #define REGNAME _EDI
|
---|
79 | #include "opreg_template.h"
|
---|
80 | #undef REG
|
---|
81 | #undef REGNAME
|
---|
82 |
|
---|
83 | #ifdef TARGET_X86_64
|
---|
84 |
|
---|
85 | #define REG (env->regs[8])
|
---|
86 | #define REGNAME _R8
|
---|
87 | #include "opreg_template.h"
|
---|
88 | #undef REG
|
---|
89 | #undef REGNAME
|
---|
90 |
|
---|
91 | #define REG (env->regs[9])
|
---|
92 | #define REGNAME _R9
|
---|
93 | #include "opreg_template.h"
|
---|
94 | #undef REG
|
---|
95 | #undef REGNAME
|
---|
96 |
|
---|
97 | #define REG (env->regs[10])
|
---|
98 | #define REGNAME _R10
|
---|
99 | #include "opreg_template.h"
|
---|
100 | #undef REG
|
---|
101 | #undef REGNAME
|
---|
102 |
|
---|
103 | #define REG (env->regs[11])
|
---|
104 | #define REGNAME _R11
|
---|
105 | #include "opreg_template.h"
|
---|
106 | #undef REG
|
---|
107 | #undef REGNAME
|
---|
108 |
|
---|
109 | #define REG (env->regs[12])
|
---|
110 | #define REGNAME _R12
|
---|
111 | #include "opreg_template.h"
|
---|
112 | #undef REG
|
---|
113 | #undef REGNAME
|
---|
114 |
|
---|
115 | #define REG (env->regs[13])
|
---|
116 | #define REGNAME _R13
|
---|
117 | #include "opreg_template.h"
|
---|
118 | #undef REG
|
---|
119 | #undef REGNAME
|
---|
120 |
|
---|
121 | #define REG (env->regs[14])
|
---|
122 | #define REGNAME _R14
|
---|
123 | #include "opreg_template.h"
|
---|
124 | #undef REG
|
---|
125 | #undef REGNAME
|
---|
126 |
|
---|
127 | #define REG (env->regs[15])
|
---|
128 | #define REGNAME _R15
|
---|
129 | #include "opreg_template.h"
|
---|
130 | #undef REG
|
---|
131 | #undef REGNAME
|
---|
132 |
|
---|
133 | #endif
|
---|
134 |
|
---|
135 | /* operations with flags */
|
---|
136 |
|
---|
137 | /* update flags with T0 and T1 (add/sub case) */
|
---|
138 | void OPPROTO op_update2_cc(void)
|
---|
139 | {
|
---|
140 | CC_SRC = T1;
|
---|
141 | CC_DST = T0;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /* update flags with T0 (logic operation case) */
|
---|
145 | void OPPROTO op_update1_cc(void)
|
---|
146 | {
|
---|
147 | CC_DST = T0;
|
---|
148 | }
|
---|
149 |
|
---|
150 | void OPPROTO op_update_neg_cc(void)
|
---|
151 | {
|
---|
152 | CC_SRC = -T0;
|
---|
153 | CC_DST = T0;
|
---|
154 | }
|
---|
155 |
|
---|
156 | void OPPROTO op_cmpl_T0_T1_cc(void)
|
---|
157 | {
|
---|
158 | CC_SRC = T1;
|
---|
159 | CC_DST = T0 - T1;
|
---|
160 | }
|
---|
161 |
|
---|
162 | void OPPROTO op_update_inc_cc(void)
|
---|
163 | {
|
---|
164 | CC_SRC = cc_table[CC_OP].compute_c();
|
---|
165 | CC_DST = T0;
|
---|
166 | }
|
---|
167 |
|
---|
168 | void OPPROTO op_testl_T0_T1_cc(void)
|
---|
169 | {
|
---|
170 | CC_DST = T0 & T1;
|
---|
171 | }
|
---|
172 |
|
---|
173 | /* operations without flags */
|
---|
174 |
|
---|
175 | void OPPROTO op_addl_T0_T1(void)
|
---|
176 | {
|
---|
177 | T0 += T1;
|
---|
178 | }
|
---|
179 |
|
---|
180 | void OPPROTO op_orl_T0_T1(void)
|
---|
181 | {
|
---|
182 | T0 |= T1;
|
---|
183 | }
|
---|
184 |
|
---|
185 | void OPPROTO op_andl_T0_T1(void)
|
---|
186 | {
|
---|
187 | T0 &= T1;
|
---|
188 | }
|
---|
189 |
|
---|
190 | void OPPROTO op_subl_T0_T1(void)
|
---|
191 | {
|
---|
192 | T0 -= T1;
|
---|
193 | }
|
---|
194 |
|
---|
195 | void OPPROTO op_xorl_T0_T1(void)
|
---|
196 | {
|
---|
197 | T0 ^= T1;
|
---|
198 | }
|
---|
199 |
|
---|
200 | void OPPROTO op_negl_T0(void)
|
---|
201 | {
|
---|
202 | T0 = -T0;
|
---|
203 | }
|
---|
204 |
|
---|
205 | void OPPROTO op_incl_T0(void)
|
---|
206 | {
|
---|
207 | T0++;
|
---|
208 | }
|
---|
209 |
|
---|
210 | void OPPROTO op_decl_T0(void)
|
---|
211 | {
|
---|
212 | T0--;
|
---|
213 | }
|
---|
214 |
|
---|
215 | void OPPROTO op_notl_T0(void)
|
---|
216 | {
|
---|
217 | T0 = ~T0;
|
---|
218 | }
|
---|
219 |
|
---|
220 | void OPPROTO op_bswapl_T0(void)
|
---|
221 | {
|
---|
222 | T0 = bswap32(T0);
|
---|
223 | }
|
---|
224 |
|
---|
225 | #ifdef TARGET_X86_64
|
---|
226 | void OPPROTO op_bswapq_T0(void)
|
---|
227 | {
|
---|
228 | helper_bswapq_T0();
|
---|
229 | }
|
---|
230 | #endif
|
---|
231 |
|
---|
232 | /* multiply/divide */
|
---|
233 |
|
---|
234 | /* XXX: add eflags optimizations */
|
---|
235 | /* XXX: add non P4 style flags */
|
---|
236 |
|
---|
237 | void OPPROTO op_mulb_AL_T0(void)
|
---|
238 | {
|
---|
239 | unsigned int res;
|
---|
240 | res = (uint8_t)EAX * (uint8_t)T0;
|
---|
241 | EAX = (EAX & ~0xffff) | res;
|
---|
242 | CC_DST = res;
|
---|
243 | CC_SRC = (res & 0xff00);
|
---|
244 | }
|
---|
245 |
|
---|
246 | void OPPROTO op_imulb_AL_T0(void)
|
---|
247 | {
|
---|
248 | int res;
|
---|
249 | res = (int8_t)EAX * (int8_t)T0;
|
---|
250 | EAX = (EAX & ~0xffff) | (res & 0xffff);
|
---|
251 | CC_DST = res;
|
---|
252 | CC_SRC = (res != (int8_t)res);
|
---|
253 | }
|
---|
254 |
|
---|
255 | void OPPROTO op_mulw_AX_T0(void)
|
---|
256 | {
|
---|
257 | unsigned int res;
|
---|
258 | res = (uint16_t)EAX * (uint16_t)T0;
|
---|
259 | EAX = (EAX & ~0xffff) | (res & 0xffff);
|
---|
260 | EDX = (EDX & ~0xffff) | ((res >> 16) & 0xffff);
|
---|
261 | CC_DST = res;
|
---|
262 | CC_SRC = res >> 16;
|
---|
263 | }
|
---|
264 |
|
---|
265 | void OPPROTO op_imulw_AX_T0(void)
|
---|
266 | {
|
---|
267 | int res;
|
---|
268 | res = (int16_t)EAX * (int16_t)T0;
|
---|
269 | EAX = (EAX & ~0xffff) | (res & 0xffff);
|
---|
270 | EDX = (EDX & ~0xffff) | ((res >> 16) & 0xffff);
|
---|
271 | CC_DST = res;
|
---|
272 | CC_SRC = (res != (int16_t)res);
|
---|
273 | }
|
---|
274 |
|
---|
275 | void OPPROTO op_mull_EAX_T0(void)
|
---|
276 | {
|
---|
277 | uint64_t res;
|
---|
278 | res = (uint64_t)((uint32_t)EAX) * (uint64_t)((uint32_t)T0);
|
---|
279 | EAX = (uint32_t)res;
|
---|
280 | EDX = (uint32_t)(res >> 32);
|
---|
281 | CC_DST = (uint32_t)res;
|
---|
282 | CC_SRC = (uint32_t)(res >> 32);
|
---|
283 | }
|
---|
284 |
|
---|
285 | void OPPROTO op_imull_EAX_T0(void)
|
---|
286 | {
|
---|
287 | int64_t res;
|
---|
288 | res = (int64_t)((int32_t)EAX) * (int64_t)((int32_t)T0);
|
---|
289 | EAX = (uint32_t)(res);
|
---|
290 | EDX = (uint32_t)(res >> 32);
|
---|
291 | CC_DST = res;
|
---|
292 | CC_SRC = (res != (int32_t)res);
|
---|
293 | }
|
---|
294 |
|
---|
295 | void OPPROTO op_imulw_T0_T1(void)
|
---|
296 | {
|
---|
297 | int res;
|
---|
298 | res = (int16_t)T0 * (int16_t)T1;
|
---|
299 | T0 = res;
|
---|
300 | CC_DST = res;
|
---|
301 | CC_SRC = (res != (int16_t)res);
|
---|
302 | }
|
---|
303 |
|
---|
304 | void OPPROTO op_imull_T0_T1(void)
|
---|
305 | {
|
---|
306 | int64_t res;
|
---|
307 | res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1);
|
---|
308 | T0 = res;
|
---|
309 | CC_DST = res;
|
---|
310 | CC_SRC = (res != (int32_t)res);
|
---|
311 | }
|
---|
312 |
|
---|
313 | #ifdef TARGET_X86_64
|
---|
314 | void OPPROTO op_mulq_EAX_T0(void)
|
---|
315 | {
|
---|
316 | helper_mulq_EAX_T0();
|
---|
317 | }
|
---|
318 |
|
---|
319 | void OPPROTO op_imulq_EAX_T0(void)
|
---|
320 | {
|
---|
321 | helper_imulq_EAX_T0();
|
---|
322 | }
|
---|
323 |
|
---|
324 | void OPPROTO op_imulq_T0_T1(void)
|
---|
325 | {
|
---|
326 | helper_imulq_T0_T1();
|
---|
327 | }
|
---|
328 | #endif
|
---|
329 |
|
---|
330 | /* division, flags are undefined */
|
---|
331 |
|
---|
332 | void OPPROTO op_divb_AL_T0(void)
|
---|
333 | {
|
---|
334 | unsigned int num, den, q, r;
|
---|
335 |
|
---|
336 | num = (EAX & 0xffff);
|
---|
337 | den = (T0 & 0xff);
|
---|
338 | if (den == 0) {
|
---|
339 | raise_exception(EXCP00_DIVZ);
|
---|
340 | }
|
---|
341 | q = (num / den);
|
---|
342 | if (q > 0xff)
|
---|
343 | raise_exception(EXCP00_DIVZ);
|
---|
344 | q &= 0xff;
|
---|
345 | r = (num % den) & 0xff;
|
---|
346 | EAX = (EAX & ~0xffff) | (r << 8) | q;
|
---|
347 | }
|
---|
348 |
|
---|
349 | void OPPROTO op_idivb_AL_T0(void)
|
---|
350 | {
|
---|
351 | int num, den, q, r;
|
---|
352 |
|
---|
353 | num = (int16_t)EAX;
|
---|
354 | den = (int8_t)T0;
|
---|
355 | if (den == 0) {
|
---|
356 | raise_exception(EXCP00_DIVZ);
|
---|
357 | }
|
---|
358 | q = (num / den);
|
---|
359 | if (q != (int8_t)q)
|
---|
360 | raise_exception(EXCP00_DIVZ);
|
---|
361 | q &= 0xff;
|
---|
362 | r = (num % den) & 0xff;
|
---|
363 | EAX = (EAX & ~0xffff) | (r << 8) | q;
|
---|
364 | }
|
---|
365 |
|
---|
366 | void OPPROTO op_divw_AX_T0(void)
|
---|
367 | {
|
---|
368 | unsigned int num, den, q, r;
|
---|
369 |
|
---|
370 | num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
|
---|
371 | den = (T0 & 0xffff);
|
---|
372 | if (den == 0) {
|
---|
373 | raise_exception(EXCP00_DIVZ);
|
---|
374 | }
|
---|
375 | q = (num / den);
|
---|
376 | if (q > 0xffff)
|
---|
377 | raise_exception(EXCP00_DIVZ);
|
---|
378 | q &= 0xffff;
|
---|
379 | r = (num % den) & 0xffff;
|
---|
380 | EAX = (EAX & ~0xffff) | q;
|
---|
381 | EDX = (EDX & ~0xffff) | r;
|
---|
382 | }
|
---|
383 |
|
---|
384 | void OPPROTO op_idivw_AX_T0(void)
|
---|
385 | {
|
---|
386 | int num, den, q, r;
|
---|
387 |
|
---|
388 | num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
|
---|
389 | den = (int16_t)T0;
|
---|
390 | if (den == 0) {
|
---|
391 | raise_exception(EXCP00_DIVZ);
|
---|
392 | }
|
---|
393 | q = (num / den);
|
---|
394 | if (q != (int16_t)q)
|
---|
395 | raise_exception(EXCP00_DIVZ);
|
---|
396 | q &= 0xffff;
|
---|
397 | r = (num % den) & 0xffff;
|
---|
398 | EAX = (EAX & ~0xffff) | q;
|
---|
399 | EDX = (EDX & ~0xffff) | r;
|
---|
400 | }
|
---|
401 |
|
---|
402 | void OPPROTO op_divl_EAX_T0(void)
|
---|
403 | {
|
---|
404 | helper_divl_EAX_T0();
|
---|
405 | }
|
---|
406 |
|
---|
407 | void OPPROTO op_idivl_EAX_T0(void)
|
---|
408 | {
|
---|
409 | helper_idivl_EAX_T0();
|
---|
410 | }
|
---|
411 |
|
---|
412 | #ifdef TARGET_X86_64
|
---|
413 | void OPPROTO op_divq_EAX_T0(void)
|
---|
414 | {
|
---|
415 | helper_divq_EAX_T0();
|
---|
416 | }
|
---|
417 |
|
---|
418 | void OPPROTO op_idivq_EAX_T0(void)
|
---|
419 | {
|
---|
420 | helper_idivq_EAX_T0();
|
---|
421 | }
|
---|
422 | #endif
|
---|
423 |
|
---|
424 | /* constant load & misc op */
|
---|
425 |
|
---|
426 | /* XXX: consistent names */
|
---|
427 | void OPPROTO op_movl_T0_imu(void)
|
---|
428 | {
|
---|
429 | T0 = (uint32_t)PARAM1;
|
---|
430 | }
|
---|
431 |
|
---|
432 | void OPPROTO op_movl_T0_im(void)
|
---|
433 | {
|
---|
434 | T0 = (int32_t)PARAM1;
|
---|
435 | }
|
---|
436 |
|
---|
437 | void OPPROTO op_addl_T0_im(void)
|
---|
438 | {
|
---|
439 | T0 += PARAM1;
|
---|
440 | }
|
---|
441 |
|
---|
442 | void OPPROTO op_andl_T0_ffff(void)
|
---|
443 | {
|
---|
444 | T0 = T0 & 0xffff;
|
---|
445 | }
|
---|
446 |
|
---|
447 | void OPPROTO op_andl_T0_im(void)
|
---|
448 | {
|
---|
449 | T0 = T0 & PARAM1;
|
---|
450 | }
|
---|
451 |
|
---|
452 | void OPPROTO op_movl_T0_T1(void)
|
---|
453 | {
|
---|
454 | T0 = T1;
|
---|
455 | }
|
---|
456 |
|
---|
457 | void OPPROTO op_movl_T1_imu(void)
|
---|
458 | {
|
---|
459 | T1 = (uint32_t)PARAM1;
|
---|
460 | }
|
---|
461 |
|
---|
462 | void OPPROTO op_movl_T1_im(void)
|
---|
463 | {
|
---|
464 | T1 = (int32_t)PARAM1;
|
---|
465 | }
|
---|
466 |
|
---|
467 | void OPPROTO op_addl_T1_im(void)
|
---|
468 | {
|
---|
469 | T1 += PARAM1;
|
---|
470 | }
|
---|
471 |
|
---|
472 | void OPPROTO op_movl_T1_A0(void)
|
---|
473 | {
|
---|
474 | T1 = A0;
|
---|
475 | }
|
---|
476 |
|
---|
477 | void OPPROTO op_movl_A0_im(void)
|
---|
478 | {
|
---|
479 | A0 = (uint32_t)PARAM1;
|
---|
480 | }
|
---|
481 |
|
---|
482 | void OPPROTO op_addl_A0_im(void)
|
---|
483 | {
|
---|
484 | A0 = (uint32_t)(A0 + PARAM1);
|
---|
485 | }
|
---|
486 |
|
---|
487 | void OPPROTO op_movl_A0_seg(void)
|
---|
488 | {
|
---|
489 | #ifdef VBOX
|
---|
490 | /** @todo Not very efficient, but the least invasive. */
|
---|
491 | /** @todo Pass segment register index as parameter in translate.c. */
|
---|
492 | uint32_t idx = (PARAM1 - offsetof(CPUX86State,segs[0].base)) / sizeof(SegmentCache);
|
---|
493 |
|
---|
494 | if (env->segs[idx].newselector && !(env->eflags & VM_MASK)) {
|
---|
495 | sync_seg(env, idx, env->segs[idx].newselector);
|
---|
496 | }
|
---|
497 | #if 0 /* breaks Solaris */
|
---|
498 | /* Loading a null selector into a segment register is valid, but using it is most definitely not! */
|
---|
499 | if ( (env->cr[0] & (CR0_PE_MASK|CR0_PG_MASK)) == (CR0_PE_MASK|CR0_PG_MASK)
|
---|
500 | && !(env->eflags & VM_MASK)
|
---|
501 | && env->segs[idx].selector == 0) {
|
---|
502 | raise_exception(EXCP0D_GPF);
|
---|
503 | }
|
---|
504 | #endif
|
---|
505 | A0 = (uint32_t)env->segs[idx].base;
|
---|
506 | FORCE_RET();
|
---|
507 | #else /* !VBOX */
|
---|
508 | A0 = (uint32_t)*(target_ulong *)((char *)env + PARAM1);
|
---|
509 | #endif /* !VBOX */
|
---|
510 | }
|
---|
511 |
|
---|
512 | void OPPROTO op_addl_A0_seg(void)
|
---|
513 | {
|
---|
514 | #ifdef VBOX
|
---|
515 | uint32_t idx = (PARAM1 - offsetof(CPUX86State,segs[0].base)) / sizeof(SegmentCache);
|
---|
516 |
|
---|
517 | if (env->segs[idx].newselector && !(env->eflags & VM_MASK)) {
|
---|
518 | sync_seg(env, idx, env->segs[idx].newselector);
|
---|
519 | }
|
---|
520 | #if 0 /* breaks Solaris */
|
---|
521 | /* Loading a null selector into a segment register is valid, but using it is most definitely not! */
|
---|
522 | if ( (env->cr[0] & (CR0_PE_MASK|CR0_PG_MASK)) == (CR0_PE_MASK|CR0_PG_MASK)
|
---|
523 | && !(env->eflags & VM_MASK)
|
---|
524 | && env->segs[idx].selector == 0) {
|
---|
525 | raise_exception(EXCP0D_GPF);
|
---|
526 | }
|
---|
527 | #endif
|
---|
528 | A0 = (uint32_t)(A0 + env->segs[idx].base);
|
---|
529 | FORCE_RET();
|
---|
530 | #else /* !VBOX */
|
---|
531 | A0 = (uint32_t)(A0 + *(target_ulong *)((char *)env + PARAM1));
|
---|
532 | #endif /* !VBOX */
|
---|
533 | }
|
---|
534 |
|
---|
535 | void OPPROTO op_addl_A0_AL(void)
|
---|
536 | {
|
---|
537 | A0 = (uint32_t)(A0 + (EAX & 0xff));
|
---|
538 | }
|
---|
539 |
|
---|
540 | #ifdef WORDS_BIGENDIAN
|
---|
541 | typedef union UREG64 {
|
---|
542 | struct { uint16_t v3, v2, v1, v0; } w;
|
---|
543 | struct { uint32_t v1, v0; } l;
|
---|
544 | uint64_t q;
|
---|
545 | } UREG64;
|
---|
546 | #else
|
---|
547 | typedef union UREG64 {
|
---|
548 | struct { uint16_t v0, v1, v2, v3; } w;
|
---|
549 | struct { uint32_t v0, v1; } l;
|
---|
550 | uint64_t q;
|
---|
551 | } UREG64;
|
---|
552 | #endif
|
---|
553 |
|
---|
554 | #ifdef TARGET_X86_64
|
---|
555 |
|
---|
556 | #define PARAMQ1 \
|
---|
557 | ({\
|
---|
558 | UREG64 __p;\
|
---|
559 | __p.l.v1 = PARAM1;\
|
---|
560 | __p.l.v0 = PARAM2;\
|
---|
561 | __p.q;\
|
---|
562 | })
|
---|
563 |
|
---|
564 | void OPPROTO op_movq_T0_im64(void)
|
---|
565 | {
|
---|
566 | T0 = PARAMQ1;
|
---|
567 | }
|
---|
568 |
|
---|
569 | void OPPROTO op_movq_T1_im64(void)
|
---|
570 | {
|
---|
571 | T1 = PARAMQ1;
|
---|
572 | }
|
---|
573 |
|
---|
574 | void OPPROTO op_movq_A0_im(void)
|
---|
575 | {
|
---|
576 | A0 = (int32_t)PARAM1;
|
---|
577 | }
|
---|
578 |
|
---|
579 | void OPPROTO op_movq_A0_im64(void)
|
---|
580 | {
|
---|
581 | A0 = PARAMQ1;
|
---|
582 | }
|
---|
583 |
|
---|
584 | void OPPROTO op_addq_A0_im(void)
|
---|
585 | {
|
---|
586 | A0 = (A0 + (int32_t)PARAM1);
|
---|
587 | }
|
---|
588 |
|
---|
589 | void OPPROTO op_addq_A0_im64(void)
|
---|
590 | {
|
---|
591 | A0 = (A0 + PARAMQ1);
|
---|
592 | }
|
---|
593 |
|
---|
594 | void OPPROTO op_movq_A0_seg(void)
|
---|
595 | {
|
---|
596 | #ifdef VBOX
|
---|
597 | uint32_t idx = (PARAM1 - offsetof(CPUX86State,segs[0].base)) / sizeof(SegmentCache);
|
---|
598 |
|
---|
599 | if (env->segs[idx].newselector && !(env->eflags & VM_MASK))
|
---|
600 | sync_seg(env, idx, env->segs[idx].newselector);
|
---|
601 | A0 = (target_ulong)env->segs[idx].base;
|
---|
602 | #else /* !VBOX */
|
---|
603 | A0 = *(target_ulong *)((char *)env + PARAM1);
|
---|
604 | #endif /* !VBOX */
|
---|
605 | }
|
---|
606 |
|
---|
607 | void OPPROTO op_addq_A0_seg(void)
|
---|
608 | {
|
---|
609 | #ifdef VBOX
|
---|
610 | uint32_t idx = (PARAM1 - offsetof(CPUX86State,segs[0].base)) / sizeof(SegmentCache);
|
---|
611 |
|
---|
612 | if (env->segs[idx].newselector && !(env->eflags & VM_MASK))
|
---|
613 | sync_seg(env, idx, env->segs[idx].newselector);
|
---|
614 | A0 += (target_ulong)env->segs[idx].base;
|
---|
615 | #else /* !VBOX */
|
---|
616 | A0 += *(target_ulong *)((char *)env + PARAM1);
|
---|
617 | #endif /* !VBOX */
|
---|
618 | }
|
---|
619 |
|
---|
620 | void OPPROTO op_addq_A0_AL(void)
|
---|
621 | {
|
---|
622 | A0 = (A0 + (EAX & 0xff));
|
---|
623 | }
|
---|
624 |
|
---|
625 | #endif
|
---|
626 |
|
---|
627 | void OPPROTO op_andl_A0_ffff(void)
|
---|
628 | {
|
---|
629 | A0 = A0 & 0xffff;
|
---|
630 | }
|
---|
631 |
|
---|
632 | /* memory access */
|
---|
633 |
|
---|
634 | #define MEMSUFFIX _raw
|
---|
635 | #include "ops_mem.h"
|
---|
636 |
|
---|
637 | #if !defined(CONFIG_USER_ONLY)
|
---|
638 | #define MEMSUFFIX _kernel
|
---|
639 | #include "ops_mem.h"
|
---|
640 |
|
---|
641 | #define MEMSUFFIX _user
|
---|
642 | #include "ops_mem.h"
|
---|
643 | #endif
|
---|
644 |
|
---|
645 | /* indirect jump */
|
---|
646 |
|
---|
647 | void OPPROTO op_jmp_T0(void)
|
---|
648 | {
|
---|
649 | EIP = T0;
|
---|
650 | }
|
---|
651 |
|
---|
652 | void OPPROTO op_movl_eip_im(void)
|
---|
653 | {
|
---|
654 | EIP = (uint32_t)PARAM1;
|
---|
655 | }
|
---|
656 |
|
---|
657 | #ifdef TARGET_X86_64
|
---|
658 | void OPPROTO op_movq_eip_im(void)
|
---|
659 | {
|
---|
660 | EIP = (int32_t)PARAM1;
|
---|
661 | }
|
---|
662 |
|
---|
663 | void OPPROTO op_movq_eip_im64(void)
|
---|
664 | {
|
---|
665 | EIP = PARAMQ1;
|
---|
666 | }
|
---|
667 | #endif
|
---|
668 |
|
---|
669 | void OPPROTO op_hlt(void)
|
---|
670 | {
|
---|
671 | helper_hlt();
|
---|
672 | }
|
---|
673 |
|
---|
674 | void OPPROTO op_monitor(void)
|
---|
675 | {
|
---|
676 | helper_monitor();
|
---|
677 | }
|
---|
678 |
|
---|
679 | void OPPROTO op_mwait(void)
|
---|
680 | {
|
---|
681 | helper_mwait();
|
---|
682 | }
|
---|
683 |
|
---|
684 | void OPPROTO op_debug(void)
|
---|
685 | {
|
---|
686 | env->exception_index = EXCP_DEBUG;
|
---|
687 | cpu_loop_exit();
|
---|
688 | }
|
---|
689 |
|
---|
690 | void OPPROTO op_raise_interrupt(void)
|
---|
691 | {
|
---|
692 | int intno, next_eip_addend;
|
---|
693 | intno = PARAM1;
|
---|
694 | next_eip_addend = PARAM2;
|
---|
695 | raise_interrupt(intno, 1, 0, next_eip_addend);
|
---|
696 | }
|
---|
697 |
|
---|
698 | void OPPROTO op_raise_exception(void)
|
---|
699 | {
|
---|
700 | int exception_index;
|
---|
701 | exception_index = PARAM1;
|
---|
702 | raise_exception(exception_index);
|
---|
703 | }
|
---|
704 |
|
---|
705 | void OPPROTO op_into(void)
|
---|
706 | {
|
---|
707 | int eflags;
|
---|
708 | eflags = cc_table[CC_OP].compute_all();
|
---|
709 | if (eflags & CC_O) {
|
---|
710 | raise_interrupt(EXCP04_INTO, 1, 0, PARAM1);
|
---|
711 | }
|
---|
712 | FORCE_RET();
|
---|
713 | }
|
---|
714 |
|
---|
715 | void OPPROTO op_cli(void)
|
---|
716 | {
|
---|
717 | env->eflags &= ~IF_MASK;
|
---|
718 | }
|
---|
719 |
|
---|
720 | void OPPROTO op_sti(void)
|
---|
721 | {
|
---|
722 | env->eflags |= IF_MASK;
|
---|
723 | }
|
---|
724 |
|
---|
725 | void OPPROTO op_set_inhibit_irq(void)
|
---|
726 | {
|
---|
727 | env->hflags |= HF_INHIBIT_IRQ_MASK;
|
---|
728 | }
|
---|
729 |
|
---|
730 | void OPPROTO op_reset_inhibit_irq(void)
|
---|
731 | {
|
---|
732 | env->hflags &= ~HF_INHIBIT_IRQ_MASK;
|
---|
733 | }
|
---|
734 |
|
---|
735 | void OPPROTO op_rsm(void)
|
---|
736 | {
|
---|
737 | helper_rsm();
|
---|
738 | }
|
---|
739 |
|
---|
740 | #ifndef VBOX
|
---|
741 | #if 0
|
---|
742 | /* vm86plus instructions */
|
---|
743 | void OPPROTO op_cli_vm(void)
|
---|
744 | {
|
---|
745 | env->eflags &= ~VIF_MASK;
|
---|
746 | }
|
---|
747 |
|
---|
748 | void OPPROTO op_sti_vm(void)
|
---|
749 | {
|
---|
750 | env->eflags |= VIF_MASK;
|
---|
751 | if (env->eflags & VIP_MASK) {
|
---|
752 | EIP = PARAM1;
|
---|
753 | raise_exception(EXCP0D_GPF);
|
---|
754 | }
|
---|
755 | FORCE_RET();
|
---|
756 | }
|
---|
757 | #endif
|
---|
758 |
|
---|
759 | #else /* VBOX */
|
---|
760 | void OPPROTO op_cli_vme(void)
|
---|
761 | {
|
---|
762 | env->eflags &= ~VIF_MASK;
|
---|
763 | }
|
---|
764 |
|
---|
765 | void OPPROTO op_sti_vme(void)
|
---|
766 | {
|
---|
767 | /* First check, then change eflags according to the AMD manual */
|
---|
768 | if (env->eflags & VIP_MASK) {
|
---|
769 | raise_exception(EXCP0D_GPF);
|
---|
770 | }
|
---|
771 | env->eflags |= VIF_MASK;
|
---|
772 | FORCE_RET();
|
---|
773 | }
|
---|
774 | #endif /* VBOX */
|
---|
775 |
|
---|
776 | void OPPROTO op_boundw(void)
|
---|
777 | {
|
---|
778 | int low, high, v;
|
---|
779 | low = ldsw(A0);
|
---|
780 | high = ldsw(A0 + 2);
|
---|
781 | v = (int16_t)T0;
|
---|
782 | if (v < low || v > high) {
|
---|
783 | raise_exception(EXCP05_BOUND);
|
---|
784 | }
|
---|
785 | FORCE_RET();
|
---|
786 | }
|
---|
787 |
|
---|
788 | void OPPROTO op_boundl(void)
|
---|
789 | {
|
---|
790 | int low, high, v;
|
---|
791 | low = ldl(A0);
|
---|
792 | high = ldl(A0 + 4);
|
---|
793 | v = T0;
|
---|
794 | if (v < low || v > high) {
|
---|
795 | raise_exception(EXCP05_BOUND);
|
---|
796 | }
|
---|
797 | FORCE_RET();
|
---|
798 | }
|
---|
799 |
|
---|
800 | void OPPROTO op_cmpxchg8b(void)
|
---|
801 | {
|
---|
802 | helper_cmpxchg8b();
|
---|
803 | }
|
---|
804 |
|
---|
805 | void OPPROTO op_single_step(void)
|
---|
806 | {
|
---|
807 | helper_single_step();
|
---|
808 | }
|
---|
809 |
|
---|
810 | void OPPROTO op_movl_T0_0(void)
|
---|
811 | {
|
---|
812 | T0 = 0;
|
---|
813 | }
|
---|
814 |
|
---|
815 | #ifdef VBOX
|
---|
816 | void OPPROTO op_check_external_event(void)
|
---|
817 | {
|
---|
818 | if ( (env->interrupt_request & ( CPU_INTERRUPT_EXTERNAL_EXIT
|
---|
819 | | CPU_INTERRUPT_EXTERNAL_TIMER
|
---|
820 | | CPU_INTERRUPT_EXTERNAL_DMA))
|
---|
821 | || ( (env->interrupt_request & CPU_INTERRUPT_EXTERNAL_HARD)
|
---|
822 | && (env->eflags & IF_MASK)
|
---|
823 | && !(env->hflags & HF_INHIBIT_IRQ_MASK) ) )
|
---|
824 | {
|
---|
825 | helper_external_event();
|
---|
826 | }
|
---|
827 | }
|
---|
828 |
|
---|
829 | void OPPROTO op_record_call(void)
|
---|
830 | {
|
---|
831 | helper_record_call();
|
---|
832 | }
|
---|
833 |
|
---|
834 | #endif /* VBOX */
|
---|
835 |
|
---|
836 | void OPPROTO op_exit_tb(void)
|
---|
837 | {
|
---|
838 | EXIT_TB();
|
---|
839 | }
|
---|
840 |
|
---|
841 | /* multiple size ops */
|
---|
842 |
|
---|
843 | #define ldul ldl
|
---|
844 |
|
---|
845 | #define SHIFT 0
|
---|
846 | #include "ops_template.h"
|
---|
847 | #undef SHIFT
|
---|
848 |
|
---|
849 | #define SHIFT 1
|
---|
850 | #include "ops_template.h"
|
---|
851 | #undef SHIFT
|
---|
852 |
|
---|
853 | #define SHIFT 2
|
---|
854 | #include "ops_template.h"
|
---|
855 | #undef SHIFT
|
---|
856 |
|
---|
857 | #ifdef TARGET_X86_64
|
---|
858 |
|
---|
859 | #define SHIFT 3
|
---|
860 | #include "ops_template.h"
|
---|
861 | #undef SHIFT
|
---|
862 |
|
---|
863 | #endif
|
---|
864 |
|
---|
865 | /* sign extend */
|
---|
866 |
|
---|
867 | void OPPROTO op_movsbl_T0_T0(void)
|
---|
868 | {
|
---|
869 | T0 = (int8_t)T0;
|
---|
870 | }
|
---|
871 |
|
---|
872 | void OPPROTO op_movzbl_T0_T0(void)
|
---|
873 | {
|
---|
874 | T0 = (uint8_t)T0;
|
---|
875 | }
|
---|
876 |
|
---|
877 | void OPPROTO op_movswl_T0_T0(void)
|
---|
878 | {
|
---|
879 | T0 = (int16_t)T0;
|
---|
880 | }
|
---|
881 |
|
---|
882 | void OPPROTO op_movzwl_T0_T0(void)
|
---|
883 | {
|
---|
884 | T0 = (uint16_t)T0;
|
---|
885 | }
|
---|
886 |
|
---|
887 | void OPPROTO op_movswl_EAX_AX(void)
|
---|
888 | {
|
---|
889 | EAX = (uint32_t)((int16_t)EAX);
|
---|
890 | }
|
---|
891 |
|
---|
892 | #ifdef TARGET_X86_64
|
---|
893 | void OPPROTO op_movslq_T0_T0(void)
|
---|
894 | {
|
---|
895 | T0 = (int32_t)T0;
|
---|
896 | }
|
---|
897 |
|
---|
898 | void OPPROTO op_movslq_RAX_EAX(void)
|
---|
899 | {
|
---|
900 | EAX = (int32_t)EAX;
|
---|
901 | }
|
---|
902 | #endif
|
---|
903 |
|
---|
904 | void OPPROTO op_movsbw_AX_AL(void)
|
---|
905 | {
|
---|
906 | EAX = (EAX & ~0xffff) | ((int8_t)EAX & 0xffff);
|
---|
907 | }
|
---|
908 |
|
---|
909 | void OPPROTO op_movslq_EDX_EAX(void)
|
---|
910 | {
|
---|
911 | EDX = (uint32_t)((int32_t)EAX >> 31);
|
---|
912 | }
|
---|
913 |
|
---|
914 | void OPPROTO op_movswl_DX_AX(void)
|
---|
915 | {
|
---|
916 | EDX = (EDX & ~0xffff) | (((int16_t)EAX >> 15) & 0xffff);
|
---|
917 | }
|
---|
918 |
|
---|
919 | #ifdef TARGET_X86_64
|
---|
920 | void OPPROTO op_movsqo_RDX_RAX(void)
|
---|
921 | {
|
---|
922 | EDX = (int64_t)EAX >> 63;
|
---|
923 | }
|
---|
924 | #endif
|
---|
925 |
|
---|
926 | /* string ops helpers */
|
---|
927 |
|
---|
928 | void OPPROTO op_addl_ESI_T0(void)
|
---|
929 | {
|
---|
930 | ESI = (uint32_t)(ESI + T0);
|
---|
931 | }
|
---|
932 |
|
---|
933 | void OPPROTO op_addw_ESI_T0(void)
|
---|
934 | {
|
---|
935 | ESI = (ESI & ~0xffff) | ((ESI + T0) & 0xffff);
|
---|
936 | }
|
---|
937 |
|
---|
938 | void OPPROTO op_addl_EDI_T0(void)
|
---|
939 | {
|
---|
940 | EDI = (uint32_t)(EDI + T0);
|
---|
941 | }
|
---|
942 |
|
---|
943 | void OPPROTO op_addw_EDI_T0(void)
|
---|
944 | {
|
---|
945 | EDI = (EDI & ~0xffff) | ((EDI + T0) & 0xffff);
|
---|
946 | }
|
---|
947 |
|
---|
948 | void OPPROTO op_decl_ECX(void)
|
---|
949 | {
|
---|
950 | ECX = (uint32_t)(ECX - 1);
|
---|
951 | }
|
---|
952 |
|
---|
953 | void OPPROTO op_decw_ECX(void)
|
---|
954 | {
|
---|
955 | ECX = (ECX & ~0xffff) | ((ECX - 1) & 0xffff);
|
---|
956 | }
|
---|
957 |
|
---|
958 | #ifdef TARGET_X86_64
|
---|
959 | void OPPROTO op_addq_ESI_T0(void)
|
---|
960 | {
|
---|
961 | ESI = (ESI + T0);
|
---|
962 | }
|
---|
963 |
|
---|
964 | void OPPROTO op_addq_EDI_T0(void)
|
---|
965 | {
|
---|
966 | EDI = (EDI + T0);
|
---|
967 | }
|
---|
968 |
|
---|
969 | void OPPROTO op_decq_ECX(void)
|
---|
970 | {
|
---|
971 | ECX--;
|
---|
972 | }
|
---|
973 | #endif
|
---|
974 |
|
---|
975 | /* push/pop utils */
|
---|
976 |
|
---|
977 | void op_addl_A0_SS(void)
|
---|
978 | {
|
---|
979 | A0 = (uint32_t)(A0 + env->segs[R_SS].base);
|
---|
980 | }
|
---|
981 |
|
---|
982 | void op_subl_A0_2(void)
|
---|
983 | {
|
---|
984 | A0 = (uint32_t)(A0 - 2);
|
---|
985 | }
|
---|
986 |
|
---|
987 | void op_subl_A0_4(void)
|
---|
988 | {
|
---|
989 | A0 = (uint32_t)(A0 - 4);
|
---|
990 | }
|
---|
991 |
|
---|
992 | void op_addl_ESP_4(void)
|
---|
993 | {
|
---|
994 | ESP = (uint32_t)(ESP + 4);
|
---|
995 | }
|
---|
996 |
|
---|
997 | void op_addl_ESP_2(void)
|
---|
998 | {
|
---|
999 | ESP = (uint32_t)(ESP + 2);
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | void op_addw_ESP_4(void)
|
---|
1003 | {
|
---|
1004 | ESP = (ESP & ~0xffff) | ((ESP + 4) & 0xffff);
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | void op_addw_ESP_2(void)
|
---|
1008 | {
|
---|
1009 | ESP = (ESP & ~0xffff) | ((ESP + 2) & 0xffff);
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | void op_addl_ESP_im(void)
|
---|
1013 | {
|
---|
1014 | ESP = (uint32_t)(ESP + PARAM1);
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | void op_addw_ESP_im(void)
|
---|
1018 | {
|
---|
1019 | ESP = (ESP & ~0xffff) | ((ESP + PARAM1) & 0xffff);
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | #ifdef TARGET_X86_64
|
---|
1023 | void op_subq_A0_2(void)
|
---|
1024 | {
|
---|
1025 | A0 -= 2;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | void op_subq_A0_8(void)
|
---|
1029 | {
|
---|
1030 | A0 -= 8;
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | void op_addq_ESP_8(void)
|
---|
1034 | {
|
---|
1035 | ESP += 8;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | void op_addq_ESP_im(void)
|
---|
1039 | {
|
---|
1040 | ESP += PARAM1;
|
---|
1041 | }
|
---|
1042 | #endif
|
---|
1043 |
|
---|
1044 | void OPPROTO op_rdtsc(void)
|
---|
1045 | {
|
---|
1046 | helper_rdtsc();
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | void OPPROTO op_cpuid(void)
|
---|
1050 | {
|
---|
1051 | helper_cpuid();
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | void OPPROTO op_enter_level(void)
|
---|
1055 | {
|
---|
1056 | helper_enter_level(PARAM1, PARAM2);
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | #ifdef TARGET_X86_64
|
---|
1060 | void OPPROTO op_enter64_level(void)
|
---|
1061 | {
|
---|
1062 | helper_enter64_level(PARAM1, PARAM2);
|
---|
1063 | }
|
---|
1064 | #endif
|
---|
1065 |
|
---|
1066 | void OPPROTO op_sysenter(void)
|
---|
1067 | {
|
---|
1068 | helper_sysenter();
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | void OPPROTO op_sysexit(void)
|
---|
1072 | {
|
---|
1073 | helper_sysexit();
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | #ifdef TARGET_X86_64
|
---|
1077 | void OPPROTO op_syscall(void)
|
---|
1078 | {
|
---|
1079 | helper_syscall(PARAM1);
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | void OPPROTO op_sysret(void)
|
---|
1083 | {
|
---|
1084 | helper_sysret(PARAM1);
|
---|
1085 | }
|
---|
1086 | #endif
|
---|
1087 |
|
---|
1088 | void OPPROTO op_rdmsr(void)
|
---|
1089 | {
|
---|
1090 | helper_rdmsr();
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | void OPPROTO op_wrmsr(void)
|
---|
1094 | {
|
---|
1095 | helper_wrmsr();
|
---|
1096 | }
|
---|
1097 |
|
---|
1098 | /* bcd */
|
---|
1099 |
|
---|
1100 | /* XXX: exception */
|
---|
1101 | void OPPROTO op_aam(void)
|
---|
1102 | {
|
---|
1103 | int base = PARAM1;
|
---|
1104 | int al, ah;
|
---|
1105 | al = EAX & 0xff;
|
---|
1106 | ah = al / base;
|
---|
1107 | al = al % base;
|
---|
1108 | EAX = (EAX & ~0xffff) | al | (ah << 8);
|
---|
1109 | CC_DST = al;
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | void OPPROTO op_aad(void)
|
---|
1113 | {
|
---|
1114 | int base = PARAM1;
|
---|
1115 | int al, ah;
|
---|
1116 | al = EAX & 0xff;
|
---|
1117 | ah = (EAX >> 8) & 0xff;
|
---|
1118 | al = ((ah * base) + al) & 0xff;
|
---|
1119 | EAX = (EAX & ~0xffff) | al;
|
---|
1120 | CC_DST = al;
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | void OPPROTO op_aaa(void)
|
---|
1124 | {
|
---|
1125 | int icarry;
|
---|
1126 | int al, ah, af;
|
---|
1127 | int eflags;
|
---|
1128 |
|
---|
1129 | eflags = cc_table[CC_OP].compute_all();
|
---|
1130 | af = eflags & CC_A;
|
---|
1131 | al = EAX & 0xff;
|
---|
1132 | ah = (EAX >> 8) & 0xff;
|
---|
1133 |
|
---|
1134 | icarry = (al > 0xf9);
|
---|
1135 | if (((al & 0x0f) > 9 ) || af) {
|
---|
1136 | al = (al + 6) & 0x0f;
|
---|
1137 | ah = (ah + 1 + icarry) & 0xff;
|
---|
1138 | eflags |= CC_C | CC_A;
|
---|
1139 | } else {
|
---|
1140 | eflags &= ~(CC_C | CC_A);
|
---|
1141 | al &= 0x0f;
|
---|
1142 | }
|
---|
1143 | EAX = (EAX & ~0xffff) | al | (ah << 8);
|
---|
1144 | CC_SRC = eflags;
|
---|
1145 | FORCE_RET();
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | void OPPROTO op_aas(void)
|
---|
1149 | {
|
---|
1150 | int icarry;
|
---|
1151 | int al, ah, af;
|
---|
1152 | int eflags;
|
---|
1153 |
|
---|
1154 | eflags = cc_table[CC_OP].compute_all();
|
---|
1155 | af = eflags & CC_A;
|
---|
1156 | al = EAX & 0xff;
|
---|
1157 | ah = (EAX >> 8) & 0xff;
|
---|
1158 |
|
---|
1159 | icarry = (al < 6);
|
---|
1160 | if (((al & 0x0f) > 9 ) || af) {
|
---|
1161 | al = (al - 6) & 0x0f;
|
---|
1162 | ah = (ah - 1 - icarry) & 0xff;
|
---|
1163 | eflags |= CC_C | CC_A;
|
---|
1164 | } else {
|
---|
1165 | eflags &= ~(CC_C | CC_A);
|
---|
1166 | al &= 0x0f;
|
---|
1167 | }
|
---|
1168 | EAX = (EAX & ~0xffff) | al | (ah << 8);
|
---|
1169 | CC_SRC = eflags;
|
---|
1170 | FORCE_RET();
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | void OPPROTO op_daa(void)
|
---|
1174 | {
|
---|
1175 | int al, af, cf;
|
---|
1176 | int eflags;
|
---|
1177 |
|
---|
1178 | eflags = cc_table[CC_OP].compute_all();
|
---|
1179 | cf = eflags & CC_C;
|
---|
1180 | af = eflags & CC_A;
|
---|
1181 | al = EAX & 0xff;
|
---|
1182 |
|
---|
1183 | eflags = 0;
|
---|
1184 | if (((al & 0x0f) > 9 ) || af) {
|
---|
1185 | al = (al + 6) & 0xff;
|
---|
1186 | eflags |= CC_A;
|
---|
1187 | }
|
---|
1188 | if ((al > 0x9f) || cf) {
|
---|
1189 | al = (al + 0x60) & 0xff;
|
---|
1190 | eflags |= CC_C;
|
---|
1191 | }
|
---|
1192 | EAX = (EAX & ~0xff) | al;
|
---|
1193 | /* well, speed is not an issue here, so we compute the flags by hand */
|
---|
1194 | eflags |= (al == 0) << 6; /* zf */
|
---|
1195 | eflags |= parity_table[al]; /* pf */
|
---|
1196 | eflags |= (al & 0x80); /* sf */
|
---|
1197 | CC_SRC = eflags;
|
---|
1198 | FORCE_RET();
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | void OPPROTO op_das(void)
|
---|
1202 | {
|
---|
1203 | int al, al1, af, cf;
|
---|
1204 | int eflags;
|
---|
1205 |
|
---|
1206 | eflags = cc_table[CC_OP].compute_all();
|
---|
1207 | cf = eflags & CC_C;
|
---|
1208 | af = eflags & CC_A;
|
---|
1209 | al = EAX & 0xff;
|
---|
1210 |
|
---|
1211 | eflags = 0;
|
---|
1212 | al1 = al;
|
---|
1213 | if (((al & 0x0f) > 9 ) || af) {
|
---|
1214 | eflags |= CC_A;
|
---|
1215 | if (al < 6 || cf)
|
---|
1216 | eflags |= CC_C;
|
---|
1217 | al = (al - 6) & 0xff;
|
---|
1218 | }
|
---|
1219 | if ((al1 > 0x99) || cf) {
|
---|
1220 | al = (al - 0x60) & 0xff;
|
---|
1221 | eflags |= CC_C;
|
---|
1222 | }
|
---|
1223 | EAX = (EAX & ~0xff) | al;
|
---|
1224 | /* well, speed is not an issue here, so we compute the flags by hand */
|
---|
1225 | eflags |= (al == 0) << 6; /* zf */
|
---|
1226 | eflags |= parity_table[al]; /* pf */
|
---|
1227 | eflags |= (al & 0x80); /* sf */
|
---|
1228 | CC_SRC = eflags;
|
---|
1229 | FORCE_RET();
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | /* segment handling */
|
---|
1233 |
|
---|
1234 | /* never use it with R_CS */
|
---|
1235 | void OPPROTO op_movl_seg_T0(void)
|
---|
1236 | {
|
---|
1237 | load_seg(PARAM1, T0);
|
---|
1238 | }
|
---|
1239 |
|
---|
1240 | /* faster VM86 version */
|
---|
1241 | void OPPROTO op_movl_seg_T0_vm(void)
|
---|
1242 | {
|
---|
1243 | int selector;
|
---|
1244 | SegmentCache *sc;
|
---|
1245 |
|
---|
1246 | selector = T0 & 0xffff;
|
---|
1247 | /* env->segs[] access */
|
---|
1248 | sc = (SegmentCache *)((char *)env + PARAM1);
|
---|
1249 | sc->selector = selector;
|
---|
1250 | sc->base = (selector << 4);
|
---|
1251 | #ifdef VBOX
|
---|
1252 | sc->flags = 0; /* clear attributes */
|
---|
1253 | #endif
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | void OPPROTO op_movl_T0_seg(void)
|
---|
1257 | {
|
---|
1258 | T0 = env->segs[PARAM1].selector;
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 | void OPPROTO op_lsl(void)
|
---|
1262 | {
|
---|
1263 | helper_lsl();
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | void OPPROTO op_lar(void)
|
---|
1267 | {
|
---|
1268 | helper_lar();
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | void OPPROTO op_verr(void)
|
---|
1272 | {
|
---|
1273 | helper_verr();
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | void OPPROTO op_verw(void)
|
---|
1277 | {
|
---|
1278 | helper_verw();
|
---|
1279 | }
|
---|
1280 |
|
---|
1281 | void OPPROTO op_arpl(void)
|
---|
1282 | {
|
---|
1283 | if ((T0 & 3) < (T1 & 3)) {
|
---|
1284 | /* XXX: emulate bug or 0xff3f0000 oring as in bochs ? */
|
---|
1285 | T0 = (T0 & ~3) | (T1 & 3);
|
---|
1286 | T1 = CC_Z;
|
---|
1287 | } else {
|
---|
1288 | T1 = 0;
|
---|
1289 | }
|
---|
1290 | FORCE_RET();
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | void OPPROTO op_arpl_update(void)
|
---|
1294 | {
|
---|
1295 | int eflags;
|
---|
1296 | eflags = cc_table[CC_OP].compute_all();
|
---|
1297 | CC_SRC = (eflags & ~CC_Z) | T1;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | /* T0: segment, T1:eip */
|
---|
1301 | void OPPROTO op_ljmp_protected_T0_T1(void)
|
---|
1302 | {
|
---|
1303 | helper_ljmp_protected_T0_T1(PARAM1);
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | void OPPROTO op_lcall_real_T0_T1(void)
|
---|
1307 | {
|
---|
1308 | helper_lcall_real_T0_T1(PARAM1, PARAM2);
|
---|
1309 | }
|
---|
1310 |
|
---|
1311 | void OPPROTO op_lcall_protected_T0_T1(void)
|
---|
1312 | {
|
---|
1313 | helper_lcall_protected_T0_T1(PARAM1, PARAM2);
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | void OPPROTO op_iret_real(void)
|
---|
1317 | {
|
---|
1318 | helper_iret_real(PARAM1);
|
---|
1319 | }
|
---|
1320 |
|
---|
1321 | void OPPROTO op_iret_protected(void)
|
---|
1322 | {
|
---|
1323 | helper_iret_protected(PARAM1, PARAM2);
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | void OPPROTO op_lret_protected(void)
|
---|
1327 | {
|
---|
1328 | helper_lret_protected(PARAM1, PARAM2);
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | void OPPROTO op_lldt_T0(void)
|
---|
1332 | {
|
---|
1333 | helper_lldt_T0();
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | void OPPROTO op_ltr_T0(void)
|
---|
1337 | {
|
---|
1338 | helper_ltr_T0();
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 | /* CR registers access */
|
---|
1342 | void OPPROTO op_movl_crN_T0(void)
|
---|
1343 | {
|
---|
1344 | helper_movl_crN_T0(PARAM1);
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | #if !defined(CONFIG_USER_ONLY)
|
---|
1348 | void OPPROTO op_movtl_T0_cr8(void)
|
---|
1349 | {
|
---|
1350 | T0 = cpu_get_apic_tpr(env);
|
---|
1351 | }
|
---|
1352 | #endif
|
---|
1353 |
|
---|
1354 | /* DR registers access */
|
---|
1355 | void OPPROTO op_movl_drN_T0(void)
|
---|
1356 | {
|
---|
1357 | helper_movl_drN_T0(PARAM1);
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | void OPPROTO op_lmsw_T0(void)
|
---|
1361 | {
|
---|
1362 | /* only 4 lower bits of CR0 are modified. PE cannot be set to zero
|
---|
1363 | if already set to one. */
|
---|
1364 | T0 = (env->cr[0] & ~0xe) | (T0 & 0xf);
|
---|
1365 | helper_movl_crN_T0(0);
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | void OPPROTO op_invlpg_A0(void)
|
---|
1369 | {
|
---|
1370 | helper_invlpg(A0);
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | void OPPROTO op_movl_T0_env(void)
|
---|
1374 | {
|
---|
1375 | T0 = *(uint32_t *)((char *)env + PARAM1);
|
---|
1376 | }
|
---|
1377 |
|
---|
1378 | void OPPROTO op_movl_env_T0(void)
|
---|
1379 | {
|
---|
1380 | *(uint32_t *)((char *)env + PARAM1) = T0;
|
---|
1381 | }
|
---|
1382 |
|
---|
1383 | void OPPROTO op_movl_env_T1(void)
|
---|
1384 | {
|
---|
1385 | *(uint32_t *)((char *)env + PARAM1) = T1;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | void OPPROTO op_movtl_T0_env(void)
|
---|
1389 | {
|
---|
1390 | T0 = *(target_ulong *)((char *)env + PARAM1);
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | void OPPROTO op_movtl_env_T0(void)
|
---|
1394 | {
|
---|
1395 | *(target_ulong *)((char *)env + PARAM1) = T0;
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 | void OPPROTO op_movtl_T1_env(void)
|
---|
1399 | {
|
---|
1400 | T1 = *(target_ulong *)((char *)env + PARAM1);
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | void OPPROTO op_movtl_env_T1(void)
|
---|
1404 | {
|
---|
1405 | *(target_ulong *)((char *)env + PARAM1) = T1;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | void OPPROTO op_clts(void)
|
---|
1409 | {
|
---|
1410 | env->cr[0] &= ~CR0_TS_MASK;
|
---|
1411 | env->hflags &= ~HF_TS_MASK;
|
---|
1412 | }
|
---|
1413 |
|
---|
1414 | /* flags handling */
|
---|
1415 |
|
---|
1416 | void OPPROTO op_goto_tb0(void)
|
---|
1417 | {
|
---|
1418 | GOTO_TB(op_goto_tb0, PARAM1, 0);
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | void OPPROTO op_goto_tb1(void)
|
---|
1422 | {
|
---|
1423 | GOTO_TB(op_goto_tb1, PARAM1, 1);
|
---|
1424 | }
|
---|
1425 |
|
---|
1426 | void OPPROTO op_jmp_label(void)
|
---|
1427 | {
|
---|
1428 | GOTO_LABEL_PARAM(1);
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | void OPPROTO op_jnz_T0_label(void)
|
---|
1432 | {
|
---|
1433 | if (T0)
|
---|
1434 | GOTO_LABEL_PARAM(1);
|
---|
1435 | FORCE_RET();
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 | void OPPROTO op_jz_T0_label(void)
|
---|
1439 | {
|
---|
1440 | if (!T0)
|
---|
1441 | GOTO_LABEL_PARAM(1);
|
---|
1442 | FORCE_RET();
|
---|
1443 | }
|
---|
1444 |
|
---|
1445 | /* slow set cases (compute x86 flags) */
|
---|
1446 | void OPPROTO op_seto_T0_cc(void)
|
---|
1447 | {
|
---|
1448 | int eflags;
|
---|
1449 | eflags = cc_table[CC_OP].compute_all();
|
---|
1450 | T0 = (eflags >> 11) & 1;
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | void OPPROTO op_setb_T0_cc(void)
|
---|
1454 | {
|
---|
1455 | T0 = cc_table[CC_OP].compute_c();
|
---|
1456 | }
|
---|
1457 |
|
---|
1458 | void OPPROTO op_setz_T0_cc(void)
|
---|
1459 | {
|
---|
1460 | int eflags;
|
---|
1461 | eflags = cc_table[CC_OP].compute_all();
|
---|
1462 | T0 = (eflags >> 6) & 1;
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 | void OPPROTO op_setbe_T0_cc(void)
|
---|
1466 | {
|
---|
1467 | int eflags;
|
---|
1468 | eflags = cc_table[CC_OP].compute_all();
|
---|
1469 | T0 = (eflags & (CC_Z | CC_C)) != 0;
|
---|
1470 | }
|
---|
1471 |
|
---|
1472 | void OPPROTO op_sets_T0_cc(void)
|
---|
1473 | {
|
---|
1474 | int eflags;
|
---|
1475 | eflags = cc_table[CC_OP].compute_all();
|
---|
1476 | T0 = (eflags >> 7) & 1;
|
---|
1477 | }
|
---|
1478 |
|
---|
1479 | void OPPROTO op_setp_T0_cc(void)
|
---|
1480 | {
|
---|
1481 | int eflags;
|
---|
1482 | eflags = cc_table[CC_OP].compute_all();
|
---|
1483 | T0 = (eflags >> 2) & 1;
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | void OPPROTO op_setl_T0_cc(void)
|
---|
1487 | {
|
---|
1488 | int eflags;
|
---|
1489 | eflags = cc_table[CC_OP].compute_all();
|
---|
1490 | T0 = ((eflags ^ (eflags >> 4)) >> 7) & 1;
|
---|
1491 | }
|
---|
1492 |
|
---|
1493 | void OPPROTO op_setle_T0_cc(void)
|
---|
1494 | {
|
---|
1495 | int eflags;
|
---|
1496 | eflags = cc_table[CC_OP].compute_all();
|
---|
1497 | T0 = (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) != 0;
|
---|
1498 | }
|
---|
1499 |
|
---|
1500 | void OPPROTO op_xor_T0_1(void)
|
---|
1501 | {
|
---|
1502 | T0 ^= 1;
|
---|
1503 | }
|
---|
1504 |
|
---|
1505 | void OPPROTO op_set_cc_op(void)
|
---|
1506 | {
|
---|
1507 | CC_OP = PARAM1;
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 | void OPPROTO op_mov_T0_cc(void)
|
---|
1511 | {
|
---|
1512 | T0 = cc_table[CC_OP].compute_all();
|
---|
1513 | }
|
---|
1514 |
|
---|
1515 | /* XXX: clear VIF/VIP in all ops ? */
|
---|
1516 | #ifdef VBOX
|
---|
1517 | /* XXX: AMD docs say they remain unchanged. */
|
---|
1518 | #endif
|
---|
1519 |
|
---|
1520 | void OPPROTO op_movl_eflags_T0(void)
|
---|
1521 | {
|
---|
1522 | load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK));
|
---|
1523 | }
|
---|
1524 |
|
---|
1525 | void OPPROTO op_movw_eflags_T0(void)
|
---|
1526 | {
|
---|
1527 | load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK) & 0xffff);
|
---|
1528 | }
|
---|
1529 |
|
---|
1530 | void OPPROTO op_movl_eflags_T0_io(void)
|
---|
1531 | {
|
---|
1532 | load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK));
|
---|
1533 | }
|
---|
1534 |
|
---|
1535 | void OPPROTO op_movw_eflags_T0_io(void)
|
---|
1536 | {
|
---|
1537 | load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK) & 0xffff);
|
---|
1538 | }
|
---|
1539 |
|
---|
1540 | void OPPROTO op_movl_eflags_T0_cpl0(void)
|
---|
1541 | {
|
---|
1542 | load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK));
|
---|
1543 | }
|
---|
1544 |
|
---|
1545 | void OPPROTO op_movw_eflags_T0_cpl0(void)
|
---|
1546 | {
|
---|
1547 | load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK) & 0xffff);
|
---|
1548 | }
|
---|
1549 |
|
---|
1550 | #ifndef VBOX
|
---|
1551 | #if 0
|
---|
1552 | /* vm86plus version */
|
---|
1553 | void OPPROTO op_movw_eflags_T0_vm(void)
|
---|
1554 | {
|
---|
1555 | int eflags;
|
---|
1556 | eflags = T0;
|
---|
1557 | CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
---|
1558 | DF = 1 - (2 * ((eflags >> 10) & 1));
|
---|
1559 | /* we also update some system flags as in user mode */
|
---|
1560 | env->eflags = (env->eflags & ~(FL_UPDATE_MASK16 | VIF_MASK)) |
|
---|
1561 | (eflags & FL_UPDATE_MASK16);
|
---|
1562 | if (eflags & IF_MASK) {
|
---|
1563 | env->eflags |= VIF_MASK;
|
---|
1564 | if (env->eflags & VIP_MASK) {
|
---|
1565 | EIP = PARAM1;
|
---|
1566 | raise_exception(EXCP0D_GPF);
|
---|
1567 | }
|
---|
1568 | }
|
---|
1569 | FORCE_RET();
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | void OPPROTO op_movl_eflags_T0_vm(void)
|
---|
1573 | {
|
---|
1574 | int eflags;
|
---|
1575 | eflags = T0;
|
---|
1576 | CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
---|
1577 | DF = 1 - (2 * ((eflags >> 10) & 1));
|
---|
1578 | /* we also update some system flags as in user mode */
|
---|
1579 | env->eflags = (env->eflags & ~(FL_UPDATE_MASK32 | VIF_MASK)) |
|
---|
1580 | (eflags & FL_UPDATE_MASK32);
|
---|
1581 | if (eflags & IF_MASK) {
|
---|
1582 | env->eflags |= VIF_MASK;
|
---|
1583 | if (env->eflags & VIP_MASK) {
|
---|
1584 | EIP = PARAM1;
|
---|
1585 | raise_exception(EXCP0D_GPF);
|
---|
1586 | }
|
---|
1587 | }
|
---|
1588 | FORCE_RET();
|
---|
1589 | }
|
---|
1590 | #endif
|
---|
1591 |
|
---|
1592 | #else /* VBOX */
|
---|
1593 | /* IOPL != 3, CR4.VME=1 */
|
---|
1594 | void OPPROTO op_movw_eflags_T0_vme(void)
|
---|
1595 | {
|
---|
1596 | unsigned int new_eflags = T0;
|
---|
1597 |
|
---|
1598 | /* if virtual interrupt pending and (virtual) interrupts will be enabled -> #GP */
|
---|
1599 | /* if TF will be set -> #GP */
|
---|
1600 | if ( ((new_eflags & IF_MASK) && (env->eflags & VIP_MASK))
|
---|
1601 | || (new_eflags & TF_MASK)) {
|
---|
1602 | raise_exception(EXCP0D_GPF);
|
---|
1603 | } else {
|
---|
1604 | load_eflags(new_eflags, (TF_MASK | AC_MASK | ID_MASK | NT_MASK) & 0xffff);
|
---|
1605 |
|
---|
1606 | if (new_eflags & IF_MASK) {
|
---|
1607 | env->eflags |= VIF_MASK;
|
---|
1608 | } else {
|
---|
1609 | env->eflags &= ~VIF_MASK;
|
---|
1610 | }
|
---|
1611 | }
|
---|
1612 |
|
---|
1613 | FORCE_RET();
|
---|
1614 | }
|
---|
1615 | #endif /* VBOX */
|
---|
1616 |
|
---|
1617 | /* XXX: compute only O flag */
|
---|
1618 | void OPPROTO op_movb_eflags_T0(void)
|
---|
1619 | {
|
---|
1620 | int of;
|
---|
1621 | of = cc_table[CC_OP].compute_all() & CC_O;
|
---|
1622 | CC_SRC = (T0 & (CC_S | CC_Z | CC_A | CC_P | CC_C)) | of;
|
---|
1623 | }
|
---|
1624 |
|
---|
1625 | void OPPROTO op_movl_T0_eflags(void)
|
---|
1626 | {
|
---|
1627 | int eflags;
|
---|
1628 | eflags = cc_table[CC_OP].compute_all();
|
---|
1629 | eflags |= (DF & DF_MASK);
|
---|
1630 | eflags |= env->eflags & ~(VM_MASK | RF_MASK);
|
---|
1631 | T0 = eflags;
|
---|
1632 | }
|
---|
1633 |
|
---|
1634 | /* vm86plus version */
|
---|
1635 | #ifdef VBOX /* #if 0 */
|
---|
1636 | void OPPROTO op_movl_T0_eflags_vme(void)
|
---|
1637 | {
|
---|
1638 | int eflags;
|
---|
1639 | eflags = cc_table[CC_OP].compute_all();
|
---|
1640 | eflags |= (DF & DF_MASK);
|
---|
1641 | eflags |= env->eflags & ~(VM_MASK | RF_MASK | IF_MASK);
|
---|
1642 | if (env->eflags & VIF_MASK)
|
---|
1643 | eflags |= IF_MASK;
|
---|
1644 | T0 = eflags;
|
---|
1645 | }
|
---|
1646 | #endif /* VBOX / 0 */
|
---|
1647 |
|
---|
1648 | void OPPROTO op_cld(void)
|
---|
1649 | {
|
---|
1650 | DF = 1;
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 | void OPPROTO op_std(void)
|
---|
1654 | {
|
---|
1655 | DF = -1;
|
---|
1656 | }
|
---|
1657 |
|
---|
1658 | void OPPROTO op_clc(void)
|
---|
1659 | {
|
---|
1660 | int eflags;
|
---|
1661 | eflags = cc_table[CC_OP].compute_all();
|
---|
1662 | eflags &= ~CC_C;
|
---|
1663 | CC_SRC = eflags;
|
---|
1664 | }
|
---|
1665 |
|
---|
1666 | void OPPROTO op_stc(void)
|
---|
1667 | {
|
---|
1668 | int eflags;
|
---|
1669 | eflags = cc_table[CC_OP].compute_all();
|
---|
1670 | eflags |= CC_C;
|
---|
1671 | CC_SRC = eflags;
|
---|
1672 | }
|
---|
1673 |
|
---|
1674 | void OPPROTO op_cmc(void)
|
---|
1675 | {
|
---|
1676 | int eflags;
|
---|
1677 | eflags = cc_table[CC_OP].compute_all();
|
---|
1678 | eflags ^= CC_C;
|
---|
1679 | CC_SRC = eflags;
|
---|
1680 | }
|
---|
1681 |
|
---|
1682 | void OPPROTO op_salc(void)
|
---|
1683 | {
|
---|
1684 | int cf;
|
---|
1685 | cf = cc_table[CC_OP].compute_c();
|
---|
1686 | EAX = (EAX & ~0xff) | ((-cf) & 0xff);
|
---|
1687 | }
|
---|
1688 |
|
---|
1689 | static int compute_all_eflags(void)
|
---|
1690 | {
|
---|
1691 | return CC_SRC;
|
---|
1692 | }
|
---|
1693 |
|
---|
1694 | static int compute_c_eflags(void)
|
---|
1695 | {
|
---|
1696 | return CC_SRC & CC_C;
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 | CCTable cc_table[CC_OP_NB] = {
|
---|
1700 | [CC_OP_DYNAMIC] = { /* should never happen */ },
|
---|
1701 |
|
---|
1702 | [CC_OP_EFLAGS] = { compute_all_eflags, compute_c_eflags },
|
---|
1703 |
|
---|
1704 | [CC_OP_MULB] = { compute_all_mulb, compute_c_mull },
|
---|
1705 | [CC_OP_MULW] = { compute_all_mulw, compute_c_mull },
|
---|
1706 | [CC_OP_MULL] = { compute_all_mull, compute_c_mull },
|
---|
1707 |
|
---|
1708 | [CC_OP_ADDB] = { compute_all_addb, compute_c_addb },
|
---|
1709 | [CC_OP_ADDW] = { compute_all_addw, compute_c_addw },
|
---|
1710 | [CC_OP_ADDL] = { compute_all_addl, compute_c_addl },
|
---|
1711 |
|
---|
1712 | [CC_OP_ADCB] = { compute_all_adcb, compute_c_adcb },
|
---|
1713 | [CC_OP_ADCW] = { compute_all_adcw, compute_c_adcw },
|
---|
1714 | [CC_OP_ADCL] = { compute_all_adcl, compute_c_adcl },
|
---|
1715 |
|
---|
1716 | [CC_OP_SUBB] = { compute_all_subb, compute_c_subb },
|
---|
1717 | [CC_OP_SUBW] = { compute_all_subw, compute_c_subw },
|
---|
1718 | [CC_OP_SUBL] = { compute_all_subl, compute_c_subl },
|
---|
1719 |
|
---|
1720 | [CC_OP_SBBB] = { compute_all_sbbb, compute_c_sbbb },
|
---|
1721 | [CC_OP_SBBW] = { compute_all_sbbw, compute_c_sbbw },
|
---|
1722 | [CC_OP_SBBL] = { compute_all_sbbl, compute_c_sbbl },
|
---|
1723 |
|
---|
1724 | [CC_OP_LOGICB] = { compute_all_logicb, compute_c_logicb },
|
---|
1725 | [CC_OP_LOGICW] = { compute_all_logicw, compute_c_logicw },
|
---|
1726 | [CC_OP_LOGICL] = { compute_all_logicl, compute_c_logicl },
|
---|
1727 |
|
---|
1728 | [CC_OP_INCB] = { compute_all_incb, compute_c_incl },
|
---|
1729 | [CC_OP_INCW] = { compute_all_incw, compute_c_incl },
|
---|
1730 | [CC_OP_INCL] = { compute_all_incl, compute_c_incl },
|
---|
1731 |
|
---|
1732 | [CC_OP_DECB] = { compute_all_decb, compute_c_incl },
|
---|
1733 | [CC_OP_DECW] = { compute_all_decw, compute_c_incl },
|
---|
1734 | [CC_OP_DECL] = { compute_all_decl, compute_c_incl },
|
---|
1735 |
|
---|
1736 | [CC_OP_SHLB] = { compute_all_shlb, compute_c_shlb },
|
---|
1737 | [CC_OP_SHLW] = { compute_all_shlw, compute_c_shlw },
|
---|
1738 | [CC_OP_SHLL] = { compute_all_shll, compute_c_shll },
|
---|
1739 |
|
---|
1740 | [CC_OP_SARB] = { compute_all_sarb, compute_c_sarl },
|
---|
1741 | [CC_OP_SARW] = { compute_all_sarw, compute_c_sarl },
|
---|
1742 | [CC_OP_SARL] = { compute_all_sarl, compute_c_sarl },
|
---|
1743 |
|
---|
1744 | #ifdef TARGET_X86_64
|
---|
1745 | [CC_OP_MULQ] = { compute_all_mulq, compute_c_mull },
|
---|
1746 |
|
---|
1747 | [CC_OP_ADDQ] = { compute_all_addq, compute_c_addq },
|
---|
1748 |
|
---|
1749 | [CC_OP_ADCQ] = { compute_all_adcq, compute_c_adcq },
|
---|
1750 |
|
---|
1751 | [CC_OP_SUBQ] = { compute_all_subq, compute_c_subq },
|
---|
1752 |
|
---|
1753 | [CC_OP_SBBQ] = { compute_all_sbbq, compute_c_sbbq },
|
---|
1754 |
|
---|
1755 | [CC_OP_LOGICQ] = { compute_all_logicq, compute_c_logicq },
|
---|
1756 |
|
---|
1757 | [CC_OP_INCQ] = { compute_all_incq, compute_c_incl },
|
---|
1758 |
|
---|
1759 | [CC_OP_DECQ] = { compute_all_decq, compute_c_incl },
|
---|
1760 |
|
---|
1761 | [CC_OP_SHLQ] = { compute_all_shlq, compute_c_shlq },
|
---|
1762 |
|
---|
1763 | [CC_OP_SARQ] = { compute_all_sarq, compute_c_sarl },
|
---|
1764 | #endif
|
---|
1765 | };
|
---|
1766 |
|
---|
1767 | /* floating point support. Some of the code for complicated x87
|
---|
1768 | functions comes from the LGPL'ed x86 emulator found in the Willows
|
---|
1769 | TWIN windows emulator. */
|
---|
1770 |
|
---|
1771 | /* fp load FT0 */
|
---|
1772 |
|
---|
1773 | void OPPROTO op_flds_FT0_A0(void)
|
---|
1774 | {
|
---|
1775 | #ifdef USE_FP_CONVERT
|
---|
1776 | FP_CONVERT.i32 = ldl(A0);
|
---|
1777 | FT0 = FP_CONVERT.f;
|
---|
1778 | #else
|
---|
1779 | FT0 = ldfl(A0);
|
---|
1780 | #endif
|
---|
1781 | }
|
---|
1782 |
|
---|
1783 | void OPPROTO op_fldl_FT0_A0(void)
|
---|
1784 | {
|
---|
1785 | #ifdef USE_FP_CONVERT
|
---|
1786 | FP_CONVERT.i64 = ldq(A0);
|
---|
1787 | FT0 = FP_CONVERT.d;
|
---|
1788 | #else
|
---|
1789 | FT0 = ldfq(A0);
|
---|
1790 | #endif
|
---|
1791 | }
|
---|
1792 |
|
---|
1793 | /* helpers are needed to avoid static constant reference. XXX: find a better way */
|
---|
1794 | #ifdef USE_INT_TO_FLOAT_HELPERS
|
---|
1795 |
|
---|
1796 | void helper_fild_FT0_A0(void)
|
---|
1797 | {
|
---|
1798 | FT0 = (CPU86_LDouble)ldsw(A0);
|
---|
1799 | }
|
---|
1800 |
|
---|
1801 | void helper_fildl_FT0_A0(void)
|
---|
1802 | {
|
---|
1803 | FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | void helper_fildll_FT0_A0(void)
|
---|
1807 | {
|
---|
1808 | FT0 = (CPU86_LDouble)((int64_t)ldq(A0));
|
---|
1809 | }
|
---|
1810 |
|
---|
1811 | void OPPROTO op_fild_FT0_A0(void)
|
---|
1812 | {
|
---|
1813 | helper_fild_FT0_A0();
|
---|
1814 | }
|
---|
1815 |
|
---|
1816 | void OPPROTO op_fildl_FT0_A0(void)
|
---|
1817 | {
|
---|
1818 | helper_fildl_FT0_A0();
|
---|
1819 | }
|
---|
1820 |
|
---|
1821 | void OPPROTO op_fildll_FT0_A0(void)
|
---|
1822 | {
|
---|
1823 | helper_fildll_FT0_A0();
|
---|
1824 | }
|
---|
1825 |
|
---|
1826 | #else
|
---|
1827 |
|
---|
1828 | void OPPROTO op_fild_FT0_A0(void)
|
---|
1829 | {
|
---|
1830 | #ifdef USE_FP_CONVERT
|
---|
1831 | FP_CONVERT.i32 = ldsw(A0);
|
---|
1832 | FT0 = (CPU86_LDouble)FP_CONVERT.i32;
|
---|
1833 | #else
|
---|
1834 | FT0 = (CPU86_LDouble)ldsw(A0);
|
---|
1835 | #endif
|
---|
1836 | }
|
---|
1837 |
|
---|
1838 | void OPPROTO op_fildl_FT0_A0(void)
|
---|
1839 | {
|
---|
1840 | #ifdef USE_FP_CONVERT
|
---|
1841 | FP_CONVERT.i32 = (int32_t) ldl(A0);
|
---|
1842 | FT0 = (CPU86_LDouble)FP_CONVERT.i32;
|
---|
1843 | #else
|
---|
1844 | FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
|
---|
1845 | #endif
|
---|
1846 | }
|
---|
1847 |
|
---|
1848 | void OPPROTO op_fildll_FT0_A0(void)
|
---|
1849 | {
|
---|
1850 | #ifdef USE_FP_CONVERT
|
---|
1851 | FP_CONVERT.i64 = (int64_t) ldq(A0);
|
---|
1852 | FT0 = (CPU86_LDouble)FP_CONVERT.i64;
|
---|
1853 | #else
|
---|
1854 | FT0 = (CPU86_LDouble)((int64_t)ldq(A0));
|
---|
1855 | #endif
|
---|
1856 | }
|
---|
1857 | #endif
|
---|
1858 |
|
---|
1859 | /* fp load ST0 */
|
---|
1860 |
|
---|
1861 | void OPPROTO op_flds_ST0_A0(void)
|
---|
1862 | {
|
---|
1863 | int new_fpstt;
|
---|
1864 | new_fpstt = (env->fpstt - 1) & 7;
|
---|
1865 | #ifdef USE_FP_CONVERT
|
---|
1866 | FP_CONVERT.i32 = ldl(A0);
|
---|
1867 | env->fpregs[new_fpstt].d = FP_CONVERT.f;
|
---|
1868 | #else
|
---|
1869 | env->fpregs[new_fpstt].d = ldfl(A0);
|
---|
1870 | #endif
|
---|
1871 | env->fpstt = new_fpstt;
|
---|
1872 | env->fptags[new_fpstt] = 0; /* validate stack entry */
|
---|
1873 | }
|
---|
1874 |
|
---|
1875 | void OPPROTO op_fldl_ST0_A0(void)
|
---|
1876 | {
|
---|
1877 | int new_fpstt;
|
---|
1878 | new_fpstt = (env->fpstt - 1) & 7;
|
---|
1879 | #ifdef USE_FP_CONVERT
|
---|
1880 | FP_CONVERT.i64 = ldq(A0);
|
---|
1881 | env->fpregs[new_fpstt].d = FP_CONVERT.d;
|
---|
1882 | #else
|
---|
1883 | env->fpregs[new_fpstt].d = ldfq(A0);
|
---|
1884 | #endif
|
---|
1885 | env->fpstt = new_fpstt;
|
---|
1886 | env->fptags[new_fpstt] = 0; /* validate stack entry */
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | void OPPROTO op_fldt_ST0_A0(void)
|
---|
1890 | {
|
---|
1891 | helper_fldt_ST0_A0();
|
---|
1892 | }
|
---|
1893 |
|
---|
1894 | /* helpers are needed to avoid static constant reference. XXX: find a better way */
|
---|
1895 | #ifdef USE_INT_TO_FLOAT_HELPERS
|
---|
1896 |
|
---|
1897 | void helper_fild_ST0_A0(void)
|
---|
1898 | {
|
---|
1899 | int new_fpstt;
|
---|
1900 | new_fpstt = (env->fpstt - 1) & 7;
|
---|
1901 | env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0);
|
---|
1902 | env->fpstt = new_fpstt;
|
---|
1903 | env->fptags[new_fpstt] = 0; /* validate stack entry */
|
---|
1904 | }
|
---|
1905 |
|
---|
1906 | void helper_fildl_ST0_A0(void)
|
---|
1907 | {
|
---|
1908 | int new_fpstt;
|
---|
1909 | new_fpstt = (env->fpstt - 1) & 7;
|
---|
1910 | env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
|
---|
1911 | env->fpstt = new_fpstt;
|
---|
1912 | env->fptags[new_fpstt] = 0; /* validate stack entry */
|
---|
1913 | }
|
---|
1914 |
|
---|
1915 | void helper_fildll_ST0_A0(void)
|
---|
1916 | {
|
---|
1917 | int new_fpstt;
|
---|
1918 | new_fpstt = (env->fpstt - 1) & 7;
|
---|
1919 | env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0));
|
---|
1920 | env->fpstt = new_fpstt;
|
---|
1921 | env->fptags[new_fpstt] = 0; /* validate stack entry */
|
---|
1922 | }
|
---|
1923 |
|
---|
1924 | void OPPROTO op_fild_ST0_A0(void)
|
---|
1925 | {
|
---|
1926 | helper_fild_ST0_A0();
|
---|
1927 | }
|
---|
1928 |
|
---|
1929 | void OPPROTO op_fildl_ST0_A0(void)
|
---|
1930 | {
|
---|
1931 | helper_fildl_ST0_A0();
|
---|
1932 | }
|
---|
1933 |
|
---|
1934 | void OPPROTO op_fildll_ST0_A0(void)
|
---|
1935 | {
|
---|
1936 | helper_fildll_ST0_A0();
|
---|
1937 | }
|
---|
1938 |
|
---|
1939 | #else
|
---|
1940 |
|
---|
1941 | void OPPROTO op_fild_ST0_A0(void)
|
---|
1942 | {
|
---|
1943 | int new_fpstt;
|
---|
1944 | new_fpstt = (env->fpstt - 1) & 7;
|
---|
1945 | #ifdef USE_FP_CONVERT
|
---|
1946 | FP_CONVERT.i32 = ldsw(A0);
|
---|
1947 | env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
|
---|
1948 | #else
|
---|
1949 | env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0);
|
---|
1950 | #endif
|
---|
1951 | env->fpstt = new_fpstt;
|
---|
1952 | env->fptags[new_fpstt] = 0; /* validate stack entry */
|
---|
1953 | }
|
---|
1954 |
|
---|
1955 | void OPPROTO op_fildl_ST0_A0(void)
|
---|
1956 | {
|
---|
1957 | int new_fpstt;
|
---|
1958 | new_fpstt = (env->fpstt - 1) & 7;
|
---|
1959 | #ifdef USE_FP_CONVERT
|
---|
1960 | FP_CONVERT.i32 = (int32_t) ldl(A0);
|
---|
1961 | env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
|
---|
1962 | #else
|
---|
1963 | env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
|
---|
1964 | #endif
|
---|
1965 | env->fpstt = new_fpstt;
|
---|
1966 | env->fptags[new_fpstt] = 0; /* validate stack entry */
|
---|
1967 | }
|
---|
1968 |
|
---|
1969 | void OPPROTO op_fildll_ST0_A0(void)
|
---|
1970 | {
|
---|
1971 | int new_fpstt;
|
---|
1972 | new_fpstt = (env->fpstt - 1) & 7;
|
---|
1973 | #ifdef USE_FP_CONVERT
|
---|
1974 | FP_CONVERT.i64 = (int64_t) ldq(A0);
|
---|
1975 | env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i64;
|
---|
1976 | #else
|
---|
1977 | env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0));
|
---|
1978 | #endif
|
---|
1979 | env->fpstt = new_fpstt;
|
---|
1980 | env->fptags[new_fpstt] = 0; /* validate stack entry */
|
---|
1981 | }
|
---|
1982 |
|
---|
1983 | #endif
|
---|
1984 |
|
---|
1985 | /* fp store */
|
---|
1986 |
|
---|
1987 | void OPPROTO op_fsts_ST0_A0(void)
|
---|
1988 | {
|
---|
1989 | #ifdef USE_FP_CONVERT
|
---|
1990 | FP_CONVERT.f = (float)ST0;
|
---|
1991 | stfl(A0, FP_CONVERT.f);
|
---|
1992 | #else
|
---|
1993 | stfl(A0, (float)ST0);
|
---|
1994 | #endif
|
---|
1995 | FORCE_RET();
|
---|
1996 | }
|
---|
1997 |
|
---|
1998 | void OPPROTO op_fstl_ST0_A0(void)
|
---|
1999 | {
|
---|
2000 | stfq(A0, (double)ST0);
|
---|
2001 | FORCE_RET();
|
---|
2002 | }
|
---|
2003 |
|
---|
2004 | void OPPROTO op_fstt_ST0_A0(void)
|
---|
2005 | {
|
---|
2006 | helper_fstt_ST0_A0();
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | void OPPROTO op_fist_ST0_A0(void)
|
---|
2010 | {
|
---|
2011 | #if defined(__sparc__) && !defined(__sparc_v9__)
|
---|
2012 | register CPU86_LDouble d asm("o0");
|
---|
2013 | #else
|
---|
2014 | CPU86_LDouble d;
|
---|
2015 | #endif
|
---|
2016 | int val;
|
---|
2017 |
|
---|
2018 | d = ST0;
|
---|
2019 | val = floatx_to_int32(d, &env->fp_status);
|
---|
2020 | if (val != (int16_t)val)
|
---|
2021 | val = -32768;
|
---|
2022 | stw(A0, val);
|
---|
2023 | FORCE_RET();
|
---|
2024 | }
|
---|
2025 |
|
---|
2026 | void OPPROTO op_fistl_ST0_A0(void)
|
---|
2027 | {
|
---|
2028 | #if defined(__sparc__) && !defined(__sparc_v9__)
|
---|
2029 | register CPU86_LDouble d asm("o0");
|
---|
2030 | #else
|
---|
2031 | CPU86_LDouble d;
|
---|
2032 | #endif
|
---|
2033 | int val;
|
---|
2034 |
|
---|
2035 | d = ST0;
|
---|
2036 | val = floatx_to_int32(d, &env->fp_status);
|
---|
2037 | stl(A0, val);
|
---|
2038 | FORCE_RET();
|
---|
2039 | }
|
---|
2040 |
|
---|
2041 | void OPPROTO op_fistll_ST0_A0(void)
|
---|
2042 | {
|
---|
2043 | #if defined(__sparc__) && !defined(__sparc_v9__)
|
---|
2044 | register CPU86_LDouble d asm("o0");
|
---|
2045 | #else
|
---|
2046 | CPU86_LDouble d;
|
---|
2047 | #endif
|
---|
2048 | int64_t val;
|
---|
2049 |
|
---|
2050 | d = ST0;
|
---|
2051 | val = floatx_to_int64(d, &env->fp_status);
|
---|
2052 | stq(A0, val);
|
---|
2053 | FORCE_RET();
|
---|
2054 | }
|
---|
2055 |
|
---|
2056 | void OPPROTO op_fistt_ST0_A0(void)
|
---|
2057 | {
|
---|
2058 | #if defined(__sparc__) && !defined(__sparc_v9__)
|
---|
2059 | register CPU86_LDouble d asm("o0");
|
---|
2060 | #else
|
---|
2061 | CPU86_LDouble d;
|
---|
2062 | #endif
|
---|
2063 | int val;
|
---|
2064 |
|
---|
2065 | d = ST0;
|
---|
2066 | val = floatx_to_int32_round_to_zero(d, &env->fp_status);
|
---|
2067 | if (val != (int16_t)val)
|
---|
2068 | val = -32768;
|
---|
2069 | stw(A0, val);
|
---|
2070 | FORCE_RET();
|
---|
2071 | }
|
---|
2072 |
|
---|
2073 | void OPPROTO op_fisttl_ST0_A0(void)
|
---|
2074 | {
|
---|
2075 | #if defined(__sparc__) && !defined(__sparc_v9__)
|
---|
2076 | register CPU86_LDouble d asm("o0");
|
---|
2077 | #else
|
---|
2078 | CPU86_LDouble d;
|
---|
2079 | #endif
|
---|
2080 | int val;
|
---|
2081 |
|
---|
2082 | d = ST0;
|
---|
2083 | val = floatx_to_int32_round_to_zero(d, &env->fp_status);
|
---|
2084 | stl(A0, val);
|
---|
2085 | FORCE_RET();
|
---|
2086 | }
|
---|
2087 |
|
---|
2088 | void OPPROTO op_fisttll_ST0_A0(void)
|
---|
2089 | {
|
---|
2090 | #if defined(__sparc__) && !defined(__sparc_v9__)
|
---|
2091 | register CPU86_LDouble d asm("o0");
|
---|
2092 | #else
|
---|
2093 | CPU86_LDouble d;
|
---|
2094 | #endif
|
---|
2095 | int64_t val;
|
---|
2096 |
|
---|
2097 | d = ST0;
|
---|
2098 | val = floatx_to_int64_round_to_zero(d, &env->fp_status);
|
---|
2099 | stq(A0, val);
|
---|
2100 | FORCE_RET();
|
---|
2101 | }
|
---|
2102 |
|
---|
2103 | void OPPROTO op_fbld_ST0_A0(void)
|
---|
2104 | {
|
---|
2105 | helper_fbld_ST0_A0();
|
---|
2106 | }
|
---|
2107 |
|
---|
2108 | void OPPROTO op_fbst_ST0_A0(void)
|
---|
2109 | {
|
---|
2110 | helper_fbst_ST0_A0();
|
---|
2111 | }
|
---|
2112 |
|
---|
2113 | /* FPU move */
|
---|
2114 |
|
---|
2115 | void OPPROTO op_fpush(void)
|
---|
2116 | {
|
---|
2117 | fpush();
|
---|
2118 | }
|
---|
2119 |
|
---|
2120 | void OPPROTO op_fpop(void)
|
---|
2121 | {
|
---|
2122 | fpop();
|
---|
2123 | }
|
---|
2124 |
|
---|
2125 | void OPPROTO op_fdecstp(void)
|
---|
2126 | {
|
---|
2127 | env->fpstt = (env->fpstt - 1) & 7;
|
---|
2128 | env->fpus &= (~0x4700);
|
---|
2129 | }
|
---|
2130 |
|
---|
2131 | void OPPROTO op_fincstp(void)
|
---|
2132 | {
|
---|
2133 | env->fpstt = (env->fpstt + 1) & 7;
|
---|
2134 | env->fpus &= (~0x4700);
|
---|
2135 | }
|
---|
2136 |
|
---|
2137 | void OPPROTO op_ffree_STN(void)
|
---|
2138 | {
|
---|
2139 | env->fptags[(env->fpstt + PARAM1) & 7] = 1;
|
---|
2140 | }
|
---|
2141 |
|
---|
2142 | void OPPROTO op_fmov_ST0_FT0(void)
|
---|
2143 | {
|
---|
2144 | ST0 = FT0;
|
---|
2145 | }
|
---|
2146 |
|
---|
2147 | void OPPROTO op_fmov_FT0_STN(void)
|
---|
2148 | {
|
---|
2149 | FT0 = ST(PARAM1);
|
---|
2150 | }
|
---|
2151 |
|
---|
2152 | void OPPROTO op_fmov_ST0_STN(void)
|
---|
2153 | {
|
---|
2154 | ST0 = ST(PARAM1);
|
---|
2155 | }
|
---|
2156 |
|
---|
2157 | void OPPROTO op_fmov_STN_ST0(void)
|
---|
2158 | {
|
---|
2159 | ST(PARAM1) = ST0;
|
---|
2160 | }
|
---|
2161 |
|
---|
2162 | void OPPROTO op_fxchg_ST0_STN(void)
|
---|
2163 | {
|
---|
2164 | CPU86_LDouble tmp;
|
---|
2165 | tmp = ST(PARAM1);
|
---|
2166 | ST(PARAM1) = ST0;
|
---|
2167 | ST0 = tmp;
|
---|
2168 | }
|
---|
2169 |
|
---|
2170 | /* FPU operations */
|
---|
2171 |
|
---|
2172 | const int fcom_ccval[4] = {0x0100, 0x4000, 0x0000, 0x4500};
|
---|
2173 |
|
---|
2174 | void OPPROTO op_fcom_ST0_FT0(void)
|
---|
2175 | {
|
---|
2176 | int ret;
|
---|
2177 |
|
---|
2178 | ret = floatx_compare(ST0, FT0, &env->fp_status);
|
---|
2179 | env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret + 1];
|
---|
2180 | FORCE_RET();
|
---|
2181 | }
|
---|
2182 |
|
---|
2183 | void OPPROTO op_fucom_ST0_FT0(void)
|
---|
2184 | {
|
---|
2185 | int ret;
|
---|
2186 |
|
---|
2187 | ret = floatx_compare_quiet(ST0, FT0, &env->fp_status);
|
---|
2188 | env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret+ 1];
|
---|
2189 | FORCE_RET();
|
---|
2190 | }
|
---|
2191 |
|
---|
2192 | const int fcomi_ccval[4] = {CC_C, CC_Z, 0, CC_Z | CC_P | CC_C};
|
---|
2193 |
|
---|
2194 | void OPPROTO op_fcomi_ST0_FT0(void)
|
---|
2195 | {
|
---|
2196 | int eflags;
|
---|
2197 | int ret;
|
---|
2198 |
|
---|
2199 | ret = floatx_compare(ST0, FT0, &env->fp_status);
|
---|
2200 | eflags = cc_table[CC_OP].compute_all();
|
---|
2201 | eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
|
---|
2202 | CC_SRC = eflags;
|
---|
2203 | FORCE_RET();
|
---|
2204 | }
|
---|
2205 |
|
---|
2206 | void OPPROTO op_fucomi_ST0_FT0(void)
|
---|
2207 | {
|
---|
2208 | int eflags;
|
---|
2209 | int ret;
|
---|
2210 |
|
---|
2211 | ret = floatx_compare_quiet(ST0, FT0, &env->fp_status);
|
---|
2212 | eflags = cc_table[CC_OP].compute_all();
|
---|
2213 | eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
|
---|
2214 | CC_SRC = eflags;
|
---|
2215 | FORCE_RET();
|
---|
2216 | }
|
---|
2217 |
|
---|
2218 | void OPPROTO op_fcmov_ST0_STN_T0(void)
|
---|
2219 | {
|
---|
2220 | if (T0) {
|
---|
2221 | ST0 = ST(PARAM1);
|
---|
2222 | }
|
---|
2223 | FORCE_RET();
|
---|
2224 | }
|
---|
2225 |
|
---|
2226 | void OPPROTO op_fadd_ST0_FT0(void)
|
---|
2227 | {
|
---|
2228 | ST0 += FT0;
|
---|
2229 | }
|
---|
2230 |
|
---|
2231 | void OPPROTO op_fmul_ST0_FT0(void)
|
---|
2232 | {
|
---|
2233 | ST0 *= FT0;
|
---|
2234 | }
|
---|
2235 |
|
---|
2236 | void OPPROTO op_fsub_ST0_FT0(void)
|
---|
2237 | {
|
---|
2238 | ST0 -= FT0;
|
---|
2239 | }
|
---|
2240 |
|
---|
2241 | void OPPROTO op_fsubr_ST0_FT0(void)
|
---|
2242 | {
|
---|
2243 | ST0 = FT0 - ST0;
|
---|
2244 | }
|
---|
2245 |
|
---|
2246 | void OPPROTO op_fdiv_ST0_FT0(void)
|
---|
2247 | {
|
---|
2248 | ST0 = helper_fdiv(ST0, FT0);
|
---|
2249 | }
|
---|
2250 |
|
---|
2251 | void OPPROTO op_fdivr_ST0_FT0(void)
|
---|
2252 | {
|
---|
2253 | ST0 = helper_fdiv(FT0, ST0);
|
---|
2254 | }
|
---|
2255 |
|
---|
2256 | /* fp operations between STN and ST0 */
|
---|
2257 |
|
---|
2258 | void OPPROTO op_fadd_STN_ST0(void)
|
---|
2259 | {
|
---|
2260 | ST(PARAM1) += ST0;
|
---|
2261 | }
|
---|
2262 |
|
---|
2263 | void OPPROTO op_fmul_STN_ST0(void)
|
---|
2264 | {
|
---|
2265 | ST(PARAM1) *= ST0;
|
---|
2266 | }
|
---|
2267 |
|
---|
2268 | void OPPROTO op_fsub_STN_ST0(void)
|
---|
2269 | {
|
---|
2270 | ST(PARAM1) -= ST0;
|
---|
2271 | }
|
---|
2272 |
|
---|
2273 | void OPPROTO op_fsubr_STN_ST0(void)
|
---|
2274 | {
|
---|
2275 | CPU86_LDouble *p;
|
---|
2276 | p = &ST(PARAM1);
|
---|
2277 | *p = ST0 - *p;
|
---|
2278 | }
|
---|
2279 |
|
---|
2280 | void OPPROTO op_fdiv_STN_ST0(void)
|
---|
2281 | {
|
---|
2282 | CPU86_LDouble *p;
|
---|
2283 | p = &ST(PARAM1);
|
---|
2284 | *p = helper_fdiv(*p, ST0);
|
---|
2285 | }
|
---|
2286 |
|
---|
2287 | void OPPROTO op_fdivr_STN_ST0(void)
|
---|
2288 | {
|
---|
2289 | CPU86_LDouble *p;
|
---|
2290 | p = &ST(PARAM1);
|
---|
2291 | *p = helper_fdiv(ST0, *p);
|
---|
2292 | }
|
---|
2293 |
|
---|
2294 | /* misc FPU operations */
|
---|
2295 | void OPPROTO op_fchs_ST0(void)
|
---|
2296 | {
|
---|
2297 | ST0 = floatx_chs(ST0);
|
---|
2298 | }
|
---|
2299 |
|
---|
2300 | void OPPROTO op_fabs_ST0(void)
|
---|
2301 | {
|
---|
2302 | ST0 = floatx_abs(ST0);
|
---|
2303 | }
|
---|
2304 |
|
---|
2305 | void OPPROTO op_fxam_ST0(void)
|
---|
2306 | {
|
---|
2307 | helper_fxam_ST0();
|
---|
2308 | }
|
---|
2309 |
|
---|
2310 | void OPPROTO op_fld1_ST0(void)
|
---|
2311 | {
|
---|
2312 | ST0 = f15rk[1];
|
---|
2313 | }
|
---|
2314 |
|
---|
2315 | void OPPROTO op_fldl2t_ST0(void)
|
---|
2316 | {
|
---|
2317 | ST0 = f15rk[6];
|
---|
2318 | }
|
---|
2319 |
|
---|
2320 | void OPPROTO op_fldl2e_ST0(void)
|
---|
2321 | {
|
---|
2322 | ST0 = f15rk[5];
|
---|
2323 | }
|
---|
2324 |
|
---|
2325 | void OPPROTO op_fldpi_ST0(void)
|
---|
2326 | {
|
---|
2327 | ST0 = f15rk[2];
|
---|
2328 | }
|
---|
2329 |
|
---|
2330 | void OPPROTO op_fldlg2_ST0(void)
|
---|
2331 | {
|
---|
2332 | ST0 = f15rk[3];
|
---|
2333 | }
|
---|
2334 |
|
---|
2335 | void OPPROTO op_fldln2_ST0(void)
|
---|
2336 | {
|
---|
2337 | ST0 = f15rk[4];
|
---|
2338 | }
|
---|
2339 |
|
---|
2340 | void OPPROTO op_fldz_ST0(void)
|
---|
2341 | {
|
---|
2342 | ST0 = f15rk[0];
|
---|
2343 | }
|
---|
2344 |
|
---|
2345 | void OPPROTO op_fldz_FT0(void)
|
---|
2346 | {
|
---|
2347 | FT0 = f15rk[0];
|
---|
2348 | }
|
---|
2349 |
|
---|
2350 | /* associated heplers to reduce generated code length and to simplify
|
---|
2351 | relocation (FP constants are usually stored in .rodata section) */
|
---|
2352 |
|
---|
2353 | void OPPROTO op_f2xm1(void)
|
---|
2354 | {
|
---|
2355 | helper_f2xm1();
|
---|
2356 | }
|
---|
2357 |
|
---|
2358 | void OPPROTO op_fyl2x(void)
|
---|
2359 | {
|
---|
2360 | helper_fyl2x();
|
---|
2361 | }
|
---|
2362 |
|
---|
2363 | void OPPROTO op_fptan(void)
|
---|
2364 | {
|
---|
2365 | helper_fptan();
|
---|
2366 | }
|
---|
2367 |
|
---|
2368 | void OPPROTO op_fpatan(void)
|
---|
2369 | {
|
---|
2370 | helper_fpatan();
|
---|
2371 | }
|
---|
2372 |
|
---|
2373 | void OPPROTO op_fxtract(void)
|
---|
2374 | {
|
---|
2375 | helper_fxtract();
|
---|
2376 | }
|
---|
2377 |
|
---|
2378 | void OPPROTO op_fprem1(void)
|
---|
2379 | {
|
---|
2380 | helper_fprem1();
|
---|
2381 | }
|
---|
2382 |
|
---|
2383 |
|
---|
2384 | void OPPROTO op_fprem(void)
|
---|
2385 | {
|
---|
2386 | helper_fprem();
|
---|
2387 | }
|
---|
2388 |
|
---|
2389 | void OPPROTO op_fyl2xp1(void)
|
---|
2390 | {
|
---|
2391 | helper_fyl2xp1();
|
---|
2392 | }
|
---|
2393 |
|
---|
2394 | void OPPROTO op_fsqrt(void)
|
---|
2395 | {
|
---|
2396 | helper_fsqrt();
|
---|
2397 | }
|
---|
2398 |
|
---|
2399 | void OPPROTO op_fsincos(void)
|
---|
2400 | {
|
---|
2401 | helper_fsincos();
|
---|
2402 | }
|
---|
2403 |
|
---|
2404 | void OPPROTO op_frndint(void)
|
---|
2405 | {
|
---|
2406 | helper_frndint();
|
---|
2407 | }
|
---|
2408 |
|
---|
2409 | void OPPROTO op_fscale(void)
|
---|
2410 | {
|
---|
2411 | helper_fscale();
|
---|
2412 | }
|
---|
2413 |
|
---|
2414 | void OPPROTO op_fsin(void)
|
---|
2415 | {
|
---|
2416 | helper_fsin();
|
---|
2417 | }
|
---|
2418 |
|
---|
2419 | void OPPROTO op_fcos(void)
|
---|
2420 | {
|
---|
2421 | helper_fcos();
|
---|
2422 | }
|
---|
2423 |
|
---|
2424 | void OPPROTO op_fnstsw_A0(void)
|
---|
2425 | {
|
---|
2426 | int fpus;
|
---|
2427 | fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
|
---|
2428 | stw(A0, fpus);
|
---|
2429 | FORCE_RET();
|
---|
2430 | }
|
---|
2431 |
|
---|
2432 | void OPPROTO op_fnstsw_EAX(void)
|
---|
2433 | {
|
---|
2434 | int fpus;
|
---|
2435 | fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
|
---|
2436 | EAX = (EAX & ~0xffff) | fpus;
|
---|
2437 | }
|
---|
2438 |
|
---|
2439 | void OPPROTO op_fnstcw_A0(void)
|
---|
2440 | {
|
---|
2441 | stw(A0, env->fpuc);
|
---|
2442 | FORCE_RET();
|
---|
2443 | }
|
---|
2444 |
|
---|
2445 | void OPPROTO op_fldcw_A0(void)
|
---|
2446 | {
|
---|
2447 | env->fpuc = lduw(A0);
|
---|
2448 | update_fp_status();
|
---|
2449 | }
|
---|
2450 |
|
---|
2451 | void OPPROTO op_fclex(void)
|
---|
2452 | {
|
---|
2453 | env->fpus &= 0x7f00;
|
---|
2454 | }
|
---|
2455 |
|
---|
2456 | void OPPROTO op_fwait(void)
|
---|
2457 | {
|
---|
2458 | if (env->fpus & FPUS_SE)
|
---|
2459 | fpu_raise_exception();
|
---|
2460 | FORCE_RET();
|
---|
2461 | }
|
---|
2462 |
|
---|
2463 | void OPPROTO op_fninit(void)
|
---|
2464 | {
|
---|
2465 | env->fpus = 0;
|
---|
2466 | env->fpstt = 0;
|
---|
2467 | env->fpuc = 0x37f;
|
---|
2468 | env->fptags[0] = 1;
|
---|
2469 | env->fptags[1] = 1;
|
---|
2470 | env->fptags[2] = 1;
|
---|
2471 | env->fptags[3] = 1;
|
---|
2472 | env->fptags[4] = 1;
|
---|
2473 | env->fptags[5] = 1;
|
---|
2474 | env->fptags[6] = 1;
|
---|
2475 | env->fptags[7] = 1;
|
---|
2476 | }
|
---|
2477 |
|
---|
2478 | void OPPROTO op_fnstenv_A0(void)
|
---|
2479 | {
|
---|
2480 | helper_fstenv(A0, PARAM1);
|
---|
2481 | }
|
---|
2482 |
|
---|
2483 | void OPPROTO op_fldenv_A0(void)
|
---|
2484 | {
|
---|
2485 | helper_fldenv(A0, PARAM1);
|
---|
2486 | }
|
---|
2487 |
|
---|
2488 | void OPPROTO op_fnsave_A0(void)
|
---|
2489 | {
|
---|
2490 | helper_fsave(A0, PARAM1);
|
---|
2491 | }
|
---|
2492 |
|
---|
2493 | void OPPROTO op_frstor_A0(void)
|
---|
2494 | {
|
---|
2495 | helper_frstor(A0, PARAM1);
|
---|
2496 | }
|
---|
2497 |
|
---|
2498 | /* threading support */
|
---|
2499 | void OPPROTO op_lock(void)
|
---|
2500 | {
|
---|
2501 | cpu_lock();
|
---|
2502 | }
|
---|
2503 |
|
---|
2504 | void OPPROTO op_unlock(void)
|
---|
2505 | {
|
---|
2506 | cpu_unlock();
|
---|
2507 | }
|
---|
2508 |
|
---|
2509 | /* SSE support */
|
---|
2510 | static inline void memcpy16(void *d, void *s)
|
---|
2511 | {
|
---|
2512 | ((uint32_t *)d)[0] = ((uint32_t *)s)[0];
|
---|
2513 | ((uint32_t *)d)[1] = ((uint32_t *)s)[1];
|
---|
2514 | ((uint32_t *)d)[2] = ((uint32_t *)s)[2];
|
---|
2515 | ((uint32_t *)d)[3] = ((uint32_t *)s)[3];
|
---|
2516 | }
|
---|
2517 |
|
---|
2518 | void OPPROTO op_movo(void)
|
---|
2519 | {
|
---|
2520 | /* XXX: badly generated code */
|
---|
2521 | XMMReg *d, *s;
|
---|
2522 | d = (XMMReg *)((char *)env + PARAM1);
|
---|
2523 | s = (XMMReg *)((char *)env + PARAM2);
|
---|
2524 | memcpy16(d, s);
|
---|
2525 | }
|
---|
2526 |
|
---|
2527 | void OPPROTO op_movq(void)
|
---|
2528 | {
|
---|
2529 | uint64_t *d, *s;
|
---|
2530 | d = (uint64_t *)((char *)env + PARAM1);
|
---|
2531 | s = (uint64_t *)((char *)env + PARAM2);
|
---|
2532 | *d = *s;
|
---|
2533 | }
|
---|
2534 |
|
---|
2535 | void OPPROTO op_movl(void)
|
---|
2536 | {
|
---|
2537 | uint32_t *d, *s;
|
---|
2538 | d = (uint32_t *)((char *)env + PARAM1);
|
---|
2539 | s = (uint32_t *)((char *)env + PARAM2);
|
---|
2540 | *d = *s;
|
---|
2541 | }
|
---|
2542 |
|
---|
2543 | void OPPROTO op_movq_env_0(void)
|
---|
2544 | {
|
---|
2545 | uint64_t *d;
|
---|
2546 | d = (uint64_t *)((char *)env + PARAM1);
|
---|
2547 | *d = 0;
|
---|
2548 | }
|
---|
2549 |
|
---|
2550 | void OPPROTO op_fxsave_A0(void)
|
---|
2551 | {
|
---|
2552 | helper_fxsave(A0, PARAM1);
|
---|
2553 | }
|
---|
2554 |
|
---|
2555 | void OPPROTO op_fxrstor_A0(void)
|
---|
2556 | {
|
---|
2557 | helper_fxrstor(A0, PARAM1);
|
---|
2558 | }
|
---|
2559 |
|
---|
2560 | /* XXX: optimize by storing fptt and fptags in the static cpu state */
|
---|
2561 | void OPPROTO op_enter_mmx(void)
|
---|
2562 | {
|
---|
2563 | env->fpstt = 0;
|
---|
2564 | *(uint32_t *)(env->fptags) = 0;
|
---|
2565 | *(uint32_t *)(env->fptags + 4) = 0;
|
---|
2566 | }
|
---|
2567 |
|
---|
2568 | void OPPROTO op_emms(void)
|
---|
2569 | {
|
---|
2570 | /* set to empty state */
|
---|
2571 | *(uint32_t *)(env->fptags) = 0x01010101;
|
---|
2572 | *(uint32_t *)(env->fptags + 4) = 0x01010101;
|
---|
2573 | }
|
---|
2574 |
|
---|
2575 | #define SHIFT 0
|
---|
2576 | #include "ops_sse.h"
|
---|
2577 |
|
---|
2578 | #define SHIFT 1
|
---|
2579 | #include "ops_sse.h"
|
---|
2580 |
|
---|
2581 | #ifdef VBOX
|
---|
2582 | /* Instantiate the structure signatures. */
|
---|
2583 | # define REM_STRUCT_OP 1
|
---|
2584 | # include "../Sun/structs.h"
|
---|
2585 | #endif
|
---|
2586 |
|
---|