Statistics
| Branch: | Revision:

root / target-i386 / op.c @ 0573fbfc

History | View | Annotate | Download (43.6 kB)

1
/*
2
 *  i386 micro operations
3
 *
4
 *  Copyright (c) 2003 Fabrice Bellard
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20

    
21
#define ASM_SOFTMMU
22
#include "exec.h"
23

    
24
/* n must be a constant to be efficient */
25
static inline target_long lshift(target_long x, int n)
26
{
27
    if (n >= 0)
28
        return x << n;
29
    else
30
        return x >> (-n);
31
}
32

    
33
/* we define the various pieces of code used by the JIT */
34

    
35
#define REG EAX
36
#define REGNAME _EAX
37
#include "opreg_template.h"
38
#undef REG
39
#undef REGNAME
40

    
41
#define REG ECX
42
#define REGNAME _ECX
43
#include "opreg_template.h"
44
#undef REG
45
#undef REGNAME
46

    
47
#define REG EDX
48
#define REGNAME _EDX
49
#include "opreg_template.h"
50
#undef REG
51
#undef REGNAME
52

    
53
#define REG EBX
54
#define REGNAME _EBX
55
#include "opreg_template.h"
56
#undef REG
57
#undef REGNAME
58

    
59
#define REG ESP
60
#define REGNAME _ESP
61
#include "opreg_template.h"
62
#undef REG
63
#undef REGNAME
64

    
65
#define REG EBP
66
#define REGNAME _EBP
67
#include "opreg_template.h"
68
#undef REG
69
#undef REGNAME
70

    
71
#define REG ESI
72
#define REGNAME _ESI
73
#include "opreg_template.h"
74
#undef REG
75
#undef REGNAME
76

    
77
#define REG EDI
78
#define REGNAME _EDI
79
#include "opreg_template.h"
80
#undef REG
81
#undef REGNAME
82

    
83
#ifdef TARGET_X86_64
84

    
85
#define REG (env->regs[8])
86
#define REGNAME _R8
87
#include "opreg_template.h"
88
#undef REG
89
#undef REGNAME
90

    
91
#define REG (env->regs[9])
92
#define REGNAME _R9
93
#include "opreg_template.h"
94
#undef REG
95
#undef REGNAME
96

    
97
#define REG (env->regs[10])
98
#define REGNAME _R10
99
#include "opreg_template.h"
100
#undef REG
101
#undef REGNAME
102

    
103
#define REG (env->regs[11])
104
#define REGNAME _R11
105
#include "opreg_template.h"
106
#undef REG
107
#undef REGNAME
108

    
109
#define REG (env->regs[12])
110
#define REGNAME _R12
111
#include "opreg_template.h"
112
#undef REG
113
#undef REGNAME
114

    
115
#define REG (env->regs[13])
116
#define REGNAME _R13
117
#include "opreg_template.h"
118
#undef REG
119
#undef REGNAME
120

    
121
#define REG (env->regs[14])
122
#define REGNAME _R14
123
#include "opreg_template.h"
124
#undef REG
125
#undef REGNAME
126

    
127
#define REG (env->regs[15])
128
#define REGNAME _R15
129
#include "opreg_template.h"
130
#undef REG
131
#undef REGNAME
132

    
133
#endif
134

    
135
/* operations with flags */
136

    
137
/* update flags with T0 and T1 (add/sub case) */
138
void OPPROTO op_update2_cc(void)
139
{
140
    CC_SRC = T1;
141
    CC_DST = T0;
142
}
143

    
144
/* update flags with T0 (logic operation case) */
145
void OPPROTO op_update1_cc(void)
146
{
147
    CC_DST = T0;
148
}
149

    
150
void OPPROTO op_update_neg_cc(void)
151
{
152
    CC_SRC = -T0;
153
    CC_DST = T0;
154
}
155

    
156
void OPPROTO op_cmpl_T0_T1_cc(void)
157
{
158
    CC_SRC = T1;
159
    CC_DST = T0 - T1;
160
}
161

    
162
void OPPROTO op_update_inc_cc(void)
163
{
164
    CC_SRC = cc_table[CC_OP].compute_c();
165
    CC_DST = T0;
166
}
167

    
168
void OPPROTO op_testl_T0_T1_cc(void)
169
{
170
    CC_DST = T0 & T1;
171
}
172

    
173
/* operations without flags */
174

    
175
void OPPROTO op_addl_T0_T1(void)
176
{
177
    T0 += T1;
178
}
179

    
180
void OPPROTO op_orl_T0_T1(void)
181
{
182
    T0 |= T1;
183
}
184

    
185
void OPPROTO op_andl_T0_T1(void)
186
{
187
    T0 &= T1;
188
}
189

    
190
void OPPROTO op_subl_T0_T1(void)
191
{
192
    T0 -= T1;
193
}
194

    
195
void OPPROTO op_xorl_T0_T1(void)
196
{
197
    T0 ^= T1;
198
}
199

    
200
void OPPROTO op_negl_T0(void)
201
{
202
    T0 = -T0;
203
}
204

    
205
void OPPROTO op_incl_T0(void)
206
{
207
    T0++;
208
}
209

    
210
void OPPROTO op_decl_T0(void)
211
{
212
    T0--;
213
}
214

    
215
void OPPROTO op_notl_T0(void)
216
{
217
    T0 = ~T0;
218
}
219

    
220
void OPPROTO op_bswapl_T0(void)
221
{
222
    T0 = bswap32(T0);
223
}
224

    
225
#ifdef TARGET_X86_64
226
void OPPROTO op_bswapq_T0(void)
227
{
228
    helper_bswapq_T0();
229
}
230
#endif
231

    
232
/* multiply/divide */
233

    
234
/* XXX: add eflags optimizations */
235
/* XXX: add non P4 style flags */
236

    
237
void OPPROTO op_mulb_AL_T0(void)
238
{
239
    unsigned int res;
240
    res = (uint8_t)EAX * (uint8_t)T0;
241
    EAX = (EAX & ~0xffff) | res;
242
    CC_DST = res;
243
    CC_SRC = (res & 0xff00);
244
}
245

    
246
void OPPROTO op_imulb_AL_T0(void)
247
{
248
    int res;
249
    res = (int8_t)EAX * (int8_t)T0;
250
    EAX = (EAX & ~0xffff) | (res & 0xffff);
251
    CC_DST = res;
252
    CC_SRC = (res != (int8_t)res);
253
}
254

    
255
void OPPROTO op_mulw_AX_T0(void)
256
{
257
    unsigned int res;
258
    res = (uint16_t)EAX * (uint16_t)T0;
259
    EAX = (EAX & ~0xffff) | (res & 0xffff);
260
    EDX = (EDX & ~0xffff) | ((res >> 16) & 0xffff);
261
    CC_DST = res;
262
    CC_SRC = res >> 16;
263
}
264

    
265
void OPPROTO op_imulw_AX_T0(void)
266
{
267
    int res;
268
    res = (int16_t)EAX * (int16_t)T0;
269
    EAX = (EAX & ~0xffff) | (res & 0xffff);
270
    EDX = (EDX & ~0xffff) | ((res >> 16) & 0xffff);
271
    CC_DST = res;
272
    CC_SRC = (res != (int16_t)res);
273
}
274

    
275
void OPPROTO op_mull_EAX_T0(void)
276
{
277
    uint64_t res;
278
    res = (uint64_t)((uint32_t)EAX) * (uint64_t)((uint32_t)T0);
279
    EAX = (uint32_t)res;
280
    EDX = (uint32_t)(res >> 32);
281
    CC_DST = (uint32_t)res;
282
    CC_SRC = (uint32_t)(res >> 32);
283
}
284

    
285
void OPPROTO op_imull_EAX_T0(void)
286
{
287
    int64_t res;
288
    res = (int64_t)((int32_t)EAX) * (int64_t)((int32_t)T0);
289
    EAX = (uint32_t)(res);
290
    EDX = (uint32_t)(res >> 32);
291
    CC_DST = res;
292
    CC_SRC = (res != (int32_t)res);
293
}
294

    
295
void OPPROTO op_imulw_T0_T1(void)
296
{
297
    int res;
298
    res = (int16_t)T0 * (int16_t)T1;
299
    T0 = res;
300
    CC_DST = res;
301
    CC_SRC = (res != (int16_t)res);
302
}
303

    
304
void OPPROTO op_imull_T0_T1(void)
305
{
306
    int64_t res;
307
    res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1);
308
    T0 = res;
309
    CC_DST = res;
310
    CC_SRC = (res != (int32_t)res);
