op.c 44.8 KB
Newer Older
B
bellard 已提交
1 2 3 4
/*
 *  MIPS emulation micro-operations for qemu.
 * 
 *  Copyright (c) 2004-2005 Jocelyn Mayer
B
bellard 已提交
5
 *  Copyright (c) 2006 Marius Groeger (FPU operations)
T
ths 已提交
6
 *  Copyright (c) 2007 Thiemo Seufer (64-bit FPU support)
B
bellard 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * 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
 */

#include "config.h"
#include "exec.h"

B
bellard 已提交
26
#ifndef CALL_FROM_TB0
27
#define CALL_FROM_TB0(func) func()
B
bellard 已提交
28 29
#endif
#ifndef CALL_FROM_TB1
30
#define CALL_FROM_TB1(func, arg0) func(arg0)
B
bellard 已提交
31 32
#endif
#ifndef CALL_FROM_TB1_CONST16
33
#define CALL_FROM_TB1_CONST16(func, arg0) CALL_FROM_TB1(func, arg0)
B
bellard 已提交
34 35
#endif
#ifndef CALL_FROM_TB2
36
#define CALL_FROM_TB2(func, arg0, arg1) func(arg0, arg1)
B
bellard 已提交
37 38 39
#endif
#ifndef CALL_FROM_TB2_CONST16
#define CALL_FROM_TB2_CONST16(func, arg0, arg1)     \
40
        CALL_FROM_TB2(func, arg0, arg1)
B
bellard 已提交
41 42
#endif
#ifndef CALL_FROM_TB3
43
#define CALL_FROM_TB3(func, arg0, arg1, arg2) func(arg0, arg1, arg2)
B
bellard 已提交
44 45 46
#endif
#ifndef CALL_FROM_TB4
#define CALL_FROM_TB4(func, arg0, arg1, arg2, arg3) \
47
        func(arg0, arg1, arg2, arg3)
B
bellard 已提交
48 49
#endif

B
bellard 已提交
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
#define REG 1
#include "op_template.c"
#undef REG
#define REG 2
#include "op_template.c"
#undef REG
#define REG 3
#include "op_template.c"
#undef REG
#define REG 4
#include "op_template.c"
#undef REG
#define REG 5
#include "op_template.c"
#undef REG
#define REG 6
#include "op_template.c"
#undef REG
#define REG 7
#include "op_template.c"
#undef REG
#define REG 8
#include "op_template.c"
#undef REG
#define REG 9
#include "op_template.c"
#undef REG
#define REG 10
#include "op_template.c"
#undef REG
#define REG 11
#include "op_template.c"
#undef REG
#define REG 12
#include "op_template.c"
#undef REG
#define REG 13
#include "op_template.c"
#undef REG
#define REG 14
#include "op_template.c"
#undef REG
#define REG 15
#include "op_template.c"
#undef REG
#define REG 16
#include "op_template.c"
#undef REG
#define REG 17
#include "op_template.c"
#undef REG
#define REG 18
#include "op_template.c"
#undef REG
#define REG 19
#include "op_template.c"
#undef REG
#define REG 20
#include "op_template.c"
#undef REG
#define REG 21
#include "op_template.c"
#undef REG
#define REG 22
#include "op_template.c"
#undef REG
#define REG 23
#include "op_template.c"
#undef REG
#define REG 24
#include "op_template.c"
#undef REG
#define REG 25
#include "op_template.c"
#undef REG
#define REG 26
#include "op_template.c"
#undef REG
#define REG 27
#include "op_template.c"
#undef REG
#define REG 28
#include "op_template.c"
#undef REG
#define REG 29
#include "op_template.c"
#undef REG
#define REG 30
#include "op_template.c"
#undef REG
#define REG 31
#include "op_template.c"
#undef REG

144
#define TN
B
bellard 已提交
145 146 147
#include "op_template.c"
#undef TN

148
#define FREG 0
B
bellard 已提交
149
#include "fop_template.c"
150 151
#undef FREG
#define FREG 1
B
bellard 已提交
152
#include "fop_template.c"
153 154
#undef FREG
#define FREG 2
B
bellard 已提交
155
#include "fop_template.c"
156 157
#undef FREG
#define FREG 3
B
bellard 已提交
158
#include "fop_template.c"
159 160
#undef FREG
#define FREG 4
B
bellard 已提交
161
#include "fop_template.c"
162 163
#undef FREG
#define FREG 5
B
bellard 已提交
164
#include "fop_template.c"
165 166
#undef FREG
#define FREG 6
B
bellard 已提交
167
#include "fop_template.c"
168 169
#undef FREG
#define FREG 7
B
bellard 已提交
170
#include "fop_template.c"
171 172
#undef FREG
#define FREG 8
B
bellard 已提交
173
#include "fop_template.c"
174 175
#undef FREG
#define FREG 9
B
bellard 已提交
176
#include "fop_template.c"
177 178
#undef FREG
#define FREG 10
B
bellard 已提交
179
#include "fop_template.c"
180 181
#undef FREG
#define FREG 11
B
bellard 已提交
182
#include "fop_template.c"
183 184
#undef FREG
#define FREG 12
B
bellard 已提交
185
#include "fop_template.c"
186 187
#undef FREG
#define FREG 13
B
bellard 已提交
188
#include "fop_template.c"
189 190
#undef FREG
#define FREG 14
B
bellard 已提交
191
#include "fop_template.c"
192 193
#undef FREG
#define FREG 15
B
bellard 已提交
194
#include "fop_template.c"
195 196
#undef FREG
#define FREG 16
B
bellard 已提交
197
#include "fop_template.c"
198 199
#undef FREG
#define FREG 17
B
bellard 已提交
200
#include "fop_template.c"
201 202
#undef FREG
#define FREG 18
B
bellard 已提交
203
#include "fop_template.c"
204 205
#undef FREG
#define FREG 19
B
bellard 已提交
206
#include "fop_template.c"
207 208
#undef FREG
#define FREG 20
B
bellard 已提交
209
#include "fop_template.c"
210 211
#undef FREG
#define FREG 21
B
bellard 已提交
212
#include "fop_template.c"
213 214
#undef FREG
#define FREG 22
B
bellard 已提交
215
#include "fop_template.c"
216 217
#undef FREG
#define FREG 23
B
bellard 已提交
218
#include "fop_template.c"
219 220
#undef FREG
#define FREG 24
B
bellard 已提交
221
#include "fop_template.c"
222 223
#undef FREG
#define FREG 25
B
bellard 已提交
224
#include "fop_template.c"
225 226
#undef FREG
#define FREG 26
B
bellard 已提交
227
#include "fop_template.c"
228 229
#undef FREG
#define FREG 27
B
bellard 已提交
230
#include "fop_template.c"
231 232
#undef FREG
#define FREG 28
B
bellard 已提交
233
#include "fop_template.c"
234 235
#undef FREG
#define FREG 29
B
bellard 已提交
236
#include "fop_template.c"
237 238
#undef FREG
#define FREG 30
B
bellard 已提交
239
#include "fop_template.c"
240 241
#undef FREG
#define FREG 31
B
bellard 已提交
242
#include "fop_template.c"
243
#undef FREG
B
bellard 已提交
244 245 246 247 248

#define FTN
#include "fop_template.c"
#undef FTN

B
bellard 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
void op_dup_T0 (void)
{
    T2 = T0;
    RETURN();
}

void op_load_HI (void)
{
    T0 = env->HI;
    RETURN();
}

void op_store_HI (void)
{
    env->HI = T0;
    RETURN();
}

void op_load_LO (void)
{
    T0 = env->LO;
    RETURN();
}

void op_store_LO (void)
{
    env->LO = T0;
    RETURN();
}

/* Load and store */
#define MEMSUFFIX _raw
#include "op_mem.c"
#undef MEMSUFFIX
#if !defined(CONFIG_USER_ONLY)
#define MEMSUFFIX _user
#include "op_mem.c"
#undef MEMSUFFIX

#define MEMSUFFIX _kernel
#include "op_mem.c"
#undef MEMSUFFIX
#endif

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
/* Addresses computation */
void op_addr_add (void)
{
/* For compatibility with 32-bit code, data reference in user mode
   with Status_UX = 0 should be casted to 32-bit and sign extended.
   See the MIPS64 PRA manual, section 4.10. */
#ifdef TARGET_MIPS64
    if ((env->CP0_Status & (1 << CP0St_UM)) &&
        !(env->CP0_Status & (1 << CP0St_UX)))
        T0 = (int64_t)(int32_t)(T0 + T1);
    else
#endif
        T0 += T1;
    RETURN();
}

B
bellard 已提交
309 310 311
/* Arithmetic */
void op_add (void)
{
T
ths 已提交
312
    T0 = (int32_t)((int32_t)T0 + (int32_t)T1);
B
bellard 已提交
313 314 315 316 317 318 319
    RETURN();
}

void op_addo (void)
{
    target_ulong tmp;

320 321
    tmp = (int32_t)T0;
    T0 = (int32_t)T0 + (int32_t)T1;
322
    if (((tmp ^ T1 ^ (-1)) & (T0 ^ T1)) >> 31) {
323
        /* operands of same sign, result different sign */
324
        CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
B
bellard 已提交
325
    }
T
ths 已提交
326
    T0 = (int32_t)T0;
B
bellard 已提交
327 328 329 330 331
    RETURN();
}

