VirtualBox

source: vbox/trunk/src/recompiler/new/target-i386/op.c@ 1952

Last change on this file since 1952 was 1588, checked in by vboxsync, 18 years ago

Merged in http://linserv/vbox/changeset?old_path=trunk%2Fsrc%2Frecompiler&old=18834&new_path=trunk%2Fsrc%2Frecompiler&new=19696

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette