~ubuntu-branches/debian/jessie/qemu/jessie

« back to all changes in this revision

Viewing changes to target-alpha/translate.c

  • Committer: Package Import Robot
  • Author(s): Vagrant Cascadian
  • Date: 2011-10-03 12:29:18 UTC
  • mfrom: (1.2.13) (10.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20111003122918-zc4kv6epchrbgdta
Tags: 0.15.0+dfsg-1
* New upstream version.
* Install new qemu-system, qemu-user and qemu-user-static variants: 
  lm32, microblazeel, s390x, unicore32
* Patch from upstream to set QEMU_INCLUDES before QEMU_CFLAGS.
* Update debian/watch to check http://qemu.org/download.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <stdio.h>
23
23
 
24
24
#include "cpu.h"
25
 
#include "exec-all.h"
26
25
#include "disas.h"
27
26
#include "host-utils.h"
28
27
#include "tcg-op.h"
47
46
    CPUAlphaState *env;
48
47
    uint64_t pc;
49
48
    int mem_idx;
50
 
#if !defined (CONFIG_USER_ONLY)
51
 
    int pal_mode;
52
 
#endif
53
 
    uint32_t amask;
54
49
 
55
50
    /* Current rounding mode for this TB.  */
56
51
    int tb_rm;
89
84
static TCGv cpu_lock_addr;
90
85
static TCGv cpu_lock_st_addr;
91
86
static TCGv cpu_lock_value;
92
 
#ifdef CONFIG_USER_ONLY
93
 
static TCGv cpu_uniq;
 
87
static TCGv cpu_unique;
 
88
#ifndef CONFIG_USER_ONLY
 
89
static TCGv cpu_sysval;
 
90
static TCGv cpu_usp;
94
91
#endif
95
92
 
96
93
/* register names */
135
132
                                            offsetof(CPUState, lock_value),
136
133
                                            "lock_value");
137
134
 
138
 
#ifdef CONFIG_USER_ONLY
139
 
    cpu_uniq = tcg_global_mem_new_i64(TCG_AREG0,
140
 
                                      offsetof(CPUState, unique), "uniq");
 
135
    cpu_unique = tcg_global_mem_new_i64(TCG_AREG0,
 
136
                                        offsetof(CPUState, unique), "unique");
 
137
#ifndef CONFIG_USER_ONLY
 
138
    cpu_sysval = tcg_global_mem_new_i64(TCG_AREG0,
 
139
                                        offsetof(CPUState, sysval), "sysval");
 
140
    cpu_usp = tcg_global_mem_new_i64(TCG_AREG0,
 
141
                                     offsetof(CPUState, usp), "usp");
141
142
#endif
142
143
 
143
144
    /* register helpers */
147
148
    done_init = 1;
148
149
}
149
150
 
150
 
static ExitStatus gen_excp(DisasContext *ctx, int exception, int error_code)
 
151
static void gen_excp_1(int exception, int error_code)
151
152
{
152
153
    TCGv_i32 tmp1, tmp2;
153
154
 
154
 
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
155
155
    tmp1 = tcg_const_i32(exception);
156
156
    tmp2 = tcg_const_i32(error_code);
157
157
    gen_helper_excp(tmp1, tmp2);
158
158
    tcg_temp_free_i32(tmp2);
159
159
    tcg_temp_free_i32(tmp1);
 
160
}
160
161
 
 
162
static ExitStatus gen_excp(DisasContext *ctx, int exception, int error_code)
 
163
{
 
164
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
 
165
    gen_excp_1(exception, error_code);
161
166
    return EXIT_NORETURN;
162
167
}
163
168
 
322
327
#if defined(CONFIG_USER_ONLY)
323
328
    addr = cpu_lock_st_addr;
324
329
#else
325
 
    addr = tcg_local_new();
 
330
    addr = tcg_temp_local_new();
326
331
#endif
327
332
 
328
333
    if (rb != 31) {
345
350
 
346
351
        lab_fail = gen_new_label();
347
352
        lab_done = gen_new_label();
348
 
        tcg_gen_brcond(TCG_COND_NE, addr, cpu_lock_addr, lab_fail);
 
353
        tcg_gen_brcond_i64(TCG_COND_NE, addr, cpu_lock_addr, lab_fail);
349
354
 
350
355
        val = tcg_temp_new();
351
356
        if (quad) {
353
358
        } else {
354
359
            tcg_gen_qemu_ld32s(val, addr, ctx->mem_idx);
355
360
        }
356
 
        tcg_gen_brcond(TCG_COND_NE, val, cpu_lock_value, lab_fail);
 
361
        tcg_gen_brcond_i64(TCG_COND_NE, val, cpu_lock_value, lab_fail);
357
362
 
358
363
        if (quad) {
359
364
            tcg_gen_qemu_st64(cpu_ir[ra], addr, ctx->mem_idx);
398
403
    } else if (use_goto_tb(ctx, dest)) {
399
404
        tcg_gen_goto_tb(0);
400
405
        tcg_gen_movi_i64(cpu_pc, dest);
401
 
        tcg_gen_exit_tb((long)ctx->tb);
 
406
        tcg_gen_exit_tb((tcg_target_long)ctx->tb);
402
407
        return EXIT_GOTO_TB;
403
408
    } else {
404
409
        tcg_gen_movi_i64(cpu_pc, dest);
417
422
 
418
423
        tcg_gen_goto_tb(0);
419
424
        tcg_gen_movi_i64(cpu_pc, ctx->pc);
420
 
        tcg_gen_exit_tb((long)ctx->tb);
 
425
        tcg_gen_exit_tb((tcg_target_long)ctx->tb);
421
426
 
422
427
        gen_set_label(lab_true);
423
428
        tcg_gen_goto_tb(1);
424
429
        tcg_gen_movi_i64(cpu_pc, dest);
425
 
        tcg_gen_exit_tb((long)ctx->tb + 1);
 
430
        tcg_gen_exit_tb((tcg_target_long)ctx->tb + 1);
426
431
 
427
432
        return EXIT_GOTO_TB;
428
433
    } else {
1464
1469
    tcg_temp_free_i32(tmp);
1465
1470
}
1466
1471
 
 
1472
static ExitStatus gen_call_pal(DisasContext *ctx, int palcode)
 
1473
{
 
1474
    /* We're emulating OSF/1 PALcode.  Many of these are trivial access
 
1475
       to internal cpu registers.  */
 
1476
 
 
1477
    /* Unprivileged PAL call */
 
1478
    if (palcode >= 0x80 && palcode < 0xC0) {
 
1479
        switch (palcode) {
 
1480
        case 0x86:
 
1481
            /* IMB */
 
1482
            /* No-op inside QEMU.  */
 
1483
            break;
 
1484
        case 0x9E:
 
1485
            /* RDUNIQUE */
 
1486
            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_unique);
 
1487
            break;
 
1488
        case 0x9F:
 
1489
            /* WRUNIQUE */
 
1490
            tcg_gen_mov_i64(cpu_unique, cpu_ir[IR_A0]);
 
1491
            break;
 
1492
        default:
 
1493
            return gen_excp(ctx, EXCP_CALL_PAL, palcode & 0xbf);
 
1494
        }
 
1495
        return NO_EXIT;
 
1496
    }
 
1497
 
 
1498
#ifndef CONFIG_USER_ONLY
 
1499
    /* Privileged PAL code */
 
1500
    if (palcode < 0x40 && (ctx->tb->flags & TB_FLAGS_USER_MODE) == 0) {
 
1501
        switch (palcode) {
 
1502
        case 0x01:
 
1503
            /* CFLUSH */
 
1504
            /* No-op inside QEMU.  */
 
1505
            break;
 
1506
        case 0x02:
 
1507
            /* DRAINA */
 
1508
            /* No-op inside QEMU.  */
 
1509
            break;
 
1510
        case 0x2D:
 
1511
            /* WRVPTPTR */
 
1512
            tcg_gen_st_i64(cpu_ir[IR_A0], cpu_env, offsetof(CPUState, vptptr));
 
1513
            break;
 
1514
        case 0x31:
 
1515
            /* WRVAL */
 
1516
            tcg_gen_mov_i64(cpu_sysval, cpu_ir[IR_A0]);
 
1517
            break;
 
1518
        case 0x32:
 
1519
            /* RDVAL */
 
1520
            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_sysval);
 
1521
            break;
 
1522
 
 
1523
        case 0x35: {
 
1524
            /* SWPIPL */
 
1525
            TCGv tmp;
 
1526
 
 
1527
            /* Note that we already know we're in kernel mode, so we know
 
1528
               that PS only contains the 3 IPL bits.  */
 
1529
            tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUState, ps));
 
1530
 
 
1531
            /* But make sure and store only the 3 IPL bits from the user.  */
 
1532
            tmp = tcg_temp_new();
 
1533
            tcg_gen_andi_i64(tmp, cpu_ir[IR_A0], PS_INT_MASK);
 
1534
            tcg_gen_st8_i64(tmp, cpu_env, offsetof(CPUState, ps));
 
1535
            tcg_temp_free(tmp);
 
1536
            break;
 
1537
        }
 
