op.c 57.7 KB
Newer Older
B
bellard 已提交
1 2
/*
 *  MIPS emulation micro-operations for qemu.
3
 *
B
bellard 已提交
4
 *  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
void op_dup_T0 (void)
{
    T2 = T0;
    RETURN();
}

void op_load_HI (void)
{
257
    T0 = env->HI[PARAM1][env->current_tc];
B
bellard 已提交
258 259 260 261 262
    RETURN();
}

void op_store_HI (void)
{
263
    env->HI[PARAM1][env->current_tc] = T0;
B
bellard 已提交
264 265 266 267 268
    RETURN();
}

void op_load_LO (void)
{
269
    T0 = env->LO[PARAM1][env->current_tc];
B
bellard 已提交
270 271 272 273 274
    RETURN();
}

void op_store_LO (void)
{
275
    env->LO[PARAM1][env->current_tc] = T0;
B
bellard 已提交
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
    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
/* 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
300
    if ((env->hflags & MIPS_HFLAG_UM) &&
301 302 303 304 305 306 307 308
        !(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[0][env->current_tc] = (int32_t)((int64_t)(int32_t)T0 / (int32_t)T1);
        env->HI[0][env->current_tc] = (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) {
376 377
        env->LO[0][env->current_tc] = (int32_t)((uint32_t)T0 / (uint32_t)T1);
        env->HI[0][env->current_tc] = (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
{
    if (T1 != 0) {
445 446
        env->LO[0][env->current_tc] = T0 / T1;
        env->HI[0][env->current_tc] = T0 % T1;
B
bellard 已提交
447 448 449
    }
    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

#else /* TARGET_LONG_BITS > HOST_LONG_BITS */

static inline uint64_t get_HILO (void)
{
817 818
    return ((uint64_t)env->HI[0][env->current_tc] << 32) |
            ((uint64_t)(uint32_t)env->LO[0][env->current_tc]);
819 820 821 822
}

static inline void set_HILO (uint64_t HILO)
{
823 824
    env->LO[0][env->current_tc] = (int32_t)(HILO & 0xFFFFFFFF);
    env->HI[0][env->current_tc] = (int32_t)(HILO >> 32);
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 875
}

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 已提交
876
#ifdef TARGET_MIPS64
877 878
void op_dmult (void)
{
879
    CALL_FROM_TB4(muls64, &(env->HI[0][env->current_tc]), &(env->LO[0][env->current_tc]), T0, T1);
880 881 882 883 884
    RETURN();
}

void op_dmultu (void)
{
885
    CALL_FROM_TB4(mulu64, &(env->HI[0][env->current_tc]), &(env->LO[0][env->current_tc]), T0, T1);
886 887
    RETURN();
}
B
bellard 已提交
888 889 890 891 892 893
#endif

/* Conditional moves */
void op_movn (void)
{
    if (T1 != 0)
894
        env->gpr[PARAM1][env->current_tc] = T0;
B
bellard 已提交
895 896 897 898 899 900
    RETURN();
}

void op_movz (void)
{
    if (T1 == 0)
901
        env->gpr[PARAM1][env->current_tc] = T0;
B
bellard 已提交
902 903 904
    RETURN();
}

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

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

B
bellard 已提交
919 920 921 922 923 924 925 926 927 928 929 930 931 932
/* 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);
933
OP_COND(ge, (target_long)T0 >= (target_long)T1);
B
bellard 已提交
934
OP_COND(geu, T0 >= T1);
935
OP_COND(lt, (target_long)T0 < (target_long)T1);
B
bellard 已提交
936
OP_COND(ltu, T0 < T1);
937 938 939 940
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 已提交
941

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

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

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

void op_restore_breg_target (void)
{
    T2 = env->btarget;
965
    RETURN();
B
bellard 已提交
966 967 968 969
}

void op_breg (void)
{
970
    env->PC[env->current_tc] = T2;
B
bellard 已提交
971 972 973 974 975 976 977 978 979
    RETURN();
}

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

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

B
bellard 已提交
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
/* 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 已提交
1007
void op_jnz_T2 (void)
B
bellard 已提交
1008
{
B
bellard 已提交
1009 1010
    if (T2)
        GOTO_LABEL_PARAM(1);
B
bellard 已提交
1011 1012 1013 1014
    RETURN();
}

/* CP0 functions */
1015
void op_mfc0_index (void)
B
bellard 已提交
1016
{
T
ths 已提交
1017
    T0 = env->CP0_Index;
1018 1019 1020
    RETURN();
}

1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
void op_mfc0_mvpcontrol (void)
{
    T0 = env->mvp->CP0_MVPControl;
    RETURN();
}

void op_mfc0_mvpconf0 (void)
{
    T0 = env->mvp->CP0_MVPConf0;
    RETURN();
}

void op_mfc0_mvpconf1 (void)
{
    T0 = env->mvp->CP0_MVPConf1;
    RETURN();
}

1039 1040 1041 1042 1043 1044
void op_mfc0_random (void)
{
    CALL_FROM_TB0(do_mfc0_random);
    RETURN();
}

1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
void op_mfc0_vpecontrol (void)
{
    T0 = env->CP0_VPEControl;
    RETURN();
}

void op_mfc0_vpeconf0 (void)
{
    T0 = env->CP0_VPEConf0;
    RETURN();
}

void op_mfc0_vpeconf1 (void)
{
    T0 = env->CP0_VPEConf1;
    RETURN();
}

void op_mfc0_yqmask (void)
{
    T0 = env->CP0_YQMask;
    RETURN();
}

void op_mfc0_vpeschedule (void)
{
    T0 = env->CP0_VPESchedule;
    RETURN();
}

void op_mfc0_vpeschefback (void)
{
    T0 = env->CP0_VPEScheFBack;
    RETURN();
}

void op_mfc0_vpeopt (void)
{
    T0 = env->CP0_VPEOpt;
    RETURN();
}

1087 1088
void op_mfc0_entrylo0 (void)
{
T
ths 已提交
1089
    T0 = (int32_t)env->CP0_EntryLo0;
1090 1091 1092
    RETURN();
}

1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
void op_mfc0_tcstatus (void)
{
    T0 = env->CP0_TCStatus[env->current_tc];
    RETURN();
}

void op_mftc0_tcstatus(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->CP0_TCStatus[other_tc];
    RETURN();
}

void op_mfc0_tcbind (void)
{
    T0 = env->CP0_TCBind[env->current_tc];
    RETURN();
}

void op_mftc0_tcbind(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->CP0_TCBind[other_tc];
    RETURN();
}

void op_mfc0_tcrestart (void)
{
    T0 = env->PC[env->current_tc];
    RETURN();
}

void op_mftc0_tcrestart(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->PC[other_tc];
    RETURN();
}

void op_mfc0_tchalt (void)
{
    T0 = env->CP0_TCHalt[env->current_tc];
    RETURN();
}

void op_mftc0_tchalt(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->CP0_TCHalt[other_tc];
    RETURN();
}

void op_mfc0_tccontext (void)
{
    T0 = env->CP0_TCContext[env->current_tc];
    RETURN();
}

void op_mftc0_tccontext(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->CP0_TCContext[other_tc];
    RETURN();
}