311
}
312

    
313
#ifdef TARGET_X86_64
314
void OPPROTO op_mulq_EAX_T0(void)
315
{
316
    helper_mulq_EAX_T0();
317
}
318

    
319
void OPPROTO op_imulq_EAX_T0(void)
320
{
321
    helper_imulq_EAX_T0();
322
}
323

    
324
void OPPROTO op_imulq_T0_T1(void)
325
{
326
    helper_imulq_T0_T1();
327
}
328
#endif
329

    
330
/* division, flags are undefined */
331

    
332
void OPPROTO op_divb_AL_T0(void)
333
{
334
    unsigned int num, den, q, r;
335

    
336
    num = (EAX & 0xffff);
337
    den = (T0 & 0xff);
338
    if (den == 0) {
339
        raise_exception(EXCP00_DIVZ);
340
    }
341
    q = (num / den);
342
    if (q > 0xff)
343
        raise_exception(EXCP00_DIVZ);
344
    q &= 0xff;
345
    r = (num % den) & 0xff;
346
    EAX = (EAX & ~0xffff) | (r << 8) | q;
347
}
348

    
349
void OPPROTO op_idivb_AL_T0(void)
350
{
351
    int num, den, q, r;
352

    
353
    num = (int16_t)EAX;
354
    den = (int8_t)T0;
355
    if (den == 0) {
356
        raise_exception(EXCP00_DIVZ);
357
    }
358
    q = (num / den);
359
    if (q != (int8_t)q)
360
        raise_exception(EXCP00_DIVZ);
361
    q &= 0xff;
362
    r = (num % den) & 0xff;
363
    EAX = (EAX & ~0xffff) | (r << 8) | q;
364
}
365

    
366
void OPPROTO op_divw_AX_T0(void)
367
{
368
    unsigned int num, den, q, r;
369

    
370
    num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
371
    den = (T0 & 0xffff);
372
    if (den == 0) {
373
        raise_exception(EXCP00_DIVZ);
374
    }
375
    q = (num / den);
376
    if (q > 0xffff)
377
        raise_exception(EXCP00_DIVZ);
378
    q &= 0xffff;
379
    r = (num % den) & 0xffff;
380
    EAX = (EAX & ~0xffff) | q;
381
    EDX = (EDX & ~0xffff) | r;
382
}
383

    
384
void OPPROTO op_idivw_AX_T0(void)
385
{
386
    int num, den, q, r;
387

    
388
    num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
389
    den = (int16_t)T0;
390
    if (den == 0) {
391
        raise_exception(EXCP00_DIVZ);
392
    }
393
    q = (num / den);
394
    if (q != (int16_t)q)
395
        raise_exception(EXCP00_DIVZ);
396
    q &= 0xffff;
397
    r = (num % den) & 0xffff;
398
    EAX = (EAX & ~0xffff) | q;
399
    EDX = (EDX & ~0xffff) | r;
400
}
401

    
402
void OPPROTO op_divl_EAX_T0(void)
403
{
404
    helper_divl_EAX_T0();
405
}
406

    
407
void OPPROTO op_idivl_EAX_T0(void)
408
{
409
    helper_idivl_EAX_T0();
410
}
411

    
412
#ifdef TARGET_X86_64
413
void OPPROTO op_divq_EAX_T0(void)
414
{
415
    helper_divq_EAX_T0();
416
}
417

    
418
void OPPROTO op_idivq_EAX_T0(void)
419
{
420
    helper_idivq_EAX_T0();
421
}
422
#endif
423

    
424
/* constant load & misc op */
425

    
426
/* XXX: consistent names */
427
void OPPROTO op_movl_T0_imu(void)
428
{
429
    T0 = (uint32_t)PARAM1;
430
}
431

    
432
void OPPROTO op_movl_T0_im(void)
433
{
434
    T0 = (int32_t)PARAM1;
435
}
436

    
437
void OPPROTO op_addl_T0_im(void)
438
{
439
    T0 += PARAM1;
440
}
441

    
442
void OPPROTO op_andl_T0_ffff(void)
443
{
444
    T0 = T0 & 0xffff;
445
}
446

    
447
void OPPROTO op_andl_T0_im(void)
448
{
449
    T0 = T0 & PARAM1;
450
}
451

    
452
void OPPROTO op_movl_T0_T1(void)
453
{
454
    T0 = T1;
455
}
456

    
457
void OPPROTO op_movl_T1_imu(void)
458
{
459
    T1 = (uint32_t)PARAM1;
460
}
461

    
462
void OPPROTO op_movl_T1_im(void)
463
{
464
    T1 = (int32_t)PARAM1;
465
}
466

    
467
void OPPROTO op_addl_T1_im(void)
468
{
469
    T1 += PARAM1;
470
}
471

    
472
void OPPROTO op_movl_T1_A0(void)
473
{
474
    T1 = A0;
475
}
476

    
477
void OPPROTO op_movl_A0_im(void)
478
{
479
    A0 = (uint32_t)PARAM1;
480
}
481

    
482
void OPPROTO op_addl_A0_im(void)
483
{
484
    A0 = (uint32_t)(A0 + PARAM1);
485
}
486

    
487
void OPPROTO op_movl_A0_seg(void)
488
{
489
    A0 = (uint32_t)*(target_ulong *)((char *)env + PARAM1);
490
}
491

    
492
void OPPROTO op_addl_A0_seg(void)
493
{
494
    A0 = (uint32_t)(A0 + *(target_ulong *)((char *)env + PARAM1));
495
}
496

    
497
void OPPROTO op_addl_A0_AL(void)
498
{
499
    A0 = (uint32_t)(A0 + (EAX & 0xff));
500
}
501

    
502
#ifdef WORDS_BIGENDIAN
503
typedef 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
509
typedef 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
#define PARAMQ1 \
517
({\
518
    UREG64 __p;\
519
    __p.l.v1 = PARAM1;\
520
    __p.l.v0 = PARAM2;\
521
    __p.q;\
522
})
523

    
524
#ifdef TARGET_X86_64
525

    
526
void OPPROTO op_movq_T0_im64(void)
527
{
528
    T0 = PARAMQ1;
529
}
530

    
531
void OPPROTO op_movq_T1_im64(void)
532
{
533
    T1 = PARAMQ1;
534
}
535

    
536
void OPPROTO op_movq_A0_im(void)
537
{
538
    A0 = (int32_t)PARAM1;
539
}
540

    
541
void OPPROTO op_movq_A0_im64(void)
542
{
543
    A0 = PARAMQ1;
544
}
545

    
546
void OPPROTO op_addq_A0_im(void)
547
{
548
    A0 = (A0 + (int32_t)PARAM1);
549
}
550

    
551
void OPPROTO op_addq_A0_im64(void)
552
{
553
    A0 = (A0 + PARAMQ1);
554
}
555

    
556
void OPPROTO op_movq_A0_seg(void)
557
{
558
    A0 = *(target_ulong *)((char *)env + PARAM1);
559
}
560

    
561
void OPPROTO op_addq_A0_seg(void)
562
{
563
    A0 += *(target_ulong *)((char *)env + PARAM1);
564
}
565

    
566
void OPPROTO op_addq_A0_AL(void)
567
{
568
    A0 = (A0 + (EAX & 0xff));
569
}
570

    
571
#endif
572

    
573
void OPPROTO op_andl_A0_ffff(void)
574
{
575
    A0 = A0 & 0xffff;
576
}
577

    
578
/* memory access */
579

    
580
#define MEMSUFFIX _raw
581
#include "ops_mem.h"
582

    
583
#if !defined(CONFIG_USER_ONLY)
584
#define MEMSUFFIX _kernel
585
#include "ops_mem.h"
586

    
587
#define MEMSUFFIX _user
588
#include "ops_mem.h"
589
#endif
590

    
591
/* indirect jump */
592

    
593
void OPPROTO op_jmp_T0(void)
594
{
595
    EIP = T0;
596
}
597

    
598
void OPPROTO op_movl_eip_im(void)
599
{
600
    EIP = (uint32_t)PARAM1;
601
}
602

    
603
#ifdef TARGET_X86_64
604
void OPPROTO op_movq_eip_im(void)
605
{
606
    EIP = (int32_t)PARAM1;
607
}
608

    
609
void OPPROTO op_movq_eip_im64(void)
610
{
611
    EIP = PARAMQ1;
612
}
613
#endif
614

    
615
void OPPROTO op_hlt(void)
616
{
617
    helper_hlt();
618
}
619

    
620
void OPPROTO op_monitor(void)
621
{
622
    helper_monitor();
623
}
624

    
625
void OPPROTO op_mwait(void)
626
{
627
    helper_mwait();
628
}
629

    
630
void OPPROTO op_debug(void)
631
{
632
    env->exception_index = EXCP_DEBUG;
633
    cpu_loop_exit();
634
}
635

    
636
void OPPROTO op_raise_interrupt(void)
637
{
638
    int intno, next_eip_addend;
639
    intno = PARAM1;
640
    next_eip_addend = PARAM2;
641
    raise_interrupt(intno, 1, 0, next_eip_addend);
642
}
643

    
644
void OPPROTO op_raise_exception(void)
645
{
646
    int exception_index;
647
    exception_index = PARAM1;
648
    raise_exception(exception_index);
649
}
650

    
651
void 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

    
661
void OPPROTO op_cli(void)
662
{
663
    env->eflags &= ~IF_MASK;
664
}
665

    
666
void OPPROTO op_sti(void)
667
{
668
    env->eflags |= IF_MASK;
669
}
670

    
671
void OPPROTO op_set_inhibit_irq(void)
672
{
673
    env->hflags |= HF_INHIBIT_IRQ_MASK;
674
}
675

    
676
void OPPROTO op_reset_inhibit_irq(void)
677
{
678
    env->hflags &= ~HF_INHIBIT_IRQ_MASK;
679
}
680

    
681
void OPPROTO op_rsm(void)
682
{
683
    helper_rsm();
684
}
685

    
686
#if 0
687
/* vm86plus instructions */
688
void OPPROTO op_cli_vm(void)
689
{
690
    env->eflags &= ~VIF_MASK;
691
}
692

