op_helper.c 81.1 KB
Newer Older
1
#include "exec.h"
B
blueswir1 已提交
2
#include "host-utils.h"
B
blueswir1 已提交
3
#include "helper.h"
4 5 6
#if !defined(CONFIG_USER_ONLY)
#include "softmmu_exec.h"
#endif /* !defined(CONFIG_USER_ONLY) */
7

B
bellard 已提交
8
//#define DEBUG_PCALL
B
bellard 已提交
9
//#define DEBUG_MMU
10
//#define DEBUG_MXCC
B
blueswir1 已提交
11
//#define DEBUG_UNALIGNED
12
//#define DEBUG_UNASSIGNED
13
//#define DEBUG_ASI
B
bellard 已提交
14

15 16 17 18
#ifdef DEBUG_MMU
#define DPRINTF_MMU(fmt, args...) \
do { printf("MMU: " fmt , ##args); } while (0)
#else
B
blueswir1 已提交
19
#define DPRINTF_MMU(fmt, args...) do {} while (0)
20 21 22 23 24 25
#endif

#ifdef DEBUG_MXCC
#define DPRINTF_MXCC(fmt, args...) \
do { printf("MXCC: " fmt , ##args); } while (0)
#else
B
blueswir1 已提交
26
#define DPRINTF_MXCC(fmt, args...) do {} while (0)
27 28
#endif

29 30 31 32
#ifdef DEBUG_ASI
#define DPRINTF_ASI(fmt, args...) \
do { printf("ASI: " fmt , ##args); } while (0)
#else
B
blueswir1 已提交
33
#define DPRINTF_ASI(fmt, args...) do {} while (0)
34 35
#endif

36 37 38 39 40 41
#ifdef TARGET_ABI32
#define ABI32_MASK(addr) do { (addr) &= 0xffffffffULL; } while (0)
#else
#define ABI32_MASK(addr) do {} while (0)
#endif

B
bellard 已提交
42 43 44 45
void raise_exception(int tt)
{
    env->exception_index = tt;
    cpu_loop_exit();
46
}
B
bellard 已提交
47

B
blueswir1 已提交
48
void helper_trap(target_ulong nb_trap)
49
{
B
blueswir1 已提交
50 51 52 53 54 55 56 57 58 59 60 61
    env->exception_index = TT_TRAP + (nb_trap & 0x7f);
    cpu_loop_exit();
}

void helper_trapcc(target_ulong nb_trap, target_ulong do_trap)
{
    if (do_trap) {
        env->exception_index = TT_TRAP + (nb_trap & 0x7f);
        cpu_loop_exit();
    }
}

B
blueswir1 已提交
62 63
void helper_check_align(target_ulong addr, uint32_t align)
{
64 65 66 67 68
    if (addr & align) {
#ifdef DEBUG_UNALIGNED
    printf("Unaligned access to 0x" TARGET_FMT_lx " from 0x" TARGET_FMT_lx
           "\n", addr, env->pc);
#endif
B
blueswir1 已提交
69
        raise_exception(TT_UNALIGNED);
70
    }
B
blueswir1 已提交
71 72
}

73 74 75 76 77 78 79 80 81 82
#define F_HELPER(name, p) void helper_f##name##p(void)

#define F_BINOP(name)                                           \
    F_HELPER(name, s)                                           \
    {                                                           \
        FT0 = float32_ ## name (FT0, FT1, &env->fp_status);     \
    }                                                           \
    F_HELPER(name, d)                                           \
    {                                                           \
        DT0 = float64_ ## name (DT0, DT1, &env->fp_status);     \
B
blueswir1 已提交
83 84 85 86
    }                                                           \
    F_HELPER(name, q)                                           \
    {                                                           \
        QT0 = float128_ ## name (QT0, QT1, &env->fp_status);    \
87 88 89 90 91 92 93 94 95
    }

F_BINOP(add);
F_BINOP(sub);
F_BINOP(mul);
F_BINOP(div);
#undef F_BINOP

void helper_fsmuld(void)
B
blueswir1 已提交
96
{
97 98 99 100
    DT0 = float64_mul(float32_to_float64(FT0, &env->fp_status),
                      float32_to_float64(FT1, &env->fp_status),
                      &env->fp_status);
}
B
blueswir1 已提交
101

B
blueswir1 已提交
102 103 104 105 106 107 108
void helper_fdmulq(void)
{
    QT0 = float128_mul(float64_to_float128(DT0, &env->fp_status),
                       float64_to_float128(DT1, &env->fp_status),
                       &env->fp_status);
}

109 110 111
F_HELPER(neg, s)
{
    FT0 = float32_chs(FT1);
112 113
}

114 115
#ifdef TARGET_SPARC64
F_HELPER(neg, d)
116
{
117
    DT0 = float64_chs(DT1);
118
}
B
blueswir1 已提交
119 120 121 122 123 124

F_HELPER(neg, q)
{
    QT0 = float128_chs(QT1);
}
#endif
125 126 127

/* Integer to float conversion.  */
F_HELPER(ito, s)
B
bellard 已提交
128
{
T
ths 已提交
129
    FT0 = int32_to_float32(*((int32_t *)&FT1), &env->fp_status);
B
bellard 已提交
130 131
}

132
F_HELPER(ito, d)
B
bellard 已提交
133
{
T
ths 已提交
134
    DT0 = int32_to_float64(*((int32_t *)&FT1), &env->fp_status);
B
bellard 已提交
135
}
136

B
blueswir1 已提交
137 138 139 140 141
F_HELPER(ito, q)
{
    QT0 = int32_to_float128(*((int32_t *)&FT1), &env->fp_status);
}

B
blueswir1 已提交
142
#ifdef TARGET_SPARC64
143
F_HELPER(xto, s)
B
blueswir1 已提交
144 145 146 147
{
    FT0 = int64_to_float32(*((int64_t *)&DT1), &env->fp_status);
}

148
F_HELPER(xto, d)
B
blueswir1 已提交
149 150 151
{
    DT0 = int64_to_float64(*((int64_t *)&DT1), &env->fp_status);
}
B
blueswir1 已提交
152

B
blueswir1 已提交
153 154 155 156 157
F_HELPER(xto, q)
{
    QT0 = int64_to_float128(*((int64_t *)&DT1), &env->fp_status);
}
#endif
158 159 160 161 162 163 164 165 166 167 168 169
#undef F_HELPER

/* floating point conversion */
void helper_fdtos(void)
{
    FT0 = float64_to_float32(DT1, &env->fp_status);
}

void helper_fstod(void)
{
    DT0 = float32_to_float64(FT1, &env->fp_status);
}
170

B
blueswir1 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
void helper_fqtos(void)
{
    FT0 = float128_to_float32(QT1, &env->fp_status);
}

void helper_fstoq(void)
{
    QT0 = float32_to_float128(FT1, &env->fp_status);
}

void helper_fqtod(void)
{
    DT0 = float128_to_float64(QT1, &env->fp_status);
}

void helper_fdtoq(void)
{
    QT0 = float64_to_float128(DT1, &env->fp_status);
}

191 192 193 194 195 196 197 198 199 200 201
/* Float to integer conversion.  */
void helper_fstoi(void)
{
    *((int32_t *)&FT0) = float32_to_int32_round_to_zero(FT1, &env->fp_status);
}

void helper_fdtoi(void)
{
    *((int32_t *)&FT0) = float64_to_int32_round_to_zero(DT1, &env->fp_status);
}

B
blueswir1 已提交
202 203 204 205 206
void helper_fqtoi(void)
{
    *((int32_t *)&FT0) = float128_to_int32_round_to_zero(QT1, &env->fp_status);
}

207 208 209 210 211 212 213 214 215 216 217
#ifdef TARGET_SPARC64
void helper_fstox(void)
{
    *((int64_t *)&DT0) = float32_to_int64_round_to_zero(FT1, &env->fp_status);
}

void helper_fdtox(void)
{
    *((int64_t *)&DT0) = float64_to_int64_round_to_zero(DT1, &env->fp_status);
}

B
blueswir1 已提交
218 219 220 221 222
void helper_fqtox(void)
{
    *((int64_t *)&DT0) = float128_to_int64_round_to_zero(QT1, &env->fp_status);
}

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 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 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 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 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 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 693 694 695 696 697 698 699
void helper_faligndata(void)
{
    uint64_t tmp;

    tmp = (*((uint64_t *)&DT0)) << ((env->gsr & 7) * 8);
    tmp |= (*((uint64_t *)&DT1)) >> (64 - (env->gsr & 7) * 8);
    *((uint64_t *)&DT0) = tmp;
}

void helper_movl_FT0_0(void)
{
    *((uint32_t *)&FT0) = 0;
}

void helper_movl_DT0_0(void)
{
    *((uint64_t *)&DT0) = 0;
}

void helper_movl_FT0_1(void)
{
    *((uint32_t *)&FT0) = 0xffffffff;
}

void helper_movl_DT0_1(void)
{
    *((uint64_t *)&DT0) = 0xffffffffffffffffULL;
}

void helper_fnot(void)
{
    *(uint64_t *)&DT0 = ~*(uint64_t *)&DT1;
}

void helper_fnots(void)
{
    *(uint32_t *)&FT0 = ~*(uint32_t *)&FT1;
}

void helper_fnor(void)
{
    *(uint64_t *)&DT0 = ~(*(uint64_t *)&DT0 | *(uint64_t *)&DT1);
}

void helper_fnors(void)
{
    *(uint32_t *)&FT0 = ~(*(uint32_t *)&FT0 | *(uint32_t *)&FT1);
}

void helper_for(void)
{
    *(uint64_t *)&DT0 |= *(uint64_t *)&DT1;
}

void helper_fors(void)
{
    *(uint32_t *)&FT0 |= *(uint32_t *)&FT1;
}

void helper_fxor(void)
{
    *(uint64_t *)&DT0 ^= *(uint64_t *)&DT1;
}

void helper_fxors(void)
{
    *(uint32_t *)&FT0 ^= *(uint32_t *)&FT1;
}

void helper_fand(void)
{
    *(uint64_t *)&DT0 &= *(uint64_t *)&DT1;
}

void helper_fands(void)
{
    *(uint32_t *)&FT0 &= *(uint32_t *)&FT1;
}

void helper_fornot(void)
{
    *(uint64_t *)&DT0 = *(uint64_t *)&DT0 | ~*(uint64_t *)&DT1;
}

void helper_fornots(void)
{
    *(uint32_t *)&FT0 = *(uint32_t *)&FT0 | ~*(uint32_t *)&FT1;
}

void helper_fandnot(void)
{
    *(uint64_t *)&DT0 = *(uint64_t *)&DT0 & ~*(uint64_t *)&DT1;
}

void helper_fandnots(void)
{
    *(uint32_t *)&FT0 = *(uint32_t *)&FT0 & ~*(uint32_t *)&FT1;
}

void helper_fnand(void)
{
    *(uint64_t *)&DT0 = ~(*(uint64_t *)&DT0 & *(uint64_t *)&DT1);
}

void helper_fnands(void)
{
    *(uint32_t *)&FT0 = ~(*(uint32_t *)&FT0 & *(uint32_t *)&FT1);
}

void helper_fxnor(void)
{
    *(uint64_t *)&DT0 ^= ~*(uint64_t *)&DT1;
}

void helper_fxnors(void)
{
    *(uint32_t *)&FT0 ^= ~*(uint32_t *)&FT1;
}

#ifdef WORDS_BIGENDIAN
#define VIS_B64(n) b[7 - (n)]
#define VIS_W64(n) w[3 - (n)]
#define VIS_SW64(n) sw[3 - (n)]
#define VIS_L64(n) l[1 - (n)]
#define VIS_B32(n) b[3 - (n)]
#define VIS_W32(n) w[1 - (n)]
#else
#define VIS_B64(n) b[n]
#define VIS_W64(n) w[n]
#define VIS_SW64(n) sw[n]
#define VIS_L64(n) l[n]
#define VIS_B32(n) b[n]
#define VIS_W32(n) w[n]
#endif

typedef union {
    uint8_t b[8];
    uint16_t w[4];
    int16_t sw[4];
    uint32_t l[2];
    float64 d;
} vis64;

typedef union {
    uint8_t b[4];
    uint16_t w[2];
    uint32_t l;
    float32 f;
} vis32;

void helper_fpmerge(void)
{
    vis64 s, d;

    s.d = DT0;
    d.d = DT1;

    // Reverse calculation order to handle overlap
    d.VIS_B64(7) = s.VIS_B64(3);
    d.VIS_B64(6) = d.VIS_B64(3);
    d.VIS_B64(5) = s.VIS_B64(2);
    d.VIS_B64(4) = d.VIS_B64(2);
    d.VIS_B64(3) = s.VIS_B64(1);
    d.VIS_B64(2) = d.VIS_B64(1);
    d.VIS_B64(1) = s.VIS_B64(0);
    //d.VIS_B64(0) = d.VIS_B64(0);

    DT0 = d.d;
}

void helper_fmul8x16(void)
{
    vis64 s, d;
    uint32_t tmp;

    s.d = DT0;
    d.d = DT1;

#define PMUL(r)                                                 \
    tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r);       \
    if ((tmp & 0xff) > 0x7f)                                    \
        tmp += 0x100;                                           \
    d.VIS_W64(r) = tmp >> 8;

    PMUL(0);
    PMUL(1);
    PMUL(2);
    PMUL(3);
#undef PMUL

    DT0 = d.d;
}

void helper_fmul8x16al(void)
{
    vis64 s, d;
    uint32_t tmp;

    s.d = DT0;
    d.d = DT1;

#define PMUL(r)                                                 \
    tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r);       \
    if ((tmp & 0xff) > 0x7f)                                    \
        tmp += 0x100;                                           \
    d.VIS_W64(r) = tmp >> 8;

    PMUL(0);
    PMUL(1);
    PMUL(2);
    PMUL(3);
#undef PMUL

    DT0 = d.d;
}

void helper_fmul8x16au(void)
{
    vis64 s, d;
    uint32_t tmp;

    s.d = DT0;
    d.d = DT1;

#define PMUL(r)                                                 \
    tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r);       \
    if ((tmp & 0xff) > 0x7f)                                    \
        tmp += 0x100;                                           \
    d.VIS_W64(r) = tmp >> 8;

    PMUL(0);
    PMUL(1);
    PMUL(2);
    PMUL(3);
#undef PMUL

    DT0 = d.d;
}

void helper_fmul8sux16(void)
{
    vis64 s, d;
    uint32_t tmp;

    s.d = DT0;
    d.d = DT1;

#define PMUL(r)                                                         \
    tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8);       \
    if ((tmp & 0xff) > 0x7f)                                            \
        tmp += 0x100;                                                   \
    d.VIS_W64(r) = tmp >> 8;

    PMUL(0);
    PMUL(1);
    PMUL(2);
    PMUL(3);
#undef PMUL

    DT0 = d.d;
}

void helper_fmul8ulx16(void)
{
    vis64 s, d;
    uint32_t tmp;

    s.d = DT0;
    d.d = DT1;

#define PMUL(r)                                                         \
    tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2));        \
    if ((tmp & 0xff) > 0x7f)                                            \
        tmp += 0x100;                                                   \
    d.VIS_W64(r) = tmp >> 8;

    PMUL(0);
    PMUL(1);
    PMUL(2);
    PMUL(3);
#undef PMUL

    DT0 = d.d;
}

