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