693
void 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

    
704
void OPPROTO op_boundw(void)
705
{
706
    int low, high, v;
707
    low = ldsw(A0);
708
    high = ldsw(A0 + 2);
709
    v = (int16_t)T0;
710
    if (v < low || v > high) {
711
        raise_exception(EXCP05_BOUND);
712
    }
713
    FORCE_RET();
714
}
715

    
716
void OPPROTO op_boundl(void)
717
{
718
    int low, high, v;
719
    low = ldl(A0);
720
    high = ldl(A0 + 4);
721
    v = T0;
722
    if (v < low || v > high) {
723
        raise_exception(EXCP05_BOUND);
724
    }
725
    FORCE_RET();
726
}
727

    
728
void OPPROTO op_cmpxchg8b(void)
729
{
730
    helper_cmpxchg8b();
731
}
732

    
733
void OPPROTO op_single_step(void)
734
{
735
    helper_single_step();
736
}
737

    
738
void OPPROTO op_movl_T0_0(void)
739
{
740
    T0 = 0;
741
}
742

    
743
void 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

    
764
#ifdef TARGET_X86_64
765

    
766
#define SHIFT 3
767
#include "ops_template.h"
768
#undef SHIFT
769

    
770
#endif
771

    
772
/* sign extend */
773

    
774
void OPPROTO op_movsbl_T0_T0(void)
775
{
776
    T0 = (int8_t)T0;
777
}
778

    
779
void OPPROTO op_movzbl_T0_T0(void)
780
{
781
    T0 = (uint8_t)T0;
782
}
783

    
784
void OPPROTO op_movswl_T0_T0(void)
785
{
786
    T0 = (int16_t)T0;
787
}
788

    
789
void OPPROTO op_movzwl_T0_T0(void)
790
{
791
    T0 = (uint16_t)T0;
792
}
793

    
794
void OPPROTO op_movswl_EAX_AX(void)
795
{
796
    EAX = (uint32_t)((int16_t)EAX);
797
}
798

    
799
#ifdef TARGET_X86_64
800
void OPPROTO op_movslq_T0_T0(void)
801
{
802
    T0 = (int32_t)T0;
803
}
804

    
805
void OPPROTO op_movslq_RAX_EAX(void)
806
{
807
    EAX = (int32_t)EAX;
808
}
809
#endif
810

    
811
void OPPROTO op_movsbw_AX_AL(void)
812
{
813
    EAX = (EAX & ~0xffff) | ((int8_t)EAX & 0xffff);
814
}
815

    
816
void OPPROTO op_movslq_EDX_EAX(void)
817
{
818
    EDX = (uint32_t)((int32_t)EAX >> 31);
819
}
820

    
821
void OPPROTO op_movswl_DX_AX(void)
822
{
823
    EDX = (EDX & ~0xffff) | (((int16_t)EAX >> 15) & 0xffff);
824
}
825

    
826
#ifdef TARGET_X86_64
827
void OPPROTO op_movsqo_RDX_RAX(void)
828
{
829
    EDX = (int64_t)EAX >> 63;
830
}
831
#endif
832

    
833
/* string ops helpers */
834

    
835
void OPPROTO op_addl_ESI_T0(void)
836
{
837
    ESI = (uint32_t)(ESI + T0);
838
}
839

    
840
void OPPROTO op_addw_ESI_T0(void)
841
{
842
    ESI = (ESI & ~0xffff) | ((ESI + T0) & 0xffff);
843
}
844

    
845
void OPPROTO op_addl_EDI_T0(void)
846
{
847
    EDI = (uint32_t)(EDI + T0);
848
}
849

    
850
void OPPROTO op_addw_EDI_T0(void)
851
{
852
    EDI = (EDI & ~0xffff) | ((EDI + T0) & 0xffff);
853
}
854

    
855
void OPPROTO op_decl_ECX(void)
856
{
857
    ECX = (uint32_t)(ECX - 1);
858
}
859

    
860
void OPPROTO op_decw_ECX(void)
861
{
862
    ECX = (ECX & ~0xffff) | ((ECX - 1) & 0xffff);
863
}
864

    
865
#ifdef TARGET_X86_64
866
void OPPROTO op_addq_ESI_T0(void)
867
{
868
    ESI = (ESI + T0);
869
}
870

    
871
void OPPROTO op_addq_EDI_T0(void)
872
{
873
    EDI = (EDI + T0);
874
}
875

    
876
void OPPROTO op_decq_ECX(void)
877
{
878
    ECX--;
879
}
880
#endif
881

    
882
/* push/pop utils */
883

    
884
void op_addl_A0_SS(void)
885
{
886
    A0 = (uint32_t)(A0 + env->segs[R_SS].base);
887
}
888

    
889
void op_subl_A0_2(void)
890
{
891
    A0 = (uint32_t)(A0 - 2);
892
}
893

    
894
void op_subl_A0_4(void)
895
{
896
    A0 = (uint32_t)(A0 - 4);
897
}
898

    
899
void op_addl_ESP_4(void)
900
{
901
    ESP = (uint32_t)(ESP + 4);
902
}
903

    
904
void op_addl_ESP_2(void)
905
{
906
    ESP = (uint32_t)(ESP + 2);
907
}
908

    
909
void op_addw_ESP_4(void)
910
{
911
    ESP = (ESP & ~0xffff) | ((ESP + 4) & 0xffff);
912
}
913

    
914
void op_addw_ESP_2(void)
915
{
916
    ESP = (ESP & ~0xffff) | ((ESP + 2) & 0xffff);
917
}
918

    
919
void op_addl_ESP_im(void)
920
{
921
    ESP = (uint32_t)(ESP + PARAM1);
922
}
923

    
924
void op_addw_ESP_im(void)
925
{
926
    ESP = (ESP & ~0xffff) | ((ESP + PARAM1) & 0xffff);
927
}
928

    
929
#ifdef TARGET_X86_64
930
void op_subq_A0_2(void)
931
{
932
    A0 -= 2;
933
}
934

    
935
void op_subq_A0_8(void)
936
{
937
    A0 -= 8;
938
}
939

    
940
void op_addq_ESP_8(void)
941
{
942
    ESP += 8;
943
}
944

    
945
void op_addq_ESP_im(void)
946
{
947
    ESP += PARAM1;
948
}
949
#endif
950

    
951
void OPPROTO op_rdtsc(void)
952
{
953
    helper_rdtsc();
954
}
955

    
956
void OPPROTO op_cpuid(void)
957
{
958
    helper_cpuid();
959
}
960

    
961
void OPPROTO op_enter_level(void)
962
{
963
    helper_enter_level(PARAM1, PARAM2);
964
}
965

    
966
#ifdef TARGET_X86_64
967
void OPPROTO op_enter64_level(void)
968
{
969
    helper_enter64_level(PARAM1, PARAM2);
970
}
971
#endif
972

    
973
void OPPROTO op_sysenter(void)
974
{
975
    helper_sysenter();
976
}
977

    
978
void OPPROTO op_sysexit(void)
979
{
980
    helper_sysexit();
981
}
982

    
983
#ifdef TARGET_X86_64
984
void OPPROTO op_syscall(void)
985
{
986
    helper_syscall(PARAM1);
987
}
988

    
989
void OPPROTO op_sysret(void)
990
{
991
    helper_sysret(PARAM1);
992
}
993
#endif
994

    
995
void OPPROTO op_rdmsr(void)
996
{
997
    helper_rdmsr();
998
}
999

    
1000
void OPPROTO op_wrmsr(void)
1001
{
1002
    helper_wrmsr();
1003
}
1004

    
1005
/* bcd */
1006

    
1007
/* XXX: exception */
1008
void 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

    
1019
void 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

    
1030
void 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;
1052
    FORCE_RET();
1053
}
1054

    
1055
void 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;
1077
    FORCE_RET();
1078
}
1079

    
1080
void 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;
1105
    FORCE_RET();
1106
}
1107

    
1108
void 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;
1136
    FORCE_RET();
