translate.c 74.8 KB
Newer Older
J
j_mayer 已提交
1 2
/*
 *  Alpha emulation cpu translation for qemu.
3
 *
J
j_mayer 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16
 *  Copyright (c) 2007 Jocelyn Mayer
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
J
j_mayer 已提交
18 19 20 21 22 23 24 25 26
 */

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

#include "cpu.h"
#include "exec-all.h"
#include "disas.h"
27
#include "host-utils.h"
B
bellard 已提交
28
#include "tcg-op.h"
29
#include "qemu-common.h"
J
j_mayer 已提交
30

P
pbrook 已提交
31 32 33 34
#include "helper.h"
#define GEN_HELPER 1
#include "helper.h"

35
/* #define DO_SINGLE_STEP */
J
j_mayer 已提交
36
#define ALPHA_DEBUG_DISAS
37
/* #define DO_TB_FLUSH */
J
j_mayer 已提交
38

39 40

#ifdef ALPHA_DEBUG_DISAS
41
#  define LOG_DISAS(...) qemu_log(__VA_ARGS__)
42 43 44 45
#else
#  define LOG_DISAS(...) do { } while (0)
#endif

J
j_mayer 已提交
46 47 48 49 50 51 52
typedef struct DisasContext DisasContext;
struct DisasContext {
    uint64_t pc;
    int mem_idx;
#if !defined (CONFIG_USER_ONLY)
    int pal_mode;
#endif
53
    CPUAlphaState *env;
J
j_mayer 已提交
54 55 56
    uint32_t amask;
};

A
aurel32 已提交
57
/* global register indexes */
P
pbrook 已提交
58
static TCGv_ptr cpu_env;
A
aurel32 已提交
59
static TCGv cpu_ir[31];
A
aurel32 已提交
60
static TCGv cpu_fir[31];
A
aurel32 已提交
61
static TCGv cpu_pc;
62
static TCGv cpu_lock;
A
aurel32 已提交
63

A
aurel32 已提交
64
/* register names */
A
aurel32 已提交
65
static char cpu_reg_names[10*4+21*5 + 10*5+21*6];
P
pbrook 已提交
66 67 68

#include "gen-icount.h"

69
static void alpha_translate_init(void)
P
pbrook 已提交
70
{
A
aurel32 已提交
71 72
    int i;
    char *p;
P
pbrook 已提交
73
    static int done_init = 0;
A
aurel32 已提交
74

P
pbrook 已提交
75 76
    if (done_init)
        return;
A
aurel32 已提交
77

P
pbrook 已提交
78
    cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
A
aurel32 已提交
79 80 81 82

    p = cpu_reg_names;
    for (i = 0; i < 31; i++) {
        sprintf(p, "ir%d", i);
P
pbrook 已提交
83 84
        cpu_ir[i] = tcg_global_mem_new_i64(TCG_AREG0,
                                           offsetof(CPUState, ir[i]), p);
A
aurel32 已提交
85
        p += (i < 10) ? 4 : 5;
A
aurel32 已提交
86 87

        sprintf(p, "fir%d", i);
P
pbrook 已提交
88 89
        cpu_fir[i] = tcg_global_mem_new_i64(TCG_AREG0,
                                            offsetof(CPUState, fir[i]), p);
A
aurel32 已提交
90
        p += (i < 10) ? 5 : 6;
A
aurel32 已提交
91 92
    }

P
pbrook 已提交
93 94
    cpu_pc = tcg_global_mem_new_i64(TCG_AREG0,
                                    offsetof(CPUState, pc), "pc");
A
aurel32 已提交
95

P
pbrook 已提交
96 97
    cpu_lock = tcg_global_mem_new_i64(TCG_AREG0,
                                      offsetof(CPUState, lock), "lock");
98

A
aurel32 已提交
99
    /* register helpers */
P
pbrook 已提交
100
#define GEN_HELPER 2
A
aurel32 已提交
101 102
#include "helper.h"

P
pbrook 已提交
103 104 105
    done_init = 1;
}

B
Blue Swirl 已提交
106
static inline void gen_excp(DisasContext *ctx, int exception, int error_code)
J
j_mayer 已提交
107
{
P
pbrook 已提交
108
    TCGv_i32 tmp1, tmp2;
109

A
aurel32 已提交
110
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
111 112
    tmp1 = tcg_const_i32(exception);
    tmp2 = tcg_const_i32(error_code);
P
pbrook 已提交
113 114 115
    gen_helper_excp(tmp1, tmp2);
    tcg_temp_free_i32(tmp2);
    tcg_temp_free_i32(tmp1);
J
j_mayer 已提交
116 117
}

B
Blue Swirl 已提交
118
static inline void gen_invalid(DisasContext *ctx)
J
j_mayer 已提交
119 120 121 122
{
    gen_excp(ctx, EXCP_OPCDEC, 0);
}

B
Blue Swirl 已提交
123
static inline void gen_qemu_ldf(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
124
{
P
pbrook 已提交
125 126
    TCGv tmp = tcg_temp_new();
    TCGv_i32 tmp32 = tcg_temp_new_i32();
A
aurel32 已提交
127
    tcg_gen_qemu_ld32u(tmp, t1, flags);
P
pbrook 已提交
128 129 130
    tcg_gen_trunc_i64_i32(tmp32, tmp);
    gen_helper_memory_to_f(t0, tmp32);
    tcg_temp_free_i32(tmp32);
A
aurel32 已提交
131 132 133
    tcg_temp_free(tmp);
}

B
Blue Swirl 已提交
134
static inline void gen_qemu_ldg(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
135
{
P
pbrook 已提交
136
    TCGv tmp = tcg_temp_new();
A
aurel32 已提交
137
    tcg_gen_qemu_ld64(tmp, t1, flags);
P
pbrook 已提交
138
    gen_helper_memory_to_g(t0, tmp);
A
aurel32 已提交
139 140 141
    tcg_temp_free(tmp);
}

B
Blue Swirl 已提交
142
static inline void gen_qemu_lds(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
143
{
P
pbrook 已提交
144 145
    TCGv tmp = tcg_temp_new();
    TCGv_i32 tmp32 = tcg_temp_new_i32();
A
aurel32 已提交
146
    tcg_gen_qemu_ld32u(tmp, t1, flags);
P
pbrook 已提交
147 148 149
    tcg_gen_trunc_i64_i32(tmp32, tmp);
    gen_helper_memory_to_s(t0, tmp32);
    tcg_temp_free_i32(tmp32);
A
aurel32 已提交
150 151 152
    tcg_temp_free(tmp);
}

B
Blue Swirl 已提交
153
static inline void gen_qemu_ldl_l(TCGv t0, TCGv t1, int flags)
154 155 156 157 158
{
    tcg_gen_mov_i64(cpu_lock, t1);
    tcg_gen_qemu_ld32s(t0, t1, flags);
}

B
Blue Swirl 已提交
159
static inline void gen_qemu_ldq_l(TCGv t0, TCGv t1, int flags)
160 161 162 163 164
{
    tcg_gen_mov_i64(cpu_lock, t1);
    tcg_gen_qemu_ld64(t0, t1, flags);
}

B
Blue Swirl 已提交
165 166 167 168 169
static inline void gen_load_mem(DisasContext *ctx,
                                void (*tcg_gen_qemu_load)(TCGv t0, TCGv t1,
                                                          int flags),
                                int ra, int rb, int32_t disp16, int fp,
                                int clear)
170 171 172 173 174 175
{
    TCGv addr;

    if (unlikely(ra == 31))
        return;

P
pbrook 已提交
176
    addr = tcg_temp_new();
177 178 179 180 181 182 183 184 185
    if (rb != 31) {
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
        if (clear)
            tcg_gen_andi_i64(addr, addr, ~0x7);
    } else {
        if (clear)
            disp16 &= ~0x7;
        tcg_gen_movi_i64(addr, disp16);
    }
A
aurel32 已提交
186 187 188 189
    if (fp)
        tcg_gen_qemu_load(cpu_fir[ra], addr, ctx->mem_idx);
    else
        tcg_gen_qemu_load(cpu_ir[ra], addr, ctx->mem_idx);
190 191 192
    tcg_temp_free(addr);
}

B
Blue Swirl 已提交
193
static inline void gen_qemu_stf(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
194
{
P
pbrook 已提交
195 196 197 198
    TCGv_i32 tmp32 = tcg_temp_new_i32();
    TCGv tmp = tcg_temp_new();
    gen_helper_f_to_memory(tmp32, t0);
    tcg_gen_extu_i32_i64(tmp, tmp32);
A
aurel32 已提交
199 200
    tcg_gen_qemu_st32(tmp, t1, flags);
    tcg_temp_free(tmp);
P
pbrook 已提交
201
    tcg_temp_free_i32(tmp32);
A
aurel32 已提交
202 203
}

B
Blue Swirl 已提交
204
static inline void gen_qemu_stg(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
205
{
P
pbrook 已提交
206 207
    TCGv tmp = tcg_temp_new();
    gen_helper_g_to_memory(tmp, t0);
A
aurel32 已提交
208 209 210 211
    tcg_gen_qemu_st64(tmp, t1, flags);
    tcg_temp_free(tmp);
}

B
Blue Swirl 已提交
212
static inline void gen_qemu_sts(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
213
{
P
pbrook 已提交
214 215 216 217
    TCGv_i32 tmp32 = tcg_temp_new_i32();
    TCGv tmp = tcg_temp_new();
    gen_helper_s_to_memory(tmp32, t0);
    tcg_gen_extu_i32_i64(tmp, tmp32);
A
aurel32 已提交
218 219
    tcg_gen_qemu_st32(tmp, t1, flags);
    tcg_temp_free(tmp);
P
pbrook 已提交
220
    tcg_temp_free_i32(tmp32);
A
aurel32 已提交
221 222
}

B
Blue Swirl 已提交
223
static inline void gen_qemu_stl_c(TCGv t0, TCGv t1, int flags)
224 225 226 227 228 229 230
{
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
    tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1);
    tcg_gen_qemu_st32(t0, t1, flags);
231
    tcg_gen_movi_i64(t0, 1);
232 233
    tcg_gen_br(l2);
    gen_set_label(l1);
234
    tcg_gen_movi_i64(t0, 0);
235 236 237 238
    gen_set_label(l2);
    tcg_gen_movi_i64(cpu_lock, -1);
}

B
Blue Swirl 已提交
239
static inline void gen_qemu_stq_c(TCGv t0, TCGv t1, int flags)
240 241 242 243 244 245 246
{
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
    tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1);
    tcg_gen_qemu_st64(t0, t1, flags);
247
    tcg_gen_movi_i64(t0, 1);
248 249
    tcg_gen_br(l2);
    gen_set_label(l1);
250
    tcg_gen_movi_i64(t0, 0);
251 252 253 254
    gen_set_label(l2);
    tcg_gen_movi_i64(cpu_lock, -1);
}

B
Blue Swirl 已提交
255 256 257 258 259
static inline void gen_store_mem(DisasContext *ctx,
                                 void (*tcg_gen_qemu_store)(TCGv t0, TCGv t1,
                                                            int flags),
                                 int ra, int rb, int32_t disp16, int fp,
                                 int clear, int local)
260
{
261
    TCGv addr;
A
aurel32 已提交
262
    if (local)
P
pbrook 已提交
263
        addr = tcg_temp_local_new();
A
aurel32 已提交
264
    else
P
pbrook 已提交
265
        addr = tcg_temp_new();
266 267 268 269 270 271 272 273 274
    if (rb != 31) {
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
        if (clear)
            tcg_gen_andi_i64(addr, addr, ~0x7);
    } else {
        if (clear)
            disp16 &= ~0x7;
        tcg_gen_movi_i64(addr, disp16);
    }
A
aurel32 已提交
275 276 277 278 279 280
    if (ra != 31) {
        if (fp)
            tcg_gen_qemu_store(cpu_fir[ra], addr, ctx->mem_idx);
        else
            tcg_gen_qemu_store(cpu_ir[ra], addr, ctx->mem_idx);
    } else {
A
aurel32 已提交
281 282 283 284 285
        TCGv zero;
        if (local)
            zero = tcg_const_local_i64(0);
        else
            zero = tcg_const_i64(0);
286 287 288 289 290 291
        tcg_gen_qemu_store(zero, addr, ctx->mem_idx);
        tcg_temp_free(zero);
    }
    tcg_temp_free(addr);
}

B
Blue Swirl 已提交
292 293
static inline void gen_bcond(DisasContext *ctx, TCGCond cond, int ra,
                             int32_t disp, int mask)
J
j_mayer 已提交
294
{
A
aurel32 已提交
295 296 297 298 299 300
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
    if (likely(ra != 31)) {
        if (mask) {
P
pbrook 已提交
301
            TCGv tmp = tcg_temp_new();
A
aurel32 已提交
302 303 304 305 306 307 308 309 310 311 312 313 314 315
            tcg_gen_andi_i64(tmp, cpu_ir[ra], 1);
            tcg_gen_brcondi_i64(cond, tmp, 0, l1);
            tcg_temp_free(tmp);
        } else
            tcg_gen_brcondi_i64(cond, cpu_ir[ra], 0, l1);
    } else {
        /* Very uncommon case - Do not bother to optimize.  */
        TCGv tmp = tcg_const_i64(0);
        tcg_gen_brcondi_i64(cond, tmp, 0, l1);
        tcg_temp_free(tmp);
    }
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
    tcg_gen_br(l2);
    gen_set_label(l1);
316
    tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp << 2));
A
aurel32 已提交
317
    gen_set_label(l2);
J
j_mayer 已提交
318 319
}

B
Blue Swirl 已提交
320 321
static inline void gen_fbcond(DisasContext *ctx, int opc, int ra,
                              int32_t disp16)
J
j_mayer 已提交
322
{
A
aurel32 已提交
323 324
    int l1, l2;
    TCGv tmp;
P
pbrook 已提交
325
    TCGv src;
A
aurel32 已提交
326 327 328 329

    l1 = gen_new_label();
    l2 = gen_new_label();
    if (ra != 31) {
P
pbrook 已提交
330 331
        tmp = tcg_temp_new();
        src = cpu_fir[ra];
A
aurel32 已提交
332 333
    } else  {
        tmp = tcg_const_i64(0);
P
pbrook 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
        src = tmp;
    }
    switch (opc) {
    case 0x31: /* FBEQ */
        gen_helper_cmpfeq(tmp, src);
        break;
    case 0x32: /* FBLT */
        gen_helper_cmpflt(tmp, src);
        break;
    case 0x33: /* FBLE */
        gen_helper_cmpfle(tmp, src);
        break;
    case 0x35: /* FBNE */
        gen_helper_cmpfne(tmp, src);
        break;
    case 0x36: /* FBGE */
        gen_helper_cmpfge(tmp, src);
        break;
    case 0x37: /* FBGT */
        gen_helper_cmpfgt(tmp, src);
        break;
    default:
        abort();
A
aurel32 已提交
357 358 359 360 361 362 363
    }
    tcg_gen_brcondi_i64(TCG_COND_NE, tmp, 0, l1);
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
    tcg_gen_br(l2);
    gen_set_label(l1);
    tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp16 << 2));
    gen_set_label(l2);
J
j_mayer 已提交
364 365
}

