translate.c 72.8 KB
Newer Older
J
j_mayer 已提交
1 2
/*
 *  Alpha emulation cpu translation for qemu.
3
 *
J
j_mayer 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 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
/* register names */
A
aurel32 已提交
55
static char cpu_reg_names[10*4+21*5 + 10*5+21*6];
P
pbrook 已提交
56 57 58

#include "gen-icount.h"

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

P
pbrook 已提交
65 66
    if (done_init)
        return;
A
aurel32 已提交
67

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

    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 已提交
75
        p += (i < 10) ? 4 : 5;
A
aurel32 已提交
76 77 78 79 80

        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 已提交
81 82 83 84 85
    }

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

86 87 88
    cpu_lock = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
                                  offsetof(CPUState, lock), "lock");

A
aurel32 已提交
89 90 91 92 93
    /* register helpers */
#undef DEF_HELPER
#define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
#include "helper.h"

P
pbrook 已提交
94 95 96
    done_init = 1;
}

J
j_mayer 已提交
97 98
static always_inline void gen_excp (DisasContext *ctx,
                                    int exception, int error_code)
J
j_mayer 已提交
99
{
100 101
    TCGv tmp1, tmp2;

A
aurel32 已提交
102
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
103 104 105 106 107
    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 已提交
108 109
}

J
j_mayer 已提交
110
static always_inline void gen_invalid (DisasContext *ctx)
J
j_mayer 已提交
111 112 113 114
{
    gen_excp(ctx, EXCP_OPCDEC, 0);
}

A
aurel32 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
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);
}

139 140 141 142 143 144 145 146 147 148 149 150
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);
}

151 152 153
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 已提交
154
                                        int fp, int clear)
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
{
    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 已提交
171 172 173 174
    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);
175 176 177
    tcg_temp_free(addr);
}

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_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);
}

202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
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);
}

234 235 236
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 已提交
237
                                         int fp, int clear)
238 239 240 241 242 243 244 245 246 247 248
{
    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 已提交
249 250 251 252 253 254
    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 {
255 256 257 258 259 260 261
        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 已提交
262
static always_inline void gen_bcond (DisasContext *ctx,
A
aurel32 已提交
263 264
                                     TCGCond cond,
                                     int ra, int32_t disp16, int mask)
J
j_mayer 已提交
265
{
A
aurel32 已提交
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
    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 已提交
289 290
}

J
j_mayer 已提交
291
static always_inline void gen_fbcond (DisasContext *ctx,
A
aurel32 已提交
292
                                      void* func,
J
j_mayer 已提交
293
                                      int ra, int32_t disp16)
J
j_mayer 已提交
294
{
A
aurel32 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    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 已提交
313 314
}

A
aurel32 已提交
315
static always_inline void gen_cmov (TCGCond inv_cond,
J
j_mayer 已提交
316
                                    int ra, int rb, int rc,
317
                                    int islit, uint8_t lit, int mask)
J
j_mayer 已提交
318
{
A
aurel32 已提交
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    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 已提交
341
    if (islit)
A
aurel32 已提交
342
        tcg_gen_movi_i64(cpu_ir[rc], lit);
J
j_mayer 已提交
343
    else
344
        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
A
aurel32 已提交
345
    gen_set_label(l1);
J
j_mayer 已提交
346 347
}

A
aurel32 已提交
348
static always_inline void gen_farith2 (void *helper,
J
j_mayer 已提交
349
                                       int rb, int rc)
J
j_mayer 已提交
350
{
A
aurel32 已提交
351 352 353 354 355 356 357 358 359 360
    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 已提交
361 362
}

A
aurel32 已提交
363
static always_inline void gen_farith3 (void *helper,
J
j_mayer 已提交
364
                                       int ra, int rb, int rc)
J
j_mayer 已提交
365
{
A
aurel32 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
    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 已提交
385 386
}

A
aurel32 已提交
387
static always_inline void gen_fcmov (void *func,
J
j_mayer 已提交
388
                                     int ra, int rb, int rc)
J
j_mayer 已提交
389
{
A
aurel32 已提交
390 391
    int l1;
    TCGv tmp;
J
j_mayer 已提交
392

A
aurel32 已提交
393 394
    if (unlikely(rc == 31))
        return;
J
j_mayer 已提交
395

A
aurel32 已提交
396 397 398 399 400 401 402 403 404 405 406 407
    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 已提交
408
    else
A
aurel32 已提交
409 410
        tcg_gen_movi_i64(cpu_fir[rc], 0);
    gen_set_label(l1);
J
j_mayer 已提交
411 412
}

413 414 415
/* 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,
416
                                    int islit, uint8_t lit)
417 418 419 420 421
{
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
422 423 424 425 426
        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 已提交
427
        } else {
428 429 430 431 432 433 434
            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);
435
            tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], tmp1);
436
            tcg_temp_free(tmp1);
437 438 439
        }
        if (tcg_gen_ext_i64)
            tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
440 441 442 443 444 445 446
    } 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,
447
                                    int islit, uint8_t lit)
448 449 450 451 452
{
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
453 454 455
        if (islit) {
                tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], (lit & 7) * 8);
        } else {
456 457 458
            TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
            tcg_gen_andi_i64(tmp, cpu_ir[rb], 7);
            tcg_gen_shli_i64(tmp, tmp, 3);
459
            tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], tmp);
460
            tcg_temp_free(tmp);
A
aurel32 已提交
461
        }
462 463
        if (tcg_gen_ext_i64)
            tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
464 465 466 467
    } else
        tcg_gen_movi_i64(cpu_ir[rc], 0);
}

468
/* Code to call arith3 helpers */
A
aurel32 已提交
469 470 471
static always_inline void gen_arith3 (void *helper,
                                      int ra, int rb, int rc,
                                      int islit, uint8_t lit)
472 473 474 475 476
{
    if (unlikely(rc == 31))
        return;

    if (ra != 31) {
477 478
        if (islit) {
            TCGv tmp = tcg_const_i64(lit);
479 480 481 482
            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]);
483 484 485 486 487 488 489 490 491 492
    } 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);
    }
493 494
}