1137
}
1138

    
1139
/* segment handling */
1140

    
1141
/* never use it with R_CS */
1142
void OPPROTO op_movl_seg_T0(void)
1143
{
1144
    load_seg(PARAM1, T0);
1145
}
1146

    
1147
/* faster VM86 version */
1148
void OPPROTO op_movl_seg_T0_vm(void)
1149
{
1150
    int selector;
1151
    SegmentCache *sc;
1152

    
1153
    selector = T0 & 0xffff;
1154
    /* env->segs[] access */
1155
    sc = (SegmentCache *)((char *)env + PARAM1);
1156
    sc->selector = selector;
1157
    sc->base = (selector << 4);
1158
}
1159

    
1160
void OPPROTO op_movl_T0_seg(void)
1161
{
1162
    T0 = env->segs[PARAM1].selector;
1163
}
1164

    
1165
void OPPROTO op_lsl(void)
1166
{
1167
    helper_lsl();
1168
}
1169

    
1170
void OPPROTO op_lar(void)
1171
{
1172
    helper_lar();
1173
}
1174

    
1175
void OPPROTO op_verr(void)
1176
{
1177
    helper_verr();
1178
}
1179

    
1180
void OPPROTO op_verw(void)
1181
{
1182
    helper_verw();
1183
}
1184

    
1185
void 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
}
1196

    
1197
void 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
}
1203

    
1204
/* T0: segment, T1:eip */
1205
void OPPROTO op_ljmp_protected_T0_T1(void)
1206
{
1207
    helper_ljmp_protected_T0_T1(PARAM1);
1208
}
1209

    
1210
void OPPROTO op_lcall_real_T0_T1(void)
1211
{
1212
    helper_lcall_real_T0_T1(PARAM1, PARAM2);
1213
}
1214

    
1215
void OPPROTO op_lcall_protected_T0_T1(void)
1216
{
1217
    helper_lcall_protected_T0_T1(PARAM1, PARAM2);
1218
}
1219

    
1220
void OPPROTO op_iret_real(void)
1221
{
1222
    helper_iret_real(PARAM1);
1223
}
1224

    
1225
void OPPROTO op_iret_protected(void)
1226
{
1227
    helper_iret_protected(PARAM1, PARAM2);
1228
}
1229

    
1230
void OPPROTO op_lret_protected(void)
1231
{
1232
    helper_lret_protected(PARAM1, PARAM2);
1233
}
1234

    
1235
void OPPROTO op_lldt_T0(void)
1236
{
1237
    helper_lldt_T0();
1238
}
1239

    
1240
void OPPROTO op_ltr_T0(void)
1241
{
1242
    helper_ltr_T0();
1243
}
1244

    
1245
/* CR registers access. */
1246
void OPPROTO op_movl_crN_T0(void)
1247
{
1248
    helper_movl_crN_T0(PARAM1);
1249
}
1250

    
1251
/* These pseudo-opcodes check for SVM intercepts. */
1252
void OPPROTO op_svm_check_intercept(void)
1253
{
1254
    A0 = PARAM1 & PARAM2;
1255
    svm_check_intercept(PARAMQ1);
1256
}
1257

    
1258
void OPPROTO op_svm_check_intercept_param(void)
1259
{
1260
    A0 = PARAM1 & PARAM2;
1261
    svm_check_intercept_param(PARAMQ1, T1);
1262
}
1263

    
1264
void OPPROTO op_svm_vmexit(void)
1265
{
1266
    A0 = PARAM1 & PARAM2;
1267
    vmexit(PARAMQ1, T1);
1268
}
1269

    
1270
void OPPROTO op_geneflags(void)
1271
{
1272
    CC_SRC = cc_table[CC_OP].compute_all();
1273
}
1274

    
1275
/* This pseudo-opcode checks for IO intercepts. */
1276
#if !defined(CONFIG_USER_ONLY)
1277
void OPPROTO op_svm_check_intercept_io(void)
1278
{
1279
    A0 = PARAM1 & PARAM2;
1280
    /* PARAMQ1 = TYPE (0 = OUT, 1 = IN; 4 = STRING; 8 = REP)
1281
       T0      = PORT
1282
       T1      = next eip */
1283
    stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2), T1);
1284
    /* ASIZE does not appear on real hw */
1285
    svm_check_intercept_param(SVM_EXIT_IOIO,
1286
                              (PARAMQ1 & ~SVM_IOIO_ASIZE_MASK) |
1287
                              ((T0 & 0xffff) << 16));
1288
}
1289
#endif
1290

    
1291
#if !defined(CONFIG_USER_ONLY)
1292
void OPPROTO op_movtl_T0_cr8(void)
1293
{
1294
    T0 = cpu_get_apic_tpr(env);
1295
}
1296
#endif
1297

    
1298
/* DR registers access */
1299
void OPPROTO op_movl_drN_T0(void)
1300
{
1301
    helper_movl_drN_T0(PARAM1);
1302
}
1303

    
1304
void OPPROTO op_lmsw_T0(void)
1305
{
1306
    /* only 4 lower bits of CR0 are modified. PE cannot be set to zero
1307
       if already set to one. */
1308
    T0 = (env->cr[0] & ~0xe) | (T0 & 0xf);
1309
    helper_movl_crN_T0(0);
1310
}
1311

    
1312
void OPPROTO op_invlpg_A0(void)
1313
{
1314
    helper_invlpg(A0);
1315
}
1316

    
1317
void OPPROTO op_movl_T0_env(void)
1318
{
1319
    T0 = *(uint32_t *)((char *)env + PARAM1);
1320
}
1321

    
1322
void OPPROTO op_movl_env_T0(void)
1323
{
1324
    *(uint32_t *)((char *)env + PARAM1) = T0;
1325
}
1326

    
1327
void OPPROTO op_movl_env_T1(void)
1328
{
1329
    *(uint32_t *)((char *)env + PARAM1) = T1;
1330
}
1331

    
1332
void OPPROTO op_movtl_T0_env(void)
1333
{
1334
    T0 = *(target_ulong *)((char *)env + PARAM1);
1335
}
1336

    
1337
void OPPROTO op_movtl_env_T0(void)
1338
{
1339
    *(target_ulong *)((char *)env + PARAM1) = T0;
1340
}
1341

    
1342
void OPPROTO op_movtl_T1_env(void)
1343
{
1344
    T1 = *(target_ulong *)((char *)env + PARAM1);
1345
}
1346

    
1347
void OPPROTO op_movtl_env_T1(void)
1348
{
1349
    *(target_ulong *)((char *)env + PARAM1) = T1;
1350
}
1351

    
1352
void OPPROTO op_clts(void)
1353
{
1354
    env->cr[0] &= ~CR0_TS_MASK;
1355
    env->hflags &= ~HF_TS_MASK;
1356
}
1357

    
1358
/* flags handling */
1359

    
1360
void OPPROTO op_goto_tb0(void)
1361
{
1362
    GOTO_TB(op_goto_tb0, PARAM1, 0);
1363
}
1364

    
1365
void OPPROTO op_goto_tb1(void)
1366
{
1367
    GOTO_TB(op_goto_tb1, PARAM1, 1);
1368
}
1369

    
1370
void OPPROTO op_jmp_label(void)
1371
{
1372
    GOTO_LABEL_PARAM(1);
1373
}
1374

    
1375
void OPPROTO op_jnz_T0_label(void)
1376
{
1377
    if (T0)
1378
        GOTO_LABEL_PARAM(1);
1379
    FORCE_RET();
1380
}
1381

    
1382
void OPPROTO op_jz_T0_label(void)
1383
{
1384
    if (!T0)
1385
        GOTO_LABEL_PARAM(1);
1386
    FORCE_RET();
1387
}
1388

    
1389
/* slow set cases (compute x86 flags) */
1390
void OPPROTO op_seto_T0_cc(void)
1391
{
1392
    int eflags;
1393
    eflags = cc_table[CC_OP].compute_all();
1394
    T0 = (eflags >> 11) & 1;
1395
}
1396

    
1397
void OPPROTO op_setb_T0_cc(void)
1398
{
1399
    T0 = cc_table[CC_OP].compute_c();
1400
}
1401

    
1402
void OPPROTO op_setz_T0_cc(void)
1403
{
1404
    int eflags;
1405
    eflags = cc_table[CC_OP].compute_all();
1406
    T0 = (eflags >> 6) & 1;
1407
}
1408

    
1409
void OPPROTO op_setbe_T0_cc(void)
1410
{
1411
    int eflags;
1412
    eflags = cc_table[CC_OP].compute_all();
1413
    T0 = (eflags & (CC_Z | CC_C)) != 0;
1414
}
1415

    
1416
void OPPROTO op_sets_T0_cc(void)
1417
{
1418
    int eflags;
1419
    eflags = cc_table[CC_OP].compute_all();
1420
    T0 = (eflags >> 7) & 1;
1421
}
1422

    
1423
void OPPROTO op_setp_T0_cc(void)
1424
{
1425
    int eflags;
1426
    eflags = cc_table[CC_OP].compute_all();
1427
    T0 = (eflags >> 2) & 1;
1428
}
1429

    
1430
void OPPROTO op_setl_T0_cc(void)
1431
{
1432
    int eflags;
1433
    eflags = cc_table[CC_OP].compute_all();
1434
    T0 = ((eflags ^ (eflags >> 4)) >> 7) & 1;
1435
}
1436

    
1437
void OPPROTO op_setle_T0_cc(void)
1438
{
1439
    int eflags;
1440
    eflags = cc_table[CC_OP].compute_all();
1441
    T0 = (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) != 0;
1442
}
1443

    
1444
void OPPROTO op_xor_T0_1(void)
1445
{
1446
    T0 ^= 1;
1447
}
1448

    
1449
void OPPROTO op_set_cc_op(void)
1450
{
1451
    CC_OP = PARAM1;
1452
}
1453

    
1454
void OPPROTO op_mov_T0_cc(void)
1455
{
1456
    T0 = cc_table[CC_OP].compute_all();
1457
}
1458

    
1459
/* XXX: clear VIF/VIP in all ops ? */
1460

    
1461
void OPPROTO op_movl_eflags_T0(void)
1462
{
1463
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK));
1464
}
1465

    
1466
void OPPROTO op_movw_eflags_T0(void)
1467
{
1468
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK) & 0xffff);
1469
}
1470

    
1471
void OPPROTO op_movl_eflags_T0_io(void)
1472
{
1473
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK));
1474
}
1475

    
1476
void OPPROTO op_movw_eflags_T0_io(void)
1477
{
1478
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK) & 0xffff);
1479
}
1480

    
1481
void OPPROTO op_movl_eflags_T0_cpl0(void)
1482
{
1483
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK));
1484
}
1485

    
1486
void OPPROTO op_movw_eflags_T0_cpl0(void)
1487
{
1488
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK) & 0xffff);
1489
}
1490

    
1491
#if 0
1492
/* vm86plus version */
1493
void OPPROTO op_movw_eflags_T0_vm(void)
1494
{
1495
    int eflags;
1496
    eflags = T0;
1497
    CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
1498
    DF = 1 - (2 * ((eflags >> 10) & 1));
1499
    /* we also update some system flags as in user mode */
1500
    env->eflags = (env->eflags & ~(FL_UPDATE_MASK16 | VIF_MASK)) |
1501
        (eflags & FL_UPDATE_MASK16);
1502
    if (eflags & IF_MASK) {
1503
        env->eflags |= VIF_MASK;
1504
        if (env->eflags & VIP_MASK) {
1505
            EIP = PARAM1;
1506
            raise_exception(EXCP0D_GPF);
1507
        }
1508
    }
1509
    FORCE_RET();
1510
}
1511