B
Blue Swirl 已提交
366 367
static inline void gen_cmov(TCGCond inv_cond, int ra, int rb, int rc,
                            int islit, uint8_t lit, int mask)
J
j_mayer 已提交
368
{
A
aurel32 已提交
369 370 371 372 373 374 375 376 377
    int l1;

    if (unlikely(rc == 31))
        return;

    l1 = gen_new_label();

    if (ra != 31) {
        if (mask) {
P
pbrook 已提交
378
            TCGv tmp = tcg_temp_new();
A
aurel32 已提交
379 380 381 382 383 384 385 386 387 388 389 390
            tcg_gen_andi_i64(tmp, cpu_ir[ra], 1);
            tcg_gen_brcondi_i64(inv_cond, tmp, 0, l1);
            tcg_temp_free(tmp);
        } else
            tcg_gen_brcondi_i64(inv_cond, cpu_ir[ra], 0, l1);
    } else {
        /* Very uncommon case - Do not bother to optimize.  */
        TCGv tmp = tcg_const_i64(0);
        tcg_gen_brcondi_i64(inv_cond, tmp, 0, l1);
        tcg_temp_free(tmp);
    }

J
j_mayer 已提交
391
    if (islit)
A
aurel32 已提交
392
        tcg_gen_movi_i64(cpu_ir[rc], lit);
J
j_mayer 已提交
393
    else
394
        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
A
aurel32 已提交
395
    gen_set_label(l1);
J
j_mayer 已提交
396 397
}

P
pbrook 已提交
398
#define FARITH2(name)                                       \
B
Blue Swirl 已提交
399
static inline void glue(gen_f, name)(int rb, int rc)        \
P
pbrook 已提交
400 401 402 403 404 405 406 407 408 409 410
{                                                           \
    if (unlikely(rc == 31))                                 \
      return;                                               \
                                                            \
    if (rb != 31)                                           \
        gen_helper_ ## name (cpu_fir[rc], cpu_fir[rb]);    \
    else {                                                  \
        TCGv tmp = tcg_const_i64(0);                        \
        gen_helper_ ## name (cpu_fir[rc], tmp);            \
        tcg_temp_free(tmp);                                 \
    }                                                       \
J
j_mayer 已提交
411
}
P
pbrook 已提交
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
FARITH2(sqrts)
FARITH2(sqrtf)
FARITH2(sqrtg)
FARITH2(sqrtt)
FARITH2(cvtgf)
FARITH2(cvtgq)
FARITH2(cvtqf)
FARITH2(cvtqg)
FARITH2(cvtst)
FARITH2(cvtts)
FARITH2(cvttq)
FARITH2(cvtqs)
FARITH2(cvtqt)
FARITH2(cvtlq)
FARITH2(cvtql)
FARITH2(cvtqlv)
FARITH2(cvtqlsv)

#define FARITH3(name)                                                     \
B
Blue Swirl 已提交
431
static inline void glue(gen_f, name)(int ra, int rb, int rc)              \
P
pbrook 已提交
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
{                                                                         \
    if (unlikely(rc == 31))                                               \
        return;                                                           \
                                                                          \
    if (ra != 31) {                                                       \
        if (rb != 31)                                                     \
            gen_helper_ ## name (cpu_fir[rc], cpu_fir[ra], cpu_fir[rb]);  \
        else {                                                            \
            TCGv tmp = tcg_const_i64(0);                                  \
            gen_helper_ ## name (cpu_fir[rc], cpu_fir[ra], tmp);          \
            tcg_temp_free(tmp);                                           \
        }                                                                 \
    } else {                                                              \
        TCGv tmp = tcg_const_i64(0);                                      \
        if (rb != 31)                                                     \
            gen_helper_ ## name (cpu_fir[rc], tmp, cpu_fir[rb]);          \
        else                                                              \
            gen_helper_ ## name (cpu_fir[rc], tmp, tmp);                   \
        tcg_temp_free(tmp);                                               \
    }                                                                     \
J
j_mayer 已提交
452 453
}

P
pbrook 已提交
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
FARITH3(addf)
FARITH3(subf)
FARITH3(mulf)
FARITH3(divf)
FARITH3(addg)
FARITH3(subg)
FARITH3(mulg)
FARITH3(divg)
FARITH3(cmpgeq)
FARITH3(cmpglt)
FARITH3(cmpgle)
FARITH3(adds)
FARITH3(subs)
FARITH3(muls)
FARITH3(divs)
FARITH3(addt)
FARITH3(subt)
FARITH3(mult)
FARITH3(divt)
FARITH3(cmptun)
FARITH3(cmpteq)
FARITH3(cmptlt)
FARITH3(cmptle)
FARITH3(cpys)
FARITH3(cpysn)
FARITH3(cpyse)

#define FCMOV(name)                                                   \
B
Blue Swirl 已提交
482
static inline void glue(gen_f, name)(int ra, int rb, int rc)          \
P
pbrook 已提交
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
{                                                                     \
    int l1;                                                           \
    TCGv tmp;                                                         \
                                                                      \
    if (unlikely(rc == 31))                                           \
        return;                                                       \
                                                                      \
    l1 = gen_new_label();                                             \
    tmp = tcg_temp_new();                                 \
    if (ra != 31) {                                                   \
        tmp = tcg_temp_new();                             \
        gen_helper_ ## name (tmp, cpu_fir[ra]);                       \
    } else  {                                                         \
        tmp = tcg_const_i64(0);                                       \
        gen_helper_ ## name (tmp, tmp);                               \
    }                                                                 \
    tcg_gen_brcondi_i64(TCG_COND_EQ, tmp, 0, l1);                     \
    if (rb != 31)                                                     \
        tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);                    \
    else                                                              \
        tcg_gen_movi_i64(cpu_fir[rc], 0);                             \
    gen_set_label(l1);                                                \
J
j_mayer 已提交
505
}
P
pbrook 已提交
506 507 508 509 510 511
FCMOV(cmpfeq)
FCMOV(cmpfne)
FCMOV(cmpflt)
FCMOV(cmpfge)
FCMOV(cmpfle)
FCMOV(cmpfgt)
J
j_mayer 已提交
512

513
/* EXTWH, EXTWH, EXTLH, EXTQH */
B
Blue Swirl 已提交
514 515
static inline void gen_ext_h(void(*tcg_gen_ext_i64)(TCGv t0, TCGv t1),
                             int ra, int rb, int rc, int islit, uint8_t lit)
516 517 518 519 520
{
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
521 522 523 524 525
        if (islit) {
            if (lit != 0)
                tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], 64 - ((lit & 7) * 8));
            else
                tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[ra]);