495 496
static always_inline void gen_cmp(TCGCond cond,
                                  int ra, int rb, int rc,
497
                                  int islit, uint8_t lit)
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
{
    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
516
        tcg_gen_brcond_i64(cond, tmp, cpu_ir[rb], l1);
517 518 519 520 521 522 523 524

    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 已提交
525
static always_inline int translate_one (DisasContext *ctx, uint32_t insn)
J
j_mayer 已提交
526 527 528 529 530
{
    uint32_t palcode;
    int32_t disp21, disp16, disp12;
    uint16_t fn11, fn16;
    uint8_t opc, ra, rb, rc, sbz, fpfn, fn7, fn2, islit;
531
    uint8_t lit;
J
j_mayer 已提交
532 533 534 535 536 537 538 539 540
    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;
541 542 543 544 545
    if (rb == 31 && !islit) {
        islit = 1;
        lit = 0;
    } else
        lit = (insn >> 13) & 0xFF;
J
j_mayer 已提交
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
    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 已提交
605
        if (likely(ra != 31)) {
A
aurel32 已提交
606
            if (rb != 31)
A
aurel32 已提交
607 608 609
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16);
            else
                tcg_gen_movi_i64(cpu_ir[ra], disp16);
A
aurel32 已提交
610
        }
J
j_mayer 已提交
611 612 613
        break;
    case 0x09:
        /* LDAH */
A
aurel32 已提交
614
        if (likely(ra != 31)) {
A
aurel32 已提交
615
            if (rb != 31)
A
aurel32 已提交
616 617 618
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16 << 16);
            else
                tcg_gen_movi_i64(cpu_ir[ra], disp16 << 16);
A
aurel32 已提交
619
        }
J
j_mayer 已提交
620 621 622 623 624
        break;
    case 0x0A:
        /* LDBU */
        if (!(ctx->amask & AMASK_BWX))
            goto invalid_opc;
A
aurel32 已提交
625
        gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
626 627 628
        break;
    case 0x0B:
        /* LDQ_U */
A
aurel32 已提交
629
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
630 631 632 633 634
        break;
    case 0x0C:
        /* LDWU */
        if (!(ctx->amask & AMASK_BWX))
            goto invalid_opc;
A
aurel32 已提交
635
        gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
636 637 638
        break;
    case 0x0D:
        /* STW */
A
aurel32 已提交
639
        gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
640 641 642
        break;
    case 0x0E:
        /* STB */
A
aurel32 已提交
643
        gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
644 645 646
        break;
    case 0x0F:
        /* STQ_U */
A
aurel32 已提交
647
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1);
J
j_mayer 已提交
648 649 650 651 652
        break;
    case 0x10:
        switch (fn7) {
        case 0x00:
            /* ADDL */
653 654 655 656 657
            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]);
658
                    } else {
659 660
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
661
                    }
662 663
                } else {
                    if (islit)
664
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
665
                    else
666
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
667 668
                }
            }
J
j_mayer 已提交
669 670 671
            break;
        case 0x02:
            /* S4ADDL */
672 673
            if (likely(rc != 31)) {
                if (ra != 31) {
674 675 676 677 678 679 680 681
                    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);
682 683 684 685
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
686
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
687 688
                }
            }
J
j_mayer 已提交
689 690 691
            break;
        case 0x09:
            /* SUBL */
692 693
            if (likely(rc != 31)) {
                if (ra != 31) {
694
                    if (islit)
695
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
696
                    else
697
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
698
                    tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
699 700 701
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
702
                    else {
703 704 705 706
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
                }
            }
J
j_mayer 已提交
707 708 709
            break;
        case 0x0B:
            /* S4SUBL */
710 711
            if (likely(rc != 31)) {
                if (ra != 31) {
712 713 714 715 716 717 718 719
                    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);
720 721 722
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
723
                    else {
724 725
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
726
                    }
727 728
                }
            }
J
j_mayer 已提交
729 730 731
            break;
        case 0x0F:
            /* CMPBGE */
A
aurel32 已提交
732
            gen_arith3(helper_cmpbge, ra, rb, rc, islit, lit);
J
j_mayer 已提交
733 734 735
            break;
        case 0x12:
            /* S8ADDL */
736 737
            if (likely(rc != 31)) {
                if (ra != 31) {
738 739 740 741 742 743 744 745
                    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);
746 747 748 749
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
750
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
751 752
                }
            }
J
j_mayer 已提交
753 754 755
            break;
        case 0x1B:
            /* S8SUBL */
756 757
            if (likely(rc != 31)) {
                if (ra != 31) {
758 759 760 761 762 763 764 765
                    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);
766 767 768
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
769
                    else
770 771
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
772
                    }
773 774
                }
            }
J
j_mayer 已提交
775 776 777
            break;
        case 0x1D:
            /* CMPULT */
778
            gen_cmp(TCG_COND_LTU, ra, rb, rc, islit, lit);
J
j_mayer 已提交
779 780 781
            break;
        case 0x20:
            /* ADDQ */
782 783 784 785 786
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
787
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
788 789 790 791
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
792
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
793 794
                }
            }
J
j_mayer 已提交
795 796 797
            break;
        case 0x22:
            /* S4ADDQ */
798 799
            if (likely(rc != 31)) {
                if (ra != 31) {
800 801 802 803 804 805 806
                    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);
807 808 809 810
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
811
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
812 813
                }
            }
J
j_mayer 已提交
814 815 816
            break;
        case 0x29:
            /* SUBQ */
817 818 819 820 821
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
822
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
823 824 825 826
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
827
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
828 829
                }
            }
J
j_mayer 已提交
830 831 832
            break;
        case 0x2B:
            /* S4SUBQ */
833 834
            if (likely(rc != 31)) {
                if (ra != 31) {
835 836 837 838 839 840 841
                    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);
842 843 844 845
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
846
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
847 848
                }
            }
J
j_mayer 已提交
849 850 851
            break;
        case 0x2D:
            /* CMPEQ */
852
            gen_cmp(TCG_COND_EQ, ra, rb, rc, islit, lit);
J
j_mayer 已提交
853 854 855
            break;
        case 0x32:
            /* S8ADDQ */
856 857
            if (likely(rc != 31)) {
                if (ra != 31) {
858 859 860 861 862 863 864
                    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);
865 866 867 868
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
869
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
870 871
                }
            }
J
j_mayer 已提交
872 873 874
            break;
        case 0x3B:
            /* S8SUBQ */
875 876
            if (likely(rc != 31)) {
                if (ra != 31) {
877 878 879 880 881 882 883
                    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);
884 885 886 887
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
                    else
888
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
889 890
                }
            }
J
j_mayer 已提交
891 892 893
            break;
        case 0x3D:
            /* CMPULE */
894
            gen_cmp(TCG_COND_LEU, ra, rb, rc, islit, lit);
J
j_mayer 已提交
895 896 897
            break;
        case 0x40:
            /* ADDL/V */