void op_mfc0_tcschedule (void)
{
    T0 = env->CP0_TCSchedule[env->current_tc];
    RETURN();
}

void op_mftc0_tcschedule(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->CP0_TCSchedule[other_tc];
    RETURN();
}

void op_mfc0_tcschefback (void)
{
    T0 = env->CP0_TCScheFBack[env->current_tc];
    RETURN();
}

void op_mftc0_tcschefback(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->CP0_TCScheFBack[other_tc];
    RETURN();
}

1191 1192
void op_mfc0_entrylo1 (void)
{
T
ths 已提交
1193
    T0 = (int32_t)env->CP0_EntryLo1;
1194 1195 1196 1197 1198
    RETURN();
}

void op_mfc0_context (void)
{
T
ths 已提交
1199
    T0 = (int32_t)env->CP0_Context;
1200 1201 1202 1203 1204
    RETURN();
}

void op_mfc0_pagemask (void)
{
T
ths 已提交
1205
    T0 = env->CP0_PageMask;
1206 1207 1208
    RETURN();
}

1209 1210
void op_mfc0_pagegrain (void)
{
T
ths 已提交
1211
    T0 = env->CP0_PageGrain;
1212 1213 1214
    RETURN();
}

1215 1216
void op_mfc0_wired (void)
{
T
ths 已提交
1217
    T0 = env->CP0_Wired;
1218 1219 1220
    RETURN();
}

1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
void op_mfc0_srsconf0 (void)
{
    T0 = env->CP0_SRSConf0;
    RETURN();
}

void op_mfc0_srsconf1 (void)
{
    T0 = env->CP0_SRSConf1;
    RETURN();
}

void op_mfc0_srsconf2 (void)
{
    T0 = env->CP0_SRSConf2;
    RETURN();
}

void op_mfc0_srsconf3 (void)
{
    T0 = env->CP0_SRSConf3;
    RETURN();
}

void op_mfc0_srsconf4 (void)
{
    T0 = env->CP0_SRSConf4;
    RETURN();
}

1251 1252
void op_mfc0_hwrena (void)
{
T
ths 已提交
1253
    T0 = env->CP0_HWREna;
1254 1255 1256
    RETURN();
}

1257 1258
void op_mfc0_badvaddr (void)
{
T
ths 已提交
1259
    T0 = (int32_t)env->CP0_BadVAddr;
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
    RETURN();
}

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

void op_mfc0_entryhi (void)
{
T
ths 已提交
1271
    T0 = (int32_t)env->CP0_EntryHi;
1272 1273 1274
    RETURN();
}

1275 1276 1277 1278 1279 1280 1281 1282
void op_mftc0_entryhi(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = (env->CP0_EntryHi & ~0xff) | (env->CP0_TCStatus[other_tc] & 0xff);
    RETURN();
}

1283 1284
void op_mfc0_compare (void)
{
T
ths 已提交
1285
    T0 = env->CP0_Compare;
1286 1287 1288 1289 1290
    RETURN();
}

void op_mfc0_status (void)
{
T
ths 已提交
1291
    T0 = env->CP0_Status;
1292 1293 1294
    RETURN();
}

1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
void op_mftc0_status(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
    uint32_t tcstatus = env->CP0_TCStatus[other_tc];

    T0 = env->CP0_Status & ~0xf1000018;
    T0 |= tcstatus & (0xf << CP0TCSt_TCU0);
    T0 |= (tcstatus & (1 << CP0TCSt_TMX)) >> (CP0TCSt_TMX - CP0St_MX);
    T0 |= (tcstatus & (0x3 << CP0TCSt_TKSU)) >> (CP0TCSt_TKSU - CP0St_R0);
    RETURN();
}

1307 1308
void op_mfc0_intctl (void)
{
T
ths 已提交
1309
    T0 = env->CP0_IntCtl;
1310 1311 1312 1313 1314
    RETURN();
}

void op_mfc0_srsctl (void)
{
T
ths 已提交
1315 1316 1317 1318 1319 1320 1321
    T0 = env->CP0_SRSCtl;
    RETURN();
}

void op_mfc0_srsmap (void)
{
    T0 = env->CP0_SRSMap;
1322 1323 1324
    RETURN();
}

1325 1326
void op_mfc0_cause (void)
{
T
ths 已提交
1327
    T0 = env->CP0_Cause;
1328 1329 1330 1331 1332
    RETURN();
}

void op_mfc0_epc (void)
{
T
ths 已提交
1333
    T0 = (int32_t)env->CP0_EPC;
1334 1335 1336 1337 1338
    RETURN();
}

void op_mfc0_prid (void)
{
T
ths 已提交
1339
    T0 = env->CP0_PRid;
1340 1341 1342
    RETURN();
}

1343 1344
void op_mfc0_ebase (void)
{
1345
    T0 = env->CP0_EBase;
1346 1347 1348
    RETURN();
}

1349 1350
void op_mfc0_config0 (void)
{
T
ths 已提交
1351
    T0 = env->CP0_Config0;
1352 1353 1354 1355 1356
    RETURN();
}

void op_mfc0_config1 (void)
{
T
ths 已提交
1357
    T0 = env->CP0_Config1;
1358 1359 1360
    RETURN();
}

1361 1362
void op_mfc0_config2 (void)
{
T
ths 已提交
1363
    T0 = env->CP0_Config2;
1364 1365 1366 1367 1368
    RETURN();
}

void op_mfc0_config3 (void)
{
T
ths 已提交
1369
    T0 = env->CP0_Config3;
1370 1371 1372
    RETURN();
}

1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384
void op_mfc0_config6 (void)
{
    T0 = env->CP0_Config6;
    RETURN();
}

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

1385 1386
void op_mfc0_lladdr (void)
{
T
ths 已提交
1387
    T0 = (int32_t)env->CP0_LLAddr >> 4;
1388 1389 1390
    RETURN();
}

1391
void op_mfc0_watchlo (void)
1392
{
1393
    T0 = (int32_t)env->CP0_WatchLo[PARAM1];
1394 1395 1396
    RETURN();
}

1397
void op_mfc0_watchhi (void)
1398
{
1399
    T0 = env->CP0_WatchHi[PARAM1];
1400 1401 1402
    RETURN();
}

1403 1404
void op_mfc0_xcontext (void)
{
T
ths 已提交
1405
    T0 = (int32_t)env->CP0_XContext;
1406 1407 1408 1409 1410 1411 1412 1413 1414
    RETURN();
}

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

1415 1416
void op_mfc0_debug (void)
{
T
ths 已提交
1417
    T0 = env->CP0_Debug;
1418 1419 1420 1421 1422
    if (env->hflags & MIPS_HFLAG_DM)
        T0 |= 1 << CP0DB_DM;
    RETURN();
}