void op_sub (void)
{
T
ths 已提交
332
    T0 = (int32_t)((int32_t)T0 - (int32_t)T1);
B
bellard 已提交
333 334 335 336 337 338 339
    RETURN();
}

void op_subo (void)
{
    target_ulong tmp;

340
    tmp = (int32_t)T0;
B
bellard 已提交
341
    T0 = (int32_t)T0 - (int32_t)T1;
342
    if (((tmp ^ T1) & (tmp ^ T0)) >> 31) {
343
        /* operands of different sign, first operand and result different sign */
344
        CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
B
bellard 已提交
345
    }
T
ths 已提交
346
    T0 = (int32_t)T0;
B
bellard 已提交
347 348 349 350 351
    RETURN();
}

void op_mul (void)
{
T
ths 已提交
352
    T0 = (int32_t)((int32_t)T0 * (int32_t)T1);
B
bellard 已提交
353 354 355
    RETURN();
}

356 357 358 359 360 361 362
#if HOST_LONG_BITS < 64
void op_div (void)
{
    CALL_FROM_TB0(do_div);
    RETURN();
}
#else
B
bellard 已提交
363 364 365
void op_div (void)
{
    if (T1 != 0) {
366 367
        env->LO = (int32_t)((int64_t)(int32_t)T0 / (int32_t)T1);
        env->HI = (int32_t)((int64_t)(int32_t)T0 % (int32_t)T1);
B
bellard 已提交
368 369 370
    }
    RETURN();
}
371
#endif
B
bellard 已提交
372 373

void op_divu (void)
374 375
{
    if (T1 != 0) {
T
ths 已提交
376 377
        env->LO = (int32_t)((uint32_t)T0 / (uint32_t)T1);
        env->HI = (int32_t)((uint32_t)T0 % (uint32_t)T1);
378 379 380 381
    }
    RETURN();
}

T
ths 已提交
382
#ifdef TARGET_MIPS64
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
/* Arithmetic */
void op_dadd (void)
{
    T0 += T1;
    RETURN();
}

void op_daddo (void)
{
    target_long tmp;

    tmp = T0;
    T0 += T1;
    if (((tmp ^ T1 ^ (-1)) & (T0 ^ T1)) >> 63) {
        /* operands of same sign, result different sign */
398
        CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
    }
    RETURN();
}

void op_dsub (void)
{
    T0 -= T1;
    RETURN();
}

void op_dsubo (void)
{
    target_long tmp;

    tmp = T0;
    T0 = (int64_t)T0 - (int64_t)T1;
    if (((tmp ^ T1) & (tmp ^ T0)) >> 63) {
        /* operands of different sign, first operand and result different sign */
417
        CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
    }
    RETURN();
}

void op_dmul (void)
{
    T0 = (int64_t)T0 * (int64_t)T1;
    RETURN();
}

/* Those might call libgcc functions.  */
void op_ddiv (void)
{
    do_ddiv();
    RETURN();
}

435
#if TARGET_LONG_BITS > HOST_LONG_BITS
436 437 438 439 440 441 442
void op_ddivu (void)
{
    do_ddivu();
    RETURN();
}
#else
void op_ddivu (void)
B
bellard 已提交
443 444 445 446 447 448 449
{
    if (T1 != 0) {
        env->LO = T0 / T1;
        env->HI = T0 % T1;
    }
    RETURN();
}
450
#endif
T
ths 已提交
451
#endif /* TARGET_MIPS64 */
B
bellard 已提交
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479

/* Logical */
void op_and (void)
{
    T0 &= T1;
    RETURN();
}

void op_nor (void)
{
    T0 = ~(T0 | T1);
    RETURN();
}

void op_or (void)
{
    T0 |= T1;
    RETURN();
}

void op_xor (void)
{
    T0 ^= T1;
    RETURN();
}

void op_sll (void)
{
480
    T0 = (int32_t)((uint32_t)T0 << T1);
B
bellard 已提交
481 482 483 484 485
    RETURN();
}

void op_sra (void)
{
486
    T0 = (int32_t)((int32_t)T0 >> T1);
B
bellard 已提交
487 488 489 490 491
    RETURN();
}

void op_srl (void)
{
492
    T0 = (int32_t)((uint32_t)T0 >> T1);
B
bellard 已提交
493 494 495
    RETURN();
}

496 497 498 499 500
void op_rotr (void)
{
    target_ulong tmp;

    if (T1) {
501 502 503
       tmp = (int32_t)((uint32_t)T0 << (0x20 - T1));
       T0 = (int32_t)((uint32_t)T0 >> T1) | tmp;
    }
504 505 506
    RETURN();
}

B
bellard 已提交
507 508
void op_sllv (void)
{
T
ths 已提交
509
    T0 = (int32_t)((uint32_t)T1 << ((uint32_t)T0 & 0x1F));
B
bellard 已提交
510 511 512 513 514
    RETURN();
}

void op_srav (void)
{
T
ths 已提交
515
    T0 = (int32_t)((int32_t)T1 >> (T0 & 0x1F));
B
bellard 已提交
516 517 518 519 520
    RETURN();
}

void op_srlv (void)
{
T
ths 已提交
521
    T0 = (int32_t)((uint32_t)T1 >> (T0 & 0x1F));
B
bellard 已提交
522 523 524
    RETURN();
}

525 526 527 528 529 530
void op_rotrv (void)
{
    target_ulong tmp;

    T0 &= 0x1F;
    if (T0) {
T
ths 已提交
531 532
       tmp = (int32_t)((uint32_t)T1 << (0x20 - T0));
       T0 = (int32_t)((uint32_t)T1 >> T0) | tmp;
533 534 535 536 537
    } else
       T0 = T1;
    RETURN();
}

B
bellard 已提交
538 539 540 541
void op_clo (void)
{
    int n;

542
    if (T0 == ~((target_ulong)0)) {
B
bellard 已提交
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
        T0 = 32;
    } else {
        for (n = 0; n < 32; n++) {
            if (!(T0 & (1 << 31)))
                break;
            T0 = T0 << 1;
        }
        T0 = n;
    }
    RETURN();
}

void op_clz (void)
{
    int n;

    if (T0 == 0) {
        T0 = 32;
    } else {
        for (n = 0; n < 32; n++) {
            if (T0 & (1 << 31))
                break;
            T0 = T0 << 1;
        }
        T0 = n;
    }
    RETURN();
}

T
ths 已提交
572
#ifdef TARGET_MIPS64
573 574 575 576

#if TARGET_LONG_BITS > HOST_LONG_BITS
/* Those might call libgcc functions.  */
void op_dsll (void)
B
bellard 已提交
577
{
578 579
    CALL_FROM_TB0(do_dsll);
    RETURN();
B
bellard 已提交
580 581
}

582
void op_dsll32 (void)
B
bellard 已提交
583
{
584 585
    CALL_FROM_TB0(do_dsll32);
    RETURN();
B
bellard 已提交
586 587
}

588
void op_dsra (void)
B
bellard 已提交
589
{
590
    CALL_FROM_TB0(do_dsra);
B
bellard 已提交
591 592 593
    RETURN();
}

594
void op_dsra32 (void)
B
bellard 已提交
595
{
596
    CALL_FROM_TB0(do_dsra32);
B
bellard 已提交
597 598 599
    RETURN();
}

600
void op_dsrl (void)
B
bellard 已提交
601
{
602 603 604
    CALL_FROM_TB0(do_dsrl);
    RETURN();
}
B
bellard 已提交
605

606 607 608
void op_dsrl32 (void)
{
    CALL_FROM_TB0(do_dsrl32);
B
bellard 已提交
609 610 611
    RETURN();
}

612
void op_drotr (void)
B
bellard 已提交
613
{
614 615 616
    CALL_FROM_TB0(do_drotr);
    RETURN();
}
B
bellard 已提交
617

618 619 620
void op_drotr32 (void)
{
    CALL_FROM_TB0(do_drotr32);
B
bellard 已提交
621 622 623
    RETURN();
}

624
void op_dsllv (void)
B
bellard 已提交
625
{
626 627 628
    CALL_FROM_TB0(do_dsllv);
    RETURN();
}
B
bellard 已提交
629

630 631 632
void op_dsrav (void)
{
    CALL_FROM_TB0(do_dsrav);
B
bellard 已提交
633 634 635
    RETURN();
}

636
void op_dsrlv (void)
B
bellard 已提交
637
{
638 639 640
    CALL_FROM_TB0(do_dsrlv);
    RETURN();
}
B
bellard 已提交
641

642 643 644
void op_drotrv (void)
{
    CALL_FROM_TB0(do_drotrv);
B
bellard 已提交
645 646
    RETURN();
}
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692

#else /* TARGET_LONG_BITS > HOST_LONG_BITS */

void op_dsll (void)
{
    T0 = T0 << T1;
    RETURN();
}

void op_dsll32 (void)
{
    T0 = T0 << (T1 + 32);
    RETURN();
}

void op_dsra (void)
{
    T0 = (int64_t)T0 >> T1;
    RETURN();
}

void op_dsra32 (void)
{
    T0 = (int64_t)T0 >> (T1 + 32);
    RETURN();
}

void op_dsrl (void)
{
    T0 = T0 >> T1;
    RETURN();
}

void op_dsrl32 (void)
{
    T0 = T0 >> (T1 + 32);
    RETURN();
}