A
aurel32 已提交
526
        } else {
527
            TCGv tmp1, tmp2;
P
pbrook 已提交
528
            tmp1 = tcg_temp_new();
529 530 531 532 533
            tcg_gen_andi_i64(tmp1, cpu_ir[rb], 7);
            tcg_gen_shli_i64(tmp1, tmp1, 3);
            tmp2 = tcg_const_i64(64);
            tcg_gen_sub_i64(tmp1, tmp2, tmp1);
            tcg_temp_free(tmp2);
534
            tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], tmp1);
535
            tcg_temp_free(tmp1);
536 537 538
        }
        if (tcg_gen_ext_i64)
            tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
539 540 541 542 543
    } else
        tcg_gen_movi_i64(cpu_ir[rc], 0);
}

/* EXTBL, EXTWL, EXTWL, EXTLL, EXTQL */
B
Blue Swirl 已提交
544 545
static inline void gen_ext_l(void(*tcg_gen_ext_i64)(TCGv t0, TCGv t1),
                             int ra, int rb, int rc, int islit, uint8_t lit)
546 547 548 549 550
{
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
551 552 553
        if (islit) {
                tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], (lit & 7) * 8);
        } else {
P
pbrook 已提交
554
            TCGv tmp = tcg_temp_new();
555 556
            tcg_gen_andi_i64(tmp, cpu_ir[rb], 7);
            tcg_gen_shli_i64(tmp, tmp, 3);
557
            tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], tmp);
558
            tcg_temp_free(tmp);
A
aurel32 已提交
559
        }
560 561
        if (tcg_gen_ext_i64)
            tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
562 563 564 565
    } else
        tcg_gen_movi_i64(cpu_ir[rc], 0);
}

566
/* Code to call arith3 helpers */
P
pbrook 已提交
567
#define ARITH3(name)                                                  \
B
Blue Swirl 已提交
568 569
static inline void glue(gen_, name)(int ra, int rb, int rc, int islit,\
                                    uint8_t lit)                      \
P
pbrook 已提交
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
{                                                                     \
    if (unlikely(rc == 31))                                           \
        return;                                                       \
                                                                      \
    if (ra != 31) {                                                   \
        if (islit) {                                                  \
            TCGv tmp = tcg_const_i64(lit);                            \
            gen_helper_ ## name(cpu_ir[rc], cpu_ir[ra], tmp);         \
            tcg_temp_free(tmp);                                       \
        } else                                                        \
            gen_helper_ ## name (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]); \
    } else {                                                          \
        TCGv tmp1 = tcg_const_i64(0);                                 \
        if (islit) {                                                  \
            TCGv tmp2 = tcg_const_i64(lit);                           \
            gen_helper_ ## name (cpu_ir[rc], tmp1, tmp2);             \
            tcg_temp_free(tmp2);                                      \
        } else                                                        \
            gen_helper_ ## name (cpu_ir[rc], tmp1, cpu_ir[rb]);       \
        tcg_temp_free(tmp1);                                          \
    }                                                                 \
591
}
P
pbrook 已提交
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
ARITH3(cmpbge)
ARITH3(addlv)
ARITH3(sublv)
ARITH3(addqv)
ARITH3(subqv)
ARITH3(mskbl)
ARITH3(insbl)
ARITH3(mskwl)
ARITH3(inswl)
ARITH3(mskll)
ARITH3(insll)
ARITH3(zap)
ARITH3(zapnot)
ARITH3(mskql)
ARITH3(insql)
ARITH3(mskwh)
ARITH3(inswh)
ARITH3(msklh)
ARITH3(inslh)
ARITH3(mskqh)
ARITH3(insqh)
ARITH3(umulh)
ARITH3(mullv)
ARITH3(mulqv)
616

B
Blue Swirl 已提交
617 618
static inline void gen_cmp(TCGCond cond, int ra, int rb, int rc, int islit,
                           uint8_t lit)
619 620 621 622 623 624 625 626 627 628 629
{
    int l1, l2;
    TCGv tmp;

    if (unlikely(rc == 31))
    return;

    l1 = gen_new_label();
    l2 = gen_new_label();

    if (ra != 31) {
P
pbrook 已提交
630
        tmp = tcg_temp_new();
631 632 633 634 635 636
        tcg_gen_mov_i64(tmp, cpu_ir[ra]);
    } else
        tmp = tcg_const_i64(0);
    if (islit)
        tcg_gen_brcondi_i64(cond, tmp, lit, l1);
    else
637
        tcg_gen_brcond_i64(cond, tmp, cpu_ir[rb], l1);
638 639 640 641 642 643 644 645

    tcg_gen_movi_i64(cpu_ir[rc], 0);
    tcg_gen_br(l2);
    gen_set_label(l1);
    tcg_gen_movi_i64(cpu_ir[rc], 1);
    gen_set_label(l2);
}

B
Blue Swirl 已提交
646
static inline int translate_one(DisasContext *ctx, uint32_t insn)
J
j_mayer 已提交
647 648 649 650 651
{
    uint32_t palcode;
    int32_t disp21, disp16, disp12;
    uint16_t fn11, fn16;
    uint8_t opc, ra, rb, rc, sbz, fpfn, fn7, fn2, islit;
652
    uint8_t lit;
J
j_mayer 已提交
653 654 655 656 657 658 659 660 661
    int ret;

    /* Decode all instruction fields */
    opc = insn >> 26;
    ra = (insn >> 21) & 0x1F;
    rb = (insn >> 16) & 0x1F;
    rc = insn & 0x1F;
    sbz = (insn >> 13) & 0x07;
    islit = (insn >> 12) & 1;
662 663 664 665 666
    if (rb == 31 && !islit) {
        islit = 1;
        lit = 0;
    } else
        lit = (insn >> 13) & 0xFF;
J
j_mayer 已提交
667 668 669 670 671 672 673 674 675 676
    palcode = insn & 0x03FFFFFF;
    disp21 = ((int32_t)((insn & 0x001FFFFF) << 11)) >> 11;
    disp16 = (int16_t)(insn & 0x0000FFFF);
    disp12 = (int32_t)((insn & 0x00000FFF) << 20) >> 20;
    fn16 = insn & 0x0000FFFF;
    fn11 = (insn >> 5) & 0x000007FF;
    fpfn = fn11 & 0x3F;
    fn7 = (insn >> 5) & 0x0000007F;
    fn2 = (insn >> 5) & 0x00000003;
    ret = 0;
677 678
    LOG_DISAS("opc %02x ra %d rb %d rc %d disp16 %04x\n",
              opc, ra, rb, rc, disp16);
J
j_mayer 已提交
679 680 681 682 683
    switch (opc) {
    case 0x00:
        /* CALL_PAL */
        if (palcode >= 0x80 && palcode < 0xC0) {
            /* Unprivileged PAL call */
684
            gen_excp(ctx, EXCP_CALL_PAL + ((palcode & 0x3F) << 6), 0);
J
j_mayer 已提交
685 686 687 688 689 690
#if !defined (CONFIG_USER_ONLY)
        } else if (palcode < 0x40) {
            /* Privileged PAL code */
            if (ctx->mem_idx & 1)
                goto invalid_opc;
            else
691
                gen_excp(ctx, EXCP_CALL_PALP + ((palcode & 0x3F) << 6), 0);
J
j_mayer 已提交
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
#endif
        } else {
            /* Invalid PAL call */
            goto invalid_opc;
        }
        ret = 3;
        break;
    case 0x01:
        /* OPC01 */
        goto invalid_opc;
    case 0x02:
        /* OPC02 */
        goto invalid_opc;
    case 0x03:
        /* OPC03 */
        goto invalid_opc;
    case 0x04:
        /* OPC04 */
        goto invalid_opc;
    case 0x05:
        /* OPC05 */
        goto invalid_opc;
    case 0x06:
        /* OPC06 */
        goto invalid_opc;
    case 0x07:
        /* OPC07 */
        goto invalid_opc;
    case 0x08:
        /* LDA */
A
aurel32 已提交
722
        if (likely(ra != 31)) {
A
aurel32 已提交
723
            if (rb != 31)
A
aurel32 已提交
724 725 726
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16);
            else
                tcg_gen_movi_i64(cpu_ir[ra], disp16);
A
aurel32 已提交
727
        }
J
j_mayer 已提交
728 729 730
        break;
    case 0x09:
        /* LDAH */
A
aurel32 已提交
731
        if (likely(ra != 31)) {
A
aurel32 已提交
732
            if (rb != 31)
A
aurel32 已提交
733 734 735
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16 << 16);
            else
                tcg_gen_movi_i64(cpu_ir[ra], disp16 << 16);
A
aurel32 已提交
736
        }
J
j_mayer 已提交
737 738 739 740 741
        break;
    case 0x0A:
        /* LDBU */
        if (!(ctx->amask & AMASK_BWX))
            goto invalid_opc;
A
aurel32 已提交
742
        gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
743 744 745
        break;
    case 0x0B:
        /* LDQ_U */
A
aurel32 已提交
746
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
747 748 749 750 751
        break;
    case 0x0C:
        /* LDWU */
        if (!(ctx->amask & AMASK_BWX))
            goto invalid_opc;
752
        gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
753 754 755
        break;
    case 0x0D:
        /* STW */
A
aurel32 已提交
756
        gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0, 0);
J
j_mayer 已提交
757 758 759
        break;
    case 0x0E:
        /* STB */
A
aurel32 已提交
760
        gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0, 0);
J
j_mayer 已提交
761 762 763
        break;
    case 0x0F:
        /* STQ_U */
A
aurel32 已提交
764
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1, 0);
J
j_mayer 已提交
765 766 767 768 769
        break;
    case 0x10:
        switch (fn7) {
        case 0x00:
            /* ADDL */
770 771 772 773 774
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit) {
                        tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
775
                    } else {
776 777
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
778
                    }
779 780
                } else {
                    if (islit)
781
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
782
                    else
783
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
784 785
                }
            }
J
j_mayer 已提交
786 787 788
            break;
        case 0x02:
            /* S4ADDL */
789 790
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
791
                    TCGv tmp = tcg_temp_new();
792 793 794 795 796 797 798
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
                    if (islit)
                        tcg_gen_addi_i64(tmp, tmp, lit);
                    else
                        tcg_gen_add_i64(tmp, tmp, cpu_ir[rb]);
                    tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
                    tcg_temp_free(tmp);
799 800 801 802
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
803
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
804 805
                }
            }
J
j_mayer 已提交
806 807 808
            break;
        case 0x09:
            /* SUBL */