1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433
void op_mftc0_debug(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    /* XXX: Might be wrong, check with EJTAG spec. */
    T0 = (env->CP0_Debug & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
         (env->CP0_Debug_tcstatus[other_tc] &
          ((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
    RETURN();
}

1434 1435
void op_mfc0_depc (void)
{
T
ths 已提交
1436
    T0 = (int32_t)env->CP0_DEPC;
1437 1438 1439
    RETURN();
}

1440 1441
void op_mfc0_performance0 (void)
{
T
ths 已提交
1442
    T0 = env->CP0_Performance0;
1443 1444 1445
    RETURN();
}

1446 1447
void op_mfc0_taglo (void)
{
T
ths 已提交
1448
    T0 = env->CP0_TagLo;
1449 1450 1451 1452 1453
    RETURN();
}

void op_mfc0_datalo (void)
{
T
ths 已提交
1454
    T0 = env->CP0_DataLo;
1455 1456 1457
    RETURN();
}

1458 1459
void op_mfc0_taghi (void)
{
T
ths 已提交
1460
    T0 = env->CP0_TagHi;
1461 1462 1463 1464 1465
    RETURN();
}

void op_mfc0_datahi (void)
{
T
ths 已提交
1466
    T0 = env->CP0_DataHi;
1467 1468 1469
    RETURN();
}

1470 1471
void op_mfc0_errorepc (void)
{
T
ths 已提交
1472
    T0 = (int32_t)env->CP0_ErrorEPC;
1473 1474 1475 1476 1477
    RETURN();
}

void op_mfc0_desave (void)
{
T
ths 已提交
1478
    T0 = env->CP0_DESAVE;
B
bellard 已提交
1479 1480 1481
    RETURN();
}

1482
void op_mtc0_index (void)
B
bellard 已提交
1483
{
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 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 1575 1576 1577 1578 1579 1580 1581 1582
    env->CP0_Index = (env->CP0_Index & 0x80000000) | (T0 % env->tlb->nb_tlb);
    RETURN();
}

void op_mtc0_mvpcontrol (void)
{
    uint32_t mask = 0;
    uint32_t newval;

    if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP))
        mask |= (1 << CP0MVPCo_CPA) | (1 << CP0MVPCo_VPC) |
                (1 << CP0MVPCo_EVP);
    if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
        mask |= (1 << CP0MVPCo_STLB);
    newval = (env->mvp->CP0_MVPControl & ~mask) | (T0 & mask);

    // TODO: Enable/disable shared TLB, enable/disable VPEs.

    env->mvp->CP0_MVPControl = newval;
    RETURN();
}

void op_mtc0_vpecontrol (void)
{
    uint32_t mask;
    uint32_t newval;

    mask = (1 << CP0VPECo_YSI) | (1 << CP0VPECo_GSI) |
           (1 << CP0VPECo_TE) | (0xff << CP0VPECo_TargTC);
    newval = (env->CP0_VPEControl & ~mask) | (T0 & mask);

    /* Yield scheduler intercept not implemented. */
    /* Gating storage scheduler intercept not implemented. */

    // TODO: Enable/disable TCs.

    env->CP0_VPEControl = newval;
    RETURN();
}

void op_mtc0_vpeconf0 (void)
{
    uint32_t mask = 0;
    uint32_t newval;

    if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
        if (env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))
            mask |= (0xff << CP0VPEC0_XTC);
        mask |= (1 << CP0VPEC0_MVP) | (1 << CP0VPEC0_VPA);
    }
    newval = (env->CP0_VPEConf0 & ~mask) | (T0 & mask);

    // TODO: TC exclusive handling due to ERL/EXL.

    env->CP0_VPEConf0 = newval;
    RETURN();
}

void op_mtc0_vpeconf1 (void)
{
    uint32_t mask = 0;
    uint32_t newval;

    if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
        mask |= (0xff << CP0VPEC1_NCX) | (0xff << CP0VPEC1_NCP2) |
                (0xff << CP0VPEC1_NCP1);
    newval = (env->CP0_VPEConf1 & ~mask) | (T0 & mask);

    /* UDI not implemented. */
    /* CP2 not implemented. */

    // TODO: Handle FPU (CP1) binding.

    env->CP0_VPEConf1 = newval;
    RETURN();
}

void op_mtc0_yqmask (void)
{
    /* Yield qualifier inputs not implemented. */
    env->CP0_YQMask = 0x00000000;
    RETURN();
}

void op_mtc0_vpeschedule (void)
{
    env->CP0_VPESchedule = T0;
    RETURN();
}

void op_mtc0_vpeschefback (void)
{
    env->CP0_VPEScheFBack = T0;
    RETURN();
}

void op_mtc0_vpeopt (void)
{
    env->CP0_VPEOpt = T0 & 0x0000ffff;
1583 1584 1585 1586 1587
    RETURN();
}

void op_mtc0_entrylo0 (void)
{
1588 1589
    /* Large physaddr not implemented */
    /* 1k pages not implemented */
1590
    env->CP0_EntryLo0 = T0 & 0x3FFFFFFF;
1591 1592 1593
    RETURN();
}

1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 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 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 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 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722
void op_mtc0_tcstatus (void)
{
    uint32_t mask = env->CP0_TCStatus_rw_bitmask;
    uint32_t newval;

    newval = (env->CP0_TCStatus[env->current_tc] & ~mask) | (T0 & mask);

    // TODO: Sync with CP0_Status.

    env->CP0_TCStatus[env->current_tc] = newval;
    RETURN();
}

void op_mttc0_tcstatus (void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    // TODO: Sync with CP0_Status.

    env->CP0_TCStatus[other_tc] = T0;
    RETURN();
}

void op_mtc0_tcbind (void)
{
    uint32_t mask = (1 << CP0TCBd_TBE);
    uint32_t newval;

    if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
        mask |= (1 << CP0TCBd_CurVPE);
    newval = (env->CP0_TCBind[env->current_tc] & ~mask) | (T0 & mask);
    env->CP0_TCBind[env->current_tc] = newval;
    RETURN();
}

void op_mttc0_tcbind (void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
    uint32_t mask = (1 << CP0TCBd_TBE);
    uint32_t newval;

    if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
        mask |= (1 << CP0TCBd_CurVPE);
    newval = (env->CP0_TCBind[other_tc] & ~mask) | (T0 & mask);
    env->CP0_TCBind[other_tc] = newval;
    RETURN();
}

void op_mtc0_tcrestart (void)
{
    env->PC[env->current_tc] = T0;
    env->CP0_TCStatus[env->current_tc] &= ~(1 << CP0TCSt_TDS);
    env->CP0_LLAddr = 0ULL;
    /* MIPS16 not implemented. */
    RETURN();
}

void op_mttc0_tcrestart (void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    env->PC[other_tc] = T0;
    env->CP0_TCStatus[other_tc] &= ~(1 << CP0TCSt_TDS);
    env->CP0_LLAddr = 0ULL;
    /* MIPS16 not implemented. */
    RETURN();
}

void op_mtc0_tchalt (void)
{
    env->CP0_TCHalt[env->current_tc] = T0 & 0x1;

    // TODO: Halt TC / Restart (if allocated+active) TC.

    RETURN();
}

void op_mttc0_tchalt (void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    // TODO: Halt TC / Restart (if allocated+active) TC.

    env->CP0_TCHalt[other_tc] = T0;
    RETURN();
}

void op_mtc0_tccontext (void)
{
    env->CP0_TCContext[env->current_tc] = T0;
    RETURN();
}

void op_mttc0_tccontext (void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    env->CP0_TCContext[other_tc] = T0;
    RETURN();
}