A
aurel32 已提交
898
            gen_arith3(helper_addlv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
899 900 901
            break;
        case 0x49:
            /* SUBL/V */
A
aurel32 已提交
902
            gen_arith3(helper_sublv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
903 904 905
            break;
        case 0x4D:
            /* CMPLT */
906
            gen_cmp(TCG_COND_LT, ra, rb, rc, islit, lit);
J
j_mayer 已提交
907 908 909
            break;
        case 0x60:
            /* ADDQ/V */
A
aurel32 已提交
910
            gen_arith3(helper_addqv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
911 912 913
            break;
        case 0x69:
            /* SUBQ/V */
A
aurel32 已提交
914
            gen_arith3(helper_subqv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
915 916 917
            break;
        case 0x6D:
            /* CMPLE */
918
            gen_cmp(TCG_COND_LE, ra, rb, rc, islit, lit);
J
j_mayer 已提交
919 920 921 922 923 924 925 926 927
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x11:
        switch (fn7) {
        case 0x00:
            /* AND */
928
            if (likely(rc != 31)) {
929
                if (ra == 31)
930 931 932 933 934 935
                    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 已提交
936 937 938
            break;
        case 0x08:
            /* BIC */
939 940 941 942
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
943
                    else {
944 945 946 947
                        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);
948
                    }
949 950 951
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
952 953 954
            break;
        case 0x14:
            /* CMOVLBS */
A
aurel32 已提交
955
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 1);
J
j_mayer 已提交
956 957 958
            break;
        case 0x16:
            /* CMOVLBC */
A
aurel32 已提交
959
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 1);
J
j_mayer 已提交
960 961 962
            break;
        case 0x20:
            /* BIS */
963 964 965 966
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], lit);
967
                    else
968
                        tcg_gen_or_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
J
j_mayer 已提交
969
                } else {
970 971 972
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
973
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
J
j_mayer 已提交
974 975 976 977 978
                }
            }
            break;
        case 0x24:
            /* CMOVEQ */
A
aurel32 已提交
979
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
980 981 982
            break;
        case 0x26:
            /* CMOVNE */
A
aurel32 已提交
983
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
984 985 986
            break;
        case 0x28:
            /* ORNOT */
987
            if (likely(rc != 31)) {
988
                if (ra != 31) {
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
                    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 已提交
1004 1005 1006
            break;
        case 0x40:
            /* XOR */
1007 1008 1009 1010 1011
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], lit);
                    else
1012
                        tcg_gen_xor_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1013 1014 1015 1016
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
                    else
1017
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1018 1019
                }
            }
J
j_mayer 已提交
1020 1021 1022
            break;
        case 0x44:
            /* CMOVLT */
A
aurel32 已提交
1023
            gen_cmov(TCG_COND_GE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1024 1025 1026
            break;
        case 0x46:
            /* CMOVGE */
A
aurel32 已提交
1027
            gen_cmov(TCG_COND_LT, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1028 1029 1030
            break;
        case 0x48:
            /* EQV */
1031 1032 1033 1034
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1035
                    else {
1036 1037 1038 1039
                        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);
1040
                    }
1041 1042 1043 1044
                } else {
                    if (islit)
                        tcg_gen_movi_i64(cpu_ir[rc], ~lit);
                    else
1045
                        tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
1046 1047
                }
            }
J
j_mayer 已提交
1048 1049 1050
            break;
        case 0x61:
            /* AMASK */
1051 1052 1053 1054
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], helper_amask(lit));
                else
1055
                    tcg_gen_helper_1_1(helper_amask, cpu_ir[rc], cpu_ir[rb]);
1056
            }
J
j_mayer 已提交
1057 1058 1059
            break;
        case 0x64:
            /* CMOVLE */