void helper_fmuld8sux16(void)
{
    vis64 s, d;
    uint32_t tmp;

    s.d = DT0;
    d.d = DT1;

#define PMUL(r)                                                         \
    tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8);       \
    if ((tmp & 0xff) > 0x7f)                                            \
        tmp += 0x100;                                                   \
    d.VIS_L64(r) = tmp;

    // Reverse calculation order to handle overlap
    PMUL(1);
    PMUL(0);
#undef PMUL

    DT0 = d.d;
}

void helper_fmuld8ulx16(void)
{
    vis64 s, d;
    uint32_t tmp;

    s.d = DT0;
    d.d = DT1;

#define PMUL(r)                                                         \
    tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2));        \
    if ((tmp & 0xff) > 0x7f)                                            \
        tmp += 0x100;                                                   \
    d.VIS_L64(r) = tmp;

    // Reverse calculation order to handle overlap
    PMUL(1);
    PMUL(0);
#undef PMUL

    DT0 = d.d;
}

void helper_fexpand(void)
{
    vis32 s;
    vis64 d;

    s.l = (uint32_t)(*(uint64_t *)&DT0 & 0xffffffff);
    d.d = DT1;
    d.VIS_L64(0) = s.VIS_W32(0) << 4;
    d.VIS_L64(1) = s.VIS_W32(1) << 4;
    d.VIS_L64(2) = s.VIS_W32(2) << 4;
    d.VIS_L64(3) = s.VIS_W32(3) << 4;

    DT0 = d.d;
}

#define VIS_HELPER(name, F)                             \
    void name##16(void)                                 \
    {                                                   \
        vis64 s, d;                                     \
                                                        \
        s.d = DT0;                                      \
        d.d = DT1;                                      \
                                                        \
        d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0));   \
        d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1));   \
        d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2));   \
        d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3));   \
                                                        \
        DT0 = d.d;                                      \
    }                                                   \
                                                        \
    void name##16s(void)                                \
    {                                                   \
        vis32 s, d;                                     \
                                                        \
        s.f = FT0;                                      \
        d.f = FT1;                                      \
                                                        \
        d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0));   \
        d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1));   \
                                                        \
        FT0 = d.f;                                      \
    }                                                   \
                                                        \
    void name##32(void)                                 \
    {                                                   \
        vis64 s, d;                                     \
                                                        \
        s.d = DT0;                                      \
        d.d = DT1;                                      \
                                                        \
        d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0));   \
        d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1));   \
                                                        \
        DT0 = d.d;                                      \
    }                                                   \
                                                        \
    void name##32s(void)                                \
    {                                                   \
        vis32 s, d;                                     \
                                                        \
        s.f = FT0;                                      \
        d.f = FT1;                                      \
                                                        \
        d.l = F(d.l, s.l);                              \
                                                        \
        FT0 = d.f;                                      \
    }

#define FADD(a, b) ((a) + (b))
#define FSUB(a, b) ((a) - (b))
VIS_HELPER(helper_fpadd, FADD)
VIS_HELPER(helper_fpsub, FSUB)

#define VIS_CMPHELPER(name, F)                                        \
    void name##16(void)                                           \
    {                                                             \
        vis64 s, d;                                               \
                                                                  \
        s.d = DT0;                                                \
        d.d = DT1;                                                \
                                                                  \
        d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0;       \
        d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0;      \
        d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0;      \
        d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0;      \
                                                                  \
        DT0 = d.d;                                                \
    }                                                             \
                                                                  \
    void name##32(void)                                           \
    {                                                             \
        vis64 s, d;                                               \
                                                                  \
        s.d = DT0;                                                \
        d.d = DT1;                                                \
                                                                  \
        d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0;       \
        d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0;      \
                                                                  \
        DT0 = d.d;                                                \
    }

#define FCMPGT(a, b) ((a) > (b))
#define FCMPEQ(a, b) ((a) == (b))
#define FCMPLE(a, b) ((a) <= (b))
#define FCMPNE(a, b) ((a) != (b))

VIS_CMPHELPER(helper_fcmpgt, FCMPGT)
VIS_CMPHELPER(helper_fcmpeq, FCMPEQ)
VIS_CMPHELPER(helper_fcmple, FCMPLE)
VIS_CMPHELPER(helper_fcmpne, FCMPNE)
#endif

void helper_check_ieee_exceptions(void)
{
    target_ulong status;

    status = get_float_exception_flags(&env->fp_status);
    if (status) {
        /* Copy IEEE 754 flags into FSR */
        if (status & float_flag_invalid)
            env->fsr |= FSR_NVC;
        if (status & float_flag_overflow)
            env->fsr |= FSR_OFC;
        if (status & float_flag_underflow)
            env->fsr |= FSR_UFC;
        if (status & float_flag_divbyzero)
            env->fsr |= FSR_DZC;
        if (status & float_flag_inexact)
            env->fsr |= FSR_NXC;

        if ((env->fsr & FSR_CEXC_MASK) & ((env->fsr & FSR_TEM_MASK) >> 23)) {
            /* Unmasked exception, generate a trap */
            env->fsr |= FSR_FTT_IEEE_EXCP;
            raise_exception(TT_FP_EXCP);
        } else {
            /* Accumulate exceptions */
            env->fsr |= (env->fsr & FSR_CEXC_MASK) << 5;
        }
    }
}

void helper_clear_float_exceptions(void)
{
    set_float_exception_flags(0, &env->fp_status);
}

700
void helper_fabss(void)
701
{
B
bellard 已提交
702
    FT0 = float32_abs(FT1);
703 704
}

B
bellard 已提交
705
#ifdef TARGET_SPARC64
706
void helper_fabsd(void)
B
bellard 已提交
707 708 709
{
    DT0 = float64_abs(DT1);
}
B
blueswir1 已提交
710 711 712 713 714 715

void helper_fabsq(void)
{
    QT0 = float128_abs(QT1);
}
#endif
B
bellard 已提交
716

717
void helper_fsqrts(void)
718
{
B
bellard 已提交
719
    FT0 = float32_sqrt(FT1, &env->fp_status);
720 721
}

722
void helper_fsqrtd(void)
723
{
B
bellard 已提交
724
    DT0 = float64_sqrt(DT1, &env->fp_status);
725 726
}

B
blueswir1 已提交
727 728 729 730 731
void helper_fsqrtq(void)
{
    QT0 = float128_sqrt(QT1, &env->fp_status);
}

732
#define GEN_FCMP(name, size, reg1, reg2, FS, TRAP)                      \
733
    void glue(helper_, name) (void)                                     \
B
bellard 已提交
734
    {                                                                   \
B
blueswir1 已提交
735 736
        target_ulong new_fsr;                                           \
                                                                        \
B
bellard 已提交
737 738 739
        env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS);                     \
        switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) {   \
        case float_relation_unordered:                                  \
B
blueswir1 已提交
740
            new_fsr = (FSR_FCC1 | FSR_FCC0) << FS;                      \
741
            if ((env->fsr & FSR_NVM) || TRAP) {                         \
B
blueswir1 已提交
742
                env->fsr |= new_fsr;                                    \
743 744
                env->fsr |= FSR_NVC;                                    \
                env->fsr |= FSR_FTT_IEEE_EXCP;                          \
B
bellard 已提交
745 746 747 748 749 750
                raise_exception(TT_FP_EXCP);                            \
            } else {                                                    \
                env->fsr |= FSR_NVA;                                    \
            }                                                           \
            break;                                                      \
        case float_relation_less:                                       \
B
blueswir1 已提交
751
            new_fsr = FSR_FCC0 << FS;                                   \
B
bellard 已提交
752 753
            break;                                                      \
        case float_relation_greater:                                    \
B
blueswir1 已提交
754
            new_fsr = FSR_FCC1 << FS;                                   \
B
bellard 已提交
755 756
            break;                                                      \
        default:                                                        \
B
blueswir1 已提交
757
            new_fsr = 0;                                                \
B
bellard 已提交
758 759
            break;                                                      \
        }                                                               \
B
blueswir1 已提交
760
        env->fsr |= new_fsr;                                            \
761 762
    }

763 764 765 766 767
GEN_FCMP(fcmps, float32, FT0, FT1, 0, 0);
GEN_FCMP(fcmpd, float64, DT0, DT1, 0, 0);

GEN_FCMP(fcmpes, float32, FT0, FT1, 0, 1);
GEN_FCMP(fcmped, float64, DT0, DT1, 0, 1);
B
bellard 已提交
768

B
blueswir1 已提交
769 770 771
GEN_FCMP(fcmpq, float128, QT0, QT1, 0, 0);
GEN_FCMP(fcmpeq, float128, QT0, QT1, 0, 1);

B
bellard 已提交
772
#ifdef TARGET_SPARC64
773 774
GEN_FCMP(fcmps_fcc1, float32, FT0, FT1, 22, 0);
GEN_FCMP(fcmpd_fcc1, float64, DT0, DT1, 22, 0);
B
blueswir1 已提交
775
GEN_FCMP(fcmpq_fcc1, float128, QT0, QT1, 22, 0);
776 777 778

GEN_FCMP(fcmps_fcc2, float32, FT0, FT1, 24, 0);
GEN_FCMP(fcmpd_fcc2, float64, DT0, DT1, 24, 0);
B
blueswir1 已提交
779
GEN_FCMP(fcmpq_fcc2, float128, QT0, QT1, 24, 0);
780 781 782

GEN_FCMP(fcmps_fcc3, float32, FT0, FT1, 26, 0);
GEN_FCMP(fcmpd_fcc3, float64, DT0, DT1, 26, 0);
B
blueswir1 已提交
783
GEN_FCMP(fcmpq_fcc3, float128, QT0, QT1, 26, 0);
784 785 786

GEN_FCMP(fcmpes_fcc1, float32, FT0, FT1, 22, 1);
GEN_FCMP(fcmped_fcc1, float64, DT0, DT1, 22, 1);
B
blueswir1 已提交
787
GEN_FCMP(fcmpeq_fcc1, float128, QT0, QT1, 22, 1);
B
bellard 已提交
788

789 790
GEN_FCMP(fcmpes_fcc2, float32, FT0, FT1, 24, 1);
GEN_FCMP(fcmped_fcc2, float64, DT0, DT1, 24, 1);
B
blueswir1 已提交
791
GEN_FCMP(fcmpeq_fcc2, float128, QT0, QT1, 24, 1);
B
bellard 已提交
792

793 794
GEN_FCMP(fcmpes_fcc3, float32, FT0, FT1, 26, 1);
GEN_FCMP(fcmped_fcc3, float64, DT0, DT1, 26, 1);
B
blueswir1 已提交
795 796
GEN_FCMP(fcmpeq_fcc3, float128, QT0, QT1, 26, 1);
#endif
B
bellard 已提交
797

B
blueswir1 已提交
798 799
#if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
    defined(DEBUG_MXCC)
800 801 802
static void dump_mxcc(CPUState *env)
{
    printf("mxccdata: %016llx %016llx %016llx %016llx\n",
B
blueswir1 已提交
803 804
           env->mxccdata[0], env->mxccdata[1],
           env->mxccdata[2], env->mxccdata[3]);
805 806
    printf("mxccregs: %016llx %016llx %016llx %016llx\n"
           "          %016llx %016llx %016llx %016llx\n",
B
blueswir1 已提交
807 808 809 810
           env->mxccregs[0], env->mxccregs[1],
           env->mxccregs[2], env->mxccregs[3],
           env->mxccregs[4], env->mxccregs[5],
           env->mxccregs[6], env->mxccregs[7]);
811 812 813
}
#endif

B
blueswir1 已提交
814 815 816 817
#if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
    && defined(DEBUG_ASI)
static void dump_asi(const char *txt, target_ulong addr, int asi, int size,
                     uint64_t r1)
818 819 820 821
{
    switch (size)
    {
    case 1:
B
blueswir1 已提交
822 823
        DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %02" PRIx64 "\n", txt,
                    addr, asi, r1 & 0xff);
824 825
        break;
    case 2:
B
blueswir1 已提交
826 827
        DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %04" PRIx64 "\n", txt,
                    addr, asi, r1 & 0xffff);
828 829
        break;
    case 4:
B
blueswir1 已提交
830 831
        DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %08" PRIx64 "\n", txt,
                    addr, asi, r1 & 0xffffffff);
832 833
        break;
    case 8:
B
blueswir1 已提交
834 835
        DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %016" PRIx64 "\n", txt,
                    addr, asi, r1);
836 837 838 839 840
        break;
    }
}
#endif

