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

21 22
//#define DEBUG_OP

B
bellard 已提交
23 24
#include "config.h"
#include "exec.h"
25
#include "host-utils.h"
26
#include "helper_regs.h"
27
#include "op_helper.h"
B
bellard 已提交
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#define REG 0
#include "op_template.h"

#define REG 1
#include "op_template.h"

#define REG 2
#include "op_template.h"

#define REG 3
#include "op_template.h"

#define REG 4
#include "op_template.h"

#define REG 5
#include "op_template.h"

#define REG 6
#include "op_template.h"

#define REG 7
#include "op_template.h"

#define REG 8
#include "op_template.h"

#define REG 9
#include "op_template.h"

#define REG 10
#include "op_template.h"

#define REG 11
#include "op_template.h"

#define REG 12
#include "op_template.h"

#define REG 13
#include "op_template.h"

#define REG 14
#include "op_template.h"

#define REG 15
#include "op_template.h"

#define REG 16
#include "op_template.h"

#define REG 17
#include "op_template.h"

#define REG 18
#include "op_template.h"

#define REG 19
#include "op_template.h"

#define REG 20
#include "op_template.h"

#define REG 21
#include "op_template.h"

#define REG 22
#include "op_template.h"

#define REG 23
#include "op_template.h"

#define REG 24
#include "op_template.h"

#define REG 25
#include "op_template.h"

#define REG 26
#include "op_template.h"

#define REG 27
#include "op_template.h"

#define REG 28
#include "op_template.h"

#define REG 29
#include "op_template.h"

#define REG 30
#include "op_template.h"

#define REG 31
#include "op_template.h"

A
aurel32 已提交
125 126 127 128 129 130
void OPPROTO op_print_mem_EA (void)
{
    do_print_mem_EA(T0);
    RETURN();
}

131
/* PowerPC state maintenance operations */
B
bellard 已提交
132
/* set_Rc0 */
133
void OPPROTO op_set_Rc0 (void)
B
bellard 已提交
134
{
J
j_mayer 已提交
135
    env->crf[0] = T0 | xer_so;
B
bellard 已提交
136 137 138
    RETURN();
}

A
aurel32 已提交
139
/* Constants load */
140 141 142 143 144 145
void OPPROTO op_moven_T2_T0 (void)
{
    T2 = ~T0;
    RETURN();
}

146
/* Generate exceptions */
147
void OPPROTO op_raise_exception_err (void)
148
{
149
    do_raise_exception_err(PARAM1, PARAM2);
150 151
}

