translate.c 103.0 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
#undef ALPHA_DEBUG_DISAS
36
#define CONFIG_SOFTFLOAT_INLINE
37 38

#ifdef ALPHA_DEBUG_DISAS
R
Richard Henderson 已提交
39
#  define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
40 41 42 43
#else
#  define LOG_DISAS(...) do { } while (0)
#endif

J
j_mayer 已提交
44 45
typedef struct DisasContext DisasContext;
struct DisasContext {
46 47
    struct TranslationBlock *tb;
    CPUAlphaState *env;
J
j_mayer 已提交
48 49
    uint64_t pc;
    int mem_idx;
50 51 52 53 54

    /* Current rounding mode for this TB.  */
    int tb_rm;
    /* Current flush-to-zero setting for this TB.  */
    int tb_ftz;
J
j_mayer 已提交
55 56
};

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/* Return values from translate_one, indicating the state of the TB.
   Note that zero indicates that we are not exiting the TB.  */

typedef enum {
    NO_EXIT,

    /* We have emitted one or more goto_tb.  No fixup required.  */
    EXIT_GOTO_TB,

    /* We are not using a goto_tb (for whatever reason), but have updated
       the PC (for whatever reason), so there's no need to do it again on
       exiting the TB.  */
    EXIT_PC_UPDATED,

    /* We are exiting the TB, but have neither emitted a goto_tb, nor
       updated the PC for the next instruction to be executed.  */
73 74 75 76 77
    EXIT_PC_STALE,

    /* We are ending the TB with a noreturn function call, e.g. longjmp.
       No following code will be executed.  */
    EXIT_NORETURN,
78 79
} ExitStatus;

A
aurel32 已提交
80
/* global register indexes */
P
pbrook 已提交
81
static TCGv_ptr cpu_env;
A
aurel32 已提交
82
static TCGv cpu_ir[31];
A
aurel32 已提交
83
static TCGv cpu_fir[31];
A
aurel32 已提交
84
static TCGv cpu_pc;
85 86 87
static TCGv cpu_lock_addr;
static TCGv cpu_lock_st_addr;
static TCGv cpu_lock_value;
88 89 90 91
static TCGv cpu_unique;
#ifndef CONFIG_USER_ONLY
static TCGv cpu_sysval;
static TCGv cpu_usp;
92
#endif
A
aurel32 已提交
93

A
aurel32 已提交
94
/* register names */
A
aurel32 已提交
95
static char cpu_reg_names[10*4+21*5 + 10*5+21*6];
P
pbrook 已提交
96 97 98

#include "gen-icount.h"

99
static void alpha_translate_init(void)
P
pbrook 已提交
100
{
A
aurel32 已提交
101 102
    int i;
    char *p;
P
pbrook 已提交
103
    static int done_init = 0;
A
aurel32 已提交
104

P
pbrook 已提交
105 106
    if (done_init)
        return;
A
aurel32 已提交
107

P
pbrook 已提交
108
    cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
A
aurel32 已提交
109 110 111 112

    p = cpu_reg_names;
    for (i = 0; i < 31; i++) {
        sprintf(p, "ir%d", i);
P
pbrook 已提交
113 114
        cpu_ir[i] = tcg_global_mem_new_i64(TCG_AREG0,
                                           offsetof(CPUState, ir[i]), p);
A
aurel32 已提交
115
        p += (i < 10) ? 4 : 5;
A
aurel32 已提交
116 117

        sprintf(p, "fir%d", i);
P
pbrook 已提交
118 119
        cpu_fir[i] = tcg_global_mem_new_i64(TCG_AREG0,
                                            offsetof(CPUState, fir[i]), p);
A
aurel32 已提交
120
        p += (i < 10) ? 5 : 6;
A
aurel32 已提交
121 122
    }

P
pbrook 已提交
123 124
    cpu_pc = tcg_global_mem_new_i64(TCG_AREG0,
                                    offsetof(CPUState, pc), "pc");
A
aurel32 已提交
125

126 127 128 129 130 131 132 133 134
    cpu_lock_addr = tcg_global_mem_new_i64(TCG_AREG0,
					   offsetof(CPUState, lock_addr),
					   "lock_addr");
    cpu_lock_st_addr = tcg_global_mem_new_i64(TCG_AREG0,
					      offsetof(CPUState, lock_st_addr),
					      "lock_st_addr");
    cpu_lock_value = tcg_global_mem_new_i64(TCG_AREG0,
					    offsetof(CPUState, lock_value),
					    "lock_value");
135

136 137 138 139 140 141 142
    cpu_unique = tcg_global_mem_new_i64(TCG_AREG0,
                                        offsetof(CPUState, unique), "unique");
#ifndef CONFIG_USER_ONLY
    cpu_sysval = tcg_global_mem_new_i64(TCG_AREG0,
                                        offsetof(CPUState, sysval), "sysval");
    cpu_usp = tcg_global_mem_new_i64(TCG_AREG0,
                                     offsetof(CPUState, usp), "usp");
143 144
#endif

A
aurel32 已提交
145
    /* register helpers */
P
pbrook 已提交
146
#define GEN_HELPER 2
A
aurel32 已提交
147 148
#include "helper.h"

P
pbrook 已提交
149 150 151
    done_init = 1;
}

152
static void gen_excp_1(int exception, int error_code)
J
j_mayer 已提交
153
{
P
pbrook 已提交
154
    TCGv_i32 tmp1, tmp2;
155 156 157

    tmp1 = tcg_const_i32(exception);
    tmp2 = tcg_const_i32(error_code);
P
pbrook 已提交
158 159 160
    gen_helper_excp(tmp1, tmp2);
    tcg_temp_free_i32(tmp2);
    tcg_temp_free_i32(tmp1);
161
}
162

163 164 165 166
static ExitStatus gen_excp(DisasContext *ctx, int exception, int error_code)
{
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
    gen_excp_1(exception, error_code);
167
    return EXIT_NORETURN;
J
j_mayer 已提交
168 169
}

170
static inline ExitStatus gen_invalid(DisasContext *ctx)
J
j_mayer 已提交
171
{
172
    return gen_excp(ctx, EXCP_OPCDEC, 0);
J
j_mayer 已提交
173 174
}