B
blueswir1 已提交
841 842 843
#ifndef TARGET_SPARC64
#ifndef CONFIG_USER_ONLY
uint64_t helper_ld_asi(target_ulong addr, int asi, int size, int sign)
844
{
B
blueswir1 已提交
845
    uint64_t ret = 0;
846
#if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
B
blueswir1 已提交
847
    uint32_t last_addr = addr;
848
#endif
B
bellard 已提交
849

850
    helper_check_align(addr, size - 1);
B
bellard 已提交
851
    switch (asi) {
852
    case 2: /* SuperSparc MXCC registers */
B
blueswir1 已提交
853
        switch (addr) {
854
        case 0x01c00a00: /* MXCC control register */
B
blueswir1 已提交
855 856 857
            if (size == 8)
                ret = env->mxccregs[3];
            else
B
blueswir1 已提交
858 859
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
860 861 862 863 864
            break;
        case 0x01c00a04: /* MXCC control register */
            if (size == 4)
                ret = env->mxccregs[3];
            else
B
blueswir1 已提交
865 866
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
867
            break;
868 869
        case 0x01c00c00: /* Module reset register */
            if (size == 8) {
B
blueswir1 已提交
870
                ret = env->mxccregs[5];
871 872
                // should we do something here?
            } else
B
blueswir1 已提交
873 874
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
875
            break;
876
        case 0x01c00f00: /* MBus port address register */
B
blueswir1 已提交
877 878 879
            if (size == 8)
                ret = env->mxccregs[7];
            else
B
blueswir1 已提交
880 881
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
882 883
            break;
        default:
B
blueswir1 已提交
884 885
            DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr,
                         size);
886 887
            break;
        }
B
blueswir1 已提交
888 889
        DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
                     "addr = %08x -> ret = %08x,"
B
blueswir1 已提交
890
                     "addr = %08x\n", asi, size, sign, last_addr, ret, addr);
891 892 893
#ifdef DEBUG_MXCC
        dump_mxcc(env);
#endif
894
        break;
895
    case 3: /* MMU probe */
B
blueswir1 已提交
896 897 898
        {
            int mmulev;

B
blueswir1 已提交
899
            mmulev = (addr >> 8) & 15;
B
blueswir1 已提交
900 901
            if (mmulev > 4)
                ret = 0;
B
blueswir1 已提交
902 903 904 905
            else
                ret = mmu_probe(env, addr, mmulev);
            DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64 "\n",
                        addr, mmulev, ret);
B
blueswir1 已提交
906 907
        }
        break;
908
    case 4: /* read MMU regs */
B
blueswir1 已提交
909
        {
B
blueswir1 已提交
910
            int reg = (addr >> 8) & 0x1f;
911

B
blueswir1 已提交
912 913
            ret = env->mmuregs[reg];
            if (reg == 3) /* Fault status cleared on read */
B
blueswir1 已提交
914 915 916 917 918
                env->mmuregs[3] = 0;
            else if (reg == 0x13) /* Fault status read */
                ret = env->mmuregs[3];
            else if (reg == 0x14) /* Fault address read */
                ret = env->mmuregs[4];
B
blueswir1 已提交
919
            DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64 "\n", reg, ret);
B
blueswir1 已提交
920 921
        }
        break;
B
blueswir1 已提交
922 923 924 925
    case 5: // Turbosparc ITLB Diagnostic
    case 6: // Turbosparc DTLB Diagnostic
    case 7: // Turbosparc IOTLB Diagnostic
        break;
926 927 928
    case 9: /* Supervisor code access */
        switch(size) {
        case 1:
B
blueswir1 已提交
929
            ret = ldub_code(addr);
930 931
            break;
        case 2:
B
blueswir1 已提交
932
            ret = lduw_code(addr & ~1);
933 934 935
            break;
        default:
        case 4:
B
blueswir1 已提交
936
            ret = ldl_code(addr & ~3);
937 938
            break;
        case 8:
B
blueswir1 已提交
939
            ret = ldq_code(addr & ~7);
940 941 942
            break;
        }
        break;
943 944 945
    case 0xa: /* User data access */
        switch(size) {
        case 1:
B
blueswir1 已提交
946
            ret = ldub_user(addr);
947 948
            break;
        case 2:
B
blueswir1 已提交
949
            ret = lduw_user(addr & ~1);
950 951 952
            break;
        default:
        case 4:
B
blueswir1 已提交
953
            ret = ldl_user(addr & ~3);
954 955
            break;
        case 8:
B
blueswir1 已提交
956
            ret = ldq_user(addr & ~7);
957 958 959 960 961 962
            break;
        }
        break;
    case 0xb: /* Supervisor data access */
        switch(size) {
        case 1:
B
blueswir1 已提交
963
            ret = ldub_kernel(addr);
964 965
            break;
        case 2:
B
blueswir1 已提交
966
            ret = lduw_kernel(addr & ~1);
967 968 969
            break;
        default:
        case 4:
B
blueswir1 已提交
970
            ret = ldl_kernel(addr & ~3);
971 972
            break;
        case 8:
B
blueswir1 已提交
973
            ret = ldq_kernel(addr & ~7);
974 975 976
            break;
        }
        break;
977 978 979 980 981 982
    case 0xc: /* I-cache tag */
    case 0xd: /* I-cache data */
    case 0xe: /* D-cache tag */
    case 0xf: /* D-cache data */
        break;
    case 0x20: /* MMU passthrough */
B
bellard 已提交
983 984
        switch(size) {
        case 1:
B
blueswir1 已提交
985
            ret = ldub_phys(addr);
B
bellard 已提交
986 987
            break;
        case 2:
B
blueswir1 已提交
988
            ret = lduw_phys(addr & ~1);
B
bellard 已提交
989 990 991
            break;
        default:
        case 4:
B
blueswir1 已提交
992
            ret = ldl_phys(addr & ~3);
B
bellard 已提交
993
            break;
B
bellard 已提交
994
        case 8:
B
blueswir1 已提交
995
            ret = ldq_phys(addr & ~7);
B
blueswir1 已提交
996
            break;
B
bellard 已提交
997
        }
B
blueswir1 已提交
998
        break;
999
    case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1000 1001
        switch(size) {
        case 1:
B
blueswir1 已提交
1002
            ret = ldub_phys((target_phys_addr_t)addr
1003 1004 1005
                            | ((target_phys_addr_t)(asi & 0xf) << 32));
            break;
        case 2:
B
blueswir1 已提交
1006
            ret = lduw_phys((target_phys_addr_t)(addr & ~1)
1007 1008 1009 1010
                            | ((target_phys_addr_t)(asi & 0xf) << 32));
            break;
        default:
        case 4:
B
blueswir1 已提交
1011
            ret = ldl_phys((target_phys_addr_t)(addr & ~3)
1012 1013 1014
                           | ((target_phys_addr_t)(asi & 0xf) << 32));
            break;
        case 8:
B
blueswir1 已提交
1015
            ret = ldq_phys((target_phys_addr_t)(addr & ~7)
1016
                           | ((target_phys_addr_t)(asi & 0xf) << 32));
B
blueswir1 已提交
1017
            break;
1018
        }
B
blueswir1 已提交
1019
        break;
B
blueswir1 已提交
1020 1021 1022
    case 0x30: // Turbosparc secondary cache diagnostic
    case 0x31: // Turbosparc RAM snoop
    case 0x32: // Turbosparc page table descriptor diagnostic
B
blueswir1 已提交
1023 1024 1025
    case 0x39: /* data cache diagnostic register */
        ret = 0;
        break;
B
blueswir1 已提交
1026
    case 8: /* User code access, XXX */
1027
    default:
B
blueswir1 已提交
1028
        do_unassigned_access(addr, 0, 0, asi);
B
blueswir1 已提交
1029 1030
        ret = 0;
        break;
1031
    }
1032 1033 1034
    if (sign) {
        switch(size) {
        case 1:
B
blueswir1 已提交
1035
            ret = (int8_t) ret;
B
blueswir1 已提交
1036
            break;
1037
        case 2:
B
blueswir1 已提交
1038 1039 1040 1041
            ret = (int16_t) ret;
            break;
        case 4:
            ret = (int32_t) ret;
B
blueswir1 已提交
1042
            break;
1043 1044 1045 1046
        default:
            break;
        }
    }
1047
#ifdef DEBUG_ASI
B
blueswir1 已提交
1048
    dump_asi("read ", last_addr, asi, size, ret);
1049
#endif
B
blueswir1 已提交
1050
    return ret;
1051 1052
}

B
blueswir1 已提交
1053
void helper_st_asi(target_ulong addr, uint64_t val, int asi, int size)
1054
{
1055
    helper_check_align(addr, size - 1);
1056
    switch(asi) {
1057
    case 2: /* SuperSparc MXCC registers */
B
blueswir1 已提交
1058
        switch (addr) {
1059 1060
        case 0x01c00000: /* MXCC stream data register 0 */
            if (size == 8)
B
blueswir1 已提交
1061
                env->mxccdata[0] = val;
1062
            else
B
blueswir1 已提交
1063 1064
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
1065 1066 1067
            break;
        case 0x01c00008: /* MXCC stream data register 1 */
            if (size == 8)
B
blueswir1 已提交
1068
                env->mxccdata[1] = val;
1069
            else
B
blueswir1 已提交
1070 1071
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
1072 1073 1074
            break;
        case 0x01c00010: /* MXCC stream data register 2 */
            if (size == 8)
B
blueswir1 已提交
1075
                env->mxccdata[2] = val;
1076
            else
B
blueswir1 已提交
1077 1078
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
1079 1080 1081
            break;
        case 0x01c00018: /* MXCC stream data register 3 */
            if (size == 8)
B
blueswir1 已提交
1082
                env->mxccdata[3] = val;
1083
            else
B
blueswir1 已提交
1084 1085
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
1086 1087 1088
            break;
        case 0x01c00100: /* MXCC stream source */
            if (size == 8)
B
blueswir1 已提交
1089
                env->mxccregs[0] = val;
1090
            else
B
blueswir1 已提交
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
            env->mxccdata[0] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) +
                                        0);
            env->mxccdata[1] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) +
                                        8);
            env->mxccdata[2] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) +
                                        16);
            env->mxccdata[3] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) +
                                        24);
1101 1102 1103
            break;
        case 0x01c00200: /* MXCC stream destination */
            if (size == 8)
B
blueswir1 已提交
1104
                env->mxccregs[1] = val;
1105
            else
B
blueswir1 已提交
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
            stq_phys((env->mxccregs[1] & 0xffffffffULL) +  0,
                     env->mxccdata[0]);
            stq_phys((env->mxccregs[1] & 0xffffffffULL) +  8,
                     env->mxccdata[1]);
            stq_phys((env->mxccregs[1] & 0xffffffffULL) + 16,
                     env->mxccdata[2]);
            stq_phys((env->mxccregs[1] & 0xffffffffULL) + 24,
                     env->mxccdata[3]);
1116 1117 1118
            break;
        case 0x01c00a00: /* MXCC control register */
            if (size == 8)
B
blueswir1 已提交
1119
                env->mxccregs[3] = val;
1120
            else
B
blueswir1 已提交
1121 1122
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
1123 1124 1125
            break;
        case 0x01c00a04: /* MXCC control register */
            if (size == 4)
B
blueswir1 已提交
1126 1127
                env->mxccregs[3] = (env->mxccregs[0xa] & 0xffffffff00000000ULL)
                    | val;
1128
            else
B
blueswir1 已提交
1129 1130
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
1131 1132
            break;
        case 0x01c00e00: /* MXCC error register  */
1133
            // writing a 1 bit clears the error
1134
            if (size == 8)
B
blueswir1 已提交
1135
                env->mxccregs[6] &= ~val;
1136
            else
B
blueswir1 已提交
1137 1138
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
1139 1140 1141
            break;
        case 0x01c00f00: /* MBus port address register */
            if (size == 8)
B
blueswir1 已提交
1142
                env->mxccregs[7] = val;
1143
            else
B
blueswir1 已提交
1144 1145
                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
                             size);
1146 1147
            break;
        default:
B
blueswir1 已提交
1148 1149
            DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr,
                         size);
1150 1151
            break;
        }
B
blueswir1 已提交
1152 1153
        DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %08x\n", asi,
                     size, addr, val);
1154 1155 1156
#ifdef DEBUG_MXCC
        dump_mxcc(env);
#endif
1157
        break;
1158
    case 3: /* MMU flush */
B
blueswir1 已提交
1159 1160
        {
            int mmulev;
B
bellard 已提交
1161

B
blueswir1 已提交
1162
            mmulev = (addr >> 8) & 15;
1163
            DPRINTF_MMU("mmu flush level %d\n", mmulev);
B
blueswir1 已提交
1164 1165
            switch (mmulev) {
            case 0: // flush page
B
blueswir1 已提交
1166
                tlb_flush_page(env, addr & 0xfffff000);
B
blueswir1 已提交
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
                break;
            case 1: // flush segment (256k)
            case 2: // flush region (16M)
            case 3: // flush context (4G)
            case 4: // flush entire
                tlb_flush(env, 1);
                break;
            default:
                break;
            }
B
bellard 已提交
1177
#ifdef DEBUG_MMU
B
blueswir1 已提交
1178
            dump_mmu(env);
B
bellard 已提交
1179
#endif
B
blueswir1 已提交
1180
        }
1181
        break;
1182
    case 4: /* write MMU regs */
B
blueswir1 已提交
1183
        {
B
blueswir1 已提交
1184
            int reg = (addr >> 8) & 0x1f;
B
blueswir1 已提交
1185
            uint32_t oldreg;
1186

B
blueswir1 已提交
1187
            oldreg = env->mmuregs[reg];
B
bellard 已提交
1188
            switch(reg) {
1189
            case 0: // Control Register
B
blueswir1 已提交
1190
                env->mmuregs[reg] = (env->mmuregs[reg] & 0xff000000) |
B
blueswir1 已提交
1191
                                    (val & 0x00ffffff);
B
blueswir1 已提交
1192 1193
                // Mappings generated during no-fault mode or MMU
                // disabled mode are invalid in normal mode
B
blueswir1 已提交
1194 1195
                if ((oldreg & (MMU_E | MMU_NF | env->mmu_bm)) !=
                    (env->mmuregs[reg] & (MMU_E | MMU_NF | env->mmu_bm)))
B
bellard 已提交
1196 1197
                    tlb_flush(env, 1);
                break;
1198
            case 1: // Context Table Pointer Register
B
blueswir1 已提交
1199
                env->mmuregs[reg] = val & env->mmu_ctpr_mask;
1200 1201
                break;
            case 2: // Context Register
B
blueswir1 已提交
1202
                env->mmuregs[reg] = val & env->mmu_cxr_mask;
B
bellard 已提交
1203 1204 1205 1206 1207 1208
                if (oldreg != env->mmuregs[reg]) {
                    /* we flush when the MMU context changes because
                       QEMU has no MMU context support */
                    tlb_flush(env, 1);
                }
                break;
1209 1210 1211 1212
            case 3: // Synchronous Fault Status Register with Clear
            case 4: // Synchronous Fault Address Register
                break;
            case 0x10: // TLB Replacement Control Register
B
blueswir1 已提交
1213
                env->mmuregs[reg] = val & env->mmu_trcr_mask;
B
bellard 已提交
1214
                break;
1215
            case 0x13: // Synchronous Fault Status Register with Read and Clear
B
blueswir1 已提交
1216
                env->mmuregs[3] = val & env->mmu_sfsr_mask;
B
blueswir1 已提交
1217
                break;
1218
            case 0x14: // Synchronous Fault Address Register
B
blueswir1 已提交
1219
                env->mmuregs[4] = val;
B
blueswir1 已提交
1220
                break;
B
bellard 已提交
1221
            default:
B
blueswir1 已提交
1222
                env->mmuregs[reg] = val;
B
bellard 已提交
1223 1224 1225
                break;
            }
            if (oldreg != env->mmuregs[reg]) {
B
blueswir1 已提交
1226 1227
                DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
                            reg, oldreg, env->mmuregs[reg]);
B
bellard 已提交
1228
            }