1538
 
 
1539
        case 0x36:
 
1540
            /* RDPS */
 
1541
            tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUState, ps));
 
1542
            break;
 
1543
        case 0x38:
 
1544
            /* WRUSP */
 
1545
            tcg_gen_mov_i64(cpu_usp, cpu_ir[IR_A0]);
 
1546
            break;
 
1547
        case 0x3A:
 
1548
            /* RDUSP */
 
1549
            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_usp);
 
1550
            break;
 
1551
        case 0x3C:
 
1552
            /* WHAMI */
 
1553
            tcg_gen_ld32s_i64(cpu_ir[IR_V0], cpu_env,
 
1554
                              offsetof(CPUState, cpu_index));
 
1555
            break;
 
1556
 
 
1557
        default:
 
1558
            return gen_excp(ctx, EXCP_CALL_PAL, palcode & 0x3f);
 
1559
        }
 
1560
        return NO_EXIT;
 
1561
    }
 
1562
#endif
 
1563
 
 
1564
    return gen_invalid(ctx);
 
1565
}
 
1566
 
 
1567
#ifndef CONFIG_USER_ONLY
 
1568
 
 
1569
#define PR_BYTE         0x100000
 
1570
#define PR_LONG         0x200000
 
1571
 
 
1572
static int cpu_pr_data(int pr)
 
1573
{
 
1574
    switch (pr) {
 
1575
    case  0: return offsetof(CPUAlphaState, ps) | PR_BYTE;
 
1576
    case  1: return offsetof(CPUAlphaState, fen) | PR_BYTE;
 
1577
    case  2: return offsetof(CPUAlphaState, pcc_ofs) | PR_LONG;
 
1578
    case  3: return offsetof(CPUAlphaState, trap_arg0);
 
1579
    case  4: return offsetof(CPUAlphaState, trap_arg1);
 
1580
    case  5: return offsetof(CPUAlphaState, trap_arg2);
 
1581
    case  6: return offsetof(CPUAlphaState, exc_addr);
 
1582
    case  7: return offsetof(CPUAlphaState, palbr);
 
1583
    case  8: return offsetof(CPUAlphaState, ptbr);
 
1584
    case  9: return offsetof(CPUAlphaState, vptptr);
 
1585
    case 10: return offsetof(CPUAlphaState, unique);
 
1586
    case 11: return offsetof(CPUAlphaState, sysval);
 
1587
    case 12: return offsetof(CPUAlphaState, usp);
 
1588
 
 
1589
    case 32 ... 39:
 
1590
        return offsetof(CPUAlphaState, shadow[pr - 32]);
 
1591
    case 40 ... 63:
 
1592
        return offsetof(CPUAlphaState, scratch[pr - 40]);
 
1593
    }
 
1594
    return 0;
 
1595
}
 
1596
 
 
1597
static void gen_mfpr(int ra, int regno)
 
1598
{
 
1599
    int data = cpu_pr_data(regno);
 
1600
 
 
1601
    /* In our emulated PALcode, these processor registers have no
 
1602
       side effects from reading.  */
 
1603
    if (ra == 31) {
 
1604
        return;
 
1605
    }
 
1606
 
 
1607
    /* The basic registers are data only, and unknown registers
 
1608
       are read-zero, write-ignore.  */
 
1609
    if (data == 0) {
 
1610
        tcg_gen_movi_i64(cpu_ir[ra], 0);
 
1611
    } else if (data & PR_BYTE) {
 
1612
        tcg_gen_ld8u_i64(cpu_ir[ra], cpu_env, data & ~PR_BYTE);
 
1613
    } else if (data & PR_LONG) {
 
1614
        tcg_gen_ld32s_i64(cpu_ir[ra], cpu_env, data & ~PR_LONG);
 
1615
    } else {
 
1616
        tcg_gen_ld_i64(cpu_ir[ra], cpu_env, data);
 
1617
    }
 
1618
}
 
1619
 
 
1620
static void gen_mtpr(int rb, int regno)
 