A
aurel32 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165
void OPPROTO op_update_nip (void)
{
    env->nip = (uint32_t)PARAM1;
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_update_nip_64 (void)
{
    env->nip = ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
    RETURN();
}
#endif

166
void OPPROTO op_debug (void)
167 168 169 170
{
    do_raise_exception(EXCP_DEBUG);
}

A
aurel32 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
/* Load/store special registers */
void OPPROTO op_load_cr (void)
{
    do_load_cr();
    RETURN();
}

void OPPROTO op_store_cr (void)
{
    do_store_cr(PARAM1);
    RETURN();
}

void OPPROTO op_load_cro (void)
{
    T0 = env->crf[PARAM1];
    RETURN();
}

void OPPROTO op_store_cro (void)
{
    env->crf[PARAM1] = T0;
    RETURN();
}

196
void OPPROTO op_load_xer_cr (void)
B
bellard 已提交
197 198 199 200 201
{
    T0 = (xer_so << 3) | (xer_ov << 2) | (xer_ca << 1);
    RETURN();
}

202
void OPPROTO op_clear_xer_ov (void)
B
bellard 已提交
203 204 205
{
    xer_so = 0;
    xer_ov = 0;
J
j_mayer 已提交
206 207 208
    RETURN();
}

209
void OPPROTO op_clear_xer_ca (void)
J
j_mayer 已提交
210
{
B
bellard 已提交
211 212 213 214
    xer_ca = 0;
    RETURN();
}

215
void OPPROTO op_load_xer_bc (void)
B
bellard 已提交
216
{
217
    T1 = xer_bc;
B
bellard 已提交
218 219 220
    RETURN();
}

221 222 223 224 225 226
void OPPROTO op_store_xer_bc (void)
{
    xer_bc = T0;
    RETURN();
}

227
void OPPROTO op_load_xer (void)
B
bellard 已提交
228
{
229
    T0 = hreg_load_xer(env);
B
bellard 已提交
230 231 232
    RETURN();
}

233
void OPPROTO op_store_xer (void)
B
bellard 已提交
234
{
235
    hreg_store_xer(env, T0);
236 237 238
    RETURN();
}

239 240 241 242 243 244 245 246
#if defined(TARGET_PPC64)
void OPPROTO op_store_pri (void)
{
    do_store_pri(PARAM1);
    RETURN();
}
#endif

247 248
#if !defined(CONFIG_USER_ONLY)
/* Segment registers load and store */
249
void OPPROTO op_load_sr (void)
250
{
251
    T0 = env->sr[T1];
252 253 254
    RETURN();
}

255
void OPPROTO op_store_sr (void)
256 257 258 259 260
{
    do_store_sr(env, T1, T0);
    RETURN();
}

261 262 263 264 265 266 267 268 269 270 271 272 273 274
#if defined(TARGET_PPC64)
void OPPROTO op_load_slb (void)
{
    T0 = ppc_load_slb(env, T1);
    RETURN();
}

void OPPROTO op_store_slb (void)
{
    ppc_store_slb(env, T1, T0);
    RETURN();
}
#endif /* defined(TARGET_PPC64) */

275
void OPPROTO op_load_sdr1 (void)
276
{
277
    T0 = env->sdr1;
278 279 280
    RETURN();
}

281
void OPPROTO op_store_sdr1 (void)
282 283
{
    do_store_sdr1(env, T0);
B
bellard 已提交
284 285 286
    RETURN();
}

287 288 289 290 291 292 293 294 295 296 297 298 299 300
#if defined (TARGET_PPC64)
void OPPROTO op_load_asr (void)
{
    T0 = env->asr;
    RETURN();
}

void OPPROTO op_store_asr (void)
{
    ppc_store_asr(env, T0);
    RETURN();
}
#endif

A
aurel32 已提交
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
void OPPROTO op_load_msr (void)
{
    T0 = env->msr;
    RETURN();
}

void OPPROTO op_store_msr (void)
{
    do_store_msr();
    RETURN();
}

#if defined (TARGET_PPC64)
void OPPROTO op_store_msr_32 (void)
{
    T0 = (env->msr & ~0xFFFFFFFFULL) | (T0 & 0xFFFFFFFF);
    do_store_msr();
    RETURN();
}
#endif

322
void OPPROTO op_update_riee (void)
323
{
324 325 326 327 328 329
    /* We don't call do_store_msr here as we won't trigger
     * any special case nor change hflags
     */
    T0 &= (1 << MSR_RI) | (1 << MSR_EE);
    env->msr &= ~(1 << MSR_RI) | (1 << MSR_EE);
    env->msr |= T0;
330 331 332
    RETURN();
}
#endif
333 334

/* SPR */
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
void OPPROTO op_load_spr (void)
{
    T0 = env->spr[PARAM1];
    RETURN();
}

void OPPROTO op_store_spr (void)
{
    env->spr[PARAM1] = T0;
    RETURN();
}

void OPPROTO op_load_dump_spr (void)
{
    T0 = ppc_load_dump_spr(PARAM1);
    RETURN();
}

void OPPROTO op_store_dump_spr (void)
354
{
355
    ppc_store_dump_spr(PARAM1, T0);
356 357 358
    RETURN();
}

359
void OPPROTO op_mask_spr (void)
360
{
361
    env->spr[PARAM1] &= ~T0;
B
bellard 已提交
362 363 364
    RETURN();
}

365
void OPPROTO op_load_lr (void)
B
bellard 已提交
366
{
367
    T0 = env->lr;
368 369 370
    RETURN();
}

371
void OPPROTO op_store_lr (void)
372
{
373
    env->lr = T0;
374 375 376
    RETURN();
}

377
void OPPROTO op_load_ctr (void)
378
{
379
    T0 = env->ctr;
380 381 382
    RETURN();
}

383
void OPPROTO op_store_ctr (void)
384
{
385
    env->ctr = T0;
386 387 388
    RETURN();
}

389
void OPPROTO op_load_tbl (void)
390
{
391
    T0 = cpu_ppc_load_tbl(env);
392 393 394
    RETURN();
}

395
void OPPROTO op_load_tbu (void)
396
{
397
    T0 = cpu_ppc_load_tbu(env);
398 399 400
    RETURN();
}

401 402 403 404 405 406 407 408 409 410 411 412
void OPPROTO op_load_atbl (void)
{
    T0 = cpu_ppc_load_atbl(env);
    RETURN();
}

void OPPROTO op_load_atbu (void)
{
    T0 = cpu_ppc_load_atbu(env);
    RETURN();
}

413
#if !defined(CONFIG_USER_ONLY)
414
void OPPROTO op_store_tbl (void)
415
{
416
    cpu_ppc_store_tbl(env, T0);
B
bellard 已提交
417 418 419
    RETURN();
}

420
void OPPROTO op_store_tbu (void)
421
{
422
    cpu_ppc_store_tbu(env, T0);
423 424 425
    RETURN();
}

426 427 428 429 430 431 432 433 434 435 436 437
void OPPROTO op_store_atbl (void)
{
    cpu_ppc_store_atbl(env, T0);
    RETURN();
}

void OPPROTO op_store_atbu (void)
{
    cpu_ppc_store_atbu(env, T0);
    RETURN();
}

438
void OPPROTO op_load_decr (void)
439
{
440
    T0 = cpu_ppc_load_decr(env);
441 442
    RETURN();
}
443

444
void OPPROTO op_store_decr (void)
445
{
446
    cpu_ppc_store_decr(env, T0);
447 448 449
    RETURN();
}

450
void OPPROTO op_load_ibat (void)
451
{
452
    T0 = env->IBAT[PARAM1][PARAM2];
453
    RETURN();
454 455
}

456
void OPPROTO op_store_ibatu (void)
457
{
458 459 460 461
    do_store_ibatu(env, PARAM1, T0);
    RETURN();
}

462
void OPPROTO op_store_ibatl (void)
463 464 465 466 467 468 469
{
#if 1
    env->IBAT[1][PARAM1] = T0;
#else
    do_store_ibatl(env, PARAM1, T0);
#endif
    RETURN();
470 471
}

472
void OPPROTO op_load_dbat (void)
473
{
474
    T0 = env->DBAT[PARAM1][PARAM2];
475
    RETURN();
476 477
}

478
void OPPROTO op_store_dbatu (void)
479 480 481 482 483
{
    do_store_dbatu(env, PARAM1, T0);
    RETURN();
}

484
void OPPROTO op_store_dbatl (void)
485
{
486 487 488 489 490 491
#if 1
    env->DBAT[1][PARAM1] = T0;
#else
    do_store_dbatl(env, PARAM1, T0);
#endif
    RETURN();
492
}
493
#endif /* !defined(CONFIG_USER_ONLY) */
494

B
bellard 已提交
495
/* FPSCR */
496 497
#ifdef CONFIG_SOFTFLOAT
void OPPROTO op_reset_fpstatus (void)
B
bellard 已提交
498
{
499
    env->fp_status.float_exception_flags = 0;
B
bellard 已提交
500 501
    RETURN();
}
502
#endif
B
bellard 已提交
503

504
void OPPROTO op_compute_fprf (void)
B
bellard 已提交
505
{
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
    do_compute_fprf(PARAM1);
    RETURN();
}

#ifdef CONFIG_SOFTFLOAT
void OPPROTO op_float_check_status (void)
{
    do_float_check_status();
    RETURN();
}
#else
void OPPROTO op_float_check_status (void)
{
    if (env->exception_index == POWERPC_EXCP_PROGRAM &&
        (env->error_code & POWERPC_EXCP_FP)) {
        /* Differred floating-point exception after target FPR update */
        if (msr_fe0 != 0 || msr_fe1 != 0)
            do_raise_exception_err(env->exception_index, env->error_code);
    }
B
bellard 已提交
525 526
    RETURN();
}
527 528 529 530 531 532 533
#endif

void OPPROTO op_load_fpscr_FT0 (void)
{
    /* The 32 MSB of the target fpr are undefined.
     * They'll be zero...
     */
A
aurel32 已提交
534 535 536 537
    CPU_DoubleU u;

    u.l.upper = 0;
    u.l.lower = env->fpscr;
538 539 540 541 542 543
    FT0 = u.d;
    RETURN();
}

void OPPROTO op_set_FT0 (void)
{
A
aurel32 已提交
544
    CPU_DoubleU u;
545

A
aurel32 已提交
546 547
    u.l.upper = 0;
    u.l.lower = PARAM1;
548 549 550
    FT0 = u.d;
    RETURN();
}
B
bellard 已提交
551

552
void OPPROTO op_load_fpscr_T0 (void)
B
bellard 已提交
553
{
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
    T0 = (env->fpscr >> PARAM1) & 0xF;
    RETURN();
}

void OPPROTO op_load_fpcc (void)
{
    T0 = fpscr_fpcc;
    RETURN();
}

void OPPROTO op_fpscr_resetbit (void)
{
    env->fpscr &= PARAM1;
    RETURN();
}

void OPPROTO op_fpscr_setbit (void)
{
    do_fpscr_setbit(PARAM1);
    RETURN();
}

void OPPROTO op_store_fpscr (void)
{
    do_store_fpscr(PARAM1);
B
bellard 已提交
579 580 581
    RETURN();
}

B
bellard 已提交
582
/* Branch */
583
#define EIP env->nip
584

585
void OPPROTO op_setlr (void)
586
{
587
    env->lr = (uint32_t)PARAM1;
588
    RETURN();
589 590
}

591 592 593
#if defined (TARGET_PPC64)
void OPPROTO op_setlr_64 (void)
{
594
    env->lr = ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
595 596 597 598 599
    RETURN();
}
#endif

void OPPROTO op_b_T1 (void)
600
{
601
    env->nip = (uint32_t)(T1 & ~3);
602
    RETURN();
603 604
}

605 606 607
#if defined (TARGET_PPC64)
void OPPROTO op_b_T1_64 (void)
{
608
    env->nip = (uint64_t)(T1 & ~3);
609 610 611 612
    RETURN();
}
#endif

613
void OPPROTO op_jz_T0 (void)
614
{
B
bellard 已提交
615 616
    if (!T0)
        GOTO_LABEL_PARAM(1);
617 618 619
    RETURN();
}

620
void OPPROTO op_btest_T1 (void)
621 622
{
    if (T0) {
623
        env->nip = (uint32_t)(T1 & ~3);
624
    } else {
625
        env->nip = (uint32_t)PARAM1;
626 627 628 629
    }
    RETURN();
}

630 631 632 633
#if defined (TARGET_PPC64)
void OPPROTO op_btest_T1_64 (void)
{
    if (T0) {
634
        env->nip = (uint64_t)(T1 & ~3);
635
    } else {
636
        env->nip = ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
637 638 639 640 641
    }
    RETURN();
}
#endif

642
void OPPROTO op_movl_T1_ctr (void)
643
{
644
    T1 = env->ctr;
645
    RETURN();
646 647
}

648
void OPPROTO op_movl_T1_lr (void)
649
{
650
    T1 = env->lr;
651
    RETURN();
652 653 654
}

/* tests with result in T0 */
655 656
void OPPROTO op_test_ctr (void)
{
657
    T0 = (uint32_t)env->ctr;
658 659
    RETURN();
}
660

661 662
#if defined(TARGET_PPC64)
void OPPROTO op_test_ctr_64 (void)
663
{
664
    T0 = (uint64_t)env->ctr;
665 666 667 668 669 670
    RETURN();
}
#endif

void OPPROTO op_test_ctr_true (void)
{
671
    T0 = ((uint32_t)env->ctr != 0 && (T0 & PARAM1) != 0);
672
    RETURN();
673 674
}

675 676
#if defined(TARGET_PPC64)
void OPPROTO op_test_ctr_true_64 (void)
677
{
678
    T0 = ((uint64_t)env->ctr != 0 && (T0 & PARAM1) != 0);
679
    RETURN();
680
}
681
#endif
682

683
void OPPROTO op_test_ctr_false (void)
684
{
685
    T0 = ((uint32_t)env->ctr != 0 && (T0 & PARAM1) == 0);
686
    RETURN();
687 688
}

689 690
#if defined(TARGET_PPC64)
void OPPROTO op_test_ctr_false_64 (void)
691
{
692
    T0 = ((uint64_t)env->ctr != 0 && (T0 & PARAM1) == 0);
693
    RETURN();
694
}
695 696 697 698
#endif

void OPPROTO op_test_ctrz (void)
{
699
    T0 = ((uint32_t)env->ctr == 0);
700 701 702 703 704 705
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_test_ctrz_64 (void)
{
706
    T0 = ((uint64_t)env->ctr == 0);
707 708 709 710 711 712
    RETURN();
}
#endif

void OPPROTO op_test_ctrz_true (void)
{
713
    T0 = ((uint32_t)env->ctr == 0 && (T0 & PARAM1) != 0);
714 715 716 717 718 719
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_test_ctrz_true_64 (void)
{
720
    T0 = ((uint64_t)env->ctr == 0 && (T0 & PARAM1) != 0);
721 722 723
    RETURN();
}
#endif
724

725
void OPPROTO op_test_ctrz_false (void)
726
{
727
    T0 = ((uint32_t)env->ctr == 0 && (T0 & PARAM1) == 0);
728
    RETURN();
729 730
}

731 732
#if defined(TARGET_PPC64)
void OPPROTO op_test_ctrz_false_64 (void)
733
{
734
    T0 = ((uint64_t)env->ctr == 0 && (T0 & PARAM1) == 0);
735
    RETURN();
736
}
737
#endif
738

739
void OPPROTO op_test_true (void)
740
{
741
    T0 = (T0 & PARAM1);
742
    RETURN();
743 744
}

745
void OPPROTO op_test_false (void)
746
{
747
    T0 = ((T0 & PARAM1) == 0);
748
    RETURN();
749
}
B
bellard 已提交
750 751

/* CTR maintenance */
752
void OPPROTO op_dec_ctr (void)
B
bellard 已提交
753
{
754
    env->ctr--;
B
bellard 已提交
755 756 757 758 759
    RETURN();
}

/***                           Integer arithmetic                          ***/
/* add */
760
void OPPROTO op_add (void)
B
bellard 已提交
761 762 763 764 765
{
    T0 += T1;
    RETURN();
}

766
void OPPROTO op_check_addo (void)
B
bellard 已提交
767
{
768 769 770
    xer_ov = (((uint32_t)T2 ^ (uint32_t)T1 ^ UINT32_MAX) &
              ((uint32_t)T2 ^ (uint32_t)T0)) >> 31;
    xer_so |= xer_ov;
J
j_mayer 已提交
771
    RETURN();
B
bellard 已提交
772 773
}

774 775
#if defined(TARGET_PPC64)
void OPPROTO op_check_addo_64 (void)
B
bellard 已提交
776
{
777 778 779
    xer_ov = (((uint64_t)T2 ^ (uint64_t)T1 ^ UINT64_MAX) &
              ((uint64_t)T2 ^ (uint64_t)T0)) >> 63;
    xer_so |= xer_ov;
J
j_mayer 已提交
780
    RETURN();
781 782 783 784 785 786 787
}
#endif

/* add carrying */
void OPPROTO op_check_addc (void)
{
    if (likely((uint32_t)T0 >= (uint32_t)T2)) {
B
bellard 已提交
788
        xer_ca = 0;
789 790
    } else {
        xer_ca = 1;
B
bellard 已提交
791 792 793 794
    }
    RETURN();
}

795 796
#if defined(TARGET_PPC64)
void OPPROTO op_check_addc_64 (void)
B
bellard 已提交
797
{
798 799 800 801 802
    if (likely((uint64_t)T0 >= (uint64_t)T2)) {
        xer_ca = 0;
    } else {
        xer_ca = 1;
    }
B
bellard 已提交
803 804
    RETURN();
}
805
#endif
B
bellard 已提交
806 807

/* add extended */
808
void OPPROTO op_adde (void)
B
bellard 已提交
809
{
810
    do_adde();
811
    RETURN();
B
bellard 已提交
812 813
}

814 815
#if defined(TARGET_PPC64)
void OPPROTO op_adde_64 (void)
B
bellard 已提交
816
{
817
    do_adde_64();
B
bellard 已提交
818 819
    RETURN();
}
820
#endif
B
bellard 已提交
821 822

/* add immediate */
823
void OPPROTO op_addi (void)
B
bellard 已提交
824
{
825
    T0 += (int32_t)PARAM1;
B
bellard 已提交
826 827 828
    RETURN();
}

829 830
/* add to minus one extended */
void OPPROTO op_add_me (void)
B
bellard 已提交
831
{
832 833
    T0 += xer_ca + (-1);
    if (likely((uint32_t)T1 != 0))
B
bellard 已提交
834
        xer_ca = 1;
835 836
    else
        xer_ca = 0;
B
bellard 已提交
837 838 839
    RETURN();
}

840 841
#if defined(TARGET_PPC64)
void OPPROTO op_add_me_64 (void)
B
bellard 已提交
842 843
{
    T0 += xer_ca + (-1);
844
    if (likely((uint64_t)T1 != 0))
B
bellard 已提交
845
        xer_ca = 1;
846 847
    else
        xer_ca = 0;
B
bellard 已提交
848 849
    RETURN();
}
850
#endif
B
bellard 已提交
851

852
void OPPROTO op_addmeo (void)
B
bellard 已提交
853
{
854
    do_addmeo();
B
bellard 已提交
855 856 857
    RETURN();
}

858 859 860 861 862 863
void OPPROTO op_addmeo_64 (void)
{
    do_addmeo();
    RETURN();
}

B
bellard 已提交
864
/* add to zero extended */
865
void OPPROTO op_add_ze (void)
B
bellard 已提交
866 867 868 869 870
{
    T0 += xer_ca;
    RETURN();
}

871 872
/* divide word */
void OPPROTO op_divw (void)
B
bellard 已提交
873
{
874
    if (unlikely(((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) ||
875
                 (int32_t)T1 == 0)) {
876
        T0 = (int32_t)(UINT32_MAX * ((uint32_t)T0 >> 31));
877 878 879
    } else {
        T0 = (int32_t)T0 / (int32_t)T1;
    }
B
bellard 已提交
880 881 882
    RETURN();
}

883 884
#if defined(TARGET_PPC64)
void OPPROTO op_divd (void)
B
bellard 已提交
885
{
886
    if (unlikely(((int64_t)T0 == INT64_MIN && (int64_t)T1 == (int64_t)-1LL) ||
887
                 (int64_t)T1 == 0)) {
888
        T0 = (int64_t)(UINT64_MAX * ((uint64_t)T0 >> 63));
B
bellard 已提交
889
    } else {
890
        T0 = (int64_t)T0 / (int64_t)T1;
B
bellard 已提交
891 892 893
    }
    RETURN();
}
894
#endif
B
bellard 已提交
895

896
void OPPROTO op_divwo (void)
B
bellard 已提交
897
{
898
    do_divwo();
B
bellard 已提交
899 900 901
    RETURN();
}

902 903 904 905 906 907 908 909
#if defined(TARGET_PPC64)
void OPPROTO op_divdo (void)
{
    do_divdo();
    RETURN();
}
#endif

B
bellard 已提交
910
/* divide word unsigned */
911 912 913 914 915 916 917 918 919 920 921 922
void OPPROTO op_divwu (void)
{
    if (unlikely(T1 == 0)) {
        T0 = 0;
    } else {
        T0 = (uint32_t)T0 / (uint32_t)T1;
    }
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_divdu (void)
B
bellard 已提交
923
{
924
    if (unlikely(T1 == 0)) {
B
bellard 已提交
925 926 927 928 929 930
        T0 = 0;
    } else {
        T0 /= T1;
    }
    RETURN();
}
931
#endif
B
bellard 已提交
932

933
void OPPROTO op_divwuo (void)
B
bellard 已提交
934
{
935
    do_divwuo();
B
bellard 已提交
936 937 938
    RETURN();
}

939 940 941 942 943 944 945 946
#if defined(TARGET_PPC64)
void OPPROTO op_divduo (void)
{
    do_divduo();
    RETURN();
}
#endif

B
bellard 已提交
947
/* multiply high word */
948
void OPPROTO op_mulhw (void)
B
bellard 已提交
949
{
950
    T0 = ((int64_t)((int32_t)T0) * (int64_t)((int32_t)T1)) >> 32;
B
bellard 已提交
951 952 953
    RETURN();
}

954 955 956 957 958
#if defined(TARGET_PPC64)
void OPPROTO op_mulhd (void)
{
    uint64_t tl, th;

959
    muls64(&tl, &th, T0, T1);
960 961 962 963 964
    T0 = th;
    RETURN();
}
#endif

B
bellard 已提交
965
/* multiply high word unsigned */
966
void OPPROTO op_mulhwu (void)
B
bellard 已提交
967
{
968
    T0 = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1) >> 32;
B
bellard 已提交
969 970 971
    RETURN();
}

972 973 974 975 976
#if defined(TARGET_PPC64)
void OPPROTO op_mulhdu (void)
{
    uint64_t tl, th;

977
    mulu64(&tl, &th, T0, T1);
978 979 980 981 982
    T0 = th;
    RETURN();
}
#endif

B
bellard 已提交
983
/* multiply low immediate */
984
void OPPROTO op_mulli (void)
B
bellard 已提交
985
{
986
    T0 = ((int32_t)T0 * (int32_t)PARAM1);
B
bellard 已提交
987 988 989 990
    RETURN();
}

/* multiply low word */
991
void OPPROTO op_mullw (void)
992 993 994 995 996 997 998
{
    T0 = (int32_t)(T0 * T1);
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_mulld (void)
B
bellard 已提交
999 1000 1001 1002
{
    T0 *= T1;
    RETURN();
}
1003
#endif
B
bellard 已提交
1004

1005
void OPPROTO op_mullwo (void)
B
bellard 已提交
1006
{
1007
    do_mullwo();
B
bellard 已提交
1008 1009 1010
    RETURN();
}

1011 1012 1013 1014 1015 1016 1017 1018
#if defined(TARGET_PPC64)
void OPPROTO op_mulldo (void)
{
    do_mulldo();
    RETURN();
}
#endif

B
bellard 已提交
1019
/* negate */
1020
void OPPROTO op_neg (void)
B
bellard 已提交
1021
{
1022 1023
    if (likely(T0 != INT32_MIN)) {
        T0 = -(int32_t)T0;
B
bellard 已提交
1024 1025 1026 1027
    }
    RETURN();
}

1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
#if defined(TARGET_PPC64)
void OPPROTO op_neg_64 (void)
{
    if (likely(T0 != INT64_MIN)) {
        T0 = -(int64_t)T0;
    }
    RETURN();
}
#endif

1038
void OPPROTO op_nego (void)
B
bellard 已提交
1039
{
1040
    do_nego();
B
bellard 已提交
1041 1042 1043
    RETURN();
}

1044 1045 1046 1047 1048 1049 1050 1051
#if defined(TARGET_PPC64)
void OPPROTO op_nego_64 (void)
{
    do_nego_64();
    RETURN();
}
#endif

T
ths 已提交
1052
/* subtract from */
1053
void OPPROTO op_subf (void)
B
bellard 已提交
1054 1055 1056 1057 1058
{
    T0 = T1 - T0;
    RETURN();
}

T
ths 已提交
1059
/* subtract from carrying */
1060
void OPPROTO op_check_subfc (void)
B
bellard 已提交
1061
{
1062
    if (likely((uint32_t)T0 > (uint32_t)T1)) {
B
bellard 已提交
1063
        xer_ca = 0;
1064 1065
    } else {
        xer_ca = 1;
B
bellard 已提交
1066 1067 1068 1069
    }
    RETURN();
}

1070 1071
#if defined(TARGET_PPC64)
void OPPROTO op_check_subfc_64 (void)
B
bellard 已提交
1072
{
1073 1074 1075 1076 1077
    if (likely((uint64_t)T0 > (uint64_t)T1)) {
        xer_ca = 0;
    } else {
        xer_ca = 1;
    }
B
bellard 已提交
1078 1079
    RETURN();
}
1080
#endif
B
bellard 已提交
1081

T
ths 已提交
1082
/* subtract from extended */
1083
void OPPROTO op_subfe (void)
B
bellard 已提交
1084
{
1085
    do_subfe();
B
bellard 已提交
1086 1087 1088
    RETURN();
}

1089 1090
#if defined(TARGET_PPC64)
void OPPROTO op_subfe_64 (void)
B
bellard 已提交
1091
{
1092
    do_subfe_64();
B
bellard 已提交
1093 1094
    RETURN();
}
1095
#endif
B
bellard 已提交
1096

T
ths 已提交
1097
/* subtract from immediate carrying */
1098
void OPPROTO op_subfic (void)
B
bellard 已提交
1099
{
J
j_mayer 已提交
1100
    T0 = (int32_t)PARAM1 + ~T0 + 1;
1101
    if ((uint32_t)T0 <= (uint32_t)PARAM1) {
B
bellard 已提交
1102 1103 1104 1105 1106 1107 1108
        xer_ca = 1;
    } else {
        xer_ca = 0;
    }
    RETURN();
}

1109 1110 1111
#if defined(TARGET_PPC64)
void OPPROTO op_subfic_64 (void)
{
1112
    T0 = (int64_t)PARAM1 + ~T0 + 1;
1113 1114 1115 1116 1117 1118 1119 1120 1121
    if ((uint64_t)T0 <= (uint64_t)PARAM1) {
        xer_ca = 1;
    } else {
        xer_ca = 0;
    }
    RETURN();
}
#endif

T
ths 已提交
1122
/* subtract from minus one extended */
1123
void OPPROTO op_subfme (void)
B
bellard 已提交
1124 1125
{
    T0 = ~T0 + xer_ca - 1;
1126
    if (likely((uint32_t)T0 != UINT32_MAX))
1127
        xer_ca = 1;
1128 1129
    else
        xer_ca = 0;
1130 1131
    RETURN();
}
B
bellard 已提交
1132

1133 1134 1135 1136
#if defined(TARGET_PPC64)
void OPPROTO op_subfme_64 (void)
{
    T0 = ~T0 + xer_ca - 1;
1137
    if (likely((uint64_t)T0 != UINT64_MAX))
B
bellard 已提交
1138
        xer_ca = 1;
1139 1140
    else
        xer_ca = 0;
B
bellard 已提交
1141 1142
    RETURN();
}
1143
#endif
B
bellard 已提交
1144

1145
void OPPROTO op_subfmeo (void)
B
bellard 已提交
1146
{
1147
    do_subfmeo();
B
bellard 已提交
1148 1149 1150
    RETURN();
}

1151 1152 1153 1154 1155 1156 1157 1158
#if defined(TARGET_PPC64)
void OPPROTO op_subfmeo_64 (void)
{
    do_subfmeo_64();
    RETURN();
}
#endif

T
ths 已提交
1159
/* subtract from zero extended */
1160
void OPPROTO op_subfze (void)
B
bellard 已提交
1161 1162 1163
{
    T1 = ~T0;
    T0 = T1 + xer_ca;
1164
    if ((uint32_t)T0 < (uint32_t)T1) {
B
bellard 已提交
1165 1166 1167 1168 1169 1170 1171
        xer_ca = 1;
    } else {
        xer_ca = 0;
    }
    RETURN();
}

1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
#if defined(TARGET_PPC64)
void OPPROTO op_subfze_64 (void)
{
    T1 = ~T0;
    T0 = T1 + xer_ca;
    if ((uint64_t)T0 < (uint64_t)T1) {
        xer_ca = 1;
    } else {
        xer_ca = 0;
    }
    RETURN();
}
#endif

1186
void OPPROTO op_subfzeo (void)
B
bellard 已提交
1187
{
1188
    do_subfzeo();
B
bellard 已提交
1189 1190 1191
    RETURN();
}

1192 1193 1194 1195 1196 1197 1198 1199
#if defined(TARGET_PPC64)
void OPPROTO op_subfzeo_64 (void)
{
    do_subfzeo_64();
    RETURN();
}
#endif

B
bellard 已提交
1200 1201
/***                           Integer comparison                          ***/
/* compare */
1202 1203 1204 1205 1206 1207 1208 1209 1210
void OPPROTO op_cmp (void)
{
    if ((int32_t)T0 < (int32_t)T1) {
        T0 = 0x08;
    } else if ((int32_t)T0 > (int32_t)T1) {
        T0 = 0x04;
    } else {
        T0 = 0x02;
    }
J
j_mayer 已提交
1211
    T0 |= xer_so;
1212 1213 1214 1215 1216
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_cmp_64 (void)
B
bellard 已提交
1217
{
1218
    if ((int64_t)T0 < (int64_t)T1) {
B
bellard 已提交
1219
        T0 = 0x08;
1220
    } else if ((int64_t)T0 > (int64_t)T1) {
B
bellard 已提交
1221 1222 1223 1224
        T0 = 0x04;
    } else {
        T0 = 0x02;
    }
J
j_mayer 已提交
1225
    T0 |= xer_so;
B
bellard 已提交
1226 1227
    RETURN();
}
1228
#endif
B
bellard 已提交
1229 1230

/* compare immediate */
1231
void OPPROTO op_cmpi (void)
B
bellard 已提交
1232
{
1233
    if ((int32_t)T0 < (int32_t)PARAM1) {
B
bellard 已提交
1234
        T0 = 0x08;
1235
    } else if ((int32_t)T0 > (int32_t)PARAM1) {
B
bellard 已提交
1236 1237 1238 1239
        T0 = 0x04;
    } else {
        T0 = 0x02;
    }
J
j_mayer 已提交
1240
    T0 |= xer_so;
B
bellard 已提交
1241 1242 1243
    RETURN();
}

1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
#if defined(TARGET_PPC64)
void OPPROTO op_cmpi_64 (void)
{
    if ((int64_t)T0 < (int64_t)((int32_t)PARAM1)) {
        T0 = 0x08;
    } else if ((int64_t)T0 > (int64_t)((int32_t)PARAM1)) {
        T0 = 0x04;
    } else {
        T0 = 0x02;
    }
J
j_mayer 已提交
1254
    T0 |= xer_so;
1255 1256 1257 1258
    RETURN();
}
#endif

B
bellard 已提交
1259
/* compare logical */
1260
void OPPROTO op_cmpl (void)
B
bellard 已提交
1261
{
1262
    if ((uint32_t)T0 < (uint32_t)T1) {
B
bellard 已提交
1263
        T0 = 0x08;
1264
    } else if ((uint32_t)T0 > (uint32_t)T1) {
B
bellard 已提交
1265 1266 1267 1268
        T0 = 0x04;
    } else {
        T0 = 0x02;
    }
J
j_mayer 已提交
1269
    T0 |= xer_so;
B
bellard 已提交
1270 1271 1272
    RETURN();
}

1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
#if defined(TARGET_PPC64)
void OPPROTO op_cmpl_64 (void)
{
    if ((uint64_t)T0 < (uint64_t)T1) {
        T0 = 0x08;
    } else if ((uint64_t)T0 > (uint64_t)T1) {
        T0 = 0x04;
    } else {
        T0 = 0x02;
    }
J
j_mayer 已提交
1283
    T0 |= xer_so;
1284 1285 1286 1287
    RETURN();
}
#endif

B
bellard 已提交
1288
/* compare logical immediate */
1289 1290 1291 1292 1293 1294 1295 1296 1297
void OPPROTO op_cmpli (void)
{
    if ((uint32_t)T0 < (uint32_t)PARAM1) {
        T0 = 0x08;
    } else if ((uint32_t)T0 > (uint32_t)PARAM1) {
        T0 = 0x04;
    } else {
        T0 = 0x02;
    }
J
j_mayer 已提交
1298
    T0 |= xer_so;
1299 1300 1301 1302 1303
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_cmpli_64 (void)
B
bellard 已提交
1304
{
1305
    if ((uint64_t)T0 < (uint64_t)PARAM1) {
B
bellard 已提交
1306
        T0 = 0x08;
1307
    } else if ((uint64_t)T0 > (uint64_t)PARAM1) {
B
bellard 已提交
1308 1309 1310 1311
        T0 = 0x04;
    } else {
        T0 = 0x02;
    }
J
j_mayer 已提交
1312
    T0 |= xer_so;
B
bellard 已提交
1313 1314
    RETURN();
}
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
#endif

void OPPROTO op_isel (void)
{
    if (T0)
        T0 = T1;
    else
        T0 = T2;
    RETURN();
}

A
aurel32 已提交
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
void OPPROTO op_popcntb (void)
{
    do_popcntb();
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_popcntb_64 (void)
{
    do_popcntb_64();
    RETURN();
}
#endif

B
bellard 已提交
1340 1341
/***                            Integer logical                            ***/
/* and */
1342
void OPPROTO op_and (void)
B
bellard 已提交
1343 1344 1345 1346 1347 1348
{
    T0 &= T1;
    RETURN();
}

/* andc */
1349
void OPPROTO op_andc (void)
B
bellard 已提交
1350 1351 1352 1353 1354 1355
{
    T0 &= ~T1;
    RETURN();
}

/* andi. */
1356
void OPPROTO op_andi_T0 (void)
B
bellard 已提交
1357
{
1358
    T0 &= (uint32_t)PARAM1;
B
bellard 已提交
1359 1360 1361
    RETURN();
}

1362 1363
void OPPROTO op_andi_T1 (void)
{
1364
    T1 &= (uint32_t)PARAM1;
1365 1366 1367
    RETURN();
}

1368 1369 1370
#if defined(TARGET_PPC64)
void OPPROTO op_andi_T0_64 (void)
{
1371
    T0 &= ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
1372 1373 1374 1375 1376
    RETURN();
}

void OPPROTO op_andi_T1_64 (void)
{
1377
    T1 &= ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
1378 1379 1380 1381
    RETURN();
}
#endif

B
bellard 已提交
1382
/* count leading zero */
1383
void OPPROTO op_cntlzw (void)
B
bellard 已提交
1384
{
1385
    do_cntlzw();
B
bellard 已提交
1386 1387 1388
    RETURN();
}

1389 1390 1391
#if defined(TARGET_PPC64)
void OPPROTO op_cntlzd (void)
{
1392
    do_cntlzd();
1393 1394 1395 1396
    RETURN();
}
#endif

B
bellard 已提交
1397
/* eqv */
1398
void OPPROTO op_eqv (void)
B
bellard 已提交
1399 1400 1401 1402 1403 1404
{
    T0 = ~(T0 ^ T1);
    RETURN();
}

/* extend sign byte */
1405
void OPPROTO op_extsb (void)
B
bellard 已提交
1406
{
1407 1408 1409 1410 1411
#if defined (TARGET_PPC64)
    T0 = (int64_t)((int8_t)T0);
#else
    T0 = (int32_t)((int8_t)T0);
#endif
B
bellard 已提交
1412 1413 1414 1415
    RETURN();
}

/* extend sign half word */
1416
void OPPROTO op_extsh (void)
B
bellard 已提交
1417
{
1418 1419 1420 1421 1422
#if defined (TARGET_PPC64)
    T0 = (int64_t)((int16_t)T0);
#else
    T0 = (int32_t)((int16_t)T0);
#endif
B
bellard 已提交
1423 1424 1425
    RETURN();
}

1426 1427 1428 1429 1430 1431 1432 1433
#if defined (TARGET_PPC64)
void OPPROTO op_extsw (void)
{
    T0 = (int64_t)((int32_t)T0);
    RETURN();
}
#endif

B
bellard 已提交
1434
/* nand */
1435
void OPPROTO op_nand (void)
B
bellard 已提交
1436 1437 1438 1439 1440 1441
{
    T0 = ~(T0 & T1);
    RETURN();
}

/* nor */
1442
void OPPROTO op_nor (void)
B
bellard 已提交
1443 1444 1445 1446 1447 1448
{
    T0 = ~(T0 | T1);
    RETURN();
}

/* or */
1449
void OPPROTO op_or (void)
B
bellard 已提交
1450 1451 1452 1453 1454 1455
{
    T0 |= T1;
    RETURN();
}

/* orc */
1456
void OPPROTO op_orc (void)
B
bellard 已提交
1457 1458 1459 1460 1461 1462
{
    T0 |= ~T1;
    RETURN();
}

/* ori */
1463
void OPPROTO op_ori (void)
B
bellard 已提交
1464
{
1465
    T0 |= (uint32_t)PARAM1;
B
bellard 已提交
1466 1467 1468 1469
    RETURN();
}

/* xor */
1470
void OPPROTO op_xor (void)
B
bellard 已提交
1471 1472 1473 1474 1475 1476
{
    T0 ^= T1;
    RETURN();
}

/* xori */
1477
void OPPROTO op_xori (void)
B
bellard 已提交
1478
{
1479
    T0 ^= (uint32_t)PARAM1;
B
bellard 已提交
1480 1481 1482 1483
    RETURN();
}

/***                             Integer rotate                            ***/
1484
void OPPROTO op_rotl32_T0_T1 (void)
B
bellard 已提交
1485
{
1486
    T0 = rotl32(T0, T1 & 0x1F);
B
bellard 已提交
1487 1488 1489
    RETURN();
}

1490
void OPPROTO op_rotli32_T0 (void)
B
bellard 已提交
1491
{
1492
    T0 = rotl32(T0, PARAM1);
B
bellard 已提交
1493 1494 1495
    RETURN();
}

J
j_mayer 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
#if defined(TARGET_PPC64)
void OPPROTO op_rotl64_T0_T1 (void)
{
    T0 = rotl64(T0, T1 & 0x3F);
    RETURN();
}

void OPPROTO op_rotli64_T0 (void)
{
    T0 = rotl64(T0, PARAM1);
    RETURN();
}
#endif

B
bellard 已提交
1510 1511
/***                             Integer shift                             ***/
/* shift left word */
1512
void OPPROTO op_slw (void)
B
bellard 已提交
1513 1514 1515
{
    if (T1 & 0x20) {
        T0 = 0;
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
    } else {
        T0 = (uint32_t)(T0 << T1);
    }
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_sld (void)
{
    if (T1 & 0x40) {
        T0 = 0;
B
bellard 已提交
1527 1528 1529 1530 1531
    } else {
        T0 = T0 << T1;
    }
    RETURN();
}
1532
#endif
B
bellard 已提交
1533 1534

/* shift right algebraic word */
1535
void OPPROTO op_sraw (void)
B
bellard 已提交
1536
{
1537
    do_sraw();
B
bellard 已提交
1538 1539 1540
    RETURN();
}

1541 1542 1543 1544 1545 1546 1547 1548
#if defined(TARGET_PPC64)
void OPPROTO op_srad (void)
{
    do_srad();
    RETURN();
}
#endif

B
bellard 已提交
1549
/* shift right algebraic word immediate */
1550
void OPPROTO op_srawi (void)
B
bellard 已提交
1551
{
1552 1553 1554 1555
    uint32_t mask = (uint32_t)PARAM2;

    T0 = (int32_t)T0 >> PARAM1;
    if ((int32_t)T1 < 0 && (T1 & mask) != 0) {
B
bellard 已提交
1556 1557 1558 1559 1560 1561 1562
        xer_ca = 1;
    } else {
        xer_ca = 0;
    }
    RETURN();
}

1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
#if defined(TARGET_PPC64)
void OPPROTO op_sradi (void)
{
    uint64_t mask = ((uint64_t)PARAM2 << 32) | (uint64_t)PARAM3;

    T0 = (int64_t)T0 >> PARAM1;
    if ((int64_t)T1 < 0 && ((uint64_t)T1 & mask) != 0) {
        xer_ca = 1;
    } else {
        xer_ca = 0;
    }
    RETURN();
}
#endif

B
bellard 已提交
1578
/* shift right word */
1579
void OPPROTO op_srw (void)
B
bellard 已提交
1580 1581 1582 1583
{
    if (T1 & 0x20) {
        T0 = 0;
    } else {
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595
        T0 = (uint32_t)T0 >> T1;
    }
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_srd (void)
{
    if (T1 & 0x40) {
        T0 = 0;
    } else {
        T0 = (uint64_t)T0 >> T1;
B
bellard 已提交
1596 1597 1598
    }
    RETURN();
}
1599
#endif
B
bellard 已提交
1600

1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612
void OPPROTO op_sl_T0_T1 (void)
{
    T0 = T0 << T1;
    RETURN();
}

void OPPROTO op_sli_T0 (void)
{
    T0 = T0 << PARAM1;
    RETURN();
}

1613 1614 1615 1616 1617 1618
void OPPROTO op_sli_T1 (void)
{
    T1 = T1 << PARAM1;
    RETURN();
}

1619 1620
void OPPROTO op_srl_T0_T1 (void)
{
1621 1622 1623 1624 1625 1626 1627 1628
    T0 = (uint32_t)T0 >> T1;
    RETURN();
}

#if defined(TARGET_PPC64)
void OPPROTO op_srl_T0_T1_64 (void)
{
    T0 = (uint32_t)T0 >> T1;
1629 1630
    RETURN();
}
1631
#endif
1632 1633 1634

void OPPROTO op_srli_T0 (void)
{
1635
    T0 = (uint32_t)T0 >> PARAM1;
1636 1637 1638
    RETURN();
}

1639 1640 1641 1642 1643 1644 1645 1646
#if defined(TARGET_PPC64)
void OPPROTO op_srli_T0_64 (void)
{
    T0 = (uint64_t)T0 >> PARAM1;
    RETURN();
}
#endif

1647 1648
void OPPROTO op_srli_T1 (void)
{
1649
    T1 = (uint32_t)T1 >> PARAM1;
1650 1651 1652
    RETURN();
}

1653 1654 1655 1656 1657 1658 1659 1660
#if defined(TARGET_PPC64)
void OPPROTO op_srli_T1_64 (void)
{
    T1 = (uint64_t)T1 >> PARAM1;
    RETURN();
}
#endif

B
bellard 已提交
1661
/***                       Floating-Point arithmetic                       ***/
1662
/* fadd - fadd. */
1663
void OPPROTO op_fadd (void)
B
bellard 已提交
1664
{
1665
#if USE_PRECISE_EMULATION
1666 1667
    do_fadd();
#else
1668
    FT0 = float64_add(FT0, FT1, &env->fp_status);
1669
#endif
B
bellard 已提交
1670 1671 1672
    RETURN();
}

1673
/* fsub - fsub. */
1674
void OPPROTO op_fsub (void)
B
bellard 已提交
1675
{
1676
#if USE_PRECISE_EMULATION
1677 1678
    do_fsub();
#else
1679
    FT0 = float64_sub(FT0, FT1, &env->fp_status);
1680
#endif
B
bellard 已提交
1681 1682 1683
    RETURN();
}

1684
/* fmul - fmul. */
1685
void OPPROTO op_fmul (void)
B
bellard 已提交
1686
{
1687
#if USE_PRECISE_EMULATION
1688 1689
    do_fmul();
#else
1690
    FT0 = float64_mul(FT0, FT1, &env->fp_status);
1691
#endif
B
bellard 已提交
1692 1693 1694
    RETURN();
}

1695
/* fdiv - fdiv. */
1696
void OPPROTO op_fdiv (void)
B
bellard 已提交
1697
{
1698
#if USE_PRECISE_EMULATION
1699 1700
    do_fdiv();
#else
1701
    FT0 = float64_div(FT0, FT1, &env->fp_status);
1702
#endif
B
bellard 已提交
1703 1704
    RETURN();
}
1705

1706
/* fsqrt - fsqrt. */
1707
void OPPROTO op_fsqrt (void)
1708
{
1709 1710
    do_fsqrt();
    RETURN();
1711 1712
}

1713 1714 1715 1716 1717 1718 1719
/* fre - fre. */
void OPPROTO op_fre (void)
{
    do_fre();
    RETURN();
}

1720
/* fres - fres. */
1721
void OPPROTO op_fres (void)
1722
{
1723 1724
    do_fres();
    RETURN();
1725 1726
}

1727
/* frsqrte  - frsqrte. */
1728
void OPPROTO op_frsqrte (void)
1729
{
1730
    do_frsqrte();
1731
    RETURN();
1732 1733
}

1734
/* fsel - fsel. */
1735
void OPPROTO op_fsel (void)
1736
{
1737 1738
    do_fsel();
    RETURN();
1739 1740
}

1741 1742
/***                     Floating-Point multiply-and-add                   ***/
/* fmadd - fmadd. */
1743
void OPPROTO op_fmadd (void)
1744
{
1745
#if USE_PRECISE_EMULATION
J
j_mayer 已提交
1746 1747
    do_fmadd();
#else
1748 1749
    FT0 = float64_mul(FT0, FT1, &env->fp_status);
    FT0 = float64_add(FT0, FT2, &env->fp_status);
J
j_mayer 已提交
1750
#endif
1751
    RETURN();
1752 1753
}

1754
/* fmsub - fmsub. */
1755
void OPPROTO op_fmsub (void)
1756
{
1757
#if USE_PRECISE_EMULATION
J
j_mayer 已提交
1758 1759
    do_fmsub();
#else
1760 1761
    FT0 = float64_mul(FT0, FT1, &env->fp_status);
    FT0 = float64_sub(FT0, FT2, &env->fp_status);
J
j_mayer 已提交
1762
#endif
1763
    RETURN();
1764 1765
}

1766
/* fnmadd - fnmadd. - fnmadds - fnmadds. */
1767
void OPPROTO op_fnmadd (void)
1768
{
B
bellard 已提交
1769
    do_fnmadd();
1770
    RETURN();
1771 1772
}

1773
/* fnmsub - fnmsub. */
1774
void OPPROTO op_fnmsub (void)
1775
{
B
bellard 已提交
1776
    do_fnmsub();
1777
    RETURN();
1778 1779
}

1780 1781
/***                     Floating-Point round & convert                    ***/
/* frsp - frsp. */
1782
void OPPROTO op_frsp (void)
1783
{
1784
#if USE_PRECISE_EMULATION
1785 1786
    do_frsp();
#else
1787
    FT0 = float64_to_float32(FT0, &env->fp_status);
1788
#endif
1789
    RETURN();
1790 1791
}

1792
/* fctiw - fctiw. */
1793
void OPPROTO op_fctiw (void)
1794
{
1795 1796
    do_fctiw();
    RETURN();
1797 1798
}

1799
/* fctiwz - fctiwz. */
1800
void OPPROTO op_fctiwz (void)
1801
{
1802 1803
    do_fctiwz();
    RETURN();
1804 1805
}

J
j_mayer 已提交
1806 1807
#if defined(TARGET_PPC64)
/* fcfid - fcfid. */
1808
void OPPROTO op_fcfid (void)
J
j_mayer 已提交
1809 1810 1811 1812 1813 1814
{
    do_fcfid();
    RETURN();
}

/* fctid - fctid. */
1815
void OPPROTO op_fctid (void)
J
j_mayer 已提交
1816 1817 1818 1819 1820 1821
{
    do_fctid();
    RETURN();
}

/* fctidz - fctidz. */
1822
void OPPROTO op_fctidz (void)
J
j_mayer 已提交
1823 1824 1825 1826 1827 1828
{
    do_fctidz();
    RETURN();
}
#endif

1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
void OPPROTO op_frin (void)
{
    do_frin();
    RETURN();
}

void OPPROTO op_friz (void)
{
    do_friz();
    RETURN();
}

void OPPROTO op_frip (void)
{
    do_frip();
    RETURN();
}

void OPPROTO op_frim (void)
{
    do_frim();
    RETURN();
}

1853 1854
/***                         Floating-Point compare                        ***/
/* fcmpu */
1855
void OPPROTO op_fcmpu (void)
1856
{
1857 1858
    do_fcmpu();
    RETURN();
1859 1860
}

1861
/* fcmpo */
1862
void OPPROTO op_fcmpo (void)
B
bellard 已提交
1863
{
1864 1865
    do_fcmpo();
    RETURN();
B
bellard 已提交
1866 1867
}

1868 1869
/***                         Floating-point move                           ***/
/* fabs */
1870
void OPPROTO op_fabs (void)
B
bellard 已提交
1871
{
1872
    FT0 = float64_abs(FT0);
B
bellard 已提交
1873 1874 1875
    RETURN();
}

1876
/* fnabs */
1877
void OPPROTO op_fnabs (void)
B
bellard 已提交
1878
{
1879 1880
    FT0 = float64_abs(FT0);
    FT0 = float64_chs(FT0);
B
bellard 已提交
1881 1882 1883
    RETURN();
}

1884
/* fneg */
1885
void OPPROTO op_fneg (void)
B
bellard 已提交
1886
{
1887
    FT0 = float64_chs(FT0);
B
bellard 已提交
1888 1889 1890
    RETURN();
}

1891 1892
/* Load and store */
#define MEMSUFFIX _raw
1893
#include "op_helper.h"
1894
#include "op_mem.h"
1895
#if !defined(CONFIG_USER_ONLY)
1896
#define MEMSUFFIX _user
1897
#include "op_helper.h"
1898 1899
#include "op_mem.h"
#define MEMSUFFIX _kernel
1900
#include "op_helper.h"
1901
#include "op_mem.h"
1902 1903 1904 1905
#define MEMSUFFIX _hypv
#include "op_helper.h"
#include "op_mem.h"
#endif
1906

B
bellard 已提交
1907
/* Special op to check and maybe clear reservation */
1908
void OPPROTO op_check_reservation (void)
B
bellard 已提交
1909
{
1910
    if ((uint32_t)env->reserve == (uint32_t)(T0 & ~0x00000003))
1911
        env->reserve = (target_ulong)-1ULL;
B
bellard 已提交
1912 1913 1914
    RETURN();
}

1915 1916 1917 1918
#if defined(TARGET_PPC64)
void OPPROTO op_check_reservation_64 (void)
{
    if ((uint64_t)env->reserve == (uint64_t)(T0 & ~0x00000003))
1919
        env->reserve = (target_ulong)-1ULL;
1920 1921 1922 1923
    RETURN();
}
#endif

1924 1925 1926 1927 1928 1929
void OPPROTO op_wait (void)
{
    env->halted = 1;
    RETURN();
}

1930
/* Return from interrupt */
1931 1932
#if !defined(CONFIG_USER_ONLY)
void OPPROTO op_rfi (void)
1933
{
1934
    do_rfi();
B
bellard 已提交
1935 1936
    RETURN();
}
1937 1938

#if defined(TARGET_PPC64)
J
j_mayer 已提交
1939 1940 1941 1942 1943
void OPPROTO op_rfid (void)
{
    do_rfid();
    RETURN();
}
1944 1945 1946 1947 1948 1949 1950

void OPPROTO op_hrfid (void)
{
    do_hrfid();
    RETURN();
}
#endif
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965

/* Exception vectors */
void OPPROTO op_store_excp_prefix (void)
{
    T0 &= env->ivpr_mask;
    env->excp_prefix = T0;
    RETURN();
}

void OPPROTO op_store_excp_vector (void)
{
    T0 &= env->ivor_mask;
    env->excp_vectors[PARAM1] = T0;
    RETURN();
}
1966
#endif
B
bellard 已提交
1967

1968
/* Trap word */
1969
void OPPROTO op_tw (void)
B
bellard 已提交
1970
{
1971
    do_tw(PARAM1);
B
bellard 已提交
1972 1973 1974
    RETURN();
}

1975 1976 1977 1978 1979 1980 1981 1982
#if defined(TARGET_PPC64)
void OPPROTO op_td (void)
{
    do_td(PARAM1);
    RETURN();
}
#endif

1983
#if !defined(CONFIG_USER_ONLY)
1984
/* tlbia */
1985
void OPPROTO op_tlbia (void)
B
bellard 已提交
1986
{
1987
    ppc_tlb_invalidate_all(env);
1988 1989 1990 1991
    RETURN();
}

/* tlbie */
1992
void OPPROTO op_tlbie (void)
1993
{
1994
    ppc_tlb_invalidate_one(env, (uint32_t)T0);
B
bellard 已提交
1995
    RETURN();
1996
}
1997 1998 1999 2000

#if defined(TARGET_PPC64)
void OPPROTO op_tlbie_64 (void)
{
2001
    ppc_tlb_invalidate_one(env, T0);
2002 2003 2004 2005 2006 2007 2008
    RETURN();
}
#endif

#if defined(TARGET_PPC64)
void OPPROTO op_slbia (void)
{
2009
    ppc_slb_invalidate_all(env);
2010 2011 2012 2013 2014
    RETURN();
}

void OPPROTO op_slbie (void)
{
2015 2016 2017 2018 2019 2020 2021
    ppc_slb_invalidate_one(env, (uint32_t)T0);
    RETURN();
}

void OPPROTO op_slbie_64 (void)
{
    ppc_slb_invalidate_one(env, T0);
2022 2023 2024
    RETURN();
}
#endif
2025
#endif
2026

2027
#if !defined(CONFIG_USER_ONLY)
2028
/* PowerPC 602/603/755 software TLB load instructions */
2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039
void OPPROTO op_6xx_tlbld (void)
{
    do_load_6xx_tlb(0);
    RETURN();
}

void OPPROTO op_6xx_tlbli (void)
{
    do_load_6xx_tlb(1);
    RETURN();
}
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052

/* PowerPC 74xx software TLB load instructions */
void OPPROTO op_74xx_tlbld (void)
{
    do_load_74xx_tlb(0);
    RETURN();
}

void OPPROTO op_74xx_tlbli (void)
{
    do_load_74xx_tlb(1);
    RETURN();
}
2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080
#endif

/* 601 specific */
void OPPROTO op_load_601_rtcl (void)
{
    T0 = cpu_ppc601_load_rtcl(env);
    RETURN();
}

void OPPROTO op_load_601_rtcu (void)
{
    T0 = cpu_ppc601_load_rtcu(env);
    RETURN();
}

#if !defined(CONFIG_USER_ONLY)
void OPPROTO op_store_601_rtcl (void)
{
    cpu_ppc601_store_rtcl(env, T0);
    RETURN();
}

void OPPROTO op_store_601_rtcu (void)
{
    cpu_ppc601_store_rtcu(env, T0);
    RETURN();
}

2081 2082 2083 2084 2085 2086
void OPPROTO op_store_hid0_601 (void)
{
    do_store_hid0_601();
    RETURN();
}

2087 2088 2089 2090 2091 2092 2093 2094
void OPPROTO op_load_601_bat (void)
{
    T0 = env->IBAT[PARAM1][PARAM2];
    RETURN();
}

void OPPROTO op_store_601_batl (void)
{
2095
    do_store_ibatl_601(env, PARAM1, T0);
2096 2097 2098 2099 2100
    RETURN();
}

void OPPROTO op_store_601_batu (void)
{
2101
    do_store_ibatu_601(env, PARAM1, T0);
2102 2103 2104 2105 2106 2107 2108 2109
    RETURN();
}
#endif /* !defined(CONFIG_USER_ONLY) */

/* PowerPC 601 specific instructions (POWER bridge) */
/* XXX: those micro-ops need tests ! */
void OPPROTO op_POWER_abs (void)
{
J
j_mayer 已提交
2110
    if ((int32_t)T0 == INT32_MIN)
2111
        T0 = INT32_MAX;
J
j_mayer 已提交
2112
    else if ((int32_t)T0 < 0)
2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
        T0 = -T0;
    RETURN();
}

void OPPROTO op_POWER_abso (void)
{
    do_POWER_abso();
    RETURN();
}

void OPPROTO op_POWER_clcs (void)
{
    do_POWER_clcs();
    RETURN();
}

void OPPROTO op_POWER_div (void)
{
    do_POWER_div();
    RETURN();
}

void OPPROTO op_POWER_divo (void)
{
    do_POWER_divo();
    RETURN();
}

void OPPROTO op_POWER_divs (void)
{
    do_POWER_divs();
    RETURN();
}

void OPPROTO op_POWER_divso (void)
{
    do_POWER_divso();
    RETURN();
}

void OPPROTO op_POWER_doz (void)
{
2155
    if ((int32_t)T1 > (int32_t)T0)
2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221
        T0 = T1 - T0;
    else
        T0 = 0;
    RETURN();
}

void OPPROTO op_POWER_dozo (void)
{
    do_POWER_dozo();
    RETURN();
}

void OPPROTO op_load_xer_cmp (void)
{
    T2 = xer_cmp;
    RETURN();
}

void OPPROTO op_POWER_maskg (void)
{
    do_POWER_maskg();
    RETURN();
}

void OPPROTO op_POWER_maskir (void)
{
    T0 = (T0 & ~T2) | (T1 & T2);
    RETURN();
}

void OPPROTO op_POWER_mul (void)
{
    uint64_t tmp;

    tmp = (uint64_t)T0 * (uint64_t)T1;
    env->spr[SPR_MQ] = tmp >> 32;
    T0 = tmp;
    RETURN();
}

void OPPROTO op_POWER_mulo (void)
{
    do_POWER_mulo();
    RETURN();
}

void OPPROTO op_POWER_nabs (void)
{
    if (T0 > 0)
        T0 = -T0;
    RETURN();
}

void OPPROTO op_POWER_nabso (void)
{
    /* nabs never overflows */
    if (T0 > 0)
        T0 = -T0;
    xer_ov = 0;
    RETURN();
}

/* XXX: factorise POWER rotates... */
void OPPROTO op_POWER_rlmi (void)
{
    T0 = rotl32(T0, T2) & PARAM1;
2222
    T0 |= T1 & (uint32_t)PARAM2;
2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254
    RETURN();
}

void OPPROTO op_POWER_rrib (void)
{
    T2 &= 0x1FUL;
    T0 = rotl32(T0 & INT32_MIN, T2);
    T0 |= T1 & ~rotl32(INT32_MIN, T2);
    RETURN();
}

void OPPROTO op_POWER_sle (void)
{
    T1 &= 0x1FUL;
    env->spr[SPR_MQ] = rotl32(T0, T1);
    T0 = T0 << T1;
    RETURN();
}

void OPPROTO op_POWER_sleq (void)
{
    uint32_t tmp = env->spr[SPR_MQ];

    T1 &= 0x1FUL;
    env->spr[SPR_MQ] = rotl32(T0, T1);
    T0 = T0 << T1;
    T0 |= tmp >> (32 - T1);
    RETURN();
}

void OPPROTO op_POWER_sllq (void)
{
2255
    uint32_t msk = UINT32_MAX;
2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267

    msk = msk << (T1 & 0x1FUL);
    if (T1 & 0x20UL)
        msk = ~msk;
    T1 &= 0x1FUL;
    T0 = (T0 << T1) & msk;
    T0 |= env->spr[SPR_MQ] & ~msk;
    RETURN();
}

void OPPROTO op_POWER_slq (void)
{
2268
    uint32_t msk = UINT32_MAX, tmp;
2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283

    msk = msk << (T1 & 0x1FUL);
    if (T1 & 0x20UL)
        msk = ~msk;
    T1 &= 0x1FUL;
    tmp = rotl32(T0, T1);
    T0 = tmp & msk;
    env->spr[SPR_MQ] = tmp;
    RETURN();
}

void OPPROTO op_POWER_sraq (void)
{
    env->spr[SPR_MQ] = rotl32(T0, 32 - (T1 & 0x1FUL));
    if (T1 & 0x20UL)
2284
        T0 = UINT32_MAX;
2285
    else
2286
        T0 = (int32_t)T0 >> T1;
2287 2288 2289 2290 2291 2292 2293
    RETURN();
}

void OPPROTO op_POWER_sre (void)
{
    T1 &= 0x1FUL;
    env->spr[SPR_MQ] = rotl32(T0, 32 - T1);
2294
    T0 = (int32_t)T0 >> T1;
2295 2296 2297 2298 2299 2300 2301
    RETURN();
}

void OPPROTO op_POWER_srea (void)
{
    T1 &= 0x1FUL;
    env->spr[SPR_MQ] = T0 >> T1;
2302
    T0 = (int32_t)T0 >> T1;
2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439
    RETURN();
}

void OPPROTO op_POWER_sreq (void)
{
    uint32_t tmp;
    int32_t msk;

    T1 &= 0x1FUL;
    msk = INT32_MIN >> T1;
    tmp = env->spr[SPR_MQ];
    env->spr[SPR_MQ] = rotl32(T0, 32 - T1);
    T0 = T0 >> T1;
    T0 |= tmp & msk;
    RETURN();
}

void OPPROTO op_POWER_srlq (void)
{
    uint32_t tmp;
    int32_t msk;

    msk = INT32_MIN >> (T1 & 0x1FUL);
    if (T1 & 0x20UL)
        msk = ~msk;
    T1 &= 0x1FUL;
    tmp = env->spr[SPR_MQ];
    env->spr[SPR_MQ] = rotl32(T0, 32 - T1);
    T0 = T0 >> T1;
    T0 &= msk;
    T0 |= tmp & ~msk;
    RETURN();
}

void OPPROTO op_POWER_srq (void)
{
    T1 &= 0x1FUL;
    env->spr[SPR_MQ] = rotl32(T0, 32 - T1);
    T0 = T0 >> T1;
    RETURN();
}

/* POWER instructions not implemented in PowerPC 601 */
#if !defined(CONFIG_USER_ONLY)
void OPPROTO op_POWER_mfsri (void)
{
    T1 = T0 >> 28;
    T0 = env->sr[T1];
    RETURN();
}

void OPPROTO op_POWER_rac (void)
{
    do_POWER_rac();
    RETURN();
}

void OPPROTO op_POWER_rfsvc (void)
{
    do_POWER_rfsvc();
    RETURN();
}
#endif

/* PowerPC 602 specific instruction */
#if !defined(CONFIG_USER_ONLY)
void OPPROTO op_602_mfrom (void)
{
    do_op_602_mfrom();
    RETURN();
}
#endif

/* PowerPC 4xx specific micro-ops */
void OPPROTO op_405_add_T0_T2 (void)
{
    T0 = (int32_t)T0 + (int32_t)T2;
    RETURN();
}

void OPPROTO op_405_mulchw (void)
{
    T0 = ((int16_t)T0) * ((int16_t)(T1 >> 16));
    RETURN();
}

void OPPROTO op_405_mulchwu (void)
{
    T0 = ((uint16_t)T0) * ((uint16_t)(T1 >> 16));
    RETURN();
}

void OPPROTO op_405_mulhhw (void)
{
    T0 = ((int16_t)(T0 >> 16)) * ((int16_t)(T1 >> 16));
    RETURN();
}

void OPPROTO op_405_mulhhwu (void)
{
    T0 = ((uint16_t)(T0 >> 16)) * ((uint16_t)(T1 >> 16));
    RETURN();
}

void OPPROTO op_405_mullhw (void)
{
    T0 = ((int16_t)T0) * ((int16_t)T1);
    RETURN();
}

void OPPROTO op_405_mullhwu (void)
{
    T0 = ((uint16_t)T0) * ((uint16_t)T1);
    RETURN();
}

void OPPROTO op_405_check_sat (void)
{
    do_405_check_sat();
    RETURN();
}

void OPPROTO op_405_check_ovu (void)
{
    if (likely(T0 >= T2)) {
        xer_ov = 0;
    } else {
        xer_ov = 1;
        xer_so = 1;
    }
    RETURN();
}

void OPPROTO op_405_check_satu (void)
{
    if (unlikely(T0 < T2)) {
        /* Saturate result */
2440
        T0 = UINT32_MAX;
2441 2442 2443 2444
    }
    RETURN();
}

2445
void OPPROTO op_load_dcr (void)
2446
{
2447
    do_load_dcr();
2448 2449 2450
    RETURN();
}

2451
void OPPROTO op_store_dcr (void)
2452
{
2453
    do_store_dcr();
2454 2455 2456
    RETURN();
}

2457
#if !defined(CONFIG_USER_ONLY)
2458 2459 2460
/* Return from critical interrupt :
 * same as rfi, except nip & MSR are loaded from SRR2/3 instead of SRR0/1
 */
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479
void OPPROTO op_40x_rfci (void)
{
    do_40x_rfci();
    RETURN();
}

void OPPROTO op_rfci (void)
{
    do_rfci();
    RETURN();
}

void OPPROTO op_rfdi (void)
{
    do_rfdi();
    RETURN();
}

void OPPROTO op_rfmci (void)
2480
{
2481
    do_rfmci();
2482 2483 2484
    RETURN();
}

2485
void OPPROTO op_wrte (void)
2486
{
2487 2488 2489 2490 2491 2492
    /* We don't call do_store_msr here as we won't trigger
     * any special case nor change hflags
     */
    T0 &= 1 << MSR_EE;
    env->msr &= ~(1 << MSR_EE);
    env->msr |= T0;
2493 2494 2495
    RETURN();
}

2496
void OPPROTO op_440_tlbre (void)
2497
{
2498
    do_440_tlbre(PARAM1);
2499 2500 2501
    RETURN();
}

2502
void OPPROTO op_440_tlbsx (void)
2503
{
2504
    T0 = ppcemb_tlb_search(env, T0, env->spr[SPR_440_MMUCR] & 0xFF);
2505 2506 2507
    RETURN();
}

2508
void OPPROTO op_4xx_tlbsx_check (void)
2509
{
2510 2511 2512
    int tmp;

    tmp = xer_so;
2513
    if ((int)T0 != -1)
2514 2515
        tmp |= 0x02;
    env->crf[0] = tmp;
2516 2517 2518
    RETURN();
}

2519
void OPPROTO op_440_tlbwe (void)
2520
{
2521
    do_440_tlbwe(PARAM1);
2522 2523 2524
    RETURN();
}

2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538
void OPPROTO op_4xx_tlbre_lo (void)
{
    do_4xx_tlbre_lo();
    RETURN();
}

void OPPROTO op_4xx_tlbre_hi (void)
{
    do_4xx_tlbre_hi();
    RETURN();
}

void OPPROTO op_4xx_tlbsx (void)
{
2539
    T0 = ppcemb_tlb_search(env, T0, env->spr[SPR_40x_PID]);
2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576
    RETURN();
}

void OPPROTO op_4xx_tlbwe_lo (void)
{
    do_4xx_tlbwe_lo();
    RETURN();
}

void OPPROTO op_4xx_tlbwe_hi (void)
{
    do_4xx_tlbwe_hi();
    RETURN();
}
#endif

/* SPR micro-ops */
/* 440 specific */
void OPPROTO op_440_dlmzb (void)
{
    do_440_dlmzb();
    RETURN();
}

void OPPROTO op_440_dlmzb_update_Rc (void)
{
    if (T0 == 8)
        T0 = 0x2;
    else if (T0 < 4)
        T0 = 0x4;
    else
        T0 = 0x8;
    RETURN();
}

#if !defined(CONFIG_USER_ONLY)
void OPPROTO op_store_pir (void)
2577 2578 2579 2580
{
    env->spr[SPR_PIR] = T0 & 0x0000000FUL;
    RETURN();
}
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605

void OPPROTO op_load_403_pb (void)
{
    do_load_403_pb(PARAM1);
    RETURN();
}

void OPPROTO op_store_403_pb (void)
{
    do_store_403_pb(PARAM1);
    RETURN();
}

void OPPROTO op_load_40x_pit (void)
{
    T0 = load_40x_pit(env);
    RETURN();
}

void OPPROTO op_store_40x_pit (void)
{
    store_40x_pit(env, T0);
    RETURN();
}

2606 2607 2608
void OPPROTO op_store_40x_dbcr0 (void)
{
    store_40x_dbcr0(env, T0);
2609
    RETURN();
2610 2611
}

2612 2613 2614 2615 2616 2617
void OPPROTO op_store_40x_sler (void)
{
    store_40x_sler(env, T0);
    RETURN();
}

2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629
void OPPROTO op_store_booke_tcr (void)
{
    store_booke_tcr(env, T0);
    RETURN();
}

void OPPROTO op_store_booke_tsr (void)
{
    store_booke_tsr(env, T0);
    RETURN();
}
#endif /* !defined(CONFIG_USER_ONLY) */
2630 2631 2632 2633 2634

/* SPE extension */
void OPPROTO op_splatw_T1_64 (void)
{
    T1_64 = (T1_64 << 32) | (T1_64 & 0x00000000FFFFFFFFULL);
J
j_mayer 已提交
2635
    RETURN();
2636 2637 2638 2639 2640 2641 2642
}

void OPPROTO op_splatwi_T0_64 (void)
{
    uint64_t tmp = PARAM1;

    T0_64 = (tmp << 32) | tmp;
J
j_mayer 已提交
2643
    RETURN();
2644 2645 2646 2647 2648 2649 2650
}

void OPPROTO op_splatwi_T1_64 (void)
{
    uint64_t tmp = PARAM1;

    T1_64 = (tmp << 32) | tmp;
J
j_mayer 已提交
2651
    RETURN();
2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155
}

void OPPROTO op_extsh_T1_64 (void)
{
    T1_64 = (int32_t)((int16_t)T1_64);
    RETURN();
}

void OPPROTO op_sli16_T1_64 (void)
{
    T1_64 = T1_64 << 16;
    RETURN();
}

void OPPROTO op_sli32_T1_64 (void)
{
    T1_64 = T1_64 << 32;
    RETURN();
}

void OPPROTO op_srli32_T1_64 (void)
{
    T1_64 = T1_64 >> 32;
    RETURN();
}

void OPPROTO op_evsel (void)
{
    do_evsel();
    RETURN();
}

void OPPROTO op_evaddw (void)
{
    do_evaddw();
    RETURN();
}

void OPPROTO op_evsubfw (void)
{
    do_evsubfw();
    RETURN();
}

void OPPROTO op_evneg (void)
{
    do_evneg();
    RETURN();
}

void OPPROTO op_evabs (void)
{
    do_evabs();
    RETURN();
}

void OPPROTO op_evextsh (void)
{
    T0_64 = ((uint64_t)((int32_t)(int16_t)(T0_64 >> 32)) << 32) |
        (uint64_t)((int32_t)(int16_t)T0_64);
    RETURN();
}

void OPPROTO op_evextsb (void)
{
    T0_64 = ((uint64_t)((int32_t)(int8_t)(T0_64 >> 32)) << 32) |
        (uint64_t)((int32_t)(int8_t)T0_64);
    RETURN();
}

void OPPROTO op_evcntlzw (void)
{
    do_evcntlzw();
    RETURN();
}

void OPPROTO op_evrndw (void)
{
    do_evrndw();
    RETURN();
}

void OPPROTO op_brinc (void)
{
    do_brinc();
    RETURN();
}

void OPPROTO op_evcntlsw (void)
{
    do_evcntlsw();
    RETURN();
}

void OPPROTO op_evand (void)
{
    T0_64 &= T1_64;
    RETURN();
}

void OPPROTO op_evandc (void)
{
    T0_64 &= ~T1_64;
    RETURN();
}

void OPPROTO op_evor (void)
{
    T0_64 |= T1_64;
    RETURN();
}

void OPPROTO op_evxor (void)
{
    T0_64 ^= T1_64;
    RETURN();
}

void OPPROTO op_eveqv (void)
{
    T0_64 = ~(T0_64 ^ T1_64);
    RETURN();
}

void OPPROTO op_evnor (void)
{
    T0_64 = ~(T0_64 | T1_64);
    RETURN();
}

void OPPROTO op_evorc (void)
{
    T0_64 |= ~T1_64;
    RETURN();
}

void OPPROTO op_evnand (void)
{
    T0_64 = ~(T0_64 & T1_64);
    RETURN();
}

void OPPROTO op_evsrws (void)
{
    do_evsrws();
    RETURN();
}

void OPPROTO op_evsrwu (void)
{
    do_evsrwu();
    RETURN();
}

void OPPROTO op_evslw (void)
{
    do_evslw();
    RETURN();
}

void OPPROTO op_evrlw (void)
{
    do_evrlw();
    RETURN();
}

void OPPROTO op_evmergelo (void)
{
    T0_64 = (T0_64 << 32) | (T1_64 & 0x00000000FFFFFFFFULL);
    RETURN();
}

void OPPROTO op_evmergehi (void)
{
    T0_64 = (T0_64 & 0xFFFFFFFF00000000ULL) | (T1_64 >> 32);
    RETURN();
}

void OPPROTO op_evmergelohi (void)
{
    T0_64 = (T0_64 << 32) | (T1_64 >> 32);
    RETURN();
}

void OPPROTO op_evmergehilo (void)
{
    T0_64 = (T0_64 & 0xFFFFFFFF00000000ULL) | (T1_64 & 0x00000000FFFFFFFFULL);
    RETURN();
}

void OPPROTO op_evcmpgts (void)
{
    do_evcmpgts();
    RETURN();
}

void OPPROTO op_evcmpgtu (void)
{
    do_evcmpgtu();
    RETURN();
}

void OPPROTO op_evcmplts (void)
{
    do_evcmplts();
    RETURN();
}

void OPPROTO op_evcmpltu (void)
{
    do_evcmpltu();
    RETURN();
}

void OPPROTO op_evcmpeq (void)
{
    do_evcmpeq();
    RETURN();
}

void OPPROTO op_evfssub (void)
{
    do_evfssub();
    RETURN();
}

void OPPROTO op_evfsadd (void)
{
    do_evfsadd();
    RETURN();
}

void OPPROTO op_evfsnabs (void)
{
    do_evfsnabs();
    RETURN();
}

void OPPROTO op_evfsabs (void)
{
    do_evfsabs();
    RETURN();
}

void OPPROTO op_evfsneg (void)
{
    do_evfsneg();
    RETURN();
}

void OPPROTO op_evfsdiv (void)
{
    do_evfsdiv();
    RETURN();
}

void OPPROTO op_evfsmul (void)
{
    do_evfsmul();
    RETURN();
}

void OPPROTO op_evfscmplt (void)
{
    do_evfscmplt();
    RETURN();
}

void OPPROTO op_evfscmpgt (void)
{
    do_evfscmpgt();
    RETURN();
}

void OPPROTO op_evfscmpeq (void)
{
    do_evfscmpeq();
    RETURN();
}

void OPPROTO op_evfscfsi (void)
{
    do_evfscfsi();
    RETURN();
}

void OPPROTO op_evfscfui (void)
{
    do_evfscfui();
    RETURN();
}

void OPPROTO op_evfscfsf (void)
{
    do_evfscfsf();
    RETURN();
}

void OPPROTO op_evfscfuf (void)
{
    do_evfscfuf();
    RETURN();
}

void OPPROTO op_evfsctsi (void)
{
    do_evfsctsi();
    RETURN();
}

void OPPROTO op_evfsctui (void)
{
    do_evfsctui();
    RETURN();
}

void OPPROTO op_evfsctsf (void)
{
    do_evfsctsf();
    RETURN();
}

void OPPROTO op_evfsctuf (void)
{
    do_evfsctuf();
    RETURN();
}

void OPPROTO op_evfsctuiz (void)
{
    do_evfsctuiz();
    RETURN();
}

void OPPROTO op_evfsctsiz (void)
{
    do_evfsctsiz();
    RETURN();
}

void OPPROTO op_evfststlt (void)
{
    do_evfststlt();
    RETURN();
}

void OPPROTO op_evfststgt (void)
{
    do_evfststgt();
    RETURN();
}

void OPPROTO op_evfststeq (void)
{
    do_evfststeq();
    RETURN();
}

void OPPROTO op_efssub (void)
{
    T0_64 = _do_efssub(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efsadd (void)
{
    T0_64 = _do_efsadd(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efsnabs (void)
{
    T0_64 = _do_efsnabs(T0_64);
    RETURN();
}

void OPPROTO op_efsabs (void)
{
    T0_64 = _do_efsabs(T0_64);
    RETURN();
}

void OPPROTO op_efsneg (void)
{
    T0_64 = _do_efsneg(T0_64);
    RETURN();
}

void OPPROTO op_efsdiv (void)
{
    T0_64 = _do_efsdiv(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efsmul (void)
{
    T0_64 = _do_efsmul(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efscmplt (void)
{
    do_efscmplt();
    RETURN();
}

void OPPROTO op_efscmpgt (void)
{
    do_efscmpgt();
    RETURN();
}

void OPPROTO op_efscfd (void)
{
    do_efscfd();
    RETURN();
}

void OPPROTO op_efscmpeq (void)
{
    do_efscmpeq();
    RETURN();
}

void OPPROTO op_efscfsi (void)
{
    do_efscfsi();
    RETURN();
}

void OPPROTO op_efscfui (void)
{
    do_efscfui();
    RETURN();
}

void OPPROTO op_efscfsf (void)
{
    do_efscfsf();
    RETURN();
}

void OPPROTO op_efscfuf (void)
{
    do_efscfuf();
    RETURN();
}

void OPPROTO op_efsctsi (void)
{
    do_efsctsi();
    RETURN();
}

void OPPROTO op_efsctui (void)
{
    do_efsctui();
    RETURN();
}

void OPPROTO op_efsctsf (void)
{
    do_efsctsf();
    RETURN();
}

void OPPROTO op_efsctuf (void)
{
    do_efsctuf();
    RETURN();
}

void OPPROTO op_efsctsiz (void)
{
    do_efsctsiz();
    RETURN();
}

void OPPROTO op_efsctuiz (void)
{
    do_efsctuiz();
    RETURN();
}

void OPPROTO op_efststlt (void)
{
    T0 = _do_efststlt(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efststgt (void)
{
    T0 = _do_efststgt(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efststeq (void)
{
    T0 = _do_efststeq(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efdsub (void)
{
A
aurel32 已提交
3156 3157 3158 3159 3160
    CPU_DoubleU u1, u2;
    u1.ll = T0_64;
    u2.ll = T1_64;
    u1.d = float64_sub(u1.d, u2.d, &env->spe_status);
    T0_64 = u1.ll;
3161 3162 3163 3164 3165
    RETURN();
}

void OPPROTO op_efdadd (void)
{
A
aurel32 已提交
3166 3167 3168 3169 3170
    CPU_DoubleU u1, u2;
    u1.ll = T0_64;
    u2.ll = T1_64;
    u1.d = float64_add(u1.d, u2.d, &env->spe_status);
    T0_64 = u1.ll;
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205
    RETURN();
}

void OPPROTO op_efdcfsid (void)
{
    do_efdcfsi();
    RETURN();
}

void OPPROTO op_efdcfuid (void)
{
    do_efdcfui();
    RETURN();
}

void OPPROTO op_efdnabs (void)
{
    T0_64 |= 0x8000000000000000ULL;
    RETURN();
}

void OPPROTO op_efdabs (void)
{
    T0_64 &= ~0x8000000000000000ULL;
    RETURN();
}

void OPPROTO op_efdneg (void)
{
    T0_64 ^= 0x8000000000000000ULL;
    RETURN();
}

void OPPROTO op_efddiv (void)
{
A
aurel32 已提交
3206 3207 3208 3209 3210
    CPU_DoubleU u1, u2;
    u1.ll = T0_64;
    u2.ll = T1_64;
    u1.d = float64_div(u1.d, u2.d, &env->spe_status);
    T0_64 = u1.ll;
3211 3212 3213 3214 3215
    RETURN();
}

void OPPROTO op_efdmul (void)
{
A
aurel32 已提交
3216 3217 3218 3219 3220
    CPU_DoubleU u1, u2;
    u1.ll = T0_64;
    u2.ll = T1_64;
    u1.d = float64_mul(u1.d, u2.d, &env->spe_status);
    T0_64 = u1.ll;
3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336
    RETURN();
}

void OPPROTO op_efdctsidz (void)
{
    do_efdctsiz();
    RETURN();
}

void OPPROTO op_efdctuidz (void)
{
    do_efdctuiz();
    RETURN();
}

void OPPROTO op_efdcmplt (void)
{
    do_efdcmplt();
    RETURN();
}

void OPPROTO op_efdcmpgt (void)
{
    do_efdcmpgt();
    RETURN();
}

void OPPROTO op_efdcfs (void)
{
    do_efdcfs();
    RETURN();
}

void OPPROTO op_efdcmpeq (void)
{
    do_efdcmpeq();
    RETURN();
}

void OPPROTO op_efdcfsi (void)
{
    do_efdcfsi();
    RETURN();
}

void OPPROTO op_efdcfui (void)
{
    do_efdcfui();
    RETURN();
}

void OPPROTO op_efdcfsf (void)
{
    do_efdcfsf();
    RETURN();
}

void OPPROTO op_efdcfuf (void)
{
    do_efdcfuf();
    RETURN();
}

void OPPROTO op_efdctsi (void)
{
    do_efdctsi();
    RETURN();
}

void OPPROTO op_efdctui (void)
{
    do_efdctui();
    RETURN();
}

void OPPROTO op_efdctsf (void)
{
    do_efdctsf();
    RETURN();
}

void OPPROTO op_efdctuf (void)
{
    do_efdctuf();
    RETURN();
}

void OPPROTO op_efdctuiz (void)
{
    do_efdctuiz();
    RETURN();
}

void OPPROTO op_efdctsiz (void)
{
    do_efdctsiz();
    RETURN();
}

void OPPROTO op_efdtstlt (void)
{
    T0 = _do_efdtstlt(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efdtstgt (void)
{
    T0 = _do_efdtstgt(T0_64, T1_64);
    RETURN();
}

void OPPROTO op_efdtsteq (void)
{
    T0 = _do_efdtsteq(T0_64, T1_64);
    RETURN();
}