1512
void OPPROTO op_movl_eflags_T0_vm(void)
1513
{
1514
    int eflags;
1515
    eflags = T0;
1516
    CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
1517
    DF = 1 - (2 * ((eflags >> 10) & 1));
1518
    /* we also update some system flags as in user mode */
1519
    env->eflags = (env->eflags & ~(FL_UPDATE_MASK32 | VIF_MASK)) |
1520
        (eflags & FL_UPDATE_MASK32);
1521
    if (eflags & IF_MASK) {
1522
        env->eflags |= VIF_MASK;
1523
        if (env->eflags & VIP_MASK) {
1524
            EIP = PARAM1;
1525
            raise_exception(EXCP0D_GPF);
1526
        }
1527
    }
1528
    FORCE_RET();
1529
}
1530
#endif
1531

    
1532
/* XXX: compute only O flag */
1533
void OPPROTO op_movb_eflags_T0(void)
1534
{
1535
    int of;
1536
    of = cc_table[CC_OP].compute_all() & CC_O;
1537
    CC_SRC = (T0 & (CC_S | CC_Z | CC_A | CC_P | CC_C)) | of;
1538
}
1539

    
1540
void OPPROTO op_movl_T0_eflags(void)
1541
{
1542
    int eflags;
1543
    eflags = cc_table[CC_OP].compute_all();
1544
    eflags |= (DF & DF_MASK);
1545
    eflags |= env->eflags & ~(VM_MASK | RF_MASK);
1546
    T0 = eflags;
1547
}
1548

    
1549
/* vm86plus version */
1550
#if 0
1551
void OPPROTO op_movl_T0_eflags_vm(void)
1552
{
1553
    int eflags;
1554
    eflags = cc_table[CC_OP].compute_all();
1555
    eflags |= (DF & DF_MASK);
1556
    eflags |= env->eflags & ~(VM_MASK | RF_MASK | IF_MASK);
1557
    if (env->eflags & VIF_MASK)
1558
        eflags |= IF_MASK;
1559
    T0 = eflags;
1560
}
1561
#endif
1562

    
1563
void OPPROTO op_cld(void)
1564
{
1565
    DF = 1;
1566
}
1567

    
1568
void OPPROTO op_std(void)
1569
{
1570
    DF = -1;
1571
}
1572

    
1573
void OPPROTO op_clc(void)
1574
{
1575
    int eflags;
1576
    eflags = cc_table[CC_OP].compute_all();
1577
    eflags &= ~CC_C;
1578
    CC_SRC = eflags;
1579
}
1580

    
1581
void OPPROTO op_stc(void)
1582
{
1583
    int eflags;
1584
    eflags = cc_table[CC_OP].compute_all();
1585
    eflags |= CC_C;
1586
    CC_SRC = eflags;
1587
}
1588

    
1589
void OPPROTO op_cmc(void)
1590
{
1591
    int eflags;
1592
    eflags = cc_table[CC_OP].compute_all();
1593
    eflags ^= CC_C;
1594
    CC_SRC = eflags;
1595
}
1596

    
1597
void OPPROTO op_salc(void)
1598
{
1599
    int cf;
1600
    cf = cc_table[CC_OP].compute_c();
1601
    EAX = (EAX & ~0xff) | ((-cf) & 0xff);
1602
}
1603

    
1604
static int compute_all_eflags(void)
1605
{
1606
    return CC_SRC;
1607
}
1608

    
1609
static int compute_c_eflags(void)
1610
{
1611
    return CC_SRC & CC_C;
1612
}
1613

    
1614
CCTable cc_table[CC_OP_NB] = {
1615
    [CC_OP_DYNAMIC] = { /* should never happen */ },
1616

    
1617
    [CC_OP_EFLAGS] = { compute_all_eflags, compute_c_eflags },
1618

    
1619
    [CC_OP_MULB] = { compute_all_mulb, compute_c_mull },
1620
    [CC_OP_MULW] = { compute_all_mulw, compute_c_mull },
1621
    [CC_OP_MULL] = { compute_all_mull, compute_c_mull },
1622

    
1623
    [CC_OP_ADDB] = { compute_all_addb, compute_c_addb },
1624
    [CC_OP_ADDW] = { compute_all_addw, compute_c_addw  },
1625
    [CC_OP_ADDL] = { compute_all_addl, compute_c_addl  },
1626

    
1627
    [CC_OP_ADCB] = { compute_all_adcb, compute_c_adcb },
1628
    [CC_OP_ADCW] = { compute_all_adcw, compute_c_adcw  },
1629
    [CC_OP_ADCL] = { compute_all_adcl, compute_c_adcl  },
1630

    
1631
    [CC_OP_SUBB] = { compute_all_subb, compute_c_subb  },
1632
    [CC_OP_SUBW] = { compute_all_subw, compute_c_subw  },
1633
    [CC_OP_SUBL] = { compute_all_subl, compute_c_subl  },
1634

    
1635
    [CC_OP_SBBB] = { compute_all_sbbb, compute_c_sbbb  },
1636
    [CC_OP_SBBW] = { compute_all_sbbw, compute_c_sbbw  },
1637
    [CC_OP_SBBL] = { compute_all_sbbl, compute_c_sbbl  },
1638

    
1639
    [CC_OP_LOGICB] = { compute_all_logicb, compute_c_logicb },
1640
    [CC_OP_LOGICW] = { compute_all_logicw, compute_c_logicw },
1641
    [CC_OP_LOGICL] = { compute_all_logicl, compute_c_logicl },
1642

    
1643
    [CC_OP_INCB] = { compute_all_incb, compute_c_incl },
1644
    [CC_OP_INCW] = { compute_all_incw, compute_c_incl },
1645
    [CC_OP_INCL] = { compute_all_incl, compute_c_incl },
1646

    
1647
    [CC_OP_DECB] = { compute_all_decb, compute_c_incl },
1648
    [CC_OP_DECW] = { compute_all_decw, compute_c_incl },
1649
    [CC_OP_DECL] = { compute_all_decl, compute_c_incl },
1650

    
1651
    [CC_OP_SHLB] = { compute_all_shlb, compute_c_shlb },
1652
    [CC_OP_SHLW] = { compute_all_shlw, compute_c_shlw },
1653
    [CC_OP_SHLL] = { compute_all_shll, compute_c_shll },
1654

    
1655
    [CC_OP_SARB] = { compute_all_sarb, compute_c_sarl },
1656
    [CC_OP_SARW] = { compute_all_sarw, compute_c_sarl },
1657
    [CC_OP_SARL] = { compute_all_sarl, compute_c_sarl },
1658

    
1659
#ifdef TARGET_X86_64
1660
    [CC_OP_MULQ] = { compute_all_mulq, compute_c_mull },
1661

    
1662
    [CC_OP_ADDQ] = { compute_all_addq, compute_c_addq  },
1663

    
1664
    [CC_OP_ADCQ] = { compute_all_adcq, compute_c_adcq  },
1665

    
1666
    [CC_OP_SUBQ] = { compute_all_subq, compute_c_subq  },
1667

    
1668
    [CC_OP_SBBQ] = { compute_all_sbbq, compute_c_sbbq  },
1669

    
1670
    [CC_OP_LOGICQ] = { compute_all_logicq, compute_c_logicq },
1671

    
1672
    [CC_OP_INCQ] = { compute_all_incq, compute_c_incl },
1673

    
1674
    [CC_OP_DECQ] = { compute_all_decq, compute_c_incl },
1675

    
1676
    [CC_OP_SHLQ] = { compute_all_shlq, compute_c_shlq },
1677

    
1678
    [CC_OP_SARQ] = { compute_all_sarq, compute_c_sarl },
1679
#endif
1680
};
1681

    
1682
/* floating point support. Some of the code for complicated x87
1683
   functions comes from the LGPL'ed x86 emulator found in the Willows
1684
   TWIN windows emulator. */