1621
{
 
1622
    TCGv tmp;
 
1623
 
 
1624
    if (rb == 31) {
 
1625
        tmp = tcg_const_i64(0);
 
1626
    } else {
 
1627
        tmp = cpu_ir[rb];
 
1628
    }
 
1629
 
 
1630
    /* These two register numbers perform a TLB cache flush.  Thankfully we
 
1631
       can only do this inside PALmode, which means that the current basic
 
1632
       block cannot be affected by the change in mappings.  */
 
1633
    if (regno == 255) {
 
1634
        /* TBIA */
 
1635
        gen_helper_tbia();
 
1636
    } else if (regno == 254) {
 
1637
        /* TBIS */
 
1638
        gen_helper_tbis(tmp);
 
1639
    } else {
 
1640
        /* The basic registers are data only, and unknown registers
 
1641
           are read-zero, write-ignore.  */
 
1642
        int data = cpu_pr_data(regno);
 
1643
        if (data != 0) {
 
1644
            if (data & PR_BYTE) {
 
1645
                tcg_gen_st8_i64(tmp, cpu_env, data & ~PR_BYTE);
 
1646
            } else if (data & PR_LONG) {
 
1647
                tcg_gen_st32_i64(tmp, cpu_env, data & ~PR_LONG);
 
1648
            } else {
 
1649
                tcg_gen_st_i64(tmp, cpu_env, data);
 
1650
            }
 
1651
        }
 
1652
    }
 
1653
 
 
1654
    if (rb == 31) {
 
1655
        tcg_temp_free(tmp);
 
1656
    }
 
1657
}
 
1658
#endif /* !USER_ONLY*/
 
1659
 
1467
1660
static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)
1468
1661
{
1469
1662
    uint32_t palcode;
1470
 
    int32_t disp21, disp16, disp12;
 
1663
    int32_t disp21, disp16;
 
1664
#ifndef CONFIG_USER_ONLY
 
1665
    int32_t disp12;
 
1666
#endif
1471
1667
    uint16_t fn11;
1472
 
    uint8_t opc, ra, rb, rc, fpfn, fn7, fn2, islit, real_islit;
 
1668
    uint8_t opc, ra, rb, rc, fpfn, fn7, islit, real_islit;
1473
1669
    uint8_t lit;
1474
1670
    ExitStatus ret;
1475
1671
 
1487
1683
    palcode = insn & 0x03FFFFFF;
1488
1684
    disp21 = ((int32_t)((insn & 0x001FFFFF) << 11)) >> 11;
1489
1685
    disp16 = (int16_t)(insn & 0x0000FFFF);
 
1686
#ifndef CONFIG_USER_ONLY
1490
1687
    disp12 = (int32_t)((insn & 0x00000FFF) << 20) >> 20;
 
1688
#endif
1491
1689
    fn11 = (insn >> 5) & 0x000007FF;
1492
1690
    fpfn = fn11 & 0x3F;
1493
1691
    fn7 = (insn >> 5) & 0x0000007F;
1494
 
    fn2 = (insn >> 5) & 0x00000003;
1495
1692
    LOG_DISAS("opc %02x ra %2d rb %2d rc %2d disp16 %6d\n",
1496
1693
              opc, ra, rb, rc, disp16);
1497
1694
 
1499
1696
    switch (opc) {
1500
1697
    case 0x00:
1501
1698
        /* CALL_PAL */
1502
 
#ifdef CONFIG_USER_ONLY
1503
 
        if (palcode == 0x9E) {
1504
 
            /* RDUNIQUE */
1505
 
            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_uniq);
1506
 
            break;
1507
 
        } else if (palcode == 0x9F) {
1508
 
            /* WRUNIQUE */
1509
 
            tcg_gen_mov_i64(cpu_uniq, cpu_ir[IR_A0]);
1510
 
            break;
1511
 
        }
1512
 
#endif
1513
 
        if (palcode >= 0x80 && palcode < 0xC0) {
1514
 
            /* Unprivileged PAL call */
1515
 
            ret = gen_excp(ctx, EXCP_CALL_PAL + ((palcode & 0x3F) << 6), 0);
1516
 
            break;
1517
 
        }
1518
 
#ifndef CONFIG_USER_ONLY
1519
 
        if (palcode < 0x40) {
1520
 
            /* Privileged PAL code */
1521
 
            if (ctx->mem_idx & 1)
1522
 
                goto invalid_opc;
1523
 
            ret = gen_excp(ctx, EXCP_CALL_PALP + ((palcode & 0x3F) << 6), 0);
1524
 
        }
1525
 
#endif
1526
 
        /* Invalid PAL call */
1527
 
        goto invalid_opc;
 
1699
        ret = gen_call_pal(ctx, palcode);
 
1700
        break;
1528
1701
    case 0x01:
1529
1702
        /* OPC01 */
1530
1703
        goto invalid_opc;
1566
1739
        break;
1567
1740
    case 0x0A:
1568
1741
        /* LDBU */
1569
 
        if (!(ctx->amask & AMASK_BWX))
1570
 
            goto invalid_opc;
1571
 
        gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
1572
 
        break;
 
1742
        if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
 
1743
            gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
 
1744
            break;
 
1745
        }
 
1746
        goto invalid_opc;
1573
1747
    case 0x0B:
1574
1748
        /* LDQ_U */
1575
1749
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
1576
1750
        break;
1577
1751
    case 0x0C:
1578
1752
        /* LDWU */
1579
 
        if (!(ctx->amask & AMASK_BWX))
1580
 
            goto invalid_opc;
1581
 
        gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 0);
1582
 
        break;
 
1753
        if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
 
1754
            gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 0);
 
1755
            break;
 
1756
        }
 
1757
        goto invalid_opc;
1583
1758
    case 0x0D:
1584
1759
        /* STW */
1585
1760
        gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0);
1983
2158
        case 0x61:
1984
2159
            /* AMASK */
1985
2160
            if (likely(rc != 31)) {
1986
 
                if (islit)
1987
 
                    tcg_gen_movi_i64(cpu_ir[rc], lit);
1988
 
                else
1989
 
                    tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1990
 
                switch (ctx->env->implver) {
1991
 
                case IMPLVER_2106x:
1992
 
                    /* EV4, EV45, LCA, LCA45 & EV5 */
1993
 
                    break;
1994
 
                case IMPLVER_21164:
1995
 
                case IMPLVER_21264:
1996
 
                case IMPLVER_21364:
1997
 
                    tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[rc],
1998
 
                                     ~(uint64_t)ctx->amask);
1999
 
                    break;
 
2161
                uint64_t amask = ctx->tb->flags >> TB_FLAGS_AMASK_SHIFT;
 
2162
 
 
2163
                if (islit) {
 
2164
                    tcg_gen_movi_i64(cpu_ir[rc], lit & ~amask);
 
2165
                } else {
 
2166
                    tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[rb], ~amask);
2000
2167
                }
