Statistics
| Branch: | Revision:

root / target-i386 / op.c @ 5fafdf24

History | View | Annotate | Download (42.2 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
#ifdef TARGET_X86_64
517

    
518
#define PARAMQ1 \
519
({\
520
    UREG64 __p;\
521
    __p.l.v1 = PARAM1;\
522
    __p.l.v0 = PARAM2;\
523
    __p.q;\
524
})
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
#if !defined(CONFIG_USER_ONLY)
1252
void OPPROTO op_movtl_T0_cr8(void)
1253
{
1254
    T0 = cpu_get_apic_tpr(env);
1255
}
1256
#endif
1257

    
1258
/* DR registers access */
1259
void OPPROTO op_movl_drN_T0(void)
1260
{
1261
    helper_movl_drN_T0(PARAM1);
1262
}
1263

    
1264
void OPPROTO op_lmsw_T0(void)
1265
{
1266
    /* only 4 lower bits of CR0 are modified. PE cannot be set to zero
1267
       if already set to one. */
1268
    T0 = (env->cr[0] & ~0xe) | (T0 & 0xf);
1269
    helper_movl_crN_T0(0);
1270
}
1271

    
1272
void OPPROTO op_invlpg_A0(void)
1273
{
1274
    helper_invlpg(A0);
1275
}
1276

    
1277
void OPPROTO op_movl_T0_env(void)
1278
{
1279
    T0 = *(uint32_t *)((char *)env + PARAM1);
1280
}
1281

    
1282
void OPPROTO op_movl_env_T0(void)
1283
{
1284
    *(uint32_t *)((char *)env + PARAM1) = T0;
1285
}
1286

    
1287
void OPPROTO op_movl_env_T1(void)
1288
{
1289
    *(uint32_t *)((char *)env + PARAM1) = T1;
1290
}
1291

    
1292
void OPPROTO op_movtl_T0_env(void)
1293
{
1294
    T0 = *(target_ulong *)((char *)env + PARAM1);
1295
}
1296

    
1297
void OPPROTO op_movtl_env_T0(void)
1298
{
1299
    *(target_ulong *)((char *)env + PARAM1) = T0;
1300
}
1301

    
1302
void OPPROTO op_movtl_T1_env(void)
1303
{
1304
    T1 = *(target_ulong *)((char *)env + PARAM1);
1305
}
1306

    
1307
void OPPROTO op_movtl_env_T1(void)
1308
{
1309
    *(target_ulong *)((char *)env + PARAM1) = T1;
1310
}
1311

    
1312
void OPPROTO op_clts(void)
1313
{
1314
    env->cr[0] &= ~CR0_TS_MASK;
1315
    env->hflags &= ~HF_TS_MASK;
1316
}
1317

    
1318
/* flags handling */
1319

    
1320
void OPPROTO op_goto_tb0(void)
1321
{
1322
    GOTO_TB(op_goto_tb0, PARAM1, 0);
1323
}
1324

    
1325
void OPPROTO op_goto_tb1(void)
1326
{
1327
    GOTO_TB(op_goto_tb1, PARAM1, 1);
1328
}
1329

    
1330
void OPPROTO op_jmp_label(void)
1331
{
1332
    GOTO_LABEL_PARAM(1);
1333
}
1334

    
1335
void OPPROTO op_jnz_T0_label(void)
1336
{
1337
    if (T0)
1338
        GOTO_LABEL_PARAM(1);
1339
    FORCE_RET();
1340
}
1341

    
1342
void OPPROTO op_jz_T0_label(void)
1343
{
1344
    if (!T0)
1345
        GOTO_LABEL_PARAM(1);
1346
    FORCE_RET();
1347
}
1348

    
1349
/* slow set cases (compute x86 flags) */
1350
void OPPROTO op_seto_T0_cc(void)
1351
{
1352
    int eflags;
1353
    eflags = cc_table[CC_OP].compute_all();
1354
    T0 = (eflags >> 11) & 1;
1355
}
1356

    
1357
void OPPROTO op_setb_T0_cc(void)
1358
{
1359
    T0 = cc_table[CC_OP].compute_c();
1360
}
1361

    
1362
void OPPROTO op_setz_T0_cc(void)
1363
{
1364
    int eflags;
1365
    eflags = cc_table[CC_OP].compute_all();
1366
    T0 = (eflags >> 6) & 1;
1367
}
1368

    
1369
void OPPROTO op_setbe_T0_cc(void)
1370
{
1371
    int eflags;
1372
    eflags = cc_table[CC_OP].compute_all();
1373
    T0 = (eflags & (CC_Z | CC_C)) != 0;
1374
}
1375

    
1376
void OPPROTO op_sets_T0_cc(void)
1377
{
1378
    int eflags;
1379
    eflags = cc_table[CC_OP].compute_all();
1380
    T0 = (eflags >> 7) & 1;
1381
}
1382

    
1383
void OPPROTO op_setp_T0_cc(void)
1384
{
1385
    int eflags;
1386
    eflags = cc_table[CC_OP].compute_all();
1387
    T0 = (eflags >> 2) & 1;
1388
}
1389

    
1390
void OPPROTO op_setl_T0_cc(void)
1391
{
1392
    int eflags;
1393
    eflags = cc_table[CC_OP].compute_all();
1394
    T0 = ((eflags ^ (eflags >> 4)) >> 7) & 1;
1395
}
1396

    
1397
void OPPROTO op_setle_T0_cc(void)
1398
{
1399
    int eflags;
1400
    eflags = cc_table[CC_OP].compute_all();
1401
    T0 = (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) != 0;
1402
}
1403

    
1404
void OPPROTO op_xor_T0_1(void)
1405
{
1406
    T0 ^= 1;
1407
}
1408

    
1409
void OPPROTO op_set_cc_op(void)
1410
{
1411
    CC_OP = PARAM1;
1412
}
1413

    
1414
void OPPROTO op_mov_T0_cc(void)
1415
{
1416
    T0 = cc_table[CC_OP].compute_all();
1417
}
1418

    
1419
/* XXX: clear VIF/VIP in all ops ? */
1420

    
1421
void OPPROTO op_movl_eflags_T0(void)
1422
{
1423
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK));
1424
}
1425

    
1426
void OPPROTO op_movw_eflags_T0(void)
1427
{
1428
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK) & 0xffff);
1429
}
1430

    
1431
void OPPROTO op_movl_eflags_T0_io(void)
1432
{
1433
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK));
1434
}
1435

    
1436
void OPPROTO op_movw_eflags_T0_io(void)
1437
{
1438
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK) & 0xffff);
1439
}
1440

    
1441
void OPPROTO op_movl_eflags_T0_cpl0(void)
1442
{
1443
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK));
1444
}
1445

    
1446
void OPPROTO op_movw_eflags_T0_cpl0(void)
1447
{
1448
    load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK) & 0xffff);