B
Blue Swirl 已提交
175
static inline void gen_qemu_ldf(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
176
{
P
pbrook 已提交
177 178
    TCGv tmp = tcg_temp_new();
    TCGv_i32 tmp32 = tcg_temp_new_i32();
A
aurel32 已提交
179
    tcg_gen_qemu_ld32u(tmp, t1, flags);
P
pbrook 已提交
180 181 182
    tcg_gen_trunc_i64_i32(tmp32, tmp);
    gen_helper_memory_to_f(t0, tmp32);
    tcg_temp_free_i32(tmp32);
A
aurel32 已提交
183 184 185
    tcg_temp_free(tmp);
}

B
Blue Swirl 已提交
186
static inline void gen_qemu_ldg(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
187
{
P
pbrook 已提交
188
    TCGv tmp = tcg_temp_new();
A
aurel32 已提交
189
    tcg_gen_qemu_ld64(tmp, t1, flags);
P
pbrook 已提交
190
    gen_helper_memory_to_g(t0, tmp);
A
aurel32 已提交
191 192 193
    tcg_temp_free(tmp);
}

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

B
Blue Swirl 已提交
205
static inline void gen_qemu_ldl_l(TCGv t0, TCGv t1, int flags)
206 207
{
    tcg_gen_qemu_ld32s(t0, t1, flags);
208 209
    tcg_gen_mov_i64(cpu_lock_addr, t1);
    tcg_gen_mov_i64(cpu_lock_value, t0);
210 211
}

B
Blue Swirl 已提交
212
static inline void gen_qemu_ldq_l(TCGv t0, TCGv t1, int flags)
213 214
{
    tcg_gen_qemu_ld64(t0, t1, flags);
215 216
    tcg_gen_mov_i64(cpu_lock_addr, t1);
    tcg_gen_mov_i64(cpu_lock_value, t0);
217 218
}

B
Blue Swirl 已提交
219 220 221 222 223
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)
224
{
225
    TCGv addr, va;
226

227 228 229 230
    /* LDQ_U with ra $31 is UNOP.  Other various loads are forms of
       prefetches, which we can treat as nops.  No worries about
       missed exceptions here.  */
    if (unlikely(ra == 31)) {
231
        return;
232
    }
233

P
pbrook 已提交
234
    addr = tcg_temp_new();
235 236
    if (rb != 31) {
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
237
        if (clear) {
238
            tcg_gen_andi_i64(addr, addr, ~0x7);
239
        }
240
    } else {
241
        if (clear) {
242
            disp16 &= ~0x7;
243
        }
244 245
        tcg_gen_movi_i64(addr, disp16);
    }
246 247 248 249

    va = (fp ? cpu_fir[ra] : cpu_ir[ra]);
    tcg_gen_qemu_load(va, addr, ctx->mem_idx);

250 251 252
    tcg_temp_free(addr);
}

B
Blue Swirl 已提交
253
static inline void gen_qemu_stf(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
254
{
P
pbrook 已提交
255 256 257 258
    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 已提交
259 260
    tcg_gen_qemu_st32(tmp, t1, flags);
    tcg_temp_free(tmp);
P
pbrook 已提交
261
    tcg_temp_free_i32(tmp32);
A
aurel32 已提交
262 263
}

B
Blue Swirl 已提交
264
static inline void gen_qemu_stg(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
265
{
P
pbrook 已提交
266 267
    TCGv tmp = tcg_temp_new();
    gen_helper_g_to_memory(tmp, t0);
A
aurel32 已提交
268 269 270 271
    tcg_gen_qemu_st64(tmp, t1, flags);
    tcg_temp_free(tmp);
}

B
Blue Swirl 已提交
272
static inline void gen_qemu_sts(TCGv t0, TCGv t1, int flags)
A
aurel32 已提交
273
{
P
pbrook 已提交
274 275 276 277
    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 已提交
278 279
    tcg_gen_qemu_st32(tmp, t1, flags);
    tcg_temp_free(tmp);
P
pbrook 已提交
280
    tcg_temp_free_i32(tmp32);
A
aurel32 已提交
281 282
}

B
Blue Swirl 已提交
283 284 285 286
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,
287
                                 int clear)
288
{
289 290 291
    TCGv addr, va;

    addr = tcg_temp_new();
292 293
    if (rb != 31) {
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
294
        if (clear) {
295
            tcg_gen_andi_i64(addr, addr, ~0x7);
296
        }
297
    } else {
298
        if (clear) {
299
            disp16 &= ~0x7;
300
        }
301 302
        tcg_gen_movi_i64(addr, disp16);
    }
303 304 305

    if (ra == 31) {
        va = tcg_const_i64(0);
A
aurel32 已提交
306
    } else {
307
        va = (fp ? cpu_fir[ra] : cpu_ir[ra]);
308
    }
309 310
    tcg_gen_qemu_store(va, addr, ctx->mem_idx);

311
    tcg_temp_free(addr);
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    if (ra == 31) {
        tcg_temp_free(va);
    }
}

static ExitStatus gen_store_conditional(DisasContext *ctx, int ra, int rb,
                                        int32_t disp16, int quad)
{
    TCGv addr;

    if (ra == 31) {
        /* ??? Don't bother storing anything.  The user can't tell
           the difference, since the zero register always reads zero.  */
        return NO_EXIT;
    }

#if defined(CONFIG_USER_ONLY)
    addr = cpu_lock_st_addr;
#else
331
    addr = tcg_temp_local_new();
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
#endif

    if (rb != 31) {
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
    } else {
        tcg_gen_movi_i64(addr, disp16);
    }

#if defined(CONFIG_USER_ONLY)
    /* ??? This is handled via a complicated version of compare-and-swap
       in the cpu_loop.  Hopefully one day we'll have a real CAS opcode
       in TCG so that this isn't necessary.  */
    return gen_excp(ctx, quad ? EXCP_STQ_C : EXCP_STL_C, ra);
#else
    /* ??? In system mode we are never multi-threaded, so CAS can be
       implemented via a non-atomic load-compare-store sequence.  */
    {
        int lab_fail, lab_done;
        TCGv val;

        lab_fail = gen_new_label();
        lab_done = gen_new_label();
354
        tcg_gen_brcond_i64(TCG_COND_NE, addr, cpu_lock_addr, lab_fail);
355 356 357 358 359 360 361

        val = tcg_temp_new();
        if (quad) {
            tcg_gen_qemu_ld64(val, addr, ctx->mem_idx);
        } else {
            tcg_gen_qemu_ld32s(val, addr, ctx->mem_idx);
        }
362
        tcg_gen_brcond_i64(TCG_COND_NE, val, cpu_lock_value, lab_fail);
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381

        if (quad) {
            tcg_gen_qemu_st64(cpu_ir[ra], addr, ctx->mem_idx);
        } else {
            tcg_gen_qemu_st32(cpu_ir[ra], addr, ctx->mem_idx);
        }
        tcg_gen_movi_i64(cpu_ir[ra], 1);
        tcg_gen_br(lab_done);

        gen_set_label(lab_fail);
        tcg_gen_movi_i64(cpu_ir[ra], 0);

        gen_set_label(lab_done);
        tcg_gen_movi_i64(cpu_lock_addr, -1);

        tcg_temp_free(addr);
        return NO_EXIT;
    }
#endif
382 383
}

384
static int use_goto_tb(DisasContext *ctx, uint64_t dest)
J
j_mayer 已提交
385
{
386 387 388 389 390 391
    /* Check for the dest on the same page as the start of the TB.  We
       also want to suppress goto_tb in the case of single-steping and IO.  */
    return (((ctx->tb->pc ^ dest) & TARGET_PAGE_MASK) == 0
            && !ctx->env->singlestep_enabled
            && !(ctx->tb->cflags & CF_LAST_IO));
}
392

393 394 395 396 397 398 399 400 401 402 403 404 405 406
static ExitStatus gen_bdirect(DisasContext *ctx, int ra, int32_t disp)
{
    uint64_t dest = ctx->pc + (disp << 2);

    if (ra != 31) {
        tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
    }

    /* Notice branch-to-next; used to initialize RA with the PC.  */
    if (disp == 0) {
        return 0;
    } else if (use_goto_tb(ctx, dest)) {
        tcg_gen_goto_tb(0);
        tcg_gen_movi_i64(cpu_pc, dest);
407
        tcg_gen_exit_tb((tcg_target_long)ctx->tb);
408 409 410 411 412
        return EXIT_GOTO_TB;
    } else {
        tcg_gen_movi_i64(cpu_pc, dest);
        return EXIT_PC_UPDATED;
    }
413 414
}

415 416
static ExitStatus gen_bcond_internal(DisasContext *ctx, TCGCond cond,
                                     TCGv cmp, int32_t disp)
417
{
418
    uint64_t dest = ctx->pc + (disp << 2);
419
    int lab_true = gen_new_label();
A
aurel32 已提交
420

421 422 423 424 425
    if (use_goto_tb(ctx, dest)) {
        tcg_gen_brcondi_i64(cond, cmp, 0, lab_true);

        tcg_gen_goto_tb(0);
        tcg_gen_movi_i64(cpu_pc, ctx->pc);
426
        tcg_gen_exit_tb((tcg_target_long)ctx->tb);
427 428 429 430

        gen_set_label(lab_true);
        tcg_gen_goto_tb(1);
        tcg_gen_movi_i64(cpu_pc, dest);
431
        tcg_gen_exit_tb((tcg_target_long)ctx->tb + 1);
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468

        return EXIT_GOTO_TB;
    } else {
        int lab_over = gen_new_label();

        /* ??? Consider using either
             movi pc, next
             addi tmp, pc, disp
             movcond pc, cond, 0, tmp, pc
           or
             setcond tmp, cond, 0
             movi pc, next
             neg tmp, tmp
             andi tmp, tmp, disp
             add pc, pc, tmp
           The current diamond subgraph surely isn't efficient.  */

        tcg_gen_brcondi_i64(cond, cmp, 0, lab_true);
        tcg_gen_movi_i64(cpu_pc, ctx->pc);
        tcg_gen_br(lab_over);
        gen_set_label(lab_true);
        tcg_gen_movi_i64(cpu_pc, dest);
        gen_set_label(lab_over);

        return EXIT_PC_UPDATED;
    }
}

static ExitStatus gen_bcond(DisasContext *ctx, TCGCond cond, int ra,
                            int32_t disp, int mask)
{
    TCGv cmp_tmp;

    if (unlikely(ra == 31)) {
        cmp_tmp = tcg_const_i64(0);
    } else {
        cmp_tmp = tcg_temp_new();
A
aurel32 已提交
469
        if (mask) {
470
            tcg_gen_andi_i64(cmp_tmp, cpu_ir[ra], 1);
471
        } else {
472
            tcg_gen_mov_i64(cmp_tmp, cpu_ir[ra]);
473
        }
A
aurel32 已提交
474
    }
475 476

    return gen_bcond_internal(ctx, cond, cmp_tmp, disp);
J
j_mayer 已提交
477 478
}

479
/* Fold -0.0 for comparison with COND.  */
480

481
static void gen_fold_mzero(TCGCond cond, TCGv dest, TCGv src)
J
j_mayer 已提交
482
{
483
    uint64_t mzero = 1ull << 63;
A
aurel32 已提交
484

485 486 487 488
    switch (cond) {
    case TCG_COND_LE:
    case TCG_COND_GT:
        /* For <= or >, the -0.0 value directly compares the way we want.  */
489
        tcg_gen_mov_i64(dest, src);
P
pbrook 已提交
490
        break;
491 492 493 494

    case TCG_COND_EQ:
    case TCG_COND_NE:
        /* For == or !=, we can simply mask off the sign bit and compare.  */
495
        tcg_gen_andi_i64(dest, src, mzero - 1);
P
pbrook 已提交
496
        break;
497 498 499

    case TCG_COND_GE:
    case TCG_COND_LT:
500 501 502 503
        /* For >= or <, map -0.0 to +0.0 via comparison and mask.  */
        tcg_gen_setcondi_i64(TCG_COND_NE, dest, src, mzero);
        tcg_gen_neg_i64(dest, dest);
        tcg_gen_and_i64(dest, dest, src);
P
pbrook 已提交
504
        break;
505

P
pbrook 已提交
506 507
    default:
        abort();
A
aurel32 已提交
508
    }
509 510
}

511 512
static ExitStatus gen_fbcond(DisasContext *ctx, TCGCond cond, int ra,
                             int32_t disp)
513
{
514
    TCGv cmp_tmp;
515 516 517 518

    if (unlikely(ra == 31)) {
        /* Very uncommon case, but easier to optimize it to an integer
           comparison than continuing with the floating point comparison.  */
519
        return gen_bcond(ctx, cond, ra, disp, 0);
520 521
    }

522 523 524
    cmp_tmp = tcg_temp_new();
    gen_fold_mzero(cond, cmp_tmp, cpu_fir[ra]);
    return gen_bcond_internal(ctx, cond, cmp_tmp, disp);
J
j_mayer 已提交
525 526
}

527
static void gen_cmov(TCGCond cond, int ra, int rb, int rc,
528
                     int islit, uint8_t lit, int mask)
J
j_mayer 已提交
529
{
530
    TCGCond inv_cond = tcg_invert_cond(cond);
A
aurel32 已提交
531 532 533 534 535 536 537 538 539
    int l1;

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

    l1 = gen_new_label();

    if (ra != 31) {
        if (mask) {
P
pbrook 已提交
540
            TCGv tmp = tcg_temp_new();
A
aurel32 已提交
541 542 543 544 545 546 547 548 549 550 551 552
            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 已提交
553
    if (islit)
A
aurel32 已提交
554
        tcg_gen_movi_i64(cpu_ir[rc], lit);
J
j_mayer 已提交
555
    else
556
        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
A
aurel32 已提交
557
    gen_set_label(l1);
J
j_mayer 已提交
558 559
}

560
static void gen_fcmov(TCGCond cond, int ra, int rb, int rc)
561
{
562
    TCGv cmp_tmp;
563 564
    int l1;

565
    if (unlikely(rc == 31)) {
566
        return;
567 568 569
    }

    cmp_tmp = tcg_temp_new();
570
    if (unlikely(ra == 31)) {
571 572 573
        tcg_gen_movi_i64(cmp_tmp, 0);
    } else {
        gen_fold_mzero(cond, cmp_tmp, cpu_fir[ra]);
574 575 576
    }

    l1 = gen_new_label();
577 578
    tcg_gen_brcondi_i64(tcg_invert_cond(cond), cmp_tmp, 0, l1);
    tcg_temp_free(cmp_tmp);
579 580 581 582 583 584 585 586

    if (rb != 31)
        tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[rb]);
    else
        tcg_gen_movi_i64(cpu_fir[rc], 0);
    gen_set_label(l1);
}

587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
#define QUAL_RM_N       0x080   /* Round mode nearest even */
#define QUAL_RM_C       0x000   /* Round mode chopped */
#define QUAL_RM_M       0x040   /* Round mode minus infinity */
#define QUAL_RM_D       0x0c0   /* Round mode dynamic */
#define QUAL_RM_MASK    0x0c0

#define QUAL_U          0x100   /* Underflow enable (fp output) */
#define QUAL_V          0x100   /* Overflow enable (int output) */
#define QUAL_S          0x400   /* Software completion enable */
#define QUAL_I          0x200   /* Inexact detection enable */

static void gen_qual_roundmode(DisasContext *ctx, int fn11)
{
    TCGv_i32 tmp;

    fn11 &= QUAL_RM_MASK;
    if (fn11 == ctx->tb_rm) {
        return;
    }
    ctx->tb_rm = fn11;

    tmp = tcg_temp_new_i32();
    switch (fn11) {
    case QUAL_RM_N:
        tcg_gen_movi_i32(tmp, float_round_nearest_even);
        break;
    case QUAL_RM_C:
        tcg_gen_movi_i32(tmp, float_round_to_zero);
        break;
    case QUAL_RM_M:
        tcg_gen_movi_i32(tmp, float_round_down);
        break;
    case QUAL_RM_D:
        tcg_gen_ld8u_i32(tmp, cpu_env, offsetof(CPUState, fpcr_dyn_round));
        break;
    }

#if defined(CONFIG_SOFTFLOAT_INLINE)
    /* ??? The "softfloat.h" interface is to call set_float_rounding_mode.
       With CONFIG_SOFTFLOAT that expands to an out-of-line call that just
       sets the one field.  */
    tcg_gen_st8_i32(tmp, cpu_env,
                    offsetof(CPUState, fp_status.float_rounding_mode));
#else
    gen_helper_setroundmode(tmp);
#endif

    tcg_temp_free_i32(tmp);
}

static void gen_qual_flushzero(DisasContext *ctx, int fn11)
{
    TCGv_i32 tmp;

    fn11 &= QUAL_U;
    if (fn11 == ctx->tb_ftz) {
        return;
    }
    ctx->tb_ftz = fn11;

    tmp = tcg_temp_new_i32();
    if (fn11) {
        /* Underflow is enabled, use the FPCR setting.  */
        tcg_gen_ld8u_i32(tmp, cpu_env, offsetof(CPUState, fpcr_flush_to_zero));
    } else {
        /* Underflow is disabled, force flush-to-zero.  */
        tcg_gen_movi_i32(tmp, 1);
    }

#if defined(CONFIG_SOFTFLOAT_INLINE)
    tcg_gen_st8_i32(tmp, cpu_env,
                    offsetof(CPUState, fp_status.flush_to_zero));
#else
    gen_helper_setflushzero(tmp);
#endif

    tcg_temp_free_i32(tmp);
}

static TCGv gen_ieee_input(int reg, int fn11, int is_cmp)
{
    TCGv val = tcg_temp_new();
    if (reg == 31) {
        tcg_gen_movi_i64(val, 0);
    } else if (fn11 & QUAL_S) {
        gen_helper_ieee_input_s(val, cpu_fir[reg]);
    } else if (is_cmp) {
        gen_helper_ieee_input_cmp(val, cpu_fir[reg]);
    } else {
        gen_helper_ieee_input(val, cpu_fir[reg]);
    }
    return val;
}

static void gen_fp_exc_clear(void)
{
#if defined(CONFIG_SOFTFLOAT_INLINE)
    TCGv_i32 zero = tcg_const_i32(0);
    tcg_gen_st8_i32(zero, cpu_env,
                    offsetof(CPUState, fp_status.float_exception_flags));
    tcg_temp_free_i32(zero);
#else
    gen_helper_fp_exc_clear();
#endif
}

static void gen_fp_exc_raise_ignore(int rc, int fn11, int ignore)
{
    /* ??? We ought to be able to do something with imprecise exceptions.
       E.g. notice we're still in the trap shadow of something within the
       TB and do not generate the code to signal the exception; end the TB
       when an exception is forced to arrive, either by consumption of a
       register value or TRAPB or EXCB.  */
    TCGv_i32 exc = tcg_temp_new_i32();
    TCGv_i32 reg;

#if defined(CONFIG_SOFTFLOAT_INLINE)
    tcg_gen_ld8u_i32(exc, cpu_env,
                     offsetof(CPUState, fp_status.float_exception_flags));
#else
    gen_helper_fp_exc_get(exc);
#endif

    if (ignore) {
        tcg_gen_andi_i32(exc, exc, ~ignore);
    }

    /* ??? Pass in the regno of the destination so that the helper can
       set EXC_MASK, which contains a bitmask of destination registers
       that have caused arithmetic traps.  A simple userspace emulation
       does not require this.  We do need it for a guest kernel's entArith,
       or if we were to do something clever with imprecise exceptions.  */
    reg = tcg_const_i32(rc + 32);

    if (fn11 & QUAL_S) {
        gen_helper_fp_exc_raise_s(exc, reg);
    } else {
        gen_helper_fp_exc_raise(exc, reg);
    }

    tcg_temp_free_i32(reg);
    tcg_temp_free_i32(exc);
}

static inline void gen_fp_exc_raise(int rc, int fn11)
{
    gen_fp_exc_raise_ignore(rc, fn11, fn11 & QUAL_I ? 0 : float_flag_inexact);
J
j_mayer 已提交
734
}
735

736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
static void gen_fcvtlq(int rb, int rc)
{
    if (unlikely(rc == 31)) {
        return;
    }
    if (unlikely(rb == 31)) {
        tcg_gen_movi_i64(cpu_fir[rc], 0);
    } else {
        TCGv tmp = tcg_temp_new();

        /* The arithmetic right shift here, plus the sign-extended mask below
           yields a sign-extended result without an explicit ext32s_i64.  */
        tcg_gen_sari_i64(tmp, cpu_fir[rb], 32);
        tcg_gen_shri_i64(cpu_fir[rc], cpu_fir[rb], 29);
        tcg_gen_andi_i64(tmp, tmp, (int32_t)0xc0000000);
        tcg_gen_andi_i64(cpu_fir[rc], cpu_fir[rc], 0x3fffffff);
        tcg_gen_or_i64(cpu_fir[rc], cpu_fir[rc], tmp);

        tcg_temp_free(tmp);
    }
}

758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
static void gen_fcvtql(int rb, int rc)
{
    if (unlikely(rc == 31)) {
        return;
    }
    if (unlikely(rb == 31)) {
        tcg_gen_movi_i64(cpu_fir[rc], 0);
    } else {
        TCGv tmp = tcg_temp_new();

        tcg_gen_andi_i64(tmp, cpu_fir[rb], 0xC0000000);
        tcg_gen_andi_i64(cpu_fir[rc], cpu_fir[rb], 0x3FFFFFFF);
        tcg_gen_shli_i64(tmp, tmp, 32);
        tcg_gen_shli_i64(cpu_fir[rc], cpu_fir[rc], 29);
        tcg_gen_or_i64(cpu_fir[rc], cpu_fir[rc], tmp);

        tcg_temp_free(tmp);
    }
}

static void gen_fcvtql_v(DisasContext *ctx, int rb, int rc)
{
    if (rb != 31) {
        int lab = gen_new_label();
        TCGv tmp = tcg_temp_new();

        tcg_gen_ext32s_i64(tmp, cpu_fir[rb]);
        tcg_gen_brcond_i64(TCG_COND_EQ, tmp, cpu_fir[rb], lab);
        gen_excp(ctx, EXCP_ARITH, EXC_M_IOV);

        gen_set_label(lab);
    }
    gen_fcvtql(rb, rc);
}

793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
#define FARITH2(name)                                   \
static inline void glue(gen_f, name)(int rb, int rc)    \
{                                                       \
    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);                             \
    }                                                   \
}

/* ??? VAX instruction qualifiers ignored.  */
P
pbrook 已提交
809 810 811 812 813 814
FARITH2(sqrtf)
FARITH2(sqrtg)
FARITH2(cvtgf)
FARITH2(cvtgq)
FARITH2(cvtqf)
FARITH2(cvtqg)
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886

static void gen_ieee_arith2(DisasContext *ctx, void (*helper)(TCGv, TCGv),
                            int rb, int rc, int fn11)
{
    TCGv vb;

    /* ??? This is wrong: the instruction is not a nop, it still may
       raise exceptions.  */
    if (unlikely(rc == 31)) {
        return;
    }

    gen_qual_roundmode(ctx, fn11);
    gen_qual_flushzero(ctx, fn11);
    gen_fp_exc_clear();

    vb = gen_ieee_input(rb, fn11, 0);
    helper(cpu_fir[rc], vb);
    tcg_temp_free(vb);

    gen_fp_exc_raise(rc, fn11);
}

#define IEEE_ARITH2(name)                                       \
static inline void glue(gen_f, name)(DisasContext *ctx,         \
                                     int rb, int rc, int fn11)  \
{                                                               \
    gen_ieee_arith2(ctx, gen_helper_##name, rb, rc, fn11);      \
}
IEEE_ARITH2(sqrts)
IEEE_ARITH2(sqrtt)
IEEE_ARITH2(cvtst)
IEEE_ARITH2(cvtts)

static void gen_fcvttq(DisasContext *ctx, int rb, int rc, int fn11)
{
    TCGv vb;
    int ignore = 0;

    /* ??? This is wrong: the instruction is not a nop, it still may
       raise exceptions.  */
    if (unlikely(rc == 31)) {
        return;
    }

    /* No need to set flushzero, since we have an integer output.  */
    gen_fp_exc_clear();
    vb = gen_ieee_input(rb, fn11, 0);

    /* Almost all integer conversions use cropped rounding, and most
       also do not have integer overflow enabled.  Special case that.  */
    switch (fn11) {
    case QUAL_RM_C:
        gen_helper_cvttq_c(cpu_fir[rc], vb);
        break;
    case QUAL_V | QUAL_RM_C:
    case QUAL_S | QUAL_V | QUAL_RM_C:
        ignore = float_flag_inexact;
        /* FALLTHRU */
    case QUAL_S | QUAL_V | QUAL_I | QUAL_RM_C:
        gen_helper_cvttq_svic(cpu_fir[rc], vb);
        break;
    default:
        gen_qual_roundmode(ctx, fn11);
        gen_helper_cvttq(cpu_fir[rc], vb);
        ignore |= (fn11 & QUAL_V ? 0 : float_flag_overflow);
        ignore |= (fn11 & QUAL_I ? 0 : float_flag_inexact);
        break;
    }
    tcg_temp_free(vb);

    gen_fp_exc_raise_ignore(rc, fn11, ignore);
J
j_mayer 已提交
887 888
}

889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
static void gen_ieee_intcvt(DisasContext *ctx, void (*helper)(TCGv, TCGv),
			    int rb, int rc, int fn11)
{
    TCGv vb;

    /* ??? This is wrong: the instruction is not a nop, it still may
       raise exceptions.  */
    if (unlikely(rc == 31)) {
        return;
    }

    gen_qual_roundmode(ctx, fn11);

    if (rb == 31) {
        vb = tcg_const_i64(0);
    } else {
        vb = cpu_fir[rb];
    }

    /* The only exception that can be raised by integer conversion
       is inexact.  Thus we only need to worry about exceptions when
       inexact handling is requested.  */
    if (fn11 & QUAL_I) {
        gen_fp_exc_clear();
        helper(cpu_fir[rc], vb);
        gen_fp_exc_raise(rc, fn11);
    } else {
        helper(cpu_fir[rc], vb);
    }

    if (rb == 31) {
        tcg_temp_free(vb);
    }
}

#define IEEE_INTCVT(name)                                       \
static inline void glue(gen_f, name)(DisasContext *ctx,         \
                                     int rb, int rc, int fn11)  \
{                                                               \
    gen_ieee_intcvt(ctx, gen_helper_##name, rb, rc, fn11);      \
}
IEEE_INTCVT(cvtqs)
IEEE_INTCVT(cvtqt)

933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
static void gen_cpys_internal(int ra, int rb, int rc, int inv_a, uint64_t mask)
{
    TCGv va, vb, vmask;
    int za = 0, zb = 0;

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

    vmask = tcg_const_i64(mask);

    TCGV_UNUSED_I64(va);
    if (ra == 31) {
        if (inv_a) {
            va = vmask;
        } else {
            za = 1;
        }
    } else {
        va = tcg_temp_new_i64();
        tcg_gen_mov_i64(va, cpu_fir[ra]);
        if (inv_a) {
            tcg_gen_andc_i64(va, vmask, va);
        } else {
            tcg_gen_and_i64(va, va, vmask);
        }
    }

    TCGV_UNUSED_I64(vb);
    if (rb == 31) {
        zb = 1;
    } else {
        vb = tcg_temp_new_i64();
        tcg_gen_andc_i64(vb, cpu_fir[rb], vmask);
    }

    switch (za << 1 | zb) {
    case 0 | 0:
        tcg_gen_or_i64(cpu_fir[rc], va, vb);
        break;
    case 0 | 1:
        tcg_gen_mov_i64(cpu_fir[rc], va);
        break;
    case 2 | 0:
        tcg_gen_mov_i64(cpu_fir[rc], vb);
        break;
    case 2 | 1:
        tcg_gen_movi_i64(cpu_fir[rc], 0);
        break;
    }

    tcg_temp_free(vmask);
    if (ra != 31) {
        tcg_temp_free(va);
    }
    if (rb != 31) {
        tcg_temp_free(vb);
    }
}

static inline void gen_fcpys(int ra, int rb, int rc)
{
    gen_cpys_internal(ra, rb, rc, 0, 0x8000000000000000ULL);
}

static inline void gen_fcpysn(int ra, int rb, int rc)
{
    gen_cpys_internal(ra, rb, rc, 1, 0x8000000000000000ULL);
}

static inline void gen_fcpyse(int ra, int rb, int rc)
{
    gen_cpys_internal(ra, rb, rc, 0, 0xFFF0000000000000ULL);
}

1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
#define FARITH3(name)                                           \
static inline void glue(gen_f, name)(int ra, int rb, int rc)    \
{                                                               \
    TCGv va, vb;                                                \
                                                                \
    if (unlikely(rc == 31)) {                                   \
        return;                                                 \
    }                                                           \
    if (ra == 31) {                                             \
        va = tcg_const_i64(0);                                  \
    } else {                                                    \
        va = cpu_fir[ra];                                       \
    }                                                           \
    if (rb == 31) {                                             \
        vb = tcg_const_i64(0);                                  \
    } else {                                                    \
        vb = cpu_fir[rb];                                       \
    }                                                           \
                                                                \
    gen_helper_ ## name (cpu_fir[rc], va, vb);                  \
                                                                \
    if (ra == 31) {                                             \
        tcg_temp_free(va);                                      \
    }                                                           \
    if (rb == 31) {                                             \
        tcg_temp_free(vb);                                      \
    }                                                           \
}

/* ??? VAX instruction qualifiers ignored.  */
P
pbrook 已提交
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
FARITH3(addf)
FARITH3(subf)
FARITH3(mulf)
FARITH3(divf)
FARITH3(addg)
FARITH3(subg)
FARITH3(mulg)
FARITH3(divg)
FARITH3(cmpgeq)
FARITH3(cmpglt)
FARITH3(cmpgle)
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122

static void gen_ieee_arith3(DisasContext *ctx,
                            void (*helper)(TCGv, TCGv, TCGv),
                            int ra, int rb, int rc, int fn11)
{
    TCGv va, vb;

    /* ??? This is wrong: the instruction is not a nop, it still may
       raise exceptions.  */
    if (unlikely(rc == 31)) {
        return;
    }

    gen_qual_roundmode(ctx, fn11);
    gen_qual_flushzero(ctx, fn11);
    gen_fp_exc_clear();

    va = gen_ieee_input(ra, fn11, 0);
    vb = gen_ieee_input(rb, fn11, 0);
    helper(cpu_fir[rc], va, vb);
    tcg_temp_free(va);
    tcg_temp_free(vb);

    gen_fp_exc_raise(rc, fn11);
}

#define IEEE_ARITH3(name)                                               \
static inline void glue(gen_f, name)(DisasContext *ctx,                 \
                                     int ra, int rb, int rc, int fn11)  \
{                                                                       \
    gen_ieee_arith3(ctx, gen_helper_##name, ra, rb, rc, fn11);          \
}
IEEE_ARITH3(adds)
IEEE_ARITH3(subs)
IEEE_ARITH3(muls)
IEEE_ARITH3(divs)
IEEE_ARITH3(addt)
IEEE_ARITH3(subt)
IEEE_ARITH3(mult)
IEEE_ARITH3(divt)

static void gen_ieee_compare(DisasContext *ctx,
                             void (*helper)(TCGv, TCGv, TCGv),
                             int ra, int rb, int rc, int fn11)
{
    TCGv va, vb;

    /* ??? This is wrong: the instruction is not a nop, it still may
       raise exceptions.  */
    if (unlikely(rc == 31)) {
        return;
    }

    gen_fp_exc_clear();

    va = gen_ieee_input(ra, fn11, 1);
    vb = gen_ieee_input(rb, fn11, 1);
    helper(cpu_fir[rc], va, vb);
    tcg_temp_free(va);
    tcg_temp_free(vb);

    gen_fp_exc_raise(rc, fn11);
}

#define IEEE_CMP3(name)                                                 \
static inline void glue(gen_f, name)(DisasContext *ctx,                 \
                                     int ra, int rb, int rc, int fn11)  \
{                                                                       \
    gen_ieee_compare(ctx, gen_helper_##name, ra, rb, rc, fn11);         \
}
IEEE_CMP3(cmptun)
IEEE_CMP3(cmpteq)
IEEE_CMP3(cmptlt)
IEEE_CMP3(cmptle)
P
pbrook 已提交
1123

1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
static inline uint64_t zapnot_mask(uint8_t lit)
{
    uint64_t mask = 0;
    int i;

    for (i = 0; i < 8; ++i) {
        if ((lit >> i) & 1)
            mask |= 0xffull << (i * 8);
    }
    return mask;
}

1136 1137 1138
/* Implement zapnot with an immediate operand, which expands to some
   form of immediate AND.  This is a basic building block in the
   definition of many of the other byte manipulation instructions.  */
1139
static void gen_zapnoti(TCGv dest, TCGv src, uint8_t lit)
1140 1141 1142
{
    switch (lit) {
    case 0x00:
1143
        tcg_gen_movi_i64(dest, 0);
1144 1145
        break;
    case 0x01:
1146
        tcg_gen_ext8u_i64(dest, src);
1147 1148
        break;
    case 0x03:
1149
        tcg_gen_ext16u_i64(dest, src);
1150 1151
        break;
    case 0x0f:
1152
        tcg_gen_ext32u_i64(dest, src);
1153 1154
        break;
    case 0xff:
1155
        tcg_gen_mov_i64(dest, src);
1156 1157
        break;
    default:
1158
        tcg_gen_andi_i64 (dest, src, zapnot_mask (lit));
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
        break;
    }
}

static inline void gen_zapnot(int ra, int rb, int rc, int islit, uint8_t lit)
{
    if (unlikely(rc == 31))
        return;
    else if (unlikely(ra == 31))
        tcg_gen_movi_i64(cpu_ir[rc], 0);
    else if (islit)
1170
        gen_zapnoti(cpu_ir[rc], cpu_ir[ra], lit);
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
    else
        gen_helper_zapnot (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
}

static inline void gen_zap(int ra, int rb, int rc, int islit, uint8_t lit)
{
    if (unlikely(rc == 31))
        return;
    else if (unlikely(ra == 31))
        tcg_gen_movi_i64(cpu_ir[rc], 0);
    else if (islit)
1182
        gen_zapnoti(cpu_ir[rc], cpu_ir[ra], ~lit);
1183 1184 1185 1186 1187
    else
        gen_helper_zap (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
}


1188
/* EXTWH, EXTLH, EXTQH */
1189 1190
static void gen_ext_h(int ra, int rb, int rc, int islit,
                      uint8_t lit, uint8_t byte_mask)
1191 1192 1193
{
    if (unlikely(rc == 31))
        return;
1194 1195 1196
    else if (unlikely(ra == 31))
        tcg_gen_movi_i64(cpu_ir[rc], 0);
    else {
1197
        if (islit) {
1198 1199
            lit = (64 - (lit & 7) * 8) & 0x3f;
            tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit);
A
aurel32 已提交
1200
        } else {
1201
            TCGv tmp1 = tcg_temp_new();
1202 1203
            tcg_gen_andi_i64(tmp1, cpu_ir[rb], 7);
            tcg_gen_shli_i64(tmp1, tmp1, 3);
1204 1205
            tcg_gen_neg_i64(tmp1, tmp1);
            tcg_gen_andi_i64(tmp1, tmp1, 0x3f);
1206
            tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], tmp1);
1207
            tcg_temp_free(tmp1);
1208
        }
1209
        gen_zapnoti(cpu_ir[rc], cpu_ir[rc], byte_mask);
1210
    }
1211 1212
}

1213
/* EXTBL, EXTWL, EXTLL, EXTQL */
1214 1215
static void gen_ext_l(int ra, int rb, int rc, int islit,
                      uint8_t lit, uint8_t byte_mask)
1216 1217 1218
{
    if (unlikely(rc == 31))
        return;
1219 1220 1221
    else if (unlikely(ra == 31))
        tcg_gen_movi_i64(cpu_ir[rc], 0);
    else {
1222
        if (islit) {
1223
            tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], (lit & 7) * 8);
1224
        } else {
P
pbrook 已提交
1225
            TCGv tmp = tcg_temp_new();
1226 1227
            tcg_gen_andi_i64(tmp, cpu_ir[rb], 7);
            tcg_gen_shli_i64(tmp, tmp, 3);
1228
            tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], tmp);
1229
            tcg_temp_free(tmp);
A
aurel32 已提交
1230
        }
1231 1232 1233 1234
        gen_zapnoti(cpu_ir[rc], cpu_ir[rc], byte_mask);
    }
}