void op_drotr (void)
{
    target_ulong tmp;

    if (T1) {
       tmp = T0 << (0x40 - T1);
       T0 = (T0 >> T1) | tmp;
693
    }
694 695 696 697 698 699 700 701 702 703
    RETURN();
}

void op_drotr32 (void)
{
    target_ulong tmp;

    if (T1) {
       tmp = T0 << (0x40 - (32 + T1));
       T0 = (T0 >> (32 + T1)) | tmp;
704
    }
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
    RETURN();
}

void op_dsllv (void)
{
    T0 = T1 << (T0 & 0x3F);
    RETURN();
}

void op_dsrav (void)
{
    T0 = (int64_t)T1 >> (T0 & 0x3F);
    RETURN();
}

void op_dsrlv (void)
{
    T0 = T1 >> (T0 & 0x3F);
    RETURN();
}

void op_drotrv (void)
{
    target_ulong tmp;

    T0 &= 0x3F;
    if (T0) {
       tmp = T1 << (0x40 - T0);
       T0 = (T1 >> T0) | tmp;
    } else
       T0 = T1;
    RETURN();
}
#endif /* TARGET_LONG_BITS > HOST_LONG_BITS */

void op_dclo (void)
{
    int n;

    if (T0 == ~((target_ulong)0)) {
        T0 = 64;
    } else {
        for (n = 0; n < 64; n++) {
            if (!(T0 & (1ULL << 63)))
                break;
            T0 = T0 << 1;
        }
        T0 = n;
    }
    RETURN();
}

void op_dclz (void)
{
    int n;

    if (T0 == 0) {
        T0 = 64;
    } else {
        for (n = 0; n < 64; n++) {
            if (T0 & (1ULL << 63))
                break;
            T0 = T0 << 1;
        }
        T0 = n;
    }
    RETURN();
}
#endif

/* 64 bits arithmetic */
#if TARGET_LONG_BITS > HOST_LONG_BITS
B
bellard 已提交
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
void op_mult (void)
{
    CALL_FROM_TB0(do_mult);
    RETURN();
}

void op_multu (void)
{
    CALL_FROM_TB0(do_multu);
    RETURN();
}

void op_madd (void)
{
    CALL_FROM_TB0(do_madd);
    RETURN();
}

void op_maddu (void)
{
    CALL_FROM_TB0(do_maddu);
    RETURN();
}

void op_msub (void)
{
    CALL_FROM_TB0(do_msub);
    RETURN();
}

void op_msubu (void)
{
    CALL_FROM_TB0(do_msubu);
    RETURN();
}
812 813 814 815 816 817 818 819 820 821

#else /* TARGET_LONG_BITS > HOST_LONG_BITS */

static inline uint64_t get_HILO (void)
{
    return ((uint64_t)env->HI << 32) | ((uint64_t)(uint32_t)env->LO);
}

static inline void set_HILO (uint64_t HILO)
{
T
ths 已提交
822 823
    env->LO = (int32_t)(HILO & 0xFFFFFFFF);
    env->HI = (int32_t)(HILO >> 32);
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
}