1449
}
1450

    
1451
#if 0
1452
/* vm86plus version */
1453
void OPPROTO op_movw_eflags_T0_vm(void)
1454
{
1455
    int eflags;
1456
    eflags = T0;
1457
    CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
1458
    DF = 1 - (2 * ((eflags >> 10) & 1));
1459
    /* we also update some system flags as in user mode */
1460
    env->eflags = (env->eflags & ~(FL_UPDATE_MASK16 | VIF_MASK)) |
1461
        (eflags & FL_UPDATE_MASK16);
1462
    if (eflags & IF_MASK) {
1463
        env->eflags |= VIF_MASK;
1464
        if (env->eflags & VIP_MASK) {
1465
            EIP = PARAM1;
1466
            raise_exception(EXCP0D_GPF);
1467
        }
1468
    }
1469
    FORCE_RET();
1470
}
1471

1472
void OPPROTO op_movl_eflags_T0_vm(void)
1473
{
1474
    int eflags;
1475
    eflags = T0;
1476
    CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
1477
    DF = 1 - (2 * ((eflags >> 10) & 1));
1478
    /* we also update some system flags as in user mode */
1479
    env->eflags = (env->eflags & ~(FL_UPDATE_MASK32 | VIF_MASK)) |
1480
        (eflags & FL_UPDATE_MASK32);
1481
    if (eflags & IF_MASK) {
1482
        env->eflags |= VIF_MASK;
1483
        if (env->eflags & VIP_MASK) {
1484
            EIP = PARAM1;
1485
            raise_exception(EXCP0D_GPF);
1486
        }
1487
    }
1488
    FORCE_RET();
1489
}
1490
#endif
1491

    
1492
/* XXX: compute only O flag */
1493
void OPPROTO op_movb_eflags_T0(void)
1494
{
1495
    int of;
1496
    of = cc_table[CC_OP].compute_all() & CC_O;
1497
    CC_SRC = (T0 & (CC_S | CC_Z | CC_A | CC_P | CC_C)) | of;
1498
}
1499

    
1500
void OPPROTO op_movl_T0_eflags(void)
1501
{
1502
    int eflags;
1503
    eflags = cc_table[CC_OP].compute_all();
1504
    eflags |= (DF & DF_MASK);
1505
    eflags |= env->eflags & ~(VM_MASK | RF_MASK);
1506
    T0 = eflags;
1507
}
1508

    
1509
/* vm86plus version */
1510
#if 0
1511
void OPPROTO op_movl_T0_eflags_vm(void)
1512
{
1513
    int eflags;
1514
    eflags = cc_table[CC_OP].compute_all();
1515
    eflags |= (DF & DF_MASK);
1516
    eflags |= env->eflags & ~(VM_MASK | RF_MASK | IF_MASK);
1517
    if (env->eflags & VIF_MASK)
1518
        eflags |= IF_MASK;
1519
    T0 = eflags;
1520
}
1521
#endif
1522

    
1523
void OPPROTO op_cld(void)
1524
{
1525
    DF = 1;
1526
}
1527

    
1528
void OPPROTO op_std(void)
1529
{
1530
    DF = -1;
1531
}
1532

    
1533
void OPPROTO op_clc(void)
1534
{
1535
    int eflags;
1536
    eflags = cc_table[CC_OP].compute_all();
1537
    eflags &= ~CC_C;
1538
    CC_SRC = eflags;
1539
}
1540

    
1541
void OPPROTO op_stc(void)
1542
{
1543
    int eflags;
1544
    eflags = cc_table[CC_OP].compute_all();
1545
    eflags |= CC_C;
1546
    CC_SRC = eflags;
1547
}
1548

    
1549
void OPPROTO op_cmc(void)
1550
{
1551
    int eflags;
1552
    eflags = cc_table[CC_OP].compute_all();
1553
    eflags ^= CC_C;
1554
    CC_SRC = eflags;
1555
}
1556

    
1557
void OPPROTO op_salc(void)
1558
{
1559
    int cf;
1560
    cf = cc_table[CC_OP].compute_c();
1561
    EAX = (EAX & ~0xff) | ((-cf) & 0xff);
1562
}
1563

    
1564
static int compute_all_eflags(void)
1565
{
1566
    return CC_SRC;
1567
}
1568

    
1569
static int compute_c_eflags(void)
1570
{
1571
    return CC_SRC & CC_C;
1572
}
1573

    
1574
CCTable cc_table[CC_OP_NB] = {
1575
    [CC_OP_DYNAMIC] = { /* should never happen */ },
1576

    
1577
    [CC_OP_EFLAGS] = { compute_all_eflags, compute_c_eflags },
1578

    
1579
    [CC_OP_MULB] = { compute_all_mulb, compute_c_mull },
1580
    [CC_OP_MULW] = { compute_all_mulw, compute_c_mull },
1581
    [CC_OP_MULL] = { compute_all_mull, compute_c_mull },
1582

    
1583
    [CC_OP_ADDB] = { compute_all_addb, compute_c_addb },
1584
    [CC_OP_ADDW] = { compute_all_addw, compute_c_addw  },
1585
    [CC_OP_ADDL] = { compute_all_addl, compute_c_addl  },
1586

    
1587
    [CC_OP_ADCB] = { compute_all_adcb, compute_c_adcb },
1588
    [CC_OP_ADCW] = { compute_all_adcw, compute_c_adcw  },
1589
    [CC_OP_ADCL] = { compute_all_adcl, compute_c_adcl  },
1590

    
1591
    [CC_OP_SUBB] = { compute_all_subb, compute_c_subb  },
1592
    [CC_OP_SUBW] = { compute_all_subw, compute_c_subw  },
1593
    [CC_OP_SUBL] = { compute_all_subl, compute_c_subl  },
1594
   
1595
    [CC_OP_SBBB] = { compute_all_sbbb, compute_c_sbbb  },
1596
    [CC_OP_SBBW] = { compute_all_sbbw, compute_c_sbbw  },
1597
    [CC_OP_SBBL] = { compute_all_sbbl, compute_c_sbbl  },
1598
   
1599
    [CC_OP_LOGICB] = { compute_all_logicb, compute_c_logicb },
1600
    [CC_OP_LOGICW] = { compute_all_logicw, compute_c_logicw },
1601
    [CC_OP_LOGICL] = { compute_all_logicl, compute_c_logicl },
1602
   
1603
    [CC_OP_INCB] = { compute_all_incb, compute_c_incl },
1604
    [CC_OP_INCW] = { compute_all_incw, compute_c_incl },
1605
    [CC_OP_INCL] = { compute_all_incl, compute_c_incl },
1606
   
1607
    [CC_OP_DECB] = { compute_all_decb, compute_c_incl },
1608
    [CC_OP_DECW] = { compute_all_decw, compute_c_incl },
1609
    [CC_OP_DECL] = { compute_all_decl, compute_c_incl },
1610
   
1611
    [CC_OP_SHLB] = { compute_all_shlb, compute_c_shlb },
1612
    [CC_OP_SHLW] = { compute_all_shlw, compute_c_shlw },
1613
    [CC_OP_SHLL] = { compute_all_shll, compute_c_shll },
1614

    
1615
    [CC_OP_SARB] = { compute_all_sarb, compute_c_sarl },
1616
    [CC_OP_SARW] = { compute_all_sarw, compute_c_sarl },
1617
    [CC_OP_SARL] = { compute_all_sarl, compute_c_sarl },
1618

    
1619
#ifdef TARGET_X86_64
1620
    [CC_OP_MULQ] = { compute_all_mulq, compute_c_mull },
1621

    
1622
    [CC_OP_ADDQ] = { compute_all_addq, compute_c_addq  },
1623

    
1624
    [CC_OP_ADCQ] = { compute_all_adcq, compute_c_adcq  },
1625

    
1626
    [CC_OP_SUBQ] = { compute_all_subq, compute_c_subq  },
1627
   
1628
    [CC_OP_SBBQ] = { compute_all_sbbq, compute_c_sbbq  },
1629
   
1630
    [CC_OP_LOGICQ] = { compute_all_logicq, compute_c_logicq },
1631
   
1632
    [CC_OP_INCQ] = { compute_all_incq, compute_c_incl },
1633

    
1634
    [CC_OP_DECQ] = { compute_all_decq, compute_c_incl },
1635

    
1636
    [CC_OP_SHLQ] = { compute_all_shlq, compute_c_shlq },
1637

    
1638
    [CC_OP_SARQ] = { compute_all_sarq, compute_c_sarl },
1639
#endif
1640
};
1641

    
1642
/* floating point support. Some of the code for complicated x87
1643
   functions comes from the LGPL'ed x86 emulator found in the Willows
1644
   TWIN windows emulator. */