1229
#ifdef DEBUG_MMU
B
blueswir1 已提交
1230
            dump_mmu(env);
B
bellard 已提交
1231
#endif
B
blueswir1 已提交
1232
        }
1233
        break;
B
blueswir1 已提交
1234 1235 1236 1237
    case 5: // Turbosparc ITLB Diagnostic
    case 6: // Turbosparc DTLB Diagnostic
    case 7: // Turbosparc IOTLB Diagnostic
        break;
1238 1239 1240
    case 0xa: /* User data access */
        switch(size) {
        case 1:
B
blueswir1 已提交
1241
            stb_user(addr, val);
1242 1243
            break;
        case 2:
B
blueswir1 已提交
1244
            stw_user(addr & ~1, val);
1245 1246 1247
            break;
        default:
        case 4:
B
blueswir1 已提交
1248
            stl_user(addr & ~3, val);
1249 1250
            break;
        case 8:
B
blueswir1 已提交
1251
            stq_user(addr & ~7, val);
1252 1253 1254 1255 1256 1257
            break;
        }
        break;
    case 0xb: /* Supervisor data access */
        switch(size) {
        case 1:
B
blueswir1 已提交
1258
            stb_kernel(addr, val);
1259 1260
            break;
        case 2:
B
blueswir1 已提交
1261
            stw_kernel(addr & ~1, val);
1262 1263 1264
            break;
        default:
        case 4:
B
blueswir1 已提交
1265
            stl_kernel(addr & ~3, val);
1266 1267
            break;
        case 8:
B
blueswir1 已提交
1268
            stq_kernel(addr & ~7, val);
1269 1270 1271
            break;
        }
        break;
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
    case 0xc: /* I-cache tag */
    case 0xd: /* I-cache data */
    case 0xe: /* D-cache tag */
    case 0xf: /* D-cache data */
    case 0x10: /* I/D-cache flush page */
    case 0x11: /* I/D-cache flush segment */
    case 0x12: /* I/D-cache flush region */
    case 0x13: /* I/D-cache flush context */
    case 0x14: /* I/D-cache flush user */
        break;
B
bellard 已提交
1282
    case 0x17: /* Block copy, sta access */
B
blueswir1 已提交
1283
        {
B
blueswir1 已提交
1284 1285
            // val = src
            // addr = dst
B
blueswir1 已提交
1286
            // copy 32 bytes
1287
            unsigned int i;
B
blueswir1 已提交
1288
            uint32_t src = val & ~3, dst = addr & ~3, temp;
1289

1290 1291 1292 1293
            for (i = 0; i < 32; i += 4, src += 4, dst += 4) {
                temp = ldl_kernel(src);
                stl_kernel(dst, temp);
            }
B
blueswir1 已提交
1294
        }
1295
        break;
B
bellard 已提交
1296
    case 0x1f: /* Block fill, stda access */
B
blueswir1 已提交
1297
        {
B
blueswir1 已提交
1298 1299
            // addr = dst
            // fill 32 bytes with val
1300
            unsigned int i;
B
blueswir1 已提交
1301
            uint32_t dst = addr & 7;
1302 1303 1304

            for (i = 0; i < 32; i += 8, dst += 8)
                stq_kernel(dst, val);
B
blueswir1 已提交
1305
        }
1306
        break;
1307
    case 0x20: /* MMU passthrough */
B
blueswir1 已提交
1308
        {
B
bellard 已提交
1309 1310
            switch(size) {
            case 1:
B
blueswir1 已提交
1311
                stb_phys(addr, val);
B
bellard 已提交
1312 1313
                break;
            case 2:
B
blueswir1 已提交
1314
                stw_phys(addr & ~1, val);
B
bellard 已提交
1315 1316 1317
                break;
            case 4:
            default:
B
blueswir1 已提交
1318
                stl_phys(addr & ~3, val);
B
bellard 已提交
1319
                break;
B
bellard 已提交
1320
            case 8:
B
blueswir1 已提交
1321
                stq_phys(addr & ~7, val);
B
bellard 已提交
1322
                break;
B
bellard 已提交
1323
            }
B
blueswir1 已提交
1324
        }
1325
        break;
B
blueswir1 已提交
1326
    case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
B
blueswir1 已提交
1327
        {
1328 1329
            switch(size) {
            case 1:
B
blueswir1 已提交
1330 1331
                stb_phys((target_phys_addr_t)addr
                         | ((target_phys_addr_t)(asi & 0xf) << 32), val);
1332 1333
                break;
            case 2:
B
blueswir1 已提交
1334 1335
                stw_phys((target_phys_addr_t)(addr & ~1)
                         | ((target_phys_addr_t)(asi & 0xf) << 32), val);
1336 1337 1338
                break;
            case 4:
            default:
B
blueswir1 已提交
1339 1340
                stl_phys((target_phys_addr_t)(addr & ~3)
                         | ((target_phys_addr_t)(asi & 0xf) << 32), val);
1341 1342
                break;
            case 8:
B
blueswir1 已提交
1343 1344
                stq_phys((target_phys_addr_t)(addr & ~7)
                         | ((target_phys_addr_t)(asi & 0xf) << 32), val);
1345 1346
                break;
            }
B
blueswir1 已提交
1347
        }
1348
        break;
B
blueswir1 已提交
1349 1350 1351
    case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
    case 0x31: // store buffer data, Ross RT620 I-cache flush or
               // Turbosparc snoop RAM
B
blueswir1 已提交
1352 1353
    case 0x32: // store buffer control or Turbosparc page table
               // descriptor diagnostic
1354 1355
    case 0x36: /* I-cache flash clear */
    case 0x37: /* D-cache flash clear */
B
blueswir1 已提交
1356 1357
    case 0x38: /* breakpoint diagnostics */
    case 0x4c: /* breakpoint action */
1358
        break;
B
blueswir1 已提交
1359
    case 8: /* User code access, XXX */
1360
    case 9: /* Supervisor code access, XXX */
1361
    default:
B
blueswir1 已提交
1362
        do_unassigned_access(addr, 1, 0, asi);
1363
        break;
1364
    }
1365
#ifdef DEBUG_ASI
B
blueswir1 已提交
1366
    dump_asi("write", addr, asi, size, val);
1367
#endif
1368 1369
}

1370 1371 1372 1373
#endif /* CONFIG_USER_ONLY */
#else /* TARGET_SPARC64 */

#ifdef CONFIG_USER_ONLY
B
blueswir1 已提交
1374
uint64_t helper_ld_asi(target_ulong addr, int asi, int size, int sign)
1375 1376
{
    uint64_t ret = 0;
B
blueswir1 已提交
1377 1378 1379
#if defined(DEBUG_ASI)
    target_ulong last_addr = addr;
#endif
1380 1381 1382 1383

    if (asi < 0x80)
        raise_exception(TT_PRIV_ACT);

1384 1385 1386
    helper_check_align(addr, size - 1);
    ABI32_MASK(addr);

1387 1388 1389 1390 1391 1392 1393 1394
    switch (asi) {
    case 0x80: // Primary
    case 0x82: // Primary no-fault
    case 0x88: // Primary LE
    case 0x8a: // Primary no-fault LE
        {
            switch(size) {
            case 1:
B
blueswir1 已提交
1395
                ret = ldub_raw(addr);
1396 1397
                break;
            case 2:
B
blueswir1 已提交
1398
                ret = lduw_raw(addr & ~1);
1399 1400
                break;
            case 4:
B
blueswir1 已提交
1401
                ret = ldl_raw(addr & ~3);
1402 1403 1404
                break;
            default:
            case 8:
B
blueswir1 已提交
1405
                ret = ldq_raw(addr & ~7);
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
                break;
            }
        }
        break;
    case 0x81: // Secondary
    case 0x83: // Secondary no-fault
    case 0x89: // Secondary LE
    case 0x8b: // Secondary no-fault LE
        // XXX
        break;
    default:
        break;
    }

    /* Convert from little endian */
    switch (asi) {
    case 0x88: // Primary LE
    case 0x89: // Secondary LE
    case 0x8a: // Primary no-fault LE
    case 0x8b: // Secondary no-fault LE
        switch(size) {
        case 2:
            ret = bswap16(ret);
B
blueswir1 已提交
1429
            break;
1430 1431
        case 4:
            ret = bswap32(ret);
B
blueswir1 已提交
1432
            break;
1433 1434
        case 8:
            ret = bswap64(ret);
B
blueswir1 已提交
1435
            break;
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447
        default:
            break;
        }
    default:
        break;
    }

    /* Convert to signed number */
    if (sign) {
        switch(size) {
        case 1:
            ret = (int8_t) ret;
B
blueswir1 已提交
1448
            break;
1449 1450
        case 2:
            ret = (int16_t) ret;
B
blueswir1 已提交
1451
            break;
1452 1453
        case 4:
            ret = (int32_t) ret;
B
blueswir1 已提交
1454
            break;
1455 1456 1457 1458
        default:
            break;
        }
    }
B
blueswir1 已提交
1459 1460 1461 1462
#ifdef DEBUG_ASI
    dump_asi("read ", last_addr, asi, size, ret);
#endif
    return ret;
1463 1464
}

B
blueswir1 已提交
1465
void helper_st_asi(target_ulong addr, target_ulong val, int asi, int size)
1466
{
B
blueswir1 已提交
1467 1468 1469
#ifdef DEBUG_ASI
    dump_asi("write", addr, asi, size, val);
#endif
1470 1471 1472
    if (asi < 0x80)
        raise_exception(TT_PRIV_ACT);

1473 1474 1475
    helper_check_align(addr, size - 1);
    ABI32_MASK(addr);

1476 1477 1478 1479 1480 1481
    /* Convert to little endian */
    switch (asi) {
    case 0x88: // Primary LE
    case 0x89: // Secondary LE
        switch(size) {
        case 2:
B
blueswir1 已提交
1482
            addr = bswap16(addr);
B
blueswir1 已提交
1483
            break;
1484
        case 4:
B
blueswir1 已提交
1485
            addr = bswap32(addr);
B
blueswir1 已提交
1486
            break;
1487
        case 8:
B
blueswir1 已提交
1488
            addr = bswap64(addr);
B
blueswir1 已提交
1489
            break;
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
        default:
            break;
        }
    default:
        break;
    }

    switch(asi) {
    case 0x80: // Primary
    case 0x88: // Primary LE
        {
            switch(size) {
            case 1:
B
blueswir1 已提交
1503
                stb_raw(addr, val);
1504 1505
                break;
            case 2:
B
blueswir1 已提交
1506
                stw_raw(addr & ~1, val);
1507 1508
                break;
            case 4:
B
blueswir1 已提交
1509
                stl_raw(addr & ~3, val);
1510 1511 1512
                break;
            case 8:
            default:
B
blueswir1 已提交
1513
                stq_raw(addr & ~7, val);
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527
                break;
            }
        }
        break;
    case 0x81: // Secondary
    case 0x89: // Secondary LE
        // XXX
        return;

    case 0x82: // Primary no-fault, RO
    case 0x83: // Secondary no-fault, RO
    case 0x8a: // Primary no-fault LE, RO
    case 0x8b: // Secondary no-fault LE, RO
    default:
B
blueswir1 已提交
1528
        do_unassigned_access(addr, 1, 0, 1);
1529 1530 1531 1532 1533
        return;
    }
}

#else /* CONFIG_USER_ONLY */
B
bellard 已提交
1534

B
blueswir1 已提交
1535
uint64_t helper_ld_asi(target_ulong addr, int asi, int size, int sign)
B
bellard 已提交
1536
{
B
bellard 已提交
1537
    uint64_t ret = 0;
B
blueswir1 已提交
1538 1539 1540
#if defined(DEBUG_ASI)
    target_ulong last_addr = addr;
#endif
B
bellard 已提交
1541

B
blueswir1 已提交
1542
    if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
B
blueswir1 已提交
1543
        || (asi >= 0x30 && asi < 0x80 && !(env->hpstate & HS_PRIV)))
B
blueswir1 已提交
1544
        raise_exception(TT_PRIV_ACT);
B
bellard 已提交
1545

1546
    helper_check_align(addr, size - 1);
B
bellard 已提交
1547
    switch (asi) {
1548 1549 1550 1551 1552 1553 1554
    case 0x10: // As if user primary
    case 0x18: // As if user primary LE
    case 0x80: // Primary
    case 0x82: // Primary no-fault
    case 0x88: // Primary LE
    case 0x8a: // Primary no-fault LE
        if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
B
blueswir1 已提交
1555 1556 1557
            if (env->hpstate & HS_PRIV) {
                switch(size) {
                case 1:
B
blueswir1 已提交
1558
                    ret = ldub_hypv(addr);
B
blueswir1 已提交
1559 1560
                    break;
                case 2:
B
blueswir1 已提交
1561
                    ret = lduw_hypv(addr & ~1);
B
blueswir1 已提交
1562 1563
                    break;
                case 4:
B
blueswir1 已提交
1564
                    ret = ldl_hypv(addr & ~3);
B
blueswir1 已提交
1565 1566 1567
                    break;
                default:
                case 8:
B
blueswir1 已提交
1568
                    ret = ldq_hypv(addr & ~7);
B
blueswir1 已提交
1569 1570 1571 1572 1573
                    break;
                }
            } else {
                switch(size) {
                case 1:
B
blueswir1 已提交
1574
                    ret = ldub_kernel(addr);
B
blueswir1 已提交
1575 1576
                    break;
                case 2:
B
blueswir1 已提交
1577
                    ret = lduw_kernel(addr & ~1);
B
blueswir1 已提交
1578 1579
                    break;
                case 4:
B
blueswir1 已提交
1580
                    ret = ldl_kernel(addr & ~3);
B
blueswir1 已提交
1581 1582 1583
                    break;
                default:
                case 8:
B
blueswir1 已提交
1584
                    ret = ldq_kernel(addr & ~7);
B
blueswir1 已提交
1585 1586
                    break;
                }
1587 1588 1589 1590
            }
        } else {
            switch(size) {
            case 1:
B
blueswir1 已提交
1591
                ret = ldub_user(addr);
1592 1593
                break;
            case 2:
B
blueswir1 已提交
1594
                ret = lduw_user(addr & ~1);
1595 1596
                break;
            case 4:
B
blueswir1 已提交
1597
                ret = ldl_user(addr & ~3);
1598 1599 1600
                break;
            default:
            case 8:
B
blueswir1 已提交
1601
                ret = ldq_user(addr & ~7);
1602 1603 1604 1605
                break;
            }
        }
        break;