809 810
            if (likely(rc != 31)) {
                if (ra != 31) {
811
                    if (islit)
812
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
813
                    else
814
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
815
                    tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
816 817 818
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
819
                    else {
820 821 822 823
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
                }
            }
J
j_mayer 已提交
824 825 826
            break;
        case 0x0B:
            /* S4SUBL */
827 828
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
829
                    TCGv tmp = tcg_temp_new();
830 831 832 833 834 835 836
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
                    if (islit)
                        tcg_gen_subi_i64(tmp, tmp, lit);
                    else
                        tcg_gen_sub_i64(tmp, tmp, cpu_ir[rb]);
                    tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
                    tcg_temp_free(tmp);
837 838 839
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
840
                    else {
841 842
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
843
                    }
844 845
                }
            }
J
j_mayer 已提交
846 847 848
            break;
        case 0x0F:
            /* CMPBGE */
P
pbrook 已提交
849
            gen_cmpbge(ra, rb, rc, islit, lit);
J
j_mayer 已提交
850 851 852
            break;
        case 0x12:
            /* S8ADDL */
853 854
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
855
                    TCGv tmp = tcg_temp_new();
856 857 858 859 860 861 862
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
                    if (islit)
                        tcg_gen_addi_i64(tmp, tmp, lit);
                    else
                        tcg_gen_add_i64(tmp, tmp, cpu_ir[rb]);
                    tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
                    tcg_temp_free(tmp);
863 864 865 866
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
867
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
868 869
                }
            }
J
j_mayer 已提交
870 871 872
            break;
        case 0x1B:
            /* S8SUBL */
873 874
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
875
                    TCGv tmp = tcg_temp_new();
876 877 878 879 880 881 882
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
                    if (islit)
                        tcg_gen_subi_i64(tmp, tmp, lit);
                    else
                       tcg_gen_sub_i64(tmp, tmp, cpu_ir[rb]);
                    tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
                    tcg_temp_free(tmp);
883 884 885
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
886
                    else
887 888
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
889
                    }
890 891
                }
            }
J
j_mayer 已提交
892 893 894
            break;
        case 0x1D:
            /* CMPULT */
895
            gen_cmp(TCG_COND_LTU, ra, rb, rc, islit, lit);
J
j_mayer 已提交
896 897 898
            break;
        case 0x20:
            /* ADDQ */
899 900 901 902 903
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
904
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
905 906 907 908
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
909
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
910 911
                }
            }
J
j_mayer 已提交
912 913 914
            break;
        case 0x22:
            /* S4ADDQ */
915 916
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
917
                    TCGv tmp = tcg_temp_new();
918 919 920 921 922 923
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
                    if (islit)
                        tcg_gen_addi_i64(cpu_ir[rc], tmp, lit);
                    else
                        tcg_gen_add_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
                    tcg_temp_free(tmp);
924 925 926 927
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
928
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
929 930
                }
            }
J
j_mayer 已提交
931 932 933
            break;
        case 0x29:
            /* SUBQ */
934 935 936 937 938
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
939
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
940 941 942 943
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
944
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
945 946
                }
            }
J
j_mayer 已提交
947 948 949
            break;
        case 0x2B:
            /* S4SUBQ */
950 951
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
952
                    TCGv tmp = tcg_temp_new();
953 954 955 956 957 958
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
                    if (islit)
                        tcg_gen_subi_i64(cpu_ir[rc], tmp, lit);
                    else
                        tcg_gen_sub_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
                    tcg_temp_free(tmp);
959 960 961 962
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
963
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
964 965
                }
            }
J
j_mayer 已提交
966 967 968
            break;
        case 0x2D:
            /* CMPEQ */
969
            gen_cmp(TCG_COND_EQ, ra, rb, rc, islit, lit);
J
j_mayer 已提交
970 971 972
            break;
        case 0x32:
            /* S8ADDQ */
973 974
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
975
                    TCGv tmp = tcg_temp_new();
976 977 978 979 980 981
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
                    if (islit)
                        tcg_gen_addi_i64(cpu_ir[rc], tmp, lit);
                    else
                        tcg_gen_add_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
                    tcg_temp_free(tmp);
982 983 984 985
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
986
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
987 988
                }
            }
J
j_mayer 已提交
989 990 991
            break;
        case 0x3B:
            /* S8SUBQ */
992 993
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
994
                    TCGv tmp = tcg_temp_new();
995 996 997 998 999 1000
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
                    if (islit)
                        tcg_gen_subi_i64(cpu_ir[rc], tmp, lit);
                    else
                        tcg_gen_sub_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
                    tcg_temp_free(tmp);
1001 1002 1003 1004
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
1005
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1006 1007
                }
            }
J
j_mayer 已提交
1008 1009 1010
            break;
        case 0x3D:
            /* CMPULE */
1011
            gen_cmp(TCG_COND_LEU, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1012 1013 1014
            break;
        case 0x40:
            /* ADDL/V */
P
pbrook 已提交
1015
            gen_addlv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1016 1017 1018
            break;
        case 0x49:
            /* SUBL/V */
P
pbrook 已提交
1019
            gen_sublv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1020 1021 1022
            break;
        case 0x4D:
            /* CMPLT */
1023
            gen_cmp(TCG_COND_LT, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1024 1025 1026
            break;
        case 0x60:
            /* ADDQ/V */
P
pbrook 已提交
1027
            gen_addqv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1028 1029 1030
            break;
        case 0x69:
            /* SUBQ/V */
P
pbrook 已提交
1031
            gen_subqv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1032 1033 1034
            break;
        case 0x6D:
            /* CMPLE */
1035
            gen_cmp(TCG_COND_LE, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1036 1037 1038 1039 1040 1041 1042 1043 1044
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x11:
        switch (fn7) {
        case 0x00:
            /* AND */
1045
            if (likely(rc != 31)) {
1046
                if (ra == 31)
1047 1048 1049 1050 1051 1052
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
                else if (islit)
                    tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                else
                    tcg_gen_and_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
            }
J
j_mayer 已提交
1053 1054 1055
            break;
        case 0x08:
            /* BIC */
1056 1057 1058 1059
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1060 1061
                    else
                        tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1062 1063 1064
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1065 1066 1067
            break;
        case 0x14:
            /* CMOVLBS */
A
aurel32 已提交
1068
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 1);
J
j_mayer 已提交
1069 1070 1071
            break;
        case 0x16:
            /* CMOVLBC */
A
aurel32 已提交
1072
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 1);
J
j_mayer 已提交
1073 1074 1075
            break;
        case 0x20:
            /* BIS */
1076 1077 1078 1079
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], lit);
1080
                    else
1081
                        tcg_gen_or_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
J
j_mayer 已提交
1082
                } else {
1083 1084 1085
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1086
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
J
j_mayer 已提交
1087 1088 1089 1090 1091
                }
            }
            break;
        case 0x24:
            /* CMOVEQ */
A
aurel32 已提交
1092
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1093 1094 1095
            break;
        case 0x26:
            /* CMOVNE */
A
aurel32 已提交
1096
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1097 1098 1099
            break;
        case 0x28:
            /* ORNOT */
1100
            if (likely(rc != 31)) {
1101
                if (ra != 31) {
1102 1103
                    if (islit)
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1104 1105
                    else
                        tcg_gen_orc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1106 1107 1108 1109 1110 1111 1112
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], ~lit);
                    else
                        tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
                }
            }
J
j_mayer 已提交
1113 1114 1115
            break;
        case 0x40:
            /* XOR */
1116 1117 1118 1119 1120
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
1121
                        tcg_gen_xor_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1122 1123 1124 1125
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1126
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1127 1128
                }
            }
J
j_mayer 已提交
1129 1130 1131
            break;
        case 0x44:
            /* CMOVLT */
A
aurel32 已提交
1132
            gen_cmov(TCG_COND_GE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1133 1134 1135
            break;
        case 0x46:
            /* CMOVGE */
A
aurel32 已提交
1136
            gen_cmov(TCG_COND_LT, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1137 1138 1139
            break;
        case 0x48:
            /* EQV */
1140 1141 1142 1143
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1144 1145
                    else
                        tcg_gen_eqv_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1146 1147 1148 1149
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], ~lit);
                    else
1150
                        tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
1151 1152
                }
            }
J
j_mayer 已提交
1153 1154 1155
            break;
        case 0x61:
            /* AMASK */
1156 1157
            if (likely(rc != 31)) {
                if (islit)
A
aurel32 已提交
1158
                    tcg_gen_movi_i64(cpu_ir[rc], lit);
1159
                else
A
aurel32 已提交
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
                    tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
                switch (ctx->env->implver) {
                case IMPLVER_2106x:
                    /* EV4, EV45, LCA, LCA45 & EV5 */
                    break;
                case IMPLVER_21164:
                case IMPLVER_21264:
                case IMPLVER_21364:
                    tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[rc],
                                     ~(uint64_t)ctx->amask);
                    break;
                }
1172
            }
J
j_mayer 已提交
1173 1174 1175
            break;
        case 0x64:
            /* CMOVLE */