1645

    
1646
/* fp load FT0 */
1647

    
1648
void OPPROTO op_flds_FT0_A0(void)
1649
{
1650
#ifdef USE_FP_CONVERT
1651
    FP_CONVERT.i32 = ldl(A0);
1652
    FT0 = FP_CONVERT.f;
1653
#else
1654
    FT0 = ldfl(A0);
1655
#endif
1656
}
1657

    
1658
void OPPROTO op_fldl_FT0_A0(void)
1659
{
1660
#ifdef USE_FP_CONVERT
1661
    FP_CONVERT.i64 = ldq(A0);
1662
    FT0 = FP_CONVERT.d;
1663
#else
1664
    FT0 = ldfq(A0);
1665
#endif
1666
}
1667

    
1668
/* helpers are needed to avoid static constant reference. XXX: find a better way */
1669
#ifdef USE_INT_TO_FLOAT_HELPERS
1670

    
1671
void helper_fild_FT0_A0(void)
1672
{
1673
    FT0 = (CPU86_LDouble)ldsw(A0);
1674
}
1675

    
1676
void helper_fildl_FT0_A0(void)
1677
{
1678
    FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
1679
}
1680

    
1681
void helper_fildll_FT0_A0(void)
1682
{
1683
    FT0 = (CPU86_LDouble)((int64_t)ldq(A0));
1684
}
1685

    
1686
void OPPROTO op_fild_FT0_A0(void)
1687
{
1688
    helper_fild_FT0_A0();
1689
}
1690

    
1691
void OPPROTO op_fildl_FT0_A0(void)
1692
{
1693
    helper_fildl_FT0_A0();
1694
}
1695

    
1696
void OPPROTO op_fildll_FT0_A0(void)
1697
{
1698
    helper_fildll_FT0_A0();
1699
}
1700

    
1701
#else
1702

    
1703
void OPPROTO op_fild_FT0_A0(void)
1704
{
1705
#ifdef USE_FP_CONVERT
1706
    FP_CONVERT.i32 = ldsw(A0);
1707
    FT0 = (CPU86_LDouble)FP_CONVERT.i32;
1708
#else
1709
    FT0 = (CPU86_LDouble)ldsw(A0);
1710
#endif
1711
}
1712

    
1713
void OPPROTO op_fildl_FT0_A0(void)
1714
{
1715
#ifdef USE_FP_CONVERT
1716
    FP_CONVERT.i32 = (int32_t) ldl(A0);
1717
    FT0 = (CPU86_LDouble)FP_CONVERT.i32;
1718
#else
1719
    FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
1720
#endif
1721
}
1722

    
1723
void OPPROTO op_fildll_FT0_A0(void)
1724
{
1725
#ifdef USE_FP_CONVERT
1726
    FP_CONVERT.i64 = (int64_t) ldq(A0);
1727
    FT0 = (CPU86_LDouble)FP_CONVERT.i64;
1728
#else
1729
    FT0 = (CPU86_LDouble)((int64_t)ldq(A0));
1730
#endif
1731
}
1732
#endif
1733

    
1734
/* fp load ST0 */
1735

    
1736
void OPPROTO op_flds_ST0_A0(void)
1737
{
1738
    int new_fpstt;
1739
    new_fpstt = (env->fpstt - 1) & 7;
1740
#ifdef USE_FP_CONVERT
1741
    FP_CONVERT.i32 = ldl(A0);
1742
    env->fpregs[new_fpstt].d = FP_CONVERT.f;
1743
#else
1744
    env->fpregs[new_fpstt].d = ldfl(A0);
1745
#endif
1746
    env->fpstt = new_fpstt;
1747
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1748
}
1749

    
1750
void OPPROTO op_fldl_ST0_A0(void)
1751
{
1752
    int new_fpstt;
1753
    new_fpstt = (env->fpstt - 1) & 7;
1754
#ifdef USE_FP_CONVERT
1755
    FP_CONVERT.i64 = ldq(A0);
1756
    env->fpregs[new_fpstt].d = FP_CONVERT.d;
1757
#else
1758
    env->fpregs[new_fpstt].d = ldfq(A0);
1759
#endif
1760
    env->fpstt = new_fpstt;
1761
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1762
}
1763

    
1764
void OPPROTO op_fldt_ST0_A0(void)
1765
{
1766
    helper_fldt_ST0_A0();
1767
}
1768

    
1769
/* helpers are needed to avoid static constant reference. XXX: find a better way */
1770
#ifdef USE_INT_TO_FLOAT_HELPERS
1771

    
1772
void helper_fild_ST0_A0(void)
1773
{
1774
    int new_fpstt;
1775
    new_fpstt = (env->fpstt - 1) & 7;
1776
    env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0);