B
bellard 已提交
1606 1607
    case 0x14: // Bypass
    case 0x15: // Bypass, non-cacheable
1608 1609
    case 0x1c: // Bypass LE
    case 0x1d: // Bypass, non-cacheable LE
B
blueswir1 已提交
1610
        {
B
bellard 已提交
1611 1612
            switch(size) {
            case 1:
B
blueswir1 已提交
1613
                ret = ldub_phys(addr);
B
bellard 已提交
1614 1615
                break;
            case 2:
B
blueswir1 已提交
1616
                ret = lduw_phys(addr & ~1);
B
bellard 已提交
1617 1618
                break;
            case 4:
B
blueswir1 已提交
1619
                ret = ldl_phys(addr & ~3);
B
bellard 已提交
1620 1621 1622
                break;
            default:
            case 8:
B
blueswir1 已提交
1623
                ret = ldq_phys(addr & ~7);
B
bellard 已提交
1624 1625
                break;
            }
B
blueswir1 已提交
1626 1627
            break;
        }
B
bellard 已提交
1628 1629 1630 1631 1632 1633 1634
    case 0x04: // Nucleus
    case 0x0c: // Nucleus Little Endian (LE)
    case 0x11: // As if user secondary
    case 0x19: // As if user secondary LE
    case 0x24: // Nucleus quad LDD 128 bit atomic
    case 0x2c: // Nucleus quad LDD 128 bit atomic
    case 0x4a: // UPA config
1635
    case 0x81: // Secondary
B
bellard 已提交
1636 1637 1638
    case 0x83: // Secondary no-fault
    case 0x89: // Secondary LE
    case 0x8b: // Secondary no-fault LE
B
blueswir1 已提交
1639 1640
        // XXX
        break;
B
bellard 已提交
1641
    case 0x45: // LSU
B
blueswir1 已提交
1642 1643
        ret = env->lsu;
        break;
B
bellard 已提交
1644
    case 0x50: // I-MMU regs
B
blueswir1 已提交
1645
        {
B
blueswir1 已提交
1646
            int reg = (addr >> 3) & 0xf;
B
bellard 已提交
1647

B
blueswir1 已提交
1648 1649 1650
            ret = env->immuregs[reg];
            break;
        }
B
bellard 已提交
1651 1652 1653
    case 0x51: // I-MMU 8k TSB pointer
    case 0x52: // I-MMU 64k TSB pointer
    case 0x55: // I-MMU data access
B
blueswir1 已提交
1654 1655
        // XXX
        break;
B
bellard 已提交
1656
    case 0x56: // I-MMU tag read
B
blueswir1 已提交
1657 1658 1659 1660 1661 1662
        {
            unsigned int i;

            for (i = 0; i < 64; i++) {
                // Valid, ctx match, vaddr match
                if ((env->itlb_tte[i] & 0x8000000000000000ULL) != 0 &&
B
blueswir1 已提交
1663
                    env->itlb_tag[i] == addr) {
B
blueswir1 已提交
1664 1665 1666 1667 1668 1669
                    ret = env->itlb_tag[i];
                    break;
                }
            }
            break;
        }
B
bellard 已提交
1670
    case 0x58: // D-MMU regs
B
blueswir1 已提交
1671
        {
B
blueswir1 已提交
1672
            int reg = (addr >> 3) & 0xf;
B
bellard 已提交
1673

B
blueswir1 已提交
1674 1675 1676
            ret = env->dmmuregs[reg];
            break;
        }
B
bellard 已提交
1677
    case 0x5e: // D-MMU tag read
B
blueswir1 已提交
1678 1679 1680 1681 1682 1683
        {
            unsigned int i;

            for (i = 0; i < 64; i++) {
                // Valid, ctx match, vaddr match
                if ((env->dtlb_tte[i] & 0x8000000000000000ULL) != 0 &&
B
blueswir1 已提交
1684
                    env->dtlb_tag[i] == addr) {
B
blueswir1 已提交
1685 1686 1687 1688 1689 1690
                    ret = env->dtlb_tag[i];
                    break;
                }
            }
            break;
        }
B
bellard 已提交
1691 1692 1693 1694
    case 0x59: // D-MMU 8k TSB pointer
    case 0x5a: // D-MMU 64k TSB pointer
    case 0x5b: // D-MMU data pointer
    case 0x5d: // D-MMU data access
B
bellard 已提交
1695 1696 1697
    case 0x48: // Interrupt dispatch, RO
    case 0x49: // Interrupt data receive
    case 0x7f: // Incoming interrupt vector, RO
B
blueswir1 已提交
1698 1699
        // XXX
        break;
B
bellard 已提交
1700 1701 1702 1703
    case 0x54: // I-MMU data in, WO
    case 0x57: // I-MMU demap, WO
    case 0x5c: // D-MMU data in, WO
    case 0x5f: // D-MMU demap, WO
B
bellard 已提交
1704
    case 0x77: // Interrupt vector, WO
B
bellard 已提交
1705
    default:
B
blueswir1 已提交
1706
        do_unassigned_access(addr, 0, 0, 1);
B
blueswir1 已提交
1707 1708
        ret = 0;
        break;
B
bellard 已提交
1709
    }
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724

    /* Convert from little endian */
    switch (asi) {
    case 0x0c: // Nucleus Little Endian (LE)
    case 0x18: // As if user primary LE
    case 0x19: // As if user secondary LE
    case 0x1c: // Bypass LE
    case 0x1d: // Bypass, non-cacheable LE
    case 0x88: // Primary LE
    case 0x89: // Secondary LE
    case 0x8a: // Primary no-fault LE
    case 0x8b: // Secondary no-fault LE
        switch(size) {
        case 2:
            ret = bswap16(ret);
B
blueswir1 已提交
1725
            break;
1726 1727
        case 4:
            ret = bswap32(ret);
B
blueswir1 已提交
1728
            break;
1729 1730
        case 8:
            ret = bswap64(ret);
B
blueswir1 已提交
1731
            break;
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
        default:
            break;
        }
    default:
        break;
    }

    /* Convert to signed number */
    if (sign) {
        switch(size) {
        case 1:
            ret = (int8_t) ret;
B
blueswir1 已提交
1744
            break;
1745 1746
        case 2:
            ret = (int16_t) ret;
B
blueswir1 已提交
1747
            break;
1748 1749
        case 4:
            ret = (int32_t) ret;
B
blueswir1 已提交
1750
            break;
1751 1752 1753 1754
        default:
            break;
        }
    }
B
blueswir1 已提交
1755 1756 1757 1758
#ifdef DEBUG_ASI
    dump_asi("read ", last_addr, asi, size, ret);
#endif
    return ret;
B
bellard 已提交
1759 1760
}

B
blueswir1 已提交
1761
void helper_st_asi(target_ulong addr, target_ulong val, int asi, int size)
B
bellard 已提交
1762
{
B
blueswir1 已提交
1763 1764 1765
#ifdef DEBUG_ASI
    dump_asi("write", addr, asi, size, val);
#endif
B
blueswir1 已提交
1766
    if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
B
blueswir1 已提交
1767
        || (asi >= 0x30 && asi < 0x80 && !(env->hpstate & HS_PRIV)))
B
blueswir1 已提交
1768
        raise_exception(TT_PRIV_ACT);
B
bellard 已提交
1769

1770
    helper_check_align(addr, size - 1);
1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
    /* Convert to little endian */
    switch (asi) {
    case 0x0c: // Nucleus Little Endian (LE)
    case 0x18: // As if user primary LE
    case 0x19: // As if user secondary LE
    case 0x1c: // Bypass LE
    case 0x1d: // Bypass, non-cacheable LE
    case 0x88: // Primary LE
    case 0x89: // Secondary LE
        switch(size) {
        case 2:
B
blueswir1 已提交
1782
            addr = bswap16(addr);
B
blueswir1 已提交
1783
            break;
1784
        case 4:
B
blueswir1 已提交
1785
            addr = bswap32(addr);
B
blueswir1 已提交
1786
            break;
1787
        case 8:
B
blueswir1 已提交
1788
            addr = bswap64(addr);
B
blueswir1 已提交
1789
            break;
1790 1791 1792 1793 1794 1795 1796
        default:
            break;
        }
    default:
        break;
    }

B
bellard 已提交
1797
    switch(asi) {
1798 1799 1800 1801 1802
    case 0x10: // As if user primary
    case 0x18: // As if user primary LE
    case 0x80: // Primary
    case 0x88: // Primary LE
        if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
B
blueswir1 已提交
1803 1804 1805
            if (env->hpstate & HS_PRIV) {
                switch(size) {
                case 1:
B
blueswir1 已提交
1806
                    stb_hypv(addr, val);
B
blueswir1 已提交
1807 1808
                    break;
                case 2:
B
blueswir1 已提交
1809
                    stw_hypv(addr & ~1, val);
B
blueswir1 已提交
1810 1811
                    break;
                case 4:
B
blueswir1 已提交
1812
                    stl_hypv(addr & ~3, val);
B
blueswir1 已提交
1813 1814 1815
                    break;
                case 8:
                default:
B
blueswir1 已提交
1816
                    stq_hypv(addr & ~7, val);
B
blueswir1 已提交
1817 1818 1819 1820 1821
                    break;
                }
            } else {
                switch(size) {
                case 1:
B
blueswir1 已提交
1822
                    stb_kernel(addr, val);
B
blueswir1 已提交
1823 1824
                    break;
                case 2:
B
blueswir1 已提交
1825
                    stw_kernel(addr & ~1, val);
B
blueswir1 已提交
1826 1827
                    break;
                case 4:
B
blueswir1 已提交
1828
                    stl_kernel(addr & ~3, val);
B
blueswir1 已提交
1829 1830 1831
                    break;
                case 8:
                default:
B
blueswir1 已提交
1832
                    stq_kernel(addr & ~7, val);
B
blueswir1 已提交
1833 1834
                    break;
                }
1835 1836 1837 1838
            }
        } else {
            switch(size) {
            case 1:
B
blueswir1 已提交
1839
                stb_user(addr, val);
1840 1841
                break;
            case 2:
B
blueswir1 已提交
1842
                stw_user(addr & ~1, val);
1843 1844
                break;
            case 4:
B
blueswir1 已提交
1845
                stl_user(addr & ~3, val);
1846 1847 1848
                break;
            case 8:
            default:
B
blueswir1 已提交
1849
                stq_user(addr & ~7, val);
1850 1851 1852 1853
                break;
            }
        }
        break;
B
bellard 已提交
1854 1855
    case 0x14: // Bypass
    case 0x15: // Bypass, non-cacheable
1856 1857
    case 0x1c: // Bypass LE
    case 0x1d: // Bypass, non-cacheable LE
B
blueswir1 已提交
1858
        {
B
bellard 已提交
1859 1860
            switch(size) {
            case 1:
B
blueswir1 已提交
1861
                stb_phys(addr, val);
B
bellard 已提交
1862 1863
                break;
            case 2:
B
blueswir1 已提交
1864
                stw_phys(addr & ~1, val);
B
bellard 已提交
1865 1866
                break;
            case 4:
B
blueswir1 已提交
1867
                stl_phys(addr & ~3, val);
B
bellard 已提交
1868 1869 1870
                break;
            case 8:
            default:
B
blueswir1 已提交
1871
                stq_phys(addr & ~7, val);
B
bellard 已提交
1872 1873
                break;
            }
B
blueswir1 已提交
1874 1875
        }
        return;
B
bellard 已提交
1876 1877 1878 1879 1880 1881 1882
    case 0x04: // Nucleus
    case 0x0c: // Nucleus Little Endian (LE)
    case 0x11: // As if user secondary
    case 0x19: // As if user secondary LE
    case 0x24: // Nucleus quad LDD 128 bit atomic
    case 0x2c: // Nucleus quad LDD 128 bit atomic
    case 0x4a: // UPA config
B
blueswir1 已提交
1883
    case 0x81: // Secondary
B
bellard 已提交
1884
    case 0x89: // Secondary LE
B
blueswir1 已提交
1885 1886
        // XXX
        return;
B
bellard 已提交
1887
    case 0x45: // LSU
B
blueswir1 已提交
1888 1889 1890 1891
        {
            uint64_t oldreg;

            oldreg = env->lsu;
B
blueswir1 已提交
1892
            env->lsu = val & (DMMU_E | IMMU_E);
B
blueswir1 已提交
1893 1894 1895
            // Mappings generated during D/I MMU disabled mode are
            // invalid in normal mode
            if (oldreg != env->lsu) {
B
blueswir1 已提交
1896 1897
                DPRINTF_MMU("LSU change: 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
                            oldreg, env->lsu);
B
bellard 已提交
1898
#ifdef DEBUG_MMU
B
blueswir1 已提交
1899
                dump_mmu(env);
B
bellard 已提交
1900
#endif
B
blueswir1 已提交
1901 1902 1903 1904
                tlb_flush(env, 1);
            }
            return;
        }
B
bellard 已提交
1905
    case 0x50: // I-MMU regs