1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
/* INSWH, INSLH, INSQH */
static void gen_ins_h(int ra, int rb, int rc, int islit,
                      uint8_t lit, uint8_t byte_mask)
{
    if (unlikely(rc == 31))
        return;
    else if (unlikely(ra == 31) || (islit && (lit & 7) == 0))
        tcg_gen_movi_i64(cpu_ir[rc], 0);
    else {
        TCGv tmp = tcg_temp_new();

        /* The instruction description has us left-shift the byte mask
           and extract bits <15:8> and apply that zap at the end.  This
           is equivalent to simply performing the zap first and shifting
           afterward.  */
        gen_zapnoti (tmp, cpu_ir[ra], byte_mask);

        if (islit) {
            /* Note that we have handled the lit==0 case above.  */
            tcg_gen_shri_i64 (cpu_ir[rc], tmp, 64 - (lit & 7) * 8);
        } else {
            TCGv shift = tcg_temp_new();

            /* If (B & 7) == 0, we need to shift by 64 and leave a zero.
               Do this portably by splitting the shift into two parts:
               shift_count-1 and 1.  Arrange for the -1 by using
               ones-complement instead of twos-complement in the negation:
               ~((B & 7) * 8) & 63.  */

            tcg_gen_andi_i64(shift, cpu_ir[rb], 7);
            tcg_gen_shli_i64(shift, shift, 3);
            tcg_gen_not_i64(shift, shift);
            tcg_gen_andi_i64(shift, shift, 0x3f);

            tcg_gen_shr_i64(cpu_ir[rc], tmp, shift);
            tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[rc], 1);
            tcg_temp_free(shift);
        }
        tcg_temp_free(tmp);
    }
}