A
aurel32 已提交
1176
            gen_cmov(TCG_COND_GT, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1177 1178 1179
            break;
        case 0x66:
            /* CMOVGT */
A
aurel32 已提交
1180
            gen_cmov(TCG_COND_LE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1181 1182 1183
            break;
        case 0x6C:
            /* IMPLVER */
A
aurel32 已提交
1184
            if (rc != 31)
1185
                tcg_gen_movi_i64(cpu_ir[rc], ctx->env->implver);
J
j_mayer 已提交
1186 1187 1188 1189 1190 1191 1192 1193 1194
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x12:
        switch (fn7) {
        case 0x02:
            /* MSKBL */
P
pbrook 已提交
1195
            gen_mskbl(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1196 1197 1198
            break;
        case 0x06:
            /* EXTBL */
1199
            gen_ext_l(&tcg_gen_ext8u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1200 1201 1202
            break;
        case 0x0B:
            /* INSBL */
P
pbrook 已提交
1203
            gen_insbl(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1204 1205 1206
            break;
        case 0x12:
            /* MSKWL */
P
pbrook 已提交
1207
            gen_mskwl(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1208 1209 1210
            break;
        case 0x16:
            /* EXTWL */
1211
            gen_ext_l(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1212 1213 1214
            break;
        case 0x1B:
            /* INSWL */
P
pbrook 已提交
1215
            gen_inswl(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1216 1217 1218
            break;
        case 0x22:
            /* MSKLL */
P
pbrook 已提交
1219
            gen_mskll(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1220 1221 1222
            break;
        case 0x26:
            /* EXTLL */
1223
            gen_ext_l(&tcg_gen_ext32u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1224 1225 1226
            break;
        case 0x2B:
            /* INSLL */
P
pbrook 已提交
1227
            gen_insll(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1228 1229 1230
            break;
        case 0x30:
            /* ZAP */
P
pbrook 已提交
1231
            gen_zap(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1232 1233 1234
            break;
        case 0x31:
            /* ZAPNOT */
P
pbrook 已提交
1235
            gen_zapnot(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1236 1237 1238
            break;
        case 0x32:
            /* MSKQL */
P
pbrook 已提交
1239
            gen_mskql(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1240 1241 1242
            break;
        case 0x34:
            /* SRL */
1243 1244 1245 1246
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1247
                    else {
P
pbrook 已提交
1248
                        TCGv shift = tcg_temp_new();
1249 1250 1251
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
1252
                    }
1253 1254 1255
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1256 1257 1258
            break;
        case 0x36:
            /* EXTQL */
1259
            gen_ext_l(NULL, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1260 1261 1262
            break;
        case 0x39:
            /* SLL */
1263 1264 1265 1266
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1267
                    else {
P
pbrook 已提交
1268
                        TCGv shift = tcg_temp_new();
1269 1270 1271
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
1272
                    }
1273 1274 1275
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1276 1277 1278
            break;
        case 0x3B:
            /* INSQL */
P
pbrook 已提交
1279
            gen_insql(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1280 1281 1282
            break;
        case 0x3C:
            /* SRA */
1283 1284 1285 1286
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_sari_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1287
                    else {
P
pbrook 已提交
1288
                        TCGv shift = tcg_temp_new();
1289 1290 1291
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_sar_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
1292
                    }
1293 1294 1295
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1296 1297 1298
            break;
        case 0x52:
            /* MSKWH */
P
pbrook 已提交
1299
            gen_mskwh(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1300 1301 1302
            break;
        case 0x57:
            /* INSWH */
P
pbrook 已提交
1303
            gen_inswh(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1304 1305 1306
            break;
        case 0x5A:
            /* EXTWH */
1307
            gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1308 1309 1310
            break;
        case 0x62:
            /* MSKLH */
P
pbrook 已提交
1311
            gen_msklh(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1312 1313 1314
            break;
        case 0x67:
            /* INSLH */
P
pbrook 已提交
1315
            gen_inslh(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1316 1317 1318
            break;
        case 0x6A:
            /* EXTLH */
1319
            gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1320 1321 1322
            break;
        case 0x72:
            /* MSKQH */
P
pbrook 已提交
1323
            gen_mskqh(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1324 1325 1326
            break;
        case 0x77:
            /* INSQH */
P
pbrook 已提交
1327
            gen_insqh(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1328 1329 1330
            break;
        case 0x7A:
            /* EXTQH */
1331
            gen_ext_h(NULL, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1332 1333 1334 1335 1336 1337 1338 1339 1340
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x13:
        switch (fn7) {
        case 0x00:
            /* MULL */
1341
            if (likely(rc != 31)) {
1342
                if (ra == 31)
1343 1344 1345 1346 1347 1348 1349 1350 1351
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
                else {
                    if (islit)
                        tcg_gen_muli_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
                        tcg_gen_mul_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
                    tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
                }
            }
J
j_mayer 已提交
1352 1353 1354
            break;
        case 0x20:
            /* MULQ */
1355
            if (likely(rc != 31)) {
1356
                if (ra == 31)
1357 1358 1359 1360 1361 1362
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
                else if (islit)
                    tcg_gen_muli_i64(cpu_ir[rc], cpu_ir[ra], lit);
                else
                    tcg_gen_mul_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
            }
J
j_mayer 已提交
1363 1364 1365
            break;
        case 0x30:
            /* UMULH */
P
pbrook 已提交
1366
            gen_umulh(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1367 1368 1369
            break;
        case 0x40:
            /* MULL/V */
P
pbrook 已提交
1370
            gen_mullv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1371 1372 1373
            break;
        case 0x60:
            /* MULQ/V */
P
pbrook 已提交
1374
            gen_mulqv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x14:
        switch (fpfn) { /* f11 & 0x3F */
        case 0x04:
            /* ITOFS */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1386 1387
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1388
                    TCGv_i32 tmp = tcg_temp_new_i32();
A
aurel32 已提交
1389
                    tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
P
pbrook 已提交
1390 1391
                    gen_helper_memory_to_s(cpu_fir[rc], tmp);
                    tcg_temp_free_i32(tmp);
A
aurel32 已提交
1392 1393 1394
                } else
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
            }
J
j_mayer 已提交
1395 1396 1397 1398 1399
            break;
        case 0x0A:
            /* SQRTF */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
P
pbrook 已提交
1400
            gen_fsqrtf(rb, rc);
J
j_mayer 已提交
1401 1402 1403 1404 1405
            break;
        case 0x0B:
            /* SQRTS */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
P
pbrook 已提交
1406
            gen_fsqrts(rb, rc);
J
j_mayer 已提交
1407 1408 1409 1410 1411
            break;
        case 0x14:
            /* ITOFF */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1412 1413
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1414
                    TCGv_i32 tmp = tcg_temp_new_i32();
A
aurel32 已提交
1415
                    tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
P
pbrook 已提交
1416 1417
                    gen_helper_memory_to_f(cpu_fir[rc], tmp);
                    tcg_temp_free_i32(tmp);
A
aurel32 已提交
1418 1419 1420
                } else
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
            }
J
j_mayer 已提交
1421 1422 1423 1424 1425
            break;
        case 0x24:
            /* ITOFT */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1426 1427 1428 1429 1430 1431
            if (likely(rc != 31)) {
                if (ra != 31)
                    tcg_gen_mov_i64(cpu_fir[rc], cpu_ir[ra]);
                else
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
            }
J
j_mayer 已提交
1432 1433 1434 1435 1436
            break;
        case 0x2A:
            /* SQRTG */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
P
pbrook 已提交
1437
            gen_fsqrtg(rb, rc);
J
j_mayer 已提交
1438 1439 1440 1441 1442
            break;
        case 0x02B:
            /* SQRTT */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
P
pbrook 已提交
1443
            gen_fsqrtt(rb, rc);
J
j_mayer 已提交
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x15:
        /* VAX floating point */
        /* XXX: rounding mode and trap are ignored (!) */
        switch (fpfn) { /* f11 & 0x3F */
        case 0x00:
            /* ADDF */
P
pbrook 已提交
1455
            gen_faddf(ra, rb, rc);
J
j_mayer 已提交
1456 1457 1458
            break;
        case 0x01:
            /* SUBF */
P
pbrook 已提交
1459
            gen_fsubf(ra, rb, rc);
J
j_mayer 已提交
1460 1461 1462
            break;
        case 0x02:
            /* MULF */
P
pbrook 已提交
1463
            gen_fmulf(ra, rb, rc);
J
j_mayer 已提交
1464 1465 1466
            break;
        case 0x03:
            /* DIVF */
P
pbrook 已提交
1467
            gen_fdivf(ra, rb, rc);
J
j_mayer 已提交
1468 1469 1470 1471
            break;
        case 0x1E:
            /* CVTDG */
#if 0 // TODO
P
pbrook 已提交
1472
            gen_fcvtdg(rb, rc);
J
j_mayer 已提交
1473 1474 1475 1476 1477 1478
#else
            goto invalid_opc;
#endif
            break;
        case 0x20:
            /* ADDG */
P
pbrook 已提交
1479
            gen_faddg(ra, rb, rc);
J
j_mayer 已提交
1480 1481 1482
            break;
        case 0x21:
            /* SUBG */
P
pbrook 已提交
1483
            gen_fsubg(ra, rb, rc);
J
j_mayer 已提交
1484 1485 1486
            break;
        case 0x22:
            /* MULG */
P
pbrook 已提交
1487
            gen_fmulg(ra, rb, rc);
J
j_mayer 已提交
1488 1489 1490
            break;
        case 0x23:
            /* DIVG */
P
pbrook 已提交
1491
            gen_fdivg(ra, rb, rc);
J
j_mayer 已提交
1492 1493 1494
            break;
        case 0x25:
            /* CMPGEQ */
P
pbrook 已提交
1495
            gen_fcmpgeq(ra, rb, rc);
J
j_mayer 已提交
1496 1497 1498
            break;
        case 0x26:
            /* CMPGLT */
P
pbrook 已提交
1499
            gen_fcmpglt(ra, rb, rc);
J
j_mayer 已提交
1500 1501 1502
            break;
        case 0x27:
            /* CMPGLE */
P
pbrook 已提交
1503
            gen_fcmpgle(ra, rb, rc);
J
j_mayer 已提交
1504 1505 1506
            break;
        case 0x2C:
            /* CVTGF */
P
pbrook 已提交
1507
            gen_fcvtgf(rb, rc);
J
j_mayer 已提交
1508 1509 1510 1511
            break;
        case 0x2D:
            /* CVTGD */
#if 0 // TODO
P
pbrook 已提交
1512
            gen_fcvtgd(rb, rc);
J
j_mayer 已提交
1513 1514 1515 1516 1517 1518
#else
            goto invalid_opc;
#endif
            break;
        case 0x2F:
            /* CVTGQ */
P
pbrook 已提交
1519
            gen_fcvtgq(rb, rc);
J
j_mayer 已提交
1520 1521 1522
            break;
        case 0x3C:
            /* CVTQF */
P
pbrook 已提交
1523
            gen_fcvtqf(rb, rc);
J
j_mayer 已提交
1524 1525 1526
            break;
        case 0x3E:
            /* CVTQG */
P
pbrook 已提交
1527
            gen_fcvtqg(rb, rc);
J
j_mayer 已提交
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x16:
        /* IEEE floating-point */
        /* XXX: rounding mode and traps are ignored (!) */
        switch (fpfn) { /* f11 & 0x3F */
        case 0x00:
            /* ADDS */
P
pbrook 已提交
1539
            gen_fadds(ra, rb, rc);
J
j_mayer 已提交
1540 1541 1542
            break;
        case 0x01:
            /* SUBS */
P
pbrook 已提交
1543
            gen_fsubs(ra, rb, rc);
J
j_mayer 已提交
1544 1545 1546
            break;
        case 0x02:
            /* MULS */
P
pbrook 已提交
1547
            gen_fmuls(ra, rb, rc);
J
j_mayer 已提交
1548 1549 1550
            break;
        case 0x03:
            /* DIVS */
P
pbrook 已提交
1551
            gen_fdivs(ra, rb, rc);
J
j_mayer 已提交
1552 1553 1554
            break;
        case 0x20:
            /* ADDT */
P
pbrook 已提交
1555
            gen_faddt(ra, rb, rc);
J
j_mayer 已提交
1556 1557 1558
            break;
        case 0x21:
            /* SUBT */
P
pbrook 已提交
1559
            gen_fsubt(ra, rb, rc);
J
j_mayer 已提交
1560 1561 1562
            break;
        case 0x22:
            /* MULT */
P
pbrook 已提交
1563
            gen_fmult(ra, rb, rc);
J
j_mayer 已提交
1564 1565 1566
            break;
        case 0x23:
            /* DIVT */
P
pbrook 已提交
1567
            gen_fdivt(ra, rb, rc);
J
j_mayer 已提交
1568 1569 1570
            break;
        case 0x24:
            /* CMPTUN */
P
pbrook 已提交
1571
            gen_fcmptun(ra, rb, rc);
J
j_mayer 已提交
1572 1573 1574
            break;
        case 0x25:
            /* CMPTEQ */
P
pbrook 已提交
1575
            gen_fcmpteq(ra, rb, rc);
J
j_mayer 已提交
1576 1577 1578
            break;
        case 0x26:
            /* CMPTLT */
P
pbrook 已提交
1579
            gen_fcmptlt(ra, rb, rc);
J
j_mayer 已提交
1580 1581 1582
            break;
        case 0x27:
            /* CMPTLE */
P
pbrook 已提交
1583
            gen_fcmptle(ra, rb, rc);
J
j_mayer 已提交
1584 1585 1586
            break;
        case 0x2C:
            /* XXX: incorrect */
A
aurel32 已提交
1587
            if (fn11 == 0x2AC || fn11 == 0x6AC) {
J
j_mayer 已提交
1588
                /* CVTST */
P
pbrook 已提交
1589
                gen_fcvtst(rb, rc);
J
j_mayer 已提交
1590 1591
            } else {
                /* CVTTS */
P
pbrook 已提交
1592
                gen_fcvtts(rb, rc);
J
j_mayer 已提交
1593 1594 1595 1596
            }
            break;
        case 0x2F:
            /* CVTTQ */
P
pbrook 已提交
1597
            gen_fcvttq(rb, rc);
J
j_mayer 已提交
1598 1599 1600
            break;
        case 0x3C:
            /* CVTQS */
P
pbrook 已提交
1601
            gen_fcvtqs(rb, rc);
J
j_mayer 已提交
1602 1603 1604
            break;
        case 0x3E:
            /* CVTQT */
P
pbrook 已提交
1605
            gen_fcvtqt(rb, rc);
J
j_mayer 已提交
1606 1607 1608 1609 1610 1611 1612 1613 1614
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x17:
        switch (fn11) {
        case 0x010:
            /* CVTLQ */
P
pbrook 已提交
1615
            gen_fcvtlq(rb, rc);
J
j_mayer 已提交
1616 1617
            break;
        case 0x020:
A
aurel32 已提交
1618 1619
            if (likely(rc != 31)) {
                if (ra == rb)
J
j_mayer 已提交
1620
                    /* FMOV */
A
aurel32 已提交
1621 1622 1623
                    tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
                else
                    /* CPYS */
P
pbrook 已提交
1624
                    gen_fcpys(ra, rb, rc);
J
j_mayer 已提交
1625 1626 1627 1628
            }
            break;
        case 0x021:
            /* CPYSN */
P
pbrook 已提交
1629
            gen_fcpysn(ra, rb, rc);
J
j_mayer 已提交
1630 1631 1632
            break;
        case 0x022:
            /* CPYSE */
P
pbrook 已提交
1633
            gen_fcpyse(ra, rb, rc);
J
j_mayer 已提交
1634 1635 1636
            break;
        case 0x024:
            /* MT_FPCR */
A
aurel32 已提交
1637
            if (likely(ra != 31))
P
pbrook 已提交
1638
                gen_helper_store_fpcr(cpu_fir[ra]);
A
aurel32 已提交
1639 1640
            else {
                TCGv tmp = tcg_const_i64(0);
P
pbrook 已提交
1641
                gen_helper_store_fpcr(tmp);
A
aurel32 已提交
1642 1643
                tcg_temp_free(tmp);
            }
J
j_mayer 已提交
1644 1645 1646
            break;
        case 0x025:
            /* MF_FPCR */
A
aurel32 已提交
1647
            if (likely(ra != 31))
P
pbrook 已提交
1648
                gen_helper_load_fpcr(cpu_fir[ra]);
J
j_mayer 已提交
1649 1650 1651
            break;
        case 0x02A:
            /* FCMOVEQ */
P
pbrook 已提交
1652
            gen_fcmpfeq(ra, rb, rc);
J
j_mayer 已提交
1653 1654 1655
            break;
        case 0x02B:
            /* FCMOVNE */
P
pbrook 已提交
1656
            gen_fcmpfne(ra, rb, rc);
J
j_mayer 已提交
1657 1658 1659
            break;
        case 0x02C:
            /* FCMOVLT */
P
pbrook 已提交
1660
            gen_fcmpflt(ra, rb, rc);
J
j_mayer 已提交
1661 1662 1663
            break;
        case 0x02D:
            /* FCMOVGE */
P
pbrook 已提交
1664
            gen_fcmpfge(ra, rb, rc);
J
j_mayer 已提交
1665 1666 1667
            break;
        case 0x02E:
            /* FCMOVLE */
P
pbrook 已提交
1668
            gen_fcmpfle(ra, rb, rc);
J
j_mayer 已提交
1669 1670 1671
            break;
        case 0x02F:
            /* FCMOVGT */
P
pbrook 已提交
1672
            gen_fcmpfgt(ra, rb, rc);
J
j_mayer 已提交
1673 1674 1675
            break;
        case 0x030:
            /* CVTQL */
P
pbrook 已提交
1676
            gen_fcvtql(rb, rc);
J
j_mayer 已提交
1677 1678 1679
            break;
        case 0x130:
            /* CVTQL/V */
P
pbrook 已提交
1680
            gen_fcvtqlv(rb, rc);
J
j_mayer 已提交
1681 1682 1683
            break;
        case 0x530:
            /* CVTQL/SV */
P
pbrook 已提交
1684
            gen_fcvtqlsv(rb, rc);
J
j_mayer 已提交
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x18:
        switch ((uint16_t)disp16) {
        case 0x0000:
            /* TRAPB */
            /* No-op. Just exit from the current tb */
            ret = 2;
            break;
        case 0x0400:
            /* EXCB */
            /* No-op. Just exit from the current tb */
            ret = 2;
            break;
        case 0x4000:
            /* MB */
            /* No-op */
            break;
        case 0x4400:
            /* WMB */
            /* No-op */
            break;
        case 0x8000:
            /* FETCH */
            /* No-op */
            break;
        case 0xA000:
            /* FETCH_M */
            /* No-op */
            break;
        case 0xC000:
            /* RPCC */
A
aurel32 已提交
1720
            if (ra != 31)
P
pbrook 已提交
1721
                gen_helper_load_pcc(cpu_ir[ra]);
J
j_mayer 已提交
1722 1723 1724
            break;
        case 0xE000:
            /* RC */
A
aurel32 已提交
1725
            if (ra != 31)
P
pbrook 已提交
1726
                gen_helper_rc(cpu_ir[ra]);
J
j_mayer 已提交
1727 1728 1729 1730 1731 1732
            break;
        case 0xE800:
            /* ECB */
            break;
        case 0xF000:
            /* RS */
A
aurel32 已提交
1733
            if (ra != 31)
P
pbrook 已提交
1734
                gen_helper_rs(cpu_ir[ra]);
J
j_mayer 已提交
1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
            break;
        case 0xF800:
            /* WH64 */
            /* No-op */
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x19:
        /* HW_MFPR (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
1751 1752
        if (ra != 31) {
            TCGv tmp = tcg_const_i32(insn & 0xFF);
P
pbrook 已提交
1753
            gen_helper_mfpr(cpu_ir[ra], tmp, cpu_ir[ra]);
1754 1755
            tcg_temp_free(tmp);
        }
J
j_mayer 已提交
1756 1757 1758
        break;
#endif
    case 0x1A:
A
aurel32 已提交
1759 1760 1761 1762
        if (rb != 31)
            tcg_gen_andi_i64(cpu_pc, cpu_ir[rb], ~3);
        else
            tcg_gen_movi_i64(cpu_pc, 0);
A
aurel32 已提交
1763 1764
        if (ra != 31)
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
J
j_mayer 已提交
1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788
        /* Those four jumps only differ by the branch prediction hint */
        switch (fn2) {
        case 0x0:
            /* JMP */
            break;
        case 0x1:
            /* JSR */
            break;
        case 0x2:
            /* RET */
            break;
        case 0x3:
            /* JSR_COROUTINE */
            break;
        }
        ret = 1;
        break;
    case 0x1B:
        /* HW_LD (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
1789
        if (ra != 31) {
P
pbrook 已提交
1790
            TCGv addr = tcg_temp_new();
1791 1792 1793 1794 1795 1796
            if (rb != 31)
                tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
            else
                tcg_gen_movi_i64(addr, disp12);
            switch ((insn >> 12) & 0xF) {
            case 0x0:
1797
                /* Longword physical access (hw_ldl/p) */
P
pbrook 已提交
1798
                gen_helper_ldl_raw(cpu_ir[ra], addr);
1799 1800
                break;
            case 0x1:
1801
                /* Quadword physical access (hw_ldq/p) */
P
pbrook 已提交
1802
                gen_helper_ldq_raw(cpu_ir[ra], addr);
1803 1804
                break;
            case 0x2:
1805
                /* Longword physical access with lock (hw_ldl_l/p) */
P
pbrook 已提交
1806
                gen_helper_ldl_l_raw(cpu_ir[ra], addr);
1807 1808
                break;
            case 0x3:
1809
                /* Quadword physical access with lock (hw_ldq_l/p) */
P
pbrook 已提交
1810
                gen_helper_ldq_l_raw(cpu_ir[ra], addr);
1811 1812
                break;
            case 0x4:
1813 1814
                /* Longword virtual PTE fetch (hw_ldl/v) */
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, 0);
1815 1816
                break;
            case 0x5:
1817 1818
                /* Quadword virtual PTE fetch (hw_ldq/v) */
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, 0);
1819 1820 1821
                break;
            case 0x6:
                /* Incpu_ir[ra]id */
1822
                goto invalid_opc;
1823 1824
            case 0x7:
                /* Incpu_ir[ra]id */
1825
                goto invalid_opc;
1826
            case 0x8:
1827
                /* Longword virtual access (hw_ldl) */
P
pbrook 已提交
1828 1829
                gen_helper_st_virt_to_phys(addr, addr);
                gen_helper_ldl_raw(cpu_ir[ra], addr);
1830 1831
                break;
            case 0x9:
1832
                /* Quadword virtual access (hw_ldq) */
P
pbrook 已提交
1833 1834
                gen_helper_st_virt_to_phys(addr, addr);
                gen_helper_ldq_raw(cpu_ir[ra], addr);
1835 1836
                break;
            case 0xA:
1837 1838
                /* Longword virtual access with protection check (hw_ldl/w) */
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, 0);
1839 1840
                break;
            case 0xB:
1841 1842
                /* Quadword virtual access with protection check (hw_ldq/w) */
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, 0);
1843 1844
                break;
            case 0xC:
1845
                /* Longword virtual access with alt access mode (hw_ldl/a)*/
P
pbrook 已提交
1846 1847 1848 1849
                gen_helper_set_alt_mode();
                gen_helper_st_virt_to_phys(addr, addr);
                gen_helper_ldl_raw(cpu_ir[ra], addr);
                gen_helper_restore_mode();
1850 1851
                break;
            case 0xD:
1852
                /* Quadword virtual access with alt access mode (hw_ldq/a) */
P
pbrook 已提交
1853 1854 1855 1856
                gen_helper_set_alt_mode();
                gen_helper_st_virt_to_phys(addr, addr);
                gen_helper_ldq_raw(cpu_ir[ra], addr);
                gen_helper_restore_mode();
1857 1858 1859
                break;
            case 0xE:
                /* Longword virtual access with alternate access mode and
1860
                 * protection checks (hw_ldl/wa)
1861
                 */
P
pbrook 已提交
1862 1863 1864
                gen_helper_set_alt_mode();
                gen_helper_ldl_data(cpu_ir[ra], addr);
                gen_helper_restore_mode();
1865 1866 1867
                break;
            case 0xF:
                /* Quadword virtual access with alternate access mode and
1868
                 * protection checks (hw_ldq/wa)
1869
                 */
P
pbrook 已提交
1870 1871 1872
                gen_helper_set_alt_mode();
                gen_helper_ldq_data(cpu_ir[ra], addr);
                gen_helper_restore_mode();
1873 1874 1875
                break;
            }
            tcg_temp_free(addr);
J
j_mayer 已提交
1876 1877 1878 1879 1880 1881 1882 1883 1884
        }
        break;
#endif
    case 0x1C:
        switch (fn7) {
        case 0x00:
            /* SEXTB */
            if (!(ctx->amask & AMASK_BWX))
                goto invalid_opc;
1885 1886 1887 1888
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int8_t)lit));
                else
1889
                    tcg_gen_ext8s_i64(cpu_ir[rc], cpu_ir[rb]);
1890
            }
J
j_mayer 已提交
1891 1892 1893 1894 1895
            break;
        case 0x01:
            /* SEXTW */
            if (!(ctx->amask & AMASK_BWX))
                goto invalid_opc;
1896 1897 1898 1899
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
                else
1900
                    tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
1901
            }
J
j_mayer 已提交
1902 1903 1904 1905 1906
            break;
        case 0x30:
            /* CTPOP */
            if (!(ctx->amask & AMASK_CIX))
                goto invalid_opc;
1907 1908 1909 1910
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
                else
P
pbrook 已提交
1911
                    gen_helper_ctpop(cpu_ir[rc], cpu_ir[rb]);
1912
            }
J
j_mayer 已提交
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924
            break;
        case 0x31:
            /* PERR */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x32:
            /* CTLZ */
            if (!(ctx->amask & AMASK_CIX))
                goto invalid_opc;
1925 1926 1927 1928
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
                else
P
pbrook 已提交
1929
                    gen_helper_ctlz(cpu_ir[rc], cpu_ir[rb]);
1930
            }
J
j_mayer 已提交
1931 1932 1933 1934 1935
            break;
        case 0x33:
            /* CTTZ */
            if (!(ctx->amask & AMASK_CIX))
                goto invalid_opc;
1936 1937 1938 1939
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
                else
P
pbrook 已提交
1940
                    gen_helper_cttz(cpu_ir[rc], cpu_ir[rb]);
1941
            }
J
j_mayer 已提交
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
            break;
        case 0x34:
            /* UNPKBW */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x35:
            /* UNPKWL */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x36:
            /* PKWB */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x37:
            /* PKLB */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x38:
            /* MINSB8 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x39:
            /* MINSW4 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3A:
            /* MINUB8 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3B:
            /* MINUW4 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3C:
            /* MAXUB8 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3D:
            /* MAXUW4 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3E:
            /* MAXSB8 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3F:
            /* MAXSW4 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x70:
            /* FTOIT */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
2031 2032 2033 2034 2035 2036
            if (likely(rc != 31)) {
                if (ra != 31)
                    tcg_gen_mov_i64(cpu_ir[rc], cpu_fir[ra]);
                else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
2037 2038 2039 2040 2041
            break;
        case 0x78:
            /* FTOIS */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
2042
            if (rc != 31) {
P
pbrook 已提交
2043
                TCGv_i32 tmp1 = tcg_temp_new_i32();
A
aurel32 已提交
2044
                if (ra != 31)
P
pbrook 已提交
2045
                    gen_helper_s_to_memory(tmp1, cpu_fir[ra]);
A
aurel32 已提交
2046 2047
                else {
                    TCGv tmp2 = tcg_const_i64(0);
P
pbrook 已提交
2048
                    gen_helper_s_to_memory(tmp1, tmp2);
A
aurel32 已提交
2049 2050 2051
                    tcg_temp_free(tmp2);
                }
                tcg_gen_ext_i32_i64(cpu_ir[rc], tmp1);
P
pbrook 已提交
2052
                tcg_temp_free_i32(tmp1);
A
aurel32 已提交
2053
            }
J
j_mayer 已提交
2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x1D:
        /* HW_MTPR (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
2066 2067 2068
        else {
            TCGv tmp1 = tcg_const_i32(insn & 0xFF);
            if (ra != 31)
P
pbrook 已提交
2069
                gen_helper_mtpr(tmp1, cpu_ir[ra]);
2070 2071
            else {
                TCGv tmp2 = tcg_const_i64(0);
P
pbrook 已提交
2072
                gen_helper_mtpr(tmp1, tmp2);
2073 2074 2075 2076 2077
                tcg_temp_free(tmp2);
            }
            tcg_temp_free(tmp1);
            ret = 2;
        }
J
j_mayer 已提交
2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
        break;
#endif
    case 0x1E:
        /* HW_REI (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
        if (rb == 31) {
            /* "Old" alpha */
P
pbrook 已提交
2089
            gen_helper_hw_rei();
J
j_mayer 已提交
2090
        } else {
2091 2092 2093
            TCGv tmp;

            if (ra != 31) {
P
pbrook 已提交
2094
                tmp = tcg_temp_new();
2095 2096 2097
                tcg_gen_addi_i64(tmp, cpu_ir[rb], (((int64_t)insn << 51) >> 51));
            } else
                tmp = tcg_const_i64(((int64_t)insn << 51) >> 51);
P
pbrook 已提交
2098
            gen_helper_hw_ret(tmp);
2099
            tcg_temp_free(tmp);
J
j_mayer 已提交
2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110
        }
        ret = 2;
        break;
#endif
    case 0x1F:
        /* HW_ST (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
2111 2112
        else {
            TCGv addr, val;
P
pbrook 已提交
2113
            addr = tcg_temp_new();
2114 2115 2116 2117 2118 2119 2120
            if (rb != 31)
                tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
            else
                tcg_gen_movi_i64(addr, disp12);
            if (ra != 31)
                val = cpu_ir[ra];
            else {
P
pbrook 已提交
2121
                val = tcg_temp_new();
2122 2123 2124 2125 2126
                tcg_gen_movi_i64(val, 0);
            }
            switch ((insn >> 12) & 0xF) {
            case 0x0:
                /* Longword physical access */
P
pbrook 已提交
2127
                gen_helper_stl_raw(val, addr);
2128 2129 2130
                break;
            case 0x1:
                /* Quadword physical access */
P
pbrook 已提交
2131
                gen_helper_stq_raw(val, addr);
2132 2133 2134
                break;
            case 0x2:
                /* Longword physical access with lock */
P
pbrook 已提交
2135
                gen_helper_stl_c_raw(val, val, addr);
2136 2137 2138
                break;
            case 0x3:
                /* Quadword physical access with lock */
P
pbrook 已提交
2139
                gen_helper_stq_c_raw(val, val, addr);
2140 2141 2142
                break;
            case 0x4:
                /* Longword virtual access */
P
pbrook 已提交
2143 2144
                gen_helper_st_virt_to_phys(addr, addr);
                gen_helper_stl_raw(val, addr);
2145 2146 2147
                break;
            case 0x5:
                /* Quadword virtual access */
P
pbrook 已提交
2148 2149
                gen_helper_st_virt_to_phys(addr, addr);
                gen_helper_stq_raw(val, addr);
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170
                break;
            case 0x6:
                /* Invalid */
                goto invalid_opc;
            case 0x7:
                /* Invalid */
                goto invalid_opc;
            case 0x8:
                /* Invalid */
                goto invalid_opc;
            case 0x9:
                /* Invalid */
                goto invalid_opc;
            case 0xA:
                /* Invalid */
                goto invalid_opc;
            case 0xB:
                /* Invalid */
                goto invalid_opc;
            case 0xC:
                /* Longword virtual access with alternate access mode */
P
pbrook 已提交
2171 2172 2173 2174
                gen_helper_set_alt_mode();
                gen_helper_st_virt_to_phys(addr, addr);
                gen_helper_stl_raw(val, addr);
                gen_helper_restore_mode();
2175 2176 2177
                break;
            case 0xD:
                /* Quadword virtual access with alternate access mode */
P
pbrook 已提交
2178 2179 2180 2181
                gen_helper_set_alt_mode();
                gen_helper_st_virt_to_phys(addr, addr);
                gen_helper_stl_raw(val, addr);
                gen_helper_restore_mode();
2182 2183 2184 2185 2186 2187 2188 2189
                break;
            case 0xE:
                /* Invalid */
                goto invalid_opc;
            case 0xF:
                /* Invalid */
                goto invalid_opc;
            }
A
aurel32 已提交
2190
            if (ra == 31)
2191 2192
                tcg_temp_free(val);
            tcg_temp_free(addr);
J
j_mayer 已提交
2193 2194 2195 2196 2197
        }
        break;
#endif
    case 0x20:
        /* LDF */
A
aurel32 已提交
2198
        gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2199 2200 2201
        break;
    case 0x21:
        /* LDG */
A
aurel32 已提交
2202
        gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2203 2204 2205
        break;
    case 0x22:
        /* LDS */
A
aurel32 已提交
2206
        gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2207 2208 2209
        break;
    case 0x23:
        /* LDT */
A
aurel32 已提交
2210
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2211 2212 2213
        break;
    case 0x24:
        /* STF */
A
aurel32 已提交
2214
        gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0, 0);
J
j_mayer 已提交
2215 2216 2217
        break;
    case 0x25:
        /* STG */
A
aurel32 已提交
2218
        gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0, 0);
J
j_mayer 已提交
2219 2220 2221
        break;
    case 0x26:
        /* STS */
A
aurel32 已提交
2222
        gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0, 0);
J
j_mayer 已提交
2223 2224 2225
        break;
    case 0x27:
        /* STT */
A
aurel32 已提交
2226
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0, 0);
J
j_mayer 已提交
2227 2228 2229
        break;
    case 0x28:
        /* LDL */
A
aurel32 已提交
2230
        gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2231 2232 2233
        break;
    case 0x29:
        /* LDQ */
A
aurel32 已提交
2234
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2235 2236 2237
        break;
    case 0x2A:
        /* LDL_L */
2238
        gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2239 2240 2241
        break;
    case 0x2B:
        /* LDQ_L */
2242
        gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2243 2244 2245
        break;
    case 0x2C:
        /* STL */
A
aurel32 已提交
2246
        gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0, 0);
J
j_mayer 已提交
2247 2248 2249
        break;
    case 0x2D:
        /* STQ */
A
aurel32 已提交
2250
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0, 0);
J
j_mayer 已提交
2251 2252 2253
        break;
    case 0x2E:
        /* STL_C */
A
aurel32 已提交
2254
        gen_store_mem(ctx, &gen_qemu_stl_c, ra, rb, disp16, 0, 0, 1);
J
j_mayer 已提交
2255 2256 2257
        break;
    case 0x2F:
        /* STQ_C */
A
aurel32 已提交
2258
        gen_store_mem(ctx, &gen_qemu_stq_c, ra, rb, disp16, 0, 0, 1);
J
j_mayer 已提交
2259 2260 2261
        break;
    case 0x30:
        /* BR */
A
aurel32 已提交
2262 2263 2264
        if (ra != 31)
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
        tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp21 << 2));
J
j_mayer 已提交
2265 2266
        ret = 1;
        break;
P
pbrook 已提交
2267 2268 2269 2270
    case 0x31: /* FBEQ */
    case 0x32: /* FBLT */
    case 0x33: /* FBLE */
        gen_fbcond(ctx, opc, ra, disp16);
J
j_mayer 已提交
2271 2272 2273 2274
        ret = 1;
        break;
    case 0x34:
        /* BSR */
A
aurel32 已提交
2275 2276 2277
        if (ra != 31)
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
        tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp21 << 2));
J
j_mayer 已提交
2278 2279
        ret = 1;
        break;
P
pbrook 已提交
2280 2281 2282 2283
    case 0x35: /* FBNE */
    case 0x36: /* FBGE */
    case 0x37: /* FBGT */
        gen_fbcond(ctx, opc, ra, disp16);
J
j_mayer 已提交
2284 2285 2286 2287
        ret = 1;
        break;
    case 0x38:
        /* BLBC */
2288
        gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 1);
J
j_mayer 已提交
2289 2290 2291 2292
        ret = 1;
        break;
    case 0x39:
        /* BEQ */
2293
        gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 0);