2001
2168
            }
2002
2169
            break;
2210
2377
        switch (fpfn) { /* fn11 & 0x3F */
2211
2378
        case 0x04:
2212
2379
            /* ITOFS */
2213
 
            if (!(ctx->amask & AMASK_FIX))
 
2380
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
2214
2381
                goto invalid_opc;
 
2382
            }
2215
2383
            if (likely(rc != 31)) {
2216
2384
                if (ra != 31) {
2217
2385
                    TCGv_i32 tmp = tcg_temp_new_i32();
2224
2392
            break;
2225
2393
        case 0x0A:
2226
2394
            /* SQRTF */
2227
 
            if (!(ctx->amask & AMASK_FIX))
2228
 
                goto invalid_opc;
2229
 
            gen_fsqrtf(rb, rc);
2230
 
            break;
 
2395
            if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
 
2396
                gen_fsqrtf(rb, rc);
 
2397
                break;
 
2398
            }
 
2399
            goto invalid_opc;
2231
2400
        case 0x0B:
2232
2401
            /* SQRTS */
2233
 
            if (!(ctx->amask & AMASK_FIX))
2234
 
                goto invalid_opc;
2235
 
            gen_fsqrts(ctx, rb, rc, fn11);
2236
 
            break;
 
2402
            if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
 
2403
                gen_fsqrts(ctx, rb, rc, fn11);
 
2404
                break;
 
2405
            }
 
2406
            goto invalid_opc;
2237
2407
        case 0x14:
2238
2408
            /* ITOFF */
2239
 
            if (!(ctx->amask & AMASK_FIX))
 
2409
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
2240
2410
                goto invalid_opc;
 
2411
            }
2241
2412
            if (likely(rc != 31)) {
2242
2413
                if (ra != 31) {
2243
2414
                    TCGv_i32 tmp = tcg_temp_new_i32();
2250
2421
            break;
2251
2422
        case 0x24:
2252
2423
            /* ITOFT */
2253
 
            if (!(ctx->amask & AMASK_FIX))
 
2424
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
2254
2425
                goto invalid_opc;
 
2426
            }
2255
2427
            if (likely(rc != 31)) {
2256
2428
                if (ra != 31)
2257
2429
                    tcg_gen_mov_i64(cpu_fir[rc], cpu_ir[ra]);
2261
2433
            break;
2262
2434
        case 0x2A:
2263
2435
            /* SQRTG */
2264
 
            if (!(ctx->amask & AMASK_FIX))
2265
 
                goto invalid_opc;
2266
 
            gen_fsqrtg(rb, rc);
2267
 
            break;
 
2436
            if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
 
2437
                gen_fsqrtg(rb, rc);
 
2438
                break;
 
2439
            }
 
2440
            goto invalid_opc;
2268
2441
        case 0x02B:
2269
2442
            /* SQRTT */
2270
 
            if (!(ctx->amask & AMASK_FIX))
2271
 
                goto invalid_opc;
2272
 
            gen_fsqrtt(ctx, rb, rc, fn11);
2273
 
            break;
 
2443
            if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
 
2444
                gen_fsqrtt(ctx, rb, rc, fn11);
 
2445
                break;
 
2446
            }
 
2447
            goto invalid_opc;
2274
2448
        default:
2275
2449
            goto invalid_opc;
2276
2450
        }
2571
2745
        break;
2572
2746
    case 0x19:
2573
2747
        /* HW_MFPR (PALcode) */
2574
 
#if defined (CONFIG_USER_ONLY)
2575
 
        goto invalid_opc;
2576
 
#else
2577
 
        if (!ctx->pal_mode)
2578
 
            goto invalid_opc;
2579
 
        if (ra != 31) {
2580
 
            TCGv tmp = tcg_const_i32(insn & 0xFF);
2581
 
            gen_helper_mfpr(cpu_ir[ra], tmp, cpu_ir[ra]);
2582
 
            tcg_temp_free(tmp);
 
2748
#ifndef CONFIG_USER_ONLY
 
2749
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
 
2750
            gen_mfpr(ra, insn & 0xffff);
 
2751
            break;
2583
2752
        }
2584
 
        break;
2585
2753
#endif
 
2754
        goto invalid_opc;
2586
2755
    case 0x1A:
2587
2756
        /* JMP, JSR, RET, JSR_COROUTINE.  These only differ by the branch
2588
2757
           prediction stack action, which of course we don't implement.  */
2598
2767
        break;
2599
2768
    case 0x1B:
2600
2769
        /* HW_LD (PALcode) */
2601
 
#if defined (CONFIG_USER_ONLY)
2602
 
        goto invalid_opc;
2603
 
#else
2604
 
        if (!ctx->pal_mode)
2605
 
            goto invalid_opc;
2606
 
        if (ra != 31) {
2607
 
            TCGv addr = tcg_temp_new();
 
2770
#ifndef CONFIG_USER_ONLY
 
2771
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
 
2772
            TCGv addr;
 
2773
 
 
2774
            if (ra == 31) {
 
2775
                break;
 
2776
            }
 
2777
 
 
2778
            addr = tcg_temp_new();
2608
2779
            if (rb != 31)
2609
2780
                tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
2610
2781
            else
2612
2783
            switch ((insn >> 12) & 0xF) {
2613
2784
            case 0x0:
2614
2785
                /* Longword physical access (hw_ldl/p) */
2615
 
                gen_helper_ldl_raw(cpu_ir[ra], addr);
 
2786
                gen_helper_ldl_phys(cpu_ir[ra], addr);
2616
2787
                break;
2617
2788
            case 0x1:
2618
2789
                /* Quadword physical access (hw_ldq/p) */
2619
 
                gen_helper_ldq_raw(cpu_ir[ra], addr);
 
2790
                gen_helper_ldq_phys(cpu_ir[ra], addr);
2620
2791
                break;
2621
2792
            case 0x2:
2622
2793
                /* Longword physical access with lock (hw_ldl_l/p) */
2623
 
                gen_helper_ldl_l_raw(cpu_ir[ra], addr);
 
2794
                gen_helper_ldl_l_phys(cpu_ir[ra], addr);
2624
2795
                break;
2625
2796
            case 0x3:
2626
2797
                /* Quadword physical access with lock (hw_ldq_l/p) */
2627
 
                gen_helper_ldq_l_raw(cpu_ir[ra], addr);
 
2798
                gen_helper_ldq_l_phys(cpu_ir[ra], addr);
2628
2799
                break;
2629
2800
            case 0x4:
2630
2801
                /* Longword virtual PTE fetch (hw_ldl/v) */
2631
 
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, 0);
2632
 
                break;
 
2802
                goto invalid_opc;
2633
2803
            case 0x5:
2634
2804
                /* Quadword virtual PTE fetch (hw_ldq/v) */
2635
 
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, 0);
 