1277
/* INSBL, INSWL, INSLL, INSQL */
1278 1279
static void gen_ins_l(int ra, int rb, int rc, int islit,
                      uint8_t lit, uint8_t byte_mask)
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
{
    if (unlikely(rc == 31))
        return;
    else if (unlikely(ra == 31))
        tcg_gen_movi_i64(cpu_ir[rc], 0);
    else {
        TCGv tmp = tcg_temp_new();

        /* The instruction description has us left-shift the byte mask
           the same number of byte slots as the data and apply the zap
           at the end.  This is equivalent to simply performing the zap
           first and shifting afterward.  */
        gen_zapnoti (tmp, cpu_ir[ra], byte_mask);

        if (islit) {
            tcg_gen_shli_i64(cpu_ir[rc], tmp, (lit & 7) * 8);
        } else {
            TCGv shift = tcg_temp_new();
            tcg_gen_andi_i64(shift, cpu_ir[rb], 7);
            tcg_gen_shli_i64(shift, shift, 3);
            tcg_gen_shl_i64(cpu_ir[rc], tmp, shift);
            tcg_temp_free(shift);
        }
        tcg_temp_free(tmp);
1304
    }
1305 1306
}

1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
/* MSKWH, MSKLH, MSKQH */
static void gen_msk_h(int ra, int rb, int rc, int islit,
                      uint8_t lit, uint8_t byte_mask)
{
    if (unlikely(rc == 31))
        return;
    else if (unlikely(ra == 31))
        tcg_gen_movi_i64(cpu_ir[rc], 0);
    else if (islit) {
        gen_zapnoti (cpu_ir[rc], cpu_ir[ra], ~((byte_mask << (lit & 7)) >> 8));
    } else {
        TCGv shift = tcg_temp_new();
        TCGv mask = tcg_temp_new();

        /* The instruction description is as above, where the byte_mask
           is shifted left, and then we extract bits <15:8>.  This can be
           emulated with a right-shift on the expanded byte mask.  This
           requires extra care because for an input <2:0> == 0 we need a
           shift of 64 bits in order to generate a zero.  This is done by
           splitting the shift into two parts, the variable shift - 1
           followed by a constant 1 shift.  The code we expand below is
           equivalent to ~((B & 7) * 8) & 63.  */

        tcg_gen_andi_i64(shift, cpu_ir[rb], 7);
        tcg_gen_shli_i64(shift, shift, 3);
        tcg_gen_not_i64(shift, shift);
        tcg_gen_andi_i64(shift, shift, 0x3f);
        tcg_gen_movi_i64(mask, zapnot_mask (byte_mask));
        tcg_gen_shr_i64(mask, mask, shift);
        tcg_gen_shri_i64(mask, mask, 1);

        tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], mask);

        tcg_temp_free(mask);
        tcg_temp_free(shift);
    }
}

1345
/* MSKBL, MSKWL, MSKLL, MSKQL */
1346 1347
static void gen_msk_l(int ra, int rb, int rc, int islit,
                      uint8_t lit, uint8_t byte_mask)
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
{
    if (unlikely(rc == 31))
        return;
    else if (unlikely(ra == 31))
        tcg_gen_movi_i64(cpu_ir[rc], 0);
    else if (islit) {
        gen_zapnoti (cpu_ir[rc], cpu_ir[ra], ~(byte_mask << (lit & 7)));
    } else {
        TCGv shift = tcg_temp_new();
        TCGv mask = tcg_temp_new();

        tcg_gen_andi_i64(shift, cpu_ir[rb], 7);
        tcg_gen_shli_i64(shift, shift, 3);
        tcg_gen_movi_i64(mask, zapnot_mask (byte_mask));
        tcg_gen_shl_i64(mask, mask, shift);

        tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], mask);

        tcg_temp_free(mask);
        tcg_temp_free(shift);
    }
}

1371
/* Code to call arith3 helpers */
P
pbrook 已提交
1372
#define ARITH3(name)                                                  \
B
Blue Swirl 已提交
1373 1374
static inline void glue(gen_, name)(int ra, int rb, int rc, int islit,\
                                    uint8_t lit)                      \
P
pbrook 已提交
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
{                                                                     \
    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);                                          \
    }                                                                 \
1396
}
P
pbrook 已提交
1397 1398 1399 1400 1401 1402 1403 1404
ARITH3(cmpbge)
ARITH3(addlv)
ARITH3(sublv)
ARITH3(addqv)
ARITH3(subqv)
ARITH3(umulh)
ARITH3(mullv)
ARITH3(mulqv)
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
ARITH3(minub8)
ARITH3(minsb8)
ARITH3(minuw4)
ARITH3(minsw4)
ARITH3(maxub8)
ARITH3(maxsb8)
ARITH3(maxuw4)
ARITH3(maxsw4)
ARITH3(perr)

#define MVIOP2(name)                                    \
static inline void glue(gen_, name)(int rb, int rc)     \
{                                                       \
    if (unlikely(rc == 31))                             \
        return;                                         \
    if (unlikely(rb == 31))                             \
        tcg_gen_movi_i64(cpu_ir[rc], 0);                \
    else                                                \
        gen_helper_ ## name (cpu_ir[rc], cpu_ir[rb]);   \
}
MVIOP2(pklb)
MVIOP2(pkwb)
MVIOP2(unpkbl)
MVIOP2(unpkbw)
1429

1430 1431
static void gen_cmp(TCGCond cond, int ra, int rb, int rc,
                    int islit, uint8_t lit)
1432
{
1433
    TCGv va, vb;
1434

1435
    if (unlikely(rc == 31)) {
1436
        return;
1437
    }
1438

1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
    if (ra == 31) {
        va = tcg_const_i64(0);
    } else {
        va = cpu_ir[ra];
    }
    if (islit) {
        vb = tcg_const_i64(lit);
    } else {
        vb = cpu_ir[rb];
    }
1449

1450
    tcg_gen_setcond_i64(cond, cpu_ir[rc], va, vb);
1451

1452 1453 1454 1455 1456 1457
    if (ra == 31) {
        tcg_temp_free(va);
    }
    if (islit) {
        tcg_temp_free(vb);
    }
1458 1459
}

1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
static void gen_rx(int ra, int set)
{
    TCGv_i32 tmp;

    if (ra != 31) {
        tcg_gen_ld8u_i64(cpu_ir[ra], cpu_env, offsetof(CPUState, intr_flag));
    }

    tmp = tcg_const_i32(set);
    tcg_gen_st8_i32(tmp, cpu_env, offsetof(CPUState, intr_flag));
    tcg_temp_free_i32(tmp);
}

1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
static ExitStatus gen_call_pal(DisasContext *ctx, int palcode)
{
    /* We're emulating OSF/1 PALcode.  Many of these are trivial access
       to internal cpu registers.  */

    /* Unprivileged PAL call */
    if (palcode >= 0x80 && palcode < 0xC0) {
        switch (palcode) {
        case 0x86:
            /* IMB */
            /* No-op inside QEMU.  */
            break;
        case 0x9E:
            /* RDUNIQUE */
            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_unique);
            break;
        case 0x9F:
            /* WRUNIQUE */
            tcg_gen_mov_i64(cpu_unique, cpu_ir[IR_A0]);
            break;
        default:
            return gen_excp(ctx, EXCP_CALL_PAL, palcode & 0xbf);
        }
        return NO_EXIT;
    }

#ifndef CONFIG_USER_ONLY
    /* Privileged PAL code */
    if (palcode < 0x40 && (ctx->tb->flags & TB_FLAGS_USER_MODE) == 0) {
        switch (palcode) {
        case 0x01:
            /* CFLUSH */
            /* No-op inside QEMU.  */
            break;
        case 0x02:
            /* DRAINA */
            /* No-op inside QEMU.  */
            break;
        case 0x2D:
            /* WRVPTPTR */
            tcg_gen_st_i64(cpu_ir[IR_A0], cpu_env, offsetof(CPUState, vptptr));
            break;
        case 0x31:
            /* WRVAL */
            tcg_gen_mov_i64(cpu_sysval, cpu_ir[IR_A0]);
            break;
        case 0x32:
            /* RDVAL */
            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_sysval);
            break;

        case 0x35: {
            /* SWPIPL */
            TCGv tmp;

            /* Note that we already know we're in kernel mode, so we know
               that PS only contains the 3 IPL bits.  */
            tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUState, ps));

            /* But make sure and store only the 3 IPL bits from the user.  */
            tmp = tcg_temp_new();
            tcg_gen_andi_i64(tmp, cpu_ir[IR_A0], PS_INT_MASK);
            tcg_gen_st8_i64(tmp, cpu_env, offsetof(CPUState, ps));
            tcg_temp_free(tmp);
            break;
        }

        case 0x36:
            /* RDPS */
            tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUState, ps));
            break;
        case 0x38:
            /* WRUSP */
            tcg_gen_mov_i64(cpu_usp, cpu_ir[IR_A0]);
            break;
        case 0x3A:
            /* RDUSP */
            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_usp);
            break;
        case 0x3C:
            /* WHAMI */
            tcg_gen_ld32s_i64(cpu_ir[IR_V0], cpu_env,
                              offsetof(CPUState, cpu_index));
            break;

        default:
            return gen_excp(ctx, EXCP_CALL_PAL, palcode & 0x3f);
        }
        return NO_EXIT;
    }
#endif

    return gen_invalid(ctx);
}

1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630
#ifndef CONFIG_USER_ONLY

#define PR_BYTE         0x100000
#define PR_LONG         0x200000

static int cpu_pr_data(int pr)
{
    switch (pr) {
    case  0: return offsetof(CPUAlphaState, ps) | PR_BYTE;
    case  1: return offsetof(CPUAlphaState, fen) | PR_BYTE;
    case  2: return offsetof(CPUAlphaState, pcc_ofs) | PR_LONG;
    case  3: return offsetof(CPUAlphaState, trap_arg0);
    case  4: return offsetof(CPUAlphaState, trap_arg1);
    case  5: return offsetof(CPUAlphaState, trap_arg2);
    case  6: return offsetof(CPUAlphaState, exc_addr);
    case  7: return offsetof(CPUAlphaState, palbr);
    case  8: return offsetof(CPUAlphaState, ptbr);
    case  9: return offsetof(CPUAlphaState, vptptr);
    case 10: return offsetof(CPUAlphaState, unique);
    case 11: return offsetof(CPUAlphaState, sysval);
    case 12: return offsetof(CPUAlphaState, usp);

    case 32 ... 39:
        return offsetof(CPUAlphaState, shadow[pr - 32]);
    case 40 ... 63:
        return offsetof(CPUAlphaState, scratch[pr - 40]);
    }
    return 0;
}

static void gen_mfpr(int ra, int regno)
{
    int data = cpu_pr_data(regno);

    /* In our emulated PALcode, these processor registers have no
       side effects from reading.  */
    if (ra == 31) {
        return;
    }

    /* The basic registers are data only, and unknown registers
       are read-zero, write-ignore.  */
    if (data == 0) {
        tcg_gen_movi_i64(cpu_ir[ra], 0);
    } else if (data & PR_BYTE) {
        tcg_gen_ld8u_i64(cpu_ir[ra], cpu_env, data & ~PR_BYTE);
    } else if (data & PR_LONG) {
        tcg_gen_ld32s_i64(cpu_ir[ra], cpu_env, data & ~PR_LONG);
    } else {
        tcg_gen_ld_i64(cpu_ir[ra], cpu_env, data);
    }
}

static void gen_mtpr(int rb, int regno)
{
    TCGv tmp;

    if (rb == 31) {
        tmp = tcg_const_i64(0);
    } else {
        tmp = cpu_ir[rb];
    }

1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
    /* These two register numbers perform a TLB cache flush.  Thankfully we
       can only do this inside PALmode, which means that the current basic
       block cannot be affected by the change in mappings.  */
    if (regno == 255) {
        /* TBIA */
        gen_helper_tbia();
    } else if (regno == 254) {
        /* TBIS */
        gen_helper_tbis(tmp);
    } else {
        /* The basic registers are data only, and unknown registers
           are read-zero, write-ignore.  */
        int data = cpu_pr_data(regno);
        if (data != 0) {
            if (data & PR_BYTE) {
                tcg_gen_st8_i64(tmp, cpu_env, data & ~PR_BYTE);
            } else if (data & PR_LONG) {
                tcg_gen_st32_i64(tmp, cpu_env, data & ~PR_LONG);
            } else {
                tcg_gen_st_i64(tmp, cpu_env, data);
            }
1652 1653 1654 1655 1656 1657 1658 1659 1660
        }
    }

    if (rb == 31) {
        tcg_temp_free(tmp);
    }
}
#endif /* !USER_ONLY*/