J
j_mayer 已提交
2294 2295 2296 2297
        ret = 1;
        break;
    case 0x3A:
        /* BLT */
2298
        gen_bcond(ctx, TCG_COND_LT, ra, disp21, 0);
J
j_mayer 已提交
2299 2300 2301 2302
        ret = 1;
        break;
    case 0x3B:
        /* BLE */
2303
        gen_bcond(ctx, TCG_COND_LE, ra, disp21, 0);
J
j_mayer 已提交
2304 2305 2306 2307
        ret = 1;
        break;
    case 0x3C:
        /* BLBS */
2308
        gen_bcond(ctx, TCG_COND_NE, ra, disp21, 1);
J
j_mayer 已提交
2309 2310 2311 2312
        ret = 1;
        break;
    case 0x3D:
        /* BNE */
2313
        gen_bcond(ctx, TCG_COND_NE, ra, disp21, 0);
J
j_mayer 已提交
2314 2315 2316 2317
        ret = 1;
        break;
    case 0x3E:
        /* BGE */
2318
        gen_bcond(ctx, TCG_COND_GE, ra, disp21, 0);
J
j_mayer 已提交
2319 2320 2321 2322
        ret = 1;
        break;
    case 0x3F:
        /* BGT */
2323
        gen_bcond(ctx, TCG_COND_GT, ra, disp21, 0);
