translate.c 73.3 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 17 18 19 20 21 22 23 24 25 26 27
 *  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
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

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

#include "cpu.h"
#include "exec-all.h"
#include "disas.h"
28
#include "host-utils.h"
A
aurel32 已提交
29
#include "helper.h"
B
bellard 已提交
30
#include "tcg-op.h"
31
#include "qemu-common.h"
J
j_mayer 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

#define DO_SINGLE_STEP
#define ALPHA_DEBUG_DISAS
#define DO_TB_FLUSH

typedef struct DisasContext DisasContext;
struct DisasContext {
    uint64_t pc;
    int mem_idx;
#if !defined (CONFIG_USER_ONLY)
    int pal_mode;
#endif
    uint32_t amask;
};

A
aurel32 已提交
47
/* global register indexes */
P
pbrook 已提交
48
static TCGv cpu_env;
A
aurel32 已提交
49
static TCGv cpu_ir[31];
A
aurel32 已提交
50
static TCGv cpu_fir[31];
A
aurel32 已提交
51
static TCGv cpu_pc;
52
static TCGv cpu_lock;
A
aurel32 已提交
53

A
aurel32 已提交
54
/* dyngen register indexes */
55
static TCGv cpu_T[2];
A
aurel32 已提交
56 57

/* register names */
A
aurel32 已提交
58
static char cpu_reg_names[10*4+21*5 + 10*5+21*6];
P
pbrook 已提交
59 60 61

#include "gen-icount.h"

62
static void alpha_translate_init(void)
P
pbrook 已提交
63
{
A
aurel32 已提交
64 65
    int i;
    char *p;
P
pbrook 已提交
66
    static int done_init = 0;
A
aurel32 已提交
67

P
pbrook 已提交
68 69
    if (done_init)
        return;
A
aurel32 已提交
70

P
pbrook 已提交
71
    cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
A
aurel32 已提交
72

A
aurel32 已提交
73 74 75 76 77 78 79 80 81 82
#if TARGET_LONG_BITS > HOST_LONG_BITS
    cpu_T[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
                                  offsetof(CPUState, t0), "T0");
    cpu_T[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
                                  offsetof(CPUState, t1), "T1");
#else
    cpu_T[0] = tcg_global_reg_new(TCG_TYPE_I64, TCG_AREG1, "T0");
    cpu_T[1] = tcg_global_reg_new(TCG_TYPE_I64, TCG_AREG2, "T1");
#endif

A
aurel32 已提交
83 84 85 86 87
    p = cpu_reg_names;
    for (i = 0; i < 31; i++) {
        sprintf(p, "ir%d", i);
        cpu_ir[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
                                       offsetof(CPUState, ir[i]), p);
A
aurel32 已提交
88
        p += (i < 10) ? 4 : 5;
A
aurel32 已提交
89 90 91 92 93

        sprintf(p, "fir%d", i);
        cpu_fir[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
                                        offsetof(CPUState, fir[i]), p);
        p += (i < 10) ? 5 : 6;
A
aurel32 已提交
94 95 96 97 98
    }

    cpu_pc = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
                                offsetof(CPUState, pc), "pc");

99 100 101
    cpu_lock = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
                                  offsetof(CPUState, lock), "lock");

A
aurel32 已提交
102 103 104 105 106
    /* register helpers */
#undef DEF_HELPER
#define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
#include "helper.h"

P
pbrook 已提交
107 108 109
    done_init = 1;
}

J
j_mayer 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123
/* Memory moves */
#if defined(CONFIG_USER_ONLY)
#define OP_LD_TABLE(width)                                                    \
static GenOpFunc *gen_op_ld##width[] = {                                      \
    &gen_op_ld##width##_raw,                                                  \
}
#define OP_ST_TABLE(width)                                                    \
static GenOpFunc *gen_op_st##width[] = {                                      \
    &gen_op_st##width##_raw,                                                  \
}
#else
#define OP_LD_TABLE(width)                                                    \
static GenOpFunc *gen_op_ld##width[] = {                                      \
    &gen_op_ld##width##_kernel,                                               \
124 125 126
    &gen_op_ld##width##_executive,                                            \
    &gen_op_ld##width##_supervisor,                                           \
    &gen_op_ld##width##_user,                                                 \
J
j_mayer 已提交
127 128 129 130
}
#define OP_ST_TABLE(width)                                                    \
static GenOpFunc *gen_op_st##width[] = {                                      \
    &gen_op_st##width##_kernel,                                               \
131 132 133
    &gen_op_st##width##_executive,                                            \
    &gen_op_st##width##_supervisor,                                           \
    &gen_op_st##width##_user,                                                 \
J
j_mayer 已提交
134 135 136 137 138
}
#endif

#define GEN_LD(width)                                                         \
OP_LD_TABLE(width);                                                           \
J
j_mayer 已提交
139
static always_inline void gen_ld##width (DisasContext *ctx)                   \
J
j_mayer 已提交
140 141 142 143 144 145
{                                                                             \
    (*gen_op_ld##width[ctx->mem_idx])();                                      \
}

#define GEN_ST(width)                                                         \
OP_ST_TABLE(width);                                                           \
J
j_mayer 已提交
146
static always_inline void gen_st##width (DisasContext *ctx)                   \
J
j_mayer 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159
{                                                                             \
    (*gen_op_st##width[ctx->mem_idx])();                                      \
}

GEN_LD(l);
GEN_ST(l);
GEN_LD(q);
GEN_ST(q);
GEN_LD(l_l);
GEN_ST(l_c);
GEN_LD(q_l);
GEN_ST(q_c);

J
j_mayer 已提交
160 161
static always_inline void gen_excp (DisasContext *ctx,
                                    int exception, int error_code)
J
j_mayer 已提交
162
{
163 164
    TCGv tmp1, tmp2;

A
aurel32 已提交
165
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
166 167 168 169 170
    tmp1 = tcg_const_i32(exception);
    tmp2 = tcg_const_i32(error_code);
    tcg_gen_helper_0_2(helper_excp, tmp1, tmp2);
    tcg_temp_free(tmp2);
    tcg_temp_free(tmp1);
J
j_mayer 已提交
171 172
}

J
j_mayer 已提交
173
static always_inline void gen_invalid (DisasContext *ctx)
J
j_mayer 已提交
174 175 176 177
{
    gen_excp(ctx, EXCP_OPCDEC, 0);
}

A
aurel32 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
static always_inline void gen_qemu_ldf (TCGv t0, TCGv t1, int flags)
{
    TCGv tmp = tcg_temp_new(TCG_TYPE_I32);
    tcg_gen_qemu_ld32u(tmp, t1, flags);
    tcg_gen_helper_1_1(helper_memory_to_f, t0, tmp);
    tcg_temp_free(tmp);
}

static always_inline void gen_qemu_ldg (TCGv t0, TCGv t1, int flags)
{
    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
    tcg_gen_qemu_ld64(tmp, t1, flags);
    tcg_gen_helper_1_1(helper_memory_to_g, t0, tmp);
    tcg_temp_free(tmp);
}

static always_inline void gen_qemu_lds (TCGv t0, TCGv t1, int flags)
{
    TCGv tmp = tcg_temp_new(TCG_TYPE_I32);
    tcg_gen_qemu_ld32u(tmp, t1, flags);
    tcg_gen_helper_1_1(helper_memory_to_s, t0, tmp);
    tcg_temp_free(tmp);
}

202 203 204 205 206 207 208 209 210 211 212 213
static always_inline void gen_qemu_ldl_l (TCGv t0, TCGv t1, int flags)
{
    tcg_gen_mov_i64(cpu_lock, t1);
    tcg_gen_qemu_ld32s(t0, t1, flags);
}

static always_inline void gen_qemu_ldq_l (TCGv t0, TCGv t1, int flags)
{
    tcg_gen_mov_i64(cpu_lock, t1);
    tcg_gen_qemu_ld64(t0, t1, flags);
}

214 215 216
static always_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,
A
aurel32 已提交
217
                                        int fp, int clear)
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
{
    TCGv addr;

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

    addr = tcg_temp_new(TCG_TYPE_I64);
    if (rb != 31) {
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
        if (clear)
            tcg_gen_andi_i64(addr, addr, ~0x7);
    } else {
        if (clear)
            disp16 &= ~0x7;
        tcg_gen_movi_i64(addr, disp16);
    }
A
aurel32 已提交
234 235 236 237
    if (fp)
        tcg_gen_qemu_load(cpu_fir[ra], addr, ctx->mem_idx);
    else
        tcg_gen_qemu_load(cpu_ir[ra], addr, ctx->mem_idx);
238 239 240
    tcg_temp_free(addr);
}

A
aurel32 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
static always_inline void gen_qemu_stf (TCGv t0, TCGv t1, int flags)
{
    TCGv tmp = tcg_temp_new(TCG_TYPE_I32);
    tcg_gen_helper_1_1(helper_f_to_memory, tmp, t0);
    tcg_gen_qemu_st32(tmp, t1, flags);
    tcg_temp_free(tmp);
}

static always_inline void gen_qemu_stg (TCGv t0, TCGv t1, int flags)
{
    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
    tcg_gen_helper_1_1(helper_g_to_memory, tmp, t0);
    tcg_gen_qemu_st64(tmp, t1, flags);
    tcg_temp_free(tmp);
}

static always_inline void gen_qemu_sts (TCGv t0, TCGv t1, int flags)
{
    TCGv tmp = tcg_temp_new(TCG_TYPE_I32);
    tcg_gen_helper_1_1(helper_s_to_memory, tmp, t0);
    tcg_gen_qemu_st32(tmp, t1, flags);
    tcg_temp_free(tmp);
}

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
static always_inline void gen_qemu_stl_c (TCGv t0, TCGv t1, int flags)
{
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
    tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1);
    tcg_gen_qemu_st32(t0, t1, flags);
    tcg_gen_movi_i64(t0, 0);
    tcg_gen_br(l2);
    gen_set_label(l1);
    tcg_gen_movi_i64(t0, 1);
    gen_set_label(l2);
    tcg_gen_movi_i64(cpu_lock, -1);
}