void op_mtc0_tcschedule (void)
{
    env->CP0_TCSchedule[env->current_tc] = T0;
    RETURN();
}

void op_mttc0_tcschedule (void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    env->CP0_TCSchedule[other_tc] = T0;
    RETURN();
}

void op_mtc0_tcschefback (void)
{
    env->CP0_TCScheFBack[env->current_tc] = T0;
    RETURN();
}

void op_mttc0_tcschefback (void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    env->CP0_TCScheFBack[other_tc] = T0;
    RETURN();
}

1723 1724
void op_mtc0_entrylo1 (void)
{
1725 1726
    /* Large physaddr not implemented */
    /* 1k pages not implemented */
1727
    env->CP0_EntryLo1 = T0 & 0x3FFFFFFF;
1728 1729 1730 1731 1732
    RETURN();
}

void op_mtc0_context (void)
{
1733
    env->CP0_Context = (env->CP0_Context & 0x007FFFFF) | (T0 & ~0x007FFFFF);
1734 1735 1736 1737 1738
    RETURN();
}

void op_mtc0_pagemask (void)
{
1739
    /* 1k pages not implemented */
T
ths 已提交
1740
    env->CP0_PageMask = T0 & (0x1FFFFFFF & (TARGET_PAGE_MASK << 1));
1741 1742 1743 1744 1745 1746 1747 1748 1749
    RETURN();
}

void op_mtc0_pagegrain (void)
{
    /* SmartMIPS not implemented */
    /* Large physaddr not implemented */
    /* 1k pages not implemented */
    env->CP0_PageGrain = 0;
1750 1751 1752 1753 1754
    RETURN();
}

void op_mtc0_wired (void)
{
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
    env->CP0_Wired = T0 % env->tlb->nb_tlb;
    RETURN();
}

void op_mtc0_srsconf0 (void)
{
    env->CP0_SRSConf0 |= T0 & env->CP0_SRSConf0_rw_bitmask;
    RETURN();
}

void op_mtc0_srsconf1 (void)
{
    env->CP0_SRSConf1 |= T0 & env->CP0_SRSConf1_rw_bitmask;
    RETURN();
}

void op_mtc0_srsconf2 (void)
{
    env->CP0_SRSConf2 |= T0 & env->CP0_SRSConf2_rw_bitmask;
    RETURN();
}

void op_mtc0_srsconf3 (void)
{
    env->CP0_SRSConf3 |= T0 & env->CP0_SRSConf3_rw_bitmask;
    RETURN();
}

void op_mtc0_srsconf4 (void)
{
    env->CP0_SRSConf4 |= T0 & env->CP0_SRSConf4_rw_bitmask;
1786 1787 1788 1789 1790 1791
    RETURN();
}

void op_mtc0_hwrena (void)
{
    env->CP0_HWREna = T0 & 0x0000000F;
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802
    RETURN();
}

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

void op_mtc0_entryhi (void)
{
T
ths 已提交
1803
    target_ulong old, val;
1804

1805
    /* 1k pages not implemented */
1806 1807
    val = T0 & ((TARGET_PAGE_MASK << 1) | 0xFF);
#ifdef TARGET_MIPS64
T
ths 已提交
1808
    val &= env->SEGMask;
1809
#endif
1810 1811
    old = env->CP0_EntryHi;
    env->CP0_EntryHi = val;
1812 1813 1814 1815
    if (env->CP0_Config3 & (1 << CP0C3_MT)) {
        uint32_t tcst = env->CP0_TCStatus[env->current_tc] & ~0xff;
        env->CP0_TCStatus[env->current_tc] = tcst | (val & 0xff);
    }
1816 1817 1818 1819 1820 1821
    /* If the ASID changes, flush qemu's TLB.  */
    if ((old & 0xFF) != (val & 0xFF))
        CALL_FROM_TB2(cpu_mips_tlb_flush, env, 1);
    RETURN();
}

1822 1823 1824 1825 1826 1827 1828 1829 1830
void op_mttc0_entryhi(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    env->CP0_EntryHi = (env->CP0_EntryHi & 0xff) | (T0 & ~0xff);
    env->CP0_TCStatus[other_tc] = (env->CP0_TCStatus[other_tc] & ~0xff) | (T0 & 0xff);
    RETURN();
}

1831 1832 1833 1834 1835 1836 1837 1838
void op_mtc0_compare (void)
{
    CALL_FROM_TB2(cpu_mips_store_compare, env, T0);
    RETURN();
}

void op_mtc0_status (void)
{
1839
    uint32_t val, old;
1840
    uint32_t mask = env->CP0_Status_rw_bitmask;
1841

1842
    val = T0 & mask;
1843
    old = env->CP0_Status;
1844
    env->CP0_Status = (env->CP0_Status & ~mask) | val;
1845
    CALL_FROM_TB1(compute_hflags, env);
1846 1847
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB2(do_mtc0_status_debug, old, val);
1848
    CALL_FROM_TB1(cpu_mips_update_irq, env);
1849 1850 1851
    RETURN();
}

1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
void op_mttc0_status(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
    uint32_t tcstatus = env->CP0_TCStatus[other_tc];

    env->CP0_Status = T0 & ~0xf1000018;
    tcstatus = (tcstatus & ~(0xf << CP0TCSt_TCU0)) | (T0 & (0xf << CP0St_CU0));
    tcstatus = (tcstatus & ~(1 << CP0TCSt_TMX)) | ((T0 & (1 << CP0St_MX)) << (CP0TCSt_TMX - CP0St_MX));
    tcstatus = (tcstatus & ~(0x3 << CP0TCSt_TKSU)) | ((T0 & (0x3 << CP0St_R0)) << (CP0TCSt_TKSU - CP0St_R0));
    env->CP0_TCStatus[other_tc] = tcstatus;
    RETURN();
}

1865 1866
void op_mtc0_intctl (void)
{
1867 1868
    /* vectored interrupts not implemented, no performance counters. */
    env->CP0_IntCtl = (env->CP0_IntCtl & ~0x000002e0) | (T0 & 0x000002e0);
1869 1870 1871 1872 1873
    RETURN();
}

void op_mtc0_srsctl (void)
{
1874 1875
    uint32_t mask = (0xf << CP0SRSCtl_ESS) | (0xf << CP0SRSCtl_PSS);
    env->CP0_SRSCtl = (env->CP0_SRSCtl & ~mask) | (T0 & mask);
1876 1877 1878
    RETURN();
}

T
ths 已提交
1879 1880
void op_mtc0_srsmap (void)
{
1881
    env->CP0_SRSMap = T0;
T
ths 已提交
1882 1883 1884
    RETURN();
}