1661
static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)
J
j_mayer 已提交
1662 1663 1664
{
    uint32_t palcode;
    int32_t disp21, disp16, disp12;
1665 1666
    uint16_t fn11;
    uint8_t opc, ra, rb, rc, fpfn, fn7, fn2, islit, real_islit;
1667
    uint8_t lit;
1668
    ExitStatus ret;
J
j_mayer 已提交
1669 1670 1671 1672 1673 1674

    /* Decode all instruction fields */
    opc = insn >> 26;
    ra = (insn >> 21) & 0x1F;
    rb = (insn >> 16) & 0x1F;
    rc = insn & 0x1F;
1675
    real_islit = islit = (insn >> 12) & 1;
1676 1677 1678 1679 1680
    if (rb == 31 && !islit) {
        islit = 1;
        lit = 0;
    } else
        lit = (insn >> 13) & 0xFF;
J
j_mayer 已提交
1681 1682 1683 1684 1685 1686 1687 1688
    palcode = insn & 0x03FFFFFF;
    disp21 = ((int32_t)((insn & 0x001FFFFF) << 11)) >> 11;
    disp16 = (int16_t)(insn & 0x0000FFFF);
    disp12 = (int32_t)((insn & 0x00000FFF) << 20) >> 20;
    fn11 = (insn >> 5) & 0x000007FF;
    fpfn = fn11 & 0x3F;
    fn7 = (insn >> 5) & 0x0000007F;
    fn2 = (insn >> 5) & 0x00000003;
R
Richard Henderson 已提交
1689
    LOG_DISAS("opc %02x ra %2d rb %2d rc %2d disp16 %6d\n",
1690
              opc, ra, rb, rc, disp16);
R
Richard Henderson 已提交
1691

1692
    ret = NO_EXIT;
J
j_mayer 已提交
1693 1694 1695
    switch (opc) {
    case 0x00:
        /* CALL_PAL */
1696 1697
        ret = gen_call_pal(ctx, palcode);
        break;
J
j_mayer 已提交
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
    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 已提交
1721
        if (likely(ra != 31)) {
A
aurel32 已提交
1722
            if (rb != 31)
A
aurel32 已提交
1723 1724 1725
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16);
            else
                tcg_gen_movi_i64(cpu_ir[ra], disp16);
A
aurel32 已提交
1726
        }
J
j_mayer 已提交
1727 1728 1729
        break;
    case 0x09:
        /* LDAH */
A
aurel32 已提交
1730
        if (likely(ra != 31)) {
A
aurel32 已提交
1731
            if (rb != 31)
A
aurel32 已提交
1732 1733 1734
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16 << 16);
            else
                tcg_gen_movi_i64(cpu_ir[ra], disp16 << 16);
A
aurel32 已提交
1735
        }
J
j_mayer 已提交
1736 1737 1738
        break;
    case 0x0A:
        /* LDBU */
1739 1740 1741 1742 1743
        if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
            gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
            break;
        }
        goto invalid_opc;
J
j_mayer 已提交
1744 1745
    case 0x0B:
        /* LDQ_U */
A
aurel32 已提交
1746
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
1747 1748 1749
        break;
    case 0x0C:
        /* LDWU */
1750 1751 1752 1753 1754
        if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
            gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 0);
            break;
        }
        goto invalid_opc;
J
j_mayer 已提交
1755 1756
    case 0x0D:
        /* STW */
1757
        gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
1758 1759 1760
        break;
    case 0x0E:
        /* STB */
1761
        gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
1762 1763 1764
        break;
    case 0x0F:
        /* STQ_U */
1765
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
1766 1767 1768 1769 1770
        break;
    case 0x10:
        switch (fn7) {
        case 0x00:
            /* ADDL */
1771 1772 1773 1774 1775
            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]);
1776
                    } else {
1777 1778
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1779
                    }
1780 1781
                } else {
                    if (islit)
1782
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
1783
                    else
1784
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
1785 1786
                }
            }
J
j_mayer 已提交
1787 1788 1789
            break;
        case 0x02:
            /* S4ADDL */
1790 1791
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1792
                    TCGv tmp = tcg_temp_new();
1793 1794 1795 1796 1797 1798 1799
                    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);
1800 1801 1802 1803
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1804
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
1805 1806
                }
            }
J
j_mayer 已提交
1807 1808 1809
            break;
        case 0x09:
            /* SUBL */
1810 1811
            if (likely(rc != 31)) {
                if (ra != 31) {
1812
                    if (islit)
1813
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
1814
                    else
1815
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1816
                    tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1817 1818 1819
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
1820
                    else {
1821 1822 1823 1824
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
                }
            }
J
j_mayer 已提交
1825 1826 1827
            break;
        case 0x0B:
            /* S4SUBL */
1828 1829
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1830
                    TCGv tmp = tcg_temp_new();
1831 1832 1833 1834 1835 1836 1837
                    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);
1838 1839 1840
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
1841
                    else {
1842 1843
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1844
                    }
1845 1846
                }
            }
J
j_mayer 已提交
1847 1848 1849
            break;
        case 0x0F:
            /* CMPBGE */
P
pbrook 已提交
1850
            gen_cmpbge(ra, rb, rc, islit, lit);
J
j_mayer 已提交
1851 1852 1853
            break;
        case 0x12:
            /* S8ADDL */
1854 1855
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1856
                    TCGv tmp = tcg_temp_new();
1857 1858 1859 1860 1861 1862 1863
                    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);
1864 1865 1866 1867
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1868
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
1869 1870
                }
            }
J
j_mayer 已提交
1871 1872 1873
            break;
        case 0x1B:
            /* S8SUBL */
1874 1875
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1876
                    TCGv tmp = tcg_temp_new();
1877 1878 1879 1880 1881 1882 1883
                    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);
1884 1885 1886
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
1887
                    else
1888 1889
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1890
                    }
1891 1892
                }
            }
J
j_mayer 已提交
1893 1894 1895
            break;
        case 0x1D:
            /* CMPULT */
1896
            gen_cmp(TCG_COND_LTU, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1897 1898 1899
            break;
        case 0x20:
            /* ADDQ */
1900 1901 1902 1903 1904
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
1905
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1906 1907 1908 1909
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1910
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1911 1912
                }
            }
J
j_mayer 已提交
1913 1914 1915
            break;
        case 0x22:
            /* S4ADDQ */
1916 1917
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1918
                    TCGv tmp = tcg_temp_new();
1919 1920 1921 1922 1923 1924
                    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);
1925 1926 1927 1928
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1929
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1930 1931
                }
            }
J
j_mayer 已提交
1932 1933 1934
            break;
        case 0x29:
            /* SUBQ */
1935 1936 1937 1938 1939
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
1940
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1941 1942 1943 1944
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
1945
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1946 1947
                }
            }
J
j_mayer 已提交
1948 1949 1950
            break;
        case 0x2B:
            /* S4SUBQ */
1951 1952
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1953
                    TCGv tmp = tcg_temp_new();
1954 1955 1956 1957 1958 1959
                    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);
1960 1961 1962 1963
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
1964
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1965 1966
                }
            }
J
j_mayer 已提交
1967 1968 1969
            break;
        case 0x2D:
            /* CMPEQ */
1970
            gen_cmp(TCG_COND_EQ, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1971 1972 1973
            break;
        case 0x32:
            /* S8ADDQ */
1974 1975
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1976
                    TCGv tmp = tcg_temp_new();
1977 1978 1979 1980 1981 1982
                    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);
1983 1984 1985 1986
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1987
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1988 1989
                }
            }
J
j_mayer 已提交
1990 1991 1992
            break;
        case 0x3B:
            /* S8SUBQ */
1993 1994
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
1995
                    TCGv tmp = tcg_temp_new();
1996 1997 1998 1999 2000 2001
                    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);
2002 2003 2004 2005
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
2006
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
2007 2008
                }
            }
J
j_mayer 已提交
2009 2010 2011
            break;
        case 0x3D:
            /* CMPULE */
2012
            gen_cmp(TCG_COND_LEU, ra, rb, rc, islit, lit);
J
j_mayer 已提交
2013 2014 2015
            break;
        case 0x40:
            /* ADDL/V */
P
pbrook 已提交
2016
            gen_addlv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2017 2018 2019
            break;
        case 0x49:
            /* SUBL/V */
P
pbrook 已提交
2020
            gen_sublv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2021 2022 2023
            break;
        case 0x4D:
            /* CMPLT */
2024
            gen_cmp(TCG_COND_LT, ra, rb, rc, islit, lit);
J
j_mayer 已提交
2025 2026 2027
            break;
        case 0x60:
            /* ADDQ/V */
P
pbrook 已提交
2028
            gen_addqv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2029 2030 2031
            break;
        case 0x69:
            /* SUBQ/V */
P
pbrook 已提交
2032
            gen_subqv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2033 2034 2035
            break;
        case 0x6D:
            /* CMPLE */
2036
            gen_cmp(TCG_COND_LE, ra, rb, rc, islit, lit);
J
j_mayer 已提交
2037 2038 2039 2040 2041 2042 2043 2044 2045
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x11:
        switch (fn7) {
        case 0x00:
            /* AND */
2046
            if (likely(rc != 31)) {
2047
                if (ra == 31)
2048 2049 2050 2051 2052 2053
                    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 已提交
2054 2055 2056
            break;
        case 0x08:
            /* BIC */
2057 2058 2059 2060
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
2061 2062
                    else
                        tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2063 2064 2065
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
2066 2067 2068
            break;
        case 0x14:
            /* CMOVLBS */
2069
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 1);
J
j_mayer 已提交
2070 2071 2072
            break;
        case 0x16:
            /* CMOVLBC */
2073
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 1);
J
j_mayer 已提交
2074 2075 2076
            break;
        case 0x20:
            /* BIS */
2077 2078 2079 2080
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], lit);
2081
                    else
2082
                        tcg_gen_or_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
J
j_mayer 已提交
2083
                } else {
2084 2085 2086
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
2087
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
J
j_mayer 已提交
2088 2089 2090 2091 2092
                }
            }
            break;
        case 0x24:
            /* CMOVEQ */
2093
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
2094 2095 2096
            break;
        case 0x26:
            /* CMOVNE */
2097
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
2098 2099 2100
            break;
        case 0x28:
            /* ORNOT */
2101
            if (likely(rc != 31)) {
2102
                if (ra != 31) {
2103 2104
                    if (islit)
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
2105 2106
                    else
                        tcg_gen_orc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2107 2108 2109 2110 2111 2112 2113
                } 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 已提交
2114 2115 2116
            break;
        case 0x40:
            /* XOR */
2117 2118 2119 2120 2121
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
2122
                        tcg_gen_xor_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2123 2124 2125 2126
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
2127
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
2128 2129
                }
            }
J
j_mayer 已提交
2130 2131 2132
            break;
        case 0x44:
            /* CMOVLT */
2133
            gen_cmov(TCG_COND_LT, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
2134 2135 2136
            break;
        case 0x46:
            /* CMOVGE */
2137
            gen_cmov(TCG_COND_GE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
2138 2139 2140
            break;
        case 0x48:
            /* EQV */
2141 2142 2143 2144
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
2145 2146
                    else
                        tcg_gen_eqv_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2147 2148 2149 2150
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], ~lit);
                    else
2151
                        tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
2152 2153
                }
            }
J
j_mayer 已提交
2154 2155 2156
            break;
        case 0x61:
            /* AMASK */
2157
            if (likely(rc != 31)) {
2158 2159 2160 2161 2162 2163
                uint64_t amask = ctx->tb->flags >> TB_FLAGS_AMASK_SHIFT;

                if (islit) {
                    tcg_gen_movi_i64(cpu_ir[rc], lit & ~amask);
                } else {
                    tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[rb], ~amask);
A
aurel32 已提交
2164
                }
2165
            }
J
j_mayer 已提交
2166 2167 2168
            break;
        case 0x64:
            /* CMOVLE */