J
j_mayer 已提交
2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334
        ret = 1;
        break;
    invalid_opc:
        gen_invalid(ctx);
        ret = 3;
        break;
    }

    return ret;
}

B
Blue Swirl 已提交
2335 2336 2337
static inline void gen_intermediate_code_internal(CPUState *env,
                                                  TranslationBlock *tb,
                                                  int search_pc)
J
j_mayer 已提交
2338 2339 2340 2341 2342 2343 2344 2345
{
#if defined ALPHA_DEBUG_DISAS
    static int insn_count;
#endif
    DisasContext ctx, *ctxp = &ctx;
    target_ulong pc_start;
    uint32_t insn;
    uint16_t *gen_opc_end;
2346
    CPUBreakpoint *bp;
J
j_mayer 已提交
2347 2348
    int j, lj = -1;
    int ret;
P
pbrook 已提交
2349 2350
    int num_insns;
    int max_insns;
J
j_mayer 已提交
2351 2352 2353 2354 2355

    pc_start = tb->pc;
    gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
    ctx.pc = pc_start;
    ctx.amask = env->amask;
2356
    ctx.env = env;
J
j_mayer 已提交
2357 2358 2359 2360 2361 2362
#if defined (CONFIG_USER_ONLY)
    ctx.mem_idx = 0;
#else
    ctx.mem_idx = ((env->ps >> 3) & 3);
    ctx.pal_mode = env->ipr[IPR_EXC_ADDR] & 1;
#endif
P
pbrook 已提交
2363 2364 2365 2366 2367 2368
    num_insns = 0;
    max_insns = tb->cflags & CF_COUNT_MASK;
    if (max_insns == 0)
        max_insns = CF_COUNT_MASK;

    gen_icount_start();
J
j_mayer 已提交
2369
    for (ret = 0; ret == 0;) {
B
Blue Swirl 已提交
2370 2371
        if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
            QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
2372
                if (bp->pc == ctx.pc) {
J
j_mayer 已提交
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384
                    gen_excp(&ctx, EXCP_DEBUG, 0);
                    break;
                }
            }
        }
        if (search_pc) {
            j = gen_opc_ptr - gen_opc_buf;
            if (lj < j) {
                lj++;
                while (lj < j)
                    gen_opc_instr_start[lj++] = 0;
            }
2385 2386 2387
            gen_opc_pc[lj] = ctx.pc;
            gen_opc_instr_start[lj] = 1;
            gen_opc_icount[lj] = num_insns;
J
j_mayer 已提交
2388
        }