1885 1886
void op_mtc0_cause (void)
{
1887
    uint32_t mask = 0x00C00300;
1888
    uint32_t old = env->CP0_Cause;
1889

1890
    if (env->insn_flags & ISA_MIPS32R2)
1891 1892
        mask |= 1 << CP0Ca_DC;

1893
    env->CP0_Cause = (env->CP0_Cause & ~mask) | (T0 & mask);
1894

1895 1896 1897 1898 1899 1900 1901
    if ((old ^ env->CP0_Cause) & (1 << CP0Ca_DC)) {
        if (env->CP0_Cause & (1 << CP0Ca_DC))
            CALL_FROM_TB1(cpu_mips_stop_count, env);
        else
            CALL_FROM_TB1(cpu_mips_start_count, env);
    }

1902 1903 1904 1905
    /* 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);
1906 1907 1908 1909 1910 1911
    }
    RETURN();
}

void op_mtc0_epc (void)
{
1912
    env->CP0_EPC = T0;
1913 1914 1915
    RETURN();
}

1916 1917 1918 1919
void op_mtc0_ebase (void)
{
    /* vectored interrupts not implemented */
    /* Multi-CPU not implemented */
1920
    env->CP0_EBase = 0x80000000 | (T0 & 0x3FFFF000);
1921 1922 1923
    RETURN();
}

1924 1925
void op_mtc0_config0 (void)
{
1926
    env->CP0_Config0 = (env->CP0_Config0 & 0x81FFFFF8) | (T0 & 0x00000007);
1927 1928 1929
    RETURN();
}

1930 1931 1932 1933 1934 1935 1936
void op_mtc0_config2 (void)
{
    /* tertiary/secondary caches not implemented */
    env->CP0_Config2 = (env->CP0_Config2 & 0x8FFF0FFF);
    RETURN();
}

1937
void op_mtc0_watchlo (void)
1938
{
T
ths 已提交
1939 1940
    /* Watch exceptions for instructions, data loads, data stores
       not implemented. */
1941
    env->CP0_WatchLo[PARAM1] = (T0 & ~0x7);
1942 1943 1944
    RETURN();
}

1945
void op_mtc0_watchhi (void)
1946
{
1947 1948
    env->CP0_WatchHi[PARAM1] = (T0 & 0x40FF0FF8);
    env->CP0_WatchHi[PARAM1] &= ~(env->CP0_WatchHi[PARAM1] & T0 & 0x7);
1949 1950 1951
    RETURN();
}

1952 1953 1954 1955 1956 1957 1958
void op_mtc0_xcontext (void)
{
    target_ulong mask = (1ULL << (env->SEGBITS - 7)) - 1;
    env->CP0_XContext = (env->CP0_XContext & mask) | (T0 & ~mask);
    RETURN();
}

1959 1960 1961 1962 1963 1964
void op_mtc0_framemask (void)
{
    env->CP0_Framemask = T0; /* XXX */
    RETURN();
}

1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
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();
}

1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
void op_mttc0_debug(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    /* XXX: Might be wrong, check with EJTAG spec. */
    env->CP0_Debug_tcstatus[other_tc] = T0 & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt));
    env->CP0_Debug = (env->CP0_Debug & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
                     (T0 & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
    RETURN();
}

1986 1987
void op_mtc0_depc (void)
{
1988
    env->CP0_DEPC = T0;
1989 1990 1991
    RETURN();
}

1992 1993 1994 1995 1996 1997
void op_mtc0_performance0 (void)
{
    env->CP0_Performance0 = T0; /* XXX */
    RETURN();
}

1998 1999
void op_mtc0_taglo (void)
{
T
ths 已提交
2000
    env->CP0_TagLo = T0 & 0xFFFFFCF6;
2001 2002 2003
    RETURN();
}

2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
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();
}

2022 2023
void op_mtc0_errorepc (void)
{
2024
    env->CP0_ErrorEPC = T0;
2025 2026 2027 2028 2029 2030
    RETURN();
}

void op_mtc0_desave (void)
{
    env->CP0_DESAVE = T0;
B
bellard 已提交
2031 2032 2033
    RETURN();
}

2034
#ifdef TARGET_MIPS64
2035
void op_dmfc0_yqmask (void)
2036
{
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049
    T0 = env->CP0_YQMask;
    RETURN();
}

void op_dmfc0_vpeschedule (void)
{
    T0 = env->CP0_VPESchedule;
    RETURN();
}

void op_dmfc0_vpeschefback (void)
{
    T0 = env->CP0_VPEScheFBack;
2050 2051 2052
    RETURN();
}

T
ths 已提交
2053 2054 2055 2056 2057 2058
void op_dmfc0_entrylo0 (void)
{
    T0 = env->CP0_EntryLo0;
    RETURN();
}

2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
void op_dmfc0_tcrestart (void)
{
    T0 = env->PC[env->current_tc];
    RETURN();
}

void op_dmfc0_tchalt (void)
{
    T0 = env->CP0_TCHalt[env->current_tc];
    RETURN();
}

void op_dmfc0_tccontext (void)
{
    T0 = env->CP0_TCContext[env->current_tc];
    RETURN();
}

void op_dmfc0_tcschedule (void)
{
    T0 = env->CP0_TCSchedule[env->current_tc];
    RETURN();
}

void op_dmfc0_tcschefback (void)
{
    T0 = env->CP0_TCScheFBack[env->current_tc];
    RETURN();
}

T
ths 已提交
2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124
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();
}

2125
void op_dmfc0_watchlo (void)
T
ths 已提交
2126
{
2127
    T0 = env->CP0_WatchLo[PARAM1];
T
ths 已提交
2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147
    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();
}
2148
#endif /* TARGET_MIPS64 */
T
ths 已提交
2149

2150 2151 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 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 2222 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 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300
/* MIPS MT functions */
void op_mftgpr(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->gpr[PARAM1][other_tc];
    RETURN();
}

void op_mftlo(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->LO[PARAM1][other_tc];
    RETURN();
}

void op_mfthi(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->HI[PARAM1][other_tc];
    RETURN();
}

void op_mftacx(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->ACX[PARAM1][other_tc];
    RETURN();
}

void op_mftdsp(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->DSPControl[other_tc];
    RETURN();
}

void op_mttgpr(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->gpr[PARAM1][other_tc];
    RETURN();
}

void op_mttlo(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->LO[PARAM1][other_tc];
    RETURN();
}

void op_mtthi(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->HI[PARAM1][other_tc];
    RETURN();
}

void op_mttacx(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->ACX[PARAM1][other_tc];
    RETURN();
}

void op_mttdsp(void)
{
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);

    T0 = env->DSPControl[other_tc];
    RETURN();
}


void op_dmt(void)
{
    // TODO
    T0 = 0;
    // rt = T0
    RETURN();
}

void op_emt(void)
{
    // TODO
    T0 = 0;
    // rt = T0
    RETURN();
}

void op_dvpe(void)
{
    // TODO
    T0 = 0;
    // rt = T0
    RETURN();
}

void op_evpe(void)
{
    // TODO
    T0 = 0;
    // rt = T0
    RETURN();
}

void op_fork(void)
{
    // T0 = rt, T1 = rs
    T0 = 0;
    // TODO: store to TC register
    RETURN();
}

void op_yield(void)
{
    if (T0 < 0) {
        /* No scheduling policy implemented. */
        if (T0 != -2) {
            if (env->CP0_VPEControl & (1 << CP0VPECo_YSI) &&
                env->CP0_TCStatus[env->current_tc] & (1 << CP0TCSt_DT)) {
                env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
                env->CP0_VPEControl |= 4 << CP0VPECo_EXCPT;
                CALL_FROM_TB1(do_raise_exception, EXCP_THREAD);
            }
        }
    } else if (T0 == 0) {
	if (0 /* TODO: TC underflow */) {
            env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
            CALL_FROM_TB1(do_raise_exception, EXCP_THREAD);
        } else {
            // TODO: Deallocate TC
        }
    } else if (T0 > 0) {
        /* Yield qualifier inputs not implemented. */
        env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
        env->CP0_VPEControl |= 2 << CP0VPECo_EXCPT;
        CALL_FROM_TB1(do_raise_exception, EXCP_THREAD);
    }
    T0 = env->CP0_YQMask;
    RETURN();
}