2169
            gen_cmov(TCG_COND_LE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
2170 2171 2172
            break;
        case 0x66:
            /* CMOVGT */
2173
            gen_cmov(TCG_COND_GT, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
2174 2175 2176
            break;
        case 0x6C:
            /* IMPLVER */
A
aurel32 已提交
2177
            if (rc != 31)
2178
                tcg_gen_movi_i64(cpu_ir[rc], ctx->env->implver);
J
j_mayer 已提交
2179 2180 2181 2182 2183 2184 2185 2186 2187
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x12:
        switch (fn7) {
        case 0x02:
            /* MSKBL */
2188
            gen_msk_l(ra, rb, rc, islit, lit, 0x01);
J
j_mayer 已提交
2189 2190 2191
            break;
        case 0x06:
            /* EXTBL */
2192
            gen_ext_l(ra, rb, rc, islit, lit, 0x01);
J
j_mayer 已提交
2193 2194 2195
            break;
        case 0x0B:
            /* INSBL */
2196
            gen_ins_l(ra, rb, rc, islit, lit, 0x01);
J
j_mayer 已提交
2197 2198 2199
            break;
        case 0x12:
            /* MSKWL */
2200
            gen_msk_l(ra, rb, rc, islit, lit, 0x03);
J
j_mayer 已提交
2201 2202 2203
            break;
        case 0x16:
            /* EXTWL */
2204
            gen_ext_l(ra, rb, rc, islit, lit, 0x03);
J
j_mayer 已提交
2205 2206 2207
            break;
        case 0x1B:
            /* INSWL */
2208
            gen_ins_l(ra, rb, rc, islit, lit, 0x03);
J
j_mayer 已提交
2209 2210 2211
            break;
        case 0x22:
            /* MSKLL */
2212
            gen_msk_l(ra, rb, rc, islit, lit, 0x0f);
J
j_mayer 已提交
2213 2214 2215
            break;
        case 0x26:
            /* EXTLL */
2216
            gen_ext_l(ra, rb, rc, islit, lit, 0x0f);
J
j_mayer 已提交
2217 2218 2219
            break;
        case 0x2B:
            /* INSLL */
2220
            gen_ins_l(ra, rb, rc, islit, lit, 0x0f);
J
j_mayer 已提交
2221 2222 2223
            break;
        case 0x30:
            /* ZAP */
P
pbrook 已提交
2224
            gen_zap(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2225 2226 2227
            break;
        case 0x31:
            /* ZAPNOT */
P
pbrook 已提交
2228
            gen_zapnot(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2229 2230 2231
            break;
        case 0x32:
            /* MSKQL */
2232
            gen_msk_l(ra, rb, rc, islit, lit, 0xff);
J
j_mayer 已提交
2233 2234 2235
            break;
        case 0x34:
            /* SRL */
2236 2237 2238 2239
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
2240
                    else {
P
pbrook 已提交
2241
                        TCGv shift = tcg_temp_new();
2242 2243 2244
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
2245
                    }
2246 2247 2248
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
2249 2250 2251
            break;
        case 0x36:
            /* EXTQL */
2252
            gen_ext_l(ra, rb, rc, islit, lit, 0xff);
J
j_mayer 已提交
2253 2254 2255
            break;
        case 0x39:
            /* SLL */
2256 2257 2258 2259
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
2260
                    else {
P
pbrook 已提交
2261
                        TCGv shift = tcg_temp_new();
2262 2263 2264
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
2265
                    }
2266 2267 2268
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
2269 2270 2271
            break;
        case 0x3B:
            /* INSQL */
2272
            gen_ins_l(ra, rb, rc, islit, lit, 0xff);
J
j_mayer 已提交
2273 2274 2275
            break;
        case 0x3C:
            /* SRA */
2276 2277 2278 2279
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_sari_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
2280
                    else {
P
pbrook 已提交
2281
                        TCGv shift = tcg_temp_new();
2282 2283 2284
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_sar_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
2285
                    }
2286 2287 2288
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
2289 2290 2291
            break;
        case 0x52:
            /* MSKWH */
2292
            gen_msk_h(ra, rb, rc, islit, lit, 0x03);
J
j_mayer 已提交
2293 2294 2295
            break;
        case 0x57:
            /* INSWH */
2296
            gen_ins_h(ra, rb, rc, islit, lit, 0x03);
J
j_mayer 已提交
2297 2298 2299
            break;
        case 0x5A:
            /* EXTWH */
2300
            gen_ext_h(ra, rb, rc, islit, lit, 0x03);
J
j_mayer 已提交
2301 2302 2303
            break;
        case 0x62:
            /* MSKLH */
2304
            gen_msk_h(ra, rb, rc, islit, lit, 0x0f);
J
j_mayer 已提交
2305 2306 2307
            break;
        case 0x67:
            /* INSLH */
2308
            gen_ins_h(ra, rb, rc, islit, lit, 0x0f);
J
j_mayer 已提交
2309 2310 2311
            break;
        case 0x6A:
            /* EXTLH */
2312
            gen_ext_h(ra, rb, rc, islit, lit, 0x0f);
J
j_mayer 已提交
2313 2314 2315
            break;
        case 0x72:
            /* MSKQH */
2316
            gen_msk_h(ra, rb, rc, islit, lit, 0xff);
J
j_mayer 已提交
2317 2318 2319
            break;
        case 0x77:
            /* INSQH */
2320
            gen_ins_h(ra, rb, rc, islit, lit, 0xff);
J
j_mayer 已提交
2321 2322 2323
            break;
        case 0x7A:
            /* EXTQH */
2324
            gen_ext_h(ra, rb, rc, islit, lit, 0xff);
J
j_mayer 已提交
2325 2326 2327 2328 2329 2330 2331 2332 2333
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x13:
        switch (fn7) {
        case 0x00:
            /* MULL */
2334
            if (likely(rc != 31)) {
2335
                if (ra == 31)
2336 2337 2338 2339 2340 2341 2342 2343 2344
                    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 已提交
2345 2346 2347
            break;
        case 0x20:
            /* MULQ */
2348
            if (likely(rc != 31)) {
2349
                if (ra == 31)
2350 2351 2352 2353 2354 2355
                    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 已提交
2356 2357 2358
            break;
        case 0x30:
            /* UMULH */
P
pbrook 已提交
2359
            gen_umulh(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2360 2361 2362
            break;
        case 0x40:
            /* MULL/V */
P
pbrook 已提交
2363
            gen_mullv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2364 2365 2366
            break;
        case 0x60:
            /* MULQ/V */
P
pbrook 已提交
2367
            gen_mulqv(ra, rb, rc, islit, lit);
J
j_mayer 已提交
2368 2369 2370 2371 2372 2373
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x14:
2374
        switch (fpfn) { /* fn11 & 0x3F */
J
j_mayer 已提交
2375 2376
        case 0x04:
            /* ITOFS */
2377
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
J
j_mayer 已提交
2378
                goto invalid_opc;
2379
            }
A
aurel32 已提交
2380 2381
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
2382
                    TCGv_i32 tmp = tcg_temp_new_i32();
A
aurel32 已提交
2383
                    tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
P
pbrook 已提交
2384 2385
                    gen_helper_memory_to_s(cpu_fir[rc], tmp);
                    tcg_temp_free_i32(tmp);
A
aurel32 已提交
2386 2387 2388
                } else
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
            }
J
j_mayer 已提交
2389 2390 2391
            break;
        case 0x0A:
            /* SQRTF */
2392 2393 2394 2395 2396
            if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
                gen_fsqrtf(rb, rc);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2397 2398
        case 0x0B:
            /* SQRTS */
2399 2400 2401 2402 2403
            if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
                gen_fsqrts(ctx, rb, rc, fn11);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2404 2405
        case 0x14:
            /* ITOFF */
2406
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
J
j_mayer 已提交
2407
                goto invalid_opc;
2408
            }
A
aurel32 已提交
2409 2410
            if (likely(rc != 31)) {
                if (ra != 31) {
P
pbrook 已提交
2411
                    TCGv_i32 tmp = tcg_temp_new_i32();
A
aurel32 已提交
2412
                    tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
P
pbrook 已提交
2413 2414
                    gen_helper_memory_to_f(cpu_fir[rc], tmp);
                    tcg_temp_free_i32(tmp);
A
aurel32 已提交
2415 2416 2417
                } else
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
            }
J
j_mayer 已提交
2418 2419 2420
            break;
        case 0x24:
            /* ITOFT */
2421
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
J
j_mayer 已提交
2422
                goto invalid_opc;
2423
            }
A
aurel32 已提交
2424 2425 2426 2427 2428 2429
            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 已提交
2430 2431 2432
            break;
        case 0x2A:
            /* SQRTG */
2433 2434 2435 2436 2437
            if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
                gen_fsqrtg(rb, rc);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2438 2439
        case 0x02B:
            /* SQRTT */
2440 2441 2442 2443 2444
            if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
                gen_fsqrtt(ctx, rb, rc, fn11);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2445 2446 2447 2448 2449 2450 2451
        default:
            goto invalid_opc;
        }
        break;
    case 0x15:
        /* VAX floating point */
        /* XXX: rounding mode and trap are ignored (!) */
2452
        switch (fpfn) { /* fn11 & 0x3F */
J
j_mayer 已提交
2453 2454
        case 0x00:
            /* ADDF */
P
pbrook 已提交
2455
            gen_faddf(ra, rb, rc);
J
j_mayer 已提交
2456 2457 2458
            break;
        case 0x01:
            /* SUBF */
P
pbrook 已提交
2459
            gen_fsubf(ra, rb, rc);
J
j_mayer 已提交
2460 2461 2462
            break;
        case 0x02:
            /* MULF */
P
pbrook 已提交
2463
            gen_fmulf(ra, rb, rc);
J
j_mayer 已提交
2464 2465 2466
            break;
        case 0x03:
            /* DIVF */
P
pbrook 已提交
2467
            gen_fdivf(ra, rb, rc);
J
j_mayer 已提交
2468 2469 2470 2471
            break;
        case 0x1E:
            /* CVTDG */
#if 0 // TODO
P
pbrook 已提交
2472
            gen_fcvtdg(rb, rc);
J
j_mayer 已提交
2473 2474 2475 2476 2477 2478
#else
            goto invalid_opc;
#endif
            break;
        case 0x20:
            /* ADDG */
P
pbrook 已提交
2479
            gen_faddg(ra, rb, rc);
J
j_mayer 已提交
2480 2481 2482
            break;
        case 0x21:
            /* SUBG */
P
pbrook 已提交
2483
            gen_fsubg(ra, rb, rc);
J
j_mayer 已提交
2484 2485 2486
            break;
        case 0x22:
            /* MULG */
P
pbrook 已提交
2487
            gen_fmulg(ra, rb, rc);
J
j_mayer 已提交
2488 2489 2490
            break;
        case 0x23:
            /* DIVG */
P
pbrook 已提交
2491
            gen_fdivg(ra, rb, rc);
J
j_mayer 已提交
2492 2493 2494
            break;
        case 0x25:
            /* CMPGEQ */
P
pbrook 已提交
2495
            gen_fcmpgeq(ra, rb, rc);
J
j_mayer 已提交
2496 2497 2498
            break;
        case 0x26:
            /* CMPGLT */
P
pbrook 已提交
2499
            gen_fcmpglt(ra, rb, rc);
J
j_mayer 已提交
2500 2501 2502
            break;
        case 0x27:
            /* CMPGLE */
P
pbrook 已提交
2503
            gen_fcmpgle(ra, rb, rc);
J
j_mayer 已提交
2504 2505 2506
            break;
        case 0x2C:
            /* CVTGF */
P
pbrook 已提交
2507
            gen_fcvtgf(rb, rc);
J
j_mayer 已提交
2508 2509 2510 2511
            break;
        case 0x2D:
            /* CVTGD */
#if 0 // TODO
P
pbrook 已提交
2512
            gen_fcvtgd(rb, rc);
J
j_mayer 已提交
2513 2514 2515 2516 2517 2518
#else
            goto invalid_opc;
#endif
            break;
        case 0x2F:
            /* CVTGQ */
P
pbrook 已提交
2519
            gen_fcvtgq(rb, rc);
J
j_mayer 已提交
2520 2521 2522
            break;
        case 0x3C:
            /* CVTQF */
P
pbrook 已提交
2523
            gen_fcvtqf(rb, rc);
J
j_mayer 已提交
2524 2525 2526
            break;
        case 0x3E:
            /* CVTQG */
P
pbrook 已提交
2527
            gen_fcvtqg(rb, rc);
J
j_mayer 已提交
2528 2529 2530 2531 2532 2533 2534
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x16:
        /* IEEE floating-point */
2535
        switch (fpfn) { /* fn11 & 0x3F */
J
j_mayer 已提交
2536 2537
        case 0x00:
            /* ADDS */
2538
            gen_fadds(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2539 2540 2541
            break;
        case 0x01:
            /* SUBS */
2542
            gen_fsubs(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2543 2544 2545
            break;
        case 0x02:
            /* MULS */
2546
            gen_fmuls(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2547 2548 2549
            break;
        case 0x03:
            /* DIVS */
2550
            gen_fdivs(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2551 2552 2553
            break;
        case 0x20:
            /* ADDT */
2554
            gen_faddt(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2555 2556 2557
            break;
        case 0x21:
            /* SUBT */
2558
            gen_fsubt(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2559 2560 2561
            break;
        case 0x22:
            /* MULT */
2562
            gen_fmult(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2563 2564 2565
            break;
        case 0x23:
            /* DIVT */
2566
            gen_fdivt(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2567 2568 2569
            break;
        case 0x24:
            /* CMPTUN */
2570
            gen_fcmptun(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2571 2572 2573
            break;
        case 0x25:
            /* CMPTEQ */
2574
            gen_fcmpteq(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2575 2576 2577
            break;
        case 0x26:
            /* CMPTLT */
2578
            gen_fcmptlt(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2579 2580 2581
            break;
        case 0x27:
            /* CMPTLE */
2582
            gen_fcmptle(ctx, ra, rb, rc, fn11);
J
j_mayer 已提交
2583 2584
            break;
        case 0x2C:
A
aurel32 已提交
2585
            if (fn11 == 0x2AC || fn11 == 0x6AC) {
J
j_mayer 已提交
2586
                /* CVTST */
2587
                gen_fcvtst(ctx, rb, rc, fn11);
J
j_mayer 已提交
2588 2589
            } else {
                /* CVTTS */
2590
                gen_fcvtts(ctx, rb, rc, fn11);
J
j_mayer 已提交
2591 2592 2593 2594
            }
            break;
        case 0x2F:
            /* CVTTQ */
2595
            gen_fcvttq(ctx, rb, rc, fn11);
J
j_mayer 已提交
2596 2597 2598
            break;
        case 0x3C:
            /* CVTQS */
2599
            gen_fcvtqs(ctx, rb, rc, fn11);
J
j_mayer 已提交
2600 2601 2602
            break;
        case 0x3E:
            /* CVTQT */
2603
            gen_fcvtqt(ctx, rb, rc, fn11);
J
j_mayer 已提交
2604 2605 2606 2607 2608 2609 2610 2611 2612
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x17:
        switch (fn11) {
        case 0x010:
            /* CVTLQ */
P
pbrook 已提交
2613
            gen_fcvtlq(rb, rc);
J
j_mayer 已提交
2614 2615
            break;
        case 0x020:
A
aurel32 已提交
2616
            if (likely(rc != 31)) {
R
Richard Henderson 已提交
2617
                if (ra == rb) {
J
j_mayer 已提交
2618
                    /* FMOV */
R
Richard Henderson 已提交
2619 2620 2621 2622 2623
                    if (ra == 31)
                        tcg_gen_movi_i64(cpu_fir[rc], 0);
                    else
                        tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
                } else {
A
aurel32 已提交
2624
                    /* CPYS */
P
pbrook 已提交
2625
                    gen_fcpys(ra, rb, rc);
R
Richard Henderson 已提交
2626
                }
J
j_mayer 已提交
2627 2628 2629 2630
            }
            break;
        case 0x021:
            /* CPYSN */
P
pbrook 已提交
2631
            gen_fcpysn(ra, rb, rc);
J
j_mayer 已提交
2632 2633 2634
            break;
        case 0x022:
            /* CPYSE */
P
pbrook 已提交
2635
            gen_fcpyse(ra, rb, rc);
J
j_mayer 已提交
2636 2637 2638
            break;
        case 0x024:
            /* MT_FPCR */
A
aurel32 已提交
2639
            if (likely(ra != 31))
P
pbrook 已提交
2640
                gen_helper_store_fpcr(cpu_fir[ra]);
A
aurel32 已提交
2641 2642
            else {
                TCGv tmp = tcg_const_i64(0);
P
pbrook 已提交
2643
                gen_helper_store_fpcr(tmp);
A
aurel32 已提交
2644 2645
                tcg_temp_free(tmp);
            }
J
j_mayer 已提交
2646 2647 2648
            break;
        case 0x025:
            /* MF_FPCR */
A
aurel32 已提交
2649
            if (likely(ra != 31))
P
pbrook 已提交
2650
                gen_helper_load_fpcr(cpu_fir[ra]);
J
j_mayer 已提交
2651 2652 2653
            break;
        case 0x02A:
            /* FCMOVEQ */
2654
            gen_fcmov(TCG_COND_EQ, ra, rb, rc);
J
j_mayer 已提交
2655 2656 2657
            break;
        case 0x02B:
            /* FCMOVNE */
2658
            gen_fcmov(TCG_COND_NE, ra, rb, rc);
J
j_mayer 已提交
2659 2660 2661
            break;
        case 0x02C:
            /* FCMOVLT */
2662
            gen_fcmov(TCG_COND_LT, ra, rb, rc);
J
j_mayer 已提交
2663 2664 2665
            break;
        case 0x02D:
            /* FCMOVGE */
2666
            gen_fcmov(TCG_COND_GE, ra, rb, rc);
J
j_mayer 已提交
2667 2668 2669
            break;
        case 0x02E:
            /* FCMOVLE */
2670
            gen_fcmov(TCG_COND_LE, ra, rb, rc);
J
j_mayer 已提交
2671 2672 2673
            break;
        case 0x02F:
            /* FCMOVGT */
2674
            gen_fcmov(TCG_COND_GT, ra, rb, rc);
J
j_mayer 已提交
2675 2676 2677
            break;
        case 0x030:
            /* CVTQL */
P
pbrook 已提交
2678
            gen_fcvtql(rb, rc);
J
j_mayer 已提交
2679 2680 2681 2682 2683
            break;
        case 0x130:
            /* CVTQL/V */
        case 0x530:
            /* CVTQL/SV */
2684 2685 2686 2687
            /* ??? I'm pretty sure there's nothing that /sv needs to do that
               /v doesn't do.  The only thing I can think is that /sv is a
               valid instruction merely for completeness in the ISA.  */
            gen_fcvtql_v(ctx, rb, rc);
J
j_mayer 已提交
2688 2689 2690 2691 2692 2693 2694 2695 2696
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x18:
        switch ((uint16_t)disp16) {
        case 0x0000:
            /* TRAPB */
2697
            /* No-op.  */
J
j_mayer 已提交
2698 2699 2700
            break;
        case 0x0400:
            /* EXCB */
2701
            /* No-op.  */
J
j_mayer 已提交
2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720
            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 已提交
2721
            if (ra != 31)
P
pbrook 已提交
2722
                gen_helper_load_pcc(cpu_ir[ra]);
J
j_mayer 已提交
2723 2724 2725
            break;
        case 0xE000:
            /* RC */
2726
            gen_rx(ra, 0);
J
j_mayer 已提交
2727 2728 2729 2730 2731 2732
            break;
        case 0xE800:
            /* ECB */
            break;
        case 0xF000:
            /* RS */
2733
            gen_rx(ra, 1);
J
j_mayer 已提交
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744
            break;
        case 0xF800:
            /* WH64 */
            /* No-op */
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x19:
        /* HW_MFPR (PALcode) */
2745
#ifndef CONFIG_USER_ONLY
2746
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
2747 2748 2749 2750
            gen_mfpr(ra, insn & 0xffff);
            break;
        }
#endif
J
j_mayer 已提交
2751 2752
        goto invalid_opc;
    case 0x1A:
2753 2754 2755
        /* JMP, JSR, RET, JSR_COROUTINE.  These only differ by the branch
           prediction stack action, which of course we don't implement.  */
        if (rb != 31) {
A
aurel32 已提交
2756
            tcg_gen_andi_i64(cpu_pc, cpu_ir[rb], ~3);
2757
        } else {
A
aurel32 已提交
2758
            tcg_gen_movi_i64(cpu_pc, 0);
2759 2760
        }
        if (ra != 31) {
A
aurel32 已提交
2761
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
2762
        }
2763
        ret = EXIT_PC_UPDATED;
J
j_mayer 已提交
2764 2765 2766
        break;
    case 0x1B:
        /* HW_LD (PALcode) */
2767 2768 2769 2770 2771 2772 2773 2774 2775
#ifndef CONFIG_USER_ONLY
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
            TCGv addr;

            if (ra == 31) {
                break;
            }

            addr = tcg_temp_new();
2776 2777 2778 2779 2780 2781
            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:
2782
                /* Longword physical access (hw_ldl/p) */
2783
                gen_helper_ldl_phys(cpu_ir[ra], addr);
2784 2785
                break;
            case 0x1:
2786
                /* Quadword physical access (hw_ldq/p) */
2787
                gen_helper_ldq_phys(cpu_ir[ra], addr);
2788 2789
                break;
            case 0x2:
2790
                /* Longword physical access with lock (hw_ldl_l/p) */
2791
                gen_helper_ldl_l_phys(cpu_ir[ra], addr);
2792 2793
                break;
            case 0x3:
2794
                /* Quadword physical access with lock (hw_ldq_l/p) */
2795
                gen_helper_ldq_l_phys(cpu_ir[ra], addr);
2796 2797
                break;
            case 0x4:
2798
                /* Longword virtual PTE fetch (hw_ldl/v) */
2799
                goto invalid_opc;
2800
            case 0x5:
2801
                /* Quadword virtual PTE fetch (hw_ldq/v) */
2802
                goto invalid_opc;
2803 2804 2805
                break;
            case 0x6:
                /* Incpu_ir[ra]id */
2806
                goto invalid_opc;
2807 2808
            case 0x7:
                /* Incpu_ir[ra]id */
2809
                goto invalid_opc;
2810
            case 0x8:
2811
                /* Longword virtual access (hw_ldl) */
2812
                goto invalid_opc;
2813
            case 0x9:
2814
                /* Quadword virtual access (hw_ldq) */
2815
                goto invalid_opc;
2816
            case 0xA:
2817
                /* Longword virtual access with protection check (hw_ldl/w) */
2818
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, MMU_KERNEL_IDX);
2819 2820
                break;
            case 0xB:
2821
                /* Quadword virtual access with protection check (hw_ldq/w) */
2822
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, MMU_KERNEL_IDX);
2823 2824
                break;
            case 0xC:
2825
                /* Longword virtual access with alt access mode (hw_ldl/a)*/
2826
                goto invalid_opc;
2827
            case 0xD:
2828
                /* Quadword virtual access with alt access mode (hw_ldq/a) */
2829
                goto invalid_opc;
2830 2831
            case 0xE:
                /* Longword virtual access with alternate access mode and
2832 2833
                   protection checks (hw_ldl/wa) */
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, MMU_USER_IDX);
2834 2835 2836
                break;
            case 0xF:
                /* Quadword virtual access with alternate access mode and
2837 2838
                   protection checks (hw_ldq/wa) */
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, MMU_USER_IDX);
2839 2840 2841
                break;
            }
            tcg_temp_free(addr);
2842
            break;
J
j_mayer 已提交
2843 2844
        }
#endif
2845
        goto invalid_opc;
J
j_mayer 已提交
2846 2847 2848 2849
    case 0x1C:
        switch (fn7) {
        case 0x00:
            /* SEXTB */
2850
            if ((ctx->tb->flags & TB_FLAGS_AMASK_BWX) == 0) {
J
j_mayer 已提交
2851
                goto invalid_opc;
2852
            }
2853 2854 2855 2856
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int8_t)lit));
                else
2857
                    tcg_gen_ext8s_i64(cpu_ir[rc], cpu_ir[rb]);
2858
            }
J
j_mayer 已提交
2859 2860 2861
            break;
        case 0x01:
            /* SEXTW */
2862 2863 2864 2865 2866 2867 2868 2869 2870
            if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
                if (likely(rc != 31)) {
                    if (islit) {
                        tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
                    } else {
                        tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
                    }
                }
                break;
2871
            }
2872
            goto invalid_opc;
J
j_mayer 已提交
2873 2874
        case 0x30:
            /* CTPOP */
2875 2876 2877 2878 2879 2880 2881 2882 2883
            if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
                if (likely(rc != 31)) {
                    if (islit) {
                        tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
                    } else {
                        gen_helper_ctpop(cpu_ir[rc], cpu_ir[rb]);
                    }
                }
                break;
2884
            }
2885
            goto invalid_opc;
J
j_mayer 已提交
2886 2887
        case 0x31:
            /* PERR */
2888 2889 2890 2891 2892
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_perr(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2893 2894
        case 0x32:
            /* CTLZ */
2895 2896 2897 2898 2899 2900 2901 2902 2903
            if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
                if (likely(rc != 31)) {
                    if (islit) {
                        tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
                    } else {
                        gen_helper_ctlz(cpu_ir[rc], cpu_ir[rb]);
                    }
                }
                break;
2904
            }
2905
            goto invalid_opc;
J
j_mayer 已提交
2906 2907
        case 0x33:
            /* CTTZ */
2908 2909 2910 2911 2912 2913 2914 2915 2916
            if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
                if (likely(rc != 31)) {
                    if (islit) {
                        tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
                    } else {
                        gen_helper_cttz(cpu_ir[rc], cpu_ir[rb]);
                    }
                }
                break;
2917
            }
2918
            goto invalid_opc;
J
j_mayer 已提交
2919 2920
        case 0x34:
            /* UNPKBW */
2921 2922 2923 2924 2925 2926 2927 2928
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                if (real_islit || ra != 31) {
                    goto invalid_opc;
                }
                gen_unpkbw(rb, rc);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2929
        case 0x35:
2930
            /* UNPKBL */
2931 2932 2933 2934 2935 2936 2937 2938
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                if (real_islit || ra != 31) {
                    goto invalid_opc;
                }
                gen_unpkbl(rb, rc);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2939 2940
        case 0x36:
            /* PKWB */
2941 2942 2943 2944 2945 2946 2947 2948
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                if (real_islit || ra != 31) {
                    goto invalid_opc;
                }
                gen_pkwb(rb, rc);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2949 2950
        case 0x37:
            /* PKLB */
2951 2952 2953 2954 2955 2956 2957 2958
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                if (real_islit || ra != 31) {
                    goto invalid_opc;
                }
                gen_pklb(rb, rc);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2959 2960
        case 0x38:
            /* MINSB8 */
2961 2962 2963 2964 2965
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_minsb8(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2966 2967
        case 0x39:
            /* MINSW4 */
2968 2969 2970 2971 2972
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_minsw4(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2973 2974
        case 0x3A:
            /* MINUB8 */
2975 2976 2977 2978 2979
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_minub8(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2980 2981
        case 0x3B:
            /* MINUW4 */
2982 2983 2984 2985 2986
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_minuw4(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2987 2988
        case 0x3C:
            /* MAXUB8 */
2989 2990 2991 2992 2993
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_maxub8(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
2994 2995
        case 0x3D:
            /* MAXUW4 */
2996 2997 2998 2999 3000
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_maxuw4(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
3001 3002
        case 0x3E:
            /* MAXSB8 */
3003 3004 3005 3006 3007
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_maxsb8(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
3008 3009
        case 0x3F:
            /* MAXSW4 */
3010 3011 3012 3013 3014
            if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
                gen_maxsw4(ra, rb, rc, islit, lit);
                break;
            }
            goto invalid_opc;
J
j_mayer 已提交
3015 3016
        case 0x70:
            /* FTOIT */
3017
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
J
j_mayer 已提交
3018
                goto invalid_opc;
3019
            }
A
aurel32 已提交
3020 3021 3022 3023 3024 3025
            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 已提交
3026 3027 3028
            break;
        case 0x78:
            /* FTOIS */
3029
            if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
J
j_mayer 已提交
3030
                goto invalid_opc;
3031
            }
A
aurel32 已提交
3032
            if (rc != 31) {
P
pbrook 已提交
3033
                TCGv_i32 tmp1 = tcg_temp_new_i32();
A
aurel32 已提交
3034
                if (ra != 31)
P
pbrook 已提交
3035
                    gen_helper_s_to_memory(tmp1, cpu_fir[ra]);
A
aurel32 已提交
3036 3037
                else {
                    TCGv tmp2 = tcg_const_i64(0);
P
pbrook 已提交
3038
                    gen_helper_s_to_memory(tmp1, tmp2);
A
aurel32 已提交
3039 3040 3041
                    tcg_temp_free(tmp2);
                }
                tcg_gen_ext_i32_i64(cpu_ir[rc], tmp1);
P
pbrook 已提交
3042
                tcg_temp_free_i32(tmp1);
A
aurel32 已提交
3043
            }
J
j_mayer 已提交
3044 3045 3046 3047 3048 3049 3050
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x1D:
        /* HW_MTPR (PALcode) */
3051
#ifndef CONFIG_USER_ONLY
3052 3053
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
            gen_mtpr(rb, insn & 0xffff);
3054 3055 3056
            break;
        }
#endif
J
j_mayer 已提交
3057 3058
        goto invalid_opc;
    case 0x1E:
3059
        /* HW_RET (PALcode) */
3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074
#ifndef CONFIG_USER_ONLY
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
            if (rb == 31) {
                /* Pre-EV6 CPUs interpreted this as HW_REI, loading the return
                   address from EXC_ADDR.  This turns out to be useful for our
                   emulation PALcode, so continue to accept it.  */
                TCGv tmp = tcg_temp_new();
                tcg_gen_ld_i64(tmp, cpu_env, offsetof(CPUState, exc_addr));
                gen_helper_hw_ret(tmp);
                tcg_temp_free(tmp);
            } else {
                gen_helper_hw_ret(cpu_ir[rb]);
            }
            ret = EXIT_PC_UPDATED;
            break;
J
j_mayer 已提交
3075 3076
        }
#endif
3077
        goto invalid_opc;
J
j_mayer 已提交
3078 3079
    case 0x1F:
        /* HW_ST (PALcode) */
3080 3081
#ifndef CONFIG_USER_ONLY
        if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
3082
            TCGv addr, val;
P
pbrook 已提交
3083
            addr = tcg_temp_new();
3084 3085 3086 3087 3088 3089 3090
            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 已提交
3091
                val = tcg_temp_new();
3092 3093 3094 3095 3096
                tcg_gen_movi_i64(val, 0);
            }
            switch ((insn >> 12) & 0xF) {
            case 0x0:
                /* Longword physical access */
3097
                gen_helper_stl_phys(addr, val);
3098 3099 3100
                break;
            case 0x1:
                /* Quadword physical access */
3101
                gen_helper_stq_phys(addr, val);
3102 3103 3104
                break;
            case 0x2:
                /* Longword physical access with lock */
3105
                gen_helper_stl_c_phys(val, addr, val);
3106 3107 3108
                break;
            case 0x3:
                /* Quadword physical access with lock */
3109
                gen_helper_stq_c_phys(val, addr, val);
3110 3111 3112
                break;
            case 0x4:
                /* Longword virtual access */
3113
                goto invalid_opc;
3114 3115
            case 0x5:
                /* Quadword virtual access */
3116
                goto invalid_opc;
3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136
            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 */
3137
                goto invalid_opc;
3138 3139
            case 0xD:
                /* Quadword virtual access with alternate access mode */
3140
                goto invalid_opc;
3141 3142 3143 3144 3145 3146 3147
            case 0xE:
                /* Invalid */
                goto invalid_opc;
            case 0xF:
                /* Invalid */
                goto invalid_opc;
            }
A
aurel32 已提交
3148
            if (ra == 31)
3149 3150
                tcg_temp_free(val);
            tcg_temp_free(addr);
3151
            break;
J
j_mayer 已提交
3152 3153
        }
#endif
3154
        goto invalid_opc;
J
j_mayer 已提交
3155 3156
    case 0x20:
        /* LDF */
A
aurel32 已提交
3157
        gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
3158 3159 3160
        break;
    case 0x21:
        /* LDG */
A
aurel32 已提交
3161
        gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
3162 3163 3164
        break;
    case 0x22:
        /* LDS */
A
aurel32 已提交
3165
        gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
3166 3167 3168
        break;
    case 0x23:
        /* LDT */
A
aurel32 已提交
3169
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
3170 3171 3172
        break;
    case 0x24:
        /* STF */
3173
        gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
3174 3175 3176
        break;
    case 0x25:
        /* STG */
3177
        gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
3178 3179 3180
        break;
    case 0x26:
        /* STS */
3181
        gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
3182 3183 3184
        break;
    case 0x27:
        /* STT */
3185
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
3186 3187 3188
        break;
    case 0x28:
        /* LDL */
A
aurel32 已提交
3189
        gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
3190 3191 3192
        break;
    case 0x29:
        /* LDQ */
A
aurel32 已提交
3193
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
3194 3195 3196
        break;
    case 0x2A:
        /* LDL_L */
3197
        gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
3198 3199 3200
        break;
    case 0x2B:
        /* LDQ_L */
3201
        gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
3202 3203 3204
        break;
    case 0x2C:
        /* STL */
3205
        gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
3206 3207 3208
        break;
    case 0x2D:
        /* STQ */
3209
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
3210 3211 3212
        break;
    case 0x2E:
        /* STL_C */
3213
        ret = gen_store_conditional(ctx, ra, rb, disp16, 0);
J
j_mayer 已提交
3214 3215 3216
        break;
    case 0x2F:
        /* STQ_C */
3217
        ret = gen_store_conditional(ctx, ra, rb, disp16, 1);
J
j_mayer 已提交
3218 3219 3220
        break;
    case 0x30:
        /* BR */
3221
        ret = gen_bdirect(ctx, ra, disp21);
J
j_mayer 已提交
3222
        break;
P
pbrook 已提交
3223
    case 0x31: /* FBEQ */
3224
        ret = gen_fbcond(ctx, TCG_COND_EQ, ra, disp21);
3225
        break;
P
pbrook 已提交
3226
    case 0x32: /* FBLT */
3227
        ret = gen_fbcond(ctx, TCG_COND_LT, ra, disp21);
3228
        break;
P
pbrook 已提交
3229
    case 0x33: /* FBLE */
3230
        ret = gen_fbcond(ctx, TCG_COND_LE, ra, disp21);
J
j_mayer 已提交
3231 3232 3233
        break;
    case 0x34:
        /* BSR */
3234
        ret = gen_bdirect(ctx, ra, disp21);
J
j_mayer 已提交
3235
        break;
P
pbrook 已提交
3236
    case 0x35: /* FBNE */
3237
        ret = gen_fbcond(ctx, TCG_COND_NE, ra, disp21);
3238
        break;
P
pbrook 已提交
3239
    case 0x36: /* FBGE */
3240
        ret = gen_fbcond(ctx, TCG_COND_GE, ra, disp21);
3241
        break;
P
pbrook 已提交
3242
    case 0x37: /* FBGT */
3243
        ret = gen_fbcond(ctx, TCG_COND_GT, ra, disp21);
J
j_mayer 已提交
3244 3245 3246
        break;
    case 0x38:
        /* BLBC */
3247
        ret = gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 1);
J
j_mayer 已提交
3248 3249 3250
        break;
    case 0x39:
        /* BEQ */
3251
        ret = gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 0);
J
j_mayer 已提交
3252 3253 3254
        break;
    case 0x3A:
        /* BLT */
3255
        ret = gen_bcond(ctx, TCG_COND_LT, ra, disp21, 0);
J
j_mayer 已提交
3256 3257 3258
        break;
    case 0x3B:
        /* BLE */
3259
        ret = gen_bcond(ctx, TCG_COND_LE, ra, disp21, 0);
J
j_mayer 已提交
3260 3261 3262
        break;
    case 0x3C:
        /* BLBS */
3263
        ret = gen_bcond(ctx, TCG_COND_NE, ra, disp21, 1);
J
j_mayer 已提交
3264 3265 3266
        break;
    case 0x3D:
        /* BNE */
3267
        ret = gen_bcond(ctx, TCG_COND_NE, ra, disp21, 0);
J
j_mayer 已提交
3268 3269 3270
        break;
    case 0x3E:
        /* BGE */
3271
        ret = gen_bcond(ctx, TCG_COND_GE, ra, disp21, 0);
J
j_mayer 已提交
3272 3273 3274
        break;
    case 0x3F:
        /* BGT */
3275
        ret = gen_bcond(ctx, TCG_COND_GT, ra, disp21, 0);
J
j_mayer 已提交
3276 3277
        break;
    invalid_opc:
3278
        ret = gen_invalid(ctx);
J
j_mayer 已提交
3279 3280 3281 3282 3283 3284
        break;
    }

    return ret;
}

B
Blue Swirl 已提交
3285 3286 3287
static inline void gen_intermediate_code_internal(CPUState *env,
                                                  TranslationBlock *tb,
                                                  int search_pc)
J
j_mayer 已提交
3288 3289 3290 3291 3292
{
    DisasContext ctx, *ctxp = &ctx;
    target_ulong pc_start;
    uint32_t insn;
    uint16_t *gen_opc_end;
3293
    CPUBreakpoint *bp;
J
j_mayer 已提交
3294
    int j, lj = -1;
3295
    ExitStatus ret;
P
pbrook 已提交
3296 3297
    int num_insns;
    int max_insns;
J
j_mayer 已提交
3298 3299 3300

    pc_start = tb->pc;
    gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
3301 3302 3303

    ctx.tb = tb;
    ctx.env = env;
J
j_mayer 已提交
3304
    ctx.pc = pc_start;
3305
    ctx.mem_idx = cpu_mmu_index(env);
3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316

    /* ??? Every TB begins with unset rounding mode, to be initialized on
       the first fp insn of the TB.  Alternately we could define a proper
       default for every TB (e.g. QUAL_RM_N or QUAL_RM_D) and make sure
       to reset the FP_STATUS to that default at the end of any TB that
       changes the default.  We could even (gasp) dynamiclly figure out
       what default would be most efficient given the running program.  */
    ctx.tb_rm = -1;
    /* Similarly for flush-to-zero.  */
    ctx.tb_ftz = -1;

P
pbrook 已提交
3317 3318 3319 3320 3321 3322
    num_insns = 0;
    max_insns = tb->cflags & CF_COUNT_MASK;
    if (max_insns == 0)
        max_insns = CF_COUNT_MASK;

    gen_icount_start();
3323
    do {
B
Blue Swirl 已提交
3324 3325
        if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
            QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
3326
                if (bp->pc == ctx.pc) {
J
j_mayer 已提交
3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338
                    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;
            }
3339 3340 3341
            gen_opc_pc[lj] = ctx.pc;
            gen_opc_instr_start[lj] = 1;
            gen_opc_icount[lj] = num_insns;
J
j_mayer 已提交
3342
        }
P
pbrook 已提交
3343 3344
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
            gen_io_start();
J
j_mayer 已提交
3345
        insn = ldl_code(ctx.pc);
P
pbrook 已提交
3346
        num_insns++;
3347 3348 3349 3350 3351

	if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
            tcg_gen_debug_insn_start(ctx.pc);
        }

J
j_mayer 已提交
3352 3353
        ctx.pc += 4;
        ret = translate_one(ctxp, insn);
A
aurel32 已提交
3354

3355 3356 3357 3358 3359 3360 3361 3362 3363
        /* If we reach a page boundary, are single stepping,
           or exhaust instruction count, stop generation.  */
        if (ret == NO_EXIT
            && ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0
                || gen_opc_ptr >= gen_opc_end
                || num_insns >= max_insns
                || singlestep
                || env->singlestep_enabled)) {
            ret = EXIT_PC_STALE;
3364
        }
3365 3366 3367 3368
    } while (ret == NO_EXIT);

    if (tb->cflags & CF_LAST_IO) {
        gen_io_end();
J
j_mayer 已提交
3369
    }