B
blueswir1 已提交
1906
        {
B
blueswir1 已提交
1907
            int reg = (addr >> 3) & 0xf;
B
blueswir1 已提交
1908
            uint64_t oldreg;
1909

B
blueswir1 已提交
1910
            oldreg = env->immuregs[reg];
B
bellard 已提交
1911 1912 1913 1914 1915 1916 1917 1918 1919 1920
            switch(reg) {
            case 0: // RO
            case 4:
                return;
            case 1: // Not in I-MMU
            case 2:
            case 7:
            case 8:
                return;
            case 3: // SFSR
B
blueswir1 已提交
1921 1922
                if ((val & 1) == 0)
                    val = 0; // Clear SFSR
B
bellard 已提交
1923 1924 1925 1926 1927 1928
                break;
            case 5: // TSB access
            case 6: // Tag access
            default:
                break;
            }
B
blueswir1 已提交
1929
            env->immuregs[reg] = val;
B
bellard 已提交
1930
            if (oldreg != env->immuregs[reg]) {
B
blueswir1 已提交
1931 1932
                DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64 " -> 0x%08"
                            PRIx64 "\n", reg, oldreg, env->immuregs[reg]);
B
bellard 已提交
1933
            }
1934
#ifdef DEBUG_MMU
B
blueswir1 已提交
1935
            dump_mmu(env);
B
bellard 已提交
1936
#endif
B
blueswir1 已提交
1937 1938
            return;
        }
B
bellard 已提交
1939
    case 0x54: // I-MMU data in
B
blueswir1 已提交
1940 1941 1942 1943 1944 1945 1946
        {
            unsigned int i;

            // Try finding an invalid entry
            for (i = 0; i < 64; i++) {
                if ((env->itlb_tte[i] & 0x8000000000000000ULL) == 0) {
                    env->itlb_tag[i] = env->immuregs[6];
B
blueswir1 已提交
1947
                    env->itlb_tte[i] = val;
B
blueswir1 已提交
1948 1949 1950 1951 1952 1953 1954
                    return;
                }
            }
            // Try finding an unlocked entry
            for (i = 0; i < 64; i++) {
                if ((env->itlb_tte[i] & 0x40) == 0) {
                    env->itlb_tag[i] = env->immuregs[6];
B
blueswir1 已提交
1955
                    env->itlb_tte[i] = val;
B
blueswir1 已提交
1956 1957 1958 1959 1960 1961
                    return;
                }
            }
            // error state?
            return;
        }
B
bellard 已提交
1962
    case 0x55: // I-MMU data access
B
blueswir1 已提交
1963
        {
B
blueswir1 已提交
1964
            unsigned int i = (addr >> 3) & 0x3f;
B
bellard 已提交
1965

B
blueswir1 已提交
1966
            env->itlb_tag[i] = env->immuregs[6];
B
blueswir1 已提交
1967
            env->itlb_tte[i] = val;
B
blueswir1 已提交
1968 1969
            return;
        }
B
bellard 已提交
1970
    case 0x57: // I-MMU demap
B
blueswir1 已提交
1971 1972
        // XXX
        return;
B
bellard 已提交
1973
    case 0x58: // D-MMU regs
B
blueswir1 已提交
1974
        {
B
blueswir1 已提交
1975
            int reg = (addr >> 3) & 0xf;
B
blueswir1 已提交
1976
            uint64_t oldreg;
1977

B
blueswir1 已提交
1978
            oldreg = env->dmmuregs[reg];
B
bellard 已提交
1979 1980 1981 1982 1983
            switch(reg) {
            case 0: // RO
            case 4:
                return;
            case 3: // SFSR
B
blueswir1 已提交
1984 1985
                if ((val & 1) == 0) {
                    val = 0; // Clear SFSR, Fault address
B
blueswir1 已提交
1986 1987
                    env->dmmuregs[4] = 0;
                }
B
blueswir1 已提交
1988
                env->dmmuregs[reg] = val;
B
bellard 已提交
1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
                break;
            case 1: // Primary context
            case 2: // Secondary context
            case 5: // TSB access
            case 6: // Tag access
            case 7: // Virtual Watchpoint
            case 8: // Physical Watchpoint
            default:
                break;
            }
B
blueswir1 已提交
1999
            env->dmmuregs[reg] = val;
B
bellard 已提交
2000
            if (oldreg != env->dmmuregs[reg]) {
B
blueswir1 已提交
2001 2002
                DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64 " -> 0x%08"
                            PRIx64 "\n", reg, oldreg, env->dmmuregs[reg]);
B
bellard 已提交
2003
            }
2004
#ifdef DEBUG_MMU
B
blueswir1 已提交
2005
            dump_mmu(env);
B
bellard 已提交
2006
#endif
B
blueswir1 已提交
2007 2008
            return;
        }
B
bellard 已提交
2009
    case 0x5c: // D-MMU data in
B
blueswir1 已提交
2010 2011 2012 2013 2014 2015 2016
        {
            unsigned int i;

            // Try finding an invalid entry
            for (i = 0; i < 64; i++) {
                if ((env->dtlb_tte[i] & 0x8000000000000000ULL) == 0) {
                    env->dtlb_tag[i] = env->dmmuregs[6];
B
blueswir1 已提交
2017
                    env->dtlb_tte[i] = val;
B
blueswir1 已提交
2018 2019 2020 2021 2022 2023 2024
                    return;
                }
            }
            // Try finding an unlocked entry
            for (i = 0; i < 64; i++) {
                if ((env->dtlb_tte[i] & 0x40) == 0) {
                    env->dtlb_tag[i] = env->dmmuregs[6];
B
blueswir1 已提交
2025
                    env->dtlb_tte[i] = val;
B
blueswir1 已提交
2026 2027 2028 2029 2030 2031
                    return;
                }
            }
            // error state?
            return;
        }
B
bellard 已提交
2032
    case 0x5d: // D-MMU data access
B
blueswir1 已提交
2033
        {
B
blueswir1 已提交
2034
            unsigned int i = (addr >> 3) & 0x3f;
B
bellard 已提交
2035

B
blueswir1 已提交
2036
            env->dtlb_tag[i] = env->dmmuregs[6];
B
blueswir1 已提交
2037
            env->dtlb_tte[i] = val;
B
blueswir1 已提交
2038 2039
            return;
        }
B
bellard 已提交
2040
    case 0x5f: // D-MMU demap
B
bellard 已提交
2041
    case 0x49: // Interrupt data receive
B
blueswir1 已提交
2042 2043
        // XXX
        return;
B
bellard 已提交
2044 2045 2046 2047 2048 2049 2050
    case 0x51: // I-MMU 8k TSB pointer, RO
    case 0x52: // I-MMU 64k TSB pointer, RO
    case 0x56: // I-MMU tag read, RO
    case 0x59: // D-MMU 8k TSB pointer, RO
    case 0x5a: // D-MMU 64k TSB pointer, RO
    case 0x5b: // D-MMU data pointer, RO
    case 0x5e: // D-MMU tag read, RO
B
bellard 已提交
2051 2052 2053 2054 2055 2056
    case 0x48: // Interrupt dispatch, RO
    case 0x7f: // Incoming interrupt vector, RO
    case 0x82: // Primary no-fault, RO
    case 0x83: // Secondary no-fault, RO
    case 0x8a: // Primary no-fault LE, RO
    case 0x8b: // Secondary no-fault LE, RO
B
bellard 已提交
2057
    default:
B
blueswir1 已提交
2058
        do_unassigned_access(addr, 1, 0, 1);
B
blueswir1 已提交
2059
        return;
B
bellard 已提交
2060 2061
    }
}
2062
#endif /* CONFIG_USER_ONLY */
2063

B
blueswir1 已提交
2064
void helper_ldf_asi(target_ulong addr, int asi, int size, int rd)
2065 2066
{
    unsigned int i;
B
blueswir1 已提交
2067
    target_ulong val;
2068

2069
    helper_check_align(addr, 3);
2070 2071 2072 2073 2074
    switch (asi) {
    case 0xf0: // Block load primary
    case 0xf1: // Block load secondary
    case 0xf8: // Block load primary LE
    case 0xf9: // Block load secondary LE
B
blueswir1 已提交
2075 2076 2077 2078
        if (rd & 7) {
            raise_exception(TT_ILL_INSN);
            return;
        }
2079
        helper_check_align(addr, 0x3f);
B
blueswir1 已提交
2080
        for (i = 0; i < 16; i++) {
B
blueswir1 已提交
2081 2082
            *(uint32_t *)&env->fpr[rd++] = helper_ld_asi(addr, asi & 0x8f, 4,
                                                         0);
B
blueswir1 已提交
2083
            addr += 4;
2084 2085 2086 2087 2088 2089 2090
        }

        return;
    default:
        break;
    }

B
blueswir1 已提交
2091
    val = helper_ld_asi(addr, asi, size, 0);
2092 2093 2094
    switch(size) {
    default:
    case 4:
B
blueswir1 已提交
2095
        *((uint32_t *)&FT0) = val;
2096 2097
        break;
    case 8:
B
blueswir1 已提交
2098
        *((int64_t *)&DT0) = val;
2099
        break;
B
blueswir1 已提交
2100 2101 2102
    case 16:
        // XXX
        break;
2103 2104 2105
    }
}

B
blueswir1 已提交
2106
void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
2107 2108
{
    unsigned int i;
B
blueswir1 已提交
2109
    target_ulong val = 0;
2110

2111
    helper_check_align(addr, 3);
2112 2113 2114 2115 2116
    switch (asi) {
    case 0xf0: // Block store primary
    case 0xf1: // Block store secondary
    case 0xf8: // Block store primary LE
    case 0xf9: // Block store secondary LE
B
blueswir1 已提交
2117 2118 2119 2120
        if (rd & 7) {
            raise_exception(TT_ILL_INSN);
            return;
        }
2121
        helper_check_align(addr, 0x3f);
B
blueswir1 已提交
2122
        for (i = 0; i < 16; i++) {
B
blueswir1 已提交
2123 2124 2125
            val = *(uint32_t *)&env->fpr[rd++];
            helper_st_asi(addr, val, asi & 0x8f, 4);
            addr += 4;
2126 2127 2128 2129 2130 2131 2132 2133 2134 2135
        }

        return;
    default:
        break;
    }

    switch(size) {
    default:
    case 4:
B
blueswir1 已提交
2136
        val = *((uint32_t *)&FT0);
2137 2138
        break;
    case 8:
B
blueswir1 已提交
2139
        val = *((int64_t *)&DT0);
2140
        break;
B
blueswir1 已提交
2141 2142 2143
    case 16:
        // XXX
        break;
2144
    }
B
blueswir1 已提交
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158
    helper_st_asi(addr, val, asi, size);
}

target_ulong helper_cas_asi(target_ulong addr, target_ulong val1,
                            target_ulong val2, uint32_t asi)
{
    target_ulong ret;

    val1 &= 0xffffffffUL;
    ret = helper_ld_asi(addr, asi, 4, 0);
    ret &= 0xffffffffUL;
    if (val1 == ret)
        helper_st_asi(addr, val2 & 0xffffffffUL, asi, 4);
    return ret;
2159 2160
}

B
blueswir1 已提交
2161 2162 2163 2164 2165 2166 2167 2168 2169 2170
target_ulong helper_casx_asi(target_ulong addr, target_ulong val1,
                             target_ulong val2, uint32_t asi)
{
    target_ulong ret;

    ret = helper_ld_asi(addr, asi, 8, 0);
    if (val1 == ret)
        helper_st_asi(addr, val2, asi, 8);
    return ret;
}
2171
#endif /* TARGET_SPARC64 */
B
bellard 已提交
2172 2173

#ifndef TARGET_SPARC64
B
blueswir1 已提交
2174
void helper_rett(void)
2175
{
2176 2177
    unsigned int cwp;

2178 2179 2180
    if (env->psret == 1)
        raise_exception(TT_ILL_INSN);

2181
    env->psret = 1;
2182
    cwp = (env->cwp + 1) & (NWINDOWS - 1);
2183 2184 2185 2186 2187 2188
    if (env->wim & (1 << cwp)) {
        raise_exception(TT_WIN_UNF);
    }
    set_cwp(cwp);
    env->psrs = env->psrps;
}
B
bellard 已提交
2189
#endif
2190

B
blueswir1 已提交
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
target_ulong helper_udiv(target_ulong a, target_ulong b)
{
    uint64_t x0;
    uint32_t x1;

    x0 = a | ((uint64_t) (env->y) << 32);
    x1 = b;

    if (x1 == 0) {
        raise_exception(TT_DIV_ZERO);
    }

    x0 = x0 / x1;
    if (x0 > 0xffffffff) {
        env->cc_src2 = 1;
        return 0xffffffff;
    } else {
        env->cc_src2 = 0;
        return x0;
    }
}

target_ulong helper_sdiv(target_ulong a, target_ulong b)
{
    int64_t x0;
    int32_t x1;

    x0 = a | ((int64_t) (env->y) << 32);
    x1 = b;

    if (x1 == 0) {
        raise_exception(TT_DIV_ZERO);
    }

    x0 = x0 / x1;
    if ((int32_t) x0 != x0) {
        env->cc_src2 = 1;
        return x0 < 0? 0x80000000: 0x7fffffff;
    } else {
        env->cc_src2 = 0;
        return x0;
    }
}

B
blueswir1 已提交
2235 2236 2237 2238 2239
uint64_t helper_pack64(target_ulong high, target_ulong low)
{
    return ((uint64_t)high << 32) | (uint64_t)(low & 0xffffffff);
}

B
blueswir1 已提交
2240 2241
void helper_stdf(target_ulong addr, int mem_idx)
{
2242
    helper_check_align(addr, 7);
B
blueswir1 已提交
2243 2244 2245
#if !defined(CONFIG_USER_ONLY)
    switch (mem_idx) {
    case 0:
2246
        stfq_user(addr, DT0);
B
blueswir1 已提交
2247 2248
        break;
    case 1:
2249
        stfq_kernel(addr, DT0);
B
blueswir1 已提交
2250 2251 2252
        break;
#ifdef TARGET_SPARC64
    case 2:
2253
        stfq_hypv(addr, DT0);
B
blueswir1 已提交
2254 2255 2256 2257 2258 2259
        break;
#endif
    default:
        break;
    }
#else
2260 2261
    ABI32_MASK(addr);
    stfq_raw(addr, DT0);
B
blueswir1 已提交
2262 2263 2264 2265 2266
#endif
}