A
aurel32 已提交
1060
            gen_cmov(TCG_COND_GT, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1061 1062 1063
            break;
        case 0x66:
            /* CMOVGT */
A
aurel32 已提交
1064
            gen_cmov(TCG_COND_LE, ra, rb, rc, islit, lit, 0);
J
j_mayer 已提交
1065 1066 1067
            break;
        case 0x6C:
            /* IMPLVER */
A
aurel32 已提交
1068
            if (rc != 31)
1069
                tcg_gen_helper_1_0(helper_load_implver, cpu_ir[rc]);
J
j_mayer 已提交
1070 1071 1072 1073 1074 1075 1076 1077 1078
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x12:
        switch (fn7) {
        case 0x02:
            /* MSKBL */
A
aurel32 已提交
1079
            gen_arith3(helper_mskbl, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1080 1081 1082
            break;
        case 0x06:
            /* EXTBL */
1083
            gen_ext_l(&tcg_gen_ext8u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1084 1085 1086
            break;
        case 0x0B:
            /* INSBL */
A
aurel32 已提交
1087
            gen_arith3(helper_insbl, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1088 1089 1090
            break;
        case 0x12:
            /* MSKWL */
A
aurel32 已提交
1091
            gen_arith3(helper_mskwl, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1092 1093 1094
            break;
        case 0x16:
            /* EXTWL */
1095
            gen_ext_l(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1096 1097 1098
            break;
        case 0x1B:
            /* INSWL */
A
aurel32 已提交
1099
            gen_arith3(helper_inswl, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1100 1101 1102
            break;
        case 0x22:
            /* MSKLL */
A
aurel32 已提交
1103
            gen_arith3(helper_mskll, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1104 1105 1106
            break;
        case 0x26:
            /* EXTLL */
1107
            gen_ext_l(&tcg_gen_ext32u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1108 1109 1110
            break;
        case 0x2B:
            /* INSLL */
A
aurel32 已提交
1111
            gen_arith3(helper_insll, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1112 1113 1114
            break;
        case 0x30:
            /* ZAP */
A
aurel32 已提交
1115
            gen_arith3(helper_zap, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1116 1117 1118
            break;
        case 0x31:
            /* ZAPNOT */
A
aurel32 已提交
1119
            gen_arith3(helper_zapnot, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1120 1121 1122
            break;
        case 0x32:
            /* MSKQL */
A
aurel32 已提交
1123
            gen_arith3(helper_mskql, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1124 1125 1126
            break;
        case 0x34:
            /* SRL */
1127 1128 1129 1130
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1131
                    else {
1132 1133 1134 1135
                        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);
1136
                    }
1137 1138 1139
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1140 1141 1142
            break;
        case 0x36:
            /* EXTQL */
1143
            gen_ext_l(NULL, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1144 1145 1146
            break;
        case 0x39:
            /* SLL */
1147 1148 1149 1150
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1151
                    else {
1152 1153 1154 1155
                        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);
1156
                    }
1157 1158 1159
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1160 1161 1162
            break;
        case 0x3B:
            /* INSQL */
A
aurel32 已提交
1163
            gen_arith3(helper_insql, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1164 1165 1166
            break;
        case 0x3C:
            /* SRA */
1167 1168 1169 1170
            if (likely(rc != 31)) {
                if (ra != 31) {
                    if (islit)
                        tcg_gen_sari_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1171
                    else {
1172 1173 1174 1175
                        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);
1176
                    }
1177 1178 1179
                } else
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
            }
J
j_mayer 已提交
1180 1181 1182
            break;
        case 0x52:
            /* MSKWH */
A
aurel32 已提交
1183
            gen_arith3(helper_mskwh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1184 1185 1186
            break;
        case 0x57:
            /* INSWH */
A
aurel32 已提交
1187
            gen_arith3(helper_inswh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1188 1189 1190
            break;
        case 0x5A:
            /* EXTWH */
1191
            gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1192 1193 1194
            break;
        case 0x62:
            /* MSKLH */
A
aurel32 已提交
1195
            gen_arith3(helper_msklh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1196 1197 1198
            break;
        case 0x67:
            /* INSLH */
A
aurel32 已提交
1199
            gen_arith3(helper_inslh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1200 1201 1202
            break;
        case 0x6A:
            /* EXTLH */
1203
            gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1204 1205 1206
            break;
        case 0x72:
            /* MSKQH */
A
aurel32 已提交
1207
            gen_arith3(helper_mskqh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1208 1209 1210
            break;
        case 0x77:
            /* INSQH */
A
aurel32 已提交
1211
            gen_arith3(helper_insqh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1212 1213 1214
            break;
        case 0x7A:
            /* EXTQH */
1215
            gen_ext_h(NULL, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1216 1217 1218 1219 1220 1221 1222 1223 1224
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x13:
        switch (fn7) {
        case 0x00:
            /* MULL */
1225
            if (likely(rc != 31)) {
1226
                if (ra == 31)
1227 1228 1229 1230 1231 1232 1233 1234 1235
                    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 已提交
1236 1237 1238
            break;
        case 0x20:
            /* MULQ */
1239
            if (likely(rc != 31)) {
1240
                if (ra == 31)
1241 1242 1243 1244 1245 1246
                    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 已提交
1247 1248 1249
            break;
        case 0x30:
            /* UMULH */
A
aurel32 已提交
1250
            gen_arith3(helper_umulh, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1251 1252 1253
            break;
        case 0x40:
            /* MULL/V */
A
aurel32 已提交
1254
            gen_arith3(helper_mullv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1255 1256 1257
            break;
        case 0x60:
            /* MULQ/V */
A
aurel32 已提交
1258
            gen_arith3(helper_mulqv, ra, rb, rc, islit, lit);
J
j_mayer 已提交
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
            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 已提交
1270 1271 1272 1273 1274 1275 1276 1277 1278
            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 已提交
1279 1280 1281 1282 1283
            break;
        case 0x0A:
            /* SQRTF */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1284
            gen_farith2(&helper_sqrtf, rb, rc);
J
j_mayer 已提交
1285 1286 1287 1288 1289
            break;
        case 0x0B:
            /* SQRTS */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1290
            gen_farith2(&helper_sqrts, rb, rc);
J
j_mayer 已提交
1291 1292 1293 1294 1295
            break;
        case 0x14:
            /* ITOFF */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1296 1297 1298 1299 1300 1301 1302 1303 1304
            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 已提交
1305 1306 1307 1308 1309
            break;
        case 0x24:
            /* ITOFT */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1310 1311 1312 1313 1314 1315
            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 已提交
1316 1317 1318 1319 1320
            break;
        case 0x2A:
            /* SQRTG */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1321
            gen_farith2(&helper_sqrtg, rb, rc);
J
j_mayer 已提交
1322 1323 1324 1325 1326
            break;
        case 0x02B:
            /* SQRTT */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1327
            gen_farith2(&helper_sqrtt, rb, rc);
J
j_mayer 已提交
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338
            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 已提交
1339
            gen_farith3(&helper_addf, ra, rb, rc);
J
j_mayer 已提交
1340 1341 1342
            break;
        case 0x01:
            /* SUBF */
A
aurel32 已提交
1343
            gen_farith3(&helper_subf, ra, rb, rc);
J
j_mayer 已提交
1344 1345 1346
            break;
        case 0x02:
            /* MULF */
A
aurel32 已提交
1347
            gen_farith3(&helper_mulf, ra, rb, rc);
J
j_mayer 已提交
1348 1349 1350
            break;
        case 0x03:
            /* DIVF */
A
aurel32 已提交
1351
            gen_farith3(&helper_divf, ra, rb, rc);
J
j_mayer 已提交
1352 1353 1354 1355
            break;
        case 0x1E:
            /* CVTDG */
#if 0 // TODO
A
aurel32 已提交
1356
            gen_farith2(&helper_cvtdg, rb, rc);
J
j_mayer 已提交
1357 1358 1359 1360 1361 1362
#else
            goto invalid_opc;
#endif
            break;
        case 0x20:
            /* ADDG */
A
aurel32 已提交
1363
            gen_farith3(&helper_addg, ra, rb, rc);
J
j_mayer 已提交
1364 1365 1366
            break;
        case 0x21:
            /* SUBG */
A
aurel32 已提交
1367
            gen_farith3(&helper_subg, ra, rb, rc);
J
j_mayer 已提交
1368 1369 1370
            break;
        case 0x22:
            /* MULG */
A
aurel32 已提交
1371
            gen_farith3(&helper_mulg, ra, rb, rc);
J
j_mayer 已提交
1372 1373 1374
            break;
        case 0x23:
            /* DIVG */
A
aurel32 已提交
1375
            gen_farith3(&helper_divg, ra, rb, rc);
J
j_mayer 已提交
1376 1377 1378
            break;
        case 0x25:
            /* CMPGEQ */
A
aurel32 已提交
1379
            gen_farith3(&helper_cmpgeq, ra, rb, rc);
J
j_mayer 已提交
1380 1381 1382
            break;
        case 0x26:
            /* CMPGLT */
A
aurel32 已提交
1383
            gen_farith3(&helper_cmpglt, ra, rb, rc);
J
j_mayer 已提交
1384 1385 1386
            break;
        case 0x27:
            /* CMPGLE */
A
aurel32 已提交
1387
            gen_farith3(&helper_cmpgle, ra, rb, rc);
J
j_mayer 已提交
1388 1389 1390
            break;
        case 0x2C:
            /* CVTGF */
A
aurel32 已提交
1391
            gen_farith2(&helper_cvtgf, rb, rc);
J
j_mayer 已提交
1392 1393 1394 1395
            break;
        case 0x2D:
            /* CVTGD */
#if 0 // TODO
A
aurel32 已提交
1396
            gen_farith2(ctx, &helper_cvtgd, rb, rc);
J
j_mayer 已提交
1397 1398 1399 1400 1401 1402
#else
            goto invalid_opc;
#endif
            break;
        case 0x2F:
            /* CVTGQ */
A
aurel32 已提交
1403
            gen_farith2(&helper_cvtgq, rb, rc);
J
j_mayer 已提交
1404 1405 1406
            break;
        case 0x3C:
            /* CVTQF */
A
aurel32 已提交
1407
            gen_farith2(&helper_cvtqf, rb, rc);
J
j_mayer 已提交
1408 1409 1410
            break;
        case 0x3E:
            /* CVTQG */
A
aurel32 已提交
1411
            gen_farith2(&helper_cvtqg, rb, rc);
J
j_mayer 已提交
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
            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 已提交
1423
            gen_farith3(&helper_adds, ra, rb, rc);
J
j_mayer 已提交
1424 1425 1426
            break;
        case 0x01:
            /* SUBS */
A
aurel32 已提交
1427
            gen_farith3(&helper_subs, ra, rb, rc);
J
j_mayer 已提交
1428 1429 1430
            break;
        case 0x02:
            /* MULS */
A
aurel32 已提交
1431
            gen_farith3(&helper_muls, ra, rb, rc);
J
j_mayer 已提交
1432 1433 1434
            break;
        case 0x03:
            /* DIVS */
A
aurel32 已提交
1435
            gen_farith3(&helper_divs, ra, rb, rc);
J
j_mayer 已提交
1436 1437 1438
            break;
        case 0x20:
            /* ADDT */
A
aurel32 已提交
1439
            gen_farith3(&helper_addt, ra, rb, rc);
J
j_mayer 已提交
1440 1441 1442
            break;
        case 0x21:
            /* SUBT */
A
aurel32 已提交
1443
            gen_farith3(&helper_subt, ra, rb, rc);
J
j_mayer 已提交
1444 1445 1446
            break;
        case 0x22:
            /* MULT */
A
aurel32 已提交
1447
            gen_farith3(&helper_mult, ra, rb, rc);
J
j_mayer 已提交
1448 1449 1450
            break;
        case 0x23:
            /* DIVT */
A
aurel32 已提交
1451
            gen_farith3(&helper_divt, ra, rb, rc);
J
j_mayer 已提交
1452 1453 1454
            break;
        case 0x24:
            /* CMPTUN */
A
aurel32 已提交
1455
            gen_farith3(&helper_cmptun, ra, rb, rc);
J
j_mayer 已提交
1456 1457 1458
            break;
        case 0x25:
            /* CMPTEQ */
A
aurel32 已提交
1459
            gen_farith3(&helper_cmpteq, ra, rb, rc);
J
j_mayer 已提交
1460 1461 1462
            break;
        case 0x26:
            /* CMPTLT */
A
aurel32 已提交
1463
            gen_farith3(&helper_cmptlt, ra, rb, rc);
J
j_mayer 已提交
1464 1465 1466
            break;
        case 0x27:
            /* CMPTLE */
A
aurel32 已提交
1467
            gen_farith3(&helper_cmptle, ra, rb, rc);
J
j_mayer 已提交
1468 1469 1470 1471 1472
            break;
        case 0x2C:
            /* XXX: incorrect */
            if (fn11 == 0x2AC) {
                /* CVTST */
A
aurel32 已提交
1473
                gen_farith2(&helper_cvtst, rb, rc);
J
j_mayer 已提交
1474 1475
            } else {
                /* CVTTS */
A
aurel32 已提交
1476
                gen_farith2(&helper_cvtts, rb, rc);
J
j_mayer 已提交
1477 1478 1479 1480
            }
            break;
        case 0x2F:
            /* CVTTQ */
A
aurel32 已提交
1481
            gen_farith2(&helper_cvttq, rb, rc);
J
j_mayer 已提交
1482 1483 1484
            break;
        case 0x3C:
            /* CVTQS */
A
aurel32 已提交
1485
            gen_farith2(&helper_cvtqs, rb, rc);
J
j_mayer 已提交
1486 1487 1488
            break;
        case 0x3E:
            /* CVTQT */
A
aurel32 已提交
1489
            gen_farith2(&helper_cvtqt, rb, rc);
J
j_mayer 已提交
1490 1491 1492 1493 1494 1495 1496 1497 1498
            break;
        default:
            goto invalid_opc;
        }
        break;
    case 0x17:
        switch (fn11) {
        case 0x010:
            /* CVTLQ */
A
aurel32 已提交
1499
            gen_farith2(&helper_cvtlq, rb, rc);
J
j_mayer 已提交
1500 1501
            break;
        case 0x020:
A
aurel32 已提交
1502 1503
            if (likely(rc != 31)) {
                if (ra == rb)
J
j_mayer 已提交
1504
                    /* FMOV */
A
aurel32 已提交
1505 1506 1507 1508
                    tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
                else
                    /* CPYS */
                    gen_farith3(&helper_cpys, ra, rb, rc);
J
j_mayer 已提交
1509 1510 1511 1512
            }
            break;
        case 0x021:
            /* CPYSN */
A
aurel32 已提交
1513
            gen_farith3(&helper_cpysn, ra, rb, rc);
J
j_mayer 已提交
1514 1515 1516
            break;
        case 0x022:
            /* CPYSE */
A
aurel32 已提交
1517
            gen_farith3(&helper_cpyse, ra, rb, rc);
J
j_mayer 已提交
1518 1519 1520
            break;
        case 0x024:
            /* MT_FPCR */
A
aurel32 已提交
1521 1522 1523 1524 1525 1526 1527
            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 已提交
1528 1529 1530
            break;
        case 0x025:
            /* MF_FPCR */
A
aurel32 已提交
1531 1532
            if (likely(ra != 31))
                tcg_gen_helper_1_0(helper_load_fpcr, cpu_fir[ra]);
J
j_mayer 已提交
1533 1534 1535
            break;
        case 0x02A:
            /* FCMOVEQ */
A
aurel32 已提交
1536
            gen_fcmov(&helper_cmpfeq, ra, rb, rc);
J
j_mayer 已提交
1537 1538 1539
            break;
        case 0x02B:
            /* FCMOVNE */
A
aurel32 已提交
1540
            gen_fcmov(&helper_cmpfne, ra, rb, rc);
J
j_mayer 已提交
1541 1542 1543
            break;
        case 0x02C:
            /* FCMOVLT */
A
aurel32 已提交
1544
            gen_fcmov(&helper_cmpflt, ra, rb, rc);
J
j_mayer 已提交
1545 1546 1547
            break;
        case 0x02D:
            /* FCMOVGE */
A
aurel32 已提交
1548
            gen_fcmov(&helper_cmpfge, ra, rb, rc);
J
j_mayer 已提交
1549 1550 1551
            break;
        case 0x02E:
            /* FCMOVLE */
A
aurel32 已提交
1552
            gen_fcmov(&helper_cmpfle, ra, rb, rc);
J
j_mayer 已提交
1553 1554 1555
            break;
        case 0x02F:
            /* FCMOVGT */
A
aurel32 已提交
1556
            gen_fcmov(&helper_cmpfgt, ra, rb, rc);
J
j_mayer 已提交
1557 1558 1559
            break;
        case 0x030:
            /* CVTQL */
A
aurel32 已提交
1560
            gen_farith2(&helper_cvtql, rb, rc);
J
j_mayer 已提交
1561 1562 1563
            break;
        case 0x130:
            /* CVTQL/V */
A
aurel32 已提交
1564
            gen_farith2(&helper_cvtqlv, rb, rc);
J
j_mayer 已提交
1565 1566 1567
            break;
        case 0x530:
            /* CVTQL/SV */
A
aurel32 已提交
1568
            gen_farith2(&helper_cvtqlsv, rb, rc);
J
j_mayer 已提交
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603
            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 已提交
1604
            if (ra != 31)
1605
                tcg_gen_helper_1_0(helper_load_pcc, cpu_ir[ra]);
J
j_mayer 已提交
1606 1607 1608
            break;
        case 0xE000:
            /* RC */
A
aurel32 已提交
1609
            if (ra != 31)
1610
                tcg_gen_helper_1_0(helper_rc, cpu_ir[ra]);
J
j_mayer 已提交
1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
            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 已提交
1623
            if (ra != 31)
1624
                tcg_gen_helper_1_0(helper_rs, cpu_ir[ra]);
J
j_mayer 已提交
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
            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;
1641 1642 1643 1644 1645
        if (ra != 31) {
            TCGv tmp = tcg_const_i32(insn & 0xFF);
            tcg_gen_helper_1_2(helper_mfpr, cpu_ir[ra], tmp, cpu_ir[ra]);
            tcg_temp_free(tmp);
        }
J
j_mayer 已提交
1646 1647 1648
        break;
#endif
    case 0x1A:
A
aurel32 已提交
1649 1650 1651 1652 1653 1654
        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 已提交
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678
        /* 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;
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
        if (ra != 31) {
            TCGv addr = tcg_temp_new(TCG_TYPE_I64);
            if (rb != 31)
                tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
            else
                tcg_gen_movi_i64(addr, disp12);
            switch ((insn >> 12) & 0xF) {
            case 0x0:
                /* Longword physical access */
                tcg_gen_helper_0_2(helper_ldl_raw, cpu_ir[ra], addr);
                break;
            case 0x1:
                /* Quadword physical access */
                tcg_gen_helper_0_2(helper_ldq_raw, cpu_ir[ra], addr);
                break;
            case 0x2:
                /* Longword physical access with lock */
                tcg_gen_helper_0_2(helper_ldl_l_raw, cpu_ir[ra], addr);
                break;
            case 0x3:
                /* Quadword physical access with lock */
                tcg_gen_helper_0_2(helper_ldq_l_raw, cpu_ir[ra], addr);
                break;
            case 0x4:
                /* Longword virtual PTE fetch */
                tcg_gen_helper_0_2(helper_ldl_kernel, cpu_ir[ra], addr);
                break;
            case 0x5:
                /* Quadword virtual PTE fetch */
                tcg_gen_helper_0_2(helper_ldq_kernel, cpu_ir[ra], addr);
                break;
            case 0x6:
                /* Incpu_ir[ra]id */
                goto incpu_ir[ra]id_opc;
            case 0x7:
                /* Incpu_ir[ra]id */
                goto incpu_ir[ra]id_opc;
            case 0x8:
                /* Longword virtual access */
                tcg_gen_helper_1_1(helper_st_virt_to_phys, addr, addr);
                tcg_gen_helper_0_2(helper_ldl_raw, cpu_ir[ra], addr);
                break;
            case 0x9:
                /* Quadword virtual access */
                tcg_gen_helper_1_1(helper_st_virt_to_phys, addr, addr);
                tcg_gen_helper_0_2(helper_ldq_raw, cpu_ir[ra], addr);
                break;
            case 0xA:
                /* Longword virtual access with protection check */
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, ctx->flags);
                break;
            case 0xB:
                /* Quadword virtual access with protection check */
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, ctx->flags);
                break;
            case 0xC:
                /* Longword virtual access with altenate access mode */
                tcg_gen_helper_0_0(helper_set_alt_mode);
                tcg_gen_helper_1_1(helper_st_virt_to_phys, addr, addr);
                tcg_gen_helper_0_2(helper_ldl_raw, cpu_ir[ra], addr);
                tcg_gen_helper_0_0(helper_restore_mode);
                break;
            case 0xD:
                /* Quadword virtual access with altenate access mode */
                tcg_gen_helper_0_0(helper_set_alt_mode);
                tcg_gen_helper_1_1(helper_st_virt_to_phys, addr, addr);
                tcg_gen_helper_0_2(helper_ldq_raw, cpu_ir[ra], addr);
                tcg_gen_helper_0_0(helper_restore_mode);
                break;
            case 0xE:
                /* Longword virtual access with alternate access mode and
                 * protection checks
                 */
                tcg_gen_helper_0_0(helper_set_alt_mode);
                tcg_gen_helper_0_2(helper_ldl_data, cpu_ir[ra], addr);
                tcg_gen_helper_0_0(helper_restore_mode);
                break;
            case 0xF:
                /* Quadword virtual access with alternate access mode and
                 * protection checks
                 */
                tcg_gen_helper_0_0(helper_set_alt_mode);
                tcg_gen_helper_0_2(helper_ldq_data, cpu_ir[ra], addr);
                tcg_gen_helper_0_0(helper_restore_mode);
                break;
            }
            tcg_temp_free(addr);
J
j_mayer 已提交
1766 1767 1768 1769 1770 1771 1772 1773 1774
        }
        break;
#endif
    case 0x1C:
        switch (fn7) {
        case 0x00:
            /* SEXTB */
            if (!(ctx->amask & AMASK_BWX))
                goto invalid_opc;
1775 1776 1777 1778
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int8_t)lit));
                else
1779
                    tcg_gen_ext8s_i64(cpu_ir[rc], cpu_ir[rb]);
1780
            }
J
j_mayer 已提交
1781 1782 1783 1784 1785
            break;
        case 0x01:
            /* SEXTW */
            if (!(ctx->amask & AMASK_BWX))
                goto invalid_opc;
1786 1787 1788 1789
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
                else
1790
                    tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
1791
            }
J
j_mayer 已提交
1792 1793 1794 1795 1796
            break;
        case 0x30:
            /* CTPOP */
            if (!(ctx->amask & AMASK_CIX))
                goto invalid_opc;
1797 1798 1799 1800
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
                else
1801
                    tcg_gen_helper_1_1(helper_ctpop, cpu_ir[rc], cpu_ir[rb]);
1802
            }
J
j_mayer 已提交
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
            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;
1815 1816 1817 1818
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
                else
1819
                    tcg_gen_helper_1_1(helper_ctlz, cpu_ir[rc], cpu_ir[rb]);
1820
            }
J
j_mayer 已提交
1821 1822 1823 1824 1825
            break;
        case 0x33:
            /* CTTZ */
            if (!(ctx->amask & AMASK_CIX))
                goto invalid_opc;
1826 1827 1828 1829
            if (likely(rc != 31)) {
                if (islit)
                    tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
                else
1830
                    tcg_gen_helper_1_1(helper_cttz, cpu_ir[rc], cpu_ir[rb]);
1831
            }
J
j_mayer 已提交
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 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
            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 已提交
1921 1922 1923 1924 1925 1926
            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 已提交
1927 1928 1929 1930 1931
            break;
        case 0x78:
            /* FTOIS */
            if (!(ctx->amask & AMASK_FIX))
                goto invalid_opc;
A
aurel32 已提交
1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
            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 已提交
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955
            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;
1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967
        else {
            TCGv tmp1 = tcg_const_i32(insn & 0xFF);
            if (ra != 31)
                tcg_gen_helper(helper_mtpr, tmp1, cpu_ir[ra]);
            else {
                TCGv tmp2 = tcg_const_i64(0);
                tcg_gen_helper(helper_mtpr, tmp1, tmp2);
                tcg_temp_free(tmp2);
            }
            tcg_temp_free(tmp1);
            ret = 2;
        }
J
j_mayer 已提交
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978
        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 */
1979
            tcg_gen_helper_0_0(helper_hw_rei);
J
j_mayer 已提交
1980
        } else {
1981 1982 1983 1984 1985 1986 1987 1988 1989
            TCGv tmp;

            if (ra != 31) {
                tmp = tcg_temp_new(TCG_TYPE_I64);
                tcg_gen_addi_i64(tmp, cpu_ir[rb], (((int64_t)insn << 51) >> 51));
            } else
                tmp = tcg_const_i64(((int64_t)insn << 51) >> 51);
            tcg_gen_helper_0_1(helper_hw_ret, tmp);
            tcg_temp_free(tmp);
J
j_mayer 已提交
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
        }
        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;
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082
        else {
            TCGv addr, val;
            addr = tcg_temp_new(TCG_TYPE_I64);
            if (rb != 31)
                tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
            else
                tcg_gen_movi_i64(addr, disp12);
            if (ra != 31)
                val = cpu_ir[ra];
            else {
                val = tcg_temp_new(TCG_TYPE_I64);
                tcg_gen_movi_i64(val, 0);
            }
            switch ((insn >> 12) & 0xF) {
            case 0x0:
                /* Longword physical access */
                tcg_gen_helper_0_2(helper_stl_raw, val, addr);
                break;
            case 0x1:
                /* Quadword physical access */
                tcg_gen_helper_0_2(helper_stq_raw, val, addr);
                break;
            case 0x2:
                /* Longword physical access with lock */
                tcg_gen_helper_1_2(helper_stl_c_raw, val, val, addr);
                break;
            case 0x3:
                /* Quadword physical access with lock */
                tcg_gen_helper_1_2(helper_stq_c_raw, val, val, addr);
                break;
            case 0x4:
                /* Longword virtual access */
                tcg_gen_helper_1_1(helper_st_virt_to_phys, addr, addr);
                tcg_gen_helper_0_2(helper_stl_raw, val, addr);
                break;
            case 0x5:
                /* Quadword virtual access */
                tcg_gen_helper_1_1(helper_st_virt_to_phys, addr, addr);
                tcg_gen_helper_0_2(helper_stq_raw, val, addr);
                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 */
                tcg_gen_helper_0_0(helper_set_alt_mode);
                tcg_gen_helper_1_1(helper_st_virt_to_phys, addr, addr);
                tcg_gen_helper_0_2(helper_stl_raw, val, addr);
                tcg_gen_helper_0_0(helper_restore_mode);
                break;
            case 0xD:
                /* Quadword virtual access with alternate access mode */
                tcg_gen_helper_0_0(helper_set_alt_mode);
                tcg_gen_helper_1_1(helper_st_virt_to_phys, addr, addr);
                tcg_gen_helper_0_2(helper_stl_raw, val, addr);
                tcg_gen_helper_0_0(helper_restore_mode);
                break;
            case 0xE:
                /* Invalid */
                goto invalid_opc;
            case 0xF:
                /* Invalid */
                goto invalid_opc;
            }
            if (ra != 31)
                tcg_temp_free(val);
            tcg_temp_free(addr);
J
j_mayer 已提交
2083 2084 2085 2086 2087 2088
        }
        ret = 2;
        break;
#endif
    case 0x20:
        /* LDF */
A
aurel32 已提交
2089
        gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2090 2091 2092
        break;
    case 0x21:
        /* LDG */
A
aurel32 已提交
2093
        gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2094 2095 2096
        break;
    case 0x22:
        /* LDS */
A
aurel32 已提交
2097
        gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2098 2099 2100
        break;
    case 0x23:
        /* LDT */
A
aurel32 已提交
2101
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2102 2103 2104
        break;
    case 0x24:
        /* STF */
A
aurel32 已提交
2105
        gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2106 2107 2108
        break;
    case 0x25:
        /* STG */
A
aurel32 已提交
2109
        gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2110 2111 2112
        break;
    case 0x26:
        /* STS */
A
aurel32 已提交
2113
        gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2114 2115 2116
        break;
    case 0x27:
        /* STT */
A
aurel32 已提交
2117
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0);
J
j_mayer 已提交
2118 2119 2120
        break;
    case 0x28:
        /* LDL */
A
aurel32 已提交
2121
        gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2122 2123 2124
        break;
    case 0x29:
        /* LDQ */
A
aurel32 已提交
2125
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2126 2127 2128
        break;
    case 0x2A:
        /* LDL_L */
2129
        gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2130 2131 2132
        break;
    case 0x2B:
        /* LDQ_L */
2133
        gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2134 2135 2136
        break;
    case 0x2C:
        /* STL */
A
aurel32 已提交
2137
        gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2138 2139 2140
        break;
    case 0x2D:
        /* STQ */
A
aurel32 已提交
2141
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2142 2143 2144
        break;
    case 0x2E:
        /* STL_C */
2145
        gen_store_mem(ctx, &gen_qemu_stl_c, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2146 2147 2148
        break;
    case 0x2F:
        /* STQ_C */
2149
        gen_store_mem(ctx, &gen_qemu_stq_c, ra, rb, disp16, 0, 0);
J
j_mayer 已提交
2150 2151 2152
        break;
    case 0x30:
        /* BR */
A
aurel32 已提交
2153 2154 2155
        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 已提交
2156 2157 2158 2159
        ret = 1;
        break;
    case 0x31:
        /* FBEQ */
A
aurel32 已提交
2160
        gen_fbcond(ctx, &helper_cmpfeq, ra, disp16);
J
j_mayer 已提交
2161 2162 2163 2164
        ret = 1;
        break;
    case 0x32:
        /* FBLT */
A
aurel32 已提交
2165
        gen_fbcond(ctx, &helper_cmpflt, ra, disp16);
J
j_mayer 已提交
2166 2167 2168 2169
        ret = 1;
        break;
    case 0x33:
        /* FBLE */
A
aurel32 已提交
2170
        gen_fbcond(ctx, &helper_cmpfle, ra, disp16);
J
j_mayer 已提交
2171 2172 2173 2174
        ret = 1;
        break;
    case 0x34:
        /* BSR */
A
aurel32 已提交
2175 2176 2177
        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 已提交
2178 2179 2180 2181
        ret = 1;
        break;
    case 0x35:
        /* FBNE */
A
aurel32 已提交
2182
        gen_fbcond(ctx, &helper_cmpfne, ra, disp16);
J
j_mayer 已提交
2183 2184 2185 2186
        ret = 1;
        break;
    case 0x36:
        /* FBGE */
A
aurel32 已提交
2187
        gen_fbcond(ctx, &helper_cmpfge, ra, disp16);
J
j_mayer 已提交
2188 2189 2190 2191
        ret = 1;
        break;
    case 0x37:
        /* FBGT */
A
aurel32 已提交
2192
        gen_fbcond(ctx, &helper_cmpfgt, ra, disp16);
J
j_mayer 已提交
2193 2194 2195 2196
        ret = 1;
        break;
    case 0x38:
        /* BLBC */
A
aurel32 已提交
2197
        gen_bcond(ctx, TCG_COND_EQ, ra, disp16, 1);
J
j_mayer 已提交
2198 2199 2200 2201
        ret = 1;
        break;
    case 0x39:
        /* BEQ */
A
aurel32 已提交
2202
        gen_bcond(ctx, TCG_COND_EQ, ra, disp16, 0);
J
j_mayer 已提交
2203 2204 2205 2206
        ret = 1;
        break;
    case 0x3A:
        /* BLT */
A
aurel32 已提交
2207
        gen_bcond(ctx, TCG_COND_LT, ra, disp16, 0);
J
j_mayer 已提交
2208 2209 2210 2211
        ret = 1;
        break;
    case 0x3B:
        /* BLE */
A
aurel32 已提交
2212
        gen_bcond(ctx, TCG_COND_LE, ra, disp16, 0);
J
j_mayer 已提交
2213 2214 2215 2216
        ret = 1;
        break;
    case 0x3C:
        /* BLBS */
A
aurel32 已提交
2217
        gen_bcond(ctx, TCG_COND_NE, ra, disp16, 1);
J
j_mayer 已提交
2218 2219 2220 2221
        ret = 1;
        break;
    case 0x3D:
        /* BNE */
A
aurel32 已提交
2222
        gen_bcond(ctx, TCG_COND_NE, ra, disp16, 0);
J
j_mayer 已提交
2223 2224 2225 2226
        ret = 1;
        break;
    case 0x3E:
        /* BGE */
A
aurel32 已提交
2227
        gen_bcond(ctx, TCG_COND_GE, ra, disp16, 0);
J
j_mayer 已提交
2228 2229 2230 2231
        ret = 1;
        break;
    case 0x3F:
        /* BGT */
A
aurel32 已提交
2232
        gen_bcond(ctx, TCG_COND_GT, ra, disp16, 0);
J
j_mayer 已提交
2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243
        ret = 1;
        break;
    invalid_opc:
        gen_invalid(ctx);
        ret = 3;
        break;
    }

    return ret;
}

2244 2245 2246
static always_inline void gen_intermediate_code_internal (CPUState *env,
                                                          TranslationBlock *tb,
                                                          int search_pc)
J
j_mayer 已提交
2247 2248 2249 2250 2251 2252 2253 2254 2255 2256
{
#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 已提交
2257 2258
    int num_insns;
    int max_insns;
J
j_mayer 已提交
2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269

    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 已提交
2270 2271 2272 2273 2274 2275
    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 已提交
2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292
    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 已提交
2293
                gen_opc_icount[lj] = num_insns;
J
j_mayer 已提交
2294 2295
            }
        }
P
pbrook 已提交
2296 2297
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
            gen_io_start();
J
j_mayer 已提交
2298 2299 2300
#if defined ALPHA_DEBUG_DISAS
        insn_count++;
        if (logfile != NULL) {
2301 2302
            fprintf(logfile, "pc " TARGET_FMT_lx " mem_idx %d\n",
                    ctx.pc, ctx.mem_idx);
J
j_mayer 已提交
2303 2304 2305 2306 2307 2308 2309 2310 2311
        }
#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 已提交
2312
        num_insns++;
J
j_mayer 已提交
2313 2314 2315 2316 2317 2318 2319 2320
        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 已提交
2321 2322
            (env->singlestep_enabled) ||
            num_insns >= max_insns) {
J
j_mayer 已提交
2323 2324 2325 2326 2327 2328 2329
            break;
        }
#if defined (DO_SINGLE_STEP)
        break;
#endif
    }
    if (ret != 1 && ret != 3) {
A
aurel32 已提交
2330
        tcg_gen_movi_i64(cpu_pc, ctx.pc);
J
j_mayer 已提交
2331 2332
    }
#if defined (DO_TB_FLUSH)
A
aurel32 已提交
2333
    tcg_gen_helper_0_0(helper_tb_flush);
J
j_mayer 已提交
2334
#endif
P
pbrook 已提交
2335 2336
    if (tb->cflags & CF_LAST_IO)
        gen_io_end();
J
j_mayer 已提交
2337
    /* Generate the return instruction */
B
bellard 已提交
2338
    tcg_gen_exit_tb(0);
P
pbrook 已提交
2339
    gen_icount_end(tb, num_insns);
J
j_mayer 已提交
2340 2341 2342 2343 2344 2345 2346 2347
    *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 已提交
2348
        tb->icount = num_insns;
J
j_mayer 已提交
2349 2350 2351 2352 2353 2354 2355
    }
#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 已提交
2356
        target_disas(logfile, pc_start, ctx.pc - pc_start, 1);
J
j_mayer 已提交
2357 2358 2359 2360 2361
        fprintf(logfile, "\n");
    }
#endif
}

2362
void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
J
j_mayer 已提交
2363
{
2364
    gen_intermediate_code_internal(env, tb, 0);
J
j_mayer 已提交
2365 2366
}

2367
void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
J
j_mayer 已提交
2368
{
2369
    gen_intermediate_code_internal(env, tb, 1);
J
j_mayer 已提交
2370 2371
}

B
bellard 已提交
2372
CPUAlphaState * cpu_alpha_init (const char *cpu_model)
J
j_mayer 已提交
2373 2374 2375 2376 2377 2378 2379 2380
{
    CPUAlphaState *env;
    uint64_t hwpcb;

    env = qemu_mallocz(sizeof(CPUAlphaState));
    if (!env)
        return NULL;
    cpu_exec_init(env);
P
pbrook 已提交
2381
    alpha_translate_init();
J
j_mayer 已提交
2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410
    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 已提交
2411

A
aurel32 已提交
2412 2413 2414 2415 2416
void gen_pc_load(CPUState *env, TranslationBlock *tb,
                unsigned long searched_pc, int pc_pos, void *puc)
{
    env->pc = gen_opc_pc[pc_pos];
}