static always_inline void gen_qemu_stq_c (TCGv t0, TCGv t1, int flags)
{
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
    tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1);
    tcg_gen_qemu_st64(t0, t1, flags);
    tcg_gen_movi_i64(t0, 0);
    tcg_gen_br(l2);
    gen_set_label(l1);
    tcg_gen_movi_i64(t0, 1);
    gen_set_label(l2);
    tcg_gen_movi_i64(cpu_lock, -1);
}

297 298 299
static always_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,
A
aurel32 已提交
300
                                         int fp, int clear)
301 302 303 304 305 306 307 308 309 310 311
{
    TCGv addr = tcg_temp_new(TCG_TYPE_I64);
    if (rb != 31) {
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
        if (clear)
            tcg_gen_andi_i64(addr, addr, ~0x7);
    } else {
        if (clear)
            disp16 &= ~0x7;
        tcg_gen_movi_i64(addr, disp16);
    }
A
aurel32 已提交
312 313 314 315 316 317
    if (ra != 31) {
        if (fp)
            tcg_gen_qemu_store(cpu_fir[ra], addr, ctx->mem_idx);
        else
            tcg_gen_qemu_store(cpu_ir[ra], addr, ctx->mem_idx);
    } else {
318 319 320 321 322 323 324
        TCGv zero = tcg_const_i64(0);
        tcg_gen_qemu_store(zero, addr, ctx->mem_idx);
        tcg_temp_free(zero);
    }
    tcg_temp_free(addr);
}

J
j_mayer 已提交
325
static always_inline void gen_bcond (DisasContext *ctx,
A
aurel32 已提交
326 327
                                     TCGCond cond,
                                     int ra, int32_t disp16, int mask)
J
j_mayer 已提交
328
{
A
aurel32 已提交
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
    if (likely(ra != 31)) {
        if (mask) {
            TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
            tcg_gen_andi_i64(tmp, cpu_ir[ra], 1);
            tcg_gen_brcondi_i64(cond, tmp, 0, l1);
            tcg_temp_free(tmp);
        } else
            tcg_gen_brcondi_i64(cond, cpu_ir[ra], 0, l1);
    } else {
        /* Very uncommon case - Do not bother to optimize.  */
        TCGv tmp = tcg_const_i64(0);
        tcg_gen_brcondi_i64(cond, tmp, 0, l1);
        tcg_temp_free(tmp);
    }
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
    tcg_gen_br(l2);
    gen_set_label(l1);
    tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp16 << 2));
    gen_set_label(l2);
J
j_mayer 已提交
352 353
}

J
j_mayer 已提交
354
static always_inline void gen_fbcond (DisasContext *ctx,
A
aurel32 已提交
355
                                      void* func,
J
j_mayer 已提交
356
                                      int ra, int32_t disp16)
J
j_mayer 已提交
357
{
A
aurel32 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
    int l1, l2;
    TCGv tmp;

    l1 = gen_new_label();
    l2 = gen_new_label();
    if (ra != 31) {
        tmp = tcg_temp_new(TCG_TYPE_I64);
        tcg_gen_helper_1_1(func, tmp, cpu_fir[ra]);
    } else  {
        tmp = tcg_const_i64(0);
        tcg_gen_helper_1_1(func, tmp, tmp);
    }
    tcg_gen_brcondi_i64(TCG_COND_NE, tmp, 0, l1);
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
    tcg_gen_br(l2);
    gen_set_label(l1);
    tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp16 << 2));
    gen_set_label(l2);
J
j_mayer 已提交
376 377
}

A
aurel32 已提交
378
static always_inline void gen_cmov (TCGCond inv_cond,
J
j_mayer 已提交
379
                                    int ra, int rb, int rc,
380
                                    int islit, uint8_t lit, int mask)
J
j_mayer 已提交
381
{
A
aurel32 已提交
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
    int l1;

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

    l1 = gen_new_label();

    if (ra != 31) {
        if (mask) {
            TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
            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 已提交
404
    if (islit)
A
aurel32 已提交
405
        tcg_gen_movi_i64(cpu_ir[rc], lit);
J
j_mayer 已提交
406
    else
407
        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
A
aurel32 已提交
408
    gen_set_label(l1);
J
j_mayer 已提交
409 410
}

A
aurel32 已提交
411
static always_inline void gen_farith2 (void *helper,
J
j_mayer 已提交
412
                                       int rb, int rc)
J
j_mayer 已提交
413
{
A
aurel32 已提交
414 415 416 417 418 419 420 421 422 423
    if (unlikely(rc == 31))
      return;

    if (rb != 31)
        tcg_gen_helper_1_1(helper, cpu_fir[rc], cpu_fir[rb]);
    else {
        TCGv tmp = tcg_const_i64(0);
        tcg_gen_helper_1_1(helper, cpu_fir[rc], tmp);
        tcg_temp_free(tmp);
    }
J
j_mayer 已提交
424 425
}

A
aurel32 已提交
426
static always_inline void gen_farith3 (void *helper,
J
j_mayer 已提交
427
                                       int ra, int rb, int rc)
J
j_mayer 已提交
428
{
A
aurel32 已提交
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
        if (rb != 31)
            tcg_gen_helper_1_2(helper, cpu_fir[rc], cpu_fir[ra], cpu_fir[rb]);
        else {
            TCGv tmp = tcg_const_i64(0);
            tcg_gen_helper_1_2(helper, cpu_fir[rc], cpu_fir[ra], tmp);
            tcg_temp_free(tmp);
        }
    } else {
        TCGv tmp = tcg_const_i64(0);
        if (rb != 31)
            tcg_gen_helper_1_2(helper, cpu_fir[rc], tmp, cpu_fir[rb]);
        else
            tcg_gen_helper_1_2(helper, cpu_fir[rc], tmp, tmp);
        tcg_temp_free(tmp);
    }
J
j_mayer 已提交
448 449
}

A
aurel32 已提交
450
static always_inline void gen_fcmov (void *func,
J
j_mayer 已提交
451
                                     int ra, int rb, int rc)
J
j_mayer 已提交
452
{
A
aurel32 已提交
453 454
    int l1;
    TCGv tmp;
J
j_mayer 已提交
455

A
aurel32 已提交
456 457
    if (unlikely(rc == 31))
        return;
J
j_mayer 已提交
458

A
aurel32 已提交
459 460 461 462 463 464 465 466 467 468 469 470
    l1 = gen_new_label();
    tmp = tcg_temp_new(TCG_TYPE_I64);
    if (ra != 31) {
        tmp = tcg_temp_new(TCG_TYPE_I64);
        tcg_gen_helper_1_1(func, tmp, cpu_fir[ra]);
    } else  {
        tmp = tcg_const_i64(0);
        tcg_gen_helper_1_1(func, tmp, tmp);
    }
    tcg_gen_brcondi_i64(TCG_COND_EQ, tmp, 0, l1);
    if (rb != 31)
        tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
A
aurel32 已提交
471
    else
A
aurel32 已提交
472 473
        tcg_gen_movi_i64(cpu_fir[rc], 0);
    gen_set_label(l1);
J
j_mayer 已提交
474 475
}

476 477 478
/* EXTWH, EXTWH, EXTLH, EXTQH */
static always_inline void gen_ext_h(void (*tcg_gen_ext_i64)(TCGv t0, TCGv t1),
                                    int ra, int rb, int rc,
479
                                    int islit, uint8_t lit)
480 481 482 483 484
{
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
485 486 487 488 489
        if (islit) {
            if (lit != 0)
                tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], 64 - ((lit & 7) * 8));
            else
                tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[ra]);
A
aurel32 已提交
490
        } else {
491 492 493 494 495 496 497
            TCGv tmp1, tmp2;
            tmp1 = tcg_temp_new(TCG_TYPE_I64);
            tcg_gen_andi_i64(tmp1, cpu_ir[rb], 7);
            tcg_gen_shli_i64(tmp1, tmp1, 3);
            tmp2 = tcg_const_i64(64);
            tcg_gen_sub_i64(tmp1, tmp2, tmp1);
            tcg_temp_free(tmp2);
498
            tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], tmp1);
499
            tcg_temp_free(tmp1);
500 501 502
        }
        if (tcg_gen_ext_i64)
            tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
503 504 505 506 507 508 509
    } else
        tcg_gen_movi_i64(cpu_ir[rc], 0);
}

/* EXTBL, EXTWL, EXTWL, EXTLL, EXTQL */
static always_inline void gen_ext_l(void (*tcg_gen_ext_i64)(TCGv t0, TCGv t1),
                                    int ra, int rb, int rc,
510
                                    int islit, uint8_t lit)
511 512 513 514 515
{
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
516 517 518
        if (islit) {
                tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], (lit & 7) * 8);
        } else {
519 520 521
            TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
            tcg_gen_andi_i64(tmp, cpu_ir[rb], 7);
            tcg_gen_shli_i64(tmp, tmp, 3);
522
            tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], tmp);
523
            tcg_temp_free(tmp);
A
aurel32 已提交
524
        }
525 526
        if (tcg_gen_ext_i64)
            tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
527 528 529 530
    } else
        tcg_gen_movi_i64(cpu_ir[rc], 0);
}

531
/* Code to call arith3 helpers */
A
aurel32 已提交
532 533 534
static always_inline void gen_arith3 (void *helper,
                                      int ra, int rb, int rc,
                                      int islit, uint8_t lit)