2805
                goto invalid_opc;
2636
2806
                break;
2637
2807
            case 0x6:
2638
2808
                /* Incpu_ir[ra]id */
2642
2812
                goto invalid_opc;
2643
2813
            case 0x8:
2644
2814
                /* Longword virtual access (hw_ldl) */
2645
 
                gen_helper_st_virt_to_phys(addr, addr);
2646
 
                gen_helper_ldl_raw(cpu_ir[ra], addr);
2647
 
                break;
 
2815
                goto invalid_opc;
2648
2816
            case 0x9:
2649
2817
                /* Quadword virtual access (hw_ldq) */
2650
 
                gen_helper_st_virt_to_phys(addr, addr);
2651
 
                gen_helper_ldq_raw(cpu_ir[ra], addr);
2652
 
                break;
 
2818
                goto invalid_opc;
2653
2819
            case 0xA:
2654
2820
                /* Longword virtual access with protection check (hw_ldl/w) */
2655
 
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, 0);
 
2821
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, MMU_KERNEL_IDX);
2656
2822
                break;
2657
2823
            case 0xB:
2658
2824
                /* Quadword virtual access with protection check (hw_ldq/w) */
2659
 
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, 0);
 
2825
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, MMU_KERNEL_IDX);
2660
2826
                break;
2661
2827
            case 0xC:
2662
2828
                /* Longword virtual access with alt access mode (hw_ldl/a)*/
2663
 
                gen_helper_set_alt_mode();
2664
 
                gen_helper_st_virt_to_phys(addr, addr);
2665
 
                gen_helper_ldl_raw(cpu_ir[ra], addr);
2666
 
                gen_helper_restore_mode();
2667
 
                break;
 
2829
                goto invalid_opc;
2668
2830
            case 0xD:
2669
2831
                /* Quadword virtual access with alt access mode (hw_ldq/a) */
2670
 
                gen_helper_set_alt_mode();
2671
 
                gen_helper_st_virt_to_phys(addr, addr);
2672
 
                gen_helper_ldq_raw(cpu_ir[ra], addr);
2673
 
                gen_helper_restore_mode();
2674
 
                break;
 
2832
                goto invalid_opc;
2675
2833
            case 0xE:
2676
2834
                /* Longword virtual access with alternate access mode and
2677
 
                 * protection checks (hw_ldl/wa)
2678
 
                 */
2679
 
                gen_helper_set_alt_mode();
2680
 
                gen_helper_ldl_data(cpu_ir[ra], addr);
2681
 
                gen_helper_restore_mode();
 
2835
                   protection checks (hw_ldl/wa) */
 
2836
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, MMU_USER_IDX);
2682
2837
                break;
2683
2838
            case 0xF:
2684
2839
                /* Quadword virtual access with alternate access mode and
2685
 
                 * protection checks (hw_ldq/wa)
2686
 
                 */
2687
 
                gen_helper_set_alt_mode();
2688
 
                gen_helper_ldq_data(cpu_ir[ra], addr);
2689
 
                gen_helper_restore_mode();
 
2840
                   protection checks (hw_ldq/wa) */
 
2841
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, MMU_USER_IDX);
2690
2842
                break;
2691
2843
            }
2692
2844
            tcg_temp_free(addr);
 
2845
            break;
2693
2846
        }
2694
 
        break;
2695
2847
#endif
 
2848
        goto invalid_opc;
2696
2849
    case 0x1C:
2697
2850
        switch (fn7) {
2698
2851
        case 0x00:
2699
2852
            /* SEXTB */
2700
 
            if (!(ctx->amask & AMASK_BWX))
 
2853
            if ((ctx->tb->flags & TB_FLAGS_AMASK_BWX) == 0) {
2701
2854
                goto invalid_opc;
 
2855
            }
2702
2856
            if (likely(rc != 31)) {
2703
2857
                if (islit)
2704
2858
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int8_t)lit));
2708
2862
            break;
2709
2863
        case 0x01:
2710
2864
            /* SEXTW */
2711
 
            if (!(ctx->amask & AMASK_BWX))
2712
 
                goto invalid_opc;
2713
 
            if (likely(rc != 31)) {
2714
 
                if (islit)
2715
 
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
2716
 
                else
2717
 
                    tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
 
2865
            if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
 
2866
                if (likely(rc != 31)) {
 
2867
                    if (islit) {
 
2868
                        tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
 
2869
                    } else {
 
2870
                        tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
 
2871
                    }
 
2872
                }
 
2873
                break;
2718
2874
            }
2719
 
            break;
 
2875
            goto invalid_opc;
2720
2876
        case 0x30:
2721
2877
            /* CTPOP */
2722
 
            if (!(ctx->amask & AMASK_CIX))
2723
 
                goto invalid_opc;
2724
 
            if (likely(rc != 31)) {
2725
 
                if (islit)
2726
 
                    tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
2727
 
                else
2728
 
                    gen_helper_ctpop(cpu_ir[rc], cpu_ir[rb]);
 
2878
            if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
 
2879
                if (likely(rc != 31)) {
 
2880
                    if (islit) {
 
2881
                        tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
 
2882
                    } else {
 
2883
                        gen_helper_ctpop(cpu_ir[rc], cpu_ir[rb]);
 
2884
                    }
 
2885
                }
 
2886
                break;
2729
2887
            }
2730
 
            break;
 
2888
            goto invalid_opc;
2731
2889
        case 0x31:
2732
2890
            /* PERR */
2733
 
            if (!(ctx->amask & AMASK_MVI))
2734
 
                goto invalid_opc;
2735
 
            gen_perr(ra, rb, rc, islit, lit);
2736
 
            break;
 
2891
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2892
                gen_perr(ra, rb, rc, islit, lit);
 
2893
                break;
 
2894
            }
 
2895
            goto invalid_opc;
2737
2896
        case 0x32:
2738
2897
            /* CTLZ */
2739
 
            if (!(ctx->amask & AMASK_CIX))
2740
 
                goto invalid_opc;
2741
 
            if (likely(rc != 31)) {
2742
 
                if (islit)
2743
 
                    tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
2744
 
                else
2745
 
                    gen_helper_ctlz(cpu_ir[rc], cpu_ir[rb]);
 
2898
            if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
 
2899
                if (likely(rc != 31)) {
 
2900
                    if (islit) {
 
2901
                        tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
 
2902
                    } else {
 
2903
                        gen_helper_ctlz(cpu_ir[rc], cpu_ir[rb]);
 
2904
                    }
 
2905
                }
 
2906
                break;
2746
2907
            }