2301
/* CP1 functions */
B
bellard 已提交
2302 2303 2304 2305 2306 2307
#if 0
# define DEBUG_FPU_STATE() CALL_FROM_TB1(dump_fpu, env)
#else
# define DEBUG_FPU_STATE() do { } while(0)
#endif

2308 2309
void op_cfc1 (void)
{
2310
    CALL_FROM_TB1(do_cfc1, PARAM1);
2311 2312 2313 2314 2315 2316
    DEBUG_FPU_STATE();
    RETURN();
}

void op_ctc1 (void)
{
2317
    CALL_FROM_TB1(do_ctc1, PARAM1);
B
bellard 已提交
2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
    DEBUG_FPU_STATE();
    RETURN();
}

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

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

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
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 已提交
2364 2365
/* Float support.
   Single precition routines have a "s" suffix, double precision a
2366 2367
   "d" suffix, 32bit integer "w", 64bit integer "l", paired singe "ps",
   paired single lowwer "pl", paired single upper "pu".  */
B
bellard 已提交
2368 2369 2370

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

2371 2372
FLOAT_OP(cvtd, s)
{
2373
    CALL_FROM_TB0(do_float_cvtd_s);
2374 2375 2376
    DEBUG_FPU_STATE();
    RETURN();
}
B
bellard 已提交
2377 2378
FLOAT_OP(cvtd, w)
{
2379
    CALL_FROM_TB0(do_float_cvtd_w);
2380 2381 2382 2383 2384
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtd, l)
{
2385
    CALL_FROM_TB0(do_float_cvtd_l);
2386 2387 2388 2389 2390
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtl, d)
{
2391
    CALL_FROM_TB0(do_float_cvtl_d);
2392 2393 2394 2395 2396
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtl, s)
{
2397
    CALL_FROM_TB0(do_float_cvtl_s);
2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtps, s)
{
    WT2 = WT0;
    WTH2 = WT1;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtps, pw)
{
2410
    CALL_FROM_TB0(do_float_cvtps_pw);
2411 2412 2413 2414 2415
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtpw, ps)
{
2416
    CALL_FROM_TB0(do_float_cvtpw_ps);
B
bellard 已提交
2417 2418 2419
    DEBUG_FPU_STATE();
    RETURN();
}
2420 2421
FLOAT_OP(cvts, d)
{
2422
    CALL_FROM_TB0(do_float_cvts_d);
2423 2424 2425
    DEBUG_FPU_STATE();
    RETURN();
}
B
bellard 已提交
2426 2427
FLOAT_OP(cvts, w)
{
2428
    CALL_FROM_TB0(do_float_cvts_w);
2429 2430 2431 2432 2433
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvts, l)
{
2434
    CALL_FROM_TB0(do_float_cvts_l);
2435 2436 2437 2438 2439
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvts, pl)
{
2440
    CALL_FROM_TB0(do_float_cvts_pl);
2441 2442 2443 2444 2445
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvts, pu)
{
2446
    CALL_FROM_TB0(do_float_cvts_pu);
B
bellard 已提交
2447 2448 2449 2450 2451
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtw, s)
{
2452
    CALL_FROM_TB0(do_float_cvtw_s);
B
bellard 已提交
2453 2454 2455 2456 2457
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(cvtw, d)
{
2458
    CALL_FROM_TB0(do_float_cvtw_d);
2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483
    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 已提交
2484 2485 2486 2487
    DEBUG_FPU_STATE();
    RETURN();
}

2488 2489 2490 2491 2492 2493
#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 已提交
2494 2495
}

2496 2497 2498 2499
FLOAT_ROUNDOP(round, l, d)
FLOAT_ROUNDOP(round, l, s)
FLOAT_ROUNDOP(round, w, d)
FLOAT_ROUNDOP(round, w, s)
B
bellard 已提交
2500

2501 2502 2503 2504
FLOAT_ROUNDOP(trunc, l, d)
FLOAT_ROUNDOP(trunc, l, s)
FLOAT_ROUNDOP(trunc, w, d)
FLOAT_ROUNDOP(trunc, w, s)
B
bellard 已提交
2505

2506 2507 2508 2509 2510 2511 2512 2513 2514 2515
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 已提交
2516