535 536 537 538 539
{
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
540 541
        if (islit) {
            TCGv tmp = tcg_const_i64(lit);
542 543 544 545
            tcg_gen_helper_1_2(helper, cpu_ir[rc], cpu_ir[ra], tmp);
            tcg_temp_free(tmp);
        } else
            tcg_gen_helper_1_2(helper, cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
546 547 548 549 550 551 552 553 554 555
    } else {
        TCGv tmp1 = tcg_const_i64(0);
        if (islit) {
            TCGv tmp2 = tcg_const_i64(lit);
            tcg_gen_helper_1_2(helper, cpu_ir[rc], tmp1, tmp2);
            tcg_temp_free(tmp2);
        } else
            tcg_gen_helper_1_2(helper, cpu_ir[rc], tmp1, cpu_ir[rb]);
        tcg_temp_free(tmp1);
    }
556 557
}

558 559
static always_inline void gen_cmp(TCGCond cond,
                                  int ra, int rb, int rc,
560
                                  int islit, uint8_t lit)
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
{
    int l1, l2;
    TCGv tmp;

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

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

    if (ra != 31) {
        tmp = tcg_temp_new(TCG_TYPE_I64);
        tcg_gen_mov_i64(tmp, cpu_ir[ra]);
    } else
        tmp = tcg_const_i64(0);
    if (islit)
        tcg_gen_brcondi_i64(cond, tmp, lit, l1);
    else
579
        tcg_gen_brcond_i64(cond, tmp, cpu_ir[rb], l1);
580 581 582 583 584 585 586 587

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

J
j_mayer 已提交
588
static always_inline int translate_one (DisasContext *ctx, uint32_t insn)
J
j_mayer 已提交
589 590 591 592 593
{
    uint32_t palcode;
    int32_t disp21, disp16, disp12;
    uint16_t fn11, fn16;
    uint8_t opc, ra, rb, rc, sbz, fpfn, fn7, fn2, islit;
594
    uint8_t lit;
J
j_mayer 已提交
595 596 597 598 599 600 601 602 603
    int ret;

    /* Decode all instruction fields */
    opc = insn >> 26;
    ra = (insn >> 21) & 0x1F;
    rb = (insn >> 16) & 0x1F;
    rc = insn & 0x1F;
    sbz = (insn >> 13) & 0x07;
    islit = (insn >> 12) & 1;
604 605 606 607 608
    if (rb == 31 && !islit) {
        islit = 1;
        lit = 0;
    } else
        lit = (insn >> 13) & 0xFF;
J
j_mayer 已提交
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
    palcode = insn & 0x03FFFFFF;
    disp21 = ((int32_t)((insn & 0x001FFFFF) << 11)) >> 11;
    disp16 = (int16_t)(insn & 0x0000FFFF);
    disp12 = (int32_t)((insn & 0x00000FFF) << 20) >> 20;
    fn16 = insn & 0x0000FFFF;
    fn11 = (insn >> 5) & 0x000007FF;
    fpfn = fn11 & 0x3F;
    fn7 = (insn >> 5) & 0x0000007F;
    fn2 = (insn >> 5) & 0x00000003;
    ret = 0;
#if defined ALPHA_DEBUG_DISAS
    if (logfile != NULL) {
        fprintf(logfile, "opc %02x ra %d rb %d rc %d disp16 %04x\n",
                opc, ra, rb, rc, disp16);
    }
#endif
    switch (opc) {
    case 0x00:
        /* CALL_PAL */
        if (palcode >= 0x80 && palcode < 0xC0) {
            /* Unprivileged PAL call */
            gen_excp(ctx, EXCP_CALL_PAL + ((palcode & 0x1F) << 6), 0);
#if !defined (CONFIG_USER_ONLY)
        } else if (palcode < 0x40) {
            /* Privileged PAL code */
            if (ctx->mem_idx & 1)
                goto invalid_opc;
            else
                gen_excp(ctx, EXCP_CALL_PALP + ((palcode & 0x1F) << 6), 0);
#endif
        } else {
            /* Invalid PAL call */
            goto invalid_opc;
        }
        ret = 3;
        break;
    case 0x01:
        /* OPC01 */
        goto invalid_opc;
    case 0x02:
        /* OPC02 */
        goto invalid_opc;
    case 0x03:
        /* OPC03 */
        goto invalid_opc;
    case 0x04:
        /* OPC04 */
        goto invalid_opc;
    case 0x05:
        /* OPC05 */
        goto invalid_opc;
    case 0x06:
        /* OPC06 */
        goto invalid_opc;
    case 0x07:
        /* OPC07 */
        goto invalid_opc;
    case 0x08:
        /* LDA */
A
aurel32 已提交
668
        if (likely(ra != 31)) {
A
aurel32 已提交
669
            if (rb != 31)
A
aurel32 已提交
670 671 672
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16);
            else
                tcg_gen_movi_i64(cpu_ir[ra], disp16);
A
aurel32 已提交
673
        }
J
j_mayer 已提交
674 675 676
        break;
    case 0x09:
        /* LDAH */
A
aurel32 已提交
677
        if (likely(ra != 31)) {
A
aurel32 已提交
678
            if (rb != 31)
A
aurel32 已提交
679 680 681
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16 << 16);
            else
                tcg_gen_movi_i64(cpu_ir[ra], disp16 << 16);
A
aurel32 已提交
682
        }
J
j_mayer 已提交
683 684 685 686 687
        break;
    case 0x0A:
        /* LDBU */
        if (!(ctx->amask & AMASK_BWX))
            goto invalid_opc;
A
aurel32 已提交
688
        gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
689 690 691
        break;
    case 0x0B:
        /* LDQ_U */
A
aurel32 已提交
692
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
693 694 695 696 697
        break;
    case 0x0C:
        /* LDWU */
        if (!(ctx->amask & AMASK_BWX))
            goto invalid_opc;
A
aurel32 已提交
698
        gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
699 700 701
        break;
    case 0x0D:
        /* STW */
A
aurel32 已提交
702
        gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
703 704 705
        break;
    case 0x0E:
        /* STB */
A
aurel32 已提交
706
        gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
707 708 709
        break;
    case 0x0F:
        /* STQ_U */
A
aurel32 已提交
710
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
711 712 713 714 715
        break;
    case 0x10:
        switch (fn7) {
        case 0x00:
            /* ADDL */
716 717 718 719 720
            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]);
721
                    } else {
722 723
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
724
                    }
725 726
                } else {
                    if (islit)
727
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
728
                    else
729
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
730 731
                }
            }
J
j_mayer 已提交
732 733 734
            break;
        case 0x02:
            /* S4ADDL */
735 736
            if (likely(rc != 31)) {
                if (ra != 31) {
737 738 739 740 741 742 743 744
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                    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);
745 746 747 748
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
749
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
750 751
                }
            }
J
j_mayer 已提交
752 753 754
            break;
        case 0x09:
            /* SUBL */
755 756
            if (likely(rc != 31)) {
                if (ra != 31) {
757
                    if (islit)
758
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
759
                    else
760
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
761
                    tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
762 763 764
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
765
                    else {
766 767 768 769
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
                }
            }
J
j_mayer 已提交
770 771 772
            break;
        case 0x0B:
            /* S4SUBL */
773 774
            if (likely(rc != 31)) {
                if (ra != 31) {
775 776 777 778 779 780 781 782
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                    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);
783 784 785
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
786
                    else {
787 788
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
789
                    }
790 791
                }
            }
J
j_mayer 已提交
792 793 794
            break;
        case 0x0F:
            /* CMPBGE */
A
aurel32 已提交
795
            gen_arith3(helper_cmpbge, ra, rb, rc, islit, lit);
J
j_mayer 已提交
796 797 798
            break;
        case 0x12:
            /* S8ADDL */
799 800
            if (likely(rc != 31)) {
                if (ra != 31) {
801 802 803 804 805 806 807 808
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                    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);
809 810 811 812
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
813
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
814 815
                }
            }
J
j_mayer 已提交
816 817 818
            break;
        case 0x1B:
            /* S8SUBL */
819 820
            if (likely(rc != 31)) {
                if (ra != 31) {
821 822 823 824 825 826 827 828
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                    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);
829 830 831
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
832
                    else
833 834
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
835
                    }
836 837
                }
            }
J
j_mayer 已提交
838 839 840
            break;
        case 0x1D:
            /* CMPULT */
841
            gen_cmp(TCG_COND_LTU, ra, rb, rc, islit, lit);
J
j_mayer 已提交
842 843 844
            break;
        case 0x20:
            /* ADDQ */
845 846 847 848 849
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
850
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
851 852 853 854
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
855
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
856 857
                }
            }
J
j_mayer 已提交
858 859 860
            break;
        case 0x22:
            /* S4ADDQ */
861 862
            if (likely(rc != 31)) {
                if (ra != 31) {
863 864 865 866 867 868 869
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                    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);
870 871 872 873
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
874
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
875 876
                }
            }
J
j_mayer 已提交
877 878 879
            break;
        case 0x29:
            /* SUBQ */
880 881 882 883 884
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
885
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
886 887 888 889
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
890
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
891 892
                }
            }
J
j_mayer 已提交
893 894 895
            break;
        case 0x2B:
            /* S4SUBQ */
896 897
            if (likely(rc != 31)) {
                if (ra != 31) {
898 899 900 901 902 903 904
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                    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);
905 906 907 908
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
909
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
910 911
                }
            }
J
j_mayer 已提交
912 913 914
            break;
        case 0x2D:
            /* CMPEQ */
915
            gen_cmp(TCG_COND_EQ, ra, rb, rc, islit, lit);
J
j_mayer 已提交
916 917 918
            break;
        case 0x32:
            /* S8ADDQ */
919 920
            if (likely(rc != 31)) {
                if (ra != 31) {
921 922 923 924 925 926 927
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                    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);
928 929 930 931
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
932
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
933 934
                }
            }