2747
 
            break;
 
2908
            goto invalid_opc;
2748
2909
        case 0x33:
2749
2910
            /* CTTZ */
2750
 
            if (!(ctx->amask & AMASK_CIX))
2751
 
                goto invalid_opc;
2752
 
            if (likely(rc != 31)) {
2753
 
                if (islit)
2754
 
                    tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
2755
 
                else
2756
 
                    gen_helper_cttz(cpu_ir[rc], cpu_ir[rb]);
 
2911
            if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
 
2912
                if (likely(rc != 31)) {
 
2913
                    if (islit) {
 
2914
                        tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
 
2915
                    } else {
 
2916
                        gen_helper_cttz(cpu_ir[rc], cpu_ir[rb]);
 
2917
                    }
 
2918
                }
 
2919
                break;
2757
2920
            }
2758
 
            break;
 
2921
            goto invalid_opc;
2759
2922
        case 0x34:
2760
2923
            /* UNPKBW */
2761
 
            if (!(ctx->amask & AMASK_MVI))
2762
 
                goto invalid_opc;
2763
 
            if (real_islit || ra != 31)
2764
 
                goto invalid_opc;
2765
 
            gen_unpkbw (rb, rc);
2766
 
            break;
 
2924
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2925
                if (real_islit || ra != 31) {
 
2926
                    goto invalid_opc;
 
2927
                }
 
2928
                gen_unpkbw(rb, rc);
 
2929
                break;
 
2930
            }
 
2931
            goto invalid_opc;
2767
2932
        case 0x35:
2768
2933
            /* UNPKBL */
2769
 
            if (!(ctx->amask & AMASK_MVI))
2770
 
                goto invalid_opc;
2771
 
            if (real_islit || ra != 31)
2772
 
                goto invalid_opc;
2773
 
            gen_unpkbl (rb, rc);
2774
 
            break;
 
2934
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2935
                if (real_islit || ra != 31) {
 
2936
                    goto invalid_opc;
 
2937
                }
 
2938
                gen_unpkbl(rb, rc);
 
2939
                break;
 
2940
            }
 
2941
            goto invalid_opc;
2775
2942
        case 0x36:
2776
2943
            /* PKWB */
2777
 
            if (!(ctx->amask & AMASK_MVI))
2778
 
                goto invalid_opc;
2779
 
            if (real_islit || ra != 31)
2780
 
                goto invalid_opc;
2781
 
            gen_pkwb (rb, rc);
2782
 
            break;
 
2944
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2945
                if (real_islit || ra != 31) {
 
2946
                    goto invalid_opc;
 
2947
                }
 
2948
                gen_pkwb(rb, rc);
 
2949
                break;
 
2950
            }
 
2951
            goto invalid_opc;
2783
2952
        case 0x37:
2784
2953
            /* PKLB */
2785
 
            if (!(ctx->amask & AMASK_MVI))
2786
 
                goto invalid_opc;
2787
 
            if (real_islit || ra != 31)
2788
 
                goto invalid_opc;
2789
 
            gen_pklb (rb, rc);
2790
 
            break;
 
2954
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2955
                if (real_islit || ra != 31) {
 
2956
                    goto invalid_opc;
 
2957
                }
 
2958
                gen_pklb(rb, rc);
 
2959
                break;
 
2960
            }
 
2961
            goto invalid_opc;
2791
2962
        case 0x38:
2792
2963
            /* MINSB8 */
2793
 
            if (!(ctx->amask & AMASK_MVI))
2794
 
                goto invalid_opc;
2795
 
            gen_minsb8 (ra, rb, rc, islit, lit);
2796
 
            break;
 
2964
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2965
                gen_minsb8(ra, rb, rc, islit, lit);
 
2966
                break;
 
2967
            }
 
2968
            goto invalid_opc;
2797
2969
        case 0x39:
2798
2970
            /* MINSW4 */
2799
 
            if (!(ctx->amask & AMASK_MVI))
2800
 
                goto invalid_opc;
2801
 
            gen_minsw4 (ra, rb, rc, islit, lit);
2802
 
            break;
 
2971
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2972
                gen_minsw4(ra, rb, rc, islit, lit);
 
2973
                break;
 
2974
            }
 
2975
            goto invalid_opc;
2803
2976
        case 0x3A:
2804
2977
            /* MINUB8 */
2805
 
            if (!(ctx->amask & AMASK_MVI))
2806
 
                goto invalid_opc;
2807
 
            gen_minub8 (ra, rb, rc, islit, lit);
2808
 
            break;
 
2978
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2979
                gen_minub8(ra, rb, rc, islit, lit);
 
2980
                break;
 
2981
            }
 
2982
            goto invalid_opc;
2809
2983
        case 0x3B:
2810
2984
            /* MINUW4 */
2811
 
            if (!(ctx->amask & AMASK_MVI))
2812
 
                goto invalid_opc;
2813
 
            gen_minuw4 (ra, rb, rc, islit, lit);
2814
 
            break;
 
2985
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2986
                gen_minuw4(ra, rb, rc, islit, lit);
 
2987
                break;
 
2988
            }
 
2989
            goto invalid_opc;
2815
2990
        case 0x3C:
2816
2991
            /* MAXUB8 */
2817
 
            if (!(ctx->amask & AMASK_MVI))
2818
 
                goto invalid_opc;
2819
 
            gen_maxub8 (ra, rb, rc, islit, lit);
2820
 
            break;
 
2992
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
2993
                gen_maxub8(ra, rb, rc, islit, lit);
 
2994
                break;
 
2995
            }
 
2996
            goto invalid_opc;
2821
2997
        case 0x3D:
2822
2998
            /* MAXUW4 */
2823
 
            if (!(ctx->amask & AMASK_MVI))
2824
 
                goto invalid_opc;
2825
 
            gen_maxuw4 (ra, rb, rc, islit, lit);
2826
 
            break;
 
2999
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
3000
                gen_maxuw4(ra, rb, rc, islit, lit);
 
3001
                break;
 
3002
            }
 
3003
            goto invalid_opc;
2827
3004
        case 0x3E:
2828
3005
            /* MAXSB8 */
2829
 
            if (!(ctx->amask & AMASK_MVI))
2830
 
                goto invalid_opc;
2831
 
            gen_maxsb8 (ra, rb, rc, islit, lit);
2832
 
            break;
 
3006
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
3007
                gen_maxsb8(ra, rb, rc, islit, lit);
 