void helper_lddf(target_ulong addr, int mem_idx)
{
2267
    helper_check_align(addr, 7);
B
blueswir1 已提交
2268 2269 2270
#if !defined(CONFIG_USER_ONLY)
    switch (mem_idx) {
    case 0:
2271
        DT0 = ldfq_user(addr);
B
blueswir1 已提交
2272 2273
        break;
    case 1:
2274
        DT0 = ldfq_kernel(addr);
B
blueswir1 已提交
2275 2276 2277
        break;
#ifdef TARGET_SPARC64
    case 2:
2278
        DT0 = ldfq_hypv(addr);
B
blueswir1 已提交
2279 2280 2281 2282 2283 2284
        break;
#endif
    default:
        break;
    }
#else
2285 2286
    ABI32_MASK(addr);
    DT0 = ldfq_raw(addr);
B
blueswir1 已提交
2287 2288 2289
#endif
}

B
blueswir1 已提交
2290
void helper_ldqf(target_ulong addr, int mem_idx)
B
blueswir1 已提交
2291 2292 2293 2294
{
    // XXX add 128 bit load
    CPU_QuadU u;

2295
    helper_check_align(addr, 7);
B
blueswir1 已提交
2296 2297 2298
#if !defined(CONFIG_USER_ONLY)
    switch (mem_idx) {
    case 0:
2299 2300
        u.ll.upper = ldq_user(addr);
        u.ll.lower = ldq_user(addr + 8);
B
blueswir1 已提交
2301 2302 2303
        QT0 = u.q;
        break;
    case 1:
2304 2305
        u.ll.upper = ldq_kernel(addr);
        u.ll.lower = ldq_kernel(addr + 8);
B
blueswir1 已提交
2306 2307 2308 2309
        QT0 = u.q;
        break;
#ifdef TARGET_SPARC64
    case 2:
2310 2311
        u.ll.upper = ldq_hypv(addr);
        u.ll.lower = ldq_hypv(addr + 8);
B
blueswir1 已提交
2312 2313 2314 2315 2316 2317 2318
        QT0 = u.q;
        break;
#endif
    default:
        break;
    }
#else
2319 2320 2321
    ABI32_MASK(addr);
    u.ll.upper = ldq_raw(addr);
    u.ll.lower = ldq_raw((addr + 8) & 0xffffffffULL);
B
blueswir1 已提交
2322
    QT0 = u.q;
B
blueswir1 已提交
2323
#endif
B
blueswir1 已提交
2324 2325
}

B
blueswir1 已提交
2326
void helper_stqf(target_ulong addr, int mem_idx)
B
blueswir1 已提交
2327 2328 2329 2330
{
    // XXX add 128 bit store
    CPU_QuadU u;

2331
    helper_check_align(addr, 7);
B
blueswir1 已提交
2332 2333 2334 2335
#if !defined(CONFIG_USER_ONLY)
    switch (mem_idx) {
    case 0:
        u.q = QT0;
2336 2337
        stq_user(addr, u.ll.upper);
        stq_user(addr + 8, u.ll.lower);
B
blueswir1 已提交
2338 2339 2340
        break;
    case 1:
        u.q = QT0;
2341 2342
        stq_kernel(addr, u.ll.upper);
        stq_kernel(addr + 8, u.ll.lower);
B
blueswir1 已提交
2343 2344 2345 2346
        break;
#ifdef TARGET_SPARC64
    case 2:
        u.q = QT0;
2347 2348
        stq_hypv(addr, u.ll.upper);
        stq_hypv(addr + 8, u.ll.lower);
B
blueswir1 已提交
2349 2350 2351 2352 2353 2354
        break;
#endif
    default:
        break;
    }
#else
B
blueswir1 已提交
2355
    u.q = QT0;
2356 2357 2358
    ABI32_MASK(addr);
    stq_raw(addr, u.ll.upper);
    stq_raw((addr + 8) & 0xffffffffULL, u.ll.lower);
B
blueswir1 已提交
2359
#endif
B
blueswir1 已提交
2360
}
B
blueswir1 已提交
2361

B
bellard 已提交
2362
void helper_ldfsr(void)
2363
{
B
bellard 已提交
2364
    int rnd_mode;
B
blueswir1 已提交
2365 2366

    PUT_FSR32(env, *((uint32_t *) &FT0));
2367 2368
    switch (env->fsr & FSR_RD_MASK) {
    case FSR_RD_NEAREST:
B
bellard 已提交
2369
        rnd_mode = float_round_nearest_even;
B
blueswir1 已提交
2370
        break;
B
bellard 已提交
2371
    default:
2372
    case FSR_RD_ZERO:
B
bellard 已提交
2373
        rnd_mode = float_round_to_zero;
B
blueswir1 已提交
2374
        break;
2375
    case FSR_RD_POS:
B
bellard 已提交
2376
        rnd_mode = float_round_up;
B
blueswir1 已提交
2377
        break;
2378
    case FSR_RD_NEG:
B
bellard 已提交
2379
        rnd_mode = float_round_down;
B
blueswir1 已提交
2380
        break;
2381
    }
B
bellard 已提交
2382
    set_float_rounding_mode(rnd_mode, &env->fp_status);
2383
}
B
bellard 已提交
2384

B
blueswir1 已提交
2385 2386 2387 2388 2389 2390
void helper_stfsr(void)
{
    *((uint32_t *) &FT0) = GET_FSR32(env);
}

void helper_debug(void)
B
bellard 已提交
2391 2392 2393 2394
{
    env->exception_index = EXCP_DEBUG;
    cpu_loop_exit();
}
2395

B
bellard 已提交
2396
#ifndef TARGET_SPARC64
2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420
/* XXX: use another pointer for %iN registers to avoid slow wrapping
   handling ? */
void helper_save(void)
{
    uint32_t cwp;

    cwp = (env->cwp - 1) & (NWINDOWS - 1);
    if (env->wim & (1 << cwp)) {
        raise_exception(TT_WIN_OVF);
    }
    set_cwp(cwp);
}

void helper_restore(void)
{
    uint32_t cwp;

    cwp = (env->cwp + 1) & (NWINDOWS - 1);
    if (env->wim & (1 << cwp)) {
        raise_exception(TT_WIN_UNF);
    }
    set_cwp(cwp);
}

B
blueswir1 已提交
2421
void helper_wrpsr(target_ulong new_psr)
2422
{
B
blueswir1 已提交
2423
    if ((new_psr & PSR_CWP) >= NWINDOWS)
2424 2425
        raise_exception(TT_ILL_INSN);
    else
B
blueswir1 已提交
2426
        PUT_PSR(env, new_psr);
2427 2428
}

B
blueswir1 已提交
2429
target_ulong helper_rdpsr(void)
2430
{
B
blueswir1 已提交
2431
    return GET_PSR(env);
2432
}
B
bellard 已提交
2433 2434

#else
2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 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 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502
/* XXX: use another pointer for %iN registers to avoid slow wrapping
   handling ? */