J
j_mayer 已提交
935 936 937
            break;
        case 0x3B:
            /* S8SUBQ */
938 939
            if (likely(rc != 31)) {
                if (ra != 31) {
940 941 942 943 944 945 946
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                    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);
947 948 949 950
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
951
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
952 953
                }
            }
J
j_mayer 已提交
954 955 956
            break;
        case 0x3D:
            /* CMPULE */
957
            gen_cmp(TCG_COND_LEU, ra, rb, rc, islit, lit);
J
j_mayer 已提交
958 959 960
            break;
        case 0x40:
            /* ADDL/V */
A
aurel32 已提交
961
            gen_arith3(helper_addlv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
962 963 964
            break;
        case 0x49:
            /* SUBL/V */
A
aurel32 已提交
965
            gen_arith3(helper_sublv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
966 967 968
            break;
        case 0x4D:
            /* CMPLT */
969
            gen_cmp(TCG_COND_LT, ra, rb, rc, islit, lit);
J
j_mayer 已提交
970 971 972
            break;
        case 0x60:
            /* ADDQ/V */
A
aurel32 已提交
973
            gen_arith3(helper_addqv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
974 975 976
            break;
        case 0x69:
            /* SUBQ/V */
A
aurel32 已提交
977
            gen_arith3(helper_subqv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
978 979 980
            break;
        case 0x6D:
            /* CMPLE */
981
            gen_cmp(TCG_COND_LE, ra, rb, rc, islit, lit);
J
j_mayer 已提交
982 983 984 985 986 987 988 989 990
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x11:
        switch (fn7) {
        case 0x00:
            /* AND */
991
            if (likely(rc != 31)) {
992
                if (ra == 31)
993 994 995 996 997 998
                    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 已提交
999 1000 1001
            break;
        case 0x08:
            /* BIC */
1002 1003 1004 1005
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1006
                    else {
1007 1008 1009 1010
                        TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                        tcg_gen_not_i64(tmp, cpu_ir[rb]);
                        tcg_gen_and_i64(cpu_ir[rc], cpu_ir[ra], tmp);
                        tcg_temp_free(tmp);
1011
                    }
1012 1013 1014
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1015 1016 1017
            break;
        case 0x14:
            /* CMOVLBS */
A
aurel32 已提交
1018
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 1);
J
j_mayer 已提交
1019 1020 1021
            break;
        case 0x16:
            /* CMOVLBC */
A
aurel32 已提交
1022
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 1);
J
j_mayer 已提交
1023 1024 1025
            break;
        case 0x20:
            /* BIS */
1026 1027 1028 1029
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], lit);
A
aurel32 已提交
1030
        	    else
1031
                        tcg_gen_or_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
J
j_mayer 已提交
1032
                } else {
1033 1034 1035
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1036
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
J
j_mayer 已提交
1037 1038 1039 1040 1041
                }
            }
            break;
        case 0x24:
            /* CMOVEQ */
A
aurel32 已提交
1042
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1043 1044 1045
            break;
        case 0x26:
            /* CMOVNE */
A
aurel32 已提交
1046
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1047 1048 1049
            break;
        case 0x28:
            /* ORNOT */
1050
            if (likely(rc != 31)) {
1051
                if (ra != 31) {
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
                    if (islit)
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
                    else {
                        TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                        tcg_gen_not_i64(tmp, cpu_ir[rb]);
                        tcg_gen_or_i64(cpu_ir[rc], cpu_ir[ra], tmp);
                        tcg_temp_free(tmp);
                    }
                } 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 已提交
1067 1068 1069
            break;
        case 0x40:
            /* XOR */
1070 1071 1072 1073 1074
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
1075
                        tcg_gen_xor_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1076 1077 1078 1079
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1080
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1081 1082
                }
            }
J
j_mayer 已提交
1083 1084 1085
            break;
        case 0x44:
            /* CMOVLT */
A
aurel32 已提交
1086
            gen_cmov(TCG_COND_GE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1087 1088 1089
            break;
        case 0x46:
            /* CMOVGE */
A
aurel32 已提交
1090
            gen_cmov(TCG_COND_LT, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1091 1092 1093
            break;
        case 0x48:
            /* EQV */
1094 1095 1096 1097
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1098
                    else {
1099 1100 1101 1102
                        TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
                        tcg_gen_not_i64(tmp, cpu_ir[rb]);
                        tcg_gen_xor_i64(cpu_ir[rc], cpu_ir[ra], tmp);
                        tcg_temp_free(tmp);
1103
                    }
1104 1105 1106 1107
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], ~lit);
                    else
1108
                        tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
1109 1110
                }
            }
J
j_mayer 已提交
1111 1112 1113
            break;
        case 0x61:
            /* AMASK */
1114 1115 1116 1117
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], helper_amask(lit));
                else
1118
                    tcg_gen_helper_1_1(helper_amask, cpu_ir[rc], cpu_ir[rb]);
1119
            }
J
j_mayer 已提交
1120 1121 1122
            break;
        case 0x64:
            /* CMOVLE */