3008
                break;
 
3009
            }
 
3010
            goto invalid_opc;
2833
3011
        case 0x3F:
2834
3012
            /* MAXSW4 */
2835
 
            if (!(ctx->amask & AMASK_MVI))
2836
 
                goto invalid_opc;
2837
 
            gen_maxsw4 (ra, rb, rc, islit, lit);
2838
 
            break;
 
3013
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
 
3014
                gen_maxsw4(ra, rb, rc, islit, lit);
 
3015
                break;
 
3016
            }
 
3017
            goto invalid_opc;
2839
3018
        case 0x70:
2840
3019
            /* FTOIT */
2841
 
            if (!(ctx->amask & AMASK_FIX))
 
3020
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
2842
3021
                goto invalid_opc;
 
3022
            }
2843
3023
            if (likely(rc != 31)) {
2844
3024
                if (ra != 31)
2845
3025
                    tcg_gen_mov_i64(cpu_ir[rc], cpu_fir[ra]);
2849
3029
            break;
2850
3030
        case 0x78:
2851
3031
            /* FTOIS */
2852
 
            if (!(ctx->amask & AMASK_FIX))
 
3032
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
2853
3033
                goto invalid_opc;
 
3034
            }
2854
3035
            if (rc != 31) {
2855
3036
                TCGv_i32 tmp1 = tcg_temp_new_i32();
2856
3037
                if (ra != 31)
2870
3051
        break;
2871
3052
    case 0x1D:
2872
3053
        /* HW_MTPR (PALcode) */
2873
 
#if defined (CONFIG_USER_ONLY)
2874
 
        goto invalid_opc;
2875
 
#else
2876
 
        if (!ctx->pal_mode)
2877
 
            goto invalid_opc;
2878
 
        else {
2879
 
            TCGv tmp1 = tcg_const_i32(insn & 0xFF);
2880
 
            if (ra != 31)
2881
 
                gen_helper_mtpr(tmp1, cpu_ir[ra]);
2882
 
            else {
2883
 
                TCGv tmp2 = tcg_const_i64(0);
2884
 
                gen_helper_mtpr(tmp1, tmp2);
2885
 
                tcg_temp_free(tmp2);
2886
 
            }
2887
 
            tcg_temp_free(tmp1);
2888
 
            ret = EXIT_PC_STALE;
 
3054
#ifndef CONFIG_USER_ONLY
 
3055
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
 
3056
            gen_mtpr(rb, insn & 0xffff);
 
3057
            break;
2889
3058
        }
2890
 
        break;
2891
3059
#endif
 
3060
        goto invalid_opc;
2892
3061
    case 0x1E:
2893
 
        /* HW_REI (PALcode) */
2894
 
#if defined (CONFIG_USER_ONLY)
2895
 
        goto invalid_opc;
2896
 
#else
2897
 
        if (!ctx->pal_mode)
2898
 
            goto invalid_opc;
2899
 
        if (rb == 31) {
2900
 
            /* "Old" alpha */
2901
 
            gen_helper_hw_rei();
2902
 
        } else {
2903
 
            TCGv tmp;
2904
 
 
2905
 
            if (ra != 31) {
2906
 
                tmp = tcg_temp_new();
2907
 
                tcg_gen_addi_i64(tmp, cpu_ir[rb], (((int64_t)insn << 51) >> 51));
2908
 
            } else
2909
 
                tmp = tcg_const_i64(((int64_t)insn << 51) >> 51);
2910
 
            gen_helper_hw_ret(tmp);
2911
 
            tcg_temp_free(tmp);
 
3062
        /* HW_RET (PALcode) */
 
3063
#ifndef CONFIG_USER_ONLY
 
3064
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
 
3065
            if (rb == 31) {
 
3066
                /* Pre-EV6 CPUs interpreted this as HW_REI, loading the return
 
3067
                   address from EXC_ADDR.  This turns out to be useful for our
 
3068
                   emulation PALcode, so continue to accept it.  */
 
3069
                TCGv tmp = tcg_temp_new();
 
3070
                tcg_gen_ld_i64(tmp, cpu_env, offsetof(CPUState, exc_addr));
 
3071
                gen_helper_hw_ret(tmp);
 
3072
                tcg_temp_free(tmp);
 
3073
            } else {
 
3074
                gen_helper_hw_ret(cpu_ir[rb]);
 
3075
            }
 
3076
            ret = EXIT_PC_UPDATED;
 
3077
            break;
2912
3078
        }
2913
 
        ret = EXIT_PC_UPDATED;
2914
 
        break;
2915
3079
#endif
 
3080
        goto invalid_opc;
2916
3081
    case 0x1F:
2917
3082
        /* HW_ST (PALcode) */
2918
 
#if defined (CONFIG_USER_ONLY)
2919
 
        goto invalid_opc;
2920
 
#else
2921
 
        if (!ctx->pal_mode)
2922
 
            goto invalid_opc;
2923
 
        else {
 
3083
#ifndef CONFIG_USER_ONLY
 
3084
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
2924
3085
            TCGv addr, val;
2925
3086
            addr = tcg_temp_new();
2926
3087
            if (rb != 31)
2936
3097
            switch ((insn >> 12) & 0xF) {
2937
3098
            case 0x0:
2938
3099
                /* Longword physical access */
2939
 
                gen_helper_stl_raw(val, addr);
 
3100
                gen_helper_stl_phys(addr, val);
2940
3101
                break;
2941
3102
            case 0x1:
2942
3103
                /* Quadword physical access */
2943
 
                gen_helper_stq_raw(val, addr);
 
3104
                gen_helper_stq_phys(addr, val);
2944
3105
                break;
2945
3106
            case 0x2:
2946
3107
                /* Longword physical access with lock */
2947
 
                gen_helper_stl_c_raw(val, val, addr);
 
3108
                gen_helper_stl_c_phys(val, addr, val);
2948
3109
                break;
2949
3110
            case 0x3:
2950
3111
                /* Quadword physical access with lock */
2951
 
                gen_helper_stq_c_raw(val, val, addr);
 
3112
                gen_helper_stq_c_phys(val, addr, val);
2952
3113
                break;
2953
3114
            case 0x4:
2954
3115
                /* Longword virtual access */
2955
 
                gen_helper_st_virt_to_phys(addr, addr);
2956
 
                gen_helper_stl_raw(val, addr);
2957
 
                break;
 
3116
                goto invalid_opc;
2958
3117
            case 0x5:
2959
3118
                /* Quadword virtual access */
2960
 
                gen_helper_st_virt_to_phys(addr, addr);
2961
 
                gen_helper_stq_raw(val, addr);
2962
 
                break;
 
3119
                goto invalid_opc;
2963
3120
            case 0x6:
2964
3121
                /* Invalid */
2965
3122
                goto invalid_opc;
2980
3137
                goto invalid_opc;
2981
3138
            case 0xC:
2982
3139
                /* Longword virtual access with alternate access mode */
2983
 
                gen_helper_set_alt_mode();
2984
 
                gen_helper_st_virt_to_phys(addr, addr);
2985
 
                gen_helper_stl_raw(val, addr);
2986
 
                gen_helper_restore_mode();
2987
 
                break;
 
3140
                goto invalid_opc;
2988
3141
            case 0xD:
2989
3142
                /* Quadword virtual access with alternate access mode */
2990
 
                gen_helper_set_alt_mode();
2991
 
                gen_helper_st_virt_to_phys(addr, addr);
2992
 
                gen_helper_stl_raw(val, addr);
2993
 
                gen_helper_restore_mode();
2994
 
                break;
 
3143
                goto invalid_opc;
2995
3144
            case 0xE:
2996
3145
                /* Invalid */
2997
3146
                goto invalid_opc;
3002
3151
            if (ra == 31)
3003
3152
                tcg_temp_free(val);
3004
3153
            tcg_temp_free(addr);
 
3154
            break;
3005
3155
        }
3006
 
        break;
3007
3156
#endif
 
3157
        goto invalid_opc;
3008
3158
    case 0x20:
3009
3159
        /* LDF */
3010
3160
        gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
3155
3305
    ctx.tb = tb;
3156
3306
    ctx.env = env;
3157
3307
    ctx.pc = pc_start;
3158
 
    ctx.amask = env->amask;
3159
 
#if defined (CONFIG_USER_ONLY)
3160
 
    ctx.mem_idx = 0;
3161
 
#else
3162
 
    ctx.mem_idx = ((env->ps >> 3) & 3);
3163
 
    ctx.pal_mode = env->ipr[IPR_EXC_ADDR] & 1;
3164
 
#endif
 
3308
    ctx.mem_idx = cpu_mmu_index(env);
3165
3309
 
3166
3310
    /* ??? Every TB begins with unset rounding mode, to be initialized on
3167
3311
       the first fp insn of the TB.  Alternately we could define a proper
3211
3355
        ctx.pc += 4;
3212
3356
        ret = translate_one(ctxp, insn);
3213
3357
 
3214
 
        if (ret == NO_EXIT) {
3215
 
            /* If we reach a page boundary, are single stepping,
3216
 
               or exhaust instruction count, stop generation.  */
3217
 
            if (env->singlestep_enabled) {
3218
 
                gen_excp(&ctx, EXCP_DEBUG, 0);
3219
 
                ret = EXIT_PC_UPDATED;
3220
 
            } else if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0
3221
 
                       || gen_opc_ptr >= gen_opc_end
3222
 
                       || num_insns >= max_insns
3223
 
                       || singlestep) {
3224
 
                ret = EXIT_PC_STALE;
3225
 
            }
 
3358
        /* If we reach a page boundary, are single stepping,
 
3359
           or exhaust instruction count, stop generation.  */
 
3360
        if (ret == NO_EXIT
 
3361
            && ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0
 
3362
                || gen_opc_ptr >= gen_opc_end
 
3363
                || num_insns >= max_insns
 
3364
                || singlestep
 
3365
                || env->singlestep_enabled)) {
 
3366
            ret = EXIT_PC_STALE;
3226
3367
        }