1685

    
1686
/* fp load FT0 */
1687

    
1688
void OPPROTO op_flds_FT0_A0(void)
1689
{
1690
#ifdef USE_FP_CONVERT
1691
    FP_CONVERT.i32 = ldl(A0);
1692
    FT0 = FP_CONVERT.f;
1693
#else
1694
    FT0 = ldfl(A0);
1695
#endif
1696
}
1697

    
1698
void OPPROTO op_fldl_FT0_A0(void)
1699
{
1700
#ifdef USE_FP_CONVERT
1701
    FP_CONVERT.i64 = ldq(A0);
1702
    FT0 = FP_CONVERT.d;
1703
#else
1704
    FT0 = ldfq(A0);
1705
#endif
1706
}
1707

    
1708
/* helpers are needed to avoid static constant reference. XXX: find a better way */
1709
#ifdef USE_INT_TO_FLOAT_HELPERS
1710

    
1711
void helper_fild_FT0_A0(void)
1712
{
1713
    FT0 = (CPU86_LDouble)ldsw(A0);
1714
}
1715

    
1716
void helper_fildl_FT0_A0(void)
1717
{
1718
    FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
1719
}
1720

    
1721
void helper_fildll_FT0_A0(void)
1722
{
1723
    FT0 = (CPU86_LDouble)((int64_t)ldq(A0));
1724
}
1725

    
1726
void OPPROTO op_fild_FT0_A0(void)
1727
{
1728
    helper_fild_FT0_A0();
1729
}
1730

    
1731
void OPPROTO op_fildl_FT0_A0(void)
1732
{
1733
    helper_fildl_FT0_A0();
1734
}
1735

    
1736
void OPPROTO op_fildll_FT0_A0(void)
1737
{
1738
    helper_fildll_FT0_A0();
1739
}
1740

    
1741
#else
1742

    
1743
void OPPROTO op_fild_FT0_A0(void)
1744
{
1745
#ifdef USE_FP_CONVERT
1746
    FP_CONVERT.i32 = ldsw(A0);
1747
    FT0 = (CPU86_LDouble)FP_CONVERT.i32;
1748
#else
1749
    FT0 = (CPU86_LDouble)ldsw(A0);
1750
#endif
1751
}
1752

    
1753
void OPPROTO op_fildl_FT0_A0(void)
1754
{
1755
#ifdef USE_FP_CONVERT
1756
    FP_CONVERT.i32 = (int32_t) ldl(A0);
1757
    FT0 = (CPU86_LDouble)FP_CONVERT.i32;
1758
#else
1759
    FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
1760
#endif
1761
}
1762

    
1763
void OPPROTO op_fildll_FT0_A0(void)
1764
{
1765
#ifdef USE_FP_CONVERT
1766
    FP_CONVERT.i64 = (int64_t) ldq(A0);
1767
    FT0 = (CPU86_LDouble)FP_CONVERT.i64;
1768
#else
1769
    FT0 = (CPU86_LDouble)((int64_t)ldq(A0));
1770
#endif
1771
}
1772
#endif
1773

    
1774
/* fp load ST0 */
1775

    
1776
void OPPROTO op_flds_ST0_A0(void)
1777
{
1778
    int new_fpstt;
1779
    new_fpstt = (env->fpstt - 1) & 7;
1780
#ifdef USE_FP_CONVERT
1781
    FP_CONVERT.i32 = ldl(A0);
1782
    env->fpregs[new_fpstt].d = FP_CONVERT.f;
1783
#else
1784
    env->fpregs[new_fpstt].d = ldfl(A0);
1785
#endif
1786
    env->fpstt = new_fpstt;
1787
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1788
}
1789

    
1790
void OPPROTO op_fldl_ST0_A0(void)
1791
{
1792
    int new_fpstt;
1793
    new_fpstt = (env->fpstt - 1) & 7;
1794
#ifdef USE_FP_CONVERT
1795
    FP_CONVERT.i64 = ldq(A0);
1796
    env->fpregs[new_fpstt].d = FP_CONVERT.d;
1797
#else
1798
    env->fpregs[new_fpstt].d = ldfq(A0);
1799
#endif
1800
    env->fpstt = new_fpstt;
1801
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1802
}
1803

    
1804
void OPPROTO op_fldt_ST0_A0(void)
1805
{
1806
    helper_fldt_ST0_A0();
1807
}
1808

    
1809
/* helpers are needed to avoid static constant reference. XXX: find a better way */
1810
#ifdef USE_INT_TO_FLOAT_HELPERS
1811

    
1812
void helper_fild_ST0_A0(void)
1813
{
1814
    int new_fpstt;
1815
    new_fpstt = (env->fpstt - 1) & 7;
1816
    env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0);
1817
    env->fpstt = new_fpstt;
1818
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1819
}
1820

    
1821
void helper_fildl_ST0_A0(void)
1822
{
1823
    int new_fpstt;
1824
    new_fpstt = (env->fpstt - 1) & 7;
1825
    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
1826
    env->fpstt = new_fpstt;
1827
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1828
}
1829

    
1830
void helper_fildll_ST0_A0(void)
1831
{
1832
    int new_fpstt;
1833
    new_fpstt = (env->fpstt - 1) & 7;
1834
    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0));
1835
    env->fpstt = new_fpstt;
1836
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1837
}
1838

    
1839
void OPPROTO op_fild_ST0_A0(void)
1840
{
1841
    helper_fild_ST0_A0();
1842
}
1843

    
1844
void OPPROTO op_fildl_ST0_A0(void)
1845
{
1846
    helper_fildl_ST0_A0();
1847
}
1848

    
1849
void OPPROTO op_fildll_ST0_A0(void)
1850
{
1851
    helper_fildll_ST0_A0();
1852
}
1853

    
1854
#else
1855

    
1856
void OPPROTO op_fild_ST0_A0(void)
1857
{
1858
    int new_fpstt;
1859
    new_fpstt = (env->fpstt - 1) & 7;
1860
#ifdef USE_FP_CONVERT
1861
    FP_CONVERT.i32 = ldsw(A0);
1862
    env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
1863
#else
1864
    env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0);
1865
#endif
1866
    env->fpstt = new_fpstt;
1867
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1868
}
1869

    
1870
void OPPROTO op_fildl_ST0_A0(void)
1871
{
1872
    int new_fpstt;
1873
    new_fpstt = (env->fpstt - 1) & 7;
1874
#ifdef USE_FP_CONVERT
1875
    FP_CONVERT.i32 = (int32_t) ldl(A0);
1876
    env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
1877
#else
1878
    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
1879
#endif
1880
    env->fpstt = new_fpstt;
1881
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1882
}
1883

    
1884
void OPPROTO op_fildll_ST0_A0(void)
1885
{
1886
    int new_fpstt;
1887
    new_fpstt = (env->fpstt - 1) & 7;
1888
#ifdef USE_FP_CONVERT
1889
    FP_CONVERT.i64 = (int64_t) ldq(A0);
1890
    env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i64;
1891
#else
1892
    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0));
1893
#endif
1894
    env->fpstt = new_fpstt;