3370 3371 3372

    switch (ret) {
    case EXIT_GOTO_TB:
3373
    case EXIT_NORETURN:
3374 3375
        break;
    case EXIT_PC_STALE:
A
aurel32 已提交
3376
        tcg_gen_movi_i64(cpu_pc, ctx.pc);
3377 3378
        /* FALLTHRU */
    case EXIT_PC_UPDATED:
3379 3380 3381 3382 3383
        if (env->singlestep_enabled) {
            gen_excp_1(EXCP_DEBUG, 0);
        } else {
            tcg_gen_exit_tb(0);
        }
3384 3385 3386
        break;
    default:
        abort();
J
j_mayer 已提交
3387
    }
3388

P
pbrook 已提交
3389
    gen_icount_end(tb, num_insns);
J
j_mayer 已提交
3390 3391 3392 3393 3394 3395 3396 3397
    *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 已提交
3398
        tb->icount = num_insns;
J
j_mayer 已提交
3399
    }
3400

R
Richard Henderson 已提交
3401
#ifdef DEBUG_DISAS
3402
    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
3403 3404 3405
        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 已提交
3406 3407 3408 3409
    }
#endif
}

3410
void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
J
j_mayer 已提交
3411
{
3412
    gen_intermediate_code_internal(env, tb, 0);
J
j_mayer 已提交
3413 3414
}