3227
3368
    } while (ret == NO_EXIT);
3228
3369
 
3238
3379
        tcg_gen_movi_i64(cpu_pc, ctx.pc);
3239
3380
        /* FALLTHRU */
3240
3381
    case EXIT_PC_UPDATED:
3241
 
        tcg_gen_exit_tb(0);
 
3382
        if (env->singlestep_enabled) {
 
3383
            gen_excp_1(EXCP_DEBUG, 0);
 
3384
        } else {
 
3385
            tcg_gen_exit_tb(0);
 
3386
        }
3242
3387
        break;
3243
3388
    default:
3244
3389
        abort();
3325
3470
    env->implver = implver;
3326
3471
    env->amask = amask;
3327
3472
 
3328
 
    env->ps = 0x1F00;
3329
3473
#if defined (CONFIG_USER_ONLY)
3330
 
    env->ps |= 1 << 3;
 
3474
    env->ps = PS_USER_MODE;
3331
3475
    cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
3332
3476
                               | FPCR_UNFD | FPCR_INED | FPCR_DNOD));
3333
 
#else
3334
 
    pal_init(env);
3335
3477
#endif
3336
3478
    env->lock_addr = -1;
3337
 
 
3338
 
    /* Initialize IPR */
3339
 
#if defined (CONFIG_USER_ONLY)
3340
 
    env->ipr[IPR_EXC_ADDR] = 0;
3341
 
    env->ipr[IPR_EXC_SUM] = 0;
3342
 
    env->ipr[IPR_EXC_MASK] = 0;
3343
 
#else
3344
 
    {
3345
 
        // uint64_t hwpcb;
3346
 
        // hwpcb = env->ipr[IPR_PCBB];
3347
 
        env->ipr[IPR_ASN] = 0;
3348
 
        env->ipr[IPR_ASTEN] = 0;
3349
 
        env->ipr[IPR_ASTSR] = 0;
3350
 
        env->ipr[IPR_DATFX] = 0;
3351
 
        /* XXX: fix this */
3352
 
        //    env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
3353
 
        //    env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
3354
 
        //    env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
3355
 
        //    env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
3356
 
        env->ipr[IPR_FEN] = 0;
3357
 
        env->ipr[IPR_IPL] = 31;
3358
 
        env->ipr[IPR_MCES] = 0;
3359
 
        env->ipr[IPR_PERFMON] = 0; /* Implementation specific */
3360
 
        //    env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
3361
 
        env->ipr[IPR_SISR] = 0;
3362
 
        env->ipr[IPR_VIRBND] = -1ULL;
3363
 
    }
3364
 
#endif
 
3479
    env->fen = 1;
3365
3480
 
3366
3481
    qemu_init_vcpu(env);
3367
3482
    return env;
3368
3483
}
3369
3484
 
3370
 
void gen_pc_load(CPUState *env, TranslationBlock *tb,
3371
 
                unsigned long searched_pc, int pc_pos, void *puc)
 
3485
void restore_state_to_opc(CPUState *env, TranslationBlock *tb, int pc_pos)
3372
3486
{
3373
3487
    env->pc = gen_opc_pc[pc_pos];
3374
3488
}