1777
    env->fpstt = new_fpstt;
1778
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1779
}
1780

    
1781
void helper_fildl_ST0_A0(void)
1782
{
1783
    int new_fpstt;
1784
    new_fpstt = (env->fpstt - 1) & 7;
1785
    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
1786
    env->fpstt = new_fpstt;
1787
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1788
}
1789

    
1790
void helper_fildll_ST0_A0(void)
1791
{
1792
    int new_fpstt;
1793
    new_fpstt = (env->fpstt - 1) & 7;
1794
    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0));
1795
    env->fpstt = new_fpstt;
1796
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1797
}
1798

    
1799
void OPPROTO op_fild_ST0_A0(void)
1800
{
1801
    helper_fild_ST0_A0();
1802
}
1803

    
1804
void OPPROTO op_fildl_ST0_A0(void)
1805
{
1806
    helper_fildl_ST0_A0();
1807
}
1808

    
1809
void OPPROTO op_fildll_ST0_A0(void)
1810
{
1811
    helper_fildll_ST0_A0();
1812
}
1813

    
1814
#else
1815

    
1816
void OPPROTO op_fild_ST0_A0(void)
1817
{
1818
    int new_fpstt;
1819
    new_fpstt = (env->fpstt - 1) & 7;
1820
#ifdef USE_FP_CONVERT
1821
    FP_CONVERT.i32 = ldsw(A0);
1822
    env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
1823
#else
1824
    env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0);