2517 2518
FLOAT_OP(movf, d)
{
2519
    if (!(env->fpu->fcr31 & PARAM1))
2520 2521 2522 2523 2524 2525
        DT2 = DT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movf, s)
{
2526
    if (!(env->fpu->fcr31 & PARAM1))
2527 2528 2529 2530 2531 2532
        WT2 = WT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movf, ps)
{
2533
    if (!(env->fpu->fcr31 & PARAM1)) {
2534 2535 2536 2537 2538 2539 2540 2541
        WT2 = WT0;
        WTH2 = WTH0;
    }
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movt, d)
{
2542
    if (env->fpu->fcr31 & PARAM1)
2543 2544 2545 2546 2547 2548
        DT2 = DT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movt, s)
{
2549
    if (env->fpu->fcr31 & PARAM1)
2550 2551 2552 2553 2554 2555
        WT2 = WT0;
    DEBUG_FPU_STATE();
    RETURN();
}
FLOAT_OP(movt, ps)
{
2556
    if (env->fpu->fcr31 & PARAM1) {
2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 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 2606 2607 2608 2609
        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 已提交
2610 2611
/* operations calling helpers, for s, d and ps */
#define FLOAT_HOP(name) \
B
bellard 已提交
2612 2613
FLOAT_OP(name, d)         \
{                         \
2614
    CALL_FROM_TB0(do_float_ ## name ## _d);  \
B
bellard 已提交
2615
    DEBUG_FPU_STATE();    \
2616
    RETURN();             \
B
bellard 已提交
2617 2618 2619
}                         \
FLOAT_OP(name, s)         \
{                         \
2620
    CALL_FROM_TB0(do_float_ ## name ## _s);  \
2621
    DEBUG_FPU_STATE();    \
2622
    RETURN();             \
2623 2624 2625
}                         \
FLOAT_OP(name, ps)        \
{                         \
2626
    CALL_FROM_TB0(do_float_ ## name ## _ps); \
B
bellard 已提交
2627
    DEBUG_FPU_STATE();    \
2628
    RETURN();             \
B
bellard 已提交
2629
}
T
ths 已提交
2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656
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 已提交
2657

T
ths 已提交
2658 2659 2660 2661 2662 2663 2664
/* operations calling helpers, for ps */
#define FLOAT_HOP(name)   \
FLOAT_OP(name, ps)        \
{                         \
    CALL_FROM_TB0(do_float_ ## name ## _ps); \
    DEBUG_FPU_STATE();    \
    RETURN();             \
2665
}
T
ths 已提交
2666 2667 2668
FLOAT_HOP(addr)
FLOAT_HOP(mulr)
#undef FLOAT_HOP
2669

2670 2671 2672 2673
/* ternary operations */
#define FLOAT_TERNOP(name1, name2) \
FLOAT_OP(name1 ## name2, d)        \
{                                  \
2674 2675
    FDT0 = float64_ ## name1 (FDT0, FDT1, &env->fpu->fp_status);    \
    FDT2 = float64_ ## name2 (FDT0, FDT2, &env->fpu->fp_status);    \
2676
    DEBUG_FPU_STATE();             \
2677
    RETURN();                      \
2678 2679 2680
}                                  \
FLOAT_OP(name1 ## name2, s)        \
{                                  \
2681 2682
    FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status);    \
    FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status);    \
2683
    DEBUG_FPU_STATE();             \
2684
    RETURN();                      \
2685 2686 2687
}                                  \
FLOAT_OP(name1 ## name2, ps)       \
{                                  \
2688 2689 2690 2691
    FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status);    \
    FSTH0 = float32_ ## name1 (FSTH0, FSTH1, &env->fpu->fp_status); \
    FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status);    \
    FSTH2 = float32_ ## name2 (FSTH0, FSTH2, &env->fpu->fp_status); \
2692
    DEBUG_FPU_STATE();             \
2693
    RETURN();                      \
2694 2695 2696 2697 2698
}
FLOAT_TERNOP(mul, add)
FLOAT_TERNOP(mul, sub)
#undef FLOAT_TERNOP

2699 2700 2701 2702
/* negated ternary operations */
#define FLOAT_NTERNOP(name1, name2) \
FLOAT_OP(n ## name1 ## name2, d)    \
{                                   \
2703 2704
    FDT0 = float64_ ## name1 (FDT0, FDT1, &env->fpu->fp_status);    \
    FDT2 = float64_ ## name2 (FDT0, FDT2, &env->fpu->fp_status);    \
2705 2706 2707 2708 2709 2710
    FDT2 ^= 1ULL << 63;             \
    DEBUG_FPU_STATE();              \
    RETURN();                       \
}                                   \
FLOAT_OP(n ## name1 ## name2, s)    \
{                                   \
2711 2712
    FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status);    \
    FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status);    \
2713 2714 2715 2716 2717 2718
    FST2 ^= 1 << 31;                \
    DEBUG_FPU_STATE();              \
    RETURN();                       \
}                                   \
FLOAT_OP(n ## name1 ## name2, ps)   \
{                                   \
2719 2720 2721 2722
    FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status);    \
    FSTH0 = float32_ ## name1 (FSTH0, FSTH1, &env->fpu->fp_status); \
    FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status);    \
    FSTH2 = float32_ ## name2 (FSTH0, FSTH2, &env->fpu->fp_status); \
2723 2724 2725 2726 2727 2728 2729 2730 2731
    FST2 ^= 1 << 31;                \
    FSTH2 ^= 1 << 31;               \
    DEBUG_FPU_STATE();              \
    RETURN();                       \
}
FLOAT_NTERNOP(mul, add)
FLOAT_NTERNOP(mul, sub)
#undef FLOAT_NTERNOP

B
bellard 已提交
2732 2733 2734 2735
/* unary operations, modifying fp status  */
#define FLOAT_UNOP(name)  \
FLOAT_OP(name, d)         \
{                         \
2736
    FDT2 = float64_ ## name(FDT0, &env->fpu->fp_status);   \
B
bellard 已提交
2737
    DEBUG_FPU_STATE();    \
2738
    RETURN();                      \
B
bellard 已提交
2739 2740 2741
}                         \
FLOAT_OP(name, s)         \
{                         \
2742
    FST2 = float32_ ## name(FST0, &env->fpu->fp_status);   \
B
bellard 已提交
2743
    DEBUG_FPU_STATE();    \
T
ths 已提交
2744
    RETURN();             \
B
bellard 已提交
2745 2746 2747 2748 2749 2750 2751 2752 2753 2754
}
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();    \
2755
    RETURN();             \
B
bellard 已提交
2756 2757 2758 2759 2760
}                         \
FLOAT_OP(name, s)         \
{                         \
    FST2 = float32_ ## name(FST0);   \
    DEBUG_FPU_STATE();    \
2761
    RETURN();             \
2762 2763 2764 2765 2766 2767
}                         \
FLOAT_OP(name, ps)        \
{                         \
    FST2 = float32_ ## name(FST0);   \
    FSTH2 = float32_ ## name(FSTH0); \
    DEBUG_FPU_STATE();    \
2768
    RETURN();             \
B
bellard 已提交
2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785
}
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();
}
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
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 已提交
2815 2816 2817

#ifdef CONFIG_SOFTFLOAT
#define clear_invalid() do {                                \
2818
    int flags = get_float_exception_flags(&env->fpu->fp_status); \
B
bellard 已提交
2819
    flags &= ~float_flag_invalid;                           \
2820
    set_float_exception_flags(flags, &env->fpu->fp_status);      \
B
bellard 已提交
2821 2822 2823 2824 2825 2826 2827
} while(0)
#else
#define clear_invalid() do { } while(0)
#endif

extern void dump_fpu_s(CPUState *env);

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
#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 已提交
2864 2865 2866

void op_bc1f (void)
{
2867
    T0 = !!(~GET_FP_COND(env->fpu) & (0x1 << PARAM1));
2868 2869 2870
    DEBUG_FPU_STATE();
    RETURN();
}
2871
void op_bc1any2f (void)
2872
{
2873
    T0 = !!(~GET_FP_COND(env->fpu) & (0x3 << PARAM1));
2874 2875 2876
    DEBUG_FPU_STATE();
    RETURN();
}
2877
void op_bc1any4f (void)
2878
{
2879
    T0 = !!(~GET_FP_COND(env->fpu) & (0xf << PARAM1));
B
bellard 已提交
2880 2881 2882 2883 2884 2885
    DEBUG_FPU_STATE();
    RETURN();
}

void op_bc1t (void)
{
2886
    T0 = !!(GET_FP_COND(env->fpu) & (0x1 << PARAM1));
2887 2888 2889
    DEBUG_FPU_STATE();
    RETURN();
}
2890
void op_bc1any2t (void)
2891
{
2892
    T0 = !!(GET_FP_COND(env->fpu) & (0x3 << PARAM1));
2893 2894 2895
    DEBUG_FPU_STATE();
    RETURN();
}
2896
void op_bc1any4t (void)
2897
{
2898
    T0 = !!(GET_FP_COND(env->fpu) & (0xf << PARAM1));
B
bellard 已提交
2899 2900 2901 2902
    DEBUG_FPU_STATE();
    RETURN();
}

B
bellard 已提交
2903 2904
void op_tlbwi (void)
{
2905
    CALL_FROM_TB0(env->tlb->do_tlbwi);
B
bellard 已提交
2906 2907 2908 2909 2910
    RETURN();
}

void op_tlbwr (void)
{
2911
    CALL_FROM_TB0(env->tlb->do_tlbwr);
B
bellard 已提交
2912 2913 2914 2915 2916
    RETURN();
}

void op_tlbp (void)
{
2917
    CALL_FROM_TB0(env->tlb->do_tlbp);
B
bellard 已提交
2918 2919 2920 2921 2922
    RETURN();
}

void op_tlbr (void)
{
2923
    CALL_FROM_TB0(env->tlb->do_tlbr);
B
bellard 已提交
2924 2925 2926 2927
    RETURN();
}

/* Specials */
2928 2929 2930
#if defined (CONFIG_USER_ONLY)
void op_tls_value (void)
{
2931
    T0 = env->tls_value;
2932 2933 2934
}
#endif

B
bellard 已提交
2935 2936 2937
void op_pmon (void)
{
    CALL_FROM_TB1(do_pmon, PARAM1);
2938 2939 2940 2941 2942 2943
    RETURN();
}

void op_di (void)
{
    T0 = env->CP0_Status;
2944 2945
    env->CP0_Status = T0 & ~(1 << CP0St_IE);
    CALL_FROM_TB1(cpu_mips_update_irq, env);
2946 2947 2948 2949 2950 2951
    RETURN();
}

void op_ei (void)
{
    T0 = env->CP0_Status;
2952 2953
    env->CP0_Status = T0 | (1 << CP0St_IE);
    CALL_FROM_TB1(cpu_mips_update_irq, env);
2954
    RETURN();
B
bellard 已提交
2955 2956 2957 2958 2959
}

void op_trap (void)
{
    if (T0) {
2960
        CALL_FROM_TB1(do_raise_exception, EXCP_TRAP);
B
bellard 已提交
2961 2962 2963 2964
    }
    RETURN();
}

B
bellard 已提交
2965 2966
void op_debug (void)
{
2967 2968
    CALL_FROM_TB1(do_raise_exception, EXCP_DEBUG);
    RETURN();
B
bellard 已提交
2969 2970
}

B
bellard 已提交
2971 2972 2973
void op_set_lladdr (void)
{
    env->CP0_LLAddr = T2;
2974
    RETURN();
B
bellard 已提交
2975 2976
}

2977 2978
void debug_pre_eret (void);
void debug_post_eret (void);
B
bellard 已提交
2979 2980
void op_eret (void)
{
2981 2982
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB0(debug_pre_eret);
T
ths 已提交
2983
    if (env->CP0_Status & (1 << CP0St_ERL)) {
2984
        env->PC[env->current_tc] = env->CP0_ErrorEPC;
T
ths 已提交
2985
        env->CP0_Status &= ~(1 << CP0St_ERL);
B
bellard 已提交
2986
    } else {
2987
        env->PC[env->current_tc] = env->CP0_EPC;
T
ths 已提交
2988
        env->CP0_Status &= ~(1 << CP0St_EXL);
B
bellard 已提交
2989
    }
2990
    CALL_FROM_TB1(compute_hflags, env);
2991 2992
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB0(debug_post_eret);
B
bellard 已提交
2993
    env->CP0_LLAddr = 1;
2994
    RETURN();
B
bellard 已提交
2995 2996 2997 2998
}

void op_deret (void)
{
2999 3000
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB0(debug_pre_eret);
3001
    env->PC[env->current_tc] = env->CP0_DEPC;
3002 3003
    env->hflags &= MIPS_HFLAG_DM;
    CALL_FROM_TB1(compute_hflags, env);
3004 3005
    if (loglevel & CPU_LOG_EXEC)
        CALL_FROM_TB0(debug_post_eret);
T
ths 已提交
3006
    env->CP0_LLAddr = 1;
3007 3008 3009 3010 3011
    RETURN();
}

void op_rdhwr_cpunum(void)
{
3012 3013
    if ((env->hflags & MIPS_HFLAG_CP0) ||
        (env->CP0_HWREna & (1 << 0)))
3014
        T0 = env->CP0_EBase & 0x3ff;
3015
    else
3016
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
3017 3018 3019 3020 3021
    RETURN();
}

void op_rdhwr_synci_step(void)
{
3022 3023
    if ((env->hflags & MIPS_HFLAG_CP0) ||
        (env->CP0_HWREna & (1 << 1)))
3024
        T0 = env->SYNCI_Step;
3025
    else
3026
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
3027 3028 3029 3030 3031
    RETURN();
}

void op_rdhwr_cc(void)
{
3032 3033
    if ((env->hflags & MIPS_HFLAG_CP0) ||
        (env->CP0_HWREna & (1 << 2)))
3034
        T0 = env->CP0_Count;
3035
    else
3036
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
3037 3038 3039 3040 3041
    RETURN();
}

void op_rdhwr_ccres(void)
{
3042 3043
    if ((env->hflags & MIPS_HFLAG_CP0) ||
        (env->CP0_HWREna & (1 << 3)))
3044
        T0 = env->CCRes;
3045
    else
3046 3047 3048 3049
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
    RETURN();
}

B
bellard 已提交
3050 3051 3052 3053 3054 3055 3056 3057
void op_save_state (void)
{
    env->hflags = PARAM1;
    RETURN();
}

void op_save_pc (void)
{
3058
    env->PC[env->current_tc] = PARAM1;
B
bellard 已提交
3059 3060 3061
    RETURN();
}

3062 3063 3064
#ifdef TARGET_MIPS64
void op_save_pc64 (void)
{
3065
    env->PC[env->current_tc] = ((uint64_t)PARAM1 << 32) | (uint32_t)PARAM2;
3066 3067 3068 3069
    RETURN();
}
#endif

T
ths 已提交
3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082
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 已提交
3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097
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();
3098
    RETURN();
B
bellard 已提交
3099 3100
}