A
aurel32 已提交
1123
            gen_cmov(TCG_COND_GT, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1124 1125 1126
            break;
        case 0x66:
            /* CMOVGT */
A
aurel32 已提交
1127
            gen_cmov(TCG_COND_LE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1128 1129 1130
            break;
        case 0x6C:
            /* IMPLVER */
A
aurel32 已提交
1131
            if (rc != 31)
1132
                tcg_gen_helper_1_0(helper_load_implver, cpu_ir[rc]);
J
j_mayer 已提交
1133 1134 1135 1136 1137 1138 1139 1140 1141
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x12:
        switch (fn7) {
        case 0x02:
            /* MSKBL */
A
aurel32 已提交
1142
            gen_arith3(helper_mskbl, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1143 1144 1145
            break;
        case 0x06:
            /* EXTBL */
1146
            gen_ext_l(&tcg_gen_ext8u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1147 1148 1149
            break;
        case 0x0B:
            /* INSBL */
A
aurel32 已提交
1150
            gen_arith3(helper_insbl, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1151 1152 1153
            break;
        case 0x12:
            /* MSKWL */
A
aurel32 已提交
1154
            gen_arith3(helper_mskwl, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1155 1156 1157
            break;
        case 0x16:
            /* EXTWL */
1158
            gen_ext_l(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1159 1160 1161
            break;
        case 0x1B:
            /* INSWL */
A
aurel32 已提交
1162
            gen_arith3(helper_inswl, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1163 1164 1165
            break;
        case 0x22:
            /* MSKLL */
A
aurel32 已提交
1166
            gen_arith3(helper_mskll, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1167 1168 1169
            break;
        case 0x26:
            /* EXTLL */
1170
            gen_ext_l(&tcg_gen_ext32u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1171 1172 1173
            break;
        case 0x2B:
            /* INSLL */
A
aurel32 已提交
1174
            gen_arith3(helper_insll, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1175 1176 1177
            break;
        case 0x30:
            /* ZAP */
A
aurel32 已提交
1178
            gen_arith3(helper_zap, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1179 1180 1181
            break;
        case 0x31:
            /* ZAPNOT */
A
aurel32 已提交
1182
            gen_arith3(helper_zapnot, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1183 1184 1185
            break;
        case 0x32:
            /* MSKQL */
A
aurel32 已提交
1186
            gen_arith3(helper_mskql, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1187 1188 1189
            break;
        case 0x34:
            /* SRL */
1190 1191 1192 1193
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1194
                    else {
1195 1196 1197 1198
                        TCGv shift = tcg_temp_new(TCG_TYPE_I64);
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
1199
                    }
1200 1201 1202
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1203 1204 1205
            break;
        case 0x36:
            /* EXTQL */
1206
            gen_ext_l(NULL, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1207 1208 1209
            break;
        case 0x39:
            /* SLL */
1210 1211 1212 1213
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1214
                    else {
1215 1216 1217 1218
                        TCGv shift = tcg_temp_new(TCG_TYPE_I64);
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
1219
                    }
1220 1221 1222
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1223 1224 1225
            break;
        case 0x3B:
            /* INSQL */
A
aurel32 已提交
1226
            gen_arith3(helper_insql, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1227 1228 1229
            break;
        case 0x3C:
            /* SRA */
1230 1231 1232 1233
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_sari_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1234
                    else {
1235 1236 1237 1238
                        TCGv shift = tcg_temp_new(TCG_TYPE_I64);
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
                        tcg_gen_sar_i64(cpu_ir[rc], cpu_ir[ra], shift);
                        tcg_temp_free(shift);
1239
                    }
1240 1241 1242
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1243 1244 1245
            break;
        case 0x52:
            /* MSKWH */
A
aurel32 已提交
1246
            gen_arith3(helper_mskwh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1247 1248 1249
            break;
        case 0x57:
            /* INSWH */
A
aurel32 已提交
1250
            gen_arith3(helper_inswh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1251 1252 1253
            break;
        case 0x5A:
            /* EXTWH */
1254
            gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1255 1256 1257
            break;
        case 0x62:
            /* MSKLH */
A
aurel32 已提交
1258
            gen_arith3(helper_msklh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1259 1260 1261
            break;
        case 0x67:
            /* INSLH */
A
aurel32 已提交
1262
            gen_arith3(helper_inslh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1263 1264 1265
            break;
        case 0x6A:
            /* EXTLH */
1266
            gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1267 1268 1269
            break;
        case 0x72:
            /* MSKQH */
A
aurel32 已提交
1270
            gen_arith3(helper_mskqh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1271 1272 1273
            break;
        case 0x77:
            /* INSQH */
A
aurel32 已提交
1274
            gen_arith3(helper_insqh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1275 1276 1277
            break;
        case 0x7A:
            /* EXTQH */
1278
            gen_ext_h(NULL, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1279 1280 1281 1282 1283 1284 1285 1286 1287
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x13:
        switch (fn7) {
        case 0x00:
            /* MULL */
1288
            if (likely(rc != 31)) {
1289
                if (ra == 31)
1290 1291 1292 1293 1294 1295 1296 1297 1298
                    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 已提交
1299 1300 1301
            break;
        case 0x20:
            /* MULQ */
1302
            if (likely(rc != 31)) {
1303
                if (ra == 31)
1304 1305 1306 1307 1308 1309
                    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 已提交
1310 1311 1312
            break;
        case 0x30:
            /* UMULH */
A
aurel32 已提交
1313
            gen_arith3(helper_umulh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1314 1315 1316
            break;
        case 0x40:
            /* MULL/V */
A
aurel32 已提交
1317
            gen_arith3(helper_mullv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1318 1319 1320
            break;
        case 0x60:
            /* MULQ/V */
A
aurel32 已提交
1321
            gen_arith3(helper_mulqv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x14:
        switch (fpfn) { /* f11 & 0x3F */
        case 0x04:
            /* ITOFS */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1333 1334 1335 1336 1337 1338 1339 1340 1341
            if (likely(rc != 31)) {
                if (ra != 31) {
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I32);
                    tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
                    tcg_gen_helper_1_1(helper_memory_to_s, cpu_fir[rc], tmp);
                    tcg_temp_free(tmp);
                } else
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
            }
J
j_mayer 已提交
1342 1343 1344 1345 1346
            break;
        case 0x0A:
            /* SQRTF */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1347
            gen_farith2(&helper_sqrtf, rb, rc);
J
j_mayer 已提交
1348 1349 1350 1351 1352
            break;
        case 0x0B:
            /* SQRTS */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1353
            gen_farith2(&helper_sqrts, rb, rc);
J
j_mayer 已提交
1354 1355 1356 1357 1358
            break;
        case 0x14:
            /* ITOFF */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1359 1360 1361 1362 1363 1364 1365 1366 1367
            if (likely(rc != 31)) {
                if (ra != 31) {
                    TCGv tmp = tcg_temp_new(TCG_TYPE_I32);
                    tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
                    tcg_gen_helper_1_1(helper_memory_to_f, cpu_fir[rc], tmp);
                    tcg_temp_free(tmp);
                } else
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
            }
J
j_mayer 已提交
1368 1369 1370 1371 1372
            break;
        case 0x24:
            /* ITOFT */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1373 1374 1375 1376 1377 1378
            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 已提交
1379 1380 1381 1382 1383
            break;
        case 0x2A:
            /* SQRTG */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1384
            gen_farith2(&helper_sqrtg, rb, rc);
J
j_mayer 已提交
1385 1386 1387 1388 1389
            break;
        case 0x02B:
            /* SQRTT */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1390
            gen_farith2(&helper_sqrtt, rb, rc);
J
j_mayer 已提交
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x15:
        /* VAX floating point */
        /* XXX: rounding mode and trap are ignored (!) */
        switch (fpfn) { /* f11 & 0x3F */
        case 0x00:
            /* ADDF */
A
aurel32 已提交
1402
            gen_farith3(&helper_addf, ra, rb, rc);
J
j_mayer 已提交
1403 1404 1405
            break;
        case 0x01:
            /* SUBF */
A
aurel32 已提交
1406
            gen_farith3(&helper_subf, ra, rb, rc);
J
j_mayer 已提交
1407 1408 1409
            break;
        case 0x02:
            /* MULF */
A
aurel32 已提交
1410
            gen_farith3(&helper_mulf, ra, rb, rc);
J
j_mayer 已提交
1411 1412 1413
            break;
        case 0x03:
            /* DIVF */
A
aurel32 已提交
1414
            gen_farith3(&helper_divf, ra, rb, rc);
J
j_mayer 已提交
1415 1416 1417 1418
            break;
        case 0x1E:
            /* CVTDG */
#if 0 // TODO
A
aurel32 已提交
1419
            gen_farith2(&helper_cvtdg, rb, rc);
J
j_mayer 已提交
1420 1421 1422 1423 1424 1425
#else
            goto invalid_opc;
#endif
            break;
        case 0x20:
            /* ADDG */
A
aurel32 已提交
1426
            gen_farith3(&helper_addg, ra, rb, rc);
J
j_mayer 已提交
1427 1428 1429
            break;
        case 0x21:
            /* SUBG */
A
aurel32 已提交
1430
            gen_farith3(&helper_subg, ra, rb, rc);
J
j_mayer 已提交
1431 1432 1433
            break;
        case 0x22:
            /* MULG */
A
aurel32 已提交
1434
            gen_farith3(&helper_mulg, ra, rb, rc);
J
j_mayer 已提交
1435 1436 1437
            break;
        case 0x23:
            /* DIVG */
A
aurel32 已提交
1438
            gen_farith3(&helper_divg, ra, rb, rc);
J
j_mayer 已提交
1439 1440 1441
            break;
        case 0x25:
            /* CMPGEQ */
A
aurel32 已提交
1442
            gen_farith3(&helper_cmpgeq, ra, rb, rc);
J
j_mayer 已提交
1443 1444 1445
            break;
        case 0x26:
            /* CMPGLT */
A
aurel32 已提交
1446
            gen_farith3(&helper_cmpglt, ra, rb, rc);
J
j_mayer 已提交
1447 1448 1449
            break;
        case 0x27:
            /* CMPGLE */
A
aurel32 已提交
1450
            gen_farith3(&helper_cmpgle, ra, rb, rc);
J
j_mayer 已提交
1451 1452 1453
            break;
        case 0x2C:
            /* CVTGF */
A
aurel32 已提交
1454
            gen_farith2(&helper_cvtgf, rb, rc);
J
j_mayer 已提交
1455 1456 1457 1458
            break;
        case 0x2D:
            /* CVTGD */
#if 0 // TODO
A
aurel32 已提交
1459
            gen_farith2(ctx, &helper_cvtgd, rb, rc);
J
j_mayer 已提交
1460 1461 1462 1463 1464 1465
#else
            goto invalid_opc;
#endif
            break;
        case 0x2F:
            /* CVTGQ */
A
aurel32 已提交
1466
            gen_farith2(&helper_cvtgq, rb, rc);
J
j_mayer 已提交
1467 1468 1469
            break;
        case 0x3C:
            /* CVTQF */
A
aurel32 已提交
1470
            gen_farith2(&helper_cvtqf, rb, rc);
J
j_mayer 已提交
1471 1472 1473
            break;
        case 0x3E:
            /* CVTQG */
A
aurel32 已提交
1474
            gen_farith2(&helper_cvtqg, rb, rc);
J
j_mayer 已提交
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x16:
        /* IEEE floating-point */
        /* XXX: rounding mode and traps are ignored (!) */
        switch (fpfn) { /* f11 & 0x3F */
        case 0x00:
            /* ADDS */
A
aurel32 已提交
1486
            gen_farith3(&helper_adds, ra, rb, rc);
J
j_mayer 已提交
1487 1488 1489
            break;
        case 0x01:
            /* SUBS */
A
aurel32 已提交
1490
            gen_farith3(&helper_subs, ra, rb, rc);
J
j_mayer 已提交
1491 1492 1493
            break;
        case 0x02:
            /* MULS */
A
aurel32 已提交
1494
            gen_farith3(&helper_muls, ra, rb, rc);
J
j_mayer 已提交
1495 1496 1497
            break;
        case 0x03:
            /* DIVS */
A
aurel32 已提交
1498
            gen_farith3(&helper_divs, ra, rb, rc);
J
j_mayer 已提交
1499 1500 1501
            break;
        case 0x20:
            /* ADDT */
A
aurel32 已提交
1502
            gen_farith3(&helper_addt, ra, rb, rc);
J
j_mayer 已提交
1503 1504 1505
            break;
        case 0x21:
            /* SUBT */
A
aurel32 已提交
1506
            gen_farith3(&helper_subt, ra, rb, rc);
J
j_mayer 已提交
1507 1508 1509
            break;
        case 0x22:
            /* MULT */
A
aurel32 已提交
1510
            gen_farith3(&helper_mult, ra, rb, rc);
J
j_mayer 已提交
1511 1512 1513
            break;
        case 0x23:
            /* DIVT */
A
aurel32 已提交
1514
            gen_farith3(&helper_divt, ra, rb, rc);
J
j_mayer 已提交
1515 1516 1517
            break;
        case 0x24:
            /* CMPTUN */
A
aurel32 已提交
1518
            gen_farith3(&helper_cmptun, ra, rb, rc);
J
j_mayer 已提交
1519 1520 1521
            break;
        case 0x25:
            /* CMPTEQ */
A
aurel32 已提交
1522
            gen_farith3(&helper_cmpteq, ra, rb, rc);
J
j_mayer 已提交
1523 1524 1525
            break;
        case 0x26:
            /* CMPTLT */
A
aurel32 已提交
1526
            gen_farith3(&helper_cmptlt, ra, rb, rc);
J
j_mayer 已提交
1527 1528 1529
            break;
        case 0x27:
            /* CMPTLE */
A
aurel32 已提交
1530
            gen_farith3(&helper_cmptle, ra, rb, rc);
J
j_mayer 已提交
1531 1532 1533 1534 1535
            break;
        case 0x2C:
            /* XXX: incorrect */
            if (fn11 == 0x2AC) {
                /* CVTST */
A
aurel32 已提交
1536
                gen_farith2(&helper_cvtst, rb, rc);
J
j_mayer 已提交
1537 1538
            } else {
                /* CVTTS */
A
aurel32 已提交
1539
                gen_farith2(&helper_cvtts, rb, rc);
J
j_mayer 已提交
1540 1541 1542 1543
            }
            break;
        case 0x2F:
            /* CVTTQ */
A
aurel32 已提交
1544
            gen_farith2(&helper_cvttq, rb, rc);
J
j_mayer 已提交
1545 1546 1547
            break;
        case 0x3C:
            /* CVTQS */
A
aurel32 已提交
1548
            gen_farith2(&helper_cvtqs, rb, rc);
J
j_mayer 已提交
1549 1550 1551
            break;
        case 0x3E:
            /* CVTQT */
A
aurel32 已提交
1552
            gen_farith2(&helper_cvtqt, rb, rc);
J
j_mayer 已提交
1553 1554 1555 1556 1557 1558 1559 1560 1561
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x17:
        switch (fn11) {
        case 0x010:
            /* CVTLQ */
A
aurel32 已提交
1562
            gen_farith2(&helper_cvtlq, rb, rc);
J
j_mayer 已提交
1563 1564
            break;
        case 0x020:
A
aurel32 已提交
1565 1566
            if (likely(rc != 31)) {
                if (ra == rb)
J
j_mayer 已提交
1567
                    /* FMOV */
A
aurel32 已提交
1568 1569 1570 1571
                    tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
                else
                    /* CPYS */
                    gen_farith3(&helper_cpys, ra, rb, rc);
J
j_mayer 已提交
1572 1573 1574 1575
            }
            break;
        case 0x021:
            /* CPYSN */
A
aurel32 已提交
1576
            gen_farith3(&helper_cpysn, ra, rb, rc);
J
j_mayer 已提交
1577 1578 1579
            break;
        case 0x022:
            /* CPYSE */
A
aurel32 已提交
1580
            gen_farith3(&helper_cpyse, ra, rb, rc);
J
j_mayer 已提交
1581 1582 1583
            break;
        case 0x024:
            /* MT_FPCR */
A
aurel32 已提交
1584 1585 1586 1587 1588 1589 1590
            if (likely(ra != 31))
                tcg_gen_helper_0_1(helper_store_fpcr, cpu_fir[ra]);
            else {
                TCGv tmp = tcg_const_i64(0);
                tcg_gen_helper_0_1(helper_store_fpcr, tmp);
                tcg_temp_free(tmp);
            }
J
j_mayer 已提交
1591 1592 1593
            break;
        case 0x025:
            /* MF_FPCR */
A
aurel32 已提交
1594 1595
            if (likely(ra != 31))
                tcg_gen_helper_1_0(helper_load_fpcr, cpu_fir[ra]);
J
j_mayer 已提交
1596 1597 1598
            break;
        case 0x02A:
            /* FCMOVEQ */
A
aurel32 已提交
1599
            gen_fcmov(&helper_cmpfeq, ra, rb, rc);
J
j_mayer 已提交
1600 1601 1602
            break;
        case 0x02B:
            /* FCMOVNE */
A
aurel32 已提交
1603
            gen_fcmov(&helper_cmpfne, ra, rb, rc);
J
j_mayer 已提交
1604 1605 1606
            break;
        case 0x02C:
            /* FCMOVLT */
A
aurel32 已提交
1607
            gen_fcmov(&helper_cmpflt, ra, rb, rc);
J
j_mayer 已提交
1608 1609 1610
            break;
        case 0x02D:
            /* FCMOVGE */
A
aurel32 已提交
1611
            gen_fcmov(&helper_cmpfge, ra, rb, rc);
J
j_mayer 已提交
1612 1613 1614
            break;
        case 0x02E:
            /* FCMOVLE */
A
aurel32 已提交
1615
            gen_fcmov(&helper_cmpfle, ra, rb, rc);
J
j_mayer 已提交
1616 1617 1618
            break;
        case 0x02F:
            /* FCMOVGT */
A
aurel32 已提交
1619
            gen_fcmov(&helper_cmpfgt, ra, rb, rc);
J
j_mayer 已提交
1620 1621 1622
            break;
        case 0x030:
            /* CVTQL */
A
aurel32 已提交
1623
            gen_farith2(&helper_cvtql, rb, rc);
J
j_mayer 已提交
1624 1625 1626
            break;
        case 0x130:
            /* CVTQL/V */
A
aurel32 已提交
1627
            gen_farith2(&helper_cvtqlv, rb, rc);
J
j_mayer 已提交
1628 1629 1630
            break;
        case 0x530:
            /* CVTQL/SV */
A
aurel32 已提交
1631
            gen_farith2(&helper_cvtqlsv, rb, rc);
J
j_mayer 已提交
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x18:
        switch ((uint16_t)disp16) {
        case 0x0000:
            /* TRAPB */
            /* No-op. Just exit from the current tb */
            ret = 2;
            break;
        case 0x0400:
            /* EXCB */
            /* No-op. Just exit from the current tb */
            ret = 2;
            break;
        case 0x4000:
            /* MB */
            /* No-op */
            break;
        case 0x4400:
            /* WMB */
            /* No-op */
            break;
        case 0x8000:
            /* FETCH */
            /* No-op */
            break;
        case 0xA000:
            /* FETCH_M */
            /* No-op */
            break;
        case 0xC000:
            /* RPCC */
A
aurel32 已提交
1667
            if (ra != 31)
1668
                tcg_gen_helper_1_0(helper_load_pcc, cpu_ir[ra]);
J
j_mayer 已提交
1669 1670 1671
            break;
        case 0xE000:
            /* RC */
A
aurel32 已提交
1672
            if (ra != 31)
1673
                tcg_gen_helper_1_0(helper_rc, cpu_ir[ra]);
J
j_mayer 已提交
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
            break;
        case 0xE800:
            /* ECB */
            /* XXX: TODO: evict tb cache at address rb */
#if 0
            ret = 2;
#else
            goto invalid_opc;
#endif
            break;
        case 0xF000:
            /* RS */
A
aurel32 已提交
1686
            if (ra != 31)
1687
                tcg_gen_helper_1_0(helper_rs, cpu_ir[ra]);
J
j_mayer 已提交
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
            break;
        case 0xF800:
            /* WH64 */
            /* No-op */
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x19:
        /* HW_MFPR (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
        gen_op_mfpr(insn & 0xFF);
A
aurel32 已提交
1705 1706
        if (ra != 31)
            tcg_gen_mov_i64(cpu_ir[ra], cpu_T[0]);
J
j_mayer 已提交
1707 1708 1709
        break;
#endif
    case 0x1A:
A
aurel32 已提交
1710 1711 1712 1713 1714 1715
        if (ra != 31)
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
        if (rb != 31)
            tcg_gen_andi_i64(cpu_pc, cpu_ir[rb], ~3);
        else
            tcg_gen_movi_i64(cpu_pc, 0);
J
j_mayer 已提交
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
        /* Those four jumps only differ by the branch prediction hint */
        switch (fn2) {
        case 0x0:
            /* JMP */
            break;
        case 0x1:
            /* JSR */
            break;
        case 0x2:
            /* RET */
            break;
        case 0x3:
            /* JSR_COROUTINE */
            break;
        }
        ret = 1;
        break;
    case 0x1B:
        /* HW_LD (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
A
aurel32 已提交
1740 1741 1742 1743 1744
        if (rb != 31)
            tcg_gen_mov_i64(cpu_T[0], cpu_ir[rb]);
        else
            tcg_gen_movi_i64(cpu_T[0], 0);
        tcg_gen_movi_i64(cpu_T[1], disp12);
1745
        tcg_gen_add_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
J
j_mayer 已提交
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825
        switch ((insn >> 12) & 0xF) {
        case 0x0:
            /* Longword physical access */
            gen_op_ldl_raw();
            break;
        case 0x1:
            /* Quadword physical access */
            gen_op_ldq_raw();
            break;
        case 0x2:
            /* Longword physical access with lock */
            gen_op_ldl_l_raw();
            break;
        case 0x3:
            /* Quadword physical access with lock */
            gen_op_ldq_l_raw();
            break;
        case 0x4:
            /* Longword virtual PTE fetch */
            gen_op_ldl_kernel();
            break;
        case 0x5:
            /* Quadword virtual PTE fetch */
            gen_op_ldq_kernel();
            break;
        case 0x6:
            /* Invalid */
            goto invalid_opc;
        case 0x7:
            /* Invalid */
            goto invalid_opc;
        case 0x8:
            /* Longword virtual access */
            gen_op_ld_phys_to_virt();
            gen_op_ldl_raw();
            break;
        case 0x9:
            /* Quadword virtual access */
            gen_op_ld_phys_to_virt();
            gen_op_ldq_raw();
            break;
        case 0xA:
            /* Longword virtual access with protection check */
            gen_ldl(ctx);
            break;
        case 0xB:
            /* Quadword virtual access with protection check */
            gen_ldq(ctx);
            break;
        case 0xC:
            /* Longword virtual access with altenate access mode */
            gen_op_set_alt_mode();
            gen_op_ld_phys_to_virt();
            gen_op_ldl_raw();
            gen_op_restore_mode();
            break;
        case 0xD:
            /* Quadword virtual access with altenate access mode */
            gen_op_set_alt_mode();
            gen_op_ld_phys_to_virt();
            gen_op_ldq_raw();
            gen_op_restore_mode();
            break;
        case 0xE:
            /* Longword virtual access with alternate access mode and
             * protection checks
             */
            gen_op_set_alt_mode();
            gen_op_ldl_data();
            gen_op_restore_mode();
            break;
        case 0xF:
            /* Quadword virtual access with alternate access mode and
             * protection checks
             */
            gen_op_set_alt_mode();
            gen_op_ldq_data();
            gen_op_restore_mode();
            break;
        }
A
aurel32 已提交
1826 1827
        if (ra != 31)
            tcg_gen_mov_i64(cpu_ir[ra], cpu_T[1]);
J
j_mayer 已提交
1828 1829 1830 1831 1832 1833 1834 1835
        break;
#endif
    case 0x1C:
        switch (fn7) {
        case 0x00:
            /* SEXTB */
            if (!(ctx->amask & AMASK_BWX))
                goto invalid_opc;
1836 1837 1838 1839
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int8_t)lit));
                else
1840
                    tcg_gen_ext8s_i64(cpu_ir[rc], cpu_ir[rb]);
1841
            }
J
j_mayer 已提交
1842 1843 1844 1845 1846
            break;
        case 0x01:
            /* SEXTW */
            if (!(ctx->amask & AMASK_BWX))
                goto invalid_opc;
1847 1848 1849 1850
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
                else
1851
                    tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
1852
            }
J
j_mayer 已提交
1853 1854 1855 1856 1857
            break;
        case 0x30:
            /* CTPOP */
            if (!(ctx->amask & AMASK_CIX))
                goto invalid_opc;
1858 1859 1860 1861
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
                else
1862
                    tcg_gen_helper_1_1(helper_ctpop, cpu_ir[rc], cpu_ir[rb]);
1863
            }
J
j_mayer 已提交
1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875
            break;
        case 0x31:
            /* PERR */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x32:
            /* CTLZ */
            if (!(ctx->amask & AMASK_CIX))
                goto invalid_opc;
1876 1877 1878 1879
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
                else
1880
                    tcg_gen_helper_1_1(helper_ctlz, cpu_ir[rc], cpu_ir[rb]);
1881
            }
J
j_mayer 已提交
1882 1883 1884 1885 1886
            break;
        case 0x33:
            /* CTTZ */
            if (!(ctx->amask & AMASK_CIX))
                goto invalid_opc;
1887 1888 1889 1890
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
                else
1891
                    tcg_gen_helper_1_1(helper_cttz, cpu_ir[rc], cpu_ir[rb]);
1892
            }
J
j_mayer 已提交
1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981
            break;
        case 0x34:
            /* UNPKBW */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x35:
            /* UNPKWL */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x36:
            /* PKWB */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x37:
            /* PKLB */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x38:
            /* MINSB8 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x39:
            /* MINSW4 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3A:
            /* MINUB8 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3B:
            /* MINUW4 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3C:
            /* MAXUB8 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3D:
            /* MAXUW4 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3E:
            /* MAXSB8 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x3F:
            /* MAXSW4 */
            if (!(ctx->amask & AMASK_MVI))
                goto invalid_opc;
            /* XXX: TODO */
            goto invalid_opc;
            break;
        case 0x70:
            /* FTOIT */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1982 1983 1984 1985 1986 1987
            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 已提交
1988 1989 1990 1991 1992
            break;
        case 0x78:
            /* FTOIS */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004
            if (rc != 31) {
                TCGv tmp1 = tcg_temp_new(TCG_TYPE_I32);
                if (ra != 31)
                    tcg_gen_helper_1_1(helper_s_to_memory, tmp1, cpu_fir[ra]);
                else {
                    TCGv tmp2 = tcg_const_i64(0);
                    tcg_gen_helper_1_1(helper_s_to_memory, tmp1, tmp2);
                    tcg_temp_free(tmp2);
                }
                tcg_gen_ext_i32_i64(cpu_ir[rc], tmp1);
                tcg_temp_free(tmp1);
            }
J
j_mayer 已提交
2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x1D:
        /* HW_MTPR (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
A
aurel32 已提交
2017 2018 2019 2020
        if (ra != 31)
            tcg_gen_mov_i64(cpu_T[0], cpu_ir[ra]);
        else
            tcg_gen_movi_i64(cpu_T[0], 0);
J
j_mayer 已提交
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035
        gen_op_mtpr(insn & 0xFF);
        ret = 2;
        break;
#endif
    case 0x1E:
        /* HW_REI (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
        if (rb == 31) {
            /* "Old" alpha */
            gen_op_hw_rei();
        } else {
A
aurel32 已提交
2036 2037 2038 2039 2040
            if (ra != 31)
                tcg_gen_mov_i64(cpu_T[0], cpu_ir[rb]);
            else
                tcg_gen_movi_i64(cpu_T[0], 0);
            tcg_gen_movi_i64(cpu_T[1], (((int64_t)insn << 51) >> 51));
2041
            tcg_gen_add_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
J
j_mayer 已提交
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053
            gen_op_hw_ret();
        }
        ret = 2;
        break;
#endif
    case 0x1F:
        /* HW_ST (PALcode) */
#if defined (CONFIG_USER_ONLY)
        goto invalid_opc;
#else
        if (!ctx->pal_mode)
            goto invalid_opc;
A
aurel32 已提交
2054
        if (ra != 31)
2055
            tcg_gen_addi_i64(cpu_T[0], cpu_ir[rb], disp12);
A
aurel32 已提交
2056
        else
2057
            tcg_gen_movi_i64(cpu_T[0], disp12);
A
aurel32 已提交
2058 2059 2060 2061
        if (ra != 31)
            tcg_gen_mov_i64(cpu_T[1], cpu_ir[ra]);
        else
            tcg_gen_movi_i64(cpu_T[1], 0);
J
j_mayer 已提交
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
        switch ((insn >> 12) & 0xF) {
        case 0x0:
            /* Longword physical access */
            gen_op_stl_raw();
            break;
        case 0x1:
            /* Quadword physical access */
            gen_op_stq_raw();
            break;
        case 0x2:
            /* Longword physical access with lock */
            gen_op_stl_c_raw();
            break;
        case 0x3:
            /* Quadword physical access with lock */
            gen_op_stq_c_raw();
            break;
        case 0x4:
            /* Longword virtual access */
            gen_op_st_phys_to_virt();
            gen_op_stl_raw();
            break;
        case 0x5:
            /* Quadword virtual access */
            gen_op_st_phys_to_virt();
            gen_op_stq_raw();
            break;
        case 0x6:
            /* Invalid */
            goto invalid_opc;
        case 0x7:
            /* Invalid */
            goto invalid_opc;
        case 0x8:
            /* Invalid */
            goto invalid_opc;
        case 0x9:
            /* Invalid */
            goto invalid_opc;
        case 0xA:
            /* Invalid */
            goto invalid_opc;
        case 0xB:
            /* Invalid */
            goto invalid_opc;
        case 0xC:
            /* Longword virtual access with alternate access mode */
            gen_op_set_alt_mode();
            gen_op_st_phys_to_virt();
            gen_op_ldl_raw();
            gen_op_restore_mode();
            break;
        case 0xD:
            /* Quadword virtual access with alternate access mode */
            gen_op_set_alt_mode();
            gen_op_st_phys_to_virt();
            gen_op_ldq_raw();
            gen_op_restore_mode();
            break;
        case 0xE:
            /* Invalid */
            goto invalid_opc;
        case 0xF:
            /* Invalid */
            goto invalid_opc;
        }
        ret = 2;
        break;
#endif
    case 0x20:
        /* LDF */
A
aurel32 已提交
2133
        gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2134 2135 2136
        break;
    case 0x21:
        /* LDG */
A
aurel32 已提交
2137
        gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2138 2139 2140
        break;
    case 0x22:
        /* LDS */
A
aurel32 已提交
2141
        gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2142 2143 2144
        break;
    case 0x23:
        /* LDT */
A
aurel32 已提交
2145
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2146 2147 2148
        break;
    case 0x24:
        /* STF */
A
aurel32 已提交
2149
        gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2150 2151 2152
        break;
    case 0x25:
        /* STG */
A
aurel32 已提交
2153
        gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2154 2155 2156
        break;
    case 0x26:
        /* STS */
A
aurel32 已提交
2157
        gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2158 2159 2160
        break;
    case 0x27:
        /* STT */
A
aurel32 已提交
2161
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2162 2163 2164
        break;
    case 0x28:
        /* LDL */
A
aurel32 已提交
2165
        gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2166 2167 2168
        break;
    case 0x29:
        /* LDQ */
A
aurel32 已提交
2169
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2170 2171 2172
        break;
    case 0x2A:
        /* LDL_L */
2173
        gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2174 2175 2176
        break;
    case 0x2B:
        /* LDQ_L */
2177
        gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2178 2179 2180
        break;
    case 0x2C:
        /* STL */
A
aurel32 已提交
2181
        gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2182 2183 2184
        break;
    case 0x2D:
        /* STQ */
A
aurel32 已提交
2185
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2186 2187 2188
        break;
    case 0x2E:
        /* STL_C */
2189
        gen_store_mem(ctx, &gen_qemu_stl_c, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2190 2191 2192
        break;
    case 0x2F:
        /* STQ_C */
2193
        gen_store_mem(ctx, &gen_qemu_stq_c, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2194 2195 2196
        break;
    case 0x30:
        /* BR */
A
aurel32 已提交
2197 2198 2199
        if (ra != 31)
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
        tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp21 << 2));
J
j_mayer 已提交
2200 2201 2202 2203
        ret = 1;
        break;
    case 0x31:
        /* FBEQ */
A
aurel32 已提交
2204
        gen_fbcond(ctx, &helper_cmpfeq, ra, disp16);
J
j_mayer 已提交
2205 2206 2207 2208
        ret = 1;
        break;
    case 0x32:
        /* FBLT */
A
aurel32 已提交
2209
        gen_fbcond(ctx, &helper_cmpflt, ra, disp16);
J
j_mayer 已提交
2210 2211 2212 2213
        ret = 1;
        break;
    case 0x33:
        /* FBLE */
A
aurel32 已提交
2214
        gen_fbcond(ctx, &helper_cmpfle, ra, disp16);
J
j_mayer 已提交
2215 2216 2217 2218
        ret = 1;
        break;
    case 0x34:
        /* BSR */
A
aurel32 已提交
2219 2220 2221
        if (ra != 31)
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
        tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp21 << 2));
J
j_mayer 已提交
2222 2223 2224 2225
        ret = 1;
        break;
    case 0x35:
        /* FBNE */
A
aurel32 已提交
2226
        gen_fbcond(ctx, &helper_cmpfne, ra, disp16);
J
j_mayer 已提交
2227 2228 2229 2230
        ret = 1;
        break;
    case 0x36:
        /* FBGE */
A
aurel32 已提交
2231
        gen_fbcond(ctx, &helper_cmpfge, ra, disp16);
J
j_mayer 已提交
2232 2233 2234 2235
        ret = 1;
        break;
    case 0x37:
        /* FBGT */
A
aurel32 已提交
2236
        gen_fbcond(ctx, &helper_cmpfgt, ra, disp16);
J
j_mayer 已提交
2237 2238 2239 2240
        ret = 1;
        break;
    case 0x38:
        /* BLBC */
A
aurel32 已提交
2241
        gen_bcond(ctx, TCG_COND_EQ, ra, disp16, 1);
J
j_mayer 已提交
2242 2243 2244 2245
        ret = 1;
        break;
    case 0x39:
        /* BEQ */
A
aurel32 已提交
2246
        gen_bcond(ctx, TCG_COND_EQ, ra, disp16, 0);
J
j_mayer 已提交
2247 2248 2249 2250
        ret = 1;
        break;
    case 0x3A:
        /* BLT */
A
aurel32 已提交
2251
        gen_bcond(ctx, TCG_COND_LT, ra, disp16, 0);
J
j_mayer 已提交
2252 2253 2254 2255
        ret = 1;
        break;
    case 0x3B:
        /* BLE */
A
aurel32 已提交
2256
        gen_bcond(ctx, TCG_COND_LE, ra, disp16, 0);
J
j_mayer 已提交
2257 2258 2259 2260
        ret = 1;
        break;
    case 0x3C:
        /* BLBS */
A
aurel32 已提交
2261
        gen_bcond(ctx, TCG_COND_NE, ra, disp16, 1);
J
j_mayer 已提交
2262 2263 2264 2265
        ret = 1;
        break;
    case 0x3D:
        /* BNE */
A
aurel32 已提交
2266
        gen_bcond(ctx, TCG_COND_NE, ra, disp16, 0);
J
j_mayer 已提交
2267 2268 2269 2270
        ret = 1;
        break;
    case 0x3E:
        /* BGE */
A
aurel32 已提交
2271
        gen_bcond(ctx, TCG_COND_GE, ra, disp16, 0);
J
j_mayer 已提交
2272 2273 2274 2275
        ret = 1;
        break;
    case 0x3F:
        /* BGT */
A
aurel32 已提交
2276
        gen_bcond(ctx, TCG_COND_GT, ra, disp16, 0);
J
j_mayer 已提交
2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287
        ret = 1;
        break;
    invalid_opc:
        gen_invalid(ctx);
        ret = 3;
        break;
    }

    return ret;
}

2288 2289 2290
static always_inline void gen_intermediate_code_internal (CPUState *env,
                                                          TranslationBlock *tb,
                                                          int search_pc)
J
j_mayer 已提交
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300
{
#if defined ALPHA_DEBUG_DISAS
    static int insn_count;
#endif
    DisasContext ctx, *ctxp = &ctx;
    target_ulong pc_start;
    uint32_t insn;
    uint16_t *gen_opc_end;
    int j, lj = -1;
    int ret;
P
pbrook 已提交
2301 2302
    int num_insns;
    int max_insns;
J
j_mayer 已提交
2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313

    pc_start = tb->pc;
    gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
    ctx.pc = pc_start;
    ctx.amask = env->amask;
#if defined (CONFIG_USER_ONLY)
    ctx.mem_idx = 0;
#else
    ctx.mem_idx = ((env->ps >> 3) & 3);
    ctx.pal_mode = env->ipr[IPR_EXC_ADDR] & 1;
#endif
P
pbrook 已提交
2314 2315 2316 2317 2318 2319
    num_insns = 0;
    max_insns = tb->cflags & CF_COUNT_MASK;
    if (max_insns == 0)
        max_insns = CF_COUNT_MASK;

    gen_icount_start();
J
j_mayer 已提交
2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336
    for (ret = 0; ret == 0;) {
        if (env->nb_breakpoints > 0) {
            for(j = 0; j < env->nb_breakpoints; j++) {
                if (env->breakpoints[j] == ctx.pc) {
                    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;
                gen_opc_pc[lj] = ctx.pc;
                gen_opc_instr_start[lj] = 1;
P
pbrook 已提交
2337
                gen_opc_icount[lj] = num_insns;
J
j_mayer 已提交
2338 2339
            }
        }
P
pbrook 已提交
2340 2341
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
            gen_io_start();
J
j_mayer 已提交
2342 2343 2344
#if defined ALPHA_DEBUG_DISAS
        insn_count++;
        if (logfile != NULL) {
2345 2346
            fprintf(logfile, "pc " TARGET_FMT_lx " mem_idx %d\n",
                    ctx.pc, ctx.mem_idx);
J
j_mayer 已提交
2347 2348 2349 2350 2351 2352 2353 2354 2355
        }
#endif
        insn = ldl_code(ctx.pc);
#if defined ALPHA_DEBUG_DISAS
        insn_count++;
        if (logfile != NULL) {
            fprintf(logfile, "opcode %08x %d\n", insn, insn_count);
        }
#endif
P
pbrook 已提交
2356
        num_insns++;
J
j_mayer 已提交
2357 2358 2359 2360 2361 2362 2363 2364
        ctx.pc += 4;
        ret = translate_one(ctxp, insn);
        if (ret != 0)
            break;
        /* if we reach a page boundary or are single stepping, stop
         * generation
         */
        if (((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) ||
P
pbrook 已提交
2365 2366
            (env->singlestep_enabled) ||
            num_insns >= max_insns) {
J
j_mayer 已提交
2367 2368 2369 2370 2371 2372 2373
            break;
        }
#if defined (DO_SINGLE_STEP)
        break;
#endif
    }
    if (ret != 1 && ret != 3) {
A
aurel32 已提交
2374
        tcg_gen_movi_i64(cpu_pc, ctx.pc);
J
j_mayer 已提交
2375 2376
    }
#if defined (DO_TB_FLUSH)
A
aurel32 已提交
2377
    tcg_gen_helper_0_0(helper_tb_flush);
J
j_mayer 已提交
2378
#endif
P
pbrook 已提交
2379 2380
    if (tb->cflags & CF_LAST_IO)
        gen_io_end();
J
j_mayer 已提交
2381
    /* Generate the return instruction */
B
bellard 已提交
2382
    tcg_gen_exit_tb(0);
P
pbrook 已提交
2383
    gen_icount_end(tb, num_insns);
J
j_mayer 已提交
2384 2385 2386 2387 2388 2389 2390 2391
    *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 已提交
2392
        tb->icount = num_insns;
J
j_mayer 已提交
2393 2394 2395 2396 2397 2398 2399
    }
#if defined ALPHA_DEBUG_DISAS
    if (loglevel & CPU_LOG_TB_CPU) {
        cpu_dump_state(env, logfile, fprintf, 0);
    }
    if (loglevel & CPU_LOG_TB_IN_ASM) {
        fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
A
aurel32 已提交
2400
        target_disas(logfile, pc_start, ctx.pc - pc_start, 1);
J
j_mayer 已提交
2401 2402 2403 2404 2405
        fprintf(logfile, "\n");
    }
#endif
}

2406
void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
J
j_mayer 已提交
2407
{
2408
    gen_intermediate_code_internal(env, tb, 0);
J
j_mayer 已提交
2409 2410
}

2411
void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
J
j_mayer 已提交
2412
{
2413
    gen_intermediate_code_internal(env, tb, 1);
J
j_mayer 已提交
2414 2415
}

B
bellard 已提交
2416
CPUAlphaState * cpu_alpha_init (const char *cpu_model)
J
j_mayer 已提交
2417 2418 2419 2420 2421 2422 2423 2424
{
    CPUAlphaState *env;
    uint64_t hwpcb;

    env = qemu_mallocz(sizeof(CPUAlphaState));
    if (!env)
        return NULL;
    cpu_exec_init(env);
P
pbrook 已提交
2425
    alpha_translate_init();
J
j_mayer 已提交
2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454
    tlb_flush(env, 1);
    /* XXX: should not be hardcoded */
    env->implver = IMPLVER_2106x;
    env->ps = 0x1F00;
#if defined (CONFIG_USER_ONLY)
    env->ps |= 1 << 3;
#endif
    pal_init(env);
    /* Initialize IPR */
    hwpcb = env->ipr[IPR_PCBB];
    env->ipr[IPR_ASN] = 0;
    env->ipr[IPR_ASTEN] = 0;
    env->ipr[IPR_ASTSR] = 0;
    env->ipr[IPR_DATFX] = 0;
    /* XXX: fix this */
    //    env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
    //    env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
    //    env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
    //    env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
    env->ipr[IPR_FEN] = 0;
    env->ipr[IPR_IPL] = 31;
    env->ipr[IPR_MCES] = 0;
    env->ipr[IPR_PERFMON] = 0; /* Implementation specific */
    //    env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
    env->ipr[IPR_SISR] = 0;
    env->ipr[IPR_VIRBND] = -1ULL;

    return env;
}
B
bellard 已提交
2455

A
aurel32 已提交
2456 2457 2458 2459 2460
void gen_pc_load(CPUState *env, TranslationBlock *tb,
                unsigned long searched_pc, int pc_pos, void *puc)
{
    env->pc = gen_opc_pc[pc_pos];
}