1825
#endif
1826
    env->fpstt = new_fpstt;
1827
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1828
}
1829

    
1830
void OPPROTO op_fildl_ST0_A0(void)
1831
{
1832
    int new_fpstt;
1833
    new_fpstt = (env->fpstt - 1) & 7;
1834
#ifdef USE_FP_CONVERT
1835
    FP_CONVERT.i32 = (int32_t) ldl(A0);
1836
    env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
1837
#else
1838
    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
1839
#endif
1840
    env->fpstt = new_fpstt;
1841
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1842
}
1843

    
1844
void OPPROTO op_fildll_ST0_A0(void)
1845
{
1846
    int new_fpstt;
1847
    new_fpstt = (env->fpstt - 1) & 7;
1848
#ifdef USE_FP_CONVERT
1849
    FP_CONVERT.i64 = (int64_t) ldq(A0);
1850
    env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i64;
1851
#else
1852
    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0));
1853
#endif
1854
    env->fpstt = new_fpstt;
1855
    env->fptags[new_fpstt] = 0; /* validate stack entry */
1856
}
1857

    
1858
#endif
1859

    
1860
/* fp store */
1861

    
1862
void OPPROTO op_fsts_ST0_A0(void)
1863
{
1864
#ifdef USE_FP_CONVERT
1865
    FP_CONVERT.f = (float)ST0;
1866
    stfl(A0, FP_CONVERT.f);
1867
#else
1868
    stfl(A0, (float)ST0);
1869
#endif
1870
    FORCE_RET();
1871
}
1872

    
1873
void OPPROTO op_fstl_ST0_A0(void)
1874
{
1875
    stfq(A0, (double)ST0);
1876
    FORCE_RET();
1877
}
1878

    
1879
void OPPROTO op_fstt_ST0_A0(void)
1880
{
1881
    helper_fstt_ST0_A0();
1882
}
1883

    
1884
void OPPROTO op_fist_ST0_A0(void)
1885
{
1886
#if defined(__sparc__) && !defined(__sparc_v9__)
1887
    register CPU86_LDouble d asm("o0");
1888
#else
1889
    CPU86_LDouble d;
1890
#endif
1891
    int val;
1892

    
1893
    d = ST0;
1894
    val = floatx_to_int32(d, &env->fp_status);
1895
    if (val != (int16_t)val)
1896
        val = -32768;
1897
    stw(A0, val);
1898
    FORCE_RET();
1899
}
1900

    
1901
void OPPROTO op_fistl_ST0_A0(void)
1902
{
1903
#if defined(__sparc__) && !defined(__sparc_v9__)
1904
    register CPU86_LDouble d asm("o0");
1905
#else
1906
    CPU86_LDouble d;
1907
#endif
1908
    int val;
1909

    
1910
    d = ST0;
1911
    val = floatx_to_int32(d, &env->fp_status);
1912
    stl(A0, val);
1913
    FORCE_RET();
1914
}
1915

    
1916
void OPPROTO op_fistll_ST0_A0(void)
1917
{
1918
#if defined(__sparc__) && !defined(__sparc_v9__)
1919
    register CPU86_LDouble d asm("o0");
1920
#else
1921
    CPU86_LDouble d;
1922
#endif
1923
    int64_t val;
1924

    
1925
    d = ST0;
1926
    val = floatx_to_int64(d, &env->fp_status);
1927
    stq(A0, val);
1928
    FORCE_RET();
1929
}
1930

    
1931
void OPPROTO op_fistt_ST0_A0(void)
1932
{
1933
#if defined(__sparc__) && !defined(__sparc_v9__)
1934
    register CPU86_LDouble d asm("o0");
1935
#else
1936
    CPU86_LDouble d;
1937
#endif
1938
    int val;
1939

    
1940
    d = ST0;
1941
    val = floatx_to_int32_round_to_zero(d, &env->fp_status);
1942
    if (val != (int16_t)val)
1943
        val = -32768;
1944
    stw(A0, val);
1945
    FORCE_RET();
1946
}
1947

    
1948
void OPPROTO op_fisttl_ST0_A0(void)
1949
{
1950
#if defined(__sparc__) && !defined(__sparc_v9__)
1951
    register CPU86_LDouble d asm("o0");
1952
#else
1953
    CPU86_LDouble d;
1954
#endif
1955
    int val;
1956

    
1957
    d = ST0;
1958
    val = floatx_to_int32_round_to_zero(d, &env->fp_status);
1959
    stl(A0, val);
1960
    FORCE_RET();
1961
}
1962

    
1963
void OPPROTO op_fisttll_ST0_A0(void)
1964
{
1965
#if defined(__sparc__) && !defined(__sparc_v9__)
1966
    register CPU86_LDouble d asm("o0");
1967
#else
1968
    CPU86_LDouble d;
1969
#endif
1970
    int64_t val;
1971

    
1972
    d = ST0;
1973
    val = floatx_to_int64_round_to_zero(d, &env->fp_status);
1974
    stq(A0, val);
1975
    FORCE_RET();
1976
}
1977

    
1978
void OPPROTO op_fbld_ST0_A0(void)
1979
{
1980
    helper_fbld_ST0_A0();
1981
}
1982

    
1983
void OPPROTO op_fbst_ST0_A0(void)
1984
{
1985
    helper_fbst_ST0_A0();
1986
}
1987

    
1988
/* FPU move */
1989

    
1990
void OPPROTO op_fpush(void)
1991
{
1992
    fpush();
1993
}
1994

    
1995
void OPPROTO op_fpop(void)
1996
{
1997
    fpop();
1998
}
1999

    
2000
void OPPROTO op_fdecstp(void)
2001
{
2002
    env->fpstt = (env->fpstt - 1) & 7;
2003
    env->fpus &= (~0x4700);
2004
}
2005

    
2006
void OPPROTO op_fincstp(void)
2007
{
2008
    env->fpstt = (env->fpstt + 1) & 7;
2009
    env->fpus &= (~0x4700);
2010
}
2011

    
2012
void OPPROTO op_ffree_STN(void)
2013
{
2014
    env->fptags[(env->fpstt + PARAM1) & 7] = 1;
2015
}
2016

    
2017
void OPPROTO op_fmov_ST0_FT0(void)
2018
{
2019
    ST0 = FT0;
2020
}
2021

    
2022
void OPPROTO op_fmov_FT0_STN(void)
2023
{
2024
    FT0 = ST(PARAM1);
2025
}
2026

    
2027
void OPPROTO op_fmov_ST0_STN(void)
2028
{
2029
    ST0 = ST(PARAM1);
2030
}
2031

    
2032
void OPPROTO op_fmov_STN_ST0(void)
2033
{
2034
    ST(PARAM1) = ST0;
2035
}
2036

    
2037
void OPPROTO op_fxchg_ST0_STN(void)
2038
{
2039
    CPU86_LDouble tmp;
2040
    tmp = ST(PARAM1);
2041
    ST(PARAM1) = ST0;
2042
    ST0 = tmp;
2043
}
2044

    
2045
/* FPU operations */
2046

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

    
2049
void OPPROTO op_fcom_ST0_FT0(void)
2050
{
2051
    int ret;
2052

    
2053
    ret = floatx_compare(ST0, FT0, &env->fp_status);
2054
    env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret + 1];