1895
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1896
}
1897

    
1898
#endif
1899

    
1900
/* fp store */
1901

    
1902
void OPPROTO op_fsts_ST0_A0(void)
1903
{
1904
#ifdef USE_FP_CONVERT
1905
    FP_CONVERT.f = (float)ST0;
1906
    stfl(A0, FP_CONVERT.f);
1907
#else
1908
    stfl(A0, (float)ST0);
1909
#endif
1910
    FORCE_RET();
1911
}
1912

    
1913
void OPPROTO op_fstl_ST0_A0(void)
1914
{
1915
    stfq(A0, (double)ST0);
1916
    FORCE_RET();
1917
}
1918

    
1919
void OPPROTO op_fstt_ST0_A0(void)
1920
{
1921
    helper_fstt_ST0_A0();
1922
}
1923

    
1924
void OPPROTO op_fist_ST0_A0(void)
1925
{
1926
#if defined(__sparc__) && !defined(__sparc_v9__)
1927
    register CPU86_LDouble d asm("o0");
1928
#else
1929
    CPU86_LDouble d;
1930
#endif
1931
    int val;
1932

    
1933
    d = ST0;
1934
    val = floatx_to_int32(d, &env->fp_status);
1935
    if (val != (int16_t)val)
1936
        val = -32768;
1937
    stw(A0, val);
1938
    FORCE_RET();
1939
}
1940

    
1941
void OPPROTO op_fistl_ST0_A0(void)
1942
{
1943
#if defined(__sparc__) && !defined(__sparc_v9__)
1944
    register CPU86_LDouble d asm("o0");
1945
#else
1946
    CPU86_LDouble d;
1947
#endif
1948
    int val;
1949

    
1950
    d = ST0;
1951
    val = floatx_to_int32(d, &env->fp_status);
1952
    stl(A0, val);
1953
    FORCE_RET();
1954
}
1955

    
1956
void OPPROTO op_fistll_ST0_A0(void)
1957
{
1958
#if defined(__sparc__) && !defined(__sparc_v9__)
1959
    register CPU86_LDouble d asm("o0");
1960
#else
1961
    CPU86_LDouble d;
1962
#endif
1963
    int64_t val;
1964

    
1965
    d = ST0;
1966
    val = floatx_to_int64(d, &env->fp_status);
1967
    stq(A0, val);
1968
    FORCE_RET();
1969
}
1970

    
1971
void OPPROTO op_fistt_ST0_A0(void)
1972
{
1973
#if defined(__sparc__) && !defined(__sparc_v9__)
1974
    register CPU86_LDouble d asm("o0");
1975
#else
1976
    CPU86_LDouble d;
1977
#endif
1978
    int val;
1979

    
1980
    d = ST0;
1981
    val = floatx_to_int32_round_to_zero(d, &env->fp_status);
1982
    if (val != (int16_t)val)
1983
        val = -32768;
1984
    stw(A0, val);
1985
    FORCE_RET();
1986
}
1987

    
1988
void OPPROTO op_fisttl_ST0_A0(void)
1989
{
1990
#if defined(__sparc__) && !defined(__sparc_v9__)
1991
    register CPU86_LDouble d asm("o0");
1992
#else
1993
    CPU86_LDouble d;
1994
#endif
1995
    int val;
1996

    
1997
    d = ST0;
1998
    val = floatx_to_int32_round_to_zero(d, &env->fp_status);
1999
    stl(A0, val);
2000
    FORCE_RET();
2001
}
2002

    
2003
void OPPROTO op_fisttll_ST0_A0(void)
2004
{
2005
#if defined(__sparc__) && !defined(__sparc_v9__)
2006
    register CPU86_LDouble d asm("o0");
2007
#else
2008
    CPU86_LDouble d;
2009
#endif
2010
    int64_t val;
2011

    
2012
    d = ST0;
2013
    val = floatx_to_int64_round_to_zero(d, &env->fp_status);
2014
    stq(A0, val);
2015
    FORCE_RET();
2016
}
2017

    
2018
void OPPROTO op_fbld_ST0_A0(void)
2019
{
2020
    helper_fbld_ST0_A0();
2021
}
2022

    
2023
void OPPROTO op_fbst_ST0_A0(void)
2024
{
2025
    helper_fbst_ST0_A0();
2026
}
2027

    
2028
/* FPU move */
2029

    
2030
void OPPROTO op_fpush(void)
2031
{
2032
    fpush();
2033
}
2034

    
2035
void OPPROTO op_fpop(void)
2036
{
2037
    fpop();
2038
}
2039

    
2040
void OPPROTO op_fdecstp(void)
2041
{
2042
    env->fpstt = (env->fpstt - 1) & 7;
2043
    env->fpus &= (~0x4700);
2044
}
2045

    
2046
void OPPROTO op_fincstp(void)
2047
{
2048
    env->fpstt = (env->fpstt + 1) & 7;
2049
    env->fpus &= (~0x4700);
2050
}
2051

    
2052
void OPPROTO op_ffree_STN(void)
2053
{
2054
    env->fptags[(env->fpstt + PARAM1) & 7] = 1;
2055
}
2056

    
2057
void OPPROTO op_fmov_ST0_FT0(void)
2058
{
2059
    ST0 = FT0;
2060
}
2061

    
2062
void OPPROTO op_fmov_FT0_STN(void)
2063
{
2064
    FT0 = ST(PARAM1);
2065
}
2066

    
2067
void OPPROTO op_fmov_ST0_STN(void)
2068
{
2069
    ST0 = ST(PARAM1);
2070
}
2071

    
2072
void OPPROTO op_fmov_STN_ST0(void)
2073
{
2074
    ST(PARAM1) = ST0;
2075
}
2076

    
2077
void OPPROTO op_fxchg_ST0_STN(void)
2078
{
2079
    CPU86_LDouble tmp;
2080
    tmp = ST(PARAM1);
2081
    ST(PARAM1) = ST0;
2082
    ST0 = tmp;
2083
}
2084

    
2085
/* FPU operations */
2086

    
2087
const int fcom_ccval[4] = {0x0100, 0x4000, 0x0000, 0x4500};
2088

    
2089
void OPPROTO op_fcom_ST0_FT0(void)
2090
{
2091
    int ret;
2092

    
2093
    ret = floatx_compare(ST0, FT0, &env->fp_status);
2094
    env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret + 1];
2095
    FORCE_RET();
2096
}
2097

    
2098
void OPPROTO op_fucom_ST0_FT0(void)
2099
{
2100
    int ret;
2101

    
2102
    ret = floatx_compare_quiet(ST0, FT0, &env->fp_status);
2103
    env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret+ 1];
2104
    FORCE_RET();
2105
}
2106

    
2107
const int fcomi_ccval[4] = {CC_C, CC_Z, 0, CC_Z | CC_P | CC_C};
2108

    
2109
void OPPROTO op_fcomi_ST0_FT0(void)
2110
{
2111
    int eflags;
2112
    int ret;
2113

    
2114
    ret = floatx_compare(ST0, FT0, &env->fp_status);
2115
    eflags = cc_table[CC_OP].compute_all();
2116
    eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
2117
    CC_SRC = eflags;
2118
    FORCE_RET();
2119
}
2120

    
2121
void OPPROTO op_fucomi_ST0_FT0(void)
2122
{
2123
    int eflags;
2124
    int ret;
2125

    
2126
    ret = floatx_compare_quiet(ST0, FT0, &env->fp_status);
2127
    eflags = cc_table[CC_OP].compute_all();
2128
    eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
2129
    CC_SRC = eflags;
2130
    FORCE_RET();
2131
}
2132

    
2133
void OPPROTO op_fcmov_ST0_STN_T0(void)
2134
{
2135
    if (T0) {
2136
        ST0 = ST(PARAM1);
2137
    }
2138
    FORCE_RET();
2139
}
2140

    
2141
void OPPROTO op_fadd_ST0_FT0(void)
2142
{
2143
    ST0 += FT0;
2144
}
2145

    
2146
void OPPROTO op_fmul_ST0_FT0(void)
2147
{
2148
    ST0 *= FT0;
2149
}
2150

    
2151
void OPPROTO op_fsub_ST0_FT0(void)
2152
{
2153
    ST0 -= FT0;
2154
}
2155

    
2156
void OPPROTO op_fsubr_ST0_FT0(void)
2157
{
2158
    ST0 = FT0 - ST0;
2159
}
2160

    
2161
void OPPROTO op_fdiv_ST0_FT0(void)
2162
{
2163
    ST0 = helper_fdiv(ST0, FT0);
2164
}
2165

    
2166
void OPPROTO op_fdivr_ST0_FT0(void)
2167
{
2168
    ST0 = helper_fdiv(FT0, ST0);
2169
}
2170

    
2171
/* fp operations between STN and ST0 */
2172

    
2173
void OPPROTO op_fadd_STN_ST0(void)
2174
{
2175
    ST(PARAM1) += ST0;
2176
}
2177

    
2178
void OPPROTO op_fmul_STN_ST0(void)
2179
{
2180
    ST(PARAM1) *= ST0;
2181
}
2182

    
2183
void OPPROTO op_fsub_STN_ST0(void)
2184
{
2185
    ST(PARAM1) -= ST0;
2186
}
2187

    
2188
void OPPROTO op_fsubr_STN_ST0(void)
2189
{
2190
    CPU86_LDouble *p;
2191
    p = &ST(PARAM1);
2192
    *p = ST0 - *p;
2193
}
2194

    
2195
void OPPROTO op_fdiv_STN_ST0(void)
2196
{
2197
    CPU86_LDouble *p;
2198
    p = &ST(PARAM1);
2199
    *p = helper_fdiv(*p, ST0);
2200
}
2201

    
2202
void OPPROTO op_fdivr_STN_ST0(void)
2203
{
2204
    CPU86_LDouble *p;
2205
    p = &ST(PARAM1);
2206
    *p = helper_fdiv(ST0, *p);
2207
}
2208

    
2209
/* misc FPU operations */
2210
void OPPROTO op_fchs_ST0(void)
2211
{
2212
    ST0 = floatx_chs(ST0);
2213
}
2214

    
2215
void OPPROTO op_fabs_ST0(void)
2216
{
2217
    ST0 = floatx_abs(ST0);
2218
}
2219

    
2220
void OPPROTO op_fxam_ST0(void)
2221
{
2222
    helper_fxam_ST0();
2223
}
2224

    
2225
void OPPROTO op_fld1_ST0(void)
2226
{
2227
    ST0 = f15rk[1];
2228
}
2229

    
2230
void OPPROTO op_fldl2t_ST0(void)
2231
{
2232
    ST0 = f15rk[6];
2233
}
2234

    
2235
void OPPROTO op_fldl2e_ST0(void)
2236
{
2237
    ST0 = f15rk[5];
2238
}
2239

    
2240
void OPPROTO op_fldpi_ST0(void)
2241
{
2242
    ST0 = f15rk[2];
2243
}
2244

    
2245
void OPPROTO op_fldlg2_ST0(void)
2246
{
2247
    ST0 = f15rk[3];
2248
}
2249

    
2250
void OPPROTO op_fldln2_ST0(void)
2251
{
2252
    ST0 = f15rk[4];
2253
}
2254

    
2255
void OPPROTO op_fldz_ST0(void)
2256
{
2257
    ST0 = f15rk[0];
2258
}
2259

    
2260
void OPPROTO op_fldz_FT0(void)
2261
{
2262
    FT0 = f15rk[0];
2263
}
2264

    
2265
/* associated heplers to reduce generated code length and to simplify
2266
   relocation (FP constants are usually stored in .rodata section) */