void op_mult (void)
{
    set_HILO((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
    RETURN();
}

void op_multu (void)
{
    set_HILO((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
    RETURN();
}

void op_madd (void)
{
    int64_t tmp;

    tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
    set_HILO((int64_t)get_HILO() + tmp);
    RETURN();
}

void op_maddu (void)
{
    uint64_t tmp;

    tmp = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
    set_HILO(get_HILO() + tmp);
    RETURN();
}

void op_msub (void)
{
    int64_t tmp;

    tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
    set_HILO((int64_t)get_HILO() - tmp);
    RETURN();
}

void op_msubu (void)
{
    uint64_t tmp;

    tmp = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
    set_HILO(get_HILO() - tmp);
    RETURN();
}
#endif /* TARGET_LONG_BITS > HOST_LONG_BITS */

T
ths 已提交
875
#ifdef TARGET_MIPS64
876 877
void op_dmult (void)
{
878
    CALL_FROM_TB4(muls64, &(env->HI), &(env->LO), T0, T1);
879 880 881 882 883
    RETURN();
}

void op_dmultu (void)
{
884
    CALL_FROM_TB4(mulu64, &(env->HI), &(env->LO), T0, T1);
885 886
    RETURN();
}
B
bellard 已提交
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
#endif

/* Conditional moves */
void op_movn (void)
{
    if (T1 != 0)
        env->gpr[PARAM1] = T0;
    RETURN();
}

void op_movz (void)
{
    if (T1 == 0)
        env->gpr[PARAM1] = T0;
    RETURN();
}

904 905 906
void op_movf (void)
{
    if (!(env->fcr31 & PARAM1))
907
        T0 = T1;
908 909 910 911 912 913
    RETURN();
}

void op_movt (void)
{
    if (env->fcr31 & PARAM1)
914
        T0 = T1;
915 916 917
    RETURN();
}

B
bellard 已提交
918 919 920 921 922 923 924 925 926 927 928 929 930 931
/* Tests */
#define OP_COND(name, cond) \
void glue(op_, name) (void) \
{                           \
    if (cond) {             \
        T0 = 1;             \
    } else {                \
        T0 = 0;             \
    }                       \
    RETURN();               \
}

OP_COND(eq, T0 == T1);
OP_COND(ne, T0 != T1);
932
OP_COND(ge, (target_long)T0 >= (target_long)T1);
B
bellard 已提交
933
OP_COND(geu, T0 >= T1);
934
OP_COND(lt, (target_long)T0 < (target_long)T1);
B
bellard 已提交
935
OP_COND(ltu, T0 < T1);
936 937 938 939
OP_COND(gez, (target_long)T0 >= 0);
OP_COND(gtz, (target_long)T0 > 0);
OP_COND(lez, (target_long)T0 <= 0);
OP_COND(ltz, (target_long)T0 < 0);
B
bellard 已提交
940

941
/* Branches */
B
bellard 已提交
942 943 944
void OPPROTO op_goto_tb0(void)
{
    GOTO_TB(op_goto_tb0, PARAM1, 0);
945
    RETURN();
B
bellard 已提交
946 947 948 949 950
}

void OPPROTO op_goto_tb1(void)
{
    GOTO_TB(op_goto_tb1, PARAM1, 1);
951
    RETURN();
B
bellard 已提交
952
}
B
bellard 已提交
953 954 955 956 957

/* Branch to register */
void op_save_breg_target (void)
{
    env->btarget = T2;
958
    RETURN();
B
bellard 已提交
959 960 961 962 963
}

void op_restore_breg_target (void)
{
    T2 = env->btarget;
964
    RETURN();
B
bellard 已提交
965 966 967 968 969 970 971 972 973 974 975 976 977 978
}

void op_breg (void)
{
    env->PC = T2;
    RETURN();
}

void op_save_btarget (void)
{
    env->btarget = PARAM1;
    RETURN();
}

979 980 981 982 983 984 985 986
#ifdef TARGET_MIPS64
void op_save_btarget64 (void)
{
    env->btarget = ((uint64_t)PARAM1 << 32) | (uint32_t)PARAM2;
    RETURN();
}
#endif

B
bellard 已提交
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
/* Conditional branch */
void op_set_bcond (void)
{
    T2 = T0;
    RETURN();
}

void op_save_bcond (void)
{
    env->bcond = T2;
    RETURN();
}

void op_restore_bcond (void)
{
    T2 = env->bcond;
    RETURN();
}

B
bellard 已提交
1006
void op_jnz_T2 (void)
B
bellard 已提交
1007
{
B
bellard 已提交
1008 1009
    if (T2)
        GOTO_LABEL_PARAM(1);
B
bellard 已提交
1010 1011 1012 1013
    RETURN();
}

/* CP0 functions */
1014
void op_mfc0_index (void)
B
bellard 已提交
1015
{
T
ths 已提交
1016
    T0 = env->CP0_Index;
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
    RETURN();
}

void op_mfc0_random (void)
{
    CALL_FROM_TB0(do_mfc0_random);
    RETURN();
}

void op_mfc0_entrylo0 (void)
{
T
ths 已提交
1028
    T0 = (int32_t)env->CP0_EntryLo0;
1029 1030 1031 1032 1033
    RETURN();
}

void op_mfc0_entrylo1 (void)
{
T
ths 已提交
1034
    T0 = (int32_t)env->CP0_EntryLo1;
1035 1036 1037 1038 1039
    RETURN();
}

void op_mfc0_context (void)
{
T
ths 已提交
1040
    T0 = (int32_t)env->CP0_Context;
1041 1042 1043 1044 1045
    RETURN();
}

void op_mfc0_pagemask (void)
{
T
ths 已提交
1046
    T0 = env->CP0_PageMask;
1047 1048 1049
    RETURN();
}

1050 1051
void op_mfc0_pagegrain (void)
{
T
ths 已提交
1052
    T0 = env->CP0_PageGrain;
1053 1054 1055
    RETURN();
}

1056 1057
void op_mfc0_wired (void)
{
T
ths 已提交
1058
    T0 = env->CP0_Wired;
1059 1060 1061
    RETURN();
}

1062 1063
void op_mfc0_hwrena (void)
{
T
ths 已提交
1064
    T0 = env->CP0_HWREna;
1065 1066 1067
    RETURN();
}

1068 1069
void op_mfc0_badvaddr (void)
{
T
ths 已提交
1070
    T0 = (int32_t)env->CP0_BadVAddr;
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
    RETURN();
}

void op_mfc0_count (void)
{
    CALL_FROM_TB0(do_mfc0_count);
    RETURN();
}

void op_mfc0_entryhi (void)
{
T
ths 已提交
1082
    T0 = (int32_t)env->CP0_EntryHi;
1083 1084 1085 1086 1087
    RETURN();
}

void op_mfc0_compare (void)
{
T
ths 已提交
1088
    T0 = env->CP0_Compare;
1089 1090 1091 1092 1093
    RETURN();
}

void op_mfc0_status (void)
{
T
ths 已提交
1094
    T0 = env->CP0_Status;
1095 1096 1097
    RETURN();
}

1098 1099
void op_mfc0_intctl (void)
{
T
ths 已提交
1100
    T0 = env->CP0_IntCtl;
1101 1102 1103 1104 1105
    RETURN();
}

void op_mfc0_srsctl (void)
{
T
ths 已提交
1106 1107 1108 1109 1110 1111 1112
    T0 = env->CP0_SRSCtl;
    RETURN();
}

void op_mfc0_srsmap (void)
{
    T0 = env->CP0_SRSMap;
1113 1114 1115
    RETURN();
}

1116 1117
void op_mfc0_cause (void)
{
T
ths 已提交
1118
    T0 = env->CP0_Cause;
1119 1120 1121 1122 1123
    RETURN();
}

void op_mfc0_epc (void)
{
T
ths 已提交
1124
    T0 = (int32_t)env->CP0_EPC;
1125 1126 1127 1128 1129
    RETURN();
}

void op_mfc0_prid (void)
{
T
ths 已提交
1130
    T0 = env->CP0_PRid;
1131 1132 1133
    RETURN();
}

1134 1135
void op_mfc0_ebase (void)
{
1136
    T0 = env->CP0_EBase;
1137 1138 1139
    RETURN();
}

1140 1141
void op_mfc0_config0 (void)
{
T
ths 已提交
1142
    T0 = env->CP0_Config0;
1143 1144 1145 1146 1147
    RETURN();
}

void op_mfc0_config1 (void)
{
T
ths 已提交
1148
    T0 = env->CP0_Config1;
1149 1150 1151
    RETURN();
}

1152 1153
void op_mfc0_config2 (void)
{
T
ths 已提交
1154
    T0 = env->CP0_Config2;
1155 1156 1157 1158 1159
    RETURN();
}

void op_mfc0_config3 (void)
{
T
ths 已提交
1160
    T0 = env->CP0_Config3;
1161 1162 1163
    RETURN();
}

1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
void op_mfc0_config6 (void)
{
    T0 = env->CP0_Config6;
    RETURN();
}

void op_mfc0_config7 (void)
{
    T0 = env->CP0_Config7;
    RETURN();
}

1176 1177
void op_mfc0_lladdr (void)
{
T
ths 已提交
1178
    T0 = (int32_t)env->CP0_LLAddr >> 4;
1179 1180 1181
    RETURN();
}

1182
void op_mfc0_watchlo (void)
1183
{
1184
    T0 = (int32_t)env->CP0_WatchLo[PARAM1];
1185 1186 1187
    RETURN();
}

1188
void op_mfc0_watchhi (void)
1189
{
1190
    T0 = env->CP0_WatchHi[PARAM1];
1191 1192 1193
    RETURN();
}

1194 1195
void op_mfc0_xcontext (void)
{
T
ths 已提交
1196
    T0 = (int32_t)env->CP0_XContext;
1197 1198 1199 1200 1201 1202 1203 1204 1205
    RETURN();
}

void op_mfc0_framemask (void)
{
    T0 = env->CP0_Framemask;
    RETURN();
}

1206 1207
void op_mfc0_debug (void)
{
T
ths 已提交
1208
    T0 = env->CP0_Debug;
1209 1210 1211 1212 1213 1214 1215
    if (env->hflags & MIPS_HFLAG_DM)
        T0 |= 1 << CP0DB_DM;
    RETURN();
}

void op_mfc0_depc (void)
{
T
ths 已提交
1216
    T0 = (int32_t)env->CP0_DEPC;
1217 1218 1219
    RETURN();
}

1220 1221
void op_mfc0_performance0 (void)
{
T
ths 已提交
1222
    T0 = env->CP0_Performance0;
1223 1224 1225
    RETURN();
}

1226 1227
void op_mfc0_taglo (void)
{
T
ths 已提交
1228
    T0 = env->CP0_TagLo;
1229 1230 1231 1232 1233
    RETURN();
}

void op_mfc0_datalo (void)
{
T
ths 已提交
1234
    T0 = env->CP0_DataLo;
1235 1236 1237
    RETURN();
}

1238 1239
void op_mfc0_taghi (void)
{
T
ths 已提交
1240
    T0 = env->CP0_TagHi;
1241 1242 1243 1244 1245
    RETURN();
}

void op_mfc0_datahi (void)
{
T
ths 已提交
1246
    T0 = env->CP0_DataHi;
1247 1248 1249
    RETURN();
}

1250 1251
void op_mfc0_errorepc (void)
{
T
ths 已提交
1252
    T0 = (int32_t)env->CP0_ErrorEPC;
1253 1254 1255 1256 1257
    RETURN();
}

void op_mfc0_desave (void)
{
T
ths 已提交
1258
    T0 = env->CP0_DESAVE;
B
bellard 已提交
1259 1260 1261
    RETURN();
}

1262
void op_mtc0_index (void)
B
bellard 已提交
1263
{
1264
    env->CP0_Index = (env->CP0_Index & 0x80000000) | (T0 % env->nb_tlb);
1265 1266 1267 1268 1269
    RETURN();
}

void op_mtc0_entrylo0 (void)
{
1270 1271
    /* Large physaddr not implemented */
    /* 1k pages not implemented */
1272
    env->CP0_EntryLo0 = T0 & 0x3FFFFFFF;
1273 1274 1275 1276 1277
    RETURN();
}

void op_mtc0_entrylo1 (void)
{
1278 1279
    /* Large physaddr not implemented */
    /* 1k pages not implemented */
1280
    env->CP0_EntryLo1 = T0 & 0x3FFFFFFF;
1281 1282 1283 1284 1285
    RETURN();
}

void op_mtc0_context (void)
{
1286
    env->CP0_Context = (env->CP0_Context & 0x007FFFFF) | (T0 & ~0x007FFFFF);
1287 1288 1289 1290 1291
    RETURN();
}

void op_mtc0_pagemask (void)
{
1292
    /* 1k pages not implemented */
T
ths 已提交
1293
    env->CP0_PageMask = T0 & (0x1FFFFFFF & (TARGET_PAGE_MASK << 1));
1294 1295 1296 1297 1298 1299 1300 1301 1302
    RETURN();
}

void op_mtc0_pagegrain (void)
{
    /* SmartMIPS not implemented */
    /* Large physaddr not implemented */
    /* 1k pages not implemented */
    env->CP0_PageGrain = 0;
1303 1304 1305 1306 1307
    RETURN();
}

void op_mtc0_wired (void)
{
1308
    env->CP0_Wired = T0 % env->nb_tlb;
1309 1310 1311 1312 1313 1314
    RETURN();
}

void op_mtc0_hwrena (void)
{
    env->CP0_HWREna = T0 & 0x0000000F;
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
    RETURN();
}

void op_mtc0_count (void)
{
    CALL_FROM_TB2(cpu_mips_store_count, env, T0);
    RETURN();
}

void op_mtc0_entryhi (void)
{
T
ths 已提交
1326
    target_ulong old, val;
1327

1328
    /* 1k pages not implemented */
1329 1330 1331 1332
    val = T0 & ((TARGET_PAGE_MASK << 1) | 0xFF);
#ifdef TARGET_MIPS64
    val = T0 & 0xC00000FFFFFFFFFFULL;
#endif
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
    old = env->CP0_EntryHi;
    env->CP0_EntryHi = val;
    /* If the ASID changes, flush qemu's TLB.  */
    if ((old & 0xFF) != (val & 0xFF))
        CALL_FROM_TB2(cpu_mips_tlb_flush, env, 1);
    RETURN();
}

void op_mtc0_compare (void)
{
    CALL_FROM_TB2(cpu_mips_store_compare, env, T0);
    RETURN();
}

void op_mtc0_status (void)
{
1349
    uint32_t val, old;
1350
    uint32_t mask = env->Status_rw_bitmask;
1351

1352
    /* No reverse endianness, no MDMX/DSP implemented. */
1353
    val = T0 & mask;
1354
    old = env->CP0_Status;
1355 1356 1357 1358 1359
    if (!(val & (1 << CP0St_EXL)) &&
        !(val & (1 << CP0St_ERL)) &&
        !(env->hflags & MIPS_HFLAG_DM) &&
        (val & (1 << CP0St_UM)))
        env->hflags |= MIPS_HFLAG_UM;
1360 1361 1362 1363 1364 1365
#ifdef TARGET_MIPS64
    if ((env->hflags & MIPS_HFLAG_UM) &&
        !(val & (1 << CP0St_PX)) &&
        !(val & (1 << CP0St_UX)))
        env->hflags &= ~MIPS_HFLAG_64;
#endif
1366 1367 1368 1369 1370 1371 1372 1373
    if (val & (1 << CP0St_CU1))
        env->hflags |= MIPS_HFLAG_FPU;
    else
        env->hflags &= ~MIPS_HFLAG_FPU;
    if (val & (1 << CP0St_FR))
        env->hflags |= MIPS_HFLAG_F64;
    else
        env->hflags &= ~MIPS_HFLAG_F64;
1374
    env->CP0_Status = (env->CP0_Status & ~mask) | val;
1375 1376
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB2(do_mtc0_status_debug, old, val);
1377
    CALL_FROM_TB1(cpu_mips_update_irq, env);
1378 1379 1380
    RETURN();
}

1381 1382
void op_mtc0_intctl (void)
{
T
ths 已提交
1383 1384 1385
    /* vectored interrupts not implemented, timer on int 7,
       no performance counters. */
    env->CP0_IntCtl |= T0 & 0x000002e0;
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
    RETURN();
}

void op_mtc0_srsctl (void)
{
    /* shadow registers not implemented */
    env->CP0_SRSCtl = 0;
    RETURN();
}

T
ths 已提交
1396 1397 1398 1399 1400 1401 1402
void op_mtc0_srsmap (void)
{
    /* shadow registers not implemented */
    env->CP0_SRSMap = 0;
    RETURN();
}

1403 1404
void op_mtc0_cause (void)
{
1405 1406 1407 1408 1409
    uint32_t mask = 0x00C00300;

    if ((env->CP0_Config0 & (0x7 << CP0C0_AR)) == (1 << CP0C0_AR))
        mask |= 1 << CP0Ca_DC;

1410
    env->CP0_Cause = (env->CP0_Cause & ~mask) | (T0 & mask);
1411

1412 1413 1414 1415
    /* Handle the software interrupt as an hardware one, as they
       are very similar */
    if (T0 & CP0Ca_IP_mask) {
        CALL_FROM_TB1(cpu_mips_update_irq, env);
1416 1417 1418 1419 1420 1421
    }
    RETURN();
}

void op_mtc0_epc (void)
{
1422
    env->CP0_EPC = T0;
1423 1424 1425
    RETURN();
}

1426 1427 1428 1429
void op_mtc0_ebase (void)
{
    /* vectored interrupts not implemented */
    /* Multi-CPU not implemented */
1430
    env->CP0_EBase = 0x80000000 | (T0 & 0x3FFFF000);
1431 1432 1433
    RETURN();
}

1434 1435
void op_mtc0_config0 (void)
{
1436
    env->CP0_Config0 = (env->CP0_Config0 & 0x81FFFFF8) | (T0 & 0x00000001);
1437 1438 1439
    RETURN();
}

1440 1441 1442 1443 1444 1445 1446
void op_mtc0_config2 (void)
{
    /* tertiary/secondary caches not implemented */
    env->CP0_Config2 = (env->CP0_Config2 & 0x8FFF0FFF);
    RETURN();
}

1447
void op_mtc0_watchlo (void)
1448
{
T
ths 已提交
1449 1450
    /* Watch exceptions for instructions, data loads, data stores
       not implemented. */
1451
    env->CP0_WatchLo[PARAM1] = (T0 & ~0x7);
1452 1453 1454
    RETURN();
}

1455
void op_mtc0_watchhi (void)
1456
{
1457 1458
    env->CP0_WatchHi[PARAM1] = (T0 & 0x40FF0FF8);
    env->CP0_WatchHi[PARAM1] &= ~(env->CP0_WatchHi[PARAM1] & T0 & 0x7);
1459 1460 1461
    RETURN();
}

1462 1463 1464 1465 1466 1467
void op_mtc0_framemask (void)
{
    env->CP0_Framemask = T0; /* XXX */
    RETURN();
}

1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
void op_mtc0_debug (void)
{
    env->CP0_Debug = (env->CP0_Debug & 0x8C03FC1F) | (T0 & 0x13300120);
    if (T0 & (1 << CP0DB_DM))
        env->hflags |= MIPS_HFLAG_DM;
    else
        env->hflags &= ~MIPS_HFLAG_DM;
    RETURN();
}

void op_mtc0_depc (void)
{
1480
    env->CP0_DEPC = T0;
1481 1482 1483
    RETURN();
}

1484 1485 1486 1487 1488 1489
void op_mtc0_performance0 (void)
{
    env->CP0_Performance0 = T0; /* XXX */
    RETURN();
}

1490 1491
void op_mtc0_taglo (void)
{
T
ths 已提交
1492
    env->CP0_TagLo = T0 & 0xFFFFFCF6;
1493 1494 1495
    RETURN();
}

1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513
void op_mtc0_datalo (void)
{
    env->CP0_DataLo = T0; /* XXX */
    RETURN();
}

void op_mtc0_taghi (void)
{
    env->CP0_TagHi = T0; /* XXX */
    RETURN();
}

void op_mtc0_datahi (void)
{
    env->CP0_DataHi = T0; /* XXX */
    RETURN();
}

1514 1515
void op_mtc0_errorepc (void)
{
1516
    env->CP0_ErrorEPC = T0;
1517 1518 1519 1520 1521 1522
    RETURN();
}

void op_mtc0_desave (void)
{
    env->CP0_DESAVE = T0;
B
bellard 已提交
1523 1524 1525
    RETURN();
}

1526
#ifdef TARGET_MIPS64
1527 1528 1529 1530 1531 1532
void op_mtc0_xcontext (void)
{
    env->CP0_XContext = (env->CP0_XContext & 0x1ffffffffULL) | (T0 & ~0x1ffffffffULL);
    RETURN();
}

T
ths 已提交
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574
void op_dmfc0_entrylo0 (void)
{
    T0 = env->CP0_EntryLo0;
    RETURN();
}

void op_dmfc0_entrylo1 (void)
{
    T0 = env->CP0_EntryLo1;
    RETURN();
}

void op_dmfc0_context (void)
{
    T0 = env->CP0_Context;
    RETURN();
}

void op_dmfc0_badvaddr (void)
{
    T0 = env->CP0_BadVAddr;
    RETURN();
}

void op_dmfc0_entryhi (void)
{
    T0 = env->CP0_EntryHi;
    RETURN();
}

void op_dmfc0_epc (void)
{
    T0 = env->CP0_EPC;
    RETURN();
}

void op_dmfc0_lladdr (void)
{
    T0 = env->CP0_LLAddr >> 4;
    RETURN();
}

1575
void op_dmfc0_watchlo (void)
T
ths 已提交
1576
{
1577
    T0 = env->CP0_WatchLo[PARAM1];
T
ths 已提交
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
    RETURN();
}

void op_dmfc0_xcontext (void)
{
    T0 = env->CP0_XContext;
    RETURN();
}

void op_dmfc0_depc (void)
{
    T0 = env->CP0_DEPC;
    RETURN();
}

void op_dmfc0_errorepc (void)
{
    T0 = env->CP0_ErrorEPC;
    RETURN();
}
1598
#endif /* TARGET_MIPS64 */
T
ths 已提交
1599

1600
/* CP1 functions */
B
bellard 已提交
1601 1602 1603 1604 1605 1606
#if 0
# define DEBUG_FPU_STATE() CALL_FROM_TB1(dump_fpu, env)
#else
# define DEBUG_FPU_STATE() do { } while(0)
#endif

T
ths 已提交
1607 1608 1609 1610
void op_cp0_enabled(void)
{
    if (!(env->CP0_Status & (1 << CP0St_CU0)) &&
	(env->hflags & MIPS_HFLAG_UM)) {
1611
        CALL_FROM_TB2(do_raise_exception_err, EXCP_CpU, 0);
T
ths 已提交
1612 1613 1614 1615
    }
    RETURN();
}

1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
void op_cfc1 (void)
{
    switch (T1) {
    case 0:
        T0 = (int32_t)env->fcr0;
        break;
    case 25:
        T0 = ((env->fcr31 >> 24) & 0xfe) | ((env->fcr31 >> 23) & 0x1);
        break;
    case 26:
        T0 = env->fcr31 & 0x0003f07c;
        break;
    case 28:
        T0 = (env->fcr31 & 0x00000f83) | ((env->fcr31 >> 22) & 0x4);
        break;
    default:
        T0 = (int32_t)env->fcr31;
        break;
    }
    DEBUG_FPU_STATE();
    RETURN();
}

void op_ctc1 (void)
{
1641
    CALL_FROM_TB0(do_ctc1);
B
bellard 已提交
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
    DEBUG_FPU_STATE();
    RETURN();
}

void op_mfc1 (void)
{
    T0 = WT0;
    DEBUG_FPU_STATE();
    RETURN();
}

void op_mtc1 (void)
{
    WT0 = T0;
    DEBUG_FPU_STATE();
    RETURN();
}

1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687
void op_dmfc1 (void)
{
    T0 = DT0;
    DEBUG_FPU_STATE();
    RETURN();
}

void op_dmtc1 (void)
{
    DT0 = T0;
    DEBUG_FPU_STATE();
    RETURN();
}

void op_mfhc1 (void)
{
    T0 = WTH0;
    DEBUG_FPU_STATE();
    RETURN();
}

void op_mthc1 (void)
{
    WTH0 = T0;
    DEBUG_FPU_STATE();
    RETURN();
}

B
bellard 已提交
1688 1689
/* Float support.
   Single precition routines have a "s" suffix, double precision a
1690 1691
   "d" suffix, 32bit integer "w", 64bit integer "l", paired singe "ps",
   paired single lowwer "pl", paired single upper "pu".  */
B
bellard 已提交
1692 1693 1694

#define FLOAT_OP(name, p) void OPPROTO op_float_##name##_##p(void)

1695 1696
FLOAT_OP(cvtd, s)
{
1697
    CALL_FROM_TB0(do_float_cvtd_s);
1698 1699 1700
    DEBUG_FPU_STATE();
    RETURN();
}
B
bellard 已提交
1701 1702
FLOAT_OP(cvtd, w)
{
1703
    CALL_FROM_TB0(do_float_cvtd_w);
1704 1705 1706 1707 1708
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtd, l)
{
1709
    CALL_FROM_TB0(do_float_cvtd_l);
1710 1711 1712 1713 1714
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtl, d)
{
1715
    CALL_FROM_TB0(do_float_cvtl_d);
1716 1717 1718 1719 1720
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtl, s)
{
1721
    CALL_FROM_TB0(do_float_cvtl_s);
1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtps, s)
{
    WT2 = WT0;
    WTH2 = WT1;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtps, pw)
{
1734
    CALL_FROM_TB0(do_float_cvtps_pw);
1735 1736 1737 1738 1739
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtpw, ps)
{
1740
    CALL_FROM_TB0(do_float_cvtpw_ps);
B
bellard 已提交
1741 1742 1743
    DEBUG_FPU_STATE();
    RETURN();
}
1744 1745
FLOAT_OP(cvts, d)
{
1746
    CALL_FROM_TB0(do_float_cvts_d);
1747 1748 1749
    DEBUG_FPU_STATE();
    RETURN();
}
B
bellard 已提交
1750 1751
FLOAT_OP(cvts, w)
{
1752
    CALL_FROM_TB0(do_float_cvts_w);
1753 1754 1755 1756 1757
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvts, l)
{
1758
    CALL_FROM_TB0(do_float_cvts_l);
1759 1760 1761 1762 1763
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvts, pl)
{
1764
    CALL_FROM_TB0(do_float_cvts_pl);
1765 1766 1767 1768 1769
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvts, pu)
{
1770
    CALL_FROM_TB0(do_float_cvts_pu);
B
bellard 已提交
1771 1772 1773 1774 1775
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtw, s)
{
1776
    CALL_FROM_TB0(do_float_cvtw_s);
B
bellard 已提交
1777 1778 1779 1780 1781
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtw, d)
{
1782
    CALL_FROM_TB0(do_float_cvtw_d);
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
    DEBUG_FPU_STATE();
    RETURN();
}

FLOAT_OP(pll, ps)
{
    DT2 = ((uint64_t)WT0 << 32) | WT1;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(plu, ps)
{
    DT2 = ((uint64_t)WT0 << 32) | WTH1;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(pul, ps)
{
    DT2 = ((uint64_t)WTH0 << 32) | WT1;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(puu, ps)
{
    DT2 = ((uint64_t)WTH0 << 32) | WTH1;
B
bellard 已提交
1808 1809 1810 1811
    DEBUG_FPU_STATE();
    RETURN();
}

1812 1813 1814 1815 1816 1817
#define FLOAT_ROUNDOP(op, ttype, stype)                    \
FLOAT_OP(op ## ttype, stype)                               \
{                                                          \
    CALL_FROM_TB0(do_float_ ## op ## ttype ## _ ## stype); \
    DEBUG_FPU_STATE();                                     \
    RETURN();                                              \
B
bellard 已提交
1818 1819
}

1820 1821 1822 1823
FLOAT_ROUNDOP(round, l, d)
FLOAT_ROUNDOP(round, l, s)
FLOAT_ROUNDOP(round, w, d)
FLOAT_ROUNDOP(round, w, s)
B
bellard 已提交
1824

1825 1826 1827 1828
FLOAT_ROUNDOP(trunc, l, d)
FLOAT_ROUNDOP(trunc, l, s)
FLOAT_ROUNDOP(trunc, w, d)
FLOAT_ROUNDOP(trunc, w, s)
B
bellard 已提交
1829

1830 1831 1832 1833 1834 1835 1836 1837 1838 1839
FLOAT_ROUNDOP(ceil, l, d)
FLOAT_ROUNDOP(ceil, l, s)
FLOAT_ROUNDOP(ceil, w, d)
FLOAT_ROUNDOP(ceil, w, s)

FLOAT_ROUNDOP(floor, l, d)
FLOAT_ROUNDOP(floor, l, s)
FLOAT_ROUNDOP(floor, w, d)
FLOAT_ROUNDOP(floor, w, s)
#undef FLOAR_ROUNDOP
B
bellard 已提交
1840

1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933
FLOAT_OP(movf, d)
{
    if (!(env->fcr31 & PARAM1))
        DT2 = DT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movf, s)
{
    if (!(env->fcr31 & PARAM1))
        WT2 = WT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movf, ps)
{
    if (!(env->fcr31 & PARAM1)) {
        WT2 = WT0;
        WTH2 = WTH0;
    }
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movt, d)
{
    if (env->fcr31 & PARAM1)
        DT2 = DT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movt, s)
{
    if (env->fcr31 & PARAM1)
        WT2 = WT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movt, ps)
{
    if (env->fcr31 & PARAM1) {
        WT2 = WT0;
        WTH2 = WTH0;
    }
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movz, d)
{
    if (!T0)
        DT2 = DT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movz, s)
{
    if (!T0)
        WT2 = WT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movz, ps)
{
    if (!T0) {
        WT2 = WT0;
        WTH2 = WTH0;
    }
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movn, d)
{
    if (T0)
        DT2 = DT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movn, s)
{
    if (T0)
        WT2 = WT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movn, ps)
{
    if (T0) {
        WT2 = WT0;
        WTH2 = WTH0;
    }
    DEBUG_FPU_STATE();
    RETURN();
}

T
ths 已提交
1934 1935
/* operations calling helpers, for s, d and ps */
#define FLOAT_HOP(name) \
B
bellard 已提交
1936 1937
FLOAT_OP(name, d)         \
{                         \
1938
    CALL_FROM_TB0(do_float_ ## name ## _d);  \
B
bellard 已提交
1939
    DEBUG_FPU_STATE();    \
1940
    RETURN();             \
B
bellard 已提交
1941 1942 1943
}                         \
FLOAT_OP(name, s)         \
{                         \
1944
    CALL_FROM_TB0(do_float_ ## name ## _s);  \
1945
    DEBUG_FPU_STATE();    \
1946
    RETURN();             \
1947 1948 1949
}                         \
FLOAT_OP(name, ps)        \
{                         \
1950
    CALL_FROM_TB0(do_float_ ## name ## _ps); \
B
bellard 已提交
1951
    DEBUG_FPU_STATE();    \
1952
    RETURN();             \
B
bellard 已提交
1953
}
T
ths 已提交
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
FLOAT_HOP(add)
FLOAT_HOP(sub)
FLOAT_HOP(mul)
FLOAT_HOP(div)
FLOAT_HOP(recip2)
FLOAT_HOP(rsqrt2)
FLOAT_HOP(rsqrt1)
FLOAT_HOP(recip1)
#undef FLOAT_HOP

/* operations calling helpers, for s and d */
#define FLOAT_HOP(name)   \
FLOAT_OP(name, d)         \
{                         \
    CALL_FROM_TB0(do_float_ ## name ## _d);  \
    DEBUG_FPU_STATE();    \
    RETURN();             \
}                         \
FLOAT_OP(name, s)         \
{                         \
    CALL_FROM_TB0(do_float_ ## name ## _s);  \
    DEBUG_FPU_STATE();    \
    RETURN();             \
}
FLOAT_HOP(rsqrt)
FLOAT_HOP(recip)
#undef FLOAT_HOP
B
bellard 已提交
1981

T
ths 已提交
1982 1983 1984 1985 1986 1987 1988
/* operations calling helpers, for ps */
#define FLOAT_HOP(name)   \
FLOAT_OP(name, ps)        \
{                         \
    CALL_FROM_TB0(do_float_ ## name ## _ps); \
    DEBUG_FPU_STATE();    \
    RETURN();             \
1989
}
T
ths 已提交
1990 1991 1992
FLOAT_HOP(addr)
FLOAT_HOP(mulr)
#undef FLOAT_HOP
1993

1994 1995 1996 1997 1998 1999 2000
/* ternary operations */
#define FLOAT_TERNOP(name1, name2) \
FLOAT_OP(name1 ## name2, d)        \
{                                  \
    FDT0 = float64_ ## name1 (FDT0, FDT1, &env->fp_status);    \
    FDT2 = float64_ ## name2 (FDT0, FDT2, &env->fp_status);    \
    DEBUG_FPU_STATE();             \
2001
    RETURN();                      \
2002 2003 2004 2005 2006 2007
}                                  \
FLOAT_OP(name1 ## name2, s)        \
{                                  \
    FST0 = float32_ ## name1 (FST0, FST1, &env->fp_status);    \
    FST2 = float32_ ## name2 (FST0, FST2, &env->fp_status);    \
    DEBUG_FPU_STATE();             \
2008
    RETURN();                      \
2009 2010 2011 2012 2013 2014 2015 2016
}                                  \
FLOAT_OP(name1 ## name2, ps)       \
{                                  \
    FST0 = float32_ ## name1 (FST0, FST1, &env->fp_status);    \
    FSTH0 = float32_ ## name1 (FSTH0, FSTH1, &env->fp_status); \
    FST2 = float32_ ## name2 (FST0, FST2, &env->fp_status);    \
    FSTH2 = float32_ ## name2 (FSTH0, FSTH2, &env->fp_status); \
    DEBUG_FPU_STATE();             \
2017
    RETURN();                      \
2018 2019 2020 2021 2022
}
FLOAT_TERNOP(mul, add)
FLOAT_TERNOP(mul, sub)
#undef FLOAT_TERNOP

2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055
/* negated ternary operations */
#define FLOAT_NTERNOP(name1, name2) \
FLOAT_OP(n ## name1 ## name2, d)    \
{                                   \
    FDT0 = float64_ ## name1 (FDT0, FDT1, &env->fp_status);    \
    FDT2 = float64_ ## name2 (FDT0, FDT2, &env->fp_status);    \
    FDT2 ^= 1ULL << 63;             \
    DEBUG_FPU_STATE();              \
    RETURN();                       \
}                                   \
FLOAT_OP(n ## name1 ## name2, s)    \
{                                   \
    FST0 = float32_ ## name1 (FST0, FST1, &env->fp_status);    \
    FST2 = float32_ ## name2 (FST0, FST2, &env->fp_status);    \
    FST2 ^= 1 << 31;                \
    DEBUG_FPU_STATE();              \
    RETURN();                       \
}                                   \
FLOAT_OP(n ## name1 ## name2, ps)   \
{                                   \
    FST0 = float32_ ## name1 (FST0, FST1, &env->fp_status);    \
    FSTH0 = float32_ ## name1 (FSTH0, FSTH1, &env->fp_status); \
    FST2 = float32_ ## name2 (FST0, FST2, &env->fp_status);    \
    FSTH2 = float32_ ## name2 (FSTH0, FSTH2, &env->fp_status); \
    FST2 ^= 1 << 31;                \
    FSTH2 ^= 1 << 31;               \
    DEBUG_FPU_STATE();              \
    RETURN();                       \
}
FLOAT_NTERNOP(mul, add)
FLOAT_NTERNOP(mul, sub)
#undef FLOAT_NTERNOP

B
bellard 已提交
2056 2057 2058 2059 2060 2061
/* unary operations, modifying fp status  */
#define FLOAT_UNOP(name)  \
FLOAT_OP(name, d)         \
{                         \
    FDT2 = float64_ ## name(FDT0, &env->fp_status);   \
    DEBUG_FPU_STATE();    \
2062
    RETURN();                      \
B
bellard 已提交
2063 2064 2065 2066 2067
}                         \
FLOAT_OP(name, s)         \
{                         \
    FST2 = float32_ ## name(FST0, &env->fp_status);   \
    DEBUG_FPU_STATE();    \
T
ths 已提交
2068
    RETURN();             \
B
bellard 已提交
2069 2070 2071 2072 2073 2074 2075 2076 2077 2078
}
FLOAT_UNOP(sqrt)
#undef FLOAT_UNOP

/* unary operations, not modifying fp status  */
#define FLOAT_UNOP(name)  \
FLOAT_OP(name, d)         \
{                         \
    FDT2 = float64_ ## name(FDT0);   \
    DEBUG_FPU_STATE();    \
2079
    RETURN();             \
B
bellard 已提交
2080 2081 2082 2083 2084
}                         \
FLOAT_OP(name, s)         \
{                         \
    FST2 = float32_ ## name(FST0);   \
    DEBUG_FPU_STATE();    \
2085
    RETURN();             \
2086 2087 2088 2089 2090 2091
}                         \
FLOAT_OP(name, ps)        \
{                         \
    FST2 = float32_ ## name(FST0);   \
    FSTH2 = float32_ ## name(FSTH0); \
    DEBUG_FPU_STATE();    \
2092
    RETURN();             \
B
bellard 已提交
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109
}
FLOAT_UNOP(abs)
FLOAT_UNOP(chs)
#undef FLOAT_UNOP

FLOAT_OP(mov, d)
{
    FDT2 = FDT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(mov, s)
{
    FST2 = FST0;
    DEBUG_FPU_STATE();
    RETURN();
}
2110 2111 2112 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
FLOAT_OP(mov, ps)
{
    FST2 = FST0;
    FSTH2 = FSTH0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(alnv, ps)
{
    switch (T0 & 0x7) {
    case 0:
        FST2 = FST0;
        FSTH2 = FSTH0;
        break;
    case 4:
#ifdef TARGET_WORDS_BIGENDIAN
        FSTH2 = FST0;
        FST2 = FSTH1;
#else
        FSTH2 = FST1;
        FST2 = FSTH0;
#endif
        break;
    default: /* unpredictable */
        break;
    }
    DEBUG_FPU_STATE();
    RETURN();
}
B
bellard 已提交
2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151

#ifdef CONFIG_SOFTFLOAT
#define clear_invalid() do {                                \
    int flags = get_float_exception_flags(&env->fp_status); \
    flags &= ~float_flag_invalid;                           \
    set_float_exception_flags(flags, &env->fp_status);      \
} while(0)
#else
#define clear_invalid() do { } while(0)
#endif

extern void dump_fpu_s(CPUState *env);

2152 2153 2154 2155 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
#define CMP_OP(fmt, op)                                \
void OPPROTO op_cmp ## _ ## fmt ## _ ## op(void)       \
{                                                      \
    CALL_FROM_TB1(do_cmp ## _ ## fmt ## _ ## op, PARAM1); \
    DEBUG_FPU_STATE();                                 \
    RETURN();                                          \
}                                                      \
void OPPROTO op_cmpabs ## _ ## fmt ## _ ## op(void)    \
{                                                      \
    CALL_FROM_TB1(do_cmpabs ## _ ## fmt ## _ ## op, PARAM1); \
    DEBUG_FPU_STATE();                                 \
    RETURN();                                          \
}
#define CMP_OPS(op)   \
CMP_OP(d, op)         \
CMP_OP(s, op)         \
CMP_OP(ps, op)

CMP_OPS(f)
CMP_OPS(un)
CMP_OPS(eq)
CMP_OPS(ueq)
CMP_OPS(olt)
CMP_OPS(ult)
CMP_OPS(ole)
CMP_OPS(ule)
CMP_OPS(sf)
CMP_OPS(ngle)
CMP_OPS(seq)
CMP_OPS(ngl)
CMP_OPS(lt)
CMP_OPS(nge)
CMP_OPS(le)
CMP_OPS(ngt)
#undef CMP_OPS
#undef CMP_OP
B
bellard 已提交
2188 2189 2190

void op_bc1f (void)
{
2191
    T0 = !!(~GET_FP_COND(env) & (0x1 << PARAM1));
2192 2193 2194
    DEBUG_FPU_STATE();
    RETURN();
}
2195
void op_bc1any2f (void)
2196
{
2197
    T0 = !!(~GET_FP_COND(env) & (0x3 << PARAM1));
2198 2199 2200
    DEBUG_FPU_STATE();
    RETURN();
}
2201
void op_bc1any4f (void)
2202
{
2203
    T0 = !!(~GET_FP_COND(env) & (0xf << PARAM1));
B
bellard 已提交
2204 2205 2206 2207 2208 2209
    DEBUG_FPU_STATE();
    RETURN();
}

void op_bc1t (void)
{
2210
    T0 = !!(GET_FP_COND(env) & (0x1 << PARAM1));
2211 2212 2213
    DEBUG_FPU_STATE();
    RETURN();
}
2214
void op_bc1any2t (void)
2215
{
2216
    T0 = !!(GET_FP_COND(env) & (0x3 << PARAM1));
2217 2218 2219
    DEBUG_FPU_STATE();
    RETURN();
}
2220
void op_bc1any4t (void)
2221
{
2222
    T0 = !!(GET_FP_COND(env) & (0xf << PARAM1));
B
bellard 已提交
2223 2224 2225 2226
    DEBUG_FPU_STATE();
    RETURN();
}

B
bellard 已提交
2227 2228
void op_tlbwi (void)
{
2229
    CALL_FROM_TB0(env->do_tlbwi);
B
bellard 已提交
2230 2231 2232 2233 2234
    RETURN();
}

void op_tlbwr (void)
{
2235
    CALL_FROM_TB0(env->do_tlbwr);
B
bellard 已提交
2236 2237 2238 2239 2240
    RETURN();
}

void op_tlbp (void)
{
2241
    CALL_FROM_TB0(env->do_tlbp);
B
bellard 已提交
2242 2243 2244 2245 2246
    RETURN();
}

void op_tlbr (void)
{
2247
    CALL_FROM_TB0(env->do_tlbr);
B
bellard 已提交
2248 2249 2250 2251
    RETURN();
}

/* Specials */
2252 2253 2254
#if defined (CONFIG_USER_ONLY)
void op_tls_value (void)
{
2255
    T0 = env->tls_value;
2256 2257 2258
}
#endif

B
bellard 已提交
2259 2260 2261
void op_pmon (void)
{
    CALL_FROM_TB1(do_pmon, PARAM1);
2262 2263 2264 2265 2266 2267
    RETURN();
}

void op_di (void)
{
    T0 = env->CP0_Status;
2268 2269
    env->CP0_Status = T0 & ~(1 << CP0St_IE);
    CALL_FROM_TB1(cpu_mips_update_irq, env);
2270 2271 2272 2273 2274 2275
    RETURN();
}

void op_ei (void)
{
    T0 = env->CP0_Status;
2276 2277
    env->CP0_Status = T0 | (1 << CP0St_IE);
    CALL_FROM_TB1(cpu_mips_update_irq, env);
2278
    RETURN();
B
bellard 已提交
2279 2280 2281 2282 2283
}

void op_trap (void)
{
    if (T0) {
2284
        CALL_FROM_TB1(do_raise_exception, EXCP_TRAP);
B
bellard 已提交
2285 2286 2287 2288
    }
    RETURN();
}

B
bellard 已提交
2289 2290
void op_debug (void)
{
2291 2292
    CALL_FROM_TB1(do_raise_exception, EXCP_DEBUG);
    RETURN();
B
bellard 已提交
2293 2294
}

B
bellard 已提交
2295 2296 2297
void op_set_lladdr (void)
{
    env->CP0_LLAddr = T2;
2298
    RETURN();
B
bellard 已提交
2299 2300
}

2301 2302
void debug_pre_eret (void);
void debug_post_eret (void);
B
bellard 已提交
2303 2304
void op_eret (void)
{
2305 2306
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB0(debug_pre_eret);
T
ths 已提交
2307
    if (env->CP0_Status & (1 << CP0St_ERL)) {
B
bellard 已提交
2308
        env->PC = env->CP0_ErrorEPC;
T
ths 已提交
2309
        env->CP0_Status &= ~(1 << CP0St_ERL);
B
bellard 已提交
2310
    } else {
B
bellard 已提交
2311
        env->PC = env->CP0_EPC;
T
ths 已提交
2312
        env->CP0_Status &= ~(1 << CP0St_EXL);
B
bellard 已提交
2313
    }
T
ths 已提交
2314 2315 2316 2317 2318
    if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
        !(env->CP0_Status & (1 << CP0St_ERL)) &&
        !(env->hflags & MIPS_HFLAG_DM) &&
        (env->CP0_Status & (1 << CP0St_UM)))
        env->hflags |= MIPS_HFLAG_UM;
2319 2320 2321 2322 2323 2324
#ifdef TARGET_MIPS64
    if ((env->hflags & MIPS_HFLAG_UM) &&
        !(env->CP0_Status & (1 << CP0St_PX)) &&
        !(env->CP0_Status & (1 << CP0St_UX)))
        env->hflags &= ~MIPS_HFLAG_64;
#endif
2325 2326
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB0(debug_post_eret);
B
bellard 已提交
2327
    env->CP0_LLAddr = 1;
2328
    RETURN();
B
bellard 已提交
2329 2330 2331 2332
}

void op_deret (void)
{
2333 2334
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB0(debug_pre_eret);
B
bellard 已提交
2335
    env->PC = env->CP0_DEPC;
T
ths 已提交
2336 2337 2338 2339 2340 2341
    env->hflags |= MIPS_HFLAG_DM;
    if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
        !(env->CP0_Status & (1 << CP0St_ERL)) &&
        !(env->hflags & MIPS_HFLAG_DM) &&
        (env->CP0_Status & (1 << CP0St_UM)))
        env->hflags |= MIPS_HFLAG_UM;
2342 2343 2344 2345 2346 2347
#ifdef TARGET_MIPS64
    if ((env->hflags & MIPS_HFLAG_UM) &&
        !(env->CP0_Status & (1 << CP0St_PX)) &&
        !(env->CP0_Status & (1 << CP0St_UX)))
        env->hflags &= ~MIPS_HFLAG_64;
#endif
2348 2349
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB0(debug_post_eret);
T
ths 已提交
2350
    env->CP0_LLAddr = 1;
2351 2352 2353 2354 2355
    RETURN();
}

void op_rdhwr_cpunum(void)
{
2356
    if (!(env->hflags & MIPS_HFLAG_UM) ||
2357
        (env->CP0_HWREna & (1 << 0)) ||
2358 2359
        (env->CP0_Status & (1 << CP0St_CU0)))
        T0 = env->CP0_EBase & 0x3ff;
2360
    else
2361
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
2362 2363 2364 2365 2366
    RETURN();
}

void op_rdhwr_synci_step(void)
{
2367
    if (!(env->hflags & MIPS_HFLAG_UM) ||
2368
        (env->CP0_HWREna & (1 << 1)) ||
2369 2370
        (env->CP0_Status & (1 << CP0St_CU0)))
        T0 = env->SYNCI_Step;
2371
    else
2372
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
2373 2374 2375 2376 2377
    RETURN();
}

void op_rdhwr_cc(void)
{
2378
    if (!(env->hflags & MIPS_HFLAG_UM) ||
2379
        (env->CP0_HWREna & (1 << 2)) ||
2380 2381
        (env->CP0_Status & (1 << CP0St_CU0)))
        T0 = env->CP0_Count;
2382
    else
2383
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
2384 2385 2386 2387 2388
    RETURN();
}

void op_rdhwr_ccres(void)
{
2389
    if (!(env->hflags & MIPS_HFLAG_UM) ||
2390
        (env->CP0_HWREna & (1 << 3)) ||
2391 2392
        (env->CP0_Status & (1 << CP0St_CU0)))
        T0 = env->CCRes;
2393
    else
2394 2395 2396 2397
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
    RETURN();
}

B
bellard 已提交
2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
void op_save_state (void)
{
    env->hflags = PARAM1;
    RETURN();
}

void op_save_pc (void)
{
    env->PC = PARAM1;
    RETURN();
}

2410 2411 2412 2413 2414 2415 2416 2417
#ifdef TARGET_MIPS64
void op_save_pc64 (void)
{
    env->PC = ((uint64_t)PARAM1 << 32) | (uint32_t)PARAM2;
    RETURN();
}
#endif

T
ths 已提交
2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430
void op_interrupt_restart (void)
{
    if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
        !(env->CP0_Status & (1 << CP0St_ERL)) &&
        !(env->hflags & MIPS_HFLAG_DM) &&
        (env->CP0_Status & (1 << CP0St_IE)) &&
        (env->CP0_Status & env->CP0_Cause & CP0Ca_IP_mask)) {
        env->CP0_Cause &= ~(0x1f << CP0Ca_EC);
        CALL_FROM_TB1(do_raise_exception, EXCP_EXT_INTERRUPT);
    }
    RETURN();
}

B
bellard 已提交
2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445
void op_raise_exception (void)
{
    CALL_FROM_TB1(do_raise_exception, PARAM1);
    RETURN();
}

void op_raise_exception_err (void)
{
    CALL_FROM_TB2(do_raise_exception_err, PARAM1, PARAM2);
    RETURN();
}

void op_exit_tb (void)
{
    EXIT_TB();
2446
    RETURN();
B
bellard 已提交
2447 2448
}

B
bellard 已提交
2449 2450 2451 2452
void op_wait (void)
{
    env->halted = 1;
    CALL_FROM_TB1(do_raise_exception, EXCP_HLT);
2453 2454 2455 2456 2457 2458 2459 2460 2461
    RETURN();
}

/* Bitfield operations. */
void op_ext(void)
{
    unsigned int pos = PARAM1;
    unsigned int size = PARAM2;

T
ths 已提交
2462
    T0 = ((uint32_t)T1 >> pos) & ((size < 32) ? ((1 << size) - 1) : ~0);
2463 2464 2465 2466 2467 2468 2469
    RETURN();
}

void op_ins(void)
{
    unsigned int pos = PARAM1;
    unsigned int size = PARAM2;
T
ths 已提交
2470
    target_ulong mask = ((size < 32) ? ((1 << size) - 1) : ~0) << pos;
2471

2472
    T0 = (T0 & ~mask) | (((uint32_t)T1 << pos) & mask);
2473 2474 2475 2476 2477 2478 2479 2480 2481
    RETURN();
}

void op_wsbh(void)
{
    T0 = ((T1 << 8) & ~0x00FF00FF) | ((T1 >> 8) & 0x00FF00FF);
    RETURN();
}

T
ths 已提交
2482
#ifdef TARGET_MIPS64
2483 2484 2485 2486 2487
void op_dext(void)
{
    unsigned int pos = PARAM1;
    unsigned int size = PARAM2;

T
ths 已提交
2488
    T0 = (T1 >> pos) & ((size < 32) ? ((1 << size) - 1) : ~0);
2489 2490 2491 2492 2493 2494 2495
    RETURN();
}

void op_dins(void)
{
    unsigned int pos = PARAM1;
    unsigned int size = PARAM2;
T
ths 已提交
2496
    target_ulong mask = ((size < 32) ? ((1 << size) - 1) : ~0) << pos;
2497

2498
    T0 = (T0 & ~mask) | ((T1 << pos) & mask);
2499 2500 2501
    RETURN();
}

2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512
void op_dsbh(void)
{
    T0 = ((T1 << 8) & ~0x00FF00FF00FF00FFULL) | ((T1 >> 8) & 0x00FF00FF00FF00FFULL);
    RETURN();
}

void op_dshd(void)
{
    T0 = ((T1 << 16) & ~0x0000FFFF0000FFFFULL) | ((T1 >> 16) & 0x0000FFFF0000FFFFULL);
    RETURN();
}
2513
#endif
2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524

void op_seb(void)
{
    T0 = ((T1 & 0xFF) ^ 0x80) - 0x80;
    RETURN();
}

void op_seh(void)
{
    T0 = ((T1 & 0xFFFF) ^ 0x8000) - 0x8000;
    RETURN();
B
bellard 已提交
2525
}