P
pbrook 已提交
2389 2390
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
            gen_io_start();
J
j_mayer 已提交
2391 2392
#if defined ALPHA_DEBUG_DISAS
        insn_count++;
2393 2394
        LOG_DISAS("pc " TARGET_FMT_lx " mem_idx %d\n",
                  ctx.pc, ctx.mem_idx);
J
j_mayer 已提交
2395 2396 2397 2398
#endif
        insn = ldl_code(ctx.pc);
#if defined ALPHA_DEBUG_DISAS
        insn_count++;
2399
        LOG_DISAS("opcode %08x %d\n", insn, insn_count);
J
j_mayer 已提交
2400
#endif
P
pbrook 已提交
2401
        num_insns++;
J
j_mayer 已提交
2402 2403 2404 2405 2406 2407 2408
        ctx.pc += 4;
        ret = translate_one(ctxp, insn);
        if (ret != 0)
            break;
        /* if we reach a page boundary or are single stepping, stop
         * generation
         */
A
aurel32 已提交
2409 2410 2411
        if (env->singlestep_enabled) {
            gen_excp(&ctx, EXCP_DEBUG, 0);
            break;
2412
        }
A
aurel32 已提交
2413

2414 2415 2416 2417 2418 2419 2420 2421 2422
        if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
            break;

        if (gen_opc_ptr >= gen_opc_end)
            break;

        if (num_insns >= max_insns)
            break;

2423 2424 2425
        if (singlestep) {
            break;
        }
J
j_mayer 已提交
2426 2427
    }
    if (ret != 1 && ret != 3) {
A
aurel32 已提交
2428
        tcg_gen_movi_i64(cpu_pc, ctx.pc);
J
j_mayer 已提交
2429 2430
    }
#if defined (DO_TB_FLUSH)
P
pbrook 已提交
2431
    gen_helper_tb_flush();
J
j_mayer 已提交
2432
#endif
P
pbrook 已提交
2433 2434
    if (tb->cflags & CF_LAST_IO)
        gen_io_end();
J
j_mayer 已提交
2435
    /* Generate the return instruction */
B
bellard 已提交
2436
    tcg_gen_exit_tb(0);
P
pbrook 已提交
2437
    gen_icount_end(tb, num_insns);
J
j_mayer 已提交
2438 2439 2440 2441 2442 2443 2444 2445
    *gen_opc_ptr = INDEX_op_end;
    if (search_pc) {
        j = gen_opc_ptr - gen_opc_buf;
        lj++;
        while (lj <= j)
            gen_opc_instr_start[lj++] = 0;
    } else {
        tb->size = ctx.pc - pc_start;
P
pbrook 已提交
2446
        tb->icount = num_insns;
J
j_mayer 已提交
2447 2448
    }
#if defined ALPHA_DEBUG_DISAS
2449
    log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
2450
    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
2451 2452 2453
        qemu_log("IN: %s\n", lookup_symbol(pc_start));
        log_target_disas(pc_start, ctx.pc - pc_start, 1);
        qemu_log("\n");
J
j_mayer 已提交
2454 2455 2456 2457
    }
#endif
}

2458
void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
J
j_mayer 已提交
2459
{
2460
    gen_intermediate_code_internal(env, tb, 0);
J
j_mayer 已提交
2461 2462
}

2463
void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
J
j_mayer 已提交
2464
{
2465
    gen_intermediate_code_internal(env, tb, 1);
J
j_mayer 已提交
2466 2467
}

B
bellard 已提交
2468
CPUAlphaState * cpu_alpha_init (const char *cpu_model)
J
j_mayer 已提交
2469 2470 2471 2472 2473 2474
{
    CPUAlphaState *env;
    uint64_t hwpcb;

    env = qemu_mallocz(sizeof(CPUAlphaState));
    cpu_exec_init(env);
P
pbrook 已提交
2475
    alpha_translate_init();
J
j_mayer 已提交
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
    tlb_flush(env, 1);
    /* XXX: should not be hardcoded */
    env->implver = IMPLVER_2106x;
    env->ps = 0x1F00;
#if defined (CONFIG_USER_ONLY)
    env->ps |= 1 << 3;
#endif
    pal_init(env);
    /* Initialize IPR */
    hwpcb = env->ipr[IPR_PCBB];
    env->ipr[IPR_ASN] = 0;
    env->ipr[IPR_ASTEN] = 0;
    env->ipr[IPR_ASTSR] = 0;
    env->ipr[IPR_DATFX] = 0;
    /* XXX: fix this */
    //    env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
    //    env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
    //    env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
    //    env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
    env->ipr[IPR_FEN] = 0;
    env->ipr[IPR_IPL] = 31;
    env->ipr[IPR_MCES] = 0;
    env->ipr[IPR_PERFMON] = 0; /* Implementation specific */
    //    env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
    env->ipr[IPR_SISR] = 0;
    env->ipr[IPR_VIRBND] = -1ULL;

2503
    qemu_init_vcpu(env);
J
j_mayer 已提交
2504 2505
    return env;
}
B
bellard 已提交
2506

A
aurel32 已提交
2507 2508 2509 2510 2511
void gen_pc_load(CPUState *env, TranslationBlock *tb,
                unsigned long searched_pc, int pc_pos, void *puc)
{
    env->pc = gen_opc_pc[pc_pos];
}