3415
void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
J
j_mayer 已提交
3416
{
3417
    gen_intermediate_code_internal(env, tb, 1);
J
j_mayer 已提交
3418 3419
}

3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443
struct cpu_def_t {
    const char *name;
    int implver, amask;
};

static const struct cpu_def_t cpu_defs[] = {
    { "ev4",   IMPLVER_2106x, 0 },
    { "ev5",   IMPLVER_21164, 0 },
    { "ev56",  IMPLVER_21164, AMASK_BWX },
    { "pca56", IMPLVER_21164, AMASK_BWX | AMASK_MVI },
    { "ev6",   IMPLVER_21264, AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP },
    { "ev67",  IMPLVER_21264, (AMASK_BWX | AMASK_FIX | AMASK_CIX
			       | AMASK_MVI | AMASK_TRAP | AMASK_PREFETCH), },
    { "ev68",  IMPLVER_21264, (AMASK_BWX | AMASK_FIX | AMASK_CIX
			       | AMASK_MVI | AMASK_TRAP | AMASK_PREFETCH), },
    { "21064", IMPLVER_2106x, 0 },
    { "21164", IMPLVER_21164, 0 },
    { "21164a", IMPLVER_21164, AMASK_BWX },
    { "21164pc", IMPLVER_21164, AMASK_BWX | AMASK_MVI },
    { "21264", IMPLVER_21264, AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP },
    { "21264a", IMPLVER_21264, (AMASK_BWX | AMASK_FIX | AMASK_CIX
				| AMASK_MVI | AMASK_TRAP | AMASK_PREFETCH), }
};

B
bellard 已提交
3444
CPUAlphaState * cpu_alpha_init (const char *cpu_model)
J
j_mayer 已提交
3445 3446
{
    CPUAlphaState *env;
3447
    int implver, amask, i, max;
J
j_mayer 已提交
3448 3449 3450

    env = qemu_mallocz(sizeof(CPUAlphaState));
    cpu_exec_init(env);
P
pbrook 已提交
3451
    alpha_translate_init();
J
j_mayer 已提交
3452
    tlb_flush(env, 1);
3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469

    /* Default to ev67; no reason not to emulate insns by default.  */
    implver = IMPLVER_21264;
    amask = (AMASK_BWX | AMASK_FIX | AMASK_CIX | AMASK_MVI
	     | AMASK_TRAP | AMASK_PREFETCH);

    max = ARRAY_SIZE(cpu_defs);
    for (i = 0; i < max; i++) {
        if (strcmp (cpu_model, cpu_defs[i].name) == 0) {
            implver = cpu_defs[i].implver;
            amask = cpu_defs[i].amask;
            break;
        }
    }
    env->implver = implver;
    env->amask = amask;

J
j_mayer 已提交
3470
#if defined (CONFIG_USER_ONLY)
3471
    env->ps = PS_USER_MODE;
R
Richard Henderson 已提交
3472 3473
    cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
                               | FPCR_UNFD | FPCR_INED | FPCR_DNOD));
3474
#endif
3475
    env->lock_addr = -1;
3476
    env->fen = 1;
3477

3478
    qemu_init_vcpu(env);
J
j_mayer 已提交
3479 3480
    return env;
}
B
bellard 已提交
3481

3482
void restore_state_to_opc(CPUState *env, TranslationBlock *tb, int pc_pos)
A
aurel32 已提交
3483 3484 3485
{
    env->pc = gen_opc_pc[pc_pos];
}