2267

    
2268
void OPPROTO op_f2xm1(void)
2269
{
2270
    helper_f2xm1();
2271
}
2272

    
2273
void OPPROTO op_fyl2x(void)
2274
{
2275
    helper_fyl2x();
2276
}
2277

    
2278
void OPPROTO op_fptan(void)
2279
{
2280
    helper_fptan();
2281
}
2282

    
2283
void OPPROTO op_fpatan(void)
2284
{
2285
    helper_fpatan();
2286
}
2287

    
2288
void OPPROTO op_fxtract(void)
2289
{
2290
    helper_fxtract();
2291
}
2292

    
2293
void OPPROTO op_fprem1(void)
2294
{
2295
    helper_fprem1();
2296
}
2297

    
2298

    
2299
void OPPROTO op_fprem(void)
2300
{
2301
    helper_fprem();
2302
}
2303

    
2304
void OPPROTO op_fyl2xp1(void)
2305
{
2306
    helper_fyl2xp1();
2307
}
2308

    
2309
void OPPROTO op_fsqrt(void)
2310
{
2311
    helper_fsqrt();
2312
}
2313

    
2314
void OPPROTO op_fsincos(void)
2315
{
2316
    helper_fsincos();
2317
}
2318

    
2319
void OPPROTO op_frndint(void)
2320
{
2321
    helper_frndint();
2322
}
2323

    
2324
void OPPROTO op_fscale(void)
2325
{
2326
    helper_fscale();
2327
}
2328

    
2329
void OPPROTO op_fsin(void)
2330
{
2331
    helper_fsin();
2332
}
2333

    
2334
void OPPROTO op_fcos(void)
2335
{
2336
    helper_fcos();
2337
}
2338

    
2339
void OPPROTO op_fnstsw_A0(void)
2340
{
2341
    int fpus;
2342
    fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
2343
    stw(A0, fpus);
2344
    FORCE_RET();
2345
}
2346

    
2347
void OPPROTO op_fnstsw_EAX(void)
2348
{
2349
    int fpus;
2350
    fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
2351
    EAX = (EAX & ~0xffff) | fpus;
2352
}
2353

    
2354
void OPPROTO op_fnstcw_A0(void)
2355
{
2356
    stw(A0, env->fpuc);
2357
    FORCE_RET();
2358
}
2359

    
2360
void OPPROTO op_fldcw_A0(void)
2361
{
2362
    env->fpuc = lduw(A0);
2363
    update_fp_status();
2364
}
2365

    
2366
void OPPROTO op_fclex(void)
2367
{
2368
    env->fpus &= 0x7f00;
2369
}
2370

    
2371
void OPPROTO op_fwait(void)
2372
{
2373
    if (env->fpus & FPUS_SE)
2374
        fpu_raise_exception();
2375
    FORCE_RET();
2376
}
2377

    
2378
void OPPROTO op_fninit(void)
2379
{
2380
    env->fpus = 0;
2381
    env->fpstt = 0;
2382
    env->fpuc = 0x37f;
2383
    env->fptags[0] = 1;
2384
    env->fptags[1] = 1;
2385
    env->fptags[2] = 1;
2386
    env->fptags[3] = 1;
2387
    env->fptags[4] = 1;
2388
    env->fptags[5] = 1;
2389
    env->fptags[6] = 1;
2390
    env->fptags[7] = 1;
2391
}
2392

    
2393
void OPPROTO op_fnstenv_A0(void)
2394
{
2395
    helper_fstenv(A0, PARAM1);
2396
}
2397

    
2398
void OPPROTO op_fldenv_A0(void)
2399
{
2400
    helper_fldenv(A0, PARAM1);
2401
}
2402

    
2403
void OPPROTO op_fnsave_A0(void)
2404
{
2405
    helper_fsave(A0, PARAM1);
2406
}
2407

    
2408
void OPPROTO op_frstor_A0(void)
2409
{
2410
    helper_frstor(A0, PARAM1);
2411
}
2412

    
2413
/* threading support */
2414
void OPPROTO op_lock(void)
2415
{
2416
    cpu_lock();
2417
}
2418

    
2419
void OPPROTO op_unlock(void)
2420
{
2421
    cpu_unlock();
2422
}
2423

    
2424
/* SSE support */
2425
static inline void memcpy16(void *d, void *s)
2426
{
2427
    ((uint32_t *)d)[0] = ((uint32_t *)s)[0];
2428
    ((uint32_t *)d)[1] = ((uint32_t *)s)[1];
2429
    ((uint32_t *)d)[2] = ((uint32_t *)s)[2];
2430
    ((uint32_t *)d)[3] = ((uint32_t *)s)[3];
2431
}
2432

    
2433
void OPPROTO op_movo(void)
2434
{
2435
    /* XXX: badly generated code */
2436
    XMMReg *d, *s;
2437
    d = (XMMReg *)((char *)env + PARAM1);
2438
    s = (XMMReg *)((char *)env + PARAM2);
2439
    memcpy16(d, s);
2440
}
2441

    
2442
void OPPROTO op_movq(void)
2443
{
2444
    uint64_t *d, *s;
2445
    d = (uint64_t *)((char *)env + PARAM1);
2446
    s = (uint64_t *)((char *)env + PARAM2);
2447
    *d = *s;
2448
}
2449

    
2450
void OPPROTO op_movl(void)
2451
{
2452
    uint32_t *d, *s;
2453
    d = (uint32_t *)((char *)env + PARAM1);
2454
    s = (uint32_t *)((char *)env + PARAM2);
2455
    *d = *s;
2456
}
2457

    
2458
void OPPROTO op_movq_env_0(void)
2459
{
2460
    uint64_t *d;
2461
    d = (uint64_t *)((char *)env + PARAM1);
2462
    *d = 0;
2463
}
2464

    
2465
void OPPROTO op_fxsave_A0(void)
2466
{
2467
    helper_fxsave(A0, PARAM1);
2468
}
2469

    
2470
void OPPROTO op_fxrstor_A0(void)
2471
{
2472
    helper_fxrstor(A0, PARAM1);
2473
}
2474

    
2475
/* XXX: optimize by storing fptt and fptags in the static cpu state */
2476
void OPPROTO op_enter_mmx(void)
2477
{
2478
    env->fpstt = 0;
2479
    *(uint32_t *)(env->fptags) = 0;
2480
    *(uint32_t *)(env->fptags + 4) = 0;
2481
}
2482

    
2483
void OPPROTO op_emms(void)
2484
{
2485
    /* set to empty state */
2486
    *(uint32_t *)(env->fptags) = 0x01010101;
2487
    *(uint32_t *)(env->fptags + 4) = 0x01010101;
2488
}
2489

    
2490
#define SHIFT 0
2491
#include "ops_sse.h"
2492

    
2493
#define SHIFT 1
2494
#include "ops_sse.h"
2495

    
2496
/* Secure Virtual Machine ops */
2497

    
2498
void OPPROTO op_vmrun(void)
2499
{
2500
    helper_vmrun(EAX);
2501
}
2502

    
2503
void OPPROTO op_vmmcall(void)
2504
{
2505
    helper_vmmcall();
2506
}
2507

    
2508
void OPPROTO op_vmload(void)
2509
{
2510
    helper_vmload(EAX);
2511
}
2512

    
2513
void OPPROTO op_vmsave(void)
2514
{
2515
    helper_vmsave(EAX);
2516
}
2517

    
2518
void OPPROTO op_stgi(void)
2519
{
2520
    helper_stgi();
2521
}
2522

    
2523
void OPPROTO op_clgi(void)
2524
{
2525
    helper_clgi();
2526
}
2527

    
2528
void OPPROTO op_skinit(void)
2529
{
2530
    helper_skinit();
2531
}
2532

    
2533
void OPPROTO op_invlpga(void)
2534
{
2535
    helper_invlpga();
2536
}