void helper_save(void)
{
    uint32_t cwp;

    cwp = (env->cwp - 1) & (NWINDOWS - 1);
    if (env->cansave == 0) {
        raise_exception(TT_SPILL | (env->otherwin != 0 ?
                                    (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
                                    ((env->wstate & 0x7) << 2)));
    } else {
        if (env->cleanwin - env->canrestore == 0) {
            // XXX Clean windows without trap
            raise_exception(TT_CLRWIN);
        } else {
            env->cansave--;
            env->canrestore++;
            set_cwp(cwp);
        }
    }
}

void helper_restore(void)
{
    uint32_t cwp;

    cwp = (env->cwp + 1) & (NWINDOWS - 1);
    if (env->canrestore == 0) {
        raise_exception(TT_FILL | (env->otherwin != 0 ?
                                   (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
                                   ((env->wstate & 0x7) << 2)));
    } else {
        env->cansave++;
        env->canrestore--;
        set_cwp(cwp);
    }
}

void helper_flushw(void)
{
    if (env->cansave != NWINDOWS - 2) {
        raise_exception(TT_SPILL | (env->otherwin != 0 ?
                                    (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
                                    ((env->wstate & 0x7) << 2)));
    }
}

void helper_saved(void)
{
    env->cansave++;
    if (env->otherwin == 0)
        env->canrestore--;
    else
        env->otherwin--;
}

void helper_restored(void)
{
    env->canrestore++;
    if (env->cleanwin < NWINDOWS - 1)
        env->cleanwin++;
    if (env->otherwin == 0)
        env->cansave--;
    else
        env->otherwin--;
}

B
blueswir1 已提交
2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523
target_ulong helper_rdccr(void)
{
    return GET_CCR(env);
}

void helper_wrccr(target_ulong new_ccr)
{
    PUT_CCR(env, new_ccr);
}

// CWP handling is reversed in V9, but we still use the V8 register
// order.
target_ulong helper_rdcwp(void)
{
    return GET_CWP64(env);
}

void helper_wrcwp(target_ulong new_cwp)
{
    PUT_CWP64(env, new_cwp);
}
B
bellard 已提交
2524

2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555
// This function uses non-native bit order
#define GET_FIELD(X, FROM, TO)                                  \
    ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))

// This function uses the order in the manuals, i.e. bit 0 is 2^0
#define GET_FIELD_SP(X, FROM, TO)               \
    GET_FIELD(X, 63 - (TO), 63 - (FROM))

target_ulong helper_array8(target_ulong pixel_addr, target_ulong cubesize)
{
    return (GET_FIELD_SP(pixel_addr, 60, 63) << (17 + 2 * cubesize)) |
        (GET_FIELD_SP(pixel_addr, 39, 39 + cubesize - 1) << (17 + cubesize)) |
        (GET_FIELD_SP(pixel_addr, 17 + cubesize - 1, 17) << 17) |
        (GET_FIELD_SP(pixel_addr, 56, 59) << 13) |
        (GET_FIELD_SP(pixel_addr, 35, 38) << 9) |
        (GET_FIELD_SP(pixel_addr, 13, 16) << 5) |
        (((pixel_addr >> 55) & 1) << 4) |
        (GET_FIELD_SP(pixel_addr, 33, 34) << 2) |
        GET_FIELD_SP(pixel_addr, 11, 12);
}

target_ulong helper_alignaddr(target_ulong addr, target_ulong offset)
{
    uint64_t tmp;

    tmp = addr + offset;
    env->gsr &= ~7ULL;
    env->gsr |= tmp & 7ULL;
    return tmp & ~7ULL;
}

B
blueswir1 已提交
2556
target_ulong helper_popc(target_ulong val)
B
bellard 已提交
2557
{
B
blueswir1 已提交
2558
    return ctpop64(val);
B
bellard 已提交
2559
}
B
bellard 已提交
2560 2561 2562 2563 2564 2565

static inline uint64_t *get_gregset(uint64_t pstate)
{
    switch (pstate) {
    default:
    case 0:
B
blueswir1 已提交
2566
        return env->bgregs;
B
bellard 已提交
2567
    case PS_AG:
B
blueswir1 已提交
2568
        return env->agregs;
B
bellard 已提交
2569
    case PS_MG:
B
blueswir1 已提交
2570
        return env->mgregs;
B
bellard 已提交
2571
    case PS_IG:
B
blueswir1 已提交
2572
        return env->igregs;
B
bellard 已提交
2573 2574 2575
    }
}

2576
static inline void change_pstate(uint64_t new_pstate)
B
bellard 已提交
2577
{
2578
    uint64_t pstate_regs, new_pstate_regs;
B
bellard 已提交
2579 2580 2581 2582 2583
    uint64_t *src, *dst;

    pstate_regs = env->pstate & 0xc01;
    new_pstate_regs = new_pstate & 0xc01;
    if (new_pstate_regs != pstate_regs) {
B
blueswir1 已提交
2584 2585 2586 2587 2588
        // Switch global register bank
        src = get_gregset(new_pstate_regs);
        dst = get_gregset(pstate_regs);
        memcpy32(dst, env->gregs);
        memcpy32(env->gregs, src);
B
bellard 已提交
2589 2590 2591 2592
    }
    env->pstate = new_pstate;
}

B
blueswir1 已提交
2593
void helper_wrpstate(target_ulong new_state)
2594
{
B
blueswir1 已提交
2595
    change_pstate(new_state & 0xf3f);
2596 2597
}

B
blueswir1 已提交
2598
void helper_done(void)
B
bellard 已提交
2599 2600
{
    env->tl--;
2601 2602 2603 2604 2605 2606 2607
    env->tsptr = &env->ts[env->tl];
    env->pc = env->tsptr->tpc;
    env->npc = env->tsptr->tnpc + 4;
    PUT_CCR(env, env->tsptr->tstate >> 32);
    env->asi = (env->tsptr->tstate >> 24) & 0xff;
    change_pstate((env->tsptr->tstate >> 8) & 0xf3f);
    PUT_CWP64(env, env->tsptr->tstate & 0xff);
B
bellard 已提交
2608 2609
}

B
blueswir1 已提交
2610
void helper_retry(void)
B
bellard 已提交
2611 2612
{
    env->tl--;
2613 2614 2615 2616 2617 2618 2619
    env->tsptr = &env->ts[env->tl];
    env->pc = env->tsptr->tpc;
    env->npc = env->tsptr->tnpc;
    PUT_CCR(env, env->tsptr->tstate >> 32);
    env->asi = (env->tsptr->tstate >> 24) & 0xff;
    change_pstate((env->tsptr->tstate >> 8) & 0xf3f);
    PUT_CWP64(env, env->tsptr->tstate & 0xff);
B
bellard 已提交
2620
}
B
bellard 已提交
2621
#endif
2622 2623 2624 2625 2626 2627 2628 2629 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

void set_cwp(int new_cwp)
{
    /* put the modified wrap registers at their proper location */
    if (env->cwp == (NWINDOWS - 1))
        memcpy32(env->regbase, env->regbase + NWINDOWS * 16);
    env->cwp = new_cwp;
    /* put the wrap registers at their temporary location */
    if (new_cwp == (NWINDOWS - 1))
        memcpy32(env->regbase + NWINDOWS * 16, env->regbase);
    env->regwptr = env->regbase + (new_cwp * 16);
    REGWPTR = env->regwptr;
}

void cpu_set_cwp(CPUState *env1, int new_cwp)
{
    CPUState *saved_env;
#ifdef reg_REGWPTR
    target_ulong *saved_regwptr;
#endif

    saved_env = env;
#ifdef reg_REGWPTR
    saved_regwptr = REGWPTR;
#endif
    env = env1;
    set_cwp(new_cwp);
    env = saved_env;
#ifdef reg_REGWPTR
    REGWPTR = saved_regwptr;
#endif
}

#ifdef TARGET_SPARC64
B
blueswir1 已提交
2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691
#ifdef DEBUG_PCALL
static const char * const excp_names[0x50] = {
    [TT_TFAULT] = "Instruction Access Fault",
    [TT_TMISS] = "Instruction Access MMU Miss",
    [TT_CODE_ACCESS] = "Instruction Access Error",
    [TT_ILL_INSN] = "Illegal Instruction",
    [TT_PRIV_INSN] = "Privileged Instruction",
    [TT_NFPU_INSN] = "FPU Disabled",
    [TT_FP_EXCP] = "FPU Exception",
    [TT_TOVF] = "Tag Overflow",
    [TT_CLRWIN] = "Clean Windows",
    [TT_DIV_ZERO] = "Division By Zero",
    [TT_DFAULT] = "Data Access Fault",
    [TT_DMISS] = "Data Access MMU Miss",
    [TT_DATA_ACCESS] = "Data Access Error",
    [TT_DPROT] = "Data Protection Error",
    [TT_UNALIGNED] = "Unaligned Memory Access",
    [TT_PRIV_ACT] = "Privileged Action",
    [TT_EXTINT | 0x1] = "External Interrupt 1",
    [TT_EXTINT | 0x2] = "External Interrupt 2",
    [TT_EXTINT | 0x3] = "External Interrupt 3",
    [TT_EXTINT | 0x4] = "External Interrupt 4",
    [TT_EXTINT | 0x5] = "External Interrupt 5",
    [TT_EXTINT | 0x6] = "External Interrupt 6",
    [TT_EXTINT | 0x7] = "External Interrupt 7",
    [TT_EXTINT | 0x8] = "External Interrupt 8",
    [TT_EXTINT | 0x9] = "External Interrupt 9",
    [TT_EXTINT | 0xa] = "External Interrupt 10",
    [TT_EXTINT | 0xb] = "External Interrupt 11",
    [TT_EXTINT | 0xc] = "External Interrupt 12",
    [TT_EXTINT | 0xd] = "External Interrupt 13",
    [TT_EXTINT | 0xe] = "External Interrupt 14",
    [TT_EXTINT | 0xf] = "External Interrupt 15",
};
#endif

2692 2693 2694 2695
void do_interrupt(int intno)
{
#ifdef DEBUG_PCALL
    if (loglevel & CPU_LOG_INT) {
B
blueswir1 已提交
2696
        static int count;
B
blueswir1 已提交
2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715
        const char *name;

        if (intno < 0 || intno >= 0x180 || (intno > 0x4f && intno < 0x80))
            name = "Unknown";
        else if (intno >= 0x100)
            name = "Trap Instruction";
        else if (intno >= 0xc0)
            name = "Window Fill";
        else if (intno >= 0x80)
            name = "Window Spill";
        else {
            name = excp_names[intno];
            if (!name)
                name = "Unknown";
        }

        fprintf(logfile, "%6d: %s (v=%04x) pc=%016" PRIx64 " npc=%016" PRIx64
                " SP=%016" PRIx64 "\n",
                count, name, intno,
2716 2717
                env->pc,
                env->npc, env->regwptr[6]);
B
blueswir1 已提交
2718
        cpu_dump_state(env, logfile, fprintf, 0);
2719
#if 0
B
blueswir1 已提交
2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730
        {
            int i;
            uint8_t *ptr;

            fprintf(logfile, "       code=");
            ptr = (uint8_t *)env->pc;
            for(i = 0; i < 16; i++) {
                fprintf(logfile, " %02x", ldub(ptr + i));
            }
            fprintf(logfile, "\n");
        }
2731
#endif
B
blueswir1 已提交
2732
        count++;
2733 2734
    }
#endif
2735
#if !defined(CONFIG_USER_ONLY)
B
bellard 已提交
2736
    if (env->tl == MAXTL) {
B
blueswir1 已提交
2737 2738
        cpu_abort(env, "Trap 0x%04x while trap level is MAXTL, Error state",
                  env->exception_index);
B
blueswir1 已提交
2739
        return;
2740 2741
    }
#endif
2742 2743 2744 2745 2746 2747
    env->tsptr->tstate = ((uint64_t)GET_CCR(env) << 32) |
        ((env->asi & 0xff) << 24) | ((env->pstate & 0xf3f) << 8) |
        GET_CWP64(env);
    env->tsptr->tpc = env->pc;
    env->tsptr->tnpc = env->npc;
    env->tsptr->tt = intno;
2748 2749 2750 2751 2752 2753 2754 2755
    change_pstate(PS_PEF | PS_PRIV | PS_AG);

    if (intno == TT_CLRWIN)
        set_cwp((env->cwp - 1) & (NWINDOWS - 1));
    else if ((intno & 0x1c0) == TT_SPILL)
        set_cwp((env->cwp - env->cansave - 2) & (NWINDOWS - 1));
    else if ((intno & 0x1c0) == TT_FILL)
        set_cwp((env->cwp + 1) & (NWINDOWS - 1));
B
bellard 已提交
2756 2757 2758
    env->tbr &= ~0x7fffULL;
    env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
    if (env->tl < MAXTL - 1) {
B
blueswir1 已提交
2759
        env->tl++;
B
bellard 已提交
2760
    } else {
B
blueswir1 已提交
2761 2762 2763
        env->pstate |= PS_RED;
        if (env->tl != MAXTL)
            env->tl++;
B
bellard 已提交
2764
    }
2765
    env->tsptr = &env->ts[env->tl];
2766 2767 2768 2769 2770
    env->pc = env->tbr;
    env->npc = env->pc + 4;
    env->exception_index = 0;
}
#else
B
blueswir1 已提交
2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805
#ifdef DEBUG_PCALL
static const char * const excp_names[0x80] = {
    [TT_TFAULT] = "Instruction Access Fault",
    [TT_ILL_INSN] = "Illegal Instruction",
    [TT_PRIV_INSN] = "Privileged Instruction",
    [TT_NFPU_INSN] = "FPU Disabled",
    [TT_WIN_OVF] = "Window Overflow",
    [TT_WIN_UNF] = "Window Underflow",
    [TT_UNALIGNED] = "Unaligned Memory Access",
    [TT_FP_EXCP] = "FPU Exception",
    [TT_DFAULT] = "Data Access Fault",
    [TT_TOVF] = "Tag Overflow",
    [TT_EXTINT | 0x1] = "External Interrupt 1",
    [TT_EXTINT | 0x2] = "External Interrupt 2",
    [TT_EXTINT | 0x3] = "External Interrupt 3",
    [TT_EXTINT | 0x4] = "External Interrupt 4",
    [TT_EXTINT | 0x5] = "External Interrupt 5",
    [TT_EXTINT | 0x6] = "External Interrupt 6",
    [TT_EXTINT | 0x7] = "External Interrupt 7",
    [TT_EXTINT | 0x8] = "External Interrupt 8",
    [TT_EXTINT | 0x9] = "External Interrupt 9",
    [TT_EXTINT | 0xa] = "External Interrupt 10",
    [TT_EXTINT | 0xb] = "External Interrupt 11",
    [TT_EXTINT | 0xc] = "External Interrupt 12",
    [TT_EXTINT | 0xd] = "External Interrupt 13",
    [TT_EXTINT | 0xe] = "External Interrupt 14",
    [TT_EXTINT | 0xf] = "External Interrupt 15",
    [TT_TOVF] = "Tag Overflow",
    [TT_CODE_ACCESS] = "Instruction Access Error",
    [TT_DATA_ACCESS] = "Data Access Error",
    [TT_DIV_ZERO] = "Division By Zero",
    [TT_NCP_INSN] = "Coprocessor Disabled",
};
#endif

2806 2807 2808 2809 2810 2811
void do_interrupt(int intno)
{
    int cwp;

#ifdef DEBUG_PCALL
    if (loglevel & CPU_LOG_INT) {
B
blueswir1 已提交
2812
        static int count;
B
blueswir1 已提交
2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826
        const char *name;

        if (intno < 0 || intno >= 0x100)
            name = "Unknown";
        else if (intno >= 0x80)
            name = "Trap Instruction";
        else {
            name = excp_names[intno];
            if (!name)
                name = "Unknown";
        }

        fprintf(logfile, "%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
                count, name, intno,
2827 2828
                env->pc,
                env->npc, env->regwptr[6]);
B
blueswir1 已提交
2829
        cpu_dump_state(env, logfile, fprintf, 0);
2830
#if 0
B
blueswir1 已提交
2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841
        {
            int i;
            uint8_t *ptr;

            fprintf(logfile, "       code=");
            ptr = (uint8_t *)env->pc;
            for(i = 0; i < 16; i++) {
                fprintf(logfile, " %02x", ldub(ptr + i));
            }
            fprintf(logfile, "\n");
        }
2842
#endif
B
blueswir1 已提交
2843
        count++;
2844 2845
    }
#endif
2846
#if !defined(CONFIG_USER_ONLY)
2847
    if (env->psret == 0) {
B
blueswir1 已提交
2848 2849
        cpu_abort(env, "Trap 0x%02x while interrupts disabled, Error state",
                  env->exception_index);
B
blueswir1 已提交
2850
        return;
2851 2852 2853
    }
#endif
    env->psret = 0;
2854
    cwp = (env->cwp - 1) & (NWINDOWS - 1);
2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866
    set_cwp(cwp);
    env->regwptr[9] = env->pc;
    env->regwptr[10] = env->npc;
    env->psrps = env->psrs;
    env->psrs = 1;
    env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4);
    env->pc = env->tbr;
    env->npc = env->pc + 4;
    env->exception_index = 0;
}
#endif

2867
#if !defined(CONFIG_USER_ONLY)
2868

2869 2870 2871
static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
                                void *retaddr);

2872
#define MMUSUFFIX _mmu
2873
#define ALIGNED_ONLY
2874
#ifdef __s390__
B
blueswir1 已提交
2875 2876
# define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & \
                          0x7fffffffUL))
2877 2878 2879
#else
# define GETPC() (__builtin_return_address(0))
#endif
2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892

#define SHIFT 0
#include "softmmu_template.h"

#define SHIFT 1
#include "softmmu_template.h"

#define SHIFT 2
#include "softmmu_template.h"

#define SHIFT 3
#include "softmmu_template.h"

2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910
/* XXX: make it generic ? */
static void cpu_restore_state2(void *retaddr)
{
    TranslationBlock *tb;
    unsigned long pc;

    if (retaddr) {
        /* now we have a real cpu fault */
        pc = (unsigned long)retaddr;
        tb = tb_find_pc(pc);
        if (tb) {
            /* the PC is inside the translated code. It means that we have
               a virtual CPU fault */
            cpu_restore_state(tb, env, pc, (void *)(long)env->cond);
        }
    }
}

2911 2912 2913
static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
                                void *retaddr)
{
B
blueswir1 已提交
2914
#ifdef DEBUG_UNALIGNED
2915 2916
    printf("Unaligned access to 0x" TARGET_FMT_lx " from 0x" TARGET_FMT_lx
           "\n", addr, env->pc);
B
blueswir1 已提交
2917
#endif
2918
    cpu_restore_state2(retaddr);
B
blueswir1 已提交
2919
    raise_exception(TT_UNALIGNED);
2920
}
2921 2922 2923 2924 2925

/* try to fill the TLB and return an exception if error. If retaddr is
   NULL, it means that the function was called in C code (i.e. not
   from generated code or from helper.c) */
/* XXX: fix it to restore all registers */
2926
void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)
2927 2928 2929 2930 2931 2932 2933 2934 2935
{
    int ret;
    CPUState *saved_env;

    /* XXX: hack to restore env in all cases, even if not called from
       generated code */
    saved_env = env;
    env = cpu_single_env;

2936
    ret = cpu_sparc_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
2937
    if (ret) {
2938
        cpu_restore_state2(retaddr);
2939 2940 2941 2942 2943 2944
        cpu_loop_exit();
    }
    env = saved_env;
}

#endif
2945 2946

#ifndef TARGET_SPARC64
2947
void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
2948 2949 2950 2951 2952 2953 2954 2955
                          int is_asi)
{
    CPUState *saved_env;

    /* XXX: hack to restore env in all cases, even if not called from
       generated code */
    saved_env = env;
    env = cpu_single_env;
2956 2957
#ifdef DEBUG_UNASSIGNED
    if (is_asi)
B
blueswir1 已提交
2958 2959
        printf("Unassigned mem %s access to " TARGET_FMT_plx
               " asi 0x%02x from " TARGET_FMT_lx "\n",
2960 2961 2962 2963 2964 2965 2966
               is_exec ? "exec" : is_write ? "write" : "read", addr, is_asi,
               env->pc);
    else
        printf("Unassigned mem %s access to " TARGET_FMT_plx " from "
               TARGET_FMT_lx "\n",
               is_exec ? "exec" : is_write ? "write" : "read", addr, env->pc);
#endif
2967
    if (env->mmuregs[3]) /* Fault status register */
B
blueswir1 已提交
2968
        env->mmuregs[3] = 1; /* overflow (not read before another fault) */
2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979
    if (is_asi)
        env->mmuregs[3] |= 1 << 16;
    if (env->psrs)
        env->mmuregs[3] |= 1 << 5;
    if (is_exec)
        env->mmuregs[3] |= 1 << 6;
    if (is_write)
        env->mmuregs[3] |= 1 << 7;
    env->mmuregs[3] |= (5 << 2) | 2;
    env->mmuregs[4] = addr; /* Fault address register */
    if ((env->mmuregs[0] & MMU_E) && !(env->mmuregs[0] & MMU_NF)) {
2980 2981 2982 2983
        if (is_exec)
            raise_exception(TT_CODE_ACCESS);
        else
            raise_exception(TT_DATA_ACCESS);
2984 2985 2986 2987
    }
    env = saved_env;
}
#else
2988
void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
2989 2990 2991 2992 2993 2994 2995 2996 2997
                          int is_asi)
{
#ifdef DEBUG_UNASSIGNED
    CPUState *saved_env;

    /* XXX: hack to restore env in all cases, even if not called from
       generated code */
    saved_env = env;
    env = cpu_single_env;
B
blueswir1 已提交
2998 2999
    printf("Unassigned mem access to " TARGET_FMT_plx " from " TARGET_FMT_lx
           "\n", addr, env->pc);
3000 3001
    env = saved_env;
#endif
3002 3003 3004 3005
    if (is_exec)
        raise_exception(TT_CODE_ACCESS);
    else
        raise_exception(TT_DATA_ACCESS);
3006 3007
}
#endif
3008