B
bellard 已提交
3101 3102 3103 3104
void op_wait (void)
{
    env->halted = 1;
    CALL_FROM_TB1(do_raise_exception, EXCP_HLT);
3105 3106 3107 3108 3109 3110 3111 3112 3113
    RETURN();
}

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

T
ths 已提交
3114
    T0 = ((uint32_t)T1 >> pos) & ((size < 32) ? ((1 << size) - 1) : ~0);
3115 3116 3117 3118 3119 3120 3121
    RETURN();
}

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

3124
    T0 = (T0 & ~mask) | (((uint32_t)T1 << pos) & mask);
3125 3126 3127 3128 3129 3130 3131 3132 3133
    RETURN();
}

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

T
ths 已提交
3134
#ifdef TARGET_MIPS64
3135 3136 3137 3138 3139
void op_dext(void)
{
    unsigned int pos = PARAM1;
    unsigned int size = PARAM2;

T
ths 已提交
3140
    T0 = (T1 >> pos) & ((size < 32) ? ((1 << size) - 1) : ~0);
3141 3142 3143 3144 3145 3146 3147
    RETURN();
}

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

3150
    T0 = (T0 & ~mask) | ((T1 << pos) & mask);
3151 3152 3153
    RETURN();
}

3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164
void op_dsbh(void)
{
    T0 = ((T1 << 8) & ~0x00FF00FF00FF00FFULL) | ((T1 >> 8) & 0x00FF00FF00FF00FFULL);
    RETURN();
}

void op_dshd(void)
{
    T0 = ((T1 << 16) & ~0x0000FFFF0000FFFFULL) | ((T1 >> 16) & 0x0000FFFF0000FFFFULL);
    RETURN();
}
3165
#endif
3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176

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

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