2055
    FORCE_RET();
2056
}
2057

    
2058
void OPPROTO op_fucom_ST0_FT0(void)
2059
{
2060
    int ret;
2061

    
2062
    ret = floatx_compare_quiet(ST0, FT0, &env->fp_status);
2063
    env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret+ 1];
2064
    FORCE_RET();
2065
}
2066

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

    
2069
void OPPROTO op_fcomi_ST0_FT0(void)
2070
{
2071
    int eflags;
2072
    int ret;
2073

    
2074
    ret = floatx_compare(ST0, FT0, &env->fp_status);
2075
    eflags = cc_table[CC_OP].compute_all();
2076
    eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
2077
    CC_SRC = eflags;
2078
    FORCE_RET();
2079
}
2080

    
2081
void OPPROTO op_fucomi_ST0_FT0(void)
2082
{
2083
    int eflags;
2084
    int ret;
2085

    
2086
    ret = floatx_compare_quiet(ST0, FT0, &env->fp_status);
2087
    eflags = cc_table[CC_OP].compute_all();
2088
    eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
2089
    CC_SRC = eflags;
2090
    FORCE_RET();
2091
}
2092

    
2093
void OPPROTO op_fcmov_ST0_STN_T0(void)
2094
{
2095
    if (T0) {
2096
        ST0 = ST(PARAM1);
2097
    }
2098
    FORCE_RET();
2099
}
2100

    
2101
void OPPROTO op_fadd_ST0_FT0(void)
2102
{
2103
    ST0 += FT0;
2104
}
2105

    
2106
void OPPROTO op_fmul_ST0_FT0(void)
2107
{
2108
    ST0 *= FT0;
2109
}
2110

    
2111
void OPPROTO op_fsub_ST0_FT0(void)
2112
{
2113
    ST0 -= FT0;
2114
}
2115

    
2116
void OPPROTO op_fsubr_ST0_FT0(void)
2117
{
2118
    ST0 = FT0 - ST0;
2119
}
2120

    
2121
void OPPROTO op_fdiv_ST0_FT0(void)
2122
{
2123
    ST0 = helper_fdiv(ST0, FT0);
2124
}
2125

    
2126
void OPPROTO op_fdivr_ST0_FT0(void)
2127
{
2128
    ST0 = helper_fdiv(FT0, ST0);
2129
}
2130

    
2131
/* fp operations between STN and ST0 */
2132

    
2133
void OPPROTO op_fadd_STN_ST0(void)
2134
{
2135
    ST(PARAM1) += ST0;
2136
}
2137

    
2138
void OPPROTO op_fmul_STN_ST0(void)
2139
{
2140
    ST(PARAM1) *= ST0;
2141
}
2142

    
2143
void OPPROTO op_fsub_STN_ST0(void)
2144
{
2145
    ST(PARAM1) -= ST0;
2146
}
2147

    
2148
void OPPROTO op_fsubr_STN_ST0(void)
2149
{
2150
    CPU86_LDouble *p;
2151
    p = &ST(PARAM1);
2152
    *p = ST0 - *p;
2153
}
2154

    
2155
void OPPROTO op_fdiv_STN_ST0(void)
2156
{
2157
    CPU86_LDouble *p;
2158
    p = &ST(PARAM1);
2159
    *p = helper_fdiv(*p, ST0);
2160
}
2161

    
2162
void OPPROTO op_fdivr_STN_ST0(void)
2163
{
2164
    CPU86_LDouble *p;
2165
    p = &ST(PARAM1);
2166
    *p = helper_fdiv(ST0, *p);
2167
}
2168

    
2169
/* misc FPU operations */
2170
void OPPROTO op_fchs_ST0(void)
2171
{
2172
    ST0 = floatx_chs(ST0);
2173
}
2174

    
2175
void OPPROTO op_fabs_ST0(void)
2176
{
2177
    ST0 = floatx_abs(ST0);
2178
}
2179

    
2180
void OPPROTO op_fxam_ST0(void)
2181
{
2182
    helper_fxam_ST0();
2183
}
2184

    
2185
void OPPROTO op_fld1_ST0(void)
2186
{
2187
    ST0 = f15rk[1];
2188
}
2189

    
2190
void OPPROTO op_fldl2t_ST0(void)
2191
{
2192
    ST0 = f15rk[6];
2193
}
2194

    
2195
void OPPROTO op_fldl2e_ST0(void)
2196
{
2197
    ST0 = f15rk[5];
2198
}
2199

    
2200
void OPPROTO op_fldpi_ST0(void)
2201
{
2202
    ST0 = f15rk[2];
2203
}
2204

    
2205
void OPPROTO op_fldlg2_ST0(void)
2206
{
2207
    ST0 = f15rk[3];
2208
}
2209

    
2210
void OPPROTO op_fldln2_ST0(void)
2211
{
2212
    ST0 = f15rk[4];
2213
}
2214

    
2215
void OPPROTO op_fldz_ST0(void)
2216
{
2217
    ST0 = f15rk[0];
2218
}
2219

    
2220
void OPPROTO op_fldz_FT0(void)
2221
{
2222
    FT0 = f15rk[0];
2223
}
2224

    
2225
/* associated heplers to reduce generated code length and to simplify
2226
   relocation (FP constants are usually stored in .rodata section) */
2227

    
2228
void OPPROTO op_f2xm1(void)
2229
{
2230
    helper_f2xm1();
2231
}
2232

    
2233
void OPPROTO op_fyl2x(void)
2234
{
2235
    helper_fyl2x();
2236
}
2237

    
2238
void OPPROTO op_fptan(void)
2239
{
2240
    helper_fptan();
2241
}
2242

    
2243
void OPPROTO op_fpatan(void)
2244
{
2245
    helper_fpatan();
2246
}
2247

    
2248
void OPPROTO op_fxtract(void)
2249
{
2250
    helper_fxtract();
2251
}
2252

    
2253
void OPPROTO op_fprem1(void)
2254
{
2255
    helper_fprem1();
2256
}
2257

    
2258

    
2259
void OPPROTO op_fprem(void)
2260
{
2261
    helper_fprem();
2262
}
2263

    
2264
void OPPROTO op_fyl2xp1(void)
2265
{
2266
    helper_fyl2xp1();
2267
}
2268

    
2269
void OPPROTO op_fsqrt(void)
2270
{
2271
    helper_fsqrt();
2272
}
2273

    
2274
void OPPROTO op_fsincos(void)
2275
{
2276
    helper_fsincos();
2277
}
2278

    
2279
void OPPROTO op_frndint(void)
2280
{
2281
    helper_frndint();
2282
}
2283

    
2284
void OPPROTO op_fscale(void)
2285
{
2286
    helper_fscale();
2287
}
2288

    
2289
void OPPROTO op_fsin(void)
2290
{
2291
    helper_fsin();
2292
}
2293

    
2294
void OPPROTO op_fcos(void)
2295
{
2296
    helper_fcos();
2297
}
2298

    
2299
void OPPROTO op_fnstsw_A0(void)
2300
{
2301
    int fpus;
2302
    fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
2303
    stw(A0, fpus);
2304
    FORCE_RET();
2305
}
2306

    
2307
void OPPROTO op_fnstsw_EAX(void)
2308
{
2309
    int fpus;
2310
    fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
2311
    EAX = (EAX & ~0xffff) | fpus;
2312
}
2313

    
2314
void OPPROTO op_fnstcw_A0(void)
2315
{
2316
    stw(A0, env->fpuc);
2317
    FORCE_RET();
2318
}
2319

    
2320
void OPPROTO op_fldcw_A0(void)
2321
{
2322
    env->fpuc = lduw(A0);
2323
    update_fp_status();
2324
}
2325

    
2326
void OPPROTO op_fclex(void)
2327
{
2328
    env->fpus &= 0x7f00;
2329
}
2330

    
2331
void OPPROTO op_fwait(void)
2332
{
2333
    if (env->fpus & FPUS_SE)
2334
        fpu_raise_exception();
2335
    FORCE_RET();
2336
}
2337

    
2338
void OPPROTO op_fninit(void)
2339
{
2340
    env->fpus = 0;
2341
    env->fpstt = 0;
2342
    env->fpuc = 0x37f;
2343
    env->fptags[0] = 1;
2344
    env->fptags[1] = 1;
2345
    env->fptags[2] = 1;
2346
    env->fptags[3] = 1;
2347
    env->fptags[4] = 1;
2348
    env->fptags[5] = 1;
2349
    env->fptags[6] = 1;
2350
    env->fptags[7] = 1;
2351
}
2352

    
2353
void OPPROTO op_fnstenv_A0(void)
2354
{
2355
    helper_fstenv(A0, PARAM1);
2356
}
2357

    
2358
void OPPROTO op_fldenv_A0(void)
2359
{
2360
    helper_fldenv(A0, PARAM1);
2361
}
2362

    
2363
void OPPROTO op_fnsave_A0(void)
2364
{
2365
    helper_fsave(A0, PARAM1);
2366
}
2367

    
2368
void OPPROTO op_frstor_A0(void)
2369
{
2370
    helper_frstor(A0, PARAM1);
2371
}
2372

    
2373
/* threading support */
2374
void OPPROTO op_lock(void)
2375
{
2376
    cpu_lock();
2377
}
2378

    
2379
void OPPROTO op_unlock(void)
2380
{
2381
    cpu_unlock();
2382
}
2383

    
2384
/* SSE support */
2385
static inline void memcpy16(void *d, void *s)
2386
{
2387
    ((uint32_t *)d)[0] = ((uint32_t *)s)[0];
2388
    ((uint32_t *)d)[1] = ((uint32_t *)s)[1];
2389
    ((uint32_t *)d)[2] = ((uint32_t *)s)[2];
2390
    ((uint32_t *)d)[3] = ((uint32_t *)s)[3];
2391
}
2392

    
2393
void OPPROTO op_movo(void)
2394
{
2395
    /* XXX: badly generated code */
2396
    XMMReg *d, *s;
2397
    d = (XMMReg *)((char *)env + PARAM1);
2398
    s = (XMMReg *)((char *)env + PARAM2);
2399
    memcpy16(d, s);
2400
}
2401

    
2402
void OPPROTO op_movq(void)
2403
{
2404
    uint64_t *d, *s;
2405
    d = (uint64_t *)((char *)env + PARAM1);
2406
    s = (uint64_t *)((char *)env + PARAM2);
2407
    *d = *s;
2408
}
2409

    
2410
void OPPROTO op_movl(void)
2411
{
2412
    uint32_t *d, *s;
2413
    d = (uint32_t *)((char *)env + PARAM1);
2414
    s = (uint32_t *)((char *)env + PARAM2);
2415
    *d = *s;
2416
}
2417

    
2418
void OPPROTO op_movq_env_0(void)
2419
{
2420
    uint64_t *d;
2421
    d = (uint64_t *)((char *)env + PARAM1);
2422
    *d = 0;
2423
}
2424

    
2425
void OPPROTO op_fxsave_A0(void)
2426
{
2427
    helper_fxsave(A0, PARAM1);
2428
}
2429

    
2430
void OPPROTO op_fxrstor_A0(void)
2431
{
2432
    helper_fxrstor(A0, PARAM1);
2433
}
2434

    
2435
/* XXX: optimize by storing fptt and fptags in the static cpu state */
2436
void OPPROTO op_enter_mmx(void)
2437
{
2438
    env->fpstt = 0;
2439
    *(uint32_t *)(env->fptags) = 0;
2440
    *(uint32_t *)(env->fptags + 4) = 0;
2441
}
2442

    
2443
void OPPROTO op_emms(void)
2444
{
2445
    /* set to empty state */
2446
    *(uint32_t *)(env->fptags) = 0x01010101;
2447
    *(uint32_t *)(env->fptags + 4) = 0x01010101;
2448
}
2449

    
2450
#define SHIFT 0
2451
#include "ops_sse.h"
2452

    
2453
#define SHIFT 1
2454
